Move the double call into the dispatch method
At some point later,
This commit is contained in:
@@ -230,11 +230,13 @@ public interface Messenger {
|
||||
* @param source Source of the message.
|
||||
* @param channel Channel that the message was sent by.
|
||||
* @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);
|
||||
|
||||
/**
|
||||
* 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 channel Channel that the message was sent by.
|
||||
|
||||
@@ -1,6 +1,5 @@
|
||||
package org.bukkit.plugin.messaging;
|
||||
|
||||
import io.papermc.paper.connection.PlayerCommonConnection;
|
||||
import io.papermc.paper.connection.PlayerConnection;
|
||||
import org.bukkit.entity.Player;
|
||||
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
|
||||
* of messages sent from a client.
|
||||
*/
|
||||
@FunctionalInterface
|
||||
public interface PluginMessageListener {
|
||||
|
||||
/**
|
||||
* A method that will be thrown when a PluginMessageSource sends a plugin
|
||||
* message on a registered channel.
|
||||
* <p>
|
||||
* Only called for joined players.
|
||||
*
|
||||
* @param channel Channel that the message was sent through.
|
||||
* @param player Source of the message.
|
||||
* @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
|
||||
* 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 connection Source of the message.
|
||||
@@ -32,6 +37,5 @@ public interface PluginMessageListener {
|
||||
*/
|
||||
@ApiStatus.Experimental
|
||||
default void onPluginMessageReceived(@NotNull String channel, @NotNull PlayerConnection connection, byte @NotNull [] message) {
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@@ -2,6 +2,7 @@ package org.bukkit.plugin.messaging;
|
||||
|
||||
import com.google.common.collect.ImmutableSet;
|
||||
import com.google.common.collect.ImmutableSet.Builder;
|
||||
import io.papermc.paper.connection.PlayerGameConnection;
|
||||
import java.util.HashMap;
|
||||
import java.util.HashSet;
|
||||
import java.util.Locale;
|
||||
@@ -440,6 +441,7 @@ public class StandardMessenger implements Messenger {
|
||||
}
|
||||
|
||||
@Override
|
||||
@Deprecated
|
||||
public void dispatchIncomingMessage(@NotNull Player source, @NotNull String channel, byte @NotNull [] message) {
|
||||
if (source == null) {
|
||||
throw new IllegalArgumentException("Player source cannot be null");
|
||||
@@ -478,6 +480,9 @@ public class StandardMessenger implements Messenger {
|
||||
for (PluginMessageListenerRegistration registration : registrations) {
|
||||
try {
|
||||
registration.getListener().onPluginMessageReceived(channel, source, message);
|
||||
if (source instanceof PlayerGameConnection gameConnection) {
|
||||
registration.getListener().onPluginMessageReceived(channel, gameConnection.getPlayer(), message);
|
||||
}
|
||||
} catch (Throwable t) {
|
||||
registration.getPlugin().getLogger().log(Level.WARNING,
|
||||
String.format("Plugin %s generated an exception whilst handling plugin message",
|
||||
|
||||
Reference in New Issue
Block a user