Added per world config

This commit is contained in:
Robin Kupper
2011-07-20 20:37:23 +02:00
parent 094a185764
commit 8568698469
8 changed files with 173 additions and 96 deletions

View File

@@ -1,6 +1,8 @@
package de.diddiz.LogBlock;
import static de.diddiz.util.BukkitUtils.friendlyWorldname;
import static de.diddiz.util.Utils.parseTimeSpec;
import java.io.File;
import java.io.IOException;
import java.util.ArrayList;
import java.util.Arrays;
@@ -16,13 +18,13 @@ import org.bukkit.util.config.Configuration;
public class Config
{
public final Map<Integer, String> tables;
public final Map<Integer, WorldConfig> worlds;
public final String url, user, password;
public final int delayBetweenRuns, forceToProcessAtLeast, timePerRun;
public final boolean useBukkitScheduler;
public final int keepLogDays;
public final boolean dumpDeletedLog;
public final boolean logBlockCreations, logBlockDestroyings, logSignTexts, logExplosions, logFire, logLeavesDecay, logLavaFlow, logChestAccess, logButtonsAndLevers, logKills, logChat;
public boolean logBlockCreations, logBlockDestroyings, logSignTexts, logExplosions, logFire, logLeavesDecay, logLavaFlow, logChestAccess, logButtonsAndLevers, logKills, logChat;
public final boolean logCreeperExplosionsAsPlayerWhoTriggeredThese;
public final LogKillsLevel logKillsLevel;
public final Set<Integer> dontRollback, replaceAnyway;
@@ -83,32 +85,10 @@ public class Config
subkeys = config.getKeys("logging");
if (subkeys == null)
subkeys = new ArrayList<String>();
if (!subkeys.contains("logBlockCreations"))
config.setProperty("logging.logBlockCreations", true);
if (!subkeys.contains("logBlockDestroyings"))
config.setProperty("logging.logBlockDestroyings", true);
if (!subkeys.contains("logSignTexts"))
config.setProperty("logging.logSignTexts", false);
if (!subkeys.contains("logExplosions"))
config.setProperty("logging.logExplosions", false);
if (!subkeys.contains("logCreeperExplosionsAsPlayerWhoTriggeredThese"))
config.setProperty("logging.logCreeperExplosionsAsPlayerWhoTriggeredThese", false);
if (!subkeys.contains("logFire"))
config.setProperty("logging.logFire", false);
if (!subkeys.contains("logLeavesDecay"))
config.setProperty("logging.logLeavesDecay", false);
if (!subkeys.contains("logLavaFlow"))
config.setProperty("logging.logLavaFlow", false);
if (!subkeys.contains("logChestAccess"))
config.setProperty("logging.logChestAccess", false);
if (!subkeys.contains("logButtonsAndLevers"))
config.setProperty("logging.logButtonsAndLevers", false);
if (!subkeys.contains("logKills"))
config.setProperty("logging.logKills", false);
if (!subkeys.contains("logKillsLevel"))
config.setProperty("logging.logKillsLevel", "PLAYERS");
if (!subkeys.contains("logChat"))
config.setProperty("logging.logChat", false);
if (!subkeys.contains("hiddenPlayers"))
config.setProperty("logging.hiddenPlayers", new ArrayList<String>());
if (!subkeys.contains("hiddenBlocks"))
@@ -165,18 +145,7 @@ public class Config
if (keepLogDays * 86400000L > System.currentTimeMillis())
throw new DataFormatException("Too large timespan for keepLogDays. Must be shorter than " + (int)(System.currentTimeMillis() / 86400000L) + " days.");
dumpDeletedLog = config.getBoolean("clearlog.dumpDeletedLog", false);
logBlockCreations = config.getBoolean("logging.logBlockCreations", true);
logBlockDestroyings = config.getBoolean("logging.logBlockDestroyings", true);
logSignTexts = config.getBoolean("logging.logSignTexts", false);
logExplosions = config.getBoolean("logging.logExplosions", false);
logCreeperExplosionsAsPlayerWhoTriggeredThese = config.getBoolean("logging.logCreeperExplosionsAsPlayerWhoTriggeredThese", false);
logFire = config.getBoolean("logging.logFire", false);
logChestAccess = config.getBoolean("logging.logChestAccess", false);
logButtonsAndLevers = config.getBoolean("logging.logButtonsAndLevers", false);
logLeavesDecay = config.getBoolean("logging.logLeavesDecay", false);
logLavaFlow = config.getBoolean("logging.logLavaFlow", false);
logKills = config.getBoolean("logging.logKills", false);
logChat = config.getBoolean("logging.logChat", false);
try {
logKillsLevel = LogKillsLevel.valueOf(config.getString("logging.logKillsLevel"));
} catch (final IllegalArgumentException ex) {
@@ -225,11 +194,84 @@ public class Config
askRedos = config.getBoolean("questioner.askRedos", true);
askClearLogs = config.getBoolean("questioner.askClearLogs", true);
final List<String> worldNames = config.getStringList("loggedWorlds", null);
final List<String> worldTables = config.getStringList("tables", null);
tables = new HashMap<Integer, String>();
if (worldNames == null || worldTables == null || worldNames.size() == 0 || worldNames.size() != worldTables.size())
throw new DataFormatException("worldNames or worldTables not set properly");
for (int i = 0; i < worldNames.size(); i++)
tables.put(worldNames.get(i).hashCode(), worldTables.get(i));
worlds = new HashMap<Integer, WorldConfig>();
if (worldNames == null || worldNames.size() == 0)
throw new DataFormatException("No worlds configured");
for (final String world : worldNames)
worlds.put(world.hashCode(), new WorldConfig(new File("plugins/LogBlock/" + friendlyWorldname(world) + ".yml")));
for (final WorldConfig wcfg : worlds.values()) {
if (wcfg.logBlockCreations)
logBlockCreations = true;
if (wcfg.logBlockDestroyings)
logBlockDestroyings = true;
if (wcfg.logSignTexts)
logSignTexts = true;
if (wcfg.logExplosions)
logExplosions = true;
if (wcfg.logFire)
logFire = true;
if (wcfg.logLeavesDecay)
logLeavesDecay = true;
if (wcfg.logLavaFlow)
logLavaFlow = true;
if (wcfg.logChestAccess)
logChestAccess = true;
if (wcfg.logButtonsAndLevers)
logButtonsAndLevers = true;
if (wcfg.logKills)
logKills = true;
if (wcfg.logChat)
logChat = true;
}
}
}
class WorldConfig
{
public final String table;
public final boolean logBlockCreations, logBlockDestroyings, logSignTexts, logExplosions, logFire, logLeavesDecay, logLavaFlow, logChestAccess, logButtonsAndLevers, logKills, logChat;
public WorldConfig(File file) {
final Configuration config = new Configuration(file);
config.load();
final List<String> keys = config.getKeys(null);
if (!keys.contains("table"))
config.setProperty("table", "lb-" + file.getName().substring(0, file.getName().length() - 4));
if (!keys.contains("logBlockCreations"))
config.setProperty("logBlockCreations", true);
if (!keys.contains("logBlockDestroyings"))
config.setProperty("logBlockDestroyings", true);
if (!keys.contains("logSignTexts"))
config.setProperty("logSignTexts", false);
if (!keys.contains("logExplosions"))
config.setProperty("logExplosions", false);
if (!keys.contains("logFire"))
config.setProperty("logFire", false);
if (!keys.contains("logLeavesDecay"))
config.setProperty("logLeavesDecay", false);
if (!keys.contains("logLavaFlow"))
config.setProperty("logLavaFlow", false);
if (!keys.contains("logChestAccess"))
config.setProperty("logChestAccess", false);
if (!keys.contains("logButtonsAndLevers"))
config.setProperty("logButtonsAndLevers", false);
if (!keys.contains("logKills"))
config.setProperty("logKills", false);
if (!keys.contains("logChat"))
config.setProperty("logChat", false);
config.save();
table = config.getString("table");
logBlockCreations = config.getBoolean("logBlockCreations", true);
logBlockDestroyings = config.getBoolean("logBlockDestroyings", true);
logSignTexts = config.getBoolean("logSignTexts", false);
logExplosions = config.getBoolean("logExplosions", false);
logFire = config.getBoolean("logFire", false);
logLeavesDecay = config.getBoolean("logLeavesDecay", false);
logLavaFlow = config.getBoolean("logLavaFlow", false);
logChestAccess = config.getBoolean("logChestAccess", false);
logButtonsAndLevers = config.getBoolean("logButtonsAndLevers", false);
logKills = config.getBoolean("logKills", false);
logChat = config.getBoolean("logChat", false);
}
}

View File

@@ -34,7 +34,7 @@ public class Consumer extends TimerTask
{
private final Queue<Row> queue = new LinkedBlockingQueue<Row>();
private final Config config;
private final Map<Integer, String> tables;
private final Map<Integer, WorldConfig> worlds;
private final Set<Integer> hiddenPlayers, hiddenBlocks;
private final Map<Integer, Integer> lastAttackedEntity = new HashMap<Integer, Integer>();
private final Map<Integer, Long> lastAttackTime = new HashMap<Integer, Long>();
@@ -49,7 +49,7 @@ public class Consumer extends TimerTask
config = logblock.getConfig();
hiddenPlayers = config.hiddenPlayers;
hiddenBlocks = config.hiddenBlocks;
tables = config.tables;
worlds = config.worlds;
}
/**
@@ -198,7 +198,7 @@ public class Consumer extends TimerTask
* Item id of the weapon. 0 for no weapon.
*/
public void queueKill(World world, String killerName, String victimName, int weapon) {
if (victimName == null || !tables.containsKey(world.getName().hashCode()))
if (victimName == null || !worlds.containsKey(world.getName().hashCode()))
return;
killerName = killerName.replaceAll("[^a-zA-Z0-9_]", "");
victimName = victimName.replaceAll("[^a-zA-Z0-9_]", "");
@@ -332,7 +332,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 || hiddenPlayers.contains(playerName.hashCode()) || !tables.containsKey(loc.getWorld().getName().hashCode()) || typeBefore != typeAfter && hiddenBlocks.contains(typeBefore) && hiddenBlocks.contains(typeAfter))
if (playerName == null || loc == null || typeBefore < 0 || typeAfter < 0 || hiddenPlayers.contains(playerName.hashCode()) || !worlds.containsKey(loc.getWorld().getName().hashCode()) || typeBefore != typeAfter && hiddenBlocks.contains(typeBefore) && hiddenBlocks.contains(typeAfter))
return;
playerName = playerName.replaceAll("[^a-zA-Z0-9_]", "");
if (signtext != null)
@@ -355,12 +355,13 @@ public class Consumer extends TimerTask
@Override
public String[] getInserts() {
final String table = worlds.get(loc.getWorld().getName().hashCode()).table;
final String[] inserts = new String[ca != null || signtext != null ? 2 : 1];
inserts[0] = "INSERT INTO `" + tables.get(loc.getWorld().getName().hashCode()) + "` (date, playerid, replaced, type, data, x, y, z) VALUES (FROM_UNIXTIME(" + date + "), " + players.get(playerName.hashCode()) + ", " + replaced + ", " + type + ", " + data + ", '" + loc.getBlockX() + "', " + loc.getBlockY() + ", '" + loc.getBlockZ() + "');";
inserts[0] = "INSERT INTO `" + table + "` (date, playerid, replaced, type, data, x, y, z) VALUES (FROM_UNIXTIME(" + date + "), " + players.get(playerName.hashCode()) + ", " + replaced + ", " + type + ", " + data + ", '" + loc.getBlockX() + "', " + loc.getBlockY() + ", '" + loc.getBlockZ() + "');";
if (signtext != null)
inserts[1] = "INSERT INTO `" + tables.get(loc.getWorld().getName().hashCode()) + "-sign` (id, signtext) values (LAST_INSERT_ID(), '" + signtext + "');";
inserts[1] = "INSERT INTO `" + table + "-sign` (id, signtext) values (LAST_INSERT_ID(), '" + signtext + "');";
else if (ca != null)
inserts[1] = "INSERT INTO `" + tables.get(loc.getWorld().getName().hashCode()) + "-chest` (id, itemtype, itemamount, itemdata) values (LAST_INSERT_ID(), " + ca.itemType + ", " + ca.itemAmount + ", " + ca.itemData + ");";
inserts[1] = "INSERT INTO `" + table + "-chest` (id, itemtype, itemamount, itemdata) values (LAST_INSERT_ID(), " + ca.itemType + ", " + ca.itemAmount + ", " + ca.itemData + ");";
return inserts;
}
@@ -387,7 +388,7 @@ public class Consumer extends TimerTask
@Override
public String[] getInserts() {
return new String[]{"INSERT INTO `" + tables.get(worldHash) + "-kills` (date, killer, victim, weapon) VALUES (FROM_UNIXTIME(" + date + "), " + (killer == null ? "NULL" : players.get(killer.hashCode())) + ", " + players.get(victim.hashCode()) + ", " + weapon + ");"};
return new String[]{"INSERT INTO `" + worlds.get(worldHash).table + "-kills` (date, killer, victim, weapon) VALUES (FROM_UNIXTIME(" + date + "), " + (killer == null ? "NULL" : players.get(killer.hashCode())) + ", " + players.get(victim.hashCode()) + ", " + weapon + ");"};
}
@Override

View File

@@ -5,6 +5,7 @@ import java.io.PrintWriter;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import org.bukkit.Location;
import org.bukkit.block.BlockFace;
import org.bukkit.block.BlockState;
@@ -22,27 +23,26 @@ class LBBlockListener extends BlockListener
{
private static final SimpleDateFormat dateFormat = new SimpleDateFormat("MM-dd HH:mm:ss");
private final Consumer consumer;
private final boolean logChestAccess;
private final boolean logSignTexts;
private final Map<Integer, WorldConfig> worlds;
private final List<String> errors = new ArrayList<String>(20);
LBBlockListener(LogBlock logblock) {
consumer = logblock.getConsumer();
logSignTexts = logblock.getConfig().logSignTexts;
logChestAccess = logblock.getConfig().logChestAccess;
worlds = logblock.getConfig().worlds;
}
@Override
public void onBlockBreak(BlockBreakEvent event) {
if (!event.isCancelled()) {
final WorldConfig wcfg = worlds.get(event.getBlock().getWorld().getName().hashCode());
if (!event.isCancelled() && wcfg != null && wcfg.logBlockDestroyings) {
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 (logSignTexts && (type == 63 || type == 68))
if (wcfg.logSignTexts && (type == 63 || type == 68))
consumer.queueSignBreak(event.getPlayer().getName(), (Sign)event.getBlock().getState());
else if (logChestAccess && (type == 23 || type == 54 || type == 61))
else if (wcfg.logChestAccess && (type == 23 || type == 54 || type == 61))
consumer.queueContainerBreak(event.getPlayer().getName(), event.getBlock().getState());
else
consumer.queueBlockBreak(event.getPlayer().getName(), event.getBlock().getState());
@@ -51,13 +51,15 @@ class LBBlockListener extends BlockListener
@Override
public void onBlockBurn(BlockBurnEvent event) {
if (!event.isCancelled())
final WorldConfig wcfg = worlds.get(event.getBlock().getWorld().getName().hashCode());
if (!event.isCancelled() && wcfg != null && wcfg.logFire)
consumer.queueBlockBreak("Fire", event.getBlock().getState());
}
@Override
public void onBlockFromTo(BlockFromToEvent event) {
if (!event.isCancelled()) {
final WorldConfig wcfg = worlds.get(event.getBlock().getWorld().getName().hashCode());
if (!event.isCancelled() && wcfg != null && wcfg.logLavaFlow) {
final int typeFrom = event.getBlock().getTypeId();
final int typeTo = event.getToBlock().getTypeId();
if (typeFrom == 10 || typeFrom == 11)
@@ -73,7 +75,8 @@ class LBBlockListener extends BlockListener
@Override
public void onBlockPlace(BlockPlaceEvent event) {
if (!event.isCancelled()) {
final WorldConfig wcfg = worlds.get(event.getBlock().getWorld().getName().hashCode());
if (!event.isCancelled() && wcfg != null && wcfg.logBlockCreations) {
final int type = event.getBlock().getTypeId();
BlockState before = event.getBlockReplacedState();
final BlockState after = event.getBlockPlaced().getState();
@@ -91,7 +94,7 @@ class LBBlockListener extends BlockListener
after.setTypeId(event.getItemInHand().getTypeId());
after.setData(new MaterialData(event.getItemInHand().getTypeId()));
}
if (logSignTexts && (type == 63 || type == 68))
if (wcfg.logSignTexts && (type == 63 || type == 68))
return;
if (before.getTypeId() == 0)
consumer.queueBlockPlace(event.getPlayer().getName(), after);
@@ -102,13 +105,15 @@ class LBBlockListener extends BlockListener
@Override
public void onLeavesDecay(LeavesDecayEvent event) {
if (!event.isCancelled())
final WorldConfig wcfg = worlds.get(event.getBlock().getWorld().getName().hashCode());
if (!event.isCancelled() && wcfg != null && wcfg.logLeavesDecay)
consumer.queueBlockBreak("LeavesDecay", event.getBlock().getState());
}
@Override
public void onSignChange(SignChangeEvent event) {
if (!event.isCancelled())
final WorldConfig wcfg = worlds.get(event.getBlock().getWorld().getName().hashCode());
if (!event.isCancelled() && wcfg != null && wcfg.logSignTexts)
consumer.queueSignPlace(event.getPlayer().getName(), event.getBlock().getLocation(), event.getBlock().getTypeId(), event.getBlock().getData(), event.getLines());
}

View File

@@ -1,5 +1,6 @@
package de.diddiz.LogBlock;
import java.util.Map;
import org.bukkit.block.Block;
import org.bukkit.block.Sign;
import org.bukkit.entity.Creeper;
@@ -17,37 +18,37 @@ import org.bukkit.event.entity.EntityListener;
class LBEntityListener extends EntityListener
{
private final Consumer consumer;
private final boolean logChestAccess;
private final boolean logCreeperExplosionsAsPlayer;
private final Config.LogKillsLevel logKillsLevel;
private final boolean logSignTexts;
private final Map<Integer, WorldConfig> worlds;
LBEntityListener(LogBlock logblock) {
consumer = logblock.getConsumer();
logSignTexts = logblock.getConfig().logSignTexts;
logChestAccess = logblock.getConfig().logChestAccess;
worlds = logblock.getConfig().worlds;
logCreeperExplosionsAsPlayer = logblock.getConfig().logCreeperExplosionsAsPlayerWhoTriggeredThese;
logKillsLevel = logblock.getConfig().logKillsLevel;
}
@Override
public void onEntityDamage(EntityDamageEvent event) {
if (event.isCancelled() || !(event instanceof EntityDamageByEntityEvent) || !(event.getEntity() instanceof LivingEntity))
return;
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;
consumer.queueKill(killer, victim);
final WorldConfig wcfg = worlds.get(event.getEntity().getWorld().getName().hashCode());
if (!event.isCancelled() && wcfg != null && wcfg.logKills && 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;
consumer.queueKill(killer, victim);
}
}
@Override
public void onEntityExplode(EntityExplodeEvent event) {
if (!event.isCancelled()) {
final WorldConfig wcfg = worlds.get(event.getEntity().getWorld().getName().hashCode());
if (!event.isCancelled() && wcfg != null && wcfg.logExplosions) {
String name;
if (event.getEntity() instanceof TNTPrimed)
name = "TNT";
@@ -66,9 +67,9 @@ class LBEntityListener extends EntityListener
name = "Environment";
for (final Block block : event.blockList()) {
final int type = block.getTypeId();
if (logSignTexts & (type == 63 || type == 68))
if (wcfg.logSignTexts & (type == 63 || type == 68))
consumer.queueSignBreak(name, (Sign)block.getState());
else if (logChestAccess && (type == 23 || type == 54 || type == 61))
else if (wcfg.logChestAccess && (type == 23 || type == 54 || type == 61))
consumer.queueContainerBreak(name, block.getState());
else
consumer.queueBlockBreak(name, block.getState());

View File

@@ -17,14 +17,14 @@ class LBToolListener extends PlayerListener
private final LogBlock logblock;
private final int toolID;
private final int toolblockID;
private final Map<Integer, String> tables;
private final Map<Integer, WorldConfig> worlds;
LBToolListener(LogBlock logblock) {
this.logblock = logblock;
handler = logblock.getCommandsHandler();
toolID = logblock.getConfig().toolID;
toolblockID = logblock.getConfig().toolblockID;
tables = logblock.getConfig().tables;
worlds = logblock.getConfig().worlds;
}
@Override
@@ -36,7 +36,7 @@ class LBToolListener extends PlayerListener
final Player player = event.getPlayer();
final Session session = logblock.getSession(player.getName());
if (type == toolID && session.toolEnabled && logblock.hasPermission(player, "logblock.tool") || type == toolblockID && session.toolBlockEnabled && logblock.hasPermission(player, "logblock.toolblock"))
if (tables.get(player.getWorld().getName().hashCode()) != null) {
if (worlds.get(player.getWorld().getName().hashCode()) != null) {
final Block block = event.getClickedBlock();
if (!(type == toolID && block.getTypeId() == 26))
event.setCancelled(true);

View File

@@ -140,7 +140,7 @@ public class LogBlock extends JavaPlugin
params.minutes = config.keepLogDays * -1440;
params.bct = BlockChangeType.ALL;
for (final World world : getServer().getWorlds())
if (config.tables.containsKey(world.getName().hashCode())) {
if (config.worlds.containsKey(world.getName().hashCode())) {
params.world = world;
try {
commandsHandler.new CommandClearLog(new ConsoleCommandSender(getServer()), params.clone(), true);

View File

@@ -85,7 +85,7 @@ public class QueryParams implements Cloneable
}
public String getTable() {
return logblock.getConfig().tables.get(world.getName().hashCode());
return logblock.getConfig().worlds.get(world.getName().hashCode()).table;
}
public String getTitle() {
@@ -345,7 +345,7 @@ public class QueryParams implements Cloneable
if (!prepareToolQuery) {
if (world == null)
throw new IllegalArgumentException("No world specified");
if (!logblock.getConfig().tables.containsKey(world.getName().hashCode()))
if (!logblock.getConfig().worlds.containsKey(world.getName().hashCode()))
throw new IllegalArgumentException("This world ('" + world.getName() + "') isn't logged");
}
if (session != null)

View File

@@ -1,11 +1,14 @@
package de.diddiz.LogBlock;
import static de.diddiz.util.BukkitUtils.friendlyWorldname;
import static de.diddiz.util.Utils.readURL;
import java.io.File;
import java.net.URL;
import java.sql.Connection;
import java.sql.DatabaseMetaData;
import java.sql.SQLException;
import java.sql.Statement;
import java.util.List;
import java.util.logging.Level;
import java.util.logging.Logger;
import org.bukkit.util.config.Configuration;
@@ -41,14 +44,41 @@ class Updater
try {
conn.setAutoCommit(true);
final Statement st = conn.createStatement();
for (final String table : logblock.getConfig().tables.values())
for (final String table : config.getStringList("tables", null))
st.execute("ALTER TABLE `" + table + "-sign` MODIFY signtext VARCHAR(255) NOT NULL");
st.close();
conn.close();
} catch (final SQLException ex) {}
config.setProperty("version", "1.20");
}
if (config.getString("version").compareTo("1.23") < 0) {
log.info("[LogBlock] Updating tables to 1.23 ...");
final Connection conn = logblock.getConnection();
try {
conn.setAutoCommit(true);
final Statement st = conn.createStatement();
for (final String table : config.getStringList("tables", null))
if (st.executeQuery("SELECT * FROM `" + table + "-chest` LIMIT 1").getMetaData().getColumnCount() != 4)
st.execute("DROP TABLE `" + table + "-chest`");
st.close();
conn.close();
} catch (final SQLException ex) {}
log.info("[LogBlock] Updating config to 1.23 ...");
final List<String> worldNames = config.getStringList("loggedWorlds", null), worldTables = config.getStringList("tables", null);
final String[] nodes = new String[]{"BlockCreations", "BlockDestroyings", "SignTexts", "Explosions", "Fire", "LeavesDecay", "LavaFlow", "ChestAccess", "ButtonsAndLevers", "Kills", "Chat"};
for (int i = 0; i < worldNames.size(); i++) {
final Configuration wcfg = new Configuration(new File("plugins/LogBlock/" + friendlyWorldname(worldNames.get(i)) + ".yml"));
wcfg.load();
wcfg.setProperty("table", worldTables.get(i));
for (final String node : nodes)
wcfg.setProperty("log" + node, config.getBoolean("logging.log" + node, true));
wcfg.save();
}
for (final String node : nodes)
config.removeProperty("logging.log" + node);
config.removeProperty("tables");
config.setProperty("version", "1.23");
}
config.save();
return true;
}
@@ -63,14 +93,12 @@ class Updater
createTable(dbm, state, "lb-players", "(playerid SMALLINT UNSIGNED NOT NULL AUTO_INCREMENT, playername varchar(32) NOT NULL DEFAULT '-', PRIMARY KEY (playerid), UNIQUE (playername))");
if (logblock.getConfig().logChat)
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))");
for (final String table : logblock.getConfig().tables.values()) {
if (dbm.getTables(null, null, table + "-chest", null).next() && state.executeQuery("SELECT * FROM `" + table + "-chest` LIMIT 1").getMetaData().getColumnCount() != 4) // Chest table update
state.execute("DROP TABLE `" + table + "-chest`");
createTable(dbm, state, 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, table + "-sign", "(id INT UNSIGNED NOT NULL, signtext VARCHAR(255) NOT NULL, PRIMARY KEY (id))");
createTable(dbm, state, 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 (logblock.getConfig().logKills)
createTable(dbm, state, 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))");
for (final WorldConfig wcfg : logblock.getConfig().worlds.values()) {
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))");
if (wcfg.logKills)
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))");
}
state.close();
conn.close();