From da7e7edc378aaff5a77ad71a8eea230324434829 Mon Sep 17 00:00:00 2001 From: Gabriele C Date: Sun, 26 Aug 2018 15:29:47 +0200 Subject: [PATCH] Fix messaging [WIP] (#1614) * Fix messaging [WIP] * Make codeclimate happy * Codeclimate, pls * got it, i hope * Improvements * Remove duplicated checks, other improvements, make login/logout broadcasts * Optimize project imports * Make codeclimate happy again --- .../fr/xephi/authme/api/v3/AuthMeApi.java | 2 - .../authme/PurgeBannedPlayersCommand.java | 2 +- .../authme/SwitchAntiBotCommand.java | 2 +- .../authme/debug/LimboPlayerViewer.java | 2 +- .../authme/datasource/CacheDataSource.java | 5 ++ .../xephi/authme/datasource/DataSource.java | 9 +++ .../xephi/authme/listener/EntityListener.java | 1 - .../xephi/authme/listener/ServerListener.java | 3 +- .../xephi/authme/mail/OAuth2SaslClient.java | 4 +- .../authme/mail/OAuth2SaslClientFactory.java | 5 +- .../process/email/AsyncChangeEmail.java | 15 ++++- .../process/register/AsyncRegister.java | 2 +- .../authme/security/crypts/BCryptService.java | 1 - .../security/crypts/HexSaltedMethod.java | 2 +- .../fr/xephi/authme/security/crypts/Ipb3.java | 2 +- .../fr/xephi/authme/security/crypts/MyBB.java | 2 +- .../authme/security/crypts/PhpFusion.java | 2 +- .../authme/security/crypts/Salted2Md5.java | 2 +- .../authme/security/crypts/SaltedSha512.java | 2 +- .../fr/xephi/authme/security/crypts/Wbb3.java | 2 +- .../fr/xephi/authme/service/GeoIpService.java | 4 +- .../service/bungeecord/BungeeReceiver.java | 35 +++++----- .../service/bungeecord/BungeeSender.java | 18 ++++-- .../service/bungeecord/MessageType.java | 64 +++++++++++++++---- .../fr/xephi/authme/task/purge/PurgeTask.java | 1 - 25 files changed, 130 insertions(+), 59 deletions(-) diff --git a/src/main/java/fr/xephi/authme/api/v3/AuthMeApi.java b/src/main/java/fr/xephi/authme/api/v3/AuthMeApi.java index 575c61ab1..7dcf137c3 100644 --- a/src/main/java/fr/xephi/authme/api/v3/AuthMeApi.java +++ b/src/main/java/fr/xephi/authme/api/v3/AuthMeApi.java @@ -12,13 +12,11 @@ import fr.xephi.authme.security.crypts.HashedPassword; import fr.xephi.authme.service.GeoIpService; import fr.xephi.authme.service.ValidationService; import fr.xephi.authme.util.PlayerUtils; - import org.bukkit.Bukkit; import org.bukkit.Location; import org.bukkit.entity.Player; import javax.inject.Inject; - import java.time.Instant; import java.util.ArrayList; import java.util.Date; diff --git a/src/main/java/fr/xephi/authme/command/executable/authme/PurgeBannedPlayersCommand.java b/src/main/java/fr/xephi/authme/command/executable/authme/PurgeBannedPlayersCommand.java index ff41ddbac..82b109cc3 100644 --- a/src/main/java/fr/xephi/authme/command/executable/authme/PurgeBannedPlayersCommand.java +++ b/src/main/java/fr/xephi/authme/command/executable/authme/PurgeBannedPlayersCommand.java @@ -1,8 +1,8 @@ package fr.xephi.authme.command.executable.authme; import fr.xephi.authme.command.ExecutableCommand; -import fr.xephi.authme.task.purge.PurgeService; import fr.xephi.authme.service.BukkitService; +import fr.xephi.authme.task.purge.PurgeService; import org.bukkit.OfflinePlayer; import org.bukkit.command.CommandSender; diff --git a/src/main/java/fr/xephi/authme/command/executable/authme/SwitchAntiBotCommand.java b/src/main/java/fr/xephi/authme/command/executable/authme/SwitchAntiBotCommand.java index 44c303843..1e72c0587 100644 --- a/src/main/java/fr/xephi/authme/command/executable/authme/SwitchAntiBotCommand.java +++ b/src/main/java/fr/xephi/authme/command/executable/authme/SwitchAntiBotCommand.java @@ -1,10 +1,10 @@ package fr.xephi.authme.command.executable.authme; -import fr.xephi.authme.service.AntiBotService; import fr.xephi.authme.command.CommandMapper; import fr.xephi.authme.command.ExecutableCommand; import fr.xephi.authme.command.FoundCommandResult; import fr.xephi.authme.command.help.HelpProvider; +import fr.xephi.authme.service.AntiBotService; import org.bukkit.ChatColor; import org.bukkit.command.CommandSender; diff --git a/src/main/java/fr/xephi/authme/command/executable/authme/debug/LimboPlayerViewer.java b/src/main/java/fr/xephi/authme/command/executable/authme/debug/LimboPlayerViewer.java index 8be10c5f2..7338c8686 100644 --- a/src/main/java/fr/xephi/authme/command/executable/authme/debug/LimboPlayerViewer.java +++ b/src/main/java/fr/xephi/authme/command/executable/authme/debug/LimboPlayerViewer.java @@ -17,8 +17,8 @@ import java.util.Map; import java.util.Optional; import java.util.function.Function; -import static fr.xephi.authme.command.executable.authme.debug.DebugSectionUtils.formatLocation; import static fr.xephi.authme.command.executable.authme.debug.DebugSectionUtils.applyToLimboPlayersMap; +import static fr.xephi.authme.command.executable.authme.debug.DebugSectionUtils.formatLocation; /** * Shows the data stored in LimboPlayers and the equivalent properties on online players. diff --git a/src/main/java/fr/xephi/authme/datasource/CacheDataSource.java b/src/main/java/fr/xephi/authme/datasource/CacheDataSource.java index 165560b1e..ec57cd57f 100644 --- a/src/main/java/fr/xephi/authme/datasource/CacheDataSource.java +++ b/src/main/java/fr/xephi/authme/datasource/CacheDataSource.java @@ -71,6 +71,11 @@ public class CacheDataSource implements DataSource { source.reload(); } + @Override + public boolean isCached() { + return true; + } + @Override public boolean isAuthAvailable(String user) { return getAuth(user) != null; diff --git a/src/main/java/fr/xephi/authme/datasource/DataSource.java b/src/main/java/fr/xephi/authme/datasource/DataSource.java index 6ce28852f..3152eb17e 100644 --- a/src/main/java/fr/xephi/authme/datasource/DataSource.java +++ b/src/main/java/fr/xephi/authme/datasource/DataSource.java @@ -14,6 +14,15 @@ import java.util.Set; */ public interface DataSource extends Reloadable { + /** + * Return whether the data source is cached and needs to send plugin messaging updates. + * + * @return true if the data source is cached. + */ + default boolean isCached() { + return false; + } + /** * Return whether there is a record for the given username. * diff --git a/src/main/java/fr/xephi/authme/listener/EntityListener.java b/src/main/java/fr/xephi/authme/listener/EntityListener.java index ff6af1c65..7c8281861 100644 --- a/src/main/java/fr/xephi/authme/listener/EntityListener.java +++ b/src/main/java/fr/xephi/authme/listener/EntityListener.java @@ -1,7 +1,6 @@ package fr.xephi.authme.listener; import fr.xephi.authme.ConsoleLogger; - import org.bukkit.entity.LivingEntity; import org.bukkit.entity.Player; import org.bukkit.entity.Projectile; diff --git a/src/main/java/fr/xephi/authme/listener/ServerListener.java b/src/main/java/fr/xephi/authme/listener/ServerListener.java index 4aceaf6fe..8bebf3613 100644 --- a/src/main/java/fr/xephi/authme/listener/ServerListener.java +++ b/src/main/java/fr/xephi/authme/listener/ServerListener.java @@ -1,15 +1,16 @@ package fr.xephi.authme.listener; import fr.xephi.authme.ConsoleLogger; -import fr.xephi.authme.service.PluginHookService; import fr.xephi.authme.listener.protocollib.ProtocolLibService; import fr.xephi.authme.permission.PermissionsManager; +import fr.xephi.authme.service.PluginHookService; import fr.xephi.authme.settings.SpawnLoader; import org.bukkit.event.EventHandler; import org.bukkit.event.EventPriority; import org.bukkit.event.Listener; import org.bukkit.event.server.PluginDisableEvent; import org.bukkit.event.server.PluginEnableEvent; + import javax.inject.Inject; /** diff --git a/src/main/java/fr/xephi/authme/mail/OAuth2SaslClient.java b/src/main/java/fr/xephi/authme/mail/OAuth2SaslClient.java index f6e7a5f33..1f9b8c50c 100644 --- a/src/main/java/fr/xephi/authme/mail/OAuth2SaslClient.java +++ b/src/main/java/fr/xephi/authme/mail/OAuth2SaslClient.java @@ -14,13 +14,13 @@ */ package fr.xephi.authme.mail; -import java.io.IOException; import javax.security.auth.callback.Callback; import javax.security.auth.callback.CallbackHandler; import javax.security.auth.callback.NameCallback; import javax.security.auth.callback.UnsupportedCallbackException; import javax.security.sasl.SaslClient; import javax.security.sasl.SaslException; +import java.io.IOException; /** * An OAuth2 implementation of SaslClient. @@ -95,4 +95,4 @@ class OAuth2SaslClient implements SaslClient { public void dispose() throws SaslException { } -} \ No newline at end of file +} diff --git a/src/main/java/fr/xephi/authme/mail/OAuth2SaslClientFactory.java b/src/main/java/fr/xephi/authme/mail/OAuth2SaslClientFactory.java index 09a448059..a3ec879e9 100644 --- a/src/main/java/fr/xephi/authme/mail/OAuth2SaslClientFactory.java +++ b/src/main/java/fr/xephi/authme/mail/OAuth2SaslClientFactory.java @@ -15,12 +15,11 @@ */ package fr.xephi.authme.mail; -import java.util.Map; -import java.util.logging.Logger; - import javax.security.auth.callback.CallbackHandler; import javax.security.sasl.SaslClient; import javax.security.sasl.SaslClientFactory; +import java.util.Map; +import java.util.logging.Logger; /** * A SaslClientFactory that returns instances of OAuth2SaslClient. diff --git a/src/main/java/fr/xephi/authme/process/email/AsyncChangeEmail.java b/src/main/java/fr/xephi/authme/process/email/AsyncChangeEmail.java index 26a5da9e7..df141c6cd 100644 --- a/src/main/java/fr/xephi/authme/process/email/AsyncChangeEmail.java +++ b/src/main/java/fr/xephi/authme/process/email/AsyncChangeEmail.java @@ -35,16 +35,17 @@ public class AsyncChangeEmail implements AsynchronousProcess { @Inject private BungeeSender bungeeSender; - + @Inject private BukkitService bukkitService; - AsyncChangeEmail() { } + AsyncChangeEmail() { + } /** * Handles the request to change the player's email address. * - * @param player the player to change the email for + * @param player the player to change the email for * @param oldEmail provided old email * @param newEmail provided new email */ @@ -70,6 +71,14 @@ public class AsyncChangeEmail implements AsynchronousProcess { } } + /** + * Saves the new email value into the database and informs services. + * + * @param auth the player auth object + * @param player the player object + * @param oldEmail the old email value + * @param newEmail the new email value + */ private void saveNewEmail(PlayerAuth auth, Player player, String oldEmail, String newEmail) { EmailChangedEvent event = bukkitService.createAndCallEvent(isAsync -> new EmailChangedEvent(player, oldEmail, newEmail, isAsync)); diff --git a/src/main/java/fr/xephi/authme/process/register/AsyncRegister.java b/src/main/java/fr/xephi/authme/process/register/AsyncRegister.java index 7f52befe2..608267f00 100644 --- a/src/main/java/fr/xephi/authme/process/register/AsyncRegister.java +++ b/src/main/java/fr/xephi/authme/process/register/AsyncRegister.java @@ -66,7 +66,7 @@ public class AsyncRegister implements AsynchronousProcess { * Checks if the player is able to register, in that case the {@link AuthMeAsyncPreRegisterEvent} is invoked. * * @param variant the registration type variant. - * @param player the player which is trying to register. + * @param player the player which is trying to register. * * @return true if the checks are successful and the event hasn't marked the action as denied, false otherwise. */ diff --git a/src/main/java/fr/xephi/authme/security/crypts/BCryptService.java b/src/main/java/fr/xephi/authme/security/crypts/BCryptService.java index 6b82305c7..f08d94d35 100644 --- a/src/main/java/fr/xephi/authme/security/crypts/BCryptService.java +++ b/src/main/java/fr/xephi/authme/security/crypts/BCryptService.java @@ -15,7 +15,6 @@ package fr.xephi.authme.security.crypts; // OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. import java.io.UnsupportedEncodingException; - import java.security.SecureRandom; /** diff --git a/src/main/java/fr/xephi/authme/security/crypts/HexSaltedMethod.java b/src/main/java/fr/xephi/authme/security/crypts/HexSaltedMethod.java index 5ac8caf8b..81e767722 100644 --- a/src/main/java/fr/xephi/authme/security/crypts/HexSaltedMethod.java +++ b/src/main/java/fr/xephi/authme/security/crypts/HexSaltedMethod.java @@ -1,10 +1,10 @@ package fr.xephi.authme.security.crypts; -import fr.xephi.authme.util.RandomStringUtils; import fr.xephi.authme.security.crypts.description.HasSalt; import fr.xephi.authme.security.crypts.description.Recommendation; import fr.xephi.authme.security.crypts.description.SaltType; import fr.xephi.authme.security.crypts.description.Usage; +import fr.xephi.authme.util.RandomStringUtils; /** * Common type for encryption methods which use a random String of hexadecimal characters diff --git a/src/main/java/fr/xephi/authme/security/crypts/Ipb3.java b/src/main/java/fr/xephi/authme/security/crypts/Ipb3.java index 15dcd189b..b29df4fc5 100644 --- a/src/main/java/fr/xephi/authme/security/crypts/Ipb3.java +++ b/src/main/java/fr/xephi/authme/security/crypts/Ipb3.java @@ -1,10 +1,10 @@ package fr.xephi.authme.security.crypts; -import fr.xephi.authme.util.RandomStringUtils; import fr.xephi.authme.security.crypts.description.HasSalt; import fr.xephi.authme.security.crypts.description.Recommendation; import fr.xephi.authme.security.crypts.description.SaltType; import fr.xephi.authme.security.crypts.description.Usage; +import fr.xephi.authme.util.RandomStringUtils; import static fr.xephi.authme.security.HashUtils.md5; diff --git a/src/main/java/fr/xephi/authme/security/crypts/MyBB.java b/src/main/java/fr/xephi/authme/security/crypts/MyBB.java index 3f0a477ab..1abbe72ca 100644 --- a/src/main/java/fr/xephi/authme/security/crypts/MyBB.java +++ b/src/main/java/fr/xephi/authme/security/crypts/MyBB.java @@ -1,10 +1,10 @@ package fr.xephi.authme.security.crypts; -import fr.xephi.authme.util.RandomStringUtils; import fr.xephi.authme.security.crypts.description.HasSalt; import fr.xephi.authme.security.crypts.description.Recommendation; import fr.xephi.authme.security.crypts.description.SaltType; import fr.xephi.authme.security.crypts.description.Usage; +import fr.xephi.authme.util.RandomStringUtils; import static fr.xephi.authme.security.HashUtils.md5; diff --git a/src/main/java/fr/xephi/authme/security/crypts/PhpFusion.java b/src/main/java/fr/xephi/authme/security/crypts/PhpFusion.java index 5a49ed4ce..b97441171 100644 --- a/src/main/java/fr/xephi/authme/security/crypts/PhpFusion.java +++ b/src/main/java/fr/xephi/authme/security/crypts/PhpFusion.java @@ -1,10 +1,10 @@ package fr.xephi.authme.security.crypts; import fr.xephi.authme.security.HashUtils; -import fr.xephi.authme.util.RandomStringUtils; import fr.xephi.authme.security.crypts.description.AsciiRestricted; import fr.xephi.authme.security.crypts.description.Recommendation; import fr.xephi.authme.security.crypts.description.Usage; +import fr.xephi.authme.util.RandomStringUtils; import javax.crypto.Mac; import javax.crypto.spec.SecretKeySpec; diff --git a/src/main/java/fr/xephi/authme/security/crypts/Salted2Md5.java b/src/main/java/fr/xephi/authme/security/crypts/Salted2Md5.java index 6d708b3ce..3d2166a75 100644 --- a/src/main/java/fr/xephi/authme/security/crypts/Salted2Md5.java +++ b/src/main/java/fr/xephi/authme/security/crypts/Salted2Md5.java @@ -1,12 +1,12 @@ package fr.xephi.authme.security.crypts; -import fr.xephi.authme.util.RandomStringUtils; import fr.xephi.authme.security.crypts.description.HasSalt; import fr.xephi.authme.security.crypts.description.Recommendation; import fr.xephi.authme.security.crypts.description.SaltType; import fr.xephi.authme.security.crypts.description.Usage; import fr.xephi.authme.settings.Settings; import fr.xephi.authme.settings.properties.SecuritySettings; +import fr.xephi.authme.util.RandomStringUtils; import javax.inject.Inject; diff --git a/src/main/java/fr/xephi/authme/security/crypts/SaltedSha512.java b/src/main/java/fr/xephi/authme/security/crypts/SaltedSha512.java index b5660d658..b5578b93b 100644 --- a/src/main/java/fr/xephi/authme/security/crypts/SaltedSha512.java +++ b/src/main/java/fr/xephi/authme/security/crypts/SaltedSha512.java @@ -1,9 +1,9 @@ package fr.xephi.authme.security.crypts; import fr.xephi.authme.security.HashUtils; -import fr.xephi.authme.util.RandomStringUtils; import fr.xephi.authme.security.crypts.description.Recommendation; import fr.xephi.authme.security.crypts.description.Usage; +import fr.xephi.authme.util.RandomStringUtils; @Recommendation(Usage.RECOMMENDED) public class SaltedSha512 extends SeparateSaltMethod { diff --git a/src/main/java/fr/xephi/authme/security/crypts/Wbb3.java b/src/main/java/fr/xephi/authme/security/crypts/Wbb3.java index 0a042b489..8e26463bb 100644 --- a/src/main/java/fr/xephi/authme/security/crypts/Wbb3.java +++ b/src/main/java/fr/xephi/authme/security/crypts/Wbb3.java @@ -1,10 +1,10 @@ package fr.xephi.authme.security.crypts; -import fr.xephi.authme.util.RandomStringUtils; import fr.xephi.authme.security.crypts.description.HasSalt; import fr.xephi.authme.security.crypts.description.Recommendation; import fr.xephi.authme.security.crypts.description.SaltType; import fr.xephi.authme.security.crypts.description.Usage; +import fr.xephi.authme.util.RandomStringUtils; import static fr.xephi.authme.security.HashUtils.sha1; diff --git a/src/main/java/fr/xephi/authme/service/GeoIpService.java b/src/main/java/fr/xephi/authme/service/GeoIpService.java index deaa55c13..924e09351 100644 --- a/src/main/java/fr/xephi/authme/service/GeoIpService.java +++ b/src/main/java/fr/xephi/authme/service/GeoIpService.java @@ -13,12 +13,12 @@ import com.maxmind.db.Reader.FileMode; import com.maxmind.db.cache.CHMCache; import com.maxmind.db.model.Country; import com.maxmind.db.model.CountryResponse; - import fr.xephi.authme.ConsoleLogger; import fr.xephi.authme.initialization.DataFolder; import fr.xephi.authme.util.FileUtils; import fr.xephi.authme.util.InternetProtocolUtils; +import javax.inject.Inject; import java.io.BufferedInputStream; import java.io.File; import java.io.FileNotFoundException; @@ -41,8 +41,6 @@ import java.util.Objects; import java.util.Optional; import java.util.zip.GZIPInputStream; -import javax.inject.Inject; - public class GeoIpService { private static final String LICENSE = diff --git a/src/main/java/fr/xephi/authme/service/bungeecord/BungeeReceiver.java b/src/main/java/fr/xephi/authme/service/bungeecord/BungeeReceiver.java index 0cc112aa9..faeedb644 100644 --- a/src/main/java/fr/xephi/authme/service/bungeecord/BungeeReceiver.java +++ b/src/main/java/fr/xephi/authme/service/bungeecord/BungeeReceiver.java @@ -15,6 +15,7 @@ import org.bukkit.plugin.messaging.Messenger; import org.bukkit.plugin.messaging.PluginMessageListener; import javax.inject.Inject; +import java.util.Optional; public class BungeeReceiver implements PluginMessageListener, SettingsDependent { @@ -59,32 +60,36 @@ public class BungeeReceiver implements PluginMessageListener, SettingsDependent return; } - String type = in.readUTF(); - String name = in.readUTF(); - switch (type) { - case MessageType.UNREGISTER: - dataSource.invalidateCache(name); + Optional type = MessageType.fromId(in.readUTF()); + if(!type.isPresent()) { + ConsoleLogger.debug("Received unsupported bungeecord message type! ({0})", type); + return; + } + + String argument = in.readUTF(); + switch (type.get()) { + case UNREGISTER: + dataSource.invalidateCache(argument); break; - case MessageType.REFRESH_PASSWORD: - case MessageType.REFRESH_QUITLOC: - case MessageType.REFRESH_EMAIL: - case MessageType.REFRESH: - dataSource.refreshCache(name); + case REFRESH_PASSWORD: + case REFRESH_QUITLOC: + case REFRESH_EMAIL: + case REFRESH: + dataSource.refreshCache(argument); break; - case MessageType.BUNGEE_LOGIN: - handleBungeeLogin(name); + case PERFORM_LOGIN: + performLogin(argument); break; default: - ConsoleLogger.debug("Received unsupported bungeecord message type! ({0})", type); } } - private void handleBungeeLogin(String name) { + private void performLogin(String name) { Player player = bukkitService.getPlayerExact(name); if (player != null && player.isOnline()) { management.forceLogin(player); ConsoleLogger.info("The user " + player.getName() + " has been automatically logged in, " - + "as requested by the AuthMeBungee integration."); + + "as requested via plugin messaging."); } } diff --git a/src/main/java/fr/xephi/authme/service/bungeecord/BungeeSender.java b/src/main/java/fr/xephi/authme/service/bungeecord/BungeeSender.java index 84fda6956..aee7a3cfc 100644 --- a/src/main/java/fr/xephi/authme/service/bungeecord/BungeeSender.java +++ b/src/main/java/fr/xephi/authme/service/bungeecord/BungeeSender.java @@ -4,6 +4,7 @@ import com.google.common.io.ByteArrayDataOutput; import com.google.common.io.ByteStreams; import fr.xephi.authme.AuthMe; import fr.xephi.authme.ConsoleLogger; +import fr.xephi.authme.datasource.DataSource; import fr.xephi.authme.initialization.SettingsDependent; import fr.xephi.authme.service.BukkitService; import fr.xephi.authme.settings.Settings; @@ -17,6 +18,7 @@ public class BungeeSender implements SettingsDependent { private final AuthMe plugin; private final BukkitService bukkitService; + private final DataSource dataSource; private boolean isEnabled; private String destinationServerOnLogin; @@ -25,9 +27,10 @@ public class BungeeSender implements SettingsDependent { * Constructor. */ @Inject - BungeeSender(AuthMe plugin, BukkitService bukkitService, Settings settings) { + BungeeSender(AuthMe plugin, BukkitService bukkitService, DataSource dataSource, Settings settings) { this.plugin = plugin; this.bukkitService = bukkitService; + this.dataSource = dataSource; reload(settings); } @@ -75,13 +78,20 @@ public class BungeeSender implements SettingsDependent { * @param type The message type, See {@link MessageType} * @param playerName the player related to the message */ - public void sendAuthMeBungeecordMessage(String type, String playerName) { + public void sendAuthMeBungeecordMessage(MessageType type, String playerName) { if (isEnabled) { - if(!plugin.isEnabled()) { + if (!plugin.isEnabled()) { ConsoleLogger.debug("Tried to send a " + type + " bungeecord message but the plugin was disabled!"); return; } - sendBungeecordMessage("AuthMe", type, playerName.toLowerCase()); + if(type.isRequiresCaching() && !dataSource.isCached()) { + return; + } + if (type.isBroadcast()) { + sendBungeecordMessage("Forward", "ALL", "AuthMe", type.getId(), playerName.toLowerCase()); + } else { + sendBungeecordMessage("AuthMe", type.getId(), playerName.toLowerCase()); + } } } diff --git a/src/main/java/fr/xephi/authme/service/bungeecord/MessageType.java b/src/main/java/fr/xephi/authme/service/bungeecord/MessageType.java index c8543bea1..bb40af203 100644 --- a/src/main/java/fr/xephi/authme/service/bungeecord/MessageType.java +++ b/src/main/java/fr/xephi/authme/service/bungeecord/MessageType.java @@ -1,19 +1,59 @@ package fr.xephi.authme.service.bungeecord; -public final class MessageType { +import java.util.Optional; - public static final String LOGIN = "login"; - public static final String LOGOUT = "logout"; - public static final String REGISTER = "register"; - public static final String UNREGISTER = "unregister"; - public static final String REFRESH_PASSWORD = "refresh.password"; - public static final String REFRESH_SESSION = "refresh.session"; - public static final String REFRESH_QUITLOC = "refresh.quitloc"; - public static final String REFRESH_EMAIL = "refresh.email"; - public static final String REFRESH = "refresh"; - public static final String BUNGEE_LOGIN = "bungeelogin"; +public enum MessageType { + REFRESH_PASSWORD("refresh.password", true), + REFRESH_SESSION("refresh.session", true), + REFRESH_QUITLOC("refresh.quitloc", true), + REFRESH_EMAIL("refresh.email", true), + REFRESH("refresh", true), + REGISTER("register", true), + UNREGISTER("unregister", true), + LOGIN("login", true), + LOGOUT("logout", true), + PERFORM_LOGIN("perform.login", false); - private MessageType() { + private final String id; + private final boolean broadcast; + private final boolean requiresCaching; + + MessageType(String id, boolean broadcast, boolean requiresCaching) { + this.id = id; + this.broadcast = broadcast; + this.requiresCaching = requiresCaching; + } + + MessageType(String id, boolean broadcast) { + this(id, broadcast, false); + } + + public String getId() { + return id; + } + + public boolean isBroadcast() { + return broadcast; + } + + public boolean isRequiresCaching() { + return requiresCaching; + } + + /** + * Returns the MessageType with the given ID. + * + * @param id the message type id. + * + * @return the MessageType with the given id, empty if invalid. + */ + public static Optional fromId(String id) { + for (MessageType current : values()) { + if (current.getId().equals(id)) { + return Optional.of(current); + } + } + return Optional.empty(); } } diff --git a/src/main/java/fr/xephi/authme/task/purge/PurgeTask.java b/src/main/java/fr/xephi/authme/task/purge/PurgeTask.java index 686bab86d..2a381ceba 100644 --- a/src/main/java/fr/xephi/authme/task/purge/PurgeTask.java +++ b/src/main/java/fr/xephi/authme/task/purge/PurgeTask.java @@ -3,7 +3,6 @@ package fr.xephi.authme.task.purge; import fr.xephi.authme.ConsoleLogger; import fr.xephi.authme.permission.PermissionsManager; import fr.xephi.authme.permission.PlayerStatePermission; -import fr.xephi.authme.permission.handlers.PermissionLoadUserException; import org.bukkit.Bukkit; import org.bukkit.ChatColor; import org.bukkit.OfflinePlayer;