Simplix-Softworks / SimplixStorage

Library to store data in a better way
Apache License 2.0
138 stars 25 forks source link

Files don't seem to be reloaded after being written to #24

Closed test414EFF closed 4 years ago

test414EFF commented 4 years ago

Describe the bug I have a plugin that allows players to create shops and bank accounts. When either of these are created, their information is written to a json file so the information can later be accessed by the plugin. When I create a shop, the plugin doesn't seem to be reading an updated version of the file until I reload or restart the server. I can get it to work by using the forceReload() method before opening the GUI, however if I try to do this directly after writing to the file, it doesn't work; this leads me to believe that the issue could be in how I'm accessing the information, but I'm really not sure. The same thing seems to happen with the bank accounts, however, the GUI is updated perfectly fine if I create more accounts after I create one account & reload the server.

I'd also like to mention that, upon opening the file(s) in question, the data is all there, as expected, when these issues occur.

To Reproduce My shop storage class: https://gist.github.com/test414EFF/6656433ce12c8f6e9912c4060393f52a My account storage class: https://gist.github.com/test414EFF/6ac16a978b9b1f6d2939792487564e62

ShopGUI Method: https://gist.github.com/test414EFF/2d048c2a5959605c5fcd1f4c5cc36201 AccountSelector Method: https://gist.github.com/test414EFF/fd68829ab058add44941881627b6eeba

Expected behavior When I access data in a json file through my plugin, I expect the data to be up to date/consistent with what I can see upon opening the file in a text editor.

Version I'm running Lightning Storage 3.0.7.

Additional context I've also tried changing the reload settings to all of the available settings and testing. These seemed to make no difference at all.

KotlinFactory commented 4 years ago

Hey 414Eff,

thank you for reporting this issue here, I will try to reproduce & fix it:)

Regards,

KotlinFactory commented 4 years ago

Hey 414EFF, we have found the bug.

It was a bit weird because it only happened with Maps

However, the bug is fixed with LightningStorage 3.0.8.

Regards,

test414EFF commented 4 years ago

Thank you so much for fixing this, and for all of your hard work on this wonderful library. I was tearing my hair out thinking this was my own fault haha

test414EFF commented 4 years ago

This fixed my bank account system perfect, however the issue still occurs with shops. When I try to open a shop after creating it without reloading or restarting the server first I get this error:

java.lang.NullPointerException: null
    at java.util.HashMap.putMapEntries(HashMap.java:496) ~[?:?]
    at java.util.HashMap.<init>(HashMap.java:485) ~[?:?]
    at cc.modernity.moderneconomy.api.ShopStorage.getShopOwner(ShopStorage.java:24) ~[?:?]
    at cc.modernity.moderneconomy.gui.ShopGUI.openShopGUI(ShopGUI.java:69) ~[?:?]
    at cc.modernity.moderneconomy.gui.ShopGUI.onClick(ShopGUI.java:154) ~[?:?]
    at com.destroystokyo.paper.event.executor.asm.generated.GeneratedEventExecutor19.execute(Unknown Source) ~[?:?]
    at org.bukkit.plugin.EventExecutor.lambda$create$1(EventExecutor.java:69) ~[patched_1.15.2.jar:git-Tuinity-"e2d2b0f"]
    at co.aikar.timings.TimedEventExecutor.execute(TimedEventExecutor.java:80) ~[patched_1.15.2.jar:git-Tuinity-"e2d2b0f"]
    at org.bukkit.plugin.RegisteredListener.callEvent(RegisteredListener.java:70) ~[patched_1.15.2.jar:git-Tuinity-"e2d2b0f"]
    at org.bukkit.plugin.SimplePluginManager.callEvent(SimplePluginManager.java:559) ~[patched_1.15.2.jar:git-Tuinity-"e2d2b0f"]
    at net.minecraft.server.v1_15_R1.PlayerConnection.a(PlayerConnection.java:2333) ~[patched_1.15.2.jar:git-Tuinity-"e2d2b0f"]
    at net.minecraft.server.v1_15_R1.PacketPlayInWindowClick.a(SourceFile:32) ~[patched_1.15.2.jar:git-Tuinity-"e2d2b0f"]
    at net.minecraft.server.v1_15_R1.PacketPlayInWindowClick.a(SourceFile:10) ~[patched_1.15.2.jar:git-Tuinity-"e2d2b0f"]
    at net.minecraft.server.v1_15_R1.PlayerConnectionUtils.lambda$ensureMainThread$0(PlayerConnectionUtils.java:23) ~[patched_1.15.2.jar:git-Tuinity-"e2d2b0f"]
    at net.minecraft.server.v1_15_R1.TickTask.run(SourceFile:18) ~[patched_1.15.2.jar:git-Tuinity-"e2d2b0f"]
    at net.minecraft.server.v1_15_R1.IAsyncTaskHandler.executeTask(IAsyncTaskHandler.java:136) ~[patched_1.15.2.jar:git-Tuinity-"e2d2b0f"]
    at net.minecraft.server.v1_15_R1.IAsyncTaskHandlerReentrant.executeTask(SourceFile:23) ~[patched_1.15.2.jar:git-Tuinity-"e2d2b0f"]
    at net.minecraft.server.v1_15_R1.IAsyncTaskHandler.executeNext(IAsyncTaskHandler.java:109) ~[patched_1.15.2.jar:git-Tuinity-"e2d2b0f"]
    at net.minecraft.server.v1_15_R1.MinecraftServer.ba(MinecraftServer.java:1038) ~[patched_1.15.2.jar:git-Tuinity-"e2d2b0f"]
    at net.minecraft.server.v1_15_R1.MinecraftServer.executeNext(MinecraftServer.java:1031) ~[patched_1.15.2.jar:git-Tuinity-"e2d2b0f"]
    at net.minecraft.server.v1_15_R1.IAsyncTaskHandler.awaitTasks(IAsyncTaskHandler.java:119) ~[patched_1.15.2.jar:git-Tuinity-"e2d2b0f"]
    at net.minecraft.server.v1_15_R1.MinecraftServer.sleepForTick(MinecraftServer.java:1015) ~[patched_1.15.2.jar:git-Tuinity-"e2d2b0f"]
    at net.minecraft.server.v1_15_R1.MinecraftServer.run(MinecraftServer.java:938) ~[patched_1.15.2.jar:git-Tuinity-"e2d2b0f"]
    at java.lang.Thread.run(Thread.java:834) [?:?]

All the relevant code is in the original issue - those are the only classes interacting with Lightning Storage.

KotlinFactory commented 4 years ago

Hey, it seems like there is no key called 'info' in your file. At least the key could not be found in your map.

Btw: To be more safe & even way faster you could just use getString(name + ".info.owner"); for the purpose, you are dealing with. With that, you might end up with an NullPointerException.

P.S. Your post reminded me to mark get() as Nullable & further improve the performance. Thanks:)

Regards,

KotlinFactory commented 4 years ago

However, if this issue still remains we will need to see you YAML-File:)

test414EFF commented 4 years ago

I know there is a key called "info" in the file though - I can see it in the file if I open it and I don't get an error if I reload the server after creating the shop. I suppose I could just do .forceReload() whenever a shop is created but I'm worried that may impact performance.

test414EFF commented 4 years ago

Here's the file as you requested: https://gist.github.com/test414EFF/e70a57ac7ad1d9467bc9f8596daacdeb