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 d7d8278c8..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,17 +109,13 @@ public class ClassicPlotMeConnector extends APlotMeConnector { owner = DBFunc.everyone; } else { if (checkUUID || checkUUID2) { - try { - 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); - } - } 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 (name.isEmpty()) { @@ -173,17 +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) { - ByteBuffer bb = ByteBuffer.wrap(bytes); - long mostSigBits = bb.getLong(); - long leastSigBits = bb.getLong(); - denied = new UUID(mostSigBits, leastSigBits); - 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) { @@ -212,17 +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) { - ByteBuffer bb = ByteBuffer.wrap(bytes); - long mostSigBits = bb.getLong(); - long leastSigBits = bb.getLong(); - helper = new UUID(mostSigBits, leastSigBits); - 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 8438659ac..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 @@ -63,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)) { @@ -83,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); @@ -92,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 @@ -117,7 +117,7 @@ public class LikePlotMeConverter { PS.debug("&3Using connector: " + connector.getClass().getCanonicalName()); - Connection connection = connector.getPlotMeConnection("PlotMe", plotConfig, dataFolder); + Connection connection = connector.getPlotMeConnection(plotConfig, dataFolder); if (!connector.isValidConnection(connection)) { sendMessage("Cannot connect to PlotMe DB. Conversion process will not continue"); @@ -126,7 +126,7 @@ public class LikePlotMeConverter { sendMessage("PlotMe conversion has started. To disable this, please set 'plotme-convert.enabled' to false in the 'settings.yml'"); - mergeWorldYml("PlotMe", plotConfig); + mergeWorldYml(plotConfig); sendMessage("Connecting to PlotMe DB"); @@ -140,8 +140,8 @@ public class LikePlotMeConverter { if (Settings.CONVERT_PLOTME) { sendMessage("Updating bukkit.yml"); - updateWorldYml("PlotMe", "bukkit.yml"); - updateWorldYml("PlotMe", "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 { 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 c2d527139..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 @@ -26,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"); @@ -109,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) { 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..d0ab1b024 100644 --- a/Bukkit/src/main/java/com/plotsquared/bukkit/titles/DefaultTitleManager.java +++ b/Bukkit/src/main/java/com/plotsquared/bukkit/titles/DefaultTitleManager.java @@ -43,9 +43,8 @@ public class DefaultTitleManager { * Create a new 1.8 title. * * @param title Title - * @throws ClassNotFoundException */ - public DefaultTitleManager(String title) throws ClassNotFoundException { + public DefaultTitleManager(String title) { this.title = title; loadClasses(); } @@ -55,9 +54,8 @@ public class DefaultTitleManager { * * @param title Title text * @param subtitle Subtitle text - * @throws ClassNotFoundException */ - public DefaultTitleManager(String title, String subtitle) throws ClassNotFoundException { + public DefaultTitleManager(String title, String subtitle) { this.title = title; this.subtitle = subtitle; loadClasses(); @@ -67,9 +65,8 @@ public class DefaultTitleManager { * Copy 1.8 title. * * @param title Title - * @throws ClassNotFoundException */ - public DefaultTitleManager(DefaultTitleManager title) throws ClassNotFoundException { + public DefaultTitleManager(DefaultTitleManager title) { // Copy title this.title = title.title; this.subtitle = title.subtitle; @@ -90,10 +87,8 @@ 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 { + public DefaultTitleManager(String title, String subtitle, int fadeInTime, int stayTime, int fadeOutTime) { this.title = title; this.subtitle = subtitle; this.fadeInTime = fadeInTime; 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..5dd450858 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 @@ -42,11 +42,9 @@ public class DefaultTitleManager_183 { /** * Create a new 1.8 title * - * @param title - * Title - * @throws ClassNotFoundException + * @param title Title */ - public DefaultTitleManager_183(String title) throws ClassNotFoundException { + public DefaultTitleManager_183(String title) { this.title = title; loadClasses(); } @@ -56,9 +54,8 @@ public class DefaultTitleManager_183 { * * @param title Title text * @param subtitle Subtitle text - * @throws ClassNotFoundException */ - public DefaultTitleManager_183(String title, String subtitle) throws ClassNotFoundException { + public DefaultTitleManager_183(String title, String subtitle) { this.title = title; this.subtitle = subtitle; loadClasses(); @@ -68,9 +65,8 @@ public class DefaultTitleManager_183 { * Copy 1.8 title. * * @param title Title - * @throws ClassNotFoundException */ - public DefaultTitleManager_183(DefaultTitleManager_183 title) throws ClassNotFoundException { + public DefaultTitleManager_183(DefaultTitleManager_183 title) { // Copy title this.title = title.title; this.subtitle = title.subtitle; @@ -91,9 +87,8 @@ 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 { + public DefaultTitleManager_183(String title, String subtitle, int fadeInTime, int stayTime, int fadeOutTime) { this.title = title; this.subtitle = subtitle; this.fadeInTime = fadeInTime; 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..9fba9c439 100644 --- a/Bukkit/src/main/java/com/plotsquared/bukkit/titles/HackTitleManager.java +++ b/Bukkit/src/main/java/com/plotsquared/bukkit/titles/HackTitleManager.java @@ -42,9 +42,8 @@ public class HackTitleManager { * Create a new 1.8 title. * * @param title Title - * @throws ClassNotFoundException NMS Error. */ - public HackTitleManager(String title) throws ClassNotFoundException { + public HackTitleManager(String title) { this.title = title; loadClasses(); } @@ -54,9 +53,8 @@ public class HackTitleManager { * * @param title Title text * @param subtitle Subtitle text - * @throws ClassNotFoundException NMS Error */ - public HackTitleManager(String title, String subtitle) throws ClassNotFoundException { + public HackTitleManager(String title, String subtitle) { this.title = title; this.subtitle = subtitle; loadClasses(); @@ -66,9 +64,8 @@ public class HackTitleManager { * Copy 1.8 title. * * @param title Title - * @throws ClassNotFoundException NMS Error */ - public HackTitleManager(HackTitleManager title) throws ClassNotFoundException { + public HackTitleManager(HackTitleManager title) { // Copy title this.title = title.title; this.subtitle = title.subtitle; @@ -89,9 +86,8 @@ 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 { + public HackTitleManager(String title, String subtitle, int fadeInTime, int stayTime, int fadeOutTime) { this.title = title; this.subtitle = subtitle; this.fadeInTime = fadeInTime; 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 aecbaa448..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; } @@ -943,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(); @@ -1147,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 c5ca382b7..d97271f4b 100644 --- a/Bukkit/src/main/java/com/plotsquared/bukkit/util/BukkitCommand.java +++ b/Bukkit/src/main/java/com/plotsquared/bukkit/util/BukkitCommand.java @@ -53,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/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/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/commands/Inbox.java b/Core/src/main/java/com/intellectualcrafters/plot/commands/Inbox.java index b95ae2cf3..bac2b4a1c 100644 --- a/Core/src/main/java/com/intellectualcrafters/plot/commands/Inbox.java +++ b/Core/src/main/java/com/intellectualcrafters/plot/commands/Inbox.java @@ -67,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()) { @@ -183,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/Purge.java b/Core/src/main/java/com/intellectualcrafters/plot/commands/Purge.java index f83ffe6ec..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; @@ -150,9 +151,10 @@ public class Purge extends SubCommand { if (plot.temp != Integer.MAX_VALUE) { ids.add(plot.temp); plot.getArea().removePlot(plot.getId()); - for (PlotPlayer plotPlayer : plot.getPlayersInPlot()) { - plotPlayer.deleteMeta("lastplot"); + for (PlotPlayer pp : plot.getPlayersInPlot()) { + PlotListener.plotEntry(pp, plot); } + plot.removeSign(); } } DBFunc.purgeIds(ids); 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 2b7b3f4d7..d30162440 100644 --- a/Core/src/main/java/com/intellectualcrafters/plot/database/SQLManager.java +++ b/Core/src/main/java/com/intellectualcrafters/plot/database/SQLManager.java @@ -3147,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/generator/HybridPlotWorld.java b/Core/src/main/java/com/intellectualcrafters/plot/generator/HybridPlotWorld.java index 4d7ad2f10..2f4294475 100644 --- a/Core/src/main/java/com/intellectualcrafters/plot/generator/HybridPlotWorld.java +++ b/Core/src/main/java/com/intellectualcrafters/plot/generator/HybridPlotWorld.java @@ -214,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/object/Plot.java b/Core/src/main/java/com/intellectualcrafters/plot/object/Plot.java index 7a775fa45..38f844210 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/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/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 1ff54e2e9..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 @@ -12,45 +12,38 @@ 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; - } Optional> comments = plot.getSettings().getComments(toString()); if (comments.isPresent()) { whenDone.value = comments.get(); @@ -73,7 +66,7 @@ public class InboxOwner extends CommentInbox { }); return true; } - + @Override public boolean addComment(Plot plot, PlotComment comment) { if (plot.owner == null) { @@ -83,27 +76,10 @@ public class InboxOwner extends CommentInbox { 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 4bc114f58..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 @@ -15,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 @@ -35,18 +34,16 @@ 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.owner == null) { - return false; - } Optional> comments = plot.getSettings().getComments(toString()); if (comments.isPresent()) { whenDone.value = comments.get(); @@ -70,9 +67,6 @@ public class InboxPublic extends CommentInbox { @Override public boolean addComment(Plot plot, PlotComment comment) { - if (plot.owner == null) { - return false; - } plot.getSettings().addComment(comment); DBFunc.setComment(plot, comment); return true; @@ -82,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 c62690594..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,11 +33,12 @@ 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 @@ -64,21 +67,4 @@ public class InboxReport extends CommentInbox { return "report"; } - @Override - public boolean removeComment(Plot plot, PlotComment comment) { - if (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/ChunkManager.java b/Core/src/main/java/com/intellectualcrafters/plot/util/ChunkManager.java index 9f1d46bf3..bbb7292e5 100644 --- a/Core/src/main/java/com/intellectualcrafters/plot/util/ChunkManager.java +++ b/Core/src/main/java/com/intellectualcrafters/plot/util/ChunkManager.java @@ -111,7 +111,7 @@ public abstract class ChunkManager { Runnable smallTask = new Runnable() { @Override public void run() { - if (regions.size() == 0) { + if (regions.isEmpty()) { TaskManager.runTask(whenDone); return; } 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/UUIDHandlerImplementation.java b/Core/src/main/java/com/intellectualcrafters/plot/util/UUIDHandlerImplementation.java index 333aca30d..6dd62f0a2 100644 --- a/Core/src/main/java/com/intellectualcrafters/plot/util/UUIDHandlerImplementation.java +++ b/Core/src/main/java/com/intellectualcrafters/plot/util/UUIDHandlerImplementation.java @@ -24,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()); 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..12a45c976 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("["); @@ -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/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/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 "); }