-
Notifications
You must be signed in to change notification settings - Fork 13
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
1e18156
commit 72274b2
Showing
7 changed files
with
126 additions
and
5 deletions.
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
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 |
---|---|---|
|
@@ -5,7 +5,7 @@ plugins { | |
} | ||
|
||
group = "gg.flyte" | ||
version = "1.0.29" | ||
version = "1.0.30" | ||
|
||
repositories { | ||
mavenCentral() | ||
|
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
19 changes: 19 additions & 0 deletions
19
src/main/kotlin/gg/flyte/twilight/event/custom/chat/ChatClickEvent.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,19 @@ | ||
package gg.flyte.twilight.event.custom.chat | ||
|
||
import gg.flyte.twilight.event.TwilightEvent | ||
import org.bukkit.entity.Player | ||
|
||
/** | ||
* Represents an event that is triggered when a chat component with a custom click event is interacted with. | ||
* | ||
* This event carries information about the player who clicked the chat component and the data that was | ||
* sent along with the click event, typically used to determine what action should be taken as a result | ||
* of the click. | ||
* | ||
* @param player The player who clicked the chat component. | ||
* @param data The array of strings sent with the click event. | ||
*/ | ||
class ChatClickEvent( | ||
val player: Player, | ||
val data: Array<String> | ||
) : TwilightEvent() |
37 changes: 37 additions & 0 deletions
37
src/main/kotlin/gg/flyte/twilight/event/custom/chat/Extension.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,37 @@ | ||
package gg.flyte.twilight.event.custom.chat | ||
|
||
import net.kyori.adventure.text.Component | ||
import net.kyori.adventure.text.event.ClickEvent | ||
import net.md_5.bungee.api.chat.TextComponent | ||
|
||
/** | ||
* Attaches a custom click event to a Component. | ||
* | ||
* This function adds a click event to the Component that triggers a command | ||
* when the component is clicked in the chat. The command is constructed by | ||
* prefixing '/chatclick' with the joined string representations of the provided | ||
* vararg data parameters, separated by spaces. This will then trigger the | ||
* ChatClickEvent which will contain the data. | ||
* | ||
* @param data Vararg parameter strings that are concatenated and used as data for the command. | ||
* @return The Component with the attached click event. | ||
*/ | ||
fun Component.customClickEvent(vararg data: String): Component { | ||
return this.clickEvent(ClickEvent.clickEvent(ClickEvent.Action.RUN_COMMAND, "/chatclick ${data.joinToString(" ")}")) | ||
} | ||
|
||
/** | ||
* Attaches a custom click event to a TextComponent. | ||
* | ||
* This function assigns a new click event to the TextComponent that will execute a command | ||
* when the component is interacted with in the chat. The command consists of '/chatclick' | ||
* followed by the space-separated concatenation of the input data. This will then trigger | ||
* the ChatClickEvent which will contain the data. | ||
* | ||
* @param data Vararg parameter strings that are combined into a single command string. | ||
* @return The TextComponent with the new click event. | ||
*/ | ||
fun TextComponent.customClickEvent(vararg data: String): TextComponent { | ||
clickEvent = net.md_5.bungee.api.chat.ClickEvent(net.md_5.bungee.api.chat.ClickEvent.Action.RUN_COMMAND, "/chatclick ${data.joinToString(" ")}") | ||
return this | ||
} |
27 changes: 27 additions & 0 deletions
27
src/main/kotlin/gg/flyte/twilight/event/custom/chat/command/ChatClickCommand.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,27 @@ | ||
package gg.flyte.twilight.event.custom.chat.command | ||
|
||
import gg.flyte.twilight.Twilight | ||
import gg.flyte.twilight.event.custom.chat.ChatClickEvent | ||
import org.bukkit.command.CommandMap | ||
import org.bukkit.command.CommandSender | ||
import org.bukkit.command.defaults.BukkitCommand | ||
import org.bukkit.entity.Player | ||
|
||
object ChatClickCommand : BukkitCommand("chatclick") { | ||
|
||
fun register() { | ||
runCatching { | ||
val commandMapField = Twilight.plugin.server.javaClass.getDeclaredField("commandMap") | ||
commandMapField.isAccessible = true | ||
val commandMap = commandMapField.get(Twilight.plugin.server) as CommandMap | ||
commandMap.register("chatclick", this@ChatClickCommand) | ||
} | ||
} | ||
|
||
override fun execute(sender: CommandSender, commandLabel: String, args: Array<String>): Boolean { | ||
if (sender !is Player) return false | ||
Twilight.plugin.server.pluginManager.callEvent(ChatClickEvent(sender, args)) | ||
return false | ||
} | ||
|
||
} |
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