Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add Chatbot trait to make NPCs able to reply to everything said to th…
…em, using Artificial Intelligence Markup Language files. Such files are not included by default.
- Loading branch information
1 parent
fc1b8e8
commit 2c80620
Showing
7 changed files
with
130 additions
and
14 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
53 changes: 53 additions & 0 deletions
53
src/main/java/net/aufdemrand/denizen/npc/traits/ChatbotTrait.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
package net.aufdemrand.denizen.npc.traits; | ||
|
||
import java.io.File; | ||
|
||
import net.aufdemrand.denizen.Settings; | ||
import net.aufdemrand.denizen.utilities.Utilities; | ||
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); | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters