Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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/).

<h2 align="center">Available Permissions</h2>

- **Harvest in Radius**: If Configuration has "Enable Permissions" set to `true` player will need the permission `rightclickharvest.radius_harvest` to harvest in radius.

<h2 align="center">FAQ</h2>

- **Does this work client-side?** No, RightClickHarvest **must** be installed on the server and can **optionally** be installed on the client.
Expand Down
1 change: 1 addition & 0 deletions common/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ public class Config implements ConfigExtensions<Config> {
@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<Link> getLinks() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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;
Expand Down
Original file line number Diff line number Diff line change
@@ -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()));
}
}
Original file line number Diff line number Diff line change
@@ -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; }
}
3 changes: 2 additions & 1 deletion fabric/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -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") {
Expand Down
1 change: 1 addition & 0 deletions gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
5 changes: 5 additions & 0 deletions libs.versions.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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" }
Expand All @@ -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" }
3 changes: 2 additions & 1 deletion neoforge/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -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") {
Expand Down
7 changes: 7 additions & 0 deletions neoforge/src/main/resources/META-INF/neoforge.mods.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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"