forked from LogBlock/LogBlock
Rewrote logging config
This commit is contained in:
@@ -4,6 +4,7 @@ import static de.diddiz.LogBlock.Session.getSession;
|
||||
import static de.diddiz.util.BukkitUtils.giveTool;
|
||||
import static de.diddiz.util.BukkitUtils.saveSpawnHeight;
|
||||
import static de.diddiz.util.Utils.isInt;
|
||||
import static de.diddiz.util.Utils.listing;
|
||||
import static org.bukkit.Bukkit.getLogger;
|
||||
import java.io.Closeable;
|
||||
import java.io.File;
|
||||
@@ -107,32 +108,11 @@ public class CommandsHandler implements CommandExecutor
|
||||
final String world = ((Player)sender).getWorld().getName();
|
||||
final WorldConfig wcfg = config.worlds.get(world.hashCode());
|
||||
sender.sendMessage(ChatColor.DARK_AQUA + "Currently logging in " + world + ":");
|
||||
String msg = "";
|
||||
if (wcfg.logBlockPlacings)
|
||||
msg += ", BlockPlacings";
|
||||
if (wcfg.logBlockBreaks)
|
||||
msg += ", BlockBreaks";
|
||||
if (wcfg.logSignTexts)
|
||||
msg += ", SignTexts";
|
||||
if (wcfg.logExplosions)
|
||||
msg += ", Explosions";
|
||||
if (wcfg.logFire)
|
||||
msg += ", Fire";
|
||||
if (wcfg.logLeavesDecay)
|
||||
msg += ", LeavesDecay";
|
||||
if (wcfg.logLavaFlow)
|
||||
msg += ", LavaFlow";
|
||||
if (wcfg.logWaterFlow)
|
||||
msg += ", WaterFlow";
|
||||
if (wcfg.logChestAccess)
|
||||
msg += ", ChestAccess";
|
||||
if (wcfg.logButtonsAndLevers)
|
||||
msg += ", ButtonsAndLevers";
|
||||
if (wcfg.logKills)
|
||||
msg += ", Kills";
|
||||
if (wcfg.logChat)
|
||||
msg += ", Chat";
|
||||
sender.sendMessage(ChatColor.GOLD + msg.substring(2));
|
||||
final List<String> logging = new ArrayList<String>();
|
||||
for (final Logging l : Logging.values())
|
||||
if (wcfg.isLogging(l))
|
||||
logging.add(l.toString());
|
||||
sender.sendMessage(ChatColor.GOLD + listing(logging, ", ", " and "));
|
||||
}
|
||||
} else if (config.toolsByName.get(command) != null) {
|
||||
final Tool tool = config.toolsByName.get(command);
|
||||
|
||||
@@ -2,6 +2,8 @@ package de.diddiz.LogBlock;
|
||||
|
||||
import static de.diddiz.util.BukkitUtils.friendlyWorldname;
|
||||
import static de.diddiz.util.Utils.parseTimeSpec;
|
||||
import static de.diddiz.util.Utils.toIntList;
|
||||
import static de.diddiz.util.Utils.toStringList;
|
||||
import static org.bukkit.Bukkit.getConsoleSender;
|
||||
import static org.bukkit.Bukkit.getLogger;
|
||||
import java.io.File;
|
||||
@@ -21,7 +23,7 @@ import org.bukkit.configuration.ConfigurationSection;
|
||||
import org.bukkit.configuration.file.YamlConfiguration;
|
||||
import org.bukkit.permissions.PermissionDefault;
|
||||
|
||||
public class Config
|
||||
public class Config extends LoggingEnabledMapping
|
||||
{
|
||||
public final Map<Integer, WorldConfig> worlds;
|
||||
public final String url, user, password;
|
||||
@@ -30,7 +32,6 @@ public class Config
|
||||
public final boolean enableAutoClearLog;
|
||||
public final List<String> autoClearLog;
|
||||
public final boolean dumpDeletedLog;
|
||||
public boolean logBlockPlacings, logBlockBreaks, logSignTexts, logExplosions, logFire, logLeavesDecay, logLavaFlow, logWaterFlow, logChestAccess, logButtonsAndLevers, logKills, logChat, logSnowForm, logSnowFade, logDoors, logCakes, logEndermen;
|
||||
public final boolean logCreeperExplosionsAsPlayerWhoTriggeredThese, logPlayerInfo;
|
||||
public final LogKillsLevel logKillsLevel;
|
||||
public final Set<Integer> dontRollback, replaceAnyway;
|
||||
@@ -183,120 +184,43 @@ public class Config
|
||||
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.logBlockPlacings)
|
||||
logBlockPlacings = true;
|
||||
if (wcfg.logBlockBreaks)
|
||||
logBlockBreaks = 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.logWaterFlow)
|
||||
logWaterFlow = true;
|
||||
if (wcfg.logChestAccess)
|
||||
logChestAccess = true;
|
||||
if (wcfg.logButtonsAndLevers)
|
||||
logButtonsAndLevers = true;
|
||||
if (wcfg.logKills)
|
||||
logKills = true;
|
||||
if (wcfg.logChat)
|
||||
logChat = true;
|
||||
if (wcfg.logSnowForm)
|
||||
logSnowForm = true;
|
||||
if (wcfg.logSnowFade)
|
||||
logSnowFade = true;
|
||||
if (wcfg.logDoors)
|
||||
logDoors = true;
|
||||
if (wcfg.logCakes)
|
||||
logCakes = true;
|
||||
if (wcfg.logEndermen)
|
||||
logEndermen = true;
|
||||
}
|
||||
}
|
||||
for (final WorldConfig wcfg : worlds.values())
|
||||
for (final Logging l : Logging.values())
|
||||
if (wcfg.isLogging(l))
|
||||
setLogging(l, true);
|
||||
|
||||
public static List<String> toStringList(List<?> list) {
|
||||
if (list == null)
|
||||
return new ArrayList<String>();
|
||||
final List<String> strs = new ArrayList<String>(list.size());
|
||||
for (final Object obj : list)
|
||||
if (obj instanceof String)
|
||||
strs.add((String)obj);
|
||||
else
|
||||
strs.add(String.valueOf(obj));
|
||||
return strs;
|
||||
}
|
||||
|
||||
public static List<Integer> toIntList(List<?> list) {
|
||||
if (list == null)
|
||||
return new ArrayList<Integer>();
|
||||
final List<Integer> ints = new ArrayList<Integer>(list.size());
|
||||
for (final Object obj : list)
|
||||
if (obj instanceof Integer)
|
||||
ints.add((Integer)obj);
|
||||
else
|
||||
try {
|
||||
ints.add(Integer.valueOf(String.valueOf(obj)));
|
||||
} catch (final NumberFormatException ex) {
|
||||
getLogger().warning("[LogBlock] Config error: '" + obj + "' is not a number");
|
||||
}
|
||||
return ints;
|
||||
}
|
||||
}
|
||||
|
||||
class WorldConfig
|
||||
class WorldConfig extends LoggingEnabledMapping
|
||||
{
|
||||
public final String table;
|
||||
public final boolean logBlockPlacings, logBlockBreaks, logSignTexts, logExplosions, logFire, logLeavesDecay, logLavaFlow, logWaterFlow, logChestAccess, logButtonsAndLevers, logKills, logChat, logSnowForm, logSnowFade, logDoors, logCakes, logEndermen;
|
||||
|
||||
public WorldConfig(File file) throws IOException {
|
||||
final Map<String, Object> def = new HashMap<String, Object>();
|
||||
def.put("table", "lb-" + file.getName().substring(0, file.getName().length() - 4));
|
||||
def.put("logBlockCreations", true);
|
||||
def.put("logBlockDestroyings", true);
|
||||
def.put("logSignTexts", true);
|
||||
def.put("logExplosions", true);
|
||||
def.put("logFire", true);
|
||||
def.put("logLeavesDecay", false);
|
||||
def.put("logLavaFlow", false);
|
||||
def.put("logWaterFlow", false);
|
||||
def.put("logChestAccess", false);
|
||||
def.put("logButtonsAndLevers", false);
|
||||
def.put("logKills", false);
|
||||
def.put("logChat", false);
|
||||
def.put("logSnowForm", false);
|
||||
def.put("logSnowFade", false);
|
||||
def.put("logDoors", false);
|
||||
def.put("logCakes", false);
|
||||
def.put("logEndermen", false);
|
||||
for (final Logging l : Logging.values())
|
||||
def.put("logging." + l.toString(), false);
|
||||
final YamlConfiguration config = YamlConfiguration.loadConfiguration(file);
|
||||
for (final Entry<String, Object> e : def.entrySet())
|
||||
if (config.get(e.getKey()) == null)
|
||||
config.set(e.getKey(), e.getValue());
|
||||
config.save(file);
|
||||
table = config.getString("table");
|
||||
logBlockPlacings = config.getBoolean("logBlockCreations", true);
|
||||
logBlockBreaks = 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);
|
||||
logWaterFlow = config.getBoolean("logWaterFlow", false);
|
||||
logChestAccess = config.getBoolean("logChestAccess", false);
|
||||
logButtonsAndLevers = config.getBoolean("logButtonsAndLevers", false);
|
||||
logKills = config.getBoolean("logKills", false);
|
||||
logChat = config.getBoolean("logChat", false);
|
||||
logSnowForm = config.getBoolean("logSnowForm", false);
|
||||
logSnowFade = config.getBoolean("logSnowFade", false);
|
||||
logDoors = config.getBoolean("logDoors", false);
|
||||
logCakes = config.getBoolean("logCakes", false);
|
||||
logEndermen = config.getBoolean("logEndermen", false);
|
||||
for (final Logging l : Logging.values())
|
||||
setLogging(l, config.getBoolean("logging." + l.toString()));
|
||||
}
|
||||
}
|
||||
|
||||
abstract class LoggingEnabledMapping
|
||||
{
|
||||
private final boolean[] logging = new boolean[Logging.length];
|
||||
|
||||
public void setLogging(Logging l, boolean enabled) {
|
||||
logging[l.ordinal()] = enabled;
|
||||
}
|
||||
|
||||
public boolean isLogging(Logging l) {
|
||||
return logging[l.ordinal()];
|
||||
}
|
||||
}
|
||||
|
||||
@@ -41,15 +41,15 @@ class LBBlockListener extends BlockListener
|
||||
@Override
|
||||
public void onBlockBreak(BlockBreakEvent event) {
|
||||
final WorldConfig wcfg = worlds.get(event.getBlock().getWorld().getName().hashCode());
|
||||
if (!event.isCancelled() && wcfg != null && wcfg.logBlockBreaks) {
|
||||
if (!event.isCancelled() && wcfg != null && wcfg.isLogging(Logging.BLOCKBREAK)) {
|
||||
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 (wcfg.logSignTexts && (type == 63 || type == 68))
|
||||
if (wcfg.isLogging(Logging.SIGNTEXT) && (type == 63 || type == 68))
|
||||
consumer.queueSignBreak(event.getPlayer().getName(), (Sign)event.getBlock().getState());
|
||||
else if (wcfg.logChestAccess && (type == 23 || type == 54 || type == 61))
|
||||
else if (wcfg.isLogging(Logging.CHESTACCESS) && (type == 23 || type == 54 || type == 61))
|
||||
consumer.queueContainerBreak(event.getPlayer().getName(), event.getBlock().getState());
|
||||
else if (type == 79)
|
||||
consumer.queueBlockReplace(event.getPlayer().getName(), event.getBlock().getState(), 9, (byte)0);
|
||||
@@ -61,7 +61,7 @@ class LBBlockListener extends BlockListener
|
||||
@Override
|
||||
public void onBlockBurn(BlockBurnEvent event) {
|
||||
final WorldConfig wcfg = worlds.get(event.getBlock().getWorld().getName().hashCode());
|
||||
if (!event.isCancelled() && wcfg != null && wcfg.logFire)
|
||||
if (!event.isCancelled() && wcfg != null && wcfg.isLogging(Logging.FIRE))
|
||||
consumer.queueBlockBreak("Fire", event.getBlock().getState());
|
||||
}
|
||||
|
||||
@@ -73,7 +73,7 @@ class LBBlockListener extends BlockListener
|
||||
final int typeTo = event.getToBlock().getTypeId();
|
||||
if (typeFrom == 10 || typeFrom == 11) {
|
||||
if (typeTo == 0) {
|
||||
if (wcfg.logLavaFlow)
|
||||
if (wcfg.isLogging(Logging.LAVAFLOW))
|
||||
consumer.queueBlockPlace("LavaFlow", event.getToBlock().getLocation(), 10, (byte)(event.getBlock().getData() + 1));
|
||||
} else if (nonFluidProofBlocks.contains(typeTo))
|
||||
consumer.queueBlockReplace("LavaFlow", event.getToBlock().getState(), 10, (byte)(event.getBlock().getData() + 1));
|
||||
@@ -85,7 +85,7 @@ class LBBlockListener extends BlockListener
|
||||
} else if (typeFrom == 8 || typeFrom == 9)
|
||||
if (typeTo == 0 || nonFluidProofBlocks.contains(typeTo)) {
|
||||
if (typeTo == 0) {
|
||||
if (wcfg.logWaterFlow)
|
||||
if (wcfg.isLogging(Logging.WATERFLOW))
|
||||
consumer.queueBlockPlace("WaterFlow", event.getToBlock().getLocation(), 8, (byte)(event.getBlock().getData() + 1));
|
||||
} else
|
||||
consumer.queueBlockReplace("WaterFlow", event.getToBlock().getState(), 8, (byte)(event.getBlock().getData() + 1));
|
||||
@@ -99,7 +99,7 @@ class LBBlockListener extends BlockListener
|
||||
@Override
|
||||
public void onBlockPlace(BlockPlaceEvent event) {
|
||||
final WorldConfig wcfg = worlds.get(event.getBlock().getWorld().getName().hashCode());
|
||||
if (!event.isCancelled() && wcfg != null && wcfg.logBlockPlacings) {
|
||||
if (!event.isCancelled() && wcfg != null && wcfg.isLogging(Logging.BLOCKPLACE)) {
|
||||
final int type = event.getBlock().getTypeId();
|
||||
final BlockState before = event.getBlockReplacedState();
|
||||
final BlockState after = event.getBlockPlaced().getState();
|
||||
@@ -111,7 +111,7 @@ class LBBlockListener extends BlockListener
|
||||
after.setTypeId(event.getItemInHand().getTypeId());
|
||||
after.setData(new MaterialData(event.getItemInHand().getTypeId()));
|
||||
}
|
||||
if (wcfg.logSignTexts && (type == 63 || type == 68))
|
||||
if (wcfg.isLogging(Logging.SIGNTEXT) && (type == 63 || type == 68))
|
||||
return;
|
||||
if (before.getTypeId() == 0)
|
||||
consumer.queueBlockPlace(event.getPlayer().getName(), after);
|
||||
@@ -123,14 +123,14 @@ class LBBlockListener extends BlockListener
|
||||
@Override
|
||||
public void onLeavesDecay(LeavesDecayEvent event) {
|
||||
final WorldConfig wcfg = worlds.get(event.getBlock().getWorld().getName().hashCode());
|
||||
if (!event.isCancelled() && wcfg != null && wcfg.logLeavesDecay)
|
||||
if (!event.isCancelled() && wcfg != null && wcfg.isLogging(Logging.LEAVESDECAY))
|
||||
consumer.queueBlockBreak("LeavesDecay", event.getBlock().getState());
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onSignChange(SignChangeEvent event) {
|
||||
final WorldConfig wcfg = worlds.get(event.getBlock().getWorld().getName().hashCode());
|
||||
if (!event.isCancelled() && wcfg != null && wcfg.logSignTexts)
|
||||
if (!event.isCancelled() && wcfg != null && wcfg.isLogging(Logging.SIGNTEXT))
|
||||
consumer.queueSignPlace(event.getPlayer().getName(), event.getBlock().getLocation(), event.getBlock().getTypeId(), event.getBlock().getData(), event.getLines());
|
||||
}
|
||||
|
||||
@@ -139,7 +139,7 @@ class LBBlockListener extends BlockListener
|
||||
final WorldConfig wcfg = worlds.get(event.getBlock().getWorld().getName().hashCode());
|
||||
if (!event.isCancelled() && wcfg != null) {
|
||||
final int type = event.getNewState().getTypeId();
|
||||
if (wcfg.logSnowForm && (type == 78 || type == 79))
|
||||
if (wcfg.isLogging(Logging.SNOWFORM) && (type == 78 || type == 79))
|
||||
consumer.queueBlockReplace("SnowForm", event.getBlock().getState(), event.getNewState());
|
||||
}
|
||||
}
|
||||
@@ -149,7 +149,7 @@ class LBBlockListener extends BlockListener
|
||||
final WorldConfig wcfg = worlds.get(event.getBlock().getWorld().getName().hashCode());
|
||||
if (!event.isCancelled() && wcfg != null) {
|
||||
final int type = event.getBlock().getTypeId();
|
||||
if (wcfg.logSnowFade && (type == 78 || type == 79))
|
||||
if (wcfg.isLogging(Logging.SNOWFADE) && (type == 78 || type == 79))
|
||||
consumer.queueBlockReplace("SnowFade", event.getBlock().getState(), event.getNewState());
|
||||
}
|
||||
}
|
||||
|
||||
@@ -40,7 +40,7 @@ class LBEntityListener extends EntityListener
|
||||
@Override
|
||||
public void onEntityDamage(EntityDamageEvent event) {
|
||||
final WorldConfig wcfg = worlds.get(event.getEntity().getWorld().getName().hashCode());
|
||||
if (!event.isCancelled() && wcfg != null && wcfg.logKills && event instanceof EntityDamageByEntityEvent && event.getEntity() instanceof LivingEntity) {
|
||||
if (!event.isCancelled() && wcfg != null && wcfg.isLogging(Logging.KILL) && 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)
|
||||
@@ -60,7 +60,7 @@ class LBEntityListener extends EntityListener
|
||||
@Override
|
||||
public void onEntityExplode(EntityExplodeEvent event) {
|
||||
final WorldConfig wcfg = worlds.get(event.getLocation().getWorld().getName().hashCode());
|
||||
if (!event.isCancelled() && wcfg != null && wcfg.logExplosions) {
|
||||
if (!event.isCancelled() && wcfg != null && wcfg.isLogging(Logging.EXPLOSION)) {
|
||||
final String name;
|
||||
if (event.getEntity() == null)
|
||||
name = "Explosion";
|
||||
@@ -78,9 +78,9 @@ class LBEntityListener extends EntityListener
|
||||
name = "Explosion";
|
||||
for (final Block block : event.blockList()) {
|
||||
final int type = block.getTypeId();
|
||||
if (wcfg.logSignTexts & (type == 63 || type == 68))
|
||||
if (wcfg.isLogging(Logging.SIGNTEXT) & (type == 63 || type == 68))
|
||||
consumer.queueSignBreak(name, (Sign)block.getState());
|
||||
else if (wcfg.logChestAccess && (type == 23 || type == 54 || type == 61))
|
||||
else if (wcfg.isLogging(Logging.CHESTACCESS) && (type == 23 || type == 54 || type == 61))
|
||||
consumer.queueContainerBreak(name, block.getState());
|
||||
else
|
||||
consumer.queueBlockBreak(name, block.getState());
|
||||
@@ -91,14 +91,14 @@ class LBEntityListener extends EntityListener
|
||||
@Override
|
||||
public void onEndermanPickup(EndermanPickupEvent event) {
|
||||
final WorldConfig wcfg = worlds.get(event.getBlock().getWorld().getName().hashCode());
|
||||
if (!event.isCancelled() && wcfg != null && wcfg.logEndermen)
|
||||
if (!event.isCancelled() && wcfg != null && wcfg.isLogging(Logging.ENDERMEN))
|
||||
consumer.queueBlockBreak("Enderman", event.getBlock().getState());
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onEndermanPlace(EndermanPlaceEvent event) {
|
||||
final WorldConfig wcfg = worlds.get(event.getLocation().getWorld().getName().hashCode());
|
||||
if (!event.isCancelled() && wcfg != null && wcfg.logEndermen && event.getEntity() instanceof Enderman) {
|
||||
if (!event.isCancelled() && wcfg != null && wcfg.isLogging(Logging.ENDERMEN) && event.getEntity() instanceof Enderman) {
|
||||
final EntityEnderman enderman = ((CraftEnderman)event.getEntity()).getHandle();
|
||||
consumer.queueBlockPlace("Enderman", event.getLocation(), enderman.getCarriedId(), (byte)enderman.getCarriedData());
|
||||
}
|
||||
|
||||
@@ -25,14 +25,14 @@ class LBPlayerListener extends PlayerListener
|
||||
@Override
|
||||
public void onPlayerBucketEmpty(PlayerBucketEmptyEvent event) {
|
||||
final WorldConfig wcfg = worlds.get(event.getPlayer().getWorld().getName().hashCode());
|
||||
if (!event.isCancelled() && wcfg != null && wcfg.logBlockPlacings)
|
||||
if (!event.isCancelled() && wcfg != null && wcfg.isLogging(Logging.BLOCKPLACE))
|
||||
consumer.queueBlockPlace(event.getPlayer().getName(), event.getBlockClicked().getRelative(event.getBlockFace()).getLocation(), event.getBucket() == Material.WATER_BUCKET ? 9 : 11, (byte)0);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onPlayerBucketFill(PlayerBucketFillEvent event) {
|
||||
final WorldConfig wcfg = worlds.get(event.getPlayer().getWorld().getName().hashCode());
|
||||
if (!event.isCancelled() && wcfg != null && wcfg.logBlockBreaks)
|
||||
if (!event.isCancelled() && wcfg != null && wcfg.isLogging(Logging.BLOCKBREAK))
|
||||
consumer.queueBlockBreak(event.getPlayer().getName(), event.getBlockClicked().getState());
|
||||
}
|
||||
|
||||
@@ -41,11 +41,11 @@ class LBPlayerListener extends PlayerListener
|
||||
final WorldConfig wcfg = worlds.get(event.getPlayer().getWorld().getName().hashCode());
|
||||
if (!event.isCancelled() && wcfg != null && (event.getAction() == Action.LEFT_CLICK_BLOCK || event.getAction() == Action.RIGHT_CLICK_BLOCK)) {
|
||||
final int type = event.getClickedBlock().getTypeId();
|
||||
if (wcfg.logButtonsAndLevers && (type == 69 || type == 77))
|
||||
if (wcfg.isLogging(Logging.SWITCHINTERACT) && (type == 69 || type == 77))
|
||||
consumer.queueBlock(event.getPlayer().getName(), event.getClickedBlock().getLocation(), type, type, (byte)0);
|
||||
else if (wcfg.logDoors && (type == 64 || type == 96 || type == 107 && event.getAction() == Action.RIGHT_CLICK_BLOCK))
|
||||
else if (wcfg.isLogging(Logging.DOORINTERACT) && (type == 64 || type == 96 || type == 107 && event.getAction() == Action.RIGHT_CLICK_BLOCK))
|
||||
consumer.queueBlock(event.getPlayer().getName(), event.getClickedBlock().getLocation(), type, type, (byte)((event.getClickedBlock().getData() & 4) / 4));
|
||||
else if (wcfg.logCakes && type == 92 && event.getPlayer().getHealth() < 20)
|
||||
else if (wcfg.isLogging(Logging.CAKEEAT) && type == 92 && event.getPlayer().getHealth() < 20)
|
||||
consumer.queueBlock(event.getPlayer().getName(), event.getClickedBlock().getLocation(), type, type, (byte)0);
|
||||
}
|
||||
}
|
||||
@@ -53,14 +53,14 @@ class LBPlayerListener extends PlayerListener
|
||||
@Override
|
||||
public void onPlayerCommandPreprocess(PlayerCommandPreprocessEvent event) {
|
||||
final WorldConfig wcfg = worlds.get(event.getPlayer().getWorld().getName().hashCode());
|
||||
if (wcfg != null && wcfg.logChat)
|
||||
if (wcfg != null && wcfg.isLogging(Logging.CHAT))
|
||||
consumer.queueChat(event.getPlayer().getName(), event.getMessage());
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onPlayerChat(PlayerChatEvent event) {
|
||||
final WorldConfig wcfg = worlds.get(event.getPlayer().getWorld().getName().hashCode());
|
||||
if (wcfg != null && wcfg.logChat)
|
||||
if (wcfg != null && wcfg.isLogging(Logging.CHAT))
|
||||
consumer.queueChat(event.getPlayer().getName(), event.getMessage());
|
||||
}
|
||||
|
||||
|
||||
@@ -108,18 +108,18 @@ public class LogBlock extends JavaPlugin
|
||||
} catch (final Exception ex) {
|
||||
getLogger().warning("[LogBlock] Failed to download WorldEdit. You may have to download it manually. You don't have to install it, just place the jar in the lib folder.");
|
||||
}
|
||||
if (config.logChestAccess && pm.getPlugin("Spout") == null)
|
||||
if (config.isLogging(Logging.CHESTACCESS) && pm.getPlugin("Spout") == null)
|
||||
if (config.installSpout)
|
||||
try {
|
||||
download(getLogger(), new URL("http://ci.getspout.org/job/Spout/Recommended/artifact/target/spout-dev-SNAPSHOT.jar"), new File("plugins/Spout.jar"));
|
||||
pm.loadPlugin(new File("plugins/Spout.jar"));
|
||||
pm.enablePlugin(pm.getPlugin("Spout"));
|
||||
} catch (final Exception ex) {
|
||||
config.logChestAccess = false;
|
||||
config.setLogging(Logging.CHESTACCESS, false);
|
||||
getLogger().warning("[LogBlock] Failed to install Spout, you may have to restart your server or install it manually.");
|
||||
}
|
||||
else {
|
||||
config.logChestAccess = false;
|
||||
config.setLogging(Logging.CHESTACCESS, false);
|
||||
getLogger().warning("[LogBlock] Spout is not installed. Disabling chest logging.");
|
||||
}
|
||||
commandsHandler = new CommandsHandler(this);
|
||||
@@ -140,42 +140,42 @@ public class LogBlock extends JavaPlugin
|
||||
pm.registerEvent(Type.PLAYER_CHANGED_WORLD, lbToolListener, Priority.Normal, this);
|
||||
if (config.askRollbackAfterBan)
|
||||
pm.registerEvent(Type.PLAYER_COMMAND_PREPROCESS, lbToolListener, Priority.Normal, this);
|
||||
if (config.logBlockPlacings) {
|
||||
if (config.isLogging(Logging.BLOCKPLACE)) {
|
||||
pm.registerEvent(Type.BLOCK_PLACE, lbBlockListener, Priority.Monitor, this);
|
||||
pm.registerEvent(Type.PLAYER_BUCKET_EMPTY, lbPlayerListener, Priority.Monitor, this);
|
||||
}
|
||||
if (config.logBlockBreaks) {
|
||||
if (config.isLogging(Logging.BLOCKBREAK)) {
|
||||
pm.registerEvent(Type.BLOCK_BREAK, lbBlockListener, Priority.Monitor, this);
|
||||
pm.registerEvent(Type.PLAYER_BUCKET_FILL, lbPlayerListener, Priority.Monitor, this);
|
||||
pm.registerEvent(Type.BLOCK_FROMTO, lbBlockListener, Priority.Monitor, this);
|
||||
}
|
||||
if (config.logSignTexts)
|
||||
if (config.isLogging(Logging.SIGNTEXT))
|
||||
pm.registerEvent(Type.SIGN_CHANGE, lbBlockListener, Priority.Monitor, this);
|
||||
if (config.logFire)
|
||||
if (config.isLogging(Logging.FIRE))
|
||||
pm.registerEvent(Type.BLOCK_BURN, lbBlockListener, Priority.Monitor, this);
|
||||
if (config.logSnowForm)
|
||||
if (config.isLogging(Logging.SNOWFORM))
|
||||
pm.registerEvent(Type.BLOCK_FORM, lbBlockListener, Priority.Monitor, this);
|
||||
if (config.logSnowFade)
|
||||
if (config.isLogging(Logging.SNOWFADE))
|
||||
pm.registerEvent(Type.BLOCK_FADE, lbBlockListener, Priority.Monitor, this);
|
||||
if (config.logExplosions)
|
||||
if (config.isLogging(Logging.EXPLOSION))
|
||||
pm.registerEvent(Type.ENTITY_EXPLODE, lbEntityListener, Priority.Monitor, this);
|
||||
if (config.logLeavesDecay)
|
||||
if (config.isLogging(Logging.LEAVESDECAY))
|
||||
pm.registerEvent(Type.LEAVES_DECAY, lbBlockListener, Priority.Monitor, this);
|
||||
if (config.logChestAccess)
|
||||
if (pm.getPlugin("Spout") != null)
|
||||
if (config.isLogging(Logging.CHESTACCESS))
|
||||
if (pm.isPluginEnabled("Spout"))
|
||||
pm.registerEvent(Type.CUSTOM_EVENT, new LBChestAccessListener(this), Priority.Monitor, this);
|
||||
else
|
||||
getLogger().warning("[LogBlock] BukkitContrib not found. Can't log chest accesses.");
|
||||
if (config.logButtonsAndLevers || config.logDoors || config.logCakes)
|
||||
getLogger().warning("[LogBlock] Spout not found. Can't log chest accesses.");
|
||||
if (config.isLogging(Logging.SWITCHINTERACT) || config.isLogging(Logging.DOORINTERACT) || config.isLogging(Logging.CAKEEAT))
|
||||
pm.registerEvent(Type.PLAYER_INTERACT, lbPlayerListener, Priority.Monitor, this);
|
||||
if (config.logKills)
|
||||
if (config.isLogging(Logging.KILL))
|
||||
pm.registerEvent(Type.ENTITY_DAMAGE, lbEntityListener, Priority.Monitor, this);
|
||||
if (config.logChat) {
|
||||
if (config.isLogging(Logging.CHAT)) {
|
||||
pm.registerEvent(Type.PLAYER_CHAT, lbPlayerListener, Priority.Monitor, this);
|
||||
pm.registerEvent(Type.PLAYER_COMMAND_PREPROCESS, lbPlayerListener, Priority.Monitor, this);
|
||||
pm.registerEvent(Type.SERVER_COMMAND, new LBServerListener(this), Priority.Monitor, this);
|
||||
}
|
||||
if (config.logEndermen) {
|
||||
if (config.isLogging(Logging.ENDERMEN)) {
|
||||
pm.registerEvent(Type.ENDERMAN_PICKUP, lbEntityListener, Priority.Monitor, this);
|
||||
pm.registerEvent(Type.ENDERMAN_PLACE, lbEntityListener, Priority.Monitor, this);
|
||||
}
|
||||
|
||||
@@ -0,0 +1,7 @@
|
||||
package de.diddiz.LogBlock;
|
||||
|
||||
public enum Logging {
|
||||
BLOCKPLACE, BLOCKBREAK, SIGNTEXT, EXPLOSION, FIRE, LEAVESDECAY, LAVAFLOW, WATERFLOW, CHESTACCESS, KILL, CHAT, SNOWFORM, SNOWFADE, DOORINTERACT, SWITCHINTERACT, CAKEEAT, ENDERMEN;
|
||||
|
||||
public static int length = Logging.values().length;
|
||||
}
|
||||
@@ -25,7 +25,7 @@ class Updater
|
||||
return false;
|
||||
if (config.getString("version").compareTo("1.27") < 0) {
|
||||
getLogger().info("[LogBlock] Updating tables to 1.27 ...");
|
||||
if (logblock.getLBConfig().logChat) {
|
||||
if (logblock.getLBConfig().isLogging(Logging.CHAT)) {
|
||||
final Connection conn = logblock.getConnection();
|
||||
try {
|
||||
conn.setAutoCommit(true);
|
||||
@@ -94,13 +94,13 @@ class Updater
|
||||
final DatabaseMetaData dbm = conn.getMetaData();
|
||||
conn.setAutoCommit(true);
|
||||
createTable(dbm, state, "lb-players", "(playerid SMALLINT UNSIGNED NOT NULL AUTO_INCREMENT, playername varchar(32) NOT NULL, firstlogin DATETIME NOT NULL, lastlogin DATETIME NOT NULL, onlinetime TIME NOT NULL, ip varchar(255) NOT NULL, PRIMARY KEY (playerid), UNIQUE (playername))");
|
||||
if (logblock.getLBConfig().logChat)
|
||||
if (logblock.getLBConfig().isLogging(Logging.CHAT))
|
||||
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), FULLTEXT message (message)) ENGINE=MyISAM");
|
||||
for (final WorldConfig wcfg : logblock.getLBConfig().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)
|
||||
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))");
|
||||
}
|
||||
state.close();
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
package de.diddiz.util;
|
||||
|
||||
import static org.bukkit.Bukkit.getLogger;
|
||||
import java.io.BufferedOutputStream;
|
||||
import java.io.BufferedReader;
|
||||
import java.io.File;
|
||||
@@ -12,6 +13,8 @@ import java.io.OutputStream;
|
||||
import java.net.URL;
|
||||
import java.text.ParseException;
|
||||
import java.text.SimpleDateFormat;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.logging.Logger;
|
||||
|
||||
public class Utils
|
||||
@@ -83,6 +86,19 @@ public class Utils
|
||||
return builder.toString();
|
||||
}
|
||||
|
||||
public static String listing(List<?> entries, String delimiter, String finalDelimiter) {
|
||||
final int len = entries.size();
|
||||
if (len == 0)
|
||||
return "";
|
||||
if (len == 1)
|
||||
return entries.get(0).toString();
|
||||
final StringBuilder builder = new StringBuilder(entries.get(0).toString());
|
||||
for (int i = 1; i < len - 1; i++)
|
||||
builder.append(delimiter + entries.get(i).toString());
|
||||
builder.append(finalDelimiter + entries.get(len - 1).toString());
|
||||
return builder.toString();
|
||||
}
|
||||
|
||||
public static int parseTimeSpec(String[] spec) {
|
||||
if (spec == null || spec.length < 1 || spec.length > 2)
|
||||
return -1;
|
||||
@@ -166,4 +182,32 @@ public class Utils
|
||||
return name.toLowerCase().endsWith(ext);
|
||||
}
|
||||
}
|
||||
|
||||
public static List<String> toStringList(List<?> list) {
|
||||
if (list == null)
|
||||
return new ArrayList<String>();
|
||||
final List<String> strs = new ArrayList<String>(list.size());
|
||||
for (final Object obj : list)
|
||||
if (obj instanceof String)
|
||||
strs.add((String)obj);
|
||||
else
|
||||
strs.add(String.valueOf(obj));
|
||||
return strs;
|
||||
}
|
||||
|
||||
public static List<Integer> toIntList(List<?> list) {
|
||||
if (list == null)
|
||||
return new ArrayList<Integer>();
|
||||
final List<Integer> ints = new ArrayList<Integer>(list.size());
|
||||
for (final Object obj : list)
|
||||
if (obj instanceof Integer)
|
||||
ints.add((Integer)obj);
|
||||
else
|
||||
try {
|
||||
ints.add(Integer.valueOf(String.valueOf(obj)));
|
||||
} catch (final NumberFormatException ex) {
|
||||
getLogger().warning("[LogBlock] Config error: '" + obj + "' is not a number");
|
||||
}
|
||||
return ints;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user