From 8f3d35bca38d3ebc4b7fd7c0cad79e7f2b4b7aa1 Mon Sep 17 00:00:00 2001 From: MattBDev Date: Thu, 28 Apr 2016 16:38:51 -0400 Subject: [PATCH 01/10] Bug Fix and Cleanup --- .../com/plotsquared/bukkit/BukkitMain.java | 9 +- .../bukkit/chat/TextualComponent.java | 4 +- .../database/plotme/LikePlotMeConverter.java | 6 +- .../bukkit/listeners/PlayerEvents.java | 191 ++--- .../bukkit/listeners/PlayerEvents_1_9.java | 3 - .../listeners/worldedit/WEListener.java | 9 +- .../bukkit/titles/DefaultTitleManager.java | 4 +- .../bukkit/titles/HackTitleManager.java | 2 +- .../bukkit/util/BukkitChunkManager.java | 205 ++--- .../plotsquared/bukkit/util/BukkitUtil.java | 10 +- .../com/plotsquared/bukkit/util/Metrics.java | 5 - .../bukkit/util/block/FastQueue_1_9.java | 4 +- .../bukkit/uuid/FileUUIDHandler.java | 6 +- .../configuration/file/YamlConfiguration.java | 5 +- .../ConfigurationSerialization.java | 9 +- .../jnbt/ByteArrayTag.java | 2 +- .../intellectualcrafters/jnbt/ByteTag.java | 2 +- .../jnbt/CompoundTag.java | 2 +- .../jnbt/CompoundTagBuilder.java | 2 +- .../intellectualcrafters/jnbt/DoubleTag.java | 2 +- .../intellectualcrafters/jnbt/FloatTag.java | 2 +- .../jnbt/IntArrayTag.java | 2 +- .../com/intellectualcrafters/jnbt/IntTag.java | 2 +- .../intellectualcrafters/jnbt/ListTag.java | 2 +- .../jnbt/ListTagBuilder.java | 2 +- .../intellectualcrafters/jnbt/LongTag.java | 2 +- .../intellectualcrafters/jnbt/ShortTag.java | 2 +- .../intellectualcrafters/jnbt/StringTag.java | 2 +- .../intellectualcrafters/json/JSONObject.java | 2 +- .../intellectualcrafters/json/JSONString.java | 2 +- .../json/JSONTokener.java | 4 +- .../com/intellectualcrafters/plot/PS.java | 13 +- .../plot/commands/Area.java | 24 +- .../plot/commands/Auto.java | 2 +- .../plot/commands/DebugClaimTest.java | 2 +- .../plot/commands/FlagCmd.java | 5 - .../plot/commands/GenerateDocs.java | 19 +- .../plot/commands/ListCmd.java | 6 +- .../plot/commands/Merge.java | 13 +- .../plot/commands/RegenAllRoads.java | 2 +- .../plot/commands/Setup.java | 24 +- .../plot/commands/Update.java | 2 +- .../intellectualcrafters/plot/config/C.java | 9 +- .../plot/config/Configuration.java | 16 +- .../plot/database/SQLManager.java | 805 +++++++++--------- .../plot/database/SQLite.java | 2 +- .../plot/database/StmtMod.java | 6 +- .../intellectualcrafters/plot/flag/Flag.java | 2 +- .../plot/generator/AugmentedUtils.java | 3 +- .../plot/object/Plot.java | 36 +- .../plot/object/PlotAnalysis.java | 2 +- .../plot/object/PlotHandler.java | 4 +- .../plot/object/PlotPlayer.java | 13 - .../plot/util/BO3Handler.java | 2 +- .../plot/util/MainUtil.java | 18 +- .../plot/util/MathMan.java | 2 +- .../plot/util/ReflectionUtils.java | 32 +- .../plot/util/SchematicHandler.java | 2 + .../plotsquared/general/commands/Command.java | 2 +- .../general/commands/CommandCaller.java | 6 + .../plotsquared/listener/WESubscriber.java | 3 +- .../intellectualcrafters/plot/FlagTest.java | 4 +- .../plot/database/AbstractDBTEst.java | 54 +- .../plot/util/EventUtilTest.java | 6 - .../sponge/listener/MainListener.java | 8 +- .../sponge/util/SpongeTitleManager.java | 1 - .../sponge/util/block/SlowQueue.java | 1 - .../sponge/uuid/SpongeOnlineUUIDWrapper.java | 3 +- 68 files changed, 780 insertions(+), 880 deletions(-) diff --git a/Bukkit/src/main/java/com/plotsquared/bukkit/BukkitMain.java b/Bukkit/src/main/java/com/plotsquared/bukkit/BukkitMain.java index 9f7f03251..03b667983 100644 --- a/Bukkit/src/main/java/com/plotsquared/bukkit/BukkitMain.java +++ b/Bukkit/src/main/java/com/plotsquared/bukkit/BukkitMain.java @@ -620,11 +620,14 @@ public final class BukkitMain extends JavaPlugin implements Listener, IPlotMain public PlotPlayer wrapPlayer(Object player) { if (player instanceof Player) { return BukkitUtil.getPlayer((Player) player); - } else if (player instanceof OfflinePlayer) { + } + if (player instanceof OfflinePlayer) { return BukkitUtil.getPlayer((OfflinePlayer) player); - } else if (player instanceof String) { + } + if (player instanceof String) { return UUIDHandler.getPlayer((String) player); - } else if (player instanceof UUID) { + } + if (player instanceof UUID) { return UUIDHandler.getPlayer((UUID) player); } return null; diff --git a/Bukkit/src/main/java/com/plotsquared/bukkit/chat/TextualComponent.java b/Bukkit/src/main/java/com/plotsquared/bukkit/chat/TextualComponent.java index ad90d4b7b..08a62255e 100644 --- a/Bukkit/src/main/java/com/plotsquared/bukkit/chat/TextualComponent.java +++ b/Bukkit/src/main/java/com/plotsquared/bukkit/chat/TextualComponent.java @@ -192,7 +192,7 @@ public abstract class TextualComponent implements Cloneable { } @Override - public TextualComponent clone() throws CloneNotSupportedException { + public TextualComponent clone() { // Since this is a private and final class, we can just reinstantiate this class instead of casting super.clone return new ArbitraryTextTypeComponent(getKey(), getValue()); } @@ -266,7 +266,7 @@ public abstract class TextualComponent implements Cloneable { } @Override - public TextualComponent clone() throws CloneNotSupportedException { + public TextualComponent clone() { // Since this is a private and final class, we can just reinstantiate this class instead of casting super.clone return new ComplexTextTypeComponent(getKey(), getValue()); } diff --git a/Bukkit/src/main/java/com/plotsquared/bukkit/database/plotme/LikePlotMeConverter.java b/Bukkit/src/main/java/com/plotsquared/bukkit/database/plotme/LikePlotMeConverter.java index 1973e8b7f..205cd6eec 100644 --- a/Bukkit/src/main/java/com/plotsquared/bukkit/database/plotme/LikePlotMeConverter.java +++ b/Bukkit/src/main/java/com/plotsquared/bukkit/database/plotme/LikePlotMeConverter.java @@ -264,7 +264,7 @@ public class LikePlotMeConverter { sendMessage("Saving configuration..."); try { PS.get().config.save(PS.get().configFile); - } catch (IOException e) { + } catch (IOException ignored) { sendMessage(" - &cFailed to save configuration."); } TaskManager.runTask(new Runnable() { @@ -293,7 +293,7 @@ public class LikePlotMeConverter { Bukkit.getServer().dispatchCommand(Bukkit.getServer().getConsoleSender(), "mv unload " + actualWorldName); try { Thread.sleep(1000); - } catch (InterruptedException ex) { + } catch (InterruptedException ignored) { Thread.currentThread().interrupt(); } // load world with MV @@ -304,7 +304,7 @@ public class LikePlotMeConverter { Bukkit.getServer().dispatchCommand(Bukkit.getServer().getConsoleSender(), "mw unload " + actualWorldName); try { Thread.sleep(1000); - } catch (InterruptedException ex) { + } catch (InterruptedException ignored) { Thread.currentThread().interrupt(); } // load world with MW diff --git a/Bukkit/src/main/java/com/plotsquared/bukkit/listeners/PlayerEvents.java b/Bukkit/src/main/java/com/plotsquared/bukkit/listeners/PlayerEvents.java index ac1154369..8fc9572f5 100644 --- a/Bukkit/src/main/java/com/plotsquared/bukkit/listeners/PlayerEvents.java +++ b/Bukkit/src/main/java/com/plotsquared/bukkit/listeners/PlayerEvents.java @@ -196,8 +196,9 @@ public class PlayerEvents extends PlotListener implements Listener { if (plot == null) { return; } - if (plot.getFlag(Flags.REDSTONE).isPresent()) { - if (plot.getFlag(Flags.REDSTONE).get()) { + Optional flag = plot.getFlag(Flags.REDSTONE); + if (flag.isPresent()) { + if (flag.get()) { return; } else { event.setNewCurrent(0); @@ -245,7 +246,8 @@ public class PlayerEvents extends PlotListener implements Listener { if (plot == null) { return; } - if (plot.getFlag(Flags.REDSTONE).isPresent() && !plot.getFlag(Flags.REDSTONE).get()) { + Optional flag = plot.getFlag(Flags.REDSTONE); + if (flag.isPresent() && !flag.get()) { event.setCancelled(true); } return; @@ -322,7 +324,8 @@ public class PlayerEvents extends PlotListener implements Listener { } entity.remove(); return false; - } else if (!(shooter instanceof Entity) && shooter != null) { + } + if (!(shooter instanceof Entity) && shooter != null) { if (plot == null) { entity.remove(); return false; @@ -374,7 +377,7 @@ public class PlayerEvents extends PlotListener implements Listener { String c = parts[0]; if (parts[0].contains(":")) { c = parts[0].split(":")[1]; - msg = msg.replace(parts[0].split(":")[0] + ":", ""); + msg = msg.replace(parts[0].split(":")[0] + ':', ""); } String l = c; List aliases = new ArrayList<>(); @@ -513,7 +516,8 @@ public class PlayerEvents extends PlotListener implements Listener { player.teleport(event.getTo()); MainUtil.sendMessage(pp, C.BORDER); return; - } else if (x2 < -border) { + } + if (x2 < -border) { to.setX(-border + 4); player.teleport(event.getTo()); MainUtil.sendMessage(pp, C.BORDER); @@ -633,7 +637,8 @@ public class PlayerEvents extends PlotListener implements Listener { MainUtil.sendMessage(pp, C.NO_PERMISSION_EVENT, C.PERMISSION_ADMIN_DESTROY_UNOWNED); event.setCancelled(true); return; - } else if (!plot.isAdded(pp.getUUID())) { + } + if (!plot.isAdded(pp.getUUID())) { Optional> destroy = plot.getFlag(Flags.BREAK); Block block = event.getBlock(); if (destroy.isPresent() && destroy.get() @@ -686,7 +691,8 @@ public class PlayerEvents extends PlotListener implements Listener { } Plot plot = area.getOwnedPlot(location); if (plot != null) { - if (plot.getFlag(Flags.EXPLOSION).isPresent() && plot.getFlag(Flags.EXPLOSION).get()) { + Optional flag = plot.getFlag(Flags.EXPLOSION); + if (flag.isPresent() && flag.get()) { List meta = event.getEntity().getMetadata("plot"); Plot origin; if (meta.isEmpty()) { @@ -780,19 +786,23 @@ public class PlayerEvents extends PlotListener implements Listener { return; } Plot plot = area.getOwnedPlot(location); + Optional flag; switch (block.getType()) { case GRASS: - if (plot.getFlag(Flags.GRASS_GROW).isPresent() && plot.getFlag(Flags.GRASS_GROW).get()) { + flag = plot.getFlag(Flags.GRASS_GROW); + if (flag.isPresent() && flag.get()) { event.setCancelled(true); } break; case MYCEL: - if (plot.getFlag(Flags.MYCEL_GROW).isPresent() && plot.getFlag(Flags.MYCEL_GROW).get()) { + flag = plot.getFlag(Flags.MYCEL_GROW); + if (flag.isPresent() && flag.get()) { event.setCancelled(true); } break; case VINE: - if (plot.getFlag(Flags.VINE_GROW).isPresent() && plot.getFlag(Flags.VINE_GROW).get()) { + flag = plot.getFlag(Flags.VINE_GROW); + if (flag.isPresent() && flag.get()) { event.setCancelled(true); } break; @@ -831,10 +841,8 @@ public class PlayerEvents extends PlotListener implements Listener { if (!plot.isAdded(pp.getUUID())) { Optional> destroy = plot.getFlag(Flags.BREAK); Block block = event.getBlock(); - if (destroy.isPresent() && destroy.get().contains(new PlotBlock((short) block.getTypeId(), block.getData()))) { - return; - } - if (Permissions.hasPermission(pp, C.PERMISSION_ADMIN_DESTROY_OTHER)) { + if (destroy.isPresent() && destroy.get().contains(new PlotBlock((short) block.getTypeId(), block.getData())) || Permissions + .hasPermission(pp, C.PERMISSION_ADMIN_DESTROY_OTHER)) { return; } event.setCancelled(true); @@ -850,8 +858,8 @@ public class PlayerEvents extends PlotListener implements Listener { } @EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true) - public void onFade(BlockFadeEvent e) { - Block b = e.getBlock(); + public void onFade(BlockFadeEvent event) { + Block b = event.getBlock(); Location location = BukkitUtil.getLocation(b.getLocation()); PlotArea area = location.getPlotArea(); if (area == null) { @@ -859,7 +867,7 @@ public class PlayerEvents extends PlotListener implements Listener { } Plot plot = area.getOwnedPlot(location); if (plot == null) { - e.setCancelled(true); + event.setCancelled(true); return; } switch (b.getType()) { @@ -867,7 +875,7 @@ public class PlayerEvents extends PlotListener implements Listener { Optional ice_melt = plot.getFlag(Flags.ICE_MELT); if (ice_melt.isPresent()) { if (!ice_melt.get()) { - e.setCancelled(true); + event.setCancelled(true); } } break; @@ -875,7 +883,7 @@ public class PlayerEvents extends PlotListener implements Listener { Optional snow_melt = plot.getFlag(Flags.SNOW_MELT); if (snow_melt.isPresent()) { if (!snow_melt.get()) { - e.setCancelled(true); + event.setCancelled(true); } } break; @@ -883,7 +891,7 @@ public class PlayerEvents extends PlotListener implements Listener { Optional soil_dry = plot.getFlag(Flags.SOIL_DRY); if (soil_dry.isPresent()) { if (!soil_dry.get()) { - e.setCancelled(true); + event.setCancelled(true); } } break; @@ -902,9 +910,8 @@ public class PlayerEvents extends PlotListener implements Listener { Plot plot = area.getOwnedPlot(tLocation); Location fLocation = BukkitUtil.getLocation(from.getLocation()); if (plot != null) { - if (plot.getFlag(Flags.DISABLE_PHYSICS).or(false)) { - event.setCancelled(true); - } else if (!area.contains(fLocation.getX(), fLocation.getZ()) || !Objects.equals(plot, area.getOwnedPlot(fLocation))) { + if (plot.getFlag(Flags.DISABLE_PHYSICS).or(false) || !area.contains(fLocation.getX(), fLocation.getZ()) || !Objects + .equals(plot, area.getOwnedPlot(fLocation))) { event.setCancelled(true); } } else if (!area.contains(fLocation.getX(), fLocation.getZ()) || !Objects.equals(plot, area.getOwnedPlot(fLocation))) { @@ -977,7 +984,7 @@ public class PlayerEvents extends PlotListener implements Listener { return; } } - } catch (Throwable e) { + } catch (Throwable ignored) { this.pistonBlocks = false; } } @@ -1006,7 +1013,7 @@ public class PlayerEvents extends PlotListener implements Listener { return; } } - } catch (Throwable e) { + } catch (Throwable ignored) { this.pistonBlocks = false; } } @@ -1183,7 +1190,8 @@ public class PlayerEvents extends PlotListener implements Listener { eventType = PlayerBlockEventType.INTERACT_BLOCK; lb = new BukkitLazyBlock(0, block); break; - } else if (id < 198) { + } + if (id < 198) { location = BukkitUtil.getLocation(block.getRelative(event.getBlockFace()).getLocation()); eventType = PlayerBlockEventType.PLACE_BLOCK; lb = new BukkitLazyBlock(id, block); @@ -1341,11 +1349,7 @@ public class PlayerEvents extends PlotListener implements Listener { return; } Plot plot = area.getOwnedPlotAbs(location); - if (plot == null) { - event.setCancelled(true); - return; - } - if (plot.getFlag(Flags.DISABLE_PHYSICS).or(false)) { + if (plot == null || plot.getFlag(Flags.DISABLE_PHYSICS).or(false)) { event.setCancelled(true); return; } @@ -1411,7 +1415,7 @@ public class PlayerEvents extends PlotListener implements Listener { } public boolean checkEntity(Entity entity, Plot plot) { - if (plot == null || plot.owner == null || plot.getFlags().isEmpty() && plot.getArea().DEFAULT_FLAGS.isEmpty()) { + if (plot == null || !plot.hasOwner() || plot.getFlags().isEmpty() && plot.getArea().DEFAULT_FLAGS.isEmpty()) { return false; } switch (entity.getType()) { @@ -1509,9 +1513,11 @@ public class PlayerEvents extends PlotListener implements Listener { } else { return checkEntity(plot, Flags.ENTITY_CAP, Flags.MOB_CAP); } - } else if (entity instanceof Vehicle) { + } + if (entity instanceof Vehicle) { return checkEntity(plot, Flags.ENTITY_CAP, Flags.VEHICLE_CAP); - } else if (entity instanceof Hanging) { + } + if (entity instanceof Hanging) { return checkEntity(plot, Flags.ENTITY_CAP, Flags.MISC_CAP); } return checkEntity(plot, Flags.ENTITY_CAP); @@ -1519,8 +1525,8 @@ public class PlayerEvents extends PlotListener implements Listener { } @EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true) - public void onBlockBurn(BlockBurnEvent e) { - Block b = e.getBlock(); + public void onBlockBurn(BlockBurnEvent event) { + Block b = event.getBlock(); Location location = BukkitUtil.getLocation(b.getLocation()); PlotArea area = location.getPlotArea(); @@ -1530,8 +1536,7 @@ public class PlayerEvents extends PlotListener implements Listener { Plot plot = location.getOwnedPlot(); if (plot == null || !plot.getFlag(Flags.BLOCK_BURN).or(false)) { - e.setCancelled(true); - return; + event.setCancelled(true); } } @@ -1582,56 +1587,41 @@ public class PlayerEvents extends PlotListener implements Listener { } else if (!plot.getFlag(Flags.BLOCK_IGNITION).or(false)) { event.setCancelled(true); } - } else if (ignitingEntity != null) { - if (plot == null || !plot.getFlag(Flags.BLOCK_IGNITION).or(false)) { + } else { + if (plot == null) { event.setCancelled(true); return; } - if (igniteCause == BlockIgniteEvent.IgniteCause.FIREBALL) { - if (ignitingEntity instanceof Fireball) { - Projectile fireball = (Projectile) ignitingEntity; - Location location = null; - if (fireball.getShooter() instanceof Entity) { - Entity shooter = (Entity) fireball.getShooter(); - location = BukkitUtil.getLocation(shooter.getLocation()); - } else if (fireball.getShooter() instanceof BlockProjectileSource) { - Block shooter = ((BlockProjectileSource) fireball.getShooter()).getBlock(); - location = BukkitUtil.getLocation(shooter.getLocation()); - } - if (location != null && (location.getPlot() == null || !location.getPlot().equals(plot))) { - event.setCancelled(true); + if (ignitingEntity != null) { + if (!plot.getFlag(Flags.BLOCK_IGNITION).or(false)) { + event.setCancelled(true); + return; + } + if (igniteCause == BlockIgniteEvent.IgniteCause.FIREBALL) { + if (ignitingEntity instanceof Fireball) { + Projectile fireball = (Projectile) ignitingEntity; + Location location = null; + if (fireball.getShooter() instanceof Entity) { + Entity shooter = (Entity) fireball.getShooter(); + location = BukkitUtil.getLocation(shooter.getLocation()); + } else if (fireball.getShooter() instanceof BlockProjectileSource) { + Block shooter = ((BlockProjectileSource) fireball.getShooter()).getBlock(); + location = BukkitUtil.getLocation(shooter.getLocation()); + } + if (location != null && !plot.equals(location.getPlot())) { + event.setCancelled(true); + } } } - } - } else if (event.getIgnitingBlock() != null) { - Block ignitingBlock = event.getIgnitingBlock(); - if (igniteCause == BlockIgniteEvent.IgniteCause.FLINT_AND_STEEL) { - if (plot == null || !plot.getFlag(Flags.BLOCK_IGNITION).or(false)) { + } else if (event.getIgnitingBlock() != null) { + Block ignitingBlock = event.getIgnitingBlock(); + Plot plotIgnited = BukkitUtil.getLocation(ignitingBlock.getLocation()).getPlot(); + if (igniteCause == BlockIgniteEvent.IgniteCause.FLINT_AND_STEEL && (!plot.getFlag(Flags.BLOCK_IGNITION).or(false) + || plotIgnited == null || !plotIgnited.equals(plot)) + || (igniteCause == BlockIgniteEvent.IgniteCause.SPREAD || igniteCause == BlockIgniteEvent.IgniteCause.LAVA) && ( + !plot.getFlag(Flags.BLOCK_IGNITION).or(false) || plotIgnited == null || !plotIgnited.equals(plot))) { event.setCancelled(true); - return; - } - if (BukkitUtil.getLocation(ignitingBlock.getLocation()).getPlot() == null) { - event.setCancelled(true); - return; - } - if (!BukkitUtil.getLocation(ignitingBlock.getLocation()).getPlot().equals(plot)) { - event.setCancelled(true); - return; - } - } - if (igniteCause == BlockIgniteEvent.IgniteCause.SPREAD || igniteCause == BlockIgniteEvent.IgniteCause.LAVA) { - if (plot == null || !plot.getFlag(Flags.BLOCK_IGNITION).or(false)) { - event.setCancelled(true); - return; - } - if (BukkitUtil.getLocation(ignitingBlock.getLocation()).getPlot() == null) { - event.setCancelled(true); - return; - } - if (!BukkitUtil.getLocation(ignitingBlock.getLocation()).getPlot().equals(plot)) { - event.setCancelled(true); - return; } } } @@ -1931,7 +1921,8 @@ public class PlayerEvents extends PlotListener implements Listener { event.setCancelled(true); } return; - } else if (!plot.isAdded(pp.getUUID())) { + } + if (!plot.isAdded(pp.getUUID())) { if (!plot.getFlag(Flags.HANGING_PLACE).or(false)) { if (!Permissions.hasPermission(pp, C.PERMISSION_ADMIN_BUILD_OTHER)) { MainUtil.sendMessage(pp, C.NO_PERMISSION_EVENT, C.PERMISSION_ADMIN_BUILD_OTHER); @@ -2055,13 +2046,13 @@ public class PlayerEvents extends PlotListener implements Listener { } @EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true) - public void onVehicleDestroy(VehicleDestroyEvent e) { - Location l = BukkitUtil.getLocation(e.getVehicle()); + public void onVehicleDestroy(VehicleDestroyEvent event) { + Location l = BukkitUtil.getLocation(event.getVehicle()); PlotArea area = l.getPlotArea(); if (area == null) { return; } - Entity d = e.getAttacker(); + Entity d = event.getAttacker(); if (d instanceof Player) { Player p = (Player) d; PlotPlayer pp = BukkitUtil.getPlayer(p); @@ -2069,13 +2060,13 @@ public class PlayerEvents extends PlotListener implements Listener { if (plot == null) { if (!Permissions.hasPermission(pp, "plots.admin.vehicle.break.road")) { MainUtil.sendMessage(pp, C.NO_PERMISSION_EVENT, "plots.admin.vehicle.break.road"); - e.setCancelled(true); + event.setCancelled(true); } } else { if (!plot.hasOwner()) { if (!Permissions.hasPermission(pp, "plots.admin.vehicle.break.unowned")) { MainUtil.sendMessage(pp, C.NO_PERMISSION_EVENT, "plots.admin.vehicle.break.unowned"); - e.setCancelled(true); + event.setCancelled(true); return; } return; @@ -2086,7 +2077,7 @@ public class PlayerEvents extends PlotListener implements Listener { } if (!Permissions.hasPermission(pp, "plots.admin.vehicle.break.other")) { MainUtil.sendMessage(pp, C.NO_PERMISSION_EVENT, "plots.admin.vehicle.break.other"); - e.setCancelled(true); + event.setCancelled(true); } } } @@ -2113,15 +2104,15 @@ public class PlayerEvents extends PlotListener implements Listener { } @EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true) - public void onEntityDamageByEntityEvent(EntityDamageByEntityEvent e) { - Entity damager = e.getDamager(); + public void onEntityDamageByEntityEvent(EntityDamageByEntityEvent event) { + Entity damager = event.getDamager(); Location l = BukkitUtil.getLocation(damager); if (!PS.get().hasPlotArea(l.getWorld())) { return; } - Entity victim = e.getEntity(); + Entity victim = event.getEntity(); if (!entityDamage(damager, victim)) { - e.setCancelled(true); + event.setCancelled(true); } } @@ -2267,29 +2258,29 @@ public class PlayerEvents extends PlotListener implements Listener { } @EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true) - public void onPlayerEggThrow(PlayerEggThrowEvent e) { - Location l = BukkitUtil.getLocation(e.getEgg().getLocation()); + public void onPlayerEggThrow(PlayerEggThrowEvent event) { + Location l = BukkitUtil.getLocation(event.getEgg().getLocation()); PlotArea area = l.getPlotArea(); if (area == null) { return; } - Player p = e.getPlayer(); + Player p = event.getPlayer(); PlotPlayer pp = BukkitUtil.getPlayer(p); Plot plot = area.getPlot(l); if (plot == null) { if (!Permissions.hasPermission(pp, "plots.admin.projectile.road")) { MainUtil.sendMessage(pp, C.NO_PERMISSION_EVENT, "plots.admin.projectile.road"); - e.setHatching(false); + event.setHatching(false); } } else if (!plot.hasOwner()) { if (!Permissions.hasPermission(pp, "plots.admin.projectile.unowned")) { MainUtil.sendMessage(pp, C.NO_PERMISSION_EVENT, "plots.admin.projectile.unowned"); - e.setHatching(false); + event.setHatching(false); } } else if (!plot.isAdded(pp.getUUID())) { if (!Permissions.hasPermission(pp, "plots.admin.projectile.other")) { MainUtil.sendMessage(pp, C.NO_PERMISSION_EVENT, "plots.admin.projectile.other"); - e.setHatching(false); + event.setHatching(false); } } } @@ -2336,7 +2327,7 @@ public class PlayerEvents extends PlotListener implements Listener { if (loc.getY() > area.MAX_BUILD_HEIGHT && loc.getY() < area.MIN_BUILD_HEIGHT && !Permissions .hasPermission(pp, C.PERMISSION_ADMIN_BUILD_HEIGHTLIMIT)) { event.setCancelled(true); - MainUtil.sendMessage(pp, C.HEIGHT_LIMIT.s().replace("{limit}", "" + area.MAX_BUILD_HEIGHT)); + MainUtil.sendMessage(pp, C.HEIGHT_LIMIT.s().replace("{limit}", String.valueOf(area.MAX_BUILD_HEIGHT))); } } else if (!Permissions.hasPermission(pp, C.PERMISSION_ADMIN_BUILD_OTHER)) { MainUtil.sendMessage(pp, C.NO_PERMISSION_EVENT, C.PERMISSION_ADMIN_BUILD_ROAD); diff --git a/Bukkit/src/main/java/com/plotsquared/bukkit/listeners/PlayerEvents_1_9.java b/Bukkit/src/main/java/com/plotsquared/bukkit/listeners/PlayerEvents_1_9.java index 73e2f1965..6a9b3abb0 100644 --- a/Bukkit/src/main/java/com/plotsquared/bukkit/listeners/PlayerEvents_1_9.java +++ b/Bukkit/src/main/java/com/plotsquared/bukkit/listeners/PlayerEvents_1_9.java @@ -9,9 +9,6 @@ import org.bukkit.event.EventPriority; import org.bukkit.event.Listener; import org.bukkit.event.entity.LingeringPotionSplashEvent; -/** - * Created by Jesse on 3/30/2016. - */ public class PlayerEvents_1_9 implements Listener { private final PlayerEvents parent; diff --git a/Bukkit/src/main/java/com/plotsquared/bukkit/listeners/worldedit/WEListener.java b/Bukkit/src/main/java/com/plotsquared/bukkit/listeners/worldedit/WEListener.java index bd6f78de9..4c154fdaa 100644 --- a/Bukkit/src/main/java/com/plotsquared/bukkit/listeners/worldedit/WEListener.java +++ b/Bukkit/src/main/java/com/plotsquared/bukkit/listeners/worldedit/WEListener.java @@ -27,6 +27,7 @@ import org.bukkit.event.player.PlayerCommandPreprocessEvent; import java.util.Arrays; import java.util.Collections; import java.util.HashSet; +import java.util.Set; public class WEListener implements Listener { @@ -35,16 +36,16 @@ public class WEListener implements Listener { public final HashSet rad2 = new HashSet<>(Arrays.asList("fill", "fillr", "removenear", "remove")); public final HashSet rad2_1 = new HashSet<>(Arrays.asList("hcyl", "cyl")); public final HashSet rad2_2 = new HashSet<>(Arrays.asList("sphere", "pyramid")); - public final HashSet rad2_3 = new HashSet<>(Collections.singletonList("brush smooth")); - public final HashSet rad3_1 = new HashSet<>(Collections.singletonList("brush gravity")); + public final Set rad2_3 = Collections.singleton("brush smooth"); + public final Set rad3_1 = Collections.singleton("brush gravity"); public final HashSet rad3_2 = new HashSet<>(Arrays.asList("brush sphere", "brush cylinder")); public final HashSet region = new HashSet<>( Arrays.asList("move", "set", "replace", "overlay", "walls", "outline", "deform", "hollow", "smooth", "naturalize", "paste", "count", "distr", "regen", "copy", "cut", "green", "setbiome")); - public final HashSet regionExtend = new HashSet<>(Collections.singletonList("stack")); - public final HashSet restricted = new HashSet<>(Collections.singletonList("up")); + public final Set regionExtend = Collections.singleton("stack"); + public final Set restricted = Collections.singleton("up"); public final HashSet other = new HashSet<>(Arrays.asList("undo", "redo")); public String reduceCmd(String cmd, boolean single) { diff --git a/Bukkit/src/main/java/com/plotsquared/bukkit/titles/DefaultTitleManager.java b/Bukkit/src/main/java/com/plotsquared/bukkit/titles/DefaultTitleManager.java index 89e457d2e..b7054a632 100644 --- a/Bukkit/src/main/java/com/plotsquared/bukkit/titles/DefaultTitleManager.java +++ b/Bukkit/src/main/java/com/plotsquared/bukkit/titles/DefaultTitleManager.java @@ -57,14 +57,14 @@ public class DefaultTitleManager extends TitleManager { // Send title Object serialized = getMethod(this.nmsChatSerializer, "a", String.class).invoke(null, "{text:\"" + ChatColor.translateAlternateColorCodes('&', this.getTitle()) + "\",color:" + this.titleColor.name().toLowerCase() - + "}"); + + '}'); packet = this.packetTitle.getConstructor(this.packetActions, this.chatBaseComponent).newInstance(actions[0], serialized); sendPacket.invoke(connection, packet); if (!this.getSubtitle().isEmpty()) { // Send subtitle if present serialized = getMethod(this.nmsChatSerializer, "a", String.class).invoke(null, "{text:\"" + ChatColor.translateAlternateColorCodes('&', this.getSubtitle()) + "\",color:" + this.subtitleColor.name() - .toLowerCase() + "}"); + .toLowerCase() + '}'); packet = this.packetTitle.getConstructor(this.packetActions, this.chatBaseComponent).newInstance(actions[1], serialized); sendPacket.invoke(connection, packet); } diff --git a/Bukkit/src/main/java/com/plotsquared/bukkit/titles/HackTitleManager.java b/Bukkit/src/main/java/com/plotsquared/bukkit/titles/HackTitleManager.java index 11dc5fefb..de5774cd4 100644 --- a/Bukkit/src/main/java/com/plotsquared/bukkit/titles/HackTitleManager.java +++ b/Bukkit/src/main/java/com/plotsquared/bukkit/titles/HackTitleManager.java @@ -148,7 +148,7 @@ public class HackTitleManager extends TitleManager { return null; } - private Field getField(String name, Class clazz) throws Exception { + private Field getField(String name, Class clazz) throws NoSuchFieldException, SecurityException { return clazz.getDeclaredField(name); } diff --git a/Bukkit/src/main/java/com/plotsquared/bukkit/util/BukkitChunkManager.java b/Bukkit/src/main/java/com/plotsquared/bukkit/util/BukkitChunkManager.java index e181810f8..7d1a89709 100644 --- a/Bukkit/src/main/java/com/plotsquared/bukkit/util/BukkitChunkManager.java +++ b/Bukkit/src/main/java/com/plotsquared/bukkit/util/BukkitChunkManager.java @@ -742,12 +742,12 @@ public class BukkitChunkManager extends ChunkManager { chest.getInventory().setContents(blockLocEntry.getValue()); state.update(true); } else { - PS.debug("&c[WARN] Plot clear failed to regenerate chest: " + (blockLocEntry.getKey().x + xOffset) + "," + blockLocEntry - .getKey().y + "," + (blockLocEntry.getKey().z + zOffset)); + PS.debug("&c[WARN] Plot clear failed to regenerate chest: " + (blockLocEntry.getKey().x + xOffset) + ',' + blockLocEntry + .getKey().y + ',' + (blockLocEntry.getKey().z + zOffset)); } } catch (IllegalArgumentException ignored) { - PS.debug("&c[WARN] Plot clear failed to regenerate chest (e): " + (blockLocEntry.getKey().x + xOffset) + "," + blockLocEntry - .getKey().y + "," + (blockLocEntry.getKey().z + zOffset)); + PS.debug("&c[WARN] Plot clear failed to regenerate chest (e): " + (blockLocEntry.getKey().x + xOffset) + ',' + blockLocEntry + .getKey().y + ',' + (blockLocEntry.getKey().z + zOffset)); } } for (Entry blockLocEntry : this.signContents.entrySet()) { @@ -765,14 +765,14 @@ public class BukkitChunkManager extends ChunkManager { state.update(true); } else { PS.debug( - "&c[WARN] Plot clear failed to regenerate sign: " + (blockLocEntry.getKey().x + xOffset) + "," + blockLocEntry + "&c[WARN] Plot clear failed to regenerate sign: " + (blockLocEntry.getKey().x + xOffset) + ',' + blockLocEntry .getKey().y - + "," + ( + + ',' + ( blockLocEntry.getKey().z + zOffset)); } - } catch (IndexOutOfBoundsException e) { - PS.debug("&c[WARN] Plot clear failed to regenerate sign: " + (blockLocEntry.getKey().x + xOffset) + "," + blockLocEntry.getKey().y - + "," + ( + } catch (IndexOutOfBoundsException ignored) { + PS.debug("&c[WARN] Plot clear failed to regenerate sign: " + (blockLocEntry.getKey().x + xOffset) + ',' + blockLocEntry.getKey().y + + ',' + ( blockLocEntry.getKey().z + zOffset)); } } @@ -785,12 +785,12 @@ public class BukkitChunkManager extends ChunkManager { ((InventoryHolder) state).getInventory().setContents(blockLocEntry.getValue()); state.update(true); } else { - PS.debug("&c[WARN] Plot clear failed to regenerate dispenser: " + (blockLocEntry.getKey().x + xOffset) + "," + blockLocEntry - .getKey().y + "," + (blockLocEntry.getKey().z + zOffset)); + PS.debug("&c[WARN] Plot clear failed to regenerate dispenser: " + (blockLocEntry.getKey().x + xOffset) + ',' + blockLocEntry + .getKey().y + ',' + (blockLocEntry.getKey().z + zOffset)); } } catch (IllegalArgumentException ignored) { - PS.debug("&c[WARN] Plot clear failed to regenerate dispenser (e): " + (blockLocEntry.getKey().x + xOffset) + "," + blockLocEntry - .getKey().y + "," + (blockLocEntry.getKey().z + zOffset)); + PS.debug("&c[WARN] Plot clear failed to regenerate dispenser (e): " + (blockLocEntry.getKey().x + xOffset) + ',' + blockLocEntry + .getKey().y + ',' + (blockLocEntry.getKey().z + zOffset)); } } for (Entry blockLocEntry : this.dropperContents.entrySet()) { @@ -802,12 +802,12 @@ public class BukkitChunkManager extends ChunkManager { ((InventoryHolder) state).getInventory().setContents(blockLocEntry.getValue()); state.update(true); } else { - PS.debug("&c[WARN] Plot clear failed to regenerate dispenser: " + (blockLocEntry.getKey().x + xOffset) + "," + blockLocEntry - .getKey().y + "," + (blockLocEntry.getKey().z + zOffset)); + PS.debug("&c[WARN] Plot clear failed to regenerate dispenser: " + (blockLocEntry.getKey().x + xOffset) + ',' + blockLocEntry + .getKey().y + ',' + (blockLocEntry.getKey().z + zOffset)); } } catch (IllegalArgumentException ignored) { - PS.debug("&c[WARN] Plot clear failed to regenerate dispenser (e): " + (blockLocEntry.getKey().x + xOffset) + "," + blockLocEntry - .getKey().y + "," + (blockLocEntry.getKey().z + zOffset)); + PS.debug("&c[WARN] Plot clear failed to regenerate dispenser (e): " + (blockLocEntry.getKey().x + xOffset) + ',' + blockLocEntry + .getKey().y + ',' + (blockLocEntry.getKey().z + zOffset)); } } for (Entry blockLocEntry : this.beaconContents.entrySet()) { @@ -819,12 +819,12 @@ public class BukkitChunkManager extends ChunkManager { ((InventoryHolder) state).getInventory().setContents(blockLocEntry.getValue()); state.update(true); } else { - PS.debug("&c[WARN] Plot clear failed to regenerate beacon: " + (blockLocEntry.getKey().x + xOffset) + "," + blockLocEntry - .getKey().y + "," + (blockLocEntry.getKey().z + zOffset)); + PS.debug("&c[WARN] Plot clear failed to regenerate beacon: " + (blockLocEntry.getKey().x + xOffset) + ',' + blockLocEntry + .getKey().y + ',' + (blockLocEntry.getKey().z + zOffset)); } } catch (IllegalArgumentException ignored) { - PS.debug("&c[WARN] Plot clear failed to regenerate beacon (e): " + (blockLocEntry.getKey().x + xOffset) + "," + blockLocEntry - .getKey().y + "," + (blockLocEntry.getKey().z + zOffset)); + PS.debug("&c[WARN] Plot clear failed to regenerate beacon (e): " + (blockLocEntry.getKey().x + xOffset) + ',' + blockLocEntry + .getKey().y + ',' + (blockLocEntry.getKey().z + zOffset)); } } for (Entry blockLocMaterialEntry : this.jukeboxDisc.entrySet()) { @@ -837,15 +837,15 @@ public class BukkitChunkManager extends ChunkManager { ((Jukebox) state).setPlaying(blockLocMaterialEntry.getValue()); state.update(true); } else { - PS.debug("&c[WARN] Plot clear failed to restore jukebox: " + (blockLocMaterialEntry.getKey().x + xOffset) + "," + PS.debug("&c[WARN] Plot clear failed to restore jukebox: " + (blockLocMaterialEntry.getKey().x + xOffset) + ',' + blockLocMaterialEntry - .getKey().y + "," + ( + .getKey().y + ',' + ( blockLocMaterialEntry.getKey().z + zOffset)); } } catch (Exception ignored) { - PS.debug("&c[WARN] Plot clear failed to regenerate jukebox (e): " + (blockLocMaterialEntry.getKey().x + xOffset) + "," + PS.debug("&c[WARN] Plot clear failed to regenerate jukebox (e): " + (blockLocMaterialEntry.getKey().x + xOffset) + ',' + blockLocMaterialEntry - .getKey().y + "," + ( + .getKey().y + ',' + ( blockLocMaterialEntry.getKey().z + zOffset)); } } @@ -863,12 +863,12 @@ public class BukkitChunkManager extends ChunkManager { ((Skull) state).setSkullType((SkullType) data[3]); state.update(true); } else { - PS.debug("&c[WARN] Plot clear failed to restore skull: " + (blockLocEntry.getKey().x + xOffset) + "," + blockLocEntry - .getKey().y + "," + (blockLocEntry.getKey().z + zOffset)); + PS.debug("&c[WARN] Plot clear failed to restore skull: " + (blockLocEntry.getKey().x + xOffset) + ',' + blockLocEntry + .getKey().y + ',' + (blockLocEntry.getKey().z + zOffset)); } } catch (Exception e) { - PS.debug("&c[WARN] Plot clear failed to regenerate skull (e): " + (blockLocEntry.getKey().x + xOffset) + "," + blockLocEntry - .getKey().y + "," + (blockLocEntry.getKey().z + zOffset)); + PS.debug("&c[WARN] Plot clear failed to regenerate skull (e): " + (blockLocEntry.getKey().x + xOffset) + ',' + blockLocEntry + .getKey().y + ',' + (blockLocEntry.getKey().z + zOffset)); e.printStackTrace(); } } @@ -881,12 +881,12 @@ public class BukkitChunkManager extends ChunkManager { ((InventoryHolder) state).getInventory().setContents(blockLocEntry.getValue()); state.update(true); } else { - PS.debug("&c[WARN] Plot clear failed to regenerate hopper: " + (blockLocEntry.getKey().x + xOffset) + "," + blockLocEntry - .getKey().y + "," + (blockLocEntry.getKey().z + zOffset)); + PS.debug("&c[WARN] Plot clear failed to regenerate hopper: " + (blockLocEntry.getKey().x + xOffset) + ',' + blockLocEntry + .getKey().y + ',' + (blockLocEntry.getKey().z + zOffset)); } } catch (IllegalArgumentException ignored) { - PS.debug("&c[WARN] Plot clear failed to regenerate hopper (e): " + (blockLocEntry.getKey().x + xOffset) + "," + blockLocEntry - .getKey().y + "," + (blockLocEntry.getKey().z + zOffset)); + PS.debug("&c[WARN] Plot clear failed to regenerate hopper (e): " + (blockLocEntry.getKey().x + xOffset) + ',' + blockLocEntry + .getKey().y + ',' + (blockLocEntry.getKey().z + zOffset)); } } for (Entry blockLocNoteEntry : this.noteBlockContents.entrySet()) { @@ -898,15 +898,15 @@ public class BukkitChunkManager extends ChunkManager { ((NoteBlock) state).setNote(blockLocNoteEntry.getValue()); state.update(true); } else { - PS.debug("&c[WARN] Plot clear failed to regenerate note block: " + (blockLocNoteEntry.getKey().x + xOffset) + "," + PS.debug("&c[WARN] Plot clear failed to regenerate note block: " + (blockLocNoteEntry.getKey().x + xOffset) + ',' + blockLocNoteEntry - .getKey().y + "," + ( + .getKey().y + ',' + ( blockLocNoteEntry.getKey().z + zOffset)); } } catch (Exception ignored) { - PS.debug("&c[WARN] Plot clear failed to regenerate note block (e): " + (blockLocNoteEntry.getKey().x + xOffset) + "," + PS.debug("&c[WARN] Plot clear failed to regenerate note block (e): " + (blockLocNoteEntry.getKey().x + xOffset) + ',' + blockLocNoteEntry - .getKey().y + "," + ( + .getKey().y + ',' + ( blockLocNoteEntry.getKey().z + zOffset)); } } @@ -918,14 +918,14 @@ public class BukkitChunkManager extends ChunkManager { if (state instanceof BrewingStand) { ((BrewingStand) state).setBrewingTime(blockLocShortEntry.getValue()); } else { - PS.debug("&c[WARN] Plot clear failed to restore brewing stand cooking: " + (blockLocShortEntry.getKey().x + xOffset) + "," + PS.debug("&c[WARN] Plot clear failed to restore brewing stand cooking: " + (blockLocShortEntry.getKey().x + xOffset) + ',' + blockLocShortEntry - .getKey().y + "," + ( + .getKey().y + ',' + ( blockLocShortEntry.getKey().z + zOffset)); } } catch (Exception ignored) { - PS.debug("&c[WARN] Plot clear failed to restore brewing stand cooking (e): " + (blockLocShortEntry.getKey().x + xOffset) + "," - + blockLocShortEntry.getKey().y + "," + (blockLocShortEntry.getKey().z + zOffset)); + PS.debug("&c[WARN] Plot clear failed to restore brewing stand cooking (e): " + (blockLocShortEntry.getKey().x + xOffset) + ',' + + blockLocShortEntry.getKey().y + ',' + (blockLocShortEntry.getKey().z + zOffset)); } } for (Entry blockLocEntityTypeEntry : this.spawnerData.entrySet()) { @@ -938,14 +938,14 @@ public class BukkitChunkManager extends ChunkManager { ((CreatureSpawner) state).setSpawnedType(blockLocEntityTypeEntry.getValue()); state.update(true); } else { - PS.debug("&c[WARN] Plot clear failed to restore spawner type: " + (blockLocEntityTypeEntry.getKey().x + xOffset) + "," + PS.debug("&c[WARN] Plot clear failed to restore spawner type: " + (blockLocEntityTypeEntry.getKey().x + xOffset) + ',' + blockLocEntityTypeEntry - .getKey().y + "," + ( + .getKey().y + ',' + ( blockLocEntityTypeEntry.getKey().z + zOffset)); } - } catch (Exception e) { - PS.debug("&c[WARN] Plot clear failed to restore spawner type (e): " + (blockLocEntityTypeEntry.getKey().x + xOffset) + "," - + blockLocEntityTypeEntry.getKey().y + "," + (blockLocEntityTypeEntry.getKey().z + zOffset)); + } catch (Exception ignored) { + PS.debug("&c[WARN] Plot clear failed to restore spawner type (e): " + (blockLocEntityTypeEntry.getKey().x + xOffset) + ',' + + blockLocEntityTypeEntry.getKey().y + ',' + (blockLocEntityTypeEntry.getKey().z + zOffset)); } } for (Entry blockLocStringEntry : this.cmdData.entrySet()) { @@ -957,15 +957,15 @@ public class BukkitChunkManager extends ChunkManager { ((CommandBlock) state).setCommand(blockLocStringEntry.getValue()); state.update(true); } else { - PS.debug("&c[WARN] Plot clear failed to restore command block: " + (blockLocStringEntry.getKey().x + xOffset) + "," + PS.debug("&c[WARN] Plot clear failed to restore command block: " + (blockLocStringEntry.getKey().x + xOffset) + ',' + blockLocStringEntry - .getKey().y + "," + ( + .getKey().y + ',' + ( blockLocStringEntry.getKey().z + zOffset)); } - } catch (Exception e) { - PS.debug("&c[WARN] Plot clear failed to restore command block (e): " + (blockLocStringEntry.getKey().x + xOffset) + "," + } catch (Exception ignored) { + PS.debug("&c[WARN] Plot clear failed to restore command block (e): " + (blockLocStringEntry.getKey().x + xOffset) + ',' + blockLocStringEntry - .getKey().y + "," + ( + .getKey().y + ',' + ( blockLocStringEntry.getKey().z + zOffset)); } } @@ -978,15 +978,15 @@ public class BukkitChunkManager extends ChunkManager { ((InventoryHolder) state).getInventory().setContents(blockLocEntry.getValue()); state.update(true); } else { - PS.debug("&c[WARN] Plot clear failed to regenerate brewing stand: " + (blockLocEntry.getKey().x + xOffset) + "," + PS.debug("&c[WARN] Plot clear failed to regenerate brewing stand: " + (blockLocEntry.getKey().x + xOffset) + ',' + blockLocEntry - .getKey().y + "," + ( + .getKey().y + ',' + ( blockLocEntry.getKey().z + zOffset)); } - } catch (IllegalArgumentException e) { - PS.debug("&c[WARN] Plot clear failed to regenerate brewing stand (e): " + (blockLocEntry.getKey().x + xOffset) + "," - + blockLocEntry.getKey().y + "," + (blockLocEntry.getKey().z + zOffset)); + } catch (IllegalArgumentException ignored) { + PS.debug("&c[WARN] Plot clear failed to regenerate brewing stand (e): " + (blockLocEntry.getKey().x + xOffset) + ',' + + blockLocEntry.getKey().y + ',' + (blockLocEntry.getKey().z + zOffset)); } } for (Entry blockLocEntry : this.furnaceTime.entrySet()) { @@ -1000,13 +1000,13 @@ public class BukkitChunkManager extends ChunkManager { ((Furnace) state).setCookTime(time[1]); } else { PS.debug( - "&c[WARN] Plot clear failed to restore furnace cooking: " + (blockLocEntry.getKey().x + xOffset) + "," + blockLocEntry - .getKey().y + "," + (blockLocEntry.getKey().z + zOffset)); + "&c[WARN] Plot clear failed to restore furnace cooking: " + (blockLocEntry.getKey().x + xOffset) + ',' + blockLocEntry + .getKey().y + ',' + (blockLocEntry.getKey().z + zOffset)); } - } catch (Exception e) { + } catch (Exception ignored) { PS.debug( - "&c[WARN] Plot clear failed to restore furnace cooking (e): " + (blockLocEntry.getKey().x + xOffset) + "," + blockLocEntry - .getKey().y + "," + (blockLocEntry.getKey().z + zOffset)); + "&c[WARN] Plot clear failed to restore furnace cooking (e): " + (blockLocEntry.getKey().x + xOffset) + ',' + blockLocEntry + .getKey().y + ',' + (blockLocEntry.getKey().z + zOffset)); } } for (Entry blockLocEntry : this.furnaceContents.entrySet()) { @@ -1018,12 +1018,12 @@ public class BukkitChunkManager extends ChunkManager { ((InventoryHolder) state).getInventory().setContents(blockLocEntry.getValue()); state.update(true); } else { - PS.debug("&c[WARN] Plot clear failed to regenerate furnace: " + (blockLocEntry.getKey().x + xOffset) + "," + blockLocEntry - .getKey().y + "," + (blockLocEntry.getKey().z + zOffset)); + PS.debug("&c[WARN] Plot clear failed to regenerate furnace: " + (blockLocEntry.getKey().x + xOffset) + ',' + blockLocEntry + .getKey().y + ',' + (blockLocEntry.getKey().z + zOffset)); } - } catch (IllegalArgumentException e) { - PS.debug("&c[WARN] Plot clear failed to regenerate furnace (e): " + (blockLocEntry.getKey().x + xOffset) + "," + blockLocEntry - .getKey().y + "," + (blockLocEntry.getKey().z + zOffset)); + } catch (IllegalArgumentException ignored) { + PS.debug("&c[WARN] Plot clear failed to regenerate furnace (e): " + (blockLocEntry.getKey().x + xOffset) + ',' + blockLocEntry + .getKey().y + ',' + (blockLocEntry.getKey().z + zOffset)); } } for (Entry blockLocByteEntry : this.bannerBase.entrySet()) { @@ -1039,12 +1039,12 @@ public class BukkitChunkManager extends ChunkManager { banner.setPatterns(patterns); state.update(true); } else { - PS.debug("&c[WARN] Plot clear failed to regenerate banner: " + (blockLocByteEntry.getKey().x + xOffset) + "," - + blockLocByteEntry.getKey().y + "," + (blockLocByteEntry.getKey().z + zOffset)); + PS.debug("&c[WARN] Plot clear failed to regenerate banner: " + (blockLocByteEntry.getKey().x + xOffset) + ',' + + blockLocByteEntry.getKey().y + ',' + (blockLocByteEntry.getKey().z + zOffset)); } - } catch (Exception e) { - PS.debug("&c[WARN] Plot clear failed to regenerate banner (e): " + (blockLocByteEntry.getKey().x + xOffset) + "," - + blockLocByteEntry.getKey().y + "," + (blockLocByteEntry.getKey().z + zOffset)); + } catch (Exception ignored) { + PS.debug("&c[WARN] Plot clear failed to regenerate banner (e): " + (blockLocByteEntry.getKey().x + xOffset) + ',' + + blockLocByteEntry.getKey().y + ',' + (blockLocByteEntry.getKey().z + zOffset)); } } } @@ -1074,33 +1074,42 @@ public class BukkitChunkManager extends ChunkManager { if (block.getState() instanceof InventoryHolder) { InventoryHolder inventoryHolder = (InventoryHolder) block.getState(); ItemStack[] inventory = inventoryHolder.getInventory().getContents().clone(); - if (id == Material.CHEST) { - this.chestContents.put(bl, inventory); - } else if (id == Material.DISPENSER) { - this.dispenserContents.put(bl, inventory); - } else if (id == Material.BEACON) { - this.beaconContents.put(bl, inventory); - } else if (id == Material.DROPPER) { - this.dropperContents.put(bl, inventory); - } else if (id == Material.HOPPER) { - this.hopperContents.put(bl, inventory); - } else if (id == Material.BREWING_STAND) { - BrewingStand brewingStand = (BrewingStand) inventoryHolder; - short time = (short) brewingStand.getBrewingTime(); - if (time > 0) { - this.brewTime.put(bl, time); - } - ItemStack[] invBre = brewingStand.getInventory().getContents().clone(); - this.brewingStandContents.put(bl, invBre); - } else if (id == Material.FURNACE || id == Material.BURNING_FURNACE) { - Furnace furnace = (Furnace) inventoryHolder; - short burn = furnace.getBurnTime(); - short cook = furnace.getCookTime(); - ItemStack[] invFur = furnace.getInventory().getContents().clone(); - this.furnaceContents.put(bl, invFur); - if (cook != 0) { - this.furnaceTime.put(bl, new Short[]{burn, cook}); - } + switch (id) { + case CHEST: + this.chestContents.put(bl, inventory); + break; + case DISPENSER: + this.dispenserContents.put(bl, inventory); + break; + case BEACON: + this.beaconContents.put(bl, inventory); + break; + case DROPPER: + this.dropperContents.put(bl, inventory); + break; + case HOPPER: + this.hopperContents.put(bl, inventory); + break; + case BREWING_STAND: + BrewingStand brewingStand = (BrewingStand) inventoryHolder; + short time = (short) brewingStand.getBrewingTime(); + if (time > 0) { + this.brewTime.put(bl, time); + } + ItemStack[] invBre = brewingStand.getInventory().getContents().clone(); + this.brewingStandContents.put(bl, invBre); + break; + case FURNACE: + case BURNING_FURNACE: + Furnace furnace = (Furnace) inventoryHolder; + short burn = furnace.getBurnTime(); + short cook = furnace.getCookTime(); + ItemStack[] invFur = furnace.getInventory().getContents().clone(); + this.furnaceContents.put(bl, invFur); + if (cook != 0) { + this.furnaceTime.put(bl, new Short[]{burn, cook}); + } + break; } } else if (block.getState() instanceof CreatureSpawner) { CreatureSpawner spawner = (CreatureSpawner) block.getState(); diff --git a/Bukkit/src/main/java/com/plotsquared/bukkit/util/BukkitUtil.java b/Bukkit/src/main/java/com/plotsquared/bukkit/util/BukkitUtil.java index 13a559d9c..fff80fe74 100644 --- a/Bukkit/src/main/java/com/plotsquared/bukkit/util/BukkitUtil.java +++ b/Bukkit/src/main/java/com/plotsquared/bukkit/util/BukkitUtil.java @@ -194,7 +194,7 @@ public class BukkitUtil extends WorldUtil { try { Biome biome = Biome.valueOf(biomeStr.toUpperCase()); return Arrays.asList(Biome.values()).indexOf(biome); - } catch (IllegalArgumentException e) { + } catch (IllegalArgumentException ignored) { return -1; } } @@ -252,7 +252,7 @@ public class BukkitUtil extends WorldUtil { } } return false; - } catch (Exception e) { + } catch (Exception ignored) { return false; } } @@ -271,8 +271,7 @@ public class BukkitUtil extends WorldUtil { try { Material material = Material.valueOf(name.toUpperCase()); return new StringComparison().new ComparisonResult(0, new PlotBlock((short) material.getId(), (byte) 0)); - } catch (IllegalArgumentException e) { - //ignored + } catch (IllegalArgumentException ignored) { } try { byte data; @@ -297,8 +296,7 @@ public class BukkitUtil extends WorldUtil { StringComparison outer = new StringComparison<>(); return outer.new ComparisonResult(match, block); - } catch (NumberFormatException e) { - //ignored + } catch (NumberFormatException ignored) { } return null; } diff --git a/Bukkit/src/main/java/com/plotsquared/bukkit/util/Metrics.java b/Bukkit/src/main/java/com/plotsquared/bukkit/util/Metrics.java index abfb5994d..52afe43f7 100644 --- a/Bukkit/src/main/java/com/plotsquared/bukkit/util/Metrics.java +++ b/Bukkit/src/main/java/com/plotsquared/bukkit/util/Metrics.java @@ -520,11 +520,6 @@ public class Metrics { return graph.name.equals(this.name); } - /** - * Called when the server owner decides to opt-out of BukkitMetrics while the server is running. - */ - protected void onOptOut() { - } } /** diff --git a/Bukkit/src/main/java/com/plotsquared/bukkit/util/block/FastQueue_1_9.java b/Bukkit/src/main/java/com/plotsquared/bukkit/util/block/FastQueue_1_9.java index cb4c67f63..c3e4ea506 100644 --- a/Bukkit/src/main/java/com/plotsquared/bukkit/util/block/FastQueue_1_9.java +++ b/Bukkit/src/main/java/com/plotsquared/bukkit/util/block/FastQueue_1_9.java @@ -24,8 +24,8 @@ import org.bukkit.block.Biome; import java.lang.reflect.Field; import java.lang.reflect.InvocationTargetException; import java.lang.reflect.Method; -import java.util.Arrays; import java.util.Collection; +import java.util.Collections; import java.util.HashMap; import java.util.Iterator; import java.util.Map.Entry; @@ -223,7 +223,7 @@ public class FastQueue_1_9 extends SlowQueue { TaskManager.runTaskLater(new Runnable() { @Override public void run() { - sendChunk(fs.getChunkWrapper().world, Arrays.asList(new ChunkLoc(fs.getX(), fs.getZ()))); + sendChunk(fs.getChunkWrapper().world, Collections.singletonList(new ChunkLoc(fs.getX(), fs.getZ()))); } }, 1); } diff --git a/Bukkit/src/main/java/com/plotsquared/bukkit/uuid/FileUUIDHandler.java b/Bukkit/src/main/java/com/plotsquared/bukkit/uuid/FileUUIDHandler.java index 2cd6d6805..c3a2fdc2b 100644 --- a/Bukkit/src/main/java/com/plotsquared/bukkit/uuid/FileUUIDHandler.java +++ b/Bukkit/src/main/java/com/plotsquared/bukkit/uuid/FileUUIDHandler.java @@ -114,7 +114,7 @@ public class FileUUIDHandler extends UUIDHandlerImplementation { } toAdd.put(new StringWrapper(name), uuid); } - } catch (Exception e) { + } catch (IOException e) { e.printStackTrace(); PS.debug(C.PREFIX + "Invalid playerdata: " + current); } @@ -153,7 +153,7 @@ public class FileUUIDHandler extends UUIDHandlerImplementation { try { UUID uuid = UUID.fromString(s); uuids.add(uuid); - } catch (Exception e) { + } catch (Exception ignored) { PS.debug(C.PREFIX + "Invalid PlayerData: " + current); } } @@ -198,7 +198,7 @@ public class FileUUIDHandler extends UUIDHandlerImplementation { ExpireManager.IMP.storeDate(uuid, last); } toAdd.put(new StringWrapper(name), uuid); - } catch (Throwable e) { + } catch (IOException ignored) { PS.debug(C.PREFIX + "&6Invalid PlayerData: " + uuid.toString() + ".dat"); } } diff --git a/Core/src/main/java/com/intellectualcrafters/configuration/file/YamlConfiguration.java b/Core/src/main/java/com/intellectualcrafters/configuration/file/YamlConfiguration.java index d1e9c11e7..f869b3eea 100644 --- a/Core/src/main/java/com/intellectualcrafters/configuration/file/YamlConfiguration.java +++ b/Core/src/main/java/com/intellectualcrafters/configuration/file/YamlConfiguration.java @@ -51,7 +51,6 @@ public class YamlConfiguration extends FileConfiguration { config.load(file); } catch (InvalidConfigurationException | IOException ex) { try { - file.getAbsolutePath(); File dest = new File(file.getAbsolutePath() + "_broken"); int i = 0; while (dest.exists()) { @@ -126,7 +125,7 @@ public class YamlConfiguration extends FileConfiguration { input = (Map) yaml.load(contents); } catch (final YAMLException e) { throw new InvalidConfigurationException(e); - } catch (final ClassCastException e) { + } catch (final ClassCastException ignored) { throw new InvalidConfigurationException("Top level is not a Map."); } @@ -189,7 +188,7 @@ public class YamlConfiguration extends FileConfiguration { if (options().copyHeader()) { final Configuration def = getDefaults(); - if (def != null && def instanceof FileConfiguration) { + if (def instanceof FileConfiguration) { final FileConfiguration filedefaults = (FileConfiguration) def; final String defaultsHeader = filedefaults.buildHeader(); diff --git a/Core/src/main/java/com/intellectualcrafters/configuration/serialization/ConfigurationSerialization.java b/Core/src/main/java/com/intellectualcrafters/configuration/serialization/ConfigurationSerialization.java index 0640894a5..3bb971376 100644 --- a/Core/src/main/java/com/intellectualcrafters/configuration/serialization/ConfigurationSerialization.java +++ b/Core/src/main/java/com/intellectualcrafters/configuration/serialization/ConfigurationSerialization.java @@ -209,7 +209,7 @@ public class ConfigurationSerialization { } else { return result; } - } catch (Throwable ex) { + } catch (IllegalAccessException | InvocationTargetException | IllegalArgumentException ex) { Logger.getLogger(ConfigurationSerialization.class.getName()) .log(Level.SEVERE, "Could not call method '" + method.toString() + "' of " + this.clazz + " for deserialization", @@ -222,7 +222,7 @@ public class ConfigurationSerialization { protected ConfigurationSerializable deserializeViaCtor(Constructor ctor, Map args) { try { return ctor.newInstance(args); - } catch (Throwable ex) { + } 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", @@ -238,22 +238,17 @@ public class ConfigurationSerialization { } ConfigurationSerializable result = null; Method method = getMethod("deserialize", true); - if (method != null) { result = deserializeViaMethod(method, args); } - if (result == null) { method = getMethod("valueOf", true); - if (method != null) { result = deserializeViaMethod(method, args); } } - if (result == null) { Constructor constructor = getConstructor(); - if (constructor != null) { result = deserializeViaCtor(constructor, args); } diff --git a/Core/src/main/java/com/intellectualcrafters/jnbt/ByteArrayTag.java b/Core/src/main/java/com/intellectualcrafters/jnbt/ByteArrayTag.java index 791380e06..420a6ad69 100644 --- a/Core/src/main/java/com/intellectualcrafters/jnbt/ByteArrayTag.java +++ b/Core/src/main/java/com/intellectualcrafters/jnbt/ByteArrayTag.java @@ -44,7 +44,7 @@ public final class ByteArrayTag extends Tag { } String name = getName(); String append = ""; - if (name != null && !name.equals("")) { + if (name != null && !name.isEmpty()) { append = "(\"" + getName() + "\")"; } return "TAG_Byte_Array" + append + ": " + hex; diff --git a/Core/src/main/java/com/intellectualcrafters/jnbt/ByteTag.java b/Core/src/main/java/com/intellectualcrafters/jnbt/ByteTag.java index 627fc754d..7e8c2b7e4 100644 --- a/Core/src/main/java/com/intellectualcrafters/jnbt/ByteTag.java +++ b/Core/src/main/java/com/intellectualcrafters/jnbt/ByteTag.java @@ -36,7 +36,7 @@ public final class ByteTag extends Tag { public String toString() { String name = getName(); String append = ""; - if (name != null && !name.equals("")) { + if (name != null && !name.isEmpty()) { append = "(\"" + getName() + "\")"; } return "TAG_Byte" + append + ": " + this.value; diff --git a/Core/src/main/java/com/intellectualcrafters/jnbt/CompoundTag.java b/Core/src/main/java/com/intellectualcrafters/jnbt/CompoundTag.java index 75c76b1ed..4bbbd62b5 100644 --- a/Core/src/main/java/com/intellectualcrafters/jnbt/CompoundTag.java +++ b/Core/src/main/java/com/intellectualcrafters/jnbt/CompoundTag.java @@ -373,7 +373,7 @@ public final class CompoundTag extends Tag { public String toString() { String name = getName(); String append = ""; - if (name != null && !name.equals("")) { + if (name != null && !name.isEmpty()) { append = "(\"" + getName() + "\")"; } StringBuilder bldr = new StringBuilder(); diff --git a/Core/src/main/java/com/intellectualcrafters/jnbt/CompoundTagBuilder.java b/Core/src/main/java/com/intellectualcrafters/jnbt/CompoundTagBuilder.java index 69614f05d..54e33db01 100644 --- a/Core/src/main/java/com/intellectualcrafters/jnbt/CompoundTagBuilder.java +++ b/Core/src/main/java/com/intellectualcrafters/jnbt/CompoundTagBuilder.java @@ -16,7 +16,7 @@ public class CompoundTagBuilder { * Create a new instance. */ CompoundTagBuilder() { - this.entries = new HashMap(); + this.entries = new HashMap<>(); } /** diff --git a/Core/src/main/java/com/intellectualcrafters/jnbt/DoubleTag.java b/Core/src/main/java/com/intellectualcrafters/jnbt/DoubleTag.java index 891f3c0ed..c5954abd0 100644 --- a/Core/src/main/java/com/intellectualcrafters/jnbt/DoubleTag.java +++ b/Core/src/main/java/com/intellectualcrafters/jnbt/DoubleTag.java @@ -36,7 +36,7 @@ public final class DoubleTag extends Tag { public String toString() { String name = getName(); String append = ""; - if (name != null && !name.equals("")) { + if (name != null && !name.isEmpty()) { append = "(\"" + getName() + "\")"; } return "TAG_Double" + append + ": " + this.value; diff --git a/Core/src/main/java/com/intellectualcrafters/jnbt/FloatTag.java b/Core/src/main/java/com/intellectualcrafters/jnbt/FloatTag.java index 2f17aff0d..21ab3734b 100644 --- a/Core/src/main/java/com/intellectualcrafters/jnbt/FloatTag.java +++ b/Core/src/main/java/com/intellectualcrafters/jnbt/FloatTag.java @@ -36,7 +36,7 @@ public final class FloatTag extends Tag { public String toString() { String name = getName(); String append = ""; - if (name != null && !name.equals("")) { + if (name != null && !name.isEmpty()) { append = "(\"" + getName() + "\")"; } return "TAG_Float" + append + ": " + this.value; diff --git a/Core/src/main/java/com/intellectualcrafters/jnbt/IntArrayTag.java b/Core/src/main/java/com/intellectualcrafters/jnbt/IntArrayTag.java index 5a53adffb..a33fa6952 100644 --- a/Core/src/main/java/com/intellectualcrafters/jnbt/IntArrayTag.java +++ b/Core/src/main/java/com/intellectualcrafters/jnbt/IntArrayTag.java @@ -48,7 +48,7 @@ public final class IntArrayTag extends Tag { } String name = getName(); String append = ""; - if (name != null && !name.equals("")) { + if (name != null && !name.isEmpty()) { append = "(\"" + getName() + "\")"; } return "TAG_Int_Array" + append + ": " + hex; diff --git a/Core/src/main/java/com/intellectualcrafters/jnbt/IntTag.java b/Core/src/main/java/com/intellectualcrafters/jnbt/IntTag.java index 349c0d57b..da15b74f8 100644 --- a/Core/src/main/java/com/intellectualcrafters/jnbt/IntTag.java +++ b/Core/src/main/java/com/intellectualcrafters/jnbt/IntTag.java @@ -36,7 +36,7 @@ public final class IntTag extends Tag { public String toString() { String name = getName(); String append = ""; - if (name != null && !name.equals("")) { + if (name != null && !name.isEmpty()) { append = "(\"" + getName() + "\")"; } return "TAG_Int" + append + ": " + this.value; diff --git a/Core/src/main/java/com/intellectualcrafters/jnbt/ListTag.java b/Core/src/main/java/com/intellectualcrafters/jnbt/ListTag.java index 8eda20d3c..c81add4ec 100644 --- a/Core/src/main/java/com/intellectualcrafters/jnbt/ListTag.java +++ b/Core/src/main/java/com/intellectualcrafters/jnbt/ListTag.java @@ -378,7 +378,7 @@ public final class ListTag extends Tag { public String toString() { String name = getName(); String append = ""; - if (name != null && !name.equals("")) { + if (name != null && !name.isEmpty()) { append = "(\"" + getName() + "\")"; } StringBuilder bldr = new StringBuilder(); diff --git a/Core/src/main/java/com/intellectualcrafters/jnbt/ListTagBuilder.java b/Core/src/main/java/com/intellectualcrafters/jnbt/ListTagBuilder.java index 32a95d355..0a0d2531a 100644 --- a/Core/src/main/java/com/intellectualcrafters/jnbt/ListTagBuilder.java +++ b/Core/src/main/java/com/intellectualcrafters/jnbt/ListTagBuilder.java @@ -23,7 +23,7 @@ public class ListTagBuilder { ListTagBuilder(Class type) { checkNotNull(type); this.type = type; - this.entries = new ArrayList(); + this.entries = new ArrayList<>(); } /** diff --git a/Core/src/main/java/com/intellectualcrafters/jnbt/LongTag.java b/Core/src/main/java/com/intellectualcrafters/jnbt/LongTag.java index ce91cc0ef..422a4a9de 100644 --- a/Core/src/main/java/com/intellectualcrafters/jnbt/LongTag.java +++ b/Core/src/main/java/com/intellectualcrafters/jnbt/LongTag.java @@ -36,7 +36,7 @@ public final class LongTag extends Tag { public String toString() { String name = getName(); String append = ""; - if (name != null && !name.equals("")) { + if (name != null && !name.isEmpty()) { append = "(\"" + getName() + "\")"; } return "TAG_Long" + append + ": " + this.value; diff --git a/Core/src/main/java/com/intellectualcrafters/jnbt/ShortTag.java b/Core/src/main/java/com/intellectualcrafters/jnbt/ShortTag.java index c368282d3..df96b425e 100644 --- a/Core/src/main/java/com/intellectualcrafters/jnbt/ShortTag.java +++ b/Core/src/main/java/com/intellectualcrafters/jnbt/ShortTag.java @@ -36,7 +36,7 @@ public final class ShortTag extends Tag { public String toString() { String name = getName(); String append = ""; - if (name != null && !name.equals("")) { + if (name != null && !name.isEmpty()) { append = "(\"" + getName() + "\")"; } return "TAG_Short" + append + ": " + this.value; diff --git a/Core/src/main/java/com/intellectualcrafters/jnbt/StringTag.java b/Core/src/main/java/com/intellectualcrafters/jnbt/StringTag.java index 1f8ceb123..0360715c0 100644 --- a/Core/src/main/java/com/intellectualcrafters/jnbt/StringTag.java +++ b/Core/src/main/java/com/intellectualcrafters/jnbt/StringTag.java @@ -40,7 +40,7 @@ public final class StringTag extends Tag { public String toString() { String name = getName(); String append = ""; - if (name != null && !name.equals("")) { + if (name != null && !name.isEmpty()) { append = "(\"" + getName() + "\")"; } return "TAG_String" + append + ": " + this.value; diff --git a/Core/src/main/java/com/intellectualcrafters/json/JSONObject.java b/Core/src/main/java/com/intellectualcrafters/json/JSONObject.java index 768032038..1cb9f55d8 100644 --- a/Core/src/main/java/com/intellectualcrafters/json/JSONObject.java +++ b/Core/src/main/java/com/intellectualcrafters/json/JSONObject.java @@ -1330,7 +1330,7 @@ public class JSONObject { } } return true; - } catch (Throwable exception) { + } catch (JSONException exception) { return false; } } diff --git a/Core/src/main/java/com/intellectualcrafters/json/JSONString.java b/Core/src/main/java/com/intellectualcrafters/json/JSONString.java index 2cf8273a9..231506795 100644 --- a/Core/src/main/java/com/intellectualcrafters/json/JSONString.java +++ b/Core/src/main/java/com/intellectualcrafters/json/JSONString.java @@ -12,5 +12,5 @@ public interface JSONString { * * @return A strictly syntactically correct JSON text. */ - public String toJSONString(); + String toJSONString(); } diff --git a/Core/src/main/java/com/intellectualcrafters/json/JSONTokener.java b/Core/src/main/java/com/intellectualcrafters/json/JSONTokener.java index 0563977b4..fa23fb91d 100644 --- a/Core/src/main/java/com/intellectualcrafters/json/JSONTokener.java +++ b/Core/src/main/java/com/intellectualcrafters/json/JSONTokener.java @@ -342,7 +342,7 @@ public class JSONTokener { } back(); string = sb.toString().trim(); - if (string != null && string.isEmpty()) { + if (string.isEmpty()) { throw syntaxError("Missing value"); } return JSONObject.stringToValue(string); @@ -370,7 +370,7 @@ public class JSONTokener { index = startIndex; character = startCharacter; line = startLine; - return c; + return 0; } } while (c != to); } catch (final IOException exception) { diff --git a/Core/src/main/java/com/intellectualcrafters/plot/PS.java b/Core/src/main/java/com/intellectualcrafters/plot/PS.java index 2273590c0..0007d967b 100644 --- a/Core/src/main/java/com/intellectualcrafters/plot/PS.java +++ b/Core/src/main/java/com/intellectualcrafters/plot/PS.java @@ -137,7 +137,7 @@ public class PS { try { URL url = PS.class.getProtectionDomain().getCodeSource().getLocation(); this.file = new File(new URL(url.toURI().toString().split("\\!")[0].replaceAll("jar:file", "file")).toURI().getPath()); - } catch (MalformedURLException | URISyntaxException | SecurityException | NullPointerException e) { + } catch (MalformedURLException | URISyntaxException | SecurityException e) { e.printStackTrace(); this.file = new File(this.IMP.getDirectory().getParentFile(), "PlotSquared.jar"); if (!this.file.exists()) { @@ -489,11 +489,10 @@ public class PS { return areas[0]; } else if (id == null) { return null; - } else { - for (PlotArea area : areas) { - if (StringMan.isEqual(id, area.id)) { - return area; - } + } + for (PlotArea area : areas) { + if (StringMan.isEqual(id, area.id)) { + return area; } } return null; @@ -1474,7 +1473,7 @@ public class PS { return; } if (type == 1) { - throw new IllegalArgumentException("Invalid type for multi-area world. Expected `2`, got `" + type + "`"); + throw new IllegalArgumentException("Invalid type for multi-area world. Expected `2`, got `" + 1 + "`"); } for (String areaId : areasSection.getKeys(false)) { PS.log(C.PREFIX + "&3 - " + areaId); diff --git a/Core/src/main/java/com/intellectualcrafters/plot/commands/Area.java b/Core/src/main/java/com/intellectualcrafters/plot/commands/Area.java index c58954355..21c4fb848 100644 --- a/Core/src/main/java/com/intellectualcrafters/plot/commands/Area.java +++ b/Core/src/main/java/com/intellectualcrafters/plot/commands/Area.java @@ -112,7 +112,7 @@ public class Area extends SubCommand { object.plotManager = "PlotSquared"; object.setupGenerator = "PlotSquared"; object.step = area.getSettingNodes(); - final String path = "worlds." + area.worldname + ".areas." + area.id + "-" + object.min + "-" + object.max; + final String path = "worlds." + area.worldname + ".areas." + area.id + '-' + object.min + '-' + object.max; Runnable run = new Runnable() { @Override public void run() { @@ -254,7 +254,7 @@ public class Area extends SubCommand { } }; if (hasConfirmation(player)) { - CmdConfirm.addPending(player, getCommandString() + " " + StringMan.join(args, " "), run); + CmdConfirm.addPending(player, getCommandString() + ' ' + StringMan.join(args, " "), run); } else { run.run(); } @@ -310,11 +310,11 @@ public class Area extends SubCommand { int claimed = area.getPlotCount(); int clusters = area.getClusters().size(); String region; - String generator = area.getGenerator() + ""; + String generator = String.valueOf(area.getGenerator()); if (area.TYPE == 2) { PlotId min = area.getMin(); PlotId max = area.getMax(); - name = area.worldname + ";" + area.id + ";" + min + ";" + max; + name = area.worldname + ';' + area.id + ';' + min + ';' + max; int size = (max.x - min.x + 1) * (max.y - min.y + 1); percent = claimed == 0 ? 0 : size / (double) claimed; region = area.getRegion().toString(); @@ -326,7 +326,7 @@ public class Area extends SubCommand { String value = "&r$1NAME: " + name + "\n$1Type: $2" + area.TYPE + "\n$1Terrain: $2" + area.TERRAIN - + "\n$1Usage: $2" + String.format("%.2f", percent) + "%" + + "\n$1Usage: $2" + String.format("%.2f", percent) + '%' + "\n$1Claimed: $2" + claimed + "\n$1Clusters: $2" + clusters + "\n$1Region: $2" + region @@ -363,11 +363,11 @@ public class Area extends SubCommand { int claimed = area.getPlotCount(); int clusters = area.getClusters().size(); String region; - String generator = area.getGenerator() + ""; + String generator = String.valueOf(area.getGenerator()); if (area.TYPE == 2) { PlotId min = area.getMin(); PlotId max = area.getMax(); - name = area.worldname + ";" + area.id + ";" + min + ";" + max; + name = area.worldname + ';' + area.id + ';' + min + ';' + max; int size = (max.x - min.x + 1) * (max.y - min.y + 1); percent = claimed == 0 ? 0 : size / (double) claimed; region = area.getRegion().toString(); @@ -377,18 +377,18 @@ public class Area extends SubCommand { region = "N/A"; } PlotMessage tooltip = new PlotMessage() - .text("Claimed=").color("$1").text("" + claimed).color("$2") - .text("\nUsage=").color("$1").text(String.format("%.2f", percent) + "%").color("$2") - .text("\nClusters=").color("$1").text("" + clusters).color("$2") + .text("Claimed=").color("$1").text(String.valueOf(claimed)).color("$2") + .text("\nUsage=").color("$1").text(String.format("%.2f", percent) + '%').color("$2") + .text("\nClusters=").color("$1").text(String.valueOf(clusters)).color("$2") .text("\nRegion=").color("$1").text(region).color("$2") .text("\nGenerator=").color("$1").text(generator).color("$2"); // type / terrain String visit = "/plot area tp " + area.toString(); message.text("[").color("$3") - .text(i + "").command(visit).tooltip(visit).color("$1") + .text(String.valueOf(i)).command(visit).tooltip(visit).color("$1") .text("]").color("$3") - .text(" " + name).tooltip(tooltip).command(getCommandString() + " info " + area).color("$1").text(" - ") + .text(' ' + name).tooltip(tooltip).command(getCommandString() + " info " + area).color("$1").text(" - ") .color("$2") .text(area.TYPE + ":" + area.TERRAIN).color("$3"); } diff --git a/Core/src/main/java/com/intellectualcrafters/plot/commands/Auto.java b/Core/src/main/java/com/intellectualcrafters/plot/commands/Auto.java index ac370bfb3..041368a0f 100644 --- a/Core/src/main/java/com/intellectualcrafters/plot/commands/Auto.java +++ b/Core/src/main/java/com/intellectualcrafters/plot/commands/Auto.java @@ -72,7 +72,7 @@ public class Auto extends SubCommand { if (args.length > 1) { schematic = args[1]; } - } catch (NumberFormatException e) { + } catch (NumberFormatException ignored) { size_x = 1; size_z = 1; schematic = args[0]; diff --git a/Core/src/main/java/com/intellectualcrafters/plot/commands/DebugClaimTest.java b/Core/src/main/java/com/intellectualcrafters/plot/commands/DebugClaimTest.java index 3f0bfc80a..104920752 100644 --- a/Core/src/main/java/com/intellectualcrafters/plot/commands/DebugClaimTest.java +++ b/Core/src/main/java/com/intellectualcrafters/plot/commands/DebugClaimTest.java @@ -92,7 +92,7 @@ public class DebugClaimTest extends SubCommand { } if (uuid != null) { MainUtil.sendMessage(plr, " - &aFound plot: " + plot.getId() + " : " + line); - plot.owner = uuid; + plot.setOwner(uuid); plots.add(plot); } else { MainUtil.sendMessage(plr, " - &cInvalid PlayerName: " + plot.getId() + " : " + line); diff --git a/Core/src/main/java/com/intellectualcrafters/plot/commands/FlagCmd.java b/Core/src/main/java/com/intellectualcrafters/plot/commands/FlagCmd.java index ef0797fe4..d8dc726c4 100644 --- a/Core/src/main/java/com/intellectualcrafters/plot/commands/FlagCmd.java +++ b/Core/src/main/java/com/intellectualcrafters/plot/commands/FlagCmd.java @@ -31,11 +31,6 @@ import java.util.Map; permission = "plots.flag") public class FlagCmd extends SubCommand { - @Override - public String getUsage() { - return super.getUsage(); - } - @Override public boolean onCommand(PlotPlayer player, String[] args) { diff --git a/Core/src/main/java/com/intellectualcrafters/plot/commands/GenerateDocs.java b/Core/src/main/java/com/intellectualcrafters/plot/commands/GenerateDocs.java index 53035ddb6..468e63252 100644 --- a/Core/src/main/java/com/intellectualcrafters/plot/commands/GenerateDocs.java +++ b/Core/src/main/java/com/intellectualcrafters/plot/commands/GenerateDocs.java @@ -5,6 +5,7 @@ import com.intellectualcrafters.plot.util.StringMan; import com.plotsquared.general.commands.Command; import java.io.File; +import java.io.IOException; import java.nio.charset.StandardCharsets; import java.nio.file.Files; import java.util.ArrayList; @@ -58,7 +59,7 @@ public class GenerateDocs { String comment = GenerateDocs.getComments(lines); GenerateDocs.log("#### Description"); - GenerateDocs.log("`" + command.getDescription() + "`"); + GenerateDocs.log('`' + command.getDescription() + '`'); if (!comment.isEmpty()) { GenerateDocs.log("##### Comments"); GenerateDocs.log("``` java"); @@ -76,18 +77,18 @@ public class GenerateDocs { GenerateDocs.log(" - `" + StringMan.join(usages, "`\n - `") + "` "); GenerateDocs.log(""); } else { - GenerateDocs.log("`" + mainUsage + "` "); + GenerateDocs.log('`' + mainUsage + "` "); } if (command.getRequiredType() != RequiredType.NONE) { GenerateDocs.log("#### Required callers"); - GenerateDocs.log("`" + command.getRequiredType().name() + "`"); + GenerateDocs.log('`' + command.getRequiredType().name() + '`'); } List aliases = command.getAliases(); if (!aliases.isEmpty()) { GenerateDocs.log("#### Aliases"); - GenerateDocs.log("`" + StringMan.getString(command.getAliases()) + "`"); + GenerateDocs.log('`' + StringMan.getString(command.getAliases()) + '`'); } GenerateDocs.log("#### Permissions"); @@ -96,21 +97,21 @@ public class GenerateDocs { GenerateDocs.log(" - `" + command.getPermission() + "` "); GenerateDocs.log(""); GenerateDocs.log("##### Other"); - GenerateDocs.log(" - `" + StringMan.join(perms, "`\n - `") + "`"); + GenerateDocs.log(" - `" + StringMan.join(perms, "`\n - `") + '`'); GenerateDocs.log(""); } else { - GenerateDocs.log("`" + command.getPermission() + "` "); + GenerateDocs.log('`' + command.getPermission() + "` "); } GenerateDocs.log("***"); GenerateDocs.log(""); - } catch (Exception e) { + } catch (IOException e) { e.printStackTrace(); } } public static List getUsage(String cmd, List lines) { Pattern p = Pattern.compile("\"([^\"]*)\""); - HashSet usages = new HashSet(); + HashSet usages = new HashSet<>(); for (String line : lines) { if (line.contains("COMMAND_SYNTAX") && !line.contains("getUsage()")) { Matcher m = p.matcher(line); @@ -203,7 +204,7 @@ public class GenerateDocs { line = line.trim(); if (line.startsWith("/** ") || line.startsWith("*/ ") || line.startsWith("* ")) { line = line.replaceAll("/[*][*] ", "").replaceAll("[*]/ ", "").replaceAll("[*] ", "").trim(); - result.append(line + "\n"); + result.append(line + '\n'); } } return result.toString().trim(); diff --git a/Core/src/main/java/com/intellectualcrafters/plot/commands/ListCmd.java b/Core/src/main/java/com/intellectualcrafters/plot/commands/ListCmd.java index c67c53e51..69d1c5961 100644 --- a/Core/src/main/java/com/intellectualcrafters/plot/commands/ListCmd.java +++ b/Core/src/main/java/com/intellectualcrafters/plot/commands/ListCmd.java @@ -245,12 +245,10 @@ public class ListCmd extends SubCommand { } plots = new ArrayList<>(); for (Plot plot : PS.get().getPlots()) { -/* - Flag price = FlagManager.getPlotFlagRaw(plot, "price"); - if (price != null) { + Optional price = plot.getFlag(Flags.PRICE); + if (price.isPresent()) { plots.add(plot); } -*/ } break; case "unowned": diff --git a/Core/src/main/java/com/intellectualcrafters/plot/commands/Merge.java b/Core/src/main/java/com/intellectualcrafters/plot/commands/Merge.java index 3dcb50e64..d10c3887e 100644 --- a/Core/src/main/java/com/intellectualcrafters/plot/commands/Merge.java +++ b/Core/src/main/java/com/intellectualcrafters/plot/commands/Merge.java @@ -14,7 +14,6 @@ import com.intellectualcrafters.plot.util.StringMan; import com.intellectualcrafters.plot.util.UUIDHandler; import com.plotsquared.general.commands.CommandDeclaration; -import java.util.HashSet; import java.util.UUID; @CommandDeclaration(command = "merge", @@ -74,7 +73,7 @@ public class Merge extends SubCommand { final PlotArea plotworld = plot.getArea(); final double price = plotworld.PRICES.containsKey("merge") ? plotworld.PRICES.get("merge") : 0; if (EconHandler.manager != null && plotworld.USE_ECONOMY && price > 0d && EconHandler.manager.getMoney(plr) < price) { - sendMessage(plr, C.CANNOT_AFFORD_MERGE, price + ""); + sendMessage(plr, C.CANNOT_AFFORD_MERGE, String.valueOf(price)); return false; } final int size = plot.getConnectedPlots().size(); @@ -108,7 +107,7 @@ public class Merge extends SubCommand { if (plot.autoMerge(-1, maxSize, uuid, terrain)) { if (EconHandler.manager != null && plotworld.USE_ECONOMY && price > 0d) { EconHandler.manager.withdrawMoney(plr, price); - sendMessage(plr, C.REMOVED_BALANCE, price + ""); + sendMessage(plr, C.REMOVED_BALANCE, String.valueOf(price)); } MainUtil.sendMessage(plr, C.SUCCESS_MERGE); return true; @@ -138,7 +137,7 @@ public class Merge extends SubCommand { if (plot.autoMerge(direction, maxSize - size, uuid, terrain)) { if (EconHandler.manager != null && plotworld.USE_ECONOMY && price > 0d) { EconHandler.manager.withdrawMoney(plr, price); - sendMessage(plr, C.REMOVED_BALANCE, price + ""); + sendMessage(plr, C.REMOVED_BALANCE, String.valueOf(price)); } MainUtil.sendMessage(plr, C.SUCCESS_MERGE); return true; @@ -152,7 +151,7 @@ public class Merge extends SubCommand { MainUtil.sendMessage(plr, C.NO_PERMISSION, C.PERMISSION_MERGE_OTHER); return false; } - HashSet uuids = adjacent.getOwners(); + java.util.Set uuids = adjacent.getOwners(); boolean isOnline = false; for (final UUID owner : uuids) { final PlotPlayer accepter = UUIDHandler.getPlayer(owner); @@ -173,11 +172,11 @@ public class Merge extends SubCommand { } if (EconHandler.manager != null && plotworld.USE_ECONOMY && price > 0d) { if (EconHandler.manager.getMoney(plr) < price) { - sendMessage(plr, C.CANNOT_AFFORD_MERGE, price + ""); + sendMessage(plr, C.CANNOT_AFFORD_MERGE, String.valueOf(price)); return; } EconHandler.manager.withdrawMoney(plr, price); - sendMessage(plr, C.REMOVED_BALANCE, price + ""); + sendMessage(plr, C.REMOVED_BALANCE, String.valueOf(price)); } MainUtil.sendMessage(plr, C.SUCCESS_MERGE); } diff --git a/Core/src/main/java/com/intellectualcrafters/plot/commands/RegenAllRoads.java b/Core/src/main/java/com/intellectualcrafters/plot/commands/RegenAllRoads.java index 7b8f4e515..d33726f07 100644 --- a/Core/src/main/java/com/intellectualcrafters/plot/commands/RegenAllRoads.java +++ b/Core/src/main/java/com/intellectualcrafters/plot/commands/RegenAllRoads.java @@ -47,7 +47,7 @@ public class RegenAllRoads extends SubCommand { } String name = args[0]; PlotManager manager = area.getPlotManager(); - if ((manager == null) || !(manager instanceof HybridPlotManager)) { + if (!(manager instanceof HybridPlotManager)) { MainUtil.sendMessage(plr, C.NOT_VALID_PLOT_WORLD); return false; } diff --git a/Core/src/main/java/com/intellectualcrafters/plot/commands/Setup.java b/Core/src/main/java/com/intellectualcrafters/plot/commands/Setup.java index 5fff60ec7..b46793554 100644 --- a/Core/src/main/java/com/intellectualcrafters/plot/commands/Setup.java +++ b/Core/src/main/java/com/intellectualcrafters/plot/commands/Setup.java @@ -65,8 +65,8 @@ public class Setup extends SubCommand { if (object.setup_index > 0) { object.setup_index--; ConfigurationNode node = object.step[object.setup_index]; - sendMessage(plr, C.SETUP_STEP, object.setup_index + 1 + "", node.getDescription(), node.getType().getType(), - node.getDefaultValue() + ""); + sendMessage(plr, C.SETUP_STEP, object.setup_index + 1, node.getDescription(), node.getType().getType(), + String.valueOf(node.getDefaultValue())); return false; } else if (object.current > 0) { object.current--; @@ -127,8 +127,8 @@ public class Setup extends SubCommand { return true; } ConfigurationNode step = object.step[object.setup_index]; - sendMessage(plr, C.SETUP_STEP, object.setup_index + 1 + "", step.getDescription(), step.getType().getType(), - step.getDefaultValue() + ""); + sendMessage(plr, C.SETUP_STEP, object.setup_index + 1, step.getDescription(), step.getType().getType(), + String.valueOf(step.getDefaultValue())); } else { if (gen.isFull()) { object.plotManager = object.setupGenerator; @@ -216,8 +216,8 @@ public class Setup extends SubCommand { .getNewPlotArea("CheckingPlotSquaredGenerator", null, null, null).getSettingNodes(); } ConfigurationNode step = object.step[object.setup_index]; - sendMessage(plr, C.SETUP_STEP, object.setup_index + 1 + "", step.getDescription(), step.getType().getType(), - step.getDefaultValue() + ""); + sendMessage(plr, C.SETUP_STEP, object.setup_index + 1, step.getDescription(), step.getType().getType(), + String.valueOf(step.getDefaultValue())); break; } case 6: // world setup @@ -229,8 +229,8 @@ public class Setup extends SubCommand { } ConfigurationNode step = object.step[object.setup_index]; if (args.length < 1) { - sendMessage(plr, C.SETUP_STEP, object.setup_index + 1 + "", step.getDescription(), step.getType().getType(), - step.getDefaultValue() + ""); + sendMessage(plr, C.SETUP_STEP, object.setup_index + 1, step.getDescription(), step.getType().getType(), + String.valueOf(step.getDefaultValue())); return false; } boolean valid = step.isValid(args[0]); @@ -243,13 +243,13 @@ public class Setup extends SubCommand { return false; } step = object.step[object.setup_index]; - sendMessage(plr, C.SETUP_STEP, object.setup_index + 1 + "", step.getDescription(), step.getType().getType(), - step.getDefaultValue() + ""); + sendMessage(plr, C.SETUP_STEP, object.setup_index + 1, step.getDescription(), step.getType().getType(), + String.valueOf(step.getDefaultValue())); return false; } else { sendMessage(plr, C.SETUP_INVALID_ARG, args[0], step.getConstant()); - sendMessage(plr, C.SETUP_STEP, object.setup_index + 1 + "", step.getDescription(), step.getType().getType(), - step.getDefaultValue() + ""); + sendMessage(plr, C.SETUP_STEP, object.setup_index + 1, step.getDescription(), step.getType().getType(), + String.valueOf(step.getDefaultValue())); return false; } case 7: diff --git a/Core/src/main/java/com/intellectualcrafters/plot/commands/Update.java b/Core/src/main/java/com/intellectualcrafters/plot/commands/Update.java index 29c180ec6..f9dd378dc 100644 --- a/Core/src/main/java/com/intellectualcrafters/plot/commands/Update.java +++ b/Core/src/main/java/com/intellectualcrafters/plot/commands/Update.java @@ -41,7 +41,7 @@ public class Update extends SubCommand { MainUtil.sendMessage(plr, "&cTo manually specify an update URL: /plot update "); return false; } - if (PS.get().update(null, url) && (url == PS.get().update)) { + if (PS.get().update(plr, url) && (url == PS.get().update)) { PS.get().update = null; } return true; diff --git a/Core/src/main/java/com/intellectualcrafters/plot/config/C.java b/Core/src/main/java/com/intellectualcrafters/plot/config/C.java index c3abd620e..18433c84e 100644 --- a/Core/src/main/java/com/intellectualcrafters/plot/config/C.java +++ b/Core/src/main/java/com/intellectualcrafters/plot/config/C.java @@ -7,6 +7,7 @@ import com.intellectualcrafters.plot.util.StringMan; import com.plotsquared.general.commands.CommandCaller; import java.io.File; +import java.io.IOException; import java.util.EnumSet; import java.util.HashMap; import java.util.HashSet; @@ -730,7 +731,7 @@ public enum C { if (!split[0].equalsIgnoreCase(caption.category)) { changed = true; yml.set(key, null); - yml.set(caption.category + "." + caption.name().toLowerCase(), value); + yml.set(caption.category + '.' + caption.name().toLowerCase(), value); } captions.add(caption); caption.s = value; @@ -747,7 +748,7 @@ public enum C { // HashMap replacements = new HashMap<>(); replacements.clear(); for (String style : styles) { - replacements.put("$" + style, "\u00a7" + config.getString(style)); + replacements.put('$' + style, '§' + config.getString(style)); } for (char letter : "1234567890abcdefklmnor".toCharArray()) { replacements.put("&" + letter, "\u00a7" + letter); @@ -761,14 +762,14 @@ public enum C { continue; } changed = true; - yml.set(caption.category + "." + caption.name().toLowerCase(), caption.def); + yml.set(caption.category + '.' + caption.name().toLowerCase(), caption.def); } caption.s = StringMan.replaceFromMap(caption.s, replacements); } if (changed) { yml.save(file); } - } catch (Exception e) { + } catch (IOException | IllegalArgumentException e) { e.printStackTrace(); } } diff --git a/Core/src/main/java/com/intellectualcrafters/plot/config/Configuration.java b/Core/src/main/java/com/intellectualcrafters/plot/config/Configuration.java index 09d91043c..e1545b98e 100644 --- a/Core/src/main/java/com/intellectualcrafters/plot/config/Configuration.java +++ b/Core/src/main/java/com/intellectualcrafters/plot/config/Configuration.java @@ -41,7 +41,7 @@ public class Configuration { try { Integer.parseInt(string); return true; - } catch (Exception e) { + } catch (NumberFormatException ignored) { return false; } } @@ -54,12 +54,8 @@ public class Configuration { public static final SettingValue BOOLEAN = new SettingValue("BOOLEAN") { @Override public boolean validateValue(String string) { - try { - Boolean.parseBoolean(string); - return true; - } catch (Exception e) { - return false; - } + Boolean.parseBoolean(string); + return true; } @Override @@ -73,7 +69,7 @@ public class Configuration { try { Double.parseDouble(string); return true; - } catch (Exception e) { + } catch (NumberFormatException ignored) { return false; } } @@ -89,7 +85,7 @@ public class Configuration { try { int biome = WorldUtil.IMP.getBiomeFromString(string.toUpperCase()); return biome != -1; - } catch (Exception e) { + } catch (Exception ignored) { return false; } } @@ -134,7 +130,7 @@ public class Configuration { } } return true; - } catch (NumberFormatException e) { + } catch (NumberFormatException ignored) { return false; } } diff --git a/Core/src/main/java/com/intellectualcrafters/plot/database/SQLManager.java b/Core/src/main/java/com/intellectualcrafters/plot/database/SQLManager.java index 0cd6a5a2c..eb9f1c904 100644 --- a/Core/src/main/java/com/intellectualcrafters/plot/database/SQLManager.java +++ b/Core/src/main/java/com/intellectualcrafters/plot/database/SQLManager.java @@ -40,6 +40,7 @@ import java.util.concurrent.ConcurrentLinkedQueue; import java.util.concurrent.atomic.AtomicInteger; +@SuppressWarnings("SqlDialectInspection") public class SQLManager implements AbstractDB { // Public final @@ -173,7 +174,7 @@ public class SQLManager implements AbstractDB { this.plotTasks.put(plot, tasks); } if (task == null) { - task = new UniqueStatement(plot.hashCode() + "") { + task = new UniqueStatement(String.valueOf(plot.hashCode())) { @Override public PreparedStatement get() { @@ -207,7 +208,7 @@ public class SQLManager implements AbstractDB { this.playerTasks.put(uuid, tasks); } if (task == null) { - task = new UniqueStatement(uuid.hashCode() + "") { + task = new UniqueStatement(String.valueOf(uuid.hashCode())) { @Override public PreparedStatement get() { @@ -238,7 +239,7 @@ public class SQLManager implements AbstractDB { this.clusterTasks.put(cluster, tasks); } if (task == null) { - task = new UniqueStatement(cluster.hashCode() + "") { + task = new UniqueStatement(String.valueOf(cluster.hashCode())) { @Override public PreparedStatement get() { @@ -397,7 +398,8 @@ public class SQLManager implements AbstractDB { if (count > 0) { commit(); return true; - } else if (count != -1) { + } + if (count != -1) { if (!this.connection.getAutoCommit()) { this.connection.setAutoCommit(true); } @@ -611,7 +613,7 @@ public class SQLManager implements AbstractDB { stmt.setInt(i * 5 + 2, plot.getId().y); try { stmt.setString(i * 5 + 3, plot.owner.toString()); - } catch (SQLException e) { + } catch (SQLException ignored) { stmt.setString(i * 5 + 3, AbstractDB.everyone.toString()); } stmt.setString(i * 5 + 4, plot.getArea().toString()); @@ -625,7 +627,7 @@ public class SQLManager implements AbstractDB { stmt.setInt(i * 6 + 3, plot.getId().y); try { stmt.setString(i * 6 + 4, plot.owner.toString()); - } catch (SQLException e1) { + } catch (SQLException ignored) { stmt.setString(i * 6 + 4, AbstractDB.everyone.toString()); } stmt.setString(i * 6 + 5, plot.getArea().toString()); @@ -742,18 +744,15 @@ public class SQLManager implements AbstractDB { PS.debug("&6[WARN] Could not bulk save!"); try { String nonBulk = mod.getCreateSQL(); - PreparedStatement preparedStmt = this.connection.prepareStatement(nonBulk); - for (T obj : objList) { - try { + try (PreparedStatement preparedStmt = this.connection.prepareStatement(nonBulk)) { + for (T obj : objList) { mod.setSQL(preparedStmt, obj); preparedStmt.addBatch(); - } catch (SQLException e3) { - PS.debug("&c[ERROR] Failed to save " + obj + "!"); } + PS.debug("&aBatch 3"); + preparedStmt.executeBatch(); + preparedStmt.close(); } - PS.debug("&aBatch 3"); - preparedStmt.executeBatch(); - preparedStmt.close(); } catch (SQLException e3) { e3.printStackTrace(); PS.debug("&c[ERROR] Failed to save all!"); @@ -807,9 +806,9 @@ public class SQLManager implements AbstractDB { int k = 0; for (Entry, ?> flag : pair.settings.flags.entrySet()) { if (k != 0) { - flag_string.append(","); + flag_string.append(','); } - flag_string.append(flag.getKey().getName() + ":" + flag.getKey().valueToString(flag.getValue()).replaceAll(":", "¯") + flag_string.append(flag.getKey().getName() + ':' + flag.getKey().valueToString(flag.getValue()).replaceAll(":", "¯") .replaceAll(",", "´")); k++; } @@ -822,7 +821,7 @@ public class SQLManager implements AbstractDB { if (loc.y == 0) { position = "DEFAULT"; } else { - position = loc.x + "," + loc.y + "," + loc.z; + position = loc.x + "," + loc.y + ',' + loc.z; } statement.setString(i * 10 + 10, position); } @@ -844,9 +843,9 @@ public class SQLManager implements AbstractDB { int k = 0; for (Entry, ?> flag : pair.settings.flags.entrySet()) { if (k != 0) { - flag_string.append(","); + flag_string.append(','); } - flag_string.append(flag.getKey().getName() + ":" + flag.getKey().valueToString(flag.getValue()).replaceAll(":", "¯") + flag_string.append(flag.getKey().getName() + ':' + flag.getKey().valueToString(flag.getValue()).replaceAll(":", "¯") .replaceAll(",", "´")); k++; } @@ -862,7 +861,7 @@ public class SQLManager implements AbstractDB { if (loc.y == 0) { position = "DEFAULT"; } else { - position = loc.x + "," + loc.y + "," + loc.z; + position = loc.x + "," + loc.y + ',' + loc.z; } stmt.setString(i * 10 + 10, position); } @@ -960,10 +959,10 @@ public class SQLManager implements AbstractDB { } public void commit() { + if (this.closed) { + return; + } try { - if (this.closed) { - return; - } if (!this.connection.getAutoCommit()) { this.connection.commit(); this.connection.setAutoCommit(true); @@ -992,7 +991,6 @@ public class SQLManager implements AbstractDB { @Override public void execute(PreparedStatement statement) { - } @Override @@ -1181,7 +1179,7 @@ public class SQLManager implements AbstractDB { + "`comment` VARCHAR(40) NOT NULL," + "`inbox` VARCHAR(40) NOT NULL, `timestamp` INT(11) NOT NULL," + "`sender` VARCHAR(40) NOT NULL" - + ")"); + + ')'); stmt.addBatch("CREATE TABLE IF NOT EXISTS `" + this.prefix + "plot_settings` (" @@ -1196,7 +1194,7 @@ public class SQLManager implements AbstractDB { + " `merged` INT(11) DEFAULT NULL," + " `position` VARCHAR(50) NOT NULL DEFAULT 'DEFAULT'," + " PRIMARY KEY (`plot_plot_id`)" - + ")"); + + ')'); stmt.addBatch("CREATE TABLE IF NOT EXISTS `" + this.prefix + "plot_rating` (`plot_plot_id` INT(11) NOT NULL, `rating` INT(2) NOT NULL, `player` VARCHAR(40) NOT NULL)"); stmt.addBatch("CREATE TABLE IF NOT EXISTS `" @@ -1210,7 +1208,7 @@ public class SQLManager implements AbstractDB { + "`owner` VARCHAR(40) NOT NULL," + "`world` VARCHAR(45) NOT NULL," + "`timestamp` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP" - + ")"); + + ')'); stmt.addBatch("CREATE TABLE IF NOT EXISTS `" + this.prefix + "cluster_helpers` (`cluster_id` INT(11) NOT NULL," + "`user_uuid` VARCHAR(40) NOT NULL)"); stmt.addBatch("CREATE TABLE IF NOT EXISTS `" + this.prefix + "cluster_invited` (`cluster_id` INT(11) NOT NULL," @@ -1229,7 +1227,7 @@ public class SQLManager implements AbstractDB { + " `merged` INT(11) DEFAULT NULL," + " `position` VARCHAR(50) NOT NULL DEFAULT 'DEFAULT'," + " PRIMARY KEY (`cluster_id`)" - + ")"); + + ')'); stmt.addBatch("CREATE TABLE IF NOT EXISTS `" + this.prefix + "player_meta` (" @@ -1237,7 +1235,7 @@ public class SQLManager implements AbstractDB { + " `uuid` VARCHAR(40) NOT NULL," + " `key` VARCHAR(32) NOT NULL," + " `value` blob NOT NULL" - + ")"); + + ')'); } stmt.executeBatch(); stmt.clearBatch(); @@ -1411,21 +1409,22 @@ public class SQLManager implements AbstractDB { if (cluster.temp > 0) { return cluster.temp; } - PreparedStatement stmt = this.connection.prepareStatement("SELECT `id` FROM `" + int c_id; + try (PreparedStatement stmt = this.connection.prepareStatement("SELECT `id` FROM `" + this.prefix - + "cluster` WHERE `pos1_x` = ? AND `pos1_z` = ? AND `pos2_x` = ? AND `pos2_z` = ? AND `world` = ? ORDER BY `timestamp` ASC"); - stmt.setInt(1, cluster.getP1().x); - stmt.setInt(2, cluster.getP1().y); - stmt.setInt(3, cluster.getP2().x); - stmt.setInt(4, cluster.getP2().y); - stmt.setString(5, cluster.area.toString()); - ResultSet r = stmt.executeQuery(); - int c_id = Integer.MAX_VALUE; - while (r.next()) { - c_id = r.getInt("id"); + + "cluster` WHERE `pos1_x` = ? AND `pos1_z` = ? AND `pos2_x` = ? AND `pos2_z` = ? AND `world` = ? ORDER BY `timestamp` ASC")) { + stmt.setInt(1, cluster.getP1().x); + stmt.setInt(2, cluster.getP1().y); + stmt.setInt(3, cluster.getP2().x); + stmt.setInt(4, cluster.getP2().y); + stmt.setString(5, cluster.area.toString()); + try (ResultSet resultSet = stmt.executeQuery()) { + c_id = Integer.MAX_VALUE; + while (resultSet.next()) { + c_id = resultSet.getInt("id"); + } + } } - stmt.close(); - r.close(); if (c_id == Integer.MAX_VALUE || c_id == 0) { if (cluster.temp > 0) { return cluster.temp; @@ -1493,8 +1492,7 @@ public class SQLManager implements AbstractDB { rs = data.getColumns(null, null, this.prefix + "plot_comments", "hashcode"); if (!rs.next()) { rs.close(); - try { - Statement statement = this.connection.createStatement(); + try (Statement statement = this.connection.createStatement()) { statement.addBatch("DROP TABLE `" + this.prefix + "plot_comments`"); if (Settings.DB.USE_MYSQL) { statement.addBatch("CREATE TABLE IF NOT EXISTS `" @@ -1514,17 +1512,16 @@ public class SQLManager implements AbstractDB { + "`comment` VARCHAR(40) NOT NULL," + "`inbox` VARCHAR(40) NOT NULL, `timestamp` INT(11) NOT NULL," + "`sender` VARCHAR(40) NOT NULL" - + ")"); + + ')'); } statement.executeBatch(); - statement.close(); - } catch (SQLException e) { - Statement statement = this.connection.createStatement(); - statement.addBatch("ALTER IGNORE TABLE `" + this.prefix + "plot_comments` ADD `inbox` VARCHAR(11) DEFAULT `public`"); - statement.addBatch("ALTER IGNORE TABLE `" + this.prefix + "plot_comments` ADD `timestamp` INT(11) DEFAULT 0"); - statement.addBatch("ALTER TABLE `" + this.prefix + "plot` DROP `tier`"); - statement.executeBatch(); - statement.close(); + } catch (SQLException ignored) { + try (Statement statement = this.connection.createStatement()) { + statement.addBatch("ALTER IGNORE TABLE `" + this.prefix + "plot_comments` ADD `inbox` VARCHAR(11) DEFAULT `public`"); + statement.addBatch("ALTER IGNORE TABLE `" + this.prefix + "plot_comments` ADD `timestamp` INT(11) DEFAULT 0"); + statement.addBatch("ALTER TABLE `" + this.prefix + "plot` DROP `tier`"); + statement.executeBatch(); + } } } } @@ -1534,7 +1531,6 @@ public class SQLManager implements AbstractDB { try (Statement statement = this.connection.createStatement()) { statement.executeUpdate( "DELETE FROM `" + this.prefix + "plot_denied` WHERE `plot_plot_id` NOT IN (SELECT `id` FROM `" + this.prefix + "plot`)"); - statement.close(); } catch (SQLException e) { e.printStackTrace(); } @@ -1555,7 +1551,6 @@ public class SQLManager implements AbstractDB { PS.debug("RESTORING: " + this.prefix + table); } } - statement.close(); } catch (SQLException e2) { e2.printStackTrace(); } @@ -1620,7 +1615,7 @@ public class SQLManager implements AbstractDB { for (String areaKey : areaSection.getKeys(false)) { String[] split = areaKey.split("(? toDelete = new ArrayList<>(); - while (resultSet.next()) { - 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)) { - if (Settings.AUTO_PURGE) { - toDelete.add(id); - continue; - } else { - AtomicInteger value = noExist.get(areaid); - if (value != null) { - value.incrementAndGet(); - } else { - noExist.put(areaid, new AtomicInteger(1)); - } - } - } - o = resultSet.getString("owner"); - user = uuids.get(o); - if (user == null) { - user = UUID.fromString(o); - uuids.put(o, user); - } - Timestamp timestamp = resultSet.getTimestamp("timestamp"); - long time = timestamp.getTime(); - 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); - if (map != null) { - Plot last = map.put(p.getId(), p); - if (last != null) { - map.put(last.getId(), last); + try (Statement statement = this.connection.createStatement()) { + int id; + String o; + UUID user; + try (ResultSet resultSet = statement + .executeQuery("SELECT `id`, `plot_id_x`, `plot_id_z`, `owner`, `world`, `timestamp` FROM `" + this.prefix + "plot`")) { + ArrayList toDelete = new ArrayList<>(); + while (resultSet.next()) { + 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)) { if (Settings.AUTO_PURGE) { toDelete.add(id); + continue; } else { - PS.debug("&cPLOT " + id + " in `" + this.prefix - + "plot` is a duplicate. Delete this plot or set `auto-purge: true` in the settings.yml."); + AtomicInteger value = noExist.get(areaid); + if (value != null) { + value.incrementAndGet(); + } else { + noExist.put(areaid, new AtomicInteger(1)); + } } - continue; } - } else { - map = new HashMap<>(); - newPlots.put(areaid, map); - map.put(p.getId(), p); + o = resultSet.getString("owner"); + user = uuids.get(o); + if (user == null) { + user = UUID.fromString(o); + uuids.put(o, user); + } + Timestamp timestamp = resultSet.getTimestamp("timestamp"); + long time = timestamp.getTime(); + 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); + if (map != null) { + Plot last = map.put(p.getId(), p); + if (last != null) { + map.put(last.getId(), last); + if (Settings.AUTO_PURGE) { + toDelete.add(id); + } else { + PS.debug("&cPLOT " + id + " in `" + this.prefix + + "plot` is a duplicate. Delete this plot or set `auto-purge: true` in the settings.yml."); + } + continue; + } + } else { + map = new HashMap<>(); + newPlots.put(areaid, map); + map.put(p.getId(), p); + } + plots.put(id, p); } - plots.put(id, p); + deleteRows(toDelete, this.prefix + "plot", "id"); } - deleteRows(toDelete, this.prefix + "plot", "id"); - } - if (Settings.CACHE_RATINGS) { - try (ResultSet r = statement.executeQuery("SELECT `plot_plot_id`, `player`, `rating` FROM `" + this.prefix + "plot_rating`")) { + if (Settings.CACHE_RATINGS) { + try (ResultSet r = statement.executeQuery("SELECT `plot_plot_id`, `player`, `rating` FROM `" + this.prefix + "plot_rating`")) { + ArrayList toDelete = new ArrayList<>(); + while (r.next()) { + id = r.getInt("plot_plot_id"); + o = r.getString("player"); + user = uuids.get(o); + if (user == null) { + user = UUID.fromString(o); + uuids.put(o, user); + } + Plot plot = plots.get(id); + if (plot != null) { + plot.getSettings().getRatings().put(user, r.getInt("rating")); + } else if (Settings.AUTO_PURGE) { + toDelete.add(id); + } else { + PS.debug("&cENTRY " + id + " in `plot_rating` does not exist. Create this plot or set `auto-purge: true` in the " + + "settings.yml."); + } + } + deleteRows(toDelete, this.prefix + "plot_rating", "plot_plot_id"); + } + } + + /* + * Getting helpers + */ + try (ResultSet r = statement.executeQuery("SELECT `user_uuid`, `plot_plot_id` FROM `" + this.prefix + "plot_helpers`")) { ArrayList toDelete = new ArrayList<>(); while (r.next()) { id = r.getInt("plot_plot_id"); - o = r.getString("player"); + o = r.getString("user_uuid"); user = uuids.get(o); if (user == null) { user = UUID.fromString(o); @@ -1702,175 +1724,145 @@ public class SQLManager implements AbstractDB { } Plot plot = plots.get(id); if (plot != null) { - plot.getSettings().getRatings().put(user, r.getInt("rating")); + plot.getTrusted().add(user); } else if (Settings.AUTO_PURGE) { toDelete.add(id); } else { - PS.debug("&cENTRY " + id + " in `plot_rating` does not exist. Create this plot or set `auto-purge: true` in the " - + "settings.yml."); + PS.debug("&cENTRY " + id + " in `plot_helpers` does not exist. Create this plot or set `auto-purge: true` in the settings" + + ".yml."); } } - deleteRows(toDelete, this.prefix + "plot_rating", "plot_plot_id"); + deleteRows(toDelete, this.prefix + "plot_helpers", "plot_plot_id"); } - } - - /* - * Getting helpers - */ - try (ResultSet r = statement.executeQuery("SELECT `user_uuid`, `plot_plot_id` FROM `" + this.prefix + "plot_helpers`")) { - ArrayList toDelete = new ArrayList<>(); - while (r.next()) { - id = r.getInt("plot_plot_id"); - o = r.getString("user_uuid"); - user = uuids.get(o); - if (user == null) { - user = UUID.fromString(o); - uuids.put(o, user); - } - Plot plot = plots.get(id); - if (plot != null) { - plot.getTrusted().add(user); - } else if (Settings.AUTO_PURGE) { - toDelete.add(id); - } else { - PS.debug("&cENTRY " + id + " in `plot_helpers` does not exist. Create this plot or set `auto-purge: true` in the settings" - + ".yml."); - } - } - deleteRows(toDelete, this.prefix + "plot_helpers", "plot_plot_id"); - } /* * Getting trusted */ - try (ResultSet r = statement.executeQuery("SELECT `user_uuid`, `plot_plot_id` FROM `" + this.prefix + "plot_trusted`")) { - ArrayList toDelete = new ArrayList<>(); - while (r.next()) { - id = r.getInt("plot_plot_id"); - o = r.getString("user_uuid"); - user = uuids.get(o); - if (user == null) { - user = UUID.fromString(o); - uuids.put(o, user); - } - Plot plot = plots.get(id); - if (plot != null) { - plot.getMembers().add(user); - } else if (Settings.AUTO_PURGE) { - toDelete.add(id); - } else { - PS.debug("&cENTRY " + id + " in `plot_trusted` does not exist. Create this plot or set `auto-purge: true` in the settings" - + ".yml."); + try (ResultSet r = statement.executeQuery("SELECT `user_uuid`, `plot_plot_id` FROM `" + this.prefix + "plot_trusted`")) { + ArrayList toDelete = new ArrayList<>(); + while (r.next()) { + id = r.getInt("plot_plot_id"); + o = r.getString("user_uuid"); + user = uuids.get(o); + if (user == null) { + user = UUID.fromString(o); + uuids.put(o, user); + } + Plot plot = plots.get(id); + if (plot != null) { + plot.getMembers().add(user); + } else if (Settings.AUTO_PURGE) { + toDelete.add(id); + } else { + PS.debug("&cENTRY " + id + " in `plot_trusted` does not exist. Create this plot or set `auto-purge: true` in the settings" + + ".yml."); + } } + deleteRows(toDelete, this.prefix + "plot_trusted", "plot_plot_id"); } - deleteRows(toDelete, this.prefix + "plot_trusted", "plot_plot_id"); - } /* * Getting denied */ - try (ResultSet r = statement.executeQuery("SELECT `user_uuid`, `plot_plot_id` FROM `" + this.prefix + "plot_denied`")) { - ArrayList toDelete = new ArrayList<>(); - while (r.next()) { - id = r.getInt("plot_plot_id"); - o = r.getString("user_uuid"); - user = uuids.get(o); - if (user == null) { - user = UUID.fromString(o); - uuids.put(o, user); - } - Plot plot = plots.get(id); - if (plot != null) { - plot.getDenied().add(user); - } else if (Settings.AUTO_PURGE) { - toDelete.add(id); - } else { - PS.debug("&cENTRY " + id - + " in `plot_denied` does not exist. Create this plot or set `auto-purge: true` in the settings.yml."); - } - } - deleteRows(toDelete, this.prefix + "plot_denied", "plot_plot_id"); - } - - try (ResultSet resultSet = statement.executeQuery("SELECT * FROM `" + this.prefix + "plot_settings`")) { - ArrayList toDelete = new ArrayList<>(); - while (resultSet.next()) { - id = resultSet.getInt("plot_plot_id"); - Plot plot = plots.get(id); - if (plot != null) { - plots.remove(id); - String alias = resultSet.getString("alias"); - if (alias != null) { - plot.getSettings().setAlias(alias); + try (ResultSet r = statement.executeQuery("SELECT `user_uuid`, `plot_plot_id` FROM `" + this.prefix + "plot_denied`")) { + ArrayList toDelete = new ArrayList<>(); + while (r.next()) { + id = r.getInt("plot_plot_id"); + o = r.getString("user_uuid"); + user = uuids.get(o); + if (user == null) { + user = UUID.fromString(o); + uuids.put(o, user); } - String pos = resultSet.getString("position"); - switch (pos.toLowerCase()) { - case "": - case "default": - case "0,0,0": - case "center": - break; - default: - try { - plot.getSettings().setPosition(BlockLoc.fromString(pos)); - } catch (Exception ignored) { - } - } - Integer m = resultSet.getInt("merged"); - boolean[] merged = new boolean[4]; - for (int i = 0; i < 4; i++) { - merged[3 - i] = (m & 1 << i) != 0; - } - plot.getSettings().setMerged(merged); - String[] flags_string; - String myflags = resultSet.getString("flags"); - if (myflags == null) { - flags_string = new String[]{}; + Plot plot = plots.get(id); + if (plot != null) { + plot.getDenied().add(user); + } else if (Settings.AUTO_PURGE) { + toDelete.add(id); } else { - if (!myflags.isEmpty()) { - flags_string = myflags.split(","); - } else { - flags_string = new String[]{}; - } + PS.debug("&cENTRY " + id + + " in `plot_denied` does not exist. Create this plot or set `auto-purge: true` in the settings.yml."); } - HashMap, Object> flags = new HashMap<>(); - boolean exception = false; - for (String element : flags_string) { - if (element.contains(":")) { - String[] split = element.split(":"); - try { - String flag_str = split[1].replaceAll("\u00AF", ":").replaceAll("\u00B4", ","); - Flag flag = FlagManager.getFlag(split[0]); - flags.put(flag, flag.parseValue(flag_str)); - } catch (Exception e) { - e.printStackTrace(); - exception = true; - } - } else { - element = element.replaceAll("\u00AF", ":").replaceAll("\u00B4", ","); - if (StringMan.isAlpha(element.replaceAll("_", "").replaceAll("-", ""))) { - Flag flag = FlagManager.getFlag(element); - flags.put(flag, flag.parseValue("")); - } else { - PS.debug("INVALID FLAG: " + element); - } - } - } - if (exception) { - PS.debug("&cPlot " + id + " | " + plot + " had an invalid flag. A fix has been attempted."); - PS.debug("&c" + myflags); - this.setFlags(plot, flags); - } - plot.getSettings().flags = flags; - } else if (Settings.AUTO_PURGE) { - toDelete.add(id); - } else { - PS.debug("&cENTRY " + id + " in `plot_settings` does not exist. Create this plot or set `auto-purge: true` in the settings" - + ".yml."); } + deleteRows(toDelete, this.prefix + "plot_denied", "plot_plot_id"); + } + + try (ResultSet resultSet = statement.executeQuery("SELECT * FROM `" + this.prefix + "plot_settings`")) { + ArrayList toDelete = new ArrayList<>(); + while (resultSet.next()) { + id = resultSet.getInt("plot_plot_id"); + Plot plot = plots.get(id); + if (plot != null) { + plots.remove(id); + String alias = resultSet.getString("alias"); + if (alias != null) { + plot.getSettings().setAlias(alias); + } + String pos = resultSet.getString("position"); + switch (pos.toLowerCase()) { + case "": + case "default": + case "0,0,0": + case "center": + break; + default: + try { + plot.getSettings().setPosition(BlockLoc.fromString(pos)); + } catch (Exception ignored) { + } + } + Integer m = resultSet.getInt("merged"); + boolean[] merged = new boolean[4]; + for (int i = 0; i < 4; i++) { + merged[3 - i] = (m & 1 << i) != 0; + } + plot.getSettings().setMerged(merged); + String[] flags_string; + String myflags = resultSet.getString("flags"); + if (myflags == null || myflags.isEmpty()) { + flags_string = new String[]{}; + } else { + flags_string = myflags.split(","); + } + HashMap, Object> flags = new HashMap<>(); + boolean exception = false; + for (String element : flags_string) { + if (element.contains(":")) { + String[] split = element.split(":"); + try { + String flag_str = split[1].replaceAll("\u00AF", ":").replaceAll("\u00B4", ","); + Flag flag = FlagManager.getFlag(split[0]); + flags.put(flag, flag.parseValue(flag_str)); + } catch (Exception e) { + e.printStackTrace(); + exception = true; + } + } else { + element = element.replaceAll("\u00AF", ":").replaceAll("\u00B4", ","); + if (StringMan.isAlpha(element.replaceAll("_", "").replaceAll("-", ""))) { + Flag flag = FlagManager.getFlag(element); + flags.put(flag, flag.parseValue("")); + } else { + PS.debug("INVALID FLAG: " + element); + } + } + } + if (exception) { + PS.debug("&cPlot " + id + " | " + plot + " had an invalid flag. A fix has been attempted."); + PS.debug("&c" + myflags); + this.setFlags(plot, flags); + } + plot.getSettings().flags = flags; + } else if (Settings.AUTO_PURGE) { + toDelete.add(id); + } else { + PS.debug( + "&cENTRY " + id + " in `plot_settings` does not exist. Create this plot or set `auto-purge: true` in the settings" + + ".yml."); + } + } + deleteRows(toDelete, this.prefix + "plot_settings", "plot_plot_id"); } - statement.close(); - deleteRows(toDelete, this.prefix + "plot_settings", "plot_plot_id"); } if (!plots.entrySet().isEmpty()) { createEmptySettings(new ArrayList<>(plots.keySet()), null); @@ -2027,23 +2019,23 @@ public class SQLManager implements AbstractDB { stmt_prefix = " OR `plot_plot_id` = "; } PreparedStatement stmt = SQLManager.this.connection - .prepareStatement("DELETE FROM `" + SQLManager.this.prefix + "plot_helpers` WHERE `plot_plot_id` = " + idstr + ""); + .prepareStatement("DELETE FROM `" + SQLManager.this.prefix + "plot_helpers` WHERE `plot_plot_id` = " + idstr); stmt.executeUpdate(); stmt.close(); stmt = SQLManager.this.connection - .prepareStatement("DELETE FROM `" + SQLManager.this.prefix + "plot_denied` WHERE `plot_plot_id` = " + idstr + ""); + .prepareStatement("DELETE FROM `" + SQLManager.this.prefix + "plot_denied` WHERE `plot_plot_id` = " + idstr); stmt.executeUpdate(); stmt.close(); stmt = SQLManager.this.connection - .prepareStatement("DELETE FROM `" + SQLManager.this.prefix + "plot_settings` WHERE `plot_plot_id` = " + idstr + ""); + .prepareStatement("DELETE FROM `" + SQLManager.this.prefix + "plot_settings` WHERE `plot_plot_id` = " + idstr); stmt.executeUpdate(); stmt.close(); stmt = SQLManager.this.connection - .prepareStatement("DELETE FROM `" + SQLManager.this.prefix + "plot_trusted` WHERE `plot_plot_id` = " + idstr + ""); + .prepareStatement("DELETE FROM `" + SQLManager.this.prefix + "plot_trusted` WHERE `plot_plot_id` = " + idstr); stmt.executeUpdate(); stmt.close(); stmt = SQLManager.this.connection - .prepareStatement("DELETE FROM `" + SQLManager.this.prefix + "plot` WHERE `id` = " + idstr2 + ""); + .prepareStatement("DELETE FROM `" + SQLManager.this.prefix + "plot` WHERE `id` = " + idstr2); stmt.executeUpdate(); stmt.close(); } catch (SQLException e) { @@ -2344,10 +2336,10 @@ public class SQLManager implements AbstractDB { try (PreparedStatement statement = this.connection .prepareStatement("SELECT `rating`, `player` FROM `" + this.prefix + "plot_rating` WHERE `plot_plot_id` = ? ")) { statement.setInt(1, getId(plot)); - try (ResultSet set = statement.executeQuery()) { - while (set.next()) { - UUID uuid = UUID.fromString(set.getString("player")); - int rating = set.getInt("rating"); + try (ResultSet resultSet = statement.executeQuery()) { + while (resultSet.next()) { + UUID uuid = UUID.fromString(resultSet.getString("player")); + int rating = resultSet.getInt("rating"); map.put(uuid, rating); } } @@ -2526,7 +2518,7 @@ public class SQLManager implements AbstractDB { for (String areaKey : areaSection.getKeys(false)) { String[] split = areaKey.split("(? set = newClusters.get(areaid); + if (set == null) { + set = new HashSet<>(); + newClusters.put(areaid, set); + } + set.add(cluster); } - owner = r.getString("owner"); - user = uuids.get(owner); - if (user == null) { - user = UUID.fromString(owner); - uuids.put(owner, user); - } - cluster = new PlotCluster(null, pos1, pos2, user, id); - clusters.put(id, cluster); - Set set = newClusters.get(areaid); - if (set == null) { - set = new HashSet<>(); - newClusters.put(areaid, set); - } - set.add(cluster); - } /* * Getting helpers */ - r = stmt.executeQuery("SELECT `user_uuid`, `cluster_id` FROM `" + this.prefix + "cluster_helpers`"); - while (r.next()) { - id = r.getInt("cluster_id"); - owner = r.getString("user_uuid"); - user = uuids.get(owner); - if (user == null) { - user = UUID.fromString(owner); - uuids.put(owner, user); + resultSet = stmt.executeQuery("SELECT `user_uuid`, `cluster_id` FROM `" + this.prefix + "cluster_helpers`"); + while (resultSet.next()) { + id = resultSet.getInt("cluster_id"); + owner = resultSet.getString("user_uuid"); + user = uuids.get(owner); + if (user == null) { + user = UUID.fromString(owner); + uuids.put(owner, user); + } + cluster = clusters.get(id); + if (cluster != null) { + cluster.helpers.add(user); + } else { + PS.debug("&cCluster " + id + " in cluster_helpers does not exist. Please create the cluster or remove this entry."); + } } - cluster = clusters.get(id); - if (cluster != null) { - cluster.helpers.add(user); - } else { - PS.debug("&cCluster " + id + " in cluster_helpers does not exist. Please create the cluster or remove this entry."); - } - } /* * Getting invited */ - r = stmt.executeQuery("SELECT `user_uuid`, `cluster_id` FROM `" + this.prefix + "cluster_invited`"); - while (r.next()) { - id = r.getInt("cluster_id"); - owner = r.getString("user_uuid"); - user = uuids.get(owner); - if (user == null) { - user = UUID.fromString(owner); - uuids.put(owner, user); - } - cluster = clusters.get(id); - if (cluster != null) { - cluster.invited.add(user); - } else { - PS.debug("&cCluster " + id + " in cluster_invited does not exist. Please create the cluster or remove this entry."); - } - } - r = stmt.executeQuery("SELECT * FROM `" + this.prefix + "cluster_settings`"); - while (r.next()) { - id = r.getInt("cluster_id"); - cluster = clusters.get(id); - if (cluster != null) { - String alias = r.getString("alias"); - if (alias != null) { - cluster.settings.setAlias(alias); + resultSet = stmt.executeQuery("SELECT `user_uuid`, `cluster_id` FROM `" + this.prefix + "cluster_invited`"); + while (resultSet.next()) { + id = resultSet.getInt("cluster_id"); + owner = resultSet.getString("user_uuid"); + user = uuids.get(owner); + if (user == null) { + user = UUID.fromString(owner); + uuids.put(owner, user); } - String pos = r.getString("position"); - switch (pos.toLowerCase()) { - case "": - case "default": - case "0,0,0": - case "center": - break; - default: - try { - BlockLoc loc = BlockLoc.fromString(pos); - cluster.settings.setPosition(loc); - } catch (Exception ignored) { - } - } - Integer m = r.getInt("merged"); - boolean[] merged = new boolean[4]; - for (int i = 0; i < 4; i++) { - merged[3 - i] = (m & 1 << i) != 0; - } - cluster.settings.setMerged(merged); - String[] flags_string; - String myflags = r.getString("flags"); - if (myflags == null) { - flags_string = new String[]{}; + cluster = clusters.get(id); + if (cluster != null) { + cluster.invited.add(user); } else { - if (!myflags.isEmpty()) { - flags_string = myflags.split(","); - } else { - flags_string = new String[]{}; - } + PS.debug("&cCluster " + id + " in cluster_invited does not exist. Please create the cluster or remove this entry."); } - HashMap, Object> flags = new HashMap<>(); - boolean exception = false; - for (String element : flags_string) { - if (element.contains(":")) { - String[] split = element.split(":"); - try { - String flag_str = split[1].replaceAll("\u00AF", ":").replaceAll("�", ","); - Flag flag = FlagManager.getFlag(split[0]); - flags.put(flag, flag_str); - } catch (Exception e) { - e.printStackTrace(); - exception = true; - } - } else { - Flag flag = FlagManager.getFlag(element); - flags.put(flag, ""); - } - } - if (exception) { - PS.debug("&cCluster " + id + " had an invalid flag. A fix has been attempted."); - PS.debug("&c" + myflags); - } - cluster.settings.flags = flags; - } else { - PS.debug("&cCluster " + id + " in cluster_settings does not exist. Please create the cluster or remove this entry."); } + resultSet = stmt.executeQuery("SELECT * FROM `" + this.prefix + "cluster_settings`"); + while (resultSet.next()) { + id = resultSet.getInt("cluster_id"); + cluster = clusters.get(id); + if (cluster != null) { + String alias = resultSet.getString("alias"); + if (alias != null) { + cluster.settings.setAlias(alias); + } + String pos = resultSet.getString("position"); + switch (pos.toLowerCase()) { + case "": + case "default": + case "0,0,0": + case "center": + break; + default: + try { + BlockLoc loc = BlockLoc.fromString(pos); + cluster.settings.setPosition(loc); + } catch (Exception ignored) { + } + } + Integer m = resultSet.getInt("merged"); + boolean[] merged = new boolean[4]; + for (int i = 0; i < 4; i++) { + merged[3 - i] = (m & 1 << i) != 0; + } + cluster.settings.setMerged(merged); + String[] flags_string; + String myflags = resultSet.getString("flags"); + if (myflags == null || myflags.isEmpty()) { + flags_string = new String[]{}; + } else { + flags_string = myflags.split(","); + } + HashMap, Object> flags = new HashMap<>(); + boolean exception = false; + for (String element : flags_string) { + if (element.contains(":")) { + String[] split = element.split(":"); + try { + String flag_str = split[1].replaceAll("\u00AF", ":").replaceAll("�", ","); + Flag flag = FlagManager.getFlag(split[0]); + flags.put(flag, flag.parseValue(flag_str)); + } catch (Exception e) { + e.printStackTrace(); + exception = true; + } + } else { + Flag flag = FlagManager.getFlag(element); + flags.put(flag, flag.parseValue("")); + } + } + if (exception) { + PS.debug("&cCluster " + id + " had an invalid flag. A fix has been attempted."); + PS.debug("&c" + myflags); + } + cluster.settings.flags = flags; + } else { + PS.debug("&cCluster " + id + " in cluster_settings does not exist. Please create the cluster or remove this entry."); + } + } + resultSet.close(); } - stmt.close(); - r.close(); boolean invalidPlot = false; for (Entry entry : noExist.entrySet()) { String a = entry.getKey(); @@ -2700,10 +2688,11 @@ public class SQLManager implements AbstractDB { int i = 0; for (Entry, Object> flag : flags.entrySet()) { if (i != 0) { - flag_string.append(","); + flag_string.append(','); } - flag_string.append(flag.getKey().getName() + ":" + flag.getKey().valueToString(flag.getValue()).replaceAll(":", "¯").replaceAll(",", - "´")); + flag_string.append(flag.getKey().getName()).append(":") + .append(flag.getKey().valueToString(flag.getValue()).replaceAll(":", "¯").replaceAll(",", + "´")); i++; } addClusterTask(cluster, new UniqueStatement("setFlags") { @@ -2793,15 +2782,15 @@ public class SQLManager implements AbstractDB { @Override public void execute(PreparedStatement statement) { - } @Override public void addBatch(PreparedStatement statement) throws SQLException { statement.executeUpdate(); - ResultSet keys = statement.getGeneratedKeys(); - if (keys.next()) { - cluster.temp = keys.getInt(1); + try (ResultSet keys = statement.getGeneratedKeys()) { + if (keys.next()) { + cluster.temp = keys.getInt(1); + } } } }); @@ -3038,12 +3027,10 @@ public class SQLManager implements AbstractDB { } for (Entry> entry : database.entrySet()) { - String worldname = entry.getKey(); HashMap map = entry.getValue(); if (!map.isEmpty()) { for (Entry entry2 : map.entrySet()) { - Plot plot = entry2.getValue(); - PS.debug("$1Plot was deleted: " + entry2.getValue() + "// TODO implement this when sure safe"); + PS.debug("$1Plot was deleted: " + entry2.getValue().toString() + "// TODO implement this when sure safe"); } } } @@ -3112,30 +3099,30 @@ public class SQLManager implements AbstractDB { try (Statement stmt = SQLManager.this.connection.createStatement()) { stmt.executeUpdate( "UPDATE `" + SQLManager.this.prefix + "cluster` SET `owner` = '" + now.toString() + "' WHERE `owner` = '" + old.toString() - + "'"); + + '\''); stmt.executeUpdate( "UPDATE `" + SQLManager.this.prefix + "cluster_helpers` SET `user_uuid` = '" + now.toString() + "' WHERE `user_uuid` = '" + old.toString() - + "'"); + + '\''); stmt.executeUpdate( "UPDATE `" + SQLManager.this.prefix + "cluster_invited` SET `user_uuid` = '" + now.toString() + "' WHERE `user_uuid` = '" + old.toString() - + "'"); + + '\''); stmt.executeUpdate( "UPDATE `" + SQLManager.this.prefix + "plot` SET `owner` = '" + now.toString() + "' WHERE `owner` = '" + old.toString() - + "'"); + + '\''); stmt.executeUpdate( "UPDATE `" + SQLManager.this.prefix + "plot_denied` SET `user_uuid` = '" + now.toString() + "' WHERE `user_uuid` = '" + old.toString() - + "'"); + + '\''); stmt.executeUpdate( "UPDATE `" + SQLManager.this.prefix + "plot_helpers` SET `user_uuid` = '" + now.toString() + "' WHERE `user_uuid` = '" + old.toString() - + "'"); + + '\''); stmt.executeUpdate( "UPDATE `" + SQLManager.this.prefix + "plot_trusted` SET `user_uuid` = '" + now.toString() + "' WHERE `user_uuid` = '" + old.toString() - + "'"); + + '\''); } catch (SQLException e) { e.printStackTrace(); } diff --git a/Core/src/main/java/com/intellectualcrafters/plot/database/SQLite.java b/Core/src/main/java/com/intellectualcrafters/plot/database/SQLite.java index a1460fd5b..388b96eb8 100644 --- a/Core/src/main/java/com/intellectualcrafters/plot/database/SQLite.java +++ b/Core/src/main/java/com/intellectualcrafters/plot/database/SQLite.java @@ -39,7 +39,7 @@ public class SQLite extends Database { if (!file.exists()) { try { file.createNewFile(); - } catch (IOException e) { + } catch (IOException ignored) { PS.debug("&cUnable to create database!"); } } diff --git a/Core/src/main/java/com/intellectualcrafters/plot/database/StmtMod.java b/Core/src/main/java/com/intellectualcrafters/plot/database/StmtMod.java index 697417e34..4bd455965 100644 --- a/Core/src/main/java/com/intellectualcrafters/plot/database/StmtMod.java +++ b/Core/src/main/java/com/intellectualcrafters/plot/database/StmtMod.java @@ -12,9 +12,9 @@ public abstract class StmtMod { public String getCreateMySQL(int size, String query, int params) { StringBuilder statement = new StringBuilder(query); for (int i = 0; i < size - 1; i++) { - statement.append("(").append(StringMan.repeat(",?", params).substring(1)).append("),"); + statement.append('(').append(StringMan.repeat(",?", params).substring(1)).append("),"); } - statement.append("(").append(StringMan.repeat(",?", params).substring(1)).append(")"); + statement.append('(').append(StringMan.repeat(",?", params).substring(1)).append(')'); return statement.toString(); } @@ -22,7 +22,7 @@ public abstract class StmtMod { StringBuilder statement = new StringBuilder(query); String modParams = StringMan.repeat(",?", params).substring(1); for (int i = 0; i < size - 1; i++) { - statement.append("UNION SELECT ").append(modParams).append(" "); + statement.append("UNION SELECT ").append(modParams).append(' '); } return statement.toString(); } diff --git a/Core/src/main/java/com/intellectualcrafters/plot/flag/Flag.java b/Core/src/main/java/com/intellectualcrafters/plot/flag/Flag.java index 02f7d3b21..efcd0c58e 100644 --- a/Core/src/main/java/com/intellectualcrafters/plot/flag/Flag.java +++ b/Core/src/main/java/com/intellectualcrafters/plot/flag/Flag.java @@ -2,7 +2,7 @@ package com.intellectualcrafters.plot.flag; public class Flag { - private String name; + private final String name; /** * Flag object used to store basic information for a Plot. Flags are a diff --git a/Core/src/main/java/com/intellectualcrafters/plot/generator/AugmentedUtils.java b/Core/src/main/java/com/intellectualcrafters/plot/generator/AugmentedUtils.java index 441bdd817..15dd548b9 100644 --- a/Core/src/main/java/com/intellectualcrafters/plot/generator/AugmentedUtils.java +++ b/Core/src/main/java/com/intellectualcrafters/plot/generator/AugmentedUtils.java @@ -127,9 +127,8 @@ public class AugmentedUtils { } if (!has) { continue; - } else { - toReturn = true; } + toReturn = true; secondaryMask = new PlotChunk(wrap) { @Override public Object getChunkAbs() { diff --git a/Core/src/main/java/com/intellectualcrafters/plot/object/Plot.java b/Core/src/main/java/com/intellectualcrafters/plot/object/Plot.java index b427c7abe..3fe67531d 100644 --- a/Core/src/main/java/com/intellectualcrafters/plot/object/Plot.java +++ b/Core/src/main/java/com/intellectualcrafters/plot/object/Plot.java @@ -2,6 +2,7 @@ package com.intellectualcrafters.plot.object; import com.google.common.base.Optional; import com.google.common.collect.BiMap; +import com.google.common.collect.ImmutableSet; import com.intellectualcrafters.jnbt.CompoundTag; import com.intellectualcrafters.plot.PS; import com.intellectualcrafters.plot.config.C; @@ -212,19 +213,19 @@ public class Plot { String[] split = string.split(";|,"); if (split.length == 2) { if (defaultArea != null) { - PlotId id = PlotId.fromString(split[0] + ";" + split[1]); + PlotId id = PlotId.fromString(split[0] + ';' + split[1]); return id != null ? defaultArea.getPlotAbs(id) : null; } } else if (split.length == 3) { PlotArea pa = PS.get().getPlotArea(split[0], null); if (pa != null) { - PlotId id = PlotId.fromString(split[1] + ";" + split[2]); + PlotId id = PlotId.fromString(split[1] + ';' + split[2]); return pa.getPlotAbs(id); } } else if (split.length == 4) { PlotArea pa = PS.get().getPlotArea(split[0], split[1]); if (pa != null) { - PlotId id = PlotId.fromString(split[1] + ";" + split[2]); + PlotId id = PlotId.fromString(split[1] + ';' + split[2]); return pa.getPlotAbs(id); } } @@ -348,17 +349,17 @@ public class Plot { } /** - * Get a list of owner UUIDs for a plot (supports multi-owner mega-plots). + * Get a immutable set of owner UUIDs for a plot (supports multi-owner mega-plots). * @return */ - public HashSet getOwners() { + public Set getOwners() { if (this.owner == null) { return new HashSet<>(); } if (isMerged()) { HashSet plots = getConnectedPlots(); Plot[] array = plots.toArray(new Plot[plots.size()]); - HashSet owners = new HashSet(1); + ImmutableSet.Builder owners = ImmutableSet.builder(); UUID last = this.owner; owners.add(this.owner); for (Plot current : array) { @@ -367,9 +368,9 @@ public class Plot { last = current.owner; } } - return owners; + return owners.build(); } - return new HashSet<>(Collections.singletonList(this.owner)); + return ImmutableSet.of(this.owner); } /** @@ -380,10 +381,7 @@ public class Plot { * @return true if the player is added/trusted or is the owner */ public boolean isAdded(UUID uuid) { - if (this.owner == null) { - return false; - } - if (getDenied().contains(uuid)) { + if (this.owner == null || getDenied().contains(uuid)) { return false; } if (getTrusted().contains(uuid) || getTrusted().contains(DBFunc.everyone)) { @@ -1742,7 +1740,7 @@ public class Plot { TaskManager.runTaskAsync(new Runnable() { @Override public void run() { - String name = Plot.this.id + "," + Plot.this.area + "," + MainUtil.getName(Plot.this.owner); + String name = Plot.this.id + "," + Plot.this.area + ',' + MainUtil.getName(Plot.this.owner); boolean result = SchematicHandler.manager.save(value, Settings.SCHEMATIC_SAVE_PATH + File.separator + name + ".schematic"); if (whenDone != null) { @@ -2034,7 +2032,7 @@ public class Plot { this.create(); } return this.owner; - } catch (IllegalArgumentException e) { + } catch (IllegalArgumentException ignored) { return null; } } @@ -2576,16 +2574,15 @@ public class Plot { return; } TaskManager.TELEPORT_QUEUE.remove(name); - if (!player.isOnline()) { - return; + if (player.isOnline()) { + MainUtil.sendMessage(player, C.TELEPORTED_TO_PLOT); + player.teleport(location); } - MainUtil.sendMessage(player, C.TELEPORTED_TO_PLOT); - player.teleport(location); } }, Settings.TELEPORT_DELAY * 20); return true; } - return result; + return false; } public boolean isOnline() { @@ -2876,6 +2873,7 @@ public class Plot { } public boolean hasFlag(Flag flag) { + //todo return false; } } diff --git a/Core/src/main/java/com/intellectualcrafters/plot/object/PlotAnalysis.java b/Core/src/main/java/com/intellectualcrafters/plot/object/PlotAnalysis.java index 6a34c0b01..4336de754 100644 --- a/Core/src/main/java/com/intellectualcrafters/plot/object/PlotAnalysis.java +++ b/Core/src/main/java/com/intellectualcrafters/plot/object/PlotAnalysis.java @@ -515,7 +515,7 @@ public class PlotAnalysis { int SIZE = 10; List[] bucket = new ArrayList[SIZE]; for (int i = 0; i < bucket.length; i++) { - bucket[i] = new ArrayList(); + bucket[i] = new ArrayList<>(); } boolean maxLength = false; int placement = 1; diff --git a/Core/src/main/java/com/intellectualcrafters/plot/object/PlotHandler.java b/Core/src/main/java/com/intellectualcrafters/plot/object/PlotHandler.java index cfd7f757a..6fb59513c 100644 --- a/Core/src/main/java/com/intellectualcrafters/plot/object/PlotHandler.java +++ b/Core/src/main/java/com/intellectualcrafters/plot/object/PlotHandler.java @@ -1,6 +1,6 @@ package com.intellectualcrafters.plot.object; -import java.util.HashSet; +import java.util.Set; import java.util.UUID; public class PlotHandler { @@ -8,7 +8,7 @@ public class PlotHandler { if ((plot1.owner == null) || (plot2.owner == null)) { return false; } - final HashSet owners = plot1.getOwners(); + final Set owners = plot1.getOwners(); owners.retainAll(plot2.getOwners()); return !owners.isEmpty(); } diff --git a/Core/src/main/java/com/intellectualcrafters/plot/object/PlotPlayer.java b/Core/src/main/java/com/intellectualcrafters/plot/object/PlotPlayer.java index ad61abf25..b8a60edc4 100644 --- a/Core/src/main/java/com/intellectualcrafters/plot/object/PlotPlayer.java +++ b/Core/src/main/java/com/intellectualcrafters/plot/object/PlotPlayer.java @@ -245,19 +245,6 @@ public abstract class PlotPlayer implements CommandCaller { */ public abstract UUID getUUID(); - /** - * Check the player's permissions
- * - Will be cached if permission caching is enabled - */ - @Override - public abstract boolean hasPermission(String permission); - - /** - * Send the player a message - */ - @Override - public abstract void sendMessage(String message); - /** * Teleport the player to a location * @param location diff --git a/Core/src/main/java/com/intellectualcrafters/plot/util/BO3Handler.java b/Core/src/main/java/com/intellectualcrafters/plot/util/BO3Handler.java index 14c8318f6..7930b6c24 100644 --- a/Core/src/main/java/com/intellectualcrafters/plot/util/BO3Handler.java +++ b/Core/src/main/java/com/intellectualcrafters/plot/util/BO3Handler.java @@ -254,7 +254,7 @@ public class BO3Handler { try (FileOutputStream fos = new FileOutputStream(bo3File)) { write(fos, plot, bo3); } - } catch (Exception e) { + } catch (IOException e) { e.printStackTrace(); return false; } diff --git a/Core/src/main/java/com/intellectualcrafters/plot/util/MainUtil.java b/Core/src/main/java/com/intellectualcrafters/plot/util/MainUtil.java index f5ef72336..0019882ca 100644 --- a/Core/src/main/java/com/intellectualcrafters/plot/util/MainUtil.java +++ b/Core/src/main/java/com/intellectualcrafters/plot/util/MainUtil.java @@ -20,6 +20,7 @@ import com.intellectualcrafters.plot.object.RegionWrapper; import com.intellectualcrafters.plot.object.RunnableVal; import java.io.File; +import java.io.IOException; import java.io.OutputStream; import java.io.OutputStreamWriter; import java.io.PrintWriter; @@ -125,7 +126,7 @@ public class MainUtil { filename = "plot." + extension; } else { website = Settings.WEB_URL + "save.php?" + uuid; - filename = file + "." + extension; + filename = file + '.' + extension; } final URL url; try { @@ -183,7 +184,7 @@ public class MainUtil { whenDone.value = url; } TaskManager.runTask(whenDone); - } catch (Exception e) { + } catch (IOException e) { e.printStackTrace(); TaskManager.runTask(whenDone); } @@ -298,7 +299,8 @@ public class MainUtil { public static String getName(UUID owner) { if (owner == null) { return C.NONE.s(); - } else if (owner.equals(DBFunc.everyone)) { + } + if (owner.equals(DBFunc.everyone)) { return C.EVERYONE.s(); } String name = UUIDHandler.getName(owner); @@ -365,7 +367,7 @@ public class MainUtil { uuid = UUID.fromString(term); } uuids.add(uuid); - } catch (Exception e) { + } catch (Exception ignored) { id = PlotId.fromString(term); if (id != null) { continue; @@ -772,20 +774,20 @@ public class MainUtil { } String info; if (full && Settings.RATING_CATEGORIES != null && Settings.RATING_CATEGORIES.size() > 1) { - String rating = ""; - String prefix = ""; double[] ratings = MainUtil.getAverageRatings(plot); for (double v : ratings) { } + String rating = ""; + String prefix = ""; for (int i = 0; i < ratings.length; i++) { - rating += prefix + Settings.RATING_CATEGORIES.get(i) + "=" + String.format("%.1f", ratings[i]); + rating += prefix + Settings.RATING_CATEGORIES.get(i) + '=' + String.format("%.1f", ratings[i]); prefix = ","; } info = newInfo.replaceAll("%rating%", rating); } else { - info = newInfo.replaceAll("%rating%", String.format("%.1f", plot.getAverageRating()) + "/" + max); + info = newInfo.replaceAll("%rating%", String.format("%.1f", plot.getAverageRating()) + '/' + max); } whenDone.run(info); } diff --git a/Core/src/main/java/com/intellectualcrafters/plot/util/MathMan.java b/Core/src/main/java/com/intellectualcrafters/plot/util/MathMan.java index 64270ae3c..6e9c67833 100644 --- a/Core/src/main/java/com/intellectualcrafters/plot/util/MathMan.java +++ b/Core/src/main/java/com/intellectualcrafters/plot/util/MathMan.java @@ -115,7 +115,7 @@ public class MathMan { } public static double sqrtApprox(double d) { - return Double.longBitsToDouble(((Double.doubleToLongBits(d) - (1l << 52)) >> 1) + (1l << 61)); + return Double.longBitsToDouble(((Double.doubleToLongBits(d) - (1L << 52)) >> 1) + (1L << 61)); } public static float invSqrt(float x) { diff --git a/Core/src/main/java/com/intellectualcrafters/plot/util/ReflectionUtils.java b/Core/src/main/java/com/intellectualcrafters/plot/util/ReflectionUtils.java index 462154b21..9275179a8 100644 --- a/Core/src/main/java/com/intellectualcrafters/plot/util/ReflectionUtils.java +++ b/Core/src/main/java/com/intellectualcrafters/plot/util/ReflectionUtils.java @@ -27,8 +27,8 @@ public class ReflectionUtils { public ReflectionUtils(String version) { if (version != null) { - preClassB += "." + version; - preClassM += "." + version; + preClassB += '.' + version; + preClassM += '.' + version; } } @@ -73,29 +73,29 @@ public class ReflectionUtils { } catch (ClassCastException ignored) { } } - } catch (Throwable e) { + } catch (IllegalAccessException | IllegalArgumentException | SecurityException e) { e.printStackTrace(); } return list; } public static Class getNmsClass(String name) { - String className = preClassM + "." + name; + String className = preClassM + '.' + name; return getClass(className); } public static Class getCbClass(String name) { - String className = preClassB + "." + name; + String className = preClassB + '.' + name; return getClass(className); } public static Class getUtilClass(String name) { try { return Class.forName(name); //Try before 1.8 first - } catch (ClassNotFoundException ex) { + } catch (ClassNotFoundException ignored) { try { return Class.forName("net.minecraft.util." + name); //Not 1.8 - } catch (ClassNotFoundException ex2) { + } catch (ClassNotFoundException ignored2) { return null; } } @@ -110,9 +110,9 @@ public class ReflectionUtils { public static Method makeMethod(Class clazz, String methodName, Class... paramaters) { try { return clazz.getDeclaredMethod(methodName, paramaters); - } catch (NoSuchMethodException ex) { + } catch (NoSuchMethodException ignored) { return null; - } catch (Exception ex) { + } catch (SecurityException ex) { throw new RuntimeException(ex); } } @@ -127,7 +127,7 @@ public class ReflectionUtils { return (T) method.invoke(instance, paramaters); } catch (InvocationTargetException ex) { throw new RuntimeException(ex.getCause()); - } catch (Exception ex) { + } catch (IllegalAccessException | IllegalArgumentException ex) { throw new RuntimeException(ex); } } @@ -136,9 +136,9 @@ public class ReflectionUtils { public static Constructor makeConstructor(Class clazz, Class... paramaterTypes) { try { return (Constructor) clazz.getConstructor(paramaterTypes); - } catch (NoSuchMethodException ex) { + } catch (NoSuchMethodException ignored) { return null; - } catch (Exception ex) { + } catch (SecurityException ex) { throw new RuntimeException(ex); } } @@ -152,7 +152,7 @@ public class ReflectionUtils { return constructor.newInstance(paramaters); } catch (InvocationTargetException ex) { throw new RuntimeException(ex.getCause()); - } catch (Exception ex) { + } catch (IllegalAccessException | IllegalArgumentException | InstantiationException ex) { throw new RuntimeException(ex); } } @@ -160,9 +160,9 @@ public class ReflectionUtils { public static Field makeField(Class clazz, String name) { try { return clazz.getDeclaredField(name); - } catch (NoSuchFieldException ex) { + } catch (NoSuchFieldException ignored) { return null; - } catch (Exception ex) { + } catch (SecurityException ex) { throw new RuntimeException(ex); } } @@ -175,7 +175,7 @@ public class ReflectionUtils { field.setAccessible(true); try { return (T) field.get(instance); - } catch (Exception ex) { + } catch (IllegalAccessException | IllegalArgumentException ex) { throw new RuntimeException(ex); } } diff --git a/Core/src/main/java/com/intellectualcrafters/plot/util/SchematicHandler.java b/Core/src/main/java/com/intellectualcrafters/plot/util/SchematicHandler.java index 4137b330b..572b17319 100644 --- a/Core/src/main/java/com/intellectualcrafters/plot/util/SchematicHandler.java +++ b/Core/src/main/java/com/intellectualcrafters/plot/util/SchematicHandler.java @@ -577,6 +577,8 @@ public abstract class SchematicHandler { try (OutputStream stream = new FileOutputStream(tmp); NBTOutputStream output = new NBTOutputStream(new GZIPOutputStream(stream))) { output.writeTag(tag); } + } catch (FileNotFoundException e) { + e.printStackTrace(); } catch (IOException e) { e.printStackTrace(); return false; diff --git a/Core/src/main/java/com/plotsquared/general/commands/Command.java b/Core/src/main/java/com/plotsquared/general/commands/Command.java index 97fd00cfa..31acf7791 100644 --- a/Core/src/main/java/com/plotsquared/general/commands/Command.java +++ b/Core/src/main/java/com/plotsquared/general/commands/Command.java @@ -253,7 +253,7 @@ public abstract class Command { return; } if (page == 0 && totalPages != 0) { // Next - new PlotMessage().text("<-").color("$3").text(" | ").color("$3").text("->").color("$1").command(baseCommand + " " + (page + 2)) + new PlotMessage().text("<-").color("$3").text(" | ").color("$3").text("->").color("$1").command(baseCommand + " " + (0 + 2)) .text(C.CLICKABLE.s()).color("$2").send(player); return; } diff --git a/Core/src/main/java/com/plotsquared/general/commands/CommandCaller.java b/Core/src/main/java/com/plotsquared/general/commands/CommandCaller.java index fba200cf1..314b7250f 100644 --- a/Core/src/main/java/com/plotsquared/general/commands/CommandCaller.java +++ b/Core/src/main/java/com/plotsquared/general/commands/CommandCaller.java @@ -4,8 +4,14 @@ import com.intellectualcrafters.plot.commands.RequiredType; public interface CommandCaller { + /** + * Send the player a message. + */ void sendMessage(String message); + /** + * Check the player's permissions. Will be cached if permission caching is enabled. + */ boolean hasPermission(String perm); RequiredType getSuperCaller(); diff --git a/Core/src/main/java/com/plotsquared/listener/WESubscriber.java b/Core/src/main/java/com/plotsquared/listener/WESubscriber.java index 850c94021..ecda7b943 100644 --- a/Core/src/main/java/com/plotsquared/listener/WESubscriber.java +++ b/Core/src/main/java/com/plotsquared/listener/WESubscriber.java @@ -123,11 +123,10 @@ public class WESubscriber { if (maskextent != null) { wrapper = new ExtentWrapper(maskextent); field.set(maskextent, history); - event.setExtent(wrapper); } else { wrapper = new ExtentWrapper(history); - event.setExtent(wrapper); } + event.setExtent(wrapper); field.set(history, reorder); field.set(reorder, new ProcessedWEExtent(world, mask, max, new FastModeExtent(worldObj, true), wrapper)); } diff --git a/Core/src/test/java/com/intellectualcrafters/plot/FlagTest.java b/Core/src/test/java/com/intellectualcrafters/plot/FlagTest.java index 48df1167d..e1d2d1078 100644 --- a/Core/src/test/java/com/intellectualcrafters/plot/FlagTest.java +++ b/Core/src/test/java/com/intellectualcrafters/plot/FlagTest.java @@ -3,7 +3,7 @@ package com.intellectualcrafters.plot; import static org.junit.Assert.assertEquals; import com.google.common.base.Optional; -import com.intellectualcrafters.plot.database.AbstractDBTEst; +import com.intellectualcrafters.plot.database.AbstractDBTest; import com.intellectualcrafters.plot.database.DBFunc; import com.intellectualcrafters.plot.flag.Flag; import com.intellectualcrafters.plot.flag.Flags; @@ -27,7 +27,7 @@ public class FlagTest { @Before public void setUp() throws Exception { EventUtil.manager = new EventUtilTest(); - DBFunc.dbManager = new AbstractDBTEst(); + DBFunc.dbManager = new AbstractDBTest(); } @Test diff --git a/Core/src/test/java/com/intellectualcrafters/plot/database/AbstractDBTEst.java b/Core/src/test/java/com/intellectualcrafters/plot/database/AbstractDBTEst.java index d94661796..c04f69238 100644 --- a/Core/src/test/java/com/intellectualcrafters/plot/database/AbstractDBTEst.java +++ b/Core/src/test/java/com/intellectualcrafters/plot/database/AbstractDBTEst.java @@ -15,70 +15,54 @@ import java.util.Map; import java.util.Set; import java.util.UUID; -public class AbstractDBTEst implements AbstractDB { +public class AbstractDBTest implements AbstractDB { @Override public void setOwner(Plot plot, UUID uuid) { - } @Override public void createPlotsAndData(ArrayList plots, Runnable whenDone) { - } @Override public void createPlot(Plot plot) { - } - @Override public void createTables() throws Exception { - + @Override public void createTables() { } @Override public void delete(Plot plot) { - } @Override public void deleteSettings(Plot plot) { - } @Override public void deleteHelpers(Plot plot) { - } @Override public void deleteTrusted(Plot plot) { - } @Override public void deleteDenied(Plot plot) { - } @Override public void deleteComments(Plot plot) { - } @Override public void deleteRatings(Plot plot) { - } @Override public void delete(PlotCluster cluster) { - } @Override public void addPersistentMeta(UUID uuid, String key, byte[] meta, boolean delete) { - } @Override public void removePersistentMeta(UUID uuid, String key) { - } @Override public void getPersistentMeta(UUID uuid, RunnableVal> result) { - } @Override public void createPlotSettings(int id, Plot plot) { - } @Override public int getId(Plot plot) { @@ -94,7 +78,6 @@ public class AbstractDBTEst implements AbstractDB { } @Override public void validateAllPlots(Set toValidate) { - } @Override public HashMap> getClusters() { @@ -102,83 +85,63 @@ public class AbstractDBTEst implements AbstractDB { } @Override public void setMerged(Plot plot, boolean[] merged) { - } @Override public void swapPlots(Plot plot1, Plot plot2) { - } @Override public void setFlags(Plot plot, HashMap, Object> flags) { - } @Override public void setFlags(PlotCluster cluster, HashMap, Object> flags) { - } @Override public void setClusterName(PlotCluster cluster, String name) { - } @Override public void setAlias(Plot plot, String alias) { - } @Override public void purgeIds(Set uniqueIds) { - } @Override public void purge(PlotArea area, Set plotIds) { - } @Override public void setPosition(Plot plot, String position) { - } @Override public void setPosition(PlotCluster cluster, String position) { - } @Override public void removeTrusted(Plot plot, UUID uuid) { - } @Override public void removeHelper(PlotCluster cluster, UUID uuid) { - } @Override public void removeMember(Plot plot, UUID uuid) { - } @Override public void removeInvited(PlotCluster cluster, UUID uuid) { - } @Override public void setTrusted(Plot plot, UUID uuid) { - } @Override public void setHelper(PlotCluster cluster, UUID uuid) { - } @Override public void setMember(Plot plot, UUID uuid) { - } @Override public void setInvited(PlotCluster cluster, UUID uuid) { - } @Override public void removeDenied(Plot plot, UUID uuid) { - } @Override public void setDenied(Plot plot, UUID uuid) { - } @Override public HashMap getRatings(Plot plot) { @@ -186,43 +149,33 @@ public class AbstractDBTEst implements AbstractDB { } @Override public void setRating(Plot plot, UUID rater, int value) { - } @Override public void removeComment(Plot plot, PlotComment comment) { - } @Override public void clearInbox(Plot plot, String inbox) { - } @Override public void setComment(Plot plot, PlotComment comment) { - } @Override public void getComments(Plot plot, String inbox, RunnableVal> whenDone) { - } @Override public void createPlotAndSettings(Plot plot, Runnable whenDone) { - } @Override public void createCluster(PlotCluster cluster) { - } @Override public void resizeCluster(PlotCluster current, PlotId min, PlotId max) { - } @Override public void movePlot(Plot originalPlot, Plot newPlot) { - } @Override public void replaceUUID(UUID old, UUID now) { - } @Override public boolean deleteTables() { @@ -230,14 +183,11 @@ public class AbstractDBTEst implements AbstractDB { } @Override public void close() { - } @Override public void replaceWorld(String oldWorld, String newWorld, PlotId min, PlotId max) { - } @Override public void updateTables(int[] oldVersion) { - } } diff --git a/Core/src/test/java/com/intellectualcrafters/plot/util/EventUtilTest.java b/Core/src/test/java/com/intellectualcrafters/plot/util/EventUtilTest.java index 2d2c37fe4..88d26c1ed 100644 --- a/Core/src/test/java/com/intellectualcrafters/plot/util/EventUtilTest.java +++ b/Core/src/test/java/com/intellectualcrafters/plot/util/EventUtilTest.java @@ -31,7 +31,6 @@ public class EventUtilTest extends EventUtil { } @Override public void callDelete(Plot plot) { - } @Override public boolean callFlagAdd(Flag flag, Plot plot) { @@ -55,22 +54,17 @@ public class EventUtilTest extends EventUtil { } @Override public void callEntry(PlotPlayer player, Plot plot) { - } @Override public void callLeave(PlotPlayer player, Plot plot) { - } @Override public void callDenied(PlotPlayer initiator, Plot plot, UUID player, boolean added) { - } @Override public void callTrusted(PlotPlayer initiator, Plot plot, UUID player, boolean added) { - } @Override public void callMember(PlotPlayer initiator, Plot plot, UUID player, boolean added) { - } } \ No newline at end of file diff --git a/Sponge/src/main/java/com/plotsquared/sponge/listener/MainListener.java b/Sponge/src/main/java/com/plotsquared/sponge/listener/MainListener.java index 04dda11f0..4f92abd6a 100644 --- a/Sponge/src/main/java/com/plotsquared/sponge/listener/MainListener.java +++ b/Sponge/src/main/java/com/plotsquared/sponge/listener/MainListener.java @@ -182,7 +182,7 @@ public class MainListener { } @Listener - public void onSpawnEntity(SpawnEntityEvent event) throws Exception { + public void onSpawnEntity(SpawnEntityEvent event) { World world = event.getTargetWorld(); event.filterEntities(entity -> { if (entity instanceof Player) { @@ -283,7 +283,7 @@ public class MainListener { }); } - public void onNotifyNeighborBlock(NotifyNeighborBlockEvent event) throws Exception { + public void onNotifyNeighborBlock(NotifyNeighborBlockEvent event) { AtomicBoolean cancelled = new AtomicBoolean(false); // SpongeUtil.printCause("physics", event.getCause()); // PlotArea area = plotloc.getPlotArea(); @@ -320,7 +320,7 @@ public class MainListener { } @Listener - public void onInteract(InteractEvent event) throws Exception { + public void onInteract(InteractEvent event) { Player player = SpongeUtil.getCause(event.getCause(), Player.class); if (player == null) { event.setCancelled(true); @@ -366,7 +366,7 @@ public class MainListener { } @Listener - public void onExplosion(ExplosionEvent e) throws Exception { + public void onExplosion(ExplosionEvent e) { if (e instanceof ExplosionEvent.Detonate) { ExplosionEvent.Detonate event = (Detonate) e; World world = event.getTargetWorld(); diff --git a/Sponge/src/main/java/com/plotsquared/sponge/util/SpongeTitleManager.java b/Sponge/src/main/java/com/plotsquared/sponge/util/SpongeTitleManager.java index 8ef386fc1..a4628e409 100644 --- a/Sponge/src/main/java/com/plotsquared/sponge/util/SpongeTitleManager.java +++ b/Sponge/src/main/java/com/plotsquared/sponge/util/SpongeTitleManager.java @@ -3,7 +3,6 @@ package com.plotsquared.sponge.util; import com.intellectualcrafters.plot.object.PlotPlayer; import com.intellectualcrafters.plot.util.AbstractTitle; import com.plotsquared.sponge.object.SpongePlayer; -import org.spongepowered.api.text.Text; import org.spongepowered.api.text.title.Title; public class SpongeTitleManager extends AbstractTitle { diff --git a/Sponge/src/main/java/com/plotsquared/sponge/util/block/SlowQueue.java b/Sponge/src/main/java/com/plotsquared/sponge/util/block/SlowQueue.java index bc7f804da..0c4aa5cfa 100644 --- a/Sponge/src/main/java/com/plotsquared/sponge/util/block/SlowQueue.java +++ b/Sponge/src/main/java/com/plotsquared/sponge/util/block/SlowQueue.java @@ -116,7 +116,6 @@ public class SlowQueue implements PlotQueue { IChunkProvider provider = nmsWorld.getChunkProvider(); if (!(provider instanceof ChunkProviderServer)) { PS.debug("Not valid world generator for: " + world); - return; } /* ChunkProviderServer chunkServer = (ChunkProviderServer) provider; IChunkProvider chunkProvider = chunkServer.serverChunkGenerator; diff --git a/Sponge/src/main/java/com/plotsquared/sponge/uuid/SpongeOnlineUUIDWrapper.java b/Sponge/src/main/java/com/plotsquared/sponge/uuid/SpongeOnlineUUIDWrapper.java index 905c9fee3..fe45ed968 100644 --- a/Sponge/src/main/java/com/plotsquared/sponge/uuid/SpongeOnlineUUIDWrapper.java +++ b/Sponge/src/main/java/com/plotsquared/sponge/uuid/SpongeOnlineUUIDWrapper.java @@ -8,6 +8,7 @@ import com.plotsquared.sponge.SpongeMain; import com.plotsquared.sponge.object.SpongePlayer; import java.util.UUID; +import java.util.concurrent.ExecutionException; public class SpongeOnlineUUIDWrapper extends UUIDWrapper { @@ -36,7 +37,7 @@ public class SpongeOnlineUUIDWrapper extends UUIDWrapper { String name; try { name = SpongeMain.THIS.getResolver().get(uuid, true).get().getName().orElse(null); - } catch (final Exception e) { + } catch (InterruptedException | ExecutionException ignored) { name = null; } final String username = name; From 421203a27d480b16ae9a40419e77613656a2d28a Mon Sep 17 00:00:00 2001 From: MattBDev Date: Fri, 29 Apr 2016 18:14:12 -0400 Subject: [PATCH 02/10] Bug Fix and Cleanup --- .../plot/api/PlotAPI.java | 3 +- .../com/plotsquared/bukkit/BukkitMain.java | 16 +- .../bukkit/commands/DebugUUID.java | 2 +- .../plotme/ClassicPlotMeConnector.java | 9 +- .../database/plotme/LikePlotMeConverter.java | 4 +- .../bukkit/generator/BukkitPlotGenerator.java | 2 +- .../listeners/worldedit/WEListener.java | 32 ++-- .../bukkit/object/entity/EntityWrapper.java | 3 +- .../bukkit/titles/HackTitleManager.java | 3 +- .../bukkit/util/BukkitChunkManager.java | 39 ++--- .../bukkit/util/BukkitHybridUtils.java | 3 +- .../bukkit/util/BukkitPlainChatManager.java | 9 +- .../plotsquared/bukkit/util/BukkitUtil.java | 6 +- .../com/plotsquared/bukkit/util/Metrics.java | 10 +- .../plotsquared/bukkit/util/SendChunk.java | 2 +- .../bukkit/util/block/FastQueue_1_7.java | 2 +- .../bukkit/util/block/FastQueue_1_8.java | 4 +- .../bukkit/util/block/FastQueue_1_8_3.java | 2 +- .../bukkit/util/block/FastQueue_1_9.java | 2 +- .../bukkit/uuid/OfflineUUIDWrapper.java | 9 +- .../configuration/ConfigurationOptions.java | 4 +- .../configuration/MemorySection.java | 27 ++-- .../configuration/file/FileConfiguration.java | 31 +--- .../configuration/file/YamlConfiguration.java | 16 +- .../file/YamlConfigurationOptions.java | 2 +- .../configuration/file/YamlConstructor.java | 2 +- .../configuration/file/YamlRepresenter.java | 2 +- .../ConfigurationSerialization.java | 16 +- .../com/intellectualcrafters/jnbt/EndTag.java | 3 +- .../jnbt/NBTConstants.java | 3 +- .../intellectualcrafters/jnbt/NBTUtils.java | 3 +- .../intellectualcrafters/json/JSONObject.java | 34 ++-- .../com/intellectualcrafters/json/XML.java | 3 +- .../com/intellectualcrafters/plot/PS.java | 10 +- .../plot/commands/Buy.java | 2 +- .../plot/commands/Continue.java | 2 +- .../plot/commands/DebugExec.java | 10 +- .../plot/commands/Delete.java | 6 +- .../plot/commands/Done.java | 7 +- .../plot/commands/ListCmd.java | 5 +- .../plot/commands/Load.java | 10 +- .../plot/commands/Owner.java | 9 +- .../plot/commands/Rate.java | 5 +- .../plot/commands/Reload.java | 4 +- .../plot/commands/Trim.java | 34 ++-- .../plot/config/Configuration.java | 3 +- .../plot/database/SQLManager.java | 52 +++--- .../plot/flag/FlagManager.java | 17 +- .../plot/generator/AugmentedUtils.java | 3 +- .../generator/IndependentPlotGenerator.java | 3 +- .../plot/generator/SquarePlotManager.java | 2 +- .../plot/object/ConsolePlayer.java | 27 ++-- .../plot/object/Plot.java | 61 +++---- .../plot/object/PlotArea.java | 31 ++-- .../plot/object/PlotId.java | 2 +- .../plot/object/PlotPlayer.java | 3 +- .../plot/util/ChunkManager.java | 3 +- .../plot/util/MainUtil.java | 2 +- .../plot/util/ReflectionUtils.java | 122 ++++++-------- .../plot/util/UUIDHandlerImplementation.java | 2 +- .../general/commands/Argument.java | 3 +- .../plotsquared/general/commands/Command.java | 3 +- .../plotsquared/listener/PlotListener.java | 5 +- .../plotsquared/listener/WESubscriber.java | 3 +- .../plot/database/AbstractDBTEst.java | 150 ++++++------------ .../plot/util/EventUtilTest.java | 18 +-- .../generator/SpongeAugmentedGenerator.java | 3 +- .../plotsquared/sponge/util/SpongeUtil.java | 42 ++--- 68 files changed, 377 insertions(+), 595 deletions(-) diff --git a/Bukkit/src/main/java/com/intellectualcrafters/plot/api/PlotAPI.java b/Bukkit/src/main/java/com/intellectualcrafters/plot/api/PlotAPI.java index 32405d01d..5105ae664 100644 --- a/Bukkit/src/main/java/com/intellectualcrafters/plot/api/PlotAPI.java +++ b/Bukkit/src/main/java/com/intellectualcrafters/plot/api/PlotAPI.java @@ -54,8 +54,7 @@ public class PlotAPI { * @deprecated Not needed */ @Deprecated - public PlotAPI(JavaPlugin plugin) { - } + public PlotAPI(JavaPlugin plugin) {} /** * Get all plots. diff --git a/Bukkit/src/main/java/com/plotsquared/bukkit/BukkitMain.java b/Bukkit/src/main/java/com/plotsquared/bukkit/BukkitMain.java index 03b667983..3a51307c2 100644 --- a/Bukkit/src/main/java/com/plotsquared/bukkit/BukkitMain.java +++ b/Bukkit/src/main/java/com/plotsquared/bukkit/BukkitMain.java @@ -141,9 +141,7 @@ public final class BukkitMain extends JavaPlugin implements Listener, IPlotMain } this.getServer().getConsoleSender().sendMessage(message); return; - } catch (Throwable ignored) { - //ignored - } + } catch (Throwable ignored) {} System.out.println(ConsoleColors.fromString(message)); } @@ -401,14 +399,14 @@ public final class BukkitMain extends JavaPlugin implements Listener, IPlotMain try { new SendChunk(); MainUtil.canSendChunk = true; - } catch (Throwable e) { + } catch (ClassNotFoundException | NoSuchFieldException | NoSuchMethodException e) { e.printStackTrace(); MainUtil.canSendChunk = false; } if (PS.get().checkVersion(getServerVersion(), 1, 9, 0)) { try { return new FastQueue_1_9(); - } catch (Throwable e) { + } catch (ClassNotFoundException | NoSuchFieldException | NoSuchMethodException e) { e.printStackTrace(); return new SlowQueue(); } @@ -416,11 +414,11 @@ public final class BukkitMain extends JavaPlugin implements Listener, IPlotMain if (PS.get().checkVersion(getServerVersion(), 1, 8, 0)) { try { return new FastQueue_1_8_3(); - } catch (Throwable e) { + } catch (NoSuchMethodException | ClassNotFoundException | NoSuchFieldException e) { e.printStackTrace(); try { return new FastQueue_1_8(); - } catch (Throwable e2) { + } catch (NoSuchMethodException | NoSuchFieldException | ClassNotFoundException e2) { e2.printStackTrace(); return new SlowQueue(); } @@ -428,7 +426,7 @@ public final class BukkitMain extends JavaPlugin implements Listener, IPlotMain } try { return new FastQueue_1_7(); - } catch (Throwable e) { + } catch (ClassNotFoundException | NoSuchFieldException | NoSuchMethodException e) { e.printStackTrace(); return new SlowQueue(); } @@ -657,7 +655,7 @@ public final class BukkitMain extends JavaPlugin implements Listener, IPlotMain public List getPluginIds() { ArrayList names = new ArrayList<>(); for (Plugin plugin : Bukkit.getPluginManager().getPlugins()) { - names.add(plugin.getName() + ";" + plugin.getDescription().getVersion() + ":" + plugin.isEnabled()); + names.add(plugin.getName() + ';' + plugin.getDescription().getVersion() + ':' + plugin.isEnabled()); } return names; } diff --git a/Bukkit/src/main/java/com/plotsquared/bukkit/commands/DebugUUID.java b/Bukkit/src/main/java/com/plotsquared/bukkit/commands/DebugUUID.java index 716b37530..7e738bae2 100644 --- a/Bukkit/src/main/java/com/plotsquared/bukkit/commands/DebugUUID.java +++ b/Bukkit/src/main/java/com/plotsquared/bukkit/commands/DebugUUID.java @@ -285,7 +285,7 @@ public class DebugUUID extends SubCommand { } try { PS.get().config.save(PS.get().configFile); - } catch (IOException e) { + } catch (IOException ignored) { MainUtil.sendMessage(player, "Could not save configuration. It will need to be manual set!"); } diff --git a/Bukkit/src/main/java/com/plotsquared/bukkit/database/plotme/ClassicPlotMeConnector.java b/Bukkit/src/main/java/com/plotsquared/bukkit/database/plotme/ClassicPlotMeConnector.java index 3e6ee0184..d237706a4 100644 --- a/Bukkit/src/main/java/com/plotsquared/bukkit/database/plotme/ClassicPlotMeConnector.java +++ b/Bukkit/src/main/java/com/plotsquared/bukkit/database/plotme/ClassicPlotMeConnector.java @@ -42,9 +42,8 @@ public class ClassicPlotMeConnector extends APlotMeConnector { } else { return new SQLite(dataFolder + File.separator + "plots.db").openConnection(); } - } catch (SQLException | ClassNotFoundException ignored) { - //ignored - ignored.printStackTrace(); + } catch (SQLException | ClassNotFoundException e) { + e.printStackTrace(); } return null; } @@ -229,9 +228,7 @@ public class ClassicPlotMeConnector extends APlotMeConnector { resultSet.close(); statement.close(); - } catch (SQLException ignored) { - //ignored - } + } catch (SQLException ignored) {} return plots; } diff --git a/Bukkit/src/main/java/com/plotsquared/bukkit/database/plotme/LikePlotMeConverter.java b/Bukkit/src/main/java/com/plotsquared/bukkit/database/plotme/LikePlotMeConverter.java index 205cd6eec..97ed3bc3f 100644 --- a/Bukkit/src/main/java/com/plotsquared/bukkit/database/plotme/LikePlotMeConverter.java +++ b/Bukkit/src/main/java/com/plotsquared/bukkit/database/plotme/LikePlotMeConverter.java @@ -200,9 +200,7 @@ public class LikePlotMeConverter { PS.get().config.set("worlds." + actualWorldName + ".wall.height", height); PS.get().config.save(PS.get().configFile); } - } catch (IOException ignored) { - //ignored - } + } catch (IOException ignored) {} } for (Entry> entry : plots.entrySet()) { String world = entry.getKey(); diff --git a/Bukkit/src/main/java/com/plotsquared/bukkit/generator/BukkitPlotGenerator.java b/Bukkit/src/main/java/com/plotsquared/bukkit/generator/BukkitPlotGenerator.java index f56473119..d4af8e08a 100644 --- a/Bukkit/src/main/java/com/plotsquared/bukkit/generator/BukkitPlotGenerator.java +++ b/Bukkit/src/main/java/com/plotsquared/bukkit/generator/BukkitPlotGenerator.java @@ -233,7 +233,7 @@ public class BukkitPlotGenerator extends ChunkGenerator implements GeneratorWrap } catch (Exception e) { e.printStackTrace(); } - ArrayList toAdd = new ArrayList(); + ArrayList toAdd = new ArrayList<>(); List existing = world.getPopulators(); for (BlockPopulator populator : this.populators) { if (!existing.contains(populator)) { diff --git a/Bukkit/src/main/java/com/plotsquared/bukkit/listeners/worldedit/WEListener.java b/Bukkit/src/main/java/com/plotsquared/bukkit/listeners/worldedit/WEListener.java index 4c154fdaa..45e2d5922 100644 --- a/Bukkit/src/main/java/com/plotsquared/bukkit/listeners/worldedit/WEListener.java +++ b/Bukkit/src/main/java/com/plotsquared/bukkit/listeners/worldedit/WEListener.java @@ -31,22 +31,21 @@ import java.util.Set; public class WEListener implements Listener { - public final HashSet rad1 = new HashSet<>( + public final Set other = new HashSet<>(Arrays.asList("undo", "redo")); + private final Set rad1 = new HashSet<>( Arrays.asList("forestgen", "pumpkins", "drain", "fixwater", "fixlava", "replacenear", "snow", "thaw", "ex", "butcher", "size")); - public final HashSet rad2 = new HashSet<>(Arrays.asList("fill", "fillr", "removenear", "remove")); - public final HashSet rad2_1 = new HashSet<>(Arrays.asList("hcyl", "cyl")); - public final HashSet rad2_2 = new HashSet<>(Arrays.asList("sphere", "pyramid")); - public final Set rad2_3 = Collections.singleton("brush smooth"); - public final Set rad3_1 = Collections.singleton("brush gravity"); - public final HashSet rad3_2 = new HashSet<>(Arrays.asList("brush sphere", "brush cylinder")); - - public final HashSet region = new HashSet<>( + private final Set rad2 = new HashSet<>(Arrays.asList("fill", "fillr", "removenear", "remove")); + private final Set rad2_1 = new HashSet<>(Arrays.asList("hcyl", "cyl")); + private final Set rad2_2 = new HashSet<>(Arrays.asList("sphere", "pyramid")); + private final Set rad2_3 = Collections.singleton("brush smooth"); + private final Set rad3_1 = Collections.singleton("brush gravity"); + private final Set rad3_2 = new HashSet<>(Arrays.asList("brush sphere", "brush cylinder")); + private final Set region = new HashSet<>( Arrays.asList("move", "set", "replace", "overlay", "walls", "outline", "deform", "hollow", "smooth", "naturalize", "paste", "count", "distr", "regen", "copy", "cut", "green", "setbiome")); - public final Set regionExtend = Collections.singleton("stack"); - public final Set restricted = Collections.singleton("up"); - public final HashSet other = new HashSet<>(Arrays.asList("undo", "redo")); + private final Set regionExtend = Collections.singleton("stack"); + private final Set restricted = Collections.singleton("up"); public String reduceCmd(String cmd, boolean single) { if (cmd.startsWith("/worldedit:/")) { @@ -75,14 +74,14 @@ public class WEListener implements Listener { } } return max; - } catch (NumberFormatException e) { + } catch (NumberFormatException ignored) { return 0; } } public boolean checkVolume(PlotPlayer player, long volume, long max, Cancellable e) { if (volume > max) { - MainUtil.sendMessage(player, C.WORLDEDIT_VOLUME.s().replaceAll("%current%", volume + "").replaceAll("%max%", max + "")); + MainUtil.sendMessage(player, C.WORLDEDIT_VOLUME.s().replaceAll("%current%", String.valueOf(volume)).replaceAll("%max%", String.valueOf(max))); e.setCancelled(true); } if (Permissions.hasPermission(player, "plots.worldedit.bypass")) { @@ -181,7 +180,7 @@ public class WEListener implements Listener { boolean single = true; if (split.length >= 2) { String reduced = reduceCmd(split[0], single); - String reduced2 = reduceCmd(split[0] + " " + split[1], single); + String reduced2 = reduceCmd(split[0] + ' ' + split[1], single); if (this.rad1.contains(reduced)) { if (delay(p, message, false)) { e.setCancelled(true); @@ -234,7 +233,8 @@ public class WEListener implements Listener { int iterations = getInt(split[3]); if (iterations > maxIterations) { MainUtil.sendMessage(pp, - C.WORLDEDIT_ITERATIONS.s().replaceAll("%current%", iterations + "").replaceAll("%max%", maxIterations + "")); + C.WORLDEDIT_ITERATIONS.s().replaceAll("%current%", String.valueOf(iterations)).replaceAll("%max%", + String.valueOf(maxIterations))); e.setCancelled(true); if (Permissions.hasPermission(pp, "plots.worldedit.bypass")) { MainUtil.sendMessage(pp, C.WORLDEDIT_BYPASS); diff --git a/Bukkit/src/main/java/com/plotsquared/bukkit/object/entity/EntityWrapper.java b/Bukkit/src/main/java/com/plotsquared/bukkit/object/entity/EntityWrapper.java index ba61f6c89..0ae98e8a1 100644 --- a/Bukkit/src/main/java/com/plotsquared/bukkit/object/entity/EntityWrapper.java +++ b/Bukkit/src/main/java/com/plotsquared/bukkit/object/entity/EntityWrapper.java @@ -465,8 +465,7 @@ public class EntityWrapper { if (this.base.passenger != null) { try { entity.setPassenger(this.base.passenger.spawn(world, x_offset, z_offset)); - } catch (Exception ignored) { - } + } catch (Exception ignored) {} } if (this.base.fall != 0) { entity.setFallDistance(this.base.fall); diff --git a/Bukkit/src/main/java/com/plotsquared/bukkit/titles/HackTitleManager.java b/Bukkit/src/main/java/com/plotsquared/bukkit/titles/HackTitleManager.java index de5774cd4..a652be9f9 100644 --- a/Bukkit/src/main/java/com/plotsquared/bukkit/titles/HackTitleManager.java +++ b/Bukkit/src/main/java/com/plotsquared/bukkit/titles/HackTitleManager.java @@ -143,8 +143,7 @@ public class HackTitleManager extends TitleManager { private Class getClass(String namespace) { try { return Class.forName(namespace); - } catch (ClassNotFoundException ignored) { - } + } catch (ClassNotFoundException ignored) {} return null; } diff --git a/Bukkit/src/main/java/com/plotsquared/bukkit/util/BukkitChunkManager.java b/Bukkit/src/main/java/com/plotsquared/bukkit/util/BukkitChunkManager.java index 7d1a89709..54769acc1 100644 --- a/Bukkit/src/main/java/com/plotsquared/bukkit/util/BukkitChunkManager.java +++ b/Bukkit/src/main/java/com/plotsquared/bukkit/util/BukkitChunkManager.java @@ -58,6 +58,7 @@ import java.util.Collections; import java.util.HashMap; import java.util.HashSet; import java.util.List; +import java.util.Map; import java.util.Map.Entry; import java.util.Set; @@ -616,25 +617,25 @@ public class BukkitChunkManager extends ChunkManager { public static class ContentMap { - public final HashMap chestContents; - public final HashMap furnaceContents; - public final HashMap dispenserContents; - public final HashMap dropperContents; - public final HashMap brewingStandContents; - public final HashMap beaconContents; - public final HashMap hopperContents; - public final HashMap furnaceTime; - public final HashMap skullData; - public final HashMap jukeboxDisc; - public final HashMap brewTime; - public final HashMap spawnerData; - public final HashMap cmdData; - public final HashMap signContents; - public final HashMap noteBlockContents; - public final HashMap> bannerPatterns; - public final HashMap bannerBase; - public final HashSet entities; - public final HashMap allBlocks; + public final Map chestContents; + public final Map furnaceContents; + public final Map dispenserContents; + public final Map dropperContents; + public final Map brewingStandContents; + public final Map beaconContents; + public final Map hopperContents; + public final Map furnaceTime; + public final Map skullData; + public final Map jukeboxDisc; + public final Map brewTime; + public final Map spawnerData; + public final Map cmdData; + public final Map signContents; + public final Map noteBlockContents; + public final Map> bannerPatterns; + public final Map bannerBase; + public final Set entities; + public final Map allBlocks; public ContentMap() { this.chestContents = new HashMap<>(); diff --git a/Bukkit/src/main/java/com/plotsquared/bukkit/util/BukkitHybridUtils.java b/Bukkit/src/main/java/com/plotsquared/bukkit/util/BukkitHybridUtils.java index 06a02fe56..3ce09c872 100644 --- a/Bukkit/src/main/java/com/plotsquared/bukkit/util/BukkitHybridUtils.java +++ b/Bukkit/src/main/java/com/plotsquared/bukkit/util/BukkitHybridUtils.java @@ -49,8 +49,7 @@ public class BukkitHybridUtils extends HybridUtils { } final BiomeGrid nullBiomeGrid = new BiomeGrid() { @Override - public void setBiome(int a, int b, Biome c) { - } + public void setBiome(int a, int b, Biome c) {} @Override public Biome getBiome(int a, int b) { diff --git a/Bukkit/src/main/java/com/plotsquared/bukkit/util/BukkitPlainChatManager.java b/Bukkit/src/main/java/com/plotsquared/bukkit/util/BukkitPlainChatManager.java index a0cd0d70a..11872a8db 100644 --- a/Bukkit/src/main/java/com/plotsquared/bukkit/util/BukkitPlainChatManager.java +++ b/Bukkit/src/main/java/com/plotsquared/bukkit/util/BukkitPlainChatManager.java @@ -22,12 +22,10 @@ public class BukkitPlainChatManager extends ChatManager> { } @Override - public void tooltip(PlotMessage message, PlotMessage... tooltips) { - } + public void tooltip(PlotMessage message, PlotMessage... tooltips) {} @Override - public void command(PlotMessage message, String command) { - } + public void command(PlotMessage message, String command) {} @Override public void text(PlotMessage message, String text) { @@ -44,7 +42,6 @@ public class BukkitPlainChatManager extends ChatManager> { } @Override - public void suggest(PlotMessage plotMessage, String command) { - } + public void suggest(PlotMessage plotMessage, String command) {} } diff --git a/Bukkit/src/main/java/com/plotsquared/bukkit/util/BukkitUtil.java b/Bukkit/src/main/java/com/plotsquared/bukkit/util/BukkitUtil.java index fff80fe74..a7b8990d6 100644 --- a/Bukkit/src/main/java/com/plotsquared/bukkit/util/BukkitUtil.java +++ b/Bukkit/src/main/java/com/plotsquared/bukkit/util/BukkitUtil.java @@ -271,8 +271,7 @@ public class BukkitUtil extends WorldUtil { try { Material material = Material.valueOf(name.toUpperCase()); return new StringComparison().new ComparisonResult(0, new PlotBlock((short) material.getId(), (byte) 0)); - } catch (IllegalArgumentException ignored) { - } + } catch (IllegalArgumentException ignored) {} try { byte data; String[] split = name.split(":"); @@ -296,8 +295,7 @@ public class BukkitUtil extends WorldUtil { StringComparison outer = new StringComparison<>(); return outer.new ComparisonResult(match, block); - } catch (NumberFormatException ignored) { - } + } catch (NumberFormatException ignored) {} return null; } diff --git a/Bukkit/src/main/java/com/plotsquared/bukkit/util/Metrics.java b/Bukkit/src/main/java/com/plotsquared/bukkit/util/Metrics.java index 52afe43f7..151678f28 100644 --- a/Bukkit/src/main/java/com/plotsquared/bukkit/util/Metrics.java +++ b/Bukkit/src/main/java/com/plotsquared/bukkit/util/Metrics.java @@ -95,8 +95,7 @@ public class Metrics { if (gzos != null) { try { gzos.close(); - } catch (IOException ignore) { - } + } catch (IOException ignore) {} } } return baos.toByteArray(); @@ -117,7 +116,7 @@ public class Metrics { Double.parseDouble(value); isValueNumeric = true; } - } catch (NumberFormatException e) { + } catch (NumberFormatException ignored) { isValueNumeric = false; } if (json.charAt(json.length() - 1) != '{') { @@ -446,7 +445,7 @@ public class Metrics { try { Class.forName("mineshafter.MineServer"); return true; - } catch (ClassNotFoundException e) { + } catch (ClassNotFoundException ignored) { return false; } } @@ -569,8 +568,7 @@ public class Metrics { /** * Called after the website graphs have been updated */ - public void reset() { - } + public void reset() {} @Override public int hashCode() { diff --git a/Bukkit/src/main/java/com/plotsquared/bukkit/util/SendChunk.java b/Bukkit/src/main/java/com/plotsquared/bukkit/util/SendChunk.java index 4365998d6..b59d912e2 100644 --- a/Bukkit/src/main/java/com/plotsquared/bukkit/util/SendChunk.java +++ b/Bukkit/src/main/java/com/plotsquared/bukkit/util/SendChunk.java @@ -42,7 +42,7 @@ public class SendChunk { /** * Constructor */ - public SendChunk() { + public SendChunk() throws ClassNotFoundException, NoSuchMethodException, NoSuchFieldException { RefClass classCraftPlayer = getRefClass("{cb}.entity.CraftPlayer"); this.methodGetHandlePlayer = classCraftPlayer.getMethod("getHandle"); RefClass classCraftChunk = getRefClass("{cb}.CraftChunk"); diff --git a/Bukkit/src/main/java/com/plotsquared/bukkit/util/block/FastQueue_1_7.java b/Bukkit/src/main/java/com/plotsquared/bukkit/util/block/FastQueue_1_7.java index 7db7cfef8..b29f5826f 100644 --- a/Bukkit/src/main/java/com/plotsquared/bukkit/util/block/FastQueue_1_7.java +++ b/Bukkit/src/main/java/com/plotsquared/bukkit/util/block/FastQueue_1_7.java @@ -38,7 +38,7 @@ public class FastQueue_1_7 extends SlowQueue { private final HashMap toUpdate = new HashMap<>(); - public FastQueue_1_7() throws RuntimeException { + public FastQueue_1_7() throws NoSuchMethodException, ClassNotFoundException, NoSuchFieldException { this.methodGetHandle = this.classCraftWorld.getMethod("getHandle"); this.methodGetChunkAt = this.classWorld.getMethod("getChunkAt", int.class, int.class); this.methodA = this.classChunk.getMethod("a", int.class, int.class, int.class, this.classBlock, int.class); diff --git a/Bukkit/src/main/java/com/plotsquared/bukkit/util/block/FastQueue_1_8.java b/Bukkit/src/main/java/com/plotsquared/bukkit/util/block/FastQueue_1_8.java index b534ec3f4..139e14c24 100644 --- a/Bukkit/src/main/java/com/plotsquared/bukkit/util/block/FastQueue_1_8.java +++ b/Bukkit/src/main/java/com/plotsquared/bukkit/util/block/FastQueue_1_8.java @@ -41,7 +41,7 @@ public class FastQueue_1_8 extends SlowQueue { private final RefConstructor constructorBlockPosition; private final SendChunk sendChunk; - public FastQueue_1_8() throws RuntimeException { + public FastQueue_1_8() throws NoSuchMethodException, ClassNotFoundException, NoSuchFieldException { this.methodInitLighting = this.classChunk.getMethod("initLighting"); this.constructorBlockPosition = this.classBlockPosition.getConstructor(int.class, int.class, int.class); this.methodGetByCombinedId = this.classBlock.getMethod("getByCombinedId", int.class); @@ -56,7 +56,7 @@ public class FastQueue_1_8 extends SlowQueue { return; } int count = 0; - ArrayList chunks = new ArrayList(); + ArrayList chunks = new ArrayList<>(); Iterator> i = FastQueue_1_8.this.toUpdate.entrySet().iterator(); while (i.hasNext() && count < 128) { chunks.add(i.next().getValue()); diff --git a/Bukkit/src/main/java/com/plotsquared/bukkit/util/block/FastQueue_1_8_3.java b/Bukkit/src/main/java/com/plotsquared/bukkit/util/block/FastQueue_1_8_3.java index f679a01c2..ee0cb7eb1 100644 --- a/Bukkit/src/main/java/com/plotsquared/bukkit/util/block/FastQueue_1_8_3.java +++ b/Bukkit/src/main/java/com/plotsquared/bukkit/util/block/FastQueue_1_8_3.java @@ -49,7 +49,7 @@ public class FastQueue_1_8_3 extends SlowQueue { private final RefMethod methodGetWorld; private final RefField tileEntityListTick; - public FastQueue_1_8_3() throws RuntimeException { + public FastQueue_1_8_3() throws NoSuchMethodException, ClassNotFoundException, NoSuchFieldException { RefClass classCraftChunk = getRefClass("{cb}.CraftChunk"); RefClass classCraftWorld = getRefClass("{cb}.CraftWorld"); this.methodGetHandleChunk = classCraftChunk.getMethod("getHandle"); diff --git a/Bukkit/src/main/java/com/plotsquared/bukkit/util/block/FastQueue_1_9.java b/Bukkit/src/main/java/com/plotsquared/bukkit/util/block/FastQueue_1_9.java index c3e4ea506..79d30d56a 100644 --- a/Bukkit/src/main/java/com/plotsquared/bukkit/util/block/FastQueue_1_9.java +++ b/Bukkit/src/main/java/com/plotsquared/bukkit/util/block/FastQueue_1_9.java @@ -53,7 +53,7 @@ public class FastQueue_1_9 extends SlowQueue { private final RefField tileEntityListTick; - public FastQueue_1_9() throws RuntimeException { + public FastQueue_1_9() throws NoSuchFieldException, NoSuchMethodException, ClassNotFoundException { RefClass classCraftChunk = getRefClass("{cb}.CraftChunk"); this.methodGetHandleChunk = classCraftChunk.getMethod("getHandle"); RefClass classChunk = getRefClass("{nms}.Chunk"); diff --git a/Bukkit/src/main/java/com/plotsquared/bukkit/uuid/OfflineUUIDWrapper.java b/Bukkit/src/main/java/com/plotsquared/bukkit/uuid/OfflineUUIDWrapper.java index a33c506f6..273ff8fc1 100644 --- a/Bukkit/src/main/java/com/plotsquared/bukkit/uuid/OfflineUUIDWrapper.java +++ b/Bukkit/src/main/java/com/plotsquared/bukkit/uuid/OfflineUUIDWrapper.java @@ -14,6 +14,7 @@ import org.bukkit.OfflinePlayer; import org.bukkit.Server; import org.bukkit.entity.Player; +import java.lang.reflect.InvocationTargetException; import java.lang.reflect.Method; import java.util.Collection; import java.util.UUID; @@ -48,11 +49,9 @@ public class OfflineUUIDWrapper extends UUIDWrapper { @Override public OfflinePlotPlayer getOfflinePlayer(UUID uuid) { BiMap map = UUIDHandler.getUuidMap().inverse(); - String name; - try { + String name = null; + if (map.containsKey(uuid)) { name = map.get(uuid).value; - } catch (NullPointerException e) { - name = null; } if (name != null) { OfflinePlayer op = Bukkit.getOfflinePlayer(name); @@ -81,7 +80,7 @@ public class OfflineUUIDWrapper extends UUIDWrapper { @SuppressWarnings("unchecked") Collection p = (Collection) players; return p.toArray(new Player[p.size()]); } - } catch (Exception e) { + } catch (IllegalAccessException | InvocationTargetException | IllegalArgumentException ignored) { PS.debug("Failed to resolve online players"); this.getOnline = null; Collection onlinePlayers = Bukkit.getOnlinePlayers(); diff --git a/Core/src/main/java/com/intellectualcrafters/configuration/ConfigurationOptions.java b/Core/src/main/java/com/intellectualcrafters/configuration/ConfigurationOptions.java index 2c7766890..067493ee5 100644 --- a/Core/src/main/java/com/intellectualcrafters/configuration/ConfigurationOptions.java +++ b/Core/src/main/java/com/intellectualcrafters/configuration/ConfigurationOptions.java @@ -4,10 +4,10 @@ package com.intellectualcrafters.configuration; * Various settings for controlling the input and output of a {@link * Configuration} */ -public class ConfigurationOptions { +class ConfigurationOptions { + private final Configuration configuration; private char pathSeparator = '.'; private boolean copyDefaults = false; - private final Configuration configuration; protected ConfigurationOptions(final Configuration configuration) { this.configuration = configuration; diff --git a/Core/src/main/java/com/intellectualcrafters/configuration/MemorySection.java b/Core/src/main/java/com/intellectualcrafters/configuration/MemorySection.java index b817358dd..70db80141 100644 --- a/Core/src/main/java/com/intellectualcrafters/configuration/MemorySection.java +++ b/Core/src/main/java/com/intellectualcrafters/configuration/MemorySection.java @@ -76,8 +76,7 @@ public class MemorySection implements ConfigurationSection { if (obj instanceof String) { try { return Double.parseDouble((String) obj); - } catch (NumberFormatException ignored) { - } + } catch (NumberFormatException ignored) {} } else if (obj instanceof List) { List val = (List) obj; if (!val.isEmpty()) { @@ -94,8 +93,7 @@ public class MemorySection implements ConfigurationSection { if (obj instanceof String) { try { return Integer.parseInt((String) obj); - } catch (NumberFormatException ignored) { - } + } catch (NumberFormatException ignored) {} } else if (obj instanceof List) { List val = (List) obj; if (!val.isEmpty()) { @@ -112,8 +110,7 @@ public class MemorySection implements ConfigurationSection { if (obj instanceof String) { try { return Long.parseLong((String) obj); - } catch (NumberFormatException ignored) { - } + } catch (NumberFormatException ignored) {} } else if (obj instanceof List) { List val = (List) obj; if (!val.isEmpty()) { @@ -569,8 +566,7 @@ public class MemorySection implements ConfigurationSection { } else if (object instanceof String) { try { result.add(Integer.valueOf((String) object)); - } catch (NumberFormatException ignored) { - } + } catch (NumberFormatException ignored) {} } else if (object instanceof Character) { result.add((int) (Character) object); } else if (object instanceof Number) { @@ -614,8 +610,7 @@ public class MemorySection implements ConfigurationSection { } else if (object instanceof String) { try { result.add(Double.valueOf((String) object)); - } catch (NumberFormatException ignored) { - } + } catch (NumberFormatException ignored) {} } else if (object instanceof Character) { result.add((double) (Character) object); } else if (object instanceof Number) { @@ -638,8 +633,7 @@ public class MemorySection implements ConfigurationSection { } else if (object instanceof String) { try { result.add(Float.valueOf((String) object)); - } catch (NumberFormatException ignored) { - } + } catch (NumberFormatException ignored) {} } else if (object instanceof Character) { result.add((float) (Character) object); } else if (object instanceof Number) { @@ -662,8 +656,7 @@ public class MemorySection implements ConfigurationSection { } else if (object instanceof String) { try { result.add(Long.valueOf((String) object)); - } catch (NumberFormatException ignored) { - } + } catch (NumberFormatException ignored) {} } else if (object instanceof Character) { result.add((long) (Character) object); } else if (object instanceof Number) { @@ -686,8 +679,7 @@ public class MemorySection implements ConfigurationSection { } else if (object instanceof String) { try { result.add(Byte.valueOf((String) object)); - } catch (NumberFormatException ignored) { - } + } catch (NumberFormatException ignored) {} } else if (object instanceof Character) { result.add((byte) ((Character) object).charValue()); } else if (object instanceof Number) { @@ -733,8 +725,7 @@ public class MemorySection implements ConfigurationSection { } else if (object instanceof String) { try { result.add(Short.valueOf((String) object)); - } catch (NumberFormatException ignored) { - } + } catch (NumberFormatException ignored) {} } else if (object instanceof Character) { result.add((short) ((Character) object).charValue()); } else if (object instanceof Number) { diff --git a/Core/src/main/java/com/intellectualcrafters/configuration/file/FileConfiguration.java b/Core/src/main/java/com/intellectualcrafters/configuration/file/FileConfiguration.java index ff7fd88c8..dcdec3c34 100644 --- a/Core/src/main/java/com/intellectualcrafters/configuration/file/FileConfiguration.java +++ b/Core/src/main/java/com/intellectualcrafters/configuration/file/FileConfiguration.java @@ -25,8 +25,7 @@ public abstract class FileConfiguration extends MemoryConfiguration { /** * Creates an empty {@link FileConfiguration} with no default values. */ - public FileConfiguration() { - } + FileConfiguration() {} /** * Creates an empty {@link FileConfiguration} using the specified {@link @@ -54,9 +53,6 @@ public abstract class FileConfiguration extends MemoryConfiguration { * @throws IllegalArgumentException Thrown when file is null. */ public void save(File file) throws IOException { - if (file == null) { - throw new NullPointerException("File cannot be null"); - } file.getParentFile().mkdirs(); String data = saveToString(); @@ -65,30 +61,7 @@ public abstract class FileConfiguration extends MemoryConfiguration { writer.write(data); } } - - /** - * Saves this {@link FileConfiguration} to the specified location. - *

- * If the file does not exist, it will be created. If already exists, it - * will be overwritten. If it cannot be overwritten or created, an - * exception will be thrown. - *

- * This method will save using the system default encoding, or possibly - * using UTF8. - * - * @param file File to save to. - * @throws IOException Thrown when the given file cannot be written to for - * any reason. - * @throws IllegalArgumentException Thrown when file is null. - */ - public void save(String file) throws IOException { - if (file == null) { - throw new NullPointerException("File cannot be null"); - } - - save(new File(file)); - } - + /** * Saves this {@link FileConfiguration} to a string, and returns it. * diff --git a/Core/src/main/java/com/intellectualcrafters/configuration/file/YamlConfiguration.java b/Core/src/main/java/com/intellectualcrafters/configuration/file/YamlConfiguration.java index f869b3eea..59ad896c1 100644 --- a/Core/src/main/java/com/intellectualcrafters/configuration/file/YamlConfiguration.java +++ b/Core/src/main/java/com/intellectualcrafters/configuration/file/YamlConfiguration.java @@ -21,8 +21,8 @@ import java.util.Map; * Note that this implementation is not synchronized. */ public class YamlConfiguration extends FileConfiguration { - protected static final String COMMENT_PREFIX = "# "; - protected static final String BLANK_CONFIG = "{}\n"; + private static final String COMMENT_PREFIX = "# "; + private static final String BLANK_CONFIG = "{}\n"; private final DumperOptions yamlOptions = new DumperOptions(); private final Representer yamlRepresenter = new YamlRepresenter(); private final Yaml yaml = new Yaml(new YamlConstructor(), yamlRepresenter, yamlOptions); @@ -40,7 +40,7 @@ public class YamlConfiguration extends FileConfiguration { * @return Resulting configuration * @throws IllegalArgumentException Thrown if file is null */ - public static YamlConfiguration loadConfiguration(final File file) { + public static YamlConfiguration loadConfiguration(File file) { if (file == null) { throw new NullPointerException("File cannot be null"); } @@ -163,7 +163,7 @@ public class YamlConfiguration extends FileConfiguration { if (line.startsWith(COMMENT_PREFIX)) { if (i > 0) { - result.append("\n"); + result.append('\n'); } if (line.length() > COMMENT_PREFIX.length()) { @@ -172,7 +172,7 @@ public class YamlConfiguration extends FileConfiguration { foundHeader = true; } else if (foundHeader && line.isEmpty()) { - result.append("\n"); + result.append('\n'); } else if (foundHeader) { readingHeader = false; } @@ -189,8 +189,8 @@ public class YamlConfiguration extends FileConfiguration { final Configuration def = getDefaults(); if (def instanceof FileConfiguration) { - final FileConfiguration filedefaults = (FileConfiguration) def; - final String defaultsHeader = filedefaults.buildHeader(); + final FileConfiguration fileDefaults = (FileConfiguration) def; + final String defaultsHeader = fileDefaults.buildHeader(); if ((defaultsHeader != null) && !defaultsHeader.isEmpty()) { return defaultsHeader; @@ -207,7 +207,7 @@ public class YamlConfiguration extends FileConfiguration { boolean startedHeader = false; for (int i = lines.length - 1; i >= 0; i--) { - builder.insert(0, "\n"); + builder.insert(0, '\n'); if (startedHeader || !lines[i].isEmpty()) { builder.insert(0, lines[i]); diff --git a/Core/src/main/java/com/intellectualcrafters/configuration/file/YamlConfigurationOptions.java b/Core/src/main/java/com/intellectualcrafters/configuration/file/YamlConfigurationOptions.java index 236325ae0..d33416387 100644 --- a/Core/src/main/java/com/intellectualcrafters/configuration/file/YamlConfigurationOptions.java +++ b/Core/src/main/java/com/intellectualcrafters/configuration/file/YamlConfigurationOptions.java @@ -7,7 +7,7 @@ package com.intellectualcrafters.configuration.file; public class YamlConfigurationOptions extends FileConfigurationOptions { private int indent = 2; - protected YamlConfigurationOptions(final YamlConfiguration configuration) { + YamlConfigurationOptions(final YamlConfiguration configuration) { super(configuration); } diff --git a/Core/src/main/java/com/intellectualcrafters/configuration/file/YamlConstructor.java b/Core/src/main/java/com/intellectualcrafters/configuration/file/YamlConstructor.java index fad595c5b..c70ea67b7 100644 --- a/Core/src/main/java/com/intellectualcrafters/configuration/file/YamlConstructor.java +++ b/Core/src/main/java/com/intellectualcrafters/configuration/file/YamlConstructor.java @@ -11,7 +11,7 @@ import java.util.Map; public class YamlConstructor extends SafeConstructor { - public YamlConstructor() { + YamlConstructor() { yamlConstructors.put(Tag.MAP, new ConstructCustomObject()); } diff --git a/Core/src/main/java/com/intellectualcrafters/configuration/file/YamlRepresenter.java b/Core/src/main/java/com/intellectualcrafters/configuration/file/YamlRepresenter.java index e1077556e..61eecfa1c 100644 --- a/Core/src/main/java/com/intellectualcrafters/configuration/file/YamlRepresenter.java +++ b/Core/src/main/java/com/intellectualcrafters/configuration/file/YamlRepresenter.java @@ -9,7 +9,7 @@ import org.yaml.snakeyaml.representer.Representer; import java.util.LinkedHashMap; import java.util.Map; -public class YamlRepresenter extends Representer { +class YamlRepresenter extends Representer { public YamlRepresenter() { this.multiRepresenters.put(ConfigurationSection.class, new RepresentConfigurationSection()); diff --git a/Core/src/main/java/com/intellectualcrafters/configuration/serialization/ConfigurationSerialization.java b/Core/src/main/java/com/intellectualcrafters/configuration/serialization/ConfigurationSerialization.java index 3bb971376..92b7edfba 100644 --- a/Core/src/main/java/com/intellectualcrafters/configuration/serialization/ConfigurationSerialization.java +++ b/Core/src/main/java/com/intellectualcrafters/configuration/serialization/ConfigurationSerialization.java @@ -17,8 +17,7 @@ import java.util.logging.Logger; public class ConfigurationSerialization { public static final String SERIALIZED_TYPE_KEY = "=="; - private static final Map> aliases = - new HashMap>(); + private static final Map> aliases = new HashMap<>(); private final Class clazz; protected ConfigurationSerialization(Class clazz) { @@ -128,8 +127,7 @@ public class ConfigurationSerialization { * @param clazz Class to unregister */ public static void unregisterClass(Class clazz) { - while (aliases.values().remove(clazz)) { - } + while (aliases.values().remove(clazz)) {} } /** @@ -154,7 +152,7 @@ public class ConfigurationSerialization { DelegateDeserialization delegate = clazz.getAnnotation(DelegateDeserialization.class); if (delegate != null) { - if ((delegate.value() == null) || (delegate.value() == clazz)) { + if (delegate.value() == clazz) { delegate = null; } else { return getAlias(delegate.value()); @@ -182,9 +180,7 @@ public class ConfigurationSerialization { } return method; - } catch (NoSuchMethodException ex) { - return null; - } catch (SecurityException ex) { + } catch (NoSuchMethodException | SecurityException ignored) { return null; } } @@ -192,9 +188,7 @@ public class ConfigurationSerialization { protected Constructor getConstructor() { try { return this.clazz.getConstructor(Map.class); - } catch (NoSuchMethodException ex) { - return null; - } catch (SecurityException ex) { + } catch (NoSuchMethodException | SecurityException ignored) { return null; } } diff --git a/Core/src/main/java/com/intellectualcrafters/jnbt/EndTag.java b/Core/src/main/java/com/intellectualcrafters/jnbt/EndTag.java index d22efc989..8c7eba1e1 100644 --- a/Core/src/main/java/com/intellectualcrafters/jnbt/EndTag.java +++ b/Core/src/main/java/com/intellectualcrafters/jnbt/EndTag.java @@ -8,8 +8,7 @@ public final class EndTag extends Tag { /** * Creates the tag. */ - public EndTag() { - } + public EndTag() {} @Override public Object getValue() { diff --git a/Core/src/main/java/com/intellectualcrafters/jnbt/NBTConstants.java b/Core/src/main/java/com/intellectualcrafters/jnbt/NBTConstants.java index add5b7498..43282b5ad 100644 --- a/Core/src/main/java/com/intellectualcrafters/jnbt/NBTConstants.java +++ b/Core/src/main/java/com/intellectualcrafters/jnbt/NBTConstants.java @@ -16,8 +16,7 @@ public final class NBTConstants { /** * Default private constructor. */ - private NBTConstants() { - } + private NBTConstants() {} /** * Convert a type ID to its corresponding {@link Tag} class. diff --git a/Core/src/main/java/com/intellectualcrafters/jnbt/NBTUtils.java b/Core/src/main/java/com/intellectualcrafters/jnbt/NBTUtils.java index 3b8bba993..a0f2cabd7 100644 --- a/Core/src/main/java/com/intellectualcrafters/jnbt/NBTUtils.java +++ b/Core/src/main/java/com/intellectualcrafters/jnbt/NBTUtils.java @@ -10,8 +10,7 @@ public final class NBTUtils { /** * Default private constructor. */ - private NBTUtils() { - } + private NBTUtils() {} /** * Gets the type name of a tag. diff --git a/Core/src/main/java/com/intellectualcrafters/json/JSONObject.java b/Core/src/main/java/com/intellectualcrafters/json/JSONObject.java index 1cb9f55d8..cb7b79aa6 100644 --- a/Core/src/main/java/com/intellectualcrafters/json/JSONObject.java +++ b/Core/src/main/java/com/intellectualcrafters/json/JSONObject.java @@ -88,8 +88,7 @@ public class JSONObject { for (String name : names) { try { putOnce(name, jo.opt(name)); - } catch (JSONException ignore) { - } + } catch (JSONException ignore) {} } } @@ -194,8 +193,7 @@ public class JSONObject { for (String name : names) { try { putOpt(name, c.getField(name).get(object)); - } catch (JSONException | SecurityException | NoSuchFieldException | IllegalArgumentException | IllegalAccessException ignore) { - } + } catch (JSONException | SecurityException | NoSuchFieldException | IllegalArgumentException | IllegalAccessException ignore) {} } } @@ -461,8 +459,7 @@ public class JSONObject { } } } - } catch (NumberFormatException ignore) { - } + } catch (NumberFormatException ignore) {} } return string; } @@ -586,7 +583,7 @@ public class JSONObject { return object.toString(); } return new JSONObject(object); - } catch (JSONException exception) { + } catch (JSONException ignored) { return null; } } @@ -734,7 +731,7 @@ public class JSONObject { Object object = get(key); try { return object instanceof Number ? ((Number) object).doubleValue() : Double.parseDouble((String) object); - } catch (NumberFormatException e) { + } catch (NumberFormatException ignored) { throw new JSONException("JSONObject[" + quote(key) + "] is not a number."); } } @@ -752,7 +749,7 @@ public class JSONObject { Object object = get(key); try { return object instanceof Number ? ((Number) object).intValue() : Integer.parseInt((String) object); - } catch (NumberFormatException e) { + } catch (NumberFormatException ignored) { throw new JSONException("JSONObject[" + quote(key) + "] is not an int."); } } @@ -804,7 +801,7 @@ public class JSONObject { Object object = get(key); try { return object instanceof Number ? ((Number) object).longValue() : Long.parseLong((String) object); - } catch (NumberFormatException e) { + } catch (NumberFormatException ignored) { throw new JSONException("JSONObject[" + quote(key) + "] is not a long."); } } @@ -953,7 +950,7 @@ public class JSONObject { public boolean optBoolean(String key, boolean defaultValue) { try { return getBoolean(key); - } catch (JSONException e) { + } catch (JSONException ignored) { return defaultValue; } } @@ -982,7 +979,7 @@ public class JSONObject { public double optDouble(String key, double defaultValue) { try { return getDouble(key); - } catch (JSONException e) { + } catch (JSONException ignored) { return defaultValue; } } @@ -1011,7 +1008,7 @@ public class JSONObject { public int optInt(String key, int defaultValue) { try { return getInt(key); - } catch (JSONException e) { + } catch (JSONException ignored) { return defaultValue; } } @@ -1066,7 +1063,7 @@ public class JSONObject { public long optLong(String key, long defaultValue) { try { return getLong(key); - } catch (JSONException e) { + } catch (JSONException ignored) { return defaultValue; } } @@ -1127,8 +1124,7 @@ public class JSONObject { } } } - } catch (IllegalAccessException | IllegalArgumentException | InvocationTargetException ignore) { - } + } catch (IllegalAccessException | IllegalArgumentException | InvocationTargetException ignore) {} } } @@ -1330,7 +1326,7 @@ public class JSONObject { } } return true; - } catch (JSONException exception) { + } catch (JSONException ignored) { return false; } } @@ -1370,7 +1366,7 @@ public class JSONObject { public String toString() { try { return this.toString(0); - } catch (JSONException e) { + } catch (JSONException ignored) { return null; } } @@ -1476,7 +1472,7 @@ public class JSONObject { protected final Object clone() { try { return super.clone(); - } catch (CloneNotSupportedException e) { + } catch (CloneNotSupportedException ignored) { return this; } } diff --git a/Core/src/main/java/com/intellectualcrafters/json/XML.java b/Core/src/main/java/com/intellectualcrafters/json/XML.java index ad3a3e509..5386b0b62 100644 --- a/Core/src/main/java/com/intellectualcrafters/json/XML.java +++ b/Core/src/main/java/com/intellectualcrafters/json/XML.java @@ -245,8 +245,7 @@ class XML { if (value.toString().equals(string)) { return value; } - } catch (NumberFormatException ignored) { - } + } catch (NumberFormatException ignored) {} } return string; } diff --git a/Core/src/main/java/com/intellectualcrafters/plot/PS.java b/Core/src/main/java/com/intellectualcrafters/plot/PS.java index 0007d967b..5d71d20df 100644 --- a/Core/src/main/java/com/intellectualcrafters/plot/PS.java +++ b/Core/src/main/java/com/intellectualcrafters/plot/PS.java @@ -829,7 +829,7 @@ public class PS { return result; } - public ArrayList sortPlotsByTemp(Collection plots) { + public List sortPlotsByTemp(Collection plots) { int max = 0; int overflowCount = 0; for (Plot plot : plots) { @@ -1761,7 +1761,7 @@ public class PS { // Close the connection DBFunc.close(); UUIDHandler.handleShutdown(); - } catch (NullPointerException e) { + } catch (NullPointerException ignored) { PS.log("&cCould not close database connection!"); } } @@ -2099,7 +2099,7 @@ public class PS { } this.config = YamlConfiguration.loadConfiguration(this.configFile); setupConfig(); - } catch (IOException err_trans) { + } catch (IOException ignored) { PS.log("Failed to save settings.yml"); } try { @@ -2111,7 +2111,7 @@ public class PS { } this.storage = YamlConfiguration.loadConfiguration(this.storageFile); setupStorage(); - } catch (IOException err_trans) { + } catch (IOException ignored) { PS.log("Failed to save storage.yml"); } try { @@ -2123,7 +2123,7 @@ public class PS { } this.commands = YamlConfiguration.loadConfiguration(this.commandsFile); setupStorage(); - } catch (IOException err_trans) { + } catch (IOException ignored) { PS.log("Failed to save commands.yml"); } try { diff --git a/Core/src/main/java/com/intellectualcrafters/plot/commands/Buy.java b/Core/src/main/java/com/intellectualcrafters/plot/commands/Buy.java index 8f603528d..54ea00d04 100644 --- a/Core/src/main/java/com/intellectualcrafters/plot/commands/Buy.java +++ b/Core/src/main/java/com/intellectualcrafters/plot/commands/Buy.java @@ -43,7 +43,7 @@ public class Buy extends SubCommand { return false; } plots = plot.getConnectedPlots(); - } catch (Exception e) { + } catch (Exception ignored) { return sendMessage(plr, C.NOT_VALID_PLOT_ID); } } else { diff --git a/Core/src/main/java/com/intellectualcrafters/plot/commands/Continue.java b/Core/src/main/java/com/intellectualcrafters/plot/commands/Continue.java index dfb3a1060..afe6e71fc 100644 --- a/Core/src/main/java/com/intellectualcrafters/plot/commands/Continue.java +++ b/Core/src/main/java/com/intellectualcrafters/plot/commands/Continue.java @@ -27,7 +27,7 @@ public class Continue extends SubCommand { MainUtil.sendMessage(plr, C.NO_PLOT_PERMS); return false; } - if (!plot.getFlags().containsKey("done")) { + if (!plot.hasFlag(Flags.DONE)) { MainUtil.sendMessage(plr, C.DONE_NOT_DONE); return false; } diff --git a/Core/src/main/java/com/intellectualcrafters/plot/commands/DebugExec.java b/Core/src/main/java/com/intellectualcrafters/plot/commands/DebugExec.java index 9121de624..47ae56c09 100644 --- a/Core/src/main/java/com/intellectualcrafters/plot/commands/DebugExec.java +++ b/Core/src/main/java/com/intellectualcrafters/plot/commands/DebugExec.java @@ -80,8 +80,7 @@ public class DebugExec extends SubCommand { this.engine.eval(script, this.scope); } } - } catch (IOException | ScriptException ignored) { - } + } catch (IOException | ScriptException ignored) {} } public ScriptEngine getEngine() { @@ -360,12 +359,7 @@ public class DebugExec extends SubCommand { @Override public void run(Integer i, File file, PlotMessage message) { String name = file.getName(); - - message.text("[").color("$3") - .text(i + "").color("$1") - .text("]").color("$3") - .text(" " + name).color("$1"); - + message.text("[").color("$3").text(String.valueOf(i)).color("$1").text("]").color("$3").text(' ' + name).color("$1"); } }, "/plot debugexec list-scripts", "List of scripts"); return true; diff --git a/Core/src/main/java/com/intellectualcrafters/plot/commands/Delete.java b/Core/src/main/java/com/intellectualcrafters/plot/commands/Delete.java index bb600c711..e1377b49a 100644 --- a/Core/src/main/java/com/intellectualcrafters/plot/commands/Delete.java +++ b/Core/src/main/java/com/intellectualcrafters/plot/commands/Delete.java @@ -12,8 +12,6 @@ import com.intellectualcrafters.plot.util.Permissions; import com.intellectualcrafters.plot.util.TaskManager; import com.plotsquared.general.commands.CommandDeclaration; -import java.util.HashSet; - @CommandDeclaration( command = "delete", permission = "plots.delete", @@ -40,7 +38,7 @@ public class Delete extends SubCommand { return !sendMessage(plr, C.NO_PLOT_PERMS); } final PlotArea plotworld = plot.getArea(); - final HashSet plots = plot.getConnectedPlots(); + final java.util.Set plots = plot.getConnectedPlots(); Runnable run = new Runnable() { @Override public void run() { @@ -57,7 +55,7 @@ public class Delete extends SubCommand { double value = plotworld.PRICES.get("sell") * plots.size(); if (value > 0d) { EconHandler.manager.depositMoney(plr, value); - sendMessage(plr, C.ADDED_BALANCE, value + ""); + sendMessage(plr, C.ADDED_BALANCE, String.valueOf(value)); } } MainUtil.sendMessage(plr, C.CLEARING_DONE, System.currentTimeMillis() - start); diff --git a/Core/src/main/java/com/intellectualcrafters/plot/commands/Done.java b/Core/src/main/java/com/intellectualcrafters/plot/commands/Done.java index d6354ee03..4df2939cc 100644 --- a/Core/src/main/java/com/intellectualcrafters/plot/commands/Done.java +++ b/Core/src/main/java/com/intellectualcrafters/plot/commands/Done.java @@ -2,8 +2,6 @@ package com.intellectualcrafters.plot.commands; import com.intellectualcrafters.plot.config.C; import com.intellectualcrafters.plot.config.Settings; -import com.intellectualcrafters.plot.flag.Flag; -import com.intellectualcrafters.plot.flag.FlagManager; import com.intellectualcrafters.plot.flag.Flags; import com.intellectualcrafters.plot.generator.HybridUtils; import com.intellectualcrafters.plot.object.Location; @@ -34,7 +32,7 @@ public class Done extends SubCommand { MainUtil.sendMessage(plr, C.NO_PLOT_PERMS); return false; } - if (plot.getFlags().containsKey("done")) { + if (plot.hasFlag(Flags.DONE)) { MainUtil.sendMessage(plr, C.DONE_ALREADY_DONE); return false; } @@ -50,8 +48,7 @@ public class Done extends SubCommand { plot.removeRunning(); if ((value == null) || (value.getComplexity() >= Settings.CLEAR_THRESHOLD)) { long flagValue = System.currentTimeMillis() / 1000; - Flag flag = Flags.DONE; - FlagManager.addPlotFlag(plot, flag, flagValue); + plot.setFlag(Flags.DONE,flagValue); MainUtil.sendMessage(plr, C.DONE_SUCCESS); } else { MainUtil.sendMessage(plr, C.DONE_INSUFFICIENT_COMPLEXITY); diff --git a/Core/src/main/java/com/intellectualcrafters/plot/commands/ListCmd.java b/Core/src/main/java/com/intellectualcrafters/plot/commands/ListCmd.java index 69d1c5961..ebaa625e5 100644 --- a/Core/src/main/java/com/intellectualcrafters/plot/commands/ListCmd.java +++ b/Core/src/main/java/com/intellectualcrafters/plot/commands/ListCmd.java @@ -101,7 +101,7 @@ public class ListCmd extends SubCommand { if (page < 0) { page = 0; } - } catch (Exception e) { + } catch (NumberFormatException ignored) { page = -1; } } @@ -313,8 +313,7 @@ public class ListCmd extends SubCommand { if (uuid == null) { try { uuid = UUID.fromString(args[0]); - } catch (Exception ignored) { - } + } catch (Exception ignored) {} } if (uuid != null) { if (!Permissions.hasPermission(plr, "plots.list.player")) { diff --git a/Core/src/main/java/com/intellectualcrafters/plot/commands/Load.java b/Core/src/main/java/com/intellectualcrafters/plot/commands/Load.java index d23f0ba48..7334a11f3 100644 --- a/Core/src/main/java/com/intellectualcrafters/plot/commands/Load.java +++ b/Core/src/main/java/com/intellectualcrafters/plot/commands/Load.java @@ -68,14 +68,14 @@ public class Load extends SubCommand { String schematic; try { schematic = schematics.get(Integer.parseInt(args[0]) - 1); - } catch (NumberFormatException e) { + } catch (NumberFormatException ignored) { // use /plot load - MainUtil.sendMessage(plr, C.NOT_VALID_NUMBER, "(1, " + schematics.size() + ")"); + MainUtil.sendMessage(plr, C.NOT_VALID_NUMBER, "(1, " + schematics.size() + ')'); return false; } final URL url; try { - url = new URL(Settings.WEB_URL + "saves/" + plr.getUUID() + "/" + schematic + ".schematic"); + url = new URL(Settings.WEB_URL + "saves/" + plr.getUUID() + '/' + schematic + ".schematic"); } catch (MalformedURLException e) { e.printStackTrace(); MainUtil.sendMessage(plr, C.LOAD_FAILED); @@ -147,7 +147,7 @@ public class Load extends SubCommand { } String time = secToTime((System.currentTimeMillis() / 1000) - Long.parseLong(split[0])); String world = split[1]; - PlotId id = PlotId.fromString(split[2] + ";" + split[3]); + PlotId id = PlotId.fromString(split[2] + ';' + split[3]); String size = split[4]; String server = split[5].replaceAll(".schematic", ""); String color; @@ -157,7 +157,7 @@ public class Load extends SubCommand { color = "$1"; } MainUtil.sendMessage(player, - "$3[$2" + (i + 1) + "$3] " + color + time + "$3 | " + color + world + ";" + id + "$3 | " + color + size + "x" + size); + "$3[$2" + (i + 1) + "$3] " + color + time + "$3 | " + color + world + ';' + id + "$3 | " + color + size + 'x' + size); } catch (Exception e) { e.printStackTrace(); } diff --git a/Core/src/main/java/com/intellectualcrafters/plot/commands/Owner.java b/Core/src/main/java/com/intellectualcrafters/plot/commands/Owner.java index 3e9b624df..08400128e 100644 --- a/Core/src/main/java/com/intellectualcrafters/plot/commands/Owner.java +++ b/Core/src/main/java/com/intellectualcrafters/plot/commands/Owner.java @@ -11,7 +11,7 @@ import com.intellectualcrafters.plot.util.TaskManager; import com.intellectualcrafters.plot.util.UUIDHandler; import com.plotsquared.general.commands.CommandDeclaration; -import java.util.HashSet; +import java.util.Set; import java.util.UUID; @CommandDeclaration( @@ -27,15 +27,14 @@ public class Owner extends SetCommand { @Override public boolean set(final PlotPlayer plr, final Plot plot, String value) { - HashSet plots = plot.getConnectedPlots(); + Set plots = plot.getConnectedPlots(); UUID uuid = null; String name = null; if (value.length() == 36) { try { uuid = UUID.fromString(value); name = MainUtil.getName(uuid); - } catch (Exception ignored) { - } + } catch (Exception ignored) {} } else { uuid = UUIDHandler.getUUID(value, null); name = UUIDHandler.getName(uuid); @@ -43,7 +42,7 @@ public class Owner extends SetCommand { } if (uuid == null) { if (value.equalsIgnoreCase("none")) { - HashSet connected = plot.getConnectedPlots(); + Set connected = plot.getConnectedPlots(); plot.unlinkPlot(false, false); for (Plot current : connected) { current.unclaim(); diff --git a/Core/src/main/java/com/intellectualcrafters/plot/commands/Rate.java b/Core/src/main/java/com/intellectualcrafters/plot/commands/Rate.java index eb5070158..7a3e67176 100644 --- a/Core/src/main/java/com/intellectualcrafters/plot/commands/Rate.java +++ b/Core/src/main/java/com/intellectualcrafters/plot/commands/Rate.java @@ -4,6 +4,7 @@ import com.intellectualcrafters.plot.PS; import com.intellectualcrafters.plot.config.C; import com.intellectualcrafters.plot.config.Settings; import com.intellectualcrafters.plot.database.DBFunc; +import com.intellectualcrafters.plot.flag.Flags; import com.intellectualcrafters.plot.object.Plot; import com.intellectualcrafters.plot.object.PlotInventory; import com.intellectualcrafters.plot.object.PlotItemStack; @@ -61,7 +62,7 @@ public class Rate extends SubCommand { }); UUID uuid = player.getUUID(); for (Plot p : plots) { - if ((!Settings.REQUIRE_DONE || p.getFlags().containsKey("done")) && p.isBasePlot() && (p.hasRatings() || !p.getRatings() + if ((!Settings.REQUIRE_DONE || p.hasFlag(Flags.DONE)) && p.isBasePlot() && (p.hasRatings() || !p.getRatings() .containsKey(uuid)) && !p.isAdded(uuid)) { p.teleportPlayer(player); MainUtil.sendMessage(player, C.RATE_THIS); @@ -84,7 +85,7 @@ public class Rate extends SubCommand { sendMessage(player, C.RATING_NOT_YOUR_OWN); return false; } - if (Settings.REQUIRE_DONE && !plot.getFlags().containsKey("done")) { + if (Settings.REQUIRE_DONE && !plot.hasFlag(Flags.DONE)) { sendMessage(player, C.RATING_NOT_DONE); return false; } diff --git a/Core/src/main/java/com/intellectualcrafters/plot/commands/Reload.java b/Core/src/main/java/com/intellectualcrafters/plot/commands/Reload.java index 6b9ceefc5..64da9db21 100644 --- a/Core/src/main/java/com/intellectualcrafters/plot/commands/Reload.java +++ b/Core/src/main/java/com/intellectualcrafters/plot/commands/Reload.java @@ -1,6 +1,7 @@ package com.intellectualcrafters.plot.commands; import com.intellectualcrafters.configuration.ConfigurationSection; +import com.intellectualcrafters.configuration.InvalidConfigurationException; import com.intellectualcrafters.configuration.MemorySection; import com.intellectualcrafters.configuration.file.YamlConfiguration; import com.intellectualcrafters.plot.PS; @@ -11,6 +12,7 @@ import com.intellectualcrafters.plot.object.RunnableVal; import com.intellectualcrafters.plot.util.MainUtil; import com.plotsquared.general.commands.CommandDeclaration; +import java.io.IOException; import java.util.Objects; @CommandDeclaration(command = "reload", @@ -77,7 +79,7 @@ public class Reload extends SubCommand { }); PS.get().config.save(PS.get().configFile); MainUtil.sendMessage(plr, C.RELOADED_CONFIGS); - } catch (Exception e) { + } catch (InvalidConfigurationException | IOException e) { e.printStackTrace(); MainUtil.sendMessage(plr, C.RELOAD_FAILED); } diff --git a/Core/src/main/java/com/intellectualcrafters/plot/commands/Trim.java b/Core/src/main/java/com/intellectualcrafters/plot/commands/Trim.java index 94af9bdb8..ca83543bc 100644 --- a/Core/src/main/java/com/intellectualcrafters/plot/commands/Trim.java +++ b/Core/src/main/java/com/intellectualcrafters/plot/commands/Trim.java @@ -52,15 +52,7 @@ public class Trim extends SubCommand { String name = file.getName(); if (name.endsWith("mca")) { if (file.getTotalSpace() <= 8192) { - try { - String[] split = name.split("\\."); - int x = Integer.parseInt(split[1]); - int z = Integer.parseInt(split[2]); - ChunkLoc loc = new ChunkLoc(x, z); - empty.add(loc); - } catch (NumberFormatException e) { - PS.debug("INVALID MCA: " + name); - } + checkMca(name); } else { Path path = Paths.get(file.getPath()); try { @@ -69,24 +61,26 @@ public class Trim extends SubCommand { long modification = file.lastModified(); long diff = Math.abs(creation - modification); if (diff < 10000) { - try { - String[] split = name.split("\\."); - int x = Integer.parseInt(split[1]); - int z = Integer.parseInt(split[2]); - ChunkLoc loc = new ChunkLoc(x, z); - empty.add(loc); - } catch (Exception e) { - PS.debug("INVALID MCA: " + name); - } + checkMca(name); } - } catch (IOException ignored) { - } + } catch (IOException ignored) {} } } } Trim.TASK = false; TaskManager.runTaskAsync(whenDone); } + private void checkMca(String name) { + try { + String[] split = name.split("\\."); + int x = Integer.parseInt(split[1]); + int z = Integer.parseInt(split[2]); + ChunkLoc loc = new ChunkLoc(x, z); + empty.add(loc); + } catch (NumberFormatException ignored) { + PS.debug("INVALID MCA: " + name); + } + } }); Trim.TASK = true; return true; diff --git a/Core/src/main/java/com/intellectualcrafters/plot/config/Configuration.java b/Core/src/main/java/com/intellectualcrafters/plot/config/Configuration.java index e1545b98e..211821a55 100644 --- a/Core/src/main/java/com/intellectualcrafters/plot/config/Configuration.java +++ b/Core/src/main/java/com/intellectualcrafters/plot/config/Configuration.java @@ -162,8 +162,7 @@ public class Configuration { if (result != null && result.match < 2) { values[i] = result.best; } - } catch (NumberFormatException ignored) { - } + } catch (NumberFormatException ignored) {} } int gcd = gcd(counts); for (int i = 0; i < counts.length; i++) { diff --git a/Core/src/main/java/com/intellectualcrafters/plot/database/SQLManager.java b/Core/src/main/java/com/intellectualcrafters/plot/database/SQLManager.java index eb9f1c904..dbe9c2231 100644 --- a/Core/src/main/java/com/intellectualcrafters/plot/database/SQLManager.java +++ b/Core/src/main/java/com/intellectualcrafters/plot/database/SQLManager.java @@ -182,16 +182,13 @@ public class SQLManager implements AbstractDB { } @Override - public void set(PreparedStatement stmt) { - } + public void set(PreparedStatement stmt) {} @Override - public void addBatch(PreparedStatement statement) { - } + public void addBatch(PreparedStatement statement) {} @Override - public void execute(PreparedStatement statement) { - } + public void execute(PreparedStatement statement) {} }; } @@ -216,16 +213,13 @@ public class SQLManager implements AbstractDB { } @Override - public void set(PreparedStatement stmt) { - } + public void set(PreparedStatement stmt) {} @Override - public void addBatch(PreparedStatement statement) { - } + public void addBatch(PreparedStatement statement) {} @Override - public void execute(PreparedStatement statement) { - } + public void execute(PreparedStatement statement) {} }; } @@ -247,16 +241,13 @@ public class SQLManager implements AbstractDB { } @Override - public void set(PreparedStatement stmt) { - } + public void set(PreparedStatement stmt) {} @Override - public void addBatch(PreparedStatement statement) { - } + public void addBatch(PreparedStatement statement) {} @Override - public void execute(PreparedStatement statement) { - } + public void execute(PreparedStatement statement) {} }; } @@ -990,8 +981,7 @@ public class SQLManager implements AbstractDB { } @Override - public void execute(PreparedStatement statement) { - } + public void execute(PreparedStatement statement) {} @Override public void addBatch(PreparedStatement statement) throws SQLException { @@ -1808,8 +1798,7 @@ public class SQLManager implements AbstractDB { default: try { plot.getSettings().setPosition(BlockLoc.fromString(pos)); - } catch (Exception ignored) { - } + } catch (Exception ignored) {} } Integer m = resultSet.getInt("merged"); boolean[] merged = new boolean[4]; @@ -1963,7 +1952,7 @@ public class SQLManager implements AbstractDB { @Override public void setFlags(final Plot plot, HashMap, Object> flags) { - final String flag_string = FlagManager.toString(flags); //todo MattBDev: Fix this for flags to work. + final String flag_string = FlagManager.toString(flags); addPlotTask(plot, new UniqueStatement("setFlags") { @Override public void set(PreparedStatement stmt) throws SQLException { @@ -2178,8 +2167,7 @@ public class SQLManager implements AbstractDB { } @Override - public void execute(PreparedStatement statement) { - } + public void execute(PreparedStatement statement) {} @Override public void addBatch(PreparedStatement statement) throws SQLException { @@ -2480,8 +2468,7 @@ public class SQLManager implements AbstractDB { } @Override - public void execute(PreparedStatement statement) { - } + public void execute(PreparedStatement statement) {} @Override public void addBatch(PreparedStatement statement) throws SQLException { @@ -2621,8 +2608,7 @@ public class SQLManager implements AbstractDB { try { BlockLoc loc = BlockLoc.fromString(pos); cluster.settings.setPosition(loc); - } catch (Exception ignored) { - } + } catch (Exception ignored) {} } Integer m = resultSet.getInt("merged"); boolean[] merged = new boolean[4]; @@ -2690,9 +2676,8 @@ public class SQLManager implements AbstractDB { if (i != 0) { flag_string.append(','); } - flag_string.append(flag.getKey().getName()).append(":") - .append(flag.getKey().valueToString(flag.getValue()).replaceAll(":", "¯").replaceAll(",", - "´")); + flag_string.append(flag.getKey().getName()).append(':') + .append(flag.getKey().valueToString(flag.getValue()).replaceAll(":", "¯").replaceAll(",", "´")); i++; } addClusterTask(cluster, new UniqueStatement("setFlags") { @@ -2781,8 +2766,7 @@ public class SQLManager implements AbstractDB { } @Override - public void execute(PreparedStatement statement) { - } + public void execute(PreparedStatement statement) {} @Override public void addBatch(PreparedStatement statement) throws SQLException { diff --git a/Core/src/main/java/com/intellectualcrafters/plot/flag/FlagManager.java b/Core/src/main/java/com/intellectualcrafters/plot/flag/FlagManager.java index 467fb99c8..c099af9b0 100644 --- a/Core/src/main/java/com/intellectualcrafters/plot/flag/FlagManager.java +++ b/Core/src/main/java/com/intellectualcrafters/plot/flag/FlagManager.java @@ -63,9 +63,8 @@ public class FlagManager { public static String toString(HashMap, Object> flags) { StringBuilder flag_string = new StringBuilder(); int i = 0; - Flag flag; for (Map.Entry, Object> entry : flags.entrySet()) { - flag = entry.getKey(); + Flag flag = entry.getKey(); if (i != 0) { flag_string.append(","); } @@ -132,7 +131,7 @@ public class FlagManager { * @param plot * @return set of flags */ - public static HashMap, Object> getPlotFlags(Plot plot) { + public static Map, Object> getPlotFlags(Plot plot) { if (!plot.hasOwner()) { return null; } @@ -158,7 +157,7 @@ public class FlagManager { return flags; } - public static HashMap, Object> getSettingFlags(PlotArea area, PlotSettings settings) { + public static Map, Object> getSettingFlags(PlotArea area, PlotSettings settings) { return getPlotFlags(area, settings, false); } @@ -227,7 +226,7 @@ public class FlagManager { * * @param player with permissions * - * @return List (AbstractFlag) + * @return List (Flag) */ public static List getFlags(PlotPlayer player) { List returnFlags = new ArrayList<>(); @@ -240,11 +239,11 @@ public class FlagManager { } /** - * Get an AbstractFlag by a string Returns null if flag does not exist + * Get an Flag by a String * - * @param string Flag Key + * @param string the flag name * - * @return AbstractFlag + * @return the flag or null if the flag the provided name does not exist */ public static Flag getFlag(String string) { for (Flag flag : Flags.getFlags()) { @@ -258,7 +257,7 @@ public class FlagManager { return null; } - public static HashMap, Object> parseFlags(List flagstrings) { + public static Map, Object> parseFlags(List flagstrings) { HashMap, Object> map = new HashMap<>(); for (String key : flagstrings) { diff --git a/Core/src/main/java/com/intellectualcrafters/plot/generator/AugmentedUtils.java b/Core/src/main/java/com/intellectualcrafters/plot/generator/AugmentedUtils.java index 15dd548b9..019b383ee 100644 --- a/Core/src/main/java/com/intellectualcrafters/plot/generator/AugmentedUtils.java +++ b/Core/src/main/java/com/intellectualcrafters/plot/generator/AugmentedUtils.java @@ -143,8 +143,7 @@ public class AugmentedUtils { } @Override - public void setBiome(int x, int z, int biome) { - } + public void setBiome(int x, int z, int biome) {} @Override public PlotChunk clone() { diff --git a/Core/src/main/java/com/intellectualcrafters/plot/generator/IndependentPlotGenerator.java b/Core/src/main/java/com/intellectualcrafters/plot/generator/IndependentPlotGenerator.java index 84fe328de..81ac2d5a5 100644 --- a/Core/src/main/java/com/intellectualcrafters/plot/generator/IndependentPlotGenerator.java +++ b/Core/src/main/java/com/intellectualcrafters/plot/generator/IndependentPlotGenerator.java @@ -55,8 +55,7 @@ public abstract class IndependentPlotGenerator { * - e.g. If setup doesn't support some standard options * @param setup */ - public void processSetup(SetupObject setup) { - } + public void processSetup(SetupObject setup) {} /** * It is preferred for the PlotArea object to do most of the initialization necessary. diff --git a/Core/src/main/java/com/intellectualcrafters/plot/generator/SquarePlotManager.java b/Core/src/main/java/com/intellectualcrafters/plot/generator/SquarePlotManager.java index 611a982cb..b60e0e0c5 100644 --- a/Core/src/main/java/com/intellectualcrafters/plot/generator/SquarePlotManager.java +++ b/Core/src/main/java/com/intellectualcrafters/plot/generator/SquarePlotManager.java @@ -176,7 +176,7 @@ public abstract class SquarePlotManager extends GridPlotManager { return plot.getMerged(7) ? id : null; } PS.debug("invalid location: " + Arrays.toString(merged)); - } catch (Exception e) { + } catch (Exception ignored) { PS.debug("Invalid plot / road width in settings.yml for world: " + plotworld.worldname); } return null; diff --git a/Core/src/main/java/com/intellectualcrafters/plot/object/ConsolePlayer.java b/Core/src/main/java/com/intellectualcrafters/plot/object/ConsolePlayer.java index 33d7d535d..13e6d37d0 100644 --- a/Core/src/main/java/com/intellectualcrafters/plot/object/ConsolePlayer.java +++ b/Core/src/main/java/com/intellectualcrafters/plot/object/ConsolePlayer.java @@ -87,12 +87,10 @@ public class ConsolePlayer extends PlotPlayer { } @Override - public void setCompassTarget(Location location) { - } + public void setCompassTarget(Location location) {} @Override - public void setAttribute(String key) { - } + public void setAttribute(String key) {} @Override public boolean getAttribute(String key) { @@ -100,8 +98,7 @@ public class ConsolePlayer extends PlotPlayer { } @Override - public void removeAttribute(String key) { - } + public void removeAttribute(String key) {} @Override public void setMeta(String key, Object value) { @@ -124,8 +121,7 @@ public class ConsolePlayer extends PlotPlayer { } @Override - public void setWeather(PlotWeather weather) { - } + public void setWeather(PlotWeather weather) {} @Override public PlotGameMode getGameMode() { @@ -133,24 +129,19 @@ public class ConsolePlayer extends PlotPlayer { } @Override - public void setGameMode(PlotGameMode gameMode) { - } + public void setGameMode(PlotGameMode gameMode) {} @Override - public void setTime(long time) { - } + public void setTime(long time) {} @Override - public void setFlight(boolean fly) { - } + public void setFlight(boolean fly) {} @Override - public void playMusic(Location location, int id) { - } + public void playMusic(Location location, int id) {} @Override - public void kick(String message) { - } + public void kick(String message) {} @Override public void stopSpectating() {} diff --git a/Core/src/main/java/com/intellectualcrafters/plot/object/Plot.java b/Core/src/main/java/com/intellectualcrafters/plot/object/Plot.java index 3fe67531d..b781d5f1c 100644 --- a/Core/src/main/java/com/intellectualcrafters/plot/object/Plot.java +++ b/Core/src/main/java/com/intellectualcrafters/plot/object/Plot.java @@ -335,7 +335,7 @@ public class Plot { if (!isMerged()) { return false; } - HashSet connected = getConnectedPlots(); + Set connected = getConnectedPlots(); for (Plot current : connected) { if (uuid.equals(current.owner)) { return true; @@ -350,14 +350,14 @@ public class Plot { /** * Get a immutable set of owner UUIDs for a plot (supports multi-owner mega-plots). - * @return + * @return the Plot owners */ public Set getOwners() { if (this.owner == null) { - return new HashSet<>(); + return Collections.emptySet(); } if (isMerged()) { - HashSet plots = getConnectedPlots(); + Set plots = getConnectedPlots(); Plot[] array = plots.toArray(new Plot[plots.size()]); ImmutableSet.Builder owners = ImmutableSet.builder(); UUID last = this.owner; @@ -747,14 +747,11 @@ public class Plot { } public boolean clear(boolean checkRunning, final boolean isDelete, final Runnable whenDone) { - if (checkRunning && this.getRunning() != 0) { - return false; - } - if (!EventUtil.manager.callClear(this)) { + if (checkRunning && this.getRunning() != 0 || !EventUtil.manager.callClear(this)) { return false; } final HashSet regions = this.getRegions(); - final HashSet plots = this.getConnectedPlots(); + final Set plots = this.getConnectedPlots(); final ArrayDeque queue = new ArrayDeque<>(plots); if (isDelete) { this.removeSign(); @@ -841,7 +838,7 @@ public class Plot { } /** - * Unlink the plot and all connected plots + * Unlink the plot and all connected plots. * @param createSign * @param createRoad * @return @@ -850,7 +847,7 @@ public class Plot { if (!this.isMerged()) { return false; } - HashSet plots = this.getConnectedPlots(); + Set plots = this.getConnectedPlots(); ArrayList ids = new ArrayList<>(plots.size()); for (Plot current : plots) { current.setHome(null); @@ -982,7 +979,7 @@ public class Plot { if (!this.hasOwner()) { return false; } - final HashSet plots = this.getConnectedPlots(); + final Set plots = this.getConnectedPlots(); this.clear(false, true, new Runnable() { @Override public void run() { @@ -1062,9 +1059,8 @@ public class Plot { } /** - * Unclaim the plot (does not modify terrain)
- * - Changes made to this plot will not be reflected in unclaimed plot objects
- * @return + * Unclaim the plot (does not modify terrain). Changes made to this plot will not be reflected in unclaimed plot objects. + * @return false if the Plot has no owner, otherwise true. */ public boolean unclaim() { if (this.owner == null) { @@ -1264,9 +1260,7 @@ public class Plot { }); } - /** - * Remove the plot sign if it is set - */ + /** Remove the plot sign if it is set. */ public void removeSign() { PlotManager manager = this.area.getPlotManager(); if (!this.area.ALLOW_SIGNS) { @@ -1276,9 +1270,7 @@ public class Plot { SetQueue.IMP.setBlock(this.area.worldname, loc.getX(), loc.getY(), loc.getZ(), 0); } - /** - * Set the plot sign if plot signs are enabled. - */ + /** Set the plot sign if plot signs are enabled. */ public void setSign() { if (this.owner == null) { this.setSign("unknown"); @@ -2076,7 +2068,7 @@ public class Plot { } HashSet visited = new HashSet<>(); HashSet merged = new HashSet<>(); - HashSet connected = this.getConnectedPlots(); + Set connected = this.getConnectedPlots(); for (Plot current : connected) { merged.add(current.getId()); } @@ -2091,8 +2083,7 @@ public class Plot { Set plots; if ((dir == -1 || dir == 0) && !current.getMerged(0)) { Plot other = current.getRelative(0); - if (other != null - && other.isOwner(uuid) + if (other != null && other.isOwner(uuid) && (other.getBasePlot(false).equals(current.getBasePlot(false)) || (plots = other.getConnectedPlots()).size() <= max && frontier.addAll(plots) && (max -= plots.size()) != -1)) { current.mergePlot(other, removeRoads); @@ -2103,12 +2094,9 @@ public class Plot { } if (max >= 0 && (dir == -1 || dir == 1) && !current.getMerged(1)) { Plot other = current.getRelative(1); - if (other != null - && other.isOwner(uuid) + if (other != null && other.isOwner(uuid) && (other.getBasePlot(false).equals(current.getBasePlot(false)) - || (plots = other.getConnectedPlots()).size() <= max && frontier.addAll(plots) && - - (max -= plots.size()) != -1)) { + || (plots = other.getConnectedPlots()).size() <= max && frontier.addAll(plots) && (max -= plots.size()) != -1)) { current.mergePlot(other, removeRoads); merged.add(current.getId()); merged.add(other.getId()); @@ -2243,14 +2231,14 @@ public class Plot { * - This result is cached globally * @return */ - public HashSet getConnectedPlots() { + public Set getConnectedPlots() { if (this.settings == null) { - return new HashSet<>(Collections.singletonList(this)); + return Collections.singleton(this); } boolean[] merged = this.getMerged(); int hash = MainUtil.hash(merged); if (hash == 0) { - return new HashSet<>(Collections.singletonList(this)); + return Collections.singleton(this); } if (connected_cache != null && connected_cache.contains(this)) { return connected_cache; @@ -2386,7 +2374,7 @@ public class Plot { regions_cache.add(new RegionWrapper(pos1.getX(), pos2.getX(), pos1.getY(), pos2.getY(), pos1.getZ(), pos2.getZ())); return regions_cache; } - HashSet plots = this.getConnectedPlots(); + Set plots = this.getConnectedPlots(); HashSet regions = regions_cache = new HashSet<>(); HashSet visited = new HashSet<>(); for (Plot current : plots) { @@ -2712,7 +2700,7 @@ public class Plot { return false; } boolean occupied = false; - HashSet plots = this.getConnectedPlots(); + Set plots = this.getConnectedPlots(); for (Plot plot : plots) { Plot other = plot.getRelative(destination.getArea(), offset.x, offset.y); if (other.hasOwner()) { @@ -2806,7 +2794,7 @@ public class Plot { TaskManager.runTaskLater(whenDone, 1); return false; } - HashSet plots = this.getConnectedPlots(); + Set plots = this.getConnectedPlots(); for (Plot plot : plots) { Plot other = plot.getRelative(destination.getArea(), offset.x, offset.y); if (other.hasOwner()) { @@ -2873,7 +2861,6 @@ public class Plot { } public boolean hasFlag(Flag flag) { - //todo - return false; + return getFlags().containsKey(flag); } } diff --git a/Core/src/main/java/com/intellectualcrafters/plot/object/PlotArea.java b/Core/src/main/java/com/intellectualcrafters/plot/object/PlotArea.java index 7a0eb8172..128576106 100644 --- a/Core/src/main/java/com/intellectualcrafters/plot/object/PlotArea.java +++ b/Core/src/main/java/com/intellectualcrafters/plot/object/PlotArea.java @@ -7,6 +7,7 @@ import com.intellectualcrafters.plot.config.ConfigurationNode; import com.intellectualcrafters.plot.config.Settings; import com.intellectualcrafters.plot.flag.Flag; import com.intellectualcrafters.plot.flag.FlagManager; +import com.intellectualcrafters.plot.flag.Flags; import com.intellectualcrafters.plot.generator.GridPlotWorld; import com.intellectualcrafters.plot.generator.IndependentPlotGenerator; import com.intellectualcrafters.plot.util.EconHandler; @@ -53,9 +54,9 @@ public abstract class PlotArea { public boolean SCHEMATIC_ON_CLAIM = false; public String SCHEMATIC_FILE = "null"; public List SCHEMATICS = null; - public HashMap, Object> DEFAULT_FLAGS; + public Map, Object> DEFAULT_FLAGS; public boolean USE_ECONOMY = false; - public HashMap PRICES = new HashMap<>(); + public Map PRICES = new HashMap<>(); public boolean SPAWN_EGGS = false; public boolean SPAWN_CUSTOM = true; public boolean SPAWN_BREEDING = false; @@ -165,10 +166,7 @@ public abstract class PlotArea { if (this == obj) { return true; } - if (obj == null) { - return false; - } - if (getClass() != obj.getClass()) { + if (obj == null || getClass() != obj.getClass()) { return false; } PlotArea plotarea = (PlotArea) obj; @@ -187,11 +185,8 @@ public abstract class PlotArea { public boolean isCompatible(PlotArea plotArea) { ConfigurationSection section = PS.get().config.getConfigurationSection("worlds"); for (ConfigurationNode setting : plotArea.getSettingNodes()) { - Object constant = section.get(plotArea.worldname + "." + setting.getConstant()); - if (constant == null) { - return false; - } - if (!constant.equals(section.get(this.worldname + "." + setting.getConstant()))) { + Object constant = section.get(plotArea.worldname + '.' + setting.getConstant()); + if (constant == null || !constant.equals(section.get(this.worldname + '.' + setting.getConstant()))) { return false; } } @@ -269,7 +264,7 @@ public abstract class PlotArea { try { String[] split = homeDefault.split(","); this.DEFAULT_HOME = new PlotLoc(Integer.parseInt(split[0]), Integer.parseInt(split[1])); - } catch (NumberFormatException e) { + } catch (NumberFormatException ignored) { this.DEFAULT_HOME = null; } } @@ -283,7 +278,7 @@ public abstract class PlotArea { Set keys = section.getKeys(false); for (String key : keys) { if (!"default".equals(key)) { - flags.add(key + ";" + section.get(key)); + flags.add(key + ';' + section.get(key)); } } } @@ -475,8 +470,8 @@ public abstract class PlotArea { return myPlots; } - public Set getPlots(UUID uuid) { - HashSet myplots = new HashSet<>(); + public Set getPlots(final UUID uuid) { + final HashSet myplots = new HashSet<>(); for (Plot plot : getPlots()) { if (plot.isBasePlot()) { if (plot.isOwner(uuid)) { @@ -488,7 +483,7 @@ public abstract class PlotArea { } public Set getPlots(PlotPlayer player) { - return player != null ? getPlots(player.getUUID()) : new HashSet(); + return getPlots(player.getUUID()); } public Set getPlotsAbs(PlotPlayer player) { @@ -499,7 +494,7 @@ public abstract class PlotArea { int count = 0; if (!Settings.DONE_COUNTS_TOWARDS_LIMIT) { for (Plot plot : getPlotsAbs(uuid)) { - if (!plot.getFlags().containsKey("done")) { + if (!plot.hasFlag(Flags.DONE)) { count++; } } @@ -617,7 +612,7 @@ public abstract class PlotArea { } } - + public void foreachBasePlot(RunnableVal run) { for (Plot plot : getPlots()) { if (plot.isBasePlot()) { diff --git a/Core/src/main/java/com/intellectualcrafters/plot/object/PlotId.java b/Core/src/main/java/com/intellectualcrafters/plot/object/PlotId.java index 6ebc38930..dfb6b791a 100644 --- a/Core/src/main/java/com/intellectualcrafters/plot/object/PlotId.java +++ b/Core/src/main/java/com/intellectualcrafters/plot/object/PlotId.java @@ -42,7 +42,7 @@ public class PlotId { try { x = Integer.parseInt(parts[0]); y = Integer.parseInt(parts[1]); - } catch (NumberFormatException e) { + } catch (NumberFormatException ignored) { return null; } return new PlotId(x, y); diff --git a/Core/src/main/java/com/intellectualcrafters/plot/object/PlotPlayer.java b/Core/src/main/java/com/intellectualcrafters/plot/object/PlotPlayer.java index b8a60edc4..4675a357e 100644 --- a/Core/src/main/java/com/intellectualcrafters/plot/object/PlotPlayer.java +++ b/Core/src/main/java/com/intellectualcrafters/plot/object/PlotPlayer.java @@ -4,6 +4,7 @@ import com.intellectualcrafters.plot.PS; import com.intellectualcrafters.plot.commands.RequiredType; import com.intellectualcrafters.plot.config.Settings; import com.intellectualcrafters.plot.database.DBFunc; +import com.intellectualcrafters.plot.flag.Flags; import com.intellectualcrafters.plot.util.EventUtil; import com.intellectualcrafters.plot.util.ExpireManager; import com.intellectualcrafters.plot.util.Permissions; @@ -145,7 +146,7 @@ public abstract class PlotPlayer implements CommandCaller { public void run(PlotArea value) { if (!Settings.DONE_COUNTS_TOWARDS_LIMIT) { for (Plot plot : value.getPlotsAbs(uuid)) { - if (!plot.getFlags().containsKey("done")) { + if (!plot.hasFlag(Flags.DONE)) { count.incrementAndGet(); } } diff --git a/Core/src/main/java/com/intellectualcrafters/plot/util/ChunkManager.java b/Core/src/main/java/com/intellectualcrafters/plot/util/ChunkManager.java index c08db1ef7..ff93b902b 100644 --- a/Core/src/main/java/com/intellectualcrafters/plot/util/ChunkManager.java +++ b/Core/src/main/java/com/intellectualcrafters/plot/util/ChunkManager.java @@ -222,8 +222,7 @@ public abstract class ChunkManager { int z = Integer.parseInt(split[2]); ChunkLoc loc = new ChunkLoc(x, z); chunks.add(loc); - } catch (NumberFormatException ignored) { - } + } catch (NumberFormatException ignored) {} } } return chunks; diff --git a/Core/src/main/java/com/intellectualcrafters/plot/util/MainUtil.java b/Core/src/main/java/com/intellectualcrafters/plot/util/MainUtil.java index 0019882ca..b0f8c53a7 100644 --- a/Core/src/main/java/com/intellectualcrafters/plot/util/MainUtil.java +++ b/Core/src/main/java/com/intellectualcrafters/plot/util/MainUtil.java @@ -431,7 +431,7 @@ public class MainUtil { if (arg == null) { if (player == null) { if (message) { - MainUtil.sendMessage(player, C.NOT_VALID_PLOT_WORLD); + PS.log(C.NOT_VALID_PLOT_WORLD); } return null; } diff --git a/Core/src/main/java/com/intellectualcrafters/plot/util/ReflectionUtils.java b/Core/src/main/java/com/intellectualcrafters/plot/util/ReflectionUtils.java index 9275179a8..62cbe04b0 100644 --- a/Core/src/main/java/com/intellectualcrafters/plot/util/ReflectionUtils.java +++ b/Core/src/main/java/com/intellectualcrafters/plot/util/ReflectionUtils.java @@ -70,8 +70,7 @@ public class ReflectionUtils { Object value = field.get(null); try { list.add((T) value); - } catch (ClassCastException ignored) { - } + } catch (ClassCastException ignored) {} } } catch (IllegalAccessException | IllegalArgumentException | SecurityException e) { e.printStackTrace(); @@ -92,12 +91,11 @@ public class ReflectionUtils { public static Class getUtilClass(String name) { try { return Class.forName(name); //Try before 1.8 first + } catch (ClassNotFoundException ignored) {} + try { + return Class.forName("net.minecraft.util." + name); //Not 1.8 } catch (ClassNotFoundException ignored) { - try { - return Class.forName("net.minecraft.util." + name); //Not 1.8 - } catch (ClassNotFoundException ignored2) { - return null; - } + return null; } } @@ -112,8 +110,6 @@ public class ReflectionUtils { return clazz.getDeclaredMethod(methodName, paramaters); } catch (NoSuchMethodException ignored) { return null; - } catch (SecurityException ex) { - throw new RuntimeException(ex); } } @@ -138,8 +134,6 @@ public class ReflectionUtils { return (Constructor) clazz.getConstructor(paramaterTypes); } catch (NoSuchMethodException ignored) { return null; - } catch (SecurityException ex) { - throw new RuntimeException(ex); } } @@ -162,8 +156,6 @@ public class ReflectionUtils { return clazz.getDeclaredField(name); } catch (NoSuchFieldException ignored) { return null; - } catch (SecurityException ex) { - throw new RuntimeException(ex); } } @@ -187,7 +179,7 @@ public class ReflectionUtils { field.setAccessible(true); try { field.set(instance, value); - } catch (Exception ex) { + } catch (IllegalAccessException | IllegalArgumentException ex) { throw new RuntimeException(ex); } } @@ -195,7 +187,7 @@ public class ReflectionUtils { public static Class getClass(String name) { try { return Class.forName(name); - } catch (ClassNotFoundException ex) { + } catch (ClassNotFoundException ignored) { return null; } } @@ -203,7 +195,7 @@ public class ReflectionUtils { public static Class getClass(String name, Class superClass) { try { return Class.forName(name).asSubclass(superClass); - } catch (ClassCastException | ClassNotFoundException ex) { + } catch (ClassCastException | ClassNotFoundException ignored) { return null; } } @@ -212,21 +204,15 @@ public class ReflectionUtils { * Get class for name. Replace {nms} to net.minecraft.server.V*. Replace {cb} to org.bukkit.craftbukkit.V*. Replace * {nm} to net.minecraft * - * @param classes possible class paths + * @param className possible class paths * * @return RefClass object * - * @throws RuntimeException if no class found + * @throws ClassNotFoundException if no class found */ - public static RefClass getRefClass(String... classes) throws RuntimeException { - for (String className : classes) { - try { - className = className.replace("{cb}", preClassB).replace("{nms}", preClassM).replace("{nm}", "net.minecraft"); - return getRefClass(Class.forName(className)); - } catch (ClassNotFoundException ignored) { - } - } - throw new RuntimeException("no class found"); + public static RefClass getRefClass(String className) throws ClassNotFoundException { + className = className.replace("{cb}", preClassB).replace("{nms}", preClassM).replace("{nm}", "net.minecraft"); + return getRefClass(Class.forName(className)); } /** @@ -281,26 +267,22 @@ public class ReflectionUtils { * * @throws RuntimeException if method not found */ - public RefMethod getMethod(String name, Object... types) { + public RefMethod getMethod(String name, Object... types) throws NoSuchMethodException { + Class[] classes = new Class[types.length]; + int i = 0; + for (Object e : types) { + if (e instanceof Class) { + classes[i++] = (Class) e; + } else if (e instanceof RefClass) { + classes[i++] = ((RefClass) e).getRealClass(); + } else { + classes[i++] = e.getClass(); + } + } try { - Class[] classes = new Class[types.length]; - int i = 0; - for (Object e : types) { - if (e instanceof Class) { - classes[i++] = (Class) e; - } else if (e instanceof RefClass) { - classes[i++] = ((RefClass) e).getRealClass(); - } else { - classes[i++] = e.getClass(); - } - } - try { - return new RefMethod(this.clazz.getMethod(name, classes)); - } catch (NoSuchMethodException ignored) { - return new RefMethod(this.clazz.getDeclaredMethod(name, classes)); - } - } catch (NoSuchMethodException | SecurityException e) { - throw new RuntimeException(e); + return new RefMethod(this.clazz.getMethod(name, classes)); + } catch (NoSuchMethodException ignored) { + return new RefMethod(this.clazz.getDeclaredMethod(name, classes)); } } @@ -313,26 +295,22 @@ public class ReflectionUtils { * * @throws RuntimeException if constructor not found */ - public RefConstructor getConstructor(Object... types) { + public RefConstructor getConstructor(Object... types) throws NoSuchMethodException { + Class[] classes = new Class[types.length]; + int i = 0; + for (Object e : types) { + if (e instanceof Class) { + classes[i++] = (Class) e; + } else if (e instanceof RefClass) { + classes[i++] = ((RefClass) e).getRealClass(); + } else { + classes[i++] = e.getClass(); + } + } try { - Class[] classes = new Class[types.length]; - int i = 0; - for (Object e : types) { - if (e instanceof Class) { - classes[i++] = (Class) e; - } else if (e instanceof RefClass) { - classes[i++] = ((RefClass) e).getRealClass(); - } else { - classes[i++] = e.getClass(); - } - } - try { - return new RefConstructor(this.clazz.getConstructor(classes)); - } catch (NoSuchMethodException ignored) { - return new RefConstructor(this.clazz.getDeclaredConstructor(classes)); - } - } catch (NoSuchMethodException | SecurityException e) { - throw new RuntimeException(e); + return new RefConstructor(this.clazz.getConstructor(classes)); + } catch (NoSuchMethodException ignored) { + return new RefConstructor(this.clazz.getDeclaredConstructor(classes)); } } @@ -466,15 +444,11 @@ public class ReflectionUtils { * * @throws RuntimeException if field not found */ - public RefField getField(String name) { + public RefField getField(String name) throws NoSuchFieldException { try { - try { - return new RefField(this.clazz.getField(name)); - } catch (NoSuchFieldException ignored) { - return new RefField(this.clazz.getDeclaredField(name)); - } - } catch (Exception e) { - throw new RuntimeException(e); + return new RefField(this.clazz.getField(name)); + } catch (NoSuchFieldException ignored) { + return new RefField(this.clazz.getDeclaredField(name)); } } @@ -570,7 +544,7 @@ public class ReflectionUtils { public Object call(Object... params) { try { return this.method.invoke(null, params); - } catch (Exception e) { + } catch (IllegalAccessException | IllegalArgumentException | InvocationTargetException e) { throw new RuntimeException(e); } } diff --git a/Core/src/main/java/com/intellectualcrafters/plot/util/UUIDHandlerImplementation.java b/Core/src/main/java/com/intellectualcrafters/plot/util/UUIDHandlerImplementation.java index 2fdc8d0b1..2e52fb87c 100644 --- a/Core/src/main/java/com/intellectualcrafters/plot/util/UUIDHandlerImplementation.java +++ b/Core/src/main/java/com/intellectualcrafters/plot/util/UUIDHandlerImplementation.java @@ -152,7 +152,7 @@ public abstract class UUIDHandlerImplementation { } return false; } - } catch (Exception e) { + } catch (Exception ignored) { BiMap inverse = this.uuidMap.inverse(); if (inverse.containsKey(uuid)) { if (this.uuidMap.containsKey(name)) { diff --git a/Core/src/main/java/com/plotsquared/general/commands/Argument.java b/Core/src/main/java/com/plotsquared/general/commands/Argument.java index f8a0249c5..f9696a7b6 100644 --- a/Core/src/main/java/com/plotsquared/general/commands/Argument.java +++ b/Core/src/main/java/com/plotsquared/general/commands/Argument.java @@ -10,8 +10,7 @@ public abstract class Argument { Integer value = null; try { value = java.lang.Integer.parseInt(in); - } catch (Exception ignored) { - } + } catch (Exception ignored) {} return value; } }; diff --git a/Core/src/main/java/com/plotsquared/general/commands/Command.java b/Core/src/main/java/com/plotsquared/general/commands/Command.java index 31acf7791..8290b0257 100644 --- a/Core/src/main/java/com/plotsquared/general/commands/Command.java +++ b/Core/src/main/java/com/plotsquared/general/commands/Command.java @@ -298,8 +298,7 @@ public abstract class Command { MainCommand.getInstance().help.execute(player, args, null, null); return; } - } catch (IllegalArgumentException ignored) { - } + } catch (IllegalArgumentException ignored) {} // Command recommendation MainUtil.sendMessage(player, C.NOT_VALID_SUBCOMMAND); List commands = getCommands(player); diff --git a/Core/src/main/java/com/plotsquared/listener/PlotListener.java b/Core/src/main/java/com/plotsquared/listener/PlotListener.java index b8204ec5a..69fd48a63 100644 --- a/Core/src/main/java/com/plotsquared/listener/PlotListener.java +++ b/Core/src/main/java/com/plotsquared/listener/PlotListener.java @@ -43,7 +43,7 @@ public class PlotListener { pp.setMeta("lastplot", plot); EventUtil.manager.callEntry(pp, plot); if (plot.hasOwner()) { - HashMap, Object> flags = FlagManager.getPlotFlags(plot); + Map, Object> flags = FlagManager.getPlotFlags(plot); int size = flags.size(); boolean titles = Settings.TITLES; final String greeting; @@ -122,8 +122,7 @@ public class PlotListener { try { pp.setMeta("music", loc); pp.playMusic(loc, id); - } catch (Exception ignored) { - } + } catch (Exception ignored) {} } } } else { diff --git a/Core/src/main/java/com/plotsquared/listener/WESubscriber.java b/Core/src/main/java/com/plotsquared/listener/WESubscriber.java index ecda7b943..36ae2c632 100644 --- a/Core/src/main/java/com/plotsquared/listener/WESubscriber.java +++ b/Core/src/main/java/com/plotsquared/listener/WESubscriber.java @@ -84,8 +84,7 @@ public class WESubscriber { if (tool instanceof BrushTool) { hasMask = ((BrushTool) tool).getMask() != null; } - } catch (Exception ignored) { - } + } catch (Exception ignored) {} } AbstractDelegateExtent extent = (AbstractDelegateExtent) event.getExtent(); ChangeSetExtent history = null; diff --git a/Core/src/test/java/com/intellectualcrafters/plot/database/AbstractDBTEst.java b/Core/src/test/java/com/intellectualcrafters/plot/database/AbstractDBTEst.java index c04f69238..9d5a6ec2c 100644 --- a/Core/src/test/java/com/intellectualcrafters/plot/database/AbstractDBTEst.java +++ b/Core/src/test/java/com/intellectualcrafters/plot/database/AbstractDBTEst.java @@ -17,53 +17,37 @@ import java.util.UUID; public class AbstractDBTest implements AbstractDB { - @Override public void setOwner(Plot plot, UUID uuid) { - } + @Override public void setOwner(Plot plot, UUID uuid) {} - @Override public void createPlotsAndData(ArrayList plots, Runnable whenDone) { - } + @Override public void createPlotsAndData(ArrayList plots, Runnable whenDone) {} - @Override public void createPlot(Plot plot) { - } + @Override public void createPlot(Plot plot) {} - @Override public void createTables() { - } + @Override public void createTables() {} - @Override public void delete(Plot plot) { - } + @Override public void delete(Plot plot) {} - @Override public void deleteSettings(Plot plot) { - } + @Override public void deleteSettings(Plot plot) {} - @Override public void deleteHelpers(Plot plot) { - } + @Override public void deleteHelpers(Plot plot) {} - @Override public void deleteTrusted(Plot plot) { - } + @Override public void deleteTrusted(Plot plot) {} - @Override public void deleteDenied(Plot plot) { - } + @Override public void deleteDenied(Plot plot) {} - @Override public void deleteComments(Plot plot) { - } + @Override public void deleteComments(Plot plot) {} - @Override public void deleteRatings(Plot plot) { - } + @Override public void deleteRatings(Plot plot) {} - @Override public void delete(PlotCluster cluster) { - } + @Override public void delete(PlotCluster cluster) {} - @Override public void addPersistentMeta(UUID uuid, String key, byte[] meta, boolean delete) { - } + @Override public void addPersistentMeta(UUID uuid, String key, byte[] meta, boolean delete) {} - @Override public void removePersistentMeta(UUID uuid, String key) { - } + @Override public void removePersistentMeta(UUID uuid, String key) {} - @Override public void getPersistentMeta(UUID uuid, RunnableVal> result) { - } + @Override public void getPersistentMeta(UUID uuid, RunnableVal> result) {} - @Override public void createPlotSettings(int id, Plot plot) { - } + @Override public void createPlotSettings(int id, Plot plot) {} @Override public int getId(Plot plot) { return 0; @@ -77,117 +61,83 @@ public class AbstractDBTest implements AbstractDB { return null; } - @Override public void validateAllPlots(Set toValidate) { - } + @Override public void validateAllPlots(Set toValidate) {} @Override public HashMap> getClusters() { return null; } - @Override public void setMerged(Plot plot, boolean[] merged) { - } + @Override public void setMerged(Plot plot, boolean[] merged) {} - @Override public void swapPlots(Plot plot1, Plot plot2) { - } + @Override public void swapPlots(Plot plot1, Plot plot2) {} - @Override public void setFlags(Plot plot, HashMap, Object> flags) { - } + @Override public void setFlags(Plot plot, HashMap, Object> flags) {} - @Override public void setFlags(PlotCluster cluster, HashMap, Object> flags) { - } + @Override public void setFlags(PlotCluster cluster, HashMap, Object> flags) {} - @Override public void setClusterName(PlotCluster cluster, String name) { - } + @Override public void setClusterName(PlotCluster cluster, String name) {} - @Override public void setAlias(Plot plot, String alias) { - } + @Override public void setAlias(Plot plot, String alias) {} - @Override public void purgeIds(Set uniqueIds) { - } + @Override public void purgeIds(Set uniqueIds) {} - @Override public void purge(PlotArea area, Set plotIds) { - } + @Override public void purge(PlotArea area, Set plotIds) {} - @Override public void setPosition(Plot plot, String position) { - } + @Override public void setPosition(Plot plot, String position) {} - @Override public void setPosition(PlotCluster cluster, String position) { - } + @Override public void setPosition(PlotCluster cluster, String position) {} - @Override public void removeTrusted(Plot plot, UUID uuid) { - } + @Override public void removeTrusted(Plot plot, UUID uuid) {} - @Override public void removeHelper(PlotCluster cluster, UUID uuid) { - } + @Override public void removeHelper(PlotCluster cluster, UUID uuid) {} - @Override public void removeMember(Plot plot, UUID uuid) { - } + @Override public void removeMember(Plot plot, UUID uuid) {} - @Override public void removeInvited(PlotCluster cluster, UUID uuid) { - } + @Override public void removeInvited(PlotCluster cluster, UUID uuid) {} - @Override public void setTrusted(Plot plot, UUID uuid) { - } + @Override public void setTrusted(Plot plot, UUID uuid) {} - @Override public void setHelper(PlotCluster cluster, UUID uuid) { - } + @Override public void setHelper(PlotCluster cluster, UUID uuid) {} - @Override public void setMember(Plot plot, UUID uuid) { - } + @Override public void setMember(Plot plot, UUID uuid) {} - @Override public void setInvited(PlotCluster cluster, UUID uuid) { - } + @Override public void setInvited(PlotCluster cluster, UUID uuid) {} - @Override public void removeDenied(Plot plot, UUID uuid) { - } + @Override public void removeDenied(Plot plot, UUID uuid) {} - @Override public void setDenied(Plot plot, UUID uuid) { - } + @Override public void setDenied(Plot plot, UUID uuid) {} @Override public HashMap getRatings(Plot plot) { return null; } - @Override public void setRating(Plot plot, UUID rater, int value) { - } + @Override public void setRating(Plot plot, UUID rater, int value) {} - @Override public void removeComment(Plot plot, PlotComment comment) { - } + @Override public void removeComment(Plot plot, PlotComment comment) {} - @Override public void clearInbox(Plot plot, String inbox) { - } + @Override public void clearInbox(Plot plot, String inbox) {} - @Override public void setComment(Plot plot, PlotComment comment) { - } + @Override public void setComment(Plot plot, PlotComment comment) {} - @Override public void getComments(Plot plot, String inbox, RunnableVal> whenDone) { - } + @Override public void getComments(Plot plot, String inbox, RunnableVal> whenDone) {} - @Override public void createPlotAndSettings(Plot plot, Runnable whenDone) { - } + @Override public void createPlotAndSettings(Plot plot, Runnable whenDone) {} - @Override public void createCluster(PlotCluster cluster) { - } + @Override public void createCluster(PlotCluster cluster) {} - @Override public void resizeCluster(PlotCluster current, PlotId min, PlotId max) { - } + @Override public void resizeCluster(PlotCluster current, PlotId min, PlotId max) {} - @Override public void movePlot(Plot originalPlot, Plot newPlot) { - } + @Override public void movePlot(Plot originalPlot, Plot newPlot) {} - @Override public void replaceUUID(UUID old, UUID now) { - } + @Override public void replaceUUID(UUID old, UUID now) {} @Override public boolean deleteTables() { return false; } - @Override public void close() { - } + @Override public void close() {} - @Override public void replaceWorld(String oldWorld, String newWorld, PlotId min, PlotId max) { - } + @Override public void replaceWorld(String oldWorld, String newWorld, PlotId min, PlotId max) {} - @Override public void updateTables(int[] oldVersion) { - } + @Override public void updateTables(int[] oldVersion) {} } diff --git a/Core/src/test/java/com/intellectualcrafters/plot/util/EventUtilTest.java b/Core/src/test/java/com/intellectualcrafters/plot/util/EventUtilTest.java index 88d26c1ed..e093b9b9e 100644 --- a/Core/src/test/java/com/intellectualcrafters/plot/util/EventUtilTest.java +++ b/Core/src/test/java/com/intellectualcrafters/plot/util/EventUtilTest.java @@ -30,8 +30,7 @@ public class EventUtilTest extends EventUtil { return false; } - @Override public void callDelete(Plot plot) { - } + @Override public void callDelete(Plot plot) {} @Override public boolean callFlagAdd(Flag flag, Plot plot) { return true; @@ -53,18 +52,13 @@ public class EventUtilTest extends EventUtil { return false; } - @Override public void callEntry(PlotPlayer player, Plot plot) { - } + @Override public void callEntry(PlotPlayer player, Plot plot) {} - @Override public void callLeave(PlotPlayer player, Plot plot) { - } + @Override public void callLeave(PlotPlayer player, Plot plot) {} - @Override public void callDenied(PlotPlayer initiator, Plot plot, UUID player, boolean added) { - } + @Override public void callDenied(PlotPlayer initiator, Plot plot, UUID player, boolean added) {} - @Override public void callTrusted(PlotPlayer initiator, Plot plot, UUID player, boolean added) { - } + @Override public void callTrusted(PlotPlayer initiator, Plot plot, UUID player, boolean added) {} - @Override public void callMember(PlotPlayer initiator, Plot plot, UUID player, boolean added) { - } + @Override public void callMember(PlotPlayer initiator, Plot plot, UUID player, boolean added) {} } \ No newline at end of file diff --git a/Sponge/src/main/java/com/plotsquared/sponge/generator/SpongeAugmentedGenerator.java b/Sponge/src/main/java/com/plotsquared/sponge/generator/SpongeAugmentedGenerator.java index fad765e6d..00bc42d61 100644 --- a/Sponge/src/main/java/com/plotsquared/sponge/generator/SpongeAugmentedGenerator.java +++ b/Sponge/src/main/java/com/plotsquared/sponge/generator/SpongeAugmentedGenerator.java @@ -19,8 +19,7 @@ public class SpongeAugmentedGenerator implements GenerationPopulator { private static SpongeAugmentedGenerator generator; - private SpongeAugmentedGenerator() { - } + private SpongeAugmentedGenerator() {} public static SpongeAugmentedGenerator get(World world) { WorldGenerator wg = world.getWorldGenerator(); diff --git a/Sponge/src/main/java/com/plotsquared/sponge/util/SpongeUtil.java b/Sponge/src/main/java/com/plotsquared/sponge/util/SpongeUtil.java index 961d12b7d..a750627a7 100644 --- a/Sponge/src/main/java/com/plotsquared/sponge/util/SpongeUtil.java +++ b/Sponge/src/main/java/com/plotsquared/sponge/util/SpongeUtil.java @@ -139,13 +139,14 @@ public class SpongeUtil extends WorldUtil { } }; } - + private static void initBlockCache() { try { PS.debug("Caching block id/data: Please wait..."); stateArray = new BlockState[Character.MAX_VALUE]; stateMap = new HashMap<>(); - Method methodGetByCombinedId = ReflectionUtils.findMethod(Class.forName("net.minecraft.block.Block"), true, Class.forName("net.minecraft.block.state.IBlockState"), int.class); + Method methodGetByCombinedId = ReflectionUtils + .findMethod(Class.forName("net.minecraft.block.Block"), true, Class.forName("net.minecraft.block.state.IBlockState"), int.class); for (int i = 0; i < Character.MAX_VALUE; i++) { try { BlockState state = (BlockState) methodGetByCombinedId.invoke(null, i); @@ -159,11 +160,11 @@ public class SpongeUtil extends WorldUtil { } } PS.debug("Done!"); - } catch (Throwable e) { + } catch (ClassNotFoundException e) { e.printStackTrace(); } } - + public static BlockState getBlockState(int id, int data) { return (BlockState) Block.getBlockById(id).getStateFromMeta(data); } @@ -251,15 +252,15 @@ public class SpongeUtil extends WorldUtil { } return new org.spongepowered.api.world.Location<>(world.get(), location.getX(), location.getY(), location.getZ()); } - + public static Location getLocation(String world, Vector3i position) { return new Location(world, position.getX(), position.getY(), position.getZ()); } - + public static Location getLocation(String world, Vector3d position) { return new Location(world, MathMan.roundInt(position.getX()), MathMan.roundInt(position.getY()), MathMan.roundInt(position.getZ())); } - + @Override public boolean isBlockSolid(PlotBlock block) { BlockState state = SpongeUtil.getBlockState(block.id, block.data); @@ -270,7 +271,7 @@ public class SpongeUtil extends WorldUtil { return false; } } - + @Override public StringComparison.ComparisonResult getClosestBlock(String name) { try { @@ -304,17 +305,16 @@ public class SpongeUtil extends WorldUtil { StringComparison outer = new StringComparison(); return outer.new ComparisonResult(match, block); - } catch (NumberFormatException ignored) { - } + } catch (NumberFormatException ignored) {} return null; } - + @Override public String getClosestMatchingName(PlotBlock block) { // TODO Auto-generated method stub return null; } - + @Override public String[] getBiomeList() { if (biomes == null) { @@ -322,13 +322,13 @@ public class SpongeUtil extends WorldUtil { } return biomeMap.keySet().toArray(new String[biomeMap.size()]); } - + @Override public boolean addItems(String world, PlotItem items) { // TODO Auto-generated method stub throw new UnsupportedOperationException("NOT IMPLEMENTED YET"); } - + @Override public int getBiomeFromString(String biome) { if (biomes == null) { @@ -336,12 +336,12 @@ public class SpongeUtil extends WorldUtil { } return biomeMap.get(biome.toUpperCase()); } - + @Override public String getBiome(String world, int x, int z) { return SpongeUtil.getWorld(world).getBiome(x, z).getName().toUpperCase(); } - + @Override public PlotBlock getBlock(Location location) { BlockState state = SpongeUtil.getWorld(location.getWorld()).getBlock(location.getX(), location.getY(), location.getZ()); @@ -397,17 +397,17 @@ public class SpongeUtil extends WorldUtil { } return result; } - + @Override public boolean isWorld(String worldName) { return SpongeUtil.getWorld(worldName) != null; } - + @Override public String getMainWorld() { return Sponge.getServer().getWorlds().iterator().next().getName(); } - + @Override public int getHighestBlock(String worldName, int x, int z) { World world = SpongeUtil.getWorld(worldName); @@ -422,7 +422,7 @@ public class SpongeUtil extends WorldUtil { } return 64; } - + @Override public void setSign(String worldName, int x, int y, int z, String[] lines) { World world = SpongeUtil.getWorld(worldName); @@ -442,7 +442,7 @@ public class SpongeUtil extends WorldUtil { } sign.offer(Keys.SIGN_LINES, text); } - + @Override public void setBiomes(String worldName, RegionWrapper region, String biomename) { World world = SpongeUtil.getWorld(worldName); From 5d8492b6758ba8f55ee471354ee8a7fb3cd3ce1d Mon Sep 17 00:00:00 2001 From: Paulomart Date: Thu, 5 May 2016 19:13:55 +0200 Subject: [PATCH 03/10] Fixes cast exception --- .../com/intellectualcrafters/plot/commands/Database.java | 5 +++-- .../java/com/intellectualcrafters/plot/commands/Visit.java | 2 +- .../com/intellectualcrafters/plot/database/AbstractDB.java | 2 +- .../java/com/intellectualcrafters/plot/database/DBFunc.java | 2 +- .../com/intellectualcrafters/plot/database/SQLManager.java | 6 +++--- 5 files changed, 9 insertions(+), 8 deletions(-) diff --git a/Core/src/main/java/com/intellectualcrafters/plot/commands/Database.java b/Core/src/main/java/com/intellectualcrafters/plot/commands/Database.java index 3f5756854..e45b01a5d 100644 --- a/Core/src/main/java/com/intellectualcrafters/plot/commands/Database.java +++ b/Core/src/main/java/com/intellectualcrafters/plot/commands/Database.java @@ -18,6 +18,7 @@ import java.sql.SQLException; import java.util.ArrayList; import java.util.Arrays; import java.util.HashMap; +import java.util.List; import java.util.Map.Entry; @CommandDeclaration( @@ -30,7 +31,7 @@ import java.util.Map.Entry; usage = "/plots database [area] ") public class Database extends SubCommand { - public static void insertPlots(final SQLManager manager, final ArrayList plots, final PlotPlayer player) { + public static void insertPlots(final SQLManager manager, final List plots, final PlotPlayer player) { TaskManager.runTaskAsync(new Runnable() { @Override public void run() { @@ -61,7 +62,7 @@ public class Database extends SubCommand { MainUtil.sendMessage(player, "/plot database [area] "); return false; } - ArrayList plots; + List plots; PlotArea area = PS.get().getPlotAreaByString(args[0]); if (area != null) { plots = PS.get().sortPlotsByTemp(area.getPlots()); diff --git a/Core/src/main/java/com/intellectualcrafters/plot/commands/Visit.java b/Core/src/main/java/com/intellectualcrafters/plot/commands/Visit.java index c00b20a34..b749580e6 100644 --- a/Core/src/main/java/com/intellectualcrafters/plot/commands/Visit.java +++ b/Core/src/main/java/com/intellectualcrafters/plot/commands/Visit.java @@ -92,7 +92,7 @@ public class Visit extends SubCommand { sendMessage(player, C.NOT_VALID_NUMBER, "(1, " + unsorted.size() + ")"); return false; } - ArrayList plots = PS.get().sortPlotsByTemp(unsorted); + List plots = PS.get().sortPlotsByTemp(unsorted); Plot plot = plots.get(page - 1); if (!plot.hasOwner()) { if (!Permissions.hasPermission(player, "plots.visit.unowned")) { diff --git a/Core/src/main/java/com/intellectualcrafters/plot/database/AbstractDB.java b/Core/src/main/java/com/intellectualcrafters/plot/database/AbstractDB.java index bc27bf59e..428ae7d49 100644 --- a/Core/src/main/java/com/intellectualcrafters/plot/database/AbstractDB.java +++ b/Core/src/main/java/com/intellectualcrafters/plot/database/AbstractDB.java @@ -36,7 +36,7 @@ public interface AbstractDB { * @param plots Plots for which the default table entries should be created * @param whenDone */ - void createPlotsAndData(ArrayList plots, Runnable whenDone); + void createPlotsAndData(List plots, Runnable whenDone); /** * Create a plot diff --git a/Core/src/main/java/com/intellectualcrafters/plot/database/DBFunc.java b/Core/src/main/java/com/intellectualcrafters/plot/database/DBFunc.java index 473cd6c46..fe57e3cc4 100644 --- a/Core/src/main/java/com/intellectualcrafters/plot/database/DBFunc.java +++ b/Core/src/main/java/com/intellectualcrafters/plot/database/DBFunc.java @@ -81,7 +81,7 @@ public class DBFunc { * * @param plots List containing all plot objects */ - public static void createPlotsAndData(ArrayList plots, Runnable whenDone) { + public static void createPlotsAndData(List plots, Runnable whenDone) { DBFunc.dbManager.createPlotsAndData(plots, whenDone); } diff --git a/Core/src/main/java/com/intellectualcrafters/plot/database/SQLManager.java b/Core/src/main/java/com/intellectualcrafters/plot/database/SQLManager.java index dbe9c2231..e0199104d 100644 --- a/Core/src/main/java/com/intellectualcrafters/plot/database/SQLManager.java +++ b/Core/src/main/java/com/intellectualcrafters/plot/database/SQLManager.java @@ -436,7 +436,7 @@ public class SQLManager implements AbstractDB { } @Override - public void createPlotsAndData(final ArrayList myList, final Runnable whenDone) { + public void createPlotsAndData(final List myList, final Runnable whenDone) { addGlobalTask(new Runnable() { @Override public void run() { @@ -580,7 +580,7 @@ public class SQLManager implements AbstractDB { * * @param myList list of plots to be created */ - public void createPlots(ArrayList myList, Runnable whenDone) { + public void createPlots(List myList, Runnable whenDone) { StmtMod mod = new StmtMod() { @Override public String getCreateMySQL(int size) { @@ -638,7 +638,7 @@ public class SQLManager implements AbstractDB { setBulk(myList, mod, whenDone); } - public void setBulk(ArrayList objList, StmtMod mod, Runnable whenDone) { + public void setBulk(List objList, StmtMod mod, Runnable whenDone) { int size = objList.size(); if (size == 0) { if (whenDone != null) { From e4350feb2a65423f964a4ac11cda630f6d0cbf00 Mon Sep 17 00:00:00 2001 From: Matt Date: Thu, 5 May 2016 13:17:17 -0400 Subject: [PATCH 04/10] Fixed missing type change --- .../com/intellectualcrafters/plot/database/AbstractDBTEst.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Core/src/test/java/com/intellectualcrafters/plot/database/AbstractDBTEst.java b/Core/src/test/java/com/intellectualcrafters/plot/database/AbstractDBTEst.java index 9d5a6ec2c..e48a0b43d 100644 --- a/Core/src/test/java/com/intellectualcrafters/plot/database/AbstractDBTEst.java +++ b/Core/src/test/java/com/intellectualcrafters/plot/database/AbstractDBTEst.java @@ -19,7 +19,7 @@ public class AbstractDBTest implements AbstractDB { @Override public void setOwner(Plot plot, UUID uuid) {} - @Override public void createPlotsAndData(ArrayList plots, Runnable whenDone) {} + @Override public void createPlotsAndData(List plots, Runnable whenDone) {} @Override public void createPlot(Plot plot) {} From 8925c66b6e3ac720b550ff7d598663cad346af42 Mon Sep 17 00:00:00 2001 From: MattBDev Date: Thu, 5 May 2016 13:19:15 -0400 Subject: [PATCH 05/10] Fix file name --- .../com/intellectualcrafters/plot/database/AbstractDBTEst.java | 1 - 1 file changed, 1 deletion(-) diff --git a/Core/src/test/java/com/intellectualcrafters/plot/database/AbstractDBTEst.java b/Core/src/test/java/com/intellectualcrafters/plot/database/AbstractDBTEst.java index e48a0b43d..5d1313d05 100644 --- a/Core/src/test/java/com/intellectualcrafters/plot/database/AbstractDBTEst.java +++ b/Core/src/test/java/com/intellectualcrafters/plot/database/AbstractDBTEst.java @@ -8,7 +8,6 @@ import com.intellectualcrafters.plot.object.PlotId; import com.intellectualcrafters.plot.object.RunnableVal; import com.intellectualcrafters.plot.object.comment.PlotComment; -import java.util.ArrayList; import java.util.HashMap; import java.util.List; import java.util.Map; From 894524f9983bb54b54ebd50afbcd86675cacf2c5 Mon Sep 17 00:00:00 2001 From: MattBDev Date: Thu, 5 May 2016 13:39:54 -0400 Subject: [PATCH 06/10] Fix test file --- .../plot/database/AbstractDBTEst.java | 142 ------------------ .../plot/database/AbstractDBTest.java | 5 + 2 files changed, 5 insertions(+), 142 deletions(-) delete mode 100644 Core/src/test/java/com/intellectualcrafters/plot/database/AbstractDBTEst.java create mode 100644 Core/src/test/java/com/intellectualcrafters/plot/database/AbstractDBTest.java diff --git a/Core/src/test/java/com/intellectualcrafters/plot/database/AbstractDBTEst.java b/Core/src/test/java/com/intellectualcrafters/plot/database/AbstractDBTEst.java deleted file mode 100644 index 5d1313d05..000000000 --- a/Core/src/test/java/com/intellectualcrafters/plot/database/AbstractDBTEst.java +++ /dev/null @@ -1,142 +0,0 @@ -package com.intellectualcrafters.plot.database; - -import com.intellectualcrafters.plot.flag.Flag; -import com.intellectualcrafters.plot.object.Plot; -import com.intellectualcrafters.plot.object.PlotArea; -import com.intellectualcrafters.plot.object.PlotCluster; -import com.intellectualcrafters.plot.object.PlotId; -import com.intellectualcrafters.plot.object.RunnableVal; -import com.intellectualcrafters.plot.object.comment.PlotComment; - -import java.util.HashMap; -import java.util.List; -import java.util.Map; -import java.util.Set; -import java.util.UUID; - -public class AbstractDBTest implements AbstractDB { - - @Override public void setOwner(Plot plot, UUID uuid) {} - - @Override public void createPlotsAndData(List plots, Runnable whenDone) {} - - @Override public void createPlot(Plot plot) {} - - @Override public void createTables() {} - - @Override public void delete(Plot plot) {} - - @Override public void deleteSettings(Plot plot) {} - - @Override public void deleteHelpers(Plot plot) {} - - @Override public void deleteTrusted(Plot plot) {} - - @Override public void deleteDenied(Plot plot) {} - - @Override public void deleteComments(Plot plot) {} - - @Override public void deleteRatings(Plot plot) {} - - @Override public void delete(PlotCluster cluster) {} - - @Override public void addPersistentMeta(UUID uuid, String key, byte[] meta, boolean delete) {} - - @Override public void removePersistentMeta(UUID uuid, String key) {} - - @Override public void getPersistentMeta(UUID uuid, RunnableVal> result) {} - - @Override public void createPlotSettings(int id, Plot plot) {} - - @Override public int getId(Plot plot) { - return 0; - } - - @Override public int getClusterId(PlotCluster cluster) { - return 0; - } - - @Override public HashMap> getPlots() { - return null; - } - - @Override public void validateAllPlots(Set toValidate) {} - - @Override public HashMap> getClusters() { - return null; - } - - @Override public void setMerged(Plot plot, boolean[] merged) {} - - @Override public void swapPlots(Plot plot1, Plot plot2) {} - - @Override public void setFlags(Plot plot, HashMap, Object> flags) {} - - @Override public void setFlags(PlotCluster cluster, HashMap, Object> flags) {} - - @Override public void setClusterName(PlotCluster cluster, String name) {} - - @Override public void setAlias(Plot plot, String alias) {} - - @Override public void purgeIds(Set uniqueIds) {} - - @Override public void purge(PlotArea area, Set plotIds) {} - - @Override public void setPosition(Plot plot, String position) {} - - @Override public void setPosition(PlotCluster cluster, String position) {} - - @Override public void removeTrusted(Plot plot, UUID uuid) {} - - @Override public void removeHelper(PlotCluster cluster, UUID uuid) {} - - @Override public void removeMember(Plot plot, UUID uuid) {} - - @Override public void removeInvited(PlotCluster cluster, UUID uuid) {} - - @Override public void setTrusted(Plot plot, UUID uuid) {} - - @Override public void setHelper(PlotCluster cluster, UUID uuid) {} - - @Override public void setMember(Plot plot, UUID uuid) {} - - @Override public void setInvited(PlotCluster cluster, UUID uuid) {} - - @Override public void removeDenied(Plot plot, UUID uuid) {} - - @Override public void setDenied(Plot plot, UUID uuid) {} - - @Override public HashMap getRatings(Plot plot) { - return null; - } - - @Override public void setRating(Plot plot, UUID rater, int value) {} - - @Override public void removeComment(Plot plot, PlotComment comment) {} - - @Override public void clearInbox(Plot plot, String inbox) {} - - @Override public void setComment(Plot plot, PlotComment comment) {} - - @Override public void getComments(Plot plot, String inbox, RunnableVal> whenDone) {} - - @Override public void createPlotAndSettings(Plot plot, Runnable whenDone) {} - - @Override public void createCluster(PlotCluster cluster) {} - - @Override public void resizeCluster(PlotCluster current, PlotId min, PlotId max) {} - - @Override public void movePlot(Plot originalPlot, Plot newPlot) {} - - @Override public void replaceUUID(UUID old, UUID now) {} - - @Override public boolean deleteTables() { - return false; - } - - @Override public void close() {} - - @Override public void replaceWorld(String oldWorld, String newWorld, PlotId min, PlotId max) {} - - @Override public void updateTables(int[] oldVersion) {} -} diff --git a/Core/src/test/java/com/intellectualcrafters/plot/database/AbstractDBTest.java b/Core/src/test/java/com/intellectualcrafters/plot/database/AbstractDBTest.java new file mode 100644 index 000000000..37caccf36 --- /dev/null +++ b/Core/src/test/java/com/intellectualcrafters/plot/database/AbstractDBTest.java @@ -0,0 +1,5 @@ +package com.intellectualcrafters.plot.database; + +public class AbstractDBTest { + +} From 1535c5e2f5838dfd0fc9738eda4ad776d34053ba Mon Sep 17 00:00:00 2001 From: MattBDev Date: Thu, 5 May 2016 13:41:11 -0400 Subject: [PATCH 07/10] Fix test file --- .../plot/database/AbstractDBTest.java | 140 +++++++++++++++++- 1 file changed, 139 insertions(+), 1 deletion(-) diff --git a/Core/src/test/java/com/intellectualcrafters/plot/database/AbstractDBTest.java b/Core/src/test/java/com/intellectualcrafters/plot/database/AbstractDBTest.java index 37caccf36..a0dce66bf 100644 --- a/Core/src/test/java/com/intellectualcrafters/plot/database/AbstractDBTest.java +++ b/Core/src/test/java/com/intellectualcrafters/plot/database/AbstractDBTest.java @@ -1,5 +1,143 @@ package com.intellectualcrafters.plot.database; -public class AbstractDBTest { +import com.intellectualcrafters.plot.flag.Flag; +import com.intellectualcrafters.plot.object.Plot; +import com.intellectualcrafters.plot.object.PlotArea; +import com.intellectualcrafters.plot.object.PlotCluster; +import com.intellectualcrafters.plot.object.PlotId; +import com.intellectualcrafters.plot.object.RunnableVal; +import com.intellectualcrafters.plot.object.comment.PlotComment; +import java.util.HashMap; +import java.util.List; +import java.util.Map; +import java.util.Set; +import java.util.UUID; + +public class AbstractDBTest implements AbstractDB { + + @Override public void setOwner(Plot plot, UUID uuid) {} + + @Override public void createPlotsAndData(List plots, Runnable whenDone) {} + + @Override public void createPlot(Plot plot) {} + + @Override public void createTables() {} + + @Override public void delete(Plot plot) {} + + @Override public void deleteSettings(Plot plot) {} + + @Override public void deleteHelpers(Plot plot) {} + + @Override public void deleteTrusted(Plot plot) {} + + @Override public void deleteDenied(Plot plot) {} + + @Override public void deleteComments(Plot plot) {} + + @Override public void deleteRatings(Plot plot) {} + + @Override public void delete(PlotCluster cluster) {} + + @Override public void addPersistentMeta(UUID uuid, String key, byte[] meta, boolean delete) {} + + @Override public void removePersistentMeta(UUID uuid, String key) {} + + @Override public void getPersistentMeta(UUID uuid, RunnableVal> result) {} + + @Override public void createPlotSettings(int id, Plot plot) {} + + @Override public int getId(Plot plot) { + return 0; + } + + @Override public int getClusterId(PlotCluster cluster) { + return 0; + } + + @Override public HashMap> getPlots() { + return null; + } + + @Override public void validateAllPlots(Set toValidate) {} + + @Override public HashMap> getClusters() { + return null; + } + + @Override public void setMerged(Plot plot, boolean[] merged) {} + + @Override public void swapPlots(Plot plot1, Plot plot2) {} + + @Override public void setFlags(Plot plot, HashMap, Object> flags) {} + + @Override public void setFlags(PlotCluster cluster, HashMap, Object> flags) {} + + @Override public void setClusterName(PlotCluster cluster, String name) {} + + @Override public void setAlias(Plot plot, String alias) {} + + @Override public void purgeIds(Set uniqueIds) {} + + @Override public void purge(PlotArea area, Set plotIds) {} + + @Override public void setPosition(Plot plot, String position) {} + + @Override public void setPosition(PlotCluster cluster, String position) {} + + @Override public void removeTrusted(Plot plot, UUID uuid) {} + + @Override public void removeHelper(PlotCluster cluster, UUID uuid) {} + + @Override public void removeMember(Plot plot, UUID uuid) {} + + @Override public void removeInvited(PlotCluster cluster, UUID uuid) {} + + @Override public void setTrusted(Plot plot, UUID uuid) {} + + @Override public void setHelper(PlotCluster cluster, UUID uuid) {} + + @Override public void setMember(Plot plot, UUID uuid) {} + + @Override public void setInvited(PlotCluster cluster, UUID uuid) {} + + @Override public void removeDenied(Plot plot, UUID uuid) {} + + @Override public void setDenied(Plot plot, UUID uuid) {} + + @Override public HashMap getRatings(Plot plot) { + return null; + } + + @Override public void setRating(Plot plot, UUID rater, int value) {} + + @Override public void removeComment(Plot plot, PlotComment comment) {} + + @Override public void clearInbox(Plot plot, String inbox) {} + + @Override public void setComment(Plot plot, PlotComment comment) {} + + @Override public void getComments(Plot plot, String inbox, RunnableVal> whenDone) {} + + @Override public void createPlotAndSettings(Plot plot, Runnable whenDone) {} + + @Override public void createCluster(PlotCluster cluster) {} + + @Override public void resizeCluster(PlotCluster current, PlotId min, PlotId max) {} + + @Override public void movePlot(Plot originalPlot, Plot newPlot) {} + + @Override public void replaceUUID(UUID old, UUID now) {} + + @Override public boolean deleteTables() { + return false; + } + + @Override public void close() {} + + @Override public void replaceWorld(String oldWorld, String newWorld, PlotId min, PlotId max) {} + + @Override public void updateTables(int[] oldVersion) {} } + From e63b436edd9c450dc522115e4128e2154dd7a1c1 Mon Sep 17 00:00:00 2001 From: MattBDev Date: Fri, 6 May 2016 22:03:02 -0400 Subject: [PATCH 08/10] Possible build everywhere fix. --- .../plot/util/EventUtil.java | 32 ++++++++----------- 1 file changed, 14 insertions(+), 18 deletions(-) diff --git a/Core/src/main/java/com/intellectualcrafters/plot/util/EventUtil.java b/Core/src/main/java/com/intellectualcrafters/plot/util/EventUtil.java index d81a2a23c..f8bfec7c1 100644 --- a/Core/src/main/java/com/intellectualcrafters/plot/util/EventUtil.java +++ b/Core/src/main/java/com/intellectualcrafters/plot/util/EventUtil.java @@ -208,9 +208,9 @@ public abstract class EventUtil { if (flagValue.isPresent()) { value = flagValue.get(); } else { - return true; + value = null; } - if (!value.contains(PlotBlock.EVERYTHING) && !value.contains(block.getPlotBlock())) { + if (value == null || !value.contains(PlotBlock.EVERYTHING) && !value.contains(block.getPlotBlock())) { if (Permissions.hasPermission(pp, C.PERMISSION_ADMIN_BUILD_OTHER.s(), notifyPerms)) { return true; } @@ -255,9 +255,9 @@ public abstract class EventUtil { if (flagValue.isPresent()) { value = flagValue.get(); } else { - return true; + value = null; } - if (!value.contains(PlotBlock.EVERYTHING) && !value.contains(block.getPlotBlock())) { + if (value == null || !value.contains(PlotBlock.EVERYTHING) && !value.contains(block.getPlotBlock())) { if (Permissions.hasPermission(pp, C.PERMISSION_ADMIN_INTERACT_OTHER.s(), notifyPerms)) { return true; } @@ -281,9 +281,9 @@ public abstract class EventUtil { if (flag.isPresent()) { value = flag.get(); } else { - return true; + value = null; } - if (!value.contains(PlotBlock.EVERYTHING) && !value.contains(block.getPlotBlock())) { + if (value == null || !value.contains(PlotBlock.EVERYTHING) && !value.contains(block.getPlotBlock())) { if (Permissions.hasPermission(pp, C.PERMISSION_ADMIN_INTERACT_OTHER.s(), notifyPerms)) { return true; } @@ -306,9 +306,9 @@ public abstract class EventUtil { if (flag.isPresent()) { value = flag.get(); } else { - return true; + value = null; } - if (!value.contains(PlotBlock.EVERYTHING) && !value.contains(block.getPlotBlock())) { + if (value == null || !value.contains(PlotBlock.EVERYTHING) && !value.contains(block.getPlotBlock())) { if (Permissions.hasPermission(pp, C.PERMISSION_ADMIN_INTERACT_OTHER.s(), notifyPerms)) { return true; } @@ -323,7 +323,6 @@ public abstract class EventUtil { if (!plot.hasOwner()) { return Permissions.hasPermission(pp, C.PERMISSION_ADMIN_INTERACT_UNOWNED.s(), notifyPerms); } - if (plot.getFlag(Flags.MOB_PLACE).or(false)) { return true; } @@ -332,9 +331,9 @@ public abstract class EventUtil { if (flagValue.isPresent()) { value = flagValue.get(); } else { - return true; + value = null; } - if (!value.contains(PlotBlock.EVERYTHING) && !value.contains(block.getPlotBlock())) { + if (value == null || !value.contains(PlotBlock.EVERYTHING) && !value.contains(block.getPlotBlock())) { if (Permissions.hasPermission(pp, C.PERMISSION_ADMIN_INTERACT_OTHER.s(), notifyPerms)) { return true; } @@ -351,19 +350,17 @@ public abstract class EventUtil { if (!plot.hasOwner()) { return Permissions.hasPermission(pp, C.PERMISSION_ADMIN_INTERACT_UNOWNED.s(), notifyPerms); } - if (plot.getFlag(Flags.MISC_PLACE).or(false)) { return true; } Optional> flag = plot.getFlag(Flags.PLACE); - HashSet value; if (flag.isPresent()) { value = flag.get(); } else { - return true; + value = null; } - if (!value.contains(PlotBlock.EVERYTHING) && !value.contains(block.getPlotBlock())) { + if (value == null || !value.contains(PlotBlock.EVERYTHING) && !value.contains(block.getPlotBlock())) { if (Permissions.hasPermission(pp, C.PERMISSION_ADMIN_INTERACT_OTHER.s(), notifyPerms)) { return true; } @@ -379,7 +376,6 @@ public abstract class EventUtil { if (!plot.hasOwner()) { return Permissions.hasPermission(pp, C.PERMISSION_ADMIN_INTERACT_UNOWNED.s(), notifyPerms); } - if (plot.getFlag(Flags.VEHICLE_PLACE).or(false)) { return true; } @@ -388,9 +384,9 @@ public abstract class EventUtil { if (flag.isPresent()) { value = flag.get(); } else { - return true; + value = null; } - if (!value.contains(PlotBlock.EVERYTHING) && !value.contains(block.getPlotBlock())) { + if (value == null || !value.contains(PlotBlock.EVERYTHING) && !value.contains(block.getPlotBlock())) { if (Permissions.hasPermission(pp, C.PERMISSION_ADMIN_INTERACT_OTHER.s(), notifyPerms)) { return true; } From 3be0f7449818c09d5c58ea00cbca70e4a77d1b77 Mon Sep 17 00:00:00 2001 From: MattBDev Date: Tue, 10 May 2016 13:41:59 -0400 Subject: [PATCH 09/10] Fix #1098 --- .../plot/database/SQLManager.java | 58 ++++++++++--------- .../plot/flag/FlagManager.java | 15 +++++ .../plot/generator/HybridPlotWorld.java | 2 +- .../plot/object/BlockLoc.java | 2 +- 4 files changed, 47 insertions(+), 30 deletions(-) diff --git a/Core/src/main/java/com/intellectualcrafters/plot/database/SQLManager.java b/Core/src/main/java/com/intellectualcrafters/plot/database/SQLManager.java index e0199104d..400820b36 100644 --- a/Core/src/main/java/com/intellectualcrafters/plot/database/SQLManager.java +++ b/Core/src/main/java/com/intellectualcrafters/plot/database/SQLManager.java @@ -733,17 +733,13 @@ public class SQLManager implements AbstractDB { e.printStackTrace(); PS.debug("&cERROR 2: | " + objList.get(0).getClass().getCanonicalName()); PS.debug("&6[WARN] Could not bulk save!"); - try { - String nonBulk = mod.getCreateSQL(); - try (PreparedStatement preparedStmt = this.connection.prepareStatement(nonBulk)) { - for (T obj : objList) { - mod.setSQL(preparedStmt, obj); - preparedStmt.addBatch(); - } - PS.debug("&aBatch 3"); - preparedStmt.executeBatch(); - preparedStmt.close(); + try (PreparedStatement preparedStmt = this.connection.prepareStatement(mod.getCreateSQL())) { + for (T obj : objList) { + mod.setSQL(preparedStmt, obj); + preparedStmt.addBatch(); } + PS.debug("&aBatch 3"); + preparedStmt.executeBatch(); } catch (SQLException e3) { e3.printStackTrace(); PS.debug("&c[ERROR] Failed to save all!"); @@ -1819,9 +1815,13 @@ public class SQLManager implements AbstractDB { if (element.contains(":")) { String[] split = element.split(":"); try { - String flag_str = split[1].replaceAll("\u00AF", ":").replaceAll("\u00B4", ","); - Flag flag = FlagManager.getFlag(split[0]); - flags.put(flag, flag.parseValue(flag_str)); + String flag_str = split[1].replaceAll("¯", ":").replaceAll("\u00B4", ","); + Flag flag = FlagManager.getFlag(split[0],false); + if (flag == null) { + PS.debug(String.format("No flag found for string value of: %s", split[0])); + } else { + flags.put(flag, flag.parseValue(flag_str)); + } } catch (Exception e) { e.printStackTrace(); exception = true; @@ -1829,8 +1829,12 @@ public class SQLManager implements AbstractDB { } else { element = element.replaceAll("\u00AF", ":").replaceAll("\u00B4", ","); if (StringMan.isAlpha(element.replaceAll("_", "").replaceAll("-", ""))) { - Flag flag = FlagManager.getFlag(element); - flags.put(flag, flag.parseValue("")); + Flag flag = FlagManager.getFlag(element,false); + if (flag == null) { + PS.debug(String.format("No flag found for string value of: %s", element)); + } else { + flags.put(flag, flag.parseValue("")); + } } else { PS.debug("INVALID FLAG: " + element); } @@ -2624,27 +2628,25 @@ public class SQLManager implements AbstractDB { flags_string = myflags.split(","); } HashMap, Object> flags = new HashMap<>(); - boolean exception = false; for (String element : flags_string) { if (element.contains(":")) { String[] split = element.split(":"); - try { - String flag_str = split[1].replaceAll("\u00AF", ":").replaceAll("�", ","); - Flag flag = FlagManager.getFlag(split[0]); + String flag_str = split[1].replaceAll("\u00AF", ":").replaceAll("�", ","); + Flag flag = FlagManager.getFlag(split[0],false); + if (flag == null) { + PS.debug(String.format("No flag found for string value of: %s", split[0])); + } else { flags.put(flag, flag.parseValue(flag_str)); - } catch (Exception e) { - e.printStackTrace(); - exception = true; } } else { - Flag flag = FlagManager.getFlag(element); - flags.put(flag, flag.parseValue("")); + Flag flag = FlagManager.getFlag(element,false); + if (flag == null) { + PS.debug(String.format("No flag found for string value of: %s", element)); + } else { + flags.put(flag, flag.parseValue("")); + } } } - if (exception) { - PS.debug("&cCluster " + id + " had an invalid flag. A fix has been attempted."); - PS.debug("&c" + myflags); - } cluster.settings.flags = flags; } else { PS.debug("&cCluster " + id + " in cluster_settings does not exist. Please create the cluster or remove this entry."); diff --git a/Core/src/main/java/com/intellectualcrafters/plot/flag/FlagManager.java b/Core/src/main/java/com/intellectualcrafters/plot/flag/FlagManager.java index c099af9b0..27ce607b9 100644 --- a/Core/src/main/java/com/intellectualcrafters/plot/flag/FlagManager.java +++ b/Core/src/main/java/com/intellectualcrafters/plot/flag/FlagManager.java @@ -257,6 +257,21 @@ public class FlagManager { return null; } + public static Flag getFlag(String string, boolean ignoreReserved) { + for (Flag flag : Flags.getFlags()) { + if (flag.getName().equalsIgnoreCase(string)) { + if (!ignoreReserved) { + if (isReserved(flag)) { + return null; + } + } + return flag; + } + } + return null; + } + + public static Map, Object> parseFlags(List flagstrings) { HashMap, Object> map = new HashMap<>(); diff --git a/Core/src/main/java/com/intellectualcrafters/plot/generator/HybridPlotWorld.java b/Core/src/main/java/com/intellectualcrafters/plot/generator/HybridPlotWorld.java index 2f4294475..267e36750 100644 --- a/Core/src/main/java/com/intellectualcrafters/plot/generator/HybridPlotWorld.java +++ b/Core/src/main/java/com/intellectualcrafters/plot/generator/HybridPlotWorld.java @@ -158,7 +158,7 @@ public class HybridPlotWorld extends ClassicPlotWorld { } try { setupSchematics(); - } catch (Exception e) { + } catch (Exception ignored) { PS.debug("&c - road schematics are disabled for this world."); } } diff --git a/Core/src/main/java/com/intellectualcrafters/plot/object/BlockLoc.java b/Core/src/main/java/com/intellectualcrafters/plot/object/BlockLoc.java index e3e310609..32f029d8d 100644 --- a/Core/src/main/java/com/intellectualcrafters/plot/object/BlockLoc.java +++ b/Core/src/main/java/com/intellectualcrafters/plot/object/BlockLoc.java @@ -74,7 +74,7 @@ public class BlockLoc { if (this.x == 0 && this.y == 0 && this.z == 0) { return ""; } - return this.x + "," + this.y + "," + this.z + "," + this.yaw + "," + this.pitch; + return this.x + "," + this.y + ',' + this.z + ',' + this.yaw + ',' + this.pitch; } } From a4647b05e201b408983b6882f326954c5f726e0a Mon Sep 17 00:00:00 2001 From: MattBDev Date: Tue, 10 May 2016 14:24:02 -0400 Subject: [PATCH 10/10] Fix #1011 --- .../com/plotsquared/bukkit/listeners/PlotPlusListener.java | 7 +++++-- Sponge/build.gradle | 1 + build.gradle | 1 + 3 files changed, 7 insertions(+), 2 deletions(-) diff --git a/Bukkit/src/main/java/com/plotsquared/bukkit/listeners/PlotPlusListener.java b/Bukkit/src/main/java/com/plotsquared/bukkit/listeners/PlotPlusListener.java index 6eba7c518..c61c18180 100644 --- a/Bukkit/src/main/java/com/plotsquared/bukkit/listeners/PlotPlusListener.java +++ b/Bukkit/src/main/java/com/plotsquared/bukkit/listeners/PlotPlusListener.java @@ -131,8 +131,11 @@ public class PlotPlusListener extends PlotListener implements Listener { return; } UUID uuid = pp.getUUID(); - if (plot.isAdded(uuid) && plot.getFlag(Flags.ITEM_DROP).or(false)) { - event.setCancelled(true); + if (plot.isAdded(uuid)) { + Optional flag = plot.getFlag(Flags.ITEM_DROP); + if (flag.isPresent() && !flag.get()) { + event.setCancelled(true); + } } } diff --git a/Sponge/build.gradle b/Sponge/build.gradle index 7acf27887..02a459af2 100644 --- a/Sponge/build.gradle +++ b/Sponge/build.gradle @@ -1,6 +1,7 @@ buildscript { repositories { jcenter() + mavenLocal() maven { name = "forge" url = "http://files.minecraftforge.net/maven" diff --git a/build.gradle b/build.gradle index 9dae120c8..5f0327dd2 100644 --- a/build.gradle +++ b/build.gradle @@ -3,6 +3,7 @@ buildscript { mavenCentral() maven { url = "https://oss.sonatype.org/content/repositories/snapshots/" } jcenter() + mavenLocal() } dependencies { classpath 'com.github.jengelman.gradle.plugins:shadow:1.2.3'