From 38435d50b4fecbc3254919c25121d67c49dca35e Mon Sep 17 00:00:00 2001 From: MattBDev <4009945+MattBDev@users.noreply.github.com> Date: Tue, 18 Feb 2020 18:00:39 -0500 Subject: [PATCH] More minor cleanup --- .../com/boydti/fawe/bukkit/FaweBukkit.java | 5 --- .../src/main/java/com/boydti/fawe/Fawe.java | 3 +- .../src/main/java/com/boydti/fawe/IFawe.java | 2 - .../implementation/queue/QueueHandler.java | 15 ++++---- .../fawe/database/RollbackDatabase.java | 2 +- .../com/boydti/fawe/object/HistoryExtent.java | 5 ++- .../com/boydti/fawe/util/IncendoPaster.java | 37 +++++++++---------- 7 files changed, 31 insertions(+), 38 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 0815b7298..2a4f1fed8 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 @@ -296,11 +296,6 @@ public class FaweBukkit implements IFawe, Listener { wePlayer.unregister(); } - @Override - public String getPlatform() { - return "bukkit"; - } - @Override public UUID getUUID(String name) { return Bukkit.getOfflinePlayer(name).getUniqueId(); 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 095d67cc6..aee82d89d 100644 --- a/worldedit-core/src/main/java/com/boydti/fawe/Fawe.java +++ b/worldedit-core/src/main/java/com/boydti/fawe/Fawe.java @@ -15,6 +15,7 @@ import com.boydti.fawe.util.WEManager; import com.github.luben.zstd.util.Native; import com.sk89q.worldedit.WorldEdit; import com.sk89q.worldedit.extension.platform.Actor; +import com.sk89q.worldedit.extension.platform.Capability; import com.sk89q.worldedit.session.request.Request; import java.io.BufferedReader; import java.io.File; @@ -281,7 +282,7 @@ public class Fawe { MainUtil.copyFile(MainUtil.getJarFile(), "lang/strings.json", null); // Setting up config.yml File file = new File(this.IMP.getDirectory(), "config.yml"); - Settings.IMP.PLATFORM = IMP.getPlatform().replace("\"", ""); + Settings.IMP.PLATFORM = WorldEdit.getInstance().getPlatformManager().queryCapability(Capability.WORLD_EDITING).getPlatformName(); try (InputStream stream = getClass().getResourceAsStream("/fawe.properties"); BufferedReader br = new BufferedReader(new InputStreamReader(stream))) { String versionString = 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 0374687d8..fac9bbeba 100644 --- a/worldedit-core/src/main/java/com/boydti/fawe/IFawe.java +++ b/worldedit-core/src/main/java/com/boydti/fawe/IFawe.java @@ -31,8 +31,6 @@ public interface IFawe { public default void registerPacketListener() {} - String getPlatform(); - UUID getUUID(String name); String getName(UUID uuid); diff --git a/worldedit-core/src/main/java/com/boydti/fawe/beta/implementation/queue/QueueHandler.java b/worldedit-core/src/main/java/com/boydti/fawe/beta/implementation/queue/QueueHandler.java index 343d4b484..912e0bdd5 100644 --- a/worldedit-core/src/main/java/com/boydti/fawe/beta/implementation/queue/QueueHandler.java +++ b/worldedit-core/src/main/java/com/boydti/fawe/beta/implementation/queue/QueueHandler.java @@ -38,14 +38,15 @@ import java.util.function.Supplier; @SuppressWarnings("UnstableApiUsage") public abstract class QueueHandler implements Trimable, Runnable { - private ForkJoinPool forkJoinPoolPrimary = new ForkJoinPool(); - private ForkJoinPool forkJoinPoolSecondary = new ForkJoinPool(); - private ThreadPoolExecutor blockingExecutor = FaweCache.IMP.newBlockingExecutor(); - private ConcurrentLinkedQueue syncTasks = new ConcurrentLinkedQueue<>(); - private ConcurrentLinkedQueue syncWhenFree = new ConcurrentLinkedQueue<>(); + private final ForkJoinPool forkJoinPoolPrimary = new ForkJoinPool(); + private final ForkJoinPool forkJoinPoolSecondary = new ForkJoinPool(); + private final ThreadPoolExecutor blockingExecutor = FaweCache.IMP.newBlockingExecutor(); + private final ConcurrentLinkedQueue syncTasks = new ConcurrentLinkedQueue<>(); + private final ConcurrentLinkedQueue syncWhenFree = new ConcurrentLinkedQueue<>(); - private Map>> chunkGetCache = new HashMap<>(); - private CleanableThreadLocal> queuePool = new CleanableThreadLocal<>(QueueHandler.this::create); + private final Map>> chunkGetCache = new HashMap<>(); + private final CleanableThreadLocal> queuePool = new CleanableThreadLocal<>( + QueueHandler.this::create); /** * Used to calculate elapsed time in milliseconds and ensure block placement doesn't lag the * server diff --git a/worldedit-core/src/main/java/com/boydti/fawe/database/RollbackDatabase.java b/worldedit-core/src/main/java/com/boydti/fawe/database/RollbackDatabase.java index a9753eb7b..d0388af10 100644 --- a/worldedit-core/src/main/java/com/boydti/fawe/database/RollbackDatabase.java +++ b/worldedit-core/src/main/java/com/boydti/fawe/database/RollbackDatabase.java @@ -53,7 +53,7 @@ public class RollbackDatabase extends AsyncNotifyQueue { private @Language("SQLite") String DELETE_EDITS_USER = "DELETE FROM `{0}edits` WHERE `player`=? AND `time`>? AND `x2`>=? AND `x1`<=? AND `y2`>=? AND `y1`<=? AND `z2`>=? AND `z1`<=?"; private @Language("SQLite") String DELETE_EDIT_USER = "DELETE FROM `{0}edits` WHERE `player`=? AND `id`=?"; - private ConcurrentLinkedQueue historyChanges = new ConcurrentLinkedQueue<>(); + private final ConcurrentLinkedQueue historyChanges = new ConcurrentLinkedQueue<>(); public RollbackDatabase(World world) throws SQLException, ClassNotFoundException { super((t, e) -> e.printStackTrace()); diff --git a/worldedit-core/src/main/java/com/boydti/fawe/object/HistoryExtent.java b/worldedit-core/src/main/java/com/boydti/fawe/object/HistoryExtent.java index e6ae99514..85f4cef2e 100644 --- a/worldedit-core/src/main/java/com/boydti/fawe/object/HistoryExtent.java +++ b/worldedit-core/src/main/java/com/boydti/fawe/object/HistoryExtent.java @@ -18,6 +18,7 @@ import com.sk89q.worldedit.world.block.BaseBlock; import com.sk89q.worldedit.world.block.BlockStateHolder; import java.util.ArrayList; import java.util.List; +import java.util.Objects; import javax.annotation.Nullable; /** @@ -97,7 +98,7 @@ public class HistoryExtent extends AbstractDelegateExtent { @Override public boolean setBiome(BlockVector2 position, BiomeType newBiome) { BiomeType oldBiome = this.getBiome(position); - if (oldBiome.getId() != newBiome.getId()) { + if (!Objects.equals(oldBiome.getId(), newBiome.getId())) { this.changeSet.addBiomeChange(position.getBlockX(), position.getBlockZ(), oldBiome, newBiome); return getExtent().setBiome(position, newBiome); } else { @@ -108,7 +109,7 @@ public class HistoryExtent extends AbstractDelegateExtent { @Override public boolean setBiome(int x, int y, int z, BiomeType newBiome) { BiomeType oldBiome = this.getBiome(BlockVector2.at(x, z)); - if (oldBiome.getId() != newBiome.getId()) { + if (!Objects.equals(oldBiome.getId(), newBiome.getId())) { this.changeSet.addBiomeChange(x, z, oldBiome, newBiome); return getExtent().setBiome(x, y, z, newBiome); } else { diff --git a/worldedit-core/src/main/java/com/boydti/fawe/util/IncendoPaster.java b/worldedit-core/src/main/java/com/boydti/fawe/util/IncendoPaster.java index 12e0e76f2..65894158b 100644 --- a/worldedit-core/src/main/java/com/boydti/fawe/util/IncendoPaster.java +++ b/worldedit-core/src/main/java/com/boydti/fawe/util/IncendoPaster.java @@ -16,6 +16,8 @@ import java.nio.file.Files; import java.util.*; import java.util.concurrent.Callable; import java.util.concurrent.TimeUnit; +import java.util.stream.Collectors; +import java.util.stream.IntStream; /** * Single class paster for the Incendo paste service @@ -60,7 +62,7 @@ public final class IncendoPaster implements Paster { return new PasteTask(content); } - private final class PasteTask implements Callable { + private static final class PasteTask implements Callable { private PasteTask(String content) {} @@ -153,14 +155,11 @@ public final class IncendoPaster implements Paster { throw new IllegalStateException(String.format("Server returned status: %d %s", httpURLConnection.getResponseCode(), httpURLConnection.getResponseMessage())); } - final StringBuilder input = new StringBuilder(); + final String input; try (final BufferedReader inputStream = new BufferedReader(new InputStreamReader(httpURLConnection.getInputStream()))) { - String line; - while ((line = inputStream.readLine()) != null) { - input.append(line).append("\n"); - } + input = inputStream.lines().map(line -> line + "\n").collect(Collectors.joining()); } - return input.toString(); + return input; } /** @@ -215,13 +214,15 @@ public final class IncendoPaster implements Paster { "# Welcome to this paste\n# It is meant to provide us at IntellectualSites with better information about your " + "problem\n"); b.append("\n# Server Information\n"); + assert Fawe.imp() != null; b.append(Fawe.imp().getDebugInfo()); b.append("\n# YAY! Now, let's see what we can find in your JVM\n"); Runtime runtime = Runtime.getRuntime(); RuntimeMXBean rb = ManagementFactory.getRuntimeMXBean(); - b.append("Uptime: ").append(TimeUnit.MINUTES.convert(rb.getUptime(), TimeUnit.MILLISECONDS) + " minutes").append('\n'); - b.append("Free Memory: ").append(runtime.freeMemory() / 1024 / 1024 + " MB").append('\n'); - b.append("Max Memory: ").append(runtime.maxMemory() / 1024 / 1024 + " MB").append('\n'); + b.append("Uptime: ").append(TimeUnit.MINUTES.convert(rb.getUptime(), TimeUnit.MILLISECONDS)) + .append(" minutes").append('\n'); + b.append("Free Memory: ").append(runtime.freeMemory() / 1024 / 1024).append(" MB").append('\n'); + b.append("Max Memory: ").append(runtime.maxMemory() / 1024 / 1024).append(" MB").append('\n'); b.append("Java Name: ").append(rb.getVmName()).append('\n'); b.append("Java Version: '").append(System.getProperty("java.version")).append("'\n"); b.append("Java Vendor: '").append(System.getProperty("java.vendor")).append("'\n"); @@ -267,18 +268,14 @@ public final class IncendoPaster implements Paster { } private static String readFile(final File file) throws IOException { - final StringBuilder content = new StringBuilder(); - final List lines = new ArrayList<>(); + final String content; + final List lines; try (final BufferedReader reader = new BufferedReader(new FileReader(file))) { - String line; - while ((line = reader.readLine()) != null) { - lines.add(line); - } + lines = reader.lines().collect(Collectors.toList()); } - for (int i = Math.max(0, lines.size() - 1000); i < lines.size(); i++) { - content.append(lines.get(i)).append("\n"); - } - return content.toString(); + content = IntStream.range(Math.max(0, lines.size() - 1000), lines.size()) + .mapToObj(i -> lines.get(i) + "\n").collect(Collectors.joining()); + return content; } }