26
26
package in .twizmwaz .cardinal .component ;
27
27
28
28
import com .google .common .collect .Lists ;
29
- import in .twizmwaz .cardinal .module .team .Team ;
30
29
import net .md_5 .bungee .api .ChatColor ;
31
30
import net .md_5 .bungee .api .chat .BaseComponent ;
32
31
import net .md_5 .bungee .api .chat .ClickEvent ;
33
32
import net .md_5 .bungee .api .chat .HoverEvent ;
34
33
35
34
import java .util .List ;
36
35
37
- public class TeamComponentBuilder {
36
+ /**
37
+ * This is a base for other component builders to use, it has all the {@link BaseComponent} fields.
38
+ *
39
+ * @param <B> The builder class, should always be the same as the class.
40
+ * @param <C> The component output.
41
+ */
42
+ public abstract class BaseComponentBuilder <B extends BaseComponentBuilder , C extends BaseComponent > {
38
43
39
- private Team team ;
40
44
private ChatColor color ;
41
45
private boolean bold ;
42
46
private boolean italic ;
@@ -46,15 +50,13 @@ public class TeamComponentBuilder {
46
50
private ClickEvent clickEvent ;
47
51
private HoverEvent hoverEvent ;
48
52
private List <BaseComponent > extra ;
49
- private boolean hover ;
53
+
54
+ private B thisObject ;
50
55
51
56
/**
52
- * Creates a builder of {@link TeamComponent} based on specified values.
53
- *
54
- * @param team The team for this component.
57
+ * This is a base for other component builders to use, it has all the {@link BaseComponent} fields.
55
58
*/
56
- public TeamComponentBuilder (Team team ) {
57
- this .team = team ;
59
+ public BaseComponentBuilder () {
58
60
color = null ;
59
61
bold = false ;
60
62
italic = false ;
@@ -64,66 +66,67 @@ public TeamComponentBuilder(Team team) {
64
66
clickEvent = null ;
65
67
hoverEvent = null ;
66
68
extra = Lists .newArrayList ();
67
- hover = true ;
69
+ thisObject = getThis () ;
68
70
}
69
71
70
- public TeamComponentBuilder color (ChatColor color ) {
72
+ /**
73
+ * Must be implemented by all sub classes, should just be a "return this;".
74
+ * @return The builder object.
75
+ */
76
+ public abstract B getThis ();
77
+
78
+
79
+ public B color (ChatColor color ) {
71
80
this .color = color ;
72
- return this ;
81
+ return thisObject ;
73
82
}
74
83
75
- public TeamComponentBuilder bold (boolean bold ) {
84
+ public B bold (boolean bold ) {
76
85
this .bold = bold ;
77
- return this ;
86
+ return thisObject ;
78
87
}
79
88
80
- public TeamComponentBuilder italic (boolean italic ) {
89
+ public B italic (boolean italic ) {
81
90
this .italic = italic ;
82
- return this ;
91
+ return thisObject ;
83
92
}
84
93
85
- public TeamComponentBuilder underlined (boolean underlined ) {
94
+ public B underlined (boolean underlined ) {
86
95
this .underlined = underlined ;
87
- return this ;
96
+ return thisObject ;
88
97
}
89
98
90
- public TeamComponentBuilder strikethrough (boolean strikethrough ) {
99
+ public B strikethrough (boolean strikethrough ) {
91
100
this .strikethrough = strikethrough ;
92
- return this ;
101
+ return thisObject ;
93
102
}
94
103
95
- public TeamComponentBuilder obfuscated (boolean obfuscated ) {
104
+ public B obfuscated (boolean obfuscated ) {
96
105
this .obfuscated = obfuscated ;
97
- return this ;
106
+ return thisObject ;
98
107
}
99
108
100
- public TeamComponentBuilder clickEvent (ClickEvent clickEvent ) {
109
+ public B clickEvent (ClickEvent clickEvent ) {
101
110
this .clickEvent = clickEvent ;
102
- return this ;
111
+ return thisObject ;
103
112
}
104
113
105
- public TeamComponentBuilder hoverEvent (HoverEvent hoverEvent ) {
114
+ public B hoverEvent (HoverEvent hoverEvent ) {
106
115
this .hoverEvent = hoverEvent ;
107
- return this ;
116
+ return thisObject ;
108
117
}
109
118
110
- public TeamComponentBuilder extra (List <BaseComponent > extra ) {
119
+ public B extra (List <BaseComponent > extra ) {
111
120
this .extra = extra ;
112
- return this ;
113
- }
114
-
115
- public TeamComponentBuilder hover (boolean hover ) {
116
- this .hover = hover ;
117
- return this ;
121
+ return thisObject ;
118
122
}
119
123
120
124
/**
121
- * Builds a {@link TeamComponent } from the specified values.
125
+ * Builds a {@link C } from the specified values.
122
126
*
123
127
* @return The built component.
124
128
*/
125
- public TeamComponent build () {
126
- TeamComponent component = new TeamComponent (team );
129
+ public C build (C component ) {
127
130
component .setColor (color );
128
131
component .setBold (bold );
129
132
component .setItalic (italic );
@@ -133,7 +136,6 @@ public TeamComponent build() {
133
136
component .setClickEvent (clickEvent );
134
137
component .setHoverEvent (hoverEvent );
135
138
component .setExtra (extra );
136
- component .setHover (hover );
137
139
return component ;
138
140
}
139
141
0 commit comments