Add /npc waypoint add

This commit is contained in:
fullwall 2020-05-16 16:22:15 +08:00
parent 4633b75c24
commit df5ed08e32
3 changed files with 33 additions and 0 deletions

View File

@ -1,5 +1,10 @@
package net.citizensnpcs.commands;
import java.util.List;
import org.bukkit.Bukkit;
import org.bukkit.Location;
import org.bukkit.World;
import org.bukkit.command.CommandSender;
import net.citizensnpcs.Citizens;
@ -9,14 +14,40 @@ import net.citizensnpcs.api.command.Requirements;
import net.citizensnpcs.api.command.exception.CommandException;
import net.citizensnpcs.api.npc.NPC;
import net.citizensnpcs.api.util.Messaging;
import net.citizensnpcs.trait.waypoint.LinearWaypointProvider;
import net.citizensnpcs.trait.waypoint.Waypoint;
import net.citizensnpcs.trait.waypoint.WaypointProvider;
import net.citizensnpcs.trait.waypoint.Waypoints;
import net.citizensnpcs.util.Messages;
import net.citizensnpcs.util.Util;
@Requirements(ownership = true, selected = true)
public class WaypointCommands {
public WaypointCommands(Citizens plugin) {
}
@Command(
aliases = { "waypoints", "waypoint", "wp" },
usage = "add [x] [y] [z] (world) (--index idx)",
desc = "Adds a waypoint at a point",
modifiers = { "add" },
min = 4,
max = 5,
permission = "citizens.waypoints.add")
public void add(CommandContext args, CommandSender sender, NPC npc) throws CommandException {
WaypointProvider provider = npc.getTrait(Waypoints.class).getCurrentProvider();
if (!(provider instanceof LinearWaypointProvider))
throw new CommandException();
List<Waypoint> waypoints = (List<Waypoint>) ((LinearWaypointProvider) provider).waypoints();
World world = args.argsLength() > 4 ? Bukkit.getWorld(args.getString(4)) : npc.getStoredLocation().getWorld();
if (world == null)
throw new CommandException(Messages.WORLD_NOT_FOUND);
Location loc = new Location(world, args.getInteger(1), args.getInteger(2), args.getInteger(3));
int index = args.getFlagInteger("index", waypoints.size());
waypoints.add(index, new Waypoint(loc));
Messaging.sendTr(sender, Messages.WAYPOINT_ADDED, Util.prettyPrintLocation(loc), index);
}
// TODO: refactor into a policy style system
@Command(
aliases = { "waypoints", "waypoint", "wp" },

View File

@ -354,6 +354,7 @@ public class Messages {
public static final String WANDER_WAYPOINTS_RANGE_SET = "citizens.editors.waypoints.wander.range-set";
public static final String WANDER_WAYPOINTS_REGION_EDITING_START = "citizens.editors.waypoints.wander.editing-regions";
public static final String WANDER_WAYPOINTS_REMOVED_REGION = "citizens.editors.waypoints.wander.removed-region";
public static final String WAYPOINT_ADDED = "citizens.commands.waypoints.add.waypoint-added";
public static final String WAYPOINT_PROVIDER_SET = "citizens.waypoints.set-provider";
public static final String WAYPOINT_TELEPORTING_DISABLED = "citizens.commands.waypoints.disableteleporting.disabled";
public static final String WAYPOINT_TRIGGER_ADD_PROMPT = "citizens.editors.waypoints.triggers.add.prompt";

View File

@ -249,6 +249,7 @@ citizens.commands.traitc.missing=Trait not found.
citizens.commands.traitc.not-configurable=That trait is not configurable.
citizens.commands.traitc.not-on-npc=The NPC doesn''t have that trait.
citizens.commands.unknown-command=Unknown command. Did you mean:
citizens.commands.waypoints.add.waypoint-added=Added waypoint at [[{0}]] (index [[{1}]]).
citizens.commands.waypoints.disableteleporting.disable=[[{0}]] will no longer teleport when stuck pathfinding.
citizens.commands.waypoints.opendoors.enabled=[[{0}]] will now open doors while pathfinding.
citizens.commands.waypoints.opendoors.disabled=[[{0}]] will no longer doors while pathfinding.