Skip to content

Commit

Permalink
Fix holograms disappearing when changing world/moving away from them
Browse files Browse the repository at this point in the history
  • Loading branch information
GliczDev committed May 2, 2024
1 parent 7ea6350 commit 4944fc5
Show file tree
Hide file tree
Showing 4 changed files with 27 additions and 4 deletions.
6 changes: 4 additions & 2 deletions plugin/src/main/java/me/glicz/holograms/GlitchHolograms.java
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,8 @@
import me.glicz.holograms.command.GlitchHologramsCommand;
import me.glicz.holograms.line.HologramLine;
import me.glicz.holograms.line.HologramLineImpl;
import me.glicz.holograms.listener.PlayerJoinQuitListener;
import me.glicz.holograms.listener.JoinQuitListener;
import me.glicz.holograms.listener.PlayerChunkLoadListener;
import me.glicz.holograms.listener.WorldUnloadListener;
import me.glicz.holograms.loader.HologramLoader;
import me.glicz.holograms.nms.NMSBridge;
Expand Down Expand Up @@ -51,7 +52,8 @@ public void onEnable() {
new GlitchHologramsCommand().register();

Bukkit.getServicesManager().register(GlitchHologramsAPI.class, this, this, ServicePriority.Highest);
Bukkit.getPluginManager().registerEvents(new PlayerJoinQuitListener(), this);
Bukkit.getPluginManager().registerEvents(new JoinQuitListener(), this);
Bukkit.getPluginManager().registerEvents(new PlayerChunkLoadListener(), this);
Bukkit.getPluginManager().registerEvents(new WorldUnloadListener(), this);

HologramLoader.loadAll();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ public void show(@NotNull Player player) {
throw new IllegalArgumentException(player.getName());
}

if (hologram.isInUpdateRange(player)) {
if (player.getWorld() == location.getWorld()) {
GlitchHolograms.get().nmsBridge().sendHologramLine(player, entity, content(player));
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
import org.bukkit.event.player.PlayerJoinEvent;
import org.bukkit.event.player.PlayerQuitEvent;

public class PlayerJoinQuitListener implements Listener {
public class JoinQuitListener implements Listener {
@EventHandler
public void onJoin(PlayerJoinEvent e) {
GlitchHologramsAPI.get().getRegisteredHolograms()
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
package me.glicz.holograms.listener;

import io.papermc.paper.event.packet.PlayerChunkLoadEvent;
import me.glicz.holograms.GlitchHologramsAPI;
import org.bukkit.Location;
import org.bukkit.event.EventHandler;
import org.bukkit.event.Listener;

public class PlayerChunkLoadListener implements Listener {
@EventHandler
public void onPlayerChunkLoad(PlayerChunkLoadEvent e) {
GlitchHologramsAPI.get().getRegisteredHolograms().forEach(hologram -> {
if (!hologram.viewers().contains(e.getPlayer())) return;

Location location = hologram.location();
if (e.getChunk().getX() == location.getBlockX() >> 4 && e.getChunk().getZ() == location.getBlockZ() >> 4) {
hologram.show(e.getPlayer());
}
});
}
}

0 comments on commit 4944fc5

Please sign in to comment.