Let this be over, please make it end
This commit is contained in:
parent
67691336e2
commit
1ce45d6635
6 changed files with 114 additions and 31 deletions
|
@ -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<String, //town
|
||||
HashMap<String, //world
|
||||
/**
|
||||
* TODO write javadoc
|
||||
*/
|
||||
private final HashMap<Integer, //town
|
||||
HashMap<UUID, //world
|
||||
HashMap<Long, //region
|
||||
RegionChunkList>>> lists
|
||||
= new HashMap<String,
|
||||
HashMap<String,
|
||||
RegionChunkList>>> tree
|
||||
= new HashMap<Integer,
|
||||
HashMap<UUID,
|
||||
HashMap<Long,
|
||||
RegionChunkList>>>();
|
||||
|
||||
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<World> 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<Town> towns, List<World> worlds, Server server)
|
||||
{
|
||||
HashMap<UUID, HashMap<Long, RegionChunkList>> townbranch;
|
||||
HashMap<Long, RegionChunkList> worldbranch;
|
||||
|
||||
for (Town town : towns)
|
||||
{
|
||||
townbranch = new HashMap<UUID, HashMap<Long, RegionChunkList>>();
|
||||
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<UUID, HashMap<Long, RegionChunkList>> townbranch,
|
||||
List<World> worlds)
|
||||
{
|
||||
for (World world : worlds)
|
||||
{
|
||||
townbranch.put(world.getUID(), new HashMap<Long, RegionChunkList>());
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* TODO write javadoc
|
||||
*
|
||||
* @param townbranch
|
||||
* @param town
|
||||
* @param worlds
|
||||
* @param server
|
||||
*/
|
||||
private static void addleaves(
|
||||
HashMap<UUID, HashMap<Long, RegionChunkList>> townbranch,
|
||||
Town town, List<World> worlds, Server server)
|
||||
{
|
||||
long region;
|
||||
RegionChunkList chunklist;
|
||||
HashMap<Long, RegionChunkList> 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
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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
|
||||
{
|
||||
/**
|
||||
|
|
|
@ -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);
|
||||
|
||||
|
|
|
@ -20,7 +20,14 @@ public class Main extends JavaPlugin implements Listener
|
|||
{
|
||||
// --------------------- STATIC ---------------------
|
||||
|
||||
/**
|
||||
* TODO write javadoc
|
||||
*/
|
||||
static File pluginDir;
|
||||
|
||||
/**
|
||||
* TODO write javadoc
|
||||
*/
|
||||
static File backupsDir;
|
||||
|
||||
/**
|
||||
|
|
|
@ -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.<p>
|
||||
*
|
||||
* 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()
|
||||
{
|
||||
try
|
||||
void close() throws IOException
|
||||
{
|
||||
readwrite.close();
|
||||
}
|
||||
catch (IOException e)
|
||||
{
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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.
|
||||
*/
|
||||
|
|
Loading…
Reference in a new issue