Fix code formatting according to checkstyle config

This commit is contained in:
games647 committed 2022-07-11 12:14:31 +02:00
1 parent cf53ecacdf
commit 752600f0e2
44 files changed
+274 -203

No files matched your search

@@ -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 = '§';
@@ -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();
}
}
@@ -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<Verification> 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.
* <p>
* 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<Verification> 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);
}
}
@@ -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;
@@ -74,12 +74,12 @@ public abstract class BedrockService<B> {
"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()) {
@@ -60,12 +60,16 @@ public class FloodgateService extends BedrockService<FloodgatePlayer> {
*/
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<FloodgatePlayer> {
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);
}
@@ -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
+ '}';
}
}
@@ -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 {
@@ -122,7 +122,8 @@ public class FastLoginCore<P extends C, C, T extends PlatformPlugin<C>> {
}
// 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<Proxy> proxies = config.getStringList("proxies")
@@ -191,7 +192,7 @@ public class FastLoginCore<P extends C, C, T extends PlatformPlugin<C>> {
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<P extends C, C, T extends PlatformPlugin<C>> {
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<P extends C, C, T extends PlatformPlugin<C>> {
} 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;
@@ -106,9 +106,9 @@ public abstract class JoinManagement<P extends C, C, S extends LoginSource> {
}
}
} 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);
@@ -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));