mirror of
https://github.com/taoneill/war.git
synced 2024-11-27 12:46:11 +01:00
Closes gh-162. Lobby can now be detached from warzone with /setzonelobby zoneName. War v1.5 is almost ready.
This commit is contained in:
parent
c5290030bf
commit
e1417811cf
@ -709,17 +709,20 @@ public class War extends JavaPlugin {
|
||||
}
|
||||
|
||||
public void performSetZoneLobby(Player player, String[] arguments) {
|
||||
if((!this.inAnyWarzone(player.getLocation())
|
||||
&& !this.inAnyWarzoneLobby(player.getLocation()))
|
||||
|| arguments.length < 1 || arguments.length > 1
|
||||
|| (arguments.length == 1 && !arguments[0].equals("north") && !arguments[0].equals("n")
|
||||
String usageStr = "Usage: When inside a warzone - /setzonelobby <north/n/east/e/south/s/west/w>." +
|
||||
"Attaches the lobby to the specified zone wall. When outside a warzone - /setzonelobby <zonename>. " +
|
||||
"Moves the lobby to your current position.";
|
||||
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
|
||||
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, "Usage: /setzonelobby <north/n/east/e/south/s/west/w>. Must be in warzone." +
|
||||
"Defines on which side the zone lobby lies. " +
|
||||
"Removes any previously set lobby.");
|
||||
} else {
|
||||
&& !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) {
|
||||
@ -760,6 +763,33 @@ public class War extends JavaPlugin {
|
||||
this.msg(player, "Warzone lobby created on " + wallStr + "side of zone.");
|
||||
}
|
||||
WarzoneMapper.save(this, warzone, false);
|
||||
} else {
|
||||
// Not in a warzone: set the lobby position to where the player is standing
|
||||
Warzone warzone = this.matchWarzone(arguments[0]);
|
||||
if(warzone == null) {
|
||||
this.badMsg(player, "No warzone matches " + arguments[0] + ".");
|
||||
} else {
|
||||
// Move the warzone lobby
|
||||
ZoneLobby lobby = warzone.getLobby();
|
||||
if(lobby != null) {
|
||||
// reset existing lobby
|
||||
lobby.getVolume().resetBlocks();
|
||||
lobby.setLocation(player.getLocation());
|
||||
lobby.initialize();
|
||||
this.msg(player, "Warzone lobby moved to your location.");
|
||||
} else {
|
||||
// new lobby
|
||||
lobby = new ZoneLobby(this, warzone, player.getLocation());
|
||||
warzone.setLobby(lobby);
|
||||
lobby.initialize();
|
||||
if(warHub != null) { // warhub has to change
|
||||
warHub.getVolume().resetBlocks();
|
||||
warHub.initialize();
|
||||
}
|
||||
this.msg(player, "Warzone lobby moved to your location.");
|
||||
}
|
||||
WarzoneMapper.save(this, warzone, false);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -771,11 +801,16 @@ public class War extends JavaPlugin {
|
||||
&& !arguments[1].equals("c1") && !arguments[1].equals("c2")
|
||||
&& !arguments[1].equals("pos1") && !arguments[1].equals("pos2")
|
||||
&& !arguments[1].equals("wand")))) {
|
||||
if(arguments.length == 1) {
|
||||
// we only have a zone name, default to wand mode
|
||||
this.addWandBearer(player, arguments[0]);
|
||||
} else {
|
||||
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 outline is valid.");
|
||||
}
|
||||
} else {
|
||||
ZoneSetter setter = new ZoneSetter(this, player, arguments[0]);
|
||||
if(arguments[1].equals("northwest") || arguments[1].equals("nw")) {
|
||||
@ -1243,6 +1278,15 @@ public class War extends JavaPlugin {
|
||||
return null;
|
||||
}
|
||||
|
||||
public Warzone matchWarzone(String warzoneSubString) {
|
||||
for(Warzone warzone : warzones) {
|
||||
if(warzone.getName().toLowerCase().contains(warzoneSubString.toLowerCase())) {
|
||||
return warzone;
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
public void addWandBearer(Player player, String zoneName) {
|
||||
if(wandBearers.containsKey(player.getName())){
|
||||
String alreadyHaveWand = wandBearers.get(player.getName());
|
||||
|
@ -39,6 +39,12 @@ public class ZoneLobby {
|
||||
private int lobbyHalfSide;
|
||||
private final int lobbyDepth = 10;
|
||||
|
||||
/**
|
||||
* Use this constructor with /setzonelobby <n/s/e/w>
|
||||
* @param war
|
||||
* @param warzone
|
||||
* @param wall On which wall of the warzone will the lobby be stuck to at mid-weight
|
||||
*/
|
||||
public ZoneLobby(War war, Warzone warzone, BlockFace wall) {
|
||||
this.war = war;
|
||||
this.warzone = warzone;
|
||||
@ -48,9 +54,27 @@ public class ZoneLobby {
|
||||
lobbyHalfSide = 7;
|
||||
}
|
||||
this.wall = wall;
|
||||
//this.changeWall(wall);
|
||||
}
|
||||
|
||||
/**
|
||||
* Use this constructor with /setzonelobby <zonename>.
|
||||
* Makes sure the lobby is not sticking inside the zone.
|
||||
* @param war
|
||||
* @param warzone
|
||||
* @param wall On which wall of the warzone will the lobby be stuck to at mid-weight
|
||||
*/
|
||||
public ZoneLobby(War war, Warzone warzone, Location playerLocation) {
|
||||
this.war = war;
|
||||
this.warzone = warzone;
|
||||
int lobbyWidth = warzone.getTeams().size() * 4 + 5;
|
||||
lobbyHalfSide = lobbyWidth / 2;
|
||||
if(lobbyHalfSide < 7) {
|
||||
lobbyHalfSide = 7;
|
||||
}
|
||||
setLocation(playerLocation);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Convenience ctor when loading form disk.
|
||||
* This figures out the middle wall block of the lobby from the volume instead
|
||||
@ -79,28 +103,75 @@ public class ZoneLobby {
|
||||
}
|
||||
}
|
||||
|
||||
public void setWall(BlockFace newWall) {
|
||||
this.wall = newWall;
|
||||
/**
|
||||
* Changes the lobby's position. Orientation is determined from the player location.
|
||||
* Creates volume or resets. Saves new lobby blocks.
|
||||
* @param playerLocation
|
||||
*/
|
||||
public void setLocation(Location playerLocation) {
|
||||
createVolumeOrReset();
|
||||
BlockFace facing = null;
|
||||
BlockFace opposite = null;
|
||||
float yaw = playerLocation.getYaw();
|
||||
if(yaw >= 45 && yaw < 135) {
|
||||
facing = BlockFace.NORTH;
|
||||
opposite = BlockFace.SOUTH;
|
||||
} else if(yaw >= 135 && yaw < 225) {
|
||||
facing = BlockFace.EAST;
|
||||
opposite = BlockFace.WEST;
|
||||
} else if(yaw >= 225 && yaw < 315) {
|
||||
facing = BlockFace.SOUTH;
|
||||
opposite = BlockFace.NORTH;
|
||||
} else if(yaw >= 315 || yaw < 45) {
|
||||
facing = BlockFace.WEST;
|
||||
opposite = BlockFace.EAST;
|
||||
}
|
||||
this.wall = opposite; // a player facing south places a lobby that looks just like a lobby stuck to the north wall
|
||||
|
||||
private void changeWall(BlockFace newWall) {
|
||||
if(volume == null) {
|
||||
// no previous wall
|
||||
this.volume = new Volume("lobby", war, warzone.getWorld());
|
||||
} else if(volume.isSaved()) {
|
||||
volume.resetBlocks();
|
||||
}
|
||||
|
||||
this.wall = newWall;
|
||||
// find center of the wall and set the new volume corners
|
||||
ZoneVolume zoneVolume = warzone.getVolume();
|
||||
calculateLobbyWidth();
|
||||
|
||||
int lobbyWidth = warzone.getTeams().size() * 4 + 5;
|
||||
lobbyHalfSide = lobbyWidth / 2;
|
||||
if(lobbyHalfSide < 7) {
|
||||
lobbyHalfSide = 7;
|
||||
lobbyMiddleWallBlock = new BlockInfo(warzone.getWorld().getBlockAt(playerLocation.getBlockX(),
|
||||
playerLocation.getBlockY(),
|
||||
playerLocation.getBlockZ())
|
||||
.getFace(facing, 6));
|
||||
|
||||
Block corner1 = null;
|
||||
Block corner2 = null;
|
||||
int x = lobbyMiddleWallBlock.getX();
|
||||
int y = lobbyMiddleWallBlock.getY();
|
||||
int z = lobbyMiddleWallBlock.getZ();
|
||||
|
||||
if(wall == BlockFace.NORTH) {
|
||||
//lobbyMiddleWallBlock = new BlockInfo(warzone.getWorld().getBlockAt(x, y, wallCenterPos));
|
||||
corner1 = warzone.getWorld().getBlockAt(x, y - 1, z + lobbyHalfSide);
|
||||
corner2 = warzone.getWorld().getBlockAt(x - lobbyDepth, y + 1 + lobbyHeight, z - lobbyHalfSide);
|
||||
} else if (wall == BlockFace.EAST){
|
||||
corner1 = warzone.getWorld().getBlockAt(x - lobbyHalfSide, y - 1, z);
|
||||
corner2 = warzone.getWorld().getBlockAt(x + lobbyHalfSide, y + 1 + lobbyHeight, z - lobbyDepth);
|
||||
} else if (wall == BlockFace.SOUTH){
|
||||
corner1 = warzone.getWorld().getBlockAt(x, y -1 , z - lobbyHalfSide);
|
||||
corner2 = warzone.getWorld().getBlockAt(x + lobbyDepth, y + 1 + lobbyHeight, z + lobbyHalfSide);
|
||||
} else if (wall == BlockFace.WEST){
|
||||
corner1 = warzone.getWorld().getBlockAt(x + lobbyHalfSide, y - 1, z);
|
||||
corner2 = warzone.getWorld().getBlockAt(x - lobbyHalfSide, y + 1 + lobbyHeight, z + lobbyDepth);
|
||||
}
|
||||
|
||||
saveLobbyBlocks(corner1, corner2);
|
||||
}
|
||||
|
||||
/**
|
||||
* Classic way of creating a lobby. Lobby position goes to middle of zone wall.
|
||||
* Creates volume or resets. Saves new lobby blocks.
|
||||
* @param newWall
|
||||
*/
|
||||
public void setWall(BlockFace newWall) {
|
||||
createVolumeOrReset();
|
||||
this.wall = newWall;
|
||||
|
||||
ZoneVolume zoneVolume = warzone.getVolume();
|
||||
calculateLobbyWidth();
|
||||
|
||||
Block corner1 = null;
|
||||
Block corner2 = null;
|
||||
|
||||
@ -148,17 +219,37 @@ public class ZoneLobby {
|
||||
corner2 = warzone.getWorld().getBlockAt(wallCenterPos - lobbyHalfSide, y + 1 + lobbyHeight, z + lobbyDepth);
|
||||
}
|
||||
|
||||
saveLobbyBlocks(corner1, corner2);
|
||||
}
|
||||
|
||||
private void createVolumeOrReset() {
|
||||
if(volume == null) {
|
||||
// no previous wall
|
||||
this.volume = new Volume("lobby", war, warzone.getWorld());
|
||||
} else if(volume.isSaved()) {
|
||||
volume.resetBlocks();
|
||||
}
|
||||
}
|
||||
|
||||
private void calculateLobbyWidth() {
|
||||
int lobbyWidth = warzone.getTeams().size() * 4 + 5;
|
||||
lobbyHalfSide = lobbyWidth / 2;
|
||||
if(lobbyHalfSide < 7) {
|
||||
lobbyHalfSide = 7;
|
||||
}
|
||||
}
|
||||
|
||||
private void saveLobbyBlocks(Block corner1, Block corner2) {
|
||||
if(corner1 != null && corner2 != null) {
|
||||
// save the blocks, wide enough for three team gates, 3+1 high and 10 deep, extruding out from the zone wall.
|
||||
this.volume.setCornerOne(corner1);
|
||||
this.volume.setCornerTwo(corner2);
|
||||
this.volume.saveBlocks();
|
||||
//VolumeMapper.save(volume, warzone.getName(), war);
|
||||
}
|
||||
}
|
||||
|
||||
public void initialize() {
|
||||
changeWall(wall); // watch out! this saves the lobby blocks (you gotta the lobby blocks before)
|
||||
//changeWall(wall); // watch out! this resets+saves the lobby blocks
|
||||
|
||||
// maybe the number of teams change, now reset the gate positions
|
||||
setGatePositions(BlockInfo.getBlock(warzone.getWorld(), lobbyMiddleWallBlock));
|
||||
|
Loading…
Reference in New Issue
Block a user