A start on gh-83. Won't completely break when MultiVerse isn't finished loading. Will handle this better later.

This commit is contained in:
taoneill 2011-03-14 23:52:24 -04:00
parent 1cf30f18b8
commit fc70b78040
4 changed files with 233 additions and 280 deletions

View File

@ -1,15 +0,0 @@
package com.tommytony.war;
import org.bukkit.ChatColor;
import org.bukkit.Material;
/**
*
* @author tommytony
*
*/
public class TeamChatColors {
public static final ChatColor TEAMDIAMOND = ChatColor.DARK_AQUA;
public static final ChatColor TEAMIRON = ChatColor.GRAY;
public static final ChatColor TEAMGOLD = ChatColor.GOLD;
}

View File

@ -1,39 +0,0 @@
package com.tommytony.war;
import org.bukkit.Material;
/**
*
* @author tommytony
*
*/
public class TeamMaterials {
public static final Material TEAMDIAMOND = Material.DIAMOND_BLOCK;
public static final Material TEAMIRON = Material.IRON_BLOCK;
public static final Material TEAMGOLD = Material.GOLD_BLOCK;
public static Material teamMaterialFromString(String str) {
String lowered = str.toLowerCase();
if(lowered.equals("diamond") || lowered.equals("d")) {
return TEAMDIAMOND;
} else if (lowered.equals("iron") || lowered.equals("i")) {
return TEAMIRON;
} else if (lowered.equals("gold") || lowered.equals("g")) {
return TEAMGOLD;
}
return null;
}
public static String teamMaterialToString(Material material) {
if(material.getId() == TEAMDIAMOND.getId()) {
return "diamond";
}
if(material.getId() == TEAMIRON.getId()) {
return "iron";
}
if(material.getId() == TEAMGOLD.getId()) {
return "gold";
}
return null;
}
}

View File

@ -55,12 +55,14 @@ public class WarMapper {
if(warzoneName != null && !warzoneName.equals("")){ if(warzoneName != null && !warzoneName.equals("")){
war.logInfo("Restoring zone " + warzoneName + "..."); war.logInfo("Restoring zone " + warzoneName + "...");
Warzone zone = WarzoneMapper.load(war, warzoneName, !newWar); // cascade load, only load blocks if warzone exists Warzone zone = WarzoneMapper.load(war, warzoneName, !newWar); // cascade load, only load blocks if warzone exists
war.getWarzones().add(zone); if(zone != null) { // could have failed, would've been logged already
zone.getVolume().resetBlocks(); war.getWarzones().add(zone);
if(zone.getLobby() != null) { zone.getVolume().resetBlocks();
zone.getLobby().getVolume().resetBlocks(); if(zone.getLobby() != null) {
zone.getLobby().getVolume().resetBlocks();
}
zone.initializeZone(); // is this wise?
} }
zone.initializeZone(); // is this wise?
} }
} }

View File

@ -47,241 +47,246 @@ public class WarzoneMapper {
world = war.getServer().getWorld(worldStr); world = war.getServer().getWorld(worldStr);
} }
// Create the zone
Warzone warzone = new Warzone(war, world, name);
// Create file if needed if(world == null) {
if(!warzoneConfig.containsKey("name")) { war.logWarn("Failed to restore warzone " + name + "! World " + worldStr + " was not loaded yet. Try /reload once the server is up and running.");
WarzoneMapper.save(war, warzone, false); } else {
war.getLogger().info("Warzone " + name + " config file created."); // Create the zone
try { Warzone warzone = new Warzone(war, world, name);
warzoneConfig.load();
} catch (IOException e) {
//war.getLogger().info("Failed to reload warzone-" + name + ".txt file after creating it.");
e.printStackTrace();
}
}
// northwest // Create file if needed
String nwStr = warzoneConfig.getString("northWest"); if(!warzoneConfig.containsKey("name")) {
if(nwStr != null && !nwStr.equals("")) { WarzoneMapper.save(war, warzone, false);
String[] nwStrSplit = nwStr.split(","); war.getLogger().info("Warzone " + name + " config file created.");
try {
int nwX = Integer.parseInt(nwStrSplit[0]); warzoneConfig.load();
int nwY = Integer.parseInt(nwStrSplit[1]); } catch (IOException e) {
int nwZ = Integer.parseInt(nwStrSplit[2]); //war.getLogger().info("Failed to reload warzone-" + name + ".txt file after creating it.");
Location nw = new Location(world, nwX, nwY, nwZ); e.printStackTrace();
warzone.setNorthwest(nw);
}
// southeast
String seStr = warzoneConfig.getString("southEast");
if(nwStr != null && !nwStr.equals("")) {
String[] seStrSplit = seStr.split(",");
int seX = Integer.parseInt(seStrSplit[0]);
int seY = Integer.parseInt(seStrSplit[1]);
int seZ = Integer.parseInt(seStrSplit[2]);
Location se = new Location(world, seX, seY, seZ);
warzone.setSoutheast(se);
}
// teleport
String teleportStr = warzoneConfig.getString("teleport");
if(teleportStr != null && !teleportStr.equals("")) {
String[] teleportSplit = teleportStr.split(",");
int teleX = Integer.parseInt(teleportSplit[0]);
int teleY = Integer.parseInt(teleportSplit[1]);
int teleZ = Integer.parseInt(teleportSplit[2]);
int yaw = Integer.parseInt(teleportSplit[3]);
warzone.setTeleport(new Location(world, teleX, teleY, teleZ, yaw, 0));
}
// teams
String teamsStr = warzoneConfig.getString("teams");
if(teamsStr != null && !teamsStr.equals("")) {
String[] teamsSplit = teamsStr.split(";");
warzone.getTeams().clear();
for(String teamStr : teamsSplit) {
if(teamStr != null && !teamStr.equals("")){
String[] teamStrSplit = teamStr.split(",");
int teamX = Integer.parseInt(teamStrSplit[1]);
int teamY = Integer.parseInt(teamStrSplit[2]);
int teamZ = Integer.parseInt(teamStrSplit[3]);
Location teamLocation = new Location(world, teamX, teamY, teamZ);
if(teamStrSplit.length > 4) {
int yaw = Integer.parseInt(teamStrSplit[4]);
teamLocation.setYaw(yaw);
}
Team team = new Team(teamStrSplit[0],
TeamKinds.teamKindFromString(teamStrSplit[0]),
teamLocation,
war, warzone );
team.setRemainingLives(warzone.getLifePool());
warzone.getTeams().add(team);
} }
} }
}
// teamFlags // northwest
String teamFlagsStr = warzoneConfig.getString("teamFlags"); String nwStr = warzoneConfig.getString("northWest");
if(teamFlagsStr != null && !teamFlagsStr.equals("")) { if(nwStr != null && !nwStr.equals("")) {
String[] teamFlagsSplit = teamFlagsStr.split(";"); String[] nwStrSplit = nwStr.split(",");
for(String teamFlagStr : teamFlagsSplit) {
if(teamFlagStr != null && !teamFlagStr.equals("")){ int nwX = Integer.parseInt(nwStrSplit[0]);
String[] teamFlagStrSplit =teamFlagStr.split(","); int nwY = Integer.parseInt(nwStrSplit[1]);
Team team = warzone.getTeamByKind(TeamKinds.teamKindFromString(teamFlagStrSplit[0])); int nwZ = Integer.parseInt(nwStrSplit[2]);
if(team != null) { Location nw = new Location(world, nwX, nwY, nwZ);
int teamFlagX = Integer.parseInt(teamFlagStrSplit[1]); warzone.setNorthwest(nw);
int teamFlagY = Integer.parseInt(teamFlagStrSplit[2]); }
int teamFlagZ = Integer.parseInt(teamFlagStrSplit[3]);
Location teamFlagLocation = new Location(world, teamFlagX, teamFlagY, teamFlagZ); // southeast
if(teamFlagStrSplit.length > 4) { String seStr = warzoneConfig.getString("southEast");
int yaw = Integer.parseInt(teamFlagStrSplit[4]); if(nwStr != null && !nwStr.equals("")) {
teamFlagLocation.setYaw(yaw); String[] seStrSplit = seStr.split(",");
int seX = Integer.parseInt(seStrSplit[0]);
int seY = Integer.parseInt(seStrSplit[1]);
int seZ = Integer.parseInt(seStrSplit[2]);
Location se = new Location(world, seX, seY, seZ);
warzone.setSoutheast(se);
}
// teleport
String teleportStr = warzoneConfig.getString("teleport");
if(teleportStr != null && !teleportStr.equals("")) {
String[] teleportSplit = teleportStr.split(",");
int teleX = Integer.parseInt(teleportSplit[0]);
int teleY = Integer.parseInt(teleportSplit[1]);
int teleZ = Integer.parseInt(teleportSplit[2]);
int yaw = Integer.parseInt(teleportSplit[3]);
warzone.setTeleport(new Location(world, teleX, teleY, teleZ, yaw, 0));
}
// teams
String teamsStr = warzoneConfig.getString("teams");
if(teamsStr != null && !teamsStr.equals("")) {
String[] teamsSplit = teamsStr.split(";");
warzone.getTeams().clear();
for(String teamStr : teamsSplit) {
if(teamStr != null && !teamStr.equals("")){
String[] teamStrSplit = teamStr.split(",");
int teamX = Integer.parseInt(teamStrSplit[1]);
int teamY = Integer.parseInt(teamStrSplit[2]);
int teamZ = Integer.parseInt(teamStrSplit[3]);
Location teamLocation = new Location(world, teamX, teamY, teamZ);
if(teamStrSplit.length > 4) {
int yaw = Integer.parseInt(teamStrSplit[4]);
teamLocation.setYaw(yaw);
} }
team.setTeamFlag(teamFlagLocation); // this may screw things up Team team = new Team(teamStrSplit[0],
TeamKinds.teamKindFromString(teamStrSplit[0]),
teamLocation,
war, warzone );
team.setRemainingLives(warzone.getLifePool());
warzone.getTeams().add(team);
} }
} }
} }
}
// ff // teamFlags
warzone.setFriendlyFire(warzoneConfig.getBoolean("friendlyFire")); String teamFlagsStr = warzoneConfig.getString("teamFlags");
if(teamFlagsStr != null && !teamFlagsStr.equals("")) {
// loadout String[] teamFlagsSplit = teamFlagsStr.split(";");
String loadoutStr = warzoneConfig.getString("loadout"); for(String teamFlagStr : teamFlagsSplit) {
if(loadoutStr != null && !loadoutStr.equals("")) { if(teamFlagStr != null && !teamFlagStr.equals("")){
String[] loadoutStrSplit = loadoutStr.split(";"); String[] teamFlagStrSplit =teamFlagStr.split(",");
warzone.getLoadout().clear(); Team team = warzone.getTeamByKind(TeamKinds.teamKindFromString(teamFlagStrSplit[0]));
for(String itemStr : loadoutStrSplit) { if(team != null) {
if(itemStr != null && !itemStr.equals("")) { int teamFlagX = Integer.parseInt(teamFlagStrSplit[1]);
String[] itemStrSplit = itemStr.split(","); int teamFlagY = Integer.parseInt(teamFlagStrSplit[2]);
ItemStack item = new ItemStack(Integer.parseInt(itemStrSplit[0]), int teamFlagZ = Integer.parseInt(teamFlagStrSplit[3]);
Integer.parseInt(itemStrSplit[1])); Location teamFlagLocation = new Location(world, teamFlagX, teamFlagY, teamFlagZ);
warzone.getLoadout().put(Integer.parseInt(itemStrSplit[2]), item); if(teamFlagStrSplit.length > 4) {
int yaw = Integer.parseInt(teamFlagStrSplit[4]);
teamFlagLocation.setYaw(yaw);
}
team.setTeamFlag(teamFlagLocation); // this may screw things up
}
}
} }
} }
}
// life pool // ff
warzone.setLifePool(warzoneConfig.getInt("lifePool")); warzone.setFriendlyFire(warzoneConfig.getBoolean("friendlyFire"));
// drawZoneOutline // loadout
warzone.setDrawZoneOutline(warzoneConfig.getBoolean("drawZoneOutline")); String loadoutStr = warzoneConfig.getString("loadout");
if(loadoutStr != null && !loadoutStr.equals("")) {
// autoAssignOnly String[] loadoutStrSplit = loadoutStr.split(";");
warzone.setAutoAssignOnly(warzoneConfig.getBoolean("autoAssignOnly")); warzone.getLoadout().clear();
for(String itemStr : loadoutStrSplit) {
// team cap if(itemStr != null && !itemStr.equals("")) {
warzone.setTeamCap(warzoneConfig.getInt("teamCap")); String[] itemStrSplit = itemStr.split(",");
ItemStack item = new ItemStack(Integer.parseInt(itemStrSplit[0]),
// score cap Integer.parseInt(itemStrSplit[1]));
warzone.setScoreCap(warzoneConfig.getInt("scoreCap")); warzone.getLoadout().put(Integer.parseInt(itemStrSplit[2]), item);
}
// blockHeads
warzone.setBlockHeads(warzoneConfig.getBoolean("blockHeads"));
// spawnStyle
String spawnStyle = warzoneConfig.getString("spawnStyle");
if(spawnStyle != null && !spawnStyle.equals("")){
spawnStyle = spawnStyle.toLowerCase();
if(spawnStyle.equals(TeamSpawnStyles.SMALL)) {
warzone.setSpawnStyle(spawnStyle);
} else if (spawnStyle.equals(TeamSpawnStyles.FLAT)){
warzone.setSpawnStyle(spawnStyle);
}
// default is already initialized to BIG (see Warzone)
}
// reward
String rewardStr = warzoneConfig.getString("reward");
if(rewardStr != null && !rewardStr.equals("")) {
String[] rewardStrSplit = rewardStr.split(";");
warzone.getReward().clear();
for(String itemStr : rewardStrSplit) {
if(itemStr != null && !itemStr.equals("")) {
String[] itemStrSplit = itemStr.split(",");
ItemStack item = new ItemStack(Integer.parseInt(itemStrSplit[0]),
Integer.parseInt(itemStrSplit[1]));
warzone.getReward().put(Integer.parseInt(itemStrSplit[2]), item);
} }
} }
}
// unbreakableZoneBlocks // life pool
warzone.setUnbreakableZoneBlocks(warzoneConfig.getBoolean("unbreakableZoneBlocks")); warzone.setLifePool(warzoneConfig.getInt("lifePool"));
// disabled // drawZoneOutline
warzone.setDisabled(warzoneConfig.getBoolean("disabled")); warzone.setDrawZoneOutline(warzoneConfig.getBoolean("drawZoneOutline"));
// defaultNoCreatures // autoAssignOnly
warzone.setNoCreatures(warzoneConfig.getBoolean("noCreatures")); warzone.setAutoAssignOnly(warzoneConfig.getBoolean("autoAssignOnly"));
// dropLootOnDeath // team cap
//warzone.setDropLootOnDeath(warzoneConfig.getBoolean("dropLootOnDeath")); warzone.setTeamCap(warzoneConfig.getInt("teamCap"));
// monuments // score cap
String monumentsStr = warzoneConfig.getString("monuments"); warzone.setScoreCap(warzoneConfig.getInt("scoreCap"));
if(monumentsStr != null && !monumentsStr.equals("")) {
String[] monumentsSplit = monumentsStr.split(";"); // blockHeads
warzone.getMonuments().clear(); warzone.setBlockHeads(warzoneConfig.getBoolean("blockHeads"));
for(String monumentStr : monumentsSplit) {
if(monumentStr != null && !monumentStr.equals("")){ // spawnStyle
String[] monumentStrSplit = monumentStr.split(","); String spawnStyle = warzoneConfig.getString("spawnStyle");
int monumentX = Integer.parseInt(monumentStrSplit[1]); if(spawnStyle != null && !spawnStyle.equals("")){
int monumentY = Integer.parseInt(monumentStrSplit[2]); spawnStyle = spawnStyle.toLowerCase();
int monumentZ = Integer.parseInt(monumentStrSplit[3]); if(spawnStyle.equals(TeamSpawnStyles.SMALL)) {
Monument monument = new Monument(monumentStrSplit[0], war, warzone, warzone.setSpawnStyle(spawnStyle);
new Location(world, monumentX, monumentY, monumentZ)); } else if (spawnStyle.equals(TeamSpawnStyles.FLAT)){
warzone.getMonuments().add(monument); warzone.setSpawnStyle(spawnStyle);
}
// default is already initialized to BIG (see Warzone)
}
// reward
String rewardStr = warzoneConfig.getString("reward");
if(rewardStr != null && !rewardStr.equals("")) {
String[] rewardStrSplit = rewardStr.split(";");
warzone.getReward().clear();
for(String itemStr : rewardStrSplit) {
if(itemStr != null && !itemStr.equals("")) {
String[] itemStrSplit = itemStr.split(",");
ItemStack item = new ItemStack(Integer.parseInt(itemStrSplit[0]),
Integer.parseInt(itemStrSplit[1]));
warzone.getReward().put(Integer.parseInt(itemStrSplit[2]), item);
}
} }
} }
}
// lobby // unbreakableZoneBlocks
String lobbyStr = warzoneConfig.getString("lobby"); warzone.setUnbreakableZoneBlocks(warzoneConfig.getBoolean("unbreakableZoneBlocks"));
warzoneConfig.close(); // disabled
warzone.setDisabled(warzoneConfig.getBoolean("disabled"));
if(loadBlocks && warzone.getNorthwest() != null && warzone.getSoutheast() != null) { // defaultNoCreatures
warzone.setNoCreatures(warzoneConfig.getBoolean("noCreatures"));
// zone blocks // dropLootOnDeath
VerticalVolume zoneVolume = VolumeMapper.loadVerticalVolume(warzone.getName(), warzone.getName(), war, warzone.getWorld()); //warzone.setDropLootOnDeath(warzoneConfig.getBoolean("dropLootOnDeath"));
warzone.setVolume(zoneVolume);
}
// monument blocks // monuments
for(Monument monument: warzone.getMonuments()) { String monumentsStr = warzoneConfig.getString("monuments");
monument.setVolume(VolumeMapper.loadVolume(monument.getName(),warzone.getName(), war, world)); if(monumentsStr != null && !monumentsStr.equals("")) {
} String[] monumentsSplit = monumentsStr.split(";");
warzone.getMonuments().clear();
// team spawn blocks for(String monumentStr : monumentsSplit) {
for(Team team : warzone.getTeams()) { if(monumentStr != null && !monumentStr.equals("")){
team.setSpawnVolume(VolumeMapper.loadVolume(team.getName(), warzone.getName(), war, world)); String[] monumentStrSplit = monumentStr.split(",");
if(team.getTeamFlag() != null) { int monumentX = Integer.parseInt(monumentStrSplit[1]);
team.setFlagVolume(VolumeMapper.loadVolume(team.getName()+"flag", warzone.getName(), war, world)); int monumentY = Integer.parseInt(monumentStrSplit[2]);
int monumentZ = Integer.parseInt(monumentStrSplit[3]);
Monument monument = new Monument(monumentStrSplit[0], war, warzone,
new Location(world, monumentX, monumentY, monumentZ));
warzone.getMonuments().add(monument);
}
}
} }
}
// lobby // lobby
BlockFace lobbyFace = null; String lobbyStr = warzoneConfig.getString("lobby");
if(lobbyStr != null && !lobbyStr.equals("")){
if(lobbyStr.equals("south")) { warzoneConfig.close();
lobbyFace = BlockFace.SOUTH;
} else if(lobbyStr.equals("east")) { if(loadBlocks && warzone.getNorthwest() != null && warzone.getSoutheast() != null) {
lobbyFace = BlockFace.EAST;
} else if(lobbyStr.equals("north")) { // zone blocks
lobbyFace = BlockFace.NORTH; VerticalVolume zoneVolume = VolumeMapper.loadVerticalVolume(warzone.getName(), warzone.getName(), war, warzone.getWorld());
} else if(lobbyStr.equals("west")) { warzone.setVolume(zoneVolume);
lobbyFace = BlockFace.WEST;
} }
Volume lobbyVolume = VolumeMapper.loadVolume("lobby", warzone.getName(), war, world);
ZoneLobby lobby = new ZoneLobby(war, warzone, lobbyFace, lobbyVolume); // monument blocks
warzone.setLobby(lobby); for(Monument monument: warzone.getMonuments()) {
monument.setVolume(VolumeMapper.loadVolume(monument.getName(),warzone.getName(), war, world));
}
// team spawn blocks
for(Team team : warzone.getTeams()) {
team.setSpawnVolume(VolumeMapper.loadVolume(team.getName(), warzone.getName(), war, world));
if(team.getTeamFlag() != null) {
team.setFlagVolume(VolumeMapper.loadVolume(team.getName()+"flag", warzone.getName(), war, world));
}
}
// lobby
BlockFace lobbyFace = null;
if(lobbyStr != null && !lobbyStr.equals("")){
if(lobbyStr.equals("south")) {
lobbyFace = BlockFace.SOUTH;
} else if(lobbyStr.equals("east")) {
lobbyFace = BlockFace.EAST;
} else if(lobbyStr.equals("north")) {
lobbyFace = BlockFace.NORTH;
} else if(lobbyStr.equals("west")) {
lobbyFace = BlockFace.WEST;
}
Volume lobbyVolume = VolumeMapper.loadVolume("lobby", warzone.getName(), war, world);
ZoneLobby lobby = new ZoneLobby(war, warzone, lobbyFace, lobbyVolume);
warzone.setLobby(lobby);
}
return warzone;
} }
return null;
return warzone;
} }
public static void save(War war, Warzone warzone, boolean saveAllBlocks) { public static void save(War war, Warzone warzone, boolean saveAllBlocks) {