Added a bunch of functions
This commit is contained in:
@@ -10,6 +10,7 @@ import org.slf4j.LoggerFactory;
|
||||
|
||||
import net.fabricmc.fabric.api.networking.v1.ServerPlayConnectionEvents;
|
||||
import net.fabricmc.loader.api.FabricLoader;
|
||||
import net.minecraft.server.MinecraftServer;
|
||||
import net.minecraft.server.network.ServerPlayerEntity;
|
||||
import java.io.IOException;
|
||||
import java.nio.charset.StandardCharsets;
|
||||
@@ -18,6 +19,9 @@ import java.io.File;
|
||||
import com.google.gson.Gson;
|
||||
import com.google.gson.GsonBuilder;
|
||||
|
||||
import static spark.Spark.*;
|
||||
|
||||
import net.fabricmc.fabric.api.event.lifecycle.v1.ServerLifecycleEvents;
|
||||
import net.fabricmc.fabric.api.message.v1.ServerMessageEvents;
|
||||
|
||||
public class PolarcraftMod implements ModInitializer {
|
||||
@@ -29,9 +33,10 @@ public class PolarcraftMod implements ModInitializer {
|
||||
private static final Gson GSON = new GsonBuilder().setPrettyPrinting().create();
|
||||
private static final File CONFIG_FILE = new File(FabricLoader.getInstance().getConfigDir().toFile(), "polarcraft.json");
|
||||
|
||||
public static String configChatMessageUrl = "https://example.com/api/minecraft/message/chattodiscord";
|
||||
public static String configGameMessageUrl = "https://example.com/api/minecraft/message/gametodiscord";
|
||||
public static String configVerifyUrl = "https://example.com/api/minecraft/verifyuuid";
|
||||
public static String configChatMessageUrl = "https://example.com/message/player";
|
||||
public static String configGameMessageUrl = "https://example.com/message/game";
|
||||
public static String configVerifyUrl = "https://example.com/verifyminecraft";
|
||||
|
||||
|
||||
@Override
|
||||
public void onInitialize() {
|
||||
@@ -54,6 +59,28 @@ public class PolarcraftMod implements ModInitializer {
|
||||
ServerMessageEvents.CHAT_MESSAGE.register((message, sender, params) -> {
|
||||
messageFunctions.sendChatMessage(message, sender);
|
||||
});
|
||||
|
||||
ServerLifecycleEvents.SERVER_STARTED.register((MinecraftServer server) -> {
|
||||
port(8080); // Choose a suitable port for your web server
|
||||
|
||||
// Define the /console POST endpoint
|
||||
post("/console", (req, res) -> {
|
||||
String command = req.body(); // Get the command from the request body
|
||||
// Validate and sanitize the command if needed
|
||||
|
||||
// Execute the console command in the Minecraft environment
|
||||
executeConsoleCommand(command, server);
|
||||
|
||||
res.status(200);
|
||||
return "Command executed successfully.";
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
private static void executeConsoleCommand(String command, MinecraftServer server) {
|
||||
// Code to execute the console command within the Minecraft environment.
|
||||
|
||||
server.getCommandManager().executeWithPrefix(server.getCommandSource(), command);
|
||||
}
|
||||
|
||||
private void loadConfig() {
|
||||
@@ -74,7 +101,7 @@ public class PolarcraftMod implements ModInitializer {
|
||||
|
||||
private void saveConfig() {
|
||||
try {
|
||||
FileUtils.writeStringToFile(CONFIG_FILE, GSON.toJson(new MyModConfig(configChatMessageUrl, configGameMessageUrl,configVerifyUrl)), StandardCharsets.UTF_8);
|
||||
FileUtils.writeStringToFile(CONFIG_FILE, GSON.toJson(new MyModConfig(configChatMessageUrl, configGameMessageUrl, configVerifyUrl)), StandardCharsets.UTF_8);
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
@@ -91,4 +118,4 @@ public class PolarcraftMod implements ModInitializer {
|
||||
this.verifyUrl = verifyUrl;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@@ -49,16 +49,16 @@ public class verifyFunction {
|
||||
JsonElement element = gson.fromJson(response.toString(), JsonElement.class);
|
||||
JsonObject jsonResponse = element.getAsJsonObject();
|
||||
|
||||
boolean verified = jsonResponse.get("verified").getAsBoolean();
|
||||
boolean whitelisted = jsonResponse.get("whitelisted").getAsBoolean();
|
||||
|
||||
if (!verified) {
|
||||
if (!whitelisted) {
|
||||
int code = jsonResponse.get("code").getAsInt();
|
||||
|
||||
player.networkHandler.disconnect(Text.literal("Whitelist yourself by using this code: " + code));
|
||||
player.networkHandler.disconnect(Text.literal("Whitelist yourself by using the /whitelist command in Discord with this code: " + code));
|
||||
} else {
|
||||
server.getCommandManager().executeWithPrefix(server.getCommandSource(), "/lp user " + player.getUuid() + " meta set display " + "\"" + jsonResponse.get("username").getAsString() + "\"");
|
||||
|
||||
messageFunctions.sendGameMessage(player.getUuid(), jsonResponse.get("usernameWithoutStyle").getAsString() + " joined the game");
|
||||
messageFunctions.sendGameMessage(player.getUuid(), jsonResponse.get("rawUsername").getAsString() + " joined the game");
|
||||
}
|
||||
} catch (IOException e) {
|
||||
player.networkHandler.disconnect(Text.literal("There was an error while verifing your account"));
|
||||
|
@@ -24,7 +24,7 @@
|
||||
],
|
||||
"depends": {
|
||||
"fabricloader": ">=0.14.19",
|
||||
"minecraft": "~1.19.4",
|
||||
"minecraft": ">=1.20.1",
|
||||
"java": ">=17",
|
||||
"fabric-api": "*"
|
||||
},
|
||||
|
Reference in New Issue
Block a user