diff --git a/Bukkit/src/main/java/com/intellectualcrafters/plot/api/PlotAPI.java b/Bukkit/src/main/java/com/intellectualcrafters/plot/api/PlotAPI.java index ca456b97b..a19c9de7d 100644 --- a/Bukkit/src/main/java/com/intellectualcrafters/plot/api/PlotAPI.java +++ b/Bukkit/src/main/java/com/intellectualcrafters/plot/api/PlotAPI.java @@ -13,6 +13,7 @@ import com.intellectualcrafters.plot.object.PlotManager; import com.intellectualcrafters.plot.object.PlotPlayer; import com.intellectualcrafters.plot.util.ChunkManager; 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.UUIDHandler; @@ -46,14 +47,6 @@ import java.util.UUID; */ public class PlotAPI { - /** - * Permission that allows for admin access, this permission node will allow - * the player to use any part of the plugin, without limitations. - * @deprecated Use C.PERMISSION_ADMIN instead - */ - @Deprecated - public static final String ADMIN_PERMISSION = C.PERMISSION_ADMIN.s(); - /** * Deprecated, does nothing. * @param plugin not needed @@ -63,24 +56,6 @@ public class PlotAPI { public PlotAPI(JavaPlugin plugin) { } - /** - * Default Constructor that does nothing. - * - * @deprecated Use this class if you just want to do a few simple things - * - * - */ - @Deprecated - public PlotAPI() { - } - /** * Get all plots. * @@ -156,7 +131,7 @@ public class PlotAPI { * * @return ChunkManager * - * @see com.intellectualcrafters.plot.util.ChunkManager + * @see ChunkManager */ public ChunkManager getChunkManager() { return ChunkManager.manager; @@ -176,7 +151,7 @@ public class PlotAPI { * * @return UUIDWrapper * - * @see com.intellectualcrafters.plot.uuid.UUIDWrapper + * @see UUIDWrapper */ public UUIDWrapper getUUIDWrapper() { return UUIDHandler.getUUIDWrapper(); @@ -211,7 +186,7 @@ public class PlotAPI { * * @return Array of strings * - * @see com.intellectualcrafters.plot.util.Permissions + * @see Permissions * @deprecated Use {@link C} to list all the permissions */ @Deprecated @@ -231,7 +206,7 @@ public class PlotAPI { * * @return SchematicHandler * - * @see com.intellectualcrafters.plot.util.SchematicHandler + * @see SchematicHandler */ public SchematicHandler getSchematicHandler() { return SchematicHandler.manager; @@ -256,7 +231,7 @@ public class PlotAPI { * * @return PlotManager * - * @see com.intellectualcrafters.plot.object.PlotManager + * @see PlotManager * @see PS#getPlotManager(Plot) */ @Deprecated @@ -288,7 +263,7 @@ public class PlotAPI { * @return PlotManager * * @see PS#getPlotManager(Plot) - * @see com.intellectualcrafters.plot.object.PlotManager + * @see PlotManager */ @Deprecated public PlotManager getPlotManager(String world) { @@ -314,7 +289,7 @@ public class PlotAPI { * @return The {@link PlotArea} for the world or null if not in plotworld * * @see #getPlotAreas(World) - * @see com.intellectualcrafters.plot.object.PlotArea + * @see PlotArea */ @Deprecated public PlotArea getWorldSettings(World world) { @@ -332,7 +307,7 @@ public class PlotAPI { * @return The {@link PlotArea} for the world or null if not in plotworld * * @see PS#getPlotArea(String, String) - * @see com.intellectualcrafters.plot.object.PlotArea + * @see PlotArea */ @Deprecated public PlotArea getWorldSettings(String world) { @@ -392,7 +367,7 @@ public class PlotAPI { * @param caption The caption * * @see #sendConsoleMessage(String) - * @see com.intellectualcrafters.plot.config.C + * @see C */ public void sendConsoleMessage(C caption) { sendConsoleMessage(caption.s()); @@ -403,8 +378,8 @@ public class PlotAPI { * * @param flag Flag that should be registered * - * @see com.intellectualcrafters.plot.flag.FlagManager#addFlag(com.intellectualcrafters.plot.flag.AbstractFlag) - * @see com.intellectualcrafters.plot.flag.AbstractFlag + * @see FlagManager#addFlag(AbstractFlag) + * @see AbstractFlag */ public void addFlag(AbstractFlag flag) { FlagManager.addFlag(flag); @@ -415,8 +390,8 @@ public class PlotAPI { * * @return array of Flag[] * - * @see com.intellectualcrafters.plot.flag.FlagManager#getFlags() - * @see com.intellectualcrafters.plot.flag.AbstractFlag + * @see FlagManager#getFlags() + * @see AbstractFlag */ public AbstractFlag[] getFlags() { return FlagManager.getFlags().toArray(new AbstractFlag[FlagManager.getFlags().size()]); @@ -468,7 +443,7 @@ public class PlotAPI { * * @return plot if found, otherwise it creates a temporary plot * - * @see #getPlot(org.bukkit.Location) + * @see #getPlot(Location) * @see Plot */ public Plot getPlot(Player player) { @@ -638,7 +613,7 @@ public class PlotAPI { * Register a subcommand. * @deprecated Command registration is done on object creation * @param c SubCommand, that we want to register - * @see com.intellectualcrafters.plot.commands.SubCommand + * @see SubCommand */ @Deprecated public void registerCommand(SubCommand c) { diff --git a/Bukkit/src/main/java/com/plotsquared/bukkit/BukkitMain.java b/Bukkit/src/main/java/com/plotsquared/bukkit/BukkitMain.java index 9e3a19c3b..755475b38 100644 --- a/Bukkit/src/main/java/com/plotsquared/bukkit/BukkitMain.java +++ b/Bukkit/src/main/java/com/plotsquared/bukkit/BukkitMain.java @@ -73,14 +73,9 @@ 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 java.io.File; -import java.util.ArrayList; -import java.util.Arrays; -import java.util.Iterator; -import java.util.List; -import java.util.UUID; import org.bukkit.Bukkit; import org.bukkit.ChatColor; +import org.bukkit.Chunk; import org.bukkit.Location; import org.bukkit.OfflinePlayer; import org.bukkit.World; @@ -93,9 +88,15 @@ import org.bukkit.metadata.MetadataValue; import org.bukkit.plugin.Plugin; import org.bukkit.plugin.java.JavaPlugin; +import java.io.File; +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 { - public static BukkitMain THIS; public static WorldEditPlugin worldEdit; private int[] version; @@ -123,7 +124,6 @@ public class BukkitMain extends JavaPlugin implements Listener, IPlotMain { @Override public void onEnable() { - BukkitMain.THIS = this; new PS(this, "Bukkit"); } @@ -131,40 +131,35 @@ public class BukkitMain extends JavaPlugin implements Listener, IPlotMain { public void onDisable() { PS.get().disable(); Bukkit.getScheduler().cancelTasks(this); - BukkitMain.THIS = null; } @Override public void log(String message) { - if (BukkitMain.THIS != null) { - try { - message = C.color(message); - if (!Settings.CONSOLE_COLOR) { - message = ChatColor.stripColor(message); - } - this.getServer().getConsoleSender().sendMessage(message); - return; - } catch (Throwable ignored) { - //ignored + try { + message = C.color(message); + if (!Settings.CONSOLE_COLOR) { + message = ChatColor.stripColor(message); } + this.getServer().getConsoleSender().sendMessage(message); + return; + } catch (Throwable ignored) { + //ignored } System.out.println(ConsoleColors.fromString(message)); } @Override public void disable() { - if (BukkitMain.THIS != null) { - onDisable(); - } + onDisable(); } @Override public int[] getPluginVersion() { - String version = getDescription().getVersion(); - if (version.contains("-SNAPSHOT")) { - version = version.split("-SNAPSHOT")[0]; + String ver = getDescription().getVersion(); + if (ver.contains("-SNAPSHOT")) { + ver = ver.split("-SNAPSHOT")[0]; } - String[] split = version.split("\\."); + String[] split = ver.split("\\."); return new int[]{Integer.parseInt(split[0]), Integer.parseInt(split[1]), Integer.parseInt(split[2])}; } @@ -189,7 +184,7 @@ public class BukkitMain extends JavaPlugin implements Listener, IPlotMain { @Override public TaskManager getTaskManager() { - return new BukkitTaskManager(); + return new BukkitTaskManager(this); } @Override @@ -402,7 +397,7 @@ public class BukkitMain extends JavaPlugin implements Listener, IPlotMain { } @Override - public PlotQueue initPlotQueue() { + public PlotQueue initPlotQueue() { try { new SendChunk(); MainUtil.canSendChunk = true; @@ -449,18 +444,15 @@ public class BukkitMain extends JavaPlugin implements Listener, IPlotMain { TaskManager.runTaskLaterAsync(new Runnable() { @Override public void run() { - if (new LikePlotMeConverter("PlotMe").run(new ClassicPlotMeConnector())) { + if (new LikePlotMeConverter().run(new ClassicPlotMeConnector())) { return; } - if (new LikePlotMeConverter("PlotMe").run(new PlotMeConnector_017())) { - return; - } - if (new LikePlotMeConverter("AthionPlots").run(new ClassicPlotMeConnector())) { + if (new LikePlotMeConverter().run(new PlotMeConnector_017())) { return; } } }, 20); - return Bukkit.getPluginManager().getPlugin("PlotMe") != null || Bukkit.getPluginManager().getPlugin("AthionPlots") != null; + return Bukkit.getPluginManager().getPlugin("PlotMe") != null; } @Override 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 b39fc4f43..444251c8d 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 @@ -15,7 +15,7 @@ import java.util.HashMap; abstract class APlotMeConnector { - public abstract Connection getPlotMeConnection(String plugin, FileConfiguration plotConfig, String dataFolder); + public abstract Connection getPlotMeConnection(FileConfiguration plotConfig, String dataFolder); public abstract HashMap> getPlotMePlots(Connection connection) throws SQLException; diff --git a/Bukkit/src/main/java/com/plotsquared/bukkit/database/plotme/ClassicPlotMeConnector.java b/Bukkit/src/main/java/com/plotsquared/bukkit/database/plotme/ClassicPlotMeConnector.java index 1890af663..3e6ee0184 100644 --- a/Bukkit/src/main/java/com/plotsquared/bukkit/database/plotme/ClassicPlotMeConnector.java +++ b/Bukkit/src/main/java/com/plotsquared/bukkit/database/plotme/ClassicPlotMeConnector.java @@ -30,16 +30,15 @@ public class ClassicPlotMeConnector extends APlotMeConnector { private String prefix; @Override - public Connection getPlotMeConnection(String plugin, FileConfiguration plotConfig, String dataFolder) { - this.plugin = plugin.toLowerCase(); - this.prefix = plotConfig.getString("mySQLprefix", plugin.toLowerCase()); + public Connection getPlotMeConnection(FileConfiguration plotConfig, String dataFolder) { + this.plugin = this.plugin.toLowerCase(); + this.prefix = plotConfig.getString("mySQLprefix", this.plugin.toLowerCase()); try { if (plotConfig.getBoolean("usemySQL")) { String user = plotConfig.getString("mySQLuname"); String password = plotConfig.getString("mySQLpass"); String con = plotConfig.getString("mySQLconn"); return DriverManager.getConnection(con, user, password); - // return new MySQL(plotsquared, hostname, port, database, username, password) } else { return new SQLite(dataFolder + File.separator + "plots.db").openConnection(); } @@ -110,32 +109,21 @@ public class ClassicPlotMeConnector extends APlotMeConnector { owner = DBFunc.everyone; } else { if (checkUUID || checkUUID2) { - try { - byte[] bytes = resultSet.getBytes(column); - if (bytes != null) { - try { - ByteBuffer bb = ByteBuffer.wrap(bytes); - long high = bb.getLong(); - long low = bb.getLong(); - owner = new UUID(high, low); - } catch (Exception e) { - e.printStackTrace(); - owner = UUID.nameUUIDFromBytes(bytes); - } - UUIDHandler.add(new StringWrapper(name), owner); - } - } catch (SQLException e) { - e.printStackTrace(); + byte[] bytes = resultSet.getBytes(column); + if (bytes != null) { + ByteBuffer bb = ByteBuffer.wrap(bytes); + long high = bb.getLong(); + long low = bb.getLong(); + owner = new UUID(high, low); + UUIDHandler.add(new StringWrapper(name), owner); } } - if (owner == null) { - if (name.isEmpty()) { - PS.log("&cCould not identify owner for plot: " + id + " -> '" + name + "'"); - missing++; - continue; - } - owner = UUID.nameUUIDFromBytes(("OfflinePlayer:" + name.toLowerCase()).getBytes(Charsets.UTF_8)); + if (name.isEmpty()) { + PS.log("&cCould not identify owner for plot: " + id + " -> '" + name + "'"); + missing++; + continue; } + owner = UUID.nameUUIDFromBytes(("OfflinePlayer:" + name.toLowerCase()).getBytes(Charsets.UTF_8)); } } else { UUIDHandler.add(new StringWrapper(name), owner); @@ -180,22 +168,13 @@ public class ClassicPlotMeConnector extends APlotMeConnector { if ("*".equals(name)) { denied = DBFunc.everyone; } else if (DBFunc.hasColumn(resultSet, "playerid")) { - try { - byte[] bytes = resultSet.getBytes("playerid"); - if (bytes != null) { - try { - ByteBuffer bb = ByteBuffer.wrap(bytes); - long high = bb.getLong(); - long low = bb.getLong(); - denied = new UUID(high, low); - } catch (Exception e) { - e.printStackTrace(); - denied = UUID.nameUUIDFromBytes(bytes); - } - UUIDHandler.add(new StringWrapper(name), denied); - } - } catch (SQLException e) { - e.printStackTrace(); + byte[] bytes = resultSet.getBytes("playerid"); + if (bytes != null) { + ByteBuffer bb = ByteBuffer.wrap(bytes); + long mostSigBits = bb.getLong(); + long leastSigBits = bb.getLong(); + denied = new UUID(mostSigBits, leastSigBits); + UUIDHandler.add(new StringWrapper(name), denied); } } if (denied == null) { @@ -224,22 +203,13 @@ public class ClassicPlotMeConnector extends APlotMeConnector { if ("*".equals(name)) { helper = DBFunc.everyone; } else if (DBFunc.hasColumn(resultSet, "playerid")) { - try { - byte[] bytes = resultSet.getBytes("playerid"); - if (bytes != null) { - try { - ByteBuffer bb = ByteBuffer.wrap(bytes); - long high = bb.getLong(); - long low = bb.getLong(); - helper = new UUID(high, low); - } catch (Exception e) { - e.printStackTrace(); - helper = UUID.nameUUIDFromBytes(bytes); - } - UUIDHandler.add(new StringWrapper(name), helper); - } - } catch (SQLException e) { - e.printStackTrace(); + byte[] bytes = resultSet.getBytes("playerid"); + if (bytes != null) { + ByteBuffer bb = ByteBuffer.wrap(bytes); + long mostSigBits = bb.getLong(); + long leastSigBits = bb.getLong(); + helper = new UUID(mostSigBits, leastSigBits); + UUIDHandler.add(new StringWrapper(name), helper); } } if (helper == null) { diff --git a/Bukkit/src/main/java/com/plotsquared/bukkit/database/plotme/LikePlotMeConverter.java b/Bukkit/src/main/java/com/plotsquared/bukkit/database/plotme/LikePlotMeConverter.java index 803f24177..f21e2415a 100644 --- a/Bukkit/src/main/java/com/plotsquared/bukkit/database/plotme/LikePlotMeConverter.java +++ b/Bukkit/src/main/java/com/plotsquared/bukkit/database/plotme/LikePlotMeConverter.java @@ -24,6 +24,7 @@ import java.nio.file.Files; import java.nio.file.Path; import java.nio.file.Paths; import java.sql.Connection; +import java.sql.SQLException; import java.util.ArrayList; import java.util.Collections; import java.util.HashMap; @@ -33,17 +34,6 @@ import java.util.concurrent.atomic.AtomicBoolean; public class LikePlotMeConverter { - private final String plugin; - - /** - * Constructor. - * - * @param plugin Plugin Used to run the converter - */ - public LikePlotMeConverter(String plugin) { - this.plugin = plugin; - } - public static String getWorld(String world) { for (World newWorld : Bukkit.getWorlds()) { if (newWorld.getName().equalsIgnoreCase(world)) { @@ -58,11 +48,7 @@ public class LikePlotMeConverter { } public String getPlotMePath() { - return new File(".").getAbsolutePath() + File.separator + "plugins" + File.separator + this.plugin + File.separator; - } - - public String getAthionPlotsPath() { - return new File(".").getAbsolutePath() + File.separator + "plugins" + File.separator + this.plugin + File.separator; + return new File(".").getAbsolutePath() + File.separator + "plugins" + File.separator + "PlotMe" + File.separator; } public FileConfiguration getPlotMeConfig(String dataFolder) { @@ -77,10 +63,10 @@ public class LikePlotMeConverter { return plotConfig.getConfigurationSection("worlds").getKeys(false); } - public void mergeWorldYml(String plugin, FileConfiguration plotConfig) { + public void mergeWorldYml(FileConfiguration plotConfig) { try { File genConfig = - new File("plugins" + File.separator + plugin + File.separator + "PlotMe-DefaultGenerator" + File.separator + "config.yml"); + new File("plugins" + File.separator + "PlotMe" + File.separator + "PlotMe-DefaultGenerator" + File.separator + "config.yml"); if (genConfig.exists()) { YamlConfiguration yml = YamlConfiguration.loadConfiguration(genConfig); for (String key : yml.getKeys(true)) { @@ -97,7 +83,7 @@ public class LikePlotMeConverter { } } - public void updateWorldYml(String plugin, String location) { + public void updateWorldYml(String location) { try { Path path = Paths.get(location); File file = new File(location); @@ -106,7 +92,7 @@ public class LikePlotMeConverter { } String content = new String(Files.readAllBytes(path), StandardCharsets.UTF_8); content = content.replaceAll("PlotMe-DefaultGenerator", "PlotSquared"); - content = content.replaceAll(plugin, "PlotSquared"); + content = content.replaceAll("PlotMe", "PlotSquared"); Files.write(path, content.getBytes(StandardCharsets.UTF_8)); } catch (IOException ignored) { //ignored @@ -131,31 +117,31 @@ public class LikePlotMeConverter { PS.debug("&3Using connector: " + connector.getClass().getCanonicalName()); - Connection connection = connector.getPlotMeConnection(this.plugin, plotConfig, dataFolder); + Connection connection = connector.getPlotMeConnection(plotConfig, dataFolder); if (!connector.isValidConnection(connection)) { sendMessage("Cannot connect to PlotMe DB. Conversion process will not continue"); return false; } - sendMessage(this.plugin + " conversion has started. To disable this, please set 'plotme-convert.enabled' to false in the 'settings.yml'"); + sendMessage("PlotMe conversion has started. To disable this, please set 'plotme-convert.enabled' to false in the 'settings.yml'"); - mergeWorldYml(this.plugin, plotConfig); + mergeWorldYml(plotConfig); - sendMessage("Connecting to " + this.plugin + " DB"); + sendMessage("Connecting to PlotMe DB"); ArrayList createdPlots = new ArrayList<>(); sendMessage("Collecting plot data"); - String dbPrefix = this.plugin.toLowerCase(); + String dbPrefix = "PlotMe".toLowerCase(); sendMessage(" - " + dbPrefix + "Plots"); final Set worlds = getPlotMeWorlds(plotConfig); if (Settings.CONVERT_PLOTME) { sendMessage("Updating bukkit.yml"); - updateWorldYml(this.plugin, "bukkit.yml"); - updateWorldYml(this.plugin, "plugins/Multiverse-Core/worlds.yml"); + updateWorldYml("bukkit.yml"); + updateWorldYml("plugins/Multiverse-Core/worlds.yml"); for (String world : plotConfig.getConfigurationSection("worlds").getKeys(false)) { sendMessage("Copying config for: " + world); try { @@ -188,24 +174,17 @@ public class LikePlotMeConverter { for (String world : plots.keySet()) { String actualWorldName = getWorld(world); String plotMeWorldName = world.toLowerCase(); - Integer pathwidth = plotmeDgYml.getInt("worlds." + plotMeWorldName + ".PathWidth"); // - /* - * TODO: dead code - * - if (pathwidth == null) { - pathwidth = 7; - } - */ - PS.get().config.set("worlds." + world + ".road.width", pathwidth); + Integer pathWidth = plotmeDgYml.getInt("worlds." + plotMeWorldName + ".PathWidth"); // + PS.get().config.set("worlds." + world + ".road.width", pathWidth); - Integer pathheight = plotmeDgYml.getInt("worlds." + plotMeWorldName + ".RoadHeight"); // - if (pathheight == 0) { - pathheight = 64; + int pathHeight = plotmeDgYml.getInt("worlds." + plotMeWorldName + ".RoadHeight"); // + if (pathHeight == 0) { + pathHeight = 64; } - PS.get().config.set("worlds." + world + ".road.height", pathheight); - PS.get().config.set("worlds." + world + ".wall.height", pathheight); - PS.get().config.set("worlds." + world + ".plot.height", pathheight); - Integer plotSize = plotmeDgYml.getInt("worlds." + plotMeWorldName + ".PlotSize"); // + PS.get().config.set("worlds." + world + ".road.height", pathHeight); + PS.get().config.set("worlds." + world + ".wall.height", pathHeight); + PS.get().config.set("worlds." + world + ".plot.height", pathHeight); + int plotSize = plotmeDgYml.getInt("worlds." + plotMeWorldName + ".PlotSize", 32); // if (plotSize == 0) { plotSize = 32; } @@ -218,7 +197,7 @@ public class LikePlotMeConverter { PS.get().config.set("worlds." + world + ".plot.filling", Collections.singletonList(filling)); String road = plotmeDgYml.getString("worlds." + plotMeWorldName + ".RoadMainBlock", "5"); PS.get().config.set("worlds." + world + ".road.block", road); - Integer height = plotmeDgYml.getInt("worlds." + plotMeWorldName + ".RoadHeight"); // + int height = plotmeDgYml.getInt("worlds." + plotMeWorldName + ".RoadHeight"); // if (height == 0) { height = plotmeDgYml.getInt("worlds." + plotMeWorldName + ".GroundHeight"); // if (height == 0) { @@ -364,7 +343,7 @@ public class LikePlotMeConverter { } } }); - } catch (Exception e) { + } catch (InterruptedException | SQLException e) { e.printStackTrace(); PS.debug("&/end/"); } diff --git a/Bukkit/src/main/java/com/plotsquared/bukkit/database/plotme/PlotMeConnector_017.java b/Bukkit/src/main/java/com/plotsquared/bukkit/database/plotme/PlotMeConnector_017.java index 8e81567fa..c7180127b 100644 --- a/Bukkit/src/main/java/com/plotsquared/bukkit/database/plotme/PlotMeConnector_017.java +++ b/Bukkit/src/main/java/com/plotsquared/bukkit/database/plotme/PlotMeConnector_017.java @@ -19,7 +19,6 @@ import java.sql.PreparedStatement; import java.sql.ResultSet; import java.sql.SQLException; import java.util.HashMap; -import java.util.Map.Entry; import java.util.UUID; public class PlotMeConnector_017 extends APlotMeConnector { @@ -27,8 +26,8 @@ public class PlotMeConnector_017 extends APlotMeConnector { private String plugin; @Override - public Connection getPlotMeConnection(String plugin, FileConfiguration plotConfig, String dataFolder) { - this.plugin = plugin.toLowerCase(); + public Connection getPlotMeConnection(FileConfiguration plotConfig, String dataFolder) { + this.plugin = this.plugin.toLowerCase(); try { if (plotConfig.getBoolean("usemySQL")) { String user = plotConfig.getString("mySQLuname"); @@ -110,14 +109,10 @@ public class PlotMeConnector_017 extends APlotMeConnector { owner = DBFunc.everyone; } else { if (checkUUID) { - try { - byte[] bytes = resultSet.getBytes("ownerid"); - if (bytes != null) { - owner = UUID.nameUUIDFromBytes(bytes); - UUIDHandler.add(new StringWrapper(name), owner); - } - } catch (Exception e) { - e.printStackTrace(); + byte[] bytes = resultSet.getBytes("ownerid"); + if (bytes != null) { + owner = UUID.nameUUIDFromBytes(bytes); + UUIDHandler.add(new StringWrapper(name), owner); } } if (owner == null) { @@ -131,8 +126,7 @@ public class PlotMeConnector_017 extends APlotMeConnector { Plot plot = new Plot(PlotArea.createGeneric(world), id, owner); plots.put(key, plot); } - for (Entry entry : plots.entrySet()) { - Plot plot = entry.getValue(); + for (Plot plot : plots.values()) { HashMap mergeMap = merges.get(plot.getArea().worldname); if (mergeMap != null) { if (mergeMap.containsKey(plot.getId())) { @@ -180,8 +174,7 @@ public class PlotMeConnector_017 extends APlotMeConnector { } HashMap> processed = new HashMap<>(); - for (Entry entry : plots.entrySet()) { - Plot plot = entry.getValue(); + for (Plot plot : plots.values()) { HashMap map = processed.get(plot.getArea().worldname); if (map == null) { map = new HashMap<>(); 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 74f1c3332..540b88766 100644 --- a/Bukkit/src/main/java/com/plotsquared/bukkit/generator/BukkitPlotGenerator.java +++ b/Bukkit/src/main/java/com/plotsquared/bukkit/generator/BukkitPlotGenerator.java @@ -16,17 +16,18 @@ import com.intellectualcrafters.plot.util.PlotChunk; import com.intellectualcrafters.plot.util.SetQueue; import com.plotsquared.bukkit.util.BukkitUtil; import com.plotsquared.bukkit.util.block.GenChunk; -import java.util.ArrayList; -import java.util.HashMap; -import java.util.List; -import java.util.Random; -import java.util.Set; import org.bukkit.Chunk; import org.bukkit.World; import org.bukkit.block.Biome; import org.bukkit.generator.BlockPopulator; import org.bukkit.generator.ChunkGenerator; +import java.util.ArrayList; +import java.util.HashMap; +import java.util.List; +import java.util.Random; +import java.util.Set; + public class BukkitPlotGenerator extends ChunkGenerator implements GeneratorWrapper { private final PlotChunk chunkSetter; @@ -35,10 +36,9 @@ public class BukkitPlotGenerator extends ChunkGenerator implements GeneratorWrap private final List populators = new ArrayList<>(); private final ChunkGenerator platformGenerator; private final boolean full; + private final HashMap dataMap = new HashMap<>(); private boolean loaded = false; - HashMap dataMap = new HashMap<>(); - public BukkitPlotGenerator(IndependentPlotGenerator generator) { this.plotGenerator = generator; this.platformGenerator = this; @@ -47,8 +47,8 @@ public class BukkitPlotGenerator extends ChunkGenerator implements GeneratorWrap public void populate(World world, Random r, Chunk c) { ChunkLoc loc = new ChunkLoc(c.getX(), c.getZ()); byte[][] resultData; - if (!dataMap.containsKey(loc)) { - GenChunk result = (GenChunk) chunkSetter; + if (!BukkitPlotGenerator.this.dataMap.containsKey(loc)) { + GenChunk result = (GenChunk) BukkitPlotGenerator.this.chunkSetter; // Set the chunk location result.setChunkWrapper(SetQueue.IMP.new ChunkWrapper(world.getName(), loc.x, loc.z)); // Set the result data @@ -60,7 +60,7 @@ public class BukkitPlotGenerator extends ChunkGenerator implements GeneratorWrap generate(world, loc.x, loc.z, result); resultData = result.result_data; } else { - resultData = dataMap.remove(loc); + resultData = BukkitPlotGenerator.this.dataMap.remove(loc); } if (resultData != null) { for (int i = 0; i < resultData.length; i++) { @@ -76,11 +76,11 @@ public class BukkitPlotGenerator extends ChunkGenerator implements GeneratorWrap } } } - random.state = c.getX() << 16 | c.getZ() & 0xFFFF; + BukkitPlotGenerator.this.random.state = c.getX() << 16 | c.getZ() & 0xFFFF; PlotArea area = PS.get().getPlotArea(world.getName(), null); SetQueue.ChunkWrapper wrap = SetQueue.IMP.new ChunkWrapper(area.worldname, c.getX(), c.getZ()); PlotChunk chunk = SetQueue.IMP.queue.getChunk(wrap); - if (plotGenerator.populateChunk(chunk, area, random)) { + if (BukkitPlotGenerator.this.plotGenerator.populateChunk(chunk, area, BukkitPlotGenerator.this.random)) { chunk.addToQueue(); } } @@ -232,12 +232,9 @@ public class BukkitPlotGenerator extends ChunkGenerator implements GeneratorWrap } catch (Exception e) { e.printStackTrace(); } - if (world == null) { - return populators; - } ArrayList toAdd = new ArrayList(); List existing = world.getPopulators(); - for (BlockPopulator populator : populators) { + for (BlockPopulator populator : this.populators) { if (!existing.contains(populator)) { toAdd.add(populator); } @@ -269,7 +266,7 @@ public class BukkitPlotGenerator extends ChunkGenerator implements GeneratorWrap // Return the result data return result.cd; } - + public void generate(World world, int cx, int cz, PlotChunk result) { // Load if improperly loaded if (!this.loaded) { @@ -305,7 +302,7 @@ public class BukkitPlotGenerator extends ChunkGenerator implements GeneratorWrap return this.platformGenerator.generateExtBlockSections(world, r, cx, cz, grid); } else { generate(world, cx, cz, result); - dataMap.put(new ChunkLoc(cx, cz), result.result_data); + this.dataMap.put(new ChunkLoc(cx, cz), result.result_data); } } catch (Throwable e) { @@ -330,7 +327,7 @@ public class BukkitPlotGenerator extends ChunkGenerator implements GeneratorWrap @Override public String toString() { if (this.platformGenerator == this) { - return "" + this.plotGenerator; + return this.plotGenerator.getName(); } if (this.platformGenerator == null) { return "null"; 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 96abea7f1..6500620fd 100644 --- a/Bukkit/src/main/java/com/plotsquared/bukkit/listeners/PlayerEvents.java +++ b/Bukkit/src/main/java/com/plotsquared/bukkit/listeners/PlayerEvents.java @@ -42,6 +42,7 @@ import org.bukkit.entity.Creature; import org.bukkit.entity.EnderDragon; import org.bukkit.entity.Entity; import org.bukkit.entity.EntityType; +import org.bukkit.entity.FallingBlock; import org.bukkit.entity.Fireball; import org.bukkit.entity.Hanging; import org.bukkit.entity.HumanEntity; @@ -109,6 +110,7 @@ import org.bukkit.plugin.Plugin; 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; @@ -362,7 +364,7 @@ public class PlayerEvents extends PlotListener implements Listener { } } Player player = event.getPlayer(); - BukkitPlayer pp = (BukkitPlayer) BukkitUtil.getPlayer(player); + PlotPlayer pp = BukkitUtil.getPlayer(player); Plot plot = pp.getCurrentPlot(); if (plot == null) { return; @@ -464,8 +466,8 @@ public class PlayerEvents extends PlotListener implements Listener { @EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true) public void playerRespawn(PlayerRespawnEvent event) { - final Player player = event.getPlayer(); - final PlotPlayer pp = BukkitUtil.getPlayer(player); + Player player = event.getPlayer(); + PlotPlayer pp = BukkitUtil.getPlayer(player); EventUtil.manager.doDeathTask(pp); } @@ -572,14 +574,13 @@ public class PlayerEvents extends PlotListener implements Listener { @EventHandler(priority = EventPriority.LOWEST, ignoreCancelled = true) public void onChat(AsyncPlayerChatEvent event) { - Player player = event.getPlayer(); - PlotPlayer plr = BukkitUtil.getPlayer(player); - Location loc = plr.getLocation(); - PlotArea area = loc.getPlotArea(); - if (area == null || (!area.PLOT_CHAT && !plr.getAttribute("chat"))) { + PlotPlayer plotPlayer = BukkitUtil.getPlayer(event.getPlayer()); + Location location = plotPlayer.getLocation(); + PlotArea area = location.getPlotArea(); + if (area == null || (!area.PLOT_CHAT && !plotPlayer.getAttribute("chat"))) { return; } - Plot plot = area.getPlot(loc); + Plot plot = area.getPlot(location); if (plot == null) { return; } @@ -614,7 +615,7 @@ public class PlayerEvents extends PlotListener implements Listener { } @EventHandler(priority = EventPriority.LOWEST) - public void BlockDestroy(BlockBreakEvent event) { + public void blockDestroy(BlockBreakEvent event) { Player player = event.getPlayer(); Location loc = BukkitUtil.getLocation(event.getBlock().getLocation()); PlotArea area = loc.getPlotArea(); @@ -756,7 +757,7 @@ public class PlayerEvents extends PlotListener implements Listener { return; } Entity e = event.getEntity(); - if (!(e instanceof org.bukkit.entity.FallingBlock)) { + if (!(e instanceof FallingBlock)) { event.setCancelled(true); } } @@ -773,20 +774,16 @@ public class PlayerEvents extends PlotListener implements Listener { } @EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true) - public void onBS(BlockSpreadEvent e) { - Block b = e.getBlock(); - Location loc = BukkitUtil.getLocation(b.getLocation()); - if (loc.isPlotRoad()) { - e.setCancelled(true); - } + public void onBlockSpread(BlockSpreadEvent event) { + onBlockForm(event); //send to super class. } @EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true) - public void onBF(BlockFormEvent e) { - Block b = e.getBlock(); - Location loc = BukkitUtil.getLocation(b.getLocation()); + public void onBlockForm(BlockFormEvent event) { + Block block = event.getBlock(); + Location loc = BukkitUtil.getLocation(block.getLocation()); if (loc.isPlotRoad()) { - e.setCancelled(true); + event.setCancelled(true); } } 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 157372840..ebb1369a3 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,14 +34,14 @@ import org.bukkit.util.Vector; public class EntityWrapper { + public final EntityType type; + public final float yaw; + public final float pitch; + public final short depth; private final int hash; - public EntityType type; - public float yaw; - public float pitch; public double x; public double y; public double z; - public short depth; public EntityBaseStats base = null; // Extended public ItemStack stack; diff --git a/Bukkit/src/main/java/com/plotsquared/bukkit/object/schematic/StateWrapper.java b/Bukkit/src/main/java/com/plotsquared/bukkit/object/schematic/StateWrapper.java index ab7b46236..3431e6b77 100644 --- a/Bukkit/src/main/java/com/plotsquared/bukkit/object/schematic/StateWrapper.java +++ b/Bukkit/src/main/java/com/plotsquared/bukkit/object/schematic/StateWrapper.java @@ -8,11 +8,6 @@ import com.intellectualcrafters.jnbt.Tag; import com.intellectualcrafters.plot.object.schematic.ItemType; import com.intellectualcrafters.plot.util.MathMan; import com.plotsquared.bukkit.util.BukkitUtil; -import java.util.ArrayList; -import java.util.HashMap; -import java.util.List; -import java.util.Map; -import java.util.Map.Entry; import org.bukkit.World; import org.bukkit.block.Block; import org.bukkit.block.BlockState; @@ -21,6 +16,12 @@ import org.bukkit.inventory.Inventory; import org.bukkit.inventory.InventoryHolder; import org.bukkit.inventory.ItemStack; +import java.util.ArrayList; +import java.util.HashMap; +import java.util.List; +import java.util.Map; +import java.util.Map.Entry; + public class StateWrapper { public BlockState state = null; @@ -38,8 +39,8 @@ public class StateWrapper { if (this.tag == null) { return false; } - switch (tag.getString("id").toLowerCase()) { - case "chest": { + switch (this.tag.getString("id").toLowerCase()) { + case "chest": List itemsTag = this.tag.getListTag("Items").getValue(); int length = itemsTag.size(); short[] ids = new short[length]; @@ -75,9 +76,7 @@ public class StateWrapper { } state.update(true); return true; - } else { } - } } return false; } diff --git a/Bukkit/src/main/java/com/plotsquared/bukkit/titles/DefaultTitleManager.java b/Bukkit/src/main/java/com/plotsquared/bukkit/titles/DefaultTitleManager.java index 4d34be9c6..5e8c339bc 100644 --- a/Bukkit/src/main/java/com/plotsquared/bukkit/titles/DefaultTitleManager.java +++ b/Bukkit/src/main/java/com/plotsquared/bukkit/titles/DefaultTitleManager.java @@ -1,86 +1,14 @@ package com.plotsquared.bukkit.titles; import com.plotsquared.bukkit.chat.Reflection; -import org.bukkit.Bukkit; import org.bukkit.ChatColor; import org.bukkit.entity.Player; import java.lang.reflect.Field; import java.lang.reflect.InvocationTargetException; import java.lang.reflect.Method; -import java.util.HashMap; -import java.util.Map; -/** - * [ PlotSquared DefaultTitleManager by Maxim Van de Wynckel ] - * - * @author Maxim Van de Wynckel - * - */ -public class DefaultTitleManager { - - private static final Map, Class> CORRESPONDING_TYPES = new HashMap<>(); - /* Title packet */ - private Class packetTitle; - /* Title packet actions ENUM */ - private Class packetActions; - /* Chat serializer */ - private Class nmsChatSerializer; - private Class chatBaseComponent; - /* Title text and color */ - private String title = ""; - private ChatColor titleColor = ChatColor.WHITE; - /* Subtitle text and color */ - private String subtitle = ""; - private ChatColor subtitleColor = ChatColor.WHITE; - /* Title timings */ - private int fadeInTime = -1; - private int stayTime = -1; - private int fadeOutTime = -1; - private boolean ticks = false; - - /** - * Create a new 1.8 title. - * - * @param title Title - * @throws ClassNotFoundException - */ - public DefaultTitleManager(String title) throws ClassNotFoundException { - this.title = title; - loadClasses(); - } - - /** - * Create a new 1.8 title. - * - * @param title Title text - * @param subtitle Subtitle text - * @throws ClassNotFoundException - */ - public DefaultTitleManager(String title, String subtitle) throws ClassNotFoundException { - this.title = title; - this.subtitle = subtitle; - loadClasses(); - } - - /** - * Copy 1.8 title. - * - * @param title Title - * @throws ClassNotFoundException - */ - public DefaultTitleManager(DefaultTitleManager title) throws ClassNotFoundException { - // Copy title - this.title = title.title; - this.subtitle = title.subtitle; - this.titleColor = title.titleColor; - this.subtitleColor = title.subtitleColor; - this.fadeInTime = title.fadeInTime; - this.fadeOutTime = title.fadeOutTime; - this.stayTime = title.stayTime; - this.ticks = title.ticks; - loadClasses(); - } +public class DefaultTitleManager extends TitleManager { /** * Create a new 1.8 title. @@ -90,16 +18,9 @@ public class DefaultTitleManager { * @param fadeInTime Fade in time * @param stayTime Stay on screen time * @param fadeOutTime Fade out time - * @throws ClassNotFoundException */ - public DefaultTitleManager(String title, String subtitle, int fadeInTime, int stayTime, int fadeOutTime) - throws ClassNotFoundException { - this.title = title; - this.subtitle = subtitle; - this.fadeInTime = fadeInTime; - this.stayTime = stayTime; - this.fadeOutTime = fadeOutTime; - loadClasses(); + public DefaultTitleManager(String title, String subtitle, int fadeInTime, int stayTime, int fadeOutTime) { + super(title, subtitle, fadeInTime, stayTime, fadeOutTime); } private static boolean equalsTypeArray(Class[] a, Class[] o) { @@ -117,115 +38,20 @@ public class DefaultTitleManager { /** * Load spigot and NMS classes. */ - private void loadClasses() { + @Override void loadClasses() { this.packetTitle = Reflection.getNMSClass("PacketPlayOutTitle"); this.packetActions = Reflection.getNMSClass("EnumTitleAction"); this.chatBaseComponent = Reflection.getNMSClass("IChatBaseComponent"); this.nmsChatSerializer = Reflection.getNMSClass("ChatSerializer"); } - /** - * Get title text. - * - * @return Title text - */ - public String getTitle() { - return this.title; - } - - /** - * Set title text. - * - * @param title Title - */ - public void setTitle(String title) { - this.title = title; - } - - /** - * Get subtitle text. - * - * @return Subtitle text - */ - public String getSubtitle() { - return this.subtitle; - } - - /** - * Set subtitle text. - * - * @param subtitle Subtitle text - */ - public void setSubtitle(String subtitle) { - this.subtitle = subtitle; - } - - /** - * Set the title color. - * - * @param color Chat color - */ - public void setTitleColor(ChatColor color) { - this.titleColor = color; - } - - /** - * Set the subtitle color. - * - * @param color Chat color - */ - public void setSubtitleColor(ChatColor color) { - this.subtitleColor = color; - } - - /** - * Set title fade in time. - * - * @param time Time - */ - public void setFadeInTime(int time) { - this.fadeInTime = time; - } - - /** - * Set title fade out time. - * - * @param time Time - */ - public void setFadeOutTime(int time) { - this.fadeOutTime = time; - } - - /** - * Set title stay time. - * - * @param time Time - */ - public void setStayTime(int time) { - this.stayTime = time; - } - - /** - * Set timings to ticks. - */ - public void setTimingsToTicks() { - this.ticks = true; - } - - /** - * Set timings to seconds. - */ - public void setTimingsToSeconds() { - this.ticks = false; - } - /** * Send the title to a player. * * @param player Player * @throws Exception */ - public void send(Player player) throws Exception { + @Override public void send(Player player) throws Exception { if (this.packetTitle != null) { // First reset previous settings resetTitle(player); @@ -243,13 +69,14 @@ public class DefaultTitleManager { } // Send title Object serialized = getMethod(this.nmsChatSerializer, "a", String.class).invoke(null, - "{text:\"" + ChatColor.translateAlternateColorCodes('&', this.title) + "\",color:" + this.titleColor.name().toLowerCase() + "}"); + "{text:\"" + ChatColor.translateAlternateColorCodes('&', this.getTitle()) + "\",color:" + this.titleColor.name().toLowerCase() + + "}"); packet = this.packetTitle.getConstructor(this.packetActions, this.chatBaseComponent).newInstance(actions[0], serialized); sendPacket.invoke(connection, packet); - if (!this.subtitle.isEmpty()) { + if (!this.getSubtitle().isEmpty()) { // Send subtitle if present serialized = getMethod(this.nmsChatSerializer, "a", String.class).invoke(null, - "{text:\"" + ChatColor.translateAlternateColorCodes('&', this.subtitle) + "\",color:" + this.subtitleColor.name() + "{text:\"" + ChatColor.translateAlternateColorCodes('&', this.getSubtitle()) + "\",color:" + this.subtitleColor.name() .toLowerCase() + "}"); packet = this.packetTitle.getConstructor(this.packetActions, this.chatBaseComponent).newInstance(actions[1], serialized); sendPacket.invoke(connection, packet); @@ -257,24 +84,13 @@ public class DefaultTitleManager { } } - /** - * Broadcast the title to all players. - * - * @throws Exception - */ - public void broadcast() throws Exception { - for (Player p : Bukkit.getOnlinePlayers()) { - send(p); - } - } - /** * Clear the title. * * @param player Player * @throws Exception */ - public void clearTitle(Player player) throws Exception { + @Override public void clearTitle(Player player) throws Exception { // Send timings first Object handle = getHandle(player); Object connection = getField(handle.getClass(), "playerConnection").get(handle); @@ -290,7 +106,7 @@ public class DefaultTitleManager { * @param player Player * @throws Exception */ - public void resetTitle(Player player) throws Exception { + @Override public void resetTitle(Player player) throws Exception { // Send timings first Object handle = getHandle(player); Object connection = getField(handle.getClass(), "playerConnection").get(handle); @@ -300,29 +116,10 @@ public class DefaultTitleManager { sendPacket.invoke(connection, packet); } - private Class getPrimitiveType(Class clazz) { - return CORRESPONDING_TYPES.containsKey(clazz) ? CORRESPONDING_TYPES.get(clazz) : clazz; - } - - private Class[] toPrimitiveTypeArray(Class[] classes) { - int a = classes != null ? classes.length : 0; - Class[] types = new Class[a]; - for (int i = 0; i < a; i++) { - types[i] = getPrimitiveType(classes[i]); - } - return types; - } - private Object getHandle(Object obj) { try { return getMethod("getHandle", obj.getClass()).invoke(obj); - } catch (IllegalAccessException e) { - e.printStackTrace(); - return null; - } catch (IllegalArgumentException e) { - e.printStackTrace(); - return null; - } catch (InvocationTargetException e) { + } catch (IllegalAccessException | IllegalArgumentException | InvocationTargetException e) { e.printStackTrace(); return null; } @@ -344,10 +141,7 @@ public class DefaultTitleManager { Field field = clazz.getDeclaredField(name); field.setAccessible(true); return field; - } catch (NoSuchFieldException e) { - e.printStackTrace(); - return null; - } catch (SecurityException e) { + } catch (NoSuchFieldException | SecurityException e) { e.printStackTrace(); return null; } diff --git a/Bukkit/src/main/java/com/plotsquared/bukkit/titles/DefaultTitleManager_183.java b/Bukkit/src/main/java/com/plotsquared/bukkit/titles/DefaultTitleManager_183.java index e0ee10b99..609d10fd4 100644 --- a/Bukkit/src/main/java/com/plotsquared/bukkit/titles/DefaultTitleManager_183.java +++ b/Bukkit/src/main/java/com/plotsquared/bukkit/titles/DefaultTitleManager_183.java @@ -1,87 +1,13 @@ package com.plotsquared.bukkit.titles; import com.plotsquared.bukkit.chat.Reflection; -import org.bukkit.Bukkit; import org.bukkit.ChatColor; import org.bukkit.entity.Player; import java.lang.reflect.Field; import java.lang.reflect.Method; -import java.util.HashMap; -import java.util.Map; -/** - * [ PlotSquared DefaultTitleManager by Maxim Van de Wynckel ] - * - * @version 1.1.0 - * @author Maxim Van de Wynckel - * - */ -public class DefaultTitleManager_183 { - - private static final Map, Class> CORRESPONDING_TYPES = new HashMap<>(); - /* Title packet */ - private Class packetTitle; - /* Title packet actions ENUM */ - private Class packetActions; - /* Chat serializer */ - private Class nmsChatSerializer; - private Class chatBaseComponent; - /* Title text and color */ - private String title = ""; - private ChatColor titleColor = ChatColor.WHITE; - /* Subtitle text and color */ - private String subtitle = ""; - private ChatColor subtitleColor = ChatColor.WHITE; - /* Title timings */ - private int fadeInTime = -1; - private int stayTime = -1; - private int fadeOutTime = -1; - private boolean ticks = false; - - /** - * Create a new 1.8 title - * - * @param title - * Title - * @throws ClassNotFoundException - */ - public DefaultTitleManager_183(String title) throws ClassNotFoundException { - this.title = title; - loadClasses(); - } - - /** - * Create a new 1.8 title. - * - * @param title Title text - * @param subtitle Subtitle text - * @throws ClassNotFoundException - */ - public DefaultTitleManager_183(String title, String subtitle) throws ClassNotFoundException { - this.title = title; - this.subtitle = subtitle; - loadClasses(); - } - - /** - * Copy 1.8 title. - * - * @param title Title - * @throws ClassNotFoundException - */ - public DefaultTitleManager_183(DefaultTitleManager_183 title) throws ClassNotFoundException { - // Copy title - this.title = title.title; - this.subtitle = title.subtitle; - this.titleColor = title.titleColor; - this.subtitleColor = title.subtitleColor; - this.fadeInTime = title.fadeInTime; - this.fadeOutTime = title.fadeOutTime; - this.stayTime = title.stayTime; - this.ticks = title.ticks; - loadClasses(); - } +public class DefaultTitleManager_183 extends TitleManager { /** * Create a new 1.8 title. @@ -91,15 +17,9 @@ public class DefaultTitleManager_183 { * @param fadeInTime Fade in time * @param stayTime Stay on screen time * @param fadeOutTime Fade out time - * @throws ClassNotFoundException */ - public DefaultTitleManager_183(String title, String subtitle, int fadeInTime, int stayTime, int fadeOutTime) throws ClassNotFoundException { - this.title = title; - this.subtitle = subtitle; - this.fadeInTime = fadeInTime; - this.stayTime = stayTime; - this.fadeOutTime = fadeOutTime; - loadClasses(); + public DefaultTitleManager_183(String title, String subtitle, int fadeInTime, int stayTime, int fadeOutTime) { + super(title, subtitle, fadeInTime, stayTime, fadeOutTime); } private static boolean equalsTypeArray(Class[] a, Class[] o) { @@ -117,7 +37,8 @@ public class DefaultTitleManager_183 { /** * Load spigot and NMS classes. */ - private void loadClasses() { + @Override + void loadClasses() { this.packetTitle = Reflection.getNMSClass("PacketPlayOutTitle"); this.chatBaseComponent = Reflection.getNMSClass("IChatBaseComponent"); this.packetActions = Reflection.getNMSClass("PacketPlayOutTitle$EnumTitleAction"); @@ -125,108 +46,7 @@ public class DefaultTitleManager_183 { } - /** - * Get title text. - * - * @return Title text - */ - public String getTitle() { - return this.title; - } - - /** - * Set title text. - * - * @param title Title - */ - public void setTitle(String title) { - this.title = title; - } - - /** - * Get subtitle text. - * - * @return Subtitle text - */ - public String getSubtitle() { - return this.subtitle; - } - - /** - * Set subtitle text. - * - * @param subtitle Subtitle text - */ - public void setSubtitle(String subtitle) { - this.subtitle = subtitle; - } - - /** - * Set the title color. - * - * @param color Chat color - */ - public void setTitleColor(ChatColor color) { - this.titleColor = color; - } - - /** - * Set the subtitle color. - * - * @param color Chat color - */ - public void setSubtitleColor(ChatColor color) { - this.subtitleColor = color; - } - - /** - * Set title fade in time. - * - * @param time - * Time - */ - public void setFadeInTime(int time) { - this.fadeInTime = time; - } - - /** - * Set title fade out time. - * - * @param time Time - */ - public void setFadeOutTime(int time) { - this.fadeOutTime = time; - } - - /** - * Set title stay time. - * - * @param time Time - */ - public void setStayTime(int time) { - this.stayTime = time; - } - - /** - * Set timings to ticks. - */ - public void setTimingsToTicks() { - this.ticks = true; - } - - /** - * Set timings to seconds. - */ - public void setTimingsToSeconds() { - this.ticks = false; - } - - /** - * Send the title to a player. - * - * @param player Player - * @throws Exception - */ + @Override public void send(Player player) throws Exception { if (this.packetTitle != null) { // First reset previous settings @@ -247,13 +67,14 @@ public class DefaultTitleManager_183 { } // Send title Object serialized = getMethod(this.nmsChatSerializer, "a", String.class).invoke(null, - "{text:\"" + ChatColor.translateAlternateColorCodes('&', this.title) + "\",color:" + this.titleColor.name().toLowerCase() + "}"); + "{text:\"" + ChatColor.translateAlternateColorCodes('&', this.getTitle()) + "\",color:" + this.titleColor.name().toLowerCase() + + "}"); packet = this.packetTitle.getConstructor(this.packetActions, this.chatBaseComponent).newInstance(actions[0], serialized); sendPacket.invoke(connection, packet); - if (!this.subtitle.isEmpty()) { + if (!this.getSubtitle().isEmpty()) { // Send subtitle if present serialized = getMethod(this.nmsChatSerializer, "a", String.class).invoke(null, - "{text:\"" + ChatColor.translateAlternateColorCodes('&', this.subtitle) + "\",color:" + this.subtitleColor.name() + "{text:\"" + ChatColor.translateAlternateColorCodes('&', this.getSubtitle()) + "\",color:" + this.subtitleColor.name() .toLowerCase() + "}"); packet = this.packetTitle.getConstructor(this.packetActions, this.chatBaseComponent).newInstance(actions[1], serialized); sendPacket.invoke(connection, packet); @@ -261,22 +82,13 @@ public class DefaultTitleManager_183 { } } - /** - * Broadcast the title to all players. - * @throws Exception - */ - public void broadcast() throws Exception { - for (Player p : Bukkit.getOnlinePlayers()) { - send(p); - } - } - /** * Clear the title. * * @param player Player * @throws Exception */ + @Override public void clearTitle(Player player) throws Exception { // Send timings first Object handle = getHandle(player); @@ -293,6 +105,7 @@ public class DefaultTitleManager_183 { * @param player Player * @throws Exception */ + @Override public void resetTitle(Player player) throws Exception { // Send timings first Object handle = getHandle(player); @@ -303,19 +116,6 @@ public class DefaultTitleManager_183 { sendPacket.invoke(connection, packet); } - private Class getPrimitiveType(Class clazz) { - return CORRESPONDING_TYPES.containsKey(clazz) ? CORRESPONDING_TYPES.get(clazz) : clazz; - } - - private Class[] toPrimitiveTypeArray(Class[] classes) { - int a = classes != null ? classes.length : 0; - Class[] types = new Class[a]; - for (int i = 0; i < a; i++) { - types[i] = getPrimitiveType(classes[i]); - } - return types; - } - private Object getHandle(Object obj) { try { return getMethod("getHandle", obj.getClass()).invoke(obj); diff --git a/Bukkit/src/main/java/com/plotsquared/bukkit/titles/DefaultTitle_183.java b/Bukkit/src/main/java/com/plotsquared/bukkit/titles/DefaultTitle_183.java index 8746cab58..386fdb3ba 100644 --- a/Bukkit/src/main/java/com/plotsquared/bukkit/titles/DefaultTitle_183.java +++ b/Bukkit/src/main/java/com/plotsquared/bukkit/titles/DefaultTitle_183.java @@ -11,7 +11,7 @@ public class DefaultTitle_183 extends AbstractTitle { try { DefaultTitleManager_183 title = new DefaultTitleManager_183(head, sub, in, delay, out); title.send(((BukkitPlayer) player).player); - } catch (Throwable e) { + } catch (Exception e) { AbstractTitle.TITLE_CLASS = new HackTitle(); AbstractTitle.TITLE_CLASS.sendTitle(player, head, sub, in, delay, out); } diff --git a/Bukkit/src/main/java/com/plotsquared/bukkit/titles/HackTitle.java b/Bukkit/src/main/java/com/plotsquared/bukkit/titles/HackTitle.java index 15ecc2dc3..c0a42bf60 100644 --- a/Bukkit/src/main/java/com/plotsquared/bukkit/titles/HackTitle.java +++ b/Bukkit/src/main/java/com/plotsquared/bukkit/titles/HackTitle.java @@ -13,7 +13,7 @@ public class HackTitle extends AbstractTitle { try { HackTitleManager title = new HackTitleManager(head, sub, in, delay, out); title.send(((BukkitPlayer) player).player); - } catch (Throwable e) { + } catch (Exception e) { PS.debug("&cYour server version does not support titles!"); Settings.TITLES = false; AbstractTitle.TITLE_CLASS = null; diff --git a/Bukkit/src/main/java/com/plotsquared/bukkit/titles/HackTitleManager.java b/Bukkit/src/main/java/com/plotsquared/bukkit/titles/HackTitleManager.java index 5fd787a86..933af3229 100644 --- a/Bukkit/src/main/java/com/plotsquared/bukkit/titles/HackTitleManager.java +++ b/Bukkit/src/main/java/com/plotsquared/bukkit/titles/HackTitleManager.java @@ -8,78 +8,8 @@ import org.bukkit.entity.Player; import java.lang.reflect.Field; import java.lang.reflect.InvocationTargetException; import java.lang.reflect.Method; -import java.util.HashMap; -import java.util.Map; -/** - * Minecraft 1.8 Title. - * - * @version 1.0.4 - * @author Maxim Van de Wynckel - */ -public class HackTitleManager { - - private static final Map, Class> CORRESPONDING_TYPES = new HashMap<>(); - /* Title packet */ - private Class packetTitle; - /* Title packet actions ENUM */ - private Class packetActions; - /* Chat serializer */ - private Class nmsChatSerializer; - /* Title text and color */ - private String title = ""; - private ChatColor titleColor = ChatColor.WHITE; - /* Subtitle text and color */ - private String subtitle = ""; - private ChatColor subtitleColor = ChatColor.WHITE; - /* Title timings. */ - private int fadeInTime = -1; - private int stayTime = -1; - private int fadeOutTime = -1; - private boolean ticks = false; - - /** - * Create a new 1.8 title. - * - * @param title Title - * @throws ClassNotFoundException NMS Error. - */ - public HackTitleManager(String title) throws ClassNotFoundException { - this.title = title; - loadClasses(); - } - - /** - * Create a new 1.8 title. - * - * @param title Title text - * @param subtitle Subtitle text - * @throws ClassNotFoundException NMS Error - */ - public HackTitleManager(String title, String subtitle) throws ClassNotFoundException { - this.title = title; - this.subtitle = subtitle; - loadClasses(); - } - - /** - * Copy 1.8 title. - * - * @param title Title - * @throws ClassNotFoundException NMS Error - */ - public HackTitleManager(HackTitleManager title) throws ClassNotFoundException { - // Copy title - this.title = title.title; - this.subtitle = title.subtitle; - this.titleColor = title.titleColor; - this.subtitleColor = title.subtitleColor; - this.fadeInTime = title.fadeInTime; - this.fadeOutTime = title.fadeOutTime; - this.stayTime = title.stayTime; - this.ticks = title.ticks; - loadClasses(); - } +public class HackTitleManager extends TitleManager { /** * Create a new 1.8 title. @@ -89,15 +19,9 @@ public class HackTitleManager { * @param fadeInTime Fade in time * @param stayTime Stay on screen time * @param fadeOutTime Fade out time - * @throws ClassNotFoundException NMS error */ - public HackTitleManager(String title, String subtitle, int fadeInTime, int stayTime, int fadeOutTime) throws ClassNotFoundException { - this.title = title; - this.subtitle = subtitle; - this.fadeInTime = fadeInTime; - this.stayTime = stayTime; - this.fadeOutTime = fadeOutTime; - loadClasses(); + public HackTitleManager(String title, String subtitle, int fadeInTime, int stayTime, int fadeOutTime) { + super(title, subtitle, fadeInTime, stayTime, fadeOutTime); } private static boolean equalsTypeArray(Class[] a, Class[] o) { @@ -115,114 +39,20 @@ public class HackTitleManager { /** * Load spigot and NMS classes. */ - private void loadClasses() { + @Override + void loadClasses() { this.packetTitle = getClass("org.spigotmc.ProtocolInjector$PacketTitle"); this.packetActions = getClass("org.spigotmc.ProtocolInjector$PacketTitle$Action"); this.nmsChatSerializer = Reflection.getNMSClass("ChatSerializer"); } - /** - * Get title text. - * - * @return Title text - */ - public String getTitle() { - return this.title; - } - - /** - * Set title text. - * - * @param title Title - */ - public void setTitle(String title) { - this.title = title; - } - - /** - * Get subtitle text. - * - * @return Subtitle text - */ - public String getSubtitle() { - return this.subtitle; - } - - /** - * Set subtitle text. - * - * @param subtitle Subtitle text - */ - public void setSubtitle(String subtitle) { - this.subtitle = subtitle; - } - - /** - * Set the title color. - * - * @param color Chat color - */ - public void setTitleColor(ChatColor color) { - this.titleColor = color; - } - - /** - * Set the subtitle color. - * - * @param color Chat color - */ - public void setSubtitleColor(ChatColor color) { - this.subtitleColor = color; - } - - /** - * Set title fade in time. - * - * @param time Time - */ - public void setFadeInTime(int time) { - this.fadeInTime = time; - } - - /** - * Set title fade out time. - * - * @param time Time - */ - public void setFadeOutTime(int time) { - this.fadeOutTime = time; - } - - /** - * Set title stay time. - * - * @param time Time - */ - public void setStayTime(int time) { - this.stayTime = time; - } - - /** - * Set timings to ticks. - */ - public void setTimingsToTicks() { - this.ticks = true; - } - - /** - * Set timings to seconds. - */ - public void setTimingsToSeconds() { - this.ticks = false; - } - /** * Send the title to a player. * * @param player Player * @throws Exception on NMS error */ - public void send(Player player) throws Exception { + @Override public void send(Player player) throws Exception { if ((getProtocolVersion(player) >= 47) && isSpigot() && (this.packetTitle != null)) { // First reset previous settings resetTitle(player); @@ -241,14 +71,15 @@ public class HackTitleManager { } // Send title Object serialized = getMethod(this.nmsChatSerializer, "a", String.class).invoke(null, - "{text:\"" + ChatColor.translateAlternateColorCodes('&', this.title) + "\",color:" + this.titleColor.name().toLowerCase() + "}"); + "{text:\"" + ChatColor.translateAlternateColorCodes('&', this.getTitle()) + "\",color:" + this.titleColor.name().toLowerCase() + + "}"); packet = this.packetTitle.getConstructor(this.packetActions, Reflection.getNMSClass("IChatBaseComponent")) .newInstance(actions[0], serialized); sendPacket.invoke(connection, packet); - if (!this.subtitle.isEmpty()) { + if (!this.getSubtitle().isEmpty()) { // Send subtitle if present serialized = getMethod(this.nmsChatSerializer, "a", String.class).invoke(null, - "{text:\"" + ChatColor.translateAlternateColorCodes('&', this.subtitle) + "\",color:" + this.subtitleColor.name() + "{text:\"" + ChatColor.translateAlternateColorCodes('&', this.getSubtitle()) + "\",color:" + this.subtitleColor.name() .toLowerCase() + "}"); packet = this.packetTitle.getConstructor(this.packetActions, Reflection.getNMSClass("IChatBaseComponent")) .newInstance(actions[1], serialized); @@ -257,23 +88,13 @@ public class HackTitleManager { } } - /** - * Broadcast the title to all players. - * @throws Exception on NMS Error - */ - public void broadcast() throws Exception { - for (Player p : Bukkit.getOnlinePlayers()) { - send(p); - } - } - /** * Clear the title. * * @param player Player * @throws Exception on NMS Error */ - public void clearTitle(Player player) throws Exception { + @Override public void clearTitle(Player player) throws Exception { if ((getProtocolVersion(player) >= 47) && isSpigot()) { // Send timings first Object handle = getHandle(player); @@ -291,7 +112,7 @@ public class HackTitleManager { * @param player Player * @throws Exception on NMS error. */ - public void resetTitle(Player player) throws Exception { + @Override public void resetTitle(Player player) throws Exception { if ((getProtocolVersion(player) >= 47) && isSpigot()) { // Send timings first Object handle = getHandle(player); @@ -350,19 +171,6 @@ public class HackTitleManager { return f.get(obj); } - private Class getPrimitiveType(Class clazz) { - return CORRESPONDING_TYPES.containsKey(clazz) ? CORRESPONDING_TYPES.get(clazz) : clazz; - } - - private Class[] toPrimitiveTypeArray(Class[] classes) { - int a = classes != null ? classes.length : 0; - Class[] types = new Class[a]; - for (int i = 0; i < a; i++) { - types[i] = getPrimitiveType(classes[i]); - } - return types; - } - private Object getHandle(Object obj) { try { return getMethod("getHandle", obj.getClass()).invoke(obj); diff --git a/Bukkit/src/main/java/com/plotsquared/bukkit/titles/TitleManager.java b/Bukkit/src/main/java/com/plotsquared/bukkit/titles/TitleManager.java new file mode 100644 index 000000000..bd2e0ee84 --- /dev/null +++ b/Bukkit/src/main/java/com/plotsquared/bukkit/titles/TitleManager.java @@ -0,0 +1,204 @@ +package com.plotsquared.bukkit.titles; + +import org.bukkit.Bukkit; +import org.bukkit.ChatColor; +import org.bukkit.entity.Player; + +import java.util.HashMap; +import java.util.Map; + +public abstract class TitleManager { + + private static final Map, Class> CORRESPONDING_TYPES = new HashMap<>(); + /* Title packet */ + Class packetTitle; + /* Title packet actions ENUM */ + Class packetActions; + /* Chat serializer */ + Class nmsChatSerializer; + Class chatBaseComponent; + ChatColor titleColor = ChatColor.WHITE; + ChatColor subtitleColor = ChatColor.WHITE; + /* Title timings */ + int fadeInTime = -1; + int stayTime = -1; + int fadeOutTime = -1; + boolean ticks = false; + /* Title text and color */ + private String title = ""; + /* Subtitle text and color */ + private String subtitle = ""; + + /** + * Create a new 1.8 title. + * + * @param title Title text + * @param subtitle Subtitle text + * @param fadeInTime Fade in time + * @param stayTime Stay on screen time + * @param fadeOutTime Fade out time + */ + TitleManager(String title, String subtitle, int fadeInTime, int stayTime, int fadeOutTime) { + this.title = title; + this.subtitle = subtitle; + this.fadeInTime = fadeInTime; + this.stayTime = stayTime; + this.fadeOutTime = fadeOutTime; + loadClasses(); + } + + abstract void loadClasses(); + + /** + * Get title text. + * + * @return Title text + */ + public final String getTitle() { + return this.title; + } + + /** + * Set title text. + * + * @param title Title + */ + public final void setTitle(String title) { + this.title = title; + } + + /** + * Get subtitle text. + * + * @return Subtitle text + */ + public final String getSubtitle() { + return this.subtitle; + } + + /** + * Set subtitle text. + * + * @param subtitle Subtitle text + */ + public final void setSubtitle(String subtitle) { + this.subtitle = subtitle; + } + + /** + * Set the title color. + * + * @param color Chat color + */ + public final void setTitleColor(ChatColor color) { + this.titleColor = color; + } + + /** + * Set the subtitle color. + * + * @param color Chat color + */ + public final void setSubtitleColor(ChatColor color) { + this.subtitleColor = color; + } + + /** + * Set title fade in time. + * + * @param time Time + */ + public final void setFadeInTime(int time) { + this.fadeInTime = time; + } + + /** + * Set title fade out time. + * + * @param time Time + */ + public final void setFadeOutTime(int time) { + this.fadeOutTime = time; + } + + /** + * Set title stay time. + * + * @param time Time + */ + public final void setStayTime(int time) { + this.stayTime = time; + } + + /** + * Set timings to ticks. + */ + public final void setTimingsToTicks() { + this.ticks = true; + } + + /** + * Set timings to seconds. + */ + public final void setTimingsToSeconds() { + this.ticks = false; + } + + /** + * Send the title to a player. + * + * @param player Player + * @throws Exception + */ + public abstract void send(Player player) throws Exception; + + /** + * Broadcast the title to all players. + * + * @throws Exception + */ + public final void broadcast() throws Exception { + for (Player p : Bukkit.getOnlinePlayers()) { + send(p); + } + } + + /** + * Clear the title. + * + * @param player Player + * @throws Exception + */ + public abstract void clearTitle(Player player) throws Exception; + + /** + * Reset the title settings. + * + * @param player Player + * @throws Exception + */ + public abstract void resetTitle(Player player) throws Exception; + + private Class getPrimitiveType(Class clazz) { + if (CORRESPONDING_TYPES.containsKey(clazz)) { + return CORRESPONDING_TYPES.get(clazz); + } else { + return clazz; + } + } + + final Class[] toPrimitiveTypeArray(Class[] classes) { + int a; + if (classes != null) { + a = classes.length; + } else { + a = 0; + } + Class[] types = new Class[a]; + for (int i = 0; i < a; i++) { + types[i] = getPrimitiveType(classes[i]); + } + return types; + } + +} diff --git a/Bukkit/src/main/java/com/plotsquared/bukkit/util/BukkitChatManager.java b/Bukkit/src/main/java/com/plotsquared/bukkit/util/BukkitChatManager.java index 626c100b7..f9bcb4b17 100644 --- a/Bukkit/src/main/java/com/plotsquared/bukkit/util/BukkitChatManager.java +++ b/Bukkit/src/main/java/com/plotsquared/bukkit/util/BukkitChatManager.java @@ -45,7 +45,7 @@ public class BukkitChatManager extends ChatManager { @Override public void send(PlotMessage m, PlotPlayer player) { - if (ConsolePlayer.isConsole(player)) { + if (player instanceof ConsolePlayer) { player.sendMessage(m.$(this).toOldMessageFormat()); } else { m.$(this).send(((BukkitPlayer) player).player); diff --git a/Bukkit/src/main/java/com/plotsquared/bukkit/util/BukkitChunkManager.java b/Bukkit/src/main/java/com/plotsquared/bukkit/util/BukkitChunkManager.java index 0829e123f..30b8e3b25 100644 --- a/Bukkit/src/main/java/com/plotsquared/bukkit/util/BukkitChunkManager.java +++ b/Bukkit/src/main/java/com/plotsquared/bukkit/util/BukkitChunkManager.java @@ -20,14 +20,6 @@ import com.intellectualcrafters.plot.util.TaskManager; import com.intellectualcrafters.plot.util.UUIDHandler; import com.intellectualcrafters.plot.util.WorldUtil; import com.plotsquared.bukkit.object.entity.EntityWrapper; -import java.util.ArrayDeque; -import java.util.ArrayList; -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 org.bukkit.Bukkit; import org.bukkit.Chunk; import org.bukkit.DyeColor; @@ -60,545 +52,17 @@ import org.bukkit.entity.Player; import org.bukkit.inventory.InventoryHolder; import org.bukkit.inventory.ItemStack; +import java.util.ArrayDeque; +import java.util.ArrayList; +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; + public class BukkitChunkManager extends ChunkManager { - public static class ContentMap { - public HashMap chestContents; - public HashMap furnaceContents; - public HashMap dispenserContents; - public HashMap dropperContents; - public HashMap brewingStandContents; - public HashMap beaconContents; - public HashMap hopperContents; - public HashMap furnaceTime; - public HashMap skullData; - public HashMap jukeboxDisc; - public HashMap brewTime; - public HashMap spawnerData; - public HashMap cmdData; - public HashMap signContents; - public HashMap noteBlockContents; - public HashMap> bannerPatterns; - public HashMap bannerBase; - public HashSet entities; - public HashMap allBlocks; - - public ContentMap() { - chestContents = new HashMap<>(); - furnaceContents = new HashMap<>(); - dispenserContents = new HashMap<>(); - dropperContents = new HashMap<>(); - brewingStandContents = new HashMap<>(); - beaconContents = new HashMap<>(); - hopperContents = new HashMap<>(); - furnaceTime = new HashMap<>(); - skullData = new HashMap<>(); - brewTime = new HashMap<>(); - jukeboxDisc = new HashMap<>(); - spawnerData = new HashMap<>(); - noteBlockContents = new HashMap<>(); - signContents = new HashMap<>(); - cmdData = new HashMap<>(); - bannerBase = new HashMap<>(); - bannerPatterns = new HashMap<>(); - entities = new HashSet<>(); - allBlocks = new HashMap<>(); - } - - public void saveRegion(World world, int x1, int x2, int z1, int z2) { - if (z1 > z2) { - int tmp = z1; - z1 = z2; - z2 = tmp; - } - if (x1 > x2) { - int tmp = x1; - x1 = x2; - x2 = tmp; - } - for (int x = x1; x <= x2; x++) { - for (int z = z1; z <= z2; z++) { - saveBlocks(world, 256, x, z, 0, 0, true); - } - } - } - - public void saveEntitiesIn(Chunk chunk, RegionWrapper region) { - saveEntitiesIn(chunk, region, 0, 0, false); - } - - public void saveEntitiesOut(Chunk chunk, RegionWrapper region) { - for (Entity entity : chunk.getEntities()) { - Location loc = BukkitUtil.getLocation(entity); - int x = loc.getX(); - int z = loc.getZ(); - if (isIn(region, x, z)) { - continue; - } - if (entity.getVehicle() != null) { - continue; - } - EntityWrapper wrap = new EntityWrapper(entity, (short) 2); - entities.add(wrap); - } - } - - public void saveEntitiesIn(Chunk chunk, RegionWrapper region, int offsetX, int offsetZ, boolean delete) { - for (Entity entity : chunk.getEntities()) { - Location loc = BukkitUtil.getLocation(entity); - int x = loc.getX(); - int z = loc.getZ(); - if (!isIn(region, x, z)) { - continue; - } - if (entity.getVehicle() != null) { - continue; - } - EntityWrapper wrap = new EntityWrapper(entity, (short) 2); - wrap.x += offsetX; - wrap.z += offsetZ; - entities.add(wrap); - if (delete) { - if (!(entity instanceof Player)) { - entity.remove(); - } - } - } - } - - public void restoreEntities(World world, int xOffset, int zOffset) { - for (EntityWrapper entity : entities) { - try { - entity.spawn(world, xOffset, zOffset); - } catch (Exception e) { - PS.debug("Failed to restore entity (e): " + entity.x + "," + entity.y + "," + entity.z + " : " + entity.type); - e.printStackTrace(); - } - } - entities.clear(); - } - - public void restoreBlocks(World world, int xOffset, int zOffset) { - for (Entry blockLocEntry : chestContents.entrySet()) { - try { - Block block = - world.getBlockAt(blockLocEntry.getKey().x + xOffset, blockLocEntry.getKey().y, blockLocEntry.getKey().z + zOffset); - BlockState state = block.getState(); - if (state instanceof InventoryHolder) { - InventoryHolder chest = (InventoryHolder) state; - chest.getInventory().setContents(blockLocEntry.getValue()); - state.update(true); - } else { - PS.debug("&c[WARN] Plot clear failed to regenerate chest: " + (blockLocEntry.getKey().x + xOffset) + "," + blockLocEntry - .getKey().y + "," + (blockLocEntry.getKey().z + zOffset)); - } - } catch (IllegalArgumentException e) { - PS.debug("&c[WARN] Plot clear failed to regenerate chest (e): " + (blockLocEntry.getKey().x + xOffset) + "," + blockLocEntry - .getKey().y + "," + (blockLocEntry.getKey().z + zOffset)); - } - } - for (Entry blockLocEntry : signContents.entrySet()) { - try { - Block block = - world.getBlockAt(blockLocEntry.getKey().x + xOffset, blockLocEntry.getKey().y, blockLocEntry.getKey().z + zOffset); - BlockState state = block.getState(); - if (state instanceof Sign) { - Sign sign = (Sign) state; - int i = 0; - for (String line : blockLocEntry.getValue()) { - sign.setLine(i, line); - i++; - } - state.update(true); - } else { - PS.debug( - "&c[WARN] Plot clear failed to regenerate sign: " + (blockLocEntry.getKey().x + xOffset) + "," + blockLocEntry.getKey().y - + "," + ( - blockLocEntry.getKey().z + zOffset)); - } - } catch (IndexOutOfBoundsException e) { - PS.debug("&c[WARN] Plot clear failed to regenerate sign: " + (blockLocEntry.getKey().x + xOffset) + "," + blockLocEntry.getKey().y - + "," + ( - blockLocEntry.getKey().z + zOffset)); - } - } - for (Entry blockLocEntry : dispenserContents.entrySet()) { - try { - Block block = - world.getBlockAt(blockLocEntry.getKey().x + xOffset, blockLocEntry.getKey().y, blockLocEntry.getKey().z + zOffset); - BlockState state = block.getState(); - if (state instanceof Dispenser) { - ((InventoryHolder) state).getInventory().setContents(blockLocEntry.getValue()); - state.update(true); - } else { - PS.debug("&c[WARN] Plot clear failed to regenerate dispenser: " + (blockLocEntry.getKey().x + xOffset) + "," + blockLocEntry - .getKey().y + "," + (blockLocEntry.getKey().z + zOffset)); - } - } catch (IllegalArgumentException e) { - PS.debug("&c[WARN] Plot clear failed to regenerate dispenser (e): " + (blockLocEntry.getKey().x + xOffset) + "," + blockLocEntry - .getKey().y + "," + (blockLocEntry.getKey().z + zOffset)); - } - } - for (Entry blockLocEntry : dropperContents.entrySet()) { - try { - Block block = - world.getBlockAt(blockLocEntry.getKey().x + xOffset, blockLocEntry.getKey().y, blockLocEntry.getKey().z + zOffset); - BlockState state = block.getState(); - if (state instanceof Dropper) { - ((InventoryHolder) state).getInventory().setContents(blockLocEntry.getValue()); - state.update(true); - } else { - PS.debug("&c[WARN] Plot clear failed to regenerate dispenser: " + (blockLocEntry.getKey().x + xOffset) + "," + blockLocEntry - .getKey().y + "," + (blockLocEntry.getKey().z + zOffset)); - } - } catch (IllegalArgumentException e) { - PS.debug("&c[WARN] Plot clear failed to regenerate dispenser (e): " + (blockLocEntry.getKey().x + xOffset) + "," + blockLocEntry - .getKey().y + "," + (blockLocEntry.getKey().z + zOffset)); - } - } - for (Entry blockLocEntry : beaconContents.entrySet()) { - try { - Block block = - world.getBlockAt(blockLocEntry.getKey().x + xOffset, blockLocEntry.getKey().y, blockLocEntry.getKey().z + zOffset); - BlockState state = block.getState(); - if (state instanceof Beacon) { - ((InventoryHolder) state).getInventory().setContents(blockLocEntry.getValue()); - state.update(true); - } else { - PS.debug("&c[WARN] Plot clear failed to regenerate beacon: " + (blockLocEntry.getKey().x + xOffset) + "," + blockLocEntry - .getKey().y + "," + (blockLocEntry.getKey().z + zOffset)); - } - } catch (IllegalArgumentException e) { - PS.debug("&c[WARN] Plot clear failed to regenerate beacon (e): " + (blockLocEntry.getKey().x + xOffset) + "," + blockLocEntry - .getKey().y + "," + (blockLocEntry.getKey().z + zOffset)); - } - } - for (Entry blockLocMaterialEntry : jukeboxDisc.entrySet()) { - try { - Block block = - world.getBlockAt(blockLocMaterialEntry.getKey().x + xOffset, blockLocMaterialEntry.getKey().y, blockLocMaterialEntry - .getKey().z + zOffset); - BlockState state = block.getState(); - if (state instanceof Jukebox) { - ((Jukebox) state).setPlaying(blockLocMaterialEntry.getValue()); - state.update(true); - } else { - PS.debug("&c[WARN] Plot clear failed to restore jukebox: " + (blockLocMaterialEntry.getKey().x + xOffset) + "," - + blockLocMaterialEntry - .getKey().y + "," + ( - blockLocMaterialEntry.getKey().z + zOffset)); - } - } catch (Exception e) { - PS.debug("&c[WARN] Plot clear failed to regenerate jukebox (e): " + (blockLocMaterialEntry.getKey().x + xOffset) + "," - + blockLocMaterialEntry - .getKey().y + "," + ( - blockLocMaterialEntry.getKey().z + zOffset)); - } - } - for (Entry blockLocEntry : skullData.entrySet()) { - try { - Block block = - world.getBlockAt(blockLocEntry.getKey().x + xOffset, blockLocEntry.getKey().y, blockLocEntry.getKey().z + zOffset); - BlockState state = block.getState(); - if (state instanceof Skull) { - Object[] data = blockLocEntry.getValue(); - if (data[0] != null) { - ((Skull) state).setOwner((String) data[0]); - } - if ((Integer) data[1] != 0) { - ((Skull) state).setRotation(BlockFace.values()[(int) data[1]]); - } - if ((Integer) data[2] != 0) { - ((Skull) state).setSkullType(SkullType.values()[(int) data[2]]); - } - state.update(true); - } else { - PS.debug("&c[WARN] Plot clear failed to restore skull: " + (blockLocEntry.getKey().x + xOffset) + "," + blockLocEntry.getKey().y - + "," + ( - blockLocEntry.getKey().z + zOffset)); - } - } catch (Exception e) { - PS.debug("&c[WARN] Plot clear failed to regenerate skull (e): " + (blockLocEntry.getKey().x + xOffset) + "," + blockLocEntry - .getKey().y + "," + (blockLocEntry.getKey().z + zOffset)); - } - } - for (Entry blockLocEntry : hopperContents.entrySet()) { - try { - Block block = - world.getBlockAt(blockLocEntry.getKey().x + xOffset, blockLocEntry.getKey().y, blockLocEntry.getKey().z + zOffset); - BlockState state = block.getState(); - if (state instanceof Hopper) { - ((InventoryHolder) state).getInventory().setContents(blockLocEntry.getValue()); - state.update(true); - } else { - PS.debug("&c[WARN] Plot clear failed to regenerate hopper: " + (blockLocEntry.getKey().x + xOffset) + "," + blockLocEntry - .getKey().y + "," + (blockLocEntry.getKey().z + zOffset)); - } - } catch (IllegalArgumentException e) { - PS.debug("&c[WARN] Plot clear failed to regenerate hopper (e): " + (blockLocEntry.getKey().x + xOffset) + "," + blockLocEntry - .getKey().y + "," + (blockLocEntry.getKey().z + zOffset)); - } - } - for (Entry blockLocNoteEntry : noteBlockContents.entrySet()) { - try { - Block block = world.getBlockAt( - blockLocNoteEntry.getKey().x + xOffset, blockLocNoteEntry.getKey().y, blockLocNoteEntry.getKey().z + zOffset); - BlockState state = block.getState(); - if (state instanceof NoteBlock) { - ((NoteBlock) state).setNote(blockLocNoteEntry.getValue()); - state.update(true); - } else { - PS.debug("&c[WARN] Plot clear failed to regenerate note block: " + (blockLocNoteEntry.getKey().x + xOffset) + "," - + blockLocNoteEntry - .getKey().y + "," + ( - blockLocNoteEntry.getKey().z + zOffset)); - } - } catch (Exception e) { - PS.debug("&c[WARN] Plot clear failed to regenerate note block (e): " + (blockLocNoteEntry.getKey().x + xOffset) + "," - + blockLocNoteEntry - .getKey().y + "," + ( - blockLocNoteEntry.getKey().z + zOffset)); - } - } - for (Entry blockLocShortEntry : brewTime.entrySet()) { - try { - Block block = world.getBlockAt( - blockLocShortEntry.getKey().x + xOffset, blockLocShortEntry.getKey().y, blockLocShortEntry.getKey().z + zOffset); - BlockState state = block.getState(); - if (state instanceof BrewingStand) { - ((BrewingStand) state).setBrewingTime(blockLocShortEntry.getValue()); - } else { - PS.debug("&c[WARN] Plot clear failed to restore brewing stand cooking: " + (blockLocShortEntry.getKey().x + xOffset) + "," - + blockLocShortEntry - .getKey().y + "," + ( - blockLocShortEntry.getKey().z + zOffset)); - } - } catch (Exception e) { - PS.debug("&c[WARN] Plot clear failed to restore brewing stand cooking (e): " + (blockLocShortEntry.getKey().x + xOffset) + "," - + blockLocShortEntry.getKey().y + "," + (blockLocShortEntry.getKey().z + zOffset)); - } - } - for (Entry blockLocEntityTypeEntry : spawnerData.entrySet()) { - try { - Block block = - world.getBlockAt(blockLocEntityTypeEntry.getKey().x + xOffset, blockLocEntityTypeEntry.getKey().y, blockLocEntityTypeEntry - .getKey().z + zOffset); - BlockState state = block.getState(); - if (state instanceof CreatureSpawner) { - ((CreatureSpawner) state).setSpawnedType(blockLocEntityTypeEntry.getValue()); - state.update(true); - } else { - PS.debug("&c[WARN] Plot clear failed to restore spawner type: " + (blockLocEntityTypeEntry.getKey().x + xOffset) + "," - + blockLocEntityTypeEntry - .getKey().y + "," + ( - blockLocEntityTypeEntry.getKey().z + zOffset)); - } - } catch (Exception e) { - PS.debug("&c[WARN] Plot clear failed to restore spawner type (e): " + (blockLocEntityTypeEntry.getKey().x + xOffset) + "," - + blockLocEntityTypeEntry.getKey().y + "," + (blockLocEntityTypeEntry.getKey().z + zOffset)); - } - } - for (Entry blockLocStringEntry : cmdData.entrySet()) { - try { - Block block = world.getBlockAt( - blockLocStringEntry.getKey().x + xOffset, blockLocStringEntry.getKey().y, blockLocStringEntry.getKey().z + zOffset); - BlockState state = block.getState(); - if (state instanceof CommandBlock) { - ((CommandBlock) state).setCommand(blockLocStringEntry.getValue()); - state.update(true); - } else { - PS.debug("&c[WARN] Plot clear failed to restore command block: " + (blockLocStringEntry.getKey().x + xOffset) + "," - + blockLocStringEntry - .getKey().y + "," + ( - blockLocStringEntry.getKey().z + zOffset)); - } - } catch (Exception e) { - PS.debug("&c[WARN] Plot clear failed to restore command block (e): " + (blockLocStringEntry.getKey().x + xOffset) + "," - + blockLocStringEntry - .getKey().y + "," + ( - blockLocStringEntry.getKey().z + zOffset)); - } - } - for (Entry blockLocEntry : brewingStandContents.entrySet()) { - try { - Block block = - world.getBlockAt(blockLocEntry.getKey().x + xOffset, blockLocEntry.getKey().y, blockLocEntry.getKey().z + zOffset); - BlockState state = block.getState(); - if (state instanceof BrewingStand) { - ((InventoryHolder) state).getInventory().setContents(blockLocEntry.getValue()); - state.update(true); - } else { - PS.debug("&c[WARN] Plot clear failed to regenerate brewing stand: " + (blockLocEntry.getKey().x + xOffset) + "," + blockLocEntry - .getKey().y + "," + ( - blockLocEntry.getKey().z - + zOffset)); - } - } catch (IllegalArgumentException e) { - PS.debug("&c[WARN] Plot clear failed to regenerate brewing stand (e): " + (blockLocEntry.getKey().x + xOffset) + "," + blockLocEntry - .getKey().y + "," + ( - blockLocEntry.getKey().z - + zOffset)); - } - } - for (Entry blockLocEntry : furnaceTime.entrySet()) { - try { - Block block = - world.getBlockAt(blockLocEntry.getKey().x + xOffset, blockLocEntry.getKey().y, blockLocEntry.getKey().z + zOffset); - BlockState state = block.getState(); - if (state instanceof Furnace) { - Short[] time = blockLocEntry.getValue(); - ((Furnace) state).setBurnTime(time[0]); - ((Furnace) state).setCookTime(time[1]); - } else { - PS.debug("&c[WARN] Plot clear failed to restore furnace cooking: " + (blockLocEntry.getKey().x + xOffset) + "," + blockLocEntry - .getKey().y + "," + ( - blockLocEntry.getKey().z + zOffset)); - } - } catch (Exception e) { - PS.debug("&c[WARN] Plot clear failed to restore furnace cooking (e): " + (blockLocEntry.getKey().x + xOffset) + "," + blockLocEntry - .getKey().y + "," + ( - blockLocEntry.getKey().z + zOffset)); - } - } - for (Entry blockLocEntry : furnaceContents.entrySet()) { - try { - Block block = - world.getBlockAt(blockLocEntry.getKey().x + xOffset, blockLocEntry.getKey().y, blockLocEntry.getKey().z + zOffset); - BlockState state = block.getState(); - if (state instanceof Furnace) { - ((InventoryHolder) state).getInventory().setContents(blockLocEntry.getValue()); - state.update(true); - } else { - PS.debug("&c[WARN] Plot clear failed to regenerate furnace: " + (blockLocEntry.getKey().x + xOffset) + "," + blockLocEntry - .getKey().y + "," + (blockLocEntry.getKey().z + zOffset)); - } - } catch (IllegalArgumentException e) { - PS.debug("&c[WARN] Plot clear failed to regenerate furnace (e): " + (blockLocEntry.getKey().x + xOffset) + "," + blockLocEntry - .getKey().y + "," + (blockLocEntry.getKey().z + zOffset)); - } - } - for (Entry blockLocByteEntry : bannerBase.entrySet()) { - try { - Block block = world.getBlockAt( - blockLocByteEntry.getKey().x + xOffset, blockLocByteEntry.getKey().y, blockLocByteEntry.getKey().z + zOffset); - BlockState state = block.getState(); - if (state instanceof Banner) { - Banner banner = (Banner) state; - DyeColor base = blockLocByteEntry.getValue(); - List patterns = bannerPatterns.get(blockLocByteEntry.getKey()); - banner.setBaseColor(base); - banner.setPatterns(patterns); - state.update(true); - } else { - PS.debug("&c[WARN] Plot clear failed to regenerate banner: " + (blockLocByteEntry.getKey().x + xOffset) + "," + blockLocByteEntry - .getKey().y + "," + ( - blockLocByteEntry.getKey().z + zOffset)); - } - } catch (Exception e) { - PS.debug("&c[WARN] Plot clear failed to regenerate banner (e): " + (blockLocByteEntry.getKey().x + xOffset) + "," + blockLocByteEntry - .getKey().y + "," + ( - blockLocByteEntry.getKey().z + zOffset)); - } - } - } - - public void saveBlocks(World world, int maxY, int x, int z, int offsetX, int offsetZ, boolean storeNormal) { - maxY = Math.min(255, maxY); - PlotBlock[] ids; - if (storeNormal) { - ids = new PlotBlock[maxY + 1]; - } else { - ids = null; - } - for (short y = 0; y <= maxY; y++) { - Block block = world.getBlockAt(x, y, z); - Material id = block.getType(); - if (storeNormal) { - int typeId = id.getId(); - ids[y] = new PlotBlock((short) typeId, typeId == 0 ? 0 : block.getData()); - } - if (!id.equals(Material.AIR)) { - try { - BlockLoc bl = new BlockLoc(x + offsetX, y, z + offsetZ); - if (block.getState() instanceof InventoryHolder) { - InventoryHolder inventoryHolder = (InventoryHolder) block.getState(); - ItemStack[] inventory = inventoryHolder.getInventory().getContents().clone(); - if (id == Material.CHEST) { - chestContents.put(bl, inventory); - } else if (id == Material.DISPENSER) { - dispenserContents.put(bl, inventory); - } else if (id == Material.BEACON) { - beaconContents.put(bl, inventory); - } else if (id == Material.DROPPER) { - dropperContents.put(bl, inventory); - } else if (id == Material.HOPPER) { - hopperContents.put(bl, inventory); - } else if (id == Material.BREWING_STAND) { - BrewingStand brewingStand = (BrewingStand) inventoryHolder; - short time = (short) brewingStand.getBrewingTime(); - if (time > 0) { - brewTime.put(bl, time); - } - ItemStack[] invBre = brewingStand.getInventory().getContents().clone(); - brewingStandContents.put(bl, invBre); - } else if (id == Material.FURNACE || id == Material.BURNING_FURNACE) { - Furnace furnace = (Furnace) inventoryHolder; - short burn = furnace.getBurnTime(); - short cook = furnace.getCookTime(); - ItemStack[] invFur = furnace.getInventory().getContents().clone(); - furnaceContents.put(bl, invFur); - if (cook != 0) { - furnaceTime.put(bl, new Short[]{burn, cook}); - } - } - } else if (block.getState() instanceof CreatureSpawner) { - CreatureSpawner spawner = (CreatureSpawner) block.getState(); - EntityType type = spawner.getSpawnedType(); - if (type != null) { - spawnerData.put(bl, type); - } - } else if (block.getState() instanceof CommandBlock) { - CommandBlock cmd = (CommandBlock) block.getState(); - String string = cmd.getCommand(); - if (string != null && !string.isEmpty()) { - cmdData.put(bl, string); - } - } else if (block.getState() instanceof NoteBlock) { - NoteBlock noteBlock = (NoteBlock) block.getState(); - Note note = noteBlock.getNote(); - noteBlockContents.put(bl, note); - } else if (block.getState() instanceof Jukebox) { - Jukebox jukebox = (Jukebox) block.getState(); - Material playing = jukebox.getPlaying(); - if (playing != null) { - jukeboxDisc.put(bl, playing); - } - } else if (block.getState() instanceof Skull) { - Skull skull = (Skull) block.getState(); - String o = skull.getOwner(); - byte skullType = getOrdinal(SkullType.values(), skull.getSkullType()); - skull.getRotation(); - short rot = getOrdinal(BlockFace.values(), skull.getRotation()); - skullData.put(bl, new Object[]{o, rot, skullType}); - } else if (block.getState() instanceof Banner) { - Banner banner = (Banner) block.getState(); - DyeColor base = banner.getBaseColor(); - bannerBase.put(bl, base); - bannerPatterns.put(bl, banner.getPatterns()); - - } - } catch (Exception e) { - PS.debug("------------ FAILED TO DO SOMETHING --------"); - e.printStackTrace(); - PS.debug("------------ but we caught it ^ --------"); - } - } - } - PlotLoc loc = new PlotLoc(x + offsetX, z + offsetZ); - allBlocks.put(loc, ids); - } - } - public static boolean isIn(RegionWrapper region, int x, int z) { return x >= region.minX && x <= region.maxX && z >= region.minZ && z <= region.maxZ; } @@ -673,6 +137,22 @@ public class BukkitChunkManager extends ChunkManager { return chunks; } + @Override + public void regenerateChunk(String world, ChunkLoc loc) { + World worldObj = Bukkit.getWorld(world); + worldObj.regenerateChunk(loc.x, loc.z); + SetQueue.IMP.queue.sendChunk(world, Collections.singletonList(loc)); + for (Entry entry : UUIDHandler.getPlayers().entrySet()) { + PlotPlayer pp = entry.getValue(); + Location pLoc = pp.getLocation(); + if (!StringMan.isEqual(world, pLoc.getWorld()) || !pLoc.getChunkLoc().equals(loc)) { + continue; + } + pLoc.setY(WorldUtil.IMP.getHighestBlock(world, pLoc.getX(), pLoc.getZ())); + pp.teleport(pLoc); + } + } + @Override public boolean copyRegion(Location pos1, Location pos2, Location newPos, final Runnable whenDone) { final int relX = newPos.getX() - pos1.getX(); @@ -927,7 +407,7 @@ public class BukkitChunkManager extends ChunkManager { RegionWrapper region1 = new RegionWrapper(bot1.getX(), top1.getX(), bot1.getZ(), top1.getZ()); RegionWrapper region2 = new RegionWrapper(bot2.getX(), top2.getX(), bot2.getZ(), top2.getZ()); final World world1 = Bukkit.getWorld(bot1.getWorld()); - final World world2 = Bukkit.getWorld(bot2.getWorld()); + World world2 = Bukkit.getWorld(bot2.getWorld()); int relX = bot2.getX() - bot1.getX(); int relZ = bot2.getZ() - bot1.getZ(); @@ -1131,4 +611,550 @@ public class BukkitChunkManager extends ChunkManager { } count[0]++; } + + public static class ContentMap { + + public final HashMap chestContents; + public final HashMap furnaceContents; + public final HashMap dispenserContents; + public final HashMap dropperContents; + public final HashMap brewingStandContents; + public final HashMap beaconContents; + public final HashMap hopperContents; + public final HashMap furnaceTime; + public final HashMap skullData; + public final HashMap jukeboxDisc; + public final HashMap brewTime; + public final HashMap spawnerData; + public final HashMap cmdData; + public final HashMap signContents; + public final HashMap noteBlockContents; + public final HashMap> bannerPatterns; + public final HashMap bannerBase; + public final HashSet entities; + public final HashMap allBlocks; + + public ContentMap() { + this.chestContents = new HashMap<>(); + this.furnaceContents = new HashMap<>(); + this.dispenserContents = new HashMap<>(); + this.dropperContents = new HashMap<>(); + this.brewingStandContents = new HashMap<>(); + this.beaconContents = new HashMap<>(); + this.hopperContents = new HashMap<>(); + this.furnaceTime = new HashMap<>(); + this.skullData = new HashMap<>(); + this.brewTime = new HashMap<>(); + this.jukeboxDisc = new HashMap<>(); + this.spawnerData = new HashMap<>(); + this.noteBlockContents = new HashMap<>(); + this.signContents = new HashMap<>(); + this.cmdData = new HashMap<>(); + this.bannerBase = new HashMap<>(); + this.bannerPatterns = new HashMap<>(); + this.entities = new HashSet<>(); + this.allBlocks = new HashMap<>(); + } + + public void saveRegion(World world, int x1, int x2, int z1, int z2) { + if (z1 > z2) { + int tmp = z1; + z1 = z2; + z2 = tmp; + } + if (x1 > x2) { + int tmp = x1; + x1 = x2; + x2 = tmp; + } + for (int x = x1; x <= x2; x++) { + for (int z = z1; z <= z2; z++) { + saveBlocks(world, 256, x, z, 0, 0, true); + } + } + } + + public void saveEntitiesIn(Chunk chunk, RegionWrapper region) { + saveEntitiesIn(chunk, region, 0, 0, false); + } + + public void saveEntitiesOut(Chunk chunk, RegionWrapper region) { + for (Entity entity : chunk.getEntities()) { + Location loc = BukkitUtil.getLocation(entity); + int x = loc.getX(); + int z = loc.getZ(); + if (isIn(region, x, z)) { + continue; + } + if (entity.getVehicle() != null) { + continue; + } + EntityWrapper wrap = new EntityWrapper(entity, (short) 2); + this.entities.add(wrap); + } + } + + public void saveEntitiesIn(Chunk chunk, RegionWrapper region, int offsetX, int offsetZ, boolean delete) { + for (Entity entity : chunk.getEntities()) { + Location loc = BukkitUtil.getLocation(entity); + int x = loc.getX(); + int z = loc.getZ(); + if (!isIn(region, x, z)) { + continue; + } + if (entity.getVehicle() != null) { + continue; + } + EntityWrapper wrap = new EntityWrapper(entity, (short) 2); + wrap.x += offsetX; + wrap.z += offsetZ; + this.entities.add(wrap); + if (delete) { + if (!(entity instanceof Player)) { + entity.remove(); + } + } + } + } + + public void restoreEntities(World world, int xOffset, int zOffset) { + for (EntityWrapper entity : this.entities) { + try { + entity.spawn(world, xOffset, zOffset); + } catch (Exception e) { + PS.debug("Failed to restore entity (e): " + entity.x + "," + entity.y + "," + entity.z + " : " + entity.type); + e.printStackTrace(); + } + } + this.entities.clear(); + } + + public void restoreBlocks(World world, int xOffset, int zOffset) { + for (Entry blockLocEntry : this.chestContents.entrySet()) { + try { + Block block = + world.getBlockAt(blockLocEntry.getKey().x + xOffset, blockLocEntry.getKey().y, blockLocEntry.getKey().z + zOffset); + BlockState state = block.getState(); + if (state instanceof InventoryHolder) { + InventoryHolder chest = (InventoryHolder) state; + chest.getInventory().setContents(blockLocEntry.getValue()); + state.update(true); + } else { + PS.debug("&c[WARN] Plot clear failed to regenerate chest: " + (blockLocEntry.getKey().x + xOffset) + "," + blockLocEntry + .getKey().y + "," + (blockLocEntry.getKey().z + zOffset)); + } + } catch (IllegalArgumentException e) { + PS.debug("&c[WARN] Plot clear failed to regenerate chest (e): " + (blockLocEntry.getKey().x + xOffset) + "," + blockLocEntry + .getKey().y + "," + (blockLocEntry.getKey().z + zOffset)); + } + } + for (Entry blockLocEntry : this.signContents.entrySet()) { + try { + Block block = + world.getBlockAt(blockLocEntry.getKey().x + xOffset, blockLocEntry.getKey().y, blockLocEntry.getKey().z + zOffset); + BlockState state = block.getState(); + if (state instanceof Sign) { + Sign sign = (Sign) state; + int i = 0; + for (String line : blockLocEntry.getValue()) { + sign.setLine(i, line); + i++; + } + state.update(true); + } else { + PS.debug( + "&c[WARN] Plot clear failed to regenerate sign: " + (blockLocEntry.getKey().x + xOffset) + "," + blockLocEntry + .getKey().y + + "," + ( + blockLocEntry.getKey().z + zOffset)); + } + } catch (IndexOutOfBoundsException e) { + PS.debug("&c[WARN] Plot clear failed to regenerate sign: " + (blockLocEntry.getKey().x + xOffset) + "," + blockLocEntry.getKey().y + + "," + ( + blockLocEntry.getKey().z + zOffset)); + } + } + for (Entry blockLocEntry : this.dispenserContents.entrySet()) { + try { + Block block = + world.getBlockAt(blockLocEntry.getKey().x + xOffset, blockLocEntry.getKey().y, blockLocEntry.getKey().z + zOffset); + BlockState state = block.getState(); + if (state instanceof Dispenser) { + ((InventoryHolder) state).getInventory().setContents(blockLocEntry.getValue()); + state.update(true); + } else { + PS.debug("&c[WARN] Plot clear failed to regenerate dispenser: " + (blockLocEntry.getKey().x + xOffset) + "," + blockLocEntry + .getKey().y + "," + (blockLocEntry.getKey().z + zOffset)); + } + } catch (IllegalArgumentException e) { + PS.debug("&c[WARN] Plot clear failed to regenerate dispenser (e): " + (blockLocEntry.getKey().x + xOffset) + "," + blockLocEntry + .getKey().y + "," + (blockLocEntry.getKey().z + zOffset)); + } + } + for (Entry blockLocEntry : this.dropperContents.entrySet()) { + try { + Block block = + world.getBlockAt(blockLocEntry.getKey().x + xOffset, blockLocEntry.getKey().y, blockLocEntry.getKey().z + zOffset); + BlockState state = block.getState(); + if (state instanceof Dropper) { + ((InventoryHolder) state).getInventory().setContents(blockLocEntry.getValue()); + state.update(true); + } else { + PS.debug("&c[WARN] Plot clear failed to regenerate dispenser: " + (blockLocEntry.getKey().x + xOffset) + "," + blockLocEntry + .getKey().y + "," + (blockLocEntry.getKey().z + zOffset)); + } + } catch (IllegalArgumentException e) { + PS.debug("&c[WARN] Plot clear failed to regenerate dispenser (e): " + (blockLocEntry.getKey().x + xOffset) + "," + blockLocEntry + .getKey().y + "," + (blockLocEntry.getKey().z + zOffset)); + } + } + for (Entry blockLocEntry : this.beaconContents.entrySet()) { + try { + Block block = + world.getBlockAt(blockLocEntry.getKey().x + xOffset, blockLocEntry.getKey().y, blockLocEntry.getKey().z + zOffset); + BlockState state = block.getState(); + if (state instanceof Beacon) { + ((InventoryHolder) state).getInventory().setContents(blockLocEntry.getValue()); + state.update(true); + } else { + PS.debug("&c[WARN] Plot clear failed to regenerate beacon: " + (blockLocEntry.getKey().x + xOffset) + "," + blockLocEntry + .getKey().y + "," + (blockLocEntry.getKey().z + zOffset)); + } + } catch (IllegalArgumentException e) { + PS.debug("&c[WARN] Plot clear failed to regenerate beacon (e): " + (blockLocEntry.getKey().x + xOffset) + "," + blockLocEntry + .getKey().y + "," + (blockLocEntry.getKey().z + zOffset)); + } + } + for (Entry blockLocMaterialEntry : this.jukeboxDisc.entrySet()) { + try { + Block block = + world.getBlockAt(blockLocMaterialEntry.getKey().x + xOffset, blockLocMaterialEntry.getKey().y, blockLocMaterialEntry + .getKey().z + zOffset); + BlockState state = block.getState(); + if (state instanceof Jukebox) { + ((Jukebox) state).setPlaying(blockLocMaterialEntry.getValue()); + state.update(true); + } else { + PS.debug("&c[WARN] Plot clear failed to restore jukebox: " + (blockLocMaterialEntry.getKey().x + xOffset) + "," + + blockLocMaterialEntry + .getKey().y + "," + ( + blockLocMaterialEntry.getKey().z + zOffset)); + } + } catch (Exception e) { + PS.debug("&c[WARN] Plot clear failed to regenerate jukebox (e): " + (blockLocMaterialEntry.getKey().x + xOffset) + "," + + blockLocMaterialEntry + .getKey().y + "," + ( + blockLocMaterialEntry.getKey().z + zOffset)); + } + } + for (Entry blockLocEntry : this.skullData.entrySet()) { + try { + Block block = + world.getBlockAt(blockLocEntry.getKey().x + xOffset, blockLocEntry.getKey().y, blockLocEntry.getKey().z + zOffset); + BlockState state = block.getState(); + if (state instanceof Skull) { + Object[] data = blockLocEntry.getValue(); + if (data[0] != null) { + ((Skull) state).setOwner((String) data[0]); + } + if ((Integer) data[1] != 0) { + ((Skull) state).setRotation(BlockFace.values()[(int) data[1]]); + } + if ((Integer) data[2] != 0) { + ((Skull) state).setSkullType(SkullType.values()[(int) data[2]]); + } + state.update(true); + } else { + PS.debug("&c[WARN] Plot clear failed to restore skull: " + (blockLocEntry.getKey().x + xOffset) + "," + blockLocEntry + .getKey().y + + "," + ( + blockLocEntry.getKey().z + zOffset)); + } + } catch (Exception e) { + PS.debug("&c[WARN] Plot clear failed to regenerate skull (e): " + (blockLocEntry.getKey().x + xOffset) + "," + blockLocEntry + .getKey().y + "," + (blockLocEntry.getKey().z + zOffset)); + } + } + for (Entry blockLocEntry : this.hopperContents.entrySet()) { + try { + Block block = + world.getBlockAt(blockLocEntry.getKey().x + xOffset, blockLocEntry.getKey().y, blockLocEntry.getKey().z + zOffset); + BlockState state = block.getState(); + if (state instanceof Hopper) { + ((InventoryHolder) state).getInventory().setContents(blockLocEntry.getValue()); + state.update(true); + } else { + PS.debug("&c[WARN] Plot clear failed to regenerate hopper: " + (blockLocEntry.getKey().x + xOffset) + "," + blockLocEntry + .getKey().y + "," + (blockLocEntry.getKey().z + zOffset)); + } + } catch (IllegalArgumentException e) { + PS.debug("&c[WARN] Plot clear failed to regenerate hopper (e): " + (blockLocEntry.getKey().x + xOffset) + "," + blockLocEntry + .getKey().y + "," + (blockLocEntry.getKey().z + zOffset)); + } + } + for (Entry blockLocNoteEntry : this.noteBlockContents.entrySet()) { + try { + Block block = world.getBlockAt( + blockLocNoteEntry.getKey().x + xOffset, blockLocNoteEntry.getKey().y, blockLocNoteEntry.getKey().z + zOffset); + BlockState state = block.getState(); + if (state instanceof NoteBlock) { + ((NoteBlock) state).setNote(blockLocNoteEntry.getValue()); + state.update(true); + } else { + PS.debug("&c[WARN] Plot clear failed to regenerate note block: " + (blockLocNoteEntry.getKey().x + xOffset) + "," + + blockLocNoteEntry + .getKey().y + "," + ( + blockLocNoteEntry.getKey().z + zOffset)); + } + } catch (Exception e) { + PS.debug("&c[WARN] Plot clear failed to regenerate note block (e): " + (blockLocNoteEntry.getKey().x + xOffset) + "," + + blockLocNoteEntry + .getKey().y + "," + ( + blockLocNoteEntry.getKey().z + zOffset)); + } + } + for (Entry blockLocShortEntry : this.brewTime.entrySet()) { + try { + Block block = world.getBlockAt( + blockLocShortEntry.getKey().x + xOffset, blockLocShortEntry.getKey().y, blockLocShortEntry.getKey().z + zOffset); + BlockState state = block.getState(); + if (state instanceof BrewingStand) { + ((BrewingStand) state).setBrewingTime(blockLocShortEntry.getValue()); + } else { + PS.debug("&c[WARN] Plot clear failed to restore brewing stand cooking: " + (blockLocShortEntry.getKey().x + xOffset) + "," + + blockLocShortEntry + .getKey().y + "," + ( + blockLocShortEntry.getKey().z + zOffset)); + } + } catch (Exception e) { + PS.debug("&c[WARN] Plot clear failed to restore brewing stand cooking (e): " + (blockLocShortEntry.getKey().x + xOffset) + "," + + blockLocShortEntry.getKey().y + "," + (blockLocShortEntry.getKey().z + zOffset)); + } + } + for (Entry blockLocEntityTypeEntry : this.spawnerData.entrySet()) { + try { + Block block = + world.getBlockAt(blockLocEntityTypeEntry.getKey().x + xOffset, blockLocEntityTypeEntry.getKey().y, blockLocEntityTypeEntry + .getKey().z + zOffset); + BlockState state = block.getState(); + if (state instanceof CreatureSpawner) { + ((CreatureSpawner) state).setSpawnedType(blockLocEntityTypeEntry.getValue()); + state.update(true); + } else { + PS.debug("&c[WARN] Plot clear failed to restore spawner type: " + (blockLocEntityTypeEntry.getKey().x + xOffset) + "," + + blockLocEntityTypeEntry + .getKey().y + "," + ( + blockLocEntityTypeEntry.getKey().z + zOffset)); + } + } catch (Exception e) { + PS.debug("&c[WARN] Plot clear failed to restore spawner type (e): " + (blockLocEntityTypeEntry.getKey().x + xOffset) + "," + + blockLocEntityTypeEntry.getKey().y + "," + (blockLocEntityTypeEntry.getKey().z + zOffset)); + } + } + for (Entry blockLocStringEntry : this.cmdData.entrySet()) { + try { + Block block = world.getBlockAt( + blockLocStringEntry.getKey().x + xOffset, blockLocStringEntry.getKey().y, blockLocStringEntry.getKey().z + zOffset); + BlockState state = block.getState(); + if (state instanceof CommandBlock) { + ((CommandBlock) state).setCommand(blockLocStringEntry.getValue()); + state.update(true); + } else { + PS.debug("&c[WARN] Plot clear failed to restore command block: " + (blockLocStringEntry.getKey().x + xOffset) + "," + + blockLocStringEntry + .getKey().y + "," + ( + blockLocStringEntry.getKey().z + zOffset)); + } + } catch (Exception e) { + PS.debug("&c[WARN] Plot clear failed to restore command block (e): " + (blockLocStringEntry.getKey().x + xOffset) + "," + + blockLocStringEntry + .getKey().y + "," + ( + blockLocStringEntry.getKey().z + zOffset)); + } + } + for (Entry blockLocEntry : this.brewingStandContents.entrySet()) { + try { + Block block = + world.getBlockAt(blockLocEntry.getKey().x + xOffset, blockLocEntry.getKey().y, blockLocEntry.getKey().z + zOffset); + BlockState state = block.getState(); + if (state instanceof BrewingStand) { + ((InventoryHolder) state).getInventory().setContents(blockLocEntry.getValue()); + state.update(true); + } else { + PS.debug("&c[WARN] Plot clear failed to regenerate brewing stand: " + (blockLocEntry.getKey().x + xOffset) + "," + + blockLocEntry + .getKey().y + "," + ( + blockLocEntry.getKey().z + + zOffset)); + } + } catch (IllegalArgumentException e) { + PS.debug("&c[WARN] Plot clear failed to regenerate brewing stand (e): " + (blockLocEntry.getKey().x + xOffset) + "," + + blockLocEntry + .getKey().y + "," + ( + blockLocEntry.getKey().z + + zOffset)); + } + } + for (Entry blockLocEntry : this.furnaceTime.entrySet()) { + try { + Block block = + world.getBlockAt(blockLocEntry.getKey().x + xOffset, blockLocEntry.getKey().y, blockLocEntry.getKey().z + zOffset); + BlockState state = block.getState(); + if (state instanceof Furnace) { + Short[] time = blockLocEntry.getValue(); + ((Furnace) state).setBurnTime(time[0]); + ((Furnace) state).setCookTime(time[1]); + } else { + PS.debug( + "&c[WARN] Plot clear failed to restore furnace cooking: " + (blockLocEntry.getKey().x + xOffset) + "," + blockLocEntry + .getKey().y + "," + ( + blockLocEntry.getKey().z + zOffset)); + } + } catch (Exception e) { + PS.debug( + "&c[WARN] Plot clear failed to restore furnace cooking (e): " + (blockLocEntry.getKey().x + xOffset) + "," + blockLocEntry + .getKey().y + "," + ( + blockLocEntry.getKey().z + zOffset)); + } + } + for (Entry blockLocEntry : this.furnaceContents.entrySet()) { + try { + Block block = + world.getBlockAt(blockLocEntry.getKey().x + xOffset, blockLocEntry.getKey().y, blockLocEntry.getKey().z + zOffset); + BlockState state = block.getState(); + if (state instanceof Furnace) { + ((InventoryHolder) state).getInventory().setContents(blockLocEntry.getValue()); + state.update(true); + } else { + PS.debug("&c[WARN] Plot clear failed to regenerate furnace: " + (blockLocEntry.getKey().x + xOffset) + "," + blockLocEntry + .getKey().y + "," + (blockLocEntry.getKey().z + zOffset)); + } + } catch (IllegalArgumentException e) { + PS.debug("&c[WARN] Plot clear failed to regenerate furnace (e): " + (blockLocEntry.getKey().x + xOffset) + "," + blockLocEntry + .getKey().y + "," + (blockLocEntry.getKey().z + zOffset)); + } + } + for (Entry blockLocByteEntry : this.bannerBase.entrySet()) { + try { + Block block = world.getBlockAt( + blockLocByteEntry.getKey().x + xOffset, blockLocByteEntry.getKey().y, blockLocByteEntry.getKey().z + zOffset); + BlockState state = block.getState(); + if (state instanceof Banner) { + Banner banner = (Banner) state; + DyeColor base = blockLocByteEntry.getValue(); + List patterns = this.bannerPatterns.get(blockLocByteEntry.getKey()); + banner.setBaseColor(base); + banner.setPatterns(patterns); + state.update(true); + } else { + PS.debug("&c[WARN] Plot clear failed to regenerate banner: " + (blockLocByteEntry.getKey().x + xOffset) + "," + + blockLocByteEntry + .getKey().y + "," + ( + blockLocByteEntry.getKey().z + zOffset)); + } + } catch (Exception e) { + PS.debug("&c[WARN] Plot clear failed to regenerate banner (e): " + (blockLocByteEntry.getKey().x + xOffset) + "," + + blockLocByteEntry + .getKey().y + "," + ( + blockLocByteEntry.getKey().z + zOffset)); + } + } + } + + public void saveBlocks(World world, int maxY, int x, int z, int offsetX, int offsetZ, boolean storeNormal) { + maxY = Math.min(255, maxY); + PlotBlock[] ids; + if (storeNormal) { + ids = new PlotBlock[maxY + 1]; + } else { + ids = null; + } + for (short y = 0; y <= maxY; y++) { + Block block = world.getBlockAt(x, y, z); + Material id = block.getType(); + if (storeNormal) { + int typeId = id.getId(); + ids[y] = new PlotBlock((short) typeId, typeId == 0 ? 0 : block.getData()); + } + if (!id.equals(Material.AIR)) { + try { + BlockLoc bl = new BlockLoc(x + offsetX, y, z + offsetZ); + if (block.getState() instanceof InventoryHolder) { + InventoryHolder inventoryHolder = (InventoryHolder) block.getState(); + ItemStack[] inventory = inventoryHolder.getInventory().getContents().clone(); + if (id == Material.CHEST) { + this.chestContents.put(bl, inventory); + } else if (id == Material.DISPENSER) { + this.dispenserContents.put(bl, inventory); + } else if (id == Material.BEACON) { + this.beaconContents.put(bl, inventory); + } else if (id == Material.DROPPER) { + this.dropperContents.put(bl, inventory); + } else if (id == Material.HOPPER) { + this.hopperContents.put(bl, inventory); + } else if (id == Material.BREWING_STAND) { + BrewingStand brewingStand = (BrewingStand) inventoryHolder; + short time = (short) brewingStand.getBrewingTime(); + if (time > 0) { + this.brewTime.put(bl, time); + } + ItemStack[] invBre = brewingStand.getInventory().getContents().clone(); + this.brewingStandContents.put(bl, invBre); + } else if (id == Material.FURNACE || id == Material.BURNING_FURNACE) { + Furnace furnace = (Furnace) inventoryHolder; + short burn = furnace.getBurnTime(); + short cook = furnace.getCookTime(); + ItemStack[] invFur = furnace.getInventory().getContents().clone(); + this.furnaceContents.put(bl, invFur); + if (cook != 0) { + this.furnaceTime.put(bl, new Short[]{burn, cook}); + } + } + } else if (block.getState() instanceof CreatureSpawner) { + CreatureSpawner spawner = (CreatureSpawner) block.getState(); + EntityType type = spawner.getSpawnedType(); + if (type != null) { + this.spawnerData.put(bl, type); + } + } else if (block.getState() instanceof CommandBlock) { + CommandBlock cmd = (CommandBlock) block.getState(); + String string = cmd.getCommand(); + if (string != null && !string.isEmpty()) { + this.cmdData.put(bl, string); + } + } else if (block.getState() instanceof NoteBlock) { + NoteBlock noteBlock = (NoteBlock) block.getState(); + Note note = noteBlock.getNote(); + this.noteBlockContents.put(bl, note); + } else if (block.getState() instanceof Jukebox) { + Jukebox jukebox = (Jukebox) block.getState(); + Material playing = jukebox.getPlaying(); + if (playing != null) { + this.jukeboxDisc.put(bl, playing); + } + } else if (block.getState() instanceof Skull) { + Skull skull = (Skull) block.getState(); + String o = skull.getOwner(); + byte skullType = getOrdinal(SkullType.values(), skull.getSkullType()); + skull.getRotation(); + short rot = getOrdinal(BlockFace.values(), skull.getRotation()); + this.skullData.put(bl, new Object[]{o, rot, skullType}); + } else if (block.getState() instanceof Banner) { + Banner banner = (Banner) block.getState(); + DyeColor base = banner.getBaseColor(); + this.bannerBase.put(bl, base); + this.bannerPatterns.put(bl, banner.getPatterns()); + + } + } catch (Exception e) { + PS.debug("------------ FAILED TO DO SOMETHING --------"); + e.printStackTrace(); + PS.debug("------------ but we caught it ^ --------"); + } + } + } + PlotLoc loc = new PlotLoc(x + offsetX, z + offsetZ); + this.allBlocks.put(loc, ids); + } + } } diff --git a/Bukkit/src/main/java/com/plotsquared/bukkit/util/BukkitCommand.java b/Bukkit/src/main/java/com/plotsquared/bukkit/util/BukkitCommand.java index fdf932783..d97271f4b 100644 --- a/Bukkit/src/main/java/com/plotsquared/bukkit/util/BukkitCommand.java +++ b/Bukkit/src/main/java/com/plotsquared/bukkit/util/BukkitCommand.java @@ -4,9 +4,12 @@ import com.intellectualcrafters.plot.commands.MainCommand; import com.intellectualcrafters.plot.object.ConsolePlayer; import com.intellectualcrafters.plot.object.PlotPlayer; import com.plotsquared.bukkit.commands.DebugUUID; -import org.bukkit.Bukkit; +import org.bukkit.command.Command; import org.bukkit.command.CommandExecutor; import org.bukkit.command.CommandSender; +import org.bukkit.command.ConsoleCommandSender; +import org.bukkit.command.ProxiedCommandSender; +import org.bukkit.command.RemoteConsoleCommandSender; import org.bukkit.command.TabCompleter; import org.bukkit.entity.Player; @@ -22,41 +25,19 @@ public class BukkitCommand implements CommandExecutor, TabCompleter { } @Override - public boolean onCommand(final CommandSender commandSender, org.bukkit.command.Command command, final String commandLabel, String[] args) { + public boolean onCommand(CommandSender commandSender, Command command, String commandLabel, String[] args) { if (commandSender instanceof Player) { return MainCommand.onCommand(BukkitUtil.getPlayer((Player) commandSender), args); } - if (commandSender.getClass() == Bukkit.getConsoleSender().getClass()) { + if (commandSender instanceof ConsoleCommandSender || commandSender instanceof ProxiedCommandSender + || commandSender instanceof RemoteConsoleCommandSender) { return MainCommand.onCommand(ConsolePlayer.getConsole(), args); } - @SuppressWarnings("deprecation") - ConsolePlayer sender = new ConsolePlayer() { - @Override - public void sendMessage(String message) { - commandSender.sendMessage(commandLabel); - } - - @Override - public boolean hasPermission(String permission) { - return commandSender.hasPermission(commandLabel); - } - - @Override - public String getName() { - if (commandSender.getName().equals("CONSOLE")) { - return "*"; - } - return commandSender.getName(); - } - }; - sender.teleport(ConsolePlayer.getConsole().getLocationFull()); - boolean result = MainCommand.onCommand(sender, args); - ConsolePlayer.getConsole().teleport(sender.getLocationFull()); - return result; + return false; } @Override - public List onTabComplete(CommandSender commandSender, org.bukkit.command.Command command, String s, String[] args) { + public List onTabComplete(CommandSender commandSender, Command command, String s, String[] args) { if (!(commandSender instanceof Player)) { return null; } @@ -72,6 +53,6 @@ public class BukkitCommand implements CommandExecutor, TabCompleter { for (Object o : objects) { result.add(o.toString()); } - return result.size() == 0 ? null : result; + return result.isEmpty() ? null : result; } } diff --git a/Bukkit/src/main/java/com/plotsquared/bukkit/util/BukkitEconHandler.java b/Bukkit/src/main/java/com/plotsquared/bukkit/util/BukkitEconHandler.java index 5cdffb7a3..145c04842 100644 --- a/Bukkit/src/main/java/com/plotsquared/bukkit/util/BukkitEconHandler.java +++ b/Bukkit/src/main/java/com/plotsquared/bukkit/util/BukkitEconHandler.java @@ -15,16 +15,6 @@ public class BukkitEconHandler extends EconHandler { private Economy econ; private Permission perms; - public Economy getEconomy() { - init(); - return this.econ; - } - - public Permission getPermissions() { - init(); - return this.perms; - } - public boolean init() { if (this.econ == null || this.perms == null) { setupPermissions(); diff --git a/Bukkit/src/main/java/com/plotsquared/bukkit/util/BukkitTaskManager.java b/Bukkit/src/main/java/com/plotsquared/bukkit/util/BukkitTaskManager.java index 61f72f0b9..7a6c89ded 100644 --- a/Bukkit/src/main/java/com/plotsquared/bukkit/util/BukkitTaskManager.java +++ b/Bukkit/src/main/java/com/plotsquared/bukkit/util/BukkitTaskManager.java @@ -6,35 +6,41 @@ import org.bukkit.Bukkit; public class BukkitTaskManager extends TaskManager { + private final BukkitMain bukkitMain; + + public BukkitTaskManager(BukkitMain bukkitMain) { + this.bukkitMain = bukkitMain; + } + @Override public int taskRepeat(Runnable runnable, int interval) { - return BukkitMain.THIS.getServer().getScheduler().scheduleSyncRepeatingTask(BukkitMain.THIS, runnable, interval, interval); + return this.bukkitMain.getServer().getScheduler().scheduleSyncRepeatingTask(this.bukkitMain, runnable, interval, interval); } @SuppressWarnings("deprecation") @Override public int taskRepeatAsync(Runnable runnable, int interval) { - return BukkitMain.THIS.getServer().getScheduler().scheduleAsyncRepeatingTask(BukkitMain.THIS, runnable, interval, interval); + return this.bukkitMain.getServer().getScheduler().scheduleAsyncRepeatingTask(this.bukkitMain, runnable, interval, interval); } @Override public void taskAsync(Runnable runnable) { - BukkitMain.THIS.getServer().getScheduler().runTaskAsynchronously(BukkitMain.THIS, runnable).getTaskId(); + this.bukkitMain.getServer().getScheduler().runTaskAsynchronously(this.bukkitMain, runnable).getTaskId(); } @Override public void task(Runnable runnable) { - BukkitMain.THIS.getServer().getScheduler().runTask(BukkitMain.THIS, runnable).getTaskId(); + this.bukkitMain.getServer().getScheduler().runTask(this.bukkitMain, runnable).getTaskId(); } @Override public void taskLater(Runnable runnable, int delay) { - BukkitMain.THIS.getServer().getScheduler().runTaskLater(BukkitMain.THIS, runnable, delay).getTaskId(); + this.bukkitMain.getServer().getScheduler().runTaskLater(this.bukkitMain, runnable, delay).getTaskId(); } @Override public void taskLaterAsync(Runnable runnable, int delay) { - BukkitMain.THIS.getServer().getScheduler().runTaskLaterAsynchronously(BukkitMain.THIS, runnable, delay); + this.bukkitMain.getServer().getScheduler().runTaskLaterAsynchronously(this.bukkitMain, runnable, delay); } @Override diff --git a/Bukkit/src/main/java/com/plotsquared/bukkit/util/SendChunk.java b/Bukkit/src/main/java/com/plotsquared/bukkit/util/SendChunk.java index 840b149cd..4365998d6 100644 --- a/Bukkit/src/main/java/com/plotsquared/bukkit/util/SendChunk.java +++ b/Bukkit/src/main/java/com/plotsquared/bukkit/util/SendChunk.java @@ -50,6 +50,7 @@ public class SendChunk { RefClass classChunk = getRefClass("{nms}.Chunk"); this.methodInitLighting = classChunk.getMethod("initLighting"); RefClass classMapChunk = getRefClass("{nms}.PacketPlayOutMapChunk"); + //TODO in 1.7.10 this is PacketPlayOutMapChunk(Chunk chunk, boolean flag, int i, int version) this.mapChunk = classMapChunk.getConstructor(classChunk.getRealClass(), boolean.class, int.class); RefClass classEntityPlayer = getRefClass("{nms}.EntityPlayer"); this.connection = classEntityPlayer.getField("playerConnection"); diff --git a/Bukkit/src/main/java/com/plotsquared/bukkit/util/block/FastQueue_1_8.java b/Bukkit/src/main/java/com/plotsquared/bukkit/util/block/FastQueue_1_8.java index bd1c21f0e..b534ec3f4 100644 --- a/Bukkit/src/main/java/com/plotsquared/bukkit/util/block/FastQueue_1_8.java +++ b/Bukkit/src/main/java/com/plotsquared/bukkit/util/block/FastQueue_1_8.java @@ -12,7 +12,6 @@ import com.intellectualcrafters.plot.util.ReflectionUtils.RefMethod; import com.intellectualcrafters.plot.util.SetQueue; import com.intellectualcrafters.plot.util.SetQueue.ChunkWrapper; import com.intellectualcrafters.plot.util.TaskManager; -import com.plotsquared.bukkit.util.BukkitUtil; import com.plotsquared.bukkit.util.SendChunk; import org.bukkit.Chunk; import org.bukkit.World; @@ -370,7 +369,6 @@ public class FastQueue_1_8 extends SlowQueue { */ @Override public void sendChunk(String world, Collection locations) { - World worldObj = BukkitUtil.getWorld(world); for (ChunkLoc loc : locations) { ChunkWrapper wrapper = SetQueue.IMP.new ChunkWrapper(world, loc.x, loc.z); this.toUpdate.remove(wrapper); diff --git a/Bukkit/src/main/java/com/plotsquared/bukkit/util/block/FastQueue_1_8_3.java b/Bukkit/src/main/java/com/plotsquared/bukkit/util/block/FastQueue_1_8_3.java index 719819955..d1e015dab 100644 --- a/Bukkit/src/main/java/com/plotsquared/bukkit/util/block/FastQueue_1_8_3.java +++ b/Bukkit/src/main/java/com/plotsquared/bukkit/util/block/FastQueue_1_8_3.java @@ -1,5 +1,7 @@ package com.plotsquared.bukkit.util.block; +import static com.intellectualcrafters.plot.util.ReflectionUtils.getRefClass; + import com.intellectualcrafters.plot.object.ChunkLoc; import com.intellectualcrafters.plot.object.PseudoRandom; import com.intellectualcrafters.plot.util.ChunkManager; @@ -15,6 +17,12 @@ import com.intellectualcrafters.plot.util.SetQueue.ChunkWrapper; import com.intellectualcrafters.plot.util.TaskManager; import com.plotsquared.bukkit.util.BukkitUtil; import com.plotsquared.bukkit.util.SendChunk; +import org.bukkit.Chunk; +import org.bukkit.Material; +import org.bukkit.World; +import org.bukkit.World.Environment; +import org.bukkit.block.Biome; + import java.lang.reflect.Field; import java.lang.reflect.InvocationTargetException; import java.lang.reflect.Method; @@ -24,14 +32,6 @@ import java.util.HashMap; import java.util.Iterator; import java.util.Map.Entry; import java.util.Set; -import org.bukkit.Chunk; -import org.bukkit.Material; -import org.bukkit.World; -import org.bukkit.World.Environment; -import org.bukkit.block.Biome; - - -import static com.intellectualcrafters.plot.util.ReflectionUtils.getRefClass; public class FastQueue_1_8_3 extends SlowQueue { @@ -266,7 +266,7 @@ public class FastQueue_1_8_3 extends SlowQueue { World world = BukkitUtil.getWorld(worldname); Chunk chunk = world.getChunkAt(loc.x, loc.z); if (chunk.getTileEntities().length > 0) { - Object w = methodGetHandleWorld.of(world).call(); + Object w = this.methodGetHandleWorld.of(world).call(); ((Collection) this.tileEntityListTick.of(w).get()).clear(); } super.regenerateChunk(worldname, loc); diff --git a/Bukkit/src/main/java/com/plotsquared/bukkit/util/block/FastQueue_1_9.java b/Bukkit/src/main/java/com/plotsquared/bukkit/util/block/FastQueue_1_9.java index c0d7b8f06..f3d150562 100644 --- a/Bukkit/src/main/java/com/plotsquared/bukkit/util/block/FastQueue_1_9.java +++ b/Bukkit/src/main/java/com/plotsquared/bukkit/util/block/FastQueue_1_9.java @@ -1,5 +1,7 @@ package com.plotsquared.bukkit.util.block; +import static com.intellectualcrafters.plot.util.ReflectionUtils.getRefClass; + import com.intellectualcrafters.plot.object.ChunkLoc; import com.intellectualcrafters.plot.object.PseudoRandom; import com.intellectualcrafters.plot.util.ChunkManager; @@ -13,6 +15,12 @@ import com.intellectualcrafters.plot.util.ReflectionUtils.RefMethod.RefExecutor; import com.intellectualcrafters.plot.util.SetQueue.ChunkWrapper; import com.intellectualcrafters.plot.util.TaskManager; import com.plotsquared.bukkit.util.BukkitUtil; +import org.bukkit.Chunk; +import org.bukkit.Material; +import org.bukkit.World; +import org.bukkit.World.Environment; +import org.bukkit.block.Biome; + import java.lang.reflect.Field; import java.lang.reflect.InvocationTargetException; import java.lang.reflect.Method; @@ -22,14 +30,6 @@ import java.util.HashMap; import java.util.Iterator; import java.util.Map.Entry; import java.util.Set; -import org.bukkit.Chunk; -import org.bukkit.Material; -import org.bukkit.World; -import org.bukkit.World.Environment; -import org.bukkit.block.Biome; - - -import static com.intellectualcrafters.plot.util.ReflectionUtils.getRefClass; public class FastQueue_1_9 extends SlowQueue { @@ -85,8 +85,8 @@ public class FastQueue_1_9 extends SlowQueue { World world = BukkitUtil.getWorld(worldname); Chunk chunk = world.getChunkAt(loc.x, loc.z); if (chunk.getTileEntities().length > 0) { - Object c = methodGetHandleChunk.of(chunk).call(); - Object w = methodGetWorld.of(c).call(); + Object c = this.methodGetHandleChunk.of(chunk).call(); + Object w = this.methodGetWorld.of(c).call(); ((Collection) this.tileEntityListTick.of(w).get()).clear(); } super.regenerateChunk(worldname, loc); @@ -97,7 +97,7 @@ public class FastQueue_1_9 extends SlowQueue { * @param plotChunk */ @Override - public void execute(final PlotChunk plotChunk) { + public void execute(PlotChunk plotChunk) { final FastChunk_1_9 fs = (FastChunk_1_9) plotChunk; Chunk chunk = plotChunk.getChunk(); World world = chunk.getWorld(); @@ -425,7 +425,7 @@ public class FastQueue_1_9 extends SlowQueue { * @param locations */ @Override - public void sendChunk(final String world, final Collection locations) { + public void sendChunk(String world, Collection locations) { World worldObj = BukkitUtil.getWorld(world); for (ChunkLoc loc : locations) { worldObj.refreshChunk(loc.x, loc.z); diff --git a/Bukkit/src/main/java/com/plotsquared/bukkit/util/block/SlowQueue.java b/Bukkit/src/main/java/com/plotsquared/bukkit/util/block/SlowQueue.java index 86821aae4..222269f75 100644 --- a/Bukkit/src/main/java/com/plotsquared/bukkit/util/block/SlowQueue.java +++ b/Bukkit/src/main/java/com/plotsquared/bukkit/util/block/SlowQueue.java @@ -9,13 +9,14 @@ import com.intellectualcrafters.plot.util.PlotQueue; import com.intellectualcrafters.plot.util.SetQueue; import com.intellectualcrafters.plot.util.SetQueue.ChunkWrapper; import com.plotsquared.bukkit.util.BukkitUtil; +import org.bukkit.Chunk; +import org.bukkit.block.Biome; +import org.bukkit.block.Block; + import java.util.Collection; import java.util.Iterator; import java.util.Map.Entry; import java.util.concurrent.ConcurrentHashMap; -import org.bukkit.Chunk; -import org.bukkit.block.Biome; -import org.bukkit.block.Block; public class SlowQueue implements PlotQueue { diff --git a/Core/src/main/java/com/intellectualcrafters/configuration/Configuration.java b/Core/src/main/java/com/intellectualcrafters/configuration/Configuration.java index 4b9208715..c41a59555 100644 --- a/Core/src/main/java/com/intellectualcrafters/configuration/Configuration.java +++ b/Core/src/main/java/com/intellectualcrafters/configuration/Configuration.java @@ -3,80 +3,82 @@ package com.intellectualcrafters.configuration; import java.util.Map; /** - * Represents a source of configurable options and settings + * Represents a source of configurable options and settings. */ public interface Configuration extends ConfigurationSection { /** * Sets the default value of the given path as provided. - *

- * If no source {@link Configuration} was provided as a default + * + *

If no source {@link Configuration} was provided as a default * collection, then a new {@link MemoryConfiguration} will be created to - * hold the new default value. - *

- * If value is null, the value will be removed from the default - * Configuration source. + * hold the new default value.

+ * + *

If value is null, the value will be removed from the default + * Configuration source.

* * @param path Path of the value to set. * @param value Value to set the default to. * @throws IllegalArgumentException Thrown if path is null. */ - @Override void addDefault(final String path, final Object value); + @Override void addDefault(String path, Object value); /** * Sets the default values of the given paths as provided. - *

- * If no source {@link Configuration} was provided as a default + * + *

If no source {@link Configuration} was provided as a default * collection, then a new {@link MemoryConfiguration} will be created to - * hold the new default values. + * hold the new default values.

* * @param defaults A map of Path->Values to add to defaults. * @throws IllegalArgumentException Thrown if defaults is null. */ - void addDefaults(final Map defaults); + void addDefaults(Map defaults); /** * Sets the default values of the given paths as provided. - *

- * If no source {@link Configuration} was provided as a default + * + *

If no source {@link Configuration} was provided as a default * collection, then a new {@link MemoryConfiguration} will be created to - * hold the new default value. - *

- * This method will not hold a reference to the specified Configuration, + * hold the new default value.

+ * + *

This method will not hold a reference to the specified Configuration, * nor will it automatically update if that Configuration ever changes. If * you require this, you should set the default source with {@link - * #setDefaults(com.intellectualcrafters.configuration.Configuration)}. + * #setDefaults(Configuration)}.

* * @param defaults A configuration holding a list of defaults to copy. * @throws IllegalArgumentException Thrown if defaults is null or this. */ - void addDefaults(final Configuration defaults); - - /** - * Sets the source of all default values for this {@link Configuration}. - *

- * If a previous source was set, or previous default values were defined, - * then they will not be copied to the new source. - * - * @param defaults New source of default values for this configuration. - * @throws IllegalArgumentException Thrown if defaults is null or this. - */ - void setDefaults(final Configuration defaults); + void addDefaults(Configuration defaults); /** * Gets the source {@link Configuration} for this configuration. + * *

* If no configuration source was set, but default values were added, then * a {@link MemoryConfiguration} will be returned. If no source was set - * and no defaults were set, then this method will return null. + * and no defaults were set, then this method will return null.

* * @return Configuration source for default values, or null if none exist. */ Configuration getDefaults(); /** - * Gets the {@link ConfigurationOptions} for this {@link Configuration}. + * Sets the source of all default values for this {@link Configuration}. + * *

- * All setters through this method are chainable. + * If a previous source was set, or previous default values were defined, + * then they will not be copied to the new source.

+ * + * @param defaults New source of default values for this configuration. + * @throws IllegalArgumentException Thrown if defaults is null or this. + */ + void setDefaults(Configuration defaults); + + /** + * Gets the {@link ConfigurationOptions} for this {@link Configuration}. + * + *

All setters through this method are chainable.

* * @return Options for this configuration */ diff --git a/Core/src/main/java/com/intellectualcrafters/configuration/MemoryConfiguration.java b/Core/src/main/java/com/intellectualcrafters/configuration/MemoryConfiguration.java index d22312cae..4148ac9ce 100644 --- a/Core/src/main/java/com/intellectualcrafters/configuration/MemoryConfiguration.java +++ b/Core/src/main/java/com/intellectualcrafters/configuration/MemoryConfiguration.java @@ -23,35 +23,35 @@ public class MemoryConfiguration extends MemorySection implements Configuration * @param defaults Default value provider * @throws IllegalArgumentException Thrown if defaults is null */ - public MemoryConfiguration(final Configuration defaults) { + public MemoryConfiguration(Configuration defaults) { this.defaults = defaults; } @Override - public void addDefault(final String path, final Object value) { + public void addDefault(String path, Object value) { if (path == null) { throw new NullPointerException("Path may not be null"); } - if (defaults == null) { - defaults = new MemoryConfiguration(); + if (this.defaults == null) { + this.defaults = new MemoryConfiguration(); } - - defaults.set(path, value); + + this.defaults.set(path, value); } @Override - public void addDefaults(final Map defaults) { + public void addDefaults(Map defaults) { if (defaults == null) { throw new NullPointerException("Defaults may not be null"); } - - for (final Map.Entry entry : defaults.entrySet()) { + + for (Map.Entry entry : defaults.entrySet()) { addDefault(entry.getKey(), entry.getValue()); } } @Override - public void addDefaults(final Configuration defaults) { + public void addDefaults(Configuration defaults) { if (defaults == null) { throw new NullPointerException("Defaults may not be null"); } @@ -60,19 +60,19 @@ public class MemoryConfiguration extends MemorySection implements Configuration } @Override - public void setDefaults(final Configuration defaults) { + public Configuration getDefaults() { + return this.defaults; + } + + @Override + public void setDefaults(Configuration defaults) { if (defaults == null) { throw new NullPointerException("Defaults may not be null"); } - + this.defaults = defaults; } - @Override - public Configuration getDefaults() { - return defaults; - } - @Override public ConfigurationSection getParent() { return null; @@ -80,10 +80,10 @@ public class MemoryConfiguration extends MemorySection implements Configuration @Override public MemoryConfigurationOptions options() { - if (options == null) { - options = new MemoryConfigurationOptions(this); + if (this.options == null) { + this.options = new MemoryConfigurationOptions(this); } - - return options; + + return this.options; } } diff --git a/Core/src/main/java/com/intellectualcrafters/configuration/MemorySection.java b/Core/src/main/java/com/intellectualcrafters/configuration/MemorySection.java index 5e42c95f6..03a31142d 100644 --- a/Core/src/main/java/com/intellectualcrafters/configuration/MemorySection.java +++ b/Core/src/main/java/com/intellectualcrafters/configuration/MemorySection.java @@ -537,16 +537,16 @@ public class MemorySection implements ConfigurationSection { @Override public List getStringList(String path) { - final List list = getList(path); + List list = getList(path); if (list == null) { return new ArrayList<>(0); } - final List result = new ArrayList<>(); + List result = new ArrayList<>(); - for (final Object object : list) { - if ((object instanceof String) || (isPrimitiveWrapper(object))) { + for (Object object : list) { + if ((object instanceof String) || isPrimitiveWrapper(object)) { result.add(String.valueOf(object)); } } diff --git a/Core/src/main/java/com/intellectualcrafters/plot/PS.java b/Core/src/main/java/com/intellectualcrafters/plot/PS.java index dccd9cf7d..20638a8c5 100644 --- a/Core/src/main/java/com/intellectualcrafters/plot/PS.java +++ b/Core/src/main/java/com/intellectualcrafters/plot/PS.java @@ -53,6 +53,7 @@ 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.File; import java.io.FileInputStream; import java.io.FileOutputStream; @@ -89,6 +90,7 @@ import java.util.zip.ZipInputStream; public class PS { private static PS instance; + public final IPlotMain IMP; private final HashSet plotAreaHashCheck = new HashSet<>(); /** * All plot areas mapped by world (quick world access). @@ -98,6 +100,9 @@ public class PS { * All plot areas mapped by location (quick location based access). */ private final HashMap> plotAreaGrid = new HashMap<>(); + private final int[] version; + private final String platform; + private final Thread thread; public HashMap> clusters_tmp; public HashMap> plots_tmp; public File styleFile; @@ -108,7 +113,6 @@ public class PS { public YamlConfiguration config; public YamlConfiguration storage; public YamlConfiguration commands; - public IPlotMain IMP = null; public TaskManager TASK; public WorldEdit worldedit; public URL update; @@ -117,25 +121,23 @@ public class PS { * All plot areas (quick global access). */ private PlotArea[] plotAreas = new PlotArea[0]; - private File storageFile; private File file = null; // This file - private int[] version; private int[] lastVersion; - private String platform = null; private Database database; - private Thread thread; /** * Initialize PlotSquared with the desired Implementation class. - * @param imp_class + * @param iPlotMain Implementation of {@link IPlotMain} used + * @param platform The platform being used */ - public PS(IPlotMain imp_class, String platform) { + public PS(IPlotMain iPlotMain, String platform) { + PS.instance = this; + this.thread = Thread.currentThread(); + this.IMP = iPlotMain; + this.platform = platform; + this.version = this.IMP.getPluginVersion(); try { - PS.instance = this; - this.thread = Thread.currentThread(); - SetupUtils.generators = new HashMap<>(); - this.IMP = imp_class; new ReflectionUtils(this.IMP.getNMSPackage()); try { URL url = PS.class.getProtectionDomain().getCodeSource().getLocation(); @@ -147,8 +149,6 @@ public class PS { this.file = new File(this.IMP.getDirectory().getParentFile(), "PlotSquared-" + platform + ".jar"); } } - this.version = this.IMP.getPluginVersion(); - this.platform = platform; if (getJavaVersion() < 1.7) { PS.log(C.CONSOLE_JAVA_OUTDATED_1_7); this.IMP.disable(); @@ -194,50 +194,7 @@ public class PS { } // create UUIDWrapper UUIDHandler.implementation = this.IMP.initUUIDHandler(); - TaskManager.runTaskLater(new Runnable() { - @Override - public void run() { - debug("Starting UUID caching"); - UUIDHandler.startCaching(new Runnable() { - @Override - public void run() { - for (Plot plot : getPlots()) { - if (plot.hasOwner() && plot.temp != -1) { - if (UUIDHandler.getName(plot.owner) == null) { - UUIDHandler.implementation.unknown.add(plot.owner); - } - } - } - // Auto clearing - if (Settings.AUTO_CLEAR) { - ExpireManager.IMP = new ExpireManager(); - if (Settings.AUTO_CLEAR_CONFIRMATION) { - ExpireManager.IMP.runConfirmedTask(); - } else { - ExpireManager.IMP.runAutomatedTask(); - } - } - // PlotMe - if (Settings.CONVERT_PLOTME || Settings.CACHE_PLOTME) { - TaskManager.runTaskLater(new Runnable() { - - @Override - public void run() { - if (PS.this.IMP.initPlotMeConverter()) { - PS.log("&c=== IMPORTANT ==="); - PS.log("&cTHIS MESSAGE MAY BE EXTREMELY HELPFUL IF YOU HAVE TROUBLE CONVERTING PLOTME!"); - PS.log("&c - Make sure 'UUID.read-from-disk' is disabled (false)!"); - PS.log("&c - Sometimes the database can be locked, deleting PlotMe.jar beforehand will fix the issue!"); - PS.log("&c - After the conversion is finished, please set 'plotme-convert.enabled' to false in the " - + "'settings.yml'"); - } - } - }, 20); - } - } - }); - } - }, 20); + startUuidCatching(); // create event util class EventUtil.manager = this.IMP.initEventUtil(); // create Hybrid utility class @@ -348,10 +305,6 @@ public class PS { PS.get().IMP.log(StringMan.getString(message)); } - public static void stacktrace() { - System.err.println(StringMan.join(new Exception().getStackTrace(), "\n\tat ")); - } - /** * Log a message to the IPlotMain logger. * @@ -364,6 +317,53 @@ public class PS { } } + private void startUuidCatching() { + TaskManager.runTaskLater(new Runnable() { + @Override + public void run() { + debug("Starting UUID caching"); + UUIDHandler.startCaching(new Runnable() { + @Override + public void run() { + for (Plot plot : getPlots()) { + if (plot.hasOwner() && plot.temp != -1) { + if (UUIDHandler.getName(plot.owner) == null) { + UUIDHandler.implementation.unknown.add(plot.owner); + } + } + } + // Auto clearing + if (Settings.AUTO_CLEAR) { + ExpireManager.IMP = new ExpireManager(); + if (Settings.AUTO_CLEAR_CONFIRMATION) { + ExpireManager.IMP.runConfirmedTask(); + } else { + ExpireManager.IMP.runAutomatedTask(); + } + } + // PlotMe + if (Settings.CONVERT_PLOTME || Settings.CACHE_PLOTME) { + TaskManager.runTaskLater(new Runnable() { + + @Override + public void run() { + if (PS.this.IMP.initPlotMeConverter()) { + PS.log("&c=== IMPORTANT ==="); + PS.log("&cTHIS MESSAGE MAY BE EXTREMELY HELPFUL IF YOU HAVE TROUBLE CONVERTING PLOTME!"); + PS.log("&c - Make sure 'UUID.read-from-disk' is disabled (false)!"); + PS.log("&c - Sometimes the database can be locked, deleting PlotMe.jar beforehand will fix the issue!"); + PS.log("&c - After the conversion is finished, please set 'plotme-convert.enabled' to false in the " + + "'settings.yml'"); + } + } + }, 20); + } + } + }); + } + }, 20); + } + public boolean isMainThread(Thread thread) { return this.thread == thread; } @@ -2398,10 +2398,6 @@ public class PS { return count; } - public int getPlotAreaCount(String world) { - return this.plotAreaMap.size(); - } - public Set getPlotAreas() { HashSet set = new HashSet<>(this.plotAreas.length); Collections.addAll(set, this.plotAreas); 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 2e5838fbd..cfd8d45e6 100644 --- a/Core/src/main/java/com/intellectualcrafters/plot/commands/Area.java +++ b/Core/src/main/java/com/intellectualcrafters/plot/commands/Area.java @@ -43,46 +43,46 @@ import java.util.Set; public class Area extends SubCommand { @Override - public boolean onCommand(final PlotPlayer plr, String[] args) { + public boolean onCommand(final PlotPlayer player, String[] args) { if (args.length == 0) { - C.COMMAND_SYNTAX.send(plr, getUsage()); + C.COMMAND_SYNTAX.send(player, getUsage()); return false; } switch (args[0].toLowerCase()) { case "c": case "setup": case "create": - if (!Permissions.hasPermission(plr, "plots.area.create")) { - C.NO_PERMISSION.send(plr, "plots.area.create"); + if (!Permissions.hasPermission(player, "plots.area.create")) { + C.NO_PERMISSION.send(player, "plots.area.create"); return false; } switch (args.length) { case 1: - C.COMMAND_SYNTAX.send(plr, "/plot area create [world[:id]] [=]..."); + C.COMMAND_SYNTAX.send(player, "/plot area create [world[:id]] [=]..."); return false; case 2: switch (args[1].toLowerCase()) { case "pos1": { // Set position 1 - HybridPlotWorld area = plr.getMeta("area_create_area"); + HybridPlotWorld area = player.getMeta("area_create_area"); if (area == null) { - C.COMMAND_SYNTAX.send(plr, "/plot area create [world[:id]] [=]..."); + C.COMMAND_SYNTAX.send(player, "/plot area create [world[:id]] [=]..."); return false; } - Location location = plr.getLocation(); - plr.setMeta("area_pos1", location); - C.SET_ATTRIBUTE.send(plr, "area_pos1", location.getX() + "," + location.getZ()); - MainUtil.sendMessage(plr, "You will now set pos2: /plot area create pos2" + Location location = player.getLocation(); + player.setMeta("area_pos1", location); + C.SET_ATTRIBUTE.send(player, "area_pos1", location.getX() + "," + location.getZ()); + MainUtil.sendMessage(player, "You will now set pos2: /plot area create pos2" + "\nNote: The chosen plot size may result in the created area not exactly matching your second position."); 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 = player.getMeta("area_create_area"); if (area == null) { - C.COMMAND_SYNTAX.send(plr, "/plot area create [world[:id]] [=]..."); + C.COMMAND_SYNTAX.send(player, "/plot area create [world[:id]] [=]..."); return false; } - Location pos1 = plr.getLocation(); - Location pos2 = plr.getMeta("area_pos1"); + Location pos1 = player.getLocation(); + Location pos2 = player.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); @@ -99,7 +99,7 @@ public class Area extends SubCommand { final RegionWrapper region = new RegionWrapper(bx, tx, bz, tz); Set areas = PS.get().getPlotAreas(area.worldname, region); if (!areas.isEmpty()) { - C.CLUSTER_INTERSECTION.send(plr, areas.iterator().next().toString()); + C.CLUSTER_INTERSECTION.send(player, areas.iterator().next().toString()); return false; } final SetupObject object = new SetupObject(); @@ -125,8 +125,8 @@ public class Area extends SubCommand { final String world = SetupUtils.manager.setupWorld(object); if (WorldUtil.IMP.isWorld(world)) { PS.get().loadWorld(world, null); - C.SETUP_FINISHED.send(plr); - plr.teleport(WorldUtil.IMP.getSpawn(world)); + C.SETUP_FINISHED.send(player); + player.teleport(WorldUtil.IMP.getSpawn(world)); if (area.TERRAIN != 3) { ChunkManager.largeRegionTask(world, region, new RunnableVal() { @Override @@ -136,12 +136,12 @@ public class Area extends SubCommand { }, null); } } else { - MainUtil.sendMessage(plr, "An error occurred while creating the world: " + area.worldname); + MainUtil.sendMessage(player, "An error occurred while creating the world: " + area.worldname); } } }; - if (hasConfirmation(plr)) { - CmdConfirm.addPending(plr, "/plot area create pos2 (Creates world)", run); + if (hasConfirmation(player)) { + CmdConfirm.addPending(player, "/plot area create pos2 (Creates world)", run); } else { run.run(); } @@ -160,7 +160,7 @@ public class Area extends SubCommand { final HybridPlotWorld pa = new HybridPlotWorld(object.world, id, new HybridGen(), null, null); PlotArea other = PS.get().getPlotArea(pa.worldname, id); if (other != null && Objects.equals(pa.id, other.id)) { - C.SETUP_WORLD_TAKEN.send(plr, pa.toString()); + C.SETUP_WORLD_TAKEN.send(player, pa.toString()); return false; } Set areas = PS.get().getPlotAreas(pa.worldname); @@ -172,7 +172,7 @@ public class Area extends SubCommand { for (int i = 2; i < args.length; i++) { String[] pair = args[i].split("="); if (pair.length != 2) { - C.COMMAND_SYNTAX.send(plr, "/plot area create [world[:id]] [=]..."); + C.COMMAND_SYNTAX.send(player, "/plot area create [world[:id]] [=]..."); return false; } switch (pair[0].toLowerCase()) { @@ -218,13 +218,13 @@ public class Area extends SubCommand { object.type = pa.TYPE; break; default: - C.COMMAND_SYNTAX.send(plr, "/plot area create [world[:id]] [=]..."); + C.COMMAND_SYNTAX.send(player, "/plot area create [world[:id]] [=]..."); return false; } } if (pa.TYPE != 2) { if (WorldUtil.IMP.isWorld(pa.worldname)) { - C.SETUP_WORLD_TAKEN.send(plr, pa.worldname); + C.SETUP_WORLD_TAKEN.send(player, pa.worldname); return false; } Runnable run = new Runnable() { @@ -241,10 +241,10 @@ public class Area extends SubCommand { object.setupGenerator = "PlotSquared"; String world = SetupUtils.manager.setupWorld(object); if (WorldUtil.IMP.isWorld(world)) { - C.SETUP_FINISHED.send(plr); - plr.teleport(WorldUtil.IMP.getSpawn(world)); + C.SETUP_FINISHED.send(player); + player.teleport(WorldUtil.IMP.getSpawn(world)); } else { - MainUtil.sendMessage(plr, "An error occurred while creating the world: " + pa.worldname); + MainUtil.sendMessage(player, "An error occurred while creating the world: " + pa.worldname); } try { PS.get().config.save(PS.get().configFile); @@ -253,55 +253,55 @@ public class Area extends SubCommand { } } }; - if (hasConfirmation(plr)) { - CmdConfirm.addPending(plr, "/plot area " + StringMan.join(args, " "), run); + if (hasConfirmation(player)) { + CmdConfirm.addPending(player, "/plot area " + StringMan.join(args, " "), run); } else { run.run(); } return true; } if (pa.id == null) { - C.COMMAND_SYNTAX.send(plr, "/plot area create [world[:id]] [=]..."); + C.COMMAND_SYNTAX.send(player, "/plot area create [world[:id]] [=]..."); return false; } if (WorldUtil.IMP.isWorld(pa.worldname)) { - if (!plr.getLocation().getWorld().equals(pa.worldname)) { - plr.teleport(WorldUtil.IMP.getSpawn(pa.worldname)); + if (!player.getLocation().getWorld().equals(pa.worldname)) { + player.teleport(WorldUtil.IMP.getSpawn(pa.worldname)); } } else { object.terrain = 0; object.type = 0; SetupUtils.manager.setupWorld(object); - plr.teleport(WorldUtil.IMP.getSpawn(pa.worldname)); + player.teleport(WorldUtil.IMP.getSpawn(pa.worldname)); } - plr.setMeta("area_create_area", pa); - MainUtil.sendMessage(plr, "$1Go to the first corner and use: $2/plot area create pos1"); + player.setMeta("area_create_area", pa); + MainUtil.sendMessage(player, "$1Go to the first corner and use: $2/plot area create pos1"); break; } return true; case "i": case "info": { - if (!Permissions.hasPermission(plr, "plots.area.info")) { - C.NO_PERMISSION.send(plr, "plots.area.info"); + if (!Permissions.hasPermission(player, "plots.area.info")) { + C.NO_PERMISSION.send(player, "plots.area.info"); return false; } PlotArea area; switch (args.length) { case 1: - area = plr.getApplicablePlotArea(); + area = player.getApplicablePlotArea(); break; case 2: area = PS.get().getPlotAreaByString(args[1]); break; default: - C.COMMAND_SYNTAX.send(plr, "/plot area info [area]"); + C.COMMAND_SYNTAX.send(player, "/plot area info [area]"); return false; } if (area == null) { if (args.length == 2) { - C.NOT_VALID_PLOT_WORLD.send(plr, args[1]); + C.NOT_VALID_PLOT_WORLD.send(player, args[1]); } else { - C.NOT_IN_PLOT_WORLD.send(plr); + C.NOT_IN_PLOT_WORLD.send(player); } return false; } @@ -331,13 +331,13 @@ public class Area extends SubCommand { + "\n$1Clusters: $2" + clusters + "\n$1Region: $2" + region + "\n$1Generator: $2" + generator; - MainUtil.sendMessage(plr, C.PLOT_INFO_HEADER.s() + '\n' + value + '\n' + C.PLOT_INFO_FOOTER.s(), false); + MainUtil.sendMessage(player, C.PLOT_INFO_HEADER.s() + '\n' + value + '\n' + C.PLOT_INFO_FOOTER.s(), false); return true; } case "l": case "list": - if (!Permissions.hasPermission(plr, "plots.area.list")) { - C.NO_PERMISSION.send(plr, "plots.area.list"); + if (!Permissions.hasPermission(player, "plots.area.list")) { + C.NO_PERMISSION.send(player, "plots.area.list"); return false; } int page; @@ -351,11 +351,11 @@ public class Area extends SubCommand { break; } default: - C.COMMAND_SYNTAX.send(plr, "/plot area list [#]"); + C.COMMAND_SYNTAX.send(player, "/plot area list [#]"); return false; } ArrayList areas = new ArrayList<>(PS.get().getPlotAreas()); - paginate(plr, areas, 8, page, new RunnableVal3() { + paginate(player, areas, 8, page, new RunnableVal3() { @Override public void run(Integer i, PlotArea area, PlotMessage message) { String name; @@ -397,17 +397,17 @@ public class Area extends SubCommand { case "clear": case "reset": case "regenerate": { - if (!Permissions.hasPermission(plr, "plots.area.regen")) { - C.NO_PERMISSION.send(plr, "plots.area.regen"); + if (!Permissions.hasPermission(player, "plots.area.regen")) { + C.NO_PERMISSION.send(player, "plots.area.regen"); return false; } - final PlotArea area = plr.getApplicablePlotArea(); + final PlotArea area = player.getApplicablePlotArea(); if (area == null) { - C.NOT_IN_PLOT_WORLD.send(plr); + C.NOT_IN_PLOT_WORLD.send(player); return false; } if (area.TYPE != 2) { - MainUtil.sendMessage(plr, "$4Stop the server and delete: " + area.worldname + "/region"); + MainUtil.sendMessage(player, "$4Stop the server and delete: " + area.worldname + "/region"); return false; } ChunkManager.largeRegionTask(area.worldname, area.getRegion(), new RunnableVal() { @@ -423,17 +423,17 @@ public class Area extends SubCommand { case "teleport": case "visit": case "tp": - if (!Permissions.hasPermission(plr, "plots.area.tp")) { - C.NO_PERMISSION.send(plr, "plots.area.tp"); + if (!Permissions.hasPermission(player, "plots.area.tp")) { + C.NO_PERMISSION.send(player, "plots.area.tp"); return false; } if (args.length != 2) { - C.COMMAND_SYNTAX.send(plr, "/plot visit [area]"); + C.COMMAND_SYNTAX.send(player, "/plot visit [area]"); return false; } PlotArea area = PS.get().getPlotAreaByString(args[1]); if (area == null) { - C.NOT_VALID_PLOT_WORLD.send(plr, args[1]); + C.NOT_VALID_PLOT_WORLD.send(player, args[1]); return false; } Location center; @@ -445,18 +445,18 @@ public class Area extends SubCommand { region.minZ + (region.maxZ - region.minZ) / 2); center.setY(WorldUtil.IMP.getHighestBlock(area.worldname, center.getX(), center.getZ())); } - plr.teleport(center); + player.teleport(center); return true; case "delete": case "remove": - MainUtil.sendMessage(plr, "$1World creation settings may be stored in multiple locations:" + MainUtil.sendMessage(player, "$1World creation settings may be stored in multiple locations:" + "\n$3 - $2Bukkit bukkit.yml" + "\n$3 - $2PlotSquared settings.yml" + "\n$3 - $2Multiverse worlds.yml (or any world management plugin)" + "\n$1Stop the server and delete it from these locations."); return true; } - C.COMMAND_SYNTAX.send(plr, getUsage()); + C.COMMAND_SYNTAX.send(player, getUsage()); return false; } diff --git a/Core/src/main/java/com/intellectualcrafters/plot/commands/Clear.java b/Core/src/main/java/com/intellectualcrafters/plot/commands/Clear.java index f16381879..712d53fa1 100644 --- a/Core/src/main/java/com/intellectualcrafters/plot/commands/Clear.java +++ b/Core/src/main/java/com/intellectualcrafters/plot/commands/Clear.java @@ -12,6 +12,7 @@ import com.intellectualcrafters.plot.util.Permissions; import com.intellectualcrafters.plot.util.SetQueue; import com.intellectualcrafters.plot.util.TaskManager; import com.plotsquared.general.commands.CommandDeclaration; + import java.util.Set; @CommandDeclaration(command = "clear", @@ -20,7 +21,7 @@ import java.util.Set; category = CommandCategory.APPEARANCE, usage = "/plot clear [id]", aliases = "reset", - confirmation=true) + confirmation = true) public class Clear extends SubCommand { @Override diff --git a/Core/src/main/java/com/intellectualcrafters/plot/commands/DebugExec.java b/Core/src/main/java/com/intellectualcrafters/plot/commands/DebugExec.java index dc2de88c9..dbb964df5 100644 --- a/Core/src/main/java/com/intellectualcrafters/plot/commands/DebugExec.java +++ b/Core/src/main/java/com/intellectualcrafters/plot/commands/DebugExec.java @@ -37,6 +37,7 @@ import com.intellectualcrafters.plot.util.WorldUtil; import com.plotsquared.general.commands.Command; import com.plotsquared.general.commands.CommandDeclaration; import com.plotsquared.listener.WEManager; + import java.io.File; import java.io.IOException; import java.nio.charset.StandardCharsets; @@ -46,6 +47,7 @@ import java.util.Date; import java.util.HashMap; import java.util.List; import java.util.UUID; + import javax.script.Bindings; import javax.script.ScriptContext; import javax.script.ScriptEngine; @@ -145,7 +147,7 @@ public class DebugExec extends SubCommand { @Override public boolean onCommand(final PlotPlayer player, String[] args) { - java.util.List allowed_params = + List allowed_params = Arrays.asList("calibrate-analysis", "remove-flag", "stop-expire", "start-expire", "show-expired", "update-expired", "seen", "list-scripts"); if (args.length > 0) { String arg = args[0].toLowerCase(); @@ -331,7 +333,7 @@ public class DebugExec extends SubCommand { } break; case "list-scripts": - final String path = PS.get().IMP.getDirectory() + File.separator + "scripts"; + String path = PS.get().IMP.getDirectory() + File.separator + "scripts"; File folder = new File(path); File[] filesArray = folder.listFiles(); @@ -355,8 +357,7 @@ public class DebugExec extends SubCommand { @Override public void run(Integer i, File file, PlotMessage message) { - String name; - name = file.getName(); + String name = file.getName(); message.text("[").color("$3") .text(i + "").color("$1") @@ -416,7 +417,7 @@ public class DebugExec extends SubCommand { default: script = StringMan.join(args, " "); } - if (!ConsolePlayer.isConsole(player)) { + if (!(player instanceof ConsolePlayer)) { MainUtil.sendMessage(player, C.NOT_CONSOLE); return false; } @@ -436,13 +437,13 @@ public class DebugExec extends SubCommand { } catch (ScriptException e) { e.printStackTrace(); } - ConsolePlayer.getConsole().sendMessage("> " + (System.currentTimeMillis() - start) + "ms -> " + result); + PS.log("> " + (System.currentTimeMillis() - start) + "ms -> " + result); } }); } else { long start = System.currentTimeMillis(); Object result = this.engine.eval(script, this.scope); - ConsolePlayer.getConsole().sendMessage("> " + (System.currentTimeMillis() - start) + "ms -> " + result); + PS.log("> " + (System.currentTimeMillis() - start) + "ms -> " + result); } return true; } catch (ScriptException e) { diff --git a/Core/src/main/java/com/intellectualcrafters/plot/commands/Delete.java b/Core/src/main/java/com/intellectualcrafters/plot/commands/Delete.java index e74edac35..fac36dbc0 100644 --- a/Core/src/main/java/com/intellectualcrafters/plot/commands/Delete.java +++ b/Core/src/main/java/com/intellectualcrafters/plot/commands/Delete.java @@ -11,6 +11,7 @@ import com.intellectualcrafters.plot.util.MainUtil; import com.intellectualcrafters.plot.util.Permissions; import com.intellectualcrafters.plot.util.TaskManager; import com.plotsquared.general.commands.CommandDeclaration; + import java.util.HashSet; @CommandDeclaration( @@ -21,7 +22,7 @@ import java.util.HashSet; aliases = {"dispose", "del"}, category = CommandCategory.CLAIMING, requiredType = RequiredType.NONE, - confirmation=true) + confirmation = true) public class Delete extends SubCommand { @Override diff --git a/Core/src/main/java/com/intellectualcrafters/plot/commands/Deny.java b/Core/src/main/java/com/intellectualcrafters/plot/commands/Deny.java index 2dd84d50c..db878ee83 100644 --- a/Core/src/main/java/com/intellectualcrafters/plot/commands/Deny.java +++ b/Core/src/main/java/com/intellectualcrafters/plot/commands/Deny.java @@ -31,8 +31,8 @@ public class Deny extends SubCommand { @Override public boolean onCommand(PlotPlayer plr, String[] args) { - Location loc = plr.getLocation(); - Plot plot = loc.getPlotAbs(); + Location location = plr.getLocation(); + Plot plot = location.getPlotAbs(); if (plot == null) { return !sendMessage(plr, C.NOT_IN_PLOT); } diff --git a/Core/src/main/java/com/intellectualcrafters/plot/commands/Done.java b/Core/src/main/java/com/intellectualcrafters/plot/commands/Done.java index 165e585ef..231276d33 100644 --- a/Core/src/main/java/com/intellectualcrafters/plot/commands/Done.java +++ b/Core/src/main/java/com/intellectualcrafters/plot/commands/Done.java @@ -19,7 +19,7 @@ import com.plotsquared.general.commands.CommandDeclaration; description = "Mark a plot as done", permission = "plots.done", category = CommandCategory.SETTINGS, - requiredType = RequiredType.NONE) + requiredType = RequiredType.PLAYER) public class Done extends SubCommand { @Override diff --git a/Core/src/main/java/com/intellectualcrafters/plot/commands/Download.java b/Core/src/main/java/com/intellectualcrafters/plot/commands/Download.java index 441ea13fe..b1b0bd1bd 100644 --- a/Core/src/main/java/com/intellectualcrafters/plot/commands/Download.java +++ b/Core/src/main/java/com/intellectualcrafters/plot/commands/Download.java @@ -22,7 +22,7 @@ import java.net.URL; command = "download", aliases = {"dl"}, category = CommandCategory.SCHEMATIC, - requiredType = RequiredType.NONE, + requiredType = RequiredType.PLAYER, description = "Download your plot", permission = "plots.download") public class Download extends SubCommand { diff --git a/Core/src/main/java/com/intellectualcrafters/plot/commands/FlagCmd.java b/Core/src/main/java/com/intellectualcrafters/plot/commands/FlagCmd.java index d1b3bad8b..de2109dab 100644 --- a/Core/src/main/java/com/intellectualcrafters/plot/commands/FlagCmd.java +++ b/Core/src/main/java/com/intellectualcrafters/plot/commands/FlagCmd.java @@ -13,6 +13,7 @@ import com.intellectualcrafters.plot.util.MainUtil; import com.intellectualcrafters.plot.util.Permissions; import com.intellectualcrafters.plot.util.StringMan; import com.plotsquared.general.commands.CommandDeclaration; + import java.util.ArrayList; import java.util.Arrays; import java.util.HashMap; @@ -24,7 +25,7 @@ import java.util.Map; usage = "/plot flag ", description = "Set plot flags", category = CommandCategory.SETTINGS, - requiredType = RequiredType.NONE, + requiredType = RequiredType.PLAYER, permission = "plots.flag") public class FlagCmd extends SubCommand { @@ -75,18 +76,18 @@ public class FlagCmd extends SubCommand { MainUtil.sendMessage(player, C.COMMAND_SYNTAX, "/plot flag info "); return false; } - AbstractFlag af = FlagManager.getFlag(args[1]); - if (af == null) { + AbstractFlag flag = FlagManager.getFlag(args[1]); + if (flag == null) { MainUtil.sendMessage(player, C.NOT_VALID_FLAG); MainUtil.sendMessage(player, C.COMMAND_SYNTAX, "/plot flag info "); return false; } // flag key - MainUtil.sendMessage(player, C.FLAG_KEY, af.getKey()); + MainUtil.sendMessage(player, C.FLAG_KEY, flag.getKey()); // flag type - MainUtil.sendMessage(player, C.FLAG_TYPE, af.value.getClass().getSimpleName()); + MainUtil.sendMessage(player, C.FLAG_TYPE, flag.value.getClass().getSimpleName()); // Flag type description - MainUtil.sendMessage(player, C.FLAG_DESC, af.getValueDesc()); + MainUtil.sendMessage(player, C.FLAG_DESC, flag.getValueDesc()); return true; } case "set": { @@ -167,7 +168,7 @@ public class FlagCmd extends SubCommand { MainUtil.sendMessage(player, C.FLAG_REMOVED); return true; } - case "add": { + case "add": if (!Permissions.hasPermission(player, "plots.flag.add")) { MainUtil.sendMessage(player, C.NO_PERMISSION, "plots.flag.add"); return false; @@ -206,7 +207,6 @@ public class FlagCmd extends SubCommand { } MainUtil.sendMessage(player, C.FLAG_ADDED); return true; - } case "list": if (!Permissions.hasPermission(player, "plots.flag.list")) { MainUtil.sendMessage(player, C.NO_PERMISSION, "plots.flag.list"); @@ -217,12 +217,12 @@ public class FlagCmd extends SubCommand { return false; } HashMap> flags = new HashMap<>(); - for (AbstractFlag af : FlagManager.getFlags()) { - String type = af.value.getClass().getSimpleName().replaceAll("Value", ""); + for (AbstractFlag flag1 : FlagManager.getFlags()) { + String type = flag1.value.getClass().getSimpleName().replaceAll("Value", ""); if (!flags.containsKey(type)) { flags.put(type, new ArrayList()); } - flags.get(type).add(af.getKey()); + flags.get(type).add(flag1.getKey()); } String message = ""; String prefix = ""; diff --git a/Core/src/main/java/com/intellectualcrafters/plot/commands/Inbox.java b/Core/src/main/java/com/intellectualcrafters/plot/commands/Inbox.java index 2c90058ab..bac2b4a1c 100644 --- a/Core/src/main/java/com/intellectualcrafters/plot/commands/Inbox.java +++ b/Core/src/main/java/com/intellectualcrafters/plot/commands/Inbox.java @@ -1,5 +1,6 @@ package com.intellectualcrafters.plot.commands; +import com.google.common.base.Optional; import com.intellectualcrafters.plot.config.C; import com.intellectualcrafters.plot.object.Plot; import com.intellectualcrafters.plot.object.PlotPlayer; @@ -66,8 +67,14 @@ public class Inbox extends SubCommand { @Override public boolean onCommand(final PlotPlayer player, String[] args) { - final Plot plot = player.getCurrentPlot(); + if (plot == null) { + sendMessage(player, C.NOT_IN_PLOT); + return false; + } else if (!plot.hasOwner()) { + sendMessage(player, C.PLOT_UNOWNED); + return false; + } if (args.length == 0) { sendMessage(player, C.COMMAND_SYNTAX, "/plot inbox [inbox] [delete |clear|page]"); for (final CommentInbox inbox : CommentManager.inboxes.values()) { @@ -155,9 +162,9 @@ public class Inbox extends SubCommand { sendMessage(player, C.NO_PERM_INBOX_MODIFY); } inbox.clearInbox(plot); - ArrayList comments = plot.getSettings().getComments(inbox.toString()); - if (comments != null) { - plot.getSettings().removeComments(comments); + Optional> comments = plot.getSettings().getComments(inbox.toString()); + if (comments.isPresent()) { + plot.getSettings().removeComments(comments.get()); } MainUtil.sendMessage(player, C.COMMENT_REMOVED, "*"); return true; @@ -182,11 +189,7 @@ public class Inbox extends SubCommand { displayComments(player, value, page); } })) { - if (plot == null) { - sendMessage(player, C.NOT_IN_PLOT); - } else { - sendMessage(player, C.PLOT_UNOWNED); - } + sendMessage(player, C.PLOT_UNOWNED); return false; } return true; diff --git a/Core/src/main/java/com/intellectualcrafters/plot/commands/Kick.java b/Core/src/main/java/com/intellectualcrafters/plot/commands/Kick.java index 16a817f5f..c681ff406 100644 --- a/Core/src/main/java/com/intellectualcrafters/plot/commands/Kick.java +++ b/Core/src/main/java/com/intellectualcrafters/plot/commands/Kick.java @@ -26,8 +26,8 @@ public class Kick extends SubCommand { @Override public boolean onCommand(PlotPlayer plr, String[] args) { - Location loc = plr.getLocation(); - Plot plot = loc.getPlot(); + Location location = plr.getLocation(); + Plot plot = location.getPlot(); if (plot == null) { return !sendMessage(plr, C.NOT_IN_PLOT); } @@ -40,8 +40,8 @@ public class Kick extends SubCommand { MainUtil.sendMessage(plr, C.INVALID_PLAYER, args[0]); return false; } - Location otherLoc = player.getLocation(); - if (!plr.getLocation().getWorld().equals(otherLoc.getWorld()) || !plot.equals(otherLoc.getPlot())) { + Location location2 = player.getLocation(); + if (!plr.getLocation().getWorld().equals(location2.getWorld()) || !plot.equals(location2.getPlot())) { MainUtil.sendMessage(plr, C.INVALID_PLAYER, args[0]); return false; } @@ -49,7 +49,7 @@ public class Kick extends SubCommand { C.CANNOT_KICK_PLAYER.send(plr, player.getName()); return false; } - Location spawn = WorldUtil.IMP.getSpawn(loc.getWorld()); + Location spawn = WorldUtil.IMP.getSpawn(location.getWorld()); C.YOU_GOT_KICKED.send(player); if (plot.equals(spawn.getPlot())) { Location newSpawn = WorldUtil.IMP.getSpawn(player); 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 249fbfa54..154a214aa 100644 --- a/Core/src/main/java/com/intellectualcrafters/plot/commands/MainCommand.java +++ b/Core/src/main/java/com/intellectualcrafters/plot/commands/MainCommand.java @@ -14,6 +14,7 @@ import com.intellectualcrafters.plot.util.EconHandler; import com.intellectualcrafters.plot.util.Permissions; import com.plotsquared.general.commands.Command; import com.plotsquared.general.commands.CommandDeclaration; + import java.util.Arrays; /** @@ -113,14 +114,6 @@ public class MainCommand extends Command { return instance; } - @Deprecated - /** - * @Deprecated legacy - */ - public void addCommand(SubCommand command) { - PS.debug("Command registration is now done during instantiation"); - } - public static boolean onCommand(final PlotPlayer player, String... args) { if (args.length >= 1 && args[0].contains(":")) { String[] split2 = args[0].split(":"); @@ -181,6 +174,14 @@ public class MainCommand extends Command { return true; } + @Deprecated + /** + * @Deprecated legacy + */ + public void addCommand(SubCommand command) { + PS.debug("Command registration is now done during instantiation"); + } + @Override public void execute(PlotPlayer player, String[] args, RunnableVal3 confirm, RunnableVal2 whenDone) { // Clear perm caching // @@ -192,7 +193,8 @@ public class MainCommand extends Command { if (args.length >= 2) { PlotArea area = player.getApplicablePlotArea(); Plot newPlot = Plot.fromString(area, args[0]); - if (newPlot != null && (ConsolePlayer.isConsole(player) || newPlot.getArea().equals(area) || Permissions.hasPermission(player, C.PERMISSION_ADMIN)) && !newPlot.isDenied(player.getUUID())) { + if (newPlot != null && (player instanceof ConsolePlayer || newPlot.getArea().equals(area) || Permissions + .hasPermission(player, C.PERMISSION_ADMIN)) && !newPlot.isDenied(player.getUUID())) { // Save meta loc = player.getMeta("location"); plot = player.getMeta("lastplot"); 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 ed6215494..3dcb50e64 100644 --- a/Core/src/main/java/com/intellectualcrafters/plot/commands/Merge.java +++ b/Core/src/main/java/com/intellectualcrafters/plot/commands/Merge.java @@ -22,8 +22,8 @@ import java.util.UUID; description = "Merge the plot you are standing on, with another plot", permission = "plots.merge", usage = "/plot merge [removeroads]", category = CommandCategory.SETTINGS, - requiredType = RequiredType.NONE, - confirmation=true) + requiredType = RequiredType.PLAYER, + confirmation = true) public class Merge extends SubCommand { public static final String[] values = new String[]{"north", "east", "south", "west", "auto"}; diff --git a/Core/src/main/java/com/intellectualcrafters/plot/commands/Purge.java b/Core/src/main/java/com/intellectualcrafters/plot/commands/Purge.java index 3d9c482c8..73eb77d90 100644 --- a/Core/src/main/java/com/intellectualcrafters/plot/commands/Purge.java +++ b/Core/src/main/java/com/intellectualcrafters/plot/commands/Purge.java @@ -11,6 +11,7 @@ import com.intellectualcrafters.plot.util.CmdConfirm; import com.intellectualcrafters.plot.util.StringMan; import com.intellectualcrafters.plot.util.UUIDHandler; import com.plotsquared.general.commands.CommandDeclaration; +import com.plotsquared.listener.PlotListener; import java.util.HashMap; import java.util.HashSet; @@ -24,7 +25,7 @@ import java.util.UUID; description = "Purge all plots for a world", category = CommandCategory.ADMINISTRATION, requiredType = RequiredType.CONSOLE, - confirmation=true) + confirmation = true) public class Purge extends SubCommand { @Override @@ -145,12 +146,15 @@ public class Purge extends SubCommand { Runnable run = new Runnable() { @Override public void run() { - HashSet ids = new HashSet(); + HashSet ids = new HashSet<>(); for (Plot plot : toDelete) { if (plot.temp != Integer.MAX_VALUE) { ids.add(plot.temp); - PlotArea area = plot.getArea(); plot.getArea().removePlot(plot.getId()); + for (PlotPlayer pp : plot.getPlayersInPlot()) { + PlotListener.plotEntry(pp, plot); + } + plot.removeSign(); } } DBFunc.purgeIds(ids); diff --git a/Core/src/main/java/com/intellectualcrafters/plot/commands/SchematicCmd.java b/Core/src/main/java/com/intellectualcrafters/plot/commands/SchematicCmd.java index ba5bc8363..3ac516f24 100644 --- a/Core/src/main/java/com/intellectualcrafters/plot/commands/SchematicCmd.java +++ b/Core/src/main/java/com/intellectualcrafters/plot/commands/SchematicCmd.java @@ -141,7 +141,7 @@ public class SchematicCmd extends SubCommand { // } case "saveall": case "exportall": { - if (!ConsolePlayer.isConsole(plr)) { + if (!(plr instanceof ConsolePlayer)) { MainUtil.sendMessage(plr, C.NOT_CONSOLE); return false; } @@ -197,10 +197,9 @@ public class SchematicCmd extends SubCommand { MainUtil.sendMessage(plr, C.NO_PLOT_PERMS); return false; } - Plot p2 = plot; loc.getWorld(); Collection plots = new ArrayList(); - plots.add(p2); + plots.add(plot); boolean result = SchematicHandler.manager.exportAll(plots, null, null, new Runnable() { @Override public void run() { diff --git a/Core/src/main/java/com/intellectualcrafters/plot/commands/Target.java b/Core/src/main/java/com/intellectualcrafters/plot/commands/Target.java index 17e4214f4..ff4f73840 100644 --- a/Core/src/main/java/com/intellectualcrafters/plot/commands/Target.java +++ b/Core/src/main/java/com/intellectualcrafters/plot/commands/Target.java @@ -15,7 +15,7 @@ import com.plotsquared.general.commands.CommandDeclaration; usage = "/plot target <|nearest>", description = "Target a plot with your compass", permission = "plots.target", - requiredType = RequiredType.NONE, + requiredType = RequiredType.PLAYER, category = CommandCategory.INFO) public class Target extends SubCommand { 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 b03fbf913..f120f9433 100644 --- a/Core/src/main/java/com/intellectualcrafters/plot/config/C.java +++ b/Core/src/main/java/com/intellectualcrafters/plot/config/C.java @@ -3,9 +3,9 @@ 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; @@ -621,14 +621,14 @@ public enum C { * What locale category should this translation fall under. */ private final String category; - /** - * Translated. - */ - private String s; /** * Should the string be prefixed. */ private final boolean prefix; + /** + * Translated. + */ + private String s; /** * Constructor. @@ -799,7 +799,7 @@ public enum C { public void send(CommandCaller plr, Object... args) { String msg = format(this, args); if (plr == null) { - ConsolePlayer.getConsole().sendMessage(msg); + PS.log(msg); } else { plr.sendMessage(msg); } diff --git a/Core/src/main/java/com/intellectualcrafters/plot/config/ConfigurationNode.java b/Core/src/main/java/com/intellectualcrafters/plot/config/ConfigurationNode.java index cd24cef08..59197c9a7 100644 --- a/Core/src/main/java/com/intellectualcrafters/plot/config/ConfigurationNode.java +++ b/Core/src/main/java/com/intellectualcrafters/plot/config/ConfigurationNode.java @@ -19,7 +19,7 @@ public class ConfigurationNode { private final SettingValue type; private Object value; - public ConfigurationNode(String constant, Object defaultValue, String description, SettingValue type, boolean required) { + public ConfigurationNode(String constant, Object defaultValue, String description, SettingValue type) { this.constant = constant; this.defaultValue = defaultValue; this.description = description; 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 d911f5748..87f873cce 100644 --- a/Core/src/main/java/com/intellectualcrafters/plot/config/Settings.java +++ b/Core/src/main/java/com/intellectualcrafters/plot/config/Settings.java @@ -6,16 +6,11 @@ import java.util.List; /** * Updater and DB settings * - - */ public class Settings { public static boolean USE_SQLUUIDHANDLER = false; public static boolean AUTO_PURGE = false; - /** - * - */ public static boolean UPDATE_NOTIFICATIONS = true; public static boolean FAST_CLEAR = false; @@ -163,8 +158,6 @@ public class Settings { /** * Database settings - * - */ public static class DB { /** diff --git a/Core/src/main/java/com/intellectualcrafters/plot/database/AbstractDB.java b/Core/src/main/java/com/intellectualcrafters/plot/database/AbstractDB.java index 5521dff8c..9aaf2e693 100644 --- a/Core/src/main/java/com/intellectualcrafters/plot/database/AbstractDB.java +++ b/Core/src/main/java/com/intellectualcrafters/plot/database/AbstractDB.java @@ -139,8 +139,7 @@ public interface AbstractDB { /** * Set plot flags. - * - * @param plot Plot Object + * @param plot Plot Object * @param flags flags to set (flag[]) */ void setFlags(Plot plot, Collection flags); diff --git a/Core/src/main/java/com/intellectualcrafters/plot/database/DBFunc.java b/Core/src/main/java/com/intellectualcrafters/plot/database/DBFunc.java index a9ead64b5..7461a9330 100644 --- a/Core/src/main/java/com/intellectualcrafters/plot/database/DBFunc.java +++ b/Core/src/main/java/com/intellectualcrafters/plot/database/DBFunc.java @@ -290,7 +290,7 @@ public class DBFunc { * @param comment */ public static void removeComment(Plot plot, PlotComment comment) { - if (plot != null && plot.temp == -1) { + if (plot.temp == -1) { return; } DBFunc.dbManager.removeComment(plot, comment); 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 4ff60e809..d30162440 100644 --- a/Core/src/main/java/com/intellectualcrafters/plot/database/SQLManager.java +++ b/Core/src/main/java/com/intellectualcrafters/plot/database/SQLManager.java @@ -1443,18 +1443,19 @@ public class SQLManager implements AbstractDB { if (plot.temp > 0) { return plot.temp; } - PreparedStatement stmt = this.connection.prepareStatement( - "SELECT `id` FROM `" + this.prefix + "plot` WHERE `plot_id_x` = ? AND `plot_id_z` = ? AND world = ? ORDER BY `timestamp` ASC"); - stmt.setInt(1, plot.getId().x); - stmt.setInt(2, plot.getId().y); - stmt.setString(3, plot.getArea().toString()); - ResultSet r = stmt.executeQuery(); - int id = Integer.MAX_VALUE; - while (r.next()) { - id = r.getInt("id"); + int id; + try (PreparedStatement statement = this.connection.prepareStatement( + "SELECT `id` FROM `" + this.prefix + "plot` WHERE `plot_id_x` = ? AND `plot_id_z` = ? AND world = ? ORDER BY `timestamp` ASC")) { + statement.setInt(1, plot.getId().x); + statement.setInt(2, plot.getId().y); + statement.setString(3, plot.getArea().toString()); + try (ResultSet resultSet = statement.executeQuery()) { + id = Integer.MAX_VALUE; + while (resultSet.next()) { + id = resultSet.getInt("id"); + } + } } - r.close(); - stmt.close(); if (id == Integer.MAX_VALUE || id == 0) { if (plot.temp > 0) { return plot.temp; @@ -1625,17 +1626,17 @@ public class SQLManager implements AbstractDB { /* * Getting plots */ - Statement stmt = this.connection.createStatement(); + Statement statement = this.connection.createStatement(); int id; String o; UUID user; - try (ResultSet r = stmt + try (ResultSet resultSet = statement .executeQuery("SELECT `id`, `plot_id_x`, `plot_id_z`, `owner`, `world`, `timestamp` FROM `" + this.prefix + "plot`")) { ArrayList toDelete = new ArrayList<>(); - while (r.next()) { - PlotId plot_id = new PlotId(r.getInt("plot_id_x"), r.getInt("plot_id_z")); - id = r.getInt("id"); - String areaid = r.getString("world"); + while (resultSet.next()) { + PlotId plot_id = new PlotId(resultSet.getInt("plot_id_x"), resultSet.getInt("plot_id_z")); + id = resultSet.getInt("id"); + String areaid = resultSet.getString("world"); if (!areas.contains(areaid)) { if (Settings.AUTO_PURGE) { toDelete.add(id); @@ -1649,13 +1650,13 @@ public class SQLManager implements AbstractDB { } } } - o = r.getString("owner"); + o = resultSet.getString("owner"); user = uuids.get(o); if (user == null) { user = UUID.fromString(o); uuids.put(o, user); } - Timestamp timestamp = r.getTimestamp("timestamp"); + Timestamp timestamp = resultSet.getTimestamp("timestamp"); long time = timestamp.getTime(); Plot p = new Plot(plot_id, user, new HashSet(), new HashSet(), new HashSet(), "", null, null, null, new boolean[]{false, false, false, false}, time, id); @@ -1682,7 +1683,7 @@ public class SQLManager implements AbstractDB { deleteRows(toDelete, this.prefix + "plot", "id"); } if (Settings.CACHE_RATINGS) { - try (ResultSet r = stmt.executeQuery("SELECT `plot_plot_id`, `player`, `rating` FROM `" + this.prefix + "plot_rating`")) { + try (ResultSet r = statement.executeQuery("SELECT `plot_plot_id`, `player`, `rating` FROM `" + this.prefix + "plot_rating`")) { ArrayList toDelete = new ArrayList<>(); while (r.next()) { id = r.getInt("plot_plot_id"); @@ -1709,7 +1710,7 @@ public class SQLManager implements AbstractDB { /* * Getting helpers */ - try (ResultSet r = stmt.executeQuery("SELECT `user_uuid`, `plot_plot_id` FROM `" + this.prefix + "plot_helpers`")) { + try (ResultSet r = statement.executeQuery("SELECT `user_uuid`, `plot_plot_id` FROM `" + this.prefix + "plot_helpers`")) { ArrayList toDelete = new ArrayList<>(); while (r.next()) { id = r.getInt("plot_plot_id"); @@ -1735,7 +1736,7 @@ public class SQLManager implements AbstractDB { /* * Getting trusted */ - try (ResultSet r = stmt.executeQuery("SELECT `user_uuid`, `plot_plot_id` FROM `" + this.prefix + "plot_trusted`")) { + try (ResultSet r = statement.executeQuery("SELECT `user_uuid`, `plot_plot_id` FROM `" + this.prefix + "plot_trusted`")) { ArrayList toDelete = new ArrayList<>(); while (r.next()) { id = r.getInt("plot_plot_id"); @@ -1761,7 +1762,7 @@ public class SQLManager implements AbstractDB { /* * Getting denied */ - try (ResultSet r = stmt.executeQuery("SELECT `user_uuid`, `plot_plot_id` FROM `" + this.prefix + "plot_denied`")) { + try (ResultSet r = statement.executeQuery("SELECT `user_uuid`, `plot_plot_id` FROM `" + this.prefix + "plot_denied`")) { ArrayList toDelete = new ArrayList<>(); while (r.next()) { id = r.getInt("plot_plot_id"); @@ -1783,7 +1784,7 @@ public class SQLManager implements AbstractDB { deleteRows(toDelete, this.prefix + "plot_denied", "plot_plot_id"); } - try (ResultSet r = stmt.executeQuery("SELECT * FROM `" + this.prefix + "plot_settings`")) { + try (ResultSet r = statement.executeQuery("SELECT * FROM `" + this.prefix + "plot_settings`")) { ArrayList toDelete = new ArrayList<>(); while (r.next()) { id = r.getInt("plot_plot_id"); @@ -1860,7 +1861,7 @@ public class SQLManager implements AbstractDB { + ".yml."); } } - stmt.close(); + statement.close(); deleteRows(toDelete, this.prefix + "plot_settings", "plot_plot_id"); } if (!plots.entrySet().isEmpty()) { @@ -2012,7 +2013,7 @@ public class SQLManager implements AbstractDB { stmt_prefix = " OR `id` = "; } stmt_prefix = ""; - StringBuilder idstr = new StringBuilder(""); + StringBuilder idstr = new StringBuilder(); for (Integer id : uniqueIds) { idstr.append(stmt_prefix).append(id); stmt_prefix = " OR `plot_plot_id` = "; @@ -3146,7 +3147,7 @@ public class SQLManager implements AbstractDB { public abstract class UniqueStatement { - public String method; + public final String method; public UniqueStatement(String method) { this.method = method; diff --git a/Core/src/main/java/com/intellectualcrafters/plot/flag/FlagManager.java b/Core/src/main/java/com/intellectualcrafters/plot/flag/FlagManager.java index 327cf8c00..3be530cc4 100644 --- a/Core/src/main/java/com/intellectualcrafters/plot/flag/FlagManager.java +++ b/Core/src/main/java/com/intellectualcrafters/plot/flag/FlagManager.java @@ -26,6 +26,10 @@ import java.util.Set; */ public class FlagManager { + //TODO Default Flags + public static final IntegerFlag MUSIC = new IntegerFlag("music"); + + private static final HashSet reserved = new HashSet<>(); private static final HashSet flags = new HashSet<>(); diff --git a/Core/src/main/java/com/intellectualcrafters/plot/flag/IntegerFlag.java b/Core/src/main/java/com/intellectualcrafters/plot/flag/IntegerFlag.java new file mode 100644 index 000000000..85e1f1916 --- /dev/null +++ b/Core/src/main/java/com/intellectualcrafters/plot/flag/IntegerFlag.java @@ -0,0 +1,8 @@ +package com.intellectualcrafters.plot.flag; + +public class IntegerFlag extends Flag { + + public IntegerFlag(String name) { + super(name); + } +} diff --git a/Core/src/main/java/com/intellectualcrafters/plot/generator/ClassicPlotWorld.java b/Core/src/main/java/com/intellectualcrafters/plot/generator/ClassicPlotWorld.java index 8fbfea171..4ac5d5ff5 100644 --- a/Core/src/main/java/com/intellectualcrafters/plot/generator/ClassicPlotWorld.java +++ b/Core/src/main/java/com/intellectualcrafters/plot/generator/ClassicPlotWorld.java @@ -34,18 +34,18 @@ public abstract class ClassicPlotWorld extends SquarePlotWorld { @Override public ConfigurationNode[] getSettingNodes() { return new ConfigurationNode[] { - new ConfigurationNode("plot.height", this.PLOT_HEIGHT, "Plot height", Configuration.INTEGER, true), - new ConfigurationNode("plot.size", this.PLOT_WIDTH, "Plot width", Configuration.INTEGER, true), - new ConfigurationNode("plot.filling", this.MAIN_BLOCK, "Plot block", Configuration.BLOCKLIST, true), - new ConfigurationNode("plot.floor", this.TOP_BLOCK, "Plot floor block", Configuration.BLOCKLIST, true), - new ConfigurationNode("wall.block", this.WALL_BLOCK, "Top wall block", Configuration.BLOCK, true), - new ConfigurationNode("wall.block_claimed", this.CLAIMED_WALL_BLOCK, "Wall block (claimed)", Configuration.BLOCK, true), - new ConfigurationNode("road.width", this.ROAD_WIDTH, "Road width", Configuration.INTEGER, true), - new ConfigurationNode("road.height", this.ROAD_HEIGHT, "Road height", Configuration.INTEGER, true), - new ConfigurationNode("road.block", this.ROAD_BLOCK, "Road block", Configuration.BLOCK, true), - new ConfigurationNode("wall.filling", this.WALL_FILLING, "Wall filling block", Configuration.BLOCK, true), - new ConfigurationNode("wall.height", this.WALL_HEIGHT, "Wall height", Configuration.INTEGER, true), - new ConfigurationNode("plot.bedrock", this.PLOT_BEDROCK, "Plot bedrock generation", Configuration.BOOLEAN, true)}; + new ConfigurationNode("plot.height", this.PLOT_HEIGHT, "Plot height", Configuration.INTEGER), + new ConfigurationNode("plot.size", this.PLOT_WIDTH, "Plot width", Configuration.INTEGER), + new ConfigurationNode("plot.filling", this.MAIN_BLOCK, "Plot block", Configuration.BLOCKLIST), + new ConfigurationNode("plot.floor", this.TOP_BLOCK, "Plot floor block", Configuration.BLOCKLIST), + new ConfigurationNode("wall.block", this.WALL_BLOCK, "Top wall block", Configuration.BLOCK), + new ConfigurationNode("wall.block_claimed", this.CLAIMED_WALL_BLOCK, "Wall block (claimed)", Configuration.BLOCK), + new ConfigurationNode("road.width", this.ROAD_WIDTH, "Road width", Configuration.INTEGER), + new ConfigurationNode("road.height", this.ROAD_HEIGHT, "Road height", Configuration.INTEGER), + new ConfigurationNode("road.block", this.ROAD_BLOCK, "Road block", Configuration.BLOCK), + new ConfigurationNode("wall.filling", this.WALL_FILLING, "Wall filling block", Configuration.BLOCK), + new ConfigurationNode("wall.height", this.WALL_HEIGHT, "Wall height", Configuration.INTEGER), + new ConfigurationNode("plot.bedrock", this.PLOT_BEDROCK, "Plot bedrock generation", Configuration.BOOLEAN)}; } /** 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 c0188f1c3..2f4294475 100644 --- a/Core/src/main/java/com/intellectualcrafters/plot/generator/HybridPlotWorld.java +++ b/Core/src/main/java/com/intellectualcrafters/plot/generator/HybridPlotWorld.java @@ -13,6 +13,7 @@ import com.intellectualcrafters.plot.util.MathMan; import com.intellectualcrafters.plot.util.SchematicHandler; import com.intellectualcrafters.plot.util.SchematicHandler.Dimension; import com.intellectualcrafters.plot.util.SchematicHandler.Schematic; + import java.io.File; import java.util.HashMap; import java.util.Map; @@ -163,11 +164,11 @@ public class HybridPlotWorld extends ClassicPlotWorld { } @Override - public boolean isCompatible(PlotArea plotworld) { - if (!(plotworld instanceof SquarePlotWorld)) { + public boolean isCompatible(PlotArea plotArea) { + if (!(plotArea instanceof SquarePlotWorld)) { return false; } - return ((SquarePlotWorld) plotworld).PLOT_WIDTH == this.PLOT_WIDTH; + return ((SquarePlotWorld) plotArea).PLOT_WIDTH == this.PLOT_WIDTH; } public void setupSchematics() { @@ -213,7 +214,7 @@ public class HybridPlotWorld extends ClassicPlotWorld { } } HashMap items = schematic3.getTiles(); - if (items.size() > 0) { + if (!items.isEmpty()) { this.G_SCH_STATE = new HashMap<>(); for (Map.Entry entry : items.entrySet()) { BlockLoc loc = entry.getKey(); diff --git a/Core/src/main/java/com/intellectualcrafters/plot/generator/IndependentPlotGenerator.java b/Core/src/main/java/com/intellectualcrafters/plot/generator/IndependentPlotGenerator.java index 7f67c2afa..84fe328de 100644 --- a/Core/src/main/java/com/intellectualcrafters/plot/generator/IndependentPlotGenerator.java +++ b/Core/src/main/java/com/intellectualcrafters/plot/generator/IndependentPlotGenerator.java @@ -9,8 +9,8 @@ import com.intellectualcrafters.plot.object.SetupObject; import com.intellectualcrafters.plot.util.PlotChunk; /** - * This class allows for implementation independent world generation
- * - Sponge/Bukkit API

+ * This class allows for implementation independent world generation. + * - Sponge/Bukkit API * Use the specify method to get the generator for that platform. */ public abstract class IndependentPlotGenerator { diff --git a/Core/src/main/java/com/intellectualcrafters/plot/generator/PlotGenerator.java b/Core/src/main/java/com/intellectualcrafters/plot/generator/PlotGenerator.java index aa2319223..138b1316e 100644 --- a/Core/src/main/java/com/intellectualcrafters/plot/generator/PlotGenerator.java +++ b/Core/src/main/java/com/intellectualcrafters/plot/generator/PlotGenerator.java @@ -7,7 +7,7 @@ import com.intellectualcrafters.plot.object.SetupObject; public abstract class PlotGenerator { - public T generator; + public final T generator; public PlotGenerator(T generator) { this.generator = generator; diff --git a/Core/src/main/java/com/intellectualcrafters/plot/object/ConsolePlayer.java b/Core/src/main/java/com/intellectualcrafters/plot/object/ConsolePlayer.java index a4d485a59..33d7d535d 100644 --- a/Core/src/main/java/com/intellectualcrafters/plot/object/ConsolePlayer.java +++ b/Core/src/main/java/com/intellectualcrafters/plot/object/ConsolePlayer.java @@ -39,10 +39,6 @@ public class ConsolePlayer extends PlotPlayer { return instance; } - public static boolean isConsole(PlotPlayer plr) { - return plr instanceof ConsolePlayer; - } - @Override public long getPreviousLogin() { return 0; @@ -133,7 +129,7 @@ public class ConsolePlayer extends PlotPlayer { @Override public PlotGameMode getGameMode() { - return PlotGameMode.CREATIVE; + return PlotGameMode.NOT_SET; } @Override diff --git a/Core/src/main/java/com/intellectualcrafters/plot/object/Location.java b/Core/src/main/java/com/intellectualcrafters/plot/object/Location.java index 61065be54..231266995 100644 --- a/Core/src/main/java/com/intellectualcrafters/plot/object/Location.java +++ b/Core/src/main/java/com/intellectualcrafters/plot/object/Location.java @@ -3,11 +3,6 @@ package com.intellectualcrafters.plot.object; import com.intellectualcrafters.plot.PS; import com.intellectualcrafters.plot.util.MathMan; -/** - * Created 2015-02-11 for PlotSquared - * - - */ public class Location implements Cloneable, Comparable { private int x; @@ -27,7 +22,7 @@ public class Location implements Cloneable, Comparable { } public Location() { - this("", 0, 0, 0, 0, 0); + this.world = ""; } public Location(String world, int x, int y, int z) { 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 cda7b404b..bafbc6e67 100644 --- a/Core/src/main/java/com/intellectualcrafters/plot/object/Plot.java +++ b/Core/src/main/java/com/intellectualcrafters/plot/object/Plot.java @@ -20,6 +20,7 @@ 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.Rectangle; import java.awt.geom.Area; import java.awt.geom.PathIterator; @@ -765,8 +766,8 @@ public class Plot { @Override public void run() { if (queue.isEmpty()) { - final AtomicInteger finished = new AtomicInteger(0); - final Runnable run = new Runnable() { + AtomicInteger finished = new AtomicInteger(0); + Runnable run = new Runnable() { @Override public void run() { for (RegionWrapper region : regions) { @@ -794,11 +795,11 @@ public class Plot { manager.clearPlot(Plot.this.area, current, this); } }; - if (!isMerged() && area.getRegion().equals(getLargestRegion())) { - ChunkManager.largeRegionTask(area.worldname, area.getRegion(), new RunnableVal() { + if (!isMerged() && this.area.getRegion().equals(getLargestRegion())) { + ChunkManager.largeRegionTask(this.area.worldname, this.area.getRegion(), new RunnableVal() { @Override public void run(ChunkLoc value) { - ChunkManager.manager.regenerateChunk(area.worldname, value); + ChunkManager.manager.regenerateChunk(Plot.this.area.worldname, value); } }, whenDone); } else { @@ -1773,7 +1774,7 @@ public class Plot { * Upload this plot as a world file
* - The mca files are each 512x512, so depending on the plot size it may also download adjacent plots
* - Works best when (plot width + road width) % 512 == 0
- * @see com.intellectualcrafters.plot.util.WorldUtil + * @see WorldUtil * @param whenDone */ public void uploadWorld(RunnableVal whenDone) { @@ -1784,7 +1785,7 @@ public class Plot { * Upload this plot as a BO3
* - May not work on non default generator
* - BO3 includes flags/ignores plot main/floor block
- * @see com.intellectualcrafters.plot.util.BO3Handler + * @see BO3Handler * @param whenDone */ public void uploadBO3(RunnableVal whenDone) { @@ -1991,8 +1992,6 @@ public class Plot { int index = caption.indexOf("%plr%"); if (index == -1) { continue; - } else if (index < -1) { - PS.debug("This should NEVER happen. Seriously, it's impossible."); } String line = lines[i - 1]; if (line.length() <= index) { @@ -2487,7 +2486,7 @@ public class Plot { RegionWrapper max = null; double area = Double.NEGATIVE_INFINITY; for (RegionWrapper region : regions) { - double current = ((region.maxX - (double) region.minX + 1)) * (region.maxZ - (double) region.minZ + 1); + double current = (region.maxX - (double) region.minX + 1) * (region.maxZ - (double) region.minZ + 1); if (current > area) { max = region; area = current; diff --git a/Core/src/main/java/com/intellectualcrafters/plot/object/PlotAnalysis.java b/Core/src/main/java/com/intellectualcrafters/plot/object/PlotAnalysis.java index 460a279b0..f4b0c03ad 100644 --- a/Core/src/main/java/com/intellectualcrafters/plot/object/PlotAnalysis.java +++ b/Core/src/main/java/com/intellectualcrafters/plot/object/PlotAnalysis.java @@ -19,7 +19,7 @@ import java.util.concurrent.atomic.AtomicInteger; public class PlotAnalysis { - public static PlotAnalysis MODIFIERS = new PlotAnalysis(); + public static final PlotAnalysis MODIFIERS = new PlotAnalysis(); public static boolean running = false; public int changes; public int faces; diff --git a/Core/src/main/java/com/intellectualcrafters/plot/object/PlotArea.java b/Core/src/main/java/com/intellectualcrafters/plot/object/PlotArea.java index 05a1eaa82..d9f21d11c 100644 --- a/Core/src/main/java/com/intellectualcrafters/plot/object/PlotArea.java +++ b/Core/src/main/java/com/intellectualcrafters/plot/object/PlotArea.java @@ -67,7 +67,7 @@ public abstract class PlotArea { public int MAX_BUILD_HEIGHT = 256; public int MIN_BUILD_HEIGHT = 1; public PlotGameMode GAMEMODE = PlotGameMode.CREATIVE; - int hash; + private int hash; private RegionWrapper region; private ConcurrentHashMap meta; private QuadMap clusters; @@ -91,7 +91,7 @@ public abstract class PlotArea { } /** - * Create a new PlotArea object with no functionality/information
+ * Create a new PlotArea object with no functionality/information. * - Mainly used during startup before worlds are created as a temporary object * @param world * @return @@ -106,8 +106,9 @@ public abstract class PlotArea { } /** - * Returns the region for this PlotArea or a RegionWrapper encompassing the whole world if none exists - * @NotNull + * Returns the region for this PlotArea or a RegionWrapper encompassing + * the whole world if none exists. + * * @return RegionWrapper */ public RegionWrapper getRegion() { @@ -119,7 +120,7 @@ public abstract class PlotArea { } /** - * Returns the region for this PlotArea + * Returns the region for this PlotArea. * * @return RegionWrapper or null if no applicable region */ @@ -135,7 +136,7 @@ public abstract class PlotArea { } /** - * Returns the min PlotId + * Returns the min PlotId. * @return */ public PlotId getMin() { @@ -143,7 +144,7 @@ public abstract class PlotArea { } /** - * Returns the max PlotId + * Returns the max PlotId. * @return */ public PlotId getMax() { @@ -151,7 +152,7 @@ public abstract class PlotArea { } /** - * Get the implementation independent generator for this area + * Get the implementation independent generator for this area. * * @return */ @@ -179,14 +180,14 @@ public abstract class PlotArea { } /** - * Check if a PlotArea is compatible (move/copy etc) - * @param plotarea + * Check if a PlotArea is compatible (move/copy etc). + * @param plotArea * @return */ - public boolean isCompatible(PlotArea plotarea) { + public boolean isCompatible(PlotArea plotArea) { ConfigurationSection section = PS.get().config.getConfigurationSection("worlds"); - for (ConfigurationNode setting : plotarea.getSettingNodes()) { - Object constant = section.get(plotarea.worldname + "." + setting.getConstant()); + for (ConfigurationNode setting : plotArea.getSettingNodes()) { + Object constant = section.get(plotArea.worldname + "." + setting.getConstant()); if (constant == null) { return false; } @@ -198,7 +199,7 @@ public abstract class PlotArea { } /** - * When a world is created, the following method will be called for each + * When a world is created, the following method will be called for each. * * @param config Configuration Section */ @@ -358,7 +359,11 @@ public abstract class PlotArea { @Override public String toString() { - return this.id == null ? this.worldname : this.worldname + ";" + this.id; + if (this.id == null) { + return this.worldname; + } else { + return this.worldname + ";" + this.id; + } } @Override diff --git a/Core/src/main/java/com/intellectualcrafters/plot/object/PlotId.java b/Core/src/main/java/com/intellectualcrafters/plot/object/PlotId.java index d05b9b08a..7c0533354 100644 --- a/Core/src/main/java/com/intellectualcrafters/plot/object/PlotId.java +++ b/Core/src/main/java/com/intellectualcrafters/plot/object/PlotId.java @@ -17,7 +17,7 @@ public class PlotId { * @param x The plot x coordinate * @param y The plot y coordinate */ - public PlotId(final int x, final int y) { + public PlotId(int x, int y) { this.x = x; this.y = y; } @@ -29,11 +29,11 @@ public class PlotId { * * @return null if the string is invalid */ - public static PlotId fromString(final String string) { + public static PlotId fromString(String string) { if (string == null) { return null; } - final String[] parts = string.split(";"); + String[] parts = string.split(";"); if (parts.length < 2) { return null; } @@ -42,7 +42,7 @@ public class PlotId { try { x = Integer.parseInt(parts[0]); y = Integer.parseInt(parts[1]); - } catch (final Exception e) { + } catch (Exception e) { return null; } return new PlotId(x, y); @@ -67,7 +67,7 @@ public class PlotId { * @param direction * @return PlotId */ - public PlotId getRelative(final int direction) { + public PlotId getRelative(int direction) { switch (direction) { case 0: return new PlotId(this.x, this.y - 1); @@ -92,7 +92,7 @@ public class PlotId { } @Override - public boolean equals(final Object obj) { + public boolean equals(Object obj) { if (this == obj) { return true; } @@ -105,8 +105,8 @@ public class PlotId { if (getClass() != obj.getClass()) { return false; } - final PlotId other = (PlotId) obj; - return x == other.x && y == other.y; + PlotId other = (PlotId) obj; + return this.x == other.x && this.y == other.y; } /** @@ -116,7 +116,7 @@ public class PlotId { */ @Override public String toString() { - return x + ";" + y; + return this.x + ";" + this.y; } /** @@ -125,15 +125,15 @@ public class PlotId { * TODO maybe make x/y values private and add this to the mutators */ public void recalculateHash() { - hash = 0; + this.hash = 0; hashCode(); } @Override public int hashCode() { - if (hash == 0) { - hash = (x << 16) | (y & 0xFFFF); + if (this.hash == 0) { + this.hash = (this.x << 16) | (this.y & 0xFFFF); } - return hash; + return this.hash; } } diff --git a/Core/src/main/java/com/intellectualcrafters/plot/object/PlotLoc.java b/Core/src/main/java/com/intellectualcrafters/plot/object/PlotLoc.java index 6b861c14d..96a9ad9fe 100644 --- a/Core/src/main/java/com/intellectualcrafters/plot/object/PlotLoc.java +++ b/Core/src/main/java/com/intellectualcrafters/plot/object/PlotLoc.java @@ -3,28 +3,28 @@ package com.intellectualcrafters.plot.object; public class PlotLoc { public int x; public int z; - - public PlotLoc(final int x, final int z) { + + public PlotLoc(int x, int z) { this.x = x; this.z = z; } @Override public int hashCode() { - final int prime = 31; + int prime = 31; int result = 1; - result = (prime * result) + x; - result = (prime * result) + z; + result = (prime * result) + this.x; + result = (prime * result) + this.z; return result; } @Override public String toString() { - return x + "," + z; + return this.x + "," + this.z; } @Override - public boolean equals(final Object obj) { + public boolean equals(Object obj) { if (this == obj) { return true; } @@ -34,7 +34,7 @@ public class PlotLoc { if (getClass() != obj.getClass()) { return false; } - final PlotLoc other = (PlotLoc) obj; - return ((x == other.x) && (z == other.z)); + PlotLoc other = (PlotLoc) obj; + return (this.x == other.x) && (this.z == other.z); } } diff --git a/Core/src/main/java/com/intellectualcrafters/plot/object/PlotMessage.java b/Core/src/main/java/com/intellectualcrafters/plot/object/PlotMessage.java index 8aa6ded1b..def432cd3 100644 --- a/Core/src/main/java/com/intellectualcrafters/plot/object/PlotMessage.java +++ b/Core/src/main/java/com/intellectualcrafters/plot/object/PlotMessage.java @@ -10,50 +10,50 @@ public class PlotMessage { public PlotMessage() { reset(ChatManager.manager); } - - public T $(final ChatManager manager) { - return (T) builder; - } - - public PlotMessage(final String text) { + + public PlotMessage(String text) { this(); text(text); } - public T reset(ChatManager manager) { - return (T) (builder = manager.builder()); + public T $(ChatManager manager) { + return (T) this.builder; } - - public PlotMessage text(final String text) { + + public T reset(ChatManager manager) { + return (T) (this.builder = manager.builder()); + } + + public PlotMessage text(String text) { ChatManager.manager.text(this, text); return this; } - - public PlotMessage tooltip(final PlotMessage... tooltip) { + + public PlotMessage tooltip(PlotMessage... tooltip) { ChatManager.manager.tooltip(this, tooltip); return this; } - - public PlotMessage tooltip(final String tooltip) { + + public PlotMessage tooltip(String tooltip) { return tooltip(new PlotMessage(tooltip)); } - - public PlotMessage command(final String command) { + + public PlotMessage command(String command) { ChatManager.manager.command(this, command); return this; } - - public PlotMessage suggest(final String command) { + + public PlotMessage suggest(String command) { ChatManager.manager.suggest(this, command); return this; } - - public PlotMessage color(final String color) { + + public PlotMessage color(String color) { ChatManager.manager.color(this, C.color(color)); return this; } - - public void send(final PlotPlayer player) { + + public void send(PlotPlayer player) { ChatManager.manager.send(this, player); } } diff --git a/Core/src/main/java/com/intellectualcrafters/plot/object/PlotSettings.java b/Core/src/main/java/com/intellectualcrafters/plot/object/PlotSettings.java index ac18f32e2..8bc64d1f8 100644 --- a/Core/src/main/java/com/intellectualcrafters/plot/object/PlotSettings.java +++ b/Core/src/main/java/com/intellectualcrafters/plot/object/PlotSettings.java @@ -1,5 +1,6 @@ package com.intellectualcrafters.plot.object; +import com.google.common.base.Optional; import com.intellectualcrafters.plot.flag.Flag; import com.intellectualcrafters.plot.flag.FlagManager; import com.intellectualcrafters.plot.object.comment.PlotComment; @@ -151,17 +152,17 @@ public class PlotSettings { return ""; } - public ArrayList getComments(String inbox) { + public Optional> getComments(String inbox) { ArrayList c = new ArrayList<>(); if (this.comments == null) { - return null; + return Optional.absent(); } for (PlotComment comment : this.comments) { if (comment.inbox.equals(inbox)) { c.add(comment); } } - return c; + return Optional.of(c); } public void setComments(List comments) { diff --git a/Core/src/main/java/com/intellectualcrafters/plot/object/comment/CommentInbox.java b/Core/src/main/java/com/intellectualcrafters/plot/object/comment/CommentInbox.java index eedb2aa19..cd4353299 100644 --- a/Core/src/main/java/com/intellectualcrafters/plot/object/comment/CommentInbox.java +++ b/Core/src/main/java/com/intellectualcrafters/plot/object/comment/CommentInbox.java @@ -1,5 +1,6 @@ package com.intellectualcrafters.plot.object.comment; +import com.intellectualcrafters.plot.database.DBFunc; import com.intellectualcrafters.plot.object.Plot; import com.intellectualcrafters.plot.object.PlotPlayer; import com.intellectualcrafters.plot.object.RunnableVal; @@ -18,7 +19,7 @@ public abstract class CommentInbox { public abstract boolean canModify(Plot plot, PlotPlayer player); /** - * The plot may be null if the user is not standing in a plot. Return false if this is not a plot-less inbox. + * *
* The `whenDone` parameter should be executed when it's done fetching the comments. * The value should be set to List of comments @@ -31,7 +32,11 @@ public abstract class CommentInbox { public abstract boolean addComment(Plot plot, PlotComment comment); - public abstract boolean removeComment(Plot plot, PlotComment comment); + public void removeComment(Plot plot, PlotComment comment) { + DBFunc.removeComment(plot, comment); + } - public abstract boolean clearInbox(Plot plot); + public void clearInbox(Plot plot) { + DBFunc.clearInbox(plot, toString()); + } } diff --git a/Core/src/main/java/com/intellectualcrafters/plot/object/comment/InboxOwner.java b/Core/src/main/java/com/intellectualcrafters/plot/object/comment/InboxOwner.java index 886bb573e..08c6d7c1c 100644 --- a/Core/src/main/java/com/intellectualcrafters/plot/object/comment/InboxOwner.java +++ b/Core/src/main/java/com/intellectualcrafters/plot/object/comment/InboxOwner.java @@ -1,5 +1,6 @@ package com.intellectualcrafters.plot.object.comment; +import com.google.common.base.Optional; import com.intellectualcrafters.plot.database.DBFunc; import com.intellectualcrafters.plot.object.Plot; import com.intellectualcrafters.plot.object.PlotPlayer; @@ -11,48 +12,41 @@ import java.util.ArrayList; import java.util.List; public class InboxOwner extends CommentInbox { - + @Override public boolean canRead(Plot plot, PlotPlayer player) { - if (plot == null) { - return Permissions.hasPermission(player, "plots.inbox.read." + toString()); + if (Permissions.hasPermission(player, "plots.inbox.read." + toString())) { + if (plot.isOwner(player.getUUID()) || Permissions.hasPermission(player, "plots.inbox.read." + toString() + ".other")) { + return true; + } } - return Permissions.hasPermission(player, "plots.inbox.read." + toString()) && (plot.isOwner(player.getUUID()) || Permissions - .hasPermission(player, "plots.inbox.read." - + toString() - + ".other")); + return false; } - + @Override public boolean canWrite(Plot plot, PlotPlayer player) { if (plot == null) { return Permissions.hasPermission(player, "plots.inbox.write." + toString()); } return Permissions.hasPermission(player, "plots.inbox.write." + toString()) && (plot.isOwner(player.getUUID()) || Permissions - .hasPermission(player, "plots.inbox.write." - + toString() - + ".other")); + .hasPermission(player, "plots.inbox.write." + toString() + ".other")); } - + @Override public boolean canModify(Plot plot, PlotPlayer player) { - if (plot == null) { - return Permissions.hasPermission(player, "plots.inbox.modify." + toString()); + if (Permissions.hasPermission(player, "plots.inbox.modify." + toString())) { + if (plot.isOwner(player.getUUID()) || Permissions.hasPermission(player, "plots.inbox.modify." + toString() + ".other")) { + return true; + } } - return Permissions.hasPermission(player, "plots.inbox.modify." + toString()) && (plot.isOwner(player.getUUID()) || Permissions - .hasPermission(player, "plots.inbox.modify." - + toString() - + ".other")); + return false; } - + @Override - public boolean getComments(final Plot plot, final RunnableVal whenDone) { - if ((plot == null) || (plot.owner == null)) { - return false; - } - ArrayList comments = plot.getSettings().getComments(toString()); - if (comments != null) { - whenDone.value = comments; + public boolean getComments(final Plot plot, final RunnableVal> whenDone) { + Optional> comments = plot.getSettings().getComments(toString()); + if (comments.isPresent()) { + whenDone.value = comments.get(); TaskManager.runTask(whenDone); return true; } @@ -72,37 +66,20 @@ public class InboxOwner extends CommentInbox { }); return true; } - + @Override public boolean addComment(Plot plot, PlotComment comment) { - if ((plot == null) || (plot.owner == null)) { + if (plot.owner == null) { return false; } plot.getSettings().addComment(comment); DBFunc.setComment(plot, comment); return true; } - + @Override public String toString() { return "owner"; } - - @Override - public boolean removeComment(Plot plot, PlotComment comment) { - if ((plot == null) || (plot.owner == null)) { - return false; - } - DBFunc.removeComment(plot, comment); - return false; - } - - @Override - public boolean clearInbox(Plot plot) { - if (plot == null || plot.owner == null) { - return false; - } - DBFunc.clearInbox(plot, this.toString()); - return false; - } + } diff --git a/Core/src/main/java/com/intellectualcrafters/plot/object/comment/InboxPublic.java b/Core/src/main/java/com/intellectualcrafters/plot/object/comment/InboxPublic.java index e32e60da3..0d2fffd70 100644 --- a/Core/src/main/java/com/intellectualcrafters/plot/object/comment/InboxPublic.java +++ b/Core/src/main/java/com/intellectualcrafters/plot/object/comment/InboxPublic.java @@ -1,5 +1,6 @@ package com.intellectualcrafters.plot.object.comment; +import com.google.common.base.Optional; import com.intellectualcrafters.plot.database.DBFunc; import com.intellectualcrafters.plot.object.Plot; import com.intellectualcrafters.plot.object.PlotPlayer; @@ -14,13 +15,12 @@ public class InboxPublic extends CommentInbox { @Override public boolean canRead(Plot plot, PlotPlayer player) { - if (plot == null) { - return Permissions.hasPermission(player, "plots.inbox.read." + toString()); + if (Permissions.hasPermission(player, "plots.inbox.read." + toString())) { + if (plot.isOwner(player.getUUID()) || Permissions.hasPermission(player, "plots.inbox.read." + toString() + ".other")) { + return true; + } } - return Permissions.hasPermission(player, "plots.inbox.read." + toString()) && (plot.isOwner(player.getUUID()) || Permissions - .hasPermission(player, "plots.inbox.read." - + toString() - + ".other")); + return false; } @Override @@ -34,21 +34,19 @@ public class InboxPublic extends CommentInbox { @Override public boolean canModify(Plot plot, PlotPlayer player) { - if (plot == null) { - return Permissions.hasPermission(player, "plots.inbox.modify." + toString()); + if (Permissions.hasPermission(player, "plots.inbox.modify." + toString())) { + if (plot.isOwner(player.getUUID()) || Permissions.hasPermission(player, "plots.inbox.modify." + toString() + ".other")) { + return true; + } } - return Permissions.hasPermission(player, "plots.inbox.modify." + toString()) && (plot.isOwner(player.getUUID()) || Permissions - .hasPermission(player, "plots.inbox.modify." + toString() + ".other")); + return false; } @Override - public boolean getComments(final Plot plot, final RunnableVal whenDone) { - if ((plot == null) || (plot.owner == null)) { - return false; - } - ArrayList comments = plot.getSettings().getComments(toString()); - if (comments != null) { - whenDone.value = comments; + public boolean getComments(final Plot plot, final RunnableVal> whenDone) { + Optional> comments = plot.getSettings().getComments(toString()); + if (comments.isPresent()) { + whenDone.value = comments.get(); TaskManager.runTask(whenDone); return true; } @@ -69,9 +67,6 @@ public class InboxPublic extends CommentInbox { @Override public boolean addComment(Plot plot, PlotComment comment) { - if ((plot == null) || (plot.owner == null)) { - return false; - } plot.getSettings().addComment(comment); DBFunc.setComment(plot, comment); return true; @@ -81,22 +76,6 @@ public class InboxPublic extends CommentInbox { public String toString() { return "public"; } - - @Override - public boolean removeComment(Plot plot, PlotComment comment) { - if ((plot == null) || (plot.owner == null)) { - return false; - } - DBFunc.removeComment(plot, comment); - return false; - } - - @Override - public boolean clearInbox(Plot plot) { - if (plot == null || plot.owner == null) { - return false; - } - DBFunc.clearInbox(plot, this.toString()); - return false; - } + + } diff --git a/Core/src/main/java/com/intellectualcrafters/plot/object/comment/InboxReport.java b/Core/src/main/java/com/intellectualcrafters/plot/object/comment/InboxReport.java index ce58d50ab..f320e632e 100644 --- a/Core/src/main/java/com/intellectualcrafters/plot/object/comment/InboxReport.java +++ b/Core/src/main/java/com/intellectualcrafters/plot/object/comment/InboxReport.java @@ -13,11 +13,13 @@ public class InboxReport extends CommentInbox { @Override public boolean canRead(Plot plot, PlotPlayer player) { - if (plot == null) { - return Permissions.hasPermission(player, "plots.inbox.read." + toString()); + if (Permissions.hasPermission(player, "plots.inbox.read." + toString())) { + if (plot.isOwner(player.getUUID()) || Permissions + .hasPermission(player, "plots.inbox.read." + toString() + ".other")) { + return true; + } } - return Permissions.hasPermission(player, "plots.inbox.read." + toString()) && (plot.isOwner(player.getUUID()) || Permissions - .hasPermission(player, "plots.inbox.read." + toString() + ".other")); + return false; } @Override @@ -31,15 +33,16 @@ public class InboxReport extends CommentInbox { @Override public boolean canModify(Plot plot, PlotPlayer player) { - if (plot == null) { - return Permissions.hasPermission(player, "plots.inbox.modify." + toString()); + if (Permissions.hasPermission(player, "plots.inbox.modify." + toString())) { + if (plot.isOwner(player.getUUID()) || Permissions.hasPermission(player, "plots.inbox.modify." + toString() + ".other")) { + return true; + } } - return Permissions.hasPermission(player, "plots.inbox.modify." + toString()) && (plot.isOwner(player.getUUID()) || Permissions - .hasPermission(player, "plots.inbox.modify." + toString() + ".other")); + return false; } @Override - public boolean getComments(Plot plot, final RunnableVal whenDone) { + public boolean getComments(Plot plot, final RunnableVal> whenDone) { DBFunc.getComments(null, toString(), new RunnableVal>() { @Override public void run(List value) { @@ -52,7 +55,7 @@ public class InboxReport extends CommentInbox { @Override public boolean addComment(Plot plot, PlotComment comment) { - if ((plot == null) || (plot.owner == null)) { + if (plot.owner == null) { return false; } DBFunc.setComment(plot, comment); @@ -64,21 +67,4 @@ public class InboxReport extends CommentInbox { return "report"; } - @Override - public boolean removeComment(Plot plot, PlotComment comment) { - if (plot == null || plot.owner == null) { - return false; - } - DBFunc.removeComment(plot, comment); - return false; - } - - @Override - public boolean clearInbox(Plot plot) { - if (plot == null || plot.owner == null) { - return false; - } - DBFunc.clearInbox(plot, this.toString()); - return false; - } } diff --git a/Core/src/main/java/com/intellectualcrafters/plot/object/schematic/PlotItem.java b/Core/src/main/java/com/intellectualcrafters/plot/object/schematic/PlotItem.java index 2a18b031c..0e4f2b4ee 100644 --- a/Core/src/main/java/com/intellectualcrafters/plot/object/schematic/PlotItem.java +++ b/Core/src/main/java/com/intellectualcrafters/plot/object/schematic/PlotItem.java @@ -1,12 +1,13 @@ package com.intellectualcrafters.plot.object.schematic; public class PlotItem { - public int x; - public int y; - public int z; - public short[] id; - public byte[] data; - public byte[] amount; + + public final int x; + public final int y; + public final int z; + public final short[] id; + public final byte[] data; + public final byte[] amount; public PlotItem(short x, short y, short z, short[] id, byte[] data, byte[] amount) { this.x = x; diff --git a/Core/src/main/java/com/intellectualcrafters/plot/util/AbstractTitle.java b/Core/src/main/java/com/intellectualcrafters/plot/util/AbstractTitle.java index 34a108124..69d15f3ab 100644 --- a/Core/src/main/java/com/intellectualcrafters/plot/util/AbstractTitle.java +++ b/Core/src/main/java/com/intellectualcrafters/plot/util/AbstractTitle.java @@ -7,7 +7,7 @@ public abstract class AbstractTitle { public static AbstractTitle TITLE_CLASS; public static void sendTitle(PlotPlayer player, String head, String sub) { - if (ConsolePlayer.isConsole(player)) { + if (player instanceof ConsolePlayer) { return; } if (TITLE_CLASS != null && !player.getAttribute("disabletitles")) { diff --git a/Core/src/main/java/com/intellectualcrafters/plot/util/ChatManager.java b/Core/src/main/java/com/intellectualcrafters/plot/util/ChatManager.java index d41e2e712..335935177 100644 --- a/Core/src/main/java/com/intellectualcrafters/plot/util/ChatManager.java +++ b/Core/src/main/java/com/intellectualcrafters/plot/util/ChatManager.java @@ -7,16 +7,16 @@ public abstract class ChatManager { public static ChatManager manager; public abstract T builder(); - - public abstract void color(final PlotMessage message, final String color); - - public abstract void tooltip(final PlotMessage message, final PlotMessage... tooltip); - - public abstract void command(final PlotMessage message, final String command); - - public abstract void text(final PlotMessage message, final String text); - - public abstract void send(final PlotMessage plotMessage, final PlotPlayer player); - - public abstract void suggest(final PlotMessage plotMessage, final String command); + + public abstract void color(PlotMessage message, String color); + + public abstract void tooltip(PlotMessage message, PlotMessage... tooltip); + + public abstract void command(PlotMessage message, String command); + + public abstract void text(PlotMessage message, String text); + + public abstract void send(PlotMessage plotMessage, PlotPlayer player); + + public abstract void suggest(PlotMessage plotMessage, String command); } diff --git a/Core/src/main/java/com/intellectualcrafters/plot/util/ChunkManager.java b/Core/src/main/java/com/intellectualcrafters/plot/util/ChunkManager.java index bf99024c0..1b904dd14 100644 --- a/Core/src/main/java/com/intellectualcrafters/plot/util/ChunkManager.java +++ b/Core/src/main/java/com/intellectualcrafters/plot/util/ChunkManager.java @@ -2,13 +2,13 @@ package com.intellectualcrafters.plot.util; import com.intellectualcrafters.plot.PS; import com.intellectualcrafters.plot.object.ChunkLoc; -import com.intellectualcrafters.plot.object.ConsolePlayer; import com.intellectualcrafters.plot.object.Location; import com.intellectualcrafters.plot.object.Plot; import com.intellectualcrafters.plot.object.PlotPlayer; import com.intellectualcrafters.plot.object.RegionWrapper; import com.intellectualcrafters.plot.object.RunnableVal; import com.intellectualcrafters.plot.util.SetQueue.ChunkWrapper; + import java.io.File; import java.util.ArrayList; import java.util.Collection; @@ -114,7 +114,7 @@ public abstract class ChunkManager { Runnable smallTask = new Runnable() { @Override public void run() { - if (regions.size() == 0) { + if (regions.isEmpty()) { TaskManager.runTask(whenDone); return; } @@ -254,7 +254,7 @@ public abstract class ChunkManager { for (ChunkLoc loc : chunks) { String directory = world + File.separator + "region" + File.separator + "r." + loc.x + "." + loc.z + ".mca"; File file = new File(PS.get().IMP.getWorldContainer(), directory); - ConsolePlayer.getConsole().sendMessage("&6 - Deleting file: " + file.getName() + " (max 1024 chunks)"); + PS.log("&6 - Deleting file: " + file.getName() + " (max 1024 chunks)"); if (file.exists()) { file.delete(); } diff --git a/Core/src/main/java/com/intellectualcrafters/plot/util/CommentManager.java b/Core/src/main/java/com/intellectualcrafters/plot/util/CommentManager.java index 30b8eab95..ab36f83e0 100644 --- a/Core/src/main/java/com/intellectualcrafters/plot/util/CommentManager.java +++ b/Core/src/main/java/com/intellectualcrafters/plot/util/CommentManager.java @@ -18,7 +18,7 @@ import java.util.concurrent.atomic.AtomicInteger; public class CommentManager { - public static HashMap inboxes = new HashMap<>(); + public static final HashMap inboxes = new HashMap<>(); public static void sendTitle(final PlotPlayer player, final Plot plot) { if (!Settings.COMMENT_NOTIFICATIONS || !plot.isOwner(player.getUUID())) { diff --git a/Core/src/main/java/com/intellectualcrafters/plot/util/EconHandler.java b/Core/src/main/java/com/intellectualcrafters/plot/util/EconHandler.java index 3580a885f..f1979eeaf 100644 --- a/Core/src/main/java/com/intellectualcrafters/plot/util/EconHandler.java +++ b/Core/src/main/java/com/intellectualcrafters/plot/util/EconHandler.java @@ -19,7 +19,7 @@ public abstract class EconHandler { } public double getMoney(PlotPlayer player) { - if (ConsolePlayer.isConsole(player)) { + if (player instanceof ConsolePlayer) { return Double.MAX_VALUE; } return getBalance(player); diff --git a/Core/src/main/java/com/intellectualcrafters/plot/util/EventUtil.java b/Core/src/main/java/com/intellectualcrafters/plot/util/EventUtil.java index c7adcbfb5..f14952214 100644 --- a/Core/src/main/java/com/intellectualcrafters/plot/util/EventUtil.java +++ b/Core/src/main/java/com/intellectualcrafters/plot/util/EventUtil.java @@ -15,6 +15,7 @@ import com.intellectualcrafters.plot.object.PlotId; import com.intellectualcrafters.plot.object.PlotPlayer; import com.intellectualcrafters.plot.object.Rating; import com.plotsquared.listener.PlayerBlockEventType; + import java.util.ArrayList; import java.util.HashSet; import java.util.UUID; diff --git a/Core/src/main/java/com/intellectualcrafters/plot/util/MainUtil.java b/Core/src/main/java/com/intellectualcrafters/plot/util/MainUtil.java index dd612eaf9..32a44b945 100644 --- a/Core/src/main/java/com/intellectualcrafters/plot/util/MainUtil.java +++ b/Core/src/main/java/com/intellectualcrafters/plot/util/MainUtil.java @@ -601,7 +601,8 @@ public class MainUtil { public static boolean sendMessage(PlotPlayer player, String msg, boolean prefix) { if (!msg.isEmpty()) { if (player == null) { - ConsolePlayer.getConsole().sendMessage((prefix ? C.PREFIX.s() : "") + msg); + String message = (prefix ? C.PREFIX.s() : "") + msg; + PS.log(message); } else { player.sendMessage((prefix ? C.PREFIX.s() : "") + C.color(msg)); } @@ -638,7 +639,7 @@ public class MainUtil { public void run() { String m = C.format(c, args); if (plr == null) { - ConsolePlayer.getConsole().sendMessage(m); + PS.log(m); } else { plr.sendMessage(m); } 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 d151634a2..8ea5775b4 100644 --- a/Core/src/main/java/com/intellectualcrafters/plot/util/SchematicHandler.java +++ b/Core/src/main/java/com/intellectualcrafters/plot/util/SchematicHandler.java @@ -24,6 +24,7 @@ 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 java.io.BufferedReader; import java.io.File; import java.io.FileInputStream; @@ -705,7 +706,7 @@ public abstract class SchematicHandler { * @return Map of block location to tag */ public HashMap getTiles() { - return this.tiles == null ? new HashMap() : tiles; + return this.tiles == null ? new HashMap() : this.tiles; } /** diff --git a/Core/src/main/java/com/intellectualcrafters/plot/util/SetQueue.java b/Core/src/main/java/com/intellectualcrafters/plot/util/SetQueue.java index 5c2b6619e..6b4e414f3 100644 --- a/Core/src/main/java/com/intellectualcrafters/plot/util/SetQueue.java +++ b/Core/src/main/java/com/intellectualcrafters/plot/util/SetQueue.java @@ -2,6 +2,7 @@ package com.intellectualcrafters.plot.util; import com.intellectualcrafters.plot.object.ChunkLoc; import com.intellectualcrafters.plot.object.PlotBlock; + import java.util.ArrayDeque; import java.util.concurrent.atomic.AtomicInteger; @@ -150,7 +151,7 @@ public class SetQueue { } public void regenerateChunk(String world, ChunkLoc loc) { - queue.regenerateChunk(world, loc); + this.queue.regenerateChunk(world, loc); } public class ChunkWrapper { diff --git a/Core/src/main/java/com/intellectualcrafters/plot/util/TaskManager.java b/Core/src/main/java/com/intellectualcrafters/plot/util/TaskManager.java index 8dc970c51..69bd7299d 100644 --- a/Core/src/main/java/com/intellectualcrafters/plot/util/TaskManager.java +++ b/Core/src/main/java/com/intellectualcrafters/plot/util/TaskManager.java @@ -11,10 +11,9 @@ import java.util.concurrent.atomic.AtomicInteger; public abstract class TaskManager { - public static HashSet TELEPORT_QUEUE = new HashSet<>(); - + public static final HashSet TELEPORT_QUEUE = new HashSet<>(); + public static final HashMap tasks = new HashMap<>(); public static AtomicInteger index = new AtomicInteger(0); - public static HashMap tasks = new HashMap<>(); public static int runTaskRepeat(Runnable runnable, int interval) { if (runnable != null) { diff --git a/Core/src/main/java/com/intellectualcrafters/plot/util/UUIDHandlerImplementation.java b/Core/src/main/java/com/intellectualcrafters/plot/util/UUIDHandlerImplementation.java index 49ea2d728..6dd62f0a2 100644 --- a/Core/src/main/java/com/intellectualcrafters/plot/util/UUIDHandlerImplementation.java +++ b/Core/src/main/java/com/intellectualcrafters/plot/util/UUIDHandlerImplementation.java @@ -7,7 +7,6 @@ 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.ConsolePlayer; import com.intellectualcrafters.plot.object.OfflinePlotPlayer; import com.intellectualcrafters.plot.object.Plot; import com.intellectualcrafters.plot.object.PlotPlayer; @@ -25,8 +24,8 @@ import java.util.concurrent.ConcurrentHashMap; public abstract class UUIDHandlerImplementation { public final ConcurrentHashMap players; + public final HashSet unknown = new HashSet<>(); public UUIDWrapper uuidWrapper = null; - public HashSet unknown = new HashSet<>(); private boolean cached = false; private BiMap uuidMap = HashBiMap.create(new HashMap()); @@ -97,7 +96,7 @@ public abstract class UUIDHandlerImplementation { try { this.unknown.add(uuid); } catch (Exception e) { - ConsolePlayer.getConsole().sendMessage("&c(minor) Invalid UUID mapping: " + uuid); + PS.log("&c(minor) Invalid UUID mapping: " + uuid); e.printStackTrace(); } return false; diff --git a/Core/src/main/java/com/plotsquared/general/commands/Argument.java b/Core/src/main/java/com/plotsquared/general/commands/Argument.java index 9fd937007..f8a0249c5 100644 --- a/Core/src/main/java/com/plotsquared/general/commands/Argument.java +++ b/Core/src/main/java/com/plotsquared/general/commands/Argument.java @@ -1,10 +1,6 @@ package com.plotsquared.general.commands; -import com.intellectualcrafters.plot.object.ConsolePlayer; -import com.intellectualcrafters.plot.object.Plot; -import com.intellectualcrafters.plot.object.PlotArea; import com.intellectualcrafters.plot.object.PlotId; -import com.intellectualcrafters.plot.util.MainUtil; public abstract class Argument { @@ -37,24 +33,18 @@ public abstract class Argument { return in; } }; - public static Argument PlayerName = new Argument("PlayerName", "Dinnerbone") { + public static final Argument PlayerName = new Argument("PlayerName", "Dinnerbone") { @Override public String parse(String in) { return in.length() <= 16 ? in : null; } }; - public static Argument PlotID = new Argument("PlotID", new PlotId(-6, 3)) { + public static final Argument PlotID = new Argument("PlotID", new PlotId(-6, 3)) { @Override public PlotId parse(String in) { return PlotId.fromString(in); } }; - public static Argument Plot = new Argument("Plot", new Plot(PlotArea.createGeneric("world"), new PlotId(3, -6), null)) { - @Override - public Plot parse(String in) { - return MainUtil.getPlotFromString(ConsolePlayer.getConsole(), in, false); - } - }; private final String name; private final T example; 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 3b90f0eef..2f69d4652 100644 --- a/Core/src/main/java/com/plotsquared/general/commands/Command.java +++ b/Core/src/main/java/com/plotsquared/general/commands/Command.java @@ -459,13 +459,13 @@ public abstract class Command { } public String getUsage() { - if (this.usage != null && this.usage.length() != 0) { + if (this.usage != null && !this.usage.isEmpty()) { if (this.usage.startsWith("/")) { return this.usage; } return getCommandString() + " " + this.usage; } - if (this.allCommands.size() == 0) { + if (this.allCommands.isEmpty()) { return getCommandString(); } StringBuilder args = new StringBuilder("["); @@ -477,7 +477,7 @@ public abstract class Command { return getCommandString() + " " + args + "]"; } - public Collection tab(PlotPlayer player, String[] args, boolean space) { + public Collection tab(PlotPlayer player, String[] args, boolean space) { switch (args.length) { case 0: return this.allCommands; @@ -511,7 +511,7 @@ public abstract class Command { @Override public String toString() { - return this.aliases.size() > 0 ? this.aliases.get(0) : this.id; + return !this.aliases.isEmpty() ? this.aliases.get(0) : this.id; } @Override diff --git a/Sponge/src/main/java/com/plotsquared/sponge/SpongeMain.java b/Sponge/src/main/java/com/plotsquared/sponge/SpongeMain.java index 759a0ebef..616a1c4da 100644 --- a/Sponge/src/main/java/com/plotsquared/sponge/SpongeMain.java +++ b/Sponge/src/main/java/com/plotsquared/sponge/SpongeMain.java @@ -64,6 +64,7 @@ import org.spongepowered.api.event.game.state.GamePreInitializationEvent; import org.spongepowered.api.plugin.Plugin; import org.spongepowered.api.plugin.PluginContainer; import org.spongepowered.api.profile.GameProfileManager; +import org.spongepowered.api.world.Chunk; import org.spongepowered.api.world.World; import org.spongepowered.api.world.gen.GenerationPopulator; import org.spongepowered.api.world.gen.WorldGenerator; @@ -165,7 +166,7 @@ public class SpongeMain implements IPlotMain { @Override public int[] getPluginVersion() { PluginContainer plugin = this.game.getPluginManager().fromInstance(this).get(); - String version = plugin.getVersion().get(); + String version = plugin.getVersion().orElse(""); String[] split = version.split("\\."); return new int[]{Integer.parseInt(split[0]), Integer.parseInt(split[1]), split.length == 3 ? Integer.parseInt(split[2]) : 0}; } @@ -217,7 +218,7 @@ public class SpongeMain implements IPlotMain { @Override public TaskManager getTaskManager() { - return new SpongeTaskManager(); + return new SpongeTaskManager(this); } @Override @@ -370,7 +371,7 @@ public class SpongeMain implements IPlotMain { } @Override - public PlotQueue initPlotQueue() { + public PlotQueue initPlotQueue() { if (PS.get().checkVersion(getServerVersion(), 1, 8, 0)) { try { MainUtil.canSendChunk = true; diff --git a/Sponge/src/main/java/com/plotsquared/sponge/listener/MainListener.java b/Sponge/src/main/java/com/plotsquared/sponge/listener/MainListener.java index c08219e4d..6f964f15e 100644 --- a/Sponge/src/main/java/com/plotsquared/sponge/listener/MainListener.java +++ b/Sponge/src/main/java/com/plotsquared/sponge/listener/MainListener.java @@ -286,7 +286,7 @@ public class MainListener { public void onNotifyNeighborBlock(NotifyNeighborBlockEvent event) throws Exception { AtomicBoolean cancelled = new AtomicBoolean(false); -// SpongeUtil.printCause("physics", event.getCause()); + // SpongeUtil.printCause("physics", event.getCause()); // PlotArea area = plotloc.getPlotArea(); // event.filterDirections(new Predicate() { // diff --git a/Sponge/src/main/java/com/plotsquared/sponge/object/SpongePlayer.java b/Sponge/src/main/java/com/plotsquared/sponge/object/SpongePlayer.java index ed7b7846d..b59cc2b0c 100644 --- a/Sponge/src/main/java/com/plotsquared/sponge/object/SpongePlayer.java +++ b/Sponge/src/main/java/com/plotsquared/sponge/object/SpongePlayer.java @@ -19,6 +19,7 @@ import org.spongepowered.api.entity.living.player.gamemode.GameModes; import org.spongepowered.api.service.ban.BanService; import org.spongepowered.api.text.chat.ChatTypes; import org.spongepowered.api.text.serializer.TextSerializers; +import org.spongepowered.api.world.World; import java.time.Instant; import java.util.UUID; @@ -94,7 +95,7 @@ public class SpongePlayer extends PlotPlayer { if (!world.equals(location.getWorld())) { this.player.transferToWorld(location.getWorld(), new Vector3d(location.getX(), location.getY(), location.getZ())); } else { - org.spongepowered.api.world.Location current = this.player.getLocation(); + org.spongepowered.api.world.Location current = this.player.getLocation(); current = current.setPosition(new Vector3d(location.getX(), location.getY(), location.getZ())); this.player.setLocation(current); } diff --git a/Sponge/src/main/java/com/plotsquared/sponge/util/SpongeChatManager.java b/Sponge/src/main/java/com/plotsquared/sponge/util/SpongeChatManager.java index ded1b685f..1a7abdf89 100644 --- a/Sponge/src/main/java/com/plotsquared/sponge/util/SpongeChatManager.java +++ b/Sponge/src/main/java/com/plotsquared/sponge/util/SpongeChatManager.java @@ -22,7 +22,7 @@ public class SpongeChatManager extends ChatManager { } @Override - public void color(final PlotMessage m, final String color) { + public void color(PlotMessage m, String color) { TextColor tc = null; TextStyle ts = null; switch (color.charAt(1)) { @@ -114,10 +114,10 @@ public class SpongeChatManager extends ChatManager { } @Override - public void tooltip(final PlotMessage m, final PlotMessage... tooltips) { - final Text.Builder builder = Text.builder(); + public void tooltip(PlotMessage m, PlotMessage... tooltips) { + Text.Builder builder = Text.builder(); boolean lb = false; - for (final PlotMessage tooltip : tooltips) { + for (PlotMessage tooltip : tooltips) { if (lb) { builder.append(Text.of("\n")); } @@ -128,18 +128,18 @@ public class SpongeChatManager extends ChatManager { } @Override - public void command(final PlotMessage m, final String command) { + public void command(PlotMessage m, String command) { apply(m, getChild(m).onClick(TextActions.runCommand(command))); } @Override - public void text(final PlotMessage m, final String text) { + public void text(PlotMessage m, String text) { m.$(this).append(SpongeUtil.getText(text)); } @Override - public void send(final PlotMessage m, final PlotPlayer player) { - if (ConsolePlayer.isConsole(player)) { + public void send(PlotMessage m, PlotPlayer player) { + if (player instanceof ConsolePlayer) { player.sendMessage(m.$(this).build().toPlain()); } else { ((SpongePlayer) player).player.sendMessage(m.$(this).build()); @@ -147,7 +147,7 @@ public class SpongeChatManager extends ChatManager { } @Override - public void suggest(final PlotMessage m, final String command) { + public void suggest(PlotMessage m, String command) { apply(m, getChild(m).onClick(TextActions.suggestCommand(command))); } } diff --git a/Sponge/src/main/java/com/plotsquared/sponge/util/SpongeChunkManager.java b/Sponge/src/main/java/com/plotsquared/sponge/util/SpongeChunkManager.java index 312910917..cc76508ac 100644 --- a/Sponge/src/main/java/com/plotsquared/sponge/util/SpongeChunkManager.java +++ b/Sponge/src/main/java/com/plotsquared/sponge/util/SpongeChunkManager.java @@ -5,9 +5,6 @@ import com.intellectualcrafters.plot.object.Location; import com.intellectualcrafters.plot.object.Plot; import com.intellectualcrafters.plot.util.ChunkManager; import com.intellectualcrafters.plot.util.TaskManager; -import java.util.Optional; -import java.util.Set; -import java.util.function.Predicate; import org.spongepowered.api.entity.Entity; import org.spongepowered.api.entity.living.Living; import org.spongepowered.api.entity.living.animal.Animal; @@ -15,6 +12,10 @@ import org.spongepowered.api.entity.living.monster.Monster; import org.spongepowered.api.world.Chunk; import org.spongepowered.api.world.World; +import java.util.Optional; +import java.util.Set; +import java.util.function.Predicate; + public class SpongeChunkManager extends ChunkManager { @Override diff --git a/Sponge/src/main/java/com/plotsquared/sponge/util/SpongeCommand.java b/Sponge/src/main/java/com/plotsquared/sponge/util/SpongeCommand.java index 73c88cf6f..34c2eb32a 100644 --- a/Sponge/src/main/java/com/plotsquared/sponge/util/SpongeCommand.java +++ b/Sponge/src/main/java/com/plotsquared/sponge/util/SpongeCommand.java @@ -5,12 +5,6 @@ import com.intellectualcrafters.plot.object.ConsolePlayer; import com.intellectualcrafters.plot.object.PlotPlayer; import com.intellectualcrafters.plot.util.TaskManager; import com.plotsquared.sponge.SpongeMain; -import java.util.ArrayList; -import java.util.Collection; -import java.util.Collections; -import java.util.List; -import java.util.Optional; -import java.util.UUID; import org.spongepowered.api.command.CommandCallable; import org.spongepowered.api.command.CommandException; import org.spongepowered.api.command.CommandResult; @@ -18,18 +12,25 @@ import org.spongepowered.api.command.CommandSource; import org.spongepowered.api.entity.living.player.Player; import org.spongepowered.api.text.Text; +import java.util.ArrayList; +import java.util.Collection; +import java.util.Collections; +import java.util.List; +import java.util.Optional; +import java.util.UUID; + public class SpongeCommand implements CommandCallable { @Override - public CommandResult process(final CommandSource cmd, final String string) throws CommandException { + public CommandResult process(CommandSource cmd, String string) throws CommandException { TaskManager.runTask(() -> { - final String id = cmd.getIdentifier(); + String id = cmd.getIdentifier(); PlotPlayer pp; try { - final UUID uuid = UUID.fromString(id); - final Player player = SpongeMain.THIS.getServer().getPlayer(uuid).get(); + UUID uuid = UUID.fromString(id); + Player player = SpongeMain.THIS.getServer().getPlayer(uuid).get(); pp = SpongeUtil.getPlayer(player); - } catch (final Exception e) { + } catch (Exception e) { pp = ConsolePlayer.getConsole(); } MainCommand.onCommand(pp, string.isEmpty() ? new String[]{} : string.split(" ")); @@ -38,11 +39,11 @@ public class SpongeCommand implements CommandCallable { } @Override - public List getSuggestions(final CommandSource source, final String s) throws CommandException { + public List getSuggestions(CommandSource source, String s) throws CommandException { if (!(source instanceof Player)) { return null; } - final PlotPlayer player = SpongeUtil.getPlayer((Player) source); + PlotPlayer player = SpongeUtil.getPlayer((Player) source); String[] args = s.split(" "); if (args.length == 0) { return Collections.singletonList(MainCommand.getInstance().toString()); @@ -55,26 +56,26 @@ public class SpongeCommand implements CommandCallable { for (Object o : objects) { result.add(o.toString()); } - return result.size() == 0 ? null : result; + return result.isEmpty() ? null : result; } @Override - public boolean testPermission(final CommandSource cmd) { + public boolean testPermission(CommandSource cmd) { return true; } @Override - public Optional getShortDescription(final CommandSource cmd) { + public Optional getShortDescription(CommandSource cmd) { return Optional.of(Text.of("Shows plot help")); } @Override - public Optional getHelp(final CommandSource cmd) { + public Optional getHelp(CommandSource cmd) { return Optional.of(Text.of("/plot")); } @Override - public Text getUsage(final CommandSource cmd) { + public Text getUsage(CommandSource cmd) { return Text.of("/plot "); } diff --git a/Sponge/src/main/java/com/plotsquared/sponge/util/SpongeEventUtil.java b/Sponge/src/main/java/com/plotsquared/sponge/util/SpongeEventUtil.java index a77c5820b..345125c6c 100644 --- a/Sponge/src/main/java/com/plotsquared/sponge/util/SpongeEventUtil.java +++ b/Sponge/src/main/java/com/plotsquared/sponge/util/SpongeEventUtil.java @@ -36,25 +36,25 @@ public class SpongeEventUtil extends EventUtil { public EventManager events; public SpongeEventUtil() { - events = SpongeMain.THIS.getGame().getEventManager(); + this.events = SpongeMain.THIS.getGame().getEventManager(); } - - public boolean callEvent(final Event event) { - return !events.post(event); + + public boolean callEvent(Event event) { + return !this.events.post(event); } @Override - public boolean callClaim(final PlotPlayer player, final Plot plot, final boolean auto) { + public boolean callClaim(PlotPlayer player, Plot plot, boolean auto) { return callEvent(new PlayerClaimPlotEvent(SpongeUtil.getPlayer(player), plot, auto)); } @Override - public boolean callTeleport(final PlotPlayer player, final Location from, final Plot plot) { + public boolean callTeleport(PlotPlayer player, Location from, Plot plot) { return callEvent(new PlayerTeleportToPlotEvent(SpongeUtil.getPlayer(player), from, plot)); } @Override - public boolean callClear(final Plot plot) { + public boolean callClear(Plot plot) { return callEvent(new PlotClearEvent(plot)); } @@ -64,59 +64,59 @@ public class SpongeEventUtil extends EventUtil { } @Override - public boolean callFlagAdd(final Flag flag, final Plot plot) { + public boolean callFlagAdd(Flag flag, Plot plot) { return callEvent(new PlotFlagAddEvent(flag, plot)); } @Override - public boolean callFlagRemove(final Flag flag, final Plot plot) { + public boolean callFlagRemove(Flag flag, Plot plot) { return callEvent(new PlotFlagRemoveEvent(flag, plot)); } @Override - public boolean callMerge(final Plot plot, final ArrayList plots) { + public boolean callMerge(Plot plot, ArrayList plots) { return callEvent(new PlotMergeEvent(SpongeUtil.getWorld(plot.getArea().worldname), plot, plots)); } @Override - public boolean callUnlink(final PlotArea area, final ArrayList plots) { + public boolean callUnlink(PlotArea area, ArrayList plots) { return callEvent(new PlotUnlinkEvent(SpongeUtil.getWorld(area.worldname), plots)); } @Override - public void callEntry(final PlotPlayer player, final Plot plot) { + public void callEntry(PlotPlayer player, Plot plot) { callEvent(new PlayerEnterPlotEvent(SpongeUtil.getPlayer(player), plot)); } @Override - public void callLeave(final PlotPlayer player, final Plot plot) { + public void callLeave(PlotPlayer player, Plot plot) { callEvent(new PlayerLeavePlotEvent(SpongeUtil.getPlayer(player), plot)); } @Override - public void callDenied(final PlotPlayer initiator, final Plot plot, final UUID player, final boolean added) { + public void callDenied(PlotPlayer initiator, Plot plot, UUID player, boolean added) { callEvent(new PlayerPlotDeniedEvent(SpongeUtil.getPlayer(initiator), plot, player, added)); } @Override - public void callTrusted(final PlotPlayer initiator, final Plot plot, final UUID player, final boolean added) { + public void callTrusted(PlotPlayer initiator, Plot plot, UUID player, boolean added) { callEvent(new PlayerPlotHelperEvent(SpongeUtil.getPlayer(initiator), plot, player, added)); } @Override - public void callMember(final PlotPlayer initiator, final Plot plot, final UUID player, final boolean added) { + public void callMember(PlotPlayer initiator, Plot plot, UUID player, boolean added) { callEvent(new PlayerPlotTrustedEvent(SpongeUtil.getPlayer(initiator), plot, player, added)); } @Override - public boolean callFlagRemove(final Flag flag, final PlotCluster cluster) { + public boolean callFlagRemove(Flag flag, PlotCluster cluster) { return callEvent(new ClusterFlagRemoveEvent(flag, cluster)); } @Override - public Rating callRating(final PlotPlayer player, final Plot plot, final Rating rating) { - final PlotRateEvent event = new PlotRateEvent(player, rating, plot); - events.post(event); + public Rating callRating(PlotPlayer player, Plot plot, Rating rating) { + PlotRateEvent event = new PlotRateEvent(player, rating, plot); + this.events.post(event); return event.getRating(); } diff --git a/Sponge/src/main/java/com/plotsquared/sponge/util/SpongeTaskManager.java b/Sponge/src/main/java/com/plotsquared/sponge/util/SpongeTaskManager.java index 1747c935a..6272c33f1 100644 --- a/Sponge/src/main/java/com/plotsquared/sponge/util/SpongeTaskManager.java +++ b/Sponge/src/main/java/com/plotsquared/sponge/util/SpongeTaskManager.java @@ -12,13 +12,18 @@ public class SpongeTaskManager extends TaskManager { private final AtomicInteger i = new AtomicInteger(); private final HashMap tasks = new HashMap<>(); + private final SpongeMain spongeMain; + + public SpongeTaskManager(SpongeMain spongeMain) { + this.spongeMain = spongeMain; + } @Override public int taskRepeat(Runnable runnable, int interval) { int val = this.i.incrementAndGet(); - Task.Builder builder = SpongeMain.THIS.getGame().getScheduler().createTaskBuilder(); + Task.Builder builder = this.spongeMain.getGame().getScheduler().createTaskBuilder(); Task.Builder built = builder.delayTicks(interval).intervalTicks(interval).execute(runnable); - Task task = built.submit(SpongeMain.THIS.getPlugin()); + Task task = built.submit(this.spongeMain.getPlugin()); this.tasks.put(val, task); return val; } @@ -26,35 +31,35 @@ public class SpongeTaskManager extends TaskManager { @Override public int taskRepeatAsync(Runnable runnable, int interval) { int val = this.i.incrementAndGet(); - Task.Builder builder = SpongeMain.THIS.getGame().getScheduler().createTaskBuilder(); + Task.Builder builder = this.spongeMain.getGame().getScheduler().createTaskBuilder(); Task.Builder built = builder.delayTicks(interval).async().intervalTicks(interval).execute(runnable); - Task task = built.submit(SpongeMain.THIS.getPlugin()); + Task task = built.submit(this.spongeMain.getPlugin()); this.tasks.put(val, task); return val; } @Override public void taskAsync(Runnable runnable) { - Task.Builder builder = SpongeMain.THIS.getGame().getScheduler().createTaskBuilder(); - builder.async().execute(runnable).submit(SpongeMain.THIS.getPlugin()); + Task.Builder builder = this.spongeMain.getGame().getScheduler().createTaskBuilder(); + builder.async().execute(runnable).submit(this.spongeMain.getPlugin()); } @Override public void task(Runnable runnable) { - Task.Builder builder = SpongeMain.THIS.getGame().getScheduler().createTaskBuilder(); - builder.execute(runnable).submit(SpongeMain.THIS.getPlugin()); + Task.Builder builder = this.spongeMain.getGame().getScheduler().createTaskBuilder(); + builder.execute(runnable).submit(this.spongeMain.getPlugin()); } @Override public void taskLater(Runnable runnable, int delay) { - Task.Builder builder = SpongeMain.THIS.getGame().getScheduler().createTaskBuilder(); - builder.delayTicks(delay).execute(runnable).submit(SpongeMain.THIS.getPlugin()); + Task.Builder builder = this.spongeMain.getGame().getScheduler().createTaskBuilder(); + builder.delayTicks(delay).execute(runnable).submit(this.spongeMain.getPlugin()); } @Override public void taskLaterAsync(Runnable runnable, int delay) { - Task.Builder builder = SpongeMain.THIS.getGame().getScheduler().createTaskBuilder(); - builder.async().delayTicks(delay).execute(runnable).submit(SpongeMain.THIS.getPlugin()); + Task.Builder builder = this.spongeMain.getGame().getScheduler().createTaskBuilder(); + builder.async().delayTicks(delay).execute(runnable).submit(this.spongeMain.getPlugin()); } @Override diff --git a/Sponge/src/main/java/com/plotsquared/sponge/util/SpongeUtil.java b/Sponge/src/main/java/com/plotsquared/sponge/util/SpongeUtil.java index 0a473f649..3f8b61a20 100644 --- a/Sponge/src/main/java/com/plotsquared/sponge/util/SpongeUtil.java +++ b/Sponge/src/main/java/com/plotsquared/sponge/util/SpongeUtil.java @@ -17,13 +17,6 @@ import com.intellectualcrafters.plot.util.UUIDHandler; import com.intellectualcrafters.plot.util.WorldUtil; import com.plotsquared.sponge.SpongeMain; import com.plotsquared.sponge.object.SpongePlayer; -import java.lang.reflect.Field; -import java.lang.reflect.Method; -import java.util.ArrayList; -import java.util.HashMap; -import java.util.List; -import java.util.Locale; -import java.util.Optional; import net.minecraft.block.Block; import net.minecraft.world.biome.BiomeGenBase; import org.apache.commons.lang3.NotImplementedException; @@ -49,6 +42,14 @@ import org.spongepowered.api.world.biome.BiomeType; import org.spongepowered.api.world.biome.BiomeTypes; import org.spongepowered.api.world.extent.Extent; +import java.lang.reflect.Field; +import java.lang.reflect.Method; +import java.util.ArrayList; +import java.util.HashMap; +import java.util.List; +import java.util.Locale; +import java.util.Optional; + public class SpongeUtil extends WorldUtil { public static Cause CAUSE = Cause.of(NamedCause.source("PlotSquared")); diff --git a/Sponge/src/main/java/com/plotsquared/sponge/util/block/SlowQueue.java b/Sponge/src/main/java/com/plotsquared/sponge/util/block/SlowQueue.java index 8581b889c..bc7f804da 100644 --- a/Sponge/src/main/java/com/plotsquared/sponge/util/block/SlowQueue.java +++ b/Sponge/src/main/java/com/plotsquared/sponge/util/block/SlowQueue.java @@ -10,17 +10,17 @@ import com.intellectualcrafters.plot.util.PlotQueue; import com.intellectualcrafters.plot.util.SetQueue; import com.intellectualcrafters.plot.util.SetQueue.ChunkWrapper; import com.plotsquared.sponge.util.SpongeUtil; -import java.util.Optional; import net.minecraft.world.chunk.IChunkProvider; import net.minecraft.world.gen.ChunkProviderServer; import org.spongepowered.api.block.BlockState; import org.spongepowered.api.world.Chunk; +import org.spongepowered.api.world.World; import java.util.Collection; import java.util.Iterator; import java.util.Map.Entry; +import java.util.Optional; import java.util.concurrent.ConcurrentHashMap; -import org.spongepowered.api.world.World; public class SlowQueue implements PlotQueue { @@ -148,7 +148,7 @@ public class SlowQueue implements PlotQueue { else { PS.debug("CHUNK IS NULL!?"); }*/ - } catch (Throwable e){ + } catch (Throwable e) { e.printStackTrace(); } } diff --git a/build.gradle b/build.gradle index 120977dcb..9dae120c8 100644 --- a/build.gradle +++ b/build.gradle @@ -23,6 +23,7 @@ subprojects { compile(group: 'com.sk89q', name: 'worldedit', version:'6.0.0-SNAPSHOT') { exclude(module: 'bukkit-classloader-check') } + compile 'com.google.guava:guava:10.0' } clean{ delete file("../target") diff --git a/pom.xml b/pom.xml index 4d2e24e5e..ad8947cb5 100644 --- a/pom.xml +++ b/pom.xml @@ -1,5 +1,6 @@ - + 4.0.0 com.intellectualcrafters