diff --git a/war/src/main/java/bukkit/tommytony/war/WarPlayerListener.java b/war/src/main/java/bukkit/tommytony/war/WarPlayerListener.java index ee6191f..b76c544 100644 --- a/war/src/main/java/bukkit/tommytony/war/WarPlayerListener.java +++ b/war/src/main/java/bukkit/tommytony/war/WarPlayerListener.java @@ -335,6 +335,7 @@ public class WarPlayerListener extends PlayerListener { for (Team t : zone.getTeams()) { t.teamcast("" + player.getName() + " joined team " + team.getName() + "."); } + zone.resetInventory(team, player); } else { event.setTo(zone.getTeleport()); War.war.badMsg(player, "Team " + team.getName() + " is full."); @@ -429,10 +430,17 @@ public class WarPlayerListener extends PlayerListener { } } - if (!playerWarzone.isEnoughPlayers() && !playerTeam.getSpawnVolume().contains(playerLoc)) { - War.war.badMsg(player, "Can't leave spawn until there's a minimum of " + playerWarzone.getMinPlayers() +" player(s) on at least " + playerWarzone.getMinTeams() + " team(s)."); - event.setTo(playerTeam.getTeamSpawn()); - return; + if (!playerTeam.getSpawnVolume().contains(playerLoc)) { + if (!playerWarzone.isEnoughPlayers()) { + War.war.badMsg(player, "Can't leave spawn until there's a minimum of " + playerWarzone.getMinPlayers() +" player(s) on at least " + playerWarzone.getMinTeams() + " team(s)."); + event.setTo(playerTeam.getTeamSpawn()); + return; + } + if (playerWarzone.isRespawning(player)) { + War.war.badMsg(player, "Can't leave spawn for 10 seconds after spawning!"); + event.setTo(playerTeam.getTeamSpawn()); + return; + } } // Monuments @@ -539,7 +547,7 @@ public class WarPlayerListener extends PlayerListener { playerWarzone.getNewlyRespawned().put(event.getPlayer().getName(), currentIndex); if (currentIndex == 0) { - playerWarzone.resetInventory(playerTeam, event.getPlayer(), playerWarzone.getLoadout()); + if (!playerWarzone.isRespawning(event.getPlayer())) playerWarzone.resetInventory(playerTeam, event.getPlayer(), playerWarzone.getLoadout()); War.war.msg(event.getPlayer(), "Equipped default loadout."); } else { int i = 0; @@ -547,7 +555,7 @@ public class WarPlayerListener extends PlayerListener { while (it.hasNext()) { Map.Entry pairs = (Map.Entry)it.next(); if (i == currentIndex - 1) { - playerWarzone.resetInventory(playerTeam, event.getPlayer(), (HashMap)pairs.getValue()); + if (!playerWarzone.isRespawning(event.getPlayer())) playerWarzone.resetInventory(playerTeam, event.getPlayer(), (HashMap)pairs.getValue()); War.war.msg(event.getPlayer(), "Equipped " + pairs.getKey() + " loadout."); } i++; @@ -556,7 +564,6 @@ public class WarPlayerListener extends PlayerListener { } else { War.war.badMsg(event.getPlayer(), "Can't change loadout after exiting the spawn."); } - } } } diff --git a/war/src/main/java/com/tommytony/war/Warzone.java b/war/src/main/java/com/tommytony/war/Warzone.java index f2a4e93..16a2a88 100755 --- a/war/src/main/java/com/tommytony/war/Warzone.java +++ b/war/src/main/java/com/tommytony/war/Warzone.java @@ -21,6 +21,7 @@ import org.bukkit.inventory.ItemStack; import org.bukkit.inventory.PlayerInventory; import bukkit.tommytony.war.War; +import com.tommytony.war.jobs.HelmetProtectionTask; import com.tommytony.war.jobs.InitZoneJob; import com.tommytony.war.jobs.LoadoutResetJob; import com.tommytony.war.jobs.ScoreCapReachedJob; @@ -39,6 +40,7 @@ public class Warzone { private final List monuments = new ArrayList(); private final List authors = new ArrayList(); + private final List respawn = new ArrayList(); private Location teleport; private boolean friendlyFire = false; @@ -326,23 +328,41 @@ public class Warzone { // Teleport the player back to spawn event.setTo(team.getTeamSpawn()); } + + public boolean isRespawning(Player p) { + return respawn.contains(p); + } - private void handleRespawn(Team team, Player player) { + private void handleRespawn(final Team team, final Player player) { // Fill hp player.setRemainingAir(300); player.setHealth(20); player.setFoodLevel(20); player.setSaturation(this.getSaturation()); player.setExhaustion(0); + player.setFireTicks(0); + + player.getInventory().clear(); + if (player.getGameMode() == GameMode.CREATIVE) { player.setGameMode(GameMode.SURVIVAL); } if (!this.getNewlyRespawned().keySet().contains(player.getName())) { this.getNewlyRespawned().put(player.getName(), 0); } - - LoadoutResetJob job = new LoadoutResetJob(this, team, player); - War.war.getServer().getScheduler().scheduleSyncDelayedTask(War.war, job); + + // "Respawn" Timer - player will not be able to leave spawn for 10 seconds + // TODO: Customizable "respawn" time + respawn.add(player); + final Warzone w = this; + War.war.getServer().getScheduler().scheduleSyncDelayedTask(War.war, new Runnable() { + public void run() { + respawn.remove(player); + // Getting the Loadout as visual cue + LoadoutResetJob job = new LoadoutResetJob(w, team, player, newlyRespawned.get(player.getName())); + War.war.getServer().getScheduler().scheduleSyncDelayedTask(War.war, job); + } + }, 10 * 20L); // 20 ticks = 1 second. So 10*20 ticks = 10 seconds. } public void resetInventory(Team team, Player player) { @@ -759,6 +779,7 @@ public class Warzone { for (Team team : this.teams) { team.teamcast("" + player.getName() + " joined team " + lowestNoOfPlayers.getName() + "."); } + resetInventory(lowestNoOfPlayers, player); } return lowestNoOfPlayers; } diff --git a/war/src/main/java/com/tommytony/war/jobs/HelmetProtectionTask.java b/war/src/main/java/com/tommytony/war/jobs/HelmetProtectionTask.java index 17db625..980c0e9 100644 --- a/war/src/main/java/com/tommytony/war/jobs/HelmetProtectionTask.java +++ b/war/src/main/java/com/tommytony/war/jobs/HelmetProtectionTask.java @@ -80,7 +80,7 @@ public class HelmetProtectionTask implements Runnable { } } - private ItemStack createBlockHead(Team team) { + public ItemStack createBlockHead(Team team) { return new ItemStack(team.getKind().getMaterial(), 1, (short) 1, new Byte(team.getKind().getData())); } } diff --git a/war/src/main/java/com/tommytony/war/jobs/LoadoutResetJob.java b/war/src/main/java/com/tommytony/war/jobs/LoadoutResetJob.java index 8fca549..3224184 100644 --- a/war/src/main/java/com/tommytony/war/jobs/LoadoutResetJob.java +++ b/war/src/main/java/com/tommytony/war/jobs/LoadoutResetJob.java @@ -1,6 +1,13 @@ package com.tommytony.war.jobs; +import java.util.HashMap; +import java.util.Iterator; +import java.util.Map; + import org.bukkit.entity.Player; +import org.bukkit.inventory.ItemStack; + +import bukkit.tommytony.war.War; import com.tommytony.war.Team; import com.tommytony.war.Warzone; @@ -10,15 +17,34 @@ public class LoadoutResetJob implements Runnable { private final Player player; private final Warzone zone; private final Team team; + private int loadout = 0; public LoadoutResetJob(Warzone zone, Team team, Player player) { this.zone = zone; this.team = team; this.player = player; } + + public LoadoutResetJob(Warzone zone, Team team, Player player, int loadout) { + this.zone = zone; + this.team = team; + this.player = player; + this.loadout = loadout; + } public void run() { - this.zone.resetInventory(this.team, this.player); + if (loadout==0) this.zone.resetInventory(this.team, this.player); + else { + int i = 0; + Iterator it = this.zone.getExtraLoadouts().entrySet().iterator(); + while (it.hasNext()) { + Map.Entry pairs = (Map.Entry)it.next(); + if (i == loadout - 1) { + this.zone.resetInventory(this.team, this.player, (HashMap)pairs.getValue()); + } + i++; + } + } // Stop fire here, since doing it in the same tick as death doesn't extinguish it this.player.setFireTicks(0); }