diff --git a/src/main/kotlin/net/hareworks/ghostdisplays/GhostDisplaysPlugin.kt b/src/main/kotlin/net/hareworks/ghostdisplays/GhostDisplaysPlugin.kt index 5e87363..0e40209 100644 --- a/src/main/kotlin/net/hareworks/ghostdisplays/GhostDisplaysPlugin.kt +++ b/src/main/kotlin/net/hareworks/ghostdisplays/GhostDisplaysPlugin.kt @@ -3,7 +3,6 @@ package net.hareworks.ghostdisplays import net.hareworks.ghostdisplays.api.DisplayService import net.hareworks.ghostdisplays.command.CommandRegistrar import net.hareworks.ghostdisplays.display.DisplayManager -import net.hareworks.ghostdisplays.display.EditSessionManager import net.hareworks.ghostdisplays.internal.DefaultDisplayService import net.hareworks.ghostdisplays.internal.controller.DisplayRegistry import net.hareworks.kommand_lib.KommandLib @@ -17,7 +16,6 @@ class GhostDisplaysPlugin : JavaPlugin() { private lateinit var displayRegistry: DisplayRegistry private lateinit var serviceImpl: DisplayService private lateinit var displayManager: DisplayManager - private lateinit var editSessions: EditSessionManager private lateinit var miniMessage: MiniMessage private var permissionSession: MutationSession? = null private var kommand: KommandLib? = null @@ -29,13 +27,10 @@ class GhostDisplaysPlugin : JavaPlugin() { } serviceImpl = DefaultDisplayService(this, displayRegistry) 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) permissionSession = PermitsLib.session(this) - kommand = CommandRegistrar.register(this, displayManager, editSessions, permissionSession!!) + kommand = CommandRegistrar.register(this, displayManager, permissionSession!!) instance = this logger.info("GhostDisplays ready: ${displayRegistry.controllerCount()} controllers active.") @@ -48,7 +43,6 @@ class GhostDisplaysPlugin : JavaPlugin() { override fun onDisable() { kommand?.unregister() kommand = null - runCatching { editSessions.shutdown() } runCatching { displayManager.destroyAll() } runCatching { serviceImpl.destroyAll() } permissionSession = null diff --git a/src/main/kotlin/net/hareworks/ghostdisplays/command/CommandRegistrar.kt b/src/main/kotlin/net/hareworks/ghostdisplays/command/CommandRegistrar.kt index f4a9310..0e5c6e3 100644 --- a/src/main/kotlin/net/hareworks/ghostdisplays/command/CommandRegistrar.kt +++ b/src/main/kotlin/net/hareworks/ghostdisplays/command/CommandRegistrar.kt @@ -6,7 +6,6 @@ import java.util.UUID import net.hareworks.ghostdisplays.display.DisplayManager import net.hareworks.ghostdisplays.display.DisplayManager.DisplayOperationException import net.hareworks.ghostdisplays.display.DisplayKind -import net.hareworks.ghostdisplays.display.EditSessionManager import net.hareworks.kommand_lib.KommandLib import net.hareworks.kommand_lib.kommand import net.hareworks.permits_lib.bukkit.MutationSession @@ -24,7 +23,6 @@ object CommandRegistrar { fun register( plugin: JavaPlugin, manager: DisplayManager, - editSessions: EditSessionManager, permissionSession: MutationSession ): KommandLib = kommand(plugin) { @@ -54,8 +52,7 @@ object CommandRegistrar { val location = player.anchorLocation() try { val display = manager.createTextDisplay(id, location, "", player) - editSessions.begin(player, display.id) - sender.success("Text display '${display.id}' created at ${describe(location)}. Type text in chat (or 'cancel') to set content.") + sender.success("Text display '${display.id}' created at ${describe(location)}. Use /ghostdisplay text set ${display.id} to set text.") } catch (ex: DisplayOperationException) { sender.failure(ex.message ?: "Failed to create text display.") } @@ -222,27 +219,6 @@ object CommandRegistrar { } 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("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") { string("id") { suggests { prefix -> @@ -258,7 +234,7 @@ object CommandRegistrar { val raw = token.replace('_', ' ').replace("\\n", "\n") try { 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) { 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") { @@ -531,7 +497,6 @@ object CommandRegistrar { private fun CommandSender.showUsage() { info("GhostDisplays commands:") info(" /ghostdisplay create ...") - info(" /ghostdisplay text edit - edit text via chat") info(" /ghostdisplay viewer ...") info(" /ghostdisplay audience ...") info(" /ghostdisplay list | info | delete ") diff --git a/src/main/kotlin/net/hareworks/ghostdisplays/display/EditSessionManager.kt b/src/main/kotlin/net/hareworks/ghostdisplays/display/EditSessionManager.kt deleted file mode 100644 index 059689f..0000000 --- a/src/main/kotlin/net/hareworks/ghostdisplays/display/EditSessionManager.kt +++ /dev/null @@ -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() - - 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) - } -}