diff --git a/src/de/diddiz/LogBlock/Consumer.java b/src/de/diddiz/LogBlock/Consumer.java index a80dd27..6f5e8cf 100644 --- a/src/de/diddiz/LogBlock/Consumer.java +++ b/src/de/diddiz/LogBlock/Consumer.java @@ -178,7 +178,7 @@ public class Consumer extends TimerTask int weapon = 0; if (killer instanceof Player && ((Player)killer).getItemInHand() != null) weapon = ((Player)killer).getItemInHand().getTypeId(); - queueKill(victim.getWorld(), entityName(killer), entityName(victim), weapon); + queueKill(victim.getLocation(), entityName(killer), entityName(victim), weapon); } /** @@ -190,11 +190,32 @@ public class Consumer extends TimerTask * Name of the victim. Can't be null. * @param weapon * Item id of the weapon. 0 for no weapon. + * @deprecated Use {@link #queueKill(Location,String,String,int)} instead */ + @Deprecated public void queueKill(World world, String killerName, String victimName, int weapon) { - if (victimName == null || !worlds.containsKey(world.getName().hashCode())) + queueKill( + new Location(world,0,0,0), + killerName, + victimName, + weapon + ); + } + + /** + * @param location + * Location of the victim. + * @param killerName + * Name of the killer. Can be null. + * @param victimName + * Name of the victim. Can't be null. + * @param weapon + * 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())) return; - queue.add(new KillRow(world.getName().hashCode(), killerName.replaceAll("[^a-zA-Z0-9_]", ""), victimName.replaceAll("[^a-zA-Z0-9_]", ""), weapon)); + queue.add(new KillRow(location, killerName == null ? null : killerName.replaceAll("[^a-zA-Z0-9_]", ""), victimName.replaceAll("[^a-zA-Z0-9_]", ""), weapon)); } /** @@ -394,11 +415,11 @@ public class Consumer extends TimerTask final long date; final String killer, victim; final int weapon; - final int worldHash; + final Location loc; - KillRow(int worldHash, String attacker, String defender, int weapon) { + KillRow(Location loc, String attacker, String defender, int weapon) { date = System.currentTimeMillis() / 1000; - this.worldHash = worldHash; + this.loc = loc; killer = attacker; victim = defender; this.weapon = weapon; @@ -406,7 +427,7 @@ public class Consumer extends TimerTask @Override public String[] getInserts() { - return new String[]{"INSERT INTO `" + worlds.get(worldHash).table + "-kills` (date, killer, victim, weapon) VALUES (FROM_UNIXTIME(" + date + "), " + playerID(killer) + ", " + playerID(victim) + ", " + weapon + ");"}; + 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() + ");"}; } @Override diff --git a/src/de/diddiz/LogBlock/Updater.java b/src/de/diddiz/LogBlock/Updater.java index 246bc32..04a95d6 100644 --- a/src/de/diddiz/LogBlock/Updater.java +++ b/src/de/diddiz/LogBlock/Updater.java @@ -137,6 +137,26 @@ class Updater config.set("clearlog.keepLogDays", null); config.set("version", "1.42"); } + if (config.getString("version").compareTo("1.51" /* FIXME: Needs correct version number */) < 0) { + getLogger().info("[LogBlock] Updating tables to 1.51 ...");//FIXME: Needs correct version number + final Connection conn = logblock.getConnection(); + try { + conn.setAutoCommit(true); + final Statement st = conn.createStatement(); + for (final WorldConfig wcfg : logblock.getLBConfig().worlds.values()) { + 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(); + conn.close(); + } catch (final SQLException ex) { + Bukkit.getLogger().log(Level.SEVERE, "[LogBlock Updater] Error: ", ex); + return false; + } + config.set("version", "1.51" /* FIXME: Needs correct version number */); + } logblock.saveConfig(); return true; } @@ -156,7 +176,7 @@ class Updater 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))"); if (wcfg.isLogging(Logging.KILL)) - createTable(dbm, state, wcfg.table + "-kills", "(id INT UNSIGNED NOT NULL AUTO_INCREMENT, date DATETIME NOT NULL, killer SMALLINT UNSIGNED, victim SMALLINT UNSIGNED NOT NULL, weapon SMALLINT UNSIGNED NOT NULL, PRIMARY KEY (id))"); + createTable(dbm, state, wcfg.table + "-kills", "(id INT UNSIGNED NOT NULL AUTO_INCREMENT, date DATETIME NOT NULL, killer SMALLINT UNSIGNED, victim SMALLINT UNSIGNED NOT NULL, weapon SMALLINT UNSIGNED NOT NULL, x SMALLINT NOT NULL, y TINYINT UNSIGNED NOT NULL, z SMALLINT NOT NULL, PRIMARY KEY (id))"); } state.close(); conn.close();