mirror of
https://github.com/taoneill/war.git
synced 2025-01-23 15:51:22 +01:00
Plugged in ZoneVolume for cuboid support. Added ZoneSetter to encapsulate the performSetZone operations and error handling. Still probably broken and missing wand support.
This commit is contained in:
parent
6efbf2f62d
commit
b652d12849
@ -33,6 +33,7 @@ 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;
|
||||
@ -733,131 +734,157 @@ public class War extends JavaPlugin {
|
||||
public void performSetZone(Player player, String[] arguments) {
|
||||
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")))) {
|
||||
this.badMsg(player, "Usage: /setzone <warzone-name> <'southeast'/'northwest'/'se'/'nw'>. " +
|
||||
&& !arguments[1].equals("se") && !arguments[1].equals("nw")
|
||||
&& !arguments[1].equals("corner1") && !arguments[1].equals("corner2")
|
||||
&& !arguments[1].equals("c1") && !arguments[1].equals("c2")
|
||||
&& !arguments[1].equals("pos1") && !arguments[1].equals("pos2")))) {
|
||||
this.badMsg(player, "Usage: =<Classic mode>= /setzone <warzone-name> <'northwest'/'southeast'/'nw'/'se'> (NW defaults to top block, SE to bottom). " +
|
||||
"=<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 zone if the outline is correct.");
|
||||
"Saves the zone blocks if the outline is valid.");
|
||||
} else {
|
||||
Warzone warzone = this.findWarzone(arguments[0]);
|
||||
String msgString = "";
|
||||
Location oldSoutheast = null;
|
||||
Location oldNorthwest = null;
|
||||
boolean fail = false;
|
||||
if(warzone == null) {
|
||||
// create the warzone
|
||||
warzone = new Warzone(this, player.getLocation().getWorld(), arguments[0]);
|
||||
this.getIncompleteZones().add(warzone);
|
||||
//WarMapper.save(this);
|
||||
if(arguments[1].equals("northwest") || arguments[1].equals("nw")) {
|
||||
warzone.setNorthwest(player.getLocation());
|
||||
this.msg(player, "Warzone " + warzone.getName() + " created. Northwesternmost point set to x:"
|
||||
+ (int)warzone.getNorthwest().getBlockX() + " z:" + (int)warzone.getNorthwest().getBlockZ() + ".");
|
||||
} else {
|
||||
warzone.setSoutheast(player.getLocation());
|
||||
this.msg(player, "Warzone " + warzone.getName() + " created. Southeasternmost point set to x:"
|
||||
+ (int)warzone.getSoutheast().getBlockX() + " z:" + (int)warzone.getSoutheast().getBlockZ() + ".");
|
||||
}
|
||||
//WarzoneMapper.save(this, warzone, false);
|
||||
} else {
|
||||
// change existing warzone
|
||||
if(arguments[1].equals("northwest") || arguments[1].equals("nw")) {
|
||||
if(warzone.getSoutheast() != null
|
||||
&& (player.getLocation().getBlockX() >= warzone.getSoutheast().getBlockX()
|
||||
|| player.getLocation().getBlockZ() <= warzone.getSoutheast().getBlockZ())) {
|
||||
this.badMsg(player, "You must place that corner northwest relative to the existing southeast corner!");
|
||||
} else if (warzone.getSoutheast() == null){
|
||||
// just moving the single nw corner we've placed so far
|
||||
warzone.setNorthwest(player.getLocation());
|
||||
}else {
|
||||
if(warzone.getVolume().isSaved()) {
|
||||
msg(player, "Resetting " + warzone.getName() + " blocks.");
|
||||
if(warzone.getLobby() != null) {
|
||||
warzone.getLobby().getVolume().resetBlocks();
|
||||
}
|
||||
int reset = warzone.getVolume().resetBlocks();
|
||||
|
||||
msgString = reset + " blocks reset. ";
|
||||
oldNorthwest = warzone.getNorthwest();
|
||||
}
|
||||
warzone.setNorthwest(player.getLocation());
|
||||
}
|
||||
} else if(arguments[1].equals("southeast") || arguments[1].equals("se")) {
|
||||
if(warzone.getNorthwest() != null
|
||||
&& (player.getLocation().getBlockX() <= warzone.getNorthwest().getBlockX()
|
||||
|| player.getLocation().getBlockZ() >= warzone.getNorthwest().getBlockZ())) {
|
||||
this.badMsg(player, "You must place that corner southeast relative to the existing northwest corner! ");
|
||||
fail = true;
|
||||
} else if (warzone.getNorthwest() == null){
|
||||
// just moving the single se corner we've placed so far
|
||||
warzone.setSoutheast(player.getLocation());
|
||||
} else {
|
||||
if(warzone.getVolume().isSaved()) {
|
||||
// we're resizing a zone
|
||||
msg(player, "Resetting zone " + warzone.getName() + " blocks.");
|
||||
if(warzone.getLobby() != null) {
|
||||
warzone.getLobby().getVolume().resetBlocks();
|
||||
}
|
||||
int reset = warzone.getVolume().resetBlocks();
|
||||
|
||||
msgString = reset + " blocks reset. ";
|
||||
oldSoutheast = warzone.getSoutheast();
|
||||
}
|
||||
warzone.setSoutheast(player.getLocation());
|
||||
}
|
||||
}
|
||||
ZoneSetter setter = new ZoneSetter(this, player, arguments[0]);
|
||||
if(arguments[1].equals("northwest") || arguments[1].equals("nw")) {
|
||||
setter.placeNorthwest();
|
||||
} else if (arguments[1].equals("southeast") || arguments[1].equals("se")) {
|
||||
setter.placeSoutheast();
|
||||
} else if (arguments[1].equals("corner1") || arguments[1].equals("c1") || arguments[1].equals("pos1")) {
|
||||
setter.placeCorner1();
|
||||
} else if (arguments[1].equals("corner2") || arguments[1].equals("c2") || arguments[1].equals("pos2")) {
|
||||
setter.placeCorner2();
|
||||
}
|
||||
if(warzone.getNorthwest() == null) {
|
||||
msg(player, msgString + "Still missing northwesternmost point.");
|
||||
} else if(warzone.getSoutheast() == null) {
|
||||
msg(player, msgString + "Still missing southeasternmost point.");
|
||||
} else if (warzone.tooBig()) {
|
||||
badMsg(player, msgString + "Warzone " + warzone.getName() + " is too Big. Max north-south size: 750. Max east-west size: 750.");
|
||||
} else if (warzone.tooSmall()) {
|
||||
badMsg(player, msgString + "Warzone " + warzone.getName() + " is too small. Min north-south size: 10. Min east-west size: 10.");
|
||||
} else if(!fail && warzone.ready()) {
|
||||
if(!this.warzones.contains(warzone)) {
|
||||
this.addWarzone(warzone);
|
||||
}
|
||||
if(this.incompleteZones.contains(warzone)) {
|
||||
this.incompleteZones.remove(warzone);
|
||||
}
|
||||
WarMapper.save(this);
|
||||
msgString += "New zone outline ok. Saving new warzone blocks...";
|
||||
msg(player, msgString);
|
||||
warzone.saveState(false); // we just changed the volume, cant reset walls
|
||||
if(warzone.getLobby() == null) {
|
||||
// Set default lobby on south side
|
||||
ZoneLobby lobby = new ZoneLobby(this, warzone, BlockFace.SOUTH);
|
||||
warzone.setLobby(lobby);
|
||||
if(warHub != null) { // warhub has to change
|
||||
warHub.getVolume().resetBlocks();
|
||||
warHub.initialize();
|
||||
}
|
||||
this.msg(player, "Default lobby created on south side of zone. Use /setzonelobby <n/s/e/w> to change its position.");
|
||||
} else {
|
||||
// gotta move the lobby
|
||||
warzone.getLobby().changeWall(warzone.getLobby().getWall());
|
||||
}
|
||||
warzone.initializeZone();
|
||||
WarzoneMapper.save(this, warzone, true);
|
||||
this.msg(player, "Warzone saved. Use /setteam, /setmonument and /savezone to configure the zone.");
|
||||
}
|
||||
|
||||
if(warzone.getVolume().isSaved()
|
||||
&& (warzone.tooBig() || warzone.tooSmall())
|
||||
&& (oldNorthwest != null || oldSoutheast != null) )
|
||||
{
|
||||
// we resized but the result is too small or too big. Restore the old corner and reinit the zone.
|
||||
if(oldNorthwest != null) {
|
||||
warzone.setNorthwest(oldNorthwest);
|
||||
} else if (oldSoutheast != null) {
|
||||
warzone.setSoutheast(oldSoutheast);
|
||||
}
|
||||
warzone.initializeZone();
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
// Pre 1.5
|
||||
// public void performSetZone(Player player, String[] arguments) {
|
||||
// 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")))) {
|
||||
// this.badMsg(player, "Usage: /setzone <warzone-name> <'southeast'/'northwest'/'se'/'nw'>. " +
|
||||
// "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 zone if the outline is correct.");
|
||||
// } else {
|
||||
// Warzone warzone = this.findWarzone(arguments[0]);
|
||||
// String msgString = "";
|
||||
// Location oldSoutheast = null;
|
||||
// Location oldNorthwest = null;
|
||||
// boolean fail = false;
|
||||
// if(warzone == null) {
|
||||
// // create the warzone
|
||||
// warzone = new Warzone(this, player.getLocation().getWorld(), arguments[0]);
|
||||
// this.getIncompleteZones().add(warzone);
|
||||
// //WarMapper.save(this);
|
||||
// if(arguments[1].equals("northwest") || arguments[1].equals("nw")) {
|
||||
// warzone.setNorthwest(player.getLocation());
|
||||
// this.msg(player, "Warzone " + warzone.getName() + " created. Northwesternmost point set to x:"
|
||||
// + (int)warzone.getNorthwest().getBlockX() + " z:" + (int)warzone.getNorthwest().getBlockZ() + ".");
|
||||
// } else {
|
||||
// warzone.setSoutheast(player.getLocation());
|
||||
// this.msg(player, "Warzone " + warzone.getName() + " created. Southeasternmost point set to x:"
|
||||
// + (int)warzone.getSoutheast().getBlockX() + " z:" + (int)warzone.getSoutheast().getBlockZ() + ".");
|
||||
// }
|
||||
// //WarzoneMapper.save(this, warzone, false);
|
||||
// } else {
|
||||
// // change existing warzone
|
||||
// if(arguments[1].equals("northwest") || arguments[1].equals("nw")) {
|
||||
// if(warzone.getSoutheast() != null
|
||||
// && (player.getLocation().getBlockX() >= warzone.getSoutheast().getBlockX()
|
||||
// || player.getLocation().getBlockZ() <= warzone.getSoutheast().getBlockZ())) {
|
||||
// this.badMsg(player, "You must place that corner northwest relative to the existing southeast corner!");
|
||||
// } else if (warzone.getSoutheast() == null){
|
||||
// // just moving the single nw corner we've placed so far
|
||||
// warzone.setNorthwest(player.getLocation());
|
||||
// }else {
|
||||
// if(warzone.getVolume().isSaved()) {
|
||||
// msg(player, "Resetting " + warzone.getName() + " blocks.");
|
||||
// if(warzone.getLobby() != null) {
|
||||
// warzone.getLobby().getVolume().resetBlocks();
|
||||
// }
|
||||
// int reset = warzone.getVolume().resetBlocks();
|
||||
//
|
||||
// msgString = reset + " blocks reset. ";
|
||||
// oldNorthwest = warzone.getNorthwest();
|
||||
// }
|
||||
// warzone.setNorthwest(player.getLocation());
|
||||
// }
|
||||
// } else if(arguments[1].equals("southeast") || arguments[1].equals("se")) {
|
||||
// if(warzone.getNorthwest() != null
|
||||
// && (player.getLocation().getBlockX() <= warzone.getNorthwest().getBlockX()
|
||||
// || player.getLocation().getBlockZ() >= warzone.getNorthwest().getBlockZ())) {
|
||||
// this.badMsg(player, "You must place that corner southeast relative to the existing northwest corner! ");
|
||||
// fail = true;
|
||||
// } else if (warzone.getNorthwest() == null){
|
||||
// // just moving the single se corner we've placed so far
|
||||
// warzone.setSoutheast(player.getLocation());
|
||||
// } else {
|
||||
// if(warzone.getVolume().isSaved()) {
|
||||
// // we're resizing a zone
|
||||
// msg(player, "Resetting zone " + warzone.getName() + " blocks.");
|
||||
// if(warzone.getLobby() != null) {
|
||||
// warzone.getLobby().getVolume().resetBlocks();
|
||||
// }
|
||||
// int reset = warzone.getVolume().resetBlocks();
|
||||
//
|
||||
// msgString = reset + " blocks reset. ";
|
||||
// oldSoutheast = warzone.getSoutheast();
|
||||
// }
|
||||
// warzone.setSoutheast(player.getLocation());
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
// if(warzone.getNorthwest() == null) {
|
||||
// msg(player, msgString + "Still missing northwesternmost point.");
|
||||
// } else if(warzone.getSoutheast() == null) {
|
||||
// msg(player, msgString + "Still missing southeasternmost point.");
|
||||
// } else if (warzone.tooBig()) {
|
||||
// badMsg(player, msgString + "Warzone " + warzone.getName() + " is too Big. Max north-south size: 750. Max east-west size: 750.");
|
||||
// } else if (warzone.tooSmall()) {
|
||||
// badMsg(player, msgString + "Warzone " + warzone.getName() + " is too small. Min north-south size: 10. Min east-west size: 10.");
|
||||
// } else if(!fail && warzone.ready()) {
|
||||
// if(!this.warzones.contains(warzone)) {
|
||||
// this.addWarzone(warzone);
|
||||
// }
|
||||
// if(this.incompleteZones.contains(warzone)) {
|
||||
// this.incompleteZones.remove(warzone);
|
||||
// }
|
||||
// WarMapper.save(this);
|
||||
// msgString += "New zone outline ok. Saving new warzone blocks...";
|
||||
// msg(player, msgString);
|
||||
// warzone.saveState(false); // we just changed the volume, cant reset walls
|
||||
// if(warzone.getLobby() == null) {
|
||||
// // Set default lobby on south side
|
||||
// ZoneLobby lobby = new ZoneLobby(this, warzone, BlockFace.SOUTH);
|
||||
// warzone.setLobby(lobby);
|
||||
// if(warHub != null) { // warhub has to change
|
||||
// warHub.getVolume().resetBlocks();
|
||||
// warHub.initialize();
|
||||
// }
|
||||
// this.msg(player, "Default lobby created on south side of zone. Use /setzonelobby <n/s/e/w> to change its position.");
|
||||
// } else {
|
||||
// // gotta move the lobby
|
||||
// warzone.getLobby().changeWall(warzone.getLobby().getWall());
|
||||
// }
|
||||
// warzone.initializeZone();
|
||||
// WarzoneMapper.save(this, warzone, true);
|
||||
// this.msg(player, "Warzone saved. Use /setteam, /setmonument and /savezone to configure the zone.");
|
||||
// }
|
||||
//
|
||||
// if(warzone.getVolume().isSaved()
|
||||
// && (warzone.tooBig() || warzone.tooSmall())
|
||||
// && (oldNorthwest != null || oldSoutheast != null) )
|
||||
// {
|
||||
// // we resized but the result is too small or too big. Restore the old corner and reinit the zone.
|
||||
// if(oldNorthwest != null) {
|
||||
// warzone.setNorthwest(oldNorthwest);
|
||||
// } else if (oldSoutheast != null) {
|
||||
// warzone.setSoutheast(oldSoutheast);
|
||||
// }
|
||||
// warzone.initializeZone();
|
||||
// }
|
||||
//
|
||||
// }
|
||||
// }
|
||||
|
||||
public void performNextBattle(Player player) {
|
||||
if(!this.inAnyWarzone(player.getLocation())) {
|
||||
|
@ -6,6 +6,7 @@ package com.tommytony.war;
|
||||
*
|
||||
*/
|
||||
public class TeamSpawnStyles {
|
||||
public static final String INVISIBLE = "invisible";
|
||||
public static final String SMALL = "small";
|
||||
public static final String FLAT = "flat";
|
||||
public static final String BIG = "big";
|
||||
|
@ -23,6 +23,7 @@ import com.tommytony.war.jobs.ScoreCapReachedJob;
|
||||
import com.tommytony.war.utils.InventoryStash;
|
||||
import com.tommytony.war.volumes.BlockInfo;
|
||||
import com.tommytony.war.volumes.VerticalVolume;
|
||||
import com.tommytony.war.volumes.ZoneVolume;
|
||||
|
||||
/**
|
||||
*
|
||||
@ -31,9 +32,9 @@ import com.tommytony.war.volumes.VerticalVolume;
|
||||
*/
|
||||
public class Warzone {
|
||||
private String name;
|
||||
private VerticalVolume volume;
|
||||
private Location northwest;
|
||||
private Location southeast;
|
||||
private ZoneVolume volume;
|
||||
// private Location northwest;
|
||||
// private Location southeast;
|
||||
private final List<Team> teams = new ArrayList<Team>();
|
||||
private final List<Monument> monuments = new ArrayList<Monument>();
|
||||
|
||||
@ -80,24 +81,11 @@ public class Warzone {
|
||||
this.setDropLootOnDeath(war.isDefaultDropLootOnDeath());
|
||||
this.setUnbreakableZoneBlocks(war.isDefaultUnbreakableZoneBlocks());
|
||||
this.setNoCreatures(war.getDefaultNoCreatures());
|
||||
this.volume = new VerticalVolume(name, war, this.getWorld());
|
||||
this.volume = new ZoneVolume(name, war, this.getWorld());
|
||||
}
|
||||
|
||||
public boolean ready() {
|
||||
if(getNorthwest() != null && getSoutheast() != null
|
||||
&& !tooSmall() && !tooBig()) return true;
|
||||
return false;
|
||||
}
|
||||
|
||||
public boolean tooSmall() {
|
||||
if((getSoutheast().getBlockX() - getNorthwest().getBlockX() < 10)
|
||||
|| (getNorthwest().getBlockZ() - getSoutheast().getBlockZ() < 10)) return true;
|
||||
return false;
|
||||
}
|
||||
|
||||
public boolean tooBig() {
|
||||
if((getSoutheast().getBlockX() - getNorthwest().getBlockX() > 750)
|
||||
|| (getNorthwest().getBlockZ() - getSoutheast().getBlockZ() > 750)) return true;
|
||||
if(volume.hasTwoCorners() && !volume.tooSmall() && !volume.tooBig()) return true;
|
||||
return false;
|
||||
}
|
||||
|
||||
@ -120,50 +108,50 @@ public class Warzone {
|
||||
return name;
|
||||
}
|
||||
|
||||
public void setNorthwest(Location northwest) {
|
||||
this.northwest = northwest;
|
||||
this.volume.setCornerOne(world.getBlockAt(northwest.getBlockX(), northwest.getBlockY(), northwest.getBlockZ()));
|
||||
addNorthwestCursorBlocks();
|
||||
}
|
||||
|
||||
private void addNorthwestCursorBlocks() {
|
||||
Block topNWBlock = this.world.getBlockAt(this.northwest.getBlockX(), this.northwest.getBlockY()-1, this.northwest.getBlockZ());
|
||||
BlockInfo[] originalNorthwestBlocks = new BlockInfo[3];
|
||||
originalNorthwestBlocks[0] = new BlockInfo(topNWBlock); // save blocks for reset
|
||||
originalNorthwestBlocks[1] = new BlockInfo(topNWBlock.getFace(BlockFace.EAST));
|
||||
originalNorthwestBlocks[2] = new BlockInfo(topNWBlock.getFace(BlockFace.SOUTH));
|
||||
topNWBlock.setType(Material.GLASS);
|
||||
topNWBlock.getFace(BlockFace.EAST).setType(Material.GLASS);
|
||||
topNWBlock.getFace(BlockFace.SOUTH).setType(Material.GLASS);
|
||||
this.war.getServer().getScheduler().scheduleSyncDelayedTask(this.war, new ResetCursorJob(topNWBlock, originalNorthwestBlocks, false), 75);
|
||||
}
|
||||
|
||||
public Location getNorthwest() {
|
||||
return northwest;
|
||||
}
|
||||
|
||||
public void setSoutheast(Location southeast) {
|
||||
this.southeast = southeast;
|
||||
this.volume.setCornerTwo(world.getBlockAt(southeast.getBlockX(), southeast.getBlockY(), southeast.getBlockZ()));
|
||||
addSoutheastCursorBlocks();
|
||||
}
|
||||
|
||||
private void addSoutheastCursorBlocks() {
|
||||
Block topSEBlock = this.world.getBlockAt(this.southeast.getBlockX(), this.southeast.getBlockY()-1, this.southeast.getBlockZ());
|
||||
BlockInfo[] originalSoutheastBlocks = new BlockInfo[3];
|
||||
originalSoutheastBlocks[0] = new BlockInfo(topSEBlock); // save block for reset
|
||||
originalSoutheastBlocks[1] = new BlockInfo(topSEBlock.getFace(BlockFace.WEST));
|
||||
originalSoutheastBlocks[2] = new BlockInfo(topSEBlock.getFace(BlockFace.NORTH));
|
||||
topSEBlock.setType(Material.GLASS);
|
||||
topSEBlock.getFace(BlockFace.WEST).setType(Material.GLASS);
|
||||
topSEBlock.getFace(BlockFace.NORTH).setType(Material.GLASS);
|
||||
this.war.getServer().getScheduler().scheduleSyncDelayedTask(this.war, new ResetCursorJob(topSEBlock, originalSoutheastBlocks, true), 75);
|
||||
}
|
||||
|
||||
|
||||
public Location getSoutheast() {
|
||||
return southeast;
|
||||
}
|
||||
// public void setNorthwest(Location northwest) {
|
||||
// this.northwest = northwest;
|
||||
// this.volume.setCornerOne(world.getBlockAt(northwest.getBlockX(), northwest.getBlockY(), northwest.getBlockZ()));
|
||||
// addNorthwestCursorBlocks();
|
||||
// }
|
||||
//
|
||||
// private void addNorthwestCursorBlocks() {
|
||||
// Block topNWBlock = this.world.getBlockAt(this.northwest.getBlockX(), this.northwest.getBlockY()-1, this.northwest.getBlockZ());
|
||||
// BlockInfo[] originalNorthwestBlocks = new BlockInfo[3];
|
||||
// originalNorthwestBlocks[0] = new BlockInfo(topNWBlock); // save blocks for reset
|
||||
// originalNorthwestBlocks[1] = new BlockInfo(topNWBlock.getFace(BlockFace.EAST));
|
||||
// originalNorthwestBlocks[2] = new BlockInfo(topNWBlock.getFace(BlockFace.SOUTH));
|
||||
// topNWBlock.setType(Material.GLASS);
|
||||
// topNWBlock.getFace(BlockFace.EAST).setType(Material.GLASS);
|
||||
// topNWBlock.getFace(BlockFace.SOUTH).setType(Material.GLASS);
|
||||
// this.war.getServer().getScheduler().scheduleSyncDelayedTask(this.war, new ResetCursorJob(topNWBlock, originalNorthwestBlocks, false), 75);
|
||||
// }
|
||||
//
|
||||
// public Location getNorthwest() {
|
||||
// return northwest;
|
||||
// }
|
||||
//
|
||||
// public void setSoutheast(Location southeast) {
|
||||
// this.southeast = southeast;
|
||||
// this.volume.setCornerTwo(world.getBlockAt(southeast.getBlockX(), southeast.getBlockY(), southeast.getBlockZ()));
|
||||
// addSoutheastCursorBlocks();
|
||||
// }
|
||||
//
|
||||
// private void addSoutheastCursorBlocks() {
|
||||
// Block topSEBlock = this.world.getBlockAt(this.southeast.getBlockX(), this.southeast.getBlockY()-1, this.southeast.getBlockZ());
|
||||
// BlockInfo[] originalSoutheastBlocks = new BlockInfo[3];
|
||||
// originalSoutheastBlocks[0] = new BlockInfo(topSEBlock); // save block for reset
|
||||
// originalSoutheastBlocks[1] = new BlockInfo(topSEBlock.getFace(BlockFace.WEST));
|
||||
// originalSoutheastBlocks[2] = new BlockInfo(topSEBlock.getFace(BlockFace.NORTH));
|
||||
// topSEBlock.setType(Material.GLASS);
|
||||
// topSEBlock.getFace(BlockFace.WEST).setType(Material.GLASS);
|
||||
// topSEBlock.getFace(BlockFace.NORTH).setType(Material.GLASS);
|
||||
// this.war.getServer().getScheduler().scheduleSyncDelayedTask(this.war, new ResetCursorJob(topSEBlock, originalSoutheastBlocks, true), 75);
|
||||
// }
|
||||
//
|
||||
//
|
||||
// public Location getSoutheast() {
|
||||
// return southeast;
|
||||
// }
|
||||
|
||||
public void setTeleport(Location location) {
|
||||
this.teleport = location;
|
||||
@ -275,8 +263,8 @@ public class Warzone {
|
||||
lobby.initialize();
|
||||
}
|
||||
|
||||
this.setNorthwest(this.getNorthwest());
|
||||
this.setSoutheast(this.getSoutheast());
|
||||
// this.setNorthwest(this.getNorthwest());
|
||||
// this.setSoutheast(this.getSoutheast());
|
||||
|
||||
this.flagThieves.clear();
|
||||
}
|
||||
@ -615,11 +603,11 @@ public class Warzone {
|
||||
this.world = world;
|
||||
}
|
||||
|
||||
public VerticalVolume getVolume() {
|
||||
public ZoneVolume getVolume() {
|
||||
return volume;
|
||||
}
|
||||
|
||||
public void setVolume(VerticalVolume zoneVolume) {
|
||||
public void setVolume(ZoneVolume zoneVolume) {
|
||||
this.volume = zoneVolume;
|
||||
}
|
||||
|
||||
@ -634,21 +622,21 @@ public class Warzone {
|
||||
|
||||
public boolean isNearWall(Location latestPlayerLocation) {
|
||||
if(volume.hasTwoCorners()) {
|
||||
if(Math.abs(southeast.getBlockZ() - latestPlayerLocation.getBlockZ()) < minSafeDistanceFromWall
|
||||
&& latestPlayerLocation.getBlockX() <= southeast.getBlockX()
|
||||
&& latestPlayerLocation.getBlockX() >= northwest.getBlockX()) {
|
||||
if(Math.abs(volume.getSoutheastZ() - latestPlayerLocation.getBlockZ()) < minSafeDistanceFromWall
|
||||
&& latestPlayerLocation.getBlockX() <= volume.getSoutheastX()
|
||||
&& latestPlayerLocation.getBlockX() >= volume.getNorthwestX()) {
|
||||
return true; // near east wall
|
||||
} else if (Math.abs(southeast.getBlockX() - latestPlayerLocation.getBlockX()) < minSafeDistanceFromWall
|
||||
&& latestPlayerLocation.getBlockZ() <= northwest.getBlockZ()
|
||||
&& latestPlayerLocation.getBlockZ() >= southeast.getBlockZ()) {
|
||||
} else if (Math.abs(volume.getSoutheastX() - latestPlayerLocation.getBlockX()) < minSafeDistanceFromWall
|
||||
&& latestPlayerLocation.getBlockZ() <= volume.getNorthwestZ()
|
||||
&& latestPlayerLocation.getBlockZ() >= volume.getSoutheastZ()) {
|
||||
return true; // near south wall
|
||||
} else if (Math.abs(northwest.getBlockX() - latestPlayerLocation.getBlockX()) < minSafeDistanceFromWall
|
||||
&& latestPlayerLocation.getBlockZ() <= northwest.getBlockZ()
|
||||
&& latestPlayerLocation.getBlockZ() >= southeast.getBlockZ()) {
|
||||
} else if (Math.abs(volume.getNorthwestX() - latestPlayerLocation.getBlockX()) < minSafeDistanceFromWall
|
||||
&& latestPlayerLocation.getBlockZ() <= volume.getNorthwestZ()
|
||||
&& latestPlayerLocation.getBlockZ() >= volume.getSoutheastZ()) {
|
||||
return true; // near north wall
|
||||
} else if (Math.abs(northwest.getBlockZ() - latestPlayerLocation.getBlockZ()) < minSafeDistanceFromWall
|
||||
&& latestPlayerLocation.getBlockX() <= southeast.getBlockX()
|
||||
&& latestPlayerLocation.getBlockX() >= northwest.getBlockX()) {
|
||||
} else if (Math.abs(volume.getNorthwestZ() - latestPlayerLocation.getBlockZ()) < minSafeDistanceFromWall
|
||||
&& latestPlayerLocation.getBlockX() <= volume.getSoutheastX()
|
||||
&& latestPlayerLocation.getBlockX() >= volume.getNorthwestX()) {
|
||||
return true; // near west wall
|
||||
}
|
||||
}
|
||||
@ -657,35 +645,35 @@ public class Warzone {
|
||||
|
||||
public List<Block> getNearestWallBlocks(Location latestPlayerLocation) {
|
||||
List<Block> nearestWallBlocks = new ArrayList<Block>();
|
||||
if(Math.abs(southeast.getBlockZ() - latestPlayerLocation.getBlockZ()) < minSafeDistanceFromWall
|
||||
&& latestPlayerLocation.getBlockX() <= southeast.getBlockX()
|
||||
&& latestPlayerLocation.getBlockX() >= northwest.getBlockX()) {
|
||||
if(Math.abs(volume.getSoutheastZ() - latestPlayerLocation.getBlockZ()) < minSafeDistanceFromWall
|
||||
&& latestPlayerLocation.getBlockX() <= volume.getSoutheastX()
|
||||
&& latestPlayerLocation.getBlockX() >= volume.getNorthwestX()) {
|
||||
// near east wall
|
||||
Block eastWallBlock = world.getBlockAt(latestPlayerLocation.getBlockX() + 1, latestPlayerLocation.getBlockY(), southeast.getBlockZ());
|
||||
Block eastWallBlock = world.getBlockAt(latestPlayerLocation.getBlockX() + 1, latestPlayerLocation.getBlockY(), volume.getSoutheastZ());
|
||||
nearestWallBlocks.add(eastWallBlock);
|
||||
}
|
||||
|
||||
if (Math.abs(southeast.getBlockX() - latestPlayerLocation.getBlockX()) < minSafeDistanceFromWall
|
||||
&& latestPlayerLocation.getBlockZ() <= northwest.getBlockZ()
|
||||
&& latestPlayerLocation.getBlockZ() >= southeast.getBlockZ()) {
|
||||
if (Math.abs(volume.getSoutheastX() - latestPlayerLocation.getBlockX()) < minSafeDistanceFromWall
|
||||
&& latestPlayerLocation.getBlockZ() <= volume.getNorthwestZ()
|
||||
&& latestPlayerLocation.getBlockZ() >= volume.getSoutheastZ()) {
|
||||
// near south wall
|
||||
Block southWallBlock = world.getBlockAt(southeast.getBlockX(), latestPlayerLocation.getBlockY() + 1, latestPlayerLocation.getBlockZ());
|
||||
Block southWallBlock = world.getBlockAt(volume.getSoutheastX(), latestPlayerLocation.getBlockY() + 1, latestPlayerLocation.getBlockZ());
|
||||
nearestWallBlocks.add(southWallBlock);
|
||||
}
|
||||
|
||||
if (Math.abs(northwest.getBlockX() - latestPlayerLocation.getBlockX()) < minSafeDistanceFromWall
|
||||
&& latestPlayerLocation.getBlockZ() <= northwest.getBlockZ()
|
||||
&& latestPlayerLocation.getBlockZ() >= southeast.getBlockZ()) {
|
||||
if (Math.abs(volume.getNorthwestX() - latestPlayerLocation.getBlockX()) < minSafeDistanceFromWall
|
||||
&& latestPlayerLocation.getBlockZ() <= volume.getNorthwestZ()
|
||||
&& latestPlayerLocation.getBlockZ() >= volume.getSoutheastZ()) {
|
||||
// near north wall
|
||||
Block northWallBlock = world.getBlockAt(northwest.getBlockX(), latestPlayerLocation.getBlockY() + 1, latestPlayerLocation.getBlockZ());
|
||||
Block northWallBlock = world.getBlockAt(volume.getNorthwestX(), latestPlayerLocation.getBlockY() + 1, latestPlayerLocation.getBlockZ());
|
||||
nearestWallBlocks.add(northWallBlock);
|
||||
}
|
||||
|
||||
if (Math.abs(northwest.getBlockZ() - latestPlayerLocation.getBlockZ()) < minSafeDistanceFromWall
|
||||
&& latestPlayerLocation.getBlockX() <= southeast.getBlockX()
|
||||
&& latestPlayerLocation.getBlockX() >= northwest.getBlockX()) {
|
||||
if (Math.abs(volume.getNorthwestZ() - latestPlayerLocation.getBlockZ()) < minSafeDistanceFromWall
|
||||
&& latestPlayerLocation.getBlockX() <= volume.getSoutheastX()
|
||||
&& latestPlayerLocation.getBlockX() >= volume.getNorthwestX()) {
|
||||
// near west wall
|
||||
Block westWallBlock = world.getBlockAt(latestPlayerLocation.getBlockX(), latestPlayerLocation.getBlockY() + 1, northwest.getBlockZ());
|
||||
Block westWallBlock = world.getBlockAt(latestPlayerLocation.getBlockX(), latestPlayerLocation.getBlockY() + 1, volume.getNorthwestZ());
|
||||
nearestWallBlocks.add(westWallBlock);
|
||||
}
|
||||
return nearestWallBlocks;
|
||||
@ -694,30 +682,30 @@ public class Warzone {
|
||||
|
||||
public List<BlockFace> getNearestWalls(Location latestPlayerLocation) {
|
||||
List<BlockFace> walls = new ArrayList<BlockFace>();
|
||||
if(Math.abs(southeast.getBlockZ() - latestPlayerLocation.getBlockZ()) < minSafeDistanceFromWall
|
||||
&& latestPlayerLocation.getBlockX() <= southeast.getBlockX()
|
||||
&& latestPlayerLocation.getBlockX() >= northwest.getBlockX()) {
|
||||
if(Math.abs(volume.getSoutheastZ() - latestPlayerLocation.getBlockZ()) < minSafeDistanceFromWall
|
||||
&& latestPlayerLocation.getBlockX() <= volume.getSoutheastX()
|
||||
&& latestPlayerLocation.getBlockX() >= volume.getNorthwestX()) {
|
||||
// near east wall
|
||||
walls.add(BlockFace.EAST);
|
||||
}
|
||||
|
||||
if (Math.abs(southeast.getBlockX() - latestPlayerLocation.getBlockX()) < minSafeDistanceFromWall
|
||||
&& latestPlayerLocation.getBlockZ() <= northwest.getBlockZ()
|
||||
&& latestPlayerLocation.getBlockZ() >= southeast.getBlockZ()) {
|
||||
if (Math.abs(volume.getSoutheastX() - latestPlayerLocation.getBlockX()) < minSafeDistanceFromWall
|
||||
&& latestPlayerLocation.getBlockZ() <= volume.getNorthwestZ()
|
||||
&& latestPlayerLocation.getBlockZ() >= volume.getSoutheastZ()) {
|
||||
// near south wall
|
||||
walls.add(BlockFace.SOUTH);
|
||||
}
|
||||
|
||||
if (Math.abs(northwest.getBlockX() - latestPlayerLocation.getBlockX()) < minSafeDistanceFromWall
|
||||
&& latestPlayerLocation.getBlockZ() <= northwest.getBlockZ()
|
||||
&& latestPlayerLocation.getBlockZ() >= southeast.getBlockZ()) {
|
||||
if (Math.abs(volume.getNorthwestX() - latestPlayerLocation.getBlockX()) < minSafeDistanceFromWall
|
||||
&& latestPlayerLocation.getBlockZ() <= volume.getNorthwestZ()
|
||||
&& latestPlayerLocation.getBlockZ() >= volume.getSoutheastZ()) {
|
||||
// near north wall
|
||||
walls.add(BlockFace.NORTH);
|
||||
}
|
||||
|
||||
if (Math.abs(northwest.getBlockZ() - latestPlayerLocation.getBlockZ()) < minSafeDistanceFromWall
|
||||
&& latestPlayerLocation.getBlockX() <= southeast.getBlockX()
|
||||
&& latestPlayerLocation.getBlockX() >= northwest.getBlockX()) {
|
||||
if (Math.abs(volume.getNorthwestZ() - latestPlayerLocation.getBlockZ()) < minSafeDistanceFromWall
|
||||
&& latestPlayerLocation.getBlockX() <= volume.getSoutheastX()
|
||||
&& latestPlayerLocation.getBlockX() >= volume.getNorthwestX()) {
|
||||
// near west wall
|
||||
walls.add(BlockFace.WEST);
|
||||
}
|
||||
@ -786,28 +774,6 @@ public class Warzone {
|
||||
return lobby;
|
||||
}
|
||||
|
||||
// public void autoAssign(PlayerMoveEvent event, Player player) {
|
||||
// Team lowestNoOfPlayers = null;
|
||||
// for(Team t : teams) {
|
||||
// if(lowestNoOfPlayers == null
|
||||
// || (lowestNoOfPlayers != null && lowestNoOfPlayers.getPlayers().size() > t.getPlayers().size())) {
|
||||
// lowestNoOfPlayers = t;
|
||||
// }
|
||||
// }
|
||||
// if(lowestNoOfPlayers != null) {
|
||||
// lowestNoOfPlayers.addPlayer(player);
|
||||
// lowestNoOfPlayers.resetSign();
|
||||
// if(!hasPlayerInventory(player.getName())) {
|
||||
// keepPlayerInventory(player);
|
||||
// }
|
||||
// war.msg(player, "Your inventory is is storage until you /leave.");
|
||||
// respawnPlayer(event, lowestNoOfPlayers, player);
|
||||
// for(Team team : teams){
|
||||
// team.teamcast("" + player.getName() + " joined team " + lowestNoOfPlayers.getName() + ".");
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
|
||||
public Team autoAssign(Player player) {
|
||||
Team lowestNoOfPlayers = null;
|
||||
for(Team t : teams) {
|
||||
|
@ -17,6 +17,7 @@ import com.tommytony.war.utils.SignHelper;
|
||||
import com.tommytony.war.volumes.BlockInfo;
|
||||
import com.tommytony.war.volumes.VerticalVolume;
|
||||
import com.tommytony.war.volumes.Volume;
|
||||
import com.tommytony.war.volumes.ZoneVolume;
|
||||
|
||||
/**
|
||||
*
|
||||
@ -91,7 +92,7 @@ public class ZoneLobby {
|
||||
|
||||
this.wall = newWall;
|
||||
// find center of the wall and set the new volume corners
|
||||
VerticalVolume zoneVolume = warzone.getVolume();
|
||||
ZoneVolume zoneVolume = warzone.getVolume();
|
||||
|
||||
int lobbyWidth = warzone.getTeams().size() * 4 + 5;
|
||||
lobbyHalfSide = lobbyWidth / 2;
|
||||
@ -110,7 +111,7 @@ public class ZoneLobby {
|
||||
int wallCenterPos = wallStart + wallLength / 2;
|
||||
int highestNonAirBlockAtCenter = warzone.getWorld().getHighestBlockYAt(x+1, wallCenterPos);
|
||||
if(highestNonAirBlockAtCenter < 3 || highestNonAirBlockAtCenter > 125 - lobbyHeight)
|
||||
highestNonAirBlockAtCenter = warzone.getNorthwest().getBlockY();
|
||||
highestNonAirBlockAtCenter = warzone.getVolume().getCenterY();
|
||||
lobbyMiddleWallBlock = new BlockInfo(warzone.getWorld().getBlockAt(x, highestNonAirBlockAtCenter, wallCenterPos));
|
||||
corner1 = warzone.getWorld().getBlockAt(x, highestNonAirBlockAtCenter - 1, wallCenterPos + lobbyHalfSide);
|
||||
corner2 = warzone.getWorld().getBlockAt(x - lobbyDepth,
|
||||
@ -123,7 +124,7 @@ public class ZoneLobby {
|
||||
int wallCenterPos = wallStart + wallLength / 2;
|
||||
int highestNonAirBlockAtCenter = warzone.getWorld().getHighestBlockYAt(wallCenterPos, z+1);
|
||||
if(highestNonAirBlockAtCenter < 3 || highestNonAirBlockAtCenter > 125 - lobbyHeight)
|
||||
highestNonAirBlockAtCenter = warzone.getSoutheast().getBlockY();
|
||||
highestNonAirBlockAtCenter = warzone.getVolume().getCenterY();
|
||||
lobbyMiddleWallBlock = new BlockInfo(warzone.getWorld().getBlockAt(wallCenterPos, highestNonAirBlockAtCenter, z));
|
||||
corner1 = warzone.getWorld().getBlockAt(wallCenterPos - lobbyHalfSide, highestNonAirBlockAtCenter - 1, z);
|
||||
corner2 = warzone.getWorld().getBlockAt(wallCenterPos + lobbyHalfSide,
|
||||
@ -136,7 +137,7 @@ public class ZoneLobby {
|
||||
int wallCenterPos = wallStart + wallLength / 2;
|
||||
int highestNonAirBlockAtCenter = warzone.getWorld().getHighestBlockYAt(x-1, wallCenterPos);
|
||||
if(highestNonAirBlockAtCenter < 3 || highestNonAirBlockAtCenter > 125 - lobbyHeight)
|
||||
highestNonAirBlockAtCenter = warzone.getSoutheast().getBlockY();
|
||||
highestNonAirBlockAtCenter = warzone.getVolume().getCenterY();
|
||||
lobbyMiddleWallBlock = new BlockInfo(warzone.getWorld().getBlockAt(x, highestNonAirBlockAtCenter, wallCenterPos));
|
||||
corner1 = warzone.getWorld().getBlockAt(x, highestNonAirBlockAtCenter -1 , wallCenterPos - lobbyHalfSide);
|
||||
corner2 = warzone.getWorld().getBlockAt(x + lobbyDepth,
|
||||
@ -149,7 +150,7 @@ public class ZoneLobby {
|
||||
int wallCenterPos = wallStart + wallLength / 2;
|
||||
int highestNonAirBlockAtCenter = warzone.getWorld().getHighestBlockYAt(wallCenterPos, z-1);
|
||||
if(highestNonAirBlockAtCenter < 3 || highestNonAirBlockAtCenter > 125 - lobbyHeight)
|
||||
highestNonAirBlockAtCenter = warzone.getNorthwest().getBlockY();
|
||||
highestNonAirBlockAtCenter = warzone.getVolume().getCenterY();
|
||||
lobbyMiddleWallBlock = new BlockInfo(warzone.getWorld().getBlockAt(wallCenterPos, highestNonAirBlockAtCenter, z));
|
||||
corner1 = warzone.getWorld().getBlockAt(wallCenterPos + lobbyHalfSide, highestNonAirBlockAtCenter - 1, z);
|
||||
corner2 = warzone.getWorld().getBlockAt(wallCenterPos - lobbyHalfSide, highestNonAirBlockAtCenter + 1 + lobbyHeight, z + lobbyDepth);
|
||||
|
208
war/src/main/java/com/tommytony/war/ZoneSetter.java
Normal file
208
war/src/main/java/com/tommytony/war/ZoneSetter.java
Normal file
@ -0,0 +1,208 @@
|
||||
package com.tommytony.war;
|
||||
|
||||
import org.bukkit.block.Block;
|
||||
import org.bukkit.block.BlockFace;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
import com.tommytony.war.mappers.WarMapper;
|
||||
import com.tommytony.war.mappers.WarzoneMapper;
|
||||
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 bukkit.tommytony.war.War;
|
||||
|
||||
public class ZoneSetter {
|
||||
|
||||
private final War war;
|
||||
private final Player player;
|
||||
private final String zoneName;
|
||||
|
||||
public ZoneSetter(War war, Player player, String zoneName) {
|
||||
this.war = war;
|
||||
this.player = player;
|
||||
this.zoneName = zoneName;
|
||||
}
|
||||
|
||||
public void placeNorthwest() {
|
||||
Warzone warzone = war.findWarzone(zoneName);
|
||||
Block northwestBlock = player.getLocation().getWorld().getBlockAt(player.getLocation());
|
||||
StringBuilder msgString = new StringBuilder();
|
||||
try
|
||||
{
|
||||
if(warzone == null) {
|
||||
// create the warzone
|
||||
warzone = new Warzone(war, player.getLocation().getWorld(), zoneName);
|
||||
war.getIncompleteZones().add(warzone);
|
||||
warzone.getVolume().setNorthwest(northwestBlock);
|
||||
war.msg(player, "Warzone " + warzone.getName() + " created. Northwesternmost point set to x:"
|
||||
+ (int)warzone.getVolume().getNorthwestX() + " z:" + (int)warzone.getVolume().getNorthwestZ() + ".");
|
||||
} else {
|
||||
// change existing warzone
|
||||
resetWarzone(warzone, msgString);
|
||||
warzone.getVolume().setNorthwest(northwestBlock);
|
||||
msgString.append("Warzone " + warzone.getName() + " modified. Northwesternmost point set to x:"
|
||||
+ (int)warzone.getVolume().getNorthwestX() + " z:" + (int)warzone.getVolume().getNorthwestZ() + ".");
|
||||
}
|
||||
saveIfReady(warzone, msgString);
|
||||
} catch (NotNorthwestException e) {
|
||||
war.badMsg(player, "The block you selected is not to the northwest of the existing southeasternmost block.");
|
||||
if(warzone.getVolume().isSaved()) warzone.initializeZone(); // was reset before changing
|
||||
} catch (TooSmallException e) {
|
||||
handleTooSmall();
|
||||
if(warzone.getVolume().isSaved()) warzone.initializeZone();
|
||||
} catch (TooBigException e) {
|
||||
handleTooBig();
|
||||
if(warzone.getVolume().isSaved()) warzone.initializeZone();
|
||||
}
|
||||
saveIfReady(warzone, msgString);
|
||||
}
|
||||
|
||||
public void placeSoutheast() {
|
||||
Warzone warzone = war.findWarzone(zoneName);
|
||||
Block southeastBlock = player.getLocation().getWorld().getBlockAt(player.getLocation());
|
||||
StringBuilder msgString = new StringBuilder();
|
||||
try
|
||||
{
|
||||
if(warzone == null) {
|
||||
// create the warzone
|
||||
warzone = new Warzone(war, player.getLocation().getWorld(), zoneName);
|
||||
war.getIncompleteZones().add(warzone);
|
||||
warzone.getVolume().setSoutheast(southeastBlock);
|
||||
war.msg(player, "Warzone " + warzone.getName() + " created. Southeasternmost point set to x:"
|
||||
+ (int)warzone.getVolume().getSoutheastX() + " z:" + (int)warzone.getVolume().getSoutheastZ() + ".");
|
||||
} else {
|
||||
// change existing warzone
|
||||
resetWarzone(warzone, msgString);
|
||||
warzone.getVolume().setSoutheast(southeastBlock);
|
||||
msgString.append("Warzone " + warzone.getName() + " modified. Southeasternmost point set to x:"
|
||||
+ (int)warzone.getVolume().getSoutheastX() + " z:" + (int)warzone.getVolume().getSoutheastZ() + ". ");
|
||||
}
|
||||
saveIfReady(warzone, msgString);
|
||||
} catch (NotSoutheastException e) {
|
||||
war.badMsg(player, "The block you selected is not to the southeast of the existing northwestnmost block.");
|
||||
if(warzone.getVolume().isSaved()) warzone.initializeZone(); // was reset before changing
|
||||
} catch (TooSmallException e) {
|
||||
handleTooSmall();
|
||||
if(warzone.getVolume().isSaved()) warzone.initializeZone();
|
||||
} catch (TooBigException e) {
|
||||
handleTooBig();
|
||||
if(warzone.getVolume().isSaved()) warzone.initializeZone();
|
||||
}
|
||||
saveIfReady(warzone, msgString);
|
||||
}
|
||||
|
||||
public void placeCorner1() {
|
||||
Warzone warzone = war.findWarzone(zoneName);
|
||||
Block corner1Block = player.getLocation().getWorld().getBlockAt(player.getLocation());
|
||||
StringBuilder msgString = new StringBuilder();
|
||||
try
|
||||
{
|
||||
if(warzone == null) {
|
||||
// create the warzone
|
||||
warzone = new Warzone(war, player.getLocation().getWorld(), zoneName);
|
||||
war.getIncompleteZones().add(warzone);
|
||||
warzone.getVolume().setZoneCornerOne(corner1Block);
|
||||
war.msg(player, "Warzone " + warzone.getName() + " created. Corner 1 set to x:"
|
||||
+ (int)corner1Block.getX() + " y:" + (int)corner1Block.getY() + " z:" + (int)corner1Block.getZ() + ".");
|
||||
} else {
|
||||
// change existing warzone
|
||||
resetWarzone(warzone, msgString);
|
||||
warzone.getVolume().setZoneCornerOne(corner1Block);
|
||||
msgString.append("Warzone " + warzone.getName() + " modified. Corner 1 set to x:"
|
||||
+ (int)corner1Block.getX() + " y:" + (int)corner1Block.getY() + " z:" + (int)corner1Block.getZ() + ".");
|
||||
}
|
||||
saveIfReady(warzone, msgString);
|
||||
} catch (TooSmallException e) {
|
||||
handleTooSmall();
|
||||
if(warzone.getVolume().isSaved()) warzone.initializeZone();
|
||||
} catch (TooBigException e) {
|
||||
handleTooBig();
|
||||
if(warzone.getVolume().isSaved()) warzone.initializeZone();
|
||||
}
|
||||
saveIfReady(warzone, msgString);
|
||||
}
|
||||
|
||||
public void placeCorner2() {
|
||||
Warzone warzone = war.findWarzone(zoneName);
|
||||
Block corner2Block = player.getLocation().getWorld().getBlockAt(player.getLocation());
|
||||
StringBuilder msgString = new StringBuilder();
|
||||
try
|
||||
{
|
||||
if(warzone == null) {
|
||||
// create the warzone
|
||||
warzone = new Warzone(war, player.getLocation().getWorld(), zoneName);
|
||||
war.getIncompleteZones().add(warzone);
|
||||
warzone.getVolume().setZoneCornerTwo(corner2Block);
|
||||
war.msg(player, "Warzone " + warzone.getName() + " created. Corner 2 set to x:"
|
||||
+ (int)corner2Block.getX() + " y:" + (int)corner2Block.getY() + " z:" + (int)corner2Block.getZ() + ".");
|
||||
} else {
|
||||
// change existing warzone
|
||||
resetWarzone(warzone, msgString);
|
||||
warzone.getVolume().setZoneCornerTwo(corner2Block);
|
||||
msgString.append("Warzone " + warzone.getName() + " modified. Corner 2 set to x:"
|
||||
+ (int)corner2Block.getX() + " y:" + (int)corner2Block.getY() + " z:" + (int)corner2Block.getZ() + ".");
|
||||
}
|
||||
saveIfReady(warzone, msgString);
|
||||
} catch (TooSmallException e) {
|
||||
handleTooSmall();
|
||||
if(warzone.getVolume().isSaved()) warzone.initializeZone();
|
||||
} catch (TooBigException e) {
|
||||
handleTooBig();
|
||||
if(warzone.getVolume().isSaved()) warzone.initializeZone();
|
||||
}
|
||||
saveIfReady(warzone, msgString);
|
||||
}
|
||||
|
||||
private void resetWarzone(Warzone warzone, StringBuilder msgString) {
|
||||
if(warzone.getVolume().isSaved()) {
|
||||
war.msg(player, "Resetting " + warzone.getName() + " blocks.");
|
||||
if(warzone.getLobby() != null) {
|
||||
warzone.getLobby().getVolume().resetBlocks();
|
||||
}
|
||||
int reset = warzone.getVolume().resetBlocks();
|
||||
msgString.append(reset + " blocks reset. ");
|
||||
}
|
||||
}
|
||||
|
||||
private void handleTooSmall() {
|
||||
war.badMsg(player, "That would make the " + zoneName + " warzone too small. Sides must be at least 10 blocks.");
|
||||
}
|
||||
|
||||
private void handleTooBig() {
|
||||
war.badMsg(player, "That would make the " + zoneName + " warzone too big. Sides must be less than 750 blocks.");
|
||||
}
|
||||
|
||||
private void saveIfReady(Warzone warzone, StringBuilder msgString) {
|
||||
if(warzone.ready()) {
|
||||
if(!war.getWarzones().contains(warzone)) {
|
||||
war.addWarzone(warzone);
|
||||
}
|
||||
if(war.getIncompleteZones().contains(warzone)) {
|
||||
war.getIncompleteZones().remove(warzone);
|
||||
}
|
||||
WarMapper.save(war);
|
||||
msgString.append("Saving new warzone blocks...");
|
||||
war.msg(player, msgString.toString());
|
||||
warzone.saveState(false); // we just changed the volume, cant reset walls
|
||||
if(warzone.getLobby() == null) {
|
||||
// Set default lobby on south side
|
||||
ZoneLobby lobby = new ZoneLobby(war, warzone, BlockFace.SOUTH);
|
||||
warzone.setLobby(lobby);
|
||||
if(war.getWarHub() != null) { // warhub has to change
|
||||
war.getWarHub().getVolume().resetBlocks();
|
||||
war.getWarHub().initialize();
|
||||
}
|
||||
war.msg(player, "Default lobby created on south side of zone. Use /setzonelobby <n/s/e/w> to change its position.");
|
||||
} else {
|
||||
// gotta move the lobby
|
||||
warzone.getLobby().changeWall(warzone.getLobby().getWall());
|
||||
}
|
||||
warzone.initializeZone();
|
||||
WarzoneMapper.save(war, warzone, true);
|
||||
war.msg(player, "Warzone saved. Use /setteam, /setmonument and /savezone to configure the zone.");
|
||||
}
|
||||
}
|
||||
|
||||
}
|
@ -22,6 +22,7 @@ import bukkit.tommytony.war.War;
|
||||
import com.tommytony.war.volumes.BlockInfo;
|
||||
import com.tommytony.war.volumes.VerticalVolume;
|
||||
import com.tommytony.war.volumes.Volume;
|
||||
import com.tommytony.war.volumes.ZoneVolume;
|
||||
|
||||
/**
|
||||
*
|
||||
@ -44,6 +45,13 @@ public class VolumeMapper {
|
||||
return volume;
|
||||
}
|
||||
|
||||
public static ZoneVolume loadZoneVolume(String volumeName, String zoneName,
|
||||
War war, World world) {
|
||||
ZoneVolume volume = new ZoneVolume(volumeName, war, world);
|
||||
load(volume, zoneName, war, world);
|
||||
return volume;
|
||||
}
|
||||
|
||||
public static void load(Volume volume, String zoneName, War war, World world) {
|
||||
BufferedReader in = null;
|
||||
try {
|
||||
|
@ -20,6 +20,7 @@ import com.tommytony.war.Warzone;
|
||||
import com.tommytony.war.ZoneLobby;
|
||||
import com.tommytony.war.volumes.VerticalVolume;
|
||||
import com.tommytony.war.volumes.Volume;
|
||||
import com.tommytony.war.volumes.ZoneVolume;
|
||||
|
||||
/**
|
||||
*
|
||||
@ -66,29 +67,6 @@ public class WarzoneMapper {
|
||||
}
|
||||
}
|
||||
|
||||
// northwest
|
||||
String nwStr = warzoneConfig.getString("northWest");
|
||||
if(nwStr != null && !nwStr.equals("")) {
|
||||
String[] nwStrSplit = nwStr.split(",");
|
||||
|
||||
int nwX = Integer.parseInt(nwStrSplit[0]);
|
||||
int nwY = Integer.parseInt(nwStrSplit[1]);
|
||||
int nwZ = Integer.parseInt(nwStrSplit[2]);
|
||||
Location nw = new Location(world, nwX, nwY, nwZ);
|
||||
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("")) {
|
||||
@ -262,10 +240,10 @@ public class WarzoneMapper {
|
||||
|
||||
warzoneConfig.close();
|
||||
|
||||
if(loadBlocks && warzone.getNorthwest() != null && warzone.getSoutheast() != null) {
|
||||
if(loadBlocks) {
|
||||
|
||||
// zone blocks
|
||||
VerticalVolume zoneVolume = VolumeMapper.loadVerticalVolume(warzone.getName(), warzone.getName(), war, warzone.getWorld());
|
||||
ZoneVolume zoneVolume = VolumeMapper.loadZoneVolume(warzone.getName(), warzone.getName(), war, warzone.getWorld());
|
||||
warzone.setVolume(zoneVolume);
|
||||
}
|
||||
|
||||
@ -315,22 +293,6 @@ public class WarzoneMapper {
|
||||
// world
|
||||
warzoneConfig.setString("world", warzone.getWorld().getName()); // default for now
|
||||
|
||||
// northwest
|
||||
String nwStr = "";
|
||||
Location nw = warzone.getNorthwest();
|
||||
if(nw != null) {
|
||||
nwStr = nw.getBlockX() + "," + nw.getBlockY() + "," + nw.getBlockZ();
|
||||
}
|
||||
warzoneConfig.setString("northWest", nwStr);
|
||||
|
||||
// southeast
|
||||
String seStr = "";
|
||||
Location se = warzone.getSoutheast();
|
||||
if(se != null) {
|
||||
seStr = se.getBlockX() + "," + se.getBlockY() + "," + se.getBlockZ();
|
||||
}
|
||||
warzoneConfig.setString("southEast", seStr);
|
||||
|
||||
// teleport
|
||||
String teleportStr = "";
|
||||
Location tele = warzone.getTeleport();
|
||||
|
@ -2,4 +2,9 @@ package com.tommytony.war.volumes;
|
||||
|
||||
public class NotSoutheastException extends Exception {
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
private static final long serialVersionUID = -4347064837067648341L;
|
||||
|
||||
}
|
||||
|
@ -0,0 +1,11 @@
|
||||
package com.tommytony.war.volumes;
|
||||
|
||||
public class TooBigException extends Exception {
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
private static final long serialVersionUID = 61793179891881015L;
|
||||
|
||||
|
||||
}
|
@ -0,0 +1,11 @@
|
||||
package com.tommytony.war.volumes;
|
||||
|
||||
public class TooSmallException extends Exception {
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
private static final long serialVersionUID = -1641366536434076088L;
|
||||
|
||||
|
||||
}
|
@ -7,16 +7,22 @@ import org.bukkit.block.BlockFace;
|
||||
|
||||
import bukkit.tommytony.war.War;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author tommytony
|
||||
*
|
||||
*/
|
||||
public class ZoneVolume extends Volume {
|
||||
|
||||
public ZoneVolume(String name, War war, World world) {
|
||||
super(name, war, world);
|
||||
// TODO Auto-generated constructor stub
|
||||
}
|
||||
|
||||
public void setNorthwest(Block block) throws NotNorthwestException {
|
||||
public void setNorthwest(Block block) throws NotNorthwestException, TooSmallException, TooBigException {
|
||||
// northwest defaults to top block
|
||||
BlockInfo topBlock = new BlockInfo(block.getX(), 127, block.getZ(), block.getTypeId(), block.getData());
|
||||
BlockInfo oldCornerOne = getCornerOne();
|
||||
BlockInfo oldCornerTwo = getCornerTwo();
|
||||
if(getCornerOne() == null)
|
||||
{
|
||||
if(getCornerTwo() == null) {
|
||||
@ -35,17 +41,45 @@ public class ZoneVolume extends Volume {
|
||||
}
|
||||
super.setCornerTwo(topBlock);
|
||||
} else {
|
||||
// both corners already set: we are resizing
|
||||
// both corners already set: we are resizing (only if the new block is northwest relative to the southeasternmost block)
|
||||
if (getSoutheastX() <= block.getX() || getSoutheastZ() >= block.getZ()) {
|
||||
throw new NotNorthwestException();
|
||||
}
|
||||
BlockInfo minXBlock = getMinXBlock(); // north means min X
|
||||
minXBlock.setX(block.getX()); // mutating, argh!
|
||||
BlockInfo maxZBlock = getMaxZBlock(); // west means max Z
|
||||
maxZBlock.setZ(block.getZ());
|
||||
}
|
||||
if(tooSmall()) {
|
||||
super.setCornerOne(oldCornerOne);
|
||||
super.setCornerTwo(oldCornerTwo);
|
||||
throw new TooSmallException();
|
||||
} else if (tooBig()) {
|
||||
super.setCornerOne(oldCornerOne);
|
||||
super.setCornerTwo(oldCornerTwo);
|
||||
throw new TooBigException();
|
||||
}
|
||||
}
|
||||
|
||||
public void setSoutheast(Block block) throws NotSoutheastException {
|
||||
public int getNorthwestX() {
|
||||
if(!hasTwoCorners())
|
||||
return 0;
|
||||
else
|
||||
return getMinX();
|
||||
}
|
||||
|
||||
public int getNorthwestZ() {
|
||||
if(!hasTwoCorners())
|
||||
return 0;
|
||||
else
|
||||
return getMaxZ();
|
||||
}
|
||||
|
||||
public void setSoutheast(Block block) throws NotSoutheastException, TooSmallException, TooBigException {
|
||||
// southeast defaults to bottom block
|
||||
BlockInfo bottomBlock = new BlockInfo(block.getX(), 0, block.getZ(), block.getTypeId(), block.getData());
|
||||
BlockInfo oldCornerOne = getCornerOne();
|
||||
BlockInfo oldCornerTwo = getCornerTwo();
|
||||
if(getCornerTwo() == null)
|
||||
{
|
||||
if(getCornerOne() == null) {
|
||||
@ -64,12 +98,85 @@ public class ZoneVolume extends Volume {
|
||||
}
|
||||
super.setCornerOne(bottomBlock);
|
||||
} else {
|
||||
// both corners already set: we are resizing
|
||||
// both corners already set: we are resizing (only if the new block is southeast relative to the northwesternmost block)
|
||||
if (getNorthwestX() >= block.getX() || getNorthwestZ() <= block.getZ()) {
|
||||
throw new NotSoutheastException();
|
||||
}
|
||||
BlockInfo maxXBlock = getMaxXBlock(); // south means max X
|
||||
maxXBlock.setX(block.getX()); // mutating, argh!
|
||||
BlockInfo minZBlock = getMinZBlock(); // east means min Z
|
||||
minZBlock.setZ(block.getZ());
|
||||
}
|
||||
if(tooSmall()) {
|
||||
super.setCornerOne(oldCornerOne);
|
||||
super.setCornerTwo(oldCornerTwo);
|
||||
throw new TooSmallException();
|
||||
} else if (tooBig()) {
|
||||
super.setCornerOne(oldCornerOne);
|
||||
super.setCornerTwo(oldCornerTwo);
|
||||
throw new TooBigException();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public int getSoutheastX() {
|
||||
if(!hasTwoCorners())
|
||||
return 0;
|
||||
else
|
||||
return getMaxX();
|
||||
}
|
||||
|
||||
public int getSoutheastZ() {
|
||||
if(!hasTwoCorners())
|
||||
return 0;
|
||||
else
|
||||
return getMinZ();
|
||||
}
|
||||
|
||||
public int getCenterY() {
|
||||
if(!hasTwoCorners())
|
||||
return 0;
|
||||
else
|
||||
return (getMaxY() - getMinY())/2;
|
||||
|
||||
}
|
||||
|
||||
public void setZoneCornerOne(Block block) throws TooSmallException, TooBigException {
|
||||
BlockInfo oldCornerOne = getCornerOne();
|
||||
super.setCornerOne(block);
|
||||
if(tooSmall()) {
|
||||
super.setCornerOne(oldCornerOne);
|
||||
throw new TooSmallException();
|
||||
} else if (tooBig()) {
|
||||
super.setCornerOne(oldCornerOne);
|
||||
throw new TooBigException();
|
||||
}
|
||||
}
|
||||
|
||||
public void setZoneCornerTwo(Block block) throws TooSmallException, TooBigException {
|
||||
BlockInfo oldCornerTwo = getCornerTwo();
|
||||
super.setCornerTwo(block);
|
||||
if(tooSmall()) {
|
||||
super.setCornerTwo(oldCornerTwo);
|
||||
throw new TooSmallException();
|
||||
} else if (tooBig()) {
|
||||
super.setCornerTwo(oldCornerTwo);
|
||||
throw new TooBigException();
|
||||
}
|
||||
}
|
||||
|
||||
public boolean tooSmall() {
|
||||
if(hasTwoCorners() && ((getMaxX() - getMinX() < 10)
|
||||
|| (getMaxY() - getMinY() < 10)
|
||||
|| (getMaxZ() - getMinZ() < 10))) return true;
|
||||
return false;
|
||||
}
|
||||
|
||||
public boolean tooBig() {
|
||||
if(hasTwoCorners() && ((getMaxX() - getMinX() > 750)
|
||||
|| (getMaxY() - getMinY() > 750)
|
||||
|| (getMaxZ() - getMinZ() > 750))) return true;
|
||||
return false;
|
||||
}
|
||||
|
||||
public boolean isWallBlock(Block block){
|
||||
@ -267,18 +374,11 @@ public class ZoneVolume extends Volume {
|
||||
) {
|
||||
currentBlock.setTypeId(oldBlockType);
|
||||
currentBlock.setData(oldBlockData);
|
||||
// if(oldBlockInfo.is(Material.SIGN) || oldBlockInfo.is(Material.SIGN_POST)) {
|
||||
// BlockState state = currentBlock.getState();
|
||||
// Sign currentSign = (Sign) state;
|
||||
// currentSign.setLine(0, oldBlockInfo.getSignLines()[0]);
|
||||
// currentSign.setLine(1, oldBlockInfo.getSignLines()[0]);
|
||||
// currentSign.setLine(2, oldBlockInfo.getSignLines()[0]);
|
||||
// currentSign.setLine(3, oldBlockInfo.getSignLines()[0]);
|
||||
// state.update();
|
||||
// }
|
||||
// TODO: reset wall signs, chests and dispensers properly like in resetBlocks
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
@ -48,19 +48,19 @@ commands:
|
||||
- /nextbattle
|
||||
# 2- Warzone creation commands
|
||||
setzone:
|
||||
description: (War) Use to create a warzone. 1) Classic: Northwest and Southeast corners. Lobby is created and blocks are saved when the second corner is set.
|
||||
description: (War) Use to create a warzone. Lobby is created and blocks are saved when the second corner is set.
|
||||
usage:
|
||||
- Classic/Northwest-Southeast mode -
|
||||
- =<Classic/Northwest-Southeast mode>=
|
||||
- /setzone <zonename> <northwest/southeast/nw/se>
|
||||
- ex: first, /setzone ziggy se, then, /setzone ziggy nw
|
||||
- In classic mode, corner1 is at the topmost block (127) in the northwest and corner2 is at the bottommost block (0) in the southeast.
|
||||
- Wand Cuboid mode -
|
||||
- In classic mode, corner1 defaults to the topmost block (127) in the northwest and corner2 to the bottommost block (0) in the southeast.
|
||||
- =<Wand Cuboid mode>=
|
||||
- 1) /setzone <name> wand
|
||||
- 2) Left-click to select or move corner1
|
||||
- 3) Right-click to select or move corner2
|
||||
- Turn off wand by dropping the wooden sword.
|
||||
- Wandless Cuboid mode -
|
||||
- /setzone <name> <corner1/corner2/c1/c2>
|
||||
- =<Wandless Cuboid mode>=
|
||||
- /setzone <name> <corner1/corner2/c1/c2/pos1/pos2>
|
||||
- The three modes can be mixed and matched.
|
||||
- Warzones must be at least 10 blocks wide in all directions.
|
||||
savezone:
|
||||
|
@ -12,6 +12,8 @@ import bukkit.tommytony.war.War;
|
||||
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;
|
||||
|
||||
public class ZoneVolumeSpec {
|
||||
@ -19,7 +21,7 @@ public class ZoneVolumeSpec {
|
||||
// setNorthwest
|
||||
|
||||
@Test
|
||||
public void setNorthwest_whenCreatingAndNoCornersAreSet_shouldSetCorner1AtTop() throws NotNorthwestException{
|
||||
public void setNorthwest_whenCreatingAndNoCornersAreSet_shouldSetCorner1AtTop() throws NotNorthwestException, TooSmallException, TooBigException{
|
||||
// Arrange
|
||||
War warMock = mock(War.class);
|
||||
World worldMock = mock(World.class);
|
||||
@ -44,7 +46,7 @@ public class ZoneVolumeSpec {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void setNorthwest_whenCreating_AndNoCorner1IsSet_ButCorner2Set_AndNewCornerBlockIsToEastOfCorner2_shouldThrowNotNorthwestException(){
|
||||
public void setNorthwest_whenCreating_AndNoCorner1IsSet_ButCorner2Set_AndNewCornerBlockIsToEastOfCorner2_shouldThrowNotNorthwestException() throws TooSmallException, TooBigException{
|
||||
// Arrange
|
||||
War warMock = mock(War.class);
|
||||
World worldMock = mock(World.class);
|
||||
@ -75,7 +77,7 @@ public class ZoneVolumeSpec {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void setNorthwest_whenCreating_AndNoCorner1IsSet_ButCorner2Set_AndNewCornerBlockIsToSouthOfCorner2_shouldThrowNotNorthwestException(){
|
||||
public void setNorthwest_whenCreating_AndNoCorner1IsSet_ButCorner2Set_AndNewCornerBlockIsToSouthOfCorner2_shouldThrowNotNorthwestException() throws TooSmallException, TooBigException{
|
||||
// Arrange
|
||||
War warMock = mock(War.class);
|
||||
World worldMock = mock(World.class);
|
||||
@ -106,7 +108,69 @@ public class ZoneVolumeSpec {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void setNorthwest_whenCreatingAndCorner1AlreadySet_shouldSetCorner2AtTop() throws NotNorthwestException{ // nw always goes to top
|
||||
public void setNorthwest_whenCreating_AndNoCorner1IsSet_ButCorner2Set_AndNewCornerBlockIsTooCloseToCorner2_shouldThrowTooSmallException() throws NotNorthwestException, TooBigException{
|
||||
// Arrange
|
||||
War warMock = mock(War.class);
|
||||
World worldMock = mock(World.class);
|
||||
ZoneVolume volume = new ZoneVolume("test", warMock, worldMock);
|
||||
Block blockMock = mock(Block.class);
|
||||
when(blockMock.getX()).thenReturn(-5); // further south
|
||||
when(blockMock.getY()).thenReturn(64); // at sea level
|
||||
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);
|
||||
}
|
||||
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
|
||||
War warMock = mock(War.class);
|
||||
World worldMock = mock(World.class);
|
||||
ZoneVolume volume = new ZoneVolume("test", warMock, worldMock);
|
||||
Block blockMock = mock(Block.class);
|
||||
when(blockMock.getX()).thenReturn(-1000); // further south
|
||||
when(blockMock.getY()).thenReturn(64); // at sea level
|
||||
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);
|
||||
}
|
||||
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
|
||||
War warMock = mock(War.class);
|
||||
World worldMock = mock(World.class);
|
||||
@ -139,7 +203,7 @@ public class ZoneVolumeSpec {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void setNorthwest_whenCreating_AndCorner1AlreadySet_ButNewCornerBlockIsEastOfCorner1_shouldThrowNotNorthwestException(){
|
||||
public void setNorthwest_whenCreating_AndCorner1AlreadySet_ButNewCornerBlockIsEastOfCorner1_shouldThrowNotNorthwestException() throws TooSmallException, TooBigException{
|
||||
// Arrange
|
||||
War warMock = mock(War.class);
|
||||
World worldMock = mock(World.class);
|
||||
@ -170,7 +234,7 @@ public class ZoneVolumeSpec {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void setNorthwest_whenCreating_AndCorner1AlreadySet_ButNewCornerBlockIsSouthOfCorner1_shouldThrowNotNorthwestException(){
|
||||
public void setNorthwest_whenCreating_AndCorner1AlreadySet_ButNewCornerBlockIsSouthOfCorner1_shouldThrowNotNorthwestException() throws TooSmallException, TooBigException{
|
||||
// Arrange
|
||||
War warMock = mock(War.class);
|
||||
World worldMock = mock(World.class);
|
||||
@ -201,7 +265,7 @@ public class ZoneVolumeSpec {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void setNorthwest_whenChangingVolumeWithCorner1NwCorner2Se_shouldMoveCorner1() throws NotNorthwestException{
|
||||
public void setNorthwest_whenChangingVolumeWithCorner1NwCorner2Se_shouldMoveCorner1() throws NotNorthwestException, TooSmallException, TooBigException{
|
||||
// Arrange
|
||||
War warMock = mock(War.class);
|
||||
World worldMock = mock(World.class);
|
||||
@ -237,7 +301,7 @@ public class ZoneVolumeSpec {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void setNorthwest_whenChangingVolumeWithCorner1SeCorner2Nw_shouldMoveCorner2() throws NotNorthwestException{
|
||||
public void setNorthwest_whenChangingVolumeWithCorner1SeCorner2Nw_shouldMoveCorner2() throws NotNorthwestException, TooSmallException, TooBigException{
|
||||
// Arrange
|
||||
War warMock = mock(War.class);
|
||||
World worldMock = mock(World.class);
|
||||
@ -273,7 +337,7 @@ public class ZoneVolumeSpec {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void setNorthwest_whenChangingVolumeWithCorner1NeCorner2Sw_shouldMoveCorner1XAndCorner2Z() throws NotNorthwestException{
|
||||
public void setNorthwest_whenChangingVolumeWithCorner1NeCorner2Sw_shouldMoveCorner1XAndCorner2Z() throws NotNorthwestException, TooSmallException, TooBigException{
|
||||
// Arrange
|
||||
War warMock = mock(War.class);
|
||||
World worldMock = mock(World.class);
|
||||
@ -309,7 +373,7 @@ public class ZoneVolumeSpec {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void setNorthwest_whenChangingVolumeWithCorner1SwCorner2Ne_shouldMoveCorner1ZAndCorner2X() throws NotNorthwestException{
|
||||
public void setNorthwest_whenChangingVolumeWithCorner1SwCorner2Ne_shouldMoveCorner1ZAndCorner2X() throws NotNorthwestException, TooSmallException, TooBigException{
|
||||
// Arrange
|
||||
War warMock = mock(War.class);
|
||||
World worldMock = mock(World.class);
|
||||
@ -351,7 +415,7 @@ public class ZoneVolumeSpec {
|
||||
// setSoutheast
|
||||
|
||||
@Test
|
||||
public void setSoutheast_whenCreatingAndNoCornersAreSet_shouldSetCorner2AtBottom() throws NotSoutheastException{
|
||||
public void setSoutheast_whenCreatingAndNoCornersAreSet_shouldSetCorner2AtBottom() throws NotSoutheastException, TooSmallException, TooBigException{
|
||||
// Arrange
|
||||
War warMock = mock(War.class);
|
||||
World worldMock = mock(World.class);
|
||||
@ -376,7 +440,7 @@ public class ZoneVolumeSpec {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void setSoutheast_whenCreatingAndNoCorner2IsSet_ButCorner1IsAlreadySet_AndNewCornerBlockIsToWestOfCorner1_shouldThrowNotSoutheastException(){
|
||||
public void setSoutheast_whenCreatingAndNoCorner2IsSet_ButCorner1IsAlreadySet_AndNewCornerBlockIsToWestOfCorner1_shouldThrowNotSoutheastException() throws TooSmallException, TooBigException{
|
||||
// Arrange
|
||||
War warMock = mock(War.class);
|
||||
World worldMock = mock(World.class);
|
||||
@ -407,7 +471,7 @@ public class ZoneVolumeSpec {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void setSoutheast_whenCreatingAndNoCorner2IsSet_ButCorner1IsAlreadySet_AndNewCornerBlockIsToNorthOfCorner1_shouldThrowNotSoutheastException(){
|
||||
public void setSoutheast_whenCreatingAndNoCorner2IsSet_ButCorner1IsAlreadySet_AndNewCornerBlockIsToNorthOfCorner1_shouldThrowNotSoutheastException() throws TooSmallException, TooBigException{
|
||||
// Arrange
|
||||
War warMock = mock(War.class);
|
||||
World worldMock = mock(World.class);
|
||||
@ -438,7 +502,7 @@ public class ZoneVolumeSpec {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void setSoutheast_whenCreatingAndCorner2AlreadySet_shouldSetCorner1AtBottom() throws NotSoutheastException{ // se always goes to bottom
|
||||
public void setSoutheast_whenCreatingAndCorner2AlreadySet_shouldSetCorner1AtBottom() throws NotSoutheastException, TooSmallException, TooBigException{ // se always goes to bottom
|
||||
// Arrange
|
||||
War warMock = mock(War.class);
|
||||
World worldMock = mock(World.class);
|
||||
@ -471,7 +535,7 @@ public class ZoneVolumeSpec {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void setSoutheast_whenCreating_AndCorner2AlreadySet_ButNewCornerBlockIsToWestOfCorner2_shouldThrowNotSoutheastException(){
|
||||
public void setSoutheast_whenCreating_AndCorner2AlreadySet_ButNewCornerBlockIsToWestOfCorner2_shouldThrowNotSoutheastException() throws TooSmallException, TooBigException{
|
||||
// Arrange
|
||||
War warMock = mock(War.class);
|
||||
World worldMock = mock(World.class);
|
||||
@ -502,7 +566,7 @@ public class ZoneVolumeSpec {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void setSoutheast_whenCreating_AndCorner2AlreadySet_ButNewCornerBlockIsToNorthOfCorner2_shouldThrowNotSoutheastException(){
|
||||
public void setSoutheast_whenCreating_AndCorner2AlreadySet_ButNewCornerBlockIsToNorthOfCorner2_shouldThrowNotSoutheastException() throws TooSmallException, TooBigException{
|
||||
// Arrange
|
||||
War warMock = mock(War.class);
|
||||
World worldMock = mock(World.class);
|
||||
@ -533,7 +597,7 @@ public class ZoneVolumeSpec {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void setSoutheast_whenChangingVolumeWithCorner1NwCorner2Se_shouldMoveCorner2() throws NotSoutheastException{
|
||||
public void setSoutheast_whenChangingVolumeWithCorner1NwCorner2Se_shouldMoveCorner2() throws NotSoutheastException, TooSmallException, TooBigException{
|
||||
// Arrange
|
||||
War warMock = mock(War.class);
|
||||
World worldMock = mock(World.class);
|
||||
@ -569,7 +633,7 @@ public class ZoneVolumeSpec {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void setSoutheast_whenChangingVolumeWithCorner1SeCorner2Nw_shouldMoveCorner1() throws NotSoutheastException{
|
||||
public void setSoutheast_whenChangingVolumeWithCorner1SeCorner2Nw_shouldMoveCorner1() throws NotSoutheastException, TooSmallException, TooBigException{
|
||||
// Arrange
|
||||
War warMock = mock(War.class);
|
||||
World worldMock = mock(World.class);
|
||||
@ -605,7 +669,7 @@ public class ZoneVolumeSpec {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void setSoutheast_whenChangingVolumeWithCorner1NeCorner2Sw_shouldMoveCorner1ZAndCorner2X() throws NotSoutheastException{
|
||||
public void setSoutheast_whenChangingVolumeWithCorner1NeCorner2Sw_shouldMoveCorner1ZAndCorner2X() throws NotSoutheastException, TooSmallException, TooBigException{
|
||||
// Arrange
|
||||
War warMock = mock(War.class);
|
||||
World worldMock = mock(World.class);
|
||||
@ -641,7 +705,7 @@ public class ZoneVolumeSpec {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void setSoutheast_whenChangingVolumeWithCorner1SwCorner2Ne_shouldMoveCorner1XAndCorner2Z() throws NotSoutheastException{
|
||||
public void setSoutheast_whenChangingVolumeWithCorner1SwCorner2Ne_shouldMoveCorner1XAndCorner2Z() throws NotSoutheastException, TooSmallException, TooBigException{
|
||||
// Arrange
|
||||
War warMock = mock(War.class);
|
||||
World worldMock = mock(World.class);
|
||||
|
@ -48,19 +48,19 @@ commands:
|
||||
- /nextbattle
|
||||
# 2- Warzone creation commands
|
||||
setzone:
|
||||
description: (War) Use to create a warzone. 1) Classic: Northwest and Southeast corners. Lobby is created and blocks are saved when the second corner is set.
|
||||
description: (War) Use to create a warzone. Lobby is created and blocks are saved when the second corner is set.
|
||||
usage:
|
||||
- Classic/Northwest-Southeast mode -
|
||||
- =<Classic/Northwest-Southeast mode>=
|
||||
- /setzone <zonename> <northwest/southeast/nw/se>
|
||||
- ex: first, /setzone ziggy se, then, /setzone ziggy nw
|
||||
- In classic mode, corner1 is at the topmost block (127) in the northwest and corner2 is at the bottommost block (0) in the southeast.
|
||||
- Wand Cuboid mode -
|
||||
- In classic mode, corner1 defaults to the topmost block (127) in the northwest and corner2 to the bottommost block (0) in the southeast.
|
||||
- =<Wand Cuboid mode>=
|
||||
- 1) /setzone <name> wand
|
||||
- 2) Left-click to select or move corner1
|
||||
- 3) Right-click to select or move corner2
|
||||
- Turn off wand by dropping the wooden sword.
|
||||
- Wandless Cuboid mode -
|
||||
- /setzone <name> <corner1/corner2/c1/c2>
|
||||
- =<Wandless Cuboid mode>=
|
||||
- /setzone <name> <corner1/corner2/c1/c2/pos1/pos2>
|
||||
- The three modes can be mixed and matched.
|
||||
- Warzones must be at least 10 blocks wide in all directions.
|
||||
savezone:
|
||||
|
Loading…
Reference in New Issue
Block a user