From 0010b06afa513185df1c33b9d1d62d778d0d9c57 Mon Sep 17 00:00:00 2001 From: Jesse Boyd Date: Sat, 18 Oct 2014 11:06:29 -0700 Subject: [PATCH] Added support for console messages (untested) --- .../src/com/intellectualcrafters/plot/C.java | 11 +++++ .../intellectualcrafters/plot/PlotMain.java | 4 ++ .../plot/commands/Auto.java | 2 +- .../plot/commands/Camera.java | 2 +- .../plot/commands/Claim.java | 2 +- .../plot/commands/Clear.java | 5 +- .../plot/commands/Clipboard.java | 2 +- .../plot/commands/Command.java | 4 ++ .../plot/commands/CommandPermission.java | 4 +- .../plot/commands/Copy.java | 2 +- .../plot/commands/Debug.java | 16 +++---- .../plot/commands/Delete.java | 2 +- .../plot/commands/Denied.java | 2 +- .../plot/commands/Help.java | 2 +- .../plot/commands/Helpers.java | 2 +- .../plot/commands/Home.java | 2 +- .../plot/commands/Info.java | 42 +++++++++++++--- .../plot/commands/Inventory.java | 2 +- .../plot/commands/Kick.java | 2 +- .../plot/commands/MainCommand.java | 28 +++++------ .../plot/commands/Merge.java | 2 +- .../plot/commands/Paste.java | 2 +- .../plot/commands/Purge.java | 48 +++++++++++++++++++ .../plot/commands/Rate.java | 2 +- .../plot/commands/Reload.java | 12 ++--- .../plot/commands/Schematic.java | 4 +- .../plot/commands/Set.java | 2 +- .../plot/commands/SetOwner.java | 2 +- .../plot/commands/Setup.java | 25 ++++++---- .../plot/commands/SubCommand.java | 9 ++-- .../plot/commands/TP.java | 2 +- .../plot/commands/Trusted.java | 2 +- .../plot/commands/Unlink.java | 2 +- .../plot/commands/Visit.java | 2 +- .../plot/commands/list.java | 15 ++++-- .../plot/commands/plugin.java | 2 +- .../plot/database/DBFunc.java | 4 ++ 37 files changed, 197 insertions(+), 78 deletions(-) create mode 100644 PlotSquared/src/com/intellectualcrafters/plot/commands/Purge.java diff --git a/PlotSquared/src/com/intellectualcrafters/plot/C.java b/PlotSquared/src/com/intellectualcrafters/plot/C.java index a2117617f..14a7f1075 100644 --- a/PlotSquared/src/com/intellectualcrafters/plot/C.java +++ b/PlotSquared/src/com/intellectualcrafters/plot/C.java @@ -16,6 +16,11 @@ import org.bukkit.ChatColor; * @author Citymonstret */ public enum C { + /* + * Console + */ + NOT_CONSOLE("&cFor safety reasons, this command can only be executed by console."), + IS_CONSOLE("&cThis command can only be executed by a player."), /* Clipboard */ @@ -128,6 +133,11 @@ public enum C { * */ COMMAND_WENT_WRONG("&cSomething went wrong when executing that command..."), + /* + * purge + */ + PURGE_SYNTAX("&c/plots purge {world}"), + PURGE_SUCCESS("All plots for the specified world have now been purged."), /* * No {plot} */ @@ -190,6 +200,7 @@ public enum C { PLOT_INFO_UNCLAIMED("&cPlot &6%s&c is not yet claimed"), PLOT_INFO("ID: &6%id%&c, Alias: &6%alias%&c, Owner: &6%owner%&c, Biome: &6%biome%&c, Time: &6%time%&c, Weather: &6%weather%&c, Helpers:&6%helpers%&c, Trusted:&6%trusted%&c, Denied:&6%denied%&c, Rating: &6%rating%&c, Flags: &6%flags%"), PLOT_USER_LIST(" &6%user%&c,"), + INFO_SYNTAX_CONSOLE("/plot info {world} X;Y"), /* * Generating */ diff --git a/PlotSquared/src/com/intellectualcrafters/plot/PlotMain.java b/PlotSquared/src/com/intellectualcrafters/plot/PlotMain.java index ff9d4e102..3c84dc468 100644 --- a/PlotSquared/src/com/intellectualcrafters/plot/PlotMain.java +++ b/PlotSquared/src/com/intellectualcrafters/plot/PlotMain.java @@ -156,6 +156,10 @@ public class PlotMain extends JavaPlugin { * @return */ public static boolean hasPermissions(Player player, String[] perms) { + // Assumes null player is console. + if (player==null) { + return true; + } if (player.isOp()) { return true; } diff --git a/PlotSquared/src/com/intellectualcrafters/plot/commands/Auto.java b/PlotSquared/src/com/intellectualcrafters/plot/commands/Auto.java index 5368d5bae..a22f926f8 100644 --- a/PlotSquared/src/com/intellectualcrafters/plot/commands/Auto.java +++ b/PlotSquared/src/com/intellectualcrafters/plot/commands/Auto.java @@ -24,7 +24,7 @@ import com.intellectualcrafters.plot.PlotWorld; @SuppressWarnings("deprecation") public class Auto extends SubCommand { public Auto() { - super("auto", "plots.auto", "Claim the nearest plot", "auto", "a", CommandCategory.CLAIMING); + super("auto", "plots.auto", "Claim the nearest plot", "auto", "a", CommandCategory.CLAIMING, true); } // TODO auto claim a mega plot!!!!!!!!!!!! diff --git a/PlotSquared/src/com/intellectualcrafters/plot/commands/Camera.java b/PlotSquared/src/com/intellectualcrafters/plot/commands/Camera.java index c3b4e79dd..bc97008c2 100644 --- a/PlotSquared/src/com/intellectualcrafters/plot/commands/Camera.java +++ b/PlotSquared/src/com/intellectualcrafters/plot/commands/Camera.java @@ -26,7 +26,7 @@ public class Camera extends SubCommand implements Listener { private CameraAPI api; public Camera() { - super("camera", "plots.camera", "Go into camera mode", "camera", "c", CommandCategory.TELEPORT); + super("camera", "plots.camera", "Go into camera mode", "camera", "c", CommandCategory.TELEPORT, true); this.api = CameraAPI.getInstance(); this.travelers = new ArrayList(); } diff --git a/PlotSquared/src/com/intellectualcrafters/plot/commands/Claim.java b/PlotSquared/src/com/intellectualcrafters/plot/commands/Claim.java index 772bb272a..99147738f 100644 --- a/PlotSquared/src/com/intellectualcrafters/plot/commands/Claim.java +++ b/PlotSquared/src/com/intellectualcrafters/plot/commands/Claim.java @@ -29,7 +29,7 @@ import com.intellectualcrafters.plot.events.PlayerClaimPlotEvent; public class Claim extends SubCommand { public Claim() { - super(Command.CLAIM, "Claim the current plot you're standing on.", "claim", CommandCategory.CLAIMING); + super(Command.CLAIM, "Claim the current plot you're standing on.", "claim", CommandCategory.CLAIMING, true); } @Override diff --git a/PlotSquared/src/com/intellectualcrafters/plot/commands/Clear.java b/PlotSquared/src/com/intellectualcrafters/plot/commands/Clear.java index ec4d00e16..9295bdb34 100644 --- a/PlotSquared/src/com/intellectualcrafters/plot/commands/Clear.java +++ b/PlotSquared/src/com/intellectualcrafters/plot/commands/Clear.java @@ -20,7 +20,10 @@ import com.intellectualcrafters.plot.Plot; public class Clear extends SubCommand { public Clear() { - super(Command.CLEAR, "Clear a plot", "clear", CommandCategory.ACTIONS); + super(Command.CLEAR, "Clear a plot", "clear", CommandCategory.ACTIONS, true); + + // TODO console clear plot at location + } @Override diff --git a/PlotSquared/src/com/intellectualcrafters/plot/commands/Clipboard.java b/PlotSquared/src/com/intellectualcrafters/plot/commands/Clipboard.java index fbe053a3f..1ff68a6c1 100644 --- a/PlotSquared/src/com/intellectualcrafters/plot/commands/Clipboard.java +++ b/PlotSquared/src/com/intellectualcrafters/plot/commands/Clipboard.java @@ -13,7 +13,7 @@ import static com.intellectualcrafters.plot.PlotSelection.currentSelection; public class Clipboard extends SubCommand { public Clipboard() { - super(Command.CLIPBOARD, "View information about your current copy", "clipboard", CommandCategory.INFO); + super(Command.CLIPBOARD, "View information about your current copy", "clipboard", CommandCategory.INFO, true); } @Override diff --git a/PlotSquared/src/com/intellectualcrafters/plot/commands/Command.java b/PlotSquared/src/com/intellectualcrafters/plot/commands/Command.java index addbc67e4..5f5f1a0ce 100644 --- a/PlotSquared/src/com/intellectualcrafters/plot/commands/Command.java +++ b/PlotSquared/src/com/intellectualcrafters/plot/commands/Command.java @@ -83,6 +83,10 @@ public enum Command { * */ SET("set", "s"), + /** + * + */ + PURGE("purge"), /** * */ diff --git a/PlotSquared/src/com/intellectualcrafters/plot/commands/CommandPermission.java b/PlotSquared/src/com/intellectualcrafters/plot/commands/CommandPermission.java index d5427bec9..78714f228 100644 --- a/PlotSquared/src/com/intellectualcrafters/plot/commands/CommandPermission.java +++ b/PlotSquared/src/com/intellectualcrafters/plot/commands/CommandPermission.java @@ -11,6 +11,8 @@ package com.intellectualcrafters.plot.commands; import org.bukkit.entity.Player; +import com.intellectualcrafters.plot.PlotMain; + /** * Created by Citymonstret on 2014-08-03. * @@ -35,6 +37,6 @@ public class CommandPermission { * @return */ public boolean hasPermission(Player player) { - return player.hasPermission(this.permission) || player.hasPermission("plots.admin"); + return PlotMain.hasPermission(player, this.permission) || PlotMain.hasPermission(player, "plots.admin"); } } diff --git a/PlotSquared/src/com/intellectualcrafters/plot/commands/Copy.java b/PlotSquared/src/com/intellectualcrafters/plot/commands/Copy.java index 233f4c9df..269840725 100644 --- a/PlotSquared/src/com/intellectualcrafters/plot/commands/Copy.java +++ b/PlotSquared/src/com/intellectualcrafters/plot/commands/Copy.java @@ -18,7 +18,7 @@ import org.bukkit.entity.Player; public class Copy extends SubCommand { public Copy() { - super(Command.COPY, "Copy a plot", "clear", CommandCategory.ACTIONS); + super(Command.COPY, "Copy a plot", "clear", CommandCategory.ACTIONS, true); } @Override diff --git a/PlotSquared/src/com/intellectualcrafters/plot/commands/Debug.java b/PlotSquared/src/com/intellectualcrafters/plot/commands/Debug.java index 9cf52c2d3..c700ca974 100644 --- a/PlotSquared/src/com/intellectualcrafters/plot/commands/Debug.java +++ b/PlotSquared/src/com/intellectualcrafters/plot/commands/Debug.java @@ -9,6 +9,7 @@ package com.intellectualcrafters.plot.commands; import org.bukkit.Bukkit; +import org.bukkit.World; import org.bukkit.entity.Player; import com.intellectualcrafters.plot.C; @@ -33,7 +34,7 @@ public class Debug extends SubCommand { // private extends SubCommand^Implements {Command, Information} from // >>\\S.txt6\\ public Debug() { - super(Command.DEBUG, "Show debug information", "debug [msg]", CommandCategory.INFO); + super(Command.DEBUG, "Show debug information", "debug [msg]", CommandCategory.INFO, false); { /** * This. @@ -43,7 +44,6 @@ public class Debug extends SubCommand { @Override public boolean execute(Player plr, String... args) { - PlotMain.getWorldSettings(plr.getWorld()); if ((args.length > 0) && args[0].equalsIgnoreCase("msg")) { StringBuilder msg = new StringBuilder(); for (C c : C.values()) { @@ -87,12 +87,13 @@ public class Debug extends SubCommand { information.append(getLine(line, "Owned Plots", PlotMain.getPlots().size())); // information.append(getLine(line, "PlotWorld Size", // PlotHelper.getWorldFolderSize() + "MB")); - for (String world : PlotMain.getPlotWorlds()) { - information.append(getLine(line, "World: " + world + " size", PlotHelper.getWorldFolderSize(Bukkit.getWorld(world)))); + for (String worldname : PlotMain.getPlotWorlds()) { + World world = Bukkit.getWorld(worldname); + information.append(getLine(line, "World: " + world + " size", PlotHelper.getWorldFolderSize(world))); + information.append(getLine(line, " - Entities", PlotHelper.getEntities(world))); + information.append(getLine(line, " - Loaded Tile Entities", PlotHelper.getTileEntities(world))); + information.append(getLine(line, " - Loaded Chunks", PlotHelper.getLoadedChunks(world))); } - information.append(getLine(line, "Entities", PlotHelper.getEntities(plr.getWorld()))); - information.append(getLine(line, "Loaded Tile Entities", PlotHelper.getTileEntities(plr.getWorld()))); - information.append(getLine(line, "Loaded Chunks", PlotHelper.getLoadedChunks(plr.getWorld()))); information.append(getSection(section, "RAM")); information.append(getLine(line, "Free Ram", RUtils.getFreeRam() + "MB")); information.append(getLine(line, "Total Ram", RUtils.getTotalRam() + "MB")); @@ -117,5 +118,4 @@ public class Debug extends SubCommand { private String getLine(String line, String var, Object val) { return line.replaceAll("%var%", var).replaceAll("%val%", "" + val) + "\n"; } - } diff --git a/PlotSquared/src/com/intellectualcrafters/plot/commands/Delete.java b/PlotSquared/src/com/intellectualcrafters/plot/commands/Delete.java index dfb07a3d5..d0d3bd0d8 100644 --- a/PlotSquared/src/com/intellectualcrafters/plot/commands/Delete.java +++ b/PlotSquared/src/com/intellectualcrafters/plot/commands/Delete.java @@ -26,7 +26,7 @@ import com.intellectualcrafters.plot.database.DBFunc; public class Delete extends SubCommand { public Delete() { - super(Command.DELETE, "Delete a plot", "delete", CommandCategory.ACTIONS); + super(Command.DELETE, "Delete a plot", "delete", CommandCategory.ACTIONS, true); } @Override diff --git a/PlotSquared/src/com/intellectualcrafters/plot/commands/Denied.java b/PlotSquared/src/com/intellectualcrafters/plot/commands/Denied.java index 42afa0dfd..d51c72109 100644 --- a/PlotSquared/src/com/intellectualcrafters/plot/commands/Denied.java +++ b/PlotSquared/src/com/intellectualcrafters/plot/commands/Denied.java @@ -27,7 +27,7 @@ import com.intellectualcrafters.plot.events.PlayerPlotDeniedEvent; public class Denied extends SubCommand { public Denied() { - super(Command.DENIED, "Manage plot helpers", "denied {add|remove} {player}", CommandCategory.ACTIONS); + super(Command.DENIED, "Manage plot helpers", "denied {add|remove} {player}", CommandCategory.ACTIONS, true); } @Override diff --git a/PlotSquared/src/com/intellectualcrafters/plot/commands/Help.java b/PlotSquared/src/com/intellectualcrafters/plot/commands/Help.java index 8ddf03b30..1ef66a699 100644 --- a/PlotSquared/src/com/intellectualcrafters/plot/commands/Help.java +++ b/PlotSquared/src/com/intellectualcrafters/plot/commands/Help.java @@ -15,7 +15,7 @@ import org.bukkit.entity.Player; */ public class Help extends SubCommand { public Help() { - super("help", "", "Get this help menu", "help", "he", SubCommand.CommandCategory.INFO); + super("help", "", "Get this help menu", "help", "he", SubCommand.CommandCategory.INFO, false); } @Override diff --git a/PlotSquared/src/com/intellectualcrafters/plot/commands/Helpers.java b/PlotSquared/src/com/intellectualcrafters/plot/commands/Helpers.java index 80089522d..49a0d263a 100644 --- a/PlotSquared/src/com/intellectualcrafters/plot/commands/Helpers.java +++ b/PlotSquared/src/com/intellectualcrafters/plot/commands/Helpers.java @@ -24,7 +24,7 @@ import com.intellectualcrafters.plot.events.PlayerPlotHelperEvent; public class Helpers extends SubCommand { public Helpers() { - super(Command.HELPERS, "Manage plot helpers", "helpers {add|remove} {player}", CommandCategory.ACTIONS); + super(Command.HELPERS, "Manage plot helpers", "helpers {add|remove} {player}", CommandCategory.ACTIONS, true); } @Override diff --git a/PlotSquared/src/com/intellectualcrafters/plot/commands/Home.java b/PlotSquared/src/com/intellectualcrafters/plot/commands/Home.java index 326909614..fb6ec7bcc 100644 --- a/PlotSquared/src/com/intellectualcrafters/plot/commands/Home.java +++ b/PlotSquared/src/com/intellectualcrafters/plot/commands/Home.java @@ -21,7 +21,7 @@ import com.intellectualcrafters.plot.PlotMain; public class Home extends SubCommand { public Home() { - super(Command.HOME, "Go to your plot", "home {id|alias}", CommandCategory.TELEPORT); + super(Command.HOME, "Go to your plot", "home {id|alias}", CommandCategory.TELEPORT, true); } private Plot isAlias(String a) { diff --git a/PlotSquared/src/com/intellectualcrafters/plot/commands/Info.java b/PlotSquared/src/com/intellectualcrafters/plot/commands/Info.java index fbc8a01f4..66295dd02 100644 --- a/PlotSquared/src/com/intellectualcrafters/plot/commands/Info.java +++ b/PlotSquared/src/com/intellectualcrafters/plot/commands/Info.java @@ -22,6 +22,9 @@ import com.intellectualcrafters.plot.C; import com.intellectualcrafters.plot.PlayerFunctions; import com.intellectualcrafters.plot.Plot; import com.intellectualcrafters.plot.PlotHelper; +import com.intellectualcrafters.plot.PlotId; +import com.intellectualcrafters.plot.PlotMain; +import com.intellectualcrafters.plot.PlotWorld; import com.intellectualcrafters.plot.UUIDHandler; import com.intellectualcrafters.plot.database.DBFunc; @@ -31,18 +34,43 @@ import com.intellectualcrafters.plot.database.DBFunc; public class Info extends SubCommand { public Info() { - super(Command.INFO, "Display plot info", "info", CommandCategory.INFO); + super(Command.INFO, "Display plot info", "info", CommandCategory.INFO, false); } @Override public boolean execute(Player player, String... args) { - if (!PlayerFunctions.isInPlot(player)) { - PlayerFunctions.sendMessage(player, C.NOT_IN_PLOT); - return true; + + Plot plot; + if (player!=null) { + if (!PlayerFunctions.isInPlot(player)) { + PlayerFunctions.sendMessage(player, C.NOT_IN_PLOT); + return false; + } + plot = PlayerFunctions.getCurrentPlot(player); + } + else { + if (args.length!=2) { + PlayerFunctions.sendMessage(player, C.INFO_SYNTAX_CONSOLE); + return false; + } + PlotWorld plotworld = PlotMain.getWorldSettings(args[0]); + if (plotworld==null) { + PlayerFunctions.sendMessage(player, C.NOT_VALID_WORLD); + return false; + } + try { + String[] split = args[1].split(";"); + PlotId id = new PlotId(Integer.parseInt(split[0]), Integer.parseInt(split[1])); + plot = PlotHelper.getPlot(Bukkit.getWorld(plotworld.worldname), id); + if (plot==null) { + PlayerFunctions.sendMessage(player, C.NOT_VALID_PLOT_ID); + } + } + catch (Exception e) { + PlayerFunctions.sendMessage(player, C.INFO_SYNTAX_CONSOLE); + return false; + } } - - // || - Plot plot = PlayerFunctions.getCurrentPlot(player); boolean hasOwner = plot.hasOwner(); boolean containsEveryone; diff --git a/PlotSquared/src/com/intellectualcrafters/plot/commands/Inventory.java b/PlotSquared/src/com/intellectualcrafters/plot/commands/Inventory.java index 358c21478..2629d15cd 100644 --- a/PlotSquared/src/com/intellectualcrafters/plot/commands/Inventory.java +++ b/PlotSquared/src/com/intellectualcrafters/plot/commands/Inventory.java @@ -20,7 +20,7 @@ import org.bukkit.inventory.meta.ItemMeta; public class Inventory extends SubCommand { public Inventory() { - super("inventory", "plots.inventory", "Open a command inventory", "inventory", "inv", CommandCategory.INFO); + super("inventory", "plots.inventory", "Open a command inventory", "inventory", "inv", CommandCategory.INFO, true); } @Override diff --git a/PlotSquared/src/com/intellectualcrafters/plot/commands/Kick.java b/PlotSquared/src/com/intellectualcrafters/plot/commands/Kick.java index 7e9185d0f..f5d323172 100644 --- a/PlotSquared/src/com/intellectualcrafters/plot/commands/Kick.java +++ b/PlotSquared/src/com/intellectualcrafters/plot/commands/Kick.java @@ -21,7 +21,7 @@ import com.intellectualcrafters.plot.Plot; public class Kick extends SubCommand { public Kick() { - super(Command.KICK, "Kick a player from your plot", "kick", CommandCategory.ACTIONS); + super(Command.KICK, "Kick a player from your plot", "kick", CommandCategory.ACTIONS, true); } @Override diff --git a/PlotSquared/src/com/intellectualcrafters/plot/commands/MainCommand.java b/PlotSquared/src/com/intellectualcrafters/plot/commands/MainCommand.java index 58f96ef6b..e6492170d 100644 --- a/PlotSquared/src/com/intellectualcrafters/plot/commands/MainCommand.java +++ b/PlotSquared/src/com/intellectualcrafters/plot/commands/MainCommand.java @@ -45,20 +45,14 @@ public class MainCommand implements CommandExecutor { @Override public boolean onCommand(CommandSender sender, Command cmd, String commandLabel, String[] args) { - if (!(sender instanceof Player)) { - if (args.length > 0) { - if (args[0].equalsIgnoreCase("reload")) { - new Reload().executeConsole(args); - } - } - else { - PlotMain.sendConsoleSenderMessage(C.PREFIX.s() + C.HELP_HEADER.s()); - PlotMain.sendConsoleSenderMessage("&6/plots reload &c-&6 reloads the plugin"); - } - return false; + Player player; + if (sender instanceof Player) { + player = (Player) sender; } - Player player = (Player) sender; - if (!player.hasPermission("plots.use")) { + else { + player = null; + } + if (PlotMain.hasPermission(player, "plots.use")) { return no_permission(player); } if ((args.length < 1) @@ -106,7 +100,13 @@ public class MainCommand implements CommandExecutor { arguments[x - 1] = args[x]; } if (command.permission.hasPermission(player)) { - return command.execute(player, arguments); + if (player!=null || !command.isPlayer ) { + return command.execute(player, arguments); + } + else { + PlayerFunctions.sendMessage(player, C.IS_CONSOLE); + return false; + } } else { return no_permission(player); diff --git a/PlotSquared/src/com/intellectualcrafters/plot/commands/Merge.java b/PlotSquared/src/com/intellectualcrafters/plot/commands/Merge.java index 74571696e..499470384 100644 --- a/PlotSquared/src/com/intellectualcrafters/plot/commands/Merge.java +++ b/PlotSquared/src/com/intellectualcrafters/plot/commands/Merge.java @@ -36,7 +36,7 @@ public class Merge extends SubCommand { public static String[] aliases = new String[] { "n", "e", "s", "w" }; public Merge() { - super(Command.MERGE, "Merge the plot you are standing on with another plot.", "merge", CommandCategory.ACTIONS); + super(Command.MERGE, "Merge the plot you are standing on with another plot.", "merge", CommandCategory.ACTIONS, true); } public static String direction(float yaw) { diff --git a/PlotSquared/src/com/intellectualcrafters/plot/commands/Paste.java b/PlotSquared/src/com/intellectualcrafters/plot/commands/Paste.java index d7a7d8db6..9ca2f64df 100644 --- a/PlotSquared/src/com/intellectualcrafters/plot/commands/Paste.java +++ b/PlotSquared/src/com/intellectualcrafters/plot/commands/Paste.java @@ -10,7 +10,7 @@ import org.bukkit.entity.Player; public class Paste extends SubCommand { public Paste() { - super(Command.PASTE, "Paste a plot", "paste", CommandCategory.ACTIONS); + super(Command.PASTE, "Paste a plot", "paste", CommandCategory.ACTIONS, true); } @Override diff --git a/PlotSquared/src/com/intellectualcrafters/plot/commands/Purge.java b/PlotSquared/src/com/intellectualcrafters/plot/commands/Purge.java new file mode 100644 index 000000000..37fcbbd1b --- /dev/null +++ b/PlotSquared/src/com/intellectualcrafters/plot/commands/Purge.java @@ -0,0 +1,48 @@ +/* + * Copyright (c) IntellectualCrafters - 2014. You are not allowed to distribute + * and/or monetize any of our intellectual property. IntellectualCrafters is not + * affiliated with Mojang AB. Minecraft is a trademark of Mojang AB. + * + * >> File = Purge.java >> Generated by: Citymonstret at 2014-08-09 01:42 + */ + +package com.intellectualcrafters.plot.commands; + +import org.bukkit.entity.Player; + +import com.intellectualcrafters.plot.C; +import com.intellectualcrafters.plot.PlayerFunctions; +import com.intellectualcrafters.plot.PlotMain; +import com.intellectualcrafters.plot.PlotWorld; +import com.intellectualcrafters.plot.database.DBFunc; + +/** + * @Deprecated + */ +public class Purge extends SubCommand { + + public Purge() { + super("purge", "plots.admin", "Purge all plots for a world", "", "purge", CommandCategory.ACTIONS, false); + } + + @Override + public boolean execute(Player plr, String... args) { + if (args.length!=1) { + PlayerFunctions.sendMessage(plr, C.PURGE_SYNTAX); + return false; + } + PlotWorld plotworld = PlotMain.getWorldSettings(args[0]); + if (plotworld == null) { + PlayerFunctions.sendMessage(plr, C.NOT_VALID_PLOT_WORLD); + return false; + } + if (plr!=null) { + PlayerFunctions.sendMessage(plr, (C.NOT_CONSOLE)); + return false; + } + DBFunc.purge(args[0]); + PlayerFunctions.sendMessage(plr, (C.PURGE_SUCCESS)); + return true; + } + +} diff --git a/PlotSquared/src/com/intellectualcrafters/plot/commands/Rate.java b/PlotSquared/src/com/intellectualcrafters/plot/commands/Rate.java index 4d30ef690..9789b6ec0 100644 --- a/PlotSquared/src/com/intellectualcrafters/plot/commands/Rate.java +++ b/PlotSquared/src/com/intellectualcrafters/plot/commands/Rate.java @@ -17,7 +17,7 @@ public class Rate extends SubCommand { */ public Rate() { - super("rate", "plots.rate", "Rate the plot", "rate {0-10}", "rt", CommandCategory.ACTIONS); + super("rate", "plots.rate", "Rate the plot", "rate {0-10}", "rt", CommandCategory.ACTIONS, true); } @Override diff --git a/PlotSquared/src/com/intellectualcrafters/plot/commands/Reload.java b/PlotSquared/src/com/intellectualcrafters/plot/commands/Reload.java index 2a547e2f8..1d5cef8bd 100644 --- a/PlotSquared/src/com/intellectualcrafters/plot/commands/Reload.java +++ b/PlotSquared/src/com/intellectualcrafters/plot/commands/Reload.java @@ -20,7 +20,10 @@ import com.intellectualcrafters.plot.PlotMain; public class Reload extends SubCommand { public Reload() { - super("reload", "plots.admin", "Reload configurations", "", "reload", CommandCategory.INFO); + super("reload", "plots.admin", "Reload configurations", "", "reload", CommandCategory.INFO, false); + + // TODO reload worlds as well + } @Override @@ -30,12 +33,7 @@ public class Reload extends SubCommand { PlotMain.BroadcastWithPerms(C.RELOADED_CONFIGS); } catch (Exception e) { - if (plr != null) { - PlayerFunctions.sendMessage(plr, C.RELOAD_FAILED); - } - else { - PlotMain.sendConsoleSenderMessage(C.RELOAD_FAILED); - } + PlayerFunctions.sendMessage(plr, C.RELOAD_FAILED); } return true; } diff --git a/PlotSquared/src/com/intellectualcrafters/plot/commands/Schematic.java b/PlotSquared/src/com/intellectualcrafters/plot/commands/Schematic.java index 2f152d1e7..f5b64e951 100644 --- a/PlotSquared/src/com/intellectualcrafters/plot/commands/Schematic.java +++ b/PlotSquared/src/com/intellectualcrafters/plot/commands/Schematic.java @@ -11,7 +11,9 @@ import com.intellectualcrafters.plot.SchematicHandler; public class Schematic extends SubCommand { public Schematic() { - super("schematic", "plots.admin", "Schematic Command", "schematic {arg}", "sch", CommandCategory.ACTIONS); + super("schematic", "plots.admin", "Schematic Command", "schematic {arg}", "sch", CommandCategory.ACTIONS, true); + + // TODO command to fetch schematic from worldedit directory } @Override diff --git a/PlotSquared/src/com/intellectualcrafters/plot/commands/Set.java b/PlotSquared/src/com/intellectualcrafters/plot/commands/Set.java index 72fa7c10b..9500fb30f 100644 --- a/PlotSquared/src/com/intellectualcrafters/plot/commands/Set.java +++ b/PlotSquared/src/com/intellectualcrafters/plot/commands/Set.java @@ -40,7 +40,7 @@ import com.intellectualcrafters.plot.events.PlotFlagRemoveEvent; public class Set extends SubCommand { public Set() { - super(Command.SET, "Set a plot value", "set {arg} {value...}", CommandCategory.ACTIONS); + super(Command.SET, "Set a plot value", "set {arg} {value...}", CommandCategory.ACTIONS, true); } public static String[] values = new String[] { "biome", "wall", "wall_filling", "floor", "alias", "home", "rain", diff --git a/PlotSquared/src/com/intellectualcrafters/plot/commands/SetOwner.java b/PlotSquared/src/com/intellectualcrafters/plot/commands/SetOwner.java index 8510d5ae2..dd25ee01b 100644 --- a/PlotSquared/src/com/intellectualcrafters/plot/commands/SetOwner.java +++ b/PlotSquared/src/com/intellectualcrafters/plot/commands/SetOwner.java @@ -23,7 +23,7 @@ import com.intellectualcrafters.plot.database.DBFunc; public class SetOwner extends SubCommand { public SetOwner() { - super("setowner", "plots.admin", "Set the plot owner", "setowner {player}", "so", CommandCategory.ACTIONS); + super("setowner", "plots.admin", "Set the plot owner", "setowner {player}", "so", CommandCategory.ACTIONS, true); } /* diff --git a/PlotSquared/src/com/intellectualcrafters/plot/commands/Setup.java b/PlotSquared/src/com/intellectualcrafters/plot/commands/Setup.java index b340aa822..f04dede7c 100644 --- a/PlotSquared/src/com/intellectualcrafters/plot/commands/Setup.java +++ b/PlotSquared/src/com/intellectualcrafters/plot/commands/Setup.java @@ -54,15 +54,22 @@ public class Setup extends SubCommand implements Listener { } public Setup() { - super("setup", "plots.admin", "Setup a PlotWorld", "setup {world}", "setup", CommandCategory.ACTIONS); + super("setup", "plots.admin", "Setup a PlotWorld", "setup {world}", "setup", CommandCategory.ACTIONS, false); } @Override public boolean execute(Player plr, String... args) { - boolean finished = false; - - if (setupMap.containsKey(plr.getName())) { - SetupObject object = setupMap.get(plr.getName()); + String plrname; + + if (plr==null) { + plrname = ""; + } + else { + plrname = plr.getName(); + } + + if (setupMap.containsKey(plrname)) { + SetupObject object = setupMap.get(plrname); if (object.getCurrent() == object.getMax()) { ConfigurationNode[] steps = object.step; String world = object.world; @@ -88,7 +95,7 @@ public class Setup extends SubCommand implements Listener { } sendMessage(plr, C.SETUP_FINISHED, object.world); - setupMap.remove(plr.getName()); + setupMap.remove(plrname); return true; } @@ -100,7 +107,7 @@ public class Setup extends SubCommand implements Listener { } else { if (args[0].equalsIgnoreCase("cancel")) { - setupMap.remove(plr.getName()); + setupMap.remove(plrname); PlayerFunctions.sendMessage(plr, "&cCancelled setup."); return true; } @@ -189,9 +196,9 @@ public class Setup extends SubCommand implements Listener { plotworld = new DefaultPlotWorld(world); } - setupMap.put(plr.getName(), new SetupObject(world, plotworld, args[1])); + setupMap.put(plrname, new SetupObject(world, plotworld, args[1])); sendMessage(plr, C.SETUP_INIT); - SetupObject object = setupMap.get(plr.getName()); + SetupObject object = setupMap.get(plrname); ConfigurationNode step = object.step[object.current]; sendMessage(plr, C.SETUP_STEP, object.current + 1 + "", step.getDescription(), step.getType().getType(), step.getDefaultValue() + ""); diff --git a/PlotSquared/src/com/intellectualcrafters/plot/commands/SubCommand.java b/PlotSquared/src/com/intellectualcrafters/plot/commands/SubCommand.java index 2b912dcc1..d4173d52c 100644 --- a/PlotSquared/src/com/intellectualcrafters/plot/commands/SubCommand.java +++ b/PlotSquared/src/com/intellectualcrafters/plot/commands/SubCommand.java @@ -8,6 +8,7 @@ package com.intellectualcrafters.plot.commands; +import org.bukkit.command.CommandSender; import org.bukkit.entity.Player; import com.intellectualcrafters.plot.C; @@ -19,7 +20,7 @@ import com.intellectualcrafters.plot.PlayerFunctions; * @author Citymonstret */ public abstract class SubCommand { - + public boolean isPlayer; /** * Command */ @@ -59,13 +60,14 @@ public abstract class SubCommand { * CommandCategory. Pick whichever closests to what you want. */ public SubCommand(String cmd, String permission, String description, String usage, String alias, - CommandCategory category) { + CommandCategory category, boolean isPlayer) { this.cmd = cmd; this.permission = new CommandPermission(permission); this.description = description; this.alias = alias; this.usage = usage; this.category = category; + this.isPlayer = isPlayer; } /** @@ -78,13 +80,14 @@ public abstract class SubCommand { * @param category * CommandCategory. Pick whichever closests to what you want. */ - public SubCommand(Command command, String description, String usage, CommandCategory category) { + public SubCommand(Command command, String description, String usage, CommandCategory category, boolean isPlayer) { this.cmd = command.getCommand(); this.permission = command.getPermission(); this.alias = command.getAlias(); this.description = description; this.usage = usage; this.category = category; + this.isPlayer = isPlayer; } /** diff --git a/PlotSquared/src/com/intellectualcrafters/plot/commands/TP.java b/PlotSquared/src/com/intellectualcrafters/plot/commands/TP.java index c7e506a3b..64ec17666 100644 --- a/PlotSquared/src/com/intellectualcrafters/plot/commands/TP.java +++ b/PlotSquared/src/com/intellectualcrafters/plot/commands/TP.java @@ -26,7 +26,7 @@ import com.intellectualcrafters.plot.PlotMain; public class TP extends SubCommand { public TP() { - super(Command.TP, "Teleport to a plot", "tp {alias|id}", CommandCategory.TELEPORT); + super(Command.TP, "Teleport to a plot", "tp {alias|id}", CommandCategory.TELEPORT, true); } @Override diff --git a/PlotSquared/src/com/intellectualcrafters/plot/commands/Trusted.java b/PlotSquared/src/com/intellectualcrafters/plot/commands/Trusted.java index 1a0c32107..e78b22e94 100644 --- a/PlotSquared/src/com/intellectualcrafters/plot/commands/Trusted.java +++ b/PlotSquared/src/com/intellectualcrafters/plot/commands/Trusted.java @@ -24,7 +24,7 @@ import com.intellectualcrafters.plot.events.PlayerPlotTrustedEvent; public class Trusted extends SubCommand { public Trusted() { - super(Command.TRUSTED, "Manage trusted users for a plot", "trusted {add|remove} {player}", CommandCategory.ACTIONS); + super(Command.TRUSTED, "Manage trusted users for a plot", "trusted {add|remove} {player}", CommandCategory.ACTIONS, true); } @Override diff --git a/PlotSquared/src/com/intellectualcrafters/plot/commands/Unlink.java b/PlotSquared/src/com/intellectualcrafters/plot/commands/Unlink.java index a7ec2abcc..b58d894a7 100644 --- a/PlotSquared/src/com/intellectualcrafters/plot/commands/Unlink.java +++ b/PlotSquared/src/com/intellectualcrafters/plot/commands/Unlink.java @@ -32,7 +32,7 @@ import com.intellectualcrafters.plot.events.PlotUnlinkEvent; public class Unlink extends SubCommand { public Unlink() { - super(Command.UNLINK, "Unlink a mega-plot", "unlink", CommandCategory.ACTIONS); + super(Command.UNLINK, "Unlink a mega-plot", "unlink", CommandCategory.ACTIONS, true); } @Override diff --git a/PlotSquared/src/com/intellectualcrafters/plot/commands/Visit.java b/PlotSquared/src/com/intellectualcrafters/plot/commands/Visit.java index 8f07300c7..378a57b0e 100644 --- a/PlotSquared/src/com/intellectualcrafters/plot/commands/Visit.java +++ b/PlotSquared/src/com/intellectualcrafters/plot/commands/Visit.java @@ -22,7 +22,7 @@ import com.intellectualcrafters.plot.PlotMain; public class Visit extends SubCommand { public Visit() { - super("visit", "plots.visit", "Visit someones plot", "visit {player} [#]", "v", CommandCategory.TELEPORT); + super("visit", "plots.visit", "Visit someones plot", "visit {player} [#]", "v", CommandCategory.TELEPORT, true); } public List getPlots(UUID uuid) { diff --git a/PlotSquared/src/com/intellectualcrafters/plot/commands/list.java b/PlotSquared/src/com/intellectualcrafters/plot/commands/list.java index ae29c8a5e..f60431414 100644 --- a/PlotSquared/src/com/intellectualcrafters/plot/commands/list.java +++ b/PlotSquared/src/com/intellectualcrafters/plot/commands/list.java @@ -27,7 +27,7 @@ import com.intellectualcrafters.plot.UUIDHandler; public class list extends SubCommand { public list() { - super(Command.LIST, "List all plots", "list {mine|all|world}", CommandCategory.INFO); + super(Command.LIST, "List all plots", "list {mine|shared|all|world}", CommandCategory.INFO, false); } @Override @@ -35,11 +35,16 @@ public class list extends SubCommand { if (args.length < 1) { StringBuilder builder = new StringBuilder(); builder.append(C.SUBCOMMAND_SET_OPTIONS_HEADER.s()); - builder.append(getArgumentList(new String[] { "mine", "shared", "world", "all" })); + if (plr!=null) { + builder.append(getArgumentList(new String[] { "mine", "shared", "world", "all" })); + } + else { + builder.append(getArgumentList(new String[] { "all" })); + } PlayerFunctions.sendMessage(plr, builder.toString()); return true; } - if (args[0].equalsIgnoreCase("mine")) { + if (args[0].equalsIgnoreCase("mine") && plr!=null) { StringBuilder string = new StringBuilder(); string.append(C.PLOT_LIST_HEADER.s().replaceAll("%word%", "your") + "\n"); int idx = 0; @@ -58,7 +63,7 @@ public class list extends SubCommand { return true; } else - if (args[0].equalsIgnoreCase("shared")) { + if (args[0].equalsIgnoreCase("shared") && plr!=null) { StringBuilder string = new StringBuilder(); string.append(C.PLOT_LIST_HEADER.s().replaceAll("%word%", "all") + "\n"); for (Plot p : PlotMain.getPlots()) { @@ -86,7 +91,7 @@ public class list extends SubCommand { return true; } else - if (args[0].equalsIgnoreCase("world")) { + if (args[0].equalsIgnoreCase("world") && plr!=null) { StringBuilder string = new StringBuilder(); string.append(C.PLOT_LIST_HEADER.s().replaceAll("%word%", "all") + "\n"); HashMap plots = PlotMain.getPlots(plr.getWorld()); diff --git a/PlotSquared/src/com/intellectualcrafters/plot/commands/plugin.java b/PlotSquared/src/com/intellectualcrafters/plot/commands/plugin.java index 76dd3b79e..ea3006116 100644 --- a/PlotSquared/src/com/intellectualcrafters/plot/commands/plugin.java +++ b/PlotSquared/src/com/intellectualcrafters/plot/commands/plugin.java @@ -23,7 +23,7 @@ import java.util.ArrayList; public class plugin extends SubCommand { public plugin() { - super("plugin", "plots.use", "Show plugin information", "plugin", "pl", CommandCategory.INFO); + super("plugin", "plots.use", "Show plugin information", "plugin", "pl", CommandCategory.INFO, false); } public static String diff --git a/PlotSquared/src/com/intellectualcrafters/plot/database/DBFunc.java b/PlotSquared/src/com/intellectualcrafters/plot/database/DBFunc.java index 99eb4decb..5d8710cb9 100644 --- a/PlotSquared/src/com/intellectualcrafters/plot/database/DBFunc.java +++ b/PlotSquared/src/com/intellectualcrafters/plot/database/DBFunc.java @@ -629,6 +629,10 @@ public class DBFunc { PlotMain.getMain().getServer().getScheduler().runTaskAsynchronously(PlotMain.getMain(), r); } + public static void purge(final String world) { + // TODO purge + } + /** * @param plot * @param position