falkreon / Jankson

JSON5 / HJSON parser and preprocessor which preserves ordering and comments
MIT License
51 stars 9 forks source link

The default value of the config is written to the file multiple times, one for each time I start my mod #75

Closed TechPro424 closed 1 year ago

TechPro424 commented 1 year ago

The default value of the config is written to the file multiple times, one for each time I start my mod Here's my config system: https://gist.github.com/TechPro424/aac4a8f988b13ab0381c1e6295d5fbad

The JsonOperations.loadConfigFromFile(); is called twice, once in my mod's onInitialize() method in the main entrypoint, and in the Config class itself It's called in the mod's onInitialize() method so that any problems/errors with serializing the config can be identified on launch, rather than waiting for the mod's functionality to kick in, and once more in the Config class to store the serialized config in the instance

I don't think this should cause issues, but just in case

TechPro424 commented 1 year ago

Real world example of problem:

{
    "globalBlacklist": [
        "mod_id:item_id",
        "mod_id:item2_id",
        "mod_id:item_id",
        "mod_id:item2_id",
        "mod_id:item_id",
        "mod_id:item2_id",
        "mod_id:item_id",
        "mod_id:item2_id",
        "mod_id:item_id",
        "mod_id:item2_id",
        "minecraft:warped_planks",
        "minecraft:hi",
        "minecraft:b",
        "minecraft:cat"
    ],
    "overworldBlacklist": [],
    "netherBlacklist": [],
    "endBlacklist": []
}

the

"mod_id:item_id",
"mod_id:item2_id"

is added once for each time I start the mod

falkreon commented 1 year ago

Interesting! This looks like a bug that's been here for a very long time, but that no one has noticed.

I peeked at the actual Item-Blacklist repository and it looks like you're using 1.2.2 straight off of maven central, which is :+1:, that's the newest 1.2.x.

I think the surgical solution for me here is to clear the collection here - https://github.com/falkreon/Jankson/blob/java8/src/main/java/blue/endless/jankson/impl/POJODeserializer.java#L233-L242

I just need to give that some thought and make sure there won't be any unusual side effects.

TechPro424 commented 1 year ago

Could you give me a build with this change made so that I can include it in my mod and test it out?

falkreon commented 1 year ago

I'm glad I sat on this - the same issue was present for maps, so I've fixed both! I'll push a GitHub release momentarily that'll work with jitpack. MavenCentral takes longer to replicate, but when it's available it will show up as 1.2.3.

TechPro424 commented 1 year ago

Hey @falkreon Tried out 1.2.3

Now what happens is that the default value is duplicated when I follow the following steps

1) Start the game with my mod 2) Open a world 3) Add something to the blacklist

adding more items to the blacklist subsequently does not cause this, but when I close the game and repeat the above steps, it occurs again