From c9aec150aeac0e828ef6e7d0b3e86ca12ae43882 Mon Sep 17 00:00:00 2001 From: Jakob K Date: Mon, 28 Jun 2021 13:37:53 +0200 Subject: [PATCH] Add onClick shortcut functions to LiteralTextBuilder --- .../axay/kspigot/chat/LiteralTextBuilder.kt | 20 +++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/src/main/kotlin/net/axay/kspigot/chat/LiteralTextBuilder.kt b/src/main/kotlin/net/axay/kspigot/chat/LiteralTextBuilder.kt index 8192cd4c..1ea3484c 100644 --- a/src/main/kotlin/net/axay/kspigot/chat/LiteralTextBuilder.kt +++ b/src/main/kotlin/net/axay/kspigot/chat/LiteralTextBuilder.kt @@ -106,6 +106,26 @@ class LiteralTextBuilder(val internalText: BaseComponent, ) { ) } + /** + * Sets the command which should be executed by the Player if he clicks + * on the text. + * + * @param command the command which should be executed, the `/ should be added here + * @param onlySuggest if true, the command won't be executed immediately, + * instead it will be suggested in the command prompt + */ + fun onClickCommand(command: String, onlySuggest: Boolean = false) { + clickEvent = ClickEvent(if (onlySuggest) ClickEvent.Action.SUGGEST_COMMAND else ClickEvent.Action.RUN_COMMAND, command) + } + + /** + * Sets the String which should be copied to the clipboard if the + * Player clicks on this text. + */ + fun onClickCopy(copyText: String) { + clickEvent = ClickEvent(ClickEvent.Action.COPY_TO_CLIPBOARD, copyText) + } + /** * Adds a line break. */