Mirror von
https://github.com/ViaVersion/ViaVersion.git
synchronisiert 2024-10-05 01:31:05 +02:00
Semi force packet types in PacketWrapper at creation and transformation
Dieser Commit ist enthalten in:
Ursprung
874dbafe26
Commit
b81109f512
@ -93,19 +93,17 @@ public abstract class AbstractProtocol<C1 extends ClientboundPacketType, C2 exte
|
|||||||
newClientboundPackets.put(newConstant.getName(), newConstant);
|
newClientboundPackets.put(newConstant.getName(), newConstant);
|
||||||
}
|
}
|
||||||
|
|
||||||
for (ClientboundPacketType packet : oldClientboundPacketEnum.getEnumConstants()) {
|
for (C1 packet : oldClientboundPacketEnum.getEnumConstants()) {
|
||||||
ClientboundPacketType mappedPacket = newClientboundPackets.get(packet.getName());
|
C2 mappedPacket = (C2) newClientboundPackets.get(packet.getName());
|
||||||
int oldId = packet.getId();
|
|
||||||
if (mappedPacket == null) {
|
if (mappedPacket == null) {
|
||||||
// Packet doesn't exist on new client
|
// 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!");
|
"Packet " + packet + " in " + getClass().getSimpleName() + " has no mapping - it needs to be manually cancelled or remapped!");
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
int newId = mappedPacket.getId();
|
if (!hasRegisteredClientbound(packet)) {
|
||||||
if (!hasRegisteredClientbound(State.PLAY, oldId)) {
|
registerClientbound(packet, mappedPacket);
|
||||||
registerClientbound(State.PLAY, oldId, newId);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -117,19 +115,17 @@ public abstract class AbstractProtocol<C1 extends ClientboundPacketType, C2 exte
|
|||||||
oldServerboundConstants.put(oldConstant.getName(), oldConstant);
|
oldServerboundConstants.put(oldConstant.getName(), oldConstant);
|
||||||
}
|
}
|
||||||
|
|
||||||
for (ServerboundPacketType packet : newServerboundPacketEnum.getEnumConstants()) {
|
for (S2 packet : newServerboundPacketEnum.getEnumConstants()) {
|
||||||
ServerboundPacketType mappedPacket = oldServerboundConstants.get(packet.getName());
|
S1 mappedPacket = (S1) oldServerboundConstants.get(packet.getName());
|
||||||
int newId = packet.getId();
|
|
||||||
if (mappedPacket == null) {
|
if (mappedPacket == null) {
|
||||||
// Packet doesn't exist on old server
|
// 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!");
|
"Packet " + packet + " in " + getClass().getSimpleName() + " has no mapping - it needs to be manually cancelled or remapped!");
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
int oldId = mappedPacket.getId();
|
if (!hasRegisteredServerbound(packet)) {
|
||||||
if (!hasRegisteredServerbound(State.PLAY, newId)) {
|
registerServerbound(packet, mappedPacket);
|
||||||
registerServerbound(State.PLAY, oldId, newId);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -158,6 +154,7 @@ public abstract class AbstractProtocol<C1 extends ClientboundPacketType, C2 exte
|
|||||||
connection.addEntityTracker(this.getClass(), tracker);
|
connection.addEntityTracker(this.getClass(), tracker);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void registerServerbound(State state, int oldPacketID, int newPacketID, PacketRemapper packetRemapper, boolean override) {
|
public void registerServerbound(State state, int oldPacketID, int newPacketID, PacketRemapper packetRemapper, boolean override) {
|
||||||
ProtocolPacket protocolPacket = new ProtocolPacket(state, oldPacketID, newPacketID, packetRemapper);
|
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);
|
: 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!");
|
Preconditions.checkNotNull(mappedPacket, "Packet type " + packetType + " in " + packetType.getClass().getSimpleName() + " could not be automatically mapped!");
|
||||||
|
|
||||||
int oldId = packetType.getId();
|
registerClientbound(packetType, (C2) mappedPacket, packetRemapper);
|
||||||
int newId = mappedPacket.getId();
|
|
||||||
registerClientbound(State.PLAY, oldId, newId, packetRemapper);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void registerClientbound(C1 packetType, @Nullable C2 mappedPacketType, @Nullable PacketRemapper packetRemapper) {
|
public void registerClientbound(C1 packetType, @Nullable C2 mappedPacketType, @Nullable PacketRemapper packetRemapper, boolean override) {
|
||||||
checkPacketType(packetType, packetType.getClass() == oldClientboundPacketEnum);
|
register(clientbound, packetType, mappedPacketType, oldClientboundPacketEnum, newClientboundPacketEnum, packetRemapper, override);
|
||||||
checkPacketType(mappedPacketType, mappedPacketType == null || mappedPacketType.getClass() == newClientboundPacketEnum);
|
|
||||||
|
|
||||||
registerClientbound(State.PLAY, packetType.getId(), mappedPacketType != null ? mappedPacketType.getId() : -1, packetRemapper);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void cancelClientbound(C1 packetType) {
|
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
|
@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);
|
: 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!");
|
Preconditions.checkNotNull(mappedPacket, "Packet type " + packetType + " in " + packetType.getClass().getSimpleName() + " could not be automatically mapped!");
|
||||||
|
|
||||||
int oldId = mappedPacket.getId();
|
registerServerbound(packetType, (S1) mappedPacket, packetRemapper);
|
||||||
int newId = packetType.getId();
|
|
||||||
registerServerbound(State.PLAY, oldId, newId, packetRemapper);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void registerServerbound(S2 packetType, @Nullable S1 mappedPacketType, @Nullable PacketRemapper packetRemapper) {
|
public void registerServerbound(S2 packetType, @Nullable S1 mappedPacketType, @Nullable PacketRemapper packetRemapper, boolean override) {
|
||||||
checkPacketType(packetType, packetType.getClass() == newServerboundPacketEnum);
|
register(serverbound, packetType, mappedPacketType, newServerboundPacketEnum, oldServerboundPacketEnum, packetRemapper, override);
|
||||||
checkPacketType(mappedPacketType, mappedPacketType == null || mappedPacketType.getClass() == oldServerboundPacketEnum);
|
|
||||||
|
|
||||||
registerServerbound(State.PLAY, mappedPacketType != null ? mappedPacketType.getId() : -1, packetType.getId(), packetRemapper);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void cancelServerbound(S2 packetType) {
|
public void cancelServerbound(S2 packetType) {
|
||||||
Preconditions.checkArgument(packetType.getClass() == newServerboundPacketEnum);
|
registerServerbound(packetType, null, new PacketRemapper() {
|
||||||
cancelServerbound(State.PLAY, -1, packetType.getId());
|
@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
|
@Override
|
||||||
public boolean hasRegisteredClientbound(State state, int oldPacketID) {
|
public boolean hasRegisteredClientbound(C1 packetType) {
|
||||||
Packet packet = new Packet(state, oldPacketID);
|
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);
|
return clientbound.containsKey(packet);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean hasRegisteredServerbound(State state, int newPacketId) {
|
public boolean hasRegisteredServerbound(State state, int unmappedPacketId) {
|
||||||
Packet packet = new Packet(state, newPacketId);
|
Packet packet = new Packet(state, unmappedPacketId);
|
||||||
return serverbound.containsKey(packet);
|
return serverbound.containsKey(packet);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void transform(Direction direction, State state, PacketWrapper packetWrapper) throws Exception {
|
public void transform(Direction direction, State state, PacketWrapper packetWrapper) throws Exception {
|
||||||
Packet statePacket = new Packet(state, packetWrapper.getId());
|
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);
|
ProtocolPacket protocolPacket = packetMap.get(statePacket);
|
||||||
if (protocolPacket == null) {
|
if (protocolPacket == null) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Write packet id
|
// Write packet id
|
||||||
int oldId = packetWrapper.getId();
|
int unmappedId = packetWrapper.getId();
|
||||||
int newId = direction == Direction.CLIENTBOUND ? protocolPacket.getNewID() : protocolPacket.getOldID();
|
if (protocolPacket.isMappedOverTypes()) {
|
||||||
packetWrapper.setId(newId);
|
packetWrapper.setPacketType(protocolPacket.getMappedPacketType());
|
||||||
|
} else {
|
||||||
|
int mappedId = direction == Direction.CLIENTBOUND ? protocolPacket.getNewId() : protocolPacket.getOldId();
|
||||||
|
if (unmappedId != mappedId) {
|
||||||
|
packetWrapper.setId(mappedId);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
PacketRemapper remapper = protocolPacket.getRemapper();
|
PacketRemapper remapper = protocolPacket.getRemapper();
|
||||||
if (remapper != null) {
|
if (remapper != null) {
|
||||||
try {
|
try {
|
||||||
remapper.remap(packetWrapper);
|
remapper.remap(packetWrapper);
|
||||||
} catch (InformativeException e) { // Catch InformativeExceptions, pass through CancelExceptions
|
} catch (InformativeException e) { // Catch InformativeExceptions, pass through CancelExceptions
|
||||||
throwRemapError(direction, state, oldId, newId, e);
|
throwRemapError(direction, state, unmappedId, packetWrapper.getId(), e);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -390,14 +417,34 @@ public abstract class AbstractProtocol<C1 extends ClientboundPacketType, C2 exte
|
|||||||
|
|
||||||
public static final class ProtocolPacket {
|
public static final class ProtocolPacket {
|
||||||
private final State state;
|
private final State state;
|
||||||
private final int oldID;
|
private final int oldId;
|
||||||
private final int newID;
|
private final int newId;
|
||||||
|
private final PacketType unmappedPacketType;
|
||||||
|
private final PacketType mappedPacketType;
|
||||||
private final PacketRemapper remapper;
|
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.state = state;
|
||||||
this.oldID = oldID;
|
this.oldId = oldId;
|
||||||
this.newID = newID;
|
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;
|
this.remapper = remapper;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -405,12 +452,40 @@ public abstract class AbstractProtocol<C1 extends ClientboundPacketType, C2 exte
|
|||||||
return state;
|
return state;
|
||||||
}
|
}
|
||||||
|
|
||||||
public int getOldID() {
|
@Deprecated
|
||||||
return oldID;
|
public int getOldId() {
|
||||||
|
return oldId;
|
||||||
}
|
}
|
||||||
|
|
||||||
public int getNewID() {
|
@Deprecated
|
||||||
return newID;
|
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
|
@Nullable
|
||||||
|
@ -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> {
|
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) {
|
default void registerServerbound(State state, int oldPacketID, int newPacketID) {
|
||||||
registerServerbound(state, oldPacketID, newPacketID, null);
|
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) {
|
default void registerServerbound(State state, int oldPacketID, int newPacketID, PacketRemapper packetRemapper) {
|
||||||
registerServerbound(state, oldPacketID, newPacketID, packetRemapper, false);
|
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 registerServerbound(State state, int oldPacketID, int newPacketID, PacketRemapper packetRemapper, boolean override);
|
||||||
|
|
||||||
void cancelServerbound(State state, int oldPacketID, int newPacketID);
|
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);
|
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) {
|
default void registerClientbound(State state, int oldPacketID, int newPacketID) {
|
||||||
registerClientbound(state, oldPacketID, newPacketID, null);
|
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) {
|
default void registerClientbound(State state, int oldPacketID, int newPacketID, PacketRemapper packetRemapper) {
|
||||||
registerClientbound(state, oldPacketID, newPacketID, packetRemapper, false);
|
registerClientbound(state, oldPacketID, newPacketID, packetRemapper, false);
|
||||||
}
|
}
|
||||||
@ -107,8 +87,20 @@ public interface Protocol<C1 extends ClientboundPacketType, C2 extends Clientbou
|
|||||||
cancelClientbound(state, oldPacketID, -1);
|
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);
|
void registerClientbound(State state, int oldPacketID, int newPacketID, PacketRemapper packetRemapper, boolean override);
|
||||||
|
|
||||||
|
// ---------------------------------------------------------------------------------------
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Registers a clientbound protocol and automatically maps it to the new id.
|
* 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);
|
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.
|
* 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.
|
* 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);
|
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.
|
* 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);
|
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.
|
* 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 mappedPacketType serverbound packet type after transforming for the server
|
||||||
* @param packetRemapper remapper
|
* @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.
|
* 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);
|
void cancelServerbound(S2 packetType);
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Checks if a clientbound packet has already been registered.
|
* Checks if a clientbound packet has already been registered.
|
||||||
*
|
*
|
||||||
* @param state state which the packet is sent in
|
* @param packetType clientbound packet type
|
||||||
* @param oldPacketID old packet ID
|
|
||||||
* @return true if already registered
|
* @return true if already registered
|
||||||
*/
|
*/
|
||||||
boolean hasRegisteredClientbound(State state, int oldPacketID);
|
boolean hasRegisteredClientbound(C1 packetType);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Checks if a serverbound packet has already been registered.
|
* Checks if a serverbound packet has already been registered.
|
||||||
*
|
*
|
||||||
* @param state state which the packet is sent in
|
* @param packetType serverbound packet type
|
||||||
* @param newPacketId packet ID
|
|
||||||
* @return true if already registered
|
* @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
|
* Transform a packet using this protocol
|
||||||
|
@ -151,16 +151,14 @@ public interface ProtocolManager {
|
|||||||
* The used packet types have to match the given protocol version.
|
* The used packet types have to match the given protocol version.
|
||||||
*
|
*
|
||||||
* @param inputVersion input 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 clientboundPacketsClass clientbound packets class
|
||||||
* @param serverboundPacketsClass serverbound packets class
|
* @param serverboundPacketsClass serverbound packets class
|
||||||
* @return versioned packet creator
|
* @return versioned packet creator
|
||||||
* @throws IllegalArgumentException if either of the packet classes are the base {@link ClientboundPacketType} or {@link ServerboundPacketType} interfaces
|
* @throws IllegalArgumentException if either of the packet classes are the base {@link ClientboundPacketType} or {@link ServerboundPacketType} interfaces
|
||||||
*/
|
*/
|
||||||
<C extends ClientboundPacketType,
|
VersionedPacketCreator createVersionedPacketCreator(ProtocolVersion inputVersion,
|
||||||
S extends ServerboundPacketType
|
Class<? extends ClientboundPacketType> clientboundPacketsClass,
|
||||||
> VersionedPacketCreator<C, S> createVersionedPacketCreator(ProtocolVersion inputVersion, Class<C> clientboundPacketsClass, Class<S> serverboundPacketsClass);
|
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.
|
* 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.
|
* 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 buf input buffer
|
||||||
* @param connection user connection
|
* @param connection user connection
|
||||||
* @return new packet wrapper instance
|
* @return new packet wrapper instance
|
||||||
* @see PacketWrapper#create(PacketType, ByteBuf, UserConnection)
|
* @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);
|
PacketWrapper createPacketWrapper(int packetId, @Nullable ByteBuf buf, UserConnection connection);
|
||||||
}
|
}
|
||||||
|
@ -50,4 +50,13 @@ public interface PacketType {
|
|||||||
* @return direction
|
* @return direction
|
||||||
*/
|
*/
|
||||||
Direction direction();
|
Direction direction();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns the protocol state the packet belongs to.
|
||||||
|
*
|
||||||
|
* @return protocol state
|
||||||
|
*/
|
||||||
|
default State state() {
|
||||||
|
return State.PLAY;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -41,34 +41,36 @@ public interface PacketWrapper {
|
|||||||
/**
|
/**
|
||||||
* Creates a new packet wrapper instance.
|
* 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
|
* @param connection user connection
|
||||||
* @return new packet wrapper
|
* @return new packet wrapper
|
||||||
*/
|
*/
|
||||||
static PacketWrapper create(PacketType packetType, UserConnection connection) {
|
static PacketWrapper create(@Nullable PacketType packetType, UserConnection connection) {
|
||||||
return create(packetType.getId(), null, connection);
|
return create(packetType, null, connection);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Creates a new packet wrapper instance.
|
* 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 inputBuffer input buffer
|
||||||
* @param connection user connection
|
* @param connection user connection
|
||||||
* @return new packet wrapper
|
* @return new packet wrapper
|
||||||
*/
|
*/
|
||||||
static PacketWrapper create(PacketType packetType, @Nullable ByteBuf inputBuffer, UserConnection connection) {
|
static PacketWrapper create(@Nullable PacketType packetType, @Nullable ByteBuf inputBuffer, UserConnection connection) {
|
||||||
return create(packetType.getId(), inputBuffer, connection);
|
return Via.getManager().getProtocolManager().createPacketWrapper(packetType, inputBuffer, connection);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Creates a new packet wrapper instance.
|
* 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 inputBuffer input buffer
|
||||||
* @param connection user connection
|
* @param connection user connection
|
||||||
* @return new packet wrapper
|
* @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) {
|
static PacketWrapper create(int packetId, @Nullable ByteBuf inputBuffer, UserConnection connection) {
|
||||||
return Via.getManager().getProtocolManager().createPacketWrapper(packetId, inputBuffer, 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;
|
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();
|
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
|
* @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) {
|
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)}.
|
* Sets the packet id. If set to -1, it will not be written to the buffer with {@link #writeToBuffer(ByteBuf)}.
|
||||||
*
|
*
|
||||||
* @param id packet id
|
* @param id packet id
|
||||||
|
* @deprecated magic id, loses packet type info; use {@link #setPacketType(PacketType)}
|
||||||
*/
|
*/
|
||||||
|
@Deprecated
|
||||||
void setId(int id);
|
void setId(int id);
|
||||||
}
|
}
|
||||||
|
@ -23,100 +23,48 @@
|
|||||||
package com.viaversion.viaversion.api.protocol.packet;
|
package com.viaversion.viaversion.api.protocol.packet;
|
||||||
|
|
||||||
import com.viaversion.viaversion.api.connection.ProtocolInfo;
|
import com.viaversion.viaversion.api.connection.ProtocolInfo;
|
||||||
import com.viaversion.viaversion.api.connection.UserConnection;
|
|
||||||
import org.checkerframework.checker.nullness.qual.Nullable;
|
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.
|
* 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.
|
* 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
|
* @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 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
|
* @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.
|
* 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 packet packet wrapper
|
||||||
* @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
|
|
||||||
* @return whether this packet specifically has been sent, false if cancelled
|
* @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 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 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
|
* @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.
|
* Transforms a packet to the protocol version of the given connection or server, or null if cancelled at some point.
|
||||||
* Returns false if the packet has been cancelled at some point, but does not indicate whether a replacement has been constructed.
|
* The target version is given by {@link ProtocolInfo#getProtocolVersion()} or {@link ProtocolInfo#getServerProtocolVersion()}.
|
||||||
*
|
*
|
||||||
* @param connection user connection
|
* @param packet packet wrapper
|
||||||
* @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
|
|
||||||
* @return created and transformed packet wrapper, or null if cancelled at some point
|
* @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 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 RuntimeException if no path from the input version to the required client version exists
|
||||||
* @throws Exception if an error occurred while constructing the packet
|
* @throws Exception if an error occurred while constructing the packet
|
||||||
*/
|
*/
|
||||||
@Nullable PacketWrapper transform(UserConnection connection, C packetType, Consumer<PacketWrapper> packetWriter) throws Exception;
|
@Nullable PacketWrapper transform(PacketWrapper packet) 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;
|
|
||||||
}
|
}
|
||||||
|
@ -17,6 +17,7 @@
|
|||||||
*/
|
*/
|
||||||
package com.viaversion.viaversion.bukkit.listeners.protocol1_9to1_8;
|
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.Bukkit;
|
||||||
import org.bukkit.entity.HumanEntity;
|
import org.bukkit.entity.HumanEntity;
|
||||||
import org.bukkit.entity.Player;
|
import org.bukkit.entity.Player;
|
||||||
@ -58,7 +59,7 @@ public class ArmorListener extends ViaBukkitListener {
|
|||||||
armor += ArmorType.findById(stack.getTypeId()).getArmorPoints();
|
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 {
|
try {
|
||||||
wrapper.write(Type.VAR_INT, player.getEntityId()); // Player ID
|
wrapper.write(Type.VAR_INT, player.getEntityId()); // Player ID
|
||||||
wrapper.write(Type.INT, 1); // only 1 property
|
wrapper.write(Type.INT, 1); // only 1 property
|
||||||
|
@ -17,6 +17,7 @@
|
|||||||
*/
|
*/
|
||||||
package com.viaversion.viaversion.bukkit.listeners.protocol1_9to1_8;
|
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.World;
|
||||||
import org.bukkit.entity.Player;
|
import org.bukkit.entity.Player;
|
||||||
import org.bukkit.event.EventHandler;
|
import org.bukkit.event.EventHandler;
|
||||||
@ -58,7 +59,7 @@ public class DeathListener extends ViaBukkitListener {
|
|||||||
// If online
|
// If online
|
||||||
UserConnection userConnection = getUserConnection(p);
|
UserConnection userConnection = getUserConnection(p);
|
||||||
if (userConnection != null) {
|
if (userConnection != null) {
|
||||||
PacketWrapper wrapper = PacketWrapper.create(0x2C, null, userConnection);
|
PacketWrapper wrapper = PacketWrapper.create(ClientboundPackets1_9.COMBAT_EVENT, null, userConnection);
|
||||||
try {
|
try {
|
||||||
wrapper.write(Type.VAR_INT, 2); // Event - Entity dead
|
wrapper.write(Type.VAR_INT, 2); // Event - Entity dead
|
||||||
wrapper.write(Type.VAR_INT, p.getEntityId()); // Player ID
|
wrapper.write(Type.VAR_INT, p.getEntityId()); // Player ID
|
||||||
|
@ -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.Type;
|
||||||
import com.viaversion.viaversion.api.type.types.version.Types1_14;
|
import com.viaversion.viaversion.api.type.types.version.Types1_14;
|
||||||
import com.viaversion.viaversion.bukkit.listeners.ViaBukkitListener;
|
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 com.viaversion.viaversion.protocols.protocol1_15to1_14_4.Protocol1_15To1_14_4;
|
||||||
import org.bukkit.entity.Player;
|
import org.bukkit.entity.Player;
|
||||||
import org.bukkit.event.EventHandler;
|
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
|
// Cancelling can only be done by updating the player's metadata
|
||||||
if (event.isGliding() && event.isCancelled()) {
|
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 {
|
try {
|
||||||
packet.write(Type.VAR_INT, player.getEntityId());
|
packet.write(Type.VAR_INT, player.getEntityId());
|
||||||
|
|
||||||
|
@ -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.protocol.packet.PacketWrapper;
|
||||||
import com.viaversion.viaversion.api.type.Type;
|
import com.viaversion.viaversion.api.type.Type;
|
||||||
import com.viaversion.viaversion.api.type.types.version.Types1_9;
|
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.Protocol1_9To1_8;
|
||||||
import com.viaversion.viaversion.protocols.protocol1_9to1_8.storage.EntityTracker1_9;
|
import com.viaversion.viaversion.protocols.protocol1_9to1_8.storage.EntityTracker1_9;
|
||||||
import net.md_5.bungee.api.event.ServerConnectedEvent;
|
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);
|
EntityTracker1_9 tracker = user.getEntityTracker(Protocol1_9To1_8.class);
|
||||||
int entityId = tracker.getProvidedEntityId();
|
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(Type.VAR_INT, entityId);
|
||||||
wrapper.write(Types1_9.METADATA_LIST, Collections.singletonList(new Metadata(0, MetaType1_9.Byte, (byte) 0)));
|
wrapper.write(Types1_9.METADATA_LIST, Collections.singletonList(new Metadata(0, MetaType1_9.Byte, (byte) 0)));
|
||||||
|
@ -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.PacketWrapper;
|
||||||
import com.viaversion.viaversion.api.protocol.packet.State;
|
import com.viaversion.viaversion.api.protocol.packet.State;
|
||||||
import com.viaversion.viaversion.api.type.Type;
|
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.Protocol1_9To1_8;
|
||||||
import com.viaversion.viaversion.protocols.protocol1_9to1_8.providers.MovementTransmitterProvider;
|
import com.viaversion.viaversion.protocols.protocol1_9to1_8.providers.MovementTransmitterProvider;
|
||||||
import com.viaversion.viaversion.protocols.protocol1_9to1_8.storage.MovementTracker;
|
import com.viaversion.viaversion.protocols.protocol1_9to1_8.storage.MovementTracker;
|
||||||
@ -38,7 +39,7 @@ public class BungeeMovementTransmitter extends MovementTransmitterProvider {
|
|||||||
|
|
||||||
public void sendPlayer(UserConnection userConnection) {
|
public void sendPlayer(UserConnection userConnection) {
|
||||||
if (userConnection.getProtocolInfo().getState() == State.PLAY) {
|
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);
|
MovementTracker tracker = userConnection.get(MovementTracker.class);
|
||||||
wrapper.write(Type.BOOLEAN, tracker.isGround());
|
wrapper.write(Type.BOOLEAN, tracker.isGround());
|
||||||
try {
|
try {
|
||||||
|
@ -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.protocol.packet.PacketWrapper;
|
||||||
import com.viaversion.viaversion.api.type.Type;
|
import com.viaversion.viaversion.api.type.Type;
|
||||||
import com.viaversion.viaversion.exception.CancelException;
|
import com.viaversion.viaversion.exception.CancelException;
|
||||||
|
import com.viaversion.viaversion.protocol.packet.PacketWrapperImpl;
|
||||||
import com.viaversion.viaversion.util.ChatColorUtil;
|
import com.viaversion.viaversion.util.ChatColorUtil;
|
||||||
import com.viaversion.viaversion.util.PipelineUtil;
|
import com.viaversion.viaversion.util.PipelineUtil;
|
||||||
import io.netty.buffer.ByteBuf;
|
import io.netty.buffer.ByteBuf;
|
||||||
@ -290,7 +291,7 @@ public class UserConnectionImpl implements UserConnection {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
PacketWrapper wrapper = PacketWrapper.create(id, buf, this);
|
PacketWrapper wrapper = new PacketWrapperImpl(id, buf, this);
|
||||||
try {
|
try {
|
||||||
protocolInfo.getPipeline().transform(direction, protocolInfo.getState(), wrapper);
|
protocolInfo.getPipeline().transform(direction, protocolInfo.getState(), wrapper);
|
||||||
} catch (CancelException ex) {
|
} catch (CancelException ex) {
|
||||||
|
@ -29,6 +29,7 @@ import com.viaversion.viaversion.api.protocol.ProtocolManager;
|
|||||||
import com.viaversion.viaversion.api.protocol.ProtocolPathEntry;
|
import com.viaversion.viaversion.api.protocol.ProtocolPathEntry;
|
||||||
import com.viaversion.viaversion.api.protocol.ProtocolPathKey;
|
import com.viaversion.viaversion.api.protocol.ProtocolPathKey;
|
||||||
import com.viaversion.viaversion.api.protocol.packet.ClientboundPacketType;
|
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.PacketWrapper;
|
||||||
import com.viaversion.viaversion.api.protocol.packet.ServerboundPacketType;
|
import com.viaversion.viaversion.api.protocol.packet.ServerboundPacketType;
|
||||||
import com.viaversion.viaversion.api.protocol.packet.VersionedPacketCreator;
|
import com.viaversion.viaversion.api.protocol.packet.VersionedPacketCreator;
|
||||||
@ -266,11 +267,11 @@ public class ProtocolManagerImpl implements ProtocolManager {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public <C extends ClientboundPacketType,
|
public VersionedPacketCreator createVersionedPacketCreator(ProtocolVersion inputVersion,
|
||||||
S extends ServerboundPacketType
|
Class<? extends ClientboundPacketType> clientboundPacketsClass,
|
||||||
> VersionedPacketCreator<C, S> createVersionedPacketCreator(ProtocolVersion inputVersion, Class<C> clientboundPacketsClass, Class<S> serverboundPacketsClass) {
|
Class<? extends ServerboundPacketType> serverboundPacketsClass) {
|
||||||
Preconditions.checkArgument(clientboundPacketsClass != ClientboundPacketType.class && serverboundPacketsClass != ServerboundPacketType.class);
|
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
|
@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) {
|
public PacketWrapper createPacketWrapper(int packetId, @Nullable ByteBuf buf, UserConnection connection) {
|
||||||
return new PacketWrapperImpl(packetId, buf, connection);
|
return new PacketWrapperImpl(packetId, buf, connection);
|
||||||
}
|
}
|
||||||
|
@ -22,6 +22,7 @@ import com.viaversion.viaversion.api.Via;
|
|||||||
import com.viaversion.viaversion.api.connection.UserConnection;
|
import com.viaversion.viaversion.api.connection.UserConnection;
|
||||||
import com.viaversion.viaversion.api.protocol.Protocol;
|
import com.viaversion.viaversion.api.protocol.Protocol;
|
||||||
import com.viaversion.viaversion.api.protocol.packet.Direction;
|
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.PacketWrapper;
|
||||||
import com.viaversion.viaversion.api.protocol.packet.State;
|
import com.viaversion.viaversion.api.protocol.packet.State;
|
||||||
import com.viaversion.viaversion.api.protocol.remapper.PacketHandler;
|
import com.viaversion.viaversion.api.protocol.remapper.PacketHandler;
|
||||||
@ -48,7 +49,9 @@ public class PacketWrapperImpl implements PacketWrapper {
|
|||||||
private final ByteBuf inputBuffer;
|
private final ByteBuf inputBuffer;
|
||||||
private final UserConnection userConnection;
|
private final UserConnection userConnection;
|
||||||
private boolean send = true;
|
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 Deque<Pair<Type, Object>> readableObjects = new ArrayDeque<>();
|
||||||
private final List<Pair<Type, Object>> packetValues = new ArrayList<>();
|
private final List<Pair<Type, Object>> packetValues = new ArrayList<>();
|
||||||
|
|
||||||
@ -58,6 +61,13 @@ public class PacketWrapperImpl implements PacketWrapper {
|
|||||||
this.userConnection = userConnection;
|
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
|
@Override
|
||||||
public <T> T get(Type<T> type, int index) throws Exception {
|
public <T> T get(Type<T> type, int index) throws Exception {
|
||||||
int currentIndex = 0;
|
int currentIndex = 0;
|
||||||
@ -70,7 +80,7 @@ public class PacketWrapperImpl implements PacketWrapper {
|
|||||||
}
|
}
|
||||||
|
|
||||||
Exception e = new ArrayIndexOutOfBoundsException("Could not find type " + type.getTypeName() + " at " + index);
|
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
|
@Override
|
||||||
@ -112,7 +122,7 @@ public class PacketWrapperImpl implements PacketWrapper {
|
|||||||
currentIndex++;
|
currentIndex++;
|
||||||
}
|
}
|
||||||
Exception e = new ArrayIndexOutOfBoundsException("Could not find type " + type.getTypeName() + " at " + index);
|
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
|
@Override
|
||||||
@ -124,7 +134,7 @@ public class PacketWrapperImpl implements PacketWrapper {
|
|||||||
try {
|
try {
|
||||||
return type.read(inputBuffer);
|
return type.read(inputBuffer);
|
||||||
} catch (Exception e) {
|
} 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
|
return read(type); // retry
|
||||||
} else {
|
} else {
|
||||||
Exception e = new IOException("Unable to read type " + type.getTypeName() + ", found " + read.getKey().getTypeName());
|
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 {
|
try {
|
||||||
packetValue.getKey().write(buffer, packetValue.getValue());
|
packetValue.getKey().write(buffer, packetValue.getValue());
|
||||||
} catch (Exception e) {
|
} 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++;
|
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
|
@Override
|
||||||
public int getId() {
|
public int getId() {
|
||||||
return id;
|
return id;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@Deprecated
|
||||||
public void setId(int id) {
|
public void setId(int id) {
|
||||||
|
// Loses packet type info
|
||||||
|
this.packetType = null;
|
||||||
this.id = id;
|
this.id = id;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -467,6 +491,7 @@ public class PacketWrapperImpl implements PacketWrapper {
|
|||||||
"packetValues=" + packetValues +
|
"packetValues=" + packetValues +
|
||||||
", readableObjects=" + readableObjects +
|
", readableObjects=" + readableObjects +
|
||||||
", id=" + id +
|
", id=" + id +
|
||||||
|
", packetType" + packetType +
|
||||||
'}';
|
'}';
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -34,15 +34,15 @@ import org.checkerframework.checker.nullness.qual.Nullable;
|
|||||||
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.List;
|
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 int inputProtocolVersion;
|
||||||
private final Class<C> clientboundPacketsClass;
|
private final Class<? extends ClientboundPacketType> clientboundPacketsClass;
|
||||||
private final Class<S> serverboundPacketsClass;
|
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(inputVersion);
|
||||||
Preconditions.checkNotNull(clientboundPacketsClass);
|
Preconditions.checkNotNull(clientboundPacketsClass);
|
||||||
Preconditions.checkNotNull(serverboundPacketsClass);
|
Preconditions.checkNotNull(serverboundPacketsClass);
|
||||||
@ -52,57 +52,53 @@ public class VersionedPacketCreatorImpl<C extends ClientboundPacketType, S exten
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean send(UserConnection connection, C packetType, Consumer<PacketWrapper> packetWriter) throws Exception {
|
public boolean send(PacketWrapper packet) throws Exception {
|
||||||
Preconditions.checkArgument(packetType.getClass() == clientboundPacketsClass);
|
validatePacket(packet);
|
||||||
return createAndSend(connection, packetType, packetWriter, true);
|
return transformAndSendPacket(packet, true);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean send(UserConnection connection, S packetType, Consumer<PacketWrapper> packetWriter) throws Exception {
|
public boolean scheduleSend(PacketWrapper packet) throws Exception {
|
||||||
Preconditions.checkArgument(packetType.getClass() == serverboundPacketsClass);
|
validatePacket(packet);
|
||||||
return createAndSend(connection, packetType, packetWriter, true);
|
return transformAndSendPacket(packet, false);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean scheduleSend(UserConnection connection, C packetType, Consumer<PacketWrapper> packetWriter) throws Exception {
|
public @Nullable PacketWrapper transform(PacketWrapper packet) throws Exception {
|
||||||
Preconditions.checkArgument(packetType.getClass() == clientboundPacketsClass);
|
validatePacket(packet);
|
||||||
return createAndSend(connection, packetType, packetWriter, false);
|
transformPacket(packet);
|
||||||
}
|
|
||||||
|
|
||||||
@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);
|
|
||||||
return packet.isCancelled() ? null : packet;
|
return packet.isCancelled() ? null : packet;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
private void validatePacket(PacketWrapper packet) {
|
||||||
public @Nullable PacketWrapper transform(UserConnection connection, S packetType, Consumer<PacketWrapper> packetWriter) throws Exception {
|
if (packet.user() == null) {
|
||||||
Preconditions.checkArgument(packetType.getClass() == serverboundPacketsClass);
|
throw new IllegalArgumentException("PacketWrapper does not have a targetted UserConnection");
|
||||||
PacketWrapper packet = createAndTransform(connection, packetType, packetWriter);
|
}
|
||||||
return packet.isCancelled() ? null : packet;
|
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 {
|
private boolean transformAndSendPacket(PacketWrapper packet, boolean currentThread) throws Exception {
|
||||||
PacketWrapper packet = createAndTransform(connection, packetType, packetWriter);
|
transformPacket(packet);
|
||||||
if (!packet.isCancelled()) {
|
if (packet.isCancelled()) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (currentThread) {
|
if (currentThread) {
|
||||||
if (packetType.direction() == Direction.CLIENTBOUND) {
|
if (packet.getPacketType().direction() == Direction.CLIENTBOUND) {
|
||||||
packet.sendRaw();
|
packet.sendRaw();
|
||||||
} else {
|
} else {
|
||||||
packet.sendToServerRaw();
|
packet.sendToServerRaw();
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
if (packetType.direction() == Direction.CLIENTBOUND) {
|
if (packet.getPacketType().direction() == Direction.CLIENTBOUND) {
|
||||||
packet.scheduleSendRaw();
|
packet.scheduleSendRaw();
|
||||||
} else {
|
} else {
|
||||||
packet.scheduleSendToServerRaw();
|
packet.scheduleSendToServerRaw();
|
||||||
@ -111,9 +107,11 @@ public class VersionedPacketCreatorImpl<C extends ClientboundPacketType, S exten
|
|||||||
return true;
|
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 clientbound: Constructor given inputProtocolVersion → Client version
|
||||||
// If serverbound: Constructor given inputProtocolVersion → Server version
|
// If serverbound: Constructor given inputProtocolVersion → Server version
|
||||||
|
PacketType packetType = packet.getPacketType();
|
||||||
|
UserConnection connection = packet.user();
|
||||||
boolean clientbound = packetType.direction() == Direction.CLIENTBOUND;
|
boolean clientbound = packetType.direction() == Direction.CLIENTBOUND;
|
||||||
int serverProtocolVersion = clientbound ? this.inputProtocolVersion : connection.getProtocolInfo().getServerProtocolVersion();
|
int serverProtocolVersion = clientbound ? this.inputProtocolVersion : connection.getProtocolInfo().getServerProtocolVersion();
|
||||||
int clientProtocolVersion = clientbound ? connection.getProtocolInfo().getProtocolVersion() : this.inputProtocolVersion;
|
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);
|
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) {
|
if (protocolList != null) {
|
||||||
// Reset reader and apply pipeline
|
// Reset reader and apply pipeline
|
||||||
packet.resetReader();
|
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);
|
+ " and server version " + serverProtocolVersion + ". Are you sure you used the correct input version and packet write types?", e);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return packet;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -19,9 +19,8 @@ package com.viaversion.viaversion.protocols.base;
|
|||||||
|
|
||||||
import com.viaversion.viaversion.api.Via;
|
import com.viaversion.viaversion.api.Via;
|
||||||
import com.viaversion.viaversion.api.connection.ProtocolInfo;
|
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.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.Protocol;
|
||||||
import com.viaversion.viaversion.api.protocol.ProtocolPathEntry;
|
import com.viaversion.viaversion.api.protocol.ProtocolPathEntry;
|
||||||
import com.viaversion.viaversion.api.protocol.ProtocolPipeline;
|
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.ArrayList;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
public class BaseProtocol extends AbstractSimpleProtocol {
|
public class BaseProtocol extends AbstractProtocol {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void registerPackets() {
|
protected void registerPackets() {
|
||||||
/* Incoming Packets */
|
|
||||||
|
|
||||||
// Handshake Packet
|
// Handshake Packet
|
||||||
registerServerbound(State.HANDSHAKE, 0x00, 0x00, new PacketRemapper() {
|
registerServerbound(ServerboundHandshakePackets.CLIENT_INTENTION, new PacketRemapper() {
|
||||||
@Override
|
@Override
|
||||||
public void registerMap() {
|
public void registerMap() {
|
||||||
handler(wrapper -> {
|
handler(wrapper -> {
|
||||||
@ -108,11 +105,6 @@ public class BaseProtocol extends AbstractSimpleProtocol {
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
|
||||||
public void init(UserConnection userConnection) {
|
|
||||||
// Nothing gets added, ProtocolPipeline handles ProtocolInfo
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void register(ViaProviders providers) {
|
public void register(ViaProviders providers) {
|
||||||
providers.register(VersionProvider.class, new BaseVersionProvider());
|
providers.register(VersionProvider.class, new BaseVersionProvider());
|
||||||
|
@ -23,7 +23,7 @@ import com.google.gson.JsonObject;
|
|||||||
import com.google.gson.JsonParseException;
|
import com.google.gson.JsonParseException;
|
||||||
import com.viaversion.viaversion.api.Via;
|
import com.viaversion.viaversion.api.Via;
|
||||||
import com.viaversion.viaversion.api.connection.ProtocolInfo;
|
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.ProtocolPathEntry;
|
||||||
import com.viaversion.viaversion.api.protocol.packet.PacketWrapper;
|
import com.viaversion.viaversion.api.protocol.packet.PacketWrapper;
|
||||||
import com.viaversion.viaversion.api.protocol.packet.State;
|
import com.viaversion.viaversion.api.protocol.packet.State;
|
||||||
@ -43,14 +43,14 @@ import java.util.List;
|
|||||||
import java.util.UUID;
|
import java.util.UUID;
|
||||||
import java.util.logging.Level;
|
import java.util.logging.Level;
|
||||||
|
|
||||||
public class BaseProtocol1_7 extends AbstractSimpleProtocol {
|
public class BaseProtocol1_7 extends AbstractProtocol {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void registerPackets() {
|
protected void registerPackets() {
|
||||||
/* Outgoing Packets */
|
/* Outgoing Packets */
|
||||||
|
|
||||||
// Status Response Packet
|
// Status Response Packet
|
||||||
registerClientbound(State.STATUS, 0x00, 0x00, new PacketRemapper() { // Status Response Packet
|
registerClientbound(ClientboundStatusPackets.STATUS_RESPONSE, new PacketRemapper() { // Status Response Packet
|
||||||
@Override
|
@Override
|
||||||
public void registerMap() {
|
public void registerMap() {
|
||||||
map(Type.STRING);
|
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
|
// Login Success Packet
|
||||||
registerClientbound(State.LOGIN, 0x02, 0x02, new PacketRemapper() {
|
registerClientbound(ClientboundLoginPackets.GAME_PROFILE, new PacketRemapper() {
|
||||||
@Override
|
@Override
|
||||||
public void registerMap() {
|
public void registerMap() {
|
||||||
handler(new PacketHandler() {
|
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 */
|
/* Incoming Packets */
|
||||||
|
|
||||||
registerServerbound(State.STATUS, 0x00, 0x00); // Status Request Packet
|
|
||||||
registerServerbound(State.STATUS, 0x01, 0x01); // Status Ping Packet
|
|
||||||
|
|
||||||
// Login Start Packet
|
// Login Start Packet
|
||||||
registerServerbound(State.LOGIN, 0x00, 0x00, new PacketRemapper() {
|
registerServerbound(ServerboundLoginPackets.HELLO, new PacketRemapper() {
|
||||||
@Override
|
@Override
|
||||||
public void registerMap() {
|
public void registerMap() {
|
||||||
handler(new PacketHandler() {
|
handler(new PacketHandler() {
|
||||||
@ -185,7 +173,7 @@ public class BaseProtocol1_7 extends AbstractSimpleProtocol {
|
|||||||
if (!wrapper.user().getChannel().isOpen()) return;
|
if (!wrapper.user().getChannel().isOpen()) return;
|
||||||
if (!wrapper.user().shouldApplyBlockProtocol()) 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()));
|
Protocol1_9To1_8.FIX_JSON.write(disconnectPacket, ChatColorUtil.translateAlternateColorCodes(Via.getConfig().getBlockedDisconnectMsg()));
|
||||||
wrapper.cancel(); // cancel current
|
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
|
@Override
|
||||||
|
@ -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;
|
||||||
|
}
|
||||||
|
}
|
@ -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;
|
||||||
|
}
|
||||||
|
}
|
@ -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;
|
||||||
|
}
|
||||||
|
}
|
@ -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;
|
||||||
|
}
|
||||||
|
}
|
@ -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;
|
||||||
|
}
|
||||||
|
}
|
@ -66,7 +66,7 @@ public class Protocol1_10To1_9_3_4 extends AbstractProtocol<ClientboundPackets1_
|
|||||||
itemRewriter.register();
|
itemRewriter.register();
|
||||||
|
|
||||||
// Named sound effect
|
// Named sound effect
|
||||||
registerClientbound(State.PLAY, 0x19, 0x19, new PacketRemapper() {
|
registerClientbound(ClientboundPackets1_9_3.NAMED_SOUND, new PacketRemapper() {
|
||||||
@Override
|
@Override
|
||||||
public void registerMap() {
|
public void registerMap() {
|
||||||
map(Type.STRING); // 0 - Sound name
|
map(Type.STRING); // 0 - Sound name
|
||||||
@ -80,7 +80,7 @@ public class Protocol1_10To1_9_3_4 extends AbstractProtocol<ClientboundPackets1_
|
|||||||
});
|
});
|
||||||
|
|
||||||
// Sound effect
|
// Sound effect
|
||||||
registerClientbound(State.PLAY, 0x46, 0x46, new PacketRemapper() {
|
registerClientbound(ClientboundPackets1_9_3.SOUND, new PacketRemapper() {
|
||||||
@Override
|
@Override
|
||||||
public void registerMap() {
|
public void registerMap() {
|
||||||
map(Type.VAR_INT); // 0 - Sound name
|
map(Type.VAR_INT); // 0 - Sound name
|
||||||
@ -102,7 +102,7 @@ public class Protocol1_10To1_9_3_4 extends AbstractProtocol<ClientboundPackets1_
|
|||||||
});
|
});
|
||||||
|
|
||||||
// Metadata packet
|
// Metadata packet
|
||||||
registerClientbound(State.PLAY, 0x39, 0x39, new PacketRemapper() {
|
registerClientbound(ClientboundPackets1_9_3.ENTITY_METADATA, new PacketRemapper() {
|
||||||
@Override
|
@Override
|
||||||
public void registerMap() {
|
public void registerMap() {
|
||||||
map(Type.VAR_INT); // 0 - Entity ID
|
map(Type.VAR_INT); // 0 - Entity ID
|
||||||
@ -111,7 +111,7 @@ public class Protocol1_10To1_9_3_4 extends AbstractProtocol<ClientboundPackets1_
|
|||||||
});
|
});
|
||||||
|
|
||||||
// Spawn Mob
|
// Spawn Mob
|
||||||
registerClientbound(State.PLAY, 0x03, 0x03, new PacketRemapper() {
|
registerClientbound(ClientboundPackets1_9_3.SPAWN_MOB, new PacketRemapper() {
|
||||||
@Override
|
@Override
|
||||||
public void registerMap() {
|
public void registerMap() {
|
||||||
map(Type.VAR_INT); // 0 - Entity id
|
map(Type.VAR_INT); // 0 - Entity id
|
||||||
@ -131,7 +131,7 @@ public class Protocol1_10To1_9_3_4 extends AbstractProtocol<ClientboundPackets1_
|
|||||||
});
|
});
|
||||||
|
|
||||||
// Spawn Player
|
// Spawn Player
|
||||||
registerClientbound(State.PLAY, 0x05, 0x05, new PacketRemapper() {
|
registerClientbound(ClientboundPackets1_9_3.SPAWN_PLAYER, new PacketRemapper() {
|
||||||
@Override
|
@Override
|
||||||
public void registerMap() {
|
public void registerMap() {
|
||||||
map(Type.VAR_INT); // 0 - Entity ID
|
map(Type.VAR_INT); // 0 - Entity ID
|
||||||
@ -146,7 +146,7 @@ public class Protocol1_10To1_9_3_4 extends AbstractProtocol<ClientboundPackets1_
|
|||||||
});
|
});
|
||||||
|
|
||||||
// Packet Send ResourcePack
|
// Packet Send ResourcePack
|
||||||
registerClientbound(State.PLAY, 0x32, 0x32, new PacketRemapper() {
|
registerClientbound(ClientboundPackets1_9_3.RESOURCE_PACK, new PacketRemapper() {
|
||||||
@Override
|
@Override
|
||||||
public void registerMap() {
|
public void registerMap() {
|
||||||
map(Type.STRING); // 0 - URL
|
map(Type.STRING); // 0 - URL
|
||||||
@ -163,7 +163,7 @@ public class Protocol1_10To1_9_3_4 extends AbstractProtocol<ClientboundPackets1_
|
|||||||
});
|
});
|
||||||
|
|
||||||
// Packet ResourcePack status
|
// Packet ResourcePack status
|
||||||
registerServerbound(State.PLAY, 0x16, 0x16, new PacketRemapper() {
|
registerServerbound(ServerboundPackets1_9_3.RESOURCE_PACK_STATUS, new PacketRemapper() {
|
||||||
@Override
|
@Override
|
||||||
public void registerMap() {
|
public void registerMap() {
|
||||||
handler(new PacketHandler() {
|
handler(new PacketHandler() {
|
||||||
|
@ -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.EntityIdRewriter;
|
||||||
import com.viaversion.viaversion.protocols.protocol1_11to1_10.Protocol1_11To1_10;
|
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_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 com.viaversion.viaversion.rewriter.EntityRewriter;
|
||||||
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
@ -129,7 +130,7 @@ public class MetadataRewriter1_11To1_10 extends EntityRewriter<Protocol1_11To1_1
|
|||||||
tracker.addHologram(entityId);
|
tracker.addHologram(entityId);
|
||||||
try {
|
try {
|
||||||
// Send movement
|
// 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.VAR_INT, entityId);
|
||||||
wrapper.write(Type.SHORT, (short) 0);
|
wrapper.write(Type.SHORT, (short) 0);
|
||||||
wrapper.write(Type.SHORT, (short) (128D * (-Via.getConfig().getHologramYOffset() * 32D)));
|
wrapper.write(Type.SHORT, (short) (128D * (-Via.getConfig().getHologramYOffset() * 32D)));
|
||||||
|
@ -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.minecraft.chunks.ChunkSection;
|
||||||
import com.viaversion.viaversion.api.protocol.packet.PacketWrapper;
|
import com.viaversion.viaversion.api.protocol.packet.PacketWrapper;
|
||||||
import com.viaversion.viaversion.api.type.Type;
|
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.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.BlockConnectionProvider;
|
||||||
import com.viaversion.viaversion.protocols.protocol1_13to1_12_2.blockconnections.providers.PacketBlockConnectionProvider;
|
import com.viaversion.viaversion.protocols.protocol1_13to1_12_2.blockconnections.providers.PacketBlockConnectionProvider;
|
||||||
@ -62,7 +63,7 @@ public class ConnectionData {
|
|||||||
if (handler == null) continue;
|
if (handler == null) continue;
|
||||||
|
|
||||||
int newBlockState = handler.connect(user, pos, blockState);
|
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.POSITION, pos);
|
||||||
blockUpdatePacket.write(Type.VAR_INT, newBlockState);
|
blockUpdatePacket.write(Type.VAR_INT, newBlockState);
|
||||||
try {
|
try {
|
||||||
@ -135,7 +136,7 @@ public class ConnectionData {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (!updates.isEmpty()) {
|
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, chunkX + chunkDeltaX);
|
||||||
wrapper.write(Type.INT, chunkZ + chunkDeltaZ);
|
wrapper.write(Type.INT, chunkZ + chunkDeltaZ);
|
||||||
wrapper.write(Type.BLOCK_CHANGE_RECORD_ARRAY, updates.toArray(EMPTY_RECORDS));
|
wrapper.write(Type.BLOCK_CHANGE_RECORD_ARRAY, updates.toArray(EMPTY_RECORDS));
|
||||||
|
@ -25,6 +25,7 @@ import com.viaversion.viaversion.api.minecraft.Position;
|
|||||||
import com.viaversion.viaversion.api.platform.providers.Provider;
|
import com.viaversion.viaversion.api.platform.providers.Provider;
|
||||||
import com.viaversion.viaversion.api.protocol.packet.PacketWrapper;
|
import com.viaversion.viaversion.api.protocol.packet.PacketWrapper;
|
||||||
import com.viaversion.viaversion.api.type.Type;
|
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.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.BannerHandler;
|
||||||
import com.viaversion.viaversion.protocols.protocol1_13to1_12_2.providers.blockentities.BedHandler;
|
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 {
|
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.POSITION, position);
|
||||||
wrapper.write(Type.VAR_INT, blockId);
|
wrapper.write(Type.VAR_INT, blockId);
|
||||||
|
|
||||||
|
@ -21,6 +21,7 @@ import com.viaversion.viaversion.api.connection.StorableObject;
|
|||||||
import com.viaversion.viaversion.api.connection.UserConnection;
|
import com.viaversion.viaversion.api.connection.UserConnection;
|
||||||
import com.viaversion.viaversion.api.protocol.packet.PacketWrapper;
|
import com.viaversion.viaversion.api.protocol.packet.PacketWrapper;
|
||||||
import com.viaversion.viaversion.api.type.Type;
|
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;
|
import com.viaversion.viaversion.protocols.protocol1_13to1_12_2.Protocol1_13To1_12_2;
|
||||||
|
|
||||||
public class TabCompleteTracker implements StorableObject {
|
public class TabCompleteTracker implements StorableObject {
|
||||||
@ -31,7 +32,7 @@ public class TabCompleteTracker implements StorableObject {
|
|||||||
|
|
||||||
public void sendPacketToServer(UserConnection connection) {
|
public void sendPacketToServer(UserConnection connection) {
|
||||||
if (lastTabComplete == null || timeToSend > System.currentTimeMillis()) return;
|
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.STRING, lastTabComplete);
|
||||||
wrapper.write(Type.BOOLEAN, false);
|
wrapper.write(Type.BOOLEAN, false);
|
||||||
wrapper.write(Type.OPTIONAL_POSITION, null);
|
wrapper.write(Type.OPTIONAL_POSITION, null);
|
||||||
|
@ -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.protocol.packet.PacketWrapper;
|
||||||
import com.viaversion.viaversion.api.type.Type;
|
import com.viaversion.viaversion.api.type.Type;
|
||||||
import com.viaversion.viaversion.api.type.types.Particle;
|
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.Protocol1_14To1_13_2;
|
||||||
import com.viaversion.viaversion.protocols.protocol1_14to1_13_2.storage.EntityTracker1_14;
|
import com.viaversion.viaversion.protocols.protocol1_14to1_13_2.storage.EntityTracker1_14;
|
||||||
import com.viaversion.viaversion.rewriter.EntityRewriter;
|
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);
|
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, entityId);
|
||||||
equipmentPacket.write(Type.VAR_INT, 4);
|
equipmentPacket.write(Type.VAR_INT, 4);
|
||||||
equipmentPacket.write(Type.FLAT_VAR_INT_ITEM, armorItem);
|
equipmentPacket.write(Type.FLAT_VAR_INT_ITEM, armorItem);
|
||||||
|
@ -25,6 +25,7 @@ import com.viaversion.viaversion.api.minecraft.Position;
|
|||||||
import com.viaversion.viaversion.api.protocol.packet.PacketWrapper;
|
import com.viaversion.viaversion.api.protocol.packet.PacketWrapper;
|
||||||
import com.viaversion.viaversion.api.type.Type;
|
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_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.HashMap;
|
||||||
import java.util.List;
|
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 {
|
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.POSITION, pos);
|
||||||
wrapper.write(Type.UNSIGNED_BYTE, id);
|
wrapper.write(Type.UNSIGNED_BYTE, id);
|
||||||
wrapper.write(Type.NBT, tag);
|
wrapper.write(Type.NBT, tag);
|
||||||
|
@ -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_8;
|
||||||
import com.viaversion.viaversion.api.type.types.version.Types1_9;
|
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_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.ItemRewriter;
|
||||||
import com.viaversion.viaversion.protocols.protocol1_9to1_8.Protocol1_9To1_8;
|
import com.viaversion.viaversion.protocols.protocol1_9to1_8.Protocol1_9To1_8;
|
||||||
import com.viaversion.viaversion.protocols.protocol1_9to1_8.metadata.MetadataRewriter1_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 {
|
public void handle(PacketWrapper wrapper) throws Exception {
|
||||||
short item = wrapper.read(Type.SHORT);
|
short item = wrapper.read(Type.SHORT);
|
||||||
if (item != 0) {
|
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, wrapper.get(Type.VAR_INT, 0));
|
||||||
packet.write(Type.VAR_INT, 0);
|
packet.write(Type.VAR_INT, 0);
|
||||||
packet.write(Type.ITEM, new DataItem(item, (byte) 1, (short) 0, null));
|
packet.write(Type.ITEM, new DataItem(item, (byte) 1, (short) 0, null));
|
||||||
|
@ -136,7 +136,7 @@ public class WorldPackets {
|
|||||||
Chunk1_9to1_8Type type = new Chunk1_9to1_8Type(clientChunks);
|
Chunk1_9to1_8Type type = new Chunk1_9to1_8Type(clientChunks);
|
||||||
Chunk1_8 chunk = (Chunk1_8) wrapper.read(type);
|
Chunk1_8 chunk = (Chunk1_8) wrapper.read(type);
|
||||||
if (chunk.isUnloadPacket()) {
|
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.getX());
|
||||||
wrapper.write(Type.INT, chunk.getZ());
|
wrapper.write(Type.INT, chunk.getZ());
|
||||||
@ -427,7 +427,7 @@ public class WorldPackets {
|
|||||||
Optional<CompoundTag> tag = provider.get(wrapper.user(), pos);
|
Optional<CompoundTag> tag = provider.get(wrapper.user(), pos);
|
||||||
// Send the Update Block Entity packet if present
|
// Send the Update Block Entity packet if present
|
||||||
if (tag.isPresent()) {
|
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.POSITION, pos);
|
||||||
updateBlockEntity.write(Type.UNSIGNED_BYTE, (short) 2);
|
updateBlockEntity.write(Type.UNSIGNED_BYTE, (short) 2);
|
||||||
|
@ -23,6 +23,7 @@ import com.viaversion.viaversion.api.minecraft.Position;
|
|||||||
import com.viaversion.viaversion.api.platform.providers.Provider;
|
import com.viaversion.viaversion.api.platform.providers.Provider;
|
||||||
import com.viaversion.viaversion.api.protocol.packet.PacketWrapper;
|
import com.viaversion.viaversion.api.protocol.packet.PacketWrapper;
|
||||||
import com.viaversion.viaversion.api.type.Type;
|
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.Protocol1_9To1_8;
|
||||||
import com.viaversion.viaversion.protocols.protocol1_9to1_8.storage.CommandBlockStorage;
|
import com.viaversion.viaversion.protocols.protocol1_9to1_8.storage.CommandBlockStorage;
|
||||||
import com.viaversion.viaversion.protocols.protocol1_9to1_8.storage.EntityTracker1_9;
|
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 {
|
public void sendPermission(UserConnection user) throws Exception {
|
||||||
if (!isEnabled())
|
if (!isEnabled())
|
||||||
return;
|
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);
|
EntityTracker1_9 tracker = user.getEntityTracker(Protocol1_9To1_8.class);
|
||||||
wrapper.write(Type.INT, tracker.getProvidedEntityId()); // Entity ID
|
wrapper.write(Type.INT, tracker.getProvidedEntityId()); // Entity ID
|
||||||
|
@ -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.Type;
|
||||||
import com.viaversion.viaversion.api.type.types.version.Types1_9;
|
import com.viaversion.viaversion.api.type.types.version.Types1_9;
|
||||||
import com.viaversion.viaversion.data.entity.EntityTrackerBase;
|
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.Protocol1_9To1_8;
|
||||||
import com.viaversion.viaversion.protocols.protocol1_9to1_8.chat.GameMode;
|
import com.viaversion.viaversion.protocols.protocol1_9to1_8.chat.GameMode;
|
||||||
import com.viaversion.viaversion.protocols.protocol1_9to1_8.metadata.MetadataRewriter1_9To1_8;
|
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) {
|
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, entityID);
|
||||||
wrapper.write(Type.VAR_INT, 1); // slot
|
wrapper.write(Type.VAR_INT, 1); // slot
|
||||||
wrapper.write(Type.ITEM, this.itemInSecondHand = item);
|
wrapper.write(Type.ITEM, this.itemInSecondHand = item);
|
||||||
@ -234,7 +235,7 @@ public class EntityTracker1_9 extends EntityTrackerBase {
|
|||||||
knownHolograms.add(entityId);
|
knownHolograms.add(entityId);
|
||||||
try {
|
try {
|
||||||
// Send movement
|
// 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.VAR_INT, entityId);
|
||||||
wrapper.write(Type.SHORT, (short) 0);
|
wrapper.write(Type.SHORT, (short) 0);
|
||||||
wrapper.write(Type.SHORT, (short) (128D * (Via.getConfig().getHologramYOffset() * 32D)));
|
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) {
|
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
|
wrapper.write(Type.STRING, "viaversion"); // Use viaversion as name
|
||||||
if (add) {
|
if (add) {
|
||||||
// add
|
// add
|
||||||
@ -340,7 +341,7 @@ public class EntityTracker1_9 extends EntityTrackerBase {
|
|||||||
public void sendMetadataBuffer(int entityId) {
|
public void sendMetadataBuffer(int entityId) {
|
||||||
List<Metadata> metadataList = metadataBuffer.get(entityId);
|
List<Metadata> metadataList = metadataBuffer.get(entityId);
|
||||||
if (metadataList != null) {
|
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(Type.VAR_INT, entityId);
|
||||||
wrapper.write(Types1_9.METADATA_LIST, metadataList);
|
wrapper.write(Types1_9.METADATA_LIST, metadataList);
|
||||||
Via.getManager().getProtocolManager().getProtocol(Protocol1_9To1_8.class).get(MetadataRewriter1_9To1_8.class)
|
Via.getManager().getProtocolManager().getProtocol(Protocol1_9To1_8.class).get(MetadataRewriter1_9To1_8.class)
|
||||||
|
@ -34,7 +34,7 @@ import java.util.NoSuchElementException;
|
|||||||
* @param <E> List Type
|
* @param <E> List Type
|
||||||
* @deprecated get rid of this at some point
|
* @deprecated get rid of this at some point
|
||||||
*/
|
*/
|
||||||
@Deprecated
|
@Deprecated/*(forRemoval = true)*/
|
||||||
public class ConcurrentList<E> extends ArrayList<E> {
|
public class ConcurrentList<E> extends ArrayList<E> {
|
||||||
|
|
||||||
private final Object lock = new Object();
|
private final Object lock = new Object();
|
||||||
|
@ -25,7 +25,7 @@ import java.util.ListIterator;
|
|||||||
/**
|
/**
|
||||||
* @deprecated scary
|
* @deprecated scary
|
||||||
*/
|
*/
|
||||||
@Deprecated
|
@Deprecated/*(forRemoval = true)*/
|
||||||
public abstract class ListWrapper implements List {
|
public abstract class ListWrapper implements List {
|
||||||
private final List list;
|
private final List list;
|
||||||
|
|
||||||
|
@ -17,6 +17,7 @@
|
|||||||
*/
|
*/
|
||||||
package com.viaversion.viaversion.sponge.listeners.protocol1_9to1_8.sponge4;
|
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.Sponge;
|
||||||
import org.spongepowered.api.entity.living.player.Player;
|
import org.spongepowered.api.entity.living.player.Player;
|
||||||
import org.spongepowered.api.event.Listener;
|
import org.spongepowered.api.event.Listener;
|
||||||
@ -60,7 +61,7 @@ public class Sponge4ArmorListener extends ViaListener {
|
|||||||
armor += calculate(player.getLeggings());
|
armor += calculate(player.getLeggings());
|
||||||
armor += calculate(player.getBoots());
|
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 {
|
try {
|
||||||
wrapper.write(Type.VAR_INT, getEntityId(player)); // Player ID
|
wrapper.write(Type.VAR_INT, getEntityId(player)); // Player ID
|
||||||
wrapper.write(Type.INT, 1); // only 1 property
|
wrapper.write(Type.INT, 1); // only 1 property
|
||||||
|
@ -21,6 +21,7 @@ import com.viaversion.viaversion.SpongePlugin;
|
|||||||
import com.viaversion.viaversion.api.Via;
|
import com.viaversion.viaversion.api.Via;
|
||||||
import com.viaversion.viaversion.api.protocol.packet.PacketWrapper;
|
import com.viaversion.viaversion.api.protocol.packet.PacketWrapper;
|
||||||
import com.viaversion.viaversion.api.type.Type;
|
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.Protocol1_9To1_8;
|
||||||
import com.viaversion.viaversion.sponge.listeners.ViaSpongeListener;
|
import com.viaversion.viaversion.sponge.listeners.ViaSpongeListener;
|
||||||
import org.spongepowered.api.entity.living.player.Player;
|
import org.spongepowered.api.entity.living.player.Player;
|
||||||
@ -64,7 +65,7 @@ public class DeathListener extends ViaSpongeListener {
|
|||||||
Via.getPlatform().runSync(new Runnable() {
|
Via.getPlatform().runSync(new Runnable() {
|
||||||
@Override
|
@Override
|
||||||
public void run() {
|
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 {
|
try {
|
||||||
int entityId = getEntityId(p);
|
int entityId = getEntityId(p);
|
||||||
wrapper.write(Type.VAR_INT, 2); // Event - Entity dead
|
wrapper.write(Type.VAR_INT, 2); // Event - Entity dead
|
||||||
|
@ -22,6 +22,7 @@ import com.viaversion.viaversion.api.Via;
|
|||||||
import com.viaversion.viaversion.api.protocol.packet.PacketWrapper;
|
import com.viaversion.viaversion.api.protocol.packet.PacketWrapper;
|
||||||
import com.viaversion.viaversion.api.type.Type;
|
import com.viaversion.viaversion.api.type.Type;
|
||||||
import com.viaversion.viaversion.protocols.protocol1_9to1_8.ArmorType;
|
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.protocols.protocol1_9to1_8.Protocol1_9To1_8;
|
||||||
import com.viaversion.viaversion.sponge.listeners.ViaSpongeListener;
|
import com.viaversion.viaversion.sponge.listeners.ViaSpongeListener;
|
||||||
import org.spongepowered.api.data.type.HandTypes;
|
import org.spongepowered.api.data.type.HandTypes;
|
||||||
@ -58,7 +59,7 @@ public class Sponge5ArmorListener extends ViaSpongeListener {
|
|||||||
armor += calculate(player.getLeggings());
|
armor += calculate(player.getLeggings());
|
||||||
armor += calculate(player.getBoots());
|
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 {
|
try {
|
||||||
wrapper.write(Type.VAR_INT, getEntityId(player)); // Player ID
|
wrapper.write(Type.VAR_INT, getEntityId(player)); // Player ID
|
||||||
wrapper.write(Type.INT, 1); // only 1 property
|
wrapper.write(Type.INT, 1); // only 1 property
|
||||||
|
@ -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.PacketWrapper;
|
||||||
import com.viaversion.viaversion.api.protocol.packet.State;
|
import com.viaversion.viaversion.api.protocol.packet.State;
|
||||||
import com.viaversion.viaversion.api.type.Type;
|
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.Protocol1_9To1_8;
|
||||||
import com.viaversion.viaversion.protocols.protocol1_9to1_8.providers.MovementTransmitterProvider;
|
import com.viaversion.viaversion.protocols.protocol1_9to1_8.providers.MovementTransmitterProvider;
|
||||||
import com.viaversion.viaversion.protocols.protocol1_9to1_8.storage.MovementTracker;
|
import com.viaversion.viaversion.protocols.protocol1_9to1_8.storage.MovementTracker;
|
||||||
@ -38,7 +39,7 @@ public class VelocityMovementTransmitter extends MovementTransmitterProvider {
|
|||||||
|
|
||||||
public void sendPlayer(UserConnection userConnection) {
|
public void sendPlayer(UserConnection userConnection) {
|
||||||
if (userConnection.getProtocolInfo().getState() == State.PLAY) {
|
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);
|
MovementTracker tracker = userConnection.get(MovementTracker.class);
|
||||||
wrapper.write(Type.BOOLEAN, tracker.isGround());
|
wrapper.write(Type.BOOLEAN, tracker.isGround());
|
||||||
try {
|
try {
|
||||||
|
Laden…
In neuem Issue referenzieren
Einen Benutzer sperren