org.spongepowered.api.service.ban.BanService Java Examples
The following examples show how to use
org.spongepowered.api.service.ban.BanService.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: PardonExecutor.java From EssentialCmds with MIT License | 6 votes |
public CommandResult execute(CommandSource src, CommandContext ctx) throws CommandException { Game game = EssentialCmds.getEssentialCmds().getGame(); User player = ctx.<User> getOne("player").get(); BanService srv = game.getServiceManager().provide(BanService.class).get(); if (!srv.isBanned(player.getProfile())) { src.sendMessage(Text.of(TextColors.RED, "That player is not currently banned.")); return CommandResult.empty(); } srv.removeBan(srv.getBanFor(player.getProfile()).get()); src.sendMessage(Text.of(TextColors.GREEN, "Success! ", TextColors.YELLOW, player.getName() + " has been unbanned.")); return CommandResult.success(); }
Example #2
Source File: UnbanCommand.java From UltimateCore with MIT License | 6 votes |
@Override public CommandResult execute(CommandSource src, CommandContext args) throws CommandException { GameProfile profile = args.<GameProfile>getOne("player").orElse(null); InetAddress address = args.<InetAddress>getOne("ip").orElse(null); //Unban user + Send message BanService bs = Sponge.getServiceManager().provide(BanService.class).get(); if (profile != null && bs.getBanFor(profile).isPresent()) { bs.removeBan(bs.getBanFor(profile).get()); Messages.send(src, "ban.command.unban.success", "%player%", profile.getName().orElse("")); return CommandResult.success(); } if (address != null && bs.getBanFor(address).isPresent()) { bs.removeBan(bs.getBanFor(address).get()); Messages.send(src, "ban.command.unban.success-ip", "%ip%", address.toString().replace("/", "")); return CommandResult.success(); } //Not banned throw Messages.error(src, "ban.command.unban.notbanned"); }
Example #3
Source File: PlayerOnlineListener.java From Plan with GNU Lesser General Public License v3.0 | 5 votes |
private boolean isBanned(GameProfile profile) { Optional<ProviderRegistration<BanService>> banService = Sponge.getServiceManager().getRegistration(BanService.class); boolean banned = false; if (banService.isPresent()) { banned = banService.get().getProvider().isBanned(profile); } return banned; }
Example #4
Source File: PlayerList.java From ChatUI with MIT License | 5 votes |
private void addDefaultAddons(Player player) { TextFormat link = TextFormat.of(TextColors.BLUE, TextStyles.UNDERLINE); if (player.hasPermission(PERM_KICK)) { addAddon(listPlayer -> Text.builder("Kick").format(link).onClick(Utils.execClick(view -> listPlayer.kick())).build()); } if (player.hasPermission(PERM_BAN)) { addAddon(listPlayer -> Text.builder("Ban").format(link) .onClick(Utils.execClick(view -> Sponge.getServiceManager().provideUnchecked(BanService.class).addBan(Ban.of(listPlayer.getProfile())))) .build()); } }
Example #5
Source File: TempBanExecutor.java From EssentialCmds with MIT License | 5 votes |
public CommandResult execute(CommandSource src, CommandContext ctx) throws CommandException { Game game = EssentialCmds.getEssentialCmds().getGame(); User player = ctx.<User> getOne("player").get(); String time = ctx.<String> getOne("time").get(); String reason = ctx.<String> getOne("reason").orElse("The BanHammer has spoken!"); BanService srv = game.getServiceManager().provide(BanService.class).get(); if (srv.isBanned(player.getProfile())) { src.sendMessage(Text.of(TextColors.RED, "That player has already been banned.")); return CommandResult.empty(); } srv.addBan(Ban.builder() .type(BanTypes.PROFILE) .source(src).profile(player.getProfile()) .expirationDate(getInstantFromString(time)) .reason(TextSerializers.formattingCode('&').deserialize(reason)) .build()); if (player.isOnline()) { player.getPlayer().get().kick(Text.builder() .append(Text.of(TextColors.DARK_RED, "You have been tempbanned!\n", TextColors.RED, "Reason: ")) .append(TextSerializers.formattingCode('&').deserialize(reason), Text.of("\n")) .append(Text.of(TextColors.GOLD, "Time: ", TextColors.GRAY, getFormattedString(time))) .build()); } src.sendMessage(Text.of(TextColors.GREEN, "Success! ", TextColors.YELLOW, player.getName() + " has been banned.")); return CommandResult.success(); }
Example #6
Source File: BanExecutor.java From EssentialCmds with MIT License | 5 votes |
public CommandResult execute(CommandSource src, CommandContext ctx) throws CommandException { Game game = EssentialCmds.getEssentialCmds().getGame(); User player = ctx.<User> getOne("player").get(); String reason = ctx.<String> getOne("reason").orElse("The BanHammer has spoken!"); BanService srv = game.getServiceManager().provide(BanService.class).get(); if (srv.isBanned(player.getProfile())) { src.sendMessage(Text.of(TextColors.RED, "That player has already been banned.")); return CommandResult.empty(); } srv.addBan(Ban.builder().type(BanTypes.PROFILE).source(src).profile(player.getProfile()).reason(TextSerializers.formattingCode('&').deserialize(reason)).build()); if (player.isOnline()) { player.getPlayer().get().kick(Text.builder() .append(Text.of(TextColors.DARK_RED, "You have been banned!\n ", TextColors.RED, "Reason: ")) .append(TextSerializers.formattingCode('&').deserialize(reason)) .build()); } src.sendMessage(Text.of(TextColors.GREEN, "Success! ", TextColors.YELLOW, player.getName() + " has been banned.")); return CommandResult.success(); }
Example #7
Source File: BanListener.java From UltimateCore with MIT License | 5 votes |
@Listener(order = Order.LATE) public void onMotd(ClientPingServerEvent event) { try { ModuleConfig config = Modules.BAN.get().getConfig().get(); if (!config.get().getNode("ban-motd", "enabled").getBoolean()) return; String ip = event.getClient().getAddress().getAddress().toString().replace("/", ""); GlobalDataFile file = new GlobalDataFile("ipcache"); if (file.get().getChildrenMap().keySet().contains(ip)) { //Player GameProfile profile = Sponge.getServer().getGameProfileManager().get(UUID.fromString(file.get().getNode(ip, "uuid").getString())).get(); InetAddress address = InetAddress.getByName(ip); //Check if banned BanService bs = Sponge.getServiceManager().provide(BanService.class).get(); UserStorageService us = Sponge.getServiceManager().provide(UserStorageService.class).get(); if (bs.isBanned(profile) || bs.isBanned(address)) { Text motd = VariableUtil.replaceVariables(Messages.toText(config.get().getNode("ban-motd", "text").getString()), us.get(profile.getUniqueId()).orElse(null)); //Replace ban vars Ban ban = bs.isBanned(profile) ? bs.getBanFor(profile).get() : bs.getBanFor(address).get(); Long time = ban.getExpirationDate().map(date -> (date.toEpochMilli() - System.currentTimeMillis())).orElse(-1L); motd = TextUtil.replace(motd, "%time%", (time == -1L ? Messages.getFormatted("core.time.ever") : Text.of(TimeUtil.format(time)))); motd = TextUtil.replace(motd, "%reason%", ban.getReason().orElse(Messages.getFormatted("ban.command.ban.defaultreason"))); event.getResponse().setDescription(motd); } } } catch (Exception ex) { ex.printStackTrace(); } }
Example #8
Source File: PlayerEventHandler.java From GriefDefender with MIT License | 4 votes |
public PlayerEventHandler(BaseStorage dataStore, GriefDefenderPlugin plugin) { this.dataStore = dataStore; this.worldEditProvider = GriefDefenderPlugin.getInstance().worldEditProvider; this.banService = Sponge.getServiceManager().getRegistration(BanService.class).get().getProvider(); }
Example #9
Source File: PlayerEventHandler.java From GriefPrevention with MIT License | 4 votes |
public PlayerEventHandler(DataStore dataStore, GriefPreventionPlugin plugin) { this.dataStore = dataStore; this.worldEditProvider = GriefPreventionPlugin.instance.worldEditProvider; this.banService = Sponge.getServiceManager().getRegistration(BanService.class).get().getProvider(); }
Example #10
Source File: BanCommand.java From UltimateCore with MIT License | 4 votes |
@Override public CommandResult execute(CommandSource src, CommandContext args) throws CommandException { GameProfile profile = args.<GameProfile>getOne("player").orElse(null); InetAddress address = args.<InetAddress>getOne("ip").orElse(null); Long time = args.<Long>getOne("time").orElse(-1L); Text reason = args.<String>getOne("reason").map(Messages::toText).orElse(Messages.getFormatted(src, "ban.command.ban.defaultreason")); //Try to find user User user = null; if (profile != null) { user = Sponge.getServiceManager().provide(UserStorageService.class).get().get(profile).get(); } else { //Try to find user from ip address for (GameProfile prof : Sponge.getServer().getGameProfileManager().getCache().getProfiles()) { PlayerDataFile config = new PlayerDataFile(prof.getUniqueId()); CommentedConfigurationNode node = config.get(); if (node.getNode("lastip").getString("").equalsIgnoreCase(address.toString().replace("/", ""))) { user = Sponge.getServiceManager().provide(UserStorageService.class).get().get(prof).get(); } } } //If user is present, check exempt if (user != null) { if ((BanPermissions.UC_BAN_EXEMPTPOWER.getIntFor(user) > BanPermissions.UC_BAN_POWER.getIntFor(src)) && src instanceof Player) { throw new ErrorMessageException(Messages.getFormatted(src, "ban.command.ban.exempt", "%player%", user)); } } //Ban user BanService bs = Sponge.getServiceManager().provide(BanService.class).get(); Ban.Builder bb = Ban.builder(); if (profile != null) { bb = bb.type(BanTypes.PROFILE).profile(profile); } else { bb = bb.type(BanTypes.IP).address(address); } bb = bb.source(src).startDate(Instant.now()); if (time > 0) bb = bb.expirationDate(Instant.now().plusMillis(time)); bb = bb.reason(reason); bs.addBan(bb.build()); //Kick player if (user != null && user.getPlayer().isPresent()) { if (profile != null) { user.getPlayer().get().kick(Messages.getFormatted(user.getPlayer().get(), "ban.banned", "%time%", (time == -1L ? Messages.getFormatted("core.time.ever") : TimeUtil.format(time)), "%reason%", reason)); } else { user.getPlayer().get().kick(Messages.getFormatted(user.getPlayer().get(), "ban.ipbanned", "%time%", (time == -1L ? Messages.getFormatted("core.time.ever") : TimeUtil.format(time)), "%reason%", reason)); } } //Send message if (profile != null) { Messages.send(src, "ban.command.ban.success", "%player%", profile.getName().orElse(""), "%time%", (time == -1L ? Messages.getFormatted("core.time.ever") : TimeUtil.format(time)), "%reason%", reason); } else { Messages.send(src, "ban.command.ban.success-ip", "%ip%", address.toString().replace("/", ""), "%time%", (time == -1L ? Messages.getFormatted("core.time.ever") : TimeUtil.format(time)), "%reason%", reason); } return CommandResult.success(); }
Example #11
Source File: SpongeBanProvider.java From ServerListPlus with GNU General Public License v3.0 | 4 votes |
private static Optional<BanService> getBanService() { return Sponge.getGame().getServiceManager().provide(BanService.class); }