ZNPCsPlus/plugin/src/main/java/lol/pyr/znpcsplus/commands/MoveCommand.java

39 lines
1.4 KiB
Java
Raw Normal View History

2023-05-09 10:47:43 +00:00
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;
2023-05-10 15:01:14 +00:00
import lol.pyr.znpcsplus.npc.NpcImpl;
2023-05-09 10:47:43 +00:00
import lol.pyr.znpcsplus.npc.NpcRegistryImpl;
2023-05-21 12:45:43 +00:00
import lol.pyr.znpcsplus.util.NpcLocation;
2023-05-09 10:47:43 +00:00
import net.kyori.adventure.text.Component;
import net.kyori.adventure.text.format.NamedTextColor;
import org.bukkit.entity.Player;
2023-05-10 15:01:14 +00:00
import java.util.Collections;
2023-05-09 10:47:43 +00:00
import java.util.List;
public class MoveCommand implements CommandHandler {
private final NpcRegistryImpl npcRegistry;
public MoveCommand(NpcRegistryImpl npcRegistry) {
this.npcRegistry = npcRegistry;
}
2023-05-09 10:47:43 +00:00
@Override
2023-05-10 15:01:14 +00:00
public void run(CommandContext context) throws CommandExecutionException {
context.setUsage(context.getLabel() + " move <id>");
2023-05-10 15:01:14 +00:00
Player player = context.ensureSenderIsPlayer();
NpcImpl npc = context.parse(NpcEntryImpl.class).getNpc();
2023-05-21 12:45:43 +00:00
npc.setLocation(new NpcLocation(player.getLocation()));
2023-05-10 15:01:14 +00:00
context.send(Component.text("NPC moved to your current location.", NamedTextColor.GREEN));
2023-05-09 10:47:43 +00:00
}
@Override
public List<String> suggest(CommandContext context) throws CommandExecutionException {
2023-05-21 12:45:43 +00:00
if (context.argSize() == 1) return context.suggestCollection(npcRegistry.getModifiableIds());
2023-05-10 15:01:14 +00:00
return Collections.emptyList();
2023-05-09 10:47:43 +00:00
}
}