Search in sources :

Example 6 with BanService

use of org.spongepowered.api.service.ban.BanService in project Nucleus by NucleusPowered.

the class UnbanCommand 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.empty();
    }
    service.removeBan(obp.get());
    MutableMessageChannel notify = new PermissionMessageChannel(BanCommand.notifyPermission).asMutable();
    notify.addMember(src);
    notify.send(plugin.getMessageProvider().getTextMessageWithFormat("command.unban.success", obp.get().getProfile().getName().orElse("standard.unknown"), src.getName()));
    return CommandResult.success();
}
Also used : PermissionMessageChannel(io.github.nucleuspowered.nucleus.util.PermissionMessageChannel) GameProfile(org.spongepowered.api.profile.GameProfile) BanService(org.spongepowered.api.service.ban.BanService) GameProfile(org.spongepowered.api.profile.GameProfile) MutableMessageChannel(org.spongepowered.api.text.channel.MutableMessageChannel)

Example 7 with BanService

use of org.spongepowered.api.service.ban.BanService in project LanternServer by LanternPowered.

the class CommandPardonIp method completeSpec.

@Override
public void completeSpec(PluginContainer pluginContainer, CommandSpec.Builder specBuilder) {
    specBuilder.arguments(GenericArguments.string(Text.of("address"))).executor((src, args) -> {
        final String target = args.<String>getOne("address").get();
        InetAddress address;
        if (CommandBanIp.IP_PATTERN.matcher(target).matches()) {
            try {
                address = InetAddress.getByName(target);
            } catch (UnknownHostException e) {
                throw new IllegalStateException("Unable to parse a valid InetAddress: " + target, e);
            }
        } else {
            throw new CommandException(t("commands.unbanip.invalid"));
        }
        final BanService banService = Sponge.getServiceManager().provideUnchecked(BanService.class);
        banService.pardon(address);
        src.sendMessage(t("commands.banip.success", address.toString()));
        return CommandResult.success();
    });
}
Also used : UnknownHostException(java.net.UnknownHostException) CommandException(org.spongepowered.api.command.CommandException) BanService(org.spongepowered.api.service.ban.BanService) InetAddress(java.net.InetAddress)

Example 8 with BanService

use of org.spongepowered.api.service.ban.BanService in project LanternServer by LanternPowered.

the class CommandBanIp method completeSpec.

@Override
public void completeSpec(PluginContainer pluginContainer, CommandSpec.Builder specBuilder) {
    specBuilder.arguments(GenericArguments.string(Text.of("address")), GenericArguments.optional(GenericArguments2.remainingString(Text.of("reason")))).executor((src, args) -> {
        final String target = args.<String>getOne("address").get();
        final String reason = args.<String>getOne("reason").orElse(null);
        InetAddress address;
        if (IP_PATTERN.matcher(target).matches()) {
            try {
                address = InetAddress.getByName(target);
            } catch (UnknownHostException e) {
                throw new IllegalStateException("Unable to parse a valid InetAddress: " + target, e);
            }
        } else {
            // Ip address failed, try to find a player
            Optional<Player> player = Sponge.getGame().getServer().getPlayer(target);
            if (!player.isPresent()) {
                throw new CommandException(t("commands.banip.invalid"));
            }
            address = player.get().getConnection().getAddress().getAddress();
        }
        final BanService banService = Sponge.getServiceManager().provideUnchecked(BanService.class);
        final Ban ban = Ban.builder().type(BanTypes.IP).address(address).reason(reason == null ? null : Text.of(reason)).source(src).build();
        banService.addBan(ban);
        final List<LanternPlayer> playersToKick = Lantern.getServer().getRawOnlinePlayers().stream().filter(player -> player.getConnection().getAddress().getAddress().equals(address)).collect(Collectors.toList());
        if (!playersToKick.isEmpty()) {
            final Text kickReason = t("multiplayer.disconnect.ip_banned");
            for (LanternPlayer player : playersToKick) {
                player.kick(kickReason);
            }
        }
        src.sendMessage(t("commands.banip.success", address.toString()));
        return CommandResult.success();
    });
}
Also used : CommandResult(org.spongepowered.api.command.CommandResult) TranslationHelper.t(org.lanternpowered.server.text.translation.TranslationHelper.t) Sponge(org.spongepowered.api.Sponge) BanTypes(org.spongepowered.api.util.ban.BanTypes) GenericArguments(org.spongepowered.api.command.args.GenericArguments) UnknownHostException(java.net.UnknownHostException) Collectors(java.util.stream.Collectors) Ban(org.spongepowered.api.util.ban.Ban) CommandSpec(org.spongepowered.api.command.spec.CommandSpec) CommandException(org.spongepowered.api.command.CommandException) InetAddress(java.net.InetAddress) List(java.util.List) Text(org.spongepowered.api.text.Text) Lantern(org.lanternpowered.server.game.Lantern) GenericArguments2(org.lanternpowered.server.command.element.GenericArguments2) LanternPlayer(org.lanternpowered.server.entity.living.player.LanternPlayer) Optional(java.util.Optional) Player(org.spongepowered.api.entity.living.player.Player) Pattern(java.util.regex.Pattern) PluginContainer(org.spongepowered.api.plugin.PluginContainer) BanService(org.spongepowered.api.service.ban.BanService) LanternPlayer(org.lanternpowered.server.entity.living.player.LanternPlayer) Player(org.spongepowered.api.entity.living.player.Player) UnknownHostException(java.net.UnknownHostException) Text(org.spongepowered.api.text.Text) CommandException(org.spongepowered.api.command.CommandException) Ban(org.spongepowered.api.util.ban.Ban) BanService(org.spongepowered.api.service.ban.BanService) InetAddress(java.net.InetAddress) LanternPlayer(org.lanternpowered.server.entity.living.player.LanternPlayer)

Example 9 with BanService

use of org.spongepowered.api.service.ban.BanService in project LanternServer by LanternPowered.

the class LanternUserStorageService method delete.

@Override
public boolean delete(GameProfile profile) {
    // Ops Config
    this.opsConfig.removeEntry(profile.getUniqueId());
    // Whitelist Service
    this.whitelistService.get().removeProfile(profile);
    // Ban Service
    final BanService banService = this.banService.get();
    banService.getBanFor(profile).ifPresent(banService::removeBan);
    return true;
}
Also used : BanService(org.spongepowered.api.service.ban.BanService)

Example 10 with BanService

use of org.spongepowered.api.service.ban.BanService in project Nucleus by NucleusPowered.

the class BanCommand method executeBan.

private CommandResult executeBan(CommandSource src, GameProfile u, String r) {
    BanService service = Sponge.getServiceManager().provideUnchecked(BanService.class);
    UserStorageService uss = Sponge.getServiceManager().provideUnchecked(UserStorageService.class);
    User user = uss.get(u).get();
    if (!user.isOnline() && !permissions.testSuffix(src, "offline")) {
        src.sendMessage(plugin.getMessageProvider().getTextMessageWithFormat("command.ban.offline.noperms"));
        return CommandResult.empty();
    }
    if (service.isBanned(u)) {
        src.sendMessage(plugin.getMessageProvider().getTextMessageWithFormat("command.ban.alreadyset", u.getName().orElse(plugin.getMessageProvider().getMessageWithFormat("standard.unknown"))));
        return CommandResult.empty();
    }
    // Create the ban.
    Ban bp = Ban.builder().type(BanTypes.PROFILE).profile(u).source(src).reason(TextSerializers.FORMATTING_CODE.deserialize(r)).build();
    service.addBan(bp);
    // Get the permission, "quickstart.ban.notify"
    MutableMessageChannel send = new PermissionMessageChannel(notifyPermission).asMutable();
    send.addMember(src);
    send.send(plugin.getMessageProvider().getTextMessageWithFormat("command.ban.applied", u.getName().orElse(plugin.getMessageProvider().getMessageWithFormat("standard.unknown")), src.getName()));
    send.send(plugin.getMessageProvider().getTextMessageWithFormat("standard.reasoncoloured", r));
    if (Sponge.getServer().getPlayer(u.getUniqueId()).isPresent()) {
        Sponge.getServer().getPlayer(u.getUniqueId()).get().kick(TextSerializers.FORMATTING_CODE.deserialize(r));
    }
    return CommandResult.success();
}
Also used : UserStorageService(org.spongepowered.api.service.user.UserStorageService) PermissionMessageChannel(io.github.nucleuspowered.nucleus.util.PermissionMessageChannel) User(org.spongepowered.api.entity.living.player.User) BanService(org.spongepowered.api.service.ban.BanService) Ban(org.spongepowered.api.util.ban.Ban) MutableMessageChannel(org.spongepowered.api.text.channel.MutableMessageChannel)

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