[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: | Resolved |
| Project: | Spigot |
| Component/s: | None |
| Affects Version/s: | None |
| Fix Version/s: | None |
| Type: | Bug | Priority: | Minor |
| Reporter: | Michael Duchesne | Assignee: | Unassigned |
| Resolution: | Fixed | Votes: | 0 |
| Labels: | 1.11.2, API, AssertionError, ExecutionException | ||
| Environment: |
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. |
||
| 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 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 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; } } ------------------------------------------------------------------------------------ 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); } } } } ----------------------------------------------------------------------------------------------------- I do not think I am doing anything wrong but if the problem comes from I'd like to know how to fix this. |
| 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 ] |
|
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 ] |
|
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 ] |
|
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. Here is my class } @EventHandler(priority = EventPriority.HIGH) 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)); } } } 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 ] |
|
You haven't included your reproduction code. |