Merge branch 'bugfix/bukkit-MOTD' into 'dev'

Fix bukkit and downstream fork MOTD crash

See merge request crafty-controller/crafty-4!686
This commit is contained in:
Iain Powrie
2024-01-16 17:58:58 +00:00
2 changed files with 22 additions and 20 deletions

View File

@ -3,7 +3,7 @@
### New features ### New features
TBD TBD
### Bug fixes ### Bug fixes
TBD - Fix bukkit and downstream fork MOTD crash ([Merge Request](https://gitlab.com/crafty-controller/crafty-4/-/merge_requests/686))
### Tweaks ### Tweaks
TBD TBD
### Lang ### Lang

View File

@ -12,6 +12,7 @@ from app.classes.minecraft.bedrock_ping import BedrockPing
from app.classes.shared.console import Console from app.classes.shared.console import Console
logger = logging.getLogger(__name__) logger = logging.getLogger(__name__)
MOTD_CODES = ["bold", "italic", "underlined", "strikethrough"]
class Server: class Server:
@ -34,26 +35,27 @@ class Server:
lines = [] lines = []
description = self.description description = self.description
if "text" in description.keys():
lines.append(description["text"])
if "extra" in description.keys(): if "extra" in description.keys():
for e in description["extra"]: if isinstance(description["extra"], list):
# Conversion format code needed only for Java Version for e in description["extra"]:
lines.append(get_code_format("reset")) if not isinstance(e, dict):
if "bold" in e.keys(): lines.append(e)
lines.append(get_code_format("bold")) continue
if "italic" in e.keys(): # Conversion format code needed only for Java Version
lines.append(get_code_format("italic")) lines.append(get_code_format("reset"))
if "underlined" in e.keys(): for item in MOTD_CODES:
lines.append(get_code_format("underlined")) if e.get(item, False):
if "strikethrough" in e.keys(): lines.append(get_code_format(item))
lines.append(get_code_format("strikethrough")) if "color" in e.keys():
if "color" in e.keys(): lines.append(get_code_format(e["color"]))
lines.append(get_code_format(e["color"])) # Then append the text
# Then append the text if "text" in e.keys():
if "text" in e.keys(): if e["text"] == "\n":
if e["text"] == "\n": lines.append("§§")
lines.append("§§") else:
else: lines.append(e["text"])
lines.append(e["text"])
total_text = " ".join(lines) total_text = " ".join(lines)
self.description = total_text self.description = total_text