Demand most action commands to be run from the console.

For players they either have no extra value over vanilla commands or
they have too high of an abuse potential.
This commit is contained in:
asofold 2014-07-27 16:53:21 +02:00
parent 7c967ab2e2
commit c99612154c
6 changed files with 53 additions and 6 deletions

View File

@ -12,7 +12,9 @@ import java.util.Set;
import org.bukkit.ChatColor; 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.ConsoleCommandSender;
import org.bukkit.command.TabExecutor; import org.bukkit.command.TabExecutor;
import org.bukkit.entity.Player;
/** /**
* Base command class, featuring some features.<br> * Base command class, featuring some features.<br>
@ -50,6 +52,34 @@ public abstract class AbstractCommand<A> implements TabExecutor{
return b.toString(); return b.toString();
} }
/**
*
* @param sender
* @return True if sender is a Player, otherwise false is returned and a message sent.
*/
public static boolean demandPlayer(CommandSender sender) {
if (sender instanceof Player) {
return true;
} else {
sender.sendMessage("[NoCheatPlus] A player is required to run this command.");
return false;
}
}
/**
*
* @param sender
* @return True if sender is a Player, otherwise false is returned and a message sent.
*/
public static boolean demandConsoleCommandSender(CommandSender sender) {
if (sender instanceof ConsoleCommandSender) {
return true;
} else {
sender.sendMessage("[NoCheatPlus] This command can only be run from the console.");
return false;
}
}
//////////////// ////////////////
// Not static. // Not static.
//////////////// ////////////////

View File

@ -25,7 +25,9 @@ public class BanCommand extends BaseCommand {
@Override @Override
public boolean onCommand(final CommandSender sender, Command command, String label, String[] args) { public boolean onCommand(final CommandSender sender, Command command, String label, String[] args) {
if (!demandConsoleCommandSender(sender)) {
return true;
}
// TODO: Consider supporting vanilla syntax or removing this command :p. // TODO: Consider supporting vanilla syntax or removing this command :p.
// Args contains "ban" as first arg. // Args contains "ban" as first arg.

View File

@ -21,6 +21,9 @@ public class KickCommand extends BaseCommand {
@Override @Override
public boolean onCommand(final CommandSender sender, Command command, String label, String[] args) { public boolean onCommand(final CommandSender sender, Command command, String label, String[] args) {
if (!demandConsoleCommandSender(sender)) {
return true;
}
// Args contains "kick" as first arg. // Args contains "kick" as first arg.
if (args.length < 2) return false; if (args.length < 2) return false;
final String name = args[1]; final String name = args[1];

View File

@ -26,7 +26,12 @@ public class TellCommand extends BaseCommand {
@Override @Override
public boolean onCommand(CommandSender sender, Command command, String label, final String[] args) { public boolean onCommand(CommandSender sender, Command command, String label, final String[] args) {
if (args.length < 3) return false; if (!demandConsoleCommandSender(sender)) {
return true;
}
if (args.length < 3) {
return false;
}
final String name = args[1].trim(); final String name = args[1].trim();
final String message = AbstractCommand.join(args, 2); final String message = AbstractCommand.join(args, 2);
tell(name, message); tell(name, message);
@ -39,7 +44,7 @@ public class TellCommand extends BaseCommand {
} }
/* (non-Javadoc) /* (non-Javadoc)
* @see fr.neatmonster.nocheatplus.command.actions.delay.DelayableCommand#onTabComplete(org.bukkit.command.CommandSender, org.bukkit.command.Command, java.lang.String, java.lang.String[]) * @see fr.neatmonster.nocheatplus.command.BaseCommand#onTabComplete(org.bukkit.command.CommandSender, org.bukkit.command.Command, java.lang.String, java.lang.String[])
*/ */
@Override @Override
public List<String> onTabComplete(CommandSender sender, Command command, public List<String> onTabComplete(CommandSender sender, Command command,

View File

@ -4,6 +4,7 @@ import org.bukkit.Bukkit;
import org.bukkit.Server; import org.bukkit.Server;
import org.bukkit.command.Command; import org.bukkit.command.Command;
import org.bukkit.command.CommandSender; import org.bukkit.command.CommandSender;
import org.bukkit.command.ConsoleCommandSender;
import org.bukkit.plugin.java.JavaPlugin; import org.bukkit.plugin.java.JavaPlugin;
import fr.neatmonster.nocheatplus.command.AbstractCommand; import fr.neatmonster.nocheatplus.command.AbstractCommand;
@ -18,12 +19,14 @@ public class DelayCommand extends DelayableCommand {
public DelayCommand(JavaPlugin plugin){ public DelayCommand(JavaPlugin plugin){
super(plugin, "delay", Permissions.COMMAND_DELAY, 1, 0, true); super(plugin, "delay", Permissions.COMMAND_DELAY, 1, 0, true);
demandConsoleCommandSender = true;
} }
@Override @Override
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) {
if (alteredArgs.length < 2) return false; return false;
}
final String cmd = AbstractCommand.join(alteredArgs, 1); final String cmd = AbstractCommand.join(alteredArgs, 1);
schedule(new Runnable() { schedule(new Runnable() {
@Override @Override

View File

@ -52,6 +52,7 @@ public abstract class DelayableCommand extends BaseCommand {
protected final int delayIndex; protected final int delayIndex;
protected final boolean mustHaveDelay; protected final boolean mustHaveDelay;
protected final int delayPreset; protected final int delayPreset;
protected boolean demandConsoleCommandSender = false;
/** /**
* (Delay is not obligatory, inserted after the first argument.) * (Delay is not obligatory, inserted after the first argument.)
@ -115,6 +116,9 @@ public abstract class DelayableCommand extends BaseCommand {
@Override @Override
public boolean onCommand(final CommandSender sender, final Command command, public boolean onCommand(final CommandSender sender, final Command command,
final String label, final String[] args ) { final String label, final String[] args ) {
if (demandConsoleCommandSender && !demandConsoleCommandSender(sender)) {
return true;
}
// Parse the delay and alter the args accordingly. // Parse the delay and alter the args accordingly.
long delay = parseDelay(args, delayIndex, delayPreset); long delay = parseDelay(args, delayIndex, delayPreset);
String[] alteredArgs; String[] alteredArgs;