From 480ee72e08f6c424bdcb3c96ce1cb94e37d06c05 Mon Sep 17 00:00:00 2001 From: TheBusyBiscuit Date: Mon, 19 Aug 2019 09:17:40 +0200 Subject: [PATCH] Fixes #1009 --- .gitignore | 3 +- .../Slimefun/api/BlockStorage.java | 49 +++++++------------ src/plugin.yml | 2 +- 3 files changed, 22 insertions(+), 32 deletions(-) diff --git a/.gitignore b/.gitignore index b063d2331..d63466cfc 100644 --- a/.gitignore +++ b/.gitignore @@ -4,4 +4,5 @@ /.settings/ *.iml /target -/.idea/ \ No newline at end of file +/.idea/ +dependency-reduced-pom.xml \ No newline at end of file diff --git a/src/me/mrCookieSlime/Slimefun/api/BlockStorage.java b/src/me/mrCookieSlime/Slimefun/api/BlockStorage.java index 6f2eebbb6..8bbe6b6f3 100644 --- a/src/me/mrCookieSlime/Slimefun/api/BlockStorage.java +++ b/src/me/mrCookieSlime/Slimefun/api/BlockStorage.java @@ -19,9 +19,11 @@ import org.bukkit.configuration.file.FileConfiguration; import org.bukkit.configuration.file.YamlConfiguration; import org.bukkit.entity.HumanEntity; import org.bukkit.inventory.ItemStack; -import org.json.simple.JSONObject; -import org.json.simple.parser.JSONParser; -import org.json.simple.parser.ParseException; + +import com.google.gson.JsonElement; +import com.google.gson.JsonObject; +import com.google.gson.JsonParser; +import com.google.gson.JsonPrimitive; import me.mrCookieSlime.CSCoreLibPlugin.Configuration.Config; import me.mrCookieSlime.CSCoreLibPlugin.general.Math.DoubleHandler; @@ -316,20 +318,13 @@ public class BlockStorage { } private static Map parseJSON(String json) { - Map map = new HashMap(); + Map map = new HashMap<>(); if (json != null && json.length() > 2) { - try { - JSONParser parser = new JSONParser(); - JSONObject obj = (JSONObject) parser.parse(json); - for (Object entry: obj.keySet()) { - String key = entry.toString(); - String value = obj.get(entry).toString(); - map.put(key, value); - } - - } catch (ParseException e) { - e.printStackTrace(); + JsonParser parser = new JsonParser(); + JsonObject obj = (JsonObject) parser.parse(json); + for (Map.Entry entry: obj.entrySet()) { + map.put(entry.getKey(), entry.getValue().getAsString()); } } return map; @@ -350,13 +345,12 @@ public class BlockStorage { } } - @SuppressWarnings("unchecked") private static String serializeBlockInfo(Config cfg) { - JSONObject json = new JSONObject(); + JsonObject json = new JsonObject(); for (String key : cfg.getKeys()) { - json.put(key, cfg.getString(key)); + json.add(key, new JsonPrimitive(cfg.getString(key))); } - return json.toJSONString(); + return json.toString(); } private static String getJSONData(Chunk chunk) { return map_chunks.get(serializeChunk(chunk)); @@ -572,7 +566,7 @@ public class BlockStorage { } public static Set getTickingChunks() { - return new HashSet(loaded_tickers); + return new HashSet<>(loaded_tickers); } @Deprecated @@ -586,7 +580,7 @@ public class BlockStorage { @Deprecated public static Set getTickingBlocks(String chunk) { - Set ret = new HashSet(); + Set ret = new HashSet<>(); for (Location l: getTickingLocations(chunk)) { ret.add(l.getBlock()); } @@ -594,7 +588,7 @@ public class BlockStorage { } public static Set getTickingLocations(String chunk) { - return new HashSet(ticking_chunks.get(chunk)); + return new HashSet<>(ticking_chunks.get(chunk)); } public BlockMenu loadInventory(Location l, BlockMenuPreset preset) { @@ -652,10 +646,6 @@ public class BlockStorage { if (!storage.hasInventory(l)) return storage.loadInventory(l, BlockMenuPreset.getPreset(checkID(l))); else return storage.inventories.get(l); } - - public static JSONParser getParser() { - return new JSONParser(); - } public static Config getChunkInfo(Chunk chunk) { try { @@ -684,18 +674,17 @@ public class BlockStorage { return map_chunks.containsKey(serializeChunk(chunk)); } - @SuppressWarnings("unchecked") public static void setChunkInfo(Chunk chunk, String key, String value) { Config cfg = new Config("data-storage/Slimefun/temp.yml"); if (hasChunkInfo(chunk)) cfg = getChunkInfo(chunk); cfg.setValue(key, value); - JSONObject json = new JSONObject(); + JsonObject json = new JsonObject(); for (String path: cfg.getKeys()) { - json.put(path, cfg.getString(path)); + json.add(path, new JsonPrimitive(cfg.getString(path))); } - map_chunks.put(serializeChunk(chunk), json.toJSONString()); + map_chunks.put(serializeChunk(chunk), json.toString()); chunk_changes++; } diff --git a/src/plugin.yml b/src/plugin.yml index fcea0a420..23797f09b 100644 --- a/src/plugin.yml +++ b/src/plugin.yml @@ -7,7 +7,7 @@ website: http://TheBusyBiscuit.github.io/ main: me.mrCookieSlime.Slimefun.SlimefunStartup softdepend: [CS-CoreLib, ClearLag, WorldEdit] -api-version: 1.13 +api-version: 1.14 commands: slimefun: