From 48a3621ac61147b7ea03830e1430a54e83cd045c Mon Sep 17 00:00:00 2001 From: nossr50 Date: Fri, 10 May 2019 09:49:43 -0700 Subject: [PATCH] Avoid race conditions --- .../gmail/nossr50/config/ConfigManager.java | 8 ++++- .../config/hocon/CustomXPPerkSerializer.java | 1 - .../config/hocon/SerializedConfigLoader.java | 10 +++++- .../hocon/experience/ConfigExperience.java | 3 +- .../ConfigExperienceCustomBoosts.java | 10 +++--- .../ConfigExperienceSkillMultiplier.java | 24 ++++++++----- .../ConfigExperienceFormula.java | 34 ++++++++++++------- .../ConfigExperienceFormulaExponential.java | 12 +++---- .../ConfigExperienceFormulaLinear.java | 6 ++-- .../nossr50/skills/mining/MiningManager.java | 1 - 10 files changed, 69 insertions(+), 40 deletions(-) diff --git a/src/main/java/com/gmail/nossr50/config/ConfigManager.java b/src/main/java/com/gmail/nossr50/config/ConfigManager.java index c99bd71ad..901dae3e1 100644 --- a/src/main/java/com/gmail/nossr50/config/ConfigManager.java +++ b/src/main/java/com/gmail/nossr50/config/ConfigManager.java @@ -206,6 +206,13 @@ public final class ConfigManager { } private void initSerializedConfigs() { + //There's some race conditions here because mcMMO is goddamn spaghetti mess, language has to load first + configLanguage = new SerializedConfigLoader<>(ConfigLanguage.class, "language.conf", "Language", null); + + /* + * No more race conditions + */ + configDatabase = new SerializedConfigLoader<>(ConfigDatabase.class, "database_settings.conf", "Database", null); configScoreboard = new SerializedConfigLoader<>(ConfigScoreboard.class, "scoreboard.conf", "Scoreboard", null); configLeveling = new SerializedConfigLoader<>(ConfigLeveling.class, "player_leveling.conf", "Player-Leveling", null); @@ -218,7 +225,6 @@ public final class ConfigManager { configAutomatedBackups = new SerializedConfigLoader<>(ConfigAutomatedBackups.class, "automated_backups.conf", "Automated-Backups", null); configCommands = new SerializedConfigLoader<>(ConfigCommands.class, "commands.conf", "Commands", null); configItems = new SerializedConfigLoader<>(ConfigItems.class, "custom_items.conf", "Items", null); - configLanguage = new SerializedConfigLoader<>(ConfigLanguage.class, "language.conf", "Language", null); configParticles = new SerializedConfigLoader<>(ConfigParticles.class, "particle_spawning.conf", "Particles", null); configParty = new SerializedConfigLoader<>(ConfigParty.class, "party.conf", "Party", null); configNotifications = new SerializedConfigLoader<>(ConfigNotifications.class, "alerts_and_notifications.conf", "Notifications", null); diff --git a/src/main/java/com/gmail/nossr50/config/hocon/CustomXPPerkSerializer.java b/src/main/java/com/gmail/nossr50/config/hocon/CustomXPPerkSerializer.java index be1fe1aa3..fcb4846c9 100644 --- a/src/main/java/com/gmail/nossr50/config/hocon/CustomXPPerkSerializer.java +++ b/src/main/java/com/gmail/nossr50/config/hocon/CustomXPPerkSerializer.java @@ -5,7 +5,6 @@ import com.gmail.nossr50.datatypes.experience.CustomXPPerk; import com.gmail.nossr50.datatypes.skills.PrimarySkillType; import com.gmail.nossr50.mcMMO; import com.gmail.nossr50.util.StringUtils; -import com.google.common.reflect.TypeResolver; 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/SerializedConfigLoader.java b/src/main/java/com/gmail/nossr50/config/hocon/SerializedConfigLoader.java index 7408421b3..ee03c62a6 100644 --- a/src/main/java/com/gmail/nossr50/config/hocon/SerializedConfigLoader.java +++ b/src/main/java/com/gmail/nossr50/config/hocon/SerializedConfigLoader.java @@ -101,7 +101,15 @@ public class SerializedConfigLoader { .setDefaultOptions(configurationOptions) .build(); - this.configMapper = ObjectMapper.forClass(clazz).bindToNew(); + //Catch errors + try { + this.configMapper = ObjectMapper.forClass(clazz).bindToNew(); + } catch (ObjectMappingException e) { + if(e.getMessage() != null) + System.out.println(e.getMessage()); + + e.printStackTrace(); + } reload(); save(); diff --git a/src/main/java/com/gmail/nossr50/config/hocon/experience/ConfigExperience.java b/src/main/java/com/gmail/nossr50/config/hocon/experience/ConfigExperience.java index 8d4e2d8a7..270b5fce3 100644 --- a/src/main/java/com/gmail/nossr50/config/hocon/experience/ConfigExperience.java +++ b/src/main/java/com/gmail/nossr50/config/hocon/experience/ConfigExperience.java @@ -4,6 +4,7 @@ import com.gmail.nossr50.datatypes.experience.CustomXPPerk; import ninja.leaping.configurate.objectmapping.Setting; import ninja.leaping.configurate.objectmapping.serialize.ConfigSerializable; +import java.util.ArrayList; import java.util.HashMap; import java.util.HashSet; @@ -30,7 +31,7 @@ public class ConfigExperience { * BOILER PLATE GETTERS */ - public HashSet getCustomXPBoosts() { + public ArrayList getCustomXPBoosts() { return configExperienceCustomBoosts.getCustomXPBoosts(); } diff --git a/src/main/java/com/gmail/nossr50/config/hocon/experience/ConfigExperienceCustomBoosts.java b/src/main/java/com/gmail/nossr50/config/hocon/experience/ConfigExperienceCustomBoosts.java index d2f26fe12..6f1eab2cc 100644 --- a/src/main/java/com/gmail/nossr50/config/hocon/experience/ConfigExperienceCustomBoosts.java +++ b/src/main/java/com/gmail/nossr50/config/hocon/experience/ConfigExperienceCustomBoosts.java @@ -5,15 +5,15 @@ import com.gmail.nossr50.datatypes.skills.PrimarySkillType; import ninja.leaping.configurate.objectmapping.Setting; import ninja.leaping.configurate.objectmapping.serialize.ConfigSerializable; -import java.util.HashSet; +import java.util.ArrayList; @ConfigSerializable public class ConfigExperienceCustomBoosts { - private static final HashSet CUSTOM_BOOST_SET_DEFAULT; + private static final ArrayList CUSTOM_BOOST_SET_DEFAULT; static { - CUSTOM_BOOST_SET_DEFAULT = new HashSet<>(); + CUSTOM_BOOST_SET_DEFAULT = new ArrayList<>(); CustomXPPerk customXPPerk = new CustomXPPerk("examplecustomxpperk"); customXPPerk.setCustomXPValue(PrimarySkillType.MINING, 13.37f); customXPPerk.setCustomXPValue(PrimarySkillType.WOODCUTTING, 4.0f); @@ -23,9 +23,9 @@ public class ConfigExperienceCustomBoosts { @Setting(value = "Custom-Global-XP-Permissions", comment = "You can give custom global xp perks to players by adding 'mcmmo.customperks.xp.' to your players" + "\nEnter the name of a permission node and the value of the XP boost that permission node should have." + "\nPlayers do not benefit from custom xp perks without being assigned positive permission nodes for said xp perks") - private HashSet customXPBoosts = CUSTOM_BOOST_SET_DEFAULT; + private ArrayList customXPBoosts = CUSTOM_BOOST_SET_DEFAULT; - public HashSet getCustomXPBoosts() { + public ArrayList getCustomXPBoosts() { return customXPBoosts; } } diff --git a/src/main/java/com/gmail/nossr50/config/hocon/experience/ConfigExperienceSkillMultiplier.java b/src/main/java/com/gmail/nossr50/config/hocon/experience/ConfigExperienceSkillMultiplier.java index 0f4e4941a..f4f876714 100644 --- a/src/main/java/com/gmail/nossr50/config/hocon/experience/ConfigExperienceSkillMultiplier.java +++ b/src/main/java/com/gmail/nossr50/config/hocon/experience/ConfigExperienceSkillMultiplier.java @@ -3,26 +3,34 @@ package com.gmail.nossr50.config.hocon.experience; import com.gmail.nossr50.datatypes.skills.PrimarySkillType; import ninja.leaping.configurate.objectmapping.Setting; import ninja.leaping.configurate.objectmapping.serialize.ConfigSerializable; +import static com.gmail.nossr50.datatypes.skills.PrimarySkillType.*; import java.util.HashMap; @ConfigSerializable public class ConfigExperienceSkillMultiplier { - private static final HashMap SKILL_GLOBAL_MULT_DEFAULT; + private static final HashMap SKILL_GLOBAL_MULT_DEFAULT; static { SKILL_GLOBAL_MULT_DEFAULT = new HashMap<>(); - for (PrimarySkillType primarySkillType : PrimarySkillType.values()) { - if (primarySkillType.isChildSkill()) - continue; - - SKILL_GLOBAL_MULT_DEFAULT.put(primarySkillType, 1.0D); - } + SKILL_GLOBAL_MULT_DEFAULT.put(ACROBATICS, 1.0f); + SKILL_GLOBAL_MULT_DEFAULT.put(ALCHEMY, 1.0f); + SKILL_GLOBAL_MULT_DEFAULT.put(ARCHERY, 1.0f); + SKILL_GLOBAL_MULT_DEFAULT.put(AXES, 1.0f); + SKILL_GLOBAL_MULT_DEFAULT.put(EXCAVATION, 1.0f); + SKILL_GLOBAL_MULT_DEFAULT.put(FISHING, 1.0f); + SKILL_GLOBAL_MULT_DEFAULT.put(HERBALISM, 1.0f); + SKILL_GLOBAL_MULT_DEFAULT.put(MINING, 1.0f); + SKILL_GLOBAL_MULT_DEFAULT.put(REPAIR, 1.0f); + SKILL_GLOBAL_MULT_DEFAULT.put(SWORDS, 1.0f); + SKILL_GLOBAL_MULT_DEFAULT.put(TAMING, 1.0f); + SKILL_GLOBAL_MULT_DEFAULT.put(UNARMED, 1.0f); + SKILL_GLOBAL_MULT_DEFAULT.put(WOODCUTTING, 1.0f); } @Setting(value = "Skill-XP-Multipliers") - private HashMap perSkillGlobalMultiplier = SKILL_GLOBAL_MULT_DEFAULT; + private HashMap perSkillGlobalMultiplier = SKILL_GLOBAL_MULT_DEFAULT; public double getSkillGlobalMultiplier(PrimarySkillType primarySkillType) { return perSkillGlobalMultiplier.get(primarySkillType); diff --git a/src/main/java/com/gmail/nossr50/config/hocon/playerleveling/ConfigExperienceFormula.java b/src/main/java/com/gmail/nossr50/config/hocon/playerleveling/ConfigExperienceFormula.java index 59a0b5dc7..eea151bac 100644 --- a/src/main/java/com/gmail/nossr50/config/hocon/playerleveling/ConfigExperienceFormula.java +++ b/src/main/java/com/gmail/nossr50/config/hocon/playerleveling/ConfigExperienceFormula.java @@ -11,16 +11,24 @@ import java.util.HashMap; public class ConfigExperienceFormula { public static final boolean CUMULATIVE_CURVE_DEFAULT = false; - private static final HashMap SKILL_FORMULA_MODIFIER_DEFAULT; + private static final HashMap SKILL_FORMULA_MODIFIER_DEFAULT; static { SKILL_FORMULA_MODIFIER_DEFAULT = new HashMap<>(); - for (PrimarySkillType primarySkillType : PrimarySkillType.values()) { - if (primarySkillType.isChildSkill()) - continue; - - SKILL_FORMULA_MODIFIER_DEFAULT.put(primarySkillType, 1.0D); - } + //TODO: This code is causing compiler issues + SKILL_FORMULA_MODIFIER_DEFAULT.put(PrimarySkillType.ACROBATICS, 1.0f); + SKILL_FORMULA_MODIFIER_DEFAULT.put(PrimarySkillType.ALCHEMY, 1.0f); + SKILL_FORMULA_MODIFIER_DEFAULT.put(PrimarySkillType.AXES, 1.0f); + SKILL_FORMULA_MODIFIER_DEFAULT.put(PrimarySkillType.ARCHERY, 1.0f); + SKILL_FORMULA_MODIFIER_DEFAULT.put(PrimarySkillType.EXCAVATION, 1.0f); + SKILL_FORMULA_MODIFIER_DEFAULT.put(PrimarySkillType.FISHING, 1.0f); + SKILL_FORMULA_MODIFIER_DEFAULT.put(PrimarySkillType.HERBALISM, 1.0f); + SKILL_FORMULA_MODIFIER_DEFAULT.put(PrimarySkillType.MINING, 1.0f); + SKILL_FORMULA_MODIFIER_DEFAULT.put(PrimarySkillType.REPAIR, 1.0f); + SKILL_FORMULA_MODIFIER_DEFAULT.put(PrimarySkillType.SWORDS, 1.0f); + SKILL_FORMULA_MODIFIER_DEFAULT.put(PrimarySkillType.TAMING, 1.0f); + SKILL_FORMULA_MODIFIER_DEFAULT.put(PrimarySkillType.UNARMED, 1.0f); + SKILL_FORMULA_MODIFIER_DEFAULT.put(PrimarySkillType.WOODCUTTING, 1.0f); } @Setting(value = "Player-XP-Formula-Type", comment = "Determines which formula is used to determine XP needed to level" + @@ -42,13 +50,13 @@ public class ConfigExperienceFormula { @Setting(value = "Skill-Formula-Multipliers", comment = "The end result of how much XP is needed to level is determined by multiplying against this value" + "\nHigher values will make skills take longer to level, lower values will decrease time to level instead.") - private HashMap skillXpModifier = SKILL_FORMULA_MODIFIER_DEFAULT; + private HashMap skillXpModifier = SKILL_FORMULA_MODIFIER_DEFAULT; public FormulaType getFormulaType() { return formulaType; } - public double getSkillXpFormulaModifier(PrimarySkillType primarySkillType) { + public float getSkillXpFormulaModifier(PrimarySkillType primarySkillType) { return skillXpModifier.get(primarySkillType); } @@ -64,7 +72,7 @@ public class ConfigExperienceFormula { return configExperienceFormulaExponential; } - public double getMultiplier(FormulaType formulaType) { + public float getMultiplier(FormulaType formulaType) { switch (formulaType) { case LINEAR: return getLinearMultiplier(); @@ -90,11 +98,11 @@ public class ConfigExperienceFormula { return configExperienceFormulaExponential.getExponentialBaseModifier(); } - public double getExponentialMultiplier() { + public float getExponentialMultiplier() { return configExperienceFormulaExponential.getExponentialMultiplier(); } - public double getExponentialExponent() { + public float getExponentialExponent() { return configExperienceFormulaExponential.getExponentialExponent(); } @@ -102,7 +110,7 @@ public class ConfigExperienceFormula { return configExperienceFormulaLinear.getLinearBaseModifier(); } - public double getLinearMultiplier() { + public float getLinearMultiplier() { return configExperienceFormulaLinear.getLinearMultiplier(); } } \ No newline at end of file diff --git a/src/main/java/com/gmail/nossr50/config/hocon/playerleveling/ConfigExperienceFormulaExponential.java b/src/main/java/com/gmail/nossr50/config/hocon/playerleveling/ConfigExperienceFormulaExponential.java index fa96823c3..be721bc1d 100644 --- a/src/main/java/com/gmail/nossr50/config/hocon/playerleveling/ConfigExperienceFormulaExponential.java +++ b/src/main/java/com/gmail/nossr50/config/hocon/playerleveling/ConfigExperienceFormulaExponential.java @@ -7,27 +7,27 @@ import ninja.leaping.configurate.objectmapping.serialize.ConfigSerializable; public class ConfigExperienceFormulaExponential { private static final int BASE_DEFAULT = 2000; - private static final double MULTIPLIER_DEFAULT = 0.1; - private static final double EXPONENT_DEFAULT = 1.80; + private static final float MULTIPLIER_DEFAULT = 0.1f; + private static final float EXPONENT_DEFAULT = 1.80f; @Setting(value = "Base-Amount", comment = "Default value: " + BASE_DEFAULT) private int baseModifier = BASE_DEFAULT; @Setting(value = "Multiplier", comment = "Default value: " + MULTIPLIER_DEFAULT) - private double multiplier = MULTIPLIER_DEFAULT; + private float multiplier = MULTIPLIER_DEFAULT; @Setting(value = "Exponent", comment = "Default value: " + EXPONENT_DEFAULT) - private double exponent = EXPONENT_DEFAULT; + private float exponent = EXPONENT_DEFAULT; public int getExponentialBaseModifier() { return baseModifier; } - public double getExponentialMultiplier() { + public float getExponentialMultiplier() { return multiplier; } - public double getExponentialExponent() { + public float getExponentialExponent() { return exponent; } } \ No newline at end of file diff --git a/src/main/java/com/gmail/nossr50/config/hocon/playerleveling/ConfigExperienceFormulaLinear.java b/src/main/java/com/gmail/nossr50/config/hocon/playerleveling/ConfigExperienceFormulaLinear.java index 1400bfdae..944c8a59c 100644 --- a/src/main/java/com/gmail/nossr50/config/hocon/playerleveling/ConfigExperienceFormulaLinear.java +++ b/src/main/java/com/gmail/nossr50/config/hocon/playerleveling/ConfigExperienceFormulaLinear.java @@ -7,19 +7,19 @@ import ninja.leaping.configurate.objectmapping.serialize.ConfigSerializable; public class ConfigExperienceFormulaLinear { private static final int BASE_DEFAULT = 1020; - private static final double MULTIPLIER_DEFAULT = 20.0D; + private static final float MULTIPLIER_DEFAULT = 20.0F; @Setting(value = "Base-Amount", comment = "Default value: " + BASE_DEFAULT) private int baseModifier = BASE_DEFAULT; @Setting(value = "Multiplier", comment = "Default value: " + MULTIPLIER_DEFAULT) - private double multiplier = MULTIPLIER_DEFAULT; + private float multiplier = MULTIPLIER_DEFAULT; public int getLinearBaseModifier() { return baseModifier; } - public double getLinearMultiplier() { + public float getLinearMultiplier() { return multiplier; } diff --git a/src/main/java/com/gmail/nossr50/skills/mining/MiningManager.java b/src/main/java/com/gmail/nossr50/skills/mining/MiningManager.java index e221c19d8..3d55ddff8 100644 --- a/src/main/java/com/gmail/nossr50/skills/mining/MiningManager.java +++ b/src/main/java/com/gmail/nossr50/skills/mining/MiningManager.java @@ -26,7 +26,6 @@ import org.bukkit.enchantments.Enchantment; import org.bukkit.entity.Player; import org.bukkit.entity.TNTPrimed; import org.bukkit.inventory.ItemStack; -import sun.security.krb5.Config; import java.util.ArrayList; import java.util.List;