private static final void mysqlFind( final Plugin plugin, final Location location, final int radius, final WorldManager manager, final ArrayList<Player> players) { PreparedStatement ps = null; ResultSet rs = null; Connection conn = null; HashMap<BBPlayerInfo, Integer> modifications = new HashMap<BBPlayerInfo, Integer>(); try { conn = ConnectionManager.getConnection(); if (conn == null) return; // TODO maybe more customizable actions? String actionString = "action IN('" + Action.BLOCK_BROKEN.ordinal() + "', '" + Action.BLOCK_PLACED.ordinal() + "', '" + Action.LEAF_DECAY.ordinal() + "', '" + Action.TNT_EXPLOSION.ordinal() + "', '" + Action.CREEPER_EXPLOSION.ordinal() + "', '" + Action.MISC_EXPLOSION.ordinal() + "', '" + Action.LAVA_FLOW.ordinal() + "', '" + Action.BLOCK_BURN.ordinal() + "')"; /* * org.h2.jdbc.JdbcSQLException: Column "ID" must be in the GROUP BY * list; SQL statement: */ if (BBSettings.usingDBMS(DBMS.H2) || BBSettings.usingDBMS(DBMS.POSTGRES)) { ps = conn.prepareStatement( "SELECT player, count(player) AS modifications FROM " + BBDataTable.getInstance().getTableName() + " WHERE " + actionString + " AND rbacked = '0' AND x < ? AND x > ? AND y < ? AND y > ? AND z < ? AND z > ? AND world = ? GROUP BY id,player ORDER BY id DESC"); } else { ps = conn.prepareStatement( "SELECT player, count(player) AS modifications FROM " + BBDataTable.getInstance().getTableName() + " WHERE " + actionString + " AND rbacked = '0' AND x < ? AND x > ? AND y < ? AND y > ? AND z < ? AND z > ? AND world = ? GROUP BY player ORDER BY id DESC"); } ps.setInt(1, location.getBlockX() + radius); ps.setInt(2, location.getBlockX() - radius); ps.setInt(3, location.getBlockY() + radius); ps.setInt(4, location.getBlockY() - radius); ps.setInt(5, location.getBlockZ() + radius); ps.setInt(6, location.getBlockZ() - radius); ps.setInt(7, manager.getWorld(location.getWorld().getName())); rs = ps.executeQuery(); conn.commit(); int size = 0; while (rs.next()) { BBPlayerInfo player = BBUsersTable.getInstance().getUserByID(rs.getInt("player")); int mods = rs.getInt("modifications"); modifications.put(player, mods); size++; } if (size > 0) { StringBuilder playerList = new StringBuilder(); for (Entry<BBPlayerInfo, Integer> entry : modifications.entrySet()) { if (entry.getKey() != null) { playerList.append(entry.getKey().getName()); playerList.append(" ("); playerList.append(entry.getValue()); playerList.append("), "); } } if (playerList.indexOf(",") != -1) { playerList.delete(playerList.lastIndexOf(","), playerList.length()); } // TODO Put into sync'd runnable for (Player player : players) { player.sendMessage( BigBrother.premessage + playerList.length() + " player(s) have modified this area:"); player.sendMessage(playerList.toString()); } } else { for (Player player : players) { player.sendMessage(BigBrother.premessage + "No modifications in this area."); } } } catch (SQLException ex) { BBLogging.severe("Find SQL Exception", ex); } finally { ConnectionManager.cleanup("Find SQL", conn, ps, rs); } }