Updated events to Bukkit-1.1

This commit is contained in:
DiddiZ
2012-01-27 01:39:37 +01:00
parent c7bea1fb9e
commit d5056374bc
37 changed files with 916 additions and 703 deletions
+2 -1
View File
@@ -1,5 +1,6 @@
package de.diddiz.LogBlock;
import static de.diddiz.LogBlock.config.Config.autoClearLog;
import static org.bukkit.Bukkit.getConsoleSender;
import static org.bukkit.Bukkit.getLogger;
import static org.bukkit.Bukkit.getServer;
@@ -17,7 +18,7 @@ public class AutoClearLog implements Runnable
@Override
public void run() {
final CommandsHandler handler = logblock.getCommandsHandler();
for (final String paramStr : logblock.getLBConfig().autoClearLog)
for (final String paramStr : autoClearLog)
try {
final QueryParams params = new QueryParams(logblock, getConsoleSender(), Arrays.asList(paramStr.split(" ")));
handler.new CommandClearLog(getServer().getConsoleSender(), params, false);
+41 -28
View File
@@ -1,6 +1,20 @@
package de.diddiz.LogBlock;
import static de.diddiz.LogBlock.Session.getSession;
import static de.diddiz.LogBlock.config.Config.askClearLogAfterRollback;
import static de.diddiz.LogBlock.config.Config.askClearLogs;
import static de.diddiz.LogBlock.config.Config.askRedos;
import static de.diddiz.LogBlock.config.Config.askRollbacks;
import static de.diddiz.LogBlock.config.Config.checkVersion;
import static de.diddiz.LogBlock.config.Config.defaultTime;
import static de.diddiz.LogBlock.config.Config.dumpDeletedLog;
import static de.diddiz.LogBlock.config.Config.getWorldConfig;
import static de.diddiz.LogBlock.config.Config.linesLimit;
import static de.diddiz.LogBlock.config.Config.linesPerPage;
import static de.diddiz.LogBlock.config.Config.rollbackMaxArea;
import static de.diddiz.LogBlock.config.Config.rollbackMaxTime;
import static de.diddiz.LogBlock.config.Config.toolsByName;
import static de.diddiz.LogBlock.config.Config.toolsByType;
import static de.diddiz.util.BukkitUtils.giveTool;
import static de.diddiz.util.BukkitUtils.saveSpawnHeight;
import static de.diddiz.util.Utils.isInt;
@@ -31,18 +45,17 @@ import org.bukkit.scheduler.BukkitScheduler;
import de.diddiz.LogBlock.QueryParams.BlockChangeType;
import de.diddiz.LogBlock.QueryParams.Order;
import de.diddiz.LogBlock.QueryParams.SummarizationMode;
import de.diddiz.LogBlock.config.WorldConfig;
import de.diddiz.LogBlockQuestioner.LogBlockQuestioner;
public class CommandsHandler implements CommandExecutor
{
private final LogBlock logblock;
private final Config config;
private final BukkitScheduler scheduler;
private final LogBlockQuestioner questioner;
CommandsHandler(LogBlock logblock) {
this.logblock = logblock;
config = logblock.getLBConfig();
scheduler = logblock.getServer().getScheduler();
questioner = (LogBlockQuestioner)logblock.getServer().getPluginManager().getPlugin("LogBlockQuestioner");
}
@@ -52,7 +65,7 @@ public class CommandsHandler implements CommandExecutor
try {
if (args.length == 0) {
sender.sendMessage(ChatColor.LIGHT_PURPLE + "LogBlock v" + logblock.getDescription().getVersion() + " by DiddiZ");
if (config.checkVersion)
if (checkVersion)
sender.sendMessage(ChatColor.LIGHT_PURPLE + logblock.getUpdater().checkVersion());
sender.sendMessage(ChatColor.LIGHT_PURPLE + "Type /lb help for help");
} else {
@@ -102,7 +115,7 @@ public class CommandsHandler implements CommandExecutor
for (final String permission : new String[]{"me", "lookup", "tp", "rollback", "clearlog", "hide", "ignoreRestrictions", "spawnTools"})
if (logblock.hasPermission(sender, "logblock." + permission))
sender.sendMessage(ChatColor.GOLD + "logblock." + permission);
for (final Tool tool : config.toolsByType.values())
for (final Tool tool : toolsByType.values())
if (logblock.hasPermission(sender, "logblock.tools." + tool.name))
sender.sendMessage(ChatColor.GOLD + "logblock.tools." + tool.name);
} else if (command.equals("logging")) {
@@ -113,7 +126,7 @@ public class CommandsHandler implements CommandExecutor
else if (sender instanceof Player)
world = ((Player)sender).getWorld();
if (world != null) {
final WorldConfig wcfg = config.worlds.get(world.getName().hashCode());
final WorldConfig wcfg = getWorldConfig(world.getName());
if (wcfg != null) {
sender.sendMessage(ChatColor.DARK_AQUA + "Currently logging in " + world.getName() + ":");
final List<String> logging = new ArrayList<String>();
@@ -129,8 +142,8 @@ public class CommandsHandler implements CommandExecutor
sender.sendMessage(ChatColor.RED + "No world specified");
} else
sender.sendMessage(ChatColor.RED + "You aren't allowed to do this.");
} else if (config.toolsByName.get(command) != null) {
final Tool tool = config.toolsByName.get(command);
} else if (toolsByName.get(command) != null) {
final Tool tool = toolsByName.get(command);
if (logblock.hasPermission(sender, "logblock.tools." + tool.name)) {
if (sender instanceof Player) {
final Player player = (Player)sender;
@@ -187,7 +200,7 @@ public class CommandsHandler implements CommandExecutor
} else if (command.equals("hide")) {
if (sender instanceof Player) {
if (logblock.hasPermission(sender, "logblock.hide")) {
if (logblock.getConsumer().hide((Player)sender))
if (Consumer.hide((Player)sender))
sender.sendMessage(ChatColor.GREEN + "You are now hidden and aren't logged. Type '/lb hide' again to unhide");
else
sender.sendMessage(ChatColor.GREEN + "You aren't hidden anylonger.");
@@ -217,7 +230,7 @@ public class CommandsHandler implements CommandExecutor
} else if (command.equals("rollback") || command.equals("undo") || command.equals("rb")) {
if (logblock.hasPermission(sender, "logblock.rollback")) {
final QueryParams params = new QueryParams(logblock);
params.since = config.defaultTime;
params.since = defaultTime;
params.bct = BlockChangeType.ALL;
params.parseArgs(sender, argsToList(args, 1));
new CommandRollback(sender, params, true);
@@ -226,7 +239,7 @@ public class CommandsHandler implements CommandExecutor
} else if (command.equals("redo")) {
if (logblock.hasPermission(sender, "logblock.rollback")) {
final QueryParams params = new QueryParams(logblock);
params.since = config.defaultTime;
params.since = defaultTime;
params.bct = BlockChangeType.ALL;
params.parseArgs(sender, argsToList(args, 1));
new CommandRedo(sender, params, true);
@@ -308,13 +321,13 @@ public class CommandsHandler implements CommandExecutor
return true;
}
private void showPage(CommandSender sender, int page) {
private static void showPage(CommandSender sender, int page) {
final Session session = getSession(sender);
if (session.lookupCache != null && session.lookupCache.length > 0) {
final int startpos = (page - 1) * config.linesPerPage;
final int startpos = (page - 1) * linesPerPage;
if (page > 0 && startpos <= session.lookupCache.length - 1) {
final int stoppos = startpos + config.linesPerPage >= session.lookupCache.length ? session.lookupCache.length - 1 : startpos + config.linesPerPage - 1;
final int numberOfPages = (int)Math.ceil(session.lookupCache.length / (double)config.linesPerPage);
final int stoppos = startpos + linesPerPage >= session.lookupCache.length ? session.lookupCache.length - 1 : startpos + linesPerPage - 1;
final int numberOfPages = (int)Math.ceil(session.lookupCache.length / (double)linesPerPage);
if (numberOfPages != 1)
sender.sendMessage(ChatColor.DARK_AQUA + "Page " + page + "/" + numberOfPages);
for (int i = startpos; i <= stoppos; i++)
@@ -329,12 +342,12 @@ public class CommandsHandler implements CommandExecutor
private boolean checkRestrictions(CommandSender sender, QueryParams params) {
if (sender.isOp() || logblock.hasPermission(sender, "logblock.ignoreRestrictions"))
return true;
if (config.rollbackMaxTime > 0 && (params.before > 0 || params.since > config.rollbackMaxTime)) {
sender.sendMessage(ChatColor.RED + "You are not allowed to rollback more than " + config.rollbackMaxTime + " minutes");
if (rollbackMaxTime > 0 && (params.before > 0 || params.since > rollbackMaxTime)) {
sender.sendMessage(ChatColor.RED + "You are not allowed to rollback more than " + rollbackMaxTime + " minutes");
return false;
}
if (config.rollbackMaxArea > 0 && (params.sel == null && params.loc == null || params.radius > config.rollbackMaxArea || params.sel != null && (params.sel.getLength() > config.rollbackMaxArea || params.sel.getWidth() > config.rollbackMaxArea))) {
sender.sendMessage(ChatColor.RED + "You are not allowed to rollback an area larger than " + config.rollbackMaxArea + " blocks");
if (rollbackMaxArea > 0 && (params.sel == null && params.loc == null || params.radius > rollbackMaxArea || params.sel != null && (params.sel.getLength() > rollbackMaxArea || params.sel.getWidth() > rollbackMaxArea))) {
sender.sendMessage(ChatColor.RED + "You are not allowed to rollback an area larger than " + rollbackMaxArea + " blocks");
return false;
}
return true;
@@ -411,8 +424,8 @@ public class CommandsHandler implements CommandExecutor
while (rs.next())
blockchanges.add(factory.getLookupCacheElement(rs));
getSession(sender).lookupCache = blockchanges.toArray(new LookupCacheElement[blockchanges.size()]);
if (blockchanges.size() > config.linesPerPage)
sender.sendMessage(ChatColor.DARK_AQUA.toString() + blockchanges.size() + " changes found." + (blockchanges.size() == config.linesLimit ? " Use 'limit -1' to see all changes." : ""));
if (blockchanges.size() > linesPerPage)
sender.sendMessage(ChatColor.DARK_AQUA.toString() + blockchanges.size() + " changes found." + (blockchanges.size() == linesLimit ? " Use 'limit -1' to see all changes." : ""));
if (params.sum != SummarizationMode.NONE)
sender.sendMessage(ChatColor.GOLD + "Created - Destroyed - " + (params.sum == SummarizationMode.TYPES ? "Block" : "Player"));
showPage(sender, 1);
@@ -431,7 +444,7 @@ public class CommandsHandler implements CommandExecutor
public class CommandWriteLogFile extends AbstractCommand
{
CommandWriteLogFile(CommandSender sender, QueryParams params, boolean async) throws Exception {
public CommandWriteLogFile(CommandSender sender, QueryParams params, boolean async) throws Exception {
super(sender, params, async);
}
@@ -590,14 +603,14 @@ public class CommandsHandler implements CommandExecutor
sender.sendMessage(ChatColor.RED + "Rollback aborted");
return;
}
if (!params.silent && config.askRollbacks && questioner != null && sender instanceof Player && !questioner.ask((Player)sender, "Are you sure you want to continue?", "yes", "no").equals("yes")) {
if (!params.silent && askRollbacks && questioner != null && sender instanceof Player && !questioner.ask((Player)sender, "Are you sure you want to continue?", "yes", "no").equals("yes")) {
sender.sendMessage(ChatColor.RED + "Rollback aborted");
return;
}
editor.start();
getSession(sender).lookupCache = editor.errors;
sender.sendMessage(ChatColor.GREEN + "Rollback finished successfully (" + editor.getElapsedTime() + " ms, " + editor.getSuccesses() + "/" + changes + " blocks" + (editor.getErrors() > 0 ? ", " + ChatColor.RED + editor.getErrors() + " errors" + ChatColor.GREEN : "") + (editor.getBlacklistCollisions() > 0 ? ", " + editor.getBlacklistCollisions() + " blacklist collisions" : "") + ")");
if (!params.silent && config.askClearLogAfterRollback && logblock.hasPermission(sender, "logblock.clearlog") && questioner != null && sender instanceof Player) {
if (!params.silent && askClearLogAfterRollback && logblock.hasPermission(sender, "logblock.clearlog") && questioner != null && sender instanceof Player) {
Thread.sleep(1000);
if (questioner.ask((Player)sender, "Do you want to delete the rollbacked log?", "yes", "no").equals("yes")) {
params.silent = true;
@@ -652,7 +665,7 @@ public class CommandsHandler implements CommandExecutor
sender.sendMessage(ChatColor.RED + "Redo aborted");
return;
}
if (!params.silent && config.askRedos && questioner != null && sender instanceof Player && !questioner.ask((Player)sender, "Are you sure you want to continue?", "yes", "no").equals("yes")) {
if (!params.silent && askRedos && questioner != null && sender instanceof Player && !questioner.ask((Player)sender, "Are you sure you want to continue?", "yes", "no").equals("yes")) {
sender.sendMessage(ChatColor.RED + "Redo aborted");
return;
}
@@ -694,7 +707,7 @@ public class CommandsHandler implements CommandExecutor
rs = state.executeQuery("SELECT count(*) FROM `" + table + "` " + join + params.getWhere());
rs.next();
if ((deleted = rs.getInt(1)) > 0) {
if (!params.silent && config.askClearLogs && sender instanceof Player && questioner != null) {
if (!params.silent && askClearLogs && sender instanceof Player && questioner != null) {
sender.sendMessage(ChatColor.DARK_AQUA + "Searching " + params.getTitle() + ":");
sender.sendMessage(ChatColor.GREEN.toString() + deleted + " blocks found.");
if (!questioner.ask((Player)sender, "Are you sure you want to continue?", "yes", "no").equals("yes")) {
@@ -702,7 +715,7 @@ public class CommandsHandler implements CommandExecutor
return;
}
}
if (config.dumpDeletedLog)
if (dumpDeletedLog)
try {
state.execute("SELECT * FROM `" + table + "` " + join + params.getWhere() + "INTO OUTFILE '" + new File(dumpFolder, time + " " + table + " " + params.getTitle().replace(":", ".") + ".csv").getAbsolutePath().replace("\\", "\\\\") + "' FIELDS TERMINATED BY ',' OPTIONALLY ENCLOSED BY '\"' LINES TERMINATED BY '\n'");
} catch (final SQLException ex) {
@@ -716,7 +729,7 @@ public class CommandsHandler implements CommandExecutor
rs = state.executeQuery("SELECT COUNT(*) FROM `" + table + "-sign` LEFT JOIN `" + table + "` USING (id) WHERE `" + table + "`.id IS NULL");
rs.next();
if ((deleted = rs.getInt(1)) > 0) {
if (config.dumpDeletedLog)
if (dumpDeletedLog)
state.execute("SELECT id, signtext FROM `" + table + "-sign` LEFT JOIN `" + table + "` USING (id) WHERE `" + table + "`.id IS NULL INTO OUTFILE '" + new File(dumpFolder, time + " " + table + "-sign " + params.getTitle() + ".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;");
sender.sendMessage(ChatColor.GREEN + "Cleared out table " + table + "-sign. Deleted " + deleted + " entries.");
@@ -724,7 +737,7 @@ public class CommandsHandler implements CommandExecutor
rs = state.executeQuery("SELECT COUNT(*) FROM `" + table + "-chest` LEFT JOIN `" + table + "` USING (id) WHERE `" + table + "`.id IS NULL");
rs.next();
if ((deleted = rs.getInt(1)) > 0) {
if (config.dumpDeletedLog)
if (dumpDeletedLog)
state.execute("SELECT id, itemtype, itemamount, itemdata FROM `" + table + "-chest` LEFT JOIN `" + table + "` USING (id) WHERE `" + table + "`.id IS NULL INTO OUTFILE '" + new File(dumpFolder, time + " " + table + "-chest " + params.getTitle() + ".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;");
sender.sendMessage(ChatColor.GREEN + "Cleared out table " + table + "-chest. Deleted " + deleted + " entries.");
+17 -23
View File
@@ -1,5 +1,11 @@
package de.diddiz.LogBlock;
import static de.diddiz.LogBlock.config.Config.forceToProcessAtLeast;
import static de.diddiz.LogBlock.config.Config.getWorldConfig;
import static de.diddiz.LogBlock.config.Config.hiddenBlocks;
import static de.diddiz.LogBlock.config.Config.hiddenPlayers;
import static de.diddiz.LogBlock.config.Config.isLogged;
import static de.diddiz.LogBlock.config.Config.timePerRun;
import static de.diddiz.util.BukkitUtils.compressInventory;
import static de.diddiz.util.BukkitUtils.entityName;
import static de.diddiz.util.BukkitUtils.rawData;
@@ -34,9 +40,6 @@ import org.bukkit.inventory.ItemStack;
public class Consumer extends TimerTask
{
private final Queue<Row> queue = new LinkedBlockingQueue<Row>();
private final Config config;
private final Map<Integer, WorldConfig> worlds;
private final Set<Integer> hiddenPlayers, hiddenBlocks;
private final Set<String> failedPlayers = new HashSet<String>();
private final LogBlock logblock;
private final Map<String, Integer> playerIds = new HashMap<String, Integer>();
@@ -44,10 +47,6 @@ public class Consumer extends TimerTask
Consumer(LogBlock logblock) {
this.logblock = logblock;
config = logblock.getLBConfig();
hiddenPlayers = config.hiddenPlayers;
hiddenBlocks = config.hiddenBlocks;
worlds = config.worlds;
}
/**
@@ -194,12 +193,7 @@ public class Consumer extends TimerTask
*/
@Deprecated
public void queueKill(World world, String killerName, String victimName, int weapon) {
queueKill(
new Location(world,0,0,0),
killerName,
victimName,
weapon
);
queueKill(new Location(world, 0, 0, 0), killerName, victimName, weapon);
}
/**
@@ -213,7 +207,7 @@ public class Consumer extends TimerTask
* Item id of the weapon. 0 for no weapon.
*/
public void queueKill(Location location, String killerName, String victimName, int weapon) {
if (victimName == null || !worlds.containsKey(location.getWorld().getName().hashCode()))
if (victimName == null || !isLogged(location.getWorld()))
return;
queue.add(new KillRow(location, killerName == null ? null : killerName.replaceAll("[^a-zA-Z0-9_]", ""), victimName.replaceAll("[^a-zA-Z0-9_]", ""), weapon));
}
@@ -277,7 +271,7 @@ public class Consumer extends TimerTask
state = conn.createStatement();
final long start = System.currentTimeMillis();
int count = 0;
process: while (!queue.isEmpty() && (System.currentTimeMillis() - start < config.timePerRun || count < config.forceToProcessAtLeast)) {
process: while (!queue.isEmpty() && (System.currentTimeMillis() - start < timePerRun || count < forceToProcessAtLeast)) {
final Row r = queue.poll();
if (r == null)
continue;
@@ -345,13 +339,13 @@ public class Consumer extends TimerTask
return queue.size();
}
boolean hide(Player player) {
final int hash = player.getName().hashCode();
if (hiddenPlayers.contains(hash)) {
hiddenPlayers.remove(hash);
static boolean hide(Player player) {
final String playerName = player.getName();
if (hiddenPlayers.contains(playerName)) {
hiddenPlayers.remove(playerName);
return false;
}
hiddenPlayers.add(hash);
hiddenPlayers.add(playerName);
return true;
}
@@ -365,7 +359,7 @@ public class Consumer extends TimerTask
}
private void queueBlock(String playerName, Location loc, int typeBefore, int typeAfter, byte data, String signtext, ChestAccess ca) {
if (playerName == null || loc == null || typeBefore < 0 || typeAfter < 0 || typeBefore > 255 || typeAfter > 255 || hiddenPlayers.contains(playerName.hashCode()) || !worlds.containsKey(loc.getWorld().getName().hashCode()) || typeBefore != typeAfter && hiddenBlocks.contains(typeBefore) && hiddenBlocks.contains(typeAfter))
if (playerName == null || loc == null || typeBefore < 0 || typeAfter < 0 || typeBefore > 255 || typeAfter > 255 || hiddenPlayers.contains(playerName) || !isLogged(loc.getWorld()) || typeBefore != typeAfter && hiddenBlocks.contains(typeBefore) && hiddenBlocks.contains(typeAfter))
return;
queue.add(new BlockRow(loc, playerName.replaceAll("[^a-zA-Z0-9_]", ""), typeBefore, typeAfter, data, signtext != null ? signtext.replace("\\", "\\\\").replace("'", "\\'") : null, ca));
}
@@ -394,7 +388,7 @@ public class Consumer extends TimerTask
@Override
public String[] getInserts() {
final String table = worlds.get(loc.getWorld().getName().hashCode()).table;
final String table = getWorldConfig(loc.getWorld()).table;
final String[] inserts = new String[ca != null || signtext != null ? 2 : 1];
inserts[0] = "INSERT INTO `" + table + "` (date, playerid, replaced, type, data, x, y, z) VALUES (FROM_UNIXTIME(" + date + "), " + playerID(playerName) + ", " + replaced + ", " + type + ", " + data + ", '" + loc.getBlockX() + "', " + loc.getBlockY() + ", '" + loc.getBlockZ() + "');";
if (signtext != null)
@@ -427,7 +421,7 @@ public class Consumer extends TimerTask
@Override
public String[] getInserts() {
return new String[]{"INSERT INTO `" + worlds.get(loc.getWorld().getName().hashCode()).table + "-kills` (date, killer, victim, weapon, x, y, z) VALUES (FROM_UNIXTIME(" + date + "), " + playerID(killer) + ", " + playerID(victim) + ", " + weapon + ", " + loc.getBlockX() + ", " + loc.getBlockY() + ", " + loc.getBlockZ() + ");"};
return new String[]{"INSERT INTO `" + getWorldConfig(loc.getWorld()).table + "-kills` (date, killer, victim, weapon, x, y, z) VALUES (FROM_UNIXTIME(" + date + "), " + playerID(killer) + ", " + playerID(victim) + ", " + weapon + ", " + loc.getBlockX() + ", " + loc.getBlockY() + ", " + loc.getBlockZ() + ");"};
}
@Override
-170
View File
@@ -1,170 +0,0 @@
package de.diddiz.LogBlock;
import java.io.File;
import java.io.PrintWriter;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.HashSet;
import java.util.List;
import java.util.Map;
import java.util.Set;
import org.bukkit.Location;
import org.bukkit.block.Block;
import org.bukkit.block.BlockFace;
import org.bukkit.block.BlockState;
import org.bukkit.block.Sign;
import org.bukkit.event.block.BlockBreakEvent;
import org.bukkit.event.block.BlockBurnEvent;
import org.bukkit.event.block.BlockFadeEvent;
import org.bukkit.event.block.BlockFormEvent;
import org.bukkit.event.block.BlockFromToEvent;
import org.bukkit.event.block.BlockListener;
import org.bukkit.event.block.BlockPlaceEvent;
import org.bukkit.event.block.LeavesDecayEvent;
import org.bukkit.event.block.SignChangeEvent;
import org.bukkit.material.MaterialData;
class LBBlockListener extends BlockListener
{
private static final SimpleDateFormat dateFormat = new SimpleDateFormat("MM-dd HH:mm:ss");
private static final Set<Integer> nonFluidProofBlocks = new HashSet<Integer>(Arrays.asList(27, 28, 31, 32, 37, 38, 39, 40, 50, 51, 55, 59, 66, 69, 70, 75, 76, 78, 93, 94, 104, 105, 106));
private final Consumer consumer;
private final Map<Integer, WorldConfig> worlds;
private final List<String> errors = new ArrayList<String>(20);
LBBlockListener(LogBlock logblock) {
consumer = logblock.getConsumer();
worlds = logblock.getLBConfig().worlds;
}
@Override
public void onBlockBreak(BlockBreakEvent event) {
final WorldConfig wcfg = worlds.get(event.getBlock().getWorld().getName().hashCode());
if (!event.isCancelled() && wcfg != null && wcfg.isLogging(Logging.BLOCKBREAK)) {
final int type = event.getBlock().getTypeId();
if (type == 0) {
final Location loc = event.getBlock().getLocation();
addError(dateFormat.format(System.currentTimeMillis()) + " Bukkit provided no block type for the block broken by " + event.getPlayer().getName() + " at " + loc.getWorld().getName() + ":" + loc.getBlockX() + ":" + loc.getBlockY() + ":" + loc.getBlockZ() + ".");
}
if (wcfg.isLogging(Logging.SIGNTEXT) && (type == 63 || type == 68))
consumer.queueSignBreak(event.getPlayer().getName(), (Sign)event.getBlock().getState());
else if (wcfg.isLogging(Logging.CHESTACCESS) && (type == 23 || type == 54 || type == 61))
consumer.queueContainerBreak(event.getPlayer().getName(), event.getBlock().getState());
else if (type == 79)
consumer.queueBlockReplace(event.getPlayer().getName(), event.getBlock().getState(), 9, (byte)0);
else
consumer.queueBlockBreak(event.getPlayer().getName(), event.getBlock().getState());
}
}
@Override
public void onBlockBurn(BlockBurnEvent event) {
final WorldConfig wcfg = worlds.get(event.getBlock().getWorld().getName().hashCode());
if (!event.isCancelled() && wcfg != null && wcfg.isLogging(Logging.FIRE))
consumer.queueBlockBreak("Fire", event.getBlock().getState());
}
@Override
public void onBlockFromTo(BlockFromToEvent event) {
final WorldConfig wcfg = worlds.get(event.getBlock().getWorld().getName().hashCode());
if (!event.isCancelled() && wcfg != null) {
final int typeFrom = event.getBlock().getTypeId();
final int typeTo = event.getToBlock().getTypeId();
if (typeFrom == 10 || typeFrom == 11) {
if (typeTo == 0) {
if (wcfg.isLogging(Logging.LAVAFLOW))
consumer.queueBlockPlace("LavaFlow", event.getToBlock().getLocation(), 10, (byte)(event.getBlock().getData() + 1));
} else if (nonFluidProofBlocks.contains(typeTo))
consumer.queueBlockReplace("LavaFlow", event.getToBlock().getState(), 10, (byte)(event.getBlock().getData() + 1));
else if (typeTo == 8 || typeTo == 9)
if (event.getFace() == BlockFace.DOWN)
consumer.queueBlockReplace("LavaFlow", event.getToBlock().getState(), 10, (byte)0);
else
consumer.queueBlockReplace("LavaFlow", event.getToBlock().getState(), 4, (byte)0);
} else if (typeFrom == 8 || typeFrom == 9)
if (typeTo == 0 || nonFluidProofBlocks.contains(typeTo)) {
if (typeTo == 0) {
if (wcfg.isLogging(Logging.WATERFLOW))
consumer.queueBlockPlace("WaterFlow", event.getToBlock().getLocation(), 8, (byte)(event.getBlock().getData() + 1));
} else
consumer.queueBlockReplace("WaterFlow", event.getToBlock().getState(), 8, (byte)(event.getBlock().getData() + 1));
final Block lower = event.getToBlock().getRelative(BlockFace.DOWN);
if (lower.getTypeId() == 10 || lower.getTypeId() == 11)
consumer.queueBlockReplace("WaterFlow", lower.getState(), lower.getData() == 0 ? 49 : 4, (byte)0);
}
}
}
@Override
public void onBlockPlace(BlockPlaceEvent event) {
final WorldConfig wcfg = worlds.get(event.getBlock().getWorld().getName().hashCode());
if (!event.isCancelled() && wcfg != null && wcfg.isLogging(Logging.BLOCKPLACE)) {
final int type = event.getBlock().getTypeId();
final BlockState before = event.getBlockReplacedState();
final BlockState after = event.getBlockPlaced().getState();
if (type == 0 && event.getItemInHand() != null) {
if (event.getItemInHand().getTypeId() == 51)
return;
final Location loc = event.getBlock().getLocation();
addError(dateFormat.format(System.currentTimeMillis()) + " Bukkit provided no block type for the block placed by " + event.getPlayer().getName() + " at " + loc.getWorld().getName() + ":" + loc.getBlockX() + ":" + loc.getBlockY() + ":" + loc.getBlockZ() + ". Item in hand was: " + event.getItemInHand().getType() + ".");
after.setTypeId(event.getItemInHand().getTypeId());
after.setData(new MaterialData(event.getItemInHand().getTypeId()));
}
if (wcfg.isLogging(Logging.SIGNTEXT) && (type == 63 || type == 68))
return;
if (before.getTypeId() == 0)
consumer.queueBlockPlace(event.getPlayer().getName(), after);
else
consumer.queueBlockReplace(event.getPlayer().getName(), before, after);
}
}
@Override
public void onLeavesDecay(LeavesDecayEvent event) {
final WorldConfig wcfg = worlds.get(event.getBlock().getWorld().getName().hashCode());
if (!event.isCancelled() && wcfg != null && wcfg.isLogging(Logging.LEAVESDECAY))
consumer.queueBlockBreak("LeavesDecay", event.getBlock().getState());
}
@Override
public void onSignChange(SignChangeEvent event) {
final WorldConfig wcfg = worlds.get(event.getBlock().getWorld().getName().hashCode());
if (!event.isCancelled() && wcfg != null && wcfg.isLogging(Logging.SIGNTEXT))
consumer.queueSignPlace(event.getPlayer().getName(), event.getBlock().getLocation(), event.getBlock().getTypeId(), event.getBlock().getData(), event.getLines());
}
@Override
public void onBlockForm(BlockFormEvent event) {
final WorldConfig wcfg = worlds.get(event.getBlock().getWorld().getName().hashCode());
if (!event.isCancelled() && wcfg != null) {
final int type = event.getNewState().getTypeId();
if (wcfg.isLogging(Logging.SNOWFORM) && (type == 78 || type == 79))
consumer.queueBlockReplace("SnowForm", event.getBlock().getState(), event.getNewState());
}
}
@Override
public void onBlockFade(BlockFadeEvent event) {
final WorldConfig wcfg = worlds.get(event.getBlock().getWorld().getName().hashCode());
if (!event.isCancelled() && wcfg != null) {
final int type = event.getBlock().getTypeId();
if (wcfg.isLogging(Logging.SNOWFADE) && (type == 78 || type == 79))
consumer.queueBlockReplace("SnowFade", event.getBlock().getState(), event.getNewState());
}
}
private void addError(String error) {
errors.add(error);
if (errors.size() == 20)
try {
final File file = new File("plugins/LogBlock/error/BlockListener.log");
file.getParentFile().mkdirs();
final PrintWriter writer = new PrintWriter(file);
for (final String err : errors)
writer.println(err);
writer.close();
errors.clear();
} catch (final Exception ex) {}
}
}
@@ -1,122 +0,0 @@
package de.diddiz.LogBlock;
import java.util.HashMap;
import java.util.Map;
import net.minecraft.server.EntityEnderman;
import org.bukkit.block.Block;
import org.bukkit.block.Sign;
import org.bukkit.craftbukkit.entity.CraftEnderman;
import org.bukkit.entity.Creeper;
import org.bukkit.entity.EnderDragon;
import org.bukkit.entity.Enderman;
import org.bukkit.entity.Entity;
import org.bukkit.entity.Fireball;
import org.bukkit.entity.LivingEntity;
import org.bukkit.entity.Monster;
import org.bukkit.entity.Player;
import org.bukkit.entity.TNTPrimed;
import org.bukkit.event.entity.EndermanPickupEvent;
import org.bukkit.event.entity.EndermanPlaceEvent;
import org.bukkit.event.entity.EntityDamageByEntityEvent;
import org.bukkit.event.entity.EntityDamageEvent;
import org.bukkit.event.entity.EntityExplodeEvent;
import org.bukkit.event.entity.EntityListener;
class LBEntityListener extends EntityListener
{
private final Consumer consumer;
private final boolean logCreeperExplosionsAsPlayer;
private final Config.LogKillsLevel logKillsLevel;
private final Map<Integer, WorldConfig> worlds;
private final Map<Integer, Integer> lastAttackedEntity = new HashMap<Integer, Integer>();
private final Map<Integer, Long> lastAttackTime = new HashMap<Integer, Long>();
LBEntityListener(LogBlock logblock) {
consumer = logblock.getConsumer();
worlds = logblock.getLBConfig().worlds;
logCreeperExplosionsAsPlayer = logblock.getLBConfig().logCreeperExplosionsAsPlayerWhoTriggeredThese;
logKillsLevel = logblock.getLBConfig().logKillsLevel;
}
@Override
public void onEntityDamage(EntityDamageEvent event) {
final WorldConfig wcfg = worlds.get(event.getEntity().getWorld().getName().hashCode());
if (!event.isCancelled() && wcfg != null && wcfg.isLogging(Logging.KILL) && event instanceof EntityDamageByEntityEvent && event.getEntity() instanceof LivingEntity) {
final LivingEntity victim = (LivingEntity)event.getEntity();
final Entity killer = ((EntityDamageByEntityEvent)event).getDamager();
if (victim.getHealth() - event.getDamage() > 0 || victim.getHealth() <= 0)
return;
if (logKillsLevel == Config.LogKillsLevel.PLAYERS && !(victim instanceof Player && killer instanceof Player))
return;
else if (logKillsLevel == Config.LogKillsLevel.MONSTERS && !((victim instanceof Player || victim instanceof Monster) && killer instanceof Player || killer instanceof Monster))
return;
if (lastAttackedEntity.containsKey(killer.getEntityId()) && lastAttackedEntity.get(killer.getEntityId()) == victim.getEntityId() && System.currentTimeMillis() - lastAttackTime.get(killer.getEntityId()) < 5000)
return;
consumer.queueKill(killer, victim);
lastAttackedEntity.put(killer.getEntityId(), victim.getEntityId());
lastAttackTime.put(killer.getEntityId(), System.currentTimeMillis());
}
}
@Override
public void onEntityExplode(EntityExplodeEvent event) {
final WorldConfig wcfg = worlds.get(event.getLocation().getWorld().getName().hashCode());
if (!event.isCancelled() && wcfg != null) {
final String name;
if (event.getEntity() == null) {
if (!wcfg.isLogging(Logging.MISCEXPLOSION))
return;
name = "Explosion";
} else if (event.getEntity() instanceof TNTPrimed) {
if (!wcfg.isLogging(Logging.TNTEXPLOSION))
return;
name = "TNT";
} else if (event.getEntity() instanceof Creeper) {
if (!wcfg.isLogging(Logging.CREEPEREXPLOSION))
return;
if (logCreeperExplosionsAsPlayer) {
final Entity target = ((Creeper)event.getEntity()).getTarget();
name = target instanceof Player ? ((Player)target).getName() : "Creeper";
} else
name = "Creeper";
} else if (event.getEntity() instanceof Fireball) {
if (!wcfg.isLogging(Logging.GHASTFIREBALLEXPLOSION))
return;
name = "Ghast";
} else if (event.getEntity() instanceof EnderDragon) {
if (!wcfg.isLogging(Logging.ENDERDRAGON))
return;
name = "EnderDragon";
} else {
if (!wcfg.isLogging(Logging.MISCEXPLOSION))
return;
name = "Explosion";
}
for (final Block block : event.blockList()) {
final int type = block.getTypeId();
if (wcfg.isLogging(Logging.SIGNTEXT) & (type == 63 || type == 68))
consumer.queueSignBreak(name, (Sign)block.getState());
else if (wcfg.isLogging(Logging.CHESTACCESS) && (type == 23 || type == 54 || type == 61))
consumer.queueContainerBreak(name, block.getState());
else
consumer.queueBlockBreak(name, block.getState());
}
}
}
@Override
public void onEndermanPickup(EndermanPickupEvent event) {
final WorldConfig wcfg = worlds.get(event.getBlock().getWorld().getName().hashCode());
if (!event.isCancelled() && wcfg != null && wcfg.isLogging(Logging.ENDERMEN))
consumer.queueBlockBreak("Enderman", event.getBlock().getState());
}
@Override
public void onEndermanPlace(EndermanPlaceEvent event) {
final WorldConfig wcfg = worlds.get(event.getLocation().getWorld().getName().hashCode());
if (!event.isCancelled() && wcfg != null && wcfg.isLogging(Logging.ENDERMEN) && event.getEntity() instanceof Enderman) {
final EntityEnderman enderman = ((CraftEnderman)event.getEntity()).getHandle();
consumer.queueBlockPlace("Enderman", event.getLocation(), enderman.getCarriedId(), (byte)enderman.getCarriedData());
}
}
}
@@ -1,102 +0,0 @@
package de.diddiz.LogBlock;
import java.util.Map;
import org.bukkit.Location;
import org.bukkit.Material;
import org.bukkit.entity.Player;
import org.bukkit.event.block.Action;
import org.bukkit.event.player.PlayerBucketEmptyEvent;
import org.bukkit.event.player.PlayerBucketFillEvent;
import org.bukkit.event.player.PlayerChatEvent;
import org.bukkit.event.player.PlayerCommandPreprocessEvent;
import org.bukkit.event.player.PlayerInteractEvent;
import org.bukkit.event.player.PlayerJoinEvent;
import org.bukkit.event.player.PlayerListener;
import org.bukkit.event.player.PlayerQuitEvent;
class LBPlayerListener extends PlayerListener
{
private final Consumer consumer;
private final Map<Integer, WorldConfig> worlds;
LBPlayerListener(LogBlock logblock) {
consumer = logblock.getConsumer();
worlds = logblock.getLBConfig().worlds;
}
@Override
public void onPlayerBucketEmpty(PlayerBucketEmptyEvent event) {
final WorldConfig wcfg = worlds.get(event.getPlayer().getWorld().getName().hashCode());
if (!event.isCancelled() && wcfg != null && wcfg.isLogging(Logging.BLOCKPLACE))
consumer.queueBlockPlace(event.getPlayer().getName(), event.getBlockClicked().getRelative(event.getBlockFace()).getLocation(), event.getBucket() == Material.WATER_BUCKET ? 9 : 11, (byte)0);
}
@Override
public void onPlayerBucketFill(PlayerBucketFillEvent event) {
final WorldConfig wcfg = worlds.get(event.getPlayer().getWorld().getName().hashCode());
if (!event.isCancelled() && wcfg != null && wcfg.isLogging(Logging.BLOCKBREAK))
consumer.queueBlockBreak(event.getPlayer().getName(), event.getBlockClicked().getState());
}
@Override
public void onPlayerInteract(PlayerInteractEvent event) {
final WorldConfig wcfg = worlds.get(event.getPlayer().getWorld().getName().hashCode());
if (!event.isCancelled() && wcfg != null && (event.getAction() == Action.LEFT_CLICK_BLOCK || event.getAction() == Action.RIGHT_CLICK_BLOCK)) {
final int type = event.getClickedBlock().getTypeId();
final Player player = event.getPlayer();
final Location loc = event.getClickedBlock().getLocation();
switch (type) {
case 69:
case 77:
if (wcfg.isLogging(Logging.SWITCHINTERACT))
consumer.queueBlock(player.getName(), loc, type, type, (byte)0);
break;
case 107:
if (event.getAction() != Action.RIGHT_CLICK_BLOCK)
break;
case 64:
case 96:
if (wcfg.isLogging(Logging.DOORINTERACT))
consumer.queueBlock(player.getName(), loc, type, type, (byte)((event.getClickedBlock().getData() & 4) / 4));
break;
case 92:
if (wcfg.isLogging(Logging.CAKEEAT) && player.getFoodLevel() < 20)
consumer.queueBlock(player.getName(), loc, 92, 92, (byte)0);
break;
case 25:
if (wcfg.isLogging(Logging.NOTEBLOCKINTERACT))
consumer.queueBlock(player.getName(), loc, 25, 25, (byte)0);
break;
case 93:
case 94:
if (wcfg.isLogging(Logging.DIODEINTERACT) && event.getAction() == Action.RIGHT_CLICK_BLOCK)
consumer.queueBlock(player.getName(), loc, type, type, (byte)0);
break;
}
}
}
@Override
public void onPlayerCommandPreprocess(PlayerCommandPreprocessEvent event) {
final WorldConfig wcfg = worlds.get(event.getPlayer().getWorld().getName().hashCode());
if (wcfg != null && wcfg.isLogging(Logging.CHAT))
consumer.queueChat(event.getPlayer().getName(), event.getMessage());
}
@Override
public void onPlayerChat(PlayerChatEvent event) {
final WorldConfig wcfg = worlds.get(event.getPlayer().getWorld().getName().hashCode());
if (wcfg != null && wcfg.isLogging(Logging.CHAT))
consumer.queueChat(event.getPlayer().getName(), event.getMessage());
}
@Override
public void onPlayerJoin(PlayerJoinEvent event) {
consumer.queueJoin(event.getPlayer());
}
@Override
public void onPlayerQuit(PlayerQuitEvent event) {
consumer.queueLeave(event.getPlayer());
}
}
@@ -1,18 +0,0 @@
package de.diddiz.LogBlock;
import org.bukkit.event.server.ServerCommandEvent;
import org.bukkit.event.server.ServerListener;
public class LBServerListener extends ServerListener
{
private final Consumer consumer;
LBServerListener(LogBlock logblock) {
consumer = logblock.getConsumer();
}
@Override
public void onServerCommand(ServerCommandEvent event) {
consumer.queueChat("Console", "/" + event.getCommand());
}
}
@@ -9,19 +9,17 @@ import org.bukkit.Location;
import org.bukkit.entity.Player;
import org.bukkit.inventory.ItemStack;
import org.getspout.spoutapi.event.inventory.InventoryCloseEvent;
import org.getspout.spoutapi.event.inventory.InventoryListener;
import org.getspout.spoutapi.event.inventory.InventoryOpenEvent;
import de.diddiz.LogBlock.listeners.LoggingListener;
class LBSpoutChestAccessListener extends InventoryListener
class LBSpoutChestAccessListener extends LoggingListener
{
private final Consumer consumer;
private final Map<Player, ItemStack[]> containers = new HashMap<Player, ItemStack[]>();
LBSpoutChestAccessListener(LogBlock logblock) {
consumer = logblock.getConsumer();
private LBSpoutChestAccessListener(LogBlock lb) {
super(lb);
}
@Override
public void onInventoryClose(InventoryCloseEvent event) {
if (!event.isCancelled() && event.getLocation() != null) {
final Player player = event.getPlayer();
@@ -37,7 +35,6 @@ class LBSpoutChestAccessListener extends InventoryListener
}
}
@Override
public void onInventoryOpen(InventoryOpenEvent event) {
if (!event.isCancelled() && event.getLocation() != null && event.getLocation().getBlock().getTypeId() != 58)
containers.put(event.getPlayer(), compressInventory(event.getInventory().getContents()));
+87 -84
View File
@@ -1,7 +1,19 @@
package de.diddiz.LogBlock;
import static de.diddiz.LogBlock.config.Config.askRollbackAfterBan;
import static de.diddiz.LogBlock.config.Config.autoClearLogDelay;
import static de.diddiz.LogBlock.config.Config.checkVersion;
import static de.diddiz.LogBlock.config.Config.delayBetweenRuns;
import static de.diddiz.LogBlock.config.Config.enableAutoClearLog;
import static de.diddiz.LogBlock.config.Config.isLogging;
import static de.diddiz.LogBlock.config.Config.load;
import static de.diddiz.LogBlock.config.Config.logPlayerInfo;
import static de.diddiz.LogBlock.config.Config.password;
import static de.diddiz.LogBlock.config.Config.toolsByType;
import static de.diddiz.LogBlock.config.Config.url;
import static de.diddiz.LogBlock.config.Config.useBukkitScheduler;
import static de.diddiz.LogBlock.config.Config.user;
import static de.diddiz.util.Utils.download;
import static org.bukkit.Bukkit.getLogger;
import java.io.File;
import java.io.FileNotFoundException;
import java.net.URL;
@@ -17,20 +29,35 @@ import org.bukkit.ChatColor;
import org.bukkit.command.Command;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;
import org.bukkit.event.Event.Priority;
import org.bukkit.event.Event.Type;
import org.bukkit.event.Listener;
import org.bukkit.permissions.Permission;
import org.bukkit.plugin.PluginManager;
import org.bukkit.plugin.java.JavaPlugin;
import com.nijiko.permissions.PermissionHandler;
import com.nijikokun.bukkit.Permissions.Permissions;
import de.diddiz.LogBlock.config.Config;
import de.diddiz.LogBlock.listeners.BanListener;
import de.diddiz.LogBlock.listeners.BlockBreakLogging;
import de.diddiz.LogBlock.listeners.BlockBurnLogging;
import de.diddiz.LogBlock.listeners.BlockPlaceLogging;
import de.diddiz.LogBlock.listeners.ChatLogging;
import de.diddiz.LogBlock.listeners.ChestAccessLogging;
import de.diddiz.LogBlock.listeners.EndermenLogging;
import de.diddiz.LogBlock.listeners.ExplosionLogging;
import de.diddiz.LogBlock.listeners.FluidFlowLogging;
import de.diddiz.LogBlock.listeners.InteractLogging;
import de.diddiz.LogBlock.listeners.KillLogging;
import de.diddiz.LogBlock.listeners.LeavesDecayLogging;
import de.diddiz.LogBlock.listeners.PlayerInfoLogging;
import de.diddiz.LogBlock.listeners.SignChangeLogging;
import de.diddiz.LogBlock.listeners.SnowFadeLogging;
import de.diddiz.LogBlock.listeners.SnowFormLogging;
import de.diddiz.LogBlock.listeners.StructureGrowLogging;
import de.diddiz.LogBlock.listeners.ToolListener;
import de.diddiz.util.MySQLConnectionPool;
public class LogBlock extends JavaPlugin
{
private static LogBlock logblock = null;
private Config config;
private MySQLConnectionPool pool;
private Consumer consumer = null;
private CommandsHandler commandsHandler;
@@ -43,10 +70,6 @@ public class LogBlock extends JavaPlugin
return logblock;
}
public Config getLBConfig() {
return config;
}
public Consumer getConsumer() {
return consumer;
}
@@ -64,11 +87,11 @@ public class LogBlock extends JavaPlugin
logblock = this;
try {
updater = new Updater(this);
config = new Config(this);
if (config.checkVersion)
Config.load(this);
if (checkVersion)
getLogger().info("[LogBlock] Version check: " + updater.checkVersion());
getLogger().info("[LogBlock] Connecting to " + config.user + "@" + config.url + "...");
pool = new MySQLConnectionPool(config.url, config.user, config.password);
getLogger().info("[LogBlock] Connecting to " + user + "@" + url + "...");
pool = new MySQLConnectionPool(url, user, password);
final Connection conn = getConnection();
if (conn == null) {
noDb = true;
@@ -76,7 +99,7 @@ public class LogBlock extends JavaPlugin
}
conn.close();
if (updater.update())
config = new Config(this);
load(this);
updater.checkTables();
} catch (final NullPointerException ex) {
getLogger().log(Level.SEVERE, "[LogBlock] Error while loading: ", ex);
@@ -113,84 +136,64 @@ public class LogBlock extends JavaPlugin
getLogger().info("[LogBlock] Permissions plugin found.");
} else
getLogger().info("[LogBlock] Permissions plugin not found. Using Bukkit Permissions.");
if (config.enableAutoClearLog && config.autoClearLogDelay > 0)
getServer().getScheduler().scheduleAsyncRepeatingTask(this, new AutoClearLog(this), 6000, config.autoClearLogDelay * 60 * 20);
if (enableAutoClearLog && autoClearLogDelay > 0)
getServer().getScheduler().scheduleAsyncRepeatingTask(this, new AutoClearLog(this), 6000, autoClearLogDelay * 60 * 20);
getServer().getScheduler().scheduleAsyncDelayedTask(this, new DumpedLogImporter(this));
final Listener lbBlockListener = new LBBlockListener(this);
final Listener lbPlayerListener = new LBPlayerListener(this);
final Listener lbEntityListener = new LBEntityListener(this);
final Listener lbToolListener = new LBToolListener(this);
pm.registerEvent(Type.PLAYER_INTERACT, lbToolListener, Priority.Normal, this);
pm.registerEvent(Type.PLAYER_CHANGED_WORLD, lbToolListener, Priority.Normal, this);
if (config.askRollbackAfterBan)
pm.registerEvent(Type.PLAYER_COMMAND_PREPROCESS, lbToolListener, Priority.Normal, this);
if (config.isLogging(Logging.BLOCKPLACE)) {
pm.registerEvent(Type.BLOCK_PLACE, lbBlockListener, Priority.Monitor, this);
pm.registerEvent(Type.PLAYER_BUCKET_EMPTY, lbPlayerListener, Priority.Monitor, this);
}
if (config.isLogging(Logging.BLOCKBREAK)) {
pm.registerEvent(Type.BLOCK_BREAK, lbBlockListener, Priority.Monitor, this);
pm.registerEvent(Type.PLAYER_BUCKET_FILL, lbPlayerListener, Priority.Monitor, this);
pm.registerEvent(Type.BLOCK_FROMTO, lbBlockListener, Priority.Monitor, this);
}
if (config.isLogging(Logging.SIGNTEXT))
pm.registerEvent(Type.SIGN_CHANGE, lbBlockListener, Priority.Monitor, this);
if (config.isLogging(Logging.FIRE))
pm.registerEvent(Type.BLOCK_BURN, lbBlockListener, Priority.Monitor, this);
if (config.isLogging(Logging.SNOWFORM))
pm.registerEvent(Type.BLOCK_FORM, lbBlockListener, Priority.Monitor, this);
if (config.isLogging(Logging.SNOWFADE))
pm.registerEvent(Type.BLOCK_FADE, lbBlockListener, Priority.Monitor, this);
if (config.isLogging(Logging.CREEPEREXPLOSION) || config.isLogging(Logging.TNTEXPLOSION) || config.isLogging(Logging.GHASTFIREBALLEXPLOSION) || config.isLogging(Logging.ENDERDRAGON) || config.isLogging(Logging.MISCEXPLOSION))
pm.registerEvent(Type.ENTITY_EXPLODE, lbEntityListener, Priority.Monitor, this);
if (config.isLogging(Logging.LEAVESDECAY))
pm.registerEvent(Type.LEAVES_DECAY, lbBlockListener, Priority.Monitor, this);
if (config.isLogging(Logging.CHESTACCESS))
if (pm.isPluginEnabled("Spout")) {
pm.registerEvent(Type.CUSTOM_EVENT, new LBSpoutChestAccessListener(this), Priority.Monitor, this);
getLogger().info("[LogBlock] Using Spout as chest access API");
} else {
final Listener chestAccessListener = new LBChestAccessListener(this);
pm.registerEvent(Type.PLAYER_INTERACT, chestAccessListener, Priority.Monitor, this);
pm.registerEvent(Type.PLAYER_CHAT, chestAccessListener, Priority.Monitor, this);
pm.registerEvent(Type.PLAYER_COMMAND_PREPROCESS, chestAccessListener, Priority.Monitor, this);
pm.registerEvent(Type.PLAYER_TELEPORT, chestAccessListener, Priority.Monitor, this);
pm.registerEvent(Type.PLAYER_QUIT, chestAccessListener, Priority.Monitor, this);
getLogger().info("[LogBlock] Using own chest access API");
}
if (config.isLogging(Logging.SWITCHINTERACT) || config.isLogging(Logging.DOORINTERACT) || config.isLogging(Logging.CAKEEAT))
pm.registerEvent(Type.PLAYER_INTERACT, lbPlayerListener, Priority.Monitor, this);
if (config.isLogging(Logging.KILL))
pm.registerEvent(Type.ENTITY_DAMAGE, lbEntityListener, Priority.Monitor, this);
if (config.isLogging(Logging.CHAT)) {
pm.registerEvent(Type.PLAYER_CHAT, lbPlayerListener, Priority.Monitor, this);
pm.registerEvent(Type.PLAYER_COMMAND_PREPROCESS, lbPlayerListener, Priority.Monitor, this);
pm.registerEvent(Type.SERVER_COMMAND, new LBServerListener(this), Priority.Monitor, this);
}
if (config.isLogging(Logging.ENDERMEN)) {
pm.registerEvent(Type.ENDERMAN_PICKUP, lbEntityListener, Priority.Monitor, this);
pm.registerEvent(Type.ENDERMAN_PLACE, lbEntityListener, Priority.Monitor, this);
}
if (config.isLogging(Logging.NATURALSTRUCTUREGROW) || config.isLogging(Logging.BONEMEALSTRUCTUREGROW))
pm.registerEvent(Type.STRUCTURE_GROW, new LBWorldListener(this), Priority.Monitor, this);
if (config.logPlayerInfo) {
pm.registerEvent(Type.PLAYER_JOIN, lbPlayerListener, Priority.Monitor, this);
pm.registerEvent(Type.PLAYER_QUIT, lbPlayerListener, Priority.Monitor, this);
}
if (config.useBukkitScheduler) {
if (getServer().getScheduler().scheduleAsyncRepeatingTask(this, consumer, config.delayBetweenRuns * 20, config.delayBetweenRuns * 20) > 0)
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))
// if (pm.isPluginEnabled("Spout")) { //TODO
// pm.registerEvents(Type.CUSTOM_EVENT, new LBSpoutChestAccessListener(this), Priority.Monitor, this);
// getLogger().info("[LogBlock] Using Spout as chest access API");
// } else {
pm.registerEvents(new ChestAccessLogging(this), this);
getLogger().info("[LogBlock] Using own chest access API");
// }
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);
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, config.delayBetweenRuns * 1000, config.delayBetweenRuns * 1000);
timer.scheduleAtFixedRate(consumer, delayBetweenRuns * 1000, delayBetweenRuns * 1000);
}
} else {
timer = new Timer();
timer.scheduleAtFixedRate(consumer, config.delayBetweenRuns * 1000, config.delayBetweenRuns * 1000);
timer.scheduleAtFixedRate(consumer, delayBetweenRuns * 1000, delayBetweenRuns * 1000);
getLogger().info("[LogBlock] Scheduled consumer with timer.");
}
for (final Tool tool : config.toolsByType.values())
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);
@@ -205,7 +208,7 @@ public class LogBlock extends JavaPlugin
timer.cancel();
getServer().getScheduler().cancelTasks(this);
if (consumer != null) {
if (config.logPlayerInfo && getServer().getOnlinePlayers() != null)
if (logPlayerInfo && getServer().getOnlinePlayers() != null)
for (final Player player : getServer().getOnlinePlayers())
consumer.queueLeave(player);
if (consumer.getQueueSize() > 0) {
@@ -242,7 +245,7 @@ public class LogBlock extends JavaPlugin
return true;
}
boolean hasPermission(CommandSender sender, String permission) {
public boolean hasPermission(CommandSender sender, String permission) {
if (permissions != null && sender instanceof Player)
return permissions.has((Player)sender, permission);
return sender.hasPermission(permission);
+10 -12
View File
@@ -1,6 +1,10 @@
package de.diddiz.LogBlock;
import static de.diddiz.LogBlock.Session.getSession;
import static de.diddiz.LogBlock.config.Config.defaultDist;
import static de.diddiz.LogBlock.config.Config.defaultTime;
import static de.diddiz.LogBlock.config.Config.getWorldConfig;
import static de.diddiz.LogBlock.config.Config.isLogged;
import static de.diddiz.util.BukkitUtils.friendlyWorldname;
import static de.diddiz.util.BukkitUtils.getBlockEquivalents;
import static de.diddiz.util.MaterialName.materialName;
@@ -117,7 +121,7 @@ public class QueryParams implements Cloneable
}
public String getTable() {
return logblock.getLBConfig().worlds.get(world.getName().hashCode()).table;
return getWorldConfig(world).table;
}
public String getTitle() {
@@ -314,7 +318,7 @@ public class QueryParams implements Cloneable
if (player == null && !prepareToolQuery)
throw new IllegalArgumentException("You have to ba a player to use area");
if (values.length == 0) {
radius = logblock.getLBConfig().defaultDist;
radius = defaultDist;
if (!prepareToolQuery)
loc = player.getLocation();
} else {
@@ -337,17 +341,11 @@ public class QueryParams implements Cloneable
throw new IllegalArgumentException("You have to define a cuboid selection");
setSelection(selection);
} else if (param.equals("time") || param.equals("since")) {
if (values.length == 0)
since = logblock.getLBConfig().defaultTime;
else
since = parseTimeSpec(values);
since = values.length > 0 ? parseTimeSpec(values) : defaultTime;
if (since == -1)
throw new IllegalArgumentException("Failed to parse time spec for '" + param + "'");
} else if (param.equals("before")) {
if (values.length == 0)
before = logblock.getLBConfig().defaultTime;
else
before = parseTimeSpec(values);
before = values.length > 0 ? parseTimeSpec(values) : defaultTime;
if (before == -1)
throw new IllegalArgumentException("Faile to parse time spec for '" + param + "'");
} else if (param.equals("sum")) {
@@ -425,7 +423,7 @@ public class QueryParams implements Cloneable
if (!prepareToolQuery && bct != BlockChangeType.CHAT) {
if (world == null)
throw new IllegalArgumentException("No world specified");
if (!logblock.getLBConfig().worlds.containsKey(world.getName().hashCode()))
if (!isLogged(world))
throw new IllegalArgumentException("This world ('" + world.getName() + "') isn't logged");
}
if (session != null)
@@ -478,7 +476,7 @@ public class QueryParams implements Cloneable
loc = p.loc;
radius = p.radius;
sel = p.sel;
if (p.since != 0 || since != logblock.getLBConfig().defaultTime)
if (p.since != 0 || since != defaultTime)
since = p.since;
before = p.before;
sum = p.sum;
+2 -14
View File
@@ -1,5 +1,6 @@
package de.diddiz.LogBlock;
import static de.diddiz.LogBlock.config.Config.toolsByType;
import static org.bukkit.Bukkit.getServer;
import java.util.HashMap;
import java.util.Map;
@@ -18,7 +19,7 @@ public class Session
toolData = new HashMap<Tool, ToolData>();
final LogBlock logblock = LogBlock.getInstance();
if (player != null)
for (final Tool tool : logblock.getLBConfig().toolsByType.values())
for (final Tool tool : toolsByType.values())
toolData.put(tool, new ToolData(tool, logblock, player));
}
@@ -43,16 +44,3 @@ public class Session
return session;
}
}
class ToolData
{
boolean enabled;
QueryParams params;
ToolMode mode;
ToolData(Tool tool, LogBlock logblock, Player player) {
enabled = tool.defaultEnabled && logblock.hasPermission(player, "logblock.tools." + tool.name);
params = tool.params.clone();
mode = tool.mode;
}
}
-4
View File
@@ -26,7 +26,3 @@ public class Tool
this.permissionDefault = permissionDefault;
}
}
enum ToolBehavior {
TOOL, BLOCK, NONE
}
+5
View File
@@ -0,0 +1,5 @@
package de.diddiz.LogBlock;
public enum ToolBehavior {
TOOL, BLOCK, NONE
}
+16
View File
@@ -0,0 +1,16 @@
package de.diddiz.LogBlock;
import org.bukkit.entity.Player;
public class ToolData
{
public boolean enabled;
public QueryParams params;
public ToolMode mode;
public ToolData(Tool tool, LogBlock logblock, Player player) {
enabled = tool.defaultEnabled && logblock.hasPermission(player, "logblock.tools." + tool.name);
params = tool.params.clone();
mode = tool.mode;
}
}
+7 -4
View File
@@ -1,5 +1,7 @@
package de.diddiz.LogBlock;
import static de.diddiz.LogBlock.config.Config.getLoggedWorlds;
import static de.diddiz.LogBlock.config.Config.isLogging;
import static de.diddiz.util.BukkitUtils.friendlyWorldname;
import static de.diddiz.util.Utils.readURL;
import static org.bukkit.Bukkit.getLogger;
@@ -14,6 +16,7 @@ import java.util.logging.Level;
import org.bukkit.Bukkit;
import org.bukkit.configuration.ConfigurationSection;
import org.bukkit.configuration.file.YamlConfiguration;
import de.diddiz.LogBlock.config.WorldConfig;
class Updater
{
@@ -29,7 +32,7 @@ class Updater
return false;
if (config.getString("version").compareTo("1.27") < 0) {
getLogger().info("[LogBlock] Updating tables to 1.27 ...");
if (logblock.getLBConfig().isLogging(Logging.CHAT)) {
if (isLogging(Logging.CHAT)) {
final Connection conn = logblock.getConnection();
try {
conn.setAutoCommit(true);
@@ -162,7 +165,7 @@ class Updater
try {
conn.setAutoCommit(true);
final Statement st = conn.createStatement();
for (final WorldConfig wcfg : logblock.getLBConfig().worlds.values())
for (final WorldConfig wcfg : getLoggedWorlds())
if (wcfg.isLogging(Logging.KILL))
st.execute("ALTER TABLE `" + wcfg.table + "-kills` ADD (x SMALLINT NOT NULL DEFAULT 0, y TINYINT UNSIGNED NOT NULL DEFAULT 0, z SMALLINT NOT NULL DEFAULT 0)");
st.close();
@@ -185,9 +188,9 @@ class Updater
final DatabaseMetaData dbm = conn.getMetaData();
conn.setAutoCommit(true);
createTable(dbm, state, "lb-players", "(playerid SMALLINT UNSIGNED NOT NULL AUTO_INCREMENT, playername varchar(32) NOT NULL, firstlogin DATETIME NOT NULL, lastlogin DATETIME NOT NULL, onlinetime TIME NOT NULL, ip varchar(255) NOT NULL, PRIMARY KEY (playerid), UNIQUE (playername))");
if (logblock.getLBConfig().isLogging(Logging.CHAT))
if (isLogging(Logging.CHAT))
createTable(dbm, state, "lb-chat", "(id INT UNSIGNED NOT NULL AUTO_INCREMENT, date DATETIME NOT NULL, playerid SMALLINT UNSIGNED NOT NULL, message VARCHAR(255) NOT NULL, PRIMARY KEY (id), KEY playerid (playerid), FULLTEXT message (message)) ENGINE=MyISAM");
for (final WorldConfig wcfg : logblock.getLBConfig().worlds.values()) {
for (final WorldConfig wcfg : getLoggedWorlds()) {
createTable(dbm, state, wcfg.table, "(id INT UNSIGNED NOT NULL AUTO_INCREMENT, date DATETIME NOT NULL, playerid SMALLINT UNSIGNED NOT NULL, replaced TINYINT UNSIGNED NOT NULL, type TINYINT UNSIGNED NOT NULL, data TINYINT UNSIGNED NOT NULL, x SMALLINT NOT NULL, y TINYINT UNSIGNED NOT NULL, z SMALLINT NOT NULL, PRIMARY KEY (id), KEY coords (x, z, y), KEY date (date), KEY playerid (playerid))");
createTable(dbm, state, wcfg.table + "-sign", "(id INT UNSIGNED NOT NULL, signtext VARCHAR(255) NOT NULL, PRIMARY KEY (id))");
createTable(dbm, state, wcfg.table + "-chest", "(id INT UNSIGNED NOT NULL, itemtype SMALLINT UNSIGNED NOT NULL, itemamount SMALLINT NOT NULL, itemdata TINYINT UNSIGNED NOT NULL, PRIMARY KEY (id))");
+4 -4
View File
@@ -1,5 +1,7 @@
package de.diddiz.LogBlock;
import static de.diddiz.LogBlock.config.Config.dontRollback;
import static de.diddiz.LogBlock.config.Config.replaceAnyway;
import static de.diddiz.util.BukkitUtils.equalTypes;
import static de.diddiz.util.BukkitUtils.modifyContainer;
import static de.diddiz.util.MaterialName.materialName;
@@ -27,7 +29,6 @@ import org.bukkit.material.PistonExtensionMaterial;
public class WorldEditor implements Runnable
{
private final LogBlock logblock;
private final Config config;
private final Queue<Edit> edits = new LinkedBlockingQueue<Edit>();
private final World world;
private int taskID;
@@ -37,7 +38,6 @@ public class WorldEditor implements Runnable
public WorldEditor(LogBlock logblock, World world) {
this.logblock = logblock;
config = logblock.getLBConfig();
this.world = world;
}
@@ -126,7 +126,7 @@ public class WorldEditor implements Runnable
}
PerformResult perform() throws WorldEditorException {
if (config.dontRollback.contains(replaced))
if (dontRollback.contains(replaced))
return PerformResult.BLACKLISTED;
final Block block = loc.getBlock();
if (replaced == 0 && block.getTypeId() == 0)
@@ -157,7 +157,7 @@ public class WorldEditor implements Runnable
return PerformResult.NO_ACTION;
return PerformResult.SUCCESS;
}
if (!(equalTypes(block.getTypeId(), type) || config.replaceAnyway.contains(block.getTypeId())))
if (!(equalTypes(block.getTypeId(), type) || replaceAnyway.contains(block.getTypeId())))
return PerformResult.NO_ACTION;
if (state instanceof ContainerBlock) {
((ContainerBlock)state).getInventory().clear();
@@ -1,4 +1,4 @@
package de.diddiz.LogBlock;
package de.diddiz.LogBlock.config;
import static de.diddiz.util.BukkitUtils.friendlyWorldname;
import static de.diddiz.util.Utils.parseTimeSpec;
@@ -9,6 +9,7 @@ import java.io.File;
import java.io.IOException;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collection;
import java.util.HashMap;
import java.util.HashSet;
import java.util.List;
@@ -20,37 +21,44 @@ import java.util.zip.DataFormatException;
import org.bukkit.Material;
import org.bukkit.World;
import org.bukkit.configuration.ConfigurationSection;
import org.bukkit.configuration.file.YamlConfiguration;
import org.bukkit.permissions.PermissionDefault;
import de.diddiz.LogBlock.LogBlock;
import de.diddiz.LogBlock.Logging;
import de.diddiz.LogBlock.QueryParams;
import de.diddiz.LogBlock.Tool;
import de.diddiz.LogBlock.ToolBehavior;
import de.diddiz.LogBlock.ToolMode;
public class Config extends LoggingEnabledMapping
public class Config
{
public final Map<Integer, WorldConfig> worlds;
public final String url, user, password;
public final int delayBetweenRuns, forceToProcessAtLeast, timePerRun;
public final boolean useBukkitScheduler;
public final boolean enableAutoClearLog;
public final List<String> autoClearLog;
public final int autoClearLogDelay;
public final boolean dumpDeletedLog;
public final boolean logCreeperExplosionsAsPlayerWhoTriggeredThese, logPlayerInfo;
public final LogKillsLevel logKillsLevel;
public final Set<Integer> dontRollback, replaceAnyway;
public final int rollbackMaxTime, rollbackMaxArea;
public final Map<String, Tool> toolsByName;
public final Map<Integer, Tool> toolsByType;
public final int defaultDist, defaultTime;
public final int linesPerPage, linesLimit;
public final boolean askRollbacks, askRedos, askClearLogs, askClearLogAfterRollback, askRollbackAfterBan;
public final String banPermission;
public final boolean checkVersion;
public final Set<Integer> hiddenPlayers, hiddenBlocks;
private static LoggingEnabledMapping superWorldConfig;
private static Map<String, WorldConfig> worldConfigs;
public static String url, user, password;
public static int delayBetweenRuns, forceToProcessAtLeast, timePerRun;
public static boolean useBukkitScheduler;
public static boolean enableAutoClearLog;
public static List<String> autoClearLog;
public static int autoClearLogDelay;
public static boolean dumpDeletedLog;
public static boolean logCreeperExplosionsAsPlayerWhoTriggeredThese, logPlayerInfo;
public static LogKillsLevel logKillsLevel;
public static Set<Integer> dontRollback, replaceAnyway;
public static int rollbackMaxTime, rollbackMaxArea;
public static Map<String, Tool> toolsByName;
public static Map<Integer, Tool> toolsByType;
public static int defaultDist, defaultTime;
public static int linesPerPage, linesLimit;
public static boolean askRollbacks, askRedos, askClearLogs, askClearLogAfterRollback, askRollbackAfterBan;
public static String banPermission;
public static boolean checkVersion;
public static Set<Integer> hiddenBlocks;
public static Set<String> hiddenPlayers;
public static enum LogKillsLevel {
PLAYERS, MONSTERS, ANIMALS;
}
Config(LogBlock logblock) throws DataFormatException, IOException {
public static void load(LogBlock logblock) throws DataFormatException, IOException {
final ConfigurationSection config = logblock.getConfig();
final Map<String, Object> def = new HashMap<String, Object>();
def.put("version", logblock.getDescription().getVersion());
@@ -137,9 +145,9 @@ public class Config extends LoggingEnabledMapping
} catch (final IllegalArgumentException ex) {
throw new DataFormatException("lookup.toolblockID doesn't appear to be a valid log level. Allowed are 'PLAYERS', 'MONSTERS' and 'ANIMALS'");
}
hiddenPlayers = new HashSet<Integer>();
for (final Object playerName : config.getList("logging.hiddenPlayers"))
hiddenPlayers.add(playerName.hashCode());
hiddenPlayers = new HashSet<String>();
for (final String playerName : config.getStringList("logging.hiddenPlayers"))
hiddenPlayers.add(playerName);
hiddenBlocks = new HashSet<Integer>();
for (final Object blocktype : config.getList("logging.hiddenBlocks")) {
final Material mat = Material.matchMaterial(String.valueOf(blocktype));
@@ -191,15 +199,16 @@ public class Config extends LoggingEnabledMapping
toolsByName.put(alias, tool);
}
final List<String> loggedWorlds = config.getStringList("loggedWorlds");
worlds = new HashMap<Integer, WorldConfig>();
worldConfigs = new HashMap<String, WorldConfig>();
if (loggedWorlds.size() == 0)
throw new DataFormatException("No worlds configured");
for (final String world : loggedWorlds)
worlds.put(world.hashCode(), new WorldConfig(new File(logblock.getDataFolder(), friendlyWorldname(world) + ".yml")));
for (final WorldConfig wcfg : worlds.values())
worldConfigs.put(world, new WorldConfig(new File(logblock.getDataFolder(), friendlyWorldname(world) + ".yml")));
superWorldConfig = new LoggingEnabledMapping();
for (final WorldConfig wcfg : worldConfigs.values())
for (final Logging l : Logging.values())
if (wcfg.isLogging(l))
setLogging(l, true);
superWorldConfig.setLogging(l, true);
}
private static String getStringIncludingInts(ConfigurationSection cfg, String key) {
@@ -210,29 +219,34 @@ public class Config extends LoggingEnabledMapping
str = "No value set for '" + key + "'";
return str;
}
}
class WorldConfig extends LoggingEnabledMapping
{
public final String table;
public static boolean isLogging(World world, Logging l) {
final WorldConfig wcfg = worldConfigs.get(world.getName());
return wcfg != null && wcfg.isLogging(l);
}
public WorldConfig(File file) throws IOException {
final Map<String, Object> def = new HashMap<String, Object>();
def.put("table", "lb-" + file.getName().substring(0, file.getName().length() - 4));
for (final Logging l : Logging.values())
def.put("logging." + l.toString(), l.isDefaultEnabled());
final YamlConfiguration config = YamlConfiguration.loadConfiguration(file);
for (final Entry<String, Object> e : def.entrySet())
if (config.get(e.getKey()) == null)
config.set(e.getKey(), e.getValue());
config.save(file);
table = config.getString("table");
for (final Logging l : Logging.values())
setLogging(l, config.getBoolean("logging." + l.toString()));
public static boolean isLogged(World world) {
return worldConfigs.containsKey(world.getName());
}
public static WorldConfig getWorldConfig(World world) {
return worldConfigs.get(world.getName());
}
public static WorldConfig getWorldConfig(String world) {
return worldConfigs.get(world);
}
public static boolean isLogging(Logging l) {
return superWorldConfig.isLogging(l);
}
public static Collection<WorldConfig> getLoggedWorlds() {
return worldConfigs.values();
}
}
abstract class LoggingEnabledMapping
class LoggingEnabledMapping
{
private final boolean[] logging = new boolean[Logging.length];
@@ -0,0 +1,29 @@
package de.diddiz.LogBlock.config;
import java.io.File;
import java.io.IOException;
import java.util.HashMap;
import java.util.Map;
import java.util.Map.Entry;
import org.bukkit.configuration.file.YamlConfiguration;
import de.diddiz.LogBlock.Logging;
public class WorldConfig extends LoggingEnabledMapping
{
public final String table;
public WorldConfig(File file) throws IOException {
final Map<String, Object> def = new HashMap<String, Object>();
def.put("table", "lb-" + file.getName().substring(0, file.getName().length() - 4));
for (final Logging l : Logging.values())
def.put("logging." + l.toString(), l.isDefaultEnabled());
final YamlConfiguration config = YamlConfiguration.loadConfiguration(file);
for (final Entry<String, Object> e : def.entrySet())
if (config.get(e.getKey()) == null)
config.set(e.getKey(), e.getValue());
config.save(file);
table = config.getString("table");
for (final Logging l : Logging.values())
setLogging(l, config.getBoolean("logging." + l.toString()));
}
}
@@ -0,0 +1,46 @@
package de.diddiz.LogBlock.listeners;
import static de.diddiz.LogBlock.config.Config.banPermission;
import static de.diddiz.LogBlock.config.Config.isLogged;
import static org.bukkit.Bukkit.getScheduler;
import org.bukkit.World;
import org.bukkit.event.EventHandler;
import org.bukkit.event.Listener;
import org.bukkit.event.player.PlayerCommandPreprocessEvent;
import de.diddiz.LogBlock.CommandsHandler;
import de.diddiz.LogBlock.LogBlock;
import de.diddiz.LogBlock.QueryParams;
public class BanListener implements Listener
{
private final CommandsHandler handler;
private final LogBlock logblock;
public BanListener(LogBlock logblock) {
this.logblock = logblock;
handler = logblock.getCommandsHandler();
}
@EventHandler
public void onPlayerCommandPreprocess(final PlayerCommandPreprocessEvent event) {
final String[] split = event.getMessage().split(" ");
if (split.length > 1 && split[0].equalsIgnoreCase("/ban") && logblock.hasPermission(event.getPlayer(), banPermission)) {
final QueryParams p = new QueryParams(logblock);
p.setPlayer(split[1].equalsIgnoreCase("g") ? split[2] : split[1]);
p.since = 0;
p.silent = false;
getScheduler().scheduleAsyncDelayedTask(logblock, new Runnable() {
@Override
public void run() {
for (final World world : logblock.getServer().getWorlds())
if (isLogged(world)) {
p.world = world;
try {
handler.new CommandRollback(event.getPlayer(), p, false);
} catch (final Exception ex) {}
}
}
});
}
}
}
@@ -0,0 +1,41 @@
package de.diddiz.LogBlock.listeners;
import static de.diddiz.LogBlock.config.Config.getWorldConfig;
import static de.diddiz.LogBlock.config.Config.isLogging;
import org.bukkit.block.Sign;
import org.bukkit.event.EventHandler;
import org.bukkit.event.EventPriority;
import org.bukkit.event.block.BlockBreakEvent;
import org.bukkit.event.player.PlayerBucketFillEvent;
import de.diddiz.LogBlock.LogBlock;
import de.diddiz.LogBlock.Logging;
import de.diddiz.LogBlock.config.WorldConfig;
public class BlockBreakLogging extends LoggingListener
{
public BlockBreakLogging(LogBlock lb) {
super(lb);
}
@EventHandler(priority = EventPriority.MONITOR)
public void onBlockBreak(BlockBreakEvent event) {
final WorldConfig wcfg = getWorldConfig(event.getBlock().getWorld());
if (!event.isCancelled() && wcfg.isLogging(Logging.BLOCKBREAK)) {
final int type = event.getBlock().getTypeId();
if (wcfg.isLogging(Logging.SIGNTEXT) && (type == 63 || type == 68))
consumer.queueSignBreak(event.getPlayer().getName(), (Sign)event.getBlock().getState());
else if (wcfg.isLogging(Logging.CHESTACCESS) && (type == 23 || type == 54 || type == 61))
consumer.queueContainerBreak(event.getPlayer().getName(), event.getBlock().getState());
else if (type == 79)
consumer.queueBlockReplace(event.getPlayer().getName(), event.getBlock().getState(), 9, (byte)0);
else
consumer.queueBlockBreak(event.getPlayer().getName(), event.getBlock().getState());
}
}
@EventHandler(priority = EventPriority.MONITOR)
public void onPlayerBucketFill(PlayerBucketFillEvent event) {
if (!event.isCancelled() && isLogging(event.getPlayer().getWorld(), Logging.BLOCKBREAK))
consumer.queueBlockBreak(event.getPlayer().getName(), event.getBlockClicked().getState());
}
}
@@ -0,0 +1,21 @@
package de.diddiz.LogBlock.listeners;
import static de.diddiz.LogBlock.config.Config.isLogging;
import org.bukkit.event.EventHandler;
import org.bukkit.event.EventPriority;
import org.bukkit.event.block.BlockBurnEvent;
import de.diddiz.LogBlock.LogBlock;
import de.diddiz.LogBlock.Logging;
public class BlockBurnLogging extends LoggingListener
{
public BlockBurnLogging(LogBlock lb) {
super(lb);
}
@EventHandler(priority = EventPriority.MONITOR)
public void onBlockBurn(BlockBurnEvent event) {
if (!event.isCancelled() && isLogging(event.getBlock().getWorld(), Logging.FIRE))
consumer.queueBlockBreak("Fire", event.getBlock().getState());
}
}
@@ -0,0 +1,49 @@
package de.diddiz.LogBlock.listeners;
import static de.diddiz.LogBlock.config.Config.getWorldConfig;
import static de.diddiz.LogBlock.config.Config.isLogging;
import org.bukkit.Material;
import org.bukkit.block.BlockState;
import org.bukkit.event.EventHandler;
import org.bukkit.event.EventPriority;
import org.bukkit.event.block.BlockPlaceEvent;
import org.bukkit.event.player.PlayerBucketEmptyEvent;
import org.bukkit.material.MaterialData;
import de.diddiz.LogBlock.LogBlock;
import de.diddiz.LogBlock.Logging;
import de.diddiz.LogBlock.config.WorldConfig;
public class BlockPlaceLogging extends LoggingListener
{
public BlockPlaceLogging(LogBlock lb) {
super(lb);
}
@EventHandler(priority = EventPriority.MONITOR)
public void onBlockPlace(BlockPlaceEvent event) {
final WorldConfig wcfg = getWorldConfig(event.getBlock().getWorld());
if (!event.isCancelled() && wcfg != null && wcfg.isLogging(Logging.BLOCKPLACE)) {
final int type = event.getBlock().getTypeId();
final BlockState before = event.getBlockReplacedState();
final BlockState after = event.getBlockPlaced().getState();
if (type == 0 && event.getItemInHand() != null) {
if (event.getItemInHand().getTypeId() == 51)
return;
after.setTypeId(event.getItemInHand().getTypeId());
after.setData(new MaterialData(event.getItemInHand().getTypeId()));
}
if (wcfg.isLogging(Logging.SIGNTEXT) && (type == 63 || type == 68))
return;
if (before.getTypeId() == 0)
consumer.queueBlockPlace(event.getPlayer().getName(), after);
else
consumer.queueBlockReplace(event.getPlayer().getName(), before, after);
}
}
@EventHandler(priority = EventPriority.MONITOR)
public void onPlayerBucketEmpty(PlayerBucketEmptyEvent event) {
if (!event.isCancelled() && isLogging(event.getPlayer().getWorld(), Logging.BLOCKPLACE))
consumer.queueBlockPlace(event.getPlayer().getName(), event.getBlockClicked().getRelative(event.getBlockFace()).getLocation(), event.getBucket() == Material.WATER_BUCKET ? 9 : 11, (byte)0);
}
}
@@ -0,0 +1,34 @@
package de.diddiz.LogBlock.listeners;
import static de.diddiz.LogBlock.config.Config.isLogging;
import org.bukkit.event.EventHandler;
import org.bukkit.event.EventPriority;
import org.bukkit.event.player.PlayerChatEvent;
import org.bukkit.event.player.PlayerCommandPreprocessEvent;
import org.bukkit.event.server.ServerCommandEvent;
import de.diddiz.LogBlock.LogBlock;
import de.diddiz.LogBlock.Logging;
public class ChatLogging extends LoggingListener
{
public ChatLogging(LogBlock lb) {
super(lb);
}
@EventHandler(priority = EventPriority.MONITOR)
public void onPlayerCommandPreprocess(PlayerCommandPreprocessEvent event) {
if (isLogging(event.getPlayer().getWorld(), Logging.CHAT))
consumer.queueChat(event.getPlayer().getName(), event.getMessage());
}
@EventHandler(priority = EventPriority.MONITOR)
public void onPlayerChat(PlayerChatEvent event) {
if (isLogging(event.getPlayer().getWorld(), Logging.CHAT))
consumer.queueChat(event.getPlayer().getName(), event.getMessage());
}
@EventHandler(priority = EventPriority.MONITOR)
public void onServerCommand(ServerCommandEvent event) {
consumer.queueChat("Console", "/" + event.getCommand());
}
}
@@ -1,5 +1,6 @@
package de.diddiz.LogBlock;
package de.diddiz.LogBlock.listeners;
import static de.diddiz.LogBlock.config.Config.isLogging;
import static de.diddiz.util.BukkitUtils.compareInventories;
import static de.diddiz.util.BukkitUtils.compressInventory;
import static de.diddiz.util.BukkitUtils.rawData;
@@ -10,22 +11,24 @@ import org.bukkit.block.Block;
import org.bukkit.block.BlockState;
import org.bukkit.block.ContainerBlock;
import org.bukkit.entity.Player;
import org.bukkit.event.EventHandler;
import org.bukkit.event.EventPriority;
import org.bukkit.event.block.Action;
import org.bukkit.event.player.PlayerChatEvent;
import org.bukkit.event.player.PlayerCommandPreprocessEvent;
import org.bukkit.event.player.PlayerInteractEvent;
import org.bukkit.event.player.PlayerListener;
import org.bukkit.event.player.PlayerQuitEvent;
import org.bukkit.event.player.PlayerTeleportEvent;
import org.bukkit.inventory.ItemStack;
import de.diddiz.LogBlock.LogBlock;
import de.diddiz.LogBlock.Logging;
class LBChestAccessListener extends PlayerListener
public class ChestAccessLogging extends LoggingListener
{
private final Consumer consumer;
private final Map<Player, ContainerState> containers = new HashMap<Player, ContainerState>();
LBChestAccessListener(LogBlock logblock) {
consumer = logblock.getConsumer();
public ChestAccessLogging(LogBlock lb) {
super(lb);
}
public void checkInventoryClose(Player player) {
@@ -50,31 +53,31 @@ class LBChestAccessListener extends PlayerListener
containers.put(player, new ContainerState(block.getLocation(), compressInventory(((ContainerBlock)state).getInventory().getContents())));
}
@Override
@EventHandler(priority = EventPriority.MONITOR)
public void onPlayerChat(PlayerChatEvent event) {
checkInventoryClose(event.getPlayer());
}
@Override
@EventHandler(priority = EventPriority.MONITOR)
public void onPlayerCommandPreprocess(PlayerCommandPreprocessEvent event) {
checkInventoryClose(event.getPlayer());
}
@Override
@EventHandler(priority = EventPriority.MONITOR)
public void onPlayerQuit(PlayerQuitEvent event) {
checkInventoryClose(event.getPlayer());
}
@Override
@EventHandler(priority = EventPriority.MONITOR)
public void onPlayerTeleport(PlayerTeleportEvent event) {
checkInventoryClose(event.getPlayer());
}
@Override
@EventHandler(priority = EventPriority.MONITOR)
public void onPlayerInteract(PlayerInteractEvent event) {
final Player player = event.getPlayer();
checkInventoryClose(player);
if (event.getAction() == Action.RIGHT_CLICK_BLOCK) {
if (!event.isCancelled() && event.getAction() == Action.RIGHT_CLICK_BLOCK && isLogging(player.getWorld(), Logging.CHESTACCESS)) {
final Block block = event.getClickedBlock();
final int type = block.getTypeId();
if (type == 23 || type == 54 || type == 61 || type == 62)
@@ -0,0 +1,33 @@
package de.diddiz.LogBlock.listeners;
import static de.diddiz.LogBlock.config.Config.isLogging;
import net.minecraft.server.EntityEnderman;
import org.bukkit.craftbukkit.entity.CraftEnderman;
import org.bukkit.entity.Enderman;
import org.bukkit.event.EventHandler;
import org.bukkit.event.EventPriority;
import org.bukkit.event.entity.EndermanPickupEvent;
import org.bukkit.event.entity.EndermanPlaceEvent;
import de.diddiz.LogBlock.LogBlock;
import de.diddiz.LogBlock.Logging;
public class EndermenLogging extends LoggingListener
{
public EndermenLogging(LogBlock lb) {
super(lb);
}
@EventHandler(priority = EventPriority.MONITOR)
public void onEndermanPickup(EndermanPickupEvent event) {
if (!event.isCancelled() && isLogging(event.getBlock().getWorld(), Logging.ENDERMEN))
consumer.queueBlockBreak("Enderman", event.getBlock().getState());
}
@EventHandler(priority = EventPriority.MONITOR)
public void onEndermanPlace(EndermanPlaceEvent event) {
if (!event.isCancelled() && isLogging(event.getLocation().getWorld(), Logging.ENDERMEN) && event.getEntity() instanceof Enderman) {
final EntityEnderman enderman = ((CraftEnderman)event.getEntity()).getHandle();
consumer.queueBlockPlace("Enderman", event.getLocation(), enderman.getCarriedId(), (byte)enderman.getCarriedData());
}
}
}
@@ -0,0 +1,68 @@
package de.diddiz.LogBlock.listeners;
import static de.diddiz.LogBlock.config.Config.getWorldConfig;
import static de.diddiz.LogBlock.config.Config.logCreeperExplosionsAsPlayerWhoTriggeredThese;
import org.bukkit.block.Block;
import org.bukkit.block.Sign;
import org.bukkit.entity.Creeper;
import org.bukkit.entity.EnderDragon;
import org.bukkit.entity.Entity;
import org.bukkit.entity.Fireball;
import org.bukkit.entity.Player;
import org.bukkit.entity.TNTPrimed;
import org.bukkit.event.entity.EntityExplodeEvent;
import de.diddiz.LogBlock.LogBlock;
import de.diddiz.LogBlock.Logging;
import de.diddiz.LogBlock.config.WorldConfig;
public class ExplosionLogging extends LoggingListener
{
public ExplosionLogging(LogBlock lb) {
super(lb);
}
public void onEntityExplode(EntityExplodeEvent event) {
final WorldConfig wcfg = getWorldConfig(event.getLocation().getWorld());
if (!event.isCancelled() && wcfg != null) {
final String name;
if (event.getEntity() == null) {
if (!wcfg.isLogging(Logging.MISCEXPLOSION))
return;
name = "Explosion";
} else if (event.getEntity() instanceof TNTPrimed) {
if (!wcfg.isLogging(Logging.TNTEXPLOSION))
return;
name = "TNT";
} else if (event.getEntity() instanceof Creeper) {
if (!wcfg.isLogging(Logging.CREEPEREXPLOSION))
return;
if (logCreeperExplosionsAsPlayerWhoTriggeredThese) {
final Entity target = ((Creeper)event.getEntity()).getTarget();
name = target instanceof Player ? ((Player)target).getName() : "Creeper";
} else
name = "Creeper";
} else if (event.getEntity() instanceof Fireball) {
if (!wcfg.isLogging(Logging.GHASTFIREBALLEXPLOSION))
return;
name = "Ghast";
} else if (event.getEntity() instanceof EnderDragon) {
if (!wcfg.isLogging(Logging.ENDERDRAGON))
return;
name = "EnderDragon";
} else {
if (!wcfg.isLogging(Logging.MISCEXPLOSION))
return;
name = "Explosion";
}
for (final Block block : event.blockList()) {
final int type = block.getTypeId();
if (wcfg.isLogging(Logging.SIGNTEXT) & (type == 63 || type == 68))
consumer.queueSignBreak(name, (Sign)block.getState());
else if (wcfg.isLogging(Logging.CHESTACCESS) && (type == 23 || type == 54 || type == 61))
consumer.queueContainerBreak(name, block.getState());
else
consumer.queueBlockBreak(name, block.getState());
}
}
}
}
@@ -0,0 +1,54 @@
package de.diddiz.LogBlock.listeners;
import static de.diddiz.LogBlock.config.Config.getWorldConfig;
import java.util.Arrays;
import java.util.HashSet;
import java.util.Set;
import org.bukkit.block.Block;
import org.bukkit.block.BlockFace;
import org.bukkit.event.EventHandler;
import org.bukkit.event.EventPriority;
import org.bukkit.event.block.BlockFromToEvent;
import de.diddiz.LogBlock.LogBlock;
import de.diddiz.LogBlock.Logging;
import de.diddiz.LogBlock.config.WorldConfig;
public class FluidFlowLogging extends LoggingListener
{
private static final Set<Integer> nonFluidProofBlocks = new HashSet<Integer>(Arrays.asList(27, 28, 31, 32, 37, 38, 39, 40, 50, 51, 55, 59, 66, 69, 70, 75, 76, 78, 93, 94, 104, 105, 106));
public FluidFlowLogging(LogBlock lb) {
super(lb);
}
@EventHandler(priority = EventPriority.MONITOR)
public void onBlockFromTo(BlockFromToEvent event) {
final WorldConfig wcfg = getWorldConfig(event.getBlock().getWorld());
if (!event.isCancelled() && wcfg != null) {
final int typeFrom = event.getBlock().getTypeId();
final int typeTo = event.getToBlock().getTypeId();
if (typeFrom == 10 || typeFrom == 11) {
if (typeTo == 0) {
if (wcfg.isLogging(Logging.LAVAFLOW))
consumer.queueBlockPlace("LavaFlow", event.getToBlock().getLocation(), 10, (byte)(event.getBlock().getData() + 1));
} else if (nonFluidProofBlocks.contains(typeTo))
consumer.queueBlockReplace("LavaFlow", event.getToBlock().getState(), 10, (byte)(event.getBlock().getData() + 1));
else if (typeTo == 8 || typeTo == 9)
if (event.getFace() == BlockFace.DOWN)
consumer.queueBlockReplace("LavaFlow", event.getToBlock().getState(), 10, (byte)0);
else
consumer.queueBlockReplace("LavaFlow", event.getToBlock().getState(), 4, (byte)0);
} else if (typeFrom == 8 || typeFrom == 9)
if (typeTo == 0 || nonFluidProofBlocks.contains(typeTo)) {
if (typeTo == 0) {
if (wcfg.isLogging(Logging.WATERFLOW))
consumer.queueBlockPlace("WaterFlow", event.getToBlock().getLocation(), 8, (byte)(event.getBlock().getData() + 1));
} else
consumer.queueBlockReplace("WaterFlow", event.getToBlock().getState(), 8, (byte)(event.getBlock().getData() + 1));
final Block lower = event.getToBlock().getRelative(BlockFace.DOWN);
if (lower.getTypeId() == 10 || lower.getTypeId() == 11)
consumer.queueBlockReplace("WaterFlow", lower.getState(), lower.getData() == 0 ? 49 : 4, (byte)0);
}
}
}
}
@@ -0,0 +1,57 @@
package de.diddiz.LogBlock.listeners;
import static de.diddiz.LogBlock.config.Config.getWorldConfig;
import org.bukkit.Location;
import org.bukkit.entity.Player;
import org.bukkit.event.EventHandler;
import org.bukkit.event.EventPriority;
import org.bukkit.event.block.Action;
import org.bukkit.event.player.PlayerInteractEvent;
import de.diddiz.LogBlock.LogBlock;
import de.diddiz.LogBlock.Logging;
import de.diddiz.LogBlock.config.WorldConfig;
public class InteractLogging extends LoggingListener
{
public InteractLogging(LogBlock lb) {
super(lb);
}
@EventHandler(priority = EventPriority.MONITOR)
public void onPlayerInteract(PlayerInteractEvent event) {
final WorldConfig wcfg = getWorldConfig(event.getPlayer().getWorld());
if (!event.isCancelled() && wcfg != null && (event.getAction() == Action.LEFT_CLICK_BLOCK || event.getAction() == Action.RIGHT_CLICK_BLOCK)) {
final int type = event.getClickedBlock().getTypeId();
final Player player = event.getPlayer();
final Location loc = event.getClickedBlock().getLocation();
switch (type) {
case 69:
case 77:
if (wcfg.isLogging(Logging.SWITCHINTERACT))
consumer.queueBlock(player.getName(), loc, type, type, (byte)0);
break;
case 107:
if (event.getAction() != Action.RIGHT_CLICK_BLOCK)
break;
case 64:
case 96:
if (wcfg.isLogging(Logging.DOORINTERACT))
consumer.queueBlock(player.getName(), loc, type, type, (byte)((event.getClickedBlock().getData() & 4) / 4));
break;
case 92:
if (wcfg.isLogging(Logging.CAKEEAT) && player.getFoodLevel() < 20)
consumer.queueBlock(player.getName(), loc, 92, 92, (byte)0);
break;
case 25:
if (wcfg.isLogging(Logging.NOTEBLOCKINTERACT))
consumer.queueBlock(player.getName(), loc, 25, 25, (byte)0);
break;
case 93:
case 94:
if (wcfg.isLogging(Logging.DIODEINTERACT) && event.getAction() == Action.RIGHT_CLICK_BLOCK)
consumer.queueBlock(player.getName(), loc, type, type, (byte)0);
break;
}
}
}
}
@@ -0,0 +1,46 @@
package de.diddiz.LogBlock.listeners;
import static de.diddiz.LogBlock.config.Config.isLogging;
import static de.diddiz.LogBlock.config.Config.logKillsLevel;
import java.util.HashMap;
import java.util.Map;
import org.bukkit.entity.Entity;
import org.bukkit.entity.LivingEntity;
import org.bukkit.entity.Monster;
import org.bukkit.entity.Player;
import org.bukkit.event.EventHandler;
import org.bukkit.event.EventPriority;
import org.bukkit.event.entity.EntityDamageByEntityEvent;
import org.bukkit.event.entity.EntityDamageEvent;
import de.diddiz.LogBlock.LogBlock;
import de.diddiz.LogBlock.Logging;
import de.diddiz.LogBlock.config.Config.LogKillsLevel;
public class KillLogging extends LoggingListener
{
private final Map<Integer, Integer> lastAttackedEntity = new HashMap<Integer, Integer>();
private final Map<Integer, Long> lastAttackTime = new HashMap<Integer, Long>();
public KillLogging(LogBlock lb) {
super(lb);
}
@EventHandler(priority = EventPriority.MONITOR)
public void onEntityDamage(EntityDamageEvent event) {
if (!event.isCancelled() && isLogging(event.getEntity().getWorld(), Logging.KILL) && event instanceof EntityDamageByEntityEvent && event.getEntity() instanceof LivingEntity) {
final LivingEntity victim = (LivingEntity)event.getEntity();
final Entity killer = ((EntityDamageByEntityEvent)event).getDamager();
if (victim.getHealth() - event.getDamage() > 0 || victim.getHealth() <= 0)
return;
if (logKillsLevel == LogKillsLevel.PLAYERS && !(victim instanceof Player && killer instanceof Player))
return;
else if (logKillsLevel == LogKillsLevel.MONSTERS && !((victim instanceof Player || victim instanceof Monster) && killer instanceof Player || killer instanceof Monster))
return;
if (lastAttackedEntity.containsKey(killer.getEntityId()) && lastAttackedEntity.get(killer.getEntityId()) == victim.getEntityId() && System.currentTimeMillis() - lastAttackTime.get(killer.getEntityId()) < 5000)
return;
consumer.queueKill(killer, victim);
lastAttackedEntity.put(killer.getEntityId(), victim.getEntityId());
lastAttackTime.put(killer.getEntityId(), System.currentTimeMillis());
}
}
}
@@ -0,0 +1,21 @@
package de.diddiz.LogBlock.listeners;
import static de.diddiz.LogBlock.config.Config.isLogging;
import org.bukkit.event.EventHandler;
import org.bukkit.event.EventPriority;
import org.bukkit.event.block.LeavesDecayEvent;
import de.diddiz.LogBlock.LogBlock;
import de.diddiz.LogBlock.Logging;
public class LeavesDecayLogging extends LoggingListener
{
public LeavesDecayLogging(LogBlock lb) {
super(lb);
}
@EventHandler(priority = EventPriority.MONITOR)
public void onLeavesDecay(LeavesDecayEvent event) {
if (!event.isCancelled() && isLogging(event.getBlock().getWorld(), Logging.LEAVESDECAY))
consumer.queueBlockBreak("LeavesDecay", event.getBlock().getState());
}
}
@@ -0,0 +1,14 @@
package de.diddiz.LogBlock.listeners;
import org.bukkit.event.Listener;
import de.diddiz.LogBlock.Consumer;
import de.diddiz.LogBlock.LogBlock;
public class LoggingListener implements Listener
{
protected final Consumer consumer;
public LoggingListener(LogBlock lb) {
consumer = lb.getConsumer();
}
}
@@ -0,0 +1,24 @@
package de.diddiz.LogBlock.listeners;
import org.bukkit.event.EventHandler;
import org.bukkit.event.EventPriority;
import org.bukkit.event.player.PlayerJoinEvent;
import org.bukkit.event.player.PlayerQuitEvent;
import de.diddiz.LogBlock.LogBlock;
public class PlayerInfoLogging extends LoggingListener
{
public PlayerInfoLogging(LogBlock lb) {
super(lb);
}
@EventHandler(priority = EventPriority.MONITOR)
public void onPlayerJoin(PlayerJoinEvent event) {
consumer.queueJoin(event.getPlayer());
}
@EventHandler(priority = EventPriority.MONITOR)
public void onPlayerQuit(PlayerQuitEvent event) {
consumer.queueLeave(event.getPlayer());
}
}
@@ -0,0 +1,21 @@
package de.diddiz.LogBlock.listeners;
import static de.diddiz.LogBlock.config.Config.isLogging;
import org.bukkit.event.EventHandler;
import org.bukkit.event.EventPriority;
import org.bukkit.event.block.SignChangeEvent;
import de.diddiz.LogBlock.LogBlock;
import de.diddiz.LogBlock.Logging;
public class SignChangeLogging extends LoggingListener
{
public SignChangeLogging(LogBlock lb) {
super(lb);
}
@EventHandler(priority = EventPriority.MONITOR)
public void onSignChange(SignChangeEvent event) {
if (!event.isCancelled() && isLogging(event.getBlock().getWorld(), Logging.SIGNTEXT))
consumer.queueSignPlace(event.getPlayer().getName(), event.getBlock().getLocation(), event.getBlock().getTypeId(), event.getBlock().getData(), event.getLines());
}
}
@@ -0,0 +1,24 @@
package de.diddiz.LogBlock.listeners;
import static de.diddiz.LogBlock.config.Config.isLogging;
import org.bukkit.event.EventHandler;
import org.bukkit.event.EventPriority;
import org.bukkit.event.block.BlockFadeEvent;
import de.diddiz.LogBlock.LogBlock;
import de.diddiz.LogBlock.Logging;
public class SnowFadeLogging extends LoggingListener
{
public SnowFadeLogging(LogBlock lb) {
super(lb);
}
@EventHandler(priority = EventPriority.MONITOR)
public void onBlockFade(BlockFadeEvent event) {
if (!event.isCancelled() && isLogging(event.getBlock().getWorld(), Logging.SNOWFADE)) {
final int type = event.getBlock().getTypeId();
if (type == 78 || type == 79)
consumer.queueBlockReplace("SnowFade", event.getBlock().getState(), event.getNewState());
}
}
}
@@ -0,0 +1,31 @@
package de.diddiz.LogBlock.listeners;
import static de.diddiz.LogBlock.config.Config.isLogging;
import org.bukkit.event.EventHandler;
import org.bukkit.event.EventPriority;
import org.bukkit.event.block.BlockFormEvent;
import org.bukkit.event.block.LeavesDecayEvent;
import de.diddiz.LogBlock.LogBlock;
import de.diddiz.LogBlock.Logging;
public class SnowFormLogging extends LoggingListener
{
public SnowFormLogging(LogBlock lb) {
super(lb);
}
@EventHandler(priority = EventPriority.MONITOR)
public void onLeavesDecay(LeavesDecayEvent event) {
if (!event.isCancelled() && isLogging(event.getBlock().getWorld(), Logging.SNOWFORM))
consumer.queueBlockBreak("LeavesDecay", event.getBlock().getState());
}
@EventHandler(priority = EventPriority.MONITOR)
public void onBlockForm(BlockFormEvent event) {
if (!event.isCancelled() && isLogging(event.getBlock().getWorld(), Logging.SNOWFORM)) {
final int type = event.getNewState().getTypeId();
if (type == 78 || type == 79)
consumer.queueBlockReplace("SnowForm", event.getBlock().getState(), event.getNewState());
}
}
}
@@ -1,23 +1,23 @@
package de.diddiz.LogBlock;
package de.diddiz.LogBlock.listeners;
import java.util.Map;
import static de.diddiz.LogBlock.config.Config.getWorldConfig;
import org.bukkit.block.BlockState;
import org.bukkit.event.EventHandler;
import org.bukkit.event.EventPriority;
import org.bukkit.event.world.StructureGrowEvent;
import org.bukkit.event.world.WorldListener;
import de.diddiz.LogBlock.LogBlock;
import de.diddiz.LogBlock.Logging;
import de.diddiz.LogBlock.config.WorldConfig;
public class LBWorldListener extends WorldListener
public class StructureGrowLogging extends LoggingListener
{
private final Consumer consumer;
private final Map<Integer, WorldConfig> worlds;
LBWorldListener(LogBlock logblock) {
consumer = logblock.getConsumer();
worlds = logblock.getLBConfig().worlds;
public StructureGrowLogging(LogBlock lb) {
super(lb);
}
@Override
@EventHandler(priority = EventPriority.MONITOR)
public void onStructureGrow(StructureGrowEvent event) {
final WorldConfig wcfg = worlds.get(event.getWorld().getName().hashCode());
final WorldConfig wcfg = getWorldConfig(event.getWorld());
if (!event.isCancelled() && wcfg != null) {
final String playerName;
if (event.getPlayer() != null) {
@@ -1,44 +1,48 @@
package de.diddiz.LogBlock;
package de.diddiz.LogBlock.listeners;
import static de.diddiz.LogBlock.Session.getSession;
import static de.diddiz.LogBlock.Session.hasSession;
import java.util.Map;
import static de.diddiz.LogBlock.config.Config.isLogged;
import static de.diddiz.LogBlock.config.Config.toolsByType;
import java.util.Map.Entry;
import org.bukkit.ChatColor;
import org.bukkit.World;
import org.bukkit.block.Block;
import org.bukkit.block.BlockFace;
import org.bukkit.entity.Player;
import org.bukkit.event.EventHandler;
import org.bukkit.event.Listener;
import org.bukkit.event.block.Action;
import org.bukkit.event.player.PlayerChangedWorldEvent;
import org.bukkit.event.player.PlayerCommandPreprocessEvent;
import org.bukkit.event.player.PlayerInteractEvent;
import org.bukkit.event.player.PlayerListener;
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;
import de.diddiz.LogBlock.Session;
import de.diddiz.LogBlock.Tool;
import de.diddiz.LogBlock.ToolBehavior;
import de.diddiz.LogBlock.ToolData;
import de.diddiz.LogBlock.ToolMode;
class LBToolListener extends PlayerListener
public class ToolListener implements Listener
{
private final CommandsHandler handler;
private final LogBlock logblock;
private final Map<Integer, Tool> toolsByType;
private final Map<Integer, WorldConfig> worlds;
LBToolListener(LogBlock logblock) {
public ToolListener(LogBlock logblock) {
this.logblock = logblock;
handler = logblock.getCommandsHandler();
worlds = logblock.getLBConfig().worlds;
toolsByType = logblock.getLBConfig().toolsByType;
}
@Override
@EventHandler
public void onPlayerInteract(PlayerInteractEvent event) {
if (!event.isCancelled() && event.getMaterial() != null) {
final Action action = event.getAction();
final int type = event.getMaterial().getId();
final Tool tool = toolsByType.get(type);
final Player player = event.getPlayer();
if (tool != null && (action == Action.RIGHT_CLICK_BLOCK || action == Action.LEFT_CLICK_BLOCK) && worlds.containsKey(player.getWorld().getName().hashCode()) && logblock.hasPermission(player, "logblock.tools." + tool.name)) {
if (tool != null && (action == Action.RIGHT_CLICK_BLOCK || action == Action.LEFT_CLICK_BLOCK) && isLogged(player.getWorld()) && logblock.hasPermission(player, "logblock.tools." + tool.name)) {
final ToolBehavior behavior = action == Action.RIGHT_CLICK_BLOCK ? tool.rightClickBehavior : tool.leftClickBehavior;
final ToolData toolData = getSession(player).toolData.get(tool);
if (behavior != ToolBehavior.NONE && toolData.enabled) {
@@ -77,30 +81,7 @@ class LBToolListener extends PlayerListener
}
}
@Override
public void onPlayerCommandPreprocess(final PlayerCommandPreprocessEvent event) {
final String[] split = event.getMessage().split(" ");
if (split.length > 1 && split[0].equalsIgnoreCase("/ban") && logblock.hasPermission(event.getPlayer(), logblock.getLBConfig().banPermission)) {
final QueryParams p = new QueryParams(logblock);
p.setPlayer(split[1].equalsIgnoreCase("g") ? split[2] : split[1]);
p.since = 0;
p.silent = false;
logblock.getServer().getScheduler().scheduleAsyncDelayedTask(logblock, new Runnable() {
@Override
public void run() {
for (final World world : logblock.getServer().getWorlds())
if (worlds.get(world.getName().hashCode()) != null) {
p.world = world;
try {
handler.new CommandRollback(event.getPlayer(), p, false);
} catch (final Exception ex) {}
}
}
});
}
}
@Override
@EventHandler
public void onPlayerChangedWorld(PlayerChangedWorldEvent event) {
final Player player = event.getPlayer();
if (hasSession(player)) {