tweaks724/src/main/java/eu/m724/tweaks/TweaksConfig.java
Minecon724 a7506bd3c6
Some checks failed
/ deploy (push) Failing after 53s
commit
2024-11-26 20:25:13 +01:00

98 lines
No EOL
3.5 KiB
Java

package eu.m724.tweaks;
import org.bukkit.configuration.file.FileConfiguration;
import org.bukkit.plugin.Plugin;
public record TweaksConfig(
boolean isProtocolLib,
boolean worldborderHide,
boolean brandEnabled,
String brandText,
boolean brandShowPing,
boolean brandShowMspt,
boolean doorEnabled,
boolean doorDoubleOpen,
boolean doorKnocking,
boolean motdEnabled,
String motdSet,
boolean chatEnabled,
boolean chatLocalEvents,
String chatDefaultName,
boolean compassEnabled,
int compassWidth,
int compassPrecision,
boolean pomodoroEnabled,
boolean pomodoroForce,
boolean updaterEnabled
) {
public static final int CONFIG_VERSION = 1;
private static TweaksConfig config;
public static TweaksConfig getConfig() {
return config;
}
public static TweaksConfig load(Plugin plugin) {
plugin.saveDefaultConfig();
FileConfiguration config = plugin.getConfig();
boolean isProtocolLib = plugin.getServer().getPluginManager().getPlugin("ProtocolLib") != null;
int configVersion = config.getInt("magic number dont modify this", 0);
RuntimeException exception = new RuntimeException("Config version is %d, expected %d".formatted(configVersion, CONFIG_VERSION));
if (configVersion == 0) {
throw exception;
} else if (configVersion > CONFIG_VERSION) {
throw new RuntimeException("Please follow update instructions", exception);
} else if (configVersion < CONFIG_VERSION) {
throw new RuntimeException("Did you downgrade the plugin? Remove config.yml and let the plugin re-create it", exception);
}
boolean hideWorldBorder = config.getBoolean("worldborder.hide");
boolean brandEnabled = config.getBoolean("brand.enabled");
String brandText = config.getString("brand.text");
boolean brandShowPing = config.getBoolean("brand.showPing");
boolean brandShowMspt = config.getBoolean("brand.showMspt");
boolean doorDoubleOpen = config.getBoolean("doors.doubleOpen");
boolean doorKnocking = config.getBoolean("doors.knocking");
boolean doorEnabled = doorDoubleOpen || doorKnocking;
String motdSet = config.getString("motd.set");
boolean motdEnabled = !(motdSet.equals("false") || motdSet.isBlank());
boolean chatEnabled = config.getBoolean("chat.enabled");
boolean chatLocalEvents = config.getBoolean("chat.localEvents");
String chatDefaultName = config.getString("chat.defaultName");
boolean compassEnabled = config.getBoolean("compass.enabled");
int compassWidth = config.getInt("compass.width");
int compassPrecision = config.getInt("compass.precision");
boolean pomodoroEnabled = config.getBoolean("pomodoro.enabled");
boolean pomodoroForce = config.getBoolean("pomodoro.force");
TweaksConfig.config = new TweaksConfig(
isProtocolLib,
hideWorldBorder,
brandEnabled, brandText, brandShowPing, brandShowMspt,
doorEnabled, doorDoubleOpen, doorKnocking,
motdEnabled, motdSet,
chatEnabled, chatLocalEvents, chatDefaultName,
compassEnabled, compassWidth, compassPrecision,
pomodoroEnabled, pomodoroForce,
true // TODO
);
return TweaksConfig.config;
}
}