From 68ce7330ef4d3dc46677f1e0806b0bdc7a54f81a Mon Sep 17 00:00:00 2001 From: Chaoscaot Date: Thu, 10 Dec 2020 19:18:50 +0100 Subject: [PATCH] Fixing Double Execution of Code --- .../bungeecore/listeners/BanListener.java | 16 ++++++++++------ 1 file changed, 10 insertions(+), 6 deletions(-) diff --git a/src/de/steamwar/bungeecore/listeners/BanListener.java b/src/de/steamwar/bungeecore/listeners/BanListener.java index d996c90..810e95a 100644 --- a/src/de/steamwar/bungeecore/listeners/BanListener.java +++ b/src/de/steamwar/bungeecore/listeners/BanListener.java @@ -52,6 +52,15 @@ public class BanListener extends BasicListener { List ips = BannedUserIPs.get(event.getConnection().getAddress().getAddress().getHostAddress()); if(!ips.isEmpty()){ + Timestamp highestBan = Timestamp.from(Instant.now()); + for(BannedUserIPs banned : ips) { + if(highestBan.before(banned.getTimestamp())) + highestBan = banned.getTimestamp(); + } + ClickEvent clickEvent = new ClickEvent(ClickEvent.Action.RUN_COMMAND, "/ban " + user.getUserName() + " " + + highestBan.toLocalDateTime().format(DateTimeFormatter.ofPattern("dd.MM.yyyy_HH:mm")) + + " Bannumgehung"); + for (ProxiedPlayer target : ProxyServer.getInstance().getPlayers()){ if ((target.hasPermission("bungeecore.teamchat")) && (target.getChatMode() == ProxiedPlayer.ChatMode.COMMANDS_ONLY @@ -59,20 +68,15 @@ public class BanListener extends BasicListener { 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")); + msg.setClickEvent(clickEvent); target.sendMessage(msg); } }