diff --git a/Bukkit/src/main/java/com/github/intellectualsites/plotsquared/bukkit/object/BukkitOfflinePlayer.java b/Bukkit/src/main/java/com/github/intellectualsites/plotsquared/bukkit/object/BukkitOfflinePlayer.java index 390e9d9be..7c52a25de 100644 --- a/Bukkit/src/main/java/com/github/intellectualsites/plotsquared/bukkit/object/BukkitOfflinePlayer.java +++ b/Bukkit/src/main/java/com/github/intellectualsites/plotsquared/bukkit/object/BukkitOfflinePlayer.java @@ -2,6 +2,7 @@ package com.github.intellectualsites.plotsquared.bukkit.object; import com.github.intellectualsites.plotsquared.plot.object.OfflinePlotPlayer; import org.bukkit.OfflinePlayer; +import org.jetbrains.annotations.NotNull; import java.util.UUID; @@ -19,7 +20,7 @@ public class BukkitOfflinePlayer implements OfflinePlotPlayer { this.player = player; } - @Override public UUID getUUID() { + @NotNull @Override public UUID getUUID() { return this.player.getUniqueId(); } diff --git a/Bukkit/src/main/java/com/github/intellectualsites/plotsquared/bukkit/object/BukkitPlayer.java b/Bukkit/src/main/java/com/github/intellectualsites/plotsquared/bukkit/object/BukkitPlayer.java index 1afe93656..7b1ce2c54 100644 --- a/Bukkit/src/main/java/com/github/intellectualsites/plotsquared/bukkit/object/BukkitPlayer.java +++ b/Bukkit/src/main/java/com/github/intellectualsites/plotsquared/bukkit/object/BukkitPlayer.java @@ -6,7 +6,12 @@ import com.github.intellectualsites.plotsquared.plot.config.Captions; import com.github.intellectualsites.plotsquared.plot.object.Location; import com.github.intellectualsites.plotsquared.plot.object.PlotBlock; import com.github.intellectualsites.plotsquared.plot.object.PlotPlayer; -import com.github.intellectualsites.plotsquared.plot.util.*; +import com.github.intellectualsites.plotsquared.plot.util.EconHandler; +import com.github.intellectualsites.plotsquared.plot.util.MathMan; +import com.github.intellectualsites.plotsquared.plot.util.PlotGameMode; +import com.github.intellectualsites.plotsquared.plot.util.PlotWeather; +import com.github.intellectualsites.plotsquared.plot.util.StringMan; +import com.github.intellectualsites.plotsquared.plot.util.UUIDHandler; import org.bukkit.GameMode; import org.bukkit.Material; import org.bukkit.Sound; @@ -18,8 +23,8 @@ import org.bukkit.event.player.PlayerTeleportEvent; import org.bukkit.event.player.PlayerTeleportEvent.TeleportCause; import org.bukkit.permissions.PermissionAttachmentInfo; import org.bukkit.plugin.RegisteredListener; +import org.jetbrains.annotations.NotNull; -import javax.annotation.Nonnull; import java.util.Arrays; import java.util.Set; import java.util.UUID; @@ -55,7 +60,7 @@ public class BukkitPlayer extends PlotPlayer { return location == null ? BukkitUtil.getLocation(this.player) : location; } - @Nonnull @Override public UUID getUUID() { + @NotNull @Override public UUID getUUID() { if (this.uuid == null) { this.uuid = UUIDHandler.getUUID(this); } diff --git a/Bukkit/src/main/java/com/github/intellectualsites/plotsquared/bukkit/util/OfflinePlayerUtil.java b/Bukkit/src/main/java/com/github/intellectualsites/plotsquared/bukkit/util/OfflinePlayerUtil.java index f1bc97bb1..a3e40fae1 100644 --- a/Bukkit/src/main/java/com/github/intellectualsites/plotsquared/bukkit/util/OfflinePlayerUtil.java +++ b/Bukkit/src/main/java/com/github/intellectualsites/plotsquared/bukkit/util/OfflinePlayerUtil.java @@ -13,14 +13,6 @@ import static com.github.intellectualsites.plotsquared.plot.util.ReflectionUtils public class OfflinePlayerUtil { - public static Player loadPlayer(String name) { - return loadPlayer(Bukkit.getOfflinePlayer(name)); - } - - public static Player loadPlayer(UUID id) { - return loadPlayer(Bukkit.getOfflinePlayer(id)); - } - public static Player loadPlayer(OfflinePlayer player) { if (player == null) { return null; 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 eebac8ef0..1049d902a 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 @@ -26,8 +26,8 @@ public class GenChunk extends ScopedLocalBlockQueue { public BiomeGrid biomeGrid; public Chunk chunk; public String world; - public int cx; - public int cz; + public int chunkX; + public int chunkZ; @Getter @Setter private ChunkData cd = null; public GenChunk() { @@ -39,7 +39,7 @@ public class GenChunk extends ScopedLocalBlockQueue { if (chunk == null) { World worldObj = BukkitUtil.getWorld(world); if (worldObj != null) { - this.chunk = worldObj.getChunkAt(cx, cz); + this.chunk = worldObj.getChunkAt(chunkX, chunkZ); } } return chunk; @@ -52,8 +52,8 @@ public class GenChunk extends ScopedLocalBlockQueue { public void setChunk(ChunkWrapper wrap) { chunk = null; world = wrap.world; - cx = wrap.x; - cz = wrap.z; + chunkX = wrap.x; + chunkZ = wrap.z; } @Override public void fillBiome(String biomeName) { @@ -82,13 +82,13 @@ public class GenChunk extends ScopedLocalBlockQueue { Arrays.fill(data, start, end, block); } } - int minx = Math.min(pos1.getX(), pos2.getX()); - int miny = Math.min(pos1.getY(), pos2.getY()); - int minz = Math.min(pos1.getZ(), pos2.getZ()); - int maxx = Math.max(pos1.getX(), pos2.getX()); - int maxy = Math.max(pos1.getY(), pos2.getY()); - int maxz = Math.max(pos1.getZ(), pos2.getZ()); - cd.setRegion(minx, miny, minz, maxx + 1, maxy + 1, maxz + 1, block.to(Material.class)); + int minX = Math.min(pos1.getX(), pos2.getX()); + int minY = Math.min(pos1.getY(), pos2.getY()); + int minZ = Math.min(pos1.getZ(), pos2.getZ()); + int maxX = Math.max(pos1.getX(), pos2.getX()); + int maxY = Math.max(pos1.getY(), pos2.getY()); + int maxZ = Math.max(pos1.getZ(), pos2.getZ()); + cd.setRegion(minX, minY, minZ, maxX + 1, maxY + 1, maxZ + 1, block.to(Material.class)); } @Override public boolean setBiome(int x, int z, String biome) { @@ -147,11 +147,11 @@ public class GenChunk extends ScopedLocalBlockQueue { } public int getX() { - return chunk == null ? cx : chunk.getX(); + return chunk == null ? chunkX : chunk.getX(); } public int getZ() { - return chunk == null ? cz : chunk.getZ(); + return chunk == null ? chunkZ : chunk.getZ(); } @Override public String getWorld() { diff --git a/Bukkit/src/main/java/com/github/intellectualsites/plotsquared/bukkit/uuid/DefaultUUIDWrapper.java b/Bukkit/src/main/java/com/github/intellectualsites/plotsquared/bukkit/uuid/DefaultUUIDWrapper.java index ce058b691..40d902f8e 100644 --- a/Bukkit/src/main/java/com/github/intellectualsites/plotsquared/bukkit/uuid/DefaultUUIDWrapper.java +++ b/Bukkit/src/main/java/com/github/intellectualsites/plotsquared/bukkit/uuid/DefaultUUIDWrapper.java @@ -7,13 +7,14 @@ import com.github.intellectualsites.plotsquared.plot.object.PlotPlayer; import com.github.intellectualsites.plotsquared.plot.uuid.UUIDWrapper; import org.bukkit.Bukkit; import org.bukkit.OfflinePlayer; +import org.jetbrains.annotations.NotNull; import java.util.Arrays; import java.util.UUID; public class DefaultUUIDWrapper extends UUIDWrapper { - @Override public UUID getUUID(PlotPlayer player) { + @NotNull @Override public UUID getUUID(PlotPlayer player) { return ((BukkitPlayer) player).player.getUniqueId(); } diff --git a/Bukkit/src/main/java/com/github/intellectualsites/plotsquared/bukkit/uuid/LowerOfflineUUIDWrapper.java b/Bukkit/src/main/java/com/github/intellectualsites/plotsquared/bukkit/uuid/LowerOfflineUUIDWrapper.java index 55e2039a0..3f33387b9 100644 --- a/Bukkit/src/main/java/com/github/intellectualsites/plotsquared/bukkit/uuid/LowerOfflineUUIDWrapper.java +++ b/Bukkit/src/main/java/com/github/intellectualsites/plotsquared/bukkit/uuid/LowerOfflineUUIDWrapper.java @@ -4,14 +4,14 @@ import com.github.intellectualsites.plotsquared.plot.object.OfflinePlotPlayer; import com.github.intellectualsites.plotsquared.plot.object.PlotPlayer; import com.google.common.base.Charsets; import org.bukkit.OfflinePlayer; +import org.jetbrains.annotations.NotNull; import java.util.UUID; public class LowerOfflineUUIDWrapper extends OfflineUUIDWrapper { - @Override public UUID getUUID(PlotPlayer player) { - return UUID.nameUUIDFromBytes( - ("OfflinePlayer:" + player.getName().toLowerCase()).getBytes(Charsets.UTF_8)); + @NotNull @Override public UUID getUUID(PlotPlayer player) { + return UUID.nameUUIDFromBytes(("OfflinePlayer:" + player.getName().toLowerCase()).getBytes(Charsets.UTF_8)); } @Override public UUID getUUID(OfflinePlotPlayer player) { diff --git a/Bukkit/src/main/java/com/github/intellectualsites/plotsquared/bukkit/uuid/OfflineUUIDWrapper.java b/Bukkit/src/main/java/com/github/intellectualsites/plotsquared/bukkit/uuid/OfflineUUIDWrapper.java index 6686c09f1..306f67e4e 100644 --- a/Bukkit/src/main/java/com/github/intellectualsites/plotsquared/bukkit/uuid/OfflineUUIDWrapper.java +++ b/Bukkit/src/main/java/com/github/intellectualsites/plotsquared/bukkit/uuid/OfflineUUIDWrapper.java @@ -13,6 +13,7 @@ import org.bukkit.Bukkit; import org.bukkit.OfflinePlayer; import org.bukkit.Server; import org.bukkit.entity.Player; +import org.jetbrains.annotations.NotNull; import java.lang.reflect.InvocationTargetException; import java.lang.reflect.Method; @@ -33,9 +34,8 @@ public class OfflineUUIDWrapper extends UUIDWrapper { } } - @Override public UUID getUUID(PlotPlayer player) { - return UUID - .nameUUIDFromBytes(("OfflinePlayer:" + player.getName()).getBytes(Charsets.UTF_8)); + @NotNull @Override public UUID getUUID(PlotPlayer player) { + return UUID.nameUUIDFromBytes(("OfflinePlayer:" + player.getName()).getBytes(Charsets.UTF_8)); } @Override public UUID getUUID(OfflinePlotPlayer player) { diff --git a/Core/src/main/java/com/github/intellectualsites/plotsquared/commands/Command.java b/Core/src/main/java/com/github/intellectualsites/plotsquared/commands/Command.java index bf803d712..277ebe2e7 100644 --- a/Core/src/main/java/com/github/intellectualsites/plotsquared/commands/Command.java +++ b/Core/src/main/java/com/github/intellectualsites/plotsquared/commands/Command.java @@ -10,7 +10,11 @@ import com.github.intellectualsites.plotsquared.plot.object.PlotMessage; import com.github.intellectualsites.plotsquared.plot.object.PlotPlayer; import com.github.intellectualsites.plotsquared.plot.object.RunnableVal2; import com.github.intellectualsites.plotsquared.plot.object.RunnableVal3; -import com.github.intellectualsites.plotsquared.plot.util.*; +import com.github.intellectualsites.plotsquared.plot.util.MainUtil; +import com.github.intellectualsites.plotsquared.plot.util.MathMan; +import com.github.intellectualsites.plotsquared.plot.util.Permissions; +import com.github.intellectualsites.plotsquared.plot.util.StringComparison; +import com.github.intellectualsites.plotsquared.plot.util.StringMan; import java.io.IOException; import java.lang.reflect.InvocationTargetException; @@ -150,10 +154,10 @@ public abstract class Command { this.perm = declaration.permission(); this.required = declaration.requiredType(); this.category = declaration.category(); - HashMap options = new HashMap<>(); List aliasOptions = new ArrayList<>(); aliasOptions.add(this.id); aliasOptions.addAll(Arrays.asList(declaration.aliases())); + HashMap options = new HashMap<>(); options.put("aliases", aliasOptions); options.put("description", declaration.description()); options.put("usage", declaration.usage()); diff --git a/Core/src/main/java/com/github/intellectualsites/plotsquared/configuration/serialization/ConfigurationSerialization.java b/Core/src/main/java/com/github/intellectualsites/plotsquared/configuration/serialization/ConfigurationSerialization.java index 0783b4af5..cb1abd54a 100644 --- a/Core/src/main/java/com/github/intellectualsites/plotsquared/configuration/serialization/ConfigurationSerialization.java +++ b/Core/src/main/java/com/github/intellectualsites/plotsquared/configuration/serialization/ConfigurationSerialization.java @@ -212,10 +212,15 @@ public class ConfigurationSerialization { return result; } } catch (IllegalAccessException | InvocationTargetException | IllegalArgumentException ex) { - Logger.getLogger(ConfigurationSerialization.class.getName()).log(Level.SEVERE, - "Could not call method '" + method.toString() + "' of " + this.clazz - + " for deserialization", - ex instanceof InvocationTargetException ? ex.getCause() : ex); + if (ex instanceof InvocationTargetException) { + Logger.getLogger(ConfigurationSerialization.class.getName()).log(Level.SEVERE, + "Could not call method '" + method.toString() + "' of " + this.clazz + + " for deserialization", ex.getCause()); + } else { + Logger.getLogger(ConfigurationSerialization.class.getName()).log(Level.SEVERE, + "Could not call method '" + method.toString() + "' of " + this.clazz + + " for deserialization", ex); + } } return null; @@ -226,10 +231,15 @@ public class ConfigurationSerialization { try { return ctor.newInstance(args); } catch (IllegalAccessException | IllegalArgumentException | InvocationTargetException | InstantiationException ex) { - Logger.getLogger(ConfigurationSerialization.class.getName()).log(Level.SEVERE, - "Could not call constructor '" + ctor.toString() + "' of " + this.clazz - + " for deserialization", - ex instanceof InvocationTargetException ? ex.getCause() : ex); + if (ex instanceof InvocationTargetException) { + Logger.getLogger(ConfigurationSerialization.class.getName()).log(Level.SEVERE, + "Could not call constructor '" + ctor.toString() + "' of " + this.clazz + + " for deserialization", ex.getCause()); + } else { + Logger.getLogger(ConfigurationSerialization.class.getName()).log(Level.SEVERE, + "Could not call constructor '" + ctor.toString() + "' of " + this.clazz + + " for deserialization", ex); + } } return null; diff --git a/Core/src/main/java/com/github/intellectualsites/plotsquared/plot/commands/Auto.java b/Core/src/main/java/com/github/intellectualsites/plotsquared/plot/commands/Auto.java index fb6d571be..fa187877e 100644 --- a/Core/src/main/java/com/github/intellectualsites/plotsquared/plot/commands/Auto.java +++ b/Core/src/main/java/com/github/intellectualsites/plotsquared/plot/commands/Auto.java @@ -5,8 +5,17 @@ import com.github.intellectualsites.plotsquared.plot.PlotSquared; import com.github.intellectualsites.plotsquared.plot.config.Captions; import com.github.intellectualsites.plotsquared.plot.config.Settings; import com.github.intellectualsites.plotsquared.plot.database.DBFunc; -import com.github.intellectualsites.plotsquared.plot.object.*; -import com.github.intellectualsites.plotsquared.plot.util.*; +import com.github.intellectualsites.plotsquared.plot.object.Expression; +import com.github.intellectualsites.plotsquared.plot.object.Plot; +import com.github.intellectualsites.plotsquared.plot.object.PlotArea; +import com.github.intellectualsites.plotsquared.plot.object.PlotId; +import com.github.intellectualsites.plotsquared.plot.object.PlotPlayer; +import com.github.intellectualsites.plotsquared.plot.object.RunnableVal; +import com.github.intellectualsites.plotsquared.plot.util.ByteArrayUtilities; +import com.github.intellectualsites.plotsquared.plot.util.EconHandler; +import com.github.intellectualsites.plotsquared.plot.util.MainUtil; +import com.github.intellectualsites.plotsquared.plot.util.Permissions; +import com.github.intellectualsites.plotsquared.plot.util.TaskManager; import javax.annotation.Nullable; import java.util.Set; @@ -68,15 +77,15 @@ public class Auto extends SubCommand { * @param player * @param area * @param start - * @param schem + * @param schematic */ public static void homeOrAuto(final PlotPlayer player, final PlotArea area, PlotId start, - final String schem) { + final String schematic) { Set plots = player.getPlots(); if (!plots.isEmpty()) { plots.iterator().next().teleportPlayer(player); } else { - autoClaimSafe(player, area, start, schem); + autoClaimSafe(player, area, start, schematic); } } @@ -86,11 +95,11 @@ public class Auto extends SubCommand { * @param player * @param area * @param start - * @param schem + * @param schematic */ public static void autoClaimSafe(final PlotPlayer player, final PlotArea area, PlotId start, - final String schem) { - autoClaimSafe(player, area, start, schem, null); + final String schematic) { + autoClaimSafe(player, area, start, schematic, null); } /** @@ -99,10 +108,10 @@ public class Auto extends SubCommand { * @param player * @param area * @param start - * @param schem + * @param schematic */ public static void autoClaimSafe(final PlotPlayer player, final PlotArea area, PlotId start, - final String schem, @Nullable final Integer allowedPlots) { + final String schematic, @Nullable final Integer allowedPlots) { player.setMeta(Auto.class.getName(), true); autoClaimFromDatabase(player, area, start, new RunnableVal() { @Override public void run(final Plot plot) { @@ -112,7 +121,7 @@ public class Auto extends SubCommand { if (plot == null) { MainUtil.sendMessage(player, Captions.NO_FREE_PLOTS); } else if (checkAllowedPlots(player, area, allowedPlots, 1, 1)) { - plot.claim(player, true, schem, false); + plot.claim(player, true, schematic, false); if (area.AUTO_MERGE) { plot.autoMerge(-1, Integer.MAX_VALUE, player.getUUID(), true); } diff --git a/Core/src/main/java/com/github/intellectualsites/plotsquared/plot/commands/Clear.java b/Core/src/main/java/com/github/intellectualsites/plotsquared/plot/commands/Clear.java index c16b603ac..6bde7ffd0 100644 --- a/Core/src/main/java/com/github/intellectualsites/plotsquared/plot/commands/Clear.java +++ b/Core/src/main/java/com/github/intellectualsites/plotsquared/plot/commands/Clear.java @@ -36,33 +36,27 @@ import com.github.intellectualsites.plotsquared.plot.util.block.GlobalBlockQueue checkTrue(plot.getRunning() == 0, Captions.WAIT_FOR_TIMER); checkTrue(!Settings.Done.RESTRICT_BUILDING || !Flags.DONE.isSet(plot) || Permissions .hasPermission(player, Captions.PERMISSION_CONTINUE), Captions.DONE_ALREADY_DONE); - confirm.run(this, new Runnable() { - @Override public void run() { - final long start = System.currentTimeMillis(); - boolean result = plot.clear(true, false, new Runnable() { - @Override public void run() { - plot.unlink(); - GlobalBlockQueue.IMP.addTask(new Runnable() { - @Override public void run() { - plot.removeRunning(); - // If the state changes, then mark it as no longer done - if (plot.getFlag(Flags.DONE).isPresent()) { - FlagManager.removePlotFlag(plot, Flags.DONE); - } - if (plot.getFlag(Flags.ANALYSIS).isPresent()) { - FlagManager.removePlotFlag(plot, Flags.ANALYSIS); - } - MainUtil.sendMessage(player, Captions.CLEARING_DONE, - "" + (System.currentTimeMillis() - start)); - } - }); + confirm.run(this, () -> { + final long start = System.currentTimeMillis(); + boolean result = plot.clear(true, false, () -> { + plot.unlink(); + GlobalBlockQueue.IMP.addTask(() -> { + plot.removeRunning(); + // If the state changes, then mark it as no longer done + if (plot.getFlag(Flags.DONE).isPresent()) { + FlagManager.removePlotFlag(plot, Flags.DONE); } + if (plot.getFlag(Flags.ANALYSIS).isPresent()) { + FlagManager.removePlotFlag(plot, Flags.ANALYSIS); + } + MainUtil.sendMessage(player, Captions.CLEARING_DONE, + "" + (System.currentTimeMillis() - start)); }); - if (!result) { - MainUtil.sendMessage(player, Captions.WAIT_FOR_TIMER); - } else { - plot.addRunning(); - } + }); + if (!result) { + MainUtil.sendMessage(player, Captions.WAIT_FOR_TIMER); + } else { + plot.addRunning(); } }, null); } diff --git a/Core/src/main/java/com/github/intellectualsites/plotsquared/plot/commands/Cluster.java b/Core/src/main/java/com/github/intellectualsites/plotsquared/plot/commands/Cluster.java index a59c65550..32d7095a9 100644 --- a/Core/src/main/java/com/github/intellectualsites/plotsquared/plot/commands/Cluster.java +++ b/Core/src/main/java/com/github/intellectualsites/plotsquared/plot/commands/Cluster.java @@ -466,7 +466,6 @@ import java.util.UUID; PlotSquared.get().getPlots(player.getLocation().getWorld(), uuid))) { PlotCluster current = plot.getCluster(); if (current != null && current.equals(cluster)) { - player.getLocation().getWorld(); plot.unclaim(); } } diff --git a/Core/src/main/java/com/github/intellectualsites/plotsquared/plot/commands/Condense.java b/Core/src/main/java/com/github/intellectualsites/plotsquared/plot/commands/Condense.java index 478a0cab9..184e2289d 100644 --- a/Core/src/main/java/com/github/intellectualsites/plotsquared/plot/commands/Condense.java +++ b/Core/src/main/java/com/github/intellectualsites/plotsquared/plot/commands/Condense.java @@ -11,8 +11,12 @@ import com.github.intellectualsites.plotsquared.plot.util.MathMan; import com.github.intellectualsites.plotsquared.plot.util.TaskManager; import com.github.intellectualsites.plotsquared.plot.util.WorldUtil; +import java.util.ArrayList; +import java.util.Collection; +import java.util.HashSet; +import java.util.Iterator; +import java.util.List; import java.util.Set; -import java.util.*; import java.util.concurrent.atomic.AtomicBoolean; @CommandDeclaration(command = "condense", permission = "plots.admin", @@ -104,6 +108,7 @@ import java.util.concurrent.atomic.AtomicBoolean; return false; } MainUtil.sendMessage(player, "TASK STARTED..."); + Condense.TASK = true; Runnable run = new Runnable() { @Override public void run() { if (!Condense.TASK) { @@ -147,7 +152,6 @@ import java.util.concurrent.atomic.AtomicBoolean; } } }; - Condense.TASK = true; TaskManager.runTaskAsync(run); return true; } diff --git a/Core/src/main/java/com/github/intellectualsites/plotsquared/plot/commands/Database.java b/Core/src/main/java/com/github/intellectualsites/plotsquared/plot/commands/Database.java index e94850121..d908f2105 100644 --- a/Core/src/main/java/com/github/intellectualsites/plotsquared/plot/commands/Database.java +++ b/Core/src/main/java/com/github/intellectualsites/plotsquared/plot/commands/Database.java @@ -87,8 +87,8 @@ import java.util.Map.Entry; HashMap> map = manager.getPlots(); plots = new ArrayList<>(); for (Entry> entry : map.entrySet()) { - String areaname = entry.getKey(); - PlotArea pa = PlotSquared.get().getPlotAreaByString(areaname); + String areaName = entry.getKey(); + PlotArea pa = PlotSquared.get().getPlotAreaByString(areaName); if (pa != null) { for (Entry entry2 : entry.getValue().entrySet()) { Plot plot = entry2.getValue(); @@ -123,9 +123,9 @@ import java.util.Map.Entry; plots.add(plot); } } else { - HashMap plotmap = PlotSquared.get().plots_tmp - .computeIfAbsent(areaname, k -> new HashMap<>()); - plotmap.putAll(entry.getValue()); + HashMap plotMap = PlotSquared.get().plots_tmp + .computeIfAbsent(areaName, k -> new HashMap<>()); + plotMap.putAll(entry.getValue()); } } DBFunc.createPlotsAndData(plots, diff --git a/Core/src/main/java/com/github/intellectualsites/plotsquared/plot/commands/DebugPaste.java b/Core/src/main/java/com/github/intellectualsites/plotsquared/plot/commands/DebugPaste.java index f28b33a0a..7fe7bfdd1 100644 --- a/Core/src/main/java/com/github/intellectualsites/plotsquared/plot/commands/DebugPaste.java +++ b/Core/src/main/java/com/github/intellectualsites/plotsquared/plot/commands/DebugPaste.java @@ -27,11 +27,11 @@ import java.util.stream.Collectors; extends SubCommand { private static String readFile(@NonNull final File file) throws IOException { - final StringBuilder content = new StringBuilder(); final List lines; try (final BufferedReader reader = new BufferedReader(new FileReader(file))) { lines = reader.lines().collect(Collectors.toList()); } + final StringBuilder content = new StringBuilder(); for (int i = Math.max(0, lines.size() - 1000); i < lines.size(); i++) { content.append(lines.get(i)).append("\n"); } @@ -41,7 +41,6 @@ import java.util.stream.Collectors; @Override public boolean onCommand(final PlotPlayer player, String[] args) { TaskManager.runTaskAsync(() -> { try { - final IncendoPaster incendoPaster = new IncendoPaster("plotsquared"); StringBuilder b = new StringBuilder(); b.append( @@ -79,6 +78,7 @@ import java.util.stream.Collectors; "\n# You can do so at https://github.com/IntellectualSites/PlotSquared/issues"); b.append("\n# or via our Discord at https://discord.gg/ngZCzbU"); + final IncendoPaster incendoPaster = new IncendoPaster("plotsquared"); incendoPaster.addFile(new IncendoPaster.PasteFile("information", b.toString())); try { diff --git a/Core/src/main/java/com/github/intellectualsites/plotsquared/plot/commands/Deny.java b/Core/src/main/java/com/github/intellectualsites/plotsquared/plot/commands/Deny.java index 34a2936f8..fa6a1f96c 100644 --- a/Core/src/main/java/com/github/intellectualsites/plotsquared/plot/commands/Deny.java +++ b/Core/src/main/java/com/github/intellectualsites/plotsquared/plot/commands/Deny.java @@ -8,9 +8,13 @@ import com.github.intellectualsites.plotsquared.plot.database.DBFunc; import com.github.intellectualsites.plotsquared.plot.object.Location; import com.github.intellectualsites.plotsquared.plot.object.Plot; import com.github.intellectualsites.plotsquared.plot.object.PlotPlayer; -import com.github.intellectualsites.plotsquared.plot.util.*; +import com.github.intellectualsites.plotsquared.plot.util.EventUtil; +import com.github.intellectualsites.plotsquared.plot.util.MainUtil; +import com.github.intellectualsites.plotsquared.plot.util.Permissions; +import com.github.intellectualsites.plotsquared.plot.util.PlotGameMode; +import com.github.intellectualsites.plotsquared.plot.util.UUIDHandler; +import com.github.intellectualsites.plotsquared.plot.util.WorldUtil; -import java.util.Iterator; import java.util.Set; import java.util.UUID; @@ -44,9 +48,7 @@ import java.util.UUID; MainUtil.sendMessage(player, Captions.INVALID_PLAYER, args[0]); return false; } - Iterator iter = uuids.iterator(); - while (iter.hasNext()) { - UUID uuid = iter.next(); + for (UUID uuid : uuids) { if (uuid == DBFunc.EVERYONE && !( Permissions.hasPermission(player, Captions.PERMISSION_DENY_EVERYONE) || Permissions .hasPermission(player, Captions.PERMISSION_ADMIN_COMMAND_DENY))) { diff --git a/Core/src/main/java/com/github/intellectualsites/plotsquared/plot/commands/ListCmd.java b/Core/src/main/java/com/github/intellectualsites/plotsquared/plot/commands/ListCmd.java index e2951db6a..bd4613409 100644 --- a/Core/src/main/java/com/github/intellectualsites/plotsquared/plot/commands/ListCmd.java +++ b/Core/src/main/java/com/github/intellectualsites/plotsquared/plot/commands/ListCmd.java @@ -5,12 +5,22 @@ import com.github.intellectualsites.plotsquared.plot.PlotSquared; import com.github.intellectualsites.plotsquared.plot.PlotSquared.SortType; import com.github.intellectualsites.plotsquared.plot.config.Captions; import com.github.intellectualsites.plotsquared.plot.flag.Flags; -import com.github.intellectualsites.plotsquared.plot.object.*; +import com.github.intellectualsites.plotsquared.plot.object.Plot; +import com.github.intellectualsites.plotsquared.plot.object.PlotArea; +import com.github.intellectualsites.plotsquared.plot.object.PlotMessage; +import com.github.intellectualsites.plotsquared.plot.object.PlotPlayer; +import com.github.intellectualsites.plotsquared.plot.object.Rating; +import com.github.intellectualsites.plotsquared.plot.object.RunnableVal3; import com.github.intellectualsites.plotsquared.plot.util.*; import com.github.intellectualsites.plotsquared.plot.util.expiry.ExpireManager; -import java.util.*; +import java.util.ArrayList; +import java.util.Arrays; +import java.util.Iterator; +import java.util.List; import java.util.Map.Entry; +import java.util.Optional; +import java.util.UUID; @CommandDeclaration(command = "list", aliases = {"l", "find", "search"}, description = "List plots", permission = "plots.list", category = CommandCategory.INFO, @@ -20,7 +30,7 @@ public class ListCmd extends SubCommand { private String[] getArgumentList(PlotPlayer player) { List args = new ArrayList<>(); if (EconHandler.manager != null && Permissions - .hasPermission(player, Captions.PERMISSION_LIST_FORSALE)) { + .hasPermission(player, Captions.PERMISSION_LIST_FOR_SALE)) { args.add("forsale"); } if (Permissions.hasPermission(player, Captions.PERMISSION_LIST_MINE)) { @@ -222,9 +232,9 @@ public class ListCmd extends SubCommand { sort = false; break; case "forsale": - if (!Permissions.hasPermission(player, Captions.PERMISSION_LIST_FORSALE)) { + if (!Permissions.hasPermission(player, Captions.PERMISSION_LIST_FOR_SALE)) { MainUtil.sendMessage(player, Captions.NO_PERMISSION, - Captions.PERMISSION_LIST_FORSALE); + Captions.PERMISSION_LIST_FOR_SALE); return false; } if (EconHandler.manager == null) { diff --git a/Core/src/main/java/com/github/intellectualsites/plotsquared/plot/commands/Load.java b/Core/src/main/java/com/github/intellectualsites/plotsquared/plot/commands/Load.java index 234568fda..d18332798 100644 --- a/Core/src/main/java/com/github/intellectualsites/plotsquared/plot/commands/Load.java +++ b/Core/src/main/java/com/github/intellectualsites/plotsquared/plot/commands/Load.java @@ -4,7 +4,11 @@ import com.github.intellectualsites.plotsquared.commands.CommandDeclaration; import com.github.intellectualsites.plotsquared.plot.PlotSquared; import com.github.intellectualsites.plotsquared.plot.config.Captions; import com.github.intellectualsites.plotsquared.plot.config.Settings; -import com.github.intellectualsites.plotsquared.plot.object.*; +import com.github.intellectualsites.plotsquared.plot.object.Plot; +import com.github.intellectualsites.plotsquared.plot.object.PlotArea; +import com.github.intellectualsites.plotsquared.plot.object.PlotId; +import com.github.intellectualsites.plotsquared.plot.object.PlotPlayer; +import com.github.intellectualsites.plotsquared.plot.object.RunnableVal; import com.github.intellectualsites.plotsquared.plot.object.schematic.Schematic; import com.github.intellectualsites.plotsquared.plot.util.MainUtil; import com.github.intellectualsites.plotsquared.plot.util.Permissions; @@ -50,9 +54,9 @@ import java.util.List; MainUtil.sendMessage(player, Captions.LOAD_NULL); return false; } - String schem; + String schematic; try { - schem = schematics.get(Integer.parseInt(args[0]) - 1); + schematic = schematics.get(Integer.parseInt(args[0]) - 1); } catch (Exception ignored) { // use /plot load MainUtil.sendMessage(player, Captions.NOT_VALID_NUMBER, @@ -61,7 +65,7 @@ import java.util.List; } final URL url; try { - url = new URL(Settings.Web.URL + "saves/" + player.getUUID() + '/' + schem); + url = new URL(Settings.Web.URL + "saves/" + player.getUUID() + '/' + schematic); } catch (MalformedURLException e) { e.printStackTrace(); MainUtil.sendMessage(player, Captions.LOAD_FAILED); @@ -70,8 +74,8 @@ import java.util.List; plot.addRunning(); MainUtil.sendMessage(player, Captions.GENERATING_COMPONENT); TaskManager.runTaskAsync(() -> { - Schematic schematic = SchematicHandler.manager.getSchematic(url); - if (schematic == null) { + Schematic taskSchematic = SchematicHandler.manager.getSchematic(url); + if (taskSchematic == null) { plot.removeRunning(); sendMessage(player, Captions.SCHEMATIC_INVALID, "non-existent or not in gzip format"); @@ -79,7 +83,7 @@ import java.util.List; } PlotArea area = plot.getArea(); SchematicHandler.manager - .paste(schematic, plot, 0, area.MIN_BUILD_HEIGHT, 0, false, + .paste(taskSchematic, plot, 0, area.MIN_BUILD_HEIGHT, 0, false, new RunnableVal() { @Override public void run(Boolean value) { plot.removeRunning(); diff --git a/Core/src/main/java/com/github/intellectualsites/plotsquared/plot/commands/Remove.java b/Core/src/main/java/com/github/intellectualsites/plotsquared/plot/commands/Remove.java index 30c364671..875eb6e4c 100644 --- a/Core/src/main/java/com/github/intellectualsites/plotsquared/plot/commands/Remove.java +++ b/Core/src/main/java/com/github/intellectualsites/plotsquared/plot/commands/Remove.java @@ -44,11 +44,11 @@ import java.util.UUID; int count = 0; switch (args[0]) { case "unknown": { - ArrayList toRemove = new ArrayList<>(); HashSet all = new HashSet<>(); all.addAll(plot.getMembers()); all.addAll(plot.getTrusted()); all.addAll(plot.getDenied()); + ArrayList toRemove = new ArrayList<>(); for (UUID uuid : all) { if (UUIDHandler.getName(uuid) == null) { toRemove.add(uuid); diff --git a/Core/src/main/java/com/github/intellectualsites/plotsquared/plot/commands/SchematicCmd.java b/Core/src/main/java/com/github/intellectualsites/plotsquared/plot/commands/SchematicCmd.java index 48f0a8a1c..24ccbe016 100644 --- a/Core/src/main/java/com/github/intellectualsites/plotsquared/plot/commands/SchematicCmd.java +++ b/Core/src/main/java/com/github/intellectualsites/plotsquared/plot/commands/SchematicCmd.java @@ -4,9 +4,19 @@ import com.github.intellectualsites.plotsquared.commands.CommandDeclaration; import com.github.intellectualsites.plotsquared.plot.PlotSquared; import com.github.intellectualsites.plotsquared.plot.config.Captions; import com.github.intellectualsites.plotsquared.plot.config.Settings; -import com.github.intellectualsites.plotsquared.plot.object.*; +import com.github.intellectualsites.plotsquared.plot.object.ConsolePlayer; +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.PlotPlayer; +import com.github.intellectualsites.plotsquared.plot.object.RunnableVal; import com.github.intellectualsites.plotsquared.plot.object.schematic.Schematic; -import com.github.intellectualsites.plotsquared.plot.util.*; +import com.github.intellectualsites.plotsquared.plot.util.MainUtil; +import com.github.intellectualsites.plotsquared.plot.util.Permissions; +import com.github.intellectualsites.plotsquared.plot.util.SchematicHandler; +import com.github.intellectualsites.plotsquared.plot.util.StringMan; +import com.github.intellectualsites.plotsquared.plot.util.TaskManager; +import com.google.common.collect.Lists; import java.net.URL; import java.util.ArrayList; @@ -191,9 +201,7 @@ public class SchematicCmd extends SubCommand { MainUtil.sendMessage(player, Captions.NO_PLOT_PERMS); return false; } - location.getWorld(); - Collection plots = new ArrayList<>(); - plots.add(plot); + ArrayList plots = Lists.newArrayList(plot); boolean result = SchematicHandler.manager.exportAll(plots, null, null, () -> { MainUtil.sendMessage(player, "&aFinished export"); SchematicCmd.this.running = false; @@ -212,7 +220,7 @@ public class SchematicCmd extends SubCommand { return false; } final String string = - StringMan.join(SchematicHandler.manager.getShematicNames(), "$2, $1"); + StringMan.join(SchematicHandler.manager.getSchematicNames(), "$2, $1"); Captions.SCHEMATIC_LIST.send(player, string); } break; diff --git a/Core/src/main/java/com/github/intellectualsites/plotsquared/plot/commands/Setup.java b/Core/src/main/java/com/github/intellectualsites/plotsquared/plot/commands/Setup.java index 66fbd041a..2b7e5ab7f 100644 --- a/Core/src/main/java/com/github/intellectualsites/plotsquared/plot/commands/Setup.java +++ b/Core/src/main/java/com/github/intellectualsites/plotsquared/plot/commands/Setup.java @@ -6,7 +6,11 @@ import com.github.intellectualsites.plotsquared.plot.config.Captions; import com.github.intellectualsites.plotsquared.plot.config.Configuration; import com.github.intellectualsites.plotsquared.plot.config.ConfigurationNode; import com.github.intellectualsites.plotsquared.plot.generator.GeneratorWrapper; -import com.github.intellectualsites.plotsquared.plot.object.*; +import com.github.intellectualsites.plotsquared.plot.object.PlotArea; +import com.github.intellectualsites.plotsquared.plot.object.PlotId; +import com.github.intellectualsites.plotsquared.plot.object.PlotMessage; +import com.github.intellectualsites.plotsquared.plot.object.PlotPlayer; +import com.github.intellectualsites.plotsquared.plot.object.SetupObject; import com.github.intellectualsites.plotsquared.plot.util.MainUtil; import com.github.intellectualsites.plotsquared.plot.util.SetupUtils; import com.github.intellectualsites.plotsquared.plot.util.StringMan; @@ -345,7 +349,7 @@ import java.util.Map.Entry; return messages; } - @Override public boolean parseInut(String input) { + @Override public boolean parseInput(String input) { this.generator = input.toLowerCase(); return true; } @@ -385,7 +389,7 @@ import java.util.Map.Entry; return messages; } - @Override public boolean parseInut(String input) { + @Override public boolean parseInput(String input) { if (!WORLD_TYPES.keySet().contains(input.toLowerCase())) { return false; } @@ -416,7 +420,7 @@ import java.util.Map.Entry; public abstract Collection showDescriptionMessage(); - public abstract boolean parseInut(String input); + public abstract boolean parseInput(String input); public final PlotMessage getUsage() { return new PlotMessage("Usage: ").color("$1") diff --git a/Core/src/main/java/com/github/intellectualsites/plotsquared/plot/commands/Trust.java b/Core/src/main/java/com/github/intellectualsites/plotsquared/plot/commands/Trust.java index 6724efdda..81a508ee3 100644 --- a/Core/src/main/java/com/github/intellectualsites/plotsquared/plot/commands/Trust.java +++ b/Core/src/main/java/com/github/intellectualsites/plotsquared/plot/commands/Trust.java @@ -39,25 +39,25 @@ import java.util.UUID; checkTrue(args.length == 1, Captions.COMMAND_SYNTAX, getUsage()); final Set uuids = MainUtil.getUUIDsFromString(args[0]); checkTrue(!uuids.isEmpty(), Captions.INVALID_PLAYER, args[0]); - Iterator iter = uuids.iterator(); + Iterator iterator = uuids.iterator(); int size = currentPlot.getTrusted().size() + currentPlot.getMembers().size(); - while (iter.hasNext()) { - UUID uuid = iter.next(); + while (iterator.hasNext()) { + UUID uuid = iterator.next(); if (uuid == DBFunc.EVERYONE && !( Permissions.hasPermission(player, Captions.PERMISSION_TRUST_EVERYONE) || Permissions .hasPermission(player, Captions.PERMISSION_ADMIN_COMMAND_TRUST))) { MainUtil.sendMessage(player, Captions.INVALID_PLAYER, MainUtil.getName(uuid)); - iter.remove(); + iterator.remove(); continue; } if (currentPlot.isOwner(uuid)) { MainUtil.sendMessage(player, Captions.ALREADY_OWNER, MainUtil.getName(uuid)); - iter.remove(); + iterator.remove(); continue; } if (currentPlot.getTrusted().contains(uuid)) { MainUtil.sendMessage(player, Captions.ALREADY_ADDED, MainUtil.getName(uuid)); - iter.remove(); + iterator.remove(); continue; } size += currentPlot.getMembers().contains(uuid) ? 0 : 1; diff --git a/Core/src/main/java/com/github/intellectualsites/plotsquared/plot/config/Captions.java b/Core/src/main/java/com/github/intellectualsites/plotsquared/plot/config/Captions.java index 2037bcdf1..0c6f501df 100644 --- a/Core/src/main/java/com/github/intellectualsites/plotsquared/plot/config/Captions.java +++ b/Core/src/main/java/com/github/intellectualsites/plotsquared/plot/config/Captions.java @@ -125,8 +125,8 @@ public enum Captions { PERMISSION_FLAG_ADD("plots.flag.add", "static.permissions"), PERMISSION_FLAG_LIST("plots.flag.list", "static.permissions"), PERMISSION_ADMIN_COMMAND_KICK("plots.admin.command.kick", "static.permissions"), - PERMISSION_GRANT("plots.grant.%s0", "static.permissions"), - PERMISSION_LIST_FORSALE("plots.list.forsale", "static.permissions"), + PERMISSION_GRANT("plots.grant.%s0", "static.permissions"), PERMISSION_LIST_FOR_SALE( + "plots.list.forsale", "static.permissions"), PERMISSION_LIST_MINE("plots.list.mine", "static.permissions"), PERMISSION_LIST_SHARED("plots.list.shared", "static.permissions"), PERMISSION_LIST_WORLD("plots.list.world", "static.permissions"), @@ -211,37 +211,25 @@ public enum Captions { CLUSTER_AVAILABLE_ARGS( "$1The following sub commands are available: $4list$2, $4create$2, $4delete$2, $4resize$2, $4invite$2, $4kick$2, $4leave$2, " + "$4members$2, $4info$2, $4tp$2, $4sethome", "Cluster"), CLUSTER_LIST_HEADING( - "$2There are $1%s$2 clusters in this world", "Cluster"), - - CLUSTER_LIST_ELEMENT("$2 - $1%s&-", "Cluster"), CLUSTER_INTERSECTION( - "$2The proposed area overlaps with: %s0", "Cluster"), - - CLUSTER_OUTSIDE("$2The proposed area is outside the plot area: %s0", "Cluster"), CLUSTER_ADDED( - "$4Successfully created the cluster.", "Cluster"), - - CLUSTER_DELETED("$4Successfully deleted the cluster.", "Cluster"), CLUSTER_RESIZED( - "$4Successfully resized the cluster.", "Cluster"), - - CLUSTER_ADDED_USER("$4Successfully added user to the cluster.", "Cluster"), CANNOT_KICK_PLAYER( - "$2You cannot kick that player", "Cluster"), - - CLUSTER_INVITED("$1You have been invited to the following cluster: $2%s", - "Cluster"), CLUSTER_REMOVED("$1You have been removed from cluster: $2%s", "Cluster"), - - CLUSTER_KICKED_USER("$4Successfully kicked the user", "Cluster"), INVALID_CLUSTER( - "$1Invalid cluster name: $2%s", "Cluster"), - - CLUSTER_NOT_ADDED("$2That player was not added to the plot cluster", - "Cluster"), CLUSTER_CANNOT_LEAVE("$1You must delete or transfer ownership before leaving", - "Cluster"), - - CLUSTER_ADDED_HELPER("$4Successfully added a helper to the cluster", + "$2There are $1%s$2 clusters in this world", "Cluster"), CLUSTER_LIST_ELEMENT("$2 - $1%s&-", + "Cluster"), CLUSTER_INTERSECTION( + "$2The proposed area overlaps with: %s0", "Cluster"), CLUSTER_OUTSIDE( + "$2The proposed area is outside the plot area: %s0", "Cluster"), CLUSTER_ADDED( + "$4Successfully created the cluster.", "Cluster"), CLUSTER_DELETED( + "$4Successfully deleted the cluster.", "Cluster"), CLUSTER_RESIZED( + "$4Successfully resized the cluster.", "Cluster"), CLUSTER_ADDED_USER( + "$4Successfully added user to the cluster.", "Cluster"), CANNOT_KICK_PLAYER( + "$2You cannot kick that player", "Cluster"), CLUSTER_INVITED( + "$1You have been invited to the following cluster: $2%s", "Cluster"), CLUSTER_REMOVED( + "$1You have been removed from cluster: $2%s", "Cluster"), CLUSTER_KICKED_USER( + "$4Successfully kicked the user", "Cluster"), INVALID_CLUSTER( + "$1Invalid cluster name: $2%s", "Cluster"), CLUSTER_NOT_ADDED( + "$2That player was not added to the plot cluster", "Cluster"), CLUSTER_CANNOT_LEAVE( + "$1You must delete or transfer ownership before leaving", + "Cluster"), CLUSTER_ADDED_HELPER("$4Successfully added a helper to the cluster", "Cluster"), CLUSTER_REMOVED_HELPER("$4Successfully removed a helper from the cluster", - "Cluster"), - - CLUSTER_REGENERATED("$4Successfully started cluster regeneration", + "Cluster"), CLUSTER_REGENERATED("$4Successfully started cluster regeneration", "Cluster"), CLUSTER_TELEPORTING("$4Teleporting...", "Cluster"), - CLUSTER_INFO( "$1Current cluster: $2%id%&-$1Name: $2%name%&-$1Owner: $2%owner%&-$1Size: $2%size%&-$1Rights: $2%rights%", "Cluster"), diff --git a/Core/src/main/java/com/github/intellectualsites/plotsquared/plot/database/SQLManager.java b/Core/src/main/java/com/github/intellectualsites/plotsquared/plot/database/SQLManager.java index fac357c46..ed0eee71d 100644 --- a/Core/src/main/java/com/github/intellectualsites/plotsquared/plot/database/SQLManager.java +++ b/Core/src/main/java/com/github/intellectualsites/plotsquared/plot/database/SQLManager.java @@ -308,7 +308,6 @@ import java.util.concurrent.atomic.AtomicInteger; PlotSquared.debug("============ DATABASE ERROR ============"); PlotSquared.debug("There was an error updating the database."); PlotSquared.debug(" - It will be corrected on shutdown"); - PlotSquared.debug("========================================"); e.printStackTrace(); PlotSquared.debug("========================================"); } @@ -326,15 +325,15 @@ import java.util.concurrent.atomic.AtomicInteger; PreparedStatement statement = null; UniqueStatement task = null; UniqueStatement lastTask = null; - Iterator>> iter = + Iterator>> iterator = this.plotTasks.entrySet().iterator(); - while (iter.hasNext()) { + while (iterator.hasNext()) { try { - Entry> entry = iter.next(); + Entry> entry = iterator.next(); Plot plot = entry.getKey(); Queue tasks = entry.getValue(); if (tasks.isEmpty()) { - iter.remove(); + iterator.remove(); continue; } task = tasks.remove(); @@ -352,7 +351,7 @@ import java.util.concurrent.atomic.AtomicInteger; task.set(statement); task.addBatch(statement); try { - if (statement != null && statement.isClosed()) { + if (statement.isClosed()) { statement = null; } } catch (AbstractMethodError ignore) { @@ -1615,17 +1614,17 @@ import java.util.concurrent.atomic.AtomicInteger; PlotId plot_id = new PlotId(resultSet.getInt("plot_id_x"), resultSet.getInt("plot_id_z")); id = resultSet.getInt("id"); - String areaid = resultSet.getString("world"); - if (!areas.contains(areaid)) { + String areaID = resultSet.getString("world"); + if (!areas.contains(areaID)) { if (Settings.Enabled_Components.DATABASE_PURGER) { toDelete.add(id); continue; } else { - AtomicInteger value = noExist.get(areaid); + AtomicInteger value = noExist.get(areaID); if (value != null) { value.incrementAndGet(); } else { - noExist.put(areaid, new AtomicInteger(1)); + noExist.put(areaID, new AtomicInteger(1)); } } } @@ -1657,7 +1656,7 @@ import java.util.concurrent.atomic.AtomicInteger; .getTime(); } catch (ParseException e) { PlotSquared.debug( - "Could not parse date for plot: #" + id + "(" + areaid + ";" + "Could not parse date for plot: #" + id + "(" + areaID + ";" + plot_id + ") (" + parsable + ")"); time = System.currentTimeMillis() + id; } @@ -1665,7 +1664,7 @@ import java.util.concurrent.atomic.AtomicInteger; Plot p = new Plot(plot_id, user, new HashSet<>(), new HashSet<>(), new HashSet<>(), "", null, null, null, new boolean[] {false, false, false, false}, time, id); - HashMap map = newPlots.get(areaid); + HashMap map = newPlots.get(areaID); if (map != null) { Plot last = map.put(p.getId(), p); if (last != null) { @@ -1679,7 +1678,7 @@ import java.util.concurrent.atomic.AtomicInteger; } } else { map = new HashMap<>(); - newPlots.put(areaid, map); + newPlots.put(areaID, map); map.put(p.getId(), p); } plots.put(id, p); 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 1d18cbdcd..005a22d72 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 @@ -1,7 +1,12 @@ package com.github.intellectualsites.plotsquared.plot.generator; import com.github.intellectualsites.plotsquared.plot.PlotSquared; -import com.github.intellectualsites.plotsquared.plot.object.*; +import com.github.intellectualsites.plotsquared.plot.object.Location; +import com.github.intellectualsites.plotsquared.plot.object.PlotArea; +import com.github.intellectualsites.plotsquared.plot.object.PlotBlock; +import com.github.intellectualsites.plotsquared.plot.object.PlotManager; +import com.github.intellectualsites.plotsquared.plot.object.RegionWrapper; +import com.github.intellectualsites.plotsquared.plot.object.StringPlotBlock; import com.github.intellectualsites.plotsquared.plot.util.block.DelegateLocalBlockQueue; import com.github.intellectualsites.plotsquared.plot.util.block.GlobalBlockQueue; import com.github.intellectualsites.plotsquared.plot.util.block.LocalBlockQueue; @@ -49,7 +54,7 @@ public class AugmentedUtils { queue = GlobalBlockQueue.IMP.getNewQueue(world, false); } LocalBlockQueue primaryMask; - // coords + // coordinates int bxx; int bzz; int txx; 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 4796e3644..44e1d1705 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,14 +3,7 @@ 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.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.object.*; import com.github.intellectualsites.plotsquared.plot.util.ChunkManager; import com.github.intellectualsites.plotsquared.plot.util.MainUtil; import com.github.intellectualsites.plotsquared.plot.util.MathMan; @@ -18,6 +11,7 @@ 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; @@ -32,12 +26,11 @@ public class HybridPlotManager extends ClassicPlotManager { new FileBytes(Settings.Paths.TEMPLATES + "/tmp-data.yml", Template.getBytes(plotArea))); String dir = "schematics" + File.separator + "GEN_ROAD_SCHEMATIC" + File.separator + plotArea.worldname + File.separator; - String newDir = - "schematics" + File.separator + "GEN_ROAD_SCHEMATIC" + File.separator + "__TEMP_DIR__" - + File.separator; try { File sideroad = MainUtil.getFile(PlotSquared.get().IMP.getDirectory(), dir + "sideroad.schem"); + String newDir = "schematics" + File.separator + "GEN_ROAD_SCHEMATIC" + File.separator + + "__TEMP_DIR__" + File.separator; if (sideroad.exists()) { files.add(new FileBytes(newDir + "sideroad.schem", Files.readAllBytes(sideroad.toPath()))); diff --git a/Core/src/main/java/com/github/intellectualsites/plotsquared/plot/listener/WEManager.java b/Core/src/main/java/com/github/intellectualsites/plotsquared/plot/listener/WEManager.java index 0d80cab31..3692efa51 100644 --- a/Core/src/main/java/com/github/intellectualsites/plotsquared/plot/listener/WEManager.java +++ b/Core/src/main/java/com/github/intellectualsites/plotsquared/plot/listener/WEManager.java @@ -3,7 +3,11 @@ package com.github.intellectualsites.plotsquared.plot.listener; import com.github.intellectualsites.plotsquared.plot.PlotSquared; import com.github.intellectualsites.plotsquared.plot.config.Settings; import com.github.intellectualsites.plotsquared.plot.flag.Flags; -import com.github.intellectualsites.plotsquared.plot.object.*; +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.PlotPlayer; +import com.github.intellectualsites.plotsquared.plot.object.RegionWrapper; import java.util.HashSet; import java.util.UUID; @@ -68,7 +72,6 @@ public class WEManager { } boolean allowMember = player.hasPermission("plots.worldedit.member"); Plot plot = player.getCurrentPlot(); - HashSet allowed = new HashSet<>(); if (plot == null) { plot = player.getMeta("WorldEditRegionPlot"); } 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 e357de0b7..6900500f9 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 @@ -166,16 +166,16 @@ import java.util.Map.Entry; compile(); } final StringBuilder builder = new StringBuilder(); - Iterator> iter = blocks.entrySet().iterator(); - while (iter.hasNext()) { - Entry entry = iter.next(); + Iterator> iterator = blocks.entrySet().iterator(); + while (iterator.hasNext()) { + Entry entry = iterator.next(); PlotBlock block = entry.getKey(); builder.append(block.getRawId()); Double weight = entry.getValue(); if (weight != 1) { builder.append(":").append(weight.intValue()); } - if (iter.hasNext()) { + if (iterator.hasNext()) { builder.append(","); } } 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 e2f83172e..78c7675d2 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 @@ -2220,13 +2220,13 @@ public class Plot { if (!EventUtil.manager.callMerge(this, dir, max)) { return false; } - HashSet visited = new HashSet<>(); - HashSet merged; Set connected = this.getConnectedPlots(); - merged = connected.stream().map(Plot::getId).collect(Collectors.toCollection(HashSet::new)); + HashSet merged = + connected.stream().map(Plot::getId).collect(Collectors.toCollection(HashSet::new)); ArrayDeque frontier = new ArrayDeque<>(connected); Plot current; boolean toReturn = false; + HashSet visited = new HashSet<>(); while ((current = frontier.poll()) != null && max >= 0) { if (visited.contains(current)) { continue; @@ -2421,10 +2421,10 @@ public class Plot { regions_cache = null; HashSet tmpSet = new HashSet<>(); - ArrayDeque frontier = new ArrayDeque<>(); - HashSet queuecache = new HashSet<>(); tmpSet.add(this); Plot tmp; + HashSet queuecache = new HashSet<>(); + ArrayDeque frontier = new ArrayDeque<>(); if (merged[0]) { tmp = this.area.getPlotAbs(this.id.getRelative(Direction.NORTH)); if (!tmp.getMerged(Direction.SOUTH)) { @@ -2923,51 +2923,51 @@ public class Plot { plot.swapData(other, null); } // copy terrain - Runnable move = new Runnable() { - @Override public void run() { - if (regions.isEmpty()) { - Plot plot = destination.getRelative(0, 0); - for (Plot current : plot.getConnectedPlots()) { - getManager().claimPlot(current.getArea(), current); - Plot originPlot = originArea.getPlotAbs( - new PlotId(current.id.x - offset.x, current.id.y - offset.y)); - originPlot.getManager().unClaimPlot(originArea, originPlot, null); - } - plot.setSign(); - TaskManager.runTask(whenDone); - return; - } - final Runnable task = this; - RegionWrapper region = regions.poll(); - Location[] corners = region.getCorners(getWorldName()); - final Location pos1 = corners[0]; - final Location pos2 = corners[1]; - Location newPos = pos1.clone().add(offsetX, 0, offsetZ); - newPos.setWorld(destination.getWorldName()); - ChunkManager.manager.copyRegion(pos1, pos2, newPos, - () -> ChunkManager.manager.regenerateRegion(pos1, pos2, false, task)); - } - }; - Runnable swap = new Runnable() { - @Override public void run() { - if (regions.isEmpty()) { - TaskManager.runTask(whenDone); - return; - } - RegionWrapper region = regions.poll(); - Location[] corners = region.getCorners(getWorldName()); - Location pos1 = corners[0]; - Location pos2 = corners[1]; - Location pos3 = pos1.clone().add(offsetX, 0, offsetZ); - Location pos4 = pos2.clone().add(offsetX, 0, offsetZ); - pos3.setWorld(destination.getWorldName()); - pos4.setWorld(destination.getWorldName()); - ChunkManager.manager.swap(pos1, pos2, pos3, pos4, this); - } - }; if (occupied) { + Runnable swap = new Runnable() { + @Override public void run() { + if (regions.isEmpty()) { + TaskManager.runTask(whenDone); + return; + } + RegionWrapper region = regions.poll(); + Location[] corners = region.getCorners(getWorldName()); + Location pos1 = corners[0]; + Location pos2 = corners[1]; + Location pos3 = pos1.clone().add(offsetX, 0, offsetZ); + Location pos4 = pos2.clone().add(offsetX, 0, offsetZ); + pos3.setWorld(destination.getWorldName()); + pos4.setWorld(destination.getWorldName()); + ChunkManager.manager.swap(pos1, pos2, pos3, pos4, this); + } + }; swap.run(); } else { + Runnable move = new Runnable() { + @Override public void run() { + if (regions.isEmpty()) { + Plot plot = destination.getRelative(0, 0); + for (Plot current : plot.getConnectedPlots()) { + getManager().claimPlot(current.getArea(), current); + Plot originPlot = originArea.getPlotAbs( + new PlotId(current.id.x - offset.x, current.id.y - offset.y)); + originPlot.getManager().unClaimPlot(originArea, originPlot, null); + } + plot.setSign(); + TaskManager.runTask(whenDone); + return; + } + final Runnable task = this; + RegionWrapper region = regions.poll(); + Location[] corners = region.getCorners(getWorldName()); + final Location pos1 = corners[0]; + final Location pos2 = corners[1]; + Location newPos = pos1.clone().add(offsetX, 0, offsetZ); + newPos.setWorld(destination.getWorldName()); + ChunkManager.manager.copyRegion(pos1, pos2, newPos, + () -> ChunkManager.manager.regenerateRegion(pos1, pos2, false, task)); + } + }; move.run(); } return true; diff --git a/Core/src/main/java/com/github/intellectualsites/plotsquared/plot/object/PlotArea.java b/Core/src/main/java/com/github/intellectualsites/plotsquared/plot/object/PlotArea.java index 9cdd5a4bd..253d74b40 100644 --- a/Core/src/main/java/com/github/intellectualsites/plotsquared/plot/object/PlotArea.java +++ b/Core/src/main/java/com/github/intellectualsites/plotsquared/plot/object/PlotArea.java @@ -10,7 +10,12 @@ import com.github.intellectualsites.plotsquared.plot.flag.FlagManager; import com.github.intellectualsites.plotsquared.plot.flag.Flags; import com.github.intellectualsites.plotsquared.plot.generator.GridPlotWorld; import com.github.intellectualsites.plotsquared.plot.generator.IndependentPlotGenerator; -import com.github.intellectualsites.plotsquared.plot.util.*; +import com.github.intellectualsites.plotsquared.plot.util.EconHandler; +import com.github.intellectualsites.plotsquared.plot.util.EventUtil; +import com.github.intellectualsites.plotsquared.plot.util.MainUtil; +import com.github.intellectualsites.plotsquared.plot.util.MathMan; +import com.github.intellectualsites.plotsquared.plot.util.PlotGameMode; +import com.github.intellectualsites.plotsquared.plot.util.StringMan; import com.github.intellectualsites.plotsquared.plot.util.area.QuadMap; import com.github.intellectualsites.plotsquared.plot.util.block.GlobalBlockQueue; import com.github.intellectualsites.plotsquared.plot.util.block.LocalBlockQueue; @@ -844,11 +849,10 @@ public abstract class PlotArea { return false; } + manager.startPlotMerge(this, plotIds); final Set trusted = new HashSet<>(); final Set members = new HashSet<>(); final Set denied = new HashSet<>(); - - manager.startPlotMerge(this, plotIds); for (int x = pos1.x; x <= pos2.x; x++) { for (int y = pos1.y; y <= pos2.y; y++) { PlotId id = new PlotId(x, y); diff --git a/Core/src/main/java/com/github/intellectualsites/plotsquared/plot/object/worlds/SinglePlotArea.java b/Core/src/main/java/com/github/intellectualsites/plotsquared/plot/object/worlds/SinglePlotArea.java index a51ef110b..e1f6505f6 100644 --- a/Core/src/main/java/com/github/intellectualsites/plotsquared/plot/object/worlds/SinglePlotArea.java +++ b/Core/src/main/java/com/github/intellectualsites/plotsquared/plot/object/worlds/SinglePlotArea.java @@ -50,21 +50,21 @@ public class SinglePlotArea extends GridPlotWorld { // Duplicate 0;0 if (setup.type != 0) { File container = PlotSquared.imp().getWorldContainer(); - File dest = new File(container, worldName); - if (!dest.exists()) { + File destination = new File(container, worldName); + if (!destination.exists()) { File src = new File(container, "0,0"); if (src.exists()) { - if (!dest.exists()) { - dest.mkdirs(); + if (!destination.exists()) { + destination.mkdirs(); } File levelDat = new File(src, "level.dat"); if (levelDat.exists()) { try { Files.copy(levelDat.toPath(), - new File(dest, levelDat.getName()).toPath()); + new File(destination, levelDat.getName()).toPath()); File data = new File(src, "data"); if (data.exists()) { - File dataDest = new File(dest, "data"); + File dataDest = new File(destination, "data"); dataDest.mkdirs(); for (File file : data.listFiles()) { Files.copy(file.toPath(), diff --git a/Core/src/main/java/com/github/intellectualsites/plotsquared/plot/object/worlds/SinglePlotAreaManager.java b/Core/src/main/java/com/github/intellectualsites/plotsquared/plot/object/worlds/SinglePlotAreaManager.java index 95b303eea..f2e0b3c03 100644 --- a/Core/src/main/java/com/github/intellectualsites/plotsquared/plot/object/worlds/SinglePlotAreaManager.java +++ b/Core/src/main/java/com/github/intellectualsites/plotsquared/plot/object/worlds/SinglePlotAreaManager.java @@ -35,8 +35,7 @@ public class SinglePlotAreaManager extends DefaultPlotAreaManager { return true; } int mode = 0; - for (int i = 0; i < chars.length; i++) { - char c = chars[i]; + for (char c : chars) { switch (mode) { case 0: mode = 1; diff --git a/Core/src/main/java/com/github/intellectualsites/plotsquared/plot/util/HastebinUtility.java b/Core/src/main/java/com/github/intellectualsites/plotsquared/plot/util/HastebinUtility.java index d2495b646..3b0563a3d 100644 --- a/Core/src/main/java/com/github/intellectualsites/plotsquared/plot/util/HastebinUtility.java +++ b/Core/src/main/java/com/github/intellectualsites/plotsquared/plot/util/HastebinUtility.java @@ -1,6 +1,11 @@ package com.github.intellectualsites.plotsquared.plot.util; -import java.io.*; +import java.io.BufferedReader; +import java.io.DataOutputStream; +import java.io.File; +import java.io.FileReader; +import java.io.IOException; +import java.io.InputStreamReader; import java.net.HttpURLConnection; import java.net.URL; import java.util.ArrayList; @@ -47,7 +52,6 @@ public class HastebinUtility { } public static String upload(final File file) throws IOException { - final StringBuilder content = new StringBuilder(); List lines = new ArrayList<>(); try (BufferedReader reader = new BufferedReader(new FileReader(file))) { String line; @@ -56,6 +60,7 @@ public class HastebinUtility { lines.add(line); } } + final StringBuilder content = new StringBuilder(); for (int i = Math.max(0, lines.size() - 1000); i < lines.size(); i++) { content.append(lines.get(i)).append("\n"); } diff --git a/Core/src/main/java/com/github/intellectualsites/plotsquared/plot/util/MainUtil.java b/Core/src/main/java/com/github/intellectualsites/plotsquared/plot/util/MainUtil.java index cfc910748..2e1784b59 100644 --- a/Core/src/main/java/com/github/intellectualsites/plotsquared/plot/util/MainUtil.java +++ b/Core/src/main/java/com/github/intellectualsites/plotsquared/plot/util/MainUtil.java @@ -399,8 +399,6 @@ public class MainUtil { List uuids = new ArrayList<>(); PlotId id = null; - PlotArea area = null; - String alias = null; for (String term : split) { try { @@ -418,6 +416,8 @@ public class MainUtil { IntStream.range(0, size).mapToObj(i -> new ArrayList()) .collect(Collectors.toCollection(() -> new ArrayList<>(size))); + PlotArea area = null; + String alias = null; for (Plot plot : PlotSquared.get().getPlots()) { int count = 0; if (!uuids.isEmpty()) { diff --git a/Core/src/main/java/com/github/intellectualsites/plotsquared/plot/util/ReflectionUtils.java b/Core/src/main/java/com/github/intellectualsites/plotsquared/plot/util/ReflectionUtils.java index cf6bbee2d..621766c17 100644 --- a/Core/src/main/java/com/github/intellectualsites/plotsquared/plot/util/ReflectionUtils.java +++ b/Core/src/main/java/com/github/intellectualsites/plotsquared/plot/util/ReflectionUtils.java @@ -1,7 +1,15 @@ package com.github.intellectualsites.plotsquared.plot.util; -import java.lang.reflect.*; -import java.util.*; +import java.lang.reflect.Constructor; +import java.lang.reflect.Field; +import java.lang.reflect.InvocationTargetException; +import java.lang.reflect.Method; +import java.lang.reflect.Modifier; +import java.util.ArrayList; +import java.util.Arrays; +import java.util.Collections; +import java.util.List; +import java.util.Map; /** * @author DPOH-VAR @@ -137,21 +145,22 @@ public class ReflectionUtils { } @SuppressWarnings("unchecked") - public static Constructor makeConstructor(Class clazz, Class... paramaterTypes) { + public static Constructor makeConstructor(Class clazz, Class... parameterTypes) { try { - return (Constructor) clazz.getConstructor(paramaterTypes); + return (Constructor) clazz.getConstructor(parameterTypes); } catch (NoSuchMethodException ignored) { + //todo print a constructor not found method return null; } } - public static T callConstructor(Constructor constructor, Object... paramaters) { + public static T callConstructor(Constructor constructor, Object... parameters) { if (constructor == null) { throw new RuntimeException("No such constructor"); } constructor.setAccessible(true); try { - return constructor.newInstance(paramaters); + return constructor.newInstance(parameters); } catch (InvocationTargetException ex) { throw new RuntimeException(ex.getCause()); } catch (IllegalAccessException | IllegalArgumentException | InstantiationException ex) { diff --git a/Core/src/main/java/com/github/intellectualsites/plotsquared/plot/util/SchematicHandler.java b/Core/src/main/java/com/github/intellectualsites/plotsquared/plot/util/SchematicHandler.java index cf04f7f94..d6df9d003 100644 --- a/Core/src/main/java/com/github/intellectualsites/plotsquared/plot/util/SchematicHandler.java +++ b/Core/src/main/java/com/github/intellectualsites/plotsquared/plot/util/SchematicHandler.java @@ -7,12 +7,25 @@ import com.github.intellectualsites.plotsquared.plot.config.Settings; import com.github.intellectualsites.plotsquared.plot.flag.Flag; import com.github.intellectualsites.plotsquared.plot.flag.Flags; import com.github.intellectualsites.plotsquared.plot.generator.ClassicPlotWorld; -import com.github.intellectualsites.plotsquared.plot.object.*; +import com.github.intellectualsites.plotsquared.plot.object.ChunkLoc; +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.RegionWrapper; +import com.github.intellectualsites.plotsquared.plot.object.RunnableVal; import com.github.intellectualsites.plotsquared.plot.object.schematic.Schematic; import com.github.intellectualsites.plotsquared.plot.util.block.LocalBlockQueue; -import com.sk89q.jnbt.*; +import com.sk89q.jnbt.CompoundTag; +import com.sk89q.jnbt.NBTInputStream; +import com.sk89q.jnbt.NBTOutputStream; +import com.sk89q.jnbt.StringTag; +import com.sk89q.jnbt.Tag; import com.sk89q.worldedit.extent.clipboard.BlockArrayClipboard; -import com.sk89q.worldedit.extent.clipboard.io.*; +import com.sk89q.worldedit.extent.clipboard.io.ClipboardFormat; +import com.sk89q.worldedit.extent.clipboard.io.ClipboardFormats; +import com.sk89q.worldedit.extent.clipboard.io.ClipboardReader; +import com.sk89q.worldedit.extent.clipboard.io.MCEditSchematicReader; +import com.sk89q.worldedit.extent.clipboard.io.SpongeSchematicReader; import com.sk89q.worldedit.math.BlockVector3; import com.sk89q.worldedit.world.block.BaseBlock; @@ -267,7 +280,7 @@ public abstract class SchematicHandler { * * @return Immutable collection with schematic names */ - public Collection getShematicNames() { + public Collection getSchematicNames() { final File parent = MainUtil.getFile(PlotSquared.get().IMP.getDirectory(), Settings.Paths.SCHEMATICS); final List names = new ArrayList<>(); diff --git a/Core/src/main/java/com/github/intellectualsites/plotsquared/plot/util/UUIDHandler.java b/Core/src/main/java/com/github/intellectualsites/plotsquared/plot/util/UUIDHandler.java index 52e65a3fd..feb58f51f 100644 --- a/Core/src/main/java/com/github/intellectualsites/plotsquared/plot/util/UUIDHandler.java +++ b/Core/src/main/java/com/github/intellectualsites/plotsquared/plot/util/UUIDHandler.java @@ -9,8 +9,9 @@ import com.github.intellectualsites.plotsquared.plot.object.RunnableVal; import com.github.intellectualsites.plotsquared.plot.object.StringWrapper; import com.github.intellectualsites.plotsquared.plot.uuid.UUIDWrapper; import com.google.common.collect.BiMap; +import org.jetbrains.annotations.NotNull; -import javax.annotation.Nonnull; +import javax.annotation.Nullable; import java.util.HashMap; import java.util.HashSet; import java.util.Map; @@ -85,7 +86,7 @@ public class UUIDHandler { implementation.add(toAdd); } - @Nonnull public static UUID getUUID(PlotPlayer player) { + @NotNull public static UUID getUUID(PlotPlayer player) { return implementation.getUUID(player); } @@ -96,7 +97,7 @@ public class UUIDHandler { return implementation.getUUID(player); } - public static String getName(UUID uuid) { + @Nullable public static String getName(UUID uuid) { if (implementation == null) { return null; } @@ -120,13 +121,13 @@ public class UUIDHandler { return check(implementation.getPlayer(name)); } - private static PlotPlayer check(PlotPlayer plr) { - if (plr != null && !plr.isOnline()) { - UUIDHandler.getPlayers().remove(plr.getName()); - PlotSquared.get().IMP.unregister(plr); - plr = null; + private static PlotPlayer check(@Nullable PlotPlayer player) { + if (player != null && !player.isOnline()) { + UUIDHandler.getPlayers().remove(player.getName()); + PlotSquared.get().IMP.unregister(player); + player = null; } - return plr; + return player; } public static UUID getUUIDFromString(String nameOrUUIDString) { diff --git a/Core/src/main/java/com/github/intellectualsites/plotsquared/plot/util/UUIDHandlerImplementation.java b/Core/src/main/java/com/github/intellectualsites/plotsquared/plot/util/UUIDHandlerImplementation.java index baf7523ca..9ccae793b 100644 --- a/Core/src/main/java/com/github/intellectualsites/plotsquared/plot/util/UUIDHandlerImplementation.java +++ b/Core/src/main/java/com/github/intellectualsites/plotsquared/plot/util/UUIDHandlerImplementation.java @@ -4,13 +4,23 @@ import com.github.intellectualsites.plotsquared.plot.PlotSquared; import com.github.intellectualsites.plotsquared.plot.config.Captions; import com.github.intellectualsites.plotsquared.plot.config.Settings; import com.github.intellectualsites.plotsquared.plot.database.DBFunc; -import com.github.intellectualsites.plotsquared.plot.object.*; +import com.github.intellectualsites.plotsquared.plot.object.OfflinePlotPlayer; +import com.github.intellectualsites.plotsquared.plot.object.Plot; +import com.github.intellectualsites.plotsquared.plot.object.PlotPlayer; +import com.github.intellectualsites.plotsquared.plot.object.RunnableVal; +import com.github.intellectualsites.plotsquared.plot.object.StringWrapper; import com.github.intellectualsites.plotsquared.plot.uuid.UUIDWrapper; import com.google.common.base.Charsets; import com.google.common.collect.BiMap; import com.google.common.collect.HashBiMap; +import org.jetbrains.annotations.NotNull; -import java.util.*; +import javax.annotation.Nullable; +import java.util.HashMap; +import java.util.HashSet; +import java.util.Map; +import java.util.Set; +import java.util.UUID; import java.util.concurrent.ConcurrentHashMap; public abstract class UUIDHandlerImplementation { @@ -216,7 +226,7 @@ public abstract class UUIDHandlerImplementation { this.uuidMap.clear(); } - public String getName(UUID uuid) { + @Nullable public String getName(UUID uuid) { if (uuid == null) { return null; } @@ -227,7 +237,7 @@ public abstract class UUIDHandlerImplementation { return null; } - public UUID getUUID(String name, RunnableVal ifFetch) { + @Nullable public UUID getUUID(String name, RunnableVal ifFetch) { if (name.isEmpty()) { return null; } @@ -255,7 +265,7 @@ public abstract class UUIDHandlerImplementation { return null; } - public UUID getUUID(PlotPlayer player) { + @NotNull public UUID getUUID(PlotPlayer player) { return this.uuidWrapper.getUUID(player); } @@ -263,7 +273,7 @@ public abstract class UUIDHandlerImplementation { return this.uuidWrapper.getUUID(player); } - public PlotPlayer getPlayer(UUID uuid) { + @Nullable public PlotPlayer getPlayer(UUID uuid) { String name = getName(uuid); if (name != null) { return getPlayer(name); diff --git a/Core/src/main/java/com/github/intellectualsites/plotsquared/plot/util/WorldUtil.java b/Core/src/main/java/com/github/intellectualsites/plotsquared/plot/util/WorldUtil.java index 2e05542aa..3aaed57fb 100644 --- a/Core/src/main/java/com/github/intellectualsites/plotsquared/plot/util/WorldUtil.java +++ b/Core/src/main/java/com/github/intellectualsites/plotsquared/plot/util/WorldUtil.java @@ -3,9 +3,17 @@ package com.github.intellectualsites.plotsquared.plot.util; import com.github.intellectualsites.plotsquared.plot.PlotSquared; import com.github.intellectualsites.plotsquared.plot.object.*; import com.github.intellectualsites.plotsquared.plot.object.schematic.PlotItem; -import com.sk89q.jnbt.*; +import com.sk89q.jnbt.CompoundTag; +import com.sk89q.jnbt.IntTag; +import com.sk89q.jnbt.NBTInputStream; +import com.sk89q.jnbt.NBTOutputStream; +import com.sk89q.jnbt.Tag; -import java.io.*; +import java.io.ByteArrayOutputStream; +import java.io.File; +import java.io.FileInputStream; +import java.io.IOException; +import java.io.OutputStream; import java.net.URL; import java.util.Map; import java.util.Set; @@ -66,7 +74,6 @@ public abstract class WorldUtil { try (final ZipOutputStream zos = new ZipOutputStream(output)) { File dat = getDat(plot.getWorldName()); Location spawn = getSpawn(plot.getWorldName()); - byte[] buffer = new byte[1024]; if (dat != null) { ZipEntry ze = new ZipEntry("world" + File.separator + dat.getName()); zos.putNextEntry(ze); @@ -89,6 +96,7 @@ public abstract class WorldUtil { } } setSpawn(spawn); + byte[] buffer = new byte[1024]; for (Plot current : plot.getConnectedPlots()) { Location bot = current.getBottomAbs(); Location top = current.getTopAbs(); @@ -107,12 +115,12 @@ public abstract class WorldUtil { "world" + File.separator + "region" + File.separator + name); zos.putNextEntry(ze); - final FileInputStream in = new FileInputStream(file); - int len; - while ((len = in.read(buffer)) > 0) { - zos.write(buffer, 0, len); + try (FileInputStream in = new FileInputStream(file)) { + int len; + while ((len = in.read(buffer)) > 0) { + zos.write(buffer, 0, len); + } } - in.close(); zos.closeEntry(); } } diff --git a/Core/src/main/java/com/github/intellectualsites/plotsquared/plot/util/block/GlobalBlockQueue.java b/Core/src/main/java/com/github/intellectualsites/plotsquared/plot/util/block/GlobalBlockQueue.java index a448eb127..6d75b6bfb 100644 --- a/Core/src/main/java/com/github/intellectualsites/plotsquared/plot/util/block/GlobalBlockQueue.java +++ b/Core/src/main/java/com/github/intellectualsites/plotsquared/plot/util/block/GlobalBlockQueue.java @@ -81,52 +81,50 @@ public class GlobalBlockQueue { return false; } running.set(true); - TaskManager.runTaskRepeat(new Runnable() { - @Override public void run() { - if (inactiveQueues.isEmpty() && activeQueues.isEmpty()) { - lastSuccess = System.currentTimeMillis(); - tasks(); - return; - } - SET_TASK.value1 = 50 + Math.min( - (50 + GlobalBlockQueue.this.last) - (GlobalBlockQueue.this.last = - System.currentTimeMillis()), - GlobalBlockQueue.this.secondLast - System.currentTimeMillis()); - SET_TASK.value2 = getNextQueue(); - if (SET_TASK.value2 == null) { - return; - } - if (!PlotSquared.get().isMainThread(Thread.currentThread())) { - throw new IllegalStateException( - "This shouldn't be possible for placement to occur off the main thread"); - } - // Disable the async catcher as it can't discern async vs parallel - SET_TASK.value2.startSet(true); - try { - if (PARALLEL_THREADS <= 1) { - SET_TASK.run(); - } else { - ArrayList threads = new ArrayList<>(); - for (int i = 0; i < PARALLEL_THREADS; i++) { - threads.add(new Thread(SET_TASK)); - } - for (Thread thread : threads) { - thread.start(); - } - for (Thread thread : threads) { - try { - thread.join(); - } catch (InterruptedException e) { - e.printStackTrace(); - } + TaskManager.runTaskRepeat(() -> { + if (inactiveQueues.isEmpty() && activeQueues.isEmpty()) { + lastSuccess = System.currentTimeMillis(); + tasks(); + return; + } + SET_TASK.value1 = 50 + Math.min( + (50 + GlobalBlockQueue.this.last) - (GlobalBlockQueue.this.last = + System.currentTimeMillis()), + GlobalBlockQueue.this.secondLast - System.currentTimeMillis()); + SET_TASK.value2 = getNextQueue(); + if (SET_TASK.value2 == null) { + return; + } + if (!PlotSquared.get().isMainThread(Thread.currentThread())) { + throw new IllegalStateException( + "This shouldn't be possible for placement to occur off the main thread"); + } + // Disable the async catcher as it can't discern async vs parallel + SET_TASK.value2.startSet(true); + try { + if (PARALLEL_THREADS <= 1) { + SET_TASK.run(); + } else { + ArrayList threads = new ArrayList<>(); + for (int i = 0; i < PARALLEL_THREADS; i++) { + threads.add(new Thread(SET_TASK)); + } + for (Thread thread : threads) { + thread.start(); + } + for (Thread thread : threads) { + try { + thread.join(); + } catch (InterruptedException e) { + e.printStackTrace(); } } - } catch (Throwable e) { - e.printStackTrace(); - } finally { - // Enable it again (note that we are still on the main thread) - SET_TASK.value2.endSet(true); } + } catch (Throwable e) { + e.printStackTrace(); + } finally { + // Enable it again (note that we are still on the main thread) + SET_TASK.value2.endSet(true); } }, 1); return true; diff --git a/Core/src/main/java/com/github/intellectualsites/plotsquared/plot/util/expiry/ExpireManager.java b/Core/src/main/java/com/github/intellectualsites/plotsquared/plot/util/expiry/ExpireManager.java index cf4e025eb..2fbcdee01 100644 --- a/Core/src/main/java/com/github/intellectualsites/plotsquared/plot/util/expiry/ExpireManager.java +++ b/Core/src/main/java/com/github/intellectualsites/plotsquared/plot/util/expiry/ExpireManager.java @@ -169,13 +169,12 @@ public class ExpireManager { return new ArrayList<>(); } - boolean shouldCheckAccountAge = false; - long diff = getAge(plot); if (diff == 0) { return new ArrayList<>(); } // Filter out non old plots + boolean shouldCheckAccountAge = false; for (int i = 0; i < applicable.size(); i++) { ExpiryTask et = applicable.poll(); if (et.applies(diff)) { diff --git a/Core/src/main/java/com/github/intellectualsites/plotsquared/plot/uuid/UUIDWrapper.java b/Core/src/main/java/com/github/intellectualsites/plotsquared/plot/uuid/UUIDWrapper.java index 235b51a34..c2a0af542 100644 --- a/Core/src/main/java/com/github/intellectualsites/plotsquared/plot/uuid/UUIDWrapper.java +++ b/Core/src/main/java/com/github/intellectualsites/plotsquared/plot/uuid/UUIDWrapper.java @@ -2,12 +2,13 @@ package com.github.intellectualsites.plotsquared.plot.uuid; import com.github.intellectualsites.plotsquared.plot.object.OfflinePlotPlayer; import com.github.intellectualsites.plotsquared.plot.object.PlotPlayer; +import org.jetbrains.annotations.NotNull; import java.util.UUID; public abstract class UUIDWrapper { - public abstract UUID getUUID(PlotPlayer player); + @NotNull public abstract UUID getUUID(PlotPlayer player); public abstract UUID getUUID(OfflinePlotPlayer player);