mirror of
https://github.com/CitizensDev/Citizens2.git
synced 2024-11-23 19:16:34 +01:00
Prevent NPE in moveto if NPC is not spawned
This commit is contained in:
parent
5a3f616fe1
commit
2b0e7af138
@ -643,6 +643,9 @@ public class NPCCommands {
|
||||
// Spawn the NPC if it isn't spawned to prevent NPEs
|
||||
if (!npc.isSpawned())
|
||||
npc.spawn(npc.getTrait(CurrentLocation.class).getLocation());
|
||||
if (npc.getBukkitEntity() == null) {
|
||||
throw new CommandException("NPC could not be spawned.");
|
||||
}
|
||||
Location current = npc.getBukkitEntity().getLocation();
|
||||
Location to;
|
||||
if (args.argsLength() > 1) {
|
||||
|
@ -2,7 +2,6 @@ package net.citizensnpcs.npc.ai.speech;
|
||||
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
import java.util.logging.Level;
|
||||
|
||||
import net.citizensnpcs.Settings.Setting;
|
||||
import net.citizensnpcs.api.CitizensAPI;
|
||||
@ -25,15 +24,13 @@ public class Chat implements VocalChord {
|
||||
|
||||
@Override
|
||||
public void talk(SpeechContext context) {
|
||||
// Check valid talker
|
||||
if (context.getTalker() == null)
|
||||
return;
|
||||
NPC npc = CitizensAPI.getNPCRegistry().getNPC(context.getTalker().getEntity());
|
||||
if (npc == null)
|
||||
return;
|
||||
|
||||
// If no recipients, chat to the world with CHAT_FORMAT and CHAT_RANGE
|
||||
// settings
|
||||
// chat to the world with CHAT_FORMAT and CHAT_RANGE settings
|
||||
if (!context.hasRecipients()) {
|
||||
String text = Setting.CHAT_FORMAT.asString().replace("<npc>", npc.getName())
|
||||
.replace("<text>", context.getMessage());
|
||||
@ -42,7 +39,7 @@ public class Chat implements VocalChord {
|
||||
}
|
||||
|
||||
// Assumed recipients at this point
|
||||
else if (context.size() <= 1) { // One recipient
|
||||
else if (context.size() <= 1) {
|
||||
String text = Setting.CHAT_FORMAT_TO_TARGET.asString().replace("<npc>", npc.getName())
|
||||
.replace("<text>", context.getMessage());
|
||||
String targetName = "";
|
||||
@ -77,14 +74,14 @@ public class Chat implements VocalChord {
|
||||
int max = Setting.CHAT_MAX_NUMBER_OF_TARGETS.asInt();
|
||||
String[] format = Setting.CHAT_FORMAT_WITH_TARGETS_TO_BYSTANDERS.asString().split("\\|");
|
||||
if (format.length != 4)
|
||||
Messaging.log(Level.WARNING, "npc.chat.format.with-target-to-bystanders invalid!");
|
||||
Messaging.severe("npc.chat.format.with-target-to-bystanders invalid!");
|
||||
if (max == 1) {
|
||||
targets = format[0].replace("<npc>", targetNames.get(0)) + format[3];
|
||||
} else if (max == 2 || targetNames.size() == 2) {
|
||||
if (targetNames.size() == 2)
|
||||
if (targetNames.size() == 2) {
|
||||
targets = format[0].replace("<npc>", targetNames.get(0))
|
||||
+ format[2].replace("<npc>", targetNames.get(1));
|
||||
else
|
||||
} else
|
||||
targets = format[0].replace("<npc>", targetNames.get(0))
|
||||
+ format[1].replace("<npc>", targetNames.get(1)) + format[3];
|
||||
} else if (max >= 3) {
|
||||
@ -96,9 +93,9 @@ public class Chat implements VocalChord {
|
||||
break;
|
||||
targets = targets + format[1].replace("<npc>", targetNames.get(x));
|
||||
}
|
||||
if (targetNames.size() == max)
|
||||
if (targetNames.size() == max) {
|
||||
targets = targets + format[2].replace("<npc>", targetNames.get(x));
|
||||
else
|
||||
} else
|
||||
targets = targets + format[3];
|
||||
}
|
||||
|
||||
|
@ -13,7 +13,6 @@ import org.bukkit.entity.LivingEntity;
|
||||
import com.google.common.base.Preconditions;
|
||||
|
||||
public class CitizensSpeechFactory implements SpeechFactory {
|
||||
|
||||
Map<String, Class<? extends VocalChord>> registered = new HashMap<String, Class<? extends VocalChord>>();
|
||||
|
||||
@Override
|
||||
|
Loading…
Reference in New Issue
Block a user