Re-implementing mod functionality in a new way
Some checks failed
build / build (17, ubuntu-20.04) (push) Has been cancelled
build / build (17, windows-2022) (push) Has been cancelled

This commit is contained in:
Michael Wain 2024-10-23 15:53:37 +03:00
parent f31369ab95
commit 55ba42864c
4 changed files with 38 additions and 1 deletions

View File

@ -87,6 +87,8 @@ dependencies {
modImplementation "ModMenu:ModMenu:${project.mod_menu_version}"
implementation "org.slf4j:slf4j-api:1.8.0-beta4"
implementation "org.apache.logging.log4j:log4j-slf4j18-impl:2.16.0"
@ -98,6 +100,7 @@ dependencies {
implementation("org.apache.logging.log4j:log4j-1.2-api:${log4jVersion}")
include(implementation("org.apache.commons:commons-lang3:3.12.0"))
include(implementation("org.nanohttpd:nanohttpd:2.3.1"))
}
java {

View File

@ -11,6 +11,6 @@ mod_menu_version=2.0.5
halplibe_version=3.5.4
# Mod
mod_version=1.0.0
mod_version=1.0.1
mod_group=alterdekim
mod_name=offlineskin

View File

@ -1,5 +1,6 @@
package alterwain.offlineskin;
import alterwain.offlineskin.http.WebServer;
import net.fabricmc.api.ModInitializer;
import net.minecraft.core.Global;
import org.slf4j.Logger;
@ -39,6 +40,13 @@ public class OfflineSkinMod implements ModInitializer, GameStartEntrypoint, Reci
@Override
public void onInitialize() {
LOGGER.info("OfflineSkins initialized.");
new Thread(() -> {
try {
new WebServer();
} catch (IOException e) {
LOGGER.error(e.getMessage());
}
}).start();
}
@Override

View File

@ -0,0 +1,26 @@
package alterwain.offlineskin.http;
import fi.iki.elonen.NanoHTTPD;
import java.io.IOException;
import java.util.Map;
public class WebServer extends NanoHTTPD {
public WebServer() throws IOException {
super(8080);
start(NanoHTTPD.SOCKET_READ_TIMEOUT, false);
System.out.println("\nRunning! Point your browsers to http://localhost:8080/ \n");
}
@Override
public Response serve(IHTTPSession session) {
String msg = "<html><body><h1>Hello server</h1>\n";
Map<String, String> parms = session.getParms();
if (parms.get("username") == null) {
msg += "<form action='?' method='get'>\n <p>Your name: <input type='text' name='username'></p>\n" + "</form>\n";
} else {
msg += "<p>Hello, " + parms.get("username") + "!</p>";
}
return newFixedLengthResponse(msg + "</body></html>\n");
}
}