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

execute(AdminPerformer,Void)   B

Complexity

Conditions 6

Size

Total Lines 53
Code Lines 37

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 34
CRAP Score 6.0061

Importance

Changes 0
Metric Value
cc 6
eloc 37
dl 0
loc 53
ccs 34
cts 36
cp 0.9444
crap 6.0061
rs 8.0586
c 0
b 0
f 0

How to fix   Long Method   

Long Method

Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.

For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.

Commonly applied refactorings include:

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.debug;
21
22
import fr.arakne.utils.maps.serializer.CellData;
23
import fr.quatrevieux.araknemu.common.account.Permission;
24
import fr.quatrevieux.araknemu.data.world.entity.environment.MapTemplate;
25
import fr.quatrevieux.araknemu.data.world.repository.environment.MapTemplateRepository;
26
import fr.quatrevieux.araknemu.game.admin.AbstractCommand;
27
import fr.quatrevieux.araknemu.game.admin.AdminPerformer;
28
import fr.quatrevieux.araknemu.game.admin.exception.AdminException;
29
30
/**
31
 * Get stats on map cells
32
 */
33
public final class MapStats extends AbstractCommand<Void> {
34
    private final MapTemplateRepository repository;
35
36 1
    public MapStats(MapTemplateRepository repository) {
37 1
        this.repository = repository;
38 1
    }
39
40
    @Override
41
    protected void build(Builder builder) {
42 1
        builder
43 1
            .description("Compute stats un maps and cells")
44 1
            .requires(Permission.DEBUG)
45
        ;
46 1
    }
47
48
    @Override
49
    public String name() {
50 1
        return "mapstats";
51
    }
52
53
    @Override
54
    public void execute(AdminPerformer performer, Void arguments) throws AdminException {
55 1
        performer.info("Loading map stats...");
56
57 1
        final int[] movements = new int[10];
58
59 1
        int count = 0;
60 1
        int withFightPos = 0;
61 1
        int cellCount = 0;
62 1
        int desactived = 0;
63 1
        int interactive = 0;
64
65 1
        for (MapTemplate template : repository.all()) {
66 1
            ++count;
67
68 1
            if (template.fightPlaces().length >= 2) {
69 1
                ++withFightPos;
70
            }
71
72 1
            cellCount += template.cells().length;
73
74 1
            for (CellData cell : template.cells()) {
75 1
                ++movements[cell.movement().ordinal()];
76
77 1
                if (!cell.active()) {
78
                    ++desactived;
79
                }
80
81 1
                if (cell.layer2().interactive()) {
82
                    ++interactive;
83
                }
84
            }
85 1
        }
86
87 1
        performer.success("============================");
88 1
        performer.success("        Maps stats");
89 1
        performer.success("============================");
90
91 1
        performer.info("Maps        : {}", count);
92 1
        performer.info("Fight pos   : {} ({}%)", withFightPos, withFightPos * 100 / count);
93 1
        performer.info("Cells       : {} ({} per maps)", cellCount, cellCount / count);
94 1
        performer.info("Desactived  : {} ({}%)", desactived, desactived * 100 / cellCount);
95 1
        performer.info("Interactive : {} ({}%)", interactive, interactive * 100 / cellCount);
96 1
        performer.info("Unwalkable  : {} ({}%)", movements[0], movements[0] * 100 / cellCount);
97 1
        performer.info("Mov 1       : {} ({}%)", movements[1], movements[1] * 100 / cellCount);
98 1
        performer.info("Triggers    : {} ({}%)", movements[2], movements[2] * 100 / cellCount);
99 1
        performer.info("Mov 3       : {} ({}%)", movements[3], movements[3] * 100 / cellCount);
100 1
        performer.info("Normal      : {} ({}%)", movements[4], movements[4] * 100 / cellCount);
101 1
        performer.info("Mount park  : {} ({}%)", movements[5], movements[5] * 100 / cellCount);
102 1
        performer.info("Road        : {} ({}%)", movements[6], movements[6] * 100 / cellCount);
103 1
        performer.info("Mov 7       : {} ({}%)", movements[7], movements[7] * 100 / cellCount);
104
105 1
        performer.success("============================");
106 1
    }
107
}
108