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

PlayerDeathEvent.setKeepLevel(false) does not have any affect when the gamrule keepInventory is set to true

XMLWordPrintable

    • This server is running CraftBukkit version 3208-Spigot-18c71bf-97f629b (MC: 1.17.1) (Implementing API version 1.17.1-R0.1-SNAPSHOT)
    • Yes

      I'm working on a plugin that involves setting whether or not a player will keep their inventory and/or XP upon death. Using a listener for PlayerDeathEvent, I am able to successfully do this for the players inventory using PlayerDeathEvent.setKeepInventory(true/false) and originally it worked for XP using PlayerDeathEvent.setKeepLevel(true/false), but upon testing my code when the gamerule keepInventory was set to true, the setKeepInventory method still worked as intended, but setKeepLevel(false) still allows the player to keep their experience after dying. I have worked around this by adding a listener for PlayerRespawnEvent, but it would be much preferable for the setKeepLevel method to work as intended. I have included a test plugin to demonstrate the bug. Its source code is as follows:

      package me.kirkfox.keeplevelbug;
      
      import org.bukkit.event.EventHandler;
      import org.bukkit.event.Listener;
      import org.bukkit.event.entity.PlayerDeathEvent;
      import org.bukkit.plugin.java.JavaPlugin;
      
      public final class KeepLevelBug extends JavaPlugin implements Listener {
      
          @Override
          public void onEnable() {
              getServer().getPluginManager().registerEvents(this, this);
          }
      
          @EventHandler
          public void onPlayerDeath(PlayerDeathEvent e) {
              e.setKeepInventory(false);
              e.setKeepLevel(false);
          }
      }
      

      Simply load the plugin, set the gamerule keepInventory to true, insert items in your inventory and give yourself experience in your experience bar and then kill your player. Upon respawning, the player will have an empty inventory but will still have retained the experience. The intended mechanic is for both the inventory and experience bar to be empty upon death.

            Unassigned Unassigned
            KirkFox Kirk Fox
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

              Created:
              Updated:
              Resolved: