CommandHandler.java 1.55 KB
Newer Older
Jaida Wu's avatar
Jaida Wu committed
1
2
3
package emu.grasscutter.command;

import emu.grasscutter.Grasscutter;
Melledy's avatar
Melledy committed
4
import emu.grasscutter.game.player.Player;
muhammadeko's avatar
muhammadeko committed
5
import emu.grasscutter.server.event.game.CommandResponseEvent;
6
import emu.grasscutter.server.event.game.ReceiveCommandFeedbackEvent;
muhammadeko's avatar
muhammadeko committed
7
import emu.grasscutter.server.event.types.ServerEvent;
8
import static emu.grasscutter.utils.Language.translate;
Jaida Wu's avatar
Jaida Wu committed
9
10
11
12

import java.util.List;

public interface CommandHandler {
13

Jaida Wu's avatar
Jaida Wu committed
14
15
16
17
18
19
    /**
     * 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.
     */
20
    static void sendMessage(Player player, String message) {
21
22
23
24
25
26
27
28
        // 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.
Jaida Wu's avatar
Jaida Wu committed
29
        if (player == null) {
30
            Grasscutter.getLogger().info(event.getMessage());
Jaida Wu's avatar
Jaida Wu committed
31
        } else {
32
            player.dropMessage(event.getMessage());
Jaida Wu's avatar
Jaida Wu committed
33
34
        }
    }
35

36
37
38
    static void sendTranslatedMessage(Player player, String messageKey, Object... args) {
        sendMessage(player, translate(player, messageKey, args));
    }
Jaida Wu's avatar
Jaida Wu committed
39

KingRainbow44's avatar
KingRainbow44 committed
40
41
42
43
44
    /**
     * Called when a player/console invokes a command.
     * @param sender The player/console that invoked the command.
     * @param args The arguments to the command.
     */
AnimeGitB's avatar
AnimeGitB committed
45
    default void execute(Player sender, Player targetPlayer, List<String> args) {
Jaida Wu's avatar
Jaida Wu committed
46
47
    }
}