diff --git a/src/main/java/fr/xephi/authme/command/executable/authme/ConverterCommand.java b/src/main/java/fr/xephi/authme/command/executable/authme/ConverterCommand.java index 4a02cfdc5..5c4800edf 100644 --- a/src/main/java/fr/xephi/authme/command/executable/authme/ConverterCommand.java +++ b/src/main/java/fr/xephi/authme/command/executable/authme/ConverterCommand.java @@ -1,6 +1,5 @@ package fr.xephi.authme.command.executable.authme; -import fr.xephi.authme.AuthMe; import fr.xephi.authme.command.CommandService; import fr.xephi.authme.command.ExecutableCommand; import fr.xephi.authme.converter.Converter; @@ -23,9 +22,6 @@ import java.util.List; */ public class ConverterCommand implements ExecutableCommand { - @Inject - private AuthMe authMe; - @Inject private BukkitService bukkitService; diff --git a/src/main/java/fr/xephi/authme/listener/AuthMePlayerListener.java b/src/main/java/fr/xephi/authme/listener/AuthMePlayerListener.java index ce882bcbc..9e471b85c 100644 --- a/src/main/java/fr/xephi/authme/listener/AuthMePlayerListener.java +++ b/src/main/java/fr/xephi/authme/listener/AuthMePlayerListener.java @@ -51,7 +51,6 @@ import java.util.concurrent.ConcurrentHashMap; import static fr.xephi.authme.listener.ListenerService.shouldCancelEvent; import static fr.xephi.authme.settings.properties.RestrictionSettings.ALLOWED_MOVEMENT_RADIUS; -import static fr.xephi.authme.settings.properties.RestrictionSettings.ALLOW_ALL_COMMANDS_IF_REGISTRATION_IS_OPTIONAL; import static fr.xephi.authme.settings.properties.RestrictionSettings.ALLOW_UNAUTHED_MOVEMENT; /** @@ -82,41 +81,21 @@ public class AuthMePlayerListener implements Listener { @Inject private AuthMe plugin; - private void sendLoginOrRegisterMessage(final Player player) { - bukkitService.runTaskAsynchronously(new Runnable() { - @Override - public void run() { - if (dataSource.isAuthAvailable(player.getName().toLowerCase())) { - m.send(player, MessageKey.LOGIN_MESSAGE); - } else { - if (settings.getProperty(RegistrationSettings.USE_EMAIL_REGISTRATION)) { - m.send(player, MessageKey.REGISTER_EMAIL_MESSAGE); - } else { - m.send(player, MessageKey.REGISTER_MESSAGE); - } - } - } - }); - } - @EventHandler(ignoreCancelled = true, priority = EventPriority.LOWEST) public void onPlayerCommandPreprocess(PlayerCommandPreprocessEvent event) { String cmd = event.getMessage().split(" ")[0].toLowerCase(); - if (settings.getProperty(HooksSettings.USE_ESSENTIALS_MOTD) && "/motd".equals(cmd)) { - return; - } - if (!settings.getProperty(RegistrationSettings.FORCE) - && settings.getProperty(ALLOW_ALL_COMMANDS_IF_REGISTRATION_IS_OPTIONAL)) { + if (settings.getProperty(HooksSettings.USE_ESSENTIALS_MOTD) && cmd.equals("/motd")) { return; } if (settings.getProperty(RestrictionSettings.ALLOW_COMMANDS).contains(cmd)) { return; } - if (Utils.checkAuth(event.getPlayer())) { + final Player player = event.getPlayer(); + if (!shouldCancelEvent(player)) { return; } event.setCancelled(true); - sendLoginOrRegisterMessage(event.getPlayer()); + m.send(player, MessageKey.DENIED_COMMAND); } @EventHandler(ignoreCancelled = true, priority = EventPriority.LOWEST) @@ -128,12 +107,7 @@ public class AuthMePlayerListener implements Listener { final Player player = event.getPlayer(); if (shouldCancelEvent(player)) { event.setCancelled(true); - bukkitService.runTaskAsynchronously(new Runnable() { - @Override - public void run() { - m.send(player, MessageKey.DENIED_CHAT); - } - }); + m.send(player, MessageKey.DENIED_CHAT); } else if (settings.getProperty(RestrictionSettings.HIDE_CHAT)) { Set recipients = event.getRecipients(); Iterator iter = recipients.iterator(); @@ -143,6 +117,9 @@ public class AuthMePlayerListener implements Listener { iter.remove(); } } + if (recipients.size() == 0) { + event.setCancelled(true); + } } } diff --git a/src/main/java/fr/xephi/authme/listener/FailedVerificationException.java b/src/main/java/fr/xephi/authme/listener/FailedVerificationException.java index e560ca7f0..31957cdb9 100644 --- a/src/main/java/fr/xephi/authme/listener/FailedVerificationException.java +++ b/src/main/java/fr/xephi/authme/listener/FailedVerificationException.java @@ -6,6 +6,7 @@ import fr.xephi.authme.util.StringUtils; /** * Exception thrown when a verification has failed. */ +@SuppressWarnings("serial") public class FailedVerificationException extends Exception { private final MessageKey reason; diff --git a/src/main/java/fr/xephi/authme/output/MessageKey.java b/src/main/java/fr/xephi/authme/output/MessageKey.java index 0f052c27a..eb7a52381 100644 --- a/src/main/java/fr/xephi/authme/output/MessageKey.java +++ b/src/main/java/fr/xephi/authme/output/MessageKey.java @@ -5,6 +5,8 @@ package fr.xephi.authme.output; */ public enum MessageKey { + DENIED_COMMAND("denied_command"), + SAME_IP_ONLINE("same_ip_online"), DENIED_CHAT("denied_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 96c790e2a..926ddac78 100644 --- a/src/main/java/fr/xephi/authme/settings/properties/RestrictionSettings.java +++ b/src/main/java/fr/xephi/authme/settings/properties/RestrictionSettings.java @@ -22,12 +22,6 @@ public class RestrictionSettings implements SettingsClass { 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!"}) - public static final Property ALLOW_ALL_COMMANDS_IF_REGISTRATION_IS_OPTIONAL = - newProperty("settings.restrictions.allowAllCommandsIfRegistrationIsOptional", false); - @Comment("Allowed commands for unauthenticated players") public static final Property> ALLOW_COMMANDS = newListProperty("settings.restrictions.allowCommands", diff --git a/src/main/resources/messages/messages_en.yml b/src/main/resources/messages/messages_en.yml index 2623ac0b9..75a4fcead 100644 --- a/src/main/resources/messages/messages_en.yml +++ b/src/main/resources/messages/messages_en.yml @@ -1,3 +1,4 @@ +denied_command: '&cIn order to be able to use this command you must be authenticated!' same_ip_online: 'A player with the same IP is already in game!' denied_chat: '&cIn order to be able to chat you must be authenticated!' kick_antibot: 'AntiBot protection mode is enabled! You have to wait some minutes before joining the server.' diff --git a/src/test/java/fr/xephi/authme/listener/OnJoinVerifierTest.java b/src/test/java/fr/xephi/authme/listener/OnJoinVerifierTest.java index 4f0032498..eb7e15112 100644 --- a/src/test/java/fr/xephi/authme/listener/OnJoinVerifierTest.java +++ b/src/test/java/fr/xephi/authme/listener/OnJoinVerifierTest.java @@ -388,7 +388,7 @@ public class OnJoinVerifierTest { return player; } - @SuppressWarnings("unchecked") + @SuppressWarnings({ "unchecked", "rawtypes" }) private void returnOnlineListFromBukkitServer(Collection onlineList) { // Note ljacqu 20160529: The compiler gets lost in generics because Collection is returned // from getOnlinePlayers(). We need to uncheck onlineList to a simple Collection or it will refuse to compile.