Massaging the death handling into maybe creating less chunk errors and bugs. Zone makers now shouldnt be able to mess with important blocks.

This commit is contained in:
taoneill 2011-01-29 19:00:19 -05:00
parent ce625ee4b1
commit eaf713fb1e
7 changed files with 59 additions and 44 deletions

View File

@ -307,6 +307,7 @@ public class War extends JavaPlugin {
player.sendMessage(this.str("Usage: /nextbattle. Resets the zone blocks and all teams' life pools. Must be in warzone."));
} else {
Warzone warzone = this.warzone(player.getLocation());
warzone.clearFlagThieves();
for(Team team: warzone.getTeams()) {
team.teamcast(this.str("The battle was interrupted. " + playerListener.getAllTeamsMsg(player) + " Resetting warzone " + warzone.getName() + " and life pools..."));
}
@ -565,6 +566,7 @@ public class War extends JavaPlugin {
lobby = warzone.getLobby();
}
int resetBlocks = 0;
warzone.clearFlagThieves();
for(Team team: warzone.getTeams()) {
team.teamcast(this.str("The war has ended. " + playerListener.getAllTeamsMsg(player) + " Resetting warzone " + warzone.getName() + " and teams..."));
for(Player p : team.getPlayers()) {
@ -656,7 +658,7 @@ public class War extends JavaPlugin {
} else {
// new team
Team newTeam = new Team(name, teamMaterial, player.getLocation(), this, warzone);
newTeam.setRemainingTickets(warzone.getLifePool());
newTeam.setRemainingLives(warzone.getLifePool());
warzone.getTeams().add(newTeam);
if(warzone.getLobby() != null) {
warzone.getLobby().getVolume().resetBlocks();
@ -693,7 +695,7 @@ public class War extends JavaPlugin {
team.setTeamFlag(player.getLocation());
Location playerLoc = player.getLocation();
player.teleportTo(new Location(playerLoc.getWorld(),
playerLoc.getBlockX(), playerLoc.getBlockY() + 1, playerLoc.getBlockZ()));
playerLoc.getBlockX()+1, playerLoc.getBlockY(), playerLoc.getBlockZ()));
player.sendMessage(this.str("Team " + name + " flag added here."));
} else {
// relocate flag
@ -701,7 +703,7 @@ public class War extends JavaPlugin {
team.setTeamFlag(player.getLocation());
Location playerLoc = player.getLocation();
player.teleportTo(new Location(playerLoc.getWorld(),
playerLoc.getBlockX(), playerLoc.getBlockY() + 1, playerLoc.getBlockZ()));
playerLoc.getBlockX()+1, playerLoc.getBlockY() + 1, playerLoc.getBlockZ()));
player.sendMessage(this.str("Team " + name + " flag moved."));
}

View File

@ -13,7 +13,6 @@ import org.bukkit.inventory.ItemStack;
import com.tommytony.war.Monument;
import com.tommytony.war.Team;
import com.tommytony.war.TeamMaterials;
import com.tommytony.war.Warzone;
/**
@ -56,7 +55,7 @@ public class WarBlockListener extends BlockListener {
}
}
if(zone != null && zone.isImportantBlock(block) && !isZoneMaker){
if(zone != null && zone.isImportantBlock(block)){
player.sendMessage(war.str("Can't build here."));
event.setCancelled(true);
return;
@ -64,7 +63,7 @@ public class WarBlockListener extends BlockListener {
// protect warzone lobbies
if(block != null) {
for(Warzone wz: war.getWarzones()) {
if(wz.getLobby() != null && wz.getLobby().getVolume().contains(block) && !isZoneMaker) {
if(wz.getLobby() != null && wz.getLobby().getVolume().contains(block)) {
player.sendMessage(war.str("Can't build here."));
event.setCancelled(true);
return;
@ -105,7 +104,7 @@ public class WarBlockListener extends BlockListener {
monument.uncapture();
}
return;
}else if(warzone != null && warzone.isImportantBlock(block) && !isZoneMaker) {
}else if(warzone != null && warzone.isImportantBlock(block)) {
if(team != null && team.getSpawnVolume().contains(block)) {
if(player.getInventory().contains(team.getMaterial())) {
player.sendMessage(war.str("You already have a " + team.getName() + " block."));
@ -128,10 +127,10 @@ public class WarBlockListener extends BlockListener {
for(Team t : warzone.getTeams()) {
t.teamcast(war.str(player.getName() + " stole team " + lostFlagTeam.getName() + "'s flag."));
if(t.getName().equals(lostFlagTeam.getName())){
t.teamcast(war.str("Prevent " + player.getName() + " from reaching team " + team.getName() + "'s spawn."));
t.teamcast(war.str("Prevent " + player.getName() + " from reaching team " + team.getName() + "'s spawn or flag."));
}
}
player.sendMessage(war.str("You have team " + lostFlagTeam.getName() + "'s flag. Reach your team spawn to capture it!"));
player.sendMessage(war.str("You have team " + lostFlagTeam.getName() + "'s flag. Reach your team spawn or flag to capture it!"));
}
event.setCancelled(true);
return;

View File

@ -241,7 +241,8 @@ public class WarPlayerListener extends PlayerListener {
if(team != null
&& playerWarzone.nearAnyOwnedMonument(playerLoc, team)
&& player.getHealth() < 20
&& random.nextInt(42) == 3 ) { // one chance out of many of getting healed
&& player.getHealth() > 0 // don't heal the dead
&& random.nextInt(100) == 3 ) { // one chance out of 100 of getting healed
int currentHp = player.getHealth();
int newHp = currentHp + 5;
if(newHp > 20) newHp = 20;
@ -258,9 +259,8 @@ public class WarPlayerListener extends PlayerListener {
// flags can be captured at own spawn or own flag pole
team.addPoint();
if(team.getPoints() >= playerWarzone.getScoreCap()) {
handleScoreCapReached(player, team.getName(), playerWarzone);
event.setFrom(playerWarzone.getTeleport());
player.teleportTo(playerWarzone.getTeleport());
handleScoreCapReached(team.getName(), playerWarzone);
event.setCancelled(true);
} else {
// added a point
@ -313,7 +313,7 @@ public class WarPlayerListener extends PlayerListener {
teamsMessage += "none.";
}
for(Team team :warzone.getTeams()) {
teamsMessage += team.getName() + " (" + team.getPoints() + " points, "+ team.getRemainingTickets() + "/" + warzone.getLifePool() + " lives left. ";
teamsMessage += team.getName() + " (" + team.getPoints() + " points, "+ team.getRemainingLifes() + "/" + warzone.getLifePool() + " lives left. ";
for(Player member : team.getPlayers()) {
teamsMessage += member.getName() + " ";
}
@ -329,7 +329,7 @@ public class WarPlayerListener extends PlayerListener {
boolean scoreCapReached = false;
synchronized(playerWarzone) {
synchronized(player) {
int remaining = playerTeam.getRemainingTickets();
int remaining = playerTeam.getRemainingLifes();
if(remaining == 0) { // your death caused your team to lose
List<Team> teams = playerWarzone.getTeams();
for(Team t : teams) {
@ -354,19 +354,21 @@ public class WarPlayerListener extends PlayerListener {
for(Team winner : scoreCapTeams) {
winnersStr += winner.getName() + " ";
}
handleScoreCapReached(player, winnersStr, playerWarzone);
event.setFrom(playerWarzone.getTeleport());
handleScoreCapReached(winnersStr, playerWarzone);
event.setCancelled(true);
scoreCapReached = true;
} else {
// We can keep going
// A new battle starts. Reset the zone but not the teams.
for(Team t : teams) {
t.teamcast(war.str("A new battle begins. The warzone is being reset..."));
}
playerWarzone.getVolume().resetBlocks();
playerWarzone.initializeZone();
playerWarzone.initializeZone(event);
newBattle = true;
playerTeam.setRemainingTickets(playerTeam.getRemainingTickets()); // TODO get rid of this dirty workaround for the twice move-on-death bug
}
} else {
// player died
if(playerWarzone.isFlagThief(player.getName())) {
// died while carrying flag.. dropped it
Team victim = playerWarzone.getVictimTeamForThief(player.getName());
@ -377,21 +379,16 @@ public class WarPlayerListener extends PlayerListener {
t.teamcast(war.str(player.getName() + " died and dropped team " + victim.getName() + "'s flag."));
}
}
playerTeam.setRemainingTickets(remaining - 1);
playerTeam.setRemainingLives(remaining - 1);
}
}
}
synchronized(player) {
if(!newBattle && !scoreCapReached) {
playerTeam.resetSign();
playerWarzone.respawnPlayer(event, playerTeam, player);
playerTeam.resetSign();
war.info(player.getName() + " died and was tp'd back to team " + playerTeam.getName() + "'s spawn");
} else if (scoreCapReached) {
// game ended, still need to move the player who died
event.setFrom(playerWarzone.getTeleport());
player.teleportTo(playerWarzone.getTeleport());
event.setCancelled(true);
playerTeam.resetSign();
war.info(player.getName() + " died and enemy team reached score cap");
} else if (newBattle){
war.info(player.getName() + " died and battle ended in team " + playerTeam.getName() + "'s disfavor");
@ -399,16 +396,14 @@ public class WarPlayerListener extends PlayerListener {
}
}
private void handleScoreCapReached(Player player, String winnersStr, Warzone playerWarzone) {
private void handleScoreCapReached(String winnersStr, Warzone playerWarzone) {
winnersStr = "Score cap reached! Winning team(s): " + winnersStr;
winnersStr += ". Your inventory has (hopefully) been reset. The warzone is being reset... Please choose a new team.";
// Score cap reached. Reset everything.
for(Team t : playerWarzone.getTeams()) {
t.teamcast(war.str(winnersStr));
for(Player tp : t.getPlayers()) {
if(tp.getName() != player.getName()) {
tp.teleportTo(playerWarzone.getTeleport());
}
if(playerWarzone.hasPlayerInventory(tp.getName())){
playerWarzone.restorePlayerInventory(tp);
}
@ -421,5 +416,8 @@ public class WarPlayerListener extends PlayerListener {
}
playerWarzone.getVolume().resetBlocks();
playerWarzone.initializeZone();
if(war.getWarHub() != null) {
war.getWarHub().resetZoneSign(playerWarzone);
}
}
}

View File

@ -26,7 +26,7 @@ public class Team {
private Location teamSpawn = null;
private Location teamFlag = null;
private String name;
private int remainingTickets;
private int remainingLives;
private int points = 0;
private Volume spawnVolume;
private Volume flagVolume;
@ -150,7 +150,7 @@ public class Team {
sign.setType(Material.SIGN_POST);
sign.setData(new MaterialData(Material.SIGN_POST, (byte)6));
sign.setLine(0, "Team " + name);
sign.setLine(1, remainingTickets + "/" + warzone.getLifePool() + " lives left");
sign.setLine(1, remainingLives + "/" + warzone.getLifePool() + " lives left");
sign.setLine(2, points + "/" + warzone.getScoreCap() + " pts");
sign.setLine(3, players.size() + "/" + warzone.getTeamCap() + " players");
state.update(true);
@ -209,12 +209,12 @@ public class Team {
return false;
}
public void setRemainingTickets(int remainingTickets) {
this.remainingTickets = remainingTickets;
public void setRemainingLives(int remainingLives) {
this.remainingLives = remainingLives;
}
public int getRemainingTickets() {
return remainingTickets;
public int getRemainingLifes() {
return remainingLives;
}
public void addPoint() {
@ -317,7 +317,7 @@ public class Team {
warzone.getWorld().getBlockAt(x, y, z-1).setType(Material.FENCE);
warzone.getWorld().getBlockAt(x, y+1, z-1).setType(Material.FENCE);
warzone.getWorld().getBlockAt(x, y+2, z-1).setType(Material.FENCE);
warzone.getWorld().getBlockAt(x, y+2, z).setType(material);
warzone.getWorld().getBlockAt(x, y+2, z).setType(Material.FENCE);
warzone.getWorld().getBlockAt(x, y+1, z).setType(material);
}

View File

@ -221,7 +221,7 @@ public class Warzone {
for(Player player : team.getPlayers()) {
respawnPlayer(team, player);
}
team.setRemainingTickets(lifePool);
team.setRemainingLives(lifePool);
team.setTeamSpawn(team.getTeamSpawn());
if(team.getTeamFlag() != null) team.setTeamFlag(team.getTeamFlag());
team.resetSign();
@ -236,14 +236,18 @@ public class Warzone {
// everyone back to team spawn with full health
for(Team team : teams) {
for(Player player : team.getPlayers()) {
if(player.getName().equals(event.getPlayer().getName())) respawnPlayer(event, team, player);
if(player.getName().equals(event.getPlayer().getName())) {
respawnPlayer(event, team, player);
}
respawnPlayer(team, player);
}
team.setRemainingTickets(lifePool);
team.setRemainingLives(lifePool);
team.setTeamSpawn(team.getTeamSpawn());
if(team.getTeamFlag() != null) team.setTeamFlag(team.getTeamFlag());
team.resetSign();
}
initZone();
}
}
@ -269,6 +273,8 @@ public class Warzone {
this.setNorthwest(this.getNorthwest());
this.setSoutheast(this.getSoutheast());
this.flagThieves.clear();
}
public void addZoneOutline(BlockFace wall) {
@ -795,6 +801,12 @@ public class Warzone {
playerTeam.removePlayer(player.getName());
playerTeam.resetSign();
if(zone != null) {
if(zone.isFlagThief(player.getName())) {
Team victim = zone.getVictimTeamForThief(player.getName());
victim.getFlagVolume().resetBlocks();
victim.initializeTeamFlag();
zone.removeThief(player.getName());
}
if(zone.getLobby() != null) {
zone.getLobby().resetTeamGateSign(playerTeam);
}
@ -847,5 +859,9 @@ public class Warzone {
flagThieves.remove(thief);
}
public void clearFlagThieves() {
flagThieves.clear();
}
}

View File

@ -520,7 +520,7 @@ public class ZoneLobby {
lines[0] = "Team " + team.getName();
lines[1] = team.getPlayers().size() + "/" + warzone.getTeamCap() + " players";
lines[2] = team.getPoints() + "/" + warzone.getScoreCap() + " pts";
lines[3] = team.getRemainingTickets() + "/" + warzone.getLifePool() + " lives left";
lines[3] = team.getRemainingLifes() + "/" + warzone.getLifePool() + " lives left";
resetGateSign(gate, lines, true);
}
}

View File

@ -106,7 +106,7 @@ public class WarzoneMapper {
TeamMaterials.teamMaterialFromString(teamStrSplit[0]),
new Location(world, teamX, teamY, teamZ),
war, warzone );
team.setRemainingTickets(warzone.getLifePool());
team.setRemainingLives(warzone.getLifePool());
warzone.getTeams().add(team);
}
}