mirror of
https://github.com/plexusorg/Plex.git
synced 2024-12-22 17:17:37 +00:00
add the ability to override the chat
safe serialize minimessage methods
This commit is contained in:
parent
6c4903c3fe
commit
4450427d4e
@ -25,7 +25,6 @@ import org.jetbrains.annotations.NotNull;
|
|||||||
public class ChatListener extends PlexListener
|
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();
|
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
|
@EventHandler
|
||||||
public void onChat(AsyncChatEvent event)
|
public void onChat(AsyncChatEvent event)
|
||||||
{
|
{
|
||||||
@ -72,7 +71,7 @@ public class ChatListener extends PlexListener
|
|||||||
component = component.append(prefix);
|
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);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1,7 +1,6 @@
|
|||||||
package dev.plex.util.minimessage;
|
package dev.plex.util.minimessage;
|
||||||
|
|
||||||
import com.google.common.collect.ImmutableList;
|
import com.google.common.collect.ImmutableList;
|
||||||
import java.util.List;
|
|
||||||
import net.kyori.adventure.text.Component;
|
import net.kyori.adventure.text.Component;
|
||||||
import net.kyori.adventure.text.minimessage.Context;
|
import net.kyori.adventure.text.minimessage.Context;
|
||||||
import net.kyori.adventure.text.minimessage.MiniMessage;
|
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.NotNull;
|
||||||
import org.jetbrains.annotations.Nullable;
|
import org.jetbrains.annotations.Nullable;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
public class SafeMiniMessage
|
public class SafeMiniMessage
|
||||||
{
|
{
|
||||||
public static final MiniMessage MINI_MESSAGE = MiniMessage.builder().tags(new SafeMiniMessageTagResolver()).build();
|
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)
|
public static Component mmDeserializeWithoutEvents(String text)
|
||||||
{
|
{
|
||||||
return mmDeserialize(text)
|
return mmDeserialize(text).clickEvent(null).hoverEvent(null);
|
||||||
.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
|
public static class SafeMiniMessageTagResolver implements TagResolver
|
||||||
|
Loading…
Reference in New Issue
Block a user