mirror of
https://github.com/taoneill/war.git
synced 2025-02-12 17:31:21 +01:00
Rewriting the file read-writing.
This commit is contained in:
parent
d598c921d5
commit
f2be251106
@ -39,9 +39,11 @@ public class War extends JavaPlugin {
|
||||
String version = "0.3";
|
||||
|
||||
private final List<Warzone> warzones = new ArrayList<Warzone>();
|
||||
private final List<String> zoneMakerNames = new ArrayList<String>();
|
||||
private final HashMap<Integer, ItemStack> defaultLoadout = new HashMap<Integer, ItemStack>();
|
||||
private int defaultLifepool = 7;
|
||||
private boolean defaultFriendlyFire = false;
|
||||
private boolean defaultFriendlyFire = false;
|
||||
private boolean defaultDrawZoneOutline = true;
|
||||
|
||||
|
||||
public void onDisable() {
|
||||
@ -70,19 +72,13 @@ public class War extends JavaPlugin {
|
||||
pm.registerEvent(Event.Type.BLOCK_DAMAGED, blockListener, Priority.Normal, this); // BROKEN
|
||||
|
||||
// Load files from disk or create them
|
||||
this.defaultLoadout.put(0, new ItemStack(272, 1));
|
||||
this.defaultLoadout.put(1, new ItemStack(261, 1));
|
||||
this.defaultLoadout.put(2, new ItemStack(262, 12));
|
||||
this.defaultLoadout.put(3, new ItemStack(274, 1));
|
||||
this.defaultLoadout.put(4, new ItemStack(273, 1));
|
||||
this.defaultLoadout.put(5, new ItemStack(275, 1));
|
||||
this.defaultLoadout.put(27, new ItemStack(259, 1));
|
||||
this.defaultLoadout.put(6, new ItemStack(297, 1));
|
||||
this.defaultLoadout.put(8, new ItemStack(3, 12));
|
||||
this.defaultLoadout.put(100, new ItemStack(301, 1));
|
||||
this.defaultLoadout.put(101, new ItemStack(300, 1));
|
||||
this.defaultLoadout.put(102, new ItemStack(299, 1));
|
||||
this.defaultLoadout.put(103, new ItemStack(298, 1));
|
||||
this.defaultLoadout.put(0, new ItemStack(Material.StoneSword));
|
||||
this.defaultLoadout.put(1, new ItemStack(Material.Bow));
|
||||
this.defaultLoadout.put(2, new ItemStack(Material.Arrow, 7));
|
||||
this.defaultLoadout.put(3, new ItemStack(Material.StonePickaxe));
|
||||
this.defaultLoadout.put(4, new ItemStack(Material.StoneSpade));
|
||||
this.defaultLoadout.put(5, new ItemStack(Material.StoneAxe));
|
||||
this.defaultLoadout.put(6, new ItemStack(Material.Bread, 2));
|
||||
this.defaultLifepool = 7;
|
||||
this.defaultFriendlyFire = false;
|
||||
WarMapper.load(this);
|
||||
@ -187,5 +183,13 @@ public class War extends JavaPlugin {
|
||||
return null;
|
||||
}
|
||||
|
||||
public List<String> getZoneMakerNames() {
|
||||
return zoneMakerNames;
|
||||
}
|
||||
|
||||
public boolean getDefaultDrawZoneOutline() {
|
||||
return defaultDrawZoneOutline ;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
@ -15,7 +15,6 @@ import com.tommytony.war.Monument;
|
||||
import com.tommytony.war.Team;
|
||||
import com.tommytony.war.TeamMaterials;
|
||||
import com.tommytony.war.Warzone;
|
||||
import com.tommytony.war.ZoneWallGuard;
|
||||
import com.tommytony.war.mappers.WarMapper;
|
||||
import com.tommytony.war.mappers.WarzoneMapper;
|
||||
|
||||
@ -439,7 +438,6 @@ public class WarPlayerListener extends PlayerListener {
|
||||
if(warzone.hasMonument(monumentName)) {
|
||||
// move the existing monument
|
||||
Monument monument = warzone.getMonument(monumentName);
|
||||
monument.remove();
|
||||
monument.setLocation(player.getLocation());
|
||||
player.sendMessage(war.str("Monument " + monument.getName() + " was moved."));
|
||||
} else {
|
||||
@ -508,10 +506,7 @@ 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."));
|
||||
|
@ -146,9 +146,7 @@ public class Monument {
|
||||
return name;
|
||||
}
|
||||
|
||||
public void setLocation(Location location) {
|
||||
this.location = location;
|
||||
|
||||
public void setLocation(Location location) {
|
||||
volume.changeCenter(location);
|
||||
this.addMonumentBlocks();
|
||||
}
|
||||
|
@ -15,7 +15,6 @@ import org.bukkit.World;
|
||||
import bukkit.tommytony.war.War;
|
||||
|
||||
import com.tommytony.war.volumes.VerticalVolume;
|
||||
import com.tommytony.war.volumes.Volume;
|
||||
|
||||
/**
|
||||
*
|
||||
@ -34,6 +33,7 @@ public class Warzone {
|
||||
private boolean friendlyFire;
|
||||
private int lifePool;
|
||||
private HashMap<Integer, ItemStack> loadout;
|
||||
private boolean drawZoneOutline;
|
||||
|
||||
private HashMap<String, List<ItemStack>> inventories = new HashMap<String, List<ItemStack>>();
|
||||
private World world;
|
||||
@ -43,6 +43,7 @@ public class Warzone {
|
||||
private List<ZoneWallGuard> zoneWallGuards = new ArrayList<ZoneWallGuard>();
|
||||
private War war;
|
||||
|
||||
|
||||
public Warzone(War war, World world, String name) {
|
||||
this.world = world;
|
||||
this.war = war;
|
||||
@ -50,6 +51,7 @@ public class Warzone {
|
||||
this.friendlyFire = war.getDefaultFriendlyFire();
|
||||
this.setLifePool(war.getDefaultLifepool());
|
||||
this.setLoadout(war.getDefaultLoadout());
|
||||
this.drawZoneOutline = war.getDefaultDrawZoneOutline();
|
||||
this.volume = new VerticalVolume(name, war, this);
|
||||
}
|
||||
|
||||
@ -167,38 +169,13 @@ public class Warzone {
|
||||
*/
|
||||
public void initializeZone() {
|
||||
if(ready() && volume.isSaved()){
|
||||
// get surface corners
|
||||
volume.getMinX();
|
||||
volume.getMinZ();
|
||||
volume.getMinY();
|
||||
int c1maxY = world.getHighestBlockYAt(volume.getMinX(), volume.getMinZ());
|
||||
int c2maxY = world.getHighestBlockYAt(volume.getMaxX(), volume.getMaxZ());
|
||||
Block ne = world.getBlockAt(volume.getMinX(), c1maxY, volume.getMinZ());
|
||||
Block nw = world.getBlockAt(volume.getMinX(), c2maxY, volume.getMaxZ());
|
||||
Block sw = world.getBlockAt(volume.getMinX(), c1maxY, volume.getMaxZ());
|
||||
Block se = world.getBlockAt(volume.getMaxX(), c2maxY, volume.getMinZ());
|
||||
|
||||
// add north wall, ne - nw
|
||||
Block lastBlock = null;
|
||||
for(int z = volume.getMinZ(); z < volume.getMaxZ(); z++) {
|
||||
lastBlock = highestBlockToGlass(ne.getX(), z, lastBlock);
|
||||
}
|
||||
|
||||
// add east, ne - se
|
||||
lastBlock = null;
|
||||
for(int x = volume.getMinX(); x < volume.getMaxX(); x++) {
|
||||
lastBlock = highestBlockToGlass(x, ne.getZ(), lastBlock);
|
||||
}
|
||||
|
||||
// add south, se - sw
|
||||
lastBlock = null;
|
||||
for(int z = volume.getMinZ(); z < volume.getMaxZ(); z++) {
|
||||
lastBlock = highestBlockToGlass(se.getX(), z, lastBlock);
|
||||
}
|
||||
|
||||
// add west, nw - sw
|
||||
for(int x = volume.getMinX(); x < volume.getMaxX(); x++) {
|
||||
lastBlock = highestBlockToGlass(x, nw.getZ(), lastBlock);
|
||||
|
||||
// add wall outlines
|
||||
if(drawZoneOutline) {
|
||||
addZoneOutline(BlockFace.North);
|
||||
addZoneOutline(BlockFace.East);
|
||||
addZoneOutline(BlockFace.South);
|
||||
addZoneOutline(BlockFace.West);
|
||||
}
|
||||
|
||||
// everyone back to team spawn with full health
|
||||
@ -222,6 +199,32 @@ public class Warzone {
|
||||
}
|
||||
}
|
||||
|
||||
private void addZoneOutline(BlockFace wall) {
|
||||
int c1maxY = world.getHighestBlockYAt(volume.getMinX(), volume.getMinZ());
|
||||
int c2maxY = world.getHighestBlockYAt(volume.getMaxX(), volume.getMaxZ());
|
||||
Block ne = world.getBlockAt(volume.getMinX(), c1maxY, volume.getMinZ());
|
||||
Block nw = world.getBlockAt(volume.getMinX(), c2maxY, volume.getMaxZ());
|
||||
Block se = world.getBlockAt(volume.getMaxX(), c2maxY, volume.getMinZ());
|
||||
Block lastBlock = null;
|
||||
if(BlockFace.North == wall) {
|
||||
for(int z = volume.getMinZ(); z < volume.getMaxZ(); z++) {
|
||||
lastBlock = highestBlockToGlass(ne.getX(), z, lastBlock);
|
||||
}
|
||||
} else if (BlockFace.East == wall) {
|
||||
for(int x = volume.getMinX(); x < volume.getMaxX(); x++) {
|
||||
lastBlock = highestBlockToGlass(x, ne.getZ(), lastBlock);
|
||||
}
|
||||
} else if (BlockFace.South == wall) {
|
||||
for(int z = volume.getMinZ(); z < volume.getMaxZ(); z++) {
|
||||
lastBlock = highestBlockToGlass(se.getX(), z, lastBlock);
|
||||
}
|
||||
} else if (BlockFace.West == wall) {
|
||||
for(int x = volume.getMinX(); x < volume.getMaxX(); x++) {
|
||||
lastBlock = highestBlockToGlass(x, nw.getZ(), lastBlock);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private Block highestBlockToGlass(int x, int z, Block lastBlock) {
|
||||
int highest = world.getHighestBlockYAt(x, z);
|
||||
Block block = world.getBlockAt(x, highest -1 , z);
|
||||
@ -271,21 +274,29 @@ public class Warzone {
|
||||
|
||||
// Reset inventory to loadout
|
||||
PlayerInventory playerInv = player.getInventory();
|
||||
for(int i = 0; i < playerInv.getSize(); i++){
|
||||
playerInv.setItem(i, null);
|
||||
}
|
||||
// BUKKIT
|
||||
// for(int i = 0; i < playerInv.getSize(); i++){
|
||||
// playerInv.setItem(index, new ItemStack(Material.))
|
||||
// playerInv.setItem(i, null);
|
||||
// }
|
||||
for(Integer slot : loadout.keySet()) {
|
||||
if(slot == 100) {
|
||||
playerInv.setBoots(loadout.get(slot));
|
||||
} else if(slot == 101) {
|
||||
playerInv.setLeggings(loadout.get(slot));
|
||||
} else if(slot == 102) {
|
||||
playerInv.setChestplate(loadout.get(slot));
|
||||
} else if(slot == 103) {
|
||||
playerInv.setHelmet(loadout.get(slot));
|
||||
} else {
|
||||
// if(slot == 101) {
|
||||
// playerInv.setLeggings(loadout.get(slot));
|
||||
// } else if(slot == 102) {
|
||||
// playerInv.setChestplate(loadout.get(slot));
|
||||
// } else if(slot == 103) {
|
||||
// playerInv.setHelmet(loadout.get(slot));
|
||||
// } else {
|
||||
playerInv.setItem(slot, loadout.get(slot));
|
||||
}
|
||||
//}
|
||||
}
|
||||
|
||||
if(team.getMaterial() == Material.GoldBlock) {
|
||||
playerInv.setHelmet(new ItemStack(Material.GoldBoots));
|
||||
} else if (team.getMaterial() == Material.DiamondBlock) {
|
||||
playerInv.setHelmet(new ItemStack(Material.DiamondBoots));
|
||||
} else if (team.getMaterial() == Material.IronBlock) {
|
||||
playerInv.setHelmet(new ItemStack(Material.IronBoots));
|
||||
}
|
||||
|
||||
player.setHealth(20);
|
||||
@ -466,79 +477,93 @@ public class Warzone {
|
||||
public boolean isNearWall(Location latestPlayerLocation) {
|
||||
if(volume.hasTwoCorners()) {
|
||||
if(Math.abs(southeast.getBlockZ() - latestPlayerLocation.getBlockZ()) < minSafeDistanceFromWall
|
||||
&& latestPlayerLocation.getBlockX() < southeast.getBlockX()
|
||||
&& latestPlayerLocation.getBlockX() > northwest.getBlockX()) {
|
||||
&& latestPlayerLocation.getBlockX() <= southeast.getBlockX()
|
||||
&& latestPlayerLocation.getBlockX() >= northwest.getBlockX()) {
|
||||
return true; // near east wall
|
||||
} else if (Math.abs(southeast.getBlockX() - latestPlayerLocation.getBlockX()) < minSafeDistanceFromWall
|
||||
&& latestPlayerLocation.getBlockZ() < northwest.getBlockZ()
|
||||
&& latestPlayerLocation.getBlockZ() > southeast.getBlockZ()) {
|
||||
&& latestPlayerLocation.getBlockZ() <= northwest.getBlockZ()
|
||||
&& latestPlayerLocation.getBlockZ() >= southeast.getBlockZ()) {
|
||||
return true; // near south wall
|
||||
} else if (Math.abs(northwest.getBlockX() - latestPlayerLocation.getBlockX()) < minSafeDistanceFromWall
|
||||
&& latestPlayerLocation.getBlockZ() < northwest.getBlockZ()
|
||||
&& latestPlayerLocation.getBlockZ() > southeast.getBlockZ()) {
|
||||
&& latestPlayerLocation.getBlockZ() <= northwest.getBlockZ()
|
||||
&& latestPlayerLocation.getBlockZ() >= southeast.getBlockZ()) {
|
||||
return true; // near north wall
|
||||
} else if (Math.abs(northwest.getBlockZ() - latestPlayerLocation.getBlockZ()) < minSafeDistanceFromWall
|
||||
&& latestPlayerLocation.getBlockX() < southeast.getBlockX()
|
||||
&& latestPlayerLocation.getBlockX() > northwest.getBlockX()) {
|
||||
&& latestPlayerLocation.getBlockX() <= southeast.getBlockX()
|
||||
&& latestPlayerLocation.getBlockX() >= northwest.getBlockX()) {
|
||||
return true; // near west wall
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
public Block getNearestWallBlock(Location latestPlayerLocation) {
|
||||
public List<Block> getNearestWallBlocks(Location latestPlayerLocation) {
|
||||
List<Block> nearestWallBlocks = new ArrayList<Block>();
|
||||
if(Math.abs(southeast.getBlockZ() - latestPlayerLocation.getBlockZ()) < minSafeDistanceFromWall
|
||||
&& latestPlayerLocation.getBlockX() <= southeast.getBlockX()
|
||||
&& latestPlayerLocation.getBlockX() >= northwest.getBlockX()) {
|
||||
// near east wall
|
||||
Block eastWallBlock = world.getBlockAt(latestPlayerLocation.getBlockX() + 1, latestPlayerLocation.getBlockY(), southeast.getBlockZ());
|
||||
return eastWallBlock;
|
||||
} else if (Math.abs(southeast.getBlockX() - latestPlayerLocation.getBlockX()) < minSafeDistanceFromWall
|
||||
nearestWallBlocks.add(eastWallBlock);
|
||||
}
|
||||
|
||||
if (Math.abs(southeast.getBlockX() - latestPlayerLocation.getBlockX()) < minSafeDistanceFromWall
|
||||
&& latestPlayerLocation.getBlockZ() <= northwest.getBlockZ()
|
||||
&& latestPlayerLocation.getBlockZ() >= southeast.getBlockZ()) {
|
||||
// near south wall
|
||||
Block southWallBlock = world.getBlockAt(southeast.getBlockX(), latestPlayerLocation.getBlockY() + 1, latestPlayerLocation.getBlockZ());
|
||||
return southWallBlock;
|
||||
} else if (Math.abs(northwest.getBlockX() - latestPlayerLocation.getBlockX()) < minSafeDistanceFromWall
|
||||
nearestWallBlocks.add(southWallBlock);
|
||||
}
|
||||
|
||||
if (Math.abs(northwest.getBlockX() - latestPlayerLocation.getBlockX()) < minSafeDistanceFromWall
|
||||
&& latestPlayerLocation.getBlockZ() <= northwest.getBlockZ()
|
||||
&& latestPlayerLocation.getBlockZ() >= southeast.getBlockZ()) {
|
||||
// near north wall
|
||||
Block northWallBlock = world.getBlockAt(northwest.getBlockX(), latestPlayerLocation.getBlockY() + 1, latestPlayerLocation.getBlockZ());
|
||||
return northWallBlock;
|
||||
} else if (Math.abs(northwest.getBlockZ() - latestPlayerLocation.getBlockZ()) < minSafeDistanceFromWall
|
||||
nearestWallBlocks.add(northWallBlock);
|
||||
}
|
||||
|
||||
if (Math.abs(northwest.getBlockZ() - latestPlayerLocation.getBlockZ()) < minSafeDistanceFromWall
|
||||
&& latestPlayerLocation.getBlockX() <= southeast.getBlockX()
|
||||
&& latestPlayerLocation.getBlockX() >= northwest.getBlockX()) {
|
||||
// near west wall
|
||||
Block westWallBlock = world.getBlockAt(latestPlayerLocation.getBlockX(), latestPlayerLocation.getBlockY() + 1, northwest.getBlockZ());
|
||||
return westWallBlock;
|
||||
nearestWallBlocks.add(westWallBlock);
|
||||
}
|
||||
return null;
|
||||
return nearestWallBlocks;
|
||||
// note: y + 1 to line up 3 sided square with player eyes
|
||||
}
|
||||
|
||||
public BlockFace getNearestWall(Location latestPlayerLocation) {
|
||||
public List<BlockFace> getNearestWalls(Location latestPlayerLocation) {
|
||||
List<BlockFace> walls = new ArrayList<BlockFace>();
|
||||
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
|
||||
walls.add(BlockFace.East);
|
||||
}
|
||||
|
||||
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
|
||||
walls.add(BlockFace.South);
|
||||
}
|
||||
|
||||
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
|
||||
walls.add(BlockFace.North);
|
||||
}
|
||||
|
||||
if (Math.abs(northwest.getBlockZ() - latestPlayerLocation.getBlockZ()) < minSafeDistanceFromWall
|
||||
&& latestPlayerLocation.getBlockX() <= southeast.getBlockX()
|
||||
&& latestPlayerLocation.getBlockX() >= northwest.getBlockX()) {
|
||||
// near west wall
|
||||
return BlockFace.West;
|
||||
walls.add(BlockFace.West);
|
||||
}
|
||||
return null;
|
||||
return walls;
|
||||
}
|
||||
|
||||
public ZoneWallGuard getPlayerZoneWallGuard(String name, BlockFace wall) {
|
||||
@ -552,15 +577,17 @@ public class Warzone {
|
||||
}
|
||||
|
||||
public void protectZoneWallAgainstPlayer(Player player) {
|
||||
BlockFace nearestWall = getNearestWall(player.getLocation());
|
||||
ZoneWallGuard guard = getPlayerZoneWallGuard(player.getName(), nearestWall);
|
||||
if(guard != null) {
|
||||
// already protected, need to move the guard
|
||||
guard.updatePlayerPosition(player.getLocation());
|
||||
} else {
|
||||
// new guard
|
||||
guard = new ZoneWallGuard(player, war, this);
|
||||
zoneWallGuards.add(guard);
|
||||
List<BlockFace> nearestWalls = getNearestWalls(player.getLocation());
|
||||
for(BlockFace wall : nearestWalls) {
|
||||
ZoneWallGuard guard = getPlayerZoneWallGuard(player.getName(), wall);
|
||||
if(guard != null) {
|
||||
// already protected, need to move the guard
|
||||
guard.updatePlayerPosition(player.getLocation());
|
||||
} else {
|
||||
// new guard
|
||||
guard = new ZoneWallGuard(player, war, this, wall);
|
||||
zoneWallGuards.add(guard);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -570,6 +597,9 @@ public class Warzone {
|
||||
if(guard.getPlayer().getName().equals(player.getName())){
|
||||
playerGuards.add(guard);
|
||||
int reset = volume.resetWallBlocks(guard.getWall()); // this should restore old blocks
|
||||
if(drawZoneOutline) {
|
||||
addZoneOutline(guard.getWall());
|
||||
}
|
||||
war.getLogger().info("Reset " + reset + " blocks in " + guard.getWall() + "wall of warzone " + name);
|
||||
}
|
||||
}
|
||||
|
@ -1,5 +1,7 @@
|
||||
package com.tommytony.war;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import org.bukkit.Block;
|
||||
import org.bukkit.BlockFace;
|
||||
import org.bukkit.HumanEntity;
|
||||
@ -21,9 +23,10 @@ public class ZoneWallGuard {
|
||||
private final int radius = 3;
|
||||
|
||||
|
||||
public ZoneWallGuard(Player player, War war, Warzone warzone) {
|
||||
public ZoneWallGuard(Player player, War war, Warzone warzone, BlockFace wall) {
|
||||
this.player = player;
|
||||
this.war = war;
|
||||
this.wall = wall;
|
||||
this.playerLocation = player.getLocation();
|
||||
this.warzone = warzone;
|
||||
this.activate();
|
||||
@ -31,7 +34,7 @@ public class ZoneWallGuard {
|
||||
|
||||
private void activate() {
|
||||
// save current blocks
|
||||
Block nearestWallBlock = warzone.getNearestWallBlock(playerLocation);
|
||||
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();
|
||||
@ -42,51 +45,86 @@ public class ZoneWallGuard {
|
||||
// war.getLogger().info("Warzone wall guard updated: " + saved + " blocks saved for " + player.getName());
|
||||
// }
|
||||
// add wall guard blocks
|
||||
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);
|
||||
|
||||
for(Block block : nearestWallBlocks) {
|
||||
block.setType(Material.Glass);
|
||||
block.getFace(BlockFace.Up).setType(Material.Glass);
|
||||
block.getFace(BlockFace.Down).setType(Material.Glass);
|
||||
if(this.wall == BlockFace.North && warzone.getVolume().isNorthWallBlock(block)) {
|
||||
toGlass(block.getFace(BlockFace.East), BlockFace.North);
|
||||
toGlass(block.getFace(BlockFace.East).getFace(BlockFace.Up), BlockFace.North);
|
||||
toGlass(block.getFace(BlockFace.East).getFace(BlockFace.Down), BlockFace.North);
|
||||
toGlass(block.getFace(BlockFace.West), BlockFace.North);
|
||||
toGlass(block.getFace(BlockFace.West).getFace(BlockFace.Up), BlockFace.North);
|
||||
toGlass(block.getFace(BlockFace.West).getFace(BlockFace.Down), BlockFace.North);
|
||||
} else if(this.wall == BlockFace.South && warzone.getVolume().isSouthWallBlock(block)) {
|
||||
toGlass(block.getFace(BlockFace.East), BlockFace.South);
|
||||
toGlass(block.getFace(BlockFace.East).getFace(BlockFace.Up), BlockFace.South);
|
||||
toGlass(block.getFace(BlockFace.East).getFace(BlockFace.Down), BlockFace.South);
|
||||
toGlass(block.getFace(BlockFace.West), BlockFace.South);
|
||||
toGlass(block.getFace(BlockFace.West).getFace(BlockFace.Up), BlockFace.South);
|
||||
toGlass(block.getFace(BlockFace.West).getFace(BlockFace.Down), BlockFace.South);
|
||||
} else if(this.wall == BlockFace.East && warzone.getVolume().isEastWallBlock(block)) {
|
||||
toGlass(block.getFace(BlockFace.North), BlockFace.East);
|
||||
toGlass(block.getFace(BlockFace.North).getFace(BlockFace.Up), BlockFace.East);
|
||||
toGlass(block.getFace(BlockFace.North).getFace(BlockFace.Down), BlockFace.East);
|
||||
toGlass(block.getFace(BlockFace.South), BlockFace.West);
|
||||
toGlass(block.getFace(BlockFace.South).getFace(BlockFace.Up), BlockFace.West);
|
||||
toGlass(block.getFace(BlockFace.South).getFace(BlockFace.Down), BlockFace.West);
|
||||
} else if(this.wall == BlockFace.West && warzone.getVolume().isWestWallBlock(block)) {
|
||||
toGlass(block.getFace(BlockFace.North), BlockFace.West);
|
||||
toGlass(block.getFace(BlockFace.North).getFace(BlockFace.Up), BlockFace.West);
|
||||
toGlass(block.getFace(BlockFace.North).getFace(BlockFace.Down), BlockFace.West);
|
||||
toGlass(block.getFace(BlockFace.South), BlockFace.West);
|
||||
toGlass(block.getFace(BlockFace.South).getFace(BlockFace.Up), BlockFace.West);
|
||||
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) {
|
||||
@ -121,10 +159,6 @@ public class ZoneWallGuard {
|
||||
return player;
|
||||
}
|
||||
|
||||
public void setWall(BlockFace wall) {
|
||||
this.wall = wall;
|
||||
}
|
||||
|
||||
public BlockFace getWall() {
|
||||
return wall;
|
||||
}
|
||||
|
@ -54,6 +54,16 @@ public class WarMapper {
|
||||
}
|
||||
}
|
||||
|
||||
// zone makers
|
||||
String makersStr = warConfig.getString("zoneMakers");
|
||||
String[] makersSplit = makersStr.split(",");
|
||||
war.getZoneMakerNames().clear();
|
||||
for(String makerName : makersSplit) {
|
||||
if(makerName != null && !makerName.equals("")){
|
||||
war.getZoneMakerNames().add(makerName);
|
||||
}
|
||||
}
|
||||
|
||||
// defaultLoadout
|
||||
String defaultLoadoutStr = warConfig.getString("defaultLoadout");
|
||||
String[] defaultLoadoutSplit = defaultLoadoutStr.split(";");
|
||||
@ -73,6 +83,9 @@ public class WarMapper {
|
||||
// defaultFriendlyFire
|
||||
war.setDefaultFriendlyFire(warConfig.getBoolean("defaultFriendlyFire"));
|
||||
|
||||
// defaultDrawZoneOutline
|
||||
war.setDefaultFriendlyFire(warConfig.getBoolean("defaultDrawZoneOutline"));
|
||||
|
||||
warConfig.close();
|
||||
war.getLogger().info("Loaded war config.");
|
||||
}
|
||||
@ -88,6 +101,13 @@ public class WarMapper {
|
||||
}
|
||||
warConfig.setString("warzones", warzonesStr);
|
||||
|
||||
// zone makers: default is none and it means everyone can use /setzone
|
||||
String makersStr = ""; // everyone
|
||||
for(String name : war.getZoneMakerNames()) {
|
||||
makersStr += name + ",";
|
||||
}
|
||||
warConfig.setString("zoneMakers", makersStr);
|
||||
|
||||
// defaultLoadout
|
||||
String defaultLoadoutStr = "";
|
||||
HashMap<Integer, ItemStack> items = war.getDefaultLoadout();
|
||||
@ -103,6 +123,9 @@ public class WarMapper {
|
||||
// defaultFriendlyFire
|
||||
warConfig.setBoolean("defaultFriendlyFire", war.getDefaultFriendlyFire());
|
||||
|
||||
// defaultFriendlyFire
|
||||
warConfig.setBoolean("defaultDrawZoneOutline", war.getDefaultDrawZoneOutline());
|
||||
|
||||
warConfig.save();
|
||||
warConfig.close();
|
||||
//war.getLogger().info("Saved war config.");
|
||||
|
@ -149,31 +149,40 @@ public class WarzoneMapper {
|
||||
|
||||
warzoneConfig.close();
|
||||
|
||||
if(loadBlocks) {
|
||||
|
||||
PropertiesFile warzoneBlocksFile = new PropertiesFile(war.getName() + "/warzone-" + warzone.getName() + ".dat");
|
||||
if(loadBlocks && warzone.getNorthwest() != null && warzone.getSoutheast() != null) {
|
||||
|
||||
// zone blocks
|
||||
VerticalVolume zoneVolume = new VerticalVolume("zone", war, warzone);
|
||||
String stateStr = warzoneBlocksFile.getString("zoneBlocks");
|
||||
if(stateStr != null && !stateStr.equals("")) {
|
||||
zoneVolume.blocksFromString(stateStr);
|
||||
warzone.setVolume(zoneVolume);
|
||||
try {
|
||||
zoneVolume.fromDisk();
|
||||
} catch (IOException e) {
|
||||
war.getLogger().warning("Failed to read volume file " + warzone.getVolume().getName() +
|
||||
" for warzone " + warzone.getName() + ". " + e.getClass().getName() + " " + e.getMessage());
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
||||
// monument blocks
|
||||
for(Monument monument: warzone.getMonuments()) {
|
||||
String monumentBlocksStr = warzoneBlocksFile.getString("monument"+monument.getName()+"Blocks");
|
||||
monument.getVolume().blocksFromString(monumentBlocksStr);
|
||||
try {
|
||||
monument.getVolume().fromDisk();
|
||||
} catch (IOException e) {
|
||||
war.getLogger().warning("Failed to read volume file " + warzone.getVolume().getName() +
|
||||
" for warzone " + warzone.getName() + ". " + e.getClass().getName() + " " + e.getMessage());
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
// team spawn blocks
|
||||
for(Team team : warzone.getTeams()) {
|
||||
String teamBlocksStr = warzoneBlocksFile.getString("team"+team.getName()+"Blocks");
|
||||
team.getVolume().blocksFromString(teamBlocksStr);
|
||||
try {
|
||||
team.getVolume().fromDisk();
|
||||
} catch (IOException e) {
|
||||
war.getLogger().warning("Failed to read volume file " + warzone.getVolume().getName() +
|
||||
" for warzone " + warzone.getName() + ". " + e.getClass().getName() + " " + e.getMessage());
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
warzoneBlocksFile.close();
|
||||
//war.getLogger().info("Loaded warzone " + name + " config and blocks.");
|
||||
} else {
|
||||
//war.getLogger().info("Loaded warzone " + name + " config.");
|
||||
@ -253,24 +262,37 @@ public class WarzoneMapper {
|
||||
warzoneConfig.close();
|
||||
|
||||
if(saveBlocks) {
|
||||
(new File(war.getName()+"/"+warzone.getName())).mkdir();
|
||||
// zone blocks
|
||||
PropertiesFile warzoneBlocksFile = new PropertiesFile(war.getName() + "/warzone-" + warzone.getName() + ".dat");
|
||||
warzoneBlocksFile.setString("zoneBlocks", warzone.getVolume().blocksToString()); // oh boy
|
||||
try {
|
||||
warzone.getVolume().toDisk();
|
||||
} catch (IOException e) {
|
||||
war.getLogger().warning("Failed to write volume file " + warzone.getVolume().getName() +
|
||||
" for warzone " + warzone.getName() + ". " + e.getClass().getName() + " " + e.getMessage());
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
||||
// monument blocks
|
||||
for(Monument monument: monuments) {
|
||||
String monumentBlocksStr = monument.getVolume().blocksToString();
|
||||
warzoneBlocksFile.setString("monument"+monument.getName()+"Blocks", monumentBlocksStr);
|
||||
try {
|
||||
monument.getVolume().toDisk();
|
||||
} catch (IOException e) {
|
||||
war.getLogger().warning("Failed to write volume file " + warzone.getVolume().getName() +
|
||||
" for warzone " + warzone.getName() + ". " + e.getClass().getName() + " " + e.getMessage());
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
// team spawn blocks
|
||||
for(Team team : teams) {
|
||||
String teamBlocksStr = team.getVolume().blocksToString();
|
||||
warzoneBlocksFile.setString("team"+team.getName()+"Blocks", teamBlocksStr);
|
||||
try {
|
||||
team.getVolume().toDisk();
|
||||
} catch (IOException e) {
|
||||
war.getLogger().warning("Failed to write volume file " + warzone.getVolume().getName() +
|
||||
" for warzone " + warzone.getName() + ". " + e.getClass().getName() + " " + e.getMessage());
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
warzoneBlocksFile.save();
|
||||
warzoneBlocksFile.close();
|
||||
}
|
||||
|
||||
// if(saveBlocks) {
|
||||
@ -286,12 +308,16 @@ public class WarzoneMapper {
|
||||
if(!deletedConfig) {
|
||||
war.getLogger().warning("Failed to delete file " + war.getName() + "/warzone-"+name+".txt");
|
||||
}
|
||||
File warzoneBlocksFile = new File(war.getName() + "/warzone-" + name + ".dat");
|
||||
boolean deletedData = warzoneBlocksFile.delete();
|
||||
if(!deletedData) {
|
||||
war.getLogger().warning("Failed to delete file " + war.getName() + "/warzone-"+name+".dat");
|
||||
}
|
||||
|
||||
File zoneFolder = new File(war.getName() + "/warzone-" + name);
|
||||
File[] files = zoneFolder.listFiles();
|
||||
for(File file : files) {
|
||||
boolean deletedData = file.delete();
|
||||
if(!deletedData) {
|
||||
war.getLogger().warning(file.getName());
|
||||
}
|
||||
}
|
||||
zoneFolder.delete();
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -83,10 +83,12 @@ public class VerticalVolume extends Volume{
|
||||
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++;
|
||||
}
|
||||
if(oldBlockInfo != null) {
|
||||
Block currentBlock = getWorld().getBlockAt(x, y, z);
|
||||
if(resetBlock(oldBlockInfo, currentBlock)) {
|
||||
noOfResetBlocks++;
|
||||
}
|
||||
}
|
||||
x++;
|
||||
}
|
||||
y++;
|
||||
@ -99,10 +101,12 @@ public class VerticalVolume extends Volume{
|
||||
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++;
|
||||
}
|
||||
if(oldBlockInfo != null) {
|
||||
Block currentBlock = getWorld().getBlockAt(x, y, z);
|
||||
if(resetBlock(oldBlockInfo, currentBlock)) {
|
||||
noOfResetBlocks++;
|
||||
}
|
||||
}
|
||||
x++;
|
||||
}
|
||||
y++;
|
||||
@ -115,10 +119,12 @@ public class VerticalVolume extends Volume{
|
||||
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++;
|
||||
}
|
||||
if(oldBlockInfo != null) {
|
||||
Block currentBlock = getWorld().getBlockAt(x, y, z);
|
||||
if(resetBlock(oldBlockInfo, currentBlock)) {
|
||||
noOfResetBlocks++;
|
||||
}
|
||||
}
|
||||
z++;
|
||||
}
|
||||
y++;
|
||||
@ -131,10 +137,12 @@ public class VerticalVolume extends Volume{
|
||||
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++;
|
||||
}
|
||||
if(oldBlockInfo != null) {
|
||||
Block currentBlock = getWorld().getBlockAt(x, y, z);
|
||||
if(resetBlock(oldBlockInfo, currentBlock)) {
|
||||
noOfResetBlocks++;
|
||||
}
|
||||
}
|
||||
z++;
|
||||
}
|
||||
y++;
|
||||
@ -142,7 +150,7 @@ public class VerticalVolume extends Volume{
|
||||
}
|
||||
}
|
||||
} catch (Exception e) {
|
||||
this.getWar().getLogger().warning(getWar().str("Failed to reset wall " + wall + " in volume " + getName() + ". " + e.getMessage()));
|
||||
this.getWar().getLogger().warning("Failed to reset wall " + wall + " in volume " + getName() + ". " + e.getClass().toString() + " " + e.getMessage());
|
||||
}
|
||||
return noOfResetBlocks;
|
||||
}
|
||||
|
@ -1,7 +1,18 @@
|
||||
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.Location;
|
||||
import org.bukkit.Material;
|
||||
@ -96,9 +107,9 @@ public class Volume {
|
||||
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]);
|
||||
currentSign.setLine(1, oldBlockInfo.getSignLines()[1]);
|
||||
currentSign.setLine(2, oldBlockInfo.getSignLines()[2]);
|
||||
currentSign.setLine(3, oldBlockInfo.getSignLines()[3]);
|
||||
state.update();
|
||||
}
|
||||
noOfResetBlocks++;
|
||||
@ -111,7 +122,7 @@ public class Volume {
|
||||
}
|
||||
}
|
||||
} catch (Exception e) {
|
||||
this.getWar().getLogger().warning(getWar().str("Failed to reset volume " + getName() + " blocks. " + e.getMessage()));
|
||||
this.getWar().getLogger().warning(getWar().str("Failed to reset volume " + getName() + " blocks. " + e.getClass().toString() + " " + e.getMessage()));
|
||||
}
|
||||
return noOfResetBlocks;
|
||||
}
|
||||
@ -194,68 +205,170 @@ public class Volume {
|
||||
return blockInfos;
|
||||
}
|
||||
|
||||
public String blocksToString() {
|
||||
StringBuilder volumeStringBuilder = new StringBuilder();
|
||||
volumeStringBuilder.append(cornerOne.getX() + "," + cornerOne.getY() + "," + cornerOne.getZ() + ";");
|
||||
volumeStringBuilder.append(cornerTwo.getX() + "," + cornerTwo.getY() + "," + cornerTwo.getZ() + ";");
|
||||
|
||||
for(int i = 0; i < getSizeX(); i++){
|
||||
for(int j = 0; j < getSizeY(); j++) {
|
||||
for(int k = 0; k < getSizeZ(); k++) {
|
||||
BlockInfo info = getBlockInfos()[i][j][k];
|
||||
volumeStringBuilder.append(info.getTypeID() + "," + info.getData() + "," + info.getSignLines()[0]);
|
||||
if(info.getType() == Material.Sign || info.getType() == Material.SignPost) {
|
||||
String[] lines = info.getSignLines();
|
||||
volumeStringBuilder.append(lines[0] + "\n");
|
||||
volumeStringBuilder.append(lines[1] + "\n");
|
||||
volumeStringBuilder.append(lines[2] + "\n");
|
||||
volumeStringBuilder.append(lines[3] + "\n");
|
||||
// public String blocksToString() {
|
||||
// if(hasTwoCorners() && blockInfos != null) {
|
||||
// StringBuilder volumeStringBuilder = new StringBuilder();
|
||||
// volumeStringBuilder.append(cornerOne.getX() + "," + cornerOne.getY() + "," + cornerOne.getZ() + ";");
|
||||
// volumeStringBuilder.append(cornerTwo.getX() + "," + cornerTwo.getY() + "," + cornerTwo.getZ() + ";");
|
||||
//
|
||||
// for(int i = 0; i < getSizeX(); i++){
|
||||
// for(int j = 0; j < getSizeY(); j++) {
|
||||
// for(int k = 0; k < getSizeZ(); k++) {
|
||||
// BlockInfo info = getBlockInfos()[i][j][k];
|
||||
// if(info == null) {
|
||||
// volumeStringBuilder.append("0,0,");
|
||||
// } else {
|
||||
// volumeStringBuilder.append(info.getTypeID() + "," + info.getData() + ",");
|
||||
// if(info.getType() == Material.Sign || info.getType() == Material.SignPost) {
|
||||
// String[] lines = info.getSignLines();
|
||||
// volumeStringBuilder.append(lines[0] + "\n");
|
||||
// volumeStringBuilder.append(lines[1] + "\n");
|
||||
// volumeStringBuilder.append(lines[2] + "\n");
|
||||
// volumeStringBuilder.append(lines[3] + "\n");
|
||||
// }
|
||||
// }
|
||||
//
|
||||
// volumeStringBuilder.append(";");
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
// return volumeStringBuilder.toString();
|
||||
// }
|
||||
// return "";
|
||||
// }
|
||||
|
||||
// public void blocksFromString(String volumeString) {
|
||||
// Scanner scanner = new Scanner(volumeString);
|
||||
// int x1 = 0;
|
||||
// if(scanner.hasNext(".+,")) x1 = Integer.parseInt(scanner.next(".+,").replace(",", ""));
|
||||
// int y1 = 0;
|
||||
// if(scanner.hasNext(".+,")) y1 = Integer.parseInt(scanner.next(".+,").replace(",", ""));
|
||||
// int z1 = 0;
|
||||
// if(scanner.hasNext(".+,")) z1 = Integer.parseInt(scanner.next(".+,").replace(",", ""));
|
||||
// if(scanner.hasNext(";")) scanner.next(";");
|
||||
// cornerOne = getWorld().getBlockAt(x1, y1, z1);
|
||||
//
|
||||
// int x2 = 0;
|
||||
// if(scanner.hasNext(".+,")) x2 = Integer.parseInt(scanner.next(".+,").replace(",", ""));
|
||||
// int y2 = 0;
|
||||
// if(scanner.hasNext(".+,")) y2 = Integer.parseInt(scanner.next(".+,").replace(",", ""));
|
||||
// int z2 = 0;
|
||||
// if(scanner.hasNext(".+,")) z2 = Integer.parseInt(scanner.next(".+,").replace(",", ""));
|
||||
// if(scanner.hasNext(";")) scanner.next(";");
|
||||
// cornerTwo = getWorld().getBlockAt(x2, y2, z2);
|
||||
//
|
||||
// setBlockInfos(new BlockInfo[getSizeX()][getSizeY()][getSizeZ()]);
|
||||
// for(int i = 0; i < getSizeX(); i++){
|
||||
// for(int j = 0; j < getSizeY(); j++) {
|
||||
// for(int k = 0; k < getSizeZ(); k++) {
|
||||
// int typeID = 0;
|
||||
// if(scanner.hasNext(".+,")) typeID = Integer.parseInt(scanner.next(".+,").replace(",", ""));
|
||||
// byte data = 0;
|
||||
// if(scanner.hasNext(".+,")) data = Byte.parseByte(scanner.next(".+,").replace(",", ""));
|
||||
// String[] lines = null;
|
||||
// if(typeID == Material.Sign.getID() || typeID == Material.SignPost.getID()) {
|
||||
// lines = new String[4];
|
||||
// if(scanner.hasNextLine()) lines[0] = scanner.nextLine();
|
||||
// if(scanner.hasNextLine()) lines[1] = scanner.nextLine();
|
||||
// if(scanner.hasNextLine()) lines[2] = scanner.nextLine();
|
||||
// if(scanner.hasNextLine()) lines[3] = scanner.nextLine();
|
||||
// }
|
||||
// if(scanner.hasNext(";")) scanner.next(";");
|
||||
// getBlockInfos()[i][j][k] = new BlockInfo(typeID, data, lines);
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
|
||||
public void fromDisk() throws IOException {
|
||||
BufferedReader in = null;
|
||||
try {
|
||||
in = new BufferedReader(new FileReader(new File(war.getName() + "/warzone-" + warzone.getName() + "/" + name)));
|
||||
;
|
||||
String firstLine = in.readLine();
|
||||
if(firstLine != null && !firstLine.equals("")) {
|
||||
int x1 = Integer.parseInt(in.readLine());
|
||||
int y1 = Integer.parseInt(in.readLine());
|
||||
int z1 = Integer.parseInt(in.readLine());
|
||||
int x2 = Integer.parseInt(in.readLine());
|
||||
int y2 = Integer.parseInt(in.readLine());
|
||||
int z2 = Integer.parseInt(in.readLine());
|
||||
cornerOne = getWorld().getBlockAt(x1, y1, z1);
|
||||
cornerTwo = getWorld().getBlockAt(x2, y2, z2);
|
||||
|
||||
setBlockInfos(new BlockInfo[getSizeX()][getSizeY()][getSizeZ()]);
|
||||
for(int i = 0; i < getSizeX(); i++){
|
||||
for(int j = 0; j < getSizeY(); j++) {
|
||||
for(int k = 0; k < getSizeZ(); k++) {
|
||||
String blockLine = in.readLine();
|
||||
String[] blockSplit = blockLine.split(",");
|
||||
|
||||
int typeID = Integer.parseInt(blockSplit[0]);
|
||||
byte data = Byte.parseByte(blockSplit[1]);
|
||||
String[] lines = null;
|
||||
if(typeID == Material.Sign.getID() || typeID == Material.SignPost.getID()) {
|
||||
String signLines = blockSplit[2];
|
||||
if(blockSplit.length > 3) {
|
||||
// sign includes commas
|
||||
for(int splitI = 3; splitI < blockSplit.length; splitI++) {
|
||||
signLines.concat(blockSplit[splitI]);
|
||||
}
|
||||
}
|
||||
String[] signLinesSplit = signLines.split("[line]");
|
||||
lines = new String[4];
|
||||
lines[0] = signLinesSplit[0];
|
||||
lines[1] = signLinesSplit[1];
|
||||
lines[2] = signLinesSplit[2];
|
||||
lines[3] = signLinesSplit[3];
|
||||
}
|
||||
getBlockInfos()[i][j][k] = new BlockInfo(typeID, data, lines);
|
||||
}
|
||||
}
|
||||
volumeStringBuilder.append(";");
|
||||
}
|
||||
}
|
||||
} finally {
|
||||
if(in != null) in.close();
|
||||
}
|
||||
return volumeStringBuilder.toString();
|
||||
}
|
||||
|
||||
public void blocksFromString(String volumeString) {
|
||||
Scanner scanner = new Scanner(volumeString);
|
||||
int x1 = scanner.nextInt();
|
||||
scanner.next(",");
|
||||
int y1 = scanner.nextInt();
|
||||
scanner.next(",");
|
||||
int z1 = scanner.nextInt();
|
||||
scanner.next(";");
|
||||
cornerOne = getWorld().getBlockAt(x1, y1, z1);
|
||||
int x2 = scanner.nextInt();
|
||||
scanner.next(",");
|
||||
int y2 = scanner.nextInt();
|
||||
scanner.next(",");
|
||||
int z2 = scanner.nextInt();
|
||||
scanner.next(";");
|
||||
cornerOne = getWorld().getBlockAt(x2, y2, z2);
|
||||
|
||||
setBlockInfos(new BlockInfo[getSizeX()][getSizeY()][getSizeZ()]);
|
||||
for(int i = 0; i < getSizeX(); i++){
|
||||
for(int j = 0; j < getSizeY(); j++) {
|
||||
for(int k = 0; k < getSizeZ(); k++) {
|
||||
// scan ne
|
||||
int typeID = scanner.nextInt();
|
||||
scanner.next(",");
|
||||
byte data = scanner.nextByte();
|
||||
String[] lines = null;
|
||||
if(typeID == Material.Sign.getID() || typeID == Material.SignPost.getID()) {
|
||||
scanner.next(",");
|
||||
lines = new String[4];
|
||||
lines[0] = scanner.nextLine();
|
||||
lines[1] = scanner.nextLine();
|
||||
lines[2] = scanner.nextLine();
|
||||
lines[3] = scanner.nextLine();
|
||||
public void toDisk() throws IOException {
|
||||
if(isSaved() && getBlockInfos() != null) {
|
||||
BufferedWriter out = null;
|
||||
try {
|
||||
out = new BufferedWriter(new FileWriter(new File(war.getName() + "/warzone-" + warzone.getName() + "/" + name)));
|
||||
out.write("corner1"); out.newLine();
|
||||
out.write(cornerOne.getX()); out.newLine();
|
||||
out.write(cornerOne.getY()); out.newLine();
|
||||
out.write(cornerOne.getZ()); out.newLine();
|
||||
out.write("corner2"); out.newLine();
|
||||
out.write(cornerTwo.getX()); out.newLine();
|
||||
out.write(cornerTwo.getY()); out.newLine();
|
||||
out.write(cornerTwo.getZ()); out.newLine();
|
||||
|
||||
for(int i = 0; i < getSizeX(); i++){
|
||||
for(int j = 0; j < getSizeY(); j++) {
|
||||
for(int k = 0; k < getSizeZ(); k++) {
|
||||
BlockInfo info = getBlockInfos()[i][j][k];
|
||||
if(info == null) {
|
||||
out.write("0,0,"); out.newLine();
|
||||
} else {
|
||||
if(info.getType() == Material.Sign || info.getType() == Material.SignPost) {
|
||||
String[] lines = info.getSignLines();
|
||||
out.write(info.getTypeID() + "," + info.getData() + "," + lines[0] + "[line]" + lines[1] + "[line]" + lines[2] + "[line]"+ lines[3]);
|
||||
|
||||
} else {
|
||||
out.write(info.getTypeID() + "," + info.getData() + ",");
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
scanner.next(";");
|
||||
getBlockInfos()[i][j][k] = new BlockInfo(typeID, data, lines);
|
||||
}
|
||||
} finally {
|
||||
if(out != null) out.close();
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user