forked from LogBlock/LogBlock
Added logKillsLevel config.
This commit is contained in:
@@ -25,6 +25,7 @@ public class Config {
|
|||||||
final boolean logLeavesDecay;
|
final boolean logLeavesDecay;
|
||||||
final boolean logChestAccess;
|
final boolean logChestAccess;
|
||||||
final boolean logKills;
|
final boolean logKills;
|
||||||
|
final LogKillsLevel logKillsLevel;
|
||||||
final List<Integer> dontRollback;
|
final List<Integer> dontRollback;
|
||||||
final List<Integer> replaceAnyway;
|
final List<Integer> replaceAnyway;
|
||||||
final int defaultDist;
|
final int defaultDist;
|
||||||
@@ -32,6 +33,10 @@ public class Config {
|
|||||||
final int toolID;
|
final int toolID;
|
||||||
final int toolblockID;
|
final int toolblockID;
|
||||||
|
|
||||||
|
enum LogKillsLevel {
|
||||||
|
PLAYERS, MONSTERS, ANIMALS
|
||||||
|
}
|
||||||
|
|
||||||
Config (LogBlock logblock) throws Exception {
|
Config (LogBlock logblock) throws Exception {
|
||||||
Configuration config = logblock.getConfiguration();
|
Configuration config = logblock.getConfiguration();
|
||||||
config.load();
|
config.load();
|
||||||
@@ -89,6 +94,8 @@ public class Config {
|
|||||||
config.setProperty("logging.logLeavesDecay", false);
|
config.setProperty("logging.logLeavesDecay", false);
|
||||||
if (!subkeys.contains("logKills"))
|
if (!subkeys.contains("logKills"))
|
||||||
config.setProperty("logging.logKills", false);
|
config.setProperty("logging.logKills", false);
|
||||||
|
if (!subkeys.contains("logKillsLevel"))
|
||||||
|
config.setProperty("logging.logKillsLevel", "PLAYERS");
|
||||||
subkeys = config.getKeys("rollback");
|
subkeys = config.getKeys("rollback");
|
||||||
if (subkeys == null)
|
if (subkeys == null)
|
||||||
subkeys = new ArrayList<String>();
|
subkeys = new ArrayList<String>();
|
||||||
@@ -124,6 +131,11 @@ public class Config {
|
|||||||
logChestAccess = config.getBoolean("logging.logChestAccess", false);
|
logChestAccess = config.getBoolean("logging.logChestAccess", false);
|
||||||
logLeavesDecay = config.getBoolean("logging.logLeavesDecay", false);
|
logLeavesDecay = config.getBoolean("logging.logLeavesDecay", false);
|
||||||
logKills = config.getBoolean("logging.logKills", 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);
|
dontRollback = config.getIntList("rollback.dontRollback", null);
|
||||||
replaceAnyway = config.getIntList("rollback.replaceAnyway", null);
|
replaceAnyway = config.getIntList("rollback.replaceAnyway", null);
|
||||||
defaultDist = config.getInt("lookup.defaultDist", 20);
|
defaultDist = config.getInt("lookup.defaultDist", 20);
|
||||||
|
@@ -11,17 +11,8 @@ import java.util.concurrent.LinkedBlockingQueue;
|
|||||||
import java.util.logging.Level;
|
import java.util.logging.Level;
|
||||||
|
|
||||||
import org.bukkit.block.Block;
|
import org.bukkit.block.Block;
|
||||||
import org.bukkit.entity.Creeper;
|
|
||||||
import org.bukkit.entity.Entity;
|
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.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
|
public class Consumer extends TimerTask implements Runnable
|
||||||
{
|
{
|
||||||
@@ -80,6 +71,7 @@ public class Consumer extends TimerTask implements Runnable
|
|||||||
String defenderName = getEntityName(defender);
|
String defenderName = getEntityName(defender);
|
||||||
if (attackerName == null || defenderName == null)
|
if (attackerName == null || defenderName == null)
|
||||||
return;
|
return;
|
||||||
|
LogBlock.log.info(attackerName + " killed " + defenderName + " with " + weapon);
|
||||||
lastAttackedEntity.put(attacker.getEntityId(), defender.getEntityId());
|
lastAttackedEntity.put(attacker.getEntityId(), defender.getEntityId());
|
||||||
lastAttackTime.put(attacker.getEntityId(), System.currentTimeMillis());
|
lastAttackTime.put(attacker.getEntityId(), System.currentTimeMillis());
|
||||||
kqueue.add(new KillRow(table, getEntityName(attacker), getEntityName(defender), weapon));
|
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) {
|
private String getEntityName(Entity entity) {
|
||||||
if (entity instanceof Player)
|
if (entity instanceof Player)
|
||||||
return ((Player)entity).getName();
|
return ((Player)entity).getName();
|
||||||
if (entity instanceof Creeper)
|
return entity.getClass().getSimpleName().substring(5);
|
||||||
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;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private class ChestAccess
|
private class ChestAccess
|
||||||
|
@@ -20,6 +20,7 @@ import org.bukkit.entity.Creeper;
|
|||||||
import org.bukkit.entity.Entity;
|
import org.bukkit.entity.Entity;
|
||||||
import org.bukkit.entity.Fireball;
|
import org.bukkit.entity.Fireball;
|
||||||
import org.bukkit.entity.LivingEntity;
|
import org.bukkit.entity.LivingEntity;
|
||||||
|
import org.bukkit.entity.Monster;
|
||||||
import org.bukkit.entity.Player;
|
import org.bukkit.entity.Player;
|
||||||
import org.bukkit.entity.TNTPrimed;
|
import org.bukkit.entity.TNTPrimed;
|
||||||
import org.bukkit.event.Event;
|
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))");
|
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())
|
if (!dbm.getTables(null, null, "lb-players", null).next())
|
||||||
return false;
|
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()) {
|
for (String table : config.tables.values()) {
|
||||||
if (!dbm.getTables(null, null, table, null).next()) {
|
if (!dbm.getTables(null, null, table, null).next()) {
|
||||||
log.log(Level.INFO, "[LogBlock] Crating table " + table + ".");
|
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())
|
if (!dbm.getTables(null, null, table + "-chest", null).next())
|
||||||
return false;
|
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;
|
return true;
|
||||||
} catch (SQLException ex) {
|
} catch (SQLException ex) {
|
||||||
@@ -562,19 +570,15 @@ public class LogBlock extends JavaPlugin
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onEntityDamage(EntityDamageEvent event) {
|
public void onEntityDamage(EntityDamageEvent event) {
|
||||||
if (event.isCancelled())
|
if (event.isCancelled() || !(event instanceof EntityDamageByEntityEvent) || !(event.getEntity() instanceof LivingEntity))
|
||||||
return;
|
|
||||||
if (!(event instanceof EntityDamageByEntityEvent))
|
|
||||||
return;
|
|
||||||
if (!(event.getEntity() instanceof LivingEntity))
|
|
||||||
return;
|
return;
|
||||||
LivingEntity victim = (LivingEntity)event.getEntity();
|
LivingEntity victim = (LivingEntity)event.getEntity();
|
||||||
Entity killer = ((EntityDamageByEntityEvent)event).getDamager();
|
Entity killer = ((EntityDamageByEntityEvent)event).getDamager();
|
||||||
if (!(victim instanceof Player) && !(killer instanceof Player))
|
if (victim.getHealth() - event.getDamage() > 0 || victim.getHealth() <= 0 )
|
||||||
return;
|
return;
|
||||||
if (victim.getHealth() - event.getDamage() > 0)
|
if (config.logKillsLevel == Config.LogKillsLevel.PLAYERS && !(victim instanceof Player && killer instanceof Player))
|
||||||
return;
|
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;
|
return;
|
||||||
consumer.queueKill(killer, victim);
|
consumer.queueKill(killer, victim);
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user