Skip to content

API functionality to log items picked up/dropped #506

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
44 changes: 43 additions & 1 deletion docs/api/version/v9.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -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();
Expand Down Expand Up @@ -501,4 +543,4 @@ Thread thread = new Thread(runnable);
thread.start();
```

---
---
24 changes: 24 additions & 0 deletions src/main/java/net/coreprotect/CoreProtectAPI.java
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down