forked from LogBlock/LogBlock
Removed static and public fields.
This commit is contained in:
@@ -6,6 +6,7 @@ import java.sql.ResultSet;
|
||||
import java.sql.SQLException;
|
||||
import java.text.SimpleDateFormat;
|
||||
import java.util.logging.Level;
|
||||
import java.util.logging.Logger;
|
||||
|
||||
import org.bukkit.ChatColor;
|
||||
import org.bukkit.Location;
|
||||
@@ -14,20 +15,22 @@ import org.bukkit.entity.Player;
|
||||
|
||||
public class AreaBlockSearch implements Runnable
|
||||
{
|
||||
private Player player;
|
||||
private Location location;
|
||||
private int type;
|
||||
private int size;
|
||||
private Connection conn = null;
|
||||
private String table;
|
||||
private final Logger log;
|
||||
private final Player player;
|
||||
private final Location location;
|
||||
private final int type;
|
||||
private final int size;
|
||||
private final Connection conn;
|
||||
private final String table;
|
||||
|
||||
AreaBlockSearch(Connection conn, Player player, int type, int size, String table) {
|
||||
AreaBlockSearch(LogBlock logblock, Player player, int type, int size) {
|
||||
this.player = player;
|
||||
this.location = player.getLocation();
|
||||
this.type = type;
|
||||
this.size = size;
|
||||
this.conn = conn;
|
||||
this.table = table;
|
||||
log = logblock.getServer().getLogger();
|
||||
conn = logblock.getConnection();
|
||||
table = logblock.getConfig().tables.get(player.getWorld().getName().hashCode());
|
||||
}
|
||||
|
||||
public void run() {
|
||||
@@ -36,8 +39,16 @@ public class AreaBlockSearch implements Runnable
|
||||
ResultSet rs = null;
|
||||
SimpleDateFormat formatter = new SimpleDateFormat("MM-dd HH:mm:ss");
|
||||
try {
|
||||
if (conn == null) {
|
||||
player.sendMessage(ChatColor.RED + "Failed to create database connection");
|
||||
return;
|
||||
}
|
||||
if (table == null) {
|
||||
player.sendMessage(ChatColor.RED + "This world isn't logged");
|
||||
return;
|
||||
}
|
||||
conn.setAutoCommit(false);
|
||||
ps = conn.prepareStatement("SELECT * FROM `" + table + "` INNER JOIN `lb-players` USING (`playerid`) WHERE (type = ? or replaced = ?) and y > ? and y < ? and x > ? and x < ? and z > ? and z < ? order by date desc limit 10");
|
||||
ps = conn.prepareStatement("SELECT * FROM `" + table + "` INNER JOIN `lb-players` USING (playerid) WHERE (type = ? or replaced = ?) and y > ? and y < ? and x > ? and x < ? and z > ? and z < ? order by date desc limit 10");
|
||||
ps.setInt(1, type);
|
||||
ps.setInt(2, type);
|
||||
ps.setInt(3, location.getBlockY() - size);
|
||||
@@ -62,7 +73,7 @@ public class AreaBlockSearch implements Runnable
|
||||
if (!hist)
|
||||
player.sendMessage(ChatColor.DARK_AQUA + "None.");
|
||||
} catch (SQLException ex) {
|
||||
LogBlock.log.log(Level.SEVERE, "[LogBlock AreaBlockSearch] SQL exception", ex);
|
||||
log.log(Level.SEVERE, "[LogBlock AreaBlockSearch] SQL exception", ex);
|
||||
} finally {
|
||||
try {
|
||||
if (rs != null)
|
||||
@@ -72,7 +83,7 @@ public class AreaBlockSearch implements Runnable
|
||||
if (conn != null)
|
||||
conn.close();
|
||||
} catch (SQLException ex) {
|
||||
LogBlock.log.log(Level.SEVERE, "[LogBlock AreaBlockSearch] SQL exception on close", ex);
|
||||
log.log(Level.SEVERE, "[LogBlock AreaBlockSearch] SQL exception on close", ex);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@@ -5,28 +5,39 @@ import java.sql.PreparedStatement;
|
||||
import java.sql.ResultSet;
|
||||
import java.sql.SQLException;
|
||||
import java.util.logging.Level;
|
||||
import java.util.logging.Logger;
|
||||
|
||||
import org.bukkit.ChatColor;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
public class AreaStats implements Runnable
|
||||
{
|
||||
private Player player;
|
||||
private int size;
|
||||
private Connection conn = null;
|
||||
private String table;
|
||||
private final Logger log;
|
||||
private final Player player;
|
||||
private final int size;
|
||||
private final Connection conn;
|
||||
private final String table;
|
||||
|
||||
AreaStats(Connection conn, Player player, int size, String table) {
|
||||
AreaStats(LogBlock logblock, Player player, int size) {
|
||||
this.player = player;
|
||||
this.size = size;
|
||||
this.conn = conn;
|
||||
this.table = table;
|
||||
log = logblock.getServer().getLogger();
|
||||
conn = logblock.getConnection();
|
||||
table = logblock.getConfig().tables.get(player.getWorld().getName().hashCode());
|
||||
}
|
||||
|
||||
public void run() {
|
||||
PreparedStatement ps = null;
|
||||
ResultSet rs = null;
|
||||
try {
|
||||
if (conn == null) {
|
||||
player.sendMessage(ChatColor.RED + "Failed to create database connection");
|
||||
return;
|
||||
}
|
||||
if (table == null) {
|
||||
player.sendMessage(ChatColor.RED + "This world isn't logged");
|
||||
return;
|
||||
}
|
||||
conn.setAutoCommit(false);
|
||||
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 + "` 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");
|
||||
ps.setInt(1, player.getLocation().getBlockX()-size);
|
||||
@@ -49,7 +60,7 @@ public class AreaStats implements Runnable
|
||||
}
|
||||
}
|
||||
} catch (SQLException ex) {
|
||||
LogBlock.log.log(Level.SEVERE, "[LogBlock AreaStats] SQL exception", ex);
|
||||
log.log(Level.SEVERE, "[LogBlock AreaStats] SQL exception", ex);
|
||||
} finally {
|
||||
try {
|
||||
if (rs != null)
|
||||
@@ -59,7 +70,7 @@ public class AreaStats implements Runnable
|
||||
if (conn != null)
|
||||
conn.close();
|
||||
} catch (SQLException ex) {
|
||||
LogBlock.log.log(Level.SEVERE, "[LogBlock AreaStats] SQL exception on close", ex);
|
||||
log.log(Level.SEVERE, "[LogBlock AreaStats] SQL exception on close", ex);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@@ -6,6 +6,7 @@ import java.sql.ResultSet;
|
||||
import java.sql.SQLException;
|
||||
import java.text.SimpleDateFormat;
|
||||
import java.util.logging.Level;
|
||||
import java.util.logging.Logger;
|
||||
|
||||
import org.bukkit.ChatColor;
|
||||
import org.bukkit.Material;
|
||||
@@ -14,33 +15,35 @@ import org.bukkit.entity.Player;
|
||||
|
||||
public class BlockStats implements Runnable
|
||||
{
|
||||
private final LogBlock logblock;
|
||||
private Player player;
|
||||
private Block block;
|
||||
private final Logger log;
|
||||
private final Connection conn;
|
||||
private final String table;
|
||||
private final Player player;
|
||||
private final Block block;
|
||||
|
||||
BlockStats(LogBlock logblock, Player player, Block block) {
|
||||
this.logblock = logblock;
|
||||
log = logblock.getServer().getLogger();
|
||||
conn = logblock.getConnection();
|
||||
table = logblock.getConfig().tables.get(player.getWorld().getName().hashCode());
|
||||
this.player = player;
|
||||
this.block = block;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void run() {
|
||||
Connection conn = logblock.pool.getConnection();
|
||||
if (conn == null) {
|
||||
player.sendMessage(ChatColor.RED + "Failed to create database connection");
|
||||
return;
|
||||
}
|
||||
String table = logblock.config.tables.get(block.getWorld().getName().hashCode());
|
||||
if (table == null) {
|
||||
player.sendMessage(ChatColor.RED + "This world isn't logged");
|
||||
return;
|
||||
}
|
||||
boolean hist = false;
|
||||
PreparedStatement ps = null;
|
||||
ResultSet rs = null;
|
||||
SimpleDateFormat formatter = new SimpleDateFormat("MM-dd HH:mm:ss");
|
||||
try {
|
||||
if (conn == null) {
|
||||
player.sendMessage(ChatColor.RED + "Failed to create database connection");
|
||||
return;
|
||||
}
|
||||
if (table == null) {
|
||||
player.sendMessage(ChatColor.RED + "This world isn't logged");
|
||||
return;
|
||||
}
|
||||
conn.setAutoCommit(false);
|
||||
ps = conn.prepareStatement("SELECT date, replaced, type, signtext, playername FROM `" + table + "` LEFT JOIN `" + table + "-sign` USING (id) INNER JOIN `lb-players` USING (playerid) WHERE x = ? AND y = ? AND z = ? ORDER BY date DESC LIMIT 15");
|
||||
ps.setInt(1, block.getX());
|
||||
@@ -69,7 +72,7 @@ public class BlockStats implements Runnable
|
||||
if (!hist)
|
||||
player.sendMessage(ChatColor.DARK_AQUA + "None.");
|
||||
} catch (SQLException ex) {
|
||||
LogBlock.log.log(Level.SEVERE, "[LogBlock BlockStats] SQL exception", ex);
|
||||
log.log(Level.SEVERE, "[LogBlock BlockStats] SQL exception", ex);
|
||||
} finally {
|
||||
try {
|
||||
if (rs != null)
|
||||
@@ -79,7 +82,7 @@ public class BlockStats implements Runnable
|
||||
if (conn != null)
|
||||
conn.close();
|
||||
} catch (SQLException ex) {
|
||||
LogBlock.log.log(Level.SEVERE, "[LogBlock BlockStats] SQL exception on close", ex);
|
||||
log.log(Level.SEVERE, "[LogBlock BlockStats] SQL exception on close", ex);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@@ -7,58 +7,63 @@ import java.sql.SQLException;
|
||||
import java.sql.Statement;
|
||||
import java.text.SimpleDateFormat;
|
||||
import java.util.logging.Level;
|
||||
import java.util.logging.Logger;
|
||||
|
||||
public class ClearLog implements Runnable
|
||||
{
|
||||
private final LogBlock logblock;
|
||||
private final Logger log;
|
||||
private final Config config;
|
||||
private final Connection conn;
|
||||
private final File dumpFolder;
|
||||
|
||||
public ClearLog(LogBlock logblock) {
|
||||
this.logblock = logblock;
|
||||
log = logblock.getServer().getLogger();
|
||||
config = logblock.getConfig();
|
||||
conn = logblock.getConnection();
|
||||
dumpFolder = new File(logblock.getDataFolder(), "dumb");
|
||||
}
|
||||
|
||||
@Override
|
||||
public void run() {
|
||||
File dumpFolder = new File(logblock.getDataFolder(), "dumb");
|
||||
dumpFolder.mkdirs();
|
||||
Connection conn = logblock.pool.getConnection();
|
||||
if (conn == null)
|
||||
return;
|
||||
Statement state = null;
|
||||
try {
|
||||
if (conn == null)
|
||||
return;
|
||||
dumpFolder.mkdirs();
|
||||
state = conn.createStatement();
|
||||
String time = new SimpleDateFormat("yy-MM-dd-HH-mm-ss").format(System.currentTimeMillis() - logblock.config.keepLogDays*86400000L);
|
||||
String time = new SimpleDateFormat("yy-MM-dd-HH-mm-ss").format(System.currentTimeMillis() - config.keepLogDays*86400000L);
|
||||
ResultSet rs;
|
||||
for (String table : logblock.config.tables.values()) {
|
||||
for (String table : config.tables.values()) {
|
||||
rs = state.executeQuery("SELECT count(*) FROM `" + table + "` WHERE date < '" + time + "'");
|
||||
rs.next();
|
||||
int deleted = rs.getInt(1);
|
||||
if (deleted > 0) {
|
||||
if (logblock.config.dumpDeletedLog)
|
||||
if (config.dumpDeletedLog)
|
||||
state.execute("SELECT * FROM `" + table + "` WHERE date < '" + time + "' INTO OUTFILE '" + new File(dumpFolder, table + "-" + time + ".csv").getAbsolutePath().replace("\\", "\\\\") + "' FIELDS TERMINATED BY ',' OPTIONALLY ENCLOSED BY '\"' LINES TERMINATED BY '\n'");
|
||||
state.execute("DELETE FROM `" + table + "` WHERE date < '" + time + "'");
|
||||
LogBlock.log.info("[LogBlock] Cleared out table " + table + ". Deleted " + deleted + " entries.");
|
||||
log.info("[LogBlock] Cleared out table " + table + ". Deleted " + deleted + " entries.");
|
||||
}
|
||||
rs = state.executeQuery("SELECT COUNT(*) FROM `" + table + "-sign` LEFT JOIN `" + table + "` USING (id) WHERE `" + table + "`.id IS NULL");
|
||||
rs.next();
|
||||
deleted = rs.getInt(1);
|
||||
if (deleted > 0) {
|
||||
if (logblock.config.dumpDeletedLog)
|
||||
if (config.dumpDeletedLog)
|
||||
state.execute("SELECT id, signtext FROM `" + table + "-sign` LEFT JOIN `" + table + "` USING (id) WHERE `" + table + "`.id IS NULL INTO OUTFILE '" + new File(dumpFolder, table + "-sign-" + time + ".csv").getAbsolutePath().replace("\\", "\\\\") + "' FIELDS TERMINATED BY ',' OPTIONALLY ENCLOSED BY '\"' LINES TERMINATED BY '\n'");
|
||||
state.execute("DELETE `" + table + "-sign` FROM `" + table + "-sign` LEFT JOIN `" + table + "` USING (id) WHERE `" + table + "`.id IS NULL;");
|
||||
LogBlock.log.info("[LogBlock] Cleared out table " + table + "-sign. Deleted " + deleted + " entries.");
|
||||
log.info("[LogBlock] Cleared out table " + table + "-sign. Deleted " + deleted + " entries.");
|
||||
}
|
||||
rs = state.executeQuery("SELECT COUNT(*) FROM `" + table + "-chest` LEFT JOIN `" + table + "` USING (id) WHERE `" + table + "`.id IS NULL");
|
||||
rs.next();
|
||||
deleted = rs.getInt(1);
|
||||
if (deleted > 0) {
|
||||
if (logblock.config.dumpDeletedLog)
|
||||
if (config.dumpDeletedLog)
|
||||
state.execute("SELECT id, intype, inamount, outtype, outamount FROM `" + table + "-chest` LEFT JOIN `" + table + "` USING (id) WHERE `" + table + "`.id IS NULL INTO OUTFILE '" + new File(dumpFolder, table + "-chest-" + time + ".csv").getAbsolutePath().replace("\\", "\\\\") + "' FIELDS TERMINATED BY ',' OPTIONALLY ENCLOSED BY '\"' LINES TERMINATED BY '\n'");
|
||||
state.execute("DELETE `" + table + "-chest` FROM `" + table + "-chest` LEFT JOIN `" + table + "` USING (id) WHERE `" + table + "`.id IS NULL;");
|
||||
LogBlock.log.info("[LogBlock] Cleared out table " + table + "-chest. Deleted " + deleted + " entries.");
|
||||
log.info("[LogBlock] Cleared out table " + table + "-chest. Deleted " + deleted + " entries.");
|
||||
}
|
||||
}
|
||||
} catch (SQLException ex) {
|
||||
LogBlock.log.log(Level.SEVERE, "[LogBlock] SQL exception", ex);
|
||||
log.log(Level.SEVERE, "[LogBlock] SQL exception", ex);
|
||||
} finally {
|
||||
try {
|
||||
if (state != null)
|
||||
@@ -66,7 +71,7 @@ public class ClearLog implements Runnable
|
||||
if (conn != null)
|
||||
conn.close();
|
||||
} catch (SQLException ex) {
|
||||
LogBlock.log.log(Level.SEVERE, "[LogBlock] SQL exception on close", ex);
|
||||
log.log(Level.SEVERE, "[LogBlock] SQL exception on close", ex);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@@ -9,29 +9,29 @@ import org.bukkit.Material;
|
||||
import org.bukkit.util.config.Configuration;
|
||||
|
||||
public class Config {
|
||||
final HashMap<Integer, String> tables;
|
||||
final String url;
|
||||
final String user;
|
||||
final String password;
|
||||
final int delay;
|
||||
final boolean useBukkitScheduler;
|
||||
final int keepLogDays;
|
||||
final boolean dumpDeletedLog;
|
||||
final boolean logBlockCreations;
|
||||
final boolean logBlockDestroyings;
|
||||
final boolean logSignTexts;
|
||||
final boolean logExplosions;
|
||||
final boolean logFire;
|
||||
final boolean logLeavesDecay;
|
||||
final boolean logChestAccess;
|
||||
final boolean logKills;
|
||||
final LogKillsLevel logKillsLevel;
|
||||
final List<Integer> dontRollback;
|
||||
final List<Integer> replaceAnyway;
|
||||
final int defaultDist;
|
||||
final int defaultTime;
|
||||
final int toolID;
|
||||
final int toolblockID;
|
||||
public final HashMap<Integer, String> tables;
|
||||
public final String url;
|
||||
public final String user;
|
||||
public final String password;
|
||||
public final int delay;
|
||||
public final boolean useBukkitScheduler;
|
||||
public final int keepLogDays;
|
||||
public final boolean dumpDeletedLog;
|
||||
public final boolean logBlockCreations;
|
||||
public final boolean logBlockDestroyings;
|
||||
public final boolean logSignTexts;
|
||||
public final boolean logExplosions;
|
||||
public final boolean logFire;
|
||||
public final boolean logLeavesDecay;
|
||||
public final boolean logChestAccess;
|
||||
public final boolean logKills;
|
||||
public final LogKillsLevel logKillsLevel;
|
||||
public final List<Integer> dontRollback;
|
||||
public final List<Integer> replaceAnyway;
|
||||
public final int defaultDist;
|
||||
public final int defaultTime;
|
||||
public final int toolID;
|
||||
public final int toolblockID;
|
||||
|
||||
enum LogKillsLevel {
|
||||
PLAYERS, MONSTERS, ANIMALS
|
||||
|
@@ -9,6 +9,7 @@ import java.util.HashSet;
|
||||
import java.util.TimerTask;
|
||||
import java.util.concurrent.LinkedBlockingQueue;
|
||||
import java.util.logging.Level;
|
||||
import java.util.logging.Logger;
|
||||
|
||||
import org.bukkit.block.Block;
|
||||
import org.bukkit.entity.Entity;
|
||||
@@ -17,15 +18,20 @@ import org.bukkit.entity.TNTPrimed;
|
||||
|
||||
public class Consumer extends TimerTask implements Runnable
|
||||
{
|
||||
private final LogBlock logblock;
|
||||
private final Logger log;
|
||||
private final Config config;
|
||||
private LinkedBlockingQueue<BlockRow> bqueue = new LinkedBlockingQueue<BlockRow>();
|
||||
private LinkedBlockingQueue<KillRow> kqueue = new LinkedBlockingQueue<KillRow>();
|
||||
private HashSet<Integer> hiddenplayers = new HashSet<Integer>();
|
||||
private HashMap<Integer, Integer> lastAttackedEntity = new HashMap<Integer, Integer>();
|
||||
private HashMap<Integer, Long> lastAttackTime = new HashMap<Integer, Long>();
|
||||
private LogBlock logblock;
|
||||
|
||||
|
||||
Consumer (LogBlock logblock) {
|
||||
this.logblock = logblock;
|
||||
log = logblock.getServer().getLogger();
|
||||
config = logblock.getConfig();
|
||||
}
|
||||
|
||||
public void queueBlock(Player player, Block block, int typeAfter) {
|
||||
@@ -45,7 +51,7 @@ public class Consumer extends TimerTask implements Runnable
|
||||
return;
|
||||
if (hiddenplayers.contains(playerName.hashCode()))
|
||||
return;
|
||||
String table = logblock.config.tables.get(block.getWorld().getName().hashCode());
|
||||
String table = config.tables.get(block.getWorld().getName().hashCode());
|
||||
if (table == null)
|
||||
return;
|
||||
if (playerName.length() > 32)
|
||||
@@ -56,13 +62,13 @@ public class Consumer extends TimerTask implements Runnable
|
||||
if (ca != null)
|
||||
row.ca = ca;
|
||||
if (!bqueue.offer(row))
|
||||
LogBlock.log.info("[LogBlock] Failed to queue block for " + playerName);
|
||||
log.info("[LogBlock] Failed to queue block for " + playerName);
|
||||
}
|
||||
|
||||
public void queueKill(Entity attacker, Entity defender) {
|
||||
if (lastAttackedEntity.containsKey(attacker.getEntityId()) && lastAttackedEntity.get(attacker.getEntityId()) == defender.getEntityId() && System.currentTimeMillis() - lastAttackTime.get(attacker.getEntityId()) < 3000)
|
||||
return;
|
||||
String table = logblock.config.tables.get(defender.getWorld().getName().hashCode());
|
||||
String table = config.tables.get(defender.getWorld().getName().hashCode());
|
||||
if (table == null)
|
||||
return;
|
||||
int weapon = 0;
|
||||
@@ -93,14 +99,14 @@ public class Consumer extends TimerTask implements Runnable
|
||||
}
|
||||
|
||||
public synchronized void run() {
|
||||
Connection conn = logblock.pool.getConnection();
|
||||
Connection conn = logblock.getConnection();
|
||||
if (conn == null)
|
||||
return;
|
||||
Statement state = null;
|
||||
BlockRow b; KillRow k;
|
||||
int count = 0;
|
||||
if (bqueue.size() > 100)
|
||||
LogBlock.log.info("[LogBlock Consumer] Queue overloaded. Size: " + bqueue.size());
|
||||
log.info("[LogBlock Consumer] Queue overloaded. Size: " + bqueue.size());
|
||||
try {
|
||||
conn.setAutoCommit(false);
|
||||
state = conn.createStatement();
|
||||
@@ -115,13 +121,13 @@ public class Consumer extends TimerTask implements Runnable
|
||||
if (keys.next())
|
||||
state.execute("INSERT INTO `" + b.table + "-sign` (id, signtext) values (" + keys.getInt(1) + ", '" + b.signtext + "')");
|
||||
else
|
||||
LogBlock.log.severe("[LogBlock Consumer] Failed to get generated keys");
|
||||
log.severe("[LogBlock Consumer] Failed to get generated keys");
|
||||
} else if (b.ca != null) {
|
||||
ResultSet keys = state.getGeneratedKeys();
|
||||
if (keys.next())
|
||||
state.execute("INSERT INTO `" + b.table + "-chest` (id, intype, inamount, outtype, outamount) values (" + keys.getInt(1) + ", " + b.ca.inType + ", " + b.ca.inAmount + ", " + b.ca.outType + ", " + b.ca.outAmount + ")");
|
||||
else
|
||||
LogBlock.log.severe("[LogBlock Consumer] Failed to get generated keys");
|
||||
log.severe("[LogBlock Consumer] Failed to get generated keys");
|
||||
}
|
||||
count++;
|
||||
}
|
||||
@@ -134,7 +140,7 @@ public class Consumer extends TimerTask implements Runnable
|
||||
}
|
||||
conn.commit();
|
||||
} catch (SQLException ex) {
|
||||
LogBlock.log.log(Level.SEVERE, "[LogBlock Consumer] SQL exception", ex);
|
||||
log.log(Level.SEVERE, "[LogBlock Consumer] SQL exception", ex);
|
||||
} finally {
|
||||
try {
|
||||
if (conn != null)
|
||||
@@ -142,7 +148,7 @@ public class Consumer extends TimerTask implements Runnable
|
||||
if (state != null)
|
||||
state.close();
|
||||
} catch (SQLException ex) {
|
||||
LogBlock.log.log(Level.SEVERE, "[LogBlock Consumer] SQL exception on close", ex);
|
||||
log.log(Level.SEVERE, "[LogBlock Consumer] SQL exception on close", ex);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@@ -10,35 +10,37 @@ import org.bukkit.event.block.SignChangeEvent;
|
||||
|
||||
public class LBBlockListener extends BlockListener
|
||||
{
|
||||
private final LogBlock logblock;
|
||||
private final Config config;
|
||||
private final Consumer consumer;
|
||||
|
||||
LBBlockListener(LogBlock logblock) {
|
||||
this.logblock = logblock;
|
||||
config = logblock.getConfig();
|
||||
consumer = logblock.getConsumer();
|
||||
}
|
||||
|
||||
public void onBlockPlace(BlockPlaceEvent event) {
|
||||
if (!event.isCancelled() && !(logblock.config.logSignTexts && (event.getBlock().getType() == Material.WALL_SIGN || event.getBlock().getType() == Material.SIGN_POST))) {
|
||||
logblock.consumer.queueBlock(event.getPlayer().getName(), event.getBlockPlaced(), event.getBlockReplacedState().getTypeId(), event.getBlockPlaced().getTypeId(), event.getBlockPlaced().getData());
|
||||
if (!event.isCancelled() && !(config.logSignTexts && (event.getBlock().getType() == Material.WALL_SIGN || event.getBlock().getType() == Material.SIGN_POST))) {
|
||||
consumer.queueBlock(event.getPlayer().getName(), event.getBlockPlaced(), event.getBlockReplacedState().getTypeId(), event.getBlockPlaced().getTypeId(), event.getBlockPlaced().getData());
|
||||
}
|
||||
}
|
||||
|
||||
public void onBlockBreak(BlockBreakEvent event) {
|
||||
if (!event.isCancelled())
|
||||
logblock.consumer.queueBlock(event.getPlayer().getName(), event.getBlock(), event.getBlock().getTypeId(), 0, event.getBlock().getData());
|
||||
consumer.queueBlock(event.getPlayer().getName(), event.getBlock(), event.getBlock().getTypeId(), 0, event.getBlock().getData());
|
||||
}
|
||||
|
||||
public void onSignChange(SignChangeEvent event) {
|
||||
if (!event.isCancelled())
|
||||
logblock.consumer.queueBlock(event.getPlayer().getName(), event.getBlock(), 0, event.getBlock().getTypeId(), event.getBlock().getData(), "sign [" + event.getLine(0) + "] [" + event.getLine(1) + "] [" + event.getLine(2) + "] [" + event.getLine(3) + "]", null);
|
||||
consumer.queueBlock(event.getPlayer().getName(), event.getBlock(), 0, event.getBlock().getTypeId(), event.getBlock().getData(), "sign [" + event.getLine(0) + "] [" + event.getLine(1) + "] [" + event.getLine(2) + "] [" + event.getLine(3) + "]", null);
|
||||
}
|
||||
|
||||
public void onBlockBurn(BlockBurnEvent event) {
|
||||
if (!event.isCancelled())
|
||||
logblock.consumer.queueBlock("Fire", event.getBlock(), event.getBlock().getTypeId(), 0, event.getBlock().getData());
|
||||
consumer.queueBlock("Fire", event.getBlock(), event.getBlock().getTypeId(), 0, event.getBlock().getData());
|
||||
}
|
||||
|
||||
public void onLeavesDecay(LeavesDecayEvent event) {
|
||||
if (!event.isCancelled())
|
||||
logblock.consumer.queueBlock("LeavesDecay", event.getBlock(), event.getBlock().getTypeId(), 0, event.getBlock().getData());
|
||||
consumer.queueBlock("LeavesDecay", event.getBlock(), event.getBlock().getTypeId(), 0, event.getBlock().getData());
|
||||
}
|
||||
}
|
||||
|
@@ -15,10 +15,12 @@ import org.bukkit.event.entity.EntityListener;
|
||||
|
||||
public class LBEntityListener extends EntityListener
|
||||
{
|
||||
private final LogBlock logblock;
|
||||
private final Config config;
|
||||
private final Consumer consumer;
|
||||
|
||||
LBEntityListener(LogBlock logblock) {
|
||||
this.logblock = logblock;
|
||||
config= logblock.getConfig();
|
||||
consumer = logblock.getConsumer();
|
||||
}
|
||||
|
||||
public void onEntityExplode(EntityExplodeEvent event) {
|
||||
@@ -33,7 +35,7 @@ public class LBEntityListener extends EntityListener
|
||||
else
|
||||
name = "Environment";
|
||||
for (Block block : event.blockList())
|
||||
logblock.consumer.queueBlock(name, block, block.getTypeId(), 0, block.getData());
|
||||
consumer.queueBlock(name, block, block.getTypeId(), 0, block.getData());
|
||||
}
|
||||
}
|
||||
|
||||
@@ -44,10 +46,10 @@ public class LBEntityListener extends EntityListener
|
||||
Entity killer = ((EntityDamageByEntityEvent)event).getDamager();
|
||||
if (victim.getHealth() - event.getDamage() > 0 || victim.getHealth() <= 0 )
|
||||
return;
|
||||
if (logblock.config.logKillsLevel == Config.LogKillsLevel.PLAYERS && !(victim instanceof Player && killer instanceof Player))
|
||||
if (config.logKillsLevel == Config.LogKillsLevel.PLAYERS && !(victim instanceof Player && killer instanceof Player))
|
||||
return;
|
||||
else if (logblock.config.logKillsLevel == Config.LogKillsLevel.MONSTERS && !((victim instanceof Player || victim instanceof Monster) && killer instanceof Player || killer instanceof Monster))
|
||||
else if (config.logKillsLevel == Config.LogKillsLevel.MONSTERS && !((victim instanceof Player || victim instanceof Monster) && killer instanceof Player || killer instanceof Monster))
|
||||
return;
|
||||
logblock.consumer.queueKill(killer, victim);
|
||||
consumer.queueKill(killer, victim);
|
||||
}
|
||||
}
|
||||
|
@@ -4,6 +4,7 @@ import java.sql.Connection;
|
||||
import java.sql.SQLException;
|
||||
import java.sql.Statement;
|
||||
import java.util.logging.Level;
|
||||
import java.util.logging.Logger;
|
||||
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.event.block.Action;
|
||||
@@ -15,43 +16,47 @@ import org.bukkit.event.player.PlayerListener;
|
||||
|
||||
public class LBPlayerListener extends PlayerListener
|
||||
{
|
||||
private final Logger log;
|
||||
private final LogBlock logblock;
|
||||
private final Consumer consumer;
|
||||
|
||||
LBPlayerListener(LogBlock logblock) {
|
||||
this.logblock = logblock;
|
||||
log = logblock.getServer().getLogger();
|
||||
consumer = logblock.getConsumer();
|
||||
}
|
||||
|
||||
public void onPlayerInteract(PlayerInteractEvent event) {
|
||||
if (!event.isCancelled()) {
|
||||
if (event.getAction() == Action.RIGHT_CLICK_BLOCK && (event.getClickedBlock().getType() == Material.CHEST || event.getClickedBlock().getType() == Material.FURNACE ||event.getClickedBlock().getType() == Material.DISPENSER)) {
|
||||
logblock.consumer.queueBlock(event.getPlayer(), event.getClickedBlock(), (short)0, (byte)0, (short)0, (byte)0);
|
||||
consumer.queueBlock(event.getPlayer(), event.getClickedBlock(), (short)0, (byte)0, (short)0, (byte)0);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void onPlayerBucketFill(PlayerBucketFillEvent event) {
|
||||
if (!event.isCancelled()) {
|
||||
logblock.consumer.queueBlock(event.getPlayer().getName(), event.getBlockClicked(), event.getBlockClicked().getTypeId(), 0, event.getBlockClicked().getData());
|
||||
consumer.queueBlock(event.getPlayer().getName(), event.getBlockClicked(), event.getBlockClicked().getTypeId(), 0, event.getBlockClicked().getData());
|
||||
}
|
||||
}
|
||||
|
||||
public void onPlayerBucketEmpty(PlayerBucketEmptyEvent event) {
|
||||
if (event.getBucket() == Material.WATER_BUCKET)
|
||||
logblock.consumer.queueBlock(event.getPlayer(), event.getBlockClicked().getFace(event.getBlockFace()), Material.STATIONARY_WATER.getId());
|
||||
consumer.queueBlock(event.getPlayer(), event.getBlockClicked().getFace(event.getBlockFace()), Material.STATIONARY_WATER.getId());
|
||||
else if (event.getBucket() == Material.LAVA_BUCKET)
|
||||
logblock.consumer.queueBlock(event.getPlayer(), event.getBlockClicked().getFace(event.getBlockFace()), Material.STATIONARY_LAVA.getId());
|
||||
consumer.queueBlock(event.getPlayer(), event.getBlockClicked().getFace(event.getBlockFace()), Material.STATIONARY_LAVA.getId());
|
||||
}
|
||||
|
||||
public void onPlayerJoin(PlayerJoinEvent event) {
|
||||
Connection conn = logblock.pool.getConnection();
|
||||
Statement state = null;
|
||||
Connection conn = logblock.getConnection();
|
||||
if (conn == null)
|
||||
return;
|
||||
Statement state = null;
|
||||
try {
|
||||
state = conn.createStatement();
|
||||
state.execute("INSERT IGNORE INTO `lb-players` (playername) VALUES ('" + event.getPlayer().getName() + "');");
|
||||
} catch (SQLException ex) {
|
||||
LogBlock.log.log(Level.SEVERE, "[LogBlock] SQL exception", ex);
|
||||
log.log(Level.SEVERE, "[LogBlock] SQL exception", ex);
|
||||
} finally {
|
||||
try {
|
||||
if (state != null)
|
||||
@@ -59,7 +64,7 @@ public class LBPlayerListener extends PlayerListener
|
||||
if (conn != null)
|
||||
conn.close();
|
||||
} catch (SQLException ex) {
|
||||
LogBlock.log.log(Level.SEVERE, "[LogBlock] SQL exception on close", ex);
|
||||
log.log(Level.SEVERE, "[LogBlock] SQL exception on close", ex);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@@ -8,18 +8,20 @@ import org.bukkit.event.player.PlayerListener;
|
||||
public class LBToolPlayerListener extends PlayerListener
|
||||
{
|
||||
private final LogBlock logblock;
|
||||
private final Config config;
|
||||
|
||||
LBToolPlayerListener(LogBlock logblock) {
|
||||
this.logblock = logblock;
|
||||
config = logblock.getConfig();
|
||||
}
|
||||
|
||||
public void onPlayerInteract(PlayerInteractEvent event) {
|
||||
if (!event.isCancelled()) {
|
||||
if (event.getAction() == Action.RIGHT_CLICK_BLOCK && event.getMaterial().getId() == logblock.config.toolID && logblock.checkPermission(event.getPlayer(), "logblock.lookup")) {
|
||||
if (event.getAction() == Action.RIGHT_CLICK_BLOCK && event.getMaterial().getId() == config.toolID && logblock.checkPermission(event.getPlayer(), "logblock.lookup")) {
|
||||
logblock.getServer().getScheduler().scheduleAsyncDelayedTask(logblock, new BlockStats(logblock, event.getPlayer(), event.getClickedBlock()));
|
||||
if (event.getClickedBlock().getType() != Material.BED_BLOCK)
|
||||
event.setCancelled(true);
|
||||
} else if (event.getAction() == Action.RIGHT_CLICK_BLOCK && event.getMaterial().getId() == logblock.config.toolblockID && logblock.checkPermission(event.getPlayer(), "logblock.lookup")) {
|
||||
} else if (event.getAction() == Action.RIGHT_CLICK_BLOCK && event.getMaterial().getId() == config.toolblockID && logblock.checkPermission(event.getPlayer(), "logblock.lookup")) {
|
||||
logblock.getServer().getScheduler().scheduleAsyncDelayedTask(logblock, new BlockStats(logblock, event.getPlayer(), event.getClickedBlock().getFace(event.getBlockFace())));
|
||||
event.setCancelled(true);
|
||||
}
|
||||
|
@@ -34,13 +34,21 @@ import de.diddiz.util.Download;
|
||||
|
||||
public class LogBlock extends JavaPlugin
|
||||
{
|
||||
public static Logger log;
|
||||
public Config config;
|
||||
public ConnectionPool pool;
|
||||
public Consumer consumer = null;
|
||||
private Logger log;
|
||||
private Config config;
|
||||
private ConnectionPool pool;
|
||||
private Consumer consumer = null;
|
||||
private Timer timer = null;
|
||||
private PermissionHandler permissions = null;
|
||||
|
||||
public Config getConfig() {
|
||||
return config;
|
||||
}
|
||||
|
||||
public Consumer getConsumer() {
|
||||
return consumer;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onEnable() {
|
||||
log = getServer().getLogger();
|
||||
@@ -71,7 +79,7 @@ public class LogBlock extends JavaPlugin
|
||||
}
|
||||
try {
|
||||
pool = new ConnectionPool("com.mysql.jdbc.Driver", config.url, config.user, config.password);
|
||||
Connection conn = pool.getConnection();
|
||||
Connection conn = getConnection();
|
||||
conn.close();
|
||||
} catch (Exception ex) {
|
||||
log.log(Level.SEVERE, "[LogBlock] Exception while checking database connection", ex);
|
||||
@@ -85,6 +93,7 @@ public class LogBlock extends JavaPlugin
|
||||
}
|
||||
if (config.keepLogDays >= 0)
|
||||
new Thread(new ClearLog(this)).start();
|
||||
consumer = new Consumer(this);
|
||||
LBBlockListener lbBlockListener = new LBBlockListener(this);
|
||||
LBPlayerListener lbPlayerListener = new LBPlayerListener(this);
|
||||
LBEntityListener lbEntityListener = new LBEntityListener(this);
|
||||
@@ -111,7 +120,6 @@ public class LogBlock extends JavaPlugin
|
||||
pm.registerEvent(Type.PLAYER_INTERACT, lbPlayerListener, Priority.Monitor, this);
|
||||
if (config.logKills)
|
||||
pm.registerEvent(Type.ENTITY_DAMAGE, lbEntityListener, Priority.Monitor, this);
|
||||
consumer = new Consumer(this);
|
||||
if (config.useBukkitScheduler) {
|
||||
if (getServer().getScheduler().scheduleAsyncRepeatingTask(this, consumer, config.delay * 20, config.delay * 20) > 0)
|
||||
log.info("[LogBlock] Scheduled consumer with bukkit scheduler.");
|
||||
@@ -152,15 +160,6 @@ public class LogBlock extends JavaPlugin
|
||||
return true;
|
||||
}
|
||||
Player player = (Player)sender;
|
||||
Connection conn = pool.getConnection();
|
||||
String table = config.tables.get(player.getWorld().getName().hashCode());
|
||||
if (conn == null) {
|
||||
player.sendMessage(ChatColor.RED + "Can't create SQL connection.");
|
||||
return true;
|
||||
} else if (table == null) {
|
||||
player.sendMessage(ChatColor.RED + "This world isn't logged");
|
||||
return true;
|
||||
}
|
||||
if (args.length == 0) {
|
||||
player.sendMessage(ChatColor.LIGHT_PURPLE + "LogBlock v" + getDescription().getVersion() + " by DiddiZ");
|
||||
player.sendMessage(ChatColor.LIGHT_PURPLE + "Type /lb help for help");
|
||||
@@ -217,12 +216,12 @@ public class LogBlock extends JavaPlugin
|
||||
int radius = config.defaultDist;
|
||||
if (args.length == 2 && isInt(args[1]))
|
||||
radius = Integer.parseInt(args[1]);
|
||||
new Thread(new AreaStats(conn, player, radius, table)).start();
|
||||
new Thread(new AreaStats(this, player, radius)).start();
|
||||
} else
|
||||
player.sendMessage(ChatColor.RED + "You aren't allowed to do this");
|
||||
} else if (args[0].equalsIgnoreCase("world")) {
|
||||
if (checkPermission(player,"logblock.area")) {
|
||||
new Thread(new AreaStats(conn, player, Short.MAX_VALUE, table)).start();
|
||||
new Thread(new AreaStats(this, player, Short.MAX_VALUE)).start();
|
||||
} else
|
||||
player.sendMessage(ChatColor.RED + "You aren't allowed to do this");
|
||||
} else if (args[0].equalsIgnoreCase("player")) {
|
||||
@@ -231,7 +230,7 @@ public class LogBlock extends JavaPlugin
|
||||
int radius = config.defaultDist;
|
||||
if (args.length == 3 && isInt(args[2]))
|
||||
radius = Integer.parseInt(args[2]);
|
||||
new Thread(new PlayerAreaStats(conn, player, args[1], radius, table)).start();
|
||||
new Thread(new PlayerAreaStats(this, player, args[1], radius)).start();
|
||||
} else
|
||||
player.sendMessage(ChatColor.RED + "Usage: /lb player [name] <radius>");
|
||||
} else
|
||||
@@ -244,7 +243,7 @@ public class LogBlock extends JavaPlugin
|
||||
if (args.length == 3 && isInt(args[2]))
|
||||
radius = Integer.parseInt(args[2]);
|
||||
if (mat != null)
|
||||
new Thread(new AreaBlockSearch(conn, player, mat.getId(), radius, table)).start();
|
||||
new Thread(new AreaBlockSearch(this, player, mat.getId(), radius)).start();
|
||||
else
|
||||
player.sendMessage(ChatColor.RED + "Can't find any item like '" + args[1] + "'");
|
||||
} else
|
||||
@@ -260,7 +259,7 @@ public class LogBlock extends JavaPlugin
|
||||
if (args.length == 5)
|
||||
minutes = parseTimeSpec(args[3], args[4]);
|
||||
player.sendMessage(ChatColor.GREEN + "Rolling back " + args[2] + " by " + minutes + " minutes.");
|
||||
getServer().getScheduler().scheduleAsyncDelayedTask(this, new Rollback(player, conn, this, args[2], -1, null, minutes, table, false));
|
||||
getServer().getScheduler().scheduleAsyncDelayedTask(this, new Rollback(this, player, args[2], -1, null, minutes, false));
|
||||
} else
|
||||
player.sendMessage(ChatColor.RED + "Usage: /lb rollback player [name] <time> <minutes|hours|days>");
|
||||
} else if (args[1].equalsIgnoreCase("area")) {
|
||||
@@ -269,7 +268,7 @@ public class LogBlock extends JavaPlugin
|
||||
minutes = parseTimeSpec(args[3], args[4]);
|
||||
if (isInt(args[2])) {
|
||||
player.sendMessage(ChatColor.GREEN + "Rolling back area within " + args[2] + " blocks of you by " + minutes + " minutes.");
|
||||
getServer().getScheduler().scheduleAsyncDelayedTask(this, new Rollback(player, conn, this, null, Integer.parseInt(args[2]), null, minutes, table, false));
|
||||
getServer().getScheduler().scheduleAsyncDelayedTask(this, new Rollback(this, player, null, Integer.parseInt(args[2]), null, minutes, false));
|
||||
} else
|
||||
player.sendMessage(ChatColor.RED + "Can't parse to an int: " + args[2]);
|
||||
} else
|
||||
@@ -280,7 +279,7 @@ public class LogBlock extends JavaPlugin
|
||||
minutes = parseTimeSpec(args[4], args[5]);
|
||||
if (isInt(args[3])) {
|
||||
player.sendMessage(ChatColor.GREEN + "Rolling back " + args[2] + " within " + args[3] + " blocks by " + minutes + " minutes.");
|
||||
getServer().getScheduler().scheduleAsyncDelayedTask(this, new Rollback(player, conn, this, args[2], Integer.parseInt(args[3]), null, minutes, table, false));
|
||||
getServer().getScheduler().scheduleAsyncDelayedTask(this, new Rollback(this, player, args[2], Integer.parseInt(args[3]), null, minutes, false));
|
||||
} else
|
||||
player.sendMessage(ChatColor.RED + "Can't parse to an int: " + args[3]);
|
||||
} else
|
||||
@@ -295,7 +294,7 @@ public class LogBlock extends JavaPlugin
|
||||
if (sel != null) {
|
||||
if (sel instanceof CuboidSelection) {
|
||||
player.sendMessage(ChatColor.GREEN + "Rolling back selection by " + minutes + " minutes.");
|
||||
getServer().getScheduler().scheduleAsyncDelayedTask(this, new Rollback(player, conn, this, null, -1, sel, minutes, table, false));
|
||||
getServer().getScheduler().scheduleAsyncDelayedTask(this, new Rollback(this, player, null, -1, sel, minutes, false));
|
||||
} else
|
||||
player.sendMessage(ChatColor.RED + "You have to define a cuboid selection");
|
||||
} else
|
||||
@@ -324,7 +323,7 @@ public class LogBlock extends JavaPlugin
|
||||
if (args.length == 5)
|
||||
minutes = parseTimeSpec(args[3], args[4]);
|
||||
player.sendMessage(ChatColor.GREEN + "Redoing " + args[2] + " for " + minutes + " minutes.");
|
||||
getServer().getScheduler().scheduleAsyncDelayedTask(this, new Rollback(player, conn, this, args[2], -1, null, minutes, table, true));
|
||||
getServer().getScheduler().scheduleAsyncDelayedTask(this, new Rollback(this, player, args[2], -1, null, minutes, true));
|
||||
} else
|
||||
player.sendMessage(ChatColor.RED + "Usage: /lb redo player [name] <time> <minutes|hours|days>");
|
||||
} else if (args[1].equalsIgnoreCase("area")) {
|
||||
@@ -333,7 +332,7 @@ public class LogBlock extends JavaPlugin
|
||||
minutes = parseTimeSpec(args[3], args[4]);
|
||||
if (isInt(args[2])) {
|
||||
player.sendMessage(ChatColor.GREEN + "Redoing area within " + args[2] + " blocks of you for " + minutes + " minutes.");
|
||||
getServer().getScheduler().scheduleAsyncDelayedTask(this, new Rollback(player, conn, this, null, Integer.parseInt(args[2]), null, minutes, table, true));
|
||||
getServer().getScheduler().scheduleAsyncDelayedTask(this, new Rollback(this, player, null, Integer.parseInt(args[2]), null, minutes, true));
|
||||
} else
|
||||
player.sendMessage(ChatColor.RED + "Can't parse to an int: " + args[2]);
|
||||
} else
|
||||
@@ -344,7 +343,7 @@ public class LogBlock extends JavaPlugin
|
||||
minutes = parseTimeSpec(args[4], args[5]);
|
||||
if (isInt(args[3])) {
|
||||
player.sendMessage(ChatColor.GREEN + "Redoing " + args[2] + " within " + args[3] + " blocks for " + minutes + " minutes.");
|
||||
getServer().getScheduler().scheduleAsyncDelayedTask(this, new Rollback(player, conn, this, args[2], Integer.parseInt(args[3]), null, minutes, table, true));
|
||||
getServer().getScheduler().scheduleAsyncDelayedTask(this, new Rollback(this, player, args[2], Integer.parseInt(args[3]), null, minutes, true));
|
||||
} else
|
||||
player.sendMessage(ChatColor.RED + "Can't parse to an int: " + args[3]);
|
||||
} else
|
||||
@@ -359,7 +358,7 @@ public class LogBlock extends JavaPlugin
|
||||
if (sel != null) {
|
||||
if (sel instanceof CuboidSelection) {
|
||||
player.sendMessage(ChatColor.GREEN + "Redoing selection for " + minutes + " minutes.");
|
||||
getServer().getScheduler().scheduleAsyncDelayedTask(this, new Rollback(player, conn, this, null, -1, sel, minutes, table, true));
|
||||
getServer().getScheduler().scheduleAsyncDelayedTask(this, new Rollback(this, player, null, -1, sel, minutes, true));
|
||||
} else
|
||||
player.sendMessage(ChatColor.RED + "You have to define a cuboid selection");
|
||||
} else
|
||||
@@ -382,7 +381,7 @@ public class LogBlock extends JavaPlugin
|
||||
} else if (args[0].equalsIgnoreCase("writelogfile")) {
|
||||
if (checkPermission(player,"logblock.rollback")) {
|
||||
if (args.length == 2) {
|
||||
new Thread(new WriteLogFile(conn, player, args[1], table)).start();
|
||||
new Thread(new WriteLogFile(this, player, args[1])).start();
|
||||
}
|
||||
else
|
||||
player.sendMessage(ChatColor.RED + "Usage: /lb writelogfile [name]");
|
||||
@@ -390,7 +389,7 @@ public class LogBlock extends JavaPlugin
|
||||
player.sendMessage(ChatColor.RED + "You aren't allowed to do this");
|
||||
} else if (args[0].equalsIgnoreCase("me")) {
|
||||
if (checkPermission(player,"logblock.me")) {
|
||||
new Thread(new PlayerAreaStats(conn, player, player.getName(), Short.MAX_VALUE, table)).start();
|
||||
new Thread(new PlayerAreaStats(this, player, player.getName(), Short.MAX_VALUE)).start();
|
||||
} else
|
||||
player.sendMessage(ChatColor.RED + "You aren't allowed to do this");
|
||||
} else if (args[0].equalsIgnoreCase("help")) {
|
||||
@@ -416,7 +415,7 @@ public class LogBlock extends JavaPlugin
|
||||
}
|
||||
|
||||
private boolean checkTables() {
|
||||
Connection conn = pool.getConnection();
|
||||
Connection conn = getConnection();
|
||||
Statement state = null;
|
||||
if (conn == null)
|
||||
return false;
|
||||
@@ -516,4 +515,13 @@ public class LogBlock extends JavaPlugin
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
public Connection getConnection() {
|
||||
try {
|
||||
return pool.connect(ConnectionPool.URL_PREFIX, null);
|
||||
} catch (SQLException ex) {
|
||||
log.log(Level.SEVERE, "[LogBlock] Error while fetching connection", ex);
|
||||
return null;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@@ -5,6 +5,7 @@ import java.sql.PreparedStatement;
|
||||
import java.sql.ResultSet;
|
||||
import java.sql.SQLException;
|
||||
import java.util.logging.Level;
|
||||
import java.util.logging.Logger;
|
||||
|
||||
import org.bukkit.ChatColor;
|
||||
import org.bukkit.Material;
|
||||
@@ -12,24 +13,34 @@ import org.bukkit.entity.Player;
|
||||
|
||||
public class PlayerAreaStats implements Runnable
|
||||
{
|
||||
private Player player;
|
||||
private String name;
|
||||
private int size;
|
||||
private Connection conn = null;
|
||||
private String table;
|
||||
private final Logger log;
|
||||
private final Connection conn;
|
||||
private final String table;
|
||||
private final Player player;
|
||||
private final String name;
|
||||
private final int size;
|
||||
|
||||
PlayerAreaStats(Connection conn, Player player, String name, int size, String table) {
|
||||
PlayerAreaStats(LogBlock logblock, Player player, String name, int size) {
|
||||
this.player = player;
|
||||
this.name = name;
|
||||
this.size = size;
|
||||
this.conn = conn;
|
||||
this.table = table;
|
||||
log = logblock.getServer().getLogger();
|
||||
conn = logblock.getConnection();
|
||||
table = logblock.getConfig().tables.get(player.getWorld().getName().hashCode());
|
||||
}
|
||||
|
||||
public void run() {
|
||||
PreparedStatement ps = null;
|
||||
ResultSet rs = null;
|
||||
try {
|
||||
if (conn == null) {
|
||||
player.sendMessage(ChatColor.RED + "Failed to create database connection");
|
||||
return;
|
||||
}
|
||||
if (table == null) {
|
||||
player.sendMessage(ChatColor.RED + "This world isn't logged");
|
||||
return;
|
||||
}
|
||||
conn.setAutoCommit(false);
|
||||
ps = conn.prepareStatement("SELECT `type`, SUM(`created`) AS `created`, SUM(`destroyed`) AS `destroyed` FROM ((SELECT `type`, count(`type`) AS `created`, 0 AS `destroyed` FROM `" + table + "` INNER JOIN `lb-players` USING (`playerid`) WHERE `playername` = ? AND x > ? AND x < ? AND z > ? AND z < ? AND `type` > 0 AND `type` != `replaced` GROUP BY `type`) UNION (SELECT `replaced` AS `type`, 0 AS `created`, count(`replaced`) AS `destroyed` FROM `" + table + "` INNER JOIN `lb-players` USING (`playerid`) WHERE `playername` = ? AND x > ? AND x < ? AND z > ? AND z < ? AND `replaced` > 0 AND `type` != `replaced` GROUP BY `replaced`)) AS t GROUP BY `type` ORDER BY SUM(`created`) + SUM(`destroyed`) DESC LIMIT 15");
|
||||
ps.setString(1, name);
|
||||
@@ -54,7 +65,7 @@ public class PlayerAreaStats implements Runnable
|
||||
}
|
||||
}
|
||||
} catch (SQLException ex) {
|
||||
LogBlock.log.log(Level.SEVERE, "[LogBlock PlayerAreaStats] SQL exception", ex);
|
||||
log.log(Level.SEVERE, "[LogBlock PlayerAreaStats] SQL exception", ex);
|
||||
} finally {
|
||||
try {
|
||||
if (rs != null)
|
||||
@@ -64,7 +75,7 @@ public class PlayerAreaStats implements Runnable
|
||||
if (conn != null)
|
||||
conn.close();
|
||||
} catch (SQLException ex) {
|
||||
LogBlock.log.log(Level.SEVERE, "[LogBlock PlayerAreaStats] SQL exception on close", ex);
|
||||
log.log(Level.SEVERE, "[LogBlock PlayerAreaStats] SQL exception on close", ex);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@@ -5,6 +5,7 @@ import java.sql.ResultSet;
|
||||
import java.sql.SQLException;
|
||||
import java.util.concurrent.LinkedBlockingQueue;
|
||||
import java.util.logging.Level;
|
||||
import java.util.logging.Logger;
|
||||
|
||||
import org.bukkit.ChatColor;
|
||||
import org.bukkit.World;
|
||||
@@ -15,35 +16,41 @@ import com.sk89q.worldedit.bukkit.selections.Selection;
|
||||
|
||||
public class Rollback implements Runnable
|
||||
{
|
||||
private Player player;
|
||||
private Connection conn;
|
||||
private LogBlock logblock;
|
||||
private String query;
|
||||
private boolean redo;
|
||||
private final Logger log;
|
||||
private final LogBlock logblock;
|
||||
private final Config config;
|
||||
private final Player player;
|
||||
private final Connection conn;
|
||||
private final String query;
|
||||
private final boolean redo;
|
||||
|
||||
Rollback(Player player, Connection conn, LogBlock logblock, String name, int radius, Selection sel, int minutes, String table, boolean redo) {
|
||||
this.player = player;
|
||||
this.conn = conn;
|
||||
Rollback(LogBlock logblock, Player player, String name, int radius, Selection sel, int minutes, boolean redo) {
|
||||
this.logblock = logblock;
|
||||
this.player = player;
|
||||
this.redo = redo;
|
||||
log = logblock.getServer().getLogger();
|
||||
conn = logblock.getConnection();
|
||||
config = logblock.getConfig();
|
||||
StringBuffer sql = new StringBuffer();
|
||||
if (!redo)
|
||||
query = "SELECT replaced, type, data, x, y, z ";
|
||||
sql.append("SELECT replaced, type, data, x, y, z ");
|
||||
else
|
||||
query = "SELECT type AS replaced, replaced AS type, data, x, y, z ";
|
||||
query += "FROM `" + table + "` INNER JOIN `lb-players` USING (playerid) WHERE (type <> replaced OR (type = 0 AND replaced = 0)) AND ";
|
||||
sql.append("SELECT type AS replaced, replaced AS type, data, x, y, z ");
|
||||
sql.append("FROM `" + logblock.getConfig().tables.get(player.getWorld().getName().hashCode()) + "` INNER JOIN `lb-players` USING (playerid) WHERE (type <> replaced OR (type = 0 AND replaced = 0)) AND ");
|
||||
if (name != null)
|
||||
query += "playername = '" + name + "' AND ";
|
||||
sql.append("playername = '" + name + "' AND ");
|
||||
if (radius != -1)
|
||||
query += "x > '" + (player.getLocation().getBlockX() - radius) + "' AND x < '" + (player.getLocation().getBlockX() + radius) + "' AND z > '" + (player.getLocation().getBlockZ() - radius) + "' AND z < '" + (player.getLocation().getBlockZ() + radius) + "' AND ";
|
||||
sql.append("x > '" + (player.getLocation().getBlockX() - radius) + "' AND x < '" + (player.getLocation().getBlockX() + radius) + "' AND z > '" + (player.getLocation().getBlockZ() - radius) + "' AND z < '" + (player.getLocation().getBlockZ() + radius) + "' AND ");
|
||||
if (sel != null)
|
||||
query += "x >= '"+ Math.min(sel.getMinimumPoint().getBlockX(), sel.getMaximumPoint().getBlockX()) + "' AND x <= '" + Math.max(sel.getMinimumPoint().getBlockX(), sel.getMaximumPoint().getBlockX()) + "' AND y >= '" + Math.min(sel.getMinimumPoint().getBlockY(), sel.getMaximumPoint().getBlockY()) + "' AND y <= '" + Math.max(sel.getMinimumPoint().getBlockY(), sel.getMaximumPoint().getBlockY()) + "' AND z >= '" + Math.min(sel.getMinimumPoint().getBlockZ(), sel.getMaximumPoint().getBlockZ()) + "' AND z <= '" + Math.max(sel.getMinimumPoint().getBlockZ(), sel.getMaximumPoint().getBlockZ()) + "' AND ";
|
||||
sql.append("x >= '"+ Math.min(sel.getMinimumPoint().getBlockX(), sel.getMaximumPoint().getBlockX()) + "' AND x <= '" + Math.max(sel.getMinimumPoint().getBlockX(), sel.getMaximumPoint().getBlockX()) + "' AND y >= '" + Math.min(sel.getMinimumPoint().getBlockY(), sel.getMaximumPoint().getBlockY()) + "' AND y <= '" + Math.max(sel.getMinimumPoint().getBlockY(), sel.getMaximumPoint().getBlockY()) + "' AND z >= '" + Math.min(sel.getMinimumPoint().getBlockZ(), sel.getMaximumPoint().getBlockZ()) + "' AND z <= '" + Math.max(sel.getMinimumPoint().getBlockZ(), sel.getMaximumPoint().getBlockZ()) + "' AND ");
|
||||
if (minutes >= 0)
|
||||
query += "date > date_sub(now(), INTERVAL " + minutes + " MINUTE) AND ";
|
||||
query = query.substring(0, query.length() - 4);
|
||||
sql.append("date > date_sub(now(), INTERVAL " + minutes + " MINUTE) AND ");
|
||||
sql.delete(sql.length() - 5, sql.length() - 1);
|
||||
if (!redo)
|
||||
query += "ORDER BY date DESC, id DESC";
|
||||
sql.append("ORDER BY date DESC, id DESC");
|
||||
else
|
||||
query += "ORDER BY date ASC, id ASC";
|
||||
sql.append("ORDER BY date ASC, id ASC");
|
||||
query = sql.toString();
|
||||
}
|
||||
|
||||
public void run() {
|
||||
@@ -51,13 +58,17 @@ public class Rollback implements Runnable
|
||||
LinkedBlockingQueue<Edit> edits = new LinkedBlockingQueue<Edit>();
|
||||
edits.clear();
|
||||
try {
|
||||
if (!config.tables.containsKey(player.getWorld().getName().hashCode())) {
|
||||
player.sendMessage(ChatColor.RED + "This world isn't logged!");
|
||||
return;
|
||||
}
|
||||
rs = conn.createStatement().executeQuery(query);
|
||||
while (rs.next()) {
|
||||
Edit e = new Edit(rs.getInt("type"), rs.getInt("replaced"), rs.getByte("data"), rs.getInt("x"), rs.getInt("y"), rs.getInt("z"), player.getWorld());
|
||||
edits.offer(e);
|
||||
}
|
||||
} catch (SQLException ex) {
|
||||
LogBlock.log.log(Level.SEVERE, "[LogBlock Rollback] SQL exception", ex);
|
||||
log.log(Level.SEVERE, "[LogBlock Rollback] SQL exception", ex);
|
||||
player.sendMessage(ChatColor.RED + "Error, check server logs.");
|
||||
return;
|
||||
} finally {
|
||||
@@ -67,7 +78,7 @@ public class Rollback implements Runnable
|
||||
if (conn != null)
|
||||
conn.close();
|
||||
} catch (SQLException ex) {
|
||||
LogBlock.log.log(Level.SEVERE, "[LogBlock Rollback] SQL exception on close", ex);
|
||||
log.log(Level.SEVERE, "[LogBlock Rollback] SQL exception on close", ex);
|
||||
player.sendMessage(ChatColor.RED + "Error, check server logs.");
|
||||
return;
|
||||
}
|
||||
@@ -85,7 +96,7 @@ public class Rollback implements Runnable
|
||||
try {
|
||||
this.wait();
|
||||
} catch (InterruptedException e) {
|
||||
LogBlock.log.severe("[LogBlock Rollback] Interrupted");
|
||||
log.severe("[LogBlock Rollback] Interrupted");
|
||||
}
|
||||
}
|
||||
logblock.getServer().getScheduler().cancelTask(taskID);
|
||||
@@ -160,13 +171,13 @@ public class Rollback implements Runnable
|
||||
}
|
||||
|
||||
private PerformResult perform() {
|
||||
if (logblock.config.dontRollback.contains(replaced))
|
||||
if (config.dontRollback.contains(replaced))
|
||||
return PerformResult.BLACKLISTED;
|
||||
try {
|
||||
Block block = world.getBlockAt(x, y, z);
|
||||
if (!world.isChunkLoaded(block.getChunk()))
|
||||
world.loadChunk(block.getChunk());
|
||||
if (equalsType(block.getTypeId(), type) || logblock.config.replaceAnyway.contains(block.getTypeId()) || (type == 0 && replaced == 0)) {
|
||||
if (equalsType(block.getTypeId(), type) || config.replaceAnyway.contains(block.getTypeId()) || (type == 0 && replaced == 0)) {
|
||||
if (block.setTypeIdAndData(replaced, data, false))
|
||||
return PerformResult.SUCCESS;
|
||||
else
|
||||
@@ -174,7 +185,7 @@ public class Rollback implements Runnable
|
||||
} else
|
||||
return PerformResult.NO_ACTION;
|
||||
} catch (Exception ex) {
|
||||
LogBlock.log.severe("[LogBlock Rollback] " + ex.toString());
|
||||
log.severe("[LogBlock Rollback] " + ex.toString());
|
||||
return PerformResult.ERROR;
|
||||
}
|
||||
}
|
||||
|
@@ -9,6 +9,7 @@ import java.sql.ResultSet;
|
||||
import java.sql.SQLException;
|
||||
import java.text.SimpleDateFormat;
|
||||
import java.util.logging.Level;
|
||||
import java.util.logging.Logger;
|
||||
|
||||
import org.bukkit.ChatColor;
|
||||
import org.bukkit.Material;
|
||||
@@ -16,16 +17,18 @@ import org.bukkit.entity.Player;
|
||||
|
||||
public class WriteLogFile implements Runnable
|
||||
{
|
||||
private Connection conn;
|
||||
private Player player;
|
||||
private String name;
|
||||
private String table;
|
||||
private final Logger log;
|
||||
private final Connection conn;
|
||||
private final Player player;
|
||||
private final String name;
|
||||
private final String table;
|
||||
|
||||
WriteLogFile(Connection conn, Player player, String name, String table) {
|
||||
this.conn = conn;
|
||||
WriteLogFile(LogBlock logblock, Player player, String name) {
|
||||
this.player = player;
|
||||
this.name = name;
|
||||
this.table = table;
|
||||
log = logblock.getServer().getLogger();
|
||||
conn = logblock.getConnection();
|
||||
table = logblock.getConfig().tables.get(player.getWorld().getName().hashCode());
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -36,8 +39,16 @@ public class WriteLogFile implements Runnable
|
||||
String newline = System.getProperty("line.separator");
|
||||
String msg;
|
||||
try {
|
||||
if (conn == null) {
|
||||
player.sendMessage(ChatColor.RED + "Failed to create database connection");
|
||||
return;
|
||||
}
|
||||
if (table == null) {
|
||||
player.sendMessage(ChatColor.RED + "This world isn't logged");
|
||||
return;
|
||||
}
|
||||
conn.setAutoCommit(false);
|
||||
ps = conn.prepareStatement("SELECT * FROM `" + table + "` LEFT JOIN `" + table + "-sign` USING (`id`) INNER JOIN `lb-players` USING (`playerid`) WHERE `playername` = ? ORDER BY `date` ASC");
|
||||
ps = conn.prepareStatement("SELECT * FROM `" + table + "` LEFT JOIN `" + table + "-sign` USING (id) INNER JOIN `lb-players` USING (playerid) WHERE playername = ? ORDER BY date ASC");
|
||||
ps.setString(1, name);
|
||||
rs = ps.executeQuery();
|
||||
File file = new File ("plugins/LogBlock/log/" + name + ".log");
|
||||
@@ -65,10 +76,10 @@ public class WriteLogFile implements Runnable
|
||||
player.sendMessage(ChatColor.GREEN + "Done");
|
||||
} catch (SQLException ex) {
|
||||
player.sendMessage(ChatColor.RED + "SQL exception");
|
||||
LogBlock.log.log(Level.SEVERE, "[LogBlock WriteLogFile] SQL exception", ex);
|
||||
log.log(Level.SEVERE, "[LogBlock WriteLogFile] SQL exception", ex);
|
||||
} catch (IOException ex) {
|
||||
player.sendMessage(ChatColor.RED + "IO exception");
|
||||
LogBlock.log.log(Level.SEVERE, "[LogBlock WriteLogFile] IO exception", ex);
|
||||
log.log(Level.SEVERE, "[LogBlock WriteLogFile] IO exception", ex);
|
||||
} finally {
|
||||
try {
|
||||
if (rs != null)
|
||||
@@ -78,7 +89,7 @@ public class WriteLogFile implements Runnable
|
||||
if (conn != null)
|
||||
conn.close();
|
||||
} catch (SQLException ex) {
|
||||
LogBlock.log.log(Level.SEVERE, "[LogBlock BlockStats] SQL exception on close", ex);
|
||||
log.log(Level.SEVERE, "[LogBlock BlockStats] SQL exception on close", ex);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@@ -36,9 +36,6 @@ import java.util.Enumeration;
|
||||
import java.util.Map;
|
||||
import java.util.Properties;
|
||||
import java.util.Vector;
|
||||
import java.util.logging.Level;
|
||||
|
||||
import de.diddiz.LogBlock.LogBlock;
|
||||
|
||||
public class ConnectionPool implements Driver {
|
||||
public static final String URL_PREFIX = "jdbc:jdc:";
|
||||
@@ -58,15 +55,6 @@ public class ConnectionPool implements Driver {
|
||||
return pool.getConnection();
|
||||
}
|
||||
|
||||
public Connection getConnection() {
|
||||
try {
|
||||
return pool.getConnection();
|
||||
} catch (SQLException ex) {
|
||||
LogBlock.log.log(Level.SEVERE, "[LogBlock ConnectionPool] Error while fetching connection", ex);
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
public boolean acceptsURL(String url) {
|
||||
return url.startsWith(URL_PREFIX);
|
||||
}
|
||||
|
Reference in New Issue
Block a user