Survey
* Your assessment is very important for improving the workof artificial intelligence, which forms the content of this project
* Your assessment is very important for improving the workof artificial intelligence, which forms the content of this project
[SPIGOT-2977] Execution Exception, Assertion Error on ItemStack.setAmount() to 0 or removeItem Created: 31/Dec/16 Updated: 01/Jan/17 Resolved: 01/Jan/17 Status: Project: Component/s: Affects Version/s: Fix Version/s: Resolved Spigot None None Type: Reporter: Resolution: Labels: Environment: Bug Minor Priority: Michael Duchesne Unassigned Assignee: Fixed 0 Votes: 1.11.2, API, AssertionError, ExecutionException Runing spigot 1.11.2 (latest build offered by the BuildTools at this time), running the server on a windows 7 pc, running Java 8. Version: This server is running CraftBukkit version git-Spigot-7d78b81-e2a288c (MC: 1.11.2) (Implementing API version 1.11.2-R0.1-SNAPSHOT) None Description So I am developping a plugin using Spigot's api obviously and while I was trying to remove and Item after it being used i run over this exception --------------------------------------------------------------------------------[Server thread/FATAL]: Error executing task java.util.concurrent.ExecutionException: java.lang.AssertionError: TRAP at java.util.concurrent.FutureTask.report(Unknown Source) ~[?:1.8.0_111] at java.util.concurrent.FutureTask.get(Unknown Source) ~[?:1.8.0_111] at net.minecraft.server.v1_11_R1.SystemUtils.a(SourceFile:47) [spigot.jar:git-Spigot-7d78b81e2a288c] at net.minecraft.server.v1_11_R1.MinecraftServer.D(MinecraftServer.java:739) [spigot.jar:gitSpigot-7d78b81-e2a288c] at net.minecraft.server.v1_11_R1.DedicatedServer.D(DedicatedServer.java:399) [spigot.jar:gitSpigot-7d78b81-e2a288c] at net.minecraft.server.v1_11_R1.MinecraftServer.C(MinecraftServer.java:675) [spigot.jar:gitSpigot-7d78b81-e2a288c] at net.minecraft.server.v1_11_R1.MinecraftServer.run(MinecraftServer.java:574) [spigot.jar:git-Spigot-7d78b81-e2a288c] at java.lang.Thread.run(Unknown Source) [?:1.8.0_111] Caused by: java.lang.AssertionError: TRAP at net.minecraft.server.v1_11_R1.ItemStack.F(ItemStack.java:86) ~[spigot.jar:git-Spigot7d78b81-e2a288c] at net.minecraft.server.v1_11_R1.ItemStack.setCount(ItemStack.java:814) ~[spigot.jar:git- Spigot-7d78b81-e2a288c] at net.minecraft.server.v1_11_R1.PlayerInteractManager.a(PlayerInteractManager.java:403) ~[spigot.jar:git-Spigot-7d78b81-e2a288c] at net.minecraft.server.v1_11_R1.PlayerConnection.a(PlayerConnection.java:957) ~[spigot.jar:git-Spigot-7d78b81-e2a288c] at net.minecraft.server.v1_11_R1.PacketPlayInBlockPlace.a(PacketPlayInBlockPlace.java:26) ~[spigot.jar:git-Spigot-7d78b81-e2a288c] at net.minecraft.server.v1_11_R1.PacketPlayInBlockPlace.a(PacketPlayInBlockPlace.java:1) ~[spigot.jar:git-Spigot-7d78b81-e2a288c] at net.minecraft.server.v1_11_R1.PlayerConnectionUtils$1.run(SourceFile:13) ~[spigot.jar:gitSpigot-7d78b81-e2a288c] at java.util.concurrent.Executors$RunnableAdapter.call(Unknown Source) ~[?:1.8.0_111] at java.util.concurrent.FutureTask.run(Unknown Source) ~[?:1.8.0_111] at net.minecraft.server.v1_11_R1.SystemUtils.a(SourceFile:46) ~[spigot.jar:git-Spigot7d78b81-e2a288c] ... 5 more ------------------------------------------------------------------------------------------------It happens after all the things are done, and everything in my code executes sucessfully, so I am guessing it is coming from the API. I am currently running the latest build offered by the BuildTools. Hope it can helps you if it really coming from Spigot, keep up the good work! If you want more details or have any questions feel free to ask! Comments Comment by md_5 [ 01/Jan/17 ] You haven't included your reproduction code. Comment by Michael Duchesne [ 01/Jan/17 ] Yeah sorry totally forgot, I tried to submit quickly before going out. My plugin basically TP player at the destination written on the paper on the fourth line of the lore. When clicked it teleports the player and consumes a "scroll" wich is a piece of paper. Here is my class --------------------------------------------------------------------------------------------------public class Scroll extends ListePoint implements Listener { public Scroll() { } @EventHandler(priority = EventPriority.HIGH) public void scrollActivation(PlayerInteractEvent event) { if (event.getAction().toString().equals(Action.RIGHT_CLICK_AIR.toString())) { ItemStack item = event.getPlayer().getInventory().getItemInMainHand(); if (item.getType() == Material.PAPER && item.getItemMeta().getLore().size() > 2) { Player player = event.getPlayer(); String dest = ChatColor.stripColor(item.getItemMeta().getLore().get(3)); if (isAPoint(dest)) { player.teleport(getLocation(dest)); player.sendMessage("Vous avez été téléporté vers " + ChatColor.AQUA + dest); item.setAmount(item.getAmount() - 1); player.getInventory().setItem(player.getInventory().getHeldItemSlot(), item); } } } } } --------------------------------------------------------------------------------------------So i also forgot to mention that the error only happens when I try to set an ItemStack of size zero or when I use the remove or removeItem method. Otherwise my code is working without any issue as long as the stack size is greater than 0. But from what I remember this code was working fine when I was using Spigot 1.9. Note that even with the error the code executes sucessfully and the paper disapear from my inventory, the error shows up after everything. I also tried to catch it in my class but I was not successful. Comment by md_5 [ 01/Jan/17 ] Minecraft 1.11 changes the way empty item stacks are handled. It sounds like you are trying to set an item stack that is already air to something else, but I can't really tell without a minimal reproduction. Comment by Michael Duchesne [ 01/Jan/17 ] Will you try it or do I need to find how to do it myself? Or could you give me a hint on what to do? Comment by md_5 [ 01/Jan/17 ] It's helpful if you try yourself, maybe just with the set amount code. I'm struggling to see how this issue can arise with the code you have given. Comment by Michael Duchesne [ 01/Jan/17 ] Ok so I made some test. I first of all tried to just set an item stack with the amount of 0, with the remove and removeItem method. I basically registered i command and wrote a little class wich call the different method depending on the first parameter eith pass it. --------------------------------------------------------------------------------public class ClearCommand implements CommandExecutor { public ClearCommand(){} @Override public boolean onCommand(CommandSender sender, Command cmd, String arg, String[] param){ Player player = (Player)sender; ItemStack item = player.getInventory().getItemInMainHand(); //I created a command called "/remove" and here I will try the 3 differents method of removing item depending on the argument you pass //first method set the itemstack to 0 units if (param[0].equals("set")) { item.setAmount(0); player.getInventory().setItem(player.getInventory().getHeldItemSlot(), item); } //second method with the removeve() else if (param[0].equals("remove")) player.getInventory().remove(item); //third method with the removeItem() else if (param[0].equals("removeitem")) player.getInventory().removeItem(item); return true; } } -----------------------------------------------------------------------------------None of them returned an error. Si I then wrote a second class where I had a listener to an interact Event and then removed the inHand item when the event was fired. Here is the class ------------------------------------------------------------------------------------public class ClearItem implements Listener { @EventHandler(priority = EventPriority.HIGH) public void itemActivation(PlayerInteractEvent event) { if (event.getAction().toString().equals(Action.RIGHT_CLICK_AIR.toString())) { Player player = event.getPlayer(); ItemStack item = event.getPlayer().getInventory().getItemInMainHand(); if (item.getType() == Material.PAPER) { item.setAmount(0); player.getInventory().setItem(player.getInventory().getHeldItemSlot(), item); } else if (item.getType() == Material.BRICK) {player.getInventory().remove(item);} else if (item.getType() == Material.BEDROCK) { player.getInventory().removeItem(item); } } } } ----------------------------------------------------------------------------------------------------Again I tested the 3 methods and all of them fired the same error. I hope those simpler class will help you understand the problem, but further than that i do not have the knowledge to help you more. Note that even if I get an error in the console the items have been sucessfully removed from my inventory. I do not think I am doing anything wrong but if the problem comes from I'd like to know how to fix this. Generated at Fri May 12 23:26:15 UTC 2017 using JIRA 7.3.0#73011sha1:3c73d0e0b5ea20e2128531b9adf9b0585752b90a.