Skip to content

Commit

Permalink
Adds FancyHolograms driver
Browse files Browse the repository at this point in the history
  • Loading branch information
anjoismysign committed Jul 31, 2024
1 parent e9995a4 commit b6efe17
Show file tree
Hide file tree
Showing 8 changed files with 205 additions and 41 deletions.
11 changes: 11 additions & 0 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,11 @@
<id>md_5-public</id>
<url>https://repo.md-5.net/content/groups/public/</url>
</repository>
<repository>
<id>fancyplugins-releases</id>
<name>FancyPlugins Repository</name>
<url>https://repo.fancyplugins.de/releases</url>
</repository>
</repositories>

<dependencies>
Expand Down Expand Up @@ -143,6 +148,12 @@
<artifactId>blis</artifactId>
<version>1.0.1</version>
</dependency>
<dependency>
<groupId>de.oliver</groupId>
<artifactId>FancyHolograms</artifactId>
<version>2.3.0</version>
<scope>provided</scope>
</dependency>
</dependencies>
<distributionManagement>
<repository>
Expand Down
27 changes: 22 additions & 5 deletions src/main/java/us/mytheria/bloblib/api/BlobLibHologramAPI.java
Original file line number Diff line number Diff line change
@@ -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;

Expand All @@ -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<String> lines) {
plugin.getHologramManager().create(name, location, lines);
getHologramDriver().create(name, location, lines);
}

/**
Expand All @@ -44,36 +53,44 @@ public void createHologram(String name, Location location, List<String> 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<String> 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);
}

/**
* Sets a hologram's lines
*
* @param name name of hologram
* @param lines lines of hologram
* @deprecated Use {@link #getHologramDriver()} instead
*/
@Deprecated
public void setHologramLines(String name, List<String> lines) {
plugin.getHologramManager().setLines(name, lines);
getHologramDriver().setLines(name, lines);
}
}
37 changes: 6 additions & 31 deletions src/main/java/us/mytheria/bloblib/hologram/Absent.java
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package us.mytheria.bloblib.hologram;

import org.bukkit.Location;
import org.jetbrains.annotations.NotNull;

import java.util.List;

Expand All @@ -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<String> 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<String> 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<String> lines) {
}

@Override
public @NotNull HologramDriverType getType() {
return HologramDriverType.ABSENT;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -33,4 +34,9 @@ public void setLines(String name, List<String> lines) {
Hologram hologram = DHAPI.getHologram(name);
DHAPI.setHologramLines(hologram, lines);
}

@Override
public @NotNull HologramDriverType getType() {
return HologramDriverType.DECENT_HOLOGRAMS;
}
}
125 changes: 125 additions & 0 deletions src/main/java/us/mytheria/bloblib/hologram/FancyHolograms.java
Original file line number Diff line number Diff line change
@@ -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<String> lines) {
create(name, location, lines, false);
}

@Override
public void create(String name,
Location location,
List<String> 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<String> 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<String> 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;
}
}
19 changes: 14 additions & 5 deletions src/main/java/us/mytheria/bloblib/hologram/HologramDriver.java
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -16,7 +17,7 @@ public interface HologramDriver {
void create(String name, Location location, List<String> 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
Expand All @@ -26,24 +27,32 @@ public interface HologramDriver {
void create(String name, Location location, List<String> 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<String> lines);

/**
* Gets the driver type
*
* @return The driver type
*/
@NotNull
HologramDriverType getType();
}
11 changes: 11 additions & 0 deletions src/main/java/us/mytheria/bloblib/hologram/HologramDriverType.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
package us.mytheria.bloblib.hologram;

public enum HologramDriverType {
DECENT_HOLOGRAMS,
FANCY_HOLOGRAMS,
ABSENT;

public boolean isAbsent() {
return this == ABSENT;
}
}
Loading

0 comments on commit b6efe17

Please sign in to comment.