diff --git a/src/main/java/xyz/oribuin/eternaltags/EternalTags.java b/src/main/java/xyz/oribuin/eternaltags/EternalTags.java index f78c7cf..5ef3d66 100644 --- a/src/main/java/xyz/oribuin/eternaltags/EternalTags.java +++ b/src/main/java/xyz/oribuin/eternaltags/EternalTags.java @@ -6,6 +6,7 @@ import xyz.oribuin.eternaltags.gui.MenuProvider; import xyz.oribuin.eternaltags.hook.Expansion; import xyz.oribuin.eternaltags.listener.BungeeListener; +import xyz.oribuin.eternaltags.listener.ChatListener; import xyz.oribuin.eternaltags.listener.PlayerListeners; import xyz.oribuin.eternaltags.manager.CommandManager; import xyz.oribuin.eternaltags.manager.ConfigurationManager; @@ -44,6 +45,11 @@ public void enable() { // Register Plugin Listeners pluginManager.registerEvents(new PlayerListeners(), this); + // Enable Placeholder Formatting :-) + if (Setting.CHAT_PLACEHOLDERS.getBoolean()) { + pluginManager.registerEvents(new ChatListener(), this); + } + // Register Event Waiter eventWaiter = new EventWaiter(); diff --git a/src/main/java/xyz/oribuin/eternaltags/listener/ChatListener.java b/src/main/java/xyz/oribuin/eternaltags/listener/ChatListener.java new file mode 100644 index 0000000..8814d73 --- /dev/null +++ b/src/main/java/xyz/oribuin/eternaltags/listener/ChatListener.java @@ -0,0 +1,33 @@ +package xyz.oribuin.eternaltags.listener; + +import me.clip.placeholderapi.PlaceholderAPI; +import org.bukkit.entity.Player; +import org.bukkit.event.EventHandler; +import org.bukkit.event.EventPriority; +import org.bukkit.event.Listener; +import org.bukkit.event.player.AsyncPlayerChatEvent; + +import java.util.regex.Matcher; + +/** + * Adds PlaceholderAPI Support to the chat within the messages sent. + */ +@SuppressWarnings("deprecation") // thank you paper +public class ChatListener implements Listener { + + /** + * Thank you PacksGamingHD for creating the original code. + */ + @EventHandler(ignoreCancelled = true, priority = EventPriority.MONITOR) + public void onChat(AsyncPlayerChatEvent event) { + Player player = event.getPlayer(); + String format = event.getFormat(); + Matcher matcher = PlaceholderAPI.getBracketPlaceholderPattern().matcher(format); + if (!matcher.find()) return; // No placeholders found + + format = PlaceholderAPI.setBracketPlaceholders(player, format); + + event.setFormat(format); + } + +} diff --git a/src/main/java/xyz/oribuin/eternaltags/manager/CommandManager.java b/src/main/java/xyz/oribuin/eternaltags/manager/CommandManager.java index f323066..8f298ce 100644 --- a/src/main/java/xyz/oribuin/eternaltags/manager/CommandManager.java +++ b/src/main/java/xyz/oribuin/eternaltags/manager/CommandManager.java @@ -3,18 +3,6 @@ import dev.rosewood.rosegarden.RosePlugin; import dev.rosewood.rosegarden.command.framework.BaseRoseCommand; import dev.rosewood.rosegarden.manager.AbstractCommandManager; -import xyz.oribuin.eternaltags.command.impl.CategoriesCommand; -import xyz.oribuin.eternaltags.command.impl.ClearCommand; -import xyz.oribuin.eternaltags.command.impl.ConvertCommand; -import xyz.oribuin.eternaltags.command.impl.CreateCommand; -import xyz.oribuin.eternaltags.command.impl.DeleteCommand; -import xyz.oribuin.eternaltags.command.impl.EditCommand; -import xyz.oribuin.eternaltags.command.impl.FavoriteCommand; -import xyz.oribuin.eternaltags.command.impl.RandomCommand; -import xyz.oribuin.eternaltags.command.impl.ReloadCommand; -import xyz.oribuin.eternaltags.command.impl.SearchCommand; -import xyz.oribuin.eternaltags.command.impl.SetAllCommand; -import xyz.oribuin.eternaltags.command.impl.SetCommand; import xyz.oribuin.eternaltags.command.impl.TagsCommand; import java.util.List; diff --git a/src/main/java/xyz/oribuin/eternaltags/manager/ConfigurationManager.java b/src/main/java/xyz/oribuin/eternaltags/manager/ConfigurationManager.java index 5eb97ca..a5b0e62 100644 --- a/src/main/java/xyz/oribuin/eternaltags/manager/ConfigurationManager.java +++ b/src/main/java/xyz/oribuin/eternaltags/manager/ConfigurationManager.java @@ -32,6 +32,9 @@ public enum Setting implements RoseSetting { REMOVE_TAGS("remove-inaccessible-tags", false, "Should a tag be automatically removed if the player doesn't have permission to use it?"), // Formatting + CHAT_PLACEHOLDERS("chat-placeholders", false, "Should the plugin change the Chat Format to allow PlaceholderAPI placeholders to be used?", + "It is recommended to enable this if you are using EssentialsXChat or a chat plugin that does not support PlaceholderAPI.", + "It's not recommended for you to enable this if your chat plugin already supports PlaceholderAPI (Most do)."), FORMATTED_PLACEHOLDER("formatted-placeholder", "None", "The placeholder that will show when the player has no active tag."), TAG_UNLOCKED_FORMAT("tag-unlocked-format", "&a&lUnlocked", "The format that will show when the player has the tag unlocked."), TAG_LOCKED_FORMAT("tag-locked-format", "&c&lLocked", "The format that will show when the player has the tag locked."),