From 339ec5be3ed4d42cd411a7179ac35c616a912fa0 Mon Sep 17 00:00:00 2001 From: Zrips Date: Tue, 11 Jun 2024 14:30:32 +0300 Subject: [PATCH] Fixing StackMob support --- .../jobs/hooks/stackMob/StackMobHandler.java | 6 ++-- .../jobs/listeners/JobsPaymentListener.java | 28 +++++++++++-------- 2 files changed, 18 insertions(+), 16 deletions(-) diff --git a/src/main/java/com/gamingmesh/jobs/hooks/stackMob/StackMobHandler.java b/src/main/java/com/gamingmesh/jobs/hooks/stackMob/StackMobHandler.java index b00bf579..fefdfb12 100644 --- a/src/main/java/com/gamingmesh/jobs/hooks/stackMob/StackMobHandler.java +++ b/src/main/java/com/gamingmesh/jobs/hooks/stackMob/StackMobHandler.java @@ -1,7 +1,5 @@ package com.gamingmesh.jobs.hooks.stackMob; -import java.util.Collection; - import org.bukkit.entity.LivingEntity; import org.bukkit.plugin.java.JavaPlugin; @@ -14,8 +12,8 @@ public class StackMobHandler { return getPlugin().getEntityManager().isStackedEntity(entity); } - public Collection getStackEntities() { - return getPlugin().getEntityManager().getStackEntities(); + public StackEntity getStackEntity(LivingEntity entity) { + return getPlugin().getEntityManager().getStackEntity(entity); } public StackMob getPlugin() { diff --git a/src/main/java/com/gamingmesh/jobs/listeners/JobsPaymentListener.java b/src/main/java/com/gamingmesh/jobs/listeners/JobsPaymentListener.java index bd304087..3227ca76 100644 --- a/src/main/java/com/gamingmesh/jobs/listeners/JobsPaymentListener.java +++ b/src/main/java/com/gamingmesh/jobs/listeners/JobsPaymentListener.java @@ -133,9 +133,11 @@ import net.Zrips.CMILib.Items.CMIItemStack; import net.Zrips.CMILib.Items.CMIMC; import net.Zrips.CMILib.Items.CMIMaterial; import net.Zrips.CMILib.Locale.LC; +import net.Zrips.CMILib.Logs.CMIDebug; import net.Zrips.CMILib.Messages.CMIMessages; import net.Zrips.CMILib.Version.Version; import net.Zrips.CMILib.Version.Schedulers.CMIScheduler; +import uk.antiperson.stackmob.entity.StackEntity; public final class JobsPaymentListener implements Listener { @@ -349,10 +351,11 @@ public final class JobsPaymentListener implements Listener { Jobs.action(jDamager, new CustomKillInfo(sheep.getColor().name(), ActionType.SHEAR)); } } else if (JobsHook.StackMob.isEnabled() && HookManager.getStackMobHandler().isStacked(sheep)) { - for (uk.antiperson.stackmob.entity.StackEntity stacked : HookManager.getStackMobHandler().getStackEntities()) { - if (stacked.getEntity().getType() == sheep.getType()) { - Jobs.action(jDamager, new CustomKillInfo(((Sheep) stacked.getEntity()).getColor().name(), ActionType.SHEAR)); - } + + StackEntity stack = HookManager.getStackMobHandler().getStackEntity(sheep); + if (stack != null) { + Jobs.action(jDamager, new CustomKillInfo(sheep.getColor().name(), ActionType.SHEAR)); + return; } } } @@ -615,10 +618,11 @@ public final class JobsPaymentListener implements Listener { Jobs.action(jDamager, new EntityActionInfo(animal, ActionType.TAME)); } } else if (JobsHook.StackMob.isEnabled() && HookManager.getStackMobHandler().isStacked(animal)) { - for (uk.antiperson.stackmob.entity.StackEntity stacked : HookManager.getStackMobHandler().getStackEntities()) { - if (stacked.getEntity().getType() == animal.getType()) { - Jobs.action(jDamager, new EntityActionInfo(stacked.getEntity(), ActionType.TAME)); - } + + StackEntity stack = HookManager.getStackMobHandler().getStackEntity(animal); + if (stack != null) { + Jobs.action(jDamager, new EntityActionInfo(animal, ActionType.TAME)); + return; } } } @@ -1407,10 +1411,10 @@ public final class JobsPaymentListener implements Listener { Jobs.action(jDamager, new EntityActionInfo(lVictim, ActionType.KILL), killer, lVictim); } } else if (JobsHook.StackMob.isEnabled() && HookManager.getStackMobHandler().isStacked(lVictim)) { - for (uk.antiperson.stackmob.entity.StackEntity stacked : HookManager.getStackMobHandler().getStackEntities()) { - if (stacked.getEntity().getType() == lVictim.getType()) { - Jobs.action(jDamager, new EntityActionInfo(stacked.getEntity(), ActionType.KILL), killer, stacked.getEntity()); - } + StackEntity stack = HookManager.getStackMobHandler().getStackEntity(lVictim); + if (stack != null) { + Jobs.action(jDamager, new EntityActionInfo(lVictim, ActionType.KILL), killer, lVictim); + return; } } }