forked from ChomeNS/chomens-bot-java
add list
This commit is contained in:
parent
14b2b53682
commit
b2fccdd28d
3 changed files with 95 additions and 1 deletions
|
@ -0,0 +1,92 @@
|
|||
package me.chayapak1.chomens_bot.commands;
|
||||
|
||||
import me.chayapak1.chomens_bot.Bot;
|
||||
import me.chayapak1.chomens_bot.chatParsers.data.MutablePlayerListEntry;
|
||||
import me.chayapak1.chomens_bot.command.Command;
|
||||
import me.chayapak1.chomens_bot.command.CommandContext;
|
||||
import net.kyori.adventure.text.Component;
|
||||
import net.kyori.adventure.text.JoinConfiguration;
|
||||
import net.kyori.adventure.text.event.ClickEvent;
|
||||
import net.kyori.adventure.text.event.HoverEvent;
|
||||
import net.kyori.adventure.text.format.NamedTextColor;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
public class ListCommand implements Command {
|
||||
public String name() { return "list"; }
|
||||
|
||||
public String description() {
|
||||
return "Lists all players in the server (including vanished)";
|
||||
}
|
||||
|
||||
public List<String> usage() {
|
||||
final List<String> usages = new ArrayList<>();
|
||||
usages.add("");
|
||||
|
||||
return usages;
|
||||
}
|
||||
|
||||
public List<String> alias() {
|
||||
final List<String> aliases = new ArrayList<>();
|
||||
aliases.add("");
|
||||
|
||||
return aliases;
|
||||
}
|
||||
|
||||
public int trustLevel() {
|
||||
return 0;
|
||||
}
|
||||
|
||||
public Component execute(CommandContext context, String[] args, String[] fullArgs) {
|
||||
final Bot bot = context.bot();
|
||||
|
||||
final List<MutablePlayerListEntry> list = bot.players().list();
|
||||
|
||||
final List<Component> playersComponent = new ArrayList<>();
|
||||
|
||||
for (MutablePlayerListEntry entry : list) {
|
||||
playersComponent.add(
|
||||
Component.translatable(
|
||||
"%s › %s",
|
||||
Component
|
||||
.text(entry.profile().getName())
|
||||
.hoverEvent(
|
||||
HoverEvent.showText(
|
||||
Component.text("Click here to copy the username to your clipboard").color(NamedTextColor.GREEN)
|
||||
)
|
||||
)
|
||||
.clickEvent(
|
||||
ClickEvent.copyToClipboard(entry.profile().getName())
|
||||
)
|
||||
.color(NamedTextColor.YELLOW),
|
||||
Component
|
||||
.text(entry.profile().getIdAsString())
|
||||
.hoverEvent(
|
||||
HoverEvent.showText(
|
||||
Component.text("Click here to copy the UUID to your clipboard").color(NamedTextColor.GREEN)
|
||||
)
|
||||
)
|
||||
.clickEvent(
|
||||
ClickEvent.copyToClipboard(entry.profile().getIdAsString())
|
||||
)
|
||||
.color(NamedTextColor.AQUA)
|
||||
).color(NamedTextColor.DARK_GRAY)
|
||||
);
|
||||
}
|
||||
|
||||
final Component component = Component.empty()
|
||||
.append(Component.text("Players ").color(NamedTextColor.GREEN))
|
||||
.append(Component.text("(").color(NamedTextColor.DARK_GRAY))
|
||||
.append(Component.text(list.size()).color(NamedTextColor.GRAY))
|
||||
.append(Component.text(")").color(NamedTextColor.DARK_GRAY))
|
||||
.append(Component.newline())
|
||||
.append(
|
||||
Component.join(JoinConfiguration.newlines(), playersComponent)
|
||||
);
|
||||
|
||||
context.sendOutput(component);
|
||||
|
||||
return Component.text("success");
|
||||
}
|
||||
}
|
|
@ -36,6 +36,7 @@ public class CommandHandlerPlugin {
|
|||
registerCommand(new WikipediaCommand());
|
||||
registerCommand(new UrbanCommand());
|
||||
registerCommand(new ClearChatCommand());
|
||||
registerCommand(new ListCommand());
|
||||
}
|
||||
|
||||
public void registerCommand (Command command) {
|
||||
|
|
|
@ -6,6 +6,7 @@ import com.github.steveice10.mc.protocol.packet.ingame.clientbound.ClientboundPl
|
|||
import com.github.steveice10.packetlib.Session;
|
||||
import com.github.steveice10.packetlib.event.session.SessionAdapter;
|
||||
import com.github.steveice10.packetlib.packet.Packet;
|
||||
import lombok.Getter;
|
||||
import me.chayapak1.chomens_bot.Bot;
|
||||
import me.chayapak1.chomens_bot.chatParsers.data.MutablePlayerListEntry;
|
||||
import net.kyori.adventure.text.Component;
|
||||
|
@ -16,7 +17,7 @@ import java.util.UUID;
|
|||
|
||||
public class PlayersPlugin extends SessionAdapter {
|
||||
private final Bot bot;
|
||||
public List<MutablePlayerListEntry> list = new ArrayList<>();
|
||||
@Getter private List<MutablePlayerListEntry> list = new ArrayList<>();
|
||||
|
||||
public PlayersPlugin (Bot bot) {
|
||||
this.bot = bot;
|
||||
|
|
Loading…
Reference in a new issue