mirror of
https://github.com/taoneill/war.git
synced 2024-11-23 18:55:28 +01:00
General cleanup (Removed unneeded code)
This commit is contained in:
parent
15d4497c5e
commit
6c0212d405
@ -26,29 +26,18 @@ import org.bukkit.plugin.java.JavaPlugin;
|
||||
|
||||
import com.nijiko.permissions.PermissionHandler;
|
||||
import com.nijikokun.bukkit.Permissions.Permissions;
|
||||
import com.tommytony.war.Monument;
|
||||
import com.tommytony.war.Team;
|
||||
import com.tommytony.war.TeamKind;
|
||||
import com.tommytony.war.TeamKinds;
|
||||
import com.tommytony.war.TeamSpawnStyles;
|
||||
import com.tommytony.war.WarHub;
|
||||
import com.tommytony.war.Warzone;
|
||||
import com.tommytony.war.ZoneLobby;
|
||||
import com.tommytony.war.ZoneSetter;
|
||||
import com.tommytony.war.mappers.VolumeMapper;
|
||||
import com.tommytony.war.mappers.WarMapper;
|
||||
import com.tommytony.war.mappers.WarzoneMapper;
|
||||
import com.tommytony.war.utils.ChatFixUtil;
|
||||
import com.tommytony.war.utils.InventoryStash;
|
||||
import com.tommytony.war.*;
|
||||
import com.tommytony.war.mappers.*;
|
||||
import com.tommytony.war.utils.*;
|
||||
|
||||
/**
|
||||
*
|
||||
*
|
||||
* @author tommytony
|
||||
*
|
||||
*/
|
||||
public class War extends JavaPlugin {
|
||||
public static PermissionHandler permissionHandler;
|
||||
|
||||
|
||||
public War(){
|
||||
super();
|
||||
}
|
||||
@ -59,7 +48,7 @@ public class War extends JavaPlugin {
|
||||
private Logger log;
|
||||
private PluginDescriptionFile desc = null;
|
||||
private boolean loaded = false;
|
||||
|
||||
|
||||
private List<Warzone> warzones;
|
||||
private final List<Warzone> incompleteZones = new ArrayList<Warzone>();
|
||||
private final List<String> zoneMakerNames = new ArrayList<String>();
|
||||
@ -80,28 +69,28 @@ public class War extends JavaPlugin {
|
||||
private final HashMap<Integer, ItemStack> defaultReward = new HashMap<Integer, ItemStack>();
|
||||
private boolean defaultUnbreakableZoneBlocks = false;
|
||||
private boolean defaultNoCreatures = false;
|
||||
|
||||
|
||||
private boolean pvpInZonesOnly = false;
|
||||
private boolean buildInZonesOnly = false;
|
||||
|
||||
|
||||
private WarHub warHub;
|
||||
|
||||
|
||||
|
||||
|
||||
public void onDisable() {
|
||||
unloadWar();
|
||||
}
|
||||
|
||||
|
||||
public void unloadWar() {
|
||||
setLoaded(false);
|
||||
for(Warzone warzone : warzones) {
|
||||
warzone.unload();
|
||||
}
|
||||
warzones.clear();
|
||||
|
||||
|
||||
if(warHub != null) {
|
||||
warHub.getVolume().resetBlocks();
|
||||
}
|
||||
|
||||
|
||||
Thread thread = new Thread(new Runnable()
|
||||
{
|
||||
public void run()
|
||||
@ -125,24 +114,24 @@ public class War extends JavaPlugin {
|
||||
});
|
||||
thread.setPriority(Thread.MIN_PRIORITY);
|
||||
thread.start();
|
||||
|
||||
|
||||
this.logInfo("Done. War v" + desc.getVersion() + " is off.");
|
||||
}
|
||||
|
||||
public void onEnable() {
|
||||
this.loadWar();
|
||||
}
|
||||
|
||||
|
||||
public void loadWar() {
|
||||
setLoaded(true);
|
||||
warzones = new ArrayList<Warzone>();
|
||||
desc = this.getDescription();
|
||||
this.log = this.getServer().getLogger();
|
||||
this.setupPermissions();
|
||||
|
||||
// Register hooks
|
||||
|
||||
// Register hooks
|
||||
PluginManager pm = getServer().getPluginManager();
|
||||
|
||||
|
||||
pm.registerEvent(Event.Type.PLAYER_QUIT, playerListener, Priority.Normal, this);
|
||||
pm.registerEvent(Event.Type.PLAYER_KICK, playerListener, Priority.Normal, this);
|
||||
pm.registerEvent(Event.Type.PLAYER_MOVE, playerListener, Priority.Normal, this);
|
||||
@ -151,19 +140,19 @@ public class War extends JavaPlugin {
|
||||
pm.registerEvent(Event.Type.PLAYER_DROP_ITEM, playerListener, Priority.Normal, this);
|
||||
pm.registerEvent(Event.Type.PLAYER_COMMAND_PREPROCESS, playerListener, Priority.Normal, this);
|
||||
pm.registerEvent(Event.Type.PLAYER_INTERACT, playerListener, Priority.Normal, this);
|
||||
|
||||
|
||||
pm.registerEvent(Event.Type.ENTITY_EXPLODE, entityListener, Priority.Normal, this);
|
||||
//pm.registerEvent(Event.Type.ENTITY_DEATH, entityListener, Priority.Normal, this);
|
||||
pm.registerEvent(Event.Type.ENTITY_DAMAGE, entityListener, Priority.Normal, this);
|
||||
pm.registerEvent(Event.Type.ENTITY_COMBUST, entityListener, Priority.Normal, this);
|
||||
pm.registerEvent(Event.Type.CREATURE_SPAWN, entityListener, Priority.Normal, this);
|
||||
pm.registerEvent(Event.Type.ENTITY_REGAIN_HEALTH, entityListener, Priority.Normal, this);
|
||||
|
||||
|
||||
pm.registerEvent(Event.Type.BLOCK_PLACE, blockListener, Priority.Normal, this);
|
||||
pm.registerEvent(Event.Type.BLOCK_BREAK, blockListener, Priority.Normal, this);
|
||||
|
||||
|
||||
//pm.registerEvent(Event.Type.CHUNK_UNLOADED, blockListener, Priority.Normal, this);
|
||||
|
||||
|
||||
// Load files from disk or create them (using these defaults)
|
||||
this.defaultLoadout.put(0, new ItemStack(Material.STONE_SWORD, 1, (byte) 8));
|
||||
this.defaultLoadout.put(1, new ItemStack(Material.BOW, 1, (byte) 8));
|
||||
@ -200,7 +189,7 @@ public class War extends JavaPlugin {
|
||||
} else {
|
||||
arguments = args;
|
||||
}
|
||||
|
||||
|
||||
// Player commands: /warzones, /warzone, /teams, /join, /leave
|
||||
if(command.equals("zones") || command.equals("warzones")){
|
||||
performZones(player);
|
||||
@ -216,11 +205,11 @@ public class War extends JavaPlugin {
|
||||
performTeam(player, arguments);
|
||||
} else if(command.equals("warhub")) {
|
||||
performWarhub(player);
|
||||
} else if(this.isZoneMaker(player)) {
|
||||
} else if(this.isZoneMaker(player)) {
|
||||
// Mod commands : /nextbattle
|
||||
if(command.equals("nextbattle")) {
|
||||
performNextBattle(player);
|
||||
}
|
||||
}
|
||||
// Warzone maker commands: /setzone, /savezone, /setteam, /setmonument, /resetzone
|
||||
else if(command.equals("setzone")) {
|
||||
performSetZone(player, arguments);
|
||||
@ -290,7 +279,7 @@ public class War extends JavaPlugin {
|
||||
loadout.put(i, stack);
|
||||
i++;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
if(inv.getBoots() != null && inv.getBoots().getType() != Material.AIR) {
|
||||
loadout.put(100, inv.getBoots());
|
||||
@ -349,7 +338,7 @@ public class War extends JavaPlugin {
|
||||
}
|
||||
msg(player, "You are now impersonating a regular player. Type /zonemaker again to toggle back to war maker mode.");
|
||||
}
|
||||
|
||||
|
||||
WarMapper.save(this);
|
||||
}
|
||||
}
|
||||
@ -380,7 +369,7 @@ public class War extends JavaPlugin {
|
||||
zone.getLobby().initialize();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
this.msg(player, "War hub removed.");
|
||||
} else {
|
||||
this.badMsg(player, "No War hub to delete.");
|
||||
@ -414,7 +403,7 @@ public class War extends JavaPlugin {
|
||||
}
|
||||
|
||||
public void performDeleteMonument(Player player, String[] arguments) {
|
||||
if(arguments.length < 1 || (!this.inAnyWarzone(player.getLocation())
|
||||
if(arguments.length < 1 || (!this.inAnyWarzone(player.getLocation())
|
||||
&& !this.inAnyWarzoneLobby(player.getLocation()))) {
|
||||
this.badMsg(player, "Usage: /deletemonument <name>." +
|
||||
" Deletes the monument. " +
|
||||
@ -441,7 +430,7 @@ public class War extends JavaPlugin {
|
||||
}
|
||||
|
||||
public void performSetMonument(Player player, String[] arguments) {
|
||||
if(!this.inAnyWarzone(player.getLocation()) || arguments.length < 1 || arguments.length > 1
|
||||
if(!this.inAnyWarzone(player.getLocation()) || arguments.length < 1 || arguments.length > 1
|
||||
|| (arguments.length == 1 && this.warzone(player.getLocation()) != null
|
||||
&& arguments[0].equals(this.warzone(player.getLocation()).getName()))) {
|
||||
this.badMsg(player, "Usage: /setmonument <name>. Creates or moves a monument. Monument can't have same name as zone. Must be in warzone.");
|
||||
@ -465,7 +454,7 @@ public class War extends JavaPlugin {
|
||||
}
|
||||
|
||||
public void performDeleteTeam(Player player, String[] arguments) {
|
||||
if(arguments.length < 1 || (!this.inAnyWarzone(player.getLocation())
|
||||
if(arguments.length < 1 || (!this.inAnyWarzone(player.getLocation())
|
||||
&& !this.inAnyWarzoneLobby(player.getLocation()))) {
|
||||
this.badMsg(player, "Usage: /deleteteam <team-name/color>." +
|
||||
" Deletes the team and its spawn. " +
|
||||
@ -482,7 +471,7 @@ public class War extends JavaPlugin {
|
||||
Team team = warzone.getTeamByKind(TeamKinds.teamKindFromString(name));
|
||||
if(team != null) {
|
||||
if(team.getFlagVolume() != null) team.getFlagVolume().resetBlocks();
|
||||
team.getSpawnVolume().resetBlocks();
|
||||
team.getSpawnVolume().resetBlocks();
|
||||
warzone.getTeams().remove(team);
|
||||
if(warzone.getLobby() != null) {
|
||||
warzone.getLobby().getVolume().resetBlocks();
|
||||
@ -499,23 +488,23 @@ public class War extends JavaPlugin {
|
||||
}
|
||||
|
||||
public void performSetTeamFlag(Player player, String[] arguments) {
|
||||
if(arguments.length < 1 || !this.inAnyWarzone(player.getLocation())
|
||||
if(arguments.length < 1 || !this.inAnyWarzone(player.getLocation())
|
||||
|| (arguments.length > 0 && TeamKinds.teamKindFromString(arguments[0]) == null)) {
|
||||
this.badMsg(player, "Usage: /setteamflag <team-name/color>, e.g. /setteamflag diamond. " +
|
||||
"Sets the team flag post to the current location. " +
|
||||
"Must be in a warzone (try /zones and /zone). ");
|
||||
} else {
|
||||
TeamKind kind = TeamKinds.teamKindFromString(arguments[0]);
|
||||
TeamKind kind = TeamKinds.teamKindFromString(arguments[0]);
|
||||
Warzone warzone = this.warzone(player.getLocation());
|
||||
Team team = warzone.getTeamByKind(kind);
|
||||
if(team == null) {
|
||||
// no such team yet
|
||||
// no such team yet
|
||||
this.badMsg(player, "Place the team spawn first.");
|
||||
} else if (team.getFlagVolume() == null){
|
||||
// new team flag
|
||||
team.setTeamFlag(player.getLocation());
|
||||
Location playerLoc = player.getLocation();
|
||||
player.teleport(new Location(playerLoc.getWorld(),
|
||||
player.teleport(new Location(playerLoc.getWorld(),
|
||||
playerLoc.getBlockX()+1, playerLoc.getBlockY(), playerLoc.getBlockZ()));
|
||||
this.msg(player, "Team " + team.getName() + " flag added here.");
|
||||
WarzoneMapper.save(this, warzone, false);
|
||||
@ -524,7 +513,7 @@ public class War extends JavaPlugin {
|
||||
team.getFlagVolume().resetBlocks();
|
||||
team.setTeamFlag(player.getLocation());
|
||||
Location playerLoc = player.getLocation();
|
||||
player.teleport(new Location(playerLoc.getWorld(),
|
||||
player.teleport(new Location(playerLoc.getWorld(),
|
||||
playerLoc.getBlockX()+1, playerLoc.getBlockY(), playerLoc.getBlockZ()+1));
|
||||
this.msg(player, "Team " + team.getName() + " flag moved.");
|
||||
WarzoneMapper.save(this, warzone, false);
|
||||
@ -533,13 +522,13 @@ public class War extends JavaPlugin {
|
||||
}
|
||||
|
||||
public void performSetTeam(Player player, String[] arguments) {
|
||||
if(arguments.length < 1 || !this.inAnyWarzone(player.getLocation())
|
||||
if(arguments.length < 1 || !this.inAnyWarzone(player.getLocation())
|
||||
|| (arguments.length > 0 && TeamKinds.teamKindFromString(arguments[0]) == null)) {
|
||||
this.badMsg(player, "Usage: /setteam <team-kind/color>, e.g. /setteam red." +
|
||||
"Sets the team spawn to the current location. " +
|
||||
"Must be in a warzone (try /zones and /zone). ");
|
||||
} else {
|
||||
TeamKind teamKind = TeamKinds.teamKindFromString(arguments[0]);
|
||||
TeamKind teamKind = TeamKinds.teamKindFromString(arguments[0]);
|
||||
Warzone warzone = this.warzone(player.getLocation());
|
||||
Team existingTeam = warzone.getTeamByKind(teamKind);
|
||||
if(existingTeam != null) {
|
||||
@ -560,7 +549,7 @@ public class War extends JavaPlugin {
|
||||
newTeam.setTeamSpawn(player.getLocation());
|
||||
this.msg(player, "Team " + newTeam.getName() + " created with spawn here.");
|
||||
}
|
||||
|
||||
|
||||
WarzoneMapper.save(this, warzone, false);
|
||||
}
|
||||
}
|
||||
@ -637,7 +626,7 @@ public class War extends JavaPlugin {
|
||||
team.resetPoints();
|
||||
team.getPlayers().clear();
|
||||
}
|
||||
|
||||
|
||||
Warzone resetWarzone = null;
|
||||
this.msg(player, "Reloading warzone " + warzone.getName() + ".");
|
||||
if(arguments.length == 1 && (arguments[0].equals("hard") || arguments[0].equals("h"))) {
|
||||
@ -656,7 +645,7 @@ public class War extends JavaPlugin {
|
||||
lobby.getVolume().resetBlocksAsJob();
|
||||
}
|
||||
warzone.initializeZoneAsJob();
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -683,7 +672,7 @@ public class War extends JavaPlugin {
|
||||
}
|
||||
warzone.initializeZone(); // bring back team spawns etc
|
||||
this.msg(player, "Warzone config saved. Zone reset.");
|
||||
|
||||
|
||||
if(warHub != null) { // maybe the zone was disabled/enabled
|
||||
warHub.getVolume().resetBlocks();
|
||||
warHub.initialize();
|
||||
@ -717,13 +706,13 @@ public class War extends JavaPlugin {
|
||||
lobby.getVolume().resetBlocks();
|
||||
}
|
||||
warzone.initializeZone(); // bring back team spawns etc
|
||||
|
||||
|
||||
if(warHub != null) { // maybe the zone was disabled/enabled
|
||||
warHub.getVolume().resetBlocks();
|
||||
warHub.initialize();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
this.msg(player, "Warzone " + warzone.getName() + " initial state changed. Saved " + savedBlocks + " blocks.");
|
||||
}
|
||||
}
|
||||
@ -735,14 +724,14 @@ public class War extends JavaPlugin {
|
||||
if(arguments.length < 1 || arguments.length > 1) {
|
||||
this.badMsg(player, usageStr);
|
||||
} else if (this.inAnyWarzone(player.getLocation()) || this.inAnyWarzoneLobby(player.getLocation())){
|
||||
// Inside a warzone: use the classic n/s/e/w mode
|
||||
// Inside a warzone: use the classic n/s/e/w mode
|
||||
if(!arguments[0].equals("north") && !arguments[0].equals("n")
|
||||
&& !arguments[0].equals("east") && !arguments[0].equals("e")
|
||||
&& !arguments[0].equals("south") && !arguments[0].equals("s")
|
||||
&& !arguments[0].equals("west") && !arguments[0].equals("w")){
|
||||
this.badMsg(player, usageStr);
|
||||
return;
|
||||
}
|
||||
}
|
||||
Warzone warzone = this.warzone(player.getLocation());
|
||||
ZoneLobby lobby = this.lobby(player.getLocation());
|
||||
if(warzone == null && lobby != null) {
|
||||
@ -764,7 +753,7 @@ public class War extends JavaPlugin {
|
||||
} else if(arguments[0].equals("west") || arguments[0].equals("w")) {
|
||||
wall = BlockFace.WEST;
|
||||
wallStr = "west";
|
||||
}
|
||||
}
|
||||
if(lobby != null) {
|
||||
// reset existing lobby
|
||||
lobby.getVolume().resetBlocks();
|
||||
@ -809,12 +798,12 @@ public class War extends JavaPlugin {
|
||||
this.msg(player, "Warzone lobby moved to your location.");
|
||||
}
|
||||
WarzoneMapper.save(this, warzone, false);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void performSetZone(Player player, String[] arguments) {
|
||||
if(arguments.length < 2 || arguments.length > 2
|
||||
if(arguments.length < 2 || arguments.length > 2
|
||||
|| (arguments.length == 2 && (!arguments[1].equals("southeast") && !arguments[1].equals("northwest")
|
||||
&& !arguments[1].equals("se") && !arguments[1].equals("nw")
|
||||
&& !arguments[1].equals("corner1") && !arguments[1].equals("corner2")
|
||||
@ -829,7 +818,7 @@ public class War extends JavaPlugin {
|
||||
"=<Wand Cuboid mode>= /setzone <warzone-name> wand (gives you a wooden sword to right and left click, drop to disable). " +
|
||||
"=<Wandless Cuboid mode>= /setzone <warzone-name> <'corner1'/'corner2'/'c1'/'c2'/'pos1'/'pos2'> (block where you're standing). " +
|
||||
"Set one corner, then the next. Defines the outline of the warzone, which will be reset at the start of every battle. " +
|
||||
"Saves the zone blocks if the outline is valid.");
|
||||
"Saves the zone blocks if the outline is valid.");
|
||||
}
|
||||
} else {
|
||||
ZoneSetter setter = new ZoneSetter(this, player, arguments[0]);
|
||||
@ -909,14 +898,14 @@ public class War extends JavaPlugin {
|
||||
" Teams are warzone specific." +
|
||||
" You must be inside a warzone or zone lobby to join a team." +
|
||||
" Use as an alternative to walking through the team gate.");
|
||||
} else {
|
||||
} else {
|
||||
// drop from old team if any
|
||||
Team previousTeam = this.getPlayerTeam(player.getName());
|
||||
if(previousTeam != null) {
|
||||
Warzone zone = this.getPlayerTeamWarzone(player.getName());
|
||||
if(!previousTeam.removePlayer(player.getName())){
|
||||
logWarn("Could not remove player " + player.getName() + " from team " + previousTeam.getName());
|
||||
}
|
||||
}
|
||||
if(zone.isFlagThief(player.getName())) {
|
||||
Team victim = zone.getVictimTeamForThief(player.getName());
|
||||
victim.getFlagVolume().resetBlocks();
|
||||
@ -928,7 +917,7 @@ public class War extends JavaPlugin {
|
||||
}
|
||||
previousTeam.resetSign();
|
||||
}
|
||||
|
||||
|
||||
// join new team
|
||||
String name = arguments[0];
|
||||
TeamKind kind = TeamKinds.teamKindFromString(arguments[0]);
|
||||
@ -997,7 +986,7 @@ public class War extends JavaPlugin {
|
||||
if(playerTeam != null) {
|
||||
Warzone playerWarzone = getPlayerTeamWarzone(player.getName());
|
||||
playerWarzone.handlePlayerLeave(player, warzone.getTeleport(), true);
|
||||
} else {
|
||||
} else {
|
||||
player.teleport(warzone.getTeleport());
|
||||
}
|
||||
warped = true;
|
||||
@ -1016,7 +1005,7 @@ public class War extends JavaPlugin {
|
||||
warzonesMessage += "none.";
|
||||
}
|
||||
for(Warzone warzone : this.getWarzones()) {
|
||||
|
||||
|
||||
warzonesMessage += warzone.getName() + " ("
|
||||
+ warzone.getTeams().size() + " teams, ";
|
||||
int playerTotal = 0;
|
||||
@ -1107,7 +1096,7 @@ public class War extends JavaPlugin {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
private boolean updateFromNamedParams(Player player, String[] arguments) {
|
||||
try {
|
||||
Map<String,String> namedParams = new HashMap<String,String>();
|
||||
@ -1119,7 +1108,7 @@ public class War extends JavaPlugin {
|
||||
}
|
||||
if(namedParams.containsKey("lifepool")){
|
||||
setDefaultLifepool(Integer.parseInt(namedParams.get("lifepool")));
|
||||
}
|
||||
}
|
||||
if(namedParams.containsKey("monumentheal")){
|
||||
setDefaultMonumentHeal(Integer.parseInt(namedParams.get("monumentheal")));
|
||||
}
|
||||
@ -1132,19 +1121,19 @@ public class War extends JavaPlugin {
|
||||
if(namedParams.containsKey("ff")){
|
||||
String onOff = namedParams.get("ff");
|
||||
setDefaultFriendlyFire(onOff.equals("on"));
|
||||
}
|
||||
}
|
||||
if(namedParams.containsKey("autoassign")){
|
||||
String onOff = namedParams.get("autoassign");
|
||||
setDefaultAutoAssignOnly(onOff.equals("on") || onOff.equals("true"));
|
||||
}
|
||||
}
|
||||
if(namedParams.containsKey("outline")){
|
||||
String onOff = namedParams.get("outline");
|
||||
setDefaultDrawZoneOutline(onOff.equals("on") || onOff.equals("true"));
|
||||
}
|
||||
}
|
||||
if(namedParams.containsKey("pvpinzonesonly")){
|
||||
String onOff = namedParams.get("pvpinzonesonly");
|
||||
setPvpInZonesOnly(onOff.equals("on") || onOff.equals("true"));
|
||||
}
|
||||
}
|
||||
if(namedParams.containsKey("blockheads")){
|
||||
String onOff = namedParams.get("blockheads");
|
||||
setDefaultBlockHeads(onOff.equals("on") || onOff.equals("true"));
|
||||
@ -1196,7 +1185,7 @@ public class War extends JavaPlugin {
|
||||
private void setZoneRallyPoint(String warzoneName, Player player) {
|
||||
Warzone zone = findWarzone(warzoneName);
|
||||
if(zone == null) {
|
||||
badMsg(player, "Can't set rally point. No such warzone.");
|
||||
badMsg(player, "Can't set rally point. No such warzone.");
|
||||
} else {
|
||||
zone.setRallyPoint(player.getLocation());
|
||||
WarzoneMapper.save(this, zone, false);
|
||||
@ -1210,19 +1199,19 @@ public class War extends JavaPlugin {
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
|
||||
public Warzone getPlayerTeamWarzone(String playerName) {
|
||||
for(Warzone warzone : warzones) {
|
||||
Team team = warzone.getPlayerTeam(playerName);
|
||||
if(team != null) return warzone;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
public Logger getLogger() {
|
||||
return log;
|
||||
}
|
||||
|
||||
|
||||
public Warzone warzone(Location location) {
|
||||
for(Warzone warzone : warzones) {
|
||||
if(location.getWorld().getName().equals(warzone.getWorld().getName())
|
||||
@ -1235,13 +1224,13 @@ public class War extends JavaPlugin {
|
||||
Block locBlock = location.getWorld().getBlockAt(location.getBlockX(), location.getBlockY(), location.getBlockZ());
|
||||
Warzone currentZone = warzone(location);
|
||||
if(currentZone == null) {
|
||||
return false;
|
||||
return false;
|
||||
} else if (currentZone.getVolume().isWallBlock(locBlock)) {
|
||||
return false; // wall block doesnt count. this lets people in at the lobby side wall because wall gates overlap with the zone.
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
public boolean inWarzone(String warzoneName, Location location) {
|
||||
Warzone currentZone = warzone(location);
|
||||
if(currentZone == null) {
|
||||
@ -1259,32 +1248,32 @@ public class War extends JavaPlugin {
|
||||
public List<Warzone> getWarzones() {
|
||||
return warzones;
|
||||
}
|
||||
|
||||
|
||||
public void msg(Player player, String str) {
|
||||
String out = ChatColor.GRAY + "War> " + ChatColor.WHITE + colorTeams(str, ChatColor.WHITE) + " ";
|
||||
ChatFixUtil.sendMessage(player, out);
|
||||
}
|
||||
|
||||
|
||||
public void badMsg(Player player, String str) {
|
||||
String out = ChatColor.GRAY + "War> " + ChatColor.RED + colorTeams(str, ChatColor.RED) + " ";
|
||||
ChatFixUtil.sendMessage(player, out);
|
||||
}
|
||||
|
||||
|
||||
private String colorTeams(String str, ChatColor msgColor) {
|
||||
for(TeamKind kind : TeamKinds.getTeamkinds()) {
|
||||
str = str.replaceAll(" " + kind.getDefaultName(), " " + kind.getColor() + kind.getDefaultName() + msgColor);
|
||||
}
|
||||
return str;
|
||||
}
|
||||
|
||||
|
||||
public void logInfo(String str) {
|
||||
this.getLogger().log(Level.INFO, "War> " + str);
|
||||
}
|
||||
|
||||
|
||||
public void logWarn(String str) {
|
||||
this.getLogger().log(Level.WARNING, "War> " + str);
|
||||
}
|
||||
|
||||
|
||||
// the only way to find a zone that has only one corner
|
||||
public Warzone findWarzone(String warzoneName) {
|
||||
for(Warzone warzone : warzones) {
|
||||
@ -1292,14 +1281,14 @@ public class War extends JavaPlugin {
|
||||
return warzone;
|
||||
}
|
||||
}
|
||||
for(Warzone warzone : incompleteZones) {
|
||||
for(Warzone warzone : incompleteZones) {
|
||||
if(warzone.getName().equals(warzoneName)) {
|
||||
return warzone;
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
|
||||
public Warzone matchWarzone(String warzoneSubString) {
|
||||
for(Warzone warzone : warzones) {
|
||||
if(warzone.getName().toLowerCase().startsWith(warzoneSubString.toLowerCase())) {
|
||||
@ -1314,7 +1303,7 @@ public class War extends JavaPlugin {
|
||||
String alreadyHaveWand = wandBearers.get(player.getName());
|
||||
if(player.getInventory().first(Material.WOOD_SWORD) != -1) {
|
||||
if(zoneName.equals(alreadyHaveWand)) {
|
||||
this.badMsg(player, "You already have a wand for zone " + alreadyHaveWand + ". Drop the wooden sword first.");
|
||||
this.badMsg(player, "You already have a wand for zone " + alreadyHaveWand + ". Drop the wooden sword first.");
|
||||
} else {
|
||||
// new zone, already have sword
|
||||
wandBearers.remove(player.getName());
|
||||
@ -1327,7 +1316,7 @@ public class War extends JavaPlugin {
|
||||
// same zone, give him a new sword
|
||||
player.getInventory().addItem(new ItemStack(Material.WOOD_SWORD, 1, (byte) 8));
|
||||
this.msg(player, "Here's a new sword for zone " + zoneName + ".");
|
||||
}
|
||||
}
|
||||
}
|
||||
} else {
|
||||
if(player.getInventory().firstEmpty() == -1) {
|
||||
@ -1336,22 +1325,22 @@ public class War extends JavaPlugin {
|
||||
wandBearers.put(player.getName(), zoneName);
|
||||
player.getInventory().addItem(new ItemStack(Material.WOOD_SWORD, 1, (byte) 8));
|
||||
//player.getWorld().dropItem(player.getLocation(), new ItemStack(Material.WOOD_SWORD));
|
||||
this.msg(player, "You now have a wand for zone " + zoneName + ". Left-click with wodden sword for corner 1. Right-click for corner 2.");
|
||||
this.msg(player, "You now have a wand for zone " + zoneName + ". Left-click with wodden sword for corner 1. Right-click for corner 2.");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public boolean isWandBearer(Player player) {
|
||||
return wandBearers.containsKey(player.getName());
|
||||
}
|
||||
|
||||
|
||||
public String getWandBearerZone(Player player) {
|
||||
if(isWandBearer(player)) {
|
||||
return wandBearers.get(player.getName());
|
||||
}
|
||||
return "";
|
||||
}
|
||||
|
||||
|
||||
public void removeWandBearer(Player player) {
|
||||
if(wandBearers.containsKey(player.getName())){
|
||||
wandBearers.remove(player.getName());
|
||||
@ -1377,7 +1366,7 @@ public class War extends JavaPlugin {
|
||||
public int getDefaultMonumentHeal() {
|
||||
return defaultMonumentHeal;
|
||||
}
|
||||
|
||||
|
||||
public void setDefaultFriendlyFire(boolean defaultFriendlyFire) {
|
||||
this.defaultFriendlyFire = defaultFriendlyFire;
|
||||
}
|
||||
@ -1400,9 +1389,9 @@ public class War extends JavaPlugin {
|
||||
public List<String> getZoneMakerNames() {
|
||||
return zoneMakerNames;
|
||||
}
|
||||
|
||||
|
||||
public boolean canPlayWar(Player player) {
|
||||
if(War.permissionHandler != null
|
||||
if(War.permissionHandler != null
|
||||
&& (War.permissionHandler.has(player, "war.player")
|
||||
|| War.permissionHandler.has(player, "War.player"))) {
|
||||
return true;
|
||||
@ -1413,9 +1402,9 @@ public class War extends JavaPlugin {
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
public boolean canWarp(Player player) {
|
||||
if(War.permissionHandler != null
|
||||
if(War.permissionHandler != null
|
||||
&& (War.permissionHandler.has(player, "war.warp")
|
||||
|| War.permissionHandler.has(player, "War.warp"))) {
|
||||
return true;
|
||||
@ -1426,10 +1415,10 @@ public class War extends JavaPlugin {
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
public boolean canBuildOutsideZone(Player player) {
|
||||
if(isBuildInZonesOnly()) {
|
||||
if(War.permissionHandler != null
|
||||
if(War.permissionHandler != null
|
||||
&& (War.permissionHandler.has(player, "war.build")
|
||||
|| War.permissionHandler.has(player, "War.build"))) {
|
||||
return true;
|
||||
@ -1440,8 +1429,7 @@ public class War extends JavaPlugin {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
@SuppressWarnings("static-access")
|
||||
|
||||
public boolean isZoneMaker(Player player) {
|
||||
boolean isPlayerImpersonator = false;
|
||||
for(String disguised : zoneMakersImpersonatingPlayers) {
|
||||
@ -1451,13 +1439,13 @@ public class War extends JavaPlugin {
|
||||
for(String zoneMaker : zoneMakerNames) {
|
||||
if(zoneMaker.equals(player.getName())) return true;
|
||||
}
|
||||
if(War.permissionHandler != null
|
||||
if(War.permissionHandler != null
|
||||
&& (War.permissionHandler.has(player, "war.*")
|
||||
|| War.permissionHandler.has(player, "War.*"))) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
return false;
|
||||
}
|
||||
|
||||
public boolean getDefaultDrawZoneOutline() {
|
||||
@ -1465,7 +1453,7 @@ public class War extends JavaPlugin {
|
||||
}
|
||||
|
||||
public boolean getDefaultAutoAssignOnly() {
|
||||
|
||||
|
||||
return defaultAutoAssignOnly;
|
||||
}
|
||||
|
||||
@ -1483,9 +1471,9 @@ public class War extends JavaPlugin {
|
||||
|
||||
public ZoneLobby lobby(Location location) {
|
||||
for(Warzone warzone : warzones) {
|
||||
if(warzone.getLobby() != null
|
||||
&& warzone.getLobby().getVolume() != null
|
||||
&& warzone.getLobby().getVolume().contains(location))
|
||||
if(warzone.getLobby() != null
|
||||
&& warzone.getLobby().getVolume() != null
|
||||
&& warzone.getLobby().getVolume().contains(location))
|
||||
return warzone.getLobby();
|
||||
}
|
||||
return null;
|
||||
@ -1497,7 +1485,7 @@ public class War extends JavaPlugin {
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
public boolean inWarzoneLobby(String warzoneName, Location location) {
|
||||
ZoneLobby currentLobby = lobby(location);
|
||||
if(currentLobby == null) {
|
||||
@ -1543,12 +1531,12 @@ public class War extends JavaPlugin {
|
||||
public List<String> getZoneMakersImpersonatingPlayers() {
|
||||
return zoneMakersImpersonatingPlayers;
|
||||
}
|
||||
|
||||
|
||||
public void setupPermissions() {
|
||||
Plugin permissionsPlugin = this.getServer().getPluginManager().getPlugin("Permissions");
|
||||
if(this.permissionHandler == null) {
|
||||
if(War.permissionHandler == null) {
|
||||
if(permissionsPlugin != null) {
|
||||
this.permissionHandler = ((Permissions) permissionsPlugin).getHandler();
|
||||
War.permissionHandler = ((Permissions) permissionsPlugin).getHandler();
|
||||
} else {
|
||||
logInfo("Permissions system not enabled. Defaulting to regular War config.");
|
||||
}
|
||||
@ -1630,5 +1618,4 @@ public class War extends JavaPlugin {
|
||||
public boolean isLoaded() {
|
||||
return loaded;
|
||||
}
|
||||
|
||||
}
|
@ -29,7 +29,7 @@ import com.tommytony.war.ZoneSetter;
|
||||
|
||||
|
||||
/**
|
||||
*
|
||||
*
|
||||
* @author tommytony
|
||||
*
|
||||
*/
|
||||
@ -37,7 +37,7 @@ public class WarPlayerListener extends PlayerListener {
|
||||
|
||||
private final War war;
|
||||
private Random random = null;
|
||||
|
||||
|
||||
|
||||
public WarPlayerListener(War war) {
|
||||
this.war = war;
|
||||
@ -66,25 +66,25 @@ public class WarPlayerListener extends PlayerListener {
|
||||
Team team = war.getPlayerTeam(player.getName());
|
||||
if(team != null) {
|
||||
Warzone zone = war.getPlayerTeamWarzone(player.getName());
|
||||
|
||||
|
||||
if(zone.isFlagThief(player.getName())) {
|
||||
// a flag thief can't drop his flag
|
||||
war.badMsg(player, "Can't drop items while stealing flag. What are you doing?! Run!");
|
||||
event.setCancelled(true);
|
||||
|
||||
|
||||
} else {
|
||||
Item item = event.getItemDrop();
|
||||
if(item != null) {
|
||||
ItemStack itemStack = item.getItemStack();
|
||||
if(itemStack != null
|
||||
&& itemStack.getType() == team.getKind().getMaterial()
|
||||
if(itemStack != null
|
||||
&& itemStack.getType() == team.getKind().getMaterial()
|
||||
&& itemStack.getData().getData() == team.getKind().getData()) {
|
||||
// Can't drop your team's kind block
|
||||
war.badMsg(player, "Can't drop " + team.getName() + " block blocks.");
|
||||
event.setCancelled(true);
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
if(zone.isNearWall(player.getLocation()) && itemStack != null) {
|
||||
war.badMsg(player, "Can't drop items near the zone border!");
|
||||
event.setCancelled(true);
|
||||
@ -110,7 +110,7 @@ public class WarPlayerListener extends PlayerListener {
|
||||
Team team = war.getPlayerTeam(player.getName());
|
||||
if(team != null) {
|
||||
Warzone zone = war.getPlayerTeamWarzone(player.getName());
|
||||
|
||||
|
||||
if(zone.isFlagThief(player.getName())) {
|
||||
// a flag thief can't pick up anything
|
||||
event.setCancelled(true);
|
||||
@ -133,7 +133,7 @@ public class WarPlayerListener extends PlayerListener {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public void onInventoryOpen(PlayerInventoryEvent event) {
|
||||
if(war.isLoaded()) {
|
||||
Player player = event.getPlayer();
|
||||
@ -152,7 +152,7 @@ public class WarPlayerListener extends PlayerListener {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public void onPlayerCommandPreprocess(PlayerCommandPreprocessEvent event) {
|
||||
if(war.isLoaded()) {
|
||||
Player player = event.getPlayer();
|
||||
@ -177,7 +177,7 @@ public class WarPlayerListener extends PlayerListener {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public void onPlayerKick(PlayerKickEvent event) {
|
||||
if(war.isLoaded()) {
|
||||
Player player = event.getPlayer();
|
||||
@ -186,7 +186,7 @@ public class WarPlayerListener extends PlayerListener {
|
||||
boolean inWarzone = war.inAnyWarzone(player.getLocation());
|
||||
boolean inLobby = war.inAnyWarzone(player.getLocation());
|
||||
boolean inWarhub = false;
|
||||
if(war.getWarHub() != null && war.getWarHub().getVolume().contains(player.getLocation())) {
|
||||
if(war.getWarHub() != null && war.getWarHub().getVolume().contains(player.getLocation())) {
|
||||
inWarhub = true;
|
||||
}
|
||||
if(inWarzone || inLobby || inWarhub) {
|
||||
@ -196,7 +196,7 @@ public class WarPlayerListener extends PlayerListener {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public void onPlayerInteract(PlayerInteractEvent event) {
|
||||
if(war.isLoaded()) {
|
||||
Player player = event.getPlayer();
|
||||
@ -215,7 +215,7 @@ public class WarPlayerListener extends PlayerListener {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public void onPlayerMove(PlayerMoveEvent event) {
|
||||
if(war.isLoaded()) {
|
||||
Player player = event.getPlayer();
|
||||
@ -226,7 +226,7 @@ public class WarPlayerListener extends PlayerListener {
|
||||
locLobby = war.lobby(playerLoc);
|
||||
boolean canPlay = war.canPlayWar(player);
|
||||
boolean isMaker = war.isZoneMaker(player);
|
||||
|
||||
|
||||
// Zone walls
|
||||
Team currentTeam = war.getPlayerTeam(player.getName());
|
||||
Warzone playerWarzone = war.getPlayerTeamWarzone(player.getName()); // this uses the teams, so it asks: get the player's team's warzone
|
||||
@ -240,7 +240,7 @@ public class WarPlayerListener extends PlayerListener {
|
||||
protecting = nearbyZone.protectZoneWallAgainstPlayer(player);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
if(!protecting) {
|
||||
// zone makers still need to delete their walls
|
||||
// make sure to delete any wall guards as you leave
|
||||
@ -248,10 +248,10 @@ public class WarPlayerListener extends PlayerListener {
|
||||
zone.dropZoneWallGuardIfAny(player);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// Warzone lobby gates
|
||||
if(locLobby != null) {
|
||||
Warzone zone = locLobby.getZone();
|
||||
Warzone zone = locLobby.getZone();
|
||||
Team oldTeam = war.getPlayerTeam(player.getName());
|
||||
boolean isAutoAssignGate = false;
|
||||
if(oldTeam == null && canPlay) { // trying to counter spammy player move
|
||||
@ -266,8 +266,8 @@ public class WarPlayerListener extends PlayerListener {
|
||||
noOfPlayers += t.getPlayers().size();
|
||||
}
|
||||
if(noOfPlayers < zone.getTeams().size() * zone.getTeamCap()) {
|
||||
Team team = zone.autoAssign(player);
|
||||
|
||||
zone.autoAssign(player);
|
||||
|
||||
if(war.getWarHub() != null) {
|
||||
war.getWarHub().resetZoneSign(zone);
|
||||
}
|
||||
@ -279,7 +279,7 @@ public class WarPlayerListener extends PlayerListener {
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
// go through all the team gates
|
||||
for(Team team : zone.getTeams()){
|
||||
if(zone.getLobby().isInTeamGate(team, playerLoc)) {
|
||||
@ -305,8 +305,8 @@ public class WarPlayerListener extends PlayerListener {
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
if (war.getWarHub() != null && zone.getLobby().isInWarHubLinkGate(playerLoc)
|
||||
|
||||
if (war.getWarHub() != null && zone.getLobby().isInWarHubLinkGate(playerLoc)
|
||||
&& !war.getWarHub().getVolume().contains(player.getLocation())){
|
||||
dropFromOldTeamIfAny(player);
|
||||
event.setTo(war.getWarHub().getLocation());
|
||||
@ -315,9 +315,9 @@ public class WarPlayerListener extends PlayerListener {
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
// Warhub zone gates
|
||||
WarHub hub = war.getWarHub();
|
||||
if(hub != null && hub.getVolume().contains(player.getLocation())) {
|
||||
@ -329,7 +329,7 @@ public class WarPlayerListener extends PlayerListener {
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
boolean isLeaving = playerWarzone != null && playerWarzone.getLobby().isLeavingZone(playerLoc);
|
||||
Team playerTeam = war.getPlayerTeam(player.getName());
|
||||
if(isLeaving) { // already in a team and in warzone, leaving
|
||||
@ -338,26 +338,26 @@ public class WarPlayerListener extends PlayerListener {
|
||||
boolean atSpawnAlready = playerTeam.getTeamSpawn().getBlockX() == player.getLocation().getBlockX() &&
|
||||
playerTeam.getTeamSpawn().getBlockY() == player.getLocation().getBlockY() &&
|
||||
playerTeam.getTeamSpawn().getBlockZ() == player.getLocation().getBlockZ();
|
||||
if(!atSpawnAlready) {
|
||||
if(!atSpawnAlready) {
|
||||
playerWarzone.handlePlayerLeave(player, playerWarzone.getTeleport(), event, true);
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
if(playerWarzone != null) {
|
||||
// Player belongs to a warzone team but is outside: he snuck out or is at spawn and died
|
||||
if(locZone == null && playerTeam != null && playerWarzone.getLobby() != null
|
||||
if(locZone == null && playerTeam != null && playerWarzone.getLobby() != null
|
||||
&& !playerWarzone.getLobby().getVolume().contains(playerLoc)
|
||||
&& !isLeaving) {
|
||||
war.badMsg(player, "Use /leave to exit the zone.");
|
||||
event.setTo(playerTeam.getTeamSpawn());
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
// Monuments
|
||||
if(playerTeam != null
|
||||
&& playerWarzone.nearAnyOwnedMonument(playerLoc, playerTeam)
|
||||
&& playerWarzone.nearAnyOwnedMonument(playerLoc, playerTeam)
|
||||
&& player.getHealth() < 20
|
||||
&& player.getHealth() > 0 // don't heal the dead
|
||||
&& random.nextInt(77) == 3 ) { // one chance out of many of getting healed
|
||||
@ -377,9 +377,9 @@ public class WarPlayerListener extends PlayerListener {
|
||||
war.msg(player, "Your dance pleases the monument's voodoo. You gain "+heartNum+"heart"+isS+"!");
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
// Flag capture
|
||||
if(playerWarzone.isFlagThief(player.getName())
|
||||
if(playerWarzone.isFlagThief(player.getName())
|
||||
&& (playerTeam.getSpawnVolume().contains(player.getLocation())
|
||||
|| (playerTeam.getFlagVolume() != null && playerTeam.getFlagVolume().contains(player.getLocation())))) {
|
||||
if(playerWarzone.isTeamFlagStolen(playerTeam)) {
|
||||
@ -407,14 +407,14 @@ public class WarPlayerListener extends PlayerListener {
|
||||
playerWarzone.respawnPlayer(event, playerTeam, player);
|
||||
playerTeam.resetSign();
|
||||
playerWarzone.getLobby().resetTeamGateSign(playerTeam);
|
||||
}
|
||||
}
|
||||
playerWarzone.removeThief(player.getName());
|
||||
}
|
||||
}
|
||||
return;
|
||||
}
|
||||
} else if (locZone != null && locZone.getLobby() != null
|
||||
&& !locZone.getLobby().isLeavingZone(playerLoc) && !isMaker) {
|
||||
} else if (locZone != null && locZone.getLobby() != null
|
||||
&& !locZone.getLobby().isLeavingZone(playerLoc) && !isMaker) {
|
||||
// player is not in any team, but inside warzone boundaries, get him out
|
||||
Warzone zone = war.warzone(playerLoc);
|
||||
event.setTo(zone.getTeleport());
|
||||
@ -424,7 +424,7 @@ public class WarPlayerListener extends PlayerListener {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
private void handleDisabledZone(PlayerMoveEvent event, Player player, Warzone zone) {
|
||||
if(zone.getLobby() != null) {
|
||||
war.badMsg(player, "This warzone is disabled.");
|
||||
|
@ -7,38 +7,34 @@ import org.bukkit.Material;
|
||||
import org.bukkit.World;
|
||||
import org.bukkit.block.Block;
|
||||
import org.bukkit.block.BlockState;
|
||||
import org.bukkit.block.Dispenser;
|
||||
import org.bukkit.block.Sign;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
|
||||
import com.tommytony.war.Warzone;
|
||||
import com.tommytony.war.utils.DeferredBlockReset;
|
||||
|
||||
public class DeferredBlockResetsJob implements Runnable {
|
||||
|
||||
List<DeferredBlockReset> deferred = new ArrayList<DeferredBlockReset>();
|
||||
private final World world;
|
||||
|
||||
|
||||
public DeferredBlockResetsJob(World world) {
|
||||
this.world = world;
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
public void add(DeferredBlockReset pleaseResetLater) {
|
||||
deferred.add(pleaseResetLater);
|
||||
}
|
||||
|
||||
|
||||
public boolean isEmpty() {
|
||||
return deferred.isEmpty();
|
||||
}
|
||||
|
||||
|
||||
|
||||
public void run() {
|
||||
for(DeferredBlockReset reset : deferred) {
|
||||
Block worldBlock = world.getBlockAt(reset.getX(), reset.getY(), reset.getZ());
|
||||
worldBlock.setType(Material.getMaterial(reset.getBlockType()));
|
||||
|
||||
|
||||
if(reset.getBlockType() == Material.SIGN_POST.getId()) {
|
||||
BlockState state = worldBlock.getState();
|
||||
state.setData(new org.bukkit.material.Sign(reset.getBlockType(), reset.getBlockData()));
|
||||
@ -55,12 +51,12 @@ public class DeferredBlockResetsJob implements Runnable {
|
||||
}
|
||||
} else {
|
||||
// normal data reset
|
||||
worldBlock.setData(reset.getBlockData());
|
||||
worldBlock.setData(reset.getBlockData());
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -3,12 +3,9 @@ package com.tommytony.war.mappers;
|
||||
import java.io.BufferedReader;
|
||||
import java.io.BufferedWriter;
|
||||
import java.io.File;
|
||||
import java.io.FileInputStream;
|
||||
import java.io.FileNotFoundException;
|
||||
import java.io.FileReader;
|
||||
import java.io.FileWriter;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStreamReader;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
@ -26,7 +23,6 @@ import org.bukkit.material.MaterialData;
|
||||
import bukkit.tommytony.war.War;
|
||||
|
||||
import com.tommytony.war.jobs.DeferredBlockResetsJob;
|
||||
import com.tommytony.war.jobs.ZoneVolumeSaveJob;
|
||||
import com.tommytony.war.utils.DeferredBlockReset;
|
||||
import com.tommytony.war.volumes.Volume;
|
||||
import com.tommytony.war.volumes.ZoneVolume;
|
||||
@ -34,12 +30,12 @@ import com.tommytony.war.volumes.ZoneVolume;
|
||||
/**
|
||||
* The ZoneVolumeMapper take the blocks from disk and sets them in the worlds, since
|
||||
* the ZoneVolume doesn't hold its blocks in memory like regular Volumes.
|
||||
*
|
||||
*
|
||||
* @author tommytony
|
||||
*
|
||||
*/
|
||||
public class PreDeGaulleZoneVolumeMapper {
|
||||
|
||||
|
||||
private static List<ItemStack> readInventoryString(String invString) {
|
||||
List<ItemStack> items = new ArrayList<ItemStack>();
|
||||
String[] itemsStrSplit = invString.split(";;");
|
||||
@ -73,7 +69,7 @@ public class PreDeGaulleZoneVolumeMapper {
|
||||
try {
|
||||
in = new BufferedReader(new FileReader(new File(war.getDataFolder().getPath() + "/dat/warzone-" + zoneName + "/volume-" + volume.getName() + ".dat")));
|
||||
String firstLine = in.readLine();
|
||||
|
||||
|
||||
if(firstLine != null && !firstLine.equals("")) {
|
||||
boolean height129Fix = false;
|
||||
int x1 = Integer.parseInt(in.readLine());
|
||||
@ -91,10 +87,10 @@ public class PreDeGaulleZoneVolumeMapper {
|
||||
y2 = 127;
|
||||
}
|
||||
int z2 = Integer.parseInt(in.readLine());
|
||||
|
||||
|
||||
volume.setCornerOne(world.getBlockAt(x1, y1, z1));
|
||||
volume.setCornerTwo(world.getBlockAt(x2, y2, z2));
|
||||
|
||||
volume.setCornerTwo(world.getBlockAt(x2, y2, z2));
|
||||
|
||||
if(!onlyLoadCorners) {
|
||||
DeferredBlockResetsJob deferred = new DeferredBlockResetsJob(world);
|
||||
int blockReads = 0, visitedBlocks = 0, x = 0, y = 0, z = 0, i = 0, j = 0 , k = 0;
|
||||
@ -107,13 +103,13 @@ public class PreDeGaulleZoneVolumeMapper {
|
||||
String blockLine;
|
||||
String[] blockSplit;
|
||||
for(i = 0; i < volume.getSizeX(); i++){
|
||||
y = volume.getMinY();
|
||||
y = volume.getMinY();
|
||||
for(j = 0; j < volume.getSizeY(); j++) {
|
||||
z = volume.getMinZ();
|
||||
for(k = 0; k < volume.getSizeZ(); k++) {
|
||||
try {
|
||||
blockLine = in.readLine();
|
||||
|
||||
|
||||
if(blockLine != null && !blockLine.equals("")) {
|
||||
blockSplit = blockLine.split(",");
|
||||
if(blockLine != null && !blockLine.equals("") && blockSplit.length > 1) {
|
||||
@ -124,11 +120,11 @@ public class PreDeGaulleZoneVolumeMapper {
|
||||
if(worldBlockId != diskBlockType ||
|
||||
(worldBlockId == diskBlockType && worldBlock.getData() != diskBlockData ) ||
|
||||
(worldBlockId == diskBlockType && worldBlock.getData() == diskBlockData &&
|
||||
(diskBlockType == Material.WALL_SIGN.getId() || diskBlockType == Material.SIGN_POST.getId()
|
||||
(diskBlockType == Material.WALL_SIGN.getId() || diskBlockType == Material.SIGN_POST.getId()
|
||||
|| diskBlockType == Material.CHEST.getId() || diskBlockType == Material.DISPENSER.getId())
|
||||
)
|
||||
) {
|
||||
if(diskBlockType == Material.WALL_SIGN.getId()
|
||||
if(diskBlockType == Material.WALL_SIGN.getId()
|
||||
|| diskBlockType == Material.SIGN_POST.getId()) {
|
||||
// Signs read
|
||||
String linesStr = "";
|
||||
@ -139,7 +135,7 @@ public class PreDeGaulleZoneVolumeMapper {
|
||||
String[] lines = linesStr.split(";;");
|
||||
|
||||
// Signs set
|
||||
// A sign post hanging on a wall south of here will
|
||||
// A sign post hanging on a wall south of here will
|
||||
if(diskBlockType == Material.SIGN_POST.getId() && ((diskBlockData & 0x04) == 0x04)
|
||||
&& i+1 != volume.getSizeX()) {
|
||||
deferred.add(new DeferredBlockReset(x, y, z, diskBlockType, diskBlockData, lines));
|
||||
@ -166,7 +162,7 @@ public class PreDeGaulleZoneVolumeMapper {
|
||||
String itemsStr = blockSplit[2];
|
||||
items = readInventoryString(itemsStr);
|
||||
}
|
||||
|
||||
|
||||
// Chests set
|
||||
worldBlock.setType(Material.getMaterial(diskBlockType));
|
||||
worldBlock.setData(diskBlockData);
|
||||
@ -193,7 +189,7 @@ public class PreDeGaulleZoneVolumeMapper {
|
||||
//String itemsStr = lineScanner.nextLine();
|
||||
items = readInventoryString(itemsStr);
|
||||
}
|
||||
|
||||
|
||||
// Dispensers set
|
||||
worldBlock.setType(Material.getMaterial(diskBlockType));
|
||||
worldBlock.setData(diskBlockData);
|
||||
@ -214,7 +210,7 @@ public class PreDeGaulleZoneVolumeMapper {
|
||||
}
|
||||
} else if(diskBlockType == Material.WOODEN_DOOR.getId() || diskBlockType == Material.IRON_DOOR_BLOCK.getId()){
|
||||
// Door blocks
|
||||
|
||||
|
||||
if(j-1 > 0) {
|
||||
Block blockBelow = world.getBlockAt(x, y-1, z);
|
||||
boolean belowIsGlass = blockBelow.getTypeId() == Material.GLASS.getId();
|
||||
@ -230,8 +226,8 @@ public class PreDeGaulleZoneVolumeMapper {
|
||||
worldBlock.setType(Material.GLASS);
|
||||
}
|
||||
}
|
||||
|
||||
} else if(((diskBlockType == Material.TORCH.getId() && ((diskBlockData & 0x02) == 0x02))
|
||||
|
||||
} else if(((diskBlockType == Material.TORCH.getId() && ((diskBlockData & 0x02) == 0x02))
|
||||
|| (diskBlockType == Material.REDSTONE_TORCH_OFF.getId() && ((diskBlockData & 0x02) == 0x02))
|
||||
|| (diskBlockType == Material.REDSTONE_TORCH_ON.getId() && ((diskBlockData & 0x02) == 0x02))
|
||||
|| (diskBlockType == Material.LEVER.getId() && ((diskBlockData & 0x02) == 0x02))
|
||||
@ -253,12 +249,12 @@ public class PreDeGaulleZoneVolumeMapper {
|
||||
}
|
||||
blockReads++;
|
||||
}
|
||||
|
||||
|
||||
} catch (Exception e) {
|
||||
volume.getWar().getLogger().warning("Failed to reset block in zone volume " + volume.getName() + ". "
|
||||
+ "Blocks read: " + blockReads
|
||||
+ ". Visited blocks so far:" + visitedBlocks
|
||||
+ ". Blocks reset: "+ noOfResetBlocks +
|
||||
volume.getWar().getLogger().warning("Failed to reset block in zone volume " + volume.getName() + ". "
|
||||
+ "Blocks read: " + blockReads
|
||||
+ ". Visited blocks so far:" + visitedBlocks
|
||||
+ ". Blocks reset: "+ noOfResetBlocks +
|
||||
". Error at x:" + x + " y:" + y + " z:" + z + ". Exception:" + e.getClass().toString() + " " + e.getMessage());
|
||||
e.printStackTrace();
|
||||
} finally {
|
||||
@ -281,11 +277,11 @@ public class PreDeGaulleZoneVolumeMapper {
|
||||
}
|
||||
}
|
||||
} catch (IOException e) {
|
||||
war.logWarn("Failed to read volume file " + volume.getName() +
|
||||
war.logWarn("Failed to read volume file " + volume.getName() +
|
||||
" for warzone " + zoneName + ". " + e.getClass().getName() + " " + e.getMessage());
|
||||
e.printStackTrace();
|
||||
} catch (Exception e) {
|
||||
war.logWarn("Unexpected error caused failure to read volume file " + zoneName +
|
||||
war.logWarn("Unexpected error caused failure to read volume file " + zoneName +
|
||||
" for warzone " + volume.getName() + ". " + e.getClass().getName() + " " + e.getMessage());
|
||||
e.printStackTrace();
|
||||
} finally {
|
||||
@ -312,9 +308,9 @@ public class PreDeGaulleZoneVolumeMapper {
|
||||
try {
|
||||
(new File(war.getDataFolder().getPath() +"/dat/warzone-"+zoneName)).mkdir();
|
||||
if(zoneName.equals("")) out = new BufferedWriter(new FileWriter(new File(war.getDataFolder().getPath() + "/dat/volume-" + volume.getName() + ".dat")));
|
||||
else out = new BufferedWriter(new FileWriter(new File(war.getDataFolder().getPath() +
|
||||
else out = new BufferedWriter(new FileWriter(new File(war.getDataFolder().getPath() +
|
||||
"/dat/warzone-" + zoneName + "/volume-" + volume.getName() + ".dat")));
|
||||
|
||||
|
||||
out.write("corner1"); out.newLine();
|
||||
out.write(Integer.toString(volume.getCornerOne().getX())); out.newLine();
|
||||
out.write(Integer.toString(volume.getCornerOne().getY())); out.newLine();
|
||||
@ -323,7 +319,7 @@ public class PreDeGaulleZoneVolumeMapper {
|
||||
out.write(Integer.toString(volume.getCornerTwo().getX())); out.newLine();
|
||||
out.write(Integer.toString(volume.getCornerTwo().getY())); out.newLine();
|
||||
out.write(Integer.toString(volume.getCornerTwo().getZ())); out.newLine();
|
||||
|
||||
|
||||
int x = 0;
|
||||
int y = 0;
|
||||
int z = 0;
|
||||
@ -331,7 +327,7 @@ public class PreDeGaulleZoneVolumeMapper {
|
||||
int typeId;
|
||||
byte data;
|
||||
BlockState state;
|
||||
|
||||
|
||||
x = volume.getMinX();
|
||||
for(int i = 0; i < volume.getSizeX(); i++){
|
||||
y = volume.getMinY();
|
||||
@ -343,9 +339,9 @@ public class PreDeGaulleZoneVolumeMapper {
|
||||
typeId = block.getTypeId();
|
||||
data = block.getData();
|
||||
state = block.getState();
|
||||
|
||||
|
||||
out.write(typeId + "," + data + ",");
|
||||
|
||||
|
||||
if(state instanceof Sign) {
|
||||
// Signs
|
||||
String extra = "";
|
||||
@ -356,7 +352,7 @@ public class PreDeGaulleZoneVolumeMapper {
|
||||
}
|
||||
out.write(extra);
|
||||
}
|
||||
|
||||
|
||||
} else if(state instanceof Chest) {
|
||||
// Chests
|
||||
Chest chest = (Chest)state;
|
||||
@ -373,9 +369,9 @@ public class PreDeGaulleZoneVolumeMapper {
|
||||
if(items != null) {
|
||||
for(ItemStack item : items) {
|
||||
if(item != null) {
|
||||
extra += item.getTypeId() + ";"
|
||||
+ item.getAmount() + ";"
|
||||
+ item.getDurability();
|
||||
extra += item.getTypeId() + ";"
|
||||
+ item.getAmount() + ";"
|
||||
+ item.getDurability();
|
||||
if(item.getData() != null)
|
||||
extra += ";" + item.getData().getData() ;
|
||||
extra += ";;";
|
||||
@ -384,7 +380,7 @@ public class PreDeGaulleZoneVolumeMapper {
|
||||
out.write(extra);
|
||||
}
|
||||
} else if(state instanceof Dispenser) {
|
||||
// Dispensers
|
||||
// Dispensers
|
||||
Dispenser dispenser = (Dispenser)state;
|
||||
Inventory inv = dispenser.getInventory();
|
||||
int size = inv.getSize();
|
||||
@ -399,9 +395,9 @@ public class PreDeGaulleZoneVolumeMapper {
|
||||
if(items != null) {
|
||||
for(ItemStack item : items) {
|
||||
if(item != null) {
|
||||
extra += item.getTypeId() + ";"
|
||||
+ item.getAmount() + ";"
|
||||
+ item.getDurability();
|
||||
extra += item.getTypeId() + ";"
|
||||
+ item.getAmount() + ";"
|
||||
+ item.getDurability();
|
||||
if(item.getData() != null)
|
||||
extra += ";" + item.getData().getData() ;
|
||||
extra += ";;";
|
||||
@ -415,7 +411,7 @@ public class PreDeGaulleZoneVolumeMapper {
|
||||
}
|
||||
catch (Exception e) {
|
||||
war.logWarn("Unexpected error while saving a block to " +
|
||||
" file for zone " + zoneName + ". Blocks saved so far: " + noOfSavedBlocks
|
||||
" file for zone " + zoneName + ". Blocks saved so far: " + noOfSavedBlocks
|
||||
+ "Position: x:" + x + " y:" + y + " z:" + z + ". " + e.getClass().getName() + " " + e.getMessage());
|
||||
e.printStackTrace();
|
||||
} finally {
|
||||
@ -427,14 +423,14 @@ public class PreDeGaulleZoneVolumeMapper {
|
||||
x++;
|
||||
}
|
||||
} catch (IOException e) {
|
||||
war.logWarn("Failed to write volume file " + zoneName +
|
||||
war.logWarn("Failed to write volume file " + zoneName +
|
||||
" for warzone " + volume.getName() + ". " + e.getClass().getName() + " " + e.getMessage());
|
||||
e.printStackTrace();
|
||||
} catch (Exception e) {
|
||||
war.logWarn("Unexpected error caused failure to write volume file " + zoneName +
|
||||
war.logWarn("Unexpected error caused failure to write volume file " + zoneName +
|
||||
" for warzone " + volume.getName() + ". " + e.getClass().getName() + " " + e.getMessage());
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
finally {
|
||||
if(out != null)
|
||||
try {
|
||||
@ -443,7 +439,7 @@ public class PreDeGaulleZoneVolumeMapper {
|
||||
war.logWarn("Failed to close file writer for volume " + volume.getName() +
|
||||
" for warzone " + zoneName + ". " + e.getClass().getName() + " " + e.getMessage());
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
return noOfSavedBlocks;
|
||||
|
@ -16,35 +16,33 @@ import org.bukkit.material.MaterialData;
|
||||
|
||||
import bukkit.tommytony.war.War;
|
||||
|
||||
import com.tommytony.war.Warzone;
|
||||
import com.tommytony.war.volumes.Volume;
|
||||
import com.tommytony.war.volumes.ZoneVolume;
|
||||
|
||||
/**
|
||||
*
|
||||
*
|
||||
* @author tommytony
|
||||
*
|
||||
*/
|
||||
public class VolumeMapper {
|
||||
|
||||
|
||||
public static Volume loadVolume(String volumeName, String zoneName,
|
||||
War war, World world) {
|
||||
Volume volume = new Volume(volumeName, war, world);
|
||||
load(volume, zoneName, war, world);
|
||||
return volume;
|
||||
}
|
||||
|
||||
|
||||
// public static ZoneVolume loadZoneVolume(String volumeName, String zoneName,
|
||||
// War war, World world, Warzone zone) {
|
||||
// ZoneVolume volume = new ZoneVolume(volumeName, war, world, zone);
|
||||
// load(volume, zoneName, war, world);
|
||||
// return volume;
|
||||
// }
|
||||
|
||||
|
||||
public static void load(Volume volume, String zoneName, War war, World world) {
|
||||
BufferedReader in = null;
|
||||
try {
|
||||
if(zoneName.equals("")) in = new BufferedReader(new FileReader(new File(war.getDataFolder().getPath() +
|
||||
if(zoneName.equals("")) in = new BufferedReader(new FileReader(new File(war.getDataFolder().getPath() +
|
||||
"/dat/volume-" + volume.getName() + ".dat"))); // for the warhub
|
||||
else in = new BufferedReader(new FileReader(new File(war.getDataFolder().getPath() + "/dat/warzone-" + zoneName + "/volume-" + volume.getName() + ".dat")));
|
||||
String firstLine = in.readLine();
|
||||
@ -65,10 +63,10 @@ public class VolumeMapper {
|
||||
y2 = 127;
|
||||
}
|
||||
int z2 = Integer.parseInt(in.readLine());
|
||||
|
||||
|
||||
volume.setCornerOne(world.getBlockAt(x1, y1, z1));
|
||||
volume.setCornerTwo(world.getBlockAt(x2, y2, z2));
|
||||
|
||||
volume.setCornerTwo(world.getBlockAt(x2, y2, z2));
|
||||
|
||||
volume.setBlockTypes(new int[volume.getSizeX()][volume.getSizeY()][volume.getSizeZ()]);
|
||||
volume.setBlockDatas(new byte[volume.getSizeX()][volume.getSizeY()][volume.getSizeZ()]);
|
||||
int blockReads = 0;
|
||||
@ -82,11 +80,11 @@ public class VolumeMapper {
|
||||
if(blockLine != null && !blockLine.equals("") && blockSplit.length > 1) {
|
||||
int typeID = Integer.parseInt(blockSplit[0]);
|
||||
byte data = Byte.parseByte(blockSplit[1]);
|
||||
|
||||
|
||||
volume.getBlockTypes()[i][j][k] = typeID;
|
||||
volume.getBlockDatas()[i][j][k] = data;
|
||||
|
||||
if(typeID == Material.WALL_SIGN.getId()
|
||||
|
||||
if(typeID == Material.WALL_SIGN.getId()
|
||||
|| typeID == Material.SIGN_POST.getId()) {
|
||||
// Signs
|
||||
String linesStr = "";
|
||||
@ -153,12 +151,12 @@ public class VolumeMapper {
|
||||
}
|
||||
}
|
||||
volume.getInvBlockContents().put("dispenser-" + i + "-" + j + "-" + k, items);
|
||||
}
|
||||
}
|
||||
}
|
||||
blockReads++;
|
||||
}
|
||||
} catch (Exception e) {
|
||||
war.logWarn("Unexpected error while reading block from volume " + volume.getName() +
|
||||
war.logWarn("Unexpected error while reading block from volume " + volume.getName() +
|
||||
" file for zone " + zoneName + ". Blocks read so far: " + blockReads
|
||||
+ "Position: x:" + i + " y:" + j + " z:" + k + ". " + e.getClass().getName() + " " + e.getMessage());
|
||||
e.printStackTrace();
|
||||
@ -173,11 +171,11 @@ public class VolumeMapper {
|
||||
}
|
||||
}
|
||||
} catch (IOException e) {
|
||||
war.logWarn("Failed to read volume file " + volume.getName() +
|
||||
war.logWarn("Failed to read volume file " + volume.getName() +
|
||||
" for warzone " + zoneName + ". " + e.getClass().getName() + " " + e.getMessage());
|
||||
e.printStackTrace();
|
||||
} catch (Exception e) {
|
||||
war.logWarn("Unexpected error caused failure to read volume file " + zoneName +
|
||||
war.logWarn("Unexpected error caused failure to read volume file " + zoneName +
|
||||
" for warzone " + volume.getName() + ". " + e.getClass().getName() + " " + e.getMessage());
|
||||
e.printStackTrace();
|
||||
} finally {
|
||||
@ -191,15 +189,15 @@ public class VolumeMapper {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public static void save(Volume volume, String zoneName, War war) {
|
||||
if(volume.hasTwoCorners()) {
|
||||
BufferedWriter out = null;
|
||||
try {
|
||||
if(zoneName.equals("")) out = new BufferedWriter(new FileWriter(new File(war.getDataFolder().getPath() + "/dat/volume-" + volume.getName() + ".dat")));
|
||||
else out = new BufferedWriter(new FileWriter(new File(war.getDataFolder().getPath() +
|
||||
else out = new BufferedWriter(new FileWriter(new File(war.getDataFolder().getPath() +
|
||||
"/dat/warzone-" + zoneName + "/volume-" + volume.getName() + ".dat")));
|
||||
|
||||
|
||||
out.write("corner1"); out.newLine();
|
||||
out.write(Integer.toString(volume.getCornerOne().getX())); out.newLine();
|
||||
out.write(Integer.toString(volume.getCornerOne().getY())); out.newLine();
|
||||
@ -216,7 +214,7 @@ public class VolumeMapper {
|
||||
int typeId = volume.getBlockTypes()[i][j][k];
|
||||
byte data = volume.getBlockDatas()[i][j][k];
|
||||
out.write(typeId + "," + data + ",");
|
||||
if(typeId == Material.WALL_SIGN.getId()
|
||||
if(typeId == Material.WALL_SIGN.getId()
|
||||
|| typeId == Material.SIGN_POST.getId()) {
|
||||
// Signs
|
||||
String extra = "";
|
||||
@ -234,9 +232,9 @@ public class VolumeMapper {
|
||||
if(contents != null) {
|
||||
for(ItemStack item : contents) {
|
||||
if(item != null) {
|
||||
extra += item.getTypeId() + ";"
|
||||
+ item.getAmount() + ";"
|
||||
+ item.getDurability();
|
||||
extra += item.getTypeId() + ";"
|
||||
+ item.getAmount() + ";"
|
||||
+ item.getDurability();
|
||||
if(item.getData() != null)
|
||||
extra += ";" + item.getData().getData() ;
|
||||
extra += ";;";
|
||||
@ -251,9 +249,9 @@ public class VolumeMapper {
|
||||
if(contents != null) {
|
||||
for(ItemStack item : contents) {
|
||||
if(item != null) {
|
||||
extra += item.getTypeId() + ";"
|
||||
+ item.getAmount() + ";"
|
||||
+ item.getDurability();
|
||||
extra += item.getTypeId() + ";"
|
||||
+ item.getAmount() + ";"
|
||||
+ item.getDurability();
|
||||
if(item.getData() != null)
|
||||
extra += ";" + item.getData().getData() ;
|
||||
extra += ";;";
|
||||
@ -265,8 +263,8 @@ public class VolumeMapper {
|
||||
out.newLine();
|
||||
}
|
||||
catch (Exception e) {
|
||||
war.logWarn("Unexpected error while writing block into volume " + volume.getName() +
|
||||
" file for zone " + zoneName + ". Blocks written so far: " + blockWrites
|
||||
war.logWarn("Unexpected error while writing block into volume " + volume.getName() +
|
||||
" file for zone " + zoneName + ". Blocks written so far: " + blockWrites
|
||||
+ "Position: x:" + i + " y:" + j + " z:" + k + ". " + e.getClass().getName() + " " + e.getMessage());
|
||||
e.printStackTrace();
|
||||
}
|
||||
@ -274,14 +272,14 @@ public class VolumeMapper {
|
||||
}
|
||||
}
|
||||
} catch (IOException e) {
|
||||
war.logWarn("Failed to write volume file " + zoneName +
|
||||
war.logWarn("Failed to write volume file " + zoneName +
|
||||
" for warzone " + volume.getName() + ". " + e.getClass().getName() + " " + e.getMessage());
|
||||
e.printStackTrace();
|
||||
} catch (Exception e) {
|
||||
war.logWarn("Unexpected error caused failure to write volume file " + zoneName +
|
||||
war.logWarn("Unexpected error caused failure to write volume file " + zoneName +
|
||||
" for warzone " + volume.getName() + ". " + e.getClass().getName() + " " + e.getMessage());
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
finally {
|
||||
if(out != null)
|
||||
try {
|
||||
@ -290,7 +288,7 @@ public class VolumeMapper {
|
||||
war.logWarn("Failed to close file writer for volume " + volume.getName() +
|
||||
" for warzone " + zoneName + ". " + e.getClass().getName() + " " + e.getMessage());
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -1,9 +1,5 @@
|
||||
package com.tommytony.war.utils;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
|
||||
public class DeferredBlockReset {
|
||||
|
||||
private final int x;
|
||||
@ -12,7 +8,6 @@ public class DeferredBlockReset {
|
||||
private final int blockType;
|
||||
private final byte blockData;
|
||||
private String[] lines;
|
||||
private List<ItemStack> items;
|
||||
|
||||
public DeferredBlockReset(int x, int y, int z, int blockType, byte blockData) {
|
||||
this.x = x;
|
||||
@ -21,7 +16,7 @@ public class DeferredBlockReset {
|
||||
this.blockType = blockType;
|
||||
this.blockData = blockData;
|
||||
}
|
||||
|
||||
|
||||
// Signs
|
||||
public DeferredBlockReset(int x, int y, int z, int blockType, byte blockData, String[] signLines) {
|
||||
this.x = x;
|
||||
@ -55,7 +50,4 @@ public class DeferredBlockReset {
|
||||
public String[] getLines() {
|
||||
return lines;
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
||||
}
|
@ -1,7 +1,6 @@
|
||||
package com.tommytony.war.spec.volumes;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import org.bukkit.World;
|
||||
import org.bukkit.block.Block;
|
||||
@ -12,20 +11,13 @@ import static org.mockito.Mockito.*;
|
||||
|
||||
import bukkit.tommytony.war.War;
|
||||
|
||||
import com.tommytony.war.Monument;
|
||||
import com.tommytony.war.Team;
|
||||
import com.tommytony.war.Warzone;
|
||||
import com.tommytony.war.volumes.BlockInfo;
|
||||
import com.tommytony.war.volumes.NotNorthwestException;
|
||||
import com.tommytony.war.volumes.NotSoutheastException;
|
||||
import com.tommytony.war.volumes.TooBigException;
|
||||
import com.tommytony.war.volumes.TooSmallException;
|
||||
import com.tommytony.war.volumes.ZoneVolume;
|
||||
import com.tommytony.war.*;
|
||||
import com.tommytony.war.volumes.*;
|
||||
|
||||
public class ZoneVolumeSpecTest {
|
||||
|
||||
// setNorthwest
|
||||
|
||||
|
||||
@Test
|
||||
public void setNorthwest_whenCreatingAndNoCornersAreSet_shouldSetCorner1AtTop() throws NotNorthwestException, TooSmallException, TooBigException{
|
||||
// Arrange
|
||||
@ -41,10 +33,10 @@ public class ZoneVolumeSpecTest {
|
||||
when(blockMock.getZ()).thenReturn(0);
|
||||
when(blockMock.getTypeId()).thenReturn(10);
|
||||
when(blockMock.getData()).thenReturn((byte)2);
|
||||
|
||||
|
||||
// Act
|
||||
volume.setNorthwest(blockMock);
|
||||
|
||||
|
||||
// Assert
|
||||
assertEquals(null, volume.getCornerTwo());
|
||||
assertEquals(0, volume.getCornerOne().getX());
|
||||
@ -53,7 +45,7 @@ public class ZoneVolumeSpecTest {
|
||||
assertEquals(10, volume.getCornerOne().getTypeId());
|
||||
assertEquals((byte)2, volume.getCornerOne().getData());
|
||||
}
|
||||
|
||||
|
||||
@Test
|
||||
public void setNorthwest_whenCreating_AndNoCorner1IsSet_ButCorner2Set_AndNewCornerBlockIsToEastOfCorner2_shouldThrowNotNorthwestException() throws TooSmallException, TooBigException{
|
||||
// Arrange
|
||||
@ -69,25 +61,25 @@ public class ZoneVolumeSpecTest {
|
||||
when(blockMock.getZ()).thenReturn(-64); // further east
|
||||
when(blockMock.getTypeId()).thenReturn(10);
|
||||
when(blockMock.getData()).thenReturn((byte)2);
|
||||
|
||||
|
||||
// Act
|
||||
BlockInfo existingCorner2 = new BlockInfo(0, 64, 0, 4, (byte)4);
|
||||
volume.setCornerTwo(existingCorner2); // corner 2 already set
|
||||
boolean failed = false;
|
||||
try {
|
||||
volume.setNorthwest(blockMock);
|
||||
volume.setNorthwest(blockMock);
|
||||
}
|
||||
catch(NotNorthwestException e) {
|
||||
failed = true;
|
||||
}
|
||||
|
||||
|
||||
// Assert
|
||||
// first corner shouldn't move
|
||||
assertTrue(failed);
|
||||
assertEquals(null, volume.getCornerOne());
|
||||
assertEquals(existingCorner2, volume.getCornerTwo());
|
||||
}
|
||||
|
||||
|
||||
@Test
|
||||
public void setNorthwest_whenCreating_AndNoCorner1IsSet_ButCorner2Set_AndNewCornerBlockIsToSouthOfCorner2_shouldThrowNotNorthwestException() throws TooSmallException, TooBigException{
|
||||
// Arrange
|
||||
@ -103,25 +95,25 @@ public class ZoneVolumeSpecTest {
|
||||
when(blockMock.getZ()).thenReturn(64); // further west
|
||||
when(blockMock.getTypeId()).thenReturn(10);
|
||||
when(blockMock.getData()).thenReturn((byte)2);
|
||||
|
||||
|
||||
// Act
|
||||
BlockInfo existingCorner2 = new BlockInfo(0, 64, 0, 4, (byte)4);
|
||||
volume.setCornerTwo(existingCorner2); // corner 2 already set
|
||||
boolean failed = false;
|
||||
try {
|
||||
volume.setNorthwest(blockMock);
|
||||
volume.setNorthwest(blockMock);
|
||||
}
|
||||
catch(NotNorthwestException e) {
|
||||
failed = true;
|
||||
}
|
||||
|
||||
|
||||
// Assert
|
||||
// first corner shouldn't move
|
||||
assertTrue(failed);
|
||||
assertEquals(null, volume.getCornerOne());
|
||||
assertEquals(existingCorner2, volume.getCornerTwo());
|
||||
}
|
||||
|
||||
|
||||
@Test
|
||||
public void setNorthwest_whenCreating_AndNoCorner1IsSet_ButCorner2Set_AndNewCornerBlockIsTooCloseToCorner2_shouldThrowTooSmallException() throws NotNorthwestException, TooBigException{
|
||||
// Arrange
|
||||
@ -137,25 +129,25 @@ public class ZoneVolumeSpecTest {
|
||||
when(blockMock.getZ()).thenReturn(5); // further west
|
||||
when(blockMock.getTypeId()).thenReturn(10);
|
||||
when(blockMock.getData()).thenReturn((byte)2);
|
||||
|
||||
|
||||
// Act
|
||||
BlockInfo existingCorner2 = new BlockInfo(0, 64, 0, 4, (byte)4);
|
||||
volume.setCornerTwo(existingCorner2); // corner 2 already set
|
||||
boolean failed = false;
|
||||
try {
|
||||
volume.setNorthwest(blockMock);
|
||||
volume.setNorthwest(blockMock);
|
||||
}
|
||||
catch(TooSmallException e) {
|
||||
failed = true;
|
||||
}
|
||||
|
||||
|
||||
// Assert
|
||||
// first corner shouldn't move
|
||||
assertTrue(failed);
|
||||
assertEquals(null, volume.getCornerOne());
|
||||
assertEquals(existingCorner2, volume.getCornerTwo());
|
||||
}
|
||||
|
||||
|
||||
@Test
|
||||
public void setNorthwest_whenCreating_AndNoCorner1IsSet_ButCorner2Set_AndNewCornerBlockIsTooFarFromCorner2_shouldThrowTooBigException() throws NotNorthwestException, TooSmallException{
|
||||
// Arrange
|
||||
@ -171,25 +163,25 @@ public class ZoneVolumeSpecTest {
|
||||
when(blockMock.getZ()).thenReturn(1000); // further west
|
||||
when(blockMock.getTypeId()).thenReturn(10);
|
||||
when(blockMock.getData()).thenReturn((byte)2);
|
||||
|
||||
|
||||
// Act
|
||||
BlockInfo existingCorner2 = new BlockInfo(0, 64, 0, 4, (byte)4);
|
||||
volume.setCornerTwo(existingCorner2); // corner 2 already set
|
||||
boolean failed = false;
|
||||
try {
|
||||
volume.setNorthwest(blockMock);
|
||||
volume.setNorthwest(blockMock);
|
||||
}
|
||||
catch(TooBigException e) {
|
||||
failed = true;
|
||||
}
|
||||
|
||||
|
||||
// Assert
|
||||
// first corner shouldn't move
|
||||
assertTrue(failed);
|
||||
assertEquals(null, volume.getCornerOne());
|
||||
assertEquals(existingCorner2, volume.getCornerTwo());
|
||||
}
|
||||
|
||||
|
||||
@Test
|
||||
public void setNorthwest_whenCreatingAndCorner1AlreadySet_shouldSetCorner2AtTop() throws NotNorthwestException, TooSmallException, TooBigException{ // nw always goes to top
|
||||
// Arrange
|
||||
@ -205,12 +197,12 @@ public class ZoneVolumeSpecTest {
|
||||
when(blockMock.getZ()).thenReturn(64); // further west
|
||||
when(blockMock.getTypeId()).thenReturn(10);
|
||||
when(blockMock.getData()).thenReturn((byte)2);
|
||||
|
||||
|
||||
// Act
|
||||
BlockInfo existingCorner1 = new BlockInfo(0, 64, 0, 4, (byte)4);
|
||||
volume.setCornerOne(existingCorner1); // corner 1 already set
|
||||
volume.setNorthwest(blockMock);
|
||||
|
||||
|
||||
// Assert
|
||||
// first corner shouldn't move
|
||||
assertEquals(0, volume.getCornerOne().getX());
|
||||
@ -218,14 +210,14 @@ public class ZoneVolumeSpecTest {
|
||||
assertEquals(0, volume.getCornerOne().getZ());
|
||||
assertEquals(4, volume.getCornerOne().getTypeId());
|
||||
assertEquals((byte)4, volume.getCornerOne().getData());
|
||||
|
||||
|
||||
assertEquals(-64, volume.getCornerTwo().getX());
|
||||
assertEquals(127, volume.getCornerTwo().getY()); // the new corner should shoot up to the top
|
||||
assertEquals(64, volume.getCornerTwo().getZ());
|
||||
assertEquals(10, volume.getCornerTwo().getTypeId());
|
||||
assertEquals((byte)2, volume.getCornerTwo().getData());
|
||||
}
|
||||
|
||||
|
||||
@Test
|
||||
public void setNorthwest_whenCreating_AndCorner1AlreadySet_ButNewCornerBlockIsEastOfCorner1_shouldThrowNotNorthwestException() throws TooSmallException, TooBigException{
|
||||
// Arrange
|
||||
@ -241,25 +233,25 @@ public class ZoneVolumeSpecTest {
|
||||
when(blockMock.getZ()).thenReturn(-64); // further east
|
||||
when(blockMock.getTypeId()).thenReturn(10);
|
||||
when(blockMock.getData()).thenReturn((byte)2);
|
||||
|
||||
|
||||
// Act
|
||||
BlockInfo existingCorner1 = new BlockInfo(0, 64, 0, 4, (byte)4);
|
||||
volume.setCornerOne(existingCorner1); // corner 1 already set
|
||||
boolean failed = false;
|
||||
try {
|
||||
volume.setNorthwest(blockMock);
|
||||
volume.setNorthwest(blockMock);
|
||||
}
|
||||
catch(NotNorthwestException e) {
|
||||
failed = true;
|
||||
}
|
||||
|
||||
|
||||
// Assert
|
||||
// first corner shouldn't move
|
||||
assertTrue(failed);
|
||||
assertEquals(null, volume.getCornerTwo());
|
||||
assertEquals(existingCorner1, volume.getCornerOne());
|
||||
}
|
||||
|
||||
|
||||
@Test
|
||||
public void setNorthwest_whenCreating_AndCorner1AlreadySet_ButNewCornerBlockIsSouthOfCorner1_shouldThrowNotNorthwestException() throws TooSmallException, TooBigException{
|
||||
// Arrange
|
||||
@ -275,25 +267,25 @@ public class ZoneVolumeSpecTest {
|
||||
when(blockMock.getZ()).thenReturn(64); // further west
|
||||
when(blockMock.getTypeId()).thenReturn(10);
|
||||
when(blockMock.getData()).thenReturn((byte)2);
|
||||
|
||||
|
||||
// Act
|
||||
BlockInfo existingCorner1 = new BlockInfo(0, 64, 0, 4, (byte)4);
|
||||
volume.setCornerOne(existingCorner1); // corner 1 already set
|
||||
boolean failed = false;
|
||||
try {
|
||||
volume.setNorthwest(blockMock);
|
||||
volume.setNorthwest(blockMock);
|
||||
}
|
||||
catch(NotNorthwestException e) {
|
||||
failed = true;
|
||||
}
|
||||
|
||||
|
||||
// Assert
|
||||
// first corner shouldn't move
|
||||
assertTrue(failed);
|
||||
assertEquals(null, volume.getCornerTwo());
|
||||
assertEquals(existingCorner1, volume.getCornerOne());
|
||||
}
|
||||
|
||||
|
||||
@Test
|
||||
public void setNorthwest_whenChangingVolumeWithCorner1NwCorner2Se_shouldMoveCorner1() throws NotNorthwestException, TooSmallException, TooBigException{
|
||||
// Arrange
|
||||
@ -309,14 +301,14 @@ public class ZoneVolumeSpecTest {
|
||||
when(blockMock.getZ()).thenReturn(64); // further west
|
||||
when(blockMock.getTypeId()).thenReturn(10);
|
||||
when(blockMock.getData()).thenReturn((byte)2);
|
||||
|
||||
|
||||
// Act
|
||||
BlockInfo existingCorner1 = new BlockInfo(-32, 32, 32, 2, (byte)2); // corner 1 at minX and maxZ (nw)
|
||||
volume.setCornerOne(existingCorner1); // corner 1 already set
|
||||
BlockInfo existingCorner2 = new BlockInfo(32, 96, -32, 4, (byte)4); // corner 2 at maxX and minZ (se)
|
||||
volume.setCornerTwo(existingCorner2); // corner 2 already set
|
||||
volume.setNorthwest(blockMock);
|
||||
|
||||
|
||||
// Assert
|
||||
// first corner should move but not along y
|
||||
assertEquals(-64, volume.getCornerOne().getX());
|
||||
@ -324,7 +316,7 @@ public class ZoneVolumeSpecTest {
|
||||
assertEquals(64, volume.getCornerOne().getZ());
|
||||
assertEquals(2, volume.getCornerOne().getTypeId());
|
||||
assertEquals((byte)2, volume.getCornerOne().getData());
|
||||
|
||||
|
||||
// second corner shouldn't move
|
||||
assertEquals(32, volume.getCornerTwo().getX());
|
||||
assertEquals(96, volume.getCornerTwo().getY()); // moving an existing corner shouldn't change its height
|
||||
@ -332,7 +324,7 @@ public class ZoneVolumeSpecTest {
|
||||
assertEquals(4, volume.getCornerTwo().getTypeId());
|
||||
assertEquals((byte)4, volume.getCornerTwo().getData());
|
||||
}
|
||||
|
||||
|
||||
@Test
|
||||
public void setNorthwest_whenChangingVolumeWithCorner1SeCorner2Nw_shouldMoveCorner2() throws NotNorthwestException, TooSmallException, TooBigException{
|
||||
// Arrange
|
||||
@ -348,14 +340,14 @@ public class ZoneVolumeSpecTest {
|
||||
when(blockMock.getZ()).thenReturn(64); // further west
|
||||
when(blockMock.getTypeId()).thenReturn(10);
|
||||
when(blockMock.getData()).thenReturn((byte)2);
|
||||
|
||||
|
||||
// Act
|
||||
BlockInfo existingCorner1 = new BlockInfo(32, 32, -32, 2, (byte)2); // corner 1 at maxX and minZ (se)
|
||||
volume.setCornerOne(existingCorner1); // corner 1 already set
|
||||
BlockInfo existingCorner2 = new BlockInfo(-32, 96, 32, 4, (byte)4); // corner 2 at minX and maxZ (nw)
|
||||
volume.setCornerTwo(existingCorner2); // corner 2 already set
|
||||
volume.setNorthwest(blockMock);
|
||||
|
||||
|
||||
// Assert
|
||||
// first corner shouldn't move
|
||||
assertEquals(32, volume.getCornerOne().getX());
|
||||
@ -363,7 +355,7 @@ public class ZoneVolumeSpecTest {
|
||||
assertEquals(-32, volume.getCornerOne().getZ());
|
||||
assertEquals(2, volume.getCornerOne().getTypeId());
|
||||
assertEquals((byte)2, volume.getCornerOne().getData());
|
||||
|
||||
|
||||
// second corner should move but not along y
|
||||
assertEquals(-64, volume.getCornerTwo().getX());
|
||||
assertEquals(96, volume.getCornerTwo().getY()); // moving an existing corner shouldn't change its height
|
||||
@ -371,7 +363,7 @@ public class ZoneVolumeSpecTest {
|
||||
assertEquals(4, volume.getCornerTwo().getTypeId());
|
||||
assertEquals((byte)4, volume.getCornerTwo().getData());
|
||||
}
|
||||
|
||||
|
||||
@Test
|
||||
public void setNorthwest_whenChangingVolumeWithCorner1NeCorner2Sw_shouldMoveCorner1XAndCorner2Z() throws NotNorthwestException, TooSmallException, TooBigException{
|
||||
// Arrange
|
||||
@ -387,14 +379,14 @@ public class ZoneVolumeSpecTest {
|
||||
when(blockMock.getZ()).thenReturn(64); // further west
|
||||
when(blockMock.getTypeId()).thenReturn(10);
|
||||
when(blockMock.getData()).thenReturn((byte)2);
|
||||
|
||||
|
||||
// Act
|
||||
BlockInfo existingCorner1 = new BlockInfo(-32, 32, -32, 2, (byte)2); // corner 1 at minX and minZ (ne)
|
||||
volume.setCornerOne(existingCorner1); // corner 1 already set
|
||||
BlockInfo existingCorner2 = new BlockInfo(32, 96, 32, 4, (byte)4); // corner 2 at maxX and maxZ (sw)
|
||||
volume.setCornerTwo(existingCorner2); // corner 2 already set
|
||||
volume.setNorthwest(blockMock);
|
||||
|
||||
|
||||
// Assert
|
||||
// first corner should move along x but not along y or z
|
||||
assertEquals(-64, volume.getCornerOne().getX());
|
||||
@ -402,7 +394,7 @@ public class ZoneVolumeSpecTest {
|
||||
assertEquals(-32, volume.getCornerOne().getZ());
|
||||
assertEquals(2, volume.getCornerOne().getTypeId());
|
||||
assertEquals((byte)2, volume.getCornerOne().getData());
|
||||
|
||||
|
||||
// second corner should move along z but not along x or y
|
||||
assertEquals(32, volume.getCornerTwo().getX());
|
||||
assertEquals(96, volume.getCornerTwo().getY());
|
||||
@ -410,7 +402,7 @@ public class ZoneVolumeSpecTest {
|
||||
assertEquals(4, volume.getCornerTwo().getTypeId());
|
||||
assertEquals((byte)4, volume.getCornerTwo().getData());
|
||||
}
|
||||
|
||||
|
||||
@Test
|
||||
public void setNorthwest_whenChangingVolumeWithCorner1SwCorner2Ne_shouldMoveCorner1ZAndCorner2X() throws NotNorthwestException, TooSmallException, TooBigException{
|
||||
// Arrange
|
||||
@ -426,14 +418,14 @@ public class ZoneVolumeSpecTest {
|
||||
when(blockMock.getZ()).thenReturn(64); // further west
|
||||
when(blockMock.getTypeId()).thenReturn(10);
|
||||
when(blockMock.getData()).thenReturn((byte)2);
|
||||
|
||||
|
||||
// Act
|
||||
BlockInfo existingCorner1 = new BlockInfo(32, 32, 32, 2, (byte)2); // corner 1 at maxX and maxZ (sw)
|
||||
volume.setCornerOne(existingCorner1); // corner 1 already set
|
||||
BlockInfo existingCorner2 = new BlockInfo(-32, 96, -32, 4, (byte)4); // corner 2 at minX and minZ (ne)
|
||||
volume.setCornerTwo(existingCorner2); // corner 2 already set
|
||||
volume.setNorthwest(blockMock);
|
||||
|
||||
|
||||
// Assert
|
||||
// first corner should move along z but not along x or y
|
||||
assertEquals(32, volume.getCornerOne().getX());
|
||||
@ -441,7 +433,7 @@ public class ZoneVolumeSpecTest {
|
||||
assertEquals(64, volume.getCornerOne().getZ());
|
||||
assertEquals(2, volume.getCornerOne().getTypeId());
|
||||
assertEquals((byte)2, volume.getCornerOne().getData());
|
||||
|
||||
|
||||
// second corner should move along x but not along y or z
|
||||
assertEquals(-64, volume.getCornerTwo().getX());
|
||||
assertEquals(96, volume.getCornerTwo().getY());
|
||||
@ -449,13 +441,13 @@ public class ZoneVolumeSpecTest {
|
||||
assertEquals(4, volume.getCornerTwo().getTypeId());
|
||||
assertEquals((byte)4, volume.getCornerTwo().getData());
|
||||
}
|
||||
|
||||
|
||||
// getNorthwestX
|
||||
|
||||
|
||||
// getNorthwestZ
|
||||
|
||||
|
||||
// setSoutheast
|
||||
|
||||
|
||||
@Test
|
||||
public void setSoutheast_whenCreatingAndNoCornersAreSet_shouldSetCorner2AtBottom() throws NotSoutheastException, TooSmallException, TooBigException{
|
||||
// Arrange
|
||||
@ -471,10 +463,10 @@ public class ZoneVolumeSpecTest {
|
||||
when(blockMock.getZ()).thenReturn(0);
|
||||
when(blockMock.getTypeId()).thenReturn(10);
|
||||
when(blockMock.getData()).thenReturn((byte)2);
|
||||
|
||||
|
||||
// Act
|
||||
volume.setSoutheast(blockMock);
|
||||
|
||||
|
||||
// Assert
|
||||
assertEquals(null, volume.getCornerOne());
|
||||
assertEquals(0, volume.getCornerTwo().getX());
|
||||
@ -483,7 +475,7 @@ public class ZoneVolumeSpecTest {
|
||||
assertEquals(10, volume.getCornerTwo().getTypeId());
|
||||
assertEquals((byte)2, volume.getCornerTwo().getData());
|
||||
}
|
||||
|
||||
|
||||
@Test
|
||||
public void setSoutheast_whenCreatingAndNoCorner2IsSet_ButCorner1IsAlreadySet_AndNewCornerBlockIsToWestOfCorner1_shouldThrowNotSoutheastException() throws TooSmallException, TooBigException{
|
||||
// Arrange
|
||||
@ -499,25 +491,25 @@ public class ZoneVolumeSpecTest {
|
||||
when(blockMock.getZ()).thenReturn(64); // further west
|
||||
when(blockMock.getTypeId()).thenReturn(10);
|
||||
when(blockMock.getData()).thenReturn((byte)2);
|
||||
|
||||
|
||||
// Act
|
||||
BlockInfo existingCorner1 = new BlockInfo(0, 64, 0, 4, (byte)4);
|
||||
volume.setCornerOne(existingCorner1); // corner 1 already set
|
||||
boolean failed = false;
|
||||
try {
|
||||
volume.setSoutheast(blockMock);
|
||||
volume.setSoutheast(blockMock);
|
||||
}
|
||||
catch(NotSoutheastException e) {
|
||||
failed = true;
|
||||
}
|
||||
|
||||
|
||||
// Assert
|
||||
// first corner shouldn't move
|
||||
assertTrue(failed);
|
||||
assertEquals(null, volume.getCornerTwo());
|
||||
assertEquals(existingCorner1, volume.getCornerOne());
|
||||
}
|
||||
|
||||
|
||||
@Test
|
||||
public void setSoutheast_whenCreatingAndNoCorner2IsSet_ButCorner1IsAlreadySet_AndNewCornerBlockIsToNorthOfCorner1_shouldThrowNotSoutheastException() throws TooSmallException, TooBigException{
|
||||
// Arrange
|
||||
@ -533,25 +525,25 @@ public class ZoneVolumeSpecTest {
|
||||
when(blockMock.getZ()).thenReturn(-64); // further east
|
||||
when(blockMock.getTypeId()).thenReturn(10);
|
||||
when(blockMock.getData()).thenReturn((byte)2);
|
||||
|
||||
|
||||
// Act
|
||||
BlockInfo existingCorner1 = new BlockInfo(0, 64, 0, 4, (byte)4);
|
||||
volume.setCornerOne(existingCorner1); // corner 1 already set
|
||||
boolean failed = false;
|
||||
try {
|
||||
volume.setSoutheast(blockMock);
|
||||
volume.setSoutheast(blockMock);
|
||||
}
|
||||
catch(NotSoutheastException e) {
|
||||
failed = true;
|
||||
}
|
||||
|
||||
|
||||
// Assert
|
||||
// first corner shouldn't move
|
||||
assertTrue(failed);
|
||||
assertEquals(null, volume.getCornerTwo());
|
||||
assertEquals(existingCorner1, volume.getCornerOne());
|
||||
}
|
||||
|
||||
|
||||
@Test
|
||||
public void setSoutheast_whenCreatingAndCorner2AlreadySet_shouldSetCorner1AtBottom() throws NotSoutheastException, TooSmallException, TooBigException{ // se always goes to bottom
|
||||
// Arrange
|
||||
@ -567,12 +559,12 @@ public class ZoneVolumeSpecTest {
|
||||
when(blockMock.getZ()).thenReturn(-64); // further east
|
||||
when(blockMock.getTypeId()).thenReturn(10);
|
||||
when(blockMock.getData()).thenReturn((byte)2);
|
||||
|
||||
|
||||
// Act
|
||||
BlockInfo existingCorner2 = new BlockInfo(0, 64, 0, 4, (byte)4);
|
||||
volume.setCornerTwo(existingCorner2); // corner 2 already set
|
||||
volume.setSoutheast(blockMock);
|
||||
|
||||
|
||||
// Assert
|
||||
// first corner shouldn't move
|
||||
assertEquals(0, volume.getCornerTwo().getX());
|
||||
@ -580,14 +572,14 @@ public class ZoneVolumeSpecTest {
|
||||
assertEquals(0, volume.getCornerTwo().getZ());
|
||||
assertEquals(4, volume.getCornerTwo().getTypeId());
|
||||
assertEquals((byte)4, volume.getCornerTwo().getData());
|
||||
|
||||
|
||||
assertEquals(64, volume.getCornerOne().getX());
|
||||
assertEquals(0, volume.getCornerOne().getY()); // the new corner should shoot down
|
||||
assertEquals(-64, volume.getCornerOne().getZ());
|
||||
assertEquals(10, volume.getCornerOne().getTypeId());
|
||||
assertEquals((byte)2, volume.getCornerOne().getData());
|
||||
}
|
||||
|
||||
|
||||
@Test
|
||||
public void setSoutheast_whenCreating_AndCorner2AlreadySet_ButNewCornerBlockIsToWestOfCorner2_shouldThrowNotSoutheastException() throws TooSmallException, TooBigException{
|
||||
// Arrange
|
||||
@ -603,25 +595,25 @@ public class ZoneVolumeSpecTest {
|
||||
when(blockMock.getZ()).thenReturn(64); // further west
|
||||
when(blockMock.getTypeId()).thenReturn(10);
|
||||
when(blockMock.getData()).thenReturn((byte)2);
|
||||
|
||||
|
||||
// Act
|
||||
BlockInfo existingCorner2 = new BlockInfo(0, 64, 0, 4, (byte)4);
|
||||
volume.setCornerTwo(existingCorner2); // corner 2 already set
|
||||
boolean failed = false;
|
||||
try {
|
||||
volume.setSoutheast(blockMock);
|
||||
volume.setSoutheast(blockMock);
|
||||
}
|
||||
catch(NotSoutheastException e) {
|
||||
failed = true;
|
||||
}
|
||||
|
||||
|
||||
// Assert
|
||||
// first corner shouldn't move
|
||||
assertTrue(failed);
|
||||
assertEquals(null, volume.getCornerOne());
|
||||
assertEquals(existingCorner2, volume.getCornerTwo());
|
||||
}
|
||||
|
||||
|
||||
@Test
|
||||
public void setSoutheast_whenCreating_AndCorner2AlreadySet_ButNewCornerBlockIsToNorthOfCorner2_shouldThrowNotSoutheastException() throws TooSmallException, TooBigException{
|
||||
// Arrange
|
||||
@ -637,25 +629,25 @@ public class ZoneVolumeSpecTest {
|
||||
when(blockMock.getZ()).thenReturn(-64); // further east
|
||||
when(blockMock.getTypeId()).thenReturn(10);
|
||||
when(blockMock.getData()).thenReturn((byte)2);
|
||||
|
||||
|
||||
// Act
|
||||
BlockInfo existingCorner2 = new BlockInfo(0, 64, 0, 4, (byte)4);
|
||||
volume.setCornerTwo(existingCorner2); // corner 2 already set
|
||||
boolean failed = false;
|
||||
try {
|
||||
volume.setSoutheast(blockMock);
|
||||
volume.setSoutheast(blockMock);
|
||||
}
|
||||
catch(NotSoutheastException e) {
|
||||
failed = true;
|
||||
}
|
||||
|
||||
|
||||
// Assert
|
||||
// first corner shouldn't move
|
||||
assertTrue(failed);
|
||||
assertEquals(null, volume.getCornerOne());
|
||||
assertEquals(existingCorner2, volume.getCornerTwo());
|
||||
}
|
||||
|
||||
|
||||
@Test
|
||||
public void setSoutheast_whenChangingVolumeWithCorner1NwCorner2Se_shouldMoveCorner2() throws NotSoutheastException, TooSmallException, TooBigException{
|
||||
// Arrange
|
||||
@ -671,14 +663,14 @@ public class ZoneVolumeSpecTest {
|
||||
when(blockMock.getZ()).thenReturn(-64); // further east
|
||||
when(blockMock.getTypeId()).thenReturn(10);
|
||||
when(blockMock.getData()).thenReturn((byte)2);
|
||||
|
||||
|
||||
// Act
|
||||
BlockInfo existingCorner1 = new BlockInfo(-32, 32, 32, 2, (byte)2); // corner 1 at minX and maxZ (nw)
|
||||
volume.setCornerOne(existingCorner1); // corner 1 already set
|
||||
BlockInfo existingCorner2 = new BlockInfo(32, 96, -32, 4, (byte)4); // corner 2 at maxX and minZ (se)
|
||||
volume.setCornerTwo(existingCorner2); // corner 2 already set
|
||||
volume.setSoutheast(blockMock);
|
||||
|
||||
|
||||
// Assert
|
||||
// first corner shouldn't move
|
||||
assertEquals(-32, volume.getCornerOne().getX());
|
||||
@ -686,7 +678,7 @@ public class ZoneVolumeSpecTest {
|
||||
assertEquals(32, volume.getCornerOne().getZ());
|
||||
assertEquals(2, volume.getCornerOne().getTypeId());
|
||||
assertEquals((byte)2, volume.getCornerOne().getData());
|
||||
|
||||
|
||||
// second corner should move but not along y
|
||||
assertEquals(64, volume.getCornerTwo().getX());
|
||||
assertEquals(96, volume.getCornerTwo().getY());
|
||||
@ -694,7 +686,7 @@ public class ZoneVolumeSpecTest {
|
||||
assertEquals(4, volume.getCornerTwo().getTypeId());
|
||||
assertEquals((byte)4, volume.getCornerTwo().getData());
|
||||
}
|
||||
|
||||
|
||||
@Test
|
||||
public void setSoutheast_whenChangingVolumeWithCorner1SeCorner2Nw_shouldMoveCorner1() throws NotSoutheastException, TooSmallException, TooBigException{
|
||||
// Arrange
|
||||
@ -710,14 +702,14 @@ public class ZoneVolumeSpecTest {
|
||||
when(blockMock.getZ()).thenReturn(-64); // further east
|
||||
when(blockMock.getTypeId()).thenReturn(10);
|
||||
when(blockMock.getData()).thenReturn((byte)2);
|
||||
|
||||
|
||||
// Act
|
||||
BlockInfo existingCorner1 = new BlockInfo(32, 32, -32, 2, (byte)2); // corner 1 at maxX and minZ (se)
|
||||
volume.setCornerOne(existingCorner1); // corner 1 already set
|
||||
BlockInfo existingCorner2 = new BlockInfo(-32, 96, 32, 4, (byte)4); // corner 2 at minX and maxZ (nw)
|
||||
volume.setCornerTwo(existingCorner2); // corner 2 already set
|
||||
volume.setSoutheast(blockMock);
|
||||
|
||||
|
||||
// Assert
|
||||
// first corner should move but not along y
|
||||
assertEquals(64, volume.getCornerOne().getX());
|
||||
@ -725,7 +717,7 @@ public class ZoneVolumeSpecTest {
|
||||
assertEquals(-64, volume.getCornerOne().getZ());
|
||||
assertEquals(2, volume.getCornerOne().getTypeId());
|
||||
assertEquals((byte)2, volume.getCornerOne().getData());
|
||||
|
||||
|
||||
// second corner shouldn't move
|
||||
assertEquals(-32, volume.getCornerTwo().getX());
|
||||
assertEquals(96, volume.getCornerTwo().getY());
|
||||
@ -733,7 +725,7 @@ public class ZoneVolumeSpecTest {
|
||||
assertEquals(4, volume.getCornerTwo().getTypeId());
|
||||
assertEquals((byte)4, volume.getCornerTwo().getData());
|
||||
}
|
||||
|
||||
|
||||
@Test
|
||||
public void setSoutheast_whenChangingVolumeWithCorner1NeCorner2Sw_shouldMoveCorner1ZAndCorner2X() throws NotSoutheastException, TooSmallException, TooBigException{
|
||||
// Arrange
|
||||
@ -749,14 +741,14 @@ public class ZoneVolumeSpecTest {
|
||||
when(blockMock.getZ()).thenReturn(-64); // further east
|
||||
when(blockMock.getTypeId()).thenReturn(10);
|
||||
when(blockMock.getData()).thenReturn((byte)2);
|
||||
|
||||
|
||||
// Act
|
||||
BlockInfo existingCorner1 = new BlockInfo(-32, 32, -32, 2, (byte)2); // corner 1 at minX and minZ (ne)
|
||||
volume.setCornerOne(existingCorner1); // corner 1 already set
|
||||
BlockInfo existingCorner2 = new BlockInfo(32, 96, 32, 4, (byte)4); // corner 2 at maxX and maxZ (sw)
|
||||
volume.setCornerTwo(existingCorner2); // corner 2 already set
|
||||
volume.setSoutheast(blockMock);
|
||||
|
||||
|
||||
// Assert
|
||||
// first corner should move along z but not along x or y
|
||||
assertEquals(-32, volume.getCornerOne().getX());
|
||||
@ -764,7 +756,7 @@ public class ZoneVolumeSpecTest {
|
||||
assertEquals(-64, volume.getCornerOne().getZ());
|
||||
assertEquals(2, volume.getCornerOne().getTypeId());
|
||||
assertEquals((byte)2, volume.getCornerOne().getData());
|
||||
|
||||
|
||||
// second corner should move along x but not along y or z
|
||||
assertEquals(64, volume.getCornerTwo().getX());
|
||||
assertEquals(96, volume.getCornerTwo().getY());
|
||||
@ -772,7 +764,7 @@ public class ZoneVolumeSpecTest {
|
||||
assertEquals(4, volume.getCornerTwo().getTypeId());
|
||||
assertEquals((byte)4, volume.getCornerTwo().getData());
|
||||
}
|
||||
|
||||
|
||||
@Test
|
||||
public void setSoutheast_whenChangingVolumeWithCorner1SwCorner2Ne_shouldMoveCorner1XAndCorner2Z() throws NotSoutheastException, TooSmallException, TooBigException{
|
||||
// Arrange
|
||||
@ -788,14 +780,14 @@ public class ZoneVolumeSpecTest {
|
||||
when(blockMock.getZ()).thenReturn(-64); // further east
|
||||
when(blockMock.getTypeId()).thenReturn(10);
|
||||
when(blockMock.getData()).thenReturn((byte)2);
|
||||
|
||||
|
||||
// Act
|
||||
BlockInfo existingCorner1 = new BlockInfo(32, 32, 32, 2, (byte)2); // corner 1 at maxX and maxZ (sw)
|
||||
volume.setCornerOne(existingCorner1); // corner 1 already set
|
||||
BlockInfo existingCorner2 = new BlockInfo(-32, 96, -32, 4, (byte)4); // corner 2 at minX and minZ (ne)
|
||||
volume.setCornerTwo(existingCorner2); // corner 2 already set
|
||||
volume.setSoutheast(blockMock);
|
||||
|
||||
|
||||
// Assert
|
||||
// first corner should move along x but not along y or z
|
||||
assertEquals(64, volume.getCornerOne().getX());
|
||||
@ -803,7 +795,7 @@ public class ZoneVolumeSpecTest {
|
||||
assertEquals(32, volume.getCornerOne().getZ());
|
||||
assertEquals(2, volume.getCornerOne().getTypeId());
|
||||
assertEquals((byte)2, volume.getCornerOne().getData());
|
||||
|
||||
|
||||
// second corner should move along z but not along x or y
|
||||
assertEquals(-32, volume.getCornerTwo().getX());
|
||||
assertEquals(96, volume.getCornerTwo().getY());
|
||||
@ -811,13 +803,13 @@ public class ZoneVolumeSpecTest {
|
||||
assertEquals(4, volume.getCornerTwo().getTypeId());
|
||||
assertEquals((byte)4, volume.getCornerTwo().getData());
|
||||
}
|
||||
|
||||
|
||||
// getSoutheastX
|
||||
|
||||
|
||||
// getSoutheastZ
|
||||
|
||||
|
||||
// setCornerOne
|
||||
|
||||
|
||||
// setCornerTwo
|
||||
|
||||
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user