Added logKillsLevel config.

This commit is contained in:
Robin Kupper
2011-04-15 22:17:26 +02:00
parent ea2889da4d
commit df9bc00df7
3 changed files with 27 additions and 37 deletions

View File

@@ -25,6 +25,7 @@ public class Config {
final boolean logLeavesDecay;
final boolean logChestAccess;
final boolean logKills;
final LogKillsLevel logKillsLevel;
final List<Integer> dontRollback;
final List<Integer> replaceAnyway;
final int defaultDist;
@@ -32,6 +33,10 @@ public class Config {
final int toolID;
final int toolblockID;
enum LogKillsLevel {
PLAYERS, MONSTERS, ANIMALS
}
Config (LogBlock logblock) throws Exception {
Configuration config = logblock.getConfiguration();
config.load();
@@ -89,6 +94,8 @@ public class Config {
config.setProperty("logging.logLeavesDecay", false);
if (!subkeys.contains("logKills"))
config.setProperty("logging.logKills", false);
if (!subkeys.contains("logKillsLevel"))
config.setProperty("logging.logKillsLevel", "PLAYERS");
subkeys = config.getKeys("rollback");
if (subkeys == null)
subkeys = new ArrayList<String>();
@@ -124,6 +131,11 @@ public class Config {
logChestAccess = config.getBoolean("logging.logChestAccess", false);
logLeavesDecay = config.getBoolean("logging.logLeavesDecay", false);
logKills = config.getBoolean("logging.logKills", false);
try {
logKillsLevel = LogKillsLevel.valueOf(config.getString("logging.logKillsLevel"));
} catch (IllegalArgumentException ex) {
throw new Exception("lookup.toolblockID doesn't appear to be a valid log level. Allowed are 'PLAYERS', 'MONSTERS' and 'ANIMALS'");
}
dontRollback = config.getIntList("rollback.dontRollback", null);
replaceAnyway = config.getIntList("rollback.replaceAnyway", null);
defaultDist = config.getInt("lookup.defaultDist", 20);

View File

@@ -11,17 +11,8 @@ import java.util.concurrent.LinkedBlockingQueue;
import java.util.logging.Level;
import org.bukkit.block.Block;
import org.bukkit.entity.Creeper;
import org.bukkit.entity.Entity;
import org.bukkit.entity.Ghast;
import org.bukkit.entity.Giant;
import org.bukkit.entity.PigZombie;
import org.bukkit.entity.Player;
import org.bukkit.entity.Skeleton;
import org.bukkit.entity.Slime;
import org.bukkit.entity.Spider;
import org.bukkit.entity.Wolf;
import org.bukkit.entity.Zombie;
public class Consumer extends TimerTask implements Runnable
{
@@ -80,6 +71,7 @@ public class Consumer extends TimerTask implements Runnable
String defenderName = getEntityName(defender);
if (attackerName == null || defenderName == null)
return;
LogBlock.log.info(attackerName + " killed " + defenderName + " with " + weapon);
lastAttackedEntity.put(attacker.getEntityId(), defender.getEntityId());
lastAttackTime.put(attacker.getEntityId(), System.currentTimeMillis());
kqueue.add(new KillRow(table, getEntityName(attacker), getEntityName(defender), weapon));
@@ -158,25 +150,7 @@ public class Consumer extends TimerTask implements Runnable
private String getEntityName(Entity entity) {
if (entity instanceof Player)
return ((Player)entity).getName();
if (entity instanceof Creeper)
return "Creeper";
if (entity instanceof Ghast)
return "Ghast";
if (entity instanceof Giant)
return "Giant";
if (entity instanceof PigZombie)
return "PigZombie";
if (entity instanceof Skeleton)
return "Skeleton";
if (entity instanceof Slime)
return "Slime";
if (entity instanceof Spider)
return "Spider";
if (entity instanceof Wolf)
return "Wolf";
if (entity instanceof Zombie)
return "Zombie";
return null;
return entity.getClass().getSimpleName().substring(5);
}
private class ChestAccess

View File

@@ -20,6 +20,7 @@ import org.bukkit.entity.Creeper;
import org.bukkit.entity.Entity;
import org.bukkit.entity.Fireball;
import org.bukkit.entity.LivingEntity;
import org.bukkit.entity.Monster;
import org.bukkit.entity.Player;
import org.bukkit.entity.TNTPrimed;
import org.bukkit.event.Event;
@@ -440,8 +441,8 @@ public class LogBlock extends JavaPlugin
state.execute("CREATE TABLE `lb-players` (playerid SMALLINT UNSIGNED NOT NULL AUTO_INCREMENT, playername varchar(32) NOT NULL DEFAULT '-', PRIMARY KEY (playerid), UNIQUE (playername))");
if (!dbm.getTables(null, null, "lb-players", null).next())
return false;
state.execute("INSERT IGNORE INTO `lb-players` (playername) VALUES ('TNT'), ('Creeper'), ('Fire'), ('LeavesDecay'), ('Ghast'), ('Environment')");
}
state.execute("INSERT IGNORE INTO `lb-players` (playername) VALUES ('TNT'), ('Creeper'), ('Fire'), ('LeavesDecay'), ('Ghast'), ('Environment')");
for (String table : config.tables.values()) {
if (!dbm.getTables(null, null, table, null).next()) {
log.log(Level.INFO, "[LogBlock] Crating table " + table + ".");
@@ -461,6 +462,13 @@ public class LogBlock extends JavaPlugin
if (!dbm.getTables(null, null, table + "-chest", null).next())
return false;
}
if (config.logKills && !dbm.getTables(null, null, table + "-kills", null).next()) {
log.log(Level.INFO, "[LogBlock] Crating table " + table + "-kills.");
state.execute("CREATE TABLE `" + 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));");
if (!dbm.getTables(null, null, table + "-kills", null).next())
return false;
state.execute("INSERT IGNORE INTO `lb-players` (playername) VALUES ('Chicken'), ('Cow'), ('Creeper'), ('Ghast'), ('Giant'), ('Pig'), ('PigZombie'), ('Sheep'), ('Skeleton'), ('Slime'), ('Spider'), ('Squid'), ('Wolf'), ('Zombie')");
}
}
return true;
} catch (SQLException ex) {
@@ -562,19 +570,15 @@ public class LogBlock extends JavaPlugin
@Override
public void onEntityDamage(EntityDamageEvent event) {
if (event.isCancelled())
return;
if (!(event instanceof EntityDamageByEntityEvent))
return;
if (!(event.getEntity() instanceof LivingEntity))
if (event.isCancelled() || !(event instanceof EntityDamageByEntityEvent) || !(event.getEntity() instanceof LivingEntity))
return;
LivingEntity victim = (LivingEntity)event.getEntity();
Entity killer = ((EntityDamageByEntityEvent)event).getDamager();
if (!(victim instanceof Player) && !(killer instanceof Player))
if (victim.getHealth() - event.getDamage() > 0 || victim.getHealth() <= 0 )
return;
if (victim.getHealth() - event.getDamage() > 0)
if (config.logKillsLevel == Config.LogKillsLevel.PLAYERS && !(victim instanceof Player && killer instanceof Player))
return;
if (victim.getHealth() <= 0 )
else if (config.logKillsLevel == Config.LogKillsLevel.MONSTERS && !((victim instanceof Player || victim instanceof Monster) && killer instanceof Player || killer instanceof Monster))
return;
consumer.queueKill(killer, victim);
}