diff --git a/src/com/massivecraft/massivecore/command/type/sender/TypeSenderIdAbstract.java b/src/com/massivecraft/massivecore/command/type/sender/TypeSenderIdAbstract.java index dc9e7a09..0a05bd6c 100644 --- a/src/com/massivecraft/massivecore/command/type/sender/TypeSenderIdAbstract.java +++ b/src/com/massivecraft/massivecore/command/type/sender/TypeSenderIdAbstract.java @@ -158,7 +158,7 @@ public abstract class TypeSenderIdAbstract extends TypeAbstract Set ret = new MassiveSet(ids.size()); for (String id : ids) { - if ( ! Mixin.canSee(sender, id)) continue; + if ( ! Mixin.isVisible(id, sender)) continue; String name = IdUtil.getName(id); if (name == null) continue; ret.add(name); diff --git a/src/com/massivecraft/massivecore/engine/EngineMassiveCoreMain.java b/src/com/massivecraft/massivecore/engine/EngineMassiveCoreMain.java index c42df497..2bc81b35 100644 --- a/src/com/massivecraft/massivecore/engine/EngineMassiveCoreMain.java +++ b/src/com/massivecraft/massivecore/engine/EngineMassiveCoreMain.java @@ -145,9 +145,9 @@ public class EngineMassiveCoreMain extends EngineAbstract // TODO: Should this only be players? Would a player actually want to tab-complete @console? 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 (!Mixin.canSee(watcher, senderName)) continue; + if ( ! Mixin.isVisible(senderName, watcher)) continue; event.getTabCompletions().add(senderName); } diff --git a/src/com/massivecraft/massivecore/mixin/Mixin.java b/src/com/massivecraft/massivecore/mixin/Mixin.java index 4b78899a..95abdddb 100644 --- a/src/com/massivecraft/massivecore/mixin/Mixin.java +++ b/src/com/massivecraft/massivecore/mixin/Mixin.java @@ -236,9 +236,13 @@ public class Mixin // 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); } // -------------------------------------------- // diff --git a/src/com/massivecraft/massivecore/mixin/VisibilityMixin.java b/src/com/massivecraft/massivecore/mixin/VisibilityMixin.java index 63c169cd..6cef7356 100644 --- a/src/com/massivecraft/massivecore/mixin/VisibilityMixin.java +++ b/src/com/massivecraft/massivecore/mixin/VisibilityMixin.java @@ -2,5 +2,6 @@ package com.massivecraft.massivecore.mixin; public interface VisibilityMixin { - public boolean canSee(Object watcherObject, Object watcheeObject); + public boolean isVisible(Object watcheeObject); + public boolean isVisible(Object watcheeObject, Object watcherObject); } diff --git a/src/com/massivecraft/massivecore/mixin/VisibilityMixinDefault.java b/src/com/massivecraft/massivecore/mixin/VisibilityMixinDefault.java index e9caff92..9380ddd1 100644 --- a/src/com/massivecraft/massivecore/mixin/VisibilityMixinDefault.java +++ b/src/com/massivecraft/massivecore/mixin/VisibilityMixinDefault.java @@ -3,6 +3,7 @@ package com.massivecraft.massivecore.mixin; import org.bukkit.entity.Player; import com.massivecraft.massivecore.util.IdUtil; +import com.massivecraft.massivecore.util.MUtil; public class VisibilityMixinDefault extends VisibilityMixinAbstract { @@ -18,14 +19,36 @@ public class VisibilityMixinDefault extends VisibilityMixinAbstract // -------------------------------------------- // @Override - public boolean canSee(Object watcherObject, Object watcheeObject) + public boolean isVisible(Object watcheeObject) { - Player pwatcher = IdUtil.getPlayer(watcherObject); - Player pwatchee = IdUtil.getPlayer(watcheeObject); + // The Bukkit API is not about general visibility. + // 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; + 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); } diff --git a/src/com/massivecraft/massivecore/store/SenderEntity.java b/src/com/massivecraft/massivecore/store/SenderEntity.java index 4dd2a619..2f967287 100644 --- a/src/com/massivecraft/massivecore/store/SenderEntity.java +++ b/src/com/massivecraft/massivecore/store/SenderEntity.java @@ -122,9 +122,14 @@ public abstract class SenderEntity> extends Entity return Mixin.getIp(this.getId()); } + public boolean isVisible() + { + return Mixin.isVisible(this); + } + public boolean isVisible(Object watcherObject) { - return Mixin.canSee(watcherObject, this); + return Mixin.isVisible(this, watcherObject); } public boolean isOnline(Object watcherObject)