Skip to content

Commit

Permalink
fix: PromptSign callback was not called
Browse files Browse the repository at this point in the history
  • Loading branch information
acrylic-style committed Jul 16, 2024
1 parent c745065 commit 77a1b50
Show file tree
Hide file tree
Showing 4 changed files with 30 additions and 10 deletions.
2 changes: 1 addition & 1 deletion build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ plugins {
}

group = "net.azisaba"
version = "6.12.1"
version = "6.12.2"

java {
toolchain.languageVersion.set(JavaLanguageVersion.of(8))
Expand Down
1 change: 1 addition & 0 deletions src/main/java/com/github/mori01231/lifecore/LifeCore.kt
Original file line number Diff line number Diff line change
Expand Up @@ -275,6 +275,7 @@ class LifeCore : JavaPlugin() {
pm.registerEvents(KotlinLoveItemListener(this), this)
pm.registerEvents(CommandListScreen.EventListener(), this)
pm.registerEvents(UpdateInventoryOnCloseListener(this), this)
pm.registerEvents(PromptSignListener, this)

// Items
pm.registerEvents(OreOnlyItemListener(), this)
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
package com.github.mori01231.lifecore.listener

import com.github.mori01231.lifecore.event.AsyncPreSignChangeEvent
import com.github.mori01231.lifecore.util.PromptSign
import org.bukkit.event.EventHandler
import org.bukkit.event.EventPriority
import org.bukkit.event.Listener

object PromptSignListener : Listener {
@EventHandler(priority = EventPriority.MONITOR, ignoreCancelled = true)
fun onSign(e: AsyncPreSignChangeEvent) {
PromptSign.awaitingSign[e.player.uniqueId]?.invoke(e.lines.toList())
}
}
23 changes: 14 additions & 9 deletions src/main/java/com/github/mori01231/lifecore/util/PromptSign.kt
Original file line number Diff line number Diff line change
@@ -1,29 +1,34 @@
package com.github.mori01231.lifecore.util

import com.github.mori01231.lifecore.LifeCore
import net.minecraft.server.v1_15_R1.BlockPosition
import net.minecraft.server.v1_15_R1.CancelledPacketHandleException
import net.minecraft.server.v1_15_R1.PacketPlayOutOpenSignEditor
import org.bukkit.Bukkit
import org.bukkit.Material
import org.bukkit.craftbukkit.v1_15_R1.entity.CraftPlayer
import org.bukkit.entity.Player
import org.bukkit.plugin.java.JavaPlugin
import java.util.*
import java.util.concurrent.ConcurrentHashMap
import java.util.function.Consumer

object PromptSign {

private val awaitingSign = ConcurrentHashMap<UUID, (List<String>) -> Unit>()
internal val awaitingSign = ConcurrentHashMap<UUID, (List<String>) -> Unit>()

@JvmStatic
fun promptSign(player: Player, action: Consumer<List<String>>) {
val loc0 = player.location.clone().apply { y = 0.0 }
val loc0 = player.location.clone().apply { y += 3 }
val origBlockData = loc0.block.blockData
player.sendBlockChange(loc0, Material.AIR.createBlockData())
player.sendBlockChange(loc0, Material.OAK_SIGN.createBlockData())
awaitingSign[player.uniqueId] = {
player.sendBlockChange(loc0, origBlockData)
action.accept(it)
}
(player as CraftPlayer).handle.playerConnection
.sendPacket(PacketPlayOutOpenSignEditor(BlockPosition(loc0.blockX, loc0.blockY, loc0.blockZ)))
Bukkit.getScheduler().runTask(JavaPlugin.getPlugin(LifeCore::class.java), Runnable {
awaitingSign[player.uniqueId] = {
player.sendBlockChange(loc0, origBlockData)
action.accept(it)
}
(player as CraftPlayer).handle.playerConnection
.sendPacket(PacketPlayOutOpenSignEditor(BlockPosition(loc0.blockX, loc0.blockY, loc0.blockZ)))
})
}
}

0 comments on commit 77a1b50

Please sign in to comment.