#1225: Add modern time API methods to ban API

By: Yannick Lamprecht <yannicklamprecht@live.de>
This commit is contained in:
CraftBukkit/Spigot
2023-07-15 10:43:30 +10:00
parent 4f0075b49c
commit c00ddac0c8
5 changed files with 75 additions and 2 deletions

View File

@@ -4,6 +4,8 @@ import com.google.common.base.Preconditions;
import com.google.common.collect.ImmutableSet;
import com.google.common.net.InetAddresses;
import java.net.InetAddress;
import java.time.Duration;
import java.time.Instant;
import java.util.Date;
import java.util.Set;
import net.minecraft.server.players.IpBanEntry;
@@ -52,6 +54,18 @@ public class CraftIpBanList implements org.bukkit.ban.IpBanList {
return this.addBan(this.getIpFromAddress(target), reason, expires, source);
}
@Override
public BanEntry<InetAddress> addBan(InetAddress target, String reason, Instant expires, String source) {
Date date = expires != null ? Date.from(expires) : null;
return addBan(target, reason, date, source);
}
@Override
public BanEntry<InetAddress> addBan(InetAddress target, String reason, Duration duration, String source) {
Instant instant = duration != null ? Instant.now().plus(duration) : null;
return addBan(target, reason, instant, source);
}
@Override
public Set<BanEntry> getBanEntries() {
ImmutableSet.Builder<BanEntry> builder = ImmutableSet.builder();

View File

@@ -3,6 +3,8 @@ package org.bukkit.craftbukkit.ban;
import com.google.common.base.Preconditions;
import com.google.common.collect.ImmutableSet;
import com.mojang.authlib.GameProfile;
import java.time.Duration;
import java.time.Instant;
import java.util.Date;
import java.util.Set;
import java.util.UUID;
@@ -50,6 +52,18 @@ public class CraftProfileBanList implements ProfileBanList {
return this.addBan(((CraftPlayerProfile) target).buildGameProfile(), reason, expires, source);
}
@Override
public BanEntry<PlayerProfile> addBan(PlayerProfile target, String reason, Instant expires, String source) {
Date date = expires != null ? Date.from(expires) : null;
return addBan(target, reason, date, source);
}
@Override
public BanEntry<PlayerProfile> addBan(PlayerProfile target, String reason, Duration duration, String source) {
Instant instant = duration != null ? Instant.now().plus(duration) : null;
return addBan(target, reason, instant, source);
}
@Override
public Set<BanEntry> getBanEntries() {
ImmutableSet.Builder<BanEntry> builder = ImmutableSet.builder();