/** * Update a ban. * * @param ban */ public void updateBan(Ban ban) { Canary.db().prepare(); DatabaseRow[] rows = getTable().getFilteredRows("name", ban.getSubject()); // It's only this one if (rows != null && rows.length > 0) { DatabaseRow row = rows[0]; row.setStringCell("reason", ban.getReason()); row.setStringCell("ip", ban.getIp()); row.setLongCell("timestamp", ban.getTimestamp()); } Canary.db().execute(); }
/** * Add a new Ban to the list of bans. * * @param ban */ public void addBan(Ban ban) { if (banExists(ban)) { updateBan(ban); return; } Canary.db().prepare(); DatabaseRow newData = getTable().addRow(); newData.setStringCell("name", ban.getSubject()); newData.setLongCell("timestamp", ban.getTimestamp()); newData.setStringCell("reason", ban.getReason()); newData.setStringCell("ip", ban.getIp()); Canary.db().execute(); }
private boolean banExists(Ban ban) { DatabaseRow[] rows = getTable().getFilteredRows("name", ban.getSubject()); if (rows == null || rows.length == 0) { return false; } return true; }
/** * 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; }