geforkt von SteamWar/BungeeCore
Merge pull request 'Whois Fabric Mod Info' (#444) from whois_fabric_mods into master
Reviewed-on: SteamWar/BungeeCore#444 Reviewed-by: Lixfel <lixfel@steamwar.de>
Dieser Commit ist enthalten in:
Commit
e859fe9211
@ -21,25 +21,25 @@ package de.steamwar.bungeecore.commands;
|
||||
|
||||
import de.steamwar.bungeecore.Message;
|
||||
import de.steamwar.bungeecore.Storage;
|
||||
import de.steamwar.bungeecore.sql.Punishment;
|
||||
import de.steamwar.bungeecore.sql.SteamwarUser;
|
||||
import de.steamwar.bungeecore.sql.Team;
|
||||
import de.steamwar.bungeecore.listeners.mods.Utils;
|
||||
import de.steamwar.bungeecore.sql.*;
|
||||
import de.steamwar.command.SWCommand;
|
||||
import de.steamwar.command.SWCommandUtils;
|
||||
import de.steamwar.command.TypeMapper;
|
||||
import lombok.Getter;
|
||||
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;
|
||||
|
||||
import java.net.InetSocketAddress;
|
||||
import java.sql.Timestamp;
|
||||
import java.text.DecimalFormat;
|
||||
import java.time.Instant;
|
||||
import java.util.HashSet;
|
||||
import java.util.List;
|
||||
import java.util.Set;
|
||||
|
||||
import java.util.*;
|
||||
import java.util.stream.Collectors;
|
||||
import java.util.stream.Stream;
|
||||
|
||||
|
||||
public class WhoisCommand extends SWCommand {
|
||||
public WhoisCommand() {
|
||||
@ -47,7 +47,7 @@ public class WhoisCommand extends SWCommand {
|
||||
}
|
||||
|
||||
@Register(description = "WHOIS_USAGE")
|
||||
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);
|
||||
if (user == null) {
|
||||
try {
|
||||
@ -68,7 +68,8 @@ public class WhoisCommand extends SWCommand {
|
||||
if (user == null) {
|
||||
Message.send("UNKNOWN_PLAYER", player);
|
||||
} else {
|
||||
sendUserinfo(player, user, all);
|
||||
EnumSet<WhoisParameterTypes> set = parameters.length == 0 ? EnumSet.noneOf(WhoisParameterTypes.class) : EnumSet.copyOf(Arrays.asList(parameters));
|
||||
sendUserinfo(player, user, set);
|
||||
}
|
||||
}
|
||||
|
||||
@ -77,7 +78,7 @@ public class WhoisCommand extends SWCommand {
|
||||
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, EnumSet<WhoisParameterTypes> parameterTypes) {
|
||||
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_ID", player, user.getId());
|
||||
@ -103,10 +104,28 @@ public class WhoisCommand extends SWCommand {
|
||||
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());
|
||||
|
||||
if (Utils.playerModMap.containsKey(user.getUuid())) {
|
||||
Mod.Platform modPlatform = Utils.playerModMap.get(user.getUuid()).get(0).getPlatform();
|
||||
Message.send("WHOIS_PLATFORM", player, modPlatform.toString());
|
||||
}
|
||||
|
||||
if (parameterTypes.contains(WhoisParameterTypes.MOD)) {
|
||||
List<Mod> activeMods = Utils.playerModMap.get(user.getUuid());
|
||||
|
||||
if (activeMods != null && !activeMods.isEmpty()) {
|
||||
Message.send("WHOIS_ACTIVE_MODS", player,activeMods.size());
|
||||
String result = activeMods.stream().map(mod -> "§" + mod.getModType().getColorCode() + mod.getModName()).collect(Collectors.joining("§8, "));
|
||||
Message.send("WHOIS_ACTIVE_MOD", player, result);
|
||||
} else {
|
||||
Message.send("WHOIS_NO_ACTIVE_MODS", player);
|
||||
}
|
||||
}
|
||||
|
||||
Message.send("WHOIS_PUNISHMENTS", player);
|
||||
List<Punishment> punishmentList = Punishment.getAllPunishmentsOfPlayer(user.getId());
|
||||
Set<Punishment.PunishmentType> found = new HashSet<>();
|
||||
boolean isPunished = false;
|
||||
boolean all = parameterTypes.contains(WhoisParameterTypes.ALL);
|
||||
for (Punishment punishment : punishmentList) {
|
||||
if (!all && !punishment.getType().isMulti() && !found.add(punishment.getType())) {
|
||||
continue;
|
||||
@ -121,4 +140,46 @@ public class WhoisCommand extends SWCommand {
|
||||
Message.send(all ? "WHOIS_NO_ALL_PUNISHMENT" : "WHOIS_NO_PUNISHMENT", player);
|
||||
}
|
||||
}
|
||||
|
||||
@ClassMapper(value = WhoisParameterTypes.class, local = true)
|
||||
public TypeMapper<WhoisParameterTypes> argumentTypeMapper() {
|
||||
WhoisParameterTypes[] values = WhoisParameterTypes.values();
|
||||
|
||||
return new TypeMapper<WhoisParameterTypes>() {
|
||||
@Override
|
||||
public WhoisParameterTypes map(CommandSender commandSender, String[] previousArguments, String s) {
|
||||
UserGroup userGroup = 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 = 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 EnumSet<UserGroup> userGroupSet;
|
||||
|
||||
@Getter
|
||||
private List<String> tabCompletes;
|
||||
|
||||
|
||||
WhoisParameterTypes(List<String> tabCompletes, UserGroup... userGroups) {
|
||||
this.userGroupSet = EnumSet.copyOf(Arrays.asList(userGroups));
|
||||
this.tabCompletes = tabCompletes;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -28,6 +28,7 @@ import de.steamwar.bungeecore.bot.util.DiscordRanks;
|
||||
import de.steamwar.bungeecore.commands.ChallengeCommand;
|
||||
import de.steamwar.bungeecore.commands.CheckCommand;
|
||||
import de.steamwar.bungeecore.commands.MsgCommand;
|
||||
import de.steamwar.bungeecore.listeners.mods.Utils;
|
||||
import de.steamwar.bungeecore.sql.SteamwarUser;
|
||||
import de.steamwar.bungeecore.sql.UserGroup;
|
||||
import net.md_5.bungee.api.AbstractReconnectHandler;
|
||||
@ -135,6 +136,7 @@ public class ConnectionListener extends BasicListener {
|
||||
public void onDisconnect(PlayerDisconnectEvent e){
|
||||
ChallengeCommand.remove(e.getPlayer());
|
||||
MsgCommand.remove(e.getPlayer());
|
||||
Utils.playerModMap.remove(e.getPlayer().getUniqueId());
|
||||
}
|
||||
|
||||
@EventHandler
|
||||
|
@ -89,7 +89,7 @@ public class Fabric extends BasicListener {
|
||||
}
|
||||
Storage.fabricExpectPluginMessage.remove(player);
|
||||
|
||||
List<Mod> mods = new LinkedList<>();
|
||||
List<Mod> mods = new ArrayList<>();
|
||||
|
||||
Utils.VarInt varInt = Utils.readVarInt(data,0);
|
||||
|
||||
@ -122,15 +122,6 @@ public class Fabric extends BasicListener {
|
||||
mods.add(Mod.get(mod.getAsString(), Mod.Platform.FABRIC));
|
||||
}
|
||||
|
||||
/*
|
||||
boolean isSorted = isSortedAlphabetically(mods);
|
||||
|
||||
if(!isSorted) {
|
||||
banPlayer(user, player, "Mods are not sorted alphabetically: " + mods.stream().map(Mod::getModName).collect(Collectors.joining(", ")));
|
||||
return;
|
||||
}
|
||||
*/
|
||||
|
||||
if(!neededModsContained(mods)) {
|
||||
logMessage(user, "Needed mods are not contained", dataString);
|
||||
return;
|
||||
@ -159,17 +150,6 @@ public class Fabric extends BasicListener {
|
||||
}
|
||||
}
|
||||
|
||||
private boolean isSortedAlphabetically(List<Mod> mods) {
|
||||
boolean isSorted = true;
|
||||
for(int i = 0; i < mods.size() - 1; i++) {
|
||||
if(mods.get(i).getModName().compareToIgnoreCase(mods.get(i + 1).getModName()) > 0) {
|
||||
isSorted = false;
|
||||
break;
|
||||
}
|
||||
}
|
||||
return isSorted;
|
||||
}
|
||||
|
||||
private boolean neededModsContained(List<Mod> mods) {
|
||||
return mods.stream()
|
||||
.map(Mod::getModName)
|
||||
|
@ -33,15 +33,15 @@ import net.md_5.bungee.api.connection.ProxiedPlayer;
|
||||
import java.sql.Timestamp;
|
||||
import java.time.Instant;
|
||||
import java.time.temporal.ChronoUnit;
|
||||
import java.util.Iterator;
|
||||
import java.util.List;
|
||||
import java.util.Locale;
|
||||
import java.util.UUID;
|
||||
import java.util.*;
|
||||
import java.util.function.Consumer;
|
||||
import java.util.logging.Level;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
class Utils {
|
||||
public class Utils {
|
||||
|
||||
public static final Map<UUID,List<Mod>> playerModMap = new HashMap<>();
|
||||
|
||||
private Utils(){}
|
||||
|
||||
static VarInt readVarInt(byte[] array, int startPos) {
|
||||
@ -69,6 +69,7 @@ class Utils {
|
||||
static boolean handleMods(UUID uuid, Locale locale, Consumer<BaseComponent[]> disconnect, List<Mod> mods){
|
||||
SteamwarUser user = SteamwarUser.get(uuid);
|
||||
boolean privileged = user.getUserGroup().privilegedMods();
|
||||
playerModMap.put(uuid,new ArrayList<>(mods));
|
||||
|
||||
ModType max = ModType.YELLOW;
|
||||
Iterator<Mod> it = mods.iterator();
|
||||
@ -80,8 +81,10 @@ class Utils {
|
||||
max = ModType.RED;
|
||||
}
|
||||
|
||||
if(mods.isEmpty())
|
||||
if(mods.isEmpty()) {
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
ModType finalMax = max;
|
||||
String modList = mods.stream().filter(mod -> finalMax == ModType.YELLOW || mod.getModType() == ModType.RED).map(Mod::getModName).collect(Collectors.joining("\n"));
|
||||
|
@ -74,11 +74,11 @@ public class Mod {
|
||||
}
|
||||
|
||||
public enum ModType {
|
||||
UNKLASSIFIED(0),
|
||||
GREEN(1),
|
||||
YELLOW(2),
|
||||
RED(3),
|
||||
YOUTUBER_ONLY(4);
|
||||
UNKLASSIFIED(0,"7"),
|
||||
GREEN(1,"a"),
|
||||
YELLOW(2,"e"),
|
||||
RED(3,"c"),
|
||||
YOUTUBER_ONLY(4,"6");
|
||||
|
||||
static ModType valueOf(int value){
|
||||
for(ModType mt : values()){
|
||||
@ -88,9 +88,15 @@ public class Mod {
|
||||
throw new EnumConstantNotPresentException(ModType.class, Integer.toString(value));
|
||||
}
|
||||
|
||||
ModType(int value){
|
||||
ModType(int value,String colorcode){
|
||||
this.value = value;
|
||||
this.colorcode = colorcode;
|
||||
}
|
||||
int value;
|
||||
String colorcode;
|
||||
|
||||
public String getColorCode() {
|
||||
return colorcode;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -578,7 +578,7 @@ SERVER_WORLD_ERROR=§cCreating the world failed.
|
||||
|
||||
|
||||
#WhoisCommand
|
||||
WHOIS_USAGE=§c/whois [player/ID] <-a>
|
||||
WHOIS_USAGE=§c/whois [player/ID] [-a/-m]
|
||||
WHOIS_USERNAME=§7Username§8: §e{0}
|
||||
WHOIS_UUID=§7UUID§8: §e{0}
|
||||
WHOIS_UUID_HOVER=§eCopy UUID
|
||||
@ -596,6 +596,10 @@ WHOIS_PUNISHMENTS=§7Punish:
|
||||
WHOIS_PUNISHMENT=§7{0}§8» §f§l{1}: §e{2} - {3} §f{4}
|
||||
WHOIS_NO_PUNISHMENT=§a✓ §7This player has no active punishment.
|
||||
WHOIS_NO_ALL_PUNISHMENT=§a✓ §7The player has not done anything yet.
|
||||
WHOIS_ACTIVE_MODS=§7Active Mods ({0}):
|
||||
WHOIS_NO_ACTIVE_MODS=§7This player has no active mods.
|
||||
WHOIS_ACTIVE_MOD={0}
|
||||
WHOIS_PLATFORM=§7Modloader: §e{0}
|
||||
|
||||
#VerifyCommand
|
||||
VERIFY_USAGE=§c/verify [Code]
|
||||
|
@ -557,7 +557,7 @@ SERVER_WORLD_ERROR=§cDas Erstellen der Welt ist fehlgeschlagen.
|
||||
|
||||
|
||||
#WhoisCommand
|
||||
WHOIS_USAGE=§c/whois [Spieler/ID] <-a>
|
||||
WHOIS_USAGE=§c/whois [Spieler/ID] [-a/-m]
|
||||
WHOIS_USERNAME=§7Username§8: §e{0}
|
||||
WHOIS_GROUP=§7Gruppe§8: {0}{1}
|
||||
WHOIS_UUID=§7UUID§8: §e{0}
|
||||
@ -575,6 +575,8 @@ WHOIS_PUNISHMENTS=§7Strafen:
|
||||
WHOIS_PUNISHMENT=§7{0}§8» §f§l{1}: §e{2} - {3} §f{4}
|
||||
WHOIS_NO_PUNISHMENT=§a✓ §7Der Spieler hat keine aktiven Strafen.
|
||||
WHOIS_NO_ALL_PUNISHMENT=§a✓ §7Der Spieler hat noch nichts getan.
|
||||
WHOIS_ACTIVE_MODS=§7Aktive Mods ({0}):
|
||||
WHOIS_NO_ACTIVE_MODS=§7Der Spieler hat keine aktiven Mods.
|
||||
|
||||
#VerifyCommand
|
||||
VERIFY_USAGE=§c/verify [Code]
|
||||
|
In neuem Issue referenzieren
Einen Benutzer sperren