diff --git a/paper-server/src/main/java/org/bukkit/craftbukkit/CraftServer.java b/paper-server/src/main/java/org/bukkit/craftbukkit/CraftServer.java index 24aaa290da..d1c94997bb 100644 --- a/paper-server/src/main/java/org/bukkit/craftbukkit/CraftServer.java +++ b/paper-server/src/main/java/org/bukkit/craftbukkit/CraftServer.java @@ -23,6 +23,7 @@ import java.io.FileInputStream; import java.io.FileNotFoundException; import java.io.IOException; import java.io.InputStreamReader; +import java.net.InetAddress; import java.net.InetSocketAddress; import java.util.ArrayList; import java.util.Collections; @@ -1721,14 +1722,14 @@ public final class CraftServer implements Server { } @Override - public void banIP(InetSocketAddress address) { + public void banIP(InetAddress address) { Preconditions.checkArgument(address != null, "Address cannot be null."); ((CraftIpBanList) this.getBanList(BanList.Type.IP)).addBan(address, null, null, null); } @Override - public void unbanIP(InetSocketAddress address) { + public void unbanIP(InetAddress address) { Preconditions.checkArgument(address != null, "Address cannot be null."); ((CraftIpBanList) this.getBanList(BanList.Type.IP)).pardon(address); diff --git a/paper-server/src/main/java/org/bukkit/craftbukkit/ban/CraftIpBanEntry.java b/paper-server/src/main/java/org/bukkit/craftbukkit/ban/CraftIpBanEntry.java index 7fc94112ba..e6d6689dd2 100644 --- a/paper-server/src/main/java/org/bukkit/craftbukkit/ban/CraftIpBanEntry.java +++ b/paper-server/src/main/java/org/bukkit/craftbukkit/ban/CraftIpBanEntry.java @@ -1,13 +1,14 @@ package org.bukkit.craftbukkit.ban; -import java.net.InetSocketAddress; +import com.google.common.net.InetAddresses; +import java.net.InetAddress; import java.time.Instant; import java.util.Date; import net.minecraft.server.players.IpBanEntry; import net.minecraft.server.players.IpBanList; import org.bukkit.BanEntry; -public final class CraftIpBanEntry implements BanEntry { +public final class CraftIpBanEntry implements BanEntry { private static final Date minorDate = Date.from(Instant.parse("1899-12-31T04:00:00Z")); private final IpBanList list; private final String target; @@ -31,8 +32,8 @@ public final class CraftIpBanEntry implements BanEntry { } @Override - public InetSocketAddress getBanTarget() { - return new InetSocketAddress(this.target, 0); + public InetAddress getBanTarget() { + return InetAddresses.forString(this.target); } @Override diff --git a/paper-server/src/main/java/org/bukkit/craftbukkit/ban/CraftIpBanList.java b/paper-server/src/main/java/org/bukkit/craftbukkit/ban/CraftIpBanList.java index dbc8d7a861..4f1fd304e4 100644 --- a/paper-server/src/main/java/org/bukkit/craftbukkit/ban/CraftIpBanList.java +++ b/paper-server/src/main/java/org/bukkit/craftbukkit/ban/CraftIpBanList.java @@ -3,7 +3,7 @@ package org.bukkit.craftbukkit.ban; import com.google.common.base.Preconditions; import com.google.common.collect.ImmutableSet; import com.google.common.net.InetAddresses; -import java.net.InetSocketAddress; +import java.net.InetAddress; import java.util.Date; import java.util.Set; import net.minecraft.server.players.IpBanEntry; @@ -18,7 +18,7 @@ public class CraftIpBanList implements org.bukkit.ban.IpBanList { } @Override - public BanEntry getBanEntry(String target) { + public BanEntry getBanEntry(String target) { Preconditions.checkArgument(target != null, "Target cannot be null"); IpBanEntry entry = this.list.get(target); @@ -30,12 +30,12 @@ public class CraftIpBanList implements org.bukkit.ban.IpBanList { } @Override - public BanEntry getBanEntry(InetSocketAddress target) { + public BanEntry getBanEntry(InetAddress target) { return this.getBanEntry(this.getIpFromAddress(target)); } @Override - public BanEntry addBan(String target, String reason, Date expires, String source) { + public BanEntry addBan(String target, String reason, Date expires, String source) { Preconditions.checkArgument(target != null, "Ban target cannot be null"); IpBanEntry entry = new IpBanEntry(target, new Date(), @@ -48,13 +48,25 @@ public class CraftIpBanList implements org.bukkit.ban.IpBanList { } @Override - public BanEntry addBan(InetSocketAddress target, String reason, Date expires, String source) { + public BanEntry addBan(InetAddress target, String reason, Date expires, String source) { return this.addBan(this.getIpFromAddress(target), reason, expires, source); } @Override - public Set> getBanEntries() { - ImmutableSet.Builder> builder = ImmutableSet.builder(); + public Set getBanEntries() { + ImmutableSet.Builder builder = ImmutableSet.builder(); + for (String target : list.getUserList()) { + IpBanEntry ipBanEntry = list.get(target); + if (ipBanEntry != null) { + builder.add(new CraftIpBanEntry(target, ipBanEntry, list)); + } + } + return builder.build(); + } + + @Override + public Set> getEntries() { + ImmutableSet.Builder> builder = ImmutableSet.builder(); for (String target : list.getUserList()) { IpBanEntry ipBanEntry = list.get(target); if (ipBanEntry != null) { @@ -71,7 +83,7 @@ public class CraftIpBanList implements org.bukkit.ban.IpBanList { } @Override - public boolean isBanned(InetSocketAddress target) { + public boolean isBanned(InetAddress target) { return this.isBanned(getIpFromAddress(target)); } @@ -82,15 +94,14 @@ public class CraftIpBanList implements org.bukkit.ban.IpBanList { } @Override - public void pardon(InetSocketAddress target) { + public void pardon(InetAddress target) { this.pardon(getIpFromAddress(target)); } - private String getIpFromAddress(InetSocketAddress address) { + private String getIpFromAddress(InetAddress address) { if (address == null) { return null; } - Preconditions.checkArgument(!address.isUnresolved(), "%s its not a valid address", address); - return InetAddresses.toAddrString(address.getAddress()); + return InetAddresses.toAddrString(address); } } diff --git a/paper-server/src/main/java/org/bukkit/craftbukkit/ban/CraftProfileBanList.java b/paper-server/src/main/java/org/bukkit/craftbukkit/ban/CraftProfileBanList.java index d8cac25b50..622fe2aaea 100644 --- a/paper-server/src/main/java/org/bukkit/craftbukkit/ban/CraftProfileBanList.java +++ b/paper-server/src/main/java/org/bukkit/craftbukkit/ban/CraftProfileBanList.java @@ -51,7 +51,18 @@ public class CraftProfileBanList implements ProfileBanList { } @Override - public Set> getBanEntries() { + public Set getBanEntries() { + ImmutableSet.Builder builder = ImmutableSet.builder(); + for (GameProfileBanEntry entry : list.getEntries()) { + GameProfile profile = entry.getUser(); + builder.add(new CraftProfileBanEntry(profile, entry, list)); + } + + return builder.build(); + } + + @Override + public Set> getEntries() { ImmutableSet.Builder> builder = ImmutableSet.builder(); for (GameProfileBanEntry entry : list.getEntries()) { GameProfile profile = entry.getUser(); diff --git a/paper-server/src/main/java/org/bukkit/craftbukkit/entity/CraftPlayer.java b/paper-server/src/main/java/org/bukkit/craftbukkit/entity/CraftPlayer.java index 2576596f5c..2d25ce6a05 100644 --- a/paper-server/src/main/java/org/bukkit/craftbukkit/entity/CraftPlayer.java +++ b/paper-server/src/main/java/org/bukkit/craftbukkit/entity/CraftPlayer.java @@ -11,6 +11,7 @@ import it.unimi.dsi.fastutil.shorts.ShortSet; import java.io.ByteArrayOutputStream; import java.io.IOException; import java.lang.ref.WeakReference; +import java.net.InetAddress; import java.net.InetSocketAddress; import java.net.SocketAddress; import java.util.ArrayList; @@ -1208,9 +1209,9 @@ public class CraftPlayer extends CraftHumanEntity implements Player { } @Override - public BanEntry banIp(String reason, Date expires, String source, boolean kickPlayer) { + public BanEntry banIp(String reason, Date expires, String source, boolean kickPlayer) { Preconditions.checkArgument(getAddress() != null, "The Address of this Player is null"); - BanEntry banEntry = ((IpBanList) server.getBanList(BanList.Type.IP)).addBan(getAddress(), reason, expires, source); + BanEntry banEntry = ((IpBanList) server.getBanList(BanList.Type.IP)).addBan(getAddress().getAddress(), reason, expires, source); if (kickPlayer) { this.kickPlayer(reason); }