Restore older Java compatibility

This commit is contained in:
games647
2024-05-21 17:00:04 +02:00
parent d04e421927
commit 7a8e5a59d0
6 changed files with 30 additions and 22 deletions

View File

@ -116,7 +116,7 @@ final class EncryptionUtil {
* @param random random generator * @param random random generator
* @return a token with 4 bytes long * @return a token with 4 bytes long
*/ */
public static byte[] generateVerifyToken(RandomGenerator random) { public static byte[] generateVerifyToken(Random random) {
byte[] token = new byte[VERIFY_TOKEN_LENGTH]; byte[] token = new byte[VERIFY_TOKEN_LENGTH];
random.nextBytes(token); random.nextBytes(token);
return token; return token;

View File

@ -26,7 +26,7 @@
package com.github.games647.fastlogin.core.hooks; package com.github.games647.fastlogin.core.hooks;
import java.security.SecureRandom; import java.security.SecureRandom;
import java.util.random.RandomGenerator; import java.util.Random;
import java.util.stream.IntStream; import java.util.stream.IntStream;
public class DefaultPasswordGenerator<P> implements PasswordGenerator<P> { public class DefaultPasswordGenerator<P> implements PasswordGenerator<P> {
@ -35,7 +35,7 @@ public class DefaultPasswordGenerator<P> implements PasswordGenerator<P> {
private static final char[] PASSWORD_CHARACTERS = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789" private static final char[] PASSWORD_CHARACTERS = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789"
.toCharArray(); .toCharArray();
private final RandomGenerator random = new SecureRandom(); private final Random random = new SecureRandom();
@Override @Override
public String getRandomPassword(P player) { public String getRandomPassword(P player) {

View File

@ -59,13 +59,16 @@ public class FloodgateService extends BedrockService<FloodgatePlayer> {
*/ */
public boolean isValidFloodgateConfigString(String key) { public boolean isValidFloodgateConfigString(String key) {
String value = core.getConfig().get(key).toString().toLowerCase(Locale.ENGLISH); String value = core.getConfig().get(key).toString().toLowerCase(Locale.ENGLISH);
return switch (value) { switch (value) {
case "true", "linked", "false", "no-conflict" -> true; case "true":
default -> { case "linked":
case "false":
case "no-conflict":
return true;
default:
core.getPlugin().getLog().error("Invalid value detected for {} in FastLogin/config.yml.", key); core.getPlugin().getLog().error("Invalid value detected for {} in FastLogin/config.yml.", key);
yield false; return false;
} }
};
} }
@Override @Override

View File

@ -70,12 +70,17 @@ public enum FloodgateState {
*/ */
public static FloodgateState fromInt(int num) { public static FloodgateState fromInt(int num) {
// using Enum.values()[i] is expensive as per https://stackoverflow.com/a/8762387/9767089 // using Enum.values()[i] is expensive as per https://stackoverflow.com/a/8762387/9767089
return switch (num) { switch (num) {
case 0 -> FloodgateState.FALSE; case 0:
case 1 -> FloodgateState.TRUE; return FloodgateState.FALSE;
case 2 -> FloodgateState.LINKED; case 1:
case 3 -> FloodgateState.NOT_MIGRATED; return FloodgateState.TRUE;
default -> null; case 2:
}; return FloodgateState.LINKED;
case 3:
return FloodgateState.NOT_MIGRATED;
default:
return null;
}
} }
} }

View File

@ -109,7 +109,7 @@ public abstract class JoinManagement<P extends C, C, S extends LoginSource> {
premiumUUID = core.getResolver().findProfile(username); premiumUUID = core.getResolver().findProfile(username);
} }
if (premiumUUID.isEmpty() if (premiumUUID.isPresent()
|| (!isNameChanged(source, username, premiumUUID.get()) || (!isNameChanged(source, username, premiumUUID.get())
&& !isUsernameAvailable(source, username, profile))) { && !isUsernameAvailable(source, username, profile))) {
//nothing detected the player as premium -> start a cracked session //nothing detected the player as premium -> start a cracked session

View File

@ -163,16 +163,16 @@ public class StoredProfile extends Profile {
} }
@Override @Override
public synchronized boolean equals(Object o) { public synchronized boolean equals(Object other) {
if (this == o) { if (this == other) {
return true; return true;
} }
if (!(o instanceof StoredProfile that)) { if (!(other instanceof StoredProfile)) {
return false; return false;
} }
StoredProfile that = (StoredProfile) other;
if (!super.equals(o)) { if (!super.equals(other)) {
return false; return false;
} }