From b6efe170995503505f4bdc1b7aacab5f7ac73d9e Mon Sep 17 00:00:00 2001 From: lbenav8095 Date: Wed, 31 Jul 2024 03:02:48 -0400 Subject: [PATCH] Adds FancyHolograms driver --- pom.xml | 11 ++ .../bloblib/api/BlobLibHologramAPI.java | 27 +++- .../us/mytheria/bloblib/hologram/Absent.java | 37 +----- .../bloblib/hologram/DecentHolograms.java | 6 + .../bloblib/hologram/FancyHolograms.java | 125 ++++++++++++++++++ .../bloblib/hologram/HologramDriver.java | 19 ++- .../bloblib/hologram/HologramDriverType.java | 11 ++ .../bloblib/hologram/HologramManager.java | 10 ++ 8 files changed, 205 insertions(+), 41 deletions(-) create mode 100644 src/main/java/us/mytheria/bloblib/hologram/FancyHolograms.java create mode 100644 src/main/java/us/mytheria/bloblib/hologram/HologramDriverType.java diff --git a/pom.xml b/pom.xml index 973da951..5ee57f37 100644 --- a/pom.xml +++ b/pom.xml @@ -44,6 +44,11 @@ md_5-public https://repo.md-5.net/content/groups/public/ + + fancyplugins-releases + FancyPlugins Repository + https://repo.fancyplugins.de/releases + @@ -143,6 +148,12 @@ blis 1.0.1 + + de.oliver + FancyHolograms + 2.3.0 + provided + diff --git a/src/main/java/us/mytheria/bloblib/api/BlobLibHologramAPI.java b/src/main/java/us/mytheria/bloblib/api/BlobLibHologramAPI.java index a1bc2646..14257ad9 100644 --- a/src/main/java/us/mytheria/bloblib/api/BlobLibHologramAPI.java +++ b/src/main/java/us/mytheria/bloblib/api/BlobLibHologramAPI.java @@ -1,7 +1,9 @@ package us.mytheria.bloblib.api; import org.bukkit.Location; +import org.jetbrains.annotations.NotNull; import us.mytheria.bloblib.BlobLib; +import us.mytheria.bloblib.hologram.HologramDriver; import java.util.List; @@ -26,15 +28,22 @@ public static BlobLibHologramAPI getInstance() { return getInstance(null); } + @NotNull + public HologramDriver getHologramDriver() { + return plugin.getHologramManager().getDriver(); + } + /** * Creates a hologram * * @param name name of hologram * @param location Bukkit's Location of hologram * @param lines lines of hologram + * @deprecated Use {@link #getHologramDriver()} instead */ + @Deprecated public void createHologram(String name, Location location, List lines) { - plugin.getHologramManager().create(name, location, lines); + getHologramDriver().create(name, location, lines); } /** @@ -44,27 +53,33 @@ public void createHologram(String name, Location location, List lines) { * @param location Bukkit's Location of hologram * @param lines lines of hologram * @param saveToConfig if true, hologram will be saved in configuration + * @deprecated Use {@link #getHologramDriver()} instead */ + @Deprecated public void createHologram(String name, Location location, List lines, boolean saveToConfig) { - plugin.getHologramManager().create(name, location, lines, saveToConfig); + getHologramDriver().create(name, location, lines, saveToConfig); } /** * Updates a hologram * * @param name name of hologram + * @deprecated Use {@link #getHologramDriver()} instead */ + @Deprecated public void updateHologram(String name) { - plugin.getHologramManager().update(name); + getHologramDriver().update(name); } /** * Deletes a hologram * * @param name name of hologram + * @deprecated Use {@link #getHologramDriver()} instead */ + @Deprecated public void removeHologram(String name) { - plugin.getHologramManager().remove(name); + getHologramDriver().remove(name); } /** @@ -72,8 +87,10 @@ public void removeHologram(String name) { * * @param name name of hologram * @param lines lines of hologram + * @deprecated Use {@link #getHologramDriver()} instead */ + @Deprecated public void setHologramLines(String name, List lines) { - plugin.getHologramManager().setLines(name, lines); + getHologramDriver().setLines(name, lines); } } diff --git a/src/main/java/us/mytheria/bloblib/hologram/Absent.java b/src/main/java/us/mytheria/bloblib/hologram/Absent.java index 63103098..9b7e51e6 100644 --- a/src/main/java/us/mytheria/bloblib/hologram/Absent.java +++ b/src/main/java/us/mytheria/bloblib/hologram/Absent.java @@ -1,6 +1,7 @@ package us.mytheria.bloblib.hologram; import org.bukkit.Location; +import org.jetbrains.annotations.NotNull; import java.util.List; @@ -9,54 +10,28 @@ */ public class Absent implements HologramDriver { - /** - * Does nothing since the driver is absent - * - * @param name the name of the hologram - * @param location the location of the hologram - * @param lines the lines of the hologram - */ @Override public void create(String name, Location location, List lines) { } - /** - * Does nothing since the driver is absent - * - * @param name the name of the hologram - * @param location the location of the hologram - * @param lines the lines of the hologram - * @param saveToConfig if the hologram should be saved to the config - */ @Override public void create(String name, Location location, List lines, boolean saveToConfig) { } - /** - * Does nothing since the driver is absent - * - * @param name the name of the hologram - */ @Override public void update(String name) { } - /** - * Does nothing since the driver is absent - * - * @param name the name of the hologram - */ @Override public void remove(String name) { } - /** - * Does nothing since the driver is absent - * - * @param name the name of the hologram - * @param lines the lines of the hologram - */ @Override public void setLines(String name, List lines) { } + + @Override + public @NotNull HologramDriverType getType() { + return HologramDriverType.ABSENT; + } } diff --git a/src/main/java/us/mytheria/bloblib/hologram/DecentHolograms.java b/src/main/java/us/mytheria/bloblib/hologram/DecentHolograms.java index 628d3780..bac9be28 100644 --- a/src/main/java/us/mytheria/bloblib/hologram/DecentHolograms.java +++ b/src/main/java/us/mytheria/bloblib/hologram/DecentHolograms.java @@ -3,6 +3,7 @@ import eu.decentsoftware.holograms.api.DHAPI; import eu.decentsoftware.holograms.api.holograms.Hologram; import org.bukkit.Location; +import org.jetbrains.annotations.NotNull; import java.util.List; @@ -33,4 +34,9 @@ public void setLines(String name, List lines) { Hologram hologram = DHAPI.getHologram(name); DHAPI.setHologramLines(hologram, lines); } + + @Override + public @NotNull HologramDriverType getType() { + return HologramDriverType.DECENT_HOLOGRAMS; + } } diff --git a/src/main/java/us/mytheria/bloblib/hologram/FancyHolograms.java b/src/main/java/us/mytheria/bloblib/hologram/FancyHolograms.java new file mode 100644 index 00000000..e4ec4536 --- /dev/null +++ b/src/main/java/us/mytheria/bloblib/hologram/FancyHolograms.java @@ -0,0 +1,125 @@ +package us.mytheria.bloblib.hologram; + +import de.oliver.fancyholograms.api.FancyHologramsPlugin; +import de.oliver.fancyholograms.api.HologramManager; +import de.oliver.fancyholograms.api.data.HologramData; +import de.oliver.fancyholograms.api.data.TextHologramData; +import de.oliver.fancyholograms.api.hologram.Hologram; +import org.bukkit.Color; +import org.bukkit.Location; +import org.bukkit.entity.Display; +import org.bukkit.entity.TextDisplay; +import org.jetbrains.annotations.NotNull; +import org.jetbrains.annotations.Nullable; +import org.joml.Vector3f; + +import java.util.List; + +public class FancyHolograms implements HologramDriver { + + @Override + public void create(String name, Location location, List lines) { + create(name, location, lines, false); + } + + @Override + public void create(String name, + Location location, + List lines, + boolean saveToConfig) { + create(name, + location, + lines, + saveToConfig, + false, + Color.fromARGB(0, 0, 0, 0), + null, + null, + false, + -1, + 0.0F, + 1.0F, + null, + null, + null); + } + + public void create(String name, + Location location, + List lines, + boolean saveToConfig, + boolean seeThrough, + @Nullable Color background, + @Nullable Display.Billboard billboard, + @Nullable TextDisplay.TextAlignment textAlignment, + boolean textShadow, + int textUpdateInterval, + float shadowRadius, + float shadowStrength, + @Nullable Display.Brightness brightness, + @Nullable Vector3f scale, + @Nullable Vector3f translation) { + HologramManager manager = FancyHologramsPlugin.get().getHologramManager(); + TextHologramData hologramData = new TextHologramData(name, location); + if (scale != null) + hologramData.setScale(scale); + if (translation != null) + hologramData.setTranslation(translation); + if (brightness != null) + hologramData.setBrightness(brightness); + hologramData.setShadowRadius(shadowRadius); + hologramData.setShadowStrength(shadowStrength); + hologramData.setTextUpdateInterval(textUpdateInterval); + hologramData.setTextShadow(textShadow); + if (textAlignment != null) + hologramData.setTextAlignment(textAlignment); + if (billboard != null) + hologramData.setBillboard(billboard); + hologramData.setSeeThrough(seeThrough); + if (background != null) + hologramData.setBackground(background); + hologramData.setPersistent(saveToConfig); + hologramData.setText(lines); + Hologram hologram = manager.create(hologramData); + manager.addHologram(hologram); + } + + @Nullable + public Hologram get(String name) { + HologramManager manager = FancyHologramsPlugin.get().getHologramManager(); + return manager.getHologram(name).orElse(null); + } + + @Override + public void update(String name) { + Hologram hologram = get(name); + if (hologram == null) + return; + hologram.refreshForViewers(); + } + + @Override + public void remove(String name) { + Hologram hologram = get(name); + if (hologram == null) + return; + hologram.deleteHologram(); + } + + @Override + public void setLines(String name, List lines) { + Hologram hologram = get(name); + if (hologram == null) + return; + HologramData hologramData = hologram.getData(); + if (hologramData instanceof TextHologramData textHologramData) { + textHologramData.setText(lines); + hologram.refreshForViewers(); + } + } + + @Override + public @NotNull HologramDriverType getType() { + return HologramDriverType.FANCY_HOLOGRAMS; + } +} diff --git a/src/main/java/us/mytheria/bloblib/hologram/HologramDriver.java b/src/main/java/us/mytheria/bloblib/hologram/HologramDriver.java index c959b9fe..5ec6d8a1 100644 --- a/src/main/java/us/mytheria/bloblib/hologram/HologramDriver.java +++ b/src/main/java/us/mytheria/bloblib/hologram/HologramDriver.java @@ -1,13 +1,14 @@ package us.mytheria.bloblib.hologram; import org.bukkit.Location; +import org.jetbrains.annotations.NotNull; import java.util.List; public interface HologramDriver { /** - * Creates an Hologram with the given arguments. + * Creates a Hologram with the given arguments. * * @param name Hologram ID * @param location Location of the Hologram @@ -16,7 +17,7 @@ public interface HologramDriver { void create(String name, Location location, List lines); /** - * Creates an Hologram with the given arguments. + * Creates a Hologram with the given arguments. * * @param name Hologram ID * @param location Location of the Hologram @@ -26,24 +27,32 @@ public interface HologramDriver { void create(String name, Location location, List lines, boolean saveToConfig); /** - * Updates an Hologram which ID equals 'name' argument. + * Updates a Hologram which ID equals 'name' argument. * * @param name Hologram ID */ void update(String name); /** - * Removes an Hologram which ID equals 'name' argument. + * Removes a Hologram which ID equals 'name' argument. * * @param name Hologram ID */ void remove(String name); /** - * Sets lines for an Hologram which ID equals 'name' argument. + * Sets lines for a Hologram which ID equals 'name' argument. * * @param name Hologram ID * @param lines Lines to set */ void setLines(String name, List lines); + + /** + * Gets the driver type + * + * @return The driver type + */ + @NotNull + HologramDriverType getType(); } diff --git a/src/main/java/us/mytheria/bloblib/hologram/HologramDriverType.java b/src/main/java/us/mytheria/bloblib/hologram/HologramDriverType.java new file mode 100644 index 00000000..6ba2a6b2 --- /dev/null +++ b/src/main/java/us/mytheria/bloblib/hologram/HologramDriverType.java @@ -0,0 +1,11 @@ +package us.mytheria.bloblib.hologram; + +public enum HologramDriverType { + DECENT_HOLOGRAMS, + FANCY_HOLOGRAMS, + ABSENT; + + public boolean isAbsent() { + return this == ABSENT; + } +} diff --git a/src/main/java/us/mytheria/bloblib/hologram/HologramManager.java b/src/main/java/us/mytheria/bloblib/hologram/HologramManager.java index 9939c46e..585d537b 100644 --- a/src/main/java/us/mytheria/bloblib/hologram/HologramManager.java +++ b/src/main/java/us/mytheria/bloblib/hologram/HologramManager.java @@ -2,6 +2,7 @@ import org.bukkit.Bukkit; import org.bukkit.Location; +import org.jetbrains.annotations.NotNull; import java.util.List; @@ -13,9 +14,18 @@ public HologramManager() { driver = new DecentHolograms(); return; } + if (Bukkit.getServer().getPluginManager().getPlugin("FancyHolograms") != null) { + driver = new FancyHolograms(); + return; + } driver = new Absent(); } + @NotNull + public HologramDriver getDriver() { + return driver; + } + public void create(String name, Location location, List lines) { driver.create(name, location, lines); }