diff --git a/src/simpleWarBackup/Backup.java b/src/simpleWarBackup/Backup.java index 601c986..edd57d4 100644 --- a/src/simpleWarBackup/Backup.java +++ b/src/simpleWarBackup/Backup.java @@ -38,7 +38,7 @@ public class Backup /** * TODO write javadoc */ - private final File directory; + private final File folder; private final String name; /** @@ -52,7 +52,7 @@ public class Backup { checkName(this.name = name); //throws NameCollisionException - directory = new File(plugin.getDataFolder(), name); + folder = new File(plugin.getDataFolder(), name); Server server = plugin.getServer(); List worlds = server.getWorlds(); @@ -74,7 +74,7 @@ public class Backup { checkName(this.name = name); //throws NameCollisionException - directory = new File(plugin.getDataFolder(), name); + folder = new File(plugin.getDataFolder(), name); Server server = plugin.getServer(); List worlds = server.getWorlds(); @@ -83,21 +83,6 @@ public class Backup } - /** - * TODO write javadoc - * - * @param name - * @throws NameCollisionException - */ - private static void checkName(String name) throws NameCollisionException - { - for (String filename : Main.backupsDir.list()) if (filename.equals(name)) - { - throw new NameCollisionException(); - } - } - - /** * TODO write javadoc * @@ -143,7 +128,7 @@ public class Backup //create chunk list if nonexistent if (chunklist == null) { - File townDir = new File(directory, town.getUID().toString()); + File townDir = new File(folder, town.getUID().toString()); File worldDir = new File(townDir, worldname); File chunksDir = new File(worldDir, "region chunk lists"); File chlistDir = new File(chunksDir, "r."+coord.x+"."+coord.z+".chunklist"); @@ -152,7 +137,7 @@ public class Backup worldbranch.put(coord, chunklist); } - //add chunk to chunk list + chunklist.storeChunk(x, z); } @@ -161,6 +146,21 @@ public class Backup } + + /** + * TODO write javadoc + * + * @param name + * @throws NameCollisionException + */ + private static void checkName(String name) throws NameCollisionException + { + for (String filename : Main.backupsDir.list()) if (filename.equals(name)) + { + throw new NameCollisionException(); + } + } + /** * Holds region coordinates. A region is 32x32 chunks. A chunk is 16x16 blocks.

diff --git a/src/simpleWarBackup/BackupIO.java b/src/simpleWarBackup/BackupIO.java index a34eb10..a0a4d9d 100644 --- a/src/simpleWarBackup/BackupIO.java +++ b/src/simpleWarBackup/BackupIO.java @@ -156,64 +156,6 @@ public class BackupIO */ private static void restoreAll(CraftWorld world, String backup) { - - } - - - - - - - - - - - - public static boolean restoreTest(int x, int z) throws IOException - { - CraftWorld world = (CraftWorld) Bukkit.getWorld("world"); - - File worldDir = new File(Main.backupsDir, "world"); - File backupDir = new File(worldDir, "test"); - File regionDir = new File(backupDir, "region"); - File mcaFile = new File(regionDir, "r.1.1.mca"); - - RegionFile regionFileSource = RegionFile_Cache.get(backupDir, x, z); - RegionFile regionFileTarget = RegionFile_Cache.getFromMinecraft(world, x, z); - - DataInputStream dataInput = regionFileSource.a(x & 31, z & 31); - DataOutputStream dataOutput = regionFileTarget.b(x & 31, z & 31); - - /* Look in RegionFile to find how to get length. - * Length is recorded in the first 4 bytes of each - * chunk's data, in the body of the region file. - * - * Read header for chunk data location, seek to - * that location and read first 4 bytes. This is - * the length for byte[] buf below. - */ - /*int length; - { - RandomAccessFile raf = RegionFileCache.getRAF(regionFileSource); - if (raf == null) return false; - ... - } - - byte[] buf = new byte[length]; - - dataInput.readFully(buf); - dataOutput.write(buf); - dataOutput.close();*/ - - if (dataInput == null) - return false; - - NBTCompressedStreamTools.a( - NBTCompressedStreamTools.a(dataInput), - (java.io.DataOutput) dataOutput); - - dataOutput.close(); - - return true; + //world.isChunkLoaded(x,z); } } diff --git a/src/simpleWarBackup/Main.java b/src/simpleWarBackup/Main.java index f4fe1a1..a280096 100644 --- a/src/simpleWarBackup/Main.java +++ b/src/simpleWarBackup/Main.java @@ -51,71 +51,17 @@ public class Main extends JavaPlugin implements Listener { initialize(this); - //TEST - getCommand("testBackupChunk").setExecutor(this); - getCommand("testRestoreChunk").setExecutor(this); + getCommand("warbackup").setExecutor(this); } - - - - - - - - - - + /** + * TODO write javadoc + */ public boolean onCommand(CommandSender sender, Command command, String label, String[] args) { - if (!(sender instanceof Player)) return false; - if (!sender.getName().equals("iie")) return false; - - sender.sendMessage("some command received"); - Location loc = ((Player) sender).getLocation(); - World world = loc.getWorld(); - Chunk chunk = loc.getChunk(); - - //test-chunks to be test-restored - int[][] xz = {{187, 187}, - {40 , 40 }}; - - if (command.getName().equals("testBackupChunk")) - { - try { BackupIO.backup((CraftWorld) world, "test", (CraftChunk) chunk); } - catch (IOException e) { e.printStackTrace(); } - } - else if (command.getName().equals("testRestoreChunk")) - { - sender.sendMessage("testRestoreChunk command received"); - for (int[] coords : xz) - { - if (world.isChunkLoaded(coords[0], coords[1])) - { - sender.sendMessage("chunk " + coords[0] + ", " + coords[1] + " is still loaded"); - return false; - } - } - { - sender.sendMessage("chunk is not loaded"); - try - { - for (int[] coords : xz) - { - sender.sendMessage( - BackupIO.restoreTest(coords[0], coords[1]) ? "restore worked" : - "restore failed"); - } - } - catch (IOException e) - { - e.printStackTrace(); - sender.sendMessage("IOException, restore failed"); - } - } - } + //world.isChunkLoaded(x,z); return true; } }