forked from LogBlock/LogBlock
Fixed area stats not beeing ordered very well and showing 0
This commit is contained in:
@@ -5,8 +5,6 @@ import java.sql.PreparedStatement;
|
|||||||
import java.sql.ResultSet;
|
import java.sql.ResultSet;
|
||||||
import java.sql.SQLException;
|
import java.sql.SQLException;
|
||||||
import java.sql.Statement;
|
import java.sql.Statement;
|
||||||
import java.util.HashMap;
|
|
||||||
import java.util.HashSet;
|
|
||||||
import java.util.logging.Level;
|
import java.util.logging.Level;
|
||||||
|
|
||||||
import org.bukkit.ChatColor;
|
import org.bukkit.ChatColor;
|
||||||
@@ -27,38 +25,29 @@ public class AreaStats implements Runnable
|
|||||||
}
|
}
|
||||||
|
|
||||||
public void run() {
|
public void run() {
|
||||||
HashSet<String> players = new HashSet<String>();
|
|
||||||
HashMap<String, Integer> created = new HashMap<String, Integer>();
|
|
||||||
HashMap<String, Integer> destroyed = new HashMap<String, Integer>();
|
|
||||||
PreparedStatement ps = null;
|
PreparedStatement ps = null;
|
||||||
ResultSet rs = null;
|
ResultSet rs = null;
|
||||||
try {
|
try {
|
||||||
conn.setAutoCommit(false);
|
conn.setAutoCommit(false);
|
||||||
ps = conn.prepareStatement("SELECT playername, count(playername) as num from `" + table + "` INNER JOIN `lb-players` USING (`playerid`) where type > 0 and y > ? and y < ? and x > ? and x < ? and z > ? and z < ? group by playername order by count(playername) desc limit 10", Statement.RETURN_GENERATED_KEYS);
|
ps = conn.prepareStatement("SELECT `playername`, SUM(`created`) AS `created`, SUM(`destroyed`) AS `destroyed` FROM ((SELECT `playerid`, count(`type`) AS `created`, 0 AS `destroyed` FROM `" + table + "` WHERE `type` > 0 AND x > ? AND x < ? AND z > ? AND z < ? AND `type` != `replaced` GROUP BY `playerid`) UNION (SELECT `playerid`, 0 AS `created`, count(`replaced`) AS `destroyed` FROM `" + table + "` INNER JOIN `lb-players` USING (`playerid`) WHERE `replaced` > 0 AND x > ? AND x < ? AND z > ? AND z < ? AND `type` != `replaced` GROUP BY `playerid`)) AS t INNER JOIN `lb-players` USING (`playerid`) GROUP BY `playerid` ORDER BY SUM(`created`) + SUM(`destroyed`) DESC LIMIT 15", Statement.NO_GENERATED_KEYS);
|
||||||
ps.setInt(1, player.getLocation().getBlockY()-size);
|
ps.setInt(1, player.getLocation().getBlockX()-size);
|
||||||
ps.setInt(2, player.getLocation().getBlockY()+size);
|
ps.setInt(2, player.getLocation().getBlockX()+size);
|
||||||
ps.setInt(3, player.getLocation().getBlockX()-size);
|
ps.setInt(3, player.getLocation().getBlockZ()-size);
|
||||||
ps.setInt(4, player.getLocation().getBlockX()+size);
|
ps.setInt(4, player.getLocation().getBlockZ()+size);
|
||||||
ps.setInt(5, player.getLocation().getBlockZ()-size);
|
ps.setInt(5, player.getLocation().getBlockX()-size);
|
||||||
ps.setInt(6, player.getLocation().getBlockZ()+size);
|
ps.setInt(6, player.getLocation().getBlockX()+size);
|
||||||
|
ps.setInt(7, player.getLocation().getBlockZ()-size);
|
||||||
|
ps.setInt(8, player.getLocation().getBlockZ()+size);
|
||||||
rs = ps.executeQuery();
|
rs = ps.executeQuery();
|
||||||
while (rs.next()) {
|
player.sendMessage(ChatColor.DARK_AQUA + "Within " + size + " blocks of you: ");
|
||||||
players.add(rs.getString("playername"));
|
if (!rs.next())
|
||||||
created.put(rs.getString("playername"), rs.getInt("num"));
|
player.sendMessage(ChatColor.DARK_AQUA + "No results found.");
|
||||||
}
|
else {
|
||||||
rs.close();
|
player.sendMessage(ChatColor.GOLD + String.format("%-6s %-6s %s", "Creat", "Destr", "Player"));
|
||||||
ps.close();
|
rs.beforeFirst();
|
||||||
ps = conn.prepareStatement("SELECT playername, count(playername) as num from `" + table + "` INNER JOIN `lb-players` USING (`playerid`) where replaced > 0 and y > ? and y < ? and x > ? and x < ? and z > ? and z < ? group by playername order by count(playername) desc limit 10", Statement.RETURN_GENERATED_KEYS);
|
while (rs.next()) {
|
||||||
ps.setInt(1, player.getLocation().getBlockY()-size);
|
player.sendMessage(ChatColor.GOLD + String.format("%-6d %-6d %s", rs.getInt("created"), rs.getInt("destroyed"), rs.getString("playername")));
|
||||||
ps.setInt(2, player.getLocation().getBlockY()+size);
|
}
|
||||||
ps.setInt(3, player.getLocation().getBlockX()-size);
|
|
||||||
ps.setInt(4, player.getLocation().getBlockX()+size);
|
|
||||||
ps.setInt(5, player.getLocation().getBlockZ()-size);
|
|
||||||
ps.setInt(6, player.getLocation().getBlockZ()+size);
|
|
||||||
rs = ps.executeQuery();
|
|
||||||
while (rs.next()) {
|
|
||||||
players.add(rs.getString("playername"));
|
|
||||||
destroyed.put(rs.getString("playername"), rs.getInt("num"));
|
|
||||||
}
|
}
|
||||||
} catch (SQLException ex) {
|
} catch (SQLException ex) {
|
||||||
LogBlock.log.log(Level.SEVERE, "[LogBlock AreaStats] SQL exception", ex);
|
LogBlock.log.log(Level.SEVERE, "[LogBlock AreaStats] SQL exception", ex);
|
||||||
@@ -74,20 +63,5 @@ public class AreaStats implements Runnable
|
|||||||
LogBlock.log.log(Level.SEVERE, "[LogBlock AreaStats] SQL exception on close", ex);
|
LogBlock.log.log(Level.SEVERE, "[LogBlock AreaStats] SQL exception on close", ex);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
player.sendMessage(ChatColor.DARK_AQUA + "Within " + size + " blocks of you: ");
|
|
||||||
if (players.size() == 0)
|
|
||||||
player.sendMessage(ChatColor.DARK_AQUA + "No results found.");
|
|
||||||
else {
|
|
||||||
player.sendMessage(ChatColor.GOLD + String.format("%-6s %-6s %s", "Creat", "Destr", "Player"));
|
|
||||||
for (String p: players) {
|
|
||||||
Integer c = created.get(p);
|
|
||||||
Integer d = destroyed.get(p);
|
|
||||||
if (c == null)
|
|
||||||
c = 0;
|
|
||||||
if (d == null)
|
|
||||||
d = 0;
|
|
||||||
player.sendMessage(ChatColor.GOLD + String.format("%-6d %-6d %s", c, d, p));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user