mirror of
https://github.com/YouHaveTrouble/NotJustNameplates.git
synced 2026-05-11 22:16:57 +00:00
add task removing orphan nameplates if something unexpected happens
This commit is contained in:
@@ -7,6 +7,7 @@ import org.bukkit.*;
|
|||||||
import org.bukkit.block.Block;
|
import org.bukkit.block.Block;
|
||||||
import org.bukkit.craftbukkit.v1_20_R1.entity.CraftPlayer;
|
import org.bukkit.craftbukkit.v1_20_R1.entity.CraftPlayer;
|
||||||
import org.bukkit.entity.Player;
|
import org.bukkit.entity.Player;
|
||||||
|
import org.bukkit.entity.TextDisplay;
|
||||||
import org.bukkit.event.EventHandler;
|
import org.bukkit.event.EventHandler;
|
||||||
import org.bukkit.event.EventPriority;
|
import org.bukkit.event.EventPriority;
|
||||||
import org.bukkit.event.Listener;
|
import org.bukkit.event.Listener;
|
||||||
@@ -25,6 +26,13 @@ public class NameplateManager implements Listener {
|
|||||||
public NameplateManager(NotJustNameplates plugin) {
|
public NameplateManager(NotJustNameplates plugin) {
|
||||||
reloadNameplates();
|
reloadNameplates();
|
||||||
Bukkit.getScheduler().runTaskTimer(plugin, () -> nameplates.values().forEach(Nameplate::update), 0, 1);
|
Bukkit.getScheduler().runTaskTimer(plugin, () -> nameplates.values().forEach(Nameplate::update), 0, 1);
|
||||||
|
|
||||||
|
// Remove all orphan nameplates
|
||||||
|
Bukkit.getScheduler().runTaskTimer(plugin, () -> Bukkit.getWorlds().forEach(world -> world.getEntities().forEach(entity -> {
|
||||||
|
if (!(entity instanceof TextDisplay textDisplay)) return;
|
||||||
|
if (textDisplay.getPersistentDataContainer().has(Nameplate.NAMEPLATE_KEY)) return;
|
||||||
|
textDisplay.remove();
|
||||||
|
})), 100, 100);
|
||||||
}
|
}
|
||||||
|
|
||||||
@EventHandler(ignoreCancelled = true, priority = EventPriority.HIGHEST)
|
@EventHandler(ignoreCancelled = true, priority = EventPriority.HIGHEST)
|
||||||
|
|||||||
Reference in New Issue
Block a user