use of org.spongepowered.api.service.ban.BanService in project Nucleus by NucleusPowered.
the class CheckBanCommand method executeCommand.
@Override
public CommandResult executeCommand(CommandSource src, CommandContext args) throws Exception {
GameProfile gp;
if (args.hasAny(key)) {
gp = args.<GameProfile>getOne(key).get();
} else {
gp = args.<GameProfile>getOne(key2).get();
}
BanService service = Sponge.getServiceManager().provideUnchecked(BanService.class);
Optional<Ban.Profile> obp = service.getBanFor(gp);
if (!obp.isPresent()) {
src.sendMessage(plugin.getMessageProvider().getTextMessageWithFormat("command.checkban.notset", gp.getName().orElse(plugin.getMessageProvider().getMessageWithFormat("standard.unknown"))));
return CommandResult.success();
}
Ban.Profile bp = obp.get();
String name;
if (bp.getBanSource().isPresent()) {
name = bp.getBanSource().get().toPlain();
} else {
name = plugin.getMessageProvider().getMessageWithFormat("standard.unknown");
}
if (bp.getExpirationDate().isPresent()) {
src.sendMessage(plugin.getMessageProvider().getTextMessageWithFormat("command.checkban.bannedfor", gp.getName().orElse(plugin.getMessageProvider().getMessageWithFormat("standard.unknown")), name, Util.getTimeToNow(bp.getExpirationDate().get())));
} else {
src.sendMessage(plugin.getMessageProvider().getTextMessageWithFormat("command.checkban.bannedperm", gp.getName().orElse(plugin.getMessageProvider().getMessageWithFormat("standard.unknown")), name));
}
src.sendMessage(plugin.getMessageProvider().getTextMessageWithFormat("command.checkban.created", Util.FULL_TIME_FORMATTER.withLocale(src.getLocale()).format(bp.getCreationDate())));
src.sendMessage(plugin.getMessageProvider().getTextMessageWithFormat("standard.reasoncoloured", TextSerializers.FORMATTING_CODE.serialize(bp.getReason().orElse(plugin.getMessageProvider().getTextMessageWithFormat("ban.defaultreason")))));
return CommandResult.success();
}
use of org.spongepowered.api.service.ban.BanService in project Nucleus by NucleusPowered.
the class ConnectionListener method onPlayerJoinAndCancelled.
/**
* Perform connection events on when a player is currently not permitted to join.
*
* @param event The event.
*/
@Listener(order = Order.FIRST)
@IsCancelled(Tristate.TRUE)
public void onPlayerJoinAndCancelled(ClientConnectionEvent.Login event, @Getter("getTargetUser") User user) {
// Don't affect the banned.
BanService banService = Sponge.getServiceManager().provideUnchecked(BanService.class);
if (banService.isBanned(user.getProfile()) || banService.isBanned(event.getConnection().getAddress().getAddress())) {
return;
}
if (Sponge.getServer().hasWhitelist()) {
if (this.whitelistMessage != null) {
event.setMessage(this.whitelistMessage);
event.setMessageCancelled(false);
}
// Do not continue, whitelist should always apply.
return;
}
int slotsLeft = Sponge.getServer().getMaxPlayers() - Sponge.getServer().getOnlinePlayers().size();
if (slotsLeft <= 0) {
if (user.hasPermission(this.joinFullServer)) {
// It will be negative, reserved slots is positive - need to account for that.
if (this.reservedSlots <= -1 || -slotsLeft < this.reservedSlots) {
event.setCancelled(false);
return;
}
}
if (this.fullMessage != null) {
event.setMessage(this.fullMessage);
}
}
}
Aggregations