From d09f8edfa2fc7f3eff4c9dcc5452f3ad6740f05a Mon Sep 17 00:00:00 2001 From: Lixfel Date: Fri, 5 Jul 2024 10:09:29 +0200 Subject: [PATCH] Fix BauLock, 1.15 - 1.20.1 Tablist, Builderserver, BugCommand Signed-off-by: Lixfel --- CommonCore | 2 +- .../steamwar/messages/BungeeCore.properties | 2 +- .../messages/BungeeCore_de.properties | 2 +- .../steamwar/velocitycore/ServerStarter.java | 2 +- .../velocitycore/commands/BauCommand.java | 16 ++++-- .../velocitycore/commands/BugCommand.java | 4 +- .../velocitycore/commands/TpCommand.java | 4 +- .../velocitycore/tablist/Tablist.java | 53 +++++++++++++++++++ .../velocitycore/tablist/TablistManager.java | 2 +- .../steamwar/velocitycore/util/BauLock.java | 9 +--- 10 files changed, 75 insertions(+), 21 deletions(-) diff --git a/CommonCore b/CommonCore index e76473e0..1237a699 160000 --- a/CommonCore +++ b/CommonCore @@ -1 +1 @@ -Subproject commit e76473e0beffe3df5c6d1c3430f62332b7371579 +Subproject commit 1237a699ba244ecfac65478df34e714afbe2366e diff --git a/src/de/steamwar/messages/BungeeCore.properties b/src/de/steamwar/messages/BungeeCore.properties index 870d5806..0e45249f 100644 --- a/src/de/steamwar/messages/BungeeCore.properties +++ b/src/de/steamwar/messages/BungeeCore.properties @@ -184,7 +184,7 @@ UNNOTEAMSERVER=§e{0} §7may now set §e§lteam servers§7 again§8. NOTE_TEAM={0} §e{1} §7received a §e§lnote§7 from §e{2} {3}: §f{4} #BugCommand -BUG_MESSAGE=§7Your bugreport was saved. +BUG_MESSAGE=§7Please describe the issue in a Discord ticket with the bug ID §e{0} §7further§8. #IgnoreCommand IGNORE_YOURSELF=§cHow are you going to ignore yourself? diff --git a/src/de/steamwar/messages/BungeeCore_de.properties b/src/de/steamwar/messages/BungeeCore_de.properties index c61446ee..c52b6a99 100644 --- a/src/de/steamwar/messages/BungeeCore_de.properties +++ b/src/de/steamwar/messages/BungeeCore_de.properties @@ -168,7 +168,7 @@ UNNOTEAMSERVER=§e{0} §7darf nun wieder §e§lTeamserver§7 setzen§8. NOTE_TEAM={0} §e{1} §7erhielt von §e{2} {3} §7die §e§lNotiz§7§8: §f{4} #BugCommand -BUG_MESSAGE=§7Dein Bugreport wurde gespeichert. +BUG_MESSAGE=§7Bitte beschreibe das Problem in einem Discordticket genauer und gebe dabei die Bug-ID §e{0} §7an§8. #IgnoreCommand IGNORE_YOURSELF=§cWie willst du dich selber ignorieren? diff --git a/src/de/steamwar/velocitycore/ServerStarter.java b/src/de/steamwar/velocitycore/ServerStarter.java index aa7e14f7..75edf040 100644 --- a/src/de/steamwar/velocitycore/ServerStarter.java +++ b/src/de/steamwar/velocitycore/ServerStarter.java @@ -214,7 +214,7 @@ public class ServerStarter { directory = version.getServerDirectory("Builder"); worldDir = version.getWorldFolder(BUILDER_BASE_PATH); worldName = map; - serverNameProvider = port -> map + "⛏"; + serverNameProvider = port -> "*" + map; checkpoint = true; constructor = (serverName, port, builder, shutdownCallback, failureCallback) -> new Builderserver(serverName, worldName, port, builder, shutdownCallback, failureCallback); diff --git a/src/de/steamwar/velocitycore/commands/BauCommand.java b/src/de/steamwar/velocitycore/commands/BauCommand.java index d53b2e95..037b4ab6 100644 --- a/src/de/steamwar/velocitycore/commands/BauCommand.java +++ b/src/de/steamwar/velocitycore/commands/BauCommand.java @@ -93,17 +93,23 @@ public class BauCommand extends SWCommand { @Validator(value = "teleportTarget", local = true) public TypeValidator teleportTargetValidator() { - return (sender, value, messageSender) -> { - if (value == null) { + return (sender, owner, messageSender) -> { + if (owner == null) { messageSender.send("UNKNOWN_PLAYER"); return false; } - if (sender.user().getId() != value.getId() && BauweltMember.getBauMember(value.getId(), sender.user().getId()) == null) { - SubserverSystem.sendDeniedMessage(sender, value.getUUID()); + if (sender.user().getId() != owner.getId() && BauweltMember.getBauMember(owner.getId(), sender.user().getId()) == null) { + SubserverSystem.sendDeniedMessage(sender, owner.getUUID()); messageSender.send("BAU_TP_NOALLOWED"); return false; } - return !BauLock.checkNotifyLocked(value, sender); + + if (BauLock.isLocked(owner, sender.user())) { + messageSender.send("BAU_LOCKED_NOALLOWED"); + Chatter.of(owner.getUUID()).system("BAU_LOCK_BLOCKED", sender); + return false; + } + return true; }; } diff --git a/src/de/steamwar/velocitycore/commands/BugCommand.java b/src/de/steamwar/velocitycore/commands/BugCommand.java index 58172a02..22c9f391 100644 --- a/src/de/steamwar/velocitycore/commands/BugCommand.java +++ b/src/de/steamwar/velocitycore/commands/BugCommand.java @@ -30,10 +30,10 @@ public class BugCommand extends SWCommand { @Register public void bugMessage(Chatter sender, String... message) { - SWException.log( + int id = SWException.logGetId( String.join(" ", message), sender.withPlayerOrOffline(player -> player.getCurrentServer().map(connection -> connection.getServerInfo().getName()).orElse("offline"), () -> "offline") + " " + sender.user().getUserName() + " " + sender.user().getId() ); - sender.system("BUG_MESSAGE"); + sender.system("BUG_MESSAGE", id); } } diff --git a/src/de/steamwar/velocitycore/commands/TpCommand.java b/src/de/steamwar/velocitycore/commands/TpCommand.java index 8bd203c0..031e2baa 100644 --- a/src/de/steamwar/velocitycore/commands/TpCommand.java +++ b/src/de/steamwar/velocitycore/commands/TpCommand.java @@ -124,7 +124,9 @@ public class TpCommand extends SWCommand { sender.system("JOIN_PLAYER_BLOCK"); return; } - } else if (BauLock.checkNotifyLocked(SteamwarUser.get(bauserver.getOwner()), sender)) { + } else if (BauLock.isLocked(SteamwarUser.get(bauserver.getOwner()), sender.user())) { + sender.system("BAU_LOCKED_NOALLOWED"); + Chatter.of(bauserver.getOwner()).system("BAU_LOCK_BLOCKED", sender); return; } else if (!bauserver.getOwner().equals(sender.user().getUUID()) && BauweltMember.getBauMember(bauserver.getOwner(), sender.user().getUUID()) == null) { SubserverSystem.sendDeniedMessage(sender, bauserver.getOwner()); diff --git a/src/de/steamwar/velocitycore/tablist/Tablist.java b/src/de/steamwar/velocitycore/tablist/Tablist.java index 4d687029..31c404bc 100644 --- a/src/de/steamwar/velocitycore/tablist/Tablist.java +++ b/src/de/steamwar/velocitycore/tablist/Tablist.java @@ -19,12 +19,14 @@ package de.steamwar.velocitycore.tablist; +import com.velocitypowered.api.network.ProtocolVersion; import com.velocitypowered.api.proxy.Player; import com.velocitypowered.api.util.GameProfile; import com.velocitypowered.proxy.connection.backend.VelocityServerConnection; import com.velocitypowered.proxy.connection.client.ConnectedPlayer; 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.UpsertPlayerInfoPacket; import com.velocitypowered.proxy.protocol.packet.chat.ComponentHolder; @@ -205,6 +207,40 @@ public class Tablist extends ChannelInboundHandlerAdapter { directTabItems.remove(uuid); } } + } else if(msg instanceof LegacyPlayerListItemPacket packet) { + if(packet.getAction() == LegacyPlayerListItemPacket.ADD_PLAYER) { + for(LegacyPlayerListItemPacket.Item entry : packet.getItems()) { + entry.setLatency(1).setPlayerKey(null); + + if (!Storage.teamServers.containsValue(connection.getServerInfo())) { + entry.setDisplayName(Component.empty()); + } else if (entry.getDisplayName() == null) { + entry.setDisplayName(Component.text(entry.getName()).color(NamedTextColor.GRAY)); + } + + UpsertPlayerInfoPacket.Entry newEntry = new UpsertPlayerInfoPacket.Entry(entry.getUuid()); + newEntry.setProfile(new GameProfile(entry.getUuid(), entry.getName(), entry.getProperties())); + newEntry.setDisplayName(new ComponentHolder(player.getProtocolVersion(), entry.getDisplayName())); + newEntry.setListed(true); + synchronized (directTabItems) { + directTabItems.put(entry.getUuid(), newEntry); + } + } + } else if(packet.getAction() == LegacyPlayerListItemPacket.UPDATE_GAMEMODE) { + for(LegacyPlayerListItemPacket.Item entry : packet.getItems()) { + if(!player.getUniqueId().equals(entry.getUuid()) && entry.getGameMode() == 3) + entry.setGameMode(1); + } + } else if(packet.getAction() == LegacyPlayerListItemPacket.REMOVE_PLAYER) { + for(LegacyPlayerListItemPacket.Item entry : packet.getItems()) { + synchronized (directTabItems) { + directTabItems.remove(entry.getUuid()); + } + } + } else { + ReferenceCountUtil.release(msg); + return; + } } ctx.fireChannelRead(msg); @@ -214,6 +250,23 @@ public class Tablist extends ChannelInboundHandlerAdapter { if(items.isEmpty()) return; + if(player.getProtocolVersion().lessThan(ProtocolVersion.MINECRAFT_1_19_3)) { + int legacyAction = LegacyPlayerListItemPacket.REMOVE_PLAYER; + if(action == UpsertPlayerInfoPacket.Action.UPDATE_DISPLAY_NAME) + legacyAction = LegacyPlayerListItemPacket.UPDATE_DISPLAY_NAME; + else if (action == UpsertPlayerInfoPacket.Action.ADD_PLAYER) + legacyAction = LegacyPlayerListItemPacket.ADD_PLAYER; + + sendPacket(player, new LegacyPlayerListItemPacket(legacyAction, items.stream().map(item -> new LegacyPlayerListItemPacket + .Item(item.getProfileId()) + .setName(item.getProfile().getName()) + .setProperties(item.getProfile().getProperties()) + .setDisplayName(item.getDisplayName().getComponent()) + .setLatency(item.getLatency()) + .setGameMode(item.getGameMode())).toList())); + return; + } + if(action == null) { //REMOVE sendPacket(player, new RemovePlayerInfoPacket(items.stream().map(item -> item.getProfile().getId()).toList())); return; diff --git a/src/de/steamwar/velocitycore/tablist/TablistManager.java b/src/de/steamwar/velocitycore/tablist/TablistManager.java index 4a8c6210..5189f4cb 100644 --- a/src/de/steamwar/velocitycore/tablist/TablistManager.java +++ b/src/de/steamwar/velocitycore/tablist/TablistManager.java @@ -61,10 +61,10 @@ public class TablistManager extends BasicListener { @Subscribe public void onJoin(PostLoginEvent event) { - Tablist.sendPacket(event.getPlayer(), createTeamPacket); synchronized (tablists) { tablists.put(event.getPlayer(), new Tablist(event.getPlayer())); } + Tablist.sendPacket(event.getPlayer(), createTeamPacket); } @Subscribe diff --git a/src/de/steamwar/velocitycore/util/BauLock.java b/src/de/steamwar/velocitycore/util/BauLock.java index 1352d95f..03bc4315 100644 --- a/src/de/steamwar/velocitycore/util/BauLock.java +++ b/src/de/steamwar/velocitycore/util/BauLock.java @@ -34,8 +34,7 @@ public class BauLock { owner.system("BAU_LOCKED_" + state.name()); } - public static boolean checkNotifyLocked(SteamwarUser owner, Chatter sender) { - SteamwarUser target = sender.user(); + public static boolean isLocked(SteamwarUser owner, SteamwarUser target) { if (owner.getId() == target.getId()) return false; @@ -62,12 +61,6 @@ public class BauLock { locked = false; } - if(locked) { - sender.system("BAU_LOCKED_NOALLOWED"); - Chatter.of(owner.getUUID()).system("BAU_LOCK_BLOCKED", sender); - } - return locked; } - }