From dfd29f6713367133e3aa04e1038f186cd30cf7d3 Mon Sep 17 00:00:00 2001 From: Matt Date: Sun, 13 Mar 2016 14:09:48 -0400 Subject: [PATCH 1/6] Various changes Plot class is now more reliable as most fields are private Cleanup some classes. Fixes #955 makes progress on #953 --- .../com/plotsquared/bukkit/BukkitMain.java | 74 ++++++- .../bukkit/listeners/PlayerEvents.java | 147 ++++++------- .../com/intellectualcrafters/plot/PS.java | 76 +++++-- .../plot/commands/Info.java | 13 +- .../plot/commands/MainCommand.java | 10 +- .../plot/config/Settings.java | 8 - .../plot/database/SQLManager.java | 36 ++- .../plot/generator/SquarePlotManager.java | 4 +- .../plot/object/Plot.java | 205 ++++++++---------- .../plot/util/StringMan.java | 2 +- 10 files changed, 335 insertions(+), 240 deletions(-) diff --git a/Bukkit/src/main/java/com/plotsquared/bukkit/BukkitMain.java b/Bukkit/src/main/java/com/plotsquared/bukkit/BukkitMain.java index cf531d256..ca76ee0fa 100644 --- a/Bukkit/src/main/java/com/plotsquared/bukkit/BukkitMain.java +++ b/Bukkit/src/main/java/com/plotsquared/bukkit/BukkitMain.java @@ -12,23 +12,74 @@ import com.intellectualcrafters.plot.generator.GeneratorWrapper; import com.intellectualcrafters.plot.generator.HybridGen; import com.intellectualcrafters.plot.generator.HybridUtils; import com.intellectualcrafters.plot.generator.IndependentPlotGenerator; -import com.intellectualcrafters.plot.object.*; -import com.intellectualcrafters.plot.util.*; +import com.intellectualcrafters.plot.object.Plot; +import com.intellectualcrafters.plot.object.PlotArea; +import com.intellectualcrafters.plot.object.PlotPlayer; +import com.intellectualcrafters.plot.object.RunnableVal; +import com.intellectualcrafters.plot.object.SetupObject; +import com.intellectualcrafters.plot.util.AbstractTitle; +import com.intellectualcrafters.plot.util.ChatManager; +import com.intellectualcrafters.plot.util.ChunkManager; +import com.intellectualcrafters.plot.util.ConsoleColors; +import com.intellectualcrafters.plot.util.EconHandler; +import com.intellectualcrafters.plot.util.EventUtil; +import com.intellectualcrafters.plot.util.InventoryUtil; +import com.intellectualcrafters.plot.util.MainUtil; +import com.intellectualcrafters.plot.util.PlotQueue; +import com.intellectualcrafters.plot.util.SchematicHandler; +import com.intellectualcrafters.plot.util.SetupUtils; +import com.intellectualcrafters.plot.util.StringMan; +import com.intellectualcrafters.plot.util.TaskManager; +import com.intellectualcrafters.plot.util.UUIDHandler; +import com.intellectualcrafters.plot.util.UUIDHandlerImplementation; +import com.intellectualcrafters.plot.util.WorldUtil; import com.intellectualcrafters.plot.uuid.UUIDWrapper; import com.plotsquared.bukkit.commands.DebugUUID; import com.plotsquared.bukkit.database.plotme.ClassicPlotMeConnector; import com.plotsquared.bukkit.database.plotme.LikePlotMeConverter; import com.plotsquared.bukkit.database.plotme.PlotMeConnector_017; import com.plotsquared.bukkit.generator.BukkitPlotGenerator; -import com.plotsquared.bukkit.listeners.*; +import com.plotsquared.bukkit.listeners.ChunkListener; +import com.plotsquared.bukkit.listeners.ForceFieldListener; +import com.plotsquared.bukkit.listeners.PlayerEvents; +import com.plotsquared.bukkit.listeners.PlayerEvents_1_8; +import com.plotsquared.bukkit.listeners.PlayerEvents_1_8_3; +import com.plotsquared.bukkit.listeners.PlotPlusListener; +import com.plotsquared.bukkit.listeners.WorldEvents; import com.plotsquared.bukkit.listeners.worldedit.WEListener; import com.plotsquared.bukkit.titles.DefaultTitle_19; -import com.plotsquared.bukkit.util.*; -import com.plotsquared.bukkit.util.block.*; -import com.plotsquared.bukkit.uuid.*; +import com.plotsquared.bukkit.util.BukkitChatManager; +import com.plotsquared.bukkit.util.BukkitChunkManager; +import com.plotsquared.bukkit.util.BukkitCommand; +import com.plotsquared.bukkit.util.BukkitEconHandler; +import com.plotsquared.bukkit.util.BukkitEventUtil; +import com.plotsquared.bukkit.util.BukkitHybridUtils; +import com.plotsquared.bukkit.util.BukkitInventoryUtil; +import com.plotsquared.bukkit.util.BukkitPlainChatManager; +import com.plotsquared.bukkit.util.BukkitSchematicHandler; +import com.plotsquared.bukkit.util.BukkitSetupUtils; +import com.plotsquared.bukkit.util.BukkitTaskManager; +import com.plotsquared.bukkit.util.BukkitUtil; +import com.plotsquared.bukkit.util.Metrics; +import com.plotsquared.bukkit.util.SendChunk; +import com.plotsquared.bukkit.util.SetGenCB; +import com.plotsquared.bukkit.util.block.FastQueue_1_7; +import com.plotsquared.bukkit.util.block.FastQueue_1_8; +import com.plotsquared.bukkit.util.block.FastQueue_1_8_3; +import com.plotsquared.bukkit.util.block.FastQueue_1_9; +import com.plotsquared.bukkit.util.block.SlowQueue; +import com.plotsquared.bukkit.uuid.DefaultUUIDWrapper; +import com.plotsquared.bukkit.uuid.FileUUIDHandler; +import com.plotsquared.bukkit.uuid.LowerOfflineUUIDWrapper; +import com.plotsquared.bukkit.uuid.OfflineUUIDWrapper; +import com.plotsquared.bukkit.uuid.SQLUUIDHandler; import com.sk89q.worldedit.bukkit.WorldEditPlugin; -import org.bukkit.*; +import org.bukkit.Bukkit; +import org.bukkit.ChatColor; import org.bukkit.Location; +import org.bukkit.OfflinePlayer; +import org.bukkit.Server; +import org.bukkit.World; import org.bukkit.command.PluginCommand; import org.bukkit.entity.Entity; import org.bukkit.entity.Player; @@ -42,7 +93,11 @@ import java.io.File; import java.io.IOException; import java.lang.reflect.InvocationTargetException; import java.lang.reflect.Method; -import java.util.*; +import java.util.ArrayList; +import java.util.Arrays; +import java.util.Iterator; +import java.util.List; +import java.util.UUID; public class BukkitMain extends JavaPlugin implements Listener, IPlotMain { @@ -87,9 +142,6 @@ public class BukkitMain extends JavaPlugin implements Listener, IPlotMain { @Override public void log(String message) { - if (message == null) { - return; - } if ((THIS != null) && (Bukkit.getServer().getConsoleSender() != null)) { try { message = C.color(message); 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 d247e7a8b..e101706fc 100644 --- a/Bukkit/src/main/java/com/plotsquared/bukkit/listeners/PlayerEvents.java +++ b/Bukkit/src/main/java/com/plotsquared/bukkit/listeners/PlayerEvents.java @@ -27,16 +27,6 @@ import com.plotsquared.bukkit.object.BukkitLazyBlock; import com.plotsquared.bukkit.object.BukkitPlayer; import com.plotsquared.bukkit.util.BukkitUtil; import com.plotsquared.listener.PlayerBlockEventType; -import java.util.ArrayList; -import java.util.Arrays; -import java.util.HashSet; -import java.util.Iterator; -import java.util.List; -import java.util.Map.Entry; -import java.util.Objects; -import java.util.Set; -import java.util.UUID; -import java.util.regex.Pattern; import org.bukkit.Bukkit; import org.bukkit.ChatColor; import org.bukkit.Material; @@ -52,11 +42,13 @@ import org.bukkit.entity.EnderDragon; import org.bukkit.entity.Entity; import org.bukkit.entity.EntityType; import org.bukkit.entity.Hanging; +import org.bukkit.entity.Horse; import org.bukkit.entity.HumanEntity; import org.bukkit.entity.LivingEntity; import org.bukkit.entity.Monster; import org.bukkit.entity.Player; import org.bukkit.entity.Projectile; +import org.bukkit.entity.Skeleton; import org.bukkit.entity.TNTPrimed; import org.bukkit.entity.Tameable; import org.bukkit.entity.ThrownPotion; @@ -115,6 +107,17 @@ import org.bukkit.projectiles.BlockProjectileSource; import org.bukkit.projectiles.ProjectileSource; import org.bukkit.util.Vector; +import java.util.ArrayList; +import java.util.Arrays; +import java.util.HashSet; +import java.util.Iterator; +import java.util.List; +import java.util.Map.Entry; +import java.util.Objects; +import java.util.Set; +import java.util.UUID; +import java.util.regex.Pattern; + /** * Player Events involving plots * @@ -1307,9 +1310,7 @@ public class PlayerEvents extends com.plotsquared.listener.PlotListener implemen } public boolean checkEntity(final Entity entity, final Plot plot) { - if (plot == null || plot.owner == null || plot.settings == null || plot.getFlags().isEmpty() && plot.getArea().DEFAULT_FLAGS - .isEmpty - ()) { + if (plot == null || plot.owner == null || plot.getFlags().isEmpty() && plot.getArea().DEFAULT_FLAGS.isEmpty()) { return false; } switch (entity.getType()) { @@ -1324,6 +1325,10 @@ public class PlayerEvents extends com.plotsquared.listener.PlotListener implemen case SNOWBALL: case ENDER_PEARL: case ARROW: + case TIPPED_ARROW: + case SPECTRAL_ARROW: + case SHULKER_BULLET: + case DRAGON_FIREBALL: // projectile case PRIMED_TNT: case FALLING_BLOCK: @@ -1336,6 +1341,7 @@ public class PlayerEvents extends com.plotsquared.listener.PlotListener implemen case LEASH_HITCH: case FIREWORK: case WEATHER: + case AREA_EFFECT_CLOUD: case LIGHTNING: case WITHER_SKULL: case UNKNOWN: @@ -1360,7 +1366,6 @@ public class PlayerEvents extends com.plotsquared.listener.PlotListener implemen case MUSHROOM_COW: case OCELOT: case PIG: - case HORSE: case SQUID: case VILLAGER: case IRON_GOLEM: @@ -1389,26 +1394,30 @@ public class PlayerEvents extends com.plotsquared.listener.PlotListener implemen case WITCH: case WITHER: case ZOMBIE: + case SHULKER: // monster return checkEntity(plot, "entity-cap", "mob-cap", "hostile-cap"); + case HORSE: + Horse horse = ((Horse) entity); + if (horse.getVariant().equals(Horse.Variant.SKELETON_HORSE) && entity.getPassenger() instanceof Skeleton) { + return checkEntity(plot, "entity-cap", "mob-cap", "hostile-cap"); + } + return checkEntity(plot, "entity-cap", "mob-cap", "animal-cap"); default: - String[] types; if (entity instanceof LivingEntity) { if (entity instanceof Animals) { - types = new String[] { "entity-cap", "mob-cap", "animal-cap" }; + return checkEntity(plot, "entity-cap", "mob-cap", "animal-cap"); } else if (entity instanceof Monster) { - types = new String[] { "entity-cap", "mob-cap", "hostile-cap" }; + return checkEntity(plot, "entity-cap", "mob-cap", "hostile-cap"); } else { - types = new String[] { "entity-cap", "mob-cap" }; + return checkEntity(plot, "entity-cap", "mob-cap"); } } else if (entity instanceof Vehicle) { - types = new String[] { "entity-cap", "vehicle-cap" }; + return checkEntity(plot, "entity-cap", "vehicle-cap"); } else if (entity instanceof Hanging) { - types = new String[] { "entity-cap", "misc-cap" }; - } else { - types = new String[] { "entity-cap" }; + return checkEntity(plot, "entity-cap", "misc-cap"); } - return checkEntity(plot, types); + return checkEntity(plot, "entity-cap"); } } @@ -1423,12 +1432,10 @@ public class PlayerEvents extends com.plotsquared.listener.PlotListener implemen final Entity ent = e.getIgnitingEntity(); if (ent != null) { loc = BukkitUtil.getLocation(ent); + } else if (player != null) { + loc = BukkitUtil.getLocation(player); } else { - if (player != null) { - loc = BukkitUtil.getLocation(player); - } else { - return; - } + return; } } PlotArea area = loc.getPlotArea(); @@ -1511,24 +1518,22 @@ public class PlayerEvents extends com.plotsquared.listener.PlotListener implemen } } else if (lastPlot != null && now.equals(lastPlot)) { return; - } else { - if (!plotEntry(pp, now) && tmp_teleport) { - MainUtil.sendMessage(pp, C.NO_PERMISSION_EVENT, C.PERMISSION_ADMIN_ENTRY_DENIED); - if (!now.equals(area.getPlot(BukkitUtil.getLocation(from)))) { + } else if (!plotEntry(pp, now) && tmp_teleport) { + MainUtil.sendMessage(pp, C.NO_PERMISSION_EVENT, C.PERMISSION_ADMIN_ENTRY_DENIED); + if (!now.equals(area.getPlot(BukkitUtil.getLocation(from)))) { + tmp_teleport = false; + player.teleport(from); + tmp_teleport = true; + } else { + Location spawn = BukkitUtil.getLocation(player.getWorld().getSpawnLocation()); + if (spawn.getEuclideanDistanceSquared(pp.getLocation()) > 2) { tmp_teleport = false; - player.teleport(from); + player.teleport(player.getWorld().getSpawnLocation()); tmp_teleport = true; - } else { - Location spawn = BukkitUtil.getLocation(player.getWorld().getSpawnLocation()); - if (spawn.getEuclideanDistanceSquared(pp.getLocation()) > 2) { - tmp_teleport = false; - player.teleport(player.getWorld().getSpawnLocation()); - tmp_teleport = true; - } } - event.setCancelled(true); - return; } + event.setCancelled(true); + return; } final Integer border = area.getBorder(); if (tmp_teleport) { @@ -1583,24 +1588,22 @@ public class PlayerEvents extends com.plotsquared.listener.PlotListener implemen } } else if (lastPlot != null && now.equals(lastPlot)) { return; - } else { - if (!plotEntry(pp, now) && tmp_teleport) { - MainUtil.sendMessage(pp, C.NO_PERMISSION_EVENT, C.PERMISSION_ADMIN_ENTRY_DENIED); - if (!now.equals(area.getPlot(BukkitUtil.getLocation(from)))) { + } else if (!plotEntry(pp, now) && tmp_teleport) { + MainUtil.sendMessage(pp, C.NO_PERMISSION_EVENT, C.PERMISSION_ADMIN_ENTRY_DENIED); + if (!now.equals(area.getPlot(BukkitUtil.getLocation(from)))) { + tmp_teleport = false; + player.teleport(from); + tmp_teleport = true; + } else { + Location spawn = BukkitUtil.getLocation(player.getWorld().getSpawnLocation()); + if (spawn.getEuclideanDistanceSquared(pp.getLocation()) > 2) { tmp_teleport = false; - player.teleport(from); + player.teleport(player.getWorld().getSpawnLocation()); tmp_teleport = true; - } else { - Location spawn = BukkitUtil.getLocation(player.getWorld().getSpawnLocation()); - if (spawn.getEuclideanDistanceSquared(pp.getLocation()) > 2) { - tmp_teleport = false; - player.teleport(player.getWorld().getSpawnLocation()); - tmp_teleport = true; - } } - event.setCancelled(true); - return; } + event.setCancelled(true); + return; } final Integer border = area.getBorder(); if (tmp_teleport) { @@ -1638,24 +1641,22 @@ public class PlayerEvents extends com.plotsquared.listener.PlotListener implemen } MainUtil.sendMessage(pp, C.NO_PERMISSION_EVENT, C.PERMISSION_ADMIN_BUILD_ROAD); e.setCancelled(true); - } else { - if (!plot.hasOwner()) { - if (Permissions.hasPermission(pp, C.PERMISSION_ADMIN_BUILD_UNOWNED)) { - return; - } - MainUtil.sendMessage(pp, C.NO_PERMISSION_EVENT, C.PERMISSION_ADMIN_BUILD_UNOWNED); - e.setCancelled(true); - } else if (!plot.isAdded(pp.getUUID())) { - final Flag use = FlagManager.getPlotFlagRaw(plot, C.FLAG_USE.s()); - if (use != null && ((HashSet) use.getValue()).contains(new PlotBlock((short) e.getBucket().getId(), (byte) 0))) { - return; - } - if (Permissions.hasPermission(pp, C.PERMISSION_ADMIN_BUILD_OTHER)) { - return; - } - MainUtil.sendMessage(pp, C.NO_PERMISSION_EVENT, C.PERMISSION_ADMIN_BUILD_OTHER); - e.setCancelled(true); + } else if (!plot.hasOwner()) { + if (Permissions.hasPermission(pp, C.PERMISSION_ADMIN_BUILD_UNOWNED)) { + return; } + MainUtil.sendMessage(pp, C.NO_PERMISSION_EVENT, C.PERMISSION_ADMIN_BUILD_UNOWNED); + e.setCancelled(true); + } else if (!plot.isAdded(pp.getUUID())) { + final Flag use = FlagManager.getPlotFlagRaw(plot, C.FLAG_USE.s()); + if (use != null && ((HashSet) use.getValue()).contains(new PlotBlock((short) e.getBucket().getId(), (byte) 0))) { + return; + } + if (Permissions.hasPermission(pp, C.PERMISSION_ADMIN_BUILD_OTHER)) { + return; + } + MainUtil.sendMessage(pp, C.NO_PERMISSION_EVENT, C.PERMISSION_ADMIN_BUILD_OTHER); + e.setCancelled(true); } } diff --git a/Core/src/main/java/com/intellectualcrafters/plot/PS.java b/Core/src/main/java/com/intellectualcrafters/plot/PS.java index 7ace1dc97..2fc597262 100644 --- a/Core/src/main/java/com/intellectualcrafters/plot/PS.java +++ b/Core/src/main/java/com/intellectualcrafters/plot/PS.java @@ -8,7 +8,11 @@ import com.intellectualcrafters.plot.commands.WE_Anywhere; import com.intellectualcrafters.plot.config.C; import com.intellectualcrafters.plot.config.Configuration; import com.intellectualcrafters.plot.config.Settings; -import com.intellectualcrafters.plot.database.*; +import com.intellectualcrafters.plot.database.DBFunc; +import com.intellectualcrafters.plot.database.Database; +import com.intellectualcrafters.plot.database.MySQL; +import com.intellectualcrafters.plot.database.SQLManager; +import com.intellectualcrafters.plot.database.SQLite; import com.intellectualcrafters.plot.flag.AbstractFlag; import com.intellectualcrafters.plot.flag.FlagManager; import com.intellectualcrafters.plot.flag.FlagValue; @@ -16,21 +20,67 @@ import com.intellectualcrafters.plot.generator.GeneratorWrapper; import com.intellectualcrafters.plot.generator.HybridPlotWorld; import com.intellectualcrafters.plot.generator.HybridUtils; import com.intellectualcrafters.plot.generator.IndependentPlotGenerator; -import com.intellectualcrafters.plot.object.*; -import com.intellectualcrafters.plot.util.*; +import com.intellectualcrafters.plot.object.Location; +import com.intellectualcrafters.plot.object.Plot; +import com.intellectualcrafters.plot.object.PlotAnalysis; +import com.intellectualcrafters.plot.object.PlotArea; +import com.intellectualcrafters.plot.object.PlotCluster; +import com.intellectualcrafters.plot.object.PlotFilter; +import com.intellectualcrafters.plot.object.PlotId; +import com.intellectualcrafters.plot.object.PlotManager; +import com.intellectualcrafters.plot.object.PlotPlayer; +import com.intellectualcrafters.plot.object.RegionWrapper; +import com.intellectualcrafters.plot.object.RunnableVal; +import com.intellectualcrafters.plot.util.AbstractTitle; +import com.intellectualcrafters.plot.util.ChatManager; +import com.intellectualcrafters.plot.util.ChunkManager; +import com.intellectualcrafters.plot.util.CommentManager; +import com.intellectualcrafters.plot.util.EconHandler; +import com.intellectualcrafters.plot.util.EventUtil; +import com.intellectualcrafters.plot.util.ExpireManager; +import com.intellectualcrafters.plot.util.InventoryUtil; +import com.intellectualcrafters.plot.util.MainUtil; +import com.intellectualcrafters.plot.util.MathMan; +import com.intellectualcrafters.plot.util.PlotGamemode; +import com.intellectualcrafters.plot.util.PlotWeather; +import com.intellectualcrafters.plot.util.ReflectionUtils; +import com.intellectualcrafters.plot.util.SchematicHandler; +import com.intellectualcrafters.plot.util.SetQueue; +import com.intellectualcrafters.plot.util.SetupUtils; +import com.intellectualcrafters.plot.util.StringMan; +import com.intellectualcrafters.plot.util.TaskManager; +import com.intellectualcrafters.plot.util.UUIDHandler; +import com.intellectualcrafters.plot.util.WorldUtil; import com.intellectualcrafters.plot.util.area.QuadMap; import com.plotsquared.listener.WESubscriber; import com.sk89q.worldedit.WorldEdit; -import java.io.*; +import java.io.File; +import java.io.FileInputStream; +import java.io.FileOutputStream; +import java.io.IOException; +import java.io.InputStream; import java.net.MalformedURLException; import java.net.URISyntaxException; import java.net.URL; import java.net.URLConnection; import java.nio.file.Files; import java.sql.SQLException; -import java.util.*; +import java.util.ArrayDeque; +import java.util.ArrayList; +import java.util.Arrays; +import java.util.Collection; +import java.util.Collections; +import java.util.Comparator; +import java.util.HashMap; +import java.util.HashSet; +import java.util.Iterator; +import java.util.List; +import java.util.Map; import java.util.Map.Entry; +import java.util.Objects; +import java.util.Set; +import java.util.UUID; import java.util.regex.Pattern; import java.util.zip.ZipEntry; import java.util.zip.ZipInputStream; @@ -46,12 +96,7 @@ public class PS { // protected static: private static PS instance; - private HashSet plotareaHashCheck = new HashSet<>(); - private boolean plotareaHasCollision = false; - /** - * All plot areas (quick global access) - */ - private PlotArea[] plotareas = new PlotArea[0]; + private final HashSet plotareaHashCheck = new HashSet<>(); /** * All plot areas mapped by world (quick world access) */ @@ -73,6 +118,11 @@ public class PS { public TaskManager TASK; public WorldEdit worldedit; public URL update; + private boolean plotareaHasCollision = false; + /** + * All plot areas (quick global access) + */ + private PlotArea[] plotareas = new PlotArea[0]; // private: private File storageFile; private File FILE = null; // This file @@ -2312,7 +2362,7 @@ public class PS { */ private void setupStorage() { storage.set("version", StringMan.join(VERSION, ".")); - final Map options = new HashMap<>(); + final Map options = new HashMap<>(9); options.put("mysql.use", false); options.put("sqlite.use", true); options.put("sqlite.db", "storage"); @@ -2343,7 +2393,7 @@ public class PS { */ private void showDebug() { if (Settings.DEBUG) { - final Map settings = new HashMap<>(); + final Map settings = new HashMap<>(9); settings.put("Kill Road Mobs", "" + Settings.KILL_ROAD_MOBS); settings.put("Use Metrics", "" + Settings.METRICS); settings.put("Delete Plots On Ban", "" + Settings.DELETE_PLOTS_ON_BAN); diff --git a/Core/src/main/java/com/intellectualcrafters/plot/commands/Info.java b/Core/src/main/java/com/intellectualcrafters/plot/commands/Info.java index c82ddd072..13bc921ed 100644 --- a/Core/src/main/java/com/intellectualcrafters/plot/commands/Info.java +++ b/Core/src/main/java/com/intellectualcrafters/plot/commands/Info.java @@ -20,8 +20,6 @@ //////////////////////////////////////////////////////////////////////////////////////////////////// package com.intellectualcrafters.plot.commands; -import java.util.UUID; - import com.intellectualcrafters.plot.config.C; import com.intellectualcrafters.plot.database.DBFunc; import com.intellectualcrafters.plot.object.Plot; @@ -32,8 +30,9 @@ import com.intellectualcrafters.plot.object.RunnableVal; import com.intellectualcrafters.plot.util.MainUtil; import com.plotsquared.general.commands.CommandDeclaration; -@CommandDeclaration(command = "info", aliases = { "i" }, description = "Display plot info", usage = "/plot info ", - category = CommandCategory.INFO) +import java.util.UUID; + +@CommandDeclaration(command = "info", aliases = "i", description = "Display plot info", usage = "/plot info ", category = CommandCategory.INFO) public class Info extends SubCommand { @Override @@ -73,7 +72,7 @@ public class Info extends SubCommand { plot = player.getCurrentPlot(); } if (plot == null) { - MainUtil.sendMessage(player, C.NOT_IN_PLOT); + MainUtil.sendMessage(player, C.NOT_IN_PLOT.s()); return false; } if (arg != null) { @@ -116,8 +115,8 @@ public class Info extends SubCommand { boolean trustedEveryone; // Wildcard player {added} { - containsEveryone = (plot.getTrusted() != null) && plot.getTrusted().contains(DBFunc.everyone); - trustedEveryone = (plot.getMembers() != null) && plot.getMembers().contains(DBFunc.everyone); + containsEveryone = plot.getTrusted().contains(DBFunc.everyone); + trustedEveryone = plot.getMembers().contains(DBFunc.everyone); } // Unclaimed? if (!hasOwner && !containsEveryone && !trustedEveryone) { diff --git a/Core/src/main/java/com/intellectualcrafters/plot/commands/MainCommand.java b/Core/src/main/java/com/intellectualcrafters/plot/commands/MainCommand.java index 3a67e200c..c337b673e 100644 --- a/Core/src/main/java/com/intellectualcrafters/plot/commands/MainCommand.java +++ b/Core/src/main/java/com/intellectualcrafters/plot/commands/MainCommand.java @@ -41,7 +41,6 @@ import com.plotsquared.general.commands.CommandManager; import java.util.ArrayList; import java.util.Arrays; import java.util.Collections; -import java.util.HashMap; import java.util.HashSet; import java.util.List; @@ -53,8 +52,7 @@ import java.util.List; public class MainCommand extends CommandManager { private static MainCommand instance; - private HashMap> setCommands; - + private MainCommand() { super(null, new ArrayList>()); instance = this; @@ -282,8 +280,8 @@ public class MainCommand extends CommandManager { break; } // Save meta - loc = (Location) player.getMeta("location"); - plot = (Plot) player.getMeta("lastplot"); + loc = player.getMeta("location"); + plot = player.getMeta("lastplot"); tp = true; // Set loc player.setMeta("location", newPlot.getBottomAbs()); @@ -320,7 +318,7 @@ public class MainCommand extends CommandManager { public int getMatch(String[] args, Command cmd) { int count = 0; String perm = cmd.getPermission(); - HashSet desc = new HashSet(); + HashSet desc = new HashSet<>(); for (String alias : cmd.getAliases()) { if (alias.startsWith(args[0])) { count += 5; diff --git a/Core/src/main/java/com/intellectualcrafters/plot/config/Settings.java b/Core/src/main/java/com/intellectualcrafters/plot/config/Settings.java index 3dc6a7c03..e9ba60fd2 100644 --- a/Core/src/main/java/com/intellectualcrafters/plot/config/Settings.java +++ b/Core/src/main/java/com/intellectualcrafters/plot/config/Settings.java @@ -122,18 +122,10 @@ public class Settings { * Max allowed plots */ public static int MAX_PLOTS = 127; - /** - * WorldGuard region on claimed plots - */ - public static boolean WORLDGUARD = false; /** * metrics */ public static boolean METRICS = true; - /** - * plot specific resource pack - */ - public static String PLOT_SPECIFIC_RESOURCE_PACK = ""; /** * Kill road mobs? */ 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 a44be9779..4801ee468 100644 --- a/Core/src/main/java/com/intellectualcrafters/plot/database/SQLManager.java +++ b/Core/src/main/java/com/intellectualcrafters/plot/database/SQLManager.java @@ -25,15 +25,37 @@ import com.intellectualcrafters.plot.PS; import com.intellectualcrafters.plot.config.Settings; import com.intellectualcrafters.plot.flag.Flag; import com.intellectualcrafters.plot.flag.FlagManager; -import com.intellectualcrafters.plot.object.*; +import com.intellectualcrafters.plot.object.BlockLoc; +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.PlotSettings; +import com.intellectualcrafters.plot.object.RunnableVal; import com.intellectualcrafters.plot.object.comment.PlotComment; import com.intellectualcrafters.plot.util.MainUtil; import com.intellectualcrafters.plot.util.StringMan; import com.intellectualcrafters.plot.util.TaskManager; -import java.sql.*; -import java.util.*; +import java.sql.Connection; +import java.sql.DatabaseMetaData; +import java.sql.PreparedStatement; +import java.sql.ResultSet; +import java.sql.SQLException; +import java.sql.Statement; +import java.sql.Timestamp; +import java.util.ArrayList; +import java.util.Collection; +import java.util.HashMap; +import java.util.HashSet; +import java.util.Iterator; +import java.util.LinkedHashMap; +import java.util.List; +import java.util.Map; import java.util.Map.Entry; +import java.util.Queue; +import java.util.Set; +import java.util.UUID; import java.util.concurrent.ConcurrentHashMap; import java.util.concurrent.ConcurrentLinkedQueue; import java.util.concurrent.atomic.AtomicInteger; @@ -1224,9 +1246,6 @@ public class SQLManager implements AbstractDB { @Override public void deleteSettings(final Plot plot) { - if (plot.settings == null) { - return; - } addPlotTask(plot, new UniqueStatement("delete_plot_settings") { @Override public void set(final PreparedStatement stmt) throws SQLException { @@ -1669,10 +1688,7 @@ public class SQLManager implements AbstractDB { } final Plot plot = plots.get(id); if (plot != null) { - if (plot.getSettings().ratings == null) { - plot.getSettings().ratings = new HashMap<>(); - } - plot.getSettings().ratings.put(user, r.getInt("rating")); + plot.getSettings().getRatings().put(user, r.getInt("rating")); } else if (Settings.AUTO_PURGE) { toDelete.add(id); } else { 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 cb6186564..0f2e85a4f 100644 --- a/Core/src/main/java/com/intellectualcrafters/plot/generator/SquarePlotManager.java +++ b/Core/src/main/java/com/intellectualcrafters/plot/generator/SquarePlotManager.java @@ -115,9 +115,7 @@ public abstract class SquarePlotManager extends GridPlotManager { end = pathWidthLower + dpw.PLOT_WIDTH; } int dx; - int dz; int rx; - int rz; if (x < 0) { dx = (x / size); rx = size + (x % size); @@ -125,6 +123,8 @@ public abstract class SquarePlotManager extends GridPlotManager { dx = (x / size) + 1; rx = (x % size); } + int dz; + int rz; if (z < 0) { dz = (z / size); rz = size + (z % size); 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 2b6dbe829..3e347c529 100644 --- a/Core/src/main/java/com/intellectualcrafters/plot/object/Plot.java +++ b/Core/src/main/java/com/intellectualcrafters/plot/object/Plot.java @@ -29,18 +29,34 @@ import com.intellectualcrafters.plot.config.Settings; import com.intellectualcrafters.plot.database.DBFunc; import com.intellectualcrafters.plot.flag.Flag; import com.intellectualcrafters.plot.flag.FlagManager; -import com.intellectualcrafters.plot.util.*; +import com.intellectualcrafters.plot.util.BO3Handler; +import com.intellectualcrafters.plot.util.ChunkManager; +import com.intellectualcrafters.plot.util.EventUtil; +import com.intellectualcrafters.plot.util.MainUtil; +import com.intellectualcrafters.plot.util.Permissions; +import com.intellectualcrafters.plot.util.SchematicHandler; +import com.intellectualcrafters.plot.util.SetQueue; +import com.intellectualcrafters.plot.util.TaskManager; +import com.intellectualcrafters.plot.util.UUIDHandler; +import com.intellectualcrafters.plot.util.WorldUtil; import com.plotsquared.listener.PlotListener; -import java.awt.*; +import java.awt.Rectangle; import java.awt.geom.Area; import java.awt.geom.PathIterator; import java.io.File; import java.net.URL; import java.nio.charset.StandardCharsets; -import java.util.*; +import java.util.ArrayDeque; +import java.util.ArrayList; +import java.util.Collection; +import java.util.Collections; +import java.util.HashMap; +import java.util.HashSet; import java.util.List; import java.util.Map.Entry; +import java.util.Set; +import java.util.UUID; import java.util.concurrent.ConcurrentHashMap; import java.util.concurrent.atomic.AtomicInteger; @@ -61,11 +77,9 @@ public class Plot { private static HashSet connected_cache; private static HashSet regions_cache; /** - * plot ID - * Direct access is Deprecated: use getId() + * The {@link PlotId} */ - @Deprecated - public final PlotId id; + private final PlotId id; /** * plot owner * (Merged plots can have multiple owners) @@ -73,39 +87,6 @@ public class Plot { */ @Deprecated public UUID owner; - /** - * Plot creation timestamp (not accurate if the plot was created before this was implemented)
- * - Milliseconds since the epoch
- * Direct access is Deprecated: use {@link #getTimestamp() getTimestamp} - */ - @Deprecated - public long timestamp; - /** - * List of trusted (with plot permissions) - * Direct access is Deprecated: use getTrusted() - */ - @Deprecated - public HashSet trusted; - /** - * List of members users (with plot permissions) - * Direct access is Deprecated: use getMembers() - */ - @Deprecated - public HashSet members; - /** - * List of denied players - * Direct access is Deprecated: use getDenied() - */ - @Deprecated - public HashSet denied; - /** - * External settings class
- * - Please favor the methods over direct access to this class
- * - The methods are more likely to be left unchanged from version changes
- * Direct access is Deprecated: use getSettings() - */ - @Deprecated - public PlotSettings settings; /** * Has the plot changed since the last save cycle? */ @@ -119,8 +100,30 @@ public class Plot { @Deprecated public int temp; /** - * plot world - * Direct access is Deprecated: use getWorld() + * Plot creation timestamp (not accurate if the plot was created before this was implemented)
+ * - Milliseconds since the epoch
+ */ + private long timestamp; + /** + * List of trusted (with plot permissions) + */ + private HashSet trusted; + /** + * List of members users (with plot permissions) + */ + private HashSet members; + /** + * List of denied players + */ + private HashSet denied; + /** + * External settings class
+ * - Please favor the methods over direct access to this class
+ * - The methods are more likely to be left unchanged from version changes
+ */ + private PlotSettings settings; + /** + * The {@link PlotArea} */ private PlotArea area; /** @@ -486,10 +489,7 @@ public class Plot { * @return */ public boolean isBasePlot() { - if ((this.settings == null) || !this.isMerged()) { - return true; - } - return this.equals(this.getBasePlot(false)); + return !this.isMerged() || this.equals(this.getBasePlot(false)); } /** @@ -530,10 +530,7 @@ public class Plot { * @return */ public boolean isMerged() { - if (this.settings == null) { - return false; - } - return this.settings.getMerged(0) || this.settings.getMerged(2) || this.settings.getMerged(1) || this.settings.getMerged(3); + return getSettings().getMerged(0) || getSettings().getMerged(2) || getSettings().getMerged(1) || getSettings().getMerged(3); } /** @@ -567,40 +564,41 @@ public class Plot { * @return true if merged in that direction */ public boolean getMerged(final int direction) { - if (this.settings == null) { - return false; - } - switch (direction) { - case 0: - case 1: - case 2: - case 3: - return this.settings.getMerged(direction); - case 7: - int i = direction - 4; - int i2 = 0; - if (this.settings.getMerged(i2)) { - if (this.settings.getMerged(i)) { - if (this.area.getPlotAbs(this.id.getRelative(i)).getMerged(i2)) { - if (this.area.getPlotAbs(this.id.getRelative(i2)).getMerged(i)) { - return true; + if (isMerged()) { + switch (direction) { + case 0: + case 1: + case 2: + case 3: + return this.getSettings().getMerged(direction); + case 7: + int i = direction - 4; + int i2 = 0; + if (this.getSettings().getMerged(i2)) { + if (this.getSettings().getMerged(i)) { + if (this.area.getPlotAbs(this.id.getRelative(i)).getMerged(i2)) { + if (this.area.getPlotAbs(this.id.getRelative(i2)).getMerged(i)) { + return true; + } } } } - } - return false; - case 4: - case 5: - case 6: - i = direction - 4; - i2 = direction - 3; - return this.settings.getMerged(i2) - && this.settings.getMerged(i) - && this.area.getPlotAbs(this.id.getRelative(i)).getMerged(i2) - && this.area.getPlotAbs(this.id.getRelative(i2)).getMerged(i); - + return false; + case 4: + case 5: + case 6: + i = direction - 4; + i2 = direction - 3; + return this.getSettings().getMerged(i2) + && this.getSettings().getMerged(i) + && this.area.getPlotAbs(this.id.getRelative(i)).getMerged(i2) + && this.area.getPlotAbs(this.id.getRelative(i2)).getMerged(i); + + } + return false; + } else { + return false; } - return false; } /** @@ -1132,16 +1130,12 @@ public class Plot { */ public void setHome(final BlockLoc loc) { final BlockLoc pos = this.getSettings().getPosition(); - if ((((pos == null) || pos.equals(new BlockLoc(0, 0, 0))) && (loc == null)) || ((pos != null) && pos.equals(loc))) { + if (pos.equals(new BlockLoc(0, 0, 0)) && loc == null || pos.equals(loc)) { return; } final Plot plot = this.getBasePlot(false); plot.getSettings().setPosition(loc); - if (plot.getSettings().getPosition() == null) { - DBFunc.setPosition(plot, ""); - } else { - DBFunc.setPosition(plot, this.getSettings().getPosition().toString()); - } + DBFunc.setPosition(plot, this.getSettings().getPosition().toString()); } /** @@ -1240,11 +1234,7 @@ public class Plot { public boolean hasRatings() { Plot base = this.getBasePlot(false); - if (base.settings != null && base.settings.ratings != null) { - return true; - } else { - return false; - } + return base.settings != null && base.settings.ratings != null; } /** @@ -1368,7 +1358,7 @@ public class Plot { this.getDenied().clear(); this.settings = new PlotSettings(); if (this.area.addPlot(this)) { - DBFunc.createPlotAndSettings(Plot.this, new Runnable() { + DBFunc.createPlotAndSettings(this, new Runnable() { @Override public void run() { final PlotArea plotworld = Plot.this.area; @@ -1910,10 +1900,7 @@ public class Plot { * @return boolean [ north, east, south, west ] */ public boolean[] getMerged() { - if (this.settings == null) { - return new boolean[] { false, false, false, false }; - } - return this.settings.getMerged(); + return this.getSettings().getMerged(); } /** @@ -1948,10 +1935,7 @@ public class Plot { * @return */ public BlockLoc getPosition() { - if (this.settings == null) { - return new BlockLoc(0, 0, 0); - } - return this.settings.getPosition(); + return this.getSettings().getPosition(); } /** @@ -2256,10 +2240,10 @@ public class Plot { PS.debug("Fixing invalid merge: " + this); if (tmp.isOwnerAbs(owner)) { tmp.getSettings().setMerged(2, true); - DBFunc.setMerged(tmp, tmp.settings.getMerged()); + DBFunc.setMerged(tmp, tmp.getSettings().getMerged()); } else { this.getSettings().setMerged(0, false); - DBFunc.setMerged(this, this.settings.getMerged()); + DBFunc.setMerged(this, this.getSettings().getMerged()); } } queuecache.add(tmp); @@ -2272,10 +2256,10 @@ public class Plot { PS.debug("Fixing invalid merge: " + this); if (tmp.isOwnerAbs(owner)) { tmp.getSettings().setMerged(3, true); - DBFunc.setMerged(tmp, tmp.settings.getMerged()); + DBFunc.setMerged(tmp, tmp.getSettings().getMerged()); } else { this.getSettings().setMerged(1, false); - DBFunc.setMerged(this, this.settings.getMerged()); + DBFunc.setMerged(this, this.getSettings().getMerged()); } } queuecache.add(tmp); @@ -2288,10 +2272,10 @@ public class Plot { PS.debug("Fixing invalid merge: " + this); if (tmp.isOwnerAbs(owner)) { tmp.getSettings().setMerged(0, true); - DBFunc.setMerged(tmp, tmp.settings.getMerged()); + DBFunc.setMerged(tmp, tmp.getSettings().getMerged()); } else { this.getSettings().setMerged(2, false); - DBFunc.setMerged(this, this.settings.getMerged()); + DBFunc.setMerged(this, this.getSettings().getMerged()); } } queuecache.add(tmp); @@ -2304,10 +2288,10 @@ public class Plot { PS.debug("Fixing invalid merge: " + this); if (tmp.isOwnerAbs(owner)) { tmp.getSettings().setMerged(1, true); - DBFunc.setMerged(tmp, tmp.settings.getMerged()); + DBFunc.setMerged(tmp, tmp.getSettings().getMerged()); } else { this.getSettings().setMerged(3, false); - DBFunc.setMerged(this, this.settings.getMerged()); + DBFunc.setMerged(this, this.getSettings().getMerged()); } } queuecache.add(tmp); @@ -2324,6 +2308,9 @@ public class Plot { connected_cache.add(current); queuecache.remove(current); merged = current.getMerged(); + for (int i = 0; i < 5; i++) { + + } if (merged[0]) { tmp = current.area.getPlotAbs(current.id.getRelative(0)); if ((tmp != null) && !queuecache.contains(tmp) && !connected_cache.contains(tmp)) { @@ -2794,7 +2781,7 @@ public class Plot { for (final Plot plot : plots) { final Plot other = plot.getRelative(offset.x, offset.y); other.create(other.owner, false); - if ((plot.getFlags() != null) && !plot.getFlags().isEmpty()) { + if (!plot.getFlags().isEmpty()) { other.getSettings().flags = plot.getFlags(); DBFunc.setFlags(other, plot.getFlags().values()); } diff --git a/Core/src/main/java/com/intellectualcrafters/plot/util/StringMan.java b/Core/src/main/java/com/intellectualcrafters/plot/util/StringMan.java index eacb088b3..d845617a8 100644 --- a/Core/src/main/java/com/intellectualcrafters/plot/util/StringMan.java +++ b/Core/src/main/java/com/intellectualcrafters/plot/util/StringMan.java @@ -44,7 +44,7 @@ public class StringMan { if (obj == null) { return "null"; } - if (obj.getClass() == String.class) { + if (obj instanceof String) { return (String) obj; } if (obj.getClass().isArray()) { From 8739f3ef78a0fde8d1b43944985e1be1ee5ef659 Mon Sep 17 00:00:00 2001 From: Jesse Boyd Date: Mon, 14 Mar 2016 12:34:58 +1100 Subject: [PATCH 2/6] Horses aren't hostile. --- .../bukkit/listeners/PlayerEvents.java | 30 +++++++------------ 1 file changed, 11 insertions(+), 19 deletions(-) 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 e101706fc..f77a22a35 100644 --- a/Bukkit/src/main/java/com/plotsquared/bukkit/listeners/PlayerEvents.java +++ b/Bukkit/src/main/java/com/plotsquared/bukkit/listeners/PlayerEvents.java @@ -27,6 +27,16 @@ import com.plotsquared.bukkit.object.BukkitLazyBlock; import com.plotsquared.bukkit.object.BukkitPlayer; import com.plotsquared.bukkit.util.BukkitUtil; import com.plotsquared.listener.PlayerBlockEventType; +import java.util.ArrayList; +import java.util.Arrays; +import java.util.HashSet; +import java.util.Iterator; +import java.util.List; +import java.util.Map.Entry; +import java.util.Objects; +import java.util.Set; +import java.util.UUID; +import java.util.regex.Pattern; import org.bukkit.Bukkit; import org.bukkit.ChatColor; import org.bukkit.Material; @@ -42,13 +52,11 @@ import org.bukkit.entity.EnderDragon; import org.bukkit.entity.Entity; import org.bukkit.entity.EntityType; import org.bukkit.entity.Hanging; -import org.bukkit.entity.Horse; import org.bukkit.entity.HumanEntity; import org.bukkit.entity.LivingEntity; import org.bukkit.entity.Monster; import org.bukkit.entity.Player; import org.bukkit.entity.Projectile; -import org.bukkit.entity.Skeleton; import org.bukkit.entity.TNTPrimed; import org.bukkit.entity.Tameable; import org.bukkit.entity.ThrownPotion; @@ -107,17 +115,6 @@ import org.bukkit.projectiles.BlockProjectileSource; import org.bukkit.projectiles.ProjectileSource; import org.bukkit.util.Vector; -import java.util.ArrayList; -import java.util.Arrays; -import java.util.HashSet; -import java.util.Iterator; -import java.util.List; -import java.util.Map.Entry; -import java.util.Objects; -import java.util.Set; -import java.util.UUID; -import java.util.regex.Pattern; - /** * Player Events involving plots * @@ -1374,6 +1371,7 @@ public class PlayerEvents extends com.plotsquared.listener.PlotListener implemen case COW: case SNOWMAN: case BAT: + case HORSE: // animal return checkEntity(plot, "entity-cap", "mob-cap", "animal-cap"); case BLAZE: @@ -1397,12 +1395,6 @@ public class PlayerEvents extends com.plotsquared.listener.PlotListener implemen case SHULKER: // monster return checkEntity(plot, "entity-cap", "mob-cap", "hostile-cap"); - case HORSE: - Horse horse = ((Horse) entity); - if (horse.getVariant().equals(Horse.Variant.SKELETON_HORSE) && entity.getPassenger() instanceof Skeleton) { - return checkEntity(plot, "entity-cap", "mob-cap", "hostile-cap"); - } - return checkEntity(plot, "entity-cap", "mob-cap", "animal-cap"); default: if (entity instanceof LivingEntity) { if (entity instanceof Animals) { From ae885eafcaac8368ec1faf8246794e641cc7aa67 Mon Sep 17 00:00:00 2001 From: Matt Date: Sun, 13 Mar 2016 22:44:59 -0400 Subject: [PATCH 3/6] Various changes and Merge Economy Fix --- .../plotsquared/bukkit/util/BukkitUtil.java | 21 +++++++++++++++---- .../plot/commands/Auto.java | 12 +++-------- .../plot/commands/Claim.java | 12 +++-------- .../plot/commands/Merge.java | 5 ++--- .../plot/util/BO3Handler.java | 8 +++---- .../plotsquared/general/commands/Command.java | 3 --- 6 files changed, 29 insertions(+), 32 deletions(-) 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 84c2e4b76..4a7c4b2be 100644 --- a/Bukkit/src/main/java/com/plotsquared/bukkit/util/BukkitUtil.java +++ b/Bukkit/src/main/java/com/plotsquared/bukkit/util/BukkitUtil.java @@ -5,9 +5,17 @@ import com.intellectualcrafters.plot.object.PlotBlock; import com.intellectualcrafters.plot.object.PlotPlayer; import com.intellectualcrafters.plot.object.RegionWrapper; import com.intellectualcrafters.plot.object.schematic.PlotItem; -import com.intellectualcrafters.plot.util.*; +import com.intellectualcrafters.plot.util.MathMan; +import com.intellectualcrafters.plot.util.StringComparison; +import com.intellectualcrafters.plot.util.StringMan; +import com.intellectualcrafters.plot.util.TaskManager; +import com.intellectualcrafters.plot.util.UUIDHandler; +import com.intellectualcrafters.plot.util.WorldUtil; import com.plotsquared.bukkit.object.BukkitPlayer; -import org.bukkit.*; +import org.bukkit.Bukkit; +import org.bukkit.Material; +import org.bukkit.OfflinePlayer; +import org.bukkit.World; import org.bukkit.block.Biome; import org.bukkit.block.Block; import org.bukkit.block.BlockState; @@ -17,7 +25,12 @@ import org.bukkit.entity.Player; import org.bukkit.inventory.Inventory; import org.bukkit.inventory.InventoryHolder; import org.bukkit.inventory.ItemStack; -import org.bukkit.material.*; +import org.bukkit.material.MaterialData; +import org.bukkit.material.Sandstone; +import org.bukkit.material.Step; +import org.bukkit.material.Tree; +import org.bukkit.material.WoodenStep; +import org.bukkit.material.Wool; import java.util.Arrays; import java.util.List; @@ -282,7 +295,7 @@ public class BukkitUtil extends WorldUtil { final World world = getWorld(loc.getWorld()); final Block block = world.getBlockAt(loc.getX(), loc.getY(), loc.getZ()); if (block == null) { - return new PlotBlock((short) 0, (byte) 0); + return PlotBlock.EVERYTHING; } return new PlotBlock((short) block.getTypeId(), block.getData()); } 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 6b183f904..7d2bef836 100644 --- a/Core/src/main/java/com/intellectualcrafters/plot/commands/Auto.java +++ b/Core/src/main/java/com/intellectualcrafters/plot/commands/Auto.java @@ -32,14 +32,8 @@ import com.intellectualcrafters.plot.util.MainUtil; import com.intellectualcrafters.plot.util.Permissions; import com.plotsquared.general.commands.CommandDeclaration; -@CommandDeclaration( -command = "auto", -permission = "plots.auto", -category = CommandCategory.CLAIMING, -requiredType = RequiredType.NONE, -description = "Claim the nearest plot", -aliases = { "a" }, -usage = "/plot auto [length,width]") +@CommandDeclaration(command = "auto", permission = "plots.auto", category = CommandCategory.CLAIMING, requiredType = RequiredType.NONE, + description = "Claim the nearest plot", aliases = "a", usage = "/plot auto [length,width]") public class Auto extends SubCommand { public static PlotId getNextPlotId(final PlotId id, final int step) { @@ -149,7 +143,7 @@ public class Auto extends SubCommand { sendMessage(plr, C.REMOVED_BALANCE, cost + ""); } } - if (schematic != null && !schematic.equals("")) { + if (schematic != null && !schematic.isEmpty()) { if (!plotarea.SCHEMATICS.contains(schematic.toLowerCase())) { sendMessage(plr, C.SCHEMATIC_INVALID, "non-existent: " + schematic); return true; diff --git a/Core/src/main/java/com/intellectualcrafters/plot/commands/Claim.java b/Core/src/main/java/com/intellectualcrafters/plot/commands/Claim.java index 0dff579b2..835789061 100644 --- a/Core/src/main/java/com/intellectualcrafters/plot/commands/Claim.java +++ b/Core/src/main/java/com/intellectualcrafters/plot/commands/Claim.java @@ -31,14 +31,8 @@ import com.intellectualcrafters.plot.util.EconHandler; import com.intellectualcrafters.plot.util.Permissions; import com.plotsquared.general.commands.CommandDeclaration; -@CommandDeclaration( -command = "claim", -aliases = { "c" }, -description = "Claim the current plot you're standing on", -category = CommandCategory.CLAIMING, -requiredType = RequiredType.NONE, -permission = "plots.claim", -usage = "/plot claim") +@CommandDeclaration(command = "claim", aliases = "c", description = "Claim the current plot you're standing on", category = CommandCategory.CLAIMING, + requiredType = RequiredType.NONE, permission = "plots.claim", usage = "/plot claim") public class Claim extends SubCommand { @Override public boolean onCommand(final PlotPlayer plr, final String... args) { @@ -87,7 +81,7 @@ public class Claim extends SubCommand { } sendMessage(plr, C.REMOVED_GRANTED_PLOT, "1", "" + (grants - 1)); } - if (!schematic.equals("")) { + if (!schematic.isEmpty()) { if (world.SCHEMATIC_CLAIM_SPECIFY) { if (!world.SCHEMATICS.contains(schematic.toLowerCase())) { return sendMessage(plr, C.SCHEMATIC_INVALID, "non-existent: " + schematic); 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 381fcce4c..4d899277d 100644 --- a/Core/src/main/java/com/intellectualcrafters/plot/commands/Merge.java +++ b/Core/src/main/java/com/intellectualcrafters/plot/commands/Merge.java @@ -89,8 +89,7 @@ public class Merge extends SubCommand { } final PlotArea plotworld = plot.getArea(); final double price = plotworld.PRICES.get("merge"); - if (EconHandler.manager != null && plotworld.USE_ECONOMY && price > 0d - && EconHandler.manager.getMoney(plr) < price) { + if (EconHandler.manager != null && plotworld.USE_ECONOMY && price > 0d && EconHandler.manager.getMoney(plr) < price) { sendMessage(plr, C.CANNOT_AFFORD_MERGE, price + ""); return false; } @@ -123,7 +122,7 @@ public class Merge extends SubCommand { terrain = "true".equalsIgnoreCase(args[1]); } if (plot.autoMerge(-1, maxSize, uuid, terrain)) { - if (EconHandler.manager != null && price > 0d) { + if (EconHandler.manager != null && plotworld.USE_ECONOMY && price > 0d) { EconHandler.manager.withdrawMoney(plr, price); sendMessage(plr, C.REMOVED_BALANCE, price + ""); } 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 aa211fe51..2cefac90d 100644 --- a/Core/src/main/java/com/intellectualcrafters/plot/util/BO3Handler.java +++ b/Core/src/main/java/com/intellectualcrafters/plot/util/BO3Handler.java @@ -95,7 +95,7 @@ public class BO3Handler { BO3 bo3 = map.get(loc); for (int y = 1; y < height; y++) { final PlotBlock block = WorldUtil.IMP.getBlock(new Location(plot.getArea().worldname, x, y, z)); - if ((block != null) && !contains(cpw.MAIN_BLOCK, block)) { + if (!contains(cpw.MAIN_BLOCK, block)) { if (bo3 == null) { bo3 = new BO3(alias, loc); map.put(loc, bo3); @@ -105,7 +105,7 @@ public class BO3Handler { } } final PlotBlock floor = WorldUtil.IMP.getBlock(new Location(plot.getArea().worldname, x, height, z)); - if ((floor != null) && !contains(cpw.TOP_BLOCK, floor)) { + if (!contains(cpw.TOP_BLOCK, floor)) { if (bo3 == null) { bo3 = new BO3(alias, loc); map.put(loc, bo3); @@ -115,7 +115,7 @@ public class BO3Handler { } for (int y = height + 1; y < 256; y++) { final PlotBlock block = WorldUtil.IMP.getBlock(new Location(plot.getArea().worldname, x, y, z)); - if ((block != null) && (block.id != 0)) { + if (block.id != 0) { if (bo3 == null) { bo3 = new BO3(alias, loc); map.put(loc, bo3); @@ -205,4 +205,4 @@ public class BO3Handler { } return base; } -} \ No newline at end of file +} 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 771ac8469..d81e1d5a6 100644 --- a/Core/src/main/java/com/plotsquared/general/commands/Command.java +++ b/Core/src/main/java/com/plotsquared/general/commands/Command.java @@ -155,9 +155,6 @@ public abstract class Command extends CommandManager { if (this == obj) { return true; } - if (obj == null) { - return false; - } if (getClass() != obj.getClass()) { return false; } From bee6f83e7976ff917148ea26f480c5b3ac6c528a Mon Sep 17 00:00:00 2001 From: Matt Date: Mon, 14 Mar 2016 02:18:04 -0400 Subject: [PATCH 4/6] Various changes --- .../com/plotsquared/bukkit/BukkitMain.java | 6 +- .../plotsquared/bukkit/chat/MessagePart.java | 6 +- .../database/plotme/APlotMeConnector.java | 40 +++-------- .../bukkit/generator/BukkitPlotGenerator.java | 26 +++---- .../bukkit/listeners/PlayerEvents.java | 24 +++---- .../bukkit/object/entity/EntityWrapper.java | 13 +--- .../intellectualcrafters/json/JSONArray.java | 8 +-- .../intellectualcrafters/json/JSONObject.java | 2 +- .../com/intellectualcrafters/json/XML.java | 65 ++++++++---------- .../plot/commands/Area.java | 36 ++++++---- .../plot/commands/Cluster.java | 18 ++--- .../plot/commands/Condense.java | 4 +- .../plot/commands/Rate.java | 22 +++--- .../plot/commands/list.java | 32 +++++---- .../intellectualcrafters/plot/config/C.java | 18 +++-- .../plot/database/MySQL.java | 14 ++-- .../plot/database/SQLManager.java | 3 +- .../plot/database/SQLite.java | 17 +++-- .../plot/generator/HybridPlotWorld.java | 15 ++--- .../plot/object/Plot.java | 2 +- .../plot/object/PlotCluster.java | 67 +++++++++---------- .../plot/util/ExpireManager.java | 14 ++-- .../plot/util/SchematicHandler.java | 49 +++++++++++--- .../plot/util/StringMan.java | 2 +- .../plot/util/helpmenu/HelpObject.java | 10 ++- 25 files changed, 250 insertions(+), 263 deletions(-) diff --git a/Bukkit/src/main/java/com/plotsquared/bukkit/BukkitMain.java b/Bukkit/src/main/java/com/plotsquared/bukkit/BukkitMain.java index ca76ee0fa..6fce37ca5 100644 --- a/Bukkit/src/main/java/com/plotsquared/bukkit/BukkitMain.java +++ b/Bukkit/src/main/java/com/plotsquared/bukkit/BukkitMain.java @@ -623,10 +623,8 @@ public class BukkitMain extends JavaPlugin implements Listener, IPlotMain { PS.get().loadWorld(worldname, (BukkitPlotGenerator) gen); } else if (gen != null) { PS.get().loadWorld(worldname, new BukkitPlotGenerator(worldname, gen)); - } else { - if (PS.get().config.contains("worlds." + worldname)) { - PS.get().loadWorld(worldname, null); - } + } else if (PS.get().config.contains("worlds." + worldname)) { + PS.get().loadWorld(worldname, null); } } diff --git a/Bukkit/src/main/java/com/plotsquared/bukkit/chat/MessagePart.java b/Bukkit/src/main/java/com/plotsquared/bukkit/chat/MessagePart.java index 3e1ba2006..ccbe2e433 100644 --- a/Bukkit/src/main/java/com/plotsquared/bukkit/chat/MessagePart.java +++ b/Bukkit/src/main/java/com/plotsquared/bukkit/chat/MessagePart.java @@ -51,12 +51,12 @@ final class MessagePart implements JsonRepresentedObject, ConfigurationSerializa } ChatColor color = ChatColor.WHITE; - ArrayList styles = new ArrayList(); + ArrayList styles = new ArrayList<>(); String clickActionName = null, clickActionData = null, hoverActionName = null; JsonRepresentedObject hoverActionData = null; TextualComponent text = null; String insertionData = null; - ArrayList translationReplacements = new ArrayList(); + ArrayList translationReplacements = new ArrayList<>(); MessagePart(final TextualComponent text) { this.text = text; @@ -134,7 +134,7 @@ final class MessagePart implements JsonRepresentedObject, ConfigurationSerializa @Override public Map serialize() { - final HashMap map = new HashMap(); + final HashMap map = new HashMap<>(); map.put("text", text); map.put("styles", styles); map.put("color", color.getChar()); diff --git a/Bukkit/src/main/java/com/plotsquared/bukkit/database/plotme/APlotMeConnector.java b/Bukkit/src/main/java/com/plotsquared/bukkit/database/plotme/APlotMeConnector.java index d78d5a6c3..559dbb202 100644 --- a/Bukkit/src/main/java/com/plotsquared/bukkit/database/plotme/APlotMeConnector.java +++ b/Bukkit/src/main/java/com/plotsquared/bukkit/database/plotme/APlotMeConnector.java @@ -1,18 +1,17 @@ package com.plotsquared.bukkit.database.plotme; -import java.sql.Connection; -import java.sql.SQLException; -import java.util.Collections; -import java.util.HashMap; - -import org.bukkit.Bukkit; -import org.bukkit.World; - import com.intellectualcrafters.configuration.file.FileConfiguration; import com.intellectualcrafters.plot.PS; import com.intellectualcrafters.plot.object.Location; import com.intellectualcrafters.plot.object.Plot; import com.intellectualcrafters.plot.object.PlotId; +import org.bukkit.Bukkit; +import org.bukkit.World; + +import java.sql.Connection; +import java.sql.SQLException; +import java.util.Collections; +import java.util.HashMap; public abstract class APlotMeConnector { public abstract Connection getPlotMeConnection(final String plugin, final FileConfiguration plotConfig, final String dataFolder); @@ -69,35 +68,14 @@ public abstract class APlotMeConnector { public void setMerged(final HashMap> merges, final String world, final PlotId id, final int direction) { final HashMap plots = merges.get(world); - PlotId id2; - switch (direction) { - case 0: { - id2 = new PlotId(id.x, id.y); - break; - } - case 1: { - id2 = new PlotId(id.x, id.y); - break; - } - case 2: { - id2 = new PlotId(id.x, id.y); - break; - } - case 3: { - id2 = new PlotId(id.x, id.y); - break; - } - default: { - return; - } - } + PlotId id2 = new PlotId(id.x, id.y); boolean[] merge1; - boolean[] merge2; if (plots.containsKey(id)) { merge1 = plots.get(id); } else { merge1 = new boolean[] { false, false, false, false }; } + boolean[] merge2; if (plots.containsKey(id2)) { merge2 = plots.get(id2); } else { 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 ed425373f..0ff0f4720 100644 --- a/Bukkit/src/main/java/com/plotsquared/bukkit/generator/BukkitPlotGenerator.java +++ b/Bukkit/src/main/java/com/plotsquared/bukkit/generator/BukkitPlotGenerator.java @@ -24,7 +24,11 @@ import com.intellectualcrafters.plot.PS; import com.intellectualcrafters.plot.generator.GeneratorWrapper; import com.intellectualcrafters.plot.generator.HybridGen; import com.intellectualcrafters.plot.generator.IndependentPlotGenerator; -import com.intellectualcrafters.plot.object.*; +import com.intellectualcrafters.plot.object.PlotArea; +import com.intellectualcrafters.plot.object.PlotId; +import com.intellectualcrafters.plot.object.PlotManager; +import com.intellectualcrafters.plot.object.PseudoRandom; +import com.intellectualcrafters.plot.object.SetupObject; import com.intellectualcrafters.plot.util.ChunkManager; import com.intellectualcrafters.plot.util.MainUtil; import com.intellectualcrafters.plot.util.PlotChunk; @@ -48,9 +52,9 @@ public class BukkitPlotGenerator extends ChunkGenerator implements GeneratorWrap private final PseudoRandom random = new PseudoRandom(); private final IndependentPlotGenerator plotGenerator; private final List populators = new ArrayList<>(); + private final ChunkGenerator platformGenerator; + private final boolean full; private boolean loaded = false; - private ChunkGenerator platformGenerator; - private boolean full; public BukkitPlotGenerator(IndependentPlotGenerator generator) { this.plotGenerator = generator; @@ -58,11 +62,6 @@ public class BukkitPlotGenerator extends ChunkGenerator implements GeneratorWrap populators.add(new BlockPopulator() { @Override public void populate(World world, Random r, Chunk c) { - if (!(chunkSetter instanceof GenChunk)) { - PS.debug("Current PlotChunk is not relevant to population?"); - PS.stacktrace(); - return; - } GenChunk result = (GenChunk) chunkSetter; if (result.result_data != null) { for (int i = 0; i < result.result_data.length; i++) { @@ -90,7 +89,7 @@ public class BukkitPlotGenerator extends ChunkGenerator implements GeneratorWrap throw new IllegalArgumentException("ChunkGenerator: " + cg.getClass().getName() + " is already a BukkitPlotGenerator!"); } this.full = false; - PS.get().debug("BukkitPlotGenerator does not fully support: " + cg); + PS.debug("BukkitPlotGenerator does not fully support: " + cg); platformGenerator = cg; plotGenerator = new IndependentPlotGenerator() { @Override @@ -229,11 +228,6 @@ public class BukkitPlotGenerator extends ChunkGenerator implements GeneratorWrap @Override public ChunkData generateChunkData(World world, Random random, int cx, int cz, BiomeGrid grid) { - if (!(chunkSetter instanceof GenChunk)) { - PS.debug("Current PlotChunk is not relevant to generation?"); - PS.stacktrace(); - return null; - } GenChunk result = (GenChunk) chunkSetter; // Set the chunk location result.setChunkWrapper(SetQueue.IMP.new ChunkWrapper(world.getName(), cx, cz)); @@ -278,10 +272,6 @@ public class BukkitPlotGenerator extends ChunkGenerator implements GeneratorWrap @Override public short[][] generateExtBlockSections(final World world, final Random r, final int cx, final int cz, final BiomeGrid grid) { - if (!(chunkSetter instanceof GenChunk)) { - PS.stacktrace(); - return new short[16][]; - } GenChunk result = (GenChunk) chunkSetter; // Set the chunk location result.setChunkWrapper(SetQueue.IMP.new ChunkWrapper(world.getName(), cx, cz)); 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 f77a22a35..539504f94 100644 --- a/Bukkit/src/main/java/com/plotsquared/bukkit/listeners/PlayerEvents.java +++ b/Bukkit/src/main/java/com/plotsquared/bukkit/listeners/PlayerEvents.java @@ -27,16 +27,6 @@ import com.plotsquared.bukkit.object.BukkitLazyBlock; import com.plotsquared.bukkit.object.BukkitPlayer; import com.plotsquared.bukkit.util.BukkitUtil; import com.plotsquared.listener.PlayerBlockEventType; -import java.util.ArrayList; -import java.util.Arrays; -import java.util.HashSet; -import java.util.Iterator; -import java.util.List; -import java.util.Map.Entry; -import java.util.Objects; -import java.util.Set; -import java.util.UUID; -import java.util.regex.Pattern; import org.bukkit.Bukkit; import org.bukkit.ChatColor; import org.bukkit.Material; @@ -115,11 +105,21 @@ import org.bukkit.projectiles.BlockProjectileSource; import org.bukkit.projectiles.ProjectileSource; import org.bukkit.util.Vector; +import java.util.ArrayList; +import java.util.Arrays; +import java.util.HashSet; +import java.util.Iterator; +import java.util.List; +import java.util.Map.Entry; +import java.util.Objects; +import java.util.Set; +import java.util.UUID; +import java.util.regex.Pattern; + /** * Player Events involving plots * */ -@SuppressWarnings({ "deprecation", "unchecked" }) public class PlayerEvents extends com.plotsquared.listener.PlotListener implements Listener { private boolean pistonBlocks = true; @@ -353,11 +353,11 @@ public class PlayerEvents extends com.plotsquared.listener.PlotListener implemen if (c.equals(cmdLabel.getName())) { break; } - PluginCommand p; final String label = cmdLabel.getName().replaceFirst("/", ""); if (aliases.contains(label)) { continue; } + PluginCommand p; if ((p = Bukkit.getPluginCommand(label)) != null) { for (String a : p.getAliases()) { if (aliases.contains(a)) { 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 921f97d5e..a06e4adc9 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 @@ -34,6 +34,7 @@ import org.bukkit.util.Vector; public class EntityWrapper { + private final int hash; public EntityType type; public float yaw; public float pitch; @@ -54,8 +55,6 @@ public class EntityWrapper { private HorseStats horse; private ArmorStandStats stand; - private int hash; - @SuppressWarnings("deprecation") public EntityWrapper(final org.bukkit.entity.Entity entity, final short depth) { hash = entity.getEntityId(); @@ -153,10 +152,7 @@ public class EntityWrapper { } // END MISC // // INVENTORY HOLDER // - case MINECART_CHEST: { - storeInventory((InventoryHolder) entity); - return; - } + case MINECART_CHEST: case MINECART_HOPPER: { storeInventory((InventoryHolder) entity); return; @@ -508,10 +504,7 @@ public class EntityWrapper { } // END MISC // // INVENTORY HOLDER // - case MINECART_CHEST: { - restoreInventory((InventoryHolder) entity); - return entity; - } + case MINECART_CHEST: case MINECART_HOPPER: { restoreInventory((InventoryHolder) entity); return entity; diff --git a/Core/src/main/java/com/intellectualcrafters/json/JSONArray.java b/Core/src/main/java/com/intellectualcrafters/json/JSONArray.java index 103049a5f..989f83799 100644 --- a/Core/src/main/java/com/intellectualcrafters/json/JSONArray.java +++ b/Core/src/main/java/com/intellectualcrafters/json/JSONArray.java @@ -558,7 +558,7 @@ public class JSONArray { * @return this. */ public JSONArray put(final int value) { - this.put(new Integer(value)); + this.put(Integer.valueOf(value)); return this; } @@ -570,7 +570,7 @@ public class JSONArray { * @return this. */ public JSONArray put(final long value) { - this.put(new Long(value)); + this.put(Long.valueOf(value)); return this; } @@ -658,7 +658,7 @@ public class JSONArray { * @throws JSONException If the index is negative. */ public JSONArray put(final int index, final int value) throws JSONException { - this.put(index, new Integer(value)); + this.put(index, Integer.valueOf(value)); return this; } @@ -674,7 +674,7 @@ public class JSONArray { * @throws JSONException If the index is negative. */ public JSONArray put(final int index, final long value) throws JSONException { - this.put(index, new Long(value)); + this.put(index, Long.valueOf(value)); return this; } diff --git a/Core/src/main/java/com/intellectualcrafters/json/JSONObject.java b/Core/src/main/java/com/intellectualcrafters/json/JSONObject.java index d8b53c523..c090c1967 100644 --- a/Core/src/main/java/com/intellectualcrafters/json/JSONObject.java +++ b/Core/src/main/java/com/intellectualcrafters/json/JSONObject.java @@ -452,7 +452,7 @@ public class JSONObject { return d; } } else { - final Long myLong = new Long(string); + final Long myLong = Long.valueOf(string); if (string.equals(myLong.toString())) { if (myLong == myLong.intValue()) { return myLong.intValue(); diff --git a/Core/src/main/java/com/intellectualcrafters/json/XML.java b/Core/src/main/java/com/intellectualcrafters/json/XML.java index 2190b6311..be8e1986d 100644 --- a/Core/src/main/java/com/intellectualcrafters/json/XML.java +++ b/Core/src/main/java/com/intellectualcrafters/json/XML.java @@ -8,18 +8,19 @@ import java.util.Iterator; * @author JSON.org * @version 2014-05-03 */ -public class XML { - public static final Character AMP = '&'; - public static final Character APOS = '\''; - public static final Character BANG = '!'; - public static final Character EQ = '='; - public static final Character GT = '>'; - public static final Character LT = '<'; - public static final Character QUEST = '?'; - public static final Character QUOT = '"'; - public static final Character SLASH = '/'; - - public static String escape(final String string) { +class XML { + + static final Character AMP = '&'; + static final Character APOS = '\''; + static final Character BANG = '!'; + static final Character EQ = '='; + static final Character GT = '>'; + static final Character LT = '<'; + static final Character QUEST = '?'; + static final Character QUOT = '"'; + static final Character SLASH = '/'; + + static String escape(final String string) { final StringBuilder sb = new StringBuilder(string.length()); for (int i = 0, length = string.length(); i < length; i++) { final char c = string.charAt(i); @@ -53,14 +54,13 @@ public class XML { * * @throws JSONException */ - public static void noSpace(final String string) throws JSONException { - int i; + static void noSpace(final String string) throws JSONException { final int length = string.length(); if (length == 0) { throw new JSONException("Empty string."); } - for (i = 0; i < length; i += 1) { - if (Character.isWhitespace(string.charAt(i))) { + for (char c : string.toCharArray()) { + if (Character.isWhitespace(c)) { throw new JSONException("'" + string + "' contains a space character."); } } @@ -78,12 +78,6 @@ public class XML { * @throws JSONException */ private static boolean parse(final XMLTokener x, final JSONObject context, final String name) throws JSONException { - char c; - int i; - JSONObject jsonobject = null; - String string; - String tagName; - Object token; // Test for and skip past these forms: // // @@ -93,10 +87,11 @@ public class XML { // <> // <= // << - token = x.nextToken(); + Object token = x.nextToken(); // "); @@ -116,7 +111,7 @@ public class XML { } throw x.syntaxError("Expected 'CDATA['"); } - i = 1; + int i = 1; do { token = x.nextMeta(); if (token == null) { @@ -149,9 +144,9 @@ public class XML { throw x.syntaxError("Misshaped tag"); // Open tag < } else { - tagName = (String) token; + String tagName = (String) token; token = null; - jsonobject = new JSONObject(); + JSONObject jsonobject = new JSONObject(); for (;;) { if (token == null) { token = x.nextToken(); @@ -225,7 +220,7 @@ public class XML { * * @return A simple JSON value. */ - public static Object stringToValue(final String string) { + static Object stringToValue(final String string) { if ("true".equalsIgnoreCase(string)) { return Boolean.TRUE; } @@ -292,12 +287,8 @@ public class XML { final StringBuilder sb = new StringBuilder(); int i; JSONArray ja; - JSONObject jo; - String key; - Iterator keys; int length; String string; - Object value; if (object instanceof JSONObject) { // Emit if (tagName != null) { @@ -306,11 +297,11 @@ public class XML { sb.append('>'); } // Loop thru the keys. - jo = (JSONObject) object; - keys = jo.keys(); + JSONObject jo = (JSONObject) object; + Iterator keys = jo.keys(); while (keys.hasNext()) { - key = keys.next(); - value = jo.opt(key); + String key = keys.next(); + Object value = jo.opt(key); if (value == null) { value = ""; } @@ -378,7 +369,7 @@ public class XML { } return sb.toString(); } else { - string = (object == null) ? "null" : escape(object.toString()); + string = escape(object.toString()); return (tagName == null) ? "\"" + string + "\"" : (string.isEmpty()) ? "<" + tagName + "/>" : "<" + tagName + ">" + string + ""; } 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 852b43ebe..72baa1387 100644 --- a/Core/src/main/java/com/intellectualcrafters/plot/commands/Area.java +++ b/Core/src/main/java/com/intellectualcrafters/plot/commands/Area.java @@ -7,8 +7,24 @@ import com.intellectualcrafters.plot.config.Configuration; import com.intellectualcrafters.plot.generator.AugmentedUtils; import com.intellectualcrafters.plot.generator.HybridGen; import com.intellectualcrafters.plot.generator.HybridPlotWorld; -import com.intellectualcrafters.plot.object.*; -import com.intellectualcrafters.plot.util.*; +import com.intellectualcrafters.plot.object.ChunkLoc; +import com.intellectualcrafters.plot.object.Location; +import com.intellectualcrafters.plot.object.PlotArea; +import com.intellectualcrafters.plot.object.PlotId; +import com.intellectualcrafters.plot.object.PlotMessage; +import com.intellectualcrafters.plot.object.PlotPlayer; +import com.intellectualcrafters.plot.object.RegionWrapper; +import com.intellectualcrafters.plot.object.RunnableVal; +import com.intellectualcrafters.plot.object.RunnableVal3; +import com.intellectualcrafters.plot.object.SetupObject; +import com.intellectualcrafters.plot.util.ChunkManager; +import com.intellectualcrafters.plot.util.CmdConfirm; +import com.intellectualcrafters.plot.util.MainUtil; +import com.intellectualcrafters.plot.util.MathMan; +import com.intellectualcrafters.plot.util.Permissions; +import com.intellectualcrafters.plot.util.SetupUtils; +import com.intellectualcrafters.plot.util.StringMan; +import com.intellectualcrafters.plot.util.WorldUtil; import com.plotsquared.general.commands.CommandDeclaration; import java.io.IOException; @@ -16,14 +32,8 @@ import java.util.ArrayList; import java.util.Objects; import java.util.Set; -@CommandDeclaration( -command = "area", -permission = "plots.area", -category = CommandCategory.ADMINISTRATION, -requiredType = RequiredType.NONE, -description = "Create a new PlotArea", -aliases = { "world" }, -usage = "/plot area ") +@CommandDeclaration(command = "area", permission = "plots.area", category = CommandCategory.ADMINISTRATION, requiredType = RequiredType.NONE, + description = "Create a new PlotArea", aliases = "world", usage = "/plot area ") public class Area extends SubCommand { @Override @@ -48,7 +58,7 @@ public class Area extends SubCommand { case 2: { switch (args[1].toLowerCase()) { case "pos1": { // Set position 1 - HybridPlotWorld area = plr. getMeta("area_create_area"); + HybridPlotWorld area = plr.getMeta("area_create_area"); if (area == null) { C.COMMAND_SYNTAX.send(plr, "/plot area create [world[:id]] [=]..."); return false; @@ -61,13 +71,13 @@ public class Area extends SubCommand { return true; } case "pos2": { // Set position 2 and finish creation for type=2 (partial) - final HybridPlotWorld area = plr. getMeta("area_create_area"); + final HybridPlotWorld area = plr.getMeta("area_create_area"); if (area == null) { C.COMMAND_SYNTAX.send(plr, "/plot area create [world[:id]] [=]..."); return false; } Location pos1 = plr.getLocation(); - Location pos2 = plr. getMeta("area_pos1"); + Location pos2 = plr.getMeta("area_pos1"); int dx = Math.abs(pos1.getX() - pos2.getX()); int dz = Math.abs(pos1.getZ() - pos2.getZ()); int numx = Math.max(1, (dx + 1 + area.ROAD_WIDTH + (area.SIZE / 2)) / area.SIZE); diff --git a/Core/src/main/java/com/intellectualcrafters/plot/commands/Cluster.java b/Core/src/main/java/com/intellectualcrafters/plot/commands/Cluster.java index bdbe65517..d69576576 100644 --- a/Core/src/main/java/com/intellectualcrafters/plot/commands/Cluster.java +++ b/Core/src/main/java/com/intellectualcrafters/plot/commands/Cluster.java @@ -24,7 +24,13 @@ 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.object.*; +import com.intellectualcrafters.plot.object.BlockLoc; +import com.intellectualcrafters.plot.object.Location; +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.PlotPlayer; import com.intellectualcrafters.plot.util.MainUtil; import com.intellectualcrafters.plot.util.Permissions; import com.intellectualcrafters.plot.util.UUIDHandler; @@ -35,13 +41,8 @@ import java.util.HashSet; import java.util.Set; import java.util.UUID; -@CommandDeclaration( -command = "cluster", -aliases = { "clusters" }, -category = CommandCategory.ADMINISTRATION, -requiredType = RequiredType.NONE, -permission = "plots.cluster", -description = "Manage a plot cluster") +@CommandDeclaration(command = "cluster", aliases = "clusters", category = CommandCategory.ADMINISTRATION, requiredType = RequiredType.NONE, + permission = "plots.cluster", description = "Manage a plot cluster") public class Cluster extends SubCommand { @Override @@ -379,7 +380,6 @@ public class Cluster extends SubCommand { for (final Plot plot : new ArrayList<>(PS.get().getPlots(plr.getLocation().getWorld(), uuid))) { final PlotCluster current = plot.getCluster(); if ((current != null) && current.equals(cluster)) { - plr.getLocation().getWorld(); plot.unclaim(); } } diff --git a/Core/src/main/java/com/intellectualcrafters/plot/commands/Condense.java b/Core/src/main/java/com/intellectualcrafters/plot/commands/Condense.java index ccf202221..413ce8c3b 100644 --- a/Core/src/main/java/com/intellectualcrafters/plot/commands/Condense.java +++ b/Core/src/main/java/com/intellectualcrafters/plot/commands/Condense.java @@ -94,12 +94,12 @@ public class Condense extends SubCommand { int size = sizes.get(i); ArrayList array = buckets[size]; if (array == null) { - array = new ArrayList(); + array = new ArrayList<>(); buckets[size] = array; } array.add(plot); } - final ArrayList allPlots = new ArrayList(plots.size()); + final ArrayList allPlots = new ArrayList<>(plots.size()); for (int i = buckets.length - 1; i >= 0; i--) { ArrayList array = buckets[i]; if (array != null) { 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 4c8eb861c..224718ab7 100644 --- a/Core/src/main/java/com/intellectualcrafters/plot/commands/Rate.java +++ b/Core/src/main/java/com/intellectualcrafters/plot/commands/Rate.java @@ -44,14 +44,8 @@ import java.util.HashMap; import java.util.Map.Entry; import java.util.UUID; -@CommandDeclaration( - command = "rate", - permission = "plots.rate", - description = "Rate the plot", - usage = "/plot rate [#|next]", - aliases = {"rt"}, - category = CommandCategory.INFO, - requiredType = RequiredType.NONE) +@CommandDeclaration(command = "rate", permission = "plots.rate", description = "Rate the plot", usage = "/plot rate [#|next]", aliases = "rt", + category = CommandCategory.INFO, requiredType = RequiredType.NONE) public class Rate extends SubCommand { @Override @@ -221,21 +215,23 @@ public class Rate extends SubCommand { private int value; - public MutableInt(int i) { + MutableInt(int i) { value = i; } - public void increment() { + + void increment() { value++; } - public void decrement() { + + void decrement() { value--; } - public int getValue() { + int getValue() { return value; } - public void add(Number v) { + void add(Number v) { this.value += v.intValue(); } } diff --git a/Core/src/main/java/com/intellectualcrafters/plot/commands/list.java b/Core/src/main/java/com/intellectualcrafters/plot/commands/list.java index 9bdfa1043..8dff2ef6d 100644 --- a/Core/src/main/java/com/intellectualcrafters/plot/commands/list.java +++ b/Core/src/main/java/com/intellectualcrafters/plot/commands/list.java @@ -31,7 +31,14 @@ import com.intellectualcrafters.plot.object.PlotMessage; import com.intellectualcrafters.plot.object.PlotPlayer; import com.intellectualcrafters.plot.object.Rating; import com.intellectualcrafters.plot.object.RunnableVal3; -import com.intellectualcrafters.plot.util.*; +import com.intellectualcrafters.plot.util.EconHandler; +import com.intellectualcrafters.plot.util.ExpireManager; +import com.intellectualcrafters.plot.util.MainUtil; +import com.intellectualcrafters.plot.util.MathMan; +import com.intellectualcrafters.plot.util.Permissions; +import com.intellectualcrafters.plot.util.StringComparison; +import com.intellectualcrafters.plot.util.StringMan; +import com.intellectualcrafters.plot.util.UUIDHandler; import com.plotsquared.general.commands.CommandDeclaration; import java.util.ArrayList; @@ -97,7 +104,7 @@ public class list extends SubCommand { } public void noArgs(final PlotPlayer plr) { - MainUtil.sendMessage(plr, C.SUBCOMMAND_SET_OPTIONS_HEADER.s() + getArgumentList(plr)); + MainUtil.sendMessage(plr, C.SUBCOMMAND_SET_OPTIONS_HEADER.s() + Arrays.toString(getArgumentList(plr))); } @Override @@ -228,10 +235,9 @@ public class list extends SubCommand { @Override public int compare(final Plot p1, final Plot p2) { double v1 = 0; - double v2 = 0; - final int p1s = p1.getSettings().ratings != null ? p1.getSettings().ratings.size() : 0; - final int p2s = p2.getSettings().ratings != null ? p2.getSettings().ratings.size() : 0; - if ((p1.getSettings().ratings != null) && (p1s > 0)) { + final int p1s = p1.getSettings().getRatings().size(); + final int p2s = p2.getRatings().size(); + if (!p1.getSettings().getRatings().isEmpty()) { for (final Entry entry : p1.getRatings().entrySet()) { final double av = entry.getValue().getAverageRating(); v1 += av * av; @@ -239,7 +245,8 @@ public class list extends SubCommand { v1 /= p1s; v1 += p1s; } - if ((p2.getSettings().ratings != null) && (p2s > 0)) { + double v2 = 0; + if (!p2.getSettings().getRatings().isEmpty()) { for (final Entry entry : p2.getRatings().entrySet()) { final double av = entry.getValue().getAverageRating(); v2 += av * av; @@ -414,14 +421,5 @@ public class list extends SubCommand { } }, "/plot list " + args[0], C.PLOT_LIST_HEADER_PAGED.s()); } - - private String getArgumentList(final String[] strings) { - final StringBuilder builder = new StringBuilder(); - String prefix = ""; - for (final String s : strings) { - builder.append(prefix + s); - prefix = " | "; - } - return builder.toString(); - } + } 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 3ee601f08..9f2ae21ac 100644 --- a/Core/src/main/java/com/intellectualcrafters/plot/config/C.java +++ b/Core/src/main/java/com/intellectualcrafters/plot/config/C.java @@ -20,6 +20,13 @@ //////////////////////////////////////////////////////////////////////////////////////////////////// package com.intellectualcrafters.plot.config; +import com.intellectualcrafters.configuration.ConfigurationSection; +import com.intellectualcrafters.configuration.file.YamlConfiguration; +import com.intellectualcrafters.plot.PS; +import com.intellectualcrafters.plot.object.ConsolePlayer; +import com.intellectualcrafters.plot.util.StringMan; +import com.plotsquared.general.commands.CommandCaller; + import java.io.File; import java.util.EnumSet; import java.util.HashMap; @@ -28,13 +35,6 @@ import java.util.LinkedHashMap; import java.util.Map; import java.util.Set; -import com.intellectualcrafters.configuration.ConfigurationSection; -import com.intellectualcrafters.configuration.file.YamlConfiguration; -import com.intellectualcrafters.plot.PS; -import com.intellectualcrafters.plot.object.ConsolePlayer; -import com.intellectualcrafters.plot.util.StringMan; -import com.plotsquared.general.commands.CommandCaller; - /** * Captions class. * @@ -655,9 +655,7 @@ public enum C { */ C(final String d, final boolean prefix, final String cat) { this.d = d; - if (s == null) { - s = d; - } + this.s = d; this.prefix = prefix; this.cat = cat.toLowerCase(); } diff --git a/Core/src/main/java/com/intellectualcrafters/plot/database/MySQL.java b/Core/src/main/java/com/intellectualcrafters/plot/database/MySQL.java index 9998b0fb4..2d2c85911 100644 --- a/Core/src/main/java/com/intellectualcrafters/plot/database/MySQL.java +++ b/Core/src/main/java/com/intellectualcrafters/plot/database/MySQL.java @@ -20,14 +20,14 @@ //////////////////////////////////////////////////////////////////////////////////////////////////// package com.intellectualcrafters.plot.database; +import com.intellectualcrafters.plot.PS; + import java.sql.Connection; import java.sql.DriverManager; import java.sql.ResultSet; import java.sql.SQLException; import java.sql.Statement; -import com.intellectualcrafters.plot.PS; - /** * Connects to and uses a MySQL database * @@ -103,8 +103,9 @@ public class MySQL extends Database { if (checkConnection()) { openConnection(); } - final Statement statement = connection.createStatement(); - return statement.executeQuery(query); + try (Statement statement = connection.createStatement()) { + return statement.executeQuery(query); + } } @Override @@ -112,7 +113,8 @@ public class MySQL extends Database { if (checkConnection()) { openConnection(); } - final Statement statement = connection.createStatement(); - return statement.executeUpdate(query); + try (Statement statement = connection.createStatement()) { + return statement.executeUpdate(query); + } } } 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 4801ee468..8963e09fa 100644 --- a/Core/src/main/java/com/intellectualcrafters/plot/database/SQLManager.java +++ b/Core/src/main/java/com/intellectualcrafters/plot/database/SQLManager.java @@ -2577,7 +2577,8 @@ public class SQLManager implements AbstractDB { try { BlockLoc loc = BlockLoc.fromString(pos); cluster.settings.setPosition(loc); - } catch (final Exception e) {} + } catch (final Exception ignored) { + } } final Integer m = r.getInt("merged"); final boolean[] merged = new boolean[4]; 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 65a38d83d..826745329 100644 --- a/Core/src/main/java/com/intellectualcrafters/plot/database/SQLite.java +++ b/Core/src/main/java/com/intellectualcrafters/plot/database/SQLite.java @@ -20,6 +20,8 @@ //////////////////////////////////////////////////////////////////////////////////////////////////// package com.intellectualcrafters.plot.database; +import com.intellectualcrafters.plot.PS; + import java.io.File; import java.io.IOException; import java.sql.Connection; @@ -28,11 +30,10 @@ import java.sql.ResultSet; import java.sql.SQLException; import java.sql.Statement; -import com.intellectualcrafters.plot.PS; - /** * Connects to and uses a SQLite database - * + * + * @author tips48 */ public class SQLite extends Database { @@ -94,8 +95,9 @@ public class SQLite extends Database { if (checkConnection()) { openConnection(); } - final Statement statement = connection.createStatement(); - return statement.executeQuery(query); + try (Statement statement = connection.createStatement()) { + return statement.executeQuery(query); + } } @Override @@ -103,8 +105,9 @@ public class SQLite extends Database { if (checkConnection()) { openConnection(); } - final Statement statement = connection.createStatement(); - return statement.executeUpdate(query); + try (Statement statement = connection.createStatement()) { + return statement.executeUpdate(query); + } } @Override 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 a1e62add0..2e9138d7c 100644 --- a/Core/src/main/java/com/intellectualcrafters/plot/generator/HybridPlotWorld.java +++ b/Core/src/main/java/com/intellectualcrafters/plot/generator/HybridPlotWorld.java @@ -97,16 +97,6 @@ public class HybridPlotWorld extends ClassicPlotWorld { case 163: case 164: case 180: - data = wrap(data, 0); - data = wrap(data, 4); - data = wrap(data, 8); - data = wrap(data, 12); - return data; - - case 26: - case 86: - data = wrap(data, 0); - return data; case 64: case 71: case 193: @@ -127,6 +117,11 @@ public class HybridPlotWorld extends ClassicPlotWorld { data = wrap(data, 8); data = wrap(data, 12); return data; + + case 26: + case 86: + data = wrap(data, 0); + return data; case 28: case 66: case 157: 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 3e347c529..2737e3b3b 100644 --- a/Core/src/main/java/com/intellectualcrafters/plot/object/Plot.java +++ b/Core/src/main/java/com/intellectualcrafters/plot/object/Plot.java @@ -2069,7 +2069,7 @@ public class Plot { } visited.add(current); Set plots; - if ((max >= 0) && ((dir == -1) || (dir == 0)) && !current.getMerged(0)) { + if ((dir == -1 || (dir == 0)) && !current.getMerged(0)) { final Plot other = current.getRelative(0); if ((other != null) && other.isOwner(uuid) diff --git a/Core/src/main/java/com/intellectualcrafters/plot/object/PlotCluster.java b/Core/src/main/java/com/intellectualcrafters/plot/object/PlotCluster.java index 76cc68ebf..041536b79 100644 --- a/Core/src/main/java/com/intellectualcrafters/plot/object/PlotCluster.java +++ b/Core/src/main/java/com/intellectualcrafters/plot/object/PlotCluster.java @@ -1,41 +1,22 @@ package com.intellectualcrafters.plot.object; -import java.util.HashSet; -import java.util.UUID; - import com.intellectualcrafters.plot.database.DBFunc; import com.intellectualcrafters.plot.util.MainUtil; +import java.util.HashSet; +import java.util.UUID; + public class PlotCluster { public PlotArea area; public PlotSettings settings; public UUID owner; - public HashSet helpers = new HashSet(); - public HashSet invited = new HashSet(); + public HashSet helpers = new HashSet<>(); + public HashSet invited = new HashSet<>(); + public int temp; private PlotId pos1; private PlotId pos2; private RegionWrapper region; - - public int temp; - public PlotId getP1() { - return pos1; - } - - public PlotId getP2() { - return pos2; - } - - public void setP1(final PlotId id) { - pos1 = id; - setRegion(); - } - - public void setP2(final PlotId id) { - pos2 = id; - setRegion(); - } - public PlotCluster(final PlotArea area, final PlotId pos1, final PlotId pos2, final UUID owner) { this.area = area; this.pos1 = pos1; @@ -55,6 +36,24 @@ public class PlotCluster { this.temp = temp; setRegion(); } + + public PlotId getP1() { + return pos1; + } + + public void setP1(final PlotId id) { + pos1 = id; + setRegion(); + } + + public PlotId getP2() { + return pos2; + } + + public void setP2(final PlotId id) { + pos2 = id; + setRegion(); + } private void setRegion() { region = new RegionWrapper(pos1.x, pos2.x, pos1.y, pos2.y); @@ -83,6 +82,14 @@ public class PlotCluster { public int getArea() { return ((1 + pos2.x) - pos1.x) * ((1 + pos2.y) - pos1.y); } + + public void setArea(PlotArea plotarea) { + if (this.area != null) { + this.area.removeCluster(this); + } + this.area = plotarea; + plotarea.addCluster(this); + } @Override public int hashCode() { @@ -136,7 +143,7 @@ public class PlotCluster { final PlotId top = getP2(); return new PlotId((bot.x + top.x) / 2, (bot.y + top.y) / 2); } - + public Plot getCenterPlot() { return area.getPlotAbs(getCenterPlotId()); } @@ -155,14 +162,6 @@ public class PlotCluster { return (pos1.x <= this.pos2.x) && (pos2.x >= this.pos1.x) && (pos1.y <= this.pos2.y) && (pos2.y >= this.pos1.y); } - public void setArea(PlotArea plotarea) { - if (this.area != null) { - this.area.removeCluster(this); - } - this.area = plotarea; - plotarea.addCluster(this); - } - public boolean contains(final PlotId id) { return (pos1.x <= id.x) && (pos1.y <= id.y) && (pos2.x >= id.x) && (pos2.y >= id.y); } diff --git a/Core/src/main/java/com/intellectualcrafters/plot/util/ExpireManager.java b/Core/src/main/java/com/intellectualcrafters/plot/util/ExpireManager.java index d1da5b4a3..6d43b46fc 100644 --- a/Core/src/main/java/com/intellectualcrafters/plot/util/ExpireManager.java +++ b/Core/src/main/java/com/intellectualcrafters/plot/util/ExpireManager.java @@ -7,7 +7,14 @@ import com.intellectualcrafters.plot.database.DBFunc; import com.intellectualcrafters.plot.flag.Flag; import com.intellectualcrafters.plot.flag.FlagManager; import com.intellectualcrafters.plot.generator.HybridUtils; -import com.intellectualcrafters.plot.object.*; +import com.intellectualcrafters.plot.object.OfflinePlotPlayer; +import com.intellectualcrafters.plot.object.Plot; +import com.intellectualcrafters.plot.object.PlotAnalysis; +import com.intellectualcrafters.plot.object.PlotArea; +import com.intellectualcrafters.plot.object.PlotMessage; +import com.intellectualcrafters.plot.object.PlotPlayer; +import com.intellectualcrafters.plot.object.RunnableVal; +import com.intellectualcrafters.plot.object.RunnableVal2; import java.util.HashSet; import java.util.Iterator; @@ -20,7 +27,7 @@ public class ExpireManager { public static ExpireManager IMP; private static HashSet plotsToDelete; - private ConcurrentHashMap dates_cache = new ConcurrentHashMap<>(); + private final ConcurrentHashMap dates_cache = new ConcurrentHashMap<>(); /** * 0 = stopped, 1 = stopping, 2 = running */ @@ -154,7 +161,7 @@ public class ExpireManager { } return; } - if (plots.size() == 0) { + if (plots.isEmpty()) { running = 3; TaskManager.runTaskLater(new Runnable() { @Override @@ -165,7 +172,6 @@ public class ExpireManager { } } }, 86400000); - return; } else { TaskManager.runTaskLaterAsync(task, Settings.CLEAR_INTERVAL * 20); } 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 01cd4d757..169772860 100644 --- a/Core/src/main/java/com/intellectualcrafters/plot/util/SchematicHandler.java +++ b/Core/src/main/java/com/intellectualcrafters/plot/util/SchematicHandler.java @@ -1,24 +1,56 @@ package com.intellectualcrafters.plot.util; import com.google.common.collect.Lists; -import com.intellectualcrafters.jnbt.*; +import com.intellectualcrafters.jnbt.ByteArrayTag; +import com.intellectualcrafters.jnbt.CompoundTag; +import com.intellectualcrafters.jnbt.IntTag; +import com.intellectualcrafters.jnbt.ListTag; +import com.intellectualcrafters.jnbt.NBTInputStream; +import com.intellectualcrafters.jnbt.NBTOutputStream; +import com.intellectualcrafters.jnbt.ShortTag; +import com.intellectualcrafters.jnbt.StringTag; +import com.intellectualcrafters.jnbt.Tag; import com.intellectualcrafters.json.JSONArray; import com.intellectualcrafters.json.JSONException; import com.intellectualcrafters.plot.PS; import com.intellectualcrafters.plot.config.Settings; import com.intellectualcrafters.plot.flag.Flag; import com.intellectualcrafters.plot.generator.ClassicPlotWorld; -import com.intellectualcrafters.plot.object.*; +import com.intellectualcrafters.plot.object.ChunkLoc; +import com.intellectualcrafters.plot.object.Location; +import com.intellectualcrafters.plot.object.Plot; +import com.intellectualcrafters.plot.object.PlotArea; +import com.intellectualcrafters.plot.object.PlotBlock; +import com.intellectualcrafters.plot.object.RegionWrapper; +import com.intellectualcrafters.plot.object.RunnableVal; import com.intellectualcrafters.plot.object.schematic.PlotItem; -import java.io.*; +import java.io.BufferedReader; +import java.io.File; +import java.io.FileInputStream; +import java.io.FileNotFoundException; +import java.io.FileOutputStream; +import java.io.IOException; +import java.io.InputStream; +import java.io.InputStreamReader; +import java.io.OutputStream; +import java.io.OutputStreamWriter; +import java.io.PrintWriter; import java.net.HttpURLConnection; import java.net.URL; import java.net.URLConnection; import java.nio.channels.Channels; import java.nio.channels.ReadableByteChannel; import java.nio.charset.StandardCharsets; -import java.util.*; +import java.util.ArrayList; +import java.util.Collection; +import java.util.HashMap; +import java.util.HashSet; +import java.util.Iterator; +import java.util.List; +import java.util.Map; +import java.util.Set; +import java.util.UUID; import java.util.zip.GZIPInputStream; import java.util.zip.GZIPOutputStream; @@ -35,7 +67,7 @@ public abstract class SchematicHandler { return false; } exportAll = true; - final ArrayList plots = new ArrayList(collection); + final ArrayList plots = new ArrayList<>(collection); TaskManager.runTask(new Runnable() { @Override public void run() { @@ -661,14 +693,14 @@ public abstract class SchematicHandler { getCompoundTag(plot.getArea().worldname, plot.getRegions(), new RunnableVal() { @Override public void run(CompoundTag value) { - if (plot.getFlags().size() > 0) { + if (!plot.getFlags().isEmpty()) { HashMap flagMap = new HashMap<>(); for (Map.Entry entry : plot.getFlags().entrySet()) { String key = entry.getKey(); flagMap.put(key, new StringTag(key, entry.getValue().getValueString())); } CompoundTag tag = new CompoundTag("Flags", flagMap); - HashMap map = new HashMap(value.getValue()); + HashMap map = new HashMap<>(value.getValue()); map.put("Flags", tag); value.setValue(map); } @@ -716,9 +748,8 @@ public abstract class SchematicHandler { // Lossy but fast private final short[] ids; private final byte[] datas; - private Map flags; - private final Dimension schematicDimension; + private Map flags; private HashSet items; public Schematic(final short[] i, final byte[] b, final Dimension d, Map flags) { diff --git a/Core/src/main/java/com/intellectualcrafters/plot/util/StringMan.java b/Core/src/main/java/com/intellectualcrafters/plot/util/StringMan.java index d845617a8..e16b5c3cc 100644 --- a/Core/src/main/java/com/intellectualcrafters/plot/util/StringMan.java +++ b/Core/src/main/java/com/intellectualcrafters/plot/util/StringMan.java @@ -124,7 +124,7 @@ public class StringMan { public static boolean isAlphanumericUnd(final String str) { for (int i = 0; i < str.length(); i++) { final char c = str.charAt(i); - if ((c < 0x30) || ((c >= 0x3a) && (c <= 0x40)) || ((c > 0x5a) && (c <= 0x60)) || (c > 0x7a) || (c == '_')) { + if (c < 0x30 || (c >= 0x3a) && (c <= 0x40) || (c > 0x5a) && (c <= 0x60) || (c > 0x7a)) { return false; } } diff --git a/Core/src/main/java/com/intellectualcrafters/plot/util/helpmenu/HelpObject.java b/Core/src/main/java/com/intellectualcrafters/plot/util/helpmenu/HelpObject.java index 438a42929..bf8a46613 100644 --- a/Core/src/main/java/com/intellectualcrafters/plot/util/helpmenu/HelpObject.java +++ b/Core/src/main/java/com/intellectualcrafters/plot/util/helpmenu/HelpObject.java @@ -6,16 +6,14 @@ import com.plotsquared.general.commands.Argument; import com.plotsquared.general.commands.Command; public class HelpObject { - - private final Command _command; + private final String _rendered; public HelpObject(final Command command, final String label) { - _command = command; - _rendered = StringMan.replaceAll(C.HELP_ITEM.s(), "%usage%", _command.getUsage().replaceAll("\\{label\\}", label), "[%alias%]", - !_command.getAliases().isEmpty() ? "(" + StringMan.join(_command.getAliases(), "|") + ")" : "", "%desc%", _command.getDescription(), + _rendered = StringMan.replaceAll(C.HELP_ITEM.s(), "%usage%", command.getUsage().replaceAll("\\{label\\}", label), "[%alias%]", + !command.getAliases().isEmpty() ? "(" + StringMan.join(command.getAliases(), "|") + ")" : "", "%desc%", command.getDescription(), "%arguments%", - buildArgumentList(_command.getRequiredArguments()), "{label}", label); + buildArgumentList(command.getRequiredArguments()), "{label}", label); } @Override From bb8883dfaff48c7f9d9c3512391780161fcb4e0f Mon Sep 17 00:00:00 2001 From: Matt Date: Mon, 14 Mar 2016 11:01:52 -0400 Subject: [PATCH 5/6] Added snow-melt flag --- .../com/plotsquared/bukkit/listeners/PlotPlusListener.java | 5 ++++- Core/src/main/java/com/intellectualcrafters/plot/PS.java | 1 + 2 files changed, 5 insertions(+), 1 deletion(-) 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 eea883097..07ae581ca 100644 --- a/Bukkit/src/main/java/com/plotsquared/bukkit/listeners/PlotPlusListener.java +++ b/Bukkit/src/main/java/com/plotsquared/bukkit/listeners/PlotPlusListener.java @@ -57,7 +57,7 @@ import java.util.UUID; * */ -@SuppressWarnings({ "deprecation" }) +@SuppressWarnings("deprecation") public class PlotPlusListener extends PlotListener implements Listener { private final static HashMap feedRunnable = new HashMap<>(); private final static HashMap healRunnable = new HashMap<>(); @@ -122,6 +122,9 @@ public class PlotPlusListener extends PlotListener implements Listener { if (!FlagManager.isBooleanFlag(plot, "ice-melt", false)) { event.setCancelled(true); } + if (FlagManager.isPlotFlagFalse(plot, "snow-melt")) { + event.setCancelled(true); + } } @EventHandler(priority = EventPriority.HIGH) diff --git a/Core/src/main/java/com/intellectualcrafters/plot/PS.java b/Core/src/main/java/com/intellectualcrafters/plot/PS.java index 2fc597262..6fd7f508a 100644 --- a/Core/src/main/java/com/intellectualcrafters/plot/PS.java +++ b/Core/src/main/java/com/intellectualcrafters/plot/PS.java @@ -1951,6 +1951,7 @@ public class PS { FlagManager.addFlag(new AbstractFlag("use", new FlagValue.PlotBlockListValue())); FlagManager.addFlag(new AbstractFlag("blocked-cmds", new FlagValue.StringListValue())); FlagManager.addFlag(new AbstractFlag("ice-melt", new FlagValue.BooleanValue())); + FlagManager.addFlag(new AbstractFlag("snow-melt", new FlagValue.BooleanValue())); FlagManager.addFlag(new AbstractFlag("keep") { @Override public Object parseValueRaw(final String value) { From 3fb64d9811d041f3c4d605baf67a51e6c46e1a86 Mon Sep 17 00:00:00 2001 From: Matt Date: Tue, 15 Mar 2016 01:16:29 -0400 Subject: [PATCH 6/6] Added snow-melt flag --- Core/src/main/java/com/intellectualcrafters/plot/PS.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Core/src/main/java/com/intellectualcrafters/plot/PS.java b/Core/src/main/java/com/intellectualcrafters/plot/PS.java index 6fd7f508a..85790408e 100644 --- a/Core/src/main/java/com/intellectualcrafters/plot/PS.java +++ b/Core/src/main/java/com/intellectualcrafters/plot/PS.java @@ -1561,7 +1561,7 @@ public class PS { } for (String areaId : areasSection.getKeys(false)) { log(C.PREFIX.s() + "&3 - " + areaId); - String[] split = areaId.split("(?--`"); }