Move the double call into the dispatch method

At some point later,
This commit is contained in:
Nassim Jahnke
2025-07-01 21:44:24 +02:00
parent c3be00f0ec
commit 3fec37a9c1
7 changed files with 21 additions and 25 deletions

View File

@@ -230,11 +230,13 @@ public interface Messenger {
* @param source Source of the message. * @param source Source of the message.
* @param channel Channel that the message was sent by. * @param channel Channel that the message was sent by.
* @param message Raw payload of the message. * @param message Raw payload of the message.
* @deprecated only calls the {@link Player} version of onPluginMessageReceived, use {@link #dispatchIncomingMessage(PlayerConnection, String, byte[])} instead to call both.
*/ */
@Deprecated
public void dispatchIncomingMessage(@NotNull Player source, @NotNull String channel, byte @NotNull [] message); public void dispatchIncomingMessage(@NotNull Player source, @NotNull String channel, byte @NotNull [] message);
/** /**
* Dispatches the specified incoming message to any registered listeners. * Dispatches the specified incoming message to any registered listeners. By default, also calls {@link PluginMessageListener#onPluginMessageReceived(String, Player, byte[])}.
* *
* @param source Source of the message. * @param source Source of the message.
* @param channel Channel that the message was sent by. * @param channel Channel that the message was sent by.

View File

@@ -1,6 +1,5 @@
package org.bukkit.plugin.messaging; package org.bukkit.plugin.messaging;
import io.papermc.paper.connection.PlayerCommonConnection;
import io.papermc.paper.connection.PlayerConnection; import io.papermc.paper.connection.PlayerConnection;
import org.bukkit.entity.Player; import org.bukkit.entity.Player;
import org.jetbrains.annotations.ApiStatus; import org.jetbrains.annotations.ApiStatus;
@@ -10,21 +9,27 @@ import org.jetbrains.annotations.NotNull;
* A listener for a specific Plugin Channel, which will receive notifications * A listener for a specific Plugin Channel, which will receive notifications
* of messages sent from a client. * of messages sent from a client.
*/ */
@FunctionalInterface
public interface PluginMessageListener { public interface PluginMessageListener {
/** /**
* A method that will be thrown when a PluginMessageSource sends a plugin * A method that will be thrown when a PluginMessageSource sends a plugin
* message on a registered channel. * message on a registered channel.
* <p>
* Only called for joined players.
* *
* @param channel Channel that the message was sent through. * @param channel Channel that the message was sent through.
* @param player Source of the message. * @param player Source of the message.
* @param message The raw message that was sent. * @param message The raw message that was sent.
* @see #onPluginMessageReceived(String, PlayerConnection, byte[]) for a method that is called for both joined and configuring players
*/ */
public void onPluginMessageReceived(@NotNull String channel, @NotNull Player player, byte @NotNull [] message); void onPluginMessageReceived(@NotNull String channel, @NotNull Player player, byte @NotNull [] message);
/** /**
* A method that will be invoked when a PluginMessageSource sends a plugin * A method that will be invoked when a PluginMessageSource sends a plugin
* message on a registered channel. * message on a registered channel.
* <p>
* Called for both joined players and players in the configuration stage.
* *
* @param channel Channel that the message was sent through. * @param channel Channel that the message was sent through.
* @param connection Source of the message. * @param connection Source of the message.
@@ -32,6 +37,5 @@ public interface PluginMessageListener {
*/ */
@ApiStatus.Experimental @ApiStatus.Experimental
default void onPluginMessageReceived(@NotNull String channel, @NotNull PlayerConnection connection, byte @NotNull [] message) { default void onPluginMessageReceived(@NotNull String channel, @NotNull PlayerConnection connection, byte @NotNull [] message) {
} }
} }

View File

@@ -2,6 +2,7 @@ package org.bukkit.plugin.messaging;
import com.google.common.collect.ImmutableSet; import com.google.common.collect.ImmutableSet;
import com.google.common.collect.ImmutableSet.Builder; import com.google.common.collect.ImmutableSet.Builder;
import io.papermc.paper.connection.PlayerGameConnection;
import java.util.HashMap; import java.util.HashMap;
import java.util.HashSet; import java.util.HashSet;
import java.util.Locale; import java.util.Locale;
@@ -440,6 +441,7 @@ public class StandardMessenger implements Messenger {
} }
@Override @Override
@Deprecated
public void dispatchIncomingMessage(@NotNull Player source, @NotNull String channel, byte @NotNull [] message) { public void dispatchIncomingMessage(@NotNull Player source, @NotNull String channel, byte @NotNull [] message) {
if (source == null) { if (source == null) {
throw new IllegalArgumentException("Player source cannot be null"); throw new IllegalArgumentException("Player source cannot be null");
@@ -478,6 +480,9 @@ public class StandardMessenger implements Messenger {
for (PluginMessageListenerRegistration registration : registrations) { for (PluginMessageListenerRegistration registration : registrations) {
try { try {
registration.getListener().onPluginMessageReceived(channel, source, message); registration.getListener().onPluginMessageReceived(channel, source, message);
if (source instanceof PlayerGameConnection gameConnection) {
registration.getListener().onPluginMessageReceived(channel, gameConnection.getPlayer(), message);
}
} catch (Throwable t) { } catch (Throwable t) {
registration.getPlugin().getLogger().log(Level.WARNING, registration.getPlugin().getLogger().log(Level.WARNING,
String.format("Plugin %s generated an exception whilst handling plugin message", String.format("Plugin %s generated an exception whilst handling plugin message",

View File

@@ -100,7 +100,7 @@ index 962084054c0208470d0c3c99c5dca6327c9b8752..2abc21102bbd2da79dc0c50826cff7da
} }
} }
diff --git a/net/minecraft/server/network/ServerCommonPacketListenerImpl.java b/net/minecraft/server/network/ServerCommonPacketListenerImpl.java diff --git a/net/minecraft/server/network/ServerCommonPacketListenerImpl.java b/net/minecraft/server/network/ServerCommonPacketListenerImpl.java
index b2b5fe493f71d7300e5009ae0307dbfd8da99991..27b8ce14ad51566155e457279ec3db1c4b755da7 100644 index 140f0ac42626662354e9b5386d91f1b096a945a3..2e7c4c74818befd25e296b58ef9f20319544c2fb 100644
--- a/net/minecraft/server/network/ServerCommonPacketListenerImpl.java --- a/net/minecraft/server/network/ServerCommonPacketListenerImpl.java
+++ b/net/minecraft/server/network/ServerCommonPacketListenerImpl.java +++ b/net/minecraft/server/network/ServerCommonPacketListenerImpl.java
@@ -38,12 +38,13 @@ public abstract class ServerCommonPacketListenerImpl implements ServerCommonPack @@ -38,12 +38,13 @@ public abstract class ServerCommonPacketListenerImpl implements ServerCommonPack
@@ -185,7 +185,7 @@ index b2b5fe493f71d7300e5009ae0307dbfd8da99991..27b8ce14ad51566155e457279ec3db1c
} }
@Override @Override
@@ -224,20 +254,23 @@ public abstract class ServerCommonPacketListenerImpl implements ServerCommonPack @@ -220,20 +250,23 @@ public abstract class ServerCommonPacketListenerImpl implements ServerCommonPack
protected void keepConnectionAlive() { protected void keepConnectionAlive() {
Profiler.get().push("keepAlive"); Profiler.get().push("keepAlive");
long millis = Util.getMillis(); long millis = Util.getMillis();
@@ -223,7 +223,7 @@ index b2b5fe493f71d7300e5009ae0307dbfd8da99991..27b8ce14ad51566155e457279ec3db1c
} }
} }
@@ -417,6 +450,6 @@ public abstract class ServerCommonPacketListenerImpl implements ServerCommonPack @@ -413,6 +446,6 @@ public abstract class ServerCommonPacketListenerImpl implements ServerCommonPack
} }
protected CommonListenerCookie createCookie(ClientInformation clientInformation) { protected CommonListenerCookie createCookie(ClientInformation clientInformation) {

View File

@@ -48,7 +48,7 @@
} }
} }
@@ -90,8 +_,80 @@ @@ -90,8 +_,76 @@
public void handlePong(ServerboundPongPacket packet) { public void handlePong(ServerboundPongPacket packet) {
} }
@@ -92,11 +92,7 @@
+ this.playerBrand = new net.minecraft.network.FriendlyByteBuf(io.netty.buffer.Unpooled.wrappedBuffer(data)).readUtf(256); + this.playerBrand = new net.minecraft.network.FriendlyByteBuf(io.netty.buffer.Unpooled.wrappedBuffer(data)).readUtf(256);
+ } + }
+ +
+
+ this.cserver.getMessenger().dispatchIncomingMessage(paperConnection(), identifier.toString(), data); + this.cserver.getMessenger().dispatchIncomingMessage(paperConnection(), identifier.toString(), data);
+ if (this instanceof ServerGamePacketListenerImpl gamePacketListener) {
+ this.cserver.getMessenger().dispatchIncomingMessage(gamePacketListener.player.getBukkitEntity(), identifier.toString(), data);
+ }
+ } catch (final Exception e) { + } catch (final Exception e) {
+ ServerGamePacketListenerImpl.LOGGER.error("Couldn't handle custom payload on channel {}", identifier, e); + ServerGamePacketListenerImpl.LOGGER.error("Couldn't handle custom payload on channel {}", identifier, e);
+ this.disconnect(net.minecraft.network.chat.Component.literal("Invalid custom payload payload!"), io.papermc.paper.connection.DisconnectionReason.INVALID_PAYLOAD); // Paper - kick event cause + this.disconnect(net.minecraft.network.chat.Component.literal("Invalid custom payload payload!"), io.papermc.paper.connection.DisconnectionReason.INVALID_PAYLOAD); // Paper - kick event cause

View File

@@ -99,7 +99,7 @@
this.connection.send(new ClientboundDisconnectPacket(DISCONNECT_REASON_INVALID_DATA)); this.connection.send(new ClientboundDisconnectPacket(DISCONNECT_REASON_INVALID_DATA));
this.connection.disconnect(DISCONNECT_REASON_INVALID_DATA); this.connection.disconnect(DISCONNECT_REASON_INVALID_DATA);
} }
@@ -180,4 +_,35 @@ @@ -180,4 +_,29 @@
this.startNextTask(); this.startNextTask();
} }
} }
@@ -119,11 +119,6 @@
+ } + }
+ +
+ @Override + @Override
+ public io.papermc.paper.connection.ReadablePlayerCookieConnectionImpl getCookieConnection() {
+ return this.paperConnection;
+ }
+
+ @Override
+ public void handleCustomPayload(net.minecraft.network.protocol.common.ServerboundCustomPayloadPacket packet) { + public void handleCustomPayload(net.minecraft.network.protocol.common.ServerboundCustomPayloadPacket packet) {
+ super.handleCustomPayload(packet); + super.handleCustomPayload(packet);
+ } + }
@@ -132,6 +127,5 @@
+ public io.papermc.paper.connection.PaperPlayerConfigurationConnection paperConnection() { + public io.papermc.paper.connection.PaperPlayerConfigurationConnection paperConnection() {
+ return paperConnection; + return paperConnection;
+ } + }
+
+ // Paper end + // Paper end
} }

View File

@@ -2610,7 +2610,7 @@
if (!this.receivedMovementThisTick) { if (!this.receivedMovementThisTick) {
this.player.setKnownMovement(Vec3.ZERO); this.player.setKnownMovement(Vec3.ZERO);
} }
@@ -2078,4 +_,97 @@ @@ -2078,4 +_,92 @@
interface EntityInteraction { interface EntityInteraction {
InteractionResult run(ServerPlayer player, Entity entity, InteractionHand hand); InteractionResult run(ServerPlayer player, Entity entity, InteractionHand hand);
} }
@@ -2698,11 +2698,6 @@
+ } + }
+ +
+ @Override + @Override
+ public io.papermc.paper.connection.ReadablePlayerCookieConnectionImpl getCookieConnection() {
+ return this.playerGameConnection;
+ }
+
+ @Override
+ public io.papermc.paper.connection.PaperPlayerGameConnection paperConnection() { + public io.papermc.paper.connection.PaperPlayerGameConnection paperConnection() {
+ return this.playerGameConnection; + return this.playerGameConnection;
+ } + }