SendMessageCommand.java 1.23 KB
Newer Older
KingRainbow44's avatar
KingRainbow44 committed
1
2
package emu.grasscutter.command.commands;

3
import emu.grasscutter.Grasscutter;
KingRainbow44's avatar
KingRainbow44 committed
4
5
import emu.grasscutter.command.Command;
import emu.grasscutter.command.CommandHandler;
6
import emu.grasscutter.command.Command.TargetRequirement;
Melledy's avatar
Melledy committed
7
import emu.grasscutter.game.player.Player;
KingRainbow44's avatar
KingRainbow44 committed
8
9
10

import java.util.List;

11
12
13
14
15
16
17
@Command(
    label = "sendMessage",
    aliases = {"say", "sendservmsg", "sendservermessage", "b", "broadcast"},
    usage = {"<message>"},
    permission = "server.sendmessage",
    permissionTargeted = "server.sendmessage.others",
    targetRequirement = TargetRequirement.NONE)
KingRainbow44's avatar
KingRainbow44 committed
18
19
20
public final class SendMessageCommand implements CommandHandler {

    @Override
AnimeGitB's avatar
AnimeGitB committed
21
    public void execute(Player sender, Player targetPlayer, List<String> args) {
AnimeGitB's avatar
AnimeGitB committed
22
        if (args.size() == 0) {
23
            sendUsageMessage(sender);
KingRainbow44's avatar
KingRainbow44 committed
24
25
26
            return;
        }

AnimeGitB's avatar
AnimeGitB committed
27
        String message = String.join(" ", args);
28
29
30
31
32
33
34
35

        if (targetPlayer == null) {
            for (Player p : Grasscutter.getGameServer().getPlayers().values()) {
                CommandHandler.sendMessage(p, message);
            }
        } else {
            CommandHandler.sendMessage(targetPlayer, message);
        }
36
        CommandHandler.sendTranslatedMessage(sender, "commands.sendMessage.success");
KingRainbow44's avatar
KingRainbow44 committed
37
    }
Secretboy's avatar
Secretboy committed
38
}