From e939b8237e9f6d170dc88f9931e5fc787ef29607 Mon Sep 17 00:00:00 2001 From: sauilitired Date: Thu, 20 Dec 2018 02:23:48 +0100 Subject: [PATCH] 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 --- .../bukkit/generator/BukkitPlotGenerator.java | 79 +++++-------- .../bukkit/listeners/PlayerEvents.java | 16 +-- .../bukkit/util/BukkitChunkManager.java | 26 ++--- .../bukkit/util/BukkitHybridUtils.java | 21 +--- .../bukkit/util/BukkitSchematicHandler.java | 2 +- .../plotsquared/bukkit/util/BukkitUtil.java | 1 + .../bukkit/util/block/GenChunk.java | 80 +++---------- Bukkit/src/main/resources/plugin.yml | 3 +- .../plotsquared/plot/PlotSquared.java | 7 +- .../plot/config/ConfigurationNode.java | 4 + .../plot/generator/AugmentedUtils.java | 14 +-- .../plotsquared/plot/generator/HybridGen.java | 8 +- .../generator/IndependentPlotGenerator.java | 7 +- .../plotsquared/plot/object/BlockBucket.java | 19 +-- .../plotsquared/plot/object/Plot.java | 2 +- .../object/worlds/SingleWorldGenerator.java | 5 +- .../plot/util/block/BasicLocalBlockQueue.java | 110 ++---------------- .../util/block/DelegateLocalBlockQueue.java | 6 +- .../plot/util/block/LocalBlockQueue.java | 20 +--- .../util/block/ScopedLocalBlockQueue.java | 7 +- 20 files changed, 112 insertions(+), 325 deletions(-) diff --git a/Bukkit/src/main/java/com/github/intellectualsites/plotsquared/bukkit/generator/BukkitPlotGenerator.java b/Bukkit/src/main/java/com/github/intellectualsites/plotsquared/bukkit/generator/BukkitPlotGenerator.java index fb19c1e93..cb3a44468 100644 --- a/Bukkit/src/main/java/com/github/intellectualsites/plotsquared/bukkit/generator/BukkitPlotGenerator.java +++ b/Bukkit/src/main/java/com/github/intellectualsites/plotsquared/bukkit/generator/BukkitPlotGenerator.java @@ -25,7 +25,6 @@ public class BukkitPlotGenerator extends ChunkGenerator implements GeneratorWrapper { private final GenChunk chunkSetter; - private final PseudoRandom random = new PseudoRandom(); private final IndependentPlotGenerator plotGenerator; private final ChunkGenerator platformGenerator; private final boolean full; @@ -48,41 +47,11 @@ public class BukkitPlotGenerator extends ChunkGenerator if (queue == null) { queue = GlobalBlockQueue.IMP.getNewQueue(world.getName(), false); } - byte[][] resultData = - dataMap.isEmpty() ? null : dataMap.remove(new ChunkLoc(c.getX(), c.getZ())); - if (resultData == null) { - GenChunk result = BukkitPlotGenerator.this.chunkSetter; - // Set the chunk location - result.setChunk(c); - // Set the result data - result.result = new short[16][]; - result.result_data = new byte[16][]; - result.grid = null; - result.cd = null; - // Catch any exceptions (as exceptions usually thrown) - generate(world, c.getX(), c.getZ(), result); - resultData = result.result_data; - } - if (resultData != null) { - for (int i = 0; i < resultData.length; i++) { - byte[] section = resultData[i]; - if (section == null) { - continue; - } - for (int j = 0; j < section.length; j++) { - int x = MainUtil.x_loc[i][j]; - int y = MainUtil.y_loc[i][j]; - int z = MainUtil.z_loc[i][j]; - c.getBlock(x, y, z).setData(section[j]); - } - } - } - BukkitPlotGenerator.this.random.state = c.getX() << 16 | c.getZ() & 0xFFFF; PlotArea area = PlotSquared.get().getPlotArea(world.getName(), null); ChunkWrapper wrap = new ChunkWrapper(area.worldname, c.getX(), c.getZ()); ScopedLocalBlockQueue chunk = queue.getForChunk(wrap.x, wrap.z); if (BukkitPlotGenerator.this.plotGenerator - .populateChunk(chunk, area, BukkitPlotGenerator.this.random)) { + .populateChunk(chunk, area)) { queue.flush(); } } @@ -122,8 +91,7 @@ public class BukkitPlotGenerator extends ChunkGenerator } @Override - public void generateChunk(final ScopedLocalBlockQueue result, PlotArea settings, - PseudoRandom random) { + public void generateChunk(final ScopedLocalBlockQueue result, PlotArea settings) { World w = BukkitUtil.getWorld(world); Location min = result.getMin(); int cx = min.getX() >> 4; @@ -146,6 +114,7 @@ public class BukkitPlotGenerator extends ChunkGenerator } } catch (Throwable ignored) { } + /* TODO: Redo this // Populator spillage short[][] tmp = cg.generateExtBlockSections(w, r, cx, cz, grid); if (tmp != null) { @@ -156,7 +125,7 @@ public class BukkitPlotGenerator extends ChunkGenerator for (int x = 0; x < 16; x++) { for (int z = 0; z < 16; z++) { for (int y = i << 4; y < (i << 4) + 16; y++) { - result.setBlock(x, y, z, (short) 0, (byte) 0); + result.setBlock(x, y, z, PlotBlock.get("air")); } } } @@ -171,6 +140,7 @@ public class BukkitPlotGenerator extends ChunkGenerator } } } + */ for (BlockPopulator populator : cg.getDefaultPopulators(w)) { populator.populate(w, r, w.getChunkAt(cx, cz)); } @@ -256,15 +226,14 @@ public class BukkitPlotGenerator extends ChunkGenerator // Set the result data result.cd = createChunkData(world); result.grid = grid; - result.result = null; - result.result_data = null; + result.result = generateExtBlockSections(world, random, cx, cz, grid); // Catch any exceptions (as exceptions usually thrown) try { // Fill the result data if necessary if (this.platformGenerator != this) { return this.platformGenerator.generateChunkData(world, random, cx, cz, grid); } else { - generate(world, cx, cz, result); + generate(world, result); } } catch (Throwable e) { e.printStackTrace(); @@ -273,22 +242,20 @@ public class BukkitPlotGenerator extends ChunkGenerator return result.cd; } - public void generate(World world, int cx, int cz, ScopedLocalBlockQueue result) { + public void generate(World world, ScopedLocalBlockQueue result) { // Load if improperly loaded if (!this.loaded) { String name = world.getName(); PlotSquared.get().loadWorld(name, this); this.loaded = true; } - // Set random seed - this.random.state = cx << 16 | cz & 0xFFFF; // Process the chunk if (ChunkManager.preProcessChunk(result)) { return; } PlotArea area = PlotSquared.get().getPlotArea(world.getName(), null); try { - this.plotGenerator.generateChunk(this.chunkSetter, area, this.random); + this.plotGenerator.generateChunk(this.chunkSetter, area); } catch (Throwable e) { // Recover from generator error e.printStackTrace(); @@ -296,29 +263,34 @@ public class BukkitPlotGenerator extends ChunkGenerator ChunkManager.postProcessChunk(result); } - @Override public short[][] generateExtBlockSections(World world, Random r, int cx, int cz, + + public PlotBlock[][] generateExtBlockSections(World world, Random r, int cx, int cz, BiomeGrid grid) { GenChunk result = this.chunkSetter; // Set the chunk location result.setChunk(new ChunkWrapper(world.getName(), cx, cz)); // Set the result data - result.result = new short[16][]; - result.result_data = new byte[16][]; + result.result = new PlotBlock[16][]; result.grid = grid; result.cd = null; // Catch any exceptions (as exceptions usually thrown) try { - // Fill the result data if (this.platformGenerator != this) { - return this.platformGenerator.generateExtBlockSections(world, r, cx, cz, grid); - } else { - generate(world, cx, cz, result); - 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; + final ChunkData chunkData = this.platformGenerator.generateChunkData(world, r, cx, cz, grid); + final PlotBlock[][] blocks = new PlotBlock[world.getMaxHeight() / 16][]; + // section ID = Y >> 4 + for (int x = 0; x < 16; x++) { + for (int z = 0; z < 16; z++) { + for (int y = 0; y < world.getMaxHeight(); y++) { + if (blocks[y >> 4] == null) { + blocks[y >> 4] = new PlotBlock[4096]; + } + blocks[y >> 4][((y & 0xF) << 8) | (z << 4) | x] = PlotBlock.get(chunkData.getType(x, y, z)); + } } } + } else { + generate(world, result); } } catch (Throwable e) { e.printStackTrace(); @@ -327,6 +299,7 @@ public class BukkitPlotGenerator extends ChunkGenerator return result.result; } + /** * Allow spawning everywhere. * diff --git a/Bukkit/src/main/java/com/github/intellectualsites/plotsquared/bukkit/listeners/PlayerEvents.java b/Bukkit/src/main/java/com/github/intellectualsites/plotsquared/bukkit/listeners/PlayerEvents.java index 41b8ec34f..89d045bef 100644 --- a/Bukkit/src/main/java/com/github/intellectualsites/plotsquared/bukkit/listeners/PlayerEvents.java +++ b/Bukkit/src/main/java/com/github/intellectualsites/plotsquared/bukkit/listeners/PlayerEvents.java @@ -945,9 +945,9 @@ import java.util.regex.Pattern; return; } if (PlotSquared.get().worldedit != null && pp.getAttribute("worldedit")) { - if (player.getInventory().getItemInMainHand().getType() == LegacyMappings - .fromLegacyId(PlotSquared.get().worldedit.getConfiguration().wandItem) - .getMaterial()) { + if (player.getInventory().getItemInMainHand().getType() == BukkitUtil.getBukkitLegacyMappings() + .fromLegacyToString(PlotSquared.get().worldedit.getConfiguration().wandItem) + .to(Material.class)) { return; } } @@ -1682,10 +1682,12 @@ import java.util.regex.Pattern; return; } if (PlotSquared.get().worldedit != null && pp.getAttribute("worldedit")) { - if (player.getInventory().getItemInMainHand().getType() == LegacyMappings - .fromLegacyId(PlotSquared.get().worldedit.getConfiguration().wandItem) - .getMaterial()) { - return; + if (PlotSquared.get().worldedit != null && pp.getAttribute("worldedit")) { + if (player.getInventory().getItemInMainHand().getType() == BukkitUtil.getBukkitLegacyMappings() + .fromLegacyToString(PlotSquared.get().worldedit.getConfiguration().wandItem) + .to(Material.class)) { + return; + } } } if (!EventUtil.manager.checkPlayerBlockEvent(pp, eventType, location, lb, true)) { diff --git a/Bukkit/src/main/java/com/github/intellectualsites/plotsquared/bukkit/util/BukkitChunkManager.java b/Bukkit/src/main/java/com/github/intellectualsites/plotsquared/bukkit/util/BukkitChunkManager.java index 32d067e70..ebaf47012 100644 --- a/Bukkit/src/main/java/com/github/intellectualsites/plotsquared/bukkit/util/BukkitChunkManager.java +++ b/Bukkit/src/main/java/com/github/intellectualsites/plotsquared/bukkit/util/BukkitChunkManager.java @@ -72,20 +72,20 @@ public class BukkitChunkManager extends ChunkManager { // byte data2 = block2.getData(); if (id1 == Material.AIR) { if (id2 != Material.AIR) { - queue1.setBlock(x, y, z, id2.name()); - queue2.setBlock(xx, y, zz, (short) 0, (byte) 0); + queue1.setBlock(x, y, z, PlotBlock.get(id2)); + queue2.setBlock(xx, y, zz, PlotBlock.get("air")); } } else if (id2 == Material.AIR) { - queue1.setBlock(x, y, z, (short) 0, (byte) 0); - queue2.setBlock(xx, y, zz, id1.name()); + queue1.setBlock(x, y, z, PlotBlock.get("air")); + queue2.setBlock(xx, y, zz, PlotBlock.get(id1)); } else if (id1 == id2) { if (data1 != data2) { block1.setBlockData(data2); block2.setBlockData(data1); } } else { - queue1.setBlock(x, y, z, id2.name()); - queue2.setBlock(xx, y, zz, id1.name()); + queue1.setBlock(x, y, z, PlotBlock.get(id2)); + queue2.setBlock(xx, y, zz, PlotBlock.get(id1)); // queue1.setBlock(x, y, z, (short) id2, data2); // queue2.setBlock(xx, y, zz, (short) id1, data1); } @@ -297,7 +297,7 @@ public class BukkitChunkManager extends ChunkManager { if (id != null) { value.setBlock(x, y, z, id); } else { - value.setBlock(x, y, z, 0, (byte) 0); + value.setBlock(x, y, z, PlotBlock.get("air")); } } for (int y = Math.min(128, ids.length); @@ -392,13 +392,11 @@ public class BukkitChunkManager extends ChunkManager { maps.add(swapChunk(world1, world2, chunk1, chunk2, region1, region2)); } } - GlobalBlockQueue.IMP.addTask(new Runnable() { - @Override public void run() { - for (ContentMap map : maps) { - map.restoreBlocks(world1, 0, 0); - map.restoreEntities(world1, 0, 0); - TaskManager.runTaskLater(whenDone, 1); - } + GlobalBlockQueue.IMP.addTask(() -> { + for (ContentMap map : maps) { + map.restoreBlocks(world1, 0, 0); + map.restoreEntities(world1, 0, 0); + TaskManager.runTaskLater(whenDone, 1); } }); } diff --git a/Bukkit/src/main/java/com/github/intellectualsites/plotsquared/bukkit/util/BukkitHybridUtils.java b/Bukkit/src/main/java/com/github/intellectualsites/plotsquared/bukkit/util/BukkitHybridUtils.java index 0410ef7a9..9e5b9872b 100644 --- a/Bukkit/src/main/java/com/github/intellectualsites/plotsquared/bukkit/util/BukkitHybridUtils.java +++ b/Bukkit/src/main/java/com/github/intellectualsites/plotsquared/bukkit/util/BukkitHybridUtils.java @@ -1,28 +1,9 @@ package com.github.intellectualsites.plotsquared.bukkit.util; import com.github.intellectualsites.plotsquared.plot.generator.HybridUtils; -import com.github.intellectualsites.plotsquared.plot.object.Location; -import com.github.intellectualsites.plotsquared.plot.object.PlotBlock; import com.github.intellectualsites.plotsquared.plot.object.RegionWrapper; import com.github.intellectualsites.plotsquared.plot.object.RunnableVal; -import com.github.intellectualsites.plotsquared.plot.util.ChunkManager; -import com.github.intellectualsites.plotsquared.plot.util.MainUtil; -import com.github.intellectualsites.plotsquared.plot.util.MathMan; -import com.github.intellectualsites.plotsquared.plot.util.TaskManager; -import com.github.intellectualsites.plotsquared.plot.util.block.GlobalBlockQueue; -import com.github.intellectualsites.plotsquared.plot.util.block.LocalBlockQueue; import com.github.intellectualsites.plotsquared.plot.util.expiry.PlotAnalysis; -import org.bukkit.Bukkit; -import org.bukkit.Material; -import org.bukkit.World; -import org.bukkit.block.Biome; -import org.bukkit.generator.ChunkGenerator; -import org.bukkit.generator.ChunkGenerator.BiomeGrid; -import org.bukkit.material.Directional; -import org.bukkit.material.MaterialData; - -import java.util.HashSet; -import java.util.Random; public class BukkitHybridUtils extends HybridUtils { @@ -40,6 +21,7 @@ public class BukkitHybridUtils extends HybridUtils { * - recheck each block * */ + /* TODO: Redo TaskManager.runTaskAsync(new Runnable() { @Override public void run() { final LocalBlockQueue queue = GlobalBlockQueue.IMP.getNewQueue(world, false); @@ -275,5 +257,6 @@ public class BukkitHybridUtils extends HybridUtils { }, 5); } }); + */ } } diff --git a/Bukkit/src/main/java/com/github/intellectualsites/plotsquared/bukkit/util/BukkitSchematicHandler.java b/Bukkit/src/main/java/com/github/intellectualsites/plotsquared/bukkit/util/BukkitSchematicHandler.java index c3e35b1cf..ea115b14a 100644 --- a/Bukkit/src/main/java/com/github/intellectualsites/plotsquared/bukkit/util/BukkitSchematicHandler.java +++ b/Bukkit/src/main/java/com/github/intellectualsites/plotsquared/bukkit/util/BukkitSchematicHandler.java @@ -23,7 +23,7 @@ import java.util.*; /** * Schematic Handler. */ -public abstract class BukkitSchematicHandler extends SchematicHandler { +public class BukkitSchematicHandler extends SchematicHandler { @Override public void getCompoundTag(final String world, final Set regions, final RunnableVal whenDone) { diff --git a/Bukkit/src/main/java/com/github/intellectualsites/plotsquared/bukkit/util/BukkitUtil.java b/Bukkit/src/main/java/com/github/intellectualsites/plotsquared/bukkit/util/BukkitUtil.java index dd4320484..f3981c152 100644 --- a/Bukkit/src/main/java/com/github/intellectualsites/plotsquared/bukkit/util/BukkitUtil.java +++ b/Bukkit/src/main/java/com/github/intellectualsites/plotsquared/bukkit/util/BukkitUtil.java @@ -6,6 +6,7 @@ import com.github.intellectualsites.plotsquared.plot.config.C; import com.github.intellectualsites.plotsquared.plot.object.*; import com.github.intellectualsites.plotsquared.plot.object.schematic.PlotItem; import com.github.intellectualsites.plotsquared.plot.util.*; +import com.sk89q.worldedit.bukkit.BukkitWorld; import lombok.NonNull; import org.bukkit.Bukkit; import org.bukkit.Material; diff --git a/Bukkit/src/main/java/com/github/intellectualsites/plotsquared/bukkit/util/block/GenChunk.java b/Bukkit/src/main/java/com/github/intellectualsites/plotsquared/bukkit/util/block/GenChunk.java index e700a3433..77f5b1fd6 100644 --- a/Bukkit/src/main/java/com/github/intellectualsites/plotsquared/bukkit/util/block/GenChunk.java +++ b/Bukkit/src/main/java/com/github/intellectualsites/plotsquared/bukkit/util/block/GenChunk.java @@ -12,15 +12,13 @@ import org.bukkit.World; import org.bukkit.block.Biome; import org.bukkit.generator.ChunkGenerator.BiomeGrid; import org.bukkit.generator.ChunkGenerator.ChunkData; -import org.bukkit.material.MaterialData; import java.util.Arrays; public class GenChunk extends ScopedLocalBlockQueue { public final Biome[] biomes; - public short[][] result; - public byte[][] result_data; + public PlotBlock[][] result; public ChunkData cd; public BiomeGrid grid; @@ -55,13 +53,6 @@ public class GenChunk extends ScopedLocalBlockQueue { cz = wrap.z; } - public ChunkWrapper getChunkWrapper() { - if (chunk == null) { - return new ChunkWrapper(world, cx, cz); - } - return new ChunkWrapper(chunk.getWorld().getName(), chunk.getX(), chunk.getZ()); - } - @Override public void fillBiome(String biomeName) { if (grid == null) { return; @@ -75,17 +66,17 @@ 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 + if (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]; + PlotBlock[] data = result[layer]; if (data == null) { - result[layer] = data = new short[4096]; + result[layer] = data = new PlotBlock[4096]; } int start = y << 8; int end = start + 256; - Arrays.fill(data, start, end, block.id); + Arrays.fill(data, start, end, block); } } else { super.setCuboid(pos1, pos2, block); @@ -96,14 +87,6 @@ public class GenChunk extends ScopedLocalBlockQueue { return setBiome(x, z, Biome.valueOf(biome.toUpperCase())); } - public boolean setBiome(int x, int z, int biome) { - if (this.grid != null) { - this.grid.setBiome(x, z, this.biomes[biome]); - return true; - } - return false; - } - public boolean setBiome(int x, int z, Biome biome) { if (this.grid != null) { this.grid.setBiome(x, z, biome); @@ -112,48 +95,32 @@ public class GenChunk extends ScopedLocalBlockQueue { return false; } - @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 (this.result == null) { - this.cd.setBlock(x, y, z, new MaterialData(Material.getMaterial(id), (byte) data)); + this.cd.setBlock(x, y, z, id.to(Material.class)); return true; } int i = MainUtil.CACHE_I[y][x][z]; - short[] v = this.result[i]; + PlotBlock[] v = this.result[i]; if (v == null) { - this.result[i] = v = new short[4096]; + this.result[i] = v = new PlotBlock[4096]; } int j = MainUtil.CACHE_J[y][x][z]; - v[j] = (short) id; - if (data != 0) { - byte[] vd = this.result_data[i]; - if (vd == null) { - this.result_data[i] = vd = new byte[4096]; - } - vd[j] = (byte) data; - } + v[j] = id; return true; } @Override public PlotBlock getBlock(int x, int y, int z) { int i = MainUtil.CACHE_I[y][x][z]; if (result == null) { - MaterialData md = cd.getTypeAndData(x, y, z); - return PlotBlock.get(md.getItemTypeId(), md.getData()); + return PlotBlock.get(cd.getType(x, y, z)); } - short[] array = result[i]; + PlotBlock[] array = result[i]; if (array == null) { - return PlotBlock.get(0, 0); + return PlotBlock.get(""); } int j = MainUtil.CACHE_J[y][x][z]; - short id = array[j]; - if (id == 0) { - return PlotBlock.get(id, 0); - } - byte[] dataArray = result_data[i]; - if (dataArray == null) { - return PlotBlock.get(id, 0); - } - return PlotBlock.get(id, dataArray[j]); + return array[j]; } public int getX() { @@ -181,29 +148,14 @@ public class GenChunk extends ScopedLocalBlockQueue { new GenChunk(chunk, new ChunkWrapper(getWorld(), chunk.getX(), chunk.getZ())); if (this.result != null) { for (int i = 0; i < this.result.length; i++) { - short[] matrix = this.result[i]; + PlotBlock[] matrix = this.result[i]; if (matrix != null) { - toReturn.result[i] = new short[matrix.length]; + toReturn.result[i] = new PlotBlock[matrix.length]; System.arraycopy(matrix, 0, toReturn.result[i], 0, matrix.length); } } - for (int i = 0; i < this.result_data.length; i++) { - byte[] matrix = this.result_data[i]; - if (matrix != null) { - toReturn.result_data[i] = new byte[matrix.length]; - System.arraycopy(matrix, 0, toReturn.result_data[i], 0, matrix.length); - } - } } toReturn.cd = this.cd; return toReturn; } - - public GenChunk shallowClone() { - GenChunk toReturn = new GenChunk(chunk, new ChunkWrapper(getWorld(), getX(), getZ())); - toReturn.result = this.result; - toReturn.result_data = this.result_data; - toReturn.cd = this.cd; - return toReturn; - } } diff --git a/Bukkit/src/main/resources/plugin.yml b/Bukkit/src/main/resources/plugin.yml index ae7d4ad57..5f73fb3c6 100644 --- a/Bukkit/src/main/resources/plugin.yml +++ b/Bukkit/src/main/resources/plugin.yml @@ -6,8 +6,9 @@ load: STARTUP description: > Easy, yet powerful Plot World generation and management. authors: [Citymonstret, Empire92, MattBDev] -softdepend: [WorldEdit, BarAPI, CameraAPI, Vault] +softdepend: [BarAPI, CameraAPI, Vault] loadbefore: [MultiWorld, Multiverse-Core] +depend: [WorldEdit] database: false commands: plots: diff --git a/Core/src/main/java/com/github/intellectualsites/plotsquared/plot/PlotSquared.java b/Core/src/main/java/com/github/intellectualsites/plotsquared/plot/PlotSquared.java index 1e1021052..82b647b34 100644 --- a/Core/src/main/java/com/github/intellectualsites/plotsquared/plot/PlotSquared.java +++ b/Core/src/main/java/com/github/intellectualsites/plotsquared/plot/PlotSquared.java @@ -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(), diff --git a/Core/src/main/java/com/github/intellectualsites/plotsquared/plot/config/ConfigurationNode.java b/Core/src/main/java/com/github/intellectualsites/plotsquared/plot/config/ConfigurationNode.java index 2bb9ecf93..f44929d0f 100644 --- a/Core/src/main/java/com/github/intellectualsites/plotsquared/plot/config/ConfigurationNode.java +++ b/Core/src/main/java/com/github/intellectualsites/plotsquared/plot/config/ConfigurationNode.java @@ -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(); } diff --git a/Core/src/main/java/com/github/intellectualsites/plotsquared/plot/generator/AugmentedUtils.java b/Core/src/main/java/com/github/intellectualsites/plotsquared/plot/generator/AugmentedUtils.java index 1d97cca48..bf4199469 100644 --- a/Core/src/main/java/com/github/intellectualsites/plotsquared/plot/generator/AugmentedUtils.java +++ b/Core/src/main/java/com/github/intellectualsites/plotsquared/plot/generator/AugmentedUtils.java @@ -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(); diff --git a/Core/src/main/java/com/github/intellectualsites/plotsquared/plot/generator/HybridGen.java b/Core/src/main/java/com/github/intellectualsites/plotsquared/plot/generator/HybridGen.java index e53ad13e5..120828fb6 100644 --- a/Core/src/main/java/com/github/intellectualsites/plotsquared/plot/generator/HybridGen.java +++ b/Core/src/main/java/com/github/intellectualsites/plotsquared/plot/generator/HybridGen.java @@ -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(); diff --git a/Core/src/main/java/com/github/intellectualsites/plotsquared/plot/generator/IndependentPlotGenerator.java b/Core/src/main/java/com/github/intellectualsites/plotsquared/plot/generator/IndependentPlotGenerator.java index d6f24773e..664f72186 100644 --- a/Core/src/main/java/com/github/intellectualsites/plotsquared/plot/generator/IndependentPlotGenerator.java +++ b/Core/src/main/java/com/github/intellectualsites/plotsquared/plot/generator/IndependentPlotGenerator.java @@ -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; } diff --git a/Core/src/main/java/com/github/intellectualsites/plotsquared/plot/object/BlockBucket.java b/Core/src/main/java/com/github/intellectualsites/plotsquared/plot/object/BlockBucket.java index ed4060028..ddec24deb 100644 --- a/Core/src/main/java/com/github/intellectualsites/plotsquared/plot/object/BlockBucket.java +++ b/Core/src/main/java/com/github/intellectualsites/plotsquared/plot/object/BlockBucket.java @@ -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 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> iterator = this.ranges.entrySet().iterator(); while (iterator.hasNext()) { @@ -206,6 +208,9 @@ import java.util.Map.Entry; } @Override public Map serialize() { + if (!isCompiled()) { + compile(); + } return ImmutableMap.of("blocks", this.toString()); } diff --git a/Core/src/main/java/com/github/intellectualsites/plotsquared/plot/object/Plot.java b/Core/src/main/java/com/github/intellectualsites/plotsquared/plot/object/Plot.java index eb5e9914a..6b7c60889 100644 --- a/Core/src/main/java/com/github/intellectualsites/plotsquared/plot/object/Plot.java +++ b/Core/src/main/java/com/github/intellectualsites/plotsquared/plot/object/Plot.java @@ -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(); } diff --git a/Core/src/main/java/com/github/intellectualsites/plotsquared/plot/object/worlds/SingleWorldGenerator.java b/Core/src/main/java/com/github/intellectualsites/plotsquared/plot/object/worlds/SingleWorldGenerator.java index d72a9c672..449bfeb13 100644 --- a/Core/src/main/java/com/github/intellectualsites/plotsquared/plot/object/worlds/SingleWorldGenerator.java +++ b/Core/src/main/java/com/github/intellectualsites/plotsquared/plot/object/worlds/SingleWorldGenerator.java @@ -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)); diff --git a/Core/src/main/java/com/github/intellectualsites/plotsquared/plot/util/block/BasicLocalBlockQueue.java b/Core/src/main/java/com/github/intellectualsites/plotsquared/plot/util/block/BasicLocalBlockQueue.java index 98c1dc5c8..6b2c95fa4 100644 --- a/Core/src/main/java/com/github/intellectualsites/plotsquared/plot/util/block/BasicLocalBlockQueue.java +++ b/Core/src/main/java/com/github/intellectualsites/plotsquared/plot/util/block/BasicLocalBlockQueue.java @@ -113,7 +113,7 @@ public abstract class BasicLocalBlockQueue 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 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 extends LocalBlockQueue { } public final void setChunk(LocalChunk 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 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 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 extends LocalBlockQueue { this.setInternal(x, y, z, block); } } - - /* public class CharLocalChunk extends LocalChunk { - - 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); - } - } */ } diff --git a/Core/src/main/java/com/github/intellectualsites/plotsquared/plot/util/block/DelegateLocalBlockQueue.java b/Core/src/main/java/com/github/intellectualsites/plotsquared/plot/util/block/DelegateLocalBlockQueue.java index 1ed93466b..cd3a4a81d 100644 --- a/Core/src/main/java/com/github/intellectualsites/plotsquared/plot/util/block/DelegateLocalBlockQueue.java +++ b/Core/src/main/java/com/github/intellectualsites/plotsquared/plot/util/block/DelegateLocalBlockQueue.java @@ -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); } diff --git a/Core/src/main/java/com/github/intellectualsites/plotsquared/plot/util/block/LocalBlockQueue.java b/Core/src/main/java/com/github/intellectualsites/plotsquared/plot/util/block/LocalBlockQueue.java index 66bbde46b..65dc13971 100644 --- a/Core/src/main/java/com/github/intellectualsites/plotsquared/plot/util/block/LocalBlockQueue.java +++ b/Core/src/main/java/com/github/intellectualsites/plotsquared/plot/util/block/LocalBlockQueue.java @@ -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; diff --git a/Core/src/main/java/com/github/intellectualsites/plotsquared/plot/util/block/ScopedLocalBlockQueue.java b/Core/src/main/java/com/github/intellectualsites/plotsquared/plot/util/block/ScopedLocalBlockQueue.java index 134b29818..352465aea 100644 --- a/Core/src/main/java/com/github/intellectualsites/plotsquared/plot/util/block/ScopedLocalBlockQueue.java +++ b/Core/src/main/java/com/github/intellectualsites/plotsquared/plot/util/block/ScopedLocalBlockQueue.java @@ -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); }