From e5592919b70676659598e73679e8da7fb13d5ce9 Mon Sep 17 00:00:00 2001 From: nossr50 Date: Tue, 4 Jun 2019 14:58:17 -0700 Subject: [PATCH] Add SkillRankProperty serializer --- .../gmail/nossr50/config/ConfigManager.java | 2 + .../com/gmail/nossr50/config/MainConfig.java | 177 ------------------ .../config/hocon/SkillCeilingSerializer.java | 4 +- .../hocon/SkillRankPropertySerializer.java | 46 +++++ .../hocon/skills/ranks/SkillRankProperty.java | 8 + .../nossr50/datatypes/LimitedSizeList.java | 3 +- .../nossr50/util/TextComponentFactory.java | 6 +- .../gmail/nossr50/util/skills/RankUtils.java | 2 +- 8 files changed, 63 insertions(+), 185 deletions(-) create mode 100644 src/main/java/com/gmail/nossr50/config/hocon/SkillRankPropertySerializer.java diff --git a/src/main/java/com/gmail/nossr50/config/ConfigManager.java b/src/main/java/com/gmail/nossr50/config/ConfigManager.java index 27576a86e..1686d5241 100644 --- a/src/main/java/com/gmail/nossr50/config/ConfigManager.java +++ b/src/main/java/com/gmail/nossr50/config/ConfigManager.java @@ -33,6 +33,7 @@ import com.gmail.nossr50.config.hocon.skills.fishing.ConfigFishing; import com.gmail.nossr50.config.hocon.skills.herbalism.ConfigHerbalism; import com.gmail.nossr50.config.hocon.skills.mining.ConfigMining; import com.gmail.nossr50.config.hocon.skills.ranks.ConfigRanks; +import com.gmail.nossr50.config.hocon.skills.ranks.SkillRankProperty; import com.gmail.nossr50.config.hocon.skills.repair.ConfigRepair; import com.gmail.nossr50.config.hocon.skills.salvage.ConfigSalvage; import com.gmail.nossr50.config.hocon.skills.smelting.ConfigSmelting; @@ -267,6 +268,7 @@ public final class ConfigManager { customSerializers.registerType(TypeToken.of(CustomXPPerk.class), new CustomXPPerkSerializer()); customSerializers.registerType(TypeToken.of(DamageProperty.class), new DamagePropertySerializer()); customSerializers.registerType(TypeToken.of(SkillCeiling.class), new SkillCeilingSerializer()); + customSerializers.registerType(TypeToken.of(SkillRankProperty.class), new SkillRankPropertySerializer()); } /** diff --git a/src/main/java/com/gmail/nossr50/config/MainConfig.java b/src/main/java/com/gmail/nossr50/config/MainConfig.java index d7b49398c..414abb829 100644 --- a/src/main/java/com/gmail/nossr50/config/MainConfig.java +++ b/src/main/java/com/gmail/nossr50/config/MainConfig.java @@ -232,183 +232,6 @@ public class MainConfig extends ConfigValidated { public List validateKeys() { // Validate all the settings! List reason = new ArrayList<>(); - - /* General Settings */ - /*if (getSaveInterval() <= 0) { - reason.add(GENERAL + SAVE_INTERVAL + " should be greater than 0!"); - }*/ - - /* MySQL Settings */ - /*for (SQLDatabaseManager.PoolIdentifier identifier : SQLDatabaseManager.PoolIdentifier.values()) { - if (getMySQLMaxConnections(identifier) <= 0) { - reason.add(MY_SQL + "." + DATABASE + "." + MAX_CONNECTIONS + "." + StringUtils.getCapitalized(identifier.toString()) + " should be greater than 0!"); - } - if (getMySQLMaxPoolSize(identifier) <= 0) { - reason.add(MY_SQL + "." + DATABASE + "." + MAX_POOL_SIZE + "." + StringUtils.getCapitalized(identifier.toString()) + " should be greater than 0!"); - } - }*/ - - /* Mob Healthbar */ - if (mcMMO.getConfigManager().getConfigMobs().getCombat().getHealthBars().getDisplayTimeSeconds() == 0) { - reason.add(MOB_HEALTHBAR + "." + DISPLAY_TIME + " cannot be 0! Set to -1 to disable or set a valid value."); - } - - /* Scoreboards */ - /*if (getRankScoreboardTime() != -1 && getRankScoreboardTime() <= 0) { - reason.add("ConfigScoreboard.Types.Rank.Display_Time should be greater than 0, or -1!"); - } - - if (getStatsScoreboardTime() != -1 && getStatsScoreboardTime() <= 0) { - reason.add("ConfigScoreboard.Types.Stats.Display_Time should be greater than 0, or -1!"); - } - - if (getTopScoreboardTime() != -1 && getTopScoreboardTime() <= 0) { - reason.add("ConfigScoreboard.Types.Top.Display_Time should be greater than 0, or -1!"); - } - - if (getInspectScoreboardTime() != -1 && getInspectScoreboardTime() <= 0) { - reason.add("ConfigScoreboard.Types.Inspect.Display_Time should be greater than 0, or -1!"); - } - - if (getSkillScoreboardTime() != -1 && getSkillScoreboardTime() <= 0) { - reason.add("ConfigScoreboard.Types.Skill.Display_Time should be greater than 0, or -1!"); - } - - if (getSkillLevelUpTime() != -1 && getSkillScoreboardTime() <= 0) { - reason.add("ConfigScoreboard.Types.Skill.Display_Time should be greater than 0, or -1!"); - } - - if (!(getRankUseChat() || getRankUseBoard())) { - reason.add("Either Board or Print in ConfigScoreboard.Types.Rank must be true!"); - } - - if (!(getTopUseChat() || getTopUseBoard())) { - reason.add("Either Board or Print in ConfigScoreboard.Types.Top must be true!"); - } - - if (!(getStatsUseChat() || getStatsUseBoard())) { - reason.add("Either Board or Print in ConfigScoreboard.Types.Stats must be true!"); - } - - if (!(getInspectUseChat() || getInspectUseBoard())) { - reason.add("Either Board or Print in ConfigScoreboard.Types.Inspect must be true!"); - }*/ - - /* Hardcore Mode */ - if (getHardcoreDeathStatPenaltyPercentage() < 0.01 || getHardcoreDeathStatPenaltyPercentage() > 100) { - reason.add(HARDCORE + "." + DEATH_STAT_LOSS + "." + PENALTY_PERCENTAGE + " only accepts values from 0.01 to 100!"); - } - - if (getHardcoreVampirismStatLeechPercentage() < 0.01 || getHardcoreVampirismStatLeechPercentage() > 100) { - reason.add(HARDCORE + "." + VAMPIRISM + "." + LEECH_PERCENTAGE + " only accepts values from 0.01 to 100!"); - } - - /* Items */ - if (getChimaeraUseCost() < 1 || getChimaeraUseCost() > 64) { - reason.add(ITEMS + "." + CHIMAERA_WING + "." + USE_COST + " only accepts values from 1 to 64!"); - } - - if (getChimaeraRecipeCost() < 1 || getChimaeraRecipeCost() > 9) { - reason.add(ITEMS + "." + CHIMAERA_WING + "." + RECIPE_COST + " only accepts values from 1 to 9!"); - } - - if (getChimaeraItem() == null) { - reason.add(ITEMS + "." + CHIMAERA_WING + "." + ITEM + NAME + " is invalid!"); - } - - /* Particles */ - if (getLevelUpEffectsTier() < 1) { - reason.add(PARTICLES + "." + LEVEL_UP + "Tier should be at least 1!"); - } - - /* PARTY SETTINGS */ - /*if (getAutoPartyKickInterval() < -1) { - reason.add(PARTY + "." + AUTO_KICK_INTERVAL + " should be at least -1!"); - } - - if (getAutoPartyKickTime() < 0) { - reason.add(PARTY + "." + OLD_PARTY_MEMBER_CUTOFF + " should be at least 0!"); - } - - if (getPartyShareBonusBase() <= 0) { - reason.add(PARTY + "." + SHARING_EXP_SHARE_BONUS_BASE + " should be greater than 0!"); - } - - if (getPartyShareBonusIncrease() < 0) { - reason.add(PARTY + "." + SHARING + "." + EXP_SHARE_BONUS_INCREASE + " should be at least 0!"); - } - - if (getPartyShareBonusCap() <= 0) { - reason.add(PARTY + "." + SHARING + "." + EXP_SHARE_BONUS_CAP + " should be greater than 0!"); - } - - if (getPartyShareRange() <= 0) { - reason.add(PARTY + "." + SHARING + "." + RANGE + " should be greater than 0!"); - }*/ - - /*if (getPartyXpCurveMultiplier() < 1) { - reason.add(PARTY + "." + LEVELING + "." + XP_CURVE_MODIFIER + " should be at least 1!"); - } - - for (PartyFeature partyFeature : PartyFeature.values()) { - if (PartyManager. < 0) { - reason.add(PARTY + "." + LEVELING + "." + StringUtils.getPrettyPartyFeatureString(partyFeature).replace(" ", "") + "_UnlockLevel should be at least 0!"); - } - }*/ - - - /*if (getTreeFellerThreshold() <= 0) { - reason.add(ABILITIES + "." + LIMITS + "." + TREE_FELLER_THRESHOLD + " should be greater than 0!"); - }*/ - - /*if (getRepairAnvilMaterial() == null) { - reason.add(SKILLS + "." + REPAIR + "." + ANVIL + "Type is invalid!!"); - } - - if (getSalvageAnvilMaterial() == null) { - reason.add(SKILLS + "." + REPAIR + "." + SALVAGE + "_" + ANVIL + "Type is invalid!"); - } - - if (getRepairAnvilMaterial() == getSalvageAnvilMaterial()) { - reason.add("Cannot use the same item for " + REPAIR + " and " + SALVAGE + " anvils!"); - }*/ - - if (getTamingCOTWMaterial(EntityType.WOLF) == null) { - reason.add(SKILLS + "." + TAMING + "." + CALL_OF_THE_WILD1 + ".Wolf." + ITEM + "Material is invalid!!"); - } - - if (getTamingCOTWMaterial(EntityType.OCELOT) == null) { - reason.add(SKILLS + "." + TAMING + "." + CALL_OF_THE_WILD1 + ".Ocelot." + ITEM + "Material is invalid!!"); - } - - if (getTamingCOTWMaterial(EntityType.HORSE) == null) { - reason.add(SKILLS + "." + TAMING + "." + CALL_OF_THE_WILD1 + ".Horse." + ITEM + "Material is invalid!!"); - } - - if (getTamingCOTWCost(EntityType.WOLF) <= 0) { - reason.add(SKILLS + "." + TAMING + "." + CALL_OF_THE_WILD1 + ".Wolf." + ITEM + "Amount should be greater than 0!"); - } - - if (getTamingCOTWCost(EntityType.OCELOT) <= 0) { - reason.add(SKILLS + "." + TAMING + "." + CALL_OF_THE_WILD1 + ".Ocelot." + ITEM + "Amount should be greater than 0!"); - } - - if (getTamingCOTWCost(EntityType.HORSE) <= 0) { - reason.add(SKILLS + "." + TAMING + "." + CALL_OF_THE_WILD1 + ".Horse." + ITEM + "Amount should be greater than 0!"); - } - - if (getTamingCOTWAmount(EntityType.WOLF) <= 0) { - reason.add(SKILLS + "." + TAMING + "." + CALL_OF_THE_WILD1 + ".Wolf." + SUMMON_AMOUNT + " should be greater than 0!"); - } - - if (getTamingCOTWAmount(EntityType.OCELOT) <= 0) { - reason.add(SKILLS + "." + TAMING + "." + CALL_OF_THE_WILD1 + ".Ocelot." + SUMMON_AMOUNT + " should be greater than 0!"); - } - - if (getTamingCOTWAmount(EntityType.HORSE) <= 0) { - reason.add(SKILLS + "." + TAMING + "." + CALL_OF_THE_WILD1 + ".Horse." + SUMMON_AMOUNT + " should be greater than 0!"); - } - return reason; } diff --git a/src/main/java/com/gmail/nossr50/config/hocon/SkillCeilingSerializer.java b/src/main/java/com/gmail/nossr50/config/hocon/SkillCeilingSerializer.java index 2613e6ee5..92360440c 100644 --- a/src/main/java/com/gmail/nossr50/config/hocon/SkillCeilingSerializer.java +++ b/src/main/java/com/gmail/nossr50/config/hocon/SkillCeilingSerializer.java @@ -11,8 +11,8 @@ import org.checkerframework.checker.nullness.qual.Nullable; public class SkillCeilingSerializer implements TypeSerializer { - public static final String STANDARD_MAX_LEVEL = "Standard-Max-Level"; - public static final String RETRO_MAX_LEVEL = "Retro-Max-Level"; + private static final String STANDARD_MAX_LEVEL = "Standard-Max-Level"; + private static final String RETRO_MAX_LEVEL = "Retro-Max-Level"; @Nullable @Override diff --git a/src/main/java/com/gmail/nossr50/config/hocon/SkillRankPropertySerializer.java b/src/main/java/com/gmail/nossr50/config/hocon/SkillRankPropertySerializer.java new file mode 100644 index 000000000..5abe0f645 --- /dev/null +++ b/src/main/java/com/gmail/nossr50/config/hocon/SkillRankPropertySerializer.java @@ -0,0 +1,46 @@ +package com.gmail.nossr50.config.hocon; + +import com.gmail.nossr50.config.hocon.skills.ranks.SkillRankProperty; +import com.gmail.nossr50.mcMMO; +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; + +import java.util.HashMap; +import java.util.Map; + +public class SkillRankPropertySerializer implements TypeSerializer { + + private static final String STANDARD_RANK_UNLOCK_LEVEL_REQUIREMENTS = "Standard-Rank-Unlock-Level-Requirements"; + private static final String RETRO_RANK_UNLOCK_LEVEL_REQUIREMENTS = "Retro-Rank-Unlock-Level-Requirements"; + + @Nullable + @Override + public SkillRankProperty deserialize(@NonNull TypeToken type, @NonNull ConfigurationNode value) throws ObjectMappingException { + HashMap standardMap; + HashMap retroMap; + + try { + standardMap = (HashMap) value.getNode(STANDARD_RANK_UNLOCK_LEVEL_REQUIREMENTS).getValue(new TypeToken>() {}); + retroMap = (HashMap) value.getNode(RETRO_RANK_UNLOCK_LEVEL_REQUIREMENTS).getValue(new TypeToken>() {}); + } catch (ObjectMappingException e) { + mcMMO.p.getLogger().severe("Unable to deserialize rank property information from the config, make sure the ranks are correctly set in the config. You can delete the rank config to generate a new one if problems persist."); + throw e; + } + + SkillRankProperty skillRankProperty = new SkillRankProperty(); + skillRankProperty.setStandardRanks(standardMap); + skillRankProperty.setRetroRanks(retroMap); + + return skillRankProperty; + } + + @Override + public void serialize(@NonNull TypeToken type, @Nullable SkillRankProperty obj, @NonNull ConfigurationNode value) throws ObjectMappingException { + value.getNode(STANDARD_RANK_UNLOCK_LEVEL_REQUIREMENTS).setValue(obj.getStandardRanks()); + value.getNode(RETRO_RANK_UNLOCK_LEVEL_REQUIREMENTS).setValue(obj.getStandardRanks()); + } +} diff --git a/src/main/java/com/gmail/nossr50/config/hocon/skills/ranks/SkillRankProperty.java b/src/main/java/com/gmail/nossr50/config/hocon/skills/ranks/SkillRankProperty.java index 25e3afcd8..4e568420d 100644 --- a/src/main/java/com/gmail/nossr50/config/hocon/skills/ranks/SkillRankProperty.java +++ b/src/main/java/com/gmail/nossr50/config/hocon/skills/ranks/SkillRankProperty.java @@ -72,4 +72,12 @@ public class SkillRankProperty implements SkillProperty { public void setRetroRanks(HashMap retroRanks) { this.retroRanks = retroRanks; } + + public HashMap getStandardRanks() { + return standardRanks; + } + + public HashMap getRetroRanks() { + return retroRanks; + } } diff --git a/src/main/java/com/gmail/nossr50/datatypes/LimitedSizeList.java b/src/main/java/com/gmail/nossr50/datatypes/LimitedSizeList.java index c969140a7..baa43f633 100644 --- a/src/main/java/com/gmail/nossr50/datatypes/LimitedSizeList.java +++ b/src/main/java/com/gmail/nossr50/datatypes/LimitedSizeList.java @@ -5,8 +5,7 @@ import org.bukkit.Location; public class LimitedSizeList { private final int size; - public Location[] limitedSizeOrderedList; - + private Location[] limitedSizeOrderedList; public LimitedSizeList(int size) { this.size = size; diff --git a/src/main/java/com/gmail/nossr50/util/TextComponentFactory.java b/src/main/java/com/gmail/nossr50/util/TextComponentFactory.java index f57fbc12d..d5fdd82aa 100644 --- a/src/main/java/com/gmail/nossr50/util/TextComponentFactory.java +++ b/src/main/java/com/gmail/nossr50/util/TextComponentFactory.java @@ -427,14 +427,14 @@ public class TextComponentFactory { private static void addLocked(SubSkillType subSkillType, ChatColor ccLocked, ChatColor ccLevelRequirement, ChatColor ccLevelRequired, ComponentBuilder componentBuilder) { addLocked(ccLocked, ccLevelRequirement, componentBuilder); - componentBuilder.append(String.valueOf(RankConfig.getInstance().getSubSkillUnlockLevel(subSkillType, 1))).color(ccLevelRequired); + componentBuilder.append(String.valueOf(RankUtils.getSubSkillUnlockLevel(subSkillType, 1))).color(ccLevelRequired); //componentBuilder.append("\n"); } private static void addLocked(AbstractSubSkill abstractSubSkill, ChatColor ccLocked, ChatColor ccLevelRequirement, ChatColor ccLevelRequired, ComponentBuilder componentBuilder) { addLocked(ccLocked, ccLevelRequirement, componentBuilder); - componentBuilder.append(String.valueOf(RankConfig.getInstance().getSubSkillUnlockLevel(abstractSubSkill, 1))).color(ccLevelRequired); - //componentBuilder.append("\n"); + componentBuilder.append(String.valueOf(RankUtils.getSubSkillUnlockLevel(abstractSubSkill, 1))).color(ccLevelRequired); + //componentBuilder.append("\n");m } private static void addLocked(ChatColor ccLocked, ChatColor ccLevelRequirement, ComponentBuilder componentBuilder) { diff --git a/src/main/java/com/gmail/nossr50/util/skills/RankUtils.java b/src/main/java/com/gmail/nossr50/util/skills/RankUtils.java index 75dc9e593..96c8f712d 100644 --- a/src/main/java/com/gmail/nossr50/util/skills/RankUtils.java +++ b/src/main/java/com/gmail/nossr50/util/skills/RankUtils.java @@ -26,7 +26,7 @@ public class RankUtils { /** * @param plugin plugin instance ref * @param mcMMOPlayer target player - * @param primarySkillType + * @param primarySkillType target primary skill * @param newLevel the new level of this skill */ public static void executeSkillUnlockNotifications(Plugin plugin, McMMOPlayer mcMMOPlayer, PrimarySkillType primarySkillType, int newLevel) {