Check if 2 itemstacks match

Hello, I was making a plugin and I was trying to check if the itemstack the player is holding matches the itemstack, which I loaded from the config. I currently have this, however it doesn’t seem to work…

Logger logger = Sponge.getPluginManager().getLogger(Sponge.getPluginManager().getPlugin("Test").orElse(null)); @Listener public void onRightClick(InteractEvent e, @First Player p){ File itemsFile = main.getItemsFile(); ConfigurationLoader<CommentedConfigurationNode> loader = HoconConfigurationLoader.builder().setPath(temsFile.toPath()).build(); ConfigurationNode node = null; try{node = loader.load().getNode("Item");}catch(IOException e1){e1.printStackTrace();} ItemStack Hand = p.getItemInHand().orElse(null); ItemStack item = ItemStackSerializer.deserializeItemStack(node); logger.debug("Player: "+p.getName());; logger.debug("Hand: "+Hand.get(Keys.DISPLAY_NAME).get().toString()); logger.debug("Item: "+item.get(Keys.DISPLAY_NAME).get().toString()); if(Hand != null){ if(Hand.equals(item)){ logger.info("User is holding the Item!"); p.sendTitle(Title.of(Text.of("Derp"))); } } }

You can use the ItemStackComparators class to compare based of TYPE, SIZE, TYPE_SIZE, PROPERTIES, ITEM_DATA or ALL.

1 Like

Thanks, that worked!