Fix for TNT explosion in Bridges
This commit is contained in:
parent
057594205e
commit
f071d2e727
@ -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<String> coll, String collName, boolean inform)
|
||||
{
|
||||
LinkedList<String> matchList = new LinkedList<String>();
|
||||
|
@ -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);
|
||||
|
@ -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<Block> _blocks;
|
||||
|
||||
public ExplosionEvent(Collection<Block> blocks)
|
||||
{
|
||||
this(blocks, null);
|
||||
}
|
||||
|
||||
public ExplosionEvent(Collection<Block> 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;
|
||||
}
|
||||
}
|
||||
|
@ -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)
|
||||
|
@ -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);
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user