diff --git a/src/de/diddiz/LogBlock/CommandsHandler.java b/src/de/diddiz/LogBlock/CommandsHandler.java index e361fe6..924fbe1 100644 --- a/src/de/diddiz/LogBlock/CommandsHandler.java +++ b/src/de/diddiz/LogBlock/CommandsHandler.java @@ -355,7 +355,7 @@ public class CommandsHandler implements CommandExecutor @Override public void run() { try { - rs = state.executeQuery(params.getQuery()); + rs = state.executeQuery(params.getLookupQuery()); sender.sendMessage(ChatColor.DARK_AQUA + params.getTitle()); if (rs.next()) { rs.beforeFirst(); @@ -366,7 +366,7 @@ public class CommandsHandler implements CommandExecutor else if (sum == SummarizationMode.PLAYERS) sender.sendMessage(ChatColor.GOLD + String.format("%-6s %-6s %s", "Created", "Destroyed", "Playername")); while (rs.next()) - sender.sendMessage(ChatColor.GOLD + histformatter.format(rs)); + sender.sendMessage(ChatColor.GOLD + histformatter.format(rs, params.coords)); } else sender.sendMessage(ChatColor.DARK_AQUA + "No results found."); } catch (final SQLException ex) { @@ -388,7 +388,7 @@ public class CommandsHandler implements CommandExecutor public void run() { File file = null; try { - rs = state.executeQuery(params.getQuery()); + rs = state.executeQuery(params.getLookupQuery()); file = new File("plugins/LogBlock/log/" + params.getTitle() + ".log"); file.createNewFile(); final FileWriter writer = new FileWriter(file); @@ -397,7 +397,7 @@ public class CommandsHandler implements CommandExecutor file.getParentFile().mkdirs(); sender.sendMessage(ChatColor.GREEN + "Creating " + file.getName()); while (rs.next()) - writer.write(histformatter.format(rs) + newline); + writer.write(histformatter.format(rs, params.coords) + newline); writer.close(); sender.sendMessage(ChatColor.GREEN + "Done"); } catch (final SQLException ex) { diff --git a/src/de/diddiz/LogBlock/HistoryFormatter.java b/src/de/diddiz/LogBlock/HistoryFormatter.java index 885a840..22d05d2 100644 --- a/src/de/diddiz/LogBlock/HistoryFormatter.java +++ b/src/de/diddiz/LogBlock/HistoryFormatter.java @@ -15,7 +15,7 @@ public class HistoryFormatter this.sum = sum; } - String format(ResultSet rs) throws SQLException { + String format(ResultSet rs, boolean coords) throws SQLException { if (sum == SummarizationMode.NONE) { final StringBuilder msg = new StringBuilder(formatter.format(rs.getTimestamp("date")) + " " + rs.getString("playername") + " "); final int type = rs.getInt("type"); @@ -50,6 +50,8 @@ public class HistoryFormatter msg.append("created " + getMaterialName(type)); else msg.append("replaced " + getMaterialName(replaced) + " with " + getMaterialName(type)); + if (coords) + msg.append(" at " + rs.getInt("x") + ":" + rs.getInt("y") + ":" + rs.getInt("z")); return msg.toString(); } else if (sum == SummarizationMode.TYPES) return fillWithSpaces(rs.getInt("created")) + fillWithSpaces(rs.getInt("destroyed")) + getMaterialName(rs.getInt("type")); diff --git a/src/de/diddiz/LogBlock/QueryParams.java b/src/de/diddiz/LogBlock/QueryParams.java index 0b06894..d24878c 100644 --- a/src/de/diddiz/LogBlock/QueryParams.java +++ b/src/de/diddiz/LogBlock/QueryParams.java @@ -23,13 +23,13 @@ import com.sk89q.worldedit.bukkit.selections.Selection; public class QueryParams implements Cloneable { - private static final HashSet 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())); + private static final HashSet 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())); public BlockChangeType bct = BlockChangeType.BOTH; public int limit = 15, minutes = 0, radius = -1; public Location loc = null; public Order order = Order.DESC; public List players = new ArrayList(); - public boolean prepareToolQuery = false; + public boolean prepareToolQuery = false, coords = false; public Selection sel = null; public SummarizationMode sum = SummarizationMode.NONE; public List types = new ArrayList(); @@ -61,10 +61,12 @@ public class QueryParams implements Cloneable return "ORDER BY date " + order + ", id " + order + " "; } - public String getQuery() { + public String getLookupQuery() { if (sum == SummarizationMode.NONE) { String select = "SELECT date, replaced, type, playername"; String from = "FROM `" + getTable() + "` INNER JOIN `lb-players` USING (playerid) "; + if (coords) + select += ", x, y, z"; if (types.size() == 0 || types.contains(63) || types.contains(68)) { select += ", signtext"; from += "LEFT JOIN `" + getTable() + "-sign` USING (id) "; @@ -310,6 +312,8 @@ public class QueryParams implements Cloneable order = Order.ASC; else if (param.equals("desc")) order = Order.DESC; + else if (param.equals("coords")) + coords = true; else throw new IllegalArgumentException("Not a valid argument: '" + param + "'"); if (values != null)