Coder Social home page Coder Social logo

simplix-softworks / simplixstorage Goto Github PK

View Code? Open in Web Editor NEW
133.0 6.0 26.0 9.12 MB

Library to store data in a better way

License: Apache License 2.0

Java 100.00%
bukkit yaml-files json-files bungeecord nested-objects yml toml fileutils tomlparser lightweight

simplixstorage's Introduction

SimplixStorage

SimplixStorage - A Library to store data in a better way.

Discord GitHub

Overview

Do you want to save your config files easily and independently from Bukkit or BungeeCord?
Want to do more than just use simple .yml files to store data?
Are you looking for a powerful "bukkitlike" (Very similar to Bukkit config) library to store data in files?

Then this library is just right for you.

I was looking for a library that I could use to store data with Bukkit like methods without being depended on Bukkit/BungeeCord. But there was nothing out there, so I decided to write my own library. Of course there are a few libraries with bukkitlike methods but no one has the features that I need. ThunderBolt-2 for example only supports Json files but does not support nested objects. Now I'm publishing this library because I think libraries of high quality should be publicly available for everyone. Now it is here: SimplixStorage!

SimplixStorage is extremely fast & good at storing data reliably!
It also supports nested objects!
Like bukkit it has a contains check. SimplixStorage is licensed under the Apache2 license, which means that you can also use it in private projects that are not open source.

If you have any ideas to add or issues just open a issue page. I will do my best to help.
For more details, see the wiki

Supported data types

At the moment SimplixStorage supports three file types:

Json:

A very fast and slim file format. It is much faster than yaml files and is therefore better suited for storing larger amounts of data, such as player data (rank, money, playtime, etc).

https://stackoverflow.com/questions/2451732/how-is-it-that-json-serialization-is-so-much-faster-than-yaml-serialization-in-p/2452043#2452043

Yaml:

Yaml files are not as fast as json files, but they are easier to read and are therefore more suitable than configuration files, as you often find them in bukkit plugins in the form of "config.yml".

Toml:

Toml is a compromise between the readybility of Yaml and the performance of Json, thus being a quite good way to go.

Library's used:

SimplixStorage uses a powerful combination of libraries to provide the best usability:

MIT-org.json Copyright (c) 2002 JSON.org
YAMLBEANS - Copyright (c) 2008 Nathan Sweet, Copyright (c) 2006 Ola Bini
TOML-Lib - Copyright (c) 2016 Guillaume Raffin.

simplixstorage's People

Contributors

a5h73y avatar croos3r avatar dependabot[bot] avatar dermistkaefer avatar esgibtkeinemitte avatar exceptionflug avatar fabianhick avatar jarfiles avatar kotlinfactory avatar leonardo-dgs avatar magnum97 avatar mindsolve avatar nuckerr avatar olzie-12 avatar yoyosource avatar ytcalifax avatar zeanon avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar

simplixstorage's Issues

Incorrect data type in YAML file on plugin reload with getOrSetDefault()

Describe the bug

  • Upon reloading a server with a plugin using the Yaml configuration, some integer values are rewritten to be strings in that configuration file.
  • Based on my testing, only values retrieved with Yaml#getOrSetDefault() are rewritten, though I cannot 100% verify this

To Reproduce

  1. Open a configuation file with the Yaml class
    Yaml config = new Yaml(new File(getDataFolder(), "config.yml"));
  2. Retrieve any integer value with getOrSetDefault()
    config.getOrSetDefault("test.defaulttest", 1);
  3. If the config option didn't exist before: Observe the correct addition of that value as int:
    test: 
       defaulttest: 1
  4. Restart server/reload plugin
  5. Observe changed value:
    test: 
       defaulttest: '1'

Expected behavior
The configuration value should be saved as integer in the yaml file, and not changed on reload.

Example code

Yaml config = new Yaml(new File(getDataFolder(), "config.yml"));
config.setConfigSettings(ConfigSettings.PRESERVE_COMMENTS);
// unmodified config option
config.set("test.test", 1);
config.setDefault("test.test", 2);
getLogger().info(Integer.toString(config.getInt("test.test")));

// config option that magically transforms
config.getOrSetDefault("test.defaulttest", 1);

Version
(from maven)

com.github.simplix-softworks:SimplixStorage:jar:3.2.2
com.esotericsoftware.yamlbeans:yamlbeans:jar:1.13
org.json:json:jar:20200518

Server
Minecraft: Paper 1.16.5 v662, implementing API 1.16.5-R0.1-SNAPSHOT
Java: Java 11 (OpenJDK 64-Bit Server VM 11.0.11+9) Host: Linux 5.4.106-1-pve (amd64)

Additional context

(1) YAML file after addition of values with code above:

test: 
   test: 1
   defaulttest: 1

(2) YAML file after server restart/plugin reload:

test: 
   test: 1
   defaulttest: '1'

Double dot extension

Describe the bug
When the plugin creates the file add a dot before the extension name for example Rewards.yml became Rewards..yml

To Reproduce
Watch my code.

Expected behavior
Only one dot.

Screenshots

Desktop (please complete the following information):

  • OS: [e.g. iOS]
  • Browser [e.g. chrome, safari]
  • Version [e.g. 22]

Smartphone (please complete the following information):

  • Device: OnePlus 7 Pro
  • OS: OxygenOS 10 Beta 8
  • Browser Opera GX
  • Version I Don't Know

Additional context

Does not save Double

Describe the bug
When you do json.set("Path", value) and pass value as a double, it saves an int to the file instead of a double.

double x = loc.getX();
json.set("Sirens." + openId + ".X", x);

leads to a value in the .json file of -> "X": -9992,
calling json.getDouble("Sirens." + i + ".X") then returns the int instead of a double

Wiki is outdated

Hey, just a fair warning, you might want to update the LightningBuilder to SimplixBuilder in the config

Error when using the reload callback

Describe the bug
When the reload callback is executed, there is throw an error.

To Reproduce
Steps to reproduce the behavior:

  1. With the LightningBuilder set a reload callback and use the FlatFile argument.
  2. When the reload callback is executed, is thrown an Exception

Screenshots
LightningValidationException

Desktop (please complete the following information):

  • OS: Windows
  • Version 10
    Java
  • Version: 17

Additional context
[Server thread/ERROR]: Error occurred while enabling InteractiveBooks v1.5.6 (Is it up to date?) net.leonardo_dgs.interactivebooks.simplixstorage.internal.exceptions.LightningValidationException: FileData mustn't be null at net.leonardo_dgs.interactivebooks.simplixstorage.util.Valid.notNull(Valid.java:36) ~[?:?] at net.leonardo_dgs.interactivebooks.simplixstorage.internal.FlatFile.getFileData(FlatFile.java:341) ~[?:?] at net.leonardo_dgs.interactivebooks.simplixstorage.internal.FlatFile.get(FlatFile.java:142) ~[?:?] at net.leonardo_dgs.interactivebooks.simplixstorage.internal.DataStorage.getOrDefault(DataStorage.java:285) ~[?:?] at net.leonardo_dgs.interactivebooks.simplixstorage.internal.DataStorage.getString(DataStorage.java:113) ~[?:?] at net.leonardo_dgs.interactivebooks.ConfigManager.registerBook(ConfigManager.java:64) ~[?:?] at net.leonardo_dgs.interactivebooks.ConfigManager.lambda$loadBookConfigs$0(ConfigManager.java:55) ~[?:?] at net.leonardo_dgs.interactivebooks.simplixstorage.internal.FlatFile.forceReload(FlatFile.java:291) ~[?:?] at net.leonardo_dgs.interactivebooks.simplixstorage.Yaml.<init>(Yaml.java:101) ~[?:?] at net.leonardo_dgs.interactivebooks.simplixstorage.Config.<init>(Config.java:53) ~[?:?] at net.leonardo_dgs.interactivebooks.simplixstorage.LightningBuilder.createConfig(LightningBuilder.java:128) ~[?:?] at net.leonardo_dgs.interactivebooks.ConfigManager.loadBookConfigs(ConfigManager.java:57) ~[?:?] at net.leonardo_dgs.interactivebooks.ConfigManager.loadAll(ConfigManager.java:30) ~[?:?] at net.leonardo_dgs.interactivebooks.InteractiveBooks.onEnable(InteractiveBooks.java:35) ~[?:?] at org.bukkit.plugin.java.JavaPlugin.setEnabled(JavaPlugin.java:264) ~[spigot-1.17.1.jar:3242-Spigot-6c1c1b2-d3cc412] at org.bukkit.plugin.java.JavaPluginLoader.enablePlugin(JavaPluginLoader.java:342) ~[spigot-1.17.1.jar:3242-Spigot-6c1c1b2-d3cc412] at org.bukkit.plugin.SimplePluginManager.enablePlugin(SimplePluginManager.java:480) ~[spigot-1.17.1.jar:3242-Spigot-6c1c1b2-d3cc412] at org.bukkit.craftbukkit.v1_17_R1.CraftServer.enablePlugin(CraftServer.java:514) ~[spigot-1.17.1.jar:3242-Spigot-6c1c1b2-d3cc412] at org.bukkit.craftbukkit.v1_17_R1.CraftServer.enablePlugins(CraftServer.java:428) ~[spigot-1.17.1.jar:3242-Spigot-6c1c1b2-d3cc412] at net.minecraft.server.MinecraftServer.loadWorld(MinecraftServer.java:619) ~[spigot-1.17.1.jar:3242-Spigot-6c1c1b2-d3cc412] at net.minecraft.server.dedicated.DedicatedServer.init(DedicatedServer.java:266) ~[spigot-1.17.1.jar:3242-Spigot-6c1c1b2-d3cc412] at net.minecraft.server.MinecraftServer.x(MinecraftServer.java:1010) ~[spigot-1.17.1.jar:3242-Spigot-6c1c1b2-d3cc412] at net.minecraft.server.MinecraftServer.lambda$0(MinecraftServer.java:305) ~[spigot-1.17.1.jar:3242-Spigot-6c1c1b2-d3cc412] at java.lang.Thread.run(Thread.java:833) [?:?]

Improve documentation

The documentation seems to be quite outdated, and perhaps, lacking in some places. If you want me to scroll over it and let you know exactly what I think needs updating, please don't be afraid to ask.

I wish to highlight that adding a FAQ (Frequently Asked Questions) page might be very beneficial, covering the questions you are frequently asked - saving you time that would otherwise be spent answering such question ;)

This isn't anything important - just a suggestion from me to improve the resource. Additionally, I would contribute to the Wiki myself if - if I had the knowledge. I've only just got back into using SimplixStorage (last used it when it was named LightningStorage), so I'm quite reliant on the documentation as I learn how to use this resource.

List:

  • Frequently Asked Questions page
  • Real-world examples in the docs

Thanks. :)

The Yaml configs have new lines after each key

Describe the bug
LightningStorage generates a new line character after each Yaml config key and even a space after a section key, it's annoying.
If it is expected, in the API should be added the mentioned styling options.

Code

        Yaml yamlConfig = LightningBuilder
                .fromPath("test.yml", getDataFolder().getPath())
                .setDataType(DataType.SORTED)
                .setConfigSettings(ConfigSettings.PRESERVE_COMMENTS)
                .setReloadSettings(ReloadSettings.MANUALLY)
                .createConfig();


        yamlConfig.addHeader("asdasd", "abbbb");
        yamlConfig.setPathPrefix("taaaa");
        yamlConfig.setDefault("b", "asdsadads");
        yamlConfig.setDefault("a", 32);
        yamlConfig.setDefault("c.a", "tetetetesst");

Config output

taaaa: 

   a: 32

   b: asdsadads

   c: 

      a: tetetetesst

Expected behavior
I expected that Yaml configs would be generated like in the screenshots in the SpigotMC plugin page.

Maven Repository is out of date

Cannot use the latest version because it is not present in the Nexus repository.

I manually browsed the Nexus repository and only up to version 1.9.1 is present.

I can fork the repository and compile install it manually, but that isn't ideal especially since there is a Nexus repository available.

Looking forward to incorporating JSON based storage for GlobalWarming, but would like to see the latest artifacts uploaded. Thanks!

List not stored as expected in Lightning storage file

Describe the bug
LightningStorage file type does not store list correctly

To Reproduce
Steps to reproduce the behavior:

  1. Create String array
  2. Create Lightning file and store array as list
  3. See result:
Method used to create files
private void setupConfig () {
        String string1 = "string";
        String nest1 = "Nested Value";
        String nest2 = "Another nested value";
        String[] list = new String[]{"List item one", "Another item", "The last one, I promise"};
        int ultimateAnswer = 42;
        boolean boo = true;
        Json json = new Json("lightning.json", getDataFolder().toString());
        Yaml yaml = new Yaml("lightning.yaml", getDataFolder().toString());
        Toml toml = new Toml("lightning.toml", getDataFolder().toString());
        LightningFile lightningFile = new LightningFile("lightning.ltn", getDataFolder().toString());
        List <String> header = new ArrayList <String>();

        header.add("This is a header");
        header.add("It supports array list");
        header.add("for multiple line comments.");
        header.add("Only available in YAML");

        json.setDefault("key1", string1);
        json.setDefault("nested.key1", nest1);
        json.setDefault("nested.key2", nest2);
        json.setDefault("next_key", "next_value");
        json.setDefault("the_answer_to_everything", ultimateAnswer);
        json.setDefault("listExample", list);

        yaml.setHeader(header);
        yaml.write();
        yaml.setDefault("key1", string1);
        yaml.setDefault("nested.key1", nest1);
        yaml.setDefault("nested.key2", nest2);
        yaml.setDefault("next_key", "next_value");
        yaml.setDefault("the_answer_to_everything", ultimateAnswer);
        yaml.setDefault("listExample", list);

        toml.setDefault("key1", string1);
        toml.setDefault("nested.key1", nest1);
        toml.setDefault("nested.key2", nest2);
        toml.setDefault("next_key", "next_value");
        toml.setDefault("the_answer_to_everything", ultimateAnswer);
        toml.setDefault("listExample", list);

        lightningFile.setDefault("key1", string1);
        lightningFile.setDefault("nested.key1", nest1);
        lightningFile.setDefault("nested.key2", nest2);
        lightningFile.setDefault("next_key", "next_value");
        lightningFile.setDefault("the_answer_to_everything", ultimateAnswer);
        lightningFile.setDefault("listExample", list);
}
Resulting storage file
key1 = string
nested {
  key1 = Nested Value
  key2 = Another nested value
}
next_key = next_value
the_answer_to_everything = 42
listExample = [Ljava.lang.String;@25288e12

Expected behavior
Strings would be stored, not just a reference to java object.
Also tested with Json, Yaml and Toml with perfect results. I realize this is an array, not a list and is similar to #20 but not quite the same as I am using v3.1.0

Expected results achived with Json, Yaml, & Toml:
{
   "key1": "string",
   "listExample": [
      "List item one",
      "Another item",
      "The last one, I promise"
   ],
   "next_key": "next_value",
   "nested": {
      "key1": "Nested Value",
      "key2": "Another nested value"
   },
   "the_answer_to_everything": 42
}

key1: string
nested: 
   key1: Nested Value
   key2: Another nested value
next_key: next_value
the_answer_to_everything: 42
listExample: 
- List item one
- Another item
- The last one, I promise

key1 = "string"
next_key = "next_value"
the_answer_to_everything = 42
listExample = ["List item one", "Another item", "The last one, I promise", ]

[nested]
key1 = "Nested Value"
key2 = "Another nested value"

Desktop (please complete the following information):

  • OS: Linux 5.3.0-46-generic x86_64 GNU/Linux
  • Browser Chrome
  • Version: 81.0.4044.138-1

Smartphone (please complete the following information):

  • OS: Android
  • Browser: Chrome

Additional context
Add any other context about the problem here.

HOCON config support

Is your feature request related to a problem? Please describe.
It would be useful to make consistent configs for Sponge plugins.

Describe the solution you'd like
Support for HOCON files.

Jar file size reduction.

Is your feature request related to a problem? Please describe.
Jar file size reduction.

Describe the solution you'd like
A jar file size reduced.

Describe alternatives you've considered
None yet.

Example Config files

Hello JavaFactoryDev,
I looked through your code and tried to look at examples for every config format you support. I was thinking about some JSON examples, some YAML examples, some TOML examples and some LightningFile examples. It would help me and some other creators to get some examples and ideas how to use the config files. This would especially be useful for the LightningFile as there is no known documentation I have found.

Regards,

  • yoyosource

Edit-0:
Regards section

Code improvements

  • Custom exception instead of just printing the error
  • Don't use raw types for parametized classess
  • Use Apache's Lang Validator (Because it has a better ide implementation)
  • Code Formatting / Naming is sometimes a bit inconsistent (Throwable e / Throwable ex)
  • Always use the absolute filepath in error messages. Makes debugging a lot simpler

Yaml#addDefaultsFromInputStream messes the order of keys even if the DataType is sorted

Describe the bug
When you use Yaml#addDefaultsFromInputStream, the saved config is no longer ordered, even if you set DataType.SORTED.

To Reproduce
The following code produces an unordered Yaml file.

    private Yaml loadLangConfig(String langCode) {
        File file = new File(langFolder.toPath().toString(), langCode + ".yml");
        Yaml langConfig = SimplixBuilder.fromFile(file)
                .setReloadSettings(ReloadSettings.INTELLIGENT)
                .setDataType(DataType.SORTED)
                .createYaml();

        InputStream resource = getDefaultLangFileStream(langCode);
        if (resource == null) {
            resource = getDefaultLangFileStream(settings.getDefaultLanguage());
            if (resource == null)
                resource = getDefaultLangFileStream("en_us.yml");
        }
        langConfig.addDefaultsFromInputStream(resource);

        return langConfig;
    }

Latest release shows wrong version in maven

Describe the bug
In the latest release(3.2.5), it shows version 3.2.4 instead of 3.2.5

To Reproduce
Steps to reproduce the behavior:

  1. Go to releases
  2. Paste into pom.xml
  3. Error, version 3.2.4 doesn't work anymore, latest is 3.2.5

Expected behavior
Library imports succesfully

See:

com.github.simplix-softworks
SimplixStorage
3.2.4

Version should be 3.2.5

Thanks for maintaining this library. Your work is appreciated

Rethrow exceptions

Is your feature request related to a problem? Please describe.
At the moment we as users of this api cannot act on exceptions thrown within this api since they are already being caught.

Describe the solution you'd like
A clear and concise description of what you want to happen.
Rethrow the exception so we as users of the api can handle them they way we want to.

Describe alternatives you've considered
We'll a different api but without this issue there is no need to.

Additional context
Some examples of internal exception handling within the api
https://github.com/Simplix-Softworks/SimplixStorage/blob/master/src/main/java/de/leonhard/storage/internal/FlatFile.java#L126
https://github.com/Simplix-Softworks/SimplixStorage/blob/master/src/main/java/de/leonhard/storage/internal/FlatFile.java#L282
https://github.com/Simplix-Softworks/SimplixStorage/blob/master/src/main/java/de/leonhard/storage/internal/FlatFile.java#L298

Split code base into modules

Is your feature request related to a problem? Please describe.
Having all the code in one module means even if I am not using something such as the toml class, because its all in one module I have to have it increasing the size of my final jar. I know it's bot much but it would also be cleaner imo

Describe the solution you'd like
Split the project into 5 modules:

  • commons: for classes shared by all the modules such as the FlatFile class
  • yaml: for the Yaml class
  • json: For the json class
  • toml: for thr toml class
  • simplix-config: for the special config class thing

Describe alternatives you've considered
I believe you can remove classes your not using in maven however thats something not all developers know

getLongList returns integerlist?

Describe the bug
getLongList seems to return an integer list?
List<Long> legacy = userdata.getLongList(profile.getPk() + ".followers");
When trying to loop through it i get
Exception in thread "main" java.lang.ClassCastException: java.lang.Integer cannot be cast to java.lang.Long
Here is an example of the list: https://paste.md-5.net/mitokajuni.json
Yes the list is getting returned as is, not empty.

To Reproduce
Steps to reproduce the behavior:
Create a List using #getLongList()
Loop through it using for (long entry : list), throws this error

Expected behavior
it should loop but i think it's casting Integer while creating the loop or something?

Screenshots
N/A

Desktop (please complete the following information):

  • OS: Windows 10
  • Browser Chrome?
  • Version dont know (simplixstorage version 3.2.2)

Additional context
N/A

byte[] can be null

Hello JavaFactoryDev,
I found something in FileUtils where you are throwing this:

throw new IllegalStateException("Can't return null as byte[]");

The comment Can't return null as byte[] is not needed, as I tried in my Java Project (Java Version 12.0.1). I created a Method that expected a byte array as return value and I could just return null.

public byte[] getBytes() {
    return null;
}

I tried this code and my IDE (Intelij IDEA CE) did not warn me that something is wrong. Could it be that you think that byte is a primitive but an array of a primitive is an Object? You can see this in effect while looking at a List<>.

// This does not work as 'byte' is not an Object.
List<byte> bytes = new ArrayList<>();
// This does work because 'byte[]' is a Object.
List<byte[]> bytes = new ArrayList<>();

Edit-0:
What about returning an empty byte array instead of returning null?

Edit-1:
Changed some typos.

Dot in key create problem with FlatFile

Describe the bug
When there is a dot (.) in the key of a valid json (or any other) file like this :

{
	"test" : {
		"test2.test3": "Should work"
	}
} 

FlatFile#get("test.test2.test3") doesn't return anything.

But

{
	"test" : {
		"test2": {
			"test3" : "It works "
		}
	}
} 

Correctly return "It works"

Expected behavior
When the key of a file contains a dot, it should still work.

Desktop (please complete the following information):

  • SimplixStorage: 3.2.6

Toml comments are not preserved

Describe the bug
Toml comments are not preserved when setting a value in an existing commented file.

To Reproduce
Steps to reproduce the behavior:

  1. Create a Toml file with comments
  2. Use a method that changes a value in that file
  3. Lines with comments are replaced with empty lines

Expected behavior
Preservation of comments in Toml files

Screenshots
If applicable, add screenshots to help explain your problem.

Desktop (please complete the following information):

  • OS: Windows
  • Version 10
    Java
  • Version: 17

Need some help

Example i have player storage like this
Low_Scarlet.json

money: 90

Low_Scarlet2.json

money: 99999

Low_Scarlet3.json

money: 0

How to get top money here?

Memory Leaks + Use EntrySet instead KeySet

I have found a little bug:

In de.leonhard.storage.Json at method write() :
The writer was not closed.

And,
In de.leonhard.storage.util.JsonUtils at getJsonFromMap() :
Use Map.Entry (one time loop) instead of KeySet (loop + find)

Request for future updates

hey i wanted to ask if your library will be updated in the future so that you can use it in the future as well

Discord invite invalid

ive been tryin to join your discord for support but all the links seem to be expired or invalid

Does not generate files

Describe the bug
I added the plugin as shown in the images below, but it does not generate any files.
I don't know if it's a bug or if I'm doing something wrong, but I spent a few hours reviewing my gradle settings, and it seems ok.

Screenshots
image
The logs do not appear all, only the "Here 01" when i start the server
image
It seems that it hangs when calling SimplixBuilder and does not start the rest of the plugin
image

Desktop:

  • OS: Windows
  • Version: 11

Desktop:

  • Server: 1.12.2

Another encoding bug

When I reload my server/plugin, the .yml is corrupted

  • My Intellij IDE is in UTF-8:
    image

  • My pom.xml have UTF-8 encodage configuration:
    image

How to reproduce (in my case):

  • I add the defaults value from a HashMap:
    image
    image
    image

The first load the correct encodage, but nexts (re)load corrupt the file
I can't use special character :/

Supporting comments and preserving comments in a file TOML

Is your feature request related to a problem? Please describe.
You could say yes, Yaml for example allows comments in a file and even if there are modifications the comments are kept, but in Toml this is not the case.

Describe the solution you'd like
I suggest that comments should be allowed in a Toml file as in Yaml. There are users that use my plugin that when there is some modification in the configuration as it is a Toml file the comments are lost.

MySQL support

Is your feature request related to a problem? Please describe.
My data files are not synchronized on several servers, or several machines

Describe the solution you'd like
I will find it more comfortable if you can add MySQL support. With the same methods (well almost), it would be really productive to be able to store data from one database and retrieve it from another server. It is a necessity for me, would you say?

Describe alternatives you've considered
You can add support of MySQL database as if they were files

Additional context
This functionality would be in my opinion one more reason to use the library

remove() results in ArrayIndexOutOfBoundsException

Describe the bug
Trying to use remove() to delete a hashmap in a JSON file results in this error:
https://hastebin.com/ovasapukam.sql

To Reproduce
Use remove() on a hashmap in a json file. I have not tested this with other file types or other datatypes.

Expected behavior
I expected this to remove the data from the file.

Desktop (please complete the following information):

  • OS: Windows 10
  • Browser Chrome
  • Version 3.0.0 (Didn't realize that there was a new version, though it doesn't look like it's changed much so it should still be the same. Will test and edit if anything changes upon updating to 3.0.1)

Config(yaml) has broken edit with UTF-8 Characters

Describe the bug
UTF-8 characters get broken and duplicated every time when config(yml) is edited.

To Reproduce
Steps to reproduce the bug:

  1. Add some comments with utf-8 characters
  2. Edit config using set(key, object) method
  3. Open file in Notepad++ or Hex Editor
  4. See broken config

Expected behavior
It should be no corruption of characters when plugin is editing the config file.

Screenshots
image

After edit:
image

Desktop (please complete the following information):

  • OS: [Windows 10]
    Java
  • Version: [ adoptOpenJDK16]

FlatFile#resetPathPrefix

Is your feature request related to a problem? Please describe.
It's bit boring to write setPathPrefix(null) everytime I have to go to my root section using the lib. Moreover I think it's a more elegant way to reset it using a function made for it.

Describe the solution you'd like
Just mapping a new function resetPathPrefix to setPathPrefix(null)

Unsupported class file major version 60 when compiling in java 16

Describe the bug
Whenever I try to compile my 1.17 Bukkit plugin (using java 16), if SimplixStrage is added and shaded, I get the following error while compiling: Unsupported class file major version 60. When I remove it, it compiles fine

To Reproduce
Steps to reproduce the behaviour:

  1. Create a new java 16 project
  2. Add simplix storage
  3. Add relocation
  4. Compile
  5. See error

Expected behavior
It should just build

Screenshots
image

Desktop (please complete the following information):

  • OS: [e.g. Ubuntu] Windows
  • Version [e.g. 18.04] 11 (but it shouldnt make any difference if I was on windows 10)
    Java
  • Version: [e.g. 1.8.0_291] 16

Additional context
This is a paper plugin. And the shade plugin version is 3.2.4

FlatFile sorted and unsorted behavior

Describe the bug
Unsorted and Sorted return both LinkedHashMap internally.

Expected behavior
Have one return HashMap and the other LinkedHashMap

Desktop (please complete the following information):
Current master build

Error when trying to get a list

Describe the bug
When trying to get a list from a yaml file (or any other file like Json), the first time it returns a string with no error, the second time : an error.

To Reproduce
Use this code :

Yaml YamlConfig = new Yaml("config","storagetest");
String [] defaulteffect = {"test1","test2","test3"};
System.out.println(YamlConfig.getOrSetDefault("test", defaulteffect).getClass());

First time the output is : "class [Ljava.lang.String;"
second time :
"java.lang.ClassCastException: java.util.ArrayList cannot be cast to [Ljava.lang.String;"
Expected behavior
Return a String[] containing "test1","test2" and "test3"

Jar download

Hi where can I download the jar of this library?

doubts with the use of the plugin

Hello! I am new to using everything that is Simplix Storage and I have a question, how can I get the data from a file? What I am doing is a constructor to create the configuration files easier, and I create them in my main plugin, but how can I access the config from another class? I would also like you to leave sample codes if possible, but mainly that is my question, since when using String aString = yaml.getString ("Key") ; // Default: "", I don't know how to use it well and also the "yaml" doesn't recognize me, maybe it's an easy question to answer but I don't know what to do, I am waiting for an answer, and thank you very much for reading!
image
Main Class:
image

Certain JSON file(s) still not reloading/updating automatically

Describe the bug
My shops file doesn't seem to be updated automatically even when my accounts file is. Everything works as intended after I either restart the server or do /reload.

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

Expected behavior
Both JSON files should be updated without having to reload the server.

Additional context
JSON file: https://gist.github.com/test414EFF/ffa5a20d23b632db19ce3eaa799281f3

Console spam on removing entries

Describe the bug
When you remove something from storage, there is a console spam.

To Reproduce
Steps to reproduce the behavior:

  1. Remove entry from storage.

Expected behavior
No console output when removing entries from storage.

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

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.

Example files and code

Is your feature request related to a problem? Please describe.
I agree with issue #22 that examples would be helpful.

Describe the solution you'd like
I wrote code to create config files with identical key/value pairs. If you like it I'd be honored if you add it to your wiki, or feel free to change it however you like.

Describe alternatives you've considered
Considered letting someone else do it ^_^

Additional context
Issue #29 will affect the resultant example lightning file.

0001-Add-sample-files-to-FileTypes-wiki-page.patch.gz
0002-Add-example-code-and-file-style-to-Examples-wiki-pag.patch.gz

Minify JSON with method

Is your feature request related to a problem? Please describe.
JSON too large

Describe the solution you'd like
I would like there to be an option to modify the file, i.e. there is no more space, no comments, and everything to be on one line

Describe alternatives you've considered
Remove all space

Comments dissappear when adding defaults.

Describe the bug
When I load/create config, the comments dissappear if I use
.addDefaultsFromInputStream()

Using:
LightningBuilder.fromFile(new File(location, fileName)) .addInputStreamFromResource(fileName) //Optional .setDataType(DataType.SORTED) .setReloadSettings(ReloadSettings.INTELLIGENT) .setConfigSettings(ConfigSettings.PRESERVE_COMMENTS) .createConfig()
Works, but that wouldnt add defaults from my resource file.
So Need to use .addDefaultsFromInputStream(),
But that will remove 90% of the comments. Out of like 100x comments like 4 stay on the file for some reason.

Desktop (please complete the following information):

  • OS: Windows
  • Version 10
    Java
  • Version: 18

[Feature Request] Reload callback

Is your feature request related to a problem? Please describe.
My plugin needs to do something while reloading.
I like auto-reloads, it's smart, but I didn't found some like callback stuff.

Describe the solution you'd like
A clear and concise description of what you want to happen.
Some thing like:

Config config = LightningBuilder.fromFile( FILE ).reloadCallback( (config) -> { /* do something */ }  ).createConfig();

Describe alternatives you've considered
A clear and concise description of any alternative solutions or features you've considered.
nothing

Additional context
Add any other context or screenshots about the feature request here.
nope

getOrSetDefault send message in console

Describe the bug
Everytime I use (in 3.0.5) : getOrSetDefault(), a message of the type of data I got is send in the console.
Like : "OBJ: String T: String"
To Reproduce

Yaml YamlConfig = new Yaml("config","test");
String strengthstring = YamlConfig.getOrSetDefault("test","hey :D");

Expected behavior
Send nothing

NPE when using json created from (final File file) constructor

Describe the bug
An NPE is thrown when you try to use a json created from the (final File file) constructor. This does not happen when using a different constructor. I also tested the (final File file) constructor with yaml and that does work

To Reproduce

Json json = new Json(new File("C:\\some\\path\\test.json"));
json.set("test", 1);
java.lang.reflect.InvocationTargetException
	at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
	at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
	at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
	at java.lang.reflect.Method.invoke(Method.java:498)
	at com.sun.javafx.application.LauncherImpl.launchApplicationWithArgs(LauncherImpl.java:389)
	at com.sun.javafx.application.LauncherImpl.launchApplication(LauncherImpl.java:328)
	at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
	at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
	at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
	at java.lang.reflect.Method.invoke(Method.java:498)
	at sun.launcher.LauncherHelper$FXHelper.main(LauncherHelper.java:767)
Caused by: java.lang.NullPointerException
	at de.leonhard.storage.Json.reload(Json.java:156)
	at de.leonhard.storage.Json.set(Json.java:444)

Can't Modify Json File

Describe the bug
Json files can't be modified because of an input stream not being closed. I believe this input stream is the problem:
https://github.com/JavaFactoryDev/LightningStorage/blob/63a7086cf8cb5f7dc87fdbb69e730455ad07980f/src/main/java/de/leonhard/storage/Json.java#L36
If the input stream does need to constantly stay open can you add a close() method that we can call when we're done with the json so we can modify the file?

To Reproduce
I was specifically testing with deleting the json file which fails since the input stream isnt closed

Json json = new Json("test", "C:\\some\\path\\");
Files.delete(json.getFile().toPath());
Caused by: java.nio.file.FileSystemException: The process cannot access the file because it is being used by another process.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.