Skip to content

Commit

Permalink
Block player inventory double clicks
Browse files Browse the repository at this point in the history
  • Loading branch information
focamacho committed Dec 26, 2021
1 parent 818fb3e commit f7a428a
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 1 deletion.
2 changes: 1 addition & 1 deletion build.gradle
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
allprojects {
group = 'com.focamacho'
version = '1.0.2'
version = '1.0.3'
}

subprojects {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
import org.bukkit.Material;
import org.bukkit.entity.Player;
import org.bukkit.event.EventHandler;
import org.bukkit.event.inventory.ClickType;
import org.bukkit.event.inventory.InventoryClickEvent;
import org.bukkit.event.inventory.InventoryCloseEvent;
import org.bukkit.event.inventory.InventoryOpenEvent;
Expand Down Expand Up @@ -328,6 +329,9 @@ static class Listener implements org.bukkit.event.Listener {
public void onClick(InventoryClickEvent ce) {
for (ChestMenu chestMenu : chestMenus) {
if(chestMenu.getInventory().equals(ce.getInventory())) {
// Prevent inventory double clicks from stealing items from the menu
if(ce.getClick() == ClickType.DOUBLE_CLICK) ce.setCancelled(true);

int slot = ce.getSlot();
if (slot < 9 * chestMenu.getRows()) {
ce.setCancelled(true);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -195,6 +195,9 @@ public void update() {
.property(InventoryTitle.of(Text.of(this.title)))
.property(InventoryDimension.of(this.rows, 9))
.listener(ClickInventoryEvent.class, ce -> {
// Prevent inventory double clicks from stealing items from the menu
if(ce instanceof ClickInventoryEvent.Double) ce.setCancelled(true);

if(ce.getSlot().isPresent()) {
Integer slot = ce.getSlot().get().getInventoryProperty(SlotIndex.class).get().getValue();
if(slot == null) slot = -1;
Expand Down

0 comments on commit f7a428a

Please sign in to comment.