Remove non-ASCII characters from tags & chat messages (closes #48)

This commit is contained in:
Allink 2022-08-02 03:23:08 +01:00
parent 262af44193
commit 3611148b4c
No known key found for this signature in database
GPG Key ID: 6C2F7CE6E0519E14
3 changed files with 9 additions and 5 deletions

View File

@ -7,6 +7,7 @@ import dev.plex.command.annotation.CommandPermissions;
import dev.plex.command.source.RequiredCommandSource; import dev.plex.command.source.RequiredCommandSource;
import dev.plex.player.PlexPlayer; import dev.plex.player.PlexPlayer;
import dev.plex.rank.enums.Rank; import dev.plex.rank.enums.Rank;
import dev.plex.util.PlexUtils;
import dev.plex.util.minimessage.SafeMiniMessage; import dev.plex.util.minimessage.SafeMiniMessage;
import net.kyori.adventure.text.Component; import net.kyori.adventure.text.Component;
import net.kyori.adventure.text.minimessage.MiniMessage; import net.kyori.adventure.text.minimessage.MiniMessage;
@ -46,7 +47,7 @@ public class TagCMD extends PlexCommand
{ {
return usage("/tag set <prefix>"); return usage("/tag set <prefix>");
} }
String prefix = StringUtils.join(args, " ", 1, args.length); String prefix = PlexUtils.cleanString(StringUtils.join(args, " ", 1, args.length));
Component convertedComponent = SafeMiniMessage.mmDeserializeWithoutEvents(prefix); Component convertedComponent = SafeMiniMessage.mmDeserializeWithoutEvents(prefix);

View File

@ -14,9 +14,6 @@ import net.kyori.adventure.text.Component;
import net.kyori.adventure.text.TextReplacementConfig; import net.kyori.adventure.text.TextReplacementConfig;
import net.kyori.adventure.text.event.ClickEvent; import net.kyori.adventure.text.event.ClickEvent;
import net.kyori.adventure.text.format.NamedTextColor; import net.kyori.adventure.text.format.NamedTextColor;
import net.kyori.adventure.text.minimessage.MiniMessage;
import net.kyori.adventure.text.minimessage.tag.resolver.TagResolver;
import net.kyori.adventure.text.minimessage.tag.standard.StandardTags;
import org.bukkit.entity.Player; import org.bukkit.entity.Player;
import org.bukkit.event.EventHandler; import org.bukkit.event.EventHandler;
import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.NotNull;
@ -73,7 +70,7 @@ public class ChatListener extends PlexListener
@Override @Override
public @NotNull Component render(@NotNull Player source, @NotNull Component sourceDisplayName, @NotNull Component message, @NotNull Audience viewer) public @NotNull Component render(@NotNull Player source, @NotNull Component sourceDisplayName, @NotNull Component message, @NotNull Audience viewer)
{ {
String text = PlexUtils.getTextFromComponent(message); String text = PlexUtils.cleanString(PlexUtils.getTextFromComponent(message));
Component component = Component.empty(); Component component = Component.empty();

View File

@ -1,5 +1,6 @@
package dev.plex.util; package dev.plex.util;
import com.google.common.base.CharMatcher;
import dev.plex.Plex; import dev.plex.Plex;
import dev.plex.PlexBase; import dev.plex.PlexBase;
import dev.plex.storage.StorageType; import dev.plex.storage.StorageType;
@ -229,4 +230,9 @@ public class PlexUtils implements PlexBase
pl.sendMessage(component); pl.sendMessage(component);
}); });
} }
public static String cleanString(String input)
{
return CharMatcher.ascii().retainFrom(input);
}
} }