mirror of
https://github.com/VolmitSoftware/Iris.git
synced 2025-07-19 02:36:59 +00:00
Remove little-used shortcuts, check config version
This commit is contained in:
parent
620c4087bc
commit
5d5b8b78d4
@ -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);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -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;
|
||||
}
|
||||
|
@ -189,7 +189,7 @@ public class VirtualDecreeCommand {
|
||||
}
|
||||
|
||||
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;
|
||||
}
|
||||
|
||||
@ -388,7 +388,7 @@ public class VirtualDecreeCommand {
|
||||
}
|
||||
|
||||
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)");
|
||||
return false;
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user