diff --git a/api/src/main/java/me/filoghost/holographicdisplays/api/beta/HolographicDisplaysAPI.java b/api/src/main/java/me/filoghost/holographicdisplays/api/beta/HolographicDisplaysAPI.java index 2a8d42ff..eb489a5c 100644 --- a/api/src/main/java/me/filoghost/holographicdisplays/api/beta/HolographicDisplaysAPI.java +++ b/api/src/main/java/me/filoghost/holographicdisplays/api/beta/HolographicDisplaysAPI.java @@ -13,7 +13,6 @@ import me.filoghost.holographicdisplays.api.beta.placeholder.GlobalPlaceholderRe import me.filoghost.holographicdisplays.api.beta.placeholder.IndividualPlaceholder; import me.filoghost.holographicdisplays.api.beta.placeholder.IndividualPlaceholderFactory; import me.filoghost.holographicdisplays.api.beta.placeholder.IndividualPlaceholderReplacementSupplier; -import me.filoghost.holographicdisplays.api.beta.placeholder.RegisteredPlaceholder; import org.bukkit.Location; import org.bukkit.plugin.Plugin; import org.jetbrains.annotations.NotNull; @@ -85,32 +84,32 @@ public interface HolographicDisplaysAPI { /** * @since 1 */ - RegisteredPlaceholder registerGlobalPlaceholder(@NotNull String identifier, int refreshIntervalTicks, @NotNull GlobalPlaceholderReplacementSupplier replacementSupplier); + void registerGlobalPlaceholder(@NotNull String identifier, int refreshIntervalTicks, @NotNull GlobalPlaceholderReplacementSupplier replacementSupplier); /** * @since 1 */ - RegisteredPlaceholder registerGlobalPlaceholder(@NotNull String identifier, @NotNull GlobalPlaceholder placeholder); + void registerGlobalPlaceholder(@NotNull String identifier, @NotNull GlobalPlaceholder placeholder); /** * @since 1 */ - RegisteredPlaceholder registerGlobalPlaceholderFactory(@NotNull String identifier, @NotNull GlobalPlaceholderFactory placeholderFactory); + void registerGlobalPlaceholderFactory(@NotNull String identifier, @NotNull GlobalPlaceholderFactory placeholderFactory); /** * @since 1 */ - RegisteredPlaceholder registerIndividualPlaceholder(@NotNull String identifier, int refreshIntervalTicks, @NotNull IndividualPlaceholderReplacementSupplier replacementSupplier); + void registerIndividualPlaceholder(@NotNull String identifier, int refreshIntervalTicks, @NotNull IndividualPlaceholderReplacementSupplier replacementSupplier); /** * @since 1 */ - RegisteredPlaceholder registerIndividualPlaceholder(@NotNull String identifier, @NotNull IndividualPlaceholder placeholder); + void registerIndividualPlaceholder(@NotNull String identifier, @NotNull IndividualPlaceholder placeholder); /** * @since 1 */ - RegisteredPlaceholder registerIndividualPlaceholderFactory(@NotNull String identifier, @NotNull IndividualPlaceholderFactory placeholderFactory); + void registerIndividualPlaceholderFactory(@NotNull String identifier, @NotNull IndividualPlaceholderFactory placeholderFactory); /** * @since 1 @@ -123,7 +122,7 @@ public interface HolographicDisplaysAPI { * @return a collection of placeholder identifiers * @since 1 */ - @NotNull Collection getRegisteredPlaceholders(); + @NotNull Collection getRegisteredPlaceholders(); /** * Unregisters a placeholder. diff --git a/api/src/main/java/me/filoghost/holographicdisplays/api/beta/placeholder/RegisteredPlaceholder.java b/api/src/main/java/me/filoghost/holographicdisplays/api/beta/placeholder/RegisteredPlaceholder.java deleted file mode 100644 index 1e9aed31..00000000 --- a/api/src/main/java/me/filoghost/holographicdisplays/api/beta/placeholder/RegisteredPlaceholder.java +++ /dev/null @@ -1,14 +0,0 @@ -/* - * Copyright (C) filoghost and contributors - * - * SPDX-License-Identifier: GPL-3.0-or-later - */ -package me.filoghost.holographicdisplays.api.beta.placeholder; - -import org.jetbrains.annotations.NotNull; - -public interface RegisteredPlaceholder { - - @NotNull String getIdentifier(); - -} diff --git a/plugin/src/main/java/me/filoghost/holographicdisplays/plugin/api/current/DefaultHolographicDisplaysAPI.java b/plugin/src/main/java/me/filoghost/holographicdisplays/plugin/api/current/DefaultHolographicDisplaysAPI.java index 4176b1b8..84b29e56 100644 --- a/plugin/src/main/java/me/filoghost/holographicdisplays/plugin/api/current/DefaultHolographicDisplaysAPI.java +++ b/plugin/src/main/java/me/filoghost/holographicdisplays/plugin/api/current/DefaultHolographicDisplaysAPI.java @@ -15,7 +15,6 @@ import me.filoghost.holographicdisplays.api.beta.placeholder.GlobalPlaceholderRe import me.filoghost.holographicdisplays.api.beta.placeholder.IndividualPlaceholder; import me.filoghost.holographicdisplays.api.beta.placeholder.IndividualPlaceholderFactory; import me.filoghost.holographicdisplays.api.beta.placeholder.IndividualPlaceholderReplacementSupplier; -import me.filoghost.holographicdisplays.api.beta.placeholder.RegisteredPlaceholder; import me.filoghost.holographicdisplays.plugin.hologram.base.ImmutablePosition; import me.filoghost.holographicdisplays.plugin.placeholder.registry.PlaceholderRegistry; import org.bukkit.Location; @@ -55,53 +54,53 @@ class DefaultHolographicDisplaysAPI implements HolographicDisplaysAPI { } @Override - public RegisteredPlaceholder registerGlobalPlaceholder(@NotNull String identifier, int refreshIntervalTicks, @NotNull GlobalPlaceholderReplacementSupplier replacementSupplier) { + public void registerGlobalPlaceholder(@NotNull String identifier, int refreshIntervalTicks, @NotNull GlobalPlaceholderReplacementSupplier replacementSupplier) { checkIdentifier(identifier); Preconditions.checkArgument(refreshIntervalTicks >= 0, "refreshIntervalTicks should be positive"); Preconditions.notNull(replacementSupplier, "replacementSupplier"); - return placeholderRegistry.registerGlobalPlaceholder(plugin, identifier, refreshIntervalTicks, replacementSupplier); + placeholderRegistry.registerGlobalPlaceholder(plugin, identifier, refreshIntervalTicks, replacementSupplier); } @Override - public RegisteredPlaceholder registerGlobalPlaceholder(@NotNull String identifier, @NotNull GlobalPlaceholder placeholder) { + public void registerGlobalPlaceholder(@NotNull String identifier, @NotNull GlobalPlaceholder placeholder) { checkIdentifier(identifier); Preconditions.notNull(placeholder, "placeholder"); - return placeholderRegistry.registerGlobalPlaceholder(plugin, identifier, placeholder); + placeholderRegistry.registerGlobalPlaceholder(plugin, identifier, placeholder); } @Override - public RegisteredPlaceholder registerGlobalPlaceholderFactory(@NotNull String identifier, @NotNull GlobalPlaceholderFactory placeholderFactory) { + public void registerGlobalPlaceholderFactory(@NotNull String identifier, @NotNull GlobalPlaceholderFactory placeholderFactory) { checkIdentifier(identifier); Preconditions.notNull(placeholderFactory, "placeholderFactory"); - return placeholderRegistry.registerGlobalPlaceholderFactory(plugin, identifier, placeholderFactory); + placeholderRegistry.registerGlobalPlaceholderFactory(plugin, identifier, placeholderFactory); } @Override - public RegisteredPlaceholder registerIndividualPlaceholder(@NotNull String identifier, int refreshIntervalTicks, @NotNull IndividualPlaceholderReplacementSupplier replacementSupplier) { + public void registerIndividualPlaceholder(@NotNull String identifier, int refreshIntervalTicks, @NotNull IndividualPlaceholderReplacementSupplier replacementSupplier) { checkIdentifier(identifier); Preconditions.checkArgument(refreshIntervalTicks >= 0, "refreshIntervalTicks should be positive"); Preconditions.notNull(replacementSupplier, "replacementSupplier"); - return placeholderRegistry.registerIndividualPlaceholder(plugin, identifier, refreshIntervalTicks, replacementSupplier); + placeholderRegistry.registerIndividualPlaceholder(plugin, identifier, refreshIntervalTicks, replacementSupplier); } @Override - public RegisteredPlaceholder registerIndividualPlaceholder(@NotNull String identifier, @NotNull IndividualPlaceholder placeholder) { + public void registerIndividualPlaceholder(@NotNull String identifier, @NotNull IndividualPlaceholder placeholder) { checkIdentifier(identifier); Preconditions.notNull(placeholder, "placeholder"); - return placeholderRegistry.registerIndividualPlaceholder(plugin, identifier, placeholder); + placeholderRegistry.registerIndividualPlaceholder(plugin, identifier, placeholder); } @Override - public RegisteredPlaceholder registerIndividualPlaceholderFactory(@NotNull String identifier, @NotNull IndividualPlaceholderFactory placeholderFactory) { + public void registerIndividualPlaceholderFactory(@NotNull String identifier, @NotNull IndividualPlaceholderFactory placeholderFactory) { checkIdentifier(identifier); Preconditions.notNull(placeholderFactory, "placeholderFactory"); - return placeholderRegistry.registerIndividualPlaceholderFactory(plugin, identifier, placeholderFactory); + placeholderRegistry.registerIndividualPlaceholderFactory(plugin, identifier, placeholderFactory); } private void checkIdentifier(String identifier) { @@ -137,7 +136,7 @@ class DefaultHolographicDisplaysAPI implements HolographicDisplaysAPI { } @Override - public @NotNull Collection getRegisteredPlaceholders() { + public @NotNull Collection getRegisteredPlaceholders() { return placeholderRegistry.getRegisteredPlaceholders(plugin); } diff --git a/plugin/src/main/java/me/filoghost/holographicdisplays/plugin/placeholder/registry/PlaceholderExpansion.java b/plugin/src/main/java/me/filoghost/holographicdisplays/plugin/placeholder/registry/PlaceholderExpansion.java index cca26264..82afac8e 100644 --- a/plugin/src/main/java/me/filoghost/holographicdisplays/plugin/placeholder/registry/PlaceholderExpansion.java +++ b/plugin/src/main/java/me/filoghost/holographicdisplays/plugin/placeholder/registry/PlaceholderExpansion.java @@ -5,16 +5,14 @@ */ package me.filoghost.holographicdisplays.plugin.placeholder.registry; -import me.filoghost.holographicdisplays.api.beta.placeholder.RegisteredPlaceholder; import me.filoghost.holographicdisplays.plugin.placeholder.PlaceholderException; import me.filoghost.holographicdisplays.plugin.placeholder.PlaceholderIdentifier; import me.filoghost.holographicdisplays.plugin.placeholder.PluginName; import me.filoghost.holographicdisplays.plugin.placeholder.StandardPlaceholder; import org.bukkit.plugin.Plugin; -import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; -public abstract class PlaceholderExpansion implements RegisteredPlaceholder { +public abstract class PlaceholderExpansion { private final PluginName pluginName; private final PlaceholderIdentifier identifier; @@ -28,15 +26,10 @@ public abstract class PlaceholderExpansion implements RegisteredPlaceholder { return pluginName; } - public PlaceholderIdentifier getCaseInsensitiveIdentifier() { + public PlaceholderIdentifier getIdentifier() { return identifier; } - @Override - public @NotNull String getIdentifier() { - return identifier.toString(); - } - public abstract boolean isIndividual(); public abstract @Nullable StandardPlaceholder createPlaceholder(String argument) throws PlaceholderException; diff --git a/plugin/src/main/java/me/filoghost/holographicdisplays/plugin/placeholder/registry/PlaceholderRegistry.java b/plugin/src/main/java/me/filoghost/holographicdisplays/plugin/placeholder/registry/PlaceholderRegistry.java index 6489a171..17e3dc0d 100644 --- a/plugin/src/main/java/me/filoghost/holographicdisplays/plugin/placeholder/registry/PlaceholderRegistry.java +++ b/plugin/src/main/java/me/filoghost/holographicdisplays/plugin/placeholder/registry/PlaceholderRegistry.java @@ -9,6 +9,7 @@ import com.google.common.collect.HashBasedTable; import com.google.common.collect.Iterables; import com.google.common.collect.Table; import me.filoghost.fcommons.collection.CaseInsensitiveString; +import me.filoghost.fcommons.collection.CollectionUtils; import me.filoghost.fcommons.logging.Log; import me.filoghost.holographicdisplays.api.beta.placeholder.GlobalPlaceholder; import me.filoghost.holographicdisplays.api.beta.placeholder.GlobalPlaceholderFactory; @@ -16,16 +17,13 @@ import me.filoghost.holographicdisplays.api.beta.placeholder.GlobalPlaceholderRe import me.filoghost.holographicdisplays.api.beta.placeholder.IndividualPlaceholder; import me.filoghost.holographicdisplays.api.beta.placeholder.IndividualPlaceholderFactory; import me.filoghost.holographicdisplays.api.beta.placeholder.IndividualPlaceholderReplacementSupplier; -import me.filoghost.holographicdisplays.api.beta.placeholder.RegisteredPlaceholder; import me.filoghost.holographicdisplays.plugin.placeholder.PlaceholderIdentifier; import me.filoghost.holographicdisplays.plugin.placeholder.PlaceholderOccurrence; import me.filoghost.holographicdisplays.plugin.placeholder.PluginName; import org.bukkit.plugin.Plugin; import org.jetbrains.annotations.Nullable; -import java.util.ArrayList; import java.util.Collection; -import java.util.List; import java.util.concurrent.atomic.AtomicLong; public class PlaceholderRegistry { @@ -44,38 +42,36 @@ public class PlaceholderRegistry { return version.get(); } - public PlaceholderExpansion registerIndividualPlaceholder( + public void registerIndividualPlaceholder( Plugin plugin, String identifier, int refreshIntervalTicks, IndividualPlaceholderReplacementSupplier replacementSupplier) { - return registerIndividualPlaceholder(plugin, identifier, new SimpleIndividualPlaceholder(refreshIntervalTicks, replacementSupplier)); + registerIndividualPlaceholder(plugin, identifier, new SimpleIndividualPlaceholder(refreshIntervalTicks, replacementSupplier)); } - public PlaceholderExpansion registerIndividualPlaceholder(Plugin plugin, String identifier, IndividualPlaceholder placeholder) { - return registerIndividualPlaceholderFactory(plugin, identifier, (String argument) -> placeholder); + public void registerIndividualPlaceholder(Plugin plugin, String identifier, IndividualPlaceholder placeholder) { + registerIndividualPlaceholderFactory(plugin, identifier, (String argument) -> placeholder); } - public PlaceholderExpansion registerIndividualPlaceholderFactory(Plugin plugin, String identifier, IndividualPlaceholderFactory factory) { + public void registerIndividualPlaceholderFactory(Plugin plugin, String identifier, IndividualPlaceholderFactory factory) { PlaceholderExpansion expansion = new IndividualPlaceholderExpansion(plugin, identifier, factory); registerExpansion(expansion); - return expansion; } - public PlaceholderExpansion registerGlobalPlaceholder( + public void registerGlobalPlaceholder( Plugin plugin, String identifier, int refreshIntervalTicks, GlobalPlaceholderReplacementSupplier replacementSupplier) { - return registerGlobalPlaceholder(plugin, identifier, new SimpleGlobalPlaceholder(refreshIntervalTicks, replacementSupplier)); + registerGlobalPlaceholder(plugin, identifier, new SimpleGlobalPlaceholder(refreshIntervalTicks, replacementSupplier)); } - public PlaceholderExpansion registerGlobalPlaceholder(Plugin plugin, String identifier, GlobalPlaceholder placeholder) { - return registerGlobalPlaceholderFactory(plugin, identifier, (String argument) -> placeholder); + public void registerGlobalPlaceholder(Plugin plugin, String identifier, GlobalPlaceholder placeholder) { + registerGlobalPlaceholderFactory(plugin, identifier, (String argument) -> placeholder); } - public PlaceholderExpansion registerGlobalPlaceholderFactory(Plugin plugin, String identifier, GlobalPlaceholderFactory factory) { + public void registerGlobalPlaceholderFactory(Plugin plugin, String identifier, GlobalPlaceholderFactory factory) { PlaceholderExpansion expansion = new GlobalPlaceholderExpansion(plugin, identifier, factory); registerExpansion(expansion); - return expansion; } private void registerExpansion(PlaceholderExpansion expansion) { - placeholderExpansions.put(expansion.getCaseInsensitiveIdentifier(), expansion.getPluginName(), expansion); + placeholderExpansions.put(expansion.getIdentifier(), expansion.getPluginName(), expansion); version.incrementAndGet(); } @@ -111,10 +107,11 @@ public class PlaceholderRegistry { return result; } - public List getRegisteredPlaceholders(Plugin plugin) { + public Collection getRegisteredPlaceholders(Plugin plugin) { PluginName pluginName = new PluginName(plugin); - return new ArrayList<>(placeholderExpansions.column(pluginName).values()); + Collection pluginExpansions = placeholderExpansions.column(pluginName).values(); + return CollectionUtils.toImmutableSet(pluginExpansions, expansion -> expansion.getIdentifier().toString()); } public boolean isRegisteredIdentifier(Plugin plugin, String identifier) {