Fix TNTLeague
This commit is contained in:
@@ -1,60 +0,0 @@
|
||||
/*
|
||||
* This file is a part of the SteamWar software.
|
||||
*
|
||||
* Copyright (C) 2024 SteamWar.de-Serverteam
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Affero General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU Affero General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Affero General Public License
|
||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package de.steamwar.kotlin.inventory
|
||||
|
||||
import org.bukkit.event.inventory.InventoryClickEvent
|
||||
import org.bukkit.event.inventory.InventoryCloseEvent
|
||||
import org.bukkit.inventory.Inventory
|
||||
import org.bukkit.inventory.InventoryHolder
|
||||
import org.bukkit.inventory.ItemStack
|
||||
|
||||
abstract class SWInventoryHolder: InventoryHolder {
|
||||
|
||||
val _inventory: Inventory by lazy { createInventory() }
|
||||
|
||||
private val callbacks = mutableMapOf<Int, (event: InventoryClickEvent) -> Unit>()
|
||||
|
||||
override fun getInventory(): Inventory = _inventory
|
||||
|
||||
abstract fun createInventory(): Inventory
|
||||
|
||||
open fun handleInventoryClick(event: InventoryClickEvent) {
|
||||
callbacks[event.slot]?.invoke(event)
|
||||
}
|
||||
|
||||
fun addItem(item: ItemStack, slot: Int, callback: (event: InventoryClickEvent) -> Unit) {
|
||||
_inventory.setItem(slot, item)
|
||||
addCallback(slot, callback)
|
||||
}
|
||||
|
||||
fun addCallback(slot: Int, callback: (event: InventoryClickEvent) -> Unit) {
|
||||
callbacks[slot] = callback
|
||||
}
|
||||
|
||||
open fun handleClose(event: InventoryCloseEvent) { }
|
||||
|
||||
operator fun set(slot: Int, item: Pair<ItemStack, (event: InventoryClickEvent) -> Unit>) {
|
||||
addItem(item.first, slot, item.second)
|
||||
}
|
||||
|
||||
operator fun set(slot: Int, item: ItemStack) {
|
||||
addItem(item, slot) { }
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user