Skip to content

Instantly share code, notes, and snippets.

@git-init-wesley
Created March 22, 2020 14:30
Show Gist options
  • Select an option

  • Save git-init-wesley/6cdb3ccaa1f77332498e5b5fea5b47ee to your computer and use it in GitHub Desktop.

Select an option

Save git-init-wesley/6cdb3ccaa1f77332498e5b5fea5b47ee to your computer and use it in GitHub Desktop.
TextComponent builder (BungeeCord, Normally spigot)
package net.makiru.bungee.builders;
import net.md_5.bungee.api.ChatColor;
import net.md_5.bungee.api.chat.*;
import org.jetbrains.annotations.NotNull;
import java.util.List;
/**
* Copyright © LEVASSEUR Wesley
*
* @author LEVASSEUR Wesley
*/
public class TextComponent_B {
private final TextComponent textComponent;
public TextComponent_B(@NotNull final TextComponent textComponent) {
this.textComponent = textComponent;
}
public TextComponent_B(@NotNull final String message) {
this.textComponent = new TextComponent(message);
}
public TextComponent_B(@NotNull final String message, @NotNull final ChatColor chatColor) {
this.textComponent = new TextComponent(message);
this.textComponent.setColor(chatColor);
}
public TextComponent_B setColor(@NotNull final ChatColor chatColor) {
if (this.textComponent != null)
this.textComponent.setColor(chatColor);
return this;
}
public TextComponent_B setBold(final boolean bold) {
if (this.textComponent != null)
this.textComponent.setBold(bold);
return this;
}
public TextComponent_B setItalic(final boolean italic) {
if (this.textComponent != null)
this.textComponent.setItalic(italic);
return this;
}
public TextComponent_B setObfuscated(final boolean obfuscated) {
if (this.textComponent != null)
this.textComponent.setObfuscated(obfuscated);
return this;
}
public TextComponent_B setStrikethrough(final boolean strikethrough) {
if (this.textComponent != null)
this.textComponent.setStrikethrough(strikethrough);
return this;
}
public TextComponent_B setUnderlined(final boolean underlined) {
if (this.textComponent != null)
this.textComponent.setUnderlined(underlined);
return this;
}
public TextComponent_B setClickEvent(@NotNull final ClickEvent clickEvent) {
if (this.textComponent != null)
this.textComponent.setClickEvent(clickEvent);
return this;
}
public TextComponent_B setHoverEvent(@NotNull final HoverEvent hoverEvent) {
if (this.textComponent != null)
this.textComponent.setHoverEvent(hoverEvent);
return this;
}
public TextComponent_B setInsertion(@NotNull final String insertion) {
if (this.textComponent != null)
this.textComponent.setInsertion(insertion);
return this;
}
public TextComponent_B setExtra(@NotNull final List<BaseComponent> extra) {
if (this.textComponent != null)
this.textComponent.setExtra(extra);
return this;
}
public TextComponent_B setText(@NotNull final String text) {
if (this.textComponent != null)
this.textComponent.setText(text);
return this;
}
public TextComponent_B addExtra(@NotNull final String text) {
if (textComponent != null)
textComponent.addExtra(text);
return this;
}
public TextComponent_B addExtra(@NotNull final BaseComponent component) {
if (this.textComponent != null)
this.textComponent.addExtra(component);
return this;
}
public TextComponent_B copyFormatting(@NotNull final BaseComponent component) {
if (this.textComponent != null)
this.textComponent.copyFormatting(component);
return this;
}
public TextComponent_B copyFormatting(@NotNull final BaseComponent component, final boolean replace) {
if (this.textComponent != null)
this.textComponent.copyFormatting(component, replace);
return this;
}
public TextComponent_B copyFormatting(@NotNull final BaseComponent component, @NotNull final ComponentBuilder.FormatRetention retention, final boolean replace) {
if (this.textComponent != null)
this.textComponent.copyFormatting(component, retention, replace);
return this;
}
public TextComponent_B replace(@NotNull final String regex, final String text) {
if (this.textComponent != null)
this.textComponent.setText(this.textComponent.getText().replace(regex, text));
return this;
}
public TextComponent toTextComponent() {
return this.textComponent;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment