From 21f020e13d0111ca4363f93fd35137717fba84d6 Mon Sep 17 00:00:00 2001 From: yoyosource Date: Thu, 16 Jun 2022 11:08:12 +0200 Subject: [PATCH] Update RankCommand --- .../bungeecore/commands/RankCommand.java | 41 +++++++++++-------- 1 file changed, 25 insertions(+), 16 deletions(-) diff --git a/src/de/steamwar/bungeecore/commands/RankCommand.java b/src/de/steamwar/bungeecore/commands/RankCommand.java index f76932e0..eca55186 100644 --- a/src/de/steamwar/bungeecore/commands/RankCommand.java +++ b/src/de/steamwar/bungeecore/commands/RankCommand.java @@ -23,32 +23,36 @@ import de.steamwar.bungeecore.ArenaMode; import de.steamwar.bungeecore.Message; import de.steamwar.bungeecore.sql.SteamwarUser; import de.steamwar.bungeecore.sql.UserElo; +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.connection.ProxiedPlayer; import java.util.Optional; +import java.util.stream.Collectors; -public class RankCommand extends BasicCommand { +public class RankCommand extends SWCommand { public RankCommand() { - super("rank", null); + super("rank"); } - @Override - public void execute(CommandSender sender, String[] args) { - if(!(sender instanceof ProxiedPlayer)) - return; + @Register + public void ownRank(ProxiedPlayer player) { + rank(player, player.getName()); + } - ProxiedPlayer player = (ProxiedPlayer) sender; - SteamwarUser user = SteamwarUser.get(player.getUniqueId()); - if (args.length > 0) { - SteamwarUser nUser = SteamwarUser.get(args[0]); - if (nUser == null) { - Message.send("RANK_PLAYER_NOT_FOUND", player); - return; - } - Message.send("RANK_PLAYER_FOUND", player, nUser.getUserName()); - user = nUser; + @Register + public void rank(ProxiedPlayer player, @Mapper("player") String s) { + SteamwarUser user = SteamwarUser.get(s); + if (user == null) { + Message.send("RANK_PLAYER_NOT_FOUND", player); + return; + } + if (!player.getName().equals(s)) { + Message.send("RANK_PLAYER_FOUND", player, user.getUserName()); } for(ArenaMode mode : ArenaMode.getAllModes()) { if (!mode.isRanked()) @@ -67,4 +71,9 @@ public class RankCommand extends BasicCommand { Message.send("RANK_EMBLEM", player, UserElo.getEmblemProgression(player, mode.getChatName(), user.getId())); } } + + @Mapper(value = "player", local = true) + public TypeMapper playerTypeMapper() { + return SWCommandUtils.createMapper(s -> s, s -> BungeeCord.getInstance().getPlayers().stream().map(ProxiedPlayer::getName).collect(Collectors.toList())); + } }