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

Removing item in hand crashes server

XMLWordPrintable

    • Icon: Bug Bug
    • Resolution: Duplicate
    • Icon: Minor Minor
    • None
    • None
    • None
    • CraftBukkit version git-Spigot-f39a89e-73698cf (MC: 1.15)
    • just my test plugin (RecipeTest)
    • Yes

      I noticed this back on 1.14.x, but always forgot to report this, 
      When setting the item in player's hand to null when using the PlayerInteractEvent crashes the server with this error:

      [21:54:00] [Server thread/ERROR]: Encountered an unexpected exception
      java.lang.AssertionError: TRAP
      	at net.minecraft.server.v1_15_R1.ItemStack.checkEmpty(ItemStack.java:86) ~[spigot-1.15.jar:git-Spigot-f39a89e-73698cf]
      	at net.minecraft.server.v1_15_R1.ItemStack.setCount(ItemStack.java:865) ~[spigot-1.15.jar:git-Spigot-f39a89e-73698cf]
      	at net.minecraft.server.v1_15_R1.ItemStack.add(ItemStack.java:869) ~[spigot-1.15.jar:git-Spigot-f39a89e-73698cf]
      	at net.minecraft.server.v1_15_R1.ItemStack.subtract(ItemStack.java:873) ~[spigot-1.15.jar:git-Spigot-f39a89e-73698cf]
      	at net.minecraft.server.v1_15_R1.ItemBlock.a(ItemBlock.java:64) ~[spigot-1.15.jar:git-Spigot-f39a89e-73698cf]
      	at net.minecraft.server.v1_15_R1.ItemBlock.a(ItemBlock.java:24) ~[spigot-1.15.jar:git-Spigot-f39a89e-73698cf]
      	at net.minecraft.server.v1_15_R1.ItemStack.placeItem(ItemStack.java:161) ~[spigot-1.15.jar:git-Spigot-f39a89e-73698cf]
      	at net.minecraft.server.v1_15_R1.PlayerInteractManager.a(PlayerInteractManager.java:481) ~[spigot-1.15.jar:git-Spigot-f39a89e-73698cf]
      	at net.minecraft.server.v1_15_R1.PlayerConnection.a(PlayerConnection.java:1250) ~[spigot-1.15.jar:git-Spigot-f39a89e-73698cf]
      	at net.minecraft.server.v1_15_R1.PacketPlayInUseItem.a(PacketPlayInUseItem.java:27) ~[spigot-1.15.jar:git-Spigot-f39a89e-73698cf]
      	at net.minecraft.server.v1_15_R1.PacketPlayInUseItem.a(PacketPlayInUseItem.java:1) ~[spigot-1.15.jar:git-Spigot-f39a89e-73698cf]
      	at net.minecraft.server.v1_15_R1.PlayerConnectionUtils.lambda$0(PlayerConnectionUtils.java:19) ~[spigot-1.15.jar:git-Spigot-f39a89e-73698cf]
      	at net.minecraft.server.v1_15_R1.TickTask.run(SourceFile:18) ~[spigot-1.15.jar:git-Spigot-f39a89e-73698cf]
      	at net.minecraft.server.v1_15_R1.IAsyncTaskHandler.executeTask(SourceFile:144) ~[spigot-1.15.jar:git-Spigot-f39a89e-73698cf]
      	at net.minecraft.server.v1_15_R1.IAsyncTaskHandlerReentrant.executeTask(SourceFile:23) ~[spigot-1.15.jar:git-Spigot-f39a89e-73698cf]
      	at net.minecraft.server.v1_15_R1.IAsyncTaskHandler.executeNext(SourceFile:118) ~[spigot-1.15.jar:git-Spigot-f39a89e-73698cf]
      	at net.minecraft.server.v1_15_R1.MinecraftServer.aZ(MinecraftServer.java:917) ~[spigot-1.15.jar:git-Spigot-f39a89e-73698cf]
      	at net.minecraft.server.v1_15_R1.MinecraftServer.executeNext(MinecraftServer.java:910) ~[spigot-1.15.jar:git-Spigot-f39a89e-73698cf]
      	at net.minecraft.server.v1_15_R1.IAsyncTaskHandler.awaitTasks(SourceFile:127) ~[spigot-1.15.jar:git-Spigot-f39a89e-73698cf]
      	at net.minecraft.server.v1_15_R1.MinecraftServer.sleepForTick(MinecraftServer.java:894) ~[spigot-1.15.jar:git-Spigot-f39a89e-73698cf]
      	at net.minecraft.server.v1_15_R1.MinecraftServer.run(MinecraftServer.java:827) [spigot-1.15.jar:git-Spigot-f39a89e-73698cf]
      	at java.lang.Thread.run(Thread.java:748) [?:1.8.0_201]
      

      The code I used to test:

      @EventHandler
      private void onTest(PlayerInteractEvent event) {
          Player player = event.getPlayer();
          if (event.getHand() != EquipmentSlot.HAND) return;
          if (event.getAction() != Action.RIGHT_CLICK_BLOCK) return;
          player.getInventory().setItemInMainHand(null);
      }
      

      If I have a tool (ie: a diamond sword) in my hand, click, everything is find.
      If I have a block (ie: grass block) in my hand, click, the server crashes.

      I included my test plugin to test this out (excuse the name its the same test plugin I use for everything)

      Does this happen on 1.14.4? Yes
      Does this happen in vanilla? Can't test (due to it's a plugin issue)
      Does this happen in CB? Yes, same crash

            Unassigned Unassigned
            ShaneBee Shane Bee
            Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

              Created:
              Updated:
              Resolved: