From 19bf96ab33708758c75f8ffb3f87f80677576415 Mon Sep 17 00:00:00 2001 From: nossr50 Date: Sat, 16 Nov 2024 15:48:41 -0800 Subject: [PATCH] Expand API for McMMOPlayerMasterAnglerEvent --- .../fishing/McMMOPlayerMasterAnglerEvent.java | 45 +++++++++++++++-- .../skills/fishing/FishingManager.java | 49 +++++++++++++------ 2 files changed, 75 insertions(+), 19 deletions(-) diff --git a/src/main/java/com/gmail/nossr50/events/skills/fishing/McMMOPlayerMasterAnglerEvent.java b/src/main/java/com/gmail/nossr50/events/skills/fishing/McMMOPlayerMasterAnglerEvent.java index c7b77baa6..a3532fa23 100644 --- a/src/main/java/com/gmail/nossr50/events/skills/fishing/McMMOPlayerMasterAnglerEvent.java +++ b/src/main/java/com/gmail/nossr50/events/skills/fishing/McMMOPlayerMasterAnglerEvent.java @@ -1,14 +1,53 @@ package com.gmail.nossr50.events.skills.fishing; import com.gmail.nossr50.datatypes.player.McMMOPlayer; -import org.bukkit.entity.Player; -import org.bukkit.inventory.ItemStack; +import com.gmail.nossr50.skills.fishing.FishingManager; import org.jetbrains.annotations.NotNull; public class McMMOPlayerMasterAnglerEvent extends McMMOPlayerFishingEvent { + private int reducedMinWaitTime; + private int reducedMaxWaitTime; + private final FishingManager fishingManager; - public McMMOPlayerMasterAnglerEvent(@NotNull McMMOPlayer mcMMOPlayer) { + public McMMOPlayerMasterAnglerEvent(@NotNull McMMOPlayer mcMMOPlayer, + int reducedMinWaitTime, + int reducedMaxWaitTime, + FishingManager fishingManager) { super(mcMMOPlayer); + this.fishingManager = fishingManager; + this.reducedMinWaitTime = Math.max(reducedMinWaitTime, getReducedMinWaitTimeLowerBound()); + this.reducedMaxWaitTime = Math.max(reducedMaxWaitTime, getReducedMaxWaitTimeLowerBound()); } + public int getReducedMinWaitTime() { + return reducedMinWaitTime; + } + + public void setReducedMinWaitTime(int reducedMinWaitTime) { + if (reducedMinWaitTime < 0 || reducedMinWaitTime > reducedMaxWaitTime) { + throw new IllegalArgumentException("Reduced min wait time must be greater than or equal to 0" + + " and less than reduced max wait time."); + } + this.reducedMinWaitTime = Math.max(reducedMinWaitTime, getReducedMinWaitTimeLowerBound()); + } + + public int getReducedMaxWaitTime() { + return reducedMaxWaitTime; + } + + public void setReducedMaxWaitTime(int reducedMaxWaitTime) { + if (reducedMaxWaitTime < 0 || reducedMaxWaitTime < reducedMinWaitTime) { + throw new IllegalArgumentException("Reduced max wait time must be greater than or equal to 0" + + " and greater than reduced min wait time."); + } + this.reducedMaxWaitTime = Math.max(reducedMaxWaitTime, getReducedMaxWaitTimeLowerBound()); + } + + public int getReducedMinWaitTimeLowerBound() { + return fishingManager.getMasterAnglerMinWaitLowerBound(); + } + + public int getReducedMaxWaitTimeLowerBound() { + return fishingManager.getMasterAnglerMaxWaitLowerBound(); + } } \ No newline at end of file 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 2466988c7..ed0094a56 100644 --- a/src/main/java/com/gmail/nossr50/skills/fishing/FishingManager.java +++ b/src/main/java/com/gmail/nossr50/skills/fishing/FishingManager.java @@ -56,9 +56,17 @@ public class FishingManager extends SkillManager { private Item fishingCatch; private Location hookLocation; private int fishCaughtCounter = 1; + private final int masterAnglerMinWaitLowerBound; + private final int masterAnglerMaxWaitLowerBound; public FishingManager(McMMOPlayer mcMMOPlayer) { super(mcMMOPlayer, PrimarySkillType.FISHING); + //Ticks for minWait and maxWait never go below this value + int bonusCapMin = mcMMO.p.getAdvancedConfig().getFishingReductionMinWaitCap(); + int bonusCapMax = mcMMO.p.getAdvancedConfig().getFishingReductionMaxWaitCap(); + + this.masterAnglerMinWaitLowerBound = Math.max(bonusCapMin, 0); + this.masterAnglerMaxWaitLowerBound = Math.max(bonusCapMax, masterAnglerMinWaitLowerBound + 40); } public boolean canShake(Entity target) { @@ -254,13 +262,6 @@ public class FishingManager extends SkillManager { * @param fishHook target fish hook */ public void processMasterAngler(@NotNull FishHook fishHook, int lureLevel) { - McMMOPlayerMasterAnglerEvent event = new McMMOPlayerMasterAnglerEvent(mmoPlayer); - mcMMO.p.getServer().getPluginManager().callEvent(event); - - if (event.isCancelled()) { - return; - } - MasterAnglerCompatibilityLayer masterAnglerCompatibilityLayer = (MasterAnglerCompatibilityLayer) mcMMO.getCompatibilityManager().getMasterAnglerCompatibilityLayer(); if (masterAnglerCompatibilityLayer != null) { @@ -280,12 +281,8 @@ public class FishingManager extends SkillManager { int minWaitReduction = getMasterAnglerTickMinWaitReduction(masterAnglerRank, boatBonus); int maxWaitReduction = getMasterAnglerTickMaxWaitReduction(masterAnglerRank, boatBonus, convertedLureBonus); - //Ticks for minWait and maxWait never go below this value - int bonusCapMin = mcMMO.p.getAdvancedConfig().getFishingReductionMinWaitCap(); - int bonusCapMax = mcMMO.p.getAdvancedConfig().getFishingReductionMaxWaitCap(); - - int reducedMinWaitTime = getReducedTicks(minWaitTicks, minWaitReduction, bonusCapMin); - int reducedMaxWaitTime = getReducedTicks(maxWaitTicks, maxWaitReduction, bonusCapMax); + int reducedMinWaitTime = getReducedTicks(minWaitTicks, minWaitReduction, masterAnglerMinWaitLowerBound); + int reducedMaxWaitTime = getReducedTicks(maxWaitTicks, maxWaitReduction, masterAnglerMaxWaitLowerBound); boolean badValuesFix = false; @@ -295,11 +292,23 @@ public class FishingManager extends SkillManager { badValuesFix = true; } + final McMMOPlayerMasterAnglerEvent event = + new McMMOPlayerMasterAnglerEvent(mmoPlayer, reducedMinWaitTime, reducedMaxWaitTime, this); + mcMMO.p.getServer().getPluginManager().callEvent(event); + + if (event.isCancelled()) { + return; + } + + reducedMaxWaitTime = event.getReducedMaxWaitTime(); + reducedMinWaitTime = event.getReducedMinWaitTime(); + if (mmoPlayer.isDebugMode()) { mmoPlayer.getPlayer().sendMessage(ChatColor.GOLD + "Master Angler Debug"); if (badValuesFix) { - mmoPlayer.getPlayer().sendMessage(ChatColor.RED + "Bad values were applied and corrected, check your configs, max wait should never be lower than min wait."); + mmoPlayer.getPlayer().sendMessage(ChatColor.RED + "Bad values were applied and corrected," + + " check your configs, minWaitLowerBound wait should never be lower than min wait."); } mmoPlayer.getPlayer().sendMessage("ALLOW STACK WITH LURE: " + masterAnglerCompatibilityLayer.getApplyLure(fishHook)); @@ -326,8 +335,8 @@ public class FishingManager extends SkillManager { mmoPlayer.getPlayer().sendMessage(""); mmoPlayer.getPlayer().sendMessage(ChatColor.DARK_AQUA + "Caps / Limits (edit in advanced.yml)"); - mmoPlayer.getPlayer().sendMessage("Lowest possible max wait ticks " + bonusCapMax); - mmoPlayer.getPlayer().sendMessage("Lowest possible min wait ticks " + bonusCapMin); + mmoPlayer.getPlayer().sendMessage("Lowest possible minWaitLowerBound wait ticks " + masterAnglerMinWaitLowerBound); + mmoPlayer.getPlayer().sendMessage("Lowest possible min wait ticks " + masterAnglerMaxWaitLowerBound); } masterAnglerCompatibilityLayer.setMaxWaitTime(fishHook, reducedMaxWaitTime); @@ -724,4 +733,12 @@ public class FishingManager extends SkillManager { private int getVanillaXpMultiplier() { return getVanillaXPBoostModifier(); } + + public int getMasterAnglerMinWaitLowerBound() { + return masterAnglerMinWaitLowerBound; + } + + public int getMasterAnglerMaxWaitLowerBound() { + return masterAnglerMaxWaitLowerBound; + } } \ No newline at end of file