Magic

Magic

190k Downloads

Inventory bug

christophe6 opened this issue · 18 comments

commented

Hi

We're currently experiencing an inventory bug where people are able to drop their spells. This bug appeared one year ago but we haven't been able to fix this issue during our maintenance. I recently found the code that might be causing the issue. This code prevents players from dropping our Settings menu.

https://hastebin.com/osazuwacar.java

I don't know if this is the code where it all goes wrong but I think it should be. This code works flawlessly with all other plugins. Do you know something to fix it?

Link to the old report: #396

Thanks in advance!

commented

Did you decide if this was due to your code, or do you think there's something in the plugin that needs fixing?

commented

We’re still doing the beta testing of the server but so far the bug didnt appear anymore.

commented

After all this time the server was finally opened. Unfortunately the bug appeared again... We still do not know the issue. Are there any special spigot events we should look out for that might lead to this bug? We’re using a lot of custom plugins but here’s a list of our plugins. Are any of these likely to cause issues with Magic?

https://gyazo.com/062243f5a42138340be101d65e2ba1e5

commented

ADDITION: Would it be possible in case of lag that Player#updateInventory() causes problems?

commented

ADDITION 2:

I found some other code snippets. Could any of these lead to the bug?
public boolean hasActiveSpell(Player player, String spell) { if (!player.isOnline()) return false; for (Spell s : MagicPlugin.getAPI().getMage(player).getActiveSpells()) { if (s.getName().equalsIgnoreCase(spell)) { return true; } } return false; }

and

MagicPlugin.getAPI().getMage(player).getSpell("instabroom").cast();

ADDITION 3: Could it be possible that a couple of very fast repeating tasks lead to the bug?

commented

Player.updateInventory shouldn't be causing issues... I think.

The getAPI().getMage(player) part could be causing an issue if you do it right at login or logout- that could cause the "player data loaded while offline" error you pasted much earlier.

I'm sorry you're hitting this bug again, that is a bummer. It must be some kind of race condition or something else that doesn't happen very often.

Are you able to log any time you call into the Magic API to see if that's the problem? That is assuming it will go along with some other error message... those logs could get overwhelming though, especially if you've got it in a repeating task. I'll try to think how I may be able to help more.

commented

Thanks for your reply. I tried to fix the scheduled task and we are running it live now. I hope this fixes it. Anyway, I found these errors in yesterday's logs.

https://pastebin.com/mAZZSTki
https://pastebin.com/djXphrJQ

commented
commented

That last one looks very specific ... did you add something like welcome_wand: none to your configs?

commented

Yes, I wanted to disable it. What would be the correct way to do it?

commented

It is disabled by default, just leave it out of your configs

commented

For the NullPointerException one, that looks like it might happen if you have disabled all of the wand tweak items (like cyclemode, etc)- and then a player tries to use the progressmenu.

I may need you to share some of your configs, but does that sound familiar. Do you have these wands disabled in wands.yml?

This is just my guess by looking at the error and the code, but not entirely sure. I'm going to put a check in the code for this case, at least.

I don't think any of this is related to the inventory spell dropping issues yet, though.

commented

EDIT: Changed the code snippet to the correct one

commented

is this issue still open?

commented

Of course it is

commented

Seems like your code shouldn't get in the way since it will only prevent players from dropping items.

Do they have to do anything special to drop spells, or do they just drop them as normal?

And just as a completely sanity-check, you don't have allow_spell_dropping: true in config.yml, right?

commented
28.09 17:11:00 [Server] WARN [Magic]  Player data for 6fac5afd-7d5e-47ad-a66b-4dfed710d863 (Grammatica) loaded while offline!
28.09 17:11:00 [Server] WARN java.lang.Exception: Stack trace
28.09 17:11:00 [Server] WARN at java.base/java.lang.Thread.dumpStack(Thread.java:1387)
28.09 17:11:00 [Server] WARN at com.elmakers.mine.bukkit.magic.MagicController.getMage(MagicController.java:355)
28.09 17:11:00 [Server] WARN at com.elmakers.mine.bukkit.magic.MagicController.getMage(MagicController.java:283)
28.09 17:11:00 [Server] WARN at com.elmakers.mine.bukkit.magic.MagicController.getMageFromEntity(MagicController.java:255)
28.09 17:11:00 [Server] WARN at com.elmakers.mine.bukkit.magic.MagicController.getMage(MagicController.java:291)
28.09 17:11:00 [Server] WARN at com.elmakers.mine.bukkit.magic.MagicController.getMage(MagicController.java:306)
28.09 17:11:00 [Server] WARN at com.elmakers.mine.bukkit.magic.MagicPlugin.getMage(MagicPlugin.java:366)
28.09 17:11:00 [Server] WARN at com.christophe6.questutils.BroomCountdown.hasActiveSpell(BroomCountdown.java:77)
28.09 17:11:00 [Server] WARN at com.christophe6.questutils.BroomCountdown$1.run(BroomCountdown.java:63)
28.09 17:11:00 [Server] WARN at org.bukkit.craftbukkit.v1_13_R2.scheduler.CraftTask.run(CraftTask.java:81)
28.09 17:11:00 [Server] WARN at org.bukkit.craftbukkit.v1_13_R2.scheduler.CraftScheduler.mainThreadHeartbeat(CraftScheduler.java:392)
28.09 17:11:00 [Server] WARN at net.minecraft.server.v1_13_R2.MinecraftServer.b(MinecraftServer.java:889)
28.09 17:11:00 [Server] WARN at net.minecraft.server.v1_13_R2.DedicatedServer.b(DedicatedServer.java:417)
28.09 17:11:00 [Server] WARN at net.minecraft.server.v1_13_R2.MinecraftServer.a(MinecraftServer.java:831)
28.09 17:11:00 [Server] WARN at net.minecraft.server.v1_13_R2.MinecraftServer.run(MinecraftServer.java:729)
28.09 17:11:00 [Server] WARN at java.base/java.lang.Thread.run(Thread.java:834)
28.09 17:11:00 [Server] WARN [Magic]  Failed to save wand state for wand to : ItemStack{STICK x 0}

We found this error while looking through the logs. This seems to be in my code and I'll be fixing and testing it soon but I don't know if this is related to the cause of the bug or a consequence of it.

A better description of the bug might be this:

  • You open your wand inventory.
  • You can't leave your wand inventory.
  • You can drop your spells.
  • When you go back to the wand slot and you right click you get your wand back and you also get an infinite spell drop.

Thanks for helping us out!

commented

Hi, I'm sorry for replying so late but I found the solution. We had a custom plugin that included a BukkitRunnable that contained another task. In this code we wanted to cancel the two tasks but it seemed like only one task was canceled in fact. The repeating task was constantly calling upon the Magic API which I think caused the problem. Anyways, thanks for helping me out!