From b1296194c81964d23e338b568af23d240c2ab2f5 Mon Sep 17 00:00:00 2001 From: Robin Kupper Date: Tue, 2 Aug 2011 19:57:32 +0200 Subject: [PATCH] Minor fixes and improvements --- src/de/diddiz/LogBlock/CommandsHandler.java | 25 ++++++++------------- src/de/diddiz/LogBlock/QueryParams.java | 15 +++++-------- 2 files changed, 15 insertions(+), 25 deletions(-) diff --git a/src/de/diddiz/LogBlock/CommandsHandler.java b/src/de/diddiz/LogBlock/CommandsHandler.java index 38f52a1..76fe6d7 100644 --- a/src/de/diddiz/LogBlock/CommandsHandler.java +++ b/src/de/diddiz/LogBlock/CommandsHandler.java @@ -260,7 +260,6 @@ public class CommandsHandler implements CommandExecutor else if (args[0].equalsIgnoreCase("savequeue")) { if (logblock.hasPermission(sender, "logblock.rollback")) new CommandSaveQueue(sender, null, true); - else sender.sendMessage(ChatColor.RED + "You aren't allowed to do this."); } else if (command.equals("rollback") || command.equals("undo") || command.equals("rb")) { @@ -418,16 +417,16 @@ public class CommandsHandler implements CommandExecutor params.needSignText = true; if (params.types.size() == 0 || params.types.contains(23) || params.types.contains(54) || params.types.contains(61) || params.types.contains(62)) params.needChestAccess = true; + if (params.limit < 0 && params.sum == SummarizationMode.NONE) + params.limit = config.linesLimit; conn = logblock.getConnection(); state = conn.createStatement(); - if (params.limit == 15 && params.sum == SummarizationMode.NONE) - params.limit = config.linesLimit; rs = state.executeQuery(params.getQuery()); sender.sendMessage(ChatColor.DARK_AQUA + params.getTitle() + ":"); - final List blockchanges = new ArrayList(); if (rs.next()) { rs.beforeFirst(); if (params.sum == SummarizationMode.NONE) { + final List blockchanges = new ArrayList(); while (rs.next()) blockchanges.add(new BlockChange(rs, params)); logblock.getSession(senderName(sender)).lookupCache = blockchanges.toArray(new BlockChange[blockchanges.size()]); @@ -564,7 +563,6 @@ public class CommandsHandler implements CommandExecutor params.needData = true; params.needSignText = true; params.needChestAccess = true; - params.limit = -1; params.order = Order.DESC; params.sum = SummarizationMode.NONE; conn = logblock.getConnection(); @@ -624,7 +622,6 @@ public class CommandsHandler implements CommandExecutor params.needData = true; params.needSignText = true; params.needChestAccess = true; - params.limit = -1; params.order = Order.ASC; params.sum = SummarizationMode.NONE; conn = logblock.getConnection(); @@ -676,14 +673,10 @@ public class CommandsHandler implements CommandExecutor final File dumpFolder = new File(logblock.getDataFolder(), "dump"); if (!dumpFolder.exists()) dumpFolder.mkdirs(); - final SimpleDateFormat formatter = new SimpleDateFormat("yyMMddHHmmss"); + final String time = new SimpleDateFormat("yyMMddHHmmss").format(System.currentTimeMillis()); int deleted; final String table = params.getTable(); - final String join; - if (params.players.size() > 0) - join = "INNER JOIN `lb-players` USING (playerid) "; - else - join = ""; + final String join = params.players.size() > 0 ? "INNER JOIN `lb-players` USING (playerid) " : ""; rs = state.executeQuery("SELECT count(*) FROM `" + table + "` " + join + params.getWhere()); rs.next(); if ((deleted = rs.getInt(1)) > 0) { @@ -697,10 +690,10 @@ public class CommandsHandler implements CommandExecutor } if (config.dumpDeletedLog) try { - state.execute("SELECT * FROM `" + table + "` " + join + params.getWhere() + "INTO OUTFILE '" + new File(dumpFolder, formatter.format(System.currentTimeMillis()) + " " + table + " " + params.getTitle().replace(":", ".") + ".csv").getAbsolutePath().replace("\\", "\\\\") + "' FIELDS TERMINATED BY ',' OPTIONALLY ENCLOSED BY '\"' LINES TERMINATED BY '\n'"); + 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) { sender.sendMessage(ChatColor.RED + "Error while dumping log. Make sure your MySQL user has access to the LogBlock folder, or disable clearlog.dumpDeletedLog"); - log.log(Level.SEVERE, "[LogBlock ClearLog] Exception while dumping", ex); + log.log(Level.SEVERE, "[LogBlock ClearLog] Exception while dumping log: ", ex); return; } state.execute("DELETE `" + table + "` FROM `" + table + "` " + join + params.getWhere()); @@ -710,7 +703,7 @@ public class CommandsHandler implements CommandExecutor rs.next(); if ((deleted = rs.getInt(1)) > 0) { if (config.dumpDeletedLog) - state.execute("SELECT id, signtext FROM `" + table + "-sign` LEFT JOIN `" + table + "` USING (id) WHERE `" + table + "`.id IS NULL INTO OUTFILE '" + new File(dumpFolder, formatter.format(System.currentTimeMillis()) + " " + table + "-sign " + params.getTitle() + ".csv").getAbsolutePath().replace("\\", "\\\\") + "' FIELDS TERMINATED BY ',' OPTIONALLY ENCLOSED BY '\"' LINES TERMINATED BY '\n'"); + state.execute("SELECT id, signtext FROM `" + table + "-sign` LEFT JOIN `" + table + "` USING (id) WHERE `" + table + "`.id IS NULL INTO OUTFILE '" + new File(dumpFolder, 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."); } @@ -718,7 +711,7 @@ public class CommandsHandler implements CommandExecutor rs.next(); if ((deleted = rs.getInt(1)) > 0) { if (config.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, formatter.format(System.currentTimeMillis()) + " " + table + "-chest " + params.getTitle() + ".csv").getAbsolutePath().replace("\\", "\\\\") + "' FIELDS TERMINATED BY ',' OPTIONALLY ENCLOSED BY '\"' LINES TERMINATED BY '\n'"); + 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."); } diff --git a/src/de/diddiz/LogBlock/QueryParams.java b/src/de/diddiz/LogBlock/QueryParams.java index d9554ea..ce6866c 100644 --- a/src/de/diddiz/LogBlock/QueryParams.java +++ b/src/de/diddiz/LogBlock/QueryParams.java @@ -26,7 +26,7 @@ public class QueryParams implements Cloneable { private static final Set keywords = new HashSet(Arrays.asList("player".hashCode(), "area".hashCode(), "selection".hashCode(), "sel".hashCode(), "block".hashCode(), "type".hashCode(), "sum".hashCode(), "destroyed".hashCode(), "created".hashCode(), "chestaccess".hashCode(), "all".hashCode(), "time".hashCode(), "since".hashCode(), "before".hashCode(), "limit".hashCode(), "world".hashCode(), "asc".hashCode(), "desc".hashCode(), "last".hashCode(), "coords".hashCode(), "silent".hashCode())); public BlockChangeType bct = BlockChangeType.BOTH; - public int limit = 15, minutes = 0, radius = -1; + public int limit = -1, minutes = 0, radius = -1; public Location loc = null; public Order order = Order.DESC; public List players = new ArrayList(); @@ -55,10 +55,6 @@ public class QueryParams implements Cloneable return limit > 0 ? "LIMIT " + limit : ""; } - // public String getRollbackQuery() { - // return "SELECT replaced, type, data, x, y, z, signtext, itemtype, itemamount, itemdata FROM `" + getTable() + "` " + (players.size() > 0 ? "INNER JOIN `lb-players` USING (playerid) " : "") + "LEFT JOIN `" + getTable() + "-sign` USING (id) LEFT JOIN `" + getTable() + "-chest` USING (id) " + getWhere() + getOrderBy() + getLimit(); - // } - public String getQuery() { if (sum == SummarizationMode.NONE) { String select = "SELECT "; @@ -295,9 +291,9 @@ public class QueryParams implements Cloneable throw new IllegalArgumentException("Failed to parse time spec for '" + param + "'"); } else if (param.equals("before")) { if (values == null) - minutes = logblock.getConfig().defaultTime * -1; + minutes = -logblock.getConfig().defaultTime; else - minutes = parseTimeSpec(values) * -1; + minutes = -parseTimeSpec(values); if (minutes == 1) throw new IllegalArgumentException("Faile to parse time spec for '" + param + "'"); } else if (param.equals("sum")) { @@ -328,9 +324,10 @@ public class QueryParams implements Cloneable } else if (param.equals("world")) { if (values.length != 1) throw new IllegalArgumentException("Wrong count of arguments for '" + param + "'"); - if (sender.getServer().getWorld(values[0]) == null) + final World w = sender.getServer().getWorld(values[0].replace("\"", "")); + if (w == null) throw new IllegalArgumentException("There is no world called '" + values[0] + "'"); - world = sender.getServer().getWorld(values[0]); + world = w; } else if (param.equals("asc")) order = Order.ASC; else if (param.equals("desc"))