mirror of
https://github.com/taoneill/war.git
synced 2024-11-27 20:59:39 +01:00
Fixed plugin class ctor to add folder for Configuration. Fixed from-disk lobby initialization so its positon doesnt change.
This commit is contained in:
parent
1e6d8d1e1d
commit
5a16e08c7a
@ -28,8 +28,9 @@ import java.util.logging.Logger;
|
||||
public class War extends JavaPlugin {
|
||||
|
||||
public War(PluginLoader pluginLoader, Server instance,
|
||||
PluginDescriptionFile desc, File plugin, ClassLoader cLoader) {
|
||||
super(pluginLoader, instance, desc, plugin, cLoader);
|
||||
PluginDescriptionFile desc, File folder, File plugin, ClassLoader cLoader) {
|
||||
super(pluginLoader, instance, desc, folder, plugin, cLoader);
|
||||
// TODO: switch to bukkit config file
|
||||
}
|
||||
|
||||
|
||||
|
@ -352,7 +352,7 @@ public class WarPlayerListener extends PlayerListener {
|
||||
if(lobby != null) {
|
||||
// reset existing lobby
|
||||
lobby.getVolume().resetBlocks();
|
||||
lobby.setWall(wall);
|
||||
lobby.changeWall(wall);
|
||||
lobby.initialize();
|
||||
player.sendMessage(war.str("Warzone lobby moved to " + wallStr + "side of zone."));
|
||||
} else {
|
||||
|
@ -160,6 +160,10 @@ public class Warzone {
|
||||
monument.getVolume().resetBlocks();
|
||||
}
|
||||
|
||||
if(lobby != null) {
|
||||
lobby.getVolume().resetBlocks();
|
||||
}
|
||||
|
||||
int saved = volume.saveBlocks();
|
||||
initializeZone(); // bring back stuff
|
||||
return saved;
|
||||
@ -617,7 +621,8 @@ public class Warzone {
|
||||
playerGuards.add(guard);
|
||||
int reset = volume.resetWallBlocks(guard.getWall()); // this should restore old blocks
|
||||
if(lobby != null) {
|
||||
lobby.getVolume().resetBlocks();
|
||||
lobby.getVolume().resetBlocks(); // always reset the lobby even if the guard is on another wall
|
||||
// because player can go around corner
|
||||
lobby.initialize();
|
||||
}
|
||||
if(drawZoneOutline) {
|
||||
|
@ -21,6 +21,7 @@ public class ZoneLobby {
|
||||
private final Warzone warzone;
|
||||
private BlockFace wall;
|
||||
private Volume volume;
|
||||
Block lobbyMiddleWallBlock = null; // on the zone wall, one above the zone lobby floor
|
||||
|
||||
Block warHubLinkGate = null;
|
||||
|
||||
@ -31,80 +32,116 @@ public class ZoneLobby {
|
||||
|
||||
Block zoneTeleportBlock = null;
|
||||
|
||||
private final int lobbyHeight = 3;
|
||||
private final int lobbyHalfSide = 7;
|
||||
private final int lobbyDepth = 10;
|
||||
|
||||
public ZoneLobby(War war, Warzone warzone, BlockFace wall) {
|
||||
this.war = war;
|
||||
this.warzone = warzone;
|
||||
this.setWall(wall);
|
||||
this.volume = new Volume("lobby", war, warzone.getWorld());
|
||||
this.changeWall(wall);
|
||||
}
|
||||
|
||||
/**
|
||||
* Convenience ctor when loading form disk.
|
||||
* This figures out the middle wall block of the lobby from the volume instead
|
||||
* of the other way around.
|
||||
*/
|
||||
public ZoneLobby(War war, Warzone warzone, BlockFace wall, Volume volume) {
|
||||
this.war = war;
|
||||
this.warzone = warzone;
|
||||
Volume zoneVolume = warzone.getVolume();
|
||||
this.wall = wall;
|
||||
this.setVolume(volume);
|
||||
// we're setting the zoneVolume directly, so we need to figure out the lobbyMiddleWallBlock on our own
|
||||
if(wall == BlockFace.North) {
|
||||
lobbyMiddleWallBlock = volume.getCornerOne().getFace(BlockFace.Up).getFace(BlockFace.East, lobbyHalfSide);
|
||||
} else if (wall == BlockFace.East){
|
||||
lobbyMiddleWallBlock = volume.getCornerOne().getFace(BlockFace.Up).getFace(BlockFace.South, lobbyHalfSide);
|
||||
} else if (wall == BlockFace.South){
|
||||
lobbyMiddleWallBlock = volume.getCornerOne().getFace(BlockFace.Up).getFace(BlockFace.West, lobbyHalfSide);
|
||||
} else if (wall == BlockFace.West){
|
||||
lobbyMiddleWallBlock = volume.getCornerOne().getFace(BlockFace.Up).getFace(BlockFace.North, lobbyHalfSide);
|
||||
}
|
||||
}
|
||||
|
||||
public void changeWall(BlockFace newWall) {
|
||||
if(this.wall != newWall) {
|
||||
if(volume == null) {
|
||||
// no previous wall
|
||||
this.volume = new Volume("lobby", war, warzone.getWorld());
|
||||
} else {
|
||||
// move the lobby
|
||||
this.volume.resetBlocks();
|
||||
}
|
||||
|
||||
this.wall = newWall;
|
||||
// find center of the wall and set the new volume corners
|
||||
VerticalVolume zoneVolume = warzone.getVolume();
|
||||
|
||||
Block corner1 = null;
|
||||
Block corner2 = null;
|
||||
|
||||
if(wall == BlockFace.North) {
|
||||
int wallStart = zoneVolume.getMinZ();
|
||||
int wallEnd = zoneVolume.getMaxZ();
|
||||
int x = zoneVolume.getMinX();
|
||||
int wallLength = wallEnd - wallStart + 1;
|
||||
int wallCenterPos = wallStart + wallLength / 2;
|
||||
int highestNonAirBlockAtCenter = warzone.getWorld().getHighestBlockYAt(x, wallCenterPos);
|
||||
lobbyMiddleWallBlock = warzone.getWorld().getBlockAt(x, highestNonAirBlockAtCenter+1, wallCenterPos);
|
||||
corner1 = warzone.getWorld().getBlockAt(x, highestNonAirBlockAtCenter, wallCenterPos + lobbyHalfSide);
|
||||
corner2 = warzone.getWorld().getBlockAt(x - lobbyDepth,
|
||||
highestNonAirBlockAtCenter + 1 + lobbyHeight, wallCenterPos - lobbyHalfSide);
|
||||
} else if (wall == BlockFace.East){
|
||||
int wallStart = zoneVolume.getMinX();
|
||||
int wallEnd = zoneVolume.getMaxX();
|
||||
int z = zoneVolume.getMinZ();
|
||||
int wallLength = wallEnd - wallStart + 1;
|
||||
int wallCenterPos = wallStart + wallLength / 2;
|
||||
int highestNonAirBlockAtCenter = warzone.getWorld().getHighestBlockYAt(wallCenterPos, z);
|
||||
lobbyMiddleWallBlock = warzone.getWorld().getBlockAt(wallCenterPos, highestNonAirBlockAtCenter + 1, z);
|
||||
corner1 = warzone.getWorld().getBlockAt(wallCenterPos - lobbyHalfSide, highestNonAirBlockAtCenter, z);
|
||||
corner2 = warzone.getWorld().getBlockAt(wallCenterPos + lobbyHalfSide,
|
||||
highestNonAirBlockAtCenter + 1 + lobbyHeight, z - lobbyDepth);
|
||||
} else if (wall == BlockFace.South){
|
||||
int wallStart = zoneVolume.getMinZ();
|
||||
int wallEnd = zoneVolume.getMaxZ();
|
||||
int x = zoneVolume.getMaxX();
|
||||
int wallLength = wallEnd - wallStart + 1;
|
||||
int wallCenterPos = wallStart + wallLength / 2;
|
||||
int highestNonAirBlockAtCenter = warzone.getWorld().getHighestBlockYAt(x, wallCenterPos);
|
||||
lobbyMiddleWallBlock = warzone.getWorld().getBlockAt(x, highestNonAirBlockAtCenter + 1, wallCenterPos);
|
||||
corner1 = warzone.getWorld().getBlockAt(x, highestNonAirBlockAtCenter, wallCenterPos - lobbyHalfSide);
|
||||
corner2 = warzone.getWorld().getBlockAt(x + lobbyDepth,
|
||||
highestNonAirBlockAtCenter + 1 + lobbyHeight, wallCenterPos + lobbyHalfSide);
|
||||
} else if (wall == BlockFace.West){
|
||||
int wallStart = zoneVolume.getMinX();
|
||||
int wallEnd = zoneVolume.getMaxX();
|
||||
int z = zoneVolume.getMaxZ();
|
||||
int wallLength = wallEnd - wallStart + 1;
|
||||
int wallCenterPos = wallStart + wallLength / 2;
|
||||
int highestNonAirBlockAtCenter = warzone.getWorld().getHighestBlockYAt(wallCenterPos, z);
|
||||
lobbyMiddleWallBlock = warzone.getWorld().getBlockAt(wallCenterPos, highestNonAirBlockAtCenter + 1, z);
|
||||
corner1 = warzone.getWorld().getBlockAt(wallCenterPos + lobbyHalfSide, highestNonAirBlockAtCenter, z);
|
||||
corner2 = warzone.getWorld().getBlockAt(wallCenterPos - lobbyHalfSide, highestNonAirBlockAtCenter + 1 + lobbyHeight, z + lobbyDepth);
|
||||
}
|
||||
|
||||
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() {
|
||||
// find center of the wall and position of all elements
|
||||
VerticalVolume zoneVolume = warzone.getVolume();
|
||||
Location nw = warzone.getNorthwest();
|
||||
Block nwBlock = warzone.getWorld().getBlockAt(nw.getBlockX(), nw.getBlockY(), nw.getBlockZ());
|
||||
Location se = warzone.getSoutheast();
|
||||
Block seBlock = warzone.getWorld().getBlockAt(se.getBlockX(), se.getBlockY(), se.getBlockZ());
|
||||
Block lobbyMiddleWallBlock = null;
|
||||
Block corner1 = null;
|
||||
Block corner2 = null;
|
||||
|
||||
int lobbyHeight = 3;
|
||||
int lobbyHalfSide = 7;
|
||||
int lobbyDepth = 10;
|
||||
if(wall == BlockFace.North) {
|
||||
int wallStart = zoneVolume.getMinZ();
|
||||
int wallEnd = zoneVolume.getMaxZ();
|
||||
int x = zoneVolume.getMinX();
|
||||
int wallLength = wallEnd - wallStart + 1;
|
||||
int wallCenterPos = wallStart + wallLength / 2;
|
||||
int highestNonAirBlockAtCenter = warzone.getWorld().getHighestBlockYAt(x, wallCenterPos);
|
||||
lobbyMiddleWallBlock = warzone.getWorld().getBlockAt(x, highestNonAirBlockAtCenter+1, wallCenterPos);
|
||||
corner1 = warzone.getWorld().getBlockAt(x, highestNonAirBlockAtCenter, wallCenterPos + lobbyHalfSide);
|
||||
corner2 = warzone.getWorld().getBlockAt(x - lobbyDepth, highestNonAirBlockAtCenter + 1 + lobbyHeight, wallCenterPos - lobbyHalfSide);
|
||||
setGatePositions(lobbyMiddleWallBlock);
|
||||
} else if (wall == BlockFace.East){
|
||||
int wallStart = zoneVolume.getMinX();
|
||||
int wallEnd = zoneVolume.getMaxX();
|
||||
int z = zoneVolume.getMinZ();
|
||||
int wallLength = wallEnd - wallStart + 1;
|
||||
int wallCenterPos = wallStart + wallLength / 2;
|
||||
int highestNonAirBlockAtCenter = warzone.getWorld().getHighestBlockYAt(wallCenterPos, z);
|
||||
lobbyMiddleWallBlock = warzone.getWorld().getBlockAt(wallCenterPos, highestNonAirBlockAtCenter + 1, z);
|
||||
corner1 = warzone.getWorld().getBlockAt(wallCenterPos - lobbyHalfSide, highestNonAirBlockAtCenter, z);
|
||||
corner2 = warzone.getWorld().getBlockAt(wallCenterPos + lobbyHalfSide, highestNonAirBlockAtCenter + 1 + lobbyHeight, z - lobbyDepth);
|
||||
setGatePositions(lobbyMiddleWallBlock);
|
||||
} else if (wall == BlockFace.South){
|
||||
int wallStart = zoneVolume.getMinZ();
|
||||
int wallEnd = zoneVolume.getMaxZ();
|
||||
int x = zoneVolume.getMaxX();
|
||||
int wallLength = wallEnd - wallStart + 1;
|
||||
int wallCenterPos = wallStart + wallLength / 2;
|
||||
int highestNonAirBlockAtCenter = warzone.getWorld().getHighestBlockYAt(x, wallCenterPos);
|
||||
lobbyMiddleWallBlock = warzone.getWorld().getBlockAt(x, highestNonAirBlockAtCenter + 1, wallCenterPos);
|
||||
corner1 = warzone.getWorld().getBlockAt(x, highestNonAirBlockAtCenter, wallCenterPos - lobbyHalfSide);
|
||||
corner2 = warzone.getWorld().getBlockAt(x + lobbyDepth, highestNonAirBlockAtCenter + 1 + lobbyHeight, wallCenterPos + lobbyHalfSide);
|
||||
setGatePositions(lobbyMiddleWallBlock);
|
||||
} else if (wall == BlockFace.West){
|
||||
int wallStart = zoneVolume.getMinX();
|
||||
int wallEnd = zoneVolume.getMaxX();
|
||||
int z = zoneVolume.getMaxZ();
|
||||
int wallLength = wallEnd - wallStart + 1;
|
||||
int wallCenterPos = wallStart + wallLength / 2;
|
||||
int highestNonAirBlockAtCenter = warzone.getWorld().getHighestBlockYAt(wallCenterPos, z);
|
||||
lobbyMiddleWallBlock = warzone.getWorld().getBlockAt(wallCenterPos, highestNonAirBlockAtCenter + 1, z);
|
||||
corner1 = warzone.getWorld().getBlockAt(wallCenterPos + lobbyHalfSide, highestNonAirBlockAtCenter, z);
|
||||
corner2 = warzone.getWorld().getBlockAt(wallCenterPos - lobbyHalfSide, highestNonAirBlockAtCenter + 1 + lobbyHeight, z + lobbyDepth);
|
||||
setGatePositions(lobbyMiddleWallBlock);
|
||||
}
|
||||
|
||||
if(lobbyMiddleWallBlock != null && 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);
|
||||
|
||||
// maybe the number of teams change, now reset the gate positions
|
||||
setGatePositions(lobbyMiddleWallBlock);
|
||||
|
||||
if(lobbyMiddleWallBlock != null && volume != null && volume.isSaved()) {
|
||||
// flatten the area (set all but floor to air, then replace any floor air blocks with glass)
|
||||
this.volume.setToMaterial(Material.AIR);
|
||||
this.volume.setFaceMaterial(BlockFace.Down, Material.GLASS); // beautiful
|
||||
@ -123,6 +160,8 @@ public class ZoneLobby {
|
||||
// set zone tp
|
||||
zoneTeleportBlock = lobbyMiddleWallBlock.getFace(wall, 6);
|
||||
warzone.setTeleport(new Location(warzone.getWorld(), zoneTeleportBlock.getX(), zoneTeleportBlock.getY(), zoneTeleportBlock.getZ()));
|
||||
} else {
|
||||
war.getLogger().warning("Failed to initalize zone " + warzone.getName());
|
||||
}
|
||||
}
|
||||
|
||||
@ -311,10 +350,6 @@ public class ZoneLobby {
|
||||
return wall;
|
||||
}
|
||||
|
||||
public void setWall(BlockFace wall) {
|
||||
this.wall = wall;
|
||||
}
|
||||
|
||||
public boolean isInWarHubLinkGate(Location location) {
|
||||
if(warHubLinkGate != null
|
||||
&& location.getBlockX() == warHubLinkGate.getX()
|
||||
|
@ -152,6 +152,27 @@ public class WarzoneMapper {
|
||||
|
||||
// lobby
|
||||
String lobbyStr = warzoneConfig.getString("lobby");
|
||||
|
||||
warzoneConfig.close();
|
||||
|
||||
if(loadBlocks && warzone.getNorthwest() != null && warzone.getSoutheast() != null) {
|
||||
|
||||
// zone blocks
|
||||
VerticalVolume zoneVolume = VolumeMapper.loadVerticalVolume(warzone.getName(), warzone.getName(), war, warzone.getWorld());
|
||||
warzone.setVolume(zoneVolume);
|
||||
}
|
||||
|
||||
// monument blocks
|
||||
for(Monument monument: warzone.getMonuments()) {
|
||||
monument.setVolume(VolumeMapper.loadCenteredVolume(monument.getName(),warzone.getName(), 7, war, world));
|
||||
}
|
||||
|
||||
// team spawn blocks
|
||||
for(Team team : warzone.getTeams()) {
|
||||
team.setVolume(VolumeMapper.loadVolume(team.getName(), warzone.getName(), war, world));
|
||||
}
|
||||
|
||||
// lobby
|
||||
BlockFace lobbyFace = null;
|
||||
if(lobbyStr != null && !lobbyStr.equals("")){
|
||||
if(lobbyStr.equals("south")) {
|
||||
@ -162,40 +183,12 @@ public class WarzoneMapper {
|
||||
lobbyFace = BlockFace.North;
|
||||
} else if(lobbyStr.equals("west")) {
|
||||
lobbyFace = BlockFace.West;
|
||||
}
|
||||
ZoneLobby lobby = new ZoneLobby(war, warzone, lobbyFace);
|
||||
}
|
||||
Volume lobbyVolume = VolumeMapper.loadVolume("lobby", warzone.getName(), war, world);
|
||||
ZoneLobby lobby = new ZoneLobby(war, warzone, lobbyFace, lobbyVolume);
|
||||
warzone.setLobby(lobby);
|
||||
}
|
||||
|
||||
warzoneConfig.close();
|
||||
|
||||
if(loadBlocks && warzone.getNorthwest() != null && warzone.getSoutheast() != null) {
|
||||
|
||||
// zone blocks
|
||||
VerticalVolume zoneVolume = VolumeMapper.loadVerticalVolume(warzone.getName(), warzone.getName(), war, warzone.getWorld());
|
||||
warzone.setVolume(zoneVolume);
|
||||
|
||||
// monument blocks
|
||||
for(Monument monument: warzone.getMonuments()) {
|
||||
monument.setVolume(VolumeMapper.loadCenteredVolume(monument.getName(),warzone.getName(), 7, war, world));
|
||||
}
|
||||
|
||||
// team spawn blocks
|
||||
for(Team team : warzone.getTeams()) {
|
||||
team.setVolume(VolumeMapper.loadVolume(team.getName(), warzone.getName(), war, world));
|
||||
}
|
||||
|
||||
// lobby
|
||||
if(warzone.getLobby() != null) {
|
||||
Volume lobbyVolume = VolumeMapper.loadVolume("lobby", warzone.getName(), war, world);
|
||||
warzone.getLobby().setVolume(lobbyVolume);
|
||||
}
|
||||
|
||||
//war.getLogger().info("Loaded warzone " + name + " config and blocks.");
|
||||
} else {
|
||||
//war.getLogger().info("Loaded warzone " + name + " config.");
|
||||
}
|
||||
|
||||
|
||||
return warzone;
|
||||
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user