Merge branch 'dev' into feature/paper-builds

This commit is contained in:
Zedifus 2024-01-16 18:23:18 +00:00
commit 01a7c2e238
3 changed files with 57 additions and 23 deletions

View File

@ -3,9 +3,9 @@
### New features
TBD
### Bug fixes
TBD
- Fix bukkit and downstream fork MOTD crash ([Merge Request](https://gitlab.com/crafty-controller/crafty-4/-/merge_requests/686))
### Tweaks
TBD
- Refactor Forge server initialisation flow for newer versions ([Merge Request](https://gitlab.com/crafty-controller/crafty-4/-/merge_requests/687))
### Lang
TBD
<br><br>

View File

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

View File

@ -725,8 +725,9 @@ class ServerInstance:
server_obj.execution_command = execution_command
Console.debug("SUCCESS! Forge install completed")
else:
# NEW VERSION >= 1.17
elif version_major <= 1 and version_minor < 20:
# NEW VERSION >= 1.17 and <= 1.20
# (no jar file in server dir, only run.bat and run.sh)
run_file_path = ""
if self.helper.is_os_windows():
@ -771,6 +772,37 @@ class ServerInstance:
)
server_obj.execution_command = execution_command
Console.debug("SUCCESS! Forge install completed")
else:
# NEW VERSION >= 1.20
# (executable jar is back in server dir)
# Retrieving the executable jar filename
file_path = glob.glob(
f"{server_obj.path}/forge-{version[0][0]}*.jar"
)[0]
file_name = re.findall(
r"(forge-[\-0-9.]+-shim.jar)",
file_path,
)[0]
# Let's set the proper server executable
server_obj.executable = os.path.join(file_name)
# Get memory values
memory_values = re.findall(
r"-Xms([A-Z0-9\.]+) -Xmx([A-Z0-9\.]+)",
server_obj.execution_command,
)
# Now lets set up the new run command.
# This is based off the run.sh/bat that
# Forge uses in 1.17 and <
execution_command = (
f"java -Xms{memory_values[0][0]} -Xmx{memory_values[0][1]}"
f' -jar "{file_name}" nogui'
)
server_obj.execution_command = execution_command
Console.debug("SUCCESS! Forge install completed")
except:
logger.debug("Could not find run file.")
# TODO Use regex to get version and rebuild simple execution