diff --git a/src/main/java/net/citizensnpcs/commands/NPCCommands.java b/src/main/java/net/citizensnpcs/commands/NPCCommands.java index 26ebfe387..a6f46170d 100644 --- a/src/main/java/net/citizensnpcs/commands/NPCCommands.java +++ b/src/main/java/net/citizensnpcs/commands/NPCCommands.java @@ -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) { diff --git a/src/main/java/net/citizensnpcs/npc/ai/speech/Chat.java b/src/main/java/net/citizensnpcs/npc/ai/speech/Chat.java index 50bc7f9e3..051b78ca8 100644 --- a/src/main/java/net/citizensnpcs/npc/ai/speech/Chat.java +++ b/src/main/java/net/citizensnpcs/npc/ai/speech/Chat.java @@ -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.getName()) .replace("", 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.getName()) .replace("", 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("", targetNames.get(0)) + format[3]; } else if (max == 2 || targetNames.size() == 2) { - if (targetNames.size() == 2) + if (targetNames.size() == 2) { targets = format[0].replace("", targetNames.get(0)) + format[2].replace("", targetNames.get(1)); - else + } else targets = format[0].replace("", targetNames.get(0)) + format[1].replace("", targetNames.get(1)) + format[3]; } else if (max >= 3) { @@ -96,9 +93,9 @@ public class Chat implements VocalChord { break; targets = targets + format[1].replace("", targetNames.get(x)); } - if (targetNames.size() == max) + if (targetNames.size() == max) { targets = targets + format[2].replace("", targetNames.get(x)); - else + } else targets = targets + format[3]; } diff --git a/src/main/java/net/citizensnpcs/npc/ai/speech/CitizensSpeechFactory.java b/src/main/java/net/citizensnpcs/npc/ai/speech/CitizensSpeechFactory.java index 414070800..059b0425c 100644 --- a/src/main/java/net/citizensnpcs/npc/ai/speech/CitizensSpeechFactory.java +++ b/src/main/java/net/citizensnpcs/npc/ai/speech/CitizensSpeechFactory.java @@ -13,7 +13,6 @@ import org.bukkit.entity.LivingEntity; import com.google.common.base.Preconditions; public class CitizensSpeechFactory implements SpeechFactory { - Map> registered = new HashMap>(); @Override