@Override public boolean equals(Object obj) { if (this == obj) { return true; } else if (obj != null && obj instanceof BanEntry) { BanEntry banEntry = (BanEntry) obj; return target.equals(banEntry.getTarget()) && expires.equals(banEntry.getExpiration()) && reason.equals(banEntry.getReason()) && source.equals(banEntry.getSource()) && created.equals(banEntry.getCreated()); } else { return false; } }
@Override public BanEntry addBan(String target, String reason, Date expires, String source) { final BanEntry entry = new MockBanEntry(target, expires, reason, source); this.bans.put(target, entry); return entry; }
@Test public void getBanEntries_OnePersonBanned_SetOfOnePerson() { banList.addBan("target", "reason", new Date(), "source"); Set<BanEntry> entries = banList.getBanEntries(); assertEquals(1, entries.size()); assertEquals("target", entries.iterator().next().getTarget()); }
/** * Gets the expiration date from a ban entry. * * @param target Target to get the expiration date from. * @return Returns the expiration date as a long in milliseconds. */ public long getExpirationLong(String target) { Validate.notNull(target, "Target cannot be null."); final BanEntry entry = Bukkit.getBanList(Type.NAME).getBanEntry(target); Validate.notNull(entry, "Cannot find BanList entry \"" + target + "\""); return entry.getExpiration().getTime(); }
/** * Gets the expiration date from a ban entry. * * @param target Target top get the expiration date from. * @return Returns the expiration date as a long in proper format. */ public Date getExpirationDate(String target) { Validate.notNull(target, "Target cannot be null."); final BanEntry entry = Bukkit.getBanList(Type.NAME).getBanEntry(target); Validate.notNull(entry, "Cannot find BanList entry \"" + target + "\""); return entry.getExpiration(); }
/** * Gets the reason for the ban. * * @param target The target to get the ban reason from. * @return Returns the reason for the ban. */ public String getReason(String target) { Validate.notNull(target, "Target cannot be null."); final BanEntry entry = Bukkit.getBanList(Type.NAME).getBanEntry(target); Validate.notNull(entry, "Cannot find BanList entry \"" + target + "\""); return entry.getReason(); }
/** * Checks if the BanList contains an entry. * * @param target The target to find in the list. * @return True if list contains target, false otherwise. */ public boolean isBanned(String target) { Validate.notNull(target, "Target cannot be null."); final BanEntry entry = Bukkit.getBanList(Type.NAME).getBanEntry(target); if (entry == null) { return false; } return true; }
@Override public boolean execute(CommandSender sender, String currentAlias, String[] args) { if (!testPermission(sender)) return true; BanList.Type banType = BanList.Type.NAME; if (args.length > 0) { if (args[0].equalsIgnoreCase("ips")) { banType = BanList.Type.IP; } else if (!args[0].equalsIgnoreCase("players")) { sender.sendMessage(ChatColor.RED + "Usage: " + usageMessage); return false; } } StringBuilder message = new StringBuilder(); BanEntry[] banlist = Bukkit.getBanList(banType).getBanEntries().toArray(new BanEntry[0]); for (int x = 0; x < banlist.length; x++) { if (x != 0) { if (x == banlist.length - 1) { message.append(" and "); } else { message.append(", "); } } message.append(banlist[x].getTarget()); } sender.sendMessage("There are " + banlist.length + " total banned players:"); sender.sendMessage(message.toString()); return true; }
@Override public BanEntry getBanEntry(String target) { BanEntry entry = null; for (Ban ban : this.banManager.getAllBans()) { if (ban.getSubject().equalsIgnoreCase(target) && (ban.isIpBan() == isIpBan)) { entry = new CanaryBanEntry(ban); } } return entry; }
@Override public BanEntry addBan(String target, String reason, Date expires, String source) { Ban ban = new Ban(Canary.getServer().getPlayer(target), reason, this.isIpBan); ban.setBanningPlayer(source); this.banManager.issueBan(ban); return this.getBanEntry(target); }
@Override public Set<BanEntry> getBanEntries() { Set<BanEntry> bans = Sets.newHashSet(); for (Ban ban : this.banManager.getAllBans()) { if (ban.isIpBan() == this.isIpBan) { bans.add(new CanaryBanEntry(ban)); } } return bans; }
public Set<String> getIPBans() { Set<String> ipBans = new HashSet<String>(); for (BanEntry entry : this.getBanList(Type.IP).getBanEntries()) { ipBans.add(entry.getTarget()); } return ipBans; }
/** * {@inheritDoc} * * @see com.blockhaus2000.ipm.minecraft.IpBanlist#getBannedIps() */ @Override public Set<String> getBannedIps() { final Set<String> result = new HashSet<String>(); for (final BanEntry banEntry : Bukkit.getServer().getBanList(BanList.Type.IP).getBanEntries()) { result.add(banEntry.getTarget()); } return result; }
/** * {@inheritDoc} * * @see com.blockhaus2000.ipm.minecraft.Banlist#getBannedPlayers() */ @SuppressWarnings("deprecation") @Override public Set<OfflinePlayer> getBannedPlayers() { final Set<OfflinePlayer> result = new HashSet<OfflinePlayer>(); for (final BanEntry banEntry : Bukkit.getServer().getBanList(BanList.Type.NAME).getBanEntries()) { result.add(InternalPluginManager.getServer().getPlayerManager().getOfflinePlayer(banEntry.getTarget())); } return result; }
@Override public BanEntry addBan(String target, String reason, Date expires, String source) { try { BanEntry entry = cache.get(target, () -> new PoreBanEntry(target, this)); entry.setCreated(new Date()); entry.setReason(reason); entry.setExpiration(expires); entry.setSource(source); entry.save(); return entry; } catch (ExecutionException e) { throw Throwables.propagate(e.getCause()); } }
private BanEntry loadBanEntry(T ban) { try { return cache.get(getTarget(ban), () -> new PoreBanEntry(ban, this)); } catch (ExecutionException e) { throw Throwables.propagate(e); } }
@Override public BanEntry getBanEntry(String target) { return bans.getOrDefault(target, null); }
@Override public Set<BanEntry> getBanEntries() { return new HashSet<>(this.bans.values()); }
@Override public BanEntry getBanEntry(String target) { return getBanFor(target).map(this::loadBanEntry).orElse(null); }
@Override public Set<BanEntry> getBanEntries() { return getBans().stream().map(this::loadBanEntry).collect(Collectors.toSet()); }
/** * Checks if a target is still banned or not. * * @param target This is the player that is being checked for the ban * expire. * @return Returns false if still banned, true otherwise. * * <p> * - Note: Use this method in a login event. To check if a player is * still banned. * </p> */ public boolean isBanExpired(String target) { Validate.notNull(target, "Target cannot be null."); final BanEntry entry = Bukkit.getBanList(Type.NAME).getBanEntry(target); Validate.notNull(entry, "Cannot find BanList entry \"" + target + "\""); final long currentTime = System.currentTimeMillis(); //Gets the current time if (getExpirationLong(target) > currentTime) { return false; } return true; }
/** * 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); }
BanEntry getBanEntry(String target);
BanEntry addBan(String target, String reason, Date expires, String source);
Set<BanEntry> getBanEntries();