mirror of
https://github.com/PlayPro/CoreProtect.git
synced 2024-12-28 17:47:41 +01:00
Fixed item frame transactions not logging BlockFace data
This commit is contained in:
parent
c652ce852f
commit
527be90249
@ -123,7 +123,7 @@ public class Bukkit_v1_17 extends Bukkit_v1_16 implements BukkitInterface {
|
||||
if (subMeta.hasItems()) {
|
||||
list = new ArrayList<>();
|
||||
for (ItemStack itemStack : subMeta.getItems()) {
|
||||
Map<String, Object> itemMap = Util.serializeItemStack(itemStack, slot);
|
||||
Map<String, Object> itemMap = Util.serializeItemStack(itemStack, null, slot);
|
||||
if (itemMap.size() > 0) {
|
||||
list.add(itemMap);
|
||||
}
|
||||
|
@ -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;
|
||||
}
|
||||
|
@ -317,7 +317,7 @@ public final class EntityDeathListener extends Queue implements Listener {
|
||||
List<Object> ingredients = new ArrayList<>();
|
||||
List<Object> itemMap = new ArrayList<>();
|
||||
ItemStack item = merchantRecipe.getResult().clone();
|
||||
List<List<Map<String, Object>>> metadata = ItemMetaHandler.seralize(item, item.getType(), 0);
|
||||
List<List<Map<String, Object>>> metadata = ItemMetaHandler.seralize(item, item.getType(), null, 0);
|
||||
item.setItemMeta(null);
|
||||
itemMap.add(item.serialize());
|
||||
itemMap.add(metadata);
|
||||
@ -329,7 +329,7 @@ public final class EntityDeathListener extends Queue implements Listener {
|
||||
for (ItemStack ingredient : merchantRecipe.getIngredients()) {
|
||||
itemMap = new ArrayList<>();
|
||||
item = ingredient.clone();
|
||||
metadata = ItemMetaHandler.seralize(item, item.getType(), 0);
|
||||
metadata = ItemMetaHandler.seralize(item, item.getType(), null, 0);
|
||||
item.setItemMeta(null);
|
||||
itemMap.add(item.serialize());
|
||||
itemMap.add(metadata);
|
||||
|
@ -1220,9 +1220,9 @@ public class Util extends Queue {
|
||||
return newVersion(convertArray(oldVersionSplit), convertArray(currentVersionSplit));
|
||||
}
|
||||
|
||||
public static Map<Integer, Object> serializeItemStackLegacy(ItemStack itemStack, int slot) {
|
||||
public static Map<Integer, Object> serializeItemStackLegacy(ItemStack itemStack, String faceData, int slot) {
|
||||
Map<Integer, Object> result = new HashMap<>();
|
||||
Map<String, Object> itemMap = serializeItemStack(itemStack, slot);
|
||||
Map<String, Object> itemMap = serializeItemStack(itemStack, faceData, slot);
|
||||
if (itemMap.size() > 1) {
|
||||
result.put(0, itemMap.get("0"));
|
||||
result.put(1, itemMap.get("1"));
|
||||
@ -1245,11 +1245,11 @@ public class Util extends Queue {
|
||||
return result;
|
||||
}
|
||||
|
||||
public static Map<String, Object> serializeItemStack(ItemStack itemStack, int slot) {
|
||||
public static Map<String, Object> serializeItemStack(ItemStack itemStack, String faceData, int slot) {
|
||||
Map<String, Object> itemMap = new HashMap<>();
|
||||
if (itemStack != null && !itemStack.getType().equals(Material.AIR)) {
|
||||
ItemStack item = itemStack.clone();
|
||||
List<List<Map<String, Object>>> metadata = ItemMetaHandler.seralize(item, null, slot);
|
||||
List<List<Map<String, Object>>> metadata = ItemMetaHandler.seralize(item, null, faceData, slot);
|
||||
item.setItemMeta(null);
|
||||
itemMap.put("0", item.serialize());
|
||||
itemMap.put("1", metadata);
|
||||
@ -1269,7 +1269,7 @@ public class Util extends Queue {
|
||||
List<List<Map<String, Object>>> metadata = (List<List<Map<String, Object>>>) itemMap.get("1");
|
||||
|
||||
Object[] populatedStack = Rollback.populateItemStack(item, metadata);
|
||||
result = (ItemStack) populatedStack[1];
|
||||
result = (ItemStack) populatedStack[2];
|
||||
}
|
||||
|
||||
return result;
|
||||
@ -1298,7 +1298,7 @@ public class Util extends Queue {
|
||||
ItemStack[] inventory = shulkerBox.getSnapshotInventory().getStorageContents();
|
||||
int slot = 0;
|
||||
for (ItemStack itemStack : inventory) {
|
||||
Map<Integer, Object> itemMap = serializeItemStackLegacy(itemStack, slot);
|
||||
Map<Integer, Object> itemMap = serializeItemStackLegacy(itemStack, null, slot);
|
||||
if (itemMap.size() > 0) {
|
||||
meta.add(itemMap);
|
||||
}
|
||||
|
@ -350,7 +350,7 @@ public class EntityUtil {
|
||||
@SuppressWarnings("unchecked")
|
||||
List<List<Map<String, Object>>> metadata = (List<List<Map<String, Object>>>) itemMap.get(1);
|
||||
Object[] populatedStack = Rollback.populateItemStack(result, metadata);
|
||||
result = (ItemStack) populatedStack[1];
|
||||
result = (ItemStack) populatedStack[2];
|
||||
int uses = (int) recipe.get(1);
|
||||
int maxUses = (int) recipe.get(2);
|
||||
boolean experienceReward = (boolean) recipe.get(3);
|
||||
@ -365,7 +365,7 @@ public class EntityUtil {
|
||||
@SuppressWarnings("unchecked")
|
||||
List<List<Map<String, Object>>> itemMetaData = (List<List<Map<String, Object>>>) ingredientMap.get(1);
|
||||
populatedStack = Rollback.populateItemStack(item, itemMetaData);
|
||||
item = (ItemStack) populatedStack[1];
|
||||
item = (ItemStack) populatedStack[2];
|
||||
merchantIngredients.add(item);
|
||||
}
|
||||
MerchantRecipe merchantRecipe = new MerchantRecipe(result, uses, maxUses, experienceReward);
|
||||
|
@ -109,7 +109,7 @@ public class ItemMetaHandler {
|
||||
return result.toString();
|
||||
}
|
||||
|
||||
public static List<List<Map<String, Object>>> seralize(ItemStack item, Material type, int slot) {
|
||||
public static List<List<Map<String, Object>>> seralize(ItemStack item, Material type, String faceData, int slot) {
|
||||
List<List<Map<String, Object>>> metadata = new ArrayList<>();
|
||||
List<Map<String, Object>> list = new ArrayList<>();
|
||||
List<Object> modifiers = new ArrayList<>();
|
||||
@ -210,7 +210,7 @@ public class ItemMetaHandler {
|
||||
list = new ArrayList<>();
|
||||
|
||||
for (ItemStack chargedProjectile : subMeta.getChargedProjectiles()) {
|
||||
Map<String, Object> itemMap = Util.serializeItemStack(chargedProjectile, slot);
|
||||
Map<String, Object> itemMap = Util.serializeItemStack(chargedProjectile, null, slot);
|
||||
if (itemMap.size() > 0) {
|
||||
list.add(itemMap);
|
||||
}
|
||||
@ -246,6 +246,14 @@ public class ItemMetaHandler {
|
||||
metadata.add(list);
|
||||
}
|
||||
|
||||
if (faceData != null && faceData.length() > 0) {
|
||||
Map<String, Object> meta = new HashMap<>();
|
||||
meta.put("facing", faceData);
|
||||
list = new ArrayList<>();
|
||||
list.add(meta);
|
||||
metadata.add(list);
|
||||
}
|
||||
|
||||
if (modifiers.size() > 0) {
|
||||
Map<String, Object> meta = new HashMap<>();
|
||||
meta.put("modifiers", modifiers);
|
||||
|
Loading…
Reference in New Issue
Block a user