diff --git a/bukkit/src/main/java/com/github/games647/fastlogin/bukkit/FastLoginBukkit.java b/bukkit/src/main/java/com/github/games647/fastlogin/bukkit/FastLoginBukkit.java index a81c285c..c7482801 100644 --- a/bukkit/src/main/java/com/github/games647/fastlogin/bukkit/FastLoginBukkit.java +++ b/bukkit/src/main/java/com/github/games647/fastlogin/bukkit/FastLoginBukkit.java @@ -120,9 +120,9 @@ public class FastLoginBukkit extends JavaPlugin { } //remove old blacklists - for (Player player : getServer().getOnlinePlayers()) { + getServer().getOnlinePlayers().forEach(player -> { player.removeMetadata(getName(), this); - } + }); } public BukkitCore getCore() { diff --git a/bukkit/src/main/java/com/github/games647/fastlogin/bukkit/commands/CrackedCommand.java b/bukkit/src/main/java/com/github/games647/fastlogin/bukkit/commands/CrackedCommand.java index 0cb2659f..0235c87e 100644 --- a/bukkit/src/main/java/com/github/games647/fastlogin/bukkit/commands/CrackedCommand.java +++ b/bukkit/src/main/java/com/github/games647/fastlogin/bukkit/commands/CrackedCommand.java @@ -42,11 +42,8 @@ public class CrackedCommand implements CommandExecutor { sender.sendMessage(plugin.getCore().getMessage("remove-premium")); profile.setPremium(false); profile.setUuid(null); - Bukkit.getScheduler().runTaskAsynchronously(plugin, new Runnable() { - @Override - public void run() { - plugin.getCore().getStorage().save(profile); - } + Bukkit.getScheduler().runTaskAsynchronously(plugin, () -> { + plugin.getCore().getStorage().save(profile); }); } else { sender.sendMessage(plugin.getCore().getMessage("not-premium")); @@ -87,11 +84,8 @@ public class CrackedCommand implements CommandExecutor { } else { sender.sendMessage(plugin.getCore().getMessage("remove-premium")); profile.setPremium(false); - Bukkit.getScheduler().runTaskAsynchronously(plugin, new Runnable() { - @Override - public void run() { - plugin.getCore().getStorage().save(profile); - } + Bukkit.getScheduler().runTaskAsynchronously(plugin, () -> { + plugin.getCore().getStorage().save(profile); }); } } diff --git a/bukkit/src/main/java/com/github/games647/fastlogin/bukkit/commands/PremiumCommand.java b/bukkit/src/main/java/com/github/games647/fastlogin/bukkit/commands/PremiumCommand.java index bda241ee..9ba15f47 100644 --- a/bukkit/src/main/java/com/github/games647/fastlogin/bukkit/commands/PremiumCommand.java +++ b/bukkit/src/main/java/com/github/games647/fastlogin/bukkit/commands/PremiumCommand.java @@ -59,11 +59,8 @@ public class PremiumCommand implements CommandExecutor { } else { //todo: resolve uuid profile.setPremium(true); - Bukkit.getScheduler().runTaskAsynchronously(plugin, new Runnable() { - @Override - public void run() { - plugin.getCore().getStorage().save(profile); - } + Bukkit.getScheduler().runTaskAsynchronously(plugin, () -> { + plugin.getCore().getStorage().save(profile); }); sender.sendMessage(plugin.getCore().getMessage("add-premium")); @@ -103,11 +100,8 @@ public class PremiumCommand implements CommandExecutor { } else { //todo: resolve uuid profile.setPremium(true); - Bukkit.getScheduler().runTaskAsynchronously(plugin, new Runnable() { - @Override - public void run() { - plugin.getCore().getStorage().save(profile); - } + Bukkit.getScheduler().runTaskAsynchronously(plugin, () -> { + plugin.getCore().getStorage().save(profile); }); sender.sendMessage(plugin.getCore().getMessage("add-premium-other")); diff --git a/bukkit/src/main/java/com/github/games647/fastlogin/bukkit/hooks/CrazyLoginHook.java b/bukkit/src/main/java/com/github/games647/fastlogin/bukkit/hooks/CrazyLoginHook.java index 5022e441..4e70fb54 100644 --- a/bukkit/src/main/java/com/github/games647/fastlogin/bukkit/hooks/CrazyLoginHook.java +++ b/bukkit/src/main/java/com/github/games647/fastlogin/bukkit/hooks/CrazyLoginHook.java @@ -8,7 +8,6 @@ import de.st_ddt.crazylogin.databases.CrazyLoginDataDatabase; import de.st_ddt.crazylogin.listener.PlayerListener; import de.st_ddt.crazylogin.metadata.Authenticated; -import java.util.concurrent.Callable; import java.util.concurrent.ExecutionException; import java.util.concurrent.Future; import java.util.logging.Level; @@ -32,39 +31,35 @@ public class CrazyLoginHook implements AuthPlugin { @Override public boolean forceLogin(final Player player) { //not thread-safe operation - Future future = Bukkit.getScheduler().callSyncMethod(crazyLoginPlugin - , new Callable() { - @Override - public LoginPlayerData call() throws Exception { - LoginPlayerData playerData = crazyLoginPlugin.getPlayerData(player.getName()); - if (playerData != null) { - //mark the account as logged in - playerData.setLoggedIn(true); + Future future = Bukkit.getScheduler().callSyncMethod(crazyLoginPlugin, () -> { + LoginPlayerData playerData = crazyLoginPlugin.getPlayerData(player.getName()); + if (playerData != null) { + //mark the account as logged in + playerData.setLoggedIn(true); - String ip = player.getAddress().getAddress().getHostAddress(); + String ip = player.getAddress().getAddress().getHostAddress(); //this should be done after login to restore the inventory, unhide players, prevent potential memory leaks... //from: https://github.com/ST-DDT/CrazyLogin/blob/master/src/main/java/de/st_ddt/crazylogin/CrazyLogin.java#L1948 - playerData.resetLoginFails(); - player.setFireTicks(0); + playerData.resetLoginFails(); + player.setFireTicks(0); - if (playerListener != null) { - playerListener.removeMovementBlocker(player); - playerListener.disableHidenInventory(player); - playerListener.disableSaveLogin(player); - playerListener.unhidePlayer(player); - } - - //loginFailuresPerIP.remove(IP); - //illegalCommandUsesPerIP.remove(IP); - //tempBans.remove(IP); - playerData.addIP(ip); - player.setMetadata("Authenticated", new Authenticated(crazyLoginPlugin, player)); - crazyLoginPlugin.unregisterDynamicHooks(); - return playerData; + if (playerListener != null) { + playerListener.removeMovementBlocker(player); + playerListener.disableHidenInventory(player); + playerListener.disableSaveLogin(player); + playerListener.unhidePlayer(player); } - return null; +//loginFailuresPerIP.remove(IP); +//illegalCommandUsesPerIP.remove(IP); +//tempBans.remove(IP); + playerData.addIP(ip); + player.setMetadata("Authenticated", new Authenticated(crazyLoginPlugin, player)); + crazyLoginPlugin.unregisterDynamicHooks(); + return playerData; } + + return null; }); try { @@ -110,7 +105,7 @@ public class CrazyLoginHook implements AuthPlugin { PlayerListener listener; try { listener = (PlayerListener) FieldUtils.readField(crazyLoginPlugin, "playerListener", true); - } catch (Exception ex) { + } catch (IllegalAccessException ex) { crazyLoginPlugin.getLogger().log(Level.SEVERE, "Failed to get the listener instance for auto login", ex); listener = null; } diff --git a/bukkit/src/main/java/com/github/games647/fastlogin/bukkit/hooks/RoyalAuthHook.java b/bukkit/src/main/java/com/github/games647/fastlogin/bukkit/hooks/RoyalAuthHook.java index 877134ae..0e7d8020 100644 --- a/bukkit/src/main/java/com/github/games647/fastlogin/bukkit/hooks/RoyalAuthHook.java +++ b/bukkit/src/main/java/com/github/games647/fastlogin/bukkit/hooks/RoyalAuthHook.java @@ -2,7 +2,6 @@ package com.github.games647.fastlogin.bukkit.hooks; import com.github.games647.fastlogin.core.hooks.AuthPlugin; -import java.util.concurrent.Callable; import java.util.concurrent.ExecutionException; import java.util.concurrent.Future; import java.util.logging.Level; @@ -27,17 +26,14 @@ public class RoyalAuthHook implements AuthPlugin { @Override public boolean forceLogin(final Player player) { //not thread-safe - Future future = Bukkit.getScheduler().callSyncMethod(royalAuthPlugin, new Callable() { - @Override - public Boolean call() throws Exception { - AuthPlayer authPlayer = AuthPlayer.getAuthPlayer(player); + Future future = Bukkit.getScheduler().callSyncMethod(royalAuthPlugin, () -> { + AuthPlayer authPlayer = AuthPlayer.getAuthPlayer(player); //https://github.com/RoyalDev/RoyalAuth/blob/master/src/main/java/org/royaldev/royalauth/commands/CmdLogin.java#L62 - //not thread-safe - authPlayer.login(); +//not thread-safe + authPlayer.login(); - return authPlayer.isLoggedIn(); - } + return authPlayer.isLoggedIn(); }); try { diff --git a/bukkit/src/main/java/com/github/games647/fastlogin/bukkit/hooks/UltraAuthHook.java b/bukkit/src/main/java/com/github/games647/fastlogin/bukkit/hooks/UltraAuthHook.java index 90f4d0b0..c8dd12e3 100644 --- a/bukkit/src/main/java/com/github/games647/fastlogin/bukkit/hooks/UltraAuthHook.java +++ b/bukkit/src/main/java/com/github/games647/fastlogin/bukkit/hooks/UltraAuthHook.java @@ -2,7 +2,6 @@ package com.github.games647.fastlogin.bukkit.hooks; import com.github.games647.fastlogin.core.hooks.AuthPlugin; -import java.util.concurrent.Callable; import java.util.concurrent.ExecutionException; import java.util.concurrent.Future; import java.util.logging.Level; @@ -28,12 +27,9 @@ public class UltraAuthHook implements AuthPlugin { @Override public boolean forceLogin(final Player player) { //not thread-safe - Future future = Bukkit.getScheduler().callSyncMethod(ultraAuthPlugin, new Callable() { - @Override - public Boolean call() throws Exception { - UltraAuthAPI.authenticatedPlayer(player); - return UltraAuthAPI.isAuthenticated(player); - } + Future future = Bukkit.getScheduler().callSyncMethod(ultraAuthPlugin, () -> { + UltraAuthAPI.authenticatedPlayer(player); + return UltraAuthAPI.isAuthenticated(player); }); try { diff --git a/bukkit/src/main/java/com/github/games647/fastlogin/bukkit/hooks/xAuthHook.java b/bukkit/src/main/java/com/github/games647/fastlogin/bukkit/hooks/xAuthHook.java index e3fe15c0..4036b058 100644 --- a/bukkit/src/main/java/com/github/games647/fastlogin/bukkit/hooks/xAuthHook.java +++ b/bukkit/src/main/java/com/github/games647/fastlogin/bukkit/hooks/xAuthHook.java @@ -5,7 +5,6 @@ import com.github.games647.fastlogin.core.hooks.AuthPlugin; import de.luricos.bukkit.xAuth.xAuth; import de.luricos.bukkit.xAuth.xAuthPlayer; -import java.util.concurrent.Callable; import java.util.concurrent.ExecutionException; import java.util.concurrent.Future; import java.util.logging.Level; @@ -28,20 +27,17 @@ public class xAuthHook implements AuthPlugin { @Override public boolean forceLogin(final Player player) { //not thread-safe - Future future = Bukkit.getScheduler().callSyncMethod(xAuthPlugin, new Callable() { - @Override - public Boolean call() throws Exception { - xAuthPlayer xAuthPlayer = xAuthPlugin.getPlayerManager().getPlayer(player); - if (xAuthPlayer != null) { - //we checked that the player is premium (paid account) - xAuthPlayer.setPremium(true); + Future future = Bukkit.getScheduler().callSyncMethod(xAuthPlugin, () -> { + xAuthPlayer xAuthPlayer = xAuthPlugin.getPlayerManager().getPlayer(player); + if (xAuthPlayer != null) { + //we checked that the player is premium (paid account) + xAuthPlayer.setPremium(true); - //unprotect the inventory, op status... - return xAuthPlugin.getPlayerManager().doLogin(xAuthPlayer); - } - - return false; + //unprotect the inventory, op status... + return xAuthPlugin.getPlayerManager().doLogin(xAuthPlayer); } + + return false; }); try { @@ -62,21 +58,18 @@ public class xAuthHook implements AuthPlugin { @Override public boolean forceRegister(final Player player, final String password) { //not thread-safe - Future future = Bukkit.getScheduler().callSyncMethod(xAuthPlugin, new Callable() { - @Override - public Boolean call() throws Exception { - xAuthPlayer xAuthPlayer = xAuthPlugin.getPlayerManager().getPlayer(player); - if (xAuthPlayer != null) { - //this should run async because the plugin executes a sql query, but the method - //accesses non thread-safe collections :( - boolean registerSuccess = xAuthPlugin.getAuthClass(xAuthPlayer) - .adminRegister(player.getName(), password, null); + Future future = Bukkit.getScheduler().callSyncMethod(xAuthPlugin, () -> { + xAuthPlayer xAuthPlayer = xAuthPlugin.getPlayerManager().getPlayer(player); + if (xAuthPlayer != null) { + //this should run async because the plugin executes a sql query, but the method + //accesses non thread-safe collections :( + boolean registerSuccess = xAuthPlugin.getAuthClass(xAuthPlayer) + .adminRegister(player.getName(), password, null); - return registerSuccess; - } - - return false; + return registerSuccess; } + + return false; }); try { diff --git a/bukkit/src/main/java/com/github/games647/fastlogin/bukkit/listener/BukkitJoinListener.java b/bukkit/src/main/java/com/github/games647/fastlogin/bukkit/listener/BukkitJoinListener.java index 50ee0eac..986673f6 100644 --- a/bukkit/src/main/java/com/github/games647/fastlogin/bukkit/listener/BukkitJoinListener.java +++ b/bukkit/src/main/java/com/github/games647/fastlogin/bukkit/listener/BukkitJoinListener.java @@ -21,7 +21,7 @@ public class BukkitJoinListener implements Listener { private static final long DELAY_LOGIN = 20L / 2; - protected final FastLoginBukkit plugin; + private final FastLoginBukkit plugin; public BukkitJoinListener(FastLoginBukkit plugin) { this.plugin = plugin; diff --git a/bukkit/src/main/java/com/github/games647/fastlogin/bukkit/listener/BungeeCordListener.java b/bukkit/src/main/java/com/github/games647/fastlogin/bukkit/listener/BungeeCordListener.java index 338f54cb..3c78d288 100644 --- a/bukkit/src/main/java/com/github/games647/fastlogin/bukkit/listener/BungeeCordListener.java +++ b/bukkit/src/main/java/com/github/games647/fastlogin/bukkit/listener/BungeeCordListener.java @@ -52,10 +52,10 @@ public class BungeeCordListener implements PluginMessageListener { plugin.getLogger().log(Level.FINEST, "Received plugin message for subchannel {0} from {1}" , new Object[]{subchannel, player}); - final String playerName = dataInput.readUTF(); + String playerName = dataInput.readUTF(); //check if the player is still online or disconnected - final Player checkedPlayer = plugin.getServer().getPlayerExact(playerName); + Player checkedPlayer = plugin.getServer().getPlayerExact(playerName); //fail if target player is blacklisted because already authed or wrong bungeecord id if (checkedPlayer != null && !checkedPlayer.hasMetadata(plugin.getName())) { //blacklist this target player for BungeeCord Id brute force attacks @@ -77,21 +77,18 @@ public class BungeeCordListener implements PluginMessageListener { plugin.getSessions().put(id, playerSession); Bukkit.getScheduler().runTaskAsynchronously(plugin, new ForceLoginTask(plugin, player)); } else if ("AUTO_REGISTER".equalsIgnoreCase(subchannel)) { - Bukkit.getScheduler().runTaskAsynchronously(plugin, new Runnable() { - @Override - public void run() { - AuthPlugin authPlugin = plugin.getCore().getAuthPluginHook(); - try { - //we need to check if the player is registered on Bukkit too - if (authPlugin == null || !authPlugin.isRegistered(playerName)) { - BukkitLoginSession playerSession = new BukkitLoginSession(playerName, false); - playerSession.setVerified(true); - plugin.getSessions().put(id, playerSession); - new ForceLoginTask(plugin, player).run(); - } - } catch (Exception ex) { - plugin.getLogger().log(Level.SEVERE, "Failed to query isRegistered", ex); + Bukkit.getScheduler().runTaskAsynchronously(plugin, () -> { + AuthPlugin authPlugin = plugin.getCore().getAuthPluginHook(); + try { + //we need to check if the player is registered on Bukkit too + if (authPlugin == null || !authPlugin.isRegistered(playerName)) { + BukkitLoginSession playerSession = new BukkitLoginSession(playerName, false); + playerSession.setVerified(true); + plugin.getSessions().put(id, playerSession); + new ForceLoginTask(plugin, player).run(); } + } catch (Exception ex) { + plugin.getLogger().log(Level.SEVERE, "Failed to query isRegistered", ex); } }); } diff --git a/bukkit/src/main/java/com/github/games647/fastlogin/bukkit/listener/protocollib/ProtocolLibLoginSource.java b/bukkit/src/main/java/com/github/games647/fastlogin/bukkit/listener/protocollib/ProtocolLibLoginSource.java index 84cb679f..1becc0c2 100644 --- a/bukkit/src/main/java/com/github/games647/fastlogin/bukkit/listener/protocollib/ProtocolLibLoginSource.java +++ b/bukkit/src/main/java/com/github/games647/fastlogin/bukkit/listener/protocollib/ProtocolLibLoginSource.java @@ -28,7 +28,7 @@ public class ProtocolLibLoginSource implements LoginSource { private final Random random; private String serverId; - private byte[] verifyToken = new byte[VERIFY_TOKEN_LENGTH]; + private final byte[] verifyToken = new byte[VERIFY_TOKEN_LENGTH]; public ProtocolLibLoginSource(FastLoginBukkit plugin, PacketEvent packetEvent, Player player, Random random) { this.plugin = plugin; diff --git a/bukkit/src/main/java/com/github/games647/fastlogin/bukkit/tasks/DelayedAuthHook.java b/bukkit/src/main/java/com/github/games647/fastlogin/bukkit/tasks/DelayedAuthHook.java index 3b4ff5d9..13a62851 100644 --- a/bukkit/src/main/java/com/github/games647/fastlogin/bukkit/tasks/DelayedAuthHook.java +++ b/bukkit/src/main/java/com/github/games647/fastlogin/bukkit/tasks/DelayedAuthHook.java @@ -9,8 +9,8 @@ import com.github.games647.fastlogin.bukkit.hooks.UltraAuthHook; import com.github.games647.fastlogin.bukkit.hooks.xAuthHook; import com.github.games647.fastlogin.core.hooks.AuthPlugin; import com.google.common.collect.Lists; +import java.util.List; -import java.util.ArrayList; import java.util.logging.Level; import org.bukkit.Bukkit; @@ -40,7 +40,7 @@ public class DelayedAuthHook implements Runnable { private boolean registerHooks() { AuthPlugin authPluginHook = null; try { - ArrayList>> supportedHooks = Lists.newArrayList(AuthMeHook.class + List>> supportedHooks = Lists.newArrayList(AuthMeHook.class , CrazyLoginHook.class, LogItHook.class, LoginSecurityHook.class, UltraAuthHook.class , xAuthHook.class); for (Class> clazz : supportedHooks) { diff --git a/bukkit/src/main/java/com/github/games647/fastlogin/bukkit/tasks/ForceLoginTask.java b/bukkit/src/main/java/com/github/games647/fastlogin/bukkit/tasks/ForceLoginTask.java index 596bd6f4..584365cc 100644 --- a/bukkit/src/main/java/com/github/games647/fastlogin/bukkit/tasks/ForceLoginTask.java +++ b/bukkit/src/main/java/com/github/games647/fastlogin/bukkit/tasks/ForceLoginTask.java @@ -122,12 +122,7 @@ public class ForceLoginTask implements Runnable { private boolean isOnlineThreadSafe() { //the playerlist isn't thread-safe - Future onlineFuture = Bukkit.getScheduler().callSyncMethod(plugin, new Callable() { - @Override - public Boolean call() throws Exception { - return player.isOnline(); - } - }); + Future onlineFuture = Bukkit.getScheduler().callSyncMethod(plugin, player::isOnline); try { return onlineFuture.get(); diff --git a/bungee/src/main/java/com/github/games647/fastlogin/bungee/BungeeCore.java b/bungee/src/main/java/com/github/games647/fastlogin/bungee/BungeeCore.java index bc0d5148..7b05df28 100644 --- a/bungee/src/main/java/com/github/games647/fastlogin/bungee/BungeeCore.java +++ b/bungee/src/main/java/com/github/games647/fastlogin/bungee/BungeeCore.java @@ -26,9 +26,9 @@ public class BungeeCore extends FastLoginCore { private static Map generateConfigMap(Configuration config) { Map configMap = Maps.newHashMap(); Collection keys = config.getKeys(); - for (String key : keys) { + keys.forEach(key -> { configMap.put(key, config.get(key)); - } + }); return configMap; } @@ -72,12 +72,12 @@ public class BungeeCore extends FastLoginCore { File messageFile = new File(getDataFolder(), "messages.yml"); Configuration messageConfig = ConfigurationProvider.getProvider(YamlConfiguration.class) .load(messageFile, defaults); - for (String key : messageConfig.getKeys()) { + messageConfig.getKeys().forEach((key) -> { String message = ChatColor.translateAlternateColorCodes('&', messageConfig.getString(key)); if (!message.isEmpty()) { localeMessages.put(key, message); } - } + }); } catch (IOException ex) { getLogger().log(Level.SEVERE, "Failed to load messages", ex); } diff --git a/bungee/src/main/java/com/github/games647/fastlogin/bungee/hooks/BungeeAuthPlugin.java b/bungee/src/main/java/com/github/games647/fastlogin/bungee/hooks/BungeeAuthPlugin.java index cd688efb..ead48fbf 100644 --- a/bungee/src/main/java/com/github/games647/fastlogin/bungee/hooks/BungeeAuthPlugin.java +++ b/bungee/src/main/java/com/github/games647/fastlogin/bungee/hooks/BungeeAuthPlugin.java @@ -9,9 +9,12 @@ import net.md_5.bungee.api.connection.ProxiedPlayer; @Deprecated public interface BungeeAuthPlugin extends AuthPlugin { + @Override boolean forceLogin(ProxiedPlayer player); + @Override boolean isRegistered(String playerName) throws Exception; + @Override boolean forceRegister(ProxiedPlayer player, String password); } diff --git a/bungee/src/main/java/com/github/games647/fastlogin/bungee/listener/PlayerConnectionListener.java b/bungee/src/main/java/com/github/games647/fastlogin/bungee/listener/PlayerConnectionListener.java index 520ff401..14786197 100644 --- a/bungee/src/main/java/com/github/games647/fastlogin/bungee/listener/PlayerConnectionListener.java +++ b/bungee/src/main/java/com/github/games647/fastlogin/bungee/listener/PlayerConnectionListener.java @@ -45,7 +45,10 @@ public class PlayerConnectionListener implements Listener { } preLoginEvent.registerIntent(plugin); - ProxyServer.getInstance().getScheduler().runAsync(plugin, new AsyncPremiumCheck(plugin, preLoginEvent)); + + PendingConnection connection = preLoginEvent.getConnection(); + AsyncPremiumCheck asyncPremiumCheck = new AsyncPremiumCheck(plugin, preLoginEvent, connection); + ProxyServer.getInstance().getScheduler().runAsync(plugin, asyncPremiumCheck); } @EventHandler(priority = EventPriority.LOW) diff --git a/bungee/src/main/java/com/github/games647/fastlogin/bungee/listener/PluginMessageListener.java b/bungee/src/main/java/com/github/games647/fastlogin/bungee/listener/PluginMessageListener.java index b35de067..5b2d1441 100644 --- a/bungee/src/main/java/com/github/games647/fastlogin/bungee/listener/PluginMessageListener.java +++ b/bungee/src/main/java/com/github/games647/fastlogin/bungee/listener/PluginMessageListener.java @@ -44,46 +44,43 @@ public class PluginMessageListener implements Listener { private void readMessage(PluginMessageEvent pluginMessageEvent) { //so that we can safely process this in the background - final byte[] data = Arrays.copyOf(pluginMessageEvent.getData(), pluginMessageEvent.getData().length); - final ProxiedPlayer forPlayer = (ProxiedPlayer) pluginMessageEvent.getReceiver(); + byte[] data = Arrays.copyOf(pluginMessageEvent.getData(), pluginMessageEvent.getData().length); + ProxiedPlayer forPlayer = (ProxiedPlayer) pluginMessageEvent.getReceiver(); - ProxyServer.getInstance().getScheduler().runAsync(plugin, new Runnable() { - @Override - public void run() { - ByteArrayDataInput dataInput = ByteStreams.newDataInput(data); - String subchannel = dataInput.readUTF(); - if ("ON".equals(subchannel)) { - String playerName = dataInput.readUTF(); - - if (playerName.equals(forPlayer.getName()) && plugin.getConfig().getBoolean("premium-warning") - && !plugin.getCore().getPendingConfirms().contains(forPlayer.getUniqueId())) { - String message = plugin.getCore().getMessage("premium-warning"); - forPlayer.sendMessage(TextComponent.fromLegacyText(message)); - plugin.getCore().getPendingConfirms().add(forPlayer.getUniqueId()); - return; - } - - plugin.getCore().getPendingConfirms().remove(forPlayer.getUniqueId()); - AsyncToggleMessage task = new AsyncToggleMessage(plugin, forPlayer, playerName, true); - ProxyServer.getInstance().getScheduler().runAsync(plugin, task); - } else if ("OFF".equals(subchannel)) { - String playerName = dataInput.readUTF(); - - AsyncToggleMessage task = new AsyncToggleMessage(plugin, forPlayer, playerName, false); - ProxyServer.getInstance().getScheduler().runAsync(plugin, task); - } else if ("SUCCESS".equals(subchannel)) { - if (forPlayer.getPendingConnection().isOnlineMode()) { - //bukkit module successfully received and force logged in the user - //update only on success to prevent corrupt data - BungeeLoginSession loginSession = plugin.getSession().get(forPlayer.getPendingConnection()); - PlayerProfile playerProfile = loginSession.getProfile(); - loginSession.setRegistered(true); - - if (!loginSession.isAlreadySaved()) { - playerProfile.setPremium(true); - plugin.getCore().getStorage().save(playerProfile); - loginSession.setAlreadySaved(true); - } + ProxyServer.getInstance().getScheduler().runAsync(plugin, () -> { + ByteArrayDataInput dataInput = ByteStreams.newDataInput(data); + String subchannel = dataInput.readUTF(); + if ("ON".equals(subchannel)) { + String playerName = dataInput.readUTF(); + + if (playerName.equals(forPlayer.getName()) && plugin.getConfig().getBoolean("premium-warning") + && !plugin.getCore().getPendingConfirms().contains(forPlayer.getUniqueId())) { + String message = plugin.getCore().getMessage("premium-warning"); + forPlayer.sendMessage(TextComponent.fromLegacyText(message)); + plugin.getCore().getPendingConfirms().add(forPlayer.getUniqueId()); + return; + } + + plugin.getCore().getPendingConfirms().remove(forPlayer.getUniqueId()); + AsyncToggleMessage task = new AsyncToggleMessage(plugin, forPlayer, playerName, true); + ProxyServer.getInstance().getScheduler().runAsync(plugin, task); + } else if ("OFF".equals(subchannel)) { + String playerName = dataInput.readUTF(); + + AsyncToggleMessage task = new AsyncToggleMessage(plugin, forPlayer, playerName, false); + ProxyServer.getInstance().getScheduler().runAsync(plugin, task); + } else if ("SUCCESS".equals(subchannel)) { + if (forPlayer.getPendingConnection().isOnlineMode()) { + //bukkit module successfully received and force logged in the user + //update only on success to prevent corrupt data + BungeeLoginSession loginSession = plugin.getSession().get(forPlayer.getPendingConnection()); + PlayerProfile playerProfile = loginSession.getProfile(); + loginSession.setRegistered(true); + + if (!loginSession.isAlreadySaved()) { + playerProfile.setPremium(true); + plugin.getCore().getStorage().save(playerProfile); + loginSession.setAlreadySaved(true); } } } diff --git a/bungee/src/main/java/com/github/games647/fastlogin/bungee/tasks/AsyncPremiumCheck.java b/bungee/src/main/java/com/github/games647/fastlogin/bungee/tasks/AsyncPremiumCheck.java index 941181b7..0bbe188d 100644 --- a/bungee/src/main/java/com/github/games647/fastlogin/bungee/tasks/AsyncPremiumCheck.java +++ b/bungee/src/main/java/com/github/games647/fastlogin/bungee/tasks/AsyncPremiumCheck.java @@ -8,23 +8,25 @@ import com.github.games647.fastlogin.core.shared.JoinManagement; import net.md_5.bungee.api.connection.PendingConnection; import net.md_5.bungee.api.connection.ProxiedPlayer; -import net.md_5.bungee.api.event.PreLoginEvent; +import net.md_5.bungee.api.event.AsyncEvent; public class AsyncPremiumCheck extends JoinManagement implements Runnable { private final FastLoginBungee plugin; - private final PreLoginEvent preLoginEvent; + private final AsyncEvent preLoginEvent; - public AsyncPremiumCheck(FastLoginBungee plugin, PreLoginEvent preLoginEvent) { + private final PendingConnection connection; + + public AsyncPremiumCheck(FastLoginBungee plugin, AsyncEvent preLoginEvent, PendingConnection connection) { super(plugin.getCore(), plugin.getCore().getAuthPluginHook()); this.plugin = plugin; this.preLoginEvent = preLoginEvent; + this.connection = connection; } @Override public void run() { - PendingConnection connection = preLoginEvent.getConnection(); plugin.getSession().remove(connection); String username = connection.getName(); diff --git a/bungee/src/main/java/com/github/games647/fastlogin/bungee/tasks/ForceLoginTask.java b/bungee/src/main/java/com/github/games647/fastlogin/bungee/tasks/ForceLoginTask.java index b3bbe9d5..b2d373bc 100644 --- a/bungee/src/main/java/com/github/games647/fastlogin/bungee/tasks/ForceLoginTask.java +++ b/bungee/src/main/java/com/github/games647/fastlogin/bungee/tasks/ForceLoginTask.java @@ -9,8 +9,8 @@ import com.google.common.io.ByteStreams; import java.util.UUID; import java.util.logging.Level; -import net.md_5.bungee.api.chat.TextComponent; +import net.md_5.bungee.api.chat.TextComponent; import net.md_5.bungee.api.connection.PendingConnection; import net.md_5.bungee.api.connection.ProxiedPlayer; import net.md_5.bungee.api.connection.Server; diff --git a/core/src/main/java/com/github/games647/fastlogin/core/AuthStorage.java b/core/src/main/java/com/github/games647/fastlogin/core/AuthStorage.java index 39d52aae..5cf73ad5 100644 --- a/core/src/main/java/com/github/games647/fastlogin/core/AuthStorage.java +++ b/core/src/main/java/com/github/games647/fastlogin/core/AuthStorage.java @@ -18,13 +18,13 @@ public class AuthStorage { private static final String PREMIUM_TABLE = "premium"; - private final FastLoginCore core; + private final FastLoginCore core; private final HikariDataSource dataSource; //a try to fix https://www.spigotmc.org/threads/fastlogin.101192/page-26#post-1874647 private final Calendar calendar = Calendar.getInstance(Locale.US); - public AuthStorage(FastLoginCore core, String driver, String host, int port, String databasePath + public AuthStorage(FastLoginCore core, String driver, String host, int port, String databasePath , String user, String pass) { this.core = core; diff --git a/core/src/main/java/com/github/games647/fastlogin/core/BalancedSSLFactory.java b/core/src/main/java/com/github/games647/fastlogin/core/BalancedSSLFactory.java index 61e55a0f..cc56083d 100644 --- a/core/src/main/java/com/github/games647/fastlogin/core/BalancedSSLFactory.java +++ b/core/src/main/java/com/github/games647/fastlogin/core/BalancedSSLFactory.java @@ -7,6 +7,7 @@ import java.net.UnknownHostException; import java.util.ArrayList; import java.util.List; import java.util.Set; +import java.util.concurrent.atomic.AtomicInteger; import javax.net.ssl.SSLSocketFactory; @@ -17,9 +18,7 @@ public class BalancedSSLFactory extends SSLSocketFactory { //in order to be thread-safe private final List localAddresses; - private final Object lock = new Object(); - - private int id; + private AtomicInteger id; public BalancedSSLFactory(SSLSocketFactory oldFactory, Set localAddresses) { this.oldFactory = oldFactory; @@ -65,16 +64,7 @@ public class BalancedSSLFactory extends SSLSocketFactory { } private InetAddress getNextLocalAddress() { - int next; - synchronized (lock) { - next = id; - id++; - if (next == Integer.MAX_VALUE) { - id = 0; - } - } - - int index = next % localAddresses.size(); + int index = id.incrementAndGet() % localAddresses.size(); return localAddresses.get(index); } } diff --git a/core/src/main/java/com/github/games647/fastlogin/core/CompatibleCacheBuilder.java b/core/src/main/java/com/github/games647/fastlogin/core/CompatibleCacheBuilder.java index 0e2c3f5e..20a3d85b 100644 --- a/core/src/main/java/com/github/games647/fastlogin/core/CompatibleCacheBuilder.java +++ b/core/src/main/java/com/github/games647/fastlogin/core/CompatibleCacheBuilder.java @@ -26,10 +26,10 @@ public class CompatibleCacheBuilder { * @return A new cache builder. */ public static CompatibleCacheBuilder newBuilder() { - return new CompatibleCacheBuilder(); + return new CompatibleCacheBuilder<>(); } - private CacheBuilder builder; + private final CacheBuilder builder; @SuppressWarnings("unchecked") private CompatibleCacheBuilder() { diff --git a/core/src/main/java/com/github/games647/fastlogin/core/hooks/DefaultPasswordGenerator.java b/core/src/main/java/com/github/games647/fastlogin/core/hooks/DefaultPasswordGenerator.java index ef393b87..39257333 100644 --- a/core/src/main/java/com/github/games647/fastlogin/core/hooks/DefaultPasswordGenerator.java +++ b/core/src/main/java/com/github/games647/fastlogin/core/hooks/DefaultPasswordGenerator.java @@ -4,9 +4,9 @@ import java.util.Random; public class DefaultPasswordGenerator implements PasswordGenerator { - private final Random random = new Random(); private static final char[] PASSWORD_CHARACTERS = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789" .toCharArray(); + private final Random random = new Random(); @Override public String getRandomPassword(T player) { diff --git a/core/src/main/java/com/github/games647/fastlogin/core/shared/JoinManagement.java b/core/src/main/java/com/github/games647/fastlogin/core/shared/JoinManagement.java index 6122d7b4..abd4380a 100644 --- a/core/src/main/java/com/github/games647/fastlogin/core/shared/JoinManagement.java +++ b/core/src/main/java/com/github/games647/fastlogin/core/shared/JoinManagement.java @@ -8,10 +8,10 @@ import java.util.logging.Level; public abstract class JoinManagement { - protected final FastLoginCore core; + protected final FastLoginCore core; protected final AuthPlugin authHook; - public JoinManagement(FastLoginCore core, AuthPlugin authHook) { + public JoinManagement(FastLoginCore core, AuthPlugin authHook) { this.core = core; this.authHook = authHook; } @@ -62,8 +62,7 @@ public abstract class JoinManagement { } } - private boolean checkPremiumName(String username, S source, PlayerProfile profile) - throws Exception { + private boolean checkPremiumName(String username, S source, PlayerProfile profile) throws Exception { if (core.getSharedConfig().get("autoRegister", false) && (authHook == null || !authHook.isRegistered(username))) { core.getLogger().log(Level.FINER, "Player {0} uses a premium username", username); diff --git a/core/src/main/java/com/github/games647/fastlogin/core/shared/MojangApiConnector.java b/core/src/main/java/com/github/games647/fastlogin/core/shared/MojangApiConnector.java index a6981402..09faf1ab 100644 --- a/core/src/main/java/com/github/games647/fastlogin/core/shared/MojangApiConnector.java +++ b/core/src/main/java/com/github/games647/fastlogin/core/shared/MojangApiConnector.java @@ -1,6 +1,8 @@ package com.github.games647.fastlogin.core.shared; import com.github.games647.fastlogin.core.BalancedSSLFactory; +import com.google.common.collect.Sets; + import java.io.BufferedReader; import java.io.IOException; import java.io.InputStreamReader; @@ -8,7 +10,6 @@ import java.net.HttpURLConnection; import java.net.InetAddress; import java.net.URL; import java.net.UnknownHostException; -import java.util.HashSet; import java.util.List; import java.util.Set; import java.util.UUID; @@ -56,7 +57,7 @@ public abstract class MojangApiConnector { if (localAddresses.isEmpty()) { this.sslFactory = null; } else { - Set addresses = new HashSet<>(); + Set addresses = Sets.newHashSet(); for (String localAddress : localAddresses) { try { InetAddress address = InetAddress.getByName(localAddress); diff --git a/pom.xml b/pom.xml index d4568e9b..e57e2865 100644 --- a/pom.xml +++ b/pom.xml @@ -50,8 +50,8 @@ maven-compiler-plugin 3.5.1 - 1.7 - 1.7 + 1.8 + 1.8 true true