From c652ce852fd088411e48d7de24d067f7c7929491 Mon Sep 17 00:00:00 2001 From: Intelli Date: Thu, 17 Feb 2022 21:10:49 -0700 Subject: [PATCH] Added interaction logging for players clicking item frames --- src/main/java/net/coreprotect/CoreProtectAPI.java | 2 +- src/main/java/net/coreprotect/consumer/Queue.java | 4 ++-- .../consumer/process/PlayerInteractionProcess.java | 5 +++-- src/main/java/net/coreprotect/consumer/process/Process.java | 2 +- .../coreprotect/database/logger/PlayerInteractLogger.java | 4 ++-- .../listener/player/PlayerInteractEntityListener.java | 4 ++++ .../coreprotect/listener/player/PlayerInteractListener.java | 2 +- 7 files changed, 14 insertions(+), 9 deletions(-) diff --git a/src/main/java/net/coreprotect/CoreProtectAPI.java b/src/main/java/net/coreprotect/CoreProtectAPI.java index 4d86f65..ddf087d 100755 --- a/src/main/java/net/coreprotect/CoreProtectAPI.java +++ b/src/main/java/net/coreprotect/CoreProtectAPI.java @@ -264,7 +264,7 @@ public class CoreProtectAPI extends Queue { if (Config.getGlobal().API_ENABLED) { if (user != null && location != null) { if (user.length() > 0) { - Queue.queuePlayerInteraction(user, location.getBlock().getState()); + Queue.queuePlayerInteraction(user, location.getBlock().getState(), location.getBlock().getType()); return true; } } diff --git a/src/main/java/net/coreprotect/consumer/Queue.java b/src/main/java/net/coreprotect/consumer/Queue.java index b1bf21f..64386a8 100755 --- a/src/main/java/net/coreprotect/consumer/Queue.java +++ b/src/main/java/net/coreprotect/consumer/Queue.java @@ -296,10 +296,10 @@ public class Queue { queueStandardData(consumerId, currentConsumer, new String[] { player.getName(), null }, new Object[] { timestamp, player.getLocation().clone() }); } - protected static void queuePlayerInteraction(String user, BlockState block) { + protected static void queuePlayerInteraction(String user, BlockState block, Material type) { int currentConsumer = Consumer.currentConsumer; int consumerId = Consumer.newConsumerId(currentConsumer); - addConsumer(currentConsumer, new Object[] { consumerId, Process.PLAYER_INTERACTION, null, 0, null, 0, 0, null }); + addConsumer(currentConsumer, new Object[] { consumerId, Process.PLAYER_INTERACTION, type, 0, null, 0, 0, null }); queueStandardData(consumerId, currentConsumer, new String[] { user, null }, block); } diff --git a/src/main/java/net/coreprotect/consumer/process/PlayerInteractionProcess.java b/src/main/java/net/coreprotect/consumer/process/PlayerInteractionProcess.java index 3de960e..ed6a923 100644 --- a/src/main/java/net/coreprotect/consumer/process/PlayerInteractionProcess.java +++ b/src/main/java/net/coreprotect/consumer/process/PlayerInteractionProcess.java @@ -2,16 +2,17 @@ package net.coreprotect.consumer.process; import java.sql.PreparedStatement; +import org.bukkit.Material; import org.bukkit.block.BlockState; import net.coreprotect.database.logger.PlayerInteractLogger; class PlayerInteractionProcess { - static void process(PreparedStatement preparedStmt, int batchCount, String user, Object object) { + static void process(PreparedStatement preparedStmt, int batchCount, String user, Object object, Material type) { if (object instanceof BlockState) { BlockState block = (BlockState) object; - PlayerInteractLogger.log(preparedStmt, batchCount, user, block); + PlayerInteractLogger.log(preparedStmt, batchCount, user, block, type); } } } diff --git a/src/main/java/net/coreprotect/consumer/process/Process.java b/src/main/java/net/coreprotect/consumer/process/Process.java index 23cd110..44f29f3 100755 --- a/src/main/java/net/coreprotect/consumer/process/Process.java +++ b/src/main/java/net/coreprotect/consumer/process/Process.java @@ -143,7 +143,7 @@ public class Process { ContainerBreakProcess.process(preparedStmtContainers, i, processId, id, blockType, user, object); break; case Process.PLAYER_INTERACTION: - PlayerInteractionProcess.process(preparedStmtBlocks, i, user, object); + PlayerInteractionProcess.process(preparedStmtBlocks, i, user, object, blockType); break; case Process.CONTAINER_TRANSACTION: ContainerTransactionProcess.process(preparedStmtContainers, preparedStmtItems, i, processId, id, blockType, forceData, user, object); diff --git a/src/main/java/net/coreprotect/database/logger/PlayerInteractLogger.java b/src/main/java/net/coreprotect/database/logger/PlayerInteractLogger.java index ba5a144..84819b4 100644 --- a/src/main/java/net/coreprotect/database/logger/PlayerInteractLogger.java +++ b/src/main/java/net/coreprotect/database/logger/PlayerInteractLogger.java @@ -19,9 +19,9 @@ public class PlayerInteractLogger { throw new IllegalStateException("Database class"); } - public static void log(PreparedStatement preparedStmt, int batchCount, String user, BlockState block) { + public static void log(PreparedStatement preparedStmt, int batchCount, String user, BlockState block, Material blockType) { try { - int type = Util.getBlockId(block.getType().name(), true); + int type = Util.getBlockId(blockType.name(), true); if (ConfigHandler.blacklist.get(user.toLowerCase(Locale.ROOT)) != null || Util.getType(type).equals(Material.AIR) || Util.getType(type).equals(Material.CAVE_AIR)) { return; } diff --git a/src/main/java/net/coreprotect/listener/player/PlayerInteractEntityListener.java b/src/main/java/net/coreprotect/listener/player/PlayerInteractEntityListener.java index 5eb4188..cb4fedd 100644 --- a/src/main/java/net/coreprotect/listener/player/PlayerInteractEntityListener.java +++ b/src/main/java/net/coreprotect/listener/player/PlayerInteractEntityListener.java @@ -62,6 +62,10 @@ public final class PlayerInteractEntityListener extends Queue implements Listene return; } + 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); + } + if (!Config.getConfig(player.getWorld()).ITEM_TRANSACTIONS) { return; } diff --git a/src/main/java/net/coreprotect/listener/player/PlayerInteractListener.java b/src/main/java/net/coreprotect/listener/player/PlayerInteractListener.java index 006bfd7..6b3f4ab 100755 --- a/src/main/java/net/coreprotect/listener/player/PlayerInteractListener.java +++ b/src/main/java/net/coreprotect/listener/player/PlayerInteractListener.java @@ -587,7 +587,7 @@ public final class PlayerInteractListener extends Queue implements Listener { } } - Queue.queuePlayerInteraction(player.getName(), interactBlock.getState()); + Queue.queuePlayerInteraction(player.getName(), interactBlock.getState(), type); } } else if (BlockGroup.LIGHTABLES.contains(type)) { // extinguishing a lit block such as a campfire