mirror of
https://github.com/taoneill/war.git
synced 2025-02-20 05:11:21 +01:00
Closes gh-26. Warhub orientation can now be selected.
This commit is contained in:
parent
e03365cff6
commit
54ab0d72f3
@ -24,11 +24,31 @@ public class WarHub {
|
|||||||
private Location location;
|
private Location location;
|
||||||
private Volume volume;
|
private Volume volume;
|
||||||
private Map<String, Block> zoneGateBlocks = new HashMap<String, Block>();
|
private Map<String, Block> zoneGateBlocks = new HashMap<String, Block>();
|
||||||
|
private BlockFace orientation;
|
||||||
|
|
||||||
|
public WarHub(War war, Location location, String hubOrientation) {
|
||||||
|
this.war = war;
|
||||||
|
this.location = location;
|
||||||
|
this.volume = new Volume("warhub", war, location.getWorld());
|
||||||
|
if (hubOrientation.equals("south")) {
|
||||||
|
this.setOrientation(BlockFace.SOUTH);
|
||||||
|
} else if (hubOrientation.equals("north")) {
|
||||||
|
this.setOrientation(BlockFace.SOUTH);
|
||||||
|
} else if (hubOrientation.equals("east")) {
|
||||||
|
this.setOrientation(BlockFace.EAST);
|
||||||
|
} else {
|
||||||
|
this.setOrientation(BlockFace.WEST);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
// Use when creating from player location (with yaw)
|
||||||
public WarHub(War war, Location location) {
|
public WarHub(War war, Location location) {
|
||||||
this.war = war;
|
this.war = war;
|
||||||
this.location = location;
|
this.location = location;
|
||||||
this.volume = new Volume("warhub", war, location.getWorld());
|
this.volume = new Volume("warhub", war, location.getWorld());
|
||||||
|
|
||||||
|
setLocation(location);
|
||||||
}
|
}
|
||||||
|
|
||||||
public Volume getVolume() {
|
public Volume getVolume() {
|
||||||
@ -37,6 +57,29 @@ public class WarHub {
|
|||||||
|
|
||||||
public void setLocation(Location loc) {
|
public void setLocation(Location loc) {
|
||||||
this.location = loc;
|
this.location = loc;
|
||||||
|
// Lobby orientation
|
||||||
|
int yaw = 0;
|
||||||
|
if (location.getYaw() >= 0) {
|
||||||
|
yaw = (int) (location.getYaw() % 360);
|
||||||
|
} else {
|
||||||
|
yaw = (int) (360 + (location.getYaw() % 360));
|
||||||
|
}
|
||||||
|
BlockFace facing = null;
|
||||||
|
BlockFace opposite = null;
|
||||||
|
if ((yaw >= 0 && yaw < 45) || (yaw >= 315 && yaw <= 360)) {
|
||||||
|
facing = BlockFace.WEST;
|
||||||
|
opposite = BlockFace.EAST;
|
||||||
|
} else 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;
|
||||||
|
}
|
||||||
|
this.setOrientation(facing);
|
||||||
}
|
}
|
||||||
|
|
||||||
public Location getLocation() {
|
public Location getLocation() {
|
||||||
@ -70,9 +113,36 @@ public class WarHub {
|
|||||||
int hubDepth = 6;
|
int hubDepth = 6;
|
||||||
int hubHeigth = 4;
|
int hubHeigth = 4;
|
||||||
|
|
||||||
|
BlockFace left;
|
||||||
|
BlockFace right;
|
||||||
|
BlockFace front = this.getOrientation();
|
||||||
|
BlockFace back;
|
||||||
|
byte data;
|
||||||
|
if (this.getOrientation() == BlockFace.SOUTH) {
|
||||||
|
data = (byte) 4;
|
||||||
|
left = BlockFace.EAST;
|
||||||
|
right = BlockFace.WEST;
|
||||||
|
back = BlockFace.NORTH;
|
||||||
|
} else if (this.getOrientation() == BlockFace.NORTH) {
|
||||||
|
data = (byte) 12;
|
||||||
|
left = BlockFace.WEST;
|
||||||
|
right = BlockFace.EAST;
|
||||||
|
back = BlockFace.SOUTH;
|
||||||
|
} else if (this.getOrientation() == BlockFace.EAST) {
|
||||||
|
data = (byte) 0;
|
||||||
|
left = BlockFace.NORTH;
|
||||||
|
right = BlockFace.SOUTH;
|
||||||
|
back = BlockFace.WEST;
|
||||||
|
} else {
|
||||||
|
data = (byte) 8;
|
||||||
|
left = BlockFace.SOUTH;
|
||||||
|
right = BlockFace.NORTH;
|
||||||
|
back = BlockFace.EAST;
|
||||||
|
}
|
||||||
|
|
||||||
Block locationBlock = this.location.getWorld().getBlockAt(this.location.getBlockX(), this.location.getBlockY(), this.location.getBlockZ());
|
Block locationBlock = this.location.getWorld().getBlockAt(this.location.getBlockX(), this.location.getBlockY(), this.location.getBlockZ());
|
||||||
this.volume.setCornerOne(locationBlock.getFace(BlockFace.EAST).getFace(BlockFace.SOUTH, halfHubWidth).getFace(BlockFace.DOWN));
|
this.volume.setCornerOne(locationBlock.getFace(back).getFace(left, halfHubWidth).getFace(BlockFace.DOWN));
|
||||||
this.volume.setCornerTwo(locationBlock.getFace(BlockFace.NORTH, halfHubWidth).getFace(BlockFace.WEST, hubDepth).getFace(BlockFace.UP, hubHeigth));
|
this.volume.setCornerTwo(locationBlock.getFace(right, halfHubWidth).getFace(front, hubDepth).getFace(BlockFace.UP, hubHeigth));
|
||||||
this.volume.saveBlocks();
|
this.volume.saveBlocks();
|
||||||
|
|
||||||
// glass floor
|
// glass floor
|
||||||
@ -81,7 +151,7 @@ public class WarHub {
|
|||||||
this.volume.setFaceMaterial(BlockFace.DOWN, Material.GLASS);
|
this.volume.setFaceMaterial(BlockFace.DOWN, Material.GLASS);
|
||||||
|
|
||||||
// draw gates
|
// draw gates
|
||||||
Block currentGateBlock = BlockInfo.getBlock(this.location.getWorld(), this.volume.getCornerOne()).getFace(BlockFace.UP).getFace(BlockFace.WEST, hubDepth).getFace(BlockFace.NORTH, 2);
|
Block currentGateBlock = BlockInfo.getBlock(this.location.getWorld(), this.volume.getCornerOne()).getFace(BlockFace.UP).getFace(front, hubDepth).getFace(right, 2);
|
||||||
|
|
||||||
for (Warzone zone : this.war.getWarzones()) { // gonna use the index to find it again
|
for (Warzone zone : this.war.getWarzones()) { // gonna use the index to find it again
|
||||||
if (!zone.isDisabled()) {
|
if (!zone.isDisabled()) {
|
||||||
@ -89,27 +159,27 @@ public class WarHub {
|
|||||||
currentGateBlock.getFace(BlockFace.DOWN).setType(Material.GLOWSTONE);
|
currentGateBlock.getFace(BlockFace.DOWN).setType(Material.GLOWSTONE);
|
||||||
currentGateBlock.setType(Material.PORTAL);
|
currentGateBlock.setType(Material.PORTAL);
|
||||||
currentGateBlock.getFace(BlockFace.UP).setType(Material.PORTAL);
|
currentGateBlock.getFace(BlockFace.UP).setType(Material.PORTAL);
|
||||||
currentGateBlock.getFace(BlockFace.SOUTH).setType(Material.OBSIDIAN);
|
currentGateBlock.getFace(left).setType(Material.OBSIDIAN);
|
||||||
currentGateBlock.getFace(BlockFace.NORTH).getFace(BlockFace.UP).setType(Material.OBSIDIAN);
|
currentGateBlock.getFace(right).getFace(BlockFace.UP).setType(Material.OBSIDIAN);
|
||||||
currentGateBlock.getFace(BlockFace.SOUTH).getFace(BlockFace.UP).getFace(BlockFace.UP).setType(Material.OBSIDIAN);
|
currentGateBlock.getFace(left).getFace(BlockFace.UP).getFace(BlockFace.UP).setType(Material.OBSIDIAN);
|
||||||
currentGateBlock.getFace(BlockFace.NORTH).setType(Material.OBSIDIAN);
|
currentGateBlock.getFace(right).setType(Material.OBSIDIAN);
|
||||||
currentGateBlock.getFace(BlockFace.SOUTH).getFace(BlockFace.UP).setType(Material.OBSIDIAN);
|
currentGateBlock.getFace(left).getFace(BlockFace.UP).setType(Material.OBSIDIAN);
|
||||||
currentGateBlock.getFace(BlockFace.NORTH).getFace(BlockFace.UP).getFace(BlockFace.UP).setType(Material.OBSIDIAN);
|
currentGateBlock.getFace(right).getFace(BlockFace.UP).getFace(BlockFace.UP).setType(Material.OBSIDIAN);
|
||||||
currentGateBlock.getFace(BlockFace.UP).getFace(BlockFace.UP).setType(Material.OBSIDIAN);
|
currentGateBlock.getFace(BlockFace.UP).getFace(BlockFace.UP).setType(Material.OBSIDIAN);
|
||||||
currentGateBlock = currentGateBlock.getFace(BlockFace.NORTH, 4);
|
currentGateBlock = currentGateBlock.getFace(right, 4);
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// War hub sign
|
// War hub sign
|
||||||
Block signBlock = locationBlock.getFace(BlockFace.WEST);
|
Block signBlock = locationBlock.getFace(front);
|
||||||
|
|
||||||
String[] lines = new String[4];
|
String[] lines = new String[4];
|
||||||
lines[0] = "War hub";
|
lines[0] = "War hub";
|
||||||
lines[1] = "(/warhub)";
|
lines[1] = "(/warhub)";
|
||||||
lines[2] = "Pick your";
|
lines[2] = "Pick your";
|
||||||
lines[3] = "battle!";
|
lines[3] = "battle!";
|
||||||
SignHelper.setToSign(this.war, signBlock, (byte) 8, lines);
|
SignHelper.setToSign(this.war, signBlock, data, lines);
|
||||||
|
|
||||||
// Warzone signs
|
// Warzone signs
|
||||||
for (Warzone zone : this.war.getWarzones()) {
|
for (Warzone zone : this.war.getWarzones()) {
|
||||||
@ -122,12 +192,39 @@ public class WarHub {
|
|||||||
|
|
||||||
public void resetZoneSign(Warzone zone) {
|
public void resetZoneSign(Warzone zone) {
|
||||||
|
|
||||||
|
BlockFace left;
|
||||||
|
BlockFace right;
|
||||||
|
BlockFace front = this.getOrientation();
|
||||||
|
BlockFace back;
|
||||||
|
byte data;
|
||||||
|
if (this.getOrientation() == BlockFace.SOUTH) {
|
||||||
|
data = (byte) 4;
|
||||||
|
left = BlockFace.EAST;
|
||||||
|
right = BlockFace.WEST;
|
||||||
|
back = BlockFace.NORTH;
|
||||||
|
} else if (this.getOrientation() == BlockFace.NORTH) {
|
||||||
|
data = (byte) 12;
|
||||||
|
left = BlockFace.WEST;
|
||||||
|
right = BlockFace.EAST;
|
||||||
|
back = BlockFace.SOUTH;
|
||||||
|
} else if (this.getOrientation() == BlockFace.EAST) {
|
||||||
|
data = (byte) 0;
|
||||||
|
left = BlockFace.NORTH;
|
||||||
|
right = BlockFace.SOUTH;
|
||||||
|
back = BlockFace.WEST;
|
||||||
|
} else {
|
||||||
|
data = (byte) 8;
|
||||||
|
left = BlockFace.SOUTH;
|
||||||
|
right = BlockFace.NORTH;
|
||||||
|
back = BlockFace.EAST;
|
||||||
|
}
|
||||||
|
|
||||||
Block zoneGate = this.zoneGateBlocks.get(zone.getName());
|
Block zoneGate = this.zoneGateBlocks.get(zone.getName());
|
||||||
Block block = zoneGate.getFace(BlockFace.SOUTH).getFace(BlockFace.EAST, 1);
|
Block block = zoneGate.getFace(left).getFace(back, 1);
|
||||||
if (block.getType() != Material.SIGN_POST) {
|
if (block.getType() != Material.SIGN_POST) {
|
||||||
block.setType(Material.SIGN_POST);
|
block.setType(Material.SIGN_POST);
|
||||||
}
|
}
|
||||||
block.setData((byte) 8);
|
block.setData(data);
|
||||||
|
|
||||||
int zoneCap = 0;
|
int zoneCap = 0;
|
||||||
int zonePlayers = 0;
|
int zonePlayers = 0;
|
||||||
@ -140,11 +237,19 @@ public class WarHub {
|
|||||||
lines[1] = zone.getName();
|
lines[1] = zone.getName();
|
||||||
lines[2] = zonePlayers + "/" + zoneCap + " players";
|
lines[2] = zonePlayers + "/" + zoneCap + " players";
|
||||||
lines[3] = zone.getTeams().size() + " teams";
|
lines[3] = zone.getTeams().size() + " teams";
|
||||||
SignHelper.setToSign(this.war, block, (byte) 8, lines);
|
SignHelper.setToSign(this.war, block, data, lines);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setVolume(Volume vol) {
|
public void setVolume(Volume vol) {
|
||||||
this.volume = vol;
|
this.volume = vol;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void setOrientation(BlockFace orientation) {
|
||||||
|
this.orientation = orientation;
|
||||||
|
}
|
||||||
|
|
||||||
|
public BlockFace getOrientation() {
|
||||||
|
return orientation;
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -134,20 +134,6 @@ public class ZoneLobby {
|
|||||||
opposite = BlockFace.NORTH;
|
opposite = BlockFace.NORTH;
|
||||||
}
|
}
|
||||||
|
|
||||||
// float yaw = playerLocation.getYaw() % 360;
|
|
||||||
// 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
|
this.wall = opposite; // a player facing south places a lobby that looks just like a lobby stuck to the north wall
|
||||||
|
|
||||||
this.calculateLobbyWidth();
|
this.calculateLobbyWidth();
|
||||||
|
@ -28,16 +28,20 @@ public class RestoreWarhubJob implements Runnable {
|
|||||||
int hubZ = Integer.parseInt(hubStrSplit[2]);
|
int hubZ = Integer.parseInt(hubStrSplit[2]);
|
||||||
World world = null;
|
World world = null;
|
||||||
String worldName;
|
String worldName;
|
||||||
|
String hubOrientation = "west";
|
||||||
if (hubStrSplit.length > 3) {
|
if (hubStrSplit.length > 3) {
|
||||||
worldName = hubStrSplit[3];
|
worldName = hubStrSplit[3];
|
||||||
world = this.war.getServer().getWorld(worldName);
|
world = this.war.getServer().getWorld(worldName);
|
||||||
|
if(hubStrSplit.length > 4) {
|
||||||
|
hubOrientation = hubStrSplit[4];
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
worldName = "DEFAULT";
|
worldName = "DEFAULT";
|
||||||
world = this.war.getServer().getWorlds().get(0); // default to first world
|
world = this.war.getServer().getWorlds().get(0); // default to first world
|
||||||
}
|
}
|
||||||
if (world != null) {
|
if (world != null) {
|
||||||
Location hubLocation = new Location(world, hubX, hubY, hubZ);
|
Location hubLocation = new Location(world, hubX, hubY, hubZ);
|
||||||
WarHub hub = new WarHub(this.war, hubLocation);
|
WarHub hub = new WarHub(this.war, hubLocation, hubOrientation);
|
||||||
this.war.setWarHub(hub);
|
this.war.setWarHub(hub);
|
||||||
Volume vol = VolumeMapper.loadVolume("warhub", "", this.war, world);
|
Volume vol = VolumeMapper.loadVolume("warhub", "", this.war, world);
|
||||||
hub.setVolume(vol);
|
hub.setVolume(vol);
|
||||||
|
@ -4,6 +4,7 @@ import java.io.File;
|
|||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
|
|
||||||
|
import org.bukkit.block.BlockFace;
|
||||||
import org.bukkit.inventory.ItemStack;
|
import org.bukkit.inventory.ItemStack;
|
||||||
|
|
||||||
import bukkit.tommytony.war.War;
|
import bukkit.tommytony.war.War;
|
||||||
@ -273,7 +274,18 @@ public class WarMapper {
|
|||||||
String hubStr = "";
|
String hubStr = "";
|
||||||
WarHub hub = war.getWarHub();
|
WarHub hub = war.getWarHub();
|
||||||
if (hub != null) {
|
if (hub != null) {
|
||||||
hubStr = hub.getLocation().getBlockX() + "," + hub.getLocation().getBlockY() + "," + hub.getLocation().getBlockZ() + "," + hub.getLocation().getWorld().getName();
|
String orientationStr = "";
|
||||||
|
if (BlockFace.SOUTH == hub.getOrientation()) {
|
||||||
|
orientationStr = "south";
|
||||||
|
} else if (BlockFace.EAST == hub.getOrientation()) {
|
||||||
|
orientationStr = "east";
|
||||||
|
} else if (BlockFace.NORTH == hub.getOrientation()) {
|
||||||
|
orientationStr = "north";
|
||||||
|
} else {
|
||||||
|
orientationStr = "west";
|
||||||
|
}
|
||||||
|
hubStr = hub.getLocation().getBlockX() + "," + hub.getLocation().getBlockY() + "," + hub.getLocation().getBlockZ() + ","
|
||||||
|
+ hub.getLocation().getWorld().getName() + "," + orientationStr;
|
||||||
VolumeMapper.save(hub.getVolume(), "", war);
|
VolumeMapper.save(hub.getVolume(), "", war);
|
||||||
}
|
}
|
||||||
warConfig.setString("warhub", hubStr);
|
warConfig.setString("warhub", hubStr);
|
||||||
|
Loading…
Reference in New Issue
Block a user