feat: エディットセッションを削除
This commit is contained in:
parent
b3bdc95f63
commit
f3ea947310
|
|
@ -3,7 +3,6 @@ package net.hareworks.ghostdisplays
|
||||||
import net.hareworks.ghostdisplays.api.DisplayService
|
import net.hareworks.ghostdisplays.api.DisplayService
|
||||||
import net.hareworks.ghostdisplays.command.CommandRegistrar
|
import net.hareworks.ghostdisplays.command.CommandRegistrar
|
||||||
import net.hareworks.ghostdisplays.display.DisplayManager
|
import net.hareworks.ghostdisplays.display.DisplayManager
|
||||||
import net.hareworks.ghostdisplays.display.EditSessionManager
|
|
||||||
import net.hareworks.ghostdisplays.internal.DefaultDisplayService
|
import net.hareworks.ghostdisplays.internal.DefaultDisplayService
|
||||||
import net.hareworks.ghostdisplays.internal.controller.DisplayRegistry
|
import net.hareworks.ghostdisplays.internal.controller.DisplayRegistry
|
||||||
import net.hareworks.kommand_lib.KommandLib
|
import net.hareworks.kommand_lib.KommandLib
|
||||||
|
|
@ -17,7 +16,6 @@ class GhostDisplaysPlugin : JavaPlugin() {
|
||||||
private lateinit var displayRegistry: DisplayRegistry
|
private lateinit var displayRegistry: DisplayRegistry
|
||||||
private lateinit var serviceImpl: DisplayService
|
private lateinit var serviceImpl: DisplayService
|
||||||
private lateinit var displayManager: DisplayManager
|
private lateinit var displayManager: DisplayManager
|
||||||
private lateinit var editSessions: EditSessionManager
|
|
||||||
private lateinit var miniMessage: MiniMessage
|
private lateinit var miniMessage: MiniMessage
|
||||||
private var permissionSession: MutationSession? = null
|
private var permissionSession: MutationSession? = null
|
||||||
private var kommand: KommandLib? = null
|
private var kommand: KommandLib? = null
|
||||||
|
|
@ -29,13 +27,10 @@ class GhostDisplaysPlugin : JavaPlugin() {
|
||||||
}
|
}
|
||||||
serviceImpl = DefaultDisplayService(this, displayRegistry)
|
serviceImpl = DefaultDisplayService(this, displayRegistry)
|
||||||
displayManager = DisplayManager(this, serviceImpl, miniMessage)
|
displayManager = DisplayManager(this, serviceImpl, miniMessage)
|
||||||
editSessions = EditSessionManager(this, displayManager).also {
|
|
||||||
server.pluginManager.registerEvents(it, this)
|
|
||||||
}
|
|
||||||
|
|
||||||
server.servicesManager.register(DisplayService::class.java, serviceImpl, this, ServicePriority.Normal)
|
server.servicesManager.register(DisplayService::class.java, serviceImpl, this, ServicePriority.Normal)
|
||||||
permissionSession = PermitsLib.session(this)
|
permissionSession = PermitsLib.session(this)
|
||||||
kommand = CommandRegistrar.register(this, displayManager, editSessions, permissionSession!!)
|
kommand = CommandRegistrar.register(this, displayManager, permissionSession!!)
|
||||||
|
|
||||||
instance = this
|
instance = this
|
||||||
logger.info("GhostDisplays ready: ${displayRegistry.controllerCount()} controllers active.")
|
logger.info("GhostDisplays ready: ${displayRegistry.controllerCount()} controllers active.")
|
||||||
|
|
@ -48,7 +43,6 @@ class GhostDisplaysPlugin : JavaPlugin() {
|
||||||
override fun onDisable() {
|
override fun onDisable() {
|
||||||
kommand?.unregister()
|
kommand?.unregister()
|
||||||
kommand = null
|
kommand = null
|
||||||
runCatching { editSessions.shutdown() }
|
|
||||||
runCatching { displayManager.destroyAll() }
|
runCatching { displayManager.destroyAll() }
|
||||||
runCatching { serviceImpl.destroyAll() }
|
runCatching { serviceImpl.destroyAll() }
|
||||||
permissionSession = null
|
permissionSession = null
|
||||||
|
|
|
||||||
|
|
@ -6,7 +6,6 @@ import java.util.UUID
|
||||||
import net.hareworks.ghostdisplays.display.DisplayManager
|
import net.hareworks.ghostdisplays.display.DisplayManager
|
||||||
import net.hareworks.ghostdisplays.display.DisplayManager.DisplayOperationException
|
import net.hareworks.ghostdisplays.display.DisplayManager.DisplayOperationException
|
||||||
import net.hareworks.ghostdisplays.display.DisplayKind
|
import net.hareworks.ghostdisplays.display.DisplayKind
|
||||||
import net.hareworks.ghostdisplays.display.EditSessionManager
|
|
||||||
import net.hareworks.kommand_lib.KommandLib
|
import net.hareworks.kommand_lib.KommandLib
|
||||||
import net.hareworks.kommand_lib.kommand
|
import net.hareworks.kommand_lib.kommand
|
||||||
import net.hareworks.permits_lib.bukkit.MutationSession
|
import net.hareworks.permits_lib.bukkit.MutationSession
|
||||||
|
|
@ -24,7 +23,6 @@ object CommandRegistrar {
|
||||||
fun register(
|
fun register(
|
||||||
plugin: JavaPlugin,
|
plugin: JavaPlugin,
|
||||||
manager: DisplayManager,
|
manager: DisplayManager,
|
||||||
editSessions: EditSessionManager,
|
|
||||||
permissionSession: MutationSession
|
permissionSession: MutationSession
|
||||||
): KommandLib =
|
): KommandLib =
|
||||||
kommand(plugin) {
|
kommand(plugin) {
|
||||||
|
|
@ -54,8 +52,7 @@ object CommandRegistrar {
|
||||||
val location = player.anchorLocation()
|
val location = player.anchorLocation()
|
||||||
try {
|
try {
|
||||||
val display = manager.createTextDisplay(id, location, "", player)
|
val display = manager.createTextDisplay(id, location, "", player)
|
||||||
editSessions.begin(player, display.id)
|
sender.success("Text display '${display.id}' created at ${describe(location)}. Use /ghostdisplay text set ${display.id} <content> to set text.")
|
||||||
sender.success("Text display '${display.id}' created at ${describe(location)}. Type text in chat (or 'cancel') to set content.")
|
|
||||||
} catch (ex: DisplayOperationException) {
|
} catch (ex: DisplayOperationException) {
|
||||||
sender.failure(ex.message ?: "Failed to create text display.")
|
sender.failure(ex.message ?: "Failed to create text display.")
|
||||||
}
|
}
|
||||||
|
|
@ -222,27 +219,6 @@ object CommandRegistrar {
|
||||||
}
|
}
|
||||||
|
|
||||||
literal("text") {
|
literal("text") {
|
||||||
literal("edit") {
|
|
||||||
string("id") {
|
|
||||||
suggests { prefix ->
|
|
||||||
manager.listDisplays()
|
|
||||||
.filter { it.kind == DisplayKind.TEXT }
|
|
||||||
.map { it.id }
|
|
||||||
.filter { it.startsWith(prefix, ignoreCase = true) }
|
|
||||||
}
|
|
||||||
executes {
|
|
||||||
val player = sender.requirePlayer() ?: return@executes
|
|
||||||
val id = argument<String>("id")
|
|
||||||
val display = manager.findDisplay(id)
|
|
||||||
if (display == null || display.kind != DisplayKind.TEXT) {
|
|
||||||
sender.failure("Text display '$id' not found.")
|
|
||||||
return@executes
|
|
||||||
}
|
|
||||||
editSessions.begin(player, display.id)
|
|
||||||
sender.info("Enter new MiniMessage text in chat for '${display.id}'. Type 'cancel' to abort.")
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
literal("set") {
|
literal("set") {
|
||||||
string("id") {
|
string("id") {
|
||||||
suggests { prefix ->
|
suggests { prefix ->
|
||||||
|
|
@ -258,7 +234,7 @@ object CommandRegistrar {
|
||||||
val raw = token.replace('_', ' ').replace("\\n", "\n")
|
val raw = token.replace('_', ' ').replace("\\n", "\n")
|
||||||
try {
|
try {
|
||||||
manager.updateText(id, raw)
|
manager.updateText(id, raw)
|
||||||
sender.success("Updated text for '$id'. Use /ghostdisplay text edit $id for multi-line content.")
|
sender.success("Updated text for '$id'.")
|
||||||
} catch (ex: DisplayOperationException) {
|
} catch (ex: DisplayOperationException) {
|
||||||
sender.failure(ex.message ?: "Failed to update text.")
|
sender.failure(ex.message ?: "Failed to update text.")
|
||||||
}
|
}
|
||||||
|
|
@ -266,16 +242,6 @@ object CommandRegistrar {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
literal("cancel") {
|
|
||||||
executes {
|
|
||||||
val player = sender.requirePlayer() ?: return@executes
|
|
||||||
if (editSessions.cancel(player)) {
|
|
||||||
sender.success("Editing session cancelled.")
|
|
||||||
} else {
|
|
||||||
sender.failure("You are not editing any display.")
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
literal("block") {
|
literal("block") {
|
||||||
|
|
@ -531,7 +497,6 @@ object CommandRegistrar {
|
||||||
private fun CommandSender.showUsage() {
|
private fun CommandSender.showUsage() {
|
||||||
info("GhostDisplays commands:")
|
info("GhostDisplays commands:")
|
||||||
info(" /ghostdisplay create <text|block|item> ...")
|
info(" /ghostdisplay create <text|block|item> ...")
|
||||||
info(" /ghostdisplay text edit <id> - edit text via chat")
|
|
||||||
info(" /ghostdisplay viewer <add|remove|clear> ...")
|
info(" /ghostdisplay viewer <add|remove|clear> ...")
|
||||||
info(" /ghostdisplay audience <permission|near|clear> ...")
|
info(" /ghostdisplay audience <permission|near|clear> ...")
|
||||||
info(" /ghostdisplay list | info <id> | delete <id>")
|
info(" /ghostdisplay list | info <id> | delete <id>")
|
||||||
|
|
|
||||||
|
|
@ -1,57 +0,0 @@
|
||||||
package net.hareworks.ghostdisplays.display
|
|
||||||
|
|
||||||
import java.util.UUID
|
|
||||||
import java.util.concurrent.ConcurrentHashMap
|
|
||||||
import net.hareworks.ghostdisplays.display.DisplayManager.DisplayOperationException
|
|
||||||
import org.bukkit.Bukkit
|
|
||||||
import org.bukkit.entity.Player
|
|
||||||
import org.bukkit.event.EventHandler
|
|
||||||
import org.bukkit.event.Listener
|
|
||||||
import org.bukkit.event.player.PlayerQuitEvent
|
|
||||||
import org.bukkit.plugin.java.JavaPlugin
|
|
||||||
|
|
||||||
class EditSessionManager(
|
|
||||||
private val plugin: JavaPlugin,
|
|
||||||
private val manager: DisplayManager
|
|
||||||
) : Listener {
|
|
||||||
private val sessions = ConcurrentHashMap<UUID, String>()
|
|
||||||
|
|
||||||
fun begin(player: Player, displayId: String) {
|
|
||||||
sessions[player.uniqueId] = displayId
|
|
||||||
}
|
|
||||||
|
|
||||||
fun cancel(player: Player): Boolean = sessions.remove(player.uniqueId) != null
|
|
||||||
|
|
||||||
fun shutdown() {
|
|
||||||
sessions.clear()
|
|
||||||
}
|
|
||||||
|
|
||||||
@EventHandler(ignoreCancelled = true)
|
|
||||||
fun onPlayerChat(event: io.papermc.paper.event.player.AsyncChatEvent) {
|
|
||||||
val displayId = sessions[event.player.uniqueId] ?: return
|
|
||||||
event.isCancelled = true
|
|
||||||
val serializer = net.kyori.adventure.text.serializer.plain.PlainTextComponentSerializer.plainText()
|
|
||||||
val message = serializer.serialize(event.message())
|
|
||||||
|
|
||||||
if (message.equals("cancel", ignoreCase = true)) {
|
|
||||||
sessions.remove(event.player.uniqueId)
|
|
||||||
event.player.sendMessage("GhostDisplays: editing for '$displayId' cancelled.")
|
|
||||||
return
|
|
||||||
}
|
|
||||||
Bukkit.getScheduler().runTask(plugin, Runnable {
|
|
||||||
try {
|
|
||||||
manager.updateText(displayId, message)
|
|
||||||
event.player.sendMessage("GhostDisplays: updated text for '$displayId'.")
|
|
||||||
} catch (ex: DisplayOperationException) {
|
|
||||||
event.player.sendMessage("GhostDisplays: ${ex.message}")
|
|
||||||
} finally {
|
|
||||||
sessions.remove(event.player.uniqueId)
|
|
||||||
}
|
|
||||||
})
|
|
||||||
}
|
|
||||||
|
|
||||||
@EventHandler
|
|
||||||
fun onPlayerQuit(event: PlayerQuitEvent) {
|
|
||||||
sessions.remove(event.player.uniqueId)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
Loading…
Reference in New Issue
Block a user