add the ability to override the chat

safe serialize minimessage methods
This commit is contained in:
Taah 2022-05-07 17:11:19 -07:00
parent 6c4903c3fe
commit 4450427d4e
2 changed files with 14 additions and 6 deletions

View File

@ -25,7 +25,6 @@ import org.jetbrains.annotations.NotNull;
public class ChatListener extends PlexListener
{
private final static TextReplacementConfig URL_REPLACEMENT_CONFIG = TextReplacementConfig.builder().match("(https?|ftp|file)://[-a-zA-Z0-9+&@#/%?=~_|!:,.;]*[-a-zA-Z0-9+&@#/%=~_|]").replacement((matchResult, builder) -> Component.empty().content(matchResult.group()).clickEvent(ClickEvent.openUrl(matchResult.group()))).build();
@EventHandler
public void onChat(AsyncChatEvent event)
{
@ -72,7 +71,7 @@ public class ChatListener extends PlexListener
component = component.append(prefix);
}
return component.append(Component.space()).append(PlexUtils.mmDeserialize(plugin.config.getString("chat.name-color", "<white>") + MiniMessage.builder().tags(TagResolver.resolver(StandardTags.color(), StandardTags.rainbow(), StandardTags.decorations(), StandardTags.gradient(), StandardTags.transition())).build().serialize(sourceDisplayName))).append(Component.space()).append(Component.text("»").color(NamedTextColor.GRAY)).append(Component.space()).append(SafeMiniMessage.mmDeserializeWithoutEvents(text)).replaceText(URL_REPLACEMENT_CONFIG);
return component.append(Component.space()).append(PlexUtils.mmDeserialize(plugin.config.getString("chat.name-color", "<white>") + MiniMessage.builder().tags(TagResolver.resolver(StandardTags.color(), StandardTags.rainbow(), StandardTags.decorations(), StandardTags.gradient(), StandardTags.transition())).build().serialize(sourceDisplayName))).append(Component.space()).append(Component.text("»").color(NamedTextColor.GRAY)).append(Component.space()).append(SafeMiniMessage.mmSerializeWithoutEvents(text)).replaceText(URL_REPLACEMENT_CONFIG);
}
}
}

View File

@ -1,7 +1,6 @@
package dev.plex.util.minimessage;
import com.google.common.collect.ImmutableList;
import java.util.List;
import net.kyori.adventure.text.Component;
import net.kyori.adventure.text.minimessage.Context;
import net.kyori.adventure.text.minimessage.MiniMessage;
@ -12,6 +11,8 @@ import net.kyori.adventure.text.minimessage.tag.resolver.TagResolver;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import java.util.List;
public class SafeMiniMessage
{
public static final MiniMessage MINI_MESSAGE = MiniMessage.builder().tags(new SafeMiniMessageTagResolver()).build();
@ -23,9 +24,17 @@ public class SafeMiniMessage
public static Component mmDeserializeWithoutEvents(String text)
{
return mmDeserialize(text)
.clickEvent(null)
.hoverEvent(null);
return mmDeserialize(text).clickEvent(null).hoverEvent(null);
}
public static String mmSerialize(Component component)
{
return MINI_MESSAGE.serialize(component);
}
public static String mmSerializeWithoutEvents(Component component)
{
return mmSerialize(component.clickEvent(null).hoverEvent(null));
}
public static class SafeMiniMessageTagResolver implements TagResolver