Skip to content

Commit

Permalink
feat: handle minecart hopper pull
Browse files Browse the repository at this point in the history
  • Loading branch information
Apehum committed Jan 28, 2025
1 parent 6eed242 commit e86c6aa
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 1 deletion.
3 changes: 2 additions & 1 deletion changelog.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,5 @@
- REPLACE (default) — Replaces the whole lore with a string containing the song name on burn, and removes the lore completely on erase.
- APPEND — Adds a new line to the end of the lore on burn, and removes the last line on erase.
- Fixed clicking with a custom disc into a stopped jukebox with a disc already inside would cause it to play track without actually inserting the disc.
- Fixed an IllegalStateException on ChunkUnloadEvent when using Folia [#92](https://github.com/plasmoapp/pv-addon-discs/issues/92).
- Fixed an IllegalStateException on ChunkUnloadEvent when using Folia [#92](https://github.com/plasmoapp/pv-addon-discs/issues/92).
- Added support for minecart with hopper. Pulling item from jukebox using minecart hopper stops the track.
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import org.bukkit.Location
import org.bukkit.Material
import org.bukkit.block.Block
import org.bukkit.block.Jukebox
import org.bukkit.entity.minecart.HopperMinecart
import org.bukkit.event.EventHandler
import org.bukkit.event.EventPriority
import org.bukkit.event.Listener
Expand Down Expand Up @@ -271,6 +272,19 @@ class JukeboxEventListener : Listener, PluginKoinComponent {

inner class HopperEventListener : Listener {

@EventHandler(priority = EventPriority.MONITOR, ignoreCancelled = true)
fun onMinecartHopperPull(event: InventoryMoveItemEvent) = with(keys) {
if (event.source.type.name != "JUKEBOX") return@with
if (event.destination.holder !is HopperMinecart) return@with

val block = event.source.location?.block ?: return@with

val item = event.item
if (!item.isCustomDisc()) return@with

jobByBlock.remove(block)?.cancel()
}

@EventHandler(priority = EventPriority.MONITOR, ignoreCancelled = true)
fun onHopperInsertToJukebox(event: InventoryMoveItemEvent) = with(keys) {
if (event.destination.type.name != "JUKEBOX") return
Expand Down

0 comments on commit e86c6aa

Please sign in to comment.