From 6e158b38b8ae5f52e2c374be6386f22ecd07dac0 Mon Sep 17 00:00:00 2001 From: yoyosource Date: Wed, 27 Apr 2022 09:58:15 +0200 Subject: [PATCH] Speed BrandListener up --- .../bungeecore/listeners/BrandListener.java | 17 ++++++++++++++++- 1 file changed, 16 insertions(+), 1 deletion(-) diff --git a/src/de/steamwar/bungeecore/listeners/BrandListener.java b/src/de/steamwar/bungeecore/listeners/BrandListener.java index c26baa7..fae5fb3 100644 --- a/src/de/steamwar/bungeecore/listeners/BrandListener.java +++ b/src/de/steamwar/bungeecore/listeners/BrandListener.java @@ -28,15 +28,30 @@ import net.md_5.bungee.api.event.PluginMessageEvent; import net.md_5.bungee.event.EventHandler; import net.md_5.bungee.protocol.DefinedPacket; +import java.net.InetAddress; +import java.net.NetworkInterface; +import java.net.SocketException; + public class BrandListener extends BasicListener { + private static boolean isLocalHost(InetAddress addr) { + if (addr.isAnyLocalAddress() || addr.isLoopbackAddress()) { + return true; + } + try { + return NetworkInterface.getByInetAddress(addr) != null; + } catch (SocketException e) { + return false; + } + } + @EventHandler public void onServerSwitch(PluginMessageEvent event) { if(!event.getTag().equals("minecraft:brand") && !event.getTag().equals("MC|Brand")) { return; } - if(event.getReceiver().getAddress().getHostName().contains("localhost")) { + if (isLocalHost(event.getReceiver().getAddress().getAddress())) { return; }