mirror of
https://github.com/IntellectualSites/PlotSquared.git
synced 2024-11-26 07:06:44 +01:00
plot debugclear now actually async
This commit is contained in:
parent
cea4609174
commit
427d9479b9
@ -64,7 +64,17 @@ public class DebugClear extends SubCommand {
|
||||
World bukkitWorld = Bukkit.getWorld(world);
|
||||
Location pos1 = PlotHelper.getPlotBottomLoc(bukkitWorld, plot.id).add(1, 0, 1);
|
||||
Location pos2 = PlotHelper.getPlotTopLoc(bukkitWorld, plot.id);
|
||||
ChunkManager.regenerateRegion(pos1, pos2);
|
||||
if (PlotHelper.runners.containsKey(plot)) {
|
||||
PlayerFunctions.sendMessage(null, C.WAIT_FOR_TIMER);
|
||||
return false;
|
||||
}
|
||||
PlotHelper.runners.put(plot, 1);
|
||||
ChunkManager.regenerateRegion(pos1, pos2, new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
PlotHelper.runners.remove(plot);
|
||||
}
|
||||
});
|
||||
PlotMain.sendConsoleSenderMessage("Plot " + plot.getId().toString() + " cleared.");
|
||||
PlotMain.sendConsoleSenderMessage("&aDone!");
|
||||
}
|
||||
@ -88,7 +98,17 @@ public class DebugClear extends SubCommand {
|
||||
World bukkitWorld = plr.getWorld();
|
||||
Location pos1 = PlotHelper.getPlotBottomLoc(bukkitWorld, plot.id).add(1, 0, 1);
|
||||
Location pos2 = PlotHelper.getPlotTopLoc(bukkitWorld, plot.id);
|
||||
ChunkManager.regenerateRegion(pos1, pos2);
|
||||
if (PlotHelper.runners.containsKey(plot)) {
|
||||
PlayerFunctions.sendMessage(null, C.WAIT_FOR_TIMER);
|
||||
return false;
|
||||
}
|
||||
PlotHelper.runners.put(plot, 1);
|
||||
ChunkManager.regenerateRegion(pos1, pos2, new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
PlotHelper.runners.remove(plot);
|
||||
}
|
||||
});
|
||||
PlayerFunctions.sendMessage(plr, "&aDone!");
|
||||
|
||||
// sign
|
||||
|
@ -221,6 +221,33 @@ public class HybridPlotWorld extends PlotWorld {
|
||||
Schematic schem2 = SchematicHandler.getSchematic(schem2Str);
|
||||
Schematic schem3 = SchematicHandler.getSchematic(schem3Str);
|
||||
|
||||
int shift = (int) Math.floor(this.ROAD_WIDTH / 2);
|
||||
int oddshift = 0;
|
||||
if (this.ROAD_WIDTH % 2 != 0) {
|
||||
oddshift = 1;
|
||||
}
|
||||
|
||||
if (schem3 != null) {
|
||||
PLOT_SCHEMATIC = true;
|
||||
DataCollection[] blocks3 = schem3.getBlockCollection();
|
||||
Dimension d3 = schem3.getSchematicDimension();
|
||||
short w3 = (short) d3.getX();
|
||||
short l3 = (short) d3.getZ();
|
||||
short h3 = (short) d3.getY();
|
||||
for (short x = 0; x < w3; x++) {
|
||||
for (short z = 0; z < l3; z++) {
|
||||
for (short y = 0; y < h3; y++) {
|
||||
int index = y * w3 * l3 + z * w3 + x;
|
||||
short id = blocks3[index].getBlock();
|
||||
byte data = blocks3[index].getData();
|
||||
if (id != 0) {
|
||||
addOverlayBlock((short) (x + shift + oddshift), (short) (y + this.OFFSET), (short) (z + shift + oddshift), id, data, false);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (schem1 == null || schem2 == null || this.ROAD_WIDTH == 0) {
|
||||
PlotMain.sendConsoleSenderMessage(C.PREFIX.s() + "&3 - schematic: &7false");
|
||||
return;
|
||||
@ -242,12 +269,6 @@ public class HybridPlotWorld extends PlotWorld {
|
||||
short h2 = (short) d2.getY();
|
||||
this.SCHEMATIC_HEIGHT = (short) Math.max(h2, h1);
|
||||
|
||||
int shift = (int) Math.floor(this.ROAD_WIDTH / 2);
|
||||
int oddshift = 0;
|
||||
if (this.ROAD_WIDTH % 2 != 0) {
|
||||
oddshift = 1;
|
||||
}
|
||||
|
||||
for (short x = 0; x < w1; x++) {
|
||||
for (short z = 0; z < l1; z++) {
|
||||
for (short y = 0; y < h1; y++) {
|
||||
@ -276,28 +297,6 @@ public class HybridPlotWorld extends PlotWorld {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (schem3 != null) {
|
||||
PLOT_SCHEMATIC = true;
|
||||
DataCollection[] blocks3 = schem3.getBlockCollection();
|
||||
Dimension d3 = schem3.getSchematicDimension();
|
||||
short w3 = (short) d3.getX();
|
||||
short l3 = (short) d3.getZ();
|
||||
short h3 = (short) d3.getY();
|
||||
for (short x = 0; x < w3; x++) {
|
||||
for (short z = 0; z < l3; z++) {
|
||||
for (short y = 0; y < h3; y++) {
|
||||
int index = y * w3 * l3 + z * w3 + x;
|
||||
short id = blocks3[index].getBlock();
|
||||
byte data = blocks3[index].getData();
|
||||
if (id != 0) {
|
||||
addOverlayBlock((short) (x + shift + oddshift), (short) (y + this.OFFSET), (short) (z + shift + oddshift), id, data, false);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
this.ROAD_SCHEMATIC_ENABLED = true;
|
||||
}
|
||||
|
||||
|
@ -5,6 +5,8 @@ import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.HashSet;
|
||||
|
||||
import org.apache.commons.lang.mutable.MutableInt;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.Chunk;
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.Material;
|
||||
@ -29,8 +31,11 @@ import org.bukkit.block.Skull;
|
||||
import org.bukkit.entity.Entity;
|
||||
import org.bukkit.entity.EntityType;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
import org.bukkit.plugin.Plugin;
|
||||
|
||||
import com.intellectualcrafters.plot.PlotMain;
|
||||
import com.intellectualcrafters.plot.config.C;
|
||||
import com.intellectualcrafters.plot.generator.HybridPlotManager;
|
||||
import com.intellectualcrafters.plot.object.BlockLoc;
|
||||
import com.intellectualcrafters.plot.object.ChunkLoc;
|
||||
import com.intellectualcrafters.plot.object.Plot;
|
||||
@ -42,6 +47,8 @@ public class ChunkManager {
|
||||
public static RegionWrapper CURRENT_PLOT_CLEAR = null;
|
||||
public static HashMap<ChunkLoc, HashMap<Short, Short>> GENERATE_BLOCKS = new HashMap<>();
|
||||
public static HashMap<ChunkLoc, HashMap<Short, Byte>> GENERATE_DATA = new HashMap<>();
|
||||
public static MutableInt index = new MutableInt(0);
|
||||
public static HashMap<Integer, Integer> tasks = new HashMap<>();
|
||||
|
||||
public static ArrayList<ChunkLoc> getChunkChunks(World world) {
|
||||
File[] regionFiles = new File(new File(".").getAbsolutePath() + File.separator + world.getName() + File.separator + "region").listFiles();
|
||||
@ -110,27 +117,49 @@ public class ChunkManager {
|
||||
|
||||
private static HashSet<EntityWrapper> entities;
|
||||
|
||||
public static boolean regenerateRegion(Location pos1, Location pos2) {
|
||||
World world = pos1.getWorld();
|
||||
public static boolean regenerateRegion(final Location pos1, final Location pos2, final Runnable whenDone) {
|
||||
index.increment();
|
||||
final Plugin plugin = (Plugin) PlotMain.getMain();
|
||||
|
||||
final World world = pos1.getWorld();
|
||||
Chunk c1 = world.getChunkAt(pos1);
|
||||
Chunk c2 = world.getChunkAt(pos2);
|
||||
|
||||
CURRENT_PLOT_CLEAR = new RegionWrapper(pos1.getBlockX(), pos2.getBlockX(), pos1.getBlockZ(), pos2.getBlockZ());
|
||||
final int sx = pos1.getBlockX();
|
||||
final int sz = pos1.getBlockZ();
|
||||
final int ex = pos2.getBlockX();
|
||||
final int ez = pos2.getBlockZ();
|
||||
|
||||
int sx = pos1.getBlockX();
|
||||
int sz = pos1.getBlockZ();
|
||||
int ex = pos2.getBlockX();
|
||||
int ez = pos2.getBlockZ();
|
||||
final int c1x = c1.getX();
|
||||
final int c1z = c1.getZ();
|
||||
final int c2x = c2.getX();
|
||||
final int c2z = c2.getZ();
|
||||
|
||||
int c1x = c1.getX();
|
||||
int c1z = c1.getZ();
|
||||
int c2x = c2.getX();
|
||||
int c2z = c2.getZ();
|
||||
|
||||
int maxY = world.getMaxHeight();
|
||||
final ArrayList<Chunk> chunks = new ArrayList<Chunk>();
|
||||
for (int x = c1x; x <= c2x; x ++) {
|
||||
for (int z = c1z; z <= c2z; z ++) {
|
||||
Chunk chunk = world.getChunkAt(x, z);
|
||||
chunk.load(false);
|
||||
chunks.add(chunk);
|
||||
}
|
||||
}
|
||||
final int maxY = world.getMaxHeight();
|
||||
final Integer currentIndex = index.toInteger();
|
||||
final Integer task = Bukkit.getScheduler().scheduleSyncRepeatingTask(plugin, new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
if (chunks.size() == 0) {
|
||||
System.out.print("DONE");
|
||||
TaskManager.runTaskLater(whenDone, 1);
|
||||
Bukkit.getScheduler().cancelTask(tasks.get(currentIndex));
|
||||
return;
|
||||
}
|
||||
CURRENT_PLOT_CLEAR = new RegionWrapper(pos1.getBlockX(), pos2.getBlockX(), pos1.getBlockZ(), pos2.getBlockZ());
|
||||
Chunk chunk = chunks.get(0);
|
||||
chunks.remove(0);
|
||||
int x = chunk.getX();
|
||||
int z = chunk.getZ();
|
||||
|
||||
boolean loaded = true;
|
||||
if (!chunk.isLoaded()) {
|
||||
boolean result = chunk.load(false);
|
||||
@ -177,10 +206,10 @@ public class ChunkManager {
|
||||
chunk.unload();
|
||||
chunk.load();
|
||||
}
|
||||
}
|
||||
}
|
||||
CURRENT_PLOT_CLEAR = null;
|
||||
initMaps();
|
||||
}
|
||||
}, 1, 1);
|
||||
tasks.put(currentIndex, task);
|
||||
return true;
|
||||
}
|
||||
|
||||
|
@ -765,8 +765,14 @@ import com.intellectualcrafters.plot.object.PlotWorld;
|
||||
|
||||
PlotWorld plotworld = PlotMain.getWorldSettings(world);
|
||||
if (plotworld.TERRAIN != 0) {
|
||||
runners.put(plot, 1);
|
||||
final Location pos2 = PlotHelper.getPlotTopLoc(world, plot.id);
|
||||
ChunkManager.regenerateRegion(pos1, pos2);
|
||||
ChunkManager.regenerateRegion(pos1, pos2, new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
runners.remove(plot);
|
||||
}
|
||||
});
|
||||
return;
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user