From b0f09c8e7b75e7a53831067012863f217af21dac Mon Sep 17 00:00:00 2001 From: nossr50 Date: Wed, 12 Jun 2019 10:01:18 -0700 Subject: [PATCH] Add PlayerNotificationSerializer --- .../gmail/nossr50/config/ConfigManager.java | 2 ++ .../MinecraftMaterialWrapperSerializer.java | 1 - .../PlayerNotificationSerializer.java | 34 +++++++++++++++++++ 3 files changed, 36 insertions(+), 1 deletion(-) create mode 100644 src/main/java/com/gmail/nossr50/config/hocon/serializers/PlayerNotificationSerializer.java diff --git a/src/main/java/com/gmail/nossr50/config/ConfigManager.java b/src/main/java/com/gmail/nossr50/config/ConfigManager.java index 750aef4bd..4a728ea2d 100644 --- a/src/main/java/com/gmail/nossr50/config/ConfigManager.java +++ b/src/main/java/com/gmail/nossr50/config/ConfigManager.java @@ -16,6 +16,7 @@ import com.gmail.nossr50.config.hocon.metrics.ConfigMetrics; import com.gmail.nossr50.config.hocon.mobs.ConfigMobs; import com.gmail.nossr50.config.hocon.motd.ConfigMOTD; import com.gmail.nossr50.config.hocon.notifications.ConfigNotifications; +import com.gmail.nossr50.config.hocon.notifications.PlayerNotification; import com.gmail.nossr50.config.hocon.particles.ConfigParticles; import com.gmail.nossr50.config.hocon.party.ConfigParty; import com.gmail.nossr50.config.hocon.party.data.ConfigPartyData; @@ -272,6 +273,7 @@ public final class ConfigManager { customSerializers.registerType(TypeToken.of(SkillCeiling.class), new SkillCeilingSerializer()); customSerializers.registerType(TypeToken.of(SkillRankProperty.class), new SkillRankPropertySerializer()); customSerializers.registerType(TypeToken.of(MaxBonusLevel.class), new MaxBonusLevelSerializer()); + customSerializers.registerType(TypeToken.of(PlayerNotification.class), new PlayerNotificationSerializer()); } /** diff --git a/src/main/java/com/gmail/nossr50/config/hocon/serializers/MinecraftMaterialWrapperSerializer.java b/src/main/java/com/gmail/nossr50/config/hocon/serializers/MinecraftMaterialWrapperSerializer.java index 6c6af49e9..20e54ec1a 100644 --- a/src/main/java/com/gmail/nossr50/config/hocon/serializers/MinecraftMaterialWrapperSerializer.java +++ b/src/main/java/com/gmail/nossr50/config/hocon/serializers/MinecraftMaterialWrapperSerializer.java @@ -20,7 +20,6 @@ public class MinecraftMaterialWrapperSerializer implements TypeSerializer type, MinecraftMaterialWrapper obj, ConfigurationNode value) { - value.setValue(obj.getName()); //Name value.getNode(FULLY_QUALIFIED_NAME).setValue(obj.getFullyQualifiedName()); value.getNode(BUKKIT_MATERIAL_NAME).setValue(obj.getBukkitMaterialName()); diff --git a/src/main/java/com/gmail/nossr50/config/hocon/serializers/PlayerNotificationSerializer.java b/src/main/java/com/gmail/nossr50/config/hocon/serializers/PlayerNotificationSerializer.java new file mode 100644 index 000000000..264862567 --- /dev/null +++ b/src/main/java/com/gmail/nossr50/config/hocon/serializers/PlayerNotificationSerializer.java @@ -0,0 +1,34 @@ +package com.gmail.nossr50.config.hocon.serializers; + +import com.gmail.nossr50.config.hocon.notifications.PlayerNotification; +import com.google.common.reflect.TypeToken; +import ninja.leaping.configurate.ConfigurationNode; +import ninja.leaping.configurate.objectmapping.ObjectMappingException; +import ninja.leaping.configurate.objectmapping.serialize.TypeSerializer; +import org.checkerframework.checker.nullness.qual.NonNull; +import org.checkerframework.checker.nullness.qual.Nullable; + +public class PlayerNotificationSerializer implements TypeSerializer { + private static final String ENABLED_NODE = "Enabled"; + private static final String SEND_TO_CHAT_NODE = "Send-To-Chat"; + private static final String SEND_TO_ACTION_BAR_NODE = "Send-To-Action-Bar"; + + @Nullable + @Override + public PlayerNotification deserialize(@NonNull TypeToken type, @NonNull ConfigurationNode value) throws ObjectMappingException { + Boolean enabled = value.getNode(ENABLED_NODE).getValue(TypeToken.of(Boolean.class)); + Boolean sendTochat = value.getNode(SEND_TO_CHAT_NODE).getValue(TypeToken.of(Boolean.class)); + Boolean sendToActionBar = value.getNode(SEND_TO_ACTION_BAR_NODE).getValue(TypeToken.of(Boolean.class)); + + PlayerNotification playerNotification = new PlayerNotification(enabled, sendTochat, sendToActionBar); + return playerNotification; + } + + @Override + public void serialize(@NonNull TypeToken type, @Nullable PlayerNotification obj, @NonNull ConfigurationNode value) throws ObjectMappingException { + value.getNode(ENABLED_NODE).setValue(obj.isEnabled()); + value.getNode(SEND_TO_CHAT_NODE).setValue(obj.isSendToChat()); + value.getNode(SEND_TO_ACTION_BAR_NODE).setValue(obj.isSendToActionBar()); + } + +}