Better persistence, still some bugs in there. Protected spawns and monuments. Delete commands. Sign posts that give the score.

This commit is contained in:
taoneill 2011-01-04 21:12:02 -05:00
parent f2079ddae7
commit 1c9c3f40a4
6 changed files with 453 additions and 96 deletions

View File

@ -13,16 +13,16 @@ public class Monument {
int x = (int)location.x;
int y = (int)location.y;
int z = (int)location.z;
initialState[0] = war.getServer().getBlockIdAt(x+1, y-1, z+1);
initialState[1] = war.getServer().getBlockIdAt(x+1, y-1, z);
initialState[2] = war.getServer().getBlockIdAt(x+1, y-1, z-1);
initialState[3] = war.getServer().getBlockIdAt(x, y-1, z+1);
initialState[4] = war.getServer().getBlockIdAt(x, y-1, z);
initialState[5] = war.getServer().getBlockIdAt(x, y-1, z-1);
initialState[6] = war.getServer().getBlockIdAt(x-1, y-1, z+1);
initialState[7] = war.getServer().getBlockIdAt(x-1, y-1, z);
initialState[8] = war.getServer().getBlockIdAt(x-1, y-1, z-1);
initialState[9] = war.getServer().getBlockIdAt(x, y, z);
getInitialState()[0] = war.getServer().getBlockIdAt(x+1, y-1, z+1);
getInitialState()[1] = war.getServer().getBlockIdAt(x+1, y-1, z);
getInitialState()[2] = war.getServer().getBlockIdAt(x+1, y-1, z-1);
getInitialState()[3] = war.getServer().getBlockIdAt(x, y-1, z+1);
getInitialState()[4] = war.getServer().getBlockIdAt(x, y-1, z);
getInitialState()[5] = war.getServer().getBlockIdAt(x, y-1, z-1);
getInitialState()[6] = war.getServer().getBlockIdAt(x-1, y-1, z+1);
getInitialState()[7] = war.getServer().getBlockIdAt(x-1, y-1, z);
getInitialState()[8] = war.getServer().getBlockIdAt(x-1, y-1, z-1);
getInitialState()[9] = war.getServer().getBlockIdAt(x, y, z);
this.reset();
}
@ -82,16 +82,16 @@ public class Monument {
int x = (int)getLocation().x;
int y = (int)getLocation().y;
int z = (int)getLocation().z;
war.getServer().setBlockAt(initialState[0], x+1, y-1, z+1);
war.getServer().setBlockAt(initialState[1], x+1, y-1, z);
war.getServer().setBlockAt(initialState[2], x+1, y-1, z-1);
war.getServer().setBlockAt(initialState[3], x, y-1, z+1);
war.getServer().setBlockAt(initialState[4], x, y-1, z);
war.getServer().setBlockAt(initialState[5], x, y-1, z-1);
war.getServer().setBlockAt(initialState[6], x-1, y-1, z+1);
war.getServer().setBlockAt(initialState[7], x-1, y-1, z);
war.getServer().setBlockAt(initialState[8], x-1, y-1, z-1);
war.getServer().setBlockAt(initialState[9], x, y, z);
war.getServer().setBlockAt(getInitialState()[0], x+1, y-1, z+1);
war.getServer().setBlockAt(getInitialState()[1], x+1, y-1, z);
war.getServer().setBlockAt(getInitialState()[2], x+1, y-1, z-1);
war.getServer().setBlockAt(getInitialState()[3], x, y-1, z+1);
war.getServer().setBlockAt(getInitialState()[4], x, y-1, z);
war.getServer().setBlockAt(getInitialState()[5], x, y-1, z-1);
war.getServer().setBlockAt(getInitialState()[6], x-1, y-1, z+1);
war.getServer().setBlockAt(getInitialState()[7], x-1, y-1, z);
war.getServer().setBlockAt(getInitialState()[8], x-1, y-1, z-1);
war.getServer().setBlockAt(getInitialState()[9], x, y, z);
}
public Location getLocation() {
@ -106,6 +106,54 @@ public class Monument {
public String getName() {
return name;
}
public void setInitialState(int[] initialState) {
this.initialState = initialState;
}
public int[] getInitialState() {
return initialState;
}
public void setLocation(Location location) {
this.location = location;
int x = (int)location.x;
int y = (int)location.y;
int z = (int)location.z;
getInitialState()[0] = war.getServer().getBlockIdAt(x+1, y-1, z+1);
getInitialState()[1] = war.getServer().getBlockIdAt(x+1, y-1, z);
getInitialState()[2] = war.getServer().getBlockIdAt(x+1, y-1, z-1);
getInitialState()[3] = war.getServer().getBlockIdAt(x, y-1, z+1);
getInitialState()[4] = war.getServer().getBlockIdAt(x, y-1, z);
getInitialState()[5] = war.getServer().getBlockIdAt(x, y-1, z-1);
getInitialState()[6] = war.getServer().getBlockIdAt(x-1, y-1, z+1);
getInitialState()[7] = war.getServer().getBlockIdAt(x-1, y-1, z);
getInitialState()[8] = war.getServer().getBlockIdAt(x-1, y-1, z-1);
getInitialState()[9] = war.getServer().getBlockIdAt(x, y, z);
this.reset();
}
public boolean contains(Block block) {
int x = (int)location.x;
int y = (int)location.y;
int z = (int)location.z;
int bx = block.getX();
int by = block.getY();
int bz = block.getZ();
if((bx == x && by == y && bz == z) ||
(bx == x+1 && by == y-1 && bz == z+1) ||
(bx == x+1 && by == y-1 && bz == z) ||
(bx == x+1 && by == y-1 && bz == z-1) ||
(bx == x && by == y-1 && bz == z+1) ||
(bx == x && by == y-1 && bz == z) ||
(bx == x && by == y-1 && bz == z-1) ||
(bx == x-1 && by == y-1 && bz == z+1) ||
(bx == x-1 && by == y-1 && bz == z) ||
(bx == x-1 && by == y-1 && bz == z-1) ) {
return true;
}
return false;
}

View File

@ -12,7 +12,6 @@ public class Team {
public Team(String name, Location teamSpawn) {
this.setName(name);
this.teamSpawn = teamSpawn;
this.remainingTickets = War.LIFEPOOL;
}
public void setTeamSpawn(Location teamSpawn) {
@ -61,6 +60,7 @@ public class Team {
public void setRemainingTickets(int remainingTickets) {
this.remainingTickets = remainingTickets;
}
public int getRemainingTickets() {
@ -83,4 +83,26 @@ public class Team {
return points;
}
public boolean contains(Block block) {
int x = (int)this.teamSpawn.x;
int y = (int)this.teamSpawn.y;
int z = (int)this.teamSpawn.z;
int bx = block.getX();
int by = block.getY();
int bz = block.getZ();
if((bx == x && by == y && bz == z) ||
(bx == x+1 && by == y-1 && bz == z+1) ||
(bx == x+1 && by == y-1 && bz == z) ||
(bx == x+1 && by == y-1 && bz == z-1) ||
(bx == x && by == y-1 && bz == z+1) ||
(bx == x && by == y-1 && bz == z) ||
(bx == x && by == y-1 && bz == z-1) ||
(bx == x-1 && by == y-1 && bz == z+1) ||
(bx == x-1 && by == y-1 && bz == z) ||
(bx == x-1 && by == y-1 && bz == z-1) ) {
return true;
}
return false;
}
}

View File

@ -59,6 +59,14 @@ public class War extends Plugin {
listener,
this,
PluginListener.Priority.MEDIUM);
etc.getLoader().addListener( PluginLoader.Hook.BLOCK_BROKEN,
listener,
this,
PluginListener.Priority.MEDIUM);
etc.getLoader().addListener( PluginLoader.Hook.BLOCK_PLACE,
listener,
this,
PluginListener.Priority.MEDIUM);
// Load files from disk or create them
this.defaultLoadout.add(new Item(272, 1, 0));

View File

@ -81,7 +81,7 @@ public class WarListener extends PluginListener {
player.sendMessage(war.str("Usage: /join <team-name>." +
" Teams are warzone specific." +
" You must be inside a warzone to join a team."));
} else {
} else {
// drop from old team if any
Team previousTeam = war.getPlayerTeam(player.getName());
if(previousTeam != null) {
@ -93,7 +93,8 @@ public class WarListener extends PluginListener {
// join new team
String name = split[1];
List<Team> teams = war.warzone(player.getLocation()).getTeams();
Warzone warzone = war.warzone(player.getLocation());
List<Team> teams = warzone.getTeams();
boolean foundTeam = false;
for(Team team : teams) {
if(team.getName().equals(name)) {
@ -110,6 +111,11 @@ public class WarListener extends PluginListener {
} else {
player.sendMessage(war.str("No such team. Try /teams."));
}
if(!warzone.hasPlayerInventory(player.getName())) {
warzone.keepPlayerInventory(player);
player.sendMessage(war.str("Your inventory has been stored until you /leave."));
}
}
return true;
}
@ -123,6 +129,9 @@ public class WarListener extends PluginListener {
Team playerTeam = war.getPlayerTeam(player.getName());
playerTeam.removePlayer(player.getName());
player.sendMessage(war.str("Left the team. You can now exit the warzone."));
Warzone zone = war.warzone(player.getLocation());
zone.restorePlayerInventory(player);
player.sendMessage(war.str("Your inventory has (hopefully) been restored."));
}
return true;
}
@ -162,7 +171,7 @@ public class WarListener extends PluginListener {
return true;
}
// Warzone maker commands: /setwarzone, /setwarzonestart, /resetwarzone, /newteam, /setteamspawn, .. /setmonument?
// Warzone maker commands: /setwarzone, /savewarzone, /newteam, /setteamspawn, .. /monument?
// /newteam <teamname>
else if(command.equals("/newteam")) {
@ -175,7 +184,7 @@ public class WarListener extends PluginListener {
Team newTeam = new Team(name, player.getLocation());
Warzone warzone = war.warzone(player.getLocation());
warzone.getTeams().add(newTeam);
addSpawnArea(newTeam, player.getLocation(), 41);
warzone.addSpawnArea(newTeam, player.getLocation(), 41);
player.sendMessage(war.str("Team " + name + " created with spawn here."));
WarzoneMapper.save(warzone, false);
}
@ -183,7 +192,7 @@ public class WarListener extends PluginListener {
}
// /setteamspawn
else if(command.equals("/setteamspawn")) {
else if(command.equals("/teamspawn")) {
if(split.length < 2 || !war.inAnyWarzone(player.getLocation())) {
player.sendMessage(war.str("Usage: /setteamspawn <team-name>. " +
"Sets the team spawn. " +
@ -198,8 +207,8 @@ public class WarListener extends PluginListener {
}
}
if(team != null) {
removeSpawnArea(team);
addSpawnArea(team, player.getLocation(), 41);
warzone.removeSpawnArea(team);
warzone.addSpawnArea(team, player.getLocation(), 41);
team.setTeamSpawn(player.getLocation());
player.sendMessage(war.str("Team " + team.getName() + " spawn relocated."));
} else {
@ -213,6 +222,34 @@ public class WarListener extends PluginListener {
return true;
}
// /deleteteam <teamname>
else if(command.equals("/deleteteam")) {
if(split.length < 2 || !war.inAnyWarzone(player.getLocation())) {
player.sendMessage(war.str("Usage: /deleteteam <team-name>." +
" Deletes the team and its spawn. " +
"Must be in a warzone (try /warzones and /warzone). "));
} else {
String name = split[1];
Warzone warzone = war.warzone(player.getLocation());
List<Team> teams = warzone.getTeams();
Team team = null;
for(Team t : teams) {
if(name.equals(t.getName())) {
team = t;
}
}
if(team != null) {
warzone.removeSpawnArea(team);
warzone.getTeams().remove(team);
WarzoneMapper.save(warzone, false);
player.sendMessage(war.str("Team " + name + " removed."));
} else {
player.sendMessage(war.str("No such team."));
}
}
return true;
}
// /setwarzone
else if(command.equals("/setwarzone")) {
if(split.length < 3 || (split.length == 3 && (!split[2].equals("southeast") && !split[2].equals("northwest")
@ -273,8 +310,7 @@ public class WarListener extends PluginListener {
}
return true;
}
}
// /savewarzone
else if(command.equals("/savewarzone")) {
@ -296,81 +332,78 @@ public class WarListener extends PluginListener {
return true;
}
// /deletewarzone
else if(command.equals("/deletewarzone")) {
if(!war.inAnyWarzone(player.getLocation())) {
player.sendMessage(war.str("Usage: /deletewarzone." +
" Deletes the warzone. " +
"Must be in the warzone (try /warzones and /warzone). "));
} else {
Warzone warzone = war.warzone(player.getLocation());
for(Team t : warzone.getTeams()) {
warzone.removeSpawnArea(t);
}
for(Monument m : warzone.getMonuments()) {
m.remove();
}
war.getWarzones().remove(warzone);
WarMapper.save(war);
WarzoneMapper.delete(warzone.getName());
player.sendMessage(war.str("Warzone " + warzone.getName() + " removed."));
}
return true;
}
// /monument
else if(command.equals("/monument")) {
if(!war.inAnyWarzone(player.getLocation())) {
player.sendMessage(war.str("Usage: /monument <name>. Must be in warzone."));
} else {
Warzone warzone = war.warzone(player.getLocation());
Monument monument = new Monument(split[1], war, player.getLocation());
warzone.getMonuments().add(monument);
player.sendMessage(war.str("Monument " + monument.getName() + " created."));
String monumentName = split[1];
if(warzone.hasMonument(monumentName)) {
// move the existing monument
Monument monument = warzone.getMonument(monumentName);
monument.remove();
monument.setLocation(player.getLocation());
player.sendMessage(war.str("Monument " + monument.getName() + " was moved."));
} else {
// create a new monument
Monument monument = new Monument(split[1], war, player.getLocation());
warzone.getMonuments().add(monument);
player.sendMessage(war.str("Monument " + monument.getName() + " created."));
}
WarzoneMapper.save(warzone, false);
}
return true;
}
// /deletemonument <name>
else if(command.equals("/deletemonument")) {
if(split.length < 2 || !war.inAnyWarzone(player.getLocation())) {
player.sendMessage(war.str("Usage: /deletemonument <team-name>." +
" Deletes the monument. " +
"Must be in a warzone (try /warzones and /warzone). "));
} else {
String name = split[1];
Warzone warzone = war.warzone(player.getLocation());
Monument monument = warzone.getMonument(name);
if(monument != null) {
monument.remove();
warzone.getMonuments().remove(monument);
WarzoneMapper.save(warzone, false);
player.sendMessage(war.str("Monument " + name + " removed."));
} else {
player.sendMessage(war.str("No such monument."));
}
}
return true;
}
return false;
}
private void removeSpawnArea(Team team) {
// Reset spawn to what it was before the gold blocks
int[] spawnState = team.getOldSpawnState();
int x = (int)team.getTeamSpawn().x;
int y = (int)team.getTeamSpawn().y;
int z = (int)team.getTeamSpawn().z;
war.getServer().setBlockAt(spawnState[0], x+1, y-1, z+1);
war.getServer().setBlockAt(spawnState[1], x+1, y-1, z);
war.getServer().setBlockAt(spawnState[2], x+1, y-1, z-1);
war.getServer().setBlockAt(spawnState[3], x, y-1, z+1);
war.getServer().setBlockAt(spawnState[4], x, y-1, z);
war.getServer().setBlockAt(spawnState[5], x, y-1, z-1);
war.getServer().setBlockAt(spawnState[6], x-1, y-1, z+1);
war.getServer().setBlockAt(spawnState[7], x-1, y-1, z);
war.getServer().setBlockAt(spawnState[8], x-1, y-1, z-1);
war.getServer().setBlockAt(spawnState[9], x, y, z);
}
private void addSpawnArea(Team team, Location location, int blockType) {
// Save the spawn state (i.e. the nine block under the player spawn)
int[] spawnState = new int[10];
int x = (int)location.x;
int y = (int)location.y;
int z = (int)location.z;
spawnState[0] = war.getServer().getBlockIdAt(x+1, y-1, z+1);
spawnState[1] = war.getServer().getBlockIdAt(x+1, y-1, z);
spawnState[2] = war.getServer().getBlockIdAt(x+1, y-1, z-1);
spawnState[3] = war.getServer().getBlockIdAt(x, y-1, z+1);
spawnState[4] = war.getServer().getBlockIdAt(x, y-1, z);
spawnState[5] = war.getServer().getBlockIdAt(x, y-1, z-1);
spawnState[6] = war.getServer().getBlockIdAt(x-1, y-1, z+1);
spawnState[7] = war.getServer().getBlockIdAt(x-1, y-1, z);
spawnState[8] = war.getServer().getBlockIdAt(x-1, y-1, z-1);
spawnState[9] = war.getServer().getBlockIdAt(x, y, z);
team.setTeamSpawn(location);
team.setOldSpawnState(spawnState);
// Set the spawn as gold blocks
war.getServer().setBlockAt(blockType, x+1, y-1, z+1);
war.getServer().setBlockAt(blockType, x+1, y-1, z);
war.getServer().setBlockAt(blockType, x+1, y-1, z-1);
war.getServer().setBlockAt(blockType, x, y-1, z+1);
war.getServer().setBlockAt(blockType, x, y-1, z);
war.getServer().setBlockAt(blockType, x, y-1, z-1);
war.getServer().setBlockAt(blockType, x-1, y-1, z+1);
war.getServer().setBlockAt(blockType, x-1, y-1, z);
war.getServer().setBlockAt(blockType, x-1, y-1, z-1);
Block block = new Block(63, x, y, z, 8);
war.getServer().setBlock(block);
block = war.getServer().getBlockAt(x, y, z);
ComplexBlock complexBlock = war.getServer().getComplexBlock(x, y, z);
Sign sign = (Sign)complexBlock;
sign.setText(0, "Team");
sign.setText(1, team.getName());
sign.setText(2, "spawn");
sign.update();
}
public boolean onDamage(PluginLoader.DamageType damageType, BaseEntity attacker, BaseEntity defender, int damageAmount) {
if(attacker != null && defender != null && attacker.isPlayer() && defender.isPlayer()) {
@ -412,7 +445,7 @@ public class WarListener extends PluginListener {
} else if (attackerWarzone != defenderWarzone) {
a.sendMessage(war.str("Your target is playing in another warzone."));
}
return true; // no pvp outside of the war battles, no friendly fire either
return true; // can't attack someone inside awarzone if you're not in a team
}
}
// mobs are always dangerous
@ -438,6 +471,17 @@ public class WarListener extends PluginListener {
if(!t.getName().equals(team.getName())) {
// all other teams get a point
t.addPoint();
int x = (int)t.getTeamSpawn().x;
int y = (int)t.getTeamSpawn().y;
int z = (int)t.getTeamSpawn().z;
Block block = war.getServer().getBlockAt(x, y, z);
ComplexBlock complexBlock = war.getServer().getComplexBlock(x, y, z);
Sign sign = (Sign)complexBlock;
sign.setText(0, "Team " + team.getName());
sign.setText(1, "spawn");
sign.setText(2, team.getPoints() + " pts");
sign.setText(3, team.getRemainingTickets() + "/" + zone.getLifePool() + " lives left");
sign.update();
}
}
zone.resetState();
@ -451,6 +495,18 @@ public class WarListener extends PluginListener {
player.sendMessage(war.str("You died!"));
List<Team> teams = zone.getTeams();
int x = (int)team.getTeamSpawn().x;
int y = (int)team.getTeamSpawn().y;
int z = (int)team.getTeamSpawn().z;
Block block = war.getServer().getBlockAt(x, y, z);
ComplexBlock complexBlock = war.getServer().getComplexBlock(x, y, z);
Sign sign = (Sign)complexBlock;
sign.setText(0, "Team " + team.getName());
sign.setText(1, "spawn");
sign.setText(2, team.getPoints() + " pts");
sign.setText(3, team.getRemainingTickets()+ "/" + zone.getLifePool() + " lives left");
sign.update();
// for(Team t : teams) {
// //t.teamcast(war.str(player.getName() + " died. Team " + team.getName() + " has " + team.getRemainingTickets() + "/" + War.LIFEPOOL + " lives left."));
// if(team.getRemainingTickets() == 0) {
@ -509,6 +565,38 @@ public class WarListener extends PluginListener {
player.sendMessage(war.str("Your dance pleases the monument's voodoo. You gain full health!"));
}
}
public boolean onBlockDestroy(Player player, Block block) {
return false;
}
public boolean onBlockBreak(Player player, Block block) {
if(player != null && block != null) {
Warzone warzone = war.warzone(player.getLocation());
if(warzone != null && war.getPlayerTeam(player.getName()) == null) {
// can't actually destroy blocks in a warzone if not part of a team
player.sendMessage(war.str("Can't destroy part of a warzone if you're not in a team."));
return true;
}
if(warzone != null && warzone.isImportantBlock(block)) {
player.sendMessage(war.str("Can't destroy this."));
return true;
}
}
return false;
}
public boolean onBlockPlace(Player player, Block blockPlaced, Block blockClicked, Item itemInHand) {
Warzone warzone = war.warzone(player.getLocation());
if(warzone != null) {
if(warzone.isImportantBlock(blockPlaced) || warzone.isImportantBlock(blockClicked)) {
player.sendMessage(war.str("Can't build here."));
return true;
}
}
return false;
}
private String getAllTeamsMsg(Player player){
@ -516,8 +604,9 @@ public class WarListener extends PluginListener {
if(war.warzone(player.getLocation()).getTeams().isEmpty()){
teamsMessage += "none.";
}
for(Team team : war.warzone(player.getLocation()).getTeams()) {
teamsMessage += team.getName() + " (" + team.getPoints() + " points, "+ team.getRemainingTickets() + "/" + War.LIFEPOOL + " lives left. ";
Warzone warzone = war.warzone(player.getLocation());
for(Team team :warzone.getTeams()) {
teamsMessage += team.getName() + " (" + team.getPoints() + " points, "+ team.getRemainingTickets() + "/" + warzone.getLifePool() + " lives left. ";
for(Player member : team.getPlayers()) {
teamsMessage += member.getName() + " ";
}

View File

@ -1,4 +1,5 @@
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
public class Warzone {
@ -16,6 +17,8 @@ public class Warzone {
private int lifePool;
private List<Item> loadout;
private HashMap<String, Item[]> inventories = new HashMap<String, Item[]>();
public Warzone(War war, String name) {
this.war = war;
this.server = war.getServer();
@ -205,10 +208,13 @@ public class Warzone {
// everyone back to team spawn with full health
for(Team team : teams) {
Location spawn = team.getTeamSpawn();
removeSpawnArea(team); // reset spawn
addSpawnArea(team, spawn, 41);
for(Player player : team.getPlayers()) {
respawnPlayer(team, player);
}
team.setRemainingTickets(War.LIFEPOOL);
team.setRemainingTickets(lifePool);
}
// reset monuments
@ -273,6 +279,66 @@ public class Warzone {
}
return false;
}
public void removeSpawnArea(Team team) {
// Reset spawn to what it was before the gold blocks
int[] spawnState = team.getOldSpawnState();
int x = (int)team.getTeamSpawn().x;
int y = (int)team.getTeamSpawn().y;
int z = (int)team.getTeamSpawn().z;
war.getServer().setBlockAt(spawnState[0], x+1, y-1, z+1);
war.getServer().setBlockAt(spawnState[1], x+1, y-1, z);
war.getServer().setBlockAt(spawnState[2], x+1, y-1, z-1);
war.getServer().setBlockAt(spawnState[3], x, y-1, z+1);
war.getServer().setBlockAt(spawnState[4], x, y-1, z);
war.getServer().setBlockAt(spawnState[5], x, y-1, z-1);
war.getServer().setBlockAt(spawnState[6], x-1, y-1, z+1);
war.getServer().setBlockAt(spawnState[7], x-1, y-1, z);
war.getServer().setBlockAt(spawnState[8], x-1, y-1, z-1);
war.getServer().setBlockAt(spawnState[9], x, y, z);
}
public void addSpawnArea(Team team, Location location, int blockType) {
// Save the spawn state (i.e. the nine block under the player spawn)
int[] spawnState = new int[10];
int x = (int)location.x;
int y = (int)location.y;
int z = (int)location.z;
spawnState[0] = war.getServer().getBlockIdAt(x+1, y-1, z+1);
spawnState[1] = war.getServer().getBlockIdAt(x+1, y-1, z);
spawnState[2] = war.getServer().getBlockIdAt(x+1, y-1, z-1);
spawnState[3] = war.getServer().getBlockIdAt(x, y-1, z+1);
spawnState[4] = war.getServer().getBlockIdAt(x, y-1, z);
spawnState[5] = war.getServer().getBlockIdAt(x, y-1, z-1);
spawnState[6] = war.getServer().getBlockIdAt(x-1, y-1, z+1);
spawnState[7] = war.getServer().getBlockIdAt(x-1, y-1, z);
spawnState[8] = war.getServer().getBlockIdAt(x-1, y-1, z-1);
spawnState[9] = war.getServer().getBlockIdAt(x, y, z);
team.setTeamSpawn(location);
team.setOldSpawnState(spawnState);
// Set the spawn as gold blocks
war.getServer().setBlockAt(blockType, x+1, y-1, z+1);
war.getServer().setBlockAt(blockType, x+1, y-1, z);
war.getServer().setBlockAt(blockType, x+1, y-1, z-1);
war.getServer().setBlockAt(blockType, x, y-1, z+1);
war.getServer().setBlockAt(blockType, x, y-1, z);
war.getServer().setBlockAt(blockType, x, y-1, z-1);
war.getServer().setBlockAt(blockType, x-1, y-1, z+1);
war.getServer().setBlockAt(blockType, x-1, y-1, z);
war.getServer().setBlockAt(blockType, x-1, y-1, z-1);
Block block = new Block(63, x, y, z, 8);
war.getServer().setBlock(block);
block = war.getServer().getBlockAt(x, y, z);
ComplexBlock complexBlock = war.getServer().getComplexBlock(x, y, z);
Sign sign = (Sign)complexBlock;
sign.setText(0, "Team " + team.getName());
sign.setText(1, "spawn");
sign.setText(2, "0 pts");
sign.setText(3, lifePool + "/" + lifePool + " lives left");
sign.update();
}
public List<Monument> getMonuments() {
return monuments;
@ -311,5 +377,80 @@ public class Warzone {
return initialState;
}
public boolean hasPlayerInventory(String playerName) {
return inventories.containsKey(playerName);
}
public void keepPlayerInventory(Player player) {
inventories.put(player.getName(), player.getInventory().getContents());
}
public void restorePlayerInventory(Player player) {
Item[] contents = inventories.get(player.getName());
player.getInventory().clearContents();
player.getInventory().setContents(contents);
player.getInventory().update();
inventories.remove(player.getName());
}
public boolean hasMonument(String monumentName) {
boolean hasIt = false;
for(Monument monument: monuments) {
if(monument.getName().equals(monumentName)) {
return true;
}
}
return false;
}
public Monument getMonument(String monumentName) {
boolean hasIt = false;
for(Monument monument: monuments) {
if(monument.getName().equals(monumentName)) {
return monument;
}
}
return null;
}
public boolean isImportantBlock(Block block) {
block.getX();
for(Monument m : monuments) {
if(m.contains(block)){
return true;
}
}
for(Team t : teams) {
if(t.contains(block)){
return true;
}
}
if(teleportNear(block)) {
return true;
}
return false;
}
private boolean teleportNear(Block block) {
int x = (int)this.teleport.x;
int y = (int)this.teleport.y;
int z = (int)this.teleport.z;
int bx = block.getX();
int by = block.getY();
int bz = block.getZ();
if((bx == x && by == y && bz == z) ||
(bx == x+1 && by == y-1 && bz == z+1) ||
(bx == x+1 && by == y-1 && bz == z) ||
(bx == x+1 && by == y-1 && bz == z-1) ||
(bx == x && by == y-1 && bz == z+1) ||
(bx == x && by == y-1 && bz == z) ||
(bx == x && by == y-1 && bz == z-1) ||
(bx == x-1 && by == y-1 && bz == z+1) ||
(bx == x-1 && by == y-1 && bz == z) ||
(bx == x-1 && by == y-1 && bz == z-1) ) {
return true;
}
return false;
}
}

View File

@ -116,7 +116,34 @@ public class WarzoneMapper {
}
}
}
warzoneBlocksFile.setString("zoneBlocks", stateStr);
// monument blocks
for(Monument monument: warzone.getMonuments()) {
String monumentBlocksStr = warzoneBlocksFile.getString("monument"+monument.getName()+"Blocks");
String[] monumentBlocksSplit = monumentBlocksStr.split(",");
int[] monumentState = new int[10];
for(int i = 0; i < monumentBlocksSplit.length; i++) {
String split = monumentBlocksSplit[i];
if(split != null && !split.equals("")) {
monumentState[i] = Integer.parseInt(split);
}
}
monument.setInitialState(monumentState);
}
// team spawn blocks
for(Team team : warzone.getTeams()) {
String teamBlocksStr = warzoneBlocksFile.getString("team"+team.getName()+"Blocks");
String[] teamBlocksSplit = teamBlocksStr.split(",");
int[] teamState = new int[10];
for(int i = 0; i < teamBlocksSplit.length; i++) {
String split = teamBlocksSplit[i];
if(split != null && !split.equals("")) {
teamState[i] = Integer.parseInt(split);
}
}
team.setOldSpawnState(teamState);
}
return warzone;
@ -205,6 +232,26 @@ public class WarzoneMapper {
}
}
warzoneBlocksFile.setString("zoneBlocks", stateBuilder.toString());
// monument blocks
for(Monument monument: monuments) {
String monumentBlocksStr = "";
for(int type : monument.getInitialState()) {
monumentBlocksStr += type + ",";
}
warzoneBlocksFile.setString("monument"+monument.getName()+"Blocks", monumentBlocksStr);
}
// team spawn blocks
for(Team team : teams) {
String teamBlocksStr = "";
for(int type : team.getOldSpawnState()) {
teamBlocksStr += type + ",";
}
warzoneBlocksFile.setString("team"+team.getName()+"Blocks", teamBlocksStr);
}
warzoneBlocksFile.save();
}
@ -213,6 +260,8 @@ public class WarzoneMapper {
public static void delete(String name) {
File warzoneConfig = new File("warzone-" + name + ".txt");
warzoneConfig.delete();
File warzoneBlocksFile = new File("warzone-" + name + ".dat");
warzoneBlocksFile.delete();
}
}