T2CodeLib/src/main/java/net/t2code/t2codelib/SPIGOT/api/messages/T2CtextBuilder.java

46 lines
1.4 KiB
Java
Raw Normal View History

2022-10-25 13:03:07 +00:00
package net.t2code.t2codelib.SPIGOT.api.messages;
2021-11-28 01:13:21 +00:00
import net.md_5.bungee.api.chat.ClickEvent;
import net.md_5.bungee.api.chat.ComponentBuilder;
import net.md_5.bungee.api.chat.HoverEvent;
import net.md_5.bungee.api.chat.TextComponent;
2022-10-25 13:03:07 +00:00
public class T2CtextBuilder {
2021-11-28 01:13:21 +00:00
private final String text;
private String hover;
private String click;
private ClickEvent.Action action;
2022-10-25 13:03:07 +00:00
public T2CtextBuilder(String text) {
2021-11-28 01:13:21 +00:00
this.text = text;
}
2022-10-25 13:03:07 +00:00
public T2CtextBuilder addHover(String hover) {
2021-11-28 01:13:21 +00:00
this.hover = hover;
return this;
}
2022-10-25 13:03:07 +00:00
public T2CtextBuilder addClickEvent(ClickEvent.Action clickEventAction, String value) {
2021-11-28 01:13:21 +00:00
this.action = clickEventAction;
this.click = value;
return this;
}
public TextComponent build() {
if (this.text.contains("[empty]")) return null;
2021-11-28 01:13:21 +00:00
TextComponent textComponent = new TextComponent();
textComponent.setText(this.text);
if (this.hover != null) {
textComponent.setHoverEvent(new HoverEvent(HoverEvent.Action.SHOW_TEXT, new ComponentBuilder(this.hover).create()));
}
if (this.click != null && (this.action != null)) {
textComponent.setClickEvent(new ClickEvent(action, this.click));
}
return textComponent;
}
public enum ClickEventType {
OPEN_URL, OPEN_FILE, RUN_COMMAND, SUGGEST_COMMAND, CHANGE_PAGE, COPY_TO_CLIPBOARD
}
}