Fixed incorrect logging of typed block events (II) (fixes #917)

This commit is contained in:
Intelli committed 2026-07-03 16:37:08 -06:00
1 parent 4c2c304329
commit a0ae242dac
4 files changed
+25 -7

No files matched your search

@@ -18,12 +18,11 @@ class BlockBreakProcess {
if (object instanceof BlockState) {
BlockState block = (BlockState) object;
List<Object> meta = BlockUtils.processMeta(block);
if (block instanceof Skull) {
if (block instanceof Skull && blockType != null && blockType.equals(block.getType())) {
SkullBreakLogger.log(preparedStmt, preparedStmtSkulls, batchCount, user, block);
}
else {
String persistedBlockData = blockData != null ? blockData : block.getBlockData().getAsString();
BlockBreakLogger.log(preparedStmt, batchCount, user, block.getLocation(), MaterialUtils.getBlockId(blockType), blockDataId, meta, persistedBlockData, blockData);
BlockBreakLogger.log(preparedStmt, batchCount, user, block.getLocation(), MaterialUtils.getBlockId(blockType), blockDataId, meta, blockData, blockData);
}
}
}
@@ -18,6 +18,7 @@ import net.coreprotect.event.CoreProtectPreLogEvent;
import net.coreprotect.model.action.LookupActions;
import net.coreprotect.thread.CacheHandler;
import net.coreprotect.utility.BlockTypeUtils;
import net.coreprotect.utility.MaterialUtils;
import net.coreprotect.utility.WorldUtils;
import net.coreprotect.utility.ErrorReporter;
@@ -29,7 +30,7 @@ public class BlockBreakLogger {
public static void log(PreparedStatement preparedStmt, int batchCount, String user, Location location, int type, int data, List<Object> meta, String blockData, String overrideData) {
try {
Material checkType = net.coreprotect.utility.MaterialUtils.getType(type);
Material checkType = MaterialUtils.getType(type);
String blockKey = BlockTypeUtils.getBlockDataKey(blockData);
if (blockKey.length() == 0 && checkType != null) {
blockKey = checkType.getKey().toString();
@@ -37,6 +38,13 @@ public class BlockBreakLogger {
else if (checkType != null && (checkType == Material.PAINTING || BukkitAdapter.ADAPTER.isItemFrame(checkType) || checkType == Material.ARMOR_STAND || checkType == Material.END_CRYSTAL)) {
blockKey = checkType.getKey().toString();
}
if (checkType != null && blockKey.length() > 0) {
Material blockDataType = MaterialUtils.getType(blockKey);
if (blockDataType != null && !blockDataType.equals(checkType)) {
blockKey = checkType.getKey().toString();
blockData = null;
}
}
if (checkType == null && blockKey.length() == 0) {
return;
@@ -54,7 +62,7 @@ public class BlockBreakLogger {
CacheHandler.spreadCache.remove(cacheId);
}
if (checkType == Material.LECTERN) {
if (checkType == Material.LECTERN && blockData != null) {
blockData = blockData.replaceFirst("has_book=true", "has_book=false");
}
else if (checkType != null && (checkType == Material.PAINTING || BukkitAdapter.ADAPTER.isItemFrame(checkType))) {
@@ -79,7 +87,7 @@ public class BlockBreakLogger {
return;
}
int internalType = blockKey.length() > 0 ? net.coreprotect.utility.MaterialUtils.getBlockId(blockKey, true) : type;
int internalType = blockKey.length() > 0 ? MaterialUtils.getBlockId(blockKey, true) : type;
BlockStatement.insert(preparedStmt, batchCount, time, userId, wid, x, y, z, internalType, data, meta, blockData, LookupActions.BLOCK_BREAK, 0);
}
catch (Exception e) {
@@ -28,6 +28,13 @@ public class PlayerInteractLogger {
try {
String blockData = block.getBlockData().getAsString();
String blockKey = BlockTypeUtils.getBlockDataKey(blockData);
if (blockType != null && blockKey.length() > 0) {
Material blockDataType = MaterialUtils.getType(blockKey);
if (BlockTypeUtils.isAir(blockKey) || (blockDataType != null && !blockDataType.equals(blockType))) {
blockKey = blockType.getKey().toString();
blockData = null;
}
}
if (blockKey.length() == 0 && blockType != null) {
blockKey = blockType.getKey().toString();
}
@@ -17,6 +17,7 @@ import org.bukkit.event.player.PlayerInteractEntityEvent;
import org.bukkit.inventory.EquipmentSlot;
import org.bukkit.inventory.ItemStack;
import net.coreprotect.bukkit.BukkitAdapter;
import net.coreprotect.config.Config;
import net.coreprotect.config.ConfigHandler;
import net.coreprotect.consumer.Queue;
@@ -64,7 +65,10 @@ public final class PlayerInteractEntityListener extends Queue implements Listene
}
if (frame.getItem().getType() != Material.AIR && event.getHand().equals(EquipmentSlot.HAND) && Config.getConfig(player.getWorld()).PLAYER_INTERACTIONS) {
Queue.queuePlayerInteraction(player.getName(), entity.getLocation().getBlock().getState(), Material.ITEM_FRAME);
Material frameType = BukkitAdapter.ADAPTER.getFrameType(entity);
if (frameType != null) {
Queue.queuePlayerInteraction(player.getName(), entity.getLocation().getBlock().getState(), frameType);
}
}
if (!Config.getConfig(player.getWorld()).ITEM_TRANSACTIONS) {