3
0
Mirror von https://github.com/ViaVersion/ViaVersion.git synchronisiert 2024-12-26 16:12:42 +01:00

Semi force packet types in PacketWrapper at creation and transformation

Dieser Commit ist enthalten in:
kennytv 2021-07-31 12:43:07 +02:00
Ursprung 874dbafe26
Commit b81109f512
Es konnte kein GPG-Schlüssel zu dieser Signatur gefunden werden
GPG-Schlüssel-ID: 6BE3B555EBC5982B
39 geänderte Dateien mit 636 neuen und 296 gelöschten Zeilen

Datei anzeigen

@ -93,19 +93,17 @@ public abstract class AbstractProtocol<C1 extends ClientboundPacketType, C2 exte
newClientboundPackets.put(newConstant.getName(), newConstant);
}
for (ClientboundPacketType packet : oldClientboundPacketEnum.getEnumConstants()) {
ClientboundPacketType mappedPacket = newClientboundPackets.get(packet.getName());
int oldId = packet.getId();
for (C1 packet : oldClientboundPacketEnum.getEnumConstants()) {
C2 mappedPacket = (C2) newClientboundPackets.get(packet.getName());
if (mappedPacket == null) {
// Packet doesn't exist on new client
Preconditions.checkArgument(hasRegisteredClientbound(State.PLAY, oldId),
Preconditions.checkArgument(hasRegisteredClientbound(packet),
"Packet " + packet + " in " + getClass().getSimpleName() + " has no mapping - it needs to be manually cancelled or remapped!");
continue;
}
int newId = mappedPacket.getId();
if (!hasRegisteredClientbound(State.PLAY, oldId)) {
registerClientbound(State.PLAY, oldId, newId);
if (!hasRegisteredClientbound(packet)) {
registerClientbound(packet, mappedPacket);
}
}
}
@ -117,19 +115,17 @@ public abstract class AbstractProtocol<C1 extends ClientboundPacketType, C2 exte
oldServerboundConstants.put(oldConstant.getName(), oldConstant);
}
for (ServerboundPacketType packet : newServerboundPacketEnum.getEnumConstants()) {
ServerboundPacketType mappedPacket = oldServerboundConstants.get(packet.getName());
int newId = packet.getId();
for (S2 packet : newServerboundPacketEnum.getEnumConstants()) {
S1 mappedPacket = (S1) oldServerboundConstants.get(packet.getName());
if (mappedPacket == null) {
// Packet doesn't exist on old server
Preconditions.checkArgument(hasRegisteredServerbound(State.PLAY, newId),
Preconditions.checkArgument(hasRegisteredServerbound(packet),
"Packet " + packet + " in " + getClass().getSimpleName() + " has no mapping - it needs to be manually cancelled or remapped!");
continue;
}
int oldId = mappedPacket.getId();
if (!hasRegisteredServerbound(State.PLAY, newId)) {
registerServerbound(State.PLAY, oldId, newId);
if (!hasRegisteredServerbound(packet)) {
registerServerbound(packet, mappedPacket);
}
}
}
@ -158,6 +154,7 @@ public abstract class AbstractProtocol<C1 extends ClientboundPacketType, C2 exte
connection.addEntityTracker(this.getClass(), tracker);
}
@Override
public void registerServerbound(State state, int oldPacketID, int newPacketID, PacketRemapper packetRemapper, boolean override) {
ProtocolPacket protocolPacket = new ProtocolPacket(state, oldPacketID, newPacketID, packetRemapper);
@ -209,22 +206,22 @@ public abstract class AbstractProtocol<C1 extends ClientboundPacketType, C2 exte
: Arrays.stream(newClientboundPacketEnum.getEnumConstants()).filter(en -> en.getName().equals(packetType.getName())).findAny().orElse(null);
Preconditions.checkNotNull(mappedPacket, "Packet type " + packetType + " in " + packetType.getClass().getSimpleName() + " could not be automatically mapped!");
int oldId = packetType.getId();
int newId = mappedPacket.getId();
registerClientbound(State.PLAY, oldId, newId, packetRemapper);
registerClientbound(packetType, (C2) mappedPacket, packetRemapper);
}
@Override
public void registerClientbound(C1 packetType, @Nullable C2 mappedPacketType, @Nullable PacketRemapper packetRemapper) {
checkPacketType(packetType, packetType.getClass() == oldClientboundPacketEnum);
checkPacketType(mappedPacketType, mappedPacketType == null || mappedPacketType.getClass() == newClientboundPacketEnum);
registerClientbound(State.PLAY, packetType.getId(), mappedPacketType != null ? mappedPacketType.getId() : -1, packetRemapper);
public void registerClientbound(C1 packetType, @Nullable C2 mappedPacketType, @Nullable PacketRemapper packetRemapper, boolean override) {
register(clientbound, packetType, mappedPacketType, oldClientboundPacketEnum, newClientboundPacketEnum, packetRemapper, override);
}
@Override
public void cancelClientbound(C1 packetType) {
cancelClientbound(State.PLAY, packetType.getId(), packetType.getId());
registerClientbound(packetType, null, new PacketRemapper() {
@Override
public void registerMap() {
handler(PacketWrapper::cancel);
}
});
}
@Override
@ -235,58 +232,88 @@ public abstract class AbstractProtocol<C1 extends ClientboundPacketType, C2 exte
: Arrays.stream(oldServerboundPacketEnum.getEnumConstants()).filter(en -> en.getName().equals(packetType.getName())).findAny().orElse(null);
Preconditions.checkNotNull(mappedPacket, "Packet type " + packetType + " in " + packetType.getClass().getSimpleName() + " could not be automatically mapped!");
int oldId = mappedPacket.getId();
int newId = packetType.getId();
registerServerbound(State.PLAY, oldId, newId, packetRemapper);
registerServerbound(packetType, (S1) mappedPacket, packetRemapper);
}
@Override
public void registerServerbound(S2 packetType, @Nullable S1 mappedPacketType, @Nullable PacketRemapper packetRemapper) {
checkPacketType(packetType, packetType.getClass() == newServerboundPacketEnum);
checkPacketType(mappedPacketType, mappedPacketType == null || mappedPacketType.getClass() == oldServerboundPacketEnum);
registerServerbound(State.PLAY, mappedPacketType != null ? mappedPacketType.getId() : -1, packetType.getId(), packetRemapper);
public void registerServerbound(S2 packetType, @Nullable S1 mappedPacketType, @Nullable PacketRemapper packetRemapper, boolean override) {
register(serverbound, packetType, mappedPacketType, newServerboundPacketEnum, oldServerboundPacketEnum, packetRemapper, override);
}
@Override
public void cancelServerbound(S2 packetType) {
Preconditions.checkArgument(packetType.getClass() == newServerboundPacketEnum);
cancelServerbound(State.PLAY, -1, packetType.getId());
registerServerbound(packetType, null, new PacketRemapper() {
@Override
public void registerMap() {
handler(PacketWrapper::cancel);
}
});
}
private void register(Map<Packet, ProtocolPacket> packetMap, PacketType packetType, @Nullable PacketType mappedPacketType,
Class<? extends PacketType> unmappedPacketEnum, Class<? extends PacketType> mappedPacketEnum,
@Nullable PacketRemapper remapper, boolean override) {
checkPacketType(packetType, packetType.getClass() == unmappedPacketEnum);
checkPacketType(mappedPacketType, mappedPacketType == null || mappedPacketType.getClass() == mappedPacketEnum);
Preconditions.checkArgument(mappedPacketType == null || packetType.state() == mappedPacketType.state(), "Packet type state does not match mapped packet type state");
ProtocolPacket protocolPacket = new ProtocolPacket(packetType.state(), packetType, mappedPacketType, remapper);
Packet packet = new Packet(packetType.state(), packetType.getId());
if (!override && packetMap.containsKey(packet)) {
Via.getPlatform().getLogger().log(Level.WARNING, packet + " already registered!" +
" If override is intentional, set override to true. Stacktrace: ", new Exception());
}
packetMap.put(packet, protocolPacket);
}
@Override
public boolean hasRegisteredClientbound(State state, int oldPacketID) {
Packet packet = new Packet(state, oldPacketID);
public boolean hasRegisteredClientbound(C1 packetType) {
return hasRegisteredClientbound(packetType.state(), packetType.getId());
}
@Override
public boolean hasRegisteredServerbound(S2 packetType) {
return hasRegisteredServerbound(packetType.state(), packetType.getId());
}
@Override
public boolean hasRegisteredClientbound(State state, int unmappedPacketid) {
Packet packet = new Packet(state, unmappedPacketid);
return clientbound.containsKey(packet);
}
@Override
public boolean hasRegisteredServerbound(State state, int newPacketId) {
Packet packet = new Packet(state, newPacketId);
public boolean hasRegisteredServerbound(State state, int unmappedPacketId) {
Packet packet = new Packet(state, unmappedPacketId);
return serverbound.containsKey(packet);
}
@Override
public void transform(Direction direction, State state, PacketWrapper packetWrapper) throws Exception {
Packet statePacket = new Packet(state, packetWrapper.getId());
Map<Packet, ProtocolPacket> packetMap = (direction == Direction.CLIENTBOUND ? clientbound : serverbound);
Map<Packet, ProtocolPacket> packetMap = (direction == Direction.CLIENTBOUND ? this.clientbound : serverbound);
ProtocolPacket protocolPacket = packetMap.get(statePacket);
if (protocolPacket == null) {
return;
}
// Write packet id
int oldId = packetWrapper.getId();
int newId = direction == Direction.CLIENTBOUND ? protocolPacket.getNewID() : protocolPacket.getOldID();
packetWrapper.setId(newId);
int unmappedId = packetWrapper.getId();
if (protocolPacket.isMappedOverTypes()) {
packetWrapper.setPacketType(protocolPacket.getMappedPacketType());
} else {
int mappedId = direction == Direction.CLIENTBOUND ? protocolPacket.getNewId() : protocolPacket.getOldId();
if (unmappedId != mappedId) {
packetWrapper.setId(mappedId);
}
}
PacketRemapper remapper = protocolPacket.getRemapper();
if (remapper != null) {
try {
remapper.remap(packetWrapper);
} catch (InformativeException e) { // Catch InformativeExceptions, pass through CancelExceptions
throwRemapError(direction, state, oldId, newId, e);
throwRemapError(direction, state, unmappedId, packetWrapper.getId(), e);
return;
}
@ -390,14 +417,34 @@ public abstract class AbstractProtocol<C1 extends ClientboundPacketType, C2 exte
public static final class ProtocolPacket {
private final State state;
private final int oldID;
private final int newID;
private final int oldId;
private final int newId;
private final PacketType unmappedPacketType;
private final PacketType mappedPacketType;
private final PacketRemapper remapper;
public ProtocolPacket(State state, int oldID, int newID, @Nullable PacketRemapper remapper) {
@Deprecated
public ProtocolPacket(State state, int oldId, int newId, @Nullable PacketRemapper remapper) {
this.state = state;
this.oldID = oldID;
this.newID = newID;
this.oldId = oldId;
this.newId = newId;
this.remapper = remapper;
this.unmappedPacketType = null;
this.mappedPacketType = null;
}
public ProtocolPacket(State state, PacketType unmappedPacketType, @Nullable PacketType mappedPacketType, @Nullable PacketRemapper remapper) {
this.state = state;
this.unmappedPacketType = unmappedPacketType;
if (unmappedPacketType.direction() == Direction.CLIENTBOUND) {
this.oldId = unmappedPacketType.getId();
this.newId = mappedPacketType != null ? mappedPacketType.getId() : -1;
} else {
// Serverbound switcheroo in old vs. new id caused issues and was counterintuitive
this.oldId = mappedPacketType != null ? mappedPacketType.getId() : -1;
this.newId = unmappedPacketType.getId();
}
this.mappedPacketType = mappedPacketType;
this.remapper = remapper;
}
@ -405,12 +452,40 @@ public abstract class AbstractProtocol<C1 extends ClientboundPacketType, C2 exte
return state;
}
public int getOldID() {
return oldID;
@Deprecated
public int getOldId() {
return oldId;
}
public int getNewID() {
return newID;
@Deprecated
public int getNewId() {
return newId;
}
/**
* Returns the unmapped packet type, or null if mapped over ids.
* This is NOT the same as calling {@link #getOldId()} (think of unmapped vs. old in 1.17->1.16).
*
* @return unmapped packet type, or null if mapped over ids
*/
@Nullable
public PacketType getUnmappedPacketType() {
return unmappedPacketType;
}
/**
* Returns the mapped packet type, or null if mapped over ids or mapped to no packet type.
* This is NOT the same as calling {@link #getNewId()} (think of mapped vs. new in 1.17->1.16).
*
* @return new packet type, or null if mapped over ids or mapped to no packet type
*/
@Nullable
public PacketType getMappedPacketType() {
return mappedPacketType;
}
public boolean isMappedOverTypes() {
return unmappedPacketType != null;
}
@Nullable

Datei anzeigen

@ -47,29 +47,24 @@ import org.checkerframework.checker.nullness.qual.Nullable;
*/
public interface Protocol<C1 extends ClientboundPacketType, C2 extends ClientboundPacketType, S1 extends ServerboundPacketType, S2 extends ServerboundPacketType> {
/**
* Register a serverbound packet, with simple id transformation.
*
* @param state The state which the packet is sent in.
* @param oldPacketID The old packet ID
* @param newPacketID The new packet ID
*/
default void registerServerbound(State state, int oldPacketID, int newPacketID) {
registerServerbound(state, oldPacketID, newPacketID, null);
}
/**
* Register a serverbound packet, with id transformation and remapper.
*
* @param state The state which the packet is sent in.
* @param oldPacketID The old packet ID
* @param newPacketID The new packet ID
* @param packetRemapper The remapper to use for the packet
*/
default void registerServerbound(State state, int oldPacketID, int newPacketID, PacketRemapper packetRemapper) {
registerServerbound(state, oldPacketID, newPacketID, packetRemapper, false);
}
/**
* Registers a serverbound packet, with id transformation and remapper.
*
* @param state state which the packet is sent in.
* @param oldPacketID old packet ID
* @param newPacketID new packet ID
* @param packetRemapper remapper to use for the packet
* @param override whether an existing mapper should be overridden
* @see #registerServerbound(ServerboundPacketType, ServerboundPacketType, PacketRemapper, boolean)
*/
void registerServerbound(State state, int oldPacketID, int newPacketID, PacketRemapper packetRemapper, boolean override);
void cancelServerbound(State state, int oldPacketID, int newPacketID);
@ -78,25 +73,10 @@ public interface Protocol<C1 extends ClientboundPacketType, C2 extends Clientbou
cancelServerbound(state, -1, newPacketID);
}
/**
* Register a clientbound packet, with simple id transformation.
*
* @param state The state which the packet is sent in.
* @param oldPacketID The old packet ID
* @param newPacketID The new packet ID
*/
default void registerClientbound(State state, int oldPacketID, int newPacketID) {
registerClientbound(state, oldPacketID, newPacketID, null);
}
/**
* Register a clientbound packet, with id transformation and remapper.
*
* @param state The state which the packet is sent in.
* @param oldPacketID The old packet ID
* @param newPacketID The new packet ID
* @param packetRemapper The remapper to use for the packet
*/
default void registerClientbound(State state, int oldPacketID, int newPacketID, PacketRemapper packetRemapper) {
registerClientbound(state, oldPacketID, newPacketID, packetRemapper, false);
}
@ -107,8 +87,20 @@ public interface Protocol<C1 extends ClientboundPacketType, C2 extends Clientbou
cancelClientbound(state, oldPacketID, -1);
}
/**
* Registers a clientbound packet, with id transformation and remapper.
*
* @param state state which the packet is sent in.
* @param oldPacketID old packet ID
* @param newPacketID new packet ID
* @param packetRemapper remapper to use for the packet
* @param override whether an existing mapper should be overridden
* @see #registerClientbound(ClientboundPacketType, ClientboundPacketType, PacketRemapper, boolean)
*/
void registerClientbound(State state, int oldPacketID, int newPacketID, PacketRemapper packetRemapper, boolean override);
// ---------------------------------------------------------------------------------------
/**
* Registers a clientbound protocol and automatically maps it to the new id.
*
@ -117,15 +109,6 @@ public interface Protocol<C1 extends ClientboundPacketType, C2 extends Clientbou
*/
void registerClientbound(C1 packetType, @Nullable PacketRemapper packetRemapper);
/**
* Registers a clientbound protocol.
*
* @param packetType clientbound packet type the server initially sends
* @param mappedPacketType clientbound packet type after transforming for the client
* @param packetRemapper remapper
*/
void registerClientbound(C1 packetType, C2 mappedPacketType, @Nullable PacketRemapper packetRemapper);
/**
* Maps a packet type to another packet type without a packet handler.
* Note that this should not be called for simple channel mappings of the same packet; this is already done automatically.
@ -137,6 +120,27 @@ public interface Protocol<C1 extends ClientboundPacketType, C2 extends Clientbou
registerClientbound(packetType, mappedPacketType, null);
}
/**
* Registers a clientbound packet mapping.
*
* @param packetType clientbound packet type the server initially sends
* @param mappedPacketType clientbound packet type after transforming for the client
* @param packetRemapper remapper
*/
default void registerClientbound(C1 packetType, @Nullable C2 mappedPacketType, @Nullable PacketRemapper packetRemapper) {
registerClientbound(packetType, mappedPacketType, packetRemapper, false);
}
/**
* Registers a clientbound packet mapping.
*
* @param packetType clientbound packet type the server initially sends
* @param mappedPacketType clientbound packet type after transforming for the client
* @param packetRemapper remapper
* @param override whether an existing mapping should be overridden if present
*/
void registerClientbound(C1 packetType, @Nullable C2 mappedPacketType, @Nullable PacketRemapper packetRemapper, boolean override);
/**
* Cancels any clientbound packets from the given type.
*
@ -144,6 +148,17 @@ public interface Protocol<C1 extends ClientboundPacketType, C2 extends Clientbou
*/
void cancelClientbound(C1 packetType);
/**
* Maps a packet type to another packet type without a packet handler.
* Note that this should not be called for simple channel mappings of the same packet; this is already done automatically.
*
* @param packetType serverbound packet type the client initially sends
* @param mappedPacketType serverbound packet type after transforming for the client
*/
default void registerServerbound(S2 packetType, @Nullable S1 mappedPacketType) {
registerServerbound(packetType, mappedPacketType, null);
}
/**
* Registers a serverbound protocol and automatically maps it to the server's id.
*
@ -159,7 +174,19 @@ public interface Protocol<C1 extends ClientboundPacketType, C2 extends Clientbou
* @param mappedPacketType serverbound packet type after transforming for the server
* @param packetRemapper remapper
*/
void registerServerbound(S2 packetType, @Nullable S1 mappedPacketType, @Nullable PacketRemapper packetRemapper);
default void registerServerbound(S2 packetType, @Nullable S1 mappedPacketType, @Nullable PacketRemapper packetRemapper) {
registerServerbound(packetType, mappedPacketType, packetRemapper, false);
}
/**
* Registers a serverbound packet mapping.
*
* @param packetType serverbound packet type initially sent by the client
* @param mappedPacketType serverbound packet type after transforming for the server
* @param packetRemapper remapper
* @param override whether an existing mapping should be overridden if present
*/
void registerServerbound(S2 packetType, @Nullable S1 mappedPacketType, @Nullable PacketRemapper packetRemapper, boolean override);
/**
* Cancels any serverbound packets from the given type.
@ -168,23 +195,40 @@ public interface Protocol<C1 extends ClientboundPacketType, C2 extends Clientbou
*/
void cancelServerbound(S2 packetType);
/**
* Checks if a clientbound packet has already been registered.
*
* @param state state which the packet is sent in
* @param oldPacketID old packet ID
* @param packetType clientbound packet type
* @return true if already registered
*/
boolean hasRegisteredClientbound(State state, int oldPacketID);
boolean hasRegisteredClientbound(C1 packetType);
/**
* Checks if a serverbound packet has already been registered.
*
* @param state state which the packet is sent in
* @param newPacketId packet ID
* @param packetType serverbound packet type
* @return true if already registered
*/
boolean hasRegisteredServerbound(State state, int newPacketId);
boolean hasRegisteredServerbound(S2 packetType);
/**
* Checks if a clientbound packet has already been registered.
*
* @param state state which the packet is sent in
* @param oldPacketId old packet id
* @return true if already registered
*/
boolean hasRegisteredClientbound(State state, int oldPacketId);
/**
* Checks if a serverbound packet has already been registered.
*
* @param state state which the packet is sent in
* @param unmappedPacketId new packet id
* @return true if already registered
*/
boolean hasRegisteredServerbound(State state, int unmappedPacketId);
/**
* Transform a packet using this protocol

Datei anzeigen

@ -151,16 +151,14 @@ public interface ProtocolManager {
* The used packet types have to match the given protocol version.
*
* @param inputVersion input protocol version
* @param <C> clientbound packet for the given protocol version
* @param <S> serverbound packet for the given protocol version
* @param clientboundPacketsClass clientbound packets class
* @param serverboundPacketsClass serverbound packets class
* @return versioned packet creator
* @throws IllegalArgumentException if either of the packet classes are the base {@link ClientboundPacketType} or {@link ServerboundPacketType} interfaces
*/
<C extends ClientboundPacketType,
S extends ServerboundPacketType
> VersionedPacketCreator<C, S> createVersionedPacketCreator(ProtocolVersion inputVersion, Class<C> clientboundPacketsClass, Class<S> serverboundPacketsClass);
VersionedPacketCreator createVersionedPacketCreator(ProtocolVersion inputVersion,
Class<? extends ClientboundPacketType> clientboundPacketsClass,
Class<? extends ServerboundPacketType> serverboundPacketsClass);
/**
* Returns whether protocol path calculation expects the path to come closer to the expected version with each entry, true by default.
@ -267,11 +265,23 @@ public interface ProtocolManager {
/**
* Creates a new packet wrapper instance.
*
* @param packetId packet id
* @param packetType packet type, or null if none should be written to the packet (raw id = -1)
* @param buf input buffer
* @param connection user connection
* @return new packet wrapper instance
* @see PacketWrapper#create(PacketType, ByteBuf, UserConnection)
*/
PacketWrapper createPacketWrapper(@Nullable PacketType packetType, @Nullable ByteBuf buf, UserConnection connection);
/**
* Creates a new packet wrapper instance.
*
* @param packetId packet id
* @param buf input buffer
* @param connection user connection
* @return new packet wrapper instance
* @deprecated magic id; prefer using {@link #createPacketWrapper(PacketType, ByteBuf, UserConnection)}
*/
@Deprecated
PacketWrapper createPacketWrapper(int packetId, @Nullable ByteBuf buf, UserConnection connection);
}

Datei anzeigen

@ -50,4 +50,13 @@ public interface PacketType {
* @return direction
*/
Direction direction();
/**
* Returns the protocol state the packet belongs to.
*
* @return protocol state
*/
default State state() {
return State.PLAY;
}
}

Datei anzeigen

@ -41,34 +41,36 @@ public interface PacketWrapper {
/**
* Creates a new packet wrapper instance.
*
* @param packetType packet
* @param packetType packet type, or null if none should be written to the buffer (raw id = -1)
* @param connection user connection
* @return new packet wrapper
*/
static PacketWrapper create(PacketType packetType, UserConnection connection) {
return create(packetType.getId(), null, connection);
static PacketWrapper create(@Nullable PacketType packetType, UserConnection connection) {
return create(packetType, null, connection);
}
/**
* Creates a new packet wrapper instance.
*
* @param packetType packet type
* @param packetType packet type, or null if none should be written to the buffer (raw id = -1)
* @param inputBuffer input buffer
* @param connection user connection
* @return new packet wrapper
*/
static PacketWrapper create(PacketType packetType, @Nullable ByteBuf inputBuffer, UserConnection connection) {
return create(packetType.getId(), inputBuffer, connection);
static PacketWrapper create(@Nullable PacketType packetType, @Nullable ByteBuf inputBuffer, UserConnection connection) {
return Via.getManager().getProtocolManager().createPacketWrapper(packetType, inputBuffer, connection);
}
/**
* Creates a new packet wrapper instance.
*
* @param packetId packet id
* @param packetId packet id, or -1 if none should be written to the buffer
* @param inputBuffer input buffer
* @param connection user connection
* @return new packet wrapper
* @deprecated magic id; prefer using {@link #create(PacketType, ByteBuf, UserConnection)}
*/
@Deprecated
static PacketWrapper create(int packetId, @Nullable ByteBuf inputBuffer, UserConnection connection) {
return Via.getManager().getProtocolManager().createPacketWrapper(packetId, inputBuffer, connection);
}
@ -387,25 +389,45 @@ public interface PacketWrapper {
void scheduleSendToServer(Class<? extends Protocol> protocol, boolean skipCurrentPipeline) throws Exception;
/**
* Returns the packet id.
* Returns the packet type.
* Currently only non-null for manually constructed packets before transformation.
*
* @return packet id
* @return packet type if set
*/
@Nullable PacketType getPacketType();
/**
* Sets the packet type. If set to null, it will not be written to the buffer with {@link #writeToBuffer(ByteBuf)}.
* Setting the type to null also sets the raw packet id to -1.
*
* @param packetType packet type
*/
void setPacketType(@Nullable PacketType packetType);
/**
* Returns the raw packet id.
*
* @return raw packet id
*/
int getId();
/**
* Sets the packet id. If set to -1, it will not be written to the buffer with {@link #writeToBuffer(ByteBuf)}.
* Sets the packet type.
*
* @param packetType packet type
* @deprecated use {@link #setPacketType(PacketType)}. This method will be removed in 5.0.0
*/
@Deprecated/*(forRemoval = true)*/
default void setId(PacketType packetType) {
setId(packetType.getId());
setPacketType(packetType);
}
/**
* Sets the packet id. If set to -1, it will not be written to the buffer with {@link #writeToBuffer(ByteBuf)}.
*
* @param id packet id
* @deprecated magic id, loses packet type info; use {@link #setPacketType(PacketType)}
*/
@Deprecated
void setId(int id);
}

Datei anzeigen

@ -23,100 +23,48 @@
package com.viaversion.viaversion.api.protocol.packet;
import com.viaversion.viaversion.api.connection.ProtocolInfo;
import com.viaversion.viaversion.api.connection.UserConnection;
import org.checkerframework.checker.nullness.qual.Nullable;
import java.util.function.Consumer;
/**
* Utility to send packets from a given base version to or from any client version supported by Via.
*
* @param <C> clientbound packet type
* @param <S> serverbound packet type
*/
public interface VersionedPacketCreator<C extends ClientboundPacketType, S extends ServerboundPacketType> {
public interface VersionedPacketCreator {
/**
* Sends a packet to the given user.
* Sends a packet to the user or server, depending on the packet type given by {@link PacketWrapper#getPacketType()}.
* Returns false if the packet has been cancelled at some point, but does not indicate whether a replacement has been constructed.
*
* @param connection user connection
* @param packetType clientbound packet type
* @param packetWriter consumer filling the packet with data
* @return whether this packet specifically has been sent, false if cancelled
* @throws IllegalArgumentException if the packet type is not of the expected clientbound packets class
* @throws IllegalArgumentException if the packet type is not of the expected clientbound or serverbound packets class
* @throws IllegalArgumentException if {@link PacketWrapper#user()} returns null
* @throws RuntimeException if no path from the input version to the required client version exists
* @throws Exception if an error occurred while constructing the packet or sending it
*/
boolean send(UserConnection connection, C packetType, Consumer<PacketWrapper> packetWriter) throws Exception;
boolean send(PacketWrapper packet) throws Exception;
/**
* Sends a packet to the server.
* Sends a packet to the user or server, depending on the packet type given by {@link PacketWrapper#getPacketType()}, submitted to the netty event loop.
* Returns false if the packet has been cancelled at some point, but does not indicate whether a replacement has been constructed.
*
* @param connection user connection
* @param packetType serverbound packet type
* @param packetWriter consumer filling the packet with data
* @return whether this packet specifically has been sent, false if cancelled
* @throws IllegalArgumentException if the packet type is not of the expected serverbound packets class
* @throws RuntimeException if no path from the input version to the required server version exists
* @throws Exception if an error occurred while constructing the packet or sending it
*/
boolean send(UserConnection connection, S packetType, Consumer<PacketWrapper> packetWriter) throws Exception;
/**
* Sends a packet to the given user, submitted to the netty event loop.
* Returns false if the packet has been cancelled at some point, but does not indicate whether a replacement has been constructed.
*
* @param connection user connection
* @param packetType clientbound packet type
* @param packetWriter consumer filling the packet with data
* @param packet packet wrapper
* @return whether this packet specifically has been sent, false if cancelled
* @throws IllegalArgumentException if the packet type is not of the expected clientbound packets class
* @throws IllegalArgumentException if {@link PacketWrapper#user()} returns null
* @throws RuntimeException if no path from the input version to the required client version exists
* @throws Exception if an error occurred while constructing the packet or sending it
*/
boolean scheduleSend(UserConnection connection, C packetType, Consumer<PacketWrapper> packetWriter) throws Exception;
boolean scheduleSend(PacketWrapper packet) throws Exception;
/**
* Sends a packet to the server, submitted to the netty event loop.
* Returns false if the packet has been cancelled at some point, but does not indicate whether a replacement has been constructed.
* Transforms a packet to the protocol version of the given connection or server, or null if cancelled at some point.
* The target version is given by {@link ProtocolInfo#getProtocolVersion()} or {@link ProtocolInfo#getServerProtocolVersion()}.
*
* @param connection user connection
* @param packetType serverbound packet type
* @param packetWriter consumer filling the packet with data
* @return whether this packet specifically has been sent, false if cancelled
* @throws IllegalArgumentException if the packet type is not of the expected serverbound packets class
* @throws RuntimeException if no path from the input version to the required server version exists
* @throws Exception if an error occurred while constructing the packet or sending it
*/
boolean scheduleSend(UserConnection connection, S packetType, Consumer<PacketWrapper> packetWriter) throws Exception;
/**
* Transforms a packet to the protocol version of the given connection, or null if cancelled at some point.
* The target version is given by {@link ProtocolInfo#getProtocolVersion()} with the connection as the receiver.
*
* @param connection user connection
* @param packetType clientbound packet type
* @param packetWriter consumer filling the packet with data
* @param packet packet wrapper
* @return created and transformed packet wrapper, or null if cancelled at some point
* @throws IllegalArgumentException if the packet type is not of the expected clientbound packets class
* @throws IllegalArgumentException if {@link PacketWrapper#user()} returns null
* @throws RuntimeException if no path from the input version to the required client version exists
* @throws Exception if an error occurred while constructing the packet
*/
@Nullable PacketWrapper transform(UserConnection connection, C packetType, Consumer<PacketWrapper> packetWriter) throws Exception;
/**
* Transforms a packet to the server protocol version the connection is on, or null if cancelled at some point.
* The target version is given by {@link ProtocolInfo#getServerProtocolVersion()} with the connection as the sender.
*
* @param connection user connection
* @param packetType serverbound packet type
* @param packetWriter consumer filling the packet with data
* @return created and transformed packet wrapper, or null if cancelled at some point
* @throws IllegalArgumentException if the packet type is not of the expected serverbound packets class
* @throws RuntimeException if no path from the input version to the required server version exists
* @throws Exception if an error occurred while constructing the packet
*/
@Nullable PacketWrapper transform(UserConnection connection, S packetType, Consumer<PacketWrapper> packetWriter) throws Exception;
@Nullable PacketWrapper transform(PacketWrapper packet) throws Exception;
}

Datei anzeigen

@ -17,6 +17,7 @@
*/
package com.viaversion.viaversion.bukkit.listeners.protocol1_9to1_8;
import com.viaversion.viaversion.protocols.protocol1_9to1_8.ClientboundPackets1_9;
import org.bukkit.Bukkit;
import org.bukkit.entity.HumanEntity;
import org.bukkit.entity.Player;
@ -58,7 +59,7 @@ public class ArmorListener extends ViaBukkitListener {
armor += ArmorType.findById(stack.getTypeId()).getArmorPoints();
}
PacketWrapper wrapper = PacketWrapper.create(0x4B, null, getUserConnection(player));
PacketWrapper wrapper = PacketWrapper.create(ClientboundPackets1_9.ENTITY_PROPERTIES, null, getUserConnection(player));
try {
wrapper.write(Type.VAR_INT, player.getEntityId()); // Player ID
wrapper.write(Type.INT, 1); // only 1 property

Datei anzeigen

@ -17,6 +17,7 @@
*/
package com.viaversion.viaversion.bukkit.listeners.protocol1_9to1_8;
import com.viaversion.viaversion.protocols.protocol1_9to1_8.ClientboundPackets1_9;
import org.bukkit.World;
import org.bukkit.entity.Player;
import org.bukkit.event.EventHandler;
@ -58,7 +59,7 @@ public class DeathListener extends ViaBukkitListener {
// If online
UserConnection userConnection = getUserConnection(p);
if (userConnection != null) {
PacketWrapper wrapper = PacketWrapper.create(0x2C, null, userConnection);
PacketWrapper wrapper = PacketWrapper.create(ClientboundPackets1_9.COMBAT_EVENT, null, userConnection);
try {
wrapper.write(Type.VAR_INT, 2); // Event - Entity dead
wrapper.write(Type.VAR_INT, p.getEntityId()); // Player ID

Datei anzeigen

@ -24,6 +24,7 @@ import com.viaversion.viaversion.api.protocol.packet.PacketWrapper;
import com.viaversion.viaversion.api.type.Type;
import com.viaversion.viaversion.api.type.types.version.Types1_14;
import com.viaversion.viaversion.bukkit.listeners.ViaBukkitListener;
import com.viaversion.viaversion.protocols.protocol1_15to1_14_4.ClientboundPackets1_15;
import com.viaversion.viaversion.protocols.protocol1_15to1_14_4.Protocol1_15To1_14_4;
import org.bukkit.entity.Player;
import org.bukkit.event.EventHandler;
@ -55,7 +56,7 @@ public class EntityToggleGlideListener extends ViaBukkitListener {
// Cancelling can only be done by updating the player's metadata
if (event.isGliding() && event.isCancelled()) {
PacketWrapper packet = PacketWrapper.create(0x44, null, getUserConnection(player));
PacketWrapper packet = PacketWrapper.create(ClientboundPackets1_15.ENTITY_METADATA, null, getUserConnection(player));
try {
packet.write(Type.VAR_INT, player.getEntityId());

Datei anzeigen

@ -24,6 +24,7 @@ import com.viaversion.viaversion.api.minecraft.metadata.types.MetaType1_9;
import com.viaversion.viaversion.api.protocol.packet.PacketWrapper;
import com.viaversion.viaversion.api.type.Type;
import com.viaversion.viaversion.api.type.types.version.Types1_9;
import com.viaversion.viaversion.protocols.protocol1_9to1_8.ClientboundPackets1_9;
import com.viaversion.viaversion.protocols.protocol1_9to1_8.Protocol1_9To1_8;
import com.viaversion.viaversion.protocols.protocol1_9to1_8.storage.EntityTracker1_9;
import net.md_5.bungee.api.event.ServerConnectedEvent;
@ -48,7 +49,7 @@ public class ElytraPatch implements Listener {
EntityTracker1_9 tracker = user.getEntityTracker(Protocol1_9To1_8.class);
int entityId = tracker.getProvidedEntityId();
PacketWrapper wrapper = PacketWrapper.create(0x39, null, user);
PacketWrapper wrapper = PacketWrapper.create(ClientboundPackets1_9.ENTITY_METADATA, null, user);
wrapper.write(Type.VAR_INT, entityId);
wrapper.write(Types1_9.METADATA_LIST, Collections.singletonList(new Metadata(0, MetaType1_9.Byte, (byte) 0)));

Datei anzeigen

@ -21,6 +21,7 @@ import com.viaversion.viaversion.api.connection.UserConnection;
import com.viaversion.viaversion.api.protocol.packet.PacketWrapper;
import com.viaversion.viaversion.api.protocol.packet.State;
import com.viaversion.viaversion.api.type.Type;
import com.viaversion.viaversion.protocols.protocol1_8.ServerboundPackets1_8;
import com.viaversion.viaversion.protocols.protocol1_9to1_8.Protocol1_9To1_8;
import com.viaversion.viaversion.protocols.protocol1_9to1_8.providers.MovementTransmitterProvider;
import com.viaversion.viaversion.protocols.protocol1_9to1_8.storage.MovementTracker;
@ -38,7 +39,7 @@ public class BungeeMovementTransmitter extends MovementTransmitterProvider {
public void sendPlayer(UserConnection userConnection) {
if (userConnection.getProtocolInfo().getState() == State.PLAY) {
PacketWrapper wrapper = PacketWrapper.create(0x03, null, userConnection);
PacketWrapper wrapper = PacketWrapper.create(ServerboundPackets1_8.PLAYER_MOVEMENT, null, userConnection);
MovementTracker tracker = userConnection.get(MovementTracker.class);
wrapper.write(Type.BOOLEAN, tracker.isGround());
try {

Datei anzeigen

@ -29,6 +29,7 @@ import com.viaversion.viaversion.api.protocol.packet.PacketTracker;
import com.viaversion.viaversion.api.protocol.packet.PacketWrapper;
import com.viaversion.viaversion.api.type.Type;
import com.viaversion.viaversion.exception.CancelException;
import com.viaversion.viaversion.protocol.packet.PacketWrapperImpl;
import com.viaversion.viaversion.util.ChatColorUtil;
import com.viaversion.viaversion.util.PipelineUtil;
import io.netty.buffer.ByteBuf;
@ -290,7 +291,7 @@ public class UserConnectionImpl implements UserConnection {
return;
}
PacketWrapper wrapper = PacketWrapper.create(id, buf, this);
PacketWrapper wrapper = new PacketWrapperImpl(id, buf, this);
try {
protocolInfo.getPipeline().transform(direction, protocolInfo.getState(), wrapper);
} catch (CancelException ex) {

Datei anzeigen

@ -29,6 +29,7 @@ import com.viaversion.viaversion.api.protocol.ProtocolManager;
import com.viaversion.viaversion.api.protocol.ProtocolPathEntry;
import com.viaversion.viaversion.api.protocol.ProtocolPathKey;
import com.viaversion.viaversion.api.protocol.packet.ClientboundPacketType;
import com.viaversion.viaversion.api.protocol.packet.PacketType;
import com.viaversion.viaversion.api.protocol.packet.PacketWrapper;
import com.viaversion.viaversion.api.protocol.packet.ServerboundPacketType;
import com.viaversion.viaversion.api.protocol.packet.VersionedPacketCreator;
@ -266,11 +267,11 @@ public class ProtocolManagerImpl implements ProtocolManager {
}
@Override
public <C extends ClientboundPacketType,
S extends ServerboundPacketType
> VersionedPacketCreator<C, S> createVersionedPacketCreator(ProtocolVersion inputVersion, Class<C> clientboundPacketsClass, Class<S> serverboundPacketsClass) {
public VersionedPacketCreator createVersionedPacketCreator(ProtocolVersion inputVersion,
Class<? extends ClientboundPacketType> clientboundPacketsClass,
Class<? extends ServerboundPacketType> serverboundPacketsClass) {
Preconditions.checkArgument(clientboundPacketsClass != ClientboundPacketType.class && serverboundPacketsClass != ServerboundPacketType.class);
return new VersionedPacketCreatorImpl<>(inputVersion, clientboundPacketsClass, serverboundPacketsClass);
return new VersionedPacketCreatorImpl(inputVersion, clientboundPacketsClass, serverboundPacketsClass);
}
/**
@ -464,6 +465,12 @@ public class ProtocolManagerImpl implements ProtocolManager {
}
@Override
public PacketWrapper createPacketWrapper(@Nullable PacketType packetType, @Nullable ByteBuf buf, UserConnection connection) {
return new PacketWrapperImpl(packetType, buf, connection);
}
@Override
@Deprecated
public PacketWrapper createPacketWrapper(int packetId, @Nullable ByteBuf buf, UserConnection connection) {
return new PacketWrapperImpl(packetId, buf, connection);
}

Datei anzeigen

@ -22,6 +22,7 @@ import com.viaversion.viaversion.api.Via;
import com.viaversion.viaversion.api.connection.UserConnection;
import com.viaversion.viaversion.api.protocol.Protocol;
import com.viaversion.viaversion.api.protocol.packet.Direction;
import com.viaversion.viaversion.api.protocol.packet.PacketType;
import com.viaversion.viaversion.api.protocol.packet.PacketWrapper;
import com.viaversion.viaversion.api.protocol.packet.State;
import com.viaversion.viaversion.api.protocol.remapper.PacketHandler;
@ -48,7 +49,9 @@ public class PacketWrapperImpl implements PacketWrapper {
private final ByteBuf inputBuffer;
private final UserConnection userConnection;
private boolean send = true;
private int id = -1;
/** Only non-null if specifically set and gotten before packet transformation */
private PacketType packetType;
private int id;
private final Deque<Pair<Type, Object>> readableObjects = new ArrayDeque<>();
private final List<Pair<Type, Object>> packetValues = new ArrayList<>();
@ -58,6 +61,13 @@ public class PacketWrapperImpl implements PacketWrapper {
this.userConnection = userConnection;
}
public PacketWrapperImpl(@Nullable PacketType packetType, @Nullable ByteBuf inputBuffer, UserConnection userConnection) {
this.packetType = packetType;
this.id = packetType != null ? packetType.getId() : -1;
this.inputBuffer = inputBuffer;
this.userConnection = userConnection;
}
@Override
public <T> T get(Type<T> type, int index) throws Exception {
int currentIndex = 0;
@ -70,7 +80,7 @@ public class PacketWrapperImpl implements PacketWrapper {
}
Exception e = new ArrayIndexOutOfBoundsException("Could not find type " + type.getTypeName() + " at " + index);
throw new InformativeException(e).set("Type", type.getTypeName()).set("Index", index).set("Packet ID", getId()).set("Data", packetValues);
throw new InformativeException(e).set("Type", type.getTypeName()).set("Index", index).set("Packet ID", getId()).set("Packet Type", packetType).set("Data", packetValues);
}
@Override
@ -112,7 +122,7 @@ public class PacketWrapperImpl implements PacketWrapper {
currentIndex++;
}
Exception e = new ArrayIndexOutOfBoundsException("Could not find type " + type.getTypeName() + " at " + index);
throw new InformativeException(e).set("Type", type.getTypeName()).set("Index", index).set("Packet ID", getId());
throw new InformativeException(e).set("Type", type.getTypeName()).set("Index", index).set("Packet ID", getId()).set("Packet Type", packetType);
}
@Override
@ -124,7 +134,7 @@ public class PacketWrapperImpl implements PacketWrapper {
try {
return type.read(inputBuffer);
} catch (Exception e) {
throw new InformativeException(e).set("Type", type.getTypeName()).set("Packet ID", getId()).set("Data", packetValues);
throw new InformativeException(e).set("Type", type.getTypeName()).set("Packet ID", getId()).set("Packet Type", packetType).set("Data", packetValues);
}
}
@ -138,7 +148,7 @@ public class PacketWrapperImpl implements PacketWrapper {
return read(type); // retry
} else {
Exception e = new IOException("Unable to read type " + type.getTypeName() + ", found " + read.getKey().getTypeName());
throw new InformativeException(e).set("Type", type.getTypeName()).set("Packet ID", getId()).set("Data", packetValues);
throw new InformativeException(e).set("Type", type.getTypeName()).set("Packet ID", getId()).set("Packet Type", packetType).set("Data", packetValues);
}
}
@ -199,7 +209,7 @@ public class PacketWrapperImpl implements PacketWrapper {
try {
packetValue.getKey().write(buffer, packetValue.getValue());
} catch (Exception e) {
throw new InformativeException(e).set("Index", index).set("Type", packetValue.getKey().getTypeName()).set("Packet ID", getId()).set("Data", packetValues);
throw new InformativeException(e).set("Index", index).set("Type", packetValue.getKey().getTypeName()).set("Packet ID", getId()).set("Packet Type", packetType).set("Data", packetValues);
}
index++;
}
@ -447,13 +457,27 @@ public class PacketWrapperImpl implements PacketWrapper {
}
}
@Override
public @Nullable PacketType getPacketType() {
return packetType;
}
@Override
public void setPacketType(PacketType packetType) {
this.packetType = packetType;
this.id = packetType != null ? packetType.getId() : -1;
}
@Override
public int getId() {
return id;
}
@Override
@Deprecated
public void setId(int id) {
// Loses packet type info
this.packetType = null;
this.id = id;
}
@ -467,6 +491,7 @@ public class PacketWrapperImpl implements PacketWrapper {
"packetValues=" + packetValues +
", readableObjects=" + readableObjects +
", id=" + id +
", packetType" + packetType +
'}';
}
}

Datei anzeigen

@ -34,15 +34,15 @@ import org.checkerframework.checker.nullness.qual.Nullable;
import java.util.ArrayList;
import java.util.List;
import java.util.function.Consumer;
public class VersionedPacketCreatorImpl<C extends ClientboundPacketType, S extends ServerboundPacketType> implements VersionedPacketCreator<C, S> {
public class VersionedPacketCreatorImpl implements VersionedPacketCreator {
private final int inputProtocolVersion;
private final Class<C> clientboundPacketsClass;
private final Class<S> serverboundPacketsClass;
private final Class<? extends ClientboundPacketType> clientboundPacketsClass;
private final Class<? extends ServerboundPacketType> serverboundPacketsClass;
public VersionedPacketCreatorImpl(ProtocolVersion inputVersion, Class<C> clientboundPacketsClass, Class<S> serverboundPacketsClass) {
public VersionedPacketCreatorImpl(ProtocolVersion inputVersion,
Class<? extends ClientboundPacketType> clientboundPacketsClass, Class<? extends ServerboundPacketType> serverboundPacketsClass) {
Preconditions.checkNotNull(inputVersion);
Preconditions.checkNotNull(clientboundPacketsClass);
Preconditions.checkNotNull(serverboundPacketsClass);
@ -52,57 +52,53 @@ public class VersionedPacketCreatorImpl<C extends ClientboundPacketType, S exten
}
@Override
public boolean send(UserConnection connection, C packetType, Consumer<PacketWrapper> packetWriter) throws Exception {
Preconditions.checkArgument(packetType.getClass() == clientboundPacketsClass);
return createAndSend(connection, packetType, packetWriter, true);
public boolean send(PacketWrapper packet) throws Exception {
validatePacket(packet);
return transformAndSendPacket(packet, true);
}
@Override
public boolean send(UserConnection connection, S packetType, Consumer<PacketWrapper> packetWriter) throws Exception {
Preconditions.checkArgument(packetType.getClass() == serverboundPacketsClass);
return createAndSend(connection, packetType, packetWriter, true);
public boolean scheduleSend(PacketWrapper packet) throws Exception {
validatePacket(packet);
return transformAndSendPacket(packet, false);
}
@Override
public boolean scheduleSend(UserConnection connection, C packetType, Consumer<PacketWrapper> packetWriter) throws Exception {
Preconditions.checkArgument(packetType.getClass() == clientboundPacketsClass);
return createAndSend(connection, packetType, packetWriter, false);
}
@Override
public boolean scheduleSend(UserConnection connection, S packetType, Consumer<PacketWrapper> packetWriter) throws Exception {
Preconditions.checkArgument(packetType.getClass() == serverboundPacketsClass);
return createAndSend(connection, packetType, packetWriter, false);
}
@Override
public @Nullable PacketWrapper transform(UserConnection connection, C packetType, Consumer<PacketWrapper> packetWriter) throws Exception {
Preconditions.checkArgument(packetType.getClass() == clientboundPacketsClass);
PacketWrapper packet = createAndTransform(connection, packetType, packetWriter);
public @Nullable PacketWrapper transform(PacketWrapper packet) throws Exception {
validatePacket(packet);
transformPacket(packet);
return packet.isCancelled() ? null : packet;
}
@Override
public @Nullable PacketWrapper transform(UserConnection connection, S packetType, Consumer<PacketWrapper> packetWriter) throws Exception {
Preconditions.checkArgument(packetType.getClass() == serverboundPacketsClass);
PacketWrapper packet = createAndTransform(connection, packetType, packetWriter);
return packet.isCancelled() ? null : packet;
private void validatePacket(PacketWrapper packet) {
if (packet.user() == null) {
throw new IllegalArgumentException("PacketWrapper does not have a targetted UserConnection");
}
if (packet.getPacketType() == null) {
throw new IllegalArgumentException("PacketWrapper does not have a valid packet type");
}
Class<? extends PacketType> expectedPacketClass =
packet.getPacketType().direction() == Direction.CLIENTBOUND ? clientboundPacketsClass : serverboundPacketsClass;
if (packet.getPacketType().getClass() != expectedPacketClass) {
throw new IllegalArgumentException("PacketWrapper packet type is of the wrong packet class");
}
}
private boolean createAndSend(UserConnection connection, PacketType packetType, Consumer<PacketWrapper> packetWriter, boolean currentThread) throws Exception {
PacketWrapper packet = createAndTransform(connection, packetType, packetWriter);
if (!packet.isCancelled()) {
private boolean transformAndSendPacket(PacketWrapper packet, boolean currentThread) throws Exception {
transformPacket(packet);
if (packet.isCancelled()) {
return false;
}
if (currentThread) {
if (packetType.direction() == Direction.CLIENTBOUND) {
if (packet.getPacketType().direction() == Direction.CLIENTBOUND) {
packet.sendRaw();
} else {
packet.sendToServerRaw();
}
} else {
if (packetType.direction() == Direction.CLIENTBOUND) {
if (packet.getPacketType().direction() == Direction.CLIENTBOUND) {
packet.scheduleSendRaw();
} else {
packet.scheduleSendToServerRaw();
@ -111,9 +107,11 @@ public class VersionedPacketCreatorImpl<C extends ClientboundPacketType, S exten
return true;
}
private PacketWrapper createAndTransform(UserConnection connection, PacketType packetType, Consumer<PacketWrapper> packetWriter) throws Exception {
private void transformPacket(PacketWrapper packet) throws Exception {
// If clientbound: Constructor given inputProtocolVersion Client version
// If serverbound: Constructor given inputProtocolVersion Server version
PacketType packetType = packet.getPacketType();
UserConnection connection = packet.user();
boolean clientbound = packetType.direction() == Direction.CLIENTBOUND;
int serverProtocolVersion = clientbound ? this.inputProtocolVersion : connection.getProtocolInfo().getServerProtocolVersion();
int clientProtocolVersion = clientbound ? connection.getProtocolInfo().getProtocolVersion() : this.inputProtocolVersion;
@ -130,8 +128,6 @@ public class VersionedPacketCreatorImpl<C extends ClientboundPacketType, S exten
throw new RuntimeException("No protocol path between client version " + clientProtocolVersion + " and server version " + serverProtocolVersion);
}
PacketWrapper packet = PacketWrapper.create(packetType, connection);
packetWriter.accept(packet);
if (protocolList != null) {
// Reset reader and apply pipeline
packet.resetReader();
@ -143,6 +139,5 @@ public class VersionedPacketCreatorImpl<C extends ClientboundPacketType, S exten
+ " and server version " + serverProtocolVersion + ". Are you sure you used the correct input version and packet write types?", e);
}
}
return packet;
}
}

Datei anzeigen

@ -19,9 +19,8 @@ package com.viaversion.viaversion.protocols.base;
import com.viaversion.viaversion.api.Via;
import com.viaversion.viaversion.api.connection.ProtocolInfo;
import com.viaversion.viaversion.api.connection.UserConnection;
import com.viaversion.viaversion.api.platform.providers.ViaProviders;
import com.viaversion.viaversion.api.protocol.AbstractSimpleProtocol;
import com.viaversion.viaversion.api.protocol.AbstractProtocol;
import com.viaversion.viaversion.api.protocol.Protocol;
import com.viaversion.viaversion.api.protocol.ProtocolPathEntry;
import com.viaversion.viaversion.api.protocol.ProtocolPipeline;
@ -36,14 +35,12 @@ import com.viaversion.viaversion.api.type.Type;
import java.util.ArrayList;
import java.util.List;
public class BaseProtocol extends AbstractSimpleProtocol {
public class BaseProtocol extends AbstractProtocol {
@Override
protected void registerPackets() {
/* Incoming Packets */
// Handshake Packet
registerServerbound(State.HANDSHAKE, 0x00, 0x00, new PacketRemapper() {
registerServerbound(ServerboundHandshakePackets.CLIENT_INTENTION, new PacketRemapper() {
@Override
public void registerMap() {
handler(wrapper -> {
@ -108,11 +105,6 @@ public class BaseProtocol extends AbstractSimpleProtocol {
return true;
}
@Override
public void init(UserConnection userConnection) {
// Nothing gets added, ProtocolPipeline handles ProtocolInfo
}
@Override
public void register(ViaProviders providers) {
providers.register(VersionProvider.class, new BaseVersionProvider());

Datei anzeigen

@ -23,7 +23,7 @@ import com.google.gson.JsonObject;
import com.google.gson.JsonParseException;
import com.viaversion.viaversion.api.Via;
import com.viaversion.viaversion.api.connection.ProtocolInfo;
import com.viaversion.viaversion.api.protocol.AbstractSimpleProtocol;
import com.viaversion.viaversion.api.protocol.AbstractProtocol;
import com.viaversion.viaversion.api.protocol.ProtocolPathEntry;
import com.viaversion.viaversion.api.protocol.packet.PacketWrapper;
import com.viaversion.viaversion.api.protocol.packet.State;
@ -43,14 +43,14 @@ import java.util.List;
import java.util.UUID;
import java.util.logging.Level;
public class BaseProtocol1_7 extends AbstractSimpleProtocol {
public class BaseProtocol1_7 extends AbstractProtocol {
@Override
protected void registerPackets() {
/* Outgoing Packets */
// Status Response Packet
registerClientbound(State.STATUS, 0x00, 0x00, new PacketRemapper() { // Status Response Packet
registerClientbound(ClientboundStatusPackets.STATUS_RESPONSE, new PacketRemapper() { // Status Response Packet
@Override
public void registerMap() {
map(Type.STRING);
@ -124,13 +124,8 @@ public class BaseProtocol1_7 extends AbstractSimpleProtocol {
}
});
registerClientbound(State.STATUS, 0x01, 0x01); // Status Pong Packet
registerClientbound(State.LOGIN, 0x00, 0x00); // Login Disconnect Packet
registerClientbound(State.LOGIN, 0x01, 0x01); // Encryption Request Packet
// Login Success Packet
registerClientbound(State.LOGIN, 0x02, 0x02, new PacketRemapper() {
registerClientbound(ClientboundLoginPackets.GAME_PROFILE, new PacketRemapper() {
@Override
public void registerMap() {
handler(new PacketHandler() {
@ -165,16 +160,9 @@ public class BaseProtocol1_7 extends AbstractSimpleProtocol {
}
});
registerClientbound(State.LOGIN, 0x03, 0x03); // Login Set Compression Packet
registerServerbound(State.LOGIN, 0x04, 0x04); // Plugin Request (1.13)
/* Incoming Packets */
registerServerbound(State.STATUS, 0x00, 0x00); // Status Request Packet
registerServerbound(State.STATUS, 0x01, 0x01); // Status Ping Packet
// Login Start Packet
registerServerbound(State.LOGIN, 0x00, 0x00, new PacketRemapper() {
registerServerbound(ServerboundLoginPackets.HELLO, new PacketRemapper() {
@Override
public void registerMap() {
handler(new PacketHandler() {
@ -185,7 +173,7 @@ public class BaseProtocol1_7 extends AbstractSimpleProtocol {
if (!wrapper.user().getChannel().isOpen()) return;
if (!wrapper.user().shouldApplyBlockProtocol()) return;
PacketWrapper disconnectPacket = PacketWrapper.create(0x00, null, wrapper.user()); // Disconnect Packet
PacketWrapper disconnectPacket = PacketWrapper.create(ClientboundLoginPackets.LOGIN_DISCONNECT, wrapper.user()); // Disconnect Packet
Protocol1_9To1_8.FIX_JSON.write(disconnectPacket, ChatColorUtil.translateAlternateColorCodes(Via.getConfig().getBlockedDisconnectMsg()));
wrapper.cancel(); // cancel current
@ -196,9 +184,7 @@ public class BaseProtocol1_7 extends AbstractSimpleProtocol {
}
});
}
}); // Login Start Packet
registerServerbound(State.LOGIN, 0x01, 0x01); // Encryption Response Packet
registerServerbound(State.LOGIN, 0x02, 0x02); // Plugin Response (1.13)
});
}
@Override

Datei anzeigen

@ -0,0 +1,44 @@
/*
* This file is part of ViaVersion - https://github.com/ViaVersion/ViaVersion
* Copyright (C) 2016-2021 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.protocols.base;
import com.viaversion.viaversion.api.protocol.packet.ClientboundPacketType;
import com.viaversion.viaversion.api.protocol.packet.State;
public enum ClientboundLoginPackets implements ClientboundPacketType {
LOGIN_DISCONNECT, // 0x00
HELLO, // 0x01
GAME_PROFILE, // 0x02
LOGIN_COMPRESSION, // 0x03
CUSTOM_QUERY; // 0x04
@Override
public final int getId() {
return ordinal();
}
@Override
public final String getName() {
return name();
}
@Override
public final State state() {
return State.LOGIN;
}
}

Datei anzeigen

@ -0,0 +1,41 @@
/*
* This file is part of ViaVersion - https://github.com/ViaVersion/ViaVersion
* Copyright (C) 2016-2021 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.protocols.base;
import com.viaversion.viaversion.api.protocol.packet.ClientboundPacketType;
import com.viaversion.viaversion.api.protocol.packet.State;
public enum ClientboundStatusPackets implements ClientboundPacketType {
STATUS_RESPONSE, // 0x00
PONG_RESPONSE; // 0x01
@Override
public final int getId() {
return ordinal();
}
@Override
public final String getName() {
return name();
}
@Override
public final State state() {
return State.STATUS;
}
}

Datei anzeigen

@ -0,0 +1,40 @@
/*
* This file is part of ViaVersion - https://github.com/ViaVersion/ViaVersion
* Copyright (C) 2016-2021 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.protocols.base;
import com.viaversion.viaversion.api.protocol.packet.ServerboundPacketType;
import com.viaversion.viaversion.api.protocol.packet.State;
public enum ServerboundHandshakePackets implements ServerboundPacketType {
CLIENT_INTENTION; // 0x00
@Override
public final int getId() {
return ordinal();
}
@Override
public final String getName() {
return name();
}
@Override
public final State state() {
return State.HANDSHAKE;
}
}

Datei anzeigen

@ -0,0 +1,42 @@
/*
* This file is part of ViaVersion - https://github.com/ViaVersion/ViaVersion
* Copyright (C) 2016-2021 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.protocols.base;
import com.viaversion.viaversion.api.protocol.packet.ServerboundPacketType;
import com.viaversion.viaversion.api.protocol.packet.State;
public enum ServerboundLoginPackets implements ServerboundPacketType {
HELLO, // 0x00
ENCRYPTION_KEY, // 0x01
CUSTOM_QUERY; // 0x02
@Override
public final int getId() {
return ordinal();
}
@Override
public final String getName() {
return name();
}
@Override
public final State state() {
return State.LOGIN;
}
}

Datei anzeigen

@ -0,0 +1,41 @@
/*
* This file is part of ViaVersion - https://github.com/ViaVersion/ViaVersion
* Copyright (C) 2016-2021 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.protocols.base;
import com.viaversion.viaversion.api.protocol.packet.ServerboundPacketType;
import com.viaversion.viaversion.api.protocol.packet.State;
public enum ServerboundStatusPackets implements ServerboundPacketType {
STATUS_REQUEST, // 0x00
PING_REQUEST; // 0x01
@Override
public final int getId() {
return ordinal();
}
@Override
public final String getName() {
return name();
}
@Override
public final State state() {
return State.STATUS;
}
}

Datei anzeigen

@ -66,7 +66,7 @@ public class Protocol1_10To1_9_3_4 extends AbstractProtocol<ClientboundPackets1_
itemRewriter.register();
// Named sound effect
registerClientbound(State.PLAY, 0x19, 0x19, new PacketRemapper() {
registerClientbound(ClientboundPackets1_9_3.NAMED_SOUND, new PacketRemapper() {
@Override
public void registerMap() {
map(Type.STRING); // 0 - Sound name
@ -80,7 +80,7 @@ public class Protocol1_10To1_9_3_4 extends AbstractProtocol<ClientboundPackets1_
});
// Sound effect
registerClientbound(State.PLAY, 0x46, 0x46, new PacketRemapper() {
registerClientbound(ClientboundPackets1_9_3.SOUND, new PacketRemapper() {
@Override
public void registerMap() {
map(Type.VAR_INT); // 0 - Sound name
@ -102,7 +102,7 @@ public class Protocol1_10To1_9_3_4 extends AbstractProtocol<ClientboundPackets1_
});
// Metadata packet
registerClientbound(State.PLAY, 0x39, 0x39, new PacketRemapper() {
registerClientbound(ClientboundPackets1_9_3.ENTITY_METADATA, new PacketRemapper() {
@Override
public void registerMap() {
map(Type.VAR_INT); // 0 - Entity ID
@ -111,7 +111,7 @@ public class Protocol1_10To1_9_3_4 extends AbstractProtocol<ClientboundPackets1_
});
// Spawn Mob
registerClientbound(State.PLAY, 0x03, 0x03, new PacketRemapper() {
registerClientbound(ClientboundPackets1_9_3.SPAWN_MOB, new PacketRemapper() {
@Override
public void registerMap() {
map(Type.VAR_INT); // 0 - Entity id
@ -131,7 +131,7 @@ public class Protocol1_10To1_9_3_4 extends AbstractProtocol<ClientboundPackets1_
});
// Spawn Player
registerClientbound(State.PLAY, 0x05, 0x05, new PacketRemapper() {
registerClientbound(ClientboundPackets1_9_3.SPAWN_PLAYER, new PacketRemapper() {
@Override
public void registerMap() {
map(Type.VAR_INT); // 0 - Entity ID
@ -146,7 +146,7 @@ public class Protocol1_10To1_9_3_4 extends AbstractProtocol<ClientboundPackets1_
});
// Packet Send ResourcePack
registerClientbound(State.PLAY, 0x32, 0x32, new PacketRemapper() {
registerClientbound(ClientboundPackets1_9_3.RESOURCE_PACK, new PacketRemapper() {
@Override
public void registerMap() {
map(Type.STRING); // 0 - URL
@ -163,7 +163,7 @@ public class Protocol1_10To1_9_3_4 extends AbstractProtocol<ClientboundPackets1_
});
// Packet ResourcePack status
registerServerbound(State.PLAY, 0x16, 0x16, new PacketRemapper() {
registerServerbound(ServerboundPackets1_9_3.RESOURCE_PACK_STATUS, new PacketRemapper() {
@Override
public void registerMap() {
handler(new PacketHandler() {

Datei anzeigen

@ -30,6 +30,7 @@ import com.viaversion.viaversion.api.type.Type;
import com.viaversion.viaversion.protocols.protocol1_11to1_10.EntityIdRewriter;
import com.viaversion.viaversion.protocols.protocol1_11to1_10.Protocol1_11To1_10;
import com.viaversion.viaversion.protocols.protocol1_11to1_10.storage.EntityTracker1_11;
import com.viaversion.viaversion.protocols.protocol1_9_3to1_9_1_2.ClientboundPackets1_9_3;
import com.viaversion.viaversion.rewriter.EntityRewriter;
import java.util.List;
@ -129,7 +130,7 @@ public class MetadataRewriter1_11To1_10 extends EntityRewriter<Protocol1_11To1_1
tracker.addHologram(entityId);
try {
// Send movement
PacketWrapper wrapper = PacketWrapper.create(0x25, null, connection);
PacketWrapper wrapper = PacketWrapper.create(ClientboundPackets1_9_3.ENTITY_POSITION, null, connection);
wrapper.write(Type.VAR_INT, entityId);
wrapper.write(Type.SHORT, (short) 0);
wrapper.write(Type.SHORT, (short) (128D * (-Via.getConfig().getHologramYOffset() * 32D)));

Datei anzeigen

@ -30,6 +30,7 @@ import com.viaversion.viaversion.api.minecraft.chunks.Chunk;
import com.viaversion.viaversion.api.minecraft.chunks.ChunkSection;
import com.viaversion.viaversion.api.protocol.packet.PacketWrapper;
import com.viaversion.viaversion.api.type.Type;
import com.viaversion.viaversion.protocols.protocol1_13to1_12_2.ClientboundPackets1_13;
import com.viaversion.viaversion.protocols.protocol1_13to1_12_2.Protocol1_13To1_12_2;
import com.viaversion.viaversion.protocols.protocol1_13to1_12_2.blockconnections.providers.BlockConnectionProvider;
import com.viaversion.viaversion.protocols.protocol1_13to1_12_2.blockconnections.providers.PacketBlockConnectionProvider;
@ -62,7 +63,7 @@ public class ConnectionData {
if (handler == null) continue;
int newBlockState = handler.connect(user, pos, blockState);
PacketWrapper blockUpdatePacket = PacketWrapper.create(0x0B, null, user);
PacketWrapper blockUpdatePacket = PacketWrapper.create(ClientboundPackets1_13.BLOCK_CHANGE, null, user);
blockUpdatePacket.write(Type.POSITION, pos);
blockUpdatePacket.write(Type.VAR_INT, newBlockState);
try {
@ -135,7 +136,7 @@ public class ConnectionData {
}
if (!updates.isEmpty()) {
PacketWrapper wrapper = PacketWrapper.create(0x0F, null, user);
PacketWrapper wrapper = PacketWrapper.create(ClientboundPackets1_13.MULTI_BLOCK_CHANGE, null, user);
wrapper.write(Type.INT, chunkX + chunkDeltaX);
wrapper.write(Type.INT, chunkZ + chunkDeltaZ);
wrapper.write(Type.BLOCK_CHANGE_RECORD_ARRAY, updates.toArray(EMPTY_RECORDS));

Datei anzeigen

@ -25,6 +25,7 @@ import com.viaversion.viaversion.api.minecraft.Position;
import com.viaversion.viaversion.api.platform.providers.Provider;
import com.viaversion.viaversion.api.protocol.packet.PacketWrapper;
import com.viaversion.viaversion.api.type.Type;
import com.viaversion.viaversion.protocols.protocol1_13to1_12_2.ClientboundPackets1_13;
import com.viaversion.viaversion.protocols.protocol1_13to1_12_2.Protocol1_13To1_12_2;
import com.viaversion.viaversion.protocols.protocol1_13to1_12_2.providers.blockentities.BannerHandler;
import com.viaversion.viaversion.protocols.protocol1_13to1_12_2.providers.blockentities.BedHandler;
@ -81,7 +82,7 @@ public class BlockEntityProvider implements Provider {
}
private void sendBlockChange(UserConnection user, Position position, int blockId) throws Exception {
PacketWrapper wrapper = PacketWrapper.create(0x0B, null, user);
PacketWrapper wrapper = PacketWrapper.create(ClientboundPackets1_13.BLOCK_CHANGE, null, user);
wrapper.write(Type.POSITION, position);
wrapper.write(Type.VAR_INT, blockId);

Datei anzeigen

@ -21,6 +21,7 @@ import com.viaversion.viaversion.api.connection.StorableObject;
import com.viaversion.viaversion.api.connection.UserConnection;
import com.viaversion.viaversion.api.protocol.packet.PacketWrapper;
import com.viaversion.viaversion.api.type.Type;
import com.viaversion.viaversion.protocols.protocol1_12_1to1_12.ServerboundPackets1_12_1;
import com.viaversion.viaversion.protocols.protocol1_13to1_12_2.Protocol1_13To1_12_2;
public class TabCompleteTracker implements StorableObject {
@ -31,7 +32,7 @@ public class TabCompleteTracker implements StorableObject {
public void sendPacketToServer(UserConnection connection) {
if (lastTabComplete == null || timeToSend > System.currentTimeMillis()) return;
PacketWrapper wrapper = PacketWrapper.create(0x01, null, connection);
PacketWrapper wrapper = PacketWrapper.create(ServerboundPackets1_12_1.TAB_COMPLETE, null, connection);
wrapper.write(Type.STRING, lastTabComplete);
wrapper.write(Type.BOOLEAN, false);
wrapper.write(Type.OPTIONAL_POSITION, null);

Datei anzeigen

@ -30,6 +30,7 @@ import com.viaversion.viaversion.api.minecraft.metadata.types.MetaType1_14;
import com.viaversion.viaversion.api.protocol.packet.PacketWrapper;
import com.viaversion.viaversion.api.type.Type;
import com.viaversion.viaversion.api.type.types.Particle;
import com.viaversion.viaversion.protocols.protocol1_14to1_13_2.ClientboundPackets1_14;
import com.viaversion.viaversion.protocols.protocol1_14to1_13_2.Protocol1_14To1_13_2;
import com.viaversion.viaversion.protocols.protocol1_14to1_13_2.storage.EntityTracker1_14;
import com.viaversion.viaversion.rewriter.EntityRewriter;
@ -130,7 +131,7 @@ public class MetadataRewriter1_14To1_13_2 extends EntityRewriter<Protocol1_14To1
armorItem = new DataItem(protocol.getMappingData().getNewItemId(729), (byte) 1, (short) 0, null);
}
PacketWrapper equipmentPacket = PacketWrapper.create(0x46, null, connection);
PacketWrapper equipmentPacket = PacketWrapper.create(ClientboundPackets1_14.ENTITY_EQUIPMENT, null, connection);
equipmentPacket.write(Type.VAR_INT, entityId);
equipmentPacket.write(Type.VAR_INT, 4);
equipmentPacket.write(Type.FLAT_VAR_INT_ITEM, armorItem);

Datei anzeigen

@ -25,6 +25,7 @@ import com.viaversion.viaversion.api.minecraft.Position;
import com.viaversion.viaversion.api.protocol.packet.PacketWrapper;
import com.viaversion.viaversion.api.type.Type;
import com.viaversion.viaversion.protocols.protocol1_9_1_2to1_9_3_4.Protocol1_9_1_2To1_9_3_4;
import com.viaversion.viaversion.protocols.protocol1_9_3to1_9_1_2.ClientboundPackets1_9_3;
import java.util.HashMap;
import java.util.List;
@ -75,7 +76,7 @@ public class BlockEntity {
}
private static void updateBlockEntity(Position pos, short id, CompoundTag tag, UserConnection connection) throws Exception {
PacketWrapper wrapper = PacketWrapper.create(0x09, null, connection);
PacketWrapper wrapper = PacketWrapper.create(ClientboundPackets1_9_3.BLOCK_ENTITY_DATA, null, connection);
wrapper.write(Type.POSITION, pos);
wrapper.write(Type.UNSIGNED_BYTE, id);
wrapper.write(Type.NBT, tag);

Datei anzeigen

@ -31,6 +31,7 @@ import com.viaversion.viaversion.api.type.Type;
import com.viaversion.viaversion.api.type.types.version.Types1_8;
import com.viaversion.viaversion.api.type.types.version.Types1_9;
import com.viaversion.viaversion.protocols.protocol1_8.ClientboundPackets1_8;
import com.viaversion.viaversion.protocols.protocol1_9to1_8.ClientboundPackets1_9;
import com.viaversion.viaversion.protocols.protocol1_9to1_8.ItemRewriter;
import com.viaversion.viaversion.protocols.protocol1_9to1_8.Protocol1_9To1_8;
import com.viaversion.viaversion.protocols.protocol1_9to1_8.metadata.MetadataRewriter1_9To1_8;
@ -306,7 +307,7 @@ public class SpawnPackets {
public void handle(PacketWrapper wrapper) throws Exception {
short item = wrapper.read(Type.SHORT);
if (item != 0) {
PacketWrapper packet = PacketWrapper.create(0x3C, null, wrapper.user());
PacketWrapper packet = PacketWrapper.create(ClientboundPackets1_9.ENTITY_EQUIPMENT, null, wrapper.user());
packet.write(Type.VAR_INT, wrapper.get(Type.VAR_INT, 0));
packet.write(Type.VAR_INT, 0);
packet.write(Type.ITEM, new DataItem(item, (byte) 1, (short) 0, null));

Datei anzeigen

@ -136,7 +136,7 @@ public class WorldPackets {
Chunk1_9to1_8Type type = new Chunk1_9to1_8Type(clientChunks);
Chunk1_8 chunk = (Chunk1_8) wrapper.read(type);
if (chunk.isUnloadPacket()) {
wrapper.setId(ClientboundPackets1_9.UNLOAD_CHUNK);
wrapper.setPacketType(ClientboundPackets1_9.UNLOAD_CHUNK);
wrapper.write(Type.INT, chunk.getX());
wrapper.write(Type.INT, chunk.getZ());
@ -427,7 +427,7 @@ public class WorldPackets {
Optional<CompoundTag> tag = provider.get(wrapper.user(), pos);
// Send the Update Block Entity packet if present
if (tag.isPresent()) {
PacketWrapper updateBlockEntity = PacketWrapper.create(0x09, null, wrapper.user());
PacketWrapper updateBlockEntity = PacketWrapper.create(ClientboundPackets1_9.BLOCK_ENTITY_DATA, null, wrapper.user());
updateBlockEntity.write(Type.POSITION, pos);
updateBlockEntity.write(Type.UNSIGNED_BYTE, (short) 2);

Datei anzeigen

@ -23,6 +23,7 @@ import com.viaversion.viaversion.api.minecraft.Position;
import com.viaversion.viaversion.api.platform.providers.Provider;
import com.viaversion.viaversion.api.protocol.packet.PacketWrapper;
import com.viaversion.viaversion.api.type.Type;
import com.viaversion.viaversion.protocols.protocol1_9to1_8.ClientboundPackets1_9;
import com.viaversion.viaversion.protocols.protocol1_9to1_8.Protocol1_9To1_8;
import com.viaversion.viaversion.protocols.protocol1_9to1_8.storage.CommandBlockStorage;
import com.viaversion.viaversion.protocols.protocol1_9to1_8.storage.EntityTracker1_9;
@ -57,7 +58,7 @@ public class CommandBlockProvider implements Provider {
public void sendPermission(UserConnection user) throws Exception {
if (!isEnabled())
return;
PacketWrapper wrapper = PacketWrapper.create(0x1B, null, user); // Entity status
PacketWrapper wrapper = PacketWrapper.create(ClientboundPackets1_9.ENTITY_STATUS, null, user); // Entity status
EntityTracker1_9 tracker = user.getEntityTracker(Protocol1_9To1_8.class);
wrapper.write(Type.INT, tracker.getProvidedEntityId()); // Entity ID

Datei anzeigen

@ -34,6 +34,7 @@ import com.viaversion.viaversion.api.protocol.packet.PacketWrapper;
import com.viaversion.viaversion.api.type.Type;
import com.viaversion.viaversion.api.type.types.version.Types1_9;
import com.viaversion.viaversion.data.entity.EntityTrackerBase;
import com.viaversion.viaversion.protocols.protocol1_9to1_8.ClientboundPackets1_9;
import com.viaversion.viaversion.protocols.protocol1_9to1_8.Protocol1_9To1_8;
import com.viaversion.viaversion.protocols.protocol1_9to1_8.chat.GameMode;
import com.viaversion.viaversion.protocols.protocol1_9to1_8.metadata.MetadataRewriter1_9To1_8;
@ -89,7 +90,7 @@ public class EntityTracker1_9 extends EntityTrackerBase {
}
public void setSecondHand(int entityID, Item item) {
PacketWrapper wrapper = PacketWrapper.create(0x3C, null, user());
PacketWrapper wrapper = PacketWrapper.create(ClientboundPackets1_9.ENTITY_EQUIPMENT, null, user());
wrapper.write(Type.VAR_INT, entityID);
wrapper.write(Type.VAR_INT, 1); // slot
wrapper.write(Type.ITEM, this.itemInSecondHand = item);
@ -234,7 +235,7 @@ public class EntityTracker1_9 extends EntityTrackerBase {
knownHolograms.add(entityId);
try {
// Send movement
PacketWrapper wrapper = PacketWrapper.create(0x25, null, user());
PacketWrapper wrapper = PacketWrapper.create(ClientboundPackets1_9.ENTITY_POSITION, null, user());
wrapper.write(Type.VAR_INT, entityId);
wrapper.write(Type.SHORT, (short) 0);
wrapper.write(Type.SHORT, (short) (128D * (Via.getConfig().getHologramYOffset() * 32D)));
@ -296,7 +297,7 @@ public class EntityTracker1_9 extends EntityTrackerBase {
}
public void sendTeamPacket(boolean add, boolean now) {
PacketWrapper wrapper = PacketWrapper.create(0x41, null, user());
PacketWrapper wrapper = PacketWrapper.create(ClientboundPackets1_9.TEAMS, null, user());
wrapper.write(Type.STRING, "viaversion"); // Use viaversion as name
if (add) {
// add
@ -340,7 +341,7 @@ public class EntityTracker1_9 extends EntityTrackerBase {
public void sendMetadataBuffer(int entityId) {
List<Metadata> metadataList = metadataBuffer.get(entityId);
if (metadataList != null) {
PacketWrapper wrapper = PacketWrapper.create(0x39, null, user());
PacketWrapper wrapper = PacketWrapper.create(ClientboundPackets1_9.ENTITY_METADATA, null, user());
wrapper.write(Type.VAR_INT, entityId);
wrapper.write(Types1_9.METADATA_LIST, metadataList);
Via.getManager().getProtocolManager().getProtocol(Protocol1_9To1_8.class).get(MetadataRewriter1_9To1_8.class)

Datei anzeigen

@ -34,7 +34,7 @@ import java.util.NoSuchElementException;
* @param <E> List Type
* @deprecated get rid of this at some point
*/
@Deprecated
@Deprecated/*(forRemoval = true)*/
public class ConcurrentList<E> extends ArrayList<E> {
private final Object lock = new Object();

Datei anzeigen

@ -25,7 +25,7 @@ import java.util.ListIterator;
/**
* @deprecated scary
*/
@Deprecated
@Deprecated/*(forRemoval = true)*/
public abstract class ListWrapper implements List {
private final List list;

Datei anzeigen

@ -17,6 +17,7 @@
*/
package com.viaversion.viaversion.sponge.listeners.protocol1_9to1_8.sponge4;
import com.viaversion.viaversion.protocols.protocol1_9to1_8.ClientboundPackets1_9;
import org.spongepowered.api.Sponge;
import org.spongepowered.api.entity.living.player.Player;
import org.spongepowered.api.event.Listener;
@ -60,7 +61,7 @@ public class Sponge4ArmorListener extends ViaListener {
armor += calculate(player.getLeggings());
armor += calculate(player.getBoots());
PacketWrapper wrapper = PacketWrapper.create(0x4B, null, getUserConnection(player.getUniqueId()));
PacketWrapper wrapper = PacketWrapper.create(ClientboundPackets1_9.ENTITY_PROPERTIES, null, getUserConnection(player.getUniqueId()));
try {
wrapper.write(Type.VAR_INT, getEntityId(player)); // Player ID
wrapper.write(Type.INT, 1); // only 1 property

Datei anzeigen

@ -21,6 +21,7 @@ import com.viaversion.viaversion.SpongePlugin;
import com.viaversion.viaversion.api.Via;
import com.viaversion.viaversion.api.protocol.packet.PacketWrapper;
import com.viaversion.viaversion.api.type.Type;
import com.viaversion.viaversion.protocols.protocol1_9to1_8.ClientboundPackets1_9;
import com.viaversion.viaversion.protocols.protocol1_9to1_8.Protocol1_9To1_8;
import com.viaversion.viaversion.sponge.listeners.ViaSpongeListener;
import org.spongepowered.api.entity.living.player.Player;
@ -64,7 +65,7 @@ public class DeathListener extends ViaSpongeListener {
Via.getPlatform().runSync(new Runnable() {
@Override
public void run() {
PacketWrapper wrapper = PacketWrapper.create(0x2C, null, getUserConnection(p.getUniqueId()));
PacketWrapper wrapper = PacketWrapper.create(ClientboundPackets1_9.COMBAT_EVENT, null, getUserConnection(p.getUniqueId()));
try {
int entityId = getEntityId(p);
wrapper.write(Type.VAR_INT, 2); // Event - Entity dead

Datei anzeigen

@ -22,6 +22,7 @@ import com.viaversion.viaversion.api.Via;
import com.viaversion.viaversion.api.protocol.packet.PacketWrapper;
import com.viaversion.viaversion.api.type.Type;
import com.viaversion.viaversion.protocols.protocol1_9to1_8.ArmorType;
import com.viaversion.viaversion.protocols.protocol1_9to1_8.ClientboundPackets1_9;
import com.viaversion.viaversion.protocols.protocol1_9to1_8.Protocol1_9To1_8;
import com.viaversion.viaversion.sponge.listeners.ViaSpongeListener;
import org.spongepowered.api.data.type.HandTypes;
@ -58,7 +59,7 @@ public class Sponge5ArmorListener extends ViaSpongeListener {
armor += calculate(player.getLeggings());
armor += calculate(player.getBoots());
PacketWrapper wrapper = PacketWrapper.create(0x4B, null, getUserConnection(player.getUniqueId()));
PacketWrapper wrapper = PacketWrapper.create(ClientboundPackets1_9.ENTITY_PROPERTIES, null, getUserConnection(player.getUniqueId()));
try {
wrapper.write(Type.VAR_INT, getEntityId(player)); // Player ID
wrapper.write(Type.INT, 1); // only 1 property

Datei anzeigen

@ -21,6 +21,7 @@ import com.viaversion.viaversion.api.connection.UserConnection;
import com.viaversion.viaversion.api.protocol.packet.PacketWrapper;
import com.viaversion.viaversion.api.protocol.packet.State;
import com.viaversion.viaversion.api.type.Type;
import com.viaversion.viaversion.protocols.protocol1_8.ServerboundPackets1_8;
import com.viaversion.viaversion.protocols.protocol1_9to1_8.Protocol1_9To1_8;
import com.viaversion.viaversion.protocols.protocol1_9to1_8.providers.MovementTransmitterProvider;
import com.viaversion.viaversion.protocols.protocol1_9to1_8.storage.MovementTracker;
@ -38,7 +39,7 @@ public class VelocityMovementTransmitter extends MovementTransmitterProvider {
public void sendPlayer(UserConnection userConnection) {
if (userConnection.getProtocolInfo().getState() == State.PLAY) {
PacketWrapper wrapper = PacketWrapper.create(0x03, null, userConnection);
PacketWrapper wrapper = PacketWrapper.create(ServerboundPackets1_8.PLAYER_MOVEMENT, null, userConnection);
MovementTracker tracker = userConnection.get(MovementTracker.class);
wrapper.write(Type.BOOLEAN, tracker.isGround());
try {