-
-
Notifications
You must be signed in to change notification settings - Fork 54
/
SimpleSpeechController.java
37 lines (30 loc) · 1.13 KB
/
SimpleSpeechController.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
package net.citizensnpcs.api.ai.speech;
import net.citizensnpcs.api.CitizensAPI;
import net.citizensnpcs.api.ai.speech.event.NPCSpeechEvent;
import net.citizensnpcs.api.npc.NPC;
import net.citizensnpcs.api.trait.trait.Speech;
import org.bukkit.Bukkit;
/**
* Simple implementation of {@link SpeechController} which allows a NPC to speak
* with any registered {@link VocalChord}.
*
*/
public class SimpleSpeechController implements SpeechController {
NPC npc;
public SimpleSpeechController(NPC npc) {
this.npc = npc;
}
@Override
public void speak(SpeechContext context) {
speak(context, npc.getTrait(Speech.class).getDefaultVocalChord());
}
@Override
public void speak(SpeechContext context, String vocalChordName) {
context.setTalker(npc.getBukkitEntity());
NPCSpeechEvent event = new NPCSpeechEvent(context, vocalChordName);
Bukkit.getServer().getPluginManager().callEvent(event);
if (event.isCancelled())
return;
CitizensAPI.getSpeechFactory().getVocalChord(event.getVocalChordName()).talk(context);
}
}