From c5bf0e0cb70e915d401e448edacc05447328fb41 Mon Sep 17 00:00:00 2001 From: CocoTheOwner Date: Fri, 10 Sep 2021 01:35:26 +0200 Subject: [PATCH 1/6] Simplify settings --- .../com/volmit/iris/core/IrisSettings.java | 18 ++---------------- .../com/volmit/iris/engine/IrisEngine.java | 3 +-- src/main/java/com/volmit/iris/util/data/B.java | 2 +- 3 files changed, 4 insertions(+), 19 deletions(-) diff --git a/src/main/java/com/volmit/iris/core/IrisSettings.java b/src/main/java/com/volmit/iris/core/IrisSettings.java index 7e85dc155..14e5d992f 100644 --- a/src/main/java/com/volmit/iris/core/IrisSettings.java +++ b/src/main/java/com/volmit/iris/core/IrisSettings.java @@ -36,7 +36,6 @@ public class IrisSettings { public int configurationVersion = 3; private IrisSettingsCache cache = new IrisSettingsCache(); private IrisSettingsConcurrency concurrency = new IrisSettingsConcurrency(); - private IrisSettingsParallax parallax = new IrisSettingsParallax(); private IrisSettingsGeneral general = new IrisSettingsGeneral(); private IrisSettingsGUI gui = new IrisSettingsGUI(); private IrisSettingsGenerator generator = new IrisSettingsGenerator(); @@ -116,10 +115,6 @@ public class IrisSettings { return getGui().isUseServerLaunchedGuis(); } - public long getParallaxRegionEvictionMS() { - return getParallax().getParallaxRegionEvictionMS(); - } - public void forceSave() { File s = Iris.instance.getDataFile("settings.json"); @@ -139,21 +134,14 @@ public class IrisSettings { @Data public static class IrisSettingsConcurrency { public int parallelism = -1; - } - - @Data - public static class IrisSettingsParallax { - public int parallaxRegionEvictionMS = 15000; - public int parallaxChunkEvictionMS = 5000; + public int parallaxEvictionMS = 10000; } @Data public static class IrisSettingsGeneral { public boolean commandSounds = true; public boolean debug = false; - public boolean ignoreWorldEdit = false; public boolean disableNMS = false; - public boolean keepProductionOnReload = false; public boolean pluginMetrics = true; public boolean splashLogoStartup = true; public boolean autoStartDefaultStudio = false; @@ -165,7 +153,7 @@ public class IrisSettings { public int spinb = 8; public boolean canUseCustomColors(VolmitSender volmitSender) { - return (volmitSender.isPlayer() && useCustomColorsIngame) || (!volmitSender.isPlayer() && useConsoleCustomColors); + return volmitSender.isPlayer() ? useCustomColorsIngame : useConsoleCustomColors; } } @@ -173,14 +161,12 @@ public class IrisSettings { public static class IrisSettingsGUI { public boolean useServerLaunchedGuis = true; public boolean maximumPregenGuiFPS = false; - public boolean localPregenGui = true; } @Data public static class IrisSettingsGenerator { public String defaultWorldType = "overworld"; public boolean headlessPregeneration = false; - public boolean systemEffects = true; public int maxBiomeChildDepth = 4; public boolean preventLeafDecay = true; } diff --git a/src/main/java/com/volmit/iris/engine/IrisEngine.java b/src/main/java/com/volmit/iris/engine/IrisEngine.java index acf789022..887ddd4c2 100644 --- a/src/main/java/com/volmit/iris/engine/IrisEngine.java +++ b/src/main/java/com/volmit/iris/engine/IrisEngine.java @@ -121,8 +121,7 @@ public class IrisEngine implements Engine { bud = new AtomicInteger(0); buds = new AtomicInteger(0); metrics = new EngineMetrics(32); - cleanLatch = new ChronoLatch(Math.max(10000, Math.min(IrisSettings.get().getParallax() - .getParallaxChunkEvictionMS(), IrisSettings.get().getParallax().getParallaxRegionEvictionMS()))); + cleanLatch = new ChronoLatch(Math.max(10000, IrisSettings.get().getConcurrency().getParallaxEvictionMS())); generatedLast = new AtomicInteger(0); perSecond = new AtomicDouble(0); perSecondLatch = new ChronoLatch(1000, false); diff --git a/src/main/java/com/volmit/iris/util/data/B.java b/src/main/java/com/volmit/iris/util/data/B.java index 1c87a4856..c9d6bfdbd 100644 --- a/src/main/java/com/volmit/iris/util/data/B.java +++ b/src/main/java/com/volmit/iris/util/data/B.java @@ -493,7 +493,7 @@ public class B { return null; } - if (bx instanceof Leaves && IrisSettings.get().getGenerator().preventLeafDecay) { + if (bx instanceof Leaves && IrisSettings.get().getGenerator().isPreventLeafDecay()) { ((Leaves) bx).setPersistent(true); } else if (bx instanceof Leaves) { ((Leaves) bx).setPersistent(false); From 620c4087bc8d073563d65107d8fcce08a0538ccb Mon Sep 17 00:00:00 2001 From: CocoTheOwner Date: Fri, 10 Sep 2021 01:36:43 +0200 Subject: [PATCH 2/6] Studio in studio tho --- src/main/java/com/volmit/iris/Iris.java | 2 +- src/main/java/com/volmit/iris/core/IrisSettings.java | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/main/java/com/volmit/iris/Iris.java b/src/main/java/com/volmit/iris/Iris.java index 636dafd35..33f57a4be 100644 --- a/src/main/java/com/volmit/iris/Iris.java +++ b/src/main/java/com/volmit/iris/Iris.java @@ -511,7 +511,7 @@ public class Iris extends VolmitPlugin implements Listener { J.a(this::verifyDataPacksPost, 20); splash(); - if (IrisSettings.get().getGeneral().isAutoStartDefaultStudio()) { + if (IrisSettings.get().getStudio().isAutoStartDefaultStudio()) { Iris.info("Starting up auto Studio!"); try { Player r = new KList<>(getServer().getOnlinePlayers()).getRandom(); diff --git a/src/main/java/com/volmit/iris/core/IrisSettings.java b/src/main/java/com/volmit/iris/core/IrisSettings.java index 14e5d992f..905b4db91 100644 --- a/src/main/java/com/volmit/iris/core/IrisSettings.java +++ b/src/main/java/com/volmit/iris/core/IrisSettings.java @@ -144,7 +144,6 @@ public class IrisSettings { public boolean disableNMS = false; public boolean pluginMetrics = true; public boolean splashLogoStartup = true; - public boolean autoStartDefaultStudio = false; public boolean useConsoleCustomColors = true; public boolean useCustomColorsIngame = true; public String forceMainWorld = ""; @@ -176,5 +175,6 @@ public class IrisSettings { public boolean studio = true; public boolean openVSCode = true; public boolean disableTimeAndWeather = true; + public boolean autoStartDefaultStudio = false; } } From 5d5b8b78d430b7e314c02899a2089c38fd27598b Mon Sep 17 00:00:00 2001 From: CocoTheOwner Date: Fri, 10 Sep 2021 02:09:58 +0200 Subject: [PATCH 3/6] Remove little-used shortcuts, check config version --- .../com/volmit/iris/core/IrisSettings.java | 151 ++++++++---------- .../iris/core/commands/CommandStudio.java | 2 +- .../decree/virtual/VirtualDecreeCommand.java | 4 +- 3 files changed, 66 insertions(+), 91 deletions(-) diff --git a/src/main/java/com/volmit/iris/core/IrisSettings.java b/src/main/java/com/volmit/iris/core/IrisSettings.java index 905b4db91..b6f2b508f 100644 --- a/src/main/java/com/volmit/iris/core/IrisSettings.java +++ b/src/main/java/com/volmit/iris/core/IrisSettings.java @@ -34,101 +34,18 @@ import java.io.IOException; public class IrisSettings { public static transient IrisSettings settings; public int configurationVersion = 3; - private IrisSettingsCache cache = new IrisSettingsCache(); private IrisSettingsConcurrency concurrency = new IrisSettingsConcurrency(); private IrisSettingsGeneral general = new IrisSettingsGeneral(); private IrisSettingsGUI gui = new IrisSettingsGUI(); private IrisSettingsGenerator generator = new IrisSettingsGenerator(); private IrisSettingsStudio studio = new IrisSettingsStudio(); - public static int getPriority(int c) { - return Math.max(Math.min(c, Thread.MAX_PRIORITY), Thread.MIN_PRIORITY); - } - public static int getThreadCount(int c) { - if (c < 2 && c >= 0) { - return 2; - } - - return Math.max(2, c < 0 ? Runtime.getRuntime().availableProcessors() / -c : c); - } - - public static IrisSettings get() { - if (settings != null) { - return settings; - } - - IrisSettings defaults = new IrisSettings(); - JSONObject def = new JSONObject(new Gson().toJson(defaults)); - if (settings == null) { - settings = new IrisSettings(); - - File s = Iris.instance.getDataFile("settings.json"); - - if (!s.exists()) { - try { - IO.writeAll(s, new JSONObject(new Gson().toJson(settings)).toString(4)); - } catch (JSONException | IOException e) { - e.printStackTrace(); - Iris.reportError(e); - } - } else { - try { - String ss = IO.readAll(s); - settings = new Gson().fromJson(ss, IrisSettings.class); - try { - IO.writeAll(s, new JSONObject(new Gson().toJson(settings)).toString(4)); - } catch (IOException e) { - e.printStackTrace(); - } - } catch (Throwable ee) { - Iris.reportError(ee); - Iris.error("Configuration Error in settings.json! " + ee.getClass().getSimpleName() + ": " + ee.getMessage()); - } - } - - if (!s.exists()) { - try { - IO.writeAll(s, new JSONObject(new Gson().toJson(settings)).toString(4)); - } catch (JSONException | IOException e) { - Iris.reportError(e); - e.printStackTrace(); - } - } - } - - return settings; - } - - public static void invalidate() { - synchronized (settings) { - settings = null; - } - } - - public boolean isStudio() { - return getStudio().isStudio(); - } - - @SuppressWarnings("BooleanMethodIsAlwaysInverted") - public boolean isUseServerLaunchedGuis() { - return getGui().isUseServerLaunchedGuis(); - } - - public void forceSave() { - File s = Iris.instance.getDataFile("settings.json"); - - try { - IO.writeAll(s, new JSONObject(new Gson().toJson(settings)).toString(4)); - } catch (JSONException | IOException e) { - e.printStackTrace(); - Iris.reportError(e); - } - } - - @Data - public static class IrisSettingsCache { - public int complexCacheSize = 131072; + return switch (c) { + case -1, -2, -4 -> Runtime.getRuntime().availableProcessors() / -c; + case 0, 1, 2 -> 1; + default -> Math.max(c, 2); + }; } @Data @@ -151,6 +68,7 @@ public class IrisSettings { public int spins = 7; public int spinb = 8; + @SuppressWarnings("BooleanMethodIsAlwaysInverted") public boolean canUseCustomColors(VolmitSender volmitSender) { return volmitSender.isPlayer() ? useCustomColorsIngame : useConsoleCustomColors; } @@ -177,4 +95,61 @@ public class IrisSettings { public boolean disableTimeAndWeather = true; public boolean autoStartDefaultStudio = false; } + + public static IrisSettings get() { + if (settings != null) { + return settings; + } + + settings = new IrisSettings(); + + File s = Iris.instance.getDataFile("settings.json"); + + if (!s.exists()) { + try { + IO.writeAll(s, new JSONObject(new Gson().toJson(settings)).toString(4)); + } catch (JSONException | IOException e) { + e.printStackTrace(); + Iris.reportError(e); + } + } else { + try { + String ss = IO.readAll(s); + settings = new Gson().fromJson(ss, IrisSettings.class); + try { + IO.writeAll(s, new JSONObject(new Gson().toJson(settings)).toString(4)); + } catch (IOException e) { + e.printStackTrace(); + } + } catch (Throwable ee) { + Iris.reportError(ee); + Iris.error("Configuration Error in settings.json! " + ee.getClass().getSimpleName() + ": " + ee.getMessage()); + } + } + + if (settings.getConfigurationVersion() != new IrisSettings().getConfigurationVersion()) { + Iris.error("Existing configuration's version does not match current configuration version! Resetting..."); + settings = new IrisSettings(); + settings.forceSave(); + } + + return settings; + } + + public static void invalidate() { + synchronized (settings) { + settings = null; + } + } + + public void forceSave() { + File s = Iris.instance.getDataFile("settings.json"); + + try { + IO.writeAll(s, new JSONObject(new Gson().toJson(settings)).toString(4)); + } catch (JSONException | IOException e) { + e.printStackTrace(); + Iris.reportError(e); + } + } } diff --git a/src/main/java/com/volmit/iris/core/commands/CommandStudio.java b/src/main/java/com/volmit/iris/core/commands/CommandStudio.java index e6682f17b..46ceb342c 100644 --- a/src/main/java/com/volmit/iris/core/commands/CommandStudio.java +++ b/src/main/java/com/volmit/iris/core/commands/CommandStudio.java @@ -909,7 +909,7 @@ public class CommandStudio implements DecreeExecutor { * @return true if server GUIs are not enabled */ private boolean noGUI() { - if (!IrisSettings.get().isUseServerLaunchedGuis()) { + if (!IrisSettings.get().getGui().isUseServerLaunchedGuis()) { sender().sendMessage(C.RED + "You must have server launched GUIs enabled in the settings!"); return true; } diff --git a/src/main/java/com/volmit/iris/util/decree/virtual/VirtualDecreeCommand.java b/src/main/java/com/volmit/iris/util/decree/virtual/VirtualDecreeCommand.java index 402f6143e..bc83c792b 100644 --- a/src/main/java/com/volmit/iris/util/decree/virtual/VirtualDecreeCommand.java +++ b/src/main/java/com/volmit/iris/util/decree/virtual/VirtualDecreeCommand.java @@ -189,7 +189,7 @@ public class VirtualDecreeCommand { } private boolean invokeTabComplete(KList args, KList skip, KList tabs, String raw) { - if (isStudio() && !IrisSettings.get().isStudio()) { + if (isStudio() && !IrisSettings.get().getStudio().isStudio()) { return false; } @@ -388,7 +388,7 @@ public class VirtualDecreeCommand { } public boolean invoke(VolmitSender sender, KList args, KList skip) { - if (isStudio() && !IrisSettings.get().isStudio()) { + if (isStudio() && !IrisSettings.get().getStudio().isStudio()) { sender.sendMessage(C.RED + "To use Iris Studio Commands, please enable studio in Iris/settings.json (settings auto-reload)"); return false; } From 593e10eec23413bf78f728aaa372aa2e55904cb7 Mon Sep 17 00:00:00 2001 From: CocoTheOwner Date: Fri, 10 Sep 2021 02:13:57 +0200 Subject: [PATCH 4/6] Rename mismatching version number file to another numba --- src/main/java/com/volmit/iris/core/IrisSettings.java | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/src/main/java/com/volmit/iris/core/IrisSettings.java b/src/main/java/com/volmit/iris/core/IrisSettings.java index b6f2b508f..6a1b4199f 100644 --- a/src/main/java/com/volmit/iris/core/IrisSettings.java +++ b/src/main/java/com/volmit/iris/core/IrisSettings.java @@ -129,8 +129,12 @@ public class IrisSettings { if (settings.getConfigurationVersion() != new IrisSettings().getConfigurationVersion()) { Iris.error("Existing configuration's version does not match current configuration version! Resetting..."); + if (s.renameTo(new File(s.getParentFile().getAbsolutePath() + "/settings-old.json"))) { + Iris.info("Renamed settings.json to settings-old.json"); + } settings = new IrisSettings(); settings.forceSave(); + Iris.info("Created a new settings file"); } return settings; From 27f9e2ea9f3c8121dfd6cd76e9c14d71b4386922 Mon Sep 17 00:00:00 2001 From: CocoTheOwner Date: Fri, 10 Sep 2021 02:14:40 +0200 Subject: [PATCH 5/6] V+ --- src/main/java/com/volmit/iris/core/IrisSettings.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/java/com/volmit/iris/core/IrisSettings.java b/src/main/java/com/volmit/iris/core/IrisSettings.java index 6a1b4199f..8fd9b5d78 100644 --- a/src/main/java/com/volmit/iris/core/IrisSettings.java +++ b/src/main/java/com/volmit/iris/core/IrisSettings.java @@ -33,7 +33,7 @@ import java.io.IOException; @Data public class IrisSettings { public static transient IrisSettings settings; - public int configurationVersion = 3; + public int configurationVersion = 4; private IrisSettingsConcurrency concurrency = new IrisSettingsConcurrency(); private IrisSettingsGeneral general = new IrisSettingsGeneral(); private IrisSettingsGUI gui = new IrisSettingsGUI(); From 61037af13807843d6af8fe6b61a3f945461c3edb Mon Sep 17 00:00:00 2001 From: CocoTheOwner Date: Fri, 10 Sep 2021 15:06:04 +0200 Subject: [PATCH 6/6] Remove version yeet --- src/main/java/com/volmit/iris/core/IrisSettings.java | 10 ---------- 1 file changed, 10 deletions(-) diff --git a/src/main/java/com/volmit/iris/core/IrisSettings.java b/src/main/java/com/volmit/iris/core/IrisSettings.java index 8fd9b5d78..68200fbf7 100644 --- a/src/main/java/com/volmit/iris/core/IrisSettings.java +++ b/src/main/java/com/volmit/iris/core/IrisSettings.java @@ -127,16 +127,6 @@ public class IrisSettings { } } - if (settings.getConfigurationVersion() != new IrisSettings().getConfigurationVersion()) { - Iris.error("Existing configuration's version does not match current configuration version! Resetting..."); - if (s.renameTo(new File(s.getParentFile().getAbsolutePath() + "/settings-old.json"))) { - Iris.info("Renamed settings.json to settings-old.json"); - } - settings = new IrisSettings(); - settings.forceSave(); - Iris.info("Created a new settings file"); - } - return settings; }