added fabric mod
This commit is contained in:
@@ -0,0 +1,93 @@
|
||||
package com.xeovalyte.polarcraft;
|
||||
|
||||
import net.fabricmc.api.ModInitializer;
|
||||
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
import net.fabricmc.fabric.api.networking.v1.ServerPlayConnectionEvents;
|
||||
import net.minecraft.server.network.ServerPlayerEntity;
|
||||
import net.minecraft.text.Text;
|
||||
import java.io.BufferedReader;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStreamReader;
|
||||
import java.net.HttpURLConnection;
|
||||
import java.net.URL;
|
||||
|
||||
import java.util.UUID;
|
||||
import com.google.gson.stream.JsonReader;
|
||||
import java.io.StringReader;
|
||||
|
||||
|
||||
|
||||
public class PolarcraftMod implements ModInitializer {
|
||||
// This logger is used to write text to the console and the log file.
|
||||
// It is considered best practice to use your mod id as the logger's name.
|
||||
// That way, it's clear which mod wrote info, warnings, and errors.
|
||||
public static final Logger LOGGER = LoggerFactory.getLogger("polarcraft-mod");
|
||||
|
||||
@Override
|
||||
public void onInitialize() {
|
||||
// This code runs as soon as Minecraft is in a mod-load-ready state.
|
||||
// However, some things (like resources) may still be uninitialized.
|
||||
// Proceed with mild caution.
|
||||
ServerPlayConnectionEvents.JOIN.register((handler, sender, server) -> {
|
||||
ServerPlayerEntity player = (ServerPlayerEntity) handler.player;
|
||||
LOGGER.info("Player {} joined the game.", player.getUuidAsString());
|
||||
onPlayerJoin(player);
|
||||
});
|
||||
|
||||
LOGGER.info("Hello Fabric world!");
|
||||
}
|
||||
|
||||
private void onPlayerJoin(ServerPlayerEntity player) {
|
||||
UUID uuid = player.getUuid();
|
||||
|
||||
try {
|
||||
// Create the POST request
|
||||
URL url = new URL("http://localhost:3000/api/minecraft/verifyuuid");
|
||||
HttpURLConnection con = (HttpURLConnection) url.openConnection();
|
||||
con.setRequestMethod("POST");
|
||||
con.setRequestProperty("Content-Type", "application/json");
|
||||
con.setDoOutput(true);
|
||||
|
||||
// Write the request body
|
||||
String jsonInputString = "{\"uuid\":\"" + uuid + "\"}";
|
||||
con.getOutputStream().write(jsonInputString.getBytes());
|
||||
|
||||
// Read the response
|
||||
BufferedReader in = new BufferedReader(new InputStreamReader(con.getInputStream()));
|
||||
StringBuilder responseBuilder = new StringBuilder();
|
||||
String responseLine;
|
||||
while ((responseLine = in.readLine()) != null) {
|
||||
responseBuilder.append(responseLine);
|
||||
}
|
||||
String responseBody = responseBuilder.toString();
|
||||
|
||||
// Parse the response as a JSON object
|
||||
JsonReader jsonReader = new JsonReader(new StringReader(responseBody));
|
||||
jsonReader.beginObject();
|
||||
boolean verified = false;
|
||||
int code = -1;
|
||||
while (jsonReader.hasNext()) {
|
||||
String key = jsonReader.nextName();
|
||||
if (key.equals("verified")) {
|
||||
verified = jsonReader.nextBoolean();
|
||||
} else if (key.equals("code")) {
|
||||
code = jsonReader.nextInt();
|
||||
} else {
|
||||
jsonReader.skipValue();
|
||||
}
|
||||
}
|
||||
jsonReader.endObject();
|
||||
|
||||
// Kick the player if verified is true
|
||||
if (!verified) {
|
||||
player.networkHandler.disconnect(Text.literal("Whitelist yourself by using this code: " + code));
|
||||
}
|
||||
} catch (IOException e) {
|
||||
player.networkHandler.disconnect(Text.literal("There was an error while verifing your account"));
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
}
|
@@ -0,0 +1,15 @@
|
||||
package com.xeovalyte.polarcraft.mixin;
|
||||
|
||||
import net.minecraft.server.MinecraftServer;
|
||||
import org.spongepowered.asm.mixin.Mixin;
|
||||
import org.spongepowered.asm.mixin.injection.At;
|
||||
import org.spongepowered.asm.mixin.injection.Inject;
|
||||
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;
|
||||
|
||||
@Mixin(MinecraftServer.class)
|
||||
public class ExampleMixin {
|
||||
@Inject(at = @At("HEAD"), method = "loadWorld")
|
||||
private void init(CallbackInfo info) {
|
||||
// This code is injected into the start of MinecraftServer.loadWorld()V
|
||||
}
|
||||
}
|
BIN
mod/src/main/resources/assets/polarcraft-mod/icon.png
Normal file
BIN
mod/src/main/resources/assets/polarcraft-mod/icon.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 453 B |
38
mod/src/main/resources/fabric.mod.json
Normal file
38
mod/src/main/resources/fabric.mod.json
Normal file
@@ -0,0 +1,38 @@
|
||||
{
|
||||
"schemaVersion": 1,
|
||||
"id": "polarcraft-mod",
|
||||
"version": "${version}",
|
||||
"name": "Polarcraft Mod",
|
||||
"description": "This is an example description! Tell everyone what your mod is about!",
|
||||
"authors": [
|
||||
"Me!"
|
||||
],
|
||||
"contact": {
|
||||
"homepage": "https://fabricmc.net/",
|
||||
"sources": "https://github.com/FabricMC/fabric-example-mod"
|
||||
},
|
||||
"license": "CC0-1.0",
|
||||
"icon": "assets/polarcraft-mod/icon.png",
|
||||
"environment": "*",
|
||||
"entrypoints": {
|
||||
"main": [
|
||||
"com.xeovalyte.polarcraft.PolarcraftMod"
|
||||
]
|
||||
},
|
||||
"mixins": [
|
||||
"polarcraft-mod.mixins.json",
|
||||
{
|
||||
"config": "polarcraft-mod.client.mixins.json",
|
||||
"environment": "client"
|
||||
}
|
||||
],
|
||||
"depends": {
|
||||
"fabricloader": ">=0.14.19",
|
||||
"minecraft": "~1.19.4",
|
||||
"java": ">=17",
|
||||
"fabric-api": "*"
|
||||
},
|
||||
"suggests": {
|
||||
"another-mod": "*"
|
||||
}
|
||||
}
|
11
mod/src/main/resources/polarcraft-mod.mixins.json
Normal file
11
mod/src/main/resources/polarcraft-mod.mixins.json
Normal file
@@ -0,0 +1,11 @@
|
||||
{
|
||||
"required": true,
|
||||
"package": "com.xeovalyte.polarcraft.mixin",
|
||||
"compatibilityLevel": "JAVA_17",
|
||||
"mixins": [
|
||||
"ExampleMixin"
|
||||
],
|
||||
"injectors": {
|
||||
"defaultRequire": 1
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user