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