diff --git a/README.md b/README.md
index 415d655..1fa5e2c 100644
--- a/README.md
+++ b/README.md
@@ -17,9 +17,14 @@
- **Hunger Level**: the amount of hunger to require when harvesting, or none (_default: none_).
- **Experience Type**: whether to consume or reward XP points for harvesting (_default: none_).
- **Show Server Warning**: whether to display a warning when connecting to a server which does not have RightClickHarvest installed, as the mod will not work (_default: true_).
+- **Enable Permissions**: whether to check for permissions before doing anything (_default: false_).
There are also a number of block and item tags available to customise the mod's behaviour, documented [here](https://docs.jamalam.tech/right-click-harvest/tags/).
+
Available Permissions
+
+- **Harvest in Radius**: If Configuration has "Enable Permissions" set to `true` player will need the permission `rightclickharvest.radius_harvest` to harvest in radius.
+
FAQ
- **Does this work client-side?** No, RightClickHarvest **must** be installed on the server and can **optionally** be installed on the client.
diff --git a/common/build.gradle b/common/build.gradle
index b5e3512..3f92304 100644
--- a/common/build.gradle
+++ b/common/build.gradle
@@ -16,6 +16,7 @@ dependencies {
modImplementation libs.fabric.loader
modImplementation libs.architectury.common
modImplementation libs.jamlib.common
+ compileOnly libs.luckperms.api
}
tasks.processResources.dependsOn("updateServerLangProvider")
diff --git a/common/src/main/java/io/github/jamalam360/rightclickharvest/Config.java b/common/src/main/java/io/github/jamalam360/rightclickharvest/Config.java
index 0b68267..b4af051 100644
--- a/common/src/main/java/io/github/jamalam360/rightclickharvest/Config.java
+++ b/common/src/main/java/io/github/jamalam360/rightclickharvest/Config.java
@@ -16,6 +16,7 @@ public class Config implements ConfigExtensions {
@Comment("Modpack developers, set this to true to stop RCH telling users that they probably need to equip a hoe to harvest crops (if requireHoe is set to true). This message will only be displayed once.")
@HiddenInGui
public boolean hasUserBeenWarnedForNotUsingHoe = false;
+ public boolean enablePermissions = false;
@Override
public List getLinks() {
diff --git a/common/src/main/java/io/github/jamalam360/rightclickharvest/RightClickHarvest.java b/common/src/main/java/io/github/jamalam360/rightclickharvest/RightClickHarvest.java
index d1e1165..a9d31b8 100644
--- a/common/src/main/java/io/github/jamalam360/rightclickharvest/RightClickHarvest.java
+++ b/common/src/main/java/io/github/jamalam360/rightclickharvest/RightClickHarvest.java
@@ -9,6 +9,8 @@
import io.github.jamalam360.jamlib.JamLibPlatform;
import io.github.jamalam360.jamlib.config.ConfigManager;
import io.github.jamalam360.rightclickharvest.mixin.CropBlockAccessor;
+import io.github.jamalam360.rightclickharvest.permission.PermissionManager;
+import io.github.jamalam360.rightclickharvest.permission.Permissions;
import net.minecraft.ChatFormatting;
import net.minecraft.core.BlockPos;
import net.minecraft.core.Direction;
@@ -119,7 +121,7 @@ public static InteractionResult onBlockUse(Player player, Level level, Interacti
if (state.getBlock() instanceof CocoaBlock || state.getBlock() instanceof CropBlock || state.getBlock() instanceof NetherWartBlock) {
if (isMature(state)) {
// Start radius harvesting
- if (initialCall && CONFIG.get().harvestInRadius && !state.is(RADIUS_HARVEST_BLACKLIST) && isHoe(stackInHand)) {
+ if (initialCall && CONFIG.get().harvestInRadius && !state.is(RADIUS_HARVEST_BLACKLIST) && isHoe(stackInHand) && PermissionManager.getInstance().hasPermission(player, Permissions.HARVEST)) {
int radius = 0;
boolean circle = false;
hoeInUse = true;
diff --git a/common/src/main/java/io/github/jamalam360/rightclickharvest/permission/PermissionManager.java b/common/src/main/java/io/github/jamalam360/rightclickharvest/permission/PermissionManager.java
new file mode 100644
index 0000000..c9a1704
--- /dev/null
+++ b/common/src/main/java/io/github/jamalam360/rightclickharvest/permission/PermissionManager.java
@@ -0,0 +1,47 @@
+package io.github.jamalam360.rightclickharvest.permission;
+
+import io.github.jamalam360.rightclickharvest.RightClickHarvest;
+import net.luckperms.api.LuckPerms;
+import net.luckperms.api.LuckPermsProvider;
+import net.luckperms.api.model.user.User;
+import net.luckperms.api.node.NodeType;
+import net.minecraft.world.entity.player.Player;
+
+public class PermissionManager {
+
+ private static PermissionManager instance;
+ private LuckPerms luckPerms;
+
+ private PermissionManager() {
+ if (RightClickHarvest.CONFIG.get().enablePermissions) {
+ try {
+ this.luckPerms = LuckPermsProvider.get();
+ } catch (IllegalStateException e) {
+ this.luckPerms = null;
+ RightClickHarvest.LOGGER.info(
+ "Environment don't have LuckPerms installed, no " +
+ "permissions "
+ + "will be handled");
+ }
+ }
+ }
+
+ public static PermissionManager getInstance() {
+ if (instance == null) {
+ instance = new PermissionManager();
+ }
+ return instance;
+ }
+
+ public boolean hasPermission(Player player, Permissions permission) {
+ if (luckPerms == null) {
+ return true;
+ }
+ User user = luckPerms.getUserManager().getUser(player.getUUID());
+ return user.getNodes(NodeType.PERMISSION)
+ .stream()
+ .anyMatch(it
+ -> it.getPermission().equalsIgnoreCase(
+ permission.getPermission()));
+ }
+}
diff --git a/common/src/main/java/io/github/jamalam360/rightclickharvest/permission/Permissions.java b/common/src/main/java/io/github/jamalam360/rightclickharvest/permission/Permissions.java
new file mode 100644
index 0000000..b26ce68
--- /dev/null
+++ b/common/src/main/java/io/github/jamalam360/rightclickharvest/permission/Permissions.java
@@ -0,0 +1,12 @@
+package io.github.jamalam360.rightclickharvest.permission;
+
+public enum Permissions {
+
+ HARVEST("rightclickharvest.radius_harvest");
+
+ private final String permission;
+
+ Permissions(String permission) { this.permission = permission; }
+
+ public String getPermission() { return this.permission; }
+}
diff --git a/fabric/build.gradle b/fabric/build.gradle
index eae3e0e..cec8a66 100644
--- a/fabric/build.gradle
+++ b/fabric/build.gradle
@@ -101,7 +101,8 @@ processResources {
"minecraft_version" : project.minimum_minecraft_version,
"fabric_api_version" : project.minimum_fabric_api_version,
"architectury_version": project.minimum_architectury_api_version,
- "jamlib_version" : project.minimum_jamlib_version
+ "jamlib_version" : project.minimum_jamlib_version,
+ "luckperms_version" : project.minimum_luckperms_version
]
filesMatching("fabric.mod.json") {
diff --git a/gradle.properties b/gradle.properties
index ca2a762..c4ac91b 100644
--- a/gradle.properties
+++ b/gradle.properties
@@ -9,6 +9,7 @@ minimum_minecraft_version=1.21.9
minimum_architectury_api_version=18.0.3
minimum_fabric_api_version=0.134.0+1.21.9
minimum_jamlib_version=1.3.5+1.21.9
+minimum_luckperms_version=5.5.20
branch=main
group=io.github.jamalam360
diff --git a/libs.versions.toml b/libs.versions.toml
index c48c520..640d1e2 100644
--- a/libs.versions.toml
+++ b/libs.versions.toml
@@ -19,6 +19,9 @@ jamlib = "1.3.5+1.21.10"
# https://modrinth.com/mod/modmenu/versions
modmenu = "16.0.0-rc.1"
+# https://luckperms.net/wiki/Developer-API#gradle
+luckperms-api = "5.5"
+
[libraries]
architectury-common = { module = "dev.architectury:architectury", version.ref = "architectury" }
architectury-fabric = { module = "dev.architectury:architectury-fabric", version.ref = "architectury" }
@@ -33,4 +36,6 @@ jamlib-common = { module = "io.github.jamalam360:jamlib", version.ref = "jamlib"
jamlib-fabric = { module = "io.github.jamalam360:jamlib-fabric", version.ref = "jamlib" }
jamlib-neoforge = { module = "io.github.jamalam360:jamlib-neoforge", version.ref = "jamlib" }
+luckperms-api = { module = "net.luckperms:api", version.ref = "luckperms.api"}
+
modmenu = { module = "maven.modrinth:modmenu", version.ref = "modmenu" }
diff --git a/neoforge/build.gradle b/neoforge/build.gradle
index bcaa2d6..51ef907 100644
--- a/neoforge/build.gradle
+++ b/neoforge/build.gradle
@@ -101,7 +101,8 @@ processResources {
"minecraft_version" : project.minimum_minecraft_version,
"neoforge_version" : project.minimum_minecraft_version.substring(2),
"architectury_version": project.minimum_architectury_api_version,
- "jamlib_version" : project.minimum_jamlib_version
+ "jamlib_version" : project.minimum_jamlib_version,
+ "luckperms_version" : project.minimum_luckperms_version
]
filesMatching("META-INF/neoforge.mods.toml") {
diff --git a/neoforge/src/main/resources/META-INF/neoforge.mods.toml b/neoforge/src/main/resources/META-INF/neoforge.mods.toml
index 7ae3906..db30fed 100644
--- a/neoforge/src/main/resources/META-INF/neoforge.mods.toml
+++ b/neoforge/src/main/resources/META-INF/neoforge.mods.toml
@@ -40,5 +40,12 @@ versionRange = "[${jamlib_version},)"
ordering = "AFTER"
side = "BOTH"
+[[dependencies.rightclickharvest]]
+modId = "luckperms"
+type = "optional"
+versionRange = "[${luckperms_version},)"
+ordering = "AFTER"
+side = "SERVER"
+
[[mixins]]
config = "rightclickharvest.mixins.json"