-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: PromptSign callback was not called
- Loading branch information
1 parent
c745065
commit 77a1b50
Showing
4 changed files
with
30 additions
and
10 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
14 changes: 14 additions & 0 deletions
14
src/main/java/com/github/mori01231/lifecore/listener/PromptSignListener.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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
23
src/main/java/com/github/mori01231/lifecore/util/PromptSign.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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))) | ||
}) | ||
} | ||
} |