/** * Gets the result of a primary token's registered {@link TokenParser} on a {@link CommandSource} * * @param primaryToken The primary identifier that parsed. * @param source The {@link CommandSource} to perform the operation with. * @param variables The variables that could be used in the token. * @return The {@link Text}, if any. */ default Optional<Text> applyPrimaryToken(String primaryToken, CommandSource source, Map<String, Object> variables) { Preconditions.checkArgument(primaryToken != null && !primaryToken.isEmpty()); String[] tokenData = primaryToken.split("\\|", 2); return getPrimaryTokenParserAndIdentifier(tokenData[0].toLowerCase()) .flatMap(x -> x.getFirst().parse(tokenData.length == 2 ? x.getSecond() + "|" + tokenData[1] : x.getSecond(), source, variables)); }
/** * Gets the result of a token's registered {@link TokenParser} on a {@link CommandSource} * * @param plugin The ID of the plugin that registered the token. * @param token The identifier that is passed to the {@link TokenParser}. * @param source The {@link CommandSource} to perform the operation with. * @param variables The variables that could be used in the token. * @return The {@link Text}, if any. */ default Optional<Text> applyToken(String plugin, String token, CommandSource source, Map<String, Object> variables) { Optional<TokenParser> tokenFunction = getTokenParser(plugin); return tokenFunction.flatMap(tokenParser -> tokenParser.parse(token, source, variables)); }