mirror of
https://github.com/ViaVersion/ViaFabricPlus.git
synced 2024-11-16 10:55:39 +01:00
Add ProtocolTranslator#getTargetVersion with channel argument
This commit is contained in:
parent
73d21aaf2c
commit
17ecf0c736
@ -74,11 +74,8 @@ public class ViaFabricPlusProtocol extends AbstractSimpleProtocol {
|
||||
|
||||
final ProtocolVersion version = wrapper.user().getProtocolInfo().serverProtocolVersion();
|
||||
if (!payloadDiff.containsKey(channel) || version.olderThan(payloadDiff.get(channel).getLeft())) {
|
||||
// Technically, it's wrong to just drop all payloads.
|
||||
// However, ViaVersion doesn't translate them and the server can't detect if
|
||||
// we handled the payload or not,
|
||||
// so dropping them is easier
|
||||
// than adding a bunch of useless translations for payloads
|
||||
// Technically, it's wrong to just drop all payloads. However, ViaVersion doesn't translate them and the server can't detect if
|
||||
// we handled the payload or not, so dropping them is easier than adding a bunch of useless translations for payloads
|
||||
// which don't do anything on the client anyway.
|
||||
wrapper.cancel();
|
||||
return;
|
||||
@ -101,7 +98,7 @@ public class ViaFabricPlusProtocol extends AbstractSimpleProtocol {
|
||||
public void init(UserConnection connection) {
|
||||
super.init(connection);
|
||||
|
||||
final ProtocolVersion serverVersion = connection.getChannel().attr(ProtocolTranslator.TARGET_VERSION_ATTRIBUTE_KEY).get();
|
||||
final ProtocolVersion serverVersion = ProtocolTranslator.getTargetVersion(connection.getChannel());
|
||||
|
||||
// Add storages we need for different fixes here
|
||||
if (serverVersion.equals(BedrockProtocolVersion.bedrockLatest)) {
|
||||
|
@ -158,6 +158,19 @@ public class ProtocolTranslator {
|
||||
return targetVersion;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the target version from the channel attribute, can be used in early stages of the connection
|
||||
*
|
||||
* @param channel the channel
|
||||
* @return the target version
|
||||
*/
|
||||
public static ProtocolVersion getTargetVersion(final Channel channel) {
|
||||
if (channel == null || !channel.hasAttr(TARGET_VERSION_ATTRIBUTE_KEY)) {
|
||||
throw new IllegalStateException("Target version attribute not set");
|
||||
}
|
||||
return channel.attr(TARGET_VERSION_ATTRIBUTE_KEY).get();
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the target version
|
||||
*
|
||||
|
@ -29,7 +29,7 @@ public class ViaFabricPlusBaseVersionProvider extends BaseVersionProvider {
|
||||
@Override
|
||||
public ProtocolVersion getClosestServerProtocol(UserConnection connection) throws Exception {
|
||||
if (connection.isClientSide()) {
|
||||
return connection.getChannel().attr(ProtocolTranslator.TARGET_VERSION_ATTRIBUTE_KEY).get();
|
||||
return ProtocolTranslator.getTargetVersion(connection.getChannel());
|
||||
} else {
|
||||
return super.getClosestServerProtocol(connection);
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user