3
0
Mirror von https://github.com/ViaVersion/ViaVersion.git synchronisiert 2024-12-26 16:12:42 +01:00

Use RedirectProtocolVersion#getOrigin in InitialBaseProtocol if possible (#4110)

This way, we should be able to get rid of manually adding the base protocol in projects like ViaAprilFools:
https://github.com/ViaVersion/ViaAprilFools/blob/main/common/src/main/java/net/raphimc/viaaprilfools/protocol/s3d_sharewaretov1_14/Protocol3D_SharewareTo1_14.java#L87
Dieser Commit ist enthalten in:
EnZaXD 2024-08-21 16:56:20 +02:00 committet von GitHub
Ursprung 1dde24bb68
Commit 78abf8be00
Es konnte kein GPG-Schlüssel zu dieser Signatur gefunden werden
GPG-Schlüssel-ID: B5690EEEBB952194
2 geänderte Dateien mit 9 neuen und 3 gelöschten Zeilen

Datei anzeigen

@ -24,8 +24,9 @@ import java.util.Comparator;
import org.checkerframework.checker.nullness.qual.Nullable;
/**
* Special protocol version that compares to another version. This can be used for e.g. April Fool versions which are depending
* on vanilla game versions.
* A {@link ProtocolVersion} with the version type {@link VersionType#SPECIAL} that compares equal to the given
* origin version. The origin version will also be used in {@link com.viaversion.viaversion.protocols.base.InitialBaseProtocol}
* to determine the correct base protocol.
*/
public class RedirectProtocolVersion extends ProtocolVersion {

Datei anzeigen

@ -35,6 +35,7 @@ import com.viaversion.viaversion.api.protocol.version.VersionType;
import com.viaversion.viaversion.api.type.Types;
import com.viaversion.viaversion.exception.CancelException;
import com.viaversion.viaversion.exception.InformativeException;
import com.viaversion.viaversion.protocol.RedirectProtocolVersion;
import com.viaversion.viaversion.protocol.version.BaseVersionProvider;
import com.viaversion.viaversion.protocols.base.packet.BaseClientboundPacket;
import com.viaversion.viaversion.protocols.base.packet.BasePacketTypesProvider;
@ -99,11 +100,15 @@ public class InitialBaseProtocol extends AbstractProtocol<BaseClientboundPacket,
ProtocolPipeline pipeline = info.getPipeline();
// Special versions might compare equal to normal versions and would break this getter,
// platforms need to add the base protocols manually in this case
// platforms either need to use the RedirectProtocolVersion API or add the base protocols manually
if (serverProtocol.getVersionType() != VersionType.SPECIAL) {
for (final Protocol protocol : protocolManager.getBaseProtocols(serverProtocol)) {
pipeline.add(protocol);
}
} else if (serverProtocol instanceof RedirectProtocolVersion version) {
for (final Protocol protocol : protocolManager.getBaseProtocols(version.getOrigin())) {
pipeline.add(protocol);
}
}
// Add other protocols