npc center command

This commit is contained in:
Pyrbu 2023-08-23 01:11:48 +02:00
parent 4fbc8c661d
commit 91c1cc17a5
4 changed files with 41 additions and 0 deletions

@ -57,6 +57,10 @@ public class NpcLocation {
return this.pitch;
}
public NpcLocation centered() {
return new NpcLocation(Math.floor(x) + 0.5, y, Math.floor(z) + 0.5, yaw, pitch);
}
public Location toBukkitLocation(World world) {
return new Location(world, this.x, this.y, this.z, this.yaw, this.pitch);
}

@ -293,6 +293,7 @@ public class ZNpcsPlus extends JavaPlugin {
registerEnumParser(manager, VillagerLevel.class, incorrectUsageMessage);
manager.registerCommand("npc", new MultiCommand(loadHelpMessage("root"))
.addSubcommand("center", new CenterCommand(npcRegistry))
.addSubcommand("create", new CreateCommand(npcRegistry, typeRegistry))
.addSubcommand("reloadconfig", new ReloadConfigCommand(configManager))
.addSubcommand("toggle", new ToggleCommand(npcRegistry))

@ -0,0 +1,35 @@
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 net.kyori.adventure.text.Component;
import net.kyori.adventure.text.format.NamedTextColor;
import java.util.Collections;
import java.util.List;
public class CenterCommand implements CommandHandler {
private final NpcRegistryImpl npcRegistry;
public CenterCommand(NpcRegistryImpl npcRegistry) {
this.npcRegistry = npcRegistry;
}
@Override
public void run(CommandContext context) throws CommandExecutionException {
context.setUsage(context.getLabel() + " center <id>");
NpcImpl npc = context.parse(NpcEntryImpl.class).getNpc();
npc.setLocation(npc.getLocation().centered());
context.send(Component.text("NPC has been centered on it's current block.", NamedTextColor.GREEN));
}
@Override
public List<String> suggest(CommandContext context) throws CommandExecutionException {
if (context.argSize() == 1) return context.suggestCollection(npcRegistry.getModifiableIds());
return Collections.emptyList();
}
}

@ -9,6 +9,7 @@
<gold>* <yellow>/npc type <id> <type>
<gold>* <yellow>/npc near <distance>
<gold>* <yellow>/npc center <id>
<gold>* <yellow>/npc move <id>
<gold>* <yellow>/npc teleport <id>