Search in sources :

Example 1 with IpBanListEntry

use of net.minecraft.server.players.IpBanListEntry in project SpongeCommon by SpongePowered.

the class SpongeBanBuilder method build.

@Override
public Ban build() {
    if (this.banType == null) {
        throw new IllegalStateException("BanType cannot be null!");
    }
    final LegacyComponentSerializer lcs = LegacyComponentSerializer.legacySection();
    final String sourceName = this.source != null ? lcs.serialize(this.source) : null;
    final String reason = this.reason != null ? lcs.serialize(this.reason) : null;
    if (this.banType == BanTypes.PROFILE.get()) {
        if (this.profile == null) {
            throw new IllegalStateException("User cannot be null");
        }
        return (Ban) new UserBanListEntry(SpongeGameProfile.toMcProfile(this.profile.withoutProperties()), Date.from(this.start), sourceName, this.toDate(this.end), reason);
    }
    if (this.address == null) {
        throw new IllegalStateException("Address cannot be null!");
    }
    return (Ban) new IpBanListEntry(BanUtil.addressToBanCompatibleString(this.address), Date.from(this.start), sourceName, this.toDate(this.end), reason);
}
Also used : IpBanListEntry(net.minecraft.server.players.IpBanListEntry) UserBanListEntry(net.minecraft.server.players.UserBanListEntry) LegacyComponentSerializer(net.kyori.adventure.text.serializer.legacy.LegacyComponentSerializer) Ban(org.spongepowered.api.service.ban.Ban)

Example 2 with IpBanListEntry

use of net.minecraft.server.players.IpBanListEntry in project SpongeCommon by SpongePowered.

the class SpongeBanService method isBanned.

@SuppressWarnings("unchecked")
public boolean isBanned(final InetAddress address) {
    final StoredUserListAccessor<String, IpBanListEntry> accessor = ((StoredUserListAccessor<String, IpBanListEntry>) this.getIPBanList());
    accessor.invoker$removeExpired();
    return accessor.accessor$map().containsKey(accessor.invoker$getKeyForUser(((IpBanListAccessor) accessor).invoker$getIpFromAddress(new InetSocketAddress(address, 0))));
}
Also used : IpBanListAccessor(org.spongepowered.common.accessor.server.players.IpBanListAccessor) IpBanListEntry(net.minecraft.server.players.IpBanListEntry) InetSocketAddress(java.net.InetSocketAddress)

Aggregations

IpBanListEntry (net.minecraft.server.players.IpBanListEntry)2 InetSocketAddress (java.net.InetSocketAddress)1 LegacyComponentSerializer (net.kyori.adventure.text.serializer.legacy.LegacyComponentSerializer)1 UserBanListEntry (net.minecraft.server.players.UserBanListEntry)1 Ban (org.spongepowered.api.service.ban.Ban)1 IpBanListAccessor (org.spongepowered.common.accessor.server.players.IpBanListAccessor)1