blob: c3146605c03929f02cd15944cb1da6f87e0ac3ca (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
|
package com.redstoner.bungeeBans.commands;
import com.redstoner.bungeeBans.BanManager;
import com.redstoner.bungeeBans.Util;
import com.redstoner.bungeeBans.json.IPBan;
import net.md_5.bungee.api.ChatColor;
import net.md_5.bungee.api.CommandSender;
import net.md_5.bungee.api.chat.ComponentBuilder;
import net.md_5.bungee.api.chat.TextComponent;
import net.md_5.bungee.api.plugin.Command;
import java.io.IOException;
public class UnbanIPCommand extends Command {
private BanManager<IPBan> bm;
public UnbanIPCommand(BanManager<IPBan> bm) {
super("unbanip", "bungeebans.unbanip", "pardonip");
this.bm = bm;
}
@Override
public void execute(CommandSender sender, String[] args) {
if (args.length != 1) {
sender.sendMessage(
new ComponentBuilder(ChatColor.RED + "Usage: ")
.append(ChatColor.AQUA + "/unbanip ")
.append(ChatColor.GOLD + "<ip> ")
.create()
);
return;
}
String ip = args[0];
if (!Util.validateIP(ip)) {
sender.sendMessage(new TextComponent(ChatColor.RED + "Invalid IP!"));
return;
}
IPBan ban = bm.getBan(ip);
if (ban == null) {
sender.sendMessage(new TextComponent(ChatColor.RED + "That IP is not banned!"));
return;
}
bm.removeBan(ban);
try {
bm.saveBans();
} catch (IOException e) {
sender.sendMessage(new TextComponent(ChatColor.RED + "Failed to save IP bans to file! (nothing was changed)"));
e.printStackTrace();
bm.addBan(ban);
return;
}
sender.sendMessage(
new ComponentBuilder(ChatColor.GREEN + "Unbanned IP ")
.append(ChatColor.AQUA + ip)
.create()
);
}
}
|