forked from LogBlock/LogBlock
Ensure formatting is consistant across all files.
This commit is contained in:
@@ -30,11 +30,11 @@ import java.util.logging.Level;
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.World;
|
||||
import org.bukkit.block.BlockState;
|
||||
import org.bukkit.inventory.InventoryHolder;
|
||||
import org.bukkit.block.Sign;
|
||||
import org.bukkit.entity.Entity;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.inventory.Inventory;
|
||||
import org.bukkit.inventory.InventoryHolder;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
|
||||
public class Consumer extends TimerTask
|
||||
@@ -49,7 +49,8 @@ public class Consumer extends TimerTask
|
||||
this.logblock = logblock;
|
||||
try {
|
||||
Class.forName("PlayerLeaveRow");
|
||||
} catch (final ClassNotFoundException ex) {}
|
||||
} catch (final ClassNotFoundException ex) {
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -274,7 +275,8 @@ public class Consumer extends TimerTask
|
||||
state = conn.createStatement();
|
||||
final long start = System.currentTimeMillis();
|
||||
int count = 0;
|
||||
process: while (!queue.isEmpty() && (System.currentTimeMillis() - start < timePerRun || count < forceToProcessAtLeast)) {
|
||||
process:
|
||||
while (!queue.isEmpty() && (System.currentTimeMillis() - start < timePerRun || count < forceToProcessAtLeast)) {
|
||||
final Row r = queue.poll();
|
||||
if (r == null)
|
||||
continue;
|
||||
|
@@ -62,7 +62,8 @@ public class DumpedLogImporter implements Runnable
|
||||
if (conn != null)
|
||||
try {
|
||||
conn.close();
|
||||
} catch (final SQLException ex) {}
|
||||
} catch (final SQLException ex) {
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@@ -56,255 +56,255 @@ import de.diddiz.util.MySQLConnectionPool;
|
||||
|
||||
public class LogBlock extends JavaPlugin
|
||||
{
|
||||
private static LogBlock logblock = null;
|
||||
private MySQLConnectionPool pool;
|
||||
private Consumer consumer = null;
|
||||
private CommandsHandler commandsHandler;
|
||||
private Updater updater = null;
|
||||
private Timer timer = null;
|
||||
private boolean errorAtLoading = false, noDb = false, connected = true;
|
||||
private static LogBlock logblock = null;
|
||||
private MySQLConnectionPool pool;
|
||||
private Consumer consumer = null;
|
||||
private CommandsHandler commandsHandler;
|
||||
private Updater updater = null;
|
||||
private Timer timer = null;
|
||||
private boolean errorAtLoading = false, noDb = false, connected = true;
|
||||
|
||||
public static LogBlock getInstance() {
|
||||
return logblock;
|
||||
}
|
||||
public static LogBlock getInstance() {
|
||||
return logblock;
|
||||
}
|
||||
|
||||
public Consumer getConsumer() {
|
||||
return consumer;
|
||||
}
|
||||
public Consumer getConsumer() {
|
||||
return consumer;
|
||||
}
|
||||
|
||||
public CommandsHandler getCommandsHandler() {
|
||||
return commandsHandler;
|
||||
}
|
||||
public CommandsHandler getCommandsHandler() {
|
||||
return commandsHandler;
|
||||
}
|
||||
|
||||
Updater getUpdater() {
|
||||
return updater;
|
||||
}
|
||||
Updater getUpdater() {
|
||||
return updater;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onLoad() {
|
||||
logblock = this;
|
||||
try {
|
||||
updater = new Updater(this);
|
||||
Config.load(this);
|
||||
if (checkVersion)
|
||||
getLogger().info("[LogBlock] Version check: " + updater.checkVersion());
|
||||
getLogger().info("[LogBlock] Connecting to " + user + "@" + url + "...");
|
||||
pool = new MySQLConnectionPool(url, user, password);
|
||||
final Connection conn = getConnection();
|
||||
if (conn == null) {
|
||||
noDb = true;
|
||||
return;
|
||||
}
|
||||
conn.close();
|
||||
if (updater.update())
|
||||
load(this);
|
||||
updater.checkTables();
|
||||
} catch (final NullPointerException ex) {
|
||||
getLogger().log(Level.SEVERE, "[LogBlock] Error while loading: ", ex);
|
||||
} catch (final Exception ex) {
|
||||
getLogger().severe("[LogBlock] Error while loading: " + ex.getMessage());
|
||||
errorAtLoading = true;
|
||||
return;
|
||||
}
|
||||
consumer = new Consumer(this);
|
||||
}
|
||||
@Override
|
||||
public void onLoad() {
|
||||
logblock = this;
|
||||
try {
|
||||
updater = new Updater(this);
|
||||
Config.load(this);
|
||||
if (checkVersion)
|
||||
getLogger().info("[LogBlock] Version check: " + updater.checkVersion());
|
||||
getLogger().info("[LogBlock] Connecting to " + user + "@" + url + "...");
|
||||
pool = new MySQLConnectionPool(url, user, password);
|
||||
final Connection conn = getConnection();
|
||||
if (conn == null) {
|
||||
noDb = true;
|
||||
return;
|
||||
}
|
||||
conn.close();
|
||||
if (updater.update())
|
||||
load(this);
|
||||
updater.checkTables();
|
||||
} catch (final NullPointerException ex) {
|
||||
getLogger().log(Level.SEVERE, "[LogBlock] Error while loading: ", ex);
|
||||
} catch (final Exception ex) {
|
||||
getLogger().severe("[LogBlock] Error while loading: " + ex.getMessage());
|
||||
errorAtLoading = true;
|
||||
return;
|
||||
}
|
||||
consumer = new Consumer(this);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onEnable() {
|
||||
final PluginManager pm = getPluginManager();
|
||||
if (errorAtLoading) {
|
||||
pm.disablePlugin(this);
|
||||
return;
|
||||
}
|
||||
if (noDb)
|
||||
return;
|
||||
if (pm.getPlugin("WorldEdit") == null && !new File("lib/WorldEdit.jar").exists() && !new File("WorldEdit.jar").exists())
|
||||
try {
|
||||
download(getLogger(), new URL("http://diddiz.insane-architects.net/download/WorldEdit.jar"), new File("lib/WorldEdit.jar"));
|
||||
getLogger().info("[LogBlock] You've to restart/reload your server now.");
|
||||
pm.disablePlugin(this);
|
||||
return;
|
||||
} catch (final Exception ex) {
|
||||
getLogger().warning("[LogBlock] Failed to download WorldEdit. You may have to download it manually. You don't have to install it, just place the jar in the lib folder.");
|
||||
}
|
||||
commandsHandler = new CommandsHandler(this);
|
||||
getCommand("lb").setExecutor(commandsHandler);
|
||||
getLogger().info("[LogBlock] Permissions plugin not found. Using Bukkit Permissions.");
|
||||
if (enableAutoClearLog && autoClearLogDelay > 0)
|
||||
getServer().getScheduler().scheduleAsyncRepeatingTask(this, new AutoClearLog(this), 6000, autoClearLogDelay * 60 * 20);
|
||||
getServer().getScheduler().scheduleAsyncDelayedTask(this, new DumpedLogImporter(this));
|
||||
registerEvents();
|
||||
if (useBukkitScheduler) {
|
||||
if (getServer().getScheduler().scheduleAsyncRepeatingTask(this, consumer, delayBetweenRuns * 20, delayBetweenRuns * 20) > 0)
|
||||
getLogger().info("[LogBlock] Scheduled consumer with bukkit scheduler.");
|
||||
else {
|
||||
getLogger().warning("[LogBlock] Failed to schedule consumer with bukkit scheduler. Now trying schedule with timer.");
|
||||
timer = new Timer();
|
||||
timer.scheduleAtFixedRate(consumer, delayBetweenRuns * 1000, delayBetweenRuns * 1000);
|
||||
}
|
||||
} else {
|
||||
timer = new Timer();
|
||||
timer.scheduleAtFixedRate(consumer, delayBetweenRuns * 1000, delayBetweenRuns * 1000);
|
||||
getLogger().info("[LogBlock] Scheduled consumer with timer.");
|
||||
}
|
||||
for (final Tool tool : toolsByType.values())
|
||||
if (pm.getPermission("logblock.tools." + tool.name) == null) {
|
||||
final Permission perm = new Permission("logblock.tools." + tool.name, tool.permissionDefault);
|
||||
pm.addPermission(perm);
|
||||
}
|
||||
// perm.addParent("logblock.*", true);
|
||||
getLogger().info("LogBlock v" + getDescription().getVersion() + " by DiddiZ enabled.");
|
||||
}
|
||||
@Override
|
||||
public void onEnable() {
|
||||
final PluginManager pm = getPluginManager();
|
||||
if (errorAtLoading) {
|
||||
pm.disablePlugin(this);
|
||||
return;
|
||||
}
|
||||
if (noDb)
|
||||
return;
|
||||
if (pm.getPlugin("WorldEdit") == null && !new File("lib/WorldEdit.jar").exists() && !new File("WorldEdit.jar").exists())
|
||||
try {
|
||||
download(getLogger(), new URL("http://diddiz.insane-architects.net/download/WorldEdit.jar"), new File("lib/WorldEdit.jar"));
|
||||
getLogger().info("[LogBlock] You've to restart/reload your server now.");
|
||||
pm.disablePlugin(this);
|
||||
return;
|
||||
} catch (final Exception ex) {
|
||||
getLogger().warning("[LogBlock] Failed to download WorldEdit. You may have to download it manually. You don't have to install it, just place the jar in the lib folder.");
|
||||
}
|
||||
commandsHandler = new CommandsHandler(this);
|
||||
getCommand("lb").setExecutor(commandsHandler);
|
||||
getLogger().info("[LogBlock] Permissions plugin not found. Using Bukkit Permissions.");
|
||||
if (enableAutoClearLog && autoClearLogDelay > 0)
|
||||
getServer().getScheduler().scheduleAsyncRepeatingTask(this, new AutoClearLog(this), 6000, autoClearLogDelay * 60 * 20);
|
||||
getServer().getScheduler().scheduleAsyncDelayedTask(this, new DumpedLogImporter(this));
|
||||
registerEvents();
|
||||
if (useBukkitScheduler) {
|
||||
if (getServer().getScheduler().scheduleAsyncRepeatingTask(this, consumer, delayBetweenRuns * 20, delayBetweenRuns * 20) > 0)
|
||||
getLogger().info("[LogBlock] Scheduled consumer with bukkit scheduler.");
|
||||
else {
|
||||
getLogger().warning("[LogBlock] Failed to schedule consumer with bukkit scheduler. Now trying schedule with timer.");
|
||||
timer = new Timer();
|
||||
timer.scheduleAtFixedRate(consumer, delayBetweenRuns * 1000, delayBetweenRuns * 1000);
|
||||
}
|
||||
} else {
|
||||
timer = new Timer();
|
||||
timer.scheduleAtFixedRate(consumer, delayBetweenRuns * 1000, delayBetweenRuns * 1000);
|
||||
getLogger().info("[LogBlock] Scheduled consumer with timer.");
|
||||
}
|
||||
for (final Tool tool : toolsByType.values())
|
||||
if (pm.getPermission("logblock.tools." + tool.name) == null) {
|
||||
final Permission perm = new Permission("logblock.tools." + tool.name, tool.permissionDefault);
|
||||
pm.addPermission(perm);
|
||||
}
|
||||
// perm.addParent("logblock.*", true);
|
||||
getLogger().info("LogBlock v" + getDescription().getVersion() + " by DiddiZ enabled.");
|
||||
}
|
||||
|
||||
public void reload() {
|
||||
// TODO
|
||||
}
|
||||
public void reload() {
|
||||
// TODO
|
||||
}
|
||||
|
||||
private void registerEvents() {
|
||||
final PluginManager pm = getPluginManager();
|
||||
pm.registerEvents(new ToolListener(this), this);
|
||||
if (askRollbackAfterBan)
|
||||
pm.registerEvents(new BanListener(this), this);
|
||||
if (isLogging(Logging.BLOCKPLACE))
|
||||
pm.registerEvents(new BlockPlaceLogging(this), this);
|
||||
if (isLogging(Logging.BLOCKPLACE) || isLogging(Logging.LAVAFLOW) || isLogging(Logging.WATERFLOW))
|
||||
pm.registerEvents(new FluidFlowLogging(this), this);
|
||||
if (isLogging(Logging.BLOCKBREAK))
|
||||
pm.registerEvents(new BlockBreakLogging(this), this);
|
||||
if (isLogging(Logging.SIGNTEXT))
|
||||
pm.registerEvents(new SignChangeLogging(this), this);
|
||||
if (isLogging(Logging.FIRE))
|
||||
pm.registerEvents(new BlockBurnLogging(this), this);
|
||||
if (isLogging(Logging.SNOWFORM))
|
||||
pm.registerEvents(new SnowFormLogging(this), this);
|
||||
if (isLogging(Logging.SNOWFADE))
|
||||
pm.registerEvents(new SnowFadeLogging(this), this);
|
||||
if (isLogging(Logging.CREEPEREXPLOSION) || isLogging(Logging.TNTEXPLOSION) || isLogging(Logging.GHASTFIREBALLEXPLOSION) || isLogging(Logging.ENDERDRAGON) || isLogging(Logging.MISCEXPLOSION))
|
||||
pm.registerEvents(new ExplosionLogging(this), this);
|
||||
if (isLogging(Logging.LEAVESDECAY))
|
||||
pm.registerEvents(new LeavesDecayLogging(this), this);
|
||||
if (isLogging(Logging.CHESTACCESS)) {
|
||||
pm.registerEvents(new ChestAccessLogging(this), this);
|
||||
}
|
||||
if (isLogging(Logging.SWITCHINTERACT) || isLogging(Logging.DOORINTERACT) || isLogging(Logging.CAKEEAT) || isLogging(Logging.DIODEINTERACT) || isLogging(Logging.NOTEBLOCKINTERACT))
|
||||
pm.registerEvents(new InteractLogging(this), this);
|
||||
if (isLogging(Logging.KILL))
|
||||
pm.registerEvents(new KillLogging(this), this);
|
||||
if (isLogging(Logging.CHAT))
|
||||
pm.registerEvents(new ChatLogging(this), this);
|
||||
if (isLogging(Logging.ENDERMEN))
|
||||
pm.registerEvents(new EndermenLogging(this), this);
|
||||
if (isLogging(Logging.NATURALSTRUCTUREGROW) || isLogging(Logging.BONEMEALSTRUCTUREGROW))
|
||||
pm.registerEvents(new StructureGrowLogging(this), this);
|
||||
if (logPlayerInfo)
|
||||
pm.registerEvents(new PlayerInfoLogging(this), this);
|
||||
}
|
||||
private void registerEvents() {
|
||||
final PluginManager pm = getPluginManager();
|
||||
pm.registerEvents(new ToolListener(this), this);
|
||||
if (askRollbackAfterBan)
|
||||
pm.registerEvents(new BanListener(this), this);
|
||||
if (isLogging(Logging.BLOCKPLACE))
|
||||
pm.registerEvents(new BlockPlaceLogging(this), this);
|
||||
if (isLogging(Logging.BLOCKPLACE) || isLogging(Logging.LAVAFLOW) || isLogging(Logging.WATERFLOW))
|
||||
pm.registerEvents(new FluidFlowLogging(this), this);
|
||||
if (isLogging(Logging.BLOCKBREAK))
|
||||
pm.registerEvents(new BlockBreakLogging(this), this);
|
||||
if (isLogging(Logging.SIGNTEXT))
|
||||
pm.registerEvents(new SignChangeLogging(this), this);
|
||||
if (isLogging(Logging.FIRE))
|
||||
pm.registerEvents(new BlockBurnLogging(this), this);
|
||||
if (isLogging(Logging.SNOWFORM))
|
||||
pm.registerEvents(new SnowFormLogging(this), this);
|
||||
if (isLogging(Logging.SNOWFADE))
|
||||
pm.registerEvents(new SnowFadeLogging(this), this);
|
||||
if (isLogging(Logging.CREEPEREXPLOSION) || isLogging(Logging.TNTEXPLOSION) || isLogging(Logging.GHASTFIREBALLEXPLOSION) || isLogging(Logging.ENDERDRAGON) || isLogging(Logging.MISCEXPLOSION))
|
||||
pm.registerEvents(new ExplosionLogging(this), this);
|
||||
if (isLogging(Logging.LEAVESDECAY))
|
||||
pm.registerEvents(new LeavesDecayLogging(this), this);
|
||||
if (isLogging(Logging.CHESTACCESS)) {
|
||||
pm.registerEvents(new ChestAccessLogging(this), this);
|
||||
}
|
||||
if (isLogging(Logging.SWITCHINTERACT) || isLogging(Logging.DOORINTERACT) || isLogging(Logging.CAKEEAT) || isLogging(Logging.DIODEINTERACT) || isLogging(Logging.NOTEBLOCKINTERACT))
|
||||
pm.registerEvents(new InteractLogging(this), this);
|
||||
if (isLogging(Logging.KILL))
|
||||
pm.registerEvents(new KillLogging(this), this);
|
||||
if (isLogging(Logging.CHAT))
|
||||
pm.registerEvents(new ChatLogging(this), this);
|
||||
if (isLogging(Logging.ENDERMEN))
|
||||
pm.registerEvents(new EndermenLogging(this), this);
|
||||
if (isLogging(Logging.NATURALSTRUCTUREGROW) || isLogging(Logging.BONEMEALSTRUCTUREGROW))
|
||||
pm.registerEvents(new StructureGrowLogging(this), this);
|
||||
if (logPlayerInfo)
|
||||
pm.registerEvents(new PlayerInfoLogging(this), this);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onDisable() {
|
||||
if (timer != null)
|
||||
timer.cancel();
|
||||
getServer().getScheduler().cancelTasks(this);
|
||||
if (consumer != null) {
|
||||
if (logPlayerInfo && getServer().getOnlinePlayers() != null)
|
||||
for (final Player player : getServer().getOnlinePlayers())
|
||||
consumer.queueLeave(player);
|
||||
if (consumer.getQueueSize() > 0) {
|
||||
getLogger().info("[LogBlock] Waiting for consumer ...");
|
||||
int tries = 10;
|
||||
while (consumer.getQueueSize() > 0) {
|
||||
getLogger().info("[LogBlock] Remaining queue size: " + consumer.getQueueSize());
|
||||
if (tries > 0)
|
||||
getLogger().info("[LogBlock] Remaining tries: " + tries);
|
||||
else {
|
||||
getLogger().info("Unable to save queue to database. Trying to write to a local file.");
|
||||
try {
|
||||
consumer.writeToFile();
|
||||
getLogger().info("Successfully dumped queue.");
|
||||
} catch (final FileNotFoundException ex) {
|
||||
getLogger().info("Failed to write. Given up.");
|
||||
break;
|
||||
}
|
||||
}
|
||||
consumer.run();
|
||||
tries--;
|
||||
}
|
||||
}
|
||||
}
|
||||
if (pool != null)
|
||||
pool.close();
|
||||
getLogger().info("LogBlock disabled.");
|
||||
}
|
||||
@Override
|
||||
public void onDisable() {
|
||||
if (timer != null)
|
||||
timer.cancel();
|
||||
getServer().getScheduler().cancelTasks(this);
|
||||
if (consumer != null) {
|
||||
if (logPlayerInfo && getServer().getOnlinePlayers() != null)
|
||||
for (final Player player : getServer().getOnlinePlayers())
|
||||
consumer.queueLeave(player);
|
||||
if (consumer.getQueueSize() > 0) {
|
||||
getLogger().info("[LogBlock] Waiting for consumer ...");
|
||||
int tries = 10;
|
||||
while (consumer.getQueueSize() > 0) {
|
||||
getLogger().info("[LogBlock] Remaining queue size: " + consumer.getQueueSize());
|
||||
if (tries > 0)
|
||||
getLogger().info("[LogBlock] Remaining tries: " + tries);
|
||||
else {
|
||||
getLogger().info("Unable to save queue to database. Trying to write to a local file.");
|
||||
try {
|
||||
consumer.writeToFile();
|
||||
getLogger().info("Successfully dumped queue.");
|
||||
} catch (final FileNotFoundException ex) {
|
||||
getLogger().info("Failed to write. Given up.");
|
||||
break;
|
||||
}
|
||||
}
|
||||
consumer.run();
|
||||
tries--;
|
||||
}
|
||||
}
|
||||
}
|
||||
if (pool != null)
|
||||
pool.close();
|
||||
getLogger().info("LogBlock disabled.");
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean onCommand(CommandSender sender, Command cmd, String commandLabel, String[] args) {
|
||||
if (noDb)
|
||||
sender.sendMessage(ChatColor.RED + "No database connected. Check your MySQL user/pw and database for typos. Start/restart your MySQL server.");
|
||||
return true;
|
||||
}
|
||||
@Override
|
||||
public boolean onCommand(CommandSender sender, Command cmd, String commandLabel, String[] args) {
|
||||
if (noDb)
|
||||
sender.sendMessage(ChatColor.RED + "No database connected. Check your MySQL user/pw and database for typos. Start/restart your MySQL server.");
|
||||
return true;
|
||||
}
|
||||
|
||||
public boolean hasPermission(CommandSender sender, String permission) {
|
||||
return sender.hasPermission(permission);
|
||||
}
|
||||
public boolean hasPermission(CommandSender sender, String permission) {
|
||||
return sender.hasPermission(permission);
|
||||
}
|
||||
|
||||
public Connection getConnection() {
|
||||
try {
|
||||
final Connection conn = pool.getConnection();
|
||||
if (!connected) {
|
||||
getLogger().info("[LogBlock] MySQL connection rebuild");
|
||||
connected = true;
|
||||
}
|
||||
return conn;
|
||||
} catch (final Exception ex) {
|
||||
if (connected) {
|
||||
getLogger().log(Level.SEVERE, "[LogBlock] Error while fetching connection: ", ex);
|
||||
connected = false;
|
||||
} else
|
||||
getLogger().severe("[LogBlock] MySQL connection lost");
|
||||
return null;
|
||||
}
|
||||
}
|
||||
public Connection getConnection() {
|
||||
try {
|
||||
final Connection conn = pool.getConnection();
|
||||
if (!connected) {
|
||||
getLogger().info("[LogBlock] MySQL connection rebuild");
|
||||
connected = true;
|
||||
}
|
||||
return conn;
|
||||
} catch (final Exception ex) {
|
||||
if (connected) {
|
||||
getLogger().log(Level.SEVERE, "[LogBlock] Error while fetching connection: ", ex);
|
||||
connected = false;
|
||||
} else
|
||||
getLogger().severe("[LogBlock] MySQL connection lost");
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @param params
|
||||
* QueryParams that contains the needed columns (all other will be filled with default values) and the params. World is required.
|
||||
*/
|
||||
public List<BlockChange> getBlockChanges(QueryParams params) throws SQLException {
|
||||
final Connection conn = getConnection();
|
||||
Statement state = null;
|
||||
if (conn == null)
|
||||
throw new SQLException("No connection");
|
||||
try {
|
||||
state = conn.createStatement();
|
||||
final ResultSet rs = state.executeQuery(params.getQuery());
|
||||
final List<BlockChange> blockchanges = new ArrayList<BlockChange>();
|
||||
while (rs.next())
|
||||
blockchanges.add(new BlockChange(rs, params));
|
||||
return blockchanges;
|
||||
} finally {
|
||||
if (state != null)
|
||||
state.close();
|
||||
conn.close();
|
||||
}
|
||||
}
|
||||
/**
|
||||
* @param params
|
||||
* QueryParams that contains the needed columns (all other will be filled with default values) and the params. World is required.
|
||||
*/
|
||||
public List<BlockChange> getBlockChanges(QueryParams params) throws SQLException {
|
||||
final Connection conn = getConnection();
|
||||
Statement state = null;
|
||||
if (conn == null)
|
||||
throw new SQLException("No connection");
|
||||
try {
|
||||
state = conn.createStatement();
|
||||
final ResultSet rs = state.executeQuery(params.getQuery());
|
||||
final List<BlockChange> blockchanges = new ArrayList<BlockChange>();
|
||||
while (rs.next())
|
||||
blockchanges.add(new BlockChange(rs, params));
|
||||
return blockchanges;
|
||||
} finally {
|
||||
if (state != null)
|
||||
state.close();
|
||||
conn.close();
|
||||
}
|
||||
}
|
||||
|
||||
public int getCount(QueryParams params) throws SQLException {
|
||||
final Connection conn = getConnection();
|
||||
Statement state = null;
|
||||
if (conn == null)
|
||||
throw new SQLException("No connection");
|
||||
try {
|
||||
state = conn.createStatement();
|
||||
final QueryParams p = params.clone();
|
||||
p.needCount = true;
|
||||
final ResultSet rs = state.executeQuery(p.getQuery());
|
||||
if (!rs.next())
|
||||
return 0;
|
||||
return rs.getInt(1);
|
||||
} finally {
|
||||
if (state != null)
|
||||
state.close();
|
||||
conn.close();
|
||||
}
|
||||
}
|
||||
public int getCount(QueryParams params) throws SQLException {
|
||||
final Connection conn = getConnection();
|
||||
Statement state = null;
|
||||
if (conn == null)
|
||||
throw new SQLException("No connection");
|
||||
try {
|
||||
state = conn.createStatement();
|
||||
final QueryParams p = params.clone();
|
||||
p.needCount = true;
|
||||
final ResultSet rs = state.executeQuery(p.getQuery());
|
||||
if (!rs.next())
|
||||
return 0;
|
||||
return rs.getInt(1);
|
||||
} finally {
|
||||
if (state != null)
|
||||
state.close();
|
||||
conn.close();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@@ -1,10 +1,13 @@
|
||||
package de.diddiz.LogBlock;
|
||||
|
||||
public enum Logging {
|
||||
BLOCKPLACE(true), BLOCKBREAK(true), SIGNTEXT, TNTEXPLOSION(true), CREEPEREXPLOSION(true), GHASTFIREBALLEXPLOSION(true), ENDERDRAGON(true), MISCEXPLOSION, FIRE(true), LEAVESDECAY, LAVAFLOW, WATERFLOW, CHESTACCESS, KILL, CHAT, SNOWFORM, SNOWFADE, DOORINTERACT, SWITCHINTERACT, CAKEEAT, ENDERMEN, NOTEBLOCKINTERACT, DIODEINTERACT, NATURALSTRUCTUREGROW, BONEMEALSTRUCTUREGROW;
|
||||
|
||||
public enum Logging
|
||||
{
|
||||
BLOCKPLACE(true), BLOCKBREAK(true), SIGNTEXT, TNTEXPLOSION(true), CREEPEREXPLOSION(true),
|
||||
GHASTFIREBALLEXPLOSION(true), ENDERDRAGON(true), MISCEXPLOSION, FIRE(true), LEAVESDECAY,
|
||||
LAVAFLOW, WATERFLOW, CHESTACCESS, KILL, CHAT, SNOWFORM, SNOWFADE, DOORINTERACT,
|
||||
SWITCHINTERACT, CAKEEAT, ENDERMEN, NOTEBLOCKINTERACT, DIODEINTERACT, NATURALSTRUCTUREGROW,
|
||||
BONEMEALSTRUCTUREGROW;
|
||||
public static final int length = Logging.values().length;
|
||||
|
||||
private final boolean defaultEnabled;
|
||||
|
||||
private Logging() {
|
||||
|
@@ -452,7 +452,8 @@ public class QueryParams implements Cloneable
|
||||
params.players = new ArrayList<String>(players);
|
||||
params.types = new ArrayList<Integer>(types);
|
||||
return params;
|
||||
} catch (final CloneNotSupportedException ex) {}
|
||||
} catch (final CloneNotSupportedException ex) {
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
@@ -487,15 +488,18 @@ public class QueryParams implements Cloneable
|
||||
match = p.match;
|
||||
}
|
||||
|
||||
public static enum BlockChangeType {
|
||||
public static enum BlockChangeType
|
||||
{
|
||||
ALL, BOTH, CHESTACCESS, CREATED, DESTROYED, CHAT
|
||||
}
|
||||
|
||||
public static enum Order {
|
||||
public static enum Order
|
||||
{
|
||||
ASC, DESC
|
||||
}
|
||||
|
||||
public static enum SummarizationMode {
|
||||
public static enum SummarizationMode
|
||||
{
|
||||
NONE, PLAYERS, TYPES
|
||||
}
|
||||
}
|
||||
|
@@ -1,5 +1,6 @@
|
||||
package de.diddiz.LogBlock;
|
||||
|
||||
public enum ToolBehavior {
|
||||
public enum ToolBehavior
|
||||
{
|
||||
TOOL, BLOCK, NONE
|
||||
}
|
||||
}
|
||||
|
@@ -1,8 +1,8 @@
|
||||
package de.diddiz.LogBlock;
|
||||
|
||||
public enum ToolMode {
|
||||
public enum ToolMode
|
||||
{
|
||||
CLEARLOG("logblock.clearlog"), LOOKUP("logblock.lookup"), REDO("logblock.rollback"), ROLLBACK("logblock.rollback"), WRITELOGFILE("logblock.rollback");
|
||||
|
||||
private final String permission;
|
||||
|
||||
private ToolMode(String permission) {
|
||||
|
@@ -19,8 +19,8 @@ import org.bukkit.World;
|
||||
import org.bukkit.block.Block;
|
||||
import org.bukkit.block.BlockFace;
|
||||
import org.bukkit.block.BlockState;
|
||||
import org.bukkit.inventory.InventoryHolder;
|
||||
import org.bukkit.block.Sign;
|
||||
import org.bukkit.inventory.InventoryHolder;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
import org.bukkit.material.Bed;
|
||||
import org.bukkit.material.PistonBaseMaterial;
|
||||
@@ -109,13 +109,15 @@ public class WorldEditor implements Runnable
|
||||
for (final LookupCacheElement err : errorList)
|
||||
writer.println(err.getMessage());
|
||||
writer.close();
|
||||
} catch (final Exception ex) {}
|
||||
} catch (final Exception ex) {
|
||||
}
|
||||
errors = errorList.toArray(new WorldEditorException[errorList.size()]);
|
||||
notify();
|
||||
}
|
||||
}
|
||||
|
||||
private static enum PerformResult {
|
||||
private static enum PerformResult
|
||||
{
|
||||
SUCCESS, BLACKLISTED, NO_ACTION
|
||||
}
|
||||
|
||||
|
@@ -54,7 +54,8 @@ public class Config
|
||||
public static Set<Integer> hiddenBlocks;
|
||||
public static Set<String> hiddenPlayers;
|
||||
|
||||
public static enum LogKillsLevel {
|
||||
public static enum LogKillsLevel
|
||||
{
|
||||
PLAYERS, MONSTERS, ANIMALS;
|
||||
}
|
||||
|
||||
|
@@ -29,7 +29,8 @@ public class BanListener implements Listener
|
||||
p.setPlayer(split[1].equalsIgnoreCase("g") ? split[2] : split[1]);
|
||||
p.since = 0;
|
||||
p.silent = false;
|
||||
getScheduler().scheduleAsyncDelayedTask(logblock, new Runnable() {
|
||||
getScheduler().scheduleAsyncDelayedTask(logblock, new Runnable()
|
||||
{
|
||||
@Override
|
||||
public void run() {
|
||||
for (final World world : logblock.getServer().getWorlds())
|
||||
@@ -37,7 +38,8 @@ public class BanListener implements Listener
|
||||
p.world = world;
|
||||
try {
|
||||
handler.new CommandRollback(event.getPlayer(), p, false);
|
||||
} catch (final Exception ex) {}
|
||||
} catch (final Exception ex) {
|
||||
}
|
||||
}
|
||||
}
|
||||
});
|
||||
|
@@ -1,6 +1,5 @@
|
||||
package de.diddiz.LogBlock.listeners;
|
||||
|
||||
import de.diddiz.LogBlock.LogBlock;
|
||||
import static de.diddiz.util.BukkitUtils.compareInventories;
|
||||
import static de.diddiz.util.BukkitUtils.compressInventory;
|
||||
import static de.diddiz.util.BukkitUtils.rawData;
|
||||
@@ -14,39 +13,40 @@ import org.bukkit.event.EventPriority;
|
||||
import org.bukkit.event.inventory.InventoryCloseEvent;
|
||||
import org.bukkit.event.inventory.InventoryOpenEvent;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
import de.diddiz.LogBlock.LogBlock;
|
||||
|
||||
public class ChestAccessLogging extends LoggingListener
|
||||
{
|
||||
private final Map<HumanEntity, ItemStack[]> containers = new HashMap<HumanEntity, ItemStack[]>();
|
||||
private final Map<HumanEntity, ItemStack[]> containers = new HashMap<HumanEntity, ItemStack[]>();
|
||||
|
||||
public ChestAccessLogging(LogBlock lb) {
|
||||
super(lb);
|
||||
}
|
||||
public ChestAccessLogging(LogBlock lb) {
|
||||
super(lb);
|
||||
}
|
||||
|
||||
@EventHandler(priority = EventPriority.MONITOR, ignoreCancelled = true)
|
||||
public void onInventoryClose(InventoryCloseEvent event) {
|
||||
if (event.getInventory().getHolder() instanceof BlockState) {
|
||||
final HumanEntity player = event.getPlayer();
|
||||
final ItemStack[] before = containers.get(player);
|
||||
if (before != null) {
|
||||
final ItemStack[] after = compressInventory(event.getInventory().getContents());
|
||||
final ItemStack[] diff = compareInventories(before, after);
|
||||
final Location loc = ((BlockState) event.getInventory().getHolder()).getLocation();
|
||||
for (final ItemStack item : diff) {
|
||||
consumer.queueChestAccess(player.getName(), loc, loc.getWorld().getBlockTypeIdAt(loc), (short) item.getTypeId(), (short) item.getAmount(), rawData(item));
|
||||
}
|
||||
containers.remove(player);
|
||||
}
|
||||
}
|
||||
}
|
||||
@EventHandler(priority = EventPriority.MONITOR, ignoreCancelled = true)
|
||||
public void onInventoryClose(InventoryCloseEvent event) {
|
||||
if (event.getInventory().getHolder() instanceof BlockState) {
|
||||
final HumanEntity player = event.getPlayer();
|
||||
final ItemStack[] before = containers.get(player);
|
||||
if (before != null) {
|
||||
final ItemStack[] after = compressInventory(event.getInventory().getContents());
|
||||
final ItemStack[] diff = compareInventories(before, after);
|
||||
final Location loc = ((BlockState)event.getInventory().getHolder()).getLocation();
|
||||
for (final ItemStack item : diff) {
|
||||
consumer.queueChestAccess(player.getName(), loc, loc.getWorld().getBlockTypeIdAt(loc), (short)item.getTypeId(), (short)item.getAmount(), rawData(item));
|
||||
}
|
||||
containers.remove(player);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@EventHandler(priority = EventPriority.MONITOR, ignoreCancelled = true)
|
||||
public void onInventoryOpen(InventoryOpenEvent event) {
|
||||
if (event.getInventory().getHolder() instanceof BlockState) {
|
||||
BlockState block = (BlockState) event.getInventory().getHolder();
|
||||
if (block.getTypeId() != 58) {
|
||||
containers.put(event.getPlayer(), compressInventory(event.getInventory().getContents()));
|
||||
}
|
||||
}
|
||||
}
|
||||
@EventHandler(priority = EventPriority.MONITOR, ignoreCancelled = true)
|
||||
public void onInventoryOpen(InventoryOpenEvent event) {
|
||||
if (event.getInventory().getHolder() instanceof BlockState) {
|
||||
BlockState block = (BlockState)event.getInventory().getHolder();
|
||||
if (block.getTypeId() != 58) {
|
||||
containers.put(event.getPlayer(), compressInventory(event.getInventory().getContents()));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@@ -4,6 +4,7 @@ import static de.diddiz.LogBlock.Session.getSession;
|
||||
import static de.diddiz.LogBlock.Session.hasSession;
|
||||
import static de.diddiz.LogBlock.config.Config.isLogged;
|
||||
import static de.diddiz.LogBlock.config.Config.toolsByType;
|
||||
import com.sk89q.worldedit.bukkit.selections.CuboidSelection;
|
||||
import java.util.Map.Entry;
|
||||
import org.bukkit.ChatColor;
|
||||
import org.bukkit.block.Block;
|
||||
@@ -16,7 +17,6 @@ import org.bukkit.event.player.PlayerChangedWorldEvent;
|
||||
import org.bukkit.event.player.PlayerDropItemEvent;
|
||||
import org.bukkit.event.player.PlayerInteractEvent;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
import com.sk89q.worldedit.bukkit.selections.CuboidSelection;
|
||||
import de.diddiz.LogBlock.CommandsHandler;
|
||||
import de.diddiz.LogBlock.LogBlock;
|
||||
import de.diddiz.LogBlock.QueryParams;
|
||||
|
@@ -13,11 +13,11 @@ import org.bukkit.Chunk;
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.World;
|
||||
import org.bukkit.block.BlockState;
|
||||
import org.bukkit.inventory.InventoryHolder;
|
||||
import org.bukkit.entity.Entity;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.entity.TNTPrimed;
|
||||
import org.bukkit.inventory.Inventory;
|
||||
import org.bukkit.inventory.InventoryHolder;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
|
||||
public class BukkitUtils
|
||||
|
@@ -102,7 +102,8 @@ public class MySQLConnectionPool implements Closeable
|
||||
while (true) {
|
||||
try {
|
||||
Thread.sleep(300000);
|
||||
} catch (final InterruptedException e) {}
|
||||
} catch (final InterruptedException e) {
|
||||
}
|
||||
reapConnections();
|
||||
}
|
||||
}
|
||||
@@ -428,7 +429,8 @@ public class MySQLConnectionPool implements Closeable
|
||||
void terminate() {
|
||||
try {
|
||||
conn.close();
|
||||
} catch (final SQLException ex) {}
|
||||
} catch (final SQLException ex) {
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@@ -59,7 +59,8 @@ public class Utils
|
||||
try {
|
||||
Integer.parseInt(str);
|
||||
return true;
|
||||
} catch (final NumberFormatException ex) {}
|
||||
} catch (final NumberFormatException ex) {
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
@@ -67,7 +68,8 @@ public class Utils
|
||||
try {
|
||||
Byte.parseByte(str);
|
||||
return true;
|
||||
} catch (final NumberFormatException ex) {}
|
||||
} catch (final NumberFormatException ex) {
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user