mirror of
https://github.com/CitizensDev/Citizens2.git
synced 2024-12-23 09:37:35 +01:00
Add basic /wp remove command
This commit is contained in:
parent
c31624fba3
commit
6f754d2594
@ -1,5 +1,6 @@
|
||||
package net.citizensnpcs.commands;
|
||||
|
||||
import java.util.Iterator;
|
||||
import java.util.List;
|
||||
|
||||
import org.bukkit.Bukkit;
|
||||
@ -16,6 +17,7 @@ import net.citizensnpcs.api.command.CommandContext;
|
||||
import net.citizensnpcs.api.command.Flag;
|
||||
import net.citizensnpcs.api.command.Requirements;
|
||||
import net.citizensnpcs.api.command.exception.CommandException;
|
||||
import net.citizensnpcs.api.command.exception.CommandUsageException;
|
||||
import net.citizensnpcs.api.hpastar.HPAGraph;
|
||||
import net.citizensnpcs.api.npc.NPC;
|
||||
import net.citizensnpcs.api.util.Messaging;
|
||||
@ -50,7 +52,9 @@ public class WaypointCommands {
|
||||
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 idx = index == null ? waypoints.size() : index;
|
||||
if (index == null) {
|
||||
index = waypoints.size();
|
||||
}
|
||||
waypoints.add(index, new Waypoint(loc));
|
||||
Messaging.sendTr(sender, Messages.WAYPOINT_ADDED, Util.prettyPrintLocation(loc), index);
|
||||
}
|
||||
@ -133,4 +137,40 @@ public class WaypointCommands {
|
||||
throw new CommandException("Provider not found.");
|
||||
Messaging.sendTr(sender, Messages.WAYPOINT_PROVIDER_SET, args.getString(1));
|
||||
}
|
||||
|
||||
@Command(
|
||||
aliases = { "waypoints", "waypoint", "wp" },
|
||||
usage = "remove (x y z world) (--index idx)",
|
||||
desc = "Adds a waypoint at a point",
|
||||
modifiers = { "remove" },
|
||||
min = 1,
|
||||
max = 5,
|
||||
permission = "citizens.waypoints.remove")
|
||||
public void remove(CommandContext args, CommandSender sender, NPC npc, @Flag("index") Integer index)
|
||||
throws CommandException {
|
||||
WaypointProvider provider = npc.getOrAddTrait(Waypoints.class).getCurrentProvider();
|
||||
if (!(provider instanceof LinearWaypointProvider))
|
||||
throw new CommandException();
|
||||
List<Waypoint> waypoints = (List<Waypoint>) ((LinearWaypointProvider) provider).waypoints();
|
||||
if (index != null && index >= 0 && index < waypoints.size()) {
|
||||
waypoints.remove((int) index);
|
||||
Messaging.sendTr(sender, Messages.WAYPOINT_REMOVED, index);
|
||||
} else {
|
||||
if (args.argsLength() < 4)
|
||||
throw new CommandUsageException();
|
||||
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));
|
||||
for (Iterator<Waypoint> iterator = waypoints.iterator(); iterator.hasNext();) {
|
||||
Waypoint wp = iterator.next();
|
||||
if (wp.getLocation().equals(loc)) {
|
||||
iterator.remove();
|
||||
}
|
||||
}
|
||||
Messaging.sendTr(sender, Messages.WAYPOINT_REMOVED, Util.prettyPrintLocation(loc));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -425,6 +425,7 @@ public class Messages {
|
||||
public static final String WANDER_WAYPOINTS_WORLDGUARD_REGION_SET = "citizens.editors.waypoints.wander.worldguard-region-set";
|
||||
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_REMOVED = "citizens.commands.waypoints.waypoint-removed";
|
||||
public static final String WAYPOINT_TELEPORTING_DISABLED = "citizens.commands.waypoints.disableteleporting.disabled";
|
||||
public static final String WAYPOINT_TELEPORTING_ENABLED = "citizens.commands.waypoints.disableteleporting.enabled";
|
||||
public static final String WAYPOINT_TRIGGER_ADD_PROMPT = "citizens.editors.waypoints.triggers.add.prompt";
|
||||
|
@ -333,6 +333,7 @@ citizens.commands.waypoints.disableteleporting.disabled=[[{0}]] will no longer t
|
||||
citizens.commands.waypoints.disableteleporting.enabled=[[{0}]] will now 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.
|
||||
citizens.commands.waypoints.waypoint-removed=Removed waypoint at [[{0}]].
|
||||
citizens.commands.wolf.traits-updated=[[{0}]]''s Traits were updated. Angry:[[{1}]], Sitting:[[{2}]], Tamed:[[{3}]], Collar Color:[[{4}]]
|
||||
citizens.conversations.selection.invalid-choice=[[{0}]] is not a valid option.
|
||||
citizens.economy.loaded=Loaded economy handling via Vault.
|
||||
|
Loading…
Reference in New Issue
Block a user