Multiple changes

Working on async schematic saving
Default plot clearing is now properly async (and somewhat slower)
Offline mode servers now default to lowercase (there has been ample time
to update)
Fixed some issues with plot expiry
Fixed some issues with UUID caching
Optimized UUID fetching from cache (marginal)
This commit is contained in:
boy0001 2015-07-19 23:12:48 +10:00
parent 404933c3a7
commit 9c635810b0
14 changed files with 210 additions and 140 deletions

View File

@ -8,7 +8,7 @@
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
</properties>
<artifactId>PlotSquared</artifactId>
<version>2.12.13</version>
<version>2.12.14</version>
<name>PlotSquared</name>
<packaging>jar</packaging>
<build>

View File

@ -1222,16 +1222,16 @@ public class PS {
options.put("clear.auto.calibration.changes", 1);
options.put("clear.auto.calibration.faces", 2);
options.put("clear.auto.calibration.data", 32);
options.put("clear.auto.calibration.air", 32);
options.put("clear.auto.calibration.air", 0);
options.put("clear.auto.calibration.variety", 1);
options.put("clear.auto.calibration.changes_sd", 64);
options.put("clear.auto.calibration.faces_sd", 32);
options.put("clear.auto.calibration.data_sd", 1);
options.put("clear.auto.calibration.air_sd", 32);
options.put("clear.auto.calibration.air_sd", 0);
options.put("clear.auto.calibration.variety_sd", 1);
int keep = config.getInt("keep-if-modified");
int ignore = config.getInt("ignore-if-modified");
int keep = config.getInt("clear.keep-if-modified");
int ignore = config.getInt("clear.ignore-if-modified");
if (keep > 0 || ignore > 0) {
options.put("clear.auto.threshold", 1);
log("&cIMPORTANT MESSAGE ABOUT THIS UPDATE!!!!!!!!!!!!!!!!!!!!!!!!!!!!");
@ -1247,8 +1247,8 @@ public class PS {
else {
options.put("clear.auto.threshold", Settings.CLEAR_THRESHOLD);
}
config.set("keep-if-modified", null);
config.set("ignore-if-modified", null);
config.set("clear.keep-if-modified", null);
config.set("clear.ignore-if-modified", null);
// Schematics
options.put("schematics.save_path", Settings.SCHEMATIC_SAVE_PATH);

View File

@ -45,7 +45,7 @@ public class CreateRoadSchematic extends SubCommand {
return sendMessage(player, C.NOT_IN_PLOT_WORLD);
}
HybridUtils.manager.setupRoadSchematic(plot);
MainUtil.sendMessage(player, "&6Saved new road schematic");
MainUtil.sendMessage(player, "&6Saved new road schematic (see console for more information)");
return true;
}
}

View File

@ -74,6 +74,7 @@ public class DebugExec extends SubCommand {
PlotAnalysis analysis = plot.getComplexity();
if (analysis != null) {
int complexity = analysis.getComplexity();
MainUtil.sendMessage(player, "Changes: " + analysis.changes);
MainUtil.sendMessage(player, "Complexity: " + complexity);
return true;
}

View File

@ -8,6 +8,7 @@ import com.intellectualcrafters.plot.config.C;
import com.intellectualcrafters.plot.config.Settings;
import com.intellectualcrafters.plot.object.Plot;
import com.intellectualcrafters.plot.object.PlotPlayer;
import com.intellectualcrafters.plot.object.RunnableVal;
import com.intellectualcrafters.plot.util.MainUtil;
import com.intellectualcrafters.plot.util.SchematicHandler;
import com.intellectualcrafters.plot.util.TaskManager;
@ -37,19 +38,24 @@ public class Download extends SubCommand {
}
MainUtil.runners.put(plot, 1);
MainUtil.sendMessage(plr, C.GENERATING_LINK);
final CompoundTag tag = SchematicHandler.manager.getCompoundTag(plot.world, plot.id);
SchematicHandler.manager.getCompoundTag(plot.world, plot.id, new RunnableVal<CompoundTag>() {
@Override
public void run() {
TaskManager.runTaskAsync(new Runnable() {
@Override
public void run() {
URL url = SchematicHandler.manager.upload(tag);
URL url = SchematicHandler.manager.upload(value);
if (url == null) {
MainUtil.sendMessage(plr, C.GENERATING_LINK_FAILED);
MainUtil.runners.remove(plot);
return;
}
MainUtil.sendMessage(plr, url.toString());
MainUtil.runners.remove(plot);
}
});
}
});
return true;
}
}

View File

@ -177,7 +177,7 @@ public class Settings {
*/
public static boolean TWIN_MODE_UUID = false;
public static boolean OFFLINE_MODE = false;
public static boolean UUID_LOWERCASE = false;
public static boolean UUID_LOWERCASE = true;
/**
* Command confirmation
*/

View File

@ -80,30 +80,30 @@ public class BukkitHybridUtils extends HybridUtils {
final int ctz = tz >> 4;
final Random r = new Random();
AugmentedPopulator.initCache();
final int width = tx - bx + 1;
final int length = tz - bz + 1;
System.gc();
System.gc();
final short[][][] oldblocks = new short[256][width][length];
final short[][][] newblocks = new short[256][width][length];
final List<Chunk> chunks = new ArrayList<>();
final List<Chunk> processed_chunks = new ArrayList<>();
final List<ChunkLoc> chunks = new ArrayList<>();
final List<ChunkLoc> processed_chunks = new ArrayList<>();
for (int X = cbx; X <= ctx; X++) {
for (int Z = cbz; Z <= ctz; Z++) {
Chunk chunk = world.getChunkAt(X, Z);
chunks.add(chunk);
// Chunk chunk = world.getChunkAt(X, Z);
chunks.add(new ChunkLoc(X, Z));
}
}
final Runnable run = new Runnable() {
@Override
public void run() {
for (Chunk chunk : processed_chunks) {
short[][] result = gen.generateExtBlockSections(world, r, chunk.getX(), chunk.getZ(), base);
int X = chunk.getX();
int Z = chunk.getZ();
for (ChunkLoc chunk : processed_chunks) {
short[][] result = gen.generateExtBlockSections(world, r, chunk.x, chunk.z, base);
int X = chunk.x;
int Z = chunk.z;
int xb = ((X) << 4) - bx;
int zb = ((Z) << 4) - bz;
for (int i = 0; i < result.length; i++) {
@ -128,7 +128,6 @@ public class BukkitHybridUtils extends HybridUtils {
}
}
}
int size = width * length;
int[] changes = new int[size];
int[] faces = new int[size];
@ -176,7 +175,6 @@ public class BukkitHybridUtils extends HybridUtils {
i++;
}
}
// analyze plot
// put in analysis obj
@ -206,18 +204,16 @@ public class BukkitHybridUtils extends HybridUtils {
result.add(analysis.data_sd);
result.add(analysis.air_sd);
result.add(analysis.variety_sd);
Flag flag = new Flag(FlagManager.getFlag("analysis"), result);
FlagManager.addPlotFlag(plot, flag);
System.gc();
System.gc();
whenDone.value = analysis;
whenDone.run();
}
};
System.gc();
AugmentedPopulator.initCache();
TaskManager.index.increment();
final Integer currentIndex = TaskManager.index.toInteger();
final Integer task = TaskManager.runTaskRepeat(new Runnable() {
@ -229,10 +225,11 @@ public class BukkitHybridUtils extends HybridUtils {
TaskManager.runTaskAsync(run);
return;
}
Chunk chunk = chunks.remove(0);
ChunkLoc chunk = chunks.remove(0);
world.loadChunk(chunk.x, chunk.z);
processed_chunks.add(chunk);
int X = chunk.getX();
int Z = chunk.getZ();
int X = chunk.x;
int Z = chunk.z;
int minX;
int minZ;
int maxX;
@ -246,19 +243,24 @@ public class BukkitHybridUtils extends HybridUtils {
if (Z == ctz) maxZ = MathMan.mod(tz);
else maxZ = 16;
int xb = ((X) << 4) - bx;
int zb = ((Z) << 4) - bz;
int cbx = X << 4;
int cbz = Z << 4;
int xb = (cbx) - bx;
int zb = (cbz) - bz;
for (int x = minX; x <= maxX; x++) {
int xx = cbx + cbz;
for (int z = minZ; z <= maxZ; z++) {
int zz = cbz + z;
for (int y = 0; y < 256; y++) {
Block block = chunk.getBlock(x, y, z);
int xx = xb + x;
int zz = zb + z;
newblocks[y][xx][zz] = (short) block.getTypeId();
Block block = world.getBlockAt(xx, y, zz);
int xr = xb + x;
int zr = zb + z;
newblocks[y][xr][zr] = (short) block.getTypeId();
}
}
}
world.unloadChunkRequest(chunk.x, chunk.z, true);
}
}, 1);
TaskManager.tasks.put(currentIndex, task);

View File

@ -23,12 +23,14 @@ package com.intellectualcrafters.plot.generator;
import java.io.File;
import java.io.IOException;
import java.nio.file.Files;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.HashMap;
import java.util.HashSet;
import com.intellectualcrafters.plot.PS;
import com.intellectualcrafters.plot.commands.Template;
import com.intellectualcrafters.plot.object.ChunkLoc;
import com.intellectualcrafters.plot.object.FileBytes;
import com.intellectualcrafters.plot.object.Location;
import com.intellectualcrafters.plot.object.Plot;
@ -173,24 +175,38 @@ public class HybridPlotManager extends ClassicPlotManager {
final Location pos2 = MainUtil.getPlotTopLocAbs(world, plot.id);
setWallFilling(dpw, plot.id, new PlotBlock[] { dpw.WALL_FILLING });
int p1x = pos1.getX();
int p1z = pos1.getZ();
int p2x = pos2.getX();
int p2z = pos2.getZ();
int bcx = p1x >> 4;
int bcz = p1z >> 4;
int tcx = p2x >> 4;
int tcz = p2z >> 4;
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;
boolean canRegen = plotworld.TYPE == 0 && plotworld.TERRAIN == 0;
final boolean canRegen = plotworld.TYPE == 0 && plotworld.TERRAIN == 0;
final PlotBlock[] plotfloor = dpw.TOP_BLOCK;
final PlotBlock[] filling = dpw.MAIN_BLOCK;
final PlotBlock[] bedrock = (dpw.PLOT_BEDROCK ? new PlotBlock[] { new PlotBlock((short) 7, (byte) 0) } : filling);
PlotBlock air = new PlotBlock((short) 0, (byte) 0);
final PlotBlock air = new PlotBlock((short) 0, (byte) 0);
final ArrayList<ChunkLoc> chunks = new ArrayList<ChunkLoc>();
for (int x = bcx; x <= tcx; x++) {
for (int z = bcz; z <= tcz; z++) {
chunks.add(new ChunkLoc(x, z));
}
}
TaskManager.runTask(new Runnable() {
@Override
public void run() {
long start = System.currentTimeMillis();
while (chunks.size() > 0 && System.currentTimeMillis() - start < 20) {
ChunkLoc chunk = chunks.remove(0);
int x = chunk.x;
int z = chunk.z;
int xxb = x << 4;
int zzb = z << 4;
int xxt = xxb + 15;
@ -198,9 +214,6 @@ public class HybridPlotManager extends ClassicPlotManager {
if (canRegen) {
if (xxb >= p1x && xxt <= p2x && zzb >= p1z && zzt <= p2z) {
BukkitUtil.regenerateChunk(world, x, z);
if (!MainUtil.canSendChunk) {
// BukkitUtil.refreshChunk(world, x, z);
}
continue;
}
}
@ -230,11 +243,17 @@ public class HybridPlotManager extends ClassicPlotManager {
top.setY(256);
MainUtil.setSimpleCuboidAsync(world, bot, top, air);
}
if (chunks.size() != 0) {
TaskManager.runTaskLater(this, 1);
}
else {
pastePlotSchematic(dpw, pos1, pos2);
final PlotBlock wall = isDelete ? dpw.WALL_BLOCK : dpw.CLAIMED_WALL_BLOCK;
setWall(dpw, plot.id, new PlotBlock[] { wall });
SetBlockQueue.addNotify(whenDone);
}
}
});
return true;
}

View File

@ -50,13 +50,21 @@ public abstract class HybridUtils {
final int ty = get_ey(world, bx, tx, bz, tz, by);
final Location pos3 = new Location(world, bx, by, bz);
final Location pos4 = new Location(world, tx, ty, tz);
final CompoundTag sideroad = SchematicHandler.manager.getCompoundTag(world, pos1, pos2);
final CompoundTag intersection = SchematicHandler.manager.getCompoundTag(world, pos3, pos4);
final String dir = PS.get().IMP.getDirectory() + File.separator + "schematics" + File.separator + "GEN_ROAD_SCHEMATIC" + File.separator + plot.world + File.separator;
SchematicHandler.manager.save(sideroad, dir + "sideroad.schematic");
SchematicHandler.manager.save(intersection, dir + "intersection.schematic");
SchematicHandler.manager.getCompoundTag(world, pos1, pos2, new RunnableVal<CompoundTag>() {
@Override
public void run() {
SchematicHandler.manager.save(value, dir + "sideroad.schematic");
SchematicHandler.manager.getCompoundTag(world, pos3, pos4, new RunnableVal<CompoundTag>() {
@Override
public void run() {
SchematicHandler.manager.save(value, dir + "intersection.schematic");
plotworld.ROAD_SCHEMATIC_ENABLED = true;
plotworld.setupSchematics();
}
});
}
});
return true;
}

View File

@ -53,11 +53,14 @@ public class StringWrapper {
if (getClass() != obj.getClass()) {
return false;
}
if (obj.hashCode() != hashCode()) {
return false;
}
final StringWrapper other = (StringWrapper) obj;
if ((other.value == null) || (this.value == null)) {
return false;
}
return other.value.toLowerCase().equals(this.value.toLowerCase());
return other.value.equalsIgnoreCase(this.value.toLowerCase());
}
/**
@ -70,6 +73,8 @@ public class StringWrapper {
return this.value;
}
private int hash;
/**
* Get the hash value
*
@ -80,6 +85,9 @@ public class StringWrapper {
if (this.value == null) {
return 0;
}
return this.value.toLowerCase().hashCode();
if (this.hash == 0) {
this.hash = this.value.toLowerCase().hashCode();
}
return hash;
}
}

View File

@ -41,6 +41,7 @@ import com.intellectualcrafters.jnbt.Tag;
import com.intellectualcrafters.plot.PS;
import com.intellectualcrafters.plot.object.ChunkLoc;
import com.intellectualcrafters.plot.object.Location;
import com.intellectualcrafters.plot.object.RunnableVal;
import com.intellectualcrafters.plot.object.schematic.StateWrapper;
/**
@ -52,8 +53,14 @@ import com.intellectualcrafters.plot.object.schematic.StateWrapper;
public class BukkitSchematicHandler extends SchematicHandler {
@Override
public CompoundTag getCompoundTag(final String world, final Location pos1, final Location pos2) {
// loading chunks
public void getCompoundTag(final String world, final Location pos1, final Location pos2, RunnableVal<CompoundTag> whenDone) {
// create schematic one chunk at a time
// load chunk sync
// get blocks async
// add to schematic async
// save final async
int i = 0;
int j = 0;
try {
@ -62,13 +69,15 @@ public class BukkitSchematicHandler extends SchematicHandler {
boolean result = ChunkManager.manager.loadChunk(world, new ChunkLoc(i, j));
if (!result) {
PS.log("&cIllegal selection. Cannot save non-existent chunk at " + (i / 16) + ", " + (j / 16));
return null;
whenDone.run();
return;
}
}
}
} catch (final Exception e) {
PS.log("&cIllegal selection. Cannot save corrupt chunk at " + (i / 16) + ", " + (j / 16));
return null;
whenDone.run();
return;
}
final int width = (pos2.getX() - pos1.getX()) + 1;
final int height = (pos2.getY() - pos1.getY()) + 1;
@ -93,18 +102,20 @@ public class BukkitSchematicHandler extends SchematicHandler {
pos2.getZ();
final int sy = pos1.getY();
pos2.getY();
List<Tag> tileEntities = new ArrayList<Tag>();
World worldObj = Bukkit.getWorld(world);
for (int y = 0; y < height; y++) {
int i1 = (y * width * length);
int syy = sy + y;
for (int z = 0; z < length; z++) {
int i2 = i1 + (z * width);
int szz = sz + z;
for (int x = 0; x < width; x++) {
final int index = i2 + x;
Block block = worldObj.getBlockAt(sx + x, sy + y, sz + z);
Block block = worldObj.getBlockAt(sx + x, syy, szz);
int id = block.getTypeId();
switch(id) {
case 0:
@ -249,6 +260,7 @@ public class BukkitSchematicHandler extends SchematicHandler {
}
}
schematic.put("Blocks", new ByteArrayTag("Blocks", blocks));
schematic.put("Data", new ByteArrayTag("Data", blockData));
schematic.put("Entities", new ListTag("Entities", CompoundTag.class, new ArrayList<Tag>()));
@ -257,7 +269,10 @@ public class BukkitSchematicHandler extends SchematicHandler {
if (addBlocks != null) {
schematic.put("AddBlocks", new ByteArrayTag("AddBlocks", addBlocks));
}
return new CompoundTag("Schematic", schematic);
whenDone.value = new CompoundTag("Schematic", schematic);
whenDone.run();
}

View File

@ -125,8 +125,8 @@ public class ExpireManager {
if (Settings.CLEAR_THRESHOLD != -1 && plotworld.TYPE == 0 && changed != null) {
if (changed.getComplexity() > Settings.CLEAR_THRESHOLD) {
PS.log("$2[&5Expire&dManager$2] &bIgnoring modified plot: " + plot + " : " + changed.getComplexity() + " - " + changed.changes);
FlagManager.addPlotFlag(plot, new Flag(FlagManager.getFlag("modified-blocks"), value));
expiredPlots.get(world).remove(plot);
FlagManager.addPlotFlag(plot, new Flag(FlagManager.getFlag("analysis"), value));
return;
}
}

View File

@ -38,6 +38,7 @@ import com.intellectualcrafters.plot.config.Settings;
import com.intellectualcrafters.plot.object.Location;
import com.intellectualcrafters.plot.object.Plot;
import com.intellectualcrafters.plot.object.PlotId;
import com.intellectualcrafters.plot.object.RunnableVal;
import com.intellectualcrafters.plot.object.schematic.PlotItem;
import com.intellectualcrafters.plot.object.schematic.StateWrapper;
import com.intellectualcrafters.plot.util.bukkit.BukkitUtil;
@ -57,15 +58,11 @@ public abstract class SchematicHandler {
}
exportAll = true;
final ArrayList<Plot> plots = new ArrayList<Plot>(collection);
TaskManager.index.increment();
final Integer currentIndex = TaskManager.index.toInteger();
final int task = TaskManager.runTaskRepeat(new Runnable() {
TaskManager.runTask(new Runnable() {
@Override
public void run() {
if (plots.size() == 0) {
exportAll = false;
Bukkit.getScheduler().cancelTask(TaskManager.tasks.get(currentIndex));
TaskManager.tasks.remove(currentIndex);
TaskManager.runTask(ifSuccess);
return;
}
@ -94,27 +91,38 @@ public abstract class SchematicHandler {
new WorldEditSchematic().saveSchematic(directory + File.separator + name + ".schematic", plot.world, plot.id);
}
else {
final CompoundTag sch = SchematicHandler.manager.getCompoundTag(plot.world, plot.id);
if (sch == null) {
final Runnable THIS = this;
SchematicHandler.manager.getCompoundTag(plot.world, plot.id, new RunnableVal<CompoundTag>() {
@Override
public void run() {
if (value == null) {
MainUtil.sendMessage(null, "&7 - Skipped plot &c" + plot.id);
} else {
}
else {
TaskManager.runTaskAsync(new Runnable() {
@Override
public void run() {
MainUtil.sendMessage(null, "&6ID: " + plot.id);
final boolean result = SchematicHandler.manager.save(sch, directory + File.separator + name + ".schematic");
final boolean result = SchematicHandler.manager.save(value, directory + File.separator + name + ".schematic");
if (!result) {
MainUtil.sendMessage(null, "&7 - Failed to save &c" + plot.id);
} else {
MainUtil.sendMessage(null, "&7 - &a success: " + plot.id);
}
TaskManager.runTask(new Runnable() {
@Override
public void run() {
THIS.run();
}
});
}
});
}
}
});
}
}, 20);
TaskManager.tasks.put(currentIndex, task);
}
});
return true;
}
@ -409,16 +417,16 @@ public abstract class SchematicHandler {
*
* @return tag
*/
public CompoundTag getCompoundTag(final String world, final PlotId id) {
public void getCompoundTag(final String world, final PlotId id, RunnableVal<CompoundTag> whenDone) {
if (!PS.get().getPlots(world).containsKey(id)) {
return null;
whenDone.run();
}
final Location pos1 = MainUtil.getPlotBottomLoc(world, id).add(1, 0, 1);
final Location pos2 = MainUtil.getPlotTopLoc(world, id);
return getCompoundTag(world, pos1, pos2);
getCompoundTag(world, pos1, pos2, whenDone);
}
public abstract CompoundTag getCompoundTag(final String world, final Location pos1, final Location pos2);
public abstract void getCompoundTag(final String world, final Location pos1, final Location pos2, RunnableVal<CompoundTag> whenDone);
public boolean pastePart(final String world, final DataCollection[] blocks, final Location l1, final int x_offset, final int z_offset, final int i1, final int i2, final int WIDTH, final int LENGTH) {
int length = 0;

View File

@ -210,7 +210,10 @@ public class UUIDHandler {
String name = (String) bukkit.get("lastKnownName");
long last = (long) bukkit.get("lastPlayed");
if (Settings.OFFLINE_MODE) {
if (!Settings.UUID_LOWERCASE || !name.toLowerCase().equals(name)) {
if (Settings.UUID_LOWERCASE && !name.toLowerCase().equals(name)) {
uuid = uuidWrapper.getUUID(name);
}
else {
long most = (long) compound.get("UUIDMost");
long least = (long) compound.get("UUIDLeast");
uuid = new UUID(most, least);