/
WaypointCommands.java
73 lines (67 loc) · 3.1 KB
/
WaypointCommands.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
package net.citizensnpcs.commands;
import org.bukkit.command.CommandSender;
import net.citizensnpcs.Citizens;
import net.citizensnpcs.api.command.Command;
import net.citizensnpcs.api.command.CommandContext;
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.Waypoints;
import net.citizensnpcs.util.Messages;
@Requirements(ownership = true, selected = true)
public class WaypointCommands {
public WaypointCommands(Citizens plugin) {
}
// TODO: refactor into a policy style system
@Command(
aliases = { "waypoints", "waypoint", "wp" },
usage = "disableteleport",
desc = "Disables teleportation when stuck (temporary command)",
modifiers = { "disableteleport" },
min = 1,
max = 1,
permission = "citizens.waypoints.disableteleport")
public void disableTeleporting(CommandContext args, CommandSender sender, NPC npc) throws CommandException {
npc.getNavigator().getDefaultParameters().stuckAction(null);
Messaging.sendTr(sender, Messages.WAYPOINT_TELEPORTING_DISABLED);
}
@Command(
aliases = { "waypoints", "waypoint", "wp" },
usage = "opendoors",
desc = "Enables opening doors when pathfinding (temporary command)",
modifiers = { "opendoors" },
min = 1,
max = 1,
permission = "citizens.waypoints.opendoors")
public void openDoors(CommandContext args, CommandSender sender, NPC npc) throws CommandException {
boolean opensDoors = !npc.data().get(NPC.PATHFINDER_OPEN_DOORS_METADATA, false);
npc.data().setPersistent(NPC.PATHFINDER_OPEN_DOORS_METADATA, opensDoors);
Messaging.sendTr(sender,
opensDoors ? Messages.PATHFINDER_OPEN_DOORS_ENABLED : Messages.PATHFINDER_OPEN_DOORS_DISABLED);
}
@Command(
aliases = { "waypoints", "waypoint", "wp" },
usage = "provider [provider name] (-d)",
desc = "Sets the current waypoint provider",
modifiers = { "provider" },
min = 1,
max = 2,
flags = "d",
permission = "citizens.waypoints.provider")
public void provider(CommandContext args, CommandSender sender, NPC npc) throws CommandException {
Waypoints waypoints = npc.getTrait(Waypoints.class);
if (args.argsLength() == 1) {
if (args.hasFlag('d')) {
waypoints.describeProviders(sender);
} else {
Messaging.sendTr(sender, Messages.CURRENT_WAYPOINT_PROVIDER, waypoints.getCurrentProviderName());
}
return;
}
boolean success = waypoints.setWaypointProvider(args.getString(1));
if (!success)
throw new CommandException("Provider not found.");
Messaging.sendTr(sender, Messages.WAYPOINT_PROVIDER_SET, args.getString(1));
}
}