Skip to content

Commit

Permalink
feat: 1.1.4 NPC and Hologram error and big fixes
Browse files Browse the repository at this point in the history
* fix hologram listener getting null player on an un-existing hologram

* fix hologram datalines writer not using DHAPI class

* fix npc hologram positioning that adds up recursively when changed to Location class

* edited some scheduling on creating and checking npc hologram view permission
  • Loading branch information
tintinkung committed Apr 23, 2024
1 parent 2213b14 commit b5cacfe
Show file tree
Hide file tree
Showing 12 changed files with 44 additions and 25 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ Fancy NPC plugin manager class with Decent Hologram as npc name-tag.
<dependency>
<groupId>com.aseanbte.aseanlib</groupId>
<artifactId>aseanlib-npc</artifactId>
<version>1.1.3</version>
<version>1.1.4</version>
</dependency>
<!-- FancyNpcs Plugin -->
<dependency>
Expand Down
2 changes: 1 addition & 1 deletion hologram/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
<parent>
<artifactId>aseanlib</artifactId>
<groupId>com.aseanbte.aseanlib</groupId>
<version>1.1.3</version>
<version>1.1.4</version>
</parent>
<modelVersion>4.0.0</modelVersion>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -192,7 +192,7 @@ protected static void updateDataLines(HologramPage page, int startIndex, List<Da
for(int i = 0; i < removeCount; ++i) {
int lineIndex = page.getLines().size() - 1;
if (lineIndex >= 0) {
page.getLines().remove(lineIndex);
DHAPI.removeHologramLine(page, lineIndex);
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,9 @@ public void onPlayerChangedWorldEvent(PlayerChangedWorldEvent event) {
@EventHandler
public void onHologramClick(HologramClickEvent event) {
for (DecentHologramDisplay display : DecentHologramDisplay.activeDisplays) {
if (display.getLocation() == null | display.getClickListener() == null) continue;
if (display.getLocation() == null
| display.getClickListener() == null
| display.getHologram(event.getPlayer().getUniqueId()) == null) continue;
if (display.getHologram(event.getPlayer().getUniqueId()).equals(event.getHologram()))
display.getClickListener().onClick(event);
}
Expand Down
2 changes: 1 addition & 1 deletion http/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
<parent>
<artifactId>aseanlib</artifactId>
<groupId>com.aseanbte.aseanlib</groupId>
<version>1.1.3</version>
<version>1.1.4</version>
</parent>
<modelVersion>4.0.0</modelVersion>

Expand Down
4 changes: 2 additions & 2 deletions io/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
<parent>
<artifactId>aseanlib</artifactId>
<groupId>com.aseanbte.aseanlib</groupId>
<version>1.1.3</version>
<version>1.1.4</version>
</parent>
<modelVersion>4.0.0</modelVersion>

Expand Down Expand Up @@ -56,7 +56,7 @@
<dependency>
<groupId>com.aseanbte.aseanlib</groupId>
<artifactId>aseanlib-utils</artifactId>
<version>1.1.3</version>
<version>1.1.4</version>
<scope>provided</scope>
</dependency>
</dependencies>
Expand Down
6 changes: 3 additions & 3 deletions libpsterra/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
<parent>
<artifactId>aseanlib</artifactId>
<groupId>com.aseanbte.aseanlib</groupId>
<version>1.1.3</version>
<version>1.1.4</version>
</parent>
<modelVersion>4.0.0</modelVersion>

Expand Down Expand Up @@ -48,14 +48,14 @@
<dependency>
<groupId>com.aseanbte.aseanlib</groupId>
<artifactId>aseanlib-utils</artifactId>
<version>1.1.3</version>
<version>1.1.4</version>
</dependency>

<!-- io from AlpsLib for config -->
<dependency>
<groupId>com.aseanbte.aseanlib</groupId>
<artifactId>aseanlib-io</artifactId>
<version>1.1.3</version>
<version>1.1.4</version>
</dependency>

<!-- Spigot -->
Expand Down
8 changes: 4 additions & 4 deletions npc/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
<parent>
<artifactId>aseanlib</artifactId>
<groupId>com.aseanbte.aseanlib</groupId>
<version>1.1.3</version>
<version>1.1.4</version>
</parent>
<modelVersion>4.0.0</modelVersion>

Expand All @@ -14,8 +14,8 @@
<name>AseanLib-NPC</name>

<properties>
<maven.compiler.target>1.8</maven.compiler.target>
<maven.compiler.source>1.8</maven.compiler.source>
<maven.compiler.target>17</maven.compiler.target>
<maven.compiler.source>17</maven.compiler.source>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
</properties>

Expand Down Expand Up @@ -54,7 +54,7 @@
<dependency>
<groupId>com.aseanbte.aseanlib</groupId>
<artifactId>aseanlib-hologram</artifactId>
<version>1.1.3</version>
<version>1.1.4</version>
<scope>provided</scope>
</dependency>
<dependency>
Expand Down
10 changes: 6 additions & 4 deletions npc/src/main/java/com/aseanbte/aseanlib/npc/AbstractNpc.java
Original file line number Diff line number Diff line change
Expand Up @@ -75,10 +75,12 @@ public void create(Location spawnPos, boolean saveToFile, boolean turnToPlayer)

public void show(Player player) {
if (npc == null) return;
npc.getData().showToPlayer(player.getUniqueId());
npc.spawn(player);
if (hologram != null && player.getWorld().getName().equals(hologram.getLocation().getWorld().getName()))
Bukkit.getScheduler().runTask(FancyNpcs.getInstance().getPlugin(), () -> hologram.create(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()))
hologram.create(player);
});
}

public void showForAll() {
Expand Down
25 changes: 20 additions & 5 deletions npc/src/main/java/com/aseanbte/aseanlib/npc/NpcHologram.java
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,10 @@
package com.aseanbte.aseanlib.npc;

import com.aseanbte.aseanlib.hologram.DecentHologramDisplay;
import de.oliver.fancynpcs.FancyNpcs;
import org.bukkit.Bukkit;
import org.bukkit.Location;
import org.bukkit.entity.Player;
import org.bukkit.inventory.ItemStack;
import org.jetbrains.annotations.NotNull;

Expand All @@ -47,10 +50,18 @@ public NpcHologram(@NotNull String id, Location location, AbstractNpc npc) {
}

@Override
public boolean hasViewPermission(UUID uuid) {
return npc.getNpc().getIsVisibleForPlayer().containsKey(uuid) && npc.getNpc().getIsVisibleForPlayer().get(uuid);
public void create(Player player) {
Bukkit.getScheduler().runTask(FancyNpcs.getInstance().getPlugin(), () -> {
if(npc.getNpc().getIsVisibleForPlayer().containsKey(player.getUniqueId())
&& npc.getNpc().getIsVisibleForPlayer().get(player.getUniqueId())) {
super.create(player);
}
});
}

@Override
public boolean hasViewPermission(UUID uuid) { return true; }

@Override
public ItemStack getItem() {
return null;
Expand Down Expand Up @@ -79,13 +90,17 @@ public List<DataLine<?>> getFooter(UUID playerUUID) {
@Override
public void setLocation(Location newLocation) {
this.baseLocation = newLocation;
for (UUID playerUUID : getHolograms().keySet()) getHolograms().get(playerUUID)
.setLocation(newLocation.add(0, isActionTitleVisible(playerUUID) ? NPC_HOLOGRAM_Y_WITH_ACTION_TITLE : NPC_HOLOGRAM_Y, 0));
for (UUID playerUUID : getHolograms().keySet())
getHolograms().get(playerUUID)
.setLocation(newLocation.add(0, isActionTitleVisible(playerUUID) ?
NPC_HOLOGRAM_Y_WITH_ACTION_TITLE : NPC_HOLOGRAM_Y, 0));
}

public void setActionTitleVisibility(UUID playerUUID, boolean isVisible) {
Location nameLocation = baseLocation.clone();
isActionTitleVisible.put(playerUUID, isVisible);
getHologram(playerUUID).setLocation(baseLocation.add(0, isActionTitleVisible(playerUUID) ? NPC_HOLOGRAM_Y_WITH_ACTION_TITLE : NPC_HOLOGRAM_Y, 0));
getHologram(playerUUID).setLocation(nameLocation.add(0, isActionTitleVisible(playerUUID) ?
NPC_HOLOGRAM_Y_WITH_ACTION_TITLE : NPC_HOLOGRAM_Y, 0));
reload(playerUUID);
}

Expand Down
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

<groupId>com.aseanbte.aseanlib</groupId>
<artifactId>aseanlib</artifactId>
<version>1.1.3</version>
<version>1.1.4</version>
<packaging>pom</packaging>

<name>AseanLib</name>
Expand Down
2 changes: 1 addition & 1 deletion utils/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
<parent>
<artifactId>aseanlib</artifactId>
<groupId>com.aseanbte.aseanlib</groupId>
<version>1.1.3</version>
<version>1.1.4</version>
</parent>
<modelVersion>4.0.0</modelVersion>

Expand Down

0 comments on commit b5cacfe

Please sign in to comment.