From 19616aef841deff5c1a11bf1724e6c84174ca2e2 Mon Sep 17 00:00:00 2001 From: yoyosource Date: Wed, 15 Jun 2022 20:04:43 +0200 Subject: [PATCH] Update KickCommand --- .../bungeecore/commands/KickCommand.java | 38 ++++++++----------- 1 file changed, 15 insertions(+), 23 deletions(-) diff --git a/src/de/steamwar/bungeecore/commands/KickCommand.java b/src/de/steamwar/bungeecore/commands/KickCommand.java index cb27fab..54a2e49 100644 --- a/src/de/steamwar/bungeecore/commands/KickCommand.java +++ b/src/de/steamwar/bungeecore/commands/KickCommand.java @@ -21,48 +21,40 @@ package de.steamwar.bungeecore.commands; import de.steamwar.bungeecore.BungeeCore; import de.steamwar.bungeecore.Message; +import de.steamwar.command.SWCommand; +import de.steamwar.command.SWCommandUtils; +import de.steamwar.command.TypeMapper; +import net.md_5.bungee.BungeeCord; import net.md_5.bungee.api.CommandSender; import net.md_5.bungee.api.ProxyServer; import net.md_5.bungee.api.connection.ProxiedPlayer; -import java.util.ArrayList; +import java.util.stream.Collectors; -public class KickCommand extends BasicCommand { +public class KickCommand extends SWCommand { public KickCommand() { super("kick", "bungeecore.kick"); } - @Override - public void execute(CommandSender sender, String[] args) { - if(args.length == 0){ - Message.send("KICK_USAGE", sender); - return; - } - - ProxiedPlayer target = ProxyServer.getInstance().getPlayer(args[0]); + @Register(description = "KICK_USAGE") + public void genericCommand(CommandSender sender, @Mapper("player") String player, String... message) { + ProxiedPlayer target = ProxyServer.getInstance().getPlayer(player); if(target == null){ Message.send("KICK_OFFLINE", sender); return; } - if(args.length == 1){ + if (message.length == 0) { target.disconnect(Message.parseToComponent("KICK_NORMAL", true, target)); - }else{ - StringBuilder msgBuilder = new StringBuilder(); - msgBuilder.append(BungeeCore.CHAT_PREFIX).append("§c"); - for (int i = 1; i < args.length; i++){ - msgBuilder.append(args[i]).append(" "); - } - target.disconnect(BungeeCore.stringToText(msgBuilder.toString())); + } else { + target.disconnect(BungeeCore.stringToText(BungeeCore.CHAT_PREFIX + "§c" + String.join(" ", message))); } Message.send("KICK_CONFIRM", sender, target.getName()); } - @Override - public Iterable onTabComplete(CommandSender commandSender, String[] args) { - if(args.length == 1) - return allPlayers(args[0]); - return new ArrayList<>(); + @Mapper(value = "player", local = true) + public TypeMapper playerTypeMapper() { + return SWCommandUtils.createMapper(s -> s, s -> BungeeCord.getInstance().getPlayers().stream().map(ProxiedPlayer::getName).collect(Collectors.toList())); } }