CoopCommand.java 1.43 KB
Newer Older
Kengxxiao's avatar
Kengxxiao committed
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
package emu.grasscutter.command.commands;

import emu.grasscutter.command.Command;
import emu.grasscutter.command.CommandHandler;
import emu.grasscutter.game.player.Player;

import java.util.List;

@Command(label = "coop", usage = "coop",
        description = "Forces someone to join the world of others", permission = "server.coop")
public class CoopCommand implements CommandHandler {
    @Override
    public void execute(Player sender, List<String> args) {
        if (args.size() < 2) {
            CommandHandler.sendMessage(sender, "Usage: coop <playerId> <target playerId>");
            return;
        }
        try {
            int tid = Integer.parseInt(args.get(0));
            int hostId = Integer.parseInt(args.get(1));
            Player host = sender.getServer().getPlayerByUid(hostId);
            Player want = sender.getServer().getPlayerByUid(tid);
            if (host == null || want == null) {
                CommandHandler.sendMessage(sender, "Player is offline.");
                return;
            }
            if (want.isInMultiplayer()) {
                sender.getServer().getMultiplayerManager().leaveCoop(want);
            }
            sender.getServer().getMultiplayerManager().applyEnterMp(want, hostId);
            sender.getServer().getMultiplayerManager().applyEnterMpReply(host, tid, true);
        } catch (Exception e) {
            CommandHandler.sendMessage(sender, "Player id is not valid.");
        }
    }
}