From db6115eae5cd342ff394f2d908c3f6891383ea6b Mon Sep 17 00:00:00 2001 From: MattBDev <4009945+MattBDev@users.noreply.github.com> Date: Mon, 29 Apr 2019 15:19:49 -0400 Subject: [PATCH] Documentation and formatting changes --- .../bukkit/util/block/BukkitLocalQueue.java | 16 +-- .../plotsquared/plot/config/Config.java | 103 +++++++++--------- .../plot/generator/HybridPlotManager.java | 33 +++--- .../plot/object/worlds/SinglePlotManager.java | 10 +- .../plot/util/block/BasicLocalBlockQueue.java | 4 +- .../plot/util/block/LocalBlockQueue.java | 8 ++ 6 files changed, 88 insertions(+), 86 deletions(-) diff --git a/Bukkit/src/main/java/com/github/intellectualsites/plotsquared/bukkit/util/block/BukkitLocalQueue.java b/Bukkit/src/main/java/com/github/intellectualsites/plotsquared/bukkit/util/block/BukkitLocalQueue.java index e7e7113db..483fb51c0 100644 --- a/Bukkit/src/main/java/com/github/intellectualsites/plotsquared/bukkit/util/block/BukkitLocalQueue.java +++ b/Bukkit/src/main/java/com/github/intellectualsites/plotsquared/bukkit/util/block/BukkitLocalQueue.java @@ -45,16 +45,12 @@ public class BukkitLocalQueue extends BasicLocalBlockQueue { @Override public PlotBlock getBlock(int x, int y, int z) { World worldObj = Bukkit.getWorld(getWorld()); - Block block = worldObj.getBlockAt(x, y, z); - if (block == null) { + if (worldObj != null) { + Block block = worldObj.getBlockAt(x, y, z); + return PlotBlock.get(block.getType().toString()); + } else { return PlotBlock.get(0, 0); } - // int id = block.getTypeId(); - // if (id == 0) { - // return PlotBlock.get(0, 0); - // } - // return PlotBlock.get(id, block.getData()); - return PlotBlock.get(block.getType().toString()); } @Override public void refreshChunk(int x, int z) { @@ -194,9 +190,7 @@ public class BukkitLocalQueue extends BasicLocalBlockQueue { if (biomes2 != null) { for (String biomeStr : biomes2) { if (biomeStr != null) { - if (last == null || !StringMan.isEqual(last, biomeStr)) { - biome = Biome.valueOf(biomeStr.toUpperCase()); - } + biome = Biome.valueOf(biomeStr.toUpperCase()); worldObj.setBiome(bx, bz, biome); } } diff --git a/Core/src/main/java/com/github/intellectualsites/plotsquared/plot/config/Config.java b/Core/src/main/java/com/github/intellectualsites/plotsquared/plot/config/Config.java index 82992e265..ace39f846 100644 --- a/Core/src/main/java/com/github/intellectualsites/plotsquared/plot/config/Config.java +++ b/Core/src/main/java/com/github/intellectualsites/plotsquared/plot/config/Config.java @@ -105,10 +105,10 @@ public class Config { file.getParentFile().mkdirs(); file.createNewFile(); } - PrintWriter writer = new PrintWriter(file); - Object instance = root.newInstance(); - save(writer, root, instance, 0); - writer.close(); + try (PrintWriter writer = new PrintWriter(file)) { + Object instance = root.newInstance(); + save(writer, root, instance, 0); + } } catch (Throwable e) { e.printStackTrace(); } @@ -183,7 +183,6 @@ public class Config { } } } - continue; } else { writer.write(spacing + toNodeName(field.getName() + ": ") + toYamlString( field.get(instance), spacing) + lineSeparator); @@ -281,55 +280,53 @@ public class Config { Class clazz = root == null ? MethodHandles.lookup().lookupClass() : root; Object instance = clazz.newInstance(); while (split.length > 0) { - switch (split.length) { - case 1: - return instance; - default: - Class found = null; - Class[] classes = clazz.getDeclaredClasses(); - for (Class current : classes) { - if (current.getSimpleName().equalsIgnoreCase(toFieldName(split[0]))) { - found = current; - break; - } - } - try { - Field instanceField = clazz.getDeclaredField(toFieldName(split[0])); - setAccessible(instanceField); - if (instanceField.getType() != ConfigBlock.class) { - Object value = instanceField.get(instance); - if (value == null) { - value = found.newInstance(); - instanceField.set(instance, value); - } - clazz = found; - instance = value; - split = Arrays.copyOfRange(split, 1, split.length); - continue; - } - ConfigBlock value = (ConfigBlock) instanceField.get(instance); - if (value == null) { - value = new ConfigBlock(); - instanceField.set(instance, value); - } - instance = value.get(split[1]); - if (instance == null) { - instance = found.newInstance(); - value.put(split[1], instance); - } - clazz = found; - split = Arrays.copyOfRange(split, 2, split.length); - continue; - } catch (NoSuchFieldException ignore) { - } - if (found != null) { - split = Arrays.copyOfRange(split, 1, split.length); - clazz = found; - instance = clazz.newInstance(); - continue; - } - return null; + if (split.length == 1) { + return instance; } + Class found = null; + Class[] classes = clazz.getDeclaredClasses(); + for (Class current : classes) { + if (current.getSimpleName().equalsIgnoreCase(toFieldName(split[0]))) { + found = current; + break; + } + } + try { + Field instanceField = clazz.getDeclaredField(toFieldName(split[0])); + setAccessible(instanceField); + if (instanceField.getType() != ConfigBlock.class) { + Object value = instanceField.get(instance); + if (value == null) { + value = found.newInstance(); + instanceField.set(instance, value); + } + clazz = found; + instance = value; + split = Arrays.copyOfRange(split, 1, split.length); + continue; + } + ConfigBlock value = (ConfigBlock) instanceField.get(instance); + if (value == null) { + value = new ConfigBlock(); + instanceField.set(instance, value); + } + instance = value.get(split[1]); + if (instance == null) { + instance = found.newInstance(); + value.put(split[1], instance); + } + clazz = found; + split = Arrays.copyOfRange(split, 2, split.length); + continue; + } catch (NoSuchFieldException ignore) { + } + if (found != null) { + split = Arrays.copyOfRange(split, 1, split.length); + clazz = found; + instance = clazz.newInstance(); + continue; + } + return null; } } catch (Throwable e) { e.printStackTrace(); diff --git a/Core/src/main/java/com/github/intellectualsites/plotsquared/plot/generator/HybridPlotManager.java b/Core/src/main/java/com/github/intellectualsites/plotsquared/plot/generator/HybridPlotManager.java index a3b308335..10e7c1a8d 100644 --- a/Core/src/main/java/com/github/intellectualsites/plotsquared/plot/generator/HybridPlotManager.java +++ b/Core/src/main/java/com/github/intellectualsites/plotsquared/plot/generator/HybridPlotManager.java @@ -3,7 +3,14 @@ package com.github.intellectualsites.plotsquared.plot.generator; import com.github.intellectualsites.plotsquared.plot.PlotSquared; import com.github.intellectualsites.plotsquared.plot.commands.Template; import com.github.intellectualsites.plotsquared.plot.config.Settings; -import com.github.intellectualsites.plotsquared.plot.object.*; +import com.github.intellectualsites.plotsquared.plot.object.BlockBucket; +import com.github.intellectualsites.plotsquared.plot.object.FileBytes; +import com.github.intellectualsites.plotsquared.plot.object.Location; +import com.github.intellectualsites.plotsquared.plot.object.Plot; +import com.github.intellectualsites.plotsquared.plot.object.PlotArea; +import com.github.intellectualsites.plotsquared.plot.object.PlotBlock; +import com.github.intellectualsites.plotsquared.plot.object.PlotId; +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; @@ -11,7 +18,6 @@ import com.github.intellectualsites.plotsquared.plot.util.block.GlobalBlockQueue import com.github.intellectualsites.plotsquared.plot.util.block.LocalBlockQueue; import com.google.common.collect.Sets; import com.sk89q.worldedit.world.block.BaseBlock; - import java.io.File; import java.io.IOException; import java.nio.file.Files; @@ -144,10 +150,11 @@ public class HybridPlotManager extends ClassicPlotManager { } /** - *

Clearing the plot needs to only consider removing the blocks - This implementation has used the setCuboidAsync - * function, as it is fast, and uses NMS code - It also makes use of the fact that deleting chunks is a lot faster - * than block updates This code is very messy, but you don't need to do something quite as complex unless you happen - * to have 512x512 sized plots.

+ *

Clearing the plot needs to only consider removing the blocks - This implementation has + * used the setCuboidAsync function, as it is fast, and uses NMS code - It also makes use of the + * fact that deleting chunks is a lot faster than block updates This code is very messy, but you + * don't need to do something quite as complex unless you happen to have 512x512 sized plots. + *

*/ @Override public boolean clearPlot(final PlotArea plotArea, Plot plot, final Runnable whenDone) { @@ -177,9 +184,7 @@ public class HybridPlotManager extends ClassicPlotManager { queue.regenChunk(value[0], value[1]); return; } - /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// - // Otherwise we need to set each component, as we don't want to regenerate the road or other plots that share the same chunk // - /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// + /* Otherwise we need to set each component, as we don't want to regenerate the road or other plots that share the same chunk.*/ // Set the biome MainUtil.setBiome(world, value[2], value[3], value[4], value[5], biome); // These two locations are for each component (e.g. bedrock, main block, floor, air) @@ -199,12 +204,10 @@ public class HybridPlotManager extends ClassicPlotManager { // And finally set the schematic, the y value is unimportant for this function pastePlotSchematic(dpw, queue, bot, top); } - }, new Runnable() { - @Override public void run() { - queue.enqueue(); - // And notify whatever called this when plot clearing is done - GlobalBlockQueue.IMP.addTask(whenDone); - } + }, () -> { + queue.enqueue(); + // And notify whatever called this when plot clearing is done + GlobalBlockQueue.IMP.addTask(whenDone); }, 10); return true; } diff --git a/Core/src/main/java/com/github/intellectualsites/plotsquared/plot/object/worlds/SinglePlotManager.java b/Core/src/main/java/com/github/intellectualsites/plotsquared/plot/object/worlds/SinglePlotManager.java index 2b389ca9b..7146a898b 100644 --- a/Core/src/main/java/com/github/intellectualsites/plotsquared/plot/object/worlds/SinglePlotManager.java +++ b/Core/src/main/java/com/github/intellectualsites/plotsquared/plot/object/worlds/SinglePlotManager.java @@ -30,12 +30,10 @@ public class SinglePlotManager extends PlotManager { SetupUtils.manager.unload(plot.getWorldName(), false); final File worldFolder = new File(PlotSquared.get().IMP.getWorldContainer(), plot.getWorldName()); - TaskManager.IMP.taskAsync(new Runnable() { - @Override public void run() { - MainUtil.deleteDirectory(worldFolder); - if (whenDone != null) { - whenDone.run(); - } + TaskManager.IMP.taskAsync(() -> { + MainUtil.deleteDirectory(worldFolder); + if (whenDone != null) { + whenDone.run(); } }); return true; 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 99c0386cf..282c21bc4 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 @@ -116,7 +116,9 @@ public abstract class BasicLocalBlockQueue extends LocalBlockQueue { } @Override public boolean setBlock(int x, int y, int z, PlotBlock id) { - if ((y > 255) || (y < 0)) { + if (y > 255) { + return false; + } else if (y < 0) { return false; } int cx = x >> 4; 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 65dc13971..16538784f 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 @@ -37,6 +37,14 @@ public abstract class LocalBlockQueue { public abstract void setModified(long modified); + /** + * Sets the block at the coordinates provided to the given id. + * + * @param x the x coordinate from from 0 to 15 inclusive + * @param y the y coordinate from from 0 (inclusive) - maxHeight(exclusive) + * @param z the z coordinate from 0 to 15 inclusive + * @param id the id to set the block to + */ 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);