mirror of
https://github.com/CitizensDev/Citizens2.git
synced 2024-11-30 06:33:56 +01:00
fix NPE
This commit is contained in:
parent
57adf5f5c9
commit
8340fa9c76
@ -32,16 +32,13 @@ public class NPCCommands {
|
|||||||
npcManager = plugin.getNPCManager();
|
npcManager = plugin.getNPCManager();
|
||||||
characterManager = plugin.getCharacterManager();
|
characterManager = plugin.getCharacterManager();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Command(
|
@Command(aliases = { "npc" }, desc = "Show basic NPC information", max = 0, permission = "npc.info")
|
||||||
aliases = { "npc" },
|
|
||||||
desc = "Show basic NPC information",
|
|
||||||
max = 0,
|
|
||||||
permission = "npc.info")
|
|
||||||
public void showInfo(CommandContext args, Player player, NPC npc) {
|
public void showInfo(CommandContext args, Player player, NPC npc) {
|
||||||
Messaging.send(player, StringHelper.wrapHeader(npc.getName()));
|
Messaging.send(player, StringHelper.wrapHeader(npc.getName()));
|
||||||
Messaging.send(player, " <a>ID: <e>" + npc.getId());
|
Messaging.send(player, " <a>ID: <e>" + npc.getId());
|
||||||
Messaging.send(player, " <a>Character: <e>" + npc.getCharacter().getName());
|
Messaging.send(player, " <a>Character: <e>" + npc.getCharacter() != null ? npc.getCharacter().getName()
|
||||||
|
: "None");
|
||||||
}
|
}
|
||||||
|
|
||||||
@Command(
|
@Command(
|
||||||
@ -72,9 +69,8 @@ public class NPCCommands {
|
|||||||
boolean success = true;
|
boolean success = true;
|
||||||
if (args.hasValueFlag("char")) {
|
if (args.hasValueFlag("char")) {
|
||||||
if (characterManager.getInstance(args.getFlag("char"), create) == null) {
|
if (characterManager.getInstance(args.getFlag("char"), create) == null) {
|
||||||
Messaging.sendError(player,
|
Messaging.sendError(player, "The character '" + args.getFlag("char") + "' does not exist. "
|
||||||
"The character '" + args.getFlag("char") + "' does not exist. " + create.getName()
|
+ create.getName() + " was created at your location without a character.");
|
||||||
+ " was created at your location without a character.");
|
|
||||||
success = false;
|
success = false;
|
||||||
} else {
|
} else {
|
||||||
create.setCharacter(characterManager.getInstance(args.getFlag("char"), create));
|
create.setCharacter(characterManager.getInstance(args.getFlag("char"), create));
|
||||||
@ -108,20 +104,19 @@ public class NPCCommands {
|
|||||||
npc.despawn();
|
npc.despawn();
|
||||||
Messaging.send(player, ChatColor.GREEN + "You despawned " + StringHelper.wrap(npc.getName()) + ".");
|
Messaging.send(player, ChatColor.GREEN + "You despawned " + StringHelper.wrap(npc.getName()) + ".");
|
||||||
}
|
}
|
||||||
|
|
||||||
@Command(
|
@Command(
|
||||||
aliases = { "npc" },
|
aliases = { "npc" },
|
||||||
usage = "remove",
|
usage = "remove",
|
||||||
desc = "Remove an NPC",
|
desc = "Remove an NPC",
|
||||||
modifiers = { "remove" },
|
modifiers = { "remove" },
|
||||||
min = 1,
|
min = 1,
|
||||||
max = 1,
|
max = 1,
|
||||||
permission = "npc.remove")
|
permission = "npc.remove")
|
||||||
public void removeNPC(CommandContext args, Player player, NPC npc) {
|
public void removeNPC(CommandContext args, Player player, NPC npc) {
|
||||||
npc.remove();
|
npc.remove();
|
||||||
Messaging.send(player,
|
Messaging.send(player, ChatColor.GREEN + "You permanently removed " + StringHelper.wrap(npc.getName()) + ".");
|
||||||
ChatColor.GREEN + "You permanently removed " + StringHelper.wrap(npc.getName()) + ".");
|
}
|
||||||
}
|
|
||||||
|
|
||||||
@Command(
|
@Command(
|
||||||
aliases = { "npc" },
|
aliases = { "npc" },
|
||||||
@ -139,9 +134,8 @@ public class NPCCommands {
|
|||||||
newName = newName.substring(0, 15);
|
newName = newName.substring(0, 15);
|
||||||
}
|
}
|
||||||
npc.setName(newName);
|
npc.setName(newName);
|
||||||
Messaging.send(player,
|
Messaging.send(player, ChatColor.GREEN + "You renamed " + StringHelper.wrap(oldName) + " to "
|
||||||
ChatColor.GREEN + "You renamed " + StringHelper.wrap(oldName) + " to " + StringHelper.wrap(newName)
|
+ StringHelper.wrap(newName) + ".");
|
||||||
+ ".");
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Command(
|
@Command(
|
||||||
@ -182,14 +176,13 @@ public class NPCCommands {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
if (npc.getCharacter() != null
|
if (npc.getCharacter() != null
|
||||||
&& npc.getCharacter().getClass().getAnnotation(SaveId.class).value()
|
&& npc.getCharacter().getClass().getAnnotation(SaveId.class).value().equalsIgnoreCase(
|
||||||
.equalsIgnoreCase(character.getClass().getAnnotation(SaveId.class).value())) {
|
character.getClass().getAnnotation(SaveId.class).value())) {
|
||||||
Messaging.sendError(player, "The NPC already has the character '" + args.getString(1) + "'.");
|
Messaging.sendError(player, "The NPC already has the character '" + args.getString(1) + "'.");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
Messaging.send(player,
|
Messaging.send(player, StringHelper.wrap(npc.getName() + "'s") + " character is now '"
|
||||||
StringHelper.wrap(npc.getName() + "'s") + " character is now '" + StringHelper.wrap(args.getString(1))
|
+ StringHelper.wrap(args.getString(1)) + "'.");
|
||||||
+ "'.");
|
|
||||||
npc.setCharacter(character);
|
npc.setCharacter(character);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user