-
-
Notifications
You must be signed in to change notification settings - Fork 17
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
added option to excape command by starting a message by \/command
- Loading branch information
1 parent
ec1b3c7
commit 321c766
Showing
2 changed files
with
34 additions
and
3 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
27 changes: 27 additions & 0 deletions
27
src/main/java/me/youhavetrouble/purpurextras/listeners/EscapeCommandSlashListener.java
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 me.youhavetrouble.purpurextras.listeners; | ||
|
||
import io.papermc.paper.event.player.AsyncChatEvent; | ||
import net.kyori.adventure.text.Component; | ||
import net.kyori.adventure.text.TextReplacementConfig; | ||
import net.kyori.adventure.text.serializer.plain.PlainComponentSerializer; | ||
import org.bukkit.event.EventHandler; | ||
import org.bukkit.event.EventPriority; | ||
import org.bukkit.event.Listener; | ||
|
||
public class EscapeCommandSlashListener implements Listener { | ||
|
||
@EventHandler(priority = EventPriority.NORMAL, ignoreCancelled = true) | ||
public void onCommandEscape(AsyncChatEvent event) { | ||
String message = PlainComponentSerializer.plain().serialize(event.message()); | ||
String[] messageSplit = message.split(" "); | ||
String command = messageSplit[0].substring(1); | ||
Component component = event.message().replaceText( | ||
TextReplacementConfig.builder() | ||
.match("(\\\\/\\S*)") | ||
.replacement(command) | ||
.once() | ||
.build()); | ||
event.message(component); | ||
} | ||
|
||
} |