Skip to content

Commit 8c02355

Browse files
committed
Minor cleanups and modernizations
1 parent 097bcb6 commit 8c02355

File tree

2 files changed

+30
-24
lines changed

2 files changed

+30
-24
lines changed

pom.xml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,12 +4,12 @@
44

55
<groupId>me.rayzr522</groupId>
66
<artifactId>jsonmessage</artifactId>
7-
<version>1.0.0</version>
7+
<version>1.1.0</version>
88
<name>JSONMessage</name>
99
<description>A modern implementation of Fanciful</description>
1010

1111
<properties>
12-
<java.version>1.7</java.version>
12+
<java.version>1.8</java.version>
1313
<bukkit.version>LATEST</bukkit.version>
1414
</properties>
1515

src/main/java/me/rayzr522/jsonmessage/JSONMessage.java

Lines changed: 28 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -118,9 +118,11 @@ public JsonObject toJSON() {
118118
obj.addProperty("text", "");
119119

120120
JsonArray array = new JsonArray();
121-
for (MessagePart part : parts) {
122-
array.add(part.toJSON());
123-
}
121+
122+
parts.stream()
123+
.map(MessagePart::toJSON)
124+
.forEach(array::add);
125+
124126
obj.add("extra", array);
125127

126128
return obj;
@@ -143,9 +145,11 @@ public String toString() {
143145
*/
144146
public String toLegacy() {
145147
StringBuilder output = new StringBuilder();
146-
for (MessagePart part : parts) {
147-
output.append(part.toLegacy());
148-
}
148+
149+
parts.stream()
150+
.map(MessagePart::toLegacy)
151+
.forEach(output::append);
152+
149153
return output.toString();
150154
}
151155

@@ -578,19 +582,20 @@ static void sendPacket(Object packet, Player... players) {
578582
}
579583

580584
private static void setType(Object object, byte type) {
581-
if (MAJOR_VER >= 12) {
582-
switch (type) {
583-
case 1:
584-
set("b", object, enumChatMessage);
585-
break;
586-
case 2:
587-
set("b", object, enumActionbarMessage);
588-
break;
589-
default:
590-
throw new IllegalArgumentException("type must be 1 or 2");
591-
}
592-
} else {
585+
if (MAJOR_VER < 12) {
593586
set("b", object, type);
587+
return;
588+
}
589+
590+
switch (type) {
591+
case 1:
592+
set("b", object, enumChatMessage);
593+
break;
594+
case 2:
595+
set("b", object, enumActionbarMessage);
596+
break;
597+
default:
598+
throw new IllegalArgumentException("type must be 1 or 2");
594599
}
595600
}
596601

@@ -705,7 +710,7 @@ static Object fromJson(String json) {
705710
* <br>
706711
* <br>
707712
* Example:
708-
* <p>
713+
*
709714
* <pre>
710715
* Class<?> entityPlayer = ReflectionHelper.getClass("{nms}.EntityPlayer");
711716
* </pre>
@@ -812,9 +817,10 @@ public String toLegacy() {
812817
if (color != null) {
813818
output.append(color.toString());
814819
}
815-
for (ChatColor style : styles) {
816-
output.append(style.toString());
817-
}
820+
styles.stream()
821+
.map(ChatColor::toString)
822+
.forEach(output::append);
823+
818824
return output.append(text).toString();
819825
}
820826

0 commit comments

Comments
 (0)