From 8c1c17fa1761bdba1eae3c8dbe4093d353da5561 Mon Sep 17 00:00:00 2001 From: nossr50 Date: Mon, 3 Jun 2019 01:02:45 -0700 Subject: [PATCH] Custom Serializer for DamageProperty --- Changelog.txt | 2 +- .../party/alliance/PartyAllianceCommand.java | 2 +- .../gmail/nossr50/config/ConfigManager.java | 2 ++ .../hocon/DamagePropertySerializer.java | 31 +++++++++++++++++++ .../axes/ConfigAxesCriticalStrikes.java | 1 - 5 files changed, 35 insertions(+), 3 deletions(-) create mode 100644 src/main/java/com/gmail/nossr50/config/hocon/DamagePropertySerializer.java diff --git a/Changelog.txt b/Changelog.txt index b5e6c7075..0f8728c21 100644 --- a/Changelog.txt +++ b/Changelog.txt @@ -3,7 +3,7 @@ Version 2.2.0 !!!!!!!!!!!!!!!!!!!!!!!! This changelog is not complete, I'll be going over it and cleaning it up once 2.2 is close to release !!!!!!!!!!!!!!!!!!!!!!!! - !!!!!!!!!!!!!!!!!!!!!!!! + !!!!!!!!!!!!!!!!!!!!!!!!mvn clea mcMMO's config system has been rewritten Nearly every config setting has been renamed and most have brand new comments You can now add an unlimited number of custom XP perks with custom defined XP boosts diff --git a/src/main/java/com/gmail/nossr50/commands/party/alliance/PartyAllianceCommand.java b/src/main/java/com/gmail/nossr50/commands/party/alliance/PartyAllianceCommand.java index 02b0468bd..a7e89bba8 100644 --- a/src/main/java/com/gmail/nossr50/commands/party/alliance/PartyAllianceCommand.java +++ b/src/main/java/com/gmail/nossr50/commands/party/alliance/PartyAllianceCommand.java @@ -5,9 +5,9 @@ import com.gmail.nossr50.datatypes.party.PartyFeature; import com.gmail.nossr50.datatypes.player.McMMOPlayer; import com.gmail.nossr50.locale.LocaleLoader; import com.gmail.nossr50.party.PartyManager; +import com.gmail.nossr50.util.commands.CommandUtils; import com.gmail.nossr50.util.player.UserManager; import com.google.common.collect.ImmutableList; -import com.gmail.nossr50.util.commands.CommandUtils; import org.bukkit.ChatColor; import org.bukkit.command.Command; import org.bukkit.command.CommandExecutor; diff --git a/src/main/java/com/gmail/nossr50/config/ConfigManager.java b/src/main/java/com/gmail/nossr50/config/ConfigManager.java index 14c441a50..fc69be57d 100644 --- a/src/main/java/com/gmail/nossr50/config/ConfigManager.java +++ b/src/main/java/com/gmail/nossr50/config/ConfigManager.java @@ -48,6 +48,7 @@ import com.gmail.nossr50.datatypes.experience.CustomXPPerk; import com.gmail.nossr50.datatypes.experience.FormulaType; import com.gmail.nossr50.datatypes.party.PartyFeature; import com.gmail.nossr50.datatypes.skills.PrimarySkillType; +import com.gmail.nossr50.datatypes.skills.properties.DamageProperty; import com.gmail.nossr50.mcMMO; import com.gmail.nossr50.skills.repair.repairables.Repairable; import com.gmail.nossr50.skills.salvage.salvageables.Salvageable; @@ -260,6 +261,7 @@ public final class ConfigManager { customSerializers.registerType(TypeToken.of(Salvageable.class), new SalvageableSerializer()); customSerializers.registerType(TypeToken.of(MinecraftMaterialWrapper.class), new MinecraftMaterialWrapperSerializer()); customSerializers.registerType(TypeToken.of(CustomXPPerk.class), new CustomXPPerkSerializer()); + customSerializers.registerType(TypeToken.of(DamageProperty.class), new DamagePropertySerializer()); } /** diff --git a/src/main/java/com/gmail/nossr50/config/hocon/DamagePropertySerializer.java b/src/main/java/com/gmail/nossr50/config/hocon/DamagePropertySerializer.java new file mode 100644 index 000000000..139f5bf9d --- /dev/null +++ b/src/main/java/com/gmail/nossr50/config/hocon/DamagePropertySerializer.java @@ -0,0 +1,31 @@ +package com.gmail.nossr50.config.hocon; + +import com.gmail.nossr50.datatypes.skills.properties.AbstractDamageProperty; +import com.gmail.nossr50.datatypes.skills.properties.DamageProperty; +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 DamagePropertySerializer implements TypeSerializer { + + public static final String PVP_NODE = "PVP"; + public static final String PVE_NODE = "PVE"; + + @Nullable + @Override + public DamageProperty deserialize(@NonNull TypeToken type, @NonNull ConfigurationNode value) throws ObjectMappingException { + Float pvp = value.getNode(PVP_NODE).getValue(TypeToken.of(Float.class)); + Float pve = value.getNode(PVE_NODE).getValue(TypeToken.of(Float.class)); + DamageProperty damageProperty = new AbstractDamageProperty(pve, pvp); + return damageProperty; + } + + @Override + public void serialize(@NonNull TypeToken type, @Nullable DamageProperty obj, @NonNull ConfigurationNode value) throws ObjectMappingException { + value.getNode(PVP_NODE).setValue(obj.getPVPModifier()); + value.getNode(PVE_NODE).setValue(obj.getPVEModifier()); + } +} diff --git a/src/main/java/com/gmail/nossr50/config/hocon/skills/axes/ConfigAxesCriticalStrikes.java b/src/main/java/com/gmail/nossr50/config/hocon/skills/axes/ConfigAxesCriticalStrikes.java index 5c5328acc..83a25c9b2 100644 --- a/src/main/java/com/gmail/nossr50/config/hocon/skills/axes/ConfigAxesCriticalStrikes.java +++ b/src/main/java/com/gmail/nossr50/config/hocon/skills/axes/ConfigAxesCriticalStrikes.java @@ -1,6 +1,5 @@ package com.gmail.nossr50.config.hocon.skills.axes; -import com.gmail.nossr50.datatypes.skills.SubSkillType; import com.gmail.nossr50.datatypes.skills.properties.AbstractDamageProperty; import com.gmail.nossr50.datatypes.skills.properties.AbstractMaximumProgressionLevel; import com.gmail.nossr50.datatypes.skills.properties.DamageProperty;