diff --git a/README.md b/README.md index db90529..f02bcae 100644 --- a/README.md +++ b/README.md @@ -69,7 +69,7 @@ private HologramManager hologramManager; public void onEnable() { hologramManager = HologramAPI.getManager().orElse(null); if (hologramManager == null) { - getLogger().severe("Failed to initialize HologramAPI manager."); + getLogger().severe("Failed to initialize HologramLib manager."); return; } } diff --git a/build.gradle b/build.gradle index c2b372f..1bf3fbe 100644 --- a/build.gradle +++ b/build.gradle @@ -4,7 +4,7 @@ plugins { } group = 'com.maximde' -version = '1.4.8' +version = '1.5.0' repositories { @@ -62,5 +62,5 @@ processResources { shadowJar { minimize() - archiveFileName.set("HologramAPI-${version}.jar") + archiveFileName.set("HologramLib-${version}.jar") } \ No newline at end of file diff --git a/src/main/java/com/maximde/hologramapi/HologramAPI.java b/src/main/java/com/maximde/hologramlib/HologramLib.java similarity index 81% rename from src/main/java/com/maximde/hologramapi/HologramAPI.java rename to src/main/java/com/maximde/hologramlib/HologramLib.java index 0ae3e59..c6a3525 100644 --- a/src/main/java/com/maximde/hologramapi/HologramAPI.java +++ b/src/main/java/com/maximde/hologramlib/HologramLib.java @@ -1,12 +1,12 @@ -package com.maximde.hologramapi; +package com.maximde.hologramlib; import com.github.retrooper.packetevents.PacketEvents; import com.github.retrooper.packetevents.PacketEventsAPI; import com.github.retrooper.packetevents.manager.player.PlayerManager; -import com.maximde.hologramapi.bstats.Metrics; -import com.maximde.hologramapi.hologram.HologramManager; -import com.maximde.hologramapi.utils.ItemsAdderHolder; -import com.maximde.hologramapi.utils.ReplaceText; +import com.maximde.hologramlib.bstats.Metrics; +import com.maximde.hologramlib.hologram.HologramManager; +import com.maximde.hologramlib.utils.ItemsAdderHolder; +import com.maximde.hologramlib.utils.ReplaceText; import io.github.retrooper.packetevents.factory.spigot.SpigotPacketEventsBuilder; import lombok.Getter; import lombok.SneakyThrows; @@ -20,25 +20,21 @@ import java.util.Optional; import java.util.logging.Level; -public final class HologramAPI extends JavaPlugin { +@Getter +public final class HologramLib extends JavaPlugin { - private static volatile HologramAPI instance; + private static volatile HologramLib instance; - @Getter private ReplaceText replaceText; - - @Getter private PlayerManager playerManager; - - @Getter private HologramManager hologramManager; public static Optional getManager() { return Optional.ofNullable(getInstance().hologramManager) .or(() -> { Bukkit.getLogger().log(Level.SEVERE, - "HologramAPI has not been initialized yet. " + - "Ensure 'HologramAPI' is included as a dependency in your plugin.yml."); + "HologramLib has not been initialized yet. " + + "Ensure 'HologramLib' is included as a dependency in your plugin.yml."); return Optional.empty(); }); } @@ -47,7 +43,7 @@ public static Optional getManager() { public static Optional getManager(Plugin plugin) { if (!(plugin instanceof JavaPlugin)) { Bukkit.getLogger().log(Level.SEVERE, - "Unable to initialize HologramAPI: Provided plugin is not a valid JavaPlugin."); + "Unable to initialize HologramLib: Provided plugin is not a valid JavaPlugin."); return Optional.empty(); } @@ -55,12 +51,12 @@ public static Optional getManager(Plugin plugin) { return Optional.of(instance.hologramManager); } - synchronized (HologramAPI.class) { + synchronized (HologramLib.class) { if (instance == null) { Bukkit.getLogger().log(Level.INFO, - "Initializing HologramAPI from a shaded plugin context."); + "Initializing HologramLib from a shaded plugin context."); - HologramAPI api = new HologramAPI(); + HologramLib api = new HologramLib(); api.onLoad(); api.onEnable(); @@ -92,7 +88,7 @@ public void onEnable() { initializeMetrics(); initializeReplaceText(); } catch (Exception e) { - getLogger().log(Level.SEVERE, "Failed to enable HologramAPI", e); + getLogger().log(Level.SEVERE, "Failed to enable HologramLib", e); Bukkit.getPluginManager().disablePlugin(this); } } @@ -137,9 +133,9 @@ public void onDisable() { instance = null; } - public static synchronized HologramAPI getInstance() { + public static synchronized HologramLib getInstance() { if (instance == null) { - throw new IllegalStateException("HologramAPI has not been initialized"); + throw new IllegalStateException("HologramLib has not been initialized"); } return instance; } diff --git a/src/main/java/com/maximde/hologramapi/bstats/Metrics.java b/src/main/java/com/maximde/hologramlib/bstats/Metrics.java similarity index 99% rename from src/main/java/com/maximde/hologramapi/bstats/Metrics.java rename to src/main/java/com/maximde/hologramlib/bstats/Metrics.java index 66e33d1..07d8824 100644 --- a/src/main/java/com/maximde/hologramapi/bstats/Metrics.java +++ b/src/main/java/com/maximde/hologramlib/bstats/Metrics.java @@ -12,7 +12,7 @@ * * Violations will result in a ban of your plugin and account from bStats. */ -package com.maximde.hologramapi.bstats; +package com.maximde.hologramlib.bstats; import java.io.BufferedReader; import java.io.ByteArrayOutputStream; diff --git a/src/main/java/com/maximde/hologramapi/hologram/HologramManager.java b/src/main/java/com/maximde/hologramlib/hologram/HologramManager.java similarity index 95% rename from src/main/java/com/maximde/hologramapi/hologram/HologramManager.java rename to src/main/java/com/maximde/hologramlib/hologram/HologramManager.java index 8b429ae..213811b 100644 --- a/src/main/java/com/maximde/hologramapi/hologram/HologramManager.java +++ b/src/main/java/com/maximde/hologramlib/hologram/HologramManager.java @@ -1,9 +1,9 @@ -package com.maximde.hologramapi.hologram; +package com.maximde.hologramlib.hologram; import com.github.retrooper.packetevents.protocol.entity.type.EntityTypes; import com.github.retrooper.packetevents.util.Vector3d; import com.github.retrooper.packetevents.wrapper.play.server.WrapperPlayServerSpawnEntity; -import com.maximde.hologramapi.HologramAPI; +import com.maximde.hologramlib.HologramLib; import lombok.*; import lombok.experimental.Accessors; import org.bukkit.Bukkit; @@ -130,7 +130,7 @@ public TextHologram spawn(TextHologram textHologram, Location location) { textHologram.getEntityID(), Optional.of(UUID.randomUUID()), EntityTypes.TEXT_DISPLAY, new Vector3d(location.getX(), location.getY() + 1, location.getZ()), 0f, 0f, 0f, 0, Optional.empty() ); - Bukkit.getServer().getScheduler().runTask(HologramAPI.getInstance(), () -> { + Bukkit.getServer().getScheduler().runTask(HologramLib.getInstance(), () -> { textHologram.getInternalAccess().updateAffectedPlayers(); textHologram.getInternalAccess().sendPacket(packet); textHologram.getInternalAccess().setDead(false); @@ -141,7 +141,11 @@ public TextHologram spawn(TextHologram textHologram, Location location) { } public void attach(TextHologram textHologram, int entityID) { - textHologram.attach(textHologram, entityID); + this.attach(textHologram, entityID, true); + } + + public void attach(TextHologram textHologram, int entityID, boolean persistent) { + textHologram.attach(textHologram, entityID, persistent); } public boolean register(TextHologram textHologram) { @@ -195,7 +199,7 @@ public void run() { } }; - animation.runTaskTimerAsynchronously(HologramAPI.getInstance(), textAnimation.getDelay(), textAnimation.getSpeed()); + animation.runTaskTimerAsynchronously(HologramLib.getInstance(), textAnimation.getDelay(), textAnimation.getSpeed()); return animation; } diff --git a/src/main/java/com/maximde/hologramapi/hologram/RenderMode.java b/src/main/java/com/maximde/hologramlib/hologram/RenderMode.java similarity index 91% rename from src/main/java/com/maximde/hologramapi/hologram/RenderMode.java rename to src/main/java/com/maximde/hologramlib/hologram/RenderMode.java index 05f60b4..6c8fbad 100644 --- a/src/main/java/com/maximde/hologramapi/hologram/RenderMode.java +++ b/src/main/java/com/maximde/hologramlib/hologram/RenderMode.java @@ -1,4 +1,4 @@ -package com.maximde.hologramapi.hologram; +package com.maximde.hologramlib.hologram; /** * Defines how a hologram should be rendered and to which players. diff --git a/src/main/java/com/maximde/hologramapi/hologram/TextAnimation.java b/src/main/java/com/maximde/hologramlib/hologram/TextAnimation.java similarity index 96% rename from src/main/java/com/maximde/hologramapi/hologram/TextAnimation.java rename to src/main/java/com/maximde/hologramlib/hologram/TextAnimation.java index 84d3c25..7fbe663 100644 --- a/src/main/java/com/maximde/hologramapi/hologram/TextAnimation.java +++ b/src/main/java/com/maximde/hologramlib/hologram/TextAnimation.java @@ -1,4 +1,4 @@ -package com.maximde.hologramapi.hologram; +package com.maximde.hologramlib.hologram; import lombok.Getter; import lombok.Setter; diff --git a/src/main/java/com/maximde/hologramapi/hologram/TextHologram.java b/src/main/java/com/maximde/hologramlib/hologram/TextHologram.java similarity index 95% rename from src/main/java/com/maximde/hologramapi/hologram/TextHologram.java rename to src/main/java/com/maximde/hologramlib/hologram/TextHologram.java index 03c9e8b..257d15e 100644 --- a/src/main/java/com/maximde/hologramapi/hologram/TextHologram.java +++ b/src/main/java/com/maximde/hologramlib/hologram/TextHologram.java @@ -1,4 +1,4 @@ -package com.maximde.hologramapi.hologram; +package com.maximde.hologramlib.hologram; import com.github.retrooper.packetevents.protocol.entity.type.EntityTypes; import com.github.retrooper.packetevents.util.Quaternion4f; @@ -8,9 +8,9 @@ import com.github.retrooper.packetevents.wrapper.play.server.WrapperPlayServerEntityTeleport; import com.github.retrooper.packetevents.wrapper.play.server.WrapperPlayServerSetPassengers; import com.github.retrooper.packetevents.wrapper.play.server.WrapperPlayServerSpawnEntity; -import com.maximde.hologramapi.HologramAPI; -import com.maximde.hologramapi.utils.MiniMessage; -import com.maximde.hologramapi.utils.Vector3F; +import com.maximde.hologramlib.HologramLib; +import com.maximde.hologramlib.utils.MiniMessage; +import com.maximde.hologramlib.utils.Vector3F; import io.github.retrooper.packetevents.util.SpigotConversionUtil; import lombok.Getter; import lombok.Setter; @@ -225,7 +225,7 @@ private void validateId(String id) { private void startRunnable() { if (task != null) return; - task = Bukkit.getServer().getScheduler().runTaskTimer(HologramAPI.getInstance(), this::updateAffectedPlayers, 60L, updateTaskPeriod); + task = Bukkit.getServer().getScheduler().runTaskTimer(HologramLib.getInstance(), this::updateAffectedPlayers, 60L, updateTaskPeriod); } /** @@ -233,11 +233,12 @@ private void startRunnable() { * * @param textHologram The hologram to attach * @param entityID The entity ID to attach the hologram to + * @param persistent If the hologram should be re-attached automatically or not TODO */ - public void attach(TextHologram textHologram, int entityID) { + public void attach(TextHologram textHologram, int entityID, boolean persistent) { int[] hologramToArray = { textHologram.getEntityID() }; WrapperPlayServerSetPassengers attachPacket = new WrapperPlayServerSetPassengers(entityID, hologramToArray); - Bukkit.getServer().getScheduler().runTask(HologramAPI.getInstance(), () -> { + Bukkit.getServer().getScheduler().runTask(HologramLib.getInstance(), () -> { sendPacket(attachPacket); }); } @@ -247,7 +248,7 @@ public void attach(TextHologram textHologram, int entityID) { * Should be called after making any changes to the hologram object. */ public TextHologram update() { - Bukkit.getServer().getScheduler().runTask(HologramAPI.getInstance(), () -> { + Bukkit.getServer().getScheduler().runTask(HologramLib.getInstance(), () -> { updateAffectedPlayers(); TextDisplayMeta meta = createMeta(); sendPacket(meta.createPacket()); @@ -388,7 +389,7 @@ public TextHologram setMiniMessageText(String text) { } private String replaceFontImages(String string) { - return HologramAPI.getInstance().getReplaceText().replace(string); + return HologramLib.getInstance().getReplaceText().replace(string); } private void updateAffectedPlayers() { @@ -397,7 +398,7 @@ private void updateAffectedPlayers() { .filter(player -> player.isOnline() && (player.getWorld() != this.location.getWorld() || player.getLocation().distance(this.location) > 20)) .peek(player -> { WrapperPlayServerDestroyEntities packet = new WrapperPlayServerDestroyEntities(this.entityID); - HologramAPI.getInstance().getPlayerManager().sendPacket(player, packet); + HologramLib.getInstance().getPlayerManager().sendPacket(player, packet); }) .toList(); viewers.removeAll(toRemove); @@ -427,11 +428,11 @@ private void updateAffectedPlayers() { private void sendPacket(PacketWrapper packet) { if (this.renderMode == RenderMode.NONE) return; - viewers.forEach(player -> HologramAPI.getInstance().getPlayerManager().sendPacket(player, packet)); + viewers.forEach(player -> HologramLib.getInstance().getPlayerManager().sendPacket(player, packet)); } private void sendPacket(PacketWrapper packet, List players) { if (this.renderMode == RenderMode.NONE) return; - players.forEach(player -> HologramAPI.getInstance().getPlayerManager().sendPacket(player, packet)); + players.forEach(player -> HologramLib.getInstance().getPlayerManager().sendPacket(player, packet)); } } diff --git a/src/main/java/com/maximde/hologramapi/utils/ItemsAdderHolder.java b/src/main/java/com/maximde/hologramlib/utils/ItemsAdderHolder.java similarity index 84% rename from src/main/java/com/maximde/hologramapi/utils/ItemsAdderHolder.java rename to src/main/java/com/maximde/hologramlib/utils/ItemsAdderHolder.java index a156729..37645a6 100644 --- a/src/main/java/com/maximde/hologramapi/utils/ItemsAdderHolder.java +++ b/src/main/java/com/maximde/hologramlib/utils/ItemsAdderHolder.java @@ -1,4 +1,4 @@ -package com.maximde.hologramapi.utils; +package com.maximde.hologramlib.utils; import dev.lone.itemsadder.api.FontImages.FontImageWrapper; import org.bukkit.Bukkit; @@ -9,7 +9,7 @@ public class ItemsAdderHolder implements ReplaceText { public ItemsAdderHolder() throws ClassNotFoundException { if (Bukkit.getPluginManager().getPlugin("ItemsAdder") == null) { - Bukkit.getLogger().log(Level.WARNING, "[HologramAPI] ItemsAdder plugin not found! No custom emojis support."); + Bukkit.getLogger().log(Level.WARNING, "[HologramLib] ItemsAdder plugin not found! No custom emojis support."); throw new ClassNotFoundException(); } } diff --git a/src/main/java/com/maximde/hologramapi/utils/MiniMessage.java b/src/main/java/com/maximde/hologramlib/utils/MiniMessage.java similarity index 89% rename from src/main/java/com/maximde/hologramapi/utils/MiniMessage.java rename to src/main/java/com/maximde/hologramlib/utils/MiniMessage.java index 66912d0..9040b28 100644 --- a/src/main/java/com/maximde/hologramapi/utils/MiniMessage.java +++ b/src/main/java/com/maximde/hologramlib/utils/MiniMessage.java @@ -1,4 +1,4 @@ -package com.maximde.hologramapi.utils; +package com.maximde.hologramlib.utils; import net.kyori.adventure.text.Component; diff --git a/src/main/java/com/maximde/hologramapi/utils/ReplaceText.java b/src/main/java/com/maximde/hologramlib/utils/ReplaceText.java similarity index 62% rename from src/main/java/com/maximde/hologramapi/utils/ReplaceText.java rename to src/main/java/com/maximde/hologramlib/utils/ReplaceText.java index 0ad6eed..deca937 100644 --- a/src/main/java/com/maximde/hologramapi/utils/ReplaceText.java +++ b/src/main/java/com/maximde/hologramlib/utils/ReplaceText.java @@ -1,4 +1,4 @@ -package com.maximde.hologramapi.utils; +package com.maximde.hologramlib.utils; public interface ReplaceText { String replace(String s); diff --git a/src/main/java/com/maximde/hologramapi/utils/Vector3F.java b/src/main/java/com/maximde/hologramlib/utils/Vector3F.java similarity index 97% rename from src/main/java/com/maximde/hologramapi/utils/Vector3F.java rename to src/main/java/com/maximde/hologramlib/utils/Vector3F.java index 2bb3ca1..3412d53 100644 --- a/src/main/java/com/maximde/hologramapi/utils/Vector3F.java +++ b/src/main/java/com/maximde/hologramlib/utils/Vector3F.java @@ -1,4 +1,4 @@ -package com.maximde.hologramapi.utils; +package com.maximde.hologramlib.utils; import lombok.Getter; import lombok.Setter; diff --git a/src/main/resources/plugin.yml b/src/main/resources/plugin.yml index 7e2ee2a..5f661b0 100644 --- a/src/main/resources/plugin.yml +++ b/src/main/resources/plugin.yml @@ -1,6 +1,6 @@ name: HologramAPI version: '${version}' -main: com.maximde.hologramapi.HologramAPI +main: com.maximde.hologramlib.HologramLib api-version: 1.19 author: MaximDe