Search in sources :

Example 11 with BanService

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();
}
Also used : GameProfile(org.spongepowered.api.profile.GameProfile) BanService(org.spongepowered.api.service.ban.BanService) GameProfile(org.spongepowered.api.profile.GameProfile) Ban(org.spongepowered.api.util.ban.Ban)

Example 12 with BanService

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);
        }
    }
}
Also used : BanService(org.spongepowered.api.service.ban.BanService) Listener(org.spongepowered.api.event.Listener) IsCancelled(org.spongepowered.api.event.filter.IsCancelled)

Aggregations

BanService (org.spongepowered.api.service.ban.BanService)12 Ban (org.spongepowered.api.util.ban.Ban)6 GameProfile (org.spongepowered.api.profile.GameProfile)4 PermissionMessageChannel (io.github.nucleuspowered.nucleus.util.PermissionMessageChannel)3 List (java.util.List)3 Nullable (javax.annotation.Nullable)3 LanternGameProfile (org.lanternpowered.server.profile.LanternGameProfile)3 Text (org.spongepowered.api.text.Text)3 MutableMessageChannel (org.spongepowered.api.text.channel.MutableMessageChannel)3 Vector3d (com.flowpowered.math.vector.Vector3d)2 InetAddress (java.net.InetAddress)2 UnknownHostException (java.net.UnknownHostException)2 Instant (java.time.Instant)2 Optional (java.util.Optional)2 WorldConfig (org.lanternpowered.server.config.world.WorldConfig)2 LanternWorld (org.lanternpowered.server.world.LanternWorld)2 CommandException (org.spongepowered.api.command.CommandException)2 Cause (org.spongepowered.api.event.cause.Cause)2 MessageEvent (org.spongepowered.api.event.message.MessageEvent)2 MessageChannel (org.spongepowered.api.text.channel.MessageChannel)2