From d820c202c92e5fe78c51bb75dcdcadf3acf773e8 Mon Sep 17 00:00:00 2001 From: FeuSalamander Date: Tue, 21 Mar 2023 13:43:27 +0100 Subject: [PATCH] added the "vmessage.minimessage" permission --- README.md | 1 + .../java/me/feusalamander/vmessage/Listeners.java | 11 +++++++---- 2 files changed, 8 insertions(+), 4 deletions(-) diff --git a/README.md b/README.md index 0a6c11a..74e82e6 100644 --- a/README.md +++ b/README.md @@ -7,5 +7,6 @@ - LuckPerms Prefix and Suffix Support - Velocity only - Reload command: "/vmessage reload", permission: "vmessage.reload" +- MiniMessage support, if a player want to have MiniMessage in his message he needs to have the permission "vmessage.minimessage" - Global message command: "/sendall" - You can also check my Bukkit plugin https://github.com/FeuSalamander/MiniWalls diff --git a/src/main/java/me/feusalamander/vmessage/Listeners.java b/src/main/java/me/feusalamander/vmessage/Listeners.java index 422bccf..730609c 100644 --- a/src/main/java/me/feusalamander/vmessage/Listeners.java +++ b/src/main/java/me/feusalamander/vmessage/Listeners.java @@ -26,7 +26,7 @@ import java.util.Objects; import java.util.Optional; import java.util.SortedMap; import java.util.concurrent.CompletionException; -@SuppressWarnings("UnstableApiUsage") +@SuppressWarnings({"UnstableApiUsage", "deprecation"}) public final class Listeners { public static final LegacyComponentSerializer SERIALIZER = LegacyComponentSerializer.builder() .character('&') @@ -138,25 +138,28 @@ public final class Listeners { } public void message(final Player p, final String m) { + final boolean permission = p.hasPermission("vmessage.minimessage"); String message = configuration.getMessageFormat() .replace("#player#", p.getUsername()) - .replace("#message#", m) .replace("#server#", p.getCurrentServer().orElseThrow().getServerInfo().getName()); if (luckPermsAPI != null) { message = luckperms(message, p); } - final Component finalMessage; + if(permission)message = message.replace("#message#", m); + Component finalMessage; if (configuration.isMinimessageEnabled()) { finalMessage = mm.deserialize(message.replace("ยง", "")); } else { finalMessage = SERIALIZER.deserialize(message); } + if(!permission)finalMessage = finalMessage.replaceText("#message#", Component.text(m)); if(configuration.isAllEnabled()){ proxyServer.sendMessage(finalMessage); }else { + final Component FMessage = finalMessage; proxyServer.getAllServers().forEach(server -> { if (!Objects.equals(p.getCurrentServer().map(ServerConnection::getServerInfo).orElse(null), server.getServerInfo())) { - server.sendMessage(finalMessage); + server.sendMessage(FMessage); } }); }