From 65fcb5329fb2add88a8b747fd2830909414cd03a Mon Sep 17 00:00:00 2001 From: Lixfel Date: Sun, 24 Sep 2023 08:27:47 +0200 Subject: [PATCH] Queue Packets Signed-off-by: Lixfel --- .../bungeecore/listeners/mods/Badlion.java | 3 +-- .../steamwar/bungeecore/tablist/Tablist.java | 20 ++++++++++--------- 2 files changed, 12 insertions(+), 11 deletions(-) diff --git a/src/de/steamwar/bungeecore/listeners/mods/Badlion.java b/src/de/steamwar/bungeecore/listeners/mods/Badlion.java index cfc9ab70..ce01ce43 100644 --- a/src/de/steamwar/bungeecore/listeners/mods/Badlion.java +++ b/src/de/steamwar/bungeecore/listeners/mods/Badlion.java @@ -3,7 +3,6 @@ package de.steamwar.bungeecore.listeners.mods; import de.steamwar.bungeecore.listeners.BasicListener; import net.md_5.bungee.api.event.PostLoginEvent; import net.md_5.bungee.event.EventHandler; -import net.md_5.bungee.protocol.packet.PluginMessage; public class Badlion extends BasicListener { @@ -27,6 +26,6 @@ public class Badlion extends BasicListener { } */ - event.getPlayer().unsafe().sendPacket(new PluginMessage("badlion:mods", ("{\"Clear Glass\":{\"disabled\":true},\"ClearWater\":{\"disabled\":true},\"FOV Changer\":{\"disabled\":true},\"Hitboxes\":{\"disabled\":true},\"MiniMap\":{\"disabled\":true},\"MLG Cobweb\":{\"disabled\":true},\"Replay\":{\"disabled\":true},\"Schematica\":{\"disabled\":true},\"ToggleSneak\":{\"disabled\":true},\"ToggleSprint\":{\"disabled\":true},\"TNT Time\":{\"disabled\":true}}").getBytes(), false)); + event.getPlayer().sendData("badlion:mods", ("{\"Clear Glass\":{\"disabled\":true},\"ClearWater\":{\"disabled\":true},\"FOV Changer\":{\"disabled\":true},\"Hitboxes\":{\"disabled\":true},\"MiniMap\":{\"disabled\":true},\"MLG Cobweb\":{\"disabled\":true},\"Replay\":{\"disabled\":true},\"Schematica\":{\"disabled\":true},\"ToggleSneak\":{\"disabled\":true},\"ToggleSprint\":{\"disabled\":true},\"TNT Time\":{\"disabled\":true}}").getBytes()); } } diff --git a/src/de/steamwar/bungeecore/tablist/Tablist.java b/src/de/steamwar/bungeecore/tablist/Tablist.java index 1b2a7b41..bc0858e2 100644 --- a/src/de/steamwar/bungeecore/tablist/Tablist.java +++ b/src/de/steamwar/bungeecore/tablist/Tablist.java @@ -26,6 +26,7 @@ import io.netty.channel.ChannelHandlerContext; import io.netty.channel.ChannelPipeline; import io.netty.handler.codec.MessageToMessageDecoder; import net.md_5.bungee.ServerConnection; +import net.md_5.bungee.UserConnection; import net.md_5.bungee.api.ProxyServer; import net.md_5.bungee.api.chat.BaseComponent; import net.md_5.bungee.api.chat.TextComponent; @@ -68,10 +69,7 @@ public class Tablist extends MessageToMessageDecoder { if (connection == null) return; - player.unsafe().sendPacket(new PlayerListHeaderFooter( - ComponentSerializer.toString(header(viewer, seconds)), - ComponentSerializer.toString(viewer.parse(false, "TABLIST_FOOTER", connection.getInfo().getName(), ping(), ProxyServer.getInstance().getPlayers().size())) - )); + player.setTabHeader(header(viewer, seconds), viewer.parse(false, "TABLIST_FOOTER", connection.getInfo().getName(), ping(), ProxyServer.getInstance().getPlayers().size())); List tablist = new ArrayList<>(); List direct = new ArrayList<>(); @@ -168,7 +166,7 @@ public class Tablist extends MessageToMessageDecoder { pipeline.remove("steamwar-tablist"); pipeline.addBefore(PipelineUtils.BOSS_HANDLER, "steamwar-tablist", this); - player.unsafe().sendPacket(teamPacket); + sendQueued(player, teamPacket); } } @@ -312,16 +310,16 @@ public class Tablist extends MessageToMessageDecoder { PlayerListItem packet = new PlayerListItem(); packet.setAction(action); packet.setItems(items.toArray(new PlayerListItem.Item[0])); - player.unsafe().sendPacket(packet); + sendQueued(player, packet); } else if(action == PlayerListItem.Action.REMOVE_PLAYER) { PlayerListItemRemove packet = new PlayerListItemRemove(); packet.setUuids(items.stream().map(PlayerListItem.Item::getUuid).toArray(UUID[]::new)); - player.unsafe().sendPacket(packet); + sendQueued(player, packet); } else { PlayerListItemUpdate packet = new PlayerListItemUpdate(); packet.setActions(action == PlayerListItem.Action.UPDATE_DISPLAY_NAME ? EnumSet.of(PlayerListItemUpdate.Action.UPDATE_DISPLAY_NAME, PlayerListItemUpdate.Action.UPDATE_LISTED) : EnumSet.of(PlayerListItemUpdate.Action.ADD_PLAYER, PlayerListItemUpdate.Action.UPDATE_DISPLAY_NAME, PlayerListItemUpdate.Action.UPDATE_LATENCY, PlayerListItemUpdate.Action.UPDATE_LISTED, PlayerListItemUpdate.Action.UPDATE_GAMEMODE)); packet.setItems(items.toArray(new PlayerListItem.Item[0])); - player.unsafe().sendPacket(packet); + sendQueued(player, packet); } } } @@ -331,7 +329,7 @@ public class Tablist extends MessageToMessageDecoder { Team packet = new Team(TAB_TEAM); packet.setMode((byte) (remove ? 4 : 3)); packet.setPlayers(names.toArray(new String[0])); - player.unsafe().sendPacket(packet); + sendQueued(player, packet); } } @@ -357,4 +355,8 @@ public class Tablist extends MessageToMessageDecoder { return "§c" + ping; } } + + private static void sendQueued(ProxiedPlayer player, DefinedPacket packet) { + ((UserConnection)player).sendPacketQueued(packet); + } }