SteamWar/BungeeCore
Archiviert
13
2

Merge pull request 'Whois Fabric Mod Info' (#444) from whois_fabric_mods into master
Alle Prüfungen waren erfolgreich
SteamWarCI Build successful

Reviewed-on: #444
Reviewed-by: Lixfel <lixfel@steamwar.de>
Dieser Commit ist enthalten in:
Lixfel 2023-01-15 16:42:17 +01:00
Commit e859fe9211
7 geänderte Dateien mit 103 neuen und 45 gelöschten Zeilen

Datei anzeigen

@ -21,25 +21,25 @@ package de.steamwar.bungeecore.commands;
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.Punishment; import de.steamwar.bungeecore.listeners.mods.Utils;
import de.steamwar.bungeecore.sql.SteamwarUser; import de.steamwar.bungeecore.sql.*;
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.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 java.net.InetSocketAddress;
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.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() {
@ -47,7 +47,7 @@ public class WhoisCommand extends SWCommand {
} }
@Register(description = "WHOIS_USAGE") @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); SteamwarUser user = SteamwarUser.get(target);
if (user == null) { if (user == null) {
try { try {
@ -68,7 +68,8 @@ 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); 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())); 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_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());
@ -103,10 +104,28 @@ 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 (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); 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;
@ -121,4 +140,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> 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;
}
}
} }

Datei anzeigen

@ -28,6 +28,7 @@ import de.steamwar.bungeecore.bot.util.DiscordRanks;
import de.steamwar.bungeecore.commands.ChallengeCommand; import de.steamwar.bungeecore.commands.ChallengeCommand;
import de.steamwar.bungeecore.commands.CheckCommand; import de.steamwar.bungeecore.commands.CheckCommand;
import de.steamwar.bungeecore.commands.MsgCommand; import de.steamwar.bungeecore.commands.MsgCommand;
import de.steamwar.bungeecore.listeners.mods.Utils;
import de.steamwar.bungeecore.sql.SteamwarUser; import de.steamwar.bungeecore.sql.SteamwarUser;
import de.steamwar.bungeecore.sql.UserGroup; import de.steamwar.bungeecore.sql.UserGroup;
import net.md_5.bungee.api.AbstractReconnectHandler; import net.md_5.bungee.api.AbstractReconnectHandler;
@ -135,6 +136,7 @@ public class ConnectionListener extends BasicListener {
public void onDisconnect(PlayerDisconnectEvent e){ public void onDisconnect(PlayerDisconnectEvent e){
ChallengeCommand.remove(e.getPlayer()); ChallengeCommand.remove(e.getPlayer());
MsgCommand.remove(e.getPlayer()); MsgCommand.remove(e.getPlayer());
Utils.playerModMap.remove(e.getPlayer().getUniqueId());
} }
@EventHandler @EventHandler

Datei anzeigen

@ -89,7 +89,7 @@ public class Fabric extends BasicListener {
} }
Storage.fabricExpectPluginMessage.remove(player); Storage.fabricExpectPluginMessage.remove(player);
List<Mod> mods = new LinkedList<>(); List<Mod> mods = new ArrayList<>();
Utils.VarInt varInt = Utils.readVarInt(data,0); 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)); 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)) { if(!neededModsContained(mods)) {
logMessage(user, "Needed mods are not contained", dataString); logMessage(user, "Needed mods are not contained", dataString);
return; 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) { private boolean neededModsContained(List<Mod> mods) {
return mods.stream() return mods.stream()
.map(Mod::getModName) .map(Mod::getModName)

Datei anzeigen

@ -33,15 +33,15 @@ import net.md_5.bungee.api.connection.ProxiedPlayer;
import java.sql.Timestamp; import java.sql.Timestamp;
import java.time.Instant; import java.time.Instant;
import java.time.temporal.ChronoUnit; import java.time.temporal.ChronoUnit;
import java.util.Iterator; import java.util.*;
import java.util.List;
import java.util.Locale;
import java.util.UUID;
import java.util.function.Consumer; import java.util.function.Consumer;
import java.util.logging.Level; import java.util.logging.Level;
import java.util.stream.Collectors; import java.util.stream.Collectors;
class Utils { public class Utils {
public static final Map<UUID,List<Mod>> playerModMap = new HashMap<>();
private Utils(){} private Utils(){}
static VarInt readVarInt(byte[] array, int startPos) { 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){ static boolean handleMods(UUID uuid, Locale locale, Consumer<BaseComponent[]> disconnect, List<Mod> mods){
SteamwarUser user = SteamwarUser.get(uuid); SteamwarUser user = SteamwarUser.get(uuid);
boolean privileged = user.getUserGroup().privilegedMods(); boolean privileged = user.getUserGroup().privilegedMods();
playerModMap.put(uuid,new ArrayList<>(mods));
ModType max = ModType.YELLOW; ModType max = ModType.YELLOW;
Iterator<Mod> it = mods.iterator(); Iterator<Mod> it = mods.iterator();
@ -80,8 +81,10 @@ class Utils {
max = ModType.RED; max = ModType.RED;
} }
if(mods.isEmpty()) if(mods.isEmpty()) {
return true; return true;
}
ModType finalMax = max; ModType finalMax = max;
String modList = mods.stream().filter(mod -> finalMax == ModType.YELLOW || mod.getModType() == ModType.RED).map(Mod::getModName).collect(Collectors.joining("\n")); String modList = mods.stream().filter(mod -> finalMax == ModType.YELLOW || mod.getModType() == ModType.RED).map(Mod::getModName).collect(Collectors.joining("\n"));

Datei anzeigen

@ -74,11 +74,11 @@ public class Mod {
} }
public enum ModType { public enum ModType {
UNKLASSIFIED(0), UNKLASSIFIED(0,"7"),
GREEN(1), GREEN(1,"a"),
YELLOW(2), YELLOW(2,"e"),
RED(3), RED(3,"c"),
YOUTUBER_ONLY(4); YOUTUBER_ONLY(4,"6");
static ModType valueOf(int value){ static ModType valueOf(int value){
for(ModType mt : values()){ for(ModType mt : values()){
@ -88,9 +88,15 @@ public class Mod {
throw new EnumConstantNotPresentException(ModType.class, Integer.toString(value)); throw new EnumConstantNotPresentException(ModType.class, Integer.toString(value));
} }
ModType(int value){ ModType(int value,String colorcode){
this.value = value; this.value = value;
this.colorcode = colorcode;
} }
int value; int value;
String colorcode;
public String getColorCode() {
return colorcode;
}
} }
} }

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
@ -596,6 +596,10 @@ WHOIS_PUNISHMENTS=§7Punish:
WHOIS_PUNISHMENT=§7{0}§8» §f§l{1}: §e{2} - {3} §f{4} 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_PUNISHMENT=§a✓ §7This player has no active punishment.
WHOIS_NO_ALL_PUNISHMENT=§a✓ §7The player has not done anything yet. 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 #VerifyCommand
VERIFY_USAGE=§c/verify [Code] VERIFY_USAGE=§c/verify [Code]

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}
@ -575,6 +575,8 @@ WHOIS_PUNISHMENTS=§7Strafen:
WHOIS_PUNISHMENT=§7{0}§8» §f§l{1}: §e{2} - {3} §f{4} 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_PUNISHMENT=§a✓ §7Der Spieler hat keine aktiven Strafen.
WHOIS_NO_ALL_PUNISHMENT=§a✓ §7Der Spieler hat noch nichts getan. 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 #VerifyCommand
VERIFY_USAGE=§c/verify [Code] VERIFY_USAGE=§c/verify [Code]