mirror of
https://github.com/Xiao-MoMi/Custom-Crops.git
synced 2025-12-19 23:19:19 +00:00
Update PlayerActionManager.java
This commit is contained in:
@@ -218,25 +218,35 @@ public class PlayerActionManager extends AbstractActionManager<Player> {
|
|||||||
|
|
||||||
private void registerItemAction() {
|
private void registerItemAction() {
|
||||||
registerAction((args, chance) -> {
|
registerAction((args, chance) -> {
|
||||||
if (args instanceof Section section) {
|
Boolean mainOrOff;
|
||||||
boolean mainOrOff = section.getString("hand", "main").equalsIgnoreCase("main");
|
int amount;
|
||||||
int amount = section.getInt("amount", 1);
|
if (args instanceof Integer integer) {
|
||||||
return context -> {
|
mainOrOff = null;
|
||||||
if (context.holder() == null) return;
|
amount = integer;
|
||||||
if (Math.random() > chance) return;
|
} else if (args instanceof Section section) {
|
||||||
Player player = context.holder();
|
String hand = section.getString("hand");
|
||||||
boolean tempHand = mainOrOff;
|
mainOrOff = hand == null ? null : hand.equalsIgnoreCase("main");
|
||||||
EquipmentSlot hand = context.arg(ContextKeys.SLOT);
|
amount = section.getInt("amount", 1);
|
||||||
if (hand == EquipmentSlot.OFF_HAND || hand == EquipmentSlot.HAND) {
|
|
||||||
tempHand = hand == EquipmentSlot.HAND;
|
|
||||||
}
|
|
||||||
ItemStack itemStack = tempHand ? player.getInventory().getItemInMainHand() : player.getInventory().getItemInOffHand();
|
|
||||||
itemStack.setAmount(Math.max(0, itemStack.getAmount() + amount));
|
|
||||||
};
|
|
||||||
} else {
|
} else {
|
||||||
plugin.getPluginLogger().warn("Invalid value type: " + args.getClass().getSimpleName() + " found at item-amount action which is expected to be `Section`");
|
plugin.getPluginLogger().warn("Invalid value type: " + args.getClass().getSimpleName() + " found at item-amount action which is expected to be `Section`");
|
||||||
return Action.empty();
|
return Action.empty();
|
||||||
}
|
}
|
||||||
|
return context -> {
|
||||||
|
if (context.holder() == null) return;
|
||||||
|
if (Math.random() > chance) return;
|
||||||
|
Player player = context.holder();
|
||||||
|
EquipmentSlot hand = context.arg(ContextKeys.SLOT);
|
||||||
|
if (mainOrOff == null && hand == null) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
boolean tempHand = Objects.requireNonNullElseGet(mainOrOff, () -> hand == EquipmentSlot.HAND);
|
||||||
|
ItemStack itemStack = tempHand ? player.getInventory().getItemInMainHand() : player.getInventory().getItemInOffHand();
|
||||||
|
if (amount < 0) {
|
||||||
|
itemStack.setAmount(Math.max(0, itemStack.getAmount() + amount));
|
||||||
|
} else if (amount > 0) {
|
||||||
|
PlayerUtils.giveItem(player, itemStack, amount);
|
||||||
|
}
|
||||||
|
};
|
||||||
}, "item-amount");
|
}, "item-amount");
|
||||||
registerAction((args, chance) -> {
|
registerAction((args, chance) -> {
|
||||||
int amount;
|
int amount;
|
||||||
@@ -259,7 +269,7 @@ public class PlayerActionManager extends AbstractActionManager<Player> {
|
|||||||
if (player == null) return;
|
if (player == null) return;
|
||||||
EquipmentSlot tempSlot = slot;
|
EquipmentSlot tempSlot = slot;
|
||||||
EquipmentSlot equipmentSlot = context.arg(ContextKeys.SLOT);
|
EquipmentSlot equipmentSlot = context.arg(ContextKeys.SLOT);
|
||||||
if (equipmentSlot != null) {
|
if (tempSlot == null && equipmentSlot != null) {
|
||||||
tempSlot = equipmentSlot;
|
tempSlot = equipmentSlot;
|
||||||
}
|
}
|
||||||
if (tempSlot == null) {
|
if (tempSlot == null) {
|
||||||
|
|||||||
Reference in New Issue
Block a user