Package net.aufdemrand.denizen.npc.traits

Source Code of net.aufdemrand.denizen.npc.traits.ChatbotTrait

package net.aufdemrand.denizen.npc.traits;

import java.io.File;

import net.citizensnpcs.api.ai.speech.SpeechContext;
import net.citizensnpcs.api.exception.NPCLoadException;
import net.citizensnpcs.api.persistence.Persist;
import net.citizensnpcs.api.trait.Trait;
import net.citizensnpcs.api.util.DataKey;

import org.alicebot.ab.*;
import org.bukkit.Bukkit;
import org.bukkit.entity.LivingEntity;

public class ChatbotTrait extends Trait {

    public ChatbotTrait() {
        super("chatbot");
    }

    static String path = Bukkit.getPluginManager().getPlugin("Denizen")
            .getDataFolder() + File.separator;

    @Persist("botname")
    private String botname;
    private Bot bot;
    private Chat chatSession;

    @Override
    public void load(DataKey key) throws NPCLoadException {
        setBot(key.getString("botname"));
    }

    public void chatTo(LivingEntity entity, String input) {
        SpeechContext context = new SpeechContext(reponse(input));
        context.addRecipient(entity);
        context.setTalker(getNPC().getBukkitEntity());
        npc.getDefaultSpeechController().speak(context, "chat");
    }

    public String reponse(String request) {
        return chatSession.multisentenceRespond(request);
    }

    public void setBot(String newname) {
        botname = newname;
        bot = new Bot(botname, path);
        chatSession = new Chat(bot);
    }
}
TOP

Related Classes of net.aufdemrand.denizen.npc.traits.ChatbotTrait

TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.