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,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<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) {
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());