Put commands on feet.

* Add a new base class for better sub-command handling also for
tab-completion (AbstractCommand).
* Alter package structure slightly, to group command-classes by purpose.
* Some renaming.
This commit is contained in:
asofold 2013-06-11 20:30:34 +02:00
parent 888c7d937a
commit 8ea5eccaa0
22 changed files with 324 additions and 219 deletions

View File

@ -0,0 +1,156 @@
package fr.neatmonster.nocheatplus.command;
import java.util.Collections;
import java.util.LinkedHashMap;
import java.util.LinkedHashSet;
import java.util.LinkedList;
import java.util.List;
import java.util.Map;
import java.util.Set;
import org.bukkit.ChatColor;
import org.bukkit.command.Command;
import org.bukkit.command.CommandSender;
import org.bukkit.command.TabExecutor;
/**
* Base command class, featuring some features.<br>
* Taken from the Archer plugin (@asofold), extended by aliases.
* @author mc_dev
*
*/
public abstract class AbstractCommand<A> implements TabExecutor{
public static final List<String> noTabChoices = Collections.unmodifiableList(new LinkedList<String>());
/**
* Convenience method: join with a space in between.
* @param args
* @param startIndex
* @return
*/
public static String join(String[] args, int startIndex){
return join(args, startIndex, " ");
}
/**
* Convenience method.
* @param args
* @param startIndex
* @return
*/
public static String join(String[] args, int startIndex, String sep){
final StringBuilder b = new StringBuilder(100);
if (startIndex < args.length) b.append(args[startIndex]);
for (int i = startIndex + 1; i < args.length; i++){
b.append(sep);
b.append(args[i]);
}
return b.toString();
}
////////////////
// Not static.
////////////////
protected final A access;
public final String label;
/** Permission necessary to use this command. May be null. */
public final String permission;
/** Sub commands for delegation. */
protected final Map<String, AbstractCommand<?>> subCommands = new LinkedHashMap<String, AbstractCommand<?>>();
/** The index in args to check for sub-commands. -1 stands for default, either parent + 1 or 0 */
protected int subCommandIndex = -1;
/** Aliases for the command label. */
protected final String[] aliases;
/**
*
* @param access
* @param label Lower-case.
* @param permission
*/
public AbstractCommand(A access, String label, String permission){
this(access, label, permission, null);
}
/**
*
* @param access
* @param label Lower-case.
* @param permission May be null (no permission necessary).
* @param aliases May be null (no aliases). If given, the aliases only take effect for tab completion and selection of sub commands. Lower-case.
*/
public AbstractCommand(A access, String label, String permission, String[] aliases){
this.access = access;
this.label = label;
this.permission = permission;
this.aliases = aliases;
}
public void addSubCommands(AbstractCommand<?>... commands){
for (AbstractCommand<?> subCommand : commands ){
subCommands.put(subCommand.label, subCommand);
if (subCommand.subCommandIndex == -1){
subCommand.subCommandIndex = Math.max(0, this.subCommandIndex) + 1;
}
if (subCommand.aliases != null){
for (final String alias : subCommand.aliases){
if (!subCommands.containsKey(alias)){
subCommands.put(alias, subCommand);
}
}
}
}
}
@Override
public List<String> onTabComplete(CommandSender sender, Command command, String alias, String[] args)
{
final Set<String> choices = new LinkedHashSet<String>(subCommands.size());
int len = args.length;
// Attempt to delegate.
int subCommandIndex = Math.max(0, this.subCommandIndex);
if (len == subCommandIndex || len == subCommandIndex + 1){
String arg = len == subCommandIndex ? "" : args[subCommandIndex].trim().toLowerCase();
for (AbstractCommand<?> cmd : subCommands.values()){
if (cmd.label.startsWith(arg) && (cmd.permission == null || sender.hasPermission(cmd.permission))){
// Only completes the label (!).
choices.add(cmd.label);
}
}
}
else if (len > subCommandIndex + 1){
String arg = args[subCommandIndex].trim().toLowerCase();
AbstractCommand<?> subCommand = subCommands.get(arg);
if (subCommand != null && (subCommand.permission == null || sender.hasPermission(subCommand.permission))){
return subCommand.onTabComplete(sender, command, alias, args);
}
}
// No tab completion by default.
if (choices.isEmpty()) return noTabChoices;
else return new LinkedList<String>(choices);
}
@Override
public boolean onCommand(CommandSender sender, Command command, String alias, String[] args)
{
int len = args.length;
int subCommandIndex = Math.max(0, this.subCommandIndex);
if (len > subCommandIndex){
String arg = args[subCommandIndex].trim().toLowerCase();
AbstractCommand<?> subCommand = subCommands.get(arg);
if (subCommand != null){
if (subCommand.permission != null && !sender.hasPermission(subCommand.permission)){
sender.sendMessage(ChatColor.DARK_RED + "You don't have permission.");
return true;
}
return subCommand.onCommand(sender, command, alias, args);
}
}
// Usage.
return false;
}
}

View File

@ -0,0 +1,26 @@
package fr.neatmonster.nocheatplus.command;
import org.bukkit.ChatColor;
import org.bukkit.plugin.java.JavaPlugin;
/**
* Just an interface for sub commands, for future use.
* @author mc_dev
*
*/
public abstract class BaseCommand extends AbstractCommand<JavaPlugin>{
/** The prefix of every message sent by NoCheatPlus. */
public static final String TAG = ChatColor.RED + "NCP: " + ChatColor.WHITE;
public BaseCommand(JavaPlugin plugin, String label, String permission){
this(plugin, label, permission, null);
}
public BaseCommand(JavaPlugin access, String label, String permission, String[] aliases){
super(access, label, permission, aliases);
}
}

View File

@ -1,87 +0,0 @@
package fr.neatmonster.nocheatplus.command;
import java.util.List;
import org.bukkit.command.Command;
import org.bukkit.command.CommandSender;
import org.bukkit.command.TabExecutor;
import org.bukkit.plugin.Plugin;
import org.bukkit.plugin.java.JavaPlugin;
/**
* Just an interface for sub commands, for future use.
* @author mc_dev
*
*/
public abstract class NCPCommand implements TabExecutor{
protected static final String TAG = CommandHandler.TAG;
/**
* Convenience method: join with a space in between.
* @param args
* @param startIndex
* @return
*/
public static String join(String[] args, int startIndex){
return join(args, startIndex, " ");
}
/**
* Convenience method.
* @param args
* @param startIndex
* @return
*/
public static String join(String[] args, int startIndex, String sep){
StringBuilder b = new StringBuilder(100);
if (startIndex < args.length) b.append(args[startIndex]);
for (int i = startIndex + 1; i < args.length; i++){
b.append(sep);
b.append(args[i]);
}
return b.toString();
}
/** Just a plugin reference. */
protected Plugin plugin;
/** The sub command label. */
public final String label;
/** Command aliases (important if this is a sub-command). */
public final String[] aliases;
/** The command permission. */
public String permission;
public NCPCommand(JavaPlugin plugin, String label, String permission){
this(plugin, label, permission, null);
}
public NCPCommand(JavaPlugin plugin, String label, String permission, String[] aliases){
this.plugin = plugin;
this.label = label;
this.permission = permission;
this.aliases = aliases;
}
/**
* As with CommandExecutor, just to have the argument names correctly.
*/
public abstract boolean onCommand(CommandSender sender, Command command, String label, String[] args);
/**
*
* @param sender
* @param command
* @param alias
* @param args
* @return
*/
public List<String> onTabComplete(CommandSender sender, Command command, String alias, String[] args)
{
return null;
}
}

View File

@ -1,39 +1,31 @@
package fr.neatmonster.nocheatplus.command;
import java.util.ArrayList;
import java.util.Collection;
import java.util.Collections;
import java.util.HashMap;
import java.util.HashSet;
import java.util.LinkedHashSet;
import java.util.List;
import java.util.Map;
import java.util.Set;
import org.bukkit.ChatColor;
import org.bukkit.command.Command;
import org.bukkit.command.CommandSender;
import org.bukkit.command.TabExecutor;
import org.bukkit.event.Event;
import org.bukkit.event.HandlerList;
import org.bukkit.plugin.java.JavaPlugin;
import fr.neatmonster.nocheatplus.command.actions.BanCommand;
import fr.neatmonster.nocheatplus.command.actions.DelayCommand;
import fr.neatmonster.nocheatplus.command.actions.KickCommand;
import fr.neatmonster.nocheatplus.command.actions.KickListCommand;
import fr.neatmonster.nocheatplus.command.actions.TellCommand;
import fr.neatmonster.nocheatplus.command.actions.TempKickCommand;
import fr.neatmonster.nocheatplus.command.actions.UnKickCommand;
import fr.neatmonster.nocheatplus.command.actions.delay.DelayCommand;
import fr.neatmonster.nocheatplus.command.admin.CommandsCommand;
import fr.neatmonster.nocheatplus.command.admin.ExemptCommand;
import fr.neatmonster.nocheatplus.command.admin.ExemptionsCommand;
import fr.neatmonster.nocheatplus.command.admin.InfoCommand;
import fr.neatmonster.nocheatplus.command.admin.LagCommand;
import fr.neatmonster.nocheatplus.command.admin.NCPVersionCommand;
import fr.neatmonster.nocheatplus.command.admin.ReloadCommand;
import fr.neatmonster.nocheatplus.command.admin.RemovePlayerCommand;
import fr.neatmonster.nocheatplus.command.admin.UnexemptCommand;
import fr.neatmonster.nocheatplus.command.admin.exemption.ExemptCommand;
import fr.neatmonster.nocheatplus.command.admin.exemption.ExemptionsCommand;
import fr.neatmonster.nocheatplus.command.admin.exemption.UnexemptCommand;
import fr.neatmonster.nocheatplus.components.INotifyReload;
import fr.neatmonster.nocheatplus.config.ConfPaths;
import fr.neatmonster.nocheatplus.config.ConfigManager;
@ -58,7 +50,7 @@ import fr.neatmonster.nocheatplus.config.ConfigManager;
/**
* This the class handling all the commands.
*/
public class CommandHandler implements TabExecutor {
public class NoCheatPlusCommand extends BaseCommand{
/**
* The event triggered when NoCheatPlus configuration is reloaded.
@ -86,12 +78,6 @@ public class CommandHandler implements TabExecutor {
}
}
/** The prefix of every message sent by NoCheatPlus. */
static final String TAG = ChatColor.RED + "NCP: " + ChatColor.WHITE;
/** Sub command map. */
private final Map<String, NCPCommand> commands = new HashMap<String, NCPCommand>();
private Set<String> rootLabels = new LinkedHashSet<String>();
/**
@ -100,9 +86,10 @@ public class CommandHandler implements TabExecutor {
* @param plugin
* the instance of NoCheatPlus
*/
public CommandHandler(final JavaPlugin plugin, final Collection<INotifyReload> notifyReload) {
public NoCheatPlusCommand(final JavaPlugin plugin, final Collection<INotifyReload> notifyReload) {
super(plugin, "nocheatplus", null, new String[]{"ncp"});
// Register sub commands:
for (NCPCommand cmd : new NCPCommand[]{
for (BaseCommand cmd : new BaseCommand[]{
new BanCommand(plugin),
new CommandsCommand(plugin),
new DelayCommand(plugin),
@ -120,24 +107,10 @@ public class CommandHandler implements TabExecutor {
new UnexemptCommand(plugin),
new UnKickCommand(plugin),
}){
addCommand(cmd);
addSubCommands(cmd);
rootLabels.add(cmd.label);
}
}
public void addCommand(NCPCommand command){
rootLabels.add(command.label);
Set<String> allLabels = new LinkedHashSet<String>();
allLabels.add(command.label);
if (command.aliases != null){
for (String alias : command.aliases){
allLabels.add(alias);
}
}
for (String label : allLabels){
label = label.trim().toLowerCase(); // future.
if (!commands.containsKey(label)) commands.put(label, command);
}
}
/* (non-Javadoc)
* @see org.bukkit.command.CommandExecutor#onCommand(org.bukkit.command.CommandSender, org.bukkit.command.Command,
@ -160,15 +133,15 @@ public class CommandHandler implements TabExecutor {
final boolean protectPlugins = ConfigManager.getConfigFile().getBoolean(ConfPaths.MISCELLANEOUS_PROTECTPLUGINS);
if (args.length > 0){
NCPCommand subCommand = commands.get(args[0].trim().toLowerCase());
AbstractCommand<?> subCommand = subCommands.get(args[0].trim().toLowerCase());
if (subCommand != null && sender.hasPermission(subCommand.permission)){
// Sender has permission to run the command.
return subCommand.onCommand(sender, command, commandLabel, args);
}
}
// Bit crude workaround:
for (NCPCommand cmd : commands.values()){
// Bit crude workaround. TODO: Add chuld permission to commands permissions and check that one.
for (AbstractCommand<?> cmd : subCommands.values()){
if (sender.hasPermission(cmd.permission)) return false;
}
@ -181,51 +154,51 @@ public class CommandHandler implements TabExecutor {
return false;
}
/**
* Check which of the choices starts with prefix
* @param sender
* @param choices
* @return
*/
protected List<String> getTabMatches(CommandSender sender, Collection<String> choices, String prefix){
final List<String> res = new ArrayList<String>(choices.size());
final Set<NCPCommand> done = new HashSet<NCPCommand>();
for (final String label : choices){
if (!label.startsWith(prefix)) continue;
final NCPCommand cmd = commands.get(label);
if (done.contains(cmd)) continue;
done.add(cmd);
if (sender.hasPermission(cmd.permission)) res.add(cmd.label);
}
if (!res.isEmpty()){
Collections.sort(res);
return res;
}
return null;
}
// /**
// * Check which of the choices starts with prefix
// * @param sender
// * @param choices
// * @return
// */
// protected List<String> getTabMatches(CommandSender sender, Collection<String> choices, String prefix){
// final List<String> res = new ArrayList<String>(choices.size());
// final Set<BaseCommand> done = new HashSet<BaseCommand>();
// for (final String label : choices){
// if (!label.startsWith(prefix)) continue;
// final BaseCommand cmd = commands.get(label);
// if (done.contains(cmd)) continue;
// done.add(cmd);
// if (sender.hasPermission(cmd.permission)) res.add(cmd.label);
// }
// if (!res.isEmpty()){
// Collections.sort(res);
// return res;
// }
// return null;
// }
@Override
public List<String> onTabComplete(CommandSender sender, Command command, String alias, String[] args)
{
// TODO: TabComplete check ?
if (args.length == 0 || args.length == 1 && args[0].trim().isEmpty()){
// Add labels without aliases.
return getTabMatches(sender, rootLabels, "");
}
else {
final String subLabel = args[0].trim().toLowerCase();
if (args.length == 1){
// Also check aliases for matches.
return getTabMatches(sender, commands.keySet(), subLabel);
}
else{
final NCPCommand cmd = commands.get(subLabel);
if (cmd != null && sender.hasPermission(cmd.permission)){
// Delegate the tab-completion.
return cmd.onTabComplete(sender, command, alias, args);
}
}
}
return null;
}
// @Override
// public List<String> onTabComplete(CommandSender sender, Command command, String alias, String[] args)
// {
// // TODO: TabComplete check ?
// if (args.length == 0 || args.length == 1 && args[0].trim().isEmpty()){
// // Add labels without aliases.
// return getTabMatches(sender, rootLabels, "");
// }
// else {
// final String subLabel = args[0].trim().toLowerCase();
// if (args.length == 1){
// // Also check aliases for matches.
// return getTabMatches(sender, commands.keySet(), subLabel);
// }
// else{
// final NCPCommand cmd = commands.get(subLabel);
// if (cmd != null && sender.hasPermission(cmd.permission)){
// // Delegate the tab-completion.
// return cmd.onTabComplete(sender, command, alias, args);
// }
// }
// }
// return null;
// }
}

View File

@ -7,7 +7,8 @@ import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;
import org.bukkit.plugin.java.JavaPlugin;
import fr.neatmonster.nocheatplus.command.DelayableCommand;
import fr.neatmonster.nocheatplus.command.AbstractCommand;
import fr.neatmonster.nocheatplus.command.actions.delay.DelayableCommand;
import fr.neatmonster.nocheatplus.logging.LogUtil;
import fr.neatmonster.nocheatplus.permissions.Permissions;
import fr.neatmonster.nocheatplus.players.DataManager;
@ -25,7 +26,7 @@ public class BanCommand extends DelayableCommand {
if (alteredArgs.length < 2) return false;
final String name = alteredArgs[1];
final String reason;
if (alteredArgs.length > 2) reason = join(alteredArgs, 2);
if (alteredArgs.length > 2) reason = AbstractCommand.join(alteredArgs, 2);
else reason = "";
schedule(new Runnable() {
@Override

View File

@ -5,7 +5,8 @@ import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;
import org.bukkit.plugin.java.JavaPlugin;
import fr.neatmonster.nocheatplus.command.DelayableCommand;
import fr.neatmonster.nocheatplus.command.AbstractCommand;
import fr.neatmonster.nocheatplus.command.actions.delay.DelayableCommand;
import fr.neatmonster.nocheatplus.logging.LogUtil;
import fr.neatmonster.nocheatplus.permissions.Permissions;
import fr.neatmonster.nocheatplus.players.DataManager;
@ -23,7 +24,7 @@ public class KickCommand extends DelayableCommand {
if (alteredArgs.length < 2) return false;
final String name = alteredArgs[1];
final String reason;
if (alteredArgs.length > 2) reason = join(alteredArgs, 2);
if (alteredArgs.length > 2) reason = AbstractCommand.join(alteredArgs, 2);
else reason = "";
schedule(new Runnable() {
@Override

View File

@ -7,11 +7,11 @@ import org.bukkit.command.CommandSender;
import org.bukkit.plugin.java.JavaPlugin;
import fr.neatmonster.nocheatplus.NCPAPIProvider;
import fr.neatmonster.nocheatplus.command.NCPCommand;
import fr.neatmonster.nocheatplus.command.BaseCommand;
import fr.neatmonster.nocheatplus.permissions.Permissions;
import fr.neatmonster.nocheatplus.utilities.StringUtil;
public class KickListCommand extends NCPCommand {
public class KickListCommand extends BaseCommand {
public KickListCommand(JavaPlugin plugin) {
super(plugin, "kicklist", Permissions.ADMINISTRATION_KICKLIST);

View File

@ -5,7 +5,8 @@ import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;
import org.bukkit.plugin.java.JavaPlugin;
import fr.neatmonster.nocheatplus.command.DelayableCommand;
import fr.neatmonster.nocheatplus.command.AbstractCommand;
import fr.neatmonster.nocheatplus.command.actions.delay.DelayableCommand;
import fr.neatmonster.nocheatplus.permissions.Permissions;
import fr.neatmonster.nocheatplus.players.DataManager;
import fr.neatmonster.nocheatplus.utilities.ColorUtil;
@ -26,7 +27,7 @@ public class TellCommand extends DelayableCommand {
final String[] alteredArgs, long delay) {
if (alteredArgs.length < 3) return false;
final String name = alteredArgs[1].trim();
final String message = join(alteredArgs, 2);
final String message = AbstractCommand.join(alteredArgs, 2);
schedule(new Runnable() {
@Override
public void run() {

View File

@ -6,7 +6,8 @@ import org.bukkit.entity.Player;
import org.bukkit.plugin.java.JavaPlugin;
import fr.neatmonster.nocheatplus.NCPAPIProvider;
import fr.neatmonster.nocheatplus.command.DelayableCommand;
import fr.neatmonster.nocheatplus.command.AbstractCommand;
import fr.neatmonster.nocheatplus.command.actions.delay.DelayableCommand;
import fr.neatmonster.nocheatplus.logging.LogUtil;
import fr.neatmonster.nocheatplus.permissions.Permissions;
import fr.neatmonster.nocheatplus.players.DataManager;
@ -35,7 +36,7 @@ public class TempKickCommand extends DelayableCommand {
if (duration <= 0) return false;
final long finalDuration = duration * base;
final String reason;
if (alteredArgs.length > 3) reason = join(alteredArgs, 3);
if (alteredArgs.length > 3) reason = AbstractCommand.join(alteredArgs, 3);
else reason = "";
schedule(new Runnable() {
@Override

View File

@ -5,10 +5,10 @@ import org.bukkit.command.CommandSender;
import org.bukkit.plugin.java.JavaPlugin;
import fr.neatmonster.nocheatplus.NCPAPIProvider;
import fr.neatmonster.nocheatplus.command.NCPCommand;
import fr.neatmonster.nocheatplus.command.BaseCommand;
import fr.neatmonster.nocheatplus.permissions.Permissions;
public class UnKickCommand extends NCPCommand {
public class UnKickCommand extends BaseCommand {
public UnKickCommand(JavaPlugin plugin) {
super(plugin, "unkick", Permissions.ADMINISTRATION_UNKICK);

View File

@ -1,4 +1,4 @@
package fr.neatmonster.nocheatplus.command.actions;
package fr.neatmonster.nocheatplus.command.actions.delay;
import org.bukkit.Bukkit;
import org.bukkit.Server;
@ -6,7 +6,7 @@ import org.bukkit.command.Command;
import org.bukkit.command.CommandSender;
import org.bukkit.plugin.java.JavaPlugin;
import fr.neatmonster.nocheatplus.command.DelayableCommand;
import fr.neatmonster.nocheatplus.command.AbstractCommand;
import fr.neatmonster.nocheatplus.permissions.Permissions;
/**
@ -24,7 +24,7 @@ public class DelayCommand extends DelayableCommand {
public boolean execute(CommandSender sender, Command command, String label,
String[] alteredArgs, long delay) {
if (alteredArgs.length < 2) return false;
final String cmd = join(alteredArgs, 1);
final String cmd = AbstractCommand.join(alteredArgs, 1);
schedule(new Runnable() {
@Override
public void run() {

View File

@ -1,16 +1,20 @@
package fr.neatmonster.nocheatplus.command;
package fr.neatmonster.nocheatplus.command.actions.delay;
import java.util.List;
import org.bukkit.Bukkit;
import org.bukkit.command.Command;
import org.bukkit.command.CommandSender;
import org.bukkit.plugin.java.JavaPlugin;
import fr.neatmonster.nocheatplus.command.BaseCommand;
/**
* A command that allows to specify a delay for running.
* @author mc_dev
*
*/
public abstract class DelayableCommand extends NCPCommand {
public abstract class DelayableCommand extends BaseCommand {
/**
* Parse an argument for a delay in ticks. The delay is specified with "delay=...".
@ -146,9 +150,19 @@ public abstract class DelayableCommand extends NCPCommand {
if (delay < 0)
runnable.run();
else if (delay == 0)
Bukkit.getScheduler().scheduleSyncDelayedTask(plugin, runnable);
Bukkit.getScheduler().scheduleSyncDelayedTask(access, runnable);
else
Bukkit.getScheduler().scheduleSyncDelayedTask(plugin, runnable, delay);
Bukkit.getScheduler().scheduleSyncDelayedTask(access, runnable, delay);
}
/* (non-Javadoc)
* @see fr.neatmonster.nocheatplus.command.AbstractCommand#onTabComplete(org.bukkit.command.CommandSender, org.bukkit.command.Command, java.lang.String, java.lang.String[])
*/
@Override
public List<String> onTabComplete(CommandSender sender, Command command, String alias, String[] args) {
// Fill in players.
// TODO: Add altered signature for alteredArgs ?
return null;
}
}

View File

@ -6,7 +6,7 @@ import org.bukkit.command.Command;
import org.bukkit.command.CommandSender;
import org.bukkit.plugin.java.JavaPlugin;
import fr.neatmonster.nocheatplus.command.NCPCommand;
import fr.neatmonster.nocheatplus.command.BaseCommand;
import fr.neatmonster.nocheatplus.permissions.Permissions;
import fr.neatmonster.nocheatplus.utilities.StringUtil;
@ -15,7 +15,7 @@ import fr.neatmonster.nocheatplus.utilities.StringUtil;
* @author mc_dev
*
*/
public class CommandsCommand extends NCPCommand {
public class CommandsCommand extends BaseCommand {
final String[] moreCommands = new String[]{
"/<command> ban [delay=(ticks)] (player) [(reason)...]: ban player",

View File

@ -3,6 +3,7 @@ package fr.neatmonster.nocheatplus.command.admin;
import java.text.DateFormat;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.List;
import org.bukkit.ChatColor;
import org.bukkit.command.Command;
@ -12,11 +13,11 @@ import org.bukkit.plugin.java.JavaPlugin;
import fr.neatmonster.nocheatplus.checks.ViolationHistory;
import fr.neatmonster.nocheatplus.checks.ViolationHistory.ViolationLevel;
import fr.neatmonster.nocheatplus.command.NCPCommand;
import fr.neatmonster.nocheatplus.command.BaseCommand;
import fr.neatmonster.nocheatplus.permissions.Permissions;
import fr.neatmonster.nocheatplus.players.DataManager;
public class InfoCommand extends NCPCommand {
public class InfoCommand extends BaseCommand {
public InfoCommand(JavaPlugin plugin) {
super(plugin, "info", Permissions.ADMINISTRATION_INFO);
@ -70,5 +71,14 @@ public class InfoCommand extends NCPCommand {
sender.sendMessage(TAG + "Displaying " + playerName + "'s violations... nothing to display.");
}
/* (non-Javadoc)
* @see fr.neatmonster.nocheatplus.command.AbstractCommand#onTabComplete(org.bukkit.command.CommandSender, org.bukkit.command.Command, java.lang.String, java.lang.String[])
*/
@Override
public List<String> onTabComplete(CommandSender sender, Command command, String alias, String[] args) {
// Fill in players.
return null;
}
}

View File

@ -4,12 +4,12 @@ import org.bukkit.command.Command;
import org.bukkit.command.CommandSender;
import org.bukkit.plugin.java.JavaPlugin;
import fr.neatmonster.nocheatplus.command.NCPCommand;
import fr.neatmonster.nocheatplus.command.BaseCommand;
import fr.neatmonster.nocheatplus.permissions.Permissions;
import fr.neatmonster.nocheatplus.utilities.StringUtil;
import fr.neatmonster.nocheatplus.utilities.TickTask;
public class LagCommand extends NCPCommand {
public class LagCommand extends BaseCommand {
public LagCommand(JavaPlugin plugin) {
super(plugin, "lag", Permissions.ADMINISTRATION_LAG);

View File

@ -6,11 +6,11 @@ import org.bukkit.command.CommandSender;
import org.bukkit.plugin.java.JavaPlugin;
import fr.neatmonster.nocheatplus.NCPAPIProvider;
import fr.neatmonster.nocheatplus.command.NCPCommand;
import fr.neatmonster.nocheatplus.command.BaseCommand;
import fr.neatmonster.nocheatplus.compat.MCAccess;
import fr.neatmonster.nocheatplus.permissions.Permissions;
public class NCPVersionCommand extends NCPCommand{
public class NCPVersionCommand extends BaseCommand{
public NCPVersionCommand(JavaPlugin plugin) {
super(plugin, "version", Permissions.ADMINISTRATION_VERSION, new String[]{"versions", "ver"});
@ -25,7 +25,7 @@ public class NCPVersionCommand extends NCPCommand{
"#### Server ####",
Bukkit.getServer().getVersion(),
"#### NoCheatPlus ####",
"Plugin: " + plugin.getDescription().getVersion(),
"Plugin: " + access.getDescription().getVersion(),
"MCAccess: " + mc.getMCVersion() + " / " + mc.getServerVersionTag(),
});

View File

@ -10,8 +10,8 @@ import org.bukkit.command.ConsoleCommandSender;
import org.bukkit.plugin.java.JavaPlugin;
import fr.neatmonster.nocheatplus.checks.CheckType;
import fr.neatmonster.nocheatplus.command.CommandHandler.NCPReloadEvent;
import fr.neatmonster.nocheatplus.command.NCPCommand;
import fr.neatmonster.nocheatplus.command.NoCheatPlusCommand.NCPReloadEvent;
import fr.neatmonster.nocheatplus.command.BaseCommand;
import fr.neatmonster.nocheatplus.components.INotifyReload;
import fr.neatmonster.nocheatplus.config.ConfPaths;
import fr.neatmonster.nocheatplus.config.ConfigFile;
@ -20,7 +20,7 @@ import fr.neatmonster.nocheatplus.logging.StaticLogFile;
import fr.neatmonster.nocheatplus.permissions.Permissions;
import fr.neatmonster.nocheatplus.players.DataManager;
public class ReloadCommand extends NCPCommand {
public class ReloadCommand extends BaseCommand {
/** Components that need to be notified on reload */
private final Collection<INotifyReload> notifyReload;
@ -50,9 +50,9 @@ public class ReloadCommand extends NCPCommand {
// Do the actual reload.
ConfigManager.cleanup();
ConfigManager.init(plugin);
ConfigManager.init(access);
StaticLogFile.cleanup();
StaticLogFile.setupLogger(new File(plugin.getDataFolder(), ConfigManager.getConfigFile().getString(ConfPaths.LOGGING_BACKEND_FILE_FILENAME)));
StaticLogFile.setupLogger(new File(access.getDataFolder(), ConfigManager.getConfigFile().getString(ConfPaths.LOGGING_BACKEND_FILE_FILENAME)));
// Remove all cached configs.
DataManager.clearConfigs(); // There you have to add XConfig.clear() form now on.
// Remove some checks data.

View File

@ -11,12 +11,12 @@ import org.bukkit.plugin.java.JavaPlugin;
import fr.neatmonster.nocheatplus.checks.CheckType;
import fr.neatmonster.nocheatplus.checks.ViolationHistory;
import fr.neatmonster.nocheatplus.command.CommandUtil;
import fr.neatmonster.nocheatplus.command.NCPCommand;
import fr.neatmonster.nocheatplus.command.BaseCommand;
import fr.neatmonster.nocheatplus.permissions.Permissions;
import fr.neatmonster.nocheatplus.players.DataManager;
import fr.neatmonster.nocheatplus.utilities.StringUtil;
public class RemovePlayerCommand extends NCPCommand {
public class RemovePlayerCommand extends BaseCommand {
public RemovePlayerCommand(JavaPlugin plugin) {
super(plugin, "removeplayer", Permissions.ADMINISTRATION_REMOVEPLAYER, new String[]{

View File

@ -1,4 +1,4 @@
package fr.neatmonster.nocheatplus.command.admin;
package fr.neatmonster.nocheatplus.command.admin.exemption;
import java.util.Arrays;
import java.util.List;
@ -10,13 +10,13 @@ import org.bukkit.plugin.java.JavaPlugin;
import fr.neatmonster.nocheatplus.checks.CheckType;
import fr.neatmonster.nocheatplus.command.CommandUtil;
import fr.neatmonster.nocheatplus.command.NCPCommand;
import fr.neatmonster.nocheatplus.command.BaseCommand;
import fr.neatmonster.nocheatplus.hooks.NCPExemptionManager;
import fr.neatmonster.nocheatplus.permissions.Permissions;
import fr.neatmonster.nocheatplus.players.DataManager;
import fr.neatmonster.nocheatplus.utilities.StringUtil;
public class ExemptCommand extends NCPCommand {
public class ExemptCommand extends BaseCommand {
public ExemptCommand(JavaPlugin plugin) {
super(plugin, "exempt", Permissions.ADMINISTRATION_EXEMPT);

View File

@ -1,4 +1,4 @@
package fr.neatmonster.nocheatplus.command.admin;
package fr.neatmonster.nocheatplus.command.admin.exemption;
import java.util.LinkedList;
import java.util.List;
@ -9,13 +9,13 @@ import org.bukkit.entity.Player;
import org.bukkit.plugin.java.JavaPlugin;
import fr.neatmonster.nocheatplus.checks.CheckType;
import fr.neatmonster.nocheatplus.command.NCPCommand;
import fr.neatmonster.nocheatplus.command.BaseCommand;
import fr.neatmonster.nocheatplus.hooks.NCPExemptionManager;
import fr.neatmonster.nocheatplus.permissions.Permissions;
import fr.neatmonster.nocheatplus.players.DataManager;
import fr.neatmonster.nocheatplus.utilities.StringUtil;
public class ExemptionsCommand extends NCPCommand {
public class ExemptionsCommand extends BaseCommand {
public ExemptionsCommand(JavaPlugin plugin) {
super(plugin, "exemptions", Permissions.ADMINISTRATION_EXEMPTIONS, new String[]{"exe"});
@ -37,4 +37,13 @@ public class ExemptionsCommand extends NCPCommand {
return true;
}
/* (non-Javadoc)
* @see fr.neatmonster.nocheatplus.command.AbstractCommand#onTabComplete(org.bukkit.command.CommandSender, org.bukkit.command.Command, java.lang.String, java.lang.String[])
*/
@Override
public List<String> onTabComplete(CommandSender sender, Command command, String alias, String[] args) {
// Fill in players.
return null;
}
}

View File

@ -1,4 +1,4 @@
package fr.neatmonster.nocheatplus.command.admin;
package fr.neatmonster.nocheatplus.command.admin.exemption;
import java.util.Arrays;
import java.util.List;
@ -10,13 +10,13 @@ import org.bukkit.plugin.java.JavaPlugin;
import fr.neatmonster.nocheatplus.checks.CheckType;
import fr.neatmonster.nocheatplus.command.CommandUtil;
import fr.neatmonster.nocheatplus.command.NCPCommand;
import fr.neatmonster.nocheatplus.command.BaseCommand;
import fr.neatmonster.nocheatplus.hooks.NCPExemptionManager;
import fr.neatmonster.nocheatplus.permissions.Permissions;
import fr.neatmonster.nocheatplus.players.DataManager;
import fr.neatmonster.nocheatplus.utilities.StringUtil;
public class UnexemptCommand extends NCPCommand {
public class UnexemptCommand extends BaseCommand {
public UnexemptCommand(JavaPlugin plugin) {
super(plugin, "unexempt", Permissions.ADMINISTRATION_UNEXEMPT);

View File

@ -44,7 +44,7 @@ import fr.neatmonster.nocheatplus.checks.fight.FightListener;
import fr.neatmonster.nocheatplus.checks.inventory.InventoryListener;
import fr.neatmonster.nocheatplus.checks.moving.MovingListener;
import fr.neatmonster.nocheatplus.clients.ModUtil;
import fr.neatmonster.nocheatplus.command.CommandHandler;
import fr.neatmonster.nocheatplus.command.NoCheatPlusCommand;
import fr.neatmonster.nocheatplus.compat.DefaultComponentFactory;
import fr.neatmonster.nocheatplus.compat.MCAccess;
import fr.neatmonster.nocheatplus.compat.MCAccessFactory;
@ -762,7 +762,7 @@ public class NoCheatPlus extends JavaPlugin implements NoCheatPlusAPI {
// Register the commands handler.
PluginCommand command = getCommand("nocheatplus");
CommandHandler commandHandler = new CommandHandler(this, notifyReload);
NoCheatPlusCommand commandHandler = new NoCheatPlusCommand(this, notifyReload);
command.setExecutor(commandHandler);
// (CommandHandler is TabExecutor.)