diff --git a/src/main/kotlin/net/axay/kspigot/chat/input/PlayerInput.kt b/src/main/kotlin/net/axay/kspigot/chat/input/PlayerInput.kt index b2dcaa5d..5f1b47b7 100644 --- a/src/main/kotlin/net/axay/kspigot/chat/input/PlayerInput.kt +++ b/src/main/kotlin/net/axay/kspigot/chat/input/PlayerInput.kt @@ -9,6 +9,7 @@ import net.axay.kspigot.chat.input.implementations.PlayerInputChat import net.axay.kspigot.event.unregister import net.axay.kspigot.runnables.sync import net.axay.kspigot.runnables.taskRunLater +import net.axay.kspigot.utils.mark import org.bukkit.entity.Player import org.bukkit.event.Listener @@ -49,9 +50,7 @@ fun Player.awaitAnvilInput( fun Player.awaitBookInputAsString( timeoutSeconds: Int = 1 * 60, callback: (PlayerInputResult) -> Unit, -) { - PlayerInputBookComprehensive(this, callback, timeoutSeconds) -} +) = PlayerInputBookComprehensive(this, callback, timeoutSeconds).bookItemStack /** * Opens a book and uses the text the player inserted @@ -62,14 +61,13 @@ fun Player.awaitBookInputAsString( fun Player.awaitBookInputAsList( timeoutSeconds: Int = 1 * 60, callback: (PlayerInputResult>) -> Unit, -) { - PlayerInputBookPaged(this, callback, timeoutSeconds) -} +) = PlayerInputBookPaged(this, callback, timeoutSeconds).bookItemStack /** * @param input The input the player gave. Null on timeout or invalid input. */ class PlayerInputResult internal constructor(val input: T?) + internal abstract class PlayerInput( protected val player: Player, private val callback: (PlayerInputResult) -> Unit, diff --git a/src/main/kotlin/net/axay/kspigot/chat/input/implementations/PlayerInputBook.kt b/src/main/kotlin/net/axay/kspigot/chat/input/implementations/PlayerInputBook.kt index 32740df2..ba052964 100644 --- a/src/main/kotlin/net/axay/kspigot/chat/input/implementations/PlayerInputBook.kt +++ b/src/main/kotlin/net/axay/kspigot/chat/input/implementations/PlayerInputBook.kt @@ -37,12 +37,14 @@ internal abstract class PlayerInputBook( ) : PlayerInput(player, callback, timeoutSeconds) { private val id = getID() + val bookItemStack = itemStack(Material.WRITABLE_BOOK) { + meta { + persistentDataContainer[idKey, PersistentDataType.INTEGER] = id + } + } + init { - player.openBook(itemStack(Material.WRITABLE_BOOK) { - meta { - persistentDataContainer[idKey, PersistentDataType.INTEGER] = id - } - }) + player.inventory.addItem(bookItemStack) } abstract fun loadBookContent(bookMeta: BookMeta): T @@ -53,6 +55,8 @@ internal abstract class PlayerInputBook( if (meta.persistentDataContainer[idKey, PersistentDataType.INTEGER] == id) { onReceive(loadBookContent(meta)) usedIDs -= id + it.isCancelled = true + player.inventory.removeItem(bookItemStack) } } )