mirror of
https://github.com/Xiao-MoMi/Custom-Crops.git
synced 2025-12-21 07:59:16 +00:00
Added an option to check the other hand
This commit is contained in:
@@ -334,13 +334,20 @@ public abstract class AbstractCustomEventListener implements Listener {
|
||||
}
|
||||
}
|
||||
|
||||
@EventHandler
|
||||
@EventHandler(ignoreCancelled = true)
|
||||
public void onBlockPhysics(BlockPhysicsEvent event) {
|
||||
if (ConfigManager.overriddenCrops().contains(event.getBlock().getType())) {
|
||||
event.setCancelled(true);
|
||||
}
|
||||
}
|
||||
|
||||
@EventHandler(ignoreCancelled = true)
|
||||
public void onBlockGrow(BlockGrowEvent event) {
|
||||
if (ConfigManager.overriddenCrops().contains(event.getBlock().getType())) {
|
||||
event.setCancelled(true);
|
||||
}
|
||||
}
|
||||
|
||||
@EventHandler(ignoreCancelled = true, priority = EventPriority.HIGH)
|
||||
public void onDispenser(BlockDispenseEvent event) {
|
||||
Block block = event.getBlock();
|
||||
|
||||
@@ -64,7 +64,19 @@ public class PlayerRequirementManager extends AbstractRequirementManager<Player>
|
||||
private void registerItemInHandRequirement() {
|
||||
registerRequirement((args, actions, runActions) -> {
|
||||
if (args instanceof Section section) {
|
||||
boolean mainOrOff = section.getString("hand","main").equalsIgnoreCase("main");
|
||||
String hand = section.getString("hand","main");
|
||||
int mode;
|
||||
if (hand.equalsIgnoreCase("main")) {
|
||||
mode = 1;
|
||||
} else if (hand.equalsIgnoreCase("off")) {
|
||||
mode = 2;
|
||||
} else if (hand.equalsIgnoreCase("other")) {
|
||||
mode = 3;
|
||||
} else {
|
||||
mode = 0;
|
||||
plugin.getPluginLogger().warn("Invalid hand argument: " + hand + " which is expected to be main/off/other");
|
||||
return Requirement.empty();
|
||||
}
|
||||
int amount = section.getInt("amount", 0);
|
||||
List<String> items = ListUtils.toList(section.get("item"));
|
||||
return context -> {
|
||||
@@ -73,10 +85,14 @@ public class PlayerRequirementManager extends AbstractRequirementManager<Player>
|
||||
EquipmentSlot slot = context.arg(ContextKeys.SLOT);
|
||||
ItemStack itemStack;
|
||||
if (slot == null) {
|
||||
itemStack = mainOrOff ? player.getInventory().getItemInMainHand() : player.getInventory().getItemInOffHand();
|
||||
itemStack = mode == 1 ? player.getInventory().getItemInMainHand() : player.getInventory().getItemInOffHand();
|
||||
} else {
|
||||
if (mode == 3) {
|
||||
itemStack = player.getInventory().getItem(slot == EquipmentSlot.HAND ? EquipmentSlot.OFF_HAND : EquipmentSlot.HAND);
|
||||
} else {
|
||||
itemStack = player.getInventory().getItem(slot);
|
||||
}
|
||||
}
|
||||
String id = plugin.getItemManager().id(itemStack);
|
||||
if (items.contains(id) && itemStack.getAmount() >= amount) return true;
|
||||
if (runActions) ActionManager.trigger(context, actions);
|
||||
|
||||
Reference in New Issue
Block a user