mirror of
https://github.com/TuxCoding/FastLogin.git
synced 2025-07-29 18:27:36 +02:00
Fix config loading in BungeeCord
This commit is contained in:
@ -1,5 +1,6 @@
|
||||
######1.9
|
||||
|
||||
* Upgrade to Java 8
|
||||
* Drop support for LoginSecurity 1.X since 2.X seems to be stable
|
||||
* Refactored/Cleaned up a lot of code
|
||||
* [API] Deprecated platform specific authplugin. Please use AuthPlugin< platform specific player type >
|
||||
|
@ -1,11 +1,13 @@
|
||||
package com.github.games647.fastlogin.bukkit;
|
||||
|
||||
import com.github.games647.fastlogin.core.shared.FastLoginCore;
|
||||
import com.github.games647.fastlogin.core.shared.MojangApiConnector;
|
||||
import com.google.common.base.Charsets;
|
||||
import com.google.common.util.concurrent.ThreadFactoryBuilder;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.InputStreamReader;
|
||||
import java.util.List;
|
||||
import java.util.concurrent.ThreadFactory;
|
||||
import java.util.logging.Logger;
|
||||
|
||||
@ -73,4 +75,9 @@ public class BukkitCore extends FastLoginCore<Player> {
|
||||
public void loadConfig() {
|
||||
plugin.saveDefaultConfig();
|
||||
}
|
||||
|
||||
@Override
|
||||
public MojangApiConnector makeApiConnector(Logger logger, List<String> addresses, int requests) {
|
||||
return new MojangApiBukkit(logger, addresses, requests);
|
||||
}
|
||||
}
|
||||
|
@ -18,7 +18,6 @@ import com.github.games647.fastlogin.core.hooks.AuthPlugin;
|
||||
import com.github.games647.fastlogin.core.shared.FastLoginCore;
|
||||
|
||||
import java.security.KeyPair;
|
||||
import java.util.List;
|
||||
import java.util.concurrent.ConcurrentMap;
|
||||
import java.util.logging.Level;
|
||||
|
||||
@ -48,12 +47,6 @@ public class FastLoginBukkit extends JavaPlugin {
|
||||
|
||||
core.loadConfig();
|
||||
core.loadMessages();
|
||||
|
||||
List<String> ipAddresses = getConfig().getStringList("ip-addresses");
|
||||
int requestLimit = getConfig().getInt("mojang-request-limit");
|
||||
MojangApiBukkit mojangApi = new MojangApiBukkit(getLogger(), ipAddresses, requestLimit);
|
||||
core.setMojangApiConnector(mojangApi);
|
||||
|
||||
try {
|
||||
if (ClassUtil.isPresent("org.spigotmc.SpigotConfig")) {
|
||||
bungeeCord = Class.forName("org.spigotmc.SpigotConfig").getDeclaredField("bungee").getBoolean(null);
|
||||
|
@ -83,7 +83,7 @@ public class VerifyResponseTask implements Runnable {
|
||||
String serverId = (new BigInteger(serverIdHash)).toString(16);
|
||||
|
||||
String username = session.getUsername();
|
||||
if (plugin.getCore().getMojangApiConnector().hasJoinedServer(session, serverId)) {
|
||||
if (plugin.getCore().getApiConnector().hasJoinedServer(session, serverId)) {
|
||||
plugin.getLogger().log(Level.FINE, "Player {0} has a verified premium account", username);
|
||||
|
||||
session.setVerified(true);
|
||||
|
@ -1,12 +1,12 @@
|
||||
package com.github.games647.fastlogin.bungee;
|
||||
|
||||
import com.github.games647.fastlogin.core.shared.FastLoginCore;
|
||||
import com.github.games647.fastlogin.core.shared.MojangApiConnector;
|
||||
import com.google.common.util.concurrent.ThreadFactoryBuilder;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.nio.file.Files;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.concurrent.ThreadFactory;
|
||||
import java.util.logging.Level;
|
||||
@ -28,8 +28,8 @@ public class BungeeCore extends FastLoginCore<ProxiedPlayer> {
|
||||
|
||||
private final FastLoginBungee plugin;
|
||||
|
||||
public BungeeCore(FastLoginBungee plugin) {
|
||||
super(generateConfigMap(plugin.getConfig()));
|
||||
public BungeeCore(FastLoginBungee plugin, Configuration config) {
|
||||
super(generateConfigMap(config));
|
||||
|
||||
this.plugin = plugin;
|
||||
}
|
||||
@ -57,7 +57,7 @@ public class BungeeCore extends FastLoginCore<ProxiedPlayer> {
|
||||
@Override
|
||||
public void loadMessages() {
|
||||
try {
|
||||
saveDefaultFile("messages.yml");
|
||||
plugin.saveDefaultFile("messages.yml");
|
||||
|
||||
Configuration defaults = ConfigurationProvider.getProvider(YamlConfiguration.class)
|
||||
.load(getClass().getResourceAsStream("/messages.yml"));
|
||||
@ -82,18 +82,11 @@ public class BungeeCore extends FastLoginCore<ProxiedPlayer> {
|
||||
getDataFolder().mkdir();
|
||||
}
|
||||
|
||||
saveDefaultFile("config.yml");
|
||||
plugin.saveDefaultFile("config.yml");
|
||||
}
|
||||
|
||||
private void saveDefaultFile(String fileName) {
|
||||
File configFile = new File(getDataFolder(), fileName);
|
||||
if (!configFile.exists()) {
|
||||
try (InputStream in = plugin.getResourceAsStream(fileName)) {
|
||||
Files.copy(in, configFile.toPath());
|
||||
} catch (IOException ioExc) {
|
||||
getLogger().log(Level.SEVERE, "Error saving default " + fileName, ioExc);
|
||||
}
|
||||
}
|
||||
@Override
|
||||
public MojangApiConnector makeApiConnector(Logger logger, List<String> addresses, int requests) {
|
||||
return new MojangApiBungee(logger, addresses, requests);
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -8,7 +8,8 @@ import com.google.common.collect.Maps;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.util.List;
|
||||
import java.io.InputStream;
|
||||
import java.nio.file.Files;
|
||||
import java.util.concurrent.ConcurrentMap;
|
||||
import java.util.logging.Level;
|
||||
|
||||
@ -30,17 +31,13 @@ public class FastLoginBungee extends Plugin {
|
||||
|
||||
@Override
|
||||
public void onEnable() {
|
||||
saveDefaultFile("config.yml");
|
||||
|
||||
try {
|
||||
File configFile = new File(getDataFolder(), "config.yml");
|
||||
config = ConfigurationProvider.getProvider(YamlConfiguration.class).load(configFile);
|
||||
|
||||
core = new BungeeCore(this);
|
||||
|
||||
List<String> ipAddresses = getConfig().getStringList("ip-addresses");
|
||||
int requestLimit = getConfig().getInt("mojang-request-limit");
|
||||
MojangApiBungee mojangApi = new MojangApiBungee(getLogger(), ipAddresses, requestLimit);
|
||||
core.setMojangApiConnector(mojangApi);
|
||||
|
||||
core = new BungeeCore(this, config);
|
||||
if (!core.setupDatabase()) {
|
||||
return;
|
||||
}
|
||||
@ -70,6 +67,17 @@ public class FastLoginBungee extends Plugin {
|
||||
core.close();
|
||||
}
|
||||
|
||||
public void saveDefaultFile(String fileName) {
|
||||
File configFile = new File(getDataFolder(), fileName);
|
||||
if (!configFile.exists()) {
|
||||
try (InputStream in = getResourceAsStream(fileName)) {
|
||||
Files.copy(in, configFile.toPath());
|
||||
} catch (IOException ioExc) {
|
||||
getLogger().log(Level.SEVERE, "Error saving default " + fileName, ioExc);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public BungeeCore getCore() {
|
||||
return core;
|
||||
}
|
||||
|
@ -16,6 +16,7 @@ import java.io.File;
|
||||
import java.sql.Connection;
|
||||
import java.sql.DriverManager;
|
||||
import java.sql.SQLException;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
import java.util.UUID;
|
||||
@ -65,7 +66,8 @@ public abstract class FastLoginCore<P> {
|
||||
private final Set<UUID> pendingConfirms = Sets.newHashSet();
|
||||
private final SharedConfig sharedConfig;
|
||||
|
||||
private MojangApiConnector mojangApiConnector;
|
||||
private final MojangApiConnector apiConnector;
|
||||
|
||||
private AuthStorage storage;
|
||||
private PasswordGenerator<P> passwordGenerator = new DefaultPasswordGenerator<>();
|
||||
private AuthPlugin<P> authPlugin;
|
||||
@ -73,14 +75,14 @@ public abstract class FastLoginCore<P> {
|
||||
public FastLoginCore(Map<String, Object> config) {
|
||||
this.pendingLogins = FastLoginCore.buildCache(5, 0);
|
||||
this.sharedConfig = new SharedConfig(config);
|
||||
|
||||
List<String> ipAddresses = sharedConfig.get("ip-addresses");
|
||||
int requestLimit = sharedConfig.get("mojang-request-limit");
|
||||
this.apiConnector = makeApiConnector(getLogger(), ipAddresses, requestLimit);
|
||||
}
|
||||
|
||||
public void setMojangApiConnector(MojangApiConnector mojangApiConnector) {
|
||||
this.mojangApiConnector = mojangApiConnector;
|
||||
}
|
||||
|
||||
public MojangApiConnector getMojangApiConnector() {
|
||||
return mojangApiConnector;
|
||||
public MojangApiConnector getApiConnector() {
|
||||
return apiConnector;
|
||||
}
|
||||
|
||||
public AuthStorage getStorage() {
|
||||
@ -101,6 +103,8 @@ public abstract class FastLoginCore<P> {
|
||||
|
||||
public abstract void loadConfig();
|
||||
|
||||
public abstract MojangApiConnector makeApiConnector(Logger logger, List<String> addresses, int requests);
|
||||
|
||||
public boolean setupDatabase() {
|
||||
String driver = sharedConfig.get("driver");
|
||||
String host = sharedConfig.get("host", "");
|
||||
|
@ -38,7 +38,7 @@ public abstract class JoinManagement<T, S extends LoginSource> {
|
||||
|
||||
UUID premiumUUID = null;
|
||||
if (sharedConfig.get("nameChangeCheck", false) || sharedConfig.get("autoRegister", false)) {
|
||||
premiumUUID = core.getMojangApiConnector().getPremiumUUID(username);
|
||||
premiumUUID = core.getApiConnector().getPremiumUUID(username);
|
||||
}
|
||||
|
||||
if (premiumUUID == null
|
||||
|
Reference in New Issue
Block a user