mirror of
https://github.com/darksaid98/Carbon.git
synced 2026-12-03 14:38:51 +00:00
perf: Cache URL_REPLACEMENT_CONFIG creation
And move it to the common module
This commit is contained in:
4 files changed
+19
-25
No files matched your search
+2
-9
@@ -23,7 +23,6 @@ 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,12 +32,11 @@ import net.draycia.carbon.api.util.KeyedRenderer;
|
||||
import net.draycia.carbon.velocity.CarbonChatVelocity;
|
||||
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.framework.qual.DefaultQualifier;
|
||||
|
||||
import static java.util.Objects.requireNonNullElse;
|
||||
import static net.draycia.carbon.api.util.KeyedRenderer.keyedRenderer;
|
||||
import static net.draycia.carbon.common.util.Strings.URL_REPLACEMENT_CONFIG;
|
||||
import static net.kyori.adventure.key.Key.key;
|
||||
import static net.kyori.adventure.text.Component.empty;
|
||||
import static net.kyori.adventure.text.Component.text;
|
||||
@@ -50,8 +48,6 @@ public final class VelocityChatListener {
|
||||
private final ChannelRegistry registry;
|
||||
private final UserManager<?> userManager;
|
||||
|
||||
private static final Pattern DEFAULT_URL_PATTERN = Pattern.compile("(?:(https?)://)?([-\\w_.]+\\.\\w{2,})(/\\S*)?");
|
||||
|
||||
@Inject
|
||||
private VelocityChatListener(final CarbonChat carbonChat, final ChannelRegistry registry, final UserManager<?> userManager) {
|
||||
this.carbonChat = (CarbonChatVelocity) carbonChat;
|
||||
@@ -73,10 +69,7 @@ public final class VelocityChatListener {
|
||||
Component eventMessage = text(originalMessage);
|
||||
|
||||
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());
|
||||
eventMessage = eventMessage.replaceText(URL_REPLACEMENT_CONFIG.get());
|
||||
}
|
||||
|
||||
for (final var chatChannel : this.registry) {
|
||||
|
||||
Reference in new issue
Block a user