Merge pull request #167 from envizar/command
This commit is contained in:
commit
65d768667c
2 changed files with 16 additions and 4 deletions
|
@ -26,12 +26,18 @@ public class CreateCommand implements CommandHandler {
|
|||
|
||||
@Override
|
||||
public void run(CommandContext context) throws CommandExecutionException {
|
||||
context.setUsage(context.getLabel() + " create <id> <type>");
|
||||
context.setUsage(context.getLabel() + " create <id> [<type>]");
|
||||
Player player = context.ensureSenderIsPlayer();
|
||||
|
||||
String id = context.popString();
|
||||
if (npcRegistry.getById(id) != null) context.halt(Component.text("NPC with that ID already exists.", NamedTextColor.RED));
|
||||
NpcTypeImpl type = context.parse(NpcTypeImpl.class);
|
||||
|
||||
NpcTypeImpl type;
|
||||
if (context.argSize() == 1) {
|
||||
type = context.parse(NpcTypeImpl.class);
|
||||
} else {
|
||||
type = typeRegistry.getByName("player");
|
||||
}
|
||||
|
||||
NpcEntryImpl entry = npcRegistry.create(id, player.getWorld(), type, new NpcLocation(player.getLocation()));
|
||||
entry.enableEverything();
|
||||
|
|
|
@ -21,9 +21,14 @@ public class ToggleCommand implements CommandHandler {
|
|||
|
||||
@Override
|
||||
public void run(CommandContext context) throws CommandExecutionException {
|
||||
context.setUsage(context.getLabel() + " toggle <id>");
|
||||
context.setUsage(context.getLabel() + " toggle <id> [<enable/disable>]");
|
||||
NpcImpl npc = context.parse(NpcEntryImpl.class).getNpc();
|
||||
boolean enabled = !npc.isEnabled();
|
||||
boolean enabled;
|
||||
if (context.argSize() == 1) {
|
||||
enabled = context.popString().equalsIgnoreCase("enable");
|
||||
} else {
|
||||
enabled = !npc.isEnabled();
|
||||
}
|
||||
npc.setEnabled(enabled);
|
||||
context.send(Component.text("NPC has been " + (enabled ? "enabled" : "disabled"), NamedTextColor.GREEN));
|
||||
}
|
||||
|
@ -31,6 +36,7 @@ public class ToggleCommand implements CommandHandler {
|
|||
@Override
|
||||
public List<String> suggest(CommandContext context) throws CommandExecutionException {
|
||||
if (context.argSize() == 1) return context.suggestCollection(npcRegistry.getModifiableIds());
|
||||
if (context.argSize() == 2) return context.suggestLiteral("enable", "disable");
|
||||
return Collections.emptyList();
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue