From ed55af8952a02af809ec9f4116b7b4f06f6a0fae Mon Sep 17 00:00:00 2001 From: zOnlyKroks Date: Mon, 2 Jan 2023 23:54:24 +0100 Subject: [PATCH] Make it use more mod loader + add modloader + color coding --- .../bungeecore/commands/WhoisCommand.java | 26 +++++++++++-------- .../listeners/ConnectionListener.java | 3 +++ .../bungeecore/listeners/mods/Fabric.java | 4 +-- .../bungeecore/listeners/mods/LabyMod.java | 5 +--- .../bungeecore/listeners/mods/Utils.java | 15 ++++++----- src/de/steamwar/bungeecore/sql/Mod.java | 18 ++++++++----- .../steamwar/bungeecore/sql/SteamwarUser.java | 11 -------- .../steamwar/messages/BungeeCore.properties | 3 ++- .../messages/BungeeCore_de.properties | 3 ++- 9 files changed, 45 insertions(+), 43 deletions(-) diff --git a/src/de/steamwar/bungeecore/commands/WhoisCommand.java b/src/de/steamwar/bungeecore/commands/WhoisCommand.java index 840365a..807dbbc 100644 --- a/src/de/steamwar/bungeecore/commands/WhoisCommand.java +++ b/src/de/steamwar/bungeecore/commands/WhoisCommand.java @@ -22,6 +22,7 @@ package de.steamwar.bungeecore.commands; import com.google.common.reflect.TypeParameter; import de.steamwar.bungeecore.Message; import de.steamwar.bungeecore.Storage; +import de.steamwar.bungeecore.listeners.mods.Utils; import de.steamwar.bungeecore.sql.*; import de.steamwar.command.SWCommand; import de.steamwar.command.SWCommandUtils; @@ -108,15 +109,18 @@ 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.synchronizedPlayerModMap.containsKey(user.getUuid())) { + Mod.Platform modPlatform = Utils.synchronizedPlayerModMap.get(user.getUuid()).get(0).getPlatform(); + Message.send("WHOIS_PLATFORM",player,modPlatform.toString()); + } + if(parameterTypes.contains(WhoisParameterTypes.MOD)) { - if(!user.getActiveMods().isEmpty()) { - Message.send("WHOIS_ACTIVE_MODS",player); - 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()); + List activeMods = Utils.synchronizedPlayerModMap.get(user.getUuid()); + + if(!activeMods.isEmpty()) { + Message.send("WHOIS_ACTIVE_MODS",player); + 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); } @@ -143,13 +147,13 @@ public class WhoisCommand extends SWCommand { } @ClassMapper(value = WhoisParameterTypes.class, local = true) - public TypeMapper argument() { + public TypeMapper argumentTypeMapper() { WhoisParameterTypes[] values = WhoisParameterTypes.values(); return new TypeMapper() { @Override public WhoisParameterTypes map(CommandSender commandSender, String[] previousArguments, String s) { - UserGroup userGroup = (commandSender instanceof ConsoleCommandSender) ? UserGroup.Admin : SteamwarUser.get(((ProxiedPlayer) commandSender).getUniqueId()).getUserGroup(); + UserGroup userGroup = SteamwarUser.get(((ProxiedPlayer) commandSender).getUniqueId()).getUserGroup(); return Stream.of(values) .filter(p -> p.userGroupSet.contains(userGroup)) .filter(p -> p.getTabCompletes().contains(s)) @@ -159,7 +163,7 @@ public class WhoisCommand extends SWCommand { @Override public Collection tabCompletes(CommandSender commandSender, String[] previousArguments, String s) { - UserGroup userGroup = (commandSender instanceof ConsoleCommandSender) ? UserGroup.Admin : SteamwarUser.get(((ProxiedPlayer) commandSender).getUniqueId()).getUserGroup(); + UserGroup userGroup = SteamwarUser.get(((ProxiedPlayer) commandSender).getUniqueId()).getUserGroup(); return Stream.of(values) .filter(p -> p.userGroupSet.contains(userGroup)) .flatMap(p -> p.getTabCompletes().stream()) diff --git a/src/de/steamwar/bungeecore/listeners/ConnectionListener.java b/src/de/steamwar/bungeecore/listeners/ConnectionListener.java index 44bba9f..851e0af 100644 --- a/src/de/steamwar/bungeecore/listeners/ConnectionListener.java +++ b/src/de/steamwar/bungeecore/listeners/ConnectionListener.java @@ -28,8 +28,10 @@ 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.Util; import net.md_5.bungee.api.AbstractReconnectHandler; import net.md_5.bungee.api.ProxyServer; import net.md_5.bungee.api.chat.ClickEvent; @@ -135,6 +137,7 @@ public class ConnectionListener extends BasicListener { public void onDisconnect(PlayerDisconnectEvent e){ ChallengeCommand.remove(e.getPlayer()); MsgCommand.remove(e.getPlayer()); + Utils.synchronizedPlayerModMap.remove(e.getPlayer().getUniqueId()); } @EventHandler diff --git a/src/de/steamwar/bungeecore/listeners/mods/Fabric.java b/src/de/steamwar/bungeecore/listeners/mods/Fabric.java index 7258e34..440ab12 100644 --- a/src/de/steamwar/bungeecore/listeners/mods/Fabric.java +++ b/src/de/steamwar/bungeecore/listeners/mods/Fabric.java @@ -89,7 +89,7 @@ public class Fabric extends BasicListener { } Storage.fabricExpectPluginMessage.remove(player); - ArrayList mods = new ArrayList<>(); + List mods = new ArrayList<>(); Utils.VarInt varInt = Utils.readVarInt(data,0); @@ -127,8 +127,6 @@ public class Fabric extends BasicListener { return; } - user.setActiveMods(mods); - if(Utils.handleMods(player,mods)) { if (Storage.fabricCheckedPlayers.containsKey(player)) { long current = Storage.fabricCheckedPlayers.get(player); diff --git a/src/de/steamwar/bungeecore/listeners/mods/LabyMod.java b/src/de/steamwar/bungeecore/listeners/mods/LabyMod.java index e659b4d..6a447dd 100644 --- a/src/de/steamwar/bungeecore/listeners/mods/LabyMod.java +++ b/src/de/steamwar/bungeecore/listeners/mods/LabyMod.java @@ -33,10 +33,7 @@ import net.md_5.bungee.event.EventHandler; import java.io.IOException; import java.io.StringReader; import java.nio.charset.StandardCharsets; -import java.util.Arrays; -import java.util.LinkedList; -import java.util.List; -import java.util.UUID; +import java.util.*; public class LabyMod extends BasicListener { diff --git a/src/de/steamwar/bungeecore/listeners/mods/Utils.java b/src/de/steamwar/bungeecore/listeners/mods/Utils.java index 36256b6..b63b514 100644 --- a/src/de/steamwar/bungeecore/listeners/mods/Utils.java +++ b/src/de/steamwar/bungeecore/listeners/mods/Utils.java @@ -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> synchronizedPlayerModMap = 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 disconnect, List mods){ SteamwarUser user = SteamwarUser.get(uuid); boolean privileged = user.getUserGroup().privilegedMods(); + synchronizedPlayerModMap.put(uuid,new ArrayList<>(mods)); ModType max = ModType.YELLOW; Iterator 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")); diff --git a/src/de/steamwar/bungeecore/sql/Mod.java b/src/de/steamwar/bungeecore/sql/Mod.java index dcd69ae..039d930 100644 --- a/src/de/steamwar/bungeecore/sql/Mod.java +++ b/src/de/steamwar/bungeecore/sql/Mod.java @@ -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; + } } } diff --git a/src/de/steamwar/bungeecore/sql/SteamwarUser.java b/src/de/steamwar/bungeecore/sql/SteamwarUser.java index bb87728..2c11fdb 100644 --- a/src/de/steamwar/bungeecore/sql/SteamwarUser.java +++ b/src/de/steamwar/bungeecore/sql/SteamwarUser.java @@ -81,8 +81,6 @@ public class SteamwarUser { private Locale locale; private boolean manualLocale; - private List activeMods = new CopyOnWriteArrayList<>(); - static { try { LIXFEL_DE = InetAddress.getByAddress(new byte[]{(byte) 195, (byte) 201, (byte) 242, 43}); @@ -395,13 +393,4 @@ public class SteamwarUser { updateLocale.update(locale.toLanguageTag(), manualLocale, id); NetworkSender.send(getPlayer(), new LocaleInvalidationPacket(id)); } - - public void setActiveMods(List activeMods) { - this.activeMods.clear(); - this.activeMods.addAll(activeMods); - } - - public List getActiveMods() { - return new ArrayList<>(activeMods); - } } diff --git a/src/de/steamwar/messages/BungeeCore.properties b/src/de/steamwar/messages/BungeeCore.properties index 7d2e1c9..80b9e97 100644 --- a/src/de/steamwar/messages/BungeeCore.properties +++ b/src/de/steamwar/messages/BungeeCore.properties @@ -598,7 +598,8 @@ 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: WHOIS_NO_ACTIVE_MODS=§7This player has no active mods. -WHOIS_ACTIVE_MOD=§7{0} +WHOIS_ACTIVE_MOD={0} +WHOIS_PLATFORM=§7Modloader: §e{0} #VerifyCommand VERIFY_USAGE=§c/verify [Code] diff --git a/src/de/steamwar/messages/BungeeCore_de.properties b/src/de/steamwar/messages/BungeeCore_de.properties index b4f126b..5ba1edf 100644 --- a/src/de/steamwar/messages/BungeeCore_de.properties +++ b/src/de/steamwar/messages/BungeeCore_de.properties @@ -577,7 +577,8 @@ 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: WHOIS_NO_ACTIVE_MODS=§7Der Spieler hat keine aktiven Mods. -WHOIS_ACTIVE_MOD=§7{0} +WHOIS_ACTIVE_MOD={0} +WHOIS_PLATFORM=§7Modloader:§e{0} #VerifyCommand VERIFY_USAGE=§c/verify [Code]