Don't require a base protocol for current version in BaseProtocol (#3709)

This commit is contained in:
EnZaXD 2024-02-23 15:13:33 +01:00 committed by GitHub
parent 4e1d4a75b2
commit 7640342165
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
3 changed files with 11 additions and 6 deletions

View File

@ -78,10 +78,9 @@ public interface ProtocolManager {
* The standard base protocols deal with status and login packets for userconnection initialization.
*
* @param serverVersion server protocol version
* @return base protocol for the given server protocol version
* @throws IllegalStateException if no base protocol could be found
* @return base protocol for the given server protocol version if present, else null
*/
Protocol getBaseProtocol(ProtocolVersion serverVersion);
@Nullable Protocol getBaseProtocol(ProtocolVersion serverVersion);
/**
* Returns an immutable collection of registered protocols.

View File

@ -363,13 +363,13 @@ public class ProtocolManagerImpl implements ProtocolManager {
}
@Override
public Protocol getBaseProtocol(ProtocolVersion serverVersion) {
public @Nullable Protocol getBaseProtocol(ProtocolVersion serverVersion) {
for (Pair<Range<ProtocolVersion>, Protocol> rangeProtocol : Lists.reverse(baseProtocols)) {
if (rangeProtocol.key().contains(serverVersion)) {
return rangeProtocol.value();
}
}
throw new IllegalStateException("No Base Protocol for " + serverVersion);
return null;
}
@Override

View File

@ -80,8 +80,14 @@ public class BaseProtocol extends AbstractProtocol<BaseClientboundPacket, BaseCl
// Add Base Protocol
ProtocolPipeline pipeline = info.getPipeline();
// Special versions might compare equal to normal versions and would break this getter
if (serverProtocol.getVersionType() != VersionType.SPECIAL) {
pipeline.add(protocolManager.getBaseProtocol(serverProtocol));
final Protocol baseProtocol = protocolManager.getBaseProtocol(serverProtocol);
// Platforms might add their base protocol manually (e.g. SPECIAL versions)
if (baseProtocol != null) {
pipeline.add(baseProtocol);
}
}
// Add other protocols