mirror of
https://github.com/IntellectualSites/PlotSquared.git
synced 2024-09-07 01:08:40 +02:00
CommandCaller
This commit is contained in:
parent
a39ec22c8c
commit
5a98c5410e
@ -33,6 +33,7 @@ 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.CommandCaller;
|
||||
import com.intellectualsites.commands.CommandDeclaration;
|
||||
import com.intellectualcrafters.plot.object.PlotPlayer;
|
||||
|
||||
|
@ -113,9 +113,7 @@ public class Database extends SubCommand {
|
||||
return sendMessage(plr, "Could not create the required tables and/or load the database") && sendMessage(plr, "Please see the stacktrace for more information");
|
||||
}
|
||||
UUID requester = null;
|
||||
if (plr != null) {
|
||||
requester = UUIDHandler.getUUID(plr);
|
||||
}
|
||||
requester = UUIDHandler.getUUID(plr);
|
||||
insertPlots(manager, requester, n);
|
||||
break;
|
||||
case "sqlite":
|
||||
|
@ -105,10 +105,10 @@ public class Info extends SubCommand {
|
||||
case "members":
|
||||
case "owner":
|
||||
case "rating":
|
||||
plot = MainUtil.getPlotFromString(player, null, player == null);
|
||||
plot = MainUtil.getPlotFromString(player, null, false);
|
||||
break;
|
||||
default:
|
||||
plot = MainUtil.getPlotFromString(player, arg, player == null);
|
||||
plot = MainUtil.getPlotFromString(player, arg, false);
|
||||
if (args.length == 2) {
|
||||
arg = args[1];
|
||||
}
|
||||
@ -119,15 +119,12 @@ public class Info extends SubCommand {
|
||||
}
|
||||
}
|
||||
else {
|
||||
plot = MainUtil.getPlotFromString(player, null, player == null);
|
||||
plot = MainUtil.getPlotFromString(player, null, false);
|
||||
}
|
||||
if (plot == null && arg != null) {
|
||||
plot = MainUtil.getPlotFromString(player, null, player == null);
|
||||
plot = MainUtil.getPlotFromString(player, null, false);
|
||||
}
|
||||
if (plot == null) {
|
||||
if (player == null) {
|
||||
return false;
|
||||
}
|
||||
MainUtil.sendMessage(player, C.NOT_IN_PLOT);
|
||||
return false;
|
||||
}
|
||||
@ -214,7 +211,7 @@ public class Info extends SubCommand {
|
||||
final String description = descriptionFlag == null ? C.NONE.s() : descriptionFlag.getValueString();
|
||||
|
||||
final String flags = StringMan.replaceFromMap("$2" + (StringUtils.join(FlagManager.getPlotFlags(plot.world, plot.getSettings(), true).values(), "").length() > 0 ? StringUtils.join(FlagManager.getPlotFlags(plot.world, plot.getSettings(), true).values(), "$1, $2") : C.NONE.s()), C.replacements);
|
||||
final boolean build = (player == null) || plot.isAdded(player.getUUID());
|
||||
final boolean build = plot.isAdded(player.getUUID());
|
||||
|
||||
String owner = plot.owner == null ? "unowned" : getPlayerList(plot.getOwners());
|
||||
|
||||
|
@ -24,13 +24,11 @@ import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.Iterator;
|
||||
import java.util.List;
|
||||
import java.util.UUID;
|
||||
|
||||
import com.intellectualcrafters.plot.PS;
|
||||
import com.intellectualcrafters.plot.config.C;
|
||||
import com.intellectualcrafters.plot.config.Settings;
|
||||
import com.intellectualcrafters.plot.object.ConsolePlayer;
|
||||
import com.intellectualcrafters.plot.object.Location;
|
||||
import com.intellectualcrafters.plot.object.PlotPlayer;
|
||||
import com.intellectualcrafters.plot.util.MainUtil;
|
||||
import com.intellectualcrafters.plot.util.MathMan;
|
||||
@ -40,19 +38,18 @@ import com.intellectualsites.commands.Argument;
|
||||
import com.intellectualsites.commands.Command;
|
||||
import com.intellectualsites.commands.CommandHandlingOutput;
|
||||
import com.intellectualsites.commands.CommandManager;
|
||||
import com.intellectualcrafters.plot.object.PlotPlayer;
|
||||
|
||||
/**
|
||||
* PlotSquared command class
|
||||
*
|
||||
* @author Citymonstret
|
||||
*/
|
||||
public class MainCommand extends CommandManager {
|
||||
public class MainCommand extends CommandManager<PlotPlayer> {
|
||||
|
||||
public static MainCommand instance = new MainCommand();
|
||||
|
||||
private MainCommand() {
|
||||
super(null, new ArrayList<Command>());
|
||||
super(null, new ArrayList<Command<PlotPlayer>>());
|
||||
List<SubCommand> toAdd = Arrays.asList(
|
||||
new Buy(), new Save(), new Load(),
|
||||
new Template(), new Download(),
|
||||
@ -93,10 +90,10 @@ public class MainCommand extends CommandManager {
|
||||
return false;
|
||||
}
|
||||
|
||||
public static ArrayList<Command> getCommands(final CommandCategory category, final PlotPlayer player) {
|
||||
ArrayList<Command> cmds = instance.getCommands();
|
||||
for (Iterator<Command> iter = cmds.iterator(); iter.hasNext();){
|
||||
Command cmd = iter.next();
|
||||
public static ArrayList<Command<PlotPlayer>> getCommands(final CommandCategory category, final PlotPlayer player) {
|
||||
ArrayList<Command<PlotPlayer>> cmds = instance.getCommands();
|
||||
for (Iterator<Command<PlotPlayer>> iter = cmds.iterator(); iter.hasNext();){
|
||||
Command<PlotPlayer> cmd = iter.next();
|
||||
if ((category != null && (cmd.getCategory().equals(category))) || !player.hasPermission(cmd.getPermission())) {
|
||||
iter.remove();
|
||||
}
|
||||
@ -105,7 +102,7 @@ public class MainCommand extends CommandManager {
|
||||
}
|
||||
|
||||
public static List<String> helpMenu(final PlotPlayer player, final CommandCategory category, int page) {
|
||||
List<Command> commands;
|
||||
List<Command<PlotPlayer>> commands;
|
||||
commands = getCommands(category, player);
|
||||
// final int totalPages = ((int) Math.ceil(12 * (commands.size()) /
|
||||
// 100));
|
||||
@ -122,7 +119,7 @@ public class MainCommand extends CommandManager {
|
||||
help.add(C.HELP_HEADER.s());
|
||||
// HELP_CATEGORY("&cCategory: &6%category%&c, Page: %current%&c/&6%max%&c, Displaying: &6%dis%&c/&6%total%"),
|
||||
help.add(C.HELP_CATEGORY.s().replace("%category%", category == null ? "All" : category.toString()).replace("%current%", "" + (page + 1)).replace("%max%", "" + (totalPages)).replace("%dis%", "" + perPage).replace("%total%", "" + commands.size()));
|
||||
Command cmd;
|
||||
Command<PlotPlayer> cmd;
|
||||
final int start = page * perPage;
|
||||
for (int x = start; x < max; x++) {
|
||||
cmd = commands.get(x);
|
||||
@ -230,7 +227,6 @@ public class MainCommand extends CommandManager {
|
||||
displayHelp(player, category, help_index);
|
||||
return true;
|
||||
}
|
||||
PlotPlayer caller;
|
||||
StringBuilder builder = new StringBuilder(cmd).append(" ");
|
||||
Iterator<String> iterator = Arrays.asList(args).iterator();
|
||||
while (iterator.hasNext()) {
|
||||
@ -240,31 +236,6 @@ public class MainCommand extends CommandManager {
|
||||
}
|
||||
}
|
||||
instance.handle(player, builder.toString());
|
||||
// for (final SubCommand command : subCommands) {
|
||||
// if (command.cmd.equalsIgnoreCase(args[0]) || command.alias.contains(args[0].toLowerCase())) {
|
||||
// final String[] arguments = new String[args.length - 1];
|
||||
// System.arraycopy(args, 1, arguments, 0, args.length - 1);
|
||||
// if (command.permission.hasPermissipon(player)) {
|
||||
// if ((player != null) || !command.isPlayer) {
|
||||
// return command.execute(player, arguments);
|
||||
// } else {
|
||||
// return !MainUtil.sendMessage(null, C.IS_CONSOLE);
|
||||
// }
|
||||
// } else {
|
||||
// return no_permission(player, command.permission.permission.toLowerCase());
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
// MainUtil.sendMessage(player, C.NOT_VALID_SUBCOMMAND);
|
||||
// final String[] commands = new String[subCommands.size()];
|
||||
// for (int x = 0; x < subCommands.size(); x++) {
|
||||
// commands[x] = subCommands.get(x).cmd;
|
||||
// }
|
||||
// /* Let's try to get a proper usage string */
|
||||
// final String command = new StringComparison(args[0], commands).getBestMatch();
|
||||
// return MainUtil.sendMessage(player, C.DID_YOU_MEAN, "/plot " + command);
|
||||
// PlayerFunctions.sendMessage(player, C.DID_YOU_MEAN, new
|
||||
// StringComparsion(args[0], commands).getBestMatch());
|
||||
return true;
|
||||
}
|
||||
|
||||
@ -272,30 +243,27 @@ public class MainCommand extends CommandManager {
|
||||
public int handle(PlotPlayer plr, String input) {
|
||||
String[] parts = input.split(" ");
|
||||
String[] args;
|
||||
String command = parts[0].toLowerCase();
|
||||
String label;
|
||||
if (parts.length == 1) {
|
||||
label = null;
|
||||
args = new String[0];
|
||||
} else {
|
||||
args = new String[parts.length - 1];
|
||||
System.arraycopy(parts, 1, args, 0, args.length);
|
||||
label = parts[1];
|
||||
args = new String[parts.length - 2];
|
||||
System.arraycopy(parts, 2, args, 0, args.length);
|
||||
}
|
||||
Command cmd = null;
|
||||
System.out.print(command);
|
||||
System.out.print(StringMan.join(commands.entrySet(), ", "));
|
||||
cmd = this.commands.get(command);
|
||||
Command<PlotPlayer> cmd = null;
|
||||
cmd = this.commands.get(label);
|
||||
if (cmd == null) {
|
||||
MainUtil.sendMessage(plr, C.NOT_VALID_SUBCOMMAND);
|
||||
{
|
||||
final String[] commands = new String[this.commands.size()];
|
||||
for (int i = 0; i < commands.length; i++) {
|
||||
commands[i] = this.commands.get(i).getCommand();
|
||||
}
|
||||
final String bestMatch = new StringComparison<String>(args[0], commands).getBestMatch();
|
||||
MainUtil.sendMessage(plr, C.DID_YOU_MEAN, "/plot " + bestMatch);
|
||||
ArrayList<Command<PlotPlayer>> cmds = getCommands();
|
||||
cmd = new StringComparison<Command<PlotPlayer>>(args[0], cmds).getMatchObject();
|
||||
MainUtil.sendMessage(plr, C.DID_YOU_MEAN, cmd.getUsage());
|
||||
}
|
||||
return CommandHandlingOutput.NOT_FOUND;
|
||||
}
|
||||
if (cmd.getRequiredType().allows(plr)) {
|
||||
if (!cmd.getRequiredType().allows(plr)) {
|
||||
if (ConsolePlayer.isConsole(plr)) {
|
||||
MainUtil.sendMessage(plr, C.IS_CONSOLE);
|
||||
} else {
|
||||
@ -307,7 +275,7 @@ public class MainCommand extends CommandManager {
|
||||
MainUtil.sendMessage(plr, C.NO_PERMISSION, cmd.getPermission());
|
||||
return CommandHandlingOutput.NOT_PERMITTED;
|
||||
}
|
||||
Argument[] requiredArguments = cmd.getRequiredArguments();
|
||||
Argument<?>[] requiredArguments = cmd.getRequiredArguments();
|
||||
if (requiredArguments != null && requiredArguments.length > 0) {
|
||||
boolean success = true;
|
||||
if (args.length < requiredArguments.length) {
|
||||
|
@ -1,23 +1,18 @@
|
||||
package com.intellectualcrafters.plot.commands;
|
||||
|
||||
import com.intellectualcrafters.plot.object.ConsolePlayer;
|
||||
import com.intellectualcrafters.plot.object.PlotPlayer;
|
||||
import com.intellectualsites.commands.CommandCaller;
|
||||
|
||||
public enum RequiredType {
|
||||
CONSOLE,
|
||||
PLAYER,
|
||||
NONE;
|
||||
|
||||
public boolean allows(PlotPlayer player) {
|
||||
public boolean allows(CommandCaller player) {
|
||||
switch (this) {
|
||||
case NONE:
|
||||
return true;
|
||||
case PLAYER:
|
||||
return !ConsolePlayer.isConsole(player);
|
||||
case CONSOLE:
|
||||
return ConsolePlayer.isConsole(player);
|
||||
default:
|
||||
return false;
|
||||
return this == player.getSuperCaller();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -27,9 +27,9 @@ import java.util.HashMap;
|
||||
import java.util.UUID;
|
||||
|
||||
import com.intellectualcrafters.plot.PS;
|
||||
|
||||
import com.intellectualcrafters.plot.config.C;
|
||||
import com.intellectualcrafters.plot.config.Settings;
|
||||
import com.intellectualcrafters.plot.object.ConsolePlayer;
|
||||
import com.intellectualcrafters.plot.object.Location;
|
||||
import com.intellectualcrafters.plot.object.Plot;
|
||||
import com.intellectualcrafters.plot.object.PlotId;
|
||||
@ -142,10 +142,6 @@ public class SchematicCmd extends SubCommand {
|
||||
break;
|
||||
}
|
||||
case "test": {
|
||||
if (plr == null) {
|
||||
PS.log(C.IS_CONSOLE.s());
|
||||
return false;
|
||||
}
|
||||
if (!Permissions.hasPermission(plr, "plots.schematic.test")) {
|
||||
MainUtil.sendMessage(plr, C.NO_PERMISSION, "plots.schematic.test");
|
||||
return false;
|
||||
@ -178,7 +174,7 @@ public class SchematicCmd extends SubCommand {
|
||||
}
|
||||
case "saveall":
|
||||
case "exportall": {
|
||||
if (plr != null) {
|
||||
if (!ConsolePlayer.isConsole(plr)) {
|
||||
MainUtil.sendMessage(plr, C.NOT_CONSOLE);
|
||||
return false;
|
||||
}
|
||||
@ -220,43 +216,21 @@ public class SchematicCmd extends SubCommand {
|
||||
}
|
||||
final String world;
|
||||
final Plot p2;
|
||||
if (plr != null) {
|
||||
final Location loc = plr.getLocation();
|
||||
final Plot plot = MainUtil.getPlot(loc);
|
||||
if (plot == null) {
|
||||
return !sendMessage(plr, C.NOT_IN_PLOT);
|
||||
}
|
||||
if (!plot.hasOwner()) {
|
||||
MainUtil.sendMessage(plr, C.PLOT_UNOWNED);
|
||||
return false;
|
||||
}
|
||||
if (!plot.isOwner(plr.getUUID()) && !Permissions.hasPermission(plr, "plots.admin.command.schematic.save")) {
|
||||
MainUtil.sendMessage(plr, C.NO_PLOT_PERMS);
|
||||
return false;
|
||||
}
|
||||
p2 = plot;
|
||||
world = loc.getWorld();
|
||||
} else {
|
||||
if (args.length == 3) {
|
||||
try {
|
||||
world = args[1];
|
||||
final String[] split = args[2].split(";");
|
||||
final PlotId i = new PlotId(Integer.parseInt(split[0]), Integer.parseInt(split[1]));
|
||||
if ((PS.get().getPlots(world) == null) || (PS.get().getPlots(world).get(i) == null)) {
|
||||
MainUtil.sendMessage(null, "&cInvalid world or id. Use &7/plots sch save <world> <id>");
|
||||
return false;
|
||||
}
|
||||
p2 = PS.get().getPlots(world).get(i);
|
||||
} catch (final Exception e) {
|
||||
MainUtil.sendMessage(null, "&cInvalid world or id. Use &7/plots sch save <world> <id>");
|
||||
return false;
|
||||
}
|
||||
} else {
|
||||
MainUtil.sendMessage(null, "&cInvalid world or id. Use &7/plots sch save <world> <id>");
|
||||
return false;
|
||||
}
|
||||
final Location loc = plr.getLocation();
|
||||
final Plot plot = MainUtil.getPlot(loc);
|
||||
if (plot == null) {
|
||||
return !sendMessage(plr, C.NOT_IN_PLOT);
|
||||
}
|
||||
|
||||
if (!plot.hasOwner()) {
|
||||
MainUtil.sendMessage(plr, C.PLOT_UNOWNED);
|
||||
return false;
|
||||
}
|
||||
if (!plot.isOwner(plr.getUUID()) && !Permissions.hasPermission(plr, "plots.admin.command.schematic.save")) {
|
||||
MainUtil.sendMessage(plr, C.NO_PLOT_PERMS);
|
||||
return false;
|
||||
}
|
||||
p2 = plot;
|
||||
world = loc.getWorld();
|
||||
Collection<Plot> plots = new ArrayList<Plot>();
|
||||
plots.add(p2);
|
||||
boolean result = SchematicHandler.manager.exportAll(plots, null, null, new Runnable() {
|
||||
|
@ -26,6 +26,8 @@ import java.util.List;
|
||||
import java.util.Map.Entry;
|
||||
|
||||
|
||||
|
||||
import com.intellectualsites.commands.CommandCaller;
|
||||
import com.intellectualsites.commands.CommandDeclaration;
|
||||
import com.intellectualcrafters.plot.object.PlotPlayer;
|
||||
|
||||
@ -76,13 +78,7 @@ public class Setup extends SubCommand {
|
||||
@Override
|
||||
public boolean onCommand(final PlotPlayer plr, final String[] args) {
|
||||
// going through setup
|
||||
String name;
|
||||
if (plr == null) {
|
||||
name = "*";
|
||||
}
|
||||
else {
|
||||
name = plr.getName();
|
||||
}
|
||||
String name = plr.getName();
|
||||
if (!SetupUtils.setupMap.containsKey(name)) {
|
||||
final SetupObject object = new SetupObject();
|
||||
SetupUtils.setupMap.put(name, object);
|
||||
@ -247,9 +243,7 @@ public class Setup extends SubCommand {
|
||||
world = object.setupManager.setupWorld(object);
|
||||
}
|
||||
try {
|
||||
if (plr != null) {
|
||||
plr.teleport(BlockManager.manager.getSpawn(world));
|
||||
}
|
||||
plr.teleport(BlockManager.manager.getSpawn(world));
|
||||
} catch (final Exception e) {
|
||||
plr.sendMessage("&cAn error occured. See console for more information");
|
||||
e.printStackTrace();
|
||||
@ -260,5 +254,4 @@ public class Setup extends SubCommand {
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -30,7 +30,7 @@ import com.intellectualcrafters.plot.util.MainUtil;
|
||||
* @author Citymonstret
|
||||
*/
|
||||
@SuppressWarnings({ "deprecation", "unused" })
|
||||
public abstract class SubCommand extends com.intellectualsites.commands.Command {
|
||||
public abstract class SubCommand extends com.intellectualsites.commands.Command<PlotPlayer> {
|
||||
|
||||
/**
|
||||
* The category
|
||||
@ -46,9 +46,8 @@ public abstract class SubCommand extends com.intellectualsites.commands.Command
|
||||
*
|
||||
* @see com.intellectualcrafters.plot.util.MainUtil#sendMessage(PlotPlayer, C, String...)
|
||||
*/
|
||||
public boolean sendMessage(final PlotPlayer plr, final C c, final String... args) {
|
||||
MainUtil.sendMessage(plr, c, args);
|
||||
public boolean sendMessage(PlotPlayer plr, final C c, final String... args) {
|
||||
c.send(plr, args);
|
||||
return true;
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -180,9 +180,7 @@ public class Template extends SubCommand {
|
||||
setup.world = world;
|
||||
SetupUtils.manager.setupWorld(setup);
|
||||
MainUtil.sendMessage(plr, "Done!");
|
||||
if (plr != null) {
|
||||
plr.teleport(BlockManager.manager.getSpawn(world));
|
||||
}
|
||||
plr.teleport(BlockManager.manager.getSpawn(world));
|
||||
return true;
|
||||
}
|
||||
case "export": {
|
||||
|
@ -74,42 +74,35 @@ public class list extends SubCommand {
|
||||
|
||||
private String[] getArgumentList(PlotPlayer player) {
|
||||
List<String> args = new ArrayList<>();
|
||||
if (player == null) {
|
||||
args.addAll(Arrays.asList("world", "all", "unowned", "unknown", "top", "<player", "<world>"));
|
||||
if (EconHandler.manager != null) {
|
||||
args.add("forsale");
|
||||
}
|
||||
} else {
|
||||
if (EconHandler.manager != null && player.hasPermission("plots.list.forsale")) {
|
||||
args.add("forsale");
|
||||
}
|
||||
if (player.hasPermission("plots.list.mine")) {
|
||||
args.add("mine");
|
||||
}
|
||||
if (player.hasPermission("plots.list.shared")) {
|
||||
args.add("shared");
|
||||
}
|
||||
if (player.hasPermission("plots.list.world")) {
|
||||
args.add("world");
|
||||
}
|
||||
if (player.hasPermission("plots.list.top")) {
|
||||
args.add("top");
|
||||
}
|
||||
if (player.hasPermission("plots.list..all")) {
|
||||
args.add("all");
|
||||
}
|
||||
if (player.hasPermission("plots.list.unowned")) {
|
||||
args.add("unowned");
|
||||
}
|
||||
if (player.hasPermission("plots.list.unknown")) {
|
||||
args.add("unknown");
|
||||
}
|
||||
if (player.hasPermission("plots.list.player")) {
|
||||
args.add("<player>");
|
||||
}
|
||||
if (player.hasPermission("plots.list.world")) {
|
||||
args.add("<world>");
|
||||
}
|
||||
if (EconHandler.manager != null && player.hasPermission("plots.list.forsale")) {
|
||||
args.add("forsale");
|
||||
}
|
||||
if (player.hasPermission("plots.list.mine")) {
|
||||
args.add("mine");
|
||||
}
|
||||
if (player.hasPermission("plots.list.shared")) {
|
||||
args.add("shared");
|
||||
}
|
||||
if (player.hasPermission("plots.list.world")) {
|
||||
args.add("world");
|
||||
}
|
||||
if (player.hasPermission("plots.list.top")) {
|
||||
args.add("top");
|
||||
}
|
||||
if (player.hasPermission("plots.list..all")) {
|
||||
args.add("all");
|
||||
}
|
||||
if (player.hasPermission("plots.list.unowned")) {
|
||||
args.add("unowned");
|
||||
}
|
||||
if (player.hasPermission("plots.list.unknown")) {
|
||||
args.add("unknown");
|
||||
}
|
||||
if (player.hasPermission("plots.list.player")) {
|
||||
args.add("<player>");
|
||||
}
|
||||
if (player.hasPermission("plots.list.world")) {
|
||||
args.add("<world>");
|
||||
}
|
||||
return args.toArray(new String[args.size()]);
|
||||
}
|
||||
@ -139,26 +132,11 @@ public class list extends SubCommand {
|
||||
|
||||
List<Plot> plots = null;
|
||||
|
||||
String world;
|
||||
if (plr != null) {
|
||||
world = plr.getLocation().getWorld();
|
||||
}
|
||||
else {
|
||||
Set<String> worlds = PS.get().getPlotWorlds();
|
||||
if (worlds.size() == 0) {
|
||||
world = "world";
|
||||
}
|
||||
else {
|
||||
world = worlds.iterator().next();
|
||||
}
|
||||
}
|
||||
String world = plr.getLocation().getWorld();
|
||||
String arg = args[0].toLowerCase();
|
||||
boolean sort = true;
|
||||
switch (arg) {
|
||||
case "mine": {
|
||||
if (plr == null) {
|
||||
break;
|
||||
}
|
||||
if (!Permissions.hasPermission(plr, "plots.list.mine")) {
|
||||
MainUtil.sendMessage(plr, C.NO_PERMISSION, "plots.list.mine");
|
||||
return false;
|
||||
@ -167,9 +145,6 @@ public class list extends SubCommand {
|
||||
break;
|
||||
}
|
||||
case "shared": {
|
||||
if (plr == null) {
|
||||
break;
|
||||
}
|
||||
if (!Permissions.hasPermission(plr, "plots.list.shared")) {
|
||||
MainUtil.sendMessage(plr, C.NO_PERMISSION, "plots.list.shared");
|
||||
return false;
|
||||
|
@ -36,6 +36,7 @@ import com.intellectualcrafters.plot.PS;
|
||||
import com.intellectualcrafters.plot.object.PlotPlayer;
|
||||
import com.intellectualcrafters.plot.util.MainUtil;
|
||||
import com.intellectualcrafters.plot.util.StringMan;
|
||||
import com.intellectualsites.commands.CommandCaller;
|
||||
|
||||
/**
|
||||
* Captions class.
|
||||
@ -692,12 +693,12 @@ public enum C {
|
||||
return cat;
|
||||
}
|
||||
|
||||
public void send(PlotPlayer plr, String... args) {
|
||||
public void send(CommandCaller plr, String... args) {
|
||||
if (plr == null) {
|
||||
MainUtil.sendConsoleMessage(this, args);
|
||||
}
|
||||
else {
|
||||
MainUtil.sendMessage(plr, this, args);
|
||||
plr.sendMessage(this, args);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -5,7 +5,10 @@ import java.util.Set;
|
||||
import java.util.UUID;
|
||||
|
||||
import com.intellectualcrafters.plot.PS;
|
||||
import com.intellectualcrafters.plot.commands.RequiredType;
|
||||
import com.intellectualcrafters.plot.config.C;
|
||||
import com.intellectualcrafters.plot.database.DBFunc;
|
||||
import com.intellectualcrafters.plot.util.MainUtil;
|
||||
import com.plotsquared.bukkit.util.bukkit.BukkitUtil;
|
||||
|
||||
public class ConsolePlayer implements PlotPlayer {
|
||||
@ -67,6 +70,11 @@ public class ConsolePlayer implements PlotPlayer {
|
||||
public void sendMessage(String message) {
|
||||
PS.log(message);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void sendMessage(C c, String... args) {
|
||||
MainUtil.sendMessage(this, c, args);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void teleport(Location loc) {
|
||||
@ -122,5 +130,10 @@ public class ConsolePlayer implements PlotPlayer {
|
||||
public void deleteMeta(String key) {
|
||||
this.meta.remove(key);
|
||||
}
|
||||
|
||||
@Override
|
||||
public RequiredType getSuperCaller() {
|
||||
return RequiredType.CONSOLE;
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -2,12 +2,14 @@ package com.intellectualcrafters.plot.object;
|
||||
|
||||
import java.util.UUID;
|
||||
|
||||
import com.intellectualsites.commands.CommandCaller;
|
||||
|
||||
/**
|
||||
* Created 2015-02-20 for PlotSquared
|
||||
*
|
||||
* @author Citymonstret
|
||||
*/
|
||||
public interface PlotPlayer {
|
||||
public interface PlotPlayer extends CommandCaller {
|
||||
|
||||
public long getPreviousLogin();
|
||||
|
||||
|
@ -8,16 +8,14 @@ import java.util.Set;
|
||||
|
||||
import com.intellectualcrafters.plot.commands.CommandCategory;
|
||||
import com.intellectualcrafters.plot.commands.RequiredType;
|
||||
import com.intellectualcrafters.plot.object.Plot;
|
||||
import com.intellectualcrafters.plot.object.PlotPlayer;
|
||||
|
||||
public abstract class Command extends CommandManager {
|
||||
public abstract class Command<E extends CommandCaller> extends CommandManager {
|
||||
|
||||
private RequiredType requiredType = RequiredType.NONE;
|
||||
private String command, usage = "", description = "", permission = "";
|
||||
private Set<String> aliases = new HashSet<>();
|
||||
private CommandCategory category;
|
||||
protected Argument[] requiredArguments;
|
||||
protected Argument<?>[] requiredArguments;
|
||||
|
||||
public Command() {
|
||||
super(null, new ArrayList<Command>());
|
||||
@ -97,9 +95,9 @@ public abstract class Command extends CommandManager {
|
||||
return this.command;
|
||||
}
|
||||
|
||||
public abstract boolean onCommand(PlotPlayer plr, String[] arguments);
|
||||
public abstract boolean onCommand(E plr, String[] arguments);
|
||||
|
||||
final public int handle(PlotPlayer plr, String[] args) {
|
||||
final public int handle(E plr, String[] args) {
|
||||
if (args.length == 0) {
|
||||
return super.handle(plr, "");
|
||||
}
|
||||
@ -131,7 +129,7 @@ public abstract class Command extends CommandManager {
|
||||
return this.aliases;
|
||||
}
|
||||
|
||||
final public Argument[] getRequiredArguments() {
|
||||
final public Argument<?>[] getRequiredArguments() {
|
||||
return this.requiredArguments;
|
||||
}
|
||||
|
||||
@ -150,7 +148,7 @@ public abstract class Command extends CommandManager {
|
||||
if (getClass() != obj.getClass()) {
|
||||
return false;
|
||||
}
|
||||
final Command other = (Command) obj;
|
||||
final Command<?> other = (Command<?>) obj;
|
||||
if (this.hashCode() != other.hashCode()) {
|
||||
return false;
|
||||
}
|
||||
|
@ -0,0 +1,14 @@
|
||||
package com.intellectualsites.commands;
|
||||
|
||||
import com.intellectualcrafters.plot.commands.RequiredType;
|
||||
import com.intellectualcrafters.plot.config.C;
|
||||
|
||||
public interface CommandCaller {
|
||||
void sendMessage(final String message);
|
||||
|
||||
void sendMessage(C c, String ... args);
|
||||
|
||||
boolean hasPermission(final String perm);
|
||||
|
||||
RequiredType getSuperCaller();
|
||||
}
|
@ -5,40 +5,41 @@ import java.util.Collection;
|
||||
import java.util.Collections;
|
||||
import java.util.Comparator;
|
||||
import java.util.List;
|
||||
import java.util.Set;
|
||||
import java.util.concurrent.ConcurrentHashMap;
|
||||
|
||||
import com.intellectualcrafters.plot.PS;
|
||||
import com.intellectualcrafters.plot.commands.RequiredType;
|
||||
import com.intellectualcrafters.plot.config.C;
|
||||
import com.intellectualcrafters.plot.object.ConsolePlayer;
|
||||
import com.intellectualcrafters.plot.object.PlotPlayer;
|
||||
import com.intellectualcrafters.plot.util.MainUtil;
|
||||
|
||||
@SuppressWarnings("unused")
|
||||
public class CommandManager {
|
||||
public class CommandManager<T extends CommandCaller> {
|
||||
|
||||
protected final ConcurrentHashMap<String, Command> commands;
|
||||
protected final ConcurrentHashMap<String, Command<T>> commands;
|
||||
protected final Character initialCharacter;
|
||||
|
||||
public CommandManager() {
|
||||
this('/', new ArrayList<Command>());
|
||||
this('/', new ArrayList<Command<T>>());
|
||||
}
|
||||
|
||||
public CommandManager(Character initialCharacter, List<Command> commands) {
|
||||
public CommandManager(Character initialCharacter, List<Command<T>> commands) {
|
||||
this.commands = new ConcurrentHashMap<>();
|
||||
for (Command command : commands) {
|
||||
for (Command<T> command : commands) {
|
||||
addCommand(command);
|
||||
}
|
||||
this.initialCharacter = initialCharacter;
|
||||
}
|
||||
|
||||
final public void addCommand(final Command command) {
|
||||
final public void addCommand(final Command<T> command) {
|
||||
this.commands.put(command.getCommand().toLowerCase(), command);
|
||||
for (String alias : command.getAliases()) {
|
||||
this.commands.put(alias.toLowerCase(), command);
|
||||
}
|
||||
}
|
||||
|
||||
final public boolean createCommand(final Command command) {
|
||||
final public boolean createCommand(final Command<T> command) {
|
||||
try {
|
||||
command.create();
|
||||
} catch(final Exception e) {
|
||||
@ -52,11 +53,11 @@ public class CommandManager {
|
||||
return false;
|
||||
}
|
||||
|
||||
final public ArrayList<Command> getCommands() {
|
||||
ArrayList<Command> result = new ArrayList<>(this.commands.values());
|
||||
Collections.sort(result, new Comparator<Command>() {
|
||||
final public ArrayList<Command<T>> getCommands() {
|
||||
ArrayList<Command<T>> result = new ArrayList<>(this.commands.values());
|
||||
Collections.sort(result, new Comparator<Command<T>>() {
|
||||
@Override
|
||||
public int compare(Command a, Command b) {
|
||||
public int compare(Command<T> a, Command<T> b) {
|
||||
if (a == b) {
|
||||
return 0;
|
||||
}
|
||||
@ -71,8 +72,16 @@ public class CommandManager {
|
||||
});
|
||||
return result;
|
||||
}
|
||||
|
||||
final public ArrayList<String> getCommandLabels(ArrayList<Command<T>> cmds) {
|
||||
ArrayList<String> labels = new ArrayList<>(cmds.size());
|
||||
for (Command<T> cmd : cmds) {
|
||||
labels.add(cmd.getCommand());
|
||||
}
|
||||
return labels;
|
||||
}
|
||||
|
||||
public int handle(PlotPlayer plr, String input) {
|
||||
public int handle(T plr, String input) {
|
||||
if (initialCharacter != null && !input.startsWith(initialCharacter + "")) {
|
||||
return CommandHandlingOutput.NOT_COMMAND;
|
||||
}
|
||||
@ -86,7 +95,7 @@ public class CommandManager {
|
||||
args = new String[parts.length - 1];
|
||||
System.arraycopy(parts, 1, args, 0, args.length);
|
||||
}
|
||||
Command cmd = null;
|
||||
Command<T> cmd = null;
|
||||
cmd = commands.get(command);
|
||||
if (cmd == null) {
|
||||
return CommandHandlingOutput.NOT_FOUND;
|
||||
@ -97,7 +106,7 @@ public class CommandManager {
|
||||
if (!plr.hasPermission(cmd.getPermission())) {
|
||||
return CommandHandlingOutput.NOT_PERMITTED;
|
||||
}
|
||||
Argument[] requiredArguments = cmd.getRequiredArguments();
|
||||
Argument<?>[] requiredArguments = cmd.getRequiredArguments();
|
||||
if (requiredArguments != null && requiredArguments.length > 0) {
|
||||
boolean success = true;
|
||||
if (args.length < requiredArguments.length) {
|
||||
@ -121,7 +130,7 @@ public class CommandManager {
|
||||
if (!a) {
|
||||
String usage = cmd.getUsage();
|
||||
if (usage != null && !usage.isEmpty()) {
|
||||
MainUtil.sendMessage(plr, usage);
|
||||
plr.sendMessage(usage);
|
||||
}
|
||||
return CommandHandlingOutput.WRONG_USAGE;
|
||||
}
|
||||
|
@ -53,11 +53,11 @@ public class BukkitCommand implements CommandExecutor, TabCompleter {
|
||||
return null;
|
||||
}
|
||||
final Set<String> tabOptions = new HashSet<>();
|
||||
ArrayList<Command> commands = MainCommand.instance.getCommands();
|
||||
ArrayList<Command<PlotPlayer>> commands = MainCommand.instance.getCommands();
|
||||
String best = new StringComparison(strings[0], commands).getBestMatch();
|
||||
tabOptions.add(best);
|
||||
final String arg = strings[0].toLowerCase();
|
||||
for (final Command cmd : MainCommand.instance.getCommands()) {
|
||||
for (final Command<PlotPlayer> cmd : MainCommand.instance.getCommands()) {
|
||||
String label = cmd.getCommand();
|
||||
if (!label.equalsIgnoreCase(best)) {
|
||||
if (label.startsWith(arg)) {
|
||||
|
@ -12,8 +12,11 @@ import org.bukkit.entity.Player;
|
||||
import org.bukkit.permissions.Permission;
|
||||
import org.bukkit.permissions.PermissionDefault;
|
||||
|
||||
import com.intellectualcrafters.plot.commands.RequiredType;
|
||||
import com.intellectualcrafters.plot.config.C;
|
||||
import com.intellectualcrafters.plot.config.Settings;
|
||||
import com.intellectualcrafters.plot.util.EconHandler;
|
||||
import com.intellectualcrafters.plot.util.MainUtil;
|
||||
import com.intellectualcrafters.plot.util.UUIDHandler;
|
||||
import com.plotsquared.bukkit.util.bukkit.BukkitUtil;
|
||||
|
||||
@ -82,6 +85,11 @@ public class BukkitPlayer implements PlotPlayer {
|
||||
this.player.sendMessage(message);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void sendMessage(C c, String... args) {
|
||||
MainUtil.sendMessage(this, c, args);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void teleport(final Location loc) {
|
||||
this.player.teleport(new org.bukkit.Location(BukkitUtil.getWorld(loc.getWorld()), loc.getX() + 0.5, loc.getY(), loc.getZ() + 0.5, loc.getYaw(), loc.getPitch()));
|
||||
@ -191,4 +199,9 @@ public class BukkitPlayer implements PlotPlayer {
|
||||
public void saveData() {
|
||||
player.saveData();
|
||||
}
|
||||
|
||||
@Override
|
||||
public RequiredType getSuperCaller() {
|
||||
return RequiredType.PLAYER;
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user