forked from LogBlock/LogBlock
Summarization for entities
This commit is contained in:
@ -502,7 +502,7 @@ public class CommandsHandler implements CommandExecutor {
|
||||
if (params.bct == BlockChangeType.KILLS && params.sum == SummarizationMode.PLAYERS) {
|
||||
sender.sendMessage(ChatColor.GOLD + "Kills - Killed - Player");
|
||||
} else {
|
||||
sender.sendMessage(ChatColor.GOLD + "Created - Destroyed - " + (params.sum == SummarizationMode.TYPES ? "Block" : "Player"));
|
||||
sender.sendMessage(ChatColor.GOLD + "Created - Destroyed - " + (params.sum == SummarizationMode.TYPES ? (params.bct == BlockChangeType.ENTITIES ? "Entity" : "Block") : "Player"));
|
||||
}
|
||||
}
|
||||
if (!params.noCache) {
|
||||
|
@ -26,12 +26,11 @@ public class LookupCacheElementFactory {
|
||||
return new SummedKills(rs, params, spaceFactor);
|
||||
}
|
||||
}
|
||||
if (params.bct == BlockChangeType.ENTITIES) {
|
||||
if (params.bct == BlockChangeType.ENTITIES || params.bct == BlockChangeType.ENTITIES_CREATED || params.bct == BlockChangeType.ENTITIES_KILLED) {
|
||||
if (params.sum == SummarizationMode.NONE) {
|
||||
return new EntityChange(rs, params);
|
||||
} else if (params.sum == SummarizationMode.PLAYERS) {
|
||||
throw new IllegalArgumentException();
|
||||
}
|
||||
return new SummedEntityChanges(rs, params, spaceFactor);
|
||||
}
|
||||
if (params.sum == SummarizationMode.NONE) {
|
||||
return new BlockChange(rs, params);
|
||||
|
@ -127,7 +127,7 @@ public final class QueryParams implements Cloneable {
|
||||
}
|
||||
return from;
|
||||
}
|
||||
if (bct == BlockChangeType.ENTITIES) {
|
||||
if (bct == BlockChangeType.ENTITIES || bct == BlockChangeType.ENTITIES_CREATED || bct == BlockChangeType.ENTITIES_KILLED) {
|
||||
String from = "FROM `" + getTable() + "-entities` ";
|
||||
|
||||
if (needPlayer || players.size() > 0) {
|
||||
@ -236,7 +236,7 @@ public final class QueryParams implements Cloneable {
|
||||
select += "COUNT(*) AS count ";
|
||||
} else {
|
||||
if (needId) {
|
||||
if (bct != BlockChangeType.ENTITIES) {
|
||||
if (bct != BlockChangeType.ENTITIES && bct != BlockChangeType.ENTITIES_CREATED && bct != BlockChangeType.ENTITIES_KILLED) {
|
||||
select += "`" + getTable() + "-blocks`.id, ";
|
||||
} else {
|
||||
select += "`" + getTable() + "-entities`.id, ";
|
||||
@ -245,7 +245,7 @@ public final class QueryParams implements Cloneable {
|
||||
if (needDate) {
|
||||
select += "date, ";
|
||||
}
|
||||
if (bct != BlockChangeType.ENTITIES) {
|
||||
if (bct != BlockChangeType.ENTITIES && bct != BlockChangeType.ENTITIES_CREATED && bct != BlockChangeType.ENTITIES_KILLED) {
|
||||
if (needType) {
|
||||
select += "replaced, type, ";
|
||||
}
|
||||
@ -262,7 +262,7 @@ public final class QueryParams implements Cloneable {
|
||||
if (needCoords) {
|
||||
select += "x, y, z, ";
|
||||
}
|
||||
if (bct != BlockChangeType.ENTITIES) {
|
||||
if (bct != BlockChangeType.ENTITIES && bct != BlockChangeType.ENTITIES_CREATED && bct != BlockChangeType.ENTITIES_KILLED) {
|
||||
if (needData) {
|
||||
select += "replacedState, typeState, ";
|
||||
}
|
||||
@ -295,8 +295,12 @@ public final class QueryParams implements Cloneable {
|
||||
}
|
||||
throw new IllegalStateException("Invalid summarization for kills");
|
||||
}
|
||||
if (bct == BlockChangeType.ENTITIES) {
|
||||
throw new IllegalStateException("Not implemented yet");
|
||||
if (bct == BlockChangeType.ENTITIES || bct == BlockChangeType.ENTITIES_CREATED || bct == BlockChangeType.ENTITIES_KILLED) {
|
||||
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();
|
||||
} 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();
|
||||
}
|
||||
}
|
||||
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();
|
||||
@ -317,7 +321,7 @@ public final class QueryParams implements Cloneable {
|
||||
title.append("chat messages ");
|
||||
} else if (bct == BlockChangeType.KILLS) {
|
||||
title.append("kills ");
|
||||
} else if (bct == BlockChangeType.ENTITIES) {
|
||||
} else if (bct == BlockChangeType.ENTITIES || bct == BlockChangeType.ENTITIES_CREATED || bct == BlockChangeType.ENTITIES_KILLED) {
|
||||
if (!entityTypes.isEmpty()) {
|
||||
if (excludeBlocksEntitiesMode) {
|
||||
title.append("all entities except ");
|
||||
@ -395,7 +399,7 @@ public final class QueryParams implements Cloneable {
|
||||
title.append("in ").append(friendlyWorldname(world.getName())).append(" ");
|
||||
}
|
||||
if (sum != SummarizationMode.NONE) {
|
||||
title.append("summed up by ").append(sum == SummarizationMode.TYPES ? "blocks" : "players").append(" ");
|
||||
title.append("summed up by ").append(sum == SummarizationMode.TYPES ? ((bct == BlockChangeType.ENTITIES || bct == BlockChangeType.ENTITIES_CREATED || bct == BlockChangeType.ENTITIES_KILLED) ? "entities" : "blocks") : "players").append(" ");
|
||||
}
|
||||
title.deleteCharAt(title.length() - 1);
|
||||
title.setCharAt(0, String.valueOf(title.charAt(0)).toUpperCase().toCharArray()[0]);
|
||||
@ -468,7 +472,7 @@ public final class QueryParams implements Cloneable {
|
||||
}
|
||||
}
|
||||
}
|
||||
} else if (blockChangeType == BlockChangeType.ENTITIES) {
|
||||
} else if (blockChangeType == BlockChangeType.ENTITIES || blockChangeType == BlockChangeType.ENTITIES_CREATED || blockChangeType == BlockChangeType.ENTITIES_KILLED) {
|
||||
if (!entityTypeIds.isEmpty()) {
|
||||
if (excludeBlocksEntitiesMode) {
|
||||
where.append("NOT ");
|
||||
@ -481,6 +485,11 @@ public final class QueryParams implements Cloneable {
|
||||
where.delete(where.length() - 4, where.length() - 1);
|
||||
where.append(") AND ");
|
||||
}
|
||||
if (blockChangeType == BlockChangeType.ENTITIES_CREATED) {
|
||||
where.append("action = " + EntityChange.EntityChangeType.CREATE.ordinal() + " AND ");
|
||||
} else if (blockChangeType == BlockChangeType.ENTITIES_KILLED) {
|
||||
where.append("action = " + EntityChange.EntityChangeType.KILL.ordinal() + " AND ");
|
||||
}
|
||||
} else {
|
||||
switch (blockChangeType) {
|
||||
case ALL:
|
||||
@ -802,7 +811,7 @@ public final class QueryParams implements Cloneable {
|
||||
}
|
||||
if (values[0].startsWith("p")) {
|
||||
sum = SummarizationMode.PLAYERS;
|
||||
} else if (values[0].startsWith("b")) {
|
||||
} else if (values[0].startsWith("b") || values[0].startsWith("e")) {
|
||||
sum = SummarizationMode.TYPES;
|
||||
} else if (values[0].startsWith("n")) {
|
||||
sum = SummarizationMode.NONE;
|
||||
@ -927,11 +936,6 @@ 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) {
|
||||
@ -1024,7 +1028,7 @@ public final class QueryParams implements Cloneable {
|
||||
}
|
||||
|
||||
public static enum BlockChangeType {
|
||||
ALL, BOTH, CHESTACCESS, CREATED, DESTROYED, CHAT, KILLS, ENTITIES
|
||||
ALL, BOTH, CHESTACCESS, CREATED, DESTROYED, CHAT, KILLS, ENTITIES, ENTITIES_CREATED, ENTITIES_KILLED,
|
||||
}
|
||||
|
||||
public static enum Order {
|
||||
|
35
src/main/java/de/diddiz/LogBlock/SummedEntityChanges.java
Normal file
35
src/main/java/de/diddiz/LogBlock/SummedEntityChanges.java
Normal file
@ -0,0 +1,35 @@
|
||||
package de.diddiz.LogBlock;
|
||||
|
||||
import de.diddiz.LogBlock.QueryParams.SummarizationMode;
|
||||
import org.bukkit.Location;
|
||||
|
||||
import java.sql.ResultSet;
|
||||
import java.sql.SQLException;
|
||||
|
||||
import static de.diddiz.util.Utils.spaces;
|
||||
|
||||
public class SummedEntityChanges implements LookupCacheElement {
|
||||
private final int type;
|
||||
private final int created, destroyed;
|
||||
private final float spaceFactor;
|
||||
private final Actor actor;
|
||||
|
||||
public SummedEntityChanges(ResultSet rs, QueryParams p, float spaceFactor) throws SQLException {
|
||||
// Actor currently useless here as we don't yet output UUID in results anywhere
|
||||
actor = p.sum == SummarizationMode.PLAYERS ? new Actor(rs) : null;
|
||||
type = p.sum == SummarizationMode.TYPES ? rs.getInt("entitytypeid") : 0;
|
||||
created = rs.getInt("created");
|
||||
destroyed = rs.getInt("destroyed");
|
||||
this.spaceFactor = spaceFactor;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Location getLocation() {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getMessage() {
|
||||
return created + spaces((int) ((10 - String.valueOf(created).length()) / spaceFactor)) + destroyed + spaces((int) ((10 - String.valueOf(destroyed).length()) / spaceFactor)) + (actor != null ? actor.getName() : EntityTypeConverter.getEntityType(type).toString());
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user