diff --git a/luminol-server/minecraft-patches/features/0061-Fix-mispatched-entity-custom-spawning-logic.patch b/luminol-server/minecraft-patches/features/0057-Fix-mispatched-entity-custom-spawning-logic.patch similarity index 100% rename from luminol-server/minecraft-patches/features/0061-Fix-mispatched-entity-custom-spawning-logic.patch rename to luminol-server/minecraft-patches/features/0057-Fix-mispatched-entity-custom-spawning-logic.patch diff --git a/luminol-server/minecraft-patches/features/0057-Fix-off-tickregion-sync-teleport.patch b/luminol-server/minecraft-patches/features/0058-Fix-off-tickregion-sync-teleport.patch similarity index 100% rename from luminol-server/minecraft-patches/features/0057-Fix-off-tickregion-sync-teleport.patch rename to luminol-server/minecraft-patches/features/0058-Fix-off-tickregion-sync-teleport.patch diff --git a/luminol-server/minecraft-patches/features/0058-Fix-uncorrected-death-check-of-folia.patch b/luminol-server/minecraft-patches/features/0059-Fix-uncorrected-death-check-of-folia.patch similarity index 100% rename from luminol-server/minecraft-patches/features/0058-Fix-uncorrected-death-check-of-folia.patch rename to luminol-server/minecraft-patches/features/0059-Fix-uncorrected-death-check-of-folia.patch diff --git a/luminol-server/minecraft-patches/features/0059-Teleport-async-if-entity-was-moving-to-another-regio.patch b/luminol-server/minecraft-patches/features/0060-Teleport-async-if-entity-was-moving-to-another-regio.patch similarity index 100% rename from luminol-server/minecraft-patches/features/0059-Teleport-async-if-entity-was-moving-to-another-regio.patch rename to luminol-server/minecraft-patches/features/0060-Teleport-async-if-entity-was-moving-to-another-regio.patch diff --git a/luminol-server/minecraft-patches/features/0060-Try-fixing-folia-off-region-POI-accessing-issue.patch b/luminol-server/minecraft-patches/features/0061-Try-fixing-folia-off-region-POI-accessing-issue.patch similarity index 100% rename from luminol-server/minecraft-patches/features/0060-Try-fixing-folia-off-region-POI-accessing-issue.patch rename to luminol-server/minecraft-patches/features/0061-Try-fixing-folia-off-region-POI-accessing-issue.patch diff --git a/luminol-server/paper-patches/files/src/main/java/me/earthme/luminol/commands/LuminolConfigCommand.java.patch b/luminol-server/paper-patches/files/src/main/java/me/earthme/luminol/commands/LuminolConfigCommand.java.patch index 12d66fc..e020006 100644 --- a/luminol-server/paper-patches/files/src/main/java/me/earthme/luminol/commands/LuminolConfigCommand.java.patch +++ b/luminol-server/paper-patches/files/src/main/java/me/earthme/luminol/commands/LuminolConfigCommand.java.patch @@ -1,6 +1,6 @@ --- /dev/null +++ b/src/main/java/me/earthme/luminol/commands/LuminolConfigCommand.java -@@ -1,0 +_,80 @@ +@@ -1,0 +_,121 @@ +package me.earthme.luminol.commands; + +import me.earthme.luminol.config.LuminolConfig; @@ -23,16 +23,26 @@ + this.setUsage("/luminolconfig"); + } + ++ public void wrongUse(CommandSender sender) { ++ sender.sendMessage( ++ Component ++ .text("Wrong use!") ++ .color(TextColor.color(255, 0, 0)) ++ ); ++ } ++ + @Override + public @NotNull List tabComplete(@NotNull CommandSender sender, @NotNull String alias, @NotNull String[] args, @Nullable Location location) throws IllegalArgumentException { + final List result = new ArrayList<>(); + + if (args.length == 1) { + result.add("query"); -+ // result.add("set"); // TODO Later -+ // result.add("reload"); // TODO Later ++ result.add("set"); ++ result.add("reset"); ++ result.add("reload"); ++ } else if (args.length == 2 && args[0] != "reload") { ++ result.addAll(LuminolConfig.getAllConfigPaths(args[1])); + } -+ + return result; + } + @@ -46,11 +56,7 @@ + } + + if (args.length < 1) { -+ sender.sendMessage( -+ Component -+ .text("Wrong use!\n") -+ .color(TextColor.color(255, 0, 0)) -+ ); ++ wrongUse(sender); + return true; + } + @@ -62,18 +68,53 @@ + .color(TextColor.color(0, 255, 0)) + )); + } -+ + case "set" -> { -+ // TODO Later ++ if (args.length == 2 || args.length > 3) { ++ wrongUse(sender); ++ return true; ++ } else if (LuminolConfig.setConfig(args[1], args[2])) { ++ LuminolConfig.reloadAsync().thenAccept(nullValue -> sender.sendMessage( ++ Component ++ .text("Set Config " + args[1] + " to " + args[2] + " successfully!") ++ .color(TextColor.color(0, 255, 0)) ++ )); ++ } else { ++ sender.sendMessage( ++ Component ++ .text("Failed to set config " + args[1] + " to " + args[2] + "!") ++ .color(TextColor.color(255, 0, 0)) ++ ); ++ } ++ } ++ case "reset" -> { ++ if (args.length != 2) { ++ wrongUse(sender); ++ return true; ++ } else { ++ LuminolConfig.resetConfig(args[1]); ++ LuminolConfig.reloadAsync().thenAccept(nullValue -> sender.sendMessage( ++ Component ++ .text("Reset Config " + args[1] + " to " + LuminolConfig.getConfig(args[1]) + " successfully!") ++ .color(TextColor.color(0, 255, 0)) ++ )); ++ } + } -+ + case "query" -> { -+ // TODO Later ++ if (args.length != 2) { ++ wrongUse(sender); ++ return true; ++ } else { ++ sender.sendMessage( ++ Component ++ .text("Config " + args[1] + " is " + LuminolConfig.getConfig(args[1]) + "!") ++ .color(TextColor.color(0, 255, 0)) ++ ); ++ } + } + + default -> sender.sendMessage( + Component -+ .text("Unknown action!\n") ++ .text("Unknown action!") + .color(TextColor.color(255, 0, 0)) + ); + } diff --git a/luminol-server/paper-patches/files/src/main/java/me/earthme/luminol/config/LuminolConfig.java.patch b/luminol-server/paper-patches/files/src/main/java/me/earthme/luminol/config/LuminolConfig.java.patch index 54c9120..be28931 100644 --- a/luminol-server/paper-patches/files/src/main/java/me/earthme/luminol/config/LuminolConfig.java.patch +++ b/luminol-server/paper-patches/files/src/main/java/me/earthme/luminol/config/LuminolConfig.java.patch @@ -1,6 +1,6 @@ --- /dev/null +++ b/src/main/java/me/earthme/luminol/config/LuminolConfig.java -@@ -1,0 +_,351 @@ +@@ -1,0 +_,378 @@ +package me.earthme.luminol.config; + +import com.electronwill.nightconfig.core.CommentedConfig; @@ -37,12 +37,14 @@ + private static final File baseConfigFolder = new File("luminol_config"); + private static final File baseConfigFile = new File(baseConfigFolder, "luminol_global_config.toml"); + private static final Set allInstanced = new HashSet<>(); -+ public static boolean alreadyInited = false; ++ private static final Map stagedConfigMap = new HashMap<>(); ++ private static final Map defaultvalueMap = new HashMap<>(); ++ public static boolean alreadyInit = false; + private static CommentedFileConfig configFileInstance; + + public static void setupLatch() { + Bukkit.getCommandMap().register("luminolconfig", "luminol", new LuminolConfigCommand()); -+ alreadyInited = true; ++ alreadyInit = true; + } + + public static void reload() { @@ -97,7 +99,7 @@ + throw new RuntimeException(e); + } + -+ configFileInstance.save(); ++ saveConfigs(); + } + + private static void loadAllModules() throws IllegalAccessException { @@ -122,7 +124,7 @@ + for (Field field : fields) { + int modifiers = field.getModifiers(); + if (Modifier.isStatic(modifiers) && !Modifier.isFinal(modifiers)) { -+ boolean skipLoad = field.getAnnotation(DoNotLoad.class) != null || (alreadyInited && field.getAnnotation(HotReloadUnsupported.class) != null); ++ boolean skipLoad = field.getAnnotation(DoNotLoad.class) != null || (alreadyInit && field.getAnnotation(HotReloadUnsupported.class) != null); + ConfigInfo configInfo = field.getAnnotation(ConfigInfo.class); + + if (skipLoad || configInfo == null) { @@ -133,6 +135,7 @@ + + field.setAccessible(true); + final Object currentValue = field.get(null); ++ if (!alreadyInit) defaultvalueMap.put(fullConfigKeyName, currentValue); + boolean removed = fullConfigKeyName.equals("removed.removed_config.removed"); + + if (!configFileInstance.contains(fullConfigKeyName) || removed) { @@ -180,7 +183,21 @@ + continue; + } + -+ final Object actuallyValue = configFileInstance.get(fullConfigKeyName); ++ Object actuallyValue; ++ if (stagedConfigMap.containsKey(fullConfigKeyName)) { ++ actuallyValue = stagedConfigMap.get(fullConfigKeyName); ++ if (actuallyValue == null) actuallyValue = defaultvalueMap.get(fullConfigKeyName); ++ stagedConfigMap.remove(fullConfigKeyName); ++ } else { ++ actuallyValue = configFileInstance.get(fullConfigKeyName); ++ } ++ try { ++ actuallyValue = tryTransform(field.get(null).getClass(), actuallyValue); ++ configFileInstance.set(fullConfigKeyName, actuallyValue); ++ } catch (IllegalFormatConversionException e) { ++ resetConfig(fullConfigKeyName); ++ logger.error("Failed to transform config {}, reset to default!", fullConfigKeyName); ++ } + field.set(null, actuallyValue); + } + } @@ -202,31 +219,43 @@ + } + } + -+ public static boolean setConfigAndSave(String[] keys, Object value) { -+ return setConfigAndSave(String.join(".", keys), value); -+ } -+ -+ public static boolean setConfigAndSave(String key, Object value) { -+ if (setConfig(key, value)) { -+ saveConfig(); -+ return true; -+ } -+ return false; -+ } -+ + public static boolean setConfig(String[] keys, Object value) { + return setConfig(String.join(".", keys), value); + } + + public static boolean setConfig(String key, Object value) { + if (configFileInstance.contains(key) && configFileInstance.get(key) != null) { -+ configFileInstance.set(key, value); ++ stagedConfigMap.put(key, value); + return true; + } + return false; + } + -+ public static void saveConfig() { ++ private static Object tryTransform(Class targetType, Object value) { ++ if (!targetType.isAssignableFrom(value.getClass())) { ++ try { ++ if (targetType == Integer.class) { ++ value = Integer.parseInt(value.toString()); ++ } else if (targetType == Double.class) { ++ value = Double.parseDouble(value.toString()); ++ } else if (targetType == Boolean.class) { ++ value = Boolean.parseBoolean(value.toString()); ++ } else if (targetType == Long.class) { ++ value = Long.parseLong(value.toString()); ++ } else if (targetType == Float.class) { ++ value = Float.parseFloat(value.toString()); ++ } else if (targetType == String.class) { ++ value = value.toString(); ++ } ++ } catch (Exception e) { ++ logger.error("Failed to transform value {}!", value); ++ throw new IllegalFormatConversionException((char) 0, targetType); ++ } ++ } ++ return value; ++ } ++ ++ public static void saveConfigs() { + configFileInstance.save(); + } + @@ -235,9 +264,7 @@ + } + + public static void resetConfig(String key) { -+ configFileInstance.remove(key); -+ configFileInstance.save(); -+ reload(); ++ stagedConfigMap.put(key, null); + } + + public static String getConfig(String[] keys) { @@ -245,10 +272,10 @@ + } + + public static String getConfig(String key) { -+ return configFileInstance.get(key); ++ return configFileInstance.get(key).toString(); + } + -+ public List getAllConfigPaths(String prefix) { ++ public static List getAllConfigPaths(String prefix) { + List configPaths = getAllConfigPaths(); + return configPaths.stream().filter(path -> path.startsWith(prefix)).toList(); + }