diff --git a/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/game/games/turfforts/TurfForts.java b/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/game/games/turfforts/TurfForts.java index 16df44336..3da737a34 100644 --- a/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/game/games/turfforts/TurfForts.java +++ b/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/game/games/turfforts/TurfForts.java @@ -3,6 +3,10 @@ package nautilus.game.arcade.game.games.turfforts; import java.lang.reflect.Field; import java.util.ArrayList; import java.util.HashMap; +import java.util.HashSet; +import java.util.List; +import java.util.Set; +import java.util.UUID; import org.bukkit.Bukkit; import org.bukkit.ChatColor; @@ -16,15 +20,19 @@ import org.bukkit.craftbukkit.v1_7_R4.entity.CraftArrow; import org.bukkit.craftbukkit.v1_7_R4.entity.CraftPlayer; import org.bukkit.entity.Arrow; import org.bukkit.entity.Entity; +import org.bukkit.entity.EntityType; import org.bukkit.entity.Player; import org.bukkit.event.EventHandler; import org.bukkit.event.HandlerList; +import org.bukkit.event.block.BlockBreakEvent; import org.bukkit.event.block.BlockEvent; import org.bukkit.event.block.BlockPlaceEvent; import org.bukkit.event.entity.EntityDamageEvent.DamageCause; import org.bukkit.event.entity.EntityShootBowEvent; +import org.bukkit.event.entity.ItemSpawnEvent; import org.bukkit.event.entity.PlayerDeathEvent; import org.bukkit.event.entity.ProjectileHitEvent; +import org.bukkit.event.player.PlayerQuitEvent; import net.minecraft.server.v1_7_R4.EntityArrow; import net.minecraft.server.v1_7_R4.Item; @@ -45,6 +53,8 @@ import mineplex.minecraft.game.core.combat.event.CombatDeathEvent; import mineplex.minecraft.game.core.damage.CustomDamageEvent; import nautilus.game.arcade.ArcadeManager; import nautilus.game.arcade.GameType; +import nautilus.game.arcade.events.PlayerGameRespawnEvent; +import nautilus.game.arcade.events.PlayerKitGiveEvent; import nautilus.game.arcade.game.GameTeam; import nautilus.game.arcade.game.TeamGame; import nautilus.game.arcade.game.games.turfforts.kits.KitInfiltrator; @@ -103,9 +113,11 @@ public class TurfForts extends TeamGame private long _fightTime = 90000; private boolean _fight = false; private int _lines = 0; - + private HashMap _enemyTurf = new HashMap(); - + + private Set playersThatNeedBlocks = new HashSet(); + public TurfForts(ArcadeManager manager) { super(manager, GameType.TurfWars, @@ -266,7 +278,7 @@ public class TurfForts extends TeamGame EndCheck(); } } - + @EventHandler public void BowCancel(EntityShootBowEvent event) { @@ -284,7 +296,9 @@ public class TurfForts extends TeamGame { if (event.isCancelled()) // this statement might save just a small amount of time return; - + + + if (!IsAlive(event.getPlayer())) { event.setCancelled(true); @@ -296,6 +310,18 @@ public class TurfForts extends TeamGame event.setCancelled(true); return; } + + Block block = event.getBlock(); + + GameTeam team = GetTeam(event.getPlayer()); + GameTeam otherTeam = GetOtherTeam(team); + + if (block.getType().equals(Material.WOOL) && (block.getData() == 14 && team.GetColor() != ChatColor.RED) || (block.getData() == 3 && team.GetColor() != ChatColor.AQUA)) + { + UtilPlayer.message(event.getPlayer(), F.main("Game", "You cannot break the " + F.elem(otherTeam.GetColor() + otherTeam.GetName()) + " team's blocks!")); + event.setCancelled(true); + return; + } } @EventHandler(ignoreCancelled = true) @@ -525,13 +551,44 @@ public class TurfForts extends TeamGame { for (Player player : team.GetPlayers(true)) { - player.getInventory().addItem(ItemStackFactory.Instance.CreateStack(Material.WOOL, team.GetColorData(), 24)); + if (UtilPlayer.isSpectator(player)) + { + this.playersThatNeedBlocks.add(player.getUniqueId()); + } + else + { + addBlocks(team, player); + } } } } } } - + + public void addBlocks(GameTeam team, Player player) + { + player.getInventory().addItem(ItemStackFactory.Instance.CreateStack(Material.WOOL, team.GetColorData(), 24)); + } + + @EventHandler(ignoreCancelled = true) + public void onQuit(PlayerQuitEvent event) + { + this.playersThatNeedBlocks.remove(event.getPlayer().getUniqueId()); + } + + @EventHandler(ignoreCancelled = true) + public void onSpawn(PlayerKitGiveEvent event) + { + Player player = event.GetPlayer(); + if (this.playersThatNeedBlocks.contains(player.getUniqueId())) + { + this.playersThatNeedBlocks.remove(player.getUniqueId()); + this.addBlocks(GetTeam(player), player); + } + } + + + @Override @EventHandler public void ScoreboardUpdate(UpdateEvent event) @@ -707,23 +764,6 @@ public class TurfForts extends TeamGame } */ - //Added by TheMineBench. - @EventHandler - public void blockBreak(BlockBreakEvent event) { - - Block block = event.getBlock(); - - GameTeam team = GetTeam(event.getPlayer()); - GameTeam otherTeam = GetOtherTeam(team); - - if (block.getType().equals(Material.WOOL) && (block.getData() == 14 && team.GetColor() != ChatColor.RED) || (block.getData() == 3 && team.GetColor() != ChatColor.AQUA)) - { - UtilPlayer.message(event.getPlayer(), F.main("Game", "You cannot break the " + F.elem(otherTeam.GetColor() + otherTeam.GetName()) + " team's blocks!")); - event.setCancelled(true); - return; - } - - } public GameTeam GetOtherTeam(GameTeam team) { return team.GetColor() == ChatColor.RED ? GetTeam(ChatColor.AQUA) : GetTeam(ChatColor.RED);