From 54c8bac3d3f62ce12603b33ce515af903084482f Mon Sep 17 00:00:00 2001 From: Ben Woo <30431861+benwoo1110@users.noreply.github.com> Date: Thu, 31 Aug 2023 15:16:41 +0800 Subject: [PATCH] Config node automatically use the enum node serializer --- .../MultiverseCore/configuration/node/ConfigNode.java | 4 ++++ .../MultiverseCore/worldnew/config/WorldConfigNodes.java | 8 -------- 2 files changed, 4 insertions(+), 8 deletions(-) diff --git a/src/main/java/com/onarandombox/MultiverseCore/configuration/node/ConfigNode.java b/src/main/java/com/onarandombox/MultiverseCore/configuration/node/ConfigNode.java index 5985d22c..f9efbd22 100644 --- a/src/main/java/com/onarandombox/MultiverseCore/configuration/node/ConfigNode.java +++ b/src/main/java/com/onarandombox/MultiverseCore/configuration/node/ConfigNode.java @@ -111,6 +111,7 @@ public class ConfigNode extends ConfigHeaderNode implements ValueNode { * @param The type of the builder. */ public static class Builder> extends ConfigHeaderNode.Builder { + private static final NodeSerializer ENUM_NODE_SERIALIZER = new EnumNodeSerializer<>(); protected @Nullable String name; protected @NotNull final Class type; @@ -129,6 +130,9 @@ public class ConfigNode extends ConfigHeaderNode implements ValueNode { super(path); this.name = path; this.type = type; + if (type.isEnum()) { + this.serializer = (NodeSerializer) ENUM_NODE_SERIALIZER; + } } /** diff --git a/src/main/java/com/onarandombox/MultiverseCore/worldnew/config/WorldConfigNodes.java b/src/main/java/com/onarandombox/MultiverseCore/worldnew/config/WorldConfigNodes.java index 482a9437..12bfc65d 100644 --- a/src/main/java/com/onarandombox/MultiverseCore/worldnew/config/WorldConfigNodes.java +++ b/src/main/java/com/onarandombox/MultiverseCore/worldnew/config/WorldConfigNodes.java @@ -1,10 +1,8 @@ package com.onarandombox.MultiverseCore.worldnew.config; import com.onarandombox.MultiverseCore.configuration.node.ConfigNode; -import com.onarandombox.MultiverseCore.configuration.node.EnumNodeSerializer; import com.onarandombox.MultiverseCore.configuration.node.Node; import com.onarandombox.MultiverseCore.configuration.node.NodeGroup; -import com.onarandombox.MultiverseCore.configuration.node.NodeSerializer; import com.onarandombox.MultiverseCore.world.configuration.AllowedPortalType; import org.bukkit.Difficulty; import org.bukkit.GameMode; @@ -14,8 +12,6 @@ import java.util.ArrayList; import java.util.List; public class WorldConfigNodes { - private static final NodeSerializer ENUM_NODE_SERIALIZER = new EnumNodeSerializer<>(); - private final NodeGroup nodes = new NodeGroup(); WorldConfigNodes() { @@ -63,19 +59,16 @@ public class WorldConfigNodes { public final ConfigNode DIFFICULTY = node(ConfigNode.builder("difficulty", Difficulty.class) .defaultValue(Difficulty.NORMAL) .name("difficulty") - .serializer((NodeSerializer) ENUM_NODE_SERIALIZER) .build()); public final ConfigNode ENVIRONMENT = node(ConfigNode.builder("environment", World.Environment.class) .defaultValue(World.Environment.NORMAL) .name("environment") - .serializer((NodeSerializer) ENUM_NODE_SERIALIZER) .build()); public final ConfigNode GAMEMODE = node(ConfigNode.builder("gamemode", GameMode.class) .defaultValue(GameMode.SURVIVAL) .name("gamemode") - .serializer((NodeSerializer) ENUM_NODE_SERIALIZER) .build()); public final ConfigNode GENERATOR = node(ConfigNode.builder("generator", String.class) @@ -106,7 +99,6 @@ public class WorldConfigNodes { public final ConfigNode PORTAL_FORM = node(ConfigNode.builder("portal-form", AllowedPortalType.class) .defaultValue(AllowedPortalType.ALL) .name("portal-form") - .serializer((NodeSerializer) ENUM_NODE_SERIALIZER) .build()); public final ConfigNode PVP = node(ConfigNode.builder("pvp", Boolean.class)