JSON in motd
All checks were successful
/ build (push) Successful in 54s

This commit is contained in:
Minecon724 2025-01-01 12:10:42 +01:00
parent 38a0cc331d
commit a157943187
Signed by: Minecon724
GPG key ID: 3CCC4D267742C8E8
2 changed files with 21 additions and 3 deletions

View file

@ -1,5 +1,5 @@
/*
* Copyright (C) 2024 Minecon724
* Copyright (C) 2025 Minecon724
* Tweaks724 is licensed under the GNU General Public License. See the LICENSE.md file
* in the project root for the full license text.
*/
@ -11,6 +11,9 @@ import com.comphenix.protocol.ProtocolLibrary;
import com.comphenix.protocol.events.*;
import com.comphenix.protocol.reflect.StructureModifier;
import com.google.gson.JsonElement;
import com.google.gson.JsonParseException;
import com.google.gson.JsonParser;
import eu.m724.tweaks.DebugLogger;
import eu.m724.tweaks.TweaksConfig;
import eu.m724.tweaks.TweaksPlugin;
import net.md_5.bungee.api.chat.TextComponent;
@ -64,8 +67,21 @@ public class MotdManager {
// MOTDs are split with an empty line
motds = Arrays.stream(fileContent.split("\n\n"))
.map(s -> {
JsonElement json = ComponentSerializer.toJson(TextComponent.fromLegacy(s.strip()));
.map(entry -> {
entry = entry.strip();
JsonElement json = null;
try {
json = JsonParser.parseString(entry);
DebugLogger.fine("JSON line: " + entry);
} catch (JsonParseException e) {
DebugLogger.fine("Not a JSON line: " + entry);
}
if (json == null) {
json = ComponentSerializer.toJson(TextComponent.fromLegacy(entry));
}
return Component.Serializer.fromJson(json, RegistryAccess.EMPTY);
})
.toArray(Component[]::new);

View file

@ -7,3 +7,5 @@ Random MOTD for every ping
Or just one line. If it doesn't fit it will be passed onto the second line.
Put your own files in this directory
["",{"text":"Also supports","color":"#A18D94"},{"text":" JSON","color":"#FF00FF"},{"text":"\n"},{"text":"Java","color":"dark_aqua"},{"text":"Script ","color":"aqua"},{"text":"Object","color":"gray"},{"text":" Notation","color":"red"}]