Facebook
From Ample Owl, 4 Years ago, written in Plain Text.
Embed
Download Paste or View Raw
Hits: 434
  1. Skip to content
  2.  
  3.  
  4. Why GitHub?  
  5. Enterprise
  6. Explore  
  7. Marketplace
  8. Pricing  
  9.  
  10. Sign in
  11. Sign up
  12.  
  13.  
  14.  Watch
  15. 22
  16.  Star
  17. 121
  18.  Fork
  19. 72
  20.  
  21. HyperiumClient/Hyperium
  22.  Code
  23.  Issues 14
  24.  Pull requests 2
  25.  Projects 0
  26.  Wiki
  27.   Security
  28.  Insights
  29. Dismiss
  30. Join GitHub today
  31. GitHub is home to over 36 million developers working together to host and review code, manage projects, and build software together.
  32. Sign up
  33. Branch: master
  34. Hyperium/src/main/java/cc/hyperium/mods/discord/DiscordPresence.java
  35. Find file
  36. Copy path
  37.  asbyth rewrite discord rp (#639)
  38. f893304 on Feb 11
  39. 1 contributor
  40. 147 lines (135 sloc) 5.95 KB
  41. Raw
  42. Blame
  43. History
  44.    
  45.  
  46. /*
  47.  
  48.  *     Copyright (C) 2018  Hyperium <https://hyperium.cc/>
  49.  
  50.  *
  51.  
  52.  *     This program is free software: you can redistribute it and/or modify
  53.  
  54.  *     it under the terms of the GNU Lesser General Public License as published
  55.  
  56.  *     by the Free Software Foundation, either version 3 of the License, or
  57.  
  58.  *     (at your option) any later version.
  59.  
  60.  *
  61.  
  62.  *     This program is distributed in the hope that it will be useful,
  63.  
  64.  *     but WITHOUT ANY WARRANTY; without even the implied warranty of
  65.  
  66.  *     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  67.  
  68.  *     GNU Lesser General Public License for more details.
  69.  
  70.  *
  71.  
  72.  *     You should have received a copy of the GNU Lesser General Public License
  73.  
  74.  *     along with this program.  If not, see <http://www.gnu.org/licenses/>.
  75.  
  76.  */
  77.  
  78.  
  79.  
  80. package cc.hyperium.mods.discord;
  81.  
  82.  
  83.  
  84. import cc.hyperium.Hyperium;
  85.  
  86. import cc.hyperium.config.Settings;
  87.  
  88. import cc.hyperium.event.EventBus;
  89.  
  90. import cc.hyperium.event.GuiOpenEvent;
  91.  
  92. import cc.hyperium.event.InvokeEvent;
  93.  
  94. import cc.hyperium.event.JoinMinigameEvent;
  95.  
  96. import cc.hyperium.event.ServerJoinEvent;
  97.  
  98. import cc.hyperium.event.SingleplayerJoinEvent;
  99.  
  100. import cc.hyperium.gui.GuiHyperiumScreenMainMenu;
  101.  
  102. import net.arikia.dev.drpc.DiscordEventHandlers;
  103.  
  104. import net.arikia.dev.drpc.DiscordRPC;
  105.  
  106. import net.arikia.dev.drpc.DiscordRichPresence;
  107.  
  108. import net.minecraft.client.Minecraft;
  109.  
  110. import net.minecraft.client.gui.GuiMultiplayer;
  111.  
  112. import net.minecraft.client.gui.GuiSelectWorld;
  113.  
  114.  
  115.  
  116. public class DiscordPresence {
  117.  
  118.  
  119.  
  120.     private long startTime;
  121.  
  122.  
  123.  
  124.     public void load() {
  125.  
  126.         if (Settings.DISCORD_RP) {
  127.  
  128.             EventBus.INSTANCE.register(this);
  129.  
  130.             startTime = System.currentTimeMillis();
  131.  
  132.             DiscordRPC.discordInitialize("412963310867054602L", new DiscordEventHandlers(), true);
  133.  
  134.  
  135.  
  136.             new Thread(() -> {
  137.  
  138.                 while (true) {
  139.  
  140.                     DiscordRPC.discordRunCallbacks();
  141.  
  142.                     try {
  143.  
  144.                         Thread.sleep(2000);
  145.  
  146.                     } catch (InterruptedException e) {
  147.  
  148.                         e.printStackTrace();
  149.  
  150.                     }
  151.  
  152.                 }
  153.  
  154.             }).start();
  155.  
  156.         }
  157.  
  158.     }
  159.  
  160.  
  161.  
  162.     public void shutdown() {
  163.  
  164.         DiscordRPC.discordClearPresence();
  165.  
  166.         DiscordRPC.discordShutdown();
  167.  
  168.     }
  169.  
  170.  
  171.  
  172.     @InvokeEvent
  173.  
  174.     private void onDisplayGui(GuiOpenEvent event) {
  175.  
  176.         if (event.getGui() instanceof GuiHyperiumScreenMainMenu) {
  177.  
  178.             DiscordRPC.discordUpdatePresence(
  179.  
  180.                 new DiscordRichPresence.Builder("On the Main Menu")
  181.  
  182.                     .setDetails("IGN: " + Minecraft.getMinecraft().getSession().getUsername())
  183.  
  184.                     .setStartTimestamps(startTime)
  185.  
  186.                     .setSmallImage("compass", "Hyperium")
  187.  
  188.                     .setBigImage("hyperium", "Hyperium Client")
  189.  
  190.                     .build()
  191.  
  192.             );
  193.  
  194.         } else if (event.getGui() instanceof GuiMultiplayer) {
  195.  
  196.             DiscordRPC.discordUpdatePresence(
  197.  
  198.                 new DiscordRichPresence.Builder("Browsing Servers")
  199.  
  200.                     .setDetails("IGN: " + Minecraft.getMinecraft().getSession().getUsername())
  201.  
  202.                     .setStartTimestamps(startTime)
  203.  
  204.                     .setSmallImage("compass", "Hyperium")
  205.  
  206.                     .setBigImage("hyperium", "Hyperium Client")
  207.  
  208.                     .build()
  209.  
  210.             );
  211.  
  212.         } else if (event.getGui() instanceof GuiSelectWorld) {
  213.  
  214.             DiscordRPC.discordUpdatePresence(
  215.  
  216.                 new DiscordRichPresence.Builder("Selecting a World")
  217.  
  218.                     .setDetails("IGN: " + Minecraft.getMinecraft().getSession().getUsername())
  219.  
  220.                     .setStartTimestamps(startTime)
  221.  
  222.                     .setSmallImage("compass", "Hyperium")
  223.  
  224.                     .setBigImage("hyperium", "Hyperium Client")
  225.  
  226.                     .build()
  227.  
  228.             );
  229.  
  230.         }
  231.  
  232.     }
  233.  
  234.  
  235.  
  236.     @InvokeEvent
  237.  
  238.     private void onServerJoin(ServerJoinEvent event) {
  239.  
  240.         if (Settings.DISCORD_RP_SERVER) {
  241.  
  242.             if (Hyperium.INSTANCE.getHandlers().getHypixelDetector().isHypixel()) {
  243.  
  244.                 DiscordRPC.discordUpdatePresence(
  245.  
  246.                 new DiscordRichPresence.Builder("Playing on Hypixel")
  247.  
  248.                     .setDetails("IGN: " + Minecraft.getMinecraft().getSession().getUsername())
  249.  
  250.                     .setStartTimestamps(startTime)
  251.  
  252.                     .setSmallImage("compass", "Hypixel Network")
  253.  
  254.                     .setBigImage("16", "Hypixel Network")
  255.  
  256.                     .build()
  257.  
  258.                 );
  259.  
  260.             } else {
  261.  
  262.                 DiscordRPC.discordUpdatePresence(
  263.  
  264.                     new DiscordRichPresence.Builder("On a Server")
  265.  
  266.                         .setDetails("IGN: " + Minecraft.getMinecraft().getSession().getUsername())
  267.  
  268.                         .setStartTimestamps(startTime)
  269.  
  270.                         .setSmallImage("compass", "Hyperium")
  271.  
  272.                         .setBigImage("hyperium", "Hyperium Client")
  273.  
  274.                         .build()
  275.  
  276.                 );
  277.  
  278.             }
  279.  
  280.         }
  281.  
  282.     }
  283.  
  284.  
  285.  
  286.     @InvokeEvent
  287.  
  288.     public void onMinigameJoin(JoinMinigameEvent event) {
  289.  
  290.         if (Settings.DISCORD_RP_SERVER) {
  291.  
  292.             DiscordRPC.discordUpdatePresence(
  293.  
  294.                 new DiscordRichPresence.Builder("Playing " + event.getMinigame().getScoreName() + " on Hypixel")
  295.  
  296.                     .setDetails("IGN: " + Minecraft.getMinecraft().getSession().getUsername())
  297.  
  298.                     .setStartTimestamps(startTime)
  299.  
  300.                     .setSmallImage("compass", "Minigames")
  301.  
  302.                     .setBigImage(String.valueOf(event.getMinigame().getId()), event.getMinigame().getScoreName())
  303.  
  304.                     .build()
  305.  
  306.             );
  307.  
  308.         }
  309.  
  310.     }
  311.  
  312.  
  313.  
  314.     @InvokeEvent
  315.  
  316.     public void singleplayer(SingleplayerJoinEvent event) {
  317.  
  318.         DiscordRPC.discordUpdatePresence(
  319.  
  320.             new DiscordRichPresence.Builder("Playing Singleplayer")
  321.  
  322.                 .setDetails("IGN: " + Minecraft.getMinecraft().getSession().getUsername())
  323.  
  324.                 .setStartTimestamps(startTime)
  325.  
  326.                 .setSmallImage("compass", "Singleplayer")
  327.  
  328.                 .setBigImage("hyperium", "Hyperium Client")
  329.  
  330.                 .build()
  331.  
  332.         );
  333.  
  334.     }
  335.  
  336. }
  337.  
  338. © 2019 GitHub, Inc.
  339. Terms
  340. Privacy
  341. Security
  342. Status
  343. Help
  344.  
  345. Contact GitHub
  346. Pricing
  347. API
  348. Training
  349. Blog
  350. About
  351.  
  352.