Solved dropItem is dropping the item twice?

Discussion in 'Plugin Development' started by shohouku, Jan 31, 2020.

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


    edit: so I checked and the event is running twice, why?
    So whenever a entity dies it drops an custom item but the problem is that it's dropping twice, why is that?

    I have two classes:

    This class is the custom item class.

    package items;
    import java.util.ArrayList;
    import java.util.List;
    import org.bukkit.Material;
    import org.bukkit.inventory.ItemStack;
    import org.bukkit.inventory.meta.ItemMeta;
    public class GoblinSword {
        private ItemStack itemStack;
        public void createItem() {
            this.itemStack = Sword();
        public ItemStack Sword() {
            itemStack = new ItemStack(Material.DIAMOND_SWORD, 1);
            ItemMeta meta = itemStack.getItemMeta();
            meta.setDisplayName("Goblin Sword");
            List<String> list = new ArrayList<>();
            list.add("Level 1");
            return itemStack;
        public ItemStack getItemStack() {
            return itemStack;
    I have this in another class with this code:
        public void onGoblinDeath(EntityDeathEvent e) {
            GoblinSword sword = new GoblinSword();
            ItemStack goblinsword = sword.getItemStack();
            if(e.getEntity().getName().equals("Goblin")) {
                e.getEntity().getWorld().dropItemNaturally(e.getEntity().getLocation(), goblinsword);
    Last edited: Jan 31, 2020
  2. Offline


    Did you register the event twice by accident?

    Sent from my LYA-L09 using Tapatalk
  3. Offline


    I only have it registered once.
  4. Offline


    The event is probably firing twice. You can add the entity to a list once the event fires and prevent the event from firing again if they are in the list.

    Sent from my LYA-L09 using Tapatalk
    shohouku likes this.
  5. Offline


  6. Offline


    public void onEnable() {
    getLogger().info("onEnable has been invoked!");     
    getServer().getPluginManager().registerEvents(this, this);
    Bukkit.getServer().getPluginManager().registerEvents(new Goblin(), this);
  7. Offline


    K There's no reason the event fire twice. The error is somewhere else in your code.
    two registration, or another event that do the same job, this is the 2 common case
  8. Offline


    The only code I have is above.

    What kind of list?

    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
    Last edited by a moderator: Jan 31, 2020
  9. Offline

    timtower Administrator Administrator Moderator

    @shohouku Could you post your entire Goblin class?
Thread Status:
Not open for further replies.

Share This Page