mirror of
https://github.com/Artillex-Studios/AxMinions.git
synced 2024-11-28 12:35:38 +01:00
Merge pull request #22 from oguzcanyilmazlar/miniontoolevent-item-mutable
Mutable Items through MinionToolEvent
This commit is contained in:
commit
3f85df77e5
@ -7,7 +7,7 @@ import org.bukkit.event.Event
|
||||
import org.bukkit.event.HandlerList
|
||||
import org.bukkit.inventory.ItemStack
|
||||
|
||||
class MinionToolEvent(minion: Minion, private val player: Player, private val newTool: ItemStack) : MinionEvent(minion), Cancellable {
|
||||
class MinionToolEvent(minion: Minion, private val player: Player, var newTool: ItemStack, var oldTool: ItemStack) : MinionEvent(minion), Cancellable {
|
||||
companion object {
|
||||
private val handlerList = HandlerList()
|
||||
|
||||
@ -29,10 +29,6 @@ class MinionToolEvent(minion: Minion, private val player: Player, private val ne
|
||||
return player
|
||||
}
|
||||
|
||||
fun getNewTool(): ItemStack {
|
||||
return newTool
|
||||
}
|
||||
|
||||
override fun setCancelled(cancelled: Boolean) {
|
||||
isCancelled = cancelled
|
||||
}
|
||||
|
@ -69,19 +69,20 @@ class MinionInventoryListener : Listener {
|
||||
player.sendMessage(StringUtils.formatToString(Messages.PREFIX() + Messages.WRONG_TOOL()))
|
||||
return
|
||||
}
|
||||
val minionToolEvent = MinionToolEvent(minion, player, event.currentItem!!)
|
||||
|
||||
val minionToolEvent = MinionToolEvent(minion, player, event.currentItem!!.clone(), minion.getTool()!!.clone())
|
||||
Bukkit.getPluginManager().callEvent(minionToolEvent)
|
||||
if (minionToolEvent.isCancelled) return
|
||||
|
||||
if (minion.getTool()?.type != Material.AIR) {
|
||||
val current = event.currentItem!!.clone()
|
||||
val tool = minion.getTool()?.clone()
|
||||
val current = minionToolEvent.newTool
|
||||
val tool = minionToolEvent.oldTool
|
||||
minion.setTool(current)
|
||||
minion.updateArmour()
|
||||
event.currentItem!!.amount = 0
|
||||
event.clickedInventory!!.addItem(tool)
|
||||
} else {
|
||||
minion.setTool(event.currentItem!!)
|
||||
minion.setTool(minionToolEvent.newTool)
|
||||
event.currentItem!!.amount = 0
|
||||
}
|
||||
|
||||
@ -95,18 +96,19 @@ class MinionInventoryListener : Listener {
|
||||
player.sendMessage(StringUtils.formatToString(Messages.PREFIX() + Messages.ERROR_INVENTORY_FULL()))
|
||||
return
|
||||
}
|
||||
val minionToolEvent = MinionToolEvent(minion, player, ItemStack(Material.AIR))
|
||||
val tool = minion.getTool()?.clone() ?: return
|
||||
|
||||
val minionToolEvent = MinionToolEvent(minion, player, ItemStack(Material.AIR), tool)
|
||||
Bukkit.getPluginManager().callEvent(minionToolEvent)
|
||||
if (minionToolEvent.isCancelled) return
|
||||
|
||||
val tool = minion.getTool()?.clone() ?: return
|
||||
minion.setTool(ItemStack(Material.AIR))
|
||||
minion.updateArmour()
|
||||
val toolMeta = tool.itemMeta ?: return
|
||||
val toolMeta = minionToolEvent.oldTool.itemMeta ?: return
|
||||
toolMeta.persistentDataContainer.remove(Keys.GUI)
|
||||
tool.setItemMeta(toolMeta)
|
||||
minionToolEvent.oldTool.setItemMeta(toolMeta)
|
||||
|
||||
player.inventory.addItem(tool)
|
||||
player.inventory.addItem(minionToolEvent.oldTool)
|
||||
minion.updateInventories()
|
||||
return
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user