forked from LogBlock/LogBlock
Merged worldNames and worldTables to a hashmap.
This commit is contained in:
@@ -20,7 +20,7 @@ public class ClearLog implements Runnable
|
||||
Statement state = null;
|
||||
try {
|
||||
state = conn.createStatement();
|
||||
for (String table : LogBlock.config.worldTables) {
|
||||
for (String table : LogBlock.config.tables.values()) {
|
||||
int deleted = state.executeUpdate("DELETE FROM `" + table + "` WHERE date < date_sub(now(), INTERVAL " + LogBlock.config.keepLogDays + " DAY)");
|
||||
if (deleted > 0)
|
||||
LogBlock.log.info("[LogBlock] Cleared out table " + table + ". Deleted " + deleted + " entries.");
|
||||
|
@@ -1,13 +1,13 @@
|
||||
package de.diddiz.LogBlock;
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
|
||||
import org.bukkit.util.config.Configuration;
|
||||
|
||||
public class Config {
|
||||
List<String> worldNames;
|
||||
List<String> worldTables;
|
||||
HashMap<Integer, String> tables;
|
||||
String dbDriver;
|
||||
String dbUrl;
|
||||
String dbUsername;
|
||||
@@ -31,7 +31,7 @@ public class Config {
|
||||
String logLeavesDecayAs;
|
||||
boolean usePermissions;
|
||||
|
||||
Config (LogBlock logblock) {
|
||||
Config (LogBlock logblock) throws Exception {
|
||||
Configuration config = logblock.getConfiguration();
|
||||
config.load();
|
||||
List<String> keys = config.getKeys(null);
|
||||
@@ -87,8 +87,6 @@ public class Config {
|
||||
config.setProperty("usePermissions", false);
|
||||
if (!config.save())
|
||||
LogBlock.log.severe("[LogBlock] Error while writing to config.yml");
|
||||
worldNames = config.getStringList("worldNames", null);
|
||||
worldTables = config.getStringList("worldTables", null);
|
||||
dbDriver = config.getString("driver");
|
||||
dbUrl = config.getString("url");
|
||||
dbUsername = config.getString("username");
|
||||
@@ -111,5 +109,13 @@ public class Config {
|
||||
logFireAs = config.getString("logFireAs");
|
||||
logLeavesDecayAs = config.getString("logLeavesDecayAs");
|
||||
usePermissions = config.getBoolean("usePermissions", false);
|
||||
List<String> worldNames = config.getStringList("worldNames", null);
|
||||
List<String> worldTables = config.getStringList("worldTables", null);
|
||||
tables = new HashMap<Integer, String>();
|
||||
if (worldNames == null || worldTables == null || worldNames.size() == 0 || worldNames.size() != worldTables.size())
|
||||
throw new Exception("worldNames or worldTables not set porperly");
|
||||
for (int i = 0; i < worldNames.size(); i++) {
|
||||
tables.put(worldNames.get(i).hashCode(), worldTables.get(i));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@@ -30,7 +30,7 @@ public class Consumer implements Runnable
|
||||
public void queueBlock(String playerName, Block block, int typeBefore, int typeAfter, byte data, String signtext, ChestAccess ca) {
|
||||
if (block == null || typeBefore < 0 || typeAfter < 0)
|
||||
return;
|
||||
String table = LogBlock.config.worldTables.get(LogBlock.config.worldNames.indexOf(block.getWorld().getName()));
|
||||
String table = LogBlock.config.tables.get(block.getWorld().getName().hashCode());
|
||||
if (table == null)
|
||||
return;
|
||||
if (playerName.length() > 32)
|
||||
|
@@ -80,11 +80,6 @@ public class LogBlock extends JavaPlugin
|
||||
getServer().getPluginManager().disablePlugin(this);
|
||||
return;
|
||||
}
|
||||
if (config.worldNames == null || config.worldTables == null || config.worldNames.size() == 0 || config.worldNames.size() != config.worldTables.size()) {
|
||||
log.log(Level.SEVERE, "[LogBlock] worldNames or worldTables not set porperly");
|
||||
getServer().getPluginManager().disablePlugin(this);
|
||||
return;
|
||||
}
|
||||
if (!checkTables()) {
|
||||
log.log(Level.SEVERE, "[LogBlock] Errors while checking tables. They may not exist.");
|
||||
getServer().getPluginManager().disablePlugin(this);
|
||||
@@ -138,7 +133,7 @@ public class LogBlock extends JavaPlugin
|
||||
}
|
||||
Player player = (Player)sender;
|
||||
Connection conn = getConnection();
|
||||
String table = getTable(player);
|
||||
String table = config.tables.get(player.getWorld().getName().hashCode());
|
||||
if (conn == null) {
|
||||
player.sendMessage(ChatColor.RED + "Can't create SQL connection.");
|
||||
return true;
|
||||
@@ -367,8 +362,7 @@ public class LogBlock extends JavaPlugin
|
||||
return false;
|
||||
}
|
||||
state.execute("INSERT IGNORE INTO `lb-players` (`playername`) VALUES ('" + config.logTNTExplosionsAs + "'), ('" + config.logCreeperExplosionsAs + "'), ('" + config.logFireAs + "'), ('" + config.logLeavesDecayAs + "'), ('" + config.logFireballExplosionsAs + "'), ('Environment')");
|
||||
for (int i = 0; i < config.worldNames.size(); i++) {
|
||||
String table = config.worldTables.get(i);
|
||||
for (String table : config.tables.values()) {
|
||||
if (!dbm.getTables(null, null, table, null).next()) {
|
||||
log.log(Level.INFO, "[LogBlock] Crating table " + table + ".");
|
||||
state.execute("CREATE TABLE `" + table + "` (`id` INT NOT NULL AUTO_INCREMENT, `date` datetime NOT NULL DEFAULT '0000-00-00 00:00:00', `playerid` SMALLINT UNSIGNED NOT NULL DEFAULT '0', `replaced` TINYINT UNSIGNED NOT NULL DEFAULT '0', `type` TINYINT UNSIGNED NOT NULL DEFAULT '0', `data` TINYINT UNSIGNED NOT NULL DEFAULT '0', `x` SMALLINT NOT NULL DEFAULT '0', `y` TINYINT UNSIGNED NOT NULL DEFAULT '0',`z` SMALLINT NOT NULL DEFAULT '0', PRIMARY KEY (`id`), KEY `coords` (`y`,`x`,`z`), KEY `type` (`type`), KEY `data` (`data`), KEY `replaced` (`replaced`));");
|
||||
@@ -404,21 +398,6 @@ public class LogBlock extends JavaPlugin
|
||||
return false;
|
||||
}
|
||||
|
||||
private String getTable (Player player) {
|
||||
return getTable(player.getWorld().getName());
|
||||
}
|
||||
|
||||
private String getTable (Block block) {
|
||||
return getTable(block.getWorld().getName());
|
||||
}
|
||||
|
||||
private String getTable (String worldName) {
|
||||
int idx = config.worldNames.indexOf(worldName);
|
||||
if (idx == -1)
|
||||
return null;
|
||||
return config.worldTables.get(idx);
|
||||
}
|
||||
|
||||
private boolean CheckPermission(Player player, String permission) {
|
||||
if (config.usePermissions)
|
||||
return Permissions.Security.permission(player, permission);
|
||||
@@ -555,10 +534,10 @@ public class LogBlock extends JavaPlugin
|
||||
public void onPlayerInteract(PlayerInteractEvent event) {
|
||||
if (!event.isCancelled()) {
|
||||
if (event.getAction() == Action.RIGHT_CLICK_BLOCK && event.getMaterial().getId() == LogBlock.config.toolID && CheckPermission(event.getPlayer(), "logblock.lookup")) {
|
||||
getServer().getScheduler().scheduleAsyncDelayedTask(LogBlock.this, new BlockStats(getConnection(), event.getPlayer(), event.getClickedBlock(), getTable(event.getClickedBlock())));
|
||||
getServer().getScheduler().scheduleAsyncDelayedTask(LogBlock.this, new BlockStats(getConnection(), event.getPlayer(), event.getClickedBlock(), config.tables.get(event.getPlayer().getWorld().getName().hashCode())));
|
||||
event.setCancelled(true);
|
||||
} else if (event.getAction() == Action.RIGHT_CLICK_BLOCK && event.getMaterial().getId() == LogBlock.config.toolblockID && CheckPermission(event.getPlayer(), "logblock.lookup")) {
|
||||
getServer().getScheduler().scheduleAsyncDelayedTask(LogBlock.this, new BlockStats(getConnection(), event.getPlayer(), event.getClickedBlock().getFace(event.getBlockFace()), getTable(event.getClickedBlock())));
|
||||
getServer().getScheduler().scheduleAsyncDelayedTask(LogBlock.this, new BlockStats(getConnection(), event.getPlayer(), event.getClickedBlock().getFace(event.getBlockFace()), config.tables.get(event.getPlayer().getWorld().getName().hashCode())));
|
||||
if (config.toolblockRemove)
|
||||
event.setCancelled(true);
|
||||
}
|
||||
|
Reference in New Issue
Block a user