Add permission to url link handling

This commit is contained in:
Draycia committed 2020-11-17 04:03:07 -08:00
1 parent cbd1d66f60
commit f1703b6b1d
1 file changed
+4 -3
@@ -11,10 +11,11 @@ public class UrlLinkHandler {
private static final Pattern URL_PATTERN = Pattern.compile("((?:(https?)://)?([-\\w_.]+\\.\\w{2,})(/\\S*)?)");
public UrlLinkHandler() {
// TODO: permission to make links clickable, maybe?
CarbonEvents.register(ChatFormatEvent.class, PostOrders.NORMAL, true, event -> {
event.message(URL_PATTERN.matcher(event.message()).replaceAll("<click:open_url:'$1'>$1</click>"));
// Reminder: Do not use this on event.format(), this breaks hover events when they contain URLs
if (event.sender().hasPermission("carbonchat.autourl")) {
event.message(URL_PATTERN.matcher(event.message()).replaceAll("<click:open_url:'$1'>$1</click>"));
// Reminder: Do not use this on event.format(), this breaks hover events when they contain URLs
}
});
}