Skip to content

Commit

Permalink
Fix hologram not getting unlinked when npc gets removed
Browse files Browse the repository at this point in the history
Update FancyNpcs to 1.1.3
  • Loading branch information
OliverSchlueter committed Apr 10, 2023
1 parent ea2deb8 commit fae59ba
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 1 deletion.
2 changes: 1 addition & 1 deletion build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ repositories {
}

dependencies {
compileOnly("de.oliver:FancyNpcs:1.1.2")
compileOnly("de.oliver:FancyNpcs:1.1.3")
compileOnly("me.clip:placeholderapi:2.11.3")
paperweight.paperDevBundle("1.19.4-R0.1-SNAPSHOT")
}
Expand Down
2 changes: 2 additions & 0 deletions src/main/java/de/oliver/FancyHolograms.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import de.oliver.commands.HologramCMD;
import de.oliver.listeners.NpcModifyListener;
import de.oliver.listeners.NpcRemoveListener;
import de.oliver.listeners.PlayerChangedWorldListener;
import de.oliver.listeners.PlayerJoinListener;
import de.oliver.utils.Metrics;
Expand Down Expand Up @@ -83,6 +84,7 @@ public void onEnable() {
pluginManager.registerEvents(new PlayerChangedWorldListener(), instance);
if(usingFancyNpcs){
pluginManager.registerEvents(new NpcModifyListener(), instance);
pluginManager.registerEvents(new NpcRemoveListener(), instance);
}

Bukkit.getScheduler().runTaskLater(instance, () -> {
Expand Down
23 changes: 23 additions & 0 deletions src/main/java/de/oliver/listeners/NpcRemoveListener.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
package de.oliver.listeners;

import de.oliver.FancyHolograms;
import de.oliver.Hologram;
import de.oliver.Npc;
import de.oliver.events.NpcRemoveEvent;
import org.bukkit.event.EventHandler;
import org.bukkit.event.Listener;

public class NpcRemoveListener implements Listener {

@EventHandler
public void onNpcRemove(NpcRemoveEvent event){
Npc npc = event.getNpc();

for (Hologram hologram : FancyHolograms.getInstance().getHologramManager().getAllHolograms()) {
if(hologram.getLinkedNpc() != null && hologram.getLinkedNpc() == npc){
hologram.setLinkedNpc(null);
}
}
}

}

0 comments on commit fae59ba

Please sign in to comment.