/** * Get a ban for this player name. This may return null if the ban does not exist * * @param name * @return Returns a ban object if that ban was found, null otherwise */ public Ban getBan(String name) { Ban newBan = null; Canary.db().prepare(); DatabaseRow[] toLift = getTable().getFilteredRows("name", name); if (toLift != null && toLift.length > 0) { // It should only be one newBan = new Ban(); DatabaseRow row = toLift[0]; newBan.setReason(row.getStringCell("reason")); newBan.setSubject(row.getStringCell("name")); newBan.setIp(row.getStringCell("ip")); newBan.setTimestamp(row.getLongCell("timestamp")); } Canary.db().execute(); return newBan; }
/** * Load and return all recorded bans * * @return */ public ArrayList<Ban> loadBans() { Canary.db().prepare(); ArrayList<Ban> banList = new ArrayList<Ban>(); DatabaseTable table = getTable(); DatabaseRow[] rows = table.getAllRows(); if (rows != null) { for (DatabaseRow row : rows) { Ban ban = new Ban(); ban.setIp(row.getStringCell("ip")); ban.setReason(row.getStringCell("reason")); ban.setSubject(row.getStringCell("name")); ban.setTimestamp(row.getLongCell("timestamp")); banList.add(ban); } } Canary.db().execute(); return banList; }