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
LineCount
public const int LineCount = 2
Field Value
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
HasHex
True when some character has a free RGB colour.
public bool HasHex { get; }
Property Value
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
lineintstartintlengthintflagMotdFormat
Returns
ClearStyle(int, int, int)
Back to the default colour with no formatting.
public void ClearStyle(int line, int start, int length)
Parameters
FromProperties(string?)
Parses the raw value of motd=, escapes and § codes included.
public static MotdDocument FromProperties(string? raw)
Parameters
rawstring
Returns
GetText(int)
public string GetText(int line)
Parameters
lineint
Returns
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
typeServerTypegameVersionstring
Returns
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
lineint
Returns
NearestCode(int)
The code whose colour is closest to rgb.
public static char NearestCode(int rgb)
Parameters
rgbint
Returns
RgbOf(char)
The colour a code draws, as 0xRRGGBB.
public static int RgbOf(char code)
Parameters
codechar
Returns
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
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
lineintstartintlengthintflagMotdFormatonbool
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
lineint0 or 1.
startintThe first character of the range.
lengthintHow many characters it covers.
fromRgbintThe colour of the first character, as 0xRRGGBB.
toRgbintThe colour of the last one.
hexboolEach 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
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
lineint0 or 1.
valuestringThe whole new text of the line, as the box now holds it.
caretint?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".
typingMotdStyle?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
Returns
ToCodes()
Both lines as real § codes joined by a real newline: what the game draws.
public string ToCodes()
Returns
ToCodes(int)
One line as § codes, starting from a clean state.
public string ToCodes(int line)
Parameters
lineint
Returns
ToProperties()
The value to store after motd=: ASCII only, § as \u00a7, the break as \n.
public string ToProperties()
Returns
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
sstring