/** * Replaces parameters in the string with values specified. * * <p> * * <p>For example a string like 'My name is <name>' and you provide {@code Param.P("name", * "rojoss")} it would return 'My name is rojoss' <b>Notice how there is no < and > sign * around the parameter name for {@link Param}!</b> If the message doesn't have parameters * specified nothing will happen. * * <p> * * <p><b>No need to call this for messages from {@link Msg#get(String, Param...)} as that already * replaces the specified params using this method</b> * * <p>It does not affect JSON messages unless used before parsing to JSON. * * <p> * * <p>It supports capitalization for parameters too. For example if you put <Name> it would * be replaced with Rojoss and if you put <NAME> it would be ROJOSS. Lowercase parameter * names will use the value provided in the parameter. The parameter can be prefixed with a * underscore to force the value lowercase like <_name> * * @param params The list of parameters to replace. The <p> parameter is reserved and this * gets replaced with global prefix. * @return This msg instance. * @see Param */ public Msg params(Param... params) { if (!message.contains(Character.toString(PARAM_OPEN)) || !message.contains(Character.toString(PARAM_CLOSE))) { return this; } if (message == null) { message = original; } for (Param param : params) { message = message.replace( PARAM_OPEN + param.getParam().toLowerCase() + PARAM_CLOSE, param.toString()); message = message.replace( PARAM_OPEN + "_" + param.getParam().toLowerCase() + PARAM_CLOSE, param.toString().toLowerCase()); message = message.replace( PARAM_OPEN + param.getParam().toUpperCase() + PARAM_CLOSE, param.toString().toUpperCase()); message = message.replace( PARAM_OPEN + Str.capitalize(param.getParam().toLowerCase()) + PARAM_CLOSE, Str.capitalize(param.toString())); } message = message.replace("<p>", Msg.getRaw("prefix").message); return this; }
/** * Capitalize the first letter of the message. * * <p>Uses {@link Str#capitalize(String)} * * @return This msg instance. */ public Msg capitalize() { message = Str.capitalize(message); return this; }
/** * Wrap the message to a specific length by splitting the message over multiple lines. * * <p>Uses {@link Str#wrapStringExact(String, int)} * * <p> * * <p>A new line symbol '\n' will be added at the specified length Words will be cut in half using * this wrapping method. * * @param length The length used for wrapping. * @return This msg instance. */ public Msg wrapExact(int length) { message = Str.wrapStringExact(message, length); return this; }
/** * Strip color from message. * * <p>This will remove any sort of color codes from the string. * * <p>Uses {@link Str#stripColor(String)} * * @return This msg instance. */ public Msg stripClr() { message = Str.stripColor(message); return this; }
/** * Remove color from the message and replace it with color codes. * * <p>This can be used after {@link #clr()} is used to get a string with color codes again. * * <p>Uses {@link Str#replaceColor(String)} * * @return This msg instance. */ public Msg removeClr() { message = Str.replaceColor(message); return this; }
/** * Color the message by converting color codes like '&a' ot chat colors. * * <p>Uses {@link Str#color(String)} * * <p> * * <p><b>By default messages get colored already.</b> We've made it that way because in 99% of the * cases you would want colored messages. You can use {@link #removeClr()} to change the color * back to color codes or {@link #stripClr()} to completely get rid of colors. * * @return This msg instance. */ public Msg clr() { message = Str.color(message); return this; }
/** * Construct a new message with the specified string message. * * <p><b>This is not a message key!</b> * * <p> * * <p>By default it will color messages. You can always use {@link #removeClr()} or {@link * #stripClr()} to remove/strip the color. * * <p> * * <p>See {@link Msg#fromString(String, Param...)} for more details. * * @param message A regular string with a custom message. Just like configurable message this may * contain custom JSON syntax and such. */ public Msg(String message) { this.original = message; this.message = Str.color(message); }