From 99f0e029c2445fc08c0685d2a9bdcc9e4ca83f79 Mon Sep 17 00:00:00 2001 From: nossr50 Date: Mon, 25 Feb 2019 14:08:41 -0800 Subject: [PATCH] fishing treasures pt 2 --- .../treasure/FishingTreasureConfig.java | 101 ++++++++++++++++-- .../config/treasure/TreasureFactory.java | 8 ++ .../datatypes/player/PlayerProfile.java | 2 + .../skills/subskills/AbstractSubSkill.java | 3 +- .../util/experience/FormulaManager.java | 1 + 5 files changed, 104 insertions(+), 11 deletions(-) diff --git a/src/main/java/com/gmail/nossr50/config/treasure/FishingTreasureConfig.java b/src/main/java/com/gmail/nossr50/config/treasure/FishingTreasureConfig.java index ec6530666..3f166c05c 100644 --- a/src/main/java/com/gmail/nossr50/config/treasure/FishingTreasureConfig.java +++ b/src/main/java/com/gmail/nossr50/config/treasure/FishingTreasureConfig.java @@ -3,15 +3,13 @@ package com.gmail.nossr50.config.treasure; import com.gmail.nossr50.config.Config; import com.gmail.nossr50.config.Registers; import com.gmail.nossr50.config.UnsafeValueValidation; -import com.gmail.nossr50.datatypes.treasure.EnchantmentTreasure; -import com.gmail.nossr50.datatypes.treasure.FishingTreasure; -import com.gmail.nossr50.datatypes.treasure.Rarity; -import com.gmail.nossr50.datatypes.treasure.ShakeTreasure; +import com.gmail.nossr50.datatypes.treasure.*; import com.gmail.nossr50.mcMMO; import com.gmail.nossr50.util.EnchantmentUtils; import com.google.common.reflect.TypeToken; import ninja.leaping.configurate.ConfigurationNode; import ninja.leaping.configurate.objectmapping.ObjectMappingException; +import org.bukkit.Material; import org.bukkit.configuration.ConfigurationSection; import org.bukkit.enchantments.Enchantment; import org.bukkit.entity.EntityType; @@ -28,16 +26,20 @@ public class FishingTreasureConfig extends Config implements UnsafeValueValidati public static final String DROP_LEVEL = "Drop_Level"; public static final String TIER = "Tier_"; public static final String ENCHANTMENTS_RARITY = "Enchantments_Rarity"; + public static final String ITEM_DROP_RATES = "Item_Drop_Rates"; + public static final String FISHING = "Fishing"; + public static final String ENCHANTMENT_DROP_RATES = "Enchantment_Drop_Rates"; + public static final String SHAKE = "Shake"; + public static final String AMOUNT = "Amount"; + public static final String XP = "XP"; + public static final String CUSTOM_NAME = "Custom_Name"; + public static final String LORE = "Lore"; + public static final String RARITY = "Rarity"; + public HashMap> shakeMap = new HashMap>(); public HashMap> fishingRewards = new HashMap>(); public HashMap> fishingEnchantments = new HashMap>(); - public static final String ITEM_DROP_RATES = "Item_Drop_Rates"; - public static final String FISHING = "Fishing"; - public static final String ENCHANTMENT_DROP_RATES1 = "Enchantment_Drop_Rates"; - public static final String ENCHANTMENT_DROP_RATES = ENCHANTMENT_DROP_RATES1; - public static final String SHAKE = "Shake"; - /** * This grabs an instance of this config class from the Config Manager * This method is deprecated and will be removed in the future @@ -81,7 +83,86 @@ public class FishingTreasureConfig extends Config implements UnsafeValueValidati try { for (String treasureName : fishingTreasureNode.getList(TypeToken.of(String.class))) { + //Treasure Material Definition + Material treasureMaterial = Material.matchMaterial(treasureName.toUpperCase()); + if(treasureMaterial != null) + { + ConfigurationNode currentTreasure = fishingTreasureNode.getNode(treasureName); + + //TODO: Rewrite the entire treasure system because it sucks + + /* + * TREASURE PARAMETERS + */ + int amount = currentTreasure.getNode(AMOUNT).getInt(); + int xp = currentTreasure.getNode(XP).getInt(); + String customName = null; + + /* + * PARAMETER INIT + */ + + ArrayList dropsFrom = new ArrayList(currentTreasure.getNode("Drops_From").getList(TypeToken.of(String.class))); + + //VALIDATE AMOUNT + if(amount <= 0) + { + mcMMO.p.getLogger().severe("Excavation Treasure named "+treasureName+" in the config has an amount of 0 or below, is this intentional?"); + mcMMO.p.getLogger().severe("Skipping "+treasureName+" for being invalid"); + continue; + } + + //VALIDATE XP + if(xp <= 0) + { + mcMMO.p.getLogger().info("Excavation Treasure named "+treasureName+" in the config has xp set to 0 or below, is this intentional?"); + xp = 0; + } + + //VALIDATE DROP SOURCES + if(dropsFrom == null || dropsFrom.isEmpty()) + { + mcMMO.p.getLogger().severe("Excavation Treasure named "+treasureName+" in the config has no drop targets, which would make it impossible to obtain, is this intentional?"); + mcMMO.p.getLogger().severe("Skipping "+treasureName+" for being invalid"); + continue; + } + + /* OPTIONAL PARAMETERS */ + + //Custom Name + + if(currentTreasure.getNode(CUSTOM_NAME) != null && !currentTreasure.getNode(CUSTOM_NAME).getString().equalsIgnoreCase("ChangeMe")) + { + customName = currentTreasure.getNode(CUSTOM_NAME).getString(); + } + + /* + * REGISTER TREASURE + */ + + FishingTreasure fishingTreasure = TreasureFactory.makeFishingTreasure(treasureMaterial, amount, xp, customName, currentTreasure.getNode(LORE)); + + /* + * Add to map + */ + + String configRarity = currentTreasure.getNode(RARITY).getString(); + + for(Rarity rarity : Rarity.values()) + { + if(rarity.toString().equalsIgnoreCase(configRarity)) + { + if(fishingRewards.get(rarity) == null) + fishingRewards.put(rarity, new ArrayList<>()); + + fishingRewards.get(rarity).add(fishingTreasure); + } + } + + } else { + mcMMO.p.getLogger().severe("Excavation Treasure Config - Material named "+treasureName+" does not match any known material."); + } } } catch (ObjectMappingException e) { e.printStackTrace(); diff --git a/src/main/java/com/gmail/nossr50/config/treasure/TreasureFactory.java b/src/main/java/com/gmail/nossr50/config/treasure/TreasureFactory.java index 1382aa8f6..d163aef74 100644 --- a/src/main/java/com/gmail/nossr50/config/treasure/TreasureFactory.java +++ b/src/main/java/com/gmail/nossr50/config/treasure/TreasureFactory.java @@ -1,6 +1,7 @@ package com.gmail.nossr50.config.treasure; import com.gmail.nossr50.datatypes.treasure.ExcavationTreasure; +import com.gmail.nossr50.datatypes.treasure.FishingTreasure; import com.gmail.nossr50.datatypes.treasure.HylianTreasure; import com.google.common.reflect.TypeToken; import ninja.leaping.configurate.ConfigurationNode; @@ -41,6 +42,13 @@ public class TreasureFactory { return new ExcavationTreasure(treasure, xpReward, dropChance, dropLevel); } + public static FishingTreasure makeFishingTreasure(Material material, int dropAmount, int xpReward, String customName, ConfigurationNode customLore) + { + ItemStack treasure = makeItemStack(material, dropAmount, customName, customLore); + + return new FishingTreasure(treasure, xpReward); + } + public static HylianTreasure makeHylianTreasure(Material material, int dropAmount, int xpReward, double dropChance, int dropLevel, String customName, ConfigurationNode customLore) { ItemStack treasure = makeItemStack(material, dropAmount, customName, customLore); diff --git a/src/main/java/com/gmail/nossr50/datatypes/player/PlayerProfile.java b/src/main/java/com/gmail/nossr50/datatypes/player/PlayerProfile.java index 744f8017e..fe4bb13de 100644 --- a/src/main/java/com/gmail/nossr50/datatypes/player/PlayerProfile.java +++ b/src/main/java/com/gmail/nossr50/datatypes/player/PlayerProfile.java @@ -1,6 +1,8 @@ package com.gmail.nossr50.datatypes.player; +import com.gmail.nossr50.config.AdvancedConfig; import com.gmail.nossr50.config.MainConfig; +import com.gmail.nossr50.config.experience.ExperienceConfig; import com.gmail.nossr50.datatypes.MobHealthbarType; import com.gmail.nossr50.datatypes.experience.FormulaType; import com.gmail.nossr50.datatypes.experience.SkillXpGain; diff --git a/src/main/java/com/gmail/nossr50/datatypes/skills/subskills/AbstractSubSkill.java b/src/main/java/com/gmail/nossr50/datatypes/skills/subskills/AbstractSubSkill.java index 8140b5527..2e7c9a1f5 100644 --- a/src/main/java/com/gmail/nossr50/datatypes/skills/subskills/AbstractSubSkill.java +++ b/src/main/java/com/gmail/nossr50/datatypes/skills/subskills/AbstractSubSkill.java @@ -1,5 +1,6 @@ package com.gmail.nossr50.datatypes.skills.subskills; +import com.gmail.nossr50.config.CoreSkillsConfig; import com.gmail.nossr50.datatypes.skills.SubSkillType; import com.gmail.nossr50.datatypes.skills.subskills.interfaces.Interaction; import com.gmail.nossr50.datatypes.skills.subskills.interfaces.Rank; @@ -41,7 +42,7 @@ public abstract class AbstractSubSkill implements SubSkill, Interaction, Rank, S @Override @Deprecated public boolean isEnabled() { //TODO: This might be troublesome... - return CoreSkillConfig.getInstance().isSkillEnabled(this); + return CoreSkillsConfig.getInstance().isSkillEnabled(this); } /** diff --git a/src/main/java/com/gmail/nossr50/util/experience/FormulaManager.java b/src/main/java/com/gmail/nossr50/util/experience/FormulaManager.java index 5761bcc7d..95e1242ad 100644 --- a/src/main/java/com/gmail/nossr50/util/experience/FormulaManager.java +++ b/src/main/java/com/gmail/nossr50/util/experience/FormulaManager.java @@ -1,6 +1,7 @@ package com.gmail.nossr50.util.experience; import com.gmail.nossr50.config.MainConfig; +import com.gmail.nossr50.config.experience.ExperienceConfig; import com.gmail.nossr50.datatypes.experience.FormulaType; import com.gmail.nossr50.datatypes.skills.PrimarySkillType; import com.gmail.nossr50.mcMMO;