removed test stuff to declutter
This commit is contained in:
parent
f69fb22f88
commit
f14eb4693a
3 changed files with 26 additions and 138 deletions
|
@ -38,7 +38,7 @@ public class Backup
|
||||||
/**
|
/**
|
||||||
* TODO write javadoc
|
* TODO write javadoc
|
||||||
*/
|
*/
|
||||||
private final File directory;
|
private final File folder;
|
||||||
private final String name;
|
private final String name;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -52,7 +52,7 @@ public class Backup
|
||||||
{
|
{
|
||||||
checkName(this.name = name); //throws NameCollisionException
|
checkName(this.name = name); //throws NameCollisionException
|
||||||
|
|
||||||
directory = new File(plugin.getDataFolder(), name);
|
folder = new File(plugin.getDataFolder(), name);
|
||||||
|
|
||||||
Server server = plugin.getServer();
|
Server server = plugin.getServer();
|
||||||
List<World> worlds = server.getWorlds();
|
List<World> worlds = server.getWorlds();
|
||||||
|
@ -74,7 +74,7 @@ public class Backup
|
||||||
{
|
{
|
||||||
checkName(this.name = name); //throws NameCollisionException
|
checkName(this.name = name); //throws NameCollisionException
|
||||||
|
|
||||||
directory = new File(plugin.getDataFolder(), name);
|
folder = new File(plugin.getDataFolder(), name);
|
||||||
|
|
||||||
Server server = plugin.getServer();
|
Server server = plugin.getServer();
|
||||||
List<World> worlds = server.getWorlds();
|
List<World> 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
|
* TODO write javadoc
|
||||||
*
|
*
|
||||||
|
@ -143,7 +128,7 @@ public class Backup
|
||||||
//create chunk list if nonexistent
|
//create chunk list if nonexistent
|
||||||
if (chunklist == null)
|
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 worldDir = new File(townDir, worldname);
|
||||||
File chunksDir = new File(worldDir, "region chunk lists");
|
File chunksDir = new File(worldDir, "region chunk lists");
|
||||||
File chlistDir = new File(chunksDir, "r."+coord.x+"."+coord.z+".chunklist");
|
File chlistDir = new File(chunksDir, "r."+coord.x+"."+coord.z+".chunklist");
|
||||||
|
@ -152,7 +137,7 @@ public class Backup
|
||||||
worldbranch.put(coord, chunklist);
|
worldbranch.put(coord, chunklist);
|
||||||
}
|
}
|
||||||
|
|
||||||
//add chunk to chunk list
|
|
||||||
chunklist.storeChunk(x, z);
|
chunklist.storeChunk(x, z);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -162,6 +147,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.<p>
|
* Holds region coordinates. A region is 32x32 chunks. A chunk is 16x16 blocks.<p>
|
||||||
*
|
*
|
||||||
|
|
|
@ -156,64 +156,6 @@ public class BackupIO
|
||||||
*/
|
*/
|
||||||
private static void restoreAll(CraftWorld world, String backup)
|
private static void restoreAll(CraftWorld world, String backup)
|
||||||
{
|
{
|
||||||
|
//world.isChunkLoaded(x,z);
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
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;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -51,71 +51,17 @@ public class Main extends JavaPlugin implements Listener
|
||||||
{
|
{
|
||||||
initialize(this);
|
initialize(this);
|
||||||
|
|
||||||
//TEST
|
getCommand("warbackup").setExecutor(this);
|
||||||
getCommand("testBackupChunk").setExecutor(this);
|
|
||||||
getCommand("testRestoreChunk").setExecutor(this);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* TODO write javadoc
|
||||||
|
*/
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
public boolean onCommand(CommandSender sender, Command command, String label, String[] args)
|
public boolean onCommand(CommandSender sender, Command command, String label, String[] args)
|
||||||
{
|
{
|
||||||
if (!(sender instanceof Player)) return false;
|
//world.isChunkLoaded(x,z);
|
||||||
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");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue