Implement basic entity change lookup

This commit is contained in:
Brokkonaut
2018-11-08 05:44:21 +01:00
parent 707e0a1eed
commit f9d246dd63
3 changed files with 47 additions and 42 deletions

View File

@ -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

View File

@ -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);
}

View File

@ -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,17 +232,23 @@ public final class QueryParams implements Cloneable {
select += "COUNT(*) AS count ";
} else {
if (needId) {
if (bct != BlockChangeType.ENTITIES) {
select += "`" + getTable() + "-blocks`.id, ";
} else {
select += "`" + getTable() + "-entities`.id, ";
}
}
if (needDate) {
select += "date, ";
}
if (bct != BlockChangeType.ENTITIES) {
if (needType) {
select += "replaced, type, ";
}
if (needData) {
select += "replacedData, typeData, ";
}
}
if (needPlayer) {
select += "playername, UUID, ";
}
@ -250,12 +258,21 @@ public final class QueryParams implements Cloneable {
if (needCoords) {
select += "x, y, z, ";
}
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) + " ";
}
return select;
@ -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) {