Make messages configurable for hiding plugins.

This commit is contained in:
asofold 2013-06-30 20:00:12 +02:00
parent 3b337d968d
commit 4085223594
6 changed files with 35 additions and 9 deletions

View File

@ -15,6 +15,7 @@ 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,6 +133,7 @@ public class ChatConfig extends AsyncCheckConfig {
public final boolean opInConsoleOnly;
public final boolean protectPlugins;
public final String noCommandPermMessage;
public final boolean relogCheck;
@ -228,7 +230,9 @@ public class ChatConfig extends AsyncCheckConfig {
opInConsoleOnly = config.getBoolean(ConfPaths.MISCELLANEOUS_OPINCONSOLEONLY);
// Get this one from the global config.
protectPlugins = ConfigManager.getConfigFile().getBoolean(ConfPaths.PROTECT_PLUGINS_HIDE_ACTIVE);
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

@ -156,7 +156,7 @@ public class ChatListener extends CheckListener implements INotifyReload, JoinLe
// TODO: Use a prefix map and generalize this.
// TODO: Configurable message.
if ((commandLabel.equals("plugins") || commandLabel.equals("version") || commandLabel.equals("icanhasbukkit")) && !player.hasPermission(Permissions.ADMINISTRATION_PLUGINS)) {
player.sendMessage(ChatColor.RED + "I'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.");
player.sendMessage(cc.noCommandPermMessage);
event.setCancelled(true);
return;
}

View File

@ -29,8 +29,10 @@ import fr.neatmonster.nocheatplus.command.admin.exemption.UnexemptCommand;
import fr.neatmonster.nocheatplus.command.admin.notify.NotifyCommand;
import fr.neatmonster.nocheatplus.components.INotifyReload;
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
@ -160,9 +162,11 @@ public class NoCheatPlusCommand extends BaseCommand{
return false;
}
if (ConfigManager.getConfigFile().getBoolean(ConfPaths.PROTECT_PLUGINS_HIDE_ACTIVE)){
final ConfigFile config = ConfigManager.getConfigFile();
if (config.getBoolean(ConfPaths.PROTECT_PLUGINS_HIDE_ACTIVE)){
// Prevent the NCP usage printout:
sender.sendMessage("Unknown command. Type \"help\" for help.");
// TODO: GetColoredString
sender.sendMessage(ColorUtil.replaceColors(config.getString(ConfPaths.PROTECT_PLUGINS_HIDE_MSG_NOCOMMAND)));
return true;
}
else{

View File

@ -96,8 +96,9 @@ public abstract class ConfPaths {
private static final String PROTECT_PLUGINS = PROTECT + "plugins.";
private static final String PROTECT_PLUGINS_HIDE = PROTECT_PLUGINS + "hide.";
public static final String PROTECT_PLUGINS_HIDE_ACTIVE = PROTECT_PLUGINS_HIDE + "active";
// HiddenCommandMessage + PermissionMessage
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 CHECKS = "checks.";
/** Debug flag to debug all checks (!), individual sections debug flags override this, if present. */

View File

@ -89,7 +89,9 @@ public class DefaultConfig extends ConfigFile {
// Protection features.
set(ConfPaths.PROTECT_PLUGINS_HIDE_ACTIVE, true);
set(ConfPaths.PROTECT_PLUGINS_HIDE_MSG_NOCOMMAND, "Unknown command. Type \"help\" for help.");
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.");
/*
* 888 88b, 888 888 888 88b, 888
* 888 88P' 888 e88 88e e88'888 888 ee 888 88P' 888,8, ,e e, ,"Y88b 888 ee

View File

@ -13,6 +13,8 @@ import org.bukkit.permissions.PermissionDefault;
import org.bukkit.plugin.PluginManager;
import fr.neatmonster.nocheatplus.command.CommandUtil;
import fr.neatmonster.nocheatplus.config.ConfPaths;
import fr.neatmonster.nocheatplus.config.ConfigManager;
public class PermissionUtil {
@ -68,7 +70,7 @@ public class PermissionUtil {
}
/**
*
* Set up the command protection with the "unknown command" message for the permission message (attempt to hide the command).
* @param permissionBase
* @param ignoredCommands
* @param invertIgnored
@ -76,6 +78,19 @@ public class PermissionUtil {
* @return
*/
public static List<CommandProtectionEntry> protectCommands(String permissionBase, Collection<String> ignoredCommands, boolean invertIgnored, boolean ops){
return protectCommands(permissionBase, ignoredCommands, invertIgnored, ops, ConfigManager.getConfigFile().getString(ConfPaths.PROTECT_PLUGINS_HIDE_MSG_NOCOMMAND));
}
/**
* Set up the command protection with the given permission message.
* @param permissionBase
* @param ignoredCommands
* @param invertIgnored
* @param ops
* @param permissionMessage
* @return
*/
public static List<CommandProtectionEntry> protectCommands(String permissionBase, Collection<String> ignoredCommands, boolean invertIgnored, boolean ops, String permissionMessage){
Set<String> checked = new HashSet<String>();
for (String label : ignoredCommands){
checked.add(CommandUtil.getCommandLabel(label, false));
@ -121,7 +136,7 @@ public class PermissionUtil {
else changed.add(new CommandProtectionEntry(command, lcLabel, null, null, command.getPermissionMessage()));
// Change
cmdPerm.setDefault(ops ? PermissionDefault.OP : PermissionDefault.FALSE);
command.setPermissionMessage("Unknown command. Type \"help\" for help.");
command.setPermissionMessage(permissionMessage);
}
return changed;
}