From 5056b0f73950d596e52db4622e05b48f12320846 Mon Sep 17 00:00:00 2001 From: filoghost Date: Sun, 21 Dec 2014 14:22:39 +0100 Subject: [PATCH] Small fixes --- .../holographicdisplays/object/BackendAPI.java | 2 ++ .../object/CraftVisibilityManager.java | 17 +++++++++++++++-- .../object/NamedHologramManager.java | 2 +- .../object/PluginHologramManager.java | 4 ++-- 4 files changed, 20 insertions(+), 5 deletions(-) diff --git a/HolographicDisplays/Plugin/com/gmail/filoghost/holographicdisplays/object/BackendAPI.java b/HolographicDisplays/Plugin/com/gmail/filoghost/holographicdisplays/object/BackendAPI.java index 86b33d30..b2379a10 100644 --- a/HolographicDisplays/Plugin/com/gmail/filoghost/holographicdisplays/object/BackendAPI.java +++ b/HolographicDisplays/Plugin/com/gmail/filoghost/holographicdisplays/object/BackendAPI.java @@ -2,6 +2,7 @@ package com.gmail.filoghost.holographicdisplays.object; import java.util.Collection; +import org.bukkit.Bukkit; import org.bukkit.Location; import org.bukkit.entity.Entity; import org.bukkit.plugin.Plugin; @@ -21,6 +22,7 @@ public class BackendAPI { Validator.notNull(plugin, "plugin"); Validator.notNull(source, "source"); Validator.notNull(source.getWorld(), "source's world"); + Validator.isTrue(Bukkit.isPrimaryThread(), "Async hologram creation"); PluginHologram hologram = new PluginHologram(source, plugin); PluginHologramManager.addHologram(hologram); diff --git a/HolographicDisplays/Plugin/com/gmail/filoghost/holographicdisplays/object/CraftVisibilityManager.java b/HolographicDisplays/Plugin/com/gmail/filoghost/holographicdisplays/object/CraftVisibilityManager.java index acf74628..ee071f74 100644 --- a/HolographicDisplays/Plugin/com/gmail/filoghost/holographicdisplays/object/CraftVisibilityManager.java +++ b/HolographicDisplays/Plugin/com/gmail/filoghost/holographicdisplays/object/CraftVisibilityManager.java @@ -1,6 +1,8 @@ package com.gmail.filoghost.holographicdisplays.object; +import java.util.HashSet; import java.util.Map; +import java.util.Set; import java.util.concurrent.ConcurrentHashMap; import org.bukkit.Bukkit; @@ -26,7 +28,7 @@ public class CraftVisibilityManager implements VisibilityManager { } @Override - public boolean isVisibleByDefault() { + public boolean isVisibleByDefault() { return visibleByDefault; } @@ -131,6 +133,17 @@ public class CraftVisibilityManager implements VisibilityManager { @Override public void resetVisibilityAll() { if (playersVisibilityMap != null) { + + // We need to refresh all the players + Set playerNames = new HashSet(playersVisibilityMap.keySet()); + + for (String playerName : playerNames) { + Player onlinePlayer = Bukkit.getPlayerExact(playerName); + if (onlinePlayer != null) { + resetVisibility(onlinePlayer); + } + } + playersVisibilityMap.clear(); playersVisibilityMap = null; } @@ -149,7 +162,7 @@ public class CraftVisibilityManager implements VisibilityManager { } private static boolean isNear(Player player, CraftHologram hologram) { - return player.getWorld().equals(hologram.getWorld()) && player.getLocation().distanceSquared(hologram.getLocation()) < VISIBILITY_DISTANCE_SQUARED; + return player.isOnline() && player.getWorld().equals(hologram.getWorld()) && player.getLocation().distanceSquared(hologram.getLocation()) < VISIBILITY_DISTANCE_SQUARED; } @Override diff --git a/HolographicDisplays/Plugin/com/gmail/filoghost/holographicdisplays/object/NamedHologramManager.java b/HolographicDisplays/Plugin/com/gmail/filoghost/holographicdisplays/object/NamedHologramManager.java index 67dbfc01..9d390e3f 100644 --- a/HolographicDisplays/Plugin/com/gmail/filoghost/holographicdisplays/object/NamedHologramManager.java +++ b/HolographicDisplays/Plugin/com/gmail/filoghost/holographicdisplays/object/NamedHologramManager.java @@ -51,7 +51,7 @@ public class NamedHologramManager { } } - public static void onChunkUnload(Chunk chunk) { + public static void onChunkUnload(Chunk chunk) { // Hide the holograms in that chunk. for (NamedHologram hologram : pluginHolograms) { if (hologram.isInChunk(chunk)) { diff --git a/HolographicDisplays/Plugin/com/gmail/filoghost/holographicdisplays/object/PluginHologramManager.java b/HolographicDisplays/Plugin/com/gmail/filoghost/holographicdisplays/object/PluginHologramManager.java index 8d952b46..7d3e712c 100644 --- a/HolographicDisplays/Plugin/com/gmail/filoghost/holographicdisplays/object/PluginHologramManager.java +++ b/HolographicDisplays/Plugin/com/gmail/filoghost/holographicdisplays/object/PluginHologramManager.java @@ -45,7 +45,7 @@ public class PluginHologramManager { return Collections.unmodifiableSet(ownedHolograms); } - public static void onChunkLoad(Chunk chunk) { + public static void onChunkLoad(Chunk chunk) { // Load the holograms in that chunk. for (PluginHologram hologram : pluginHolograms) { if (hologram.isInChunk(chunk)) { @@ -54,7 +54,7 @@ public class PluginHologramManager { } } - public static void onChunkUnload(Chunk chunk) { + public static void onChunkUnload(Chunk chunk) { // Hide the holograms in that chunk. for (PluginHologram hologram : pluginHolograms) { if (hologram.isInChunk(chunk)) {