mirror of
https://github.com/ViaVersion/ViaFabricPlus.git
synced 2025-02-02 23:31:36 +01:00
This commit is contained in:
parent
0798eda76f
commit
9e20576885
@ -24,16 +24,15 @@ import net.raphimc.vialoader.util.VersionEnum;
|
||||
import net.raphimc.vialoader.util.VersionRange;
|
||||
|
||||
public class LegacyServerAddress {
|
||||
private final static VersionRange SRV_RANGE = VersionRange.of(VersionEnum.r1_3_1tor1_3_2, VersionEnum.r1_16_4tor1_16_5);
|
||||
public final static VersionRange SRV_RANGE = VersionRange.andOlder(VersionEnum.r1_2_4tor1_2_5).add(VersionRange.single(VersionEnum.bedrockLatest));
|
||||
|
||||
public static ServerAddress parse(VersionEnum version, String address) {
|
||||
if (version == null) version = ProtocolHack.getTargetVersion();
|
||||
final ServerAddress mc = ServerAddress.parse(address);
|
||||
if (SRV_RANGE.contains(version) || version == VersionEnum.bedrockLatest) {
|
||||
if (!mc.equals(ServerAddress.INVALID)) {
|
||||
return AllowedAddressResolver.DEFAULT.redirectResolver.lookupRedirect(mc).orElse(mc);
|
||||
final ServerAddress modern = ServerAddress.parse(address);
|
||||
if (SRV_RANGE.contains(version) && !modern.equals(ServerAddress.INVALID)) {
|
||||
final var addressParts = address.split(":");
|
||||
return new ServerAddress(addressParts[0], addressParts.length > 1 ? Integer.parseInt(addressParts[1]) : 25565);
|
||||
}
|
||||
}
|
||||
return mc;
|
||||
return modern;
|
||||
}
|
||||
}
|
||||
|
@ -18,8 +18,10 @@
|
||||
package de.florianmichael.viafabricplus.injection.mixin.base;
|
||||
|
||||
import de.florianmichael.viafabricplus.base.event.ChangeProtocolVersionCallback;
|
||||
import de.florianmichael.viafabricplus.definition.LegacyServerAddress;
|
||||
import de.florianmichael.viafabricplus.injection.access.IServerInfo;
|
||||
import de.florianmichael.viafabricplus.protocolhack.ProtocolHack;
|
||||
import net.minecraft.client.network.ServerAddress;
|
||||
import net.minecraft.client.network.ServerInfo;
|
||||
import net.raphimc.vialoader.util.VersionEnum;
|
||||
import org.spongepowered.asm.mixin.Final;
|
||||
@ -38,8 +40,15 @@ public class MixinConnectScreen_1 {
|
||||
@Shadow
|
||||
ServerInfo field_40415;
|
||||
|
||||
@Final
|
||||
@Shadow
|
||||
ServerAddress field_33737;
|
||||
|
||||
@Redirect(method = "run", at = @At(value = "INVOKE", target = "Ljava/util/Optional;get()Ljava/lang/Object;"))
|
||||
public Object mapSocketAddress(Optional<InetSocketAddress> instance) {
|
||||
if (LegacyServerAddress.SRV_RANGE.contains(ProtocolHack.getTargetVersion())) {
|
||||
return new InetSocketAddress(field_33737.getAddress(), field_33737.getPort());
|
||||
}
|
||||
final InetSocketAddress address = instance.get();
|
||||
if (field_40415 == null) return address;
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user