Skip to content

Commit

Permalink
Fixed location_to_drop
Browse files Browse the repository at this point in the history
  • Loading branch information
0ft3n committed Dec 24, 2023
1 parent bd7a8d5 commit 1682cc6
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 1 deletion.
Original file line number Diff line number Diff line change
@@ -1,11 +1,13 @@
package com.willfp.libreforge.triggers.event

import com.willfp.eco.util.toSingletonList
import org.bukkit.Location
import org.bukkit.event.Cancellable
import org.bukkit.event.Event
import org.bukkit.event.HandlerList
import org.bukkit.event.block.BlockDropItemEvent
import org.bukkit.event.entity.EntityDeathEvent
import org.bukkit.event.player.PlayerDropItemEvent
import org.bukkit.inventory.ItemStack


Expand Down Expand Up @@ -137,3 +139,36 @@ class EditableBlockDropEvent(
event.isCancelled = p0
}
}

class EditablePlayerDropEvent(
private val event: PlayerDropItemEvent
): EditableDropEvent() {
private val modifiers = mutableListOf<DropModifier>()

override fun addModifier(modifier: DropModifier) {
modifiers += modifier
}

override val originalItems: List<ItemStack>
get() = event.itemDrop.itemStack.toSingletonList()

override val items: List<DropResult>
get() = originalItems.map { modifiers.modify(it) }

override val dropLocation: Location
get() = event.itemDrop.location

override fun removeItem(item: ItemStack) {
if (event.itemDrop.itemStack == item) {
event.itemDrop.remove()
}
}

override fun isCancelled(): Boolean {
return event.isCancelled
}

override fun setCancelled(p0: Boolean) {
event.isCancelled = p0
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import com.willfp.libreforge.toDispatcher
import com.willfp.libreforge.triggers.Trigger
import com.willfp.libreforge.triggers.TriggerData
import com.willfp.libreforge.triggers.TriggerParameter
import com.willfp.libreforge.triggers.event.EditablePlayerDropEvent
import org.bukkit.event.EventHandler
import org.bukkit.event.player.PlayerDropItemEvent

Expand All @@ -25,7 +26,7 @@ object TriggerDropItem : Trigger("drop_item") {
player = player,
item = event.itemDrop.itemStack,
value = event.itemDrop.itemStack.amount.toDouble(),
event = event,
event = EditablePlayerDropEvent(event),
location = event.itemDrop.location
)
)
Expand Down

0 comments on commit 1682cc6

Please sign in to comment.