diff --git a/src/main/java/com/gmail/nossr50/config/hocon/serializers/CustomEnumValueSerializerPartyFeature.java b/src/main/java/com/gmail/nossr50/config/hocon/serializers/CustomEnumValueSerializerPartyFeature.java index 988cf6350..46e3a2820 100644 --- a/src/main/java/com/gmail/nossr50/config/hocon/serializers/CustomEnumValueSerializerPartyFeature.java +++ b/src/main/java/com/gmail/nossr50/config/hocon/serializers/CustomEnumValueSerializerPartyFeature.java @@ -1,5 +1,6 @@ package com.gmail.nossr50.config.hocon.serializers; +import com.gmail.nossr50.config.hocon.HOCONUtil; import com.google.common.reflect.TypeToken; import ninja.leaping.configurate.ConfigurationNode; import ninja.leaping.configurate.objectmapping.ObjectMappingException; diff --git a/src/main/java/com/gmail/nossr50/config/hocon/serializers/CustomXPPerkSerializer.java b/src/main/java/com/gmail/nossr50/config/hocon/serializers/CustomXPPerkSerializer.java index 6b3cd8222..60dd3b473 100644 --- a/src/main/java/com/gmail/nossr50/config/hocon/serializers/CustomXPPerkSerializer.java +++ b/src/main/java/com/gmail/nossr50/config/hocon/serializers/CustomXPPerkSerializer.java @@ -12,30 +12,24 @@ import ninja.leaping.configurate.objectmapping.serialize.TypeSerializer; import org.checkerframework.checker.nullness.qual.NonNull; import org.checkerframework.checker.nullness.qual.Nullable; +import java.util.HashMap; +import java.util.Map; + public class CustomXPPerkSerializer implements TypeSerializer { + private static final String PERK_NAME = "perk-name"; + private static final String XP_BOOST_NODE_ROOT = "XP-Boosts"; + @Nullable @Override public CustomXPPerk deserialize(@NonNull TypeToken type, @NonNull ConfigurationNode value) throws ObjectMappingException { - String perkName = value.getNode("name").getValue(TypeToken.of(String.class)); + String perkName = value.getNode(PERK_NAME).getValue(TypeToken.of(String.class)); + + Map map = value.getNode(XP_BOOST_NODE_ROOT).getValue(new TypeToken>(){}); + HashMap xpBoostHashMap = new HashMap<>(map); + CustomXPPerk customXPPerk = new CustomXPPerk(perkName); - - //See if any children nodes match skills by name - for (ConfigurationNode configurationNode : value.getChildrenList()) { - try { - PrimarySkillType primarySkillType = matchIgnoreCase(configurationNode.getValue(TypeToken.of(String.class))); - if (primarySkillType.isChildSkill()) - continue; //Child skills gross - - Float boostValue = configurationNode.getNode("XP-Multiplier").getValue(TypeToken.of(Float.class)); - customXPPerk.setCustomXPValue(primarySkillType, boostValue); - } catch (InvalidSkillException e) { - mcMMO.p.getLogger().info("Custom XP perk has a skill defined that was not found, did you misspell it?"); - e.printStackTrace(); - } catch (ObjectMappingException e) { - e.printStackTrace(); - } - } + customXPPerk.setCustomXPMultiplierMap(xpBoostHashMap); return customXPPerk; } @@ -44,7 +38,9 @@ public class CustomXPPerkSerializer implements TypeSerializer { public void serialize(@NonNull TypeToken type, @Nullable CustomXPPerk obj, @NonNull ConfigurationNode value) throws ObjectMappingException { String name = obj.getPerkName(); - value.getNode("name").setValue(name); + HashMap xpBoostMap = new HashMap<>(); + + value.getNode(PERK_NAME).setValue(name); for (PrimarySkillType primarySkillType : PrimarySkillType.values()) { float xpMultValue = obj.getXPMultiplierValue(primarySkillType); @@ -53,9 +49,10 @@ public class CustomXPPerkSerializer implements TypeSerializer { if (xpMultValue == 1.0F) continue; - //Set value - value.getNode("name").getNode(StringUtils.getCapitalized(primarySkillType.toString())).setValue(xpMultValue); + xpBoostMap.put(primarySkillType, obj.getXPMultiplierValue(primarySkillType)); } + + value.getNode(XP_BOOST_NODE_ROOT).setValue(xpBoostMap); } private PrimarySkillType matchIgnoreCase(String string) throws InvalidSkillException { @@ -66,10 +63,4 @@ public class CustomXPPerkSerializer implements TypeSerializer { throw new InvalidSkillException(string); } - - /* - CustomXPPerk customXPPerk = new CustomXPPerk("examplecustomxpperk"); - customXPPerk.setCustomXPValue(PrimarySkillType.MINING, 13.37f); - customXPPerk.setCustomXPValue(PrimarySkillType.WOODCUTTING, 4.0f); - */ } diff --git a/src/main/java/com/gmail/nossr50/datatypes/experience/CustomXPPerk.java b/src/main/java/com/gmail/nossr50/datatypes/experience/CustomXPPerk.java index ba9faedec..f74e5d44e 100644 --- a/src/main/java/com/gmail/nossr50/datatypes/experience/CustomXPPerk.java +++ b/src/main/java/com/gmail/nossr50/datatypes/experience/CustomXPPerk.java @@ -47,6 +47,14 @@ public class CustomXPPerk { return perkName; } + /** + * Set the custom XP multiplier map for this perk (this will override all values currently held) + * @param customXPMultiplierMap new custom xp multiplier map + */ + public void setCustomXPMultiplierMap(HashMap customXPMultiplierMap) { + this.customXPMultiplierMap = customXPMultiplierMap; + } + /** * Get the address of this custom XP perk permission * This is the fully qualified name for this permission