From 55ea36c165bae19e8e2b8ad8aaa86602c2e35a5d Mon Sep 17 00:00:00 2001 From: BuildTools Date: Wed, 12 Sep 2018 20:02:17 +0100 Subject: [PATCH] still working on maketree() in Backup --- src/simpleWarBackup/Backup.java | 137 ++++++++++++++--------- src/simpleWarBackup/BackupIO.java | 4 +- src/simpleWarBackup/RegionChunkList.java | 4 +- 3 files changed, 88 insertions(+), 57 deletions(-) diff --git a/src/simpleWarBackup/Backup.java b/src/simpleWarBackup/Backup.java index 8031b85..3029160 100644 --- a/src/simpleWarBackup/Backup.java +++ b/src/simpleWarBackup/Backup.java @@ -1,6 +1,7 @@ package simpleWarBackup; import java.io.File; +import java.io.IOException; import java.util.HashMap; import java.util.List; import java.util.UUID; @@ -14,6 +15,7 @@ import com.palmergames.bukkit.towny.object.Town; import com.palmergames.bukkit.towny.object.TownBlock; import com.palmergames.bukkit.towny.object.TownyUniverse; +import simpleWarBackup.RegionChunkList.Coord; import simpleWarBackup.exceptions.NameCollisionException; /** @@ -25,13 +27,14 @@ public class Backup * TODO write javadoc */ private final HashMap>> tree + HashMap>> tree + = new HashMap>>(); + HashMap>>(); /** * TODO write javadoc @@ -49,10 +52,11 @@ public class Backup { checkName(this.name = name); //throws NameCollisionException + File folder = new File(plugin.getDataFolder(), name); Server server = plugin.getServer(); List worlds = server.getWorlds(); - maketree(TownyUniverse.getDataSource().getTowns(), worlds, server); + maketree(TownyUniverse.getDataSource().getTowns(), worlds, server, folder); } @@ -71,66 +75,93 @@ public class Backup } - - private void maketree(List towns, List worlds, Server server) + /** + * TODO write javadoc + * + * @param towns + * @param worlds + * @param server + * @param folder + * @throws IOException + */ + private void maketree(List towns, List worlds, Server server, File folder) throws IOException { - HashMap> townbranch; - HashMap worldbranch; + + HashMap> townbranch; + HashMap worldbranch; + + RegionChunkList chunklist; + Coord coord; + int x,z; + + String worldname; + + File townDir, + worldDir, + chunksDir, + chlistDir; + + /* + * + */ for (Town town : towns) { - townbranch = new HashMap>(); - splitbranch(townbranch, worlds); - addleaves(townbranch, town, worlds, server); + townbranch = new HashMap>(); + + //make world sub-branches + for (World world : worlds) + townbranch.put(world.getName(), + new HashMap()); + + //populate world sub-branches + for (TownBlock block : town.getTownBlocks()) + { + worldname = block.getWorld().getName(); + worldbranch = townbranch.get(worldname); + + x = block.getX() >> 4; + z = block.getZ() >> 4; + + coord = new Coord(x >> 5, z >> 5); + chunklist = worldbranch.get(coord); + + if (chunklist == null) + { + townDir = new File(folder, town.getUID().toString()); + worldDir = new File(townDir, worldname); + chunksDir = new File(worldDir, "region chunk lists"); + chlistDir = new File(chunksDir, "r."+coord.x+"."+coord.z+".chunklist"); + + chunklist = new RegionChunkList(chlistDir); + worldbranch.put(coord, chunklist); + } + } + tree.put(town.getUID(), townbranch); } } + /** - * TODO write javadoc + * Holds region coordinates. A region is 32x32 chunks. A chunk is 16x16 blocks.

* - * @param townbranch - * @param worlds + * The chunk coordinates of a block are (block x >> 4, block z >> 4).

+ * The region coordinates of a chunk are (chunk x >> 5, chunk z >> 5).

*/ - private static void splitbranch( - HashMap> townbranch, - List worlds) + public static class Coord { - for (World world : worlds) + final int x, z; + + /** + * @param x region x coordinate + * @param z region z coordinate + */ + public Coord(int x, int z) { - townbranch.put(world.getUID(), new HashMap()); - } - } - - - /** - * TODO write javadoc - * - * @param townbranch - * @param town - * @param worlds - * @param server - */ - private static void addleaves( - HashMap> townbranch, - Town town, List worlds, Server server) - { - long region; - RegionChunkList chunklist; - HashMap worldbranch; - for (TownBlock block : town.getTownBlocks()) - { - worldbranch = townbranch.get(server.getWorld(block.getWorld().getName()).getUID()); - - int x = block.getX(); - int z = block.getZ(); - - //round down to the nearest multiple of 16 - if (x < 0) x -= 16 + (x % 16); else x -= x % 16; - if (z < 0) z -= 16 + (z % 16); else z -= z % 16; - - //TODO finish this fucking method, and this fucking plugin + this.x = x; + this.z = z; } } } diff --git a/src/simpleWarBackup/BackupIO.java b/src/simpleWarBackup/BackupIO.java index bf9b0a5..a34eb10 100644 --- a/src/simpleWarBackup/BackupIO.java +++ b/src/simpleWarBackup/BackupIO.java @@ -33,9 +33,9 @@ public class BackupIO * @param world * @return */ - private static File getDir(String backup, String town, String worldUID) + private static File getDir(String backup, String town, String world) { - return new File(new File (new File(Main.backupsDir, backup), town), worldUID); + return new File(new File (new File(Main.backupsDir, backup), town), world); } diff --git a/src/simpleWarBackup/RegionChunkList.java b/src/simpleWarBackup/RegionChunkList.java index f6818df..c0d6a1a 100644 --- a/src/simpleWarBackup/RegionChunkList.java +++ b/src/simpleWarBackup/RegionChunkList.java @@ -103,8 +103,8 @@ public class RegionChunkList /** * TODO write javadoc (and add comment to explain numbers) * - * @param x - * @param z + * @param x chunk x coordinate + * @param z chunk z coordinate */ void storeChunk(int x, int z) {