SteamWar/BungeeCore
Archiviert
13
2

Fix BrandListener performance
Alle Prüfungen waren erfolgreich
SteamWarCI Build successful

Signed-off-by: Lixfel <agga-games@gmx.de>
Dieser Commit ist enthalten in:
Lixfel 2022-04-24 08:29:21 +02:00
Ursprung f2df750894
Commit f30b779347

Datei anzeigen

@ -19,17 +19,14 @@
package de.steamwar.bungeecore.listeners; package de.steamwar.bungeecore.listeners;
import de.steamwar.bungeecore.BungeeCore; import de.steamwar.messages.ChatSender;
import de.steamwar.bungeecore.Message;
import io.netty.buffer.ByteBuf; import io.netty.buffer.ByteBuf;
import io.netty.buffer.ByteBufAllocator; 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.connection.ProxiedPlayer;
import net.md_5.bungee.api.event.PluginMessageEvent; import net.md_5.bungee.api.event.PluginMessageEvent;
import net.md_5.bungee.event.EventHandler; import net.md_5.bungee.event.EventHandler;
import net.md_5.bungee.protocol.DefinedPacket; import net.md_5.bungee.protocol.DefinedPacket;
import net.md_5.bungee.protocol.ProtocolConstants;
import java.util.concurrent.TimeUnit;
public class BrandListener extends BasicListener { public class BrandListener extends BasicListener {
@ -42,27 +39,18 @@ public class BrandListener extends BasicListener {
if(event.getReceiver().getAddress().getHostName().contains("localhost")) { if(event.getReceiver().getAddress().getHostName().contains("localhost")) {
return; return;
} }
event.setCancelled(true);
if (!(event.getReceiver() instanceof ProxiedPlayer)) { if (!(event.getReceiver() instanceof ProxiedPlayer)) {
return; return;
} }
ProxiedPlayer player = (ProxiedPlayer) event.getReceiver();
BungeeCore.get().getProxy().getScheduler().schedule(BungeeCore.get(), () -> { event.setCancelled(true);
ProxiedPlayer player = (ProxiedPlayer) event.getReceiver(); 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 channel = player.getPendingConnection().getVersion() >= ProtocolConstants.MINECRAFT_1_13 ? "minecraft:brand" : "MC|Brand"; ByteBuf brand = ByteBufAllocator.DEFAULT.heapBuffer();
StringBuilder serverBrand = new StringBuilder(); DefinedPacket.writeString(brandString, brand);
for (byte b:event.getData()) { player.sendData(event.getTag(), DefinedPacket.toArray(brand));
serverBrand.append((char) b); brand.release();
}
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);
} }
} }