From e44a0c17001cb09ba3c3803137f97a26955e95a0 Mon Sep 17 00:00:00 2001 From: socram8888 Date: Sat, 16 Mar 2013 18:06:21 +0100 Subject: [PATCH] Added logging of Minecarts with TNT --- src/main/java/de/diddiz/LogBlock/Logging.java | 2 +- .../LogBlock/listeners/ExplosionLogging.java | 28 +++++++++++-------- 2 files changed, 17 insertions(+), 13 deletions(-) diff --git a/src/main/java/de/diddiz/LogBlock/Logging.java b/src/main/java/de/diddiz/LogBlock/Logging.java index 0c25411..2f5e3f4 100644 --- a/src/main/java/de/diddiz/LogBlock/Logging.java +++ b/src/main/java/de/diddiz/LogBlock/Logging.java @@ -7,7 +7,7 @@ public enum Logging LAVAFLOW, WATERFLOW, CHESTACCESS, KILL, CHAT, SNOWFORM, SNOWFADE, DOORINTERACT, SWITCHINTERACT, CAKEEAT, ENDERMEN, NOTEBLOCKINTERACT, DIODEINTERACT, NATURALSTRUCTUREGROW, WITHER(true), WITHER_SKULL(true), - BONEMEALSTRUCTUREGROW, WORLDEDIT; + BONEMEALSTRUCTUREGROW, WORLDEDIT, TNTMINECARTEXPLOSION(true); public static final int length = Logging.values().length; private final boolean defaultEnabled; diff --git a/src/main/java/de/diddiz/LogBlock/listeners/ExplosionLogging.java b/src/main/java/de/diddiz/LogBlock/listeners/ExplosionLogging.java index 8f324d5..f16f8ef 100644 --- a/src/main/java/de/diddiz/LogBlock/listeners/ExplosionLogging.java +++ b/src/main/java/de/diddiz/LogBlock/listeners/ExplosionLogging.java @@ -10,6 +10,7 @@ import org.bukkit.entity.EnderDragon; import org.bukkit.entity.Entity; import org.bukkit.entity.Fireball; import org.bukkit.entity.Ghast; +import org.bukkit.entity.minecart.ExplosiveMinecart; import org.bukkit.entity.Player; import org.bukkit.entity.TNTPrimed; import org.bukkit.entity.Wither; @@ -31,25 +32,29 @@ public class ExplosionLogging extends LoggingListener public void onEntityExplode(EntityExplodeEvent event) { final WorldConfig wcfg = getWorldConfig(event.getLocation().getWorld()); if (wcfg != null) { - String name = "Unknown"; - if (event.getEntity() == null) { + String name = "Explosion"; + Entity source = event.getEntity(); + if (source == null) { if (!wcfg.isLogging(Logging.MISCEXPLOSION)) return; - name = "Explosion"; - } else if (event.getEntity() instanceof TNTPrimed) { + } else if (source instanceof TNTPrimed) { if (!wcfg.isLogging(Logging.TNTEXPLOSION)) return; name = "TNT"; - } else if (event.getEntity() instanceof Creeper) { + } else if (source instanceof ExplosiveMinecart) { + if (!wcfg.isLogging(Logging.TNTMINECARTEXPLOSION)) + return; + name = "TNTMinecart"; + } else if (source instanceof Creeper) { if (!wcfg.isLogging(Logging.CREEPEREXPLOSION)) return; if (logCreeperExplosionsAsPlayerWhoTriggeredThese) { - final Entity target = ((Creeper)event.getEntity()).getTarget(); + final Entity target = ((Creeper) source).getTarget(); name = target instanceof Player ? ((Player)target).getName() : "Creeper"; } else name = "Creeper"; - } else if (event.getEntity() instanceof Fireball) { - Fireball fireball = (Fireball) event.getEntity(); + } else if (source instanceof Fireball) { + Fireball fireball = (Fireball) source; Entity shooter = fireball.getShooter(); if (shooter == null) { return; @@ -65,22 +70,21 @@ public class ExplosionLogging extends LoggingListener } name = "Wither"; } - } else if (event.getEntity() instanceof EnderDragon) { + } else if (source instanceof EnderDragon) { if (!wcfg.isLogging(Logging.ENDERDRAGON)) return; name = "EnderDragon"; - } else if (event.getEntity() instanceof Wither) { + } else if (source instanceof Wither) { if(!wcfg.isLogging(Logging.WITHER)) return; name = "Wither"; - } else if (event.getEntity() instanceof WitherSkull) { + } else if (source instanceof WitherSkull) { if(!wcfg.isLogging(Logging.WITHER_SKULL)) return; name = "WitherSkull"; } else { if (!wcfg.isLogging(Logging.MISCEXPLOSION)) return; - name = "Explosion"; } for (final Block block : event.blockList()) { final int type = block.getTypeId();