From 1ce45d6635d6a14c57126af4d17b58f4dd839bc5 Mon Sep 17 00:00:00 2001 From: BuildTools Date: Fri, 7 Sep 2018 21:55:32 +0100 Subject: [PATCH] Let this be over, please make it end --- src/simpleWarBackup/Backup.java | 98 ++++++++++++++++++++-- src/simpleWarBackup/BackupIO.java | 6 +- src/simpleWarBackup/ChunkAccess_Cache.java | 4 +- src/simpleWarBackup/Main.java | 7 ++ src/simpleWarBackup/RegionChunkList.java | 18 ++-- src/simpleWarBackup/RegionFile_Cache.java | 12 +-- 6 files changed, 114 insertions(+), 31 deletions(-) diff --git a/src/simpleWarBackup/Backup.java b/src/simpleWarBackup/Backup.java index bb136e3..8031b85 100644 --- a/src/simpleWarBackup/Backup.java +++ b/src/simpleWarBackup/Backup.java @@ -2,28 +2,42 @@ package simpleWarBackup; import java.io.File; import java.util.HashMap; +import java.util.List; +import java.util.UUID; import org.bukkit.Bukkit; +import org.bukkit.Server; +import org.bukkit.World; import com.palmergames.bukkit.towny.Towny; import com.palmergames.bukkit.towny.object.Town; import com.palmergames.bukkit.towny.object.TownBlock; +import com.palmergames.bukkit.towny.object.TownyUniverse; import simpleWarBackup.exceptions.NameCollisionException; +/** + * TODO write javadoc + */ public class Backup { - private final HashMap>> lists - = new HashMap>> tree + = new HashMap>>(); - private final String name; + /** + * TODO write javadoc + */ private final File directory; + private final String name; /** * TODO write javadoc (this is the default constructor) @@ -31,13 +45,17 @@ public class Backup * @param name * @throws NameCollisionException */ - Backup(String name) throws NameCollisionException + Backup(String name, Main plugin) throws NameCollisionException { checkName(this.name = name); //throws NameCollisionException - //com.palmergames.bukkit.towny.object.TownyUniverse.getWorld(null).getTowns(); + Server server = plugin.getServer(); + List worlds = server.getWorlds(); + + maketree(TownyUniverse.getDataSource().getTowns(), worlds, server); } + /** * TODO write javadoc * @@ -51,4 +69,68 @@ public class Backup throw new NameCollisionException(); } } + + + + private void maketree(List towns, List worlds, Server server) + { + HashMap> townbranch; + HashMap worldbranch; + + for (Town town : towns) + { + townbranch = new HashMap>(); + splitbranch(townbranch, worlds); + addleaves(townbranch, town, worlds, server); + tree.put(town.getUID(), townbranch); + } + } + + + /** + * TODO write javadoc + * + * @param townbranch + * @param worlds + */ + private static void splitbranch( + HashMap> townbranch, + List worlds) + { + for (World world : worlds) + { + 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 + } + } } diff --git a/src/simpleWarBackup/BackupIO.java b/src/simpleWarBackup/BackupIO.java index 1367676..bf9b0a5 100644 --- a/src/simpleWarBackup/BackupIO.java +++ b/src/simpleWarBackup/BackupIO.java @@ -5,12 +5,9 @@ import java.io.DataOutput; import java.io.DataOutputStream; import java.io.File; import java.io.IOException; -import java.io.RandomAccessFile; import org.bukkit.Bukkit; -import org.bukkit.craftbukkit.v1_12_R1.CraftChunk; import org.bukkit.craftbukkit.v1_12_R1.CraftWorld; -import org.bukkit.plugin.java.JavaPlugin; import net.minecraft.server.v1_12_R1.Chunk; import net.minecraft.server.v1_12_R1.NBTCompressedStreamTools; @@ -18,6 +15,9 @@ import net.minecraft.server.v1_12_R1.NBTTagCompound; import net.minecraft.server.v1_12_R1.RegionFile; import net.minecraft.server.v1_12_R1.World; +/** + * TODO write javadoc + */ public class BackupIO { /** diff --git a/src/simpleWarBackup/ChunkAccess_Cache.java b/src/simpleWarBackup/ChunkAccess_Cache.java index 335693d..a52fb66 100644 --- a/src/simpleWarBackup/ChunkAccess_Cache.java +++ b/src/simpleWarBackup/ChunkAccess_Cache.java @@ -11,7 +11,7 @@ import java.util.Map; import net.minecraft.server.v1_12_R1.RegionFile; /** - * TODO write javadoc + * TODO write javadoc (mention that everything in this class is package private) */ public class ChunkAccess_Cache { @@ -46,7 +46,7 @@ public class ChunkAccess_Cache * @param z * @return */ - public static int getChunkLength(RegionFile regionFile, int x, int z) + static int getChunkLength(RegionFile regionFile, int x, int z) { Access access = cache.get(regionFile); diff --git a/src/simpleWarBackup/Main.java b/src/simpleWarBackup/Main.java index 3952536..f4fe1a1 100644 --- a/src/simpleWarBackup/Main.java +++ b/src/simpleWarBackup/Main.java @@ -20,7 +20,14 @@ public class Main extends JavaPlugin implements Listener { // --------------------- STATIC --------------------- + /** + * TODO write javadoc + */ static File pluginDir; + + /** + * TODO write javadoc + */ static File backupsDir; /** diff --git a/src/simpleWarBackup/RegionChunkList.java b/src/simpleWarBackup/RegionChunkList.java index 5820541..f6818df 100644 --- a/src/simpleWarBackup/RegionChunkList.java +++ b/src/simpleWarBackup/RegionChunkList.java @@ -81,8 +81,7 @@ public class RegionChunkList int z = (int) (regionCoordinates >>> 32); String filename = "r." + x + "." + z + ".chunklist"; - File file = new File(directory, filename); - readwrite = new RandomAccessFile(file, "rw"); + readwrite = new RandomAccessFile(new File(directory, filename), "rw"); } @@ -157,17 +156,12 @@ public class RegionChunkList /** * Closes the RandomAccessFile associated with this RegionChunkList.

* - * When you are done with this RegionChunkList, you should invoke this method. + * When you are done with a RegionChunkList, you should invoke this method. + * + * @throws IOException if the RandomAccessFile was not closed */ - void close() + void close() throws IOException { - try - { - readwrite.close(); - } - catch (IOException e) - { - e.printStackTrace(); - } + readwrite.close(); } } diff --git a/src/simpleWarBackup/RegionFile_Cache.java b/src/simpleWarBackup/RegionFile_Cache.java index dd8c780..64b0c64 100644 --- a/src/simpleWarBackup/RegionFile_Cache.java +++ b/src/simpleWarBackup/RegionFile_Cache.java @@ -12,7 +12,7 @@ import net.minecraft.server.v1_12_R1.RegionFile; import net.minecraft.server.v1_12_R1.World; /** - * TODO write this + * TODO write javadoc */ public final class RegionFile_Cache { @@ -79,7 +79,7 @@ public final class RegionFile_Cache /* regionFile.c() closes the private RandomAccessFile * inside the regionFile object, and that's all it does. - * The entire method: if (file != null) file.close(). + * The entire method: if (file != null) file.close(); */ while (iterator.hasNext()) { @@ -93,7 +93,7 @@ public final class RegionFile_Cache /** - * TODO + * TODO write javadoc, explain what method a(...) does * * @param world * @param x @@ -102,7 +102,7 @@ public final class RegionFile_Cache */ public static RegionFile getFromMinecraft(CraftWorld world, int x, int z) { - /* root directory of the world, the directory + /* root directory of the world: the directory * sharing the world's name and holding its * data. 'region' folder is found in here. */ @@ -112,7 +112,7 @@ public final class RegionFile_Cache } /** - * TODO + * TODO write javadoc, explain what method a(...) does * * @param world * @param x @@ -121,7 +121,7 @@ public final class RegionFile_Cache */ public static RegionFile getFromMinecraft(World world, int x, int z) { - /* root directory of the world, the directory + /* root directory of the world: the directory * sharing the world's name and holding its * data. 'region' folder is found in here. */