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()));
}
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))));
}
Aggregations