Example #1
0
 /**
  * Returns string contains given components as plain text. (without style)
  *
  * @param components components to convert to plain text.
  * @return string contains given components as plain text. (without style)
  */
 public static String toPlainText(final BaseComponent... components) {
   final StringBuilder builder = new StringBuilder();
   for (final BaseComponent msg : components) {
     builder.append(msg.toPlainText());
   }
   return builder.toString();
 }
Example #2
0
 void toLegacyText(final StringBuilder builder) {
   if (this.extra != null) {
     for (final BaseComponent e : this.extra) {
       e.toLegacyText(builder);
     }
   }
 }
Example #3
0
 /**
  * Add new {@link BaseComponent} to this node.
  *
  * @param component new component to add.
  */
 public void addExtra(final BaseComponent component) {
   if (this.extra == null) {
     this.extra = new ArrayList<>(5);
   }
   component.parent = this;
   this.extra.add(component);
 }
Example #4
0
 @Override
 protected int replace_(final String text, final BaseComponent component, int limit) {
   if (this.extra != null) {
     for (final BaseComponent bs : this.extra) {
       limit = bs.replace_(text, component, limit);
       if (limit == 0) {
         return 0;
       }
     }
   }
   if (this.hoverEvent != null) {
     limit = this.hoverEvent.replace_(text, component, limit);
     if (limit == 0) {
       return 0;
     }
   }
   if (this.clickEvent != null) {
     limit = this.clickEvent.replace_(text, component, limit);
     if (limit == 0) {
       return 0;
     }
   }
   return limit;
 }
Example #5
0
 /**
  * Construct new BaseComponent as copy of old one.
  *
  * @param old component to copy.
  */
 BaseComponent(final BaseComponent old) {
   this.color = old.getColorRaw();
   this.bold = old.isBoldRaw();
   this.italic = old.isItalicRaw();
   this.underlined = old.isUnderlinedRaw();
   this.strikethrough = old.isStrikethroughRaw();
   this.obfuscated = old.isObfuscatedRaw();
   this.clickEvent = (old.clickEvent == null) ? null : old.clickEvent.duplicate();
   this.hoverEvent = (old.hoverEvent == null) ? null : old.hoverEvent.duplicate();
   if (old.extra != null) {
     this.extra = new ArrayList<>(old.extra.size());
     this.extra.addAll(
         old.extra.stream().map(BaseComponent::duplicate).collect(Collectors.toList()));
   }
 }
Example #6
0
 /**
  * Set list of extra/next elements appended after this one.
  *
  * @param components new list of extra/next elements.
  */
 public void setExtra(final List<BaseComponent> components) {
   for (final BaseComponent component : components) {
     component.parent = this;
   }
   this.extra = new ArrayList<>(components);
 }