From f30b7793476960ce7863d08671b49a945bb3519d Mon Sep 17 00:00:00 2001 From: Lixfel Date: Sun, 24 Apr 2022 08:29:21 +0200 Subject: [PATCH] Fix BrandListener performance Signed-off-by: Lixfel --- .../bungeecore/listeners/BrandListener.java | 30 ++++++------------- 1 file changed, 9 insertions(+), 21 deletions(-) diff --git a/src/de/steamwar/bungeecore/listeners/BrandListener.java b/src/de/steamwar/bungeecore/listeners/BrandListener.java index 4c810de..c26baa7 100644 --- a/src/de/steamwar/bungeecore/listeners/BrandListener.java +++ b/src/de/steamwar/bungeecore/listeners/BrandListener.java @@ -19,17 +19,14 @@ package de.steamwar.bungeecore.listeners; -import de.steamwar.bungeecore.BungeeCore; -import de.steamwar.bungeecore.Message; +import de.steamwar.messages.ChatSender; import io.netty.buffer.ByteBuf; import io.netty.buffer.ByteBufAllocator; +import net.md_5.bungee.api.ProxyServer; import net.md_5.bungee.api.connection.ProxiedPlayer; import net.md_5.bungee.api.event.PluginMessageEvent; import net.md_5.bungee.event.EventHandler; import net.md_5.bungee.protocol.DefinedPacket; -import net.md_5.bungee.protocol.ProtocolConstants; - -import java.util.concurrent.TimeUnit; public class BrandListener extends BasicListener { @@ -42,27 +39,18 @@ public class BrandListener extends BasicListener { if(event.getReceiver().getAddress().getHostName().contains("localhost")) { return; } - event.setCancelled(true); if (!(event.getReceiver() instanceof ProxiedPlayer)) { return; } + ProxiedPlayer player = (ProxiedPlayer) event.getReceiver(); - BungeeCore.get().getProxy().getScheduler().schedule(BungeeCore.get(), () -> { - ProxiedPlayer player = (ProxiedPlayer) event.getReceiver(); - - String channel = player.getPendingConnection().getVersion() >= ProtocolConstants.MINECRAFT_1_13 ? "minecraft:brand" : "MC|Brand"; - StringBuilder serverBrand = new StringBuilder(); - for (byte b:event.getData()) { - serverBrand.append((char) b); - } + event.setCancelled(true); + String brandString = ChatSender.of(player).parseToLegacy("STEAMWAR_BRAND", ProxyServer.getInstance().getName(), player.getServer().getInfo().getName(), new String(event.getData(), 1, event.getData().length - 1)); - String brandString = Message.parse("STEAMWAR_BRAND", player, BungeeCore.get().getProxy().getName(), player.getServer().getInfo().getName(), serverBrand.substring(1)); - - ByteBuf brand = ByteBufAllocator.DEFAULT.heapBuffer(); - DefinedPacket.writeString(brandString, brand); - player.sendData(channel, DefinedPacket.toArray(brand)); - brand.release(); - }, 50, TimeUnit.MILLISECONDS); + ByteBuf brand = ByteBufAllocator.DEFAULT.heapBuffer(); + DefinedPacket.writeString(brandString, brand); + player.sendData(event.getTag(), DefinedPacket.toArray(brand)); + brand.release(); } }