MassiveCore - Reworked VisibilityMixin

This commit is contained in:
Olof Larsson 2015-12-15 13:59:22 +01:00
parent d76c2125b9
commit 1311a2f100
6 changed files with 44 additions and 11 deletions

View File

@ -158,7 +158,7 @@ public abstract class TypeSenderIdAbstract<T> extends TypeAbstract<T>
Set<String> ret = new MassiveSet<String>(ids.size()); Set<String> ret = new MassiveSet<String>(ids.size());
for (String id : ids) for (String id : ids)
{ {
if ( ! Mixin.canSee(sender, id)) continue; if ( ! Mixin.isVisible(id, sender)) continue;
String name = IdUtil.getName(id); String name = IdUtil.getName(id);
if (name == null) continue; if (name == null) continue;
ret.add(name); ret.add(name);

View File

@ -145,9 +145,9 @@ public class EngineMassiveCoreMain extends EngineAbstract
// TODO: Should this only be players? Would a player actually want to tab-complete @console? // TODO: Should this only be players? Would a player actually want to tab-complete @console?
for (String senderName : IdUtil.getNames(SenderPresence.ONLINE, SenderType.ANY)) for (String senderName : IdUtil.getNames(SenderPresence.ONLINE, SenderType.ANY))
{ {
if (!predicate.apply(senderName)) continue; if ( ! predicate.apply(senderName)) continue;
if (current.contains(senderName)) continue; if (current.contains(senderName)) continue;
if (!Mixin.canSee(watcher, senderName)) continue; if ( ! Mixin.isVisible(senderName, watcher)) continue;
event.getTabCompletions().add(senderName); event.getTabCompletions().add(senderName);
} }

View File

@ -236,9 +236,13 @@ public class Mixin
// STATIC EXPOSE: VISIBILITY // STATIC EXPOSE: VISIBILITY
// -------------------------------------------- // // -------------------------------------------- //
public static boolean canSee(Object watcherObject, Object watcheeObject) public static boolean isVisible(Object watcheeObject)
{ {
return getVisibilityMixin().canSee(watcherObject, watcheeObject); return getVisibilityMixin().isVisible(watcheeObject);
}
public static boolean isVisible(Object watcheeObject, Object watcherObject)
{
return getVisibilityMixin().isVisible(watcheeObject, watcherObject);
} }
// -------------------------------------------- // // -------------------------------------------- //

View File

@ -2,5 +2,6 @@ package com.massivecraft.massivecore.mixin;
public interface VisibilityMixin public interface VisibilityMixin
{ {
public boolean canSee(Object watcherObject, Object watcheeObject); public boolean isVisible(Object watcheeObject);
public boolean isVisible(Object watcheeObject, Object watcherObject);
} }

View File

@ -3,6 +3,7 @@ package com.massivecraft.massivecore.mixin;
import org.bukkit.entity.Player; import org.bukkit.entity.Player;
import com.massivecraft.massivecore.util.IdUtil; import com.massivecraft.massivecore.util.IdUtil;
import com.massivecraft.massivecore.util.MUtil;
public class VisibilityMixinDefault extends VisibilityMixinAbstract public class VisibilityMixinDefault extends VisibilityMixinAbstract
{ {
@ -18,14 +19,36 @@ public class VisibilityMixinDefault extends VisibilityMixinAbstract
// -------------------------------------------- // // -------------------------------------------- //
@Override @Override
public boolean canSee(Object watcherObject, Object watcheeObject) public boolean isVisible(Object watcheeObject)
{ {
Player pwatcher = IdUtil.getPlayer(watcherObject); // The Bukkit API is not about general visibility.
Player pwatchee = IdUtil.getPlayer(watcheeObject); // It only handles player to player visibility.
// With this in mind we loop to do some sort of approximation.
// If there is any other player who can not see then we are not visible.
// This is for the sake of security. Rather hide than display secret information.
if (pwatcher == null) return true; Player pwatchee = IdUtil.getPlayer(watcheeObject);
if (pwatchee == null) return true; if (pwatchee == null) return true;
for (Player pwatcher : MUtil.getOnlinePlayers())
{
if (pwatchee.equals(pwatcher)) continue;
if (pwatcher.canSee(pwatchee)) continue;
return false;
}
return true;
}
@Override
public boolean isVisible(Object watcheeObject, Object watcherObject)
{
Player pwatchee = IdUtil.getPlayer(watcheeObject);
Player pwatcher = IdUtil.getPlayer(watcherObject);
if (pwatchee == null) return true;
if (pwatcher == null) return true;
return pwatcher.canSee(pwatchee); return pwatcher.canSee(pwatchee);
} }

View File

@ -122,9 +122,14 @@ public abstract class SenderEntity<E extends SenderEntity<E>> extends Entity<E>
return Mixin.getIp(this.getId()); return Mixin.getIp(this.getId());
} }
public boolean isVisible()
{
return Mixin.isVisible(this);
}
public boolean isVisible(Object watcherObject) public boolean isVisible(Object watcherObject)
{ {
return Mixin.canSee(watcherObject, this); return Mixin.isVisible(this, watcherObject);
} }
public boolean isOnline(Object watcherObject) public boolean isOnline(Object watcherObject)