Skip to content
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
2 changes: 1 addition & 1 deletion build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ repositories {
}

dependencies {
compile 'org.spigotmc:spigot-api:1.13.2-R0.1-SNAPSHOT'
compile "org.spigotmc:spigot-api:1.20.2-R0.1-SNAPSHOT"
testCompile 'junit:junit:4.12'
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
import org.bukkit.event.Listener;
import org.bukkit.event.block.Action;
import org.bukkit.event.inventory.*;
import org.bukkit.event.player.PlayerDropItemEvent;
import org.bukkit.event.player.PlayerInteractEvent;
import org.bukkit.inventory.Inventory;
import org.bukkit.inventory.ItemStack;
Expand Down Expand Up @@ -77,6 +78,7 @@ && isInShulkerBox(event.getRawSlot())) {
//close inventory if opened shulker box is dropped
if (shulkerBoxSlots.get(player.getUniqueId()).equals(event.getRawSlot())) {
if (isPickupAction(event.getAction())) {
shulkerBoxSlots.put(player.getUniqueId(),-3141); //Move Shulkerbox to impossible slot to avoid bugs :)
shulkerBoxOnCursors.add(player.getUniqueId());
return;
} else if (event.getAction() == InventoryAction.DROP_ALL_SLOT
Expand Down Expand Up @@ -173,8 +175,21 @@ && isShulkerBox(event.getOldCursor().getType())) {
}
}

@EventHandler
public void onItemDrop(PlayerDropItemEvent event){ //Because Pressing Q can dupe items
HumanEntity player;
if (shulkerBoxSlots.containsKey((player = event.getPlayer()).getUniqueId())) {
ItemStack[] items = player.getOpenInventory().getTopInventory().getContents(); //Only called if inv is open
saveShulkerBox(player, items);
player.getWorld().playSound(player.getLocation(), Sound.BLOCK_SHULKER_BOX_CLOSE, .1F, 1.0F);
}
}

private void saveShulkerBox(HumanEntity player, ItemStack[] items) {
ItemStack shulkerbox = player.getInventory().getItem(toSlot(shulkerBoxSlots.get(player.getUniqueId())));
ItemStack shulkerbox = shulkerBoxOnCursors.contains(player.getUniqueId()) //Check if the shulkerbox is on the cursor
? player.getItemOnCursor()
: player.getInventory().getItem(toSlot(shulkerBoxSlots.get(player.getUniqueId())));

if (shulkerbox == null || !isShulkerBox(shulkerbox.getType())) {
return;
}
Expand Down
2 changes: 1 addition & 1 deletion src/main/resources/plugin.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,4 @@ name: OpenShulkerBox
author: Querz
version: @plugin.version@
main: net.querz.openshulkerbox.OpenShulkerBoxPlugin
api-version: 1.13
api-version: 1.20