From d9bf5a8333c50bf0fb0ccc3cb9f7aa244ce0ff5a Mon Sep 17 00:00:00 2001 From: rand0m0User <79854039+rand0m0User@users.noreply.github.com> Date: Sat, 3 Feb 2024 21:57:55 -0800 Subject: [PATCH 1/2] add API methods to log player inventory items note: 'player' is only ever used for the player's name within the entire code base, consider using plain strings instead. --- .../java/net/coreprotect/CoreProtectAPI.java | 24 +++++++++++++++++++ 1 file changed, 24 insertions(+) diff --git a/src/main/java/net/coreprotect/CoreProtectAPI.java b/src/main/java/net/coreprotect/CoreProtectAPI.java index 464d0bade..eab923748 100755 --- a/src/main/java/net/coreprotect/CoreProtectAPI.java +++ b/src/main/java/net/coreprotect/CoreProtectAPI.java @@ -302,6 +302,30 @@ public boolean logPlacement(String user, Location location, Material type, Block return false; } + public boolean logDropItem(String user, Location location, ItemStack itemStack) { + if (Config.getGlobal().API_ENABLED) { + if (user != null && location != null && itemStack != null) { + if (user.length() > 0) { + PlayerDropItemListener.playerDropItem(location, user, itemStack); + return true; + } + } + } + return false; + } + + public boolean logPickupItem(String user, Location location, ItemStack itemStack) { + if (Config.getGlobal().API_ENABLED) { + if (user != null && location != null && itemStack != null) { + if (user.length() > 0) { + EntityPickupItemListener.onItemPickup(Bukkit.getPlayer(user), location, itemStack); + return true; + } + } + } + return false; + } + @Deprecated public boolean logPlacement(String user, Location location, Material type, byte data) { if (Config.getGlobal().API_ENABLED) { From 7280ab6cfab0cfe938f62eac7ba0c72655cf2ec1 Mon Sep 17 00:00:00 2001 From: rand0m0User <79854039+rand0m0User@users.noreply.github.com> Date: Sat, 3 Feb 2024 22:26:55 -0800 Subject: [PATCH 2/2] Update v9.md unclear if the addition of 2 methods deserves its own API version bump --- docs/api/version/v9.md | 44 +++++++++++++++++++++++++++++++++++++++++- 1 file changed, 43 insertions(+), 1 deletion(-) diff --git a/docs/api/version/v9.md b/docs/api/version/v9.md index a998d9fcd..001a8cacd 100644 --- a/docs/api/version/v9.md +++ b/docs/api/version/v9.md @@ -256,6 +256,26 @@ This will log a block as being removed/broken, and will log the block's inventor --- +#### `logDropItem(String user, Location location, ItemStack itemStack)` + +This will log a item being dropped. + +* **user:** Specify the username to log as having dropped the item. +* **location:** Specify the location of the dropped item you're logging. +* **itemStack:** Specify the ItemStack of the item you're logging. + +--- + +#### `logPickupItem(String user, Location location, ItemStack itemStack)` + +This will log a item being picked up. + +* **user:** Specify the username to log as having picked up the item. +* **location:** Specify the location of the picked up item you're logging. +* **itemStack:** Specify the ItemStack of the item you're logging. + +--- + #### `logContainerTransaction(String user, Location location)` This will log any transactions made to a block's inventory immediately after calling the method. @@ -468,6 +488,28 @@ if (CoreProtect != null){ // Ensure we have access to the API --- +- Log 24 dirt dropped at a location by the user "Notch". +```java +CoreProtectAPI CoreProtect = getCoreProtect(); +if (CoreProtect != null){ // Ensure we have access to the API + Player player = Bukkit.getPlayer("Notch") + api.logDropItem(player.getName() player.getLocation(), new ItemStack(Material.DIRT, 24)); +} +``` + +--- + +- Log 56 seeds picked up at a location by the user "Notch". +```java +CoreProtectAPI CoreProtect = getCoreProtect(); +if (CoreProtect != null){ // Ensure we have access to the API + Player player = Bukkit.getPlayer("Notch") + api.logPickupItem(player.getName() player.getLocation(), new ItemStack(Material.WHEAT_SEEDS, 56)); +} +``` + +--- + - Log adding/remove items in a chest (or some other block inventory). ```java CoreProtectAPI CoreProtect = getCoreProtect(); @@ -501,4 +543,4 @@ Thread thread = new Thread(runnable); thread.start(); ``` ---- \ No newline at end of file +---