diff --git a/core/src/main/java/me/xneox/epicguard/core/command/CommandHandler.java b/core/src/main/java/me/xneox/epicguard/core/command/CommandHandler.java index bd3c33e2..2b2c30a5 100644 --- a/core/src/main/java/me/xneox/epicguard/core/command/CommandHandler.java +++ b/core/src/main/java/me/xneox/epicguard/core/command/CommandHandler.java @@ -34,6 +34,7 @@ /** * This class holds all registered subcommands, and handles the user command/tab suggestion input. + * TODO: Better command system */ public class CommandHandler { private final Map commandMap = new HashMap<>(); diff --git a/core/src/main/java/me/xneox/epicguard/core/handler/PostLoginHandler.java b/core/src/main/java/me/xneox/epicguard/core/handler/PostLoginHandler.java index 3fcdbce9..5f0174f1 100644 --- a/core/src/main/java/me/xneox/epicguard/core/handler/PostLoginHandler.java +++ b/core/src/main/java/me/xneox/epicguard/core/handler/PostLoginHandler.java @@ -40,11 +40,10 @@ public PostLoginHandler(EpicGuard epicGuard) { * @param address Address of the online player. */ public void handle(@NotNull UUID uuid, @NotNull String address) { - OnlineUser user = this.epicGuard.userManager().getOrCreate(uuid); - // Schedule a delayed task to whitelist the player. if (this.epicGuard.config().autoWhitelist().enabled()) { this.epicGuard.platform().runTaskLater(() -> { + OnlineUser user = this.epicGuard.userManager().get(uuid); if (user != null) { // check if player has logged out AddressMeta meta = this.epicGuard.storageManager().addressMeta(address); meta.whitelisted(true); @@ -55,6 +54,7 @@ public void handle(@NotNull UUID uuid, @NotNull String address) { // Schedule a delayed task to check if the player has sent the Settings packet. if (this.epicGuard.config().settingsCheck().enabled()) { this.epicGuard.platform().runTaskLater(() -> { + OnlineUser user = this.epicGuard.userManager().get(uuid); if (user != null && !user.settingsChanged()) { this.epicGuard.platform().disconnectUser(uuid, TextUtils.multilineComponent(this.epicGuard.messages().disconnect().settingsPacket())); } diff --git a/core/src/main/java/me/xneox/epicguard/core/manager/UserManager.java b/core/src/main/java/me/xneox/epicguard/core/manager/UserManager.java index 74add567..642989e3 100644 --- a/core/src/main/java/me/xneox/epicguard/core/manager/UserManager.java +++ b/core/src/main/java/me/xneox/epicguard/core/manager/UserManager.java @@ -20,6 +20,8 @@ import java.util.UUID; import java.util.concurrent.ConcurrentHashMap; import me.xneox.epicguard.core.user.OnlineUser; +import org.jetbrains.annotations.NotNull; +import org.jetbrains.annotations.Nullable; /** * This manager caches the {@link OnlineUser} for currently online players @@ -27,15 +29,30 @@ public class UserManager { private final Map userMap = new ConcurrentHashMap<>(); + @NotNull public Collection users() { return this.userMap.values(); } - public OnlineUser getOrCreate(UUID uuid) { + /** + * Returns the {@link OnlineUser} for the specified + * UUID. Creates a new object if absent. + */ + @NotNull + public OnlineUser getOrCreate(@NotNull UUID uuid) { return this.userMap.computeIfAbsent(uuid, OnlineUser::new); } - public void removeUser(UUID uuid) { + /** + * Returns the {@link OnlineUser} for the specified + * UUID, or null if the user is offline. + */ + @Nullable + public OnlineUser get(@NotNull UUID uuid) { + return this.userMap.get(uuid); + } + + public void removeUser(@NotNull UUID uuid) { this.userMap.remove(uuid); } } diff --git a/core/src/main/java/me/xneox/epicguard/core/user/OnlineUser.java b/core/src/main/java/me/xneox/epicguard/core/user/OnlineUser.java index e8d6273f..d171468a 100644 --- a/core/src/main/java/me/xneox/epicguard/core/user/OnlineUser.java +++ b/core/src/main/java/me/xneox/epicguard/core/user/OnlineUser.java @@ -27,7 +27,7 @@ public class OnlineUser { private boolean notifications; private boolean settingsChanged; - public OnlineUser(UUID uuid) { + public OnlineUser(@NotNull UUID uuid) { this.uuid = uuid; } diff --git a/core/src/main/java/me/xneox/epicguard/core/util/TextUtils.java b/core/src/main/java/me/xneox/epicguard/core/util/TextUtils.java index 0946cbbe..07576e53 100644 --- a/core/src/main/java/me/xneox/epicguard/core/util/TextUtils.java +++ b/core/src/main/java/me/xneox/epicguard/core/util/TextUtils.java @@ -40,7 +40,7 @@ public final class TextUtils { * @return a component created from the string */ @NotNull - public static TextComponent component(String message) { + public static TextComponent component(@NotNull String message) { return SERIALIZER.deserialize(message); } diff --git a/core/src/main/java/me/xneox/epicguard/core/util/ToggleState.java b/core/src/main/java/me/xneox/epicguard/core/util/ToggleState.java index 8c0cb753..75c6d206 100644 --- a/core/src/main/java/me/xneox/epicguard/core/util/ToggleState.java +++ b/core/src/main/java/me/xneox/epicguard/core/util/ToggleState.java @@ -20,8 +20,6 @@ /** * Determines when an {@link AbstractCheck} should be performed. * Can be configured in the config for some checks. - * - * TODO: This is also used for other things than checks, should be renamed */ public enum ToggleState { NEVER, diff --git a/core/src/main/java/me/xneox/epicguard/core/util/VersionUtils.java b/core/src/main/java/me/xneox/epicguard/core/util/VersionUtils.java index f4e893e1..0d29cb18 100644 --- a/core/src/main/java/me/xneox/epicguard/core/util/VersionUtils.java +++ b/core/src/main/java/me/xneox/epicguard/core/util/VersionUtils.java @@ -16,6 +16,7 @@ package me.xneox.epicguard.core.util; import java.util.function.Consumer; +import org.jetbrains.annotations.NotNull; /** * This util holds current EpicGuard version and checks for the latest available version. @@ -30,7 +31,7 @@ public final class VersionUtils { * * @param action Action to run when there's an update available. */ - public static void checkForUpdates(Consumer action) { + public static void checkForUpdates(@NotNull Consumer action) { String latest = URLUtils.readString(CHECK_URL); if (latest == null) { return; // a warning will be thrown by the URLUtils anyway. @@ -48,7 +49,7 @@ public static void checkForUpdates(Consumer action) { * @param version Version string, eg. "5.1.0" * @return an int version value, eg. "510" */ - private static int parse(String version) { + private static int parse(@NotNull String version) { return Integer.parseInt(version.replace(".", "")); } }