Skip to content

Commit

Permalink
Add ChatInjector to EternalTags
Browse files Browse the repository at this point in the history
  • Loading branch information
Oribuin committed Aug 13, 2024
1 parent 391c094 commit cbc208f
Show file tree
Hide file tree
Showing 4 changed files with 42 additions and 12 deletions.
6 changes: 6 additions & 0 deletions src/main/java/xyz/oribuin/eternaltags/EternalTags.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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();

Expand Down
33 changes: 33 additions & 0 deletions src/main/java/xyz/oribuin/eternaltags/listener/ChatListener.java
Original file line number Diff line number Diff line change
@@ -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);
}

}
12 changes: 0 additions & 12 deletions src/main/java/xyz/oribuin/eternaltags/manager/CommandManager.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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."),
Expand Down

0 comments on commit cbc208f

Please # to comment.