Expand API

This commit is contained in:
filoghost 2021-09-25 12:15:56 +02:00
parent e8b2239c47
commit 6f6a214ecd
2 changed files with 86 additions and 6 deletions

View File

@ -7,7 +7,12 @@ package me.filoghost.holographicdisplays.api;
import me.filoghost.holographicdisplays.api.hologram.Hologram;
import me.filoghost.holographicdisplays.api.internal.HolographicDisplaysAPIProvider;
import me.filoghost.holographicdisplays.api.placeholder.GlobalPlaceholder;
import me.filoghost.holographicdisplays.api.placeholder.GlobalPlaceholderFactory;
import me.filoghost.holographicdisplays.api.placeholder.GlobalPlaceholderReplacementSupplier;
import me.filoghost.holographicdisplays.api.placeholder.IndividualPlaceholder;
import me.filoghost.holographicdisplays.api.placeholder.IndividualPlaceholderFactory;
import me.filoghost.holographicdisplays.api.placeholder.IndividualPlaceholderReplacementSupplier;
import me.filoghost.holographicdisplays.api.placeholder.RegisteredPlaceholder;
import org.bukkit.Location;
import org.bukkit.plugin.Plugin;
@ -80,7 +85,32 @@ public interface HolographicDisplaysAPI {
/**
* @since 1
*/
void registerPlaceholder(@NotNull String identifier, int refreshIntervalTicks, @NotNull GlobalPlaceholderReplacementSupplier replacementSupplier);
void registerGlobalPlaceholder(@NotNull String identifier, int refreshIntervalTicks, @NotNull GlobalPlaceholderReplacementSupplier replacementSupplier);
/**
* @since 1
*/
void registerGlobalPlaceholder(@NotNull String identifier, @NotNull GlobalPlaceholder placeholder);
/**
* @since 1
*/
void registerGlobalPlaceholderFactory(@NotNull String identifier, @NotNull GlobalPlaceholderFactory placeholderFactory);
/**
* @since 1
*/
void registerIndividualPlaceholder(@NotNull String identifier, int refreshIntervalTicks, @NotNull IndividualPlaceholderReplacementSupplier replacementSupplier);
/**
* @since 1
*/
void registerIndividualPlaceholder(@NotNull String identifier, @NotNull IndividualPlaceholder placeholder);
/**
* @since 1
*/
void registerIndividualPlaceholderFactory(@NotNull String identifier, @NotNull IndividualPlaceholderFactory placeholderFactory);
/**
* @since 1

View File

@ -9,7 +9,12 @@ import me.filoghost.fcommons.Preconditions;
import me.filoghost.holographicdisplays.api.HolographicDisplaysAPI;
import me.filoghost.holographicdisplays.api.hologram.Hologram;
import me.filoghost.holographicdisplays.api.Position;
import me.filoghost.holographicdisplays.api.placeholder.GlobalPlaceholder;
import me.filoghost.holographicdisplays.api.placeholder.GlobalPlaceholderFactory;
import me.filoghost.holographicdisplays.api.placeholder.GlobalPlaceholderReplacementSupplier;
import me.filoghost.holographicdisplays.api.placeholder.IndividualPlaceholder;
import me.filoghost.holographicdisplays.api.placeholder.IndividualPlaceholderFactory;
import me.filoghost.holographicdisplays.api.placeholder.IndividualPlaceholderReplacementSupplier;
import me.filoghost.holographicdisplays.api.placeholder.RegisteredPlaceholder;
import me.filoghost.holographicdisplays.plugin.hologram.base.ImmutablePosition;
import me.filoghost.holographicdisplays.plugin.placeholder.registry.PlaceholderRegistry;
@ -50,17 +55,62 @@ class DefaultHolographicDisplaysAPI implements HolographicDisplaysAPI {
}
@Override
public void registerPlaceholder(@NotNull String identifier, int refreshIntervalTicks, @NotNull GlobalPlaceholderReplacementSupplier replacementSupplier) {
Preconditions.notEmpty(identifier, "identifier");
for (char c : identifier.toCharArray()) {
Preconditions.checkArgument(isValidIdentifierCharacter(c), "identifier contains invalid character '" + c + "'");
}
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");
placeholderRegistry.registerGlobalPlaceholder(plugin, identifier, refreshIntervalTicks, replacementSupplier);
}
@Override
public void registerGlobalPlaceholder(@NotNull String identifier, @NotNull GlobalPlaceholder placeholder) {
checkIdentifier(identifier);
Preconditions.notNull(placeholder, "placeholder");
placeholderRegistry.registerGlobalPlaceholder(plugin, identifier, placeholder);
}
@Override
public void registerGlobalPlaceholderFactory(@NotNull String identifier, @NotNull GlobalPlaceholderFactory placeholderFactory) {
checkIdentifier(identifier);
Preconditions.notNull(placeholderFactory, "placeholderFactory");
placeholderRegistry.registerGlobalPlaceholderFactory(plugin, identifier, placeholderFactory);
}
@Override
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");
placeholderRegistry.registerIndividualPlaceholder(plugin, identifier, refreshIntervalTicks, replacementSupplier);
}
@Override
public void registerIndividualPlaceholder(@NotNull String identifier, @NotNull IndividualPlaceholder placeholder) {
checkIdentifier(identifier);
Preconditions.notNull(placeholder, "placeholder");
placeholderRegistry.registerIndividualPlaceholder(plugin, identifier, placeholder);
}
@Override
public void registerIndividualPlaceholderFactory(@NotNull String identifier, @NotNull IndividualPlaceholderFactory placeholderFactory) {
checkIdentifier(identifier);
Preconditions.notNull(placeholderFactory, "placeholderFactory");
placeholderRegistry.registerIndividualPlaceholderFactory(plugin, identifier, placeholderFactory);
}
private void checkIdentifier(String identifier) {
Preconditions.notEmpty(identifier, "identifier");
for (char c : identifier.toCharArray()) {
Preconditions.checkArgument(isValidIdentifierCharacter(c), "identifier contains invalid character '" + c + "'");
}
}
private boolean isValidIdentifierCharacter(char c) {
return ('a' <= c && c <= 'z')
|| ('A' <= c && c <= 'Z')