Подписывайтесь на наш Telegram и не пропускайте важные новости! Перейти

Вопрос Discord RPC рокстар 2.0

  • Автор темы Автор темы x1azy
  • Дата начала Дата начала
Начинающий
Начинающий
Статус
Оффлайн
Регистрация
13 Фев 2026
Сообщения
27
Реакции
0
добрые люди, дайте пожалуйста Дискорд RPC под Rockstar 2.0 (фабрик 1.21.4) уже 5 день роюсь не могу найти нечего, буду очень благодерн
 
DiscordIPC:
Expand Collapse Copy
package rich.util.discord;

import com.google.gson.JsonObject;

import java.io.IOException;
import java.io.RandomAccessFile;
import java.nio.ByteBuffer;
import java.nio.ByteOrder;
import java.nio.charset.StandardCharsets;

public class DiscordIPC {
    private static final int OP_HANDSHAKE = 0;
    private static final int OP_FRAME = 1;

    private RandomAccessFile pipe;
    private String applicationId;
    private boolean connected = false;

    public DiscordIPC(String applicationId) {
        this.applicationId = applicationId;
    }

    public boolean connect() {
        if (connected) return true;

        for (int i = 0; i < 10; i++) {
            try {
                String pipeName = getPipeName(i);
                pipe = new RandomAccessFile(pipeName, "rw");
                JsonObject handshake = new JsonObject();
                handshake.addProperty("v", 1);
                handshake.addProperty("client_id", applicationId);

                send(OP_HANDSHAKE, handshake.toString());

                // Read response
                read();

                connected = true;
                System.out.println("[Discord IPC] Connected to pipe: " + pipeName);
                return true;
            } catch (Exception e) {
                // Try next pipe
            }
        }

        System.err.println("[Discord IPC] Failed to connect to Discord");
        return false;
    }

    public void updatePresence(String details, String state, String largeImageKey, String largeImageText) {
        if (!connected) return;

        try {
            JsonObject activity = new JsonObject();
            activity.addProperty("details", details);
            activity.addProperty("state", state);

            JsonObject assets = new JsonObject();
            assets.addProperty("large_image", largeImageKey);
            assets.addProperty("large_text", largeImageText);
            activity.add("assets", assets);

            JsonObject timestamps = new JsonObject();
            timestamps.addProperty("start", System.currentTimeMillis() / 1000);
            activity.add("timestamps", timestamps);

            JsonObject frame = new JsonObject();
            frame.addProperty("cmd", "SET_ACTIVITY");
            frame.addProperty("nonce", String.valueOf(System.currentTimeMillis()));

            JsonObject args = new JsonObject();
            args.addProperty("pid", ProcessHandle.current().pid());
            args.add("activity", activity);
            frame.add("args", args);

            send(OP_FRAME, frame.toString());
            System.out.println("[Discord IPC] Sent: " + frame.toString());
        } catch (Exception e) {
            System.err.println("[Discord IPC] Error updating presence: " + e.getMessage());
            e.printStackTrace();
        }
    }

    public void clearPresence() {
        if (!connected) return;

        try {
            JsonObject frame = new JsonObject();
            frame.addProperty("cmd", "SET_ACTIVITY");

            JsonObject args = new JsonObject();
            args.addProperty("pid", ProcessHandle.current().pid());
            frame.add("args", args);

            send(OP_FRAME, frame.toString());
        } catch (Exception e) {
            System.err.println("[Discord IPC] Error clearing presence: " + e.getMessage());
        }
    }

    public void disconnect() {
        if (!connected) return;

        try {
            clearPresence();
            if (pipe != null) {
                pipe.close();
            }
            connected = false;
            System.out.println("[Discord IPC] Disconnected");
        } catch (Exception e) {
            System.err.println("[Discord IPC] Error disconnecting: " + e.getMessage());
        }
    }

    private void send(int op, String data) throws IOException {
        byte[] dataBytes = data.getBytes(StandardCharsets.UTF_8);
        ByteBuffer buffer = ByteBuffer.allocate(8 + dataBytes.length);
        buffer.order(ByteOrder.LITTLE_ENDIAN);
        buffer.putInt(op);
        buffer.putInt(dataBytes.length);
        buffer.put(dataBytes);

        pipe.write(buffer.array());
    }

    private String read() throws IOException {
        byte[] header = new byte[8];
        pipe.readFully(header);

        ByteBuffer headerBuffer = ByteBuffer.wrap(header);
        headerBuffer.order(ByteOrder.LITTLE_ENDIAN);

        int op = headerBuffer.getInt();
        int length = headerBuffer.getInt();

        byte[] data = new byte[length];
        pipe.readFully(data);

        return new String(data, StandardCharsets.UTF_8);
    }

    private String getPipeName(int i) {
        String os = System.getProperty("os.name").toLowerCase();

        if (os.contains("win")) {
            return "\\\\.\\pipe\\discord-ipc-" + i;
        } else if (os.contains("mac")) {
            String tmpDir = System.getenv("TMPDIR");
            if (tmpDir == null) tmpDir = System.getenv("TMP");
            if (tmpDir == null) tmpDir = System.getenv("TEMP");
            if (tmpDir == null) tmpDir = "/tmp";
            return tmpDir + "/discord-ipc-" + i;
        } else {
            String xdgRuntime = System.getenv("XDG_RUNTIME_DIR");
            String tmpDir = System.getenv("TMPDIR");
            String tmp = System.getenv("TMP");
            String temp = System.getenv("TEMP");

            String path = xdgRuntime != null ? xdgRuntime :
                    tmpDir != null ? tmpDir :
                            tmp != null ? tmp :
                                    temp != null ? temp : "/tmp";

            return path + "/discord-ipc-" + i;
        }
    }

    public boolean isConnected() {
        if (!connected) return false;
        try {
            if (pipe == null || pipe.getChannel() == null || !pipe.getChannel().isOpen()) {
                connected = false;
                return false;
            }
        } catch (Exception e) {
            connected = false;
            return false;
        }
        
        return true;
    }
}
DiscordRPCManager:
Expand Collapse Copy
package rich.util.discord;

public class DiscordRPCManager {
    private static final String APPLICATION_ID = ""; # айди с дискорд девелопер впиши
    private static DiscordIPC ipc;
    private static boolean running = false;
    private static long startTime = 0;

    public static void init() {
        if (ipc != null) return;

        try {
            System.out.println("[Discord RPC] Initializing with Application ID: " + APPLICATION_ID);

            if (APPLICATION_ID.equals("YOUR_APPLICATION_ID_HERE")) {
                System.err.println("[Discord RPC] ERROR: Application ID not set! Please replace YOUR_APPLICATION_ID_HERE with your actual Discord Application ID");
                return;
            }

            ipc = new DiscordIPC(APPLICATION_ID);
            System.out.println("[Discord RPC] Initialized");
        } catch (Exception e) {
            System.err.println("[Discord RPC] Failed to initialize: " + e.getMessage());
            e.printStackTrace();
        }
    }

    public static void start() {
        System.out.println("[Discord RPC] Start called");
        if (ipc != null && !ipc.isConnected()) {
            System.out.println("[Discord RPC] Reconnecting...");
            ipc.disconnect();
            ipc = null;
        }

        if (ipc == null) {
            init();
        }

        if (ipc == null) {
            System.err.println("[Discord RPC] Cannot start - not initialized");
            return;
        }

        System.out.println("[Discord RPC] Attempting to connect to Discord...");

        if (!ipc.connect()) {
            System.err.println("[Discord RPC] Failed to connect to Discord. Make sure Discord is running!");
            return;
        }

        running = true;
        startTime = System.currentTimeMillis() / 1000;

        System.out.println("[Discord RPC] Connected successfully!");
        updatePresence();
    }

    public static void stop() {
        System.out.println("[Discord RPC] Stop called");

        if (ipc == null) return;

        running = false;
        try {
            if (ipc.isConnected()) {
                ipc.clearPresence();
            }
            System.out.println("[Discord RPC] Stopped");
        } catch (Exception e) {
            System.err.println("[Discord RPC] Error stopping: " + e.getMessage());
            e.printStackTrace();
        }
    }

    public static void shutdown() {
        System.out.println("[Discord RPC] Shutdown called");

        if (ipc == null) return;

        try {
            running = false;
            ipc.disconnect();
            ipc = null;
            System.out.println("[Discord RPC] Shutdown complete");
        } catch (Exception e) {
            System.err.println("[Discord RPC] Error during shutdown: " + e.getMessage());
            e.printStackTrace();
        }
    }

    public static void updatePresence() {
        if (!running || ipc == null || !ipc.isConnected()) {
            System.err.println("[Discord RPC] Cannot update presence - not connected");
            return;
        }

        try {
            System.out.println("[Discord RPC] Updating presence...");
            ipc.updatePresence(
                    "Beta",           // details
                    "Кубик льда 🧊",     // state
                    "logo",                  // large image key
                    "dsc.gg/test"               // large image text (hover)
            );
            System.out.println("[Discord RPC] Presence updated successfully!");
        } catch (Exception e) {
            System.err.println("[Discord RPC] Error updating presence: " + e.getMessage());
            e.printStackTrace();
        }
    }

    public static boolean isRunning() {
        return running;
    }

    public static long getStartTime() {
        return startTime;
    }
}
DiscordRPCModule:
Expand Collapse Copy
package rich.modules.impl.misc;

import lombok.AccessLevel;
import lombok.experimental.FieldDefaults;
import rich.modules.module.ModuleStructure;
import rich.modules.module.category.ModuleCategory;
import rich.util.Instance;
import rich.util.discord.DiscordRPCManager;

@FieldDefaults(level = AccessLevel.PRIVATE)
public class DiscordRPCModule extends ModuleStructure {
    
    public static DiscordRPCModule getInstance() {
        return Instance.get(DiscordRPCModule.class);
    }

    public DiscordRPCModule() {
        super("Discord RPC", ModuleCategory.MISC);
    }

    @Override
    public void activate() {
        super.activate();
        DiscordRPCManager.start();
    }

    @Override
    public void deactivate() {
        super.deactivate();
        DiscordRPCManager.stop();
    }
}
добрые люди, дайте пожалуйста Дискорд RPC под Rockstar 2.0 (фабрик 1.21.4) уже 5 день роюсь не могу найти нечего, буду очень благодерн
думаю разберешься как перенести
 
DiscordIPC:
Expand Collapse Copy
package rich.util.discord;

import com.google.gson.JsonObject;

import java.io.IOException;
import java.io.RandomAccessFile;
import java.nio.ByteBuffer;
import java.nio.ByteOrder;
import java.nio.charset.StandardCharsets;

public class DiscordIPC {
    private static final int OP_HANDSHAKE = 0;
    private static final int OP_FRAME = 1;

    private RandomAccessFile pipe;
    private String applicationId;
    private boolean connected = false;

    public DiscordIPC(String applicationId) {
        this.applicationId = applicationId;
    }

    public boolean connect() {
        if (connected) return true;

        for (int i = 0; i < 10; i++) {
            try {
                String pipeName = getPipeName(i);
                pipe = new RandomAccessFile(pipeName, "rw");
                JsonObject handshake = new JsonObject();
                handshake.addProperty("v", 1);
                handshake.addProperty("client_id", applicationId);

                send(OP_HANDSHAKE, handshake.toString());

                // Read response
                read();

                connected = true;
                System.out.println("[Discord IPC] Connected to pipe: " + pipeName);
                return true;
            } catch (Exception e) {
                // Try next pipe
            }
        }

        System.err.println("[Discord IPC] Failed to connect to Discord");
        return false;
    }

    public void updatePresence(String details, String state, String largeImageKey, String largeImageText) {
        if (!connected) return;

        try {
            JsonObject activity = new JsonObject();
            activity.addProperty("details", details);
            activity.addProperty("state", state);

            JsonObject assets = new JsonObject();
            assets.addProperty("large_image", largeImageKey);
            assets.addProperty("large_text", largeImageText);
            activity.add("assets", assets);

            JsonObject timestamps = new JsonObject();
            timestamps.addProperty("start", System.currentTimeMillis() / 1000);
            activity.add("timestamps", timestamps);

            JsonObject frame = new JsonObject();
            frame.addProperty("cmd", "SET_ACTIVITY");
            frame.addProperty("nonce", String.valueOf(System.currentTimeMillis()));

            JsonObject args = new JsonObject();
            args.addProperty("pid", ProcessHandle.current().pid());
            args.add("activity", activity);
            frame.add("args", args);

            send(OP_FRAME, frame.toString());
            System.out.println("[Discord IPC] Sent: " + frame.toString());
        } catch (Exception e) {
            System.err.println("[Discord IPC] Error updating presence: " + e.getMessage());
            e.printStackTrace();
        }
    }

    public void clearPresence() {
        if (!connected) return;

        try {
            JsonObject frame = new JsonObject();
            frame.addProperty("cmd", "SET_ACTIVITY");

            JsonObject args = new JsonObject();
            args.addProperty("pid", ProcessHandle.current().pid());
            frame.add("args", args);

            send(OP_FRAME, frame.toString());
        } catch (Exception e) {
            System.err.println("[Discord IPC] Error clearing presence: " + e.getMessage());
        }
    }

    public void disconnect() {
        if (!connected) return;

        try {
            clearPresence();
            if (pipe != null) {
                pipe.close();
            }
            connected = false;
            System.out.println("[Discord IPC] Disconnected");
        } catch (Exception e) {
            System.err.println("[Discord IPC] Error disconnecting: " + e.getMessage());
        }
    }

    private void send(int op, String data) throws IOException {
        byte[] dataBytes = data.getBytes(StandardCharsets.UTF_8);
        ByteBuffer buffer = ByteBuffer.allocate(8 + dataBytes.length);
        buffer.order(ByteOrder.LITTLE_ENDIAN);
        buffer.putInt(op);
        buffer.putInt(dataBytes.length);
        buffer.put(dataBytes);

        pipe.write(buffer.array());
    }

    private String read() throws IOException {
        byte[] header = new byte[8];
        pipe.readFully(header);

        ByteBuffer headerBuffer = ByteBuffer.wrap(header);
        headerBuffer.order(ByteOrder.LITTLE_ENDIAN);

        int op = headerBuffer.getInt();
        int length = headerBuffer.getInt();

        byte[] data = new byte[length];
        pipe.readFully(data);

        return new String(data, StandardCharsets.UTF_8);
    }

    private String getPipeName(int i) {
        String os = System.getProperty("os.name").toLowerCase();

        if (os.contains("win")) {
            return "\\\\.\\pipe\\discord-ipc-" + i;
        } else if (os.contains("mac")) {
            String tmpDir = System.getenv("TMPDIR");
            if (tmpDir == null) tmpDir = System.getenv("TMP");
            if (tmpDir == null) tmpDir = System.getenv("TEMP");
            if (tmpDir == null) tmpDir = "/tmp";
            return tmpDir + "/discord-ipc-" + i;
        } else {
            String xdgRuntime = System.getenv("XDG_RUNTIME_DIR");
            String tmpDir = System.getenv("TMPDIR");
            String tmp = System.getenv("TMP");
            String temp = System.getenv("TEMP");

            String path = xdgRuntime != null ? xdgRuntime :
                    tmpDir != null ? tmpDir :
                            tmp != null ? tmp :
                                    temp != null ? temp : "/tmp";

            return path + "/discord-ipc-" + i;
        }
    }

    public boolean isConnected() {
        if (!connected) return false;
        try {
            if (pipe == null || pipe.getChannel() == null || !pipe.getChannel().isOpen()) {
                connected = false;
                return false;
            }
        } catch (Exception e) {
            connected = false;
            return false;
        }
       
        return true;
    }
}
DiscordRPCManager:
Expand Collapse Copy
package rich.util.discord;

public class DiscordRPCManager {
    private static final String APPLICATION_ID = ""; # айди с дискорд девелопер впиши
    private static DiscordIPC ipc;
    private static boolean running = false;
    private static long startTime = 0;

    public static void init() {
        if (ipc != null) return;

        try {
            System.out.println("[Discord RPC] Initializing with Application ID: " + APPLICATION_ID);

            if (APPLICATION_ID.equals("YOUR_APPLICATION_ID_HERE")) {
                System.err.println("[Discord RPC] ERROR: Application ID not set! Please replace YOUR_APPLICATION_ID_HERE with your actual Discord Application ID");
                return;
            }

            ipc = new DiscordIPC(APPLICATION_ID);
            System.out.println("[Discord RPC] Initialized");
        } catch (Exception e) {
            System.err.println("[Discord RPC] Failed to initialize: " + e.getMessage());
            e.printStackTrace();
        }
    }

    public static void start() {
        System.out.println("[Discord RPC] Start called");
        if (ipc != null && !ipc.isConnected()) {
            System.out.println("[Discord RPC] Reconnecting...");
            ipc.disconnect();
            ipc = null;
        }

        if (ipc == null) {
            init();
        }

        if (ipc == null) {
            System.err.println("[Discord RPC] Cannot start - not initialized");
            return;
        }

        System.out.println("[Discord RPC] Attempting to connect to Discord...");

        if (!ipc.connect()) {
            System.err.println("[Discord RPC] Failed to connect to Discord. Make sure Discord is running!");
            return;
        }

        running = true;
        startTime = System.currentTimeMillis() / 1000;

        System.out.println("[Discord RPC] Connected successfully!");
        updatePresence();
    }

    public static void stop() {
        System.out.println("[Discord RPC] Stop called");

        if (ipc == null) return;

        running = false;
        try {
            if (ipc.isConnected()) {
                ipc.clearPresence();
            }
            System.out.println("[Discord RPC] Stopped");
        } catch (Exception e) {
            System.err.println("[Discord RPC] Error stopping: " + e.getMessage());
            e.printStackTrace();
        }
    }

    public static void shutdown() {
        System.out.println("[Discord RPC] Shutdown called");

        if (ipc == null) return;

        try {
            running = false;
            ipc.disconnect();
            ipc = null;
            System.out.println("[Discord RPC] Shutdown complete");
        } catch (Exception e) {
            System.err.println("[Discord RPC] Error during shutdown: " + e.getMessage());
            e.printStackTrace();
        }
    }

    public static void updatePresence() {
        if (!running || ipc == null || !ipc.isConnected()) {
            System.err.println("[Discord RPC] Cannot update presence - not connected");
            return;
        }

        try {
            System.out.println("[Discord RPC] Updating presence...");
            ipc.updatePresence(
                    "Beta",           // details
                    "Кубик льда 🧊",     // state
                    "logo",                  // large image key
                    "dsc.gg/test"               // large image text (hover)
            );
            System.out.println("[Discord RPC] Presence updated successfully!");
        } catch (Exception e) {
            System.err.println("[Discord RPC] Error updating presence: " + e.getMessage());
            e.printStackTrace();
        }
    }

    public static boolean isRunning() {
        return running;
    }

    public static long getStartTime() {
        return startTime;
    }
}
DiscordRPCModule:
Expand Collapse Copy
package rich.modules.impl.misc;

import lombok.AccessLevel;
import lombok.experimental.FieldDefaults;
import rich.modules.module.ModuleStructure;
import rich.modules.module.category.ModuleCategory;
import rich.util.Instance;
import rich.util.discord.DiscordRPCManager;

@FieldDefaults(level = AccessLevel.PRIVATE)
public class DiscordRPCModule extends ModuleStructure {
   
    public static DiscordRPCModule getInstance() {
        return Instance.get(DiscordRPCModule.class);
    }

    public DiscordRPCModule() {
        super("Discord RPC", ModuleCategory.MISC);
    }

    @Override
    public void activate() {
        super.activate();
        DiscordRPCManager.start();
    }

    @Override
    public void deactivate() {
        super.deactivate();
        DiscordRPCManager.stop();
    }
}

думаю разберешься как перенести
Спасибо, Да разберусь
 
DiscordIPC:
Expand Collapse Copy
package rich.util.discord;

import com.google.gson.JsonObject;

import java.io.IOException;
import java.io.RandomAccessFile;
import java.nio.ByteBuffer;
import java.nio.ByteOrder;
import java.nio.charset.StandardCharsets;

public class DiscordIPC {
    private static final int OP_HANDSHAKE = 0;
    private static final int OP_FRAME = 1;

    private RandomAccessFile pipe;
    private String applicationId;
    private boolean connected = false;

    public DiscordIPC(String applicationId) {
        this.applicationId = applicationId;
    }

    public boolean connect() {
        if (connected) return true;

        for (int i = 0; i < 10; i++) {
            try {
                String pipeName = getPipeName(i);
                pipe = new RandomAccessFile(pipeName, "rw");
                JsonObject handshake = new JsonObject();
                handshake.addProperty("v", 1);
                handshake.addProperty("client_id", applicationId);

                send(OP_HANDSHAKE, handshake.toString());

                // Read response
                read();

                connected = true;
                System.out.println("[Discord IPC] Connected to pipe: " + pipeName);
                return true;
            } catch (Exception e) {
                // Try next pipe
            }
        }

        System.err.println("[Discord IPC] Failed to connect to Discord");
        return false;
    }

    public void updatePresence(String details, String state, String largeImageKey, String largeImageText) {
        if (!connected) return;

        try {
            JsonObject activity = new JsonObject();
            activity.addProperty("details", details);
            activity.addProperty("state", state);

            JsonObject assets = new JsonObject();
            assets.addProperty("large_image", largeImageKey);
            assets.addProperty("large_text", largeImageText);
            activity.add("assets", assets);

            JsonObject timestamps = new JsonObject();
            timestamps.addProperty("start", System.currentTimeMillis() / 1000);
            activity.add("timestamps", timestamps);

            JsonObject frame = new JsonObject();
            frame.addProperty("cmd", "SET_ACTIVITY");
            frame.addProperty("nonce", String.valueOf(System.currentTimeMillis()));

            JsonObject args = new JsonObject();
            args.addProperty("pid", ProcessHandle.current().pid());
            args.add("activity", activity);
            frame.add("args", args);

            send(OP_FRAME, frame.toString());
            System.out.println("[Discord IPC] Sent: " + frame.toString());
        } catch (Exception e) {
            System.err.println("[Discord IPC] Error updating presence: " + e.getMessage());
            e.printStackTrace();
        }
    }

    public void clearPresence() {
        if (!connected) return;

        try {
            JsonObject frame = new JsonObject();
            frame.addProperty("cmd", "SET_ACTIVITY");

            JsonObject args = new JsonObject();
            args.addProperty("pid", ProcessHandle.current().pid());
            frame.add("args", args);

            send(OP_FRAME, frame.toString());
        } catch (Exception e) {
            System.err.println("[Discord IPC] Error clearing presence: " + e.getMessage());
        }
    }

    public void disconnect() {
        if (!connected) return;

        try {
            clearPresence();
            if (pipe != null) {
                pipe.close();
            }
            connected = false;
            System.out.println("[Discord IPC] Disconnected");
        } catch (Exception e) {
            System.err.println("[Discord IPC] Error disconnecting: " + e.getMessage());
        }
    }

    private void send(int op, String data) throws IOException {
        byte[] dataBytes = data.getBytes(StandardCharsets.UTF_8);
        ByteBuffer buffer = ByteBuffer.allocate(8 + dataBytes.length);
        buffer.order(ByteOrder.LITTLE_ENDIAN);
        buffer.putInt(op);
        buffer.putInt(dataBytes.length);
        buffer.put(dataBytes);

        pipe.write(buffer.array());
    }

    private String read() throws IOException {
        byte[] header = new byte[8];
        pipe.readFully(header);

        ByteBuffer headerBuffer = ByteBuffer.wrap(header);
        headerBuffer.order(ByteOrder.LITTLE_ENDIAN);

        int op = headerBuffer.getInt();
        int length = headerBuffer.getInt();

        byte[] data = new byte[length];
        pipe.readFully(data);

        return new String(data, StandardCharsets.UTF_8);
    }

    private String getPipeName(int i) {
        String os = System.getProperty("os.name").toLowerCase();

        if (os.contains("win")) {
            return "\\\\.\\pipe\\discord-ipc-" + i;
        } else if (os.contains("mac")) {
            String tmpDir = System.getenv("TMPDIR");
            if (tmpDir == null) tmpDir = System.getenv("TMP");
            if (tmpDir == null) tmpDir = System.getenv("TEMP");
            if (tmpDir == null) tmpDir = "/tmp";
            return tmpDir + "/discord-ipc-" + i;
        } else {
            String xdgRuntime = System.getenv("XDG_RUNTIME_DIR");
            String tmpDir = System.getenv("TMPDIR");
            String tmp = System.getenv("TMP");
            String temp = System.getenv("TEMP");

            String path = xdgRuntime != null ? xdgRuntime :
                    tmpDir != null ? tmpDir :
                            tmp != null ? tmp :
                                    temp != null ? temp : "/tmp";

            return path + "/discord-ipc-" + i;
        }
    }

    public boolean isConnected() {
        if (!connected) return false;
        try {
            if (pipe == null || pipe.getChannel() == null || !pipe.getChannel().isOpen()) {
                connected = false;
                return false;
            }
        } catch (Exception e) {
            connected = false;
            return false;
        }
       
        return true;
    }
}
DiscordRPCManager:
Expand Collapse Copy
package rich.util.discord;

public class DiscordRPCManager {
    private static final String APPLICATION_ID = ""; # айди с дискорд девелопер впиши
    private static DiscordIPC ipc;
    private static boolean running = false;
    private static long startTime = 0;

    public static void init() {
        if (ipc != null) return;

        try {
            System.out.println("[Discord RPC] Initializing with Application ID: " + APPLICATION_ID);

            if (APPLICATION_ID.equals("YOUR_APPLICATION_ID_HERE")) {
                System.err.println("[Discord RPC] ERROR: Application ID not set! Please replace YOUR_APPLICATION_ID_HERE with your actual Discord Application ID");
                return;
            }

            ipc = new DiscordIPC(APPLICATION_ID);
            System.out.println("[Discord RPC] Initialized");
        } catch (Exception e) {
            System.err.println("[Discord RPC] Failed to initialize: " + e.getMessage());
            e.printStackTrace();
        }
    }

    public static void start() {
        System.out.println("[Discord RPC] Start called");
        if (ipc != null && !ipc.isConnected()) {
            System.out.println("[Discord RPC] Reconnecting...");
            ipc.disconnect();
            ipc = null;
        }

        if (ipc == null) {
            init();
        }

        if (ipc == null) {
            System.err.println("[Discord RPC] Cannot start - not initialized");
            return;
        }

        System.out.println("[Discord RPC] Attempting to connect to Discord...");

        if (!ipc.connect()) {
            System.err.println("[Discord RPC] Failed to connect to Discord. Make sure Discord is running!");
            return;
        }

        running = true;
        startTime = System.currentTimeMillis() / 1000;

        System.out.println("[Discord RPC] Connected successfully!");
        updatePresence();
    }

    public static void stop() {
        System.out.println("[Discord RPC] Stop called");

        if (ipc == null) return;

        running = false;
        try {
            if (ipc.isConnected()) {
                ipc.clearPresence();
            }
            System.out.println("[Discord RPC] Stopped");
        } catch (Exception e) {
            System.err.println("[Discord RPC] Error stopping: " + e.getMessage());
            e.printStackTrace();
        }
    }

    public static void shutdown() {
        System.out.println("[Discord RPC] Shutdown called");

        if (ipc == null) return;

        try {
            running = false;
            ipc.disconnect();
            ipc = null;
            System.out.println("[Discord RPC] Shutdown complete");
        } catch (Exception e) {
            System.err.println("[Discord RPC] Error during shutdown: " + e.getMessage());
            e.printStackTrace();
        }
    }

    public static void updatePresence() {
        if (!running || ipc == null || !ipc.isConnected()) {
            System.err.println("[Discord RPC] Cannot update presence - not connected");
            return;
        }

        try {
            System.out.println("[Discord RPC] Updating presence...");
            ipc.updatePresence(
                    "Beta",           // details
                    "Кубик льда 🧊",     // state
                    "logo",                  // large image key
                    "dsc.gg/test"               // large image text (hover)
            );
            System.out.println("[Discord RPC] Presence updated successfully!");
        } catch (Exception e) {
            System.err.println("[Discord RPC] Error updating presence: " + e.getMessage());
            e.printStackTrace();
        }
    }

    public static boolean isRunning() {
        return running;
    }

    public static long getStartTime() {
        return startTime;
    }
}
DiscordRPCModule:
Expand Collapse Copy
package rich.modules.impl.misc;

import lombok.AccessLevel;
import lombok.experimental.FieldDefaults;
import rich.modules.module.ModuleStructure;
import rich.modules.module.category.ModuleCategory;
import rich.util.Instance;
import rich.util.discord.DiscordRPCManager;

@FieldDefaults(level = AccessLevel.PRIVATE)
public class DiscordRPCModule extends ModuleStructure {
   
    public static DiscordRPCModule getInstance() {
        return Instance.get(DiscordRPCModule.class);
    }

    public DiscordRPCModule() {
        super("Discord RPC", ModuleCategory.MISC);
    }

    @Override
    public void activate() {
        super.activate();
        DiscordRPCManager.start();
    }

    @Override
    public void deactivate() {
        super.deactivate();
        DiscordRPCManager.stop();
    }
}

думаю разберешься как перенести
1772726477821.png

я криворукий пастер хз как пофиксить этот шедевр
 
Назад
Сверху Снизу