Solved Trouble removing dropped item

Discussion in 'Plugin Development' started by Blackwing_Forged, Nov 25, 2017.

Thread Status:
Not open for further replies.
  1. The item doesn't get removed when i drop it


    Code:
    @EventHandler
    public void dropItem(PlayerDropItemEvent e)
    {
            Player p = e.getPlayer();
            ItemStack dropped = e.getItemDrop().getItemStack();
            if(dropped != null && hatItems.earArray.contains(dropped))
            {
                String race = mainClass.raceConfig.getString(p.getUniqueId().toString() + ".Race");
                if(race != null)
                {
                    ItemStack item = mainClass.hatList(race);
                    p.getInventory().setHelmet(item);
                    dropped.setType(Material.AIR);
                }
            }
    }
     
  2. Please post full code.
     
  3. thats the whole event, thats all you need, the mainClass is my main class im using a constructor to reference it
    Main mainClass;
    public Events(Main instance){
    mainClass = instance;
    }
     
  4. Offline

    timtower Administrator Administrator Moderator

  5. @timtower
    Yes the event is registered, no there are no errors, i get the hat back but the item still stays on the ground, and there's nothing wrong with my mainClass or config because i tested it out with more simple code and it does the same thing:


    Code:
    @EventHandler
    public void dropItem(PlayerDropItemEvent e)
        {
            Player p = e.getPlayer();
            ItemStack item = e.getItemDrop().getItemStack();
            if(item != null && item.getType() == Material.STICK)
            {
                p.sendMessage("test");
                ItemStack clone = item.clone();
                p.getInventory().setHelmet(clone);
                item.setType(Material.AIR);
            }
    }
     
    Last edited: Nov 26, 2017
  6. Offline

    Caderape2

    @Blackwing_Forged Probably the getItemStack method return a clone.
    try to remove the item directly. 'e.getItemDrop().remove();'
     
    Blackwing_Forged likes this.
  7. omg :/ i didn't even know that was a method in there called remove, thanks a lot :)
     
  8. @Blackwing_Forged In your compiler if you're using a modern one, if you type "." after a variable it will show the methods that go along with it and you can scroll through.

    You can also look up the Bukkit API
     
  9. @OfficerDeveloper
    i know that :/ i just didn't know a method existed for it and didn't even check
     
Thread Status:
Not open for further replies.

Share This Page