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
FieldsModifier and TypeFieldDescriptionprotected final PacketMappingsprotected final PacketTypesProvider<CU,CM, SM, SU> protected final PacketMappings -
Constructor Summary
ConstructorsModifierConstructorDescriptionprotectedDeprecated.protectedAbstractProtocol(@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 voidaddEntityTracker(UserConnection connection, EntityTracker tracker) protected voidaddItemHasher(UserConnection connection, ItemHasher hasher) voidappendClientbound(CU type, PacketHandler handler) Appends a clientbound packet type handler with another, as opposed to replacing it entirely.voidappendServerbound(SU type, PacketHandler handler) Appends a serverbound packet type handler with another, as opposed to replacing it entirely.voidcancelClientbound(State state, int unmappedPacketId) voidcancelClientbound(CU packetType) Cancels any clientbound packets from the given type.voidcancelServerbound(State state, int unmappedPacketId) voidcancelServerbound(SU packetType) Cancels any serverbound packets from the given type.protected @Nullable CUprotected @Nullable SUprotected PacketMappingsprotected ProtocolLoggerprotected PacketTypesProvider<CU,CM, SM, SU> protected PacketMappings<T> @Nullable TReturns 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.booleanhasRegisteredClientbound(State state, int unmappedPacketId) Checks if a clientbound packet has already been registered.booleanhasRegisteredServerbound(State state, int unmappedPacketId) Checks if a serverbound packet has already been registered.final voidCalled 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 voidLoads the protocol's mapping data.protected voidCalled afterloadMappingData()is called; load extra mapping data for the protocol.voidCaches an object, retrievable by usingProtocol.get(Class).voidregisterClientbound(State state, int unmappedPacketId, int mappedPacketId, PacketHandler handler, boolean override) Registers a clientbound packet, with id transformation and remapper.voidregisterClientbound(CU packetType, @Nullable CM mappedPacketType, @Nullable PacketHandler handler, boolean override) Registers a clientbound packet mapping.voidregisterClientbound(CU packetType, @Nullable PacketHandler handler) Registers a clientbound protocol and automatically maps it to the new id.protected voidvoidregisterFinishConfiguration(CU packetType, PacketHandler handler) protected voidRegister the packets for this protocol.voidregisterServerbound(State state, int unmappedPacketId, int mappedPacketId, PacketHandler handler, boolean override) Registers a serverbound packet, with id transformation and remapper.voidregisterServerbound(SU packetType, @Nullable PacketHandler handler) Registers a serverbound protocol and automatically maps it to the server's id.voidregisterServerbound(SU packetType, @Nullable SM mappedPacketType, @Nullable PacketHandler handler, boolean override) Registers a serverbound packet mapping.protected @Nullable SUprotected @Nullable CUtoString()voidtransform(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, waitMethods inherited from interface com.viaversion.viaversion.api.protocol.Protocol
getComponentRewriter, getEntityRewriter, getItemRewriter, getMappingData, getParticleRewriter, getRegistryDataRewriter, getTagRewriter, hasMappingDataToLoad, hasRegisteredClientbound, hasRegisteredServerbound, init, isBaseProtocol, mappedTypes, register, registerClientbound, registerClientbound, registerClientbound, registerClientbound, registerServerbound, registerServerbound, registerServerbound, registerServerbound, types
-
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:ProtocolCalled 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:
initializein interfaceProtocol<CU extends ClientboundPacketType,CM extends ClientboundPacketType, SM extends ServerboundPacketType, SU extends ServerboundPacketType>
-
createLogger
-
registerConfigurationChangeHandlers
protected void registerConfigurationChangeHandlers() -
appendClientbound
Description copied from interface:ProtocolAppends 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:
appendClientboundin 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:ProtocolAppends 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:
appendServerboundin interfaceProtocol<CU extends ClientboundPacketType,CM extends ClientboundPacketType, SM extends ServerboundPacketType, SU extends ServerboundPacketType> - Parameters:
type- serverbound packet typehandler- packet handler
-
registerFinishConfiguration
-
loadMappingData
public final void loadMappingData()Description copied from interface:ProtocolLoads the protocol's mapping data.- Specified by:
loadMappingDatain 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 overridden. -
onMappingDataLoaded
protected void onMappingDataLoaded()Called afterloadMappingData()is called; load extra mapping data for the protocol.To be overridden if needed.
-
addEntityTracker
-
addItemHasher
-
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:ProtocolRegisters a serverbound packet, with id transformation and remapper.- Specified by:
registerServerboundin 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:
cancelServerboundin 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:ProtocolRegisters a clientbound packet, with id transformation and remapper.- Specified by:
registerClientboundin 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:
cancelClientboundin interfaceProtocol<CU extends ClientboundPacketType,CM extends ClientboundPacketType, SM extends ServerboundPacketType, SU extends ServerboundPacketType>
-
registerClientbound
Description copied from interface:ProtocolRegisters a clientbound protocol and automatically maps it to the new id.- Specified by:
registerClientboundin 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:ProtocolRegisters a clientbound packet mapping.- Specified by:
registerClientboundin 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:ProtocolCancels any clientbound packets from the given type.- Specified by:
cancelClientboundin 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:ProtocolRegisters a serverbound protocol and automatically maps it to the server's id.- Specified by:
registerServerboundin 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:ProtocolRegisters a serverbound packet mapping.- Specified by:
registerServerboundin 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:ProtocolCancels any serverbound packets from the given type.- Specified by:
cancelServerboundin 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:ProtocolChecks if a clientbound packet has already been registered.- Specified by:
hasRegisteredClientboundin 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:ProtocolChecks if a serverbound packet has already been registered.- Specified by:
hasRegisteredServerboundin 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:ProtocolTransform a packet using this protocol- Specified by:
transformin 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:
InformativeExceptionCancelException
-
getLogger
Description copied from interface:ProtocolReturns the protocol's logger.- Specified by:
getLoggerin interfaceProtocol<CU extends ClientboundPacketType,CM extends ClientboundPacketType, SM extends ServerboundPacketType, SU extends ServerboundPacketType> - Returns:
- logger
-
getPacketTypesProvider
Description copied from interface:ProtocolReturns 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:
getPacketTypesProviderin interfaceProtocol<CU extends ClientboundPacketType,CM extends ClientboundPacketType, SM extends ServerboundPacketType, SU extends ServerboundPacketType> - Returns:
- the packet types provider
-
get
Description copied from interface:ProtocolReturns a cached object by the given type if present.- Specified by:
getin 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:ProtocolCaches an object, retrievable by usingProtocol.get(Class).- Specified by:
putin interfaceProtocol<CU extends ClientboundPacketType,CM extends ClientboundPacketType, SM extends ServerboundPacketType, SU extends ServerboundPacketType> - Parameters:
object- object to cache
-
toString
-