Skip to content

Instantly share code, notes, and snippets.

@ptrcnull
Created April 9, 2020 20:11
Show Gist options
  • Save ptrcnull/cfdad593c05e01d65c33d0a8f7ba4da2 to your computer and use it in GitHub Desktop.
Save ptrcnull/cfdad593c05e01d65c33d0a8f7ba4da2 to your computer and use it in GitHub Desktop.
text utils for bungeecord plugin development
import net.md_5.bungee.api.ChatColor;
import net.md_5.bungee.api.chat.BaseComponent;
import net.md_5.bungee.api.chat.TextComponent;
public class TextUtils {
public static BaseComponent[] trans(String message, Object... args) {
return TextComponent.fromLegacyText(
ChatColor.translateAlternateColorCodes(
'&',
String.format(message, args)
)
);
}
public static class TextComponentBuilder {
private TextComponent base = new TextComponent();
private TextComponent c;
TextComponentBuilder() {
c = new TextComponent();
}
TextComponentBuilder(String message) {
c = new TextComponent(message);
}
TextComponentBuilder color(ChatColor color) {
c.setColor(color);
return this;
}
TextComponentBuilder clickEvent(ClickEvent ev) {
c.setClickEvent(ev);
return this;
}
TextComponentBuilder hoverEvent(HoverEvent ev) {
c.setHoverEvent(ev);
return this;
}
TextComponentBuilder text(String text) {
base.addExtra(c);
c = new TextComponent(text);
return this;
}
TextComponentBuilder component(TextComponent component) {
base.addExtra(c);
c = component;
return this;
}
TextComponent build() {
base.addExtra(c);
return base;
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment