CivClassic / Citadel

A Minecraft plugin to protect your chests and builds using in-game materials. Requires an attacker to break each block a certain number of times. Built for Paper 1.16.5
BSD 3-Clause "New" or "Revised" License
1 stars 21 forks source link

Reinforcing crash #28

Closed Maxopoly closed 4 years ago

Maxopoly commented 4 years ago
[23:46:16 INFO]: [Citadel] Eveelution07 created reinforcement with Stone for STONE at Location{world=CraftWorld{name=world},x=-4978.0,y=2.0,z=4328.0,pitch=0.0,yaw=0.0}         
[23:46:16 ERROR]: Encountered an unexpected exception                                                                                                                           
java.lang.AssertionError: TRAP                                                                                                                                                  
        at net.minecraft.server.v1_14_R1.ItemStack.checkEmpty(ItemStack.java:109) ~[patched_1.14.4.jar:git-Paper-243]                                                           
        at net.minecraft.server.v1_14_R1.ItemStack.setCount(ItemStack.java:897) ~[patched_1.14.4.jar:git-Paper-243]                                                             
        at net.minecraft.server.v1_14_R1.ItemStack.add(ItemStack.java:901) ~[patched_1.14.4.jar:git-Paper-243]                                                                  
        at net.minecraft.server.v1_14_R1.ItemStack.subtract(ItemStack.java:905) ~[patched_1.14.4.jar:git-Paper-243]                                                             
        at net.minecraft.server.v1_14_R1.ItemBlock.a(ItemBlock.java:64) ~[patched_1.14.4.jar:git-Paper-243]                                                                     
        at net.minecraft.server.v1_14_R1.ItemBlock.a(ItemBlock.java:24) ~[patched_1.14.4.jar:git-Paper-243]                                                                     
        at net.minecraft.server.v1_14_R1.ItemStack.placeItem(ItemStack.java:185) ~[patched_1.14.4.jar:git-Paper-243]                                                            
        at net.minecraft.server.v1_14_R1.PlayerInteractManager.a(PlayerInteractManager.java:502) ~[patched_1.14.4.jar:git-Paper-243]                                            
        at net.minecraft.server.v1_14_R1.PlayerConnection.a(PlayerConnection.java:1361) ~[?:git-Paper-243]                                                                      
        at net.minecraft.server.v1_14_R1.PacketPlayInUseItem.a(PacketPlayInUseItem.java:27) ~[patched_1.14.4.jar:git-Paper-243]                                                 
        at net.minecraft.server.v1_14_R1.PacketPlayInUseItem.a(PacketPlayInUseItem.java:5) ~[patched_1.14.4.jar:git-Paper-243]                                                  
        at net.minecraft.server.v1_14_R1.PlayerConnectionUtils.lambda$ensureMainThread$0(PlayerConnectionUtils.java:23) ~[patched_1.14.4.jar:git-Paper-243]                     
        at net.minecraft.server.v1_14_R1.TickTask.run(SourceFile:18) ~[patched_1.14.4.jar:git-Paper-243]                                                                        
        at net.minecraft.server.v1_14_R1.IAsyncTaskHandler.executeTask(IAsyncTaskHandler.java:136) ~[patched_1.14.4.jar:git-Paper-243]                                          
        at net.minecraft.server.v1_14_R1.IAsyncTaskHandlerReentrant.executeTask(SourceFile:23) ~[patched_1.14.4.jar:git-Paper-243]                                              
        at net.minecraft.server.v1_14_R1.IAsyncTaskHandler.executeNext(IAsyncTaskHandler.java:109) ~[patched_1.14.4.jar:git-Paper-243]                                          
        at net.minecraft.server.v1_14_R1.MinecraftServer.aX(MinecraftServer.java:1029) ~[patched_1.14.4.jar:git-Paper-243]                                                      
        at net.minecraft.server.v1_14_R1.MinecraftServer.executeNext(MinecraftServer.java:1022) ~[patched_1.14.4.jar:git-Paper-243]                                             
        at net.minecraft.server.v1_14_R1.IAsyncTaskHandler.awaitTasks(IAsyncTaskHandler.java:119) ~[patched_1.14.4.jar:git-Paper-243]                                           
        at net.minecraft.server.v1_14_R1.MinecraftServer.sleepForTick(MinecraftServer.java:1006) ~[patched_1.14.4.jar:git-Paper-243]                                            
        at net.minecraft.server.v1_14_R1.MinecraftServer.run(MinecraftServer.java:929) ~[patched_1.14.4.jar:git-Paper-243]                                                      
        at java.lang.Thread.run(Thread.java:748) [?:1.8.0_252]                        

I suspect creating a reinforcement with only 1 reinforcement item (which you are placing) kills the server,

Protonull commented 4 years ago

Just added a method that might help solve this issue. I don't think the server handles zero (or less) item amounts very well. Indeed I was worried about this when I rewrote OldEnchanting. The method I've added is in this pull request, meaning that would be able to do:

playerInventory.setItemInMainHand(ItemAPI.decrementItem(held))

and the item will automatically be removed should the amount run out, though this is only useful if you know where the item is. However, there's already a way to remove a singular item from an inventory without necessarily needing to know where it is:

ItemStack removing = item.clone();
removing.setAmount(1);
InventoryAPI.safelyRemoveItemsFromInventory(inventory, new ItemStack[] { removing });

It's a bit.. wordy.. and maybe this can be cleaned up, specifically with normalising the remove item and not requiring an array to be made, but it's possible.

The former use case of decrementing held items would likely be used for /ctr while the latter method used for /ctf

Maxopoly commented 4 years ago

Fixed by https://github.com/CivClassic/Citadel/commit/0771c2a7785a04508b52e5eeb92c744a7390c64f

Maxopoly commented 4 years ago

This is still happening

Maxopoly commented 4 years ago

Again caused by

[11:03:13 INFO]: [Citadel] Player created reinforcement with Stone for STONE at Location{world=CraftWorld{name=world},x=X.0,y=X.0,z=X.0,pitch=0.0,yaw=0.0}                                                
[11:03:13 INFO]: [Citadel] Sent Player reply Reinforced at 100% (50/50) health with Stone on Group 0% mature 4 min 59 sec     
Maxopoly commented 4 years ago

Not very helpful issue here: https://hub.spigotmc.org/jira/browse/SPIGOT-3020 Not prevented by newer paper versions: https://github.com/PaperMC/Paper/issues/3904

Dan brought up that it may be caused by double interacts, which sounds solid. Possible solution could be using CMCs DoubleInteractFixer at LOWEST prio on any PlayerInteractEvent during the same tick for the same block. This might have some unintended side effects, but still seems like a preferable solution.

Maxopoly commented 4 years ago

Should be finally fixed by https://github.com/CivClassic/Citadel/commit/00a4bfd34beef63c9119bd23f15267e1775da8e3

crux-f commented 2 years ago

Unfortunately this issue seems to have made a resurgence in 2022; I am getting these crashes when running a vanilla MC /item modify command to decrease the item count by 1 (resulting in a 0 count).

crash-2022-09-04_01.12.00-server.txt crash-2022-09-04_01.48.19-server.txt

Diet-Cola commented 2 years ago

Hi @crux-f

Are you using the latest version of Citadel here?