use of org.spongepowered.api.service.ban.Ban 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);
}
use of org.spongepowered.api.service.ban.Ban 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()));
}
Aggregations