[SPIGOT-704] Extra damage Created: 15/Mar/15  Updated: 25/Jun/16  Resolved: 25/Jun/16

Status: Resolved
Project: Spigot
Component/s: None
Affects Version/s: None
Fix Version/s: None

Type: Bug Priority: Minor
Reporter: St3venAU Assignee: Unassigned
Resolution: Duplicate Votes: 4
Labels: None

Attachments: File TestPlugin.jar     JPEG File nbt.jpg    
Issue Links:
Duplicate

 Description   

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



 Comments   
Comment by Thijs [ 07/May/16 ]

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

Comment by Mithrandir [ 03/May/16 ]

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

Comment by val59000 [ 13/Feb/16 ]

@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);
		
	}
Comment by St3venAU [ 13/Feb/16 ]

@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.

Comment by Black Hole [ 13/Feb/16 ]

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

Comment by val59000 [ 13/Feb/16 ]

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.

Comment by Mithrandir [ 13/Feb/16 ]

@val59000 Upvote this issue.

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

Comment by val59000 [ 13/Feb/16 ]

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).

Comment by St3venAU [ 13/Feb/16 ]

@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).

Comment by val59000 [ 12/Feb/16 ]

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.

Comment by Mithrandir [ 23/May/15 ]

Yup, it's fixed by removing that specific NBT file

Comment by Mithrandir [ 23/May/15 ]

This happens to some of my players too (Usually the same players every time, allthough maybe the only ones who actually report the issue, which is actually a benefit for them), I think I've already reported this in the past, and was told that it was fixed, untill today I found out my Moderator had this horrible bug again.

Allthough I don't have a plugin deleting inventories on login, just Authme saving the player's inventory and showing a blank inventory untill you log in.
As there already is this existing report, I won't be opening any tickets myself, but If someone from Spigot thinks it necesary for me to detail my bug's circunstances I will do.

My player is stuck at 4.5 hearts (9 damage) punching damage. So I'm going to try removing the file @St3venAU mentions and see if that helps.

Comment by md_5 [ 15/Mar/15 ]

Lots of things are horribly broken when you do them right onJoin, CraftBukkit has always fired this event too early.

Comment by St3venAU [ 15/Mar/15 ]

Note2: Clearing the player's inventory in a task scheduled for 5 ticks after the PlayerJoinEvent is an effective workaround for this bug.

Comment by St3venAU [ 15/Mar/15 ]

Note that the screenshot from the player's NBT data is from after they have relogged and therefore no longer have the diamond sword.

Generated at Mon Apr 21 21:30:34 UTC 2025 using Jira 10.3.5#10030005-sha1:190c783f2bd6c69cd5accdb70f97e48812a78d14.