Visibility Awareness in Tab Completion

This commit is contained in:
Olof Larsson 2015-09-14 16:28:33 +02:00
parent 92d1501fa5
commit e56dfd9c05
2 changed files with 30 additions and 3 deletions

View File

@ -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<T> extends ARAbstract<T>
// Step 2: Calculate type.
SenderType type = this.type;
// Step 3: Create the ret.
Set<String> ret = IdUtil.getNames(presence, type);
// Step 3: Get Ids
Set<String> ids = IdUtil.getIds(presence, type);
// Step 4: Return the ret.
// Step 4: Create Ret with visible names
Set<String> ret = new MassiveSet<String>(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;
}

View File

@ -116,6 +116,21 @@ public abstract class SenderEntity<E extends SenderEntity<E>> extends Entity<E>
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
// -------------------------------------------- //