Skip to content

Commit 3b9ab47

Browse files
Joo200aurorasmiles
andauthored
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>
1 parent d9716a5 commit 3b9ab47

2 files changed

Lines changed: 15 additions & 9 deletions

File tree

worldguard-bukkit/src/main/java/com/sk89q/worldguard/bukkit/cause/Cause.java

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,8 +32,10 @@
3232
import org.bukkit.entity.AnimalTamer;
3333
import org.bukkit.entity.AreaEffectCloud;
3434
import org.bukkit.entity.Creature;
35+
import org.bukkit.entity.Creeper;
3536
import org.bukkit.entity.Entity;
3637
import org.bukkit.entity.EntityType;
38+
import org.bukkit.entity.FallingBlock;
3739
import org.bukkit.entity.Firework;
3840
import org.bukkit.entity.LightningStrike;
3941
import org.bukkit.entity.Player;
@@ -326,15 +328,21 @@ private void addAll(@Nullable Object... element) {
326328
addAll(player.getPlayer()); // player object if online, else null
327329
}
328330
}
329-
} else if (o instanceof Creature && ((Creature) o).getTarget() != null) {
331+
} else if (o instanceof Creeper c) {
330332
indirect = true;
331-
addAll(((Creature) o).getTarget());
333+
addAll(c.getTarget(), c.getIgniter());
334+
} else if (o instanceof Creature c) {
335+
indirect = true;
336+
addAll(c.getTarget());
332337
} else if (o instanceof BlockProjectileSource) {
333338
addAll(((BlockProjectileSource) o).getBlock());
334339
} else if (o instanceof LightningStrike && PaperLib.isPaper() &&
335340
((LightningStrike) o).getCausingEntity() != null) {
336341
indirect = true;
337342
addAll(((LightningStrike) o).getCausingEntity());
343+
} else if (o instanceof FallingBlock f && PaperLib.isPaper() && f.getOrigin() != null) {
344+
indirect = true;
345+
addAll(f.getOrigin().getBlock());
338346
}
339347

340348
// Add manually tracked parent causes

worldguard-bukkit/src/main/java/com/sk89q/worldguard/bukkit/listener/EventAbstractionListener.java

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -347,7 +347,10 @@ public void onEntityChangeBlock(EntityChangeBlockEvent event) {
347347
} else if (toType == Material.AIR) {
348348
// Track the source so later we can create a proper chain of causes
349349
if (entity instanceof FallingBlock) {
350-
Cause.trackParentCause(entity, block);
350+
if (!PaperLib.isPaper()) {
351+
// On paper we use FallingBlock#getOrigin to get the origin location, on spigot we store it.
352+
Cause.trackParentCause(entity, block);
353+
}
351354

352355
// Switch around the event
353356
Events.fireToCancel(event, new SpawnEntityEvent(event, create(block), entity));
@@ -864,12 +867,7 @@ public void onPlayerInteractEntity(PlayerInteractEntityEvent event) {
864867
if (matchingItem != null && hasInteractBypass(world, matchingItem)) {
865868
useEntityEvent.setAllowed(true);
866869
}
867-
if (!Events.fireToCancel(event, useEntityEvent)) {
868-
// so this is a hack but CreeperIgniteEvent doesn't actually tell us who, so we need to do it here
869-
if (item.getType() == Material.FLINT_AND_STEEL && entity.getType() == EntityType.CREEPER) {
870-
Cause.trackParentCause(entity, player);
871-
}
872-
}
870+
Events.fireToCancel(event, useEntityEvent);
873871
}
874872

875873
@EventHandler(ignoreCancelled = true)

0 commit comments

Comments
 (0)