Add createHologram with HologramPosition

This commit is contained in:
filoghost 2021-08-23 16:20:29 +02:00
parent ca5644153e
commit dba767dd79
3 changed files with 22 additions and 0 deletions

View File

@ -6,6 +6,7 @@
package me.filoghost.holographicdisplays.api;
import me.filoghost.holographicdisplays.api.hologram.Hologram;
import me.filoghost.holographicdisplays.api.hologram.HologramPosition;
import me.filoghost.holographicdisplays.api.internal.HolographicDisplaysAPIProvider;
import me.filoghost.holographicdisplays.api.placeholder.PlaceholderReplacer;
import org.bukkit.Location;
@ -64,6 +65,8 @@ public interface HolographicDisplaysAPI {
*/
@NotNull Hologram createHologram(@NotNull Location location);
@NotNull Hologram createHologram(@NotNull HologramPosition position);
/**
* Returns all the active holograms. A hologram is no longer active after {@link Hologram#delete()} is invoked.
*

View File

@ -8,6 +8,7 @@ package me.filoghost.holographicdisplays.plugin.api.current;
import me.filoghost.fcommons.Preconditions;
import me.filoghost.holographicdisplays.api.HolographicDisplaysAPI;
import me.filoghost.holographicdisplays.api.hologram.Hologram;
import me.filoghost.holographicdisplays.api.hologram.HologramPosition;
import me.filoghost.holographicdisplays.api.placeholder.PlaceholderReplacer;
import me.filoghost.holographicdisplays.plugin.hologram.api.APIHologramManager;
import me.filoghost.holographicdisplays.plugin.hologram.base.BaseHologramPosition;
@ -39,6 +40,15 @@ class DefaultHolographicDisplaysAPI implements HolographicDisplaysAPI {
return apiHologramManager.createHologram(new BaseHologramPosition(location), plugin);
}
@Override
public @NotNull Hologram createHologram(@NotNull HologramPosition position) {
Preconditions.notNull(position, "position");
Preconditions.notNull(position.getWorldName(), "position world name");
Preconditions.checkMainThread("async hologram creation");
return apiHologramManager.createHologram(new BaseHologramPosition(position), plugin);
}
@Override
public void registerPlaceholder(@NotNull String identifier, int refreshIntervalTicks, @NotNull PlaceholderReplacer replacer) {
Preconditions.notEmpty(identifier, "identifier");

View File

@ -38,6 +38,15 @@ public class BaseHologramPosition implements HologramPosition {
this.z = location.getZ();
}
public BaseHologramPosition(@NotNull HologramPosition position) {
Preconditions.notNull(position, "position");
Preconditions.notNull(position.getWorldName(), "position's worldName");
this.worldName = position.getWorldName();
this.x = position.getX();
this.y = position.getY();
this.z = position.getZ();
}
@Override
public @NotNull String getWorldName() {
return worldName;