3
0
Mirror von https://github.com/ViaVersion/ViaVersion.git synchronisiert 2024-12-27 00:22:51 +01:00

Merge branch 'refs/heads/dev' into preview

Dieser Commit ist enthalten in:
Nassim Jahnke 2024-06-15 16:11:04 +02:00
Commit 7e60300e2e
Es konnte kein GPG-Schlüssel zu dieser Signatur gefunden werden
GPG-Schlüssel-ID: EF6771C01F6EF02F
10 geänderte Dateien mit 130 neuen und 30 gelöschten Zeilen

Datei anzeigen

@ -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());
}
}

Datei anzeigen

@ -20,6 +20,9 @@ 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
@ -33,13 +36,34 @@ 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);
public String usage() {
return "displayleaks <level>";
}
sendMessage(sender, "&6Leak detector is now %s", (ResourceLeakDetector.getLevel() == ResourceLeakDetector.Level.PARANOID ? "&aenabled" : "&cdisabled"));
@Override
public boolean execute(ViaCommandSender sender, String[] args) {
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<String> 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);
}
}

Datei anzeigen

@ -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<ProtocolVersion, Set<String>> 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<ProtocolVersion, Set<String>> entry : playerVersions.entrySet()) {

Datei anzeigen

@ -46,26 +46,25 @@ public class PPSSubCmd implements ViaSubCommand {
@Override
public boolean execute(ViaCommandSender sender, String[] args) {
Map<Integer, Set<String>> playerVersions = new HashMap<>();
Map<ProtocolVersion, Set<String>> 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<Integer, Set<String>> 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<Integer, Set<String>> entry : sorted.entrySet())
sendMessage(sender, "&8[&6%s&8]: &b%s", ProtocolVersion.getProtocol(entry.getKey()).getName(), entry.getValue());
sorted.clear();
for (Map.Entry<ProtocolVersion, Set<String>> entry : playerVersions.entrySet()) {
sendMessage(sender, "&8[&6%s&8]: &b%s", entry.getKey().getName(), entry.getValue());
}
playerVersions.clear();
return true;
}
}

Datei anzeigen

@ -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 <http://www.gnu.org/licenses/>.
*/
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 <name|*>";
}
@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<String> onTabComplete(final ViaCommandSender sender, final String[] args) {
if (args.length == 1) {
final String input = args[0].toLowerCase();
final List<String> 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);
}
}

Datei anzeigen

@ -28,7 +28,7 @@ import com.viaversion.viaversion.rewriter.ItemRewriter;
public class ItemPacketRewriter1_11_1 extends ItemRewriter<ClientboundPackets1_9_3, ServerboundPackets1_9_3, Protocol1_11To1_11_1> {
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

Datei anzeigen

@ -51,7 +51,7 @@ import java.util.Optional;
public class ItemPacketRewriter1_13 extends ItemRewriter<ClientboundPackets1_12_1, ServerboundPackets1_13, Protocol1_12_2To1_13> {
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

Datei anzeigen

@ -43,7 +43,7 @@ import org.checkerframework.checker.nullness.qual.Nullable;
public class ItemPacketRewriter1_9 extends ItemRewriter<ClientboundPackets1_8, ServerboundPackets1_9, Protocol1_8To1_9> {
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

Datei anzeigen

@ -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());
}
}
}

Datei anzeigen

@ -28,7 +28,7 @@ import com.viaversion.viaversion.rewriter.ItemRewriter;
public class ItemPacketRewriter1_10 extends ItemRewriter<ClientboundPackets1_9_3, ServerboundPackets1_9_3, Protocol1_9_3To1_10> {
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