diff --git a/src/main/java/dev/anvilcraft/rg/RollingGate.java b/src/main/java/dev/anvilcraft/rg/RollingGate.java index 619bc33..71d193b 100644 --- a/src/main/java/dev/anvilcraft/rg/RollingGate.java +++ b/src/main/java/dev/anvilcraft/rg/RollingGate.java @@ -12,7 +12,7 @@ @Mod(RollingGate.MODID) public class RollingGate { public static final String MODID = "rolling_gate"; - private static final Logger LOGGER = LogUtils.getLogger(); + public static final Logger LOGGER = LogUtils.getLogger(); public RollingGate(IEventBus modEventBus, ModContainer modContainer) { NeoForge.EVENT_BUS.addListener((ServerStartingEvent event) -> RGRuleManager.reInitSaveRules(event.getServer())); diff --git a/src/main/java/dev/anvilcraft/rg/api/RGRuleManager.java b/src/main/java/dev/anvilcraft/rg/api/RGRuleManager.java index 0217dbb..a300206 100644 --- a/src/main/java/dev/anvilcraft/rg/api/RGRuleManager.java +++ b/src/main/java/dev/anvilcraft/rg/api/RGRuleManager.java @@ -1,9 +1,12 @@ package dev.anvilcraft.rg.api; +import com.google.gson.JsonElement; import com.google.gson.JsonObject; +import dev.anvilcraft.rg.RollingGate; import net.minecraft.server.MinecraftServer; import net.minecraft.util.GsonHelper; import net.minecraft.world.level.storage.LevelResource; +import net.neoforged.fml.loading.FMLPaths; import org.apache.commons.io.FileUtils; import org.jetbrains.annotations.NotNull; import org.spongepowered.include.com.google.common.base.Charsets; @@ -20,7 +23,8 @@ public class RGRuleManager { private static final RGRuleManager INSTANCE = new RGRuleManager(); - private static final LevelResource path = new LevelResource("rolling_gate.json"); + private static final Path GlobalConfigPath = FMLPaths.CONFIGDIR.get().resolve("rolling_gate.json"); + private static final LevelResource WorldConfigPath = new LevelResource("rolling_gate.json"); private final Map> rules; public RGRuleManager() { @@ -28,12 +32,20 @@ public RGRuleManager() { } public static void reInitSaveRules(MinecraftServer server) { - Path path = server.getWorldPath(RGRuleManager.path); - JsonObject config = getOrCreateContent(path); - config.entrySet().forEach((entry) -> { + Path path = server.getWorldPath(RGRuleManager.WorldConfigPath); + setSaveRules(getOrCreateContent(GlobalConfigPath)); + setSaveRules(getOrCreateContent(path)); + } + + private static void setSaveRules(JsonObject config) { + for (Map.Entry entry : config.entrySet()) { RGRule rule = INSTANCE.rules.get(entry.getKey()); - if (rule != null) rule.setFieldValue(entry.getValue()); - }); + if (rule == null) { + RollingGate.LOGGER.warn("{}({}) not exist.", entry.getKey(), entry.getValue()); + continue; + } + rule.setFieldValue(entry.getValue()); + } } public void register(RGRule rule) {