From 4766e0ab961766d8d1ba909c1447c774673d106e Mon Sep 17 00:00:00 2001 From: yoyosource Date: Thu, 16 Jun 2022 12:21:46 +0200 Subject: [PATCH] Update WhoisCommand --- .../bungeecore/commands/WhoisCommand.java | 48 +++++++++---------- 1 file changed, 23 insertions(+), 25 deletions(-) diff --git a/src/de/steamwar/bungeecore/commands/WhoisCommand.java b/src/de/steamwar/bungeecore/commands/WhoisCommand.java index 1303059..e181572 100644 --- a/src/de/steamwar/bungeecore/commands/WhoisCommand.java +++ b/src/de/steamwar/bungeecore/commands/WhoisCommand.java @@ -23,6 +23,10 @@ import de.steamwar.bungeecore.Message; import de.steamwar.bungeecore.sql.Punishment; import de.steamwar.bungeecore.sql.SteamwarUser; import de.steamwar.bungeecore.sql.Team; +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.chat.ClickEvent; import net.md_5.bungee.api.connection.ProxiedPlayer; @@ -32,52 +36,46 @@ import java.text.DecimalFormat; import java.util.HashSet; import java.util.List; import java.util.Set; +import java.util.stream.Collectors; -public class WhoisCommand extends BasicCommand { - public WhoisCommand(){ +public class WhoisCommand extends SWCommand { + public WhoisCommand() { super("whois", "bungeecore.teamchat"); } - @Override - public void execute(CommandSender sender, String[] args) { - if(!(sender instanceof ProxiedPlayer)) - return; - ProxiedPlayer player = (ProxiedPlayer) sender; - - if(args.length == 0){ - Message.send("WHOIS_USAGE", player); - return; - } - - SteamwarUser user = SteamwarUser.get(args[0]); - if(user == null){ + @Register("WHOIS_USAGE") + public void genericCommand(ProxiedPlayer player, @Mapper("player") String target, @OptionalValue("") @StaticValue({"-all", "-a", ""}) String displayAll) { + SteamwarUser user = SteamwarUser.get(target); + if (user == null) { try { - int id = Integer.parseInt(args[0]); + int id = Integer.parseInt(target); user = SteamwarUser.get(id); - }catch (NumberFormatException ignored) {} + } catch (NumberFormatException ignored) { + } } if (user == null) { try { - long id = Long.parseLong(args[0]); + long id = Long.parseLong(target); user = SteamwarUser.get(id); } catch (NumberFormatException ignored) { // Ignored } } - if(user == null) { + if (user == null) { Message.send("UNKNOWN_PLAYER", player); return; } - boolean all = false; - if(args.length > 1 && args[1].startsWith("-")) { - all = args[1].contains("a"); - } - + boolean all = displayAll.contains("-"); sendUserinfo(player, user, all); } + @Mapper(value = "player", local = true) + public TypeMapper playerTypeMapper() { + return SWCommandUtils.createMapper(s -> s, s -> BungeeCord.getInstance().getPlayers().stream().map(ProxiedPlayer::getName).collect(Collectors.toList())); + } + private static void sendUserinfo(ProxiedPlayer player, SteamwarUser user, boolean all) { Message.send("WHOIS_USERNAME", player, user.getUserName()); Message.send("WHOIS_UUID", player, Message.parse("WHOIS_UUID_HOVER", player), new ClickEvent(ClickEvent.Action.COPY_TO_CLIPBOARD, user.getUuid().toString()), user.getUuid().toString()); @@ -86,7 +84,7 @@ public class WhoisCommand extends BasicCommand { Message.send("WHOIS_DISCORD_ID", player, user.getDiscordId()); } Timestamp firstJoin = user.getFirstjoin(); - if(firstJoin == null) + if (firstJoin == null) Message.send("WHOIS_JOINED_FIRST", player, "0000-00-00 00:00:00"); else Message.send("WHOIS_JOINED_FIRST", player, firstJoin.toString());