When items are dropped in The Bridges, only the player that broke the block can pickup the item for 8 seconds. (Only applies to specific item types)
This commit is contained in:
parent
5905ef5ef7
commit
df882012e5
@ -4,6 +4,7 @@ import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.HashSet;
|
||||
import java.util.Iterator;
|
||||
import java.util.UUID;
|
||||
|
||||
import org.bukkit.ChatColor;
|
||||
import org.bukkit.Location;
|
||||
@ -16,6 +17,7 @@ import org.bukkit.entity.Chicken;
|
||||
import org.bukkit.entity.Cow;
|
||||
import org.bukkit.entity.Entity;
|
||||
import org.bukkit.entity.FallingBlock;
|
||||
import org.bukkit.entity.Item;
|
||||
import org.bukkit.entity.Pig;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.event.EventHandler;
|
||||
@ -29,12 +31,12 @@ import org.bukkit.event.entity.ItemSpawnEvent;
|
||||
import org.bukkit.event.inventory.PrepareItemCraftEvent;
|
||||
import org.bukkit.event.player.PlayerBucketEmptyEvent;
|
||||
import org.bukkit.event.player.PlayerInteractEvent;
|
||||
import org.bukkit.event.player.PlayerPickupItemEvent;
|
||||
import org.bukkit.inventory.CraftingInventory;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
import org.bukkit.scoreboard.Score;
|
||||
import org.bukkit.metadata.FixedMetadataValue;
|
||||
import org.bukkit.util.Vector;
|
||||
|
||||
import mineplex.core.common.Rank;
|
||||
import mineplex.core.common.util.C;
|
||||
import mineplex.core.common.util.F;
|
||||
import mineplex.core.common.util.UtilBlock;
|
||||
@ -57,7 +59,6 @@ import nautilus.game.arcade.events.PlayerDeathOutEvent;
|
||||
import nautilus.game.arcade.game.Game;
|
||||
import nautilus.game.arcade.game.GameTeam;
|
||||
import nautilus.game.arcade.game.TeamGame;
|
||||
import nautilus.game.arcade.game.Game.GameState;
|
||||
import nautilus.game.arcade.game.games.bridge.kits.*;
|
||||
import nautilus.game.arcade.kit.Kit;
|
||||
import nautilus.game.arcade.ore.OreHider;
|
||||
@ -70,6 +71,11 @@ import nautilus.game.arcade.stats.TntMinerStatTracker;
|
||||
|
||||
public class Bridge extends TeamGame implements OreObsfucation
|
||||
{
|
||||
/**
|
||||
* When a block is broken of one of these materials, the item drop will be locked to the player that broke the block for 8 seconds. After that, anyone can pick up the item.
|
||||
*/
|
||||
private static final Material[] PLAYER_DROP_DELAY_MATERIALS = new Material[] { Material.LOG, Material.LOG_2, Material.IRON_ORE, Material.DIAMOND_ORE, Material.COAL_ORE, Material.GOLD_ORE, Material.WORKBENCH, Material.FURNACE };
|
||||
|
||||
//Bridge Timer
|
||||
private int _bridgeTime = 600000;
|
||||
private boolean _bridgesDown = false;
|
||||
@ -98,7 +104,6 @@ public class Bridge extends TeamGame implements OreObsfucation
|
||||
private OreHider _ore;
|
||||
private double _oreDensity = 2.2;
|
||||
|
||||
|
||||
//Map Flags
|
||||
private int _buildHeight = -1;
|
||||
private int _iceForm = -1;
|
||||
@ -111,6 +116,9 @@ public class Bridge extends TeamGame implements OreObsfucation
|
||||
private HashMap<GameTeam, Integer> _tournamentKills = new HashMap<GameTeam, Integer>();
|
||||
private long _tournamentKillMessageTimer = 0;
|
||||
|
||||
//Item pickup delay for players that don't break the block
|
||||
private HashMap<Block, UUID> _blockToUUIDMap = new HashMap<Block, UUID>();
|
||||
|
||||
|
||||
public Bridge(ArcadeManager manager)
|
||||
{
|
||||
@ -1009,6 +1017,61 @@ public class Bridge extends TeamGame implements OreObsfucation
|
||||
}
|
||||
}
|
||||
|
||||
private void addBlockPickupDelay(Player owner, Block block)
|
||||
{
|
||||
Material blockMaterial = block.getType();
|
||||
boolean shouldAddToMap = false;
|
||||
|
||||
for (int i = 0; i < PLAYER_DROP_DELAY_MATERIALS.length && !shouldAddToMap; i++)
|
||||
{
|
||||
if (blockMaterial.equals(PLAYER_DROP_DELAY_MATERIALS[i]))
|
||||
{
|
||||
shouldAddToMap = true;
|
||||
}
|
||||
}
|
||||
|
||||
if (shouldAddToMap)
|
||||
_blockToUUIDMap.put(block, owner.getUniqueId());
|
||||
}
|
||||
|
||||
@EventHandler(priority = EventPriority.MONITOR, ignoreCancelled = true)
|
||||
public void dropItem(BlockBreakEvent event)
|
||||
{
|
||||
addBlockPickupDelay(event.getPlayer(), event.getBlock());
|
||||
}
|
||||
|
||||
@EventHandler
|
||||
public void itemSpawn(ItemSpawnEvent event)
|
||||
{
|
||||
Item item = event.getEntity();
|
||||
Block block = event.getLocation().getBlock();
|
||||
|
||||
UUID uuid = _blockToUUIDMap.remove(block);
|
||||
|
||||
if (uuid != null)
|
||||
{
|
||||
item.setMetadata("owner", new FixedMetadataValue(Manager.GetPlugin(), uuid));
|
||||
}
|
||||
}
|
||||
|
||||
@EventHandler
|
||||
public void itemPickup(PlayerPickupItemEvent event)
|
||||
{
|
||||
Item item = event.getItem();
|
||||
|
||||
if (item.hasMetadata("owner"))
|
||||
{
|
||||
FixedMetadataValue ownerData = (FixedMetadataValue) item.getMetadata("owner").get(0);
|
||||
UUID ownerUUID = (UUID) ownerData.value();
|
||||
|
||||
// 8 Seconds
|
||||
if (item.getTicksLived() <= 160 && !event.getPlayer().getUniqueId().equals(ownerUUID))
|
||||
{
|
||||
event.setCancelled(true);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@EventHandler(priority = EventPriority.LOW)
|
||||
public void ChestProtect(EntityExplodeEvent event)
|
||||
{
|
||||
|
Loading…
Reference in New Issue
Block a user