Merge pull request #622 from CocoTheOwner/unusedSettings

Simplify settings
This commit is contained in:
Dan
2021-09-10 09:13:03 -04:00
committed by GitHub
6 changed files with 74 additions and 120 deletions

View File

@@ -511,7 +511,7 @@ public class Iris extends VolmitPlugin implements Listener {
J.a(this::verifyDataPacksPost, 20); J.a(this::verifyDataPacksPost, 20);
splash(); splash();
if (IrisSettings.get().getGeneral().isAutoStartDefaultStudio()) { if (IrisSettings.get().getStudio().isAutoStartDefaultStudio()) {
Iris.info("Starting up auto Studio!"); Iris.info("Starting up auto Studio!");
try { try {
Player r = new KList<>(getServer().getOnlinePlayers()).getRandom(); Player r = new KList<>(getServer().getOnlinePlayers()).getRandom();

View File

@@ -33,25 +33,67 @@ import java.io.IOException;
@Data @Data
public class IrisSettings { public class IrisSettings {
public static transient IrisSettings settings; public static transient IrisSettings settings;
public int configurationVersion = 3; public int configurationVersion = 4;
private IrisSettingsCache cache = new IrisSettingsCache();
private IrisSettingsConcurrency concurrency = new IrisSettingsConcurrency(); private IrisSettingsConcurrency concurrency = new IrisSettingsConcurrency();
private IrisSettingsParallax parallax = new IrisSettingsParallax();
private IrisSettingsGeneral general = new IrisSettingsGeneral(); private IrisSettingsGeneral general = new IrisSettingsGeneral();
private IrisSettingsGUI gui = new IrisSettingsGUI(); private IrisSettingsGUI gui = new IrisSettingsGUI();
private IrisSettingsGenerator generator = new IrisSettingsGenerator(); private IrisSettingsGenerator generator = new IrisSettingsGenerator();
private IrisSettingsStudio studio = new IrisSettingsStudio(); private IrisSettingsStudio studio = new IrisSettingsStudio();
public static int getPriority(int c) { public static int getThreadCount(int c) {
return Math.max(Math.min(c, Thread.MAX_PRIORITY), Thread.MIN_PRIORITY); return switch (c) {
case -1, -2, -4 -> Runtime.getRuntime().availableProcessors() / -c;
case 0, 1, 2 -> 1;
default -> Math.max(c, 2);
};
} }
public static int getThreadCount(int c) { @Data
if (c < 2 && c >= 0) { public static class IrisSettingsConcurrency {
return 2; public int parallelism = -1;
} public int parallaxEvictionMS = 10000;
}
return Math.max(2, c < 0 ? Runtime.getRuntime().availableProcessors() / -c : c); @Data
public static class IrisSettingsGeneral {
public boolean commandSounds = true;
public boolean debug = false;
public boolean disableNMS = false;
public boolean pluginMetrics = true;
public boolean splashLogoStartup = true;
public boolean useConsoleCustomColors = true;
public boolean useCustomColorsIngame = true;
public String forceMainWorld = "";
public int spinh = -20;
public int spins = 7;
public int spinb = 8;
@SuppressWarnings("BooleanMethodIsAlwaysInverted")
public boolean canUseCustomColors(VolmitSender volmitSender) {
return volmitSender.isPlayer() ? useCustomColorsIngame : useConsoleCustomColors;
}
}
@Data
public static class IrisSettingsGUI {
public boolean useServerLaunchedGuis = true;
public boolean maximumPregenGuiFPS = false;
}
@Data
public static class IrisSettingsGenerator {
public String defaultWorldType = "overworld";
public boolean headlessPregeneration = false;
public int maxBiomeChildDepth = 4;
public boolean preventLeafDecay = true;
}
@Data
public static class IrisSettingsStudio {
public boolean studio = true;
public boolean openVSCode = true;
public boolean disableTimeAndWeather = true;
public boolean autoStartDefaultStudio = false;
} }
public static IrisSettings get() { public static IrisSettings get() {
@@ -59,42 +101,29 @@ public class IrisSettings {
return settings; return settings;
} }
IrisSettings defaults = new IrisSettings(); settings = new IrisSettings();
JSONObject def = new JSONObject(new Gson().toJson(defaults));
if (settings == null) {
settings = new IrisSettings();
File s = Iris.instance.getDataFile("settings.json"); File s = Iris.instance.getDataFile("settings.json");
if (!s.exists()) { if (!s.exists()) {
try { try {
IO.writeAll(s, new JSONObject(new Gson().toJson(settings)).toString(4)); IO.writeAll(s, new JSONObject(new Gson().toJson(settings)).toString(4));
} catch (JSONException | IOException e) { } catch (JSONException | IOException e) {
e.printStackTrace(); e.printStackTrace();
Iris.reportError(e); 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());
}
} }
} else {
if (!s.exists()) { try {
String ss = IO.readAll(s);
settings = new Gson().fromJson(ss, IrisSettings.class);
try { try {
IO.writeAll(s, new JSONObject(new Gson().toJson(settings)).toString(4)); IO.writeAll(s, new JSONObject(new Gson().toJson(settings)).toString(4));
} catch (JSONException | IOException e) { } catch (IOException e) {
Iris.reportError(e);
e.printStackTrace(); e.printStackTrace();
} }
} catch (Throwable ee) {
Iris.reportError(ee);
Iris.error("Configuration Error in settings.json! " + ee.getClass().getSimpleName() + ": " + ee.getMessage());
} }
} }
@@ -107,19 +136,6 @@ public class IrisSettings {
} }
} }
public boolean isStudio() {
return getStudio().isStudio();
}
@SuppressWarnings("BooleanMethodIsAlwaysInverted")
public boolean isUseServerLaunchedGuis() {
return getGui().isUseServerLaunchedGuis();
}
public long getParallaxRegionEvictionMS() {
return getParallax().getParallaxRegionEvictionMS();
}
public void forceSave() { public void forceSave() {
File s = Iris.instance.getDataFile("settings.json"); File s = Iris.instance.getDataFile("settings.json");
@@ -130,65 +146,4 @@ public class IrisSettings {
Iris.reportError(e); Iris.reportError(e);
} }
} }
@Data
public static class IrisSettingsCache {
public int complexCacheSize = 131072;
}
@Data
public static class IrisSettingsConcurrency {
public int parallelism = -1;
}
@Data
public static class IrisSettingsParallax {
public int parallaxRegionEvictionMS = 15000;
public int parallaxChunkEvictionMS = 5000;
}
@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;
public boolean useConsoleCustomColors = true;
public boolean useCustomColorsIngame = true;
public String forceMainWorld = "";
public int spinh = -20;
public int spins = 7;
public int spinb = 8;
public boolean canUseCustomColors(VolmitSender volmitSender) {
return (volmitSender.isPlayer() && useCustomColorsIngame) || (!volmitSender.isPlayer() && useConsoleCustomColors);
}
}
@Data
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;
}
@Data
public static class IrisSettingsStudio {
public boolean studio = true;
public boolean openVSCode = true;
public boolean disableTimeAndWeather = true;
}
} }

View File

@@ -923,7 +923,7 @@ public class CommandStudio implements DecreeExecutor {
* @return true if server GUIs are not enabled * @return true if server GUIs are not enabled
*/ */
private boolean noGUI() { 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!"); sender().sendMessage(C.RED + "You must have server launched GUIs enabled in the settings!");
return true; return true;
} }

View File

@@ -121,8 +121,7 @@ public class IrisEngine implements Engine {
bud = new AtomicInteger(0); bud = new AtomicInteger(0);
buds = new AtomicInteger(0); buds = new AtomicInteger(0);
metrics = new EngineMetrics(32); metrics = new EngineMetrics(32);
cleanLatch = new ChronoLatch(Math.max(10000, Math.min(IrisSettings.get().getParallax() cleanLatch = new ChronoLatch(Math.max(10000, IrisSettings.get().getConcurrency().getParallaxEvictionMS()));
.getParallaxChunkEvictionMS(), IrisSettings.get().getParallax().getParallaxRegionEvictionMS())));
generatedLast = new AtomicInteger(0); generatedLast = new AtomicInteger(0);
perSecond = new AtomicDouble(0); perSecond = new AtomicDouble(0);
perSecondLatch = new ChronoLatch(1000, false); perSecondLatch = new ChronoLatch(1000, false);

View File

@@ -493,7 +493,7 @@ public class B {
return null; return null;
} }
if (bx instanceof Leaves && IrisSettings.get().getGenerator().preventLeafDecay) { if (bx instanceof Leaves && IrisSettings.get().getGenerator().isPreventLeafDecay()) {
((Leaves) bx).setPersistent(true); ((Leaves) bx).setPersistent(true);
} else if (bx instanceof Leaves) { } else if (bx instanceof Leaves) {
((Leaves) bx).setPersistent(false); ((Leaves) bx).setPersistent(false);

View File

@@ -189,7 +189,7 @@ public class VirtualDecreeCommand {
} }
private boolean invokeTabComplete(KList<String> args, KList<Integer> skip, KList<String> tabs, String raw) { private boolean invokeTabComplete(KList<String> args, KList<Integer> skip, KList<String> tabs, String raw) {
if (isStudio() && !IrisSettings.get().isStudio()) { if (isStudio() && !IrisSettings.get().getStudio().isStudio()) {
return false; return false;
} }
@@ -388,7 +388,7 @@ public class VirtualDecreeCommand {
} }
public boolean invoke(VolmitSender sender, KList<String> args, KList<Integer> skip) { public boolean invoke(VolmitSender sender, KList<String> args, KList<Integer> 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)"); sender.sendMessage(C.RED + "To use Iris Studio Commands, please enable studio in Iris/settings.json (settings auto-reload)");
return false; return false;
} }