mirror of
https://github.com/SparklyPower/SparklyPaper.git
synced 2025-12-19 15:09:27 +00:00
Useful if you want to actually control what the player is moving, because VehicleMoveEvent does not let you cancel nor change the location. Also useful to detect BoatFly hacks.
110 lines
4.9 KiB
Diff
110 lines
4.9 KiB
Diff
From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
|
|
From: MrPowerGamerBR <git@mrpowergamerbr.com>
|
|
Date: Fri, 13 Dec 2024 16:35:03 -0300
|
|
Subject: [PATCH] Extend AsyncPlayerPreLoginEvent to allow plugins to send
|
|
Login Plugin Requests to the client
|
|
|
|
|
|
diff --git a/src/main/java/net/sparklypower/sparklypaper/PendingConnection.java b/src/main/java/net/sparklypower/sparklypaper/PendingConnection.java
|
|
new file mode 100644
|
|
index 0000000000000000000000000000000000000000..11d64d825c15c122192359b86561808d0d7f5fbb
|
|
--- /dev/null
|
|
+++ b/src/main/java/net/sparklypower/sparklypaper/PendingConnection.java
|
|
@@ -0,0 +1,41 @@
|
|
+package net.sparklypower.sparklypaper;
|
|
+
|
|
+import org.bukkit.NamespacedKey;
|
|
+import org.jetbrains.annotations.NotNull;
|
|
+
|
|
+import java.util.concurrent.CompletableFuture;
|
|
+
|
|
+public interface PendingConnection {
|
|
+ /**
|
|
+ * Sends a login plugin request to the client, the client must reply with a login plugin response.
|
|
+ * <br>
|
|
+ * The vanilla client always replies with "not acknowledged", however mods, and proxies, can change
|
|
+ * the response.
|
|
+ *
|
|
+ * @param transactionId the ID of the transaction, must be unique for each connection
|
|
+ * @param channel the chanenl where the data will be sent
|
|
+ * @param data the data that will be sent
|
|
+ * @return a {@link CompletableFuture} that will be completed when the
|
|
+ * login plugin response is received or otherwise available.
|
|
+ */
|
|
+ @NotNull
|
|
+ CompletableFuture<PendingConnection.LoginPluginResponse> sendLoginPluginRequest(int transactionId, @NotNull NamespacedKey channel, byte @NotNull [] data);
|
|
+
|
|
+ class LoginPluginResponse {
|
|
+ final boolean acknowledged;
|
|
+ final byte[] response;
|
|
+
|
|
+ public LoginPluginResponse(boolean acknowledged, byte[] response) {
|
|
+ this.acknowledged = acknowledged;
|
|
+ this.response = response;
|
|
+ }
|
|
+
|
|
+ public boolean isAcknowledged() {
|
|
+ return acknowledged;
|
|
+ }
|
|
+
|
|
+ public byte[] getResponse() {
|
|
+ return response;
|
|
+ }
|
|
+ }
|
|
+}
|
|
diff --git a/src/main/java/org/bukkit/event/player/AsyncPlayerPreLoginEvent.java b/src/main/java/org/bukkit/event/player/AsyncPlayerPreLoginEvent.java
|
|
index ff5cca4a7e75274b4b278a48ae1544ff42a9836a..2ace8261a836dbdf44b35cdedb53c4b5b2986f0f 100644
|
|
--- a/src/main/java/org/bukkit/event/player/AsyncPlayerPreLoginEvent.java
|
|
+++ b/src/main/java/org/bukkit/event/player/AsyncPlayerPreLoginEvent.java
|
|
@@ -27,6 +27,7 @@ public class AsyncPlayerPreLoginEvent extends Event {
|
|
private final InetAddress rawAddress; // Paper
|
|
private final String hostname; // Paper
|
|
private final boolean transferred;
|
|
+ private net.sparklypower.sparklypaper.PendingConnection pendingConnection; // SparklyPaper - Add support for login plugin requests
|
|
|
|
@Deprecated(since = "1.7.5")
|
|
public AsyncPlayerPreLoginEvent(@NotNull final String name, @NotNull final InetAddress ipAddress) {
|
|
@@ -53,8 +54,15 @@ public class AsyncPlayerPreLoginEvent extends Event {
|
|
this(name, ipAddress, rawAddress, uniqueId, transferred, profile, "");
|
|
}
|
|
|
|
+ // SparklyPaper start - Add support for login plugin requests
|
|
@org.jetbrains.annotations.ApiStatus.Internal
|
|
public AsyncPlayerPreLoginEvent(@NotNull final String name, @NotNull final InetAddress ipAddress, @NotNull final InetAddress rawAddress, @NotNull final UUID uniqueId, boolean transferred, @NotNull com.destroystokyo.paper.profile.PlayerProfile profile, @NotNull String hostname) {
|
|
+ this(name, ipAddress, rawAddress, uniqueId, transferred, profile, hostname, null);
|
|
+ }
|
|
+
|
|
+ @org.jetbrains.annotations.ApiStatus.Internal
|
|
+ public AsyncPlayerPreLoginEvent(@NotNull final String name, @NotNull final InetAddress ipAddress, @NotNull final InetAddress rawAddress, @NotNull final UUID uniqueId, boolean transferred, @NotNull com.destroystokyo.paper.profile.PlayerProfile profile, @NotNull String hostname, @NotNull net.sparklypower.sparklypaper.PendingConnection pendingConnection) {
|
|
+ // SparklyPaper end
|
|
// Paper end
|
|
super(true);
|
|
this.result = Result.ALLOWED;
|
|
@@ -64,6 +72,7 @@ public class AsyncPlayerPreLoginEvent extends Event {
|
|
this.rawAddress = rawAddress; // Paper
|
|
this.hostname = hostname; // Paper
|
|
this.transferred = transferred;
|
|
+ this.pendingConnection = pendingConnection; // SparklyPaper - Add support for login plugin requests
|
|
}
|
|
|
|
/**
|
|
@@ -297,6 +306,18 @@ public class AsyncPlayerPreLoginEvent extends Event {
|
|
return transferred;
|
|
}
|
|
|
|
+ // SparklyPaper start - Add support for login plugin requests
|
|
+
|
|
+ /**
|
|
+ * Gets the pending connection associated with this event.
|
|
+ *
|
|
+ * @return The pending connection
|
|
+ */
|
|
+ public net.sparklypower.sparklypaper.PendingConnection getPendingConnection() {
|
|
+ return this.pendingConnection;
|
|
+ }
|
|
+ // SparklyPaper end
|
|
+
|
|
@NotNull
|
|
@Override
|
|
public HandlerList getHandlers() {
|