Solved Exception problem

Discussion in 'Spigot Plugin Development' started by HireDream, May 3, 2017.

  1. Hello,

    I have an exception when I set item in main hand to AIR on PlayerInteractEvent

    Code (Text):

    ItemStack hand = e.getPlayer().getInventory().getItemInMainHand();
    int amount = hand.getAmount();
    if (amount > 1) {
       hand.setAmount(amount - 1);
       e.getPlayer().getInventory().setItemInMainHand(hand);
    } else {
       e.getPlayer().getInventory().setItemInMainHand(new ItemStack(Material.AIR));
    }
     


    Thank you for your help.


     
  2. What is the exception? Where exactly is it thrown?
     
  3. The exception :

    Code (Text):

    Error executing task
    java.util.concurrent.ExecutionException: java.lang.AssertionError: TRAP
            at java.util.concurrent.FutureTask.report(Unknown Source) ~[?:1.8.0_121]
            at java.util.concurrent.FutureTask.get(Unknown Source) ~[?:1.8.0_121]
            at net.minecraft.server.v1_11_R1.SystemUtils.a(SourceFile:47) [spigot.jar:git-Spigot-54ec0b8-e04a179]
            at net.minecraft.server.v1_11_R1.MinecraftServer.D(MinecraftServer.java:747) [spigot.jar:git-Spigot-54ec0b8-e04a179]
            at net.minecraft.server.v1_11_R1.DedicatedServer.D(DedicatedServer.java:399) [spigot.jar:git-Spigot-54ec0b8-e04a179]
            at net.minecraft.server.v1_11_R1.MinecraftServer.C(MinecraftServer.java:678) [spigot.jar:git-Spigot-54ec0b8-e04a179]
            at net.minecraft.server.v1_11_R1.MinecraftServer.run(MinecraftServer.java:576) [spigot.jar:git-Spigot-54ec0b8-e04a179]
            at java.lang.Thread.run(Unknown Source) [?:1.8.0_121]
    Caused by: java.lang.AssertionError: TRAP
            at net.minecraft.server.v1_11_R1.ItemStack.F(ItemStack.java:94) ~[spigot.jar:git-Spigot-54ec0b8-e04a179]
            at net.minecraft.server.v1_11_R1.ItemStack.setCount(ItemStack.java:822) ~[spigot.jar:git-Spigot-54ec0b8-e04a179]
            at net.minecraft.server.v1_11_R1.PlayerInteractManager.a(PlayerInteractManager.java:403) ~[spigot.jar:git-Spigot-54ec0b8-e04a179]
            at net.minecraft.server.v1_11_R1.PlayerConnection.a(PlayerConnection.java:965) ~[spigot.jar:git-Spigot-54ec0b8-e04a179]
            at net.minecraft.server.v1_11_R1.PacketPlayInBlockPlace.a(PacketPlayInBlockPlace.java:26) ~[spigot.jar:git-Spigot-54ec0b8-e04a179]
            at net.minecraft.server.v1_11_R1.PacketPlayInBlockPlace.a(PacketPlayInBlockPlace.java:1) ~[spigot.jar:git-Spigot-54ec0b8-e04a179]
            at net.minecraft.server.v1_11_R1.PlayerConnectionUtils$1.run(SourceFile:13) ~[spigot.jar:git-Spigot-54ec0b8-e04a179]
            at java.util.concurrent.Executors$RunnableAdapter.call(Unknown Source) ~[?:1.8.0_121]
            at java.util.concurrent.FutureTask.run(Unknown Source) ~[?:1.8.0_121]
            at net.minecraft.server.v1_11_R1.SystemUtils.a(SourceFile:46) ~[spigot.jar:git-Spigot-54ec0b8-e04a179]
            ... 5 more

     
     
  4. Ok, thanks. I believe this is due to Minecraft trying to place the block you have clicked with (which you set to AIR), and because placing air is impossible (by a player), an AssertionError is thrown. Try cancelling the event after setting the item.
     
    • Like Like x 1
  5. Thank you very much, it works perfectly
     
    • Like Like x 1