Skip to content

Commit 846c64f

Browse files
authored
Allow for sending plugin messages during configuration stage (#12915)
1 parent e938088 commit 846c64f

File tree

5 files changed

+39
-4
lines changed

5 files changed

+39
-4
lines changed

paper-api/src/main/java/io/papermc/paper/connection/PlayerCommonConnection.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,12 @@
44

55
import com.destroystokyo.paper.ClientOption;
66
import org.bukkit.ServerLinks;
7+
import org.bukkit.plugin.messaging.PluginMessageRecipient;
78

89
/**
910
* Represents a connection that has properties shared between the GAME and CONFIG stage.
1011
*/
11-
public interface PlayerCommonConnection extends WritablePlayerCookieConnection, ReadablePlayerCookieConnection {
12+
public interface PlayerCommonConnection extends WritablePlayerCookieConnection, ReadablePlayerCookieConnection, PluginMessageRecipient {
1213

1314
/**
1415
* Sends data to appear in this connection's report logs.

paper-server/patches/features/0032-Improve-keepalive-ping-system.patch

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -100,7 +100,7 @@ index 962084054c0208470d0c3c99c5dca6327c9b8752..2abc21102bbd2da79dc0c50826cff7da
100100
}
101101
}
102102
diff --git a/net/minecraft/server/network/ServerCommonPacketListenerImpl.java b/net/minecraft/server/network/ServerCommonPacketListenerImpl.java
103-
index 1b42d5e9f9fd07f99009de6f4483648f416db733..08c59d603fca038fc2dde36384eea1b6c971e659 100644
103+
index 5e074e6b5b8699b5c978a31518775479a43266ac..07c4a25c121676db867e8fb438ba41ad58528a4d 100644
104104
--- a/net/minecraft/server/network/ServerCommonPacketListenerImpl.java
105105
+++ b/net/minecraft/server/network/ServerCommonPacketListenerImpl.java
106106
@@ -38,12 +38,13 @@ public abstract class ServerCommonPacketListenerImpl implements ServerCommonPack
@@ -120,7 +120,7 @@ index 1b42d5e9f9fd07f99009de6f4483648f416db733..08c59d603fca038fc2dde36384eea1b6
120120
+ private final io.papermc.paper.util.KeepAlive keepAlive; // Paper - improve keepalives
121121
private volatile boolean suspendFlushingOnServerThread = false;
122122
// CraftBukkit start
123-
protected final org.bukkit.craftbukkit.CraftServer cserver;
123+
public final org.bukkit.craftbukkit.CraftServer cserver;
124124
@@ -60,13 +61,14 @@ public abstract class ServerCommonPacketListenerImpl implements ServerCommonPack
125125
public ServerCommonPacketListenerImpl(MinecraftServer server, Connection connection, CommonListenerCookie cookie) {
126126
this.server = server;

paper-server/patches/sources/net/minecraft/server/network/ServerCommonPacketListenerImpl.java.patch

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
private int latency;
1515
private volatile boolean suspendFlushingOnServerThread = false;
1616
+ // CraftBukkit start
17-
+ protected final org.bukkit.craftbukkit.CraftServer cserver;
17+
+ public final org.bukkit.craftbukkit.CraftServer cserver;
1818
+ public boolean processedDisconnect;
1919
+ // CraftBukkit end
2020
+ public final java.util.Map<java.util.UUID, net.kyori.adventure.resource.ResourcePackCallback> packCallbacks = new java.util.concurrent.ConcurrentHashMap<>(); // Paper - adventure resource pack callbacks

paper-server/src/main/java/io/papermc/paper/connection/PaperPlayerConfigurationConnection.java

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,13 +20,18 @@
2020
import net.kyori.adventure.resource.ResourcePackRequest;
2121
import net.minecraft.network.chat.Component;
2222
import net.minecraft.network.protocol.common.ClientboundClearDialogPacket;
23+
import net.minecraft.network.protocol.common.ClientboundCustomPayloadPacket;
2324
import net.minecraft.network.protocol.common.ClientboundResourcePackPopPacket;
2425
import net.minecraft.network.protocol.common.ClientboundResourcePackPushPacket;
2526
import net.minecraft.network.protocol.common.ClientboundShowDialogPacket;
27+
import net.minecraft.network.protocol.common.custom.DiscardedPayload;
2628
import net.minecraft.network.protocol.configuration.ClientboundResetChatPacket;
29+
import net.minecraft.resources.ResourceLocation;
2730
import net.minecraft.server.level.ClientInformation;
2831
import net.minecraft.server.network.ConfigurationTask;
2932
import net.minecraft.server.network.ServerConfigurationPacketListenerImpl;
33+
import org.bukkit.plugin.Plugin;
34+
import org.bukkit.plugin.messaging.StandardMessenger;
3035
import org.jspecify.annotations.Nullable;
3136

3237
public class PaperPlayerConfigurationConnection extends PaperCommonConnection<ServerConfigurationPacketListenerImpl> implements PlayerConfigurationConnection, Audience, PluginMessageBridgeImpl {
@@ -122,4 +127,21 @@ public void completeReconfiguration() {
122127
public Set<String> channels() {
123128
return this.handle.pluginMessagerChannels;
124129
}
130+
131+
@Override
132+
public void sendPluginMessage(final Plugin source, final String channel, final byte[] message) {
133+
StandardMessenger.validatePluginMessage(this.handle.cserver.getMessenger(), source, channel, message);
134+
135+
if (this.channels().contains(channel)) {
136+
@SuppressWarnings("deprecation") // "not an API method" does not apply to us
137+
ResourceLocation id = ResourceLocation.parse(StandardMessenger.validateAndCorrectChannel(channel));
138+
ClientboundCustomPayloadPacket packet = new ClientboundCustomPayloadPacket(new DiscardedPayload(id, message));
139+
this.handle.send(packet);
140+
}
141+
}
142+
143+
@Override
144+
public Set<String> getListeningPluginChannels() {
145+
return Set.copyOf(this.channels());
146+
}
125147
}

paper-server/src/main/java/io/papermc/paper/connection/PaperPlayerGameConnection.java

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@
33
import net.minecraft.server.level.ClientInformation;
44
import net.minecraft.server.network.ServerGamePacketListenerImpl;
55
import org.bukkit.entity.Player;
6+
import org.bukkit.plugin.Plugin;
7+
import java.util.Set;
68

79
public class PaperPlayerGameConnection extends PaperCommonConnection<ServerGamePacketListenerImpl> implements PlayerGameConnection {
810

@@ -28,4 +30,14 @@ public void reenterConfiguration() {
2830
public Player getPlayer() {
2931
return this.handle.getCraftPlayer();
3032
}
33+
34+
@Override
35+
public void sendPluginMessage(final Plugin source, final String channel, final byte[] message) {
36+
getPlayer().sendPluginMessage(source, channel, message);
37+
}
38+
39+
@Override
40+
public Set<String> getListeningPluginChannels() {
41+
return getPlayer().getListeningPluginChannels();
42+
}
3143
}

0 commit comments

Comments
 (0)