From bfcf24b27b477e6192768b89a155fb27eb040bfc Mon Sep 17 00:00:00 2001 From: MattBDev <4009945+MattBDev@users.noreply.github.com> Date: Sun, 23 Feb 2020 12:48:22 -0500 Subject: [PATCH] Small quality of code changes --- .../com/boydti/fawe/bukkit/FaweBukkit.java | 20 ------------- .../plotsquared/FaweLocalBlockQueue.java | 30 +++++++++---------- .../regions/plotsquared/PlotSetBiome.java | 6 ++-- .../src/main/java/com/boydti/fawe/Fawe.java | 4 +-- .../src/main/java/com/boydti/fawe/IFawe.java | 2 -- .../fawe/beta/implementation/queue/Pool.java | 1 + .../queue/SingleThreadQueueExtent.java | 8 ++--- .../java/com/boydti/fawe/config/Settings.java | 4 +-- .../fawe/object/brush/InspectBrush.java | 7 +++-- .../com/sk89q/worldedit/LocalSession.java | 4 --- 10 files changed, 32 insertions(+), 54 deletions(-) diff --git a/worldedit-bukkit/src/main/java/com/boydti/fawe/bukkit/FaweBukkit.java b/worldedit-bukkit/src/main/java/com/boydti/fawe/bukkit/FaweBukkit.java index fb72c84de..b6b145e60 100644 --- a/worldedit-bukkit/src/main/java/com/boydti/fawe/bukkit/FaweBukkit.java +++ b/worldedit-bukkit/src/main/java/com/boydti/fawe/bukkit/FaweBukkit.java @@ -27,7 +27,6 @@ import com.boydti.fawe.util.Jars; import com.boydti.fawe.util.TaskManager; import com.boydti.fawe.util.WEManager; import com.boydti.fawe.util.image.ImageViewer; -import com.boydti.fawe.util.task.Task; import com.sk89q.worldedit.bukkit.BukkitAdapter; import com.sk89q.worldedit.bukkit.BukkitPlayer; import io.papermc.lib.PaperLib; @@ -38,7 +37,6 @@ import java.util.Collection; import java.util.UUID; import java.util.function.Supplier; import org.bukkit.Bukkit; -import org.bukkit.command.ConsoleCommandSender; import org.bukkit.entity.Player; import org.bukkit.event.EventHandler; import org.bukkit.event.EventPriority; @@ -159,24 +157,6 @@ public class FaweBukkit implements IFawe, Listener { } - @Override - public com.sk89q.worldedit.entity.Player wrap(final Object obj) { - Player player = null; - if (obj.getClass() == Player.class) { - player = (Player) obj; - } else if (obj.getClass() == String.class) { - String name = (String) obj; - player = Bukkit.getPlayer(name); - } else if (obj.getClass() == UUID.class) { - UUID uuid = (UUID) obj; - player = Bukkit.getPlayer(uuid); - } - if (player == null) { - throw new IllegalArgumentException("Unknown player type: " + obj); - } - return BukkitAdapter.adapt(player); - } - public ItemUtil getItemUtil() { ItemUtil tmp = itemUtil; if (tmp == null) { diff --git a/worldedit-bukkit/src/main/java/com/boydti/fawe/bukkit/regions/plotsquared/FaweLocalBlockQueue.java b/worldedit-bukkit/src/main/java/com/boydti/fawe/bukkit/regions/plotsquared/FaweLocalBlockQueue.java index 10c0883ab..be0c7f8eb 100644 --- a/worldedit-bukkit/src/main/java/com/boydti/fawe/bukkit/regions/plotsquared/FaweLocalBlockQueue.java +++ b/worldedit-bukkit/src/main/java/com/boydti/fawe/bukkit/regions/plotsquared/FaweLocalBlockQueue.java @@ -18,21 +18,21 @@ import com.sk89q.worldedit.world.block.BlockState; // TODO FIXME public class FaweLocalBlockQueue extends LocalBlockQueue { - public final IQueueExtent IMP; + public final IQueueExtent instance; private final World world; private BlockVector3 mutable = new MutableBlockVector3(); public FaweLocalBlockQueue(String worldName) { super(worldName); this.world = FaweAPI.getWorld(worldName); - IMP = Fawe.get().getQueueHandler().getQueue(world); + instance = Fawe.get().getQueueHandler().getQueue(world); Fawe.get().getQueueHandler().unCache(); } @Override public boolean next() { - if (!IMP.isEmpty()) { - IMP.flush(); + if (!instance.isEmpty()) { + instance.flush(); } return false; } @@ -49,7 +49,7 @@ public class FaweLocalBlockQueue extends LocalBlockQueue { @Override public int size() { - return IMP.isEmpty() ? 0 : 1; + return instance.isEmpty() ? 0 : 1; } @Override @@ -62,33 +62,33 @@ public class FaweLocalBlockQueue extends LocalBlockQueue { @Override public long getModified() { - return IMP.size(); + return instance.size(); } @Override public boolean setBlock(final int x, final int y, final int z, final BlockState id) { - return IMP.setBlock(x, y, z, id); + return instance.setBlock(x, y, z, id); } @Override public boolean setBlock(int x, int y, int z, Pattern pattern) { mutable.setComponents(x, y, z); - return pattern.apply(IMP, mutable, mutable); + return pattern.apply(instance, mutable, mutable); } @Override public boolean setBlock(final int x, final int y, final int z, final BaseBlock id) { - return IMP.setBlock(x, y, z, id); + return instance.setBlock(x, y, z, id); } @Override public BlockState getBlock(int x, int y, int z) { - return IMP.getBlock(x, y, z); + return instance.getBlock(x, y, z); } @Override public boolean setBiome(int x, int z, BiomeType biomeType) { - return IMP.setBiome(x, 0, z, biomeType); + return instance.setBiome(x, 0, z, biomeType); } @Override @@ -98,13 +98,13 @@ public class FaweLocalBlockQueue extends LocalBlockQueue { @Override public void flush() { - IMP.flush(); + instance.flush(); } @Override public boolean enqueue() { boolean val = super.enqueue(); - IMP.enableQueue(); + instance.enableQueue(); return val; } @@ -119,12 +119,12 @@ public class FaweLocalBlockQueue extends LocalBlockQueue { @Override public void regenChunk(int x, int z) { - IMP.regenerateChunk(x, z, null, null); + instance.regenerateChunk(x, z, null, null); } @Override public boolean setTile(int x, int y, int z, CompoundTag tag) { - IMP.setTile(x, y, z, (com.sk89q.jnbt.CompoundTag) FaweCache.IMP.asTag(tag)); + instance.setTile(x, y, z, (com.sk89q.jnbt.CompoundTag) FaweCache.IMP.asTag(tag)); return true; } } diff --git a/worldedit-bukkit/src/main/java/com/boydti/fawe/bukkit/regions/plotsquared/PlotSetBiome.java b/worldedit-bukkit/src/main/java/com/boydti/fawe/bukkit/regions/plotsquared/PlotSetBiome.java index 1d142d132..fe9ebea84 100644 --- a/worldedit-bukkit/src/main/java/com/boydti/fawe/bukkit/regions/plotsquared/PlotSetBiome.java +++ b/worldedit-bukkit/src/main/java/com/boydti/fawe/bukkit/regions/plotsquared/PlotSetBiome.java @@ -19,6 +19,7 @@ import com.github.intellectualsites.plotsquared.plot.util.Permissions; import com.github.intellectualsites.plotsquared.plot.util.StringMan; import com.sk89q.worldedit.EditSession; import com.sk89q.worldedit.WorldEdit; +import com.sk89q.worldedit.bukkit.BukkitAdapter; import com.sk89q.worldedit.extension.platform.Capability; import com.sk89q.worldedit.regions.CuboidRegion; import com.sk89q.worldedit.world.biome.BiomeType; @@ -29,6 +30,7 @@ import java.util.Collection; import java.util.Set; import java.util.concurrent.CompletableFuture; import java.util.concurrent.ThreadLocalRandom; +import org.bukkit.Bukkit; @CommandDeclaration( command = "generatebiome", @@ -71,11 +73,11 @@ public class PlotSetBiome extends Command { } plot.addRunning(); TaskManager.IMP.async(() -> { - EditSession session = new EditSessionBuilder(FaweAPI.getWorld(plot.getArea().worldname)) + EditSession session = new EditSessionBuilder(BukkitAdapter.adapt(Bukkit.getWorld(plot.getArea().worldname))) .autoQueue(false) .checkMemory(false) .allowedRegionsEverywhere() - .player(Fawe.imp().wrap(player.getUUID())) + .player(BukkitAdapter.adapt(Bukkit.getPlayer(player.getUUID()))) .limitUnlimited() .build(); long seed = ThreadLocalRandom.current().nextLong(); diff --git a/worldedit-core/src/main/java/com/boydti/fawe/Fawe.java b/worldedit-core/src/main/java/com/boydti/fawe/Fawe.java index a394cf03c..83b1f1c2e 100644 --- a/worldedit-core/src/main/java/com/boydti/fawe/Fawe.java +++ b/worldedit-core/src/main/java/com/boydti/fawe/Fawe.java @@ -292,11 +292,11 @@ public class Fawe { } public void setupConfigs() { - MainUtil.copyFile(MainUtil.getJarFile(), "lang/strings.json", null); + MainUtil.copyFile(MainUtil.getJarFile(), "lang" + File.separator + "strings.json", null); // Setting up config.yml File file = new File(this.IMP.getDirectory(), "config.yml"); Settings.IMP.PLATFORM = IMP.getPlatform().replace("\"", ""); - try (InputStream stream = getClass().getResourceAsStream("/fawe.properties"); + try (InputStream stream = getClass().getResourceAsStream(File.separator + "fawe.properties"); BufferedReader br = new BufferedReader(new InputStreamReader(stream))) { String versionString = br.readLine(); String commitString = br.readLine(); diff --git a/worldedit-core/src/main/java/com/boydti/fawe/IFawe.java b/worldedit-core/src/main/java/com/boydti/fawe/IFawe.java index 0c72d462d..20a15faab 100644 --- a/worldedit-core/src/main/java/com/boydti/fawe/IFawe.java +++ b/worldedit-core/src/main/java/com/boydti/fawe/IFawe.java @@ -17,8 +17,6 @@ public interface IFawe { File getDirectory(); - Player wrap(final Object obj); - TaskManager getTaskManager(); Collection getMaskManagers(); diff --git a/worldedit-core/src/main/java/com/boydti/fawe/beta/implementation/queue/Pool.java b/worldedit-core/src/main/java/com/boydti/fawe/beta/implementation/queue/Pool.java index a56b17942..bab5bbf63 100644 --- a/worldedit-core/src/main/java/com/boydti/fawe/beta/implementation/queue/Pool.java +++ b/worldedit-core/src/main/java/com/boydti/fawe/beta/implementation/queue/Pool.java @@ -1,5 +1,6 @@ package com.boydti.fawe.beta.implementation.queue; +@FunctionalInterface public interface Pool { T poll(); default boolean offer(T recycle) { diff --git a/worldedit-core/src/main/java/com/boydti/fawe/beta/implementation/queue/SingleThreadQueueExtent.java b/worldedit-core/src/main/java/com/boydti/fawe/beta/implementation/queue/SingleThreadQueueExtent.java index 4a4283255..2524d3c40 100644 --- a/worldedit-core/src/main/java/com/boydti/fawe/beta/implementation/queue/SingleThreadQueueExtent.java +++ b/worldedit-core/src/main/java/com/boydti/fawe/beta/implementation/queue/SingleThreadQueueExtent.java @@ -188,13 +188,13 @@ public class SingleThreadQueueExtent extends ExtentBatchProcessorHolder implemen * Get a new IChunk from either the pool, or create a new one
+ Initialize it at the * coordinates * - * @param X - * @param Z + * @param chunkX + * @param chunkZ * @return IChunk */ - private ChunkHolder poolOrCreate(int X, int Z) { + private ChunkHolder poolOrCreate(int chunkX, int chunkZ) { ChunkHolder next = create(false); - next.init(this, X, Z); + next.init(this, chunkX, chunkZ); return next; } diff --git a/worldedit-core/src/main/java/com/boydti/fawe/config/Settings.java b/worldedit-core/src/main/java/com/boydti/fawe/config/Settings.java index 382d01e08..09c648a4c 100644 --- a/worldedit-core/src/main/java/com/boydti/fawe/config/Settings.java +++ b/worldedit-core/src/main/java/com/boydti/fawe/config/Settings.java @@ -93,7 +93,7 @@ public class Settings extends Config { " - Use a shared directory or NFS/Samba" }) public String CLIPBOARD = "clipboard"; - @Comment("Each player has their own sub directory for schematics") + @Comment("Each player has his or her own sub directory for schematics") public boolean PER_PLAYER_SCHEMATICS = true; public String COMMANDS = "commands"; } @@ -288,7 +288,7 @@ public class Settings extends Config { "Increase or decrease queue intensity (ms) [-50,50]:", " 0 = balance of performance / stability", " -10 = Allocate 10ms less for chunk placement", - "Too high will can cause lag spikes (you might be okay with this)", + "Too high can cause lag spikes (you might be okay with this)", "Too low will result in slow edits", }) public int EXTRA_TIME_MS = 0; diff --git a/worldedit-core/src/main/java/com/boydti/fawe/object/brush/InspectBrush.java b/worldedit-core/src/main/java/com/boydti/fawe/object/brush/InspectBrush.java index a31a3c543..b4594b97e 100644 --- a/worldedit-core/src/main/java/com/boydti/fawe/object/brush/InspectBrush.java +++ b/worldedit-core/src/main/java/com/boydti/fawe/object/brush/InspectBrush.java @@ -31,7 +31,7 @@ import java.util.Iterator; import java.util.UUID; import java.util.function.Supplier; -public class InspectBrush extends BrushTool implements DoubleActionTraceTool { +public class InspectBrush extends BrushTool { /** * Construct the tool. @@ -61,13 +61,14 @@ public class InspectBrush extends BrushTool implements DoubleActionTraceTool { } public boolean perform(final Player player, LocalSession session, boolean rightClick) { - if (!session.isToolControlEnabled() || !player.hasPermission("worldedit.tool.inspect")) { + if (!player.hasPermission("worldedit.tool.inspect")) { player.print(Caption.of("", "worldedit.tool.inspect")); System.out.println("No tool control"); return false; } if (!Settings.IMP.HISTORY.USE_DATABASE) { - player.print(Caption.of("fawe.error.setting.disable", ("history.use-database (Import with /history import )"))); + player.print(Caption.of("fawe.error.setting.disable", + "history.use-database (Import with /history import )")); System.out.println("No db"); return false; } diff --git a/worldedit-core/src/main/java/com/sk89q/worldedit/LocalSession.java b/worldedit-core/src/main/java/com/sk89q/worldedit/LocalSession.java index 8e0f79881..8b39d0460 100644 --- a/worldedit-core/src/main/java/com/sk89q/worldedit/LocalSession.java +++ b/worldedit-core/src/main/java/com/sk89q/worldedit/LocalSession.java @@ -1493,9 +1493,7 @@ public class LocalSession implements TextureHolder { private void prepareEditingExtents(EditSession editSession, Actor actor) { editSession.setFastMode(fastMode); - /* editSession.setReorderMode(reorderMode); - */ if (editSession.getSurvivalExtent() != null) { editSession.getSurvivalExtent().setStripNbt(!actor.hasPermission("worldedit.setnbt")); } @@ -1526,7 +1524,6 @@ public class LocalSession implements TextureHolder { * @return The reorder mode */ public EditSession.ReorderMode getReorderMode() { -// return reorderMode; return EditSession.ReorderMode.FAST; } @@ -1536,7 +1533,6 @@ public class LocalSession implements TextureHolder { * @param reorderMode The reorder mode */ public void setReorderMode(EditSession.ReorderMode reorderMode) { -// this.reorderMode = reorderMode; } /**