[RESOLVED] Checking for Item Type and Name

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. :kissing_smiling_eyes:

First off, text components can be anywhere. A better method of checking is inventory.getName().get().toPlain().equals("Rudimentary Crafting Table")). Second, what do you mean you don’t know how to check the name? You did it in the second if statement.

I get how to check the name what I don’t get is how to check for a specific type with a specific name.

if (player.getInventory().contains(ItemTypes.EMERALD)){

Is only checking for the item type Emerald not Emerald with the name of “test”. I would imagine that slapping on .get().equals(Text.of(“test”)) wouldn’t work.

Honestly I have no clue what I’m doing in the slightest. I’m coming from a background of mainly different scripting languages and I’ve dabbled in forge modding in the past. Imagine a monkey smashing rocks together and sometimes something useful comes of it.

You already have the ItemStackSnapshot, which you get the name from. All you have to do is to check the ItemType of that too, not what the player has in their inventory.