2015-02-23 16:29:45 +11:00
|
|
|
package com.intellectualcrafters.plot.util;
|
|
|
|
|
2015-07-26 04:12:35 +10:00
|
|
|
import java.util.ArrayList;
|
2015-02-23 16:29:45 +11:00
|
|
|
import java.util.HashMap;
|
|
|
|
import java.util.List;
|
2015-09-22 23:23:28 +10:00
|
|
|
import java.util.Set;
|
2015-02-23 16:29:45 +11:00
|
|
|
|
2015-07-31 00:25:16 +10:00
|
|
|
import com.intellectualcrafters.plot.object.ChunkLoc;
|
|
|
|
import com.intellectualcrafters.plot.object.Location;
|
|
|
|
import com.intellectualcrafters.plot.object.Plot;
|
|
|
|
import com.intellectualcrafters.plot.object.PlotBlock;
|
|
|
|
import com.intellectualcrafters.plot.object.PlotId;
|
|
|
|
import com.intellectualcrafters.plot.object.PlotLoc;
|
|
|
|
import com.intellectualcrafters.plot.object.RegionWrapper;
|
|
|
|
import com.intellectualcrafters.plot.object.RunnableVal;
|
|
|
|
import com.intellectualcrafters.plot.util.SetBlockQueue.ChunkWrapper;
|
|
|
|
|
2015-09-13 14:04:31 +10:00
|
|
|
public abstract class ChunkManager {
|
|
|
|
|
2015-02-23 16:29:45 +11:00
|
|
|
public static ChunkManager manager = null;
|
|
|
|
public static RegionWrapper CURRENT_PLOT_CLEAR = null;
|
2015-03-27 18:15:41 +11:00
|
|
|
public static boolean FORCE_PASTE = false;
|
2015-09-13 14:04:31 +10:00
|
|
|
|
2015-02-26 15:43:01 +11:00
|
|
|
public static HashMap<PlotLoc, HashMap<Short, Short>> GENERATE_BLOCKS = new HashMap<>();
|
|
|
|
public static HashMap<PlotLoc, HashMap<Short, Byte>> GENERATE_DATA = new HashMap<>();
|
2015-09-13 14:04:31 +10:00
|
|
|
|
|
|
|
public static ChunkLoc getChunkChunk(final Location loc) {
|
2015-02-23 16:29:45 +11:00
|
|
|
final int x = loc.getX() >> 9;
|
|
|
|
final int z = loc.getZ() >> 9;
|
|
|
|
return new ChunkLoc(x, z);
|
|
|
|
}
|
2015-09-13 14:04:31 +10:00
|
|
|
|
2015-07-26 04:12:35 +10:00
|
|
|
/**
|
|
|
|
* The int[] will be in the form: [chunkx, chunkz, pos1x, pos1z, pos2x, pos2z, isedge] and will represent the bottom and top parts of the chunk
|
|
|
|
* @param pos1
|
|
|
|
* @param pos2
|
|
|
|
* @param task
|
|
|
|
* @param whenDone
|
|
|
|
*/
|
2015-09-13 14:04:31 +10:00
|
|
|
public static void chunkTask(final Location pos1, final Location pos2, final RunnableVal<int[]> task, final Runnable whenDone, final int allocate) {
|
2015-07-26 04:12:35 +10:00
|
|
|
final int p1x = pos1.getX();
|
|
|
|
final int p1z = pos1.getZ();
|
|
|
|
final int p2x = pos2.getX();
|
|
|
|
final int p2z = pos2.getZ();
|
|
|
|
final int bcx = p1x >> 4;
|
|
|
|
final int bcz = p1z >> 4;
|
|
|
|
final int tcx = p2x >> 4;
|
|
|
|
final int tcz = p2z >> 4;
|
2015-09-13 14:04:31 +10:00
|
|
|
|
2015-07-26 04:12:35 +10:00
|
|
|
final ArrayList<ChunkLoc> chunks = new ArrayList<ChunkLoc>();
|
2015-09-13 14:04:31 +10:00
|
|
|
|
|
|
|
for (int x = bcx; x <= tcx; x++) {
|
|
|
|
for (int z = bcz; z <= tcz; z++) {
|
2015-07-26 04:12:35 +10:00
|
|
|
chunks.add(new ChunkLoc(x, z));
|
|
|
|
}
|
|
|
|
}
|
2015-09-13 14:04:31 +10:00
|
|
|
|
|
|
|
TaskManager.runTask(new Runnable() {
|
2015-07-26 04:12:35 +10:00
|
|
|
@Override
|
2015-09-13 14:04:31 +10:00
|
|
|
public void run() {
|
2015-09-11 20:09:22 +10:00
|
|
|
final long start = System.currentTimeMillis();
|
2015-09-13 14:04:31 +10:00
|
|
|
while ((chunks.size() > 0) && ((System.currentTimeMillis() - start) < allocate)) {
|
2015-09-11 20:09:22 +10:00
|
|
|
final ChunkLoc chunk = chunks.remove(0);
|
2015-07-26 04:12:35 +10:00
|
|
|
task.value = new int[7];
|
|
|
|
task.value[0] = chunk.x;
|
|
|
|
task.value[1] = chunk.z;
|
|
|
|
task.value[2] = task.value[0] << 4;
|
|
|
|
task.value[3] = task.value[1] << 4;
|
|
|
|
task.value[4] = task.value[2] + 15;
|
|
|
|
task.value[5] = task.value[3] + 15;
|
2015-09-13 14:04:31 +10:00
|
|
|
if (task.value[0] == bcx) {
|
2015-09-11 20:09:22 +10:00
|
|
|
task.value[2] = p1x;
|
2015-07-26 04:12:35 +10:00
|
|
|
task.value[6] = 1;
|
|
|
|
}
|
2015-09-13 14:04:31 +10:00
|
|
|
if (task.value[0] == tcx) {
|
2015-07-26 04:12:35 +10:00
|
|
|
task.value[4] = p2x;
|
|
|
|
task.value[6] = 1;
|
|
|
|
}
|
2015-09-13 14:04:31 +10:00
|
|
|
if (task.value[1] == bcz) {
|
2015-07-26 04:12:35 +10:00
|
|
|
task.value[3] = p1z;
|
|
|
|
task.value[6] = 1;
|
|
|
|
}
|
2015-09-13 14:04:31 +10:00
|
|
|
if (task.value[1] == tcz) {
|
2015-07-26 04:12:35 +10:00
|
|
|
task.value[5] = p2z;
|
|
|
|
task.value[6] = 1;
|
|
|
|
}
|
|
|
|
task.run();
|
|
|
|
}
|
2015-09-13 14:04:31 +10:00
|
|
|
if (chunks.size() != 0) {
|
2015-07-26 04:12:35 +10:00
|
|
|
TaskManager.runTaskLater(this, 1);
|
2015-09-13 14:04:31 +10:00
|
|
|
} else {
|
2015-07-26 04:12:35 +10:00
|
|
|
TaskManager.runTask(whenDone);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
2015-09-13 14:04:31 +10:00
|
|
|
|
2015-09-11 20:09:22 +10:00
|
|
|
public abstract void setChunk(final ChunkWrapper loc, final PlotBlock[][] result);
|
2015-09-13 14:04:31 +10:00
|
|
|
|
2015-09-11 20:09:22 +10:00
|
|
|
public abstract int[] countEntities(final Plot plot);
|
2015-09-13 14:04:31 +10:00
|
|
|
|
2015-09-11 20:09:22 +10:00
|
|
|
public abstract boolean loadChunk(final String world, final ChunkLoc loc, final boolean force);
|
2015-09-13 14:04:31 +10:00
|
|
|
|
2015-09-11 20:09:22 +10:00
|
|
|
public abstract boolean unloadChunk(final String world, final ChunkLoc loc, final boolean save, final boolean safe);
|
2015-09-13 14:04:31 +10:00
|
|
|
|
2015-09-22 23:23:28 +10:00
|
|
|
public abstract Set<ChunkLoc> getChunkChunks(final String world);
|
2015-09-13 14:04:31 +10:00
|
|
|
|
2015-09-11 20:09:22 +10:00
|
|
|
public abstract void regenerateChunk(final String world, final ChunkLoc loc);
|
2015-09-13 14:04:31 +10:00
|
|
|
|
2015-02-23 16:29:45 +11:00
|
|
|
public abstract void deleteRegionFile(final String world, final ChunkLoc loc);
|
2015-09-13 14:04:31 +10:00
|
|
|
|
2015-06-09 02:01:09 +10:00
|
|
|
public abstract void deleteRegionFiles(final String world, final List<ChunkLoc> chunks);
|
2015-09-13 14:04:31 +10:00
|
|
|
|
2015-09-09 22:34:41 -07:00
|
|
|
public abstract void deleteRegionFiles(final String world, final List<ChunkLoc> chunks, final Runnable whenDone);
|
2015-09-13 14:04:31 +10:00
|
|
|
|
2015-02-23 16:29:45 +11:00
|
|
|
public abstract Plot hasPlot(String world, ChunkLoc chunk);
|
2015-09-13 14:04:31 +10:00
|
|
|
|
2015-09-22 23:23:28 +10:00
|
|
|
/**
|
|
|
|
* Copy a region to a new location (in the same world)
|
|
|
|
*/
|
2015-02-23 16:29:45 +11:00
|
|
|
public abstract boolean copyRegion(final Location pos1, final Location pos2, final Location newPos, final Runnable whenDone);
|
2015-09-13 14:04:31 +10:00
|
|
|
|
2015-07-26 00:43:19 +10:00
|
|
|
/**
|
|
|
|
* Assumptions:<br>
|
|
|
|
* - pos1 and pos2 are in the same plot<br>
|
|
|
|
* It can be harmful to the world if parameters outside this scope are provided
|
|
|
|
* @param pos1
|
|
|
|
* @param pos2
|
|
|
|
* @param whenDone
|
|
|
|
* @return
|
|
|
|
*/
|
2015-02-23 16:29:45 +11:00
|
|
|
public abstract boolean regenerateRegion(final Location pos1, final Location pos2, final Runnable whenDone);
|
2015-09-13 14:04:31 +10:00
|
|
|
|
2015-08-04 22:21:12 +10:00
|
|
|
public abstract void clearAllEntities(final Location pos1, final Location pos2);
|
2015-09-13 14:04:31 +10:00
|
|
|
|
2015-09-22 23:23:28 +10:00
|
|
|
public abstract void swap(final Location bot1, final Location top1, final Location bot2, final Location top2, Runnable whenDone);
|
2015-02-23 16:29:45 +11:00
|
|
|
}
|