Removed config static attribute.
This commit is contained in:
1 parent
19ba5a6c61
commit
74bbfd3c8d
9 files changed
+37
-36
No files matched your search
@@ -14,23 +14,24 @@ import org.bukkit.entity.Player;
|
|||||||
|
|
||||||
public class BlockStats implements Runnable
|
public class BlockStats implements Runnable
|
||||||
{
|
{
|
||||||
|
private final LogBlock logblock;
|
||||||
private Player player;
|
private Player player;
|
||||||
private Block block;
|
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.player = player;
|
||||||
this.conn = conn;
|
|
||||||
this.block = block;
|
this.block = block;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void run() {
|
public void run() {
|
||||||
|
Connection conn = logblock.pool.getConnection();
|
||||||
if (conn == null) {
|
if (conn == null) {
|
||||||
player.sendMessage(ChatColor.RED + "Failed to create database connection");
|
player.sendMessage(ChatColor.RED + "Failed to create database connection");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
String table = LogBlock.config.tables.get(block.getWorld().getName().hashCode());
|
String table = logblock.config.tables.get(block.getWorld().getName().hashCode());
|
||||||
if (table == null) {
|
if (table == null) {
|
||||||
player.sendMessage(ChatColor.RED + "This world isn't logged");
|
player.sendMessage(ChatColor.RED + "This world isn't logged");
|
||||||
return;
|
return;
|
||||||
|
|||||||
@@ -10,33 +10,31 @@ import java.util.logging.Level;
|
|||||||
|
|
||||||
public class ClearLog implements Runnable
|
public class ClearLog implements Runnable
|
||||||
{
|
{
|
||||||
private Connection conn;
|
private final LogBlock logblock;
|
||||||
private File dumbFolder;
|
|
||||||
|
|
||||||
public ClearLog(LogBlock logblock) {
|
public ClearLog(LogBlock logblock) {
|
||||||
conn = logblock.pool.getConnection();
|
this.logblock = logblock;
|
||||||
if (conn == null)
|
|
||||||
return;
|
|
||||||
dumbFolder = new File(logblock.getDataFolder(), "dumb");
|
|
||||||
dumbFolder.mkdirs();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void run() {
|
public void run() {
|
||||||
|
File dumpFolder = new File(logblock.getDataFolder(), "dumb");
|
||||||
|
dumpFolder.mkdirs();
|
||||||
|
Connection conn = logblock.pool.getConnection();
|
||||||
if (conn == null)
|
if (conn == null)
|
||||||
return;
|
return;
|
||||||
Statement state = null;
|
Statement state = null;
|
||||||
try {
|
try {
|
||||||
state = conn.createStatement();
|
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;
|
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 = state.executeQuery("SELECT count(*) FROM `" + table + "` WHERE date < '" + time + "'");
|
||||||
rs.next();
|
rs.next();
|
||||||
int deleted = rs.getInt(1);
|
int deleted = rs.getInt(1);
|
||||||
if (deleted > 0) {
|
if (deleted > 0) {
|
||||||
if (LogBlock.config.dumpDeletedLog)
|
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'");
|
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 + "'");
|
state.execute("DELETE FROM `" + table + "` WHERE date < '" + time + "'");
|
||||||
LogBlock.log.info("[LogBlock] Cleared out table " + table + ". Deleted " + deleted + " entries.");
|
LogBlock.log.info("[LogBlock] Cleared out table " + table + ". Deleted " + deleted + " entries.");
|
||||||
}
|
}
|
||||||
@@ -44,8 +42,8 @@ public class ClearLog implements Runnable
|
|||||||
rs.next();
|
rs.next();
|
||||||
deleted = rs.getInt(1);
|
deleted = rs.getInt(1);
|
||||||
if (deleted > 0) {
|
if (deleted > 0) {
|
||||||
if (LogBlock.config.dumpDeletedLog)
|
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'");
|
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;");
|
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.");
|
LogBlock.log.info("[LogBlock] Cleared out table " + table + "-sign. Deleted " + deleted + " entries.");
|
||||||
}
|
}
|
||||||
@@ -53,8 +51,8 @@ public class ClearLog implements Runnable
|
|||||||
rs.next();
|
rs.next();
|
||||||
deleted = rs.getInt(1);
|
deleted = rs.getInt(1);
|
||||||
if (deleted > 0) {
|
if (deleted > 0) {
|
||||||
if (LogBlock.config.dumpDeletedLog)
|
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'");
|
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;");
|
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.");
|
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.block.Block;
|
||||||
import org.bukkit.entity.Entity;
|
import org.bukkit.entity.Entity;
|
||||||
import org.bukkit.entity.Player;
|
import org.bukkit.entity.Player;
|
||||||
|
import org.bukkit.entity.TNTPrimed;
|
||||||
|
|
||||||
public class Consumer extends TimerTask implements Runnable
|
public class Consumer extends TimerTask implements Runnable
|
||||||
{
|
{
|
||||||
@@ -44,7 +45,7 @@ public class Consumer extends TimerTask implements Runnable
|
|||||||
return;
|
return;
|
||||||
if (hiddenplayers.contains(playerName.hashCode()))
|
if (hiddenplayers.contains(playerName.hashCode()))
|
||||||
return;
|
return;
|
||||||
String table = LogBlock.config.tables.get(block.getWorld().getName().hashCode());
|
String table = logblock.config.tables.get(block.getWorld().getName().hashCode());
|
||||||
if (table == null)
|
if (table == null)
|
||||||
return;
|
return;
|
||||||
if (playerName.length() > 32)
|
if (playerName.length() > 32)
|
||||||
@@ -61,7 +62,7 @@ public class Consumer extends TimerTask implements Runnable
|
|||||||
public void queueKill(Entity attacker, Entity defender) {
|
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)
|
if (lastAttackedEntity.containsKey(attacker.getEntityId()) && lastAttackedEntity.get(attacker.getEntityId()) == defender.getEntityId() && System.currentTimeMillis() - lastAttackTime.get(attacker.getEntityId()) < 3000)
|
||||||
return;
|
return;
|
||||||
String table = LogBlock.config.tables.get(defender.getWorld().getName().hashCode());
|
String table = logblock.config.tables.get(defender.getWorld().getName().hashCode());
|
||||||
if (table == null)
|
if (table == null)
|
||||||
return;
|
return;
|
||||||
int weapon = 0;
|
int weapon = 0;
|
||||||
@@ -71,7 +72,6 @@ public class Consumer extends TimerTask implements Runnable
|
|||||||
String defenderName = getEntityName(defender);
|
String defenderName = getEntityName(defender);
|
||||||
if (attackerName == null || defenderName == null)
|
if (attackerName == null || defenderName == null)
|
||||||
return;
|
return;
|
||||||
LogBlock.log.info(attackerName + " killed " + defenderName + " with " + weapon);
|
|
||||||
lastAttackedEntity.put(attacker.getEntityId(), defender.getEntityId());
|
lastAttackedEntity.put(attacker.getEntityId(), defender.getEntityId());
|
||||||
lastAttackTime.put(attacker.getEntityId(), System.currentTimeMillis());
|
lastAttackTime.put(attacker.getEntityId(), System.currentTimeMillis());
|
||||||
kqueue.add(new KillRow(table, getEntityName(attacker), getEntityName(defender), weapon));
|
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) {
|
private String getEntityName(Entity entity) {
|
||||||
if (entity instanceof Player)
|
if (entity instanceof Player)
|
||||||
return ((Player)entity).getName();
|
return ((Player)entity).getName();
|
||||||
|
if (entity instanceof TNTPrimed)
|
||||||
|
return "TNT";
|
||||||
return entity.getClass().getSimpleName().substring(5);
|
return entity.getClass().getSimpleName().substring(5);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -10,14 +10,14 @@ import org.bukkit.event.block.SignChangeEvent;
|
|||||||
|
|
||||||
public class LBBlockListener extends BlockListener
|
public class LBBlockListener extends BlockListener
|
||||||
{
|
{
|
||||||
private LogBlock logblock;
|
private final LogBlock logblock;
|
||||||
|
|
||||||
LBBlockListener(LogBlock logblock) {
|
LBBlockListener(LogBlock logblock) {
|
||||||
this.logblock = logblock;
|
this.logblock = logblock;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void onBlockPlace(BlockPlaceEvent event) {
|
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());
|
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
|
public class LBEntityListener extends EntityListener
|
||||||
{
|
{
|
||||||
private LogBlock logblock;
|
private final LogBlock logblock;
|
||||||
|
|
||||||
LBEntityListener(LogBlock logblock) {
|
LBEntityListener(LogBlock logblock) {
|
||||||
this.logblock = logblock;
|
this.logblock = logblock;
|
||||||
@@ -44,9 +44,9 @@ public class LBEntityListener extends EntityListener
|
|||||||
Entity killer = ((EntityDamageByEntityEvent)event).getDamager();
|
Entity killer = ((EntityDamageByEntityEvent)event).getDamager();
|
||||||
if (victim.getHealth() - event.getDamage() > 0 || victim.getHealth() <= 0 )
|
if (victim.getHealth() - event.getDamage() > 0 || victim.getHealth() <= 0 )
|
||||||
return;
|
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;
|
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;
|
return;
|
||||||
logblock.consumer.queueKill(killer, victim);
|
logblock.consumer.queueKill(killer, victim);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -15,7 +15,7 @@ import org.bukkit.event.player.PlayerListener;
|
|||||||
|
|
||||||
public class LBPlayerListener extends PlayerListener
|
public class LBPlayerListener extends PlayerListener
|
||||||
{
|
{
|
||||||
private LogBlock logblock;
|
private final LogBlock logblock;
|
||||||
|
|
||||||
LBPlayerListener(LogBlock logblock) {
|
LBPlayerListener(LogBlock logblock) {
|
||||||
this.logblock = logblock;
|
this.logblock = logblock;
|
||||||
|
|||||||
@@ -7,7 +7,7 @@ import org.bukkit.event.player.PlayerListener;
|
|||||||
|
|
||||||
public class LBToolPlayerListener extends PlayerListener
|
public class LBToolPlayerListener extends PlayerListener
|
||||||
{
|
{
|
||||||
private LogBlock logblock;
|
private final LogBlock logblock;
|
||||||
|
|
||||||
LBToolPlayerListener(LogBlock logblock) {
|
LBToolPlayerListener(LogBlock logblock) {
|
||||||
this.logblock = logblock;
|
this.logblock = logblock;
|
||||||
@@ -15,12 +15,12 @@ public class LBToolPlayerListener extends PlayerListener
|
|||||||
|
|
||||||
public void onPlayerInteract(PlayerInteractEvent event) {
|
public void onPlayerInteract(PlayerInteractEvent event) {
|
||||||
if (!event.isCancelled()) {
|
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() == logblock.config.toolID && logblock.checkPermission(event.getPlayer(), "logblock.lookup")) {
|
||||||
logblock.getServer().getScheduler().scheduleAsyncDelayedTask(logblock, new BlockStats(logblock.pool.getConnection(), event.getPlayer(), event.getClickedBlock()));
|
logblock.getServer().getScheduler().scheduleAsyncDelayedTask(logblock, new BlockStats(logblock, event.getPlayer(), event.getClickedBlock()));
|
||||||
if (event.getClickedBlock().getType() != Material.BED_BLOCK)
|
if (event.getClickedBlock().getType() != Material.BED_BLOCK)
|
||||||
event.setCancelled(true);
|
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() == 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())));
|
logblock.getServer().getScheduler().scheduleAsyncDelayedTask(logblock, new BlockStats(logblock, event.getPlayer(), event.getClickedBlock().getFace(event.getBlockFace())));
|
||||||
event.setCancelled(true);
|
event.setCancelled(true);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -35,7 +35,7 @@ import de.diddiz.util.Download;
|
|||||||
public class LogBlock extends JavaPlugin
|
public class LogBlock extends JavaPlugin
|
||||||
{
|
{
|
||||||
public static Logger log;
|
public static Logger log;
|
||||||
public static Config config;
|
public Config config;
|
||||||
public ConnectionPool pool;
|
public ConnectionPool pool;
|
||||||
public Consumer consumer = null;
|
public Consumer consumer = null;
|
||||||
private Timer timer = null;
|
private Timer timer = null;
|
||||||
|
|||||||
@@ -160,13 +160,13 @@ public class Rollback implements Runnable
|
|||||||
}
|
}
|
||||||
|
|
||||||
private PerformResult perform() {
|
private PerformResult perform() {
|
||||||
if (LogBlock.config.dontRollback.contains(replaced))
|
if (logblock.config.dontRollback.contains(replaced))
|
||||||
return PerformResult.BLACKLISTED;
|
return PerformResult.BLACKLISTED;
|
||||||
try {
|
try {
|
||||||
Block block = world.getBlockAt(x, y, z);
|
Block block = world.getBlockAt(x, y, z);
|
||||||
if (!world.isChunkLoaded(block.getChunk()))
|
if (!world.isChunkLoaded(block.getChunk()))
|
||||||
world.loadChunk(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))
|
if (block.setTypeIdAndData(replaced, data, false))
|
||||||
return PerformResult.SUCCESS;
|
return PerformResult.SUCCESS;
|
||||||
else
|
else
|
||||||
|
|||||||
Reference in new issue
Block a user