From 9e38c52f73a5f22f0bf8923e8071abaf355f8711 Mon Sep 17 00:00:00 2001 From: thomas Date: Sat, 8 Jan 2022 13:13:03 +0100 Subject: [PATCH] Fixed json config and moved to 1.14.4 --- dependency-reduced-pom.xml | 137 ++++-------------- pom.xml | 37 +++-- .../api/config/objects/Configuration.java | 1 - .../api/config/objects/JsonConfiguration.java | 82 +++++++++++ 4 files changed, 136 insertions(+), 121 deletions(-) create mode 100644 src/main/java/nl/iobyte/themepark/api/config/objects/JsonConfiguration.java diff --git a/dependency-reduced-pom.xml b/dependency-reduced-pom.xml index f9a8f94..26c2984 100644 --- a/dependency-reduced-pom.xml +++ b/dependency-reduced-pom.xml @@ -23,7 +23,7 @@ maven-shade-plugin - 3.2.0 + 3.2.4 package @@ -33,6 +33,7 @@ + true *:* @@ -50,6 +51,12 @@ + + + com.github.cryptomorin. + nl.iobyte.thirdparty.com.github.cryptomorin. + + @@ -65,7 +72,7 @@ onarandombox - http://repo.onarandombox.com/content/groups/public + https://repo.onarandombox.com/content/groups/public MG-Dev Jenkins CI Maven Repository @@ -80,94 +87,44 @@ org.spigotmc spigot-api - 1.12.2-R0.1-SNAPSHOT + 1.14.4-R0.1-SNAPSHOT provided - - - commons-lang - commons-lang - - - json-simple - com.googlecode.json-simple - - - guava - com.google.guava - - - gson - com.google.code.gson - - - snakeyaml - org.yaml - - - bungeecord-chat - net.md-5 - - me.clip placeholderapi 2.10.9 provided - - - annotations - org.jetbrains - - + + + net.kyori + adventure-text-serializer-bungeecord + 4.0.1 + provided + + + net.kyori + adventure-platform-viaversion + 4.0.1 + provided + + + net.kyori + adventure-platform-facet + 4.0.1 + provided com.bergerkiller.bukkit TrainCarts 1.16.5-v1 provided - - - LightAPI-fork - io.github.qveshn - - - SmoothCoastersAPI - me.m56738 - - - cloud-paper - org.bergerhealer.cloud.commandframework - - - cloud-annotations - org.bergerhealer.cloud.commandframework - - - cloud-minecraft-extras - org.bergerhealer.cloud.commandframework - - - commodore - me.lucko - - - adventure-platform-bukkit - net.kyori - - com.bergerkiller.bukkit BKCommonLib 1.16.5-v1 provided - - - Mountiplex - com.bergerkiller.mountiplex - - com.sk89q.worldguard @@ -186,44 +143,6 @@ worldedit-core 6.1.4-SNAPSHOT provided - - - truezip - de.schlichtherle - - - js - rhino - - - jsr305 - com.google.code.findbugs - - - paranamer - com.thoughtworks.paranamer - - - jlibnoise - com.sk89q.lib - - - jchronic - com.sk89q - - - guava - com.google.guava - - - snakeyaml - org.yaml - - - gson - com.google.code.gson - - diff --git a/pom.xml b/pom.xml index da1894d..29bbfb9 100644 --- a/pom.xml +++ b/pom.xml @@ -25,7 +25,7 @@ onarandombox - http://repo.onarandombox.com/content/groups/public + https://repo.onarandombox.com/content/groups/public MG-Dev Jenkins CI Maven Repository @@ -41,7 +41,7 @@ org.spigotmc spigot-api - 1.12.2-R0.1-SNAPSHOT + 1.14.4-R0.1-SNAPSHOT provided @@ -52,7 +52,7 @@ nl.iobyte menuapi - 1.0 + 1.1 com.zaxxer @@ -66,14 +66,22 @@ provided - com.dumptruckman.minecraft - JsonConfiguration - 1.1 + net.kyori + adventure-text-serializer-bungeecord + 4.0.1 + provided - net.minidev - json-smart - 2.4.7 + net.kyori + adventure-platform-viaversion + 4.0.1 + provided + + + net.kyori + adventure-platform-facet + 4.0.1 + provided com.bergerkiller.bukkit @@ -90,7 +98,7 @@ com.github.cryptomorin XSeries - 8.4.0 + 8.5.0.1 com.sk89q.worldguard @@ -133,8 +141,9 @@ org.apache.maven.plugins maven-shade-plugin - 3.2.0 + 3.2.4 + true *:* @@ -152,6 +161,12 @@ + + + com.github.cryptomorin. + nl.iobyte.thirdparty.com.github.cryptomorin. + + diff --git a/src/main/java/nl/iobyte/themepark/api/config/objects/Configuration.java b/src/main/java/nl/iobyte/themepark/api/config/objects/Configuration.java index 5517925..417d769 100644 --- a/src/main/java/nl/iobyte/themepark/api/config/objects/Configuration.java +++ b/src/main/java/nl/iobyte/themepark/api/config/objects/Configuration.java @@ -1,6 +1,5 @@ package nl.iobyte.themepark.api.config.objects; -import com.dumptruckman.bukkit.configuration.json.JsonConfiguration; import nl.iobyte.themepark.logger.ThemeParkLogger; import org.bukkit.configuration.ConfigurationSection; import org.bukkit.configuration.file.FileConfiguration; diff --git a/src/main/java/nl/iobyte/themepark/api/config/objects/JsonConfiguration.java b/src/main/java/nl/iobyte/themepark/api/config/objects/JsonConfiguration.java new file mode 100644 index 0000000..bab7129 --- /dev/null +++ b/src/main/java/nl/iobyte/themepark/api/config/objects/JsonConfiguration.java @@ -0,0 +1,82 @@ +package nl.iobyte.themepark.api.config.objects; + +import com.google.gson.Gson; +import com.google.gson.GsonBuilder; +import org.apache.commons.lang.Validate; +import org.bukkit.Bukkit; +import org.bukkit.configuration.ConfigurationSection; +import org.bukkit.configuration.InvalidConfigurationException; +import org.bukkit.configuration.file.FileConfiguration; +import org.bukkit.configuration.file.YamlConfiguration; +import org.jetbrains.annotations.NotNull; +import org.yaml.snakeyaml.error.YAMLException; + +import java.io.File; +import java.io.FileNotFoundException; +import java.io.IOException; +import java.util.Map; +import java.util.logging.Level; + +@SuppressWarnings("rawtypes") +public class JsonConfiguration extends FileConfiguration { + + private final Gson gson = new GsonBuilder().setPrettyPrinting().create(); + + @NotNull + @Override + public String saveToString() { + return gson.toJson(this.map); + } + + @Override + public void loadFromString(@NotNull String contents) throws InvalidConfigurationException { + Validate.notNull(contents, "Contents cannot be null"); + + Map input; + try { + input = this.gson.fromJson(contents, Map.class); + } catch (YAMLException var4) { + throw new InvalidConfigurationException(var4); + } catch (ClassCastException var5) { + throw new InvalidConfigurationException("Top level is not a Map."); + } + + if (input != null) { + this.convertMapsToSections(input, this); + } + } + + protected void convertMapsToSections(@NotNull Map input, @NotNull ConfigurationSection section) { + for (Map.Entry entry : input.entrySet()) { + String key = entry.getKey().toString(); + Object value = entry.getValue(); + if (value instanceof Map) { + this.convertMapsToSections((Map) value, section.createSection(key)); + } else { + section.set(key, value); + } + } + + } + + @NotNull + @Override + protected String buildHeader() { + return ""; + } + + @NotNull + public static YamlConfiguration loadConfiguration(@NotNull File file) { + Validate.notNull(file, "File cannot be null"); + YamlConfiguration config = new YamlConfiguration(); + + try { + config.load(file); + } catch (IOException | InvalidConfigurationException var4) { + Bukkit.getLogger().log(Level.SEVERE, "Cannot load " + file, var4); + } + + return config; + } + +}