Search in sources :

Example 1 with SpeechContext

use of net.citizensnpcs.api.ai.speech.SpeechContext in project Denizen-For-Bukkit by DenizenScript.

the class ChatbotTrait method chatTo.

public void chatTo(Entity entity, String input) {
    SpeechContext context = new SpeechContext(response(input));
    context.addRecipient(entity);
    context.setTalker(getNPC().getEntity());
    npc.getDefaultSpeechController().speak(context, "chat");
}
Also used : SpeechContext(net.citizensnpcs.api.ai.speech.SpeechContext)

Example 2 with SpeechContext

use of net.citizensnpcs.api.ai.speech.SpeechContext in project Citizens2 by CitizensDev.

the class NPCCommands method speak.

@Command(aliases = { "npc" }, usage = "speak message to speak --target npcid|player_name --type vocal_type", desc = "Uses the NPCs SpeechController to talk", modifiers = { "speak" }, min = 2, permission = "citizens.npc.speak")
public void speak(CommandContext args, CommandSender sender, NPC npc) throws CommandException {
    String type = npc.getTrait(Speech.class).getDefaultVocalChord();
    String message = Colorizer.parseColors(args.getJoinedStrings(1));
    if (message.length() <= 0) {
        Messaging.send(sender, "Default Vocal Chord for " + npc.getName() + ": " + npc.getTrait(Speech.class).getDefaultVocalChord());
        return;
    }
    SpeechContext context = new SpeechContext(message);
    if (args.hasValueFlag("target")) {
        if (args.getFlag("target").matches("\\d+")) {
            NPC target = CitizensAPI.getNPCRegistry().getById(Integer.valueOf(args.getFlag("target")));
            if (target != null)
                context.addRecipient(target.getEntity());
        } else {
            Player player = Bukkit.getPlayer(args.getFlag("target"));
            if (player != null) {
                context.addRecipient((Entity) player);
            }
        }
    }
    if (args.hasValueFlag("type")) {
        if (CitizensAPI.getSpeechFactory().isRegistered(args.getFlag("type")))
            type = args.getFlag("type");
    }
    npc.getDefaultSpeechController().speak(context, type);
}
Also used : NPC(net.citizensnpcs.api.npc.NPC) Player(org.bukkit.entity.Player) SpeechContext(net.citizensnpcs.api.ai.speech.SpeechContext) Speech(net.citizensnpcs.api.trait.trait.Speech) Command(net.citizensnpcs.api.command.Command)

Example 3 with SpeechContext

use of net.citizensnpcs.api.ai.speech.SpeechContext in project Citizens2 by CitizensDev.

the class Text method sendText.

private boolean sendText(Player player) {
    if (!player.hasPermission("citizens.admin") && !player.hasPermission("citizens.npc.talk"))
        return false;
    if (text.size() == 0)
        return false;
    int index = 0;
    if (randomTalker)
        index = RANDOM.nextInt(text.size());
    else {
        if (currentIndex > text.size() - 1)
            currentIndex = 0;
        index = currentIndex++;
    }
    npc.getDefaultSpeechController().speak(new SpeechContext(text.get(index), player));
    return true;
}
Also used : SpeechContext(net.citizensnpcs.api.ai.speech.SpeechContext)

Example 4 with SpeechContext

use of net.citizensnpcs.api.ai.speech.SpeechContext in project Sentinel by mcmonkey4eva.

the class SentinelTrait method sayTo.

/**
 * Causes the NPC to speak a message to a player.
 */
public void sayTo(Player player, String message) {
    SpeechContext sc = new SpeechContext(npc, message, player);
    npc.getDefaultSpeechController().speak(sc, "chat");
}
Also used : SpeechContext(net.citizensnpcs.api.ai.speech.SpeechContext)

Aggregations

SpeechContext (net.citizensnpcs.api.ai.speech.SpeechContext)4 Command (net.citizensnpcs.api.command.Command)1 NPC (net.citizensnpcs.api.npc.NPC)1 Speech (net.citizensnpcs.api.trait.trait.Speech)1 Player (org.bukkit.entity.Player)1