diff --git a/bukkit/src/main/java/com/github/games647/fastlogin/bukkit/BukkitLoginSession.java b/bukkit/src/main/java/com/github/games647/fastlogin/bukkit/BukkitLoginSession.java index 7eb39878..4e13e8c2 100644 --- a/bukkit/src/main/java/com/github/games647/fastlogin/bukkit/BukkitLoginSession.java +++ b/bukkit/src/main/java/com/github/games647/fastlogin/bukkit/BukkitLoginSession.java @@ -51,8 +51,8 @@ public class BukkitLoginSession extends LoginSession { private SkinProperty skinProperty; - public BukkitLoginSession(String username, byte[] verifyToken, ClientPublicKey publicKey, boolean registered - , StoredProfile profile) { + public BukkitLoginSession(String username, byte[] verifyToken, ClientPublicKey publicKey, boolean registered, + StoredProfile profile) { super(username, registered, profile); this.clientPublicKey = publicKey; diff --git a/bukkit/src/main/java/com/github/games647/fastlogin/bukkit/BungeeManager.java b/bukkit/src/main/java/com/github/games647/fastlogin/bukkit/BungeeManager.java index e0c4385a..7356492e 100644 --- a/bukkit/src/main/java/com/github/games647/fastlogin/bukkit/BungeeManager.java +++ b/bukkit/src/main/java/com/github/games647/fastlogin/bukkit/BungeeManager.java @@ -33,6 +33,7 @@ import com.google.common.io.ByteArrayDataOutput; import com.google.common.io.ByteStreams; import java.io.IOException; +import java.lang.reflect.Field; import java.lang.reflect.InvocationTargetException; import java.nio.file.Files; import java.nio.file.Path; @@ -113,7 +114,9 @@ public class BungeeManager { Class globalConfig = Class.forName("io.papermc.paper.configuration.GlobalConfiguration"); Object global = globalConfig.getDeclaredMethod("get").invoke(null); Object proxiesConfiguration = global.getClass().getDeclaredField("proxies").get(global); - Object velocityConfig = proxiesConfiguration.getClass().getDeclaredField("velocity").get(proxiesConfiguration); + + Field velocitySectionField = proxiesConfiguration.getClass().getDeclaredField("velocity"); + Object velocityConfig = velocitySectionField.get(proxiesConfiguration); return velocityConfig.getClass().getDeclaredField("enabled").getBoolean(velocityConfig); } catch (ClassNotFoundException classNotFoundException) { @@ -128,7 +131,9 @@ public class BungeeManager { private boolean detectProxy() { try { - if (isProxySupported("org.spigotmc.SpigotConfig", "bungee")) return true; + if (isProxySupported("org.spigotmc.SpigotConfig", "bungee")) { + return true; + } } catch (ClassNotFoundException classNotFoundException) { // leave stacktrace for class not found out plugin.getLog().warn("Cannot check for BungeeCord support: {}", classNotFoundException.getMessage()); diff --git a/bukkit/src/main/java/com/github/games647/fastlogin/bukkit/FastLoginBukkit.java b/bukkit/src/main/java/com/github/games647/fastlogin/bukkit/FastLoginBukkit.java index 8b5dad60..b2bc397c 100644 --- a/bukkit/src/main/java/com/github/games647/fastlogin/bukkit/FastLoginBukkit.java +++ b/bukkit/src/main/java/com/github/games647/fastlogin/bukkit/FastLoginBukkit.java @@ -120,18 +120,7 @@ public class FastLoginBukkit extends JavaPlugin implements PlatformPlugin * Bukkit: ... */ -public class xAuthHook implements AuthPlugin { +public class XAuthHook implements AuthPlugin { private final xAuth xAuthPlugin = xAuth.getPlugin(); private final FastLoginBukkit plugin; - public xAuthHook(FastLoginBukkit plugin) { + public XAuthHook(FastLoginBukkit plugin) { this.plugin = plugin; } diff --git a/bukkit/src/main/java/com/github/games647/fastlogin/bukkit/listener/ConnectionListener.java b/bukkit/src/main/java/com/github/games647/fastlogin/bukkit/listener/ConnectionListener.java index d31ef7a9..a9a70f89 100644 --- a/bukkit/src/main/java/com/github/games647/fastlogin/bukkit/listener/ConnectionListener.java +++ b/bukkit/src/main/java/com/github/games647/fastlogin/bukkit/listener/ConnectionListener.java @@ -97,8 +97,8 @@ public class ConnectionListener implements Listener { String sessionId = plugin.getSessionId(player.getAddress()); plugin.getLog().info("No on-going login session for player: {} with ID {}. ", player, sessionId); - plugin.getLog().info("Setups using Minecraft proxies will start delayed " + - "when the command from the proxy is received"); + plugin.getLog().info("Setups using Minecraft proxies will start delayed " + + "when the command from the proxy is received"); } else { Runnable forceLoginTask = new ForceLoginTask(plugin.getCore(), player, session); Bukkit.getScheduler().runTaskAsynchronously(plugin, forceLoginTask); diff --git a/bukkit/src/main/java/com/github/games647/fastlogin/bukkit/listener/protocollib/EncryptionUtil.java b/bukkit/src/main/java/com/github/games647/fastlogin/bukkit/listener/protocollib/EncryptionUtil.java index 844b92c6..525cda83 100644 --- a/bukkit/src/main/java/com/github/games647/fastlogin/bukkit/listener/protocollib/EncryptionUtil.java +++ b/bukkit/src/main/java/com/github/games647/fastlogin/bukkit/listener/protocollib/EncryptionUtil.java @@ -34,7 +34,6 @@ import com.google.common.primitives.Longs; import java.io.IOException; import java.math.BigInteger; import java.nio.charset.StandardCharsets; -import java.security.GeneralSecurityException; import java.security.InvalidKeyException; import java.security.KeyFactory; import java.security.KeyPair; @@ -63,20 +62,22 @@ import javax.crypto.spec.SecretKeySpec; * Encryption and decryption minecraft util for connection between servers * and paid Minecraft account clients. */ -class EncryptionUtil { +final class EncryptionUtil { public static final int VERIFY_TOKEN_LENGTH = 4; public static final String KEY_PAIR_ALGORITHM = "RSA"; private static final int RSA_LENGTH = 1_024; - private static final PublicKey mojangSessionKey; + private static final PublicKey MOJANG_SESSION_KEY; private static final int LINE_LENGTH = 76; - private static final Encoder KEY_ENCODER = Base64.getMimeEncoder(LINE_LENGTH, "\n".getBytes(StandardCharsets.UTF_8)); + private static final Encoder KEY_ENCODER = Base64.getMimeEncoder( + LINE_LENGTH, "\n".getBytes(StandardCharsets.UTF_8) + ); static { try { - mojangSessionKey = loadMojangSessionKey(); + MOJANG_SESSION_KEY = loadMojangSessionKey(); } catch (IOException | NoSuchAlgorithmException | InvalidKeySpecException ex) { throw new RuntimeException("Failed to load Mojang session key", ex); } @@ -119,7 +120,7 @@ class EncryptionUtil { /** * Generate the server id based on client and server data. * - * @param serverId session for the current login attempt + * @param serverId session for the current login attempt * @param sharedSecret shared secret between the client and the server * @param publicKey public key of the server * @return the server id formatted as a hexadecimal string. @@ -135,7 +136,6 @@ class EncryptionUtil { * @param privateKey private server key * @param sharedKey the encrypted shared key * @return shared secret key - * @throws GeneralSecurityException if it fails to decrypt the data */ public static SecretKey decryptSharedKey(PrivateKey privateKey, byte[] sharedKey) throws NoSuchPaddingException, IllegalBlockSizeException, NoSuchAlgorithmException, @@ -151,7 +151,7 @@ class EncryptionUtil { Signature verifier = Signature.getInstance("SHA1withRSA"); // key of the signer - verifier.initVerify(mojangSessionKey); + verifier.initVerify(MOJANG_SESSION_KEY); verifier.update(toSignable(clientKey).getBytes(StandardCharsets.US_ASCII)); return verifier.verify(clientKey.signature()); } diff --git a/bukkit/src/main/java/com/github/games647/fastlogin/bukkit/listener/protocollib/NameCheckTask.java b/bukkit/src/main/java/com/github/games647/fastlogin/bukkit/listener/protocollib/NameCheckTask.java index a135116f..b210feae 100644 --- a/bukkit/src/main/java/com/github/games647/fastlogin/bukkit/listener/protocollib/NameCheckTask.java +++ b/bukkit/src/main/java/com/github/games647/fastlogin/bukkit/listener/protocollib/NameCheckTask.java @@ -88,8 +88,8 @@ public class NameCheckTask extends JoinManagement - + diff --git a/core/src/main/java/com/github/games647/fastlogin/core/CommonUtil.java b/core/src/main/java/com/github/games647/fastlogin/core/CommonUtil.java index ce6645b2..324e240e 100644 --- a/core/src/main/java/com/github/games647/fastlogin/core/CommonUtil.java +++ b/core/src/main/java/com/github/games647/fastlogin/core/CommonUtil.java @@ -37,7 +37,7 @@ import org.slf4j.Logger; import org.slf4j.LoggerFactory; import org.slf4j.jul.JDK14LoggerAdapter; -public class CommonUtil { +public final class CommonUtil { private static final char COLOR_CHAR = '&'; private static final char TRANSLATED_CHAR = 'ยง'; diff --git a/core/src/main/java/com/github/games647/fastlogin/core/StoredProfile.java b/core/src/main/java/com/github/games647/fastlogin/core/StoredProfile.java index 9757eb50..ee58bdeb 100644 --- a/core/src/main/java/com/github/games647/fastlogin/core/StoredProfile.java +++ b/core/src/main/java/com/github/games647/fastlogin/core/StoredProfile.java @@ -114,11 +114,20 @@ public class StoredProfile extends Profile { @Override public synchronized boolean equals(Object o) { - if (this == o) return true; - if (!(o instanceof StoredProfile that)) return false; - if (!super.equals(o)) return false; + if (this == o) { + return true; + } + + if (!(o instanceof StoredProfile that)) { + return false; + } + + if (!super.equals(o)) { + return false; + } + return rowId == that.rowId && premium == that.premium - && Objects.equals(lastIp, that.lastIp) && lastLogin.equals(that.lastLogin); + && Objects.equals(lastIp, that.lastIp) && lastLogin.equals(that.lastLogin); } @Override @@ -128,11 +137,11 @@ public class StoredProfile extends Profile { @Override public synchronized String toString() { - return this.getClass().getSimpleName() + '{' + - "rowId=" + rowId + - ", premium=" + premium + - ", lastIp='" + lastIp + '\'' + - ", lastLogin=" + lastLogin + - "} " + super.toString(); + return this.getClass().getSimpleName() + '{' + + "rowId=" + rowId + + ", premium=" + premium + + ", lastIp='" + lastIp + '\'' + + ", lastLogin=" + lastLogin + + "} " + super.toString(); } } diff --git a/core/src/main/java/com/github/games647/fastlogin/core/antibot/ProxyAgnosticMojangResolver.java b/core/src/main/java/com/github/games647/fastlogin/core/antibot/ProxyAgnosticMojangResolver.java index ce10bb20..65def8de 100644 --- a/core/src/main/java/com/github/games647/fastlogin/core/antibot/ProxyAgnosticMojangResolver.java +++ b/core/src/main/java/com/github/games647/fastlogin/core/antibot/ProxyAgnosticMojangResolver.java @@ -36,42 +36,46 @@ import java.util.Optional; /** * An extension to {@link MojangResolver} which allows connection using transparent reverse proxies. - * The significant difference is that unlike MojangResolver from the CraftAPI implementation, which sends the "ip" parameter - * when the hostIp parameter is an IPv4 address, but skips it for IPv6, this implementation leaves out the "ip" parameter - * also for IPv4, effectively enabling transparent proxies to work. + * The significant difference is that unlike MojangResolver from the CraftAPI implementation, which sends the + * "ip" parameter when the hostIp parameter is an IPv4 address, but skips it for IPv6, this implementation leaves out + * the "ip" parameter also for IPv4, effectively enabling transparent proxies to work. + * * @author games647, Enginecrafter77 */ public class ProxyAgnosticMojangResolver extends MojangResolver { - /** - * A formatting string containing a URL used to call the {@code hasJoined} method on mojang session servers. - * - * Formatting parameters: - * 1. The username of the player in question - * 2. The serverId of this server - */ - public static final String MOJANG_SESSIONSERVER_HASJOINED_CALL_URLFMT = "https://sessionserver.mojang.com/session/minecraft/hasJoined?username=%s&serverId=%s"; - @Override - public Optional hasJoined(String username, String serverHash, InetAddress hostIp) throws IOException - { - String url = String.format(MOJANG_SESSIONSERVER_HASJOINED_CALL_URLFMT, username, serverHash); + private static final String HOST = "sessionserver.mojang.com"; - HttpURLConnection conn = this.getConnection(url); - int responseCode = conn.getResponseCode(); + /** + * A formatting string containing a URL used to call the {@code hasJoined} method on mojang session servers. + *

+ * Formatting parameters: + * 1. The username of the player in question + * 2. The serverId of this server + */ + public static final String ENDPOINT = "https://" + HOST + "/session/minecraft/hasJoined?username=%s&serverId=%s"; - Verification verification = null; + @Override + public Optional hasJoined(String username, String serverHash, InetAddress hostIp) + throws IOException { + String url = String.format(ENDPOINT, username, serverHash); - // Mojang session servers send HTTP 204 (NO CONTENT) when the authentication seems invalid - // If that's not our case, the authentication is valid, and so we can parse the response. - if(responseCode != HttpURLConnection.HTTP_NO_CONTENT) - verification = this.parseRequest(conn, this::parseVerification); + HttpURLConnection conn = this.getConnection(url); + int responseCode = conn.getResponseCode(); - return Optional.ofNullable(verification); - } + Verification verification = null; - // Functional implementation of InputStreamAction, used in hasJoined method in parseRequest call - protected Verification parseVerification(InputStream input) throws IOException - { - return this.readJson(input, Verification.class); - } + // Mojang session servers send HTTP 204 (NO CONTENT) when the authentication seems invalid + // If that's not our case, the authentication is valid, and so we can parse the response. + if (responseCode != HttpURLConnection.HTTP_NO_CONTENT) { + verification = this.parseRequest(conn, this::parseVerification); + } + + return Optional.ofNullable(verification); + } + + // Functional implementation of InputStreamAction, used in hasJoined method in parseRequest call + protected Verification parseVerification(InputStream input) throws IOException { + return this.readJson(input, Verification.class); + } } diff --git a/core/src/main/java/com/github/games647/fastlogin/core/antibot/TickingRateLimiter.java b/core/src/main/java/com/github/games647/fastlogin/core/antibot/TickingRateLimiter.java index ced7da18..c8d57c59 100644 --- a/core/src/main/java/com/github/games647/fastlogin/core/antibot/TickingRateLimiter.java +++ b/core/src/main/java/com/github/games647/fastlogin/core/antibot/TickingRateLimiter.java @@ -113,7 +113,7 @@ public class TickingRateLimiter implements RateLimiter { private final long expireTime; private int count; - public TimeRecord(long firstMinuteRecord, long expireTime) { + TimeRecord(long firstMinuteRecord, long expireTime) { this.firstMinuteRecord = firstMinuteRecord; this.expireTime = expireTime; this.count = 1; diff --git a/core/src/main/java/com/github/games647/fastlogin/core/hooks/bedrock/BedrockService.java b/core/src/main/java/com/github/games647/fastlogin/core/hooks/bedrock/BedrockService.java index b182bf8b..63dc0af5 100644 --- a/core/src/main/java/com/github/games647/fastlogin/core/hooks/bedrock/BedrockService.java +++ b/core/src/main/java/com/github/games647/fastlogin/core/hooks/bedrock/BedrockService.java @@ -74,12 +74,12 @@ public abstract class BedrockService { "Could not check whether Bedrock Player {}'s name conflicts a premium Java player's name.", username); - kickPlayer(source, username, "Could not check if your name conflicts an existing " + - "premium Java account's name. This is usually a serverside error."); + kickPlayer(source, username, "Could not check if your name conflicts an existing " + + "premium Java account's name. This is usually a serverside error."); } catch (RateLimitException rateLimitException) { core.getPlugin().getLog().warn("Mojang API rate limit hit"); - kickPlayer(source, username, "Could not check if your name conflicts an existing premium " + - "Java account's name. Try again in a few minutes"); + kickPlayer(source, username, "Could not check if your name conflicts an existing premium " + + "Java account's name. Try again in a few minutes"); } if (premiumUUID.isPresent()) { diff --git a/core/src/main/java/com/github/games647/fastlogin/core/hooks/bedrock/FloodgateService.java b/core/src/main/java/com/github/games647/fastlogin/core/hooks/bedrock/FloodgateService.java index 1b555f18..9ef8985c 100644 --- a/core/src/main/java/com/github/games647/fastlogin/core/hooks/bedrock/FloodgateService.java +++ b/core/src/main/java/com/github/games647/fastlogin/core/hooks/bedrock/FloodgateService.java @@ -60,12 +60,16 @@ public class FloodgateService extends BedrockService { */ public boolean isValidFloodgateConfigString(String key) { String value = core.getConfig().get(key).toString().toLowerCase(Locale.ENGLISH); - if (!"true".equals(value) && !"linked".equals(value) && !"false".equals(value) && !"no-conflict".equals(value)) { - core.getPlugin().getLog().error("Invalid value detected for {} in FastLogin/config.yml.", key); - return false; + switch (value) { + case "true": + case "linked": + case "false": + case "no-conflict": + return true; + default: + core.getPlugin().getLog().error("Invalid value detected for {} in FastLogin/config.yml.", key); + return false; } - - return true; } @Override @@ -82,7 +86,7 @@ public class FloodgateService extends BedrockService { if ("false".equals(allowConflict) || "linked".equals(allowConflict) && !isLinked) { - super.checkNameConflict(username, source); + super.checkNameConflict(username, source); } else { core.getPlugin().getLog().info("Skipping name conflict checking for player {}", username); } diff --git a/core/src/main/java/com/github/games647/fastlogin/core/message/ChangePremiumMessage.java b/core/src/main/java/com/github/games647/fastlogin/core/message/ChangePremiumMessage.java index 1b216ebd..d77aecf2 100644 --- a/core/src/main/java/com/github/games647/fastlogin/core/message/ChangePremiumMessage.java +++ b/core/src/main/java/com/github/games647/fastlogin/core/message/ChangePremiumMessage.java @@ -79,10 +79,10 @@ public class ChangePremiumMessage implements ChannelMessage { @Override public String toString() { - return this.getClass().getSimpleName() + '{' + - "playerName='" + playerName + '\'' + - ", shouldEnable=" + willEnable + - ", isSourceInvoker=" + isSourceInvoker + - '}'; + return this.getClass().getSimpleName() + '{' + + "playerName='" + playerName + '\'' + + ", shouldEnable=" + willEnable + + ", isSourceInvoker=" + isSourceInvoker + + '}'; } } diff --git a/core/src/main/java/com/github/games647/fastlogin/core/message/LoginActionMessage.java b/core/src/main/java/com/github/games647/fastlogin/core/message/LoginActionMessage.java index cc533eed..a10d702d 100644 --- a/core/src/main/java/com/github/games647/fastlogin/core/message/LoginActionMessage.java +++ b/core/src/main/java/com/github/games647/fastlogin/core/message/LoginActionMessage.java @@ -92,11 +92,11 @@ public class LoginActionMessage implements ChannelMessage { @Override public String toString() { - return this.getClass().getSimpleName() + '{' + - "type='" + type + '\'' + - ", playerName='" + playerName + '\'' + - ", proxyId=" + proxyId + - '}'; + return this.getClass().getSimpleName() + '{' + + "type='" + type + '\'' + + ", playerName='" + playerName + '\'' + + ", proxyId=" + proxyId + + '}'; } public enum Type { 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 474a8e23..5e968199 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 @@ -122,7 +122,8 @@ public class FastLoginCore

> { } // Initialize the resolver based on the config parameter - this.resolver = this.config.getBoolean("useProxyAgnosticResolver", false) ? new ProxyAgnosticMojangResolver() : new MojangResolver(); + this.resolver = this.config.getBoolean("useProxyAgnosticResolver", false) + ? new ProxyAgnosticMojangResolver() : new MojangResolver(); antiBot = createAntiBotService(config.getSection("anti-bot")); Set proxies = config.getStringList("proxies") @@ -191,7 +192,7 @@ public class FastLoginCore

> { config = configProvider.load(reader, defaults); } - // explicitly add keys here, because Configuration.getKeys doesn't return the keys from the default configuration + // explicitly add keys here, because Configuration.getKeys doesn't return the keys from the default config for (String key : defaults.getKeys()) { config.set(key, config.get(key)); } @@ -244,9 +245,13 @@ public class FastLoginCore

> { boolean useSSL = config.get("useSSL", false); if (useSSL) { - databaseConfig.addDataSourceProperty("allowPublicKeyRetrieval", config.getBoolean("allowPublicKeyRetrieval", false)); - databaseConfig.addDataSourceProperty("serverRSAPublicKeyFile", config.getString("ServerRSAPublicKeyFile")); - databaseConfig.addDataSourceProperty("sslMode", config.getString("sslMode", "Required")); + boolean publicKeyRetrieval = config.getBoolean("allowPublicKeyRetrieval", false); + String rsaPublicKeyFile = config.getString("ServerRSAPublicKeyFile"); + String sslMode = config.getString("sslMode", "Required"); + + databaseConfig.addDataSourceProperty("allowPublicKeyRetrieval", publicKeyRetrieval); + databaseConfig.addDataSourceProperty("serverRSAPublicKeyFile", rsaPublicKeyFile); + databaseConfig.addDataSourceProperty("sslMode", sslMode); } databaseConfig.setUsername(config.get("username", "")); @@ -270,8 +275,8 @@ public class FastLoginCore

> { } catch (ClassNotFoundException notFoundEx) { Logger log = plugin.getLog(); log.warn("This driver {} is not supported on this platform", className); - log.warn("Please choose either MySQL (Spigot, BungeeCord), SQLite (Spigot, Sponge) or " + - "MariaDB (Sponge, Velocity)", notFoundEx); + log.warn("Please choose either MySQL (Spigot, BungeeCord), SQLite (Spigot, Sponge) or " + + "MariaDB (Sponge, Velocity)", notFoundEx); } return false; 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 9ad39b90..fd3e5945 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 @@ -106,9 +106,9 @@ public abstract class JoinManagement

{ } } } catch (RateLimitException rateLimitEx) { - core.getPlugin().getLog().error("Mojang's rate limit reached for {}. The public IPv4 address of this" + - " server issued more than 600 Name -> UUID requests within 10 minutes. After those 10" + - " minutes we can make requests again.", username); + core.getPlugin().getLog().error("Mojang's rate limit reached for {}. The public IPv4 address of this" + + " server issued more than 600 Name -> UUID requests within 10 minutes. After those 10" + + " minutes we can make requests again.", username); } catch (Exception ex) { core.getPlugin().getLog().error("Failed to check premium state for {}", username, ex); core.getPlugin().getLog().error("Failed to check premium state of {}", username, ex); diff --git a/core/src/main/java/com/github/games647/fastlogin/core/storage/MySQLStorage.java b/core/src/main/java/com/github/games647/fastlogin/core/storage/MySQLStorage.java index d3a3cd40..2bbae0b4 100644 --- a/core/src/main/java/com/github/games647/fastlogin/core/storage/MySQLStorage.java +++ b/core/src/main/java/com/github/games647/fastlogin/core/storage/MySQLStorage.java @@ -31,7 +31,7 @@ import com.zaxxer.hikari.HikariConfig; public class MySQLStorage extends SQLStorage { public MySQLStorage(FastLoginCore core, String driver, String host, int port, String database, - HikariConfig config,boolean useSSL) { + HikariConfig config, boolean useSSL) { super(core, buildJDBCUrl(driver, host, port, database), setParams(config, useSSL)); diff --git a/pom.xml b/pom.xml index 5bafba1e..c9bc4dea 100644 --- a/pom.xml +++ b/pom.xml @@ -131,11 +131,17 @@ 3.1.2 checkstyle.xml - UTF-8 true - true + false false + + + com.puppycrawl.tools + checkstyle + 10.3.1 + + validate diff --git a/velocity/src/main/java/com/github/games647/fastlogin/velocity/FastLoginVelocity.java b/velocity/src/main/java/com/github/games647/fastlogin/velocity/FastLoginVelocity.java index e15dd3ef..17934c94 100644 --- a/velocity/src/main/java/com/github/games647/fastlogin/velocity/FastLoginVelocity.java +++ b/velocity/src/main/java/com/github/games647/fastlogin/velocity/FastLoginVelocity.java @@ -46,6 +46,7 @@ import com.velocitypowered.api.plugin.Plugin; import com.velocitypowered.api.plugin.annotation.DataDirectory; import com.velocitypowered.api.proxy.Player; import com.velocitypowered.api.proxy.ProxyServer; +import com.velocitypowered.api.proxy.messages.ChannelRegistrar; import com.velocitypowered.api.proxy.messages.MinecraftChannelIdentifier; import com.velocitypowered.api.proxy.server.RegisteredServer; @@ -73,7 +74,7 @@ public class FastLoginVelocity implements PlatformPlugin { private final Path dataDirectory; private final Logger logger; private final ConcurrentMap session = new MapMaker().weakKeys().makeMap(); - private static final String PROXY_ID_fILE = "proxyId.txt"; + private static final String PROXY_ID_FILE = "proxyId.txt"; private FastLoginCore core; private AsyncScheduler scheduler; @@ -98,8 +99,10 @@ public class FastLoginVelocity implements PlatformPlugin { server.getEventManager().register(this, new ConnectListener(this, core.getAntiBot())); server.getEventManager().register(this, new PluginMessageListener(this)); - server.getChannelRegistrar().register(MinecraftChannelIdentifier.create(getName(), ChangePremiumMessage.CHANGE_CHANNEL)); - server.getChannelRegistrar().register(MinecraftChannelIdentifier.create(getName(), SuccessMessage.SUCCESS_CHANNEL)); + + ChannelRegistrar channelRegistry = server.getChannelRegistrar(); + channelRegistry.register(MinecraftChannelIdentifier.create(getName(), ChangePremiumMessage.CHANGE_CHANNEL)); + channelRegistry.register(MinecraftChannelIdentifier.create(getName(), SuccessMessage.SUCCESS_CHANNEL)); } @Subscribe @@ -167,7 +170,7 @@ public class FastLoginVelocity implements PlatformPlugin { } private void loadOrGenerateProxyId() { - Path idFile = dataDirectory.resolve(PROXY_ID_fILE); + Path idFile = dataDirectory.resolve(PROXY_ID_FILE); boolean shouldGenerate = false; if (Files.exists(idFile)) { @@ -182,7 +185,8 @@ public class FastLoginVelocity implements PlatformPlugin { logger.error("Unable to load proxy id from '{}'", idFile.toAbsolutePath()); logger.error("Detailed exception:", e); } catch (IllegalArgumentException e) { - logger.error("'{}' contains an invalid uuid! FastLogin will not work without a valid id.", idFile.toAbsolutePath()); + Path filePath = idFile.toAbsolutePath(); + logger.error("'{}' contains an invalid uuid! FastLogin will not work without a valid id.", filePath); } } else { shouldGenerate = true; diff --git a/velocity/src/main/java/com/github/games647/fastlogin/velocity/VelocityLoginSession.java b/velocity/src/main/java/com/github/games647/fastlogin/velocity/VelocityLoginSession.java index 0a096db0..053c2ba2 100644 --- a/velocity/src/main/java/com/github/games647/fastlogin/velocity/VelocityLoginSession.java +++ b/velocity/src/main/java/com/github/games647/fastlogin/velocity/VelocityLoginSession.java @@ -58,10 +58,10 @@ public class VelocityLoginSession extends LoginSession { @Override public synchronized String toString() { - return this.getClass().getSimpleName() + '{' + - "alreadySaved=" + alreadySaved + - ", alreadyLogged=" + alreadyLogged + - ", registered=" + registered + - "} " + super.toString(); + return this.getClass().getSimpleName() + '{' + + "alreadySaved=" + alreadySaved + + ", alreadyLogged=" + alreadyLogged + + ", registered=" + registered + + "} " + super.toString(); } } diff --git a/velocity/src/main/java/com/github/games647/fastlogin/velocity/event/VelocityFastLoginAutoLoginEvent.java b/velocity/src/main/java/com/github/games647/fastlogin/velocity/event/VelocityFastLoginAutoLoginEvent.java index aabe153d..6049b694 100644 --- a/velocity/src/main/java/com/github/games647/fastlogin/velocity/event/VelocityFastLoginAutoLoginEvent.java +++ b/velocity/src/main/java/com/github/games647/fastlogin/velocity/event/VelocityFastLoginAutoLoginEvent.java @@ -33,7 +33,7 @@ import com.velocitypowered.api.event.ResultedEvent; import java.util.Objects; public class VelocityFastLoginAutoLoginEvent - implements FastLoginAutoLoginEvent, ResultedEvent { + implements FastLoginAutoLoginEvent, ResultedEvent { private final LoginSession session; private final StoredProfile profile; @@ -67,11 +67,11 @@ public class VelocityFastLoginAutoLoginEvent @Override public GenericResult getResult() { - return cancelled ? GenericResult.denied(): GenericResult.allowed(); + return cancelled ? GenericResult.denied() : GenericResult.allowed(); } @Override public void setResult(GenericResult result) { - cancelled = Objects.requireNonNull(result) != GenericResult.allowed(); + cancelled = Objects.requireNonNull(result) != GenericResult.allowed(); } } diff --git a/velocity/src/main/java/com/github/games647/fastlogin/velocity/listener/ConnectListener.java b/velocity/src/main/java/com/github/games647/fastlogin/velocity/listener/ConnectListener.java index d0dcfd17..1010871f 100644 --- a/velocity/src/main/java/com/github/games647/fastlogin/velocity/listener/ConnectListener.java +++ b/velocity/src/main/java/com/github/games647/fastlogin/velocity/listener/ConnectListener.java @@ -92,7 +92,9 @@ public class ConnectListener { break; case Continue: default: - Runnable asyncPremiumCheck = new AsyncPremiumCheck(plugin, connection, username, continuation, preLoginEvent); + Runnable asyncPremiumCheck = new AsyncPremiumCheck( + plugin, connection, username, continuation, preLoginEvent + ); plugin.getScheduler().runAsync(asyncPremiumCheck); break; } @@ -118,8 +120,8 @@ public class ConnectListener { } if (!plugin.getCore().getConfig().get("forwardSkin", true)) { - List skinFreeProp = removeSkin(event.getGameProfile().getProperties()); - event.setGameProfile(event.getGameProfile().withProperties(skinFreeProp)); + List newProp = removeSkin(event.getGameProfile().getProperties()); + event.setGameProfile(event.getGameProfile().withProperties(newProp)); } } } @@ -127,8 +129,9 @@ public class ConnectListener { private List removeSkin(Collection oldProperties) { List newProperties = new ArrayList<>(oldProperties.size()); for (GameProfile.Property property : oldProperties) { - if (!"textures".equals(property.getName())) + if (!"textures".equals(property.getName())) { newProperties.add(property); + } } return newProperties; diff --git a/velocity/src/main/java/com/github/games647/fastlogin/velocity/listener/PluginMessageListener.java b/velocity/src/main/java/com/github/games647/fastlogin/velocity/listener/PluginMessageListener.java index cdef0c2b..4e6b1183 100644 --- a/velocity/src/main/java/com/github/games647/fastlogin/velocity/listener/PluginMessageListener.java +++ b/velocity/src/main/java/com/github/games647/fastlogin/velocity/listener/PluginMessageListener.java @@ -55,8 +55,9 @@ public class PluginMessageListener { public PluginMessageListener(FastLoginVelocity plugin) { this.plugin = plugin; - this.successChannel = MinecraftChannelIdentifier.create(plugin.getName(), SuccessMessage.SUCCESS_CHANNEL).getId(); - this.changeChannel = MinecraftChannelIdentifier.create(plugin.getName(), ChangePremiumMessage.CHANGE_CHANNEL).getId(); + String prefix = plugin.getName(); + this.successChannel = MinecraftChannelIdentifier.create(prefix, SuccessMessage.SUCCESS_CHANNEL).getId(); + this.changeChannel = MinecraftChannelIdentifier.create(prefix, ChangePremiumMessage.CHANGE_CHANNEL).getId(); } @Subscribe @@ -95,8 +96,9 @@ public class PluginMessageListener { String playerName = changeMessage.getPlayerName(); boolean isSourceInvoker = changeMessage.isSourceInvoker(); if (changeMessage.shouldEnable()) { - if (playerName.equals(forPlayer.getUsername()) && plugin.getCore().getConfig().get("premium-warning", true) - && !core.getPendingConfirms().contains(forPlayer.getUniqueId())) { + Boolean premiumWarning = plugin.getCore().getConfig().get("premium-warning", true); + if (playerName.equals(forPlayer.getUsername()) && premiumWarning + && !core.getPendingConfirms().contains(forPlayer.getUniqueId())) { String message = core.getMessage("premium-warning"); forPlayer.sendMessage(LegacyComponentSerializer.legacyAmpersand().deserialize(message)); core.getPendingConfirms().add(forPlayer.getUniqueId()); @@ -114,7 +116,7 @@ public class PluginMessageListener { } private void onSuccessMessage(Player forPlayer) { - if (forPlayer.isOnlineMode()){ + if (forPlayer.isOnlineMode()) { //bukkit module successfully received and force logged in the user //update only on success to prevent corrupt data VelocityLoginSession loginSession = plugin.getSession().get(forPlayer.getRemoteAddress()); diff --git a/velocity/src/main/java/com/github/games647/fastlogin/velocity/task/AsyncPremiumCheck.java b/velocity/src/main/java/com/github/games647/fastlogin/velocity/task/AsyncPremiumCheck.java index 20204028..46f64261 100644 --- a/velocity/src/main/java/com/github/games647/fastlogin/velocity/task/AsyncPremiumCheck.java +++ b/velocity/src/main/java/com/github/games647/fastlogin/velocity/task/AsyncPremiumCheck.java @@ -49,7 +49,8 @@ public class AsyncPremiumCheck extends JoinManagement core, - CommandSource sender, String playerName, boolean toPremium, boolean playerSender) { + CommandSource sender, String playerName, boolean toPremium, boolean playerSender) { this.core = core; this.sender = sender; this.targetPlayer = playerName; this.toPremium = toPremium; this.isPlayerSender = playerSender; - if (sender instanceof Player) + if (sender instanceof Player) { senderName = ((Player) sender).getUsername(); - else + } else { senderName = ""; + } } @Override @@ -77,10 +79,10 @@ public class AsyncToggleMessage implements Runnable { playerProfile.setPremium(false); playerProfile.setId(null); core.getStorage().save(playerProfile); - PremiumToggleReason reason = (!isPlayerSender || !senderName.equalsIgnoreCase(playerProfile.getName())) ? - PremiumToggleReason.COMMAND_OTHER : PremiumToggleReason.COMMAND_SELF; + PremiumToggleReason reason = (!isPlayerSender || !senderName.equalsIgnoreCase(playerProfile.getName())) + ? PremiumToggleReason.COMMAND_OTHER : PremiumToggleReason.COMMAND_SELF; core.getPlugin().getProxy().getEventManager().fire( - new VelocityFastLoginPremiumToggleEvent(playerProfile, reason)); + new VelocityFastLoginPremiumToggleEvent(playerProfile, reason)); sendMessage("remove-premium"); } @@ -93,10 +95,11 @@ public class AsyncToggleMessage implements Runnable { playerProfile.setPremium(true); core.getStorage().save(playerProfile); - PremiumToggleReason reason = (!isPlayerSender || !senderName.equalsIgnoreCase(playerProfile.getName())) ? - PremiumToggleReason.COMMAND_OTHER : PremiumToggleReason.COMMAND_SELF; + PremiumToggleReason reason = (!isPlayerSender || !senderName.equalsIgnoreCase(playerProfile.getName())) + ? + PremiumToggleReason.COMMAND_OTHER : PremiumToggleReason.COMMAND_SELF; core.getPlugin().getProxy().getEventManager().fire( - new VelocityFastLoginPremiumToggleEvent(playerProfile, reason)); + new VelocityFastLoginPremiumToggleEvent(playerProfile, reason)); sendMessage("add-premium"); } @@ -105,7 +108,8 @@ public class AsyncToggleMessage implements Runnable { if (isPlayerSender) { sender.sendMessage(LegacyComponentSerializer.legacyAmpersand().deserialize(message)); } else { - core.getPlugin().getProxy().getConsoleCommandSource().sendMessage(LegacyComponentSerializer.legacyAmpersand().deserialize(message)); + ConsoleCommandSource console = core.getPlugin().getProxy().getConsoleCommandSource(); + console.sendMessage(LegacyComponentSerializer.legacyAmpersand().deserialize(message)); } } } diff --git a/velocity/src/main/java/com/github/games647/fastlogin/velocity/task/ForceLoginTask.java b/velocity/src/main/java/com/github/games647/fastlogin/velocity/task/ForceLoginTask.java index 849f53d4..da3ea231 100644 --- a/velocity/src/main/java/com/github/games647/fastlogin/velocity/task/ForceLoginTask.java +++ b/velocity/src/main/java/com/github/games647/fastlogin/velocity/task/ForceLoginTask.java @@ -52,7 +52,8 @@ public class ForceLoginTask private final boolean forcedOnlineMode; public ForceLoginTask(FastLoginCore core, - Player player, RegisteredServer server, VelocityLoginSession session, boolean forcedOnlineMode) { + Player player, RegisteredServer server, VelocityLoginSession session, + boolean forcedOnlineMode) { super(core, player, session); this.server = server;