diff --git a/README.md b/README.md index 318d11d..d73e461 100644 --- a/README.md +++ b/README.md @@ -61,7 +61,7 @@ Fancy NPC plugin manager class with Decent Hologram as npc name-tag. com.aseanbte.aseanlib aseanlib-npc - 1.1.4 + 1.1.5 diff --git a/hologram/pom.xml b/hologram/pom.xml index 5508604..3dc8962 100644 --- a/hologram/pom.xml +++ b/hologram/pom.xml @@ -5,7 +5,7 @@ aseanlib com.aseanbte.aseanlib - 1.1.4 + 1.1.5 4.0.0 diff --git a/hologram/src/main/java/com/aseanbte/aseanlib/hologram/DecentHologramContent.java b/hologram/src/main/java/com/aseanbte/aseanlib/hologram/DecentHologramContent.java index fb1c930..7e74e47 100644 --- a/hologram/src/main/java/com/aseanbte/aseanlib/hologram/DecentHologramContent.java +++ b/hologram/src/main/java/com/aseanbte/aseanlib/hologram/DecentHologramContent.java @@ -29,14 +29,48 @@ import java.util.List; import java.util.UUID; +/** + * Display contents the hologram will be using.
+ * [1] ItemStack - Display item at the top of hologram.
+ * [2] Title - Header message atop the hologram.
+ * [3] Content - the main content to display.
+ * [4] Footer - footer line, this is default as a separator line. + */ public interface DecentHologramContent { + /** + * Display entity as minecraft item. + * This will be display at the top of hologram + * @return Minecraft ItemStack + */ ItemStack getItem(); - String getTitle(UUID var1); + /** + * Title message as String. + * @param playerUUID Focused player. + * @return The message. + */ + String getTitle(UUID playerUUID); - List> getHeader(UUID var1); + /** + * Header message as DataLine. + * By default, this is using the value from getTitle as a header with a separator line + * @param playerUUID Focused player. + * @return The DataLine. + */ + List> getHeader(UUID playerUUID); - List> getContent(UUID var1); + /** + * Main content to be written in the hologram + * @param playerUUID Focused player. + * @return The DataLine. + */ + List> getContent(UUID playerUUID); - List> getFooter(UUID var1); + /** + * The footer line at the bottom of the hologram. + * By default, this is a separator line. + * @param playerUUID Focused player. + * @return The DataLine. + */ + List> getFooter(UUID playerUUID); } \ No newline at end of file diff --git a/hologram/src/main/java/com/aseanbte/aseanlib/hologram/DecentHologramDisplay.java b/hologram/src/main/java/com/aseanbte/aseanlib/hologram/DecentHologramDisplay.java index ddc59e1..1f0d270 100644 --- a/hologram/src/main/java/com/aseanbte/aseanlib/hologram/DecentHologramDisplay.java +++ b/hologram/src/main/java/com/aseanbte/aseanlib/hologram/DecentHologramDisplay.java @@ -30,12 +30,9 @@ import java.util.HashMap; import java.util.List; import java.util.UUID; -import java.util.logging.Level; import eu.decentsoftware.holograms.api.DHAPI; -import eu.decentsoftware.holograms.api.DecentHolograms; import eu.decentsoftware.holograms.api.holograms.Hologram; -import eu.decentsoftware.holograms.api.DecentHologramsAPI; import eu.decentsoftware.holograms.api.holograms.HologramLine; import eu.decentsoftware.holograms.api.holograms.HologramPage; import eu.decentsoftware.holograms.event.HologramClickEvent; @@ -48,57 +45,83 @@ import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; +/** + * Wrapper class to use DecentHologram API, this creates and manage hologram per player. + * Meaning that individual player can see the hologram personally in multiplayer world. + */ public abstract class DecentHologramDisplay implements DecentHologramContent { public static List activeDisplays = new ArrayList<>(); - public static DecentHolograms decentHolograms; - public static String contentSeparator = "§7---------------"; - public static final String EMPTY_TAG = "&f"; - private final String id; - private Location position; - private boolean isEnabled; protected final HashMap holograms = new HashMap<>(); private ClickAction clickListener; + public static final String contentSeparator = "§7---------------"; + private final String id; + private Location location; + private boolean isEnabled; /** - * This action is executed when the player clicks on the 'mark as read' text on the hologram. + * Click action which is executed when the player clicks on the hologram on the hologram. */ @FunctionalInterface public interface ClickAction { void onClick(@NotNull HologramClickEvent clickEvent); } + /** + * Register hologram listener as DecentHologramListener Class. + * {@code DecentHologramDisplay.registerPlugin(this);} + * @param plugin Plugin in use of this library. + */ public static void registerPlugin(Plugin plugin) { - decentHolograms = DecentHologramsAPI.get(); plugin.getServer().getPluginManager().registerEvents(new DecentHologramListener(), plugin); } - public DecentHologramDisplay(@NotNull String id, Location position, boolean isEnabled) { + /** + * @param id Hologram identifier for creating DecentHologram name, this will later be concatenated as "${player.uuid}-${id}" + * @param location The location in a world to create hologram. + * @param isEnabled Force enable or disable this hologram on create, this will not register new hologram in the hashmap. + */ + public DecentHologramDisplay(@NotNull String id, Location location, boolean isEnabled) { this.id = id; - this.position = position; + this.location = location; this.isEnabled = isEnabled; activeDisplays.add(this); } + /** + * Create hologram for player to see. + * If the player has correct ViewPermission and hologram is configured enabled, + * the hologram will be created + * @param player The player that will be able to view this hologram + */ public void create(Player player) { - if(!isEnabled) return; - if (this.hasViewPermission(player.getUniqueId())) { - if (this.holograms.containsKey(player.getUniqueId())) { - this.reload(player.getUniqueId()); - } else { - Bukkit.getLogger().log(Level.INFO, "[DHAPI] Created display ID: " + id + " For player: " + player.getUniqueId()); - Hologram hologram = DHAPI.createHologram(player.getUniqueId() + "-" + id, position); - // Allow only player to see - hologram.setDefaultVisibleState(false); - hologram.setShowPlayer(player); - - this.holograms.put(player.getUniqueId(), hologram); - this.reload(player.getUniqueId()); - } + if(!isEnabled | !this.hasViewPermission(player.getUniqueId())) return; + if (this.holograms.containsKey(player.getUniqueId())) { + this.reload(player.getUniqueId()); + } else { + Bukkit.getConsoleSender().sendMessage("[DHAPI] Created display ID: " + id + " For player: " + player.getUniqueId()); + Hologram hologram = DHAPI.createHologram(player.getUniqueId() + "-" + id, location); + + // Exclude all player to view this then allow only player to see + hologram.setDefaultVisibleState(false); + hologram.setShowPlayer(player); + + this.holograms.put(player.getUniqueId(), hologram); + this.reload(player.getUniqueId()); } } - public abstract boolean hasViewPermission(UUID var1); + /** + * Abstract method to add functionality to whether a player creating this hologram can view it or not. + * @param playerUUID Focused player. + * @return If true, the hologram will be created for player. Else not. + */ + public abstract boolean hasViewPermission(UUID playerUUID); + /** + * Check if a player can view this hologram. + * @param playerUUID Focused player. + * @return True if hologram is visible to player. + */ public boolean isVisible(UUID playerUUID) { return this.holograms.containsKey(playerUUID); } @@ -111,6 +134,10 @@ public List> getFooter(UUID playerUUID) { return Collections.singletonList(new TextLine(contentSeparator)); } + /** + * Re-Write hologram dataLines received by getHeader(), getContent() and getFooter() in order. + * @param playerUUID Focused player. + */ public void reload(UUID playerUUID) { if (!holograms.containsKey(playerUUID)) return; List> dataLines = new ArrayList<>(); @@ -127,10 +154,17 @@ public void reload(UUID playerUUID) { updateDataLines(holograms.get(playerUUID).getPage(0), 0, dataLines); } + /** + * Call the reload method on all holograms. + */ public void reloadAll() { for (UUID playerUUID : holograms.keySet()) reload(playerUUID); } + /** + * Remove a hologram assigned to this display from player access. + * @param playerUUID Focused player. + */ public void remove(UUID playerUUID) { if (this.holograms.containsKey(playerUUID)) { DHAPI.removeHologram(playerUUID + "-" + id); @@ -140,40 +174,72 @@ public void remove(UUID playerUUID) { this.holograms.remove(playerUUID); } + /** + * Remove all assigned hologram this display has, + * this still does not remove the display itself + */ public void removeAll() { List playerUUIDs = new ArrayList<>(holograms.keySet()); for (UUID playerUUID : playerUUIDs) remove(playerUUID); } + /** + * Delete this display entirely + */ public void delete() { this.removeAll(); this.holograms.clear(); activeDisplays.remove(this); } + /** + * Get the identifier from when this hologram is first constructed. + * @return ID as String. + */ public String getId() { return this.id; } + /** + * Get the hologram location. + * @return hologram location. + */ public Location getLocation() { - return this.position; + return this.location; } - public void setLocation(Location newPosition) { - this.position = newPosition; + this.location = newPosition; for (UUID playerUUID : holograms.keySet()) holograms.get(playerUUID).setLocation(newPosition); } + /** + * Is this hologram enabled. + * @return Is enabled. + */ public boolean isEnabled() { return this.isEnabled; } + + /** + * Force set the hologram enabled or disabled. + * @param isEnabled If false, the hologram will not be created in any way. + */ public void setEnabled(boolean isEnabled) { this.isEnabled = isEnabled; } + /** + * Get hologram instance mapped in this display. + * @param playerUUID Focused player. + * @return Hologram object from DecentHologram plugin. + */ public Hologram getHologram(UUID playerUUID) { return this.holograms.get(playerUUID); } + /** + * Get all the mapped hologram in this display. + * @return HashMap of Hologram by a player UUID. + */ public HashMap getHolograms() { return this.holograms; } @@ -248,25 +314,42 @@ protected static void replaceLine(HologramPage page, int line, String text) { } + /** + * Assign a click listener to this hologram, a ClickAction will be call when anyone clicks the hologram. + * This should be called right when reloading the hologram + *
{@code
+     * @Override
+     * public void reload(UUID playerUUID) {
+     *     super.reload(playerUUID);
+     *     super.setClickListener((clickEvent) -> {});
+     * }
+ * @param clickListener Action callback. + */ public void setClickListener(@Nullable ClickAction clickListener) { this.clickListener = clickListener; } - public @Nullable ClickAction getClickListener() { return this.clickListener; } - + /** + * Get activeDisplays in DecentHologramDisplay by ID + * @param id The id first used to construct a new DecentHologramDisplay + * @return The hologram assigned to id. + */ public static DecentHologramDisplay getById(String id) { - return (DecentHologramDisplay) activeDisplays.stream().filter((holo) -> { - return holo.getId().equals(id); - }).findFirst().orElse((DecentHologramDisplay)null); + return activeDisplays.stream().filter(holo -> holo.getId().equals(id)).findFirst().orElse(null); } - public interface DataLine { - T getLine(); - } + /** + * DataLine of any type, acts as a text lines per hologram page. + * @param DataLine type, this can only be ItemStack as ItemLine or String as TextLine + */ + public interface DataLine { T getLine(); } + /** + * Minecraft ItemStack as DataLine + */ public static class ItemLine implements DataLine { private final ItemStack line; @@ -279,6 +362,9 @@ public ItemStack getLine() { } } + /** + * String as DataLine + */ public static class TextLine implements DataLine { private final String line; @@ -290,4 +376,4 @@ public String getLine() { return this.line; } } -} +} \ No newline at end of file diff --git a/hologram/src/main/java/com/aseanbte/aseanlib/hologram/DecentHologramListener.java b/hologram/src/main/java/com/aseanbte/aseanlib/hologram/DecentHologramListener.java index 6c732d8..ee92f2a 100644 --- a/hologram/src/main/java/com/aseanbte/aseanlib/hologram/DecentHologramListener.java +++ b/hologram/src/main/java/com/aseanbte/aseanlib/hologram/DecentHologramListener.java @@ -31,6 +31,8 @@ import org.bukkit.event.player.PlayerJoinEvent; import org.bukkit.event.player.PlayerQuitEvent; +import java.util.Objects; + public class DecentHologramListener implements Listener { public DecentHologramListener() { @@ -38,10 +40,9 @@ public DecentHologramListener() { @EventHandler public void onPlayerJoinEvent(PlayerJoinEvent event) { - // Create player's hologram each time they join for (DecentHologramDisplay display : DecentHologramDisplay.activeDisplays) { if (display.getLocation() == null) return; - if (display.getLocation().getWorld().getName().equals(event.getPlayer().getWorld().getName())) + if (Objects.requireNonNull(display.getLocation().getWorld()).getName().equals(event.getPlayer().getWorld().getName())) display.create(event.getPlayer()); } @@ -58,7 +59,7 @@ public void onPlayerQuitEvent(PlayerQuitEvent event) { public void onPlayerChangedWorldEvent(PlayerChangedWorldEvent event) { for (DecentHologramDisplay display : DecentHologramDisplay.activeDisplays) { if (display.getLocation() == null) return; - if (display.getLocation().getWorld().getName().equals(event.getFrom().getName())) display.remove(event.getPlayer().getUniqueId()); + if (Objects.requireNonNull(display.getLocation().getWorld()).getName().equals(event.getFrom().getName())) display.remove(event.getPlayer().getUniqueId()); else if (display.getLocation().getWorld().getName().equals(event.getPlayer().getWorld().getName())) display.create(event.getPlayer()); } diff --git a/hologram/src/main/java/com/aseanbte/aseanlib/hologram/DecentHologramPagedDisplay.java b/hologram/src/main/java/com/aseanbte/aseanlib/hologram/DecentHologramPagedDisplay.java index d79fdd7..a4bf9e5 100644 --- a/hologram/src/main/java/com/aseanbte/aseanlib/hologram/DecentHologramPagedDisplay.java +++ b/hologram/src/main/java/com/aseanbte/aseanlib/hologram/DecentHologramPagedDisplay.java @@ -44,7 +44,7 @@ public abstract class DecentHologramPagedDisplay extends DecentHologramDisplay { private int changeState = 0; private long changeDelay = 0; private final Plugin plugin; - private static String contentSeparator = "§7---------------"; + private static final String contentSeparator = "§7---------------"; protected boolean automaticallySkipPage = true; public DecentHologramPagedDisplay(@NotNull String id, Location position, boolean isEnabled, @NotNull Plugin plugin) { diff --git a/http/pom.xml b/http/pom.xml index f96de06..ddc3e9d 100644 --- a/http/pom.xml +++ b/http/pom.xml @@ -5,7 +5,7 @@ aseanlib com.aseanbte.aseanlib - 1.1.4 + 1.1.5 4.0.0 diff --git a/io/pom.xml b/io/pom.xml index 2abfbe4..5adb3a8 100644 --- a/io/pom.xml +++ b/io/pom.xml @@ -5,7 +5,7 @@ aseanlib com.aseanbte.aseanlib - 1.1.4 + 1.1.5 4.0.0 @@ -56,7 +56,7 @@ com.aseanbte.aseanlib aseanlib-utils - 1.1.4 + 1.1.5 provided diff --git a/jitpack.yml b/jitpack.yml new file mode 100644 index 0000000..f29a667 --- /dev/null +++ b/jitpack.yml @@ -0,0 +1,5 @@ +jdk: + - openjdk17 +before_install: + - sdk install java 17.0.1-open + - sdk use java 17.0.1-open \ No newline at end of file diff --git a/libpsterra/pom.xml b/libpsterra/pom.xml index 11526d2..d3dccf8 100644 --- a/libpsterra/pom.xml +++ b/libpsterra/pom.xml @@ -5,7 +5,7 @@ aseanlib com.aseanbte.aseanlib - 1.1.4 + 1.1.5 4.0.0 @@ -48,14 +48,14 @@ com.aseanbte.aseanlib aseanlib-utils - 1.1.4 + 1.1.5 com.aseanbte.aseanlib aseanlib-io - 1.1.4 + 1.1.5 diff --git a/npc/pom.xml b/npc/pom.xml index 9f02030..419eeec 100644 --- a/npc/pom.xml +++ b/npc/pom.xml @@ -5,7 +5,7 @@ aseanlib com.aseanbte.aseanlib - 1.1.4 + 1.1.5 4.0.0 @@ -14,8 +14,8 @@ AseanLib-NPC - 17 - 17 + 1.8 + 1.8 UTF-8 @@ -54,7 +54,7 @@ com.aseanbte.aseanlib aseanlib-hologram - 1.1.4 + 1.1.5 provided diff --git a/npc/src/main/java/com/aseanbte/aseanlib/npc/AbstractNpc.java b/npc/src/main/java/com/aseanbte/aseanlib/npc/AbstractNpc.java index 2a05859..75e03fd 100644 --- a/npc/src/main/java/com/aseanbte/aseanlib/npc/AbstractNpc.java +++ b/npc/src/main/java/com/aseanbte/aseanlib/npc/AbstractNpc.java @@ -37,7 +37,7 @@ public abstract class AbstractNpc { public static final List activeNPCs = new ArrayList<>(); - private static final String EMPTY_TAG = ""; + private static final String EMPTY_TAG = "&f"; private static final String IDENTIFIER_TAG = "alpslib_"; public abstract String getDisplayName(UUID playerUUID); @@ -78,7 +78,7 @@ public void show(Player player) { Bukkit.getScheduler().runTaskAsynchronously(FancyNpcs.getInstance().getPlugin(), () -> { npc.getData().showToPlayer(player.getUniqueId()); npc.spawn(player); - if (hologram != null && player.getWorld().getName().equals(hologram.getLocation().getWorld().getName())) + if (hologram != null && player.getWorld().getName().equals(Objects.requireNonNull(hologram.getLocation().getWorld()).getName())) hologram.create(player); }); } @@ -89,7 +89,7 @@ public void showForAll() { npc.spawnForAll(); if (hologram != null) { Bukkit.getOnlinePlayers().forEach(player -> { - if (player.getWorld().getName().equals(hologram.getLocation().getWorld().getName())) + if (player.getWorld().getName().equals(Objects.requireNonNull(hologram.getLocation().getWorld()).getName())) Bukkit.getScheduler().runTask(FancyNpcs.getInstance().getPlugin(), () -> hologram.create(player)); }); } diff --git a/npc/src/main/java/com/aseanbte/aseanlib/npc/NpcHologram.java b/npc/src/main/java/com/aseanbte/aseanlib/npc/NpcHologram.java index 0fcbc25..34bc0b1 100644 --- a/npc/src/main/java/com/aseanbte/aseanlib/npc/NpcHologram.java +++ b/npc/src/main/java/com/aseanbte/aseanlib/npc/NpcHologram.java @@ -32,7 +32,12 @@ import org.bukkit.inventory.ItemStack; import org.jetbrains.annotations.NotNull; -import java.util.*; +import java.util.HashMap; +import java.util.UUID; +import java.util.Map; +import java.util.List; +import java.util.Collections; +import java.util.ArrayList; public class NpcHologram extends DecentHologramDisplay { private static final double NPC_HOLOGRAM_Y = 2.3; @@ -44,7 +49,7 @@ public class NpcHologram extends DecentHologramDisplay { private Location baseLocation; public NpcHologram(@NotNull String id, Location location, AbstractNpc npc) { - super(id, location.add(0, NPC_HOLOGRAM_Y, 0), true); + super(id, location.clone().add(0, NPC_HOLOGRAM_Y, 0), true); this.npc = npc; this.baseLocation = location; } @@ -97,9 +102,8 @@ public void setLocation(Location newLocation) { } public void setActionTitleVisibility(UUID playerUUID, boolean isVisible) { - Location nameLocation = baseLocation.clone(); isActionTitleVisible.put(playerUUID, isVisible); - getHologram(playerUUID).setLocation(nameLocation.add(0, isActionTitleVisible(playerUUID) ? + getHologram(playerUUID).setLocation(baseLocation.clone().add(0, isActionTitleVisible(playerUUID) ? NPC_HOLOGRAM_Y_WITH_ACTION_TITLE : NPC_HOLOGRAM_Y, 0)); reload(playerUUID); } diff --git a/pom.xml b/pom.xml index 0c5579f..67423a1 100644 --- a/pom.xml +++ b/pom.xml @@ -6,7 +6,7 @@ com.aseanbte.aseanlib aseanlib - 1.1.4 + 1.1.5 pom AseanLib diff --git a/utils/pom.xml b/utils/pom.xml index 666e496..2146bfc 100644 --- a/utils/pom.xml +++ b/utils/pom.xml @@ -5,7 +5,7 @@ aseanlib com.aseanbte.aseanlib - 1.1.4 + 1.1.5 4.0.0