From 81d648f94d39b2ed05dfbb9cdff234bd68714ade Mon Sep 17 00:00:00 2001 From: nossr50 Date: Thu, 4 Apr 2019 23:46:48 -0700 Subject: [PATCH] setup typed references to skill configs --- .../gmail/nossr50/config/ConfigManager.java | 171 ++++++++++-------- 1 file changed, 97 insertions(+), 74 deletions(-) diff --git a/src/main/java/com/gmail/nossr50/config/ConfigManager.java b/src/main/java/com/gmail/nossr50/config/ConfigManager.java index 5c64ead85..bd6c989cb 100644 --- a/src/main/java/com/gmail/nossr50/config/ConfigManager.java +++ b/src/main/java/com/gmail/nossr50/config/ConfigManager.java @@ -113,8 +113,6 @@ public final class ConfigManager { private SerializedConfigLoader configAdmin; private SerializedConfigLoader configMobs; - private HashMap skillConfigLoaders; - private SerializedConfigLoader configAcrobatics; private SerializedConfigLoader configAlchemy; private SerializedConfigLoader configArchery; @@ -131,16 +129,20 @@ public final class ConfigManager { private SerializedConfigLoader configSmelting; private SerializedConfigLoader configSalvage; + private HashMap skillConfigLoaders; + //Data private SerializedConfigLoader partyData; + //YAML CONFIGS + private PotionConfig potionConfig; + private MainConfig mainConfig; private FishingTreasureConfig fishingTreasureConfig; private ExcavationTreasureConfig excavationTreasureConfig; private HerbalismTreasureConfig herbalismTreasureConfig; private ExperienceConfig experienceConfig; private AdvancedConfig advancedConfig; - private PotionConfig potionConfig; private CoreSkillsConfig coreSkillsConfig; private SoundConfig soundConfig; private RankConfig rankConfig; @@ -160,52 +162,47 @@ public final class ConfigManager { public void loadConfigs() { - // Load Config Files - // I'm pretty these are supposed to be done in a specific order, so don't rearrange them willy nilly - //Register Custom Serializers - mcMMO.p.getLogger().info("Registering custom type serializers with Configurate..."); + registerCustomTypeSerializers(); - /* - TypeTokens are obtained in two ways - - For Raw basic classes: - - TypeToken stringTok = TypeToken.of(String.class); - TypeToken intTok = TypeToken.of(Integer.class); - - For Generics: - - TypeToken> stringListTok = new TypeToken>() {}; - - Wildcard example: - - TypeToken> wildMapTok = new TypeToken>() {}; - - */ - - /* - List of default serializers for reference - DEFAULT_SERIALIZERS.registerType(TypeToken.of(URI.class), new URISerializer()); - DEFAULT_SERIALIZERS.registerType(TypeToken.of(URL.class), new URLSerializer()); - DEFAULT_SERIALIZERS.registerType(TypeToken.of(UUID.class), new UUIDSerializer()); - DEFAULT_SERIALIZERS.registerPredicate(input -> input.getRawType().isAnnotationPresent(ConfigSerializable.class), new AnnotatedObjectSerializer()); - DEFAULT_SERIALIZERS.registerPredicate(NumberSerializer.getPredicate(), new NumberSerializer()); - DEFAULT_SERIALIZERS.registerType(TypeToken.of(String.class), new StringSerializer()); - DEFAULT_SERIALIZERS.registerType(TypeToken.of(Boolean.class), new BooleanSerializer()); - DEFAULT_SERIALIZERS.registerType(new TypeToken>() {}, new MapSerializer()); - DEFAULT_SERIALIZERS.registerType(new TypeToken>() {}, new ListSerializer()); - DEFAULT_SERIALIZERS.registerType(new TypeToken>() {}, new EnumValueSerializer()); - DEFAULT_SERIALIZERS.registerType(TypeToken.of(Pattern.class), new PatternSerializer()); - */ - - TypeSerializers.getDefaultSerializers().registerType(new TypeToken() {}, new CustomEnumValueSerializer()); - TypeSerializers.getDefaultSerializers().registerType(new TypeToken() {}, new CustomEnumValueSerializer()); - TypeSerializers.getDefaultSerializers().registerType(TypeToken.of(Repairable.class), new RepairableSerializer()); - - mcMMO.p.getLogger().info("Deserializing configs..."); - //TODO: Not sure about the order of MainConfig //Serialized Configs + initSerializedConfigs(); + + //Serialized Data + initSerializedDataFiles(); + + //Skill Property Registers + skillPropertiesManager = new SkillPropertiesManager(); + skillPropertiesManager.fillRegisters(); + + //Assign Maps + partyItemWeights = Maps.newHashMap(configParty.getConfig().getPartyItemShare().getItemShareMap()); //Item Share Weights + partyFeatureUnlocks = Maps.newHashMap(configParty.getConfig().getPartyXP().getPartyLevel().getPartyFeatureUnlockMap()); //Party Progression + + //Register Bonus Drops + registerBonusDrops(); + + //YAML Configs + initYAMLConfigs(); + + /* + * Managers + */ + + // Register Managers + initMiscManagers(); + initCollectionManagers(); + } + + private void initYAMLConfigs() { + potionConfig = new PotionConfig(); + } + + private void initSerializedDataFiles() { + partyData = new SerializedConfigLoader<>(ConfigPartyData.class, "partydata.conf", "PartyData", null); + } + + private void initSerializedConfigs() { 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); @@ -226,7 +223,17 @@ public final class ConfigManager { configAdmin = new SerializedConfigLoader<>(ConfigAdmin.class, "admin.conf", "Admin", null); configMobs = new SerializedConfigLoader<>(ConfigMobs.class, "creatures.conf", "Creatures", null); + initSerializedSkillConfigs(); + } + + @SuppressWarnings(value = "unchecked") + private void initSerializedSkillConfigs() { + //Init HashMap + skillConfigLoaders = new HashMap<>(); + + //Init and register serialized skill configs registerSkillConfig(PrimarySkillType.ACROBATICS, ConfigAcrobatics.class); + registerSkillConfig(PrimarySkillType.ALCHEMY, ConfigAlchemy.class); registerSkillConfig(PrimarySkillType.SALVAGE, ConfigSalvage.class); registerSkillConfig(PrimarySkillType.ARCHERY, ConfigArchery.class); registerSkillConfig(PrimarySkillType.AXES, ConfigAxes.class); @@ -241,46 +248,62 @@ public final class ConfigManager { registerSkillConfig(PrimarySkillType.WOODCUTTING, ConfigWoodcutting.class); registerSkillConfig(PrimarySkillType.SMELTING, ConfigSmelting.class); - //Serialized Data - partyData = new SerializedConfigLoader<>(ConfigPartyData.class, "partydata.conf", "PartyData", null); + //Setup Typed refs + configAcrobatics = (SerializedConfigLoader) skillConfigLoaders.get(PrimarySkillType.ACROBATICS).getConfig(); + configAlchemy = (SerializedConfigLoader) skillConfigLoaders.get(PrimarySkillType.ALCHEMY).getConfig(); + configSalvage = (SerializedConfigLoader) skillConfigLoaders.get(PrimarySkillType.SALVAGE).getConfig(); + configArchery = (SerializedConfigLoader) skillConfigLoaders.get(PrimarySkillType.ARCHERY).getConfig(); + configAxes = (SerializedConfigLoader) skillConfigLoaders.get(PrimarySkillType.AXES).getConfig(); + configExcavation = (SerializedConfigLoader) skillConfigLoaders.get(PrimarySkillType.EXCAVATION).getConfig(); + configFishing = (SerializedConfigLoader) skillConfigLoaders.get(PrimarySkillType.FISHING).getConfig(); + configHerbalism = (SerializedConfigLoader) skillConfigLoaders.get(PrimarySkillType.HERBALISM).getConfig(); + configMining = (SerializedConfigLoader) skillConfigLoaders.get(PrimarySkillType.MINING).getConfig(); + configRepair = (SerializedConfigLoader) skillConfigLoaders.get(PrimarySkillType.REPAIR).getConfig(); + configSwords = (SerializedConfigLoader) skillConfigLoaders.get(PrimarySkillType.SWORDS).getConfig(); + configTaming = (SerializedConfigLoader) skillConfigLoaders.get(PrimarySkillType.TAMING).getConfig(); + configUnarmed = (SerializedConfigLoader) skillConfigLoaders.get(PrimarySkillType.UNARMED).getConfig(); + configWoodcutting = (SerializedConfigLoader) skillConfigLoaders.get(PrimarySkillType.WOODCUTTING).getConfig(); + configSmelting = (SerializedConfigLoader) skillConfigLoaders.get(PrimarySkillType.SMELTING).getConfig(); + } - skillPropertiesManager = new SkillPropertiesManager(); - skillPropertiesManager.fillRegisters(); + private void registerCustomTypeSerializers() { + /* + TypeTokens are obtained in two ways - //Assign Maps - partyItemWeights = Maps.newHashMap(configParty.getConfig().getPartyItemShare().getItemShareMap()); //Item Share Weights - partyFeatureUnlocks = Maps.newHashMap(configParty.getConfig().getPartyXP().getPartyLevel().getPartyFeatureUnlockMap()); //Party Progression + For Raw basic classes: - //Register Bonus Drops - registerBonusDrops(); + TypeToken stringTok = TypeToken.of(String.class); + TypeToken intTok = TypeToken.of(Integer.class); - //YAML Configs - mainConfig = new MainConfig(); + For Generics: - fishingTreasureConfig = new FishingTreasureConfig(); - excavationTreasureConfig = new ExcavationTreasureConfig(); - herbalismTreasureConfig = new HerbalismTreasureConfig(); + TypeToken> stringListTok = new TypeToken>() {}; - advancedConfig = new AdvancedConfig(); + Wildcard example: - //TODO: Not sure about the order of experience config - experienceConfig = new ExperienceConfig(); + TypeToken> wildMapTok = new TypeToken>() {}; - potionConfig = new PotionConfig(); - - coreSkillsConfig = new CoreSkillsConfig(); - - soundConfig = new SoundConfig(); - - rankConfig = new RankConfig(); + */ /* - * Managers + List of default serializers for reference + DEFAULT_SERIALIZERS.registerType(TypeToken.of(URI.class), new URISerializer()); + DEFAULT_SERIALIZERS.registerType(TypeToken.of(URL.class), new URLSerializer()); + DEFAULT_SERIALIZERS.registerType(TypeToken.of(UUID.class), new UUIDSerializer()); + DEFAULT_SERIALIZERS.registerPredicate(input -> input.getRawType().isAnnotationPresent(ConfigSerializable.class), new AnnotatedObjectSerializer()); + DEFAULT_SERIALIZERS.registerPredicate(NumberSerializer.getPredicate(), new NumberSerializer()); + DEFAULT_SERIALIZERS.registerType(TypeToken.of(String.class), new StringSerializer()); + DEFAULT_SERIALIZERS.registerType(TypeToken.of(Boolean.class), new BooleanSerializer()); + DEFAULT_SERIALIZERS.registerType(new TypeToken>() {}, new MapSerializer()); + DEFAULT_SERIALIZERS.registerType(new TypeToken>() {}, new ListSerializer()); + DEFAULT_SERIALIZERS.registerType(new TypeToken>() {}, new EnumValueSerializer()); + DEFAULT_SERIALIZERS.registerType(TypeToken.of(Pattern.class), new PatternSerializer()); */ - // Register Managers - initMiscManagers(); - initCollectionManagers(); + mcMMO.p.getLogger().info("Registering custom type serializers for Configurate..."); + TypeSerializers.getDefaultSerializers().registerType(new TypeToken() {}, new CustomEnumValueSerializer()); + TypeSerializers.getDefaultSerializers().registerType(new TypeToken() {}, new CustomEnumValueSerializer()); + TypeSerializers.getDefaultSerializers().registerType(TypeToken.of(Repairable.class), new RepairableSerializer()); } private void registerSkillConfig(PrimarySkillType primarySkillType, Class clazz)