Skip to content
This repository has been archived by the owner on Apr 24, 2024. It is now read-only.

Commit

Permalink
More annotations, fix small bug in PostLoginHandler
Browse files Browse the repository at this point in the history
  • Loading branch information
awumii committed Oct 11, 2021
1 parent eaf0a46 commit 212ea3a
Show file tree
Hide file tree
Showing 7 changed files with 27 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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<String, SubCommand> commandMap = new HashMap<>();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -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()));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,22 +20,39 @@
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
*/
public class UserManager {
private final Map<UUID, OnlineUser> userMap = new ConcurrentHashMap<>();

@NotNull
public Collection<OnlineUser> 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);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand All @@ -30,7 +31,7 @@ public final class VersionUtils {
*
* @param action Action to run when there's an update available.
*/
public static void checkForUpdates(Consumer<String> action) {
public static void checkForUpdates(@NotNull Consumer<String> action) {
String latest = URLUtils.readString(CHECK_URL);
if (latest == null) {
return; // a warning will be thrown by the URLUtils anyway.
Expand All @@ -48,7 +49,7 @@ public static void checkForUpdates(Consumer<String> 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(".", ""));
}
}

0 comments on commit 212ea3a

Please sign in to comment.