IF a player clicks a certain item then remove a different item in inventory

Discussion in 'Plugin Development' started by xCyclonez, Jun 22, 2017.

Thread Status:
Not open for further replies.
  1. Offline

    xCyclonez

    if(p.getItemInHand().getItemMeta().getDisplayName().equals(ChatColor.LIGHT_PURPLE + "" + ChatColor.BOLD + "Pig Summoner" + ChatColor.GRAY + "" + ChatColor.UNDERLINE + " [Click to Summon]")) {
    if(p.getItemInHand().getEnchantments().containsKey(Enchantment.DURABILITY)) {
    if(p.getInventory().getName().equals(ChatColor.RED + "" + ChatColor.UNDERLINE + "" + ChatColor.BOLD + "Summoner Fuel")) {

    I don't know why this doesnt work
     
  2. Offline

    timtower Administrator Administrator Moderator

    @xCyclonez Then print out the values of what you are checking.
     
  3. Offline

    xCyclonez

    @timtower what do you mean?

    I'm checking for if a certain item has a name of "Summoner Fuel", it removes it then does stuff
     
  4. Offline

    timtower Administrator Administrator Moderator

    @xCyclonez When you print the name to the console, is it the same as you are checking for?
     
  5. Offline

    xCyclonez

    @timtower I'm still confused. Here are my itemstacks.

    ItemStack pig = new ItemStack(Material.CHORUS_FRUIT_POPPED);
    ItemMeta pigmeta = pig.getItemMeta();
    pigmeta.setDisplayName(ChatColor.LIGHT_PURPLE + "" + ChatColor.BOLD + "Pig Summoner" + ChatColor.GRAY + "" + ChatColor.UNDERLINE + " [Click to Summon]");
    pig.setItemMeta(pigmeta);
    pig.addUnsafeEnchantment(Enchantment.DURABILITY, 1);

    ItemStack fuel = new ItemStack(Material.FIREWORK_CHARGE);
    ItemMeta fuelmeta = fuel.getItemMeta();
    fuelmeta.setDisplayName(ChatColor.RED + "" + ChatColor.UNDERLINE + "" + ChatColor.BOLD + "Summoner Fuel");
    fuel.setItemMeta(fuelmeta);
    fuel.addUnsafeEnchantment(Enchantment.DURABILITY, 1);
     
  6. Woah there dude would be nice if you used the
    Code:
    CODE BOX
    (CODE) (/CODE) (but with [] instead of () )

    Also I believe it is a bad idea to compare using itemstacks just check each value separately plus we can't actually do anything until we see the event and the Stacktrace error if you have one
     
  7. Offline

    MelonCola

    Try debugging your code(Put a player.sendmessage or use the logs after every if statement) to indicate how far the code goes.
     
  8. Offline

    SenpaiLion

    Don't forget to make sure first that if the items actually have a displayname/item meta etc.
     
Thread Status:
Not open for further replies.

Share This Page