mirror of
https://github.com/filoghost/HolographicDisplays.git
synced 2024-09-30 08:07:35 +02:00
Initial refactoring of the API
This commit is contained in:
parent
d8930febfc
commit
ff77738a51
@ -15,7 +15,9 @@ import org.bukkit.inventory.ItemStack;
|
||||
/**
|
||||
* An object made of various lines, that can be items or holograms.
|
||||
* Holographic lines appear as a nametag without any entity below.
|
||||
* To create one, please see {@link HologramsAPI#createHologram(org.bukkit.plugin.Plugin, Location)}.
|
||||
* To create one, please see {@link HolographicDisplaysAPI#createHologram(Location)}.
|
||||
*
|
||||
* @since 1
|
||||
*/
|
||||
public interface Hologram {
|
||||
|
||||
@ -24,6 +26,7 @@ public interface Hologram {
|
||||
*
|
||||
* @param text the content of the line, can be null for an empty line
|
||||
* @return the new TextLine appended
|
||||
* @since 1
|
||||
*/
|
||||
TextLine appendTextLine(String text);
|
||||
|
||||
@ -33,6 +36,7 @@ public interface Hologram {
|
||||
*
|
||||
* @param itemStack the content of the line
|
||||
* @return the new ItemLine appended
|
||||
* @since 1
|
||||
*/
|
||||
ItemLine appendItemLine(ItemStack itemStack);
|
||||
|
||||
@ -45,6 +49,7 @@ public interface Hologram {
|
||||
* @param text the content of the line, can be null for an empty line
|
||||
* @return the new TextLine inserted
|
||||
* @throws IndexOutOfBoundsException if the index is out of range (index < 0 || index >= size())
|
||||
* @since 1
|
||||
*/
|
||||
TextLine insertTextLine(int index, String text);
|
||||
|
||||
@ -57,6 +62,7 @@ public interface Hologram {
|
||||
* @param itemStack the content of the line
|
||||
* @return the new ItemLine inserted
|
||||
* @throws IndexOutOfBoundsException if the index is out of range (index < 0 || index >= size())
|
||||
* @since 1
|
||||
*/
|
||||
ItemLine insertItemLine(int index, ItemStack itemStack);
|
||||
|
||||
@ -67,6 +73,7 @@ public interface Hologram {
|
||||
* @param index the index of the line to retrieve.
|
||||
* @return the hologram line at the given index, can be an {@link ItemLine} or a {@link TextLine}.
|
||||
* @throws IndexOutOfBoundsException if the index is out of range (index < 0 || index >= size())
|
||||
* @since 1
|
||||
*/
|
||||
HologramLine getLine(int index);
|
||||
|
||||
@ -75,12 +82,15 @@ public interface Hologram {
|
||||
*
|
||||
* @param index the index of the line, that should be between 0 and size() - 1.
|
||||
* @throws IndexOutOfBoundsException if the index is out of range (index < 0 || index >= size())
|
||||
* @since 1
|
||||
*/
|
||||
void removeLine(int index);
|
||||
|
||||
|
||||
/**
|
||||
* Removes all the lines from this hologram.
|
||||
*
|
||||
* @since 1
|
||||
*/
|
||||
void clearLines();
|
||||
|
||||
@ -89,6 +99,7 @@ public interface Hologram {
|
||||
* Checks the amount of lines of the hologram.
|
||||
*
|
||||
* @return the amount of lines
|
||||
* @since 1
|
||||
*/
|
||||
int size();
|
||||
|
||||
@ -97,6 +108,7 @@ public interface Hologram {
|
||||
* The physical height of the hologram, counting all the lines. Since: v2.1.4
|
||||
*
|
||||
* @return the height of the hologram, counting all the lines and the gaps between them
|
||||
* @since 1
|
||||
*/
|
||||
double getHeight();
|
||||
|
||||
@ -105,6 +117,7 @@ public interface Hologram {
|
||||
* Teleports a hologram to the given location.
|
||||
*
|
||||
* @param location the new location
|
||||
* @since 1
|
||||
*/
|
||||
void teleport(Location location);
|
||||
|
||||
@ -117,6 +130,7 @@ public interface Hologram {
|
||||
* @param x the X coordinate
|
||||
* @param y the Y coordinate
|
||||
* @param z the Z coordinate
|
||||
* @since 1
|
||||
*/
|
||||
void teleport(World world, double x, double y, double z);
|
||||
|
||||
@ -124,6 +138,7 @@ public interface Hologram {
|
||||
* Returns the position of the hologram.
|
||||
*
|
||||
* @return the Location of the hologram
|
||||
* @since 1
|
||||
*/
|
||||
Location getLocation();
|
||||
|
||||
@ -131,6 +146,7 @@ public interface Hologram {
|
||||
* Returns the X coordinate.
|
||||
*
|
||||
* @return the X coordinate of the hologram
|
||||
* @since 1
|
||||
*/
|
||||
double getX();
|
||||
|
||||
@ -139,6 +155,7 @@ public interface Hologram {
|
||||
* Returns the Y coordinate.
|
||||
*
|
||||
* @return the Y coordinate of the hologram
|
||||
* @since 1
|
||||
*/
|
||||
double getY();
|
||||
|
||||
@ -147,6 +164,7 @@ public interface Hologram {
|
||||
* Returns the Z coordinate.
|
||||
*
|
||||
* @return the Z coordinate of the hologram
|
||||
* @since 1
|
||||
*/
|
||||
double getZ();
|
||||
|
||||
@ -155,6 +173,7 @@ public interface Hologram {
|
||||
* Returns the world.
|
||||
*
|
||||
* @return the world of the hologram
|
||||
* @since 1
|
||||
*/
|
||||
World getWorld();
|
||||
|
||||
@ -165,6 +184,7 @@ public interface Hologram {
|
||||
* Without the plugin, holograms will be always visible.
|
||||
*
|
||||
* @return the VisibilityManager of this hologram
|
||||
* @since 1
|
||||
*/
|
||||
VisibilityManager getVisibilityManager();
|
||||
|
||||
@ -173,6 +193,7 @@ public interface Hologram {
|
||||
* Returns when the hologram was created. Useful for removing old holograms.
|
||||
*
|
||||
* @return the timestamp of when the hologram was created, in milliseconds
|
||||
* @since 1
|
||||
*/
|
||||
long getCreationTimestamp();
|
||||
|
||||
@ -181,6 +202,7 @@ public interface Hologram {
|
||||
* This is false by default.
|
||||
*
|
||||
* @return if the hologram allows placeholders
|
||||
* @since 1
|
||||
*/
|
||||
boolean isAllowPlaceholders();
|
||||
|
||||
@ -189,6 +211,7 @@ public interface Hologram {
|
||||
* By default if will not track them.
|
||||
*
|
||||
* @param allowPlaceholders if the hologram should track placeholders
|
||||
* @since 1
|
||||
*/
|
||||
void setAllowPlaceholders(boolean allowPlaceholders);
|
||||
|
||||
@ -196,6 +219,8 @@ public interface Hologram {
|
||||
* Deletes this hologram. Editing or teleporting the hologram when deleted
|
||||
* will throw an exception. Lines will be automatically cleared.
|
||||
* You should remove all the references of the hologram after deletion.
|
||||
*
|
||||
* @since 1
|
||||
*/
|
||||
void delete();
|
||||
|
||||
@ -204,6 +229,7 @@ public interface Hologram {
|
||||
* Checks if a hologram was deleted.
|
||||
*
|
||||
* @return true if this hologram was deleted
|
||||
* @since 1
|
||||
*/
|
||||
boolean isDeleted();
|
||||
|
||||
|
@ -1,99 +0,0 @@
|
||||
/*
|
||||
* Copyright (C) filoghost and contributors
|
||||
*
|
||||
* SPDX-License-Identifier: GPL-3.0-or-later
|
||||
*/
|
||||
package me.filoghost.holographicdisplays.api;
|
||||
|
||||
import me.filoghost.holographicdisplays.api.internal.BackendAPI;
|
||||
import me.filoghost.holographicdisplays.api.placeholder.PlaceholderReplacer;
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.entity.Entity;
|
||||
import org.bukkit.plugin.Plugin;
|
||||
|
||||
import java.util.Collection;
|
||||
|
||||
/**
|
||||
* This the main class of the <b>Holographic Displays API</b>.
|
||||
* It provides methods to create holograms and to register custom placeholders.
|
||||
*/
|
||||
public class HologramsAPI {
|
||||
|
||||
|
||||
private HologramsAPI() {
|
||||
// No constructor needed.
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Creates a hologram at given location.
|
||||
*
|
||||
* @param plugin the plugin that creates it
|
||||
* @param source the location where it will appear
|
||||
* @return the new hologram created
|
||||
*/
|
||||
public static Hologram createHologram(Plugin plugin, Location source) {
|
||||
return BackendAPI.getImplementation().createHologram(plugin, source);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Finds all the holograms created by a given plugin.
|
||||
*
|
||||
* @param plugin the plugin to search for in holograms
|
||||
* @return the holograms created by a plugin. the Collection is a copy
|
||||
* and modifying it has no effect on the holograms.
|
||||
*/
|
||||
public static Collection<Hologram> getHolograms(Plugin plugin) {
|
||||
return BackendAPI.getImplementation().getHolograms(plugin);
|
||||
}
|
||||
|
||||
public static void registerPlaceholder(Plugin plugin, String identifier, int refreshIntervalTicks, PlaceholderReplacer replacer) {
|
||||
BackendAPI.getImplementation().registerPlaceholder(plugin, identifier, refreshIntervalTicks, replacer);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Returns all the placeholder identifiers registered by a given plugin.
|
||||
*
|
||||
* @param plugin the plugin to search for
|
||||
* @return a collection of placeholder identifiers registered by the plugin
|
||||
*/
|
||||
public static Collection<String> getRegisteredPlaceholders(Plugin plugin) {
|
||||
return BackendAPI.getImplementation().getRegisteredPlaceholders(plugin);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Unregister a placeholder created by a plugin.
|
||||
*
|
||||
* @param plugin the plugin that owns the placeholder
|
||||
* @param identifier the identifier of the placeholder to remove
|
||||
*/
|
||||
public static void unregisterPlaceholder(Plugin plugin, String identifier) {
|
||||
BackendAPI.getImplementation().unregisterPlaceholder(plugin, identifier);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Resets and removes all the placeholders registered by a plugin. This is useful
|
||||
* when you have configurable placeholders and you want to remove all of them.
|
||||
*
|
||||
* @param plugin the plugin that owns the placeholders
|
||||
*/
|
||||
public static void unregisterPlaceholders(Plugin plugin) {
|
||||
BackendAPI.getImplementation().unregisterPlaceholders(plugin);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Checks if an entity is part of a hologram.
|
||||
*
|
||||
* @param bukkitEntity the entity to check
|
||||
* @return true if the entity is a part of a hologram
|
||||
*/
|
||||
public static boolean isHologramEntity(Entity bukkitEntity) {
|
||||
return BackendAPI.getImplementation().isHologramEntity(bukkitEntity);
|
||||
}
|
||||
|
||||
}
|
@ -0,0 +1,104 @@
|
||||
/*
|
||||
* Copyright (C) filoghost and contributors
|
||||
*
|
||||
* SPDX-License-Identifier: GPL-3.0-or-later
|
||||
*/
|
||||
package me.filoghost.holographicdisplays.api;
|
||||
|
||||
import me.filoghost.holographicdisplays.api.internal.HolographicDisplaysAPIProvider;
|
||||
import me.filoghost.holographicdisplays.api.placeholder.PlaceholderReplacer;
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.entity.Entity;
|
||||
import org.bukkit.plugin.Plugin;
|
||||
|
||||
import java.util.Collection;
|
||||
|
||||
/**
|
||||
* Main entry point for accessing the Holographic Displays API.
|
||||
*
|
||||
* @since 1
|
||||
*/
|
||||
public interface HolographicDisplaysAPI {
|
||||
|
||||
/**
|
||||
* Returns the API version number, which is increased every time the API changes. This number is used to check if a
|
||||
* certain method or class (which may have been added later) is present or not.
|
||||
* <p>
|
||||
* All public API classes and methods are documented with the Javadoc tag {@code @since}, indicating in which API
|
||||
* version that element was introduced.
|
||||
* <p>
|
||||
* It can be used it to require a minimum version, as features may be added (rarely removed) in future versions. The
|
||||
* first version of the API is 1.
|
||||
* <p>
|
||||
* The API version is independent from the normal plugin version.
|
||||
*
|
||||
* @return the current API version
|
||||
* @since 1
|
||||
*/
|
||||
static int getVersion() {
|
||||
return 1;
|
||||
}
|
||||
|
||||
static HolographicDisplaysAPI get(Plugin plugin) {
|
||||
return HolographicDisplaysAPIProvider.getImplementation().getHolographicDisplaysAPI(plugin);
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates a hologram at given location.
|
||||
*
|
||||
* @param source the location where it will appear
|
||||
* @return the created hologram
|
||||
* @since 1
|
||||
*/
|
||||
Hologram createHologram(Location source);
|
||||
|
||||
/**
|
||||
* Returns all the active holograms. A hologram is no longer active after {@link Hologram#delete()} is invoked.
|
||||
*
|
||||
* @return an immutable collection of active holograms
|
||||
* @since 1
|
||||
*/
|
||||
Collection<Hologram> getHolograms();
|
||||
|
||||
/**
|
||||
* @since 1
|
||||
*/
|
||||
void registerPlaceholder(String identifier, int refreshIntervalTicks, PlaceholderReplacer replacer);
|
||||
|
||||
/**
|
||||
* Returns all the registered placeholder identifiers.
|
||||
*
|
||||
* @return a collection of placeholder identifiers
|
||||
* @since 1
|
||||
*/
|
||||
Collection<String> getRegisteredPlaceholders();
|
||||
|
||||
/**
|
||||
* Unregisters a placeholder.
|
||||
*
|
||||
* @param identifier the identifier of the placeholder to remove
|
||||
* @since 1
|
||||
*/
|
||||
void unregisterPlaceholder(String identifier);
|
||||
|
||||
/**
|
||||
* Resets and removes all the registered placeholders.
|
||||
* <p>
|
||||
* May be useful to invoke before registering all the placeholders of your plugin.
|
||||
*
|
||||
* @since 1
|
||||
*/
|
||||
void unregisterPlaceholders();
|
||||
|
||||
/**
|
||||
* Checks if an entity is part of a hologram.
|
||||
*
|
||||
* @param entity the entity to check
|
||||
* @return if the entity is part of a hologram
|
||||
* @since 1
|
||||
*/
|
||||
static boolean isHologramEntity(Entity entity) {
|
||||
return HolographicDisplaysAPIProvider.getImplementation().isHologramEntity(entity);
|
||||
}
|
||||
|
||||
}
|
@ -11,6 +11,8 @@ import org.bukkit.entity.Player;
|
||||
* This object is used to manage the visibility of a hologram.
|
||||
* It allows to hide/show the hologram to certain players, and the default behaviour
|
||||
* (when a hologram is not specifically being hidden/shown to a player) can be customized.
|
||||
*
|
||||
* @since 1
|
||||
*/
|
||||
public interface VisibilityManager {
|
||||
|
||||
@ -19,6 +21,7 @@ public interface VisibilityManager {
|
||||
* is true by default so the hologram is visible to everyone.
|
||||
*
|
||||
* @return if the hologram hologram is visible by default
|
||||
* @since 1
|
||||
*/
|
||||
boolean isVisibleByDefault();
|
||||
|
||||
@ -27,6 +30,7 @@ public interface VisibilityManager {
|
||||
* is true by default so the hologram is visible to everyone.
|
||||
*
|
||||
* @param visibleByDefault the new behaviour
|
||||
* @since 1
|
||||
*/
|
||||
void setVisibleByDefault(boolean visibleByDefault);
|
||||
|
||||
@ -35,6 +39,7 @@ public interface VisibilityManager {
|
||||
* This is persistent if the players goes offline.
|
||||
*
|
||||
* @param player the involved player
|
||||
* @since 1
|
||||
*/
|
||||
void showTo(Player player);
|
||||
|
||||
@ -43,6 +48,7 @@ public interface VisibilityManager {
|
||||
* This is persistent if the players goes offline.
|
||||
*
|
||||
* @param player the involved player
|
||||
* @since 1
|
||||
*/
|
||||
void hideTo(Player player);
|
||||
|
||||
@ -51,6 +57,7 @@ public interface VisibilityManager {
|
||||
*
|
||||
* @param player the involved player
|
||||
* @return if the player can see the hologram
|
||||
* @since 1
|
||||
*/
|
||||
boolean isVisibleTo(Player player);
|
||||
|
||||
@ -60,11 +67,14 @@ public interface VisibilityManager {
|
||||
* to reflect the value of {@link #isVisibleByDefault()}.
|
||||
*
|
||||
* @param player the involved player
|
||||
* @since 1
|
||||
*/
|
||||
void resetVisibility(Player player);
|
||||
|
||||
/**
|
||||
* Resets the visibility for all the players. See {@link #resetVisibility(Player)} for more details.
|
||||
*
|
||||
* @since 1
|
||||
*/
|
||||
void resetVisibilityAll();
|
||||
|
||||
|
@ -9,12 +9,15 @@ import org.bukkit.entity.Player;
|
||||
|
||||
/**
|
||||
* Interface to handle items being picked up by players.
|
||||
*
|
||||
* @since 1
|
||||
*/
|
||||
public interface PickupHandler {
|
||||
|
||||
/**
|
||||
* Called when a player picks up the item.
|
||||
* @param player the player who picked up the item
|
||||
* @since 1
|
||||
*/
|
||||
void onPickup(Player player);
|
||||
|
||||
|
@ -9,12 +9,15 @@ import org.bukkit.entity.Player;
|
||||
|
||||
/**
|
||||
* Interface to handle touch holograms.
|
||||
*
|
||||
* @since 1
|
||||
*/
|
||||
public interface TouchHandler {
|
||||
|
||||
/**
|
||||
* Called when a player interacts with the hologram (right click).
|
||||
* @param player the player who interacts
|
||||
* @since 1
|
||||
*/
|
||||
void onTouch(Player player);
|
||||
|
||||
|
@ -1,47 +0,0 @@
|
||||
/*
|
||||
* Copyright (C) filoghost and contributors
|
||||
*
|
||||
* SPDX-License-Identifier: GPL-3.0-or-later
|
||||
*/
|
||||
package me.filoghost.holographicdisplays.api.internal;
|
||||
|
||||
import me.filoghost.holographicdisplays.api.Hologram;
|
||||
import me.filoghost.holographicdisplays.api.placeholder.PlaceholderReplacer;
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.entity.Entity;
|
||||
import org.bukkit.plugin.Plugin;
|
||||
|
||||
import java.util.Collection;
|
||||
|
||||
public abstract class BackendAPI {
|
||||
|
||||
private static BackendAPI implementation;
|
||||
|
||||
public static void setImplementation(BackendAPI implementation) {
|
||||
BackendAPI.implementation = implementation;
|
||||
}
|
||||
|
||||
public static BackendAPI getImplementation() {
|
||||
if (implementation == null) {
|
||||
throw new IllegalStateException("No API implementation set. Is Holographic Displays enabled?");
|
||||
}
|
||||
|
||||
return implementation;
|
||||
}
|
||||
|
||||
public abstract Hologram createHologram(Plugin plugin, Location source);
|
||||
|
||||
public abstract Collection<Hologram> getHolograms(Plugin plugin);
|
||||
|
||||
public abstract void registerPlaceholder(Plugin plugin, String identifier, int refreshIntervalTicks, PlaceholderReplacer replacer);
|
||||
|
||||
public abstract Collection<String> getRegisteredPlaceholders(Plugin plugin);
|
||||
|
||||
public abstract void unregisterPlaceholder(Plugin plugin, String identifier);
|
||||
|
||||
public abstract void unregisterPlaceholders(Plugin plugin);
|
||||
|
||||
public abstract boolean isHologramEntity(Entity bukkitEntity);
|
||||
|
||||
|
||||
}
|
@ -0,0 +1,34 @@
|
||||
/*
|
||||
* Copyright (C) filoghost and contributors
|
||||
*
|
||||
* SPDX-License-Identifier: GPL-3.0-or-later
|
||||
*/
|
||||
package me.filoghost.holographicdisplays.api.internal;
|
||||
|
||||
import me.filoghost.holographicdisplays.api.HolographicDisplaysAPI;
|
||||
import org.bukkit.entity.Entity;
|
||||
import org.bukkit.plugin.Plugin;
|
||||
import org.jetbrains.annotations.ApiStatus.Internal;
|
||||
|
||||
@Internal
|
||||
public abstract class HolographicDisplaysAPIProvider {
|
||||
|
||||
private static HolographicDisplaysAPIProvider implementation;
|
||||
|
||||
public static void setImplementation(HolographicDisplaysAPIProvider implementation) {
|
||||
HolographicDisplaysAPIProvider.implementation = implementation;
|
||||
}
|
||||
|
||||
public static HolographicDisplaysAPIProvider getImplementation() {
|
||||
if (implementation == null) {
|
||||
throw new IllegalStateException("No API implementation set. Is Holographic Displays enabled?");
|
||||
}
|
||||
|
||||
return implementation;
|
||||
}
|
||||
|
||||
public abstract HolographicDisplaysAPI getHolographicDisplaysAPI(Plugin plugin);
|
||||
|
||||
public abstract boolean isHologramEntity(Entity entity);
|
||||
|
||||
}
|
@ -9,6 +9,8 @@ import me.filoghost.holographicdisplays.api.handler.PickupHandler;
|
||||
|
||||
/**
|
||||
* A line of a Hologram that can be picked up.
|
||||
*
|
||||
* @since 1
|
||||
*/
|
||||
public interface CollectableLine extends HologramLine {
|
||||
|
||||
@ -16,6 +18,7 @@ public interface CollectableLine extends HologramLine {
|
||||
* Sets the PickupHandler for this line.
|
||||
*
|
||||
* @param pickupHandler the new PickupHandler, can be null.
|
||||
* @since 1
|
||||
*/
|
||||
void setPickupHandler(PickupHandler pickupHandler);
|
||||
|
||||
@ -23,6 +26,7 @@ public interface CollectableLine extends HologramLine {
|
||||
* Returns the current PickupHandler of this line.
|
||||
*
|
||||
* @return the current PickupHandler, can be null.
|
||||
* @since 1
|
||||
*/
|
||||
PickupHandler getPickupHandler();
|
||||
|
||||
|
@ -9,6 +9,8 @@ import me.filoghost.holographicdisplays.api.Hologram;
|
||||
|
||||
/**
|
||||
* Interface to represent a line in a Hologram.
|
||||
*
|
||||
* @since 1
|
||||
*/
|
||||
public interface HologramLine {
|
||||
|
||||
@ -16,12 +18,15 @@ public interface HologramLine {
|
||||
* Returns the parent Hologram of this line.
|
||||
*
|
||||
* @return the parent Hologram.
|
||||
* @since 1
|
||||
*/
|
||||
Hologram getParent();
|
||||
|
||||
/**
|
||||
* Removes this line from the parent Hologram. Since: v2.0.1
|
||||
* Do not call if the Hologram has been deleted, an exception will be thrown.
|
||||
*
|
||||
* @since 1
|
||||
*/
|
||||
void removeLine();
|
||||
|
||||
|
@ -7,12 +7,16 @@ package me.filoghost.holographicdisplays.api.line;
|
||||
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
|
||||
/**
|
||||
* @since 1
|
||||
*/
|
||||
public interface ItemLine extends CollectableLine, TouchableLine {
|
||||
|
||||
/**
|
||||
* Returns the ItemStack of this ItemLine.
|
||||
*
|
||||
* @return the ItemStack if this ItemLine.
|
||||
* @since 1
|
||||
*/
|
||||
ItemStack getItemStack();
|
||||
|
||||
@ -20,6 +24,7 @@ public interface ItemLine extends CollectableLine, TouchableLine {
|
||||
* Sets the ItemStack for this ItemLine.
|
||||
*
|
||||
* @param itemStack the new item, should not be null.
|
||||
* @since 1
|
||||
*/
|
||||
void setItemStack(ItemStack itemStack);
|
||||
|
||||
|
@ -5,12 +5,16 @@
|
||||
*/
|
||||
package me.filoghost.holographicdisplays.api.line;
|
||||
|
||||
/**
|
||||
* @since 1
|
||||
*/
|
||||
public interface TextLine extends TouchableLine {
|
||||
|
||||
/**
|
||||
* Returns the current text of this TextLine.
|
||||
*
|
||||
* @return the current text of this line.
|
||||
* @since 1
|
||||
*/
|
||||
String getText();
|
||||
|
||||
@ -18,6 +22,7 @@ public interface TextLine extends TouchableLine {
|
||||
* Sets the text of this TextLine.
|
||||
*
|
||||
* @param text the new text of this line.
|
||||
* @since 1
|
||||
*/
|
||||
void setText(String text);
|
||||
|
||||
|
@ -9,6 +9,8 @@ import me.filoghost.holographicdisplays.api.handler.TouchHandler;
|
||||
|
||||
/**
|
||||
* A line of a Hologram that can be touched (right click).
|
||||
*
|
||||
* @since 1
|
||||
*/
|
||||
public interface TouchableLine extends HologramLine {
|
||||
|
||||
@ -16,6 +18,7 @@ public interface TouchableLine extends HologramLine {
|
||||
* Sets the TouchHandler for this line.
|
||||
*
|
||||
* @param touchHandler the new TouchHandler, can be null.
|
||||
* @since 1
|
||||
*/
|
||||
void setTouchHandler(TouchHandler touchHandler);
|
||||
|
||||
@ -23,6 +26,7 @@ public interface TouchableLine extends HologramLine {
|
||||
* Returns the current TouchHandler of this line.
|
||||
*
|
||||
* @return the current TouchHandler, can be null.
|
||||
* @since 1
|
||||
*/
|
||||
TouchHandler getTouchHandler();
|
||||
|
||||
|
@ -5,8 +5,14 @@
|
||||
*/
|
||||
package me.filoghost.holographicdisplays.api.placeholder;
|
||||
|
||||
/**
|
||||
* @since 1
|
||||
*/
|
||||
public interface Placeholder extends PlaceholderReplacer {
|
||||
|
||||
/**
|
||||
* @since 1
|
||||
*/
|
||||
int getRefreshIntervalTicks();
|
||||
|
||||
}
|
||||
|
@ -7,8 +7,14 @@ package me.filoghost.holographicdisplays.api.placeholder;
|
||||
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
/**
|
||||
* @since 1
|
||||
*/
|
||||
public interface PlaceholderFactory {
|
||||
|
||||
|
||||
/**
|
||||
* @since 1
|
||||
*/
|
||||
Placeholder getPlaceholder(@Nullable String argument);
|
||||
|
||||
}
|
||||
|
@ -9,6 +9,8 @@ import org.jetbrains.annotations.Nullable;
|
||||
|
||||
/**
|
||||
* Simple callback to provide a placeholder replacement.
|
||||
*
|
||||
* @since 1
|
||||
*/
|
||||
@FunctionalInterface
|
||||
public interface PlaceholderReplacer {
|
||||
@ -21,6 +23,7 @@ public interface PlaceholderReplacer {
|
||||
* <b>Warning</b>: this method should be performance efficient, as it may be invoked often.
|
||||
*
|
||||
* @return the placeholder replacement
|
||||
* @since 1
|
||||
*/
|
||||
String getReplacement(@Nullable String argument);
|
||||
|
||||
|
@ -6,7 +6,7 @@
|
||||
package me.filoghost.example.deathholograms;
|
||||
|
||||
import me.filoghost.holographicdisplays.api.Hologram;
|
||||
import me.filoghost.holographicdisplays.api.HologramsAPI;
|
||||
import me.filoghost.holographicdisplays.api.HolographicDisplaysAPI;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.ChatColor;
|
||||
import org.bukkit.event.EventHandler;
|
||||
@ -20,6 +20,8 @@ import java.time.format.DateTimeFormatter;
|
||||
public class DeathHolograms extends JavaPlugin implements Listener {
|
||||
|
||||
private static final DateTimeFormatter TIME_FORMATTER = DateTimeFormatter.ofPattern("H:mm");
|
||||
|
||||
private HolographicDisplaysAPI holographicDisplaysAPI;
|
||||
|
||||
@Override
|
||||
public void onEnable() {
|
||||
@ -30,13 +32,14 @@ public class DeathHolograms extends JavaPlugin implements Listener {
|
||||
return;
|
||||
}
|
||||
|
||||
holographicDisplaysAPI = HolographicDisplaysAPI.get(this);
|
||||
Bukkit.getPluginManager().registerEvents(this, this);
|
||||
}
|
||||
|
||||
|
||||
@EventHandler
|
||||
public void onPlayerDeath(PlayerDeathEvent event) {
|
||||
Hologram hologram = HologramsAPI.createHologram(this, event.getEntity().getEyeLocation());
|
||||
Hologram hologram = holographicDisplaysAPI.createHologram(event.getEntity().getEyeLocation());
|
||||
|
||||
hologram.appendTextLine(ChatColor.RED + "Player " + ChatColor.GOLD + event.getEntity().getName() + ChatColor.RED + " died here!");
|
||||
hologram.appendTextLine(ChatColor.GRAY + "Time of death: " + TIME_FORMATTER.format(Instant.now()));
|
||||
|
@ -6,7 +6,7 @@
|
||||
package me.filoghost.example.powerups;
|
||||
|
||||
import me.filoghost.holographicdisplays.api.Hologram;
|
||||
import me.filoghost.holographicdisplays.api.HologramsAPI;
|
||||
import me.filoghost.holographicdisplays.api.HolographicDisplaysAPI;
|
||||
import me.filoghost.holographicdisplays.api.line.ItemLine;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.ChatColor;
|
||||
@ -23,7 +23,9 @@ import org.bukkit.potion.PotionEffect;
|
||||
import org.bukkit.potion.PotionEffectType;
|
||||
|
||||
public class PowerUps extends JavaPlugin implements Listener {
|
||||
|
||||
|
||||
private HolographicDisplaysAPI holographicDisplaysAPI;
|
||||
|
||||
@Override
|
||||
public void onEnable() {
|
||||
if (!Bukkit.getPluginManager().isPluginEnabled("HolographicDisplays")) {
|
||||
@ -32,7 +34,8 @@ public class PowerUps extends JavaPlugin implements Listener {
|
||||
this.setEnabled(false);
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
holographicDisplaysAPI = HolographicDisplaysAPI.get(this);
|
||||
Bukkit.getPluginManager().registerEvents(this, this);
|
||||
}
|
||||
|
||||
@ -45,7 +48,7 @@ public class PowerUps extends JavaPlugin implements Listener {
|
||||
event.setDroppedExp(0);
|
||||
|
||||
// Spawn the floating item with a label.
|
||||
Hologram hologram = HologramsAPI.createHologram(this, event.getEntity().getLocation().add(0.0, 0.9, 0.0));
|
||||
Hologram hologram = holographicDisplaysAPI.createHologram(event.getEntity().getLocation().add(0.0, 0.9, 0.0));
|
||||
hologram.appendTextLine(ChatColor.AQUA + "" + ChatColor.BOLD + "Speed PowerUp");
|
||||
ItemLine icon = hologram.appendItemLine(new ItemStack(Material.SUGAR));
|
||||
|
||||
|
@ -8,7 +8,6 @@ package com.gmail.filoghost.holograms.api;
|
||||
import com.gmail.filoghost.holograms.api.adapter.FloatingItemAdapter;
|
||||
import com.gmail.filoghost.holograms.api.adapter.HologramAdapter;
|
||||
import me.filoghost.fcommons.Preconditions;
|
||||
import me.filoghost.holographicdisplays.api.HologramsAPI;
|
||||
import me.filoghost.holographicdisplays.api.line.ItemLine;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.ChatColor;
|
||||
@ -49,7 +48,7 @@ public class HolographicDisplaysAPI {
|
||||
|
||||
validateLocation(source);
|
||||
|
||||
me.filoghost.holographicdisplays.api.Hologram hologram = HologramsAPI.createHologram(plugin, source);
|
||||
me.filoghost.holographicdisplays.api.Hologram hologram = me.filoghost.holographicdisplays.api.HolographicDisplaysAPI.get(plugin).createHologram(source);
|
||||
for (String line : lines) {
|
||||
hologram.appendTextLine(line);
|
||||
}
|
||||
@ -63,7 +62,7 @@ public class HolographicDisplaysAPI {
|
||||
validateLocation(source);
|
||||
validateItem(itemstack);
|
||||
|
||||
me.filoghost.holographicdisplays.api.Hologram hologram = HologramsAPI.createHologram(plugin, source);
|
||||
me.filoghost.holographicdisplays.api.Hologram hologram = me.filoghost.holographicdisplays.api.HolographicDisplaysAPI.get(plugin).createHologram(source);
|
||||
ItemLine itemLine = hologram.appendItemLine(itemstack);
|
||||
return new FloatingItemAdapter(plugin, hologram, itemLine);
|
||||
}
|
||||
@ -81,7 +80,7 @@ public class HolographicDisplaysAPI {
|
||||
|
||||
validateLocation(source);
|
||||
|
||||
me.filoghost.holographicdisplays.api.Hologram hologram = HologramsAPI.createHologram(plugin, source);
|
||||
me.filoghost.holographicdisplays.api.Hologram hologram = me.filoghost.holographicdisplays.api.HolographicDisplaysAPI.get(plugin).createHologram(source);
|
||||
|
||||
hologram.getVisibilityManager().setVisibleByDefault(false);
|
||||
if (whoCanSee != null) {
|
||||
@ -111,7 +110,7 @@ public class HolographicDisplaysAPI {
|
||||
validateLocation(source);
|
||||
validateItem(itemstack);
|
||||
|
||||
me.filoghost.holographicdisplays.api.Hologram hologram = HologramsAPI.createHologram(plugin, source);
|
||||
me.filoghost.holographicdisplays.api.Hologram hologram = me.filoghost.holographicdisplays.api.HolographicDisplaysAPI.get(plugin).createHologram(source);
|
||||
ItemLine itemLine = hologram.appendItemLine(itemstack);
|
||||
|
||||
hologram.getVisibilityManager().setVisibleByDefault(false);
|
||||
@ -142,7 +141,7 @@ public class HolographicDisplaysAPI {
|
||||
|
||||
@Deprecated
|
||||
public static boolean isHologramEntity(Entity bukkitEntity) {
|
||||
return HologramsAPI.isHologramEntity(bukkitEntity);
|
||||
return me.filoghost.holographicdisplays.api.HolographicDisplaysAPI.isHologramEntity(bukkitEntity);
|
||||
}
|
||||
|
||||
private static void validateLocation(Location loc) {
|
||||
|
@ -7,33 +7,30 @@ package me.filoghost.holographicdisplays;
|
||||
|
||||
import me.filoghost.fcommons.Preconditions;
|
||||
import me.filoghost.holographicdisplays.api.Hologram;
|
||||
import me.filoghost.holographicdisplays.api.internal.BackendAPI;
|
||||
import me.filoghost.holographicdisplays.api.HolographicDisplaysAPI;
|
||||
import me.filoghost.holographicdisplays.api.placeholder.PlaceholderReplacer;
|
||||
import me.filoghost.holographicdisplays.core.nms.NMSManager;
|
||||
import me.filoghost.holographicdisplays.object.api.APIHologramManager;
|
||||
import me.filoghost.holographicdisplays.placeholder.registry.PlaceholderRegistry;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.entity.Entity;
|
||||
import org.bukkit.plugin.Plugin;
|
||||
|
||||
import java.util.Collection;
|
||||
|
||||
public class DefaultBackendAPI extends BackendAPI {
|
||||
public class DefaultHolographicDisplaysAPI implements HolographicDisplaysAPI {
|
||||
|
||||
private final Plugin plugin;
|
||||
private final APIHologramManager apiHologramManager;
|
||||
private final NMSManager nmsManager;
|
||||
private final PlaceholderRegistry placeholderRegistry;
|
||||
|
||||
public DefaultBackendAPI(APIHologramManager apiHologramManager, NMSManager nmsManager, PlaceholderRegistry placeholderRegistry) {
|
||||
public DefaultHolographicDisplaysAPI(Plugin plugin, APIHologramManager apiHologramManager, PlaceholderRegistry placeholderRegistry) {
|
||||
this.plugin = plugin;
|
||||
this.apiHologramManager = apiHologramManager;
|
||||
this.nmsManager = nmsManager;
|
||||
this.placeholderRegistry = placeholderRegistry;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Hologram createHologram(Plugin plugin, Location source) {
|
||||
Preconditions.notNull(plugin, "plugin");
|
||||
public Hologram createHologram(Location source) {
|
||||
Preconditions.notNull(source, "source");
|
||||
Preconditions.notNull(source.getWorld(), "source's world");
|
||||
Preconditions.checkState(Bukkit.isPrimaryThread(), "Async hologram creation");
|
||||
@ -42,7 +39,7 @@ public class DefaultBackendAPI extends BackendAPI {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void registerPlaceholder(Plugin plugin, String identifier, int refreshIntervalTicks, PlaceholderReplacer replacer) {
|
||||
public void registerPlaceholder(String identifier, int refreshIntervalTicks, PlaceholderReplacer replacer) {
|
||||
Preconditions.notNull(identifier, "identifier");
|
||||
Preconditions.checkArgument(refreshIntervalTicks >= 0, "refreshIntervalTicks should be positive");
|
||||
Preconditions.notNull(replacer, "replacer");
|
||||
@ -51,33 +48,24 @@ public class DefaultBackendAPI extends BackendAPI {
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isHologramEntity(Entity bukkitEntity) {
|
||||
Preconditions.notNull(bukkitEntity, "bukkitEntity");
|
||||
return nmsManager.isNMSEntityBase(bukkitEntity);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Collection<Hologram> getHolograms(Plugin plugin) {
|
||||
Preconditions.notNull(plugin, "plugin");
|
||||
public Collection<Hologram> getHolograms() {
|
||||
return apiHologramManager.getHologramsByPlugin(plugin);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Collection<String> getRegisteredPlaceholders(Plugin plugin) {
|
||||
Preconditions.notNull(plugin, "plugin");
|
||||
public Collection<String> getRegisteredPlaceholders() {
|
||||
return placeholderRegistry.getRegisteredIdentifiers(plugin);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void unregisterPlaceholder(Plugin plugin, String identifier) {
|
||||
Preconditions.notNull(plugin, "plugin");
|
||||
public void unregisterPlaceholder(String identifier) {
|
||||
Preconditions.notNull(identifier, "identifier");
|
||||
|
||||
placeholderRegistry.unregister(plugin, identifier);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void unregisterPlaceholders(Plugin plugin) {
|
||||
Preconditions.notNull(plugin, "plugin");
|
||||
public void unregisterPlaceholders() {
|
||||
placeholderRegistry.unregisterAll(plugin);
|
||||
}
|
||||
|
@ -0,0 +1,51 @@
|
||||
/*
|
||||
* Copyright (C) filoghost and contributors
|
||||
*
|
||||
* SPDX-License-Identifier: GPL-3.0-or-later
|
||||
*/
|
||||
package me.filoghost.holographicdisplays;
|
||||
|
||||
import me.filoghost.fcommons.Preconditions;
|
||||
import me.filoghost.holographicdisplays.api.HolographicDisplaysAPI;
|
||||
import me.filoghost.holographicdisplays.api.internal.HolographicDisplaysAPIProvider;
|
||||
import me.filoghost.holographicdisplays.core.nms.NMSManager;
|
||||
import me.filoghost.holographicdisplays.object.api.APIHologramManager;
|
||||
import me.filoghost.holographicdisplays.placeholder.registry.PlaceholderRegistry;
|
||||
import org.bukkit.entity.Entity;
|
||||
import org.bukkit.plugin.Plugin;
|
||||
|
||||
import java.util.Map;
|
||||
import java.util.WeakHashMap;
|
||||
|
||||
public class DefaultHolographicDisplaysAPIProvider extends HolographicDisplaysAPIProvider {
|
||||
|
||||
private final APIHologramManager apiHologramManager;
|
||||
private final NMSManager nmsManager;
|
||||
private final PlaceholderRegistry placeholderRegistry;
|
||||
|
||||
// Avoid creating a new instance every time a plugin requires it
|
||||
private final Map<Plugin, HolographicDisplaysAPI> apiCache;
|
||||
|
||||
public DefaultHolographicDisplaysAPIProvider(APIHologramManager apiHologramManager, NMSManager nmsManager, PlaceholderRegistry placeholderRegistry) {
|
||||
this.apiHologramManager = apiHologramManager;
|
||||
this.nmsManager = nmsManager;
|
||||
this.placeholderRegistry = placeholderRegistry;
|
||||
this.apiCache = new WeakHashMap<>();
|
||||
}
|
||||
|
||||
@Override
|
||||
public HolographicDisplaysAPI getHolographicDisplaysAPI(Plugin plugin) {
|
||||
Preconditions.notNull(plugin, "plugin");
|
||||
|
||||
return apiCache.computeIfAbsent(plugin, pluginKey ->
|
||||
new DefaultHolographicDisplaysAPI(pluginKey, apiHologramManager, placeholderRegistry));
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isHologramEntity(Entity entity) {
|
||||
Preconditions.notNull(entity, "entity");
|
||||
|
||||
return nmsManager.isNMSEntityBase(entity);
|
||||
}
|
||||
|
||||
}
|
@ -9,7 +9,7 @@ import me.filoghost.fcommons.FCommonsPlugin;
|
||||
import me.filoghost.fcommons.FeatureSupport;
|
||||
import me.filoghost.fcommons.config.exception.ConfigException;
|
||||
import me.filoghost.fcommons.logging.ErrorCollector;
|
||||
import me.filoghost.holographicdisplays.api.internal.BackendAPI;
|
||||
import me.filoghost.holographicdisplays.api.internal.HolographicDisplaysAPIProvider;
|
||||
import me.filoghost.holographicdisplays.bridge.bungeecord.BungeeServerTracker;
|
||||
import me.filoghost.holographicdisplays.bridge.protocollib.ProtocolLibHook;
|
||||
import me.filoghost.holographicdisplays.commands.HologramCommandManager;
|
||||
@ -123,7 +123,10 @@ public class HolographicDisplays extends FCommonsPlugin implements ProtocolPacke
|
||||
registerListener(updateNotificationListener);
|
||||
|
||||
// Enable the API.
|
||||
BackendAPI.setImplementation(new DefaultBackendAPI(apiHologramManager, nmsManager, placeholderManager.getPlaceholderRegistry()));
|
||||
HolographicDisplaysAPIProvider.setImplementation(new DefaultHolographicDisplaysAPIProvider(
|
||||
apiHologramManager,
|
||||
nmsManager,
|
||||
placeholderManager.getPlaceholderRegistry()));
|
||||
|
||||
// Register bStats metrics
|
||||
int pluginID = 3123;
|
||||
|
Loading…
Reference in New Issue
Block a user