Not dropping certain items on death

Discussion in 'Plugin Development' started by Daffeh, Jul 9, 2016.

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

    Daffeh

    Does anyone know how to prevent certain items from dropping on death?

    I.E. Preventing people from dropping a special sword on death...
     
  2. Offline

    Daffeh

    Well, how do you convert an item stack to an item drop?
     
  3. @Daffeh The drops already are itemstacks
     
  4. Offline

    Daffeh

    I'm sorry, I didn't realize that, by the way, I'm trying to also save the items that aren't being dropped and if I do that along with getting rid of the items that I don't want dropped. An error occurs... It's not a NullPointerException, so that means that it's probably not because I'm grabbing the item drop after I delete it...

    If you wanna see the class that's handling all this here it is:
    Code:
    public class SoulboundDetection implements Listener {
    
        ItemDataStorage ids = new ItemDataStorage();
        Map<UUID, List<ItemStack>> soulbound = new HashMap<UUID, List<ItemStack>>();
        List<ItemStack> soulbounditems = ids.getSoulBoundItems();
    
        @EventHandler
        public void SoulBoundCheck(PlayerDeathEvent e) {
            Player player = e.getEntity();
            List<ItemStack> inventory = e.getDrops();
            List<ItemStack> soulbounditems = new ArrayList<ItemStack>();
          
            for (ItemStack item : inventory) {
                if (item.hasItemMeta()) {
                    if (item.getItemMeta().getLore().contains("Soulbound")) {
                        soulbounditems.add(item);
                    }
                }
            }
          
            soulbound.put(player.getUniqueId(), soulbounditems);
        }
    
        @EventHandler
        public void SoulBoundGive(PlayerRespawnEvent e) {
            Player player = e.getPlayer();
          
            if (soulbound.containsKey(player.getUniqueId())) {
                List<ItemStack> soulboundstuff = soulbound.get(player.getUniqueId());
                for (ItemStack item : soulboundstuff) {
                    player.getInventory().addItem(item);
                }
                soulbound.remove(player.getUniqueId());
            }
          
        }
      
        @EventHandler
        public void noDrop(PlayerDropItemEvent e) {
            for (ItemStack item : soulbounditems) {
                if (item.isSimilar(e.getItemDrop().getItemStack())) {
                    e.getPlayer().sendMessage(ChatColor.DARK_GRAY + "You just can't seem to let go of something this precious...");
                    e.setCancelled(true);
                }
            }
        }
    }
    EDIT: I intentionally didn't put in the drop removal because it was causing errors (as stated above.)
     
  5. @Daffeh You never clear the soul bound items from the drop. Also if 2 people die the first one to respawn will get all their soul bound stuff and the other persons stuff. Look into maps
     
  6. Offline

    Liam Townsley

    Couldn't you save the items you want to keep in an array list?
     
  7. @Liam Townsley He is doing that but what if 2 people die, that's 2 peoples stuff in the list then the first to spawn will hey everything
     
  8. Offline

    Liam Townsley

    EDIT: Well, Hout not killing them make it so when their health is less than 0.01 TP them to their spawn location then removing anything that is not soulbound.
     
  9. ArsenArsen likes this.
  10. Offline

    Liam Townsley

Thread Status:
Not open for further replies.

Share This Page