Solved Keep Items after Death..

Discussion in 'Plugin Development' started by ScottGambler, Apr 9, 2013.

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

    ScottGambler

    Hello Guys.

    I need help with a Listener. I don't know what's wrong with my source-code but It won't work.. I need that when a player die, his inventory get's saved in a Hashmap, and when he respawns, he got his stuff and his Armor back.

    Take a look at the source-code:
    Code:
    public final HashMap<String, ItemStack[]> inv = new HashMap<String, ItemStack[]>();
    Code:
    @EventHandler
          public void onDeath(PlayerDeathEvent e) {
            Player player = e.getEntity();
            List<ItemStack> newInventory = new ArrayList<ItemStack>();
                 newInventory.add(player.getInventory().getHelmet());
                 newInventory.add(player.getInventory().getChestplate());
                 newInventory.add(player.getInventory().getLeggings());
                 newInventory.add(player.getInventory().getBoots());
                 newInventory.add(player.getItemInHand());
     
                ItemStack[] newStack =  newInventory.toArray(new ItemStack[newInventory.size()]);
                inv.put(player.getName(), newStack);
                e.getDrops().removeAll(newInventory);
              }
    Code:
        public void onRespawn(PlayerRespawnEvent event) {
            ItemStack[]  newInventory= inv.get(event.getPlayer().getName());
            if (inv.containsKey(event.getPlayer().getName()))
                event.getPlayer().getInventory().setArmorContents(newInventory);
                inv.remove(event.getPlayer());
              }
    Hope anyone can help :)
     
  2. Offline

    pers2981

  3. Offline

    ScottGambler

    Thanks , but this would not repair your Armor. I need to repair it, when someone re spawns..If anyone know what's wrong with my source-code, please let me know.
     
  4. We need to know more than "it won't work"
     
  5. Offline

    ScottGambler

    It don't print an Error, but It also don't give you your inventory if you re-spawn.
     
  6. Adding debug messages is always handy, just log a message to be sure that the events are executing properly.
     
  7. Offline

    ScottGambler

    Oh damn! I forgot to put @EventHandler over the RespawnEvent :mad: It works now...
     
  8. Set to solved.
     
  9. Offline

    ScottGambler

    Yes, I'll do it in a few hours , because i'm now with my IPhone online and I don't know where the Button is :p
     
Thread Status:
Not open for further replies.

Share This Page