From 6d6f4467d66dbac77c1bf5fbd2ffdf075e1cc1ed Mon Sep 17 00:00:00 2001 From: AkatGabrielGoncalves Date: Sun, 17 Jul 2022 19:15:30 -0300 Subject: [PATCH 1/2] Allow for nested placeholders by following placeholderAPI method of % first then curly braces for nested --- src/main/java/mineverse/Aust1n46/chat/utilities/Format.java | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/main/java/mineverse/Aust1n46/chat/utilities/Format.java b/src/main/java/mineverse/Aust1n46/chat/utilities/Format.java index 099bbda3..b8acdabb 100644 --- a/src/main/java/mineverse/Aust1n46/chat/utilities/Format.java +++ b/src/main/java/mineverse/Aust1n46/chat/utilities/Format.java @@ -45,7 +45,7 @@ public class Format { private static final Pattern LEGACY_CHAT_COLOR_PATTERN = Pattern.compile( "(? Date: Sun, 17 Jul 2022 20:08:00 -0300 Subject: [PATCH 2/2] replace all setBracketPlaceholders to setPlaceholders --- .../mineverse/Aust1n46/chat/MineverseChat.java | 6 +++--- .../chat/command/chat/VentureChatGui.java | 2 +- .../Aust1n46/chat/command/message/Message.java | 18 +++++++++--------- .../Aust1n46/chat/command/message/Reply.java | 18 +++++++++--------- .../Aust1n46/chat/listeners/ChatListener.java | 16 ++++++++-------- .../chat/listeners/CommandListener.java | 2 +- .../Aust1n46/chat/utilities/Format.java | 4 ++-- 7 files changed, 33 insertions(+), 33 deletions(-) diff --git a/src/main/java/mineverse/Aust1n46/chat/MineverseChat.java b/src/main/java/mineverse/Aust1n46/chat/MineverseChat.java index a0b693e4..c2c9c634 100644 --- a/src/main/java/mineverse/Aust1n46/chat/MineverseChat.java +++ b/src/main/java/mineverse/Aust1n46/chat/MineverseChat.java @@ -998,7 +998,7 @@ public void run() { sendPluginMessage(stream); return; } - p.getPlayer().sendMessage(Format.FormatStringAll(PlaceholderAPI.setBracketPlaceholders(p.getPlayer(), send.replaceAll("receiver_", ""))) + msg); + p.getPlayer().sendMessage(Format.FormatStringAll(PlaceholderAPI.setPlaceholders(p.getPlayer(), send.replaceAll("receiver_", ""))) + msg); if(p.hasNotifications()) { Format.playMessageSound(p); } @@ -1015,8 +1015,8 @@ public void run() { out.writeUTF(p.getUUID().toString()); out.writeUTF(sender.toString()); out.writeUTF(sName); - out.writeUTF(Format.FormatStringAll(PlaceholderAPI.setBracketPlaceholders(p.getPlayer(), echo.replaceAll("receiver_", ""))) + msg); - out.writeUTF(Format.FormatStringAll(PlaceholderAPI.setBracketPlaceholders(p.getPlayer(), spy.replaceAll("receiver_", ""))) + msg); + out.writeUTF(Format.FormatStringAll(PlaceholderAPI.setPlaceholders(p.getPlayer(), echo.replaceAll("receiver_", ""))) + msg); + out.writeUTF(Format.FormatStringAll(PlaceholderAPI.setPlaceholders(p.getPlayer(), spy.replaceAll("receiver_", ""))) + msg); sendPluginMessage(stream); return; } diff --git a/src/main/java/mineverse/Aust1n46/chat/command/chat/VentureChatGui.java b/src/main/java/mineverse/Aust1n46/chat/command/chat/VentureChatGui.java index 3e06ccb3..93fbefcd 100644 --- a/src/main/java/mineverse/Aust1n46/chat/command/chat/VentureChatGui.java +++ b/src/main/java/mineverse/Aust1n46/chat/command/chat/VentureChatGui.java @@ -115,7 +115,7 @@ private void openInventory(MineverseChatPlayer mcp, MineverseChatPlayer target, ItemMeta gMeta = gStack.getItemMeta(); String displayName = g.getText().replace("{player_name}", target.getName()).replace("{channel}", channel.getName()).replace("{hash}", hash + ""); if (target.isOnline()) { - displayName = PlaceholderAPI.setBracketPlaceholders(target.getPlayer(), displayName); + displayName = PlaceholderAPI.setPlaceholders(target.getPlayer(), displayName); } gMeta.setDisplayName(Format.FormatStringAll(displayName)); List gLore = new ArrayList(); diff --git a/src/main/java/mineverse/Aust1n46/chat/command/message/Message.java b/src/main/java/mineverse/Aust1n46/chat/command/message/Message.java index 3b0abaad..b7f9d2e3 100644 --- a/src/main/java/mineverse/Aust1n46/chat/command/message/Message.java +++ b/src/main/java/mineverse/Aust1n46/chat/command/message/Message.java @@ -83,13 +83,13 @@ public boolean execute(CommandSender sender, String command, String[] args) { msg = Format.FormatString(msg); } - send = Format.FormatStringAll(PlaceholderAPI.setBracketPlaceholders(mcp.getPlayer(), plugin.getConfig().getString("tellformatfrom").replaceAll("sender_", ""))); - echo = Format.FormatStringAll(PlaceholderAPI.setBracketPlaceholders(mcp.getPlayer(), plugin.getConfig().getString("tellformatto").replaceAll("sender_", ""))); - spy = Format.FormatStringAll(PlaceholderAPI.setBracketPlaceholders(mcp.getPlayer(), plugin.getConfig().getString("tellformatspy").replaceAll("sender_", ""))); + send = Format.FormatStringAll(PlaceholderAPI.setPlaceholders(mcp.getPlayer(), plugin.getConfig().getString("tellformatfrom").replaceAll("sender_", ""))); + echo = Format.FormatStringAll(PlaceholderAPI.setPlaceholders(mcp.getPlayer(), plugin.getConfig().getString("tellformatto").replaceAll("sender_", ""))); + spy = Format.FormatStringAll(PlaceholderAPI.setPlaceholders(mcp.getPlayer(), plugin.getConfig().getString("tellformatspy").replaceAll("sender_", ""))); - send = Format.FormatStringAll(PlaceholderAPI.setBracketPlaceholders(player.getPlayer(), send.replaceAll("receiver_", ""))) + msg; - echo = Format.FormatStringAll(PlaceholderAPI.setBracketPlaceholders(player.getPlayer(), echo.replaceAll("receiver_", ""))) + msg; - spy = Format.FormatStringAll(PlaceholderAPI.setBracketPlaceholders(player.getPlayer(), spy.replaceAll("receiver_", ""))) + msg; + send = Format.FormatStringAll(PlaceholderAPI.setPlaceholders(player.getPlayer(), send.replaceAll("receiver_", ""))) + msg; + echo = Format.FormatStringAll(PlaceholderAPI.setPlaceholders(player.getPlayer(), echo.replaceAll("receiver_", ""))) + msg; + spy = Format.FormatStringAll(PlaceholderAPI.setPlaceholders(player.getPlayer(), spy.replaceAll("receiver_", ""))) + msg; player.setReplyPlayer(mcp.getUUID()); mcp.setReplyPlayer(player.getUUID()); @@ -182,11 +182,11 @@ private void sendBungeeCordMessage(MineverseChatPlayer mcp, String command, Stri msg = Format.FormatString(msg); } - String send = Format.FormatStringAll(PlaceholderAPI.setBracketPlaceholders(mcp.getPlayer(), plugin.getConfig().getString("tellformatfrom").replaceAll("sender_", ""))); - String echo = Format.FormatStringAll(PlaceholderAPI.setBracketPlaceholders(mcp.getPlayer(), plugin.getConfig().getString("tellformatto").replaceAll("sender_", ""))); + String send = Format.FormatStringAll(PlaceholderAPI.setPlaceholders(mcp.getPlayer(), plugin.getConfig().getString("tellformatfrom").replaceAll("sender_", ""))); + String echo = Format.FormatStringAll(PlaceholderAPI.setPlaceholders(mcp.getPlayer(), plugin.getConfig().getString("tellformatto").replaceAll("sender_", ""))); String spy = "VentureChat:NoSpy"; if (!mcp.getPlayer().hasPermission("venturechat.spy.override")) { - spy = Format.FormatStringAll(PlaceholderAPI.setBracketPlaceholders(mcp.getPlayer(), plugin.getConfig().getString("tellformatspy").replaceAll("sender_", ""))); + spy = Format.FormatStringAll(PlaceholderAPI.setPlaceholders(mcp.getPlayer(), plugin.getConfig().getString("tellformatspy").replaceAll("sender_", ""))); } try { out.writeUTF("Message"); diff --git a/src/main/java/mineverse/Aust1n46/chat/command/message/Reply.java b/src/main/java/mineverse/Aust1n46/chat/command/message/Reply.java index 986e1bf4..d5eba81c 100644 --- a/src/main/java/mineverse/Aust1n46/chat/command/message/Reply.java +++ b/src/main/java/mineverse/Aust1n46/chat/command/message/Reply.java @@ -73,13 +73,13 @@ public boolean execute(CommandSender sender, String command, String[] args) { } send = Format - .FormatStringAll(PlaceholderAPI.setBracketPlaceholders(mcp.getPlayer(), plugin.getConfig().getString("replyformatfrom").replaceAll("sender_", ""))); - echo = Format.FormatStringAll(PlaceholderAPI.setBracketPlaceholders(mcp.getPlayer(), plugin.getConfig().getString("replyformatto").replaceAll("sender_", ""))); - spy = Format.FormatStringAll(PlaceholderAPI.setBracketPlaceholders(mcp.getPlayer(), plugin.getConfig().getString("replyformatspy").replaceAll("sender_", ""))); + .FormatStringAll(PlaceholderAPI.setPlaceholders(mcp.getPlayer(), plugin.getConfig().getString("replyformatfrom").replaceAll("sender_", ""))); + echo = Format.FormatStringAll(PlaceholderAPI.setPlaceholders(mcp.getPlayer(), plugin.getConfig().getString("replyformatto").replaceAll("sender_", ""))); + spy = Format.FormatStringAll(PlaceholderAPI.setPlaceholders(mcp.getPlayer(), plugin.getConfig().getString("replyformatspy").replaceAll("sender_", ""))); - send = Format.FormatStringAll(PlaceholderAPI.setBracketPlaceholders(player.getPlayer(), send.replaceAll("receiver_", ""))) + msg; - echo = Format.FormatStringAll(PlaceholderAPI.setBracketPlaceholders(player.getPlayer(), echo.replaceAll("receiver_", ""))) + msg; - spy = Format.FormatStringAll(PlaceholderAPI.setBracketPlaceholders(player.getPlayer(), spy.replaceAll("receiver_", ""))) + msg; + send = Format.FormatStringAll(PlaceholderAPI.setPlaceholders(player.getPlayer(), send.replaceAll("receiver_", ""))) + msg; + echo = Format.FormatStringAll(PlaceholderAPI.setPlaceholders(player.getPlayer(), echo.replaceAll("receiver_", ""))) + msg; + spy = Format.FormatStringAll(PlaceholderAPI.setPlaceholders(player.getPlayer(), spy.replaceAll("receiver_", ""))) + msg; if (!mcp.getPlayer().hasPermission("venturechat.spy.override")) { for (MineverseChatPlayer p : MineverseChatAPI.getOnlineMineverseChatPlayers()) { @@ -128,11 +128,11 @@ private void sendBungeeCordReply(MineverseChatPlayer mcp, String[] args) { msg = Format.FormatString(msg); } - String send = Format.FormatStringAll(PlaceholderAPI.setBracketPlaceholders(mcp.getPlayer(), plugin.getConfig().getString("replyformatfrom").replaceAll("sender_", ""))); - String echo = Format.FormatStringAll(PlaceholderAPI.setBracketPlaceholders(mcp.getPlayer(), plugin.getConfig().getString("replyformatto").replaceAll("sender_", ""))); + String send = Format.FormatStringAll(PlaceholderAPI.setPlaceholders(mcp.getPlayer(), plugin.getConfig().getString("replyformatfrom").replaceAll("sender_", ""))); + String echo = Format.FormatStringAll(PlaceholderAPI.setPlaceholders(mcp.getPlayer(), plugin.getConfig().getString("replyformatto").replaceAll("sender_", ""))); String spy = "VentureChat:NoSpy"; if (!mcp.getPlayer().hasPermission("venturechat.spy.override")) { - spy = Format.FormatStringAll(PlaceholderAPI.setBracketPlaceholders(mcp.getPlayer(), plugin.getConfig().getString("replyformatspy").replaceAll("sender_", ""))); + spy = Format.FormatStringAll(PlaceholderAPI.setPlaceholders(mcp.getPlayer(), plugin.getConfig().getString("replyformatspy").replaceAll("sender_", ""))); } try { out.writeUTF("Message"); diff --git a/src/main/java/mineverse/Aust1n46/chat/listeners/ChatListener.java b/src/main/java/mineverse/Aust1n46/chat/listeners/ChatListener.java index e395c07b..6a758ef0 100644 --- a/src/main/java/mineverse/Aust1n46/chat/listeners/ChatListener.java +++ b/src/main/java/mineverse/Aust1n46/chat/listeners/ChatListener.java @@ -123,13 +123,13 @@ public void handleTrueAsyncPlayerChatEvent(AsyncPlayerChatEvent event) { } filtered = " " + filtered; - send = Format.FormatStringAll(PlaceholderAPI.setBracketPlaceholders(mcp.getPlayer(), plugin.getConfig().getString("tellformatfrom").replaceAll("sender_", ""))); - echo = Format.FormatStringAll(PlaceholderAPI.setBracketPlaceholders(mcp.getPlayer(), plugin.getConfig().getString("tellformatto").replaceAll("sender_", ""))); - spy = Format.FormatStringAll(PlaceholderAPI.setBracketPlaceholders(mcp.getPlayer(), plugin.getConfig().getString("tellformatspy").replaceAll("sender_", ""))); + send = Format.FormatStringAll(PlaceholderAPI.setPlaceholders(mcp.getPlayer(), plugin.getConfig().getString("tellformatfrom").replaceAll("sender_", ""))); + echo = Format.FormatStringAll(PlaceholderAPI.setPlaceholders(mcp.getPlayer(), plugin.getConfig().getString("tellformatto").replaceAll("sender_", ""))); + spy = Format.FormatStringAll(PlaceholderAPI.setPlaceholders(mcp.getPlayer(), plugin.getConfig().getString("tellformatspy").replaceAll("sender_", ""))); - send = Format.FormatStringAll(PlaceholderAPI.setBracketPlaceholders(tp.getPlayer(), send.replaceAll("receiver_", ""))) + filtered; - echo = Format.FormatStringAll(PlaceholderAPI.setBracketPlaceholders(tp.getPlayer(), echo.replaceAll("receiver_", ""))) + filtered; - spy = Format.FormatStringAll(PlaceholderAPI.setBracketPlaceholders(tp.getPlayer(), spy.replaceAll("receiver_", ""))) + filtered; + send = Format.FormatStringAll(PlaceholderAPI.setPlaceholders(tp.getPlayer(), send.replaceAll("receiver_", ""))) + filtered; + echo = Format.FormatStringAll(PlaceholderAPI.setPlaceholders(tp.getPlayer(), echo.replaceAll("receiver_", ""))) + filtered; + spy = Format.FormatStringAll(PlaceholderAPI.setPlaceholders(tp.getPlayer(), spy.replaceAll("receiver_", ""))) + filtered; if(!mcp.getPlayer().hasPermission("venturechat.spy.override")) { for(MineverseChatPlayer p : MineverseChatAPI.getOnlineMineverseChatPlayers()) { @@ -478,14 +478,14 @@ else if(!(mplayer.getFactionName().equals(mplayerp.getFactionName()))) { } if(curColor.equalsIgnoreCase("None")) { // Format the placeholders and their color codes to determine the last color code to use for the chat message color - chat = Format.getLastCode(Format.FormatStringAll(PlaceholderAPI.setBracketPlaceholders(mcp.getPlayer(), format))) + chat; + chat = Format.getLastCode(Format.FormatStringAll(PlaceholderAPI.setPlaceholders(mcp.getPlayer(), format))) + chat; } else { chat = curColor + chat; } String globalJSON = Format.convertToJson(mcp, format, chat); - format = Format.FormatStringAll(PlaceholderAPI.setBracketPlaceholders(mcp.getPlayer(), Format.FormatStringAll(format))); + format = Format.FormatStringAll(PlaceholderAPI.setPlaceholders(mcp.getPlayer(), Format.FormatStringAll(format))); String message = Format.stripColor(format + chat); // UTF-8 encoding issues. int hash = message.hashCode(); diff --git a/src/main/java/mineverse/Aust1n46/chat/listeners/CommandListener.java b/src/main/java/mineverse/Aust1n46/chat/listeners/CommandListener.java index 697c3844..e5e6fc88 100644 --- a/src/main/java/mineverse/Aust1n46/chat/listeners/CommandListener.java +++ b/src/main/java/mineverse/Aust1n46/chat/listeners/CommandListener.java @@ -165,7 +165,7 @@ public void InventoryClick(InventoryClickEvent e) { if (target != null) { command = command.replace("{player_name}", target.getName()); if (target.isOnline()) { - command = Format.FormatStringAll(PlaceholderAPI.setBracketPlaceholders(target.getPlayer(), command)); + command = Format.FormatStringAll(PlaceholderAPI.setPlaceholders(target.getPlayer(), command)); } } else { command = command.replace("{player_name}", "Discord_Message"); diff --git a/src/main/java/mineverse/Aust1n46/chat/utilities/Format.java b/src/main/java/mineverse/Aust1n46/chat/utilities/Format.java index b8acdabb..cab9c5f1 100644 --- a/src/main/java/mineverse/Aust1n46/chat/utilities/Format.java +++ b/src/main/java/mineverse/Aust1n46/chat/utilities/Format.java @@ -119,7 +119,7 @@ private static String convertPlaceholders(String s, JsonFormat format, Mineverse if (placeholder.contains(jsonAttribute.getName().replace("%", "").replace("%", ""))) { action = jsonAttribute.getClickAction(); text = Format.FormatStringAll( - PlaceholderAPI.setBracketPlaceholders(icp.getPlayer(), jsonAttribute.getClickText())); + PlaceholderAPI.setPlaceholders(icp.getPlayer(), jsonAttribute.getClickText())); for (String st : jsonAttribute.getHoverText()) { hover += Format.FormatStringAll(st) + "\n"; } @@ -127,7 +127,7 @@ private static String convertPlaceholders(String s, JsonFormat format, Mineverse } if(!hover.isEmpty()) { hover = Format.FormatStringAll( - PlaceholderAPI.setBracketPlaceholders(icp.getPlayer(), hover.substring(0, hover.length() - 1))); + PlaceholderAPI.setPlaceholders(icp.getPlayer(), hover.substring(0, hover.length() - 1))); } temp += convertToJsonColors(lastCode + formattedPlaceholder, ",\"clickEvent\":{\"action\":\"" + action + "\",\"value\":\"" + text