diff --git a/war/src/main/java/com/tommytony/war/Monument.java b/war/src/main/java/com/tommytony/war/Monument.java index 70003cd..e0be5b1 100644 --- a/war/src/main/java/com/tommytony/war/Monument.java +++ b/war/src/main/java/com/tommytony/war/Monument.java @@ -4,7 +4,7 @@ import org.bukkit.*; public class Monument { private Location location; - private int[] initialState = new int[10]; + private int[] initialState = new int[26]; private World world = null; private Team ownerTeam = null; private final String name; @@ -16,16 +16,45 @@ public class Monument { int x = location.getBlockX(); int y = location.getBlockY(); int z = location.getBlockZ(); - getInitialState()[0] = world.getBlockAt(x+1, y-1, z+1).getTypeID(); - getInitialState()[1] = world.getBlockAt(x+1, y-1, z).getTypeID(); - getInitialState()[2] = world.getBlockAt(x+1, y-1, z-1).getTypeID(); - getInitialState()[3] = world.getBlockAt(x, y-1, z+1).getTypeID(); - getInitialState()[4] = world.getBlockAt(x, y-1, z).getTypeID(); - getInitialState()[5] = world.getBlockAt(x, y-1, z-1).getTypeID(); - getInitialState()[6] = world.getBlockAt(x-1, y-1, z+1).getTypeID(); - getInitialState()[7] = world.getBlockAt(x-1, y-1, z).getTypeID(); - getInitialState()[8] = world.getBlockAt(x-1, y-1, z-1).getTypeID(); - getInitialState()[9] = world.getBlockAt(x, y, z).getTypeID(); + + // center + getInitialState()[0] = world.getBlockAt(x, y, z).getTypeID(); + getInitialState()[1] = world.getBlockAt(x, y-1, z).getTypeID(); + + // inner ring + getInitialState()[2] = world.getBlockAt(x+1, y-1, z+1).getTypeID(); + getInitialState()[3] = world.getBlockAt(x+1, y-1, z).getTypeID(); + getInitialState()[4] = world.getBlockAt(x+1, y-1, z-1).getTypeID(); + + getInitialState()[5] = world.getBlockAt(x, y-1, z+1).getTypeID(); + getInitialState()[6] = world.getBlockAt(x, y-1, z-1).getTypeID(); + + getInitialState()[7] = world.getBlockAt(x-1, y-1, z+1).getTypeID(); + getInitialState()[9] = world.getBlockAt(x-1, y-1, z).getTypeID(); + getInitialState()[9] = world.getBlockAt(x-1, y-1, z-1).getTypeID(); + + // outer ring + getInitialState()[10] = world.getBlockAt(x+2, y-1, z+2).getTypeID(); + getInitialState()[11] = world.getBlockAt(x+2, y-1, z+1).getTypeID(); + getInitialState()[12] = world.getBlockAt(x+2, y-1, z).getTypeID(); + getInitialState()[13] = world.getBlockAt(x+2, y-1, z-1).getTypeID(); + getInitialState()[14] = world.getBlockAt(x+2, y-1, z-2).getTypeID(); + + getInitialState()[15] = world.getBlockAt(x-1, y-1, z+2).getTypeID(); + getInitialState()[16] = world.getBlockAt(x-1, y-1, z-2).getTypeID(); + + getInitialState()[17] = world.getBlockAt(x, y-1, z+2).getTypeID(); + getInitialState()[18] = world.getBlockAt(x, y-1, z-2).getTypeID(); + + getInitialState()[19] = world.getBlockAt(x+1, y-1, z+2).getTypeID(); + getInitialState()[20] = world.getBlockAt(x+1, y-1, z-2).getTypeID(); + + getInitialState()[21] = world.getBlockAt(x-2, y-1, z+2).getTypeID(); + getInitialState()[22] = world.getBlockAt(x-2, y-1, z+1).getTypeID(); + getInitialState()[23] = world.getBlockAt(x-2, y-1, z).getTypeID(); + getInitialState()[24] = world.getBlockAt(x-2, y-1, z-1).getTypeID(); + getInitialState()[25] = world.getBlockAt(x-2, y-1, z-2).getTypeID(); + this.reset(); } @@ -58,10 +87,38 @@ public class Monument { public void ignite(Team team) { ownerTeam = team; + int x = location.getBlockX(); + int y = location.getBlockY(); + int z = location.getBlockZ(); + + world.getBlockAt(x+1, y-1, z+1).setType(Material.GlowingRedstoneOre); + world.getBlockAt(x+1, y-1, z).setType(Material.GlowingRedstoneOre); + world.getBlockAt(x+1, y-1, z-1).setType(Material.GlowingRedstoneOre); + + world.getBlockAt(x, y-1, z+1).setType(Material.GlowingRedstoneOre); + world.getBlockAt(x, y-1, z-1).setType(Material.GlowingRedstoneOre); + + world.getBlockAt(x-1, y-1, z+1).setType(Material.GlowingRedstoneOre); + world.getBlockAt(x-1, y-1, z).setType(Material.GlowingRedstoneOre); + world.getBlockAt(x-1, y-1, z-1).setType(Material.GlowingRedstoneOre); } public void smother() { ownerTeam = null; + int x = location.getBlockX(); + int y = location.getBlockY(); + int z = location.getBlockZ(); + world.getBlockAt(x+1, y-1, z+1).setType(Material.CoalOre); + world.getBlockAt(x+1, y-1, z).setType(Material.CoalOre); + world.getBlockAt(x+1, y-1, z-1).setType(Material.CoalOre); + + world.getBlockAt(x, y-1, z+1).setType(Material.CoalOre); + world.getBlockAt(x, y-1, z-1).setType(Material.CoalOre); + + world.getBlockAt(x-1, y-1, z+1).setType(Material.CoalOre); + world.getBlockAt(x-1, y-1, z).setType(Material.CoalOre); + world.getBlockAt(x-1, y-1, z-1).setType(Material.CoalOre); + } public void reset() { @@ -69,32 +126,88 @@ public class Monument { int x = location.getBlockX(); int y = location.getBlockY(); int z = location.getBlockZ(); - world.getBlockAt(x+1, y-1, z+1).setTypeID(49); - world.getBlockAt(x+1, y-1, z).setTypeID(49); - world.getBlockAt(x+1, y-1, z-1).setTypeID(49); - world.getBlockAt(x, y-1, z+1).setTypeID(49); - world.getBlockAt(x, y-1, z).setTypeID(87); - world.getBlockAt(x, y-1, z-1).setTypeID(49); - world.getBlockAt(x-1, y-1, z+1).setTypeID(49); - world.getBlockAt(x-1, y-1, z).setTypeID(49); - world.getBlockAt(x-1, y-1, z-1).setTypeID(49); - world.getBlockAt(x, y, z).setTypeID(0); + + // center + world.getBlockAt(x, y, z).setType(Material.Air); + world.getBlockAt(x, y-1, z).setType(Material.Soil); + + // inner ring + world.getBlockAt(x+1, y-1, z+1).setType(Material.CoalOre); + world.getBlockAt(x+1, y-1, z).setType(Material.CoalOre); + world.getBlockAt(x+1, y-1, z-1).setType(Material.CoalOre); + + world.getBlockAt(x, y-1, z+1).setType(Material.CoalOre); + world.getBlockAt(x, y-1, z-1).setType(Material.CoalOre); + + world.getBlockAt(x-1, y-1, z+1).setType(Material.CoalOre); + world.getBlockAt(x-1, y-1, z).setType(Material.CoalOre); + world.getBlockAt(x-1, y-1, z-1).setType(Material.CoalOre); + + // outer ring + //world.getBlockAt(x+2, y-1, z+2).setType(Material.Obsidian); + world.getBlockAt(x+2, y-1, z+1).setType(Material.Obsidian); + world.getBlockAt(x+2, y-1, z).setType(Material.Obsidian); + world.getBlockAt(x+2, y-1, z-1).setType(Material.Obsidian); + //world.getBlockAt(x+2, y-1, z-2).setType(Material.Obsidian); + + world.getBlockAt(x-1, y-1, z+2).setType(Material.Obsidian); + world.getBlockAt(x-1, y-1, z-2).setType(Material.Obsidian); + + world.getBlockAt(x, y-1, z+2).setType(Material.Obsidian); + world.getBlockAt(x, y-1, z-2).setType(Material.Obsidian); + + world.getBlockAt(x+1, y-1, z+2).setType(Material.Obsidian); + world.getBlockAt(x+1, y-1, z-2).setType(Material.Obsidian); + + //world.getBlockAt(x-2, y-1, z+2).setType(Material.Obsidian); + world.getBlockAt(x-2, y-1, z+1).setType(Material.Obsidian); + world.getBlockAt(x-2, y-1, z).setType(Material.Obsidian); + world.getBlockAt(x-2, y-1, z-1).setType(Material.Obsidian); + //world.getBlockAt(x-2, y-1, z-2).setType(Material.Obsidian); } public void remove() { int x = location.getBlockX(); int y = location.getBlockY(); int z = location.getBlockZ(); - world.getBlockAt(x+1, y-1, z+1).setTypeID(getInitialState()[0]); - world.getBlockAt(x+1, y-1, z).setTypeID(getInitialState()[1]); - world.getBlockAt(x+1, y-1, z-1).setTypeID(getInitialState()[2]); - world.getBlockAt(x, y-1, z+1).setTypeID(getInitialState()[3]); - world.getBlockAt(x, y-1, z).setTypeID(getInitialState()[4]); - world.getBlockAt(x, y-1, z-1).setTypeID(getInitialState()[5]); - world.getBlockAt(x-1, y-1, z+1).setTypeID(getInitialState()[6]); - world.getBlockAt(x-1, y-1, z).setTypeID(getInitialState()[7]); - world.getBlockAt(x-1, y-1, z-1).setTypeID(getInitialState()[8]); - world.getBlockAt(x, y, z).setTypeID(getInitialState()[9]); + + // center + world.getBlockAt(x, y, z).setTypeID(getInitialState()[0]); + world.getBlockAt(x, y - 1, z).setTypeID(getInitialState()[1]); + + // inner ring + world.getBlockAt(x+1, y-1, z+1).setTypeID(getInitialState()[2]); + world.getBlockAt(x+1, y-1, z).setTypeID(getInitialState()[3]); + world.getBlockAt(x+1, y-1, z-1).setTypeID(getInitialState()[4]); + + world.getBlockAt(x, y-1, z+1).setTypeID(getInitialState()[5]); + world.getBlockAt(x, y-1, z-1).setTypeID(getInitialState()[6]); + + world.getBlockAt(x-1, y-1, z+1).setTypeID(getInitialState()[7]); + world.getBlockAt(x-1, y-1, z).setTypeID(getInitialState()[8]); + world.getBlockAt(x-1, y-1, z-1).setTypeID(getInitialState()[9]); + + // outer ring + world.getBlockAt(x+2, y-1, z+2).setTypeID(getInitialState()[10]); + world.getBlockAt(x+2, y-1, z+1).setTypeID(getInitialState()[11]); + world.getBlockAt(x+2, y-1, z).setTypeID(getInitialState()[12]); + world.getBlockAt(x+2, y-1, z-1).setTypeID(getInitialState()[13]); + world.getBlockAt(x+2, y-1, z-2).setTypeID(getInitialState()[14]); + + world.getBlockAt(x-1, y-1, z+2).setTypeID(getInitialState()[15]); + world.getBlockAt(x-1, y-1, z-2).setTypeID(getInitialState()[16]); + + world.getBlockAt(x, y-1, z+2).setTypeID(getInitialState()[17]); + world.getBlockAt(x, y-1, z-2).setTypeID(getInitialState()[18]); + + world.getBlockAt(x+1, y-1, z+2).setTypeID(getInitialState()[19]); + world.getBlockAt(x+1, y-1, z-2).setTypeID(getInitialState()[20]); + + world.getBlockAt(x-2, y-1, z+2).setTypeID(getInitialState()[21]); + world.getBlockAt(x-2, y-1, z+1).setTypeID(getInitialState()[22]); + world.getBlockAt(x-2, y-1, z).setTypeID(getInitialState()[23]); + world.getBlockAt(x-2, y-1, z-1).setTypeID(getInitialState()[24]); + world.getBlockAt(x-2, y-1, z-2).setTypeID(getInitialState()[25]); } public Location getLocation() { @@ -143,7 +256,7 @@ public class Monument { int bx = block.getX(); int by = block.getY(); int bz = block.getZ(); - if((bx == x && by == y && bz == z) || + if(/*(bx == x && by == y && bz == z) ||*/ (bx == x+1 && by == y-1 && bz == z+1) || (bx == x+1 && by == y-1 && bz == z) || (bx == x+1 && by == y-1 && bz == z-1) || diff --git a/war/src/main/java/com/tommytony/war/Volume.java b/war/src/main/java/com/tommytony/war/Volume.java new file mode 100644 index 0000000..fd9f26b --- /dev/null +++ b/war/src/main/java/com/tommytony/war/Volume.java @@ -0,0 +1,160 @@ +package com.tommytony.war; + +import org.bukkit.Block; +import org.bukkit.World; +import org.bukkit.block.Sign; + +public class Volume { + private final String name; + private final World world; + private Block cornerOne; + private Block cornerTwo; + private Block[][][] blocks = null; + private final War war; + + public Volume(String name, War war, World world) { + this.name = name; + this.war = war; + this.world = world; + } + + public boolean hasTwoCorners() { + return cornerOne != null && cornerTwo != null; + } + + public void setCornerOne(Block block) { + this.cornerOne = block; + } + + public boolean saveBlocks() { + try { + if(hasTwoCorners()) { + this.blocks = new Block[getSizeX()][getSizeY()][getSizeZ()]; + int x = getMinX(); + for(int i = 0; i < getSizeX(); i++){ + int y = getMinY(); + for(int j = 0; j < getSizeY(); j++){ + int z = getMinZ(); + for(int k = 0;k < getSizeZ(); k++) { + this.blocks[i][j][k] = world.getBlockAt(x, y, z); + z++; + } + y++; + } + x++; + } + return true; + } + return false; + } catch (Exception e) { + this.war.getLogger().warning(war.str("Failed to save volume " + name + " blocks. " + e.getMessage())); + return false; + } + } + + public boolean resetBlocks() { + try { + if(hasTwoCorners() && blocks != null) { + int x = getMinX(); + for(int i = 0; i < getSizeX(); i++){ + int y = getMinY(); + for(int j = 0; j < getSizeY(); j++){ + int z = getMinZ(); + for(int k = 0;k < getSizeZ(); k++) { + Block oldBlock = blocks[i][j][k]; + Block currentBlock = world.getBlockAt(x, y, z); + currentBlock.setType(oldBlock.getType()); + currentBlock.setData(currentBlock.getData()); + if(oldBlock instanceof Sign) { + Sign oldSign = (Sign) oldBlock; + Sign currentSign = (Sign) currentBlock; + currentSign.setLine(0, oldSign.getLine(0)); + currentSign.setLine(1, oldSign.getLine(1)); + currentSign.setLine(2, oldSign.getLine(2)); + currentSign.setLine(3, oldSign.getLine(3)); + } + z++; + } + y++; + } + x++; + } + return true; + } + return false; + } catch (Exception e) { + this.war.getLogger().warning(war.str("Failed to reset volume " + name + " blocks. " + e.getMessage())); + return false; + } + } + + public void setCornerTwo(Block block) { + this.cornerTwo = block; + } + + public Block getMinXBlock() { + if(cornerOne.getX() < cornerTwo.getX()) return cornerOne; + return cornerTwo; + } + + public Block getMinYBlock() { + if(cornerOne.getY() < cornerTwo.getY()) return cornerOne; + return cornerTwo; + } + + public Block getMinZBlock() { + if(cornerOne.getZ() < cornerTwo.getZ()) return cornerOne; + return cornerTwo; + } + + public int getMinX() { + return getMinXBlock().getX(); + } + + public int getMinY() { + return getMinYBlock().getY(); + } + + public int getMinZ() { + return getMinZBlock().getZ(); + } + + public Block getMaxXBlock() { + if(cornerOne.getX() < cornerTwo.getX()) return cornerTwo; + return cornerOne; + } + + public Block getMaxYBlock() { + if(cornerOne.getY() < cornerTwo.getY()) return cornerTwo; + return cornerOne; + } + + public Block getMaxZBlock() { + if(cornerOne.getZ() < cornerTwo.getZ()) return cornerTwo; + return cornerOne; + } + + public int getMaxX() { + return getMaxXBlock().getX(); + } + + public int getMaxY() { + return getMaxYBlock().getY(); + } + + public int getMaxZ() { + return getMaxZBlock().getZ(); + } + + public int getSizeX() { + return getMaxX() - getMinX(); + } + + public int getSizeY() { + return getMaxY() - getMinY(); + } + + public int getSizeZ() { + return getMaxZ() - getMinZ(); + } +} diff --git a/war/src/main/java/com/tommytony/war/War.java b/war/src/main/java/com/tommytony/war/War.java index 387e0e3..f55a855 100644 --- a/war/src/main/java/com/tommytony/war/War.java +++ b/war/src/main/java/com/tommytony/war/War.java @@ -8,6 +8,8 @@ import org.bukkit.plugin.PluginLoader; import org.bukkit.plugin.PluginManager; import org.bukkit.plugin.java.JavaPlugin; +import com.tommytony.war.mappers.WarMapper; + import java.io.File; import java.util.ArrayList; import java.util.HashMap; @@ -54,6 +56,7 @@ public class War extends JavaPlugin { pm.registerEvent(Event.Type.ENTITY_DEATH, entityListener, Priority.Normal, this); //HEALTH_CHANGE pm.registerEvent(Event.Type.ENTITY_DAMAGEDBY_ENTITY, entityListener, Priority.Normal, this); //DAMAGE + pm.registerEvent(Event.Type.BLOCK_PLACED, blockListener, Priority.Normal, this); pm.registerEvent(Event.Type.BLOCK_IGNITE, blockListener, Priority.Normal, this); pm.registerEvent(Event.Type.BLOCK_FLOW, blockListener, Priority.Normal, this); pm.registerEvent(Event.Type.BLOCK_CANBUILD, blockListener, Priority.Normal, this); // BLOCK_PLACE diff --git a/war/src/main/java/com/tommytony/war/WarBlockListener.java b/war/src/main/java/com/tommytony/war/WarBlockListener.java index 76912f1..8390890 100644 --- a/war/src/main/java/com/tommytony/war/WarBlockListener.java +++ b/war/src/main/java/com/tommytony/war/WarBlockListener.java @@ -3,13 +3,14 @@ package com.tommytony.war; import java.util.List; import org.bukkit.Block; -import org.bukkit.Location; +import org.bukkit.Material; import org.bukkit.Player; import org.bukkit.event.block.BlockBrokenEvent; import org.bukkit.event.block.BlockCanBuildEvent; import org.bukkit.event.block.BlockFromToEvent; import org.bukkit.event.block.BlockIgniteEvent; import org.bukkit.event.block.BlockListener; +import org.bukkit.event.block.BlockPlacedEvent; public class WarBlockListener extends BlockListener { @@ -19,6 +20,30 @@ public class WarBlockListener extends BlockListener { this.war = war; } + public void onBlockPlaced(BlockPlacedEvent event) { + Player player = event.getPlayer(); + Block block = event.getBlock(); + if(player != null) { + Team team = war.getPlayerTeam(player.getName()); + Warzone zone = war.getPlayerWarzone(player.getName()); + if(team != null && block != null && zone != null + && zone.isMonumentCenterBlock(block) + && (block.getType() == Material.YellowFlower || block.getType() == Material.RedRose || block.getType() == Material.Sapling)) { + Monument monument = zone.getMonumentFromCenterBlock(block); + if(!monument.hasOwner()) { + monument.ignite(team); + List teams = zone.getTeams(); + for(Team t : teams) { + t.teamcast(war.str("Monument " + monument.getName() + " has been ignited by team " + team.getName() + ".")); + } + } else { + player.sendMessage(war.str("Monument must be smothered first.")); + } + } + } + } + + public void onBlockBroken(BlockBrokenEvent event) { Player player = event.getPlayer(); Block block = event.getBlock(); @@ -27,7 +52,6 @@ public class WarBlockListener extends BlockListener { if(warzone != null && war.getPlayerTeam(player.getName()) == null) { // can't actually destroy blocks in a warzone if not part of a team player.sendMessage(war.str("Can't destroy part of a warzone if you're not in a team.")); - // BUKKIT // event.setCancelled(true); } @@ -37,49 +61,61 @@ public class WarBlockListener extends BlockListener { // BUKKIT // event.setCancelled(true); } + + Team team = war.getPlayerTeam(player.getName()); + if(team != null && block != null && warzone != null + && warzone.isMonumentCenterBlock(block)){ + Monument monument = warzone.getMonumentFromCenterBlock(block); + if(monument.hasOwner()) { + monument.smother(); + List teams = warzone.getTeams(); + for(Team t : teams) { + t.teamcast(war.str("Monument " + monument.getName() + " has been smothered.")); + } + } + } } } public void onBlockCanBuild(BlockCanBuildEvent event) { // BUKKIT - // Player player = event.getPlayer(); // Block blockPlaced = event.getBlock(); -// Warzone warzone = war.warzone(player.getLocation()); +// +// Warzone warzone = war.warzone(new Location(warblockPlaced.getX()); // if(warzone != null) { // if(warzone.isImportantBlock(blockPlaced) || warzone.isImportantBlock(blockClicked)) { -// player.sendMessage(war.str("Can't build here.")); // event.setCancelled(true); // } // } } public void onBlockFlow(BlockFromToEvent event) { - Block block = null; - Block blockTo = event.getBlock(); - Block blockFrom = event.getFromBlock(); - if(blockTo != null) { - block = blockTo; - } else if (blockFrom != null) { - block = blockFrom; - } - - if(block != null) { - Warzone zone = war.warzone(new Location(block.getWorld(), block.getX(), block.getY(), block.getZ())); - if(zone != null && - ((blockTo != null && zone.isMonumentFirestone(blockTo) - || (blockFrom != null && zone.isMonumentFirestone(blockFrom))))) { - Monument monument = null; - if(blockTo != null) monument = zone.getMonumentForFirestone(blockTo); - if(monument == null && blockFrom != null) monument = zone.getMonumentForFirestone(blockFrom); - if(monument.hasOwner()) { - monument.setOwnerTeam(null); - List teams = zone.getTeams(); - for(Team team : teams) { - team.teamcast(war.str("Monument " + monument.getName() + " has been smothered.")); - } - } - } - } +// Block block = null; +// Block blockTo = event.getBlock(); +// Block blockFrom = event.getFromBlock(); +// if(blockTo != null) { +// block = blockTo; +// } else if (blockFrom != null) { +// block = blockFrom; +// } +// +// if(block != null) { +// Warzone zone = war.warzone(new Location(block.getWorld(), block.getX(), block.getY(), block.getZ())); +// if(zone != null && +// ((blockTo != null && zone.isMonumentCenterBlock(blockTo) +// || (blockFrom != null && zone.isMonumentCenterBlock(blockFrom))))) { +// Monument monument = null; +// if(blockTo != null) monument = zone.getMonumentFromCenterBlock(blockTo); +// if(monument == null && blockFrom != null) monument = zone.getMonumentFromCenterBlock(blockFrom); +// if(monument.hasOwner()) { +// monument.setOwnerTeam(null); +// List teams = zone.getTeams(); +// for(Team team : teams) { +// team.teamcast(war.str("Monument " + monument.getName() + " has been smothered.")); +// } +// } +// } +// } } public void onBlockIgnite(BlockIgniteEvent event) { diff --git a/war/src/main/java/com/tommytony/war/WarPlayerListener.java b/war/src/main/java/com/tommytony/war/WarPlayerListener.java index 3f07595..b832bd4 100644 --- a/war/src/main/java/com/tommytony/war/WarPlayerListener.java +++ b/war/src/main/java/com/tommytony/war/WarPlayerListener.java @@ -10,6 +10,9 @@ import org.bukkit.event.player.PlayerEvent; import org.bukkit.event.player.PlayerListener; import org.bukkit.event.player.PlayerMoveEvent; +import com.tommytony.war.mappers.WarMapper; +import com.tommytony.war.mappers.WarzoneMapper; + public class WarPlayerListener extends PlayerListener { diff --git a/war/src/main/java/com/tommytony/war/Warzone.java b/war/src/main/java/com/tommytony/war/Warzone.java index fc95705..6239df3 100644 --- a/war/src/main/java/com/tommytony/war/Warzone.java +++ b/war/src/main/java/com/tommytony/war/Warzone.java @@ -257,7 +257,7 @@ public class Warzone { player.teleportTo(team.getTeamSpawn()); } - public boolean isMonumentFirestone(Block block) { + public boolean isMonumentCenterBlock(Block block) { for(Monument monument : monuments) { int x = monument.getLocation().getBlockX(); int y = monument.getLocation().getBlockY(); @@ -269,7 +269,7 @@ public class Warzone { return false; } - public Monument getMonumentForFirestone(Block block) { + public Monument getMonumentFromCenterBlock(Block block) { for(Monument monument : monuments) { int x = monument.getLocation().getBlockX(); int y = monument.getLocation().getBlockY(); @@ -296,47 +296,128 @@ public class Warzone { int x = (int)team.getTeamSpawn().getBlockX(); int y = (int)team.getTeamSpawn().getBlockY(); int z = (int)team.getTeamSpawn().getBlockZ(); - world.getBlockAt(x+1, y-1, z+1).setTypeID(spawnState[0]); - world.getBlockAt(x+1, y-1, z).setTypeID(spawnState[1]); - world.getBlockAt(x+1, y-1, z-1).setTypeID(spawnState[2]); - world.getBlockAt(x, y-1, z+1).setTypeID(spawnState[3]); - world.getBlockAt(x, y-1, z).setTypeID(spawnState[4]); - world.getBlockAt(x, y-1, z-1).setTypeID(spawnState[5]); - world.getBlockAt(x-1, y-1, z+1).setTypeID(spawnState[6]); - world.getBlockAt(x-1, y-1, z).setTypeID(spawnState[7]); - world.getBlockAt(x-1, y-1, z-1).setTypeID(spawnState[8]); - world.getBlockAt(x, y, z).setTypeID(spawnState[9]); + + // center + world.getBlockAt(x, y, z).setTypeID(spawnState[0]); + world.getBlockAt(x, y-1, z).setTypeID(spawnState[1]); + + // inner ring + world.getBlockAt(x+1, y-1, z+1).setTypeID(spawnState[2]); + world.getBlockAt(x+1, y-1, z).setTypeID(spawnState[3]); + world.getBlockAt(x+1, y-1, z-1).setTypeID(spawnState[4]); + + world.getBlockAt(x, y-1, z+1).setTypeID(spawnState[5]); + world.getBlockAt(x, y-1, z-1).setTypeID(spawnState[6]); + + world.getBlockAt(x-1, y-1, z+1).setTypeID(spawnState[7]); + world.getBlockAt(x-1, y-1, z).setTypeID(spawnState[8]); + world.getBlockAt(x-1, y-1, z-1).setTypeID(spawnState[9]); + + // outer ring + world.getBlockAt(x+2, y-1, z+2).setTypeID(spawnState[10]); + world.getBlockAt(x+2, y-1, z+1).setTypeID(spawnState[11]); + world.getBlockAt(x+2, y-1, z).setTypeID(spawnState[12]); + world.getBlockAt(x+2, y-1, z-1).setTypeID(spawnState[13]); + world.getBlockAt(x+2, y-1, z-2).setTypeID(spawnState[14]); + + world.getBlockAt(x-1, y-1, z+2).setTypeID(spawnState[15]); + world.getBlockAt(x-1, y-1, z-2).setTypeID(spawnState[16]); + + world.getBlockAt(x, y-1, z+2).setTypeID(spawnState[17]); + world.getBlockAt(x, y-1, z-2).setTypeID(spawnState[18]); + + world.getBlockAt(x+1, y-1, z+2).setTypeID(spawnState[19]); + world.getBlockAt(x+1, y-1, z-2).setTypeID(spawnState[20]); + + world.getBlockAt(x-2, y-1, z+2).setTypeID(spawnState[21]); + world.getBlockAt(x-2, y-1, z+1).setTypeID(spawnState[22]); + world.getBlockAt(x-2, y-1, z).setTypeID(spawnState[23]); + world.getBlockAt(x-2, y-1, z-1).setTypeID(spawnState[24]); + world.getBlockAt(x-2, y-1, z-2).setTypeID(spawnState[25]); } public void addSpawnArea(Team team, Location location, int blockType) { // Save the spawn state (i.e. the nine block under the player spawn) - int[] spawnState = new int[10]; + int[] spawnState = new int[26]; int x = location.getBlockX(); int y = location.getBlockY(); int z = location.getBlockZ(); - spawnState[0] = world.getBlockAt(x+1, y-1, z+1).getTypeID(); - spawnState[1] = world.getBlockAt(x+1, y-1, z).getTypeID(); - spawnState[2] = world.getBlockAt(x+1, y-1, z-1).getTypeID(); - spawnState[3] = world.getBlockAt(x, y-1, z+1).getTypeID(); - spawnState[4] = world.getBlockAt(x, y-1, z).getTypeID(); - spawnState[5] = world.getBlockAt(x, y-1, z-1).getTypeID(); - spawnState[6] = world.getBlockAt(x-1, y-1, z+1).getTypeID(); - spawnState[7] = world.getBlockAt(x-1, y-1, z).getTypeID(); - spawnState[8] = world.getBlockAt(x-1, y-1, z-1).getTypeID(); - spawnState[9] = world.getBlockAt(x, y, z).getTypeID(); + // center + spawnState[0] = world.getBlockAt(x, y, z).getTypeID(); + spawnState[1] = world.getBlockAt(x, y-1, z).getTypeID(); + + // inner ring + spawnState[2] = world.getBlockAt(x+1, y-1, z+1).getTypeID(); + spawnState[3] = world.getBlockAt(x+1, y-1, z).getTypeID(); + spawnState[4] = world.getBlockAt(x+1, y-1, z-1).getTypeID(); + + spawnState[5] = world.getBlockAt(x, y-1, z+1).getTypeID(); + spawnState[6] = world.getBlockAt(x, y-1, z-1).getTypeID(); + + spawnState[7] = world.getBlockAt(x-1, y-1, z+1).getTypeID(); + spawnState[8] = world.getBlockAt(x-1, y-1, z).getTypeID(); + spawnState[9] = world.getBlockAt(x-1, y-1, z-1).getTypeID(); + + // outer ring + spawnState[10] = world.getBlockAt(x+2, y-1, z+2).getTypeID(); + spawnState[11] = world.getBlockAt(x+2, y-1, z+1).getTypeID(); + spawnState[12] = world.getBlockAt(x+2, y-1, z).getTypeID(); + spawnState[13] = world.getBlockAt(x+2, y-1, z-1).getTypeID(); + spawnState[14] = world.getBlockAt(x+2, y-1, z-2).getTypeID(); + + spawnState[15] = world.getBlockAt(x-1, y-1, z+2).getTypeID(); + spawnState[16] = world.getBlockAt(x-1, y-1, z-2).getTypeID(); + + spawnState[17] = world.getBlockAt(x, y-1, z+2).getTypeID(); + spawnState[18] = world.getBlockAt(x, y-1, z-2).getTypeID(); + + spawnState[19] = world.getBlockAt(x+1, y-1, z+2).getTypeID(); + spawnState[20] = world.getBlockAt(x+1, y-1, z-2).getTypeID(); + + spawnState[21] = world.getBlockAt(x-2, y-1, z+2).getTypeID(); + spawnState[22] = world.getBlockAt(x-2, y-1, z+1).getTypeID(); + spawnState[23] = world.getBlockAt(x-2, y-1, z).getTypeID(); + spawnState[24] = world.getBlockAt(x-2, y-1, z-1).getTypeID(); + spawnState[25] = world.getBlockAt(x-2, y-1, z-2).getTypeID(); + team.setTeamSpawn(location); team.setOldSpawnState(spawnState); - // Set the spawn as gold blocks - world.getBlockAt(x+1, y-1, z+1); - world.getBlockAt(x+1, y-1, z); - world.getBlockAt(x+1, y-1, z-1); - world.getBlockAt(x, y-1, z+1); - world.getBlockAt(x, y-1, z); - world.getBlockAt(x, y-1, z-1); - world.getBlockAt(x-1, y-1, z+1); - world.getBlockAt(x-1, y-1, z); - world.getBlockAt(x-1, y-1, z-1); + + // Set the spawn + + // first ring + world.getBlockAt(x+1, y-1, z+1).setType(Material.LightStone); + world.getBlockAt(x+1, y-1, z).setType(Material.LightStone); + world.getBlockAt(x+1, y-1, z-1).setType(Material.LightStone); + world.getBlockAt(x, y-1, z+1).setType(Material.LightStone); + world.getBlockAt(x, y-1, z).setType(Material.Stone); + world.getBlockAt(x, y-1, z-1).setType(Material.LightStone); + world.getBlockAt(x-1, y-1, z+1).setType(Material.LightStone); + world.getBlockAt(x-1, y-1, z).setType(Material.LightStone); + world.getBlockAt(x-1, y-1, z-1).setType(Material.LightStone); + + // outer ring + //world.getBlockAt(x+2, y-1, z+2).setType(Material.Stone); + world.getBlockAt(x+2, y-1, z+1).setType(Material.Stone); + world.getBlockAt(x+2, y-1, z).setType(Material.Stone); + world.getBlockAt(x+2, y-1, z-1).setType(Material.Stone); + //world.getBlockAt(x+2, y-1, z-2).setType(Material.Stone); + + world.getBlockAt(x-1, y-1, z+2).setType(Material.Stone); + world.getBlockAt(x-1, y-1, z-2).setType(Material.Stone); + + world.getBlockAt(x, y-1, z+2).setType(Material.Stone); + world.getBlockAt(x, y-1, z-2).setType(Material.Stone); + + world.getBlockAt(x+1, y-1, z+2).setType(Material.Stone); + world.getBlockAt(x+1, y-1, z-2).setType(Material.Stone); + + //world.getBlockAt(x-2, y-1, z+2).setType(Material.Stone); + world.getBlockAt(x-2, y-1, z+1).setType(Material.Stone); + world.getBlockAt(x-2, y-1, z).setType(Material.Stone); + world.getBlockAt(x-2, y-1, z-1).setType(Material.Stone); + //world.getBlockAt(x-2, y-1, z-2).setType(Material.Stone); resetSign(team); } diff --git a/war/src/main/java/com/tommytony/war/mappers/BlockMapper.java b/war/src/main/java/com/tommytony/war/mappers/BlockMapper.java new file mode 100644 index 0000000..c85d55b --- /dev/null +++ b/war/src/main/java/com/tommytony/war/mappers/BlockMapper.java @@ -0,0 +1,17 @@ +package com.tommytony.war.mappers; + +import org.bukkit.Block; +import org.bukkit.World; + +import com.tommytony.war.Volume; +import com.tommytony.war.War; + +public class BlockMapper { + public static Block load(War war, World world, String key) { + return null; + } + + public static void save(War war, Volume volume) { + + } +} diff --git a/war/src/main/java/com/tommytony/war/mappers/WarMapper.java b/war/src/main/java/com/tommytony/war/mappers/WarMapper.java new file mode 100644 index 0000000..5acbc4e --- /dev/null +++ b/war/src/main/java/com/tommytony/war/mappers/WarMapper.java @@ -0,0 +1,101 @@ +package com.tommytony.war.mappers; +import java.io.File; +import java.io.IOException; + +import com.tommytony.war.PropertiesFile; +import com.tommytony.war.War; +import com.tommytony.war.Warzone; + + +public class WarMapper { + + public static void load(War war) { + war.getLogger().info("Loading war config..."); + (new File(war.getName())).mkdir(); + PropertiesFile warConfig = new PropertiesFile(war.getName() + "/war.txt"); + try { + warConfig.load(); + } catch (IOException e) { + war.getLogger().info("Failed to load war.txt file."); + e.printStackTrace(); + } + + // Create file if need be + boolean newWar = false; + if(!warConfig.containsKey("warzones")) { + newWar = true; + WarMapper.save(war); + war.getLogger().info("War config file created."); + try { + warConfig.load(); + } catch (IOException e) { + war.getLogger().info("Failed to reload war.txt file after creating it."); + e.printStackTrace(); + } + } + + // warzones + String warzonesStr = warConfig.getString("warzones"); + String[] warzoneSplit = warzonesStr.split(","); + war.getWarzones().clear(); + for(String warzoneName : warzoneSplit) { + if(warzoneName != null && !warzoneName.equals("")){ + Warzone zone = WarzoneMapper.load(war, warzoneName, !newWar); // cascade load, only load blocks if warzone exists + war.getWarzones().add(zone); + zone.resetState(); // is this wise? + } + } + + // defaultLoadout +// String defaultLoadoutStr = warConfig.getString("defaultLoadout"); +// String[] defaultLoadoutSplit = defaultLoadoutStr.split(";"); +// war.getDefaultLoadout().clear(); +// for(String itemStr : defaultLoadoutSplit) { +// if(itemStr != null && !itemStr.equals("")) { +// String[] itemStrSplit = itemStr.split(","); +// ItemStack item = new ItemStack(Integer.parseInt(itemStrSplit[0]), +// Integer.parseInt(itemStrSplit[1])); +// war.getDefaultLoadout().add(item); +// } +// } + + // defaultLifePool + war.setDefaultLifepool(warConfig.getInt("defaultLifePool")); + + // defaultFriendlyFire + war.setDefaultFriendlyFire(warConfig.getBoolean("defaultFriendlyFire")); + + warConfig.close(); + war.getLogger().info("Loaded war config."); + } + + public static void save(War war) { + war.getLogger().info("Saving war config..."); + PropertiesFile warConfig = new PropertiesFile(war.getName() + "/war.txt"); + String warzonesStr = ""; + + // warzones + for(Warzone zone : war.getWarzones()) { + warzonesStr += zone.getName() + ","; + } + warConfig.setString("warzones", warzonesStr); + + // defaultLoadout +// String defaultLoadoutStr = ""; +// List items = war.getDefaultLoadout(); +// for(Item item : items) { +// defaultLoadoutStr += item.getItemId() + "," + item.getAmount() + "," + item.getSlot() + ";"; +// } +// warConfig.setString("defaultLoadout", defaultLoadoutStr); + + // defaultLifepool + warConfig.setInt("defaultLifePool", war.getDefaultLifepool()); + + // defaultFriendlyFire + warConfig.setBoolean("defaultFriendlyFire", war.getDefaultFriendlyFire()); + + warConfig.save(); + warConfig.close(); + war.getLogger().info("Saved war config."); + } +} diff --git a/war/src/main/java/com/tommytony/war/mappers/WarzoneMapper.java b/war/src/main/java/com/tommytony/war/mappers/WarzoneMapper.java new file mode 100644 index 0000000..e8eef0a --- /dev/null +++ b/war/src/main/java/com/tommytony/war/mappers/WarzoneMapper.java @@ -0,0 +1,327 @@ +package com.tommytony.war.mappers; + +import org.bukkit.*; + +import com.tommytony.war.Monument; +import com.tommytony.war.PropertiesFile; +import com.tommytony.war.Team; +import com.tommytony.war.War; +import com.tommytony.war.Warzone; + +import java.io.File; +import java.io.IOException; +import java.util.List; + + +public class WarzoneMapper { + + public static Warzone load(War war, String name, boolean loadBlocks) { + war.getLogger().info("Loading warzone " + name + " config and blocks..."); + PropertiesFile warzoneConfig = new PropertiesFile(war.getName() + "/warzone-" + name + ".txt"); + try { + warzoneConfig.load(); + } catch (IOException e) { + war.getLogger().info("Failed to load warzone-" + name + ".txt file."); + e.printStackTrace(); + } + + World[] worlds = war.getServer().getWorlds(); + World world = worlds[0]; + Warzone warzone = new Warzone(war, world, name); + + // Create file if needed + if(!warzoneConfig.containsKey("name")) { + WarzoneMapper.save(war, warzone, false); + war.getLogger().info("Warzone " + name + " config file created."); + try { + warzoneConfig.load(); + } catch (IOException e) { + war.getLogger().info("Failed to reload warzone-" + name + ".txt file after creating it."); + e.printStackTrace(); + } + } + + // world + String worldStr = warzoneConfig.getProperty("world"); + + warzone.setWorld(world); // default world for now + + // northwest + String nwStr = warzoneConfig.getString("northWest"); + String[] nwStrSplit = nwStr.split(","); + int nwX = Integer.parseInt(nwStrSplit[0]); + int nwY = Integer.parseInt(nwStrSplit[1]); + int nwZ = Integer.parseInt(nwStrSplit[2]); + Location nw = new Location(world, nwX, nwY, nwZ); + warzone.setNorthwest(nw); + + // southeast + String seStr = warzoneConfig.getString("southEast"); + String[] seStrSplit = seStr.split(","); + int seX = Integer.parseInt(seStrSplit[0]); + int seY = Integer.parseInt(seStrSplit[1]); + int seZ = Integer.parseInt(seStrSplit[2]); + Location se = new Location(world, seX, seY, seZ); + warzone.setSoutheast(se); + + // teleport + String teleportStr = warzoneConfig.getString("teleport"); + if(teleportStr != null && !teleportStr.equals("")) { + String[] teleportSplit = teleportStr.split(","); + int teleX = Integer.parseInt(teleportSplit[0]); + int teleY = Integer.parseInt(teleportSplit[1]); + int teleZ = Integer.parseInt(teleportSplit[2]); + warzone.setTeleport(new Location(world, teleX, teleY, teleZ)); + } + + // teams + String teamsStr = warzoneConfig.getString("teams"); + String[] teamsSplit = teamsStr.split(";"); + warzone.getTeams().clear(); + for(String teamStr : teamsSplit) { + if(teamStr != null && !teamStr.equals("")){ + String[] teamStrSplit = teamStr.split(","); + int teamX = Integer.parseInt(teamStrSplit[1]); + int teamY = Integer.parseInt(teamStrSplit[2]); + int teamZ = Integer.parseInt(teamStrSplit[3]); + Team team = new Team(teamStrSplit[0], + new Location(world, teamX, teamY, teamZ)); + team.setRemainingTickets(warzone.getLifePool()); + warzone.getTeams().add(team); + } + } + + // ff + warzone.setFriendlyFire(warzoneConfig.getBoolean("friendlyFire")); + + // loadout +// String loadoutStr = warzoneConfig.getString("loadout"); +// String[] loadoutStrSplit = loadoutStr.split(";"); +// warzone.getLoadout().clear(); +// for(String itemStr : loadoutStrSplit) { +// if(itemStr != null && !itemStr.equals("")) { +// String[] itemStrSplit = itemStr.split(","); +// Item item = new Item(Integer.parseInt(itemStrSplit[0]), +// Integer.parseInt(itemStrSplit[1]), Integer.parseInt(itemStrSplit[2])); +// warzone.getLoadout().add(item); +// } +// } + + // life pool + warzone.setLifePool(warzoneConfig.getInt("lifePool")); + + // monuments + String monumentsStr = warzoneConfig.getString("monuments"); + String[] monumentsSplit = monumentsStr.split(";"); + warzone.getMonuments().clear(); + for(String monumentStr : monumentsSplit) { + if(monumentStr != null && !monumentStr.equals("")){ + String[] monumentStrSplit = monumentStr.split(","); + int monumentX = Integer.parseInt(monumentStrSplit[1]); + int monumentY = Integer.parseInt(monumentStrSplit[2]); + int monumentZ = Integer.parseInt(monumentStrSplit[3]); + Monument monument = new Monument(monumentStrSplit[0], world, + new Location(world, monumentX, monumentY, monumentZ)); + warzone.getMonuments().add(monument); + } + } + + warzoneConfig.close(); + + if(loadBlocks) { + // zone blocks + PropertiesFile warzoneBlocksFile = new PropertiesFile(war.getName() + "/warzone-" + warzone.getName() + ".dat"); + int northSouth = ((int)(warzone.getSoutheast().getBlockX())) - ((int)(warzone.getNorthwest().getBlockX())); + int eastWest = ((int)(warzone.getNorthwest().getBlockZ())) - ((int)(warzone.getSoutheast().getBlockZ())); + int minY = 0; + int maxY = 128; + int[][][] state = new int[northSouth + 6][128][eastWest + 6]; + String stateStr = warzoneBlocksFile.getString("zoneBlocks"); + String[] stateStrSplit = stateStr.split(","); + int splitIndex = 0; + if(stateStrSplit.length > 1000) { + for(int i = 0; i < northSouth + 3; i++){ + for(int j = 0; j < 128; j++) { + for(int k = 0; k < eastWest + 3; k++) { + String currentBlockType = stateStrSplit[splitIndex]; + if(currentBlockType != null && !currentBlockType.equals("")) { + state[i][j][k] = Integer.parseInt(currentBlockType); + } + splitIndex++; + } + } + } + } + warzone.setInitialState(state); + + // monument blocks + for(Monument monument: warzone.getMonuments()) { + String monumentBlocksStr = warzoneBlocksFile.getString("monument"+monument.getName()+"Blocks"); + String[] monumentBlocksSplit = monumentBlocksStr.split(","); + int[] monumentState = new int[10]; + for(int i = 0; i < monumentBlocksSplit.length; i++) { + String split = monumentBlocksSplit[i]; + if(split != null && !split.equals("")) { + monumentState[i] = Integer.parseInt(split); + } + } + monument.setInitialState(monumentState); + } + + // team spawn blocks + for(Team team : warzone.getTeams()) { + String teamBlocksStr = warzoneBlocksFile.getString("team"+team.getName()+"Blocks"); + String[] teamBlocksSplit = teamBlocksStr.split(","); + int[] teamState = new int[10]; + for(int i = 0; i < teamBlocksSplit.length; i++) { + String split = teamBlocksSplit[i]; + if(split != null && !split.equals("")) { + teamState[i] = Integer.parseInt(split); + } + } + team.setOldSpawnState(teamState); + } + + warzoneBlocksFile.close(); + war.getLogger().info("Loaded warzone " + name + " config and blocks."); + } else { + war.getLogger().info("Loaded warzone " + name + " config."); + } + + return warzone; + + } + + public static void save(War war, Warzone warzone, boolean saveBlocks) { + PropertiesFile warzoneConfig = new PropertiesFile(war.getName() + "/warzone-" + warzone.getName() + ".txt"); + war.getLogger().info("Saving warzone " + warzone.getName() + "..."); + + // name + warzoneConfig.setString("name", warzone.getName()); + + // world + warzoneConfig.setString("world", "world"); // default for now + + // northwest + String nwStr = ""; + Location nw = warzone.getNorthwest(); + if(nw != null) { + nwStr = (int)nw.getBlockX() + "," + (int)nw.getBlockY() + "," + (int)nw.getBlockZ(); + } + warzoneConfig.setString("northWest", nwStr); + + // southeast + String seStr = ""; + Location se = warzone.getSoutheast(); + if(se != null) { + seStr = (int)se.getBlockX() + "," + (int)se.getBlockY() + "," + (int)se.getBlockZ(); + } + warzoneConfig.setString("southEast", seStr); + + // teleport + String teleportStr = ""; + Location tele = warzone.getTeleport(); + if(tele != null) { + teleportStr = (int)tele.getBlockX() + "," + (int)tele.getBlockY() + "," + (int)tele.getBlockZ(); + } + warzoneConfig.setString("teleport", teleportStr); + + // teams + String teamsStr = ""; + List teams = warzone.getTeams(); + for(Team team : teams) { + Location spawn = team.getTeamSpawn(); + teamsStr += team.getName() + "," + (int)spawn.getBlockX() + "," + (int)spawn.getBlockY() + "," + (int)spawn.getBlockZ() + ";"; + } + warzoneConfig.setString("teams", teamsStr); + + // ff + warzoneConfig.setBoolean("firendlyFire", warzone.getFriendlyFire()); + + // loadout +// String loadoutStr = ""; +// List items = warzone.getLoadout(); +// for(Item item : items) { +// loadoutStr += item.getItemId() + "," + item.getAmount() + "," + item.getSlot() + ";"; +// } +// warzoneConfig.setString("loadout", loadoutStr); + + // life pool + warzoneConfig.setInt("lifePool", warzone.getLifePool()); + + // monuments + String monumentsStr = ""; + List monuments = warzone.getMonuments(); + for(Monument monument : monuments) { + Location monumentLoc = monument.getLocation(); + monumentsStr += monument.getName() + "," + (int)monumentLoc.getBlockX() + "," + (int)monumentLoc.getBlockY() + "," + (int)monumentLoc.getBlockZ() + ";"; + } + warzoneConfig.setString("monuments", monumentsStr); + warzoneConfig.save(); + warzoneConfig.close(); + + if(saveBlocks) { + // zone blocks + PropertiesFile warzoneBlocksFile = new PropertiesFile(war.getName() + "/warzone-" + warzone.getName() + ".dat"); + int northSouth = warzone.getSoutheast().getBlockX() - warzone.getNorthwest().getBlockX(); + int eastWest = warzone.getNorthwest().getBlockZ() - warzone.getSoutheast().getBlockZ(); + int[][][] state = warzone.getInitialState(); + StringBuilder stateBuilder = new StringBuilder(); + int savedBlocks = 0; + if(state.length > 1) { + for(int i = 0; i < northSouth + 3; i++){ + for(int j = 0; j < 128; j++) { + for(int k = 0; k < eastWest + 3; k++) { + stateBuilder.append(state[i][j][k] + ","); + savedBlocks++; + } + } + } + } + warzoneBlocksFile.setString("zoneBlocks", stateBuilder.toString()); + + + // monument blocks + for(Monument monument: monuments) { + String monumentBlocksStr = ""; + for(int type : monument.getInitialState()) { + monumentBlocksStr += type + ","; + } + warzoneBlocksFile.setString("monument"+monument.getName()+"Blocks", monumentBlocksStr); + } + + // team spawn blocks + for(Team team : teams) { + String teamBlocksStr = ""; + for(int type : team.getOldSpawnState()) { + teamBlocksStr += type + ","; + } + warzoneBlocksFile.setString("team"+team.getName()+"Blocks", teamBlocksStr); + } + + warzoneBlocksFile.save(); + warzoneBlocksFile.close(); + } + + if(saveBlocks) { + war.getLogger().info("Saved warzone " + warzone.getName() + " config and blocks."); + } else { + war.getLogger().info("Saved warzone " + warzone.getName() + " config."); + } + } + + public static void delete(War war, String name) { + File warzoneConfig = new File(war.getName() + "/warzone-" + name + ".txt"); + boolean deletedConfig = warzoneConfig.delete(); + 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"); + } + + } + +}