Solved Detection for correct ItemStack?

Discussion in 'Plugin Development' started by Minecraft Zealot, Dec 20, 2023.

Thread Status:
Not open for further replies.
  1. I am trying to detect when a player has clicked with the correct item in hand. It looks like directly comparing with .equals() does not work. I can only get the detection for my desired item when I compare the item metas. Could I have some insight on why this is?

    @EventHandlerpublic void eee(PlayerInteractEvent e){
    if(e.getItem() == null)return;

    if(e.getItem().equals(Items.getEEE()))
    Bukkit.getLogger().info("DETECTED EEE IN HAND! 1");

    if(e.getItem() == Items.getEEE())
    Bukkit.getLogger().info("DETECTED EEE IN HAND! 2");

    if(e.getItem().getItemMeta().equals(Items.getEEE().getItemMeta()))
    Bukkit.getLogger().info("DETECTED EEE IN HAND! 3");

    if(e.getMaterial().equals(Material.GLOWSTONE_DUST) && e.getItem().displayName().equals(Items.getEEE().displayName()))
    Bukkit.getLogger().info("DETECTED EEE IN HAND! 4");

    }

    Items.getEEE() returns the exact ItemStack which is a custom item that is glowstone dust

    Only the check for #3 works.
     
  2. Offline

    timtower Administrator Administrator Moderator

    Minecraft Zealot likes this.
Thread Status:
Not open for further replies.

Share This Page