DefaultPermissionHandler.java 1.1 KB
Newer Older
4Benj_'s avatar
4Benj_ 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
package emu.grasscutter.command;

import emu.grasscutter.game.Account;
import emu.grasscutter.game.player.Player;

public class DefaultPermissionHandler implements PermissionHandler {
    @Override
    public boolean EnablePermissionCommand() {
        return true;
    }

    @Override
    public boolean checkPermission(Player player, Player targetPlayer, String permissionNode, String permissionNodeTargeted) {
        if(player == null) {
            return true;
        }

        Account account = player.getAccount();
        if (player != targetPlayer) {  // Additional permission required for targeting another player
            if (!permissionNodeTargeted.isEmpty() && !account.hasPermission(permissionNodeTargeted)) {
                CommandHandler.sendTranslatedMessage(player, "commands.generic.permission_error");
                return false;
            }
        }
        if (!permissionNode.isEmpty() && !account.hasPermission(permissionNode)) {
            CommandHandler.sendTranslatedMessage(player, "commands.generic.permission_error");
            return false;
        }

        return true;
    }
}