forked from LogBlock/LogBlock
v12: add tool-block-id, tool-block-remove, and /lb block [block]
This commit is contained in:
79
AreaBlockSearch.java
Executable file
79
AreaBlockSearch.java
Executable file
@@ -0,0 +1,79 @@
|
|||||||
|
import java.util.HashSet;
|
||||||
|
import java.util.HashMap;
|
||||||
|
import java.text.SimpleDateFormat;
|
||||||
|
|
||||||
|
import java.util.logging.*;
|
||||||
|
import java.sql.*;
|
||||||
|
|
||||||
|
public class AreaBlockSearch implements Runnable
|
||||||
|
{
|
||||||
|
static final Logger log = Logger.getLogger("Minecraft");
|
||||||
|
private Player player;
|
||||||
|
private Location location;
|
||||||
|
private int type;
|
||||||
|
private int size;
|
||||||
|
private Connection conn = null;
|
||||||
|
|
||||||
|
AreaBlockSearch(Connection conn, Player player, int type, int size)
|
||||||
|
{
|
||||||
|
this.player = player;
|
||||||
|
this.location = player.getLocation();
|
||||||
|
this.type = type;
|
||||||
|
this.size = size;
|
||||||
|
this.conn = conn;
|
||||||
|
}
|
||||||
|
public void run()
|
||||||
|
{
|
||||||
|
boolean hist = false;
|
||||||
|
PreparedStatement ps = null;
|
||||||
|
ResultSet rs = null;
|
||||||
|
Timestamp date;
|
||||||
|
SimpleDateFormat formatter = new SimpleDateFormat("MM-dd hh:mm:ss");
|
||||||
|
|
||||||
|
try {
|
||||||
|
conn.setAutoCommit(false);
|
||||||
|
ps = conn.prepareStatement("SELECT * from blocks where (type = ? or replaced = ?) and y > ? and y < ? and x > ? and x < ? and z > ? and z < ? order by date desc limit 10", Statement.RETURN_GENERATED_KEYS);
|
||||||
|
ps.setInt(1, type);
|
||||||
|
ps.setInt(2, type);
|
||||||
|
ps.setInt(3, (int)(location.y) - size);
|
||||||
|
ps.setInt(4, (int)(location.y) + size);
|
||||||
|
ps.setInt(5, (int)(location.x) - size);
|
||||||
|
ps.setInt(6, (int)(location.x) + size);
|
||||||
|
ps.setInt(7, (int)(location.z) - size);
|
||||||
|
ps.setInt(8, (int)(location.z) + size);
|
||||||
|
rs = ps.executeQuery();
|
||||||
|
|
||||||
|
player.sendMessage(Colors.Blue + "Block history within " + size + " blocks of " + (int)(location.x) + ", " + (int)(location.y) + ", " + (int)(location.z) + ": ");
|
||||||
|
|
||||||
|
while (rs.next())
|
||||||
|
{
|
||||||
|
date = rs.getTimestamp("date");
|
||||||
|
String datestr = formatter.format(date);
|
||||||
|
String msg = datestr + " " + rs.getString("player") + " (" + rs.getInt("x") + ", " + rs.getInt("y") + ", " + rs.getInt("z") + ") ";
|
||||||
|
if (rs.getInt("type") == 0)
|
||||||
|
msg = msg + "destroyed " + etc.getDataSource().getItem(rs.getInt("replaced"));
|
||||||
|
else if (rs.getInt("replaced") == 0)
|
||||||
|
msg = msg + "created " + etc.getDataSource().getItem(rs.getInt("type"));
|
||||||
|
else
|
||||||
|
msg = msg + "replaced " + etc.getDataSource().getItem(rs.getInt("replaced")) + " with " + etc.getDataSource().getItem(rs.getInt("type"));
|
||||||
|
player.sendMessage(Colors.Gold + msg);
|
||||||
|
hist = true;
|
||||||
|
}
|
||||||
|
} catch (SQLException ex) {
|
||||||
|
log.log(Level.SEVERE, this.getClass().getName() + " SQL exception", ex);
|
||||||
|
} finally {
|
||||||
|
try {
|
||||||
|
if (rs != null)
|
||||||
|
rs.close();
|
||||||
|
if (ps != null)
|
||||||
|
ps.close();
|
||||||
|
if (conn != null)
|
||||||
|
conn.close();
|
||||||
|
} catch (SQLException ex) {
|
||||||
|
log.log(Level.SEVERE, this.getClass().getName() + " SQL exception on close", ex);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (!hist)
|
||||||
|
player.sendMessage(Colors.Blue + "None.");
|
||||||
|
}
|
||||||
|
}
|
95
AreaStats.java
Executable file
95
AreaStats.java
Executable file
@@ -0,0 +1,95 @@
|
|||||||
|
import java.util.HashSet;
|
||||||
|
import java.util.HashMap;
|
||||||
|
|
||||||
|
import java.util.logging.*;
|
||||||
|
import java.sql.*;
|
||||||
|
|
||||||
|
public class AreaStats implements Runnable
|
||||||
|
{
|
||||||
|
static final Logger log = Logger.getLogger("Minecraft");
|
||||||
|
private Player player;
|
||||||
|
private int size;
|
||||||
|
private Connection conn = null;
|
||||||
|
|
||||||
|
AreaStats(Connection conn, Player player, int size)
|
||||||
|
{
|
||||||
|
this.player = player;
|
||||||
|
this.size = size;
|
||||||
|
this.conn = conn;
|
||||||
|
}
|
||||||
|
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;
|
||||||
|
ResultSet rs = null;
|
||||||
|
|
||||||
|
try {
|
||||||
|
conn.setAutoCommit(false);
|
||||||
|
ps = conn.prepareStatement("SELECT player, count(player) as num from blocks where type > 0 and y > ? and y < ? and x > ? and x < ? and z > ? and z < ? group by player order by count(player) desc limit 10", Statement.RETURN_GENERATED_KEYS);
|
||||||
|
ps.setInt(1, (int)player.getY()-size);
|
||||||
|
ps.setInt(2, (int)player.getY()+size);
|
||||||
|
ps.setInt(3, (int)player.getX()-size);
|
||||||
|
ps.setInt(4, (int)player.getX()+size);
|
||||||
|
ps.setInt(5, (int)player.getZ()-size);
|
||||||
|
ps.setInt(6, (int)player.getZ()+size);
|
||||||
|
rs = ps.executeQuery();
|
||||||
|
while (rs.next())
|
||||||
|
{
|
||||||
|
players.add(rs.getString("player"));
|
||||||
|
created.put(rs.getString("player"), rs.getInt("num"));
|
||||||
|
}
|
||||||
|
rs.close();
|
||||||
|
ps.close();
|
||||||
|
|
||||||
|
ps = conn.prepareStatement("SELECT player, count(player) as num from blocks where replaced > 0 and y > ? and y < ? and x > ? and x < ? and z > ? and z < ? group by player order by count(player) desc limit 10", Statement.RETURN_GENERATED_KEYS);
|
||||||
|
ps.setInt(1, (int)player.getY()-size);
|
||||||
|
ps.setInt(2, (int)player.getY()+size);
|
||||||
|
ps.setInt(3, (int)player.getX()-size);
|
||||||
|
ps.setInt(4, (int)player.getX()+size);
|
||||||
|
ps.setInt(5, (int)player.getZ()-size);
|
||||||
|
ps.setInt(6, (int)player.getZ()+size);
|
||||||
|
rs = ps.executeQuery();
|
||||||
|
while (rs.next())
|
||||||
|
{
|
||||||
|
players.add(rs.getString("player"));
|
||||||
|
destroyed.put(rs.getString("player"), rs.getInt("num"));
|
||||||
|
}
|
||||||
|
|
||||||
|
} catch (SQLException ex) {
|
||||||
|
log.log(Level.SEVERE, this.getClass().getName() + " SQL exception", ex);
|
||||||
|
} finally {
|
||||||
|
try {
|
||||||
|
if (rs != null)
|
||||||
|
rs.close();
|
||||||
|
if (ps != null)
|
||||||
|
ps.close();
|
||||||
|
if (conn != null)
|
||||||
|
conn.close();
|
||||||
|
} catch (SQLException ex) {
|
||||||
|
log.log(Level.SEVERE, this.getClass().getName() + " SQL exception on close", ex);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
player.sendMessage(Colors.Blue + "Within " + size + " blocks of you: ");
|
||||||
|
if (players.size() == 0)
|
||||||
|
{
|
||||||
|
player.sendMessage(Colors.Blue + "No results found.");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
player.sendMessage(Colors.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(Colors.Gold + String.format("%-6d %-6d %s", c, d, p));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
322
LogBlock.java
322
LogBlock.java
@@ -1,13 +1,8 @@
|
|||||||
import java.util.ArrayList;
|
|
||||||
import java.util.HashSet;
|
|
||||||
import java.util.HashMap;
|
|
||||||
import java.util.logging.*;
|
|
||||||
import java.util.Timer;
|
|
||||||
import java.util.TimerTask;
|
|
||||||
import java.util.concurrent.TimeUnit;
|
import java.util.concurrent.TimeUnit;
|
||||||
import java.util.concurrent.LinkedBlockingQueue;
|
import java.util.concurrent.LinkedBlockingQueue;
|
||||||
import java.text.SimpleDateFormat;
|
import java.text.SimpleDateFormat;
|
||||||
|
|
||||||
|
import java.util.logging.*;
|
||||||
import java.sql.*;
|
import java.sql.*;
|
||||||
import java.io.*;
|
import java.io.*;
|
||||||
|
|
||||||
@@ -16,15 +11,18 @@ import net.minecraft.server.MinecraftServer;
|
|||||||
public class LogBlock extends Plugin
|
public class LogBlock extends Plugin
|
||||||
{
|
{
|
||||||
private static String name = "LogBlock";
|
private static String name = "LogBlock";
|
||||||
private static int version = 10;
|
private static int version = 12;
|
||||||
private boolean debug = false;
|
private boolean debug = false;
|
||||||
private String dbDriver = "com.mysql.jdbc.Driver";
|
private String dbDriver = "com.mysql.jdbc.Driver";
|
||||||
private String dbUrl = "";
|
private String dbUrl = "";
|
||||||
private String dbUsername = "";
|
private String dbUsername = "";
|
||||||
private String dbPassword = "";
|
private String dbPassword = "";
|
||||||
|
private boolean usehModDb = false;
|
||||||
private int delay = 10;
|
private int delay = 10;
|
||||||
private int defaultDist = 20;
|
private int defaultDist = 6;
|
||||||
private int toolID = 270; // 270 is wood pick
|
private int toolID = 270; // 270 is wood pick axe
|
||||||
|
private int toolblockID = 7; // 78 is adminium
|
||||||
|
private boolean toolblockRemove = true;
|
||||||
private Consumer consumer = null;
|
private Consumer consumer = null;
|
||||||
private Block lastface = null;
|
private Block lastface = null;
|
||||||
|
|
||||||
@@ -39,17 +37,21 @@ public class LogBlock extends Plugin
|
|||||||
PropertiesFile properties = new PropertiesFile("logblock.properties");
|
PropertiesFile properties = new PropertiesFile("logblock.properties");
|
||||||
try {
|
try {
|
||||||
debug = properties.getBoolean("debug", false);
|
debug = properties.getBoolean("debug", false);
|
||||||
|
usehModDb = properties.getBoolean("use-hmod-db", false);
|
||||||
dbDriver = properties.getString("driver", "com.mysql.jdbc.Driver");
|
dbDriver = properties.getString("driver", "com.mysql.jdbc.Driver");
|
||||||
dbUrl = properties.getString("url", "jdbc:mysql://localhost:3306/db");
|
dbUrl = properties.getString("url", "jdbc:mysql://localhost:3306/db");
|
||||||
dbUsername = properties.getString("username", "user");
|
dbUsername = properties.getString("username", "user");
|
||||||
dbPassword = properties.getString("password", "pass");
|
dbPassword = properties.getString("password", "pass");
|
||||||
delay = properties.getInt("delay", 10);
|
delay = properties.getInt("delay", 6);
|
||||||
toolID = properties.getInt("tool-id", 270);
|
toolID = properties.getInt("tool-id", 270);
|
||||||
defaultDist = properties.getInt("default-distance", 20);
|
toolblockID = properties.getInt("tool-block-id", 7);
|
||||||
|
toolblockRemove = properties.getBoolean("tool-block-remove", true);
|
||||||
|
defaultDist = properties.getInt("default-distance", 10);
|
||||||
} catch (Exception ex) {
|
} catch (Exception ex) {
|
||||||
log.log(Level.SEVERE, "Exception while reading from logblock.properties", ex);
|
log.log(Level.SEVERE, "Exception while reading from logblock.properties", ex);
|
||||||
}
|
}
|
||||||
try {
|
try {
|
||||||
|
if (!usehModDb)
|
||||||
new JDCConnectionDriver(dbDriver, dbUrl, dbUsername, dbPassword);
|
new JDCConnectionDriver(dbDriver, dbUrl, dbUsername, dbPassword);
|
||||||
} catch (Exception ex) {
|
} catch (Exception ex) {
|
||||||
log.log(Level.SEVERE, "Exception while creation database connection pool", ex);
|
log.log(Level.SEVERE, "Exception while creation database connection pool", ex);
|
||||||
@@ -90,6 +92,8 @@ public class LogBlock extends Plugin
|
|||||||
|
|
||||||
private Connection getConnection() throws SQLException
|
private Connection getConnection() throws SQLException
|
||||||
{
|
{
|
||||||
|
if (usehModDb)
|
||||||
|
return etc.getSQLConnection();
|
||||||
return DriverManager.getConnection("jdbc:jdc:jdcpool");
|
return DriverManager.getConnection("jdbc:jdc:jdcpool");
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -133,6 +137,7 @@ public class LogBlock extends Plugin
|
|||||||
rs.close();
|
rs.close();
|
||||||
if (ps != null)
|
if (ps != null)
|
||||||
ps.close();
|
ps.close();
|
||||||
|
if (conn != null)
|
||||||
conn.close();
|
conn.close();
|
||||||
} catch (SQLException ex) {
|
} catch (SQLException ex) {
|
||||||
log.log(Level.SEVERE, name + " SQL exception on close", ex);
|
log.log(Level.SEVERE, name + " SQL exception on close", ex);
|
||||||
@@ -142,249 +147,6 @@ public class LogBlock extends Plugin
|
|||||||
player.sendMessage(Colors.Blue + "None.");
|
player.sendMessage(Colors.Blue + "None.");
|
||||||
}
|
}
|
||||||
|
|
||||||
private class AreaStats implements Runnable
|
|
||||||
{
|
|
||||||
private Player player;
|
|
||||||
private int size;
|
|
||||||
AreaStats(Player player, int size)
|
|
||||||
{
|
|
||||||
this.player = player;
|
|
||||||
this.size = size;
|
|
||||||
}
|
|
||||||
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>();
|
|
||||||
|
|
||||||
Connection conn = null;
|
|
||||||
PreparedStatement ps = null;
|
|
||||||
ResultSet rs = null;
|
|
||||||
|
|
||||||
try {
|
|
||||||
conn = getConnection();
|
|
||||||
conn.setAutoCommit(false);
|
|
||||||
ps = conn.prepareStatement("SELECT player, count(player) as num from blocks where type > 0 and y > 0 and x > ? and x < ? and z > ? and z < ? group by player order by count(player) desc limit 10", Statement.RETURN_GENERATED_KEYS);
|
|
||||||
ps.setInt(1, (int)player.getX()-size);
|
|
||||||
ps.setInt(2, (int)player.getX()+size);
|
|
||||||
ps.setInt(3, (int)player.getZ()-size);
|
|
||||||
ps.setInt(4, (int)player.getZ()+size);
|
|
||||||
rs = ps.executeQuery();
|
|
||||||
while (rs.next())
|
|
||||||
{
|
|
||||||
players.add(rs.getString("player"));
|
|
||||||
created.put(rs.getString("player"), rs.getInt("num"));
|
|
||||||
}
|
|
||||||
rs.close();
|
|
||||||
ps.close();
|
|
||||||
|
|
||||||
ps = conn.prepareStatement("SELECT player, count(player) as num from blocks where replaced > 0 and y > 0 and x > ? and x < ? and z > ? and z < ? group by player order by count(player) desc limit 10", Statement.RETURN_GENERATED_KEYS);
|
|
||||||
ps.setInt(1, (int)player.getX()-size);
|
|
||||||
ps.setInt(2, (int)player.getX()+size);
|
|
||||||
ps.setInt(3, (int)player.getZ()-size);
|
|
||||||
ps.setInt(4, (int)player.getZ()+size);
|
|
||||||
rs = ps.executeQuery();
|
|
||||||
while (rs.next())
|
|
||||||
{
|
|
||||||
players.add(rs.getString("player"));
|
|
||||||
destroyed.put(rs.getString("player"), rs.getInt("num"));
|
|
||||||
}
|
|
||||||
|
|
||||||
} catch (SQLException ex) {
|
|
||||||
log.log(Level.SEVERE, name + " SQL exception", ex);
|
|
||||||
} finally {
|
|
||||||
try {
|
|
||||||
if (rs != null)
|
|
||||||
rs.close();
|
|
||||||
if (ps != null)
|
|
||||||
ps.close();
|
|
||||||
conn.close();
|
|
||||||
} catch (SQLException ex) {
|
|
||||||
log.log(Level.SEVERE, name + " SQL exception on close", ex);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
player.sendMessage(Colors.Blue + "Within " + size + " blocks of you: ");
|
|
||||||
if (players.size() == 0)
|
|
||||||
{
|
|
||||||
player.sendMessage(Colors.Blue + "No results found.");
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
player.sendMessage(Colors.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(Colors.Gold + String.format("%-6d %-6d %s", c, d, p));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private class PlayerAreaStats implements Runnable
|
|
||||||
{
|
|
||||||
private Player player;
|
|
||||||
private String name;
|
|
||||||
private int size;
|
|
||||||
PlayerAreaStats(Player player, String name, int size)
|
|
||||||
{
|
|
||||||
this.player = player;
|
|
||||||
this.name = name;
|
|
||||||
this.size = size;
|
|
||||||
}
|
|
||||||
public void run()
|
|
||||||
{
|
|
||||||
HashSet<String> types = new HashSet<String>();
|
|
||||||
HashMap<String, Integer> created = new HashMap<String, Integer>();
|
|
||||||
HashMap<String, Integer> destroyed = new HashMap<String, Integer>();
|
|
||||||
|
|
||||||
Connection conn = null;
|
|
||||||
PreparedStatement ps = null;
|
|
||||||
ResultSet rs = null;
|
|
||||||
|
|
||||||
try {
|
|
||||||
conn = getConnection();
|
|
||||||
conn.setAutoCommit(false);
|
|
||||||
ps = conn.prepareStatement("SELECT type, count(type) as num from blocks where type > 0 and player = ? and y > 0 and x > ? and x < ? and z > ? and z < ? group by type order by count(replaced) desc limit 10", Statement.RETURN_GENERATED_KEYS);
|
|
||||||
ps.setString(1, name);
|
|
||||||
ps.setInt(2, (int)player.getX()-size);
|
|
||||||
ps.setInt(3, (int)player.getX()+size);
|
|
||||||
ps.setInt(4, (int)player.getZ()-size);
|
|
||||||
ps.setInt(5, (int)player.getZ()+size);
|
|
||||||
rs = ps.executeQuery();
|
|
||||||
while (rs.next())
|
|
||||||
{
|
|
||||||
types.add(etc.getDataSource().getItem(rs.getInt("type")));
|
|
||||||
created.put(etc.getDataSource().getItem(rs.getInt("type")), rs.getInt("num"));
|
|
||||||
}
|
|
||||||
rs.close();
|
|
||||||
ps.close();
|
|
||||||
|
|
||||||
ps = conn.prepareStatement("SELECT replaced, count(replaced) as num from blocks where replaced > 0 and player = ? and y > 0 and x > ? and x < ? and z > ? and z < ? group by replaced order by count(replaced) desc limit 10", Statement.RETURN_GENERATED_KEYS);
|
|
||||||
ps.setString(1, name);
|
|
||||||
ps.setInt(2, (int)player.getX()-size);
|
|
||||||
ps.setInt(3, (int)player.getX()+size);
|
|
||||||
ps.setInt(4, (int)player.getZ()-size);
|
|
||||||
ps.setInt(5, (int)player.getZ()+size);
|
|
||||||
rs = ps.executeQuery();
|
|
||||||
while (rs.next())
|
|
||||||
{
|
|
||||||
types.add(etc.getDataSource().getItem(rs.getInt("replaced")));
|
|
||||||
destroyed.put(etc.getDataSource().getItem(rs.getInt("replaced")), rs.getInt("num"));
|
|
||||||
}
|
|
||||||
|
|
||||||
} catch (SQLException ex) {
|
|
||||||
log.log(Level.SEVERE, name + " SQL exception", ex);
|
|
||||||
} finally {
|
|
||||||
try {
|
|
||||||
if (rs != null)
|
|
||||||
rs.close();
|
|
||||||
if (ps != null)
|
|
||||||
ps.close();
|
|
||||||
conn.close();
|
|
||||||
} catch (SQLException ex) {
|
|
||||||
log.log(Level.SEVERE, name + " SQL exception on close", ex);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
player.sendMessage(Colors.Blue + "Player " + name + " within " + size + " blocks of you: ");
|
|
||||||
if (types.size() == 0)
|
|
||||||
{
|
|
||||||
player.sendMessage(Colors.Blue + "No results found.");
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
player.sendMessage(Colors.Gold + String.format("%-6s %-6s %s", "Creat", "Destr", "Block"));
|
|
||||||
for (String t: types)
|
|
||||||
{
|
|
||||||
Integer c = created.get(t);
|
|
||||||
Integer d = destroyed.get(t);
|
|
||||||
if (c == null)
|
|
||||||
c = 0;
|
|
||||||
if (d == null)
|
|
||||||
d = 0;
|
|
||||||
player.sendMessage(Colors.Gold + String.format("%-6d %-6d %s", c, d, t));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private class PlayerWorldStats implements Runnable
|
|
||||||
{
|
|
||||||
private Player player;
|
|
||||||
PlayerWorldStats(Player player)
|
|
||||||
{
|
|
||||||
this.player = player;
|
|
||||||
}
|
|
||||||
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>();
|
|
||||||
|
|
||||||
Connection conn = null;
|
|
||||||
PreparedStatement ps = null;
|
|
||||||
ResultSet rs = null;
|
|
||||||
|
|
||||||
try {
|
|
||||||
conn = getConnection();
|
|
||||||
conn.setAutoCommit(false);
|
|
||||||
ps = conn.prepareStatement("SELECT player, count(player) as num from blocks where type > 0 group by player order by count(player) desc limit 5", Statement.RETURN_GENERATED_KEYS);
|
|
||||||
rs = ps.executeQuery();
|
|
||||||
while (rs.next())
|
|
||||||
{
|
|
||||||
players.add(rs.getString("player"));
|
|
||||||
created.put(rs.getString("player"), rs.getInt("num"));
|
|
||||||
}
|
|
||||||
rs.close();
|
|
||||||
ps.close();
|
|
||||||
|
|
||||||
ps = conn.prepareStatement("SELECT player, count(player) as num from blocks where replaced > 0 group by player order by count(player) desc limit 5", Statement.RETURN_GENERATED_KEYS);
|
|
||||||
rs = ps.executeQuery();
|
|
||||||
while (rs.next())
|
|
||||||
{
|
|
||||||
players.add(rs.getString("player"));
|
|
||||||
destroyed.put(rs.getString("player"), rs.getInt("num"));
|
|
||||||
}
|
|
||||||
|
|
||||||
} catch (SQLException ex) {
|
|
||||||
log.log(Level.SEVERE, name + " SQL exception", ex);
|
|
||||||
} finally {
|
|
||||||
try {
|
|
||||||
if (rs != null)
|
|
||||||
rs.close();
|
|
||||||
if (ps != null)
|
|
||||||
ps.close();
|
|
||||||
conn.close();
|
|
||||||
} catch (SQLException ex) {
|
|
||||||
log.log(Level.SEVERE, name + " SQL exception on close", ex);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
player.sendMessage(Colors.Blue + "Within entire world:");
|
|
||||||
if (players.size() == 0)
|
|
||||||
{
|
|
||||||
player.sendMessage(Colors.Blue + "No results found.");
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
player.sendMessage(Colors.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(Colors.Gold + String.format("%-6d %-6d %s", c, d, p));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private void queueBlock(Player player, Block before, Block after)
|
private void queueBlock(Player player, Block before, Block after)
|
||||||
{
|
{
|
||||||
Block b = null;
|
Block b = null;
|
||||||
@@ -419,29 +181,52 @@ public class LogBlock extends Plugin
|
|||||||
if (!player.canUseCommand(split[0]))
|
if (!player.canUseCommand(split[0]))
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
if (split[0].equalsIgnoreCase("/lb")) {
|
if (split[0].equalsIgnoreCase("/lb"))
|
||||||
|
{
|
||||||
|
Connection conn;
|
||||||
|
try {
|
||||||
|
conn = getConnection();
|
||||||
|
} catch (SQLException ex) {
|
||||||
|
log.log(Level.SEVERE, name + " SQL exception", ex);
|
||||||
|
player.sendMessage(Colors.Rose + "Error, check server logs.");
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
if (split.length == 1) {
|
if (split.length == 1) {
|
||||||
AreaStats th = new AreaStats(player, defaultDist);
|
AreaStats th = new AreaStats(conn, player, defaultDist);
|
||||||
new Thread(th).start();
|
new Thread(th).start();
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (split.length == 2) {
|
if (split.length == 2) {
|
||||||
if (split[1].equalsIgnoreCase("world")) {
|
if (split[1].equalsIgnoreCase("world")) {
|
||||||
PlayerWorldStats th = new PlayerWorldStats(player);
|
PlayerWorldStats th = new PlayerWorldStats(conn, player);
|
||||||
new Thread(th).start();
|
new Thread(th).start();
|
||||||
} else
|
return true;
|
||||||
|
}
|
||||||
player.sendMessage(Colors.Rose + "Incorrect usage.");
|
player.sendMessage(Colors.Rose + "Incorrect usage.");
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (split[1].equalsIgnoreCase("player")) {
|
if (split[1].equalsIgnoreCase("player")) {
|
||||||
PlayerAreaStats th = new PlayerAreaStats(player, split[2], defaultDist);
|
PlayerAreaStats th = new PlayerAreaStats(conn, player, split[2], defaultDist);
|
||||||
new Thread(th).start();
|
new Thread(th).start();
|
||||||
|
return true;
|
||||||
}
|
}
|
||||||
else if (split[1].equalsIgnoreCase("area")) {
|
|
||||||
AreaStats th = new AreaStats(player, Integer.parseInt(split[2]));
|
if (split[1].equalsIgnoreCase("area")) {
|
||||||
|
AreaStats th = new AreaStats(conn, player, Integer.parseInt(split[2]));
|
||||||
new Thread(th).start();
|
new Thread(th).start();
|
||||||
|
return true;
|
||||||
}
|
}
|
||||||
else
|
|
||||||
|
if (split[1].equalsIgnoreCase("block")) {
|
||||||
|
int type = etc.getDataSource().getItem(split[2]);
|
||||||
|
AreaBlockSearch th = new AreaBlockSearch(conn, player, type, defaultDist);
|
||||||
|
new Thread(th).start();
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
player.sendMessage(Colors.Rose + "Incorrect usage.");
|
player.sendMessage(Colors.Rose + "Incorrect usage.");
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
@@ -451,7 +236,10 @@ public class LogBlock extends Plugin
|
|||||||
public void onBlockRightClicked(Player player, Block blockClicked, Item item)
|
public void onBlockRightClicked(Player player, Block blockClicked, Item item)
|
||||||
{
|
{
|
||||||
if (item.getItemId() == toolID && player.canUseCommand("/blockhistory"))
|
if (item.getItemId() == toolID && player.canUseCommand("/blockhistory"))
|
||||||
|
{
|
||||||
showBlockHistory(player, blockClicked);
|
showBlockHistory(player, blockClicked);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
lastface = blockClicked.getFace(blockClicked.getFaceClicked());
|
lastface = blockClicked.getFace(blockClicked.getFaceClicked());
|
||||||
// if (debug)
|
// if (debug)
|
||||||
@@ -460,6 +248,14 @@ public class LogBlock extends Plugin
|
|||||||
|
|
||||||
public boolean onBlockPlace(Player player, Block blockPlaced, Block blockClicked, Item itemInHand)
|
public boolean onBlockPlace(Player player, Block blockPlaced, Block blockClicked, Item itemInHand)
|
||||||
{
|
{
|
||||||
|
if (itemInHand.getItemId() == toolblockID && player.canUseCommand("/blockhistory"))
|
||||||
|
{
|
||||||
|
showBlockHistory(player, blockPlaced);
|
||||||
|
if (toolblockRemove)
|
||||||
|
return true;
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
// if (debug)
|
// if (debug)
|
||||||
// lblog.info("onBlockPlace: placed " + blockPlaced.getType() + " clicked " + blockClicked.getType() + " item " + itemInHand.getItemId());
|
// lblog.info("onBlockPlace: placed " + blockPlaced.getType() + " clicked " + blockClicked.getType() + " item " + itemInHand.getItemId());
|
||||||
|
|
||||||
@@ -528,7 +324,9 @@ public class LogBlock extends Plugin
|
|||||||
log.log(Level.SEVERE, name + " SQL exception", ex);
|
log.log(Level.SEVERE, name + " SQL exception", ex);
|
||||||
} finally {
|
} finally {
|
||||||
try {
|
try {
|
||||||
|
if (ps != null)
|
||||||
ps.close();
|
ps.close();
|
||||||
|
if (conn != null)
|
||||||
conn.close();
|
conn.close();
|
||||||
} catch (SQLException ex) {
|
} catch (SQLException ex) {
|
||||||
log.log(Level.SEVERE, name + " SQL exception on close", ex);
|
log.log(Level.SEVERE, name + " SQL exception on close", ex);
|
||||||
|
95
PlayerAreaStats.java
Executable file
95
PlayerAreaStats.java
Executable file
@@ -0,0 +1,95 @@
|
|||||||
|
import java.util.HashSet;
|
||||||
|
import java.util.HashMap;
|
||||||
|
|
||||||
|
import java.util.logging.*;
|
||||||
|
import java.sql.*;
|
||||||
|
|
||||||
|
public class PlayerAreaStats implements Runnable
|
||||||
|
{
|
||||||
|
static final Logger log = Logger.getLogger("Minecraft");
|
||||||
|
private Player player;
|
||||||
|
private String name;
|
||||||
|
private int size;
|
||||||
|
private Connection conn = null;
|
||||||
|
|
||||||
|
PlayerAreaStats(Connection conn, Player player, String name, int size)
|
||||||
|
{
|
||||||
|
this.player = player;
|
||||||
|
this.name = name;
|
||||||
|
this.size = size;
|
||||||
|
this.conn = conn;
|
||||||
|
}
|
||||||
|
public void run()
|
||||||
|
{
|
||||||
|
HashSet<String> types = new HashSet<String>();
|
||||||
|
HashMap<String, Integer> created = new HashMap<String, Integer>();
|
||||||
|
HashMap<String, Integer> destroyed = new HashMap<String, Integer>();
|
||||||
|
|
||||||
|
PreparedStatement ps = null;
|
||||||
|
ResultSet rs = null;
|
||||||
|
|
||||||
|
try {
|
||||||
|
conn.setAutoCommit(false);
|
||||||
|
ps = conn.prepareStatement("SELECT type, count(type) as num from blocks where type > 0 and player = ? and y > 0 and x > ? and x < ? and z > ? and z < ? group by type order by count(replaced) desc limit 10", Statement.RETURN_GENERATED_KEYS);
|
||||||
|
ps.setString(1, name);
|
||||||
|
ps.setInt(2, (int)player.getX()-size);
|
||||||
|
ps.setInt(3, (int)player.getX()+size);
|
||||||
|
ps.setInt(4, (int)player.getZ()-size);
|
||||||
|
ps.setInt(5, (int)player.getZ()+size);
|
||||||
|
rs = ps.executeQuery();
|
||||||
|
while (rs.next())
|
||||||
|
{
|
||||||
|
types.add(etc.getDataSource().getItem(rs.getInt("type")));
|
||||||
|
created.put(etc.getDataSource().getItem(rs.getInt("type")), rs.getInt("num"));
|
||||||
|
}
|
||||||
|
rs.close();
|
||||||
|
ps.close();
|
||||||
|
|
||||||
|
ps = conn.prepareStatement("SELECT replaced, count(replaced) as num from blocks where replaced > 0 and player = ? and y > 0 and x > ? and x < ? and z > ? and z < ? group by replaced order by count(replaced) desc limit 10", Statement.RETURN_GENERATED_KEYS);
|
||||||
|
ps.setString(1, name);
|
||||||
|
ps.setInt(2, (int)player.getX()-size);
|
||||||
|
ps.setInt(3, (int)player.getX()+size);
|
||||||
|
ps.setInt(4, (int)player.getZ()-size);
|
||||||
|
ps.setInt(5, (int)player.getZ()+size);
|
||||||
|
rs = ps.executeQuery();
|
||||||
|
while (rs.next())
|
||||||
|
{
|
||||||
|
types.add(etc.getDataSource().getItem(rs.getInt("replaced")));
|
||||||
|
destroyed.put(etc.getDataSource().getItem(rs.getInt("replaced")), rs.getInt("num"));
|
||||||
|
}
|
||||||
|
|
||||||
|
} catch (SQLException ex) {
|
||||||
|
log.log(Level.SEVERE, this.getClass().getName() + " SQL exception", ex);
|
||||||
|
} finally {
|
||||||
|
try {
|
||||||
|
if (rs != null)
|
||||||
|
rs.close();
|
||||||
|
if (ps != null)
|
||||||
|
ps.close();
|
||||||
|
if (conn != null)
|
||||||
|
conn.close();
|
||||||
|
} catch (SQLException ex) {
|
||||||
|
log.log(Level.SEVERE, this.getClass().getName() + " SQL exception on close", ex);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
player.sendMessage(Colors.Blue + "Player " + name + " within " + size + " blocks of you: ");
|
||||||
|
if (types.size() == 0)
|
||||||
|
{
|
||||||
|
player.sendMessage(Colors.Blue + "No results found.");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
player.sendMessage(Colors.Gold + String.format("%-6s %-6s %s", "Creat", "Destr", "Block"));
|
||||||
|
for (String t: types)
|
||||||
|
{
|
||||||
|
Integer c = created.get(t);
|
||||||
|
Integer d = destroyed.get(t);
|
||||||
|
if (c == null)
|
||||||
|
c = 0;
|
||||||
|
if (d == null)
|
||||||
|
d = 0;
|
||||||
|
player.sendMessage(Colors.Gold + String.format("%-6d %-6d %s", c, d, t));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
82
PlayerWorldStats.java
Executable file
82
PlayerWorldStats.java
Executable file
@@ -0,0 +1,82 @@
|
|||||||
|
import java.util.HashSet;
|
||||||
|
import java.util.HashMap;
|
||||||
|
|
||||||
|
import java.util.logging.*;
|
||||||
|
import java.sql.*;
|
||||||
|
|
||||||
|
public class PlayerWorldStats implements Runnable
|
||||||
|
{
|
||||||
|
static final Logger log = Logger.getLogger("Minecraft");
|
||||||
|
private Player player;
|
||||||
|
private Connection conn = null;
|
||||||
|
|
||||||
|
PlayerWorldStats(Connection conn, Player player)
|
||||||
|
{
|
||||||
|
this.player = player;
|
||||||
|
this.conn = conn;
|
||||||
|
}
|
||||||
|
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;
|
||||||
|
ResultSet rs = null;
|
||||||
|
|
||||||
|
try {
|
||||||
|
conn.setAutoCommit(false);
|
||||||
|
ps = conn.prepareStatement("SELECT player, count(player) as num from blocks where type > 0 group by player order by count(player) desc limit 5", Statement.RETURN_GENERATED_KEYS);
|
||||||
|
rs = ps.executeQuery();
|
||||||
|
while (rs.next())
|
||||||
|
{
|
||||||
|
players.add(rs.getString("player"));
|
||||||
|
created.put(rs.getString("player"), rs.getInt("num"));
|
||||||
|
}
|
||||||
|
rs.close();
|
||||||
|
ps.close();
|
||||||
|
|
||||||
|
ps = conn.prepareStatement("SELECT player, count(player) as num from blocks where replaced > 0 group by player order by count(player) desc limit 5", Statement.RETURN_GENERATED_KEYS);
|
||||||
|
rs = ps.executeQuery();
|
||||||
|
while (rs.next())
|
||||||
|
{
|
||||||
|
players.add(rs.getString("player"));
|
||||||
|
destroyed.put(rs.getString("player"), rs.getInt("num"));
|
||||||
|
}
|
||||||
|
|
||||||
|
} catch (SQLException ex) {
|
||||||
|
log.log(Level.SEVERE, this.getClass().getName() + " SQL exception", ex);
|
||||||
|
} finally {
|
||||||
|
try {
|
||||||
|
if (rs != null)
|
||||||
|
rs.close();
|
||||||
|
if (ps != null)
|
||||||
|
ps.close();
|
||||||
|
if (conn != null)
|
||||||
|
conn.close();
|
||||||
|
} catch (SQLException ex) {
|
||||||
|
log.log(Level.SEVERE, this.getClass().getName() + " SQL exception on close", ex);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
player.sendMessage(Colors.Blue + "Within entire world:");
|
||||||
|
if (players.size() == 0)
|
||||||
|
{
|
||||||
|
player.sendMessage(Colors.Blue + "No results found.");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
player.sendMessage(Colors.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(Colors.Gold + String.format("%-6d %-6d %s", c, d, p));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
// END threaded commands
|
Reference in New Issue
Block a user