diff --git a/PlotSquared/src/main/java/com/intellectualcrafters/plot/commands/Trim.java b/PlotSquared/src/main/java/com/intellectualcrafters/plot/commands/Trim.java index 75713e057..bce3fa5fa 100644 --- a/PlotSquared/src/main/java/com/intellectualcrafters/plot/commands/Trim.java +++ b/PlotSquared/src/main/java/com/intellectualcrafters/plot/commands/Trim.java @@ -28,15 +28,15 @@ import java.nio.file.attribute.BasicFileAttributes; import java.util.ArrayList; import java.util.HashSet; -import org.bukkit.Bukkit; - import com.intellectualcrafters.plot.PlotSquared; import com.intellectualcrafters.plot.config.C; 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.PlotPlayer; import com.intellectualcrafters.plot.util.AChunkManager; +import com.intellectualcrafters.plot.util.BlockManager; import com.intellectualcrafters.plot.util.MainUtil; import com.intellectualcrafters.plot.util.TaskManager; import com.intellectualcrafters.plot.util.bukkit.ChunkManager; @@ -87,8 +87,8 @@ public class Trim extends SubCommand { MainUtil.sendMessage(plr, C.TRIM_SYNTAX); return false; } - final World world = Bukkit.getWorld(args[1]); - if ((world == null) || (PlotSquared.getPlotWorld(world) == null)) { + final String world = args[1]; + if (!BlockManager.manager.isWorld(world) || (PlotSquared.getPlotWorld(world) == null)) { MainUtil.sendMessage(plr, C.NOT_VALID_WORLD); return false; } @@ -107,14 +107,14 @@ public class Trim extends SubCommand { return true; } - public static boolean getBulkRegions(final ArrayList empty, final World world, final Runnable whenDone) { + public static boolean getBulkRegions(final ArrayList empty, final String world, final Runnable whenDone) { if (Trim.TASK) { return false; } TaskManager.runTaskAsync(new Runnable() { @Override public void run() { - final String directory = world.getName() + File.separator + "region"; + final String directory = world + File.separator + "region"; final File folder = new File(directory); final File[] regionFiles = folder.listFiles(); for (final File file : regionFiles) { @@ -173,7 +173,7 @@ public class Trim extends SubCommand { sendMessage(" - MCA #: " + chunks.size()); sendMessage(" - CHUNKS: " + (chunks.size() * 1024) + " (max)"); sendMessage(" - TIME ESTIMATE: " + (chunks.size() / 1200) + " minutes"); - Trim.TASK_ID = Bukkit.getScheduler().scheduleSyncRepeatingTask(PlotSquared.getMain(), new Runnable() { + Trim.TASK_ID = TaskManager.runTaskRepeat(new Runnable() { @Override public void run() { final long start = System.currentTimeMillis(); @@ -183,62 +183,31 @@ public class Trim extends SubCommand { System.out.print("DONE!"); Trim.TASK = false; TaskManager.runTaskAsync(whenDone); - Bukkit.getScheduler().cancelTask(Trim.TASK_ID); + PlotSquared.TASK.cancelTask(Trim.TASK_ID); return; } final Plot plot = plots.get(0); plots.remove(0); final Location pos1 = MainUtil.getPlotBottomLoc(world, plot.id); final Location pos2 = MainUtil.getPlotTopLoc(world, plot.id); - final Location pos3 = new Location(world, pos1.getBlockX(), 64, pos2.getBlockZ()); - final Location pos4 = new Location(world, pos2.getBlockX(), 64, pos1.getBlockZ()); + final Location pos3 = new Location(world, pos1.getX(), 64, pos2.getZ()); + final Location pos4 = new Location(world, pos2.getX(), 64, pos1.getZ()); chunks.remove(ChunkManager.getChunkChunk(pos1)); chunks.remove(ChunkManager.getChunkChunk(pos2)); chunks.remove(ChunkManager.getChunkChunk(pos3)); chunks.remove(ChunkManager.getChunkChunk(pos4)); } } - }, 20L, 20L); + }, 20); Trim.TASK = true; return true; } public static ArrayList expired = null; - // public static void updateUnmodifiedPlots(final World world) { - // final SquarePlotManager manager = (SquarePlotManager) PlotSquared.getPlotManager(world); - // final SquarePlotWorld plotworld = (SquarePlotWorld) PlotSquared.getPlotWorld(world); - // final ArrayList expired = new ArrayList<>(); - // final Set plots = ExpireManager.getOldPlots(world.getName()).keySet(); - // sendMessage("Checking " + plots.size() +" plots! This may take a long time..."); - // Trim.TASK_ID = Bukkit.getScheduler().scheduleSyncRepeatingTask(PlotSquared.getMain(), new Runnable() { - // @Override - // public void run() { - // if (manager != null && plots.size() > 0) { - // Plot plot = plots.iterator().next(); - // if (plot.hasOwner()) { - // SquarePlotManager.checkModified(plot, 0); - // } - // if (plot.owner == null || !SquarePlotManager.checkModified(plot, plotworld.REQUIRED_CHANGES)) { - // expired.add(plot); - // sendMessage("found expired: " + plot); - // } - // } - // else { - // Trim.expired = expired; - // Trim.TASK = false; - // sendMessage("Done!"); - // Bukkit.getScheduler().cancelTask(Trim.TASK_ID); - // return; - // } - // } - // }, 1, 1); - // } - // - public static void deleteChunks(final World world, final ArrayList chunks) { - final String worldname = world.getName(); + public static void deleteChunks(final String world, final ArrayList chunks) { for (final ChunkLoc loc : chunks) { - ChunkManager.deleteRegionFile(worldname, loc); + AChunkManager.manager.deleteRegionFile(world, loc); } } diff --git a/PlotSquared/src/main/java/com/intellectualcrafters/plot/commands/Trusted.java b/PlotSquared/src/main/java/com/intellectualcrafters/plot/commands/Trusted.java index 1ae3155f5..4c4c2279f 100644 --- a/PlotSquared/src/main/java/com/intellectualcrafters/plot/commands/Trusted.java +++ b/PlotSquared/src/main/java/com/intellectualcrafters/plot/commands/Trusted.java @@ -31,6 +31,7 @@ import com.intellectualcrafters.plot.object.Location; import com.intellectualcrafters.plot.object.Plot; import com.intellectualcrafters.plot.object.PlotPlayer; import com.intellectualcrafters.plot.util.MainUtil; +import com.intellectualcrafters.plot.util.Permissions; import com.intellectualcrafters.plot.util.bukkit.UUIDHandler; @SuppressWarnings("deprecation") @@ -84,8 +85,7 @@ public class Trusted extends SubCommand { } plot.addTrusted(uuid); DBFunc.setTrusted(loc.getWorld(), plot, uuid); - final PlayerPlotTrustedEvent event = new PlayerPlotTrustedEvent(plr, plot, uuid, true); - Bukkit.getPluginManager().callEvent(event); + // FIXME PlayerPlotTrustedEvent } else { MainUtil.sendMessage(plr, C.ALREADY_ADDED); return false; @@ -107,8 +107,7 @@ public class Trusted extends SubCommand { final UUID uuid = UUIDHandler.getUUID(args[1]); plot.removeTrusted(uuid); DBFunc.removeTrusted(loc.getWorld(), plot, uuid); - final PlayerPlotTrustedEvent event = new PlayerPlotTrustedEvent(plr, plot, uuid, false); - Bukkit.getPluginManager().callEvent(event); + // FIXME PlayerPlotTrustedEvent MainUtil.sendMessage(plr, C.TRUSTED_REMOVED); } else { MainUtil.sendMessage(plr, C.TRUSTED_NEED_ARGUMENT); diff --git a/PlotSquared/src/main/java/com/intellectualcrafters/plot/commands/Unclaim.java b/PlotSquared/src/main/java/com/intellectualcrafters/plot/commands/Unclaim.java index 49865681d..e9b2a6826 100644 --- a/PlotSquared/src/main/java/com/intellectualcrafters/plot/commands/Unclaim.java +++ b/PlotSquared/src/main/java/com/intellectualcrafters/plot/commands/Unclaim.java @@ -29,7 +29,9 @@ import com.intellectualcrafters.plot.object.Location; import com.intellectualcrafters.plot.object.Plot; import com.intellectualcrafters.plot.object.PlotPlayer; import com.intellectualcrafters.plot.object.PlotWorld; +import com.intellectualcrafters.plot.util.EconHandler; import com.intellectualcrafters.plot.util.MainUtil; +import com.intellectualcrafters.plot.util.Permissions; import com.intellectualcrafters.plot.util.bukkit.BukkitPlayerFunctions; import com.intellectualcrafters.plot.util.bukkit.UUIDHandler; @@ -45,7 +47,7 @@ public class Unclaim extends SubCommand { if (plot == null) { return !sendMessage(plr, C.NOT_IN_PLOT); } - if (!MainUtil.getTopPlot(plr.getWorld(), plot).equals(BukkitPlayerFunctions.getBottomPlot(plr.getWorld(), plot))) { + if (!MainUtil.getTopPlot(plot).equals(MainUtil.getBottomPlot(plot))) { return !sendMessage(plr, C.UNLINK_REQUIRED); } if ((((plot == null) || !plot.hasOwner() || !plot.getOwner().equals(UUIDHandler.getUUID(plr)))) && !Permissions.hasPermission(plr, "plots.admin.command.unclaim")) { @@ -53,19 +55,18 @@ public class Unclaim extends SubCommand { } assert plot != null; final PlotWorld pWorld = PlotSquared.getPlotWorld(plot.world); - if (PlotSquared.useEconomy && pWorld.USE_ECONOMY) { + if (PlotSquared.economy != null && pWorld.USE_ECONOMY) { final double c = pWorld.SELL_PRICE; if (c > 0d) { final Economy economy = PlotSquared.economy; - economy.depositPlayer(plr, c); + EconHandler.depositPlayer(plr, c); sendMessage(plr, C.ADDED_BALANCE, c + ""); } } final boolean result = PlotSquared.removePlot(loc.getWorld(), plot.id, true); if (result) { - final World world = plr.getWorld(); - final String worldname = world.getName(); - PlotSquared.getPlotManager(world).unclaimPlot(world, pWorld, plot); + final String worldname = plr.getLocation().getWorld(); + PlotSquared.getPlotManager(worldname).unclaimPlot(pWorld, plot); DBFunc.delete(worldname, plot); // TODO set wall block } else { diff --git a/PlotSquared/src/main/java/com/intellectualcrafters/plot/commands/Unlink.java b/PlotSquared/src/main/java/com/intellectualcrafters/plot/commands/Unlink.java index 0e3113a97..9bccf27bb 100644 --- a/PlotSquared/src/main/java/com/intellectualcrafters/plot/commands/Unlink.java +++ b/PlotSquared/src/main/java/com/intellectualcrafters/plot/commands/Unlink.java @@ -35,6 +35,7 @@ import com.intellectualcrafters.plot.object.PlotManager; import com.intellectualcrafters.plot.object.PlotPlayer; import com.intellectualcrafters.plot.object.PlotWorld; import com.intellectualcrafters.plot.util.MainUtil; +import com.intellectualcrafters.plot.util.Permissions; import com.intellectualcrafters.plot.util.bukkit.BukkitPlayerFunctions; import com.intellectualcrafters.plot.util.bukkit.UUIDHandler; @@ -58,41 +59,28 @@ public class Unlink extends SubCommand { if (((plot == null) || !plot.hasOwner() || !plot.getOwner().equals(UUIDHandler.getUUID(plr))) && !Permissions.hasPermission(plr, "plots.admin.command.unlink")) { return sendMessage(plr, C.NO_PLOT_PERMS); } - if (MainUtil.getTopPlot(plr.getWorld(), plot).equals(BukkitPlayerFunctions.getBottomPlot(plr.getWorld(), plot))) { + if (MainUtil.getTopPlot(plot).equals(MainUtil.getBottomPlot(plot))) { return sendMessage(plr, C.UNLINK_IMPOSSIBLE); } - final World world = plr.getWorld(); - if (!unlinkPlot(world, plot)) { + final String world = plr.getLocation().getWorld(); + if (!unlinkPlot(plot)) { MainUtil.sendMessage(plr, "&cUnlink has been cancelled"); return false; } - try { - MainUtil.update(plr.getLocation()); - } catch (final Exception e) { - // execute(final PlotPlayer plr, final String... args) { - try { - PlotSquared.log("Error on: " + getClass().getMethod("execute", Player.class, String[].class).toGenericString() + ":119, when trying to use \"SetBlockFast#update\""); - } catch (final Exception ex) { - ex.printStackTrace(); - } - } + MainUtil.update(plr.getLocation()); MainUtil.sendMessage(plr, "&6Plots unlinked successfully!"); return true; } - public static boolean unlinkPlot(final World world, final Plot plot) { - final PlotId pos1 = BukkitPlayerFunctions.getBottomPlot(world, plot).id; - final PlotId pos2 = MainUtil.getTopPlot(world, plot).id; + public static boolean unlinkPlot(final Plot plot) { + String world = plot.world; + final PlotId pos1 = MainUtil.getBottomPlot(plot).id; + final PlotId pos2 = MainUtil.getTopPlot(plot).id; final ArrayList ids = MainUtil.getPlotSelectionIds(pos1, pos2); - final PlotUnlinkEvent event = new PlotUnlinkEvent(world, ids); - Bukkit.getServer().getPluginManager().callEvent(event); - if (event.isCancelled()) { - event.setCancelled(true); - return false; - } + // FIXME PlotUnlinkEvent (cancellable) final PlotManager manager = PlotSquared.getPlotManager(world); final PlotWorld plotworld = PlotSquared.getPlotWorld(world); - manager.startPlotUnlink(world, plotworld, ids); + manager.startPlotUnlink(plotworld, ids); for (final PlotId id : ids) { final Plot myplot = PlotSquared.getPlots(world).get(id); if (plot == null) { @@ -106,7 +94,7 @@ public class Unlink extends SubCommand { } myplot.deny_entry = plot.deny_entry; myplot.settings.setMerged(new boolean[] { false, false, false, false }); - DBFunc.setMerged(world.getName(), myplot, myplot.settings.getMerged()); + DBFunc.setMerged(world, myplot, myplot.settings.getMerged()); } for (int x = pos1.x; x <= pos2.x; x++) { for (int y = pos1.y; y <= pos2.y; y++) { @@ -122,16 +110,16 @@ public class Unlink extends SubCommand { if (ly) { manager.createRoadSouth(plotworld, p); } - MainUtil.setSign(world, UUIDHandler.getName(plot.owner), plot); + MainUtil.setSign(UUIDHandler.getName(plot.owner), plot); } } - manager.finishPlotUnlink(world, plotworld, ids); + manager.finishPlotUnlink(plotworld, ids); for (final PlotId id : ids) { final Plot myPlot = MainUtil.getPlot(world, id); if (plot.hasOwner()) { final String name = UUIDHandler.getName(myPlot.owner); if (name != null) { - MainUtil.setSign(world, name, myPlot); + MainUtil.setSign(name, myPlot); } } }