Some tweaks / optimizations

This commit is contained in:
Jesse Boyd 2017-09-25 16:57:42 +10:00
parent 92f94ecedc
commit 0d608245f5
No known key found for this signature in database
GPG Key ID: 59F1DE6293AF6E1F
15 changed files with 173 additions and 30 deletions

View File

@ -51,6 +51,7 @@ import com.plotsquared.bukkit.listeners.PlayerEvents_1_9;
import com.plotsquared.bukkit.listeners.PlotPlusListener; import com.plotsquared.bukkit.listeners.PlotPlusListener;
import com.plotsquared.bukkit.listeners.PlotPlusListener_1_12; import com.plotsquared.bukkit.listeners.PlotPlusListener_1_12;
import com.plotsquared.bukkit.listeners.PlotPlusListener_Legacy; import com.plotsquared.bukkit.listeners.PlotPlusListener_Legacy;
import com.plotsquared.bukkit.listeners.SingleWorldListener;
import com.plotsquared.bukkit.listeners.WorldEvents; import com.plotsquared.bukkit.listeners.WorldEvents;
import com.plotsquared.bukkit.titles.DefaultTitle_111; import com.plotsquared.bukkit.titles.DefaultTitle_111;
import com.plotsquared.bukkit.util.BukkitChatManager; import com.plotsquared.bukkit.util.BukkitChatManager;
@ -158,6 +159,7 @@ public final class BukkitMain extends JavaPlugin implements Listener, IPlotMain
private int[] version; private int[] version;
private String name; private String name;
private SingleWorldListener singleWorldListener;
@Override @Override
public int[] getServerVersion() { public int[] getServerVersion() {
@ -200,10 +202,19 @@ public final class BukkitMain extends JavaPlugin implements Listener, IPlotMain
public void run() { public void run() {
unload(); unload();
} }
}, 5); }, 20);
try {
singleWorldListener = new SingleWorldListener(this);
} catch (Exception e) {
e.printStackTrace();
}
} }
} }
public SingleWorldListener getSingleWorldListener() {
return singleWorldListener;
}
public void unload() { public void unload() {
PlotAreaManager manager = PS.get().getPlotAreaManager(); PlotAreaManager manager = PS.get().getPlotAreaManager();
if (manager instanceof SinglePlotAreaManager) { if (manager instanceof SinglePlotAreaManager) {

View File

@ -11,6 +11,7 @@ import com.intellectualcrafters.plot.object.PlotId;
import com.intellectualcrafters.plot.object.PlotManager; import com.intellectualcrafters.plot.object.PlotManager;
import com.intellectualcrafters.plot.object.PseudoRandom; import com.intellectualcrafters.plot.object.PseudoRandom;
import com.intellectualcrafters.plot.object.SetupObject; import com.intellectualcrafters.plot.object.SetupObject;
import com.intellectualcrafters.plot.object.worlds.SingleWorldGenerator;
import com.intellectualcrafters.plot.util.ChunkManager; import com.intellectualcrafters.plot.util.ChunkManager;
import com.intellectualcrafters.plot.util.MainUtil; import com.intellectualcrafters.plot.util.MainUtil;
import com.intellectualcrafters.plot.util.MathMan; import com.intellectualcrafters.plot.util.MathMan;
@ -57,9 +58,8 @@ public class BukkitPlotGenerator extends ChunkGenerator implements GeneratorWrap
if (queue == null) { if (queue == null) {
queue = GlobalBlockQueue.IMP.getNewQueue(world.getName(), false); queue = GlobalBlockQueue.IMP.getNewQueue(world.getName(), false);
} }
ChunkLoc loc = new ChunkLoc(c.getX(), c.getZ()); byte[][] resultData = dataMap.isEmpty() ? null : dataMap.remove(new ChunkLoc(c.getX(), c.getZ()));
byte[][] resultData; if (resultData == null) {
if (!BukkitPlotGenerator.this.dataMap.containsKey(loc)) {
GenChunk result = BukkitPlotGenerator.this.chunkSetter; GenChunk result = BukkitPlotGenerator.this.chunkSetter;
// Set the chunk location // Set the chunk location
result.setChunk(c); result.setChunk(c);
@ -69,10 +69,8 @@ public class BukkitPlotGenerator extends ChunkGenerator implements GeneratorWrap
result.grid = null; result.grid = null;
result.cd = null; result.cd = null;
// Catch any exceptions (as exceptions usually thrown) // Catch any exceptions (as exceptions usually thrown)
generate(world, loc.x, loc.z, result); generate(world, c.getX(), c.getZ(), result);
resultData = result.result_data; resultData = result.result_data;
} else {
resultData = BukkitPlotGenerator.this.dataMap.remove(loc);
} }
if (resultData != null) { if (resultData != null) {
for (int i = 0; i < resultData.length; i++) { for (int i = 0; i < resultData.length; i++) {
@ -256,6 +254,9 @@ public class BukkitPlotGenerator extends ChunkGenerator implements GeneratorWrap
@Override @Override
public ChunkData generateChunkData(World world, Random random, int cx, int cz, BiomeGrid grid) { public ChunkData generateChunkData(World world, Random random, int cx, int cz, BiomeGrid grid) {
GenChunk result = this.chunkSetter; GenChunk result = this.chunkSetter;
if (this.getPlotGenerator() instanceof SingleWorldGenerator) {
if (result.cd != null) return result.cd;
}
// Set the chunk location // Set the chunk location
result.setChunk(new ChunkWrapper(world.getName(), cx, cz)); result.setChunk(new ChunkWrapper(world.getName(), cx, cz));
// Set the result data // Set the result data
@ -318,8 +319,12 @@ public class BukkitPlotGenerator extends ChunkGenerator implements GeneratorWrap
return this.platformGenerator.generateExtBlockSections(world, r, cx, cz, grid); return this.platformGenerator.generateExtBlockSections(world, r, cx, cz, grid);
} else { } else {
generate(world, cx, cz, result); generate(world, cx, cz, result);
this.dataMap.put(new ChunkLoc(cx, cz), result.result_data); for (int i = 0; i < result.result_data.length; i++) {
if (result.result_data[i] != null) {
this.dataMap.put(new ChunkLoc(cx, cz), result.result_data);
break;
}
}
} }
} catch (Throwable e) { } catch (Throwable e) {
e.printStackTrace(); e.printStackTrace();

View File

@ -38,7 +38,6 @@ public class ChunkListener implements Listener {
private RefField mustSave; private RefField mustSave;
private Chunk lastChunk; private Chunk lastChunk;
public ChunkListener() { public ChunkListener() {
if (Settings.Chunk_Processor.AUTO_TRIM) { if (Settings.Chunk_Processor.AUTO_TRIM) {
try { try {

View File

@ -0,0 +1,101 @@
package com.plotsquared.bukkit.listeners;
import com.intellectualcrafters.plot.PS;
import com.intellectualcrafters.plot.object.worlds.PlotAreaManager;
import com.intellectualcrafters.plot.object.worlds.SinglePlotAreaManager;
import com.intellectualcrafters.plot.util.ReflectionUtils;
import java.lang.reflect.Field;
import java.lang.reflect.Method;
import org.bukkit.Bukkit;
import org.bukkit.Chunk;
import org.bukkit.World;
import org.bukkit.event.EventHandler;
import org.bukkit.event.EventPriority;
import org.bukkit.event.Listener;
import org.bukkit.event.world.ChunkEvent;
import org.bukkit.event.world.ChunkLoadEvent;
import org.bukkit.plugin.Plugin;
import static com.intellectualcrafters.plot.util.ReflectionUtils.getRefClass;
public class SingleWorldListener implements Listener {
private Method methodGetHandleChunk;
private Field mustSave, done, lit, s;
public SingleWorldListener(Plugin plugin) throws Exception {
ReflectionUtils.RefClass classChunk = getRefClass("{nms}.Chunk");
ReflectionUtils.RefClass classCraftChunk = getRefClass("{cb}.CraftChunk");
this.methodGetHandleChunk = classCraftChunk.getMethod("getHandle").getRealMethod();
this.mustSave = classChunk.getField("mustSave").getRealField();
try {
this.done = classChunk.getField("done").getRealField();
this.lit = classChunk.getField("lit").getRealField();
this.s = classChunk.getField("s").getRealField();
} catch (Throwable ignore) {
ignore.printStackTrace();
}
Bukkit.getPluginManager().registerEvents(this, plugin);
}
public void markChunkAsClean(Chunk chunk) {
try {
Object nmsChunk = methodGetHandleChunk.invoke(chunk);
if (done != null) this.done.set(nmsChunk, true);
if (mustSave != null) this.mustSave.set(nmsChunk, false);
if (lit != null) this.lit.set(nmsChunk, false);
if (s != null) this.s.set(nmsChunk, false);
} catch (Throwable e) {
e.printStackTrace();
}
}
private void handle(ChunkEvent event) {
World world = event.getWorld();
String name = world.getName();
PlotAreaManager man = PS.get().getPlotAreaManager();
if (!(man instanceof SinglePlotAreaManager)) return;
if (!isPlotId(name)) return;
markChunkAsClean(event.getChunk());
}
// @EventHandler
// public void onPopulate(ChunkPopulateEvent event) {
// handle(event);
// }
@EventHandler(priority = EventPriority.LOWEST)
public void onChunkLoad(ChunkLoadEvent event) {
handle(event);
}
private boolean isPlotId(String worldName) {
int len = worldName.length();
int separator = 0;
for (int i = 0; i < len; i++) {
switch (worldName.charAt(i)) {
case ',':
case ';':
separator++;
break;
case '-':
case '0':
case '1':
case '2':
case '3':
case '4':
case '5':
case '6':
case '7':
case '8':
case '9':
break;
default:
return false;
}
}
return separator == 1;
}
}

View File

@ -187,7 +187,7 @@ public class BukkitUtil extends WorldUtil {
if (block != null) { if (block != null) {
Material type = block.getType(); Material type = block.getType();
if (type.isSolid()) { if (type.isSolid()) {
if (air > 1) return y + 1; if (air > 1) return y;
air = 0; air = 0;
} else { } else {
switch (type) { switch (type) {
@ -201,7 +201,7 @@ public class BukkitUtil extends WorldUtil {
} }
} }
} }
return bukkitWorld.getMaxHeight(); return bukkitWorld.getMaxHeight() - 1;
} }
@Override @Override

View File

@ -6,6 +6,7 @@ import com.intellectualcrafters.plot.object.PlotBlock;
import com.intellectualcrafters.plot.util.MainUtil; import com.intellectualcrafters.plot.util.MainUtil;
import com.intellectualcrafters.plot.util.block.ScopedLocalBlockQueue; import com.intellectualcrafters.plot.util.block.ScopedLocalBlockQueue;
import com.plotsquared.bukkit.util.BukkitUtil; import com.plotsquared.bukkit.util.BukkitUtil;
import java.util.Arrays;
import org.bukkit.Chunk; import org.bukkit.Chunk;
import org.bukkit.World; import org.bukkit.World;
import org.bukkit.block.Biome; import org.bukkit.block.Biome;
@ -72,6 +73,24 @@ public class GenChunk extends ScopedLocalBlockQueue {
} }
} }
@Override
public void setCuboid(Location pos1, Location pos2, PlotBlock block) {
if (block.data == 0 && result != null && pos1.getX() == 0 && pos1.getZ() == 0 && pos2.getX() == 15 && pos2.getZ() == 15) {
for (int y = pos1.getY(); y <= pos2.getY(); y++) {
int layer = y >> 4;
short[] data = result[layer];
if (data == null) {
result[layer] = data = new short[4096];
}
int start = y << 8;
int end = start + 256;
Arrays.fill(data, start, end, block.id);
}
} else {
super.setCuboid(pos1, pos2, block);
}
}
@Override @Override
public boolean setBiome(int x, int z, String biome) { public boolean setBiome(int x, int z, String biome) {
return setBiome(x, z, Biome.valueOf(biome.toUpperCase())); return setBiome(x, z, Biome.valueOf(biome.toUpperCase()));

View File

@ -442,7 +442,7 @@ public class Area extends SubCommand {
RegionWrapper region = area.getRegion(); RegionWrapper region = area.getRegion();
center = new Location(area.worldname, region.minX + (region.maxX - region.minX) / 2, 0, center = new Location(area.worldname, region.minX + (region.maxX - region.minX) / 2, 0,
region.minZ + (region.maxZ - region.minZ) / 2); region.minZ + (region.maxZ - region.minZ) / 2);
center.setY(WorldUtil.IMP.getHighestBlock(area.worldname, center.getX(), center.getZ())); center.setY(1 + WorldUtil.IMP.getHighestBlock(area.worldname, center.getX(), center.getZ()));
} }
player.teleport(center); player.teleport(center);
return true; return true;

View File

@ -54,7 +54,7 @@ public class HybridPlotWorld extends ClassicPlotWorld {
Location bot = plot.getBottomAbs(); Location bot = plot.getBottomAbs();
if (SIGN_LOCATION == null) { if (SIGN_LOCATION == null) {
bot.setY(ROAD_HEIGHT + 1); bot.setY(ROAD_HEIGHT + 1);
return bot.add(-1, ROAD_HEIGHT, -2); return bot.add(-1, 1, -2);
} else { } else {
bot.setY(0); bot.setY(0);
Location loc = bot.add(SIGN_LOCATION.getX(), SIGN_LOCATION.getY(), SIGN_LOCATION.getZ()); Location loc = bot.add(SIGN_LOCATION.getX(), SIGN_LOCATION.getY(), SIGN_LOCATION.getZ());

View File

@ -1134,8 +1134,8 @@ public class Plot {
int z = largest.minZ - 1; int z = largest.minZ - 1;
PlotManager manager = getManager(); PlotManager manager = getManager();
int y = isLoaded() ? WorldUtil.IMP.getHighestBlock(getWorldName(), x, z) : 64; int y = isLoaded() ? WorldUtil.IMP.getHighestBlock(getWorldName(), x, z) : 64;
if (area.ALLOW_SIGNS) { if (area.ALLOW_SIGNS && (y <= 0 || y >= 255)) {
y = Math.max(y, manager.getSignLoc(area, this).getY()); y = Math.max(y, manager.getSignLoc(area, this).getY() - 1);
} }
return new Location(getWorldName(), x, y + 1, z); return new Location(getWorldName(), x, y + 1, z);
} }
@ -1147,13 +1147,15 @@ public class Plot {
public Location getHome() { public Location getHome() {
BlockLoc home = this.getPosition(); BlockLoc home = this.getPosition();
if (home == null || home.x == 0 && home.z == 0) { if (home == null || home.x == 0 && home.z == 0) {
System.out.println("Default");
return this.getDefaultHome(true); return this.getDefaultHome(true);
} else { } else {
System.out.println("Custom");
Location bot = this.getBottomAbs(); Location bot = this.getBottomAbs();
Location loc = new Location(bot.getWorld(), bot.getX() + home.x, bot.getY() + home.y, bot.getZ() + home.z, home.yaw, home.pitch); Location loc = new Location(bot.getWorld(), bot.getX() + home.x, bot.getY() + home.y, bot.getZ() + home.z, home.yaw, home.pitch);
if (!isLoaded()) return loc; if (!isLoaded()) return loc;
if (WorldUtil.IMP.getBlock(loc).id != 0) { if (WorldUtil.IMP.getBlock(loc).id != 0) {
loc.setY(Math.max(WorldUtil.IMP.getHighestBlock(this.getWorldName(), loc.getX(), loc.getZ()), bot.getY())); loc.setY(Math.max(1 + WorldUtil.IMP.getHighestBlock(this.getWorldName(), loc.getX(), loc.getZ()), bot.getY()));
} }
return loc; return loc;
} }

View File

@ -139,7 +139,7 @@ public class PlotCluster {
} }
int max = MainUtil.getHeighestBlock(this.area.worldname, toReturn.getX(), toReturn.getZ()); int max = MainUtil.getHeighestBlock(this.area.worldname, toReturn.getX(), toReturn.getZ());
if (max > toReturn.getY()) { if (max > toReturn.getY()) {
toReturn.setY(max); toReturn.setY(1 + max);
} }
return toReturn; return toReturn;
} }

View File

@ -9,6 +9,7 @@ import com.intellectualcrafters.plot.object.PlotId;
import com.intellectualcrafters.plot.object.PlotManager; import com.intellectualcrafters.plot.object.PlotManager;
import com.intellectualcrafters.plot.util.MainUtil; import com.intellectualcrafters.plot.util.MainUtil;
import com.intellectualcrafters.plot.util.SetupUtils; import com.intellectualcrafters.plot.util.SetupUtils;
import com.intellectualcrafters.plot.util.TaskManager;
import java.io.File; import java.io.File;
import java.util.ArrayList; import java.util.ArrayList;
@ -34,11 +35,16 @@ public class SinglePlotManager extends PlotManager {
} }
@Override @Override
public boolean clearPlot(PlotArea plotArea, Plot plot, Runnable whenDone) { public boolean clearPlot(PlotArea plotArea, Plot plot, final Runnable whenDone) {
SetupUtils.manager.unload(plot.getWorldName(), false); SetupUtils.manager.unload(plot.getWorldName(), false);
File worldFolder = new File(PS.get().IMP.getWorldContainer(), plot.getWorldName()); final File worldFolder = new File(PS.get().IMP.getWorldContainer(), plot.getWorldName());
MainUtil.deleteDirectory(worldFolder); TaskManager.IMP.taskAsync(new Runnable() {
if (whenDone != null) whenDone.run(); @Override
public void run() {
MainUtil.deleteDirectory(worldFolder);
if (whenDone != null) whenDone.run();
}
});
return true; return true;
} }

View File

@ -565,7 +565,7 @@ public class MainUtil {
public static int getHeighestBlock(String world, int x, int z) { public static int getHeighestBlock(String world, int x, int z) {
int result = WorldUtil.IMP.getHighestBlock(world, x, z); int result = WorldUtil.IMP.getHighestBlock(world, x, z);
if (result == 0) { if (result == 0) {
return 64; return 63;
} }
return result; return result;
} }

View File

@ -183,7 +183,7 @@ public abstract class SchematicHandler {
if (pw instanceof ClassicPlotWorld) { if (pw instanceof ClassicPlotWorld) {
y_offset_actual = yOffset + ((ClassicPlotWorld) pw).PLOT_HEIGHT; y_offset_actual = yOffset + ((ClassicPlotWorld) pw).PLOT_HEIGHT;
} else { } else {
y_offset_actual = yOffset + MainUtil.getHeighestBlock(plot.getWorldName(), region.minX + 1, region.minZ + 1); y_offset_actual = yOffset + 1 + MainUtil.getHeighestBlock(plot.getWorldName(), region.minX + 1, region.minZ + 1);
} }
} }
} }

View File

@ -90,7 +90,7 @@ public abstract class LocalBlockQueue {
GlobalBlockQueue.IMP.enqueue(this); GlobalBlockQueue.IMP.enqueue(this);
} }
public final void setCuboid(Location pos1, Location pos2, PlotBlock block) { public void setCuboid(Location pos1, Location pos2, PlotBlock block) {
for (int y = pos1.getY(); y <= Math.min(255, pos2.getY()); y++) { for (int y = pos1.getY(); y <= Math.min(255, pos2.getY()); y++) {
for (int x = pos1.getX(); x <= pos2.getX(); x++) { for (int x = pos1.getX(); x <= pos2.getX(); x++) {
for (int z = pos1.getZ(); z <= pos2.getZ(); z++) { for (int z = pos1.getZ(); z <= pos2.getZ(); z++) {
@ -100,7 +100,7 @@ public abstract class LocalBlockQueue {
} }
} }
public final void setCuboid(Location pos1, Location pos2, PlotBlock[] blocks) { public void setCuboid(Location pos1, Location pos2, PlotBlock[] blocks) {
for (int y = pos1.getY(); y <= Math.min(255, pos2.getY()); y++) { for (int y = pos1.getY(); y <= Math.min(255, pos2.getY()); y++) {
for (int x = pos1.getX(); x <= pos2.getX(); x++) { for (int x = pos1.getX(); x <= pos2.getX(); x++) {
for (int z = pos1.getZ(); z <= pos2.getZ(); z++) { for (int z = pos1.getZ(); z <= pos2.getZ(); z++) {

View File

@ -332,7 +332,7 @@ public class SpongeUtil extends WorldUtil {
@Override @Override
public Location getSpawn(String world) { public Location getSpawn(String world) {
Location result = SpongeUtil.getLocation(world, SpongeUtil.getWorld(world).getSpawnLocation()); Location result = SpongeUtil.getLocation(world, SpongeUtil.getWorld(world).getSpawnLocation());
result.setY(getHighestBlock(world, result.getX(), result.getZ())); result.setY(1 + getHighestBlock(world, result.getX(), result.getZ()));
return result; return result;
} }
@ -392,15 +392,15 @@ public class SpongeUtil extends WorldUtil {
public int getHighestBlock(String worldName, int x, int z) { public int getHighestBlock(String worldName, int x, int z) {
World world = SpongeUtil.getWorld(worldName); World world = SpongeUtil.getWorld(worldName);
if (world == null) { if (world == null) {
return 64; return 63;
} }
for (int y = 255; y > 0; y--) { for (int y = 255; y > 0; y--) {
BlockState block = world.getBlock(x, y, z); BlockState block = world.getBlock(x, y, z);
if (block.getType() != BlockTypes.AIR) { if (block.getType() != BlockTypes.AIR) {
return y + 1; return y;
} }
} }
return 64; return 63;
} }
@Override @Override