diff --git a/bukkit/src/main/java/com/github/games647/fastlogin/bukkit/BukkitCore.java b/bukkit/src/main/java/com/github/games647/fastlogin/bukkit/BukkitCore.java index 78d79711..08427ea2 100644 --- a/bukkit/src/main/java/com/github/games647/fastlogin/bukkit/BukkitCore.java +++ b/bukkit/src/main/java/com/github/games647/fastlogin/bukkit/BukkitCore.java @@ -65,11 +65,6 @@ public class BukkitCore extends FastLoginCore { }); } - @Override - public void loadConfig() { - plugin.saveDefaultConfig(); - } - @Override public MojangApiConnector makeApiConnector(Logger logger, List addresses, int requests) { return new MojangApiBukkit(logger, addresses, requests); diff --git a/bukkit/src/main/java/com/github/games647/fastlogin/bukkit/MojangApiBukkit.java b/bukkit/src/main/java/com/github/games647/fastlogin/bukkit/MojangApiBukkit.java index 3207b677..77e0a4a2 100644 --- a/bukkit/src/main/java/com/github/games647/fastlogin/bukkit/MojangApiBukkit.java +++ b/bukkit/src/main/java/com/github/games647/fastlogin/bukkit/MojangApiBukkit.java @@ -1,6 +1,7 @@ package com.github.games647.fastlogin.bukkit; import com.github.games647.fastlogin.core.shared.FastLoginCore; +import com.github.games647.fastlogin.core.shared.LoginSession; import com.github.games647.fastlogin.core.shared.MojangApiConnector; import java.io.BufferedReader; @@ -24,11 +25,7 @@ public class MojangApiBukkit extends MojangApiConnector { } @Override - public boolean hasJoinedServer(Object session, String serverId) { - if (!(session instanceof BukkitLoginSession)) { - return false; - } - + public boolean hasJoinedServer(LoginSession session, String serverId) { BukkitLoginSession playerSession = (BukkitLoginSession) session; try { String url = HAS_JOINED_URL + "username=" + playerSession.getUsername() + "&serverId=" + serverId; diff --git a/bukkit/src/main/java/com/github/games647/fastlogin/bukkit/hooks/AuthMeHook.java b/bukkit/src/main/java/com/github/games647/fastlogin/bukkit/hooks/AuthMeHook.java index 124ffbbd..53c7427c 100644 --- a/bukkit/src/main/java/com/github/games647/fastlogin/bukkit/hooks/AuthMeHook.java +++ b/bukkit/src/main/java/com/github/games647/fastlogin/bukkit/hooks/AuthMeHook.java @@ -24,6 +24,7 @@ public class AuthMeHook implements AuthPlugin { } @Override + @SuppressWarnings("deprecation") public boolean forceLogin(Player player) { //skips registration and login if (isNewAPIAvailable) { @@ -36,6 +37,7 @@ public class AuthMeHook implements AuthPlugin { } @Override + @SuppressWarnings("deprecation") public boolean isRegistered(String playerName) throws Exception { if (isNewAPIAvailable) { return NewAPI.getInstance().isRegistered(playerName); @@ -45,6 +47,7 @@ public class AuthMeHook implements AuthPlugin { } @Override + @SuppressWarnings("deprecation") public boolean forceRegister(Player player, String password) { if (isNewAPIAvailable) { NewAPI.getInstance().forceRegister(player, password); 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 e417dcd2..086d78fb 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 @@ -102,8 +102,6 @@ public class BungeeCordListener implements PluginMessageListener { public Set loadBungeeCordIds() { File whitelistFile = new File(plugin.getDataFolder(), FILE_NAME); - //create a new folder if it doesn't exist. Fail silently otherwise - whitelistFile.getParentFile().mkdir(); try { if (!whitelistFile.exists()) { whitelistFile.createNewFile(); 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 1278ae13..98660277 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 @@ -23,7 +23,8 @@ import net.md_5.bungee.config.YamlConfiguration; public class BungeeCore extends FastLoginCore { private static Map generateConfigMap(Configuration config) { - return config.getKeys().stream().filter(key -> config.get(key) != null) + return config.getKeys().stream() + .filter(key -> config.get(key) != null) .collect(Collectors.toMap(key -> key, config::get)); } @@ -46,13 +47,15 @@ public class BungeeCore extends FastLoginCore { } @Override + @SuppressWarnings("deprecation") public ThreadFactory getThreadFactory() { String pluginName = plugin.getDescription().getName(); return new ThreadFactoryBuilder() .setNameFormat(pluginName + " Database Pool Thread #%1$d") //Hikari create daemons by default .setDaemon(true) - .setThreadFactory(new GroupedThreadFactory(plugin, pluginName)).build(); + .setThreadFactory(new GroupedThreadFactory(plugin, pluginName)) + .build(); } @Override @@ -77,15 +80,6 @@ public class BungeeCore extends FastLoginCore { } } - @Override - public void loadConfig() { - if (!getDataFolder().exists()) { - getDataFolder().mkdir(); - } - - plugin.saveDefaultFile("config.yml"); - } - @Override public MojangApiConnector makeApiConnector(Logger logger, List addresses, int requests) { return new MojangApiBungee(logger, addresses, requests); diff --git a/bungee/src/main/java/com/github/games647/fastlogin/bungee/FastLoginBungee.java b/bungee/src/main/java/com/github/games647/fastlogin/bungee/FastLoginBungee.java index ad40e2d1..0fc42fef 100644 --- a/bungee/src/main/java/com/github/games647/fastlogin/bungee/FastLoginBungee.java +++ b/bungee/src/main/java/com/github/games647/fastlogin/bungee/FastLoginBungee.java @@ -48,7 +48,6 @@ public class FastLoginBungee extends Plugin { return; } - core.loadConfig(); core.setApiConnector(); core.loadMessages(); @@ -73,6 +72,10 @@ public class FastLoginBungee extends Plugin { } public void saveDefaultFile(String fileName) { + if (!getDataFolder().exists()) { + getDataFolder().mkdir(); + } + File configFile = new File(getDataFolder(), fileName); if (!configFile.exists()) { InputStream in = getResourceAsStream(fileName); diff --git a/bungee/src/main/java/com/github/games647/fastlogin/bungee/MojangApiBungee.java b/bungee/src/main/java/com/github/games647/fastlogin/bungee/MojangApiBungee.java index d8bce85f..90b656f4 100644 --- a/bungee/src/main/java/com/github/games647/fastlogin/bungee/MojangApiBungee.java +++ b/bungee/src/main/java/com/github/games647/fastlogin/bungee/MojangApiBungee.java @@ -1,5 +1,6 @@ package com.github.games647.fastlogin.bungee; +import com.github.games647.fastlogin.core.shared.LoginSession; import com.github.games647.fastlogin.core.shared.MojangApiConnector; import java.util.List; @@ -33,7 +34,7 @@ public class MojangApiBungee extends MojangApiConnector { } @Override - public boolean hasJoinedServer(Object session, String serverId) { + public boolean hasJoinedServer(LoginSession session, String serverId) { //this is not needed in Bungee throw new UnsupportedOperationException("Not supported"); } 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 b2d373bc..53b23f8f 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 @@ -34,7 +34,7 @@ public class ForceLoginTask implements Runnable { BungeeLoginSession session = plugin.getSession().get(pendingConnection); if (session == null || !player.isConnected()) { - plugin.getLogger().log(Level.FINE, "Invalid session player {0} proparly left the server", player); + plugin.getLogger().log(Level.FINE, "Invalid session player {0} propaly left the server", player); return; } diff --git a/core/src/main/java/com/github/games647/fastlogin/core/PlayerProfile.java b/core/src/main/java/com/github/games647/fastlogin/core/PlayerProfile.java index e813cdbd..160e5e55 100644 --- a/core/src/main/java/com/github/games647/fastlogin/core/PlayerProfile.java +++ b/core/src/main/java/com/github/games647/fastlogin/core/PlayerProfile.java @@ -23,12 +23,7 @@ public class PlayerProfile { } public PlayerProfile(UUID uuid, String playerName, boolean premium, String lastIp) { - this.userId = -1; - - this.uuid = uuid; - this.playerName = playerName; - this.premium = premium; - this.lastIp = lastIp; + this(-1, uuid, playerName, premium, lastIp, System.currentTimeMillis()); } public synchronized String getPlayerName() { diff --git a/core/src/main/java/com/github/games647/fastlogin/core/SharedConfig.java b/core/src/main/java/com/github/games647/fastlogin/core/SharedConfig.java index 72cc2958..f4d12273 100644 --- a/core/src/main/java/com/github/games647/fastlogin/core/SharedConfig.java +++ b/core/src/main/java/com/github/games647/fastlogin/core/SharedConfig.java @@ -19,4 +19,8 @@ public class SharedConfig { public T get(String path) { return get(path, null); } + + public Map getConfigValues() { + return configValues; + } } diff --git a/core/src/main/java/com/github/games647/fastlogin/core/hooks/AuthPlugin.java b/core/src/main/java/com/github/games647/fastlogin/core/hooks/AuthPlugin.java index c97e7452..cccd4911 100644 --- a/core/src/main/java/com/github/games647/fastlogin/core/hooks/AuthPlugin.java +++ b/core/src/main/java/com/github/games647/fastlogin/core/hooks/AuthPlugin.java @@ -3,9 +3,9 @@ package com.github.games647.fastlogin.core.hooks; /** * Represents a supporting authentication plugin in BungeeCord and Bukkit/Spigot/... servers * - * @param either org.bukkit.entity.Player for Bukkit or net.md_5.bungee.api.connection.ProxiedPlayer for BungeeCord + * @param

either org.bukkit.entity.Player for Bukkit or net.md_5.bungee.api.connection.ProxiedPlayer for BungeeCord */ -public interface AuthPlugin { +public interface AuthPlugin

{ /** * Login the premium (paid account) player after the player joined successfully the server. @@ -16,7 +16,7 @@ public interface AuthPlugin { * @param player the player that needs to be logged in * @return if the operation was successful */ - boolean forceLogin(T player); + boolean forceLogin(P player); /** * Forces a register in order to protect the paid account. @@ -39,7 +39,7 @@ public interface AuthPlugin { * @param password a strong random generated password * @return if the operation was successful */ - boolean forceRegister(T player, String password); + boolean forceRegister(P player, String password); /** * Checks whether an account exists for this player name. 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 39257333..9667a0d0 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 @@ -2,14 +2,14 @@ package com.github.games647.fastlogin.core.hooks; import java.util.Random; -public class DefaultPasswordGenerator implements PasswordGenerator { +public class DefaultPasswordGenerator

implements PasswordGenerator

{ private static final char[] PASSWORD_CHARACTERS = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789" .toCharArray(); private final Random random = new Random(); @Override - public String getRandomPassword(T player) { + public String getRandomPassword(P player) { StringBuilder generatedPassword = new StringBuilder(8); for (int i = 1; i <= 8; i++) { generatedPassword.append(PASSWORD_CHARACTERS[random.nextInt(PASSWORD_CHARACTERS.length - 1)]); diff --git a/core/src/main/java/com/github/games647/fastlogin/core/hooks/PasswordGenerator.java b/core/src/main/java/com/github/games647/fastlogin/core/hooks/PasswordGenerator.java index f7dc7832..ae398e0c 100644 --- a/core/src/main/java/com/github/games647/fastlogin/core/hooks/PasswordGenerator.java +++ b/core/src/main/java/com/github/games647/fastlogin/core/hooks/PasswordGenerator.java @@ -1,6 +1,6 @@ package com.github.games647.fastlogin.core.hooks; -public interface PasswordGenerator { +public interface PasswordGenerator

{ - String getRandomPassword(T player); + String getRandomPassword(P player); } diff --git a/core/src/main/java/com/github/games647/fastlogin/core/shared/FastLoginCore.java b/core/src/main/java/com/github/games647/fastlogin/core/shared/FastLoginCore.java index 7283493c..72bfec0b 100644 --- a/core/src/main/java/com/github/games647/fastlogin/core/shared/FastLoginCore.java +++ b/core/src/main/java/com/github/games647/fastlogin/core/shared/FastLoginCore.java @@ -62,7 +62,7 @@ public abstract class FastLoginCore

{ protected final Map localeMessages = new ConcurrentHashMap<>(); - private final ConcurrentMap pendingLogins; + private final ConcurrentMap pendingLogins = FastLoginCore.buildCache(5, 0); private final Set pendingConfirms = Sets.newHashSet(); private final SharedConfig sharedConfig; @@ -72,7 +72,6 @@ public abstract class FastLoginCore

{ private AuthPlugin

authPlugin; public FastLoginCore(Map config) { - this.pendingLogins = FastLoginCore.buildCache(5, 0); this.sharedConfig = new SharedConfig(config); } @@ -102,8 +101,6 @@ public abstract class FastLoginCore

{ public abstract void loadMessages(); - public abstract void loadConfig(); - public abstract MojangApiConnector makeApiConnector(Logger logger, List addresses, int requests); public boolean setupDatabase() { @@ -165,7 +162,7 @@ public abstract class FastLoginCore

{ return false; } - public SharedConfig getSharedConfig() { + public SharedConfig getConfig() { return sharedConfig; } 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 2011ee47..db6ba71d 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 @@ -23,13 +23,12 @@ public abstract class JoinManagement { return; } - SharedConfig sharedConfig = core.getSharedConfig(); + SharedConfig config = core.getConfig(); String ip = source.getAddress().getAddress().getHostAddress(); try { if (profile.getUserId() == -1) { - if (core.getPendingLogins().containsKey(ip + username) - && sharedConfig.get("secondAttemptCracked", false)) { + if (core.getPendingLogins().containsKey(ip + username) && config.get("secondAttemptCracked", false)) { core.getLogger().log(Level.INFO, "Second attempt login -> cracked {0}", username); //first login request failed so make a cracked session @@ -38,20 +37,21 @@ public abstract class JoinManagement { } UUID premiumUUID = null; - if (sharedConfig.get("nameChangeCheck", false) || sharedConfig.get("autoRegister", false)) { + if (config.get("nameChangeCheck", false) || config.get("autoRegister", false)) { + core.getLogger().log(Level.FINER, "Player {0} uses a premium username", username); premiumUUID = core.getApiConnector().getPremiumUUID(username); } if (premiumUUID == null - || (!checkNameChange(premiumUUID, source, username) - && !checkPremiumName(username, source, profile))) { + || (!checkNameChange(source, username, premiumUUID) + && !checkPremiumName(source, username, profile))) { //nothing detected the player as premium -> start a cracked session startCrackedSession(source, profile, username); } } else if (profile.isPremium()) { requestPremiumLogin(source, profile, username, true); } else { - if (core.getSharedConfig().get("switchMode", false)) { + if (core.getConfig().get("switchMode", false)) { source.kick(core.getMessage("switch-kick-message")); return; } @@ -63,10 +63,8 @@ public abstract class JoinManagement { } } - 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); + private boolean checkPremiumName(S source, String username, PlayerProfile profile) throws Exception { + if (core.getConfig().get("autoRegister", false) && (authHook == null || !authHook.isRegistered(username))) { requestPremiumLogin(source, profile, username, false); return true; } @@ -74,9 +72,9 @@ public abstract class JoinManagement { return false; } - private boolean checkNameChange(UUID premiumUUID, S source, String username) { + private boolean checkNameChange(S source, String username, UUID premiumUUID) { //user not exists in the db - if (core.getSharedConfig().get("nameChangeCheck", false)) { + if (core.getConfig().get("nameChangeCheck", false)) { PlayerProfile profile = core.getStorage().loadProfile(premiumUUID); if (profile != null) { //uuid exists in the database 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 c4d3c0b8..31521108 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 @@ -137,7 +137,7 @@ public abstract class MojangApiConnector { return null; } - public abstract boolean hasJoinedServer(Object session, String serverId); + public abstract boolean hasJoinedServer(LoginSession session, String serverId); protected abstract String getUUIDFromJson(String json);