diff --git a/paper-api/src/main/java/io/papermc/paper/ban/BanListType.java b/paper-api/src/main/java/io/papermc/paper/ban/BanListType.java new file mode 100644 index 0000000000..fdd5cfdc8c --- /dev/null +++ b/paper-api/src/main/java/io/papermc/paper/ban/BanListType.java @@ -0,0 +1,30 @@ +package io.papermc.paper.ban; + +import org.bukkit.BanList; +import org.bukkit.ban.IpBanList; +import org.bukkit.ban.ProfileBanList; +import org.jspecify.annotations.NullMarked; + +/** + * Represents a ban-type that a {@link BanList} may track. + * It enforces the correct return value at compile time. + */ +@NullMarked +public interface BanListType { + + /** + * Banned IP addresses + */ + BanListType IP = new BanListTypeImpl<>(IpBanList.class); + /** + * Banned player profiles + */ + BanListType PROFILE = new BanListTypeImpl<>(ProfileBanList.class); + + /** + * Returns the type class of the ban list used generically + * + * @return the type class + */ + Class typeClass(); +} diff --git a/paper-api/src/main/java/io/papermc/paper/ban/BanListTypeImpl.java b/paper-api/src/main/java/io/papermc/paper/ban/BanListTypeImpl.java new file mode 100644 index 0000000000..26d4df3cbf --- /dev/null +++ b/paper-api/src/main/java/io/papermc/paper/ban/BanListTypeImpl.java @@ -0,0 +1,9 @@ +package io.papermc.paper.ban; + +import org.jetbrains.annotations.ApiStatus; +import org.jspecify.annotations.NullMarked; + +@ApiStatus.Internal +@NullMarked +record BanListTypeImpl(Class typeClass) implements BanListType { +} diff --git a/paper-api/src/main/java/org/bukkit/BanList.java b/paper-api/src/main/java/org/bukkit/BanList.java index 60aea29d51..bd06fe7cb5 100644 --- a/paper-api/src/main/java/org/bukkit/BanList.java +++ b/paper-api/src/main/java/org/bukkit/BanList.java @@ -16,7 +16,9 @@ public interface BanList { /** * Represents a ban-type that a {@link BanList} may track. + * @deprecated use {@link io.papermc.paper.ban.BanListType} to enforce the correct return value at compile time. */ + @Deprecated(since = "1.20.4") // Paper - BanList Type Improvements public enum Type { /** * Banned player names diff --git a/paper-api/src/main/java/org/bukkit/Bukkit.java b/paper-api/src/main/java/org/bukkit/Bukkit.java index c3c76dd82b..8ab94f8189 100644 --- a/paper-api/src/main/java/org/bukkit/Bukkit.java +++ b/paper-api/src/main/java/org/bukkit/Bukkit.java @@ -1663,11 +1663,27 @@ public final class Bukkit { * @param The ban target * * @return a ban list of the specified type + * @deprecated use {@link #getBanList(io.papermc.paper.ban.BanListType)} to enforce the correct return value at compile time. */ @NotNull + @Deprecated(since = "1.20.4") // Paper - add BanListType (which has a generic) public static > T getBanList(@NotNull BanList.Type type) { return server.getBanList(type); } + // Paper start - add BanListType (which has a generic) + /** + * Gets a ban list for the supplied type. + * + * @param type the type of list to fetch, cannot be null + * @param The ban target + * + * @return a ban list of the specified type + */ + @NotNull + public static , E> B getBanList(final io.papermc.paper.ban.@NotNull BanListType type) { + return server.getBanList(type); + } + // Paper end - add BanListType (which has a generic) /** * Gets a set containing all player operators. diff --git a/paper-api/src/main/java/org/bukkit/Server.java b/paper-api/src/main/java/org/bukkit/Server.java index 1b968953fd..e187bb0300 100644 --- a/paper-api/src/main/java/org/bukkit/Server.java +++ b/paper-api/src/main/java/org/bukkit/Server.java @@ -1425,10 +1425,25 @@ public interface Server extends PluginMessageRecipient, net.kyori.adventure.audi * @param The ban target * * @return a ban list of the specified type + * @deprecated use {@link #getBanList(io.papermc.paper.ban.BanListType)} to enforce the correct return value at compile time. */ + @Deprecated // Paper - add BanListType (which has a generic) @NotNull public > T getBanList(@NotNull BanList.Type type); + // Paper start - add BanListType (which has a generic) + /** + * Gets a ban list for the supplied type. + * + * @param type the type of list to fetch, cannot be null + * @param The ban target + * + * @return a ban list of the specified type + */ + @NotNull + , E> B getBanList(@NotNull io.papermc.paper.ban.BanListType type); + // Paper end - add BanListType (which has a generic) + /** * Gets a set containing all player operators. *