From 3b9ab47a97779b8c4b900084f54933f1b8556861 Mon Sep 17 00:00:00 2001 From: Joo200 Date: Thu, 17 Oct 2024 01:43:27 +0200 Subject: [PATCH] Avoid using metadata storage if possible (#2150) * Avoid using metadata storage if possible * Fix cause detection, use always on paper * Fix fat fingers Co-authored-by: aurora <21148213+aurorasmiles@users.noreply.github.com> --- .../com/sk89q/worldguard/bukkit/cause/Cause.java | 12 ++++++++++-- .../bukkit/listener/EventAbstractionListener.java | 12 +++++------- 2 files changed, 15 insertions(+), 9 deletions(-) diff --git a/worldguard-bukkit/src/main/java/com/sk89q/worldguard/bukkit/cause/Cause.java b/worldguard-bukkit/src/main/java/com/sk89q/worldguard/bukkit/cause/Cause.java index f3847b33..84f0c3f6 100644 --- a/worldguard-bukkit/src/main/java/com/sk89q/worldguard/bukkit/cause/Cause.java +++ b/worldguard-bukkit/src/main/java/com/sk89q/worldguard/bukkit/cause/Cause.java @@ -32,8 +32,10 @@ import org.bukkit.entity.AnimalTamer; import org.bukkit.entity.AreaEffectCloud; import org.bukkit.entity.Creature; +import org.bukkit.entity.Creeper; import org.bukkit.entity.Entity; import org.bukkit.entity.EntityType; +import org.bukkit.entity.FallingBlock; import org.bukkit.entity.Firework; import org.bukkit.entity.LightningStrike; import org.bukkit.entity.Player; @@ -326,15 +328,21 @@ private void addAll(@Nullable Object... element) { addAll(player.getPlayer()); // player object if online, else null } } - } else if (o instanceof Creature && ((Creature) o).getTarget() != null) { + } else if (o instanceof Creeper c) { indirect = true; - addAll(((Creature) o).getTarget()); + addAll(c.getTarget(), c.getIgniter()); + } else if (o instanceof Creature c) { + indirect = true; + addAll(c.getTarget()); } else if (o instanceof BlockProjectileSource) { addAll(((BlockProjectileSource) o).getBlock()); } else if (o instanceof LightningStrike && PaperLib.isPaper() && ((LightningStrike) o).getCausingEntity() != null) { indirect = true; addAll(((LightningStrike) o).getCausingEntity()); + } else if (o instanceof FallingBlock f && PaperLib.isPaper() && f.getOrigin() != null) { + indirect = true; + addAll(f.getOrigin().getBlock()); } // Add manually tracked parent causes diff --git a/worldguard-bukkit/src/main/java/com/sk89q/worldguard/bukkit/listener/EventAbstractionListener.java b/worldguard-bukkit/src/main/java/com/sk89q/worldguard/bukkit/listener/EventAbstractionListener.java index f2e771db..334127cc 100644 --- a/worldguard-bukkit/src/main/java/com/sk89q/worldguard/bukkit/listener/EventAbstractionListener.java +++ b/worldguard-bukkit/src/main/java/com/sk89q/worldguard/bukkit/listener/EventAbstractionListener.java @@ -347,7 +347,10 @@ public void onEntityChangeBlock(EntityChangeBlockEvent event) { } else if (toType == Material.AIR) { // Track the source so later we can create a proper chain of causes if (entity instanceof FallingBlock) { - Cause.trackParentCause(entity, block); + if (!PaperLib.isPaper()) { + // On paper we use FallingBlock#getOrigin to get the origin location, on spigot we store it. + Cause.trackParentCause(entity, block); + } // Switch around the event Events.fireToCancel(event, new SpawnEntityEvent(event, create(block), entity)); @@ -864,12 +867,7 @@ public void onPlayerInteractEntity(PlayerInteractEntityEvent event) { if (matchingItem != null && hasInteractBypass(world, matchingItem)) { useEntityEvent.setAllowed(true); } - if (!Events.fireToCancel(event, useEntityEvent)) { - // so this is a hack but CreeperIgniteEvent doesn't actually tell us who, so we need to do it here - if (item.getType() == Material.FLINT_AND_STEEL && entity.getType() == EntityType.CREEPER) { - Cause.trackParentCause(entity, player); - } - } + Events.fireToCancel(event, useEntityEvent); } @EventHandler(ignoreCancelled = true)