Interface Protocol<CU extends ClientboundPacketType,CM extends ClientboundPacketType,SM extends ServerboundPacketType,SU extends ServerboundPacketType>
- Type Parameters:
CU
- unmapped clientbound packet typesCM
- mapped clientbound packet typesSM
- mapped serverbound packet typesSU
- unmapped serverbound packet types
- All Known Subinterfaces:
ProtocolPipeline
,SimpleProtocol
- All Known Implementing Classes:
AbstractProtocol
,AbstractSimpleProtocol
public interface Protocol<CU extends ClientboundPacketType,CM extends ClientboundPacketType,SM extends ServerboundPacketType,SU extends ServerboundPacketType>
Abstract protocol class handling packet transformation between two protocol versions.
Clientbound and serverbount packet types can be set to enforce correct usage of them.
-
Method Summary
Modifier and TypeMethodDescriptionvoid
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 mappedPacketId) void
cancelServerbound
(SU packetType) Cancels any serverbound packets from the given type.<T> @Nullable T
Deprecated.default @Nullable ComponentRewriter
default @Nullable EntityRewriter<?>
Returns the protocol's entity rewriter if present.default @Nullable ItemRewriter<?>
Returns the protocol's item rewriter if present.Returns the protocol's logger.default @Nullable MappingData
Returns the protocol's mapping data if present.Returns a packet type provider for this protocol to get packet types by id.default @Nullable TagRewriter
Returns the protocol's tag rewriter if present.default boolean
Returns true if this Protocol'sloadMappingData()
method should be called.boolean
hasRegisteredClientbound
(State state, int unmappedPacketId) Checks if a clientbound packet has already been registered.default boolean
hasRegisteredClientbound
(CU packetType) Checks if a clientbound packet has already been registered.boolean
hasRegisteredServerbound
(State state, int unmappedPacketId) Checks if a serverbound packet has already been registered.default boolean
hasRegisteredServerbound
(SU packetType) Checks if a serverbound packet has already been registered.default void
init
(UserConnection connection) Initialise a user for this protocol setting up objects.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.default boolean
Returns whether this protocol is a base protocol.void
Loads the protocol's mapping data.void
Deprecated.default void
register
(ViaProviders providers) Handle protocol registration phase, use this to register providers / tasks.default void
registerClientbound
(State state, int unmappedPacketId, int mappedPacketId, @Nullable PacketHandler handler) void
registerClientbound
(State state, int unmappedPacketId, int mappedPacketId, @Nullable PacketHandler handler, boolean override) Registers a clientbound packet, with id transformation and remapper.default void
registerClientbound
(State state, ClientboundPacketType packetType, @Nullable PacketHandler handler) default void
registerClientbound
(CU packetType, @Nullable CM mappedPacketType) Maps a packet type to another packet type without a packet handler.default void
registerClientbound
(CU packetType, @Nullable CM mappedPacketType, @Nullable PacketHandler handler) Registers a clientbound packet mapping.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.default void
registerServerbound
(State state, int unmappedPacketId, int mappedPacketId, @Nullable PacketHandler handler) void
registerServerbound
(State state, int unmappedPacketId, int mappedPacketId, @Nullable PacketHandler handler, boolean override) Registers a serverbound packet, with id transformation and remapper.default void
registerServerbound
(State state, ServerboundPacketType packetType, @Nullable PacketHandler handler) void
registerServerbound
(SU packetType, @Nullable PacketHandler handler) Registers a serverbound protocol and automatically maps it to the server's id.default void
registerServerbound
(SU packetType, @Nullable SM mappedPacketType) Maps a packet type to another packet type without a packet handler.default void
registerServerbound
(SU packetType, @Nullable SM mappedPacketType, @Nullable PacketHandler handler) Registers a serverbound protocol.void
registerServerbound
(SU packetType, @Nullable SM mappedPacketType, @Nullable PacketHandler handler, boolean override) Registers a serverbound packet mapping.void
transform
(Direction direction, State state, PacketWrapper packetWrapper) Transform a packet using this protocol
-
Method Details
-
registerClientbound
default void registerClientbound(State state, ClientboundPacketType packetType, @Nullable PacketHandler handler) -
registerServerbound
default void registerServerbound(State state, ServerboundPacketType packetType, @Nullable PacketHandler handler) -
registerServerbound
default void registerServerbound(State state, int unmappedPacketId, int mappedPacketId, @Nullable PacketHandler handler) -
registerServerbound
void registerServerbound(State state, int unmappedPacketId, int mappedPacketId, @Nullable PacketHandler handler, boolean override) Registers a serverbound packet, with id transformation and remapper.- 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
-
registerClientbound
default void registerClientbound(State state, int unmappedPacketId, int mappedPacketId, @Nullable PacketHandler handler) -
cancelClientbound
-
registerClientbound
void registerClientbound(State state, int unmappedPacketId, int mappedPacketId, @Nullable PacketHandler handler, boolean override) Registers a clientbound packet, with id transformation and remapper.- 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:
-
registerClientbound
Registers a clientbound protocol and automatically maps it to the new id.- Parameters:
packetType
- clientbound packet type the server sendshandler
- packet handler
-
registerClientbound
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.- Parameters:
packetType
- clientbound packet type the server initially sendsmappedPacketType
- clientbound packet type after transforming for the client
-
registerClientbound
default void registerClientbound(CU packetType, @Nullable CM mappedPacketType, @Nullable PacketHandler handler) Registers a clientbound packet mapping.- Parameters:
packetType
- clientbound packet type the server initially sendsmappedPacketType
- clientbound packet type after transforming for the clienthandler
- packet handler
-
registerClientbound
void registerClientbound(CU packetType, @Nullable CM mappedPacketType, @Nullable PacketHandler handler, boolean override) Registers a clientbound packet mapping.- 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
Cancels any clientbound packets from the given type.- Parameters:
packetType
- clientbound packet type to cancel
-
registerServerbound
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.- Parameters:
packetType
- serverbound packet type the client initially sendsmappedPacketType
- serverbound packet type after transforming for the client
-
registerServerbound
Registers a serverbound protocol and automatically maps it to the server's id.- Parameters:
packetType
- serverbound packet type the client sendshandler
- packet handler
-
registerServerbound
default void registerServerbound(SU packetType, @Nullable SM mappedPacketType, @Nullable PacketHandler handler) Registers a serverbound protocol.- Parameters:
packetType
- serverbound packet type initially sent by the clientmappedPacketType
- serverbound packet type after transforming for the serverhandler
- packet handler
-
registerServerbound
void registerServerbound(SU packetType, @Nullable SM mappedPacketType, @Nullable PacketHandler handler, boolean override) Registers a serverbound packet mapping.- 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
Cancels any serverbound packets from the given type.- Parameters:
packetType
- serverbound packet type to cancel
-
hasRegisteredClientbound
Checks if a clientbound packet has already been registered.- Parameters:
packetType
- clientbound packet type- Returns:
- true if already registered
-
hasRegisteredServerbound
Checks if a serverbound packet has already been registered.- Parameters:
packetType
- serverbound packet type- Returns:
- true if already registered
-
hasRegisteredClientbound
Checks if a clientbound packet has already been registered.- Parameters:
state
- state which the packet is sent inunmappedPacketId
- unmapped packet id- Returns:
- true if already registered
-
hasRegisteredServerbound
Checks if a serverbound packet has already been registered.- Parameters:
state
- state which the packet is sent inunmappedPacketId
- mapped packet id- Returns:
- true if already registered
-
appendClientbound
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.- Parameters:
type
- clientbound packet typehandler
- packet handler
-
appendServerbound
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.- Parameters:
type
- serverbound packet typehandler
- packet handler
-
transform
void transform(Direction direction, State state, PacketWrapper packetWrapper) throws InformativeException, CancelException Transform a packet using this protocol- Parameters:
direction
- The direction the packet is going instate
- The current protocol statepacketWrapper
- The packet wrapper to transform- Throws:
InformativeException
CancelException
-
getPacketTypesProvider
PacketTypesProvider<CU,CM, getPacketTypesProvider()SM, SU> Returns a packet type provider for this protocol to get packet types by id. Depending on the Protocol, not every state may be populated.- Returns:
- the packet types provider
-
get
Deprecated.Returns a cached object by the given type if present.- Type Parameters:
T
- type- Parameters:
objectClass
- class of the object to get- Returns:
- object if present, else null
-
put
Deprecated.Caches an object, retrievable by usingget(Class)
.- Parameters:
object
- object to cache
-
initialize
void initialize()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.- Throws:
IllegalArgumentException
- if this method has already been called
-
hasMappingDataToLoad
default boolean hasMappingDataToLoad()Returns true if this Protocol'sloadMappingData()
method should be called.This does *not* necessarily mean that
getMappingData()
is non-null, since this may be overriden, depending on special cases.- Returns:
- true if this Protocol's
loadMappingData()
method should be called
-
loadMappingData
void loadMappingData()Loads the protocol's mapping data.- Throws:
NullPointerException
- if this protocol has no mapping data
-
register
Handle protocol registration phase, use this to register providers / tasks.To be overridden if needed.
- Parameters:
providers
- The current providers
-
init
Initialise a user for this protocol setting up objects. /!\ WARNING - May be called more than once in a singleUserConnection
To be overridden if needed.
- Parameters:
connection
- user to initialise
-
getMappingData
Returns the protocol's mapping data if present.- Returns:
- mapping data if present
-
getLogger
ProtocolLogger getLogger()Returns the protocol's logger.- Returns:
- logger
-
getEntityRewriter
Returns the protocol's entity rewriter if present.- Returns:
- entity rewriter
-
getItemRewriter
Returns the protocol's item rewriter if present.- Returns:
- item rewriter
-
getTagRewriter
Returns the protocol's tag rewriter if present.- Returns:
- tag rewriter
-
getComponentRewriter
-
isBaseProtocol
default boolean isBaseProtocol()Returns whether this protocol is a base protocol.- Returns:
- whether this represents a base protocol
-