Added logging and rollback support for players crafting items
This commit is contained in:
parent
30c1921968
commit
5494bce0fc
8 changed files with 195 additions and 5 deletions
|
|
@ -304,6 +304,7 @@ public class Lookup extends Queue {
|
|||
String queryLimit = "";
|
||||
String queryTable = "block";
|
||||
String action = "";
|
||||
String actionExclude = "";
|
||||
String includeBlock = "";
|
||||
String includeEntity = "";
|
||||
String excludeBlock = "";
|
||||
|
|
@ -445,6 +446,15 @@ public class Lookup extends Queue {
|
|||
excludeUsers = excludeUserText.toString();
|
||||
}
|
||||
|
||||
// Specify actions to exclude from a:item
|
||||
if ((lookup && actionList.size() == 0) || (actionList.contains(11) && actionList.size() == 1)) {
|
||||
StringBuilder actionText = new StringBuilder();
|
||||
actionText = actionText.append(ItemLogger.ITEM_BREAK);
|
||||
actionText.append(",").append(ItemLogger.ITEM_DESTROY);
|
||||
actionText.append(",").append(ItemLogger.ITEM_CREATE);
|
||||
actionExclude = actionText.toString();
|
||||
}
|
||||
|
||||
if (!actionList.isEmpty()) {
|
||||
StringBuilder actionText = new StringBuilder();
|
||||
for (Integer actionTarget : actionList) {
|
||||
|
|
@ -471,12 +481,15 @@ public class Lookup extends Queue {
|
|||
if (actionTarget == ItemLogger.ITEM_REMOVE) {
|
||||
actionText.append(",").append(ItemLogger.ITEM_PICKUP);
|
||||
actionText.append(",").append(ItemLogger.ITEM_REMOVE_ENDER);
|
||||
actionText.append(",").append(ItemLogger.ITEM_CREATE);
|
||||
}
|
||||
if (actionTarget == ItemLogger.ITEM_ADD) {
|
||||
actionText.append(",").append(ItemLogger.ITEM_DROP);
|
||||
actionText.append(",").append(ItemLogger.ITEM_ADD_ENDER);
|
||||
actionText.append(",").append(ItemLogger.ITEM_THROW);
|
||||
actionText.append(",").append(ItemLogger.ITEM_SHOOT);
|
||||
actionText.append(",").append(ItemLogger.ITEM_BREAK);
|
||||
actionText.append(",").append(ItemLogger.ITEM_DESTROY);
|
||||
}
|
||||
}
|
||||
// If just looking up drops/pickups, include ender chest transactions
|
||||
|
|
@ -535,7 +548,7 @@ public class Lookup extends Queue {
|
|||
if (validAction) {
|
||||
queryBlock = queryBlock + " action IN(" + action + ") AND";
|
||||
}
|
||||
else if (inventoryQuery || includeBlock.length() > 0 || includeEntity.length() > 0 || excludeBlock.length() > 0 || excludeEntity.length() > 0) {
|
||||
else if (inventoryQuery || actionExclude.length() > 0 || includeBlock.length() > 0 || includeEntity.length() > 0 || excludeBlock.length() > 0 || excludeEntity.length() > 0) {
|
||||
queryBlock = queryBlock + " action NOT IN(-1) AND";
|
||||
}
|
||||
|
||||
|
|
@ -708,10 +721,19 @@ public class Lookup extends Queue {
|
|||
rows = "rowid as id,time,user,wid,x,y,z,type,data as metadata,0 as data,amount,action,rolled_back";
|
||||
queryOrder = " ORDER BY time DESC, tbl DESC, id DESC";
|
||||
}
|
||||
|
||||
if (actionExclude.length() > 0) {
|
||||
queryBlock = queryBlock.replace("action NOT IN(-1)", "action NOT IN(" + actionExclude + ")");
|
||||
}
|
||||
|
||||
query = query + unionSelect + "SELECT " + "'2' as tbl," + rows + " FROM " + ConfigHandler.prefix + "item WHERE" + queryBlock + unionLimit + ")";
|
||||
}
|
||||
|
||||
if (query.length() == 0) {
|
||||
if (actionExclude.length() > 0) {
|
||||
baseQuery = baseQuery.replace("action NOT IN(-1)", "action NOT IN(" + actionExclude + ")");
|
||||
}
|
||||
|
||||
query = "SELECT " + "'0' as tbl," + rows + " FROM " + ConfigHandler.prefix + queryTable + " " + index + "WHERE" + baseQuery;
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -1071,8 +1071,8 @@ public class Rollback extends Queue {
|
|||
}
|
||||
|
||||
int inventoryAction = 0;
|
||||
if (rowAction == ItemLogger.ITEM_DROP || rowAction == ItemLogger.ITEM_PICKUP || rowAction == ItemLogger.ITEM_THROW || rowAction == ItemLogger.ITEM_SHOOT) {
|
||||
inventoryAction = (rowAction == ItemLogger.ITEM_PICKUP ? 1 : 0);
|
||||
if (rowAction == ItemLogger.ITEM_DROP || rowAction == ItemLogger.ITEM_PICKUP || rowAction == ItemLogger.ITEM_THROW || rowAction == ItemLogger.ITEM_SHOOT || rowAction == ItemLogger.ITEM_BREAK || rowAction == ItemLogger.ITEM_DESTROY || rowAction == ItemLogger.ITEM_CREATE) {
|
||||
inventoryAction = ((rowAction == ItemLogger.ITEM_PICKUP || rowAction == ItemLogger.ITEM_CREATE) ? 1 : 0);
|
||||
}
|
||||
else if (rowAction == ItemLogger.ITEM_REMOVE_ENDER || rowAction == ItemLogger.ITEM_ADD_ENDER) {
|
||||
inventoryAction = (rowAction == ItemLogger.ITEM_REMOVE_ENDER ? 1 : 0);
|
||||
|
|
|
|||
|
|
@ -27,6 +27,9 @@ public class ItemLogger {
|
|||
public static final int ITEM_ADD_ENDER = 5;
|
||||
public static final int ITEM_THROW = 6;
|
||||
public static final int ITEM_SHOOT = 7;
|
||||
public static final int ITEM_BREAK = 8;
|
||||
public static final int ITEM_DESTROY = 9;
|
||||
public static final int ITEM_CREATE = 10;
|
||||
|
||||
private ItemLogger() {
|
||||
throw new IllegalStateException("Database class");
|
||||
|
|
@ -60,14 +63,35 @@ public class ItemLogger {
|
|||
itemShots = shotList.toArray(itemShots);
|
||||
shotList.clear();
|
||||
|
||||
List<ItemStack> breakList = ConfigHandler.itemsBreak.getOrDefault(loggingItemId, new ArrayList<>());
|
||||
ItemStack[] itemBreaks = new ItemStack[breakList.size()];
|
||||
itemBreaks = breakList.toArray(itemBreaks);
|
||||
breakList.clear();
|
||||
|
||||
List<ItemStack> destroyList = ConfigHandler.itemsDestroy.getOrDefault(loggingItemId, new ArrayList<>());
|
||||
ItemStack[] itemDestroys = new ItemStack[destroyList.size()];
|
||||
itemDestroys = destroyList.toArray(itemDestroys);
|
||||
destroyList.clear();
|
||||
|
||||
List<ItemStack> createList = ConfigHandler.itemsCreate.getOrDefault(loggingItemId, new ArrayList<>());
|
||||
ItemStack[] itemCreates = new ItemStack[createList.size()];
|
||||
itemCreates = createList.toArray(itemCreates);
|
||||
createList.clear();
|
||||
|
||||
Util.mergeItems(null, itemPickups);
|
||||
Util.mergeItems(null, itemDrops);
|
||||
Util.mergeItems(null, itemThrows);
|
||||
Util.mergeItems(null, itemShots);
|
||||
Util.mergeItems(null, itemBreaks);
|
||||
Util.mergeItems(null, itemDestroys);
|
||||
Util.mergeItems(null, itemCreates);
|
||||
logTransaction(preparedStmt, batchCount, offset, user, location, itemPickups, ITEM_PICKUP);
|
||||
logTransaction(preparedStmt, batchCount, offset, user, location, itemDrops, ITEM_DROP);
|
||||
logTransaction(preparedStmt, batchCount, offset, user, location, itemThrows, ITEM_THROW);
|
||||
logTransaction(preparedStmt, batchCount, offset, user, location, itemShots, ITEM_SHOOT);
|
||||
logTransaction(preparedStmt, batchCount, offset, user, location, itemBreaks, ITEM_BREAK);
|
||||
logTransaction(preparedStmt, batchCount, offset, user, location, itemDestroys, ITEM_DESTROY);
|
||||
logTransaction(preparedStmt, batchCount, offset, user, location, itemCreates, ITEM_CREATE);
|
||||
}
|
||||
catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue