-
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.
- Loading branch information
1 parent
0bbb666
commit 540c800
Showing
4 changed files
with
81 additions
and
1 deletion.
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
36 changes: 36 additions & 0 deletions
36
src/main/java/com/github/mori01231/lifecore/event/AsyncPreSignChangeEvent.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,36 @@ | ||
package com.github.mori01231.lifecore.event | ||
|
||
import net.minecraft.server.v1_15_R1.BlockPosition | ||
import org.bukkit.Location | ||
import org.bukkit.entity.Player | ||
import org.bukkit.event.Cancellable | ||
import org.bukkit.event.Event | ||
import org.bukkit.event.HandlerList | ||
|
||
/** | ||
* Called when a player tries to update a sign. | ||
* @param player The player who tried to update the sign. | ||
* @param pos The position of the sign. | ||
* @param lines The lines of the sign. | ||
*/ | ||
data class AsyncPreSignChangeEvent( | ||
val player: Player, | ||
val pos: Location, | ||
val lines: List<String>, | ||
) : Event(true), Cancellable { | ||
private var cancelled = false | ||
|
||
override fun getHandlers() = handlerList | ||
|
||
companion object { | ||
@JvmStatic | ||
@get:JvmName("getHandlerList") | ||
val handlerList = HandlerList() | ||
} | ||
|
||
override fun isCancelled(): Boolean = cancelled | ||
|
||
override fun setCancelled(cancel: Boolean) { | ||
this.cancelled = cancel | ||
} | ||
} |
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
28 changes: 28 additions & 0 deletions
28
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 |
---|---|---|
@@ -0,0 +1,28 @@ | ||
package com.github.mori01231.lifecore.util | ||
|
||
import net.minecraft.server.v1_15_R1.BlockPosition | ||
import net.minecraft.server.v1_15_R1.PacketPlayOutOpenSignEditor | ||
import org.bukkit.Material | ||
import org.bukkit.craftbukkit.v1_15_R1.entity.CraftPlayer | ||
import org.bukkit.entity.Player | ||
import java.util.* | ||
import java.util.concurrent.ConcurrentHashMap | ||
|
||
object PromptSign { | ||
|
||
private val awaitingSign = ConcurrentHashMap<UUID, (List<String>) -> Unit>() | ||
|
||
@JvmStatic | ||
fun promptSign(player: Player, action: (List<String>) -> Unit) { | ||
val loc0 = player.location.clone().apply { y = 0.0 } | ||
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(it) | ||
} | ||
(player as CraftPlayer).handle.playerConnection | ||
.sendPacket(PacketPlayOutOpenSignEditor(BlockPosition(loc0.blockX, loc0.blockY, loc0.blockZ))) | ||
} | ||
} |