mirror of
https://github.com/IntellectualSites/PlotSquared.git
synced 2024-11-22 21:26:45 +01:00
Starting to convert commands to a smarter system :3
This commit is contained in:
parent
6b229ac504
commit
e1c8dcc4be
@ -31,26 +31,38 @@ import com.intellectualcrafters.plot.object.PlotPlayer;
|
||||
import com.intellectualcrafters.plot.util.EventUtil;
|
||||
import com.intellectualcrafters.plot.util.MainUtil;
|
||||
import com.intellectualcrafters.plot.util.Permissions;
|
||||
import com.intellectualsites.commands.Argument;
|
||||
import com.intellectualsites.commands.CommandDeclaration;
|
||||
import com.intellectualsites.commands.callers.CommandCaller;
|
||||
import com.plotsquared.bukkit.util.bukkit.UUIDHandler;
|
||||
import com.plotsquared.bukkit.util.bukkit.uuid.SQLUUIDHandler;
|
||||
|
||||
@CommandDeclaration(
|
||||
command = "add",
|
||||
aliases = {"a"},
|
||||
description = "Allow a user to build while you are online",
|
||||
usage = "/plot add <player>",
|
||||
category = CommandCategory.ACTIONS,
|
||||
permission = "plots.add",
|
||||
requiredType = PlotPlayer.class
|
||||
)
|
||||
public class Add extends SubCommand {
|
||||
|
||||
public Add() {
|
||||
super(Command.ADD, "Allow a user to build while you are online", "add <player>", CommandCategory.ACTIONS, true);
|
||||
requiredArguments = new Argument[] {
|
||||
Argument.PlayerName
|
||||
};
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean execute(final PlotPlayer plr, final String... args) {
|
||||
if (args.length != 1) {
|
||||
MainUtil.sendMessage(plr, C.COMMAND_SYNTAX, "/plot add <player>");
|
||||
return true;
|
||||
}
|
||||
public boolean onCommand(CommandCaller caller, String[] args) {
|
||||
final PlotPlayer plr = (PlotPlayer) caller.getSuperCaller();
|
||||
final Location loc = plr.getLocation();
|
||||
final Plot plot = MainUtil.getPlot(loc);
|
||||
if (plot == null) {
|
||||
return !sendMessage(plr, C.NOT_IN_PLOT);
|
||||
}
|
||||
if ((plot == null) || !plot.hasOwner()) {
|
||||
if (!plot.hasOwner()) {
|
||||
MainUtil.sendMessage(plr, C.PLOT_UNOWNED);
|
||||
return false;
|
||||
}
|
||||
|
@ -33,11 +33,19 @@ import com.intellectualcrafters.plot.util.ClusterManager;
|
||||
import com.intellectualcrafters.plot.util.EconHandler;
|
||||
import com.intellectualcrafters.plot.util.MainUtil;
|
||||
import com.intellectualcrafters.plot.util.Permissions;
|
||||
import com.intellectualsites.commands.CommandDeclaration;
|
||||
import com.intellectualsites.commands.callers.CommandCaller;
|
||||
|
||||
@CommandDeclaration(
|
||||
command = "auto",
|
||||
permission = "plots.auto",
|
||||
category = CommandCategory.CLAIMING,
|
||||
requiredType = PlotPlayer.class,
|
||||
description = "Claim the nearest plot",
|
||||
aliases = {"a"},
|
||||
usage = "/plot auto"
|
||||
)
|
||||
public class Auto extends SubCommand {
|
||||
public Auto() {
|
||||
super("auto", "plots.auto", "Claim the nearest plot", "auto", "a", CommandCategory.CLAIMING, true);
|
||||
}
|
||||
|
||||
public static PlotId getNextPlot(final PlotId id, final int step) {
|
||||
final int absX = Math.abs(id.x);
|
||||
@ -68,9 +76,9 @@ public class Auto extends SubCommand {
|
||||
}
|
||||
}
|
||||
|
||||
// TODO auto claim a mega plot with schematic
|
||||
@Override
|
||||
public boolean execute(final PlotPlayer plr, final String... args) {
|
||||
public boolean onCommand(CommandCaller caller, String[] args) {
|
||||
final PlotPlayer plr = (PlotPlayer) caller.getSuperCaller();
|
||||
String world;
|
||||
int size_x = 1;
|
||||
int size_z = 1;
|
||||
|
@ -36,9 +36,7 @@ import com.intellectualcrafters.plot.util.EconHandler;
|
||||
import com.intellectualcrafters.plot.util.MainUtil;
|
||||
import com.plotsquared.bukkit.util.bukkit.UUIDHandler;
|
||||
|
||||
/**
|
||||
* @author Citymonstret
|
||||
*/
|
||||
|
||||
public class Buy extends SubCommand {
|
||||
public Buy() {
|
||||
super(Command.BUY, "Buy the plot you are standing on", "b", CommandCategory.CLAIMING, true);
|
||||
|
@ -0,0 +1,58 @@
|
||||
package com.intellectualcrafters.plot.commands;
|
||||
|
||||
/**
|
||||
* CommandCategory
|
||||
*
|
||||
* @author Citymonstret
|
||||
* @author Empire92
|
||||
*/
|
||||
public enum CommandCategory {
|
||||
/**
|
||||
* Claiming Commands
|
||||
*
|
||||
* Such as: /plot claim
|
||||
*/
|
||||
CLAIMING("Claiming"),
|
||||
/**
|
||||
* Teleportation Commands
|
||||
*
|
||||
* Such as: /plot visit
|
||||
*/
|
||||
TELEPORT("Teleportation"),
|
||||
/**
|
||||
* Action Commands
|
||||
*
|
||||
* Such as: /plot clear
|
||||
*/
|
||||
ACTIONS("Actions"),
|
||||
/**
|
||||
* Information Commands
|
||||
*
|
||||
* Such as: /plot info
|
||||
*/
|
||||
INFO("Information"),
|
||||
/**
|
||||
* Debug Commands
|
||||
*
|
||||
* Such as: /plot debug
|
||||
*/
|
||||
DEBUG("Debug");
|
||||
/**
|
||||
* The category name (Readable)
|
||||
*/
|
||||
private final String name;
|
||||
|
||||
/**
|
||||
* Constructor
|
||||
*
|
||||
* @param name readable name
|
||||
*/
|
||||
CommandCategory(final String name) {
|
||||
this.name = name;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return this.name;
|
||||
}
|
||||
}
|
@ -28,6 +28,9 @@ import java.util.HashSet;
|
||||
import java.util.Map.Entry;
|
||||
import java.util.UUID;
|
||||
|
||||
import com.intellectualsites.commands.Argument;
|
||||
import com.intellectualsites.commands.CommandDeclaration;
|
||||
import com.intellectualsites.commands.callers.CommandCaller;
|
||||
import org.bukkit.Bukkit;
|
||||
|
||||
import com.intellectualcrafters.plot.PS;
|
||||
@ -48,21 +51,25 @@ import com.intellectualcrafters.plot.uuid.LowerOfflineUUIDWrapper;
|
||||
import com.intellectualcrafters.plot.uuid.OfflineUUIDWrapper;
|
||||
import com.intellectualcrafters.plot.uuid.UUIDWrapper;
|
||||
|
||||
@CommandDeclaration(
|
||||
command = "uuidconvert",
|
||||
permission = "plots.admin",
|
||||
description = "Debug UUID conversion",
|
||||
usage = "/plot uuidconvert <lower|offline|online>",
|
||||
requiredType = PS.class,
|
||||
category = CommandCategory.DEBUG
|
||||
)
|
||||
public class DebugUUID extends SubCommand {
|
||||
|
||||
public DebugUUID() {
|
||||
super("uuidconvert", "plots.admin", "Debug uuid conversion", "debuguuid", "debuguuid", CommandCategory.DEBUG, false);
|
||||
requiredArguments = new Argument[] {
|
||||
Argument.String
|
||||
};
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean execute(final PlotPlayer player, final String... args) {
|
||||
if (player != null) {
|
||||
MainUtil.sendMessage(player, C.NOT_CONSOLE);
|
||||
return false;
|
||||
}
|
||||
if (args.length == 0) {
|
||||
MainUtil.sendMessage(player, C.COMMAND_SYNTAX, "/plot uuidconvert <lower|offline|online>");
|
||||
return false;
|
||||
}
|
||||
public boolean onCommand(final CommandCaller caller, final String[] args) {
|
||||
PlotPlayer player = null;
|
||||
|
||||
UUIDWrapper currentUUIDWrapper = UUIDHandler.getUUIDWrapper();
|
||||
UUIDWrapper newWrapper = null;
|
||||
|
@ -32,15 +32,24 @@ import com.intellectualcrafters.plot.util.EconHandler;
|
||||
import com.intellectualcrafters.plot.util.MainUtil;
|
||||
import com.intellectualcrafters.plot.util.Permissions;
|
||||
import com.intellectualcrafters.plot.util.TaskManager;
|
||||
import com.intellectualsites.commands.CommandDeclaration;
|
||||
import com.intellectualsites.commands.callers.CommandCaller;
|
||||
import com.plotsquared.bukkit.util.UUIDHandler;
|
||||
import com.plotsquared.bukkit.util.bukkit.UUIDHandler;
|
||||
|
||||
@CommandDeclaration(
|
||||
command = "delete",
|
||||
permission = "plots.delete",
|
||||
description = "Delete a plot",
|
||||
usage = "/plot delete",
|
||||
category = CommandCategory.ACTIONS,
|
||||
requiredType = PlotPlayer.class
|
||||
)
|
||||
public class Delete extends SubCommand {
|
||||
public Delete() {
|
||||
super(Command.DELETE, "Delete a plot", "delete", CommandCategory.ACTIONS, true);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean execute(final PlotPlayer plr, final String... args) {
|
||||
public boolean onCommand(final CommandCaller caller, final String[] args) {
|
||||
final PlotPlayer plr = (PlotPlayer) caller.getSuperCaller();
|
||||
final Location loc = plr.getLocation();
|
||||
final Plot plot = MainUtil.getPlot(loc);
|
||||
if (plot == null) {
|
||||
@ -49,10 +58,9 @@ public class Delete extends SubCommand {
|
||||
if (!MainUtil.getTopPlot(plot).equals(MainUtil.getBottomPlot(plot))) {
|
||||
return !sendMessage(plr, C.UNLINK_REQUIRED);
|
||||
}
|
||||
if ((((plot == null) || !plot.hasOwner() || !plot.isOwner(UUIDHandler.getUUIDWrapper().getUUID(plr)))) && !Permissions.hasPermission(plr, "plots.admin.command.delete")) {
|
||||
if (((!plot.hasOwner() || !plot.isOwner(UUIDHandler.getUUIDWrapper().getUUID(plr)))) && !Permissions.hasPermission(plr, "plots.admin.command.delete")) {
|
||||
return !sendMessage(plr, C.NO_PLOT_PERMS);
|
||||
}
|
||||
assert plot != null;
|
||||
final PlotWorld pWorld = PS.get().getPlotWorld(plot.world);
|
||||
if (MainUtil.runners.containsKey(plot)) {
|
||||
MainUtil.sendMessage(plr, C.WAIT_FOR_TIMER);
|
||||
@ -61,7 +69,7 @@ public class Delete extends SubCommand {
|
||||
Runnable runnable = new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
if ((EconHandler.manager != null) && pWorld.USE_ECONOMY && (plot != null) && plot.hasOwner() && plot.isOwner(UUIDHandler.getUUID(plr))) {
|
||||
if ((EconHandler.manager != null) && pWorld.USE_ECONOMY && plot.hasOwner() && plot.isOwner(UUIDHandler.getUUID(plr))) {
|
||||
final double c = pWorld.SELL_PRICE;
|
||||
if (c > 0d) {
|
||||
EconHandler.manager.depositMoney(plr, c);
|
||||
|
@ -31,21 +31,32 @@ import com.intellectualcrafters.plot.util.BlockManager;
|
||||
import com.intellectualcrafters.plot.util.EventUtil;
|
||||
import com.intellectualcrafters.plot.util.MainUtil;
|
||||
import com.intellectualcrafters.plot.util.Permissions;
|
||||
import com.intellectualsites.commands.Argument;
|
||||
import com.intellectualsites.commands.CommandDeclaration;
|
||||
import com.intellectualsites.commands.callers.CommandCaller;
|
||||
import com.plotsquared.bukkit.util.bukkit.UUIDHandler;
|
||||
|
||||
import com.plotsquared.bukkit.util.bukkit.uuid.SQLUUIDHandler;
|
||||
|
||||
@CommandDeclaration(
|
||||
command = "deny",
|
||||
aliases = {"d"},
|
||||
description = "Deny a user from a plot",
|
||||
usage = "/plot deny <player>",
|
||||
category = CommandCategory.ACTIONS,
|
||||
requiredType = PlotPlayer.class
|
||||
)
|
||||
public class Deny extends SubCommand {
|
||||
|
||||
public Deny() {
|
||||
super(Command.DENY, "Deny a user from a plot", "deny <player>", CommandCategory.ACTIONS, true);
|
||||
requiredArguments = new Argument[] {
|
||||
Argument.PlayerName
|
||||
};
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean execute(final PlotPlayer plr, final String... args) {
|
||||
if (args.length != 1) {
|
||||
MainUtil.sendMessage(plr, C.COMMAND_SYNTAX, "/plot deny <player>");
|
||||
return true;
|
||||
}
|
||||
public boolean onCommand(final CommandCaller caller, final String[] args) {
|
||||
final PlotPlayer plr = (PlotPlayer) caller.getSuperCaller();
|
||||
final Location loc = plr.getLocation();
|
||||
final Plot plot = MainUtil.getPlot(loc);
|
||||
if (plot == null) {
|
||||
|
@ -1,39 +0,0 @@
|
||||
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
// PlotSquared - A plot manager and world generator for the Bukkit API /
|
||||
// Copyright (c) 2014 IntellectualSites/IntellectualCrafters /
|
||||
// /
|
||||
// This program is free software; you can redistribute it and/or modify /
|
||||
// it under the terms of the GNU General Public License as published by /
|
||||
// the Free Software Foundation; either version 3 of the License, or /
|
||||
// (at your option) any later version. /
|
||||
// /
|
||||
// This program is distributed in the hope that it will be useful, /
|
||||
// but WITHOUT ANY WARRANTY; without even the implied warranty of /
|
||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the /
|
||||
// GNU General Public License for more details. /
|
||||
// /
|
||||
// You should have received a copy of the GNU General Public License /
|
||||
// along with this program; if not, write to the Free Software Foundation, /
|
||||
// Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA /
|
||||
// /
|
||||
// You can contact us via: support@intellectualsites.com /
|
||||
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
package com.intellectualcrafters.plot.commands;
|
||||
|
||||
import com.intellectualcrafters.plot.PS;
|
||||
import com.intellectualcrafters.plot.object.PlotPlayer;
|
||||
|
||||
public class Disable extends SubCommand {
|
||||
public static String downloads, version;
|
||||
|
||||
public Disable() {
|
||||
super("disable", "plots.admin", "Disable PlotSquared", "disable", "unload", CommandCategory.DEBUG, false);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean execute(final PlotPlayer plr, final String... args) {
|
||||
PS.log("&cDisabling PlotSquared and all dependencies!");
|
||||
PS.get().IMP.disable();
|
||||
return true;
|
||||
}
|
||||
}
|
@ -13,14 +13,22 @@ import com.intellectualcrafters.plot.util.MainUtil;
|
||||
import com.intellectualcrafters.plot.util.Permissions;
|
||||
import com.intellectualcrafters.plot.util.SchematicHandler;
|
||||
import com.intellectualcrafters.plot.util.TaskManager;
|
||||
import com.intellectualsites.commands.CommandDeclaration;
|
||||
import com.intellectualsites.commands.callers.CommandCaller;
|
||||
|
||||
@CommandDeclaration(
|
||||
command = "download",
|
||||
aliases = {"dl"},
|
||||
category = CommandCategory.ACTIONS,
|
||||
requiredType = PlotPlayer.class,
|
||||
description = "Download your plot",
|
||||
permission = "plots.download"
|
||||
)
|
||||
public class Download extends SubCommand {
|
||||
public Download() {
|
||||
super(Command.DOWNLOAD, "Download your plot", "dl", CommandCategory.ACTIONS, true);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean execute(final PlotPlayer plr, String... args) {
|
||||
public boolean onCommand(final CommandCaller caller, final String[] args) {
|
||||
final PlotPlayer plr = (PlotPlayer) caller.getSuperCaller();
|
||||
if (!Settings.METRICS) {
|
||||
MainUtil.sendMessage(plr, "&cPlease enable metrics in order to use this command.\n&7 - Or host it yourself if you don't like the free service");
|
||||
return false;
|
||||
|
@ -7,15 +7,20 @@
|
||||
*/
|
||||
package com.intellectualcrafters.plot.commands;
|
||||
|
||||
import com.intellectualcrafters.plot.object.PlotPlayer;
|
||||
import com.intellectualsites.commands.CommandDeclaration;
|
||||
import com.intellectualsites.commands.callers.CommandCaller;
|
||||
|
||||
@CommandDeclaration(
|
||||
command = "help",
|
||||
description = "Get this help menu",
|
||||
permission = "",
|
||||
aliases = {"he"},
|
||||
category = CommandCategory.INFO
|
||||
)
|
||||
public class Help extends SubCommand {
|
||||
public Help() {
|
||||
super("help", "", "Get this help menu", "help", "he", SubCommand.CommandCategory.INFO, false);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean execute(final PlotPlayer plr, final String... args) {
|
||||
return false;
|
||||
public boolean onCommand(final CommandCaller caller, final String[] args) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
@ -27,14 +27,18 @@ import com.intellectualcrafters.plot.config.C;
|
||||
import com.intellectualcrafters.plot.object.Plot;
|
||||
import com.intellectualcrafters.plot.object.PlotPlayer;
|
||||
import com.intellectualcrafters.plot.util.MainUtil;
|
||||
import com.intellectualsites.commands.CommandDeclaration;
|
||||
import com.intellectualsites.commands.callers.CommandCaller;
|
||||
|
||||
/**
|
||||
* @author Citymonstret
|
||||
*/
|
||||
@CommandDeclaration(
|
||||
command = "home",
|
||||
aliases = {"h"},
|
||||
description = "Go to your plot",
|
||||
usage = "/plot home [id|alias]",
|
||||
category = CommandCategory.TELEPORT,
|
||||
requiredType = PlotPlayer.class
|
||||
)
|
||||
public class Home extends SubCommand {
|
||||
public Home() {
|
||||
super(Command.HOME, "Go to your plot", "home {id|alias}", CommandCategory.TELEPORT, true);
|
||||
}
|
||||
|
||||
private Plot isAlias(final String a) {
|
||||
for (final Plot p : PS.get().getPlots()) {
|
||||
@ -46,7 +50,8 @@ public class Home extends SubCommand {
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean execute(final PlotPlayer plr, String... args) {
|
||||
public boolean onCommand(final CommandCaller caller, String[] args) {
|
||||
final PlotPlayer plr = (PlotPlayer) caller.getSuperCaller();
|
||||
final ArrayList<Plot> plots = PS.get().sortPlotsByWorld(PS.get().getPlots(plr));
|
||||
if (plots.size() == 1) {
|
||||
MainUtil.teleportPlayer(plr, plr.getLocation(), plots.get(0));
|
||||
|
@ -23,6 +23,8 @@ package com.intellectualcrafters.plot.commands;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import com.intellectualsites.commands.CommandDeclaration;
|
||||
import com.intellectualsites.commands.callers.CommandCaller;
|
||||
import org.apache.commons.lang.StringUtils;
|
||||
|
||||
import com.intellectualcrafters.plot.config.C;
|
||||
@ -35,10 +37,15 @@ import com.intellectualcrafters.plot.object.comment.PlotComment;
|
||||
import com.intellectualcrafters.plot.util.MainUtil;
|
||||
import com.intellectualcrafters.plot.util.StringMan;
|
||||
|
||||
@CommandDeclaration(
|
||||
command = "inbox",
|
||||
description = "Review the comments for a plot",
|
||||
usage = "/plot inbox [inbox] [delete <index>|clear|page]",
|
||||
permission = "plots.inbox",
|
||||
category = CommandCategory.ACTIONS,
|
||||
requiredType = PlotPlayer.class
|
||||
)
|
||||
public class Inbox extends SubCommand {
|
||||
public Inbox() {
|
||||
super(Command.INBOX, "Review the comments for a plot", "inbox [inbox] [delete <index>|clear|page]", CommandCategory.ACTIONS, true);
|
||||
}
|
||||
|
||||
public void displayComments(PlotPlayer player, List<PlotComment> oldComments, int page) {
|
||||
if (oldComments == null || oldComments.size() == 0) {
|
||||
@ -79,7 +86,9 @@ public class Inbox extends SubCommand {
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean execute(final PlotPlayer player, final String... args) {
|
||||
public boolean onCommand(final CommandCaller caller, final String[] args) {
|
||||
final PlotPlayer player = (PlotPlayer) caller.getSuperCaller();
|
||||
|
||||
final Plot plot = MainUtil.getPlot(player.getLocation());
|
||||
if (args.length == 0) {
|
||||
sendMessage(player, C.COMMAND_SYNTAX, "/plot inbox [inbox] [delete <index>|clear|page]");
|
||||
|
@ -25,7 +25,10 @@ import java.util.Collection;
|
||||
import java.util.UUID;
|
||||
import java.util.regex.Matcher;
|
||||
|
||||
import com.intellectualcrafters.plot.commands.callers.PlotPlayerCaller;
|
||||
import com.intellectualcrafters.plot.flag.Flag;
|
||||
import com.intellectualsites.commands.CommandDeclaration;
|
||||
import com.intellectualsites.commands.callers.CommandCaller;
|
||||
import org.apache.commons.lang.StringUtils;
|
||||
|
||||
import com.intellectualcrafters.plot.config.C;
|
||||
@ -43,14 +46,14 @@ import com.intellectualcrafters.plot.util.StringMan;
|
||||
import com.intellectualcrafters.plot.util.TaskManager;
|
||||
import com.plotsquared.bukkit.util.bukkit.UUIDHandler;
|
||||
|
||||
/**
|
||||
* @author Citymonstret
|
||||
*/
|
||||
@SuppressWarnings({ "javadoc" })
|
||||
@CommandDeclaration(
|
||||
command = "info",
|
||||
aliases = {"i"},
|
||||
description = "Display plot info",
|
||||
usage = "/plot info <id>",
|
||||
category = CommandCategory.INFO
|
||||
)
|
||||
public class Info extends SubCommand {
|
||||
public Info() {
|
||||
super(Command.INFO, "Display plot info", "info", CommandCategory.INFO, false);
|
||||
}
|
||||
|
||||
public static String getPlayerList(final Collection<UUID> uuids) {
|
||||
ArrayList<UUID> l = new ArrayList<>(uuids);
|
||||
@ -84,7 +87,9 @@ public class Info extends SubCommand {
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean execute(final PlotPlayer player, String... args) {
|
||||
public boolean onCommand(final CommandCaller caller, String[] args) {
|
||||
final PlotPlayer player = caller instanceof PlotPlayerCaller ? (PlotPlayer) caller.getSuperCaller() : null;
|
||||
|
||||
String arg = null;
|
||||
Plot plot;
|
||||
if (args.length > 0) arg = args[0] + "";
|
||||
|
@ -1,73 +0,0 @@
|
||||
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
// PlotSquared - A plot manager and world generator for the Bukkit API /
|
||||
// Copyright (c) 2014 IntellectualSites/IntellectualCrafters /
|
||||
// /
|
||||
// This program is free software; you can redistribute it and/or modify /
|
||||
// it under the terms of the GNU General Public License as published by /
|
||||
// the Free Software Foundation; either version 3 of the License, or /
|
||||
// (at your option) any later version. /
|
||||
// /
|
||||
// This program is distributed in the hope that it will be useful, /
|
||||
// but WITHOUT ANY WARRANTY; without even the implied warranty of /
|
||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the /
|
||||
// GNU General Public License for more details. /
|
||||
// /
|
||||
// You should have received a copy of the GNU General Public License /
|
||||
// along with this program; if not, write to the Free Software Foundation, /
|
||||
// Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA /
|
||||
// /
|
||||
// You can contact us via: support@intellectualsites.com /
|
||||
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
package com.intellectualcrafters.plot.commands;
|
||||
|
||||
import java.util.ArrayList;
|
||||
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.ChatColor;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
import org.bukkit.inventory.meta.ItemMeta;
|
||||
|
||||
import com.intellectualcrafters.plot.config.C;
|
||||
import com.plotsquared.bukkit.object.BukkitPlayer;
|
||||
import com.intellectualcrafters.plot.object.PlotPlayer;
|
||||
|
||||
public class Inventory extends SubCommand {
|
||||
public Inventory() {
|
||||
super("inventory", "plots.inventory", "Open a command inventory", "inventory", "inv", CommandCategory.INFO, true);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean execute(final PlotPlayer plr, final String... args) {
|
||||
final ArrayList<SubCommand> cmds = new ArrayList<>();
|
||||
for (final SubCommand cmd : MainCommand.subCommands) {
|
||||
if (cmd.permission.hasPermission(plr)) {
|
||||
cmds.add(cmd);
|
||||
}
|
||||
}
|
||||
final int size = 9 * (int) Math.ceil(cmds.size() / 9.0);
|
||||
final org.bukkit.inventory.Inventory inventory = Bukkit.createInventory(null, size, "PlotSquared Commands");
|
||||
for (final SubCommand cmd : cmds) {
|
||||
inventory.addItem(getItem(cmd));
|
||||
}
|
||||
((BukkitPlayer) plr).player.openInventory(inventory);
|
||||
return true;
|
||||
}
|
||||
|
||||
private ItemStack getItem(final SubCommand cmd) {
|
||||
final ItemStack stack = new ItemStack(Material.COMMAND);
|
||||
final ItemMeta meta = stack.getItemMeta();
|
||||
{
|
||||
meta.setDisplayName(ChatColor.GREEN + cmd.cmd + ChatColor.DARK_GRAY + " [" + ChatColor.GREEN + cmd.alias + ChatColor.DARK_GRAY + "]");
|
||||
meta.setLore(new ArrayList<String>() {
|
||||
{
|
||||
add(C.INVENTORY_CATEGORY.s().replace("{category}", cmd.category.toString()));
|
||||
add(C.INVENTORY_DESC.s().replace("{desc}", cmd.description));
|
||||
add(C.INVENTORY_USAGE.s().replace("{usage}", "/plot " + cmd.usage));
|
||||
}
|
||||
});
|
||||
}
|
||||
stack.setItemMeta(meta);
|
||||
return stack;
|
||||
}
|
||||
}
|
@ -27,16 +27,23 @@ import com.intellectualcrafters.plot.object.PlotPlayer;
|
||||
import com.intellectualcrafters.plot.util.BlockManager;
|
||||
import com.intellectualcrafters.plot.util.MainUtil;
|
||||
import com.intellectualcrafters.plot.util.Permissions;
|
||||
import com.intellectualsites.commands.CommandDeclaration;
|
||||
import com.intellectualsites.commands.callers.CommandCaller;
|
||||
import com.plotsquared.bukkit.util.bukkit.UUIDHandler;
|
||||
|
||||
@SuppressWarnings({ "unused", "deprecation", "javadoc" })
|
||||
@CommandDeclaration(
|
||||
command = "kick",
|
||||
aliases = {"k"},
|
||||
description = "Kick a player from your plot",
|
||||
permission = "plots.kick",
|
||||
category = CommandCategory.ACTIONS,
|
||||
requiredType = PlotPlayer.class
|
||||
)
|
||||
public class Kick extends SubCommand {
|
||||
public Kick() {
|
||||
super(Command.KICK, "Kick a player from your plot", "kick", CommandCategory.ACTIONS, true);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean execute(final PlotPlayer plr, final String... args) {
|
||||
public boolean onCommand(final CommandCaller caller, final String[] args) {
|
||||
final PlotPlayer plr = (PlotPlayer) caller.getSuperCaller();
|
||||
final Location loc = plr.getLocation();
|
||||
final Plot plot = MainUtil.getPlot(loc);
|
||||
if (plot == null) {
|
||||
|
@ -3,9 +3,7 @@ package com.intellectualcrafters.plot.commands;
|
||||
import java.net.MalformedURLException;
|
||||
import java.net.URL;
|
||||
import java.util.List;
|
||||
import java.util.UUID;
|
||||
|
||||
import com.intellectualcrafters.jnbt.CompoundTag;
|
||||
import com.intellectualcrafters.plot.PS;
|
||||
import com.intellectualcrafters.plot.config.C;
|
||||
import com.intellectualcrafters.plot.config.Settings;
|
||||
@ -18,14 +16,23 @@ import com.intellectualcrafters.plot.util.Permissions;
|
||||
import com.intellectualcrafters.plot.util.SchematicHandler;
|
||||
import com.intellectualcrafters.plot.util.SchematicHandler.Schematic;
|
||||
import com.intellectualcrafters.plot.util.TaskManager;
|
||||
import com.intellectualsites.commands.CommandDeclaration;
|
||||
import com.intellectualsites.commands.callers.CommandCaller;
|
||||
|
||||
@CommandDeclaration(
|
||||
command = "load",
|
||||
aliases = {"restore"},
|
||||
category = CommandCategory.ACTIONS,
|
||||
requiredType = PlotPlayer.class,
|
||||
description = "Load your plot",
|
||||
permission = "plots.load",
|
||||
usage = "/plot restore"
|
||||
)
|
||||
public class Load extends SubCommand {
|
||||
public Load() {
|
||||
super(Command.LOAD, "Load your plot", "restore", CommandCategory.ACTIONS, true);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean execute(final PlotPlayer plr, String... args) {
|
||||
public boolean onCommand(final CommandCaller caller, final String[] args) {
|
||||
final PlotPlayer plr = (PlotPlayer) caller.getSuperCaller();
|
||||
if (!Settings.METRICS) {
|
||||
MainUtil.sendMessage(plr, "&cPlease enable metrics in order to use this command.\n&7 - Or host it yourself if you don't like the free service");
|
||||
return false;
|
||||
|
@ -28,31 +28,24 @@ import com.intellectualcrafters.plot.config.C;
|
||||
import com.intellectualcrafters.plot.object.PlotPlayer;
|
||||
import com.intellectualcrafters.plot.util.MainUtil;
|
||||
import com.intellectualcrafters.plot.util.StringComparison;
|
||||
import com.intellectualsites.commands.CommandManager;
|
||||
|
||||
/**
|
||||
* PlotSquared command class
|
||||
*
|
||||
* @author Citymonstret
|
||||
*/
|
||||
public class MainCommand {
|
||||
/**
|
||||
* Main Permission Node
|
||||
*/
|
||||
private final static SubCommand[] _subCommands = new SubCommand[] { };
|
||||
public final static ArrayList<SubCommand> subCommands = new ArrayList<SubCommand>() {
|
||||
{
|
||||
addAll(Arrays.asList(_subCommands));
|
||||
}
|
||||
};
|
||||
public class MainCommand extends CommandManager {
|
||||
|
||||
public static boolean no_permission(final PlotPlayer player, final String permission) {
|
||||
MainUtil.sendMessage(player, C.NO_PERMISSION, permission);
|
||||
return false;
|
||||
}
|
||||
|
||||
public static List<SubCommand> getCommands(final SubCommand.CommandCategory category, final PlotPlayer player) {
|
||||
public static List<SubCommand> getCommands(final CommandCategory category, final PlotPlayer player) {
|
||||
final List<SubCommand> cmds = new ArrayList<>();
|
||||
for (final SubCommand c : subCommands) {
|
||||
for (final Command c : commands) {
|
||||
if (!c.requiredType )
|
||||
if (!c.isPlayer || (player != null)) {
|
||||
if ((c.category.equals(category)) && c.permission.hasPermission(player)) {
|
||||
cmds.add(c);
|
||||
@ -62,7 +55,7 @@ public class MainCommand {
|
||||
return cmds;
|
||||
}
|
||||
|
||||
public static List<String> helpMenu(final PlotPlayer player, final SubCommand.CommandCategory category, int page) {
|
||||
public static List<String> helpMenu(final PlotPlayer player, final CommandCategory category, int page) {
|
||||
List<SubCommand> commands;
|
||||
if (category != null) {
|
||||
commands = getCommands(category, player);
|
||||
@ -109,15 +102,15 @@ public class MainCommand {
|
||||
if (args.length < 2) {
|
||||
final StringBuilder builder = new StringBuilder();
|
||||
builder.append(C.HELP_INFO.s());
|
||||
for (final SubCommand.CommandCategory category : SubCommand.CommandCategory.values()) {
|
||||
for (final CommandCategory category : CommandCategory.values()) {
|
||||
builder.append("\n").append(C.HELP_INFO_ITEM.s().replaceAll("%category%", category.toString().toLowerCase()).replaceAll("%category_desc%", category.toString()));
|
||||
}
|
||||
builder.append("\n").append(C.HELP_INFO_ITEM.s().replaceAll("%category%", "all").replaceAll("%category_desc%", "Display all commands"));
|
||||
return MainUtil.sendMessage(player, builder.toString());
|
||||
}
|
||||
final String cat = args[1];
|
||||
SubCommand.CommandCategory cato = null;
|
||||
for (final SubCommand.CommandCategory category : SubCommand.CommandCategory.values()) {
|
||||
CommandCategory cato = null;
|
||||
for (final CommandCategory category : CommandCategory.values()) {
|
||||
if (cat.equalsIgnoreCase(category.toString())) {
|
||||
cato = category;
|
||||
break;
|
||||
@ -126,7 +119,7 @@ public class MainCommand {
|
||||
if ((cato == null) && !cat.equalsIgnoreCase("all")) {
|
||||
final StringBuilder builder = new StringBuilder();
|
||||
builder.append(C.HELP_INFO.s());
|
||||
for (final SubCommand.CommandCategory category : SubCommand.CommandCategory.values()) {
|
||||
for (final CommandCategory category : CommandCategory.values()) {
|
||||
builder.append("\n").append(C.HELP_INFO_ITEM.s().replaceAll("%category%", category.toString().toLowerCase()).replaceAll("%category_desc%", category.toString()));
|
||||
}
|
||||
return MainUtil.sendMessage(player, builder.toString(), false);
|
||||
|
@ -24,6 +24,9 @@ import java.util.ArrayList;
|
||||
import java.util.HashSet;
|
||||
import java.util.UUID;
|
||||
|
||||
import com.intellectualsites.commands.Argument;
|
||||
import com.intellectualsites.commands.CommandDeclaration;
|
||||
import com.intellectualsites.commands.callers.CommandCaller;
|
||||
import org.apache.commons.lang.StringUtils;
|
||||
|
||||
import com.intellectualcrafters.plot.PS;
|
||||
@ -40,15 +43,23 @@ import com.intellectualcrafters.plot.util.MainUtil;
|
||||
import com.intellectualcrafters.plot.util.Permissions;
|
||||
import com.plotsquared.bukkit.util.bukkit.UUIDHandler;
|
||||
|
||||
/**
|
||||
* @author Citymonstret
|
||||
*/
|
||||
@CommandDeclaration(
|
||||
command = "merge",
|
||||
aliases = {"m"},
|
||||
description = "Merge the plot you are standing on, with another plot",
|
||||
permission = "plots.merge",
|
||||
usage = "/plot merge [direction]",
|
||||
category = CommandCategory.ACTIONS,
|
||||
requiredType = PlotPlayer.class
|
||||
)
|
||||
public class Merge extends SubCommand {
|
||||
public final static String[] values = new String[] { "north", "east", "south", "west" };
|
||||
public final 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, true);
|
||||
requiredArguments = new Argument[] {
|
||||
Argument.String
|
||||
};
|
||||
}
|
||||
|
||||
public static String direction(float yaw) {
|
||||
@ -74,7 +85,8 @@ public class Merge extends SubCommand {
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean execute(final PlotPlayer plr, final String... args) {
|
||||
public boolean onCommand(final CommandCaller caller, final String[] args) {
|
||||
final PlotPlayer plr = (PlotPlayer) caller.getSuperCaller();
|
||||
final Location loc = plr.getLocationFull();
|
||||
final Plot plot = MainUtil.getPlot(loc);
|
||||
if (plot == null) {
|
||||
|
@ -29,24 +29,29 @@ 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.intellectualsites.commands.Argument;
|
||||
import com.intellectualsites.commands.CommandDeclaration;
|
||||
import com.intellectualsites.commands.callers.CommandCaller;
|
||||
|
||||
/**
|
||||
* Created 2014-08-01 for PlotSquared
|
||||
*
|
||||
* @author Empire92
|
||||
*/
|
||||
@CommandDeclaration(
|
||||
command = "move",
|
||||
description = "Move a plot",
|
||||
aliases = {"debugmove"},
|
||||
permission = "plots.move",
|
||||
category = CommandCategory.ACTIONS,
|
||||
requiredType = PlotPlayer.class
|
||||
)
|
||||
public class Move extends SubCommand {
|
||||
|
||||
public Move() {
|
||||
super(Command.MOVE, "Move a plot", "debugmove", CommandCategory.ACTIONS, true);
|
||||
requiredArguments = new Argument[] {
|
||||
Argument.PlotID
|
||||
};
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean execute(final PlotPlayer plr, final String... args) {
|
||||
if (args.length < 1) {
|
||||
MainUtil.sendMessage(plr, C.NEED_PLOT_ID);
|
||||
MainUtil.sendMessage(plr, C.COMMAND_SYNTAX, "/plot move <X;Z>");
|
||||
return false;
|
||||
}
|
||||
public boolean onCommand(final CommandCaller caller, final String[] args) {
|
||||
final PlotPlayer plr = (PlotPlayer) caller.getSuperCaller();
|
||||
final Location loc = plr.getLocation();
|
||||
final Plot plot1 = MainUtil.getPlot(loc);
|
||||
if (plot1 == null) {
|
||||
|
@ -31,14 +31,22 @@ import com.intellectualcrafters.plot.object.PlotItemStack;
|
||||
import com.intellectualcrafters.plot.object.PlotPlayer;
|
||||
import com.intellectualcrafters.plot.util.BlockManager;
|
||||
import com.intellectualcrafters.plot.util.MainUtil;
|
||||
import com.intellectualsites.commands.CommandDeclaration;
|
||||
import com.intellectualsites.commands.callers.CommandCaller;
|
||||
|
||||
@CommandDeclaration(
|
||||
command = "music",
|
||||
permission = "plots.music",
|
||||
description = "Player music in a plot",
|
||||
usage = "/plot music",
|
||||
category = CommandCategory.ACTIONS,
|
||||
requiredType = PlotPlayer.class
|
||||
)
|
||||
public class MusicSubcommand extends SubCommand {
|
||||
public MusicSubcommand() {
|
||||
super("music", "plots.music", "Play music in plot", "music", "mus", CommandCategory.ACTIONS, true);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean execute(final PlotPlayer player, final String... args) {
|
||||
public boolean onCommand(final CommandCaller caller, final String[] args) {
|
||||
final PlotPlayer player = (PlotPlayer) caller.getSuperCaller();
|
||||
final Location loc = player.getLocation();
|
||||
final Plot plot = MainUtil.getPlot(loc);
|
||||
if (plot == null) {
|
||||
|
@ -32,13 +32,18 @@ import com.intellectualcrafters.plot.object.Plot;
|
||||
import com.intellectualcrafters.plot.object.PlotId;
|
||||
import com.intellectualcrafters.plot.object.PlotPlayer;
|
||||
import com.intellectualcrafters.plot.util.MainUtil;
|
||||
import com.intellectualsites.commands.CommandDeclaration;
|
||||
import com.intellectualsites.commands.callers.CommandCaller;
|
||||
import com.plotsquared.bukkit.util.bukkit.UUIDHandler;
|
||||
|
||||
@SuppressWarnings({ "javadoc" })
|
||||
@CommandDeclaration(
|
||||
command = "purge",
|
||||
permission = "plots.admin",
|
||||
description = "Purge all plots for a world",
|
||||
category = CommandCategory.ACTIONS,
|
||||
requiredType = PS.class
|
||||
)
|
||||
public class Purge extends SubCommand {
|
||||
public Purge() {
|
||||
super("purge", "plots.admin", "Purge all plots for a world", "purge", "", CommandCategory.DEBUG, false);
|
||||
}
|
||||
|
||||
public PlotId getId(final String id) {
|
||||
try {
|
||||
@ -50,49 +55,45 @@ public class Purge extends SubCommand {
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean execute(final PlotPlayer plr, final String... args) {
|
||||
if (plr != null) {
|
||||
MainUtil.sendMessage(plr, (C.NOT_CONSOLE));
|
||||
return false;
|
||||
}
|
||||
public boolean onCommand(final CommandCaller caller, final String[] args) {
|
||||
if (args.length == 1) {
|
||||
final String arg = args[0].toLowerCase();
|
||||
final PlotId id = getId(arg);
|
||||
if (id != null) {
|
||||
MainUtil.sendMessage(plr, "/plot purge x;z &l<world>");
|
||||
caller.message("/plot purxe x;z &l<world>");
|
||||
return false;
|
||||
}
|
||||
final UUID uuid = UUIDHandler.getUUID(args[0]);
|
||||
if (uuid != null) {
|
||||
MainUtil.sendMessage(plr, "/plot purge " + args[0] + " &l<world>");
|
||||
caller.message("/plot purge " + args[0] + " &l<world>");
|
||||
return false;
|
||||
}
|
||||
if (arg.equals("player")) {
|
||||
MainUtil.sendMessage(plr, "/plot purge &l<player> <world>");
|
||||
caller.message("/plot purge &l<player> <world>");
|
||||
return false;
|
||||
}
|
||||
if (arg.equals("unowned")) {
|
||||
MainUtil.sendMessage(plr, "/plot purge unowned &l<world>");
|
||||
caller.message("/plot purge unowned &l<world>");
|
||||
return false;
|
||||
}
|
||||
if (arg.equals("unknown")) {
|
||||
MainUtil.sendMessage(plr, "/plot purge unknown &l<world>");
|
||||
caller.message("/plot purge unknown &l<world>");
|
||||
return false;
|
||||
}
|
||||
if (arg.equals("all")) {
|
||||
MainUtil.sendMessage(plr, "/plot purge all &l<world>");
|
||||
caller.message("/plot purge all &l<world>");
|
||||
return false;
|
||||
}
|
||||
MainUtil.sendMessage(plr, C.PURGE_SYNTAX);
|
||||
caller.message(C.PURGE_SYNTAX);
|
||||
return false;
|
||||
}
|
||||
if (args.length != 2) {
|
||||
MainUtil.sendMessage(plr, C.PURGE_SYNTAX);
|
||||
caller.message(C.PURGE_SYNTAX);
|
||||
return false;
|
||||
}
|
||||
final String worldname = args[1];
|
||||
if (!PS.get().getAllPlotsRaw().containsKey(worldname)) {
|
||||
MainUtil.sendMessage(plr, "INVALID WORLD");
|
||||
caller.message("INVALID WORLD");
|
||||
return false;
|
||||
}
|
||||
final String arg = args[0].toLowerCase();
|
||||
@ -159,7 +160,7 @@ public class Purge extends SubCommand {
|
||||
DBFunc.purge(worldname, ids);
|
||||
return finishPurge(length);
|
||||
}
|
||||
MainUtil.sendMessage(plr, C.PURGE_SYNTAX);
|
||||
caller.message(C.PURGE_SYNTAX);
|
||||
return false;
|
||||
}
|
||||
|
||||
|
@ -26,6 +26,8 @@ import java.util.Comparator;
|
||||
import java.util.Map.Entry;
|
||||
import java.util.UUID;
|
||||
|
||||
import com.intellectualsites.commands.CommandDeclaration;
|
||||
import com.intellectualsites.commands.callers.CommandCaller;
|
||||
import org.apache.commons.lang.StringUtils;
|
||||
import org.apache.commons.lang.mutable.MutableInt;
|
||||
import org.bukkit.Bukkit;
|
||||
@ -44,17 +46,21 @@ import com.intellectualcrafters.plot.object.Rating;
|
||||
import com.intellectualcrafters.plot.util.MainUtil;
|
||||
import com.intellectualcrafters.plot.util.TaskManager;
|
||||
|
||||
@CommandDeclaration(
|
||||
command = "rate",
|
||||
permission = "plots.rate",
|
||||
description = "Rate the plot",
|
||||
usage = "/plot rate [#|next]",
|
||||
aliases = {"rt"},
|
||||
category = CommandCategory.ACTIONS,
|
||||
requiredType = PlotPlayer.class
|
||||
)
|
||||
public class Rate extends SubCommand {
|
||||
/*
|
||||
* String cmd, String permission, String description, String usage, String
|
||||
* alias, CommandCategory category
|
||||
*/
|
||||
public Rate() {
|
||||
super("rate", "plots.rate", "Rate the plot", "rate [#|next]", "rt", CommandCategory.ACTIONS, true);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean execute(final PlotPlayer player, final String... args) {
|
||||
public boolean onCommand(final CommandCaller caller, final String[] args) {
|
||||
final PlotPlayer player = (PlotPlayer) caller.getSuperCaller();
|
||||
|
||||
if (args.length == 1) {
|
||||
if (args[0].equalsIgnoreCase("next")) {
|
||||
ArrayList<Plot> plots = new ArrayList<>(PS.get().getPlots());
|
||||
|
@ -30,37 +30,43 @@ import com.intellectualcrafters.plot.object.ChunkLoc;
|
||||
import com.intellectualcrafters.plot.object.PlotManager;
|
||||
import com.intellectualcrafters.plot.object.PlotPlayer;
|
||||
import com.intellectualcrafters.plot.util.ChunkManager;
|
||||
import com.intellectualsites.commands.Argument;
|
||||
import com.intellectualsites.commands.CommandDeclaration;
|
||||
import com.intellectualsites.commands.callers.CommandCaller;
|
||||
|
||||
@CommandDeclaration(
|
||||
command = "regenallroads",
|
||||
description = "Regenerate all roads in the map using the set road schematic",
|
||||
aliases = {"rgar"},
|
||||
category = CommandCategory.DEBUG,
|
||||
requiredType = PS.class,
|
||||
permission = "plots.regenallroads"
|
||||
)
|
||||
public class RegenAllRoads extends SubCommand {
|
||||
|
||||
public RegenAllRoads() {
|
||||
super(Command.REGENALLROADS, "Regenerate all roads in the map using the set road schematic", "rgar", CommandCategory.DEBUG, false);
|
||||
requiredArguments = new Argument[] {
|
||||
Argument.String
|
||||
};
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean execute(final PlotPlayer player, final String... args) {
|
||||
if (player != null) {
|
||||
sendMessage(player, C.NOT_CONSOLE);
|
||||
return false;
|
||||
}
|
||||
if (args.length < 1) {
|
||||
sendMessage(player, C.NEED_PLOT_WORLD);
|
||||
return false;
|
||||
}
|
||||
public boolean onCommand(final CommandCaller caller, final String[] args) {
|
||||
int height = 0;
|
||||
if (args.length == 2) {
|
||||
try {
|
||||
height = Integer.parseInt(args[1]);
|
||||
}
|
||||
catch (NumberFormatException e) {
|
||||
sendMessage(player, C.NOT_VALID_NUMBER, "(0, 256)");
|
||||
sendMessage(player, C.COMMAND_SYNTAX, "/plot regenallroads <world> [height]");
|
||||
caller.message(C.NOT_VALID_NUMBER, "(0, 256)");
|
||||
caller.message(C.COMMAND_SYNTAX, "/plot regenallroads <world> [height]");
|
||||
return false;
|
||||
}
|
||||
}
|
||||
final String name = args[0];
|
||||
final PlotManager manager = PS.get().getPlotManager(name);
|
||||
if ((manager == null) || !(manager instanceof HybridPlotManager)) {
|
||||
sendMessage(player, C.NOT_VALID_PLOT_WORLD);
|
||||
caller.message(C.NOT_VALID_PLOT_WORLD);
|
||||
return false;
|
||||
}
|
||||
final List<ChunkLoc> chunks = ChunkManager.manager.getChunkChunks(name);
|
||||
|
@ -22,17 +22,22 @@ package com.intellectualcrafters.plot.commands;
|
||||
|
||||
import com.intellectualcrafters.plot.PS;
|
||||
import com.intellectualcrafters.plot.config.C;
|
||||
import com.intellectualcrafters.plot.object.PlotPlayer;
|
||||
import com.intellectualcrafters.plot.object.PlotWorld;
|
||||
import com.intellectualcrafters.plot.util.MainUtil;
|
||||
|
||||
import com.intellectualsites.commands.CommandDeclaration;
|
||||
import com.intellectualsites.commands.callers.CommandCaller;
|
||||
|
||||
@CommandDeclaration(
|
||||
command = "reload",
|
||||
permission = "plots.admin.command.reload",
|
||||
description = "Reload configurations",
|
||||
usage = "/plot reload",
|
||||
category = CommandCategory.INFO
|
||||
)
|
||||
public class Reload extends SubCommand {
|
||||
public Reload() {
|
||||
super("reload", "plots.admin.command.reload", "Reload configurations", "reload", CommandCategory.INFO, false);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean execute(final PlotPlayer plr, final String... args) {
|
||||
public boolean onCommand(final CommandCaller caller, final String[] args) {
|
||||
try {
|
||||
// The following won't affect world generation, as that has to be
|
||||
// loaded during startup unfortunately.
|
||||
@ -43,9 +48,9 @@ public class Reload extends SubCommand {
|
||||
final PlotWorld plotworld = PS.get().getPlotWorld(pw);
|
||||
plotworld.loadDefaultConfiguration(PS.get().config.getConfigurationSection("worlds." + pw));
|
||||
}
|
||||
MainUtil.sendMessage(plr, C.RELOADED_CONFIGS);
|
||||
caller.message(C.RELOADED_CONFIGS);
|
||||
} catch (final Exception e) {
|
||||
MainUtil.sendMessage(plr, C.RELOAD_FAILED);
|
||||
caller.message(C.RELOAD_FAILED);
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
@ -30,16 +30,32 @@ 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.intellectualsites.commands.Argument;
|
||||
import com.intellectualsites.commands.CommandDeclaration;
|
||||
import com.intellectualsites.commands.callers.CommandCaller;
|
||||
import com.plotsquared.bukkit.util.bukkit.UUIDHandler;
|
||||
import com.plotsquared.bukkit.util.bukkit.uuid.SQLUUIDHandler;
|
||||
|
||||
@CommandDeclaration(
|
||||
command = "remove",
|
||||
aliases = {"r"},
|
||||
description = "Remove a player from a plot",
|
||||
usage = "/plot remove <player>",
|
||||
category = CommandCategory.ACTIONS,
|
||||
requiredType = PlotPlayer.class,
|
||||
permission = "plots.remove"
|
||||
)
|
||||
public class Remove extends SubCommand {
|
||||
|
||||
public Remove() {
|
||||
super(Command.REMOVE, "Remove a player from a plot", "remove <player>", CommandCategory.ACTIONS, true);
|
||||
requiredArguments = new Argument[] {
|
||||
Argument.PlayerName
|
||||
};
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean execute(final PlotPlayer plr, final String... args) {
|
||||
public boolean onCommand(final CommandCaller caller, final String[] args) {
|
||||
PlotPlayer plr = (PlotPlayer) caller.getSuperCaller();
|
||||
if (args.length != 1) {
|
||||
MainUtil.sendMessage(plr, C.COMMAND_SYNTAX, "/plot remove <player>");
|
||||
return true;
|
||||
@ -58,59 +74,61 @@ public class Remove extends SubCommand {
|
||||
return true;
|
||||
}
|
||||
int count = 0;
|
||||
if (args[0].equals("unknown")) {
|
||||
ArrayList<UUID> toRemove = new ArrayList<>();
|
||||
HashSet<UUID> all = new HashSet<>();
|
||||
all.addAll(plot.getMembers());
|
||||
all.addAll(plot.getTrusted());
|
||||
all.addAll(plot.getDenied());
|
||||
for (UUID uuid : all) {
|
||||
if (UUIDHandler.getName(uuid) == null) {
|
||||
switch (args[0]) {
|
||||
case "unknown": {
|
||||
ArrayList<UUID> toRemove = new ArrayList<>();
|
||||
HashSet<UUID> all = new HashSet<>();
|
||||
all.addAll(plot.getMembers());
|
||||
all.addAll(plot.getTrusted());
|
||||
all.addAll(plot.getDenied());
|
||||
for (UUID uuid : all) {
|
||||
if (UUIDHandler.getName(uuid) == null) {
|
||||
toRemove.add(uuid);
|
||||
count++;
|
||||
}
|
||||
}
|
||||
for (UUID uuid : toRemove) {
|
||||
plot.removeDenied(uuid);
|
||||
plot.removeTrusted(uuid);
|
||||
plot.removeMember(uuid);
|
||||
}
|
||||
break;
|
||||
}
|
||||
case "*": {
|
||||
ArrayList<UUID> toRemove = new ArrayList<>();
|
||||
HashSet<UUID> all = new HashSet<>();
|
||||
all.addAll(plot.getMembers());
|
||||
all.addAll(plot.getTrusted());
|
||||
all.addAll(plot.getDenied());
|
||||
for (UUID uuid : all) {
|
||||
toRemove.add(uuid);
|
||||
count++;
|
||||
}
|
||||
for (UUID uuid : toRemove) {
|
||||
plot.removeDenied(uuid);
|
||||
plot.removeTrusted(uuid);
|
||||
plot.removeMember(uuid);
|
||||
}
|
||||
break;
|
||||
}
|
||||
for (UUID uuid : toRemove) {
|
||||
plot.removeDenied(uuid);
|
||||
plot.removeTrusted(uuid);
|
||||
plot.removeMember(uuid);
|
||||
}
|
||||
}
|
||||
else if (args[0].equals("*")){
|
||||
ArrayList<UUID> toRemove = new ArrayList<>();
|
||||
HashSet<UUID> all = new HashSet<>();
|
||||
all.addAll(plot.getMembers());
|
||||
all.addAll(plot.getTrusted());
|
||||
all.addAll(plot.getDenied());
|
||||
for (UUID uuid : all) {
|
||||
toRemove.add(uuid);
|
||||
count++;
|
||||
}
|
||||
for (UUID uuid : toRemove) {
|
||||
plot.removeDenied(uuid);
|
||||
plot.removeTrusted(uuid);
|
||||
plot.removeMember(uuid);
|
||||
}
|
||||
}
|
||||
else {
|
||||
UUID uuid = UUIDHandler.getUUID(args[0]);
|
||||
if (uuid != null) {
|
||||
if (plot.getTrusted().contains(uuid)) {
|
||||
if (plot.removeTrusted(uuid)) {
|
||||
count++;
|
||||
default:
|
||||
UUID uuid = UUIDHandler.getUUID(args[0]);
|
||||
if (uuid != null) {
|
||||
if (plot.getTrusted().contains(uuid)) {
|
||||
if (plot.removeTrusted(uuid)) {
|
||||
count++;
|
||||
}
|
||||
} else if (plot.getMembers().contains(uuid)) {
|
||||
if (plot.removeMember(uuid)) {
|
||||
count++;
|
||||
}
|
||||
} else if (plot.getDenied().contains(uuid)) {
|
||||
if (plot.removeDenied(uuid)) {
|
||||
count++;
|
||||
}
|
||||
}
|
||||
}
|
||||
else if (plot.getMembers().contains(uuid)) {
|
||||
if (plot.removeMember(uuid)) {
|
||||
count++;
|
||||
}
|
||||
}
|
||||
else if (plot.getDenied().contains(uuid)) {
|
||||
if (plot.removeDenied(uuid)) {
|
||||
count++;
|
||||
}
|
||||
}
|
||||
}
|
||||
break;
|
||||
}
|
||||
if (count == 0) {
|
||||
if (UUIDHandler.implementation instanceof SQLUUIDHandler) {
|
||||
|
@ -16,14 +16,22 @@ import com.intellectualcrafters.plot.util.MainUtil;
|
||||
import com.intellectualcrafters.plot.util.Permissions;
|
||||
import com.intellectualcrafters.plot.util.SchematicHandler;
|
||||
import com.intellectualcrafters.plot.util.TaskManager;
|
||||
import com.intellectualsites.commands.CommandDeclaration;
|
||||
import com.intellectualsites.commands.callers.CommandCaller;
|
||||
|
||||
@CommandDeclaration(
|
||||
command = "save",
|
||||
aliases = {"backup"},
|
||||
description = "Save your plot",
|
||||
category = CommandCategory.ACTIONS,
|
||||
requiredType = PlotPlayer.class,
|
||||
permission = "plots.save"
|
||||
)
|
||||
public class Save extends SubCommand {
|
||||
public Save() {
|
||||
super(Command.SAVE, "Save your plot", "backup", CommandCategory.ACTIONS, true);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean execute(final PlotPlayer plr, String... args) {
|
||||
public boolean onCommand(final CommandCaller caller, final String[] args) {
|
||||
final PlotPlayer plr = (PlotPlayer) caller.getSuperCaller();
|
||||
if (!Settings.METRICS) {
|
||||
MainUtil.sendMessage(plr, "&cPlease enable metrics in order to use this command.\n&7 - Or host it yourself if you don't like the free service");
|
||||
return false;
|
||||
|
@ -33,24 +33,35 @@ import com.intellectualcrafters.plot.object.PlotId;
|
||||
import com.intellectualcrafters.plot.object.PlotPlayer;
|
||||
import com.intellectualcrafters.plot.util.MainUtil;
|
||||
import com.intellectualcrafters.plot.util.Permissions;
|
||||
import com.intellectualsites.commands.Argument;
|
||||
import com.intellectualsites.commands.CommandDeclaration;
|
||||
import com.intellectualsites.commands.callers.CommandCaller;
|
||||
import com.plotsquared.bukkit.util.bukkit.UUIDHandler;
|
||||
|
||||
@CommandDeclaration(
|
||||
command = "setowner",
|
||||
permission = "plots.set.owner",
|
||||
description = "Set the plot owner",
|
||||
usage = "/plot setowner <player>",
|
||||
aliases = {"so"},
|
||||
category = CommandCategory.ACTIONS,
|
||||
requiredType = PlotPlayer.class
|
||||
)
|
||||
public class SetOwner extends SubCommand {
|
||||
|
||||
public SetOwner() {
|
||||
super("setowner", "plots.set.owner", "Set the plot owner", "setowner <player>", "so", CommandCategory.ACTIONS, true);
|
||||
requiredArguments = new Argument[] {
|
||||
Argument.PlayerName
|
||||
};
|
||||
}
|
||||
|
||||
/*
|
||||
* private UUID getUUID(String string) { OfflinePlayer player =
|
||||
* Bukkit.getOfflinePlayer(string); return ((player != null) &&
|
||||
* player.hasPlayedBefore()) ? UUIDHandler.getUUID(player) : null; }
|
||||
*/
|
||||
private UUID getUUID(final String string) {
|
||||
return UUIDHandler.getUUID(string);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean execute(final PlotPlayer plr, final String... args) {
|
||||
public boolean onCommand(final CommandCaller caller, final String[] args) {
|
||||
final PlotPlayer plr = (PlotPlayer) caller;
|
||||
final Location loc = plr.getLocation();
|
||||
final Plot plot = MainUtil.getPlot(loc);
|
||||
if ((plot == null) || (plot.owner == null)) {
|
||||
|
@ -25,6 +25,9 @@ import java.util.Arrays;
|
||||
import java.util.List;
|
||||
import java.util.Map.Entry;
|
||||
|
||||
import com.intellectualcrafters.plot.commands.callers.PlotPlayerCaller;
|
||||
import com.intellectualsites.commands.CommandDeclaration;
|
||||
import com.intellectualsites.commands.callers.CommandCaller;
|
||||
import org.apache.commons.lang.StringUtils;
|
||||
import org.bukkit.generator.ChunkGenerator;
|
||||
|
||||
@ -39,10 +42,15 @@ import com.intellectualcrafters.plot.util.BlockManager;
|
||||
import com.intellectualcrafters.plot.util.MainUtil;
|
||||
import com.plotsquared.bukkit.util.SetupUtils;
|
||||
|
||||
@CommandDeclaration(
|
||||
command = "setup",
|
||||
permission = "plots.admin.command.setup",
|
||||
description = "Setup wizard for plot worlds",
|
||||
usage = "/plot setup",
|
||||
aliases = {"create"},
|
||||
category = CommandCategory.ACTIONS
|
||||
)
|
||||
public class Setup extends SubCommand {
|
||||
public Setup() {
|
||||
super("setup", "plots.admin.command.setup", "Plotworld setup command", "setup", "create", CommandCategory.ACTIONS, false);
|
||||
}
|
||||
|
||||
public void displayGenerators(PlotPlayer plr) {
|
||||
StringBuffer message = new StringBuffer();
|
||||
@ -65,7 +73,9 @@ public class Setup extends SubCommand {
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean execute(final PlotPlayer plr, final String... args) {
|
||||
public boolean onCommand(final CommandCaller caller, final String[] args) {
|
||||
PlotPlayer plr = (caller instanceof PlotPlayerCaller) ? (PlotPlayer) caller.getSuperCaller() : null;
|
||||
|
||||
// going through setup
|
||||
String name;
|
||||
if (plr == null) {
|
||||
@ -208,7 +218,7 @@ public class Setup extends SubCommand {
|
||||
step.setValue(args[0]);
|
||||
object.setup_index++;
|
||||
if (object.setup_index == object.step.length) {
|
||||
execute(plr, args);
|
||||
onCommand(caller, args);
|
||||
return false;
|
||||
}
|
||||
step = object.step[object.setup_index];
|
||||
|
@ -20,9 +20,6 @@
|
||||
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
package com.intellectualcrafters.plot.commands;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
|
||||
import com.intellectualcrafters.plot.config.C;
|
||||
import com.intellectualcrafters.plot.object.PlotPlayer;
|
||||
import com.intellectualcrafters.plot.util.MainUtil;
|
||||
@ -33,109 +30,12 @@ import com.intellectualcrafters.plot.util.MainUtil;
|
||||
* @author Citymonstret
|
||||
*/
|
||||
@SuppressWarnings({ "deprecation", "unused" })
|
||||
public abstract class SubCommand {
|
||||
/**
|
||||
* Command
|
||||
*/
|
||||
public final String cmd;
|
||||
/**
|
||||
* Permission node
|
||||
*/
|
||||
public final CommandPermission permission;
|
||||
/**
|
||||
* Simple description
|
||||
*/
|
||||
public final String description;
|
||||
/**
|
||||
* Aliases
|
||||
*/
|
||||
public final ArrayList<String> alias;
|
||||
/**
|
||||
* Command usage
|
||||
*/
|
||||
public final String usage;
|
||||
public abstract class SubCommand extends com.intellectualsites.commands.Command {
|
||||
|
||||
/**
|
||||
* The category
|
||||
*/
|
||||
public final CommandCategory category;
|
||||
/**
|
||||
* Is this a player-online command?
|
||||
*/
|
||||
public final boolean isPlayer;
|
||||
|
||||
/**
|
||||
* @param cmd Command /plot {cmd} <-- That!
|
||||
* @param permission Permission Node
|
||||
* @param description Simple description
|
||||
* @param usage Usage description: /plot command {args...}
|
||||
* @param alias Command alias
|
||||
* @param category CommandCategory. Pick whichever is closest to what you want.
|
||||
*/
|
||||
public SubCommand(final String cmd, final String permission, final String description, final String usage, final String alias, final CommandCategory category, final boolean isPlayer) {
|
||||
this.cmd = cmd;
|
||||
this.permission = new CommandPermission(permission);
|
||||
this.description = description;
|
||||
this.alias = new ArrayList<String>();
|
||||
this.alias.add(alias);
|
||||
this.usage = usage;
|
||||
this.category = category;
|
||||
this.isPlayer = isPlayer;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param cmd Command /plot {cmd} <-- That!
|
||||
* @param permission Permission Node
|
||||
* @param description Simple description
|
||||
* @param usage Usage description: /plot command {args...}
|
||||
* @param aliases Command aliases
|
||||
* @param category CommandCategory. Pick whichever is closest to what you want.
|
||||
*/
|
||||
public SubCommand(final String cmd, final String permission, final String description, final String usage, final CommandCategory category, final boolean isPlayer, final String... aliases) {
|
||||
this.cmd = cmd;
|
||||
this.permission = new CommandPermission(permission);
|
||||
this.description = description;
|
||||
this.alias = new ArrayList<String>();
|
||||
this.alias.addAll(Arrays.asList(aliases));
|
||||
this.usage = usage;
|
||||
this.category = category;
|
||||
this.isPlayer = isPlayer;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param command Command /plot {cmd} <-- That!
|
||||
* @param description Simple description
|
||||
* @param usage Usage description: /plot command {args...}
|
||||
* @param category CommandCategory. Pick whichever closests to what you want.
|
||||
*/
|
||||
public SubCommand(final Command command, final String description, final String usage, final CommandCategory category, final boolean isPlayer) {
|
||||
this.cmd = command.getCommand();
|
||||
this.permission = command.getPermission();
|
||||
this.alias = new ArrayList<String>();
|
||||
this.alias.add(command.getAlias());
|
||||
this.description = description;
|
||||
this.usage = usage;
|
||||
this.category = category;
|
||||
this.isPlayer = isPlayer;
|
||||
}
|
||||
|
||||
/**
|
||||
* Execute.
|
||||
*
|
||||
* @param plr executor
|
||||
* @param args arguments
|
||||
*
|
||||
* @return true on success, false on failure
|
||||
*/
|
||||
public abstract boolean execute(final PlotPlayer plr, final String... args);
|
||||
|
||||
/**
|
||||
* Execute the command as console
|
||||
*
|
||||
* @param args Arguments
|
||||
*/
|
||||
public void executeConsole(final String... args) {
|
||||
this.execute(null, args);
|
||||
}
|
||||
public CommandCategory category;
|
||||
|
||||
/**
|
||||
* Send a message
|
||||
@ -151,60 +51,4 @@ public abstract class SubCommand {
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* CommandCategory
|
||||
*
|
||||
* @author Citymonstret
|
||||
* @author Empire92
|
||||
*/
|
||||
public enum CommandCategory {
|
||||
/**
|
||||
* Claiming Commands
|
||||
*
|
||||
* Such as: /plot claim
|
||||
*/
|
||||
CLAIMING("Claiming"),
|
||||
/**
|
||||
* Teleportation Commands
|
||||
*
|
||||
* Such as: /plot visit
|
||||
*/
|
||||
TELEPORT("Teleportation"),
|
||||
/**
|
||||
* Action Commands
|
||||
*
|
||||
* Such as: /plot clear
|
||||
*/
|
||||
ACTIONS("Actions"),
|
||||
/**
|
||||
* Information Commands
|
||||
*
|
||||
* Such as: /plot info
|
||||
*/
|
||||
INFO("Information"),
|
||||
/**
|
||||
* Debug Commands
|
||||
*
|
||||
* Such as: /plot debug
|
||||
*/
|
||||
DEBUG("Debug");
|
||||
/**
|
||||
* The category name (Readable)
|
||||
*/
|
||||
private final String name;
|
||||
|
||||
/**
|
||||
* Constructor
|
||||
*
|
||||
* @param name readable name
|
||||
*/
|
||||
CommandCategory(final String name) {
|
||||
this.name = name;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return this.name;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -33,19 +33,21 @@ import com.intellectualcrafters.plot.util.ChunkManager;
|
||||
import com.intellectualcrafters.plot.util.ClusterManager;
|
||||
import com.intellectualcrafters.plot.util.MainUtil;
|
||||
import com.intellectualcrafters.plot.util.Permissions;
|
||||
import com.intellectualsites.commands.CommandDeclaration;
|
||||
import com.intellectualsites.commands.callers.CommandCaller;
|
||||
|
||||
/**
|
||||
* Created 2014-08-01 for PlotSquared
|
||||
*
|
||||
* @author Empire92
|
||||
*/
|
||||
@CommandDeclaration(
|
||||
command = "swap",
|
||||
description = "Swap two plots",
|
||||
aliases = {"switch"},
|
||||
category = CommandCategory.ACTIONS,
|
||||
requiredType = PlotPlayer.class
|
||||
)
|
||||
public class Swap extends SubCommand {
|
||||
public Swap() {
|
||||
super(Command.SWAP, "Swap two plots", "switch", CommandCategory.ACTIONS, true);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean execute(final PlotPlayer plr, final String... args) {
|
||||
public boolean onCommand(final CommandCaller caller, final String[] args) {
|
||||
final PlotPlayer plr = (PlotPlayer) caller.getSuperCaller();
|
||||
MainUtil.sendMessage(plr, "&cThis command has not been optimized for large selections yet. Please bug me if this becomes an issue.");
|
||||
if (args.length < 1) {
|
||||
MainUtil.sendMessage(plr, C.NEED_PLOT_ID);
|
||||
@ -57,7 +59,7 @@ public class Swap extends SubCommand {
|
||||
if (plot == null) {
|
||||
return !sendMessage(plr, C.NOT_IN_PLOT);
|
||||
}
|
||||
if (((plot == null) || !plot.hasOwner() || !plot.isOwner(plr.getUUID())) && !Permissions.hasPermission(plr, "plots.admin.command.swap")) {
|
||||
if ((!plot.hasOwner() || !plot.isOwner(plr.getUUID())) && !Permissions.hasPermission(plr, "plots.admin.command.swap")) {
|
||||
MainUtil.sendMessage(plr, C.NO_PLOT_PERMS);
|
||||
return false;
|
||||
}
|
||||
|
@ -20,6 +20,9 @@
|
||||
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
package com.intellectualcrafters.plot.commands;
|
||||
|
||||
import com.intellectualsites.commands.Argument;
|
||||
import com.intellectualsites.commands.CommandDeclaration;
|
||||
import com.intellectualsites.commands.callers.CommandCaller;
|
||||
import org.apache.commons.lang.StringUtils;
|
||||
|
||||
import com.intellectualcrafters.plot.PS;
|
||||
@ -32,20 +35,25 @@ import com.intellectualcrafters.plot.util.BlockManager;
|
||||
import com.intellectualcrafters.plot.util.MainUtil;
|
||||
import com.plotsquared.bukkit.util.bukkit.UUIDHandler;
|
||||
|
||||
/**
|
||||
* @author Citymonstret
|
||||
*/
|
||||
@CommandDeclaration(
|
||||
command = "tp",
|
||||
description = "Teleport to a plot",
|
||||
permission = "plots.tp",
|
||||
usage = "/plot tp <alias|id>",
|
||||
requiredType = PlotPlayer.class,
|
||||
category = CommandCategory.TELEPORT
|
||||
)
|
||||
public class TP extends SubCommand {
|
||||
|
||||
public TP() {
|
||||
super(Command.TP, "Teleport to a plot", "tp {alias|id}", CommandCategory.TELEPORT, true);
|
||||
requiredArguments = new Argument[] {
|
||||
Argument.String
|
||||
};
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean execute(final PlotPlayer plr, final String... args) {
|
||||
if (args.length < 1) {
|
||||
MainUtil.sendMessage(plr, C.NEED_PLOT_ID);
|
||||
return false;
|
||||
}
|
||||
public boolean onCommand(final CommandCaller caller, final String[] args) {
|
||||
PlotPlayer plr = (PlotPlayer) caller.getSuperCaller();
|
||||
final String id = args[0];
|
||||
PlotId plotid;
|
||||
final Location loc = plr.getLocation();
|
||||
|
@ -26,31 +26,42 @@ import com.intellectualcrafters.plot.object.Location;
|
||||
import com.intellectualcrafters.plot.object.PlotId;
|
||||
import com.intellectualcrafters.plot.object.PlotPlayer;
|
||||
import com.intellectualcrafters.plot.util.MainUtil;
|
||||
import com.intellectualsites.commands.Argument;
|
||||
import com.intellectualsites.commands.CommandDeclaration;
|
||||
import com.intellectualsites.commands.callers.CommandCaller;
|
||||
|
||||
@CommandDeclaration(
|
||||
command = "target",
|
||||
usage = "/plot target <X;Z>",
|
||||
description = "Target a plot with your compass",
|
||||
permission = "plots.target",
|
||||
requiredType = PlotPlayer.class,
|
||||
category = CommandCategory.ACTIONS
|
||||
)
|
||||
public class Target extends SubCommand {
|
||||
|
||||
public Target() {
|
||||
super(Command.TARGET, "Target a plot with your compass", "target <X;Z>", CommandCategory.ACTIONS, true);
|
||||
requiredArguments = new Argument[] {
|
||||
Argument.PlotID
|
||||
};
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean execute(final PlotPlayer plr, final String... args) {
|
||||
public boolean onCommand(final CommandCaller caller, final String[] args) {
|
||||
PlotPlayer plr = (PlotPlayer) caller.getSuperCaller();
|
||||
final Location ploc = plr.getLocation();
|
||||
if (!PS.get().isPlotWorld(ploc.getWorld())) {
|
||||
MainUtil.sendMessage(plr, C.NOT_IN_PLOT_WORLD);
|
||||
return false;
|
||||
}
|
||||
if (args.length == 1) {
|
||||
final PlotId id = MainUtil.parseId(args[0]);
|
||||
if (id == null) {
|
||||
MainUtil.sendMessage(plr, C.NOT_VALID_PLOT_ID);
|
||||
return false;
|
||||
}
|
||||
final Location loc = MainUtil.getPlotHome(ploc.getWorld(), id);
|
||||
plr.setCompassTarget(loc);
|
||||
MainUtil.sendMessage(plr, C.COMPASS_TARGET);
|
||||
return true;
|
||||
final PlotId id = MainUtil.parseId(args[0]);
|
||||
if (id == null) {
|
||||
MainUtil.sendMessage(plr, C.NOT_VALID_PLOT_ID);
|
||||
return false;
|
||||
}
|
||||
MainUtil.sendMessage(plr, C.COMMAND_SYNTAX, "/plot target <X;Z>");
|
||||
return false;
|
||||
final Location loc = MainUtil.getPlotHome(ploc.getWorld(), id);
|
||||
plr.setCompassTarget(loc);
|
||||
MainUtil.sendMessage(plr, C.COMPASS_TARGET);
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
@ -41,13 +41,19 @@ import com.intellectualcrafters.plot.object.PlotWorld;
|
||||
import com.intellectualcrafters.plot.object.SetupObject;
|
||||
import com.intellectualcrafters.plot.util.BlockManager;
|
||||
import com.intellectualcrafters.plot.util.MainUtil;
|
||||
import com.intellectualsites.commands.CommandDeclaration;
|
||||
import com.intellectualsites.commands.callers.CommandCaller;
|
||||
import com.plotsquared.bukkit.util.SetupUtils;
|
||||
import com.intellectualcrafters.plot.util.TaskManager;
|
||||
|
||||
@CommandDeclaration(
|
||||
command = "template",
|
||||
permission = "plots.admin",
|
||||
description = "Create or use a world template",
|
||||
usage = "/plot template [import|export] <world> <template>",
|
||||
category = CommandCategory.DEBUG
|
||||
)
|
||||
public class Template extends SubCommand {
|
||||
public Template() {
|
||||
super("template", "plots.admin", "Create or use a world template", "template", "", CommandCategory.DEBUG, false);
|
||||
}
|
||||
|
||||
public static boolean extractAllFiles(String world, String template) {
|
||||
byte[] buffer = new byte[2048];
|
||||
@ -113,20 +119,24 @@ public class Template extends SubCommand {
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean execute(final PlotPlayer plr, final String... args) {
|
||||
public boolean onCommand(final CommandCaller caller, final String[] args) {
|
||||
if (args.length != 2 && args.length != 3) {
|
||||
if (args.length == 1) {
|
||||
if (args[0].equalsIgnoreCase("export")) {
|
||||
MainUtil.sendMessage(plr, C.COMMAND_SYNTAX, "/plot template export <world>");
|
||||
return false;
|
||||
caller.message(C.COMMAND_SYNTAX, "/plot template export <world>");
|
||||
return true;
|
||||
}
|
||||
else if (args[0].equalsIgnoreCase("import")) {
|
||||
MainUtil.sendMessage(plr, C.COMMAND_SYNTAX, "/plot template import <world> <template>");
|
||||
return false;
|
||||
caller.message(C.COMMAND_SYNTAX, "/plot template import <world> <template>");
|
||||
return true;
|
||||
}
|
||||
}
|
||||
MainUtil.sendMessage(plr, C.COMMAND_SYNTAX, "/plot template <import|export> <world> [template]");
|
||||
return false;
|
||||
caller.message(C.COMMAND_SYNTAX, "/plot template <import|explort> <world> [template]");
|
||||
return true;
|
||||
}
|
||||
PlotPlayer plr = null;
|
||||
if (caller.getSuperCaller() instanceof PlotPlayer) {
|
||||
plr = (PlotPlayer) caller.getSuperCaller();
|
||||
}
|
||||
final String world = args[1];
|
||||
switch (args[0].toLowerCase()) {
|
||||
@ -190,6 +200,7 @@ public class Template extends SubCommand {
|
||||
return false;
|
||||
}
|
||||
final PlotManager manager = PS.get().getPlotManager(world);
|
||||
final PlotPlayer finalPlr = plr;
|
||||
TaskManager.runTaskAsync(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
@ -198,10 +209,10 @@ public class Template extends SubCommand {
|
||||
}
|
||||
catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
MainUtil.sendMessage(plr, "Failed: " + e.getMessage());
|
||||
MainUtil.sendMessage(finalPlr, "Failed: " + e.getMessage());
|
||||
return;
|
||||
}
|
||||
MainUtil.sendMessage(plr, "Done!");
|
||||
MainUtil.sendMessage(finalPlr, "Done!");
|
||||
}
|
||||
});
|
||||
return true;
|
||||
|
@ -23,21 +23,32 @@ package com.intellectualcrafters.plot.commands;
|
||||
import com.intellectualcrafters.plot.config.C;
|
||||
import com.intellectualcrafters.plot.object.PlotPlayer;
|
||||
import com.intellectualcrafters.plot.util.MainUtil;
|
||||
import com.intellectualsites.commands.CommandDeclaration;
|
||||
import com.intellectualsites.commands.callers.CommandCaller;
|
||||
|
||||
// TOGGLE("toggle", "attribute"),
|
||||
|
||||
@CommandDeclaration(
|
||||
command = "toggle",
|
||||
aliases = {"attribute"},
|
||||
permission = "plots.toggle",
|
||||
description = "Toggle per user settings",
|
||||
usage = "/plot toggle <setting>",
|
||||
requiredType = PlotPlayer.class,
|
||||
category = CommandCategory.ACTIONS
|
||||
)
|
||||
public class Toggle extends SubCommand {
|
||||
public Toggle() {
|
||||
super(Command.TOGGLE, "Toggle per user settings", "toggle <setting>", CommandCategory.ACTIONS, true);
|
||||
}
|
||||
|
||||
public void noArgs(PlotPlayer player) {
|
||||
MainUtil.sendMessage(player, C.COMMAND_SYNTAX, "/plot toggle <setting>");
|
||||
MainUtil.sendMessage(player, C.SUBCOMMAND_SET_OPTIONS_HEADER.s() + "titles");
|
||||
public void noArgs(CommandCaller caller) {
|
||||
caller.message(C.COMMAND_SYNTAX, "/plot toggle <setting>");
|
||||
caller.message(C.SUBCOMMAND_SET_OPTIONS_HEADER.s() + "titles");
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean execute(final PlotPlayer player, final String... args) {
|
||||
public boolean onCommand(final CommandCaller caller, final String[] args) {
|
||||
PlotPlayer player = (PlotPlayer) caller.getSuperCaller();
|
||||
if (args.length == 0) {
|
||||
noArgs(player);
|
||||
noArgs(caller);
|
||||
return false;
|
||||
}
|
||||
switch (args[0].toLowerCase()) {
|
||||
|
@ -39,16 +39,23 @@ import com.intellectualcrafters.plot.util.BlockManager;
|
||||
import com.intellectualcrafters.plot.util.ChunkManager;
|
||||
import com.intellectualcrafters.plot.util.MainUtil;
|
||||
import com.intellectualcrafters.plot.util.TaskManager;
|
||||
import com.intellectualsites.commands.CommandDeclaration;
|
||||
import com.intellectualsites.commands.callers.CommandCaller;
|
||||
|
||||
@CommandDeclaration(
|
||||
command = "trim",
|
||||
permission = "plots.admin",
|
||||
description = "Delete unmodified portions of your plotworld",
|
||||
usage = "/plot trim",
|
||||
requiredType = PS.class,
|
||||
category = CommandCategory.DEBUG
|
||||
)
|
||||
public class Trim extends SubCommand {
|
||||
|
||||
public static boolean TASK = false;
|
||||
public static ArrayList<Plot> expired = null;
|
||||
private static int TASK_ID = 0;
|
||||
|
||||
public Trim() {
|
||||
super("trim", "plots.admin", "Delete unmodified portions of your plotworld", "trim", "", CommandCategory.DEBUG, false);
|
||||
}
|
||||
|
||||
public static boolean getBulkRegions(final ArrayList<ChunkLoc> empty, final String world, final Runnable whenDone) {
|
||||
if (Trim.TASK) {
|
||||
return false;
|
||||
@ -167,11 +174,8 @@ public class Trim extends SubCommand {
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean execute(final PlotPlayer plr, final String... args) {
|
||||
if (plr != null) {
|
||||
MainUtil.sendMessage(plr, (C.NOT_CONSOLE));
|
||||
return false;
|
||||
}
|
||||
public boolean onCommand(final CommandCaller caller, final String[] args) {
|
||||
PlotPlayer plr = null;
|
||||
if (args.length == 1) {
|
||||
final String arg = args[0].toLowerCase();
|
||||
final PlotId id = getId(arg);
|
||||
|
@ -31,26 +31,37 @@ import com.intellectualcrafters.plot.object.PlotPlayer;
|
||||
import com.intellectualcrafters.plot.util.EventUtil;
|
||||
import com.intellectualcrafters.plot.util.MainUtil;
|
||||
import com.intellectualcrafters.plot.util.Permissions;
|
||||
import com.intellectualsites.commands.Argument;
|
||||
import com.intellectualsites.commands.CommandDeclaration;
|
||||
import com.intellectualsites.commands.callers.CommandCaller;
|
||||
import com.plotsquared.bukkit.util.bukkit.UUIDHandler;
|
||||
import com.plotsquared.bukkit.util.bukkit.uuid.SQLUUIDHandler;
|
||||
|
||||
@CommandDeclaration(
|
||||
command = "trust",
|
||||
aliases = {"t"},
|
||||
requiredType = PlotPlayer.class,
|
||||
usage = "/plot trust <player>",
|
||||
description = "Allow a player to build in a plot",
|
||||
category = CommandCategory.ACTIONS
|
||||
)
|
||||
public class Trust extends SubCommand {
|
||||
|
||||
public Trust() {
|
||||
super(Command.TRUST, "Allow a player to build in a plot", "trust <player>", CommandCategory.ACTIONS, true);
|
||||
requiredArguments = new Argument[] {
|
||||
Argument.PlayerName
|
||||
};
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean execute(final PlotPlayer plr, final String... args) {
|
||||
if (args.length != 1) {
|
||||
MainUtil.sendMessage(plr, C.COMMAND_SYNTAX, "/plot trust <player>");
|
||||
return true;
|
||||
}
|
||||
public boolean onCommand(final CommandCaller caller, final String[] args) {
|
||||
final PlotPlayer plr = (PlotPlayer) caller.getSuperCaller();
|
||||
final Location loc = plr.getLocation();
|
||||
final Plot plot = MainUtil.getPlot(loc);
|
||||
if (plot == null) {
|
||||
return !sendMessage(plr, C.NOT_IN_PLOT);
|
||||
}
|
||||
if ((plot == null) || !plot.hasOwner()) {
|
||||
if (!plot.hasOwner()) {
|
||||
MainUtil.sendMessage(plr, C.PLOT_UNOWNED);
|
||||
return false;
|
||||
}
|
||||
|
@ -29,14 +29,21 @@ 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.intellectualsites.commands.CommandDeclaration;
|
||||
import com.intellectualsites.commands.callers.CommandCaller;
|
||||
|
||||
@CommandDeclaration(
|
||||
command = "unclaim",
|
||||
usage = "/plot unclaim",
|
||||
requiredType = PlotPlayer.class,
|
||||
description = "Unclaim a plot",
|
||||
category = CommandCategory.ACTIONS
|
||||
)
|
||||
public class Unclaim extends SubCommand {
|
||||
public Unclaim() {
|
||||
super(Command.UNCLAIM, "Unclaim a plot", "unclaim", CommandCategory.ACTIONS, true);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean execute(final PlotPlayer plr, final String... args) {
|
||||
public boolean onCommand(final CommandCaller caller, final String[] args) {
|
||||
final PlotPlayer plr = (PlotPlayer) caller.getSuperCaller();
|
||||
final Location loc = plr.getLocation();
|
||||
final Plot plot = MainUtil.getPlot(loc);
|
||||
if (plot == null) {
|
||||
@ -45,10 +52,9 @@ public class Unclaim extends SubCommand {
|
||||
if (!MainUtil.getTopPlot(plot).equals(MainUtil.getBottomPlot(plot))) {
|
||||
return !sendMessage(plr, C.UNLINK_REQUIRED);
|
||||
}
|
||||
if ((((plot == null) || !plot.hasOwner() || !plot.isOwner(plr.getUUID()))) && !Permissions.hasPermission(plr, "plots.admin.command.unclaim")) {
|
||||
if (((!plot.hasOwner() || !plot.isOwner(plr.getUUID()))) && !Permissions.hasPermission(plr, "plots.admin.command.unclaim")) {
|
||||
return !sendMessage(plr, C.NO_PLOT_PERMS);
|
||||
}
|
||||
assert plot != null;
|
||||
final PlotWorld pWorld = PS.get().getPlotWorld(plot.world);
|
||||
if ((EconHandler.manager != null) && pWorld.USE_ECONOMY) {
|
||||
final double c = pWorld.SELL_PRICE;
|
||||
|
@ -29,26 +29,37 @@ 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.intellectualsites.commands.Argument;
|
||||
import com.intellectualsites.commands.CommandDeclaration;
|
||||
import com.intellectualsites.commands.callers.CommandCaller;
|
||||
import com.plotsquared.bukkit.util.bukkit.UUIDHandler;
|
||||
import com.plotsquared.bukkit.util.bukkit.uuid.SQLUUIDHandler;
|
||||
|
||||
@CommandDeclaration(
|
||||
command = "undeny",
|
||||
aliases = {"ud"},
|
||||
description = "Remove a denied user from a plot",
|
||||
usage = "/plot undeny <player>",
|
||||
requiredType = PlotPlayer.class,
|
||||
category = CommandCategory.ACTIONS
|
||||
)
|
||||
public class Undeny extends SubCommand {
|
||||
|
||||
public Undeny() {
|
||||
super(Command.UNDENY, "Remove a denied user from a plot", "undeny <player>", CommandCategory.ACTIONS, true);
|
||||
requiredArguments = new Argument[] {
|
||||
Argument.PlayerName
|
||||
};
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean execute(final PlotPlayer plr, final String... args) {
|
||||
if (args.length != 1) {
|
||||
MainUtil.sendMessage(plr, C.COMMAND_SYNTAX, "/plot undeny <player>");
|
||||
return true;
|
||||
}
|
||||
public boolean onCommand(final CommandCaller caller, final String ... args) {
|
||||
final PlotPlayer plr = (PlotPlayer) caller.getSuperCaller();
|
||||
final Location loc = plr.getLocation();
|
||||
final Plot plot = MainUtil.getPlot(loc);
|
||||
if (plot == null) {
|
||||
return !sendMessage(plr, C.NOT_IN_PLOT);
|
||||
}
|
||||
if ((plot == null) || !plot.hasOwner()) {
|
||||
if (!plot.hasOwner()) {
|
||||
MainUtil.sendMessage(plr, C.PLOT_UNOWNED);
|
||||
return false;
|
||||
}
|
||||
@ -57,31 +68,33 @@ public class Undeny extends SubCommand {
|
||||
return true;
|
||||
}
|
||||
int count = 0;
|
||||
if (args[0].equals("unknown")) {
|
||||
ArrayList<UUID> toRemove = new ArrayList<>();
|
||||
for (UUID uuid : plot.getDenied()) {
|
||||
if (UUIDHandler.getName(uuid) == null) {
|
||||
toRemove.add(uuid);
|
||||
switch (args[0]) {
|
||||
case "unknown":
|
||||
ArrayList<UUID> toRemove = new ArrayList<>();
|
||||
for (UUID uuid : plot.getDenied()) {
|
||||
if (UUIDHandler.getName(uuid) == null) {
|
||||
toRemove.add(uuid);
|
||||
}
|
||||
}
|
||||
}
|
||||
for (UUID uuid : toRemove) {
|
||||
plot.removeDenied(uuid);
|
||||
count++;
|
||||
}
|
||||
}
|
||||
else if (args[0].equals("*")){
|
||||
for (UUID uuid : new ArrayList<>(plot.getDenied())) {
|
||||
plot.removeDenied(uuid);
|
||||
count++;
|
||||
}
|
||||
}
|
||||
else {
|
||||
UUID uuid = UUIDHandler.getUUID(args[0]);
|
||||
if (uuid != null) {
|
||||
if (plot.removeDenied(uuid)) {
|
||||
for (UUID uuid : toRemove) {
|
||||
plot.removeDenied(uuid);
|
||||
count++;
|
||||
}
|
||||
}
|
||||
break;
|
||||
case "*":
|
||||
for (UUID uuid : new ArrayList<>(plot.getDenied())) {
|
||||
plot.removeDenied(uuid);
|
||||
count++;
|
||||
}
|
||||
break;
|
||||
default:
|
||||
UUID uuid = UUIDHandler.getUUID(args[0]);
|
||||
if (uuid != null) {
|
||||
if (plot.removeDenied(uuid)) {
|
||||
count++;
|
||||
}
|
||||
}
|
||||
break;
|
||||
}
|
||||
if (count == 0) {
|
||||
if (UUIDHandler.implementation instanceof SQLUUIDHandler) {
|
||||
@ -96,4 +109,5 @@ public class Undeny extends SubCommand {
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -29,25 +29,29 @@ import com.intellectualcrafters.plot.util.CmdConfirm;
|
||||
import com.intellectualcrafters.plot.util.MainUtil;
|
||||
import com.intellectualcrafters.plot.util.Permissions;
|
||||
import com.intellectualcrafters.plot.util.TaskManager;
|
||||
import com.intellectualsites.commands.CommandDeclaration;
|
||||
import com.intellectualsites.commands.callers.CommandCaller;
|
||||
|
||||
/**
|
||||
* Created 2014-08-01 for PlotSquared
|
||||
*
|
||||
* @author Citymonstret
|
||||
*/
|
||||
@CommandDeclaration(
|
||||
command = "unlink",
|
||||
aliases = {"u"},
|
||||
description = "Unlink a mega-plot",
|
||||
usage = "/plot unlink",
|
||||
requiredType = PlotPlayer.class,
|
||||
category = CommandCategory.ACTIONS
|
||||
)
|
||||
public class Unlink extends SubCommand {
|
||||
public Unlink() {
|
||||
super(Command.UNLINK, "Unlink a mega-plot", "unlink", CommandCategory.ACTIONS, true);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean execute(final PlotPlayer plr, final String... args) {
|
||||
public boolean onCommand(final CommandCaller caller, final String[] args) {
|
||||
final PlotPlayer plr = (PlotPlayer) caller.getSuperCaller();
|
||||
|
||||
final Location loc = plr.getLocation();
|
||||
final Plot plot = MainUtil.getPlot(loc);
|
||||
if (plot == null) {
|
||||
return !sendMessage(plr, C.NOT_IN_PLOT);
|
||||
}
|
||||
if (((plot == null) || !plot.hasOwner() || !plot.isOwner(plr.getUUID())) && !Permissions.hasPermission(plr, "plots.admin.command.unlink")) {
|
||||
if ((!plot.hasOwner() || !plot.isOwner(plr.getUUID())) && !Permissions.hasPermission(plr, "plots.admin.command.unlink")) {
|
||||
return sendMessage(plr, C.NO_PLOT_PERMS);
|
||||
}
|
||||
if (MainUtil.getTopPlot(plot).equals(MainUtil.getBottomPlot(plot))) {
|
||||
|
@ -29,25 +29,39 @@ 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.intellectualsites.commands.Argument;
|
||||
import com.intellectualsites.commands.CommandDeclaration;
|
||||
import com.intellectualsites.commands.callers.CommandCaller;
|
||||
import com.plotsquared.bukkit.util.bukkit.UUIDHandler;
|
||||
|
||||
// UNTRUST("untrust", "ut"),
|
||||
|
||||
@CommandDeclaration(
|
||||
command = "untrust",
|
||||
aliases = {"ut"},
|
||||
permission = "plot.untrust",
|
||||
description = "Remove a trusted user from a plot",
|
||||
usage = "/plot untrust <player>",
|
||||
requiredType = PlotPlayer.class,
|
||||
category = CommandCategory.ACTIONS
|
||||
)
|
||||
public class Untrust extends SubCommand {
|
||||
|
||||
public Untrust() {
|
||||
super(Command.UNTRUST, "Remove a trusted user from a plot", "untrust <player>", CommandCategory.ACTIONS, true);
|
||||
requiredArguments = new Argument[] {
|
||||
Argument.PlayerName
|
||||
};
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean execute(final PlotPlayer plr, final String... args) {
|
||||
if (args.length != 1) {
|
||||
MainUtil.sendMessage(plr, C.COMMAND_SYNTAX, "/plot untrust <player>");
|
||||
return true;
|
||||
}
|
||||
public boolean onCommand(final CommandCaller caller, final String[] args) {
|
||||
PlotPlayer plr = (PlotPlayer) caller.getSuperCaller();
|
||||
final Location loc = plr.getLocation();
|
||||
final Plot plot = MainUtil.getPlot(loc);
|
||||
if (plot == null) {
|
||||
return !sendMessage(plr, C.NOT_IN_PLOT);
|
||||
}
|
||||
if ((plot == null) || !plot.hasOwner()) {
|
||||
if (!plot.hasOwner()) {
|
||||
MainUtil.sendMessage(plr, C.PLOT_UNOWNED);
|
||||
return false;
|
||||
}
|
||||
@ -56,31 +70,33 @@ public class Untrust extends SubCommand {
|
||||
return true;
|
||||
}
|
||||
int count = 0;
|
||||
if (args[0].equals("unknown")) {
|
||||
ArrayList<UUID> toRemove = new ArrayList<>();
|
||||
for (UUID uuid : plot.getTrusted()) {
|
||||
if (UUIDHandler.getName(uuid) == null) {
|
||||
toRemove.add(uuid);
|
||||
switch (args[0]) {
|
||||
case "unknown":
|
||||
ArrayList<UUID> toRemove = new ArrayList<>();
|
||||
for (UUID uuid : plot.getTrusted()) {
|
||||
if (UUIDHandler.getName(uuid) == null) {
|
||||
toRemove.add(uuid);
|
||||
}
|
||||
}
|
||||
}
|
||||
for (UUID uuid : toRemove) {
|
||||
plot.removeTrusted(uuid);
|
||||
count++;
|
||||
}
|
||||
}
|
||||
else if (args[0].equals("*")){
|
||||
for (UUID uuid : new ArrayList<>(plot.getTrusted())) {
|
||||
plot.removeTrusted(uuid);
|
||||
count++;
|
||||
}
|
||||
}
|
||||
else {
|
||||
UUID uuid = UUIDHandler.getUUID(args[0]);
|
||||
if (uuid != null) {
|
||||
if (plot.removeTrusted(uuid)) {
|
||||
for (UUID uuid : toRemove) {
|
||||
plot.removeTrusted(uuid);
|
||||
count++;
|
||||
}
|
||||
}
|
||||
break;
|
||||
case "*":
|
||||
for (UUID uuid : new ArrayList<>(plot.getTrusted())) {
|
||||
plot.removeTrusted(uuid);
|
||||
count++;
|
||||
}
|
||||
break;
|
||||
default:
|
||||
UUID uuid = UUIDHandler.getUUID(args[0]);
|
||||
if (uuid != null) {
|
||||
if (plot.removeTrusted(uuid)) {
|
||||
count++;
|
||||
}
|
||||
}
|
||||
break;
|
||||
}
|
||||
if (count == 0) {
|
||||
MainUtil.sendMessage(plr, C.INVALID_PLAYER, args[0]);
|
||||
|
@ -25,18 +25,26 @@ import java.net.URL;
|
||||
|
||||
import com.intellectualcrafters.plot.PS;
|
||||
import com.intellectualcrafters.plot.config.C;
|
||||
import com.intellectualcrafters.plot.object.PlotPlayer;
|
||||
|
||||
import com.intellectualcrafters.plot.util.MainUtil;
|
||||
import com.intellectualsites.commands.CommandDeclaration;
|
||||
import com.intellectualsites.commands.callers.CommandCaller;
|
||||
|
||||
@CommandDeclaration(
|
||||
command = "update",
|
||||
permission = "plots.admin",
|
||||
description = "Update PlotSquared",
|
||||
usage = "/plot update",
|
||||
requiredType = PS.class,
|
||||
aliases = {"updateplugin"},
|
||||
category = CommandCategory.DEBUG
|
||||
)
|
||||
public class Update extends SubCommand {
|
||||
public static String downloads, version;
|
||||
|
||||
public Update() {
|
||||
super("update", "plots.admin", "Update PlotSquared", "update", "updateplugin", CommandCategory.DEBUG, false);
|
||||
}
|
||||
public static String version;
|
||||
|
||||
@Override
|
||||
public boolean execute(final PlotPlayer plr, final String... args) {
|
||||
public boolean onCommand(CommandCaller caller, String[] args) {
|
||||
URL url;
|
||||
if (args.length == 0) {
|
||||
url = PS.get().update;
|
||||
@ -45,23 +53,24 @@ public class Update extends SubCommand {
|
||||
try {
|
||||
url = new URL(args[0]);
|
||||
} catch (MalformedURLException e) {
|
||||
MainUtil.sendMessage(plr, "&cInvalid url: " + args[0]);
|
||||
MainUtil.sendMessage(plr, C.COMMAND_SYNTAX, "/plot update [url]");
|
||||
MainUtil.sendConsoleMessage("&cInvalid url: " + args[0]);
|
||||
MainUtil.sendConsoleMessage(C.COMMAND_SYNTAX, "/plot update [url]");
|
||||
return false;
|
||||
}
|
||||
}
|
||||
else {
|
||||
MainUtil.sendMessage(plr, C.COMMAND_SYNTAX, "/plot update");
|
||||
caller.message(C.COMMAND_SYNTAX, getUsage());
|
||||
return false;
|
||||
}
|
||||
if (url == null) {
|
||||
MainUtil.sendMessage(plr, "&cNo update found!");
|
||||
MainUtil.sendMessage(plr, "&cTo manually specify an update URL: /plot update <url>");
|
||||
caller.message("&cNo update found!");
|
||||
caller.message("&cTo manually specify an update URL: /plot update <url>");
|
||||
return false;
|
||||
}
|
||||
if (PS.get().update(plr, url) && url == PS.get().update) {
|
||||
if (PS.get().update(null, url) && url == PS.get().update) {
|
||||
PS.get().update = null;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -30,11 +30,26 @@ 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.intellectualsites.commands.Argument;
|
||||
import com.intellectualsites.commands.CommandDeclaration;
|
||||
import com.intellectualsites.commands.callers.CommandCaller;
|
||||
import com.plotsquared.bukkit.util.bukkit.UUIDHandler;
|
||||
|
||||
@CommandDeclaration(
|
||||
command = "visit",
|
||||
permission = "plots.visit",
|
||||
description = "Visit someones plot",
|
||||
usage = "/plot visit <player|aliases|world|id> [#]",
|
||||
aliases = {"v}"},
|
||||
requiredType = PlotPlayer.class,
|
||||
category = CommandCategory.TELEPORT
|
||||
)
|
||||
public class Visit extends SubCommand {
|
||||
|
||||
public Visit() {
|
||||
super("visit", "plots.visit", "Visit someones plot", "visit {player} [#]", "v", CommandCategory.TELEPORT, true);
|
||||
requiredArguments = new Argument[] {
|
||||
Argument.String
|
||||
};
|
||||
}
|
||||
|
||||
public List<Plot> getPlots(final UUID uuid) {
|
||||
@ -48,10 +63,8 @@ public class Visit extends SubCommand {
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean execute(final PlotPlayer plr, final String... args) {
|
||||
if (args.length < 1) {
|
||||
return sendMessage(plr, C.COMMAND_SYNTAX, "/plot visit <player|alias|world|id> [#]");
|
||||
}
|
||||
public boolean onCommand(CommandCaller caller, String[] args) {
|
||||
PlotPlayer plr = (PlotPlayer) caller.getSuperCaller();
|
||||
ArrayList<Plot> plots = new ArrayList<>();
|
||||
UUID user = UUIDHandler.getUUID(args[0]);
|
||||
if (user != null ) {
|
||||
@ -116,38 +129,6 @@ public class Visit extends SubCommand {
|
||||
}
|
||||
MainUtil.teleportPlayer(plr, plr.getLocation(), plots.get(index));
|
||||
return true;
|
||||
|
||||
//
|
||||
// // from alias
|
||||
//
|
||||
//
|
||||
// id = PlotId.fromString(args[0]);
|
||||
//
|
||||
//
|
||||
//
|
||||
// final String username = args[0];
|
||||
// final UUID uuid = UUIDHandler.getUUID(username);
|
||||
// List<Plot> plots = null;
|
||||
// if (uuid != null) {
|
||||
// plots = PlotSquared.sortPlotsByWorld(getPlots(uuid));
|
||||
// }
|
||||
// if ((uuid == null) || plots.isEmpty()) {
|
||||
// return sendMessage(plr, C.FOUND_NO_PLOTS);
|
||||
// }
|
||||
// if (args.length < 2) {
|
||||
// MainUtil.teleportPlayer(plr, plr.getLocation(), plots.get(0));
|
||||
// return true;
|
||||
// }
|
||||
// int i;
|
||||
// try {
|
||||
// i = Integer.parseInt(args[1]);
|
||||
// } catch (final Exception e) {
|
||||
// return sendMessage(plr, C.NOT_VALID_NUMBER);
|
||||
// }
|
||||
// if ((i < 1) || (i > plots.size())) {
|
||||
// return sendMessage(plr, C.NOT_VALID_NUMBER);
|
||||
// }
|
||||
// MainUtil.teleportPlayer(plr, plr.getLocation(), plots.get(i - 1));
|
||||
// return true;
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -22,32 +22,42 @@ package com.intellectualcrafters.plot.commands;
|
||||
|
||||
import com.intellectualcrafters.plot.PS;
|
||||
import com.intellectualcrafters.plot.config.C;
|
||||
import com.intellectualsites.commands.CommandDeclaration;
|
||||
import com.intellectualsites.commands.callers.CommandCaller;
|
||||
import com.plotsquared.bukkit.listeners.worldedit.WEManager;
|
||||
import com.intellectualcrafters.plot.object.PlotPlayer;
|
||||
import com.intellectualcrafters.plot.util.MainUtil;
|
||||
import com.intellectualcrafters.plot.util.Permissions;
|
||||
|
||||
@CommandDeclaration(
|
||||
command = "weanywhere",
|
||||
permission = "plots.worldedit.bypass",
|
||||
description = "Force bypass of WorldEdit",
|
||||
aliases = {"wea"},
|
||||
usage = "/plot weanywhere",
|
||||
requiredType = PlotPlayer.class,
|
||||
category = CommandCategory.DEBUG
|
||||
)
|
||||
public class WE_Anywhere extends SubCommand {
|
||||
public WE_Anywhere() {
|
||||
super("weanywhere", "plots.worldedit.bypass", "Force bypass of WorldEdit", "weanywhere", "wea", CommandCategory.DEBUG, true);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean execute(final PlotPlayer plr, final String... args) {
|
||||
public boolean onCommand(CommandCaller caller, String[] arguments) {
|
||||
if (PS.get().worldEdit == null) {
|
||||
MainUtil.sendMessage(plr, "&cWorldEdit is not enabled on this server");
|
||||
return false;
|
||||
caller.message("&cWorldEdit is not enabled on this server");
|
||||
return true;
|
||||
}
|
||||
if (Permissions.hasPermission(plr, "plots.worldedit.bypass")) {
|
||||
if (WEManager.bypass.contains(plr.getName())) {
|
||||
WEManager.bypass.remove(plr.getName());
|
||||
MainUtil.sendMessage(plr, C.WORLDEDIT_RESTRICTED);
|
||||
PlotPlayer player = (PlotPlayer) caller.getSuperCaller();
|
||||
if (Permissions.hasPermission(player, "plots.worldedit.bypass")) {
|
||||
if (WEManager.bypass.contains(player.getName())) {
|
||||
WEManager.bypass.remove(player.getName());
|
||||
MainUtil.sendMessage(player, C.WORLDEDIT_RESTRICTED);
|
||||
}
|
||||
else {
|
||||
WEManager.bypass.add(plr.getName());
|
||||
MainUtil.sendMessage(plr, C.WORLDEDIT_UNMASKED);
|
||||
WEManager.bypass.add(player.getName());
|
||||
MainUtil.sendMessage(player, C.WORLDEDIT_UNMASKED);
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -0,0 +1,36 @@
|
||||
package com.intellectualcrafters.plot.commands.callers;
|
||||
|
||||
import com.intellectualcrafters.plot.PS;
|
||||
import com.intellectualcrafters.plot.config.C;
|
||||
import com.intellectualcrafters.plot.util.MainUtil;
|
||||
import com.intellectualsites.commands.Argument;
|
||||
import com.intellectualsites.commands.Command;
|
||||
import com.intellectualsites.commands.CommandManager;
|
||||
import com.intellectualsites.commands.callers.CommandCaller;
|
||||
|
||||
public class ConsoleCaller implements CommandCaller<PS> {
|
||||
@Override
|
||||
public boolean hasPermission(String permission) {
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void message(String message) {
|
||||
MainUtil.sendConsoleMessage(message);
|
||||
}
|
||||
|
||||
@Override
|
||||
public PS getSuperCaller() {
|
||||
return PS.get();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void message(C c, String... args) {
|
||||
MainUtil.sendConsoleMessage(c, args);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void sendRequiredArgumentsList(CommandManager manager, Command cmd, Argument[] required) {
|
||||
message(C.COMMAND_SYNTAX, cmd.getUsage());
|
||||
}
|
||||
}
|
@ -0,0 +1,44 @@
|
||||
package com.intellectualcrafters.plot.commands.callers;
|
||||
|
||||
import com.intellectualcrafters.plot.config.C;
|
||||
import com.intellectualcrafters.plot.object.PlotPlayer;
|
||||
import com.intellectualcrafters.plot.util.MainUtil;
|
||||
import com.intellectualsites.commands.Argument;
|
||||
import com.intellectualsites.commands.Command;
|
||||
import com.intellectualsites.commands.CommandManager;
|
||||
import com.intellectualsites.commands.callers.CommandCaller;
|
||||
|
||||
public class PlotPlayerCaller implements CommandCaller<PlotPlayer> {
|
||||
|
||||
private final PlotPlayer player;
|
||||
|
||||
public PlotPlayerCaller(final PlotPlayer player) {
|
||||
this.player = player;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean hasPermission(String permission) {
|
||||
return player.hasPermission(permission);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void message(String message) {
|
||||
player.sendMessage(message);
|
||||
}
|
||||
|
||||
@Override
|
||||
public PlotPlayer getSuperCaller() {
|
||||
return player;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void message(C c, String... args) {
|
||||
MainUtil.sendMessage(getSuperCaller(), c, args);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void sendRequiredArgumentsList(CommandManager manager, Command cmd, Argument[] required) {
|
||||
message(C.COMMAND_SYNTAX, cmd.getUsage());
|
||||
message("Argument list is yet to be implemented");
|
||||
}
|
||||
}
|
@ -29,6 +29,9 @@ import java.util.Map.Entry;
|
||||
import java.util.Set;
|
||||
import java.util.UUID;
|
||||
|
||||
import com.intellectualcrafters.plot.commands.callers.PlotPlayerCaller;
|
||||
import com.intellectualsites.commands.CommandDeclaration;
|
||||
import com.intellectualsites.commands.callers.CommandCaller;
|
||||
import org.apache.commons.lang.StringUtils;
|
||||
import org.bukkit.ChatColor;
|
||||
|
||||
@ -48,13 +51,14 @@ import com.intellectualcrafters.plot.util.StringComparison;
|
||||
import com.plotsquared.bukkit.util.bukkit.UUIDHandler;
|
||||
import com.plotsquared.bukkit.util.bukkit.chat.FancyMessage;
|
||||
|
||||
/**
|
||||
* @author Citymonstret
|
||||
*/
|
||||
@CommandDeclaration(
|
||||
command = "list",
|
||||
aliases = {"l"},
|
||||
description = "List plots",
|
||||
permission = "plots.list",
|
||||
category = CommandCategory.INFO
|
||||
)
|
||||
public class list extends SubCommand {
|
||||
public list() {
|
||||
super(Command.LIST, "List all plots", "list {mine|shared|all|world|forsale}", CommandCategory.INFO, false);
|
||||
}
|
||||
|
||||
private static String getName(final UUID id) {
|
||||
if (id == null) {
|
||||
@ -114,7 +118,9 @@ public class list extends SubCommand {
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean execute(final PlotPlayer plr, final String... args) {
|
||||
public boolean onCommand(final CommandCaller caller, final String[] args) {
|
||||
final PlotPlayer plr = caller instanceof PlotPlayerCaller ? (PlotPlayer) caller.getSuperCaller() : null;
|
||||
|
||||
if (args.length < 1) {
|
||||
noArgs(plr);
|
||||
return false;
|
||||
|
@ -27,18 +27,24 @@ import java.net.URLConnection;
|
||||
import java.util.ArrayList;
|
||||
|
||||
import com.intellectualcrafters.plot.PS;
|
||||
import com.intellectualcrafters.plot.commands.callers.PlotPlayerCaller;
|
||||
import com.intellectualcrafters.plot.config.C;
|
||||
import com.intellectualcrafters.plot.object.PlotPlayer;
|
||||
import com.intellectualcrafters.plot.util.MainUtil;
|
||||
import com.intellectualcrafters.plot.util.StringMan;
|
||||
import com.intellectualcrafters.plot.util.TaskManager;
|
||||
import com.intellectualsites.commands.CommandDeclaration;
|
||||
import com.intellectualsites.commands.callers.CommandCaller;
|
||||
|
||||
@CommandDeclaration(
|
||||
command = "plugin",
|
||||
permission = "plots.use",
|
||||
description = "Show plugin information",
|
||||
aliases = {"version}"},
|
||||
category = CommandCategory.INFO
|
||||
)
|
||||
public class plugin extends SubCommand {
|
||||
|
||||
public plugin() {
|
||||
super("plugin", "plots.use", "Show plugin information", "plugin", "version", CommandCategory.INFO, false);
|
||||
}
|
||||
|
||||
private static String convertToNumericString(final String str, final boolean dividers) {
|
||||
final StringBuilder builder = new StringBuilder();
|
||||
for (final char c : str.toCharArray()) {
|
||||
@ -64,7 +70,7 @@ public class plugin extends SubCommand {
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean execute(final PlotPlayer plr, final String... args) {
|
||||
public boolean onCommand(final CommandCaller caller, final String[] args) {
|
||||
TaskManager.runTaskAsync(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
@ -79,7 +85,7 @@ public class plugin extends SubCommand {
|
||||
}
|
||||
};
|
||||
for (final String s : strings) {
|
||||
MainUtil.sendMessage(plr, StringMan.replaceFromMap(s, C.replacements), false);
|
||||
MainUtil.sendMessage(caller instanceof PlotPlayerCaller ? (PlotPlayer) caller.getSuperCaller() : null, StringMan.replaceFromMap(s, C.replacements), false);
|
||||
}
|
||||
}
|
||||
});
|
||||
|
@ -31,6 +31,7 @@ import com.intellectualcrafters.plot.PS;
|
||||
import com.intellectualcrafters.plot.config.C;
|
||||
import com.intellectualcrafters.plot.config.Settings;
|
||||
import com.intellectualcrafters.plot.database.DBFunc;
|
||||
import com.intellectualsites.commands.callers.CommandCaller;
|
||||
import com.plotsquared.bukkit.listeners.PlotListener;
|
||||
import com.intellectualcrafters.plot.object.BlockLoc;
|
||||
import com.intellectualcrafters.plot.object.ChunkLoc;
|
||||
@ -1421,6 +1422,15 @@ public class MainUtil {
|
||||
return sendMessage(plr, msg, true);
|
||||
}
|
||||
|
||||
public static boolean sendCallerMessage(final CommandCaller plr, final String msg) {
|
||||
if (plr.getSuperCaller() instanceof PlotPlayer) {
|
||||
sendMessage((PlotPlayer) plr.getSuperCaller(), msg);
|
||||
} else {
|
||||
sendConsoleMessage(msg);
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
public static void sendConsoleMessage(String msg) {
|
||||
sendMessage(null, msg);
|
||||
}
|
||||
@ -1507,6 +1517,15 @@ public class MainUtil {
|
||||
return lines.toArray(new String[lines.size()]);
|
||||
}
|
||||
|
||||
public static boolean sendCallerMessage(final CommandCaller caller, final C c, final String... args) {
|
||||
if (caller.getSuperCaller() instanceof PlotPlayer) {
|
||||
sendMessage((PlotPlayer) caller.getSuperCaller(), c, args);
|
||||
} else {
|
||||
sendConsoleMessage(c, args);
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Send a message to the player
|
||||
*
|
||||
|
84
src/main/java/com/intellectualsites/commands/Argument.java
Normal file
84
src/main/java/com/intellectualsites/commands/Argument.java
Normal file
@ -0,0 +1,84 @@
|
||||
package com.intellectualsites.commands;
|
||||
|
||||
import com.intellectualcrafters.plot.object.PlotId;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
public abstract class Argument<T> {
|
||||
|
||||
private final String name;
|
||||
private final T example;
|
||||
|
||||
public Argument(String name, T example) {
|
||||
this.name = name;
|
||||
this.example = example;
|
||||
}
|
||||
|
||||
public abstract T parse(String in);
|
||||
|
||||
@Override
|
||||
public final String toString() {
|
||||
return this.getName();
|
||||
}
|
||||
|
||||
public final String getName() {
|
||||
return this.name;
|
||||
}
|
||||
|
||||
public final T getExample() {
|
||||
return this.example;
|
||||
}
|
||||
|
||||
public static final Argument<Integer> Integer = new Argument<java.lang.Integer>("int", 16) {
|
||||
@Override
|
||||
public Integer parse(String in) {
|
||||
Integer value = null;
|
||||
try {
|
||||
value = java.lang.Integer.parseInt(in);
|
||||
} catch(final Exception ignored) {}
|
||||
return value;
|
||||
}
|
||||
};
|
||||
|
||||
public static final Argument<Boolean> Boolean = new Argument<java.lang.Boolean>("boolean", true) {
|
||||
@Override
|
||||
public Boolean parse(String in) {
|
||||
Boolean value = null;
|
||||
if (in.equalsIgnoreCase("true") || in.equalsIgnoreCase("Yes") || in.equalsIgnoreCase("1")) {
|
||||
value = true;
|
||||
} else if (in.equalsIgnoreCase("false") || in.equalsIgnoreCase("No") || in.equalsIgnoreCase("0")) {
|
||||
value = false;
|
||||
}
|
||||
return value;
|
||||
}
|
||||
};
|
||||
|
||||
public static final Argument<String> String = new Argument<java.lang.String>("String", "Example") {
|
||||
@Override
|
||||
public String parse(String in) {
|
||||
return in;
|
||||
}
|
||||
};
|
||||
|
||||
public static Argument<String> PlayerName = new Argument<java.lang.String>("PlayerName", "Dinnerbone") {
|
||||
@Override
|
||||
public String parse(String in) {
|
||||
return in.length() < 16 ? in : null;
|
||||
}
|
||||
};
|
||||
|
||||
public static Argument<PlotId> PlotID = new Argument<com.intellectualcrafters.plot.object.PlotId>("PlotID", new PlotId(3, -32)) {
|
||||
@Override
|
||||
public PlotId parse(String in) {
|
||||
PlotId plotID;
|
||||
try {
|
||||
String[] parts = in.split(";");
|
||||
int i1 = java.lang.Integer.parseInt(parts[0]);
|
||||
int i2 = java.lang.Integer.parseInt(parts[1]);
|
||||
plotID = new PlotId(i1, i2);
|
||||
} catch(final Exception e) {
|
||||
return null;
|
||||
}
|
||||
return plotID;
|
||||
}
|
||||
};
|
||||
}
|
140
src/main/java/com/intellectualsites/commands/Command.java
Normal file
140
src/main/java/com/intellectualsites/commands/Command.java
Normal file
@ -0,0 +1,140 @@
|
||||
package com.intellectualsites.commands;
|
||||
|
||||
import com.intellectualcrafters.plot.commands.CommandCategory;
|
||||
import com.intellectualsites.commands.callers.CommandCaller;
|
||||
|
||||
import java.lang.annotation.Annotation;
|
||||
import java.util.ArrayList;
|
||||
|
||||
public abstract class Command extends CommandManager {
|
||||
|
||||
private Class requiredType = Object.class;
|
||||
private String command, usage = "", description = "", permission = "";
|
||||
private String[] aliases = new String[0];
|
||||
private CommandCategory category;
|
||||
protected Argument[] requiredArguments;
|
||||
|
||||
public Command() {
|
||||
super(null, new ArrayList<Command>());
|
||||
}
|
||||
|
||||
public Command(String command) {
|
||||
super(null, new ArrayList<Command>());
|
||||
this.command = command;
|
||||
}
|
||||
|
||||
public Command(String command, String usage) {
|
||||
super(null, new ArrayList<Command>());
|
||||
this.command = command;
|
||||
this.usage = usage;
|
||||
}
|
||||
|
||||
public Command(String command, String usage, String description) {
|
||||
super(null, new ArrayList<Command>());
|
||||
this.command = command;
|
||||
this.usage = usage;
|
||||
this.description = description;
|
||||
}
|
||||
|
||||
public Command(String command, String usage, String description, String permission) {
|
||||
super(null, new ArrayList<Command>());
|
||||
this.command = command;
|
||||
this.usage = usage;
|
||||
this.description = description;
|
||||
this.permission = permission;
|
||||
}
|
||||
|
||||
public Command(String command, String[] aliases, String usage) {
|
||||
super(null, new ArrayList<Command>());
|
||||
this.command = command;
|
||||
this.aliases = aliases;
|
||||
this.usage = usage;
|
||||
}
|
||||
|
||||
public Command(String command, String[] aliases) {
|
||||
super(null, new ArrayList<Command>());
|
||||
this.command = command;
|
||||
this.aliases = aliases;
|
||||
}
|
||||
|
||||
public Command(String command, String usage, String description, String permission, String[] aliases, Class requiredType) {
|
||||
super(null, new ArrayList<Command>());
|
||||
this.command = command;
|
||||
this.usage = usage;
|
||||
this.description = description;
|
||||
this.permission = permission;
|
||||
this.aliases = aliases;
|
||||
this.requiredType = requiredType;
|
||||
}
|
||||
|
||||
final public Class getRequiredType() {
|
||||
return this.requiredType;
|
||||
}
|
||||
|
||||
final protected void create() {
|
||||
Annotation annotation = getClass().getAnnotation(CommandDeclaration.class);
|
||||
if (annotation == null) {
|
||||
throw new RuntimeException("Command does not have a CommandDeclaration");
|
||||
}
|
||||
CommandDeclaration declaration = (CommandDeclaration) annotation;
|
||||
this.command = declaration.command();
|
||||
this.usage = declaration.usage();
|
||||
this.description = declaration.description();
|
||||
this.usage = declaration.usage();
|
||||
this.permission = declaration.permission();
|
||||
this.aliases = declaration.aliases();
|
||||
this.requiredType = declaration.requiredType();
|
||||
this.category = declaration.category();
|
||||
}
|
||||
|
||||
@Override
|
||||
final public String toString() {
|
||||
return this.command;
|
||||
}
|
||||
@Override
|
||||
final public int hashCode() {
|
||||
return this.command.hashCode();
|
||||
}
|
||||
|
||||
public abstract boolean onCommand(CommandCaller caller, String[] arguments);
|
||||
|
||||
final public int handle(CommandCaller caller, String[] args) {
|
||||
if (args.length == 0) {
|
||||
return super.handle(caller, "");
|
||||
}
|
||||
StringBuilder builder = new StringBuilder();
|
||||
for (String s : args) {
|
||||
builder.append(s).append(" ");
|
||||
}
|
||||
String s = builder.substring(0, builder.length() - 1);
|
||||
return super.handle(caller, s);
|
||||
}
|
||||
|
||||
final public String getCommand() {
|
||||
return this.command;
|
||||
}
|
||||
|
||||
final public String getUsage() {
|
||||
return this.usage;
|
||||
}
|
||||
|
||||
final public String getPermission() {
|
||||
return this.permission;
|
||||
}
|
||||
|
||||
final public String getDescription() {
|
||||
return this.description;
|
||||
}
|
||||
|
||||
final public String[] getAliases() {
|
||||
return this.aliases;
|
||||
}
|
||||
|
||||
final public Argument[] getRequiredArguments() {
|
||||
return this.requiredArguments;
|
||||
}
|
||||
|
||||
final public CommandCategory getCategory() {
|
||||
return this.category;
|
||||
}
|
||||
}
|
@ -0,0 +1,27 @@
|
||||
package com.intellectualsites.commands;
|
||||
|
||||
import com.intellectualcrafters.plot.commands.CommandCategory;
|
||||
|
||||
import java.lang.annotation.ElementType;
|
||||
import java.lang.annotation.Retention;
|
||||
import java.lang.annotation.RetentionPolicy;
|
||||
import java.lang.annotation.Target;
|
||||
|
||||
@Target(ElementType.TYPE)
|
||||
@Retention(RetentionPolicy.RUNTIME)
|
||||
public @interface CommandDeclaration {
|
||||
|
||||
String command();
|
||||
|
||||
String[] aliases() default "";
|
||||
|
||||
String permission() default "";
|
||||
|
||||
String usage() default "";
|
||||
|
||||
String description() default "";
|
||||
|
||||
Class requiredType() default Object.class;
|
||||
|
||||
CommandCategory category();
|
||||
}
|
@ -0,0 +1,31 @@
|
||||
package com.intellectualsites.commands;
|
||||
|
||||
import java.lang.reflect.Field;
|
||||
|
||||
public class CommandHandlingOutput {
|
||||
|
||||
public static int CALLER_OF_WRONG_TYPE = -6;
|
||||
public static int NOT_COMMAND = -5;
|
||||
public static int NOT_FOUND = -4;
|
||||
public static int NOT_PERMITTED = -3;
|
||||
public static int ERROR = -2;
|
||||
public static int WRONG_USAGE = -1;
|
||||
|
||||
public static int SUCCESS = 1;
|
||||
|
||||
public static String nameField(int code) {
|
||||
Field[] fields = CommandHandlingOutput.class.getDeclaredFields();
|
||||
for (final Field field : fields) {
|
||||
if (field.getGenericType() == Integer.TYPE) {
|
||||
try {
|
||||
if ((Integer) field.get(CommandHandlingOutput.class) == code) {
|
||||
return field.getName();
|
||||
}
|
||||
} catch (IllegalAccessException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
}
|
||||
return "null??";
|
||||
}
|
||||
}
|
115
src/main/java/com/intellectualsites/commands/CommandManager.java
Normal file
115
src/main/java/com/intellectualsites/commands/CommandManager.java
Normal file
@ -0,0 +1,115 @@
|
||||
package com.intellectualsites.commands;
|
||||
|
||||
import com.intellectualsites.commands.callers.CommandCaller;
|
||||
import com.intellectualsites.commands.util.StringUtil;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
|
||||
@SuppressWarnings("unused")
|
||||
public class CommandManager {
|
||||
|
||||
protected final List<Command> commands;
|
||||
private final Character initialCharacter;
|
||||
|
||||
public CommandManager() {
|
||||
this('/', new ArrayList<Command>());
|
||||
}
|
||||
|
||||
public CommandManager(Character initialCharacter, List<Command> commands) {
|
||||
this.commands = Collections.synchronizedList(commands);
|
||||
this.initialCharacter = initialCharacter;
|
||||
}
|
||||
|
||||
final public void addCommand(final Command command) {
|
||||
this.commands.add(command);
|
||||
}
|
||||
|
||||
final public boolean createCommand(final Command command) {
|
||||
try {
|
||||
command.create();
|
||||
} catch(final Exception e) {
|
||||
e.printStackTrace();
|
||||
return false;
|
||||
}
|
||||
if (command.getCommand() != null) {
|
||||
commands.add(command);
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
final public List<Command> getCommands() {
|
||||
return this.commands;
|
||||
}
|
||||
|
||||
final public int handle(CommandCaller caller, String input) {
|
||||
if (initialCharacter != null && !StringUtil.startsWith(initialCharacter, input)) {
|
||||
return CommandHandlingOutput.NOT_COMMAND;
|
||||
}
|
||||
input = initialCharacter == null ? input : StringUtil.replaceFirst(initialCharacter, input);
|
||||
String[] parts = input.split(" ");
|
||||
String[] args;
|
||||
String command = parts[0];
|
||||
if (parts.length == 1) {
|
||||
args = new String[0];
|
||||
} else {
|
||||
args = new String[parts.length - 1];
|
||||
System.arraycopy(parts, 1, args, 0, args.length);
|
||||
}
|
||||
Command cmd = null;
|
||||
for (Command c1 : this.commands) {
|
||||
if (c1.getCommand().equalsIgnoreCase(command) || StringUtil.inArray(command, c1.getAliases(), false)) {
|
||||
cmd = c1;
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (cmd == null) {
|
||||
return CommandHandlingOutput.NOT_FOUND;
|
||||
}
|
||||
if (!cmd.getRequiredType().isInstance(caller.getSuperCaller())) {
|
||||
return CommandHandlingOutput.CALLER_OF_WRONG_TYPE;
|
||||
}
|
||||
if (!caller.hasPermission(cmd.getPermission())) {
|
||||
return CommandHandlingOutput.NOT_PERMITTED;
|
||||
}
|
||||
Argument[] requiredArguments = cmd.getRequiredArguments();
|
||||
if (requiredArguments != null && requiredArguments.length > 0) {
|
||||
boolean success = true;
|
||||
if (args.length < requiredArguments.length) {
|
||||
success = false;
|
||||
} else {
|
||||
for (int i = 0; i < requiredArguments.length; i++) {
|
||||
if (requiredArguments[i].parse(args[i]) == null) {
|
||||
success = false;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
if (!success) {
|
||||
String usage = cmd.getUsage();
|
||||
caller.sendRequiredArgumentsList(this, cmd, requiredArguments);
|
||||
return CommandHandlingOutput.WRONG_USAGE;
|
||||
}
|
||||
}
|
||||
try {
|
||||
boolean a = cmd.onCommand(caller, args);
|
||||
if (!a) {
|
||||
String usage = cmd.getUsage();
|
||||
if (usage != null && !usage.isEmpty()) {
|
||||
caller.message(usage);
|
||||
}
|
||||
return CommandHandlingOutput.WRONG_USAGE;
|
||||
}
|
||||
} catch(final Throwable t) {
|
||||
t.printStackTrace();
|
||||
return CommandHandlingOutput.ERROR;
|
||||
}
|
||||
return CommandHandlingOutput.SUCCESS;
|
||||
}
|
||||
|
||||
final public char getInitialCharacter() {
|
||||
return this.initialCharacter;
|
||||
}
|
||||
}
|
@ -0,0 +1,19 @@
|
||||
package com.intellectualsites.commands.callers;
|
||||
|
||||
import com.intellectualcrafters.plot.config.C;
|
||||
import com.intellectualsites.commands.Argument;
|
||||
import com.intellectualsites.commands.Command;
|
||||
import com.intellectualsites.commands.CommandManager;
|
||||
|
||||
public interface CommandCaller<T> {
|
||||
|
||||
boolean hasPermission(String permission);
|
||||
|
||||
void message(String message);
|
||||
|
||||
T getSuperCaller();
|
||||
|
||||
void message(C c, String ... args);
|
||||
|
||||
void sendRequiredArgumentsList(CommandManager manager, Command cmd, Argument[] required);
|
||||
}
|
@ -0,0 +1,29 @@
|
||||
package com.intellectualsites.commands.callers;
|
||||
|
||||
import com.intellectualsites.commands.Argument;
|
||||
import com.intellectualsites.commands.Command;
|
||||
import com.intellectualsites.commands.CommandManager;
|
||||
|
||||
public class SystemCaller implements CommandCaller {
|
||||
|
||||
public boolean hasPermission(String permission) {
|
||||
return true;
|
||||
}
|
||||
|
||||
public void message(String message) {
|
||||
System.out.println(message);
|
||||
}
|
||||
|
||||
public Object getSuperCaller() {
|
||||
return new Object();
|
||||
}
|
||||
|
||||
public void sendRequiredArgumentsList(CommandManager manager, Command cmd, Argument[] required) {
|
||||
StringBuilder builder = new StringBuilder();
|
||||
builder.append(manager.getInitialCharacter()).append(cmd.getCommand()).append(" requires ");
|
||||
for (Argument argument : required) {
|
||||
builder.append(argument.getName()).append(" (").append(argument.getExample()).append("), ");
|
||||
}
|
||||
message(builder.substring(0, builder.length() - 2));
|
||||
}
|
||||
}
|
@ -0,0 +1,48 @@
|
||||
package com.intellectualsites.commands.test;
|
||||
|
||||
import com.intellectualsites.commands.*;
|
||||
import com.intellectualsites.commands.callers.CommandCaller;
|
||||
import com.intellectualsites.commands.callers.SystemCaller;
|
||||
|
||||
public class CommandTest {
|
||||
|
||||
public static void main(String[] args) {
|
||||
CommandCaller caller = new SystemCaller();
|
||||
CommandManager manager = new CommandManager();
|
||||
if(!manager.createCommand(new TestCommand())) {
|
||||
System.out.println("Failed to create command :(");
|
||||
}
|
||||
manager.handle(caller, "/test banana cow grass");
|
||||
}
|
||||
|
||||
@CommandDeclaration(command = "test", usage = "/test [word]")
|
||||
public static class TestCommand extends Command {
|
||||
TestCommand() {
|
||||
requiredArguments = new Argument[] {
|
||||
Argument.String, Argument.String, Argument.String
|
||||
};
|
||||
addCommand(new Command("banana", new String[0]) {
|
||||
@Override
|
||||
public boolean onCommand(CommandCaller caller, String[] arguments) {
|
||||
if (getCommands().isEmpty()) {
|
||||
addCommand(new Command("cow") {
|
||||
@Override
|
||||
public boolean onCommand(CommandCaller caller, String[] arguments) {
|
||||
caller.message("I eat " + arguments[0]);
|
||||
return true;
|
||||
}
|
||||
});
|
||||
}
|
||||
handle(caller, arguments);
|
||||
return true;
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean onCommand(CommandCaller caller, String[] arguments) {
|
||||
handle(caller, arguments);
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
@ -0,0 +1,52 @@
|
||||
package com.intellectualsites.commands.util;
|
||||
|
||||
public class StringUtil {
|
||||
|
||||
public static final String[] emptyArray = new String[0];
|
||||
|
||||
public static boolean startsWith(char c, String s) {
|
||||
return !(s == null || s.isEmpty()) && s.toCharArray()[0] == c;
|
||||
}
|
||||
|
||||
public static String replaceFirst(char c, String s) {
|
||||
if (s == null) {
|
||||
return "";
|
||||
}
|
||||
if (s.isEmpty()) {
|
||||
return s;
|
||||
}
|
||||
char[] chars = s.toCharArray();
|
||||
char[] newChars = new char[chars.length];
|
||||
int used = 0;
|
||||
boolean found = false;
|
||||
for (char cc : chars) {
|
||||
if (!found && c == cc) {
|
||||
found = true;
|
||||
} else {
|
||||
newChars[used++] = cc;
|
||||
}
|
||||
}
|
||||
if (found) {
|
||||
chars = new char[newChars.length - 1];
|
||||
System.arraycopy(newChars, 0, chars, 0, chars.length);
|
||||
return String.valueOf(chars);
|
||||
}
|
||||
return s;
|
||||
}
|
||||
|
||||
public static boolean inArray(String s, String[] a, boolean matchCase) {
|
||||
for (String aS : a) {
|
||||
if (matchCase) {
|
||||
if (s.equals(aS)) {
|
||||
return true;
|
||||
}
|
||||
} else {
|
||||
if (s.equalsIgnoreCase(aS)) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
}
|
Loading…
Reference in New Issue
Block a user