From 54445d14649e2ec5a0fb4c36fe34002954d1d3cd Mon Sep 17 00:00:00 2001 From: XiaoMoMi <972454774@qq.com> Date: Wed, 27 Mar 2024 01:59:02 +0800 Subject: [PATCH] 2.1.3 --- build.gradle.kts | 2 +- .../mechanic/item/ItemManagerImpl.java | 37 ++++++++++++++----- 2 files changed, 29 insertions(+), 10 deletions(-) diff --git a/build.gradle.kts b/build.gradle.kts index 1c410c86..aa14178f 100644 --- a/build.gradle.kts +++ b/build.gradle.kts @@ -7,7 +7,7 @@ plugins { allprojects { - version = "2.1.2.1" + version = "2.1.3" apply() apply(plugin = "java") 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 3101eb67..94ca6f81 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 @@ -78,6 +78,7 @@ import org.jetbrains.annotations.Nullable; import java.io.File; import java.util.*; import java.util.concurrent.ThreadLocalRandom; +import java.util.concurrent.TimeUnit; public class ItemManagerImpl implements ItemManager, Listener { @@ -484,6 +485,13 @@ public class ItemManagerImpl implements ItemManager, Listener { return; } + itemEntity.setInvulnerable(true); + plugin.getScheduler().runTaskAsyncLater(() -> { + if (itemEntity.isValid()) { + itemEntity.setInvulnerable(false); + } + }, 1, TimeUnit.SECONDS); + Vector vector = playerLocation.subtract(hookLocation).toVector().multiply(0.105); vector = vector.setY((vector.getY() + 0.22) * 1.18); itemEntity.setVelocity(vector); @@ -968,7 +976,7 @@ public class ItemManagerImpl implements ItemManager, Listener { * @param event The PlayerInteractEvent. */ @EventHandler - public void onInteractWithUtils(PlayerInteractEvent event) { + public void onInteractWithItems(PlayerInteractEvent event) { if (event.useItemInHand() == Event.Result.DENY) return; if (event.getHand() != EquipmentSlot.HAND) @@ -979,16 +987,27 @@ public class ItemManagerImpl implements ItemManager, Listener { if (event.getAction() != org.bukkit.event.block.Action.RIGHT_CLICK_AIR && event.getAction() != org.bukkit.event.block.Action.RIGHT_CLICK_BLOCK) return; String id = getAnyPluginItemID(itemStack); - EffectCarrier carrier = plugin.getEffectManager().getEffectCarrier("util", id); - if (carrier == null) - return; Condition condition = new Condition(event.getPlayer()); - if (!RequirementManager.isRequirementMet(condition, carrier.getRequirements())) + + Loot loot = plugin.getLootManager().getLoot(id); + if (loot != null) { + loot.triggerActions(ActionTrigger.INTERACT, condition); return; - Action[] actions = carrier.getActions(ActionTrigger.INTERACT); - if (actions != null) - for (Action action : actions) { - action.trigger(condition); + } + + // because the id can be from other plugins, so we can't infer the type of the item + for (String type : List.of("util", "bait", "rod", "hook")) { + EffectCarrier carrier = plugin.getEffectManager().getEffectCarrier(type, id); + if (carrier != null) { + if (!RequirementManager.isRequirementMet(condition, carrier.getRequirements())) + return; + Action[] actions = carrier.getActions(ActionTrigger.INTERACT); + if (actions != null) + for (Action action : actions) { + action.trigger(condition); + } + break; } + } } } \ No newline at end of file