mirror of
https://github.com/NoCheatPlus/NoCheatPlus.git
synced 2024-11-02 00:29:59 +01:00
Clean up command handling slightly, add delayable commands for tell,
kick and ban with reasons displayed if the player is online.
This commit is contained in:
parent
af1d5a94b3
commit
a502aab2c8
@ -14,8 +14,12 @@ commands:
|
||||
description: NoCheatPlus command(s).
|
||||
# permission: nocheatplus.admin.reload
|
||||
usage: |
|
||||
/<command> info: Display the violations of a player
|
||||
/<command> info <player>: Display the violations of a player
|
||||
/<command> reload: reload NoCheatPlus configuration
|
||||
Auxiliary:
|
||||
/<command> ban [delay=<ticks>] <player> [<reason>...]: ban player
|
||||
/<command> kick [delay=<ticks>] <player> [<reason>...]: kick player
|
||||
/<command> tell [delay=<ticks>] <player> <message>: tell a message
|
||||
|
||||
permissions:
|
||||
nocheatplus:
|
||||
|
@ -1,189 +0,0 @@
|
||||
package fr.neatmonster.nocheatplus;
|
||||
|
||||
import java.text.DateFormat;
|
||||
import java.text.SimpleDateFormat;
|
||||
import java.util.Date;
|
||||
import java.util.TreeMap;
|
||||
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.ChatColor;
|
||||
import org.bukkit.command.Command;
|
||||
import org.bukkit.command.CommandExecutor;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.event.Event;
|
||||
import org.bukkit.event.HandlerList;
|
||||
|
||||
import fr.neatmonster.nocheatplus.checks.ViolationHistory;
|
||||
import fr.neatmonster.nocheatplus.checks.ViolationHistory.ViolationLevel;
|
||||
import fr.neatmonster.nocheatplus.checks.blockbreak.BlockBreakConfig;
|
||||
import fr.neatmonster.nocheatplus.checks.blockinteract.BlockInteractConfig;
|
||||
import fr.neatmonster.nocheatplus.checks.blockplace.BlockPlaceConfig;
|
||||
import fr.neatmonster.nocheatplus.checks.chat.ChatConfig;
|
||||
import fr.neatmonster.nocheatplus.checks.fight.FightConfig;
|
||||
import fr.neatmonster.nocheatplus.checks.inventory.InventoryConfig;
|
||||
import fr.neatmonster.nocheatplus.checks.moving.MovingConfig;
|
||||
import fr.neatmonster.nocheatplus.config.ConfPaths;
|
||||
import fr.neatmonster.nocheatplus.config.ConfigManager;
|
||||
import fr.neatmonster.nocheatplus.players.Permissions;
|
||||
|
||||
/*
|
||||
* MM'""""'YMM dP
|
||||
* M' .mmm. `M 88
|
||||
* M MMMMMooM .d8888b. 88d8b.d8b. 88d8b.d8b. .d8888b. 88d888b. .d888b88
|
||||
* M MMMMMMMM 88' `88 88'`88'`88 88'`88'`88 88' `88 88' `88 88' `88
|
||||
* M. `MMM' .M 88. .88 88 88 88 88 88 88 88. .88 88 88 88. .88
|
||||
* MM. .dM `88888P' dP dP dP dP dP dP `88888P8 dP dP `88888P8
|
||||
* MMMMMMMMMMM
|
||||
*
|
||||
* M""MMMMM""MM dP dP
|
||||
* M MMMMM MM 88 88
|
||||
* M `M .d8888b. 88d888b. .d888b88 88 .d8888b. 88d888b.
|
||||
* M MMMMM MM 88' `88 88' `88 88' `88 88 88ooood8 88' `88
|
||||
* M MMMMM MM 88. .88 88 88 88. .88 88 88. ... 88
|
||||
* M MMMMM MM `88888P8 dP dP `88888P8 dP `88888P' dP
|
||||
* MMMMMMMMMMMM
|
||||
*/
|
||||
/**
|
||||
* This the class handling all the commands.
|
||||
*/
|
||||
public class CommandHandler implements CommandExecutor {
|
||||
|
||||
/**
|
||||
* The event triggered when NoCheatPlus configuration is reloaded.
|
||||
*/
|
||||
public static class NCPReloadEvent extends Event {
|
||||
|
||||
/** The handlers list. */
|
||||
private static final HandlerList handlers = new HandlerList();
|
||||
|
||||
/**
|
||||
* Gets the handler list.
|
||||
*
|
||||
* @return the handler list
|
||||
*/
|
||||
public static HandlerList getHandlerList() {
|
||||
return handlers;
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see org.bukkit.event.Event#getHandlers()
|
||||
*/
|
||||
@Override
|
||||
public HandlerList getHandlers() {
|
||||
return handlers;
|
||||
}
|
||||
}
|
||||
|
||||
/** The prefix of every message sent by NoCheatPlus. */
|
||||
private static final String TAG = ChatColor.RED + "NCP: " + ChatColor.WHITE;
|
||||
|
||||
/** The plugin. */
|
||||
private final NoCheatPlus plugin;
|
||||
|
||||
/**
|
||||
* Instantiates a new command handler.
|
||||
*
|
||||
* @param plugin
|
||||
* the instance of NoCheatPlus
|
||||
*/
|
||||
public CommandHandler(final NoCheatPlus plugin) {
|
||||
this.plugin = plugin;
|
||||
}
|
||||
|
||||
/**
|
||||
* Handle the '/nocheatplus info' command.
|
||||
*
|
||||
* @param sender
|
||||
* the sender
|
||||
* @param playerName
|
||||
* the player name
|
||||
* @return true, if successful
|
||||
*/
|
||||
private void handleInfoCommand(final CommandSender sender, final String playerName) {
|
||||
final Player player = Bukkit.getPlayer(playerName);
|
||||
if (player != null) {
|
||||
final DateFormat dateFormat = new SimpleDateFormat("HH:mm:ss");
|
||||
final TreeMap<Long, ViolationLevel> violations = ViolationHistory.getHistory(player).getViolationLevels();
|
||||
if (violations.size() > 0) {
|
||||
sender.sendMessage(TAG + "Displaying " + playerName + "'s violations...");
|
||||
for (final long time : violations.descendingKeySet()) {
|
||||
final ViolationLevel violationLevel = violations.get(time);
|
||||
final String[] parts = violationLevel.check.split("\\.");
|
||||
final String check = parts[parts.length - 1];
|
||||
final String parent = parts[parts.length - 2];
|
||||
final double VL = Math.round(violationLevel.VL);
|
||||
sender.sendMessage(TAG + "[" + dateFormat.format(new Date(time)) + "] (" + parent + ".)" + check
|
||||
+ " VL " + VL);
|
||||
}
|
||||
} else
|
||||
sender.sendMessage(TAG + "Displaying " + playerName + "'s violations... nothing to display.");
|
||||
} else {
|
||||
sender.sendMessage(TAG + "404 Not Found");
|
||||
sender.sendMessage(TAG + "The requested player was not found on this server.");
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Handle the '/nocheatplus reload' command.
|
||||
*
|
||||
* @param sender
|
||||
* the sender
|
||||
* @return true, if successful
|
||||
*/
|
||||
private void handleReloadCommand(final CommandSender sender) {
|
||||
sender.sendMessage(TAG + "Reloading configuration...");
|
||||
|
||||
// Do the actual reload.
|
||||
ConfigManager.cleanup();
|
||||
ConfigManager.init(plugin);
|
||||
BlockBreakConfig.clear();
|
||||
BlockInteractConfig.clear();
|
||||
BlockPlaceConfig.clear();
|
||||
ChatConfig.clear();
|
||||
FightConfig.clear();
|
||||
InventoryConfig.clear();
|
||||
MovingConfig.clear();
|
||||
|
||||
// Say to the other plugins that we've reloaded the configuration.
|
||||
Bukkit.getPluginManager().callEvent(new NCPReloadEvent());
|
||||
|
||||
sender.sendMessage(TAG + "Configuration reloaded!");
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see org.bukkit.command.CommandExecutor#onCommand(org.bukkit.command.CommandSender, org.bukkit.command.Command,
|
||||
* java.lang.String, java.lang.String[])
|
||||
*/
|
||||
@Override
|
||||
public boolean onCommand(final CommandSender sender, final Command command, final String commandLabel,
|
||||
final String[] args) {
|
||||
/*
|
||||
* ____ _
|
||||
* / ___|___ _ __ ___ _ __ ___ __ _ _ __ __| |
|
||||
* | | / _ \| '_ ` _ \| '_ ` _ \ / _` | '_ \ / _` |
|
||||
* | |__| (_) | | | | | | | | | | | (_| | | | | (_| |
|
||||
* \____\___/|_| |_| |_|_| |_| |_|\__,_|_| |_|\__,_|
|
||||
*/
|
||||
// Not our command, how did it get here?
|
||||
if (!command.getName().equalsIgnoreCase("nocheatplus"))
|
||||
return false;
|
||||
|
||||
final boolean protectPlugins = ConfigManager.getConfigFile().getBoolean(ConfPaths.MISCELLANEOUS_PROTECTPLUGINS);
|
||||
|
||||
if (args.length == 2 && args[0].equalsIgnoreCase("info")
|
||||
&& sender.hasPermission(Permissions.ADMINISTRATION_INFO))
|
||||
// Info command was used.
|
||||
handleInfoCommand(sender, args[1]);
|
||||
else if (args.length == 1 && args[0].equalsIgnoreCase("reload")
|
||||
&& sender.hasPermission(Permissions.ADMINISTRATION_RELOAD))
|
||||
// Reload command was used.
|
||||
handleReloadCommand(sender);
|
||||
else if (protectPlugins && !sender.hasPermission(Permissions.ADMINISTRATION_INFO)
|
||||
&& !sender.hasPermission(Permissions.ADMINISTRATION_RELOAD))
|
||||
sender.sendMessage("Unknown command. Type \"help\" for help.");
|
||||
else
|
||||
return false;
|
||||
return true;
|
||||
}
|
||||
}
|
@ -27,6 +27,7 @@ import fr.neatmonster.nocheatplus.checks.chat.ChatListener;
|
||||
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.command.CommandHandler;
|
||||
import fr.neatmonster.nocheatplus.config.ConfPaths;
|
||||
import fr.neatmonster.nocheatplus.config.ConfigFile;
|
||||
import fr.neatmonster.nocheatplus.config.ConfigManager;
|
||||
|
45
src/fr/neatmonster/nocheatplus/command/BanCommand.java
Normal file
45
src/fr/neatmonster/nocheatplus/command/BanCommand.java
Normal file
@ -0,0 +1,45 @@
|
||||
package fr.neatmonster.nocheatplus.command;
|
||||
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.OfflinePlayer;
|
||||
import org.bukkit.command.Command;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
import fr.neatmonster.nocheatplus.NoCheatPlus;
|
||||
import fr.neatmonster.nocheatplus.players.Permissions;
|
||||
|
||||
public class BanCommand extends DelayableCommand {
|
||||
|
||||
public BanCommand(NoCheatPlus plugin) {
|
||||
super(plugin, "ban", Permissions.ADMINISTRATION_BAN);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean execute(final CommandSender sender, Command command, String label,
|
||||
String[] alteredArgs, long delay) {
|
||||
// Args contains "ban" as first arg.
|
||||
if (alteredArgs.length < 2) return false;
|
||||
final String name = alteredArgs[1];
|
||||
final String reason;
|
||||
if (alteredArgs.length > 2) reason = join(alteredArgs, 2);
|
||||
else reason = "";
|
||||
schedule(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
ban(sender, name, reason);
|
||||
}
|
||||
}, delay);
|
||||
return true;
|
||||
}
|
||||
|
||||
void ban(CommandSender sender, String name, String reason) {
|
||||
Player player = Bukkit.getPlayerExact(name);
|
||||
if (player != null)
|
||||
player.kickPlayer(reason);
|
||||
OfflinePlayer offlinePlayer = Bukkit.getServer().getOfflinePlayer(name);
|
||||
offlinePlayer.setBanned(true);
|
||||
System.out.println("[NoCheatPlus] (" + sender.getName() + ") Banned " + offlinePlayer.getName() + " : " + reason);
|
||||
}
|
||||
|
||||
}
|
131
src/fr/neatmonster/nocheatplus/command/CommandHandler.java
Normal file
131
src/fr/neatmonster/nocheatplus/command/CommandHandler.java
Normal file
@ -0,0 +1,131 @@
|
||||
package fr.neatmonster.nocheatplus.command;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
import org.bukkit.ChatColor;
|
||||
import org.bukkit.command.Command;
|
||||
import org.bukkit.command.CommandExecutor;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.event.Event;
|
||||
import org.bukkit.event.HandlerList;
|
||||
|
||||
import fr.neatmonster.nocheatplus.NoCheatPlus;
|
||||
import fr.neatmonster.nocheatplus.config.ConfPaths;
|
||||
import fr.neatmonster.nocheatplus.config.ConfigManager;
|
||||
|
||||
/*
|
||||
* MM'""""'YMM dP
|
||||
* M' .mmm. `M 88
|
||||
* M MMMMMooM .d8888b. 88d8b.d8b. 88d8b.d8b. .d8888b. 88d888b. .d888b88
|
||||
* M MMMMMMMM 88' `88 88'`88'`88 88'`88'`88 88' `88 88' `88 88' `88
|
||||
* M. `MMM' .M 88. .88 88 88 88 88 88 88 88. .88 88 88 88. .88
|
||||
* MM. .dM `88888P' dP dP dP dP dP dP `88888P8 dP dP `88888P8
|
||||
* MMMMMMMMMMM
|
||||
*
|
||||
* M""MMMMM""MM dP dP
|
||||
* M MMMMM MM 88 88
|
||||
* M `M .d8888b. 88d888b. .d888b88 88 .d8888b. 88d888b.
|
||||
* M MMMMM MM 88' `88 88' `88 88' `88 88 88ooood8 88' `88
|
||||
* M MMMMM MM 88. .88 88 88 88. .88 88 88. ... 88
|
||||
* M MMMMM MM `88888P8 dP dP `88888P8 dP `88888P' dP
|
||||
* MMMMMMMMMMMM
|
||||
*/
|
||||
/**
|
||||
* This the class handling all the commands.
|
||||
*/
|
||||
public class CommandHandler implements CommandExecutor {
|
||||
|
||||
/**
|
||||
* The event triggered when NoCheatPlus configuration is reloaded.
|
||||
*/
|
||||
public static class NCPReloadEvent extends Event {
|
||||
|
||||
/** The handlers list. */
|
||||
private static final HandlerList handlers = new HandlerList();
|
||||
|
||||
/**
|
||||
* Gets the handler list.
|
||||
*
|
||||
* @return the handler list
|
||||
*/
|
||||
public static HandlerList getHandlerList() {
|
||||
return handlers;
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see org.bukkit.event.Event#getHandlers()
|
||||
*/
|
||||
@Override
|
||||
public HandlerList getHandlers() {
|
||||
return handlers;
|
||||
}
|
||||
}
|
||||
|
||||
/** 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>();
|
||||
|
||||
/**
|
||||
* Instantiates a new command handler.
|
||||
*
|
||||
* @param plugin
|
||||
* the instance of NoCheatPlus
|
||||
*/
|
||||
public CommandHandler(final NoCheatPlus plugin) {
|
||||
// Register sub commands:
|
||||
for (NCPCommand cmd : new NCPCommand[]{
|
||||
new BanCommand(plugin),
|
||||
new InfoCommand(plugin),
|
||||
new KickCommand(plugin),
|
||||
new ReloadCommand(plugin),
|
||||
new TellCommand(plugin)
|
||||
}){
|
||||
commands.put(cmd.label, cmd);
|
||||
}
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see org.bukkit.command.CommandExecutor#onCommand(org.bukkit.command.CommandSender, org.bukkit.command.Command,
|
||||
* java.lang.String, java.lang.String[])
|
||||
*/
|
||||
@Override
|
||||
public boolean onCommand(final CommandSender sender, final Command command, final String commandLabel,
|
||||
final String[] args) {
|
||||
/*
|
||||
* ____ _
|
||||
* / ___|___ _ __ ___ _ __ ___ __ _ _ __ __| |
|
||||
* | | / _ \| '_ ` _ \| '_ ` _ \ / _` | '_ \ / _` |
|
||||
* | |__| (_) | | | | | | | | | | | (_| | | | | (_| |
|
||||
* \____\___/|_| |_| |_|_| |_| |_|\__,_|_| |_|\__,_|
|
||||
*/
|
||||
// Not our command, how did it get here?
|
||||
if (!command.getName().equalsIgnoreCase("nocheatplus"))
|
||||
return false;
|
||||
|
||||
final boolean protectPlugins = ConfigManager.getConfigFile().getBoolean(ConfPaths.MISCELLANEOUS_PROTECTPLUGINS);
|
||||
|
||||
if (args.length > 0){
|
||||
NCPCommand subCommand = commands.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()){
|
||||
if (sender.hasPermission(cmd.permission)) return false;
|
||||
}
|
||||
|
||||
if (protectPlugins){
|
||||
// Prevent the NCP usage printout:
|
||||
sender.sendMessage("Unknown command. Type \"help\" for help.");
|
||||
return true;
|
||||
}
|
||||
else
|
||||
return false;
|
||||
}
|
||||
}
|
124
src/fr/neatmonster/nocheatplus/command/DelayableCommand.java
Normal file
124
src/fr/neatmonster/nocheatplus/command/DelayableCommand.java
Normal file
@ -0,0 +1,124 @@
|
||||
package fr.neatmonster.nocheatplus.command;
|
||||
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.command.Command;
|
||||
import org.bukkit.command.CommandSender;
|
||||
|
||||
import fr.neatmonster.nocheatplus.NoCheatPlus;
|
||||
|
||||
/**
|
||||
* A command that allows to specify a delay for running.
|
||||
* @author mc_dev
|
||||
*
|
||||
*/
|
||||
public abstract class DelayableCommand extends NCPCommand {
|
||||
|
||||
/**
|
||||
* Parse an argument for a delay in ticks. The delay is specified with "delay=...".
|
||||
* @param args
|
||||
* @param index
|
||||
* @return ticks or -1 if no delay found.
|
||||
*/
|
||||
public static long parseDelay(String[] args, int index){
|
||||
if (args.length <= index) return -1;
|
||||
String arg = args[index].trim().toLowerCase();
|
||||
if (!arg.startsWith("delay=")) return -1;
|
||||
if (arg.length() < 7) return -1;
|
||||
try{
|
||||
long res = Long.parseLong(arg.substring(6));
|
||||
if (res < 0)
|
||||
return -1;
|
||||
else
|
||||
return res;
|
||||
} catch (NumberFormatException e){
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
|
||||
private int delayIndex;
|
||||
private boolean mustHaveDelay;
|
||||
|
||||
/**
|
||||
* (Delay is not obligatory, inserted after the first argument.)
|
||||
* @param plugin
|
||||
* @param label
|
||||
*/
|
||||
public DelayableCommand(NoCheatPlus plugin, String label, String permission){
|
||||
this(plugin, label, permission, 1);
|
||||
}
|
||||
|
||||
/**
|
||||
* (Delay is not obligatory.)
|
||||
* @param plugin
|
||||
* @param label
|
||||
* @param delayIndex
|
||||
*/
|
||||
public DelayableCommand(NoCheatPlus plugin, String label, String permission, int delayIndex){
|
||||
this(plugin, label, permission, delayIndex, false);
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @param plugin
|
||||
* @param label Sub command label.
|
||||
* @param delayIndex Index at which to look for the delay specification.
|
||||
* @param mustHaveDelay If specifying a delay is obligatory.
|
||||
*/
|
||||
public DelayableCommand(NoCheatPlus plugin, String label, String permission, int delayIndex, boolean mustHaveDelay) {
|
||||
super(plugin, label, permission);
|
||||
this.delayIndex = delayIndex;
|
||||
this.mustHaveDelay = mustHaveDelay;
|
||||
}
|
||||
|
||||
/**
|
||||
* Execute the command, check validity and schedule a task for delayed execution (use schedule(...)).
|
||||
* @param sender
|
||||
* @param command
|
||||
* @param label Command label, this is not necessarily this.label (!), this.label can be the first argument.
|
||||
* @param alteredArgs args with the delay specification removed.
|
||||
* @param delay
|
||||
*/
|
||||
public abstract boolean execute(CommandSender sender, Command command, String label,
|
||||
String[] alteredArgs, long delay);
|
||||
|
||||
@Override
|
||||
public boolean onCommand(final CommandSender sender, final Command command,
|
||||
final String label, final String[] args ) {
|
||||
// Parse the delay and alter the args accordingly.
|
||||
long delay = parseDelay(args, delayIndex);
|
||||
String[] alteredArgs;
|
||||
if (delay == -1){
|
||||
// No delay found, if demanded return.
|
||||
if (mustHaveDelay) return false;
|
||||
alteredArgs = args;
|
||||
}
|
||||
else{
|
||||
alteredArgs = new String[args.length -1];
|
||||
int increment = 0;
|
||||
for (int i = 0; i < args.length; i++){
|
||||
if (i == delayIndex){
|
||||
// ignore this one.
|
||||
increment = -1;
|
||||
continue;
|
||||
}
|
||||
alteredArgs[i + increment] = args[i];
|
||||
}
|
||||
}
|
||||
return execute(sender, command, label, alteredArgs, delay);
|
||||
}
|
||||
|
||||
/**
|
||||
* Execute directly or schedule the task for later execution.
|
||||
* @param runnable
|
||||
* @param delay Delay in ticks.
|
||||
*/
|
||||
protected void schedule(Runnable runnable, long delay){
|
||||
if (delay < 0)
|
||||
runnable.run();
|
||||
else if (delay == 0)
|
||||
Bukkit.getScheduler().scheduleSyncDelayedTask(plugin, runnable);
|
||||
else
|
||||
Bukkit.getScheduler().scheduleSyncDelayedTask(plugin, runnable, delay);
|
||||
}
|
||||
|
||||
}
|
65
src/fr/neatmonster/nocheatplus/command/InfoCommand.java
Normal file
65
src/fr/neatmonster/nocheatplus/command/InfoCommand.java
Normal file
@ -0,0 +1,65 @@
|
||||
package fr.neatmonster.nocheatplus.command;
|
||||
|
||||
import java.text.DateFormat;
|
||||
import java.text.SimpleDateFormat;
|
||||
import java.util.Date;
|
||||
import java.util.TreeMap;
|
||||
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.command.Command;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
import fr.neatmonster.nocheatplus.NoCheatPlus;
|
||||
import fr.neatmonster.nocheatplus.checks.ViolationHistory;
|
||||
import fr.neatmonster.nocheatplus.checks.ViolationHistory.ViolationLevel;
|
||||
import fr.neatmonster.nocheatplus.players.Permissions;
|
||||
|
||||
public class InfoCommand extends NCPCommand {
|
||||
|
||||
public InfoCommand(NoCheatPlus plugin) {
|
||||
super(plugin, "info", Permissions.ADMINISTRATION_INFO);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean onCommand(CommandSender sender, Command command, String label,
|
||||
String[] args) {
|
||||
if (args.length != 2 ) return false;
|
||||
handleInfoCommand(sender, args[1]);
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Handle the '/nocheatplus info' command.
|
||||
*
|
||||
* @param sender
|
||||
* the sender
|
||||
* @param playerName
|
||||
* the player name
|
||||
* @return true, if successful
|
||||
*/
|
||||
private void handleInfoCommand(final CommandSender sender, final String playerName) {
|
||||
final Player player = Bukkit.getPlayer(playerName);
|
||||
if (player != null) {
|
||||
final DateFormat dateFormat = new SimpleDateFormat("HH:mm:ss");
|
||||
final TreeMap<Long, ViolationLevel> violations = ViolationHistory.getHistory(player).getViolationLevels();
|
||||
if (violations.size() > 0) {
|
||||
sender.sendMessage(TAG + "Displaying " + playerName + "'s violations...");
|
||||
for (final long time : violations.descendingKeySet()) {
|
||||
final ViolationLevel violationLevel = violations.get(time);
|
||||
final String[] parts = violationLevel.check.split("\\.");
|
||||
final String check = parts[parts.length - 1];
|
||||
final String parent = parts[parts.length - 2];
|
||||
final double VL = Math.round(violationLevel.VL);
|
||||
sender.sendMessage(TAG + "[" + dateFormat.format(new Date(time)) + "] (" + parent + ".)" + check
|
||||
+ " VL " + VL);
|
||||
}
|
||||
} else
|
||||
sender.sendMessage(TAG + "Displaying " + playerName + "'s violations... nothing to display.");
|
||||
} else {
|
||||
sender.sendMessage(TAG + "404 Not Found");
|
||||
sender.sendMessage(TAG + "The requested player was not found on this server.");
|
||||
}
|
||||
}
|
||||
|
||||
}
|
42
src/fr/neatmonster/nocheatplus/command/KickCommand.java
Normal file
42
src/fr/neatmonster/nocheatplus/command/KickCommand.java
Normal file
@ -0,0 +1,42 @@
|
||||
package fr.neatmonster.nocheatplus.command;
|
||||
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.command.Command;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
import fr.neatmonster.nocheatplus.NoCheatPlus;
|
||||
import fr.neatmonster.nocheatplus.players.Permissions;
|
||||
|
||||
public class KickCommand extends DelayableCommand {
|
||||
|
||||
public KickCommand(NoCheatPlus plugin) {
|
||||
super(plugin, "kick", Permissions.ADMINISTRATION_KICK);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean execute(final CommandSender sender, Command command, String label,
|
||||
String[] alteredArgs, long delay) {
|
||||
// Args contains "kick" as first arg.
|
||||
if (alteredArgs.length < 2) return false;
|
||||
final String name = alteredArgs[1];
|
||||
final String reason;
|
||||
if (alteredArgs.length > 2) reason = join(alteredArgs, 2);
|
||||
else reason = "";
|
||||
schedule(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
kick(sender, name, reason);
|
||||
}
|
||||
}, delay);
|
||||
return true;
|
||||
}
|
||||
|
||||
void kick(CommandSender sender, String name, String reason) {
|
||||
Player player = Bukkit.getPlayerExact(name);
|
||||
if (player == null) return;
|
||||
player.kickPlayer(reason);
|
||||
System.out.println("[NoCheatPlus] (" + sender.getName() + ") Kicked " + player.getName() + " : " + reason);
|
||||
}
|
||||
|
||||
}
|
65
src/fr/neatmonster/nocheatplus/command/NCPCommand.java
Normal file
65
src/fr/neatmonster/nocheatplus/command/NCPCommand.java
Normal file
@ -0,0 +1,65 @@
|
||||
package fr.neatmonster.nocheatplus.command;
|
||||
|
||||
import org.bukkit.command.Command;
|
||||
import org.bukkit.command.CommandExecutor;
|
||||
import org.bukkit.command.CommandSender;
|
||||
|
||||
import fr.neatmonster.nocheatplus.NoCheatPlus;
|
||||
|
||||
|
||||
/**
|
||||
* Just an interface for sub commands, for future use.
|
||||
* @author mc_dev
|
||||
*
|
||||
*/
|
||||
public abstract class NCPCommand implements CommandExecutor{
|
||||
|
||||
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();
|
||||
}
|
||||
|
||||
protected NoCheatPlus plugin;
|
||||
|
||||
/** The sub command label. */
|
||||
public final String label;
|
||||
|
||||
/** The command permission */
|
||||
public String permission;
|
||||
|
||||
|
||||
public NCPCommand(NoCheatPlus plugin, String label, String permission){
|
||||
this.plugin = plugin;
|
||||
this.label = label;
|
||||
this.permission = permission;
|
||||
}
|
||||
|
||||
/**
|
||||
* As with CommandExecutor, just to have the argument names correctly.
|
||||
*/
|
||||
public abstract boolean onCommand(CommandSender sender, Command command, String label, String[] args);
|
||||
|
||||
}
|
60
src/fr/neatmonster/nocheatplus/command/ReloadCommand.java
Normal file
60
src/fr/neatmonster/nocheatplus/command/ReloadCommand.java
Normal file
@ -0,0 +1,60 @@
|
||||
package fr.neatmonster.nocheatplus.command;
|
||||
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.command.Command;
|
||||
import org.bukkit.command.CommandSender;
|
||||
|
||||
import fr.neatmonster.nocheatplus.NoCheatPlus;
|
||||
import fr.neatmonster.nocheatplus.checks.blockbreak.BlockBreakConfig;
|
||||
import fr.neatmonster.nocheatplus.checks.blockinteract.BlockInteractConfig;
|
||||
import fr.neatmonster.nocheatplus.checks.blockplace.BlockPlaceConfig;
|
||||
import fr.neatmonster.nocheatplus.checks.chat.ChatConfig;
|
||||
import fr.neatmonster.nocheatplus.checks.fight.FightConfig;
|
||||
import fr.neatmonster.nocheatplus.checks.inventory.InventoryConfig;
|
||||
import fr.neatmonster.nocheatplus.checks.moving.MovingConfig;
|
||||
import fr.neatmonster.nocheatplus.command.CommandHandler.NCPReloadEvent;
|
||||
import fr.neatmonster.nocheatplus.config.ConfigManager;
|
||||
import fr.neatmonster.nocheatplus.players.Permissions;
|
||||
|
||||
public class ReloadCommand extends NCPCommand {
|
||||
|
||||
public ReloadCommand(NoCheatPlus plugin) {
|
||||
super(plugin, "reload", Permissions.ADMINISTRATION_RELOAD);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean onCommand(CommandSender sender, Command command, String label,
|
||||
String[] args) {
|
||||
if (args.length != 1) return false;
|
||||
handleReloadCommand(sender);
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Handle the '/nocheatplus reload' command.
|
||||
*
|
||||
* @param sender
|
||||
* the sender
|
||||
* @return true, if successful
|
||||
*/
|
||||
private void handleReloadCommand(final CommandSender sender) {
|
||||
sender.sendMessage(TAG + "Reloading configuration...");
|
||||
|
||||
// Do the actual reload.
|
||||
ConfigManager.cleanup();
|
||||
ConfigManager.init(plugin);
|
||||
BlockBreakConfig.clear();
|
||||
BlockInteractConfig.clear();
|
||||
BlockPlaceConfig.clear();
|
||||
ChatConfig.clear();
|
||||
FightConfig.clear();
|
||||
InventoryConfig.clear();
|
||||
MovingConfig.clear();
|
||||
|
||||
// Say to the other plugins that we've reloaded the configuration.
|
||||
Bukkit.getPluginManager().callEvent(new NCPReloadEvent());
|
||||
|
||||
sender.sendMessage(TAG + "Configuration reloaded!");
|
||||
}
|
||||
|
||||
}
|
43
src/fr/neatmonster/nocheatplus/command/TellCommand.java
Normal file
43
src/fr/neatmonster/nocheatplus/command/TellCommand.java
Normal file
@ -0,0 +1,43 @@
|
||||
package fr.neatmonster.nocheatplus.command;
|
||||
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.command.Command;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
import fr.neatmonster.nocheatplus.NoCheatPlus;
|
||||
import fr.neatmonster.nocheatplus.players.Permissions;
|
||||
import fr.neatmonster.nocheatplus.utilities.CheckUtils;
|
||||
|
||||
/**
|
||||
* For warnings etc.
|
||||
* @author mc_dev
|
||||
*
|
||||
*/
|
||||
public class TellCommand extends DelayableCommand {
|
||||
|
||||
public TellCommand(NoCheatPlus plugin) {
|
||||
super(plugin, "tell", Permissions.ADMINISTRATION_TELL);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean execute(CommandSender sender, Command command, String label,
|
||||
final String[] alteredArgs, long delay) {
|
||||
if (alteredArgs.length < 3) return false;
|
||||
final String name = alteredArgs[1].trim();
|
||||
final String message = join(alteredArgs, 2);
|
||||
schedule(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
tell(name, message);
|
||||
}
|
||||
}, delay);
|
||||
return true;
|
||||
}
|
||||
|
||||
private void tell(String name, String message) {
|
||||
Player player = Bukkit.getServer().getPlayerExact(name);
|
||||
if (player != null) player.sendMessage(CheckUtils.replaceColors(message));
|
||||
}
|
||||
|
||||
}
|
@ -24,10 +24,13 @@ public class Permissions {
|
||||
*/
|
||||
private static final String ADMINISTRATION = NOCHEATPLUS + ".admin";
|
||||
|
||||
public static final String ADMINISTRATION_BAN = ADMINISTRATION + ".ban";
|
||||
public static final String ADMINISTRATION_INFO = ADMINISTRATION + ".info";
|
||||
public static final String ADMINISTRATION_KICK = ADMINISTRATION + ".kick";
|
||||
public static final String ADMINISTRATION_NOTIFY = ADMINISTRATION + ".notify";
|
||||
public static final String ADMINISTRATION_PLUGINS = ADMINISTRATION + ".plugins";
|
||||
public static final String ADMINISTRATION_RELOAD = ADMINISTRATION + ".reload";
|
||||
public static final String ADMINISTRATION_TELL = ADMINISTRATION + ".tell";
|
||||
|
||||
private static final String CHECKS = NOCHEATPLUS + ".checks";
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user