From dde6a3cece4e4822f612eb02a89bdf025e568d0b Mon Sep 17 00:00:00 2001 From: okx-code Date: Tue, 19 Mar 2024 22:53:31 +0000 Subject: [PATCH] cleanup code --- .../mc/civmodcore/CivModCorePlugin.java | 2 +- .../mc/civmodcore/players/PlayerNames.java | 35 +++++++++---------- 2 files changed, 17 insertions(+), 20 deletions(-) diff --git a/plugins/civmodcore-paper/src/main/java/vg/civcraft/mc/civmodcore/CivModCorePlugin.java b/plugins/civmodcore-paper/src/main/java/vg/civcraft/mc/civmodcore/CivModCorePlugin.java index 992c5bd35..0aab7bd5f 100644 --- a/plugins/civmodcore-paper/src/main/java/vg/civcraft/mc/civmodcore/CivModCorePlugin.java +++ b/plugins/civmodcore-paper/src/main/java/vg/civcraft/mc/civmodcore/CivModCorePlugin.java @@ -89,7 +89,7 @@ public class CivModCorePlugin extends ACivMod { registerListener(DialogManager.INSTANCE); registerListener(new ScoreBoardListener()); registerListener(new WorldTracker()); - registerListener(PlayerNames.init()); + registerListener(new PlayerNames()); // Register commands this.commands = new CommandManager(this); this.commands.init(); diff --git a/plugins/civmodcore-paper/src/main/java/vg/civcraft/mc/civmodcore/players/PlayerNames.java b/plugins/civmodcore-paper/src/main/java/vg/civcraft/mc/civmodcore/players/PlayerNames.java index 689904a43..99dc6af16 100644 --- a/plugins/civmodcore-paper/src/main/java/vg/civcraft/mc/civmodcore/players/PlayerNames.java +++ b/plugins/civmodcore-paper/src/main/java/vg/civcraft/mc/civmodcore/players/PlayerNames.java @@ -15,34 +15,31 @@ import org.bukkit.event.player.PlayerLoginEvent; import org.jetbrains.annotations.ApiStatus; import org.jetbrains.annotations.NotNull; -public final class PlayerNames { - private static final Set names = Collections.synchronizedSet(new HashSet<>()); +public final class PlayerNames implements Listener { - @ApiStatus.Internal - public static @NotNull Listener init() { + private static final Set names = new HashSet<>(); + + public PlayerNames() { + names.clear(); names.addAll( Stream.of(Bukkit.getOfflinePlayers()) .map(OfflinePlayer::getName) .filter(StringUtils::isNotBlank) .toList() ); - return new Listener() { - @EventHandler( - priority = EventPriority.MONITOR, // Make sure it happens after NameLayer's AssociationListener - ignoreCancelled = true - ) - private void onLogin( - final @NotNull PlayerLoginEvent event - ) { - names.add(event.getPlayer().getName()); - } - }; } - /** - * Retrieves a copy of all known player names. - */ + @EventHandler( + priority = EventPriority.MONITOR, // Make sure it happens after NameLayer's AssociationListener + ignoreCancelled = true + ) + private void onLogin( + final @NotNull PlayerLoginEvent event + ) { + names.add(event.getPlayer().getName()); + } + public static @NotNull Collection getPlayerNames() { - return Set.of(names.toArray(String[]::new)); + return Collections.unmodifiableSet(names); } }