Compare commits
2 Commits
Author | SHA1 | Date | |
---|---|---|---|
55ba42864c | |||
f31369ab95 |
@ -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 {
|
||||
|
@ -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
|
||||
|
@ -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
|
||||
|
@ -8,14 +8,20 @@ public class SendSet extends Thread {
|
||||
private final String username;
|
||||
private final boolean isCape;
|
||||
|
||||
private boolean isRunning = true;
|
||||
|
||||
public SendSet(String username, boolean isCape) {
|
||||
this.username = username;
|
||||
this.isCape = isCape;
|
||||
}
|
||||
|
||||
public void setRunning(boolean isRunning) {
|
||||
this.isRunning = isRunning;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void run() {
|
||||
while(true) {
|
||||
while(isRunning) {
|
||||
try {
|
||||
Thread.sleep(4000);
|
||||
if (isCape) {
|
||||
|
26
src/main/java/alterwain/offlineskin/http/WebServer.java
Normal file
26
src/main/java/alterwain/offlineskin/http/WebServer.java
Normal 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");
|
||||
}
|
||||
}
|
@ -14,9 +14,13 @@ import java.awt.image.BufferedImage;
|
||||
import java.io.DataInputStream;
|
||||
import java.io.DataOutputStream;
|
||||
import java.io.IOException;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
public class Packet246SkinSet extends Packet {
|
||||
|
||||
private static final Map<String, SendSet> skinThread = new HashMap<>();
|
||||
private static final Map<String, SendSet> capeThread = new HashMap<>();
|
||||
private String username;
|
||||
private byte[] skin;
|
||||
private byte[] cape;
|
||||
@ -67,8 +71,18 @@ public class Packet246SkinSet extends Packet {
|
||||
BufferedImage skin1 = OfflineSkinMod.bytesToImage(this.skin);
|
||||
BufferedImage cape1 = OfflineSkinMod.bytesToImage(this.cape);
|
||||
OfflineSkinMod.skins.put(this.username, new SkinConfig(skin1, cape1, this.modelType));
|
||||
new SendSet(this.username, false).start();
|
||||
new SendSet(this.username, true).start();
|
||||
if( Packet246SkinSet.skinThread.containsKey(this.username) ) {
|
||||
Packet246SkinSet.skinThread.get(this.username).setRunning(false);
|
||||
}
|
||||
SendSet ss = new SendSet(this.username, false);
|
||||
Packet246SkinSet.skinThread.put(this.username, ss);
|
||||
ss.start();
|
||||
if( Packet246SkinSet.capeThread.containsKey(this.username) ) {
|
||||
Packet246SkinSet.capeThread.get(this.username).setRunning(false);
|
||||
}
|
||||
SendSet cs = new SendSet(this.username, true);
|
||||
Packet246SkinSet.capeThread.put(this.username, cs);
|
||||
cs.start();
|
||||
}
|
||||
|
||||
@Override
|
||||
|
Loading…
x
Reference in New Issue
Block a user