Commits

Yannick Lamprecht authored and md_5 committed 36b10766043
#1225: Add modern time API methods to ban API
No tags

src/main/java/org/bukkit/craftbukkit/ban/CraftIpBanList.java

Modified
1 1 package org.bukkit.craftbukkit.ban;
2 2
3 3 import com.google.common.base.Preconditions;
4 4 import com.google.common.collect.ImmutableSet;
5 5 import com.google.common.net.InetAddresses;
6 6 import java.net.InetAddress;
7 +import java.time.Duration;
8 +import java.time.Instant;
7 9 import java.util.Date;
8 10 import java.util.Set;
9 11 import net.minecraft.server.players.IpBanEntry;
10 12 import net.minecraft.server.players.IpBanList;
11 13 import org.bukkit.BanEntry;
12 14
13 15 public class CraftIpBanList implements org.bukkit.ban.IpBanList {
14 16 private final IpBanList list;
15 17
16 18 public CraftIpBanList(IpBanList list) {
45 47 this.list.add(entry);
46 48
47 49 return new CraftIpBanEntry(target, entry, list);
48 50 }
49 51
50 52 @Override
51 53 public BanEntry<InetAddress> addBan(InetAddress target, String reason, Date expires, String source) {
52 54 return this.addBan(this.getIpFromAddress(target), reason, expires, source);
53 55 }
54 56
57 + @Override
58 + public BanEntry<InetAddress> addBan(InetAddress target, String reason, Instant expires, String source) {
59 + Date date = expires != null ? Date.from(expires) : null;
60 + return addBan(target, reason, date, source);
61 + }
62 +
63 + @Override
64 + public BanEntry<InetAddress> addBan(InetAddress target, String reason, Duration duration, String source) {
65 + Instant instant = duration != null ? Instant.now().plus(duration) : null;
66 + return addBan(target, reason, instant, source);
67 + }
68 +
55 69 @Override
56 70 public Set<BanEntry> getBanEntries() {
57 71 ImmutableSet.Builder<BanEntry> builder = ImmutableSet.builder();
58 72 for (String target : list.getUserList()) {
59 73 IpBanEntry ipBanEntry = list.get(target);
60 74 if (ipBanEntry != null) {
61 75 builder.add(new CraftIpBanEntry(target, ipBanEntry, list));
62 76 }
63 77 }
64 78 return builder.build();

Everything looks good. We'll let you know here if there's anything you should know about.

Add shortcut