SrinjoySS01

Main.java

Nov 28th, 2020 (edited)
81
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. package me.srinjoy;
  2.  
  3. import com.jagrosh.discordipc.IPCClient;
  4. import com.jagrosh.discordipc.IPCListener;
  5. import com.jagrosh.discordipc.entities.RichPresence;
  6. import com.jagrosh.discordipc.entities.pipe.PipeStatus;
  7. import javafx.application.Application;
  8. import javafx.fxml.FXMLLoader;
  9. import javafx.scene.Parent;
  10. import javafx.scene.Scene;
  11. import javafx.stage.Stage;
  12.  
  13. import java.io.IOException;
  14. import java.time.OffsetDateTime;
  15.  
  16.  
  17. public class Main extends Application {
  18.  
  19.     static IPCClient client = new IPCClient(781938142047757364L);
  20.     static RichPresence.Builder builder = new RichPresence.Builder()
  21.                                 .setDetails("Playing Discord RCP app")
  22.                                 .setStartTimestamp(OffsetDateTime.now())
  23.                                 .setLargeImage("discord", "Discord RPC");
  24.     static {
  25.         client.setListener(new IPCListener() {
  26.             @Override
  27.             public void onReady(IPCClient client) {
  28.                 client.sendRichPresence(builder.build());
  29.             }
  30.         });
  31.         try {
  32.             System.out.println(client.toString());
  33.             client.connect();
  34.         } catch (Exception e) {
  35.             e.printStackTrace();
  36.         }
  37.     }
  38.  
  39.     public static void main(String[] args) {
  40.         launch(args);
  41.     }
  42.  
  43.     @Override
  44.     public void start(Stage primaryStage) throws IOException {
  45.         Parent root = FXMLLoader.load(getClass().getResource("Main.fxml"));
  46.         primaryStage.setTitle("Discord RCP");
  47.         primaryStage.setResizable(false);
  48.         primaryStage.setScene(new Scene(root));
  49.         primaryStage.show();
  50.         primaryStage.setOnCloseRequest(event -> {
  51.             System.out.println("Closing...");
  52.             if (client != null && client.getStatus() == PipeStatus.CONNECTED) {
  53.                 client.close();
  54.                 System.out.println("Client Disconnected");
  55.             }
  56.         });
  57.     }
  58. }
  59.  
RAW Paste Data