Skip to content

Commit

Permalink
refactor: name to hologramlib
Browse files Browse the repository at this point in the history
  • Loading branch information
max1mde committed Dec 22, 2024
1 parent 449b770 commit 86a2b6e
Show file tree
Hide file tree
Showing 13 changed files with 51 additions and 50 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
}
Expand Down
4 changes: 2 additions & 2 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ plugins {
}

group = 'com.maximde'
version = '1.4.8'
version = '1.5.0'

repositories {

Expand Down Expand Up @@ -62,5 +62,5 @@ processResources {

shadowJar {
minimize()
archiveFileName.set("HologramAPI-${version}.jar")
archiveFileName.set("HologramLib-${version}.jar")
}
Original file line number Diff line number Diff line change
@@ -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;
Expand All @@ -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<HologramManager> 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();
});
}
Expand All @@ -47,20 +43,20 @@ public static Optional<HologramManager> getManager() {
public static Optional<HologramManager> 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();
}

if (instance != null && instance.hologramManager != null) {
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();

Expand Down Expand Up @@ -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);
}
}
Expand Down Expand Up @@ -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;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
Original file line number Diff line number Diff line change
@@ -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;
Expand Down Expand Up @@ -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);
Expand All @@ -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) {
Expand Down Expand Up @@ -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;
}

Expand Down
Original file line number Diff line number Diff line change
@@ -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.
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package com.maximde.hologramapi.hologram;
package com.maximde.hologramlib.hologram;

import lombok.Getter;
import lombok.Setter;
Expand Down
Original file line number Diff line number Diff line change
@@ -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;
Expand All @@ -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;
Expand Down Expand Up @@ -225,19 +225,20 @@ 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);
}

/**
* Attaches this hologram to another entity, making it ride the target entity.
*
* @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);
});
}
Expand All @@ -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());
Expand Down Expand Up @@ -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() {
Expand All @@ -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);
Expand Down Expand Up @@ -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<Player> 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));
}
}
Original file line number Diff line number Diff line change
@@ -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;
Expand All @@ -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();
}
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package com.maximde.hologramapi.utils;
package com.maximde.hologramlib.utils;

import net.kyori.adventure.text.Component;

Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package com.maximde.hologramapi.utils;
package com.maximde.hologramlib.utils;

public interface ReplaceText {
String replace(String s);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package com.maximde.hologramapi.utils;
package com.maximde.hologramlib.utils;

import lombok.Getter;
import lombok.Setter;
Expand Down
2 changes: 1 addition & 1 deletion src/main/resources/plugin.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
name: HologramAPI
version: '${version}'
main: com.maximde.hologramapi.HologramAPI
main: com.maximde.hologramlib.HologramLib
api-version: 1.19
author: MaximDe

Expand Down

0 comments on commit 86a2b6e

Please sign in to comment.