From f071d2e7275f5fe6b525824e50bf916bfeea44fc Mon Sep 17 00:00:00 2001 From: Shaun Bennett Date: Mon, 17 Nov 2014 18:09:58 -0600 Subject: [PATCH] Fix for TNT explosion in Bridges --- .../mineplex/core/common/util/UtilPlayer.java | 7 +++++++ .../mineplex/core/explosion/Explosion.java | 18 ++++++++++++++++- .../core/explosion/ExplosionEvent.java | 18 +++++++++++++++++ .../game/arcade/game/games/bridge/Bridge.java | 20 ++++++++++++++++++- .../game/arcade/kit/perks/PerkBomber.java | 3 +++ 5 files changed, 64 insertions(+), 2 deletions(-) diff --git a/Plugins/Mineplex.Core.Common/src/mineplex/core/common/util/UtilPlayer.java b/Plugins/Mineplex.Core.Common/src/mineplex/core/common/util/UtilPlayer.java index ccf503360..fd8ff6eb3 100644 --- a/Plugins/Mineplex.Core.Common/src/mineplex/core/common/util/UtilPlayer.java +++ b/Plugins/Mineplex.Core.Common/src/mineplex/core/common/util/UtilPlayer.java @@ -4,7 +4,9 @@ import java.util.Collection; import java.util.HashMap; import java.util.LinkedList; import java.util.List; +import java.util.UUID; +import org.bukkit.Bukkit; import org.bukkit.ChatColor; import org.bukkit.GameMode; import org.bukkit.Location; @@ -59,6 +61,11 @@ public class UtilPlayer return null; } + public static Player searchExact(UUID uuid) + { + return UtilServer.getServer().getPlayer(uuid); + } + public static String searchCollection(Player caller, String player, Collection coll, String collName, boolean inform) { LinkedList matchList = new LinkedList(); diff --git a/Plugins/Mineplex.Core/src/mineplex/core/explosion/Explosion.java b/Plugins/Mineplex.Core/src/mineplex/core/explosion/Explosion.java index 369c7c61c..87e12f7fe 100644 --- a/Plugins/Mineplex.Core/src/mineplex/core/explosion/Explosion.java +++ b/Plugins/Mineplex.Core/src/mineplex/core/explosion/Explosion.java @@ -6,8 +6,10 @@ import java.util.HashMap; import java.util.HashSet; import java.util.Iterator; import java.util.Map.Entry; +import java.util.UUID; import mineplex.core.MiniPlugin; +import mineplex.core.common.util.UtilPlayer; import mineplex.core.updater.event.UpdateEvent; import mineplex.core.updater.UpdateType; import mineplex.core.blockrestore.BlockRestore; @@ -23,12 +25,15 @@ import org.bukkit.block.Block; import org.bukkit.entity.Entity; import org.bukkit.entity.EntityType; import org.bukkit.entity.FallingBlock; +import org.bukkit.entity.Item; +import org.bukkit.entity.Player; import org.bukkit.entity.TNTPrimed; import org.bukkit.event.EventHandler; import org.bukkit.event.EventPriority; import org.bukkit.event.entity.EntityExplodeEvent; import org.bukkit.event.entity.ExplosionPrimeEvent; import org.bukkit.event.entity.ItemSpawnEvent; +import org.bukkit.metadata.FixedMetadataValue; import org.bukkit.plugin.java.JavaPlugin; import org.bukkit.util.Vector; @@ -84,8 +89,19 @@ public class Explosion extends MiniPlugin if (event.blockList().isEmpty()) return; + // This metadata is used to identify the owner of the explosion for use in other plugins + Player owner = null; + Entity entity = event.getEntity(); + if (entity.hasMetadata("owner")) + { + FixedMetadataValue ownerData = (FixedMetadataValue) entity.getMetadata("owner").get(0); + UUID ownerUUID = (UUID) ownerData.value(); + + owner = UtilPlayer.searchExact(ownerUUID); + } + //Event for Block awareness - ExplosionEvent explodeEvent = new ExplosionEvent(event.blockList()); + ExplosionEvent explodeEvent = new ExplosionEvent(event.blockList(), owner); _plugin.getServer().getPluginManager().callEvent(explodeEvent); event.setYield(0f); diff --git a/Plugins/Mineplex.Core/src/mineplex/core/explosion/ExplosionEvent.java b/Plugins/Mineplex.Core/src/mineplex/core/explosion/ExplosionEvent.java index fcab9124f..0ef1fdb01 100644 --- a/Plugins/Mineplex.Core/src/mineplex/core/explosion/ExplosionEvent.java +++ b/Plugins/Mineplex.Core/src/mineplex/core/explosion/ExplosionEvent.java @@ -3,6 +3,7 @@ package mineplex.core.explosion; import java.util.Collection; import org.bukkit.block.Block; +import org.bukkit.entity.Player; import org.bukkit.event.Event; import org.bukkit.event.HandlerList; @@ -10,11 +11,18 @@ public class ExplosionEvent extends Event { private static final HandlerList handlers = new HandlerList(); + private Player _owner; private Collection _blocks; public ExplosionEvent(Collection blocks) + { + this(blocks, null); + } + + public ExplosionEvent(Collection blocks, Player owner) { _blocks = blocks; + _owner = owner; } public HandlerList getHandlers() @@ -31,4 +39,14 @@ public class ExplosionEvent extends Event { return _blocks; } + + public Player getOwner() + { + return _owner; + } + + public void setOwner(Player owner) + { + _owner = owner; + } } diff --git a/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/game/games/bridge/Bridge.java b/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/game/games/bridge/Bridge.java index bba5f08b7..b2b351af2 100644 --- a/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/game/games/bridge/Bridge.java +++ b/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/game/games/bridge/Bridge.java @@ -962,9 +962,27 @@ public class Bridge extends TeamGame implements OreObsfucation } @EventHandler - public void OreReveal(ExplosionEvent event) + public void handleExplosion(ExplosionEvent event) { + // Reveal ore that are inside the explosion _ore.Explosion(event); + + // Handle block ownership for explosion + if (event.getOwner() != null) + { + for (Block cur : event.GetBlocks()) + { + // These are the only blocks that will drop from the explosion so they are the only ones + // we need to worry about for keeping owner data of + if (cur.getType() == Material.IRON_ORE || + cur.getType() == Material.COAL_ORE || + cur.getType() == Material.GOLD_ORE || + cur.getType() == Material.DIAMOND_ORE) + { + _blockToUUIDMap.put(cur, event.getOwner().getUniqueId()); + } + } + } } @EventHandler(priority = EventPriority.MONITOR) diff --git a/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/kit/perks/PerkBomber.java b/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/kit/perks/PerkBomber.java index 5f5cd35e2..2c47bfd0c 100644 --- a/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/kit/perks/PerkBomber.java +++ b/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/kit/perks/PerkBomber.java @@ -14,6 +14,7 @@ import org.bukkit.event.block.*; import org.bukkit.event.entity.*; import org.bukkit.event.inventory.*; import org.bukkit.event.player.*; +import org.bukkit.metadata.FixedMetadataValue; import java.util.*; @@ -169,6 +170,8 @@ public class PerkBomber extends Perk UtilAction.velocity(tnt, player.getLocation().getDirection(), 0.5, false, 0, 0.1, 10, false); + tnt.setMetadata("owner", new FixedMetadataValue(Manager.GetPlugin(), player.getUniqueId())); + _tntMap.put(tnt, player); }