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

Player Inventory Content Length and Inventory size mismatch.

XMLWordPrintable

      Cloning an inventory of a player will throw an Illegal Argument exception, as the latest builds of spigot seem to expect a player inventory to be 39 slots, where it is currently 41.

      Example Code:
      {{Inventory original = player.getInventory();
      Inventory cloned = Bukkit.createInventory(null, original.getType());
      System.out.println("Current inventory size: " + original.getSize() + " Type: " + original.getType() + " Default size: " + original.getType().getDefaultSize());
      System.out.println("Original Inventory Type: " + original.getType());
      System.out.println("Cloned Inventory Type: " + cloned.getType());
      System.out.println("Original Inventory Size: " + original.getSize());
      System.out.println("Cloned Inventory Size: " + cloned.getSize());
      System.out.println("Original Content Size: " + original.getContents().length);
      cloned.setContents(original.getContents()); //This line will throw an exception, because original's contents is larger than original's type max size}}

      Output of the above code: {{[21:18:15 INFO]: Current inventory size: 41 Type: PLAYER Default size: 36
      [21:18:15 INFO]: Original Inventory Type: PLAYER
      [21:18:15 INFO]: Cloned Inventory Type: PLAYER
      [21:18:15 INFO]: Original Inventory Size: 41
      [21:18:15 INFO]: Cloned Inventory Size: 36
      [21:18:15 INFO]: Original Content Size: 41
      [21:18:15 ERROR]: Could not pass event InventoryClickEvent to VillagerShop v0.5
      org.bukkit.event.EventException
      at org.bukkit.plugin.java.JavaPluginLoader$1.execute(JavaPluginLoader.java:310) ~[spigot.jar:git-Spigot-dd155ed-3e3516e]
      at org.bukkit.plugin.RegisteredListener.callEvent(RegisteredListener.java:62) ~[spigot.jar:git-Spigot-dd155ed-3e3516e]
      at org.bukkit.plugin.SimplePluginManager.fireEvent(SimplePluginManager.java:502) [spigot.jar:git-Spigot-dd155ed-3e3516e]
      at org.bukkit.plugin.SimplePluginManager.callEvent(SimplePluginManager.java:487) [spigot.jar:git-Spigot-dd155ed-3e3516e]
      at net.minecraft.server.v1_9_R1.PlayerConnection.a(PlayerConnection.java:1815) [spigot.jar:git-Spigot-dd155ed-3e3516e]
      at net.minecraft.server.v1_9_R1.PacketPlayInWindowClick.a(SourceFile:33) [spigot.jar:git-Spigot-dd155ed-3e3516e]
      at net.minecraft.server.v1_9_R1.PacketPlayInWindowClick.a(SourceFile:10) [spigot.jar:git-Spigot-dd155ed-3e3516e]
      at net.minecraft.server.v1_9_R1.PlayerConnectionUtils$1.run(SourceFile:13) [spigot.jar:git-Spigot-dd155ed-3e3516e]
      at java.util.concurrent.Executors$RunnableAdapter.call(Unknown Source) [?:1.8.0_73]
      at java.util.concurrent.FutureTask.run(Unknown Source) [?:1.8.0_73]
      at net.minecraft.server.v1_9_R1.SystemUtils.a(SourceFile:45) [spigot.jar:git-Spigot-dd155ed-3e3516e]
      at net.minecraft.server.v1_9_R1.MinecraftServer.D(MinecraftServer.java:721) [spigot.jar:git-Spigot-dd155ed-3e3516e]
      at net.minecraft.server.v1_9_R1.DedicatedServer.D(DedicatedServer.java:400) [spigot.jar:git-Spigot-dd155ed-3e3516e]
      at net.minecraft.server.v1_9_R1.MinecraftServer.C(MinecraftServer.java:660) [spigot.jar:git-Spigot-dd155ed-3e3516e]
      at net.minecraft.server.v1_9_R1.MinecraftServer.run(MinecraftServer.java:559) [spigot.jar:git-Spigot-dd155ed-3e3516e]
      at java.lang.Thread.run(Unknown Source) [?:1.8.0_73]
      Caused by: java.lang.IllegalArgumentException: Invalid inventory size; expected 36 or less
      at org.bukkit.craftbukkit.v1_9_R1.inventory.CraftInventory.setContents(CraftInventory.java:65) ~[spigot.jar:git-Spigot-dd155ed-3e3516e]
      at net.bplaced.pririor.villagershop.eventHandler.canBuy(eventHandler.java:193) ~[?:?]
      at net.bplaced.pririor.villagershop.eventHandler.onInventoryClick(eventHandler.java:88) ~[?:?]
      at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) ~[?:1.8.0_73]
      at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source) ~[?:1.8.0_73]
      at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source) ~[?:1.8.0_73]
      at java.lang.reflect.Method.invoke(Unknown Source) ~[?:1.8.0_73]
      at org.bukkit.plugin.java.JavaPluginLoader$1.execute(JavaPluginLoader.java:306) ~[spigot.jar:git-Spigot-dd155ed-3e3516e]
      ... 15 more}}

            Unassigned Unassigned
            zack6849 zack6849
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

              Created:
              Updated:
              Resolved: