diff --git a/src/main/java/emu/grasscutter/command/CommandHandler.java b/src/main/java/emu/grasscutter/command/CommandHandler.java index 66553d60a..4803b154f 100644 --- a/src/main/java/emu/grasscutter/command/CommandHandler.java +++ b/src/main/java/emu/grasscutter/command/CommandHandler.java @@ -3,6 +3,7 @@ package emu.grasscutter.command; import emu.grasscutter.Grasscutter; import emu.grasscutter.game.player.Player; import emu.grasscutter.server.event.game.CommandResponseEvent; +import emu.grasscutter.server.event.game.ReceiveCommandFeedbackEvent; import emu.grasscutter.server.event.types.ServerEvent; import static emu.grasscutter.utils.Language.translate; @@ -17,15 +18,21 @@ public interface CommandHandler { * @param message The message to send. */ static void sendMessage(Player player, String message) { - if (player == null) { - Grasscutter.getLogger().info(message); - } else { - player.dropMessage(message); - } - CommandResponseEvent event = new CommandResponseEvent(ServerEvent.Type.GAME,player, message); + // Call command feedback event. + ReceiveCommandFeedbackEvent event = new ReceiveCommandFeedbackEvent(player, message); event.call(); + if (event.isCanceled()) { // If event is not cancelled, continue. + return; + } + + // Send message to target. + if (player == null) { + Grasscutter.getLogger().info(event.getMessage()); + } else { + player.dropMessage(event.getMessage()); + } } - + static void sendTranslatedMessage(Player player, String messageKey, Object... args) { sendMessage(player, translate(player, messageKey, args)); } diff --git a/src/main/java/emu/grasscutter/server/event/game/CommandResponseEvent.java b/src/main/java/emu/grasscutter/server/event/game/CommandResponseEvent.java index c3c8fd89a..1319bcb85 100644 --- a/src/main/java/emu/grasscutter/server/event/game/CommandResponseEvent.java +++ b/src/main/java/emu/grasscutter/server/event/game/CommandResponseEvent.java @@ -1,9 +1,12 @@ package emu.grasscutter.server.event.game; import emu.grasscutter.game.player.Player; -import emu.grasscutter.server.event.types.GameEvent; import emu.grasscutter.server.event.types.ServerEvent; +/** + * @deprecated Will be removed in 1.2.3-dev or 1.3.0. + */ +@Deprecated(since = "1.2.2-dev", forRemoval = true) public class CommandResponseEvent extends ServerEvent { private String message; private Player player; diff --git a/src/main/java/emu/grasscutter/server/event/game/ReceiveCommandFeedbackEvent.java b/src/main/java/emu/grasscutter/server/event/game/ReceiveCommandFeedbackEvent.java new file mode 100644 index 000000000..734f891ea --- /dev/null +++ b/src/main/java/emu/grasscutter/server/event/game/ReceiveCommandFeedbackEvent.java @@ -0,0 +1,33 @@ +package emu.grasscutter.server.event.game; + +import emu.grasscutter.game.player.Player; +import emu.grasscutter.server.event.Cancellable; +import emu.grasscutter.server.event.types.ServerEvent; + +import javax.annotation.Nullable; + +public final class ReceiveCommandFeedbackEvent extends ServerEvent implements Cancellable { + @Nullable + private final Player player; + private String message; + + public ReceiveCommandFeedbackEvent(@Nullable Player player, String message) { + super(Type.GAME); + + this.player = player; + this.message = message; + } + + public void setMessage(String message) { + this.message = message; + } + + public String getMessage() { + return this.message; + } + + @Nullable + public Player getPlayer() { + return this.player; + } +} \ No newline at end of file