During an inventory click event I am trying to get if the player has a specific item with a specific name. For testing purposing lets say I’m looking for an emerald with the name “test”.
Right now I have it so that it checks if the player has an emerald but I’m stumped on how to also check for the name at the same time.
@Listener
public void onItemCraft(ClickInventoryEvent event, @Root Player player, @Getter("getTargetInventory") Inventory inventory) {
//Sponge.getServer().getBroadcastChannel().send(Text.of());
if (inventory.getName().get().contains("Rudimentary Crafting Table")){
event.setCancelled(true);
if (event.getCursorTransaction().getFinal().get(Keys.DISPLAY_NAME).get().equals(Text.of("Emerald"))){
if (player.getInventory().contains(ItemTypes.EMERALD)){
Sponge.getServer().getBroadcastChannel().send(Text.of("Player has Emerald!"));
}
}
}
EDIT:
I’ve been asking a lot of questions on the forums lately so if anyone would like to indulge me and mentor me on discord I would be down. 