Initial API update

This commit is contained in:
filoghost 2021-08-22 09:08:30 +02:00
parent b3d8aae193
commit ac0bde854d
26 changed files with 71 additions and 69 deletions

View File

@ -40,6 +40,17 @@ public interface HolographicDisplaysAPI {
return 1;
}
/**
* Returns the API instance for managing holograms and placeholders of the specified plugin.
* <p>
* Holograms and placeholders created by other plugins are completely separate, each API instance can only manage
* and retrieve the ones of the specified plugin. Unless for very specific reasons, a plugin should only use its own
* API instance.
*
* @param plugin the plugin using the API
* @return an API instance for the specified plugin
* @since 1
*/
static @NotNull HolographicDisplaysAPI get(@NotNull Plugin plugin) {
return HolographicDisplaysAPIProvider.getImplementation().getHolographicDisplaysAPI(plugin);
}
@ -90,7 +101,7 @@ public interface HolographicDisplaysAPI {
/**
* Resets and removes all the registered placeholders.
* <p>
* May be useful to invoke before registering all the placeholders of your plugin.
* Can be useful to reset placeholders before registering all of them.
*
* @since 1
*/

View File

@ -6,6 +6,9 @@
package me.filoghost.holographicdisplays.api.hologram;
import me.filoghost.holographicdisplays.api.HolographicDisplaysAPI;
import me.filoghost.holographicdisplays.api.hologram.line.HologramLine;
import me.filoghost.holographicdisplays.api.hologram.line.ItemHologramLine;
import me.filoghost.holographicdisplays.api.hologram.line.TextHologramLine;
import org.bukkit.Location;
import org.bukkit.World;
import org.bukkit.inventory.ItemStack;
@ -28,7 +31,7 @@ public interface Hologram {
* @return the new TextLine appended
* @since 1
*/
@NotNull TextLine appendTextLine(@Nullable String text);
@NotNull TextHologramLine appendTextLine(@Nullable String text);
/**
* Appends an item line to end of this hologram.
@ -37,7 +40,7 @@ public interface Hologram {
* @return the new ItemLine appended
* @since 1
*/
@NotNull ItemLine appendItemLine(@NotNull ItemStack itemStack);
@NotNull ItemHologramLine appendItemLine(@NotNull ItemStack itemStack);
/**
* Inserts a text line in this hologram.
@ -48,7 +51,7 @@ public interface Hologram {
* @throws IndexOutOfBoundsException if the index is out of range (index &lt; 0 || index &gt;= size())
* @since 1
*/
@NotNull TextLine insertTextLine(int index, @Nullable String text);
@NotNull TextHologramLine insertTextLine(int index, @Nullable String text);
/**
* Inserts an item line in this hologram.
@ -59,13 +62,13 @@ public interface Hologram {
* @throws IndexOutOfBoundsException if the index is out of range (index &lt; 0 || index &gt;= size())
* @since 1
*/
@NotNull ItemLine insertItemLine(int index, @NotNull ItemStack itemStack);
@NotNull ItemHologramLine insertItemLine(int index, @NotNull ItemStack itemStack);
/**
* Finds the element at a given index in the lines.
*
* @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}.
* @return the hologram line at the given index, can be an {@link ItemHologramLine} or a {@link TextHologramLine}.
* @throws IndexOutOfBoundsException if the index is out of range (index &lt; 0 || index &gt;= size())
* @since 1
*/
@ -166,14 +169,6 @@ public interface Hologram {
*/
@NotNull VisibilitySettings getVisibilitySettings();
/**
* 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();
/**
* Checks if the hologram will track and replace placeholders.
* This is false by default.

View File

@ -3,7 +3,7 @@
*
* SPDX-License-Identifier: GPL-3.0-or-later
*/
package me.filoghost.holographicdisplays.api.hologram;
package me.filoghost.holographicdisplays.api.hologram.line;
import org.bukkit.entity.Player;
import org.jetbrains.annotations.NotNull;

View File

@ -3,7 +3,7 @@
*
* SPDX-License-Identifier: GPL-3.0-or-later
*/
package me.filoghost.holographicdisplays.api.hologram;
package me.filoghost.holographicdisplays.api.hologram.line;
import org.jetbrains.annotations.Nullable;
@ -12,12 +12,12 @@ import org.jetbrains.annotations.Nullable;
*
* @since 1
*/
public interface ClickableLine extends HologramLine {
public interface ClickableHologramLine extends HologramLine {
/**
* Sets the click listener.
*
* @param clickListener the new click listener
* @param clickListener the new click listener, null to unset
* @since 1
*/
void setClickListener(@Nullable ClickListener clickListener);
@ -25,7 +25,7 @@ public interface ClickableLine extends HologramLine {
/**
* Returns the current click listener.
*
* @return the current click listener
* @return the current click listener, null if not present
* @since 1
*/
@Nullable ClickListener getClickListener();

View File

@ -3,7 +3,7 @@
*
* SPDX-License-Identifier: GPL-3.0-or-later
*/
package me.filoghost.holographicdisplays.api.hologram;
package me.filoghost.holographicdisplays.api.hologram.line;
import org.jetbrains.annotations.Nullable;
@ -12,12 +12,12 @@ import org.jetbrains.annotations.Nullable;
*
* @since 1
*/
public interface CollectableLine extends HologramLine {
public interface CollectableHologramLine extends HologramLine {
/**
* Sets the pickup listener.
*
* @param pickupListener the new pickup listener
* @param pickupListener the new pickup listener, null to unset
* @since 1
*/
void setPickupListener(@Nullable PickupListener pickupListener);
@ -25,7 +25,7 @@ public interface CollectableLine extends HologramLine {
/**
* Returns the current pickup listener.
*
* @return the current pickup listener
* @return the current pickup listener, null if not present
* @since 1
*/
@Nullable PickupListener getPickupListener();

View File

@ -3,8 +3,9 @@
*
* SPDX-License-Identifier: GPL-3.0-or-later
*/
package me.filoghost.holographicdisplays.api.hologram;
package me.filoghost.holographicdisplays.api.hologram.line;
import me.filoghost.holographicdisplays.api.hologram.Hologram;
import org.jetbrains.annotations.NotNull;
/**
@ -20,6 +21,6 @@ public interface HologramLine {
* @return the parent Hologram.
* @since 1
*/
@NotNull Hologram getParent();
@NotNull Hologram getHologram();
}

View File

@ -3,7 +3,7 @@
*
* SPDX-License-Identifier: GPL-3.0-or-later
*/
package me.filoghost.holographicdisplays.api.hologram;
package me.filoghost.holographicdisplays.api.hologram.line;
import org.bukkit.inventory.ItemStack;
import org.jetbrains.annotations.Nullable;
@ -11,7 +11,7 @@ import org.jetbrains.annotations.Nullable;
/**
* @since 1
*/
public interface ItemLine extends CollectableLine, ClickableLine {
public interface ItemHologramLine extends CollectableHologramLine, ClickableHologramLine {
/**
* Returns the ItemStack of this ItemLine.

View File

@ -3,7 +3,7 @@
*
* SPDX-License-Identifier: GPL-3.0-or-later
*/
package me.filoghost.holographicdisplays.api.hologram;
package me.filoghost.holographicdisplays.api.hologram.line;
import org.bukkit.entity.Player;
import org.jetbrains.annotations.NotNull;

View File

@ -3,27 +3,27 @@
*
* SPDX-License-Identifier: GPL-3.0-or-later
*/
package me.filoghost.holographicdisplays.api.hologram;
package me.filoghost.holographicdisplays.api.hologram.line;
import org.jetbrains.annotations.Nullable;
/**
* @since 1
*/
public interface TextLine extends ClickableLine {
public interface TextHologramLine extends ClickableHologramLine {
/**
* Returns the current text of this TextLine.
* Returns the currently displayed text.
*
* @return the current text of this line.
* @return the currently displayed text.
* @since 1
*/
@Nullable String getText();
/**
* Sets the text of this TextLine.
* Sets the displayed text.
*
* @param text the new text of this line.
* @param text the new displayed text.
* @since 1
*/
void setText(@Nullable String text);

View File

@ -7,7 +7,7 @@ package me.filoghost.example.powerups;
import me.filoghost.holographicdisplays.api.HolographicDisplaysAPI;
import me.filoghost.holographicdisplays.api.hologram.Hologram;
import me.filoghost.holographicdisplays.api.hologram.ItemLine;
import me.filoghost.holographicdisplays.api.hologram.line.ItemHologramLine;
import org.bukkit.Bukkit;
import org.bukkit.ChatColor;
import org.bukkit.Effect;
@ -50,7 +50,7 @@ public class PowerUps extends JavaPlugin implements Listener {
// Spawn the floating item with a label
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));
ItemHologramLine icon = hologram.appendItemLine(new ItemStack(Material.SUGAR));
icon.setPickupListener((Player player) -> {
// Play an effect

View File

@ -19,9 +19,11 @@ import org.bukkit.inventory.ItemStack;
public class V2HologramAdapter implements Hologram {
private final APIHologram v3Hologram;
private final long creationTimestamp;
public V2HologramAdapter(APIHologram v3Hologram) {
this.v3Hologram = v3Hologram;
this.creationTimestamp = System.currentTimeMillis();
}
@Override
@ -111,7 +113,7 @@ public class V2HologramAdapter implements Hologram {
@Override
public long getCreationTimestamp() {
return v3Hologram.getCreationTimestamp();
return creationTimestamp;
}
@Override

View File

@ -19,12 +19,12 @@ public abstract class V2HologramLineAdapter implements HologramLine {
@Override
public V2HologramAdapter getParent() {
return v3Line.getParent().getV2Adapter();
return v3Line.getHologram().getV2Adapter();
}
@Override
public void removeLine() {
v3Line.getParent().removeLine(v3Line);
v3Line.getHologram().removeLine(v3Line);
}
@Override

View File

@ -7,7 +7,7 @@ package me.filoghost.holographicdisplays.plugin.api.v2;
import com.gmail.filoghost.holographicdisplays.api.handler.PickupHandler;
import com.gmail.filoghost.holographicdisplays.api.line.ItemLine;
import me.filoghost.holographicdisplays.api.hologram.PickupListener;
import me.filoghost.holographicdisplays.api.hologram.line.PickupListener;
import me.filoghost.holographicdisplays.plugin.hologram.api.APIItemLine;
import org.bukkit.inventory.ItemStack;

View File

@ -6,7 +6,7 @@
package me.filoghost.holographicdisplays.plugin.api.v2;
import com.gmail.filoghost.holographicdisplays.api.handler.PickupHandler;
import me.filoghost.holographicdisplays.api.hologram.PickupListener;
import me.filoghost.holographicdisplays.api.hologram.line.PickupListener;
import org.bukkit.entity.Player;
@SuppressWarnings("deprecation")

View File

@ -6,7 +6,7 @@
package me.filoghost.holographicdisplays.plugin.api.v2;
import com.gmail.filoghost.holographicdisplays.api.handler.TouchHandler;
import me.filoghost.holographicdisplays.api.hologram.ClickListener;
import me.filoghost.holographicdisplays.api.hologram.line.ClickListener;
import org.bukkit.entity.Player;
@SuppressWarnings("deprecation")

View File

@ -7,7 +7,7 @@ package me.filoghost.holographicdisplays.plugin.api.v2;
import com.gmail.filoghost.holographicdisplays.api.handler.TouchHandler;
import com.gmail.filoghost.holographicdisplays.api.line.TouchableLine;
import me.filoghost.holographicdisplays.api.hologram.ClickListener;
import me.filoghost.holographicdisplays.api.hologram.line.ClickListener;
import me.filoghost.holographicdisplays.plugin.hologram.api.APIClickableLine;
@SuppressWarnings("deprecation")

View File

@ -6,7 +6,7 @@
package me.filoghost.holographicdisplays.plugin.api.v2;
import com.gmail.filoghost.holographicdisplays.api.handler.TouchHandler;
import me.filoghost.holographicdisplays.api.hologram.ClickListener;
import me.filoghost.holographicdisplays.api.hologram.line.ClickListener;
import org.bukkit.entity.Player;
import org.jetbrains.annotations.NotNull;

View File

@ -6,7 +6,7 @@
package me.filoghost.holographicdisplays.plugin.api.v2;
import com.gmail.filoghost.holographicdisplays.api.handler.PickupHandler;
import me.filoghost.holographicdisplays.api.hologram.PickupListener;
import me.filoghost.holographicdisplays.api.hologram.line.PickupListener;
import org.bukkit.entity.Player;
import org.jetbrains.annotations.NotNull;

View File

@ -5,8 +5,8 @@
*/
package me.filoghost.holographicdisplays.plugin.hologram.api;
import me.filoghost.holographicdisplays.api.hologram.ClickableLine;
import me.filoghost.holographicdisplays.api.hologram.line.ClickableHologramLine;
public interface APIClickableLine extends ClickableLine, APIHologramLine {
public interface APIClickableLine extends ClickableHologramLine, APIHologramLine {
}

View File

@ -7,7 +7,7 @@ package me.filoghost.holographicdisplays.plugin.hologram.api;
import me.filoghost.fcommons.Preconditions;
import me.filoghost.holographicdisplays.api.hologram.Hologram;
import me.filoghost.holographicdisplays.api.hologram.HologramLine;
import me.filoghost.holographicdisplays.api.hologram.line.HologramLine;
import me.filoghost.holographicdisplays.plugin.api.v2.V2HologramAdapter;
import me.filoghost.holographicdisplays.plugin.config.Settings;
import me.filoghost.holographicdisplays.plugin.hologram.base.BaseHologram;
@ -26,7 +26,6 @@ public class APIHologram extends BaseHologram implements Hologram {
private final Plugin plugin;
private final APIHologramManager apiHologramManager;
private final DefaultVisibilitySettings visibilitySettings;
private final long creationTimestamp;
private final V2HologramAdapter v2Adapter;
private boolean allowPlaceholders;
@ -42,7 +41,6 @@ public class APIHologram extends BaseHologram implements Hologram {
this.plugin = plugin;
this.apiHologramManager = apiHologramManager;
this.visibilitySettings = new DefaultVisibilitySettings();
this.creationTimestamp = System.currentTimeMillis();
this.v2Adapter = new V2HologramAdapter(this);
}
@ -169,11 +167,6 @@ public class APIHologram extends BaseHologram implements Hologram {
return height;
}
@Override
public long getCreationTimestamp() {
return creationTimestamp;
}
@Override
public @NotNull DefaultVisibilitySettings getVisibilitySettings() {
return visibilitySettings;

View File

@ -5,7 +5,7 @@
*/
package me.filoghost.holographicdisplays.plugin.hologram.api;
import me.filoghost.holographicdisplays.api.hologram.HologramLine;
import me.filoghost.holographicdisplays.api.hologram.line.HologramLine;
import me.filoghost.holographicdisplays.plugin.api.v2.V2HologramLineAdapter;
import me.filoghost.holographicdisplays.plugin.hologram.base.EditableHologramLine;
import org.jetbrains.annotations.NotNull;
@ -13,7 +13,7 @@ import org.jetbrains.annotations.NotNull;
public interface APIHologramLine extends HologramLine, EditableHologramLine {
@Override
@NotNull APIHologram getParent();
@NotNull APIHologram getHologram();
void setChanged();

View File

@ -5,16 +5,16 @@
*/
package me.filoghost.holographicdisplays.plugin.hologram.api;
import me.filoghost.holographicdisplays.api.hologram.ItemLine;
import me.filoghost.holographicdisplays.api.hologram.PickupListener;
import me.filoghost.holographicdisplays.api.hologram.ClickListener;
import me.filoghost.holographicdisplays.api.hologram.line.ItemHologramLine;
import me.filoghost.holographicdisplays.api.hologram.line.PickupListener;
import me.filoghost.holographicdisplays.api.hologram.line.ClickListener;
import me.filoghost.holographicdisplays.plugin.api.v2.V2ItemLineAdapter;
import me.filoghost.holographicdisplays.plugin.hologram.base.BaseItemLine;
import org.bukkit.inventory.ItemStack;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
public class APIItemLine extends BaseItemLine implements ItemLine, APIClickableLine {
public class APIItemLine extends BaseItemLine implements ItemHologramLine, APIClickableLine {
private final APIHologram parent;
private final V2ItemLineAdapter v2Adapter;
@ -26,7 +26,7 @@ public class APIItemLine extends BaseItemLine implements ItemLine, APIClickableL
}
@Override
public @NotNull APIHologram getParent() {
public @NotNull APIHologram getHologram() {
return parent;
}

View File

@ -5,14 +5,14 @@
*/
package me.filoghost.holographicdisplays.plugin.hologram.api;
import me.filoghost.holographicdisplays.api.hologram.ClickListener;
import me.filoghost.holographicdisplays.api.hologram.TextLine;
import me.filoghost.holographicdisplays.api.hologram.line.ClickListener;
import me.filoghost.holographicdisplays.api.hologram.line.TextHologramLine;
import me.filoghost.holographicdisplays.plugin.api.v2.V2TextLineAdapter;
import me.filoghost.holographicdisplays.plugin.hologram.base.BaseTextLine;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
public class APITextLine extends BaseTextLine implements TextLine, APIClickableLine {
public class APITextLine extends BaseTextLine implements TextHologramLine, APIClickableLine {
private final APIHologram parent;
private final V2TextLineAdapter v2Adapter;
@ -24,7 +24,7 @@ public class APITextLine extends BaseTextLine implements TextLine, APIClickableL
}
@Override
public @NotNull APIHologram getParent() {
public @NotNull APIHologram getHologram() {
return parent;
}

View File

@ -6,7 +6,7 @@
package me.filoghost.holographicdisplays.plugin.hologram.base;
import me.filoghost.fcommons.logging.Log;
import me.filoghost.holographicdisplays.api.hologram.ClickListener;
import me.filoghost.holographicdisplays.api.hologram.line.ClickListener;
import me.filoghost.holographicdisplays.common.Position;
import org.bukkit.Location;
import org.bukkit.entity.Player;

View File

@ -7,7 +7,7 @@ package me.filoghost.holographicdisplays.plugin.hologram.base;
import me.filoghost.fcommons.Preconditions;
import me.filoghost.fcommons.logging.Log;
import me.filoghost.holographicdisplays.api.hologram.PickupListener;
import me.filoghost.holographicdisplays.api.hologram.line.PickupListener;
import me.filoghost.holographicdisplays.common.nms.entity.ItemNMSPacketEntity;
import me.filoghost.holographicdisplays.plugin.hologram.tracking.ItemLineTracker;
import me.filoghost.holographicdisplays.plugin.hologram.tracking.LineTrackerManager;

View File

@ -7,7 +7,7 @@ package me.filoghost.holographicdisplays.plugin.api.v2;
import com.gmail.filoghost.holographicdisplays.api.handler.TouchHandler;
import com.gmail.filoghost.holographicdisplays.api.line.TextLine;
import me.filoghost.holographicdisplays.api.hologram.ClickListener;
import me.filoghost.holographicdisplays.api.hologram.line.ClickListener;
import me.filoghost.holographicdisplays.plugin.hologram.api.APIHologram;
import me.filoghost.holographicdisplays.plugin.hologram.api.APIHologramManager;
import me.filoghost.holographicdisplays.plugin.hologram.api.APITextLine;