Compare commits
2 Commits
416c44a8f3
...
d412812dcb
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
d412812dcb | ||
|
|
21f12904ac |
|
|
@ -39,7 +39,8 @@ public class BaseCommand implements CommandExecutor, TabExecutor {
|
||||||
new NextPhase(round),
|
new NextPhase(round),
|
||||||
new EndRound(round),
|
new EndRound(round),
|
||||||
new Stuck(main),
|
new Stuck(main),
|
||||||
new Stats(statService)
|
new Stats(statService),
|
||||||
|
new ListPlayers(roundService)
|
||||||
));
|
));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -0,0 +1,71 @@
|
||||||
|
package com.alttd.hunger_games.commands.subcommands;
|
||||||
|
|
||||||
|
import com.alttd.hunger_games.commands.SubCommand;
|
||||||
|
import com.alttd.hunger_games.config.Messages;
|
||||||
|
import com.alttd.hunger_games.data_objects.PLAYER_STATE;
|
||||||
|
import com.alttd.hunger_games.services.RoundService;
|
||||||
|
import net.kyori.adventure.text.Component;
|
||||||
|
import net.kyori.adventure.text.JoinConfiguration;
|
||||||
|
import net.kyori.adventure.text.minimessage.tag.resolver.Placeholder;
|
||||||
|
import org.bukkit.Bukkit;
|
||||||
|
import org.bukkit.command.CommandSender;
|
||||||
|
import org.bukkit.entity.Player;
|
||||||
|
|
||||||
|
import java.util.*;
|
||||||
|
|
||||||
|
public class ListPlayers extends SubCommand {
|
||||||
|
|
||||||
|
private final RoundService roundService;
|
||||||
|
|
||||||
|
public ListPlayers(RoundService roundService) {
|
||||||
|
this.roundService = roundService;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean onCommand(CommandSender commandSender, String[] args) {
|
||||||
|
Set<UUID> registeredUuids = roundService.getPlayers(PLAYER_STATE.REGISTERED);
|
||||||
|
Set<UUID> spectatingUuids = roundService.getPlayers(PLAYER_STATE.SPECTATING);
|
||||||
|
|
||||||
|
List<Component> registeredNames = registeredUuids.stream()
|
||||||
|
.map(Bukkit::getPlayer)
|
||||||
|
.filter(Objects::nonNull)
|
||||||
|
.map(Player::name)
|
||||||
|
.toList();
|
||||||
|
|
||||||
|
List<Component> spectatingNames = spectatingUuids.stream()
|
||||||
|
.map(Bukkit::getPlayer)
|
||||||
|
.filter(Objects::nonNull)
|
||||||
|
.map(Player::name)
|
||||||
|
.toList();
|
||||||
|
|
||||||
|
Component inGamePlayers = Component.join(JoinConfiguration.commas(true), registeredNames);
|
||||||
|
Component spectators = Component.join(JoinConfiguration.commas(true), spectatingNames);
|
||||||
|
|
||||||
|
int inGameCount = registeredNames.size();
|
||||||
|
int totalCount = inGameCount + spectatingNames.size();
|
||||||
|
|
||||||
|
commandSender.sendRichMessage(Messages.COMMANDS.LIST_PLAYERS,
|
||||||
|
Placeholder.unparsed("in_game", String.valueOf(inGameCount)),
|
||||||
|
Placeholder.unparsed("total", String.valueOf(totalCount)),
|
||||||
|
Placeholder.component("in_game_players", inGamePlayers),
|
||||||
|
Placeholder.component("spectators", spectators)
|
||||||
|
);
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String getName() {
|
||||||
|
return "list";
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public List<String> getTabComplete(CommandSender commandSender, String[] args) {
|
||||||
|
return Collections.emptyList();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String getHelpMessage() {
|
||||||
|
return Messages.HELP.LIST;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
@ -33,6 +33,7 @@ public class Messages extends AbstractConfig {
|
||||||
public static String RELOAD = "<green>Reload config and messages: <gold>/hg reload</gold></green>";
|
public static String RELOAD = "<green>Reload config and messages: <gold>/hg reload</gold></green>";
|
||||||
public static String STUCK = "<green>Teleport to safety if stuck: <gold>/hg stuck</gold></green>";
|
public static String STUCK = "<green>Teleport to safety if stuck: <gold>/hg stuck</gold></green>";
|
||||||
public static String STATS = "<green>Show player stats: <gold>/hg stats [player]</gold></green>";
|
public static String STATS = "<green>Show player stats: <gold>/hg stats [player]</gold></green>";
|
||||||
|
public static String LIST = "<green>List all players in the game and spectators: <gold>/hg list</gold></green>";
|
||||||
public static String END_ROUND = "<green>End the game: <gold>/hg end</gold></green>";
|
public static String END_ROUND = "<green>End the game: <gold>/hg end</gold></green>";
|
||||||
|
|
||||||
@SuppressWarnings("unused")
|
@SuppressWarnings("unused")
|
||||||
|
|
@ -46,6 +47,7 @@ public class Messages extends AbstractConfig {
|
||||||
RELOAD = config.getString(prefix, "reload", RELOAD);
|
RELOAD = config.getString(prefix, "reload", RELOAD);
|
||||||
STUCK = config.getString(prefix, "stuck", STUCK);
|
STUCK = config.getString(prefix, "stuck", STUCK);
|
||||||
STATS = config.getString(prefix, "stats", STATS);
|
STATS = config.getString(prefix, "stats", STATS);
|
||||||
|
LIST = config.getString(prefix, "list", LIST);
|
||||||
END_ROUND = config.getString(prefix, "end-round", END_ROUND);
|
END_ROUND = config.getString(prefix, "end-round", END_ROUND);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -210,10 +212,15 @@ public class Messages extends AbstractConfig {
|
||||||
private static final String prefix = "commands.";
|
private static final String prefix = "commands.";
|
||||||
|
|
||||||
public static String NEXT_PHASE_SUCCESS = "<green>Skipping to the next phase/stage.</green>";
|
public static String NEXT_PHASE_SUCCESS = "<green>Skipping to the next phase/stage.</green>";
|
||||||
|
public static String LIST_PLAYERS = """
|
||||||
|
<gold>HungerGames Players (<in_game>/<total>):</gold>
|
||||||
|
<green>In Game: <white><in_game_players></white></green>
|
||||||
|
<yellow>Spectators: <white><spectators></white></yellow>""";
|
||||||
|
|
||||||
@SuppressWarnings("unused")
|
@SuppressWarnings("unused")
|
||||||
private static void load() {
|
private static void load() {
|
||||||
NEXT_PHASE_SUCCESS = config.getString(prefix + "next-phase", "success", NEXT_PHASE_SUCCESS);
|
NEXT_PHASE_SUCCESS = config.getString(prefix + "next-phase", "success", NEXT_PHASE_SUCCESS);
|
||||||
|
LIST_PLAYERS = config.getString(prefix, "list-players", LIST_PLAYERS);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -45,7 +45,7 @@ public class StatService implements RoundListener {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void stateChange(ROUND_STATE roundState) {
|
public void stateChange(ROUND_STATE roundState) {
|
||||||
if (roundState.equals(ROUND_STATE.FINALE)) {
|
if (roundState.equals(ROUND_STATE.ENDED)) {
|
||||||
saveRoundStats();
|
saveRoundStats();
|
||||||
}
|
}
|
||||||
if (roundState.equals(ROUND_STATE.PLAYER_REGISTRATION)) {
|
if (roundState.equals(ROUND_STATE.PLAYER_REGISTRATION)) {
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue
Block a user