mirror of
https://github.com/taoneill/war.git
synced 2024-11-23 18:55:28 +01:00
Warzone lobbies and warhub, related commands, teleports for gates in both. Auto-assign.
This commit is contained in:
parent
6c39559c04
commit
81ce4627f0
@ -9,6 +9,7 @@ import org.bukkit.plugin.PluginManager;
|
||||
import org.bukkit.plugin.java.JavaPlugin;
|
||||
|
||||
import com.tommytony.war.Team;
|
||||
import com.tommytony.war.WarHub;
|
||||
import com.tommytony.war.Warzone;
|
||||
import com.tommytony.war.mappers.WarMapper;
|
||||
|
||||
@ -45,6 +46,7 @@ public class War extends JavaPlugin {
|
||||
private boolean defaultFriendlyFire = false;
|
||||
private boolean defaultDrawZoneOutline = true;
|
||||
private boolean defaultAutoAssignOnly = false;
|
||||
private WarHub warHub;
|
||||
|
||||
public void onDisable() {
|
||||
Logger.getLogger("Minecraft").info(name + " " + version + " disabled.");
|
||||
@ -81,7 +83,7 @@ public class War extends JavaPlugin {
|
||||
this.defaultLifepool = 7;
|
||||
this.defaultFriendlyFire = false;
|
||||
this.defaultAutoAssignOnly = false;
|
||||
WarMapper.load(this);
|
||||
WarMapper.load(this, this.getServer().getWorlds()[0]);
|
||||
|
||||
getLogger().info(name + " " + version + " enabled.");
|
||||
}
|
||||
@ -207,5 +209,14 @@ public class War extends JavaPlugin {
|
||||
this.defaultAutoAssignOnly = autoAssign;
|
||||
}
|
||||
|
||||
public WarHub getWarHub() {
|
||||
// TODO Auto-generated method stub
|
||||
return warHub;
|
||||
}
|
||||
|
||||
public void setWarHub(WarHub warHub) {
|
||||
this.warHub = warHub;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
@ -51,6 +51,15 @@ public class WarBlockListener extends BlockListener {
|
||||
player.sendMessage(war.str("Can't build here."));
|
||||
event.setCancelled(true);
|
||||
}
|
||||
// protect warzone lobbies
|
||||
if(block != null) {
|
||||
for(Warzone wz: war.getWarzones()) {
|
||||
if(wz.getLobby().getVolume().contains(block)) {
|
||||
player.sendMessage(war.str("Can't build here."));
|
||||
event.setCancelled(true);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -88,6 +97,16 @@ public class WarBlockListener extends BlockListener {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// protect warzone lobbies
|
||||
if(block != null) {
|
||||
for(Warzone zone: war.getWarzones()) {
|
||||
if(zone.getLobby().getVolume().contains(block)) {
|
||||
player.sendMessage(war.str("Can't destroy this."));
|
||||
event.setCancelled(true);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -3,6 +3,7 @@ import java.util.List;
|
||||
import java.util.Random;
|
||||
import java.util.logging.Level;
|
||||
|
||||
import org.bukkit.BlockFace;
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.Player;
|
||||
@ -14,7 +15,9 @@ import org.bukkit.event.player.PlayerMoveEvent;
|
||||
import com.tommytony.war.Monument;
|
||||
import com.tommytony.war.Team;
|
||||
import com.tommytony.war.TeamMaterials;
|
||||
import com.tommytony.war.WarHub;
|
||||
import com.tommytony.war.Warzone;
|
||||
import com.tommytony.war.ZoneLobby;
|
||||
import com.tommytony.war.mappers.WarMapper;
|
||||
import com.tommytony.war.mappers.WarzoneMapper;
|
||||
|
||||
@ -175,8 +178,10 @@ public class WarPlayerListener extends PlayerListener {
|
||||
} else {
|
||||
Team playerTeam = war.getPlayerTeam(player.getName());
|
||||
playerTeam.removePlayer(player.getName());
|
||||
player.sendMessage(war.str("Left the team. You can now exit the warzone."));
|
||||
|
||||
Warzone zone = war.warzone(player.getLocation());
|
||||
player.teleportTo(zone.getTeleport());
|
||||
player.sendMessage(war.str("Left the zone."));
|
||||
zone.restorePlayerInventory(player);
|
||||
player.sendMessage(war.str("Your inventory has (hopefully) been restored."));
|
||||
}
|
||||
@ -223,6 +228,21 @@ public class WarPlayerListener extends PlayerListener {
|
||||
|
||||
// Warzone maker commands: /setzone, /savezone, /setteam, /setmonument, /resetzone
|
||||
|
||||
// /warhub
|
||||
else if(command.equals("warhub")) {
|
||||
WarHub hub = war.getWarHub();
|
||||
if(hub != null) {
|
||||
// reset existing hub
|
||||
hub.getVolume().resetBlocks();
|
||||
hub.setLocation(player.getLocation());
|
||||
hub.initialize();
|
||||
} else {
|
||||
hub = new WarHub(war, player.getLocation());
|
||||
hub.initialize();
|
||||
}
|
||||
WarMapper.save(war);
|
||||
}
|
||||
|
||||
// /setzone
|
||||
else if(command.equals("setzone") || command.equals("setwarzone")) {
|
||||
if(arguments.length < 2 || arguments.length > 2
|
||||
@ -292,7 +312,33 @@ public class WarPlayerListener extends PlayerListener {
|
||||
|
||||
}
|
||||
event.setCancelled(true);
|
||||
}
|
||||
}
|
||||
|
||||
else if(command.equals("setzonelobby")) {
|
||||
if(!war.inAnyWarzone(player.getLocation()) || arguments.length < 2 || arguments.length > 2
|
||||
|| (arguments.length == 2 && (!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")))) {
|
||||
player.sendMessage(war.str("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 {
|
||||
Warzone warzone = war.warzone(player.getLocation());
|
||||
BlockFace wall = null;
|
||||
if(arguments[0].equals("north") || arguments[0].equals("n")) {
|
||||
|
||||
}
|
||||
ZoneLobby lobby = warzone.getLobby();
|
||||
if(lobby != null) {
|
||||
// reset existing lobby
|
||||
lobby.getVolume().resetBlocks();
|
||||
lobby.setWall(wall);
|
||||
lobby.initialize();
|
||||
}
|
||||
WarzoneMapper.save(war, warzone, false);
|
||||
}
|
||||
}
|
||||
|
||||
// /savewarzone
|
||||
else if(command.equals("savezone") || command.equals("savewarzone")) {
|
||||
@ -307,8 +353,14 @@ public class WarPlayerListener extends PlayerListener {
|
||||
} else {
|
||||
Warzone warzone = war.warzone(player.getLocation());
|
||||
int savedBlocks = warzone.saveState();
|
||||
warzone.setTeleport(player.getLocation());
|
||||
player.sendMessage(war.str("Warzone " + warzone.getName() + " initial state and teleport location changed. Saved " + savedBlocks + " blocks."));
|
||||
if(warzone.getLobby() == null) {
|
||||
// Set default lobby on south side
|
||||
ZoneLobby lobby = new ZoneLobby(war, warzone, BlockFace.South);
|
||||
warzone.setLobby(lobby);
|
||||
lobby.initialize();
|
||||
player.sendMessage(war.str("Default lobby created on south side of zone."));
|
||||
}
|
||||
player.sendMessage(war.str("Warzone " + warzone.getName() + " initial state changed. Saved " + savedBlocks + " blocks."));
|
||||
WarzoneMapper.save(war, warzone, true);
|
||||
}
|
||||
event.setCancelled(true);
|
||||
@ -498,7 +550,6 @@ public class WarPlayerListener extends PlayerListener {
|
||||
if(playerWarzone != null) {
|
||||
Team playerTeam = war.getPlayerTeam(player.getName());
|
||||
|
||||
|
||||
// Monuments
|
||||
if(to != null && playerTeam != null
|
||||
&& playerWarzone.nearAnyOwnedMonument(to, playerTeam)
|
||||
@ -507,41 +558,68 @@ public class WarPlayerListener extends PlayerListener {
|
||||
player.setHealth(20);
|
||||
player.sendMessage(war.str("Your dance pleases the monument's voodoo. You gain full health!"));
|
||||
}
|
||||
|
||||
// if(player != null && from != null && to != null &&
|
||||
// playerTeam != null && !playerWarzone.getVolume().contains(to)) {
|
||||
// player.sendMessage(war.str("Can't go outside the warzone boundary! Use /leave to exit the battle."));
|
||||
// if(playerWarzone.getVolume().contains(from)){
|
||||
// player.teleportTo(from);
|
||||
// } else {
|
||||
// // somehow the player made it out of the zone
|
||||
// player.teleportTo(playerTeam.getTeamSpawn());
|
||||
// player.sendMessage(war.str("Brought you back to your team spawn. Use /leave to exit the battle."));
|
||||
// }
|
||||
// }
|
||||
//
|
||||
// if(player != null && from != null && to != null &&
|
||||
// playerTeam == null
|
||||
// && war.inAnyWarzone(from)
|
||||
// && !war.inAnyWarzone(to)) {
|
||||
// // leaving
|
||||
// Warzone zone = war.warzone(from);
|
||||
// player.sendMessage(war.str("Leaving warzone " + zone.getName() + "."));
|
||||
// }
|
||||
//
|
||||
// if(player != null && from != null && to != null &&
|
||||
// playerTeam == null
|
||||
// && !war.inAnyWarzone(from)
|
||||
// && war.inAnyWarzone(to)) {
|
||||
// // entering
|
||||
// Warzone zone = war.warzone(to);
|
||||
// player.sendMessage(war.str("Entering warzone " + zone.getName() + ". Tip: use /teams."));
|
||||
// }
|
||||
|
||||
|
||||
}
|
||||
|
||||
if(to != null) {
|
||||
// Warzone lobby gates
|
||||
for(Warzone zone : war.getWarzones()){
|
||||
if(zone.getLobby().isAutoAssignGate(to)) {
|
||||
dropFromOldTeamIfAny(player);
|
||||
zone.autoAssign(player);
|
||||
} else if (zone.getLobby().isInTeamGate(TeamMaterials.TEAMDIAMOND, to)){
|
||||
dropFromOldTeamIfAny(player);
|
||||
Team diamondTeam = zone.getTeamByMaterial(TeamMaterials.TEAMDIAMOND);
|
||||
diamondTeam.addPlayer(player);
|
||||
zone.keepPlayerInventory(player);
|
||||
player.sendMessage(war.str("Your inventory is is storage until you /leave."));
|
||||
zone.respawnPlayer(diamondTeam, player);
|
||||
for(Team team : zone.getTeams()){
|
||||
team.teamcast(war.str("" + player.getName() + " joined team diamond."));
|
||||
}
|
||||
} else if (zone.getLobby().isInTeamGate(TeamMaterials.TEAMIRON, to)){
|
||||
dropFromOldTeamIfAny(player);
|
||||
Team ironTeam = zone.getTeamByMaterial(TeamMaterials.TEAMIRON);
|
||||
ironTeam.addPlayer(player);
|
||||
zone.keepPlayerInventory(player);
|
||||
player.sendMessage(war.str("Your inventory is is storage until you /leave."));
|
||||
zone.respawnPlayer(ironTeam, player);
|
||||
for(Team team : zone.getTeams()){
|
||||
team.teamcast(war.str("" + player.getName() + " joined team iron."));
|
||||
}
|
||||
} else if (zone.getLobby().isInTeamGate(TeamMaterials.TEAMGOLD, to)){
|
||||
dropFromOldTeamIfAny(player);
|
||||
Team goldTeam = zone.getTeamByMaterial(TeamMaterials.TEAMGOLD);
|
||||
goldTeam.addPlayer(player);
|
||||
zone.keepPlayerInventory(player);
|
||||
player.sendMessage(war.str("Your inventory is is storage until you /leave."));
|
||||
zone.respawnPlayer(goldTeam, player);
|
||||
for(Team team : zone.getTeams()){
|
||||
team.teamcast(war.str("" + player.getName() + " joined team gold."));
|
||||
}
|
||||
} else if (zone.getLobby().isInWarHubLinkGate(to)){
|
||||
dropFromOldTeamIfAny(player);
|
||||
player.teleportTo(war.getWarHub().getLocation());
|
||||
}
|
||||
}
|
||||
// Warhub zone gates
|
||||
WarHub hub = war.getWarHub();
|
||||
Warzone zone = hub.getDestinationWarzoneForLocation(player.getLocation());
|
||||
if(zone != null) {
|
||||
player.teleportTo(zone.getTeleport());
|
||||
player.sendMessage(war.str("Welcome to warzone " + zone.getName() + "."));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void dropFromOldTeamIfAny(Player player) {
|
||||
// drop from old team if any
|
||||
Team previousTeam = war.getPlayerTeam(player.getName());
|
||||
if(previousTeam != null) {
|
||||
if(!previousTeam.removePlayer(player.getName())){
|
||||
war.getLogger().log(Level.WARNING, "Could not remove player " + player.getName() + " from team " + previousTeam.getName());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private String getAllTeamsMsg(Player player){
|
||||
String teamsMessage = "Teams: ";
|
||||
|
@ -1,23 +1,98 @@
|
||||
package com.tommytony.war;
|
||||
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.World;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import com.tommytony.war.volumes.Volume;
|
||||
import org.bukkit.Block;
|
||||
import org.bukkit.BlockFace;
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.Material;
|
||||
|
||||
import bukkit.tommytony.war.War;
|
||||
|
||||
import com.tommytony.war.volumes.Volume;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author tommytony
|
||||
*
|
||||
*/
|
||||
public class WarHub {
|
||||
private final War war;
|
||||
private final World world;
|
||||
private final Location location;
|
||||
private Location location;
|
||||
private Volume volume;
|
||||
private List<Block> zoneGateBlocks = new ArrayList<Block>();
|
||||
|
||||
public WarHub(War war, World world, Location location) {
|
||||
public WarHub(War war, Location location) {
|
||||
this.war = war;
|
||||
this.world = world;
|
||||
this.location = location;
|
||||
this.volume = new Volume("warHub", war, world);
|
||||
this.volume = new Volume("warHub", war, location.getWorld());
|
||||
}
|
||||
|
||||
public Volume getVolume() {
|
||||
return volume;
|
||||
}
|
||||
|
||||
public void setLocation(Location loc) {
|
||||
this.location = loc;
|
||||
}
|
||||
|
||||
public Location getLocation() {
|
||||
return this.location;
|
||||
}
|
||||
|
||||
public Warzone getDestinationWarzoneForLocation(Location playerLocation) {
|
||||
Warzone zone = null;
|
||||
for(Block gate : zoneGateBlocks) {
|
||||
if(gate.getX() == playerLocation.getBlockX()
|
||||
&& gate.getY() == playerLocation.getBlockY()
|
||||
&& gate.getZ() == playerLocation.getBlockZ()) {
|
||||
int zoneIndex = zoneGateBlocks.indexOf(gate);
|
||||
zone = war.getWarzones().get(zoneIndex);
|
||||
}
|
||||
}
|
||||
return zone;
|
||||
}
|
||||
|
||||
public void initialize() {
|
||||
// for now, draw the wall of gates to the west
|
||||
zoneGateBlocks.clear();
|
||||
int noOfWarzones = war.getWarzones().size();
|
||||
if(noOfWarzones > 0) {
|
||||
int hubWidth = noOfWarzones * 4 + 1;
|
||||
int halfHubWidth = hubWidth / 2;
|
||||
int hubDepth = 5;
|
||||
int hubHeigth = 4;
|
||||
|
||||
Block locationBlock = location.getWorld().getBlockAt(location.getBlockX(), location.getBlockY(), location.getBlockZ());
|
||||
volume.setCornerOne(locationBlock.getFace(BlockFace.South, halfHubWidth).getFace(BlockFace.Down));
|
||||
volume.setCornerTwo(locationBlock.getFace(BlockFace.North, halfHubWidth).getFace(BlockFace.West, hubDepth).getFace(BlockFace.North, hubHeigth));
|
||||
volume.saveBlocks();
|
||||
|
||||
// draw gates
|
||||
Block currentGateBlock = locationBlock.getFace(BlockFace.South, halfHubWidth - 2).getFace(BlockFace.West, hubDepth);
|
||||
for(Warzone zone : war.getWarzones()) { // gonna use the index to find it again
|
||||
zoneGateBlocks.add(currentGateBlock);
|
||||
currentGateBlock.setType(Material.PORTAL);
|
||||
currentGateBlock.getFace(BlockFace.Up).setType(Material.PORTAL);
|
||||
currentGateBlock.getFace(BlockFace.South).setType(Material.OBSIDIAN);
|
||||
currentGateBlock.getFace(BlockFace.North).getFace(BlockFace.Up).setType(Material.OBSIDIAN);
|
||||
currentGateBlock.getFace(BlockFace.South).getFace(BlockFace.Up).getFace(BlockFace.Up).setType(Material.OBSIDIAN);
|
||||
currentGateBlock.getFace(BlockFace.North).setType(Material.OBSIDIAN);
|
||||
currentGateBlock.getFace(BlockFace.South).getFace(BlockFace.Up).setType(Material.OBSIDIAN);
|
||||
currentGateBlock.getFace(BlockFace.North).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);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void resetSigns() {
|
||||
// TODO Signs
|
||||
}
|
||||
|
||||
public void setVolume(Volume vol) {
|
||||
this.volume = vol;
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -42,6 +42,7 @@ public class Warzone {
|
||||
private final int minSafeDistanceFromWall = 5;
|
||||
private List<ZoneWallGuard> zoneWallGuards = new ArrayList<ZoneWallGuard>();
|
||||
private War war;
|
||||
private ZoneLobby lobby;
|
||||
private boolean autoAssignOnly;
|
||||
|
||||
|
||||
@ -617,6 +618,35 @@ public class Warzone {
|
||||
return autoAssignOnly;
|
||||
}
|
||||
|
||||
public void setLobby(ZoneLobby lobby) {
|
||||
this.lobby = lobby;
|
||||
}
|
||||
|
||||
public ZoneLobby getLobby() {
|
||||
return lobby;
|
||||
}
|
||||
|
||||
public void autoAssign(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);
|
||||
if(!hasPlayerInventory(player.getName())) {
|
||||
keepPlayerInventory(player);
|
||||
}
|
||||
player.sendMessage(war.str("Your inventory is is storage until you /leave."));
|
||||
respawnPlayer(lowestNoOfPlayers, player);
|
||||
for(Team team : teams){
|
||||
team.teamcast(war.str("" + player.getName() + " joined team " + team.getName() + "."));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
@ -11,6 +11,11 @@ import com.tommytony.war.volumes.Volume;
|
||||
|
||||
import bukkit.tommytony.war.War;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author tommytony
|
||||
*
|
||||
*/
|
||||
public class ZoneLobby {
|
||||
private final War war;
|
||||
private final Warzone warzone;
|
||||
@ -24,6 +29,8 @@ public class ZoneLobby {
|
||||
Block goldGate = null;
|
||||
Block autoAssignGate = null;
|
||||
|
||||
Block zoneTeleportBlock = null;
|
||||
|
||||
public ZoneLobby(War war, Warzone warzone, BlockFace wall) {
|
||||
this.war = war;
|
||||
this.warzone = warzone;
|
||||
@ -32,7 +39,7 @@ public class ZoneLobby {
|
||||
}
|
||||
|
||||
public void initialize() {
|
||||
// first, find center of the wall and position of all elements
|
||||
// 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());
|
||||
@ -92,7 +99,7 @@ public class ZoneLobby {
|
||||
}
|
||||
|
||||
if(lobbyMiddleWallBlock != null && corner1 != null && corner2 != null) {
|
||||
// save the blocks, wide enough for three team gates, 3 high and 10 deep, extruding out from the zone wall.
|
||||
// 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();
|
||||
@ -100,18 +107,25 @@ public class ZoneLobby {
|
||||
|
||||
// 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.AIR);
|
||||
this.volume.setFaceMaterial(BlockFace.Down, Material.AIR); // beautiful
|
||||
|
||||
// add war hub link gate
|
||||
|
||||
if(war.getWarHub() != null) {
|
||||
placeGate(warHubLinkGate, Material.OBSIDIAN);
|
||||
}
|
||||
|
||||
// add team gates or single auto assign gate
|
||||
placeGateOnNorthOrSouthWall(lobbyMiddleWallBlock, TeamMaterials.TEAMDIAMOND);
|
||||
placeAutoAssignGate();
|
||||
placeGate(diamondGate, TeamMaterials.TEAMDIAMOND);
|
||||
placeGate(ironGate, TeamMaterials.TEAMIRON);
|
||||
placeGate(goldGate, TeamMaterials.TEAMGOLD);
|
||||
|
||||
// set zone tp
|
||||
// set zone tp
|
||||
zoneTeleportBlock = lobbyMiddleWallBlock.getFace(wall, 6);
|
||||
warzone.setTeleport(new Location(warzone.getWorld(), zoneTeleportBlock.getX(), zoneTeleportBlock.getY(), zoneTeleportBlock.getZ()));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
private void setGatePositions(Block lobbyMiddleWallBlock) {
|
||||
BlockFace leftSide = null; // look at the zone
|
||||
BlockFace rightSide = null;
|
||||
@ -161,30 +175,93 @@ public class ZoneLobby {
|
||||
warHubLinkGate = lobbyMiddleWallBlock.getFace(wall, 8);
|
||||
}
|
||||
|
||||
private void placeGateOnNorthOrSouthWall(Block block,
|
||||
private void placeGate(Block block,
|
||||
Material teamMaterial) {
|
||||
block.setType(Material.PORTAL);
|
||||
block.getFace(BlockFace.Up).setType(Material.PORTAL);
|
||||
block.getFace(BlockFace.East).setType(teamMaterial);
|
||||
block.getFace(BlockFace.East).getFace(BlockFace.Up).setType(teamMaterial);
|
||||
block.getFace(BlockFace.East).getFace(BlockFace.Up).getFace(BlockFace.Up).setType(teamMaterial);
|
||||
block.getFace(BlockFace.West).setType(teamMaterial);
|
||||
block.getFace(BlockFace.West).getFace(BlockFace.Up).setType(teamMaterial);
|
||||
block.getFace(BlockFace.West).getFace(BlockFace.Up).getFace(BlockFace.Up).setType(teamMaterial);
|
||||
block.getFace(BlockFace.Up).getFace(BlockFace.Up).setType(teamMaterial);
|
||||
if(block != null) {
|
||||
BlockFace leftSide = null; // look at the zone
|
||||
BlockFace rightSide = null;
|
||||
if(wall == BlockFace.North) {
|
||||
leftSide = BlockFace.East;
|
||||
rightSide = BlockFace.West;
|
||||
} else if(wall == BlockFace.East) {
|
||||
leftSide = BlockFace.South;
|
||||
rightSide = BlockFace.North;
|
||||
} else if(wall == BlockFace.South) {
|
||||
leftSide = BlockFace.West;
|
||||
rightSide = BlockFace.East;
|
||||
} else if(wall == BlockFace.West) {
|
||||
leftSide = BlockFace.North;
|
||||
rightSide = BlockFace.South;
|
||||
}
|
||||
block.setType(Material.PORTAL);
|
||||
block.getFace(BlockFace.Up).setType(Material.PORTAL);
|
||||
block.getFace(leftSide).setType(teamMaterial);
|
||||
block.getFace(rightSide).getFace(BlockFace.Up).setType(teamMaterial);
|
||||
block.getFace(leftSide).getFace(BlockFace.Up).getFace(BlockFace.Up).setType(teamMaterial);
|
||||
block.getFace(rightSide).setType(teamMaterial);
|
||||
block.getFace(leftSide).getFace(BlockFace.Up).setType(teamMaterial);
|
||||
block.getFace(rightSide).getFace(BlockFace.Up).getFace(BlockFace.Up).setType(teamMaterial);
|
||||
block.getFace(BlockFace.Up).getFace(BlockFace.Up).setType(teamMaterial);
|
||||
}
|
||||
}
|
||||
|
||||
private void placeGateOnEastOrWestWall(Block block,
|
||||
Material teamMaterial) {
|
||||
block.setType(Material.PORTAL);
|
||||
block.getFace(BlockFace.Up).setType(Material.PORTAL);
|
||||
block.getFace(BlockFace.North).setType(teamMaterial);
|
||||
block.getFace(BlockFace.North).getFace(BlockFace.Up).setType(teamMaterial);
|
||||
block.getFace(BlockFace.North).getFace(BlockFace.Up).getFace(BlockFace.Up).setType(teamMaterial);
|
||||
block.getFace(BlockFace.South).setType(teamMaterial);
|
||||
block.getFace(BlockFace.South).getFace(BlockFace.Up).setType(teamMaterial);
|
||||
block.getFace(BlockFace.South).getFace(BlockFace.Up).getFace(BlockFace.Up).setType(teamMaterial);
|
||||
block.getFace(BlockFace.Up).getFace(BlockFace.Up).setType(teamMaterial);
|
||||
private void placeAutoAssignGate() {
|
||||
if(autoAssignGate != null) {
|
||||
BlockFace leftSide = null; // look at the zone
|
||||
BlockFace rightSide = null;
|
||||
if(wall == BlockFace.North) {
|
||||
leftSide = BlockFace.East;
|
||||
rightSide = BlockFace.West;
|
||||
} else if(wall == BlockFace.East) {
|
||||
leftSide = BlockFace.South;
|
||||
rightSide = BlockFace.North;
|
||||
} else if(wall == BlockFace.South) {
|
||||
leftSide = BlockFace.West;
|
||||
rightSide = BlockFace.East;
|
||||
} else if(wall == BlockFace.West) {
|
||||
leftSide = BlockFace.North;
|
||||
rightSide = BlockFace.South;
|
||||
}
|
||||
|
||||
Team diamondTeam = warzone.getTeamByMaterial(TeamMaterials.TEAMDIAMOND);
|
||||
Team ironTeam = warzone.getTeamByMaterial(TeamMaterials.TEAMIRON);
|
||||
Team goldTeam = warzone.getTeamByMaterial(TeamMaterials.TEAMGOLD);
|
||||
autoAssignGate.setType(Material.PORTAL);
|
||||
autoAssignGate.getFace(BlockFace.Up).setType(Material.PORTAL);
|
||||
if(diamondTeam != null && ironTeam != null && goldTeam != null) {
|
||||
autoAssignGate.getFace(leftSide).setType(TeamMaterials.TEAMDIAMOND);
|
||||
autoAssignGate.getFace(leftSide).getFace(BlockFace.Up).setType(TeamMaterials.TEAMIRON);
|
||||
autoAssignGate.getFace(leftSide).getFace(BlockFace.Up).getFace(BlockFace.Up).setType(TeamMaterials.TEAMGOLD);
|
||||
autoAssignGate.getFace(rightSide).getFace(BlockFace.Up).setType(TeamMaterials.TEAMDIAMOND);
|
||||
autoAssignGate.getFace(rightSide).getFace(BlockFace.Up).getFace(BlockFace.Up).setType(TeamMaterials.TEAMIRON);
|
||||
autoAssignGate.getFace(rightSide).getFace(BlockFace.Up).setType(TeamMaterials.TEAMGOLD);
|
||||
autoAssignGate.getFace(rightSide).setType(TeamMaterials.TEAMDIAMOND);
|
||||
} else if (diamondTeam != null && ironTeam != null) {
|
||||
autoAssignGate.getFace(leftSide).setType(TeamMaterials.TEAMDIAMOND);
|
||||
autoAssignGate.getFace(leftSide).getFace(BlockFace.Up).setType(TeamMaterials.TEAMIRON);
|
||||
autoAssignGate.getFace(leftSide).getFace(BlockFace.Up).getFace(BlockFace.Up).setType(TeamMaterials.TEAMDIAMOND);
|
||||
autoAssignGate.getFace(rightSide).getFace(BlockFace.Up).setType(TeamMaterials.TEAMIRON);
|
||||
autoAssignGate.getFace(rightSide).getFace(BlockFace.Up).getFace(BlockFace.Up).setType(TeamMaterials.TEAMDIAMOND);
|
||||
autoAssignGate.getFace(rightSide).getFace(BlockFace.Up).setType(TeamMaterials.TEAMIRON);
|
||||
autoAssignGate.getFace(rightSide).setType(TeamMaterials.TEAMDIAMOND);
|
||||
} else if (ironTeam != null && goldTeam != null) {
|
||||
autoAssignGate.getFace(leftSide).setType(TeamMaterials.TEAMIRON);
|
||||
autoAssignGate.getFace(leftSide).getFace(BlockFace.Up).setType(TeamMaterials.TEAMGOLD);
|
||||
autoAssignGate.getFace(leftSide).getFace(BlockFace.Up).getFace(BlockFace.Up).setType(TeamMaterials.TEAMIRON);
|
||||
autoAssignGate.getFace(rightSide).getFace(BlockFace.Up).setType(TeamMaterials.TEAMGOLD);
|
||||
autoAssignGate.getFace(rightSide).getFace(BlockFace.Up).getFace(BlockFace.Up).setType(TeamMaterials.TEAMIRON);
|
||||
autoAssignGate.getFace(rightSide).getFace(BlockFace.Up).setType(TeamMaterials.TEAMGOLD);
|
||||
autoAssignGate.getFace(rightSide).setType(TeamMaterials.TEAMIRON);
|
||||
} else if (diamondTeam != null && goldTeam != null) {
|
||||
autoAssignGate.getFace(leftSide).setType(TeamMaterials.TEAMDIAMOND);
|
||||
autoAssignGate.getFace(leftSide).getFace(BlockFace.Up).setType(TeamMaterials.TEAMGOLD);
|
||||
autoAssignGate.getFace(leftSide).getFace(BlockFace.Up).getFace(BlockFace.Up).setType(TeamMaterials.TEAMDIAMOND);
|
||||
autoAssignGate.getFace(rightSide).getFace(BlockFace.Up).setType(TeamMaterials.TEAMGOLD);
|
||||
autoAssignGate.getFace(rightSide).getFace(BlockFace.Up).getFace(BlockFace.Up).setType(TeamMaterials.TEAMDIAMOND);
|
||||
autoAssignGate.getFace(rightSide).getFace(BlockFace.Up).setType(TeamMaterials.TEAMGOLD);
|
||||
autoAssignGate.getFace(rightSide).setType(TeamMaterials.TEAMDIAMOND);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public boolean isInTeamGate(Material team, Location location) {
|
||||
@ -218,7 +295,7 @@ public class ZoneLobby {
|
||||
}
|
||||
|
||||
public void resetSigns() {
|
||||
// TODO later
|
||||
// TODO Signs
|
||||
}
|
||||
|
||||
public Volume getVolume() {
|
||||
@ -237,4 +314,14 @@ public class ZoneLobby {
|
||||
public void setWall(BlockFace wall) {
|
||||
this.wall = wall;
|
||||
}
|
||||
|
||||
public boolean isInWarHubLinkGate(Location location) {
|
||||
if(warHubLinkGate != null
|
||||
&& location.getBlockX() == warHubLinkGate.getX()
|
||||
&& location.getBlockY() == warHubLinkGate.getY()
|
||||
&& location.getBlockZ() == warHubLinkGate.getZ()) {
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
@ -35,19 +35,9 @@ public class ZoneWallGuard {
|
||||
}
|
||||
|
||||
private void activate() {
|
||||
// save current blocks
|
||||
List<Block> nearestWallBlocks = warzone.getNearestWallBlocks(playerLocation);
|
||||
// if(volume == null) {
|
||||
// volume = new CenteredVolume("zoneGuard-" + warzone.getName() + "-" + player.getName(), nearestWallBlock, radius, war, warzone);
|
||||
// int saved = volume.saveBlocks();
|
||||
// war.getLogger().info("Warzone wall guard created: " + saved + " blocks saved for " + player.getName());
|
||||
// } else {
|
||||
// volume.changeCenter(nearestWallBlock, radius);
|
||||
// int saved = volume.saveBlocks();
|
||||
// war.getLogger().info("Warzone wall guard updated: " + saved + " blocks saved for " + player.getName());
|
||||
// }
|
||||
|
||||
// add wall guard blocks
|
||||
|
||||
for(Block block : nearestWallBlocks) {
|
||||
block.setType(Material.GLASS);
|
||||
block.getFace(BlockFace.Up).setType(Material.GLASS);
|
||||
@ -82,51 +72,6 @@ public class ZoneWallGuard {
|
||||
toGlass(block.getFace(BlockFace.South).getFace(BlockFace.Down), BlockFace.West);
|
||||
}
|
||||
}
|
||||
// nearestWallBlock.setType(Material.Glass);
|
||||
// nearestWallBlock.getFace(BlockFace.Up).setType(Material.Glass);
|
||||
// nearestWallBlock.getFace(BlockFace.Down).setType(Material.Glass);
|
||||
// if(warzone.getVolume().isNorthWallBlock(nearestWallBlock.getFace(BlockFace.East)) &&
|
||||
// warzone.getVolume().isNorthWallBlock(nearestWallBlock.getFace(BlockFace.West))) {
|
||||
// // north wall guard
|
||||
// this.wall = BlockFace.North;
|
||||
// toGlass(nearestWallBlock.getFace(BlockFace.East), BlockFace.North);
|
||||
// toGlass(nearestWallBlock.getFace(BlockFace.East).getFace(BlockFace.Up), BlockFace.North);
|
||||
// toGlass(nearestWallBlock.getFace(BlockFace.East).getFace(BlockFace.Down), BlockFace.North);
|
||||
// toGlass(nearestWallBlock.getFace(BlockFace.West), BlockFace.North);
|
||||
// toGlass(nearestWallBlock.getFace(BlockFace.West).getFace(BlockFace.Up), BlockFace.North);
|
||||
// toGlass(nearestWallBlock.getFace(BlockFace.West).getFace(BlockFace.Down), BlockFace.North);
|
||||
// } else if (warzone.getVolume().isSouthWallBlock(nearestWallBlock.getFace(BlockFace.East)) &&
|
||||
// warzone.getVolume().isSouthWallBlock(nearestWallBlock.getFace(BlockFace.West))) {
|
||||
// // south wall guard
|
||||
// this.wall = BlockFace.South;
|
||||
// toGlass(nearestWallBlock.getFace(BlockFace.East), BlockFace.South);
|
||||
// toGlass(nearestWallBlock.getFace(BlockFace.East).getFace(BlockFace.Up), BlockFace.South);
|
||||
// toGlass(nearestWallBlock.getFace(BlockFace.East).getFace(BlockFace.Down), BlockFace.South);
|
||||
// toGlass(nearestWallBlock.getFace(BlockFace.West), BlockFace.South);
|
||||
// toGlass(nearestWallBlock.getFace(BlockFace.West).getFace(BlockFace.Up), BlockFace.South);
|
||||
// toGlass(nearestWallBlock.getFace(BlockFace.West).getFace(BlockFace.Down), BlockFace.South);
|
||||
// // ..
|
||||
// } else if (warzone.getVolume().isEastWallBlock(nearestWallBlock.getFace(BlockFace.North)) &&
|
||||
// warzone.getVolume().isEastWallBlock(nearestWallBlock.getFace(BlockFace.South))) {
|
||||
// //east wall guard
|
||||
// this.wall = BlockFace.East;
|
||||
// toGlass(nearestWallBlock.getFace(BlockFace.North), BlockFace.East);
|
||||
// toGlass(nearestWallBlock.getFace(BlockFace.North).getFace(BlockFace.Up), BlockFace.East);
|
||||
// toGlass(nearestWallBlock.getFace(BlockFace.North).getFace(BlockFace.Down), BlockFace.East);
|
||||
// toGlass(nearestWallBlock.getFace(BlockFace.South), BlockFace.West);
|
||||
// toGlass(nearestWallBlock.getFace(BlockFace.South).getFace(BlockFace.Up), BlockFace.West);
|
||||
// toGlass(nearestWallBlock.getFace(BlockFace.South).getFace(BlockFace.Down), BlockFace.West);
|
||||
// } else if (warzone.getVolume().isWestWallBlock(nearestWallBlock.getFace(BlockFace.North)) &&
|
||||
// warzone.getVolume().isWestWallBlock(nearestWallBlock.getFace(BlockFace.South))) {
|
||||
// //west wall guard
|
||||
// this.wall = BlockFace.West;
|
||||
// toGlass(nearestWallBlock.getFace(BlockFace.North), BlockFace.West);
|
||||
// toGlass(nearestWallBlock.getFace(BlockFace.North).getFace(BlockFace.Up), BlockFace.West);
|
||||
// toGlass(nearestWallBlock.getFace(BlockFace.North).getFace(BlockFace.Down), BlockFace.West);
|
||||
// toGlass(nearestWallBlock.getFace(BlockFace.South), BlockFace.West);
|
||||
// toGlass(nearestWallBlock.getFace(BlockFace.South).getFace(BlockFace.Up), BlockFace.West);
|
||||
// toGlass(nearestWallBlock.getFace(BlockFace.South).getFace(BlockFace.Down), BlockFace.West);
|
||||
// }
|
||||
}
|
||||
|
||||
private void toGlass(Block block, BlockFace wall) {
|
||||
|
@ -17,6 +17,11 @@ import com.tommytony.war.volumes.CenteredVolume;
|
||||
import com.tommytony.war.volumes.VerticalVolume;
|
||||
import com.tommytony.war.volumes.Volume;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author tommytony
|
||||
*
|
||||
*/
|
||||
public class VolumeMapper {
|
||||
|
||||
public static Volume loadVolume(String volumeName, String zoneName,
|
||||
@ -43,7 +48,8 @@ public class VolumeMapper {
|
||||
public static void load(Volume volume, String zoneName, War war, World world) {
|
||||
BufferedReader in = null;
|
||||
try {
|
||||
in = new BufferedReader(new FileReader(new File("War/warzone-" + zoneName + "/volume-" + volume.getName())));
|
||||
if(zoneName.equals("")) in = new BufferedReader(new FileReader(new File("War/volume-" + volume.getName() + ".dat")));
|
||||
else in = new BufferedReader(new FileReader(new File("War/warzone-" + zoneName + "/volume-" + volume.getName() + ".dat")));
|
||||
String firstLine = in.readLine();
|
||||
if(firstLine != null && !firstLine.equals("")) {
|
||||
int x1 = Integer.parseInt(in.readLine());
|
||||
@ -112,7 +118,8 @@ public class VolumeMapper {
|
||||
if(volume.isSaved() && volume.getBlockInfos() != null) {
|
||||
BufferedWriter out = null;
|
||||
try {
|
||||
out = new BufferedWriter(new FileWriter(new File("War/warzone-" + zoneName + "/volume-" + volume.getName() + ".dat")));
|
||||
if(zoneName.equals("")) out = new BufferedWriter(new FileWriter(new File("War/volume-" + volume.getName() + ".dat")));
|
||||
else out = new BufferedWriter(new FileWriter(new File("War/warzone-" + zoneName + "/volume-" + volume.getName() + ".dat")));
|
||||
if(volume instanceof CenteredVolume) {
|
||||
out.write("center"); out.newLine();
|
||||
out.write(volume.getCornerOne().getX()); out.newLine();
|
||||
|
@ -4,10 +4,14 @@ import java.io.IOException;
|
||||
import java.util.HashMap;
|
||||
|
||||
import org.bukkit.ItemStack;
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.World;
|
||||
|
||||
import bukkit.tommytony.war.War;
|
||||
|
||||
import com.tommytony.war.WarHub;
|
||||
import com.tommytony.war.Warzone;
|
||||
import com.tommytony.war.volumes.Volume;
|
||||
|
||||
/**
|
||||
*
|
||||
@ -16,7 +20,7 @@ import com.tommytony.war.Warzone;
|
||||
*/
|
||||
public class WarMapper {
|
||||
|
||||
public static void load(War war) {
|
||||
public static void load(War war, World world) {
|
||||
//war.getLogger().info("Loading war config...");
|
||||
(new File(war.getName())).mkdir();
|
||||
PropertiesFile warConfig = new PropertiesFile(war.getName() + "/war.txt");
|
||||
@ -89,6 +93,23 @@ public class WarMapper {
|
||||
// defaultAutoAssignOnly
|
||||
war.setDefaultAutoAssignOnly(warConfig.getBoolean("defaultAutoAssignOnly"));
|
||||
|
||||
// warhub
|
||||
String hubStr = warConfig.getString("warhub");
|
||||
if(hubStr != null && !hubStr.equals("")) {
|
||||
String[] nwStrSplit = hubStr.split(",");
|
||||
|
||||
int hubX = Integer.parseInt(nwStrSplit[0]);
|
||||
int hubY = Integer.parseInt(nwStrSplit[1]);
|
||||
int hubZ = Integer.parseInt(nwStrSplit[2]);
|
||||
Location hubLocation = new Location(world, hubX, hubY, hubZ);
|
||||
WarHub hub = new WarHub(war, hubLocation);
|
||||
war.setWarHub(hub);
|
||||
Volume vol = VolumeMapper.loadVolume("warhub", "", war, world);
|
||||
hub.setVolume(vol);
|
||||
hub.getVolume().resetBlocks();
|
||||
hub.initialize();
|
||||
}
|
||||
|
||||
warConfig.close();
|
||||
war.getLogger().info("Loaded war config.");
|
||||
}
|
||||
@ -132,6 +153,14 @@ public class WarMapper {
|
||||
// defaultAutoAssignOnly
|
||||
warConfig.setBoolean("defaultAutoAssignOnly", war.getDefaultAutoAssignOnly());
|
||||
|
||||
// warhub
|
||||
String hubStr = "";
|
||||
WarHub hub = war.getWarHub();
|
||||
if(hub != null) {
|
||||
hubStr = hub.getLocation().getBlockX() + "," + hub.getLocation().getBlockY() + "," + hub.getLocation().getBlockZ();
|
||||
}
|
||||
warConfig.setString("warhub", hubStr);
|
||||
|
||||
warConfig.save();
|
||||
warConfig.close();
|
||||
//war.getLogger().info("Saved war config.");
|
||||
|
@ -5,6 +5,11 @@ import org.bukkit.Material;
|
||||
import org.bukkit.block.BlockState;
|
||||
import org.bukkit.block.Sign;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author tommytony
|
||||
*
|
||||
*/
|
||||
public class BlockInfo {
|
||||
private int x;
|
||||
private int y;
|
||||
|
@ -6,6 +6,11 @@ import org.bukkit.World;
|
||||
|
||||
import bukkit.tommytony.war.War;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author tommytony
|
||||
*
|
||||
*/
|
||||
public class CenteredVolume extends Volume {
|
||||
|
||||
private Block center;
|
||||
|
@ -9,6 +9,11 @@ import org.bukkit.block.Sign;
|
||||
|
||||
import bukkit.tommytony.war.War;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author tommytony
|
||||
*
|
||||
*/
|
||||
public class VerticalVolume extends Volume{
|
||||
|
||||
public VerticalVolume(String name, War war, World world) {
|
||||
|
@ -1,18 +1,5 @@
|
||||
package com.tommytony.war.volumes;
|
||||
|
||||
import java.io.BufferedReader;
|
||||
import java.io.BufferedWriter;
|
||||
import java.io.File;
|
||||
import java.io.FileNotFoundException;
|
||||
import java.io.FileOutputStream;
|
||||
import java.io.FileReader;
|
||||
import java.io.FileWriter;
|
||||
import java.io.IOException;
|
||||
import java.io.Writer;
|
||||
import java.util.Scanner;
|
||||
|
||||
import javax.naming.BinaryRefAddr;
|
||||
|
||||
import org.bukkit.Block;
|
||||
import org.bukkit.BlockFace;
|
||||
import org.bukkit.Location;
|
||||
@ -23,11 +10,9 @@ import org.bukkit.block.Sign;
|
||||
|
||||
import bukkit.tommytony.war.War;
|
||||
|
||||
import com.tommytony.war.Warzone;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author tao
|
||||
* @author tommytony
|
||||
*
|
||||
*/
|
||||
public class Volume {
|
||||
|
Loading…
Reference in New Issue
Block a user