Fixed plot clearing on sub chunk sized plots
Optimized chunk generation
Fixed several messages including setup having incorrect replaced args
This commit is contained in:
boy0001 2015-07-19 03:03:59 +10:00
parent 1723d8266b
commit ea8f026105
5 changed files with 116 additions and 139 deletions

View File

@ -24,6 +24,7 @@ import java.io.File;
import java.util.EnumSet;
import java.util.HashMap;
import java.util.HashSet;
import java.util.LinkedHashMap;
import java.util.Map;
import java.util.Set;
@ -179,7 +180,7 @@ public enum C {
CANNOT_AFFORD_PLOT("$2You cannot afford to buy this plot. It costs $1%s", "Economy"),
NOT_FOR_SALE("$2This plot is not for sale", "Economy"),
CANNOT_BUY_OWN("$2You cannot buy your own plot", "Economy"),
PLOT_SOLD("$4Your plot; $1%s$4, has been sold to $1%s$4 for $1$%s", "Economy"),
PLOT_SOLD("$4Your plot; $1%s0$4, has been sold to $1%s1$4 for $1$%s2", "Economy"),
CANNOT_AFFORD_MERGE("$2You cannot afford to merge the plots. It costs $1%s", "Economy"),
ADDED_BALANCE("$1%s $2has been added to your balance", "Economy"),
REMOVED_BALANCE("$1%s $2has been taken from your balance", "Economy"),
@ -187,9 +188,9 @@ public enum C {
* Setup Stuff
*/
SETUP_INIT("$1Usage: $2/plot setup <value>", "Setup"),
SETUP_STEP("$3[$1Step %s$3] $1%s $2- $1Expecting: $2%s $1Default: $2%s", "Setup"),
SETUP_INVALID_ARG("$2%s is not a valid argument for step %s. To cancel setup use: $1/plot setup cancel", "Setup"),
SETUP_VALID_ARG("$2Value $1%s $2set to %s", "Setup"),
SETUP_STEP("$3[$1Step %s0$3] $1%s1 $2- $1Expecting: $2%s2 $1Default: $2%s3", "Setup"),
SETUP_INVALID_ARG("$2%s0 is not a valid argument for step %s1. To cancel setup use: $1/plot setup cancel", "Setup"),
SETUP_VALID_ARG("$2Value $1%s0 $2set to %s1", "Setup"),
SETUP_FINISHED("$3If you are using MULTIVERSE or MULTIWORLD the world should have just been created. Otherwise you will need to add the world manually through the bukkit.yml", "Setup"),
SETUP_WORLD_TAKEN("$2%s is already a registered plotworld", "Setup"),
SETUP_MISSING_WORLD("$2You need to specify a world name ($1/plot setup &l<world>$1 <generator>$2)&-$1Additional commands:&-$2 - $1/plot setup <value>&-$2 - $1/plot setup back&-$2 - $1/plot setup cancel", "Setup"),
@ -274,7 +275,7 @@ public enum C {
*/
NOT_VALID_SUBCOMMAND("$2That is not a valid subcommand", "Commands"),
DID_YOU_MEAN("$2Did you mean: $1%s", "Commands"),
NAME_LITTLE("$2%s name is too short, $1%s$2<$1%s", "Commands"),
NAME_LITTLE("$2%s0 name is too short, $1%s1$2<$1%s3", "Commands"),
NO_COMMANDS("$2I'm sorry, but you're not permitted to use any subcommands.", "Commands"),
SUBCOMMAND_SET_OPTIONS_HEADER("$2Possible Values: ", "Commands"),
COMMAND_SYNTAX("$1Usage: $2%s", "Commands"),
@ -559,7 +560,7 @@ public enum C {
if (args.length == 0) {
return m;
}
Map<String, String> map = new HashMap<String, String>();
Map<String, String> map = new LinkedHashMap<String, String>();
if (args.length > 0) {
for (int i = args.length - 1 ; i >= 0; i--) {
if (args[i] == null) {

View File

@ -78,6 +78,7 @@ public class HybridGen extends PlotGenerator {
short pathWidthUpper;
boolean doState = false;
int maxY = 0;
short[][] cached;
/**
* Initialize variables, and create plotworld object used in calculations
@ -125,6 +126,26 @@ public class HybridGen extends PlotGenerator {
if (this.maxY == 0) {
this.maxY = 256;
}
// create cached chunk (for optimized chunk generation)
if (!this.plotworld.PLOT_SCHEMATIC) {
this.cached = new short[(plotheight + 16) / 16][];
for (int i = 0; i < cached.length; i++) {
cached[i] = new short[4096];
}
PseudoRandom random = new PseudoRandom();
for (int x = 0; x < 16; x++) {
for (int z = 0; z < 16; z++) {
cached[CACHE_I[plotheight][x][z]][CACHE_J[plotheight][x][z]] = plotfloors[random.random(plotfloors.length)];
if (this.plotworld.PLOT_BEDROCK) {
cached[CACHE_I[0][x][z]][CACHE_J[0][x][z]] = 7;
}
for (int y = 1; y < plotheight; y++) {
cached[CACHE_I[y][x][z]][CACHE_J[y][x][z]] = filling[random.random(filling.length)];
}
}
}
}
}
/**
@ -163,14 +184,6 @@ public class HybridGen extends PlotGenerator {
* generator
*/
public void generateChunk(final World world, RegionWrapper region, final PseudoRandom random, final int cx, final int cz, final BiomeGrid biomes) {
if (this.plotworld.PLOT_BEDROCK) {
for (short x = 0; x < 16; x++) {
for (short z = 0; z < 16; z++) {
setBlock(x, 0, z, (short) 7);
}
}
}
int sx = (short) ((this.X - this.plotworld.ROAD_OFFSET_X) % this.size);
int sz = (short) ((this.Z - this.plotworld.ROAD_OFFSET_Z) % this.size);
if (sx < 0) {
@ -180,13 +193,32 @@ public class HybridGen extends PlotGenerator {
sz += this.size;
}
if (biomes != null) {
for (short x = 0; x < 16; x++) {
for (short z = 0; z < 16; z++) {
biomes.setBiome(x, z, this.biome);
}
}
}
if (cached != null) {
if (sx > pathWidthLower && sz > pathWidthLower && sx + 15 < pathWidthUpper&& sz + 15 < pathWidthUpper) {
setResult(cached);
return;
}
}
if (this.plotworld.PLOT_BEDROCK) {
for (short x = 0; x < 16; x++) {
for (short z = 0; z < 16; z++) {
setBlock(x, 0, z, (short) 7);
}
}
}
if (region != null) {
for (short x = 0; x < 16; x++) {
final int absX = ((sx + x) % this.size);
for (short z = 0; z < 16; z++) {
if (biomes != null) {
biomes.setBiome(x, z, this.biome);
}
if (contains(region, x, z)) {
for (short y = 1; y < this.plotheight; y++) {
setBlock(x, y, z, this.filling);
@ -211,9 +243,6 @@ public class HybridGen extends PlotGenerator {
final boolean gx = absX > this.pathWidthLower;
final boolean lx = absX < this.pathWidthUpper;
for (short z = 0; z < 16; z++) {
if (biomes != null) {
biomes.setBiome(x, z, this.biome);
}
final int absZ = ((sz + z) % this.size);
final boolean gz = absZ > this.pathWidthLower;
final boolean lz = absZ < this.pathWidthUpper;

View File

@ -171,131 +171,70 @@ public class HybridPlotManager extends ClassicPlotManager {
final HybridPlotWorld dpw = ((HybridPlotWorld) plotworld);
final Location pos1 = MainUtil.getPlotBottomLocAbs(world, plot.id).add(1, 0, 1);
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;
boolean canRegen = plotworld.TYPE == 0 && plotworld.TERRAIN == 0;
final PlotBlock[] plotfloor = dpw.TOP_BLOCK;
final PlotBlock[] filling = dpw.MAIN_BLOCK;
final PlotBlock wall;
if (isDelete) {
wall = dpw.WALL_BLOCK;
} else {
wall = dpw.CLAIMED_WALL_BLOCK;
}
final PlotBlock wall_filling = dpw.WALL_FILLING;
setWallFilling(dpw, plot.id, new PlotBlock[] { wall_filling });
final int maxy = BukkitUtil.getMaxHeight(world);
final short bedrock = (short) (dpw.PLOT_BEDROCK ? 7 : 0);
final int startX = (pos1.getX() / 16) * 16;
final int startZ = (pos1.getZ() / 16) * 16;
final int chunkX = 16 + pos2.getX();
final int chunkZ = 16 + pos2.getZ();
final Location l1 = MainUtil.getPlotBottomLoc(world, plot.id);
final Location l2 = MainUtil.getPlotTopLoc(world, plot.id);
final int plotMinX = l1.getX() + 1;
final int plotMinZ = l1.getZ() + 1;
final int plotMaxX = l2.getX();
final int plotMaxZ = l2.getZ();
Location mn = null;
Location mx = null;
if (plotworld.TYPE == 0 && plotworld.TERRAIN == 0) {
for (int i = startX; i < chunkX; i += 16) {
for (int j = startZ; j < chunkZ; j += 16) {
final Plot plot1 = MainUtil.getPlot(new Location(world, i, 0, j));
if ((plot1 != null) && (!plot1.getId().equals(plot.getId()))) {
break;
}
final Plot plot2 = MainUtil.getPlot(new Location(world, i + 15, 0, j));
if ((plot2 != null) && (!plot2.getId().equals(plot.getId()))) {
break;
}
final Plot plot3 = MainUtil.getPlot(new Location(world, i + 15, 0, j + 15));
if ((plot3 != null) && (!plot3.getId().equals(plot.getId()))) {
break;
}
final Plot plot4 = MainUtil.getPlot(new Location(world, i, 0, j + 15));
if ((plot4 != null) && (!plot4.getId().equals(plot.getId()))) {
break;
}
final Plot plot5 = MainUtil.getPlot(new Location(world, i + 15, 0, j + 15));
if ((plot5 != null) && (!plot5.getId().equals(plot.getId()))) {
break;
}
if (mn == null) {
mn = new Location(world, Math.max(i - 1, plotMinX), 0, Math.max(j - 1, plotMinZ));
mx = new Location(world, Math.min(i + 16, plotMaxX), 0, Math.min(j + 16, plotMaxZ));
} else if ((mx.getZ() < (j + 15)) || (mx.getX() < (i + 15))) {
mx = new Location(world, Math.min(i + 16, plotMaxX), 0, Math.min(j + 16, plotMaxZ));
}
final int I = i;
final int J = j;
BukkitUtil.regenerateChunk(world, I / 16, J / 16);
final PlotBlock[] bedrock = (dpw.PLOT_BEDROCK ? new PlotBlock[] { new PlotBlock((short) 7, (byte) 0) } : filling);
PlotBlock air = new PlotBlock((short) 0, (byte) 0);
for (int x = bcx; x <= tcx; x++) {
for (int z = bcz; z <= tcz; z++) {
int xxb = x << 4;
int zzb = z << 4;
int xxt = xxb + 15;
int zzt = zzb + 15;
if (canRegen) {
if (xxb >= p1x && xxt <= p2x && zzb >= p1z && zzt <= p2z) {
BukkitUtil.regenerateChunk(world, x, z);
if (!MainUtil.canSendChunk) {
BukkitUtil.refreshChunk(world, I / 16, J / 16);
// BukkitUtil.refreshChunk(world, x, z);
}
continue;
}
}
if (x == bcx) {
xxb = p1x;
}
if (x == tcx) {
xxt = p2x;
}
if (z == bcz) {
zzb = p1z;
}
if (z == tcz) {
zzt = p2z;
}
BukkitUtil.setBiome(plot.world, xxb, zzb, xxt, zzt, dpw.PLOT_BIOME);
Location bot = new Location(world, xxb, 0, zzb);
Location top = new Location(world, xxt + 1, 1, zzt + 1);
MainUtil.setCuboidAsync(world, bot, top, bedrock);
bot.setY(1);
top.setY(dpw.PLOT_HEIGHT);
MainUtil.setCuboidAsync(world, bot, top, filling);
bot.setY(dpw.PLOT_HEIGHT);
top.setY(dpw.PLOT_HEIGHT + 1);
MainUtil.setCuboidAsync(world, bot, top, plotfloor);
bot.setY(dpw.PLOT_HEIGHT + 1);
top.setY(256);
MainUtil.setSimpleCuboidAsync(world, bot, top, air);
}
}
pastePlotSchematic(dpw, pos1, pos2);
final PlotBlock wall = isDelete ? dpw.WALL_BLOCK : dpw.CLAIMED_WALL_BLOCK;
setWall(dpw, plot.id, new PlotBlock[] { wall });
final Location max = mx;
final Location min = mn;
TaskManager.runTaskAsync(new Runnable() {
@Override
public void run() {
if (min == null) {
MainUtil.setSimpleCuboidAsync(world, new Location(world, pos1.getX(), 0, pos1.getZ()), new Location(world, pos2.getX() + 1, 1, pos2.getZ() + 1), new PlotBlock(bedrock, (byte) 0));
MainUtil.setSimpleCuboidAsync(world, new Location(world, pos1.getX(), dpw.PLOT_HEIGHT + 1, pos1.getZ()), new Location(world, pos2.getX() + 1, maxy + 1, pos2.getZ() + 1), new PlotBlock((short) 0, (byte) 0));
MainUtil.setCuboidAsync(world, new Location(world, pos1.getX(), 1, pos1.getZ()), new Location(world, pos2.getX() + 1, dpw.PLOT_HEIGHT, pos2.getZ() + 1), filling);
MainUtil.setCuboidAsync(world, new Location(world, pos1.getX(), dpw.PLOT_HEIGHT, pos1.getZ()), new Location(world, pos2.getX() + 1, dpw.PLOT_HEIGHT + 1, pos2.getZ() + 1), plotfloor);
pastePlotSchematic(dpw, l1, l2);
SetBlockQueue.addNotify(whenDone);
return;
}
if (min.getX() < plotMinX) {
min.setX(plotMinX);
}
if (min.getZ() < plotMinZ) {
min.setZ(plotMinZ);
}
if (max.getX() > plotMaxX) {
max.setX(plotMaxX);
}
if (max.getZ() > plotMaxZ) {
max.setZ(plotMaxZ);
}
MainUtil.setSimpleCuboidAsync(world, new Location(world, plotMinX, 0, plotMinZ), new Location(world, min.getX() + 1, 1, min.getZ() + 1), new PlotBlock(bedrock, (byte) 0));
MainUtil.setSimpleCuboidAsync(world, new Location(world, plotMinX, dpw.PLOT_HEIGHT + 1, plotMinZ), new Location(world, min.getX() + 1, maxy + 1, min.getZ() + 1), new PlotBlock((short) 0, (byte) 0));
MainUtil.setCuboidAsync(world, new Location(world, plotMinX, 1, plotMinZ), new Location(world, min.getX() + 1, dpw.PLOT_HEIGHT + 1, min.getZ() + 1), filling);
MainUtil.setCuboidAsync(world, new Location(world, plotMinX, dpw.PLOT_HEIGHT, plotMinZ), new Location(world, min.getX() + 1, dpw.PLOT_HEIGHT + 1, min.getZ() + 1), plotfloor);
MainUtil.setSimpleCuboidAsync(world, new Location(world, min.getX(), 0, plotMinZ), new Location(world, max.getX() + 1, 1, min.getZ() + 1), new PlotBlock(bedrock, (byte) 0));
MainUtil.setSimpleCuboidAsync(world, new Location(world, min.getX(), dpw.PLOT_HEIGHT + 1, plotMinZ), new Location(world, max.getX() + 1, maxy + 1, min.getZ() + 1), new PlotBlock((short) 0, (byte) 0));
MainUtil.setCuboidAsync(world, new Location(world, min.getX(), 1, plotMinZ), new Location(world, max.getX() + 1, dpw.PLOT_HEIGHT, min.getZ() + 1), filling);
MainUtil.setCuboidAsync(world, new Location(world, min.getX(), dpw.PLOT_HEIGHT, plotMinZ), new Location(world, max.getX() + 1, dpw.PLOT_HEIGHT + 1, min.getZ() + 1), plotfloor);
MainUtil.setSimpleCuboidAsync(world, new Location(world, max.getX(), 0, plotMinZ), new Location(world, plotMaxX + 1, 1, min.getZ() + 1), new PlotBlock(bedrock, (byte) 0));
MainUtil.setSimpleCuboidAsync(world, new Location(world, max.getX(), dpw.PLOT_HEIGHT + 1, plotMinZ), new Location(world, plotMaxX + 1, maxy + 1, min.getZ() + 1), new PlotBlock((short) 0, (byte) 0));
MainUtil.setCuboidAsync(world, new Location(world, max.getX(), 1, plotMinZ), new Location(world, plotMaxX + 1, dpw.PLOT_HEIGHT, min.getZ() + 1), filling);
MainUtil.setCuboidAsync(world, new Location(world, max.getX(), dpw.PLOT_HEIGHT, plotMinZ), new Location(world, plotMaxX + 1, dpw.PLOT_HEIGHT + 1, min.getZ() + 1), plotfloor);
MainUtil.setSimpleCuboidAsync(world, new Location(world, plotMinX, 0, min.getZ()), new Location(world, min.getX() + 1, 1, max.getZ() + 1), new PlotBlock(bedrock, (byte) 0));
MainUtil.setSimpleCuboidAsync(world, new Location(world, plotMinX, dpw.PLOT_HEIGHT + 1, min.getZ()), new Location(world, min.getX() + 1, maxy + 1, max.getZ() + 1), new PlotBlock((short) 0, (byte) 0));
MainUtil.setCuboidAsync(world, new Location(world, plotMinX, 1, min.getZ()), new Location(world, min.getX() + 1, dpw.PLOT_HEIGHT, max.getZ() + 1), filling);
MainUtil.setCuboidAsync(world, new Location(world, plotMinX, dpw.PLOT_HEIGHT, min.getZ()), new Location(world, min.getX() + 1, dpw.PLOT_HEIGHT + 1, max.getZ() + 1), plotfloor);
MainUtil.setSimpleCuboidAsync(world, new Location(world, plotMinX, 0, max.getZ()), new Location(world, min.getX() + 1, 1, plotMaxZ + 1), new PlotBlock(bedrock, (byte) 0));
MainUtil.setSimpleCuboidAsync(world, new Location(world, plotMinX, dpw.PLOT_HEIGHT + 1, max.getZ()), new Location(world, min.getX() + 1, maxy + 1, plotMaxZ + 1), new PlotBlock((short) 0, (byte) 0));
MainUtil.setCuboidAsync(world, new Location(world, plotMinX, 1, max.getZ()), new Location(world, min.getX() + 1, dpw.PLOT_HEIGHT, plotMaxZ + 1), filling);
MainUtil.setCuboidAsync(world, new Location(world, plotMinX, dpw.PLOT_HEIGHT, max.getZ()), new Location(world, min.getX() + 1, dpw.PLOT_HEIGHT + 1, plotMaxZ + 1), plotfloor);
MainUtil.setSimpleCuboidAsync(world, new Location(world, min.getX(), 0, max.getZ()), new Location(world, max.getX() + 1, 1, plotMaxZ + 1), new PlotBlock(bedrock, (byte) 0));
MainUtil.setSimpleCuboidAsync(world, new Location(world, min.getX(), dpw.PLOT_HEIGHT + 1, max.getZ()), new Location(world, max.getX() + 1, maxy + 1, plotMaxZ + 1), new PlotBlock((short) 0, (byte) 0));
MainUtil.setCuboidAsync(world, new Location(world, min.getX(), 1, max.getZ()), new Location(world, max.getX() + 1, dpw.PLOT_HEIGHT, plotMaxZ + 1), filling);
MainUtil.setCuboidAsync(world, new Location(world, min.getX(), dpw.PLOT_HEIGHT, max.getZ()), new Location(world, max.getX() + 1, dpw.PLOT_HEIGHT + 1, plotMaxZ + 1), plotfloor);
MainUtil.setSimpleCuboidAsync(world, new Location(world, max.getX(), 0, min.getZ()), new Location(world, plotMaxX + 1, 1, max.getZ() + 1), new PlotBlock(bedrock, (byte) 0));
MainUtil.setSimpleCuboidAsync(world, new Location(world, max.getX(), dpw.PLOT_HEIGHT + 1, min.getZ()), new Location(world, plotMaxX + 1, maxy + 1, max.getZ() + 1), new PlotBlock((short) 0, (byte) 0));
MainUtil.setCuboidAsync(world, new Location(world, max.getX(), 1, min.getZ()), new Location(world, plotMaxX + 1, dpw.PLOT_HEIGHT, max.getZ() + 1), filling);
MainUtil.setCuboidAsync(world, new Location(world, max.getX(), dpw.PLOT_HEIGHT, min.getZ()), new Location(world, plotMaxX + 1, dpw.PLOT_HEIGHT + 1, max.getZ() + 1), plotfloor);
MainUtil.setSimpleCuboidAsync(world, new Location(world, max.getX(), 0, max.getZ()), new Location(world, plotMaxX + 1, 1, plotMaxZ + 1), new PlotBlock(bedrock, (byte) 0));
MainUtil.setSimpleCuboidAsync(world, new Location(world, max.getX(), dpw.PLOT_HEIGHT + 1, max.getZ()), new Location(world, plotMaxX + 1, maxy + 1, plotMaxZ + 1), new PlotBlock((short) 0, (byte) 0));
MainUtil.setCuboidAsync(world, new Location(world, max.getX(), 1, max.getZ()), new Location(world, plotMaxX + 1, dpw.PLOT_HEIGHT, plotMaxZ + 1), filling);
MainUtil.setCuboidAsync(world, new Location(world, max.getX(), dpw.PLOT_HEIGHT, max.getZ()), new Location(world, plotMaxX + 1, dpw.PLOT_HEIGHT + 1, plotMaxZ + 1), plotfloor);
pastePlotSchematic(dpw, l1, l2);
SetBlockQueue.addNotify(whenDone);
}
});
return true;
}

View File

@ -100,6 +100,14 @@ public abstract class PlotGenerator extends ChunkGenerator {
return new ArrayList<BlockPopulator>();
}
/**
* Set the result;
* @param result
*/
public void setResult(short[][] result) {
this.result = result;
}
@Override
public short[][] generateExtBlockSections(World world, Random r, int cx, int cz, BiomeGrid biomes) {
try {

View File

@ -1,7 +1,7 @@
package com.intellectualcrafters.plot.object;
public class PseudoRandom {
public long state = 1;
public long state = System.nanoTime();
public long nextLong() {
final long a = state;