From ed79088560dd6dca5ca1ace9a69034d9a148f0de Mon Sep 17 00:00:00 2001 From: Chaoscaot Date: Thu, 10 Dec 2020 15:00:48 +0100 Subject: [PATCH] Add Ban Time to Banumgehungs message and moved Messages to properties --- .../bungeecore/listeners/BanListener.java | 37 +++++++++++-------- .../steamwar/messages/BungeeCore.properties | 3 ++ 2 files changed, 24 insertions(+), 16 deletions(-) diff --git a/src/de/steamwar/bungeecore/listeners/BanListener.java b/src/de/steamwar/bungeecore/listeners/BanListener.java index c9aadb7..d996c90 100644 --- a/src/de/steamwar/bungeecore/listeners/BanListener.java +++ b/src/de/steamwar/bungeecore/listeners/BanListener.java @@ -20,6 +20,7 @@ package de.steamwar.bungeecore.listeners; import de.steamwar.bungeecore.BungeeCore; +import de.steamwar.bungeecore.Message; import de.steamwar.bungeecore.sql.BannedUserIPs; import de.steamwar.bungeecore.sql.SteamwarUser; import net.md_5.bungee.api.ProxyServer; @@ -31,6 +32,9 @@ import net.md_5.bungee.api.connection.ProxiedPlayer; import net.md_5.bungee.api.event.LoginEvent; import net.md_5.bungee.event.EventHandler; +import java.sql.Timestamp; +import java.time.Instant; +import java.time.format.DateTimeFormatter; import java.util.List; public class BanListener extends BasicListener { @@ -47,27 +51,28 @@ public class BanListener extends BasicListener { List ips = BannedUserIPs.get(event.getConnection().getAddress().getAddress().getHostAddress()); if(!ips.isEmpty()){ - StringBuilder potentialBan = new StringBuilder(); - potentialBan.append(BungeeCore.CHAT_PREFIX); - potentialBan.append("§cMögliche Bannumgehung durch §r"); - potentialBan.append(user.getUserName()); - potentialBan.append("§c:"); - for(BannedUserIPs banned : ips){ - SteamwarUser bannedUser = SteamwarUser.get(banned.getUserID()); - potentialBan.append(" §e"); - potentialBan.append(banned.getTimestamp().toLocalDateTime().format(BungeeCore.DATE_FORMAT)); - potentialBan.append(" §c"); - potentialBan.append(bannedUser.getUserName()); - } - - TextComponent msg = new TextComponent(potentialBan.toString()); - msg.setHoverEvent(new HoverEvent(HoverEvent.Action.SHOW_TEXT, new ComponentBuilder("§cBanne Spieler wegen Bannumgehung").create())); - msg.setClickEvent(new ClickEvent(ClickEvent.Action.RUN_COMMAND, "/ban " + user.getUserName() + " perma Bannumgehung")); for (ProxiedPlayer target : ProxyServer.getInstance().getPlayers()){ if ((target.hasPermission("bungeecore.teamchat")) && (target.getChatMode() == ProxiedPlayer.ChatMode.COMMANDS_ONLY || target.getChatMode() == ProxiedPlayer.ChatMode.SHOWN)){ + StringBuilder potentialBan = new StringBuilder(); + potentialBan.append(Message.parsePrefixed("BAN_AVOIDING_ALERT", target, user.getUserName())); + + Timestamp highestBan = Timestamp.from(Instant.now()); + for(BannedUserIPs banned : ips) { + SteamwarUser bannedUser = SteamwarUser.get(banned.getUserID()); + potentialBan.append(Message.parse("BAN_AVOIDING_LIST", target, bannedUser.getId(), + banned.getTimestamp().toLocalDateTime().format(BungeeCore.DATE_FORMAT), bannedUser.getUserName())); + if(highestBan.before(banned.getTimestamp())) + highestBan = banned.getTimestamp(); + } + + TextComponent msg = new TextComponent(potentialBan.toString()); + msg.setHoverEvent(new HoverEvent(HoverEvent.Action.SHOW_TEXT, new ComponentBuilder(Message.parse("BAN_AVOIDING_BAN_HOVER", target)).create())); + msg.setClickEvent(new ClickEvent(ClickEvent.Action.RUN_COMMAND, "/ban " + user.getUserName() + " " + + highestBan.toLocalDateTime().format(DateTimeFormatter.ofPattern("dd.MM.yyyy_HH:mm")) + + " Bannumgehung")); target.sendMessage(msg); } } diff --git a/src/de/steamwar/messages/BungeeCore.properties b/src/de/steamwar/messages/BungeeCore.properties index e7ff281..9e7e432 100644 --- a/src/de/steamwar/messages/BungeeCore.properties +++ b/src/de/steamwar/messages/BungeeCore.properties @@ -93,6 +93,9 @@ USAGE_IGNORE=§8/§7ignore §8[§eSpieler§8] ALERT=§f{0} BAN_MESSAGE_YOU=§7Du hast §e{0} §7gebannt§8. §7Grund§8: §c{1} +BAN_AVOIDING_ALERT=§cMögliche Bannumgehung durch §r{0}§c: +BAN_AVOIDING_LIST={0} §e{1} §c +BAN_AVOIDING_BAN_HOVER=§cBanne Spieler wegen Bannumgehung MUTE_MESSAGE_YOU=§7Du hast §e{0} §7gemutet§8. §7Grund§8: §c{1}