From e56dfd9c056b1926df69af22f371b218d61bef0a Mon Sep 17 00:00:00 2001 From: Olof Larsson Date: Mon, 14 Sep 2015 16:28:33 +0200 Subject: [PATCH] Visibility Awareness in Tab Completion --- .../cmd/arg/ARSenderIdAbstract.java | 18 +++++++++++++++--- .../massivecore/store/SenderEntity.java | 15 +++++++++++++++ 2 files changed, 30 insertions(+), 3 deletions(-) diff --git a/src/com/massivecraft/massivecore/cmd/arg/ARSenderIdAbstract.java b/src/com/massivecraft/massivecore/cmd/arg/ARSenderIdAbstract.java index bdce9293..5ef3e0fd 100644 --- a/src/com/massivecraft/massivecore/cmd/arg/ARSenderIdAbstract.java +++ b/src/com/massivecraft/massivecore/cmd/arg/ARSenderIdAbstract.java @@ -9,6 +9,8 @@ import org.bukkit.command.CommandSender; import com.massivecraft.massivecore.MassiveException; import com.massivecraft.massivecore.SenderPresence; import com.massivecraft.massivecore.SenderType; +import com.massivecraft.massivecore.collections.MassiveSet; +import com.massivecraft.massivecore.mixin.Mixin; import com.massivecraft.massivecore.store.SenderIdSource; import com.massivecraft.massivecore.util.IdUtil; import com.massivecraft.massivecore.util.MUtil; @@ -121,10 +123,20 @@ public abstract class ARSenderIdAbstract extends ARAbstract // Step 2: Calculate type. SenderType type = this.type; - // Step 3: Create the ret. - Set ret = IdUtil.getNames(presence, type); + // Step 3: Get Ids + Set ids = IdUtil.getIds(presence, type); - // Step 4: Return the ret. + // Step 4: Create Ret with visible names + Set ret = new MassiveSet(ids.size()); + for (String id : ids) + { + if ( ! Mixin.canSee(sender, id)) continue; + String name = IdUtil.getName(id); + if (name == null) continue; + ret.add(name); + } + + // Step 5: Return the ret. return ret; } diff --git a/src/com/massivecraft/massivecore/store/SenderEntity.java b/src/com/massivecraft/massivecore/store/SenderEntity.java index 2c199ac1..21813902 100644 --- a/src/com/massivecraft/massivecore/store/SenderEntity.java +++ b/src/com/massivecraft/massivecore/store/SenderEntity.java @@ -116,6 +116,21 @@ public abstract class SenderEntity> extends Entity return Mixin.hasPlayedBefore(this.getId()); } + public boolean isVisible(Object watcherObject) + { + return Mixin.canSee(watcherObject, this); + } + + public boolean isOnline(Object watcherObject) + { + return this.isOnline() && this.isVisible(watcherObject); + } + + public boolean isOffline(Object watcherObject) + { + return ! this.isOnline(watcherObject); + } + // -------------------------------------------- // // DISPLAY NAME // -------------------------------------------- //