super("warp [list|remove|add] [name]", "Use and manage waypoints");
}
public void execute(Player player, String message) {
String arguments[] = extractArguments(message);
Warp warp = player.getServer().data.warp;
if (arguments.length == 0) {
String warpCommand = commandPrefix() + "warp";
player.addTMessage(Color.GRAY, "Usage:");
player.addTMessage(Color.GRAY, "%s name: teleport to waypoint", warpCommand);
player.addTMessage(Color.GRAY, "%s: list waypoints", warpCommand + " list");
player.addTMessage(Color.GRAY, "%s prefix: list waypoints starting with prefix", warpCommand + " list");
player.addTMessage(Color.GRAY, "%s name: add waypoint", warpCommand + " add");
player.addTMessage(Color.GRAY, "%s name: remove waypoint", warpCommand + " remove");
return;
}
String command = arguments[0];
if (command.equals("list")) {
String prefix = arguments.length > 1 ? arguments[1] : null;
player.addTCaptionedMessage("Waypoints", "%s", join(player.getServer().data.warp.names(prefix)));
} else if (command.equals("add")) {
if (arguments.length == 1) {
player.addTMessage(Color.RED, "You have to provide the name of a waypoint");
return;
} else if (warp.contains(arguments[1])) {
player.addTMessage(Color.RED, "There already exists a waypoint named %s", arguments[1]);
return;
}
warp.set(arguments[1], player.position);
player.getServer().data.save();
player.addTMessage(Color.GRAY, "Waypoint added");
} else if (command.equals("remove")) {
if (arguments.length == 1) {
player.addTMessage(Color.RED, "You have to provide the name of a waypoint");
return;
}
String waypoint = warp.getName(arguments[1]);
if (waypoint == null) {
player.addTMessage(Color.RED, "No such waypoint exists.");
return;
}
warp.remove(waypoint);
player.getServer().data.save();
player.addTMessage(Color.GRAY, "Waypoint removed");
} else {
String waypoint = warp.getName(command);
if (waypoint == null) {
player.addTMessage(Color.RED, "No such waypoint exists.");
return;
}
player.teleportWithWarmup(warp.get(waypoint));
}
}