[SPIGOT-1567] getInventory ().setContents () completely wipes inventory clean. Created: 01/Mar/16  Updated: 01/Mar/16  Resolved: 01/Mar/16

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

Type: Bug Priority: Major
Reporter: mibby mibster Assignee: Unassigned
Resolution: Fixed Votes: 0
Labels: 1.9


 Description   

https://hub.spigotmc.org/stash/projects/SPIGOT/repos/craftbukkit/commits/f0c37a16714f54355e9a6a1e61025b435faf6ef6

Inventory restoring is completely broken. Tested two plugins (MobArena & PVPArena) that use 'getInventory ().setContents ()' for restoring former inventory when joining an arena and leaving. Leaving the arena to restore former inventory using setContents completely wipes the inventory clean.

Before the above fix, it outputted an error similar to this.

[16:23:18] [Server thread/WARN]: java.lang.IllegalArgumentException: Invalid inventory size; expected 36 or less
[16:23:18] [Server thread/WARN]: 	at org.bukkit.craftbukkit.v1_9_R1.inventory.CraftInventory.setContents(CraftInventory.java:65)
[16:23:18] [Server thread/WARN]: 	at com.garbagemule.MobArena.util.inventory.InventoryManager.restoreInv(InventoryManager.java:79)
[16:23:18] [Server thread/WARN]: 	at com.garbagemule.MobArena.ArenaImpl.restoreInvAndExp(ArenaImpl.java:1012)
[16:23:18] [Server thread/WARN]: 	at com.garbagemule.MobArena.ArenaImpl.playerLeave(ArenaImpl.java:662)
[16:23:18] [Server thread/WARN]: 	at com.garbagemule.MobArena.commands.user.LeaveCommand.execute(LeaveCommand.java:39)
[16:23:18] [Server thread/WARN]: 	at com.garbagemule.MobArena.commands.CommandHandler.onCommand(CommandHandler.java:91)
[16:23:18] [Server thread/WARN]: 	at org.bukkit.command.PluginCommand.execute(PluginCommand.java:44)
[16:23:18] [Server thread/WARN]: 	at org.bukkit.command.SimpleCommandMap.dispatch(SimpleCommandMap.java:141)
[16:23:18] [Server thread/WARN]: 	at org.bukkit.craftbukkit.v1_9_R1.CraftServer.dispatchCommand(CraftServer.java:645)
[16:23:18] [Server thread/WARN]: 	at net.minecraft.server.v1_9_R1.PlayerConnection.handleCommand(PlayerConnection.java:1302)
[16:23:18] [Server thread/WARN]: 	at net.minecraft.server.v1_9_R1.PlayerConnection.a(PlayerConnection.java:1137)
[16:23:18] [Server thread/WARN]: 	at net.minecraft.server.v1_9_R1.PacketPlayInChat.a(PacketPlayInChat.java:45)
[16:23:18] [Server thread/WARN]: 	at net.minecraft.server.v1_9_R1.PacketPlayInChat.a(PacketPlayInChat.java:1)
[16:23:18] [Server thread/WARN]: 	at net.minecraft.server.v1_9_R1.PlayerConnectionUtils$1.run(SourceFile:13)
[16:23:18] [Server thread/WARN]: 	at java.util.concurrent.Executors$RunnableAdapter.call(Unknown Source)
[16:23:18] [Server thread/WARN]: 	at java.util.concurrent.FutureTask.run(Unknown Source)
[16:23:18] [Server thread/WARN]: 	at net.minecraft.server.v1_9_R1.SystemUtils.a(SourceFile:45)
[16:23:18] [Server thread/WARN]: 	at net.minecraft.server.v1_9_R1.MinecraftServer.D(MinecraftServer.java:716)
[16:23:18] [Server thread/WARN]: 	at net.minecraft.server.v1_9_R1.DedicatedServer.D(DedicatedServer.java:400)
[16:23:18] [Server thread/WARN]: 	at net.minecraft.server.v1_9_R1.MinecraftServer.C(MinecraftServer.java:655)
[16:23:18] [Server thread/WARN]: 	at net.minecraft.server.v1_9_R1.MinecraftServer.run(MinecraftServer.java:554)
[16:23:18] [Server thread/WARN]: 	at java.lang.Thread.run(Unknown Source)

Now it just wipes the inventory when setting, no error. Tested with a full inventory of various items, of various stack sizes.



 Comments   
Comment by mibby mibster [ 01/Mar/16 ]

Confirmed fixed. Thanks.

Comment by mibby mibster [ 01/Mar/16 ]

Here is a debug of the arena trying to add the correct former inventory items back. So the plugin function is fine, the method in spigot is broken?

16.03.01 00:42:48 [INFO] [PA-debug] [p:mibby]67 committing: net.slipcor.pvparena.commands.PAG_Join
16.03.01 00:42:48 [INFO] [PA-debug] [p:mibby]67 perm check.
16.03.01 00:42:48 [INFO] [PA-debug] [p:mibby]67 true
16.03.01 00:42:48 [INFO] [PA-debug] 67 handleJoin!
16.03.01 00:42:48 [INFO] [PA-debug] 67 calculating free team
16.03.01 00:42:48 [INFO] [PA-debug] 67 choosing an empty team
16.03.01 00:42:48 [INFO] [PA-debug] 67 team: Red
16.03.01 00:42:48 [INFO] [PA-debug] 67 team: Blue
16.03.01 00:42:48 [INFO] [PA-debug] 67 empty.size: 2
16.03.01 00:42:48 [INFO] [PA-debug] 68 Added player mibby to team Red
16.03.01 00:42:48 [INFO] [PA-debug] [p:mibby]68 teleporting CraftPlayer{name=mibby} to coord Redlounge
16.03.01 00:42:48 [INFO] [PA-debug] [p:mibby]68 onPlayerTeleport: fighting player 'mibby' (uncancel)
16.03.01 00:42:48 [INFO] [PA-debug] [p:mibby]68 aimed location: Location{world=CraftWorld{name=world},x=1876.5,y=67.5,z=7569.5,pitch=1.0498673,yaw=88.47964}
16.03.01 00:42:48 [INFO] [PA-debug] 70 mibby>LOUNGE
16.03.01 00:42:48 [INFO] [PA-debug] 70 CFG: msg.lounge
16.03.01 00:42:48 [INFO] [PA-debug] 70 @mibby: Welcome to the arena lounge! Hit a class sign and then the iron block to flag yourself as ready!
16.03.01 00:42:48 [INFO] [PA-debug] 70 MSG: MESSAGES_GENERAL
16.03.01 00:42:48 [INFO] [PA-debug] 70 @mibby: You have joined team §4Red§r!
16.03.01 00:42:48 [INFO] [PA-debug] 70 MSG: MESSAGES_GENERAL
16.03.01 00:42:48 [INFO] [PA-debug] 70 CFG: msg.playerjoinedteam
16.03.01 00:42:48 [INFO] [PA-debug] [p:mibby]70 @all/mibby: mibby joined team §4Red§r!
16.03.01 00:42:48 [INFO] [PA-debug] 70 creating PlayerState of mibby
16.03.01 00:42:48 [INFO] [PA-debug] 70 setting health to 20/20
16.03.01 00:42:48 [INFO] [PA-debug] [p:mibby]70 onEntityRegainHealth => fighing player
16.03.01 00:42:48 [INFO] [PA-debug] [p:mibby]70 saving player inventory: mibby
16.03.01 00:42:48 [INFO] [PA-debug] 70 fully clear player inventory: mibby
16.03.01 00:42:48 [INFO] [PA-debug] 70 dumping...
16.03.01 00:42:48 [INFO] [PA-debug] 70 ------------------
16.03.01 00:42:48 [INFO] [PA-debug] 70 Player: mibby
16.03.01 00:42:48 [INFO] [PA-debug] 70 telepass: false | chatting: true
16.03.01 00:42:48 [INFO] [PA-debug] 70 arena: CTF
16.03.01 00:42:48 [INFO] [PA-debug] 70 aClass: null
16.03.01 00:42:48 [INFO] [PA-debug] 70 location: w:world|x:3266.221267769142|y:110.0|z:71.62387187314314|P:30.599903106689453|Y:-7.649660110473633
16.03.01 00:42:48 [INFO] [PA-debug] 70 status: LOUNGE
16.03.01 00:42:48 [INFO] [PA-debug] 71 savedInventory: DIRT:54,REDSTONE:47,GRASS:64,DIRT:50,WOOD:64,SAPLING:64,BEDROCK:64,IRON_ORE,COAL_ORE:64,REDSTONE,REDSTONE,REDSTONE,REDSTONE,REDSTONE,REDSTONE,REDSTONE,REDSTONE,REDSTONE,DIRT,REDSTONE,REDSTONE,REDSTONE,REDSTONE,REDSTONE,REDSTONE,REDSTONE,REDSTONE,DIRT,DIRT,DIRT,DIRT,DIRT,DIRT,DIRT,DIRT,DIRT
16.03.01 00:42:48 [INFO] [PA-debug] 71 savedArmor: AIR
16.03.01 00:42:48 [INFO] [PA-debug] 71 tempPermissions:
16.03.01 00:42:48 [INFO] [PA-debug] 71 ------------------
16.03.01 00:42:48 [INFO] [PA-debug] 71 backing up PlayerState of mibby
16.03.01 00:42:48 [INFO] [PA-debug] [p:mibby]74 choosing player class
16.03.01 00:42:48 [INFO] [PA-debug] [p:mibby]74 checking class perms
16.03.01 00:42:48 [INFO] [PA-debug] 74 fully clear player inventory: mibby
16.03.01 00:42:48 [INFO] [PA-debug] [p:mibby]75 giving items to player 'mibby', class 'Soldier'
16.03.01 00:42:48 [INFO] [PA-debug] 75 Equipping player mibby with items!
16.03.01 00:42:48 [INFO] [PA-debug] 76 - IRON_SWORD|16~1
16.03.01 00:42:48 [INFO] [PA-debug] 76 - IRON_HELMET
16.03.01 00:42:48 [INFO] [PA-debug] 76 - IRON_CHESTPLATE
16.03.01 00:42:48 [INFO] [PA-debug] 76 - IRON_LEGGINGS
16.03.01 00:42:48 [INFO] [PA-debug] 76 - IRON_BOOTS
16.03.01 00:42:48 [INFO] [PA-debug] 76 - POTION~8226~
16.03.01 00:42:48 [INFO] [PA-debug] 76 parseJoin ... 
16.03.01 00:42:48 [INFO] [PA-debug] 76 players having a team: 1
16.03.01 00:42:48 [INFO] [PA-debug] 76 CFG: msg.starting
16.03.01 00:42:50 [INFO] [PA-debug] [p:mibby]118 committing: net.slipcor.pvparena.commands.PAG_Leave
16.03.01 00:42:50 [INFO] [PA-debug] 119 PALeaveEvent
16.03.01 00:42:50 [INFO] [PA-debug] [p:mibby]119 ScoreBoards: remove: mibby
16.03.01 00:42:50 [INFO] [PA-debug] [p:mibby]142 fully removing player from arena
16.03.01 00:42:50 [INFO] [PA-debug] 142 MSG: FIGHT_PLAYER_LEFT
16.03.01 00:42:50 [INFO] [PA-debug] [p:mibby]142 @all/mibby: §4mibby§e has left the fight!
16.03.01 00:42:50 [INFO] [PA-debug] 142 @mibby: You left the arena!
16.03.01 00:42:50 [INFO] [PA-debug] 142 MSG: MESSAGES_GENERAL
16.03.01 00:42:50 [INFO] [PA-debug] [p:mibby]142 removing player mibby, tp to old
16.03.01 00:42:50 [INFO] [PA-debug] [p:mibby]142 resetting player: mibby
16.03.01 00:42:50 [INFO] [PA-debug] 142 restoring PlayerState of mibby
16.03.01 00:42:50 [INFO] [PA-debug] [p:mibby]142 ScoreBoards: remove: mibby
16.03.01 00:42:50 [INFO] [PA-debug] 143 fully clear player inventory: mibby
16.03.01 00:42:50 [INFO] [PA-debug] [p:mibby]143 resetting inventory: mibby
16.03.01 00:42:50 [INFO] [PA-debug] [p:mibby]143 adding DIRT:54,REDSTONE:47,GRASS:64,DIRT:50,WOOD:64,SAPLING:64,BEDROCK:64,IRON_ORE,COAL_ORE:64,REDSTONE,REDSTONE,REDSTONE,REDSTONE,REDSTONE,REDSTONE,REDSTONE,REDSTONE,REDSTONE,DIRT,REDSTONE,REDSTONE,REDSTONE,REDSTONE,REDSTONE,REDSTONE,REDSTONE,REDSTONE,DIRT,DIRT,DIRT,DIRT,DIRT,DIRT,DIRT,DIRT,DIRT
16.03.01 00:42:50 [INFO] [PA-debug] [p:mibby]143 adding AIR
16.03.01 00:42:50 [INFO] [PA-debug] [p:mibby]143 string = old
16.03.01 00:42:50 [INFO] [PA-debug] [p:mibby]143 tping to old
16.03.01 00:42:50 [INFO] [PA-debug] 143 reading loc!
16.03.01 00:42:50 [INFO] [PA-debug] 143 : w:world|x:3266.221267769142|y:110.0|z:71.62387187314314|P:30.599903106689453|Y:-7.649660110473633
16.03.01 00:42:50 [INFO] [PA-debug] [p:mibby]143 location is fine
16.03.01 00:42:50 [INFO] [PA-debug] 143 reading loc!
16.03.01 00:42:50 [INFO] [PA-debug] 143 : w:world|x:3266.221267769142|y:110.0|z:71.62387187314314|P:30.599903106689453|Y:-7.649660110473633
16.03.01 00:42:50 [INFO] [PA-debug] [p:mibby]143 onPlayerTeleport: fighting player 'mibby' (uncancel)
16.03.01 00:42:50 [INFO] [PA-debug] [p:mibby]143 aimed location: Location{world=CraftWorld{name=world},x=3266.221267769142,y=110.0,z=71.62387187314314,pitch=30.599903,yaw=-7.64966}
16.03.01 00:42:50 [INFO] [PA-debug] 143 PAExitEvent
16.03.01 00:42:50 [INFO] [PA-debug] [p:mibby]143 ScoreBoards: remove: mibby
16.03.01 00:42:50 [INFO] [PA-debug] 144 destroying arena player mibby
16.03.01 00:42:50 [INFO] [PA-debug] 144 DEBUG PRINT OUT:
16.03.01 00:42:50 [INFO] [PA-debug] 144 mibby
16.03.01 00:42:50 [INFO] [PA-debug] 145 LOUNGE
16.03.01 00:42:50 [INFO] [PA-debug] 145 null
16.03.01 00:42:50 [INFO] [PA-debug] 145 null
16.03.01 00:42:50 [INFO] [PA-debug] 145 null
16.03.01 00:42:50 [INFO] [PA-debug] 145 clearing PlayerState of mibby
16.03.01 00:42:50 [INFO] [PA-debug] 145 mibby>NULL
Generated at Sat Dec 13 13:34:38 UTC 2025 using Jira 10.3.13#10030013-sha1:56dd970ae30ebfeda3a697d25be1f6388b68a422.