forked from LogBlock/LogBlock
Removed config static attribute.
This commit is contained in:
@@ -14,23 +14,24 @@ import org.bukkit.entity.Player;
|
||||
|
||||
public class BlockStats implements Runnable
|
||||
{
|
||||
private final LogBlock logblock;
|
||||
private Player player;
|
||||
private Block block;
|
||||
private Connection conn;
|
||||
|
||||
BlockStats(Connection conn, Player player, Block block) {
|
||||
BlockStats(LogBlock logblock, Player player, Block block) {
|
||||
this.logblock = logblock;
|
||||
this.player = player;
|
||||
this.conn = conn;
|
||||
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());
|
||||
String table = logblock.config.tables.get(block.getWorld().getName().hashCode());
|
||||
if (table == null) {
|
||||
player.sendMessage(ChatColor.RED + "This world isn't logged");
|
||||
return;
|
||||
|
@@ -10,33 +10,31 @@ import java.util.logging.Level;
|
||||
|
||||
public class ClearLog implements Runnable
|
||||
{
|
||||
private Connection conn;
|
||||
private File dumbFolder;
|
||||
private final LogBlock logblock;
|
||||
|
||||
public ClearLog(LogBlock logblock) {
|
||||
conn = logblock.pool.getConnection();
|
||||
if (conn == null)
|
||||
return;
|
||||
dumbFolder = new File(logblock.getDataFolder(), "dumb");
|
||||
dumbFolder.mkdirs();
|
||||
this.logblock = logblock;
|
||||
}
|
||||
|
||||
@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 {
|
||||
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() - logblock.config.keepLogDays*86400000L);
|
||||
ResultSet rs;
|
||||
for (String table : LogBlock.config.tables.values()) {
|
||||
for (String table : logblock.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)
|
||||
state.execute("SELECT * FROM `" + table + "` WHERE date < '" + time + "' INTO OUTFILE '" + new File(dumbFolder, table + "-" + time + ".csv").getAbsolutePath().replace("\\", "\\\\") + "' FIELDS TERMINATED BY ',' OPTIONALLY ENCLOSED BY '\"' LINES TERMINATED BY '\n'");
|
||||
if (logblock.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.");
|
||||
}
|
||||
@@ -44,8 +42,8 @@ public class ClearLog implements Runnable
|
||||
rs.next();
|
||||
deleted = rs.getInt(1);
|
||||
if (deleted > 0) {
|
||||
if (LogBlock.config.dumpDeletedLog)
|
||||
state.execute("SELECT id, signtext FROM `" + table + "-sign` LEFT JOIN `" + table + "` USING (id) WHERE `" + table + "`.id IS NULL INTO OUTFILE '" + new File(dumbFolder, table + "-sign-" + time + ".csv").getAbsolutePath().replace("\\", "\\\\") + "' FIELDS TERMINATED BY ',' OPTIONALLY ENCLOSED BY '\"' LINES TERMINATED BY '\n'");
|
||||
if (logblock.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.");
|
||||
}
|
||||
@@ -53,8 +51,8 @@ public class ClearLog implements Runnable
|
||||
rs.next();
|
||||
deleted = rs.getInt(1);
|
||||
if (deleted > 0) {
|
||||
if (LogBlock.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(dumbFolder, table + "-chest-" + time + ".csv").getAbsolutePath().replace("\\", "\\\\") + "' FIELDS TERMINATED BY ',' OPTIONALLY ENCLOSED BY '\"' LINES TERMINATED BY '\n'");
|
||||
if (logblock.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.");
|
||||
}
|
||||
|
@@ -13,6 +13,7 @@ import java.util.logging.Level;
|
||||
import org.bukkit.block.Block;
|
||||
import org.bukkit.entity.Entity;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.entity.TNTPrimed;
|
||||
|
||||
public class Consumer extends TimerTask implements Runnable
|
||||
{
|
||||
@@ -44,7 +45,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 = logblock.config.tables.get(block.getWorld().getName().hashCode());
|
||||
if (table == null)
|
||||
return;
|
||||
if (playerName.length() > 32)
|
||||
@@ -61,7 +62,7 @@ public class Consumer extends TimerTask implements Runnable
|
||||
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 = logblock.config.tables.get(defender.getWorld().getName().hashCode());
|
||||
if (table == null)
|
||||
return;
|
||||
int weapon = 0;
|
||||
@@ -71,7 +72,6 @@ public class Consumer extends TimerTask implements Runnable
|
||||
String defenderName = getEntityName(defender);
|
||||
if (attackerName == null || defenderName == null)
|
||||
return;
|
||||
LogBlock.log.info(attackerName + " killed " + defenderName + " with " + weapon);
|
||||
lastAttackedEntity.put(attacker.getEntityId(), defender.getEntityId());
|
||||
lastAttackTime.put(attacker.getEntityId(), System.currentTimeMillis());
|
||||
kqueue.add(new KillRow(table, getEntityName(attacker), getEntityName(defender), weapon));
|
||||
@@ -150,6 +150,8 @@ public class Consumer extends TimerTask implements Runnable
|
||||
private String getEntityName(Entity entity) {
|
||||
if (entity instanceof Player)
|
||||
return ((Player)entity).getName();
|
||||
if (entity instanceof TNTPrimed)
|
||||
return "TNT";
|
||||
return entity.getClass().getSimpleName().substring(5);
|
||||
}
|
||||
|
||||
|
@@ -10,14 +10,14 @@ import org.bukkit.event.block.SignChangeEvent;
|
||||
|
||||
public class LBBlockListener extends BlockListener
|
||||
{
|
||||
private LogBlock logblock;
|
||||
private final LogBlock logblock;
|
||||
|
||||
LBBlockListener(LogBlock logblock) {
|
||||
this.logblock = logblock;
|
||||
}
|
||||
|
||||
public void onBlockPlace(BlockPlaceEvent event) {
|
||||
if (!event.isCancelled() && !(LogBlock.config.logSignTexts && (event.getBlock().getType() == Material.WALL_SIGN || event.getBlock().getType() == Material.SIGN_POST))) {
|
||||
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());
|
||||
}
|
||||
}
|
||||
|
@@ -15,7 +15,7 @@ import org.bukkit.event.entity.EntityListener;
|
||||
|
||||
public class LBEntityListener extends EntityListener
|
||||
{
|
||||
private LogBlock logblock;
|
||||
private final LogBlock logblock;
|
||||
|
||||
LBEntityListener(LogBlock logblock) {
|
||||
this.logblock = logblock;
|
||||
@@ -44,9 +44,9 @@ 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 (logblock.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 (logblock.config.logKillsLevel == Config.LogKillsLevel.MONSTERS && !((victim instanceof Player || victim instanceof Monster) && killer instanceof Player || killer instanceof Monster))
|
||||
return;
|
||||
logblock.consumer.queueKill(killer, victim);
|
||||
}
|
||||
|
@@ -15,7 +15,7 @@ import org.bukkit.event.player.PlayerListener;
|
||||
|
||||
public class LBPlayerListener extends PlayerListener
|
||||
{
|
||||
private LogBlock logblock;
|
||||
private final LogBlock logblock;
|
||||
|
||||
LBPlayerListener(LogBlock logblock) {
|
||||
this.logblock = logblock;
|
||||
|
@@ -7,7 +7,7 @@ import org.bukkit.event.player.PlayerListener;
|
||||
|
||||
public class LBToolPlayerListener extends PlayerListener
|
||||
{
|
||||
private LogBlock logblock;
|
||||
private final LogBlock logblock;
|
||||
|
||||
LBToolPlayerListener(LogBlock logblock) {
|
||||
this.logblock = logblock;
|
||||
@@ -15,12 +15,12 @@ public class LBToolPlayerListener extends PlayerListener
|
||||
|
||||
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")) {
|
||||
logblock.getServer().getScheduler().scheduleAsyncDelayedTask(logblock, new BlockStats(logblock.pool.getConnection(), event.getPlayer(), event.getClickedBlock()));
|
||||
if (event.getAction() == Action.RIGHT_CLICK_BLOCK && event.getMaterial().getId() == logblock.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")) {
|
||||
logblock.getServer().getScheduler().scheduleAsyncDelayedTask(logblock, new BlockStats(logblock.pool.getConnection(), event.getPlayer(), event.getClickedBlock().getFace(event.getBlockFace())));
|
||||
} else if (event.getAction() == Action.RIGHT_CLICK_BLOCK && event.getMaterial().getId() == logblock.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);
|
||||
}
|
||||
}
|
||||
|
@@ -35,7 +35,7 @@ import de.diddiz.util.Download;
|
||||
public class LogBlock extends JavaPlugin
|
||||
{
|
||||
public static Logger log;
|
||||
public static Config config;
|
||||
public Config config;
|
||||
public ConnectionPool pool;
|
||||
public Consumer consumer = null;
|
||||
private Timer timer = null;
|
||||
|
@@ -160,13 +160,13 @@ public class Rollback implements Runnable
|
||||
}
|
||||
|
||||
private PerformResult perform() {
|
||||
if (LogBlock.config.dontRollback.contains(replaced))
|
||||
if (logblock.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) || logblock.config.replaceAnyway.contains(block.getTypeId()) || (type == 0 && replaced == 0)) {
|
||||
if (block.setTypeIdAndData(replaced, data, false))
|
||||
return PerformResult.SUCCESS;
|
||||
else
|
||||
|
Reference in New Issue
Block a user