add type command

This commit is contained in:
D3v1s0m 2023-05-12 19:18:46 +05:30
parent ea732105a3
commit 80e7ac82f7
No known key found for this signature in database
GPG Key ID: 3B6EC35367B8D82E
2 changed files with 33 additions and 0 deletions

@ -199,6 +199,7 @@ public class ZNpcsPlus extends JavaPlugin {
.addSubcommand("teleport", new TeleportCommand())
.addSubcommand("list", new ListCommand())
.addSubcommand("near", new NearCommand())
.addSubcommand("type", new TypeCommand())
.addSubcommand("storage", new MultiCommand()
.addSubcommand("save", new SaveAllCommand())
.addSubcommand("load", new LoadAllCommand()))

@ -0,0 +1,32 @@
package lol.pyr.znpcsplus.commands;
import lol.pyr.director.adventure.command.CommandContext;
import lol.pyr.director.adventure.command.CommandHandler;
import lol.pyr.director.common.command.CommandExecutionException;
import lol.pyr.znpcsplus.npc.NpcEntryImpl;
import lol.pyr.znpcsplus.npc.NpcImpl;
import lol.pyr.znpcsplus.npc.NpcRegistryImpl;
import lol.pyr.znpcsplus.npc.NpcTypeImpl;
import net.kyori.adventure.text.Component;
import net.kyori.adventure.text.format.NamedTextColor;
import java.util.Collections;
import java.util.List;
public class TypeCommand implements CommandHandler {
@Override
public void run(CommandContext context) throws CommandExecutionException {
context.setUsage(context.getLabel() + " type <id> <type>");
NpcImpl npc = context.parse(NpcEntryImpl.class).getNpc();
NpcTypeImpl type = context.parse(NpcTypeImpl.class);
npc.setType(type);
context.send(Component.text("NPC type set to " + type.getName() + ".", NamedTextColor.GREEN));
}
@Override
public List<String> suggest(CommandContext context) throws CommandExecutionException {
if (context.argSize() == 1) return context.suggestCollection(NpcRegistryImpl.get().modifiableIds());
if (context.argSize() == 2) return context.suggestStream(NpcTypeImpl.values().stream().map(NpcTypeImpl::getName));
return Collections.emptyList();
}
}