Neena Goyal

can you make me a Minecraft lan at allow me to run python discovered bought on the MC server using a plugin I will upload the main.py the dot env and the module folder in the desired manner (cogs) Cogs are the module holder in which there are different module files of python make me a Minecraft plugin that allow me to execute python files on the same on the same mc server

Kodari AI
KodariNov 6 at 6:14 am 1
PythonExecutorBridge
Minecraft plugin enabling server admins to execute Python scripts directly from in-game commands. Supports loading main.py, .env configuration, and modular cog folders. Provides /pyexec command to run scripts, /pyreload to reload modules, and /pylist to view available cogs. Integrates with Jython or external Python interpreter via subprocess, captures stdout/stderr and displays output in chat. Includes permission nodes for admin-only execution, configurable script directory, and safe execution timeout to prevent server hangs. Designed for LAN servers where Python automation enhances gameplay.

[Generation stopped]

Neena Goyal

can you make me a Minecraft lan at allow me to run python discovered bought on the MC server using a plugin I will upload the main.py the dot env and the module folder in the desired manner (cogs) Cogs are the module holder in which there are different module files of python make me a Minecraft plugin that allow me to execute python files on the same on the same like don't make this commands in the minecraft server make it like it host discord bot which is written in python on the minecraft server and make a module like the logs should we saved in the same folder of the plugin

Kodari AI
KodariNov 6 at 6:17 am 1
  1. Create a Java server plugin that starts main.py as a local Python process, with no Minecraft commands.

  2. Pass .env values to the bot, create a cogs/ folder, and save bot output under the plugin folder’s logs/.

  3. Stop the Python process cleanly when the Minecraft server disables the plugin.

Created a Paper plugin that starts main.py as a separate Python process—no Minecraft commands are added. It creates a cogs/ folder, passes values from .env into the Python process, and writes its output to plugins/PythonDiscordBot/logs/bot.log.

Place your files like this:

  • plugins/PythonDiscordBot/main.py

  • plugins/PythonDiscordBot/.env

  • plugins/PythonDiscordBot/cogs/your_cog.py

The plugin creates cogs/ and logs/ automatically. Your main.py still needs to load the cogs, and the server host needs Python plus your bot’s Python dependencies installed. Only run Python files you trust: they execute with the Minecraft server process’s operating-system permissions.

Neena Goyal

no like my bought have comes folder which have different module in it it the main.py has it module that load each file uploaded in cogs folder

📎 1 file 288 chars
📄
requirements.txt
txt 12 lines
▶
discord.py>=2.7.0
aiohttp>=3.9.0
python-dotenv>=1.0.0
Pillow>=10.0.0
# --- music / voice ---
yt-dlp
PyNaCl>=1.5.0
davey
audioop-lts>=0.2.1; python_version >= "3.13"
# ffmpeg is needed for music. If your host has none, uncomment the next line (it bundles ffmpeg, ~30 MB):
# imageio-ffmpeg
Kodari AI
KodariNov 6 at 6:20 am 1
  1. Treat main.py as the bot entry point; its existing loader remains responsible for importing the files in cogs/.

  2. Run it with the plugin folder as the working directory so .env, requirements.txt, and cogs/ are available as expected.

  3. Install requirements.txt asynchronously when present, and include installer output in logs/bot.log.

The plugin now runs your existing main.py from its data folder, so its own cog loader can load files from cogs/; the plugin doesn’t replace or duplicate that logic. If requirements.txt is present, it installs those packages before starting the bot, without blocking Minecraft’s startup. Installer and bot output go to plugins/PythonDiscordBot/logs/bot.log.

Place the files together like this:

Plain Text
plugins/PythonDiscordBot/
├── main.py
├── .env
├── requirements.txt
└── cogs/
    ├── your_cog.py
    └── another_cog.py

The server host needs Python and pip available through the configured python-command. The bot and its cogs run with the Minecraft server’s operating-system permissions, so only upload code you trust.

Kodari can make mistakes. Review important code before using.
Files
src
build.gradle
main.py
Code
5 614
src/main/java/com/kodari/pythonbot/PythonDiscordBotPlugin.java
package com.kodari.pythonbot;

import org.bukkit.plugin.java.JavaPlugin;

import java.io.BufferedReader;
import java.io.BufferedWriter;
import java.io.IOException;
import java.io.InputStreamReader;
import java.nio.charset.StandardCharsets;
import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.StandardOpenOption;
import java.time.LocalDateTime;
import java.time.format.DateTimeFormatter;
import java.util.LinkedHashMap;
import java.util.Map;
import java.util.concurrent.TimeUnit;
import java.util.regex.Pattern;

public final class PythonDiscordBotPlugin extends JavaPlugin {
    private static final Pattern ENVIRONMENT_KEY = Pattern.compile("[A-Za-z_][A-Za-z0-9_]*");
    private static final DateTimeFormatter LOG_TIME = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss");

    private final Object processLock = new Object();
    private volatile Process activeProcess;
    private volatile boolean shuttingDown;

    @Override
    public void onEnable() {
        saveDefaultConfig();

        Path pluginDirectory = getDataFolder().toPath().toAbsolutePath().normalize();
        try {
            Files.createDirectories(pluginDirectory.resolve("cogs"));
            Files.createDirectories(pluginDirectory.resolve("logs"));
        } catch (IOException exception) {
            getLogger().severe("Could not create the bot folders: " + exception.getMessage());
            getServer().getPluginManager().disablePlugin(this);
            return;
        }

        String interpreter = getConfig().getString("python-command", "python3");
        String scriptSetting = getConfig().getString("script", "main.py");
        if (interpreter == null || interpreter.isBlank() || scriptSetting == null || scriptSetting.isBlank()) {
            getLogger().severe("Set both python-command and script in config.yml.");
            getServer().getPluginManager().disablePlugin(this);
            return;
        }

        Path script = pluginDirectory.resolve(scriptSetting).normalize();
        if (!script.startsWith(pluginDirectory)) {
            getLogger().severe("The configured script must be inside this plugin's folder.");
            getServer().getPluginManager().disablePlugin(this);
            return;
        }
        if (!Files.isRegularFile(script)) {
            getLogger().warning("Python bot was not started: place " + script.getFileName()
                    + " in " + pluginDirectory + " and restart the server.");
            return;
        }

        shuttingDown = false;
        Thread startupThread = new Thread(
                () -> startBot(pluginDirectory, script, interpreter), "PythonDiscordBot-Startup");
        startupThread.setDaemon(true);
        startupThread.start();
    }

    @Override
    public void onDisable() {
        Process process;
        synchronized (processLock) {
            shuttingDown = true;
            process = activeProcess;
        }
        if (process == null || !process.isAlive()) {
            return;
        }

        process.destroy();
        try {
            if (!process.waitFor(5, TimeUnit.SECONDS)) {
                process.destroyForcibly();
                process.waitFor(2, TimeUnit.SECONDS);
            }
        } catch (InterruptedException exception) {
            Thread.currentThread().interrupt();
            process.destroyForcibly();
        }
    }

    private void startBot(Path pluginDirectory, Path script, String interpreter) {
        Path logFile = pluginDirectory.resolve("logs").resolve("bot.log");
        Path requirements = pluginDirectory.resolve("requirements.txt");
        try {
            if (Files.isRegularFile(requirements) && !installRequirements(interpreter, requirements, logFile)) {
                return;
            }
            if (shuttingDown) {
                return;
            }

            ProcessBuilder processBuilder = new ProcessBuilder(interpreter, "-u", script.toString());
            processBuilder.directory(pluginDirectory.toFile());
            processBuilder.redirectErrorStream(true);
            processBuilder.environment().putAll(readDotEnv(pluginDirectory.resolve(".env")));

            Process process = startTrackedProcess(processBuilder);
            if (process == null) {
                return;
            }
            getLogger().info("Started Python bot using " + script.getFileName() + ".");
            startOutputLogger(process, logFile);
        } catch (IOException exception) {
            if (!shuttingDown) {
                getLogger().severe("Could not start Python. Check python-command and the server's Python installation: "
                        + exception.getMessage());
            }
        }
    }

    private boolean installRequirements(String interpreter, Path requirements, Path logFile) throws IOException {
        getLogger().info("Installing Python packages from " + requirements.getFileName() + ".");
        ProcessBuilder processBuilder = new ProcessBuilder(interpreter, "-m", "pip", "install",
                "--disable-pip-version-check", "-r", requirements.toString());
        processBuilder.directory(requirements.getParent().toFile());
        processBuilder.redirectErrorStream(true);

        Process process = startTrackedProcess(processBuilder);
        if (process == null) {
            return false;
        }

        int exitCode;
        try (BufferedReader reader = new BufferedReader(
                new InputStreamReader(process.getInputStream(), StandardCharsets.UTF_8));
             BufferedWriter writer = Files.newBufferedWriter(logFile, StandardCharsets.UTF_8,
                     StandardOpenOption.CREATE, StandardOpenOption.APPEND)) {
            String line;
            while ((line = reader.readLine()) != null) {
                writer.write("[" + LocalDateTime.now().format(LOG_TIME) + "] [pip] " + line);
                writer.newLine();
                writer.flush();
                getLogger().info("[Python/pip] " + line);
            }
            exitCode = process.waitFor();
        } catch (InterruptedException exception) {
            Thread.currentThread().interrupt();
            process.destroyForcibly();
            return false;
        } finally {
            clearTrackedProcess(process);
        }

        if (exitCode != 0) {
            getLogger().severe("Python package installation failed with exit code " + exitCode
                    + ". See plugins/PythonDiscordBot/logs/bot.log.");
            return false;
        }
        return !shuttingDown;
    }

    private Process startTrackedProcess(ProcessBuilder processBuilder) throws IOException {
        synchronized (processLock) {
            if (shuttingDown) {
                return null;
            }
            activeProcess = processBuilder.start();
            return activeProcess;
        }
    }

    private void clearTrackedProcess(Process process) {
        synchronized (processLock) {
            if (activeProcess == process) {
                activeProcess = null;
            }
        }
    }

    private Map<String, String> readDotEnv(Path envFile) throws IOException {
        Map<String, String> values = new LinkedHashMap<>();
        if (!Files.isRegularFile(envFile)) {
            return values;
        }

        for (String rawLine : Files.readAllLines(envFile, StandardCharsets.UTF_8)) {
            String line = rawLine.trim();
            if (line.isEmpty() || line.startsWith("#")) {
                continue;
            }
            if (line.startsWith("export ")) {
                line = line.substring("export ".length()).trim();
            }

            int separator = line.indexOf('=');
            if (separator < 1) {
                continue;
            }