Refactor a lot of code + Add Guava v10 as shared library
This commit is contained in:
1 parent
2cd50d23ad
commit
76f5ba7ed1
29 files changed
+128
-150
No files matched your search
@@ -1,7 +1,6 @@
|
||||
package com.github.games647.fastlogin.bungee;
|
||||
|
||||
import com.github.games647.fastlogin.core.FastLoginCore;
|
||||
import com.google.common.cache.CacheBuilder;
|
||||
import com.github.games647.fastlogin.core.shared.FastLoginCore;
|
||||
import com.google.common.collect.Maps;
|
||||
import com.google.common.util.concurrent.ThreadFactoryBuilder;
|
||||
|
||||
@@ -12,23 +11,22 @@ import java.nio.file.Files;
|
||||
import java.util.Collection;
|
||||
import java.util.Map;
|
||||
import java.util.concurrent.ThreadFactory;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
import java.util.logging.Level;
|
||||
import java.util.logging.Logger;
|
||||
|
||||
import net.md_5.bungee.api.ChatColor;
|
||||
import net.md_5.bungee.api.connection.ProxiedPlayer;
|
||||
import net.md_5.bungee.api.scheduler.GroupedThreadFactory;
|
||||
import net.md_5.bungee.config.Configuration;
|
||||
import net.md_5.bungee.config.ConfigurationProvider;
|
||||
import net.md_5.bungee.config.YamlConfiguration;
|
||||
|
||||
public class BungeeCore extends FastLoginCore {
|
||||
public class BungeeCore extends FastLoginCore<ProxiedPlayer> {
|
||||
|
||||
private final FastLoginBungee plugin;
|
||||
|
||||
public BungeeCore(FastLoginBungee plugin) {
|
||||
super(CacheBuilder.newBuilder().expireAfterWrite(5, TimeUnit.MINUTES).<String, Object>build().asMap()
|
||||
, generateConfigMap(plugin.getConfig()));
|
||||
super(generateConfigMap(plugin.getConfig()));
|
||||
|
||||
this.plugin = plugin;
|
||||
}
|
||||
|
||||
@@ -4,10 +4,6 @@ import com.github.games647.fastlogin.bungee.hooks.BungeeAuthHook;
|
||||
import com.github.games647.fastlogin.bungee.hooks.BungeeAuthPlugin;
|
||||
import com.github.games647.fastlogin.bungee.listener.PlayerConnectionListener;
|
||||
import com.github.games647.fastlogin.bungee.listener.PluginMessageListener;
|
||||
import com.github.games647.fastlogin.core.FastLoginCore;
|
||||
import com.github.games647.fastlogin.core.shared.DefaultPasswordGenerator;
|
||||
import com.github.games647.fastlogin.core.shared.PasswordGenerator;
|
||||
import com.google.common.cache.CacheBuilder;
|
||||
import com.google.common.collect.Maps;
|
||||
import com.google.common.collect.Sets;
|
||||
|
||||
@@ -17,11 +13,9 @@ import java.util.List;
|
||||
import java.util.Set;
|
||||
import java.util.UUID;
|
||||
import java.util.concurrent.ConcurrentMap;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
import java.util.logging.Level;
|
||||
|
||||
import net.md_5.bungee.api.connection.PendingConnection;
|
||||
import net.md_5.bungee.api.connection.ProxiedPlayer;
|
||||
import net.md_5.bungee.api.plugin.Plugin;
|
||||
import net.md_5.bungee.config.Configuration;
|
||||
import net.md_5.bungee.config.ConfigurationProvider;
|
||||
@@ -32,11 +26,10 @@ import net.md_5.bungee.config.YamlConfiguration;
|
||||
*/
|
||||
public class FastLoginBungee extends Plugin {
|
||||
|
||||
private final FastLoginCore loginCore = new BungeeCore(this);
|
||||
private final BungeeCore loginCore = new BungeeCore(this);
|
||||
private BungeeAuthPlugin bungeeAuthPlugin;
|
||||
private Configuration config;
|
||||
|
||||
private final PasswordGenerator<ProxiedPlayer> passwordGenerator = new DefaultPasswordGenerator<>();
|
||||
private final Set<UUID> pendingConfirms = Sets.newHashSet();
|
||||
|
||||
private final ConcurrentMap<PendingConnection, BungeeLoginSession> session = Maps.newConcurrentMap();
|
||||
@@ -52,19 +45,10 @@ public class FastLoginBungee extends Plugin {
|
||||
|
||||
List<String> ipAddresses = getConfig().getStringList("ip-addresses");
|
||||
int requestLimit = getConfig().getInt("mojang-request-limit");
|
||||
ConcurrentMap<Object, Object> requestCache = CacheBuilder.newBuilder()
|
||||
.expireAfterWrite(10, TimeUnit.MINUTES).build().asMap();
|
||||
MojangApiBungee mojangApi = new MojangApiBungee(requestCache, getLogger(), ipAddresses, requestLimit);
|
||||
MojangApiBungee mojangApi = new MojangApiBungee(getLogger(), ipAddresses, requestLimit);
|
||||
loginCore.setMojangApiConnector(mojangApi);
|
||||
|
||||
String driver = config.getString("driver");
|
||||
String host = config.getString("host", "");
|
||||
int port = config.getInt("port", 3306);
|
||||
String database = config.getString("database");
|
||||
|
||||
String username = config.getString("username", "");
|
||||
String password = config.getString("password", "");
|
||||
if (!loginCore.setupDatabase(driver, host, port, database, username, password)) {
|
||||
if (!loginCore.setupDatabase()) {
|
||||
return;
|
||||
}
|
||||
} catch (IOException ioExc) {
|
||||
@@ -85,16 +69,12 @@ public class FastLoginBungee extends Plugin {
|
||||
registerHook();
|
||||
}
|
||||
|
||||
public String generatePassword(ProxiedPlayer player) {
|
||||
return passwordGenerator.getRandomPassword(player);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onDisable() {
|
||||
loginCore.close();
|
||||
}
|
||||
|
||||
public FastLoginCore getCore() {
|
||||
public BungeeCore getCore() {
|
||||
return loginCore;
|
||||
}
|
||||
|
||||
@@ -110,10 +90,6 @@ public class FastLoginBungee extends Plugin {
|
||||
return session;
|
||||
}
|
||||
|
||||
public Set<UUID> getPendingConfirms() {
|
||||
return pendingConfirms;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the auth plugin hook for BungeeCord
|
||||
*
|
||||
|
||||
@@ -2,7 +2,7 @@ package com.github.games647.fastlogin.bungee;
|
||||
|
||||
import com.github.games647.fastlogin.bungee.FastLoginBungee;
|
||||
import com.github.games647.fastlogin.core.AuthStorage;
|
||||
import com.github.games647.fastlogin.core.FastLoginCore;
|
||||
import com.github.games647.fastlogin.core.shared.FastLoginCore;
|
||||
import com.github.games647.fastlogin.core.importer.ImportPlugin;
|
||||
|
||||
import net.md_5.bungee.api.ChatColor;
|
||||
|
||||
@@ -1,20 +1,18 @@
|
||||
package com.github.games647.fastlogin.bungee;
|
||||
|
||||
import com.github.games647.fastlogin.core.FastLoginCore;
|
||||
import com.github.games647.fastlogin.core.MojangApiConnector;
|
||||
import com.github.games647.fastlogin.core.shared.FastLoginCore;
|
||||
import com.github.games647.fastlogin.core.shared.MojangApiConnector;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.UUID;
|
||||
import java.util.concurrent.ConcurrentMap;
|
||||
import java.util.logging.Logger;
|
||||
|
||||
import net.md_5.bungee.BungeeCord;
|
||||
|
||||
public class MojangApiBungee extends MojangApiConnector {
|
||||
|
||||
public MojangApiBungee(ConcurrentMap<Object, Object> requests, Logger logger, List<String> localAddresses
|
||||
, int rateLimit) {
|
||||
super(requests, logger, localAddresses, rateLimit);
|
||||
public MojangApiBungee(Logger logger, List<String> localAddresses, int rateLimit) {
|
||||
super(logger, localAddresses, rateLimit);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
+2
-2
@@ -1,10 +1,10 @@
|
||||
package com.github.games647.fastlogin.bungee.hooks;
|
||||
|
||||
import com.github.games647.fastlogin.core.AuthPlugin;
|
||||
import com.github.games647.fastlogin.core.hooks.AuthPlugin;
|
||||
import net.md_5.bungee.api.connection.ProxiedPlayer;
|
||||
|
||||
/**
|
||||
* @deprecated please use com.github.games647.fastlogin.core.AuthPlugin<net.md_5.bungee.api.connection.ProxiedPlayer>
|
||||
* @deprecated please use com.github.games647.fastlogin.core.hooks.AuthPlugin<net.md_5.bungee.api.connection.ProxiedPlayer>
|
||||
*/
|
||||
@Deprecated
|
||||
public interface BungeeAuthPlugin extends AuthPlugin<ProxiedPlayer> {
|
||||
|
||||
+1
-1
@@ -103,6 +103,6 @@ public class PlayerConnectionListener implements Listener {
|
||||
public void onDisconnect(PlayerDisconnectEvent disconnectEvent) {
|
||||
ProxiedPlayer player = disconnectEvent.getPlayer();
|
||||
plugin.getSession().remove(player.getPendingConnection());
|
||||
plugin.getPendingConfirms().remove(player.getUniqueId());
|
||||
plugin.getCore().getPendingConfirms().remove(player.getUniqueId());
|
||||
}
|
||||
}
|
||||
+3
-3
@@ -55,14 +55,14 @@ public class PluginMessageListener implements Listener {
|
||||
String playerName = dataInput.readUTF();
|
||||
|
||||
if (playerName.equals(forPlayer.getName()) && plugin.getConfig().getBoolean("premium-warning")
|
||||
&& !plugin.getPendingConfirms().contains(forPlayer.getUniqueId())) {
|
||||
&& !plugin.getCore().getPendingConfirms().contains(forPlayer.getUniqueId())) {
|
||||
String message = plugin.getCore().getMessage("premium-warning");
|
||||
forPlayer.sendMessage(TextComponent.fromLegacyText(message));
|
||||
plugin.getPendingConfirms().add(forPlayer.getUniqueId());
|
||||
plugin.getCore().getPendingConfirms().add(forPlayer.getUniqueId());
|
||||
return;
|
||||
}
|
||||
|
||||
plugin.getPendingConfirms().remove(forPlayer.getUniqueId());
|
||||
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)) {
|
||||
|
||||
@@ -81,7 +81,7 @@ public class ForceLoginTask implements Runnable {
|
||||
|
||||
session.setAlreadyLogged(true);
|
||||
|
||||
String password = plugin.generatePassword(player);
|
||||
String password = plugin.getCore().getPasswordGenerator().getRandomPassword(player);
|
||||
if (authPlugin.forceRegister(player, password)) {
|
||||
//save will happen on success message from bukkit
|
||||
sendBukkitLoginNotification(true);
|
||||
|
||||
Reference in new issue
Block a user