Passed
Pull Request — master (#172)
by Vincent
14:22
created

execute(AdminPerformer,Void)   A

Complexity

Conditions 3

Size

Total Lines 22
Code Lines 17

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 13
CRAP Score 3

Importance

Changes 0
Metric Value
cc 3
eloc 17
dl 0
loc 22
ccs 13
cts 13
cp 1
crap 3
rs 9.55
c 0
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-2020 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.data.living.entity.account.Account;
24
import fr.quatrevieux.araknemu.data.living.repository.account.AccountRepository;
25
import fr.quatrevieux.araknemu.game.account.GameAccount;
26
import fr.quatrevieux.araknemu.game.admin.AbstractCommand;
27
import fr.quatrevieux.araknemu.game.admin.AdminPerformer;
28
29
/**
30
 * Info command for account
31
 */
32
public final class Info extends AbstractCommand<Void> {
33
    private final GameAccount account;
34
    private final AccountRepository repository;
35
36 1
    public Info(GameAccount account, AccountRepository repository) {
37 1
        this.account = account;
38 1
        this.repository = repository;
39 1
    }
40
41
    @Override
42
    protected void build(Builder builder) {
43 1
        builder
44 1
            .description("Display info about the account")
45 1
            .help(
46 1
                formatter -> formatter
47 1
                    .synopsis("[context] info")
48 1
                    .line("<i>Note: this command takes no arguments, the account is only resolved by the context</i>")
49
50 1
                    .example("${account:John} info", "Display information about the 'John' account")
51 1
                    .example("${player:Alan} > account info", "Display information about the account of the 'Alan' player")
52 1
                    .example("> account info", "Display self account information")
53
            )
54 1
            .requires(Permission.MANAGE_ACCOUNT)
55
        ;
56 1
    }
57
58
    @Override
59
    public String name() {
60 1
        return "info";
61
    }
62
63
    @Override
64
    public void execute(AdminPerformer performer, Void arguments) {
65 1
        final Account entity = repository.get(new Account(account.id()));
66
67 1
        performer.success("Account info : {}", entity.name());
68 1
        performer.success("=================================");
69
70 1
        performer.info("Name:   {}", entity.name());
71 1
        performer.info("Pseudo: {}", account.pseudo());
72 1
        performer.info("ID:     {}", account.id());
73
74 1
        if (account.isLogged()) {
75 1
            performer.success("Logged: Yes");
76
        } else {
77 1
            performer.error("Logged: No");
78
        }
79
80 1
        if (!account.isMaster()) {
81 1
            performer.error("Standard account");
82
        } else {
83 1
            performer.success("Admin account");
84 1
            performer.success("Permissions: {}", entity.permissions());
85
        }
86 1
    }
87
}
88