From 2639e9802d593c364babcf0132435864374f6b2d Mon Sep 17 00:00:00 2001 From: Zrips Date: Mon, 7 Mar 2022 17:19:59 +0200 Subject: [PATCH] Entity split spawned from spawners fix --- .../jobs/listeners/JobsPayment14Listener.java | 7 +++++-- .../gamingmesh/jobs/listeners/JobsPaymentListener.java | 10 +++++++--- 2 files changed, 12 insertions(+), 5 deletions(-) diff --git a/src/main/java/com/gamingmesh/jobs/listeners/JobsPayment14Listener.java b/src/main/java/com/gamingmesh/jobs/listeners/JobsPayment14Listener.java index ef79ccd1..9ecff662 100644 --- a/src/main/java/com/gamingmesh/jobs/listeners/JobsPayment14Listener.java +++ b/src/main/java/com/gamingmesh/jobs/listeners/JobsPayment14Listener.java @@ -24,14 +24,16 @@ import com.gamingmesh.jobs.actions.ItemActionInfo; import com.gamingmesh.jobs.container.ActionType; import com.gamingmesh.jobs.container.PlayerCamp; +import net.Zrips.CMILib.Logs.CMIDebug; + public final class JobsPayment14Listener implements Listener { // BlockCookEvent does not have "cooking owner" private final Map> campPlayers = new HashMap<>(); - @EventHandler(priority = EventPriority.MONITOR, ignoreCancelled = true) + @EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true) public void onEntityTransformEvent(EntityTransformEvent event) { - + if (!Jobs.getGCManager().canPerformActionInWorld(event.getEntity().getWorld())) return; @@ -62,6 +64,7 @@ public final class JobsPayment14Listener implements Listener { case "SHEARED": break; case "SPLIT": + if (!event.getEntityType().equals(EntityType.SLIME) && !event.getEntityType().equals(EntityType.MAGMA_CUBE)) return; for (Entity entity : event.getTransformedEntities()) { diff --git a/src/main/java/com/gamingmesh/jobs/listeners/JobsPaymentListener.java b/src/main/java/com/gamingmesh/jobs/listeners/JobsPaymentListener.java index 5591495f..6bc2ddfb 100644 --- a/src/main/java/com/gamingmesh/jobs/listeners/JobsPaymentListener.java +++ b/src/main/java/com/gamingmesh/jobs/listeners/JobsPaymentListener.java @@ -128,6 +128,7 @@ import net.Zrips.CMILib.Container.CMILocation; import net.Zrips.CMILib.Entities.CMIEntityType; import net.Zrips.CMILib.Items.CMIItemStack; import net.Zrips.CMILib.Items.CMIMaterial; +import net.Zrips.CMILib.Logs.CMIDebug; import net.Zrips.CMILib.Version.Version; public final class JobsPaymentListener implements Listener { @@ -1250,10 +1251,13 @@ public final class JobsPaymentListener implements Listener { if (!Jobs.getGCManager().payNearSpawner() && lVictim.hasMetadata(Jobs.getPlayerManager().getMobSpawnerMetadata())) { try { // So lets remove meta in case some plugin removes entity in wrong way. - lVictim.removeMetadata(Jobs.getPlayerManager().getMobSpawnerMetadata(), plugin); - } catch (Exception ignored) { + // Need to delay action for other function to properly check for existing meta data relating to this entity before clearing it out + // Longer delay is needed due to mob split event being fired few seconds after mob dies and not at same time + Bukkit.getServer().getScheduler().scheduleSyncDelayedTask(plugin, () -> { + lVictim.removeMetadata(Jobs.getPlayerManager().getMobSpawnerMetadata(), plugin); + }, 200L); + } catch (Throwable ignored) { } - return; }