Пример #1
0
 /**
  * Replaces parameters in the string with values specified.
  *
  * <p>
  *
  * <p>For example a string like 'My name is &lt;name&gt;' and you provide {@code Param.P("name",
  * "rojoss")} it would return 'My name is rojoss' <b>Notice how there is no &lt; and &gt; 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 &lt;Name&gt; it would
  * be replaced with Rojoss and if you put &lt;NAME&gt; 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 &lt;_name&gt;
  *
  * @param params The list of parameters to replace. The &lt;p&gt; 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;
 }
Пример #2
0
 /**
  * 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;
 }
Пример #3
0
 /**
  * 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;
 }
Пример #4
0
 /**
  * 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;
 }
Пример #5
0
 /**
  * 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;
 }
Пример #6
0
 /**
  * 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;
 }
Пример #7
0
 /**
  * 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);
 }