Mirror von
https://github.com/PaperMC/Velocity.git
synchronisiert 2024-11-17 05:20:14 +01:00
1.20.3 working & checkstyle fixes
Dieser Commit ist enthalten in:
Ursprung
814b53f12c
Commit
efcfeb3e53
@ -133,6 +133,18 @@ public class PlayerResourcePackStatusEvent {
|
|||||||
/**
|
/**
|
||||||
* The player has accepted the resource pack and is now downloading it.
|
* The player has accepted the resource pack and is now downloading it.
|
||||||
*/
|
*/
|
||||||
ACCEPTED
|
ACCEPTED,
|
||||||
|
/**
|
||||||
|
* The URL of the resource pack failed to load.
|
||||||
|
*/
|
||||||
|
INVALID_URL,
|
||||||
|
/**
|
||||||
|
* The player failed to reload the resource pack.
|
||||||
|
*/
|
||||||
|
FAILED_RELOAD,
|
||||||
|
/**
|
||||||
|
* The resource pack was discarded.
|
||||||
|
*/
|
||||||
|
DISCARDED,
|
||||||
}
|
}
|
||||||
}
|
}
|
@ -19,7 +19,6 @@ import com.velocitypowered.api.proxy.player.TabList;
|
|||||||
import com.velocitypowered.api.proxy.server.RegisteredServer;
|
import com.velocitypowered.api.proxy.server.RegisteredServer;
|
||||||
import com.velocitypowered.api.util.GameProfile;
|
import com.velocitypowered.api.util.GameProfile;
|
||||||
import com.velocitypowered.api.util.ModInfo;
|
import com.velocitypowered.api.util.ModInfo;
|
||||||
|
|
||||||
import java.util.Collection;
|
import java.util.Collection;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Locale;
|
import java.util.Locale;
|
||||||
|
@ -7,11 +7,10 @@
|
|||||||
|
|
||||||
package com.velocitypowered.api.proxy.player;
|
package com.velocitypowered.api.proxy.player;
|
||||||
|
|
||||||
|
import java.util.UUID;
|
||||||
import net.kyori.adventure.text.Component;
|
import net.kyori.adventure.text.Component;
|
||||||
import org.checkerframework.checker.nullness.qual.Nullable;
|
import org.checkerframework.checker.nullness.qual.Nullable;
|
||||||
|
|
||||||
import java.util.UUID;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Represents the information for a resource pack to apply that can be sent to the client.
|
* Represents the information for a resource pack to apply that can be sent to the client.
|
||||||
*/
|
*/
|
||||||
|
@ -198,6 +198,7 @@ public class BackendPlaySessionHandler implements MinecraftSessionHandler {
|
|||||||
serverConn.getPlayer().queueResourcePack(toSend);
|
serverConn.getPlayer().queueResourcePack(toSend);
|
||||||
} else if (serverConn.getConnection() != null) {
|
} else if (serverConn.getConnection() != null) {
|
||||||
serverConn.getConnection().write(new ResourcePackResponse(
|
serverConn.getConnection().write(new ResourcePackResponse(
|
||||||
|
packet.getId(),
|
||||||
packet.getHash(),
|
packet.getHash(),
|
||||||
PlayerResourcePackStatusEvent.Status.DECLINED
|
PlayerResourcePackStatusEvent.Status.DECLINED
|
||||||
));
|
));
|
||||||
@ -205,6 +206,7 @@ public class BackendPlaySessionHandler implements MinecraftSessionHandler {
|
|||||||
}, playerConnection.eventLoop()).exceptionally((ex) -> {
|
}, playerConnection.eventLoop()).exceptionally((ex) -> {
|
||||||
if (serverConn.getConnection() != null) {
|
if (serverConn.getConnection() != null) {
|
||||||
serverConn.getConnection().write(new ResourcePackResponse(
|
serverConn.getConnection().write(new ResourcePackResponse(
|
||||||
|
packet.getId(),
|
||||||
packet.getHash(),
|
packet.getHash(),
|
||||||
PlayerResourcePackStatusEvent.Status.DECLINED
|
PlayerResourcePackStatusEvent.Status.DECLINED
|
||||||
));
|
));
|
||||||
@ -218,7 +220,7 @@ public class BackendPlaySessionHandler implements MinecraftSessionHandler {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean handle(RemoveResourcePack packet) {
|
public boolean handle(RemoveResourcePack packet) {
|
||||||
//TODO
|
return false; //TODO
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@ -312,7 +314,8 @@ public class BackendPlaySessionHandler implements MinecraftSessionHandler {
|
|||||||
ping -> server.getEventManager()
|
ping -> server.getEventManager()
|
||||||
.fire(new ProxyPingEvent(this.serverConn.getPlayer(), ping)),
|
.fire(new ProxyPingEvent(this.serverConn.getPlayer(), ping)),
|
||||||
playerConnection.eventLoop()).thenAcceptAsync(pingEvent -> this.playerConnection.write(
|
playerConnection.eventLoop()).thenAcceptAsync(pingEvent -> this.playerConnection.write(
|
||||||
new ServerData(new ComponentHolder(this.serverConn.ensureConnected().getProtocolVersion(),
|
new ServerData(new ComponentHolder(
|
||||||
|
this.serverConn.ensureConnected().getProtocolVersion(),
|
||||||
pingEvent.getPing().getDescriptionComponent()),
|
pingEvent.getPing().getDescriptionComponent()),
|
||||||
pingEvent.getPing().getFavicon().orElse(null), packet.isSecureChatEnforced())),
|
pingEvent.getPing().getFavicon().orElse(null), packet.isSecureChatEnforced())),
|
||||||
playerConnection.eventLoop());
|
playerConnection.eventLoop());
|
||||||
|
@ -134,12 +134,12 @@ public class ConfigSessionHandler implements MinecraftSessionHandler {
|
|||||||
resourcePackToApply = null;
|
resourcePackToApply = null;
|
||||||
serverConn.getPlayer().queueResourcePack(toSend);
|
serverConn.getPlayer().queueResourcePack(toSend);
|
||||||
} else if (serverConn.getConnection() != null) {
|
} else if (serverConn.getConnection() != null) {
|
||||||
serverConn.getConnection().write(new ResourcePackResponse(packet.getHash(),
|
serverConn.getConnection().write(new ResourcePackResponse(packet.getId(), packet.getHash(),
|
||||||
PlayerResourcePackStatusEvent.Status.DECLINED));
|
PlayerResourcePackStatusEvent.Status.DECLINED));
|
||||||
}
|
}
|
||||||
}, playerConnection.eventLoop()).exceptionally((ex) -> {
|
}, playerConnection.eventLoop()).exceptionally((ex) -> {
|
||||||
if (serverConn.getConnection() != null) {
|
if (serverConn.getConnection() != null) {
|
||||||
serverConn.getConnection().write(new ResourcePackResponse(packet.getHash(),
|
serverConn.getConnection().write(new ResourcePackResponse(packet.getId(), packet.getHash(),
|
||||||
PlayerResourcePackStatusEvent.Status.DECLINED));
|
PlayerResourcePackStatusEvent.Status.DECLINED));
|
||||||
}
|
}
|
||||||
logger.error("Exception while handling resource pack send for {}", playerConnection, ex);
|
logger.error("Exception while handling resource pack send for {}", playerConnection, ex);
|
||||||
|
@ -671,7 +671,8 @@ public class ConnectedPlayer implements MinecraftConnectionAssociation, Player,
|
|||||||
}
|
}
|
||||||
|
|
||||||
private void handleConnectionException(RegisteredServer rs,
|
private void handleConnectionException(RegisteredServer rs,
|
||||||
@Nullable Component kickReason, Component friendlyReason, boolean safe) {
|
@Nullable Component kickReason, Component friendlyReason,
|
||||||
|
boolean safe) {
|
||||||
if (!isActive()) {
|
if (!isActive()) {
|
||||||
// If the connection is no longer active, it makes no sense to try and recover it.
|
// If the connection is no longer active, it makes no sense to try and recover it.
|
||||||
return;
|
return;
|
||||||
@ -1010,6 +1011,7 @@ public class ConnectedPlayer implements MinecraftConnectionAssociation, Player,
|
|||||||
}
|
}
|
||||||
|
|
||||||
ResourcePackRequest request = new ResourcePackRequest();
|
ResourcePackRequest request = new ResourcePackRequest();
|
||||||
|
request.setId(queued.getId());
|
||||||
request.setUrl(queued.getUrl());
|
request.setUrl(queued.getUrl());
|
||||||
if (queued.getHash() != null) {
|
if (queued.getHash() != null) {
|
||||||
request.setHash(ByteBufUtil.hexDump(queued.getHash()));
|
request.setHash(ByteBufUtil.hexDump(queued.getHash()));
|
||||||
@ -1017,7 +1019,8 @@ public class ConnectedPlayer implements MinecraftConnectionAssociation, Player,
|
|||||||
request.setHash("");
|
request.setHash("");
|
||||||
}
|
}
|
||||||
request.setRequired(queued.getShouldForce());
|
request.setRequired(queued.getShouldForce());
|
||||||
request.setPrompt(queued.getPrompt() == null ? null : new ComponentHolder(getProtocolVersion(), queued.getPrompt()));
|
request.setPrompt(queued.getPrompt() == null ? null :
|
||||||
|
new ComponentHolder(getProtocolVersion(), queued.getPrompt()));
|
||||||
|
|
||||||
connection.write(request);
|
connection.write(request);
|
||||||
}
|
}
|
||||||
@ -1039,12 +1042,12 @@ public class ConnectedPlayer implements MinecraftConnectionAssociation, Player,
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Collection<ResourcePackInfo> getAppliedResourcePacks() {
|
public Collection<ResourcePackInfo> getAppliedResourcePacks() {
|
||||||
//TODO
|
return Collections.EMPTY_LIST; //TODO
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Collection<ResourcePackInfo> getPendingResourcePacks() {
|
public Collection<ResourcePackInfo> getPendingResourcePacks() {
|
||||||
//TODO
|
return Collections.EMPTY_LIST; //TODO
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -19,11 +19,10 @@ package com.velocitypowered.proxy.connection.player;
|
|||||||
|
|
||||||
import com.google.common.base.Preconditions;
|
import com.google.common.base.Preconditions;
|
||||||
import com.velocitypowered.api.proxy.player.ResourcePackInfo;
|
import com.velocitypowered.api.proxy.player.ResourcePackInfo;
|
||||||
|
import java.util.UUID;
|
||||||
import net.kyori.adventure.text.Component;
|
import net.kyori.adventure.text.Component;
|
||||||
import org.checkerframework.checker.nullness.qual.Nullable;
|
import org.checkerframework.checker.nullness.qual.Nullable;
|
||||||
|
|
||||||
import java.util.UUID;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Implements {@link ResourcePackInfo}.
|
* Implements {@link ResourcePackInfo}.
|
||||||
*/
|
*/
|
||||||
|
@ -376,10 +376,12 @@ public enum ProtocolUtils {
|
|||||||
* @param reader the {@link BinaryTagIO.Reader} to use
|
* @param reader the {@link BinaryTagIO.Reader} to use
|
||||||
* @return {@link net.kyori.adventure.nbt.CompoundBinaryTag} the CompoundTag from the buffer
|
* @return {@link net.kyori.adventure.nbt.CompoundBinaryTag} the CompoundTag from the buffer
|
||||||
*/
|
*/
|
||||||
public static CompoundBinaryTag readCompoundTag(ByteBuf buf, ProtocolVersion version, BinaryTagIO.Reader reader) {
|
public static CompoundBinaryTag readCompoundTag(ByteBuf buf, ProtocolVersion version,
|
||||||
|
BinaryTagIO.Reader reader) {
|
||||||
BinaryTag binaryTag = readBinaryTag(buf, version, reader);
|
BinaryTag binaryTag = readBinaryTag(buf, version, reader);
|
||||||
if (binaryTag.type() != BinaryTagTypes.COMPOUND) {
|
if (binaryTag.type() != BinaryTagTypes.COMPOUND) {
|
||||||
throw new DecoderException("Expected root tag to be CompoundTag, but is " + binaryTag.getClass().getSimpleName());
|
throw new DecoderException(
|
||||||
|
"Expected root tag to be CompoundTag, but is " + binaryTag.getClass().getSimpleName());
|
||||||
}
|
}
|
||||||
return (CompoundBinaryTag) binaryTag;
|
return (CompoundBinaryTag) binaryTag;
|
||||||
}
|
}
|
||||||
@ -391,7 +393,8 @@ public enum ProtocolUtils {
|
|||||||
* @param reader the {@link BinaryTagIO.Reader} to use
|
* @param reader the {@link BinaryTagIO.Reader} to use
|
||||||
* @return {@link net.kyori.adventure.nbt.BinaryTag} the BinaryTag from the buffer
|
* @return {@link net.kyori.adventure.nbt.BinaryTag} the BinaryTag from the buffer
|
||||||
*/
|
*/
|
||||||
public static BinaryTag readBinaryTag(ByteBuf buf, ProtocolVersion version, BinaryTagIO.Reader reader) {
|
public static BinaryTag readBinaryTag(ByteBuf buf, ProtocolVersion version,
|
||||||
|
BinaryTagIO.Reader reader) {
|
||||||
BinaryTagType<?> type = BINARY_TAG_TYPES[buf.readByte()];
|
BinaryTagType<?> type = BINARY_TAG_TYPES[buf.readByte()];
|
||||||
if (version.compareTo(ProtocolVersion.MINECRAFT_1_20_2) < 0) {
|
if (version.compareTo(ProtocolVersion.MINECRAFT_1_20_2) < 0) {
|
||||||
buf.skipBytes(buf.readUnsignedShort());
|
buf.skipBytes(buf.readUnsignedShort());
|
||||||
@ -409,7 +412,8 @@ public enum ProtocolUtils {
|
|||||||
* @param buf the buffer to write to
|
* @param buf the buffer to write to
|
||||||
* @param tag the BinaryTag to write
|
* @param tag the BinaryTag to write
|
||||||
*/
|
*/
|
||||||
public static <T extends BinaryTag> void writeBinaryTag(ByteBuf buf, ProtocolVersion version, T tag) {
|
public static <T extends BinaryTag> void writeBinaryTag(ByteBuf buf, ProtocolVersion version,
|
||||||
|
T tag) {
|
||||||
BinaryTagType<T> type = (BinaryTagType<T>) tag.type();
|
BinaryTagType<T> type = (BinaryTagType<T>) tag.type();
|
||||||
buf.writeByte(type.id());
|
buf.writeByte(type.id());
|
||||||
try {
|
try {
|
||||||
|
@ -109,7 +109,9 @@ import java.util.Objects;
|
|||||||
import java.util.function.Supplier;
|
import java.util.function.Supplier;
|
||||||
import org.checkerframework.checker.nullness.qual.Nullable;
|
import org.checkerframework.checker.nullness.qual.Nullable;
|
||||||
|
|
||||||
/** Registry of all Minecraft protocol states and the packets for each state. */
|
/**
|
||||||
|
* Registry of all Minecraft protocol states and the packets for each state.
|
||||||
|
*/
|
||||||
public enum StateRegistry {
|
public enum StateRegistry {
|
||||||
|
|
||||||
HANDSHAKE {
|
HANDSHAKE {
|
||||||
@ -399,7 +401,9 @@ public enum StateRegistry {
|
|||||||
map(0x43, MINECRAFT_1_20_2, true),
|
map(0x43, MINECRAFT_1_20_2, true),
|
||||||
map(0x45, MINECRAFT_1_20_3, true));
|
map(0x45, MINECRAFT_1_20_3, true));
|
||||||
clientbound.register(
|
clientbound.register(
|
||||||
RemoveResourcePack.class, RemoveResourcePack::new, map(0x43, MINECRAFT_1_20_3, false));
|
RemoveResourcePack.class,
|
||||||
|
RemoveResourcePack::new,
|
||||||
|
map(0x43, MINECRAFT_1_20_3, false));
|
||||||
clientbound.register(
|
clientbound.register(
|
||||||
ResourcePackRequest.class,
|
ResourcePackRequest.class,
|
||||||
ResourcePackRequest::new,
|
ResourcePackRequest::new,
|
||||||
@ -584,7 +588,9 @@ public enum StateRegistry {
|
|||||||
return (direction == SERVERBOUND ? serverbound : clientbound).getProtocolRegistry(version);
|
return (direction == SERVERBOUND ? serverbound : clientbound).getProtocolRegistry(version);
|
||||||
}
|
}
|
||||||
|
|
||||||
/** Packet registry. */
|
/**
|
||||||
|
* Packet registry.
|
||||||
|
*/
|
||||||
public static class PacketRegistry {
|
public static class PacketRegistry {
|
||||||
|
|
||||||
private final Direction direction;
|
private final Direction direction;
|
||||||
@ -682,7 +688,9 @@ public enum StateRegistry {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/** Protocol registry. */
|
/**
|
||||||
|
* Protocol registry.
|
||||||
|
*/
|
||||||
public class ProtocolRegistry {
|
public class ProtocolRegistry {
|
||||||
|
|
||||||
public final ProtocolVersion version;
|
public final ProtocolVersion version;
|
||||||
@ -741,7 +749,9 @@ public enum StateRegistry {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/** Packet mapping. */
|
/**
|
||||||
|
* Packet mapping.
|
||||||
|
*/
|
||||||
public static final class PacketMapping {
|
public static final class PacketMapping {
|
||||||
|
|
||||||
private final int id;
|
private final int id;
|
||||||
|
@ -39,13 +39,19 @@ public class RemoveResourcePack implements MinecraftPacket {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void decode(ByteBuf buf, Direction direction, ProtocolVersion protocolVersion) {
|
public void decode(ByteBuf buf, Direction direction, ProtocolVersion protocolVersion) {
|
||||||
|
if (buf.readBoolean()) {
|
||||||
this.id = ProtocolUtils.readUuid(buf);
|
this.id = ProtocolUtils.readUuid(buf);
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void encode(ByteBuf buf, Direction direction, ProtocolVersion protocolVersion) {
|
public void encode(ByteBuf buf, Direction direction, ProtocolVersion protocolVersion) {
|
||||||
|
buf.writeBoolean(id != null);
|
||||||
|
|
||||||
|
if (id != null) {
|
||||||
ProtocolUtils.writeUuid(buf, id);
|
ProtocolUtils.writeUuid(buf, id);
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean handle(MinecraftSessionHandler handler) {
|
public boolean handle(MinecraftSessionHandler handler) {
|
||||||
|
@ -26,15 +26,19 @@ import com.velocitypowered.proxy.protocol.ProtocolUtils.Direction;
|
|||||||
import io.netty.buffer.ByteBuf;
|
import io.netty.buffer.ByteBuf;
|
||||||
import org.checkerframework.checker.nullness.qual.MonotonicNonNull;
|
import org.checkerframework.checker.nullness.qual.MonotonicNonNull;
|
||||||
|
|
||||||
|
import java.util.UUID;
|
||||||
|
|
||||||
public class ResourcePackResponse implements MinecraftPacket {
|
public class ResourcePackResponse implements MinecraftPacket {
|
||||||
|
|
||||||
|
private UUID id;
|
||||||
private String hash = "";
|
private String hash = "";
|
||||||
private @MonotonicNonNull Status status;
|
private @MonotonicNonNull Status status;
|
||||||
|
|
||||||
public ResourcePackResponse() {
|
public ResourcePackResponse() {
|
||||||
}
|
}
|
||||||
|
|
||||||
public ResourcePackResponse(String hash, @MonotonicNonNull Status status) {
|
public ResourcePackResponse(UUID id, String hash, @MonotonicNonNull Status status) {
|
||||||
|
this.id = id;
|
||||||
this.hash = hash;
|
this.hash = hash;
|
||||||
this.status = status;
|
this.status = status;
|
||||||
}
|
}
|
||||||
@ -52,6 +56,9 @@ public class ResourcePackResponse implements MinecraftPacket {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void decode(ByteBuf buf, Direction direction, ProtocolVersion protocolVersion) {
|
public void decode(ByteBuf buf, Direction direction, ProtocolVersion protocolVersion) {
|
||||||
|
if (protocolVersion.compareTo(ProtocolVersion.MINECRAFT_1_20_3) >= 0) {
|
||||||
|
this.id = ProtocolUtils.readUuid(buf);
|
||||||
|
}
|
||||||
if (protocolVersion.compareTo(ProtocolVersion.MINECRAFT_1_9_4) <= 0) {
|
if (protocolVersion.compareTo(ProtocolVersion.MINECRAFT_1_9_4) <= 0) {
|
||||||
this.hash = ProtocolUtils.readString(buf);
|
this.hash = ProtocolUtils.readString(buf);
|
||||||
}
|
}
|
||||||
@ -60,6 +67,9 @@ public class ResourcePackResponse implements MinecraftPacket {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void encode(ByteBuf buf, Direction direction, ProtocolVersion protocolVersion) {
|
public void encode(ByteBuf buf, Direction direction, ProtocolVersion protocolVersion) {
|
||||||
|
if (protocolVersion.compareTo(ProtocolVersion.MINECRAFT_1_20_3) >= 0) {
|
||||||
|
ProtocolUtils.writeUuid(buf, id);
|
||||||
|
}
|
||||||
if (protocolVersion.compareTo(ProtocolVersion.MINECRAFT_1_9_4) <= 0) {
|
if (protocolVersion.compareTo(ProtocolVersion.MINECRAFT_1_9_4) <= 0) {
|
||||||
ProtocolUtils.writeString(buf, hash);
|
ProtocolUtils.writeString(buf, hash);
|
||||||
}
|
}
|
||||||
|
@ -20,6 +20,7 @@ package com.velocitypowered.proxy.protocol.packet.brigadier;
|
|||||||
import static com.velocitypowered.api.network.ProtocolVersion.MINECRAFT_1_19;
|
import static com.velocitypowered.api.network.ProtocolVersion.MINECRAFT_1_19;
|
||||||
import static com.velocitypowered.api.network.ProtocolVersion.MINECRAFT_1_19_3;
|
import static com.velocitypowered.api.network.ProtocolVersion.MINECRAFT_1_19_3;
|
||||||
import static com.velocitypowered.api.network.ProtocolVersion.MINECRAFT_1_19_4;
|
import static com.velocitypowered.api.network.ProtocolVersion.MINECRAFT_1_19_4;
|
||||||
|
import static com.velocitypowered.api.network.ProtocolVersion.MINECRAFT_1_20_3;
|
||||||
import static com.velocitypowered.proxy.protocol.packet.brigadier.ArgumentIdentifier.id;
|
import static com.velocitypowered.proxy.protocol.packet.brigadier.ArgumentIdentifier.id;
|
||||||
import static com.velocitypowered.proxy.protocol.packet.brigadier.ArgumentIdentifier.mapSet;
|
import static com.velocitypowered.proxy.protocol.packet.brigadier.ArgumentIdentifier.mapSet;
|
||||||
import static com.velocitypowered.proxy.protocol.packet.brigadier.DoubleArgumentPropertySerializer.DOUBLE;
|
import static com.velocitypowered.proxy.protocol.packet.brigadier.DoubleArgumentPropertySerializer.DOUBLE;
|
||||||
@ -206,54 +207,75 @@ public class ArgumentPropertyRegistry {
|
|||||||
empty(id("minecraft:item_predicate", mapSet(MINECRAFT_1_19, 15)));
|
empty(id("minecraft:item_predicate", mapSet(MINECRAFT_1_19, 15)));
|
||||||
empty(id("minecraft:color", mapSet(MINECRAFT_1_19, 16)));
|
empty(id("minecraft:color", mapSet(MINECRAFT_1_19, 16)));
|
||||||
empty(id("minecraft:component", mapSet(MINECRAFT_1_19, 17)));
|
empty(id("minecraft:component", mapSet(MINECRAFT_1_19, 17)));
|
||||||
empty(id("minecraft:message", mapSet(MINECRAFT_1_19, 18)));
|
empty(id("minecraft:style", mapSet(MINECRAFT_1_20_3, 18))); // added 1.20.3
|
||||||
empty(id("minecraft:nbt_compound_tag", mapSet(MINECRAFT_1_19, 19))); // added in 1.14
|
empty(id("minecraft:message", mapSet(MINECRAFT_1_20_3, 19), mapSet(MINECRAFT_1_19, 18)));
|
||||||
empty(id("minecraft:nbt_tag", mapSet(MINECRAFT_1_19, 20))); // added in 1.14
|
empty(id("minecraft:nbt_compound_tag", mapSet(MINECRAFT_1_20_3, 20),
|
||||||
empty(id("minecraft:nbt_path", mapSet(MINECRAFT_1_19, 21)));
|
mapSet(MINECRAFT_1_19, 19))); // added in 1.14
|
||||||
empty(id("minecraft:objective", mapSet(MINECRAFT_1_19, 22)));
|
empty(id("minecraft:nbt_tag", mapSet(MINECRAFT_1_20_3, 21),
|
||||||
empty(id("minecraft:objective_criteria", mapSet(MINECRAFT_1_19, 23)));
|
mapSet(MINECRAFT_1_19, 20))); // added in 1.14
|
||||||
empty(id("minecraft:operation", mapSet(MINECRAFT_1_19, 24)));
|
empty(id("minecraft:nbt_path", mapSet(MINECRAFT_1_20_3, 22), mapSet(MINECRAFT_1_19, 21)));
|
||||||
empty(id("minecraft:particle", mapSet(MINECRAFT_1_19, 25)));
|
empty(id("minecraft:objective", mapSet(MINECRAFT_1_20_3, 23), mapSet(MINECRAFT_1_19, 22)));
|
||||||
empty(id("minecraft:angle", mapSet(MINECRAFT_1_19, 26))); // added in 1.16.2
|
empty(id("minecraft:objective_criteria", mapSet(MINECRAFT_1_20_3, 24),
|
||||||
empty(id("minecraft:rotation", mapSet(MINECRAFT_1_19, 27)));
|
mapSet(MINECRAFT_1_19, 23)));
|
||||||
empty(id("minecraft:scoreboard_slot", mapSet(MINECRAFT_1_19, 28)));
|
empty(id("minecraft:operation", mapSet(MINECRAFT_1_20_3, 25), mapSet(MINECRAFT_1_19, 24)));
|
||||||
empty(id("minecraft:score_holder", mapSet(MINECRAFT_1_19, 29)),
|
empty(id("minecraft:particle", mapSet(MINECRAFT_1_20_3, 26), mapSet(MINECRAFT_1_19, 25)));
|
||||||
|
empty(id("minecraft:angle", mapSet(MINECRAFT_1_20_3, 27),
|
||||||
|
mapSet(MINECRAFT_1_19, 26))); // added in 1.16.2
|
||||||
|
empty(id("minecraft:rotation", mapSet(MINECRAFT_1_20_3, 28), mapSet(MINECRAFT_1_19, 27)));
|
||||||
|
empty(
|
||||||
|
id("minecraft:scoreboard_slot", mapSet(MINECRAFT_1_20_3, 29), mapSet(MINECRAFT_1_19, 28)));
|
||||||
|
empty(id("minecraft:score_holder", mapSet(MINECRAFT_1_20_3, 30), mapSet(MINECRAFT_1_19, 29)),
|
||||||
ByteArgumentPropertySerializer.BYTE);
|
ByteArgumentPropertySerializer.BYTE);
|
||||||
empty(id("minecraft:swizzle", mapSet(MINECRAFT_1_19, 30)));
|
empty(id("minecraft:swizzle", mapSet(MINECRAFT_1_20_3, 31), mapSet(MINECRAFT_1_19, 30)));
|
||||||
empty(id("minecraft:team", mapSet(MINECRAFT_1_19, 31)));
|
empty(id("minecraft:team", mapSet(MINECRAFT_1_20_3, 32), mapSet(MINECRAFT_1_19, 31)));
|
||||||
empty(id("minecraft:item_slot", mapSet(MINECRAFT_1_19, 32)));
|
empty(id("minecraft:item_slot", mapSet(MINECRAFT_1_20_3, 33), mapSet(MINECRAFT_1_19, 32)));
|
||||||
empty(id("minecraft:resource_location", mapSet(MINECRAFT_1_19, 33)));
|
empty(id("minecraft:resource_location", mapSet(MINECRAFT_1_20_3, 34),
|
||||||
|
mapSet(MINECRAFT_1_19, 33)));
|
||||||
empty(id("minecraft:mob_effect", mapSet(MINECRAFT_1_19_3, -1), mapSet(MINECRAFT_1_19, 34)));
|
empty(id("minecraft:mob_effect", mapSet(MINECRAFT_1_19_3, -1), mapSet(MINECRAFT_1_19, 34)));
|
||||||
empty(id("minecraft:function", mapSet(MINECRAFT_1_19_3, 34), mapSet(MINECRAFT_1_19, 35)));
|
empty(id("minecraft:function", mapSet(MINECRAFT_1_20_3, 35), mapSet(MINECRAFT_1_19_3, 34),
|
||||||
empty(id("minecraft:entity_anchor", mapSet(MINECRAFT_1_19_3, 35), mapSet(MINECRAFT_1_19, 36)));
|
mapSet(MINECRAFT_1_19, 35)));
|
||||||
empty(id("minecraft:int_range", mapSet(MINECRAFT_1_19_3, 36), mapSet(MINECRAFT_1_19, 37)));
|
empty(id("minecraft:entity_anchor", mapSet(MINECRAFT_1_20_3, 36), mapSet(MINECRAFT_1_19_3, 35),
|
||||||
empty(id("minecraft:float_range", mapSet(MINECRAFT_1_19_3, 37), mapSet(MINECRAFT_1_19, 38)));
|
mapSet(MINECRAFT_1_19, 36)));
|
||||||
|
empty(id("minecraft:int_range", mapSet(MINECRAFT_1_20_3, 37), mapSet(MINECRAFT_1_19_3, 36),
|
||||||
|
mapSet(MINECRAFT_1_19, 37)));
|
||||||
|
empty(id("minecraft:float_range", mapSet(MINECRAFT_1_20_3, 38), mapSet(MINECRAFT_1_19_3, 37),
|
||||||
|
mapSet(MINECRAFT_1_19, 38)));
|
||||||
empty(
|
empty(
|
||||||
id("minecraft:item_enchantment", mapSet(MINECRAFT_1_19_3, -1), mapSet(MINECRAFT_1_19, 39)));
|
id("minecraft:item_enchantment", mapSet(MINECRAFT_1_19_3, -1), mapSet(MINECRAFT_1_19, 39)));
|
||||||
empty(id("minecraft:entity_summon", mapSet(MINECRAFT_1_19_3, -1), mapSet(MINECRAFT_1_19, 40)));
|
empty(id("minecraft:entity_summon", mapSet(MINECRAFT_1_19_3, -1), mapSet(MINECRAFT_1_19, 40)));
|
||||||
empty(id("minecraft:dimension", mapSet(MINECRAFT_1_19_3, 38), mapSet(MINECRAFT_1_19, 41)));
|
empty(id("minecraft:dimension", mapSet(MINECRAFT_1_20_3, 39), mapSet(MINECRAFT_1_19_3, 38),
|
||||||
empty(id("minecraft:gamemode", mapSet(MINECRAFT_1_19_3, 39))); // 1.19.3
|
mapSet(MINECRAFT_1_19, 41)));
|
||||||
|
empty(id("minecraft:gamemode", mapSet(MINECRAFT_1_20_3, 40),
|
||||||
|
mapSet(MINECRAFT_1_19_3, 39))); // 1.19.3
|
||||||
|
|
||||||
empty(id("minecraft:time", mapSet(MINECRAFT_1_19_3, 40),
|
empty(id("minecraft:time", mapSet(MINECRAFT_1_20_3, 41), mapSet(MINECRAFT_1_19_3, 40),
|
||||||
mapSet(MINECRAFT_1_19, 42)), TimeArgumentSerializer.TIME); // added in 1.14
|
mapSet(MINECRAFT_1_19, 42)), TimeArgumentSerializer.TIME); // added in 1.14
|
||||||
|
|
||||||
register(
|
register(
|
||||||
id("minecraft:resource_or_tag", mapSet(MINECRAFT_1_19_3, 41), mapSet(MINECRAFT_1_19, 43)),
|
id("minecraft:resource_or_tag", mapSet(MINECRAFT_1_20_3, 42), mapSet(MINECRAFT_1_19_3, 41),
|
||||||
|
mapSet(MINECRAFT_1_19, 43)),
|
||||||
RegistryKeyArgument.class, RegistryKeyArgumentSerializer.REGISTRY);
|
RegistryKeyArgument.class, RegistryKeyArgumentSerializer.REGISTRY);
|
||||||
register(id("minecraft:resource_or_tag_key", mapSet(MINECRAFT_1_19_3, 42)),
|
register(id("minecraft:resource_or_tag_key", mapSet(MINECRAFT_1_20_3, 43),
|
||||||
|
mapSet(MINECRAFT_1_19_3, 42)),
|
||||||
RegistryKeyArgumentList.ResourceOrTagKey.class,
|
RegistryKeyArgumentList.ResourceOrTagKey.class,
|
||||||
RegistryKeyArgumentList.ResourceOrTagKey.Serializer.REGISTRY);
|
RegistryKeyArgumentList.ResourceOrTagKey.Serializer.REGISTRY);
|
||||||
register(id("minecraft:resource", mapSet(MINECRAFT_1_19_3, 43), mapSet(MINECRAFT_1_19, 44)),
|
register(id("minecraft:resource", mapSet(MINECRAFT_1_20_3, 44), mapSet(MINECRAFT_1_19_3, 43),
|
||||||
|
mapSet(MINECRAFT_1_19, 44)),
|
||||||
RegistryKeyArgument.class, RegistryKeyArgumentSerializer.REGISTRY);
|
RegistryKeyArgument.class, RegistryKeyArgumentSerializer.REGISTRY);
|
||||||
register(id("minecraft:resource_key", mapSet(MINECRAFT_1_19_3, 44)),
|
register(
|
||||||
|
id("minecraft:resource_key", mapSet(MINECRAFT_1_20_3, 45), mapSet(MINECRAFT_1_19_3, 44)),
|
||||||
RegistryKeyArgumentList.ResourceKey.class,
|
RegistryKeyArgumentList.ResourceKey.class,
|
||||||
RegistryKeyArgumentList.ResourceKey.Serializer.REGISTRY);
|
RegistryKeyArgumentList.ResourceKey.Serializer.REGISTRY);
|
||||||
|
|
||||||
empty(id("minecraft:template_mirror", mapSet(MINECRAFT_1_19, 45))); // 1.19
|
empty(id("minecraft:template_mirror", mapSet(MINECRAFT_1_20_3, 46),
|
||||||
empty(id("minecraft:template_rotation", mapSet(MINECRAFT_1_19, 46))); // 1.19
|
mapSet(MINECRAFT_1_19, 45))); // 1.19
|
||||||
empty(id("minecraft:heightmap", mapSet(MINECRAFT_1_19_4, 47))); // 1.19.4
|
empty(id("minecraft:template_rotation", mapSet(MINECRAFT_1_20_3, 47),
|
||||||
|
mapSet(MINECRAFT_1_19, 46))); // 1.19
|
||||||
|
empty(id("minecraft:heightmap", mapSet(MINECRAFT_1_20_3, 49),
|
||||||
|
mapSet(MINECRAFT_1_19_4, 47))); // 1.19.4
|
||||||
|
|
||||||
empty(id("minecraft:uuid", mapSet(MINECRAFT_1_19_4, 48), mapSet(MINECRAFT_1_19, 47))); // added in 1.16
|
empty(id("minecraft:uuid", mapSet(MINECRAFT_1_20_3, 48), mapSet(MINECRAFT_1_19_4, 48),
|
||||||
|
mapSet(MINECRAFT_1_19, 47))); // added in 1.16
|
||||||
|
|
||||||
// Crossstitch support
|
// Crossstitch support
|
||||||
register(id("crossstitch:mod_argument", mapSet(MINECRAFT_1_19, -256)),
|
register(id("crossstitch:mod_argument", mapSet(MINECRAFT_1_19, -256)),
|
||||||
|
@ -1,17 +1,56 @@
|
|||||||
|
/*
|
||||||
|
* Copyright (C) 2019-2023 Velocity 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 <https://www.gnu.org/licenses/>.
|
||||||
|
*/
|
||||||
|
|
||||||
package com.velocitypowered.proxy.protocol.packet.chat;
|
package com.velocitypowered.proxy.protocol.packet.chat;
|
||||||
|
|
||||||
|
import com.google.gson.JsonArray;
|
||||||
|
import com.google.gson.JsonElement;
|
||||||
|
import com.google.gson.JsonObject;
|
||||||
|
import com.google.gson.JsonPrimitive;
|
||||||
import com.velocitypowered.api.network.ProtocolVersion;
|
import com.velocitypowered.api.network.ProtocolVersion;
|
||||||
import com.velocitypowered.proxy.protocol.ProtocolUtils;
|
import com.velocitypowered.proxy.protocol.ProtocolUtils;
|
||||||
import io.netty.buffer.ByteBuf;
|
import io.netty.buffer.ByteBuf;
|
||||||
import net.kyori.adventure.nbt.BinaryTag;
|
import net.kyori.adventure.nbt.BinaryTag;
|
||||||
import net.kyori.adventure.nbt.BinaryTagIO;
|
import net.kyori.adventure.nbt.BinaryTagIO;
|
||||||
|
import net.kyori.adventure.nbt.BinaryTagType;
|
||||||
|
import net.kyori.adventure.nbt.ByteArrayBinaryTag;
|
||||||
|
import net.kyori.adventure.nbt.ByteBinaryTag;
|
||||||
|
import net.kyori.adventure.nbt.CompoundBinaryTag;
|
||||||
|
import net.kyori.adventure.nbt.DoubleBinaryTag;
|
||||||
|
import net.kyori.adventure.nbt.EndBinaryTag;
|
||||||
|
import net.kyori.adventure.nbt.FloatBinaryTag;
|
||||||
|
import net.kyori.adventure.nbt.IntArrayBinaryTag;
|
||||||
|
import net.kyori.adventure.nbt.IntBinaryTag;
|
||||||
|
import net.kyori.adventure.nbt.ListBinaryTag;
|
||||||
|
import net.kyori.adventure.nbt.LongArrayBinaryTag;
|
||||||
|
import net.kyori.adventure.nbt.LongBinaryTag;
|
||||||
|
import net.kyori.adventure.nbt.ShortBinaryTag;
|
||||||
import net.kyori.adventure.nbt.StringBinaryTag;
|
import net.kyori.adventure.nbt.StringBinaryTag;
|
||||||
import net.kyori.adventure.text.Component;
|
import net.kyori.adventure.text.Component;
|
||||||
|
import net.kyori.adventure.text.serializer.gson.GsonComponentSerializer;
|
||||||
import org.checkerframework.checker.nullness.qual.MonotonicNonNull;
|
import org.checkerframework.checker.nullness.qual.MonotonicNonNull;
|
||||||
|
|
||||||
public class ComponentHolder {
|
import java.util.ArrayList;
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.Map;
|
||||||
|
|
||||||
|
public class ComponentHolder {
|
||||||
public static ComponentHolder EMPTY = new ComponentHolder(null, Component.empty());
|
public static ComponentHolder EMPTY = new ComponentHolder(null, Component.empty());
|
||||||
|
|
||||||
static {
|
static {
|
||||||
EMPTY.json = "{\"text\":\"\"}";
|
EMPTY.json = "{\"text\":\"\"}";
|
||||||
EMPTY.binaryTag = StringBinaryTag.stringBinaryTag("");
|
EMPTY.binaryTag = StringBinaryTag.stringBinaryTag("");
|
||||||
@ -42,8 +81,8 @@ public class ComponentHolder {
|
|||||||
if (json != null) {
|
if (json != null) {
|
||||||
component = ProtocolUtils.getJsonChatSerializer(version).deserialize(json);
|
component = ProtocolUtils.getJsonChatSerializer(version).deserialize(json);
|
||||||
} else if (binaryTag != null) {
|
} else if (binaryTag != null) {
|
||||||
//TODO component = deserialize(binaryTag);
|
component = ProtocolUtils.getJsonChatSerializer(version)
|
||||||
throw new UnsupportedOperationException("binary tag -> component not implemented yet");
|
.deserialize(deserialize(binaryTag).toString());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return component;
|
return component;
|
||||||
@ -58,15 +97,172 @@ public class ComponentHolder {
|
|||||||
|
|
||||||
public BinaryTag getBinaryTag() {
|
public BinaryTag getBinaryTag() {
|
||||||
if (binaryTag == null) {
|
if (binaryTag == null) {
|
||||||
//TODO binaryTag = serialize(getComponent());
|
binaryTag = serialize(GsonComponentSerializer.gson().serializeToTree(getComponent()));
|
||||||
throw new UnsupportedOperationException("component -> binary tag not implemented yet");
|
|
||||||
}
|
}
|
||||||
return binaryTag;
|
return binaryTag;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static BinaryTag serialize(JsonElement json) {
|
||||||
|
if (json instanceof JsonPrimitive) {
|
||||||
|
JsonPrimitive jsonPrimitive = (JsonPrimitive) json;
|
||||||
|
|
||||||
|
if (jsonPrimitive.isNumber()) {
|
||||||
|
Number number = json.getAsNumber();
|
||||||
|
|
||||||
|
if (number instanceof Byte) {
|
||||||
|
return ByteBinaryTag.byteBinaryTag((Byte) number);
|
||||||
|
} else if (number instanceof Short) {
|
||||||
|
return ShortBinaryTag.shortBinaryTag((Short) number);
|
||||||
|
} else if (number instanceof Integer) {
|
||||||
|
return IntBinaryTag.intBinaryTag((Integer) number);
|
||||||
|
} else if (number instanceof Long) {
|
||||||
|
return LongBinaryTag.longBinaryTag((Long) number);
|
||||||
|
} else if (number instanceof Float) {
|
||||||
|
return FloatBinaryTag.floatBinaryTag((Float) number);
|
||||||
|
} else if (number instanceof Double) {
|
||||||
|
return DoubleBinaryTag.doubleBinaryTag((Double) number);
|
||||||
|
}
|
||||||
|
} else if (jsonPrimitive.isString()) {
|
||||||
|
return StringBinaryTag.stringBinaryTag(jsonPrimitive.getAsString());
|
||||||
|
} else if (jsonPrimitive.isBoolean()) {
|
||||||
|
return ByteBinaryTag.byteBinaryTag((byte) (jsonPrimitive.getAsBoolean() ? 1 : 0));
|
||||||
|
} else {
|
||||||
|
throw new IllegalArgumentException("Unknown JSON primitive: " + jsonPrimitive);
|
||||||
|
}
|
||||||
|
} else if (json instanceof JsonObject) {
|
||||||
|
CompoundBinaryTag.Builder compound = CompoundBinaryTag.builder();
|
||||||
|
|
||||||
|
for (Map.Entry<String, JsonElement> property : ((JsonObject) json).entrySet()) {
|
||||||
|
compound.put(property.getKey(), serialize(property.getValue()));
|
||||||
|
}
|
||||||
|
|
||||||
|
return compound.build();
|
||||||
|
} else if (json instanceof JsonArray) {
|
||||||
|
List<JsonElement> jsonArray = ((JsonArray) json).asList();
|
||||||
|
|
||||||
|
if (jsonArray.isEmpty()) {
|
||||||
|
return ListBinaryTag.empty();
|
||||||
|
}
|
||||||
|
|
||||||
|
BinaryTag listTag;
|
||||||
|
BinaryTagType<? extends BinaryTag> listType = serialize(jsonArray.get(0)).type();
|
||||||
|
|
||||||
|
switch (listType.id()) {
|
||||||
|
case 1://BinaryTagTypes.BYTE:
|
||||||
|
byte[] bytes = new byte[jsonArray.size()];
|
||||||
|
for (int i = 0; i < bytes.length; i++) {
|
||||||
|
bytes[i] = (Byte) jsonArray.get(i).getAsNumber();
|
||||||
|
}
|
||||||
|
|
||||||
|
listTag = ByteArrayBinaryTag.byteArrayBinaryTag(bytes);
|
||||||
|
break;
|
||||||
|
case 3://BinaryTagTypes.INT:
|
||||||
|
int[] ints = new int[jsonArray.size()];
|
||||||
|
for (int i = 0; i < ints.length; i++) {
|
||||||
|
ints[i] = (Integer) jsonArray.get(i).getAsNumber();
|
||||||
|
}
|
||||||
|
|
||||||
|
listTag = IntArrayBinaryTag.intArrayBinaryTag(ints);
|
||||||
|
break;
|
||||||
|
case 4://BinaryTagTypes.LONG:
|
||||||
|
long[] longs = new long[jsonArray.size()];
|
||||||
|
for (int i = 0; i < longs.length; i++) {
|
||||||
|
longs[i] = (Long) jsonArray.get(i).getAsNumber();
|
||||||
|
}
|
||||||
|
|
||||||
|
listTag = LongArrayBinaryTag.longArrayBinaryTag(longs);
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
List<BinaryTag> tagItems = new ArrayList<>(jsonArray.size());
|
||||||
|
|
||||||
|
for (JsonElement jsonEl : jsonArray) {
|
||||||
|
BinaryTag subTag = serialize(jsonEl);
|
||||||
|
|
||||||
|
if (subTag.type() != listType) {
|
||||||
|
throw new IllegalArgumentException("Cannot convert mixed JsonArray to Tag");
|
||||||
|
}
|
||||||
|
|
||||||
|
tagItems.add(subTag);
|
||||||
|
}
|
||||||
|
|
||||||
|
listTag = ListBinaryTag.listBinaryTag(listType, tagItems);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
return listTag;
|
||||||
|
}
|
||||||
|
|
||||||
|
return EndBinaryTag.endBinaryTag();
|
||||||
|
}
|
||||||
|
|
||||||
|
public static JsonElement deserialize(BinaryTag tag) {
|
||||||
|
switch (tag.type().id()) {
|
||||||
|
case 1://BinaryTagTypes.BYTE:
|
||||||
|
return new JsonPrimitive(((ByteBinaryTag) tag).value());
|
||||||
|
case 2://BinaryTagTypes.SHORT:
|
||||||
|
return new JsonPrimitive(((ShortBinaryTag) tag).value());
|
||||||
|
case 3://BinaryTagTypes.INT:
|
||||||
|
return new JsonPrimitive(((IntBinaryTag) tag).value());
|
||||||
|
case 4://BinaryTagTypes.LONG:
|
||||||
|
return new JsonPrimitive(((LongBinaryTag) tag).value());
|
||||||
|
case 5://BinaryTagTypes.FLOAT:
|
||||||
|
return new JsonPrimitive(((FloatBinaryTag) tag).value());
|
||||||
|
case 6://BinaryTagTypes.DOUBLE:
|
||||||
|
return new JsonPrimitive(((DoubleBinaryTag) tag).value());
|
||||||
|
case 7://BinaryTagTypes.BYTE_ARRAY:
|
||||||
|
byte[] byteArray = ((ByteArrayBinaryTag) tag).value();
|
||||||
|
|
||||||
|
JsonArray jsonByteArray = new JsonArray(byteArray.length);
|
||||||
|
for (byte b : byteArray) {
|
||||||
|
jsonByteArray.add(new JsonPrimitive(b));
|
||||||
|
}
|
||||||
|
|
||||||
|
return jsonByteArray;
|
||||||
|
case 8://BinaryTagTypes.STRING:
|
||||||
|
return new JsonPrimitive(((StringBinaryTag) tag).value());
|
||||||
|
case 9://BinaryTagTypes.LIST:
|
||||||
|
ListBinaryTag items = (ListBinaryTag) tag;
|
||||||
|
JsonArray jsonList = new JsonArray(items.size());
|
||||||
|
|
||||||
|
for (BinaryTag subTag : items) {
|
||||||
|
jsonList.add(deserialize(subTag));
|
||||||
|
}
|
||||||
|
|
||||||
|
return jsonList;
|
||||||
|
case 10://BinaryTagTypes.COMPOUND:
|
||||||
|
CompoundBinaryTag compound = (CompoundBinaryTag) tag;
|
||||||
|
JsonObject jsonObject = new JsonObject();
|
||||||
|
|
||||||
|
compound.keySet().forEach(key -> jsonObject.add(key, deserialize(compound.get(key))));
|
||||||
|
|
||||||
|
return jsonObject;
|
||||||
|
case 11://BinaryTagTypes.INT_ARRAY:
|
||||||
|
int[] intArray = ((IntArrayBinaryTag) tag).value();
|
||||||
|
|
||||||
|
JsonArray jsonIntArray = new JsonArray(intArray.length);
|
||||||
|
for (int i : intArray) {
|
||||||
|
jsonIntArray.add(new JsonPrimitive(i));
|
||||||
|
}
|
||||||
|
|
||||||
|
return jsonIntArray;
|
||||||
|
case 12://BinaryTagTypes.LONG_ARRAY:
|
||||||
|
long[] longArray = ((LongArrayBinaryTag) tag).value();
|
||||||
|
|
||||||
|
JsonArray jsonLongArray = new JsonArray(longArray.length);
|
||||||
|
for (long l : longArray) {
|
||||||
|
jsonLongArray.add(new JsonPrimitive(l));
|
||||||
|
}
|
||||||
|
|
||||||
|
return jsonLongArray;
|
||||||
|
default:
|
||||||
|
throw new IllegalArgumentException("Unknown NBT tag: " + tag);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
public static ComponentHolder read(ByteBuf buf, ProtocolVersion version) {
|
public static ComponentHolder read(ByteBuf buf, ProtocolVersion version) {
|
||||||
if (version.compareTo(ProtocolVersion.MINECRAFT_1_20_3) >= 0) {
|
if (version.compareTo(ProtocolVersion.MINECRAFT_1_20_3) >= 0) {
|
||||||
return new ComponentHolder(version, ProtocolUtils.readBinaryTag(buf, version, BinaryTagIO.reader()));
|
return new ComponentHolder(version,
|
||||||
|
ProtocolUtils.readBinaryTag(buf, version, BinaryTagIO.reader()));
|
||||||
} else {
|
} else {
|
||||||
return new ComponentHolder(version, ProtocolUtils.readString(buf));
|
return new ComponentHolder(version, ProtocolUtils.readString(buf));
|
||||||
}
|
}
|
||||||
|
@ -22,9 +22,8 @@ import com.velocitypowered.api.proxy.player.TabList;
|
|||||||
import com.velocitypowered.api.proxy.player.TabListEntry;
|
import com.velocitypowered.api.proxy.player.TabListEntry;
|
||||||
import com.velocitypowered.api.util.GameProfile;
|
import com.velocitypowered.api.util.GameProfile;
|
||||||
import com.velocitypowered.proxy.protocol.packet.UpsertPlayerInfo;
|
import com.velocitypowered.proxy.protocol.packet.UpsertPlayerInfo;
|
||||||
import java.util.Optional;
|
|
||||||
|
|
||||||
import com.velocitypowered.proxy.protocol.packet.chat.ComponentHolder;
|
import com.velocitypowered.proxy.protocol.packet.chat.ComponentHolder;
|
||||||
|
import java.util.Optional;
|
||||||
import net.kyori.adventure.text.Component;
|
import net.kyori.adventure.text.Component;
|
||||||
import org.checkerframework.checker.nullness.qual.Nullable;
|
import org.checkerframework.checker.nullness.qual.Nullable;
|
||||||
|
|
||||||
@ -80,7 +79,8 @@ public class VelocityTabListEntry implements TabListEntry {
|
|||||||
public TabListEntry setDisplayName(@Nullable Component displayName) {
|
public TabListEntry setDisplayName(@Nullable Component displayName) {
|
||||||
this.displayName = displayName;
|
this.displayName = displayName;
|
||||||
UpsertPlayerInfo.Entry upsertEntry = this.tabList.createRawEntry(this);
|
UpsertPlayerInfo.Entry upsertEntry = this.tabList.createRawEntry(this);
|
||||||
upsertEntry.setDisplayName(new ComponentHolder(this.tabList.getPlayer().getProtocolVersion(), displayName));
|
upsertEntry.setDisplayName(
|
||||||
|
new ComponentHolder(this.tabList.getPlayer().getProtocolVersion(), displayName));
|
||||||
this.tabList.emitActionRaw(UpsertPlayerInfo.Action.UPDATE_DISPLAY_NAME, upsertEntry);
|
this.tabList.emitActionRaw(UpsertPlayerInfo.Action.UPDATE_DISPLAY_NAME, upsertEntry);
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
@ -212,7 +212,8 @@ public class AdventureBossBarManager implements BossBar.Listener {
|
|||||||
.proxy.protocol.packet.BossBar();
|
.proxy.protocol.packet.BossBar();
|
||||||
packet.setUuid(this.id);
|
packet.setUuid(this.id);
|
||||||
packet.setAction(com.velocitypowered.proxy.protocol.packet.BossBar.ADD);
|
packet.setAction(com.velocitypowered.proxy.protocol.packet.BossBar.ADD);
|
||||||
packet.setName(new ComponentHolder(player.getProtocolVersion(), player.translateMessage(bar.name())));
|
packet.setName(
|
||||||
|
new ComponentHolder(player.getProtocolVersion(), player.translateMessage(bar.name())));
|
||||||
packet.setColor(COLORS_TO_PROTOCOL.get(bar.color()));
|
packet.setColor(COLORS_TO_PROTOCOL.get(bar.color()));
|
||||||
packet.setOverlay(OVERLAY_TO_PROTOCOL.get(bar.overlay()));
|
packet.setOverlay(OVERLAY_TO_PROTOCOL.get(bar.overlay()));
|
||||||
packet.setPercent(bar.progress());
|
packet.setPercent(bar.progress());
|
||||||
|
Laden…
In neuem Issue referenzieren
Einen Benutzer sperren