From 0c0a0d8f2b02db74bcf9d4cd83eb49c9c438253e Mon Sep 17 00:00:00 2001 From: XiaoMoMi <972454774@qq.com> Date: Sun, 12 Nov 2023 20:44:21 +0800 Subject: [PATCH] fix bugs --- .../api/event/FishHookLandEvent.java | 21 +++++++++++++--- .../condition/FishingPreparation.java | 3 +-- .../mechanic/fishing/FishingManagerImpl.java | 4 +-- .../mechanic/fishing/HookCheckTimerTask.java | 20 ++++++++------- .../mechanic/item/ItemManagerImpl.java | 3 +++ .../mechanic/misc/value/Value.java | 25 ------------------- 6 files changed, 33 insertions(+), 43 deletions(-) delete mode 100644 plugin/src/main/java/net/momirealms/customfishing/mechanic/misc/value/Value.java diff --git a/api/src/main/java/net/momirealms/customfishing/api/event/FishHookLandEvent.java b/api/src/main/java/net/momirealms/customfishing/api/event/FishHookLandEvent.java index 28bbe8d4..b8e89547 100644 --- a/api/src/main/java/net/momirealms/customfishing/api/event/FishHookLandEvent.java +++ b/api/src/main/java/net/momirealms/customfishing/api/event/FishHookLandEvent.java @@ -17,6 +17,7 @@ package net.momirealms.customfishing.api.event; +import net.momirealms.customfishing.api.mechanic.effect.Effect; import org.bukkit.entity.FishHook; import org.bukkit.entity.Player; import org.bukkit.event.HandlerList; @@ -31,18 +32,21 @@ public class FishHookLandEvent extends PlayerEvent { private static final HandlerList handlerList = new HandlerList(); private final Target target; private final FishHook fishHook; + private final Effect effect; /** * Constructs a new FishHookLandEvent. * - * @param who The player who triggered the event. - * @param target The target where the fishing hook has landed (LAVA or WATER). - * @param hook The fishing hook entity. + * @param who The player who triggered the event. + * @param target The target where the fishing hook has landed (LAVA or WATER). + * @param hook The fishing hook entity. + * @param initialEffect The initial effect */ - public FishHookLandEvent(@NotNull Player who, Target target, FishHook hook) { + public FishHookLandEvent(@NotNull Player who, Target target, FishHook hook, Effect initialEffect) { super(who); this.target = target; this.fishHook = hook; + this.effect = initialEffect; } /** @@ -67,6 +71,15 @@ public class FishHookLandEvent extends PlayerEvent { return handlerList; } + /** + * Get the fishing effect + * + * @return fishing effect + */ + public Effect getEffect() { + return effect; + } + @NotNull @Override public HandlerList getHandlers() { diff --git a/api/src/main/java/net/momirealms/customfishing/api/mechanic/condition/FishingPreparation.java b/api/src/main/java/net/momirealms/customfishing/api/mechanic/condition/FishingPreparation.java index 9d9b911d..0f3c579d 100644 --- a/api/src/main/java/net/momirealms/customfishing/api/mechanic/condition/FishingPreparation.java +++ b/api/src/main/java/net/momirealms/customfishing/api/mechanic/condition/FishingPreparation.java @@ -91,8 +91,7 @@ public class FishingPreparation extends Condition { this.insertArg("{in-bag}", "true"); for (int i = 0; i < fishingBag.getSize(); i++) { ItemStack itemInBag = fishingBag.getItem(i); - String bagItemID = plugin.getItemManager().getCustomFishingItemID(itemInBag); - if (bagItemID == null) continue; + String bagItemID = plugin.getItemManager().getAnyPluginItemID(itemInBag); if (!hasBait) { EffectCarrier effect = plugin.getEffectManager().getEffectCarrier("bait", bagItemID); if (effect != null) { diff --git a/plugin/src/main/java/net/momirealms/customfishing/mechanic/fishing/FishingManagerImpl.java b/plugin/src/main/java/net/momirealms/customfishing/mechanic/fishing/FishingManagerImpl.java index 000dda77..50405fdf 100644 --- a/plugin/src/main/java/net/momirealms/customfishing/mechanic/fishing/FishingManagerImpl.java +++ b/plugin/src/main/java/net/momirealms/customfishing/mechanic/fishing/FishingManagerImpl.java @@ -299,15 +299,13 @@ public class FishingManagerImpl implements Listener, FishingManager { } // Check mechanic requirements if (!RequirementManager.isRequirementMet( - fishingPreparation, RequirementManagerImpl.mechanicRequirements + fishingPreparation, RequirementManagerImpl.mechanicRequirements )) { removeTempFishingState(player); return; } // Merge rod/bait/util effects FishingEffect initialEffect = plugin.getEffectManager().getInitialEffect(); - fishingPreparation.mergeEffect(initialEffect); - // Merge totem effects EffectCarrier totemEffect = plugin.getTotemManager().getTotemEffect(player.getLocation()); if (totemEffect != null) diff --git a/plugin/src/main/java/net/momirealms/customfishing/mechanic/fishing/HookCheckTimerTask.java b/plugin/src/main/java/net/momirealms/customfishing/mechanic/fishing/HookCheckTimerTask.java index bfc0a935..8a2d3fc0 100644 --- a/plugin/src/main/java/net/momirealms/customfishing/mechanic/fishing/HookCheckTimerTask.java +++ b/plugin/src/main/java/net/momirealms/customfishing/mechanic/fishing/HookCheckTimerTask.java @@ -26,7 +26,7 @@ import net.momirealms.customfishing.api.event.LavaFishingEvent; import net.momirealms.customfishing.api.mechanic.TempFishingState; import net.momirealms.customfishing.api.mechanic.action.ActionTrigger; import net.momirealms.customfishing.api.mechanic.condition.FishingPreparation; -import net.momirealms.customfishing.api.mechanic.effect.Effect; +import net.momirealms.customfishing.api.mechanic.effect.FishingEffect; import net.momirealms.customfishing.api.mechanic.loot.Loot; import net.momirealms.customfishing.api.scheduler.CancellableTask; import net.momirealms.customfishing.setting.CFConfig; @@ -56,7 +56,7 @@ public class HookCheckTimerTask implements Runnable { private LavaEffectTask lavaFishingTask; private final FishHook fishHook; private final FishingPreparation fishingPreparation; - private final Effect initialEffect; + private final FishingEffect initialEffect; private final int lureLevel; private boolean firstTime; private boolean fishHooked; @@ -77,7 +77,7 @@ public class HookCheckTimerTask implements Runnable { FishingManagerImpl manager, FishHook fishHook, FishingPreparation fishingPreparation, - Effect initialEffect + FishingEffect initialEffect ) { this.manager = manager; this.fishHook = fishHook; @@ -102,15 +102,16 @@ public class HookCheckTimerTask implements Runnable { } if (fishHook.getLocation().getBlock().getType() == Material.LAVA) { // if player can fish in lava - if (!initialEffect.canLavaFishing()) { - this.destroy(); - return; - } if (firstTime) { this.fishingPreparation.setLocation(fishHook.getLocation()); + this.fishingPreparation.mergeEffect(initialEffect); + if (!initialEffect.canLavaFishing()) { + this.destroy(); + return; + } this.fishingPreparation.insertArg("{lava}", "true"); this.fishingPreparation.triggerActions(ActionTrigger.LAND); - FishHookLandEvent event = new FishHookLandEvent(fishingPreparation.getPlayer(), FishHookLandEvent.Target.LAVA, fishHook); + FishHookLandEvent event = new FishHookLandEvent(fishingPreparation.getPlayer(), FishHookLandEvent.Target.LAVA, fishHook, initialEffect); Bukkit.getPluginManager().callEvent(event); firstTime = false; this.setTempState(); @@ -138,10 +139,11 @@ public class HookCheckTimerTask implements Runnable { } if (fishHook.isInWater()) { this.fishingPreparation.setLocation(fishHook.getLocation()); + this.fishingPreparation.mergeEffect(initialEffect); this.fishingPreparation.insertArg("{lava}", "false"); this.fishingPreparation.insertArg("{open-water}", String.valueOf(fishHook.isInOpenWater())); this.fishingPreparation.triggerActions(ActionTrigger.LAND); - FishHookLandEvent event = new FishHookLandEvent(fishingPreparation.getPlayer(), FishHookLandEvent.Target.WATER, fishHook); + FishHookLandEvent event = new FishHookLandEvent(fishingPreparation.getPlayer(), FishHookLandEvent.Target.WATER, fishHook, initialEffect); Bukkit.getPluginManager().callEvent(event); // if the hook is in water // then cancel the task diff --git a/plugin/src/main/java/net/momirealms/customfishing/mechanic/item/ItemManagerImpl.java b/plugin/src/main/java/net/momirealms/customfishing/mechanic/item/ItemManagerImpl.java index 34ad5f99..6d581b1a 100644 --- a/plugin/src/main/java/net/momirealms/customfishing/mechanic/item/ItemManagerImpl.java +++ b/plugin/src/main/java/net/momirealms/customfishing/mechanic/item/ItemManagerImpl.java @@ -361,6 +361,9 @@ public class ItemManagerImpl implements ItemManager, Listener { @NotNull public ItemStack build(Player player, ItemBuilder builder, Map placeholders) { ItemStack temp = itemLibraryMap.get(builder.getLibrary()).buildItem(player, builder.getId()); + if (temp.getType() == Material.AIR) { + return temp; + } temp.setAmount(builder.getAmount()); NBTItem nbtItem = new NBTItem(temp); for (ItemBuilder.ItemPropertyEditor editor : builder.getEditors()) { diff --git a/plugin/src/main/java/net/momirealms/customfishing/mechanic/misc/value/Value.java b/plugin/src/main/java/net/momirealms/customfishing/mechanic/misc/value/Value.java deleted file mode 100644 index c37f1fd3..00000000 --- a/plugin/src/main/java/net/momirealms/customfishing/mechanic/misc/value/Value.java +++ /dev/null @@ -1,25 +0,0 @@ -/* - * Copyright (C) <2022> - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see . - */ - -package net.momirealms.customfishing.mechanic.misc.value; - -import org.bukkit.entity.Player; - -public interface Value { - - double get(Player player); -}