From c88ac55b8932dbb6b0a704aabc13bf8942a99daa Mon Sep 17 00:00:00 2001 From: Lixfel Date: Sun, 6 Feb 2022 18:09:00 +0100 Subject: [PATCH] Fix forge autoban disconnect Signed-off-by: Lixfel --- .../bungeecore/listeners/mods/Utils.java | 30 +++++++++---------- 1 file changed, 14 insertions(+), 16 deletions(-) diff --git a/src/de/steamwar/bungeecore/listeners/mods/Utils.java b/src/de/steamwar/bungeecore/listeners/mods/Utils.java index 417f8464..7e3e4cc5 100644 --- a/src/de/steamwar/bungeecore/listeners/mods/Utils.java +++ b/src/de/steamwar/bungeecore/listeners/mods/Utils.java @@ -38,6 +38,7 @@ import java.util.Locale; import java.util.UUID; import java.util.function.Consumer; import java.util.logging.Level; +import java.util.stream.Collectors; class Utils { private Utils(){} @@ -81,25 +82,22 @@ class Utils { if(mods.isEmpty()) return true; - if(mods.size() == 1){ - if(max == ModType.YELLOW) - disconnect.accept(TextComponent.fromLegacyText(Message.parse("MOD_YELLOW_SING", locale, mods.get(0).getModName()))); - else{ - user.punish(Punishment.PunishmentType.Ban, Timestamp.from(Instant.now().plus(7, ChronoUnit.DAYS)), Message.parse("MOD_RED_SING", locale, mods.get(0).getModName()), 0, false); - BungeeCore.log(Level.SEVERE, user.getUserName() + " " + user.getId() + " wurde automatisch wegen des Mods " + mods.get(0).getModName() + " gebannt."); - } - }else{ - StringBuilder sb = new StringBuilder(); - mods.forEach(mod -> sb.append(mod.getModName()).append('\n')); + ModType finalMax = max; + String modList = mods.stream().filter(mod -> finalMax == ModType.YELLOW || mod.getModType() == ModType.RED).map(Mod::getModName).collect(Collectors.joining("\n")); + String message; - if(max == ModType.YELLOW) - disconnect.accept(TextComponent.fromLegacyText(Message.parse("MOD_YELLOW_PLUR", locale, sb.toString()))); - else{ - user.punish(Punishment.PunishmentType.Ban, Timestamp.from(Instant.now().plus(7, ChronoUnit.DAYS)), Message.parse("MOD_RED_PLUR", locale, sb.toString()), 0, false); - BungeeCore.log(Level.SEVERE, user.getUserName() + " " + user.getId() + " wurde automatisch wegen der Mods " + sb + " gebannt."); - } + if(mods.size() == 1) { + message = Message.parse(max == ModType.RED ? "MOD_RED_SING" : "MOD_YELLOW_SING", locale, modList); + } else { + message = Message.parse(max == ModType.RED ? "MOD_RED_PLUR" : "MOD_YELLOW_PLUR", locale, modList); } + if(max == ModType.RED) { + user.punish(Punishment.PunishmentType.Ban, Timestamp.from(Instant.now().plus(7, ChronoUnit.DAYS)), message, 0, false); + BungeeCore.log(Level.SEVERE, user.getUserName() + " " + user.getId() + " wurde automatisch wegen der Mods " + modList + " gebannt."); + } + + disconnect.accept(TextComponent.fromLegacyText(message)); return false; }