SteamWar/BungeeCore
Archiviert
13
2

Merge pull request 'Update WhoisCommand' (#409) from CommandWhois into master
Alle Prüfungen waren erfolgreich
SteamWarCI Build successful

Reviewed-on: #409
Reviewed-by: Lixfel <lixfel@steamwar.de>
Dieser Commit ist enthalten in:
Lixfel 2022-06-16 13:32:22 +02:00
Commit e156d3ad4a

Datei anzeigen

@ -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,33 +36,26 @@ 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 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]);
@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
@ -70,12 +67,13 @@ public class WhoisCommand extends BasicCommand {
return;
}
boolean all = false;
if(args.length > 1 && args[1].startsWith("-")) {
all = args[1].contains("a");
boolean all = displayAll.contains("-");
sendUserinfo(player, user, all);
}
sendUserinfo(player, user, all);
@Mapper(value = "player", local = true)
public TypeMapper<String> 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) {