/** * Gets the {@link TokenParser} for the specified {@link PluginContainer}, if it exists. * * @param pluginContainer The {@link PluginContainer} of the pluginContainer that registered the token. * @return The {@link TokenParser} that is run for the token, if it exists. */ default Optional<TokenParser> getTokenParser(PluginContainer pluginContainer) { Preconditions.checkNotNull(pluginContainer, "pluginContainer"); return getTokenParser(pluginContainer.getId()); }
/** * 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)); }