From 1b09a2169dd748e0cf071f77fc0cc823c79b436f Mon Sep 17 00:00:00 2001 From: Creeam <102713261+HaHaWTH@users.noreply.github.com> Date: Fri, 14 Feb 2025 09:44:48 -0800 Subject: [PATCH] Fix DAB entity blacklist & Fix config modules (#227) --- .../java/org/dreeam/leaf/config/ConfigModules.java | 11 ++++------- .../leaf/config/modules/gameplay/SmoothTeleport.java | 4 ++-- .../config/modules/opt/DynamicActivationofBrain.java | 5 +++-- 3 files changed, 9 insertions(+), 11 deletions(-) diff --git a/leaf-server/src/main/java/org/dreeam/leaf/config/ConfigModules.java b/leaf-server/src/main/java/org/dreeam/leaf/config/ConfigModules.java index 475da124..d5208990 100644 --- a/leaf-server/src/main/java/org/dreeam/leaf/config/ConfigModules.java +++ b/leaf-server/src/main/java/org/dreeam/leaf/config/ConfigModules.java @@ -21,24 +21,21 @@ public abstract class ConfigModules extends LeafConfig { } public static void initModules() throws NoSuchMethodException, InvocationTargetException, InstantiationException, IllegalAccessException { - List> enabledExperimentalModules = new ArrayList<>(); + List enabledExperimentalModules = new ArrayList<>(); for (Class clazz : LeafConfig.getClasses(LeafConfig.I_CONFIG_PKG)) { ConfigModules module = (ConfigModules) clazz.getConstructor().newInstance(); module.onLoaded(); modules.add(module); for (Field field : getAnnotatedStaticFields(clazz, Experimental.class)) { - Object obj = field.get(null); - if (!(obj instanceof Boolean)) continue; - boolean enabled = (Boolean) obj; + if (!(field.get(null) instanceof Boolean enabled)) continue; if (enabled) { - enabledExperimentalModules.add(clazz); - break; + enabledExperimentalModules.add(field); } } } if (!enabledExperimentalModules.isEmpty()) { - LeafConfig.LOGGER.warn("You have following experimental module(s) enabled: {}, please report any bugs you found!", enabledExperimentalModules.stream().map(Class::getSimpleName).toList()); + LeafConfig.LOGGER.warn("You have following experimental module(s) enabled: {}, please proceed with caution!", enabledExperimentalModules.stream().map(f -> f.getClass().getSimpleName() + "." + f.getName()).toList()); } } diff --git a/leaf-server/src/main/java/org/dreeam/leaf/config/modules/gameplay/SmoothTeleport.java b/leaf-server/src/main/java/org/dreeam/leaf/config/modules/gameplay/SmoothTeleport.java index b5c44216..fb739c28 100644 --- a/leaf-server/src/main/java/org/dreeam/leaf/config/modules/gameplay/SmoothTeleport.java +++ b/leaf-server/src/main/java/org/dreeam/leaf/config/modules/gameplay/SmoothTeleport.java @@ -17,11 +17,11 @@ public class SmoothTeleport extends ConfigModules { public void onLoaded() { enabled = config.getBoolean(getBasePath(), enabled, config.pickStringRegionBased( """ - **Experimental feature, report any bugs you encounter!** + **Experimental feature** Whether to make a "smooth teleport" when players changing dimension. This requires original world and target world have same logical height to work.""", """ - **实验性功能, 请及时反馈你遇到的问题!** + **实验性功能** 是否在玩家切换世界时尝试使用 "平滑传送". 此项要求源世界和目标世界逻辑高度相同才会生效.""" )); diff --git a/leaf-server/src/main/java/org/dreeam/leaf/config/modules/opt/DynamicActivationofBrain.java b/leaf-server/src/main/java/org/dreeam/leaf/config/modules/opt/DynamicActivationofBrain.java index a6242a2c..5a144cb7 100644 --- a/leaf-server/src/main/java/org/dreeam/leaf/config/modules/opt/DynamicActivationofBrain.java +++ b/leaf-server/src/main/java/org/dreeam/leaf/config/modules/opt/DynamicActivationofBrain.java @@ -9,6 +9,7 @@ import org.dreeam.leaf.config.LeafConfig; import java.util.ArrayList; import java.util.List; +import java.util.Locale; public class DynamicActivationofBrain extends ConfigModules { @@ -69,12 +70,12 @@ public class DynamicActivationofBrain extends ConfigModules { for (String name : blackedEntities) { // Be compatible with both `minecraft:example` and `example` syntax // If unknown, show user config value in the logger instead of parsed result - String typeId = name.toLowerCase().startsWith(DEFAULT_PREFIX) ? name : DEFAULT_PREFIX + name; + String lowerName = name.toLowerCase(Locale.ROOT); + String typeId = lowerName.startsWith(DEFAULT_PREFIX) ? lowerName : DEFAULT_PREFIX + lowerName; EntityType.byString(typeId).ifPresentOrElse(entityType -> entityType.dabEnabled = false, () -> LeafConfig.LOGGER.warn("Skip unknown entity {}, in {}", name, getBasePath() + ".blacklisted-entities") - ); } }