Commits
Doc authored and md_5 committed 648196070e5
1 - | package org.bukkit.craftbukkit; |
1 + | package org.bukkit.craftbukkit.ban; |
2 2 | |
3 - | import java.io.IOException; |
3 + | import java.net.InetSocketAddress; |
4 + | import java.time.Instant; |
4 5 | import java.util.Date; |
5 - | import java.util.logging.Level; |
6 6 | import net.minecraft.server.players.IpBanEntry; |
7 7 | import net.minecraft.server.players.IpBanList; |
8 - | import org.bukkit.Bukkit; |
8 + | import org.bukkit.BanEntry; |
9 9 | |
10 - | public final class CraftIpBanEntry implements org.bukkit.BanEntry { |
10 + | public final class CraftIpBanEntry implements BanEntry<InetSocketAddress> { |
11 + | private static final Date minorDate = Date.from(Instant.parse("1899-12-31T04:00:00Z")); |
11 12 | private final IpBanList list; |
12 13 | private final String target; |
13 14 | private Date created; |
14 15 | private String source; |
15 16 | private Date expiration; |
16 17 | private String reason; |
17 18 | |
18 19 | public CraftIpBanEntry(String target, IpBanEntry entry, IpBanList list) { |
19 20 | this.list = list; |
20 21 | this.target = target; |
21 22 | this.created = entry.getCreated() != null ? new Date(entry.getCreated().getTime()) : null; |
22 23 | this.source = entry.getSource(); |
23 24 | this.expiration = entry.getExpires() != null ? new Date(entry.getExpires().getTime()) : null; |
24 25 | this.reason = entry.getReason(); |
25 26 | } |
26 27 | |
27 28 | |
28 29 | public String getTarget() { |
29 30 | return this.target; |
30 31 | } |
31 32 | |
33 + | |
34 + | public InetSocketAddress getBanTarget() { |
35 + | return new InetSocketAddress(this.target, 0); |
36 + | } |
37 + | |
32 38 | |
33 39 | public Date getCreated() { |
34 40 | return this.created == null ? null : (Date) this.created.clone(); |
35 41 | } |
36 42 | |
37 43 | |
38 44 | public void setCreated(Date created) { |
39 45 | this.created = created; |
40 46 | } |
41 47 | |
49 55 | this.source = source; |
50 56 | } |
51 57 | |
52 58 | |
53 59 | public Date getExpiration() { |
54 60 | return this.expiration == null ? null : (Date) this.expiration.clone(); |
55 61 | } |
56 62 | |
57 63 | |
58 64 | public void setExpiration(Date expiration) { |
59 - | if (expiration != null && expiration.getTime() == new Date(0, 0, 0, 0, 0, 0).getTime()) { |
65 + | if (expiration != null && expiration.getTime() == minorDate.getTime()) { |
60 66 | expiration = null; // Forces "forever" |
61 67 | } |
62 68 | |
63 69 | this.expiration = expiration; |
64 70 | } |
65 71 | |
66 72 | |
67 73 | public String getReason() { |
68 74 | return this.reason; |
69 75 | } |
70 76 | |
71 77 | |
72 78 | public void setReason(String reason) { |
73 79 | this.reason = reason; |
74 80 | } |
75 81 | |
76 82 | |
77 83 | public void save() { |
78 - | IpBanEntry entry = new IpBanEntry(target, this.created, this.source, this.expiration, this.reason); |
84 + | IpBanEntry entry = new IpBanEntry(this.target, this.created, this.source, this.expiration, this.reason); |
79 85 | this.list.add(entry); |
80 - | try { |
81 - | this.list.save(); |
82 - | } catch (IOException ex) { |
83 - | Bukkit.getLogger().log(Level.SEVERE, "Failed to save banned-ips.json, {0}", ex.getMessage()); |
84 - | } |
86 + | } |
87 + | |
88 + | |
89 + | public void remove() { |
90 + | this.list.remove(target); |
85 91 | } |
86 92 | } |