Skip to content

Commit c96be95

Browse files
committed
Added GUIComponent.createTextComponent() method
1 parent 5630770 commit c96be95

File tree

4 files changed

+20
-4
lines changed

4 files changed

+20
-4
lines changed

pom.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66

77
<groupId>com.sentropic.guiapi</groupId>
88
<artifactId>GUI_API</artifactId>
9-
<version>1.0</version>
9+
<version>1.1-beta.0</version>
1010
<packaging>jar</packaging>
1111

1212
<name>GUI API</name>

src/main/java/com/sentropic/guiapi/GUIConfig.java

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -59,8 +59,7 @@ public void reload() {
5959
Objects.requireNonNull(componentSection.getString("alignment")).toUpperCase());
6060
boolean scale = componentSection.getBoolean("scale", true);
6161

62-
TextComponent textComponent = new TextComponent(text);
63-
textComponent.setFont(font.getID());
62+
TextComponent textComponent = GUIComponent.createTextComponent(text, font.getID());
6463
GUIComponent component;
6564
if (width == -1) {
6665
component = new GUIComponent(id, textComponent, font.getWidth(text, scale), offset, alignment);

src/main/java/com/sentropic/guiapi/gui/GUIComponent.java

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@
22

33
import net.md_5.bungee.api.chat.BaseComponent;
44
import net.md_5.bungee.api.chat.TextComponent;
5+
import org.jetbrains.annotations.NotNull;
6+
import org.jetbrains.annotations.Nullable;
57

68
import java.util.HashSet;
79
import java.util.List;
@@ -149,4 +151,19 @@ public static int[] spacesFor(int width, int offset, Alignment alignment) {
149151
void onAdd(GUI gui) { }
150152

151153
void onRemove(GUI gui) { }
154+
155+
/**
156+
* Creates a text component using the given text and font.
157+
* Use inside the GUIComponent constructor to create it with a single statement.
158+
* @param text the text contained by the TextComponent
159+
* @param font the namespaced font ID to use for the text, as used in the resource pack
160+
* @return a new TextComponent with the provided text and font
161+
*/
162+
@NotNull
163+
public static TextComponent createTextComponent(@Nullable String text, @Nullable String font) {
164+
if (text == null) { text = ""; }
165+
TextComponent textComponent = new TextComponent(text);
166+
textComponent.setFont(font);
167+
return textComponent;
168+
}
152169
}

src/main/resources/plugin.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
name: GUIAPI
2-
version: 1.0
2+
version: 1.1-beta.0
33
main: com.sentropic.guiapi.GUIAPI
44
api-version: 1.16
55
softdepend: [ProtocolLib]

0 commit comments

Comments
 (0)