From 3af3c969fd9a7b6d0af4fbd07df6dd00d1bab613 Mon Sep 17 00:00:00 2001 From: riking Date: Mon, 17 Nov 2014 19:09:55 -0800 Subject: [PATCH] Activate TNT tracking on non-SportBukkit servers --- .../autoreferee/listeners/CombatListener.java | 29 +++++++++++++++---- 1 file changed, 24 insertions(+), 5 deletions(-) diff --git a/src/main/java/org/mctourney/autoreferee/listeners/CombatListener.java b/src/main/java/org/mctourney/autoreferee/listeners/CombatListener.java index 06681439..0974c6d6 100644 --- a/src/main/java/org/mctourney/autoreferee/listeners/CombatListener.java +++ b/src/main/java/org/mctourney/autoreferee/listeners/CombatListener.java @@ -11,6 +11,7 @@ import org.bukkit.entity.LivingEntity; import org.bukkit.entity.Player; import org.bukkit.entity.Projectile; +import org.bukkit.entity.TNTPrimed; import org.bukkit.event.EventHandler; import org.bukkit.event.EventPriority; import org.bukkit.event.Listener; @@ -34,7 +35,7 @@ import org.mctourney.autoreferee.AutoReferee; import org.mctourney.autoreferee.regions.AutoRefRegion.Flag; import org.mctourney.autoreferee.util.AchievementPoints; -import org.mctourney.autoreferee.util.SportBukkitUtil; +//import org.mctourney.autoreferee.util.SportBukkitUtil; import com.google.common.collect.Maps; @@ -344,16 +345,34 @@ public void hungerChange(FoodLevelChangeEvent event) public void explosionPrime(ExplosionPrimeEvent event) { AutoRefMatch match = plugin.getMatch(event.getEntity().getWorld()); - if (!SportBukkitUtil.hasSportBukkitApi() || match == null) return; + // if (!SportBukkitUtil.hasSportBukkitApi() || match == null) return; if (event.getEntityType() == EntityType.PRIMED_TNT) { - Location tntLocation = event.getEntity().getLocation().getBlock().getLocation(); - AutoRefPlayer apl = tntPropagation.remove(tntLocation); + TNTPrimed entity = (TNTPrimed) event.getEntity(); + AutoRefPlayer apl; + + Location tntLocation = entity.getLocation().getBlock().getLocation(); + apl = tntPropagation.remove(tntLocation); // if there was no propagation chain if (apl == null) { + // Try the new API + try + { + Entity tntSource = entity.getSource(); + if (tntSource instanceof Player) + apl = match.getPlayer((Player) tntSource); + } + catch (Throwable ignored) + {} + } + + // Try position-based inference + if (apl == null) + { + // try to determine if this was the first tnt in a chain if ((apl = match.getNearestPlayer(tntLocation)) == null) return; @@ -362,7 +381,7 @@ public void explosionPrime(ExplosionPrimeEvent event) } // add an owner for this tnt object - if (apl != null) plugin.setTNTOwner(event.getEntity(), apl); + if (apl != null) plugin.setTNTOwner(entity, apl); } }