fr.quatrevieux.araknemu.network.game.in.game.action.GameActionRequest   A
last analyzed

Complexity

Total Complexity 3

Size/Duplication

Total Lines 33
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
eloc 21
dl 0
loc 33
ccs 13
cts 13
cp 1
rs 10
c 0
b 0
f 0
wmc 3

5 Methods

Rating   Name   Duplication   Size   Complexity  
A GameActionRequest(int,String[]) 0 3 1
A Parser.code() 0 3 1
A type() 0 2 1
A Parser.parse(String) 0 9 2
A arguments() 0 2 1
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-2019 Vincent Quatrevieux
18
 */
19
20
package fr.quatrevieux.araknemu.network.game.in.game.action;
21
22
import fr.quatrevieux.araknemu.core.network.parser.Packet;
23
import fr.quatrevieux.araknemu.core.network.parser.ParsePacketException;
24
import fr.quatrevieux.araknemu.core.network.parser.SinglePacketParser;
25
import org.apache.commons.lang3.StringUtils;
26
import org.checkerframework.common.value.qual.MinLen;
27
28
/**
29
 * Request for start a game action
30
 *
31
 * https://github.com/Emudofus/Dofus/blob/1.29/dofus/aks/GameActions.as#L19
32
 */
33
public final class GameActionRequest implements Packet {
34
    private final int type;
35
    private final String[] arguments;
36
37 1
    public GameActionRequest(int type, String[] arguments) {
38 1
        this.type = type;
39 1
        this.arguments = arguments;
40 1
    }
41
42
    public int type() {
43 1
        return type;
44
    }
45
46
    public String[] arguments() {
47 1
        return arguments;
48
    }
49
50 1
    public static final class Parser implements SinglePacketParser<GameActionRequest> {
51
        @Override
52
        public GameActionRequest parse(String input) throws ParsePacketException {
53 1
            if (input.length() < 3) {
54 1
                throw new ParsePacketException(code() + input, "Invalid Game action packet");
55
            }
56
57 1
            return new GameActionRequest(
58 1
                Integer.parseInt(input.substring(0, 3)),
59 1
                StringUtils.split(input.substring(3), ";")
60
            );
61
        }
62
63
        @Override
64
        public @MinLen(2) String code() {
65 1
            return "GA";
66
        }
67
    }
68
}
69