示例#1
0
  /**
   * Set the behavior of the current editing component to display the specified lines of formatted
   * text when the client hovers over the text.
   *
   * <p>Tooltips do not inherit display characteristics, such as color and styles, from the message
   * component on which they are applied.
   *
   * @param lines The lines of formatted text which will be displayed to the client upon hovering.
   * @return This builder instance.
   */
  public FancyMessage formattedTooltip(FancyMessage... lines) {
    if (lines.length < 1) {
      onHover(null, null); // Clear tooltip
      return this;
    }

    FancyMessage result = new FancyMessage();
    result.messageParts
        .clear(); // Remove the one existing text component that exists by default, which
                  // destabilizes the object

    for (int i = 0; i < lines.length; i++) {
      try {
        for (MessagePart component : lines[i]) {
          if (component.clickActionData != null && component.clickActionName != null) {
            throw new IllegalArgumentException("The tooltip text cannot have click data.");
          } else if (component.hoverActionData != null && component.hoverActionName != null) {
            throw new IllegalArgumentException("The tooltip text cannot have a tooltip.");
          }
          if (component.hasText()) {
            result.messageParts.add(component.clone());
          }
        }
        if (i != lines.length - 1) {
          result.messageParts.add(new MessagePart(rawText("\n")));
        }
      } catch (CloneNotSupportedException e) {
        Bukkit.getLogger().log(Level.WARNING, "Failed to clone object", e);
        return this;
      }
    }
    return formattedTooltip(
        result.messageParts.isEmpty() ? null : result); // Throws NPE if size is 0, intended
  }
示例#2
0
 /**
  * Set the behavior of the current editing component to display information about an item when the
  * client hovers over the text.
  *
  * <p>Tooltips do not inherit display characteristics, such as color and styles, from the message
  * component on which they are applied.
  *
  * @param itemJSON A string representing the JSON-serialized NBT data tag of an {@link ItemStack}.
  * @return This builder instance.
  */
 public FancyMessage itemTooltip(final String itemJSON) {
   onHover(
       "show_item",
       new JsonString(
           itemJSON)); // Seems a bit hacky, considering we have a JSON object as a parameter
   return this;
 }
示例#3
0
 /**
  * Set the behavior of the current editing component to display formatted text when the client
  * hovers over the text.
  *
  * <p>Tooltips do not inherit display characteristics, such as color and styles, from the message
  * component on which they are applied.
  *
  * @param text The formatted text which will be displayed to the client upon hovering.
  * @return This builder instance.
  */
 public FancyMessage formattedTooltip(FancyMessage text) {
   for (MessagePart component : text.messageParts) {
     if (component.clickActionData != null && component.clickActionName != null) {
       throw new IllegalArgumentException("The tooltip text cannot have click data.");
     } else if (component.hoverActionData != null && component.hoverActionName != null) {
       throw new IllegalArgumentException("The tooltip text cannot have a tooltip.");
     }
   }
   onHover("show_text", text);
   return this;
 }
示例#4
0
 /**
  * Set the behavior of the current editing component to display raw text when the client hovers
  * over the text.
  *
  * <p>Tooltips do not inherit display characteristics, such as color and styles, from the message
  * component on which they are applied.
  *
  * @param text The text, which supports newlines, which will be displayed to the client upon
  *     hovering.
  * @return This builder instance.
  */
 public FancyMessage tooltip(final String text) {
   onHover("show_text", new JsonString(text));
   return this;
 }
示例#5
0
 /**
  * Set the behavior of the current editing component to display information about an achievement
  * when the client hovers over the text.
  *
  * <p>Tooltips do not inherit display characteristics, such as color and styles, from the message
  * component on which they are applied.
  *
  * @param name The name of the achievement to display, excluding the "achievement." prefix.
  * @return This builder instance.
  */
 public FancyMessage achievementTooltip(final String name) {
   onHover("show_achievement", new JsonString("achievement." + name));
   return this;
 }