Test Failed
Pull Request — master (#191)
by Vincent
11:25
created

forCode(int)   A

Complexity

Conditions 1

Size

Total Lines 2
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 0
Metric Value
cc 1
eloc 2
dl 0
loc 2
ccs 0
cts 0
cp 0
crap 2
rs 10
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.network.game.out.info;
21
22
import fr.arakne.utils.value.Interval;
23
24
import java.util.HashMap;
25
import java.util.Map;
26
27
/**
28
 * Error message
29 1
 */
30 1
public final class Error extends AbstractInformationMessage {
31
    private static final Map<Integer, Error> simpleErrorsByCode = new HashMap<>();
32
33 1
    public Error(Entry... entries) {
34 1
        super(Type.ERROR, entries);
35
    }
36
37 1
    public Error(int id) {
38 1
        this(new Entry(id));
39
    }
40
41
    public Error(int id, Object... arguments) {
42
        this(new Entry(id, arguments));
43
    }
44 1
45
    /**
46
     * Get the welcome message
47
     */
48
    public static Error welcome() {
49
        return forCode(89);
50
    }
51 1
52
    /**
53
     * Cannot do the action on this server
54
     */
55
    public static Error cantDoOnServer() {
56
        return forCode(226);
57
    }
58 1
59
    /**
60
     * Cannot do the action on the current state
61
     */
62
    public static Error cantDoOnCurrentState() {
63
        return forCode(116);
64
    }
65
66
    /**
67 1
     * Cannot learn the spell
68
     *
69
     * @param spellId The spell
70
     */
71
    public static Error cantLearnSpell(int spellId) {
72
        return new Error(7, spellId);
73
    }
74 1
75
    /**
76
     * Cannot cast the spell : not in the spell list
77
     */
78
    public static Error cantCastNotFound() {
79
        return forCode(169);
80
    }
81
82
    /**
83
     * Cannot cast the spell : not enough action points
84 1
     *
85
     * @param available The available action points
86
     * @param required The required action points for cast the spell
87
     */
88
    public static Error cantCastNotEnoughActionPoints(int available, int required) {
89
        return new Error(170, available, required);
90
    }
91 1
92
    /**
93
     * Cannot cast the spell : The target cell is invalid
94
     */
95
    public static Error cantCastInvalidCell() {
96
        return forCode(193);
97
    }
98 1
99
    /**
100
     * Cannot cast the spell : The target cell is not available
101
     */
102
    public static Error cantCastCellNotAvailable() {
103
        return forCode(172);
104
    }
105 1
106
    /**
107
     * Cannot cast the spell : The target cell is not in line
108
     */
109
    public static Error cantCastLineLaunch() {
110
        return forCode(173);
111
    }
112 1
113
    /**
114
     * Cannot cast the spell : The sight is blocked
115
     */
116
    public static Error cantCastSightBlocked() {
117
        return forCode(174);
118
    }
119 1
120
    /**
121
     * Cannot cast the spell : The cast is in invalid state
122
     */
123
    public static Error cantCastBadState() {
124
        return forCode(116);
125
    }
126
127
    /**
128
     * Cannot cast the spell : the cell is out of range
129 1
     *
130
     * @param range The spell range
131
     * @param distance The cell distance
132
     */
133
    public static Error cantCastBadRange(Interval range, int distance) {
134
        return new Error(171, range.min(), range.max(), distance);
135
    }
136 1
137
    /**
138
     * Cannot cast the spell
139
     */
140
    public static Error cantCast() {
141
        return forCode(175);
142
    }
143 1
144
    /**
145
     * Cannot perform the action during fight
146
     */
147
    public static Error cantDoDuringFight() {
148
        return forCode(91);
149
    }
150 1
151
    /**
152
     * Cannot move : the player is overweight
153
     */
154
    public static Error cantMoveOverweight() {
155
        return forCode(12);
156
    }
157
158
    /**
159 1
     * A shutdown is scheduled
160
     *
161
     * @param delay The delay string. The value is not translated.
162
     */
163
    public static Error shutdownScheduled(String delay) {
164
        return new Error(15, delay);
165
    }
166 1
167
    /**
168
     * A game server save is in progress
169
     */
170
    public static Error saveInProgress() {
171
        return forCode(164);
172
    }
173 1
174
    /**
175
     * The current game server save is terminated
176
     */
177
    public static Error saveTerminated() {
178
        return forCode(165);
179
    }
180
181
    /**
182
     * Create and cache a simple Error with a code
183
     *
184
     * @param code The error code
185
     *
186
     * @return The Error instance
187
     */
188
    private static Error forCode(int code) {
189
        return simpleErrorsByCode.computeIfAbsent(code, Error::new);
190
    }
191
}
192