Small fixes

This commit is contained in:
filoghost 2014-12-21 14:22:39 +01:00
parent 6347389a53
commit 5056b0f739
4 changed files with 20 additions and 5 deletions

View File

@ -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);

View File

@ -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<String> playerNames = new HashSet<String>(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

View File

@ -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)) {

View File

@ -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)) {