-
Notifications
You must be signed in to change notification settings - Fork 0
/
CraftIpBanList.java
78 lines (59 loc) · 2.32 KB
/
CraftIpBanList.java
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
69
70
71
72
73
74
75
76
77
78
package org.bukkit.craftbukkit;
import java.io.IOException;
import java.net.InetSocketAddress;
import java.util.Date;
import java.util.Set;
import net.minecraft.server.management.UserListIPBansEntry;
import net.minecraft.server.management.UserListIPBans;
import org.apache.commons.lang3.StringUtils;
import org.apache.commons.lang3.Validate;
import com.google.common.collect.ImmutableSet;
import java.util.logging.Level;
import org.bukkit.Bukkit;
public class CraftIpBanList implements org.bukkit.BanList {
private final UserListIPBans list;
public CraftIpBanList(UserListIPBans list) {
this.list = list;
}
@Override
public org.bukkit.BanEntry getBanEntry(String target) {
Validate.notNull(target, "Target cannot be null");
UserListIPBansEntry entry = (UserListIPBansEntry) list.getEntry(target);
if (entry == null) {
return null;
}
return new CraftIpBanEntry(target, entry, list);
}
@Override
public org.bukkit.BanEntry addBan(String target, String reason, Date expires, String source) {
Validate.notNull(target, "Ban target cannot be null");
UserListIPBansEntry entry = new UserListIPBansEntry(target, new Date(),
StringUtils.isBlank(source) ? null : source, expires,
StringUtils.isBlank(reason) ? null : reason);
list.addEntry(entry);
try {
list.writeChanges();
} catch (IOException ex) {
Bukkit.getLogger().log(Level.SEVERE, "Failed to save banned-ips.json, {0}", ex.getMessage());
}
return new CraftIpBanEntry(target, entry, list);
}
@Override
public Set<org.bukkit.BanEntry> getBanEntries() {
ImmutableSet.Builder<org.bukkit.BanEntry> builder = ImmutableSet.builder();
for (String target : list.getKeys()) {
builder.add(new CraftIpBanEntry(target, (UserListIPBansEntry) list.getEntry(target), list));
}
return builder.build();
}
@Override
public boolean isBanned(String target) {
Validate.notNull(target, "Target cannot be null");
return list.isBanned(InetSocketAddress.createUnresolved(target, 0));
}
@Override
public void pardon(String target) {
Validate.notNull(target, "Target cannot be null");
list.removeEntry(target);
}
}