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

View File

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

View File

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

View File

@ -7,11 +7,11 @@ import org.bukkit.command.CommandSender;
import org.bukkit.plugin.java.JavaPlugin; import org.bukkit.plugin.java.JavaPlugin;
import fr.neatmonster.nocheatplus.NCPAPIProvider; 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.permissions.Permissions;
import fr.neatmonster.nocheatplus.utilities.StringUtil; import fr.neatmonster.nocheatplus.utilities.StringUtil;
public class KickListCommand extends NCPCommand { public class KickListCommand extends BaseCommand {
public KickListCommand(JavaPlugin plugin) { public KickListCommand(JavaPlugin plugin) {
super(plugin, "kicklist", Permissions.ADMINISTRATION_KICKLIST); 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.entity.Player;
import org.bukkit.plugin.java.JavaPlugin; 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.permissions.Permissions;
import fr.neatmonster.nocheatplus.players.DataManager; import fr.neatmonster.nocheatplus.players.DataManager;
import fr.neatmonster.nocheatplus.utilities.ColorUtil; import fr.neatmonster.nocheatplus.utilities.ColorUtil;
@ -26,7 +27,7 @@ public class TellCommand extends DelayableCommand {
final String[] alteredArgs, long delay) { final String[] alteredArgs, long delay) {
if (alteredArgs.length < 3) return false; if (alteredArgs.length < 3) return false;
final String name = alteredArgs[1].trim(); final String name = alteredArgs[1].trim();
final String message = join(alteredArgs, 2); final String message = AbstractCommand.join(alteredArgs, 2);
schedule(new Runnable() { schedule(new Runnable() {
@Override @Override
public void run() { public void run() {

View File

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

View File

@ -5,10 +5,10 @@ import org.bukkit.command.CommandSender;
import org.bukkit.plugin.java.JavaPlugin; import org.bukkit.plugin.java.JavaPlugin;
import fr.neatmonster.nocheatplus.NCPAPIProvider; 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.permissions.Permissions;
public class UnKickCommand extends NCPCommand { public class UnKickCommand extends BaseCommand {
public UnKickCommand(JavaPlugin plugin) { public UnKickCommand(JavaPlugin plugin) {
super(plugin, "unkick", Permissions.ADMINISTRATION_UNKICK); 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.Bukkit;
import org.bukkit.Server; import org.bukkit.Server;
@ -6,7 +6,7 @@ import org.bukkit.command.Command;
import org.bukkit.command.CommandSender; import org.bukkit.command.CommandSender;
import org.bukkit.plugin.java.JavaPlugin; import org.bukkit.plugin.java.JavaPlugin;
import fr.neatmonster.nocheatplus.command.DelayableCommand; import fr.neatmonster.nocheatplus.command.AbstractCommand;
import fr.neatmonster.nocheatplus.permissions.Permissions; import fr.neatmonster.nocheatplus.permissions.Permissions;
/** /**
@ -24,7 +24,7 @@ public class DelayCommand extends DelayableCommand {
public boolean execute(CommandSender sender, Command command, String label, public boolean execute(CommandSender sender, Command command, String label,
String[] alteredArgs, long delay) { String[] alteredArgs, long delay) {
if (alteredArgs.length < 2) return false; if (alteredArgs.length < 2) return false;
final String cmd = join(alteredArgs, 1); final String cmd = AbstractCommand.join(alteredArgs, 1);
schedule(new Runnable() { schedule(new Runnable() {
@Override @Override
public void run() { 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.Bukkit;
import org.bukkit.command.Command; import org.bukkit.command.Command;
import org.bukkit.command.CommandSender; import org.bukkit.command.CommandSender;
import org.bukkit.plugin.java.JavaPlugin; import org.bukkit.plugin.java.JavaPlugin;
import fr.neatmonster.nocheatplus.command.BaseCommand;
/** /**
* A command that allows to specify a delay for running. * A command that allows to specify a delay for running.
* @author mc_dev * @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=...". * 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) if (delay < 0)
runnable.run(); runnable.run();
else if (delay == 0) else if (delay == 0)
Bukkit.getScheduler().scheduleSyncDelayedTask(plugin, runnable); Bukkit.getScheduler().scheduleSyncDelayedTask(access, runnable);
else 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.command.CommandSender;
import org.bukkit.plugin.java.JavaPlugin; 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.permissions.Permissions;
import fr.neatmonster.nocheatplus.utilities.StringUtil; import fr.neatmonster.nocheatplus.utilities.StringUtil;
@ -15,7 +15,7 @@ import fr.neatmonster.nocheatplus.utilities.StringUtil;
* @author mc_dev * @author mc_dev
* *
*/ */
public class CommandsCommand extends NCPCommand { public class CommandsCommand extends BaseCommand {
final String[] moreCommands = new String[]{ final String[] moreCommands = new String[]{
"/<command> ban [delay=(ticks)] (player) [(reason)...]: ban player", "/<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.DateFormat;
import java.text.SimpleDateFormat; import java.text.SimpleDateFormat;
import java.util.Date; import java.util.Date;
import java.util.List;
import org.bukkit.ChatColor; import org.bukkit.ChatColor;
import org.bukkit.command.Command; 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;
import fr.neatmonster.nocheatplus.checks.ViolationHistory.ViolationLevel; 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.permissions.Permissions;
import fr.neatmonster.nocheatplus.players.DataManager; import fr.neatmonster.nocheatplus.players.DataManager;
public class InfoCommand extends NCPCommand { public class InfoCommand extends BaseCommand {
public InfoCommand(JavaPlugin plugin) { public InfoCommand(JavaPlugin plugin) {
super(plugin, "info", Permissions.ADMINISTRATION_INFO); 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."); 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.command.CommandSender;
import org.bukkit.plugin.java.JavaPlugin; 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.permissions.Permissions;
import fr.neatmonster.nocheatplus.utilities.StringUtil; import fr.neatmonster.nocheatplus.utilities.StringUtil;
import fr.neatmonster.nocheatplus.utilities.TickTask; import fr.neatmonster.nocheatplus.utilities.TickTask;
public class LagCommand extends NCPCommand { public class LagCommand extends BaseCommand {
public LagCommand(JavaPlugin plugin) { public LagCommand(JavaPlugin plugin) {
super(plugin, "lag", Permissions.ADMINISTRATION_LAG); super(plugin, "lag", Permissions.ADMINISTRATION_LAG);

View File

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

View File

@ -10,8 +10,8 @@ import org.bukkit.command.ConsoleCommandSender;
import org.bukkit.plugin.java.JavaPlugin; import org.bukkit.plugin.java.JavaPlugin;
import fr.neatmonster.nocheatplus.checks.CheckType; import fr.neatmonster.nocheatplus.checks.CheckType;
import fr.neatmonster.nocheatplus.command.CommandHandler.NCPReloadEvent; import fr.neatmonster.nocheatplus.command.NoCheatPlusCommand.NCPReloadEvent;
import fr.neatmonster.nocheatplus.command.NCPCommand; import fr.neatmonster.nocheatplus.command.BaseCommand;
import fr.neatmonster.nocheatplus.components.INotifyReload; import fr.neatmonster.nocheatplus.components.INotifyReload;
import fr.neatmonster.nocheatplus.config.ConfPaths; import fr.neatmonster.nocheatplus.config.ConfPaths;
import fr.neatmonster.nocheatplus.config.ConfigFile; 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.permissions.Permissions;
import fr.neatmonster.nocheatplus.players.DataManager; import fr.neatmonster.nocheatplus.players.DataManager;
public class ReloadCommand extends NCPCommand { public class ReloadCommand extends BaseCommand {
/** Components that need to be notified on reload */ /** Components that need to be notified on reload */
private final Collection<INotifyReload> notifyReload; private final Collection<INotifyReload> notifyReload;
@ -50,9 +50,9 @@ public class ReloadCommand extends NCPCommand {
// Do the actual reload. // Do the actual reload.
ConfigManager.cleanup(); ConfigManager.cleanup();
ConfigManager.init(plugin); ConfigManager.init(access);
StaticLogFile.cleanup(); 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. // Remove all cached configs.
DataManager.clearConfigs(); // There you have to add XConfig.clear() form now on. DataManager.clearConfigs(); // There you have to add XConfig.clear() form now on.
// Remove some checks data. // 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.CheckType;
import fr.neatmonster.nocheatplus.checks.ViolationHistory; import fr.neatmonster.nocheatplus.checks.ViolationHistory;
import fr.neatmonster.nocheatplus.command.CommandUtil; 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.permissions.Permissions;
import fr.neatmonster.nocheatplus.players.DataManager; import fr.neatmonster.nocheatplus.players.DataManager;
import fr.neatmonster.nocheatplus.utilities.StringUtil; import fr.neatmonster.nocheatplus.utilities.StringUtil;
public class RemovePlayerCommand extends NCPCommand { public class RemovePlayerCommand extends BaseCommand {
public RemovePlayerCommand(JavaPlugin plugin) { public RemovePlayerCommand(JavaPlugin plugin) {
super(plugin, "removeplayer", Permissions.ADMINISTRATION_REMOVEPLAYER, new String[]{ 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.Arrays;
import java.util.List; import java.util.List;
@ -10,13 +10,13 @@ import org.bukkit.plugin.java.JavaPlugin;
import fr.neatmonster.nocheatplus.checks.CheckType; import fr.neatmonster.nocheatplus.checks.CheckType;
import fr.neatmonster.nocheatplus.command.CommandUtil; 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.hooks.NCPExemptionManager;
import fr.neatmonster.nocheatplus.permissions.Permissions; import fr.neatmonster.nocheatplus.permissions.Permissions;
import fr.neatmonster.nocheatplus.players.DataManager; import fr.neatmonster.nocheatplus.players.DataManager;
import fr.neatmonster.nocheatplus.utilities.StringUtil; import fr.neatmonster.nocheatplus.utilities.StringUtil;
public class ExemptCommand extends NCPCommand { public class ExemptCommand extends BaseCommand {
public ExemptCommand(JavaPlugin plugin) { public ExemptCommand(JavaPlugin plugin) {
super(plugin, "exempt", Permissions.ADMINISTRATION_EXEMPT); 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.LinkedList;
import java.util.List; import java.util.List;
@ -9,13 +9,13 @@ import org.bukkit.entity.Player;
import org.bukkit.plugin.java.JavaPlugin; import org.bukkit.plugin.java.JavaPlugin;
import fr.neatmonster.nocheatplus.checks.CheckType; 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.hooks.NCPExemptionManager;
import fr.neatmonster.nocheatplus.permissions.Permissions; import fr.neatmonster.nocheatplus.permissions.Permissions;
import fr.neatmonster.nocheatplus.players.DataManager; import fr.neatmonster.nocheatplus.players.DataManager;
import fr.neatmonster.nocheatplus.utilities.StringUtil; import fr.neatmonster.nocheatplus.utilities.StringUtil;
public class ExemptionsCommand extends NCPCommand { public class ExemptionsCommand extends BaseCommand {
public ExemptionsCommand(JavaPlugin plugin) { public ExemptionsCommand(JavaPlugin plugin) {
super(plugin, "exemptions", Permissions.ADMINISTRATION_EXEMPTIONS, new String[]{"exe"}); super(plugin, "exemptions", Permissions.ADMINISTRATION_EXEMPTIONS, new String[]{"exe"});
@ -37,4 +37,13 @@ public class ExemptionsCommand extends NCPCommand {
return true; 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.Arrays;
import java.util.List; import java.util.List;
@ -10,13 +10,13 @@ import org.bukkit.plugin.java.JavaPlugin;
import fr.neatmonster.nocheatplus.checks.CheckType; import fr.neatmonster.nocheatplus.checks.CheckType;
import fr.neatmonster.nocheatplus.command.CommandUtil; 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.hooks.NCPExemptionManager;
import fr.neatmonster.nocheatplus.permissions.Permissions; import fr.neatmonster.nocheatplus.permissions.Permissions;
import fr.neatmonster.nocheatplus.players.DataManager; import fr.neatmonster.nocheatplus.players.DataManager;
import fr.neatmonster.nocheatplus.utilities.StringUtil; import fr.neatmonster.nocheatplus.utilities.StringUtil;
public class UnexemptCommand extends NCPCommand { public class UnexemptCommand extends BaseCommand {
public UnexemptCommand(JavaPlugin plugin) { public UnexemptCommand(JavaPlugin plugin) {
super(plugin, "unexempt", Permissions.ADMINISTRATION_UNEXEMPT); 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.inventory.InventoryListener;
import fr.neatmonster.nocheatplus.checks.moving.MovingListener; import fr.neatmonster.nocheatplus.checks.moving.MovingListener;
import fr.neatmonster.nocheatplus.clients.ModUtil; 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.DefaultComponentFactory;
import fr.neatmonster.nocheatplus.compat.MCAccess; import fr.neatmonster.nocheatplus.compat.MCAccess;
import fr.neatmonster.nocheatplus.compat.MCAccessFactory; import fr.neatmonster.nocheatplus.compat.MCAccessFactory;
@ -762,7 +762,7 @@ public class NoCheatPlus extends JavaPlugin implements NoCheatPlusAPI {
// Register the commands handler. // Register the commands handler.
PluginCommand command = getCommand("nocheatplus"); PluginCommand command = getCommand("nocheatplus");
CommandHandler commandHandler = new CommandHandler(this, notifyReload); NoCheatPlusCommand commandHandler = new NoCheatPlusCommand(this, notifyReload);
command.setExecutor(commandHandler); command.setExecutor(commandHandler);
// (CommandHandler is TabExecutor.) // (CommandHandler is TabExecutor.)