try {
x = Double.parseDouble(parts[0]);
y = Double.parseDouble(parts[1]);
z = Double.parseDouble(parts[2]);
} catch (NumberFormatException e) {
throw new CommandException("Coordinates expected numbers!");
}
if (args.length > 1) {
return Lists.newArrayList(new Location(matchWorld(source, args[1]), x, y, z));
} else {
Player player = checkPlayer(source);
return Lists.newArrayList(new Location(player.getWorld(), x, y, z));
}
// Handle special hash tag groups
} else if (filter.charAt(0) == '#') {
String[] args = filter.split(":");
// Handle #world, which matches player of the same world as the
// calling source
if (args[0].equalsIgnoreCase("#spawn")) {
CommandBook.inst().checkPermission(source, "commandbook.spawn");
if (args.length > 1) {
return Lists.newArrayList(matchWorld(source, args[1]).getSpawnLocation());
} else {
Player sourcePlayer = checkPlayer(source);
return Lists.newArrayList(sourcePlayer.getLocation().getWorld().getSpawnLocation());
}
// Handle #target, which matches the player's target position
} else if (args[0].equalsIgnoreCase("#target")) {
CommandBook.inst().checkPermission(source, "commandbook.locations.target");
Player player = checkPlayer(source);
Location playerLoc = player.getLocation();
Block targetBlock = player.getTargetBlock(null, 100);
if (targetBlock == null) {
throw new CommandException("Failed to find a block in your target!");
} else {
Location loc = targetBlock.getLocation();
playerLoc.setX(loc.getX());
playerLoc.setY(loc.getY());
playerLoc.setZ(loc.getZ());
return Lists.newArrayList(LocationUtil.findFreePosition(playerLoc));
}
// Handle #home and #warp, which matches a player's home or a warp point
} else if (args[0].equalsIgnoreCase("#home")
|| args[0].equalsIgnoreCase("#warp")) {
String type = args[0].substring(1);
CommandBook.inst().checkPermission(source, "commandbook.locations." + type);
LocationsComponent component = type.equalsIgnoreCase("warp")
? CommandBook.inst().getComponentManager().getComponent(WarpsComponent.class)
: CommandBook.inst().getComponentManager().getComponent(HomesComponent.class);
if (component == null) {
throw new CommandException("This type of location is not enabled!");
}
RootLocationManager<NamedLocation> manager = component.getManager();
if (args.length == 1) {
if (type.equalsIgnoreCase("warp")) {
throw new CommandException("Please specify a warp name.");
}
// source player home
Player ply = checkPlayer(source);
NamedLocation loc = manager.get(ply.getWorld(), ply.getName());
if (loc == null) {
throw new CommandException("You have not set your home yet.");
}
return Lists.newArrayList(loc.getLocation());
} else if (args.length == 2) {
if (source instanceof Player) {
Player player = (Player) source;
NamedLocation loc = manager.get(player.getWorld(), args[1]);
if (loc != null && !(loc.getCreatorName().equalsIgnoreCase(player.getName()))) {
CommandBook.inst().checkPermission(source, "commandbook.locations." + type + ".other");
}
}
return Lists.newArrayList(LocationUtil.getManagedLocation(manager, checkPlayer(source).getWorld(), args[1]));
} else if (args.length == 3) {
if (source instanceof Player) {
Player player = (Player) source;
NamedLocation loc = manager.get(matchWorld(source, args[2]), args[1]);
if (loc != null && !(loc.getCreatorName().equalsIgnoreCase(player.getName()))) {
CommandBook.inst().checkPermission(source, "commandbook.locations." + type + ".other");
}
}
return Lists.newArrayList(LocationUtil.getManagedLocation(manager, matchWorld(source, args[2]), args[1]));
}
// Handle #me, which is for when a location argument is required
} else if (args[0].equalsIgnoreCase("#me")) {
return Lists.newArrayList(checkPlayer(source).getLocation());
} else {
throw new CommandException("Invalid group '" + filter + "'.");
}
}
List<Player> players;