mirror of
https://github.com/taoneill/war.git
synced 2024-11-27 20:59:39 +01:00
Zone wall guard works. Yahoo
This commit is contained in:
parent
894bbaca43
commit
d598c921d5
@ -47,7 +47,7 @@ public class WarBlockListener extends BlockListener {
|
|||||||
event.setCancelled(true);
|
event.setCancelled(true);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if(zone.isImportantBlock(block)){
|
if(zone != null && zone.isImportantBlock(block)){
|
||||||
player.sendMessage(war.str("Can't build here."));
|
player.sendMessage(war.str("Can't build here."));
|
||||||
event.setCancelled(true);
|
event.setCancelled(true);
|
||||||
}
|
}
|
||||||
|
@ -51,14 +51,7 @@ public class Team {
|
|||||||
this.volume.setCornerTwo(warzone.getWorld().getBlockAt(x+2, y+5, z+2));
|
this.volume.setCornerTwo(warzone.getWorld().getBlockAt(x+2, y+5, z+2));
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setTeamSpawn(Location teamSpawn) {
|
private void initializeTeamSpawn(Location teamSpawn) {
|
||||||
|
|
||||||
this.teamSpawn = teamSpawn;
|
|
||||||
|
|
||||||
// this resets the block to old state
|
|
||||||
this.setVolume();
|
|
||||||
volume.saveBlocks();
|
|
||||||
|
|
||||||
// Set the spawn
|
// Set the spawn
|
||||||
int x = teamSpawn.getBlockX();
|
int x = teamSpawn.getBlockX();
|
||||||
int y = teamSpawn.getBlockY();
|
int y = teamSpawn.getBlockY();
|
||||||
@ -129,7 +122,17 @@ public class Team {
|
|||||||
warzone.getWorld().getBlockAt(x-2, y+3, z-2).setType(material);
|
warzone.getWorld().getBlockAt(x-2, y+3, z-2).setType(material);
|
||||||
|
|
||||||
resetSign();
|
resetSign();
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setTeamSpawn(Location teamSpawn) {
|
||||||
|
|
||||||
|
this.teamSpawn = teamSpawn;
|
||||||
|
|
||||||
|
// this resets the block to old state
|
||||||
|
this.setVolume();
|
||||||
|
volume.saveBlocks();
|
||||||
|
|
||||||
|
initializeTeamSpawn(teamSpawn);
|
||||||
}
|
}
|
||||||
|
|
||||||
public Location getTeamSpawn() {
|
public Location getTeamSpawn() {
|
||||||
|
@ -39,7 +39,7 @@ public class Warzone {
|
|||||||
private World world;
|
private World world;
|
||||||
private Material originalSouthEastBlock;
|
private Material originalSouthEastBlock;
|
||||||
private Material originalNorthWestBlock;
|
private Material originalNorthWestBlock;
|
||||||
private final int minSafeDistanceFromWall = 5;
|
private final int minSafeDistanceFromWall = 4;
|
||||||
private List<ZoneWallGuard> zoneWallGuards = new ArrayList<ZoneWallGuard>();
|
private List<ZoneWallGuard> zoneWallGuards = new ArrayList<ZoneWallGuard>();
|
||||||
private War war;
|
private War war;
|
||||||
|
|
||||||
@ -91,10 +91,10 @@ public class Warzone {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public void setNorthwest(Location northwest) {
|
public void setNorthwest(Location northwest) {
|
||||||
if(this.northwest != null) {
|
if(this.northwest != null && originalNorthWestBlock != null) {
|
||||||
// reset old corner
|
// reset old corner
|
||||||
int highest = this.world.getHighestBlockYAt(this.northwest.getBlockX(), this.southeast.getBlockZ()) - 1;
|
int highest = this.world.getHighestBlockYAt(this.northwest.getBlockX(), this.northwest.getBlockZ()) - 1;
|
||||||
Block oldTopNWBlock = this.world.getBlockAt(this.northwest.getBlockX(), highest, this.southeast.getBlockZ());
|
Block oldTopNWBlock = this.world.getBlockAt(this.northwest.getBlockX(), highest, this.northwest.getBlockZ());
|
||||||
oldTopNWBlock.setType(originalNorthWestBlock);
|
oldTopNWBlock.setType(originalNorthWestBlock);
|
||||||
}
|
}
|
||||||
this.northwest = northwest;
|
this.northwest = northwest;
|
||||||
@ -111,7 +111,7 @@ public class Warzone {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public void setSoutheast(Location southeast) {
|
public void setSoutheast(Location southeast) {
|
||||||
if(this.southeast != null) {
|
if(this.southeast != null && originalSouthEastBlock != null) {
|
||||||
// reset old corner
|
// reset old corner
|
||||||
int highest = this.world.getHighestBlockYAt(this.southeast.getBlockX(), this.southeast.getBlockZ()) - 1;
|
int highest = this.world.getHighestBlockYAt(this.southeast.getBlockX(), this.southeast.getBlockZ()) - 1;
|
||||||
Block oldTopSEBlock = this.world.getBlockAt(this.southeast.getBlockX(), highest, this.southeast.getBlockZ());
|
Block oldTopSEBlock = this.world.getBlockAt(this.southeast.getBlockX(), highest, this.southeast.getBlockZ());
|
||||||
@ -140,7 +140,22 @@ public class Warzone {
|
|||||||
|
|
||||||
public int saveState() {
|
public int saveState() {
|
||||||
if(ready()){
|
if(ready()){
|
||||||
return volume.saveBlocks();
|
// removed everything to keep save clean
|
||||||
|
volume.resetWallBlocks(BlockFace.East);
|
||||||
|
volume.resetWallBlocks(BlockFace.West);
|
||||||
|
volume.resetWallBlocks(BlockFace.North);
|
||||||
|
volume.resetWallBlocks(BlockFace.South);
|
||||||
|
|
||||||
|
for(Team team : teams) {
|
||||||
|
team.getVolume().resetBlocks();
|
||||||
|
}
|
||||||
|
|
||||||
|
for(Monument monument : monuments) {
|
||||||
|
monument.remove();
|
||||||
|
}
|
||||||
|
int saved = volume.saveBlocks();
|
||||||
|
initializeZone(); // bring back stuff
|
||||||
|
return saved;
|
||||||
}
|
}
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
@ -192,7 +207,7 @@ public class Warzone {
|
|||||||
respawnPlayer(team, player);
|
respawnPlayer(team, player);
|
||||||
}
|
}
|
||||||
team.setRemainingTickets(lifePool);
|
team.setRemainingTickets(lifePool);
|
||||||
team.getVolume().resetBlocks();
|
team.setTeamSpawn(team.getTeamSpawn());
|
||||||
team.resetSign();
|
team.resetSign();
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -449,22 +464,24 @@ public class Warzone {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public boolean isNearWall(Location latestPlayerLocation) {
|
public boolean isNearWall(Location latestPlayerLocation) {
|
||||||
if(Math.abs(southeast.getBlockZ() - latestPlayerLocation.getBlockZ()) < minSafeDistanceFromWall
|
if(volume.hasTwoCorners()) {
|
||||||
&& latestPlayerLocation.getBlockX() <= southeast.getBlockX()
|
if(Math.abs(southeast.getBlockZ() - latestPlayerLocation.getBlockZ()) < minSafeDistanceFromWall
|
||||||
&& latestPlayerLocation.getBlockX() >= northwest.getBlockX()) {
|
&& latestPlayerLocation.getBlockX() < southeast.getBlockX()
|
||||||
return true; // near east wall
|
&& latestPlayerLocation.getBlockX() > northwest.getBlockX()) {
|
||||||
} else if (Math.abs(southeast.getBlockX() - latestPlayerLocation.getBlockX()) < minSafeDistanceFromWall
|
return true; // near east wall
|
||||||
&& latestPlayerLocation.getBlockZ() <= northwest.getBlockZ()
|
} else if (Math.abs(southeast.getBlockX() - latestPlayerLocation.getBlockX()) < minSafeDistanceFromWall
|
||||||
&& latestPlayerLocation.getBlockZ() >= southeast.getBlockZ()) {
|
&& latestPlayerLocation.getBlockZ() < northwest.getBlockZ()
|
||||||
return true; // near south wall
|
&& latestPlayerLocation.getBlockZ() > southeast.getBlockZ()) {
|
||||||
} else if (Math.abs(northwest.getBlockX() - latestPlayerLocation.getBlockX()) < minSafeDistanceFromWall
|
return true; // near south wall
|
||||||
&& latestPlayerLocation.getBlockZ() <= northwest.getBlockZ()
|
} else if (Math.abs(northwest.getBlockX() - latestPlayerLocation.getBlockX()) < minSafeDistanceFromWall
|
||||||
&& latestPlayerLocation.getBlockZ() >= southeast.getBlockZ()) {
|
&& latestPlayerLocation.getBlockZ() < northwest.getBlockZ()
|
||||||
return true; // near north wall
|
&& latestPlayerLocation.getBlockZ() > southeast.getBlockZ()) {
|
||||||
} else if (Math.abs(northwest.getBlockZ() - latestPlayerLocation.getBlockZ()) < minSafeDistanceFromWall
|
return true; // near north wall
|
||||||
&& latestPlayerLocation.getBlockX() <= southeast.getBlockX()
|
} else if (Math.abs(northwest.getBlockZ() - latestPlayerLocation.getBlockZ()) < minSafeDistanceFromWall
|
||||||
&& latestPlayerLocation.getBlockX() >= northwest.getBlockX()) {
|
&& latestPlayerLocation.getBlockX() < southeast.getBlockX()
|
||||||
return true; // near west wall
|
&& latestPlayerLocation.getBlockX() > northwest.getBlockX()) {
|
||||||
|
return true; // near west wall
|
||||||
|
}
|
||||||
}
|
}
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
@ -499,9 +516,34 @@ public class Warzone {
|
|||||||
// note: y + 1 to line up 3 sided square with player eyes
|
// note: y + 1 to line up 3 sided square with player eyes
|
||||||
}
|
}
|
||||||
|
|
||||||
public ZoneWallGuard getPlayerZoneWallGuard(String name) {
|
public BlockFace getNearestWall(Location latestPlayerLocation) {
|
||||||
|
if(Math.abs(southeast.getBlockZ() - latestPlayerLocation.getBlockZ()) < minSafeDistanceFromWall
|
||||||
|
&& latestPlayerLocation.getBlockX() <= southeast.getBlockX()
|
||||||
|
&& latestPlayerLocation.getBlockX() >= northwest.getBlockX()) {
|
||||||
|
// near east wall
|
||||||
|
return BlockFace.East;
|
||||||
|
} else if (Math.abs(southeast.getBlockX() - latestPlayerLocation.getBlockX()) < minSafeDistanceFromWall
|
||||||
|
&& latestPlayerLocation.getBlockZ() <= northwest.getBlockZ()
|
||||||
|
&& latestPlayerLocation.getBlockZ() >= southeast.getBlockZ()) {
|
||||||
|
// near south wall
|
||||||
|
return BlockFace.South;
|
||||||
|
} else if (Math.abs(northwest.getBlockX() - latestPlayerLocation.getBlockX()) < minSafeDistanceFromWall
|
||||||
|
&& latestPlayerLocation.getBlockZ() <= northwest.getBlockZ()
|
||||||
|
&& latestPlayerLocation.getBlockZ() >= southeast.getBlockZ()) {
|
||||||
|
// near north wall
|
||||||
|
return BlockFace.North;
|
||||||
|
} else if (Math.abs(northwest.getBlockZ() - latestPlayerLocation.getBlockZ()) < minSafeDistanceFromWall
|
||||||
|
&& latestPlayerLocation.getBlockX() <= southeast.getBlockX()
|
||||||
|
&& latestPlayerLocation.getBlockX() >= northwest.getBlockX()) {
|
||||||
|
// near west wall
|
||||||
|
return BlockFace.West;
|
||||||
|
}
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
public ZoneWallGuard getPlayerZoneWallGuard(String name, BlockFace wall) {
|
||||||
for(ZoneWallGuard guard : zoneWallGuards) {
|
for(ZoneWallGuard guard : zoneWallGuards) {
|
||||||
if(guard.getPlayer().getName().equals(name)) {
|
if(guard.getPlayer().getName().equals(name) && wall == guard.getWall()) {
|
||||||
return guard;
|
return guard;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -510,20 +552,32 @@ public class Warzone {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public void protectZoneWallAgainstPlayer(Player player) {
|
public void protectZoneWallAgainstPlayer(Player player) {
|
||||||
ZoneWallGuard guard = getPlayerZoneWallGuard(player.getName());
|
BlockFace nearestWall = getNearestWall(player.getLocation());
|
||||||
|
ZoneWallGuard guard = getPlayerZoneWallGuard(player.getName(), nearestWall);
|
||||||
if(guard != null) {
|
if(guard != null) {
|
||||||
// already protected, need to move the guard
|
// already protected, need to move the guard
|
||||||
guard.updatePlayerPosition(player.getLocation());
|
guard.updatePlayerPosition(player.getLocation());
|
||||||
} else {
|
} else {
|
||||||
// new guard
|
// new guard
|
||||||
guard = new ZoneWallGuard(player, war, this);
|
guard = new ZoneWallGuard(player, war, this);
|
||||||
|
zoneWallGuards.add(guard);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public void dropZoneWallGuardIfAny(Player player) {
|
public void dropZoneWallGuardIfAny(Player player) {
|
||||||
ZoneWallGuard guard = getPlayerZoneWallGuard(player.getName());
|
List<ZoneWallGuard> playerGuards = new ArrayList<ZoneWallGuard>();
|
||||||
guard.updatePlayerPosition(player.getLocation()); // should restore old blocks
|
for(ZoneWallGuard guard : zoneWallGuards) {
|
||||||
zoneWallGuards.remove(guard);
|
if(guard.getPlayer().getName().equals(player.getName())){
|
||||||
|
playerGuards.add(guard);
|
||||||
|
int reset = volume.resetWallBlocks(guard.getWall()); // this should restore old blocks
|
||||||
|
war.getLogger().info("Reset " + reset + " blocks in " + guard.getWall() + "wall of warzone " + name);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
// now remove those zone guards
|
||||||
|
for(ZoneWallGuard playerGuard : playerGuards) {
|
||||||
|
zoneWallGuards.remove(playerGuard);
|
||||||
|
}
|
||||||
|
playerGuards.clear();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -15,8 +15,8 @@ public class ZoneWallGuard {
|
|||||||
private Player player;
|
private Player player;
|
||||||
private Warzone warzone;
|
private Warzone warzone;
|
||||||
private Location playerLocation;
|
private Location playerLocation;
|
||||||
private CenteredVolume volume;
|
|
||||||
private final War war;
|
private final War war;
|
||||||
|
private BlockFace wall;
|
||||||
|
|
||||||
private final int radius = 3;
|
private final int radius = 3;
|
||||||
|
|
||||||
@ -32,12 +32,15 @@ public class ZoneWallGuard {
|
|||||||
private void activate() {
|
private void activate() {
|
||||||
// save current blocks
|
// save current blocks
|
||||||
Block nearestWallBlock = warzone.getNearestWallBlock(playerLocation);
|
Block nearestWallBlock = warzone.getNearestWallBlock(playerLocation);
|
||||||
if(volume == null) {
|
// if(volume == null) {
|
||||||
volume = new CenteredVolume("zoneGuard-" + warzone.getName() + "-" + player.getName(), nearestWallBlock, radius, war, warzone);
|
// volume = new CenteredVolume("zoneGuard-" + warzone.getName() + "-" + player.getName(), nearestWallBlock, radius, war, warzone);
|
||||||
} else {
|
// int saved = volume.saveBlocks();
|
||||||
volume.changeCenter(nearestWallBlock, radius);
|
// war.getLogger().info("Warzone wall guard created: " + saved + " blocks saved for " + player.getName());
|
||||||
volume.saveBlocks();
|
// } 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
|
// add wall guard blocks
|
||||||
nearestWallBlock.setType(Material.Glass);
|
nearestWallBlock.setType(Material.Glass);
|
||||||
nearestWallBlock.getFace(BlockFace.Up).setType(Material.Glass);
|
nearestWallBlock.getFace(BlockFace.Up).setType(Material.Glass);
|
||||||
@ -45,6 +48,7 @@ public class ZoneWallGuard {
|
|||||||
if(warzone.getVolume().isNorthWallBlock(nearestWallBlock.getFace(BlockFace.East)) &&
|
if(warzone.getVolume().isNorthWallBlock(nearestWallBlock.getFace(BlockFace.East)) &&
|
||||||
warzone.getVolume().isNorthWallBlock(nearestWallBlock.getFace(BlockFace.West))) {
|
warzone.getVolume().isNorthWallBlock(nearestWallBlock.getFace(BlockFace.West))) {
|
||||||
// north wall guard
|
// north wall guard
|
||||||
|
this.wall = BlockFace.North;
|
||||||
toGlass(nearestWallBlock.getFace(BlockFace.East), 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.Up), BlockFace.North);
|
||||||
toGlass(nearestWallBlock.getFace(BlockFace.East).getFace(BlockFace.Down), BlockFace.North);
|
toGlass(nearestWallBlock.getFace(BlockFace.East).getFace(BlockFace.Down), BlockFace.North);
|
||||||
@ -54,6 +58,7 @@ public class ZoneWallGuard {
|
|||||||
} else if (warzone.getVolume().isSouthWallBlock(nearestWallBlock.getFace(BlockFace.East)) &&
|
} else if (warzone.getVolume().isSouthWallBlock(nearestWallBlock.getFace(BlockFace.East)) &&
|
||||||
warzone.getVolume().isSouthWallBlock(nearestWallBlock.getFace(BlockFace.West))) {
|
warzone.getVolume().isSouthWallBlock(nearestWallBlock.getFace(BlockFace.West))) {
|
||||||
// south wall guard
|
// south wall guard
|
||||||
|
this.wall = BlockFace.South;
|
||||||
toGlass(nearestWallBlock.getFace(BlockFace.East), 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.Up), BlockFace.South);
|
||||||
toGlass(nearestWallBlock.getFace(BlockFace.East).getFace(BlockFace.Down), BlockFace.South);
|
toGlass(nearestWallBlock.getFace(BlockFace.East).getFace(BlockFace.Down), BlockFace.South);
|
||||||
@ -64,6 +69,7 @@ public class ZoneWallGuard {
|
|||||||
} else if (warzone.getVolume().isEastWallBlock(nearestWallBlock.getFace(BlockFace.North)) &&
|
} else if (warzone.getVolume().isEastWallBlock(nearestWallBlock.getFace(BlockFace.North)) &&
|
||||||
warzone.getVolume().isEastWallBlock(nearestWallBlock.getFace(BlockFace.South))) {
|
warzone.getVolume().isEastWallBlock(nearestWallBlock.getFace(BlockFace.South))) {
|
||||||
//east wall guard
|
//east wall guard
|
||||||
|
this.wall = BlockFace.East;
|
||||||
toGlass(nearestWallBlock.getFace(BlockFace.North), 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.Up), BlockFace.East);
|
||||||
toGlass(nearestWallBlock.getFace(BlockFace.North).getFace(BlockFace.Down), BlockFace.East);
|
toGlass(nearestWallBlock.getFace(BlockFace.North).getFace(BlockFace.Down), BlockFace.East);
|
||||||
@ -73,6 +79,7 @@ public class ZoneWallGuard {
|
|||||||
} else if (warzone.getVolume().isWestWallBlock(nearestWallBlock.getFace(BlockFace.North)) &&
|
} else if (warzone.getVolume().isWestWallBlock(nearestWallBlock.getFace(BlockFace.North)) &&
|
||||||
warzone.getVolume().isWestWallBlock(nearestWallBlock.getFace(BlockFace.South))) {
|
warzone.getVolume().isWestWallBlock(nearestWallBlock.getFace(BlockFace.South))) {
|
||||||
//west wall guard
|
//west wall guard
|
||||||
|
this.wall = BlockFace.West;
|
||||||
toGlass(nearestWallBlock.getFace(BlockFace.North), 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.Up), BlockFace.West);
|
||||||
toGlass(nearestWallBlock.getFace(BlockFace.North).getFace(BlockFace.Down), BlockFace.West);
|
toGlass(nearestWallBlock.getFace(BlockFace.North).getFace(BlockFace.Down), BlockFace.West);
|
||||||
@ -103,22 +110,22 @@ public class ZoneWallGuard {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private void deactivate() {
|
|
||||||
// restore old blocks
|
|
||||||
volume.resetBlocks();
|
|
||||||
}
|
|
||||||
|
|
||||||
public void updatePlayerPosition(Location location) {
|
public void updatePlayerPosition(Location location) {
|
||||||
if(warzone.isNearWall(location)) {
|
if(warzone.isNearWall(location)) {
|
||||||
deactivate();
|
|
||||||
this.playerLocation = location;
|
this.playerLocation = location;
|
||||||
activate();
|
activate();
|
||||||
} else {
|
|
||||||
deactivate();
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public Player getPlayer() {
|
public Player getPlayer() {
|
||||||
return player;
|
return player;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void setWall(BlockFace wall) {
|
||||||
|
this.wall = wall;
|
||||||
|
}
|
||||||
|
|
||||||
|
public BlockFace getWall() {
|
||||||
|
return wall;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -1,6 +1,10 @@
|
|||||||
package com.tommytony.war.volumes;
|
package com.tommytony.war.volumes;
|
||||||
|
|
||||||
import org.bukkit.Block;
|
import org.bukkit.Block;
|
||||||
|
import org.bukkit.BlockFace;
|
||||||
|
import org.bukkit.Material;
|
||||||
|
import org.bukkit.block.BlockState;
|
||||||
|
import org.bukkit.block.Sign;
|
||||||
|
|
||||||
import bukkit.tommytony.war.War;
|
import bukkit.tommytony.war.War;
|
||||||
|
|
||||||
@ -66,4 +70,104 @@ public class VerticalVolume extends Volume{
|
|||||||
}
|
}
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public int resetWallBlocks(BlockFace wall) {
|
||||||
|
int noOfResetBlocks = 0;
|
||||||
|
try {
|
||||||
|
if(hasTwoCorners() && getBlockInfos() != null) {
|
||||||
|
if(wall == BlockFace.East) {
|
||||||
|
int z = getMinZ();
|
||||||
|
int k = 0;
|
||||||
|
int y = getMinY();
|
||||||
|
for(int j = 0; j < getSizeY(); j++) {
|
||||||
|
int x = getMinX();
|
||||||
|
for(int i = 0; i < getSizeX(); i++) {
|
||||||
|
BlockInfo oldBlockInfo = getBlockInfos()[i][j][k];
|
||||||
|
Block currentBlock = getWorld().getBlockAt(x, y, z);
|
||||||
|
if(resetBlock(oldBlockInfo, currentBlock)) {
|
||||||
|
noOfResetBlocks++;
|
||||||
|
}
|
||||||
|
x++;
|
||||||
|
}
|
||||||
|
y++;
|
||||||
|
}
|
||||||
|
} else if(wall == BlockFace.West) {
|
||||||
|
int z = getMaxZ();
|
||||||
|
int k = getSizeZ()-1;
|
||||||
|
int y = getMinY();
|
||||||
|
for(int j = 0; j < getSizeY(); j++) {
|
||||||
|
int x = getMinX();
|
||||||
|
for(int i = 0; i < getSizeX(); i++) {
|
||||||
|
BlockInfo oldBlockInfo = getBlockInfos()[i][j][k];
|
||||||
|
Block currentBlock = getWorld().getBlockAt(x, y, z);
|
||||||
|
if(resetBlock(oldBlockInfo, currentBlock)) {
|
||||||
|
noOfResetBlocks++;
|
||||||
|
}
|
||||||
|
x++;
|
||||||
|
}
|
||||||
|
y++;
|
||||||
|
}
|
||||||
|
} else if(wall == BlockFace.North) {
|
||||||
|
int x = getMinX();
|
||||||
|
int i = 0;
|
||||||
|
int y = getMinY();
|
||||||
|
for(int j = 0; j < getSizeY(); j++) {
|
||||||
|
int z = getMinZ();
|
||||||
|
for(int k = 0; k < getSizeZ(); k++) {
|
||||||
|
BlockInfo oldBlockInfo = getBlockInfos()[i][j][k];
|
||||||
|
Block currentBlock = getWorld().getBlockAt(x, y, z);
|
||||||
|
if(resetBlock(oldBlockInfo, currentBlock)) {
|
||||||
|
noOfResetBlocks++;
|
||||||
|
}
|
||||||
|
z++;
|
||||||
|
}
|
||||||
|
y++;
|
||||||
|
}
|
||||||
|
} else if(wall == BlockFace.South) {
|
||||||
|
int x = getMaxX();
|
||||||
|
int i = getSizeX()-1;
|
||||||
|
int y = getMinY();
|
||||||
|
for(int j = 0; j < getSizeY(); j++) {
|
||||||
|
int z = getMinZ();
|
||||||
|
for(int k = 0; k < getSizeZ(); k++) {
|
||||||
|
BlockInfo oldBlockInfo = getBlockInfos()[i][j][k];
|
||||||
|
Block currentBlock = getWorld().getBlockAt(x, y, z);
|
||||||
|
if(resetBlock(oldBlockInfo, currentBlock)) {
|
||||||
|
noOfResetBlocks++;
|
||||||
|
}
|
||||||
|
z++;
|
||||||
|
}
|
||||||
|
y++;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} catch (Exception e) {
|
||||||
|
this.getWar().getLogger().warning(getWar().str("Failed to reset wall " + wall + " in volume " + getName() + ". " + e.getMessage()));
|
||||||
|
}
|
||||||
|
return noOfResetBlocks;
|
||||||
|
}
|
||||||
|
|
||||||
|
private boolean resetBlock(BlockInfo oldBlockInfo, Block currentBlock) {
|
||||||
|
if(currentBlock.getTypeID() != oldBlockInfo.getTypeID() ||
|
||||||
|
(currentBlock.getTypeID() == oldBlockInfo.getTypeID() && currentBlock.getData() != oldBlockInfo.getData()) ||
|
||||||
|
(currentBlock.getTypeID() == oldBlockInfo.getTypeID() && currentBlock.getData() == oldBlockInfo.getData() &&
|
||||||
|
(oldBlockInfo.is(Material.Sign) || oldBlockInfo.is(Material.SignPost))
|
||||||
|
)
|
||||||
|
) {
|
||||||
|
currentBlock.setType(oldBlockInfo.getType());
|
||||||
|
currentBlock.setData(oldBlockInfo.getData());
|
||||||
|
if(oldBlockInfo.is(Material.Sign) || oldBlockInfo.is(Material.SignPost)) {
|
||||||
|
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();
|
||||||
|
}
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -50,14 +50,14 @@ public class Volume {
|
|||||||
int noOfSavedBlocks = 0;
|
int noOfSavedBlocks = 0;
|
||||||
try {
|
try {
|
||||||
if(hasTwoCorners()) {
|
if(hasTwoCorners()) {
|
||||||
this.blockInfos = new BlockInfo[getSizeX()][getSizeY()][getSizeZ()];
|
this.setBlockInfos(new BlockInfo[getSizeX()][getSizeY()][getSizeZ()]);
|
||||||
int x = getMinX();
|
int x = getMinX();
|
||||||
for(int i = 0; i < getSizeX(); i++){
|
for(int i = 0; i < getSizeX(); i++){
|
||||||
int y = getMinY();
|
int y = getMinY();
|
||||||
for(int j = 0; j < getSizeY(); j++){
|
for(int j = 0; j < getSizeY(); j++){
|
||||||
int z = getMinZ();
|
int z = getMinZ();
|
||||||
for(int k = 0;k < getSizeZ(); k++) {
|
for(int k = 0;k < getSizeZ(); k++) {
|
||||||
this.blockInfos[i][j][k] = new BlockInfo(world.getBlockAt(x, y, z));
|
this.getBlockInfos()[i][j][k] = new BlockInfo(getWorld().getBlockAt(x, y, z));
|
||||||
z++;
|
z++;
|
||||||
noOfSavedBlocks++;
|
noOfSavedBlocks++;
|
||||||
}
|
}
|
||||||
@ -67,7 +67,7 @@ public class Volume {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
this.war.getLogger().warning(war.str("Failed to save volume " + name + " blocks. " + e.getMessage()));
|
this.getWar().getLogger().warning(getWar().str("Failed to save volume " + getName() + " blocks. " + e.getMessage()));
|
||||||
}
|
}
|
||||||
return noOfSavedBlocks;
|
return noOfSavedBlocks;
|
||||||
}
|
}
|
||||||
@ -75,15 +75,15 @@ public class Volume {
|
|||||||
public int resetBlocks() {
|
public int resetBlocks() {
|
||||||
int noOfResetBlocks = 0;
|
int noOfResetBlocks = 0;
|
||||||
try {
|
try {
|
||||||
if(hasTwoCorners() && blockInfos != null) {
|
if(hasTwoCorners() && getBlockInfos() != null) {
|
||||||
int x = getMinX();
|
int x = getMinX();
|
||||||
for(int i = 0; i < getSizeX(); i++){
|
for(int i = 0; i < getSizeX(); i++){
|
||||||
int y = getMinY();
|
int y = getMinY();
|
||||||
for(int j = 0; j < getSizeY(); j++){
|
for(int j = 0; j < getSizeY(); j++){
|
||||||
int z = getMinZ();
|
int z = getMinZ();
|
||||||
for(int k = 0;k < getSizeZ(); k++) {
|
for(int k = 0;k < getSizeZ(); k++) {
|
||||||
BlockInfo oldBlockInfo = blockInfos[i][j][k];
|
BlockInfo oldBlockInfo = getBlockInfos()[i][j][k];
|
||||||
Block currentBlock = world.getBlockAt(x, y, z);
|
Block currentBlock = getWorld().getBlockAt(x, y, z);
|
||||||
if(currentBlock.getTypeID() != oldBlockInfo.getTypeID() ||
|
if(currentBlock.getTypeID() != oldBlockInfo.getTypeID() ||
|
||||||
(currentBlock.getTypeID() == oldBlockInfo.getTypeID() && currentBlock.getData() != oldBlockInfo.getData()) ||
|
(currentBlock.getTypeID() == oldBlockInfo.getTypeID() && currentBlock.getData() != oldBlockInfo.getData()) ||
|
||||||
(currentBlock.getTypeID() == oldBlockInfo.getTypeID() && currentBlock.getData() == oldBlockInfo.getData() &&
|
(currentBlock.getTypeID() == oldBlockInfo.getTypeID() && currentBlock.getData() == oldBlockInfo.getData() &&
|
||||||
@ -111,7 +111,7 @@ public class Volume {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
this.war.getLogger().warning(war.str("Failed to reset volume " + name + " blocks. " + e.getMessage()));
|
this.getWar().getLogger().warning(getWar().str("Failed to reset volume " + getName() + " blocks. " + e.getMessage()));
|
||||||
}
|
}
|
||||||
return noOfResetBlocks;
|
return noOfResetBlocks;
|
||||||
}
|
}
|
||||||
@ -187,7 +187,7 @@ public class Volume {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public boolean isSaved() {
|
public boolean isSaved() {
|
||||||
return blockInfos != null;
|
return getBlockInfos() != null;
|
||||||
}
|
}
|
||||||
|
|
||||||
public BlockInfo[][][] getBlockInfos() {
|
public BlockInfo[][][] getBlockInfos() {
|
||||||
@ -226,16 +226,16 @@ public class Volume {
|
|||||||
scanner.next(",");
|
scanner.next(",");
|
||||||
int z1 = scanner.nextInt();
|
int z1 = scanner.nextInt();
|
||||||
scanner.next(";");
|
scanner.next(";");
|
||||||
cornerOne = world.getBlockAt(x1, y1, z1);
|
cornerOne = getWorld().getBlockAt(x1, y1, z1);
|
||||||
int x2 = scanner.nextInt();
|
int x2 = scanner.nextInt();
|
||||||
scanner.next(",");
|
scanner.next(",");
|
||||||
int y2 = scanner.nextInt();
|
int y2 = scanner.nextInt();
|
||||||
scanner.next(",");
|
scanner.next(",");
|
||||||
int z2 = scanner.nextInt();
|
int z2 = scanner.nextInt();
|
||||||
scanner.next(";");
|
scanner.next(";");
|
||||||
cornerOne = world.getBlockAt(x2, y2, z2);
|
cornerOne = getWorld().getBlockAt(x2, y2, z2);
|
||||||
|
|
||||||
blockInfos = new BlockInfo[getSizeX()][getSizeY()][getSizeZ()];
|
setBlockInfos(new BlockInfo[getSizeX()][getSizeY()][getSizeZ()]);
|
||||||
for(int i = 0; i < getSizeX(); i++){
|
for(int i = 0; i < getSizeX(); i++){
|
||||||
for(int j = 0; j < getSizeY(); j++) {
|
for(int j = 0; j < getSizeY(); j++) {
|
||||||
for(int k = 0; k < getSizeZ(); k++) {
|
for(int k = 0; k < getSizeZ(); k++) {
|
||||||
@ -281,4 +281,16 @@ public class Volume {
|
|||||||
z <= getMaxZ() && z >= getMinZ();
|
z <= getMaxZ() && z >= getMinZ();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void setBlockInfos(BlockInfo[][][] blockInfos) {
|
||||||
|
this.blockInfos = blockInfos;
|
||||||
|
}
|
||||||
|
|
||||||
|
public War getWar() {
|
||||||
|
return war;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getName() {
|
||||||
|
return name;
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user