Solved PlayerDropItemEvent Problem!

Discussion in 'Spigot Plugin Development' started by SirCodalot, Jul 2, 2016.

Thread Status:
Not open for further replies.
  1. I was trying to send a player a message and cancel the PlayerDropItemEvent if the dropped item equals to an ItemStack. I tried in many ways but it seems like it always breaks when I am trying to get the dropped item.

    Note: the Rings.xxxx is an ItemStack.
  2. By the way, configs support booleans.. config.getBoolean()

    This won't work
    Code (Text):

                   if ((event.getItemDrop().getItemStack() == Rings.willPower)
                          || (event.getItemDrop().getItemStack() == Rings.hope)
                          || (event.getItemDrop().getItemStack() == Rings.rage)
                          || (event.getItemDrop().getItemStack() == Rings.fear)
                          || (event.getItemDrop().getItemStack() == Rings.greed)
                          || (event.getItemDrop().getItemStack() ==
                          || (event.getItemDrop().getItemStack() == Rings.compassion)
                          || (event.getItemDrop().getItemStack() == Rings.death)
                          || (event.getItemDrop().getItemStack() == {
    because when you do ==, it is testing if the two things are the exact same thing - as in they are stored in the same place in memory.

    Try using ItemStack#isSimilar.

    EDIT: To clarify further,
    Code (Text):
    new ItemStack(Material.WOOD) == new ItemStack(Material.WOOD);
    returns false because you're asking if two objects you just created are the same one object - we know they are not the same object, because we just now made two separate instances.
    #2 Trophonix, Jul 2, 2016
    Last edited: Jul 2, 2016
    • Like Like x 1
  3. I think @Trophonix is right here
Thread Status:
Not open for further replies.