visibility fix

This commit is contained in:
Cheese 2015-03-20 23:20:56 +11:00
parent 0a766cd7bb
commit f54ed0ece2

View File

@ -11,9 +11,17 @@ import org.bukkit.entity.Player;
public class VisibilityData public class VisibilityData
{ {
private NautHashMap<Player, Boolean> _shouldHide = new NautHashMap<Player, Boolean>(); private NautHashMap<Player, Boolean> _shouldHide = new NautHashMap<Player, Boolean>();
private NautHashMap<Player, Boolean> _lastState = new NautHashMap<Player, Boolean>();
public void updatePlayer(Player player, Player target, boolean hide) public void updatePlayer(Player player, Player target, boolean hide)
{ {
if (_lastState.containsKey(target) && _lastState.get(target) == hide)
{
//Already this state, do nothing
//System.out.println("REPEAT " + player.getName() + " ~ " + target.getName());
return;
}
if (attemptToProcess(player, target, hide)) if (attemptToProcess(player, target, hide))
{ {
//Clear old //Clear old
@ -35,13 +43,17 @@ public class VisibilityData
//it would still send the packet, even if the client thought it was already the state. //it would still send the packet, even if the client thought it was already the state.
if (hide) if (hide)
((CraftPlayer)player).hidePlayer(target); ((CraftPlayer)player).hidePlayer(target, true, true);
else else
((CraftPlayer)player).showPlayer(target); ((CraftPlayer)player).showPlayer(target);
_lastState.put(target, hide);
//System.out.println("TRUE " + player.getName() + " ~ " + target.getName());
return true; return true;
} }
//System.out.println("FALSE " + player.getName() + " ~ " + target.getName());
return false; return false;
} }
@ -55,12 +67,10 @@ public class VisibilityData
Player target = targetIter.next(); Player target = targetIter.next();
boolean hide = _shouldHide.get(target); boolean hide = _shouldHide.get(target);
if (attemptToProcess(player, target, hide)) if (!target.isOnline() || !target.isValid() || attemptToProcess(player, target, hide))
{ {
targetIter.remove(); targetIter.remove();
} }
} }
} }
} }