Mirror von
https://github.com/GeyserMC/Geyser.git
synchronisiert 2024-12-27 00:23:03 +01:00
Add method in Connection API for transferring connections (#2891)
Dieser Commit ist enthalten in:
Ursprung
9c7210ef92
Commit
f8e983887e
@ -26,6 +26,7 @@
|
|||||||
package org.geysermc.api.session;
|
package org.geysermc.api.session;
|
||||||
|
|
||||||
import org.checkerframework.checker.nullness.qual.NonNull;
|
import org.checkerframework.checker.nullness.qual.NonNull;
|
||||||
|
import org.checkerframework.common.value.qual.IntRange;
|
||||||
|
|
||||||
import java.util.UUID;
|
import java.util.UUID;
|
||||||
|
|
||||||
@ -55,5 +56,13 @@ public interface Connection {
|
|||||||
*/
|
*/
|
||||||
String xuid();
|
String xuid();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Transfer the connection to a server. A Bedrock player can successfully transfer to the same server they are
|
||||||
|
* currently playing on.
|
||||||
|
*
|
||||||
|
* @param address The address of the server
|
||||||
|
* @param port The port of the server
|
||||||
|
* @return true if the transfer was a success
|
||||||
|
*/
|
||||||
|
boolean transfer(@NonNull String address, @IntRange(from = 0, to = 65535) int port);
|
||||||
}
|
}
|
||||||
|
@ -78,6 +78,7 @@ import lombok.AccessLevel;
|
|||||||
import lombok.Getter;
|
import lombok.Getter;
|
||||||
import lombok.NonNull;
|
import lombok.NonNull;
|
||||||
import lombok.Setter;
|
import lombok.Setter;
|
||||||
|
import org.checkerframework.common.value.qual.IntRange;
|
||||||
import org.geysermc.common.PlatformType;
|
import org.geysermc.common.PlatformType;
|
||||||
import org.geysermc.cumulus.Form;
|
import org.geysermc.cumulus.Form;
|
||||||
import org.geysermc.cumulus.util.FormBuilder;
|
import org.geysermc.cumulus.util.FormBuilder;
|
||||||
@ -1310,6 +1311,21 @@ public class GeyserSession implements GeyserConnection, CommandSender {
|
|||||||
return authData.xuid();
|
return authData.xuid();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@SuppressWarnings("ConstantConditions") // Need to enforce the parameter annotations
|
||||||
|
@Override
|
||||||
|
public boolean transfer(@NonNull String address, @IntRange(from = 0, to = 65535) int port) {
|
||||||
|
if (address == null || address.isBlank()) {
|
||||||
|
throw new IllegalArgumentException("Server address cannot be null or blank");
|
||||||
|
} else if (port < 0 || port > 65535) {
|
||||||
|
throw new IllegalArgumentException("Server port must be between 0 and 65535, was " + port);
|
||||||
|
}
|
||||||
|
TransferPacket transferPacket = new TransferPacket();
|
||||||
|
transferPacket.setAddress(address);
|
||||||
|
transferPacket.setPort(port);
|
||||||
|
sendUpstreamPacket(transferPacket);
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void sendMessage(String message) {
|
public void sendMessage(String message) {
|
||||||
TextPacket textPacket = new TextPacket();
|
TextPacket textPacket = new TextPacket();
|
||||||
|
Laden…
In neuem Issue referenzieren
Einen Benutzer sperren