Skip to content

Commit

Permalink
feat(api): lock to messages starting w/ ~
Browse files Browse the repository at this point in the history
  • Loading branch information
tristancamejo committed Dec 26, 2022
1 parent cfe7f54 commit 1435197
Showing 1 changed file with 14 additions and 8 deletions.
22 changes: 14 additions & 8 deletions src/main/java/com/tristansmp/elytra/events/ChatListener.kt
Original file line number Diff line number Diff line change
Expand Up @@ -10,18 +10,24 @@ import org.bukkit.event.Listener
class ChatListener : Listener {
@EventHandler
fun onPlayerChat(event: AsyncChatEvent) {
val needsCollection = Elytra.instance.mstore.get<Boolean>("cc:${event.player.uniqueId}:needs_collection")
try {
val message = event.message() as TextComponent

if (needsCollection == null || !needsCollection) {
return
}
if (!message.content().startsWith("~")) {
return
}

event.isCancelled = true
event.isCancelled = true

try {
val message = event.message() as TextComponent
val content = message.content().substring(1)

val needsCollection = Elytra.instance.mstore.get<Boolean>("cc:${event.player.uniqueId}:needs_collection")

if (needsCollection == null || !needsCollection) {
return
}

Elytra.instance.mstore.set("cc:${event.player.uniqueId}:results", message.content())
Elytra.instance.mstore.set("cc:${event.player.uniqueId}:results", content)

event.player.sendMessage("§d[Elytra] §aMessage collected.")

Expand Down

0 comments on commit 1435197

Please sign in to comment.