mirror of
https://github.com/Melledy/Grasscutter.git
synced 2024-11-27 01:33:16 +00:00
Replace CommandResponseEvent
with ReceiveCommandFeedbackEvent
This commit is contained in:
parent
1621e34e6f
commit
7f584f7a85
@ -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,15 +18,21 @@ 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) {
|
||||||
if (player == null) {
|
// Call command feedback event.
|
||||||
Grasscutter.getLogger().info(message);
|
ReceiveCommandFeedbackEvent event = new ReceiveCommandFeedbackEvent(player, message);
|
||||||
} else {
|
|
||||||
player.dropMessage(message);
|
|
||||||
}
|
|
||||||
CommandResponseEvent event = new CommandResponseEvent(ServerEvent.Type.GAME,player, message);
|
|
||||||
event.call();
|
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) {
|
static void sendTranslatedMessage(Player player, String messageKey, Object... args) {
|
||||||
sendMessage(player, translate(player, messageKey, args));
|
sendMessage(player, translate(player, messageKey, args));
|
||||||
}
|
}
|
||||||
|
@ -1,9 +1,12 @@
|
|||||||
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;
|
||||||
|
@ -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;
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in New Issue
Block a user