Skip to content

Commit

Permalink
fix: prevent items from being dropped
Browse files Browse the repository at this point in the history
  • Loading branch information
DebitCardz committed Feb 6, 2024
1 parent c04f3bb commit 8ebfefe
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 8 deletions.
18 changes: 11 additions & 7 deletions src/main/kotlin/me/tech/mcchestui/GUI.kt
Original file line number Diff line number Diff line change
Expand Up @@ -7,16 +7,20 @@

package me.tech.mcchestui

import me.tech.mcchestui.attached.*
import me.tech.mcchestui.item.*
import me.tech.mcchestui.listeners.*
import me.tech.mcchestui.listeners.hotbar.*
import me.tech.mcchestui.listeners.item.*
import me.tech.mcchestui.attached.AttachedInventoryCache
import me.tech.mcchestui.attached.MemoryAttachedInventoryCache
import me.tech.mcchestui.item.GUIItem
import me.tech.mcchestui.listeners.GUICloseListener
import me.tech.mcchestui.listeners.GUISlotClickListener
import me.tech.mcchestui.listeners.hotbar.GUIHotbarListener
import me.tech.mcchestui.listeners.item.GUIItemDragListener
import me.tech.mcchestui.listeners.item.GUIItemPickupListener
import me.tech.mcchestui.listeners.item.GUIItemPlaceListener
import me.tech.mcchestui.utils.*
import net.kyori.adventure.text.Component
import org.bukkit.Material
import org.bukkit.entity.Player
import org.bukkit.event.*
import org.bukkit.event.HandlerList
import org.bukkit.event.Listener
import org.bukkit.inventory.Inventory
import org.bukkit.inventory.ItemStack
import org.bukkit.inventory.PlayerInventory
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package me.tech.mcchestui.listeners
import me.tech.mcchestui.GUI
import org.bukkit.entity.Player
import org.bukkit.event.EventHandler
import org.bukkit.event.inventory.ClickType
import org.bukkit.event.inventory.InventoryClickEvent

internal class GUISlotClickListener(gui: GUI) : GUIEventListener(gui) {
Expand All @@ -16,6 +17,12 @@ internal class GUISlotClickListener(gui: GUI) : GUIEventListener(gui) {
val guiSlot = gui.slots.getOrNull(slot)
?: return // handle cancellation of task in onPlace.

if(click == ClickType.DROP || click == ClickType.CONTROL_DROP) {
if(!guiSlot.allowPickup) {
isCancelled = true
}
}

guiSlot.onClick?.let { uiEvent ->
uiEvent(this, whoClicked as Player)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ package me.tech.mcchestui.listeners.hotbar

import me.tech.mcchestui.GUI
import me.tech.mcchestui.listeners.GUIEventListener
import org.bukkit.Bukkit
import org.bukkit.Material
import org.bukkit.entity.Player
import org.bukkit.event.EventHandler
Expand Down

0 comments on commit 8ebfefe

Please sign in to comment.