Dieser Commit ist enthalten in:
Ursprung
3b4943e4c9
Commit
68ef7999fd
143
SpigotCore_Main/src/de/steamwar/message/SWTextComponent.java
Normale Datei
143
SpigotCore_Main/src/de/steamwar/message/SWTextComponent.java
Normale Datei
@ -0,0 +1,143 @@
|
||||
package de.steamwar.message;
|
||||
|
||||
import net.md_5.bungee.api.ChatColor;
|
||||
import net.md_5.bungee.api.chat.ClickEvent;
|
||||
import net.md_5.bungee.api.chat.HoverEvent;
|
||||
import net.md_5.bungee.api.chat.TextComponent;
|
||||
import net.md_5.bungee.api.chat.hover.content.Text;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
import java.text.MessageFormat;
|
||||
|
||||
public class SWTextComponent {
|
||||
|
||||
public static SWTextComponent tc() {
|
||||
return new SWTextComponent();
|
||||
}
|
||||
|
||||
public static SWTextComponent tc(String text) {
|
||||
return new SWTextComponent(text);
|
||||
}
|
||||
|
||||
public static SWTextComponent tc(String text, Message message) {
|
||||
return new SWTextComponent(text, message);
|
||||
}
|
||||
|
||||
public static SWTextComponent tc(Message message) {
|
||||
return new SWTextComponent(message);
|
||||
}
|
||||
|
||||
public static SWTextComponent prefix(Message message, Player player) {
|
||||
return new SWTextComponent(message.parse("PREFIX", player), message);
|
||||
}
|
||||
|
||||
private TextComponent textComponent;
|
||||
private TextComponent root;
|
||||
private Message message;
|
||||
|
||||
public SWTextComponent() {
|
||||
this.textComponent = new TextComponent();
|
||||
this.root = this.textComponent;
|
||||
}
|
||||
public SWTextComponent(String text) {
|
||||
this.textComponent = new TextComponent(TextComponent.fromLegacyText(text));
|
||||
this.root = this.textComponent;
|
||||
}
|
||||
public SWTextComponent(String text, Message message) {
|
||||
this.textComponent = new TextComponent(TextComponent.fromLegacyText(text));
|
||||
this.root = this.textComponent;
|
||||
this.message = message;
|
||||
}
|
||||
public SWTextComponent(Message message) {
|
||||
this.textComponent = new TextComponent();
|
||||
this.root = this.textComponent;
|
||||
this.message = message;
|
||||
}
|
||||
|
||||
public SWTextComponent a(String text) {
|
||||
textComponent.setText(text);
|
||||
root.addExtra(textComponent);
|
||||
textComponent = textComponent.duplicate();
|
||||
return this;
|
||||
}
|
||||
|
||||
public SWTextComponent a(Object text) {
|
||||
textComponent.setText(text.toString());
|
||||
root.addExtra(textComponent);
|
||||
textComponent = textComponent.duplicate();
|
||||
return this;
|
||||
}
|
||||
|
||||
public SWTextComponent a(String text, Player player, Object... args) {
|
||||
if(message == null) throw new IllegalStateException("Message is null");
|
||||
textComponent.setText(message.parse(text, player, args));
|
||||
root.addExtra(textComponent);
|
||||
textComponent = textComponent.duplicate();
|
||||
return this;
|
||||
}
|
||||
|
||||
public SWTextComponent a(String text, Object... args) {
|
||||
textComponent.setText(new MessageFormat(text).format(args));
|
||||
root.addExtra(textComponent);
|
||||
textComponent = textComponent.duplicate();
|
||||
return this;
|
||||
}
|
||||
|
||||
public SWTextComponent c(ChatColor color) {
|
||||
textComponent.setColor(color);
|
||||
return this;
|
||||
}
|
||||
|
||||
public SWTextComponent h(String hoverText) {
|
||||
textComponent.setHoverEvent(new HoverEvent(HoverEvent.Action.SHOW_TEXT, new Text(hoverText)));
|
||||
return this;
|
||||
}
|
||||
|
||||
public SWTextComponent rh() {
|
||||
textComponent.setHoverEvent(null);
|
||||
return this;
|
||||
}
|
||||
|
||||
public SWTextComponent k(ClickEvent clickEvent) {
|
||||
textComponent.setClickEvent(clickEvent);
|
||||
return this;
|
||||
}
|
||||
|
||||
public SWTextComponent k(ClickEvent.Action action, String value) {
|
||||
textComponent.setClickEvent(new ClickEvent(action, value));
|
||||
return this;
|
||||
}
|
||||
|
||||
public SWTextComponent rk() {
|
||||
textComponent.setClickEvent(null);
|
||||
return this;
|
||||
}
|
||||
|
||||
public SWTextComponent b(boolean bold) {
|
||||
textComponent.setBold(bold);
|
||||
return this;
|
||||
}
|
||||
|
||||
public SWTextComponent i(boolean italic) {
|
||||
textComponent.setItalic(italic);
|
||||
return this;
|
||||
}
|
||||
|
||||
public SWTextComponent u(boolean underlined) {
|
||||
textComponent.setUnderlined(underlined);
|
||||
return this;
|
||||
}
|
||||
|
||||
public SWTextComponent o(boolean obfuscated) {
|
||||
textComponent.setObfuscated(obfuscated);
|
||||
return this;
|
||||
}
|
||||
|
||||
public TextComponent build() {
|
||||
return textComponent;
|
||||
}
|
||||
|
||||
public void send(Player player) {
|
||||
player.spigot().sendMessage(root);
|
||||
}
|
||||
}
|
In neuem Issue referenzieren
Einen Benutzer sperren