mirror of
https://github.com/darksaid98/Carbon.git
synced 2026-12-03 14:38:51 +00:00
Don't include message prefix in message
This commit is contained in:
4 files changed
+82
-17
No files matched your search
+20
-1
@@ -23,6 +23,7 @@ import com.google.inject.Inject;
|
||||
import com.velocitypowered.api.event.Subscribe;
|
||||
import com.velocitypowered.api.event.player.PlayerChatEvent;
|
||||
import java.util.ArrayList;
|
||||
import java.util.regex.Pattern;
|
||||
import net.draycia.carbon.api.CarbonChat;
|
||||
import net.draycia.carbon.api.channels.ChannelRegistry;
|
||||
import net.draycia.carbon.api.events.CarbonChatEvent;
|
||||
@@ -33,6 +34,8 @@ import net.draycia.carbon.velocity.CarbonChatVelocity;
|
||||
import net.kyori.adventure.audience.MessageType;
|
||||
import net.kyori.adventure.identity.Identity;
|
||||
import net.kyori.adventure.text.Component;
|
||||
import net.kyori.adventure.text.TextReplacementConfig;
|
||||
import net.kyori.adventure.text.event.ClickEvent;
|
||||
import org.checkerframework.checker.nullness.qual.NonNull;
|
||||
import org.checkerframework.checker.nullness.qual.Nullable;
|
||||
import org.checkerframework.framework.qual.DefaultQualifier;
|
||||
@@ -41,6 +44,7 @@ import static java.util.Objects.requireNonNullElse;
|
||||
import static net.draycia.carbon.api.util.KeyedRenderer.keyedRenderer;
|
||||
import static net.kyori.adventure.key.Key.key;
|
||||
import static net.kyori.adventure.text.Component.empty;
|
||||
import static net.kyori.adventure.text.Component.text;
|
||||
|
||||
@DefaultQualifier(NonNull.class)
|
||||
public final class VelocityChatListener {
|
||||
@@ -48,6 +52,8 @@ public final class VelocityChatListener {
|
||||
private final CarbonChatVelocity carbonChat;
|
||||
private final ChannelRegistry registry;
|
||||
|
||||
private static final Pattern DEFAULT_URL_PATTERN = Pattern.compile("(?:(https?)://)?([-\\w_.]+\\.\\w{2,})(/\\S*)?");
|
||||
|
||||
@Inject
|
||||
private VelocityChatListener(final CarbonChat carbonChat, final ChannelRegistry registry) {
|
||||
this.carbonChat = (CarbonChatVelocity) carbonChat;
|
||||
@@ -72,6 +78,14 @@ public final class VelocityChatListener {
|
||||
var channel = requireNonNullElse(sender.selectedChannel(), this.registry.defaultValue());
|
||||
|
||||
final var originalMessage = event.getMessage();
|
||||
Component eventMessage = text(event.getMessage());
|
||||
|
||||
if (sender.hasPermission("carbon.chatlinks")) {
|
||||
eventMessage = eventMessage.replaceText(TextReplacementConfig.builder()
|
||||
.match(DEFAULT_URL_PATTERN)
|
||||
.replacement(builder -> builder.clickEvent(ClickEvent.clickEvent(ClickEvent.Action.OPEN_URL, builder.content())))
|
||||
.build());
|
||||
}
|
||||
|
||||
for (final var chatChannel : this.registry) {
|
||||
if (chatChannel.quickPrefix() == null) {
|
||||
@@ -80,6 +94,11 @@ public final class VelocityChatListener {
|
||||
|
||||
if (originalMessage.startsWith(chatChannel.quickPrefix()) && chatChannel.speechPermitted(sender).permitted()) {
|
||||
channel = chatChannel;
|
||||
eventMessage = eventMessage.replaceText(TextReplacementConfig.builder()
|
||||
.once()
|
||||
.matchLiteral(channel.quickPrefix())
|
||||
.replacement(text())
|
||||
.build());
|
||||
break;
|
||||
}
|
||||
}
|
||||
@@ -89,7 +108,7 @@ public final class VelocityChatListener {
|
||||
final var renderers = new ArrayList<KeyedRenderer>();
|
||||
renderers.add(keyedRenderer(key("carbon", "default"), channel));
|
||||
|
||||
final var chatEvent = new CarbonChatEvent(sender, Component.text(event.getMessage()), recipients, renderers, channel);
|
||||
final var chatEvent = new CarbonChatEvent(sender, eventMessage, recipients, renderers, channel);
|
||||
final var result = this.carbonChat.eventHandler().emit(chatEvent);
|
||||
|
||||
if (!result.wasSuccessful()) {
|
||||
|
||||
Reference in new issue
Block a user