forked from LogBlock/LogBlock
Clean up
This commit is contained in:
@@ -25,7 +25,7 @@ public class AreaBlockSearch implements Runnable
|
||||
|
||||
AreaBlockSearch(LogBlock logblock, Player player, int type, int size) {
|
||||
this.player = player;
|
||||
this.location = player.getLocation();
|
||||
location = player.getLocation();
|
||||
this.type = type;
|
||||
this.size = size;
|
||||
log = logblock.getServer().getLogger();
|
||||
@@ -33,11 +33,12 @@ public class AreaBlockSearch implements Runnable
|
||||
table = logblock.getConfig().tables.get(player.getWorld().getName().hashCode());
|
||||
}
|
||||
|
||||
@Override
|
||||
public void run() {
|
||||
boolean hist = false;
|
||||
PreparedStatement ps = null;
|
||||
ResultSet rs = null;
|
||||
SimpleDateFormat formatter = new SimpleDateFormat("MM-dd HH:mm:ss");
|
||||
final SimpleDateFormat formatter = new SimpleDateFormat("MM-dd HH:mm:ss");
|
||||
try {
|
||||
if (conn == null) {
|
||||
player.sendMessage(ChatColor.RED + "Failed to create database connection");
|
||||
@@ -72,7 +73,7 @@ public class AreaBlockSearch implements Runnable
|
||||
}
|
||||
if (!hist)
|
||||
player.sendMessage(ChatColor.DARK_AQUA + "None.");
|
||||
} catch (SQLException ex) {
|
||||
} catch (final SQLException ex) {
|
||||
log.log(Level.SEVERE, "[LogBlock AreaBlockSearch] SQL exception", ex);
|
||||
} finally {
|
||||
try {
|
||||
@@ -82,7 +83,7 @@ public class AreaBlockSearch implements Runnable
|
||||
ps.close();
|
||||
if (conn != null)
|
||||
conn.close();
|
||||
} catch (SQLException ex) {
|
||||
} catch (final SQLException ex) {
|
||||
log.log(Level.SEVERE, "[LogBlock AreaBlockSearch] SQL exception on close", ex);
|
||||
}
|
||||
}
|
||||
|
@@ -26,6 +26,7 @@ public class AreaStats implements Runnable
|
||||
table = logblock.getConfig().tables.get(player.getWorld().getName().hashCode());
|
||||
}
|
||||
|
||||
@Override
|
||||
public void run() {
|
||||
PreparedStatement ps = null;
|
||||
ResultSet rs = null;
|
||||
@@ -59,7 +60,7 @@ public class AreaStats implements Runnable
|
||||
player.sendMessage(ChatColor.GOLD + String.format("%-6d %-6d %s", rs.getInt("created"), rs.getInt("destroyed"), rs.getString("playername")));
|
||||
}
|
||||
}
|
||||
} catch (SQLException ex) {
|
||||
} catch (final SQLException ex) {
|
||||
log.log(Level.SEVERE, "[LogBlock AreaStats] SQL exception", ex);
|
||||
} finally {
|
||||
try {
|
||||
@@ -69,7 +70,7 @@ public class AreaStats implements Runnable
|
||||
ps.close();
|
||||
if (conn != null)
|
||||
conn.close();
|
||||
} catch (SQLException ex) {
|
||||
} catch (final SQLException ex) {
|
||||
log.log(Level.SEVERE, "[LogBlock AreaStats] SQL exception on close", ex);
|
||||
}
|
||||
}
|
||||
|
@@ -34,7 +34,7 @@ public class BlockStats implements Runnable
|
||||
boolean hist = false;
|
||||
PreparedStatement ps = null;
|
||||
ResultSet rs = null;
|
||||
SimpleDateFormat formatter = new SimpleDateFormat("MM-dd HH:mm:ss");
|
||||
final SimpleDateFormat formatter = new SimpleDateFormat("MM-dd HH:mm:ss");
|
||||
try {
|
||||
if (conn == null) {
|
||||
player.sendMessage(ChatColor.RED + "Failed to create database connection");
|
||||
@@ -53,8 +53,8 @@ public class BlockStats implements Runnable
|
||||
player.sendMessage(ChatColor.DARK_AQUA + "Block history (" + block.getX() + ", " + block.getY() + ", " + block.getZ() + "): ");
|
||||
while (rs.next()) {
|
||||
String msg = formatter.format(rs.getTimestamp("date")) + " " + rs.getString("playername") + " ";
|
||||
int type = rs.getInt("type");
|
||||
int replaced = rs.getInt("replaced");
|
||||
final int type = rs.getInt("type");
|
||||
final int replaced = rs.getInt("replaced");
|
||||
if ((type == 63 || type == 68) && rs.getString("signtext") != null)
|
||||
msg += "created " + rs.getString("signtext");
|
||||
else if (type == replaced) {
|
||||
@@ -71,7 +71,7 @@ public class BlockStats implements Runnable
|
||||
}
|
||||
if (!hist)
|
||||
player.sendMessage(ChatColor.DARK_AQUA + "None.");
|
||||
} catch (SQLException ex) {
|
||||
} catch (final SQLException ex) {
|
||||
log.log(Level.SEVERE, "[LogBlock BlockStats] SQL exception", ex);
|
||||
} finally {
|
||||
try {
|
||||
@@ -81,7 +81,7 @@ public class BlockStats implements Runnable
|
||||
ps.close();
|
||||
if (conn != null)
|
||||
conn.close();
|
||||
} catch (SQLException ex) {
|
||||
} catch (final SQLException ex) {
|
||||
log.log(Level.SEVERE, "[LogBlock BlockStats] SQL exception on close", ex);
|
||||
}
|
||||
}
|
||||
|
@@ -31,12 +31,12 @@ public class ClearLog implements Runnable
|
||||
return;
|
||||
dumpFolder.mkdirs();
|
||||
state = conn.createStatement();
|
||||
String time = new SimpleDateFormat("yy-MM-dd-HH-mm-ss").format(System.currentTimeMillis() - config.keepLogDays*86400000L);
|
||||
final String time = new SimpleDateFormat("yy-MM-dd-HH-mm-ss").format(System.currentTimeMillis() - config.keepLogDays*86400000L);
|
||||
ResultSet rs;
|
||||
for (String table : config.tables.values()) {
|
||||
for (final String table : config.tables.values()) {
|
||||
rs = state.executeQuery("SELECT count(*) FROM `" + table + "` WHERE date < '" + time + "'");
|
||||
rs.next();
|
||||
int deleted = rs.getInt(1);
|
||||
int deleted = rs.getInt(1);
|
||||
if (deleted > 0) {
|
||||
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'");
|
||||
@@ -45,7 +45,7 @@ public class ClearLog implements Runnable
|
||||
}
|
||||
rs = state.executeQuery("SELECT COUNT(*) FROM `" + table + "-sign` LEFT JOIN `" + table + "` USING (id) WHERE `" + table + "`.id IS NULL");
|
||||
rs.next();
|
||||
deleted = rs.getInt(1);
|
||||
deleted = rs.getInt(1);
|
||||
if (deleted > 0) {
|
||||
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'");
|
||||
@@ -54,7 +54,7 @@ public class ClearLog implements Runnable
|
||||
}
|
||||
rs = state.executeQuery("SELECT COUNT(*) FROM `" + table + "-chest` LEFT JOIN `" + table + "` USING (id) WHERE `" + table + "`.id IS NULL");
|
||||
rs.next();
|
||||
deleted = rs.getInt(1);
|
||||
deleted = rs.getInt(1);
|
||||
if (deleted > 0) {
|
||||
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'");
|
||||
@@ -62,7 +62,7 @@ public class ClearLog implements Runnable
|
||||
log.info("[LogBlock] Cleared out table " + table + "-chest. Deleted " + deleted + " entries.");
|
||||
}
|
||||
}
|
||||
} catch (SQLException ex) {
|
||||
} catch (final SQLException ex) {
|
||||
log.log(Level.SEVERE, "[LogBlock] SQL exception", ex);
|
||||
} finally {
|
||||
try {
|
||||
@@ -70,7 +70,7 @@ public class ClearLog implements Runnable
|
||||
state.close();
|
||||
if (conn != null)
|
||||
conn.close();
|
||||
} catch (SQLException ex) {
|
||||
} catch (final SQLException ex) {
|
||||
log.log(Level.SEVERE, "[LogBlock] SQL exception on close", ex);
|
||||
}
|
||||
}
|
||||
|
@@ -38,9 +38,9 @@ public class Config {
|
||||
}
|
||||
|
||||
Config (LogBlock logblock) throws Exception {
|
||||
Configuration config = logblock.getConfiguration();
|
||||
final Configuration config = logblock.getConfiguration();
|
||||
config.load();
|
||||
List<String> keys = config.getKeys(null);
|
||||
final List<String> keys = config.getKeys(null);
|
||||
List<String> subkeys;
|
||||
if (!keys.contains("version"))
|
||||
config.setProperty("version", logblock.getDescription().getVersion());
|
||||
@@ -133,7 +133,7 @@ public class Config {
|
||||
logKills = config.getBoolean("logging.logKills", false);
|
||||
try {
|
||||
logKillsLevel = LogKillsLevel.valueOf(config.getString("logging.logKillsLevel"));
|
||||
} catch (IllegalArgumentException ex) {
|
||||
} catch (final IllegalArgumentException ex) {
|
||||
throw new Exception("lookup.toolblockID doesn't appear to be a valid log level. Allowed are 'PLAYERS', 'MONSTERS' and 'ANIMALS'");
|
||||
}
|
||||
dontRollback = config.getIntList("rollback.dontRollback", null);
|
||||
@@ -146,8 +146,8 @@ public class Config {
|
||||
toolblockID = config.getInt("lookup.toolblockID", 7);
|
||||
if (Material.getMaterial(toolblockID) == null || !Material.getMaterial(toolblockID).isBlock() || toolblockID == 0)
|
||||
throw new Exception("lookup.toolblockID doesn't appear to be a valid block id");
|
||||
List<String> worldNames = config.getStringList("loggedWorlds", null);
|
||||
List<String> worldTables = config.getStringList("tables", null);
|
||||
final List<String> worldNames = config.getStringList("loggedWorlds", null);
|
||||
final List<String> worldTables = config.getStringList("tables", null);
|
||||
tables = new HashMap<Integer, String>();
|
||||
if (worldNames == null || worldTables == null || worldNames.size() == 0 || worldNames.size() != worldTables.size())
|
||||
throw new Exception("worldNames or worldTables not set porperly");
|
||||
|
@@ -32,7 +32,6 @@ public class Consumer extends TimerTask implements Runnable
|
||||
private final HashSet<Integer> hiddenplayers = new HashSet<Integer>();
|
||||
private final HashMap<Integer, Integer> lastAttackedEntity = new HashMap<Integer, Integer>();
|
||||
private final HashMap<Integer, Long> lastAttackTime = new HashMap<Integer, Long>();
|
||||
|
||||
|
||||
Consumer (LogBlock logblock) {
|
||||
this.logblock = logblock;
|
||||
@@ -55,7 +54,6 @@ public class Consumer extends TimerTask implements Runnable
|
||||
queueBlock(playerName, loc, typeBefore, 0, dataBefore);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Logs a block place. The block type before is assumed to be o (air).
|
||||
* @param after Blockstate of the block after actually being placed.
|
||||
@@ -153,7 +151,7 @@ public class Consumer extends TimerTask implements Runnable
|
||||
playerName = playerName.substring(0, 32);
|
||||
if (signtext != null)
|
||||
signtext = signtext.replace("\\", "\\\\").replace("'", "\\'");
|
||||
BlockRow row = new BlockRow(loc.getWorld().getName().hashCode(), playerName, typeBefore, typeAfter, data, loc.getBlockX(), loc.getBlockY(), loc.getBlockZ(), signtext, ca);
|
||||
final BlockRow row = new BlockRow(loc.getWorld().getName().hashCode(), playerName, typeBefore, typeAfter, data, loc.getBlockX(), loc.getBlockY(), loc.getBlockZ(), signtext, ca);
|
||||
if (!bqueue.offer(row))
|
||||
log.info("[LogBlock] Failed to queue block for " + playerName);
|
||||
}
|
||||
@@ -192,7 +190,7 @@ public class Consumer extends TimerTask implements Runnable
|
||||
}
|
||||
|
||||
boolean hide(Player player) {
|
||||
int hash = player.getName().hashCode();
|
||||
final int hash = player.getName().hashCode();
|
||||
if (hiddenplayers.contains(hash)) {
|
||||
hiddenplayers.remove(hash);
|
||||
return false;
|
||||
@@ -202,19 +200,20 @@ public class Consumer extends TimerTask implements Runnable
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public synchronized void run() {
|
||||
Connection conn = logblock.getConnection();
|
||||
final Connection conn = logblock.getConnection();
|
||||
if (conn == null)
|
||||
return;
|
||||
Statement state = null;
|
||||
BlockRow b; KillRow k; String table;
|
||||
int count = 0;
|
||||
if (bqueue.size() > 100)
|
||||
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();
|
||||
long start = System.currentTimeMillis();
|
||||
final long start = System.currentTimeMillis();
|
||||
while (count < 1000 && !bqueue.isEmpty() && (System.currentTimeMillis() - start < 100 || count < 100)) {
|
||||
b = bqueue.poll();
|
||||
if (b == null)
|
||||
@@ -222,13 +221,13 @@ public class Consumer extends TimerTask implements Runnable
|
||||
table = config.tables.get(b.worldHash);
|
||||
state.execute("INSERT INTO `" + table + "` (date, playerid, replaced, type, data, x, y, z) SELECT now(), playerid, " + b.replaced + ", " + b.type + ", " + b.data + ", '" + b.x + "', " + b.y + ", '" + b.z + "' FROM `lb-players` WHERE playername = '" + b.name + "'", Statement.RETURN_GENERATED_KEYS);
|
||||
if (b.signtext != null) {
|
||||
ResultSet keys = state.getGeneratedKeys();
|
||||
final ResultSet keys = state.getGeneratedKeys();
|
||||
if (keys.next())
|
||||
state.execute("INSERT INTO `" + table + "-sign` (id, signtext) values (" + keys.getInt(1) + ", '" + b.signtext + "')");
|
||||
else
|
||||
log.severe("[LogBlock Consumer] Failed to get generated keys");
|
||||
} else if (b.ca != null) {
|
||||
ResultSet keys = state.getGeneratedKeys();
|
||||
final ResultSet keys = state.getGeneratedKeys();
|
||||
if (keys.next())
|
||||
state.execute("INSERT INTO `" + table + "-chest` (id, intype, inamount, outtype, outamount) values (" + keys.getInt(1) + ", " + b.ca.inType + ", " + b.ca.inAmount + ", " + b.ca.outType + ", " + b.ca.outAmount + ")");
|
||||
else
|
||||
@@ -244,7 +243,7 @@ public class Consumer extends TimerTask implements Runnable
|
||||
state.execute("INSERT INTO `" + config.tables.get(k.worldHash) + "-kills` (date, killer, victim, weapon) SELECT now(), playerid, (SELECT playerid FROM `lb-players` WHERE playername = '" + k.victim + "'), " + k.weapon + " FROM `lb-players` WHERE playername = '" + k.killer + "'");
|
||||
}
|
||||
conn.commit();
|
||||
} catch (SQLException ex) {
|
||||
} catch (final SQLException ex) {
|
||||
log.log(Level.SEVERE, "[LogBlock Consumer] SQL exception", ex);
|
||||
} finally {
|
||||
try {
|
||||
@@ -252,7 +251,7 @@ public class Consumer extends TimerTask implements Runnable
|
||||
conn.close();
|
||||
if (state != null)
|
||||
state.close();
|
||||
} catch (SQLException ex) {
|
||||
} catch (final SQLException ex) {
|
||||
log.log(Level.SEVERE, "[LogBlock Consumer] SQL exception on close", ex);
|
||||
}
|
||||
}
|
||||
@@ -312,8 +311,8 @@ public class Consumer extends TimerTask implements Runnable
|
||||
|
||||
KillRow(int worldHash, String attacker, String defender, int weapon) {
|
||||
this.worldHash = worldHash;
|
||||
this.killer = attacker;
|
||||
this.victim = defender;
|
||||
killer = attacker;
|
||||
victim = defender;
|
||||
this.weapon = weapon;
|
||||
}
|
||||
|
||||
@@ -328,7 +327,7 @@ public class Consumer extends TimerTask implements Runnable
|
||||
return true;
|
||||
if (obj == null)
|
||||
return false;
|
||||
KillRow k = (KillRow)obj;
|
||||
final KillRow k = (KillRow)obj;
|
||||
if (!killer.equals(k.killer))
|
||||
return false;
|
||||
if (!victim.equals(k.victim))
|
||||
|
@@ -18,26 +18,31 @@ public class LBBlockListener extends BlockListener
|
||||
consumer = logblock.getConsumer();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onBlockPlace(BlockPlaceEvent event) {
|
||||
if (!event.isCancelled() && !(config.logSignTexts && (event.getBlock().getType() == Material.WALL_SIGN || event.getBlock().getType() == Material.SIGN_POST)))
|
||||
consumer.queueBlock(event.getPlayer().getName(), event.getBlock().getLocation(), event.getBlockReplacedState().getTypeId(), event.getBlockPlaced().getTypeId(), event.getBlockPlaced().getData());
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onBlockBreak(BlockBreakEvent event) {
|
||||
if (!event.isCancelled())
|
||||
consumer.queueBlockBreak(event.getPlayer().getName(), event.getBlock().getState());
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onSignChange(SignChangeEvent event) {
|
||||
if (!event.isCancelled())
|
||||
consumer.queueSign(event.getPlayer().getName(), event.getBlock().getLocation(), event.getBlock().getTypeId(), event.getBlock().getData(), "sign [" + event.getLine(0) + "] [" + event.getLine(1) + "] [" + event.getLine(2) + "] [" + event.getLine(3) + "]");
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onBlockBurn(BlockBurnEvent event) {
|
||||
if (!event.isCancelled())
|
||||
consumer.queueBlockBreak("Fire", event.getBlock().getState());
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onLeavesDecay(LeavesDecayEvent event) {
|
||||
if (!event.isCancelled())
|
||||
consumer.queueBlockBreak("LeavesDecay", event.getBlock().getState());
|
||||
|
@@ -23,27 +23,29 @@ public class LBEntityListener extends EntityListener
|
||||
consumer = logblock.getConsumer();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onEntityExplode(EntityExplodeEvent event) {
|
||||
if (!event.isCancelled()) {
|
||||
String name;
|
||||
if (event.getEntity() instanceof TNTPrimed)
|
||||
name = "TNT";
|
||||
else if (event.getEntity() instanceof Creeper)
|
||||
name = "Creeper";
|
||||
else if (event.getEntity() instanceof Fireball)
|
||||
name = "Ghast";
|
||||
else
|
||||
name = "Environment";
|
||||
for (Block block : event.blockList())
|
||||
consumer.queueBlockBreak(name, block.getState());
|
||||
if (!event.isCancelled()) {
|
||||
String name;
|
||||
if (event.getEntity() instanceof TNTPrimed)
|
||||
name = "TNT";
|
||||
else if (event.getEntity() instanceof Creeper)
|
||||
name = "Creeper";
|
||||
else if (event.getEntity() instanceof Fireball)
|
||||
name = "Ghast";
|
||||
else
|
||||
name = "Environment";
|
||||
for (final Block block : event.blockList())
|
||||
consumer.queueBlockBreak(name, block.getState());
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onEntityDamage(EntityDamageEvent event) {
|
||||
if (event.isCancelled() || !(event instanceof EntityDamageByEntityEvent) || !(event.getEntity() instanceof LivingEntity))
|
||||
return;
|
||||
LivingEntity victim = (LivingEntity)event.getEntity();
|
||||
Entity killer = ((EntityDamageByEntityEvent)event).getDamager();
|
||||
final LivingEntity victim = (LivingEntity)event.getEntity();
|
||||
final Entity killer = ((EntityDamageByEntityEvent)event).getDamager();
|
||||
if (victim.getHealth() - event.getDamage() > 0 || victim.getHealth() <= 0 )
|
||||
return;
|
||||
if (config.logKillsLevel == Config.LogKillsLevel.PLAYERS && !(victim instanceof Player && killer instanceof Player))
|
||||
|
@@ -26,16 +26,19 @@ public class LBPlayerListener extends PlayerListener
|
||||
consumer = logblock.getConsumer();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onPlayerInteract(PlayerInteractEvent event) {
|
||||
if (!event.isCancelled() && event.getAction() == Action.RIGHT_CLICK_BLOCK && (event.getClickedBlock().getType() == Material.CHEST || event.getClickedBlock().getType() == Material.FURNACE ||event.getClickedBlock().getType() == Material.DISPENSER))
|
||||
consumer.queueChestAccess(event.getPlayer().getName(), event.getClickedBlock().getLocation(), event.getClickedBlock().getTypeId(),(short)0, (byte)0, (short)0, (byte)0);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onPlayerBucketFill(PlayerBucketFillEvent event) {
|
||||
if (!event.isCancelled())
|
||||
consumer.queueBlockBreak(event.getPlayer().getName(), event.getBlockClicked().getState());
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onPlayerBucketEmpty(PlayerBucketEmptyEvent event) {
|
||||
if (event.getBucket() == Material.WATER_BUCKET)
|
||||
consumer.queueBlockPlace(event.getPlayer().getName(), event.getBlockClicked().getFace(event.getBlockFace()).getLocation(), 9, (byte)0);
|
||||
@@ -43,15 +46,16 @@ public class LBPlayerListener extends PlayerListener
|
||||
consumer.queueBlockPlace(event.getPlayer().getName(), event.getBlockClicked().getFace(event.getBlockFace()).getLocation(), 11, (byte)0);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onPlayerJoin(PlayerJoinEvent event) {
|
||||
Connection conn = logblock.getConnection();
|
||||
final 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) {
|
||||
} catch (final SQLException ex) {
|
||||
log.log(Level.SEVERE, "[LogBlock] SQL exception", ex);
|
||||
} finally {
|
||||
try {
|
||||
@@ -59,7 +63,7 @@ public class LBPlayerListener extends PlayerListener
|
||||
state.close();
|
||||
if (conn != null)
|
||||
conn.close();
|
||||
} catch (SQLException ex) {
|
||||
} catch (final SQLException ex) {
|
||||
log.log(Level.SEVERE, "[LogBlock] SQL exception on close", ex);
|
||||
}
|
||||
}
|
||||
|
@@ -15,6 +15,7 @@ public class LBToolPlayerListener extends PlayerListener
|
||||
config = logblock.getConfig();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onPlayerInteract(PlayerInteractEvent event) {
|
||||
if (!event.isCancelled()) {
|
||||
if (event.getAction() == Action.RIGHT_CLICK_BLOCK && event.getMaterial().getId() == config.toolID && logblock.checkPermission(event.getPlayer(), "logblock.lookup")) {
|
||||
|
@@ -55,12 +55,12 @@ public class LogBlock extends JavaPlugin
|
||||
log = getServer().getLogger();
|
||||
try {
|
||||
config = new Config(this);
|
||||
} catch (Exception ex) {
|
||||
} catch (final Exception ex) {
|
||||
log.log(Level.SEVERE, "[LogBlock] Exception while reading config:", ex);
|
||||
errorAtLoading = true;
|
||||
return;
|
||||
}
|
||||
File file = new File("lib/mysql-connector-java-bin.jar");
|
||||
final File file = new File("lib/mysql-connector-java-bin.jar");
|
||||
try {
|
||||
if (!file.exists() || file.length() == 0) {
|
||||
log.info("[LogBlock] Downloading " + file.getName() + "...");
|
||||
@@ -68,16 +68,16 @@ public class LogBlock extends JavaPlugin
|
||||
}
|
||||
if (!file.exists() || file.length() == 0)
|
||||
throw new FileNotFoundException(file.getAbsolutePath() + file.getName());
|
||||
} catch (Exception e) {
|
||||
} catch (final Exception e) {
|
||||
log.log(Level.SEVERE, "[LogBlock] Error while downloading " + file.getName() + ".");
|
||||
errorAtLoading = true;
|
||||
return;
|
||||
}
|
||||
try {
|
||||
pool = new ConnectionPool("com.mysql.jdbc.Driver", config.url, config.user, config.password);
|
||||
Connection conn = getConnection();
|
||||
final Connection conn = getConnection();
|
||||
conn.close();
|
||||
} catch (Exception ex) {
|
||||
} catch (final Exception ex) {
|
||||
log.log(Level.SEVERE, "[LogBlock] Exception while checking database connection", ex);
|
||||
errorAtLoading = true;
|
||||
return;
|
||||
@@ -103,10 +103,10 @@ public class LogBlock extends JavaPlugin
|
||||
log.info("[LogBlock] Permissions plugin not found. Using default permissions.");
|
||||
if (config.keepLogDays >= 0)
|
||||
new Thread(new ClearLog(this)).start();
|
||||
LBBlockListener lbBlockListener = new LBBlockListener(this);
|
||||
LBPlayerListener lbPlayerListener = new LBPlayerListener(this);
|
||||
LBEntityListener lbEntityListener = new LBEntityListener(this);
|
||||
PluginManager pm = getServer().getPluginManager();
|
||||
final LBBlockListener lbBlockListener = new LBBlockListener(this);
|
||||
final LBPlayerListener lbPlayerListener = new LBPlayerListener(this);
|
||||
final LBEntityListener lbEntityListener = new LBEntityListener(this);
|
||||
final PluginManager pm = getServer().getPluginManager();
|
||||
pm.registerEvent(Type.PLAYER_INTERACT, new LBToolPlayerListener(this), Priority.Normal, this);
|
||||
pm.registerEvent(Type.PLAYER_JOIN, lbPlayerListener, Priority.Monitor, this);
|
||||
if (config.logBlockCreations) {
|
||||
@@ -121,7 +121,7 @@ public class LogBlock extends JavaPlugin
|
||||
pm.registerEvent(Type.SIGN_CHANGE, lbBlockListener, Priority.Monitor, this);
|
||||
if (config.logFire)
|
||||
pm.registerEvent(Type.BLOCK_BURN, lbBlockListener, Priority.Monitor, this);
|
||||
if (config.logExplosions)
|
||||
if (config.logExplosions)
|
||||
pm.registerEvent(Type.ENTITY_EXPLODE, lbEntityListener, Priority.Monitor, this);
|
||||
if (config.logLeavesDecay)
|
||||
pm.registerEvent(Type.LEAVES_DECAY, lbBlockListener, Priority.Monitor, this);
|
||||
@@ -151,7 +151,7 @@ public class LogBlock extends JavaPlugin
|
||||
timer.cancel();
|
||||
if (consumer != null && consumer.getQueueSize() > 0) {
|
||||
log.info("[LogBlock] Waiting for consumer ...");
|
||||
Thread thread = new Thread(consumer);
|
||||
final Thread thread = new Thread(consumer);
|
||||
while (consumer.getQueueSize() > 0) {
|
||||
log.info("[LogBlock] Remaining queue size: " + consumer.getQueueSize());
|
||||
thread.run();
|
||||
@@ -168,52 +168,52 @@ public class LogBlock extends JavaPlugin
|
||||
sender.sendMessage("You aren't a player");
|
||||
return true;
|
||||
}
|
||||
Player player = (Player)sender;
|
||||
final Player player = (Player)sender;
|
||||
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");
|
||||
} else if (args[0].equalsIgnoreCase("tool")) {
|
||||
if (checkPermission(player, "logblock.tool")) {
|
||||
if (player.getInventory().contains(config.toolID))
|
||||
player.sendMessage(ChatColor.RED + "You have alredy a tool");
|
||||
player.sendMessage(ChatColor.RED + "You have alredy a tool");
|
||||
else {
|
||||
int free = player.getInventory().firstEmpty();
|
||||
final int free = player.getInventory().firstEmpty();
|
||||
if (free >= 0) {
|
||||
player.getInventory().setItem(free, player.getItemInHand());
|
||||
player.setItemInHand(new ItemStack(config.toolID, 1));
|
||||
player.sendMessage(ChatColor.GREEN + "Here is your tool.");
|
||||
player.sendMessage(ChatColor.GREEN + "Here is your tool.");
|
||||
} else
|
||||
player.sendMessage(ChatColor.RED + "You have no empty slot in your inventory");
|
||||
player.sendMessage(ChatColor.RED + "You have no empty slot in your inventory");
|
||||
}
|
||||
} else
|
||||
player.sendMessage(ChatColor.RED + "You aren't allowed to do this.");
|
||||
} else if (args[0].equalsIgnoreCase("toolblock")) {
|
||||
if (checkPermission(player, "logblock.toolblock")) {
|
||||
if (player.getInventory().contains(config.toolblockID))
|
||||
player.sendMessage(ChatColor.RED + "You have alredy a tool");
|
||||
player.sendMessage(ChatColor.RED + "You have alredy a tool");
|
||||
else {
|
||||
int free = player.getInventory().firstEmpty();
|
||||
final int free = player.getInventory().firstEmpty();
|
||||
if (free >= 0) {
|
||||
player.getInventory().setItem(free, player.getItemInHand());
|
||||
player.setItemInHand(new ItemStack(config.toolblockID, 1));
|
||||
player.sendMessage(ChatColor.GREEN + "Here's your tool.");
|
||||
player.sendMessage(ChatColor.GREEN + "Here's your tool.");
|
||||
} else
|
||||
player.sendMessage(ChatColor.RED + "You have no empty slot in your inventory");
|
||||
player.sendMessage(ChatColor.RED + "You have no empty slot in your inventory");
|
||||
}
|
||||
} else
|
||||
player.sendMessage(ChatColor.RED + "You aren't allowed to do this.");
|
||||
} else if (args[0].equalsIgnoreCase("hide")) {
|
||||
if (checkPermission(player, "logblock.hide")) {
|
||||
if (consumer.hide(player))
|
||||
player.sendMessage(ChatColor.GREEN + "You are now hided and won't appear in any log. Type '/lb hide' again to unhide");
|
||||
player.sendMessage(ChatColor.GREEN + "You are now hided and won't appear in any log. Type '/lb hide' again to unhide");
|
||||
else
|
||||
player.sendMessage(ChatColor.GREEN + "You aren't hided anylonger.");
|
||||
player.sendMessage(ChatColor.GREEN + "You aren't hided anylonger.");
|
||||
} else
|
||||
player.sendMessage(ChatColor.RED + "You aren't allowed to do this.");
|
||||
} else if (args[0].equalsIgnoreCase("savequeue")) {
|
||||
if (checkPermission(player, "logblock.rollback")) {
|
||||
player.sendMessage(ChatColor.DARK_AQUA + "Current queue size: " + consumer.getQueueSize());
|
||||
Thread thread = new Thread(consumer);
|
||||
final Thread thread = new Thread(consumer);
|
||||
while (consumer.getQueueSize() > 0) {
|
||||
thread.run();
|
||||
}
|
||||
@@ -240,14 +240,14 @@ public class LogBlock extends JavaPlugin
|
||||
if (args.length == 3 && isInt(args[2]))
|
||||
radius = Integer.parseInt(args[2]);
|
||||
new Thread(new PlayerAreaStats(this, player, args[1], radius)).start();
|
||||
} else
|
||||
player.sendMessage(ChatColor.RED + "Usage: /lb player [name] <radius>");
|
||||
} else
|
||||
player.sendMessage(ChatColor.RED + "Usage: /lb player [name] <radius>");
|
||||
} else
|
||||
player.sendMessage(ChatColor.RED + "You aren't allowed to do this");
|
||||
} else if (args[0].equalsIgnoreCase("block")) {
|
||||
if (checkPermission(player,"logblock.area")) {
|
||||
if (args.length == 2 || args.length == 3) {
|
||||
Material mat = Material.matchMaterial(args[1]);
|
||||
final Material mat = Material.matchMaterial(args[1]);
|
||||
int radius = config.defaultDist;
|
||||
if (args.length == 3 && isInt(args[2]))
|
||||
radius = Integer.parseInt(args[2]);
|
||||
@@ -269,7 +269,7 @@ public class LogBlock extends JavaPlugin
|
||||
minutes = parseTimeSpec(args[3], args[4]);
|
||||
player.sendMessage(ChatColor.GREEN + "Rolling back " + args[2] + " by " + minutes + " minutes.");
|
||||
getServer().getScheduler().scheduleAsyncDelayedTask(this, new Rollback(this, player, args[2], -1, null, minutes, false));
|
||||
} else
|
||||
} else
|
||||
player.sendMessage(ChatColor.RED + "Usage: /lb rollback player [name] <time> <minutes|hours|days>");
|
||||
} else if (args[1].equalsIgnoreCase("area")) {
|
||||
if (args.length == 3 || args.length == 5) {
|
||||
@@ -297,9 +297,9 @@ public class LogBlock extends JavaPlugin
|
||||
if (args.length == 2 || args.length == 4) {
|
||||
if (args.length == 4)
|
||||
minutes = parseTimeSpec(args[2], args[3]);
|
||||
Plugin we = getServer().getPluginManager().getPlugin("WorldEdit");
|
||||
final Plugin we = getServer().getPluginManager().getPlugin("WorldEdit");
|
||||
if (we != null) {
|
||||
Selection sel = ((WorldEditPlugin)we).getSelection(player);
|
||||
final Selection sel = ((WorldEditPlugin)we).getSelection(player);
|
||||
if (sel != null) {
|
||||
if (sel instanceof CuboidSelection) {
|
||||
player.sendMessage(ChatColor.GREEN + "Rolling back selection by " + minutes + " minutes.");
|
||||
@@ -310,7 +310,7 @@ public class LogBlock extends JavaPlugin
|
||||
player.sendMessage(ChatColor.RED + "No selection defined");
|
||||
} else
|
||||
player.sendMessage(ChatColor.RED + "WorldEdit plugin not found");
|
||||
} else
|
||||
} else
|
||||
player.sendMessage(ChatColor.RED + "Usage: /lb rollback selection <time> <minutes|hours|days>");
|
||||
} else
|
||||
player.sendMessage(ChatColor.RED + "Wrong rollback mode");
|
||||
@@ -333,7 +333,7 @@ public class LogBlock extends JavaPlugin
|
||||
minutes = parseTimeSpec(args[3], args[4]);
|
||||
player.sendMessage(ChatColor.GREEN + "Redoing " + args[2] + " for " + minutes + " minutes.");
|
||||
getServer().getScheduler().scheduleAsyncDelayedTask(this, new Rollback(this, player, args[2], -1, null, minutes, true));
|
||||
} else
|
||||
} else
|
||||
player.sendMessage(ChatColor.RED + "Usage: /lb redo player [name] <time> <minutes|hours|days>");
|
||||
} else if (args[1].equalsIgnoreCase("area")) {
|
||||
if (args.length == 3 || args.length == 5) {
|
||||
@@ -361,9 +361,9 @@ public class LogBlock extends JavaPlugin
|
||||
if (args.length == 2 || args.length == 4) {
|
||||
if (args.length == 4)
|
||||
minutes = parseTimeSpec(args[2], args[3]);
|
||||
Plugin we = getServer().getPluginManager().getPlugin("WorldEdit");
|
||||
final Plugin we = getServer().getPluginManager().getPlugin("WorldEdit");
|
||||
if (we != null) {
|
||||
Selection sel = ((WorldEditPlugin)we).getSelection(player);
|
||||
final Selection sel = ((WorldEditPlugin)we).getSelection(player);
|
||||
if (sel != null) {
|
||||
if (sel instanceof CuboidSelection) {
|
||||
player.sendMessage(ChatColor.GREEN + "Redoing selection for " + minutes + " minutes.");
|
||||
@@ -374,7 +374,7 @@ public class LogBlock extends JavaPlugin
|
||||
player.sendMessage(ChatColor.RED + "No selection defined");
|
||||
} else
|
||||
player.sendMessage(ChatColor.RED + "WorldEdit plugin not found");
|
||||
} else
|
||||
} else
|
||||
player.sendMessage(ChatColor.RED + "Usage: /lb redo selection <time> <minutes|hours|days>");
|
||||
} else
|
||||
player.sendMessage(ChatColor.RED + "Wrong redo mode");
|
||||
@@ -424,12 +424,12 @@ public class LogBlock extends JavaPlugin
|
||||
}
|
||||
|
||||
private boolean checkTables() {
|
||||
Connection conn = getConnection();
|
||||
final Connection conn = getConnection();
|
||||
Statement state = null;
|
||||
if (conn == null)
|
||||
return false;
|
||||
try {
|
||||
DatabaseMetaData dbm = conn.getMetaData();
|
||||
final DatabaseMetaData dbm = conn.getMetaData();
|
||||
state = conn.createStatement();
|
||||
if (!dbm.getTables(null, null, "lb-players", null).next()) {
|
||||
log.log(Level.INFO, "[LogBlock] Crating table lb-players.");
|
||||
@@ -438,7 +438,7 @@ public class LogBlock extends JavaPlugin
|
||||
return false;
|
||||
state.execute("INSERT IGNORE INTO `lb-players` (playername) VALUES ('TNT'), ('Creeper'), ('Fire'), ('LeavesDecay'), ('Ghast'), ('Environment')");
|
||||
}
|
||||
for (String table : config.tables.values()) {
|
||||
for (final String table : config.tables.values()) {
|
||||
if (!dbm.getTables(null, null, table, null).next()) {
|
||||
log.log(Level.INFO, "[LogBlock] Crating table " + table + ".");
|
||||
state.execute("CREATE TABLE `" + table + "` (id INT NOT NULL AUTO_INCREMENT, date DATETIME NOT NULL DEFAULT '0000-00-00 00:00:00', playerid SMALLINT UNSIGNED NOT NULL DEFAULT '0', replaced TINYINT UNSIGNED NOT NULL DEFAULT '0', type TINYINT UNSIGNED NOT NULL DEFAULT '0', data TINYINT UNSIGNED NOT NULL DEFAULT '0', x SMALLINT NOT NULL DEFAULT '0', y TINYINT UNSIGNED NOT NULL DEFAULT '0', z SMALLINT NOT NULL DEFAULT '0', PRIMARY KEY (id), KEY coords (y, x, z), KEY date (date));");
|
||||
@@ -463,10 +463,10 @@ public class LogBlock extends JavaPlugin
|
||||
if (!dbm.getTables(null, null, table + "-kills", null).next())
|
||||
return false;
|
||||
state.execute("INSERT IGNORE INTO `lb-players` (playername) VALUES ('Chicken'), ('Cow'), ('Creeper'), ('Ghast'), ('Giant'), ('Pig'), ('PigZombie'), ('Sheep'), ('Skeleton'), ('Slime'), ('Spider'), ('Squid'), ('Wolf'), ('Zombie')");
|
||||
}
|
||||
}
|
||||
}
|
||||
return true;
|
||||
} catch (SQLException ex) {
|
||||
} catch (final SQLException ex) {
|
||||
log.log(Level.SEVERE, "[LogBlock] SQL exception while checking tables", ex);
|
||||
} finally {
|
||||
try {
|
||||
@@ -474,7 +474,7 @@ public class LogBlock extends JavaPlugin
|
||||
state.close();
|
||||
if (conn != null)
|
||||
conn.close();
|
||||
} catch (SQLException ex) {
|
||||
} catch (final SQLException ex) {
|
||||
log.log(Level.SEVERE, "[LogBlock] SQL exception on close", ex);
|
||||
}
|
||||
}
|
||||
@@ -496,7 +496,7 @@ public class LogBlock extends JavaPlugin
|
||||
}
|
||||
|
||||
static int parseTimeSpec(String timespec) {
|
||||
String[] split = timespec.split(" ");
|
||||
final String[] split = timespec.split(" ");
|
||||
if (split.length != 2)
|
||||
return 0;
|
||||
return parseTimeSpec(split[0], split[1]);
|
||||
@@ -506,13 +506,13 @@ public class LogBlock extends JavaPlugin
|
||||
int min;
|
||||
try {
|
||||
min = Integer.parseInt(time);
|
||||
} catch (NumberFormatException ex) {
|
||||
} catch (final NumberFormatException ex) {
|
||||
return 0;
|
||||
}
|
||||
if (unit.startsWith("hour"))
|
||||
min *= 60;
|
||||
else if (unit.startsWith("day"))
|
||||
min *= (60*24);
|
||||
min *= 60*24;
|
||||
return min;
|
||||
}
|
||||
|
||||
@@ -520,15 +520,15 @@ public class LogBlock extends JavaPlugin
|
||||
try {
|
||||
Integer.parseInt(str);
|
||||
return true;
|
||||
} catch (NumberFormatException ex) {
|
||||
} catch (final NumberFormatException ex) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public Connection getConnection() {
|
||||
try {
|
||||
return pool.connect(ConnectionPool.URL_PREFIX, null);
|
||||
} catch (SQLException ex) {
|
||||
} catch (final SQLException ex) {
|
||||
log.log(Level.SEVERE, "[LogBlock] Error while fetching connection", ex);
|
||||
return null;
|
||||
}
|
||||
|
@@ -29,6 +29,7 @@ public class PlayerAreaStats implements Runnable
|
||||
table = logblock.getConfig().tables.get(player.getWorld().getName().hashCode());
|
||||
}
|
||||
|
||||
@Override
|
||||
public void run() {
|
||||
PreparedStatement ps = null;
|
||||
ResultSet rs = null;
|
||||
@@ -64,7 +65,7 @@ public class PlayerAreaStats implements Runnable
|
||||
player.sendMessage(ChatColor.GOLD + String.format("%-6d %-6d %s", rs.getInt("created"), rs.getInt("destroyed"), Material.getMaterial(rs.getInt("type")).toString().toLowerCase().replace('_', ' ')));
|
||||
}
|
||||
}
|
||||
} catch (SQLException ex) {
|
||||
} catch (final SQLException ex) {
|
||||
log.log(Level.SEVERE, "[LogBlock PlayerAreaStats] SQL exception", ex);
|
||||
} finally {
|
||||
try {
|
||||
@@ -74,7 +75,7 @@ public class PlayerAreaStats implements Runnable
|
||||
ps.close();
|
||||
if (conn != null)
|
||||
conn.close();
|
||||
} catch (SQLException ex) {
|
||||
} catch (final SQLException ex) {
|
||||
log.log(Level.SEVERE, "[LogBlock PlayerAreaStats] SQL exception on close", ex);
|
||||
}
|
||||
}
|
||||
|
@@ -31,12 +31,12 @@ public class Rollback implements Runnable
|
||||
log = logblock.getServer().getLogger();
|
||||
conn = logblock.getConnection();
|
||||
config = logblock.getConfig();
|
||||
StringBuffer sql = new StringBuffer();
|
||||
final StringBuffer sql = new StringBuffer();
|
||||
if (!redo)
|
||||
sql.append("SELECT replaced, type, data, x, y, z ");
|
||||
else
|
||||
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 ");
|
||||
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)
|
||||
sql.append("playername = '" + name + "' AND ");
|
||||
if (radius != -1)
|
||||
@@ -53,9 +53,10 @@ public class Rollback implements Runnable
|
||||
query = sql.toString();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void run() {
|
||||
ResultSet rs = null;
|
||||
LinkedBlockingQueue<Edit> edits = new LinkedBlockingQueue<Edit>();
|
||||
final LinkedBlockingQueue<Edit> edits = new LinkedBlockingQueue<Edit>();
|
||||
edits.clear();
|
||||
try {
|
||||
if (!config.tables.containsKey(player.getWorld().getName().hashCode())) {
|
||||
@@ -64,10 +65,10 @@ public class Rollback implements Runnable
|
||||
}
|
||||
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());
|
||||
final 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) {
|
||||
} catch (final SQLException ex) {
|
||||
log.log(Level.SEVERE, "[LogBlock Rollback] SQL exception", ex);
|
||||
player.sendMessage(ChatColor.RED + "Error, check server logs.");
|
||||
return;
|
||||
@@ -77,17 +78,17 @@ public class Rollback implements Runnable
|
||||
rs.close();
|
||||
if (conn != null)
|
||||
conn.close();
|
||||
} catch (SQLException ex) {
|
||||
} catch (final SQLException ex) {
|
||||
log.log(Level.SEVERE, "[LogBlock Rollback] SQL exception on close", ex);
|
||||
player.sendMessage(ChatColor.RED + "Error, check server logs.");
|
||||
return;
|
||||
}
|
||||
}
|
||||
int changes = edits.size();
|
||||
final int changes = edits.size();
|
||||
player.sendMessage(ChatColor.GREEN + "" + changes + " Changes found.");
|
||||
PerformRollback perform = new PerformRollback(edits, this);
|
||||
long start = System.currentTimeMillis();
|
||||
int taskID = logblock.getServer().getScheduler().scheduleSyncRepeatingTask(logblock, perform, 0, 1);
|
||||
final PerformRollback perform = new PerformRollback(edits, this);
|
||||
final long start = System.currentTimeMillis();
|
||||
final int taskID = logblock.getServer().getScheduler().scheduleSyncRepeatingTask(logblock, perform, 0, 1);
|
||||
if (taskID == -1) {
|
||||
player.sendMessage(ChatColor.RED + "Failed to schedule rollback task");
|
||||
return;
|
||||
@@ -95,7 +96,7 @@ public class Rollback implements Runnable
|
||||
synchronized (this) {
|
||||
try {
|
||||
this.wait();
|
||||
} catch (InterruptedException e) {
|
||||
} catch (final InterruptedException e) {
|
||||
log.severe("[LogBlock Rollback] Interrupted");
|
||||
}
|
||||
}
|
||||
@@ -129,15 +130,15 @@ public class Rollback implements Runnable
|
||||
while (!edits.isEmpty() && counter < 1000)
|
||||
{
|
||||
switch (edits.poll().perform()) {
|
||||
case SUCCESS:
|
||||
successes++;
|
||||
break;
|
||||
case ERROR:
|
||||
errors++;
|
||||
break;
|
||||
case BLACKLISTED:
|
||||
blacklisteds++;
|
||||
break;
|
||||
case SUCCESS:
|
||||
successes++;
|
||||
break;
|
||||
case ERROR:
|
||||
errors++;
|
||||
break;
|
||||
case BLACKLISTED:
|
||||
blacklisteds++;
|
||||
break;
|
||||
}
|
||||
counter++;
|
||||
}
|
||||
@@ -152,7 +153,7 @@ public class Rollback implements Runnable
|
||||
private enum PerformResult {
|
||||
ERROR, SUCCESS, BLACKLISTED, NO_ACTION
|
||||
}
|
||||
|
||||
|
||||
private class Edit
|
||||
{
|
||||
final int type, replaced;
|
||||
@@ -174,22 +175,22 @@ public class Rollback implements Runnable
|
||||
if (config.dontRollback.contains(replaced))
|
||||
return PerformResult.BLACKLISTED;
|
||||
try {
|
||||
Block block = world.getBlockAt(x, y, z);
|
||||
final Block block = world.getBlockAt(x, y, z);
|
||||
if (!world.isChunkLoaded(block.getChunk()))
|
||||
world.loadChunk(block.getChunk());
|
||||
if (equalsType(block.getTypeId(), type) || 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
|
||||
return PerformResult.ERROR;
|
||||
} else
|
||||
return PerformResult.NO_ACTION;
|
||||
} catch (Exception ex) {
|
||||
} catch (final Exception ex) {
|
||||
log.severe("[LogBlock Rollback] " + ex.toString());
|
||||
return PerformResult.ERROR;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
private boolean equalsType(int type1, int type2) {
|
||||
if ((type1 == 2 || type1 == 3) && (type2 == 2 || type2 == 3))
|
||||
return true;
|
||||
|
@@ -35,8 +35,8 @@ public class WriteLogFile implements Runnable
|
||||
public void run() {
|
||||
PreparedStatement ps = null;
|
||||
ResultSet rs = null;
|
||||
SimpleDateFormat formatter = new SimpleDateFormat("MM-dd HH:mm:ss");
|
||||
String newline = System.getProperty("line.separator");
|
||||
final SimpleDateFormat formatter = new SimpleDateFormat("MM-dd HH:mm:ss");
|
||||
final String newline = System.getProperty("line.separator");
|
||||
String msg;
|
||||
try {
|
||||
if (conn == null) {
|
||||
@@ -51,14 +51,14 @@ public class WriteLogFile implements Runnable
|
||||
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");
|
||||
final File file = new File ("plugins/LogBlock/log/" + name + ".log");
|
||||
file.getParentFile().mkdirs();
|
||||
FileWriter writer = new FileWriter(file);
|
||||
final FileWriter writer = new FileWriter(file);
|
||||
player.sendMessage(ChatColor.GREEN + "Creating " + file.getName());
|
||||
while (rs.next()) {
|
||||
msg = formatter.format(rs.getTimestamp("date")) + " " + rs.getString("playername") + " ";
|
||||
int type = rs.getInt("type");
|
||||
int replaced = rs.getInt("replaced");
|
||||
final int type = rs.getInt("type");
|
||||
final int replaced = rs.getInt("replaced");
|
||||
if ((type == 63 || type == 68) && rs.getString("signtext") != null)
|
||||
msg += "created " + rs.getString("signtext");
|
||||
else if (type == replaced) {
|
||||
@@ -74,10 +74,10 @@ public class WriteLogFile implements Runnable
|
||||
}
|
||||
writer.close();
|
||||
player.sendMessage(ChatColor.GREEN + "Done");
|
||||
} catch (SQLException ex) {
|
||||
} catch (final SQLException ex) {
|
||||
player.sendMessage(ChatColor.RED + "SQL exception");
|
||||
log.log(Level.SEVERE, "[LogBlock WriteLogFile] SQL exception", ex);
|
||||
} catch (IOException ex) {
|
||||
} catch (final IOException ex) {
|
||||
player.sendMessage(ChatColor.RED + "IO exception");
|
||||
log.log(Level.SEVERE, "[LogBlock WriteLogFile] IO exception", ex);
|
||||
} finally {
|
||||
@@ -88,7 +88,7 @@ public class WriteLogFile implements Runnable
|
||||
ps.close();
|
||||
if (conn != null)
|
||||
conn.close();
|
||||
} catch (SQLException ex) {
|
||||
} catch (final SQLException ex) {
|
||||
log.log(Level.SEVERE, "[LogBlock BlockStats] SQL exception on close", ex);
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user