From 4040cd9ba69c4a768f092010535d0d8b71a7dea7 Mon Sep 17 00:00:00 2001 From: Gabriele C Date: Fri, 15 Apr 2016 21:50:32 +0200 Subject: [PATCH] #658 Add hide_chat setting --- src/main/java/fr/xephi/authme/AuthMe.java | 2 +- .../authme/listener/AuthMePlayerListener.java | 19 ++++++++++++++----- .../fr/xephi/authme/settings/Settings.java | 3 ++- .../properties/RestrictionSettings.java | 11 ++++++++--- src/main/resources/config.yml | 2 ++ 5 files changed, 27 insertions(+), 10 deletions(-) diff --git a/src/main/java/fr/xephi/authme/AuthMe.java b/src/main/java/fr/xephi/authme/AuthMe.java index d001cd4b6..bcb45b098 100644 --- a/src/main/java/fr/xephi/authme/AuthMe.java +++ b/src/main/java/fr/xephi/authme/AuthMe.java @@ -382,7 +382,7 @@ public class AuthMe extends JavaPlugin { // Register event listeners pluginManager.registerEvents(new AuthMePlayerListener( - this, messages, dataSource, antiBot, management, bukkitService), this); + this, newSettings, messages, dataSource, antiBot, management, bukkitService), this); pluginManager.registerEvents(new AuthMeBlockListener(), this); pluginManager.registerEvents(new AuthMeEntityListener(), this); pluginManager.registerEvents(new AuthMeServerListener(this, messages, pluginHooks, spawnLoader), this); diff --git a/src/main/java/fr/xephi/authme/listener/AuthMePlayerListener.java b/src/main/java/fr/xephi/authme/listener/AuthMePlayerListener.java index 4dee6f410..6ea4bd816 100644 --- a/src/main/java/fr/xephi/authme/listener/AuthMePlayerListener.java +++ b/src/main/java/fr/xephi/authme/listener/AuthMePlayerListener.java @@ -16,7 +16,11 @@ import fr.xephi.authme.output.Messages; import fr.xephi.authme.permission.PermissionsManager; import fr.xephi.authme.permission.PlayerStatePermission; import fr.xephi.authme.process.Management; +import fr.xephi.authme.settings.NewSetting; import fr.xephi.authme.settings.Settings; +import fr.xephi.authme.settings.properties.HooksSettings; +import fr.xephi.authme.settings.properties.RegistrationSettings; +import fr.xephi.authme.settings.properties.RestrictionSettings; import fr.xephi.authme.util.BukkitService; import fr.xephi.authme.util.GeoLiteAPI; import fr.xephi.authme.util.Utils; @@ -61,15 +65,17 @@ public class AuthMePlayerListener implements Listener { public static final ConcurrentHashMap joinMessage = new ConcurrentHashMap<>(); public static final ConcurrentHashMap causeByAuthMe = new ConcurrentHashMap<>(); private final AuthMe plugin; + private final NewSetting settings; private final Messages m; private final DataSource dataSource; private final AntiBot antiBot; private final Management management; private final BukkitService bukkitService; - public AuthMePlayerListener(AuthMe plugin, Messages messages, DataSource dataSource, AntiBot antiBot, + public AuthMePlayerListener(AuthMe plugin, NewSetting settings, Messages messages, DataSource dataSource, AntiBot antiBot, Management management, BukkitService bukkitService) { this.plugin = plugin; + this.settings = settings; this.m = messages; this.dataSource = dataSource; this.antiBot = antiBot; @@ -78,15 +84,18 @@ public class AuthMePlayerListener implements Listener { } private void handleChat(AsyncPlayerChatEvent event) { - if (Settings.isChatAllowed) { + if (settings.getProperty(RestrictionSettings.ALLOW_CHAT)) { return; } final Player player = event.getPlayer(); if (Utils.checkAuth(player)) { for (Player p : Utils.getOnlinePlayers()) { + if(!settings.getProperty(RestrictionSettings.HIDE_CHAT)) { + break; + } if (!PlayerCache.getInstance().isAuthenticated(p.getName())) { - event.getRecipients().remove(p); // TODO: it should be configurable + event.getRecipients().remove(p); } } return; @@ -103,7 +112,7 @@ public class AuthMePlayerListener implements Listener { if (dataSource.isAuthAvailable(player.getName().toLowerCase())) { m.send(player, MessageKey.LOGIN_MESSAGE); } else { - if (Settings.emailRegistration) { + if (settings.getProperty(RegistrationSettings.USE_EMAIL_REGISTRATION)) { m.send(player, MessageKey.REGISTER_EMAIL_MESSAGE); } else { m.send(player, MessageKey.REGISTER_MESSAGE); @@ -116,7 +125,7 @@ public class AuthMePlayerListener implements Listener { @EventHandler(ignoreCancelled = true, priority = EventPriority.LOWEST) public void onPlayerCommandPreprocess(PlayerCommandPreprocessEvent event) { String cmd = event.getMessage().split(" ")[0].toLowerCase(); - if (Settings.useEssentialsMotd && cmd.equals("/motd")) { + if (settings.getProperty(HooksSettings.USE_ESSENTIALS_MOTD) && cmd.equals("/motd")) { return; } if (!Settings.isForcedRegistrationEnabled && Settings.allowAllCommandsIfRegIsOptional) { diff --git a/src/main/java/fr/xephi/authme/settings/Settings.java b/src/main/java/fr/xephi/authme/settings/Settings.java index 2a24628f8..f448adeeb 100644 --- a/src/main/java/fr/xephi/authme/settings/Settings.java +++ b/src/main/java/fr/xephi/authme/settings/Settings.java @@ -47,7 +47,7 @@ public final class Settings { broadcastWelcomeMessage, forceRegKick, forceRegLogin, removeJoinMessage, removeLeaveMessage, delayJoinMessage, noTeleport, allowAllCommandsIfRegIsOptional, - isRemoveSpeedEnabled, preventOtherCase; + isRemoveSpeedEnabled, preventOtherCase, hideChat; public static String getNickRegex, getUnloggedinGroup, unRegisteredGroup, backupWindowsPath, getRegisteredGroup, rakamakUsers, rakamakUsersIp, defaultWorld, @@ -154,6 +154,7 @@ public final class Settings { forceRegisterCommands = configFile.getStringList("settings.forceRegisterCommands"); forceRegisterCommandsAsConsole = configFile.getStringList("settings.forceRegisterCommandsAsConsole"); preventOtherCase = configFile.getBoolean("settings.preventOtherCase", false); + hideChat = load(RestrictionSettings.HIDE_CHAT); } /** diff --git a/src/main/java/fr/xephi/authme/settings/properties/RestrictionSettings.java b/src/main/java/fr/xephi/authme/settings/properties/RestrictionSettings.java index c2b2cb687..72cb8a9be 100644 --- a/src/main/java/fr/xephi/authme/settings/properties/RestrictionSettings.java +++ b/src/main/java/fr/xephi/authme/settings/properties/RestrictionSettings.java @@ -12,12 +12,16 @@ import static fr.xephi.authme.settings.domain.Property.newProperty; public class RestrictionSettings implements SettingsClass { @Comment({ - "Can not authenticated players chat and see the chat log?", + "Can not authenticated players chat?", "Keep in mind that this feature also blocks all commands not", "listed in the list below."}) public static final Property ALLOW_CHAT = newProperty("settings.restrictions.allowChat", false); + @Comment("Can not authenticated players see the chat log?") + public static final Property HIDE_CHAT = + newProperty("settings.restrictions.hideChat", false); + @Comment({ "Allow unlogged users to use all the commands if registration is not forced!", "WARNING: use this only if you need it!)"}) @@ -29,8 +33,9 @@ public class RestrictionSettings implements SettingsClass { newListProperty("settings.restrictions.allowCommands", "login", "register", "l", "reg", "email", "captcha"); - @Comment("Max number of allowed registrations per IP") - // TODO ljacqu 20160109: If 0 == unlimited, add this fact to the comment + @Comment({ + "Max number of allowed registrations per IP", + "The value 0 means an unlimited number of registrations!"}) public static final Property MAX_REGISTRATION_PER_IP = newProperty("settings.restrictions.maxRegPerIp", 1); diff --git a/src/main/resources/config.yml b/src/main/resources/config.yml index fd6a9cb04..86aecfaa4 100644 --- a/src/main/resources/config.yml +++ b/src/main/resources/config.yml @@ -67,6 +67,8 @@ settings: # Care that this feature blocks also all the commands not # listed in the list below. allowChat: false + # Can not authenticated players see the chat log? + hideChat: false # WARNING: use this only if you need it! # Allow unlogged users to use all the commands if registration is not forced! allowAllCommandsIfRegistrationIsOptional: false