org.bukkit.BanEntry Java Examples

The following examples show how to use org.bukkit.BanEntry. 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: ModerationCommand.java    From PGM with GNU Affero General Public License v3.0 6 votes vote down vote up
public String getPunishmentScreenFromName(Player viewer, String name) {
  if (isBanStillValid(name)) {
    BanEntry ban = Bukkit.getBanList(BanList.Type.NAME).getBanEntry(name);
    PunishmentType type =
        ban.getExpiration() != null ? PunishmentType.TEMP_BAN : PunishmentType.BAN;

    Duration length =
        type.equals(PunishmentType.TEMP_BAN)
            ? Duration.between(Instant.now(), ban.getExpiration().toInstant())
            : null;

    return formatPunishmentScreen(
        type, TextComponent.of(ban.getSource(), TextColor.AQUA), ban.getReason(), length);
  }
  return null;
}
 
Example #2
Source File: BukkitBanProvider.java    From ServerListPlus with GNU General Public License v3.0 5 votes vote down vote up
@Override
public String getBanReason(PlayerIdentity playerIdentity) {
    final BanEntry banEntry = getBanEntry(playerIdentity);

    if (banEntry == null)
        return null;

    return banEntry.getReason();
}
 
Example #3
Source File: BukkitBanProvider.java    From ServerListPlus with GNU General Public License v3.0 5 votes vote down vote up
@Override
public String getBanOperator(PlayerIdentity playerIdentity) {
    final BanEntry banEntry = getBanEntry(playerIdentity);

    if (banEntry == null)
        return null;

    return banEntry.getSource();
}
 
Example #4
Source File: BukkitBanProvider.java    From ServerListPlus with GNU General Public License v3.0 5 votes vote down vote up
@Override
public Date getBanExpiration(PlayerIdentity playerIdentity) {
    final BanEntry banEntry = getBanEntry(playerIdentity);

    if (banEntry == null)
        return null;

    return banEntry.getExpiration();
}
 
Example #5
Source File: ModerationCommand.java    From PGM with GNU Affero General Public License v3.0 4 votes vote down vote up
@Command(
    aliases = {"baninfo", "lookup", "l"},
    usage = "[player/uuid]",
    desc = "Lookup baninfo about a player",
    perms = Permissions.STAFF)
public void banInfo(Audience viewer, CommandSender sender, String target)
    throws CommandException {

  if (!XMLUtils.USERNAME_REGEX.matcher(target).matches()) {
    UUID uuid = UUID.fromString(target);
    Username username = PGM.get().getDatastore().getUsername(uuid);
    if (username.getNameLegacy() != null) {
      target = username.getNameLegacy();
    } else {
      throw new CommandException(
          TextTranslations.translateLegacy(
              TranslatableComponent.of(
                  "command.notJoinedServer",
                  TextColor.RED,
                  TextComponent.of(target, TextColor.AQUA)),
              sender));
    }
  }

  BanEntry ban = Bukkit.getBanList(BanList.Type.NAME).getBanEntry(target);

  if (ban == null
      || ban.getExpiration() != null && ban.getExpiration().toInstant().isBefore(Instant.now())) {
    throw new CommandException(
        TextTranslations.translateLegacy(
            TranslatableComponent.of(
                "moderation.records.lookupNone",
                TextColor.GRAY,
                TextComponent.of(target, TextColor.DARK_AQUA)),
            sender));
  }

  Component header =
      TextComponent.builder()
          .append(TranslatableComponent.of("moderation.records.header", TextColor.GRAY))
          .append(BROADCAST_DIV)
          .append(target, TextColor.DARK_AQUA, TextDecoration.ITALIC)
          .build();
  boolean expires = ban.getExpiration() != null;
  Component banType = TranslatableComponent.of("moderation.type.ban", TextColor.GOLD);
  Component expireDate = TextComponent.empty();
  if (expires) {
    String length =
        TextTranslations.translateLegacy(
            PeriodFormats.briefNaturalApproximate(
                ban.getCreated().toInstant(), ban.getExpiration().toInstant()),
            sender);
    Component remaining =
        PeriodFormats.briefNaturalApproximate(Instant.now(), ban.getExpiration().toInstant())
            .color(TextColor.YELLOW);

    banType =
        TranslatableComponent.of(
            "moderation.type.temp_ban",
            TextColor.GOLD,
            TextComponent.of(
                length.lastIndexOf('s') != -1
                    ? length.substring(0, length.lastIndexOf('s'))
                    : length));
    expireDate = TranslatableComponent.of("moderation.screen.expires", TextColor.GRAY, remaining);
  }

  Component createdAgo =
      PeriodFormats.relativePastApproximate(ban.getCreated().toInstant()).color(TextColor.GRAY);

  Component banTypeFormatted =
      TranslatableComponent.of("moderation.type", TextColor.GRAY, banType);

  Component reason =
      TranslatableComponent.of(
          "moderation.records.reason",
          TextColor.GRAY,
          TextComponent.of(ban.getReason(), TextColor.RED));
  Component source =
      TextComponent.builder()
          .append(
              TranslatableComponent.of(
                  "moderation.screen.signoff",
                  TextColor.GRAY,
                  TextComponent.of(ban.getSource(), TextColor.AQUA)))
          .append(TextComponent.space())
          .append(createdAgo)
          .build();

  viewer.sendMessage(TextFormatter.horizontalLineHeading(sender, header, TextColor.DARK_PURPLE));
  viewer.sendMessage(banTypeFormatted);
  viewer.sendMessage(reason);
  viewer.sendMessage(source);
  if (expires) {
    viewer.sendMessage(expireDate);
  }
}
 
Example #6
Source File: BukkitBanProvider.java    From ServerListPlus with GNU General Public License v3.0 4 votes vote down vote up
private static BanEntry getBanEntry(PlayerIdentity playerIdentity) {
    return getBanList().getBanEntry(playerIdentity.getName());
}
 
Example #7
Source File: BukkitService.java    From AuthMeReloaded with GNU General Public License v3.0 2 votes vote down vote up
/**
 * Adds a ban to the this list. If a previous ban exists, this will
 * update the previous entry.
 *
 * @param ip the ip of the ban
 * @param reason reason for the ban, null indicates implementation default
 * @param expires date for the ban's expiration (unban), or null to imply
 *     forever
 * @param source source of the ban, null indicates implementation default
 * @return the entry for the newly created ban, or the entry for the
 *     (updated) previous ban
 */
public BanEntry banIp(String ip, String reason, Date expires, String source) {
    return Bukkit.getServer().getBanList(BanList.Type.IP).addBan(ip, reason, expires, source);
}