final String targetMessage = ChatUtil.replaceColorMacros(
ChatUtil.replaceMacros(sender, config.bringMessageTarget))
.replaceAll("%ctarget%", ChatUtil.toColoredName(target, null))
.replaceAll("%target%", target.getName());
(new TeleportPlayerIterator(sender, player.getLocation()) {
@Override
public void onVictim(CommandSender sender, Player player) {
player.sendMessage(targetMessage);
}
@Override
public void onInformMany(CommandSender sender, int affected) {
sender.sendMessage(senderMessage);
}
}).iterate(Lists.newArrayList(target));
return;
} else if (!CommandBook.inst().hasPermission(sender, "commandbook.teleport.other")) {
// There was a single player match, but, the target was not bringable, and the player
// does not have permission to teleport players in his/her current world.
throw new CommandException(config.bringMessageNoPerm);
}
}
Location loc = player.getLocation();
// There was not a single player match, or that single player match did not request
// to be brought. The player does have permission to teleport players in his/her
// current world. However, we're now teleporting in targets from potentially different worlds,
// and we should ensure that the sender has permission to teleport players in those worlds.
Iterable<Player> targets = InputUtil.PlayerParser.matchPlayers(sender, args.getString(0));
for (Player aTarget : targets) {
// We have already checked the from and current locations, we must now check the to if the world does not match
if (!loc.getWorld().equals(aTarget.getWorld())) {
CommandBook.inst().checkPermission(sender, aTarget.getWorld(), "commandbook.teleport.other");
}
}
(new TeleportPlayerIterator(sender, loc)).iterate(targets);
}