Replace CommandResponseEvent with ReceiveCommandFeedbackEvent

This commit is contained in:
KingRainbow44 2022-06-24 01:06:19 -04:00
parent 1621e34e6f
commit 7f584f7a85
No known key found for this signature in database
GPG Key ID: FC2CB64B00D257BE
3 changed files with 51 additions and 8 deletions

View File

@ -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 {
* @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) {

View File

@ -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;

View File

@ -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;
}
}