Class AbstractProtocol<CU extends ClientboundPacketType,CM extends ClientboundPacketType,SM extends ServerboundPacketType,SU extends ServerboundPacketType>
java.lang.Object
com.viaversion.viaversion.api.protocol.AbstractProtocol<CU,CM,SM,SU>
- Type Parameters:
CU
- unmapped clientbound packet typeCM
- mapped clientbound packet typeSM
- mapped serverbound packet typeSU
- unmapped serverbound packet type
- All Implemented Interfaces:
Protocol<CU,
CM, SM, SU>
- Direct Known Subclasses:
AbstractSimpleProtocol
public abstract class AbstractProtocol<CU extends ClientboundPacketType,CM extends ClientboundPacketType,SM extends ServerboundPacketType,SU extends ServerboundPacketType>
extends Object
implements Protocol<CU,CM,SM,SU>
Abstract protocol class to handle packet transformation between two protocol versions.
-
Field Summary
Modifier and TypeFieldDescriptionprotected final PacketMappings
protected final PacketTypesProvider<CU,
CM, SM, SU> protected final PacketMappings
-
Constructor Summary
ModifierConstructorDescriptionprotected
Deprecated.protected
AbstractProtocol
(@Nullable Class<CU> unmappedClientboundPacketType, @Nullable Class<CM> mappedClientboundPacketType, @Nullable Class<SM> mappedServerboundPacketType, @Nullable Class<SU> unmappedServerboundPacketType) Creates a protocol with automated id mapping if the respective packet type classes are not null. -
Method Summary
Modifier and TypeMethodDescriptionprotected void
addEntityTracker
(UserConnection connection, EntityTracker tracker) void
appendClientbound
(CU type, PacketHandler handler) Appends a clientbound packet type handler with another, as opposed to replacing it entirely.void
appendServerbound
(SU type, PacketHandler handler) Appends a serverbound packet type handler with another, as opposed to replacing it entirely.void
cancelClientbound
(State state, int unmappedPacketId) void
cancelClientbound
(CU packetType) Cancels any clientbound packets from the given type.void
cancelServerbound
(State state, int unmappedPacketId) void
cancelServerbound
(SU packetType) Cancels any serverbound packets from the given type.protected @Nullable CU
protected @Nullable SU
protected PacketMappings
protected PacketTypesProvider<CU,
CM, SM, SU> protected PacketMappings
<T> @Nullable T
Returns a cached object by the given type if present.Returns the protocol's logger.final PacketTypesProvider<CU,
CM, SM, SU> 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.final void
Called withProtocolManager.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.final void
Loads the protocol's mapping data.protected void
Called afterloadMappingData()
is called; load extra mapping data for the protocol.void
Caches an object, retrievable by usingProtocol.get(Class)
.void
registerClientbound
(State state, int unmappedPacketId, int mappedPacketId, PacketHandler handler, boolean override) Registers a clientbound packet, with id transformation and remapper.void
registerClientbound
(CU packetType, @Nullable 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.protected void
protected void
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, @Nullable SM mappedPacketType, @Nullable PacketHandler handler, boolean override) Registers a serverbound packet mapping.protected @Nullable SU
protected @Nullable CU
toString()
void
transform
(Direction direction, State state, PacketWrapper packetWrapper) Transform a packet using this protocolMethods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
Methods inherited from interface com.viaversion.viaversion.api.protocol.Protocol
getComponentRewriter, getEntityRewriter, getItemRewriter, getMappingData, getTagRewriter, hasMappingDataToLoad, hasRegisteredClientbound, hasRegisteredServerbound, init, isBaseProtocol, register, registerClientbound, registerClientbound, registerClientbound, registerClientbound, registerServerbound, registerServerbound, registerServerbound, registerServerbound
-
Field Details
-
unmappedClientboundPacketType
-
mappedClientboundPacketType
-
mappedServerboundPacketType
-
unmappedServerboundPacketType
-
packetTypesProvider
protected final PacketTypesProvider<CU extends ClientboundPacketType,CM extends ClientboundPacketType, packetTypesProviderSM extends ServerboundPacketType, SU extends ServerboundPacketType> -
clientboundMappings
-
serverboundMappings
-
-
Constructor Details
-
AbstractProtocol
Deprecated. -
AbstractProtocol
protected AbstractProtocol(@Nullable Class<CU> unmappedClientboundPacketType, @Nullable Class<CM> mappedClientboundPacketType, @Nullable Class<SM> mappedServerboundPacketType, @Nullable Class<SU> unmappedServerboundPacketType) Creates a protocol with automated id mapping if the respective packet type classes are not null. They are also required to track the CONFIGURATION state.
-
-
Method Details
-
initialize
public final void initialize()Description copied from interface:Protocol
Called withProtocolManager.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.- Specified by:
initialize
in interfaceProtocol<CU extends ClientboundPacketType,
CM extends ClientboundPacketType, SM extends ServerboundPacketType, SU extends ServerboundPacketType>
-
registerConfigurationChangeHandlers
protected void registerConfigurationChangeHandlers() -
appendClientbound
Description copied from interface:Protocol
Appends a clientbound packet type handler with another, as opposed to replacing it entirely.Use
PacketWrapper.set(Type, int, Object)
to change individual parts, or callPacketWrapper.resetReader()
to reset the reader index.- Specified by:
appendClientbound
in interfaceProtocol<CU extends ClientboundPacketType,
CM extends ClientboundPacketType, SM extends ServerboundPacketType, SU extends ServerboundPacketType> - Parameters:
type
- clientbound packet typehandler
- packet handler
-
appendServerbound
Description copied from interface:Protocol
Appends a serverbound packet type handler with another, as opposed to replacing it entirely.Use
PacketWrapper.set(Type, int, Object)
to change individual parts, or callPacketWrapper.resetReader()
to reset the reader index.- Specified by:
appendServerbound
in interfaceProtocol<CU extends ClientboundPacketType,
CM extends ClientboundPacketType, SM extends ServerboundPacketType, SU extends ServerboundPacketType> - Parameters:
type
- serverbound packet typehandler
- packet handler
-
loadMappingData
public final void loadMappingData()Description copied from interface:Protocol
Loads the protocol's mapping data.- Specified by:
loadMappingData
in interfaceProtocol<CU extends ClientboundPacketType,
CM extends ClientboundPacketType, SM extends ServerboundPacketType, SU extends ServerboundPacketType>
-
registerPackets
protected void registerPackets()Register the packets for this protocol. To be overriden. -
onMappingDataLoaded
protected void onMappingDataLoaded()Called afterloadMappingData()
is called; load extra mapping data for the protocol.To be overridden if needed.
-
addEntityTracker
-
createPacketTypesProvider
-
createClientboundPacketMappings
-
createServerboundPacketMappings
-
configurationAcknowledgedPacket
-
startConfigurationPacket
-
serverboundFinishConfigurationPacket
-
clientboundFinishConfigurationPacket
-
registerServerbound
public void registerServerbound(State state, int unmappedPacketId, int mappedPacketId, PacketHandler handler, boolean override) Description copied from interface:Protocol
Registers a serverbound packet, with id transformation and remapper.- Specified by:
registerServerbound
in interfaceProtocol<CU extends ClientboundPacketType,
CM extends ClientboundPacketType, SM extends ServerboundPacketType, SU extends ServerboundPacketType> - Parameters:
state
- state which the packet is sent in.unmappedPacketId
- unmapped packet idmappedPacketId
- mapped packet idhandler
- packet handleroverride
- whether an existing mapper should be overridden- See Also:
-
cancelServerbound
- Specified by:
cancelServerbound
in interfaceProtocol<CU extends ClientboundPacketType,
CM extends ClientboundPacketType, SM extends ServerboundPacketType, SU extends ServerboundPacketType>
-
registerClientbound
public void registerClientbound(State state, int unmappedPacketId, int mappedPacketId, PacketHandler handler, boolean override) Description copied from interface:Protocol
Registers a clientbound packet, with id transformation and remapper.- Specified by:
registerClientbound
in interfaceProtocol<CU extends ClientboundPacketType,
CM extends ClientboundPacketType, SM extends ServerboundPacketType, SU extends ServerboundPacketType> - Parameters:
state
- state which the packet is sent in.unmappedPacketId
- unmapped packet idmappedPacketId
- mapped packet idhandler
- packet handleroverride
- whether an existing mapper should be overridden- See Also:
-
cancelClientbound
- Specified by:
cancelClientbound
in interfaceProtocol<CU extends ClientboundPacketType,
CM extends ClientboundPacketType, SM extends ServerboundPacketType, SU extends ServerboundPacketType>
-
registerClientbound
Description copied from interface:Protocol
Registers a clientbound protocol and automatically maps it to the new id.- Specified by:
registerClientbound
in interfaceProtocol<CU extends ClientboundPacketType,
CM extends ClientboundPacketType, SM extends ServerboundPacketType, SU extends ServerboundPacketType> - Parameters:
packetType
- clientbound packet type the server sendshandler
- packet handler
-
registerClientbound
public void registerClientbound(CU packetType, @Nullable CM mappedPacketType, @Nullable PacketHandler handler, boolean override) Description copied from interface:Protocol
Registers a clientbound packet mapping.- Specified by:
registerClientbound
in interfaceProtocol<CU extends ClientboundPacketType,
CM extends ClientboundPacketType, SM extends ServerboundPacketType, SU extends ServerboundPacketType> - Parameters:
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 present
-
cancelClientbound
Description copied from interface:Protocol
Cancels any clientbound packets from the given type.- Specified by:
cancelClientbound
in interfaceProtocol<CU extends ClientboundPacketType,
CM extends ClientboundPacketType, SM extends ServerboundPacketType, SU extends ServerboundPacketType> - Parameters:
packetType
- clientbound packet type to cancel
-
registerServerbound
Description copied from interface:Protocol
Registers a serverbound protocol and automatically maps it to the server's id.- Specified by:
registerServerbound
in interfaceProtocol<CU extends ClientboundPacketType,
CM extends ClientboundPacketType, SM extends ServerboundPacketType, SU extends ServerboundPacketType> - Parameters:
packetType
- serverbound packet type the client sendshandler
- packet handler
-
registerServerbound
public void registerServerbound(SU packetType, @Nullable SM mappedPacketType, @Nullable PacketHandler handler, boolean override) Description copied from interface:Protocol
Registers a serverbound packet mapping.- Specified by:
registerServerbound
in interfaceProtocol<CU extends ClientboundPacketType,
CM extends ClientboundPacketType, SM extends ServerboundPacketType, SU extends ServerboundPacketType> - Parameters:
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 present
-
cancelServerbound
Description copied from interface:Protocol
Cancels any serverbound packets from the given type.- Specified by:
cancelServerbound
in interfaceProtocol<CU extends ClientboundPacketType,
CM extends ClientboundPacketType, SM extends ServerboundPacketType, SU extends ServerboundPacketType> - Parameters:
packetType
- serverbound packet type to cancel
-
hasRegisteredClientbound
Description copied from interface:Protocol
Checks if a clientbound packet has already been registered.- Specified by:
hasRegisteredClientbound
in interfaceProtocol<CU extends ClientboundPacketType,
CM extends ClientboundPacketType, SM extends ServerboundPacketType, SU extends ServerboundPacketType> - Parameters:
state
- state which the packet is sent inunmappedPacketId
- unmapped packet id- Returns:
- true if already registered
-
hasRegisteredServerbound
Description copied from interface:Protocol
Checks if a serverbound packet has already been registered.- Specified by:
hasRegisteredServerbound
in interfaceProtocol<CU extends ClientboundPacketType,
CM extends ClientboundPacketType, SM extends ServerboundPacketType, SU extends ServerboundPacketType> - Parameters:
state
- state which the packet is sent inunmappedPacketId
- mapped packet id- Returns:
- true if already registered
-
transform
public void transform(Direction direction, State state, PacketWrapper packetWrapper) throws InformativeException, CancelException Description copied from interface:Protocol
Transform a packet using this protocol- Specified by:
transform
in interfaceProtocol<CU extends ClientboundPacketType,
CM extends ClientboundPacketType, SM extends ServerboundPacketType, SU extends ServerboundPacketType> - Parameters:
direction
- The direction the packet is going instate
- The current protocol statepacketWrapper
- The packet wrapper to transform- Throws:
InformativeException
CancelException
-
getLogger
Description copied from interface:Protocol
Returns the protocol's logger.- Specified by:
getLogger
in interfaceProtocol<CU extends ClientboundPacketType,
CM extends ClientboundPacketType, SM extends ServerboundPacketType, SU extends ServerboundPacketType> - Returns:
- logger
-
getPacketTypesProvider
Description copied from interface:Protocol
Returns a packet type provider for this protocol to get packet types by id. Depending on the Protocol, not every state may be populated.- Specified by:
getPacketTypesProvider
in interfaceProtocol<CU extends ClientboundPacketType,
CM extends ClientboundPacketType, SM extends ServerboundPacketType, SU extends ServerboundPacketType> - Returns:
- the packet types provider
-
get
Description copied from interface:Protocol
Returns a cached object by the given type if present.- Specified by:
get
in interfaceProtocol<CU extends ClientboundPacketType,
CM extends ClientboundPacketType, SM extends ServerboundPacketType, SU extends ServerboundPacketType> - Type Parameters:
T
- type- Parameters:
objectClass
- class of the object to get- Returns:
- object if present, else null
-
put
Description copied from interface:Protocol
Caches an object, retrievable by usingProtocol.get(Class)
.- Specified by:
put
in interfaceProtocol<CU extends ClientboundPacketType,
CM extends ClientboundPacketType, SM extends ServerboundPacketType, SU extends ServerboundPacketType> - Parameters:
object
- object to cache
-
toString
-