From 4394ac704992eaf9b3b20a09b9233aa998188ef0 Mon Sep 17 00:00:00 2001 From: nossr50 Date: Tue, 9 Apr 2019 20:12:52 -0700 Subject: [PATCH] xp config pt 3 + example fully qualified name map serializer --- Changelog.txt | 1 + .../gmail/nossr50/config/ConfigManager.java | 14 +++++--- .../MinecraftMaterialWrapperSerializer.java | 26 +++++++++++++++ .../hocon/experience/ConfigExperience.java | 24 +++++++------- .../ConfigExperienceAcrobatics.java | 15 +++++++-- .../experience/ConfigExperienceAlchemy.java | 30 +++++++++++++++++ .../ConfigNameRegisterDefaults.java | 33 +++++++++++++++++++ .../MinecraftMaterialWrapper.java | 28 ++++++++++++++++ .../alchemy/PotionGenerator.java} | 4 +-- 9 files changed, 155 insertions(+), 20 deletions(-) create mode 100644 src/main/java/com/gmail/nossr50/config/hocon/MinecraftMaterialWrapperSerializer.java create mode 100644 src/main/java/com/gmail/nossr50/config/hocon/experience/ConfigExperienceAlchemy.java create mode 100644 src/main/java/com/gmail/nossr50/config/hocon/skills/exampleconfigs/ConfigNameRegisterDefaults.java create mode 100644 src/main/java/com/gmail/nossr50/config/hocon/skills/exampleconfigs/MinecraftMaterialWrapper.java rename src/main/java/com/gmail/nossr50/{util/skills/PotionConfigGenerator.java => skills/alchemy/PotionGenerator.java} (99%) diff --git a/Changelog.txt b/Changelog.txt index ee7586bfc..ed17c13ce 100644 --- a/Changelog.txt +++ b/Changelog.txt @@ -24,6 +24,7 @@ Version 2.2.0 All config nodes will now use Capital letters at the start of each nodes name and after each hyphen (-) All config nodes now include a comment with the default value of the node to use as reference Expanded settings relating to purging users who have not leveled or users who had not logged in for many months + Acrobatic's Dodge XP increased from 120 -> 480 NOTE: Not every config key that was renamed will be listed here Admins will now be notified if a player trips over-fishing exploit detection 3+ times in a row (Locale: "Fishing.OverFishingDetected") Note: Admins are players who are op or have adminchat permission. diff --git a/src/main/java/com/gmail/nossr50/config/ConfigManager.java b/src/main/java/com/gmail/nossr50/config/ConfigManager.java index 1df63da10..c20a7e910 100644 --- a/src/main/java/com/gmail/nossr50/config/ConfigManager.java +++ b/src/main/java/com/gmail/nossr50/config/ConfigManager.java @@ -1,16 +1,14 @@ package com.gmail.nossr50.config; import com.gmail.nossr50.config.experience.ExperienceConfig; -import com.gmail.nossr50.config.hocon.CustomEnumValueSerializer; -import com.gmail.nossr50.config.hocon.RepairableSerializer; -import com.gmail.nossr50.config.hocon.SalvageableSerializer; -import com.gmail.nossr50.config.hocon.SerializedConfigLoader; +import com.gmail.nossr50.config.hocon.*; import com.gmail.nossr50.config.hocon.admin.ConfigAdmin; import com.gmail.nossr50.config.hocon.antiexploit.ConfigExploitPrevention; import com.gmail.nossr50.config.hocon.backup.ConfigAutomatedBackups; import com.gmail.nossr50.config.hocon.commands.ConfigCommands; import com.gmail.nossr50.config.hocon.database.ConfigDatabase; import com.gmail.nossr50.config.hocon.donation.ConfigAuthorAdvertisements; +import com.gmail.nossr50.config.hocon.experience.ConfigExperience; import com.gmail.nossr50.config.hocon.hardcore.ConfigHardcore; import com.gmail.nossr50.config.hocon.items.ConfigItems; import com.gmail.nossr50.config.hocon.language.ConfigLanguage; @@ -27,6 +25,7 @@ import com.gmail.nossr50.config.hocon.skills.acrobatics.ConfigAcrobatics; import com.gmail.nossr50.config.hocon.skills.alchemy.ConfigAlchemy; import com.gmail.nossr50.config.hocon.skills.archery.ConfigArchery; import com.gmail.nossr50.config.hocon.skills.axes.ConfigAxes; +import com.gmail.nossr50.config.hocon.skills.exampleconfigs.MinecraftMaterialWrapper; import com.gmail.nossr50.config.hocon.skills.excavation.ConfigExcavation; import com.gmail.nossr50.config.hocon.skills.fishing.ConfigFishing; import com.gmail.nossr50.config.hocon.skills.herbalism.ConfigHerbalism; @@ -113,6 +112,7 @@ public final class ConfigManager { private SerializedConfigLoader configSuperAbilities; private SerializedConfigLoader configAdmin; private SerializedConfigLoader configMobs; + private SerializedConfigLoader configExperience; private SerializedConfigLoader configAcrobatics; private SerializedConfigLoader configAlchemy; @@ -223,6 +223,7 @@ public final class ConfigManager { configSuperAbilities = new SerializedConfigLoader<>(ConfigSuperAbilities.class, "skill_super_abilities.conf", "Super-Abilities", null); configAdmin = new SerializedConfigLoader<>(ConfigAdmin.class, "admin.conf", "Admin", null); configMobs = new SerializedConfigLoader<>(ConfigMobs.class, "creatures.conf", "Creatures", null); + configExperience = new SerializedConfigLoader<>(ConfigExperience.class, "experience.conf", "Experience", null); initSerializedSkillConfigs(); } @@ -306,6 +307,7 @@ public final class ConfigManager { TypeSerializers.getDefaultSerializers().registerType(new TypeToken() {}, new CustomEnumValueSerializer()); TypeSerializers.getDefaultSerializers().registerType(TypeToken.of(Repairable.class), new RepairableSerializer()); TypeSerializers.getDefaultSerializers().registerType(TypeToken.of(Salvageable.class), new SalvageableSerializer()); + TypeSerializers.getDefaultSerializers().registerType(TypeToken.of(MinecraftMaterialWrapper.class), new MinecraftMaterialWrapperSerializer()); } private void registerSkillConfig(PrimarySkillType primarySkillType, Class clazz) @@ -656,4 +658,8 @@ public final class ConfigManager { { return skillPropertiesManager.getMaxChance(subSkillType); } + + public ConfigExperience getConfigExperience() { + return configExperience.getConfig(); + } } diff --git a/src/main/java/com/gmail/nossr50/config/hocon/MinecraftMaterialWrapperSerializer.java b/src/main/java/com/gmail/nossr50/config/hocon/MinecraftMaterialWrapperSerializer.java new file mode 100644 index 000000000..a3f771700 --- /dev/null +++ b/src/main/java/com/gmail/nossr50/config/hocon/MinecraftMaterialWrapperSerializer.java @@ -0,0 +1,26 @@ +package com.gmail.nossr50.config.hocon; + +import com.gmail.nossr50.config.hocon.skills.exampleconfigs.MinecraftMaterialWrapper; +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.bukkit.Material; + +public class MinecraftMaterialWrapperSerializer implements TypeSerializer { + + @Override + public MinecraftMaterialWrapper deserialize(TypeToken type, ConfigurationNode value) throws ObjectMappingException { + Material material = Material.matchMaterial(value.getValue(new TypeToken() {})); + + return new MinecraftMaterialWrapper(material); + } + + @Override + public void serialize(TypeToken type, MinecraftMaterialWrapper obj, ConfigurationNode value) { + + value.setValue(obj.getName()); //Name + value.getNode("Fully-Qualified-Name").setValue(obj.getFullyQualifiedName()); + value.getNode("Bukkit-Material-Name").setValue(obj.getBukkitMaterialName()); + } +} \ No newline at end of file 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 97e982a00..8e9bc7746 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 @@ -7,40 +7,40 @@ import ninja.leaping.configurate.objectmapping.serialize.ConfigSerializable; public class ConfigExperience { @Setting(value = "Acrobatics", comment = "XP Settings for Acrobatics") - ConfigExperienceAcrobatics experienceAcrobatics = new ConfigExperienceAcrobatics(); + private ConfigExperienceAcrobatics experienceAcrobatics = new ConfigExperienceAcrobatics(); @Setting(value = "Alchemy", comment = "XP Settings for Alchemy") - ConfigExperienceAlchemy experienceAlchemy = new ConfigExperienceAlchemy(); + private ConfigExperienceAlchemy experienceAlchemy = new ConfigExperienceAlchemy(); @Setting(value = "Archery", comment = "XP Settings for Archery") - ConfigExperienceArchery experienceArchery = new ConfigExperienceArchery(); + private ConfigExperienceArchery experienceArchery = new ConfigExperienceArchery(); @Setting(value = "Fishing", comment = "XP Settings for Fishing") - ConfigExperienceFishing experienceFishing = new ConfigExperienceFishing(); + private ConfigExperienceFishing experienceFishing = new ConfigExperienceFishing(); @Setting(value = "Excavation", comment = "XP Settings for Excavation") - ConfigExperienceExcavation experienceExcavation = new ConfigExperienceExcavation(); + private ConfigExperienceExcavation experienceExcavation = new ConfigExperienceExcavation(); @Setting(value = "Woodcutting", comment = "XP Settings for Woodcutting") - ConfigExperienceWoodcutting experienceWoodcutting = new ConfigExperienceWoodcutting(); + private ConfigExperienceWoodcutting experienceWoodcutting = new ConfigExperienceWoodcutting(); @Setting(value = "Herbalism", comment = "XP Settings for Herbalism") - ConfigExperienceHerbalism experienceHerbalism = new ConfigExperienceHerbalism(); + private ConfigExperienceHerbalism experienceHerbalism = new ConfigExperienceHerbalism(); @Setting(value = "Mining", comment = "XP Settings for Mining") - ConfigExperienceMining experienceMining = new ConfigExperienceMining(); + private ConfigExperienceMining experienceMining = new ConfigExperienceMining(); @Setting(value = "Repair", comment = "XP Settings for Repair") - ConfigExperienceRepair experienceRepair = new ConfigExperienceRepair(); + private ConfigExperienceRepair experienceRepair = new ConfigExperienceRepair(); @Setting(value = "Smelting", comment = "XP Settings for Smelting") - ConfigExperienceSmelting experienceSmelting = new ConfigExperienceSmelting(); + private ConfigExperienceSmelting experienceSmelting = new ConfigExperienceSmelting(); @Setting(value = "Taming", comment = "XP Settings for Taming") - ConfigExperienceTaming experienceTaming = new ConfigExperienceTaming(); + private ConfigExperienceTaming experienceTaming = new ConfigExperienceTaming(); @Setting(value = "Z-Combat", comment = "XP Settings for Combat") - ConfigExperienceCombat experienceCombat = new ConfigExperienceCombat(); + private ConfigExperienceCombat experienceCombat = new ConfigExperienceCombat(); public ConfigExperienceAcrobatics getExperienceAcrobatics() { return experienceAcrobatics; diff --git a/src/main/java/com/gmail/nossr50/config/hocon/experience/ConfigExperienceAcrobatics.java b/src/main/java/com/gmail/nossr50/config/hocon/experience/ConfigExperienceAcrobatics.java index fd4321553..ff94319f3 100644 --- a/src/main/java/com/gmail/nossr50/config/hocon/experience/ConfigExperienceAcrobatics.java +++ b/src/main/java/com/gmail/nossr50/config/hocon/experience/ConfigExperienceAcrobatics.java @@ -9,13 +9,24 @@ import java.util.HashMap; public class ConfigExperienceAcrobatics { private final static HashMap ACROBATICS_DEFAULT_XP_MAP; + public static final double FEATHER_FALL_MULTIPLIER_DEFAULT = 2.0D; static { ACROBATICS_DEFAULT_XP_MAP = new HashMap<>(); - + ACROBATICS_DEFAULT_XP_MAP.put("Dodge", 480); + ACROBATICS_DEFAULT_XP_MAP.put("Roll", 80); + ACROBATICS_DEFAULT_XP_MAP.put("Fall", 120); } @Setting(value = "Acrobatics-Experience-Values", comment = "Experience values for Acrobatics.") - HashMap acrobaticsXPMap; + HashMap acrobaticsXPMap = ACROBATICS_DEFAULT_XP_MAP; + @Setting(value = "Feather-Fall-XP-Multiplier", comment = "Feather Fall grants bonus XP to fall related XP gains." + + "\nThis value is multiplied against your XP to give the bonus." + + "\nDefault value: "+FEATHER_FALL_MULTIPLIER_DEFAULT) + private Double featherFallMultiplier = FEATHER_FALL_MULTIPLIER_DEFAULT; + + public HashMap getAcrobaticsXPMap() { + return acrobaticsXPMap; + } } \ No newline at end of file diff --git a/src/main/java/com/gmail/nossr50/config/hocon/experience/ConfigExperienceAlchemy.java b/src/main/java/com/gmail/nossr50/config/hocon/experience/ConfigExperienceAlchemy.java new file mode 100644 index 000000000..a359901af --- /dev/null +++ b/src/main/java/com/gmail/nossr50/config/hocon/experience/ConfigExperienceAlchemy.java @@ -0,0 +1,30 @@ +package com.gmail.nossr50.config.hocon.experience; + +import ninja.leaping.configurate.objectmapping.Setting; +import ninja.leaping.configurate.objectmapping.serialize.ConfigSerializable; + +import java.util.HashMap; + +@ConfigSerializable +public class ConfigExperienceAlchemy { + + private final static HashMap ALCHEMY_DEFAULT_XP_MAP; + + static { + ALCHEMY_DEFAULT_XP_MAP = new HashMap<>(); + ALCHEMY_DEFAULT_XP_MAP.put("Simple_Potions", 15); + ALCHEMY_DEFAULT_XP_MAP.put("Potion_One_Ingredient", 30); + ALCHEMY_DEFAULT_XP_MAP.put("Potion_One_Ingredient_One_Amplifier", 60); + ALCHEMY_DEFAULT_XP_MAP.put("Potion_One_Ingredient_Two_Amplifier", 120); + ALCHEMY_DEFAULT_XP_MAP.put("Potion_One_Ingredient_Swapped_Amplifiers", 240); + } + + @Setting(value = "Alchemy-Experience-Values", comment = "Experience values for alchemy.") + HashMapalchemyXPMap = ALCHEMY_DEFAULT_XP_MAP; + + + public HashMap getAlchemyXPMap() { + return alchemyXPMap; + } + +} \ No newline at end of file diff --git a/src/main/java/com/gmail/nossr50/config/hocon/skills/exampleconfigs/ConfigNameRegisterDefaults.java b/src/main/java/com/gmail/nossr50/config/hocon/skills/exampleconfigs/ConfigNameRegisterDefaults.java new file mode 100644 index 000000000..4659e5596 --- /dev/null +++ b/src/main/java/com/gmail/nossr50/config/hocon/skills/exampleconfigs/ConfigNameRegisterDefaults.java @@ -0,0 +1,33 @@ +package com.gmail.nossr50.config.hocon.skills.exampleconfigs; + +import ninja.leaping.configurate.objectmapping.Setting; +import ninja.leaping.configurate.objectmapping.serialize.ConfigSerializable; +import org.bukkit.Material; + +import java.util.ArrayList; + +/** + * This class is used to generate a table that can be referenced to compare Bukkit Material names + * to full qualified names used in internal registers for Minecraft + */ +@ConfigSerializable +public class ConfigNameRegisterDefaults { + + private static final ArrayList BUKKIT_MATERIAL_NAME_LOOKUP_EXAMPLE; + + static { + BUKKIT_MATERIAL_NAME_LOOKUP_EXAMPLE = new ArrayList<>(); + for(Material m : Material.values()) + { + BUKKIT_MATERIAL_NAME_LOOKUP_EXAMPLE.add(new MinecraftMaterialWrapper((m))); + } + } + + @Setting(value = "Default-Name-Registers", comment = "These are the names mcMMO will recognize for Items " + + "used internally by Minecraft.") + private ArrayList defaultMaterialNameRegisters = BUKKIT_MATERIAL_NAME_LOOKUP_EXAMPLE; + + public ArrayList getDefaultMaterialNameRegisters() { + return defaultMaterialNameRegisters; + } +} \ No newline at end of file diff --git a/src/main/java/com/gmail/nossr50/config/hocon/skills/exampleconfigs/MinecraftMaterialWrapper.java b/src/main/java/com/gmail/nossr50/config/hocon/skills/exampleconfigs/MinecraftMaterialWrapper.java new file mode 100644 index 000000000..c7742c30b --- /dev/null +++ b/src/main/java/com/gmail/nossr50/config/hocon/skills/exampleconfigs/MinecraftMaterialWrapper.java @@ -0,0 +1,28 @@ +package com.gmail.nossr50.config.hocon.skills.exampleconfigs; + +import org.bukkit.Material; + +public class MinecraftMaterialWrapper { + private String name; + private String fullyQualifiedName; + private String bukkitMaterialName; + + public MinecraftMaterialWrapper(Material material) + { + this.name = material.getKey().getKey(); + this.fullyQualifiedName = material.getKey().toString(); + this.bukkitMaterialName = material.toString(); + } + + public String getName() { + return name; + } + + public String getFullyQualifiedName() { + return fullyQualifiedName; + } + + public String getBukkitMaterialName() { + return bukkitMaterialName; + } +} diff --git a/src/main/java/com/gmail/nossr50/util/skills/PotionConfigGenerator.java b/src/main/java/com/gmail/nossr50/skills/alchemy/PotionGenerator.java similarity index 99% rename from src/main/java/com/gmail/nossr50/util/skills/PotionConfigGenerator.java rename to src/main/java/com/gmail/nossr50/skills/alchemy/PotionGenerator.java index 8c1a69215..151f78db7 100644 --- a/src/main/java/com/gmail/nossr50/util/skills/PotionConfigGenerator.java +++ b/src/main/java/com/gmail/nossr50/skills/alchemy/PotionGenerator.java @@ -1,4 +1,4 @@ -package com.gmail.nossr50.util.skills; +package com.gmail.nossr50.skills.alchemy; import org.bukkit.Material; import org.bukkit.potion.PotionData; @@ -12,7 +12,7 @@ import java.util.List; import java.util.Map; import java.util.Map.Entry; -public class PotionConfigGenerator { +public class PotionGenerator { public static class Ingredient {