Move appendClientbound/Serverbound methods to Protocol interface

This commit is contained in:
Nassim Jahnke 2024-04-24 20:11:05 +02:00
parent 0e97af29b4
commit 9dd3348510
No known key found for this signature in database
GPG Key ID: EF6771C01F6EF02F
3 changed files with 28 additions and 3 deletions

View File

@ -66,7 +66,7 @@ public interface ViaAPI<T> {
* @return API version incremented with meaningful API changes
*/
default int apiVersion() {
return 25;
return 26;
}
/**

View File

@ -146,6 +146,7 @@ public abstract class AbstractProtocol<CU extends ClientboundPacketType, CM exte
}
}
@Override
public void appendClientbound(final CU type, final PacketHandler handler) {
final PacketMapping mapping = clientboundMappings.mappedPacket(type.state(), type.getId());
if (mapping != null) {
@ -155,6 +156,7 @@ public abstract class AbstractProtocol<CU extends ClientboundPacketType, CM exte
}
}
@Override
public void appendServerbound(final SU type, final PacketHandler handler) {
final PacketMapping mapping = serverboundMappings.mappedPacket(type.state(), type.getId());
if (mapping != null) {

View File

@ -36,8 +36,8 @@ import com.viaversion.viaversion.api.protocol.remapper.PacketHandler;
import com.viaversion.viaversion.api.protocol.remapper.PacketRemapper;
import com.viaversion.viaversion.api.rewriter.EntityRewriter;
import com.viaversion.viaversion.api.rewriter.ItemRewriter;
import com.viaversion.viaversion.api.rewriter.Rewriter;
import com.viaversion.viaversion.api.rewriter.TagRewriter;
import com.viaversion.viaversion.api.type.Type;
import org.checkerframework.checker.nullness.qual.Nullable;
/**
@ -242,6 +242,28 @@ public interface Protocol<CU extends ClientboundPacketType, CM extends Clientbou
*/
boolean hasRegisteredServerbound(State state, int unmappedPacketId);
/**
* Appends a clientbound packet type handler with another, as opposed to replacing it entirely.
* <p>
* Use {@link PacketWrapper#set(Type, int, Object)} to change individual parts, or call
* {@link PacketWrapper#resetReader()} to reset the reader index.
*
* @param type clientbound packet type
* @param handler packet handler
*/
void appendClientbound(CU type, PacketHandler handler);
/**
* Appends a serverbound packet type handler with another, as opposed to replacing it entirely.
* <p>
* Use {@link PacketWrapper#set(Type, int, Object)} to change individual parts, or call
* {@link PacketWrapper#resetReader()} to reset the reader index.
*
* @param type serverbound packet type
* @param handler packet handler
*/
void appendServerbound(SU type, PacketHandler handler);
/**
* Transform a packet using this protocol
*
@ -268,7 +290,8 @@ public interface Protocol<CU extends ClientboundPacketType, CM extends Clientbou
* @return object if present, else null
*/
@Deprecated
@Nullable <T> T get(Class<T> objectClass);
@Nullable
<T> T get(Class<T> objectClass);
/**
* Caches an object, retrievable by using {@link #get(Class)}.