1.20.5 Support (#1198)

Added support to Minecraft 1.20.5 (Release Candidate 3)

* Initial 1.20.5 update

* Snapshot 24w03a

* Handle Transfer Handshake intent

* Snapshot 24w03b

* Implement PreTransferEvent

* 24w04a

* Updated EncryptionRequestPacket, JoinGamePacket and ServerDataPacket to 24w04a

* Snapshot 24w05a

* Snapshot 24w05b

* Snapshot 24w06a

* Added migration to add new configuration option

* Snapshot 24w07a

* Snapshot 24w09a

* Snapshot 24w10a

* Snapshot 24w12a

* Snapshot 24w14a

* 1.20.5-rc1

* fix unsigned commands

* fix NPE

* fix respawn packet id

* 1.20.5 Release Candidate 2

* Restored old ConnectionHandshakeEvent constructor

* Added `-Dvelocity.strictErrorHandling` system property

* 1.20.5 Release Candidate 3

---------

Co-authored-by: Gero <gecam59@gmail.com>
This commit is contained in:
Adrian
2024-04-22 21:12:25 -05:00
committed by GitHub
parent be678840de
commit 8f4adb1cec
36 changed files with 782 additions and 142 deletions

View File

@@ -8,6 +8,7 @@
package com.velocitypowered.api.event.connection;
import com.google.common.base.Preconditions;
import com.velocitypowered.api.network.HandshakeIntent;
import com.velocitypowered.api.proxy.InboundConnection;
/**
@@ -18,19 +19,39 @@ import com.velocitypowered.api.proxy.InboundConnection;
public final class ConnectionHandshakeEvent {
private final InboundConnection connection;
private final HandshakeIntent intent;
public ConnectionHandshakeEvent(InboundConnection connection, HandshakeIntent intent) {
this.connection = Preconditions.checkNotNull(connection, "connection");
this.intent = Preconditions.checkNotNull(intent, "intent");
}
/**
* This method is only retained to avoid breaking plugins
* that have not yet updated their integration tests.
*
* @param connection the inbound connection
* @deprecated use {@link #ConnectionHandshakeEvent(InboundConnection, HandshakeIntent)}
*/
@Deprecated(forRemoval = true)
public ConnectionHandshakeEvent(InboundConnection connection) {
this.connection = Preconditions.checkNotNull(connection, "connection");
this.intent = HandshakeIntent.LOGIN;
}
public InboundConnection getConnection() {
return connection;
}
public HandshakeIntent getIntent() {
return this.intent;
}
@Override
public String toString() {
return "ConnectionHandshakeEvent{"
+ "connection=" + connection
+ ", intent=" + intent
+ '}';
}
}

View File

@@ -0,0 +1,100 @@
/*
* Copyright (C) 2024 Velocity Contributors
*
* The Velocity API is licensed under the terms of the MIT License. For more details,
* reference the LICENSE file in the api top-level directory.
*/
package com.velocitypowered.api.event.connection;
import static java.util.Objects.requireNonNull;
import com.velocitypowered.api.event.ResultedEvent;
import com.velocitypowered.api.event.annotation.AwaitingEvent;
import com.velocitypowered.api.proxy.Player;
import java.net.InetSocketAddress;
import org.jetbrains.annotations.ApiStatus;
import org.jetbrains.annotations.Nullable;
/**
* This event is executed before sending a player to another host,
* either by the backend server or by a plugin using
* the {@link Player#transferToHost(InetSocketAddress)} method.
*/
@AwaitingEvent
@ApiStatus.Experimental
public final class PreTransferEvent implements ResultedEvent<PreTransferEvent.TransferResult> {
private final InetSocketAddress originalAddress;
private final Player player;
private TransferResult result = TransferResult.ALLOWED;
public PreTransferEvent(final Player player, final InetSocketAddress address) {
this.player = requireNonNull(player);
this.originalAddress = requireNonNull(address);
}
public Player player() {
return this.player;
}
public InetSocketAddress originalAddress() {
return this.originalAddress;
}
@Override
public TransferResult getResult() {
return this.result;
}
@Override
public void setResult(final TransferResult result) {
requireNonNull(result);
this.result = result;
}
/**
* Transfer Result of a player to another host.
*/
public static class TransferResult implements ResultedEvent.Result {
private static final TransferResult ALLOWED = new TransferResult(true, null);
private static final TransferResult DENIED = new TransferResult(false, null);
private final InetSocketAddress address;
private final boolean allowed;
private TransferResult(final boolean allowed, final InetSocketAddress address) {
this.address = address;
this.allowed = allowed;
}
public static TransferResult allowed() {
return ALLOWED;
}
public static TransferResult denied() {
return DENIED;
}
/**
* Sets the result of transfer to a specific host.
*
* @param address the address specified
* @return a new TransferResult
*/
public static TransferResult transferTo(final InetSocketAddress address) {
requireNonNull(address);
return new TransferResult(true, address);
}
@Override
public boolean isAllowed() {
return this.allowed;
}
@Nullable
public InetSocketAddress address() {
return this.address;
}
}
}

View File

@@ -0,0 +1,42 @@
/*
* Copyright (C) 2024 Velocity Contributors
*
* The Velocity API is licensed under the terms of the MIT License. For more details,
* reference the LICENSE file in the api top-level directory.
*/
package com.velocitypowered.api.network;
/**
* Represents the ClientIntent of a client in the Handshake state.
*/
public enum HandshakeIntent {
STATUS(1),
LOGIN(2),
TRANSFER(3);
private final int id;
HandshakeIntent(int id) {
this.id = id;
}
public int id() {
return this.id;
}
/**
* Obtain the HandshakeIntent by ID.
*
* @param id the intent id
* @return the HandshakeIntent desired
*/
public static HandshakeIntent getById(int id) {
return switch (id) {
case 1 -> STATUS;
case 2 -> LOGIN;
case 3 -> TRANSFER;
default -> null;
};
}
}

View File

@@ -16,14 +16,15 @@ package com.velocitypowered.api.network;
public enum ProtocolState {
/**
* Initial connection State.
* <p>This status can be caused by a STATUS, LOGIN or TRANSFER intent.</p>
* <p>This status can be caused by a {@link HandshakeIntent#STATUS},
* {@link HandshakeIntent#LOGIN} or {@link HandshakeIntent#TRANSFER} intent.</p>
* If the intent is LOGIN or TRANSFER, the next state will be {@link #LOGIN},
* otherwise, it will go to the {@link #STATUS} state.
*/
HANDSHAKE,
/**
* Ping State of a connection.
* <p>Connections with the STATUS HandshakeIntent will pass through this state
* <p>Connections with the {@link HandshakeIntent#STATUS} intent will pass through this state
* and be disconnected after it requests the ping from the server
* and the server responds with the respective ping.</p>
*/

View File

@@ -85,7 +85,8 @@ public enum ProtocolVersion implements Ordered<ProtocolVersion> {
MINECRAFT_1_19_4(762, "1.19.4"),
MINECRAFT_1_20(763, "1.20", "1.20.1"),
MINECRAFT_1_20_2(764, "1.20.2"),
MINECRAFT_1_20_3(765, "1.20.3", "1.20.4");
MINECRAFT_1_20_3(765, "1.20.3", "1.20.4"),
MINECRAFT_1_20_5(-1, 191, "1.20.5"); // Future Minecraft 1.20.5 | Protocol 766 | Release Candidate 3
private static final int SNAPSHOT_BIT = 30;

View File

@@ -20,6 +20,7 @@ import com.velocitypowered.api.proxy.player.TabList;
import com.velocitypowered.api.proxy.server.RegisteredServer;
import com.velocitypowered.api.util.GameProfile;
import com.velocitypowered.api.util.ModInfo;
import java.net.InetSocketAddress;
import java.util.Collection;
import java.util.List;
import java.util.Locale;
@@ -426,4 +427,13 @@ public interface Player extends
@Override
default void openBook(@NotNull Book book) {
}
/**
* Transfers a Player to a host.
*
* @param address the host address
* @throws IllegalArgumentException if the player is from a version lower than 1.20.5
* @since 3.3.0
*/
void transferToHost(@NotNull InetSocketAddress address);
}