From e2024a481b1d022aad8c2c8c7caaaf7b837d8122 Mon Sep 17 00:00:00 2001 From: Lixfel Date: Fri, 5 Jul 2024 10:32:16 +0200 Subject: [PATCH] Fix 1.20.2+ Tablist order after server switch, Test fix commands Signed-off-by: Lixfel --- .../velocitycore/listeners/ChatListener.java | 5 ++++- src/de/steamwar/velocitycore/tablist/Tablist.java | 9 ++++++--- .../velocitycore/tablist/TablistManager.java | 13 ++++++------- 3 files changed, 16 insertions(+), 11 deletions(-) diff --git a/src/de/steamwar/velocitycore/listeners/ChatListener.java b/src/de/steamwar/velocitycore/listeners/ChatListener.java index ccec6edb..74429c13 100644 --- a/src/de/steamwar/velocitycore/listeners/ChatListener.java +++ b/src/de/steamwar/velocitycore/listeners/ChatListener.java @@ -74,7 +74,7 @@ public class ChatListener extends BasicListener { public void logCommands(CommandExecuteEvent e) { String command = e.getCommand(); int space = command.indexOf(' '); - if(e.getResult().isAllowed() && VelocityCore.getProxy().getCommandManager().hasCommand(space != -1 ? command.substring(0, space) : command)) { + if(VelocityCore.getProxy().getCommandManager().hasCommand(space != -1 ? command.substring(0, space) : command)) { CommandSource source = e.getCommandSource(); String name; if(source instanceof Player player) @@ -85,6 +85,9 @@ public class ChatListener extends BasicListener { name = source.toString(); cmdLogger.log(Level.INFO, "%s -> executed command /%s".formatted(name, command)); + } else if (e.getCommandSource() instanceof Player player) { + player.spoofChatInput("/" + command); + e.setResult(CommandExecuteEvent.CommandResult.denied()); } } diff --git a/src/de/steamwar/velocitycore/tablist/Tablist.java b/src/de/steamwar/velocitycore/tablist/Tablist.java index e87948a9..f8dc1783 100644 --- a/src/de/steamwar/velocitycore/tablist/Tablist.java +++ b/src/de/steamwar/velocitycore/tablist/Tablist.java @@ -28,6 +28,7 @@ import com.velocitypowered.proxy.network.Connections; import com.velocitypowered.proxy.protocol.MinecraftPacket; import com.velocitypowered.proxy.protocol.packet.LegacyPlayerListItemPacket; import com.velocitypowered.proxy.protocol.packet.RemovePlayerInfoPacket; +import com.velocitypowered.proxy.protocol.packet.UpdateTeamsPacket; import com.velocitypowered.proxy.protocol.packet.UpsertPlayerInfoPacket; import com.velocitypowered.proxy.protocol.packet.chat.ComponentHolder; import de.steamwar.messages.Chatter; @@ -48,8 +49,8 @@ import java.util.stream.IntStream; public class Tablist extends ChannelInboundHandlerAdapter { private static final UUID[] swUuids = IntStream.range(0, 80).mapToObj(i -> UUID.randomUUID()).toArray(UUID[]::new); - public static final String[] swNames = IntStream.range(0, 80).mapToObj(i -> " »SW« " + String.format("%02d", i)).toArray(String[]::new); - public static final String TAB_TEAM = "zzzzzsw-tab"; + private static final String[] swNames = IntStream.range(0, 80).mapToObj(i -> " »SW« " + String.format("%02d", i)).toArray(String[]::new); + public static final UpdateTeamsPacket createTeamPacket = new UpdateTeamsPacket("zzzzzsw-tab", UpdateTeamsPacket.Mode.CREATE, Component.empty(), Component.empty(), Component.empty(), UpdateTeamsPacket.NameTagVisibility.NEVER, UpdateTeamsPacket.CollisionRule.ALWAYS, 21, (byte)0x00, Arrays.stream(Tablist.swNames).toList()); private final Map directTabItems; private final List current = new ArrayList<>(); @@ -139,8 +140,10 @@ public class Tablist extends ChannelInboundHandlerAdapter { directTabItems.clear(); } - if(player.getProtocolVersion().greaterThan(ProtocolVersion.MINECRAFT_1_20)) + if(player.getProtocolVersion().greaterThan(ProtocolVersion.MINECRAFT_1_20)) { current.clear(); + sendPacket(player, createTeamPacket); + } } private void injection() { diff --git a/src/de/steamwar/velocitycore/tablist/TablistManager.java b/src/de/steamwar/velocitycore/tablist/TablistManager.java index 5189f4cb..2b8b47bd 100644 --- a/src/de/steamwar/velocitycore/tablist/TablistManager.java +++ b/src/de/steamwar/velocitycore/tablist/TablistManager.java @@ -25,16 +25,17 @@ import com.velocitypowered.api.event.connection.PostLoginEvent; import com.velocitypowered.api.event.player.ServerPostConnectEvent; import com.velocitypowered.api.proxy.Player; import com.velocitypowered.api.proxy.server.RegisteredServer; -import com.velocitypowered.proxy.protocol.packet.UpdateTeamsPacket; +import de.steamwar.network.packets.common.FightInfoPacket; import de.steamwar.persistent.Servertype; import de.steamwar.persistent.Storage; import de.steamwar.persistent.Subserver; import de.steamwar.velocitycore.VelocityCore; import de.steamwar.velocitycore.listeners.BasicListener; -import de.steamwar.network.packets.common.FightInfoPacket; -import net.kyori.adventure.text.Component; -import java.util.*; +import java.util.ArrayList; +import java.util.HashMap; +import java.util.List; +import java.util.Map; import java.util.concurrent.TimeUnit; public class TablistManager extends BasicListener { @@ -46,8 +47,6 @@ public class TablistManager extends BasicListener { fightInfos.keySet().removeIf(serverInfo -> serverInfo.getPlayersConnected().isEmpty()); } - private static final UpdateTeamsPacket createTeamPacket = new UpdateTeamsPacket(Tablist.TAB_TEAM, UpdateTeamsPacket.Mode.CREATE, Component.empty(), Component.empty(), Component.empty(), UpdateTeamsPacket.NameTagVisibility.NEVER, UpdateTeamsPacket.CollisionRule.ALWAYS, 21, (byte)0x00, Arrays.stream(Tablist.swNames).toList()); - private final Map tablists = new HashMap<>(); private int seconds = 0; @@ -64,7 +63,7 @@ public class TablistManager extends BasicListener { synchronized (tablists) { tablists.put(event.getPlayer(), new Tablist(event.getPlayer())); } - Tablist.sendPacket(event.getPlayer(), createTeamPacket); + Tablist.sendPacket(event.getPlayer(), Tablist.createTeamPacket); } @Subscribe