• Type: Bug
    • Resolution: Duplicate
    • Priority: Minor
    • None
    • Affects Version/s: None
    • None

      There seems to be a bug that is caused if a plugin clears a player's inventory when they join the server.

      If a player logs out holding a weapon (e.g. diamond sword), when the log back in they attack with the damage of that weapon even though they don't have it any more. This extra damage is permanent. The only way to undo it is to delete the player's file from the world/playerdata folder.

      I have attached a screenshot of the part of the player's data file that I think may be related to the bug, as well as a test plugin that simply clears a players inventory when they join and broadcasts any damage a player deals to any entity. The plugin jar is attached and here's the source: https://gist.github.com/St3venAU/4747917e1b0bba5afacc

        1. nbt.jpg
          nbt.jpg
          29 kB
        2. TestPlugin.jar
          2 kB

          [SPIGOT-704] Extra damage

          Thijs added a comment -

          @md_5 Please change this bug to Critical and add 1.9.2 to the affected versions.

          Thijs added a comment - @md_5 Please change this bug to Critical and add 1.9.2 to the affected versions.

          Mithrandir added a comment -

          @Thijs U'r not alone dude. This issue is the F* worst cancer that could strike anyones server.

          Mithrandir added a comment - @Thijs U'r not alone dude. This issue is the F* worst cancer that could strike anyones server.

          val59000 added a comment - - edited

          @S3venAU yes there is a difference because this is a pvp logger plugin that has to kill the player, I'm not actually clearing the inventory, I just damage the player and let the server drop the items naturally.

          Anyway, weird bug, weird solution, I've found that if the player pickups a damaging item (a sword, any kind), once he has joined, it "resets" his damage attributes or something like that.
          I'm not sure why it does that but it solved my issue so I'm sharing it here.

          So, you have to give a damaging item (wooden sword here) when the player is fully loaded (50 ticks to be sure), and when the player the you remove it.
          You will see the item going in your inventory bar and remove straight away, but it's not a big deal. If you give a wooden sword it won't be a problem, just make sure you are not giving a diamond sword

          	@EventHandler(priority=EventPriority.HIGHEST)
          	public void onPlayerJoin(PlayerJoinEvent e){
          		Player player = e.getPlayer();
          
          		Bukkit.getScheduler().runTaskLater(getPlugin(), ()->{
          			player.getInventory().addItem(new ItemStack(Material.WOOD_SWORD, 1));
          			player.updateInventory();
          			Bukkit.getScheduler().runTaskLater(getPlugin(), ()->{
          				player.getInventory().remove(new ItemStack(Material.WOOD_SWORD, 1));
          				player.updateInventory();
          			}, 1);
          		}, 50);
          		
          	}
          

          val59000 added a comment - - edited @S3venAU yes there is a difference because this is a pvp logger plugin that has to kill the player, I'm not actually clearing the inventory, I just damage the player and let the server drop the items naturally. Anyway, weird bug, weird solution, I've found that if the player pickups a damaging item (a sword, any kind), once he has joined, it "resets" his damage attributes or something like that. I'm not sure why it does that but it solved my issue so I'm sharing it here. So, you have to give a damaging item (wooden sword here) when the player is fully loaded (50 ticks to be sure), and when the player the you remove it. You will see the item going in your inventory bar and remove straight away, but it's not a big deal. If you give a wooden sword it won't be a problem, just make sure you are not giving a diamond sword @EventHandler(priority=EventPriority.HIGHEST) public void onPlayerJoin(PlayerJoinEvent e){ Player player = e.getPlayer(); Bukkit.getScheduler().runTaskLater(getPlugin(), ()->{ player.getInventory().addItem( new ItemStack(Material.WOOD_SWORD, 1)); player.updateInventory(); Bukkit.getScheduler().runTaskLater(getPlugin(), ()->{ player.getInventory().remove( new ItemStack(Material.WOOD_SWORD, 1)); player.updateInventory(); }, 1); }, 50); }

          St3venAU added a comment -

          @val59000 If you are currently clearing it in the quit event, then change it to clearing within a scheduled task on join instead. I can't see that there will be any functional difference between clearing it when they quit or when they next join.

          St3venAU added a comment - @val59000 If you are currently clearing it in the quit event, then change it to clearing within a scheduled task on join instead. I can't see that there will be any functional difference between clearing it when they quit or when they next join.

          Black Hole added a comment -

          I think this will be never be fixed for 1.8.x, but might already be fixed within 1.9

          Black Hole added a comment - I think this will be never be fixed for 1.8.x, but might already be fixed within 1.9

          val59000 added a comment - - edited

          Ok, upvoted it, I wonder why it is marked as a "minor" bug, it should be "critical", it can ruin any pvp game on any server.

          val59000 added a comment - - edited Ok, upvoted it, I wonder why it is marked as a "minor" bug, it should be "critical", it can ruin any pvp game on any server.

          Mithrandir added a comment -

          @val59000 Upvote this issue.

          Anyone who is experiencing this horrible bug should upvote tis ticket.

          Mithrandir added a comment - @val59000 Upvote this issue. Anyone who is experiencing this horrible bug should upvote tis ticket.

          val59000 added a comment -

          Well I'm not clearing the inventory in the Player join event, this bug happens after I clear the inventory in the player quit event (for a pvp logger plugin).

          val59000 added a comment - Well I'm not clearing the inventory in the Player join event, this bug happens after I clear the inventory in the player quit event (for a pvp logger plugin).

          St3venAU added a comment -

          @val59000 This bug is due to the fact that the onJoin event fires before the player is fully loaded and ready to be modified. Here's how I solved the problem in my plugin. When someones joins, schedule a task for a couple of ticks later and clear the player's inventory in that task (and whatever else I want to do with the player on join).

          St3venAU added a comment - @val59000 This bug is due to the fact that the onJoin event fires before the player is fully loaded and ready to be modified. Here's how I solved the problem in my plugin. When someones joins, schedule a task for a couple of ticks later and clear the player's inventory in that task (and whatever else I want to do with the player on join).

          val59000 added a comment - - edited

          Any news on how to fix that bug ?
          It makes players able to kill other players with armors with only a few hit by hand.

          val59000 added a comment - - edited Any news on how to fix that bug ? It makes players able to kill other players with armors with only a few hit by hand.

            Assignee:
            Unassigned
            Reporter:
            St3venAU
            Votes:
            4 Vote for this issue
            Watchers:
            6 Start watching this issue

              Created:
              Updated:
              Resolved: