Created
April 9, 2020 20:11
-
-
Save ptrcnull/cfdad593c05e01d65c33d0a8f7ba4da2 to your computer and use it in GitHub Desktop.
text utils for bungeecord plugin development
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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