From 1039b8556be48e20a71af946138eb8aa0877dbc3 Mon Sep 17 00:00:00 2001 From: EnZaXD Date: Thu, 13 Jun 2024 18:34:55 +0200 Subject: [PATCH 1/6] Add remaining item types to item rewriter implementations (#3931) --- .../v1_11to1_11_1/rewriter/ItemPacketRewriter1_11_1.java | 2 +- .../v1_12_2to1_13/rewriter/ItemPacketRewriter1_13.java | 2 +- .../protocols/v1_8to1_9/rewriter/ItemPacketRewriter1_9.java | 2 +- .../protocols/v1_9_3to1_10/rewriter/ItemPacketRewriter1_10.java | 2 +- 4 files changed, 4 insertions(+), 4 deletions(-) diff --git a/common/src/main/java/com/viaversion/viaversion/protocols/v1_11to1_11_1/rewriter/ItemPacketRewriter1_11_1.java b/common/src/main/java/com/viaversion/viaversion/protocols/v1_11to1_11_1/rewriter/ItemPacketRewriter1_11_1.java index d1eba3d31..4a1c94105 100644 --- a/common/src/main/java/com/viaversion/viaversion/protocols/v1_11to1_11_1/rewriter/ItemPacketRewriter1_11_1.java +++ b/common/src/main/java/com/viaversion/viaversion/protocols/v1_11to1_11_1/rewriter/ItemPacketRewriter1_11_1.java @@ -28,7 +28,7 @@ import com.viaversion.viaversion.rewriter.ItemRewriter; public class ItemPacketRewriter1_11_1 extends ItemRewriter { public ItemPacketRewriter1_11_1(Protocol1_11To1_11_1 protocol) { - super(protocol, Types.ITEM1_8, null); + super(protocol, Types.ITEM1_8, Types.ITEM1_8_SHORT_ARRAY); } @Override diff --git a/common/src/main/java/com/viaversion/viaversion/protocols/v1_12_2to1_13/rewriter/ItemPacketRewriter1_13.java b/common/src/main/java/com/viaversion/viaversion/protocols/v1_12_2to1_13/rewriter/ItemPacketRewriter1_13.java index 1cafb02a3..d27597d51 100644 --- a/common/src/main/java/com/viaversion/viaversion/protocols/v1_12_2to1_13/rewriter/ItemPacketRewriter1_13.java +++ b/common/src/main/java/com/viaversion/viaversion/protocols/v1_12_2to1_13/rewriter/ItemPacketRewriter1_13.java @@ -51,7 +51,7 @@ import java.util.Optional; public class ItemPacketRewriter1_13 extends ItemRewriter { public ItemPacketRewriter1_13(Protocol1_12_2To1_13 protocol) { - super(protocol, Types.ITEM1_8, null, Types.ITEM1_13, null); + super(protocol, Types.ITEM1_8, Types.ITEM1_8_SHORT_ARRAY, Types.ITEM1_13, Types.ITEM1_13_SHORT_ARRAY); } @Override diff --git a/common/src/main/java/com/viaversion/viaversion/protocols/v1_8to1_9/rewriter/ItemPacketRewriter1_9.java b/common/src/main/java/com/viaversion/viaversion/protocols/v1_8to1_9/rewriter/ItemPacketRewriter1_9.java index 483fa2d3d..dd4daf56c 100644 --- a/common/src/main/java/com/viaversion/viaversion/protocols/v1_8to1_9/rewriter/ItemPacketRewriter1_9.java +++ b/common/src/main/java/com/viaversion/viaversion/protocols/v1_8to1_9/rewriter/ItemPacketRewriter1_9.java @@ -43,7 +43,7 @@ import org.checkerframework.checker.nullness.qual.Nullable; public class ItemPacketRewriter1_9 extends ItemRewriter { public ItemPacketRewriter1_9(final Protocol1_8To1_9 protocol) { - super(protocol, Types.ITEM1_8, null); + super(protocol, Types.ITEM1_8, Types.ITEM1_8_SHORT_ARRAY); } @Override diff --git a/common/src/main/java/com/viaversion/viaversion/protocols/v1_9_3to1_10/rewriter/ItemPacketRewriter1_10.java b/common/src/main/java/com/viaversion/viaversion/protocols/v1_9_3to1_10/rewriter/ItemPacketRewriter1_10.java index b5a25239b..31a8a38cf 100644 --- a/common/src/main/java/com/viaversion/viaversion/protocols/v1_9_3to1_10/rewriter/ItemPacketRewriter1_10.java +++ b/common/src/main/java/com/viaversion/viaversion/protocols/v1_9_3to1_10/rewriter/ItemPacketRewriter1_10.java @@ -28,7 +28,7 @@ import com.viaversion.viaversion.rewriter.ItemRewriter; public class ItemPacketRewriter1_10 extends ItemRewriter { public ItemPacketRewriter1_10(Protocol1_9_3To1_10 protocol) { - super(protocol, Types.ITEM1_8, null); + super(protocol, Types.ITEM1_8, Types.ITEM1_8_SHORT_ARRAY); } @Override From 72cc9e99681aeeedeef358184bbdbf7cb5ad8107 Mon Sep 17 00:00:00 2001 From: EnZaXD Date: Thu, 13 Jun 2024 18:36:08 +0200 Subject: [PATCH 2/6] Add ability to detection level in /viaversion displayleaks (#3934) --- .../defaultsubs/DisplayLeaksSubCmd.java | 33 +++++++++++++++---- 1 file changed, 26 insertions(+), 7 deletions(-) diff --git a/common/src/main/java/com/viaversion/viaversion/commands/defaultsubs/DisplayLeaksSubCmd.java b/common/src/main/java/com/viaversion/viaversion/commands/defaultsubs/DisplayLeaksSubCmd.java index 4ad96d9e6..ad8dca9ea 100644 --- a/common/src/main/java/com/viaversion/viaversion/commands/defaultsubs/DisplayLeaksSubCmd.java +++ b/common/src/main/java/com/viaversion/viaversion/commands/defaultsubs/DisplayLeaksSubCmd.java @@ -20,11 +20,14 @@ package com.viaversion.viaversion.commands.defaultsubs; import com.viaversion.viaversion.api.command.ViaCommandSender; import com.viaversion.viaversion.api.command.ViaSubCommand; import io.netty.util.ResourceLeakDetector; +import java.util.Arrays; +import java.util.List; +import java.util.stream.Collectors; public class DisplayLeaksSubCmd implements ViaSubCommand { @Override public String name() { - return "displayleaks"; + return "displayleaks "; } @Override @@ -34,12 +37,28 @@ public class DisplayLeaksSubCmd implements ViaSubCommand { @Override public boolean execute(ViaCommandSender sender, String[] args) { - if (ResourceLeakDetector.getLevel() != ResourceLeakDetector.Level.PARANOID) - ResourceLeakDetector.setLevel(ResourceLeakDetector.Level.PARANOID); - else - ResourceLeakDetector.setLevel(ResourceLeakDetector.Level.DISABLED); - - sendMessage(sender, "&6Leak detector is now %s", (ResourceLeakDetector.getLevel() == ResourceLeakDetector.Level.PARANOID ? "&aenabled" : "&cdisabled")); + if (args.length == 1) { + try { + ResourceLeakDetector.Level level = ResourceLeakDetector.Level.valueOf(args[0]); + ResourceLeakDetector.setLevel(level); + sendMessage(sender, "&6Set leak detector level to &2" + level); + } catch (IllegalArgumentException e) { + sendMessage(sender, "&cInvalid level (" + Arrays.toString(ResourceLeakDetector.Level.values()) + ")"); + } + } else { + sendMessage(sender, "&6Current leak detection level is &2" + ResourceLeakDetector.getLevel()); + } return true; } + + @Override + public List onTabComplete(ViaCommandSender sender, String[] args) { + if (args.length == 1) { + return Arrays.stream(ResourceLeakDetector.Level.values()) + .map(Enum::name) + .filter(it -> it.startsWith(args[0])) + .collect(Collectors.toList()); + } + return ViaSubCommand.super.onTabComplete(sender, args); + } } From 4a70e0ea2a529e4f677fb324405caf4fbc8a7f2f Mon Sep 17 00:00:00 2001 From: EnZaXD Date: Thu, 13 Jun 2024 19:21:52 +0200 Subject: [PATCH 3/6] Fixup command registration once again (#3937) --- .../commands/defaultsubs/DisplayLeaksSubCmd.java | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/common/src/main/java/com/viaversion/viaversion/commands/defaultsubs/DisplayLeaksSubCmd.java b/common/src/main/java/com/viaversion/viaversion/commands/defaultsubs/DisplayLeaksSubCmd.java index ad8dca9ea..d21bc4728 100644 --- a/common/src/main/java/com/viaversion/viaversion/commands/defaultsubs/DisplayLeaksSubCmd.java +++ b/common/src/main/java/com/viaversion/viaversion/commands/defaultsubs/DisplayLeaksSubCmd.java @@ -27,7 +27,7 @@ import java.util.stream.Collectors; public class DisplayLeaksSubCmd implements ViaSubCommand { @Override public String name() { - return "displayleaks "; + return "displayleaks"; } @Override @@ -35,6 +35,11 @@ public class DisplayLeaksSubCmd implements ViaSubCommand { return "Try to hunt memory leaks!"; } + @Override + public String usage() { + return "displayleaks "; + } + @Override public boolean execute(ViaCommandSender sender, String[] args) { if (args.length == 1) { From 9e523c353ae292e4fab368521f0b9b4d33d16ec8 Mon Sep 17 00:00:00 2001 From: EnZaXD Date: Fri, 14 Jun 2024 10:17:42 +0200 Subject: [PATCH 4/6] Fix book signing in 1.8->1.9 (#3939) --- .../protocols/v1_8to1_9/rewriter/PlayerPacketRewriter1_9.java | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/common/src/main/java/com/viaversion/viaversion/protocols/v1_8to1_9/rewriter/PlayerPacketRewriter1_9.java b/common/src/main/java/com/viaversion/viaversion/protocols/v1_8to1_9/rewriter/PlayerPacketRewriter1_9.java index f7d7b8464..594b6e130 100644 --- a/common/src/main/java/com/viaversion/viaversion/protocols/v1_8to1_9/rewriter/PlayerPacketRewriter1_9.java +++ b/common/src/main/java/com/viaversion/viaversion/protocols/v1_8to1_9/rewriter/PlayerPacketRewriter1_9.java @@ -40,7 +40,6 @@ import com.viaversion.viaversion.protocols.v1_8to1_9.storage.ClientChunks; import com.viaversion.viaversion.protocols.v1_8to1_9.storage.EntityTracker1_9; import com.viaversion.viaversion.protocols.v1_8to1_9.storage.MovementTracker; import com.viaversion.viaversion.util.ComponentUtil; -import com.viaversion.viaversion.util.SerializerVersion; public class PlayerPacketRewriter1_9 { public static void register(Protocol1_8To1_9 protocol) { @@ -410,7 +409,7 @@ public class PlayerPacketRewriter1_9 { final StringTag pageTag = pages.get(i); final String value = pageTag.getValue(); - pageTag.setValue(ComponentUtil.convertJson(value, SerializerVersion.V1_9, SerializerVersion.V1_8).toString()); + pageTag.setValue(ComponentUtil.plainToJson(value).toString()); } } } From c68915b2613cd14870c7bb9f96170de268cb85c5 Mon Sep 17 00:00:00 2001 From: EnZaXD Date: Sat, 15 Jun 2024 15:05:26 +0200 Subject: [PATCH 5/6] Add /viaversion player command (#3932) --- .../commands/ViaCommandHandler.java | 2 + .../commands/defaultsubs/PlayerSubCmd.java | 75 +++++++++++++++++++ 2 files changed, 77 insertions(+) create mode 100644 common/src/main/java/com/viaversion/viaversion/commands/defaultsubs/PlayerSubCmd.java diff --git a/common/src/main/java/com/viaversion/viaversion/commands/ViaCommandHandler.java b/common/src/main/java/com/viaversion/viaversion/commands/ViaCommandHandler.java index 38e4d79e7..bc7bd4ff8 100644 --- a/common/src/main/java/com/viaversion/viaversion/commands/ViaCommandHandler.java +++ b/common/src/main/java/com/viaversion/viaversion/commands/ViaCommandHandler.java @@ -30,6 +30,7 @@ import com.viaversion.viaversion.commands.defaultsubs.DumpSubCmd; import com.viaversion.viaversion.commands.defaultsubs.ListSubCmd; import com.viaversion.viaversion.commands.defaultsubs.PPSSubCmd; import com.viaversion.viaversion.commands.defaultsubs.ReloadSubCmd; +import com.viaversion.viaversion.commands.defaultsubs.PlayerSubCmd; import java.util.ArrayList; import java.util.Arrays; import java.util.Collections; @@ -194,5 +195,6 @@ public abstract class ViaCommandHandler implements ViaVersionCommand { registerSubCommand(new DontBugMeSubCmd()); registerSubCommand(new AutoTeamSubCmd()); registerSubCommand(new ReloadSubCmd()); + registerSubCommand(new PlayerSubCmd()); } } diff --git a/common/src/main/java/com/viaversion/viaversion/commands/defaultsubs/PlayerSubCmd.java b/common/src/main/java/com/viaversion/viaversion/commands/defaultsubs/PlayerSubCmd.java new file mode 100644 index 000000000..8f309d024 --- /dev/null +++ b/common/src/main/java/com/viaversion/viaversion/commands/defaultsubs/PlayerSubCmd.java @@ -0,0 +1,75 @@ +/* + * This file is part of ViaVersion - https://github.com/ViaVersion/ViaVersion + * Copyright (C) 2016-2024 ViaVersion and contributors + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ +package com.viaversion.viaversion.commands.defaultsubs; + +import com.viaversion.viaversion.api.Via; +import com.viaversion.viaversion.api.command.ViaCommandSender; +import com.viaversion.viaversion.api.command.ViaSubCommand; +import com.viaversion.viaversion.api.connection.ProtocolInfo; +import com.viaversion.viaversion.api.connection.UserConnection; +import java.util.ArrayList; +import java.util.List; + +public class PlayerSubCmd implements ViaSubCommand { + @Override + public String name() { + return "player"; + } + + @Override + public String description() { + return "Shows connection information about one or all players."; + } + + @Override + public String usage() { + return "player "; + } + + @Override + public boolean execute(final ViaCommandSender sender, final String[] args) { + if (args.length == 0) { + return false; + } + for (final UserConnection connection : Via.getManager().getConnectionManager().getConnections()) { + final ProtocolInfo info = connection.getProtocolInfo(); + if (args[0].equalsIgnoreCase(info.getUsername()) || args[0].equals("*")) { + sendMessage(sender, "&7[&6" + info.getUsername() + "&7] UUID: &2" + info.getUuid() + " &7Client-Protocol: &2" + info.protocolVersion().getName() + " &7Server-Protocol: &2" + info.serverProtocolVersion().getName()); + } + } + return true; + } + + @Override + public List onTabComplete(final ViaCommandSender sender, final String[] args) { + if (args.length == 1) { + final String input = args[0].toLowerCase(); + + final List matches = new ArrayList<>(); + for (final UserConnection connection : Via.getManager().getConnectionManager().getConnections()) { + final String name = connection.getProtocolInfo().getUsername(); + if (input.isEmpty() || name.toLowerCase().startsWith(input)) { + matches.add(name); + } + } + matches.add("*"); + return matches; + } + return ViaSubCommand.super.onTabComplete(sender, args); + } +} From 9a9ca9676d3263c5a578b7cc066f003f9b6309a0 Mon Sep 17 00:00:00 2001 From: EnZaXD Date: Sat, 15 Jun 2024 15:53:09 +0200 Subject: [PATCH 6/6] Cleanup /viaversion list and pps command (#3933) --- .../commands/defaultsubs/ListSubCmd.java | 8 +++--- .../commands/defaultsubs/PPSSubCmd.java | 28 +++++++++---------- 2 files changed, 18 insertions(+), 18 deletions(-) diff --git a/common/src/main/java/com/viaversion/viaversion/commands/defaultsubs/ListSubCmd.java b/common/src/main/java/com/viaversion/viaversion/commands/defaultsubs/ListSubCmd.java index 81d9002b3..257ca9601 100644 --- a/common/src/main/java/com/viaversion/viaversion/commands/defaultsubs/ListSubCmd.java +++ b/common/src/main/java/com/viaversion/viaversion/commands/defaultsubs/ListSubCmd.java @@ -20,6 +20,7 @@ package com.viaversion.viaversion.commands.defaultsubs; import com.viaversion.viaversion.api.Via; import com.viaversion.viaversion.api.command.ViaCommandSender; import com.viaversion.viaversion.api.command.ViaSubCommand; +import com.viaversion.viaversion.api.connection.UserConnection; import com.viaversion.viaversion.api.protocol.version.ProtocolVersion; import java.util.HashSet; import java.util.Map; @@ -46,10 +47,9 @@ public class ListSubCmd implements ViaSubCommand { public boolean execute(ViaCommandSender sender, String[] args) { Map> playerVersions = new TreeMap<>(ProtocolVersion::compareTo); - for (ViaCommandSender p : Via.getPlatform().getOnlinePlayers()) { - int playerVersion = Via.getAPI().getPlayerVersion(p.getUUID()); - ProtocolVersion key = ProtocolVersion.getProtocol(playerVersion); - playerVersions.computeIfAbsent(key, s -> new HashSet<>()).add(p.getName()); + for (UserConnection p : Via.getManager().getConnectionManager().getConnections()) { + ProtocolVersion version = p.getProtocolInfo().protocolVersion(); + playerVersions.computeIfAbsent(version, s -> new HashSet<>()).add(p.getProtocolInfo().getUsername()); } for (Map.Entry> entry : playerVersions.entrySet()) { diff --git a/common/src/main/java/com/viaversion/viaversion/commands/defaultsubs/PPSSubCmd.java b/common/src/main/java/com/viaversion/viaversion/commands/defaultsubs/PPSSubCmd.java index a3eb9b555..63e5c39e3 100644 --- a/common/src/main/java/com/viaversion/viaversion/commands/defaultsubs/PPSSubCmd.java +++ b/common/src/main/java/com/viaversion/viaversion/commands/defaultsubs/PPSSubCmd.java @@ -46,26 +46,25 @@ public class PPSSubCmd implements ViaSubCommand { @Override public boolean execute(ViaCommandSender sender, String[] args) { - Map> playerVersions = new HashMap<>(); + Map> playerVersions = new TreeMap<>(ProtocolVersion::compareTo); int totalPackets = 0; int clients = 0; long max = 0; - for (ViaCommandSender p : Via.getPlatform().getOnlinePlayers()) { - int playerVersion = Via.getAPI().getPlayerVersion(p.getUUID()); - if (!playerVersions.containsKey(playerVersion)) + for (UserConnection p : Via.getManager().getConnectionManager().getConnections()) { + ProtocolVersion playerVersion = p.getProtocolInfo().protocolVersion(); + if (!playerVersions.containsKey(playerVersion)) { playerVersions.put(playerVersion, new HashSet<>()); - UserConnection uc = Via.getManager().getConnectionManager().getConnectedClient(p.getUUID()); - if (uc != null && uc.getPacketTracker().getPacketsPerSecond() > -1) { - playerVersions.get(playerVersion).add(p.getName() + " (" + uc.getPacketTracker().getPacketsPerSecond() + " PPS)"); - totalPackets += uc.getPacketTracker().getPacketsPerSecond(); - if (uc.getPacketTracker().getPacketsPerSecond() > max) { - max = uc.getPacketTracker().getPacketsPerSecond(); + } + if (p.getPacketTracker().getPacketsPerSecond() > -1) { + playerVersions.get(playerVersion).add(p.getProtocolInfo().getUsername() + " (" + p.getPacketTracker().getPacketsPerSecond() + " PPS)"); + totalPackets += p.getPacketTracker().getPacketsPerSecond(); + if (p.getPacketTracker().getPacketsPerSecond() > max) { + max = p.getPacketTracker().getPacketsPerSecond(); } clients++; } } - Map> sorted = new TreeMap<>(playerVersions); sendMessage(sender, "&4Live Packets Per Second"); if (clients > 1) { sendMessage(sender, "&cAverage: &f" + (totalPackets / clients)); @@ -74,9 +73,10 @@ public class PPSSubCmd implements ViaSubCommand { if (clients == 0) { sendMessage(sender, "&cNo clients to display."); } - for (Map.Entry> entry : sorted.entrySet()) - sendMessage(sender, "&8[&6%s&8]: &b%s", ProtocolVersion.getProtocol(entry.getKey()).getName(), entry.getValue()); - sorted.clear(); + for (Map.Entry> entry : playerVersions.entrySet()) { + sendMessage(sender, "&8[&6%s&8]: &b%s", entry.getKey().getName(), entry.getValue()); + } + playerVersions.clear(); return true; } }