Skip to content

Commit

Permalink
Changed RPC library to fix mac support (#6)
Browse files Browse the repository at this point in the history
  • Loading branch information
angelolz authored Apr 2, 2022
1 parent 3001a7d commit 4c8d71c
Show file tree
Hide file tree
Showing 6 changed files with 55 additions and 35 deletions.
5 changes: 2 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,20 +14,19 @@ cycle through all the possible information that the mod provides :)
- [Java 8](https://java.com/en/download/) (or higher, although the exe might prompt you to install Java 8 for some reason)

### Running the program
*Note: This mod does not work on macOS.*

**Windows**
- Just launch the executable program!

**Linux**
**macOS/Linux**
- Open a terminal and navigate to where the jar file is stored using the `cd` command.
- Type the command: `java -jar *.jar`.

Upon running the program, it should automatically open the Cookie Clicker website for you.

Copy this code and save it as a bookmark.
```javascript
javascript: (function () { Game.LoadMod('https://angelolz.dev/mods/ccrpc/main.js'); }());
javascript: (function () { Game.LoadMod('https://angelolz.dev/mods/ccrpc/main.js'); }());
```

If everything was installed correctly, you should see the below output and your rich presence on Discord!
Expand Down
4 changes: 2 additions & 2 deletions l4jconfig.xml
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@
<launch4jConfig>
<dontWrapJar>false</dontWrapJar>
<headerType>console</headerType>
<jar>F:\Desktop\CodeProjects\java\personal\CookieClickerRPC\target\CookieClickerRPC-1.1.jar</jar>
<outfile>F:\Desktop\CookieClickerRPC-Windows-1.1.exe</outfile>
<jar>F:\Desktop\CodeProjects\java\personal\CookieClickerRPC\target\CookieClickerRPC-1.2.jar</jar>
<outfile>F:\Desktop\CookieClickerRPC-Windows-1.2.exe</outfile>
<errTitle>Cookie Clicker Rich Presence Mod</errTitle>
<cmdLine></cmdLine>
<chdir>.</chdir>
Expand Down
3 changes: 1 addition & 2 deletions mod/browser/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ if(typeof CCSE == 'undefined') Game.LoadMod('https://klattmose.github.io/CookieC
DRP.name = "Rich Presence";
DRP.id = "drpbrowser";
DRP.author = "Angelolz";
DRP.version = "v1.1";
DRP.version = "v1.2";
DRP.gameVersion = "2.031";

DRP.launch = function()
Expand Down Expand Up @@ -99,7 +99,6 @@ DRP.launch = function()
DRP.wsCon = true;
Game.registerHook('check', sendData);
Game.Notify("Started Rich Presence Server!", `${DRP.version}`, [5,5], 6, false);
Game.Notify("New Update!", "Your Rich Presence client may be outdated! Click <a href='https://github.com/angelolz1/CookieClickerRPC/releases' target='_blank'>here</a> to update it!", [1,7]);
}

DRP.ws.onclose = function (event) {if(DRP.wsCon) { lostConnection(); }}
Expand Down
13 changes: 9 additions & 4 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

<groupId>com.angelolz</groupId>
<artifactId>CookieClickerRPC</artifactId>
<version>1.1</version>
<version>1.2</version>

<properties>
<maven.compiler.source>11</maven.compiler.source>
Expand All @@ -18,14 +18,19 @@
<id>jitpack.io</id>
<url>https://jitpack.io</url>
</repository>
<repository>
<id>jcenter</id>
<url>https://jcenter.bintray.com</url>
<name>jcenter-bintray</name>
</repository>
</repositories>

<dependencies>
<!-- for the discord rich presence -->
<dependency>
<groupId>com.github.Vatuu</groupId>
<artifactId>discord-rpc</artifactId>
<version>1.6.2</version>
<groupId>club.minnced</groupId>
<artifactId>java-discord-rpc</artifactId>
<version>2.0.2</version>
</dependency>

<!-- websocket -->
Expand Down
61 changes: 39 additions & 22 deletions src/main/java/Main.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,33 +4,35 @@
import java.util.concurrent.Executors;
import java.util.concurrent.TimeUnit;

import net.arikia.dev.drpc.DiscordEventHandlers;
import net.arikia.dev.drpc.DiscordRPC;
import net.arikia.dev.drpc.DiscordRichPresence;
import club.minnced.discord.rpc.DiscordEventHandlers;
import club.minnced.discord.rpc.DiscordRPC;
import club.minnced.discord.rpc.DiscordRichPresence;
import org.java_websocket.server.WebSocketServer;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

public class Main
{
private static DiscordRPC lib;
private static Logger logger;
private static long startTime;
private final static String version = "v1.1";
private final static String version = "v1.2";
public static boolean warned = false;

public static void main(String[] args)
{
logger = LoggerFactory.getLogger(Main.class);
logger.info("Cookie Clicker - Discord Rich Presence {}", version);

DiscordEventHandlers handlers = new DiscordEventHandlers.Builder()
.setReadyEventHandler((user) -> {
lib = DiscordRPC.INSTANCE;
DiscordEventHandlers handlers = new DiscordEventHandlers();
handlers.ready = (user) -> {
logger.info("Welcome, {}#{}! Started Discord Rich Presence instance.", user.username, user.discriminator);
logger.info("Your Rich Presence will show once the Cookie Clicker mod is loaded.");
})
.build();
DiscordRPC.discordInitialize("895895624891895828", handlers, true);
Executors.newSingleThreadScheduledExecutor().scheduleAtFixedRate(DiscordRPC::discordRunCallbacks, 0, 1, TimeUnit.SECONDS);
};
lib.Discord_Initialize("895895624891895828", handlers, true, "");

Executors.newSingleThreadScheduledExecutor().scheduleAtFixedRate(() -> lib.Discord_RunCallbacks(), 0, 1, TimeUnit.SECONDS);

startTime = System.currentTimeMillis();

Expand Down Expand Up @@ -58,39 +60,54 @@ public static void main(String[] args)

public static void updateRichPresence(CookieData c)
{
DiscordRichPresence.Builder rp = new DiscordRichPresence
.Builder(c.cps + " per second")
.setDetails(c.cookies + " cookies")
.setBigImage("icon", "Rich Presence by Angelolz");
DiscordRichPresence presence = new DiscordRichPresence();
presence.state = c.cps + " per second";
presence.details = c.cookies + " cookies";

presence.largeImageKey = "icon";
presence.largeImageText = "Rich Presence by Angelolz";

if(c.config.show_elapsed_time == 1) rp.setStartTimestamps(startTime);
if(c.config.show_elapsed_time == 1) presence.startTimestamp = startTime;

switch(c.config.small_icon_mode)
{
case 0:
rp.setSmallImage("legacy", String.format("Prestige Lv. %s with %s ascends", c.prestige_lvl, c.resets));
presence.smallImageKey = "legacy";
presence.smallImageText = String.format("Prestige Lv. %s with %s ascends", c.prestige_lvl, c.resets);
break;
case 1:
if(c.lumps.equals("-1"))
rp.setSmallImage("normal", "Not growing any sugar lumps");
{
presence.smallImageKey = "normal";
presence.smallImageText = "Not growing any sugar lumps";
}

else
rp.setSmallImage(c.lump_status, String.format("%s sugar lumps | Growing a %s lump", c.lumps, c.lump_status));
{
presence.smallImageKey = c.lump_status;
presence.smallImageText = String.format("%s sugar lumps | Growing a %s lump", c.lumps, c.lump_status);
}
break;
case 2:
rp.setSmallImage("cursor", String.format("%s clicks | %s cookies per click", c.clicks, c.cookies_per_click));
presence.smallImageKey = "cursor";
presence.smallImageText = String.format("%s clicks | %s cookies per click", c.clicks, c.cookies_per_click);
break;
case 3:
rp.setSmallImage("goldencookie", String.format("%s GCs clicked | %s GCs missed", c.gc_clicks, c.gc_missed));
presence.smallImageKey = "goldencookie";
presence.smallImageText = String.format("%s GCs clicked | %s GCs missed", c.gc_clicks, c.gc_missed);
break;
case 4:
if(!c.season.isEmpty())
rp.setSmallImage(c.season, String.format("%s | %s", c.season_name, c.drops));
{
presence.smallImageKey = c.season;
presence.smallImageText = String.format("%s | %s", c.season_name, c.drops);
}
break;
case 5:
break;
}

DiscordRPC.discordUpdatePresence(rp.build());
lib.Discord_UpdatePresence(presence);
}

public static void setStartTime(long startTime) { Main.startTime = startTime; }
Expand Down
4 changes: 2 additions & 2 deletions src/main/java/Server.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import club.minnced.discord.rpc.DiscordRPC;
import com.google.gson.Gson;
import net.arikia.dev.drpc.DiscordRPC;
import org.java_websocket.WebSocket;
import org.java_websocket.handshake.ClientHandshake;
import org.java_websocket.server.WebSocketServer;
Expand All @@ -26,7 +26,7 @@ public void onOpen(WebSocket conn, ClientHandshake handshake)
public void onClose(WebSocket conn, int code, String reason, boolean remote)
{
Main.getLogger().info("Closed connection with Cookie Clicker and stopped Rich Presence status.");
DiscordRPC.discordClearPresence();
DiscordRPC.INSTANCE.Discord_ClearPresence();
Main.setStartTime(System.currentTimeMillis());
}

Expand Down

0 comments on commit 4c8d71c

Please sign in to comment.