execute(AdminPerformer,Void)   A
last analyzed

Complexity

Conditions 2

Size

Total Lines 10
Code Lines 7

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 5
CRAP Score 2

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 2
eloc 7
dl 0
loc 10
ccs 5
cts 5
cp 1
crap 2
rs 10
c 1
b 0
f 0
1
/*
2
 * This file is part of Araknemu.
3
 *
4
 * Araknemu is free software: you can redistribute it and/or modify
5
 * it under the terms of the GNU Lesser General Public License as published by
6
 * the Free Software Foundation, either version 3 of the License, or
7
 * (at your option) any later version.
8
 *
9
 * Araknemu is distributed in the hope that it will be useful,
10
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12
 * GNU Lesser General Public License for more details.
13
 *
14
 * You should have received a copy of the GNU Lesser General Public License
15
 * along with Araknemu.  If not, see <https://www.gnu.org/licenses/>.
16
 *
17
 * Copyright (c) 2017-2021 Vincent Quatrevieux
18
 */
19
20
package fr.quatrevieux.araknemu.game.admin.account;
21
22
import fr.quatrevieux.araknemu.common.account.Permission;
23
import fr.quatrevieux.araknemu.game.account.GameAccount;
24
import fr.quatrevieux.araknemu.game.admin.AbstractCommand;
25
import fr.quatrevieux.araknemu.game.admin.AdminPerformer;
26
import fr.quatrevieux.araknemu.game.admin.exception.AdminException;
27
28
/**
29
 * Command for revoke all temporary permissions
30
 */
31
public final class Revoke extends AbstractCommand<Void> {
32
    private final GameAccount account;
33
34 1
    public Revoke(GameAccount account) {
35 1
        this.account = account;
36 1
    }
37
38
    @Override
39
    protected void build(Builder builder) {
40 1
        builder
41 1
            .help(help -> help
42 1
                .description("Revoke all temporary permissions of an account")
43
44 1
                .example("#Bob revoke", "Revoke permissions of Bob account")
45 1
                .example("@John revoke", "Revoke permissions of the player John")
46
47 1
                .seeAlso("grant", "For grant temporary permissions")
48
            )
49 1
            .requires(Permission.SUPER_ADMIN)
50
        ;
51 1
    }
52
53
    @Override
54
    public String name() {
55 1
        return "revoke";
56
    }
57
58
    @Override
59
    public void execute(AdminPerformer performer, Void arguments) throws AdminException {
60 1
        if (!account.isLogged()) {
61 1
            performer.error("Cannot revoke permissions for {} : the account is not logged", account.pseudo());
62 1
            return;
63
        }
64
65 1
        account.revoke(performer.account().orElse(null));
66
67 1
        performer.success("Permissions revoked for {}", account.pseudo());
68 1
    }
69
}
70