mirror of
https://github.com/darksaid98/Carbon.git
synced 2026-12-01 22:15:08 +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
@@ -19,6 +19,11 @@
|
||||
*/
|
||||
package net.draycia.carbon.common.util;
|
||||
|
||||
import com.google.common.base.Suppliers;
|
||||
import java.util.function.Supplier;
|
||||
import java.util.regex.Pattern;
|
||||
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;
|
||||
@@ -26,6 +31,14 @@ import org.checkerframework.framework.qual.DefaultQualifier;
|
||||
@DefaultQualifier(NonNull.class)
|
||||
public final class Strings {
|
||||
|
||||
private static final Pattern DEFAULT_URL_PATTERN = Pattern.compile("(?:(https?)://)?([-\\w_.]+\\.\\w{2,})(/\\S*)?");
|
||||
public static final Supplier<TextReplacementConfig> URL_REPLACEMENT_CONFIG = Suppliers.memoize(
|
||||
() -> TextReplacementConfig.builder()
|
||||
.match(DEFAULT_URL_PATTERN)
|
||||
.replacement(builder -> builder.clickEvent(ClickEvent.clickEvent(ClickEvent.Action.OPEN_URL, builder.content())))
|
||||
.build()
|
||||
);
|
||||
|
||||
private Strings() {
|
||||
}
|
||||
|
||||
|
||||
Reference in new issue
Block a user