diff --git a/PlotSquared/src/main/java/com/intellectualcrafters/plot/commands/Condense.java b/PlotSquared/src/main/java/com/intellectualcrafters/plot/commands/Condense.java index 4017d85ec..e91a1cc1a 100644 --- a/PlotSquared/src/main/java/com/intellectualcrafters/plot/commands/Condense.java +++ b/PlotSquared/src/main/java/com/intellectualcrafters/plot/commands/Condense.java @@ -33,6 +33,7 @@ import com.intellectualcrafters.plot.config.C; import com.intellectualcrafters.plot.object.Plot; import com.intellectualcrafters.plot.object.PlotId; import com.intellectualcrafters.plot.object.PlotPlayer; +import com.intellectualcrafters.plot.util.BlockManager; import com.intellectualcrafters.plot.util.MainUtil; import com.intellectualcrafters.plot.util.bukkit.BukkitUtil; @@ -54,7 +55,7 @@ public class Condense extends SubCommand { return false; } final String worldname = args[0]; - if (!BukkitUtil.isWorld(worldname) || !PlotSquared.isPlotWorld(worldname)) { + if (!BlockManager.manager.isWorld(worldname) || !PlotSquared.isPlotWorld(worldname)) { MainUtil.sendMessage(plr, "INVALID WORLD"); return false; } diff --git a/PlotSquared/src/main/java/com/intellectualcrafters/plot/commands/Debug.java b/PlotSquared/src/main/java/com/intellectualcrafters/plot/commands/Debug.java index fdf095049..d0b81aa3c 100644 --- a/PlotSquared/src/main/java/com/intellectualcrafters/plot/commands/Debug.java +++ b/PlotSquared/src/main/java/com/intellectualcrafters/plot/commands/Debug.java @@ -59,6 +59,9 @@ public class Debug extends SubCommand { for (final String world : PlotSquared.getPlotWorlds()) { worlds.append(world).append(" "); } + + // FIXME not sure if we actually need any of this debug info as we should just do a timings report which is more detailed anyway + information.append(header); information.append(getSection(section, "Lag / TPS")); information.append(getLine(line, "Ticks Per Second", Lag.getTPS())); diff --git a/PlotSquared/src/main/java/com/intellectualcrafters/plot/commands/DebugClaimTest.java b/PlotSquared/src/main/java/com/intellectualcrafters/plot/commands/DebugClaimTest.java index 6e566703e..ec1acc4d5 100644 --- a/PlotSquared/src/main/java/com/intellectualcrafters/plot/commands/DebugClaimTest.java +++ b/PlotSquared/src/main/java/com/intellectualcrafters/plot/commands/DebugClaimTest.java @@ -23,26 +23,23 @@ package com.intellectualcrafters.plot.commands; import java.util.ArrayList; import java.util.UUID; -import org.bukkit.Bukkit; -import org.bukkit.Chunk; -import org.bukkit.Location; -import org.bukkit.World; -import org.bukkit.block.Block; -import org.bukkit.block.Sign; -import org.bukkit.entity.Player; - import com.google.common.collect.BiMap; import com.intellectualcrafters.plot.PlotSquared; import com.intellectualcrafters.plot.config.C; import com.intellectualcrafters.plot.database.DBFunc; import com.intellectualcrafters.plot.events.PlayerClaimPlotEvent; +import com.intellectualcrafters.plot.object.ChunkLoc; +import com.intellectualcrafters.plot.object.Location; import com.intellectualcrafters.plot.object.Plot; import com.intellectualcrafters.plot.object.PlotId; import com.intellectualcrafters.plot.object.PlotManager; import com.intellectualcrafters.plot.object.PlotPlayer; import com.intellectualcrafters.plot.object.PlotWorld; import com.intellectualcrafters.plot.object.StringWrapper; +import com.intellectualcrafters.plot.util.AChunkManager; +import com.intellectualcrafters.plot.util.BlockManager; import com.intellectualcrafters.plot.util.MainUtil; +import com.intellectualcrafters.plot.util.bukkit.BukkitUtil; import com.intellectualcrafters.plot.util.bukkit.UUIDHandler; /** @@ -54,22 +51,24 @@ public class DebugClaimTest extends SubCommand { } @SuppressWarnings("unused") - public static boolean claimPlot(final Player player, final Plot plot, final boolean teleport) { + public static boolean claimPlot(final PlotPlayer player, final Plot plot, final boolean teleport) { return claimPlot(player, plot, teleport, ""); } - public static boolean claimPlot(final Player player, final Plot plot, final boolean teleport, @SuppressWarnings("unused") final String schematic) { - final PlayerClaimPlotEvent event = new PlayerClaimPlotEvent(player, plot, true); - Bukkit.getPluginManager().callEvent(event); - if (!event.isCancelled()) { - MainUtil.createPlot(player, plot); - MainUtil.setSign(player, plot); - MainUtil.sendMessage(BukkitUtil.getPlayer(player), C.CLAIMED); + public static boolean claimPlot(final PlotPlayer player, final Plot plot, final boolean teleport, @SuppressWarnings("unused") final String schematic) { + // FIXME call claim event + // boolean result = event result + boolean result = true; + + if (!result) { + MainUtil.createPlot(player.getUUID(), plot); + MainUtil.setSign(player.getName(), plot); + MainUtil.sendMessage(player, C.CLAIMED); if (teleport) { MainUtil.teleportPlayer(player, player.getLocation(), plot); } } - return event.isCancelled(); + return result; } @Override @@ -78,8 +77,8 @@ public class DebugClaimTest extends SubCommand { if (args.length < 3) { return !MainUtil.sendMessage(null, "If you accidentally delete your database, this command will attempt to restore all plots based on the data from the plot signs. \n\n&cMissing world arg /plot debugclaimtest {world} {PlotId min} {PlotId max}"); } - final World world = Bukkit.getWorld(args[0]); - if ((world == null) || !PlotSquared.isPlotWorld(world)) { + String world = args[0]; + if (!BlockManager.manager.isWorld(world) || !PlotSquared.isPlotWorld(world)) { return !MainUtil.sendMessage(null, "&cInvalid plot world!"); } PlotId min, max; @@ -103,42 +102,37 @@ public class DebugClaimTest extends SubCommand { MainUtil.sendMessage(null, " - &cDB Already contains: " + plot.id); continue; } - final Location loc = manager.getSignLoc(world, plotworld, plot); - final Chunk chunk = world.getChunkAt(loc); - if (!chunk.isLoaded()) { - final boolean result = chunk.load(false); - if (!result) { - continue; - } + final Location loc = manager.getSignLoc(plotworld, plot); + ChunkLoc chunk = new ChunkLoc(loc.getX() >> 4, loc.getZ() >> 4); + boolean result = AChunkManager.manager.loadChunk(world, chunk); + if (!result) { + continue; } - final Block block = world.getBlockAt(loc); - if (block != null) { - if (block.getState() instanceof Sign) { - final Sign sign = (Sign) block.getState(); - String line = sign.getLine(2); - if ((line != null) && (line.length() > 2)) { - line = line.substring(2); - final BiMap map = UUIDHandler.getUuidMap(); - UUID uuid = (map.get(new StringWrapper(line))); - if (uuid == null) { - for (final StringWrapper string : map.keySet()) { - if (string.value.toLowerCase().startsWith(line.toLowerCase())) { - uuid = map.get(string); - break; - } + String[] lines = BlockManager.manager.getSign(loc); + if (lines != null) { + String line = lines[2]; + if ((line != null) && (line.length() > 2)) { + line = line.substring(2); + final BiMap map = UUIDHandler.getUuidMap(); + UUID uuid = (map.get(new StringWrapper(line))); + if (uuid == null) { + for (final StringWrapper string : map.keySet()) { + if (string.value.toLowerCase().startsWith(line.toLowerCase())) { + uuid = map.get(string); + break; } } - if (uuid == null) { - uuid = UUIDHandler.getUUID(line); - } - if (uuid != null) { - MainUtil.sendMessage(null, " - &aFound plot: " + plot.id + " : " + line); - plot.owner = uuid; - plot.hasChanged = true; - plots.add(plot); - } else { - MainUtil.sendMessage(null, " - &cInvalid playername: " + plot.id + " : " + line); - } + } + if (uuid == null) { + uuid = UUIDHandler.getUUID(line); + } + if (uuid != null) { + MainUtil.sendMessage(null, " - &aFound plot: " + plot.id + " : " + line); + plot.owner = uuid; + plot.hasChanged = true; + plots.add(plot); + } else { + MainUtil.sendMessage(null, " - &cInvalid playername: " + plot.id + " : " + line); } } } diff --git a/PlotSquared/src/main/java/com/intellectualcrafters/plot/generator/HybridUtils.java b/PlotSquared/src/main/java/com/intellectualcrafters/plot/generator/HybridUtils.java index b26fb18dd..e206b7439 100644 --- a/PlotSquared/src/main/java/com/intellectualcrafters/plot/generator/HybridUtils.java +++ b/PlotSquared/src/main/java/com/intellectualcrafters/plot/generator/HybridUtils.java @@ -11,6 +11,7 @@ import com.intellectualcrafters.plot.object.Plot; import com.intellectualcrafters.plot.object.PlotBlock; import com.intellectualcrafters.plot.object.PlotId; import com.intellectualcrafters.plot.object.PlotManager; +import com.intellectualcrafters.plot.util.AChunkManager; import com.intellectualcrafters.plot.util.BlockManager; import com.intellectualcrafters.plot.util.MainUtil; import com.intellectualcrafters.plot.util.SchematicHandler; @@ -101,7 +102,7 @@ public abstract class HybridUtils { final PlotId id2 = manager.getPlotId(plotworld, ex, 0, ez); boolean toCheck = false; if ((id1 == null) || (id2 == null) || (id1 != id2)) { - final boolean result = BukkitUtil.loadChunk(world, chunk); + final boolean result = AChunkManager.manager.loadChunk(world, chunk); if (result) { if (id1 != null) { final Plot p1 = MainUtil.getPlot(world, id1); diff --git a/PlotSquared/src/main/java/com/intellectualcrafters/plot/util/AChunkManager.java b/PlotSquared/src/main/java/com/intellectualcrafters/plot/util/AChunkManager.java index 23e0b8dd2..04471e9a0 100644 --- a/PlotSquared/src/main/java/com/intellectualcrafters/plot/util/AChunkManager.java +++ b/PlotSquared/src/main/java/com/intellectualcrafters/plot/util/AChunkManager.java @@ -20,6 +20,8 @@ public abstract class AChunkManager { return new ChunkLoc(x, z); } + public abstract boolean loadChunk(String world, ChunkLoc loc); + public abstract List getChunkChunks(String world); public abstract void deleteRegionFile(final String world, final ChunkLoc loc); diff --git a/PlotSquared/src/main/java/com/intellectualcrafters/plot/util/BlockManager.java b/PlotSquared/src/main/java/com/intellectualcrafters/plot/util/BlockManager.java index 8263868c3..df962c79a 100644 --- a/PlotSquared/src/main/java/com/intellectualcrafters/plot/util/BlockManager.java +++ b/PlotSquared/src/main/java/com/intellectualcrafters/plot/util/BlockManager.java @@ -1,5 +1,6 @@ package com.intellectualcrafters.plot.util; +import com.intellectualcrafters.plot.object.Location; import com.intellectualcrafters.plot.object.PlotBlock; import com.intellectualcrafters.plot.util.bukkit.BukkitUtil; @@ -28,6 +29,10 @@ public abstract class BlockManager { return (int) r; } + public abstract String[] getSign(Location loc); + + public abstract boolean isWorld(String world); + public abstract void functionSetBlocks(String worldname, int[] x, int[] y, int[] z, int[] id, byte[] data); public abstract void functionSetSign(String worldname, int x, int y, int z, String[] lines); diff --git a/PlotSquared/src/main/java/com/intellectualcrafters/plot/util/bukkit/BukkitUtil.java b/PlotSquared/src/main/java/com/intellectualcrafters/plot/util/bukkit/BukkitUtil.java index 44067676e..8a028c753 100644 --- a/PlotSquared/src/main/java/com/intellectualcrafters/plot/util/bukkit/BukkitUtil.java +++ b/PlotSquared/src/main/java/com/intellectualcrafters/plot/util/bukkit/BukkitUtil.java @@ -38,7 +38,8 @@ public class BukkitUtil extends BlockManager { UUIDHandler.players.remove(plr); } - public static boolean isWorld(String world) { + @Override + public boolean isWorld(String world) { return getWorld(world) != null; } @@ -52,10 +53,6 @@ public class BukkitUtil extends BlockManager { return lastPlotPlayer; } - public static boolean loadChunk(String world, ChunkLoc loc) { - return getWorld(world).getChunkAt(loc.x << 4, loc.z << 4).load(false); - } - public static Biome getBiome(final Location loc) { return getWorld(loc.getWorld()).getBiome(loc.getX(), loc.getZ()); } @@ -202,4 +199,16 @@ public class BukkitUtil extends BlockManager { public void functionSetBlock(String worldname, int x, int y, int z, int id, byte data) { BukkitUtil.setBlock(getWorld(worldname), x, y, z, id, data); } + + @Override + public String[] getSign(Location loc) { + Block block = getWorld(loc.getWorld()).getBlockAt(loc.getX(), loc.getY(), loc.getZ()); + if (block != null) { + if (block.getState() instanceof Sign) { + final Sign sign = (Sign) block.getState(); + return sign.getLines(); + } + } + return null; + } } diff --git a/PlotSquared/src/main/java/com/intellectualcrafters/plot/util/bukkit/ChunkManager.java b/PlotSquared/src/main/java/com/intellectualcrafters/plot/util/bukkit/ChunkManager.java index 331df271d..5bfb6c591 100644 --- a/PlotSquared/src/main/java/com/intellectualcrafters/plot/util/bukkit/ChunkManager.java +++ b/PlotSquared/src/main/java/com/intellectualcrafters/plot/util/bukkit/ChunkManager.java @@ -755,4 +755,9 @@ public class ChunkManager extends AChunkManager { } } } + + @Override + public boolean loadChunk(String world, ChunkLoc loc) { + return BukkitUtil.getWorld(world).getChunkAt(loc.x << 4, loc.z << 4).load(false); + } }