[CONFIG] Command protection: Change config sections + change to lists.

Commands to change to "no permission" or "unknown command" behavior,
can now be configured with a string list each. Commands that have a 
permission set will have the default set to false, while commands that
don't have a permission will be altered to have a filter permission,
namely nocheatplus.filter.command.<commandname>.
This commit is contained in:
asofold 2013-08-10 14:12:07 +02:00
parent 7f12312ef4
commit 2219fa0e6f
4 changed files with 33 additions and 18 deletions

View File

@ -15,7 +15,6 @@ import fr.neatmonster.nocheatplus.config.ConfPaths;
import fr.neatmonster.nocheatplus.config.ConfigFile;
import fr.neatmonster.nocheatplus.config.ConfigManager;
import fr.neatmonster.nocheatplus.permissions.Permissions;
import fr.neatmonster.nocheatplus.utilities.ColorUtil;
/*
* MM'""""'YMM dP dP MM'""""'YMM .8888b oo
@ -132,9 +131,6 @@ public class ChatConfig extends AsyncCheckConfig {
public final boolean opInConsoleOnly;
public final boolean protectPlugins;
public final String noCommandPermMessage;
public final boolean relogCheck;
public final String relogKickMessage;
@ -229,10 +225,6 @@ public class ChatConfig extends AsyncCheckConfig {
opInConsoleOnly = config.getBoolean(ConfPaths.MISCELLANEOUS_OPINCONSOLEONLY);
// Get this one from the global config.
final ConfigFile globalConfig = ConfigManager.getConfigFile();
protectPlugins = globalConfig.getBoolean(ConfPaths.PROTECT_PLUGINS_HIDE_ACTIVE);
noCommandPermMessage = ColorUtil.replaceColors(globalConfig.getString(ConfPaths.PROTECT_PLUGINS_HIDE_MSG_NOPERMISSION));
}
/* (non-Javadoc)

View File

@ -112,9 +112,12 @@ public abstract class ConfPaths {
@GlobalConfig
private static final String PROTECT_PLUGINS_HIDE = PROTECT_PLUGINS + "hide.";
public static final String PROTECT_PLUGINS_HIDE_ACTIVE = PROTECT_PLUGINS_HIDE + "active";
private static final String PROTECT_PLUGINS_HIDE_MSG = PROTECT_PLUGINS_HIDE + "messages.";
public static final String PROTECT_PLUGINS_HIDE_MSG_NOCOMMAND = PROTECT_PLUGINS_HIDE_MSG + "unknowncommand";
public static final String PROTECT_PLUGINS_HIDE_MSG_NOPERMISSION = PROTECT_PLUGINS_HIDE_MSG + "nopermission";
private static final String PROTECT_PLUGINS_HIDE_NOCOMMAND = PROTECT_PLUGINS_HIDE + "unknowncommand.";
public static final String PROTECT_PLUGINS_HIDE_NOCOMMAND_MSG = PROTECT_PLUGINS_HIDE_NOCOMMAND + "message";
public static final String PROTECT_PLUGINS_HIDE_NOCOMMAND_CMDS = PROTECT_PLUGINS_HIDE_NOCOMMAND + "commands";
private static final String PROTECT_PLUGINS_HIDE_NOPERMISSION = PROTECT_PLUGINS_HIDE + "nopermission.";
public static final String PROTECT_PLUGINS_HIDE_NOPERMISSION_MSG = PROTECT_PLUGINS_HIDE_NOPERMISSION + "message";
public static final String PROTECT_PLUGINS_HIDE_NOPERMISSION_CMDS = PROTECT_PLUGINS_HIDE_NOPERMISSION + "commands";
private static final String CHECKS = "checks.";
/** Debug flag to debug all checks (!), individual sections debug flags override this, if present. */
@ -662,5 +665,8 @@ public abstract class ConfPaths {
public static final String MISCELLANEOUS_PROTECTPLUGINS = "miscellaneous.protectplugins";
@Moved(newPath = PROTECT_CLIENTS_MOTD_ALLOWALL)
public static final String MISCELLANEOUS_ALLOWCLIENTMODS = "miscellaneous.allowclientmods";
@Moved(newPath = PROTECT_PLUGINS_HIDE_NOCOMMAND_MSG)
public static final String PROTECT_PLUGINS_HIDE_MSG_NOCOMMAND = "protection.plugins.hide.messages.unknowncommand";
@Moved(newPath = PROTECT_PLUGINS_HIDE_NOPERMISSION_MSG)
public static final String PROTECT_PLUGINS_HIDE_MSG_NOPERMISSION = "protection.plugins.hide.messages.nopermission";
}

View File

@ -94,8 +94,10 @@ public class DefaultConfig extends ConfigFile {
// Protection features.
// Hide plugins.
set(ConfPaths.PROTECT_PLUGINS_HIDE_ACTIVE, true);
set(ConfPaths.PROTECT_PLUGINS_HIDE_MSG_NOPERMISSION, "&cI'm sorry, but you do not have permission to perform this command. Please contact the server administrators if you believe that this is in error.");
set(ConfPaths.PROTECT_PLUGINS_HIDE_MSG_NOCOMMAND, "Unknown command. Type \"/help\" for help.");
set(ConfPaths.PROTECT_PLUGINS_HIDE_NOPERMISSION_MSG, "&cI'm sorry, but you do not have permission to perform this command. Please contact the server administrators if you believe that this is in error.");
set(ConfPaths.PROTECT_PLUGINS_HIDE_NOPERMISSION_CMDS, Arrays.asList("plugins", "version", "icanhasbukkit"));
set(ConfPaths.PROTECT_PLUGINS_HIDE_NOCOMMAND_MSG, "Unknown command. Type \"/help\" for help.");
set(ConfPaths.PROTECT_PLUGINS_HIDE_NOCOMMAND_CMDS, new LinkedList<String>());
// Client motd.
set(ConfPaths.PROTECT_CLIENTS_MOTD_ACTIVE, true);
set(ConfPaths.PROTECT_CLIENTS_MOTD_ALLOWALL, false);

View File

@ -2,7 +2,6 @@ package fr.neatmonster.nocheatplus;
import java.io.File;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collection;
import java.util.Collections;
import java.util.HashMap;
@ -653,9 +652,25 @@ public class NoCheatPlus extends JavaPlugin implements NoCheatPlusAPI {
}
protected void setupCommandProtection() {
final List<CommandProtectionEntry> changedCommands = PermissionUtil.protectCommands(
Permissions.FILTER_COMMAND, Arrays.asList("plugins", "version", "icanhasbukkit"),
true, false, ColorUtil.replaceColors(ConfigManager.getConfigFile().getString(ConfPaths.PROTECT_PLUGINS_HIDE_MSG_NOPERMISSION)));
// TODO: Might re-check with plugins enabling during runtime (!).
final List<CommandProtectionEntry> changedCommands = new LinkedList<CommandProtectionEntry>();
// Read lists and messages from config.
final ConfigFile config = ConfigManager.getConfigFile();
// (Might add options to invert selection.)
// "No permission".
// TODO: Could/should set permission message to null here (server default), might use keyword "default".
final List<String> noPerm = config.getStringList(ConfPaths.PROTECT_PLUGINS_HIDE_NOPERMISSION_CMDS);
if (noPerm != null && !noPerm.isEmpty()){
final String noPermMsg = ColorUtil.replaceColors(ConfigManager.getConfigFile().getString(ConfPaths.PROTECT_PLUGINS_HIDE_NOPERMISSION_MSG));
changedCommands.addAll(PermissionUtil.protectCommands(Permissions.FILTER_COMMAND, noPerm, true, false, noPermMsg));
}
// "Unknown command", override the other option.
final List<String> noCommand = config.getStringList(ConfPaths.PROTECT_PLUGINS_HIDE_NOCOMMAND_CMDS);
if (noCommand != null && !noCommand.isEmpty()){
final String noCommandMsg = ColorUtil.replaceColors(ConfigManager.getConfigFile().getString(ConfPaths.PROTECT_PLUGINS_HIDE_NOCOMMAND_MSG));
changedCommands.addAll(PermissionUtil.protectCommands(Permissions.FILTER_COMMAND, noCommand, true, false, noCommandMsg));
}
// Add to changes history for undoing.
if (this.changedCommands == null) this.changedCommands = changedCommands;
else this.changedCommands.addAll(changedCommands);
}