SteamWar/BungeeCore
Archiviert
13
2

Rework whois command
Alle Prüfungen waren erfolgreich
SteamWarCI Build successful

Dieser Commit ist enthalten in:
zOnlyKroks 2023-01-02 13:05:52 +01:00
Ursprung abe45da57d
Commit b6365d32f7
3 geänderte Dateien mit 71 neuen und 19 gelöschten Zeilen

Datei anzeigen

@ -19,36 +19,40 @@
package de.steamwar.bungeecore.commands; package de.steamwar.bungeecore.commands;
import com.google.common.reflect.TypeParameter;
import de.steamwar.bungeecore.Message; import de.steamwar.bungeecore.Message;
import de.steamwar.bungeecore.Storage; import de.steamwar.bungeecore.Storage;
import de.steamwar.bungeecore.sql.Mod; import de.steamwar.bungeecore.sql.*;
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.SWCommand;
import de.steamwar.command.SWCommandUtils; import de.steamwar.command.SWCommandUtils;
import de.steamwar.command.TypeMapper; import de.steamwar.command.TypeMapper;
import lombok.AllArgsConstructor;
import lombok.Getter;
import net.md_5.bungee.BungeeCord; import net.md_5.bungee.BungeeCord;
import net.md_5.bungee.api.CommandSender; import net.md_5.bungee.api.CommandSender;
import net.md_5.bungee.api.chat.ClickEvent; import net.md_5.bungee.api.chat.ClickEvent;
import net.md_5.bungee.api.connection.ProxiedPlayer; import net.md_5.bungee.api.connection.ProxiedPlayer;
import net.md_5.bungee.command.ConsoleCommandSender;
import java.net.InetSocketAddress; import java.net.InetSocketAddress;
import java.sql.Array;
import java.sql.Timestamp; import java.sql.Timestamp;
import java.text.DecimalFormat; import java.text.DecimalFormat;
import java.time.Instant; import java.time.Instant;
import java.util.HashSet;
import java.util.List; import java.util.*;
import java.util.Set; import java.util.function.Supplier;
import java.util.stream.Collectors; import java.util.stream.Collectors;
import java.util.stream.Stream;
public class WhoisCommand extends SWCommand { public class WhoisCommand extends SWCommand {
public WhoisCommand() { public WhoisCommand() {
super("whois", "bungeecore.teamchat"); super("whois", "bungeecore.teamchat");
} }
@Register(description = "WHOIS_USAGE") @Register(description = "WHOIS_COMMAND")
public void genericCommand(ProxiedPlayer player, @Mapper("player") String target, @OptionalValue("") @StaticValue(value = {"", "-all", "-a"}, allowISE = true) boolean all) { public void genericCommand(ProxiedPlayer player, @Mapper("player") String target, WhoisParameterTypes... parameters) {
SteamwarUser user = SteamwarUser.get(target); SteamwarUser user = SteamwarUser.get(target);
if (user == null) { if (user == null) {
try { try {
@ -69,7 +73,7 @@ public class WhoisCommand extends SWCommand {
if (user == null) { if (user == null) {
Message.send("UNKNOWN_PLAYER", player); Message.send("UNKNOWN_PLAYER", player);
} else { } else {
sendUserinfo(player, user, all); sendUserinfo(player, user, new HashSet<>(Arrays.asList(parameters)));
} }
} }
@ -78,7 +82,7 @@ public class WhoisCommand extends SWCommand {
return SWCommandUtils.createMapper(s -> s, s -> BungeeCord.getInstance().getPlayers().stream().map(ProxiedPlayer::getName).collect(Collectors.toList())); 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) { private static void sendUserinfo(ProxiedPlayer player, SteamwarUser user, Set<WhoisParameterTypes> parameterTypes) {
Message.send("WHOIS_USERNAME", player, user.getUserName()); 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()); Message.send("WHOIS_UUID", player, Message.parse("WHOIS_UUID_HOVER", player), new ClickEvent(ClickEvent.Action.COPY_TO_CLIPBOARD, user.getUuid().toString()), user.getUuid().toString());
Message.send("WHOIS_ID", player, user.getId()); Message.send("WHOIS_ID", player, user.getId());
@ -104,19 +108,25 @@ public class WhoisCommand extends SWCommand {
Team team = Team.get(user.getTeam()); Team team = Team.get(user.getTeam());
Message.send("WHOIS_TEAM", player, Message.parse("WHOIS_TEAM_HOVER", player, team.getTeamName()), new ClickEvent(ClickEvent.Action.RUN_COMMAND, "/team info " + team.getTeamKuerzel()), team.getTeamColor(), team.getTeamKuerzel(), team.getTeamName()); Message.send("WHOIS_TEAM", player, Message.parse("WHOIS_TEAM_HOVER", player, team.getTeamName()), new ClickEvent(ClickEvent.Action.RUN_COMMAND, "/team info " + team.getTeamKuerzel()), team.getTeamColor(), team.getTeamKuerzel(), team.getTeamName());
if(!user.getActiveMods().isEmpty()) { if(parameterTypes.contains(WhoisParameterTypes.MOD)) {
Message.send("WHOIS_ACTIVE_MODS",player); if(!user.getActiveMods().isEmpty()) {
for(Mod mod : user.getActiveMods()) { Message.send("WHOIS_ACTIVE_MODS",player);
Message.send("WHOIS_ACTIVE_MOD", player,mod.getModName()); StringBuilder msg = new StringBuilder();
for(Mod mod : user.getActiveMods()) {
msg.append(mod.getModName()).append(",");
}
msg.deleteCharAt(msg.length() - 1);
Message.send("WHOIS_ACTIVE_MOD", player,msg.toString());
}else {
Message.send("WHOIS_NO_ACTIVE_MODS",player);
} }
}else {
Message.send("WHOIS_NO_ACTIVE_MODS",player);
} }
Message.send("WHOIS_PUNISHMENTS", player); Message.send("WHOIS_PUNISHMENTS", player);
List<Punishment> punishmentList = Punishment.getAllPunishmentsOfPlayer(user.getId()); List<Punishment> punishmentList = Punishment.getAllPunishmentsOfPlayer(user.getId());
Set<Punishment.PunishmentType> found = new HashSet<>(); Set<Punishment.PunishmentType> found = new HashSet<>();
boolean isPunished = false; boolean isPunished = false;
boolean all = parameterTypes.contains(WhoisParameterTypes.ALL);
for (Punishment punishment : punishmentList) { for (Punishment punishment : punishmentList) {
if (!all && !punishment.getType().isMulti() && !found.add(punishment.getType())) { if (!all && !punishment.getType().isMulti() && !found.add(punishment.getType())) {
continue; continue;
@ -131,4 +141,46 @@ public class WhoisCommand extends SWCommand {
Message.send(all ? "WHOIS_NO_ALL_PUNISHMENT" : "WHOIS_NO_PUNISHMENT", player); Message.send(all ? "WHOIS_NO_ALL_PUNISHMENT" : "WHOIS_NO_PUNISHMENT", player);
} }
} }
@ClassMapper(value = WhoisParameterTypes.class, local = true)
public TypeMapper<WhoisParameterTypes> argument() {
WhoisParameterTypes[] values = WhoisParameterTypes.values();
return new TypeMapper<WhoisParameterTypes>() {
@Override
public WhoisParameterTypes map(CommandSender commandSender, String[] previousArguments, String s) {
UserGroup userGroup = (commandSender instanceof ConsoleCommandSender) ? UserGroup.Admin : SteamwarUser.get(((ProxiedPlayer) commandSender).getUniqueId()).getUserGroup();
return Stream.of(values)
.filter(p -> p.userGroupSet.contains(userGroup))
.filter(p -> p.getTabCompletes().contains(s))
.findFirst()
.orElse(null);
}
@Override
public Collection<String> tabCompletes(CommandSender commandSender, String[] previousArguments, String s) {
UserGroup userGroup = (commandSender instanceof ConsoleCommandSender) ? UserGroup.Admin : SteamwarUser.get(((ProxiedPlayer) commandSender).getUniqueId()).getUserGroup();
return Stream.of(values)
.filter(p -> p.userGroupSet.contains(userGroup))
.flatMap(p -> p.getTabCompletes().stream())
.collect(Collectors.toList());
}
};
}
private enum WhoisParameterTypes {
ALL(Arrays.asList("-a","-all"),UserGroup.Admin,UserGroup.Moderator,UserGroup.Developer,UserGroup.Supporter,UserGroup.Builder),
MOD(Arrays.asList("-m","-mod","-mods"),UserGroup.Admin,UserGroup.Moderator,UserGroup.Developer);
private final Set<UserGroup> userGroupSet;
@Getter
private List<String> tabCompletes;
WhoisParameterTypes(List<String> tabCompletes,UserGroup... userGroups) {
this.userGroupSet = new HashSet<>(Arrays.asList(userGroups));
this.tabCompletes = tabCompletes;
}
}
} }

Datei anzeigen

@ -578,7 +578,7 @@ SERVER_WORLD_ERROR=§cCreating the world failed.
#WhoisCommand #WhoisCommand
WHOIS_USAGE=§c/whois [player/ID] <-a> WHOIS_USAGE=§c/whois [player/ID] <-a>,<-m>
WHOIS_USERNAME=§7Username§8: §e{0} WHOIS_USERNAME=§7Username§8: §e{0}
WHOIS_UUID=§7UUID§8: §e{0} WHOIS_UUID=§7UUID§8: §e{0}
WHOIS_UUID_HOVER=§eCopy UUID WHOIS_UUID_HOVER=§eCopy UUID

Datei anzeigen

@ -557,7 +557,7 @@ SERVER_WORLD_ERROR=§cDas Erstellen der Welt ist fehlgeschlagen.
#WhoisCommand #WhoisCommand
WHOIS_USAGE=§c/whois [Spieler/ID] <-a> WHOIS_USAGE=§c/whois [Spieler/ID] <-a>,<-m>
WHOIS_USERNAME=§7Username§8: §e{0} WHOIS_USERNAME=§7Username§8: §e{0}
WHOIS_GROUP=§7Gruppe§8: {0}{1} WHOIS_GROUP=§7Gruppe§8: {0}{1}
WHOIS_UUID=§7UUID§8: §e{0} WHOIS_UUID=§7UUID§8: §e{0}