CU
- unmapped clientbound packet typeCM
- mapped clientbound packet typeSM
- mapped serverbound packet typeSU
- unmapped serverbound packet typepublic abstract class AbstractProtocol<CU extends ClientboundPacketType,CM extends ClientboundPacketType,SM extends ServerboundPacketType,SU extends ServerboundPacketType> extends java.lang.Object implements Protocol<CU,CM,SM,SU>
Modifier and Type | Field and Description |
---|---|
protected PacketMappings |
clientboundMappings |
protected java.lang.Class<CM> |
mappedClientboundPacketType |
protected java.lang.Class<SM> |
mappedServerboundPacketType |
protected PacketTypesProvider<CU,CM,SM,SU> |
packetTypesProvider |
protected PacketMappings |
serverboundMappings |
protected java.lang.Class<CU> |
unmappedClientboundPacketType |
protected java.lang.Class<SU> |
unmappedServerboundPacketType |
Modifier | Constructor and Description |
---|---|
protected |
AbstractProtocol()
Deprecated.
|
protected |
AbstractProtocol(@Nullable java.lang.Class<CU> unmappedClientboundPacketType,
@Nullable java.lang.Class<CM> mappedClientboundPacketType,
@Nullable java.lang.Class<SM> mappedServerboundPacketType,
@Nullable java.lang.Class<SU> unmappedServerboundPacketType)
Creates a protocol with automated id mapping if the respective packet type classes are not null.
|
Modifier and Type | Method and Description |
---|---|
protected void |
addEntityTracker(UserConnection connection,
EntityTracker tracker) |
void |
cancelClientbound(CU packetType)
Cancels any clientbound packets from the given type.
|
void |
cancelClientbound(State state,
int unmappedPacketId) |
void |
cancelServerbound(State state,
int unmappedPacketId) |
void |
cancelServerbound(SU packetType)
Cancels any serverbound packets from the given type.
|
protected SU |
configurationAcknowledgedPacket() |
protected PacketMappings |
createClientboundPacketMappings() |
protected PacketTypesProvider<CU,CM,SM,SU> |
createPacketTypesProvider() |
protected PacketMappings |
createServerboundPacketMappings() |
protected @Nullable ServerboundPacketType |
finishConfigurationPacket() |
<T> T |
get(java.lang.Class<T> objectClass)
Returns a cached object by the given type if present.
|
PacketTypesProvider<CU,CM,SM,SU> |
getPacketTypesProvider()
Returns a packet type provider for this protocol to get packet types by id.
|
boolean |
hasRegisteredClientbound(State state,
int unmappedPacketId)
Checks if a clientbound packet has already been registered.
|
boolean |
hasRegisteredServerbound(State state,
int unmappedPacketId)
Checks if a serverbound packet has already been registered.
|
void |
initialize()
Called with
ProtocolManager.registerProtocol(com.viaversion.viaversion.api.protocol.Protocol, com.viaversion.viaversion.api.protocol.version.ProtocolVersion, com.viaversion.viaversion.api.protocol.version.ProtocolVersion) to register packet handlers and automatic packet id remapping. |
void |
loadMappingData()
Loads the protocol's mapping data.
|
protected void |
onMappingDataLoaded()
Called after
loadMappingData() is called; load extra mapping data for the protocol. |
PacketTypesProvider<CU,CM,SM,SU> |
packetTypesProvider() |
void |
put(java.lang.Object object)
Caches an object, retrievable by using
Protocol.get(Class) . |
void |
registerClientbound(CU packetType,
CM mappedPacketType,
@Nullable PacketHandler handler,
boolean override)
Registers a clientbound packet mapping.
|
void |
registerClientbound(CU packetType,
@Nullable PacketHandler handler)
Registers a clientbound protocol and automatically maps it to the new id.
|
void |
registerClientbound(State state,
int unmappedPacketId,
int mappedPacketId,
PacketHandler handler,
boolean override)
Registers a clientbound packet, with id transformation and remapper.
|
protected void |
registerPackets()
Register the packets for this protocol.
|
void |
registerServerbound(State state,
int unmappedPacketId,
int mappedPacketId,
PacketHandler handler,
boolean override)
Registers a serverbound packet, with id transformation and remapper.
|
void |
registerServerbound(SU packetType,
@Nullable PacketHandler handler)
Registers a serverbound protocol and automatically maps it to the server's id.
|
void |
registerServerbound(SU packetType,
SM mappedPacketType,
@Nullable PacketHandler handler,
boolean override)
Registers a serverbound packet mapping.
|
protected void |
throwRemapError(Direction direction,
State state,
int unmappedPacketId,
int mappedPacketId,
InformativeException e) |
static java.lang.String |
toNiceHex(int id) |
java.lang.String |
toString() |
void |
transform(Direction direction,
State state,
PacketWrapper packetWrapper)
Transform a packet using this protocol
|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
cancelClientbound, cancelServerbound, getEntityRewriter, getItemRewriter, getMappingData, hasMappingDataToLoad, hasRegisteredClientbound, hasRegisteredServerbound, init, isBaseProtocol, register, registerClientbound, registerClientbound, registerClientbound, registerClientbound, registerClientbound, registerClientbound, registerClientbound, registerClientbound, registerClientbound, registerServerbound, registerServerbound, registerServerbound, registerServerbound, registerServerbound, registerServerbound, registerServerbound, registerServerbound, registerServerbound
protected final java.lang.Class<CU extends ClientboundPacketType> unmappedClientboundPacketType
protected final java.lang.Class<CM extends ClientboundPacketType> mappedClientboundPacketType
protected final java.lang.Class<SM extends ServerboundPacketType> mappedServerboundPacketType
protected final java.lang.Class<SU extends ServerboundPacketType> unmappedServerboundPacketType
protected final PacketTypesProvider<CU extends ClientboundPacketType,CM extends ClientboundPacketType,SM extends ServerboundPacketType,SU extends ServerboundPacketType> packetTypesProvider
protected final PacketMappings clientboundMappings
protected final PacketMappings serverboundMappings
@Deprecated protected AbstractProtocol()
protected AbstractProtocol(@Nullable java.lang.Class<CU> unmappedClientboundPacketType, @Nullable java.lang.Class<CM> mappedClientboundPacketType, @Nullable java.lang.Class<SM> mappedServerboundPacketType, @Nullable java.lang.Class<SU> unmappedServerboundPacketType)
public final void initialize()
Protocol
ProtocolManager.registerProtocol(com.viaversion.viaversion.api.protocol.Protocol, com.viaversion.viaversion.api.protocol.version.ProtocolVersion, com.viaversion.viaversion.api.protocol.version.ProtocolVersion)
to register packet handlers and automatic packet id remapping.initialize
in interface Protocol<CU extends ClientboundPacketType,CM extends ClientboundPacketType,SM extends ServerboundPacketType,SU extends ServerboundPacketType>
public final void loadMappingData()
Protocol
loadMappingData
in interface Protocol<CU extends ClientboundPacketType,CM extends ClientboundPacketType,SM extends ServerboundPacketType,SU extends ServerboundPacketType>
protected void registerPackets()
protected void onMappingDataLoaded()
loadMappingData()
is called; load extra mapping data for the protocol.
To be overridden if needed.
protected void addEntityTracker(UserConnection connection, EntityTracker tracker)
protected PacketTypesProvider<CU,CM,SM,SU> createPacketTypesProvider()
protected PacketMappings createClientboundPacketMappings()
protected PacketMappings createServerboundPacketMappings()
protected SU configurationAcknowledgedPacket()
protected @Nullable ServerboundPacketType finishConfigurationPacket()
public void registerServerbound(State state, int unmappedPacketId, int mappedPacketId, PacketHandler handler, boolean override)
Protocol
registerServerbound
in interface Protocol<CU extends ClientboundPacketType,CM extends ClientboundPacketType,SM extends ServerboundPacketType,SU extends ServerboundPacketType>
state
- state which the packet is sent in.unmappedPacketId
- unmapped packet idmappedPacketId
- mapped packet idhandler
- packet handleroverride
- whether an existing mapper should be overriddenProtocol.registerServerbound(ServerboundPacketType, ServerboundPacketType, PacketHandler, boolean)
public void cancelServerbound(State state, int unmappedPacketId)
cancelServerbound
in interface Protocol<CU extends ClientboundPacketType,CM extends ClientboundPacketType,SM extends ServerboundPacketType,SU extends ServerboundPacketType>
public void registerClientbound(State state, int unmappedPacketId, int mappedPacketId, PacketHandler handler, boolean override)
Protocol
registerClientbound
in interface Protocol<CU extends ClientboundPacketType,CM extends ClientboundPacketType,SM extends ServerboundPacketType,SU extends ServerboundPacketType>
state
- state which the packet is sent in.unmappedPacketId
- unmapped packet idmappedPacketId
- mapped packet idhandler
- packet handleroverride
- whether an existing mapper should be overriddenProtocol.registerClientbound(ClientboundPacketType, ClientboundPacketType, PacketHandler, boolean)
public void cancelClientbound(State state, int unmappedPacketId)
cancelClientbound
in interface Protocol<CU extends ClientboundPacketType,CM extends ClientboundPacketType,SM extends ServerboundPacketType,SU extends ServerboundPacketType>
public void registerClientbound(CU packetType, @Nullable PacketHandler handler)
Protocol
registerClientbound
in interface Protocol<CU extends ClientboundPacketType,CM extends ClientboundPacketType,SM extends ServerboundPacketType,SU extends ServerboundPacketType>
packetType
- clientbound packet type the server sendshandler
- packet handlerpublic void registerClientbound(CU packetType, CM mappedPacketType, @Nullable PacketHandler handler, boolean override)
Protocol
registerClientbound
in interface Protocol<CU extends ClientboundPacketType,CM extends ClientboundPacketType,SM extends ServerboundPacketType,SU extends ServerboundPacketType>
packetType
- clientbound packet type the server initially sendsmappedPacketType
- clientbound packet type after transforming for the clienthandler
- packet handleroverride
- whether an existing mapping should be overridden if presentpublic void cancelClientbound(CU packetType)
Protocol
cancelClientbound
in interface Protocol<CU extends ClientboundPacketType,CM extends ClientboundPacketType,SM extends ServerboundPacketType,SU extends ServerboundPacketType>
packetType
- clientbound packet type to cancelpublic void registerServerbound(SU packetType, @Nullable PacketHandler handler)
Protocol
registerServerbound
in interface Protocol<CU extends ClientboundPacketType,CM extends ClientboundPacketType,SM extends ServerboundPacketType,SU extends ServerboundPacketType>
packetType
- serverbound packet type the client sendshandler
- packet handlerpublic void registerServerbound(SU packetType, SM mappedPacketType, @Nullable PacketHandler handler, boolean override)
Protocol
registerServerbound
in interface Protocol<CU extends ClientboundPacketType,CM extends ClientboundPacketType,SM extends ServerboundPacketType,SU extends ServerboundPacketType>
packetType
- serverbound packet type initially sent by the clientmappedPacketType
- serverbound packet type after transforming for the serverhandler
- packet handleroverride
- whether an existing mapping should be overridden if presentpublic void cancelServerbound(SU packetType)
Protocol
cancelServerbound
in interface Protocol<CU extends ClientboundPacketType,CM extends ClientboundPacketType,SM extends ServerboundPacketType,SU extends ServerboundPacketType>
packetType
- serverbound packet type to cancelpublic boolean hasRegisteredClientbound(State state, int unmappedPacketId)
Protocol
hasRegisteredClientbound
in interface Protocol<CU extends ClientboundPacketType,CM extends ClientboundPacketType,SM extends ServerboundPacketType,SU extends ServerboundPacketType>
state
- state which the packet is sent inunmappedPacketId
- unmapped packet idpublic boolean hasRegisteredServerbound(State state, int unmappedPacketId)
Protocol
hasRegisteredServerbound
in interface Protocol<CU extends ClientboundPacketType,CM extends ClientboundPacketType,SM extends ServerboundPacketType,SU extends ServerboundPacketType>
state
- state which the packet is sent inunmappedPacketId
- mapped packet idpublic void transform(Direction direction, State state, PacketWrapper packetWrapper) throws java.lang.Exception
Protocol
transform
in interface Protocol<CU extends ClientboundPacketType,CM extends ClientboundPacketType,SM extends ServerboundPacketType,SU extends ServerboundPacketType>
direction
- The direction the packet is going instate
- The current protocol statepacketWrapper
- The packet wrapper to transformjava.lang.Exception
- Throws exception if it fails to transformprotected void throwRemapError(Direction direction, State state, int unmappedPacketId, int mappedPacketId, InformativeException e) throws InformativeException
InformativeException
public static java.lang.String toNiceHex(int id)
public PacketTypesProvider<CU,CM,SM,SU> getPacketTypesProvider()
Protocol
getPacketTypesProvider
in interface Protocol<CU extends ClientboundPacketType,CM extends ClientboundPacketType,SM extends ServerboundPacketType,SU extends ServerboundPacketType>
public <T> T get(java.lang.Class<T> objectClass)
Protocol
get
in interface Protocol<CU extends ClientboundPacketType,CM extends ClientboundPacketType,SM extends ServerboundPacketType,SU extends ServerboundPacketType>
T
- typeobjectClass
- class of the object to getpublic void put(java.lang.Object object)
Protocol
Protocol.get(Class)
.put
in interface Protocol<CU extends ClientboundPacketType,CM extends ClientboundPacketType,SM extends ServerboundPacketType,SU extends ServerboundPacketType>
object
- object to cachepublic PacketTypesProvider<CU,CM,SM,SU> packetTypesProvider()
public java.lang.String toString()
toString
in class java.lang.Object