From a189aa8eda211e67f145e50fb3562c60e5122e9d Mon Sep 17 00:00:00 2001 From: George Date: Sun, 12 May 2024 22:45:59 +0100 Subject: [PATCH 1/2] Make PlaceholderAPI optional --- README.md | 4 ++-- .../java/com/eternalcode/formatter/ChatFormatterPlugin.java | 4 +++- chatformatter-paper-plugin/build.gradle.kts | 3 ++- 3 files changed, 7 insertions(+), 4 deletions(-) diff --git a/README.md b/README.md index ae8cc275..4713905f 100644 --- a/README.md +++ b/README.md @@ -14,7 +14,7 @@ -> ⚠ **This plugin requires PlaceholderAPI and Vault to run!** +> ⚠ **This plugin requires Vault to run!** ## Preview: ![1](assets/gif/ChatFormatterHoverPlayerInfo.gif) @@ -22,7 +22,7 @@ ## Features: -- PlaceholderAPI Support +- [PlaceholderAPI](https://github.com/PlaceholderAPI/PlaceholderAPI) Support - [MiniMessages Support](https://docs.adventure.kyori.net/minimessage/format.html) with Legacy Colors Support! - Template System - Custom Placeholders System diff --git a/chatformatter-core/src/main/java/com/eternalcode/formatter/ChatFormatterPlugin.java b/chatformatter-core/src/main/java/com/eternalcode/formatter/ChatFormatterPlugin.java index f5a10b24..bf4e87d0 100644 --- a/chatformatter-core/src/main/java/com/eternalcode/formatter/ChatFormatterPlugin.java +++ b/chatformatter-core/src/main/java/com/eternalcode/formatter/ChatFormatterPlugin.java @@ -40,7 +40,9 @@ public ChatFormatterPlugin(Plugin plugin) { this.placeholderRegistry = new PlaceholderRegistry(); this.placeholderRegistry.stack(pluginConfig); - this.placeholderRegistry.playerStack(new PlaceholderAPIStack()); + if (server.getPluginManager().isPluginEnabled("PlaceholderAPI")) { + this.placeholderRegistry.playerStack(new PlaceholderAPIStack()); + } this.templateService = new TemplateService(pluginConfig); this.rankProvider = new VaultRankProvider(server); UpdaterService updaterService = new UpdaterService(plugin.getDescription()); diff --git a/chatformatter-paper-plugin/build.gradle.kts b/chatformatter-paper-plugin/build.gradle.kts index 5f537994..6c856865 100644 --- a/chatformatter-paper-plugin/build.gradle.kts +++ b/chatformatter-paper-plugin/build.gradle.kts @@ -12,7 +12,8 @@ bukkit { prefix = "ChatFormatter" author = "EternalCodeTeam" name = "ChatFormatter" - depend = listOf("PlaceholderAPI", "Vault") + depend = listOf("Vault") + softDepend = listOf("PlaceholderAPI") version = "${project.version}" commands { From 33789c7f79d4cb72718539494804157c6f78fb33 Mon Sep 17 00:00:00 2001 From: Jakubk15 <77227023+Jakubk15@users.noreply.github.com> Date: Mon, 16 Feb 2026 22:05:40 +0100 Subject: [PATCH 2/2] Update on master --- .../formatter/ChatFormatterApi.java | 2 +- .../formatter/ChatFormatterPlugin.java | 11 +++++++-- .../formatter/ChatHandlerImpl.java | 23 +++++++++++-------- 3 files changed, 24 insertions(+), 12 deletions(-) diff --git a/chatformatter-core/src/main/java/com/eternalcode/formatter/ChatFormatterApi.java b/chatformatter-core/src/main/java/com/eternalcode/formatter/ChatFormatterApi.java index 806ff2ae..babe0afd 100644 --- a/chatformatter-core/src/main/java/com/eternalcode/formatter/ChatFormatterApi.java +++ b/chatformatter-core/src/main/java/com/eternalcode/formatter/ChatFormatterApi.java @@ -1,8 +1,8 @@ package com.eternalcode.formatter; +import com.eternalcode.formatter.placeholder.PlaceholderRegistry; import com.eternalcode.formatter.rank.ChatRankProvider; import com.eternalcode.formatter.template.TemplateService; -import com.eternalcode.formatter.placeholder.PlaceholderRegistry; public interface ChatFormatterApi { diff --git a/chatformatter-core/src/main/java/com/eternalcode/formatter/ChatFormatterPlugin.java b/chatformatter-core/src/main/java/com/eternalcode/formatter/ChatFormatterPlugin.java index 788984be..025cbdc7 100644 --- a/chatformatter-core/src/main/java/com/eternalcode/formatter/ChatFormatterPlugin.java +++ b/chatformatter-core/src/main/java/com/eternalcode/formatter/ChatFormatterPlugin.java @@ -3,8 +3,8 @@ import com.eternalcode.formatter.config.ConfigManager; import com.eternalcode.formatter.config.PluginConfig; import com.eternalcode.formatter.placeholder.ConfiguredReplacer; -import com.eternalcode.formatter.placeholderapi.PlaceholderAPIInitializer; import com.eternalcode.formatter.placeholder.PlaceholderRegistry; +import com.eternalcode.formatter.placeholderapi.PlaceholderAPIInitializer; import com.eternalcode.formatter.rank.ChatRankProvider; import com.eternalcode.formatter.rank.VaultInitializer; import com.eternalcode.formatter.template.TemplateService; @@ -17,11 +17,13 @@ import org.bstats.bukkit.Metrics; import org.bukkit.Server; import org.bukkit.plugin.Plugin; +import org.jspecify.annotations.Nullable; import java.util.concurrent.TimeUnit; public class ChatFormatterPlugin implements ChatFormatterApi { + @Nullable private final PlaceholderRegistry placeholderRegistry; private final TemplateService templateService; private final ChatRankProvider rankProvider; @@ -40,7 +42,11 @@ public ChatFormatterPlugin(Plugin plugin) { this.placeholderRegistry = new PlaceholderRegistry(); PlaceholderAPIInitializer.initialize(server, this.placeholderRegistry); this.placeholderRegistry.addReplacer(new ConfiguredReplacer(pluginConfig)); - } + plugin.getLogger().info("PlaceholderAPI integration enabled"); + } else { + this.placeholderRegistry = null; + plugin.getLogger().info("PlaceholderAPI not found - running without placeholder support"); + } this.templateService = new TemplateService(pluginConfig); this.rankProvider = VaultInitializer.initialize(server); @@ -66,6 +72,7 @@ public void close() { } @Override + @Nullable public PlaceholderRegistry getPlaceholderRegistry() { return this.placeholderRegistry; } diff --git a/chatformatter-core/src/main/java/com/eternalcode/formatter/ChatHandlerImpl.java b/chatformatter-core/src/main/java/com/eternalcode/formatter/ChatHandlerImpl.java index 0b82fb04..76a5c2d5 100644 --- a/chatformatter-core/src/main/java/com/eternalcode/formatter/ChatHandlerImpl.java +++ b/chatformatter-core/src/main/java/com/eternalcode/formatter/ChatHandlerImpl.java @@ -1,15 +1,11 @@ package com.eternalcode.formatter; import com.eternalcode.formatter.adventure.AdventureUrlPostProcessor; -import java.util.Optional; -import net.kyori.adventure.text.serializer.json.JSONOptions; -import static net.kyori.adventure.text.serializer.legacy.LegacyComponentSerializer.legacySection; - import com.eternalcode.formatter.adventure.TextColorTagResolver; import com.eternalcode.formatter.legacy.Legacy; +import com.eternalcode.formatter.placeholder.PlaceholderRegistry; import com.eternalcode.formatter.rank.ChatRankProvider; import com.eternalcode.formatter.template.TemplateService; -import com.eternalcode.formatter.placeholder.PlaceholderRegistry; import com.google.common.collect.ImmutableMap; import net.kyori.adventure.text.Component; import net.kyori.adventure.text.format.NamedTextColor; @@ -19,11 +15,16 @@ import net.kyori.adventure.text.minimessage.tag.resolver.TagResolver; import net.kyori.adventure.text.minimessage.tag.standard.StandardTags; import net.kyori.adventure.text.serializer.gson.GsonComponentSerializer; +import net.kyori.adventure.text.serializer.json.JSONOptions; import org.bukkit.entity.Player; +import org.jetbrains.annotations.Nullable; import java.util.ArrayList; import java.util.List; import java.util.Map; +import java.util.Optional; + +import static net.kyori.adventure.text.serializer.legacy.LegacyComponentSerializer.legacySection; class ChatHandlerImpl implements ChatHandler { @@ -83,10 +84,11 @@ class ChatHandlerImpl implements ChatHandler { private final ChatSettings settings; private final ChatRankProvider rankProvider; + @Nullable private final PlaceholderRegistry placeholderRegistry; private final TemplateService templateService; - ChatHandlerImpl(MiniMessage miniMessage, ChatSettings settings, ChatRankProvider rankProvider, PlaceholderRegistry placeholderRegistry, TemplateService templateService) { + ChatHandlerImpl(MiniMessage miniMessage, ChatSettings settings, ChatRankProvider rankProvider, @Nullable PlaceholderRegistry placeholderRegistry, TemplateService templateService) { this.miniMessage = miniMessage; this.settings = settings; this.rankProvider = rankProvider; @@ -102,9 +104,12 @@ public ChatRenderedMessage process(ChatMessage chatMessage) { String format = this.settings.getRawFormat(this.rankProvider.getRank(sender)); format = this.templateService.applyTemplates(format); - format = viewer.isEmpty() - ? this.placeholderRegistry.format(format, sender) - : this.placeholderRegistry.format(format, sender, viewer.get()); + + if (this.placeholderRegistry != null) { + format = viewer.isEmpty() + ? this.placeholderRegistry.format(format, sender) + : this.placeholderRegistry.format(format, sender, viewer.get()); + } format = Legacy.legacyToAdventure(format);