/** * Appends a component to the builder and makes it the current target for * formatting. You can specify the amount of formatting retained from * previous part. * * @param component the component to append * @param retention the formatting to retain * @return this ComponentBuilder for chaining */ public ComponentBuilder Append(BaseComponent component, FormatRetention retention) { _parts.Add(_current); BaseComponent previous = _current; _current = component.Duplicate(); _current.CopyFormatting(previous, retention, false); return(this); }
/** * Appends the text to the builder and makes it the current target for * formatting. You can specify the amount of formatting retained from * previous part. * * @param text the text to append * @param retention the formatting to retain * @return this ComponentBuilder for chaining */ public ComponentBuilder Append(string text, FormatRetention retention) { _parts.Add(_current); BaseComponent old = _current; _current = new TextComponent(text); _current.CopyFormatting(old, retention, false); return(this); }
/** * Copies the specified formatting of a BaseComponent. * * @param component the component to copy from * @param retention the formatting to copy * @param replace if already set formatting should be replaced by the new * component */ public void CopyFormatting(BaseComponent component, FormatRetention retention, bool replace) { if (retention == FormatRetention.Events || retention == FormatRetention.All) { if (replace || ClickEvent == null) { ClickEvent = component.ClickEvent; } if (replace || HoverEvent == null) { HoverEvent = component.HoverEvent; } } if (retention == FormatRetention.Formatting || retention == FormatRetention.All) { if (replace || Color == null) { Color = component.GetColorRaw(); } if (replace || Bold == null) { Bold = component.IsBoldRaw(); } if (replace || Italic == null) { Italic = component.IsItalicRaw(); } if (replace || Underlined == null) { Underlined = component.IsUnderlinedRaw(); } if (replace || Strikethrough == null) { Strikethrough = component.IsStrikethroughRaw(); } if (replace || Obfuscated == null) { Obfuscated = (component.IsObfuscatedRaw()); } if (replace || Insertion == null) { Insertion = (component.Insertion); } } }
/** * Retains only the specified formatting. * * @param retention the formatting to retain */ public void Retain(FormatRetention retention) { if (retention == FormatRetention.Formatting || retention == FormatRetention.None) { ClickEvent = null; HoverEvent = null; } if (retention == FormatRetention.Events || retention == FormatRetention.None) { Color = TextColor.Black; Bold = false; Italic = false; Underlined = false; Strikethrough = false; Obfuscated = false; Insertion = string.Empty; } }
/** * Appends the components to the builder and makes the last element the * current target for formatting. You can specify the amount of formatting * retained from previous part. * * @param components the components to append * @param retention the formatting to retain * @return this ComponentBuilder for chaining */ public ComponentBuilder Append(BaseComponent[] components, FormatRetention retention) { if (components.Length == 0) { return(this); } //Preconditions.checkArgument(components.Length != 0, "No components to append"); BaseComponent previous = _current; foreach (BaseComponent component in components) { _parts.Add(_current); _current = component.Duplicate(); _current.CopyFormatting(previous, retention, false); } return(this); }
/** * Retains only the specified formatting. Text is not modified. * * @param retention the formatting to retain * @return this ComponentBuilder for chaining */ public ComponentBuilder Retain(FormatRetention retention) { _current.Retain(retention); return(this); }
/** * Allows joining additional components to this builder using the given * {@link Joiner}. * * Simply executes the provided joiner on this instance to facilitate a * chain pattern. * * @param joiner joiner used for operation * @param retention the formatting to retain * @return this ComponentBuilder for chaining */ public ComponentBuilder Join(IJoiner joiner, FormatRetention retention) { return(joiner.Join(this, retention)); }