mirror of
https://github.com/PaperMC/Paper.git
synced 2025-02-09 09:01:36 +01:00
#1225: Add modern time API methods to ban API
By: Yannick Lamprecht <yannicklamprecht@live.de>
This commit is contained in:
parent
4f0075b49c
commit
c00ddac0c8
@ -2,6 +2,8 @@ package org.bukkit.craftbukkit;
|
||||
|
||||
import com.mojang.authlib.GameProfile;
|
||||
import java.io.File;
|
||||
import java.time.Duration;
|
||||
import java.time.Instant;
|
||||
import java.util.Date;
|
||||
import java.util.LinkedHashMap;
|
||||
import java.util.List;
|
||||
@ -115,9 +117,19 @@ public class CraftOfflinePlayer implements OfflinePlayer, ConfigurationSerializa
|
||||
return ((ProfileBanList) server.getBanList(BanList.Type.PROFILE)).addBan(getPlayerProfile(), reason, expires, source);
|
||||
}
|
||||
|
||||
@Override
|
||||
public BanEntry<PlayerProfile> ban(String reason, Instant expires, String source) {
|
||||
return ((ProfileBanList) server.getBanList(BanList.Type.PROFILE)).addBan(getPlayerProfile(), reason, expires, source);
|
||||
}
|
||||
|
||||
@Override
|
||||
public BanEntry<PlayerProfile> ban(String reason, Duration duration, String source) {
|
||||
return ((ProfileBanList) server.getBanList(BanList.Type.PROFILE)).addBan(getPlayerProfile(), reason, duration, source);
|
||||
}
|
||||
|
||||
public void setBanned(boolean value) {
|
||||
if (value) {
|
||||
((ProfileBanList) server.getBanList(BanList.Type.PROFILE)).addBan(getPlayerProfile(), null, null, null);
|
||||
((ProfileBanList) server.getBanList(BanList.Type.PROFILE)).addBan(getPlayerProfile(), null, (Date) null, null);
|
||||
} else {
|
||||
((ProfileBanList) server.getBanList(BanList.Type.PROFILE)).pardon(getPlayerProfile());
|
||||
}
|
||||
|
@ -27,6 +27,7 @@ import java.net.InetAddress;
|
||||
import java.net.InetSocketAddress;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collections;
|
||||
import java.util.Date;
|
||||
import java.util.HashMap;
|
||||
import java.util.HashSet;
|
||||
import java.util.Iterator;
|
||||
@ -1725,7 +1726,7 @@ public final class CraftServer implements Server {
|
||||
public void banIP(InetAddress address) {
|
||||
Preconditions.checkArgument(address != null, "Address cannot be null.");
|
||||
|
||||
((CraftIpBanList) this.getBanList(BanList.Type.IP)).addBan(address, null, null, null);
|
||||
((CraftIpBanList) this.getBanList(BanList.Type.IP)).addBan(address, null, (Date) null, null);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -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();
|
||||
|
@ -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();
|
||||
|
@ -14,6 +14,8 @@ import java.lang.ref.WeakReference;
|
||||
import java.net.InetAddress;
|
||||
import java.net.InetSocketAddress;
|
||||
import java.net.SocketAddress;
|
||||
import java.time.Duration;
|
||||
import java.time.Instant;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collection;
|
||||
import java.util.Date;
|
||||
@ -1199,6 +1201,16 @@ public class CraftPlayer extends CraftHumanEntity implements Player {
|
||||
return this.ban(reason, expires, source, true);
|
||||
}
|
||||
|
||||
@Override
|
||||
public BanEntry<PlayerProfile> ban(String reason, Instant expires, String source) {
|
||||
return ban(reason, expires != null ? Date.from(expires) : null, source);
|
||||
}
|
||||
|
||||
@Override
|
||||
public BanEntry<PlayerProfile> ban(String reason, Duration duration, String source) {
|
||||
return ban(reason, duration != null ? Instant.now().plus(duration) : null, source);
|
||||
}
|
||||
|
||||
@Override
|
||||
public BanEntry<PlayerProfile> ban(String reason, Date expires, String source, boolean kickPlayer) {
|
||||
BanEntry<PlayerProfile> banEntry = ((ProfileBanList) server.getBanList(BanList.Type.PROFILE)).addBan(getPlayerProfile(), reason, expires, source);
|
||||
@ -1208,6 +1220,16 @@ public class CraftPlayer extends CraftHumanEntity implements Player {
|
||||
return banEntry;
|
||||
}
|
||||
|
||||
@Override
|
||||
public BanEntry<PlayerProfile> ban(String reason, Instant instant, String source, boolean kickPlayer) {
|
||||
return ban(reason, instant != null ? Date.from(instant) : null, source, kickPlayer);
|
||||
}
|
||||
|
||||
@Override
|
||||
public BanEntry<PlayerProfile> ban(String reason, Duration duration, String source, boolean kickPlayer) {
|
||||
return ban(reason, duration != null ? Instant.now().plus(duration) : null, source, kickPlayer);
|
||||
}
|
||||
|
||||
@Override
|
||||
public BanEntry<InetAddress> banIp(String reason, Date expires, String source, boolean kickPlayer) {
|
||||
Preconditions.checkArgument(getAddress() != null, "The Address of this Player is null");
|
||||
@ -1218,6 +1240,16 @@ public class CraftPlayer extends CraftHumanEntity implements Player {
|
||||
return banEntry;
|
||||
}
|
||||
|
||||
@Override
|
||||
public BanEntry<InetAddress> banIp(String reason, Instant instant, String source, boolean kickPlayer) {
|
||||
return banIp(reason, instant != null ? Date.from(instant) : null, source, kickPlayer);
|
||||
}
|
||||
|
||||
@Override
|
||||
public BanEntry<InetAddress> banIp(String reason, Duration duration, String source, boolean kickPlayer) {
|
||||
return banIp(reason, duration != null ? Instant.now().plus(duration) : null, source, kickPlayer);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isWhitelisted() {
|
||||
return server.getHandle().getWhiteList().isWhiteListed(getProfile());
|
||||
|
Loading…
Reference in New Issue
Block a user