Try to upgrade to Java 8. I hope enough people are using it.

This commit is contained in:
games647
2016-09-16 16:31:47 +02:00
parent 4b423c9ccb
commit 31d6b67381
25 changed files with 148 additions and 193 deletions

View File

@@ -120,9 +120,9 @@ public class FastLoginBukkit extends JavaPlugin {
} }
//remove old blacklists //remove old blacklists
for (Player player : getServer().getOnlinePlayers()) { getServer().getOnlinePlayers().forEach(player -> {
player.removeMetadata(getName(), this); player.removeMetadata(getName(), this);
} });
} }
public BukkitCore getCore() { public BukkitCore getCore() {

View File

@@ -42,11 +42,8 @@ public class CrackedCommand implements CommandExecutor {
sender.sendMessage(plugin.getCore().getMessage("remove-premium")); sender.sendMessage(plugin.getCore().getMessage("remove-premium"));
profile.setPremium(false); profile.setPremium(false);
profile.setUuid(null); profile.setUuid(null);
Bukkit.getScheduler().runTaskAsynchronously(plugin, new Runnable() { Bukkit.getScheduler().runTaskAsynchronously(plugin, () -> {
@Override
public void run() {
plugin.getCore().getStorage().save(profile); plugin.getCore().getStorage().save(profile);
}
}); });
} else { } else {
sender.sendMessage(plugin.getCore().getMessage("not-premium")); sender.sendMessage(plugin.getCore().getMessage("not-premium"));
@@ -87,11 +84,8 @@ public class CrackedCommand implements CommandExecutor {
} else { } else {
sender.sendMessage(plugin.getCore().getMessage("remove-premium")); sender.sendMessage(plugin.getCore().getMessage("remove-premium"));
profile.setPremium(false); profile.setPremium(false);
Bukkit.getScheduler().runTaskAsynchronously(plugin, new Runnable() { Bukkit.getScheduler().runTaskAsynchronously(plugin, () -> {
@Override
public void run() {
plugin.getCore().getStorage().save(profile); plugin.getCore().getStorage().save(profile);
}
}); });
} }
} }

View File

@@ -59,11 +59,8 @@ public class PremiumCommand implements CommandExecutor {
} else { } else {
//todo: resolve uuid //todo: resolve uuid
profile.setPremium(true); profile.setPremium(true);
Bukkit.getScheduler().runTaskAsynchronously(plugin, new Runnable() { Bukkit.getScheduler().runTaskAsynchronously(plugin, () -> {
@Override
public void run() {
plugin.getCore().getStorage().save(profile); plugin.getCore().getStorage().save(profile);
}
}); });
sender.sendMessage(plugin.getCore().getMessage("add-premium")); sender.sendMessage(plugin.getCore().getMessage("add-premium"));
@@ -103,11 +100,8 @@ public class PremiumCommand implements CommandExecutor {
} else { } else {
//todo: resolve uuid //todo: resolve uuid
profile.setPremium(true); profile.setPremium(true);
Bukkit.getScheduler().runTaskAsynchronously(plugin, new Runnable() { Bukkit.getScheduler().runTaskAsynchronously(plugin, () -> {
@Override
public void run() {
plugin.getCore().getStorage().save(profile); plugin.getCore().getStorage().save(profile);
}
}); });
sender.sendMessage(plugin.getCore().getMessage("add-premium-other")); sender.sendMessage(plugin.getCore().getMessage("add-premium-other"));

View File

@@ -8,7 +8,6 @@ import de.st_ddt.crazylogin.databases.CrazyLoginDataDatabase;
import de.st_ddt.crazylogin.listener.PlayerListener; import de.st_ddt.crazylogin.listener.PlayerListener;
import de.st_ddt.crazylogin.metadata.Authenticated; import de.st_ddt.crazylogin.metadata.Authenticated;
import java.util.concurrent.Callable;
import java.util.concurrent.ExecutionException; import java.util.concurrent.ExecutionException;
import java.util.concurrent.Future; import java.util.concurrent.Future;
import java.util.logging.Level; import java.util.logging.Level;
@@ -32,10 +31,7 @@ public class CrazyLoginHook implements AuthPlugin<Player> {
@Override @Override
public boolean forceLogin(final Player player) { public boolean forceLogin(final Player player) {
//not thread-safe operation //not thread-safe operation
Future<LoginPlayerData> future = Bukkit.getScheduler().callSyncMethod(crazyLoginPlugin Future<LoginPlayerData> future = Bukkit.getScheduler().callSyncMethod(crazyLoginPlugin, () -> {
, new Callable<LoginPlayerData>() {
@Override
public LoginPlayerData call() throws Exception {
LoginPlayerData playerData = crazyLoginPlugin.getPlayerData(player.getName()); LoginPlayerData playerData = crazyLoginPlugin.getPlayerData(player.getName());
if (playerData != null) { if (playerData != null) {
//mark the account as logged in //mark the account as logged in
@@ -64,7 +60,6 @@ public class CrazyLoginHook implements AuthPlugin<Player> {
} }
return null; return null;
}
}); });
try { try {
@@ -110,7 +105,7 @@ public class CrazyLoginHook implements AuthPlugin<Player> {
PlayerListener listener; PlayerListener listener;
try { try {
listener = (PlayerListener) FieldUtils.readField(crazyLoginPlugin, "playerListener", true); 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); crazyLoginPlugin.getLogger().log(Level.SEVERE, "Failed to get the listener instance for auto login", ex);
listener = null; listener = null;
} }

View File

@@ -2,7 +2,6 @@ package com.github.games647.fastlogin.bukkit.hooks;
import com.github.games647.fastlogin.core.hooks.AuthPlugin; import com.github.games647.fastlogin.core.hooks.AuthPlugin;
import java.util.concurrent.Callable;
import java.util.concurrent.ExecutionException; import java.util.concurrent.ExecutionException;
import java.util.concurrent.Future; import java.util.concurrent.Future;
import java.util.logging.Level; import java.util.logging.Level;
@@ -27,9 +26,7 @@ public class RoyalAuthHook implements AuthPlugin<Player> {
@Override @Override
public boolean forceLogin(final Player player) { public boolean forceLogin(final Player player) {
//not thread-safe //not thread-safe
Future<Boolean> future = Bukkit.getScheduler().callSyncMethod(royalAuthPlugin, new Callable<Boolean>() { Future<Boolean> future = Bukkit.getScheduler().callSyncMethod(royalAuthPlugin, () -> {
@Override
public Boolean call() throws Exception {
AuthPlayer authPlayer = AuthPlayer.getAuthPlayer(player); AuthPlayer authPlayer = AuthPlayer.getAuthPlayer(player);
//https://github.com/RoyalDev/RoyalAuth/blob/master/src/main/java/org/royaldev/royalauth/commands/CmdLogin.java#L62 //https://github.com/RoyalDev/RoyalAuth/blob/master/src/main/java/org/royaldev/royalauth/commands/CmdLogin.java#L62
@@ -37,7 +34,6 @@ public class RoyalAuthHook implements AuthPlugin<Player> {
authPlayer.login(); authPlayer.login();
return authPlayer.isLoggedIn(); return authPlayer.isLoggedIn();
}
}); });
try { try {

View File

@@ -2,7 +2,6 @@ package com.github.games647.fastlogin.bukkit.hooks;
import com.github.games647.fastlogin.core.hooks.AuthPlugin; import com.github.games647.fastlogin.core.hooks.AuthPlugin;
import java.util.concurrent.Callable;
import java.util.concurrent.ExecutionException; import java.util.concurrent.ExecutionException;
import java.util.concurrent.Future; import java.util.concurrent.Future;
import java.util.logging.Level; import java.util.logging.Level;
@@ -28,12 +27,9 @@ public class UltraAuthHook implements AuthPlugin<Player> {
@Override @Override
public boolean forceLogin(final Player player) { public boolean forceLogin(final Player player) {
//not thread-safe //not thread-safe
Future<Boolean> future = Bukkit.getScheduler().callSyncMethod(ultraAuthPlugin, new Callable<Boolean>() { Future<Boolean> future = Bukkit.getScheduler().callSyncMethod(ultraAuthPlugin, () -> {
@Override
public Boolean call() throws Exception {
UltraAuthAPI.authenticatedPlayer(player); UltraAuthAPI.authenticatedPlayer(player);
return UltraAuthAPI.isAuthenticated(player); return UltraAuthAPI.isAuthenticated(player);
}
}); });
try { try {

View File

@@ -5,7 +5,6 @@ import com.github.games647.fastlogin.core.hooks.AuthPlugin;
import de.luricos.bukkit.xAuth.xAuth; import de.luricos.bukkit.xAuth.xAuth;
import de.luricos.bukkit.xAuth.xAuthPlayer; import de.luricos.bukkit.xAuth.xAuthPlayer;
import java.util.concurrent.Callable;
import java.util.concurrent.ExecutionException; import java.util.concurrent.ExecutionException;
import java.util.concurrent.Future; import java.util.concurrent.Future;
import java.util.logging.Level; import java.util.logging.Level;
@@ -28,9 +27,7 @@ public class xAuthHook implements AuthPlugin<Player> {
@Override @Override
public boolean forceLogin(final Player player) { public boolean forceLogin(final Player player) {
//not thread-safe //not thread-safe
Future<Boolean> future = Bukkit.getScheduler().callSyncMethod(xAuthPlugin, new Callable<Boolean>() { Future<Boolean> future = Bukkit.getScheduler().callSyncMethod(xAuthPlugin, () -> {
@Override
public Boolean call() throws Exception {
xAuthPlayer xAuthPlayer = xAuthPlugin.getPlayerManager().getPlayer(player); xAuthPlayer xAuthPlayer = xAuthPlugin.getPlayerManager().getPlayer(player);
if (xAuthPlayer != null) { if (xAuthPlayer != null) {
//we checked that the player is premium (paid account) //we checked that the player is premium (paid account)
@@ -41,7 +38,6 @@ public class xAuthHook implements AuthPlugin<Player> {
} }
return false; return false;
}
}); });
try { try {
@@ -62,9 +58,7 @@ public class xAuthHook implements AuthPlugin<Player> {
@Override @Override
public boolean forceRegister(final Player player, final String password) { public boolean forceRegister(final Player player, final String password) {
//not thread-safe //not thread-safe
Future<Boolean> future = Bukkit.getScheduler().callSyncMethod(xAuthPlugin, new Callable<Boolean>() { Future<Boolean> future = Bukkit.getScheduler().callSyncMethod(xAuthPlugin, () -> {
@Override
public Boolean call() throws Exception {
xAuthPlayer xAuthPlayer = xAuthPlugin.getPlayerManager().getPlayer(player); xAuthPlayer xAuthPlayer = xAuthPlugin.getPlayerManager().getPlayer(player);
if (xAuthPlayer != null) { if (xAuthPlayer != null) {
//this should run async because the plugin executes a sql query, but the method //this should run async because the plugin executes a sql query, but the method
@@ -76,7 +70,6 @@ public class xAuthHook implements AuthPlugin<Player> {
} }
return false; return false;
}
}); });
try { try {

View File

@@ -21,7 +21,7 @@ public class BukkitJoinListener implements Listener {
private static final long DELAY_LOGIN = 20L / 2; private static final long DELAY_LOGIN = 20L / 2;
protected final FastLoginBukkit plugin; private final FastLoginBukkit plugin;
public BukkitJoinListener(FastLoginBukkit plugin) { public BukkitJoinListener(FastLoginBukkit plugin) {
this.plugin = plugin; this.plugin = plugin;

View File

@@ -52,10 +52,10 @@ public class BungeeCordListener implements PluginMessageListener {
plugin.getLogger().log(Level.FINEST, "Received plugin message for subchannel {0} from {1}" plugin.getLogger().log(Level.FINEST, "Received plugin message for subchannel {0} from {1}"
, new Object[]{subchannel, player}); , new Object[]{subchannel, player});
final String playerName = dataInput.readUTF(); String playerName = dataInput.readUTF();
//check if the player is still online or disconnected //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 //fail if target player is blacklisted because already authed or wrong bungeecord id
if (checkedPlayer != null && !checkedPlayer.hasMetadata(plugin.getName())) { if (checkedPlayer != null && !checkedPlayer.hasMetadata(plugin.getName())) {
//blacklist this target player for BungeeCord Id brute force attacks //blacklist this target player for BungeeCord Id brute force attacks
@@ -77,9 +77,7 @@ public class BungeeCordListener implements PluginMessageListener {
plugin.getSessions().put(id, playerSession); plugin.getSessions().put(id, playerSession);
Bukkit.getScheduler().runTaskAsynchronously(plugin, new ForceLoginTask(plugin, player)); Bukkit.getScheduler().runTaskAsynchronously(plugin, new ForceLoginTask(plugin, player));
} else if ("AUTO_REGISTER".equalsIgnoreCase(subchannel)) { } else if ("AUTO_REGISTER".equalsIgnoreCase(subchannel)) {
Bukkit.getScheduler().runTaskAsynchronously(plugin, new Runnable() { Bukkit.getScheduler().runTaskAsynchronously(plugin, () -> {
@Override
public void run() {
AuthPlugin<Player> authPlugin = plugin.getCore().getAuthPluginHook(); AuthPlugin<Player> authPlugin = plugin.getCore().getAuthPluginHook();
try { try {
//we need to check if the player is registered on Bukkit too //we need to check if the player is registered on Bukkit too
@@ -92,7 +90,6 @@ public class BungeeCordListener implements PluginMessageListener {
} catch (Exception ex) { } catch (Exception ex) {
plugin.getLogger().log(Level.SEVERE, "Failed to query isRegistered", ex); plugin.getLogger().log(Level.SEVERE, "Failed to query isRegistered", ex);
} }
}
}); });
} }
} }

View File

@@ -28,7 +28,7 @@ public class ProtocolLibLoginSource implements LoginSource {
private final Random random; private final Random random;
private String serverId; 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) { public ProtocolLibLoginSource(FastLoginBukkit plugin, PacketEvent packetEvent, Player player, Random random) {
this.plugin = plugin; this.plugin = plugin;

View File

@@ -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.bukkit.hooks.xAuthHook;
import com.github.games647.fastlogin.core.hooks.AuthPlugin; import com.github.games647.fastlogin.core.hooks.AuthPlugin;
import com.google.common.collect.Lists; import com.google.common.collect.Lists;
import java.util.List;
import java.util.ArrayList;
import java.util.logging.Level; import java.util.logging.Level;
import org.bukkit.Bukkit; import org.bukkit.Bukkit;
@@ -40,7 +40,7 @@ public class DelayedAuthHook implements Runnable {
private boolean registerHooks() { private boolean registerHooks() {
AuthPlugin<Player> authPluginHook = null; AuthPlugin<Player> authPluginHook = null;
try { try {
ArrayList<Class<? extends AuthPlugin<Player>>> supportedHooks = Lists.newArrayList(AuthMeHook.class List<Class<? extends AuthPlugin<Player>>> supportedHooks = Lists.newArrayList(AuthMeHook.class
, CrazyLoginHook.class, LogItHook.class, LoginSecurityHook.class, UltraAuthHook.class , CrazyLoginHook.class, LogItHook.class, LoginSecurityHook.class, UltraAuthHook.class
, xAuthHook.class); , xAuthHook.class);
for (Class<? extends AuthPlugin<Player>> clazz : supportedHooks) { for (Class<? extends AuthPlugin<Player>> clazz : supportedHooks) {

View File

@@ -122,12 +122,7 @@ public class ForceLoginTask implements Runnable {
private boolean isOnlineThreadSafe() { private boolean isOnlineThreadSafe() {
//the playerlist isn't thread-safe //the playerlist isn't thread-safe
Future<Boolean> onlineFuture = Bukkit.getScheduler().callSyncMethod(plugin, new Callable<Boolean>() { Future<Boolean> onlineFuture = Bukkit.getScheduler().callSyncMethod(plugin, player::isOnline);
@Override
public Boolean call() throws Exception {
return player.isOnline();
}
});
try { try {
return onlineFuture.get(); return onlineFuture.get();

View File

@@ -26,9 +26,9 @@ public class BungeeCore extends FastLoginCore<ProxiedPlayer> {
private static Map<String, Object> generateConfigMap(Configuration config) { private static Map<String, Object> generateConfigMap(Configuration config) {
Map<String, Object> configMap = Maps.newHashMap(); Map<String, Object> configMap = Maps.newHashMap();
Collection<String> keys = config.getKeys(); Collection<String> keys = config.getKeys();
for (String key : keys) { keys.forEach(key -> {
configMap.put(key, config.get(key)); configMap.put(key, config.get(key));
} });
return configMap; return configMap;
} }
@@ -72,12 +72,12 @@ public class BungeeCore extends FastLoginCore<ProxiedPlayer> {
File messageFile = new File(getDataFolder(), "messages.yml"); File messageFile = new File(getDataFolder(), "messages.yml");
Configuration messageConfig = ConfigurationProvider.getProvider(YamlConfiguration.class) Configuration messageConfig = ConfigurationProvider.getProvider(YamlConfiguration.class)
.load(messageFile, defaults); .load(messageFile, defaults);
for (String key : messageConfig.getKeys()) { messageConfig.getKeys().forEach((key) -> {
String message = ChatColor.translateAlternateColorCodes('&', messageConfig.getString(key)); String message = ChatColor.translateAlternateColorCodes('&', messageConfig.getString(key));
if (!message.isEmpty()) { if (!message.isEmpty()) {
localeMessages.put(key, message); localeMessages.put(key, message);
} }
} });
} catch (IOException ex) { } catch (IOException ex) {
getLogger().log(Level.SEVERE, "Failed to load messages", ex); getLogger().log(Level.SEVERE, "Failed to load messages", ex);
} }

View File

@@ -9,9 +9,12 @@ import net.md_5.bungee.api.connection.ProxiedPlayer;
@Deprecated @Deprecated
public interface BungeeAuthPlugin extends AuthPlugin<ProxiedPlayer> { public interface BungeeAuthPlugin extends AuthPlugin<ProxiedPlayer> {
@Override
boolean forceLogin(ProxiedPlayer player); boolean forceLogin(ProxiedPlayer player);
@Override
boolean isRegistered(String playerName) throws Exception; boolean isRegistered(String playerName) throws Exception;
@Override
boolean forceRegister(ProxiedPlayer player, String password); boolean forceRegister(ProxiedPlayer player, String password);
} }

View File

@@ -45,7 +45,10 @@ public class PlayerConnectionListener implements Listener {
} }
preLoginEvent.registerIntent(plugin); 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) @EventHandler(priority = EventPriority.LOW)

View File

@@ -44,12 +44,10 @@ public class PluginMessageListener implements Listener {
private void readMessage(PluginMessageEvent pluginMessageEvent) { private void readMessage(PluginMessageEvent pluginMessageEvent) {
//so that we can safely process this in the background //so that we can safely process this in the background
final byte[] data = Arrays.copyOf(pluginMessageEvent.getData(), pluginMessageEvent.getData().length); byte[] data = Arrays.copyOf(pluginMessageEvent.getData(), pluginMessageEvent.getData().length);
final ProxiedPlayer forPlayer = (ProxiedPlayer) pluginMessageEvent.getReceiver(); ProxiedPlayer forPlayer = (ProxiedPlayer) pluginMessageEvent.getReceiver();
ProxyServer.getInstance().getScheduler().runAsync(plugin, new Runnable() { ProxyServer.getInstance().getScheduler().runAsync(plugin, () -> {
@Override
public void run() {
ByteArrayDataInput dataInput = ByteStreams.newDataInput(data); ByteArrayDataInput dataInput = ByteStreams.newDataInput(data);
String subchannel = dataInput.readUTF(); String subchannel = dataInput.readUTF();
if ("ON".equals(subchannel)) { if ("ON".equals(subchannel)) {
@@ -86,7 +84,6 @@ public class PluginMessageListener implements Listener {
} }
} }
} }
}
}); });
} }
} }

View File

@@ -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.PendingConnection;
import net.md_5.bungee.api.connection.ProxiedPlayer; 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<ProxiedPlayer, BungeeLoginSource> implements Runnable { public class AsyncPremiumCheck extends JoinManagement<ProxiedPlayer, BungeeLoginSource> implements Runnable {
private final FastLoginBungee plugin; 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()); super(plugin.getCore(), plugin.getCore().getAuthPluginHook());
this.plugin = plugin; this.plugin = plugin;
this.preLoginEvent = preLoginEvent; this.preLoginEvent = preLoginEvent;
this.connection = connection;
} }
@Override @Override
public void run() { public void run() {
PendingConnection connection = preLoginEvent.getConnection();
plugin.getSession().remove(connection); plugin.getSession().remove(connection);
String username = connection.getName(); String username = connection.getName();

View File

@@ -9,8 +9,8 @@ import com.google.common.io.ByteStreams;
import java.util.UUID; import java.util.UUID;
import java.util.logging.Level; 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.PendingConnection;
import net.md_5.bungee.api.connection.ProxiedPlayer; import net.md_5.bungee.api.connection.ProxiedPlayer;
import net.md_5.bungee.api.connection.Server; import net.md_5.bungee.api.connection.Server;

View File

@@ -18,13 +18,13 @@ public class AuthStorage {
private static final String PREMIUM_TABLE = "premium"; private static final String PREMIUM_TABLE = "premium";
private final FastLoginCore core; private final FastLoginCore<?> core;
private final HikariDataSource dataSource; private final HikariDataSource dataSource;
//a try to fix https://www.spigotmc.org/threads/fastlogin.101192/page-26#post-1874647 //a try to fix https://www.spigotmc.org/threads/fastlogin.101192/page-26#post-1874647
private final Calendar calendar = Calendar.getInstance(Locale.US); 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) { , String user, String pass) {
this.core = core; this.core = core;

View File

@@ -7,6 +7,7 @@ import java.net.UnknownHostException;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.List; import java.util.List;
import java.util.Set; import java.util.Set;
import java.util.concurrent.atomic.AtomicInteger;
import javax.net.ssl.SSLSocketFactory; import javax.net.ssl.SSLSocketFactory;
@@ -17,9 +18,7 @@ public class BalancedSSLFactory extends SSLSocketFactory {
//in order to be thread-safe //in order to be thread-safe
private final List<InetAddress> localAddresses; private final List<InetAddress> localAddresses;
private final Object lock = new Object(); private AtomicInteger id;
private int id;
public BalancedSSLFactory(SSLSocketFactory oldFactory, Set<InetAddress> localAddresses) { public BalancedSSLFactory(SSLSocketFactory oldFactory, Set<InetAddress> localAddresses) {
this.oldFactory = oldFactory; this.oldFactory = oldFactory;
@@ -65,16 +64,7 @@ public class BalancedSSLFactory extends SSLSocketFactory {
} }
private InetAddress getNextLocalAddress() { private InetAddress getNextLocalAddress() {
int next; int index = id.incrementAndGet() % localAddresses.size();
synchronized (lock) {
next = id;
id++;
if (next == Integer.MAX_VALUE) {
id = 0;
}
}
int index = next % localAddresses.size();
return localAddresses.get(index); return localAddresses.get(index);
} }
} }

View File

@@ -26,10 +26,10 @@ public class CompatibleCacheBuilder<K, V> {
* @return A new cache builder. * @return A new cache builder.
*/ */
public static <K, V> CompatibleCacheBuilder<K, V> newBuilder() { public static <K, V> CompatibleCacheBuilder<K, V> newBuilder() {
return new CompatibleCacheBuilder<K, V>(); return new CompatibleCacheBuilder<>();
} }
private CacheBuilder<K, V> builder; private final CacheBuilder<K, V> builder;
@SuppressWarnings("unchecked") @SuppressWarnings("unchecked")
private CompatibleCacheBuilder() { private CompatibleCacheBuilder() {

View File

@@ -4,9 +4,9 @@ import java.util.Random;
public class DefaultPasswordGenerator<T> implements PasswordGenerator<T> { public class DefaultPasswordGenerator<T> implements PasswordGenerator<T> {
private final Random random = new Random();
private static final char[] PASSWORD_CHARACTERS = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789" private static final char[] PASSWORD_CHARACTERS = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789"
.toCharArray(); .toCharArray();
private final Random random = new Random();
@Override @Override
public String getRandomPassword(T player) { public String getRandomPassword(T player) {

View File

@@ -8,10 +8,10 @@ import java.util.logging.Level;
public abstract class JoinManagement<T, S extends LoginSource> { public abstract class JoinManagement<T, S extends LoginSource> {
protected final FastLoginCore core; protected final FastLoginCore<T> core;
protected final AuthPlugin<T> authHook; protected final AuthPlugin<T> authHook;
public JoinManagement(FastLoginCore core, AuthPlugin<T> authHook) { public JoinManagement(FastLoginCore<T> core, AuthPlugin<T> authHook) {
this.core = core; this.core = core;
this.authHook = authHook; this.authHook = authHook;
} }
@@ -62,8 +62,7 @@ public abstract class JoinManagement<T, S extends LoginSource> {
} }
} }
private boolean checkPremiumName(String username, S source, PlayerProfile profile) private boolean checkPremiumName(String username, S source, PlayerProfile profile) throws Exception {
throws Exception {
if (core.getSharedConfig().get("autoRegister", false) if (core.getSharedConfig().get("autoRegister", false)
&& (authHook == null || !authHook.isRegistered(username))) { && (authHook == null || !authHook.isRegistered(username))) {
core.getLogger().log(Level.FINER, "Player {0} uses a premium username", username); core.getLogger().log(Level.FINER, "Player {0} uses a premium username", username);

View File

@@ -1,6 +1,8 @@
package com.github.games647.fastlogin.core.shared; package com.github.games647.fastlogin.core.shared;
import com.github.games647.fastlogin.core.BalancedSSLFactory; import com.github.games647.fastlogin.core.BalancedSSLFactory;
import com.google.common.collect.Sets;
import java.io.BufferedReader; import java.io.BufferedReader;
import java.io.IOException; import java.io.IOException;
import java.io.InputStreamReader; import java.io.InputStreamReader;
@@ -8,7 +10,6 @@ import java.net.HttpURLConnection;
import java.net.InetAddress; import java.net.InetAddress;
import java.net.URL; import java.net.URL;
import java.net.UnknownHostException; import java.net.UnknownHostException;
import java.util.HashSet;
import java.util.List; import java.util.List;
import java.util.Set; import java.util.Set;
import java.util.UUID; import java.util.UUID;
@@ -56,7 +57,7 @@ public abstract class MojangApiConnector {
if (localAddresses.isEmpty()) { if (localAddresses.isEmpty()) {
this.sslFactory = null; this.sslFactory = null;
} else { } else {
Set<InetAddress> addresses = new HashSet<>(); Set<InetAddress> addresses = Sets.newHashSet();
for (String localAddress : localAddresses) { for (String localAddress : localAddresses) {
try { try {
InetAddress address = InetAddress.getByName(localAddress); InetAddress address = InetAddress.getByName(localAddress);

View File

@@ -50,8 +50,8 @@
<artifactId>maven-compiler-plugin</artifactId> <artifactId>maven-compiler-plugin</artifactId>
<version>3.5.1</version> <version>3.5.1</version>
<configuration> <configuration>
<source>1.7</source> <source>1.8</source>
<target>1.7</target> <target>1.8</target>
<showWarnings>true</showWarnings> <showWarnings>true</showWarnings>
<showDeprecation>true</showDeprecation> <showDeprecation>true</showDeprecation>
</configuration> </configuration>