Directly implement RegisteredPlaceholder

This commit is contained in:
filoghost 2021-09-25 16:30:04 +02:00
parent 8a80c063b7
commit 2b062f35bf
3 changed files with 11 additions and 14 deletions

View File

@ -5,8 +5,10 @@
*/
package me.filoghost.holographicdisplays.api.placeholder;
import org.jetbrains.annotations.NotNull;
public interface RegisteredPlaceholder {
String getIdentifier();
@NotNull String getIdentifier();
}

View File

@ -11,30 +11,30 @@ import me.filoghost.holographicdisplays.plugin.placeholder.StandardPlaceholder;
import me.filoghost.holographicdisplays.plugin.placeholder.parsing.PlaceholderIdentifier;
import me.filoghost.holographicdisplays.plugin.placeholder.parsing.PluginName;
import org.bukkit.plugin.Plugin;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
public abstract class PlaceholderExpansion {
public abstract class PlaceholderExpansion implements RegisteredPlaceholder {
private final PluginName pluginName;
private final PlaceholderIdentifier identifier;
private final RegisteredPlaceholder registeredPlaceholder;
public PlaceholderExpansion(Plugin plugin, String identifier) {
this.pluginName = new PluginName(plugin);
this.identifier = new PlaceholderIdentifier(identifier);
this.registeredPlaceholder = identifier::toString;
}
public PluginName getPluginName() {
return pluginName;
}
public PlaceholderIdentifier getIdentifier() {
public PlaceholderIdentifier getCaseInsensitiveIdentifier() {
return identifier;
}
public RegisteredPlaceholder asRegisteredPlaceholder() {
return registeredPlaceholder;
@Override
public @NotNull String getIdentifier() {
return identifier.toString();
}
public abstract boolean isIndividual();

View File

@ -68,7 +68,7 @@ public class PlaceholderRegistry {
}
private void registerExpansion(PlaceholderExpansion expansion) {
placeholderExpansions.put(expansion.getIdentifier(), expansion.getPluginName(), expansion);
placeholderExpansions.put(expansion.getCaseInsensitiveIdentifier(), expansion.getPluginName(), expansion);
version.incrementAndGet();
}
@ -101,13 +101,8 @@ public class PlaceholderRegistry {
public List<RegisteredPlaceholder> getRegisteredPlaceholders(Plugin plugin) {
PluginName pluginName = new PluginName(plugin);
List<RegisteredPlaceholder> identifiers = new ArrayList<>();
for (PlaceholderExpansion expansion : placeholderExpansions.column(pluginName).values()) {
identifiers.add(expansion.asRegisteredPlaceholder());
}
return identifiers;
return new ArrayList<>(placeholderExpansions.column(pluginName).values());
}
public boolean isRegisteredIdentifier(Plugin plugin, String identifier) {