improve BanList types

This commit is contained in:
Yannick Lamprecht
2024-02-10 20:49:47 +01:00
parent 3ebc5bb92c
commit 3073742fd7
5 changed files with 72 additions and 0 deletions

View File

@@ -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<T> {
/**
* Banned IP addresses
*/
BanListType<IpBanList> IP = new BanListTypeImpl<>(IpBanList.class);
/**
* Banned player profiles
*/
BanListType<ProfileBanList> PROFILE = new BanListTypeImpl<>(ProfileBanList.class);
/**
* Returns the type class of the ban list used generically
*
* @return the type class
*/
Class<T> typeClass();
}

View File

@@ -0,0 +1,9 @@
package io.papermc.paper.ban;
import org.jetbrains.annotations.ApiStatus;
import org.jspecify.annotations.NullMarked;
@ApiStatus.Internal
@NullMarked
record BanListTypeImpl<T>(Class<T> typeClass) implements BanListType<T> {
}