/** * 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. * @return The {@link Text}, if any. */ default Optional<Text> applyPrimaryToken(String primaryToken, CommandSource source) { return applyPrimaryToken(primaryToken, source, Maps.newHashMap()); }
/** * 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. * @return The {@link Text}, if any. */ default Optional<Text> applyToken(String plugin, String token, CommandSource source) { return applyToken(plugin, token, source, Maps.newHashMap()); }
/** * Parses a token that might be either a primary token or a standard token. * * @param token The token, without the delimiters. * @param source The source to apply the tokens with. * @return The token result, if it exists. */ default Optional<Text> parseToken(String token, CommandSource source) { return parseToken(token, source, null); }
/** * 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()); }
/** * Attempts to set the NucleusTextTemplate message using a string. * * <p>See {@link NucleusMessageTokenService#createFromString(String)} for * creating the tokens. Also see {@link #setMessage(NucleusTextTemplate)}.</p> * * @param message The message to send. */ default void setMessage(String message) { try { setMessage(NucleusAPI.getMessageTokenService().createFromString(message)); } catch (NucleusException e) { throw new IllegalArgumentException("Could not create the NucleusTextTemplate", e); } }
/** * 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)); }