Table of Contents

Class MotdDocument

Namespace
McServerLauncher.Services
Assembly
McServerLauncher.dll

A server's MOTD as the two lines the game's server list shows, with a style per character.

public sealed class MotdDocument
Inheritance
MotdDocument
Inherited Members

Remarks

The editor works on plain text boxes, so the document keeps text and style apart: SetText(int, string?, int?, MotdStyle?) re-aligns the styles after every keystroke instead of the box having to know about § codes. The codes only exist at the two edges — FromProperties(string?) when reading server.properties, and ToProperties() / ToCodes() when writing it or drawing it.

State carries across the line break on purpose. Minecraft keeps the colour and formatting of the first line when it starts the second, so a §6 in line one colours line two as well; the document models that rather than pretending the lines are independent, and serialising emits the §r needed to stop it.

Fields

ColorCodes

The 16 colour codes, in the order the game lists them.

public const string ColorCodes = "0123456789abcdef"

Field Value

string

LineCount

public const int LineCount = 2

Field Value

int

Properties

HadExtraLines

True when the source had a third line or more, which the list cannot show and this document does not keep.

public bool HadExtraLines { get; }

Property Value

bool

HasHex

True when some character has a free RGB colour.

public bool HasHex { get; }

Property Value

bool

Methods

AllHave(int, int, int, MotdFormat)

True when the range is not empty and every character already has the format.

public bool AllHave(int line, int start, int length, MotdFormat flag)

Parameters

line int
start int
length int
flag MotdFormat

Returns

bool

ClearStyle(int, int, int)

Back to the default colour with no formatting.

public void ClearStyle(int line, int start, int length)

Parameters

line int
start int
length int

FromProperties(string?)

Parses the raw value of motd=, escapes and § codes included.

public static MotdDocument FromProperties(string? raw)

Parameters

raw string

Returns

MotdDocument

GetText(int)

public string GetText(int line)

Parameters

line int

Returns

string

HexWorksOn(ServerType, string?)

Whether a server of this kind shows free RGB colours in its MOTD.

public static bool HexWorksOn(ServerType type, string? gameVersion)

Parameters

type ServerType
gameVersion string

Returns

bool

Remarks

Paper and its fork Purpur read motd= with a parser that knows the long §x§R§R§G§G§B§B form, from 1.16 on, when the game got RGB text. Vanilla and the mod loaders read only the 16 codes, and would show the §x run as stray letters, so the editor only offers it where it works.

Length(int)

public int Length(int line)

Parameters

line int

Returns

int

NearestCode(int)

The code whose colour is closest to rgb.

public static char NearestCode(int rgb)

Parameters

rgb int

Returns

char

RgbOf(char)

The colour a code draws, as 0xRRGGBB.

public static int RgbOf(char code)

Parameters

code char

Returns

int

SetColor(int, int, int, char)

Sets the colour of a range, keeping its formatting.

public void SetColor(int line, int start, int length, char color)

Parameters

line int
start int
length int
color char

SetFormat(int, int, int, MotdFormat, bool)

Turns a format on or off across a range.

public void SetFormat(int line, int start, int length, MotdFormat flag, bool on)

Parameters

line int
start int
length int
flag MotdFormat
on bool

SetGradient(int, int, int, int, int, bool)

Spreads a colour ramp from fromRgb to toRgb across a range, one step per character, keeping the formatting.

public void SetGradient(int line, int start, int length, int fromRgb, int toRgb, bool hex)

Parameters

line int

0 or 1.

start int

The first character of the range.

length int

How many characters it covers.

fromRgb int

The colour of the first character, as 0xRRGGBB.

toRgb int

The colour of the last one.

hex bool

Each character its own RGB colour. Otherwise each takes the nearest of the 16 codes, which gives bands rather than a smooth ramp — what a server without RGB text can show.

SetHex(int, int, int, int)

Sets a free RGB colour on a range, keeping its formatting.

public void SetHex(int line, int start, int length, int rgb)

Parameters

line int
start int
length int
rgb int

SetText(int, string?, int?, MotdStyle?)

Replaces a line's text, keeping every untouched character's style.

public void SetText(int line, string? value, int? caret = null, MotdStyle? typing = null)

Parameters

line int

0 or 1.

value string

The whole new text of the line, as the box now holds it.

caret int?

Where the caret is after the edit. Typing, backspace and delete all leave the edit touching the caret, which settles the cases a plain diff cannot — typing an "a" next to an "a".

typing MotdStyle?

The style new characters take; by default that of the character they replace or follow.

StyleAt(int, int)

public MotdStyle StyleAt(int line, int index)

Parameters

line int
index int

Returns

MotdStyle

ToCodes()

Both lines as real § codes joined by a real newline: what the game draws.

public string ToCodes()

Returns

string

ToCodes(int)

One line as § codes, starting from a clean state.

public string ToCodes(int line)

Parameters

line int

Returns

string

ToProperties()

The value to store after motd=: ASCII only, § as \u00a7, the break as \n.

public string ToProperties()

Returns

string

Remarks

Escaping everything past ASCII is what the game itself does when it writes the file. Older versions read server.properties as Latin-1, so a raw "·" or "ñ" would come back mangled; the escaped form reads the same everywhere.

Unescape(string)

Turns the properties-file escapes into the characters they stand for: \n, \uXXXX and \. Any other backslash is dropped, as Java's loader does.

public static string Unescape(string s)

Parameters

s string

Returns

string