Commit a1681255 authored by KingRainbow44's avatar KingRainbow44
Browse files

Replace `CommandResponseEvent` with `ReceiveCommandFeedbackEvent`

parent 74151c20
...@@ -3,6 +3,7 @@ package emu.grasscutter.command; ...@@ -3,6 +3,7 @@ package emu.grasscutter.command;
import emu.grasscutter.Grasscutter; import emu.grasscutter.Grasscutter;
import emu.grasscutter.game.player.Player; import emu.grasscutter.game.player.Player;
import emu.grasscutter.server.event.game.CommandResponseEvent; import emu.grasscutter.server.event.game.CommandResponseEvent;
import emu.grasscutter.server.event.game.ReceiveCommandFeedbackEvent;
import emu.grasscutter.server.event.types.ServerEvent; import emu.grasscutter.server.event.types.ServerEvent;
import static emu.grasscutter.utils.Language.translate; import static emu.grasscutter.utils.Language.translate;
...@@ -17,13 +18,19 @@ public interface CommandHandler { ...@@ -17,13 +18,19 @@ public interface CommandHandler {
* @param message The message to send. * @param message The message to send.
*/ */
static void sendMessage(Player player, String message) { static void sendMessage(Player player, String 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) { if (player == null) {
Grasscutter.getLogger().info(message); Grasscutter.getLogger().info(event.getMessage());
} else { } else {
player.dropMessage(message); player.dropMessage(event.getMessage());
} }
CommandResponseEvent event = new CommandResponseEvent(ServerEvent.Type.GAME,player, message);
event.call();
} }
static void sendTranslatedMessage(Player player, String messageKey, Object... args) { static void sendTranslatedMessage(Player player, String messageKey, Object... args) {
......
package emu.grasscutter.server.event.game; package emu.grasscutter.server.event.game;
import emu.grasscutter.game.player.Player; import emu.grasscutter.game.player.Player;
import emu.grasscutter.server.event.types.GameEvent;
import emu.grasscutter.server.event.types.ServerEvent; 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 { public class CommandResponseEvent extends ServerEvent {
private String message; private String message;
private Player player; private Player player;
......
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
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment