From 856e6f044735fdad67360361876dbf7d80a111bd Mon Sep 17 00:00:00 2001 From: nossr50 Date: Wed, 10 Apr 2019 04:35:14 -0700 Subject: [PATCH] Fishing now actually grants XP for caught fish (values in the config did nothing before... lol ) --- pom.xml | 10 +++ .../config/experience/ExperienceConfig.java | 1 - .../skills/subskills/acrobatics/Roll.java | 1 - .../nossr50/skills/acrobatics/Acrobatics.java | 3 - .../skills/acrobatics/AcrobaticsManager.java | 1 - .../skills/alchemy/AlchemyManager.java | 1 - .../gmail/nossr50/skills/fishing/Fishing.java | 70 ++++++++++++++++--- .../skills/fishing/FishingManager.java | 29 ++++---- 8 files changed, 87 insertions(+), 29 deletions(-) diff --git a/pom.xml b/pom.xml index 7c9998ca5..e8fd8557e 100755 --- a/pom.xml +++ b/pom.xml @@ -172,8 +172,18 @@ sk89q-repo http://maven.sk89q.com/repo/ + + jetbrains + https://mvnrepository.com/artifact/org.jetbrains/annotations + + + + org.jetbrains + annotations + 17.0.0 + com.typesafe config diff --git a/src/main/java/com/gmail/nossr50/config/experience/ExperienceConfig.java b/src/main/java/com/gmail/nossr50/config/experience/ExperienceConfig.java index 8cd3cf498..420b81973 100644 --- a/src/main/java/com/gmail/nossr50/config/experience/ExperienceConfig.java +++ b/src/main/java/com/gmail/nossr50/config/experience/ExperienceConfig.java @@ -5,7 +5,6 @@ import com.gmail.nossr50.config.ConfigValidated; import com.gmail.nossr50.datatypes.experience.FormulaType; import com.gmail.nossr50.datatypes.skills.ItemMaterialCategory; import com.gmail.nossr50.datatypes.skills.PrimarySkillType; -import com.gmail.nossr50.datatypes.skills.alchemy.PotionStage; import com.gmail.nossr50.mcMMO; import com.gmail.nossr50.util.StringUtils; import ninja.leaping.configurate.objectmapping.serialize.ConfigSerializable; diff --git a/src/main/java/com/gmail/nossr50/datatypes/skills/subskills/acrobatics/Roll.java b/src/main/java/com/gmail/nossr50/datatypes/skills/subskills/acrobatics/Roll.java index 07f14da8c..2106de8e4 100644 --- a/src/main/java/com/gmail/nossr50/datatypes/skills/subskills/acrobatics/Roll.java +++ b/src/main/java/com/gmail/nossr50/datatypes/skills/subskills/acrobatics/Roll.java @@ -1,7 +1,6 @@ package com.gmail.nossr50.datatypes.skills.subskills.acrobatics; import com.gmail.nossr50.config.AdvancedConfig; -import com.gmail.nossr50.config.experience.ExperienceConfig; import com.gmail.nossr50.datatypes.LimitedSizeList; import com.gmail.nossr50.datatypes.experience.XPGainReason; import com.gmail.nossr50.datatypes.interactions.NotificationType; diff --git a/src/main/java/com/gmail/nossr50/skills/acrobatics/Acrobatics.java b/src/main/java/com/gmail/nossr50/skills/acrobatics/Acrobatics.java index 22b413e4e..5159bd866 100644 --- a/src/main/java/com/gmail/nossr50/skills/acrobatics/Acrobatics.java +++ b/src/main/java/com/gmail/nossr50/skills/acrobatics/Acrobatics.java @@ -1,8 +1,5 @@ package com.gmail.nossr50.skills.acrobatics; -import com.gmail.nossr50.config.AdvancedConfig; -import com.gmail.nossr50.config.MainConfig; -import com.gmail.nossr50.config.experience.ExperienceConfig; import com.gmail.nossr50.mcMMO; public final class Acrobatics { diff --git a/src/main/java/com/gmail/nossr50/skills/acrobatics/AcrobaticsManager.java b/src/main/java/com/gmail/nossr50/skills/acrobatics/AcrobaticsManager.java index d64945c3b..18c7c3329 100644 --- a/src/main/java/com/gmail/nossr50/skills/acrobatics/AcrobaticsManager.java +++ b/src/main/java/com/gmail/nossr50/skills/acrobatics/AcrobaticsManager.java @@ -16,7 +16,6 @@ import com.gmail.nossr50.util.skills.RankUtils; import com.gmail.nossr50.util.skills.SkillActivationType; import com.gmail.nossr50.util.skills.SkillUtils; import org.bukkit.entity.Entity; -import org.bukkit.entity.LightningStrike; import org.bukkit.entity.Player; public class AcrobaticsManager extends SkillManager { diff --git a/src/main/java/com/gmail/nossr50/skills/alchemy/AlchemyManager.java b/src/main/java/com/gmail/nossr50/skills/alchemy/AlchemyManager.java index 92cd46330..892db1066 100644 --- a/src/main/java/com/gmail/nossr50/skills/alchemy/AlchemyManager.java +++ b/src/main/java/com/gmail/nossr50/skills/alchemy/AlchemyManager.java @@ -1,6 +1,5 @@ package com.gmail.nossr50.skills.alchemy; -import com.gmail.nossr50.config.experience.ExperienceConfig; import com.gmail.nossr50.config.skills.alchemy.PotionConfig; import com.gmail.nossr50.datatypes.experience.XPGainReason; import com.gmail.nossr50.datatypes.experience.XPGainSource; diff --git a/src/main/java/com/gmail/nossr50/skills/fishing/Fishing.java b/src/main/java/com/gmail/nossr50/skills/fishing/Fishing.java index 3b4c99ed2..3cf74d73c 100644 --- a/src/main/java/com/gmail/nossr50/skills/fishing/Fishing.java +++ b/src/main/java/com/gmail/nossr50/skills/fishing/Fishing.java @@ -2,6 +2,7 @@ package com.gmail.nossr50.skills.fishing; import com.gmail.nossr50.config.treasure.FishingTreasureConfig; import com.gmail.nossr50.datatypes.treasure.ShakeTreasure; +import com.gmail.nossr50.mcMMO; import com.gmail.nossr50.util.Misc; import com.gmail.nossr50.util.adapter.BiomeAdapter; import org.bukkit.Material; @@ -16,16 +17,45 @@ import java.util.Set; public final class Fishing { - protected static final HashMap> ENCHANTABLE_CACHE = new HashMap<>(); + private static HashMap> ENCHANTABLE_CACHE = new HashMap<>(); + private HashMap fishingXpRewardMap; + private static Set masterAnglerBiomes = BiomeAdapter.WATER_BIOMES; + private static Set iceFishingBiomes = BiomeAdapter.ICE_BIOMES; - /*public static int fishermansDietRankLevel1 = AdvancedConfig.getInstance().getFishermanDietRankChange(); - public static int fishermansDietRankLevel2 = fishermansDietRankLevel1 * 2; - public static int fishermansDietMaxLevel = fishermansDietRankLevel1 * 5;*/ + public static Fishing instance; - public static Set masterAnglerBiomes = BiomeAdapter.WATER_BIOMES; - public static Set iceFishingBiomes = BiomeAdapter.ICE_BIOMES; + public static Fishing getInstance() { + if(instance == null) + instance = new Fishing(); - private Fishing() {} + return instance; + } + + public Fishing() { + initFishingXPRewardMap(); + } + + /** + * Inits the Fishing Catch -> XP Reward map + */ + private void initFishingXPRewardMap() + { + fishingXpRewardMap = new HashMap<>(); + HashMap nameRegisterMap = mcMMO.getConfigManager().getConfigExperience().getFishingXPMap(); + + for(String qualifiedName : nameRegisterMap.keySet()) + { + Material material = Material.matchMaterial(qualifiedName); + + if(material == null) + { + mcMMO.p.getLogger().info("Unable to match qualified name to item for fishing xp map: "+qualifiedName); + continue; + } + + fishingXpRewardMap.putIfAbsent(material, nameRegisterMap.get(qualifiedName)); + } + } /** * Finds the possible drops of an entity @@ -34,7 +64,7 @@ public final class Fishing { * Targeted entity * @return possibleDrops List of ItemStack that can be dropped */ - protected static List findPossibleDrops(LivingEntity target) { + public List findPossibleDrops(LivingEntity target) { if (FishingTreasureConfig.getInstance().shakeMap.containsKey(target.getType())) return FishingTreasureConfig.getInstance().shakeMap.get(target.getType()); @@ -48,7 +78,7 @@ public final class Fishing { * List of ItemStack that can be dropped * @return Chosen ItemStack */ - protected static ItemStack chooseDrop(List possibleDrops) { + public ItemStack chooseDrop(List possibleDrops) { int dropProbability = Misc.getRandom().nextInt(100); double cumulatedProbability = 0; @@ -62,4 +92,26 @@ public final class Fishing { return null; } + + public HashMap> getEnchantableCache() { + return ENCHANTABLE_CACHE; + } + + public HashMap getFishingXpRewardMap() { + return fishingXpRewardMap; + } + + public Set getMasterAnglerBiomes() { + return masterAnglerBiomes; + } + + public Set getIceFishingBiomes() { + return iceFishingBiomes; + } + + + public int getFishXPValue(Material material) + { + return fishingXpRewardMap.get(material); + } } diff --git a/src/main/java/com/gmail/nossr50/skills/fishing/FishingManager.java b/src/main/java/com/gmail/nossr50/skills/fishing/FishingManager.java index 270cf1360..261d7f7a4 100644 --- a/src/main/java/com/gmail/nossr50/skills/fishing/FishingManager.java +++ b/src/main/java/com/gmail/nossr50/skills/fishing/FishingManager.java @@ -48,21 +48,22 @@ public class FishingManager extends SkillManager { public final long FISHING_ROD_CAST_CD_MILLISECONDS; public final int OVERFISH_LIMIT; - private long fishingRodCastTimestamp = 0L; - private long fishHookSpawnTimestamp = 0L; - private long lastWarned = 0L; - private long lastWarnedExhaust = 0L; + private long fishingRodCastTimestamp; + private long fishHookSpawnTimestamp; + private long lastWarned; + private long lastWarnedExhaust; private BoundingBox lastFishingBoundingBox; private Location hookLocation; - private int fishCaughtCounter = 1; + private int fishCaughtCounter; private final float boundingBoxSize; - private int overFishCount = 0; + private int overFishCount; public FishingManager(McMMOPlayer mcMMOPlayer) { super(mcMMOPlayer, PrimarySkillType.FISHING); OVERFISH_LIMIT = mcMMO.getConfigManager().getConfigExploitPrevention().getConfigSectionExploitFishing().getOverfishingLimit() + 1; FISHING_ROD_CAST_CD_MILLISECONDS = mcMMO.getConfigManager().getConfigExploitPrevention().getConfigSectionExploitFishing().getFishingRodSpamMilliseconds(); boundingBoxSize = mcMMO.getConfigManager().getConfigExploitPrevention().getConfigSectionExploitFishing().getOverFishingAreaSize(); + fishCaughtCounter = 1; } public boolean canShake(Entity target) { @@ -186,7 +187,7 @@ public class FishingManager extends SkillManager { } // Make sure this is a body of water, not just a block of ice. - if (!Fishing.iceFishingBiomes.contains(block.getBiome()) && (block.getRelative(BlockFace.DOWN, 3).getType() != Material.WATER)) { + if (!Fishing.getInstance().getIceFishingBiomes().contains(block.getBiome()) && (block.getRelative(BlockFace.DOWN, 3).getType() != Material.WATER)) { return false; } @@ -261,7 +262,7 @@ public class FishingManager extends SkillManager { hookLocation = location; - if (Fishing.masterAnglerBiomes.contains(location.getBlock().getBiome())) { + if (Fishing.getInstance().getMasterAnglerBiomes().contains(location.getBlock().getBiome())) { biteChance = biteChance * AdvancedConfig.getInstance().getMasterAnglerBiomeModifier(); } @@ -329,6 +330,8 @@ public class FishingManager extends SkillManager { if (mcMMO.getConfigManager().getConfigFishing().isAlwaysCatchFish()) { Misc.dropItem(player.getEyeLocation(), fishingCatch.getItemStack()); + //Add XP from Fish + fishXp+=Fishing.getInstance().getFishXPValue(fishingCatch.getItemStack().getType()); } fishingCatch.setItemStack(treasureDrop); @@ -360,13 +363,13 @@ public class FishingManager extends SkillManager { */ public void shakeCheck(LivingEntity target) { if (RandomChanceUtil.checkRandomChanceExecutionSuccess(new RandomChanceSkillStatic(getShakeChance(), getPlayer(), SubSkillType.FISHING_SHAKE))) { - List possibleDrops = Fishing.findPossibleDrops(target); + List possibleDrops = Fishing.getInstance().findPossibleDrops(target); if (possibleDrops == null || possibleDrops.isEmpty()) { return; } - ItemStack drop = Fishing.chooseDrop(possibleDrops); + ItemStack drop = Fishing.getInstance().chooseDrop(possibleDrops); // It's possible that chooseDrop returns null if the sum of probability in possibleDrops is inferior than 100 if (drop == null) { @@ -579,8 +582,8 @@ public class FishingManager extends SkillManager { private List getPossibleEnchantments(ItemStack treasureDrop) { Material dropType = treasureDrop.getType(); - if (Fishing.ENCHANTABLE_CACHE.containsKey(dropType)) { - return Fishing.ENCHANTABLE_CACHE.get(dropType); + if (Fishing.getInstance().getEnchantableCache().containsKey(dropType)) { + return Fishing.getInstance().getEnchantableCache().get(dropType); } List possibleEnchantments = new ArrayList<>(); @@ -591,7 +594,7 @@ public class FishingManager extends SkillManager { } } - Fishing.ENCHANTABLE_CACHE.put(dropType, possibleEnchantments); + Fishing.getInstance().getEnchantableCache().put(dropType, possibleEnchantments); return possibleEnchantments; }