2014-11-08 20:27:09 +01:00
|
|
|
////////////////////////////////////////////////////////////////////////////////////////////////////
|
|
|
|
// 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 /
|
|
|
|
////////////////////////////////////////////////////////////////////////////////////////////////////
|
2014-09-22 13:02:14 +02:00
|
|
|
|
|
|
|
package com.intellectualcrafters.plot.commands;
|
|
|
|
|
2014-11-16 10:48:18 +01:00
|
|
|
import com.intellectualcrafters.plot.config.C;
|
|
|
|
import com.intellectualcrafters.plot.util.PlayerFunctions;
|
2014-12-15 12:33:53 +11:00
|
|
|
|
2014-11-08 20:27:09 +01:00
|
|
|
import org.bukkit.entity.Player;
|
2014-09-22 13:02:14 +02:00
|
|
|
|
2014-12-15 12:33:53 +11:00
|
|
|
import java.util.ArrayList;
|
|
|
|
import java.util.Arrays;
|
|
|
|
|
2014-09-22 13:02:14 +02:00
|
|
|
/**
|
|
|
|
* SubCommand class
|
2014-10-11 00:33:10 -07:00
|
|
|
*
|
2014-09-22 13:02:14 +02:00
|
|
|
* @author Citymonstret
|
|
|
|
*/
|
2014-11-20 00:00:38 +01:00
|
|
|
@SuppressWarnings({"deprecation", "unused"})
|
2014-09-22 13:02:14 +02:00
|
|
|
public abstract class SubCommand {
|
2014-11-20 00:00:38 +01:00
|
|
|
|
2014-11-05 14:42:08 +11:00
|
|
|
/**
|
|
|
|
* Command
|
|
|
|
*/
|
2014-11-20 00:00:38 +01:00
|
|
|
public final String cmd;
|
2014-11-05 14:42:08 +11:00
|
|
|
/**
|
|
|
|
* Permission node
|
|
|
|
*/
|
2014-11-20 00:00:38 +01:00
|
|
|
public final CommandPermission permission;
|
2014-11-05 14:42:08 +11:00
|
|
|
/**
|
|
|
|
* Simple description
|
|
|
|
*/
|
2014-11-20 00:00:38 +01:00
|
|
|
public final String description;
|
2014-11-05 14:42:08 +11:00
|
|
|
/**
|
2014-12-15 12:33:53 +11:00
|
|
|
* Aliases
|
2014-11-05 14:42:08 +11:00
|
|
|
*/
|
2014-12-15 12:33:53 +11:00
|
|
|
public final ArrayList<String> alias;
|
2014-11-05 14:42:08 +11:00
|
|
|
/**
|
|
|
|
* Command usage
|
|
|
|
*/
|
2014-11-20 00:00:38 +01:00
|
|
|
public final String usage;
|
|
|
|
/**
|
|
|
|
* The category
|
|
|
|
*/
|
|
|
|
public final CommandCategory category;
|
|
|
|
/**
|
|
|
|
* Is this a player-online command?
|
|
|
|
*/
|
2014-11-21 23:45:46 +01:00
|
|
|
public final boolean isPlayer;
|
2014-09-22 13:02:14 +02:00
|
|
|
|
2014-11-05 14:42:08 +11:00
|
|
|
/**
|
2014-11-08 20:27:09 +01:00
|
|
|
* @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
|
2014-12-15 12:33:53 +11:00
|
|
|
* @param category CommandCategory. Pick whichever is closest to what you want.
|
2014-11-05 14:42:08 +11:00
|
|
|
*/
|
|
|
|
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;
|
2014-12-15 12:33:53 +11:00
|
|
|
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));
|
2014-11-05 14:42:08 +11:00
|
|
|
this.usage = usage;
|
|
|
|
this.category = category;
|
|
|
|
this.isPlayer = isPlayer;
|
|
|
|
}
|
2014-09-22 13:02:14 +02:00
|
|
|
|
2014-11-05 14:42:08 +11:00
|
|
|
/**
|
2014-11-08 20:27:09 +01:00
|
|
|
* @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.
|
2014-11-05 14:42:08 +11:00
|
|
|
*/
|
|
|
|
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();
|
2014-12-15 12:33:53 +11:00
|
|
|
this.alias = new ArrayList<String>();
|
|
|
|
this.alias.add(command.getAlias());
|
2014-11-05 14:42:08 +11:00
|
|
|
this.description = description;
|
|
|
|
this.usage = usage;
|
|
|
|
this.category = category;
|
|
|
|
this.isPlayer = isPlayer;
|
|
|
|
}
|
2014-09-22 13:02:14 +02:00
|
|
|
|
2014-11-05 14:42:08 +11:00
|
|
|
/**
|
|
|
|
* Execute.
|
|
|
|
*
|
2014-11-08 20:27:09 +01:00
|
|
|
* @param plr executor
|
|
|
|
* @param args arguments
|
2014-11-05 14:42:08 +11:00
|
|
|
* @return true on success, false on failure
|
|
|
|
*/
|
|
|
|
public abstract boolean execute(final Player plr, final String... args);
|
2014-09-24 22:21:43 +10:00
|
|
|
|
2014-11-20 00:00:38 +01:00
|
|
|
/**
|
|
|
|
* Execute the command as console
|
|
|
|
*
|
|
|
|
* @param args Arguments
|
|
|
|
*/
|
2014-11-05 14:42:08 +11:00
|
|
|
public void executeConsole(final String... args) {
|
|
|
|
this.execute(null, args);
|
|
|
|
}
|
2014-09-22 13:02:14 +02:00
|
|
|
|
2014-11-05 14:42:08 +11:00
|
|
|
/**
|
|
|
|
* Send a message
|
|
|
|
*
|
2014-11-20 00:00:38 +01:00
|
|
|
* @param plr Player who will receive the mssage
|
|
|
|
* @param c Caption
|
|
|
|
* @param args Arguments (%s's)
|
|
|
|
* @see com.intellectualcrafters.plot.util.PlayerFunctions#sendMessage(org.bukkit.entity.Player, com.intellectualcrafters.plot.config.C, String...)
|
2014-11-05 14:42:08 +11:00
|
|
|
*/
|
2014-11-08 20:27:09 +01:00
|
|
|
public boolean sendMessage(final Player plr, final C c, final String... args) {
|
2014-11-05 14:42:08 +11:00
|
|
|
PlayerFunctions.sendMessage(plr, c, args);
|
2014-11-08 20:27:09 +01:00
|
|
|
return true;
|
2014-11-05 14:42:08 +11:00
|
|
|
}
|
2014-09-22 13:02:14 +02:00
|
|
|
|
2014-11-20 00:00:38 +01:00
|
|
|
/**
|
|
|
|
* CommandCategory
|
|
|
|
*
|
|
|
|
* @author Citymonstret
|
|
|
|
* @author Empire92
|
|
|
|
*/
|
2014-11-05 14:42:08 +11:00
|
|
|
public enum CommandCategory {
|
2014-11-20 00:00:38 +01:00
|
|
|
/**
|
|
|
|
* Claiming Commands
|
|
|
|
* <p/>
|
|
|
|
* Such as: /plot claim
|
|
|
|
*/
|
2014-11-05 14:42:08 +11:00
|
|
|
CLAIMING("Claiming"),
|
2014-11-20 00:00:38 +01:00
|
|
|
/**
|
|
|
|
* Teleportation Commands
|
|
|
|
* <p/>
|
|
|
|
* Such as: /plot visit
|
|
|
|
*/
|
2014-11-05 14:42:08 +11:00
|
|
|
TELEPORT("Teleportation"),
|
2014-11-20 00:00:38 +01:00
|
|
|
/**
|
|
|
|
* Action Commands
|
|
|
|
* <p/>
|
|
|
|
* Such as: /plot clear
|
|
|
|
*/
|
2014-11-05 14:42:08 +11:00
|
|
|
ACTIONS("Actions"),
|
2014-11-20 00:00:38 +01:00
|
|
|
/**
|
|
|
|
* Information Commands
|
|
|
|
* <p/>
|
|
|
|
* Such as: /plot info
|
|
|
|
*/
|
2014-11-05 14:42:08 +11:00
|
|
|
INFO("Information"),
|
2014-11-20 00:00:38 +01:00
|
|
|
/**
|
|
|
|
* Debug Commands
|
|
|
|
* <p/>
|
|
|
|
* Such as: /plot debug
|
|
|
|
*/
|
2014-11-05 14:42:08 +11:00
|
|
|
DEBUG("Debug");
|
2014-09-24 22:21:43 +10:00
|
|
|
|
2014-11-20 00:00:38 +01:00
|
|
|
/**
|
|
|
|
* The category name (Readable)
|
|
|
|
*/
|
|
|
|
private final String name;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Constructor
|
|
|
|
*
|
|
|
|
* @param name readable name
|
|
|
|
*/
|
2014-11-05 14:42:08 +11:00
|
|
|
CommandCategory(final String name) {
|
|
|
|
this.name = name;
|
|
|
|
}
|
2014-09-24 22:21:43 +10:00
|
|
|
|
2014-11-05 14:42:08 +11:00
|
|
|
@Override
|
|
|
|
public String toString() {
|
|
|
|
return this.name;
|
|
|
|
}
|
|
|
|
}
|
2014-12-15 12:33:53 +11:00
|
|
|
}
|