9
0
mirror of https://github.com/Xiao-MoMi/Custom-Fishing.git synced 2025-12-19 15:09:24 +00:00

fix item meta handling

This commit is contained in:
Xiao-MoMi
2025-09-18 22:11:59 +08:00
parent e416984b7b
commit f1165cfafe
3 changed files with 25 additions and 2 deletions

View File

@@ -80,7 +80,7 @@ public interface ItemManager extends Reloadable {
/**
* Retrieves the item ID of the given item stack. If it's a vanilla item, the returned value would be capitalized for instance {@code PAPER}. If it's a CustomFishing
* item, the returned value would be the ID for instance {@code beginner_rod}. If it's an item from other plugins, the returned value would be the
* id from that plugin for instance {@code itemsadder_namespace:id} / {@code oraxen_item_id}
* id from that plugin for instance {@code namespace:id} / {@code MythicSword}
*
* @param itemStack the {@link ItemStack} to be checked
* @return the custom fishing item ID, or null if the item stack is not a custom fishing item

View File

@@ -325,7 +325,9 @@ public class BukkitItemManager implements ItemManager, Listener {
plugin.debug("Another plugin modified the item from `PlayerItemDamageEvent` called by CustomFishing");
return;
}
if (!itemStack.getItemMeta().equals(previousMeta)) {
ItemMeta itemMeta = itemStack.getItemMeta();
if (itemMeta == null || !itemMeta.equals(previousMeta)) {
return;
}

View File

@@ -334,6 +334,27 @@ public class BukkitRequirementManager implements RequirementManager<Player> {
return Requirement.empty();
}
}, "item-in-hand");
registerRequirement((args, actions, runActions) -> {
if (args instanceof Section section) {
boolean mainOrOff = section.getString("hand","main").equalsIgnoreCase("main");
int amount = section.getInt("amount", 1);
List<String> items = ListUtils.toList(section.get("item"));
return context -> {
ItemStack itemStack = mainOrOff ?
context.holder().getInventory().getItemInMainHand()
: context.holder().getInventory().getItemInOffHand();
String id = plugin.getItemManager().getItemID(itemStack);
if (!items.contains(id) || itemStack.getAmount() < amount) {
return true;
}
if (runActions) ActionManager.trigger(context, actions);
return false;
};
} else {
plugin.getPluginLogger().warn("Invalid value type: " + args.getClass().getSimpleName() + " found at !item-in-hand requirement which is expected be `Section`");
return Requirement.empty();
}
}, "!item-in-hand");
}
private void registerPluginLevelRequirement() {