From f9d246dd63b7f59ab81a0f8d5e12b23d61687e08 Mon Sep 17 00:00:00 2001 From: Brokkonaut Date: Thu, 8 Nov 2018 05:44:21 +0100 Subject: [PATCH] Implement basic entity change lookup --- .../java/de/diddiz/LogBlock/EntityChange.java | 4 +- .../LogBlock/LookupCacheElementFactory.java | 7 ++ .../java/de/diddiz/LogBlock/QueryParams.java | 78 +++++++++---------- 3 files changed, 47 insertions(+), 42 deletions(-) diff --git a/src/main/java/de/diddiz/LogBlock/EntityChange.java b/src/main/java/de/diddiz/LogBlock/EntityChange.java index 878464d..35cf6c3 100644 --- a/src/main/java/de/diddiz/LogBlock/EntityChange.java +++ b/src/main/java/de/diddiz/LogBlock/EntityChange.java @@ -51,9 +51,9 @@ public class EntityChange implements LookupCacheElement { loc = p.needCoords ? new Location(p.world, rs.getInt("x"), rs.getInt("y"), rs.getInt("z")) : null; actor = p.needPlayer ? new Actor(rs) : null; type = p.needType ? EntityTypeConverter.getEntityType(rs.getInt("entitytypeid")) : null; - entityid = p.needType ? UUID.fromString(rs.getString("entityuuid")) : null; + entityid = p.needData ? UUID.fromString(rs.getString("entityuuid")) : null; changeType = p.needType ? EntityChangeType.valueOf(rs.getInt("action")) : null; - data = p.needType ? rs.getBytes("data") : null; + data = p.needData ? rs.getBytes("data") : null; } @Override diff --git a/src/main/java/de/diddiz/LogBlock/LookupCacheElementFactory.java b/src/main/java/de/diddiz/LogBlock/LookupCacheElementFactory.java index 6a1af34..dc97d53 100755 --- a/src/main/java/de/diddiz/LogBlock/LookupCacheElementFactory.java +++ b/src/main/java/de/diddiz/LogBlock/LookupCacheElementFactory.java @@ -26,6 +26,13 @@ public class LookupCacheElementFactory { return new SummedKills(rs, params, spaceFactor); } } + if (params.bct == BlockChangeType.ENTITIES) { + if (params.sum == SummarizationMode.NONE) { + return new EntityChange(rs, params); + } else if (params.sum == SummarizationMode.PLAYERS) { + throw new IllegalArgumentException(); + } + } if (params.sum == SummarizationMode.NONE) { return new BlockChange(rs, params); } diff --git a/src/main/java/de/diddiz/LogBlock/QueryParams.java b/src/main/java/de/diddiz/LogBlock/QueryParams.java index 506dd57..94b87a7 100644 --- a/src/main/java/de/diddiz/LogBlock/QueryParams.java +++ b/src/main/java/de/diddiz/LogBlock/QueryParams.java @@ -53,6 +53,8 @@ public final class QueryParams implements Cloneable { keywords.put("both", 0); keywords.put("force", 0); keywords.put("nocache", 0); + keywords.put("entities", 0); + keywords.put("entity", 0); } public BlockChangeType bct = BlockChangeType.BOTH; public int limit = -1, before = 0, since = 0, radius = -1; @@ -127,7 +129,7 @@ public final class QueryParams implements Cloneable { if (needPlayer || players.size() > 0) { from += "INNER JOIN `lb-players` USING (playerid) "; } - if (!needCount && needType) { + if (!needCount && needData) { from += "LEFT JOIN `" + getTable() + "-entityids` USING (entityid) "; } return from; @@ -230,16 +232,22 @@ public final class QueryParams implements Cloneable { select += "COUNT(*) AS count "; } else { if (needId) { - select += "`" + getTable() + "-blocks`.id, "; + if (bct != BlockChangeType.ENTITIES) { + select += "`" + getTable() + "-blocks`.id, "; + } else { + select += "`" + getTable() + "-entities`.id, "; + } } if (needDate) { select += "date, "; } - if (needType) { - select += "replaced, type, "; - } - if (needData) { - select += "replacedData, typeData, "; + if (bct != BlockChangeType.ENTITIES) { + if (needType) { + select += "replaced, type, "; + } + if (needData) { + select += "replacedData, typeData, "; + } } if (needPlayer) { select += "playername, UUID, "; @@ -250,11 +258,20 @@ public final class QueryParams implements Cloneable { if (needCoords) { select += "x, y, z, "; } - if (needData) { - select += "replacedState, typeState, "; - } - if (needChestAccess) { - select += "item, itemremove, itemtype, "; + if (bct != BlockChangeType.ENTITIES) { + if (needData) { + select += "replacedState, typeState, "; + } + if (needChestAccess) { + select += "item, itemremove, itemtype, "; + } + } else { + if (needType) { + select += "entitytypeid, action, "; + } + if(needData) { + select += "entityuuid, data, "; + } } select = select.substring(0, select.length() - 2) + " "; } @@ -436,32 +453,7 @@ public final class QueryParams implements Cloneable { } } } - - if (loc != null) { - if (radius == 0) { - compileLocationQuery( - where, - loc.getBlockX(), loc.getBlockX(), - loc.getBlockY(), loc.getBlockY(), - loc.getBlockZ(), loc.getBlockZ() - ); - } else if (radius > 0) { - compileLocationQuery( - where, - loc.getBlockX() - radius + 1, loc.getBlockX() + radius - 1, - loc.getBlockY() - radius + 1, loc.getBlockY() + radius - 1, - loc.getBlockZ() - radius + 1, loc.getBlockZ() + radius - 1 - ); - } - - } else if (sel != null) { - compileLocationQuery( - where, - sel.getMinimumPoint().getBlockX(), sel.getMaximumPoint().getBlockX(), - sel.getMinimumPoint().getBlockY(), sel.getMaximumPoint().getBlockY(), - sel.getMinimumPoint().getBlockZ(), sel.getMaximumPoint().getBlockZ() - ); - } + } else if (blockChangeType == BlockChangeType.ENTITIES) { } else { switch (blockChangeType) { @@ -546,6 +538,8 @@ public final class QueryParams implements Cloneable { default: break; } + } + if(blockChangeType != BlockChangeType.CHAT) { if (loc != null) { if (radius == 0) { compileLocationQuery( @@ -571,7 +565,6 @@ public final class QueryParams implements Cloneable { sel.getMinimumPoint().getBlockZ(), sel.getMaximumPoint().getBlockZ() ); } - } if (!players.isEmpty() && sum != SummarizationMode.PLAYERS && blockChangeType != BlockChangeType.KILLS) { if (!excludePlayersMode) { @@ -802,7 +795,7 @@ public final class QueryParams implements Cloneable { bct = BlockChangeType.CHAT; } else if (param.equals("kills")) { bct = BlockChangeType.KILLS; - } else if (param.equals("entities")) { + } else if (param.equals("entities") || param.equals("entity")) { bct = BlockChangeType.ENTITIES; } else if (param.equals("all")) { bct = BlockChangeType.ALL; @@ -893,6 +886,11 @@ public final class QueryParams implements Cloneable { throw new IllegalArgumentException("Invalid summarization for chat"); } } + if(bct == BlockChangeType.ENTITIES) { + if (sum != SummarizationMode.NONE) { + throw new IllegalStateException("Summarization not implemented yet"); + } + } } public void setLocation(Location loc) {