generated from srnyx/plugin-template
-
-
Notifications
You must be signed in to change notification settings - Fork 3
/
AnnoyingJSON.java
103 lines (91 loc) · 3.47 KB
/
AnnoyingJSON.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
package xyz.srnyx.annoyingapi;
import net.md_5.bungee.api.chat.*;
import net.md_5.bungee.api.chat.hover.content.Text;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import xyz.srnyx.annoyingapi.utility.AnnoyingUtility;
/**
* Class to manage and build JSON messages ({@link BaseComponent}[])
*/
public class AnnoyingJSON {
@NotNull private final ComponentBuilder builder = new ComponentBuilder();
/**
* Constructs a new {@link AnnoyingJSON} instance
*/
public AnnoyingJSON() {
// Only exists to give the constructor a Javadoc
}
/**
* Gets the {@link ComponentBuilder} of the {@link AnnoyingJSON} instance
*
* @return the {@link ComponentBuilder} of the {@link AnnoyingJSON} instance
*/
@NotNull
public ComponentBuilder getBuilder() {
return builder;
}
/**
* Runs {@link ComponentBuilder#create()} and returns the result ({@link BaseComponent}[])
*
* @return the result of {@link ComponentBuilder#create()} ({@link BaseComponent}[])
*/
@NotNull
public BaseComponent[] build() {
return builder.create();
}
/**
* Runs {@link ComponentBuilder#append(BaseComponent)} on the {@link ComponentBuilder} of the {@link AnnoyingJSON} instance
*
* @param component the component to append
*
* @return the {@link AnnoyingJSON} instance
*/
@NotNull
public AnnoyingJSON append(@NotNull BaseComponent component) {
builder.append(component);
return this;
}
/**
* Appends a {@link String} (ChatColors translated) to the {@link ComponentBuilder} of the {@link AnnoyingJSON} instance
*
* @param display the {@link String} to append
*
* @return the {@link AnnoyingJSON} instance
*/
@NotNull
public AnnoyingJSON append(@NotNull String display) {
return append(new TextComponent(AnnoyingUtility.color(display)));
}
/**
* Appends a {@link String} (ChatColors translated) to the {@link ComponentBuilder} of the {@link AnnoyingJSON} instance
* <p>Also sets the {@link HoverEvent} of the appended {@link TextComponent}
*
* @param display the {@link String} to append
* @param hover the {@link HoverEvent} text to set
*
* @return the {@link AnnoyingJSON} instance
*/
@NotNull
public AnnoyingJSON append(@NotNull String display, @Nullable String hover) {
append(display);
if (hover != null) builder.event(new HoverEvent(HoverEvent.Action.SHOW_TEXT, new Text(AnnoyingUtility.color(hover))));
return this;
}
/**
* Appends a {@link String} (ChatColors translated) to the {@link ComponentBuilder} of the {@link AnnoyingJSON} instance
* <p>Also sets the {@link HoverEvent} and {@link ClickEvent} of the appended {@link TextComponent}
*
* @param display the {@link String} to append
* @param hover the {@link HoverEvent} text to set
* @param action the {@link ClickEvent} action to set
* @param value the {@link ClickEvent} value to set
*
* @return the {@link AnnoyingJSON} instance
*/
@NotNull
public AnnoyingJSON append(@NotNull String display, @Nullable String hover, @Nullable ClickEvent.Action action, @Nullable String value) {
append(display, hover);
if (action != null && value != null) builder.event(new ClickEvent(action, AnnoyingUtility.color(value)));
return this;
}
}