Search in sources :

Example 1 with IpBanListAccessor

use of org.spongepowered.common.accessor.server.players.IpBanListAccessor in project SpongeCommon by SpongePowered.

the class SpongeBanService method remove.

@Override
public CompletableFuture<Boolean> remove(final Ban ban) {
    if (!this.hasBan(ban)) {
        return CompletableFuture.completedFuture(false);
    }
    if (ban.type().equals(BanTypes.PROFILE.get())) {
        return Sponge.server().userManager().loadOrCreate(((Ban.Profile) ban).profile().uuid()).thenApplyAsync(user -> {
            Sponge.eventManager().post(SpongeEventFactory.createPardonUserEvent(PhaseTracker.getCauseStackManager().currentCause(), (Ban.Profile) ban, user));
            UserListUtil.removeEntry(this.getUserBanList(), SpongeGameProfile.toMcProfile(((Ban.Profile) ban).profile()));
            return true;
        }, SpongeCommon.server());
    } else if (ban.type().equals(BanTypes.IP.get())) {
        Sponge.eventManager().post(SpongeEventFactory.createPardonIpEvent(PhaseTracker.getCauseStackManager().currentCause(), (Ban.IP) ban));
        final InetSocketAddress inetSocketAddress = new InetSocketAddress(((Ban.IP) ban).address(), 0);
        UserListUtil.removeEntry(this.getIPBanList(), ((IpBanListAccessor) this.getIPBanList()).invoker$getIpFromAddress(inetSocketAddress));
        return CompletableFuture.completedFuture(true);
    }
    throw new IllegalArgumentException(String.format("Ban %s had unrecognized BanType %s!", ban, ban.type()));
}
Also used : IpBanListAccessor(org.spongepowered.common.accessor.server.players.IpBanListAccessor) InetSocketAddress(java.net.InetSocketAddress) Ban(org.spongepowered.api.service.ban.Ban) SpongeGameProfile(org.spongepowered.common.profile.SpongeGameProfile) GameProfile(org.spongepowered.api.profile.GameProfile)

Example 2 with IpBanListAccessor

use of org.spongepowered.common.accessor.server.players.IpBanListAccessor 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

InetSocketAddress (java.net.InetSocketAddress)2 IpBanListAccessor (org.spongepowered.common.accessor.server.players.IpBanListAccessor)2 IpBanListEntry (net.minecraft.server.players.IpBanListEntry)1 GameProfile (org.spongepowered.api.profile.GameProfile)1 Ban (org.spongepowered.api.service.ban.Ban)1 SpongeGameProfile (org.spongepowered.common.profile.SpongeGameProfile)1