mirror of
https://github.com/CitizensDev/Citizens2.git
synced 2024-11-26 12:46:04 +01:00
SpeechController updates. Now working as intended.
This commit is contained in:
parent
2be6437a63
commit
07a9295d3f
@ -45,12 +45,12 @@ public class Settings {
|
|||||||
public enum Setting {
|
public enum Setting {
|
||||||
CHAT_FORMAT("npc.chat.format.no-targets", "[<npc>]: <text>"),
|
CHAT_FORMAT("npc.chat.format.no-targets", "[<npc>]: <text>"),
|
||||||
CHAT_FORMAT_TO_TARGET("npc.chat.format.to-target", "[<npc>] -> You: <text>"),
|
CHAT_FORMAT_TO_TARGET("npc.chat.format.to-target", "[<npc>] -> You: <text>"),
|
||||||
CHAT_FORMAT_TO_BYSTANDERS("npc.chat.prefix.to-bystanders", "[<npc>] -> [<target>]: <text>"),
|
CHAT_FORMAT_TO_BYSTANDERS("npc.chat.format.with-target-to-bystanders", "[<npc>] -> [<target>]: <text>"),
|
||||||
CHAT_FORMAT_WITH_TARGETS_TO_BYSTANDERS("npc.chat.format.with-target-to-bystanders", "[<npc>] -> [<target>]: <text>"),
|
CHAT_FORMAT_WITH_TARGETS_TO_BYSTANDERS("npc.chat.format.with-targets-to-bystanders", "[<npc>] -> [<targets>]: <text>"),
|
||||||
CHAT_RANGE("npc.chat.options.range", 5),
|
CHAT_RANGE("npc.chat.options.range", 5),
|
||||||
CHAT_BYSTANDERS_HEAR_TARGETED_CHAT("npc.chat.options.bystanders-hear-targeted-chat", true),
|
CHAT_BYSTANDERS_HEAR_TARGETED_CHAT("npc.chat.options.bystanders-hear-targeted-chat", true),
|
||||||
CHAT_MAX_NUMBER_OF_TARGETS("npc.chat.options.max-number-of-targets-to-show", 3),
|
CHAT_MAX_NUMBER_OF_TARGETS("npc.chat.options.max-number-of-targets-to-show", 2),
|
||||||
CHAT_MULTIPLE_TARGETS_FORMAT("npc.chat.options.multiple-targets-format", "<target>,|<target>|& <target>|& others"),
|
CHAT_MULTIPLE_TARGETS_FORMAT("npc.chat.options.multiple-targets-format", "<target>|, <target>| & <target>| & others"),
|
||||||
DATABASE_DRIVER("storage.database.driver", ""),
|
DATABASE_DRIVER("storage.database.driver", ""),
|
||||||
DATABASE_PASSWORD("storage.database.password", ""),
|
DATABASE_PASSWORD("storage.database.password", ""),
|
||||||
DATABASE_URL("storage.database.url", ""),
|
DATABASE_URL("storage.database.url", ""),
|
||||||
|
@ -8,6 +8,8 @@ import java.util.List;
|
|||||||
import net.citizensnpcs.Citizens;
|
import net.citizensnpcs.Citizens;
|
||||||
import net.citizensnpcs.Settings.Setting;
|
import net.citizensnpcs.Settings.Setting;
|
||||||
import net.citizensnpcs.api.CitizensAPI;
|
import net.citizensnpcs.api.CitizensAPI;
|
||||||
|
import net.citizensnpcs.api.ai.speech.SpeechContext;
|
||||||
|
import net.citizensnpcs.api.ai.speech.TalkableEntity;
|
||||||
import net.citizensnpcs.api.event.PlayerCreateNPCEvent;
|
import net.citizensnpcs.api.event.PlayerCreateNPCEvent;
|
||||||
import net.citizensnpcs.api.npc.NPC;
|
import net.citizensnpcs.api.npc.NPC;
|
||||||
import net.citizensnpcs.api.npc.NPCRegistry;
|
import net.citizensnpcs.api.npc.NPCRegistry;
|
||||||
@ -15,6 +17,7 @@ import net.citizensnpcs.api.trait.Trait;
|
|||||||
import net.citizensnpcs.api.trait.trait.MobType;
|
import net.citizensnpcs.api.trait.trait.MobType;
|
||||||
import net.citizensnpcs.api.trait.trait.Owner;
|
import net.citizensnpcs.api.trait.trait.Owner;
|
||||||
import net.citizensnpcs.api.trait.trait.Spawned;
|
import net.citizensnpcs.api.trait.trait.Spawned;
|
||||||
|
import net.citizensnpcs.api.trait.trait.Speech;
|
||||||
import net.citizensnpcs.api.util.DataKey;
|
import net.citizensnpcs.api.util.DataKey;
|
||||||
import net.citizensnpcs.api.util.MemoryDataKey;
|
import net.citizensnpcs.api.util.MemoryDataKey;
|
||||||
import net.citizensnpcs.command.Command;
|
import net.citizensnpcs.command.Command;
|
||||||
@ -959,6 +962,47 @@ public class NPCCommands {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Command(
|
||||||
|
aliases = { "npc" },
|
||||||
|
usage = "speak message to speak --type vocalChordType ",
|
||||||
|
desc = "Uses the NPCs SpeechController to talk",
|
||||||
|
modifiers = { "speak" },
|
||||||
|
min = 1,
|
||||||
|
max = 3,
|
||||||
|
permission = "npc.speak")
|
||||||
|
public void speak(CommandContext args, CommandSender sender, NPC npc) throws CommandException {
|
||||||
|
|
||||||
|
String type = npc.getTrait(Speech.class).getDefaultVocalChord();
|
||||||
|
|
||||||
|
if (args.length() < 1) {
|
||||||
|
Messaging.send(sender, "Default Vocal Chord for " + npc.getName() + ": " + npc.getTrait(Speech.class).getDefaultVocalChord());
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
Messaging.send(sender, "TEST: " + args.getJoinedStrings(1));
|
||||||
|
SpeechContext context = new SpeechContext(args.getJoinedStrings(1));
|
||||||
|
|
||||||
|
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(new TalkableEntity(target));
|
||||||
|
} else {
|
||||||
|
Player player = Bukkit.getPlayer(args.getFlag("target"));
|
||||||
|
if (player != null)
|
||||||
|
context.addRecipient(new TalkableEntity(player));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (args.hasValueFlag("type")) {
|
||||||
|
if (CitizensAPI.getSpeechFactory().isRegistered(args.getFlag("type")))
|
||||||
|
type = args.getFlag("type");
|
||||||
|
}
|
||||||
|
|
||||||
|
if (context.hasRecipients())
|
||||||
|
Util.faceEntity(npc.getBukkitEntity(), context.iterator().next().getEntity());
|
||||||
|
npc.getDefaultSpeechController().speak(new SpeechContext(args.getJoinedStrings(1)), type);
|
||||||
|
}
|
||||||
|
|
||||||
@Command(
|
@Command(
|
||||||
aliases = { "npc" },
|
aliases = { "npc" },
|
||||||
usage = "speed [speed]",
|
usage = "speed [speed]",
|
||||||
|
@ -4,6 +4,8 @@ import java.util.HashMap;
|
|||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
import java.util.Map.Entry;
|
import java.util.Map.Entry;
|
||||||
|
|
||||||
|
import com.google.common.base.Preconditions;
|
||||||
|
|
||||||
import net.citizensnpcs.api.ai.speech.SpeechFactory;
|
import net.citizensnpcs.api.ai.speech.SpeechFactory;
|
||||||
import net.citizensnpcs.api.ai.speech.VocalChord;
|
import net.citizensnpcs.api.ai.speech.VocalChord;
|
||||||
|
|
||||||
@ -12,20 +14,23 @@ public class CitizensSpeechFactory implements SpeechFactory {
|
|||||||
Map<String, Class<? extends VocalChord>> registered = new HashMap<String, Class <? extends VocalChord>>();
|
Map<String, Class<? extends VocalChord>> registered = new HashMap<String, Class <? extends VocalChord>>();
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void register(Class<? extends VocalChord> clazz, String name) {
|
public VocalChord getVocalChord(Class<? extends VocalChord> clazz) {
|
||||||
registered.put(name, clazz);
|
// Return a new instance of the VocalChord specified
|
||||||
|
try {
|
||||||
|
return clazz.newInstance();
|
||||||
|
} catch (InstantiationException e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
} catch (IllegalAccessException e) {
|
||||||
|
e.printStackTrace();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
|
||||||
public String getVocalChordName(Class<? extends VocalChord> clazz) {
|
|
||||||
for (Entry<String, Class<? extends VocalChord>> vocalChord : registered.entrySet())
|
|
||||||
if (vocalChord.getValue() == clazz) return vocalChord.getKey();
|
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public VocalChord getVocalChord(String name) {
|
public VocalChord getVocalChord(String name) {
|
||||||
if (registered.containsKey(name.toLowerCase()))
|
// Check if VocalChord name is a registered type
|
||||||
|
if (isRegistered(name))
|
||||||
|
// Return a new instance of the VocalChord specified
|
||||||
try {
|
try {
|
||||||
return registered.get(name.toLowerCase()).newInstance();
|
return registered.get(name.toLowerCase()).newInstance();
|
||||||
} catch (InstantiationException e) {
|
} catch (InstantiationException e) {
|
||||||
@ -37,15 +42,27 @@ public class CitizensSpeechFactory implements SpeechFactory {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public VocalChord getVocalChord(Class<? extends VocalChord> clazz) {
|
public String getVocalChordName(Class<? extends VocalChord> clazz) {
|
||||||
try {
|
// Get the name of a VocalChord class that has been registered
|
||||||
return clazz.newInstance();
|
for (Entry<String, Class<? extends VocalChord>> vocalChord : registered.entrySet())
|
||||||
} catch (InstantiationException e) {
|
if (vocalChord.getValue() == clazz) return vocalChord.getKey();
|
||||||
e.printStackTrace();
|
|
||||||
} catch (IllegalAccessException e) {
|
|
||||||
e.printStackTrace();
|
|
||||||
}
|
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean isRegistered(String name) {
|
||||||
|
if (registered.containsKey(name.toLowerCase())) return true;
|
||||||
|
else return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void register(Class<? extends VocalChord> clazz, String name) {
|
||||||
|
Preconditions.checkNotNull(name, "info cannot be null");
|
||||||
|
Preconditions.checkNotNull(clazz, "vocalchord cannot be null");
|
||||||
|
if (registered.containsKey(name.toLowerCase()))
|
||||||
|
throw new IllegalArgumentException("vocalchord name already registered");
|
||||||
|
registered.put(name.toLowerCase(), clazz);
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -193,7 +193,8 @@ public class Text extends Trait implements Runnable, Toggleable, Listener, Conve
|
|||||||
index = currentIndex++;
|
index = currentIndex++;
|
||||||
}
|
}
|
||||||
|
|
||||||
npc.getDefaultSpeechController().speak(new SpeechContext(text.get(index), new TalkableEntity(player)));
|
npc.getDefaultSpeechController().speak(new SpeechContext(text.get(index), player));
|
||||||
|
Messaging.log("Talking...");
|
||||||
// Messaging.sendWithNPC(player, Setting.CHAT_PREFIX.asString() + text.get(index), npc);
|
// Messaging.sendWithNPC(player, Setting.CHAT_PREFIX.asString() + text.get(index), npc);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user