Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@

</div>

> ⚠ **This plugin requires PlaceholderAPI and Vault to run!**
> ⚠ **This plugin requires Vault to run!**

## 🌌 Preview:

Expand All @@ -21,7 +21,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
Expand Down
Original file line number Diff line number Diff line change
@@ -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 {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;
Expand All @@ -36,9 +38,15 @@ public ChatFormatterPlugin(Plugin plugin) {

PluginConfig pluginConfig = configManager.getPluginConfig();

this.placeholderRegistry = new PlaceholderRegistry();
PlaceholderAPIInitializer.initialize(server, this.placeholderRegistry);
this.placeholderRegistry.addReplacer(new ConfiguredReplacer(pluginConfig));
if (server.getPluginManager().isPluginEnabled("PlaceholderAPI")) {
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);
Expand All @@ -64,6 +72,7 @@ public void close() {
}

@Override
@Nullable
public PlaceholderRegistry getPlaceholderRegistry() {
return this.placeholderRegistry;
}
Expand Down
Original file line number Diff line number Diff line change
@@ -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;
Expand All @@ -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 {

Expand Down Expand Up @@ -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;
Expand All @@ -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);

Expand Down
Loading