3
0
Mirror von https://github.com/ViaVersion/ViaVersion.git synchronisiert 2024-11-03 14:50:30 +01:00

Rename PacketType methods

Just in case a packet with some magic id is going to be added, since the enum ordinal and name methods cannot be overridden
Dieser Commit ist enthalten in:
KennyTV 2021-05-02 11:14:38 +02:00
Ursprung d183d76c47
Commit af0cf1d3f2
Es konnte kein GPG-Schlüssel zu dieser Signatur gefunden werden
GPG-Schlüssel-ID: 6BE3B555EBC5982B
29 geänderte Dateien mit 292 neuen und 56 gelöschten Zeilen

Datei anzeigen

@ -80,12 +80,12 @@ public abstract class AbstractProtocol<C1 extends ClientboundPacketType, C2 exte
ClientboundPacketType[] newConstants = newClientboundPacketEnum.getEnumConstants();
Map<String, ClientboundPacketType> newClientboundPackets = new HashMap<>(newConstants.length);
for (ClientboundPacketType newConstant : newConstants) {
newClientboundPackets.put(newConstant.name(), newConstant);
newClientboundPackets.put(newConstant.getName(), newConstant);
}
for (ClientboundPacketType packet : oldClientboundPacketEnum.getEnumConstants()) {
ClientboundPacketType mappedPacket = newClientboundPackets.get(packet.name());
int oldId = packet.ordinal();
ClientboundPacketType mappedPacket = newClientboundPackets.get(packet.getName());
int oldId = packet.getId();
if (mappedPacket == null) {
// Packet doesn't exist on new client
Preconditions.checkArgument(hasRegisteredClientbound(State.PLAY, oldId),
@ -93,7 +93,7 @@ public abstract class AbstractProtocol<C1 extends ClientboundPacketType, C2 exte
continue;
}
int newId = mappedPacket.ordinal();
int newId = mappedPacket.getId();
if (!hasRegisteredClientbound(State.PLAY, oldId)) {
registerClientbound(State.PLAY, oldId, newId);
}
@ -104,12 +104,12 @@ public abstract class AbstractProtocol<C1 extends ClientboundPacketType, C2 exte
ServerboundPacketType[] oldConstants = oldServerboundPacketEnum.getEnumConstants();
Map<String, ServerboundPacketType> oldServerboundConstants = new HashMap<>(oldConstants.length);
for (ServerboundPacketType oldConstant : oldConstants) {
oldServerboundConstants.put(oldConstant.name(), oldConstant);
oldServerboundConstants.put(oldConstant.getName(), oldConstant);
}
for (ServerboundPacketType packet : newServerboundPacketEnum.getEnumConstants()) {
ServerboundPacketType mappedPacket = oldServerboundConstants.get(packet.name());
int newId = packet.ordinal();
ServerboundPacketType mappedPacket = oldServerboundConstants.get(packet.getName());
int newId = packet.getId();
if (mappedPacket == null) {
// Packet doesn't exist on old server
Preconditions.checkArgument(hasRegisteredServerbound(State.PLAY, newId),
@ -117,7 +117,7 @@ public abstract class AbstractProtocol<C1 extends ClientboundPacketType, C2 exte
continue;
}
int oldId = mappedPacket.ordinal();
int oldId = mappedPacket.getId();
if (!hasRegisteredServerbound(State.PLAY, newId)) {
registerServerbound(State.PLAY, oldId, newId);
}
@ -192,11 +192,11 @@ public abstract class AbstractProtocol<C1 extends ClientboundPacketType, C2 exte
checkPacketType(packetType, packetType.getClass() == oldClientboundPacketEnum);
ClientboundPacketType mappedPacket = oldClientboundPacketEnum == newClientboundPacketEnum ? packetType
: Arrays.stream(newClientboundPacketEnum.getEnumConstants()).filter(en -> en.name().equals(packetType.name())).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!");
int oldId = packetType.ordinal();
int newId = mappedPacket.ordinal();
int oldId = packetType.getId();
int newId = mappedPacket.getId();
registerClientbound(State.PLAY, oldId, newId, packetRemapper);
}
@ -205,12 +205,12 @@ public abstract class AbstractProtocol<C1 extends ClientboundPacketType, C2 exte
checkPacketType(packetType, packetType.getClass() == oldClientboundPacketEnum);
checkPacketType(mappedPacketType, mappedPacketType == null || mappedPacketType.getClass() == newClientboundPacketEnum);
registerClientbound(State.PLAY, packetType.ordinal(), mappedPacketType != null ? mappedPacketType.ordinal() : -1, packetRemapper);
registerClientbound(State.PLAY, packetType.getId(), mappedPacketType != null ? mappedPacketType.getId() : -1, packetRemapper);
}
@Override
public void cancelClientbound(C1 packetType) {
cancelClientbound(State.PLAY, packetType.ordinal(), packetType.ordinal());
cancelClientbound(State.PLAY, packetType.getId(), packetType.getId());
}
@Override
@ -218,11 +218,11 @@ public abstract class AbstractProtocol<C1 extends ClientboundPacketType, C2 exte
checkPacketType(packetType, packetType.getClass() == newServerboundPacketEnum);
ServerboundPacketType mappedPacket = oldServerboundPacketEnum == newServerboundPacketEnum ? packetType
: Arrays.stream(oldServerboundPacketEnum.getEnumConstants()).filter(en -> en.name().equals(packetType.name())).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!");
int oldId = mappedPacket.ordinal();
int newId = packetType.ordinal();
int oldId = mappedPacket.getId();
int newId = packetType.getId();
registerServerbound(State.PLAY, oldId, newId, packetRemapper);
}
@ -231,13 +231,13 @@ public abstract class AbstractProtocol<C1 extends ClientboundPacketType, C2 exte
checkPacketType(packetType, packetType.getClass() == newServerboundPacketEnum);
checkPacketType(mappedPacketType, mappedPacketType == null || mappedPacketType.getClass() == oldServerboundPacketEnum);
registerServerbound(State.PLAY, mappedPacketType != null ? mappedPacketType.ordinal() : -1, packetType.ordinal(), packetRemapper);
registerServerbound(State.PLAY, mappedPacketType != null ? mappedPacketType.getId() : -1, packetType.getId(), packetRemapper);
}
@Override
public void cancelServerbound(S2 packetType) {
Preconditions.checkArgument(packetType.getClass() == newServerboundPacketEnum);
cancelServerbound(State.PLAY, -1, packetType.ordinal());
cancelServerbound(State.PLAY, -1, packetType.getId());
}

Datei anzeigen

@ -34,5 +34,16 @@ import com.viaversion.viaversion.api.protocol.packet.ServerboundPacketType;
public interface SimpleProtocol extends Protocol<SimpleProtocol.DummyPacketTypes, SimpleProtocol.DummyPacketTypes, SimpleProtocol.DummyPacketTypes, SimpleProtocol.DummyPacketTypes> {
enum DummyPacketTypes implements ClientboundPacketType, ServerboundPacketType {
;
@Override
public int getId() {
return ordinal();
}
@Override
public String getName() {
return name();
}
}
}

Datei anzeigen

@ -30,17 +30,17 @@ package com.viaversion.viaversion.api.protocol.packet;
*/
public interface PacketType {
/**
* Returns the packet id for the implemented protocol.
*
* @return packet id for the implemented protocol
*/
int getId();
/**
* Returns the name of the packet, to be consistent over multiple versions.
*
* @return name of the packet
*/
String name();
/**
* Returns the ordinal, being the packet id for the implemented protocol.
*
* @return packet id for the implemented protocol
*/
int ordinal();
String getName();
}

Datei anzeigen

@ -46,7 +46,7 @@ public interface PacketWrapper {
* @return new packet wrapper
*/
static PacketWrapper create(PacketType packetType, UserConnection connection) {
return create(packetType.ordinal(), null, connection);
return create(packetType.getId(), null, connection);
}
/**
@ -58,7 +58,7 @@ public interface PacketWrapper {
* @return new packet wrapper
*/
static PacketWrapper create(PacketType packetType, @Nullable ByteBuf inputBuffer, UserConnection connection) {
return create(packetType.ordinal(), inputBuffer, connection);
return create(packetType.getId(), inputBuffer, connection);
}
/**
@ -320,11 +320,26 @@ public interface PacketWrapper {
sendToServer(packetProtocol, true);
}
/**
* Returns the packet id.
*
* @return packet id
*/
int getId();
void setId(int id);
/**
* Sets the packet id. If set to -1, it will not be written to the buffer with {@link #writeToBuffer(ByteBuf)}.
*
* @param packetType packet type
*/
default void setId(PacketType packetType) {
setId(packetType.ordinal());
setId(packetType.getId());
}
/**
* Sets the packet id. If set to -1, it will not be written to the buffer with {@link #writeToBuffer(ByteBuf)}.
*
* @param id packet id
*/
void setId(int id);
}

Datei anzeigen

@ -322,7 +322,7 @@ public class PacketWrapperImpl implements PacketWrapper {
@Override
public PacketWrapperImpl create(PacketType packetType) {
return new PacketWrapperImpl(packetType.ordinal(), null, user());
return new PacketWrapperImpl(packetType.getId(), null, user());
}
@Override

Datei anzeigen

@ -100,5 +100,15 @@ public enum ClientboundPackets1_12_1 implements ClientboundPacketType {
ENTITY_TELEPORT, // 0x4C
ADVANCEMENTS, // 0x4D
ENTITY_PROPERTIES, // 0x4E
ENTITY_EFFECT, // 0x4F
ENTITY_EFFECT; // 0x4F
@Override
public int getId() {
return ordinal();
}
@Override
public String getName() {
return name();
}
}

Datei anzeigen

@ -53,5 +53,15 @@ public enum ServerboundPackets1_12_1 implements ServerboundPacketType {
ANIMATION, // 0x1D
SPECTATE, // 0x1E
PLAYER_BLOCK_PLACEMENT, // 0x1F
USE_ITEM, // 0x20
USE_ITEM; // 0x20
@Override
public int getId() {
return ordinal();
}
@Override
public String getName() {
return name();
}
}

Datei anzeigen

@ -99,5 +99,15 @@ public enum ClientboundPackets1_12 implements ClientboundPacketType {
ENTITY_TELEPORT, // 0x4B
ADVANCEMENTS, // 0x4C
ENTITY_PROPERTIES, // 0x4D
ENTITY_EFFECT, // 0x4E
ENTITY_EFFECT; // 0x4E
@Override
public int getId() {
return ordinal();
}
@Override
public String getName() {
return name();
}
}

Datei anzeigen

@ -53,5 +53,15 @@ public enum ServerboundPackets1_12 implements ServerboundPacketType {
ANIMATION, // 0x1D
SPECTATE, // 0x1E
PLAYER_BLOCK_PLACEMENT, // 0x1F
USE_ITEM, // 0x20
USE_ITEM; // 0x20
@Override
public int getId() {
return ordinal();
}
@Override
public String getName() {
return name();
}
}

Datei anzeigen

@ -106,5 +106,15 @@ public enum ClientboundPackets1_13 implements ClientboundPacketType {
ENTITY_PROPERTIES, // 0x52
ENTITY_EFFECT, // 0x53
DECLARE_RECIPES, // 0x54
TAGS, // 0x55
TAGS; // 0x55
@Override
public int getId() {
return ordinal();
}
@Override
public String getName() {
return name();
}
}

Datei anzeigen

@ -63,5 +63,15 @@ public enum ServerboundPackets1_13 implements ServerboundPacketType {
ANIMATION, // 0x27
SPECTATE, // 0x28
PLAYER_BLOCK_PLACEMENT, // 0x29
USE_ITEM, // 0x2A
USE_ITEM; // 0x2A
@Override
public int getId() {
return ordinal();
}
@Override
public String getName() {
return name();
}
}

Datei anzeigen

@ -113,5 +113,15 @@ public enum ClientboundPackets1_14 implements ClientboundPacketType {
ENTITY_EFFECT, // 0x59
DECLARE_RECIPES, // 0x5A
TAGS, // 0x5B
ACKNOWLEDGE_PLAYER_DIGGING, // 0x5C
ACKNOWLEDGE_PLAYER_DIGGING; // 0x5C
@Override
public int getId() {
return ordinal();
}
@Override
public String getName() {
return name();
}
}

Datei anzeigen

@ -66,5 +66,15 @@ public enum ServerboundPackets1_14 implements ServerboundPacketType {
ANIMATION, // 0x2A
SPECTATE, // 0x2B
PLAYER_BLOCK_PLACEMENT, // 0x2C
USE_ITEM, // 0x2D
USE_ITEM; // 0x2D
@Override
public int getId() {
return ordinal();
}
@Override
public String getName() {
return name();
}
}

Datei anzeigen

@ -113,5 +113,15 @@ public enum ClientboundPackets1_15 implements ClientboundPacketType {
ENTITY_PROPERTIES, // 0x59
ENTITY_EFFECT, // 0x5A
DECLARE_RECIPES, // 0x5B
TAGS, // 0x5C
TAGS; // 0x5C
@Override
public int getId() {
return ordinal();
}
@Override
public String getName() {
return name();
}
}

Datei anzeigen

@ -112,5 +112,15 @@ public enum ClientboundPackets1_16_2 implements ClientboundPacketType {
ENTITY_PROPERTIES, // 0x58
ENTITY_EFFECT, // 0x59
DECLARE_RECIPES, // 0x5A
TAGS, // 0x5B
TAGS; // 0x5B
@Override
public int getId() {
return ordinal();
}
@Override
public String getName() {
return name();
}
}

Datei anzeigen

@ -68,5 +68,15 @@ public enum ServerboundPackets1_16_2 implements ServerboundPacketType {
ANIMATION, // 0x2C
SPECTATE, // 0x2D
PLAYER_BLOCK_PLACEMENT, // 0x2E
USE_ITEM, // 0x2F
USE_ITEM; // 0x2F
@Override
public int getId() {
return ordinal();
}
@Override
public String getName() {
return name();
}
}

Datei anzeigen

@ -112,5 +112,15 @@ public enum ClientboundPackets1_16 implements ClientboundPacketType {
ENTITY_PROPERTIES, // 0x58
ENTITY_EFFECT, // 0x59
DECLARE_RECIPES, // 0x5A
TAGS, // 0x5B
TAGS; // 0x5B
@Override
public int getId() {
return ordinal();
}
@Override
public String getName() {
return name();
}
}

Datei anzeigen

@ -67,5 +67,15 @@ public enum ServerboundPackets1_16 implements ServerboundPacketType {
ANIMATION, // 0x2B
SPECTATE, // 0x2C
PLAYER_BLOCK_PLACEMENT, // 0x2D
USE_ITEM, // 0x2E
USE_ITEM; // 0x2E
@Override
public int getId() {
return ordinal();
}
@Override
public String getName() {
return name();
}
}

Datei anzeigen

@ -122,5 +122,15 @@ public enum ClientboundPackets1_17 implements ClientboundPacketType {
ENTITY_PROPERTIES, // 0x62
ENTITY_EFFECT, // 0x63
DECLARE_RECIPES, // 0x64
TAGS, // 0x65
TAGS; // 0x65
@Override
public int getId() {
return ordinal();
}
@Override
public String getName() {
return name();
}
}

Datei anzeigen

@ -159,7 +159,7 @@ public class Protocol1_17To1_16_4 extends AbstractProtocol<ClientboundPackets1_1
throw new IllegalArgumentException("Invalid title type received: " + type);
}
wrapper.setId(packetType.ordinal());
wrapper.setId(packetType.getId());
});
}
});

Datei anzeigen

@ -67,5 +67,15 @@ public enum ServerboundPackets1_17 implements ServerboundPacketType {
ANIMATION, // 0x2B
SPECTATE, // 0x2C
PLAYER_BLOCK_PLACEMENT, // 0x2D
USE_ITEM, // 0x2E
USE_ITEM; // 0x2E
@Override
public int getId() {
return ordinal();
}
@Override
public String getName() {
return name();
}
}

Datei anzeigen

@ -109,7 +109,7 @@ public class EntityPackets {
throw new IllegalArgumentException("Invalid combat type received: " + type);
}
wrapper.setId(packetType.ordinal());
wrapper.setId(packetType.getId());
});
}
});

Datei anzeigen

@ -83,7 +83,7 @@ public class WorldPackets {
throw new IllegalArgumentException("Invalid world border type received: " + type);
}
wrapper.setId(packetType.ordinal());
wrapper.setId(packetType.getId());
});
}
});

Datei anzeigen

@ -94,5 +94,15 @@ public enum ClientboundPackets1_8 implements ClientboundPacketType {
SET_COMPRESSION, // 0x46
TAB_LIST, // 0x47
RESOURCE_PACK, // 0x48
UPDATE_ENTITY_NBT, // 0x49
UPDATE_ENTITY_NBT; // 0x49
@Override
public int getId() {
return ordinal();
}
@Override
public String getName() {
return name();
}
}

Datei anzeigen

@ -46,5 +46,15 @@ public enum ServerboundPackets1_8 implements ServerboundPacketType {
CLIENT_STATUS, // 0x16
PLUGIN_MESSAGE, // 0x17
SPECTATE, // 0x18
RESOURCE_PACK_STATUS, // 0x19
RESOURCE_PACK_STATUS; // 0x19
@Override
public int getId() {
return ordinal();
}
@Override
public String getName() {
return name();
}
}

Datei anzeigen

@ -96,5 +96,15 @@ public enum ClientboundPackets1_9_3 implements ClientboundPacketType {
COLLECT_ITEM, // 0x4A
ENTITY_TELEPORT, // 0x4B
ENTITY_PROPERTIES, // 0x4C
ENTITY_EFFECT, // 0x4D
ENTITY_EFFECT; // 0x4D
@Override
public int getId() {
return ordinal();
}
@Override
public String getName() {
return name();
}
}

Datei anzeigen

@ -50,5 +50,15 @@ public enum ServerboundPackets1_9_3 implements ServerboundPacketType {
ANIMATION, // 0x1A
SPECTATE, // 0x1B
PLAYER_BLOCK_PLACEMENT, // 0x1C
USE_ITEM, // 0x1D
USE_ITEM; // 0x1D
@Override
public int getId() {
return ordinal();
}
@Override
public String getName() {
return name();
}
}

Datei anzeigen

@ -97,5 +97,15 @@ public enum ClientboundPackets1_9 implements ClientboundPacketType {
COLLECT_ITEM, // 0x49
ENTITY_TELEPORT, // 0x4A
ENTITY_PROPERTIES, // 0x4B
ENTITY_EFFECT, // 0x4C
ENTITY_EFFECT; // 0x4C
@Override
public int getId() {
return ordinal();
}
@Override
public String getName() {
return name();
}
}

Datei anzeigen

@ -50,5 +50,15 @@ public enum ServerboundPackets1_9 implements ServerboundPacketType {
ANIMATION, // 0x1A
SPECTATE, // 0x1B
PLAYER_BLOCK_PLACEMENT, // 0x1C
USE_ITEM, // 0x1D
USE_ITEM; // 0x1D
@Override
public int getId() {
return ordinal();
}
@Override
public String getName() {
return name();
}
}