mirror of
https://github.com/CitizensDev/Citizens2.git
synced 2024-11-27 21:29:14 +01:00
Allow /npc spawn to use the selected NPC
This commit is contained in:
parent
96c8f0d86a
commit
b0519f05b4
@ -868,9 +868,18 @@ public class NPCCommands {
|
|||||||
} catch (NumberFormatException ex) {
|
} catch (NumberFormatException ex) {
|
||||||
String name = args.getString(1);
|
String name = args.getString(1);
|
||||||
List<NPC> possible = Lists.newArrayList();
|
List<NPC> possible = Lists.newArrayList();
|
||||||
|
double range = -1;
|
||||||
|
if (args.hasValueFlag("r"))
|
||||||
|
range = Math.abs(args.getFlagDouble("r"));
|
||||||
for (NPC test : npcRegistry) {
|
for (NPC test : npcRegistry) {
|
||||||
if (test.getName().equalsIgnoreCase(name))
|
if (test.getName().equalsIgnoreCase(name)) {
|
||||||
|
if (range > 0
|
||||||
|
&& test.isSpawned()
|
||||||
|
&& !Util.locationWithinRange(args.getSenderLocation(), test.getBukkitEntity()
|
||||||
|
.getLocation(), range))
|
||||||
|
continue;
|
||||||
possible.add(test);
|
possible.add(test);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
if (possible.size() == 1) {
|
if (possible.size() == 1) {
|
||||||
toSelect = possible.get(0);
|
toSelect = possible.get(0);
|
||||||
@ -922,15 +931,15 @@ public class NPCCommands {
|
|||||||
|
|
||||||
@Command(
|
@Command(
|
||||||
aliases = { "npc" },
|
aliases = { "npc" },
|
||||||
usage = "spawn [id]",
|
usage = "spawn (id)",
|
||||||
desc = "Spawn an existing NPC",
|
desc = "Spawn an existing NPC",
|
||||||
modifiers = { "spawn" },
|
modifiers = { "spawn" },
|
||||||
min = 2,
|
min = 1,
|
||||||
max = 2,
|
max = 2,
|
||||||
permission = "citizens.npc.spawn")
|
permission = "citizens.npc.spawn")
|
||||||
@Requirements(ownership = true)
|
@Requirements(ownership = true)
|
||||||
public void spawn(CommandContext args, CommandSender sender, NPC npc) throws CommandException {
|
public void spawn(CommandContext args, CommandSender sender, NPC npc) throws CommandException {
|
||||||
NPC respawn = npcRegistry.getById(args.getInteger(1));
|
NPC respawn = args.argsLength() > 1 ? npcRegistry.getById(args.getInteger(1)) : npc;
|
||||||
if (respawn == null)
|
if (respawn == null)
|
||||||
throw new CommandException(Messages.NO_NPC_WITH_ID_FOUND, args.getInteger(1));
|
throw new CommandException(Messages.NO_NPC_WITH_ID_FOUND, args.getInteger(1));
|
||||||
if (respawn.isSpawned())
|
if (respawn.isSpawned())
|
||||||
|
Loading…
Reference in New Issue
Block a user