This commit is contained in:
Brokkonaut
2019-06-23 16:45:14 +02:00
parent 76f7f8701d
commit 1525d7682f
25 changed files with 260 additions and 285 deletions

View File

@@ -127,7 +127,7 @@ public class BlockChange implements LookupCacheElement {
msg.append("opened ").append(type.getMaterial().name()); msg.append("opened ").append(type.getMaterial().name());
} else if (type instanceof Openable) { } else if (type instanceof Openable) {
// Door, Trapdoor, Fence gate // Door, Trapdoor, Fence gate
msg.append(((Openable)type).isOpen() ? "opened" : "closed").append(" ").append(type.getMaterial().name()); msg.append(((Openable) type).isOpen() ? "opened" : "closed").append(" ").append(type.getMaterial().name());
} else if (type.getMaterial() == Material.LEVER) { } else if (type.getMaterial() == Material.LEVER) {
msg.append("switched ").append(type.getMaterial().name()).append(" ").append(((Switch) type).isPowered() ? "on" : "off"); msg.append("switched ").append(type.getMaterial().name()).append(" ").append(((Switch) type).isPowered() ? "on" : "off");
} else if (type instanceof Switch) { } else if (type instanceof Switch) {
@@ -152,7 +152,7 @@ public class BlockChange implements LookupCacheElement {
} else if (type instanceof Sign || type instanceof WallSign) { } else if (type instanceof Sign || type instanceof WallSign) {
msg.append("edited a ").append(type.getMaterial().name()).append(" to ").append(typeDetails); msg.append("edited a ").append(type.getMaterial().name()).append(" to ").append(typeDetails);
} else { } else {
msg.append("replaced ").append(replaced.getMaterial().name()).append(replacedDetails).append(" with ").append(type.getMaterial().name()).append(typeDetails); msg.append("replaced ").append(replaced.getMaterial().name()).append(replacedDetails).append(" with ").append(type.getMaterial().name()).append(typeDetails);
} }
} else if (BukkitUtils.isEmpty(type.getMaterial())) { } else if (BukkitUtils.isEmpty(type.getMaterial())) {
msg.append("destroyed ").append(replaced.getMaterial().name()).append(replacedDetails); msg.append("destroyed ").append(replaced.getMaterial().name()).append(replacedDetails);

View File

@@ -102,7 +102,7 @@ public class CommandsHandler implements CommandExecutor {
sender.sendMessage(ChatColor.GOLD + "silent -- Displays lesser messages"); sender.sendMessage(ChatColor.GOLD + "silent -- Displays lesser messages");
} else if (command.equals("permissions")) { } else if (command.equals("permissions")) {
sender.sendMessage(ChatColor.DARK_AQUA + "You've got the following permissions:"); sender.sendMessage(ChatColor.DARK_AQUA + "You've got the following permissions:");
for (final String permission : new String[]{"me", "lookup", "tp", "rollback", "clearlog", "hide", "ignoreRestrictions", "spawnTools"}) { for (final String permission : new String[] { "me", "lookup", "tp", "rollback", "clearlog", "hide", "ignoreRestrictions", "spawnTools" }) {
if (logblock.hasPermission(sender, "logblock." + permission)) { if (logblock.hasPermission(sender, "logblock." + permission)) {
sender.sendMessage(ChatColor.GOLD + "logblock." + permission); sender.sendMessage(ChatColor.GOLD + "logblock." + permission);
} }
@@ -659,15 +659,15 @@ public class CommandsHandler implements CommandExecutor {
@Override @Override
public void run() { public void run() {
try { try {
if(params.bct == BlockChangeType.CHAT) { if (params.bct == BlockChangeType.CHAT) {
sender.sendMessage(ChatColor.RED + "Chat cannot be rolled back"); sender.sendMessage(ChatColor.RED + "Chat cannot be rolled back");
return; return;
} }
if(params.bct == BlockChangeType.KILLS) { if (params.bct == BlockChangeType.KILLS) {
sender.sendMessage(ChatColor.RED + "Kills cannot be rolled back"); sender.sendMessage(ChatColor.RED + "Kills cannot be rolled back");
return; return;
} }
if(params.sum != SummarizationMode.NONE) { if (params.sum != SummarizationMode.NONE) {
sender.sendMessage(ChatColor.RED + "Cannot rollback summarized changes"); sender.sendMessage(ChatColor.RED + "Cannot rollback summarized changes");
return; return;
} }
@@ -749,15 +749,15 @@ public class CommandsHandler implements CommandExecutor {
@Override @Override
public void run() { public void run() {
try { try {
if(params.bct == BlockChangeType.CHAT) { if (params.bct == BlockChangeType.CHAT) {
sender.sendMessage(ChatColor.RED + "Chat cannot be redone"); sender.sendMessage(ChatColor.RED + "Chat cannot be redone");
return; return;
} }
if(params.bct == BlockChangeType.KILLS) { if (params.bct == BlockChangeType.KILLS) {
sender.sendMessage(ChatColor.RED + "Kills cannot be redone"); sender.sendMessage(ChatColor.RED + "Kills cannot be redone");
return; return;
} }
if(params.sum != SummarizationMode.NONE) { if (params.sum != SummarizationMode.NONE) {
sender.sendMessage(ChatColor.RED + "Cannot redo summarized changes"); sender.sendMessage(ChatColor.RED + "Cannot redo summarized changes");
return; return;
} }
@@ -914,7 +914,7 @@ public class CommandsHandler implements CommandExecutor {
sb.append(rs.getInt("z")); sb.append(rs.getInt("z"));
sb.append(");\n"); sb.append(");\n");
} else if (params.bct == BlockChangeType.ENTITIES || params.bct == BlockChangeType.ENTITIES_CREATED || params.bct == BlockChangeType.ENTITIES_KILLED) { } else if (params.bct == BlockChangeType.ENTITIES || params.bct == BlockChangeType.ENTITIES_CREATED || params.bct == BlockChangeType.ENTITIES_KILLED) {
} else { } else {
sb.append("INSERT INTO `").append(tableBase).append("-blocks` (`id`, `date`, `playerid`, `replaced`, `replacedData`, `type`, `typeData`, `x`, `y`, `z`) VALUES ("); sb.append("INSERT INTO `").append(tableBase).append("-blocks` (`id`, `date`, `playerid`, `replaced`, `replacedData`, `type`, `typeData`, `x`, `y`, `z`) VALUES (");
sb.append(rs.getInt("id")).append(", FROM_UNIXTIME("); sb.append(rs.getInt("id")).append(", FROM_UNIXTIME(");

View File

@@ -357,7 +357,7 @@ public class Consumer extends Thread {
if (hiddenPlayers.contains(player.getName().toLowerCase())) { if (hiddenPlayers.contains(player.getName().toLowerCase())) {
return; return;
} }
while(message.length() > 256) { while (message.length() > 256) {
addQueueLast(new ChatRow(player, message.substring(0, 256))); addQueueLast(new ChatRow(player, message.substring(0, 256)));
message = message.substring(256); message = message.substring(256);
} }
@@ -827,7 +827,7 @@ public class Consumer extends Thread {
Location actorBlockLocation = actor.getBlockLocation(); Location actorBlockLocation = actor.getBlockLocation();
if (actorBlockLocation != null) { if (actorBlockLocation != null) {
Integer tempSourceActor = batchHelper.getUncommitedBlockActor(actorBlockLocation); Integer tempSourceActor = batchHelper.getUncommitedBlockActor(actorBlockLocation);
if(tempSourceActor != null) { if (tempSourceActor != null) {
sourceActor = tempSourceActor; sourceActor = tempSourceActor;
} else { } else {
PreparedStatement smt = batchHelper.getOrPrepareStatement(conn, selectActorIdStatementString, Statement.NO_GENERATED_KEYS); PreparedStatement smt = batchHelper.getOrPrepareStatement(conn, selectActorIdStatementString, Statement.NO_GENERATED_KEYS);

View File

@@ -325,12 +325,12 @@ public class LogBlock extends JavaPlugin {
conn.close(); conn.close();
} }
} }
@Override @Override
public File getFile() { public File getFile() {
return super.getFile(); return super.getFile();
} }
public Questioner getQuestioner() { public Questioner getQuestioner() {
return questioner; return questioner;
} }

View File

@@ -1,14 +1,48 @@
package de.diddiz.LogBlock; package de.diddiz.LogBlock;
public enum Logging { public enum Logging {
BLOCKPLACE(true), BLOCKBREAK(true), SIGNTEXT(true), TNTEXPLOSION(true), CREEPEREXPLOSION(true), BLOCKPLACE(true),
GHASTFIREBALLEXPLOSION(true), ENDERDRAGON(true), MISCEXPLOSION(true), FIRE(true), LEAVESDECAY, BLOCKBREAK(true),
LAVAFLOW, WATERFLOW, CHESTACCESS, KILL, CHAT, SNOWFORM, SNOWFADE, DOORINTERACT, SIGNTEXT(true),
SWITCHINTERACT, CAKEEAT, ENDERMEN, NOTEBLOCKINTERACT, DIODEINTERACT, COMPARATORINTERACT, TNTEXPLOSION(true),
PRESUREPLATEINTERACT, TRIPWIREINTERACT, CREATURECROPTRAMPLE, CROPTRAMPLE, CREEPEREXPLOSION(true),
NATURALSTRUCTUREGROW, GRASSGROWTH, MYCELIUMSPREAD, VINEGROWTH, MUSHROOMSPREAD, GHASTFIREBALLEXPLOSION(true),
WITHER(true), WITHER_SKULL(true), BONEMEALSTRUCTUREGROW, WORLDEDIT, TNTMINECARTEXPLOSION(true), ENDERDRAGON(true),
ENDERCRYSTALEXPLOSION(true), BEDEXPLOSION(true), DRAGONEGGTELEPORT(true), DAYLIGHTDETECTORINTERACT, MISCEXPLOSION(true),
FIRE(true),
LEAVESDECAY,
LAVAFLOW,
WATERFLOW,
CHESTACCESS,
KILL,
CHAT,
SNOWFORM,
SNOWFADE,
DOORINTERACT,
SWITCHINTERACT,
CAKEEAT,
ENDERMEN,
NOTEBLOCKINTERACT,
DIODEINTERACT,
COMPARATORINTERACT,
PRESUREPLATEINTERACT,
TRIPWIREINTERACT,
CREATURECROPTRAMPLE,
CROPTRAMPLE,
NATURALSTRUCTUREGROW,
GRASSGROWTH,
MYCELIUMSPREAD,
VINEGROWTH,
MUSHROOMSPREAD,
WITHER(true),
WITHER_SKULL(true),
BONEMEALSTRUCTUREGROW,
WORLDEDIT,
TNTMINECARTEXPLOSION(true),
ENDERCRYSTALEXPLOSION(true),
BEDEXPLOSION(true),
DRAGONEGGTELEPORT(true),
DAYLIGHTDETECTORINTERACT,
LECTERNBOOKCHANGE(true); LECTERNBOOKCHANGE(true);
public static final int length = Logging.values().length; public static final int length = Logging.values().length;

View File

@@ -22,7 +22,7 @@ public class MaterialConverter {
private static String[] idToBlockState = new String[10]; private static String[] idToBlockState = new String[10];
private static HashMap<String, Integer> blockStateToID = new HashMap<>(); private static HashMap<String, Integer> blockStateToID = new HashMap<>();
private static int nextBlockStateId; private static int nextBlockStateId;
private static HashMap<String, Material> materialKeyToMaterial = new HashMap<>(); private static HashMap<String, Material> materialKeyToMaterial = new HashMap<>();
static { static {

View File

@@ -273,7 +273,7 @@ public final class QueryParams implements Cloneable {
if (needType) { if (needType) {
select += "entitytypeid, action, "; select += "entitytypeid, action, ";
} }
if(needData) { if (needData) {
select += "entityid, entityuuid, data, "; select += "entityid, entityuuid, data, ";
} }
} }
@@ -291,21 +291,26 @@ public final class QueryParams implements Cloneable {
} }
if (bct == BlockChangeType.KILLS) { if (bct == BlockChangeType.KILLS) {
if (sum == SummarizationMode.PLAYERS) { if (sum == SummarizationMode.PLAYERS) {
return "SELECT playername, UUID, SUM(kills) AS kills, SUM(killed) AS killed FROM ((SELECT killer AS playerid, count(*) AS kills, 0 as killed FROM `" + getTable() + "-kills` INNER JOIN `lb-players` as killers ON (killer=killers.playerid) INNER JOIN `lb-players` as victims ON (victim=victims.playerid) " + getWhere(BlockChangeType.KILLS) + "GROUP BY killer) UNION (SELECT victim AS playerid, 0 as kills, count(*) AS killed FROM `" + getTable() + "-kills` INNER JOIN `lb-players` as killers ON (killer=killers.playerid) INNER JOIN `lb-players` as victims ON (victim=victims.playerid) " + getWhere(BlockChangeType.KILLS) + "GROUP BY victim)) AS t INNER JOIN `lb-players` USING (playerid) GROUP BY playerid ORDER BY SUM(kills) + SUM(killed) " + order + " " + getLimit(); return "SELECT playername, UUID, SUM(kills) AS kills, SUM(killed) AS killed FROM ((SELECT killer AS playerid, count(*) AS kills, 0 as killed FROM `" + getTable() + "-kills` INNER JOIN `lb-players` as killers ON (killer=killers.playerid) INNER JOIN `lb-players` as victims ON (victim=victims.playerid) " + getWhere(BlockChangeType.KILLS) + "GROUP BY killer) UNION (SELECT victim AS playerid, 0 as kills, count(*) AS killed FROM `" + getTable()
+ "-kills` INNER JOIN `lb-players` as killers ON (killer=killers.playerid) INNER JOIN `lb-players` as victims ON (victim=victims.playerid) " + getWhere(BlockChangeType.KILLS) + "GROUP BY victim)) AS t INNER JOIN `lb-players` USING (playerid) GROUP BY playerid ORDER BY SUM(kills) + SUM(killed) " + order + " " + getLimit();
} }
throw new IllegalStateException("Invalid summarization for kills"); throw new IllegalStateException("Invalid summarization for kills");
} }
if (bct == BlockChangeType.ENTITIES || bct == BlockChangeType.ENTITIES_CREATED || bct == BlockChangeType.ENTITIES_KILLED) { if (bct == BlockChangeType.ENTITIES || bct == BlockChangeType.ENTITIES_CREATED || bct == BlockChangeType.ENTITIES_KILLED) {
if (sum == SummarizationMode.TYPES) { if (sum == SummarizationMode.TYPES) {
return "SELECT entitytypeid, SUM(created) AS created, SUM(destroyed) AS destroyed FROM ((SELECT entitytypeid, count(*) AS created, 0 AS destroyed FROM `" + getTable() + "-entities` INNER JOIN `lb-players` USING (playerid) " + getWhere(BlockChangeType.ENTITIES_CREATED) + "GROUP BY entitytypeid) UNION (SELECT entitytypeid, 0 AS created, count(*) AS destroyed FROM `" + getTable() + "-entities` INNER JOIN `lb-players` USING (playerid) " + getWhere(BlockChangeType.ENTITIES_KILLED) + "GROUP BY entitytypeid)) AS t GROUP BY entitytypeid ORDER BY SUM(created) + SUM(destroyed) " + order + " " + getLimit(); return "SELECT entitytypeid, SUM(created) AS created, SUM(destroyed) AS destroyed FROM ((SELECT entitytypeid, count(*) AS created, 0 AS destroyed FROM `" + getTable() + "-entities` INNER JOIN `lb-players` USING (playerid) " + getWhere(BlockChangeType.ENTITIES_CREATED) + "GROUP BY entitytypeid) UNION (SELECT entitytypeid, 0 AS created, count(*) AS destroyed FROM `" + getTable() + "-entities` INNER JOIN `lb-players` USING (playerid) " + getWhere(BlockChangeType.ENTITIES_KILLED)
+ "GROUP BY entitytypeid)) AS t GROUP BY entitytypeid ORDER BY SUM(created) + SUM(destroyed) " + order + " " + getLimit();
} else { } else {
return "SELECT playername, UUID, SUM(created) AS created, SUM(destroyed) AS destroyed FROM ((SELECT playerid, count(*) AS created, 0 AS destroyed FROM `" + getTable() + "-entities` " + getWhere(BlockChangeType.ENTITIES_CREATED) + "GROUP BY playerid) UNION (SELECT playerid, 0 AS created, count(*) AS destroyed FROM `" + getTable() + "-entities` " + getWhere(BlockChangeType.ENTITIES_KILLED) + "GROUP BY playerid)) AS t INNER JOIN `lb-players` USING (playerid) GROUP BY playerid ORDER BY SUM(created) + SUM(destroyed) " + order + " " + getLimit(); return "SELECT playername, UUID, SUM(created) AS created, SUM(destroyed) AS destroyed FROM ((SELECT playerid, count(*) AS created, 0 AS destroyed FROM `" + getTable() + "-entities` " + getWhere(BlockChangeType.ENTITIES_CREATED) + "GROUP BY playerid) UNION (SELECT playerid, 0 AS created, count(*) AS destroyed FROM `" + getTable() + "-entities` " + getWhere(BlockChangeType.ENTITIES_KILLED)
+ "GROUP BY playerid)) AS t INNER JOIN `lb-players` USING (playerid) GROUP BY playerid ORDER BY SUM(created) + SUM(destroyed) " + order + " " + getLimit();
} }
} }
if (sum == SummarizationMode.TYPES) { if (sum == SummarizationMode.TYPES) {
return "SELECT type, SUM(created) AS created, SUM(destroyed) AS destroyed FROM ((SELECT type, count(*) AS created, 0 AS destroyed FROM `" + getTable() + "-blocks` INNER JOIN `lb-players` USING (playerid) " + getWhere(BlockChangeType.CREATED) + "GROUP BY type) UNION (SELECT replaced AS type, 0 AS created, count(*) AS destroyed FROM `" + getTable() + "-blocks` INNER JOIN `lb-players` USING (playerid) " + getWhere(BlockChangeType.DESTROYED) + "GROUP BY replaced)) AS t GROUP BY type ORDER BY SUM(created) + SUM(destroyed) " + order + " " + getLimit(); return "SELECT type, SUM(created) AS created, SUM(destroyed) AS destroyed FROM ((SELECT type, count(*) AS created, 0 AS destroyed FROM `" + getTable() + "-blocks` INNER JOIN `lb-players` USING (playerid) " + getWhere(BlockChangeType.CREATED) + "GROUP BY type) UNION (SELECT replaced AS type, 0 AS created, count(*) AS destroyed FROM `" + getTable() + "-blocks` INNER JOIN `lb-players` USING (playerid) " + getWhere(BlockChangeType.DESTROYED)
+ "GROUP BY replaced)) AS t GROUP BY type ORDER BY SUM(created) + SUM(destroyed) " + order + " " + getLimit();
} else { } else {
return "SELECT playername, UUID, SUM(created) AS created, SUM(destroyed) AS destroyed FROM ((SELECT playerid, count(*) AS created, 0 AS destroyed FROM `" + getTable() + "-blocks` " + getWhere(BlockChangeType.CREATED) + "GROUP BY playerid) UNION (SELECT playerid, 0 AS created, count(*) AS destroyed FROM `" + getTable() + "-blocks` " + getWhere(BlockChangeType.DESTROYED) + "GROUP BY playerid)) AS t INNER JOIN `lb-players` USING (playerid) GROUP BY playerid ORDER BY SUM(created) + SUM(destroyed) " + order + " " + getLimit(); return "SELECT playername, UUID, SUM(created) AS created, SUM(destroyed) AS destroyed FROM ((SELECT playerid, count(*) AS created, 0 AS destroyed FROM `" + getTable() + "-blocks` " + getWhere(BlockChangeType.CREATED) + "GROUP BY playerid) UNION (SELECT playerid, 0 AS created, count(*) AS destroyed FROM `" + getTable() + "-blocks` " + getWhere(BlockChangeType.DESTROYED)
+ "GROUP BY playerid)) AS t INNER JOIN `lb-players` USING (playerid) GROUP BY playerid ORDER BY SUM(created) + SUM(destroyed) " + order + " " + getLimit();
} }
} }
@@ -574,22 +579,20 @@ public final class QueryParams implements Cloneable {
break; break;
} }
} }
if(blockChangeType != BlockChangeType.CHAT) { if (blockChangeType != BlockChangeType.CHAT) {
if (loc != null) { if (loc != null) {
if (radius == 0) { if (radius == 0) {
compileLocationQuery( compileLocationQuery(
where, where,
loc.getBlockX(), loc.getBlockX(), loc.getBlockX(), loc.getBlockX(),
loc.getBlockY(), loc.getBlockY(), loc.getBlockY(), loc.getBlockY(),
loc.getBlockZ(), loc.getBlockZ() loc.getBlockZ(), loc.getBlockZ());
);
} else if (radius > 0) { } else if (radius > 0) {
compileLocationQuery( compileLocationQuery(
where, where,
loc.getBlockX() - radius + 1, loc.getBlockX() + radius - 1, loc.getBlockX() - radius + 1, loc.getBlockX() + radius - 1,
loc.getBlockY() - radius + 1, loc.getBlockY() + radius - 1, loc.getBlockY() - radius + 1, loc.getBlockY() + radius - 1,
loc.getBlockZ() - radius + 1, loc.getBlockZ() + radius - 1 loc.getBlockZ() - radius + 1, loc.getBlockZ() + radius - 1);
);
} }
} else if (sel != null) { } else if (sel != null) {
@@ -597,8 +600,7 @@ public final class QueryParams implements Cloneable {
where, where,
sel.getMinimumPoint().getBlockX(), sel.getMaximumPoint().getBlockX(), sel.getMinimumPoint().getBlockX(), sel.getMaximumPoint().getBlockX(),
sel.getMinimumPoint().getBlockY(), sel.getMaximumPoint().getBlockY(), sel.getMinimumPoint().getBlockY(), sel.getMaximumPoint().getBlockY(),
sel.getMinimumPoint().getBlockZ(), sel.getMaximumPoint().getBlockZ() sel.getMinimumPoint().getBlockZ(), sel.getMaximumPoint().getBlockZ());
);
} }
} }
if (!players.isEmpty() && sum != SummarizationMode.PLAYERS && blockChangeType != BlockChangeType.KILLS) { if (!players.isEmpty() && sum != SummarizationMode.PLAYERS && blockChangeType != BlockChangeType.KILLS) {
@@ -1028,14 +1030,26 @@ public final class QueryParams implements Cloneable {
} }
public static enum BlockChangeType { public static enum BlockChangeType {
ALL, BOTH, CHESTACCESS, CREATED, DESTROYED, CHAT, KILLS, ENTITIES, ENTITIES_CREATED, ENTITIES_KILLED, ALL,
BOTH,
CHESTACCESS,
CREATED,
DESTROYED,
CHAT,
KILLS,
ENTITIES,
ENTITIES_CREATED,
ENTITIES_KILLED,
} }
public static enum Order { public static enum Order {
ASC, DESC ASC,
DESC
} }
public static enum SummarizationMode { public static enum SummarizationMode {
NONE, PLAYERS, TYPES NONE,
PLAYERS,
TYPES
} }
} }

View File

@@ -1,5 +1,7 @@
package de.diddiz.LogBlock; package de.diddiz.LogBlock;
public enum ToolBehavior { public enum ToolBehavior {
TOOL, BLOCK, NONE TOOL,
BLOCK,
NONE
} }

View File

@@ -1,7 +1,11 @@
package de.diddiz.LogBlock; package de.diddiz.LogBlock;
public enum ToolMode { public enum ToolMode {
CLEARLOG("logblock.clearlog"), LOOKUP("logblock.lookup"), REDO("logblock.rollback"), ROLLBACK("logblock.rollback"), WRITELOGFILE("logblock.rollback"); CLEARLOG("logblock.clearlog"),
LOOKUP("logblock.lookup"),
REDO("logblock.rollback"),
ROLLBACK("logblock.rollback"),
WRITELOGFILE("logblock.rollback");
private final String permission; private final String permission;
private ToolMode(String permission) { private ToolMode(String permission) {

View File

@@ -431,7 +431,7 @@ class Updater {
logblock.getLogger().info("Converting " + rowsToConvert + " entries in " + wcfg.table); logblock.getLogger().info("Converting " + rowsToConvert + " entries in " + wcfg.table);
} }
rs.close(); rs.close();
PreparedStatement deleteStatement = conn.prepareStatement("DELETE FROM `" + wcfg.table + "` WHERE id = ?"); PreparedStatement deleteStatement = conn.prepareStatement("DELETE FROM `" + wcfg.table + "` WHERE id = ?");
PreparedStatement insertStatement = conn.prepareStatement("INSERT INTO `" + wcfg.table + "-blocks` (id, date, playerid, replaced, replacedData, type, typeData, x, y, z) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?)", Statement.RETURN_GENERATED_KEYS); PreparedStatement insertStatement = conn.prepareStatement("INSERT INTO `" + wcfg.table + "-blocks` (id, date, playerid, replaced, replacedData, type, typeData, x, y, z) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?)", Statement.RETURN_GENERATED_KEYS);
@@ -515,7 +515,7 @@ class Updater {
logblock.getLogger().info("Converting " + rowsToConvert + " entries in " + wcfg.table + "-chest"); logblock.getLogger().info("Converting " + rowsToConvert + " entries in " + wcfg.table + "-chest");
} }
rs.close(); rs.close();
PreparedStatement insertChestData = conn.prepareStatement("INSERT INTO `" + wcfg.table + "-chestdata` (id, item, itemremove, itemtype) VALUES (?, ?, ?, ?)"); PreparedStatement insertChestData = conn.prepareStatement("INSERT INTO `" + wcfg.table + "-chestdata` (id, item, itemremove, itemtype) VALUES (?, ?, ?, ?)");
PreparedStatement deleteChest = conn.prepareStatement("DELETE FROM `" + wcfg.table + "-chest` WHERE id = ?"); PreparedStatement deleteChest = conn.prepareStatement("DELETE FROM `" + wcfg.table + "-chest` WHERE id = ?");
while (true) { while (true) {
@@ -532,13 +532,13 @@ class Updater {
weaponMaterial = Material.AIR; weaponMaterial = Material.AIR;
} }
@SuppressWarnings("deprecation") @SuppressWarnings("deprecation")
ItemStack stack = weaponMaterial.getMaxDurability() > 0 ? new ItemStack(weaponMaterial, Math.abs(amount), (short)itemdata) : new ItemStack(weaponMaterial, Math.abs(amount)); ItemStack stack = weaponMaterial.getMaxDurability() > 0 ? new ItemStack(weaponMaterial, Math.abs(amount), (short) itemdata) : new ItemStack(weaponMaterial, Math.abs(amount));
insertChestData.setInt(1, id); insertChestData.setInt(1, id);
insertChestData.setBytes(2, Utils.saveItemStack(stack)); insertChestData.setBytes(2, Utils.saveItemStack(stack));
insertChestData.setInt(3, amount >= 0 ? 0 : 1); insertChestData.setInt(3, amount >= 0 ? 0 : 1);
insertChestData.setInt(4, MaterialConverter.getOrAddMaterialId(weaponMaterial.getKey())); insertChestData.setInt(4, MaterialConverter.getOrAddMaterialId(weaponMaterial.getKey()));
insertChestData.addBatch(); insertChestData.addBatch();
deleteChest.setInt(1, id); deleteChest.setInt(1, id);
deleteChest.addBatch(); deleteChest.addBatch();
done++; done++;
@@ -578,7 +578,7 @@ class Updater {
logblock.getLogger().info("Converting " + rowsToConvert + " entries in " + wcfg.table + "-kills"); logblock.getLogger().info("Converting " + rowsToConvert + " entries in " + wcfg.table + "-kills");
} }
rs.close(); rs.close();
PreparedStatement updateWeaponStatement = conn.prepareStatement("UPDATE `" + wcfg.table + "-kills` SET weapon = ? WHERE id = ?"); PreparedStatement updateWeaponStatement = conn.prepareStatement("UPDATE `" + wcfg.table + "-kills` SET weapon = ? WHERE id = ?");
for (int start = 0;; start += OTHER_CONVERT_BATCH_SIZE) { for (int start = 0;; start += OTHER_CONVERT_BATCH_SIZE) {
rs = st.executeQuery("SELECT id, weapon FROM `" + wcfg.table + "-kills` ORDER BY id ASC LIMIT " + start + "," + OTHER_CONVERT_BATCH_SIZE); rs = st.executeQuery("SELECT id, weapon FROM `" + wcfg.table + "-kills` ORDER BY id ASC LIMIT " + start + "," + OTHER_CONVERT_BATCH_SIZE);
@@ -855,7 +855,7 @@ class Updater {
currentMinecraftVersion = currentMinecraftVersion.substring(currentMinecraftVersion.indexOf("(MC: ") + 5); currentMinecraftVersion = currentMinecraftVersion.substring(currentMinecraftVersion.indexOf("(MC: ") + 5);
int currentVersionEnd = currentMinecraftVersion.indexOf(" "); int currentVersionEnd = currentMinecraftVersion.indexOf(" ");
int currentVersionEnd2 = currentMinecraftVersion.indexOf(")"); int currentVersionEnd2 = currentMinecraftVersion.indexOf(")");
if(currentVersionEnd2 >= 0 && (currentVersionEnd < 0 || currentVersionEnd2 < currentVersionEnd)) { if (currentVersionEnd2 >= 0 && (currentVersionEnd < 0 || currentVersionEnd2 < currentVersionEnd)) {
currentVersionEnd = currentVersionEnd2; currentVersionEnd = currentVersionEnd2;
} }
currentMinecraftVersion = currentMinecraftVersion.substring(0, currentVersionEnd); currentMinecraftVersion = currentMinecraftVersion.substring(0, currentVersionEnd);
@@ -944,6 +944,7 @@ class Updater {
public static class MaterialUpdater1_13 { public static class MaterialUpdater1_13 {
BlockData[][] blockDataMapping; BlockData[][] blockDataMapping;
Material[][] itemMapping = new Material[10][]; Material[][] itemMapping = new Material[10][];
public MaterialUpdater1_13(LogBlock plugin) throws IOException { public MaterialUpdater1_13(LogBlock plugin) throws IOException {
blockDataMapping = new BlockData[256][16]; blockDataMapping = new BlockData[256][16];
try (JarFile file = new JarFile(plugin.getFile())) { try (JarFile file = new JarFile(plugin.getFile())) {

View File

@@ -91,7 +91,6 @@ public class WorldEditor implements Runnable {
return blacklistCollisions; return blacklistCollisions;
} }
public void setSender(CommandSender sender) { public void setSender(CommandSender sender) {
this.sender = sender; this.sender = sender;
} }
@@ -202,12 +201,14 @@ public class WorldEditor implements Runnable {
} }
public static enum PerformResult { public static enum PerformResult {
SUCCESS, BLACKLISTED, NO_ACTION SUCCESS,
BLACKLISTED,
NO_ACTION
} }
public interface Edit { public interface Edit {
PerformResult perform() throws WorldEditorException; PerformResult perform() throws WorldEditorException;
public long getTime(); public long getTime();
} }
@@ -440,6 +441,7 @@ public class WorldEditor implements Runnable {
public static class EditComparator implements Comparator<Edit> { public static class EditComparator implements Comparator<Edit> {
private final int mult; private final int mult;
public EditComparator(QueryParams.Order order) { public EditComparator(QueryParams.Order order) {
mult = order == Order.DESC ? 1 : -1; mult = order == Order.DESC ? 1 : -1;
} }

View File

@@ -21,7 +21,7 @@ public class WorldEditorEditFactory {
public void processRow(ResultSet rs) throws SQLException { public void processRow(ResultSet rs) throws SQLException {
if (params.bct == BlockChangeType.ENTITIES) { if (params.bct == BlockChangeType.ENTITIES) {
editor.queueEntityEdit(rs, params, rollback); editor.queueEntityEdit(rs, params, rollback);
return; return;
} }
ChestAccess chestaccess = null; ChestAccess chestaccess = null;

View File

@@ -58,7 +58,9 @@ public class Config {
public static boolean mb4 = false; public static boolean mb4 = false;
public static enum LogKillsLevel { public static enum LogKillsLevel {
PLAYERS, MONSTERS, ANIMALS; PLAYERS,
MONSTERS,
ANIMALS;
} }
public static void load(LogBlock logblock) throws DataFormatException, IOException { public static void load(LogBlock logblock) throws DataFormatException, IOException {
@@ -158,10 +160,10 @@ public class Config {
} }
} }
logblock.saveConfig(); logblock.saveConfig();
ComparableVersion configVersion = new ComparableVersion(config.getString("version")); ComparableVersion configVersion = new ComparableVersion(config.getString("version"));
boolean oldConfig = configVersion.compareTo(new ComparableVersion(logblock.getDescription().getVersion().replace(" (manually compiled)", ""))) < 0; boolean oldConfig = configVersion.compareTo(new ComparableVersion(logblock.getDescription().getVersion().replace(" (manually compiled)", ""))) < 0;
url = "jdbc:mysql://" + config.getString("mysql.host") + ":" + config.getInt("mysql.port") + "/" + getStringIncludingInts(config, "mysql.database"); url = "jdbc:mysql://" + config.getString("mysql.host") + ":" + config.getInt("mysql.port") + "/" + getStringIncludingInts(config, "mysql.database");
user = getStringIncludingInts(config, "mysql.user"); user = getStringIncludingInts(config, "mysql.user");
password = getStringIncludingInts(config, "mysql.password"); password = getStringIncludingInts(config, "mysql.password");
@@ -246,7 +248,7 @@ public class Config {
final ToolBehavior leftClickBehavior = ToolBehavior.valueOf(tSec.getString("leftClickBehavior").toUpperCase()); final ToolBehavior leftClickBehavior = ToolBehavior.valueOf(tSec.getString("leftClickBehavior").toUpperCase());
final ToolBehavior rightClickBehavior = ToolBehavior.valueOf(tSec.getString("rightClickBehavior").toUpperCase()); final ToolBehavior rightClickBehavior = ToolBehavior.valueOf(tSec.getString("rightClickBehavior").toUpperCase());
final boolean defaultEnabled = tSec.getBoolean("defaultEnabled", false); final boolean defaultEnabled = tSec.getBoolean("defaultEnabled", false);
final Material item = Material.matchMaterial(tSec.getString("item","OAK_LOG")); final Material item = Material.matchMaterial(tSec.getString("item", "OAK_LOG"));
final boolean canDrop = tSec.getBoolean("canDrop", false); final boolean canDrop = tSec.getBoolean("canDrop", false);
final boolean removeOnDisable = tSec.getBoolean("removeOnDisable", true); final boolean removeOnDisable = tSec.getBoolean("removeOnDisable", true);
final boolean dropToDisable = tSec.getBoolean("dropToDisable", false); final boolean dropToDisable = tSec.getBoolean("dropToDisable", false);

View File

@@ -43,13 +43,13 @@ public class BlockBurnLogging extends LoggingListener {
} else { } else {
actor = new Actor("Dispenser"); actor = new Actor("Dispenser");
} }
} else if(event.getCause() == IgniteCause.LIGHTNING) { } else if (event.getCause() == IgniteCause.LIGHTNING) {
actor = new Actor("Lightning"); actor = new Actor("Lightning");
} else if(event.getCause() == IgniteCause.EXPLOSION) { } else if (event.getCause() == IgniteCause.EXPLOSION) {
actor = new Actor("Explosion"); actor = new Actor("Explosion");
} else if(event.getCause() == IgniteCause.LAVA) { } else if (event.getCause() == IgniteCause.LAVA) {
actor = new Actor("Lava"); actor = new Actor("Lava");
} else if(event.getCause() == IgniteCause.ENDER_CRYSTAL) { } else if (event.getCause() == IgniteCause.ENDER_CRYSTAL) {
actor = new Actor("EnderCrystal"); actor = new Actor("EnderCrystal");
} }
if (isLogging(event.getBlock().getWorld(), Logging.FIRE)) { if (isLogging(event.getBlock().getWorld(), Logging.FIRE)) {

View File

@@ -65,4 +65,3 @@ public class CreatureInteractLogging extends LoggingListener {
} }
} }
} }

View File

@@ -100,7 +100,7 @@ public class ExplosionLogging extends LoggingListener {
} }
actor = Actor.actorFromEntity(source); actor = Actor.actorFromEntity(source);
} else if (source instanceof EnderCrystal){ } else if (source instanceof EnderCrystal) {
if (!wcfg.isLogging(Logging.ENDERCRYSTALEXPLOSION)) { if (!wcfg.isLogging(Logging.ENDERCRYSTALEXPLOSION)) {
return; return;
} }

View File

@@ -40,7 +40,7 @@ public class FluidFlowLogging extends LoggingListener {
if (typeFrom == Material.SEAGRASS || typeFrom == Material.KELP_PLANT || typeFrom == Material.KELP) { if (typeFrom == Material.SEAGRASS || typeFrom == Material.KELP_PLANT || typeFrom == Material.KELP) {
typeFrom = Material.WATER; typeFrom = Material.WATER;
fromWaterlogged = true; fromWaterlogged = true;
} }
Block source = Config.logFluidFlowAsPlayerWhoTriggeredIt ? event.getBlock() : null; Block source = Config.logFluidFlowAsPlayerWhoTriggeredIt ? event.getBlock() : null;
final Block to = event.getToBlock(); final Block to = event.getToBlock();

View File

@@ -16,7 +16,6 @@ import org.bukkit.event.entity.EntityDeathEvent;
import static de.diddiz.LogBlock.config.Config.*; import static de.diddiz.LogBlock.config.Config.*;
public class KillLogging extends LoggingListener { public class KillLogging extends LoggingListener {
public KillLogging(LogBlock lb) { public KillLogging(LogBlock lb) {

View File

@@ -16,12 +16,6 @@ public class SnowFormLogging extends LoggingListener {
super(lb); super(lb);
} }
// @EventHandler(priority = EventPriority.MONITOR, ignoreCancelled = true)
// public void onLeavesDecay(LeavesDecayEvent event) {
// if (isLogging(event.getBlock().getWorld(), Logging.SNOWFORM))
// consumer.queueBlockBreak("LeavesDecay", event.getBlock().getState());
// }
@EventHandler(priority = EventPriority.MONITOR, ignoreCancelled = true) @EventHandler(priority = EventPriority.MONITOR, ignoreCancelled = true)
public void onBlockForm(BlockFormEvent event) { public void onBlockForm(BlockFormEvent event) {
if (isLogging(event.getBlock().getWorld(), Logging.SNOWFORM)) { if (isLogging(event.getBlock().getWorld(), Logging.SNOWFORM)) {

View File

@@ -141,14 +141,14 @@ public class BukkitUtils {
singleBlockPlants.add(Material.WHITE_TULIP); singleBlockPlants.add(Material.WHITE_TULIP);
singleBlockPlants.add(Material.PINK_TULIP); singleBlockPlants.add(Material.PINK_TULIP);
singleBlockPlants.add(Material.RED_TULIP); singleBlockPlants.add(Material.RED_TULIP);
singleBlockPlants.add(Material.OXEYE_DAISY); singleBlockPlants.add(Material.OXEYE_DAISY);
singleBlockPlants.add(Material.BROWN_MUSHROOM); singleBlockPlants.add(Material.BROWN_MUSHROOM);
singleBlockPlants.add(Material.RED_MUSHROOM); singleBlockPlants.add(Material.RED_MUSHROOM);
singleBlockPlants.add(Material.SWEET_BERRY_BUSH); singleBlockPlants.add(Material.SWEET_BERRY_BUSH);
singleBlockPlants.add(Material.LILY_OF_THE_VALLEY); singleBlockPlants.add(Material.LILY_OF_THE_VALLEY);
singleBlockPlants.add(Material.CORNFLOWER); singleBlockPlants.add(Material.CORNFLOWER);
singleBlockPlants.add(Material.WITHER_ROSE); singleBlockPlants.add(Material.WITHER_ROSE);
doublePlants = EnumSet.noneOf(Material.class); doublePlants = EnumSet.noneOf(Material.class);
doublePlants.add(Material.TALL_GRASS); doublePlants.add(Material.TALL_GRASS);
doublePlants.add(Material.LARGE_FERN); doublePlants.add(Material.LARGE_FERN);
@@ -157,7 +157,7 @@ public class BukkitUtils {
doublePlants.add(Material.LILAC); doublePlants.add(Material.LILAC);
doublePlants.add(Material.SUNFLOWER); doublePlants.add(Material.SUNFLOWER);
doublePlants.add(Material.PEONY); doublePlants.add(Material.PEONY);
blockEquivalents = new HashSet<Set<Integer>>(7); blockEquivalents = new HashSet<Set<Integer>>(7);
blockEquivalents.add(new HashSet<Integer>(Arrays.asList(2, 3, 60))); blockEquivalents.add(new HashSet<Integer>(Arrays.asList(2, 3, 60)));
blockEquivalents.add(new HashSet<Integer>(Arrays.asList(8, 9, 79))); blockEquivalents.add(new HashSet<Integer>(Arrays.asList(8, 9, 79)));
@@ -218,9 +218,9 @@ public class BukkitUtils {
relativeTopBreakable.addAll(doublePlants); relativeTopBreakable.addAll(doublePlants);
relativeTopBreakable.add(Material.BAMBOO); relativeTopBreakable.add(Material.BAMBOO);
relativeTopBreakable.add(Material.BAMBOO_SAPLING); relativeTopBreakable.add(Material.BAMBOO_SAPLING);
for(Material m : Material.values()) { for (Material m : Material.values()) {
if(m.name().startsWith("POTTED_")) { if (m.name().startsWith("POTTED_")) {
relativeTopBreakable.add(m); relativeTopBreakable.add(m);
} }
} }
@@ -249,7 +249,7 @@ public class BukkitUtils {
fallingEntityKillers.add(Material.WHITE_TULIP); fallingEntityKillers.add(Material.WHITE_TULIP);
fallingEntityKillers.add(Material.PINK_TULIP); fallingEntityKillers.add(Material.PINK_TULIP);
fallingEntityKillers.add(Material.RED_TULIP); fallingEntityKillers.add(Material.RED_TULIP);
fallingEntityKillers.add(Material.OXEYE_DAISY); fallingEntityKillers.add(Material.OXEYE_DAISY);
fallingEntityKillers.add(Material.BROWN_MUSHROOM); fallingEntityKillers.add(Material.BROWN_MUSHROOM);
fallingEntityKillers.add(Material.RED_MUSHROOM); fallingEntityKillers.add(Material.RED_MUSHROOM);
fallingEntityKillers.addAll(doublePlants); fallingEntityKillers.addAll(doublePlants);
@@ -336,8 +336,8 @@ public class BukkitUtils {
projectileItems.put(EntityType.ARROW, Material.ARROW); projectileItems.put(EntityType.ARROW, Material.ARROW);
projectileItems.put(EntityType.EGG, Material.EGG); projectileItems.put(EntityType.EGG, Material.EGG);
projectileItems.put(EntityType.ENDER_PEARL, Material.ENDER_PEARL); projectileItems.put(EntityType.ENDER_PEARL, Material.ENDER_PEARL);
projectileItems.put(EntityType.SMALL_FIREBALL, Material.FIRE_CHARGE); // Fire charge projectileItems.put(EntityType.SMALL_FIREBALL, Material.FIRE_CHARGE); // Fire charge
projectileItems.put(EntityType.FIREBALL, Material.FIRE_CHARGE); // Fire charge projectileItems.put(EntityType.FIREBALL, Material.FIRE_CHARGE); // Fire charge
projectileItems.put(EntityType.FISHING_HOOK, Material.FISHING_ROD); projectileItems.put(EntityType.FISHING_HOOK, Material.FISHING_ROD);
projectileItems.put(EntityType.SNOWBALL, Material.SNOWBALL); projectileItems.put(EntityType.SNOWBALL, Material.SNOWBALL);
projectileItems.put(EntityType.SPLASH_POTION, Material.SPLASH_POTION); projectileItems.put(EntityType.SPLASH_POTION, Material.SPLASH_POTION);
@@ -429,7 +429,7 @@ public class BukkitUtils {
dyes.put(Material.YELLOW_DYE, DyeColor.YELLOW); dyes.put(Material.YELLOW_DYE, DyeColor.YELLOW);
} }
private static final BlockFace[] relativeBlockFaces = new BlockFace[]{ private static final BlockFace[] relativeBlockFaces = new BlockFace[] {
BlockFace.EAST, BlockFace.WEST, BlockFace.NORTH, BlockFace.SOUTH, BlockFace.UP, BlockFace.DOWN BlockFace.EAST, BlockFace.WEST, BlockFace.NORTH, BlockFace.SOUTH, BlockFace.UP, BlockFace.DOWN
}; };
@@ -556,7 +556,7 @@ public class BukkitUtils {
public static Set<Material> getFallingEntityKillers() { public static Set<Material> getFallingEntityKillers() {
return fallingEntityKillers; return fallingEntityKillers;
} }
public static Set<Material> getNonFluidProofBlocks() { public static Set<Material> getNonFluidProofBlocks() {
return nonFluidProofBlocks; return nonFluidProofBlocks;
} }
@@ -654,7 +654,7 @@ public class BukkitUtils {
public static Material itemIDfromProjectileEntity(Entity e) { public static Material itemIDfromProjectileEntity(Entity e) {
return projectileItems.get(e.getType()); return projectileItems.get(e.getType());
} }
public static boolean isDoublePlant(Material m) { public static boolean isDoublePlant(Material m) {
return doublePlants.contains(m); return doublePlants.contains(m);
} }
@@ -799,7 +799,7 @@ public class BukkitUtils {
if (face.getType() == chestBlock.getType()) { if (face.getType() == chestBlock.getType()) {
// check is the neighbour connects to this chest // check is the neighbour connects to this chest
org.bukkit.block.data.type.Chest otherChestData = (org.bukkit.block.data.type.Chest) face.getBlockData(); org.bukkit.block.data.type.Chest otherChestData = (org.bukkit.block.data.type.Chest) face.getBlockData();
if(otherChestData.getType() != wantedChestType || otherChestData.getFacing() != chestFace) { if (otherChestData.getType() != wantedChestType || otherChestData.getFacing() != chestFace) {
return null; return null;
} }
return face; return face;

View File

@@ -61,22 +61,19 @@ import java.util.Stack;
* @author <a href="mailto:kenney@apache.org">Kenney Westerhof</a> * @author <a href="mailto:kenney@apache.org">Kenney Westerhof</a>
* @author <a href="mailto:hboutemy@apache.org">Hervé Boutemy</a> * @author <a href="mailto:hboutemy@apache.org">Hervé Boutemy</a>
*/ */
public class ComparableVersion public class ComparableVersion implements Comparable<ComparableVersion> {
implements Comparable<ComparableVersion>
{
private String value; private String value;
private String canonical; private String canonical;
private ListItem items; private ListItem items;
private interface Item private interface Item {
{
int INTEGER_ITEM = 0; int INTEGER_ITEM = 0;
int STRING_ITEM = 1; int STRING_ITEM = 1;
int LIST_ITEM = 2; int LIST_ITEM = 2;
int compareTo( Item item ); int compareTo(Item item);
int getType(); int getType();
@@ -86,46 +83,37 @@ public class ComparableVersion
/** /**
* Represents a numeric item in the version item list. * Represents a numeric item in the version item list.
*/ */
private static class IntegerItem private static class IntegerItem implements Item {
implements Item private static final BigInteger BIG_INTEGER_ZERO = new BigInteger("0");
{
private static final BigInteger BIG_INTEGER_ZERO = new BigInteger( "0" );
private final BigInteger value; private final BigInteger value;
public static final IntegerItem ZERO = new IntegerItem(); public static final IntegerItem ZERO = new IntegerItem();
private IntegerItem() private IntegerItem() {
{
this.value = BIG_INTEGER_ZERO; this.value = BIG_INTEGER_ZERO;
} }
public IntegerItem( String str ) public IntegerItem(String str) {
{ this.value = new BigInteger(str);
this.value = new BigInteger( str );
} }
public int getType() public int getType() {
{
return INTEGER_ITEM; return INTEGER_ITEM;
} }
public boolean isNull() public boolean isNull() {
{ return BIG_INTEGER_ZERO.equals(value);
return BIG_INTEGER_ZERO.equals( value );
} }
public int compareTo( Item item ) public int compareTo(Item item) {
{ if (item == null) {
if ( item == null ) return BIG_INTEGER_ZERO.equals(value) ? 0 : 1; // 1.0 == 1, 1.1 > 1
{
return BIG_INTEGER_ZERO.equals( value ) ? 0 : 1; // 1.0 == 1, 1.1 > 1
} }
switch ( item.getType() ) switch (item.getType()) {
{
case INTEGER_ITEM: case INTEGER_ITEM:
return value.compareTo( ( (IntegerItem) item ).value ); return value.compareTo(((IntegerItem) item).value);
case STRING_ITEM: case STRING_ITEM:
return 1; // 1.1 > 1-sp return 1; // 1.1 > 1-sp
@@ -134,12 +122,11 @@ public class ComparableVersion
return 1; // 1.1 > 1-1 return 1; // 1.1 > 1-1
default: default:
throw new RuntimeException( "invalid item: " + item.getClass() ); throw new RuntimeException("invalid item: " + item.getClass());
} }
} }
public String toString() public String toString() {
{
return value.toString(); return value.toString();
} }
} }
@@ -147,36 +134,30 @@ public class ComparableVersion
/** /**
* Represents a string in the version item list, usually a qualifier. * Represents a string in the version item list, usually a qualifier.
*/ */
private static class StringItem private static class StringItem implements Item {
implements Item
{
private static final String[] QUALIFIERS = { "alpha", "beta", "milestone", "rc", "snapshot", "", "sp" }; private static final String[] QUALIFIERS = { "alpha", "beta", "milestone", "rc", "snapshot", "", "sp" };
private static final List<String> _QUALIFIERS = Arrays.asList( QUALIFIERS ); private static final List<String> _QUALIFIERS = Arrays.asList(QUALIFIERS);
private static final Properties ALIASES = new Properties(); private static final Properties ALIASES = new Properties();
static static {
{ ALIASES.put("ga", "");
ALIASES.put( "ga", "" ); ALIASES.put("final", "");
ALIASES.put( "final", "" ); ALIASES.put("cr", "rc");
ALIASES.put( "cr", "rc" );
} }
/** /**
* A comparable value for the empty-string qualifier. This one is used to determine if a given qualifier makes * A comparable value for the empty-string qualifier. This one is used to determine if a given qualifier makes
* the version older than one without a qualifier, or more recent. * the version older than one without a qualifier, or more recent.
*/ */
private static final String RELEASE_VERSION_INDEX = String.valueOf( _QUALIFIERS.indexOf( "" ) ); private static final String RELEASE_VERSION_INDEX = String.valueOf(_QUALIFIERS.indexOf(""));
private String value; private String value;
public StringItem( String value, boolean followedByDigit ) public StringItem(String value, boolean followedByDigit) {
{ if (followedByDigit && value.length() == 1) {
if ( followedByDigit && value.length() == 1 )
{
// a1 = alpha-1, b1 = beta-1, m1 = milestone-1 // a1 = alpha-1, b1 = beta-1, m1 = milestone-1
switch ( value.charAt( 0 ) ) switch (value.charAt(0)) {
{
case 'a': case 'a':
value = "alpha"; value = "alpha";
break; break;
@@ -188,17 +169,15 @@ public class ComparableVersion
break; break;
} }
} }
this.value = ALIASES.getProperty( value , value ); this.value = ALIASES.getProperty(value, value);
} }
public int getType() public int getType() {
{
return STRING_ITEM; return STRING_ITEM;
} }
public boolean isNull() public boolean isNull() {
{ return (comparableQualifier(value).compareTo(RELEASE_VERSION_INDEX) == 0);
return ( comparableQualifier( value ).compareTo( RELEASE_VERSION_INDEX ) == 0 );
} }
/** /**
@@ -213,38 +192,33 @@ public class ComparableVersion
* @param qualifier * @param qualifier
* @return an equivalent value that can be used with lexical comparison * @return an equivalent value that can be used with lexical comparison
*/ */
public static String comparableQualifier( String qualifier ) public static String comparableQualifier(String qualifier) {
{ int i = _QUALIFIERS.indexOf(qualifier);
int i = _QUALIFIERS.indexOf( qualifier );
return i == -1 ? ( _QUALIFIERS.size() + "-" + qualifier ) : String.valueOf( i ); return i == -1 ? (_QUALIFIERS.size() + "-" + qualifier) : String.valueOf(i);
} }
public int compareTo( Item item ) public int compareTo(Item item) {
{ if (item == null) {
if ( item == null )
{
// 1-rc < 1, 1-ga > 1 // 1-rc < 1, 1-ga > 1
return comparableQualifier( value ).compareTo( RELEASE_VERSION_INDEX ); return comparableQualifier(value).compareTo(RELEASE_VERSION_INDEX);
} }
switch ( item.getType() ) switch (item.getType()) {
{
case INTEGER_ITEM: case INTEGER_ITEM:
return -1; // 1.any < 1.1 ? return -1; // 1.any < 1.1 ?
case STRING_ITEM: case STRING_ITEM:
return comparableQualifier( value ).compareTo( comparableQualifier( ( (StringItem) item ).value ) ); return comparableQualifier(value).compareTo(comparableQualifier(((StringItem) item).value));
case LIST_ITEM: case LIST_ITEM:
return -1; // 1.any < 1-1 return -1; // 1.any < 1-1
default: default:
throw new RuntimeException( "invalid item: " + item.getClass() ); throw new RuntimeException("invalid item: " + item.getClass());
} }
} }
public String toString() public String toString() {
{
return value; return value;
} }
} }
@@ -253,51 +227,37 @@ public class ComparableVersion
* Represents a version list item. This class is used both for the global item list and for sub-lists (which start * Represents a version list item. This class is used both for the global item list and for sub-lists (which start
* with '-(number)' in the version specification). * with '-(number)' in the version specification).
*/ */
private static class ListItem private static class ListItem extends ArrayList<Item> implements Item {
extends ArrayList<Item>
implements Item
{
private static final long serialVersionUID = 5914575811857700009L; private static final long serialVersionUID = 5914575811857700009L;
public int getType() public int getType() {
{
return LIST_ITEM; return LIST_ITEM;
} }
public boolean isNull() public boolean isNull() {
{ return (size() == 0);
return ( size() == 0 );
} }
void normalize() void normalize() {
{ for (ListIterator<Item> iterator = listIterator(size()); iterator.hasPrevious();) {
for ( ListIterator<Item> iterator = listIterator( size() ); iterator.hasPrevious(); )
{
Item item = iterator.previous(); Item item = iterator.previous();
if ( item.isNull() ) if (item.isNull()) {
{
iterator.remove(); // remove null trailing items: 0, "", empty list iterator.remove(); // remove null trailing items: 0, "", empty list
} } else {
else
{
break; break;
} }
} }
} }
public int compareTo( Item item ) public int compareTo(Item item) {
{ if (item == null) {
if ( item == null ) if (size() == 0) {
{
if ( size() == 0 )
{
return 0; // 1-0 = 1- (normalize) = 1 return 0; // 1-0 = 1- (normalize) = 1
} }
Item first = get( 0 ); Item first = get(0);
return first.compareTo( null ); return first.compareTo(null);
} }
switch ( item.getType() ) switch (item.getType()) {
{
case INTEGER_ITEM: case INTEGER_ITEM:
return -1; // 1-1 < 1.0.x return -1; // 1-1 < 1.0.x
@@ -306,18 +266,16 @@ public class ComparableVersion
case LIST_ITEM: case LIST_ITEM:
Iterator<Item> left = iterator(); Iterator<Item> left = iterator();
Iterator<Item> right = ( (ListItem) item ).iterator(); Iterator<Item> right = ((ListItem) item).iterator();
while ( left.hasNext() || right.hasNext() ) while (left.hasNext() || right.hasNext()) {
{
Item l = left.hasNext() ? left.next() : null; Item l = left.hasNext() ? left.next() : null;
Item r = right.hasNext() ? right.next() : null; Item r = right.hasNext() ? right.next() : null;
// if this is shorter, then invert the compare and mul with -1 // if this is shorter, then invert the compare and mul with -1
int result = l == null ? ( r == null ? 0 : -1 * r.compareTo( l ) ) : l.compareTo( r ); int result = l == null ? (r == null ? 0 : -1 * r.compareTo(l)) : l.compareTo(r);
if ( result != 0 ) if (result != 0) {
{
return result; return result;
} }
} }
@@ -325,105 +283,82 @@ public class ComparableVersion
return 0; return 0;
default: default:
throw new RuntimeException( "invalid item: " + item.getClass() ); throw new RuntimeException("invalid item: " + item.getClass());
} }
} }
public String toString() public String toString() {
{ StringBuilder buffer = new StringBuilder("(");
StringBuilder buffer = new StringBuilder( "(" ); for (Iterator<Item> iter = iterator(); iter.hasNext();) {
for ( Iterator<Item> iter = iterator(); iter.hasNext(); ) buffer.append(iter.next());
{ if (iter.hasNext()) {
buffer.append( iter.next() ); buffer.append(',');
if ( iter.hasNext() )
{
buffer.append( ',' );
} }
} }
buffer.append( ')' ); buffer.append(')');
return buffer.toString(); return buffer.toString();
} }
} }
public ComparableVersion( String version ) public ComparableVersion(String version) {
{ parseVersion(version);
parseVersion( version );
} }
public final void parseVersion( String version ) public final void parseVersion(String version) {
{
this.value = version; this.value = version;
items = new ListItem(); items = new ListItem();
version = version.toLowerCase( Locale.ENGLISH ); version = version.toLowerCase(Locale.ENGLISH);
ListItem list = items; ListItem list = items;
Stack<Item> stack = new Stack<Item>(); Stack<Item> stack = new Stack<Item>();
stack.push( list ); stack.push(list);
boolean isDigit = false; boolean isDigit = false;
int startIndex = 0; int startIndex = 0;
for ( int i = 0; i < version.length(); i++ ) for (int i = 0; i < version.length(); i++) {
{ char c = version.charAt(i);
char c = version.charAt( i );
if ( c == '.' ) if (c == '.') {
{ if (i == startIndex) {
if ( i == startIndex ) list.add(IntegerItem.ZERO);
{ } else {
list.add( IntegerItem.ZERO ); list.add(parseItem(isDigit, version.substring(startIndex, i)));
}
else
{
list.add( parseItem( isDigit, version.substring( startIndex, i ) ) );
} }
startIndex = i + 1; startIndex = i + 1;
} } else if (c == '-') {
else if ( c == '-' ) if (i == startIndex) {
{ list.add(IntegerItem.ZERO);
if ( i == startIndex ) } else {
{ list.add(parseItem(isDigit, version.substring(startIndex, i)));
list.add( IntegerItem.ZERO );
}
else
{
list.add( parseItem( isDigit, version.substring( startIndex, i ) ) );
} }
startIndex = i + 1; startIndex = i + 1;
if ( isDigit ) if (isDigit) {
{
list.normalize(); // 1.0-* = 1-* list.normalize(); // 1.0-* = 1-*
if ( ( i + 1 < version.length() ) && Character.isDigit( version.charAt( i + 1 ) ) ) if ((i + 1 < version.length()) && Character.isDigit(version.charAt(i + 1))) {
{
// new ListItem only if previous were digits and new char is a digit, // new ListItem only if previous were digits and new char is a digit,
// ie need to differentiate only 1.1 from 1-1 // ie need to differentiate only 1.1 from 1-1
list.add( list = new ListItem() ); list.add(list = new ListItem());
stack.push( list ); stack.push(list);
} }
} }
} } else if (Character.isDigit(c)) {
else if ( Character.isDigit( c ) ) if (!isDigit && i > startIndex) {
{ list.add(new StringItem(version.substring(startIndex, i), true));
if ( !isDigit && i > startIndex )
{
list.add( new StringItem( version.substring( startIndex, i ), true ) );
startIndex = i; startIndex = i;
} }
isDigit = true; isDigit = true;
} } else {
else if (isDigit && i > startIndex) {
{ list.add(parseItem(true, version.substring(startIndex, i)));
if ( isDigit && i > startIndex )
{
list.add( parseItem( true, version.substring( startIndex, i ) ) );
startIndex = i; startIndex = i;
} }
@@ -431,13 +366,11 @@ public class ComparableVersion
} }
} }
if ( version.length() > startIndex ) if (version.length() > startIndex) {
{ list.add(parseItem(isDigit, version.substring(startIndex)));
list.add( parseItem( isDigit, version.substring( startIndex ) ) );
} }
while ( !stack.isEmpty() ) while (!stack.isEmpty()) {
{
list = (ListItem) stack.pop(); list = (ListItem) stack.pop();
list.normalize(); list.normalize();
} }
@@ -445,39 +378,31 @@ public class ComparableVersion
canonical = items.toString(); canonical = items.toString();
} }
private static Item parseItem( boolean isDigit, String buf ) private static Item parseItem(boolean isDigit, String buf) {
{ return isDigit ? new IntegerItem(buf) : new StringItem(buf, false);
return isDigit ? new IntegerItem( buf ) : new StringItem( buf, false );
} }
public int compareTo( ComparableVersion o ) public int compareTo(ComparableVersion o) {
{ return items.compareTo(o.items);
return items.compareTo( o.items );
} }
public int compareTo( String version ) public int compareTo(String version) {
{
return compareTo(new ComparableVersion(version)); return compareTo(new ComparableVersion(version));
} }
public String toString() public String toString() {
{
return value; return value;
} }
public String toCanonicalString() public String toCanonicalString() {
{
return canonical; return canonical;
} }
public boolean equals( Object o ) public boolean equals(Object o) {
{ return (o instanceof ComparableVersion) && canonical.equals(((ComparableVersion) o).canonical);
return ( o instanceof ComparableVersion ) && canonical.equals( ( (ComparableVersion) o ).canonical );
} }
public int hashCode() public int hashCode() {
{
return canonical.hashCode(); return canonical.hashCode();
} }
} }

View File

@@ -20,7 +20,7 @@ import static de.diddiz.LogBlock.config.Config.mb4;
public class LoggingUtil { public class LoggingUtil {
public static void smartLogBlockPlace(Consumer consumer, Actor actor, BlockState replaced, BlockState placed) { public static void smartLogBlockPlace(Consumer consumer, Actor actor, BlockState replaced, BlockState placed) {
Location loc = replaced.getLocation(); Location loc = replaced.getLocation();
if (!placed.getType().hasGravity() || !BukkitUtils.canDirectlyFallIn(replaced.getBlock().getRelative(BlockFace.DOWN).getType())) { if (!placed.getType().hasGravity() || !BukkitUtils.canDirectlyFallIn(replaced.getBlock().getRelative(BlockFace.DOWN).getType())) {
if (BukkitUtils.isEmpty(replaced.getType())) { if (BukkitUtils.isEmpty(replaced.getType())) {
@@ -141,32 +141,32 @@ public class LoggingUtil {
} else { } else {
consumer.queueBlockBreak(actor, checkBlock.getState()); consumer.queueBlockBreak(actor, checkBlock.getState());
} }
} else if(typeAbove == Material.LANTERN) { } else if (typeAbove == Material.LANTERN) {
Lantern lantern = (Lantern) checkBlock.getBlockData(); Lantern lantern = (Lantern) checkBlock.getBlockData();
if(!lantern.isHanging()) { if (!lantern.isHanging()) {
consumer.queueBlockBreak(actor, checkBlock.getState()); consumer.queueBlockBreak(actor, checkBlock.getState());
} }
}else if(typeAbove == Material.BELL) { } else if (typeAbove == Material.BELL) {
Bell bell = (Bell) checkBlock.getBlockData(); Bell bell = (Bell) checkBlock.getBlockData();
if(bell.getAttachment() == Attachment.FLOOR) { if (bell.getAttachment() == Attachment.FLOOR) {
consumer.queueBlockBreak(actor, checkBlock.getState()); consumer.queueBlockBreak(actor, checkBlock.getState());
} }
} }
checkBlock = origin.getRelative(BlockFace.DOWN); checkBlock = origin.getRelative(BlockFace.DOWN);
Material typeBelow = checkBlock.getType(); Material typeBelow = checkBlock.getType();
if(typeBelow == Material.LANTERN) { if (typeBelow == Material.LANTERN) {
Lantern lantern = (Lantern) checkBlock.getBlockData(); Lantern lantern = (Lantern) checkBlock.getBlockData();
if(lantern.isHanging()) { if (lantern.isHanging()) {
consumer.queueBlockBreak(actor, checkBlock.getState()); consumer.queueBlockBreak(actor, checkBlock.getState());
} }
} else if(typeBelow == Material.BELL) { } else if (typeBelow == Material.BELL) {
Bell bell = (Bell) checkBlock.getBlockData(); Bell bell = (Bell) checkBlock.getBlockData();
if(bell.getAttachment() == Attachment.CEILING) { if (bell.getAttachment() == Attachment.CEILING) {
consumer.queueBlockBreak(actor, checkBlock.getState()); consumer.queueBlockBreak(actor, checkBlock.getState());
} }
} }
List<Location> relativeBreakables = BukkitUtils.getBlocksNearby(origin, BukkitUtils.getRelativeBreakables()); List<Location> relativeBreakables = BukkitUtils.getBlocksNearby(origin, BukkitUtils.getRelativeBreakables());
if (relativeBreakables.size() != 0) { if (relativeBreakables.size() != 0) {
for (Location location : relativeBreakables) { for (Location location : relativeBreakables) {

View File

@@ -29,7 +29,7 @@ public class MySQLConnectionPool implements Closeable {
ds.addDataSourceProperty("prepStmtCacheSize", "250"); ds.addDataSourceProperty("prepStmtCacheSize", "250");
ds.addDataSourceProperty("prepStmtCacheSqlLimit", "2048"); ds.addDataSourceProperty("prepStmtCacheSqlLimit", "2048");
ds.addDataSourceProperty("useServerPrepStmts", "true"); ds.addDataSourceProperty("useServerPrepStmts", "true");
ds.addDataSourceProperty("useSSL", "true"); ds.addDataSourceProperty("useSSL", "true");
ds.addDataSourceProperty("requireSSL", Boolean.toString(requireSSL)); ds.addDataSourceProperty("requireSSL", Boolean.toString(requireSSL));
ds.addDataSourceProperty("verifyServerCertificate", "false"); ds.addDataSourceProperty("verifyServerCertificate", "false");

View File

@@ -21,12 +21,12 @@ public class CuboidRegion implements Cloneable {
public CuboidRegion(World world, BlockVector first, BlockVector second) { public CuboidRegion(World world, BlockVector first, BlockVector second) {
this.world = world; this.world = world;
this.min.setX(Math.min(first.getBlockX(),second.getBlockX())); this.min.setX(Math.min(first.getBlockX(), second.getBlockX()));
this.min.setY(Math.min(first.getBlockY(),second.getBlockY())); this.min.setY(Math.min(first.getBlockY(), second.getBlockY()));
this.min.setZ(Math.min(first.getBlockZ(),second.getBlockZ())); this.min.setZ(Math.min(first.getBlockZ(), second.getBlockZ()));
this.max.setX(Math.max(first.getBlockX(),second.getBlockX())); this.max.setX(Math.max(first.getBlockX(), second.getBlockX()));
this.max.setY(Math.max(first.getBlockY(),second.getBlockY())); this.max.setY(Math.max(first.getBlockY(), second.getBlockY()));
this.max.setZ(Math.max(first.getBlockZ(),second.getBlockZ())); this.max.setZ(Math.max(first.getBlockZ(), second.getBlockZ()));
} }
public static CuboidRegion fromPlayerSelection(Player player) { public static CuboidRegion fromPlayerSelection(Player player) {

View File

@@ -1,6 +1,5 @@
package de.diddiz.LogBlock; package de.diddiz.LogBlock;
import de.diddiz.util.Utils; import de.diddiz.util.Utils;
import org.junit.Assert; import org.junit.Assert;
import org.junit.Test; import org.junit.Test;