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.executor.argument.handler; |
21
|
|
|
|
22
|
|
|
import inet.ipaddr.IPAddressString; |
23
|
|
|
import org.kohsuke.args4j.CmdLineException; |
24
|
|
|
import org.kohsuke.args4j.CmdLineParser; |
25
|
|
|
import org.kohsuke.args4j.OptionDef; |
26
|
|
|
import org.kohsuke.args4j.spi.OneArgumentOptionHandler; |
27
|
|
|
import org.kohsuke.args4j.spi.Setter; |
28
|
|
|
|
29
|
|
|
/** |
30
|
|
|
* Parse {@link IPAddressString} value |
31
|
|
|
*/ |
32
|
|
|
public final class IpAddressStringHandler extends OneArgumentOptionHandler<IPAddressString> { |
33
|
|
|
public IpAddressStringHandler(CmdLineParser parser, OptionDef option, Setter<? super IPAddressString> setter) { |
34
|
1 |
|
super(parser, option, setter); |
35
|
1 |
|
} |
36
|
|
|
|
37
|
|
|
@Override |
38
|
|
|
protected IPAddressString parse(String argument) throws NumberFormatException, CmdLineException { |
39
|
1 |
|
final IPAddressString ipAddress = new IPAddressString(argument); |
40
|
|
|
|
41
|
1 |
|
if (!ipAddress.isValid()) { |
42
|
1 |
|
throw new CmdLineException(owner, "Invalid IP address given"); |
|
|
|
|
43
|
|
|
} |
44
|
|
|
|
45
|
1 |
|
return ipAddress; |
46
|
|
|
} |
47
|
|
|
} |
48
|
|
|
|