2022-04-20 20:21:38 +08:00
|
|
|
package emu.grasscutter.command;
|
|
|
|
|
|
|
|
import emu.grasscutter.Grasscutter;
|
2022-04-27 12:24:25 +08:00
|
|
|
import emu.grasscutter.game.player.Player;
|
2022-05-18 00:24:01 +08:00
|
|
|
import emu.grasscutter.server.event.game.CommandResponseEvent;
|
2022-06-24 13:06:19 +08:00
|
|
|
import emu.grasscutter.server.event.game.ReceiveCommandFeedbackEvent;
|
2022-05-18 00:24:01 +08:00
|
|
|
import emu.grasscutter.server.event.types.ServerEvent;
|
2022-05-22 16:02:11 +08:00
|
|
|
import static emu.grasscutter.utils.Language.translate;
|
2022-04-20 20:21:38 +08:00
|
|
|
|
|
|
|
import java.util.List;
|
|
|
|
|
|
|
|
public interface CommandHandler {
|
2022-05-08 10:33:53 +08:00
|
|
|
|
2022-04-20 20:21:38 +08:00
|
|
|
/**
|
|
|
|
* Send a message to the target.
|
|
|
|
*
|
|
|
|
* @param player The player to send the message to, or null for the server console.
|
|
|
|
* @param message The message to send.
|
|
|
|
*/
|
2022-04-27 12:21:57 +08:00
|
|
|
static void sendMessage(Player player, String message) {
|
2022-06-24 13:06:19 +08:00
|
|
|
// 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.
|
2022-04-20 20:21:38 +08:00
|
|
|
if (player == null) {
|
2022-06-24 13:06:19 +08:00
|
|
|
Grasscutter.getLogger().info(event.getMessage());
|
2022-04-20 20:21:38 +08:00
|
|
|
} else {
|
2022-06-24 13:06:19 +08:00
|
|
|
player.dropMessage(event.getMessage());
|
2022-04-20 20:21:38 +08:00
|
|
|
}
|
|
|
|
}
|
2022-06-24 13:06:19 +08:00
|
|
|
|
2022-05-22 16:02:11 +08:00
|
|
|
static void sendTranslatedMessage(Player player, String messageKey, Object... args) {
|
|
|
|
sendMessage(player, translate(player, messageKey, args));
|
|
|
|
}
|
2022-04-20 20:21:38 +08:00
|
|
|
|
2022-04-21 00:17:56 +08:00
|
|
|
/**
|
|
|
|
* Called when a player/console invokes a command.
|
|
|
|
* @param sender The player/console that invoked the command.
|
|
|
|
* @param args The arguments to the command.
|
|
|
|
*/
|
2022-05-04 14:32:09 +08:00
|
|
|
default void execute(Player sender, Player targetPlayer, List<String> args) {
|
2022-04-20 20:21:38 +08:00
|
|
|
}
|
|
|
|
}
|