Fixed item frame transactions not logging BlockFace data
This commit is contained in:
parent
c652ce852f
commit
527be90249
10 changed files with 72 additions and 30 deletions
|
|
@ -1,6 +1,7 @@
|
|||
package net.coreprotect.database;
|
||||
|
||||
import java.sql.Statement;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
|
||||
|
|
@ -8,6 +9,7 @@ import org.bukkit.Bukkit;
|
|||
import org.bukkit.Location;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.block.Block;
|
||||
import org.bukkit.block.BlockFace;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.entity.ArmorStand;
|
||||
import org.bukkit.entity.Entity;
|
||||
|
|
@ -60,6 +62,7 @@ public class ContainerRollback extends Queue {
|
|||
}
|
||||
Object container = null;
|
||||
Material type = block.getType();
|
||||
List<ItemFrame> matchingFrames = new ArrayList<>();
|
||||
|
||||
if (BlockGroup.CONTAINERS.contains(type)) {
|
||||
container = Util.getContainerInventory(block.getState(), false);
|
||||
|
|
@ -74,6 +77,7 @@ public class ContainerRollback extends Queue {
|
|||
else if (entity instanceof ItemFrame) {
|
||||
type = Material.ITEM_FRAME;
|
||||
container = entity;
|
||||
matchingFrames.add((ItemFrame) entity);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -113,12 +117,27 @@ public class ContainerRollback extends Queue {
|
|||
ItemStack itemstack = new ItemStack(rowType, rowAmount, (short) rowData);
|
||||
Object[] populatedStack = Rollback.populateItemStack(itemstack, rowMetadata);
|
||||
int slot = (Integer) populatedStack[0];
|
||||
itemstack = (ItemStack) populatedStack[1];
|
||||
String faceData = (String) populatedStack[1];
|
||||
itemstack = (ItemStack) populatedStack[2];
|
||||
|
||||
if (type == Material.ITEM_FRAME && faceData.length() > 0) {
|
||||
BlockFace blockFace = BlockFace.valueOf(faceData);
|
||||
ItemFrame itemFrame = (ItemFrame) container;
|
||||
if (blockFace != itemFrame.getFacing()) {
|
||||
for (ItemFrame frame : matchingFrames) {
|
||||
if (blockFace == frame.getFacing()) {
|
||||
container = frame;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Rollback.modifyContainerItems(type, container, slot, itemstack, action);
|
||||
}
|
||||
}
|
||||
}
|
||||
matchingFrames.clear();
|
||||
|
||||
ConfigHandler.rollbackHash.put(finalUserString, new int[] { itemCount, modifyCount, entityCount, 1 });
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1010,6 +1010,7 @@ public class Rollback extends Queue {
|
|||
int lastY = 0;
|
||||
int lastZ = 0;
|
||||
int lastWorldId = 0;
|
||||
String lastFace = "";
|
||||
|
||||
for (Object[] row : itemData) {
|
||||
int[] rollbackHashData1 = ConfigHandler.rollbackHash.get(finalUserString);
|
||||
|
|
@ -1028,7 +1029,7 @@ public class Rollback extends Queue {
|
|||
byte[] rowMetadata = (byte[]) row[12];
|
||||
Material rowType = Util.getType(rowTypeRaw);
|
||||
|
||||
if ((rollbackType == 0 && rowRolledBack == 0) || (rollbackType == 1 && rowRolledBack == 1)) {
|
||||
if (rowType != null && ((rollbackType == 0 && rowRolledBack == 0) || (rollbackType == 1 && rowRolledBack == 1))) {
|
||||
if (inventoryRollback) {
|
||||
int rowUserId = (Integer) row[2];
|
||||
String rowUser = ConfigHandler.playerIdCacheReversed.get(rowUserId);
|
||||
|
|
@ -1061,9 +1062,9 @@ public class Rollback extends Queue {
|
|||
ItemStack itemstack = new ItemStack(rowType, rowAmount, (short) rowData);
|
||||
Object[] populatedStack = populateItemStack(itemstack, rowMetadata);
|
||||
if (rowAction == ItemLogger.ITEM_REMOVE_ENDER || rowAction == ItemLogger.ITEM_ADD_ENDER) {
|
||||
modifyContainerItems(containerType, player.getEnderChest(), (Integer) populatedStack[0], ((ItemStack) populatedStack[1]).clone(), action ^ 1);
|
||||
modifyContainerItems(containerType, player.getEnderChest(), (Integer) populatedStack[0], ((ItemStack) populatedStack[2]).clone(), action ^ 1);
|
||||
}
|
||||
modifyContainerItems(containerType, player.getInventory(), (Integer) populatedStack[0], (ItemStack) populatedStack[1], action);
|
||||
modifyContainerItems(containerType, player.getInventory(), (Integer) populatedStack[0], (ItemStack) populatedStack[2], action);
|
||||
|
||||
itemCount1 = itemCount1 + rowAmount;
|
||||
ConfigHandler.rollbackHash.put(finalUserString, new int[] { itemCount1, blockCount1, entityCount1, 0 });
|
||||
|
|
@ -1074,7 +1075,11 @@ public class Rollback extends Queue {
|
|||
continue; // skip inventory & ender chest transactions
|
||||
}
|
||||
|
||||
if (!containerInit || rowX != lastX || rowY != lastY || rowZ != lastZ || rowWorldId != lastWorldId) {
|
||||
ItemStack itemstack = new ItemStack(rowType, rowAmount, (short) rowData);
|
||||
Object[] populatedStack = populateItemStack(itemstack, rowMetadata);
|
||||
String faceData = (String) populatedStack[1];
|
||||
|
||||
if (!containerInit || rowX != lastX || rowY != lastY || rowZ != lastZ || rowWorldId != lastWorldId || !faceData.equals(lastFace)) {
|
||||
container = null; // container patch 2.14.0
|
||||
String world = Util.getWorldName(rowWorldId);
|
||||
if (world.length() == 0) {
|
||||
|
|
@ -1095,6 +1100,7 @@ public class Rollback extends Queue {
|
|||
containerType = block.getType();
|
||||
}
|
||||
else if (BlockGroup.CONTAINERS.contains(Material.ARMOR_STAND) || BlockGroup.CONTAINERS.contains(Material.ITEM_FRAME)) {
|
||||
BlockFace blockFace = BlockFace.valueOf(faceData);
|
||||
for (Entity entity : block.getChunk().getEntities()) {
|
||||
if (entity.getLocation().getBlockX() == rowX && entity.getLocation().getBlockY() == rowY && entity.getLocation().getBlockZ() == rowZ) {
|
||||
if (entity instanceof ArmorStand) {
|
||||
|
|
@ -1104,6 +1110,9 @@ public class Rollback extends Queue {
|
|||
else if (entity instanceof ItemFrame) {
|
||||
container = entity;
|
||||
containerType = Material.ITEM_FRAME;
|
||||
if (blockFace == ((ItemFrame) entity).getFacing()) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -1113,9 +1122,10 @@ public class Rollback extends Queue {
|
|||
lastY = rowY;
|
||||
lastZ = rowZ;
|
||||
lastWorldId = rowWorldId;
|
||||
lastFace = faceData;
|
||||
}
|
||||
|
||||
if (container != null && rowType != null) {
|
||||
if (container != null) {
|
||||
int action = 0;
|
||||
if (rollbackType == 0 && rowAction == 0) {
|
||||
action = 1;
|
||||
|
|
@ -1125,10 +1135,8 @@ public class Rollback extends Queue {
|
|||
action = 1;
|
||||
}
|
||||
|
||||
ItemStack itemstack = new ItemStack(rowType, rowAmount, (short) rowData);
|
||||
Object[] populatedStack = populateItemStack(itemstack, rowMetadata);
|
||||
int slot = (Integer) populatedStack[0];
|
||||
itemstack = (ItemStack) populatedStack[1];
|
||||
itemstack = (ItemStack) populatedStack[2];
|
||||
|
||||
modifyContainerItems(containerType, container, slot, itemstack, action);
|
||||
itemCount1 = itemCount1 + rowAmount;
|
||||
|
|
@ -1652,6 +1660,7 @@ public class Rollback extends Queue {
|
|||
@SuppressWarnings("unchecked")
|
||||
public static Object[] populateItemStack(ItemStack itemstack, Object list) {
|
||||
int slot = 0;
|
||||
String faceData = "";
|
||||
|
||||
try {
|
||||
/*
|
||||
|
|
@ -1682,6 +1691,9 @@ public class Rollback extends Queue {
|
|||
if (mapData.get("slot") != null) {
|
||||
slot = (Integer) mapData.get("slot");
|
||||
}
|
||||
else if (mapData.get("facing") != null) {
|
||||
faceData = (String) mapData.get("facing");
|
||||
}
|
||||
else if (mapData.get("modifiers") != null) {
|
||||
ItemMeta itemMeta = itemstack.getItemMeta();
|
||||
if (itemMeta.hasAttributeModifiers()) {
|
||||
|
|
@ -1798,7 +1810,7 @@ public class Rollback extends Queue {
|
|||
catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
return new Object[] { slot, itemstack };
|
||||
return new Object[] { slot, faceData, itemstack };
|
||||
}
|
||||
|
||||
public static Object[] populateItemStack(ItemStack itemstack, byte[] metadata) {
|
||||
|
|
@ -1817,7 +1829,7 @@ public class Rollback extends Queue {
|
|||
}
|
||||
}
|
||||
|
||||
return new Object[] { 0, itemstack };
|
||||
return new Object[] { 0, "", itemstack };
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -19,7 +19,7 @@ public class ContainerBreakLogger {
|
|||
public static void log(PreparedStatement preparedStmt, int batchCount, String player, Location l, Material type, ItemStack[] oldInventory) {
|
||||
try {
|
||||
Util.mergeItems(type, oldInventory);
|
||||
ContainerLogger.logTransaction(preparedStmt, batchCount, player, type, oldInventory, 0, l);
|
||||
ContainerLogger.logTransaction(preparedStmt, batchCount, player, type, null, oldInventory, 0, l);
|
||||
String loggingContainerId = player.toLowerCase(Locale.ROOT) + "." + l.getBlockX() + "." + l.getBlockY() + "." + l.getBlockZ();
|
||||
|
||||
// If there was a pending chest transaction, it would have already been processed.
|
||||
|
|
|
|||
|
|
@ -32,6 +32,8 @@ public class ContainerLogger extends Queue {
|
|||
public static void log(PreparedStatement preparedStmtContainer, PreparedStatement preparedStmtItems, int batchCount, String player, Material type, Object container, Location location) {
|
||||
try {
|
||||
ItemStack[] contents = null;
|
||||
String faceData = null;
|
||||
|
||||
if (type == Material.ARMOR_STAND) {
|
||||
EntityEquipment equipment = (EntityEquipment) container;
|
||||
if (equipment != null) {
|
||||
|
|
@ -41,6 +43,7 @@ public class ContainerLogger extends Queue {
|
|||
else if (type == Material.ITEM_FRAME) {
|
||||
ItemFrame itemFrame = (ItemFrame) container;
|
||||
contents = Util.getItemFrameItem(itemFrame);
|
||||
faceData = itemFrame.getFacing().name();
|
||||
}
|
||||
else {
|
||||
Inventory inventory = (Inventory) container;
|
||||
|
|
@ -138,8 +141,8 @@ public class ContainerLogger extends Queue {
|
|||
Util.mergeItems(type, newInventory);
|
||||
|
||||
if (type != Material.ENDER_CHEST) {
|
||||
logTransaction(preparedStmtContainer, batchCount, player, type, oldInventory, 0, location);
|
||||
logTransaction(preparedStmtContainer, batchCount, player, type, newInventory, 1, location);
|
||||
logTransaction(preparedStmtContainer, batchCount, player, type, faceData, oldInventory, 0, location);
|
||||
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);
|
||||
|
|
@ -154,7 +157,7 @@ public class ContainerLogger extends Queue {
|
|||
}
|
||||
}
|
||||
|
||||
protected static void logTransaction(PreparedStatement preparedStmt, int batchCount, String user, Material type, ItemStack[] items, int action, Location location) {
|
||||
protected static void logTransaction(PreparedStatement preparedStmt, int batchCount, String user, Material type, String faceData, ItemStack[] items, int action, Location location) {
|
||||
try {
|
||||
if (ConfigHandler.blacklist.get(user.toLowerCase(Locale.ROOT)) != null) {
|
||||
return;
|
||||
|
|
@ -164,7 +167,7 @@ public class ContainerLogger extends Queue {
|
|||
if (item != null) {
|
||||
if (item.getAmount() > 0 && !Util.isAir(item.getType())) {
|
||||
// Object[] metadata = new Object[] { slot, item.getItemMeta() };
|
||||
List<List<Map<String, Object>>> metadata = ItemMetaHandler.seralize(item, type, slot);
|
||||
List<List<Map<String, Object>>> metadata = ItemMetaHandler.seralize(item, type, faceData, slot);
|
||||
if (metadata.size() == 0) {
|
||||
metadata = null;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -63,7 +63,7 @@ public class ItemLogger {
|
|||
for (ItemStack item : items) {
|
||||
if (item != null && item.getAmount() > 0 && !Util.isAir(item.getType())) {
|
||||
// Object[] metadata = new Object[] { slot, item.getItemMeta() };
|
||||
List<List<Map<String, Object>>> data = ItemMetaHandler.seralize(item, null, 0);
|
||||
List<List<Map<String, Object>>> data = ItemMetaHandler.seralize(item, null, null, 0);
|
||||
if (data.size() == 0) {
|
||||
data = null;
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue