Add warning for meta filter user logic error

This commit is contained in:
fullwall 2024-09-16 01:20:25 +08:00
parent 3c3a8102d6
commit 17eeac29cf
2 changed files with 11 additions and 4 deletions

View File

@ -1000,10 +1000,12 @@ public class ShopTrait extends Trait {
public void onInventoryClick(InventoryClickEvent evt) {
if (!evt.getView().equals(view))
return;
if (evt.getSlotType() != SlotType.RESULT || !evt.getAction().name().contains("PICKUP")
|| (evt.getCursor() != null && evt.getCursor().getType() != Material.AIR))
if (evt.getSlotType() != SlotType.RESULT)
return;
evt.setCancelled(true);
if (!evt.getAction().name().contains("PICKUP")
|| (evt.getCursor() != null && evt.getCursor().getType() != Material.AIR))
return;
Inventory syntheticInventory = Bukkit.createInventory(null, 9);
syntheticInventory.setItem(0, evt.getClickedInventory().getItem(0));
syntheticInventory.setItem(1, evt.getClickedInventory().getItem(1));

View File

@ -24,6 +24,7 @@ import net.citizensnpcs.api.gui.InventoryMenuSlot;
import net.citizensnpcs.api.gui.Menu;
import net.citizensnpcs.api.gui.MenuContext;
import net.citizensnpcs.api.persistence.Persist;
import net.citizensnpcs.api.util.Messaging;
import net.citizensnpcs.api.util.SpigotUtil;
import net.citizensnpcs.util.InventoryMultiplexer;
import net.citizensnpcs.util.NMS;
@ -161,6 +162,7 @@ public class ItemAction extends NPCShopAction {
private boolean metaMatches(ItemStack needle, ItemStack haystack, List<String> meta) {
Map<String, Object> source = NMS.getComponentMap(needle);
Map<String, Object> compare = NMS.getComponentMap(haystack);
Messaging.idebug(() -> "Shop filter: comparing " + source + " to " + compare);
for (String nbt : meta) {
String[] parts = nbt.split("\\.");
Object acc = source;
@ -174,8 +176,11 @@ public class ItemAction extends NPCShopAction {
return false;
Map<String, Object> nextAcc = (Map<String, Object>) acc;
Map<String, Object> nextCmp = (Map<String, Object>) cmp;
if (!nextAcc.containsKey(parts[i]))
break;
if (!nextAcc.containsKey(parts[i])) {
Messaging.warn("Probable error in shop filter: source item does not contain requested meta "
+ metaFilter + " actual meta is: " + source);
return false;
}
if (!nextCmp.containsKey(parts[i]))
return false;
acc = nextAcc.get(parts[i]);