mirror of
https://github.com/CivMC/Civ.git
synced 2026-07-18 00:20:44 +00:00
cleanup code
This commit is contained in:
@@ -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();
|
||||
|
||||
@@ -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<String> names = Collections.synchronizedSet(new HashSet<>());
|
||||
public final class PlayerNames implements Listener {
|
||||
|
||||
@ApiStatus.Internal
|
||||
public static @NotNull Listener init() {
|
||||
private static final Set<String> 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<String> getPlayerNames() {
|
||||
return Set.of(names.toArray(String[]::new));
|
||||
return Collections.unmodifiableSet(names);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user