Changelist:

- Added aliases for custom configuration types
- Removed numerical ID based methods in Block Queues
- Fixed sign removal in Plot.java
- (Hopefully) fixed dividing by 0 errors in BlockBucket
- Removed random from some methods, as blockbucket has it's own random
- Temporarily removed chunk analysis
- Changed a lot in GenChunk and BukkitPlotGenerator
This commit is contained in:
sauilitired
2018-12-20 02:23:48 +01:00
parent 11ccfe7ac4
commit e939b8237e
20 changed files with 112 additions and 325 deletions

View File

@ -100,8 +100,8 @@ import java.util.zip.ZipInputStream;
//
// Register configuration serializable classes
//
ConfigurationSerialization.registerClass(PlotBlock.class);
ConfigurationSerialization.registerClass(BlockBucket.class);
ConfigurationSerialization.registerClass(PlotBlock.class, "PlotBlock");
ConfigurationSerialization.registerClass(BlockBucket.class, "BlockBucket");
try {
new ReflectionUtils(this.IMP.getNMSPackage());
@ -118,9 +118,6 @@ import java.util.zip.ZipInputStream;
"PlotSquared-" + platform + ".jar");
}
}
if (getJavaVersion() < 1.8) {
PlotSquared.log(C.CONSOLE_JAVA_OUTDATED.f(IMP.getPluginName()));
}
TaskManager.IMP = this.IMP.getTaskManager();
setupConfigs();
this.translationFile = MainUtil.getFile(this.IMP.getDirectory(),

View File

@ -1,5 +1,6 @@
package com.github.intellectualsites.plotsquared.plot.config;
import com.github.intellectualsites.plotsquared.plot.object.BlockBucket;
import com.github.intellectualsites.plotsquared.plot.object.PlotBlock;
import com.github.intellectualsites.plotsquared.plot.util.StringMan;
@ -59,6 +60,9 @@ public class ConfigurationNode {
}
return values;
}
if (this.value instanceof BlockBucket) {
return this.value.toString();
}
if (this.value instanceof PlotBlock) {
return this.value.toString();
}

View File

@ -32,8 +32,6 @@ public class AugmentedUtils {
if (areas.isEmpty()) {
return false;
}
PseudoRandom r = new PseudoRandom();
r.state = (cx << 16) | (cz & 0xFFFF);
boolean toReturn = false;
for (final PlotArea area : areas) {
if (area.TYPE == 0) {
@ -63,9 +61,9 @@ public class AugmentedUtils {
txx = Math.min(15, area.getRegion().maxX - bx);
tzz = Math.min(15, area.getRegion().maxZ - bz);
primaryMask = new DelegateLocalBlockQueue(queue) {
@Override public boolean setBlock(int x, int y, int z, int id, int data) {
@Override public boolean setBlock(int x, int y, int z, PlotBlock id) {
if (area.contains(x, z)) {
return super.setBlock(x, y, z, id, data);
return super.setBlock(x, y, z, id);
}
return false;
}
@ -107,9 +105,9 @@ public class AugmentedUtils {
}
toReturn = true;
secondaryMask = new DelegateLocalBlockQueue(primaryMask) {
@Override public boolean setBlock(int x, int y, int z, int id, int data) {
@Override public boolean setBlock(int x, int y, int z, PlotBlock id) {
if (canPlace[x - bx][z - bz]) {
return super.setBlock(x, y, z, id, data);
return super.setBlock(x, y, z, id);
}
return false;
}
@ -132,8 +130,8 @@ public class AugmentedUtils {
ScopedLocalBlockQueue scoped =
new ScopedLocalBlockQueue(secondaryMask, new Location(area.worldname, bx, 0, bz),
new Location(area.worldname, bx + 15, 255, bz + 15));
generator.generateChunk(scoped, area, r);
generator.populateChunk(scoped, area, r);
generator.generateChunk(scoped, area);
generator.populateChunk(scoped, area);
}
if (queue != null) {
queue.flush();

View File

@ -32,8 +32,7 @@ public class HybridGen extends IndependentPlotGenerator {
}
}
@Override public void generateChunk(ScopedLocalBlockQueue result, PlotArea settings,
PseudoRandom random) {
@Override public void generateChunk(ScopedLocalBlockQueue result, PlotArea settings) {
HybridPlotWorld hpw = (HybridPlotWorld) settings;
// Biome
result.fillBiome(hpw.PLOT_BIOME);
@ -41,7 +40,7 @@ public class HybridGen extends IndependentPlotGenerator {
if (hpw.PLOT_BEDROCK) {
for (short x = 0; x < 16; x++) {
for (short z = 0; z < 16; z++) {
result.setBlock(x, 0, z, (short) 7, (byte) 0);
result.setBlock(x, 0, z, PlotBlock.get("bedrock"));
}
}
}
@ -161,8 +160,7 @@ public class HybridGen extends IndependentPlotGenerator {
}
}
@Override public boolean populateChunk(ScopedLocalBlockQueue result, PlotArea settings,
PseudoRandom random) {
@Override public boolean populateChunk(ScopedLocalBlockQueue result, PlotArea settings) {
HybridPlotWorld hpw = (HybridPlotWorld) settings;
if (hpw.G_SCH_STATE != null) {
Location min = result.getMin();

View File

@ -23,13 +23,10 @@ public abstract class IndependentPlotGenerator {
*
* @param result
* @param settings
* @param random
*/
public abstract void generateChunk(ScopedLocalBlockQueue result, PlotArea settings,
PseudoRandom random);
public abstract void generateChunk(ScopedLocalBlockQueue result, PlotArea settings);
public boolean populateChunk(ScopedLocalBlockQueue result, PlotArea settings,
PseudoRandom random) {
public boolean populateChunk(ScopedLocalBlockQueue result, PlotArea setting) {
return false;
}

View File

@ -31,16 +31,10 @@ import java.util.Map.Entry;
public static BlockBucket withSingle(@NonNull final PlotBlock block) {
final BlockBucket blockBucket = new BlockBucket();
blockBucket.addBlock(block);
blockBucket.addBlock(block, 100);
return blockBucket;
}
public static BlockBucket empty() {
final BlockBucket bucket = new BlockBucket();
bucket.compiled = true;
return bucket;
}
public static BlockBucket deserialize(@NonNull final Map<String, Object> map) {
if (!map.containsKey("blocks")) {
return null;
@ -96,6 +90,11 @@ import java.util.Map.Entry;
return;
}
if (blocks.size() == 0) {
this.compiled = true;
return;
}
if (blocks.size() == 1) {
this.ranges.put(new Range(0, 100, true), blocks.keySet().toArray(new PlotBlock[1])[0]);
this.compiled = true;
@ -190,6 +189,9 @@ import java.util.Map.Entry;
}
@Override public String toString() {
if (!isCompiled()) {
compile();
}
final StringBuilder builder = new StringBuilder();
final Iterator<Entry<Range, PlotBlock>> iterator = this.ranges.entrySet().iterator();
while (iterator.hasNext()) {
@ -206,6 +208,9 @@ import java.util.Map.Entry;
}
@Override public Map<String, Object> serialize() {
if (!isCompiled()) {
compile();
}
return ImmutableMap.of("blocks", this.toString());
}

View File

@ -1372,7 +1372,7 @@ public class Plot {
}
Location loc = manager.getSignLoc(this.area, this);
LocalBlockQueue queue = GlobalBlockQueue.IMP.getNewQueue(getWorldName(), false);
queue.setBlock(loc.getX(), loc.getY(), loc.getZ(), 0);
queue.setBlock(loc.getX(), loc.getY(), loc.getZ(), PlotBlock.get("air"));
queue.flush();
}

View File

@ -17,13 +17,12 @@ public class SingleWorldGenerator extends IndependentPlotGenerator {
return "PlotSquared:single";
}
@Override public void generateChunk(ScopedLocalBlockQueue result, PlotArea settings,
PseudoRandom random) {
@Override public void generateChunk(ScopedLocalBlockQueue result, PlotArea settings) {
SinglePlotArea area = (SinglePlotArea) settings;
if (area.VOID) {
Location min = result.getMin();
if (min.getX() == 0 && min.getZ() == 0) {
result.setBlock(0, 0, 0, 7, 0);
result.setBlock(0, 0, 0, PlotBlock.get("bedrock"));
}
} else {
result.setCuboid(bedrock1, bedrock2, PlotBlock.get(7, 0));

View File

@ -113,7 +113,7 @@ public abstract class BasicLocalBlockQueue<T> extends LocalBlockQueue {
return true;
}
@Override public boolean setBlock(int x, int y, int z, String id) {
@Override public boolean setBlock(int x, int y, int z, PlotBlock id) {
if ((y > 255) || (y < 0)) {
return false;
}
@ -140,33 +140,6 @@ public abstract class BasicLocalBlockQueue<T> extends LocalBlockQueue {
return true;
}
@Override public final boolean setBlock(int x, int y, int z, int id, int data) {
if ((y > 255) || (y < 0)) {
return false;
}
int cx = x >> 4;
int cz = z >> 4;
if (cx != lastX || cz != lastZ) {
lastX = cx;
lastZ = cz;
long pair = (long) (cx) << 32 | (cz) & 0xFFFFFFFFL;
lastWrappedChunk = this.blocks.get(pair);
if (lastWrappedChunk == null) {
lastWrappedChunk = this.getLocalChunk(x >> 4, z >> 4);
lastWrappedChunk.setBlock(x & 15, y, z & 15, id, data);
LocalChunk previous = this.blocks.put(pair, lastWrappedChunk);
if (previous == null) {
chunks.add(lastWrappedChunk);
return true;
}
this.blocks.put(pair, previous);
lastWrappedChunk = previous;
}
}
lastWrappedChunk.setBlock(x & 15, y, z & 15, id, data);
return true;
}
@Override public final boolean setBiome(int x, int z, String biome) {
long pair = (long) (x >> 4) << 32 | (z >> 4) & 0xFFFFFFFFL;
LocalChunk result = this.blocks.get(pair);
@ -185,11 +158,11 @@ public abstract class BasicLocalBlockQueue<T> extends LocalBlockQueue {
}
public final void setChunk(LocalChunk<T> chunk) {
LocalChunk previous = this.blocks.put(chunk.longHash(), (LocalChunk) chunk);
LocalChunk previous = this.blocks.put(chunk.longHash(), chunk);
if (previous != null) {
chunks.remove(previous);
}
chunks.add((LocalChunk) chunk);
chunks.add(chunk);
}
@Override public void flush() {
@ -234,56 +207,10 @@ public abstract class BasicLocalBlockQueue<T> extends LocalBlockQueue {
return z;
}
/**
* Add the chunk to the queue
*/
public void addToQueue() {
parent.setChunk(this);
}
public void fill(int id, int data) {
fillCuboid(0, 15, 0, 255, 0, 15, id, data);
}
/**
* Fill a cuboid in this chunk with a block
*
* @param x1
* @param x2
* @param y1
* @param y2
* @param z1
* @param z2
* @param id
* @param data
*/
public void fillCuboid(int x1, int x2, int y1, int y2, int z1, int z2, int id, int data) {
for (int x = x1; x <= x2; x++) {
for (int y = y1; y <= y2; y++) {
for (int z = z1; z <= z2; z++) {
setBlock(x, y, z, id, data);
}
}
}
}
public void fillCuboid(int x1, int x2, int y1, int y2, int z1, int z2, String id) {
for (int x = x1; x <= x2; x++) {
for (int y = y1; y <= y2; y++) {
for (int z = z1; z <= z2; z++) {
setBlock(x, y, z, id);
}
}
}
}
public abstract void setBlock(final int x, final int y, final int z, final PlotBlock block);
public abstract void setBlock(final int x, final int y, final int z, final BaseBlock id);
public abstract void setBlock(final int x, final int y, final int z, final String id);
public abstract void setBlock(final int x, final int y, final int z, final int id,
final int data);
public void setBiome(int x, int z, String biome) {
if (this.biomes == null) {
this.biomes = new String[16][];
@ -311,15 +238,13 @@ public abstract class BasicLocalBlockQueue<T> extends LocalBlockQueue {
blocks = new PlotBlock[16][];
}
@Override
public void setBlock(final int x, final int y, final int z, @NonNull final BaseBlock id) {
this.setInternal(x, y, z, id);
@Override public void setBlock(int x, int y, int z, PlotBlock block) {
this.setInternal(x, y, z, block);
}
@Override
public void setBlock(final int x, final int y, final int z, @NonNull final String id) {
final PlotBlock block = PlotBlock.get(id);
this.setInternal(x, y, z, block);
public void setBlock(final int x, final int y, final int z, @NonNull final BaseBlock id) {
this.setInternal(x, y, z, id);
}
private void setInternal(final int x, final int y, final int z, final BaseBlock bsh) {
@ -347,23 +272,4 @@ public abstract class BasicLocalBlockQueue<T> extends LocalBlockQueue {
this.setInternal(x, y, z, block);
}
}
/* public class CharLocalChunk extends LocalChunk<char[]> {
public CharLocalChunk(BasicLocalBlockQueue parent, int x, int z) {
super(parent, x, z);
blocks = new char[16][];
}
public void setBlock(final int x, final int y, final int z, final int id, final int data) {
PlotBlock block = PlotBlock.get(id, data);
int i = MainUtil.CACHE_I[y][x][z];
int j = MainUtil.CACHE_J[y][x][z];
char[] array = blocks[i];
if (array == null) {
array = (blocks[i] = new char[4096]);
}
array[j] = (char) ((block.id << 4) + block.data);
}
} */
}

View File

@ -62,14 +62,10 @@ public class DelegateLocalBlockQueue extends LocalBlockQueue {
return parent.setBlock(x, y, z, id);
}
@Override public boolean setBlock(int x, int y, int z, String id) {
@Override public boolean setBlock(int x, int y, int z, PlotBlock id) {
return parent.setBlock(x, y, z, id);
}
@Override public boolean setBlock(int x, int y, int z, int id, int data) {
return parent.setBlock(x, y, z, id, data);
}
@Override public PlotBlock getBlock(int x, int y, int z) {
return parent.getBlock(x, y, z);
}

View File

@ -7,7 +7,6 @@ import com.github.intellectualsites.plotsquared.plot.util.UUIDHandler;
import com.github.intellectualsites.plotsquared.plot.util.WorldUtil;
import com.sk89q.jnbt.CompoundTag;
import com.sk89q.worldedit.world.block.BaseBlock;
import lombok.NonNull;
import java.util.Map;
@ -38,27 +37,10 @@ public abstract class LocalBlockQueue {
public abstract void setModified(long modified);
public abstract boolean setBlock(final int x, final int y, final int z, final int id,
final int data);
public final boolean setBlock(int x, int y, int z, int id) {
return setBlock(x, y, z, id, 0);
}
public abstract boolean setBlock(final int x, final int y, final int z, final String id);
public abstract boolean setBlock(final int x, final int y, final int z, final PlotBlock id);
public abstract boolean setBlock(final int x, final int y, final int z, final BaseBlock id);
public final boolean setBlock(int x, int y, int z, @NonNull final PlotBlock block) {
if (block instanceof LegacyPlotBlock) {
final LegacyPlotBlock legacyPlotBlock = (LegacyPlotBlock) block;
return this.setBlock(x, y, z, legacyPlotBlock.id, legacyPlotBlock.data);
} else {
final StringPlotBlock stringPlotBlock = (StringPlotBlock) block;
return this.setBlock(x, y, z, stringPlotBlock.getItemId());
}
}
public boolean setTile(int x, int y, int z, CompoundTag tag) {
SchematicHandler.manager.restoreTile(this, tag, x, y, z);
return true;

View File

@ -50,16 +50,11 @@ public class ScopedLocalBlockQueue extends DelegateLocalBlockQueue {
.setBlock(x + minX, y + minY, z + minZ, id);
}
@Override public boolean setBlock(int x, int y, int z, String id) {
@Override public boolean setBlock(int x, int y, int z, PlotBlock id) {
return x >= 0 && x <= dx && y >= 0 && y <= dy && z >= 0 && z <= dz && super
.setBlock(x + minX, y + minY, z + minZ, id);
}
@Override public boolean setBlock(int x, int y, int z, int id, int data) {
return x >= 0 && x <= dx && y >= 0 && y <= dy && z >= 0 && z <= dz && super
.setBlock(x + minX, y + minY, z + minZ, id, data);
}
public Location getMin() {
return new Location(getWorld(), minX, minY, minZ);
}