Search in sources :

Example 1 with TalkableEntity

use of net.citizensnpcs.npc.ai.speech.TalkableEntity in project Denizen-For-Bukkit by DenizenScript.

the class DenizenChat method talkToBystanders.

private void talkToBystanders(Talkable talkable, String text, DenizenSpeechContext context) {
    double range = context.getChatRange();
    List<Entity> bystanderEntities = new ArrayList<Entity>();
    if (range == 0D) {
        for (Player player : Bukkit.getServer().getOnlinePlayers()) {
            bystanderEntities.add(player);
        }
    } else {
        bystanderEntities = talkable.getEntity().getNearbyEntities(range, range, range);
    }
    for (Entity bystander : bystanderEntities) {
        boolean shouldTalk = true;
        // Exclude targeted recipients
        if (context.hasRecipients()) {
            for (Talkable target : context) {
                if (target.getEntity().equals(bystander)) {
                    shouldTalk = false;
                    break;
                }
            }
        }
        // talkNear it if 'should_talk'
        if (shouldTalk) {
            new TalkableEntity(bystander).talkNear(context, text, this);
        }
    }
}
Also used : Entity(org.bukkit.entity.Entity) net.aufdemrand.denizen.objects.dEntity(net.aufdemrand.denizen.objects.dEntity) TalkableEntity(net.citizensnpcs.npc.ai.speech.TalkableEntity) Player(org.bukkit.entity.Player) ArrayList(java.util.ArrayList) TalkableEntity(net.citizensnpcs.npc.ai.speech.TalkableEntity) Talkable(net.citizensnpcs.api.ai.speech.Talkable)

Aggregations

ArrayList (java.util.ArrayList)1 net.aufdemrand.denizen.objects.dEntity (net.aufdemrand.denizen.objects.dEntity)1 Talkable (net.citizensnpcs.api.ai.speech.Talkable)1 TalkableEntity (net.citizensnpcs.npc.ai.speech.TalkableEntity)1 Entity (org.bukkit.entity.Entity)1 Player (org.bukkit.entity.Player)1