|
- using System;
- using System.Reflection;
-
- using IllusionPlugin;
- // using GamecraftModdingAPI;
- using GamecraftModdingAPI.Commands;
- using DiscordRPC;
-
- namespace GamecraftRPC
- {
- public class MyPlugin : IPlugin // the Illusion Plugin Architecture (IPA) will ignore classes that don't implement IPlugin'
- {
- public string Name { get; } = Assembly.GetExecutingAssembly().GetName().Name;
-
- public string Version { get; } = Assembly.GetExecutingAssembly().GetName().Version.ToString();
-
- private static readonly string CLIENT_ID = "692733325902872619";
-
- private DiscordRpcClient discordRPC;
-
- // called when Gamecraft shuts down
- public void OnApplicationQuit()
- {
- // Shutdown this mod
- GamecraftModdingAPI.Utility.Logging.LogDebug($"{Name} has shutdown");
-
- // Shutdown the Gamecraft modding API last
- GamecraftModdingAPI.Main.Shutdown();
- }
-
- // called when Gamecraft starts up
- public void OnApplicationStart()
- {
- // Initialize the Gamecraft modding API first
- GamecraftModdingAPI.Main.Init();
-
- // Initialize this mod
- SimpleCustomCommandEngine rpcCommand = new SimpleCustomCommandEngine(
- () => { }, // TODO: command action
- // also try using CommandLogWarning or CommandLogError instead of CommandLog
- "RPC", // command name (used to invoke it in the console)
- "DiscordRPC Experimental command" // command description (displayed when help command is executed)
- ); // this command can also be executed using the Command Computer
-
- // register the command so the modding API knows about it
- CommandManager.AddCommand(rpcCommand);
-
- discordRPC = new DiscordRpcClient(CLIENT_ID);
-
- discordRPC.OnReady += (sender, e) =>
- {
- GamecraftModdingAPI.Utility.Logging.LogDebug($"Received Ready from user {e.User.Username}");
- };
-
- discordRPC.OnPresenceUpdate += (sender, e) =>
- {
- GamecraftModdingAPI.Utility.Logging.LogDebug($"Received Update! {e.Presence}");
- };
-
- discordRPC.Initialize();
-
- discordRPC.SetPresence(new RichPresence()
- {
- Details = "Gamecraft Rich Presence",
- State = "Gamecraft RPC test",
- Assets = new DiscordRPC.Assets()
- {
- LargeImageKey = "image_large",
- LargeImageText = "Testing stuff",
- SmallImageKey = "image_small"
- }
- });
-
- GamecraftModdingAPI.Utility.Logging.LogDebug($"{Name} has started up");
- }
-
- // unused methods
-
- public void OnFixedUpdate() { } // called once per physics update
-
- public void OnLevelWasInitialized(int level) { } // called after a level is initialized
-
- public void OnLevelWasLoaded(int level) { } // called after a level is loaded
-
- public void OnUpdate() // called once per rendered frame (frame update)
- {
- if (discordRPC != null ) discordRPC.Invoke();
- }
- }
- }
|