From 4df3535a438ff12375762cebb2fe2330d4eb40c7 Mon Sep 17 00:00:00 2001 From: Sauilitired Date: Sat, 8 Nov 2014 21:00:43 +0100 Subject: [PATCH] Allow for console plot clearing. --- .../jnbt/WorldEditUtils.java | 1 - .../intellectualcrafters/plot/PlotHelper.java | 13 +++---- .../com/intellectualcrafters/plot/PlotId.java | 21 ++++++++++++ .../intellectualcrafters/plot/PlotMain.java | 6 ++-- .../plot/commands/Clear.java | 34 ++++++++++++++++--- 5 files changed, 59 insertions(+), 16 deletions(-) diff --git a/PlotSquared/src/main/java/com/intellectualcrafters/jnbt/WorldEditUtils.java b/PlotSquared/src/main/java/com/intellectualcrafters/jnbt/WorldEditUtils.java index d27300ba0..29d646ee4 100644 --- a/PlotSquared/src/main/java/com/intellectualcrafters/jnbt/WorldEditUtils.java +++ b/PlotSquared/src/main/java/com/intellectualcrafters/jnbt/WorldEditUtils.java @@ -15,7 +15,6 @@ public class WorldEditUtils { // bukkitWorld.setBlock(vector, block); // } // catch (final WorldEditException e) { -// // TODO Auto-generated catch block // e.printStackTrace(); // } } diff --git a/PlotSquared/src/main/java/com/intellectualcrafters/plot/PlotHelper.java b/PlotSquared/src/main/java/com/intellectualcrafters/plot/PlotHelper.java index a6ee93cac..2b0ea2c5d 100644 --- a/PlotSquared/src/main/java/com/intellectualcrafters/plot/PlotHelper.java +++ b/PlotSquared/src/main/java/com/intellectualcrafters/plot/PlotHelper.java @@ -706,6 +706,12 @@ public class PlotHelper { * @param plot */ public static void clear(final Player requester, final Plot plot) { + if (requester == null) { + clearAllEntities(plot.getWorld(), plot, false); + clear(plot.getWorld(), plot); + removeSign(plot.getWorld(), plot); + return; + } if (runners.containsKey(plot)) { PlayerFunctions.sendMessage(requester, C.WAIT_FOR_TIMER); return; @@ -716,11 +722,7 @@ public class PlotHelper { final long start = System.nanoTime(); final World world; - if (requester != null) { - world = requester.getWorld(); - } else { - world = Bukkit.getWorld(plot.world); - } + world = requester.getWorld(); /* * keep @@ -730,7 +732,6 @@ public class PlotHelper { removeSign(world, plot); PlayerFunctions.sendMessage(requester, C.CLEARING_DONE.s().replaceAll("%time%", "" + ((System.nanoTime() - start) / 1000000.0))); - return; } public static void setCuboid(final World world, final Location pos1, final Location pos2, final PlotBlock[] blocks) { diff --git a/PlotSquared/src/main/java/com/intellectualcrafters/plot/PlotId.java b/PlotSquared/src/main/java/com/intellectualcrafters/plot/PlotId.java index d56a34a3b..807fd129d 100644 --- a/PlotSquared/src/main/java/com/intellectualcrafters/plot/PlotId.java +++ b/PlotSquared/src/main/java/com/intellectualcrafters/plot/PlotId.java @@ -22,6 +22,27 @@ package com.intellectualcrafters.plot; public class PlotId { + + /** + * Get a Plot Id based on a string + * + * @param string to create id from + * @return null if the string is invalid + */ + public static PlotId fromString(final String string) { + int x, y; + String[] parts = string.split(";"); + if (parts.length < 2) + return null; + try { + x = Integer.parseInt(parts[0]); + y = Integer.parseInt(parts[1]); + } catch (Exception e) { + return null; + } + return new PlotId(x, y); + } + /** * x value */ diff --git a/PlotSquared/src/main/java/com/intellectualcrafters/plot/PlotMain.java b/PlotSquared/src/main/java/com/intellectualcrafters/plot/PlotMain.java index 87ab390da..5969c2eae 100644 --- a/PlotSquared/src/main/java/com/intellectualcrafters/plot/PlotMain.java +++ b/PlotSquared/src/main/java/com/intellectualcrafters/plot/PlotMain.java @@ -763,13 +763,11 @@ public class PlotMain extends JavaPlugin { PlotHelper.canSetFast = false; } - // Setup version + downloads, will not be updated... maybe setup - // runnable? TODO Let jesse decide... com.intellectualcrafters.plot.commands.plugin.setup(this); setUUIDSaver(new PlotUUIDSaver()); + // Looks really cool xD getUUIDSaver().globalPopulate(); - // UUIDHandler.startFetch(this); } /** @@ -1154,7 +1152,7 @@ public class PlotMain extends JavaPlugin { for (final ConfigurationNode setting : plotworld.getSettingNodes()) { options.put(setting.getConstant(), setting.getValue()); - //TODO: Make jesse expalain wth was going on here + //TODO: Make jesse explain wth was going on here } for (final Entry node : options.entrySet()) { diff --git a/PlotSquared/src/main/java/com/intellectualcrafters/plot/commands/Clear.java b/PlotSquared/src/main/java/com/intellectualcrafters/plot/commands/Clear.java index 5455be724..4a76a37a3 100644 --- a/PlotSquared/src/main/java/com/intellectualcrafters/plot/commands/Clear.java +++ b/PlotSquared/src/main/java/com/intellectualcrafters/plot/commands/Clear.java @@ -21,16 +21,14 @@ package com.intellectualcrafters.plot.commands; -import com.intellectualcrafters.plot.C; -import com.intellectualcrafters.plot.PlayerFunctions; -import com.intellectualcrafters.plot.Plot; -import com.intellectualcrafters.plot.PlotMain; +import com.intellectualcrafters.plot.*; +import org.bukkit.Bukkit; import org.bukkit.entity.Player; public class Clear extends SubCommand { public Clear() { - super(Command.CLEAR, "Clear a plot", "clear", CommandCategory.ACTIONS, true); + super(Command.CLEAR, "Clear a plot", "clear", CommandCategory.ACTIONS, false); // TODO console clear plot at location @@ -38,6 +36,32 @@ public class Clear extends SubCommand { @Override public boolean execute(final Player plr, final String... args) { + if (plr == null) { + // Is console + if (args.length < 2) { + PlotMain.sendConsoleSenderMessage("You need to specify two arguments: ID (0;0) & World (world)"); + } else { + PlotId id = PlotId.fromString(args[0]); + String world = args[1]; + if (id == null) { + PlotMain.sendConsoleSenderMessage("Invalid Plot ID: " + args[0]); + } else { + if (!PlotMain.isPlotWorld(world)) { + PlotMain.sendConsoleSenderMessage("Invalid plot world: " + world); + } else { + Plot plot = PlotHelper.getPlot(Bukkit.getWorld(world), id); + if (plot == null) { + PlotMain.sendConsoleSenderMessage("Could not find plot " + args[0] + " in world " + world); + } else { + plot.clear(null); + PlotMain.sendConsoleSenderMessage("Plot " + plot.getId().toString() + " cleared."); + } + } + } + } + return true; + } + if (!PlayerFunctions.isInPlot(plr)) { return sendMessage(plr, C.NOT_IN_PLOT); }