org.spongepowered.api.util.ban.BanTypes Java Examples
The following examples show how to use
org.spongepowered.api.util.ban.BanTypes.
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: PlayerKickBanTask.java From GriefPrevention with MIT License | 5 votes |
@Override public void run() { if (this.ban) { final Ban banProfile = Ban.builder() .type(BanTypes.PROFILE) .source(this.source) .profile(player.getProfile()) .reason(this.reason) .build(); this.banService.addBan(banProfile); this.player.kick(this.reason); } else { this.player.kick(this.reason); } }
Example #2
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 #3
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 #4
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(); }