Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added MiniMessage support to built-in motd #666

Merged
merged 13 commits into from
Mar 15, 2023
Original file line number Diff line number Diff line change
Expand Up @@ -274,11 +274,7 @@ public boolean shouldQueryShowPlugins() {
@Override
public net.kyori.adventure.text.Component getMotd() {
if (motdAsComponent == null) {
if (motd.startsWith("{")) {
motdAsComponent = GsonComponentSerializer.gson().deserialize(motd);
} else {
motdAsComponent = MiniMessage.miniMessage().deserialize(motd);
}
motdAsComponent = MiniMessage.miniMessage().deserialize(motd);
4drian3d marked this conversation as resolved.
Show resolved Hide resolved
}
return motdAsComponent;
}
Expand Down Expand Up @@ -534,18 +530,29 @@ public static VelocityConfiguration read(Path path) throws IOException {

String motd = config.getOrElse("motd", "<#09add3>A Velocity Server");

// MOTD Migration
// Old MOTD Migration
if (configVersion < 2.6) {
if (!motd.startsWith("{")) {
final String migratedMotd = MiniMessage.miniMessage().serialize(
LegacyComponentSerializer.legacyAmpersand().deserialize(motd));

config.set("motd", migratedMotd);
motd = migratedMotd;
String migratedMotd = motd;

// JSON Format Migration
final String strippedMotd = migratedMotd.strip();
if (strippedMotd.startsWith("{\"") || strippedMotd.startsWith("[\"")) {
4drian3d marked this conversation as resolved.
Show resolved Hide resolved
migratedMotd = MiniMessage.miniMessage().serialize(
GsonComponentSerializer.gson().deserialize(migratedMotd))
.replace("\\", "");
}

// Legacy '&' Format Migration
migratedMotd = MiniMessage.miniMessage().serialize(
LegacyComponentSerializer.legacyAmpersand().deserialize(migratedMotd))
.replace("\\", "");

config.set("motd", migratedMotd);
motd = migratedMotd;

config.setComment("motd",
" What should be the MOTD? This gets displayed when the player adds your server to\n"
+ "their server list. MiniMessage format and JSON are accepted.");
+ " their server list. Only MiniMessage format are accepted.");
config.set("config-version", "2.6");
mustResave = true;
}
Expand Down