mirror of
https://github.com/filoghost/HolographicDisplays.git
synced 2024-12-20 07:47:38 +01:00
API changes
This commit is contained in:
parent
dba767dd79
commit
2da7d318df
@ -6,119 +6,29 @@
|
||||
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;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
/**
|
||||
* 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 HolographicDisplaysAPI#createHologram(Location)}.
|
||||
* Entity to manage a group of vertically aligned lines, which display floating text and items.
|
||||
* To create one see {@link HolographicDisplaysAPI}.
|
||||
*
|
||||
* @since 1
|
||||
*/
|
||||
public interface Hologram {
|
||||
|
||||
/**
|
||||
* Appends a text line to end of this hologram.
|
||||
*
|
||||
* @param text the content of the line, can be null for an empty line
|
||||
* @return the new TextLine appended
|
||||
* @since 1
|
||||
*/
|
||||
@NotNull TextHologramLine appendTextLine(@Nullable String text);
|
||||
|
||||
/**
|
||||
* Appends an item line to end of this hologram.
|
||||
*
|
||||
* @param itemStack the content of the line
|
||||
* @return the new ItemLine appended
|
||||
* @since 1
|
||||
*/
|
||||
@NotNull ItemHologramLine appendItemLine(@NotNull ItemStack itemStack);
|
||||
|
||||
/**
|
||||
* Inserts a text line in this hologram.
|
||||
*
|
||||
* @param index the line is inserted before this index. If 0, the new line will be inserted before the first line.
|
||||
* @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
|
||||
*/
|
||||
@NotNull TextHologramLine insertTextLine(int index, @Nullable String text);
|
||||
|
||||
/**
|
||||
* Inserts an item line in this hologram.
|
||||
*
|
||||
* @param index the line is inserted before this index. If 0, the new line will be inserted before the first line.
|
||||
* @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
|
||||
*/
|
||||
@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 ItemHologramLine} or a {@link TextHologramLine}.
|
||||
* @throws IndexOutOfBoundsException if the index is out of range (index < 0 || index >= size())
|
||||
* @since 1
|
||||
*/
|
||||
@NotNull HologramLine getLine(int index);
|
||||
|
||||
/**
|
||||
* Removes a line at a given index.
|
||||
*
|
||||
* @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 a line.
|
||||
*
|
||||
* @param line the line to be removed.
|
||||
* @return if the hologram contained the line
|
||||
* @since 1
|
||||
*/
|
||||
boolean removeLine(@NotNull HologramLine line);
|
||||
|
||||
/**
|
||||
* Removes all the lines from this hologram.
|
||||
* Returns the editable list of lines.
|
||||
*
|
||||
* @since 1
|
||||
*/
|
||||
void clearLines();
|
||||
@NotNull HologramLines lines();
|
||||
|
||||
/**
|
||||
* Checks the amount of lines of the hologram.
|
||||
* Returns the current position.
|
||||
*
|
||||
* @return the amount of lines
|
||||
* @since 1
|
||||
*/
|
||||
int getLineCount();
|
||||
|
||||
/**
|
||||
* The physical height of the hologram, counting all the lines.
|
||||
*
|
||||
* @return the height of the hologram, counting all the lines and the gaps between them
|
||||
* @since 1
|
||||
*/
|
||||
double getHeight();
|
||||
|
||||
/**
|
||||
* Returns the hologram position.
|
||||
*
|
||||
* @return the hologram position
|
||||
* @return the current position
|
||||
* @since 1
|
||||
*/
|
||||
@NotNull HologramPosition getPosition();
|
||||
|
@ -0,0 +1,113 @@
|
||||
/*
|
||||
* Copyright (C) filoghost and contributors
|
||||
*
|
||||
* SPDX-License-Identifier: GPL-3.0-or-later
|
||||
*/
|
||||
package me.filoghost.holographicdisplays.api.hologram;
|
||||
|
||||
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.inventory.ItemStack;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
/**
|
||||
* The editable list of lines of a hologram.
|
||||
*
|
||||
* @since 1
|
||||
*/
|
||||
public interface HologramLines {
|
||||
|
||||
/**
|
||||
* Adds a new text line at the end.
|
||||
*
|
||||
* @param text the content of the line, see {@link TextHologramLine#setText(String)}
|
||||
* @return the created line
|
||||
* @since 1
|
||||
*/
|
||||
@NotNull TextHologramLine appendText(@Nullable String text);
|
||||
|
||||
/**
|
||||
* Adds a new item line at the end.
|
||||
*
|
||||
* @param itemStack the content of the line, see {@link ItemHologramLine#setItemStack(ItemStack)}
|
||||
* @return the created line
|
||||
* @since 1
|
||||
*/
|
||||
@NotNull ItemHologramLine appendItem(@NotNull ItemStack itemStack);
|
||||
|
||||
/**
|
||||
* Inserts a new text line before the given index.
|
||||
*
|
||||
* @param beforeIndex the index before which the line is inserted, 0 to insert as first
|
||||
* @param text the content of the line, see {@link TextHologramLine#setText(String)}
|
||||
* @return the created line
|
||||
* @throws IndexOutOfBoundsException if the index is out of range (index < 0 || index >= size())
|
||||
* @since 1
|
||||
*/
|
||||
@NotNull TextHologramLine insertText(int beforeIndex, @Nullable String text);
|
||||
|
||||
/**
|
||||
* Inserts a new item line before the given index.
|
||||
*
|
||||
* @param beforeIndex the index before which the line is inserted, 0 to insert as first
|
||||
* @param itemStack the content of the line, see {@link ItemHologramLine#setItemStack(ItemStack)}
|
||||
* @return the created line
|
||||
* @throws IndexOutOfBoundsException if the index is out of range (index < 0 || index >= size())
|
||||
* @since 1
|
||||
*/
|
||||
@NotNull ItemHologramLine insertItem(int beforeIndex, @NotNull ItemStack itemStack);
|
||||
|
||||
/**
|
||||
* Returns the line at the given index.
|
||||
*
|
||||
* @param index the index of the line to retrieve
|
||||
* @return the line at the given index
|
||||
* @throws IndexOutOfBoundsException if the index is out of range (index < 0 || index >= size())
|
||||
* @since 1
|
||||
*/
|
||||
@NotNull HologramLine get(int index);
|
||||
|
||||
/**
|
||||
* Removes the line at the given index.
|
||||
*
|
||||
* @param index the index of the line to remove
|
||||
* @throws IndexOutOfBoundsException if the index is out of range (index < 0 || index >= size())
|
||||
* @since 1
|
||||
*/
|
||||
void remove(int index);
|
||||
|
||||
/**
|
||||
* Removes a line.
|
||||
*
|
||||
* @param line the line to be removed
|
||||
* @return if the line was found and removed
|
||||
* @since 1
|
||||
*/
|
||||
boolean remove(@NotNull HologramLine line);
|
||||
|
||||
/**
|
||||
* Removes all the lines.
|
||||
*
|
||||
* @since 1
|
||||
*/
|
||||
void clear();
|
||||
|
||||
/**
|
||||
* Returns the amount of lines.
|
||||
*
|
||||
* @return the amount of lines
|
||||
* @since 1
|
||||
*/
|
||||
int size();
|
||||
|
||||
/**
|
||||
* The total height of the lines, including the gaps between them.
|
||||
*
|
||||
* @return the total height of the lines
|
||||
* @since 1
|
||||
*/
|
||||
double getHeight();
|
||||
|
||||
}
|
@ -41,8 +41,8 @@ public class DeathHolograms extends JavaPlugin implements Listener {
|
||||
public void onPlayerDeath(PlayerDeathEvent event) {
|
||||
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()));
|
||||
hologram.lines().appendText(ChatColor.RED + "Player " + ChatColor.GOLD + event.getEntity().getName() + ChatColor.RED + " died here!");
|
||||
hologram.lines().appendText(ChatColor.GRAY + "Time of death: " + TIME_FORMATTER.format(Instant.now()));
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -49,10 +49,10 @@ 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");
|
||||
ItemHologramLine icon = hologram.appendItemLine(new ItemStack(Material.SUGAR));
|
||||
hologram.lines().appendText(ChatColor.AQUA + "" + ChatColor.BOLD + "Speed PowerUp");
|
||||
ItemHologramLine itemLine = hologram.lines().appendItem(new ItemStack(Material.SUGAR));
|
||||
|
||||
icon.setPickupListener((Player player) -> {
|
||||
itemLine.setPickupListener((Player player) -> {
|
||||
// Play an effect
|
||||
player.playEffect(hologram.getPosition().toLocation(), Effect.MOBSPAWNER_FLAMES, null);
|
||||
|
||||
|
@ -177,10 +177,10 @@ public class HolographicDisplays extends FCommonsPlugin {
|
||||
hologramDatabase.createHolograms(internalHologramManager, errorCollector);
|
||||
|
||||
for (APIHologram hologram : apiHologramManager.getHolograms()) {
|
||||
hologram.getLines().updateLinePositions();
|
||||
hologram.lines().updatePositions();
|
||||
}
|
||||
for (V2Hologram hologram : v2HologramManager.getHolograms()) {
|
||||
hologram.getLines().updateLinePositions();
|
||||
hologram.lines().updatePositions();
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -44,7 +44,7 @@ public class V2Hologram extends BaseHologram implements Hologram {
|
||||
}
|
||||
|
||||
@Override
|
||||
public BaseHologramLines<V2HologramLine> getLines() {
|
||||
public BaseHologramLines<V2HologramLine> lines() {
|
||||
return lines;
|
||||
}
|
||||
|
||||
|
@ -15,7 +15,7 @@ public interface V2HologramLine extends HologramLine, EditableHologramLine {
|
||||
|
||||
@Override
|
||||
default void removeLine() {
|
||||
getParent().getLines().remove(this);
|
||||
getParent().lines().remove(this);
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -38,7 +38,7 @@ public class AddLineCommand extends LineEditingCommand implements QuickEditComma
|
||||
|
||||
InternalHologramLine line = hologramEditor.parseHologramLine(hologram, serializedLine);
|
||||
|
||||
hologram.getLines().add(line);
|
||||
hologram.lines().add(line);
|
||||
hologramEditor.saveChanges(hologram, ChangeType.EDIT_LINES);
|
||||
|
||||
sender.sendMessage(ColorScheme.PRIMARY + "Line added.");
|
||||
|
@ -37,11 +37,11 @@ public class CopyCommand extends HologramSubCommand {
|
||||
InternalHologram toHologram = hologramEditor.getExistingHologram(args[1]);
|
||||
|
||||
List<InternalHologramLine> clonedLines = new ArrayList<>();
|
||||
for (InternalHologramLine line : fromHologram.getLines()) {
|
||||
for (InternalHologramLine line : fromHologram.lines()) {
|
||||
clonedLines.add(hologramEditor.parseHologramLine(toHologram, line.getSerializedConfigValue()));
|
||||
}
|
||||
|
||||
toHologram.getLines().setAll(clonedLines);
|
||||
toHologram.lines().setAll(clonedLines);
|
||||
hologramEditor.saveChanges(toHologram, ChangeType.EDIT_LINES);
|
||||
|
||||
sender.sendMessage(ColorScheme.PRIMARY + "Lines of hologram \"" + fromHologram.getName() + "\""
|
||||
|
@ -67,7 +67,7 @@ public class CreateCommand extends HologramSubCommand {
|
||||
line = hologram.createTextLine(defaultText, defaultText.replace(ChatColor.COLOR_CHAR, '&'));
|
||||
}
|
||||
|
||||
hologram.getLines().add(line);
|
||||
hologram.lines().add(line);
|
||||
hologramEditor.saveChanges(hologram, ChangeType.CREATE);
|
||||
|
||||
hologramEditor.teleportLookingDown(player, player.getLocation());
|
||||
|
@ -37,7 +37,7 @@ public class InfoCommand extends LineEditingCommand implements QuickEditCommand
|
||||
DisplayFormat.sendTitle(sender, "Lines of the hologram \"" + hologram.getName() + "\"");
|
||||
int index = 0;
|
||||
|
||||
for (InternalHologramLine line : hologram.getLines()) {
|
||||
for (InternalHologramLine line : hologram.lines()) {
|
||||
index++;
|
||||
sender.sendMessage(ColorScheme.SECONDARY_BOLD + index + ColorScheme.SECONDARY_DARK + ". "
|
||||
+ ColorScheme.SECONDARY + line.getSerializedConfigValue());
|
||||
|
@ -41,14 +41,14 @@ public class InsertLineCommand extends LineEditingCommand implements QuickEditCo
|
||||
int insertAfterIndex = CommandValidate.parseInteger(args[1]);
|
||||
String serializedLine = Strings.joinFrom(" ", args, 2);
|
||||
|
||||
int oldLinesAmount = hologram.getLines().size();
|
||||
int oldLinesAmount = hologram.lines().size();
|
||||
|
||||
CommandValidate.check(insertAfterIndex >= 0 && insertAfterIndex <= oldLinesAmount,
|
||||
"The line number must be between 0 and " + oldLinesAmount + ".");
|
||||
|
||||
InternalHologramLine line = hologramEditor.parseHologramLine(hologram, serializedLine);
|
||||
|
||||
hologram.getLines().insert(insertAfterIndex, line);
|
||||
hologram.lines().insert(insertAfterIndex, line);
|
||||
hologramEditor.saveChanges(hologram, ChangeType.EDIT_LINES);
|
||||
|
||||
if (insertAfterIndex == 0) {
|
||||
|
@ -114,9 +114,9 @@ public class ReadImageCommand extends LineEditingCommand {
|
||||
}
|
||||
|
||||
if (!append) {
|
||||
hologram.getLines().clear();
|
||||
hologram.lines().clear();
|
||||
}
|
||||
hologram.getLines().addAll(newLines);
|
||||
hologram.lines().addAll(newLines);
|
||||
hologramEditor.saveChanges(hologram, ChangeType.EDIT_LINES);
|
||||
|
||||
if (append) {
|
||||
|
@ -85,7 +85,7 @@ public class ReadTextCommand extends LineEditingCommand {
|
||||
}
|
||||
}
|
||||
|
||||
hologram.getLines().setAll(newLines);
|
||||
hologram.lines().setAll(newLines);
|
||||
hologramEditor.saveChanges(hologram, ChangeType.EDIT_LINES);
|
||||
|
||||
if (FileUtils.hasFileExtension(fileToRead, "jpg", "png", "jpeg", "gif")) {
|
||||
|
@ -35,7 +35,7 @@ public class RemoveLineCommand extends LineEditingCommand implements QuickEditCo
|
||||
InternalHologram hologram = hologramEditor.getExistingHologram(args[0]);
|
||||
|
||||
int lineNumber = CommandValidate.parseInteger(args[1]);
|
||||
int linesAmount = hologram.getLines().size();
|
||||
int linesAmount = hologram.lines().size();
|
||||
|
||||
CommandValidate.check(lineNumber >= 1 && lineNumber <= linesAmount,
|
||||
"The line number must be between 1 and " + linesAmount + ".");
|
||||
@ -44,7 +44,7 @@ public class RemoveLineCommand extends LineEditingCommand implements QuickEditCo
|
||||
CommandValidate.check(linesAmount >= 2,
|
||||
"A hologram must always have at least 1 line. If you want to delete it, use /" + context.getRootLabel() + " delete.");
|
||||
|
||||
hologram.getLines().remove(index);
|
||||
hologram.lines().remove(index);
|
||||
hologramEditor.saveChanges(hologram, ChangeType.EDIT_LINES);
|
||||
|
||||
sender.sendMessage(ColorScheme.PRIMARY + "Line " + lineNumber + " removed.");
|
||||
|
@ -38,7 +38,7 @@ public class SetLineCommand extends LineEditingCommand implements QuickEditComma
|
||||
String serializedLine = Strings.joinFrom(" ", args, 2);
|
||||
|
||||
int lineNumber = CommandValidate.parseInteger(args[1]);
|
||||
int linesAmount = hologram.getLines().size();
|
||||
int linesAmount = hologram.lines().size();
|
||||
|
||||
CommandValidate.check(lineNumber >= 1 && lineNumber <= linesAmount,
|
||||
"The line number must be between 1 and " + linesAmount + ".");
|
||||
@ -46,7 +46,7 @@ public class SetLineCommand extends LineEditingCommand implements QuickEditComma
|
||||
|
||||
InternalHologramLine line = hologramEditor.parseHologramLine(hologram, serializedLine);
|
||||
|
||||
hologram.getLines().set(index, line);
|
||||
hologram.lines().set(index, line);
|
||||
hologramEditor.saveChanges(hologram, ChangeType.EDIT_LINES);
|
||||
|
||||
sender.sendMessage(ColorScheme.PRIMARY + "Line " + lineNumber + " changed.");
|
||||
|
@ -30,7 +30,7 @@ public class HologramConfig {
|
||||
public HologramConfig(InternalHologram hologram) {
|
||||
this.name = hologram.getName();
|
||||
this.serializedLines = new ArrayList<>();
|
||||
for (InternalHologramLine line : hologram.getLines()) {
|
||||
for (InternalHologramLine line : hologram.lines()) {
|
||||
serializedLines.add(line.getSerializedConfigValue());
|
||||
}
|
||||
|
||||
@ -70,7 +70,7 @@ public class HologramConfig {
|
||||
}
|
||||
}
|
||||
|
||||
hologram.getLines().addAll(lines);
|
||||
hologram.lines().addAll(lines);
|
||||
}
|
||||
|
||||
private BaseHologramPosition parsePosition() throws HologramLoadException {
|
||||
|
@ -89,7 +89,7 @@ public class DisplayFormat {
|
||||
public static void sendHologramSummary(CommandSender sender, InternalHologram hologram, boolean showWorld) {
|
||||
BaseHologramPosition position = hologram.getPosition();
|
||||
sender.sendMessage(ColorScheme.SECONDARY_DARK + "- " + ColorScheme.SECONDARY_BOLD + hologram.getName()
|
||||
+ ColorScheme.SECONDARY_DARK + " (" + hologram.getLines().size() + " lines) at "
|
||||
+ ColorScheme.SECONDARY_DARK + " (" + hologram.lines().size() + " lines) at "
|
||||
+ (showWorld ? "world: \"" + position.getWorldName() + "\", " : "")
|
||||
+ "x: " + position.getBlockX() + ", "
|
||||
+ "y: " + position.getBlockY() + ", "
|
||||
|
@ -7,20 +7,16 @@ 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.line.HologramLine;
|
||||
import me.filoghost.holographicdisplays.plugin.hologram.base.BaseHologram;
|
||||
import me.filoghost.holographicdisplays.plugin.hologram.base.BaseHologramLines;
|
||||
import me.filoghost.holographicdisplays.plugin.hologram.base.BaseHologramPosition;
|
||||
import me.filoghost.holographicdisplays.plugin.hologram.tracking.LineTrackerManager;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
import org.bukkit.plugin.Plugin;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
public class APIHologram extends BaseHologram implements Hologram {
|
||||
|
||||
private final BaseHologramLines<APIHologramLine> lines;
|
||||
private final APIHologramLines lines;
|
||||
private final Plugin plugin;
|
||||
private final APIHologramManager apiHologramManager;
|
||||
private final DefaultVisibilitySettings visibilitySettings;
|
||||
@ -34,14 +30,14 @@ public class APIHologram extends BaseHologram implements Hologram {
|
||||
LineTrackerManager lineTrackerManager) {
|
||||
super(position, lineTrackerManager);
|
||||
Preconditions.notNull(plugin, "plugin");
|
||||
this.lines = new BaseHologramLines<>(this);
|
||||
this.lines = new APIHologramLines(this);
|
||||
this.plugin = plugin;
|
||||
this.apiHologramManager = apiHologramManager;
|
||||
this.visibilitySettings = new DefaultVisibilitySettings();
|
||||
}
|
||||
|
||||
@Override
|
||||
public BaseHologramLines<APIHologramLine> getLines() {
|
||||
public @NotNull APIHologramLines lines() {
|
||||
return lines;
|
||||
}
|
||||
|
||||
@ -50,79 +46,6 @@ public class APIHologram extends BaseHologram implements Hologram {
|
||||
return plugin;
|
||||
}
|
||||
|
||||
@Override
|
||||
public @NotNull APIHologramLine getLine(int index) {
|
||||
return lines.get(index);
|
||||
}
|
||||
|
||||
@Override
|
||||
public @NotNull APITextLine appendTextLine(@Nullable String text) {
|
||||
checkNotDeleted();
|
||||
|
||||
APITextLine line = new APITextLine(this, text);
|
||||
lines.add(line);
|
||||
return line;
|
||||
}
|
||||
|
||||
@Override
|
||||
public @NotNull APIItemLine appendItemLine(@NotNull ItemStack itemStack) {
|
||||
Preconditions.notNull(itemStack, "itemStack");
|
||||
checkNotDeleted();
|
||||
|
||||
APIItemLine line = new APIItemLine(this, itemStack);
|
||||
lines.add(line);
|
||||
return line;
|
||||
}
|
||||
|
||||
@Override
|
||||
public @NotNull APITextLine insertTextLine(int index, @Nullable String text) {
|
||||
checkNotDeleted();
|
||||
|
||||
APITextLine line = new APITextLine(this, text);
|
||||
lines.add(line);
|
||||
return line;
|
||||
}
|
||||
|
||||
@Override
|
||||
public @NotNull APIItemLine insertItemLine(int index, @NotNull ItemStack itemStack) {
|
||||
Preconditions.notNull(itemStack, "itemStack");
|
||||
checkNotDeleted();
|
||||
|
||||
APIItemLine line = new APIItemLine(this, itemStack);
|
||||
lines.add(line);
|
||||
return line;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void removeLine(int index) {
|
||||
checkNotDeleted();
|
||||
|
||||
lines.remove(index);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean removeLine(@NotNull HologramLine line) {
|
||||
checkNotDeleted();
|
||||
|
||||
if (line instanceof APIHologramLine) {
|
||||
return lines.remove((APIHologramLine) line);
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void clearLines() {
|
||||
checkNotDeleted();
|
||||
|
||||
lines.clear();
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getLineCount() {
|
||||
return getLines().size();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setAllowPlaceholders(boolean allowPlaceholders) {
|
||||
checkNotDeleted();
|
||||
@ -147,11 +70,6 @@ public class APIHologram extends BaseHologram implements Hologram {
|
||||
return visibilitySettings.isVisibleTo(player);
|
||||
}
|
||||
|
||||
@Override
|
||||
public double getHeight() {
|
||||
return lines.getHeight();
|
||||
}
|
||||
|
||||
@Override
|
||||
public @NotNull DefaultVisibilitySettings getVisibilitySettings() {
|
||||
return visibilitySettings;
|
||||
|
@ -0,0 +1,74 @@
|
||||
/*
|
||||
* Copyright (C) filoghost and contributors
|
||||
*
|
||||
* SPDX-License-Identifier: GPL-3.0-or-later
|
||||
*/
|
||||
package me.filoghost.holographicdisplays.plugin.hologram.api;
|
||||
|
||||
import me.filoghost.fcommons.Preconditions;
|
||||
import me.filoghost.holographicdisplays.api.hologram.HologramLines;
|
||||
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 me.filoghost.holographicdisplays.plugin.hologram.base.BaseHologramLines;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
public class APIHologramLines extends BaseHologramLines<APIHologramLine> implements HologramLines {
|
||||
|
||||
private final APIHologram hologram;
|
||||
|
||||
public APIHologramLines(APIHologram hologram) {
|
||||
super(hologram);
|
||||
this.hologram = hologram;
|
||||
}
|
||||
|
||||
@Override
|
||||
public @NotNull TextHologramLine appendText(@Nullable String text) {
|
||||
checkNotDeleted();
|
||||
|
||||
APITextLine line = new APITextLine(hologram, text);
|
||||
super.add(line);
|
||||
return line;
|
||||
}
|
||||
|
||||
@Override
|
||||
public @NotNull ItemHologramLine appendItem(@NotNull ItemStack itemStack) {
|
||||
Preconditions.notNull(itemStack, "itemStack");
|
||||
checkNotDeleted();
|
||||
|
||||
APIItemLine line = new APIItemLine(hologram, itemStack);
|
||||
super.add(line);
|
||||
return line;
|
||||
}
|
||||
|
||||
@Override
|
||||
public @NotNull TextHologramLine insertText(int beforeIndex, @Nullable String text) {
|
||||
checkNotDeleted();
|
||||
|
||||
APITextLine line = new APITextLine(hologram, text);
|
||||
super.insert(beforeIndex, line);
|
||||
return line;
|
||||
}
|
||||
|
||||
@Override
|
||||
public @NotNull ItemHologramLine insertItem(int beforeIndex, @NotNull ItemStack itemStack) {
|
||||
Preconditions.notNull(itemStack, "itemStack");
|
||||
checkNotDeleted();
|
||||
|
||||
APIItemLine line = new APIItemLine(hologram, itemStack);
|
||||
super.insert(beforeIndex, line);
|
||||
return line;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean remove(@NotNull HologramLine line) {
|
||||
if (line instanceof APIHologramLine) {
|
||||
return super.remove((APIHologramLine) line);
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
@ -26,7 +26,7 @@ public abstract class BaseHologram extends BaseHologramComponent {
|
||||
this.lineTrackerManager = lineTrackerManager;
|
||||
}
|
||||
|
||||
public abstract BaseHologramLines<? extends EditableHologramLine> getLines();
|
||||
public abstract BaseHologramLines<? extends EditableHologramLine> lines();
|
||||
|
||||
protected abstract boolean isVisibleTo(Player player);
|
||||
|
||||
@ -39,7 +39,7 @@ public abstract class BaseHologram extends BaseHologramComponent {
|
||||
@Override
|
||||
public final void setDeleted() {
|
||||
super.setDeleted();
|
||||
getLines().setDeleted();
|
||||
lines().setDeleted();
|
||||
}
|
||||
|
||||
public @NotNull BaseHologramPosition getPosition() {
|
||||
@ -71,7 +71,7 @@ public abstract class BaseHologram extends BaseHologramComponent {
|
||||
checkNotDeleted();
|
||||
|
||||
position.set(worldName, x, y, z);
|
||||
getLines().updateLinePositions();
|
||||
lines().updatePositions();
|
||||
}
|
||||
|
||||
protected void onWorldLoad(World world) {
|
||||
@ -98,7 +98,7 @@ public abstract class BaseHologram extends BaseHologramComponent {
|
||||
public String toString() {
|
||||
return "Hologram{"
|
||||
+ "position=" + position
|
||||
+ ", lines=" + getLines()
|
||||
+ ", lines=" + lines()
|
||||
+ ", deleted=" + isDeleted()
|
||||
+ "}";
|
||||
}
|
||||
|
@ -7,6 +7,7 @@ package me.filoghost.holographicdisplays.plugin.hologram.base;
|
||||
|
||||
import me.filoghost.holographicdisplays.api.hologram.HologramPosition;
|
||||
import me.filoghost.holographicdisplays.plugin.config.Settings;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collections;
|
||||
@ -38,7 +39,7 @@ public class BaseHologramLines<T extends EditableHologramLine> implements Iterab
|
||||
return lines.isEmpty();
|
||||
}
|
||||
|
||||
public T get(int index) {
|
||||
public @NotNull T get(int index) {
|
||||
return lines.get(index);
|
||||
}
|
||||
|
||||
@ -46,21 +47,21 @@ public class BaseHologramLines<T extends EditableHologramLine> implements Iterab
|
||||
checkNotDeleted();
|
||||
|
||||
lines.add(line);
|
||||
updateLinePositions();
|
||||
updatePositions();
|
||||
}
|
||||
|
||||
public void addAll(List<? extends T> newLines) {
|
||||
checkNotDeleted();
|
||||
|
||||
lines.addAll(newLines);
|
||||
updateLinePositions();
|
||||
updatePositions();
|
||||
}
|
||||
|
||||
public void insert(int afterIndex, T line) {
|
||||
public void insert(int beforeIndex, T line) {
|
||||
checkNotDeleted();
|
||||
|
||||
lines.add(afterIndex, line);
|
||||
updateLinePositions();
|
||||
lines.add(beforeIndex, line);
|
||||
updatePositions();
|
||||
}
|
||||
|
||||
public void set(int index, T line) {
|
||||
@ -68,7 +69,7 @@ public class BaseHologramLines<T extends EditableHologramLine> implements Iterab
|
||||
|
||||
T previousLine = lines.set(index, line);
|
||||
previousLine.setDeleted();
|
||||
updateLinePositions();
|
||||
updatePositions();
|
||||
}
|
||||
|
||||
public void setAll(List<T> newLines) {
|
||||
@ -76,14 +77,14 @@ public class BaseHologramLines<T extends EditableHologramLine> implements Iterab
|
||||
|
||||
clear();
|
||||
lines.addAll(newLines);
|
||||
updateLinePositions();
|
||||
updatePositions();
|
||||
}
|
||||
|
||||
public void remove(int index) {
|
||||
checkNotDeleted();
|
||||
|
||||
lines.remove(index).setDeleted();
|
||||
updateLinePositions();
|
||||
updatePositions();
|
||||
}
|
||||
|
||||
public boolean remove(T line) {
|
||||
@ -92,7 +93,7 @@ public class BaseHologramLines<T extends EditableHologramLine> implements Iterab
|
||||
boolean removed = lines.remove(line);
|
||||
if (removed) {
|
||||
line.setDeleted();
|
||||
updateLinePositions();
|
||||
updatePositions();
|
||||
}
|
||||
return removed;
|
||||
}
|
||||
@ -114,7 +115,7 @@ public class BaseHologramLines<T extends EditableHologramLine> implements Iterab
|
||||
* The top part of the first line should be exactly on the Y position of the hologram.
|
||||
* The second line is below the first, and so on.
|
||||
*/
|
||||
public void updateLinePositions() {
|
||||
public void updatePositions() {
|
||||
HologramPosition hologramPosition = hologram.getPosition();
|
||||
double currentLineY = hologramPosition.getY();
|
||||
|
||||
@ -151,7 +152,7 @@ public class BaseHologramLines<T extends EditableHologramLine> implements Iterab
|
||||
}
|
||||
}
|
||||
|
||||
private void checkNotDeleted() {
|
||||
protected void checkNotDeleted() {
|
||||
hologram.checkNotDeleted();
|
||||
}
|
||||
|
||||
|
@ -26,7 +26,7 @@ public class InternalHologram extends BaseHologram {
|
||||
}
|
||||
|
||||
@Override
|
||||
public BaseHologramLines<InternalHologramLine> getLines() {
|
||||
public BaseHologramLines<InternalHologramLine> lines() {
|
||||
return lines;
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user