Skip to content

Commit

Permalink
feat: add access perm
Browse files Browse the repository at this point in the history
  • Loading branch information
devproje committed Feb 9, 2024
1 parent dd76ae1 commit 675871f
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -51,12 +51,13 @@ object InventoryGUI {
*
* @param title The title of the inventory. This is the text shown at the top of the inventory.
* @param slotType The Inventory's Size. Defaults to 27(3 * 9) if not set.
* @param access Allow click player's storage area.
* @param init Initialize the inventory builder. Creates a default inventory if not set.
*
* @return The built inventory
*/
fun Player.gui(title: Component, slotType: InventoryType = InventoryType.CHEST_27, init: SimpleInventoryBuilder.() -> Unit = {}): Inventory {
return SimpleInventoryBuilder(this, slotType, title).apply(init).build()
fun Player.gui(title: Component, slotType: InventoryType = InventoryType.CHEST_27, access: Boolean = true, init: SimpleInventoryBuilder.() -> Unit = {}): Inventory {
return SimpleInventoryBuilder(this, slotType, title, access).apply(init).build()
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,8 @@ import kotlin.collections.HashMap
class SimpleInventoryBuilder(
override val player: Player,
override val slotType: InventoryType,
override val title: Component
override val title: Component,
val access: Boolean
) : Listener, InventoryBuilder {
override val slots = HashMap<Int, Slot>()
val closeHandlers = ArrayList<InventoryCloseEvent.() -> Unit>()
Expand Down Expand Up @@ -68,6 +69,10 @@ class SimpleInventoryBuilder(
if(event.view.title() == this.title) {
if (inventoryIds.contains(id) && event.currentItem != null && event.view.player == player) {
if (event.inventory == inventory) {
if (!access) {
event.isCancelled = true
}

for (slot in slots.entries) {
if (slot.key == event.rawSlot){
event.isCancelled = true
Expand Down
2 changes: 1 addition & 1 deletion build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ plugins {
}

group = "net.projecttl"
version = "4.5.0"
version = "4.5.1"

allprojects {
apply(plugin = "com.github.johnrengelman.shadow")
Expand Down

0 comments on commit 675871f

Please sign in to comment.