Item not removing from inventory

Discussion in 'Plugin Development' started by plisov, Aug 20, 2017.

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

    plisov

    I'm trying to make a plugin that will remove an item from a player's inventory when they die and when they respawn give them the item back. Here is the current code.
    Code:
    package me.plisov.saddlehorses;
    
    import java.util.HashMap;
    import java.util.List;
    
    import org.bukkit.ChatColor;
    import org.bukkit.Material;
    import org.bukkit.entity.Player;
    import org.bukkit.event.EventHandler;
    import org.bukkit.event.EventPriority;
    import org.bukkit.event.Listener;
    import org.bukkit.event.entity.PlayerDeathEvent;
    import org.bukkit.event.player.PlayerRespawnEvent;
    import org.bukkit.inventory.ItemStack;
    
    public class PlayerDeath implements Listener {
    
        public HashMap<Player, ItemStack> items = new HashMap<Player, ItemStack>();
    
        @EventHandler
        public void onRespawn(PlayerRespawnEvent event) {
            if (items.containsKey(event.getPlayer())) {
    
                event.getPlayer().getInventory().addItem(items.get(event.getPlayer()));
    
                items.remove(event.getPlayer());
               
                //event.getPlayer().getInventory().clear();
    
            }
        }
    
       
        @EventHandler
        public void onDeath(PlayerDeathEvent event) {
    
            if (event.getEntity() instanceof Player) {
    
                Player player = (Player) event.getEntity();
    
                List<ItemStack> drops = event.getDrops();
    
                for (ItemStack is : drops) {
    
                    if (is.getItemMeta().getDisplayName().equalsIgnoreCase(ChatColor.RED + "Horse Whistle")) {
    
                        player.sendMessage(is.getItemMeta().getDisplayName());
    
                        items.put(player, HorseItem.itemNoPlayer());
    
                        is.setAmount(0);
                    }               
                   
                    if (is.getItemMeta().getDisplayName().contains("Gauge Shotgun")) {
    
                        player.sendMessage(is.getItemMeta().getDisplayName());
    
                        items.put(player, is);
    
                        is.setType(Material.AIR);
                    }
    
                    if (is.getItemMeta().getDisplayName().contains("Carbine Rifle")) {
    
                        player.sendMessage(is.getItemMeta().getDisplayName());
    
                        items.put(player, is);
    
                        is.setType(Material.AIR);
                    }
    
                    if (is.getItemMeta().getDisplayName().contains("Scorpion Revolver")) {
    
                        player.sendMessage(is.getItemMeta().getDisplayName());
    
                        items.put(player, is);
    
                        is.setType(Material.AIR);
                    }
    
                    if (is.getItemMeta().getDisplayName().contains("Lasso")) {
    
                        player.sendMessage(is.getItemMeta().getDisplayName());
    
                        items.put(player, is);
    
                        is.setType(Material.AIR);
                    }
    
                    if (is.getItemMeta().getDisplayName().contains("Musket")) {
    
                        player.sendMessage(is.getItemMeta().getDisplayName());
    
                        items.put(player, is);
    
                        is.setType(Material.AIR);
                    }
    
                    if (is.getItemMeta().getDisplayName().contains("Flintlock Cross-Bow")) {
    
                        player.sendMessage(is.getItemMeta().getDisplayName());
    
                        items.put(player, is);
    
                        is.setType(Material.AIR);
                    }
    
                    if (is.getItemMeta().getDisplayName().contains("Hand Cranked Gatling Gun")) {
    
                        player.sendMessage(is.getItemMeta().getDisplayName());
    
                        items.put(player, is);
    
                        is.setType(Material.AIR);
                    }
                }
            }
        }
    }
    
    It worked fine until I added the plugin <Edit by Moderator: Redacted not allowed paid resource url>

    If you don't know what it is, it basically adds a corpse when a player dies that is then able to be looted.
    What happens now is when the player has an item in their inventory and they die with it, when they respawn, they don't get the item. If you look into the body, the item is in there.

    I need to make the work with it. Is there a way to have the item not show up in the Corpse and have it instead be given to the player when they respawn?

    Any help is much appreciated.
     
    Last edited by a moderator: Feb 9, 2021
  2. Offline

    Zombie_Striker

    @plisov
    Corpses has not been updated since 2015. Try CorpsesReborn:
    <Edit by Moderator: Redacted not allowed paid resource url>

    As for your current issue, it sounds like Corpse's death events are being triggered before yours. Try setting the Priority to HIGHEST for both events and see if that fixes the problem
     
    Last edited by a moderator: Feb 9, 2021
    francisco_gamer1 likes this.
Thread Status:
Not open for further replies.

Share This Page