Added logging and inventory rollback support for thrown/shot items
This commit is contained in:
parent
0d7fa2dd59
commit
b96f47cbac
19 changed files with 271 additions and 105 deletions
|
|
@ -475,12 +475,16 @@ public class Lookup extends Queue {
|
|||
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);
|
||||
}
|
||||
}
|
||||
// If just looking up drops/pickups, include ender chest transactions
|
||||
else if (actionList.contains(11) && !actionList.contains(4)) {
|
||||
if (actionTarget == ItemLogger.ITEM_DROP) {
|
||||
actionText.append(",").append(ItemLogger.ITEM_ADD_ENDER);
|
||||
actionText.append(",").append(ItemLogger.ITEM_THROW);
|
||||
actionText.append(",").append(ItemLogger.ITEM_SHOOT);
|
||||
}
|
||||
if (actionTarget == ItemLogger.ITEM_PICKUP) {
|
||||
actionText.append(",").append(ItemLogger.ITEM_REMOVE_ENDER);
|
||||
|
|
|
|||
|
|
@ -1054,7 +1054,7 @@ public class Rollback extends Queue {
|
|||
}
|
||||
|
||||
int inventoryAction = 0;
|
||||
if (rowAction == ItemLogger.ITEM_DROP || rowAction == ItemLogger.ITEM_PICKUP) {
|
||||
if (rowAction == ItemLogger.ITEM_DROP || rowAction == ItemLogger.ITEM_PICKUP || rowAction == ItemLogger.ITEM_THROW || rowAction == ItemLogger.ITEM_SHOOT) {
|
||||
inventoryAction = (rowAction == ItemLogger.ITEM_PICKUP ? 1 : 0);
|
||||
}
|
||||
else if (rowAction == ItemLogger.ITEM_REMOVE_ENDER || rowAction == ItemLogger.ITEM_ADD_ENDER) {
|
||||
|
|
|
|||
|
|
@ -145,8 +145,8 @@ public class ContainerLogger extends Queue {
|
|||
logTransaction(preparedStmtContainer, batchCount, player, type, faceData, newInventory, 1, location);
|
||||
}
|
||||
else { // pass ender chest transactions to item logger
|
||||
ItemLogger.logTransaction(preparedStmtItems, batchCount, player, location, oldInventory, ItemLogger.ITEM_REMOVE_ENDER);
|
||||
ItemLogger.logTransaction(preparedStmtItems, batchCount, player, location, newInventory, ItemLogger.ITEM_ADD_ENDER);
|
||||
ItemLogger.logTransaction(preparedStmtItems, batchCount, 0, player, location, oldInventory, ItemLogger.ITEM_REMOVE_ENDER);
|
||||
ItemLogger.logTransaction(preparedStmtItems, batchCount, 0, player, location, newInventory, ItemLogger.ITEM_ADD_ENDER);
|
||||
}
|
||||
|
||||
oldList.remove(0);
|
||||
|
|
|
|||
|
|
@ -25,12 +25,14 @@ public class ItemLogger {
|
|||
public static final int ITEM_PICKUP = 3;
|
||||
public static final int ITEM_REMOVE_ENDER = 4;
|
||||
public static final int ITEM_ADD_ENDER = 5;
|
||||
public static final int ITEM_THROW = 6;
|
||||
public static final int ITEM_SHOOT = 7;
|
||||
|
||||
private ItemLogger() {
|
||||
throw new IllegalStateException("Database class");
|
||||
}
|
||||
|
||||
public static void log(PreparedStatement preparedStmt, int batchCount, Location location, String user) {
|
||||
public static void log(PreparedStatement preparedStmt, int batchCount, Location location, int offset, String user) {
|
||||
try {
|
||||
if (ConfigHandler.blacklist.get(user.toLowerCase(Locale.ROOT)) != null) {
|
||||
return;
|
||||
|
|
@ -38,27 +40,41 @@ public class ItemLogger {
|
|||
|
||||
String loggingItemId = user.toLowerCase(Locale.ROOT) + "." + location.getBlockX() + "." + location.getBlockY() + "." + location.getBlockZ();
|
||||
|
||||
List<ItemStack> dropList = ConfigHandler.itemsDrop.getOrDefault(loggingItemId, new ArrayList<>());
|
||||
ItemStack[] itemDrops = new ItemStack[dropList.size()];
|
||||
itemDrops = dropList.toArray(itemDrops);
|
||||
dropList.clear();
|
||||
|
||||
List<ItemStack> pickupList = ConfigHandler.itemsPickup.getOrDefault(loggingItemId, new ArrayList<>());
|
||||
ItemStack[] itemPickups = new ItemStack[pickupList.size()];
|
||||
itemPickups = pickupList.toArray(itemPickups);
|
||||
pickupList.clear();
|
||||
|
||||
Util.mergeItems(null, itemDrops);
|
||||
List<ItemStack> dropList = ConfigHandler.itemsDrop.getOrDefault(loggingItemId, new ArrayList<>());
|
||||
ItemStack[] itemDrops = new ItemStack[dropList.size()];
|
||||
itemDrops = dropList.toArray(itemDrops);
|
||||
dropList.clear();
|
||||
|
||||
List<ItemStack> thrownList = ConfigHandler.itemsThrown.getOrDefault(loggingItemId, new ArrayList<>());
|
||||
ItemStack[] itemThrows = new ItemStack[thrownList.size()];
|
||||
itemThrows = thrownList.toArray(itemThrows);
|
||||
thrownList.clear();
|
||||
|
||||
List<ItemStack> shotList = ConfigHandler.itemsShot.getOrDefault(loggingItemId, new ArrayList<>());
|
||||
ItemStack[] itemShots = new ItemStack[shotList.size()];
|
||||
itemShots = shotList.toArray(itemShots);
|
||||
shotList.clear();
|
||||
|
||||
Util.mergeItems(null, itemPickups);
|
||||
logTransaction(preparedStmt, batchCount, user, location, itemDrops, ITEM_DROP);
|
||||
logTransaction(preparedStmt, batchCount, user, location, itemPickups, ITEM_PICKUP);
|
||||
Util.mergeItems(null, itemDrops);
|
||||
Util.mergeItems(null, itemThrows);
|
||||
Util.mergeItems(null, itemShots);
|
||||
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);
|
||||
}
|
||||
catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
protected static void logTransaction(PreparedStatement preparedStmt, int batchCount, String user, Location location, ItemStack[] items, int action) {
|
||||
protected static void logTransaction(PreparedStatement preparedStmt, int batchCount, int offset, String user, Location location, ItemStack[] items, int action) {
|
||||
try {
|
||||
for (ItemStack item : items) {
|
||||
if (item != null && item.getAmount() > 0 && !Util.isAir(item.getType())) {
|
||||
|
|
@ -73,7 +89,7 @@ public class ItemLogger {
|
|||
|
||||
int userId = UserStatement.getId(preparedStmt, event.getUser(), true);
|
||||
int wid = Util.getWorldId(location.getWorld().getName());
|
||||
int time = (int) (System.currentTimeMillis() / 1000L);
|
||||
int time = (int) (System.currentTimeMillis() / 1000L) - offset;
|
||||
int x = location.getBlockX();
|
||||
int y = location.getBlockY();
|
||||
int z = location.getBlockZ();
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue