Uploaded image for project: 'Spigot'
  1. Spigot
  2. SPIGOT-3364

Cancelling EntityResurrectEvent still keeps the inventory


      If a plugin cancels the EntityResurrectEvent, the player will keep the inventory even thought the world has the keepInventory game rule disabled. The experience is also lost and no experience orb is spawned, so they are completely gone.

      I've attached a test plugin which gives you a totem, random items, experience level and kills you naturally, everything without any permission check or requirement.

      It affects both Spigot and CraftBukkit.

      Test steps:

      • Create a server with the default settings and having only with the provided test plugin
      • Use the /totem command to get a totem and some random items
      • Use the /level command to get 50 levels
      • Use the /killme command to die, make sure to have the totem in your hands

      Expected results:

      Your death should be the same with or without the totem in your hands, so:

      • You should die
      • All your items should drop with velocity
      • Some experience orbs should be spawned, I don't know the exact math behind this.
      • You should see an empty hotbar before you click on respawn
      • You should see the level that you had before your death
      • Your inventory should be empty when you respawn
      • You should not have zero experience when you respawn

      What actually happens:

      The death while holding a totem of undying differs from normal deaths because:

      • No item is dropped
      • No experience orb is spawned
      • You see the items that you had before your death in your hotbar
      • All inventory items is kept on respawn

      Test plugin source code:

      public class TestPlugin extends JavaPlugin implements Listener
          public void onEnable()
              getServer().getPluginManager().registerEvents(this, this);
          public void onEntityResurrectEvent(EntityResurrectEvent event)
          public boolean onCommand(CommandSender sender, Command command, String label, String[] args)
              if(!(sender instanceof Player))
                  return false;
              Player player = (Player) sender;
                  EntityEquipment equipment = player.getEquipment();
                  equipment.setItemInMainHand(new ItemStack(Material.TOTEM));
                  PlayerInventory inventory = player.getInventory();
                  Material[] values = Material.values();
                  Random random = new Random();
                  for (int i = 0; i < 25; i++)
                      Material type = values[random.nextInt(values.length)];
                      inventory.addItem(new ItemStack(type, random.nextInt(type.getMaxStackSize()) + 1));
                  return true;
              else if(command.getName().equalsIgnoreCase("level"))
                  player.setLevel(player.getLevel() + 50);
                  return true;
              else if(command.getName().equalsIgnoreCase("killme"))
                  player.teleport(player.getLocation().add(0, 100, 0));
                  return true;
              else return false;

            Unassigned Unassigned
            joserobjr José Roberto de Araújo Júnior
            0 Vote for this issue
            1 Start watching this issue