Minor clean up

This commit is contained in:
games647 committed 2024-05-21 15:09:28 +02:00
1 parent f50004f50d
commit 6005f0db44
21 files changed
+52 -52

No files matched your search

+1 -1
View File
@@ -125,7 +125,7 @@
<dependency>
<groupId>com.zaxxer</groupId>
<artifactId>HikariCP</artifactId>
<version>4.0.3</version>
<version>5.1.0</version>
<exclusions>
<!-- HikariCP uses an old version of this API that has a typo in the service interface -->
<!-- We will use the api provided by the jdk14 dependency -->
@@ -26,7 +26,7 @@
package com.github.games647.fastlogin.core.hooks;
import java.security.SecureRandom;
import java.util.Random;
import java.util.random.RandomGenerator;
import java.util.stream.IntStream;
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"
.toCharArray();
private final Random random = new SecureRandom();
private final RandomGenerator random = new SecureRandom();
@Override
public String getRandomPassword(P player) {
@@ -59,16 +59,13 @@ public class FloodgateService extends BedrockService<FloodgatePlayer> {
*/
public boolean isValidFloodgateConfigString(String key) {
String value = core.getConfig().get(key).toString().toLowerCase(Locale.ENGLISH);
switch (value) {
case "true":
case "linked":
case "false":
case "no-conflict":
return true;
default:
return switch (value) {
case "true", "linked", "false", "no-conflict" -> true;
default -> {
core.getPlugin().getLog().error("Invalid value detected for {} in FastLogin/config.yml.", key);
return false;
}
yield false;
}
};
}
@Override
@@ -163,12 +163,12 @@ public class FastLoginCore<P extends C, C, T extends PlatformPlugin<C>> {
Action action = Action.Ignore;
switch (botSection.getString("action", "ignore")) {
case "ignore":
action = Action.Ignore;
break;
case "block":
action = Action.Block;
break;
case "ignore":
action = Action.Ignore;
break;
default:
plugin.getLog().warn("Invalid anti bot action - defaulting to ignore");
}
@@ -70,17 +70,12 @@ public enum FloodgateState {
*/
public static FloodgateState fromInt(int num) {
// using Enum.values()[i] is expensive as per https://stackoverflow.com/a/8762387/9767089
switch (num) {
case 0:
return FloodgateState.FALSE;
case 1:
return FloodgateState.TRUE;
case 2:
return FloodgateState.LINKED;
case 3:
return FloodgateState.NOT_MIGRATED;
default:
return null;
}
return switch (num) {
case 0 -> FloodgateState.FALSE;
case 1 -> FloodgateState.TRUE;
case 2 -> FloodgateState.LINKED;
case 3 -> FloodgateState.NOT_MIGRATED;
default -> null;
};
}
}
@@ -109,7 +109,7 @@ public abstract class JoinManagement<P extends C, C, S extends LoginSource> {
premiumUUID = core.getResolver().findProfile(username);
}
if (!premiumUUID.isPresent()
if (premiumUUID.isEmpty()
|| (!isNameChanged(source, username, premiumUUID.get())
&& !isUsernameAvailable(source, username, profile))) {
//nothing detected the player as premium -> start a cracked session
@@ -29,7 +29,7 @@ import java.net.InetSocketAddress;
public interface LoginSource {
void enableOnlinemode() throws Exception;
void enableOnlinemode();
void kick(String message);
@@ -32,9 +32,12 @@ import org.slf4j.Logger;
import java.nio.file.Path;
import java.util.concurrent.ThreadFactory;
import java.util.regex.Pattern;
public interface PlatformPlugin<C> {
Pattern PATTERN = Pattern.compile("%nl%");
String getName();
Path getPluginFolder();
@@ -48,7 +51,7 @@ public interface PlatformPlugin<C> {
boolean isPluginInstalled(String name);
default void sendMultiLineMessage(C receiver, String message) {
for (String line : message.split("%nl%")) {
for (String line : PATTERN.split(message)) {
sendMessage(receiver, line);
}
}
@@ -168,11 +168,10 @@ public class StoredProfile extends Profile {
return true;
}
if (!(o instanceof StoredProfile)) {
if (!(o instanceof StoredProfile that)) {
return false;
}
StoredProfile that = (StoredProfile) o;
if (!super.equals(o)) {
return false;
}
@@ -27,13 +27,13 @@ package com.github.games647.fastlogin.core.hooks;
import org.junit.jupiter.api.Test;
import static org.junit.jupiter.api.Assertions.assertTrue;
import static org.junit.jupiter.api.Assertions.assertEquals;
class DefaultPasswordGeneratorTest {
@Test
void smokeTestPassword() {
PasswordGenerator<?> passwordGenerator = new DefaultPasswordGenerator<>();
assertTrue(passwordGenerator.getRandomPassword(null).length() == 8);
assertEquals(8, passwordGenerator.getRandomPassword(null).length());
}
}