Skip to content

Commit

Permalink
Move papi dependency from config class (see revert) to ConfiguredPlac…
Browse files Browse the repository at this point in the history
…eholderAPIStack class.
  • Loading branch information
Rollczi committed May 29, 2024
1 parent 20d4242 commit d4cff2c
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 14 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import com.eternalcode.formatter.config.PluginConfig;
import com.eternalcode.formatter.legacy.LegacyPostProcessor;
import com.eternalcode.formatter.legacy.LegacyPreProcessor;
import com.eternalcode.formatter.placeholder.ConfiguredPlaceholderAPIStack;
import com.eternalcode.formatter.placeholder.PlaceholderAPIStack;
import com.eternalcode.formatter.placeholder.PlaceholderRegistry;
import com.eternalcode.formatter.rank.ChatRankProvider;
Expand Down Expand Up @@ -39,7 +40,7 @@ public ChatFormatterPlugin(Plugin plugin) {
PluginConfig pluginConfig = configManager.getPluginConfig();

this.placeholderRegistry = new PlaceholderRegistry();
this.placeholderRegistry.stack(pluginConfig);
this.placeholderRegistry.playerStack(new ConfiguredPlaceholderAPIStack(pluginConfig));
this.placeholderRegistry.playerStack(new PlaceholderAPIStack());
this.templateService = new TemplateService(pluginConfig);
this.rankProvider = new VaultRankProvider(server);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,12 @@
import com.google.common.collect.ImmutableList;
import com.google.common.collect.ImmutableMap;
import com.eternalcode.formatter.ChatSettings;
import com.eternalcode.formatter.placeholder.PlaceholderStack;
import net.dzikoysk.cdn.entity.Description;

import java.util.List;
import java.util.Map;

public class PluginConfig implements ChatSettings, PlaceholderStack, TemplateRepository {
public class PluginConfig implements ChatSettings, TemplateRepository {

@Description(" ")
@Description("# ____ _ _ _____ ChatFormatter _ _ ")
Expand Down Expand Up @@ -95,17 +94,6 @@ public String getRawFormat(String rank) {
return this.format.getOrDefault(rank, this.defaultFormat);
}

@Override
public String apply(String text) {
String value = text;

for (Map.Entry<String, String> entry : this.placeholders.entrySet()) {
value = value.replace(entry.getKey(), entry.getValue());
}

return value;
}

@Override
public List<Template> getTemplates() {
return this.templates;
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
package com.eternalcode.formatter.placeholder;

import com.eternalcode.formatter.config.PluginConfig;
import java.util.Map;
import me.clip.placeholderapi.PlaceholderAPI;
import org.bukkit.entity.Player;

public class ConfiguredPlaceholderAPIStack implements PlayerPlaceholderStack {

private final PluginConfig pluginConfig;

public ConfiguredPlaceholderAPIStack(PluginConfig pluginConfig) {
this.pluginConfig = pluginConfig;
}

@Override
public String apply(String text, Player target) {
String value = text;

value = PlaceholderAPI.setPlaceholders(target, value);

for (Map.Entry<String, String> entry : this.pluginConfig.placeholders.entrySet()) {
value = value.replace(entry.getKey(), entry.getValue());
}

return value;
}

}

0 comments on commit d4cff2c

Please sign in to comment.