Skip to content

Commit

Permalink
Cleaned up ChatListener
Browse files Browse the repository at this point in the history
  • Loading branch information
AndyNoob committed Jul 3, 2024
1 parent 76f7601 commit a963bba
Showing 1 changed file with 8 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -35,9 +35,15 @@ public void onChat(AsyncPlayerChatEvent event) {
for (Player player : event.getRecipients()) {
final Pattern pattern = Pattern.compile("@?" + player.getName());
final Matcher matcher = pattern.matcher(converted);
if (matcher.find()) {
converted = matcher.replaceAll(replacement);
boolean matched = false;
while (matcher.find()) {
matched = true;
final String lastCol = ChatColor.getLastColors(converted.substring(0, matcher.start()));
converted = matcher.replaceFirst(replacement + ChatColor.RESET + lastCol);
}
if (matched) {
final String sound = config.getString("ping.sound.name", "minecraft:entity.arrow.hit_player");

if (!sound.isEmpty())
player.playSound(
player.getEyeLocation(),
Expand Down

0 comments on commit a963bba

Please sign in to comment.