Fix loading with unloaded configuration values

This commit is contained in:
games647
2016-09-15 10:33:17 +02:00
parent 218bc50c96
commit 07d0aededa
13 changed files with 58 additions and 35 deletions
@@ -23,27 +23,25 @@ import net.md_5.bungee.config.YamlConfiguration;
*/
public class FastLoginBungee extends Plugin {
private final BungeeCore loginCore = new BungeeCore(this);
private BungeeAuthPlugin bungeeAuthPlugin;
private Configuration config;
private final ConcurrentMap<PendingConnection, BungeeLoginSession> session = Maps.newConcurrentMap();
private BungeeCore core;
private Configuration config;
@Override
public void onEnable() {
loginCore.loadConfig();
loginCore.loadMessages();
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);
loginCore.setMojangApiConnector(mojangApi);
core.setMojangApiConnector(mojangApi);
if (!loginCore.setupDatabase()) {
if (!core.setupDatabase()) {
return;
}
} catch (IOException ioExc) {
@@ -51,6 +49,9 @@ public class FastLoginBungee extends Plugin {
return;
}
core.loadConfig();
core.loadMessages();
//events
getProxy().getPluginManager().registerListener(this, new PlayerConnectionListener(this));
getProxy().getPluginManager().registerListener(this, new PluginMessageListener(this));
@@ -66,15 +67,15 @@ public class FastLoginBungee extends Plugin {
@Override
public void onDisable() {
loginCore.close();
core.close();
}
public BungeeCore getCore() {
return loginCore;
return core;
}
public void setAuthPluginHook(BungeeAuthPlugin authPlugin) {
this.bungeeAuthPlugin = authPlugin;
core.setAuthPlugin(authPlugin);
}
public Configuration getConfig() {
@@ -91,13 +92,13 @@ public class FastLoginBungee extends Plugin {
* @return the auth hook for BungeeCord. null if none found
*/
public BungeeAuthPlugin getBungeeAuthPlugin() {
return bungeeAuthPlugin;
return (BungeeAuthPlugin) core.getAuthPlugin();
}
private void registerHook() {
Plugin plugin = getProxy().getPluginManager().getPlugin("BungeeAuth");
if (plugin != null) {
bungeeAuthPlugin = new BungeeAuthHook();
core.setAuthPlugin(new BungeeAuthHook());
getLogger().info("Hooked into BungeeAuth");
}
}
@@ -1,5 +1,7 @@
package com.github.games647.fastlogin.bungee.hooks;
import com.github.games647.fastlogin.core.hooks.AuthPlugin;
import java.lang.reflect.Method;
import java.text.SimpleDateFormat;
import java.util.Date;
@@ -20,7 +22,7 @@ import net.md_5.bungee.api.connection.ProxiedPlayer;
*
* Spigot: https://www.spigotmc.org/resources/bungeeauth.493/
*/
public class BungeeAuthHook implements BungeeAuthPlugin {
public class BungeeAuthHook implements AuthPlugin<ProxiedPlayer> {
//https://github.com/MatteCarra/BungeeAuth/blob/master/src/me/vik1395/BungeeAuth/Login.java#L32
private final Tables databaseConnection = new Tables();