From 178d632262c503591878400162d8098063ec61d3 Mon Sep 17 00:00:00 2001 From: Aleteoryx Date: Mon, 30 Dec 2024 22:52:14 -0500 Subject: [PATCH] server basics --- build.gradle | 99 +++++++++---------- build.sh | 1 + .../aleteoryx/mc/fedimc/InstanceServer.java | 30 ++++++ .../me/aleteoryx/mc/fedimc/ServerMod.java | 5 + 4 files changed, 82 insertions(+), 53 deletions(-) create mode 100644 src/main/java/me/aleteoryx/mc/fedimc/InstanceServer.java diff --git a/build.gradle b/build.gradle index f7b3989..cfe6c37 100644 --- a/build.gradle +++ b/build.gradle @@ -1,88 +1,81 @@ plugins { - id 'fabric-loom' version '1.9.2' - id 'maven-publish' + id 'fabric-loom' version '1.9.2' } version = project.mod_version group = project.maven_group base { - archivesName = project.archives_base_name + archivesName = project.archives_base_name } repositories { - // Add repositories to retrieve artifacts from in here. - // You should only use this when depending on other mods because - // Loom adds the essential maven repositories to download Minecraft and libraries from automatically. - // See https://docs.gradle.org/current/userguide/declaring_repositories.html - // for more information about repositories. + // Add repositories to retrieve artifacts from in here. + // You should only use this when depending on other mods because + // Loom adds the essential maven repositories to download Minecraft and libraries from automatically. + // See https://docs.gradle.org/current/userguide/declaring_repositories.html + // for more information about repositories. + mavenCentral() } loom { - splitEnvironmentSourceSets() + splitEnvironmentSourceSets() - mods { - "fedimc" { - sourceSet sourceSets.main - sourceSet sourceSets.client - } - } + mods { + "fedimc" { + sourceSet sourceSets.main + sourceSet sourceSets.client + } + } } dependencies { - // To change the versions see the gradle.properties file - minecraft "com.mojang:minecraft:${project.minecraft_version}" - mappings "net.fabricmc:yarn:${project.yarn_mappings}:v2" - modImplementation "net.fabricmc:fabric-loader:${project.loader_version}" + // To change the versions see the gradle.properties file + minecraft "com.mojang:minecraft:${project.minecraft_version}" + mappings "net.fabricmc:yarn:${project.yarn_mappings}:v2" + modImplementation "net.fabricmc:fabric-loader:${project.loader_version}" - // Fabric API. This is technically optional, but you probably want it anyway. - modImplementation "net.fabricmc.fabric-api:fabric-api:${project.fabric_version}" + // Fabric API. This is technically optional, but you probably want it anyway. + modImplementation "net.fabricmc.fabric-api:fabric-api:${project.fabric_version}" + + // include jetty. this is painful but idt there's a better way to do it + implementation "org.eclipse.jetty:jetty-http:12.0.16" + implementation "org.eclipse.jetty:jetty-io:12.0.16" + implementation "org.eclipse.jetty:jetty-server:12.0.16" + implementation "org.eclipse.jetty:jetty-util:12.0.16" + + include "org.eclipse.jetty:jetty-http:12.0.16" + include "org.eclipse.jetty:jetty-io:12.0.16" + include "org.eclipse.jetty:jetty-server:12.0.16" + include "org.eclipse.jetty:jetty-util:12.0.16" } processResources { - inputs.property "version", project.version + inputs.property "version", project.version - filesMatching("fabric.mod.json") { - expand "version": project.version - } + filesMatching("fabric.mod.json") { + expand "version": project.version + } } tasks.withType(JavaCompile).configureEach { - it.options.release = 21 + it.options.release = 21 } java { - // Loom will automatically attach sourcesJar to a RemapSourcesJar task and to the "build" task - // if it is present. - // If you remove this line, sources will not be generated. - withSourcesJar() + // Loom will automatically attach sourcesJar to a RemapSourcesJar task and to the "build" task + // if it is present. + // If you remove this line, sources will not be generated. + withSourcesJar() - sourceCompatibility = JavaVersion.VERSION_21 - targetCompatibility = JavaVersion.VERSION_21 + sourceCompatibility = JavaVersion.VERSION_21 + targetCompatibility = JavaVersion.VERSION_21 } jar { - from("LICENSE") { - rename { "${it}_${project.base.archivesName.get()}"} - } -} - -// configure the maven publication -publishing { - publications { - create("mavenJava", MavenPublication) { - artifactId = project.archives_base_name - from components.java - } - } - - // See https://docs.gradle.org/current/userguide/publishing_maven.html for information on how to set up publishing. - repositories { - // Add repositories to publish to here. - // Notice: This block does NOT have the same function as the block in the top level. - // The repositories here will be used for publishing your artifact, not for - // retrieving dependencies. - } + from("LICENSE") { + rename { "${it}_${project.base.archivesName.get()}"} + } } diff --git a/build.sh b/build.sh index 07593fb..0059946 100755 --- a/build.sh +++ b/build.sh @@ -1,3 +1,4 @@ #!/bin/sh ./gradlew build cp build/libs/fedimc-0.0.1.jar ~/.var/app/org.prismlauncher.PrismLauncher/data/PrismLauncher/instances/fedimc-dev/minecraft/mods/ +rsync ~/.var/app/org.prismlauncher.PrismLauncher/data/PrismLauncher/instances/fedimc-dev/minecraft/mods/* linode:/var/lib/pufferpanel/servers/48943e83/mods --info=progress2 diff --git a/src/main/java/me/aleteoryx/mc/fedimc/InstanceServer.java b/src/main/java/me/aleteoryx/mc/fedimc/InstanceServer.java new file mode 100644 index 0000000..8b824d7 --- /dev/null +++ b/src/main/java/me/aleteoryx/mc/fedimc/InstanceServer.java @@ -0,0 +1,30 @@ +package me.aleteoryx.mc.fedimc; + +import org.eclipse.jetty.server.Server; +import java.util.*; + +public class InstanceServer { + static Server server; + public static void start() { + assert server == null : "InstanceServer must not be restarted!"; + server = new Server(8080); + + CoreMod.LOGGER.info("Starting FediMC embedded Jetty server..."); + + try { + server.start(); + } catch (Exception e) { + CoreMod.LOGGER.error("Couldn't start FediMC server: " + e.toString()); + } + } + public static void stop() { + CoreMod.LOGGER.info("Stopping FediMC embedded Jetty server..."); + if (server != null) { + try { + server.stop(); + } catch (Exception e) { + CoreMod.LOGGER.error("Got error while shutting down FediMC server: " + e.toString()); + } + } + } +} diff --git a/src/main/java/me/aleteoryx/mc/fedimc/ServerMod.java b/src/main/java/me/aleteoryx/mc/fedimc/ServerMod.java index 380136f..91af4a7 100644 --- a/src/main/java/me/aleteoryx/mc/fedimc/ServerMod.java +++ b/src/main/java/me/aleteoryx/mc/fedimc/ServerMod.java @@ -1,6 +1,7 @@ package me.aleteoryx.mc.fedimc; import net.fabricmc.api.DedicatedServerModInitializer; +import net.fabricmc.fabric.api.event.lifecycle.v1.ServerLifecycleEvents; import net.minecraft.server.MinecraftServer; import net.minecraft.server.network.ServerPlayerEntity; @@ -10,6 +11,10 @@ public class ServerMod implements DedicatedServerModInitializer { @Override public void onInitializeServer() { CoreMod.LOGGER.info("Hello Fabric server!"); + + InstanceServer.start(); + + ServerLifecycleEvents.SERVER_STOPPING.register((server) -> InstanceServer.stop()); } public static void chatMessage(MinecraftServer server, String message) { -- 2.45.2