Add SkillRankProperty serializer

This commit is contained in:
nossr50 2019-06-04 14:58:17 -07:00
parent b2dc322a2b
commit e5592919b7
8 changed files with 63 additions and 185 deletions

View File

@ -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.herbalism.ConfigHerbalism;
import com.gmail.nossr50.config.hocon.skills.mining.ConfigMining; 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.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.repair.ConfigRepair;
import com.gmail.nossr50.config.hocon.skills.salvage.ConfigSalvage; import com.gmail.nossr50.config.hocon.skills.salvage.ConfigSalvage;
import com.gmail.nossr50.config.hocon.skills.smelting.ConfigSmelting; 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(CustomXPPerk.class), new CustomXPPerkSerializer());
customSerializers.registerType(TypeToken.of(DamageProperty.class), new DamagePropertySerializer()); customSerializers.registerType(TypeToken.of(DamageProperty.class), new DamagePropertySerializer());
customSerializers.registerType(TypeToken.of(SkillCeiling.class), new SkillCeilingSerializer()); customSerializers.registerType(TypeToken.of(SkillCeiling.class), new SkillCeilingSerializer());
customSerializers.registerType(TypeToken.of(SkillRankProperty.class), new SkillRankPropertySerializer());
} }
/** /**

View File

@ -232,183 +232,6 @@ public class MainConfig extends ConfigValidated {
public List<String> validateKeys() { public List<String> validateKeys() {
// Validate all the settings! // Validate all the settings!
List<String> reason = new ArrayList<>(); List<String> 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; return reason;
} }

View File

@ -11,8 +11,8 @@ import org.checkerframework.checker.nullness.qual.Nullable;
public class SkillCeilingSerializer implements TypeSerializer<SkillCeiling> { public class SkillCeilingSerializer implements TypeSerializer<SkillCeiling> {
public static final String STANDARD_MAX_LEVEL = "Standard-Max-Level"; private static final String STANDARD_MAX_LEVEL = "Standard-Max-Level";
public static final String RETRO_MAX_LEVEL = "Retro-Max-Level"; private static final String RETRO_MAX_LEVEL = "Retro-Max-Level";
@Nullable @Nullable
@Override @Override

View File

@ -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<SkillRankProperty> {
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<Integer, Integer> standardMap;
HashMap<Integer, Integer> retroMap;
try {
standardMap = (HashMap<Integer, Integer>) value.getNode(STANDARD_RANK_UNLOCK_LEVEL_REQUIREMENTS).getValue(new TypeToken<Map<?, ?>>() {});
retroMap = (HashMap<Integer, Integer>) value.getNode(RETRO_RANK_UNLOCK_LEVEL_REQUIREMENTS).getValue(new TypeToken<Map<?, ?>>() {});
} 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());
}
}

View File

@ -72,4 +72,12 @@ public class SkillRankProperty implements SkillProperty {
public void setRetroRanks(HashMap<Integer, Integer> retroRanks) { public void setRetroRanks(HashMap<Integer, Integer> retroRanks) {
this.retroRanks = retroRanks; this.retroRanks = retroRanks;
} }
public HashMap<Integer, Integer> getStandardRanks() {
return standardRanks;
}
public HashMap<Integer, Integer> getRetroRanks() {
return retroRanks;
}
} }

View File

@ -5,8 +5,7 @@ import org.bukkit.Location;
public class LimitedSizeList { public class LimitedSizeList {
private final int size; private final int size;
public Location[] limitedSizeOrderedList; private Location[] limitedSizeOrderedList;
public LimitedSizeList(int size) { public LimitedSizeList(int size) {
this.size = size; this.size = size;

View File

@ -427,14 +427,14 @@ public class TextComponentFactory {
private static void addLocked(SubSkillType subSkillType, ChatColor ccLocked, ChatColor ccLevelRequirement, ChatColor ccLevelRequired, ComponentBuilder componentBuilder) { private static void addLocked(SubSkillType subSkillType, ChatColor ccLocked, ChatColor ccLevelRequirement, ChatColor ccLevelRequired, ComponentBuilder componentBuilder) {
addLocked(ccLocked, ccLevelRequirement, 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"); //componentBuilder.append("\n");
} }
private static void addLocked(AbstractSubSkill abstractSubSkill, ChatColor ccLocked, ChatColor ccLevelRequirement, ChatColor ccLevelRequired, ComponentBuilder componentBuilder) { private static void addLocked(AbstractSubSkill abstractSubSkill, ChatColor ccLocked, ChatColor ccLevelRequirement, ChatColor ccLevelRequired, ComponentBuilder componentBuilder) {
addLocked(ccLocked, ccLevelRequirement, componentBuilder); addLocked(ccLocked, ccLevelRequirement, componentBuilder);
componentBuilder.append(String.valueOf(RankConfig.getInstance().getSubSkillUnlockLevel(abstractSubSkill, 1))).color(ccLevelRequired); componentBuilder.append(String.valueOf(RankUtils.getSubSkillUnlockLevel(abstractSubSkill, 1))).color(ccLevelRequired);
//componentBuilder.append("\n"); //componentBuilder.append("\n");m
} }
private static void addLocked(ChatColor ccLocked, ChatColor ccLevelRequirement, ComponentBuilder componentBuilder) { private static void addLocked(ChatColor ccLocked, ChatColor ccLevelRequirement, ComponentBuilder componentBuilder) {

View File

@ -26,7 +26,7 @@ public class RankUtils {
/** /**
* @param plugin plugin instance ref * @param plugin plugin instance ref
* @param mcMMOPlayer target player * @param mcMMOPlayer target player
* @param primarySkillType * @param primarySkillType target primary skill
* @param newLevel the new level of this skill * @param newLevel the new level of this skill
*/ */
public static void executeSkillUnlockNotifications(Plugin plugin, McMMOPlayer mcMMOPlayer, PrimarySkillType primarySkillType, int newLevel) { public static void executeSkillUnlockNotifications(Plugin plugin, McMMOPlayer mcMMOPlayer, PrimarySkillType primarySkillType, int newLevel) {