mirror of
https://github.com/taoneill/war.git
synced 2024-11-23 18:55:28 +01:00
Close gh-282. Players cannot leave spawn for 10 seconds after respawning.
- [gh-282] Added a "Respawn" timer, players cannot leave spawn while it is active. Loadout will be given to the player at the end of the timer as a visual cue. - TODO: configurable timer, cannot attack/be attacked while respawning
This commit is contained in:
parent
ff04f24a85
commit
856da8cc77
@ -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<Integer, ItemStack>)pairs.getValue());
|
||||
if (!playerWarzone.isRespawning(event.getPlayer())) playerWarzone.resetInventory(playerTeam, event.getPlayer(), (HashMap<Integer, ItemStack>)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.");
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -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<Monument> monuments = new ArrayList<Monument>();
|
||||
|
||||
private final List<String> authors = new ArrayList<String>();
|
||||
private final List<Player> respawn = new ArrayList<Player>();
|
||||
|
||||
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;
|
||||
}
|
||||
|
@ -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()));
|
||||
}
|
||||
}
|
||||
|
@ -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<Integer, ItemStack>)pairs.getValue());
|
||||
}
|
||||
i++;
|
||||
}
|
||||
}
|
||||
// Stop fire here, since doing it in the same tick as death doesn't extinguish it
|
||||
this.player.setFireTicks(0);
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user