From e811375eaafe98a1234cf946a81ffec93433ee00 Mon Sep 17 00:00:00 2001 From: zeruth Date: Fri, 10 May 2019 04:40:09 -0400 Subject: [PATCH] Update Presence Adds RuneLitePlusPlugin -adds option for RL+ presence (disabled by default) -Redirects a lot of older RL links to our updated ones. Prepare for next development iteration 0.1.2 --- .../java/net/runelite/client/RuneLite.java | 7 +- .../runelite/client/RuneLiteProperties.java | 8 +- .../client/discord/DiscordService.java | 4 +- .../client/plugins/config/ConfigPanel.java | 1 + .../client/plugins/config/PluginListItem.java | 40 +++--- .../client/plugins/discord/DiscordPlugin.java | 4 + .../runeliteplus/RuneLitePlusConfig.java | 46 +++++++ .../runeliteplus/RuneLitePlusPlugin.java | 130 ++++++++++++++++++ .../java/net/runelite/client/ui/ClientUI.java | 9 +- .../net/runelite/client/runelite.properties | 8 +- 10 files changed, 222 insertions(+), 35 deletions(-) create mode 100644 runelite-client/src/main/java/net/runelite/client/plugins/runeliteplus/RuneLitePlusConfig.java create mode 100644 runelite-client/src/main/java/net/runelite/client/plugins/runeliteplus/RuneLitePlusPlugin.java diff --git a/runelite-client/src/main/java/net/runelite/client/RuneLite.java b/runelite-client/src/main/java/net/runelite/client/RuneLite.java index e21a3796d3..c9c575bd36 100644 --- a/runelite-client/src/main/java/net/runelite/client/RuneLite.java +++ b/runelite-client/src/main/java/net/runelite/client/RuneLite.java @@ -81,7 +81,7 @@ import org.slf4j.LoggerFactory; @Slf4j public class RuneLite { - public static final String RUNELIT_VERSION = "0.1.1"; + public static final String RUNELIT_VERSION = "0.1.2"; public static final File RUNELITE_DIR = new File(System.getProperty("user.home"), ".runelite"); public static final File PROFILES_DIR = new File(RUNELITE_DIR, "profiles"); public static final File PLUGIN_DIR = new File(RUNELITE_DIR, "plugins"); @@ -108,7 +108,7 @@ public class RuneLite private SessionManager sessionManager; @Inject - private DiscordService discordService; + public DiscordService discordService; @Inject private ClientSessionManager clientSessionManager; @@ -309,9 +309,6 @@ public class RuneLite // Close the splash screen splashScreen.close(); - // Initialize Discord service - discordService.init(); - // Register event listeners eventBus.register(clientUI); eventBus.register(pluginManager); diff --git a/runelite-client/src/main/java/net/runelite/client/RuneLiteProperties.java b/runelite-client/src/main/java/net/runelite/client/RuneLiteProperties.java index c58c588436..e86e436c54 100644 --- a/runelite-client/src/main/java/net/runelite/client/RuneLiteProperties.java +++ b/runelite-client/src/main/java/net/runelite/client/RuneLiteProperties.java @@ -31,11 +31,13 @@ import javax.annotation.Nullable; import javax.inject.Inject; import javax.inject.Singleton; import lombok.extern.slf4j.Slf4j; +import net.runelite.client.plugins.runeliteplus.RuneLitePlusPlugin; @Singleton @Slf4j public class RuneLiteProperties { + public static String discordAppID = "409416265891971072"; private static final String RUNELITE_TITLE = "runelite.title"; private static final String RUNELITE_VERSION = "runelite.version"; private static final String RUNESCAPE_VERSION = "runescape.version"; @@ -78,7 +80,11 @@ public class RuneLiteProperties public String getDiscordAppId() { - return properties.getProperty(DISCORD_APP_ID); + if (RuneLitePlusPlugin.customPresenceEnabled) { + return properties.getProperty(RuneLitePlusPlugin.rlPlusDiscordApp); + } else { + return properties.getProperty(DISCORD_APP_ID); + } } public String getDiscordInvite() diff --git a/runelite-client/src/main/java/net/runelite/client/discord/DiscordService.java b/runelite-client/src/main/java/net/runelite/client/discord/DiscordService.java index 091c479ac6..c125ca0feb 100644 --- a/runelite-client/src/main/java/net/runelite/client/discord/DiscordService.java +++ b/runelite-client/src/main/java/net/runelite/client/discord/DiscordService.java @@ -49,7 +49,7 @@ import net.runelite.discord.DiscordUser; public class DiscordService implements AutoCloseable { private final EventBus eventBus; - private final RuneLiteProperties runeLiteProperties; + public final RuneLiteProperties runeLiteProperties; private final ScheduledExecutorService executorService; private final DiscordRPC discordRPC; @@ -106,7 +106,7 @@ public class DiscordService implements AutoCloseable discordEventHandlers.joinGame = this::joinGame; discordEventHandlers.spectateGame = this::spectateGame; discordEventHandlers.joinRequest = this::joinRequest; - discordRPC.Discord_Initialize(runeLiteProperties.getDiscordAppId(), discordEventHandlers, true, null); + discordRPC.Discord_Initialize(runeLiteProperties.discordAppID, discordEventHandlers, true, null); executorService.scheduleAtFixedRate(discordRPC::Discord_RunCallbacks, 0, 2, TimeUnit.SECONDS); } diff --git a/runelite-client/src/main/java/net/runelite/client/plugins/config/ConfigPanel.java b/runelite-client/src/main/java/net/runelite/client/plugins/config/ConfigPanel.java index 63ba33a2d8..05c3590f79 100644 --- a/runelite-client/src/main/java/net/runelite/client/plugins/config/ConfigPanel.java +++ b/runelite-client/src/main/java/net/runelite/client/plugins/config/ConfigPanel.java @@ -412,6 +412,7 @@ public class ConfigPanel extends PluginPanel topPanelBackButton.setToolTipText("Back"); topPanel.add(topPanelBackButton, BorderLayout.WEST); + if (!listItem.getName().equals("RuneLitePlus")) topPanel.add(listItem.createToggleButton(), BorderLayout.EAST); String name = listItem.getName(); diff --git a/runelite-client/src/main/java/net/runelite/client/plugins/config/PluginListItem.java b/runelite-client/src/main/java/net/runelite/client/plugins/config/PluginListItem.java index 6f52c04660..6daab8d582 100644 --- a/runelite-client/src/main/java/net/runelite/client/plugins/config/PluginListItem.java +++ b/runelite-client/src/main/java/net/runelite/client/plugins/config/PluginListItem.java @@ -178,30 +178,32 @@ public class PluginListItem extends JPanel configPanel.openConfigList(); }); - final JPanel buttonPanel = new JPanel(); - buttonPanel.setLayout(new GridLayout(1, 2)); - add(buttonPanel, BorderLayout.LINE_END); - configButton.setPreferredSize(new Dimension(25, 0)); - configButton.setVisible(false); - buttonPanel.add(configButton); + final JPanel buttonPanel = new JPanel(); + buttonPanel.setLayout(new GridLayout(1, 2)); + add(buttonPanel, BorderLayout.LINE_END); - // add a listener to configButton only if there are config items to show - if (config != null && !configDescriptor.getItems().stream().allMatch(item -> item.getItem().hidden())) - { - configButton.addActionListener(e -> + configButton.setPreferredSize(new Dimension(25, 0)); + configButton.setVisible(false); + buttonPanel.add(configButton); + + // add a listener to configButton only if there are config items to show + if (config != null && !configDescriptor.getItems().stream().allMatch(item -> item.getItem().hidden())) { - configButton.setIcon(CONFIG_ICON); - configPanel.openGroupConfigPanel(PluginListItem.this, config, configDescriptor); - }); + configButton.addActionListener(e -> + { + configButton.setIcon(CONFIG_ICON); + configPanel.openGroupConfigPanel(PluginListItem.this, config, configDescriptor); + }); - configButton.setVisible(true); - configButton.setToolTipText("Edit plugin configuration"); + configButton.setVisible(true); + configButton.setToolTipText("Edit plugin configuration"); + } + if (!name.equals("RuneLitePlus")) { + toggleButton.setPreferredSize(new Dimension(25, 0)); + attachToggleButtonListener(toggleButton); + buttonPanel.add(toggleButton); } - - toggleButton.setPreferredSize(new Dimension(25, 0)); - attachToggleButtonListener(toggleButton); - buttonPanel.add(toggleButton); } private void attachToggleButtonListener(IconButton button) diff --git a/runelite-client/src/main/java/net/runelite/client/plugins/discord/DiscordPlugin.java b/runelite-client/src/main/java/net/runelite/client/plugins/discord/DiscordPlugin.java index 443dd8ac12..b14bd00dce 100644 --- a/runelite-client/src/main/java/net/runelite/client/plugins/discord/DiscordPlugin.java +++ b/runelite-client/src/main/java/net/runelite/client/plugins/discord/DiscordPlugin.java @@ -82,6 +82,8 @@ import okhttp3.Response; @Slf4j public class DiscordPlugin extends Plugin { + public static boolean discordEnabled = false; + @Inject private Client client; @@ -138,6 +140,7 @@ public class DiscordPlugin extends Plugin } wsClient.registerMessage(DiscordUserInfo.class); + discordEnabled = true; } @Override @@ -147,6 +150,7 @@ public class DiscordPlugin extends Plugin discordState.reset(); partyService.changeParty(null); wsClient.unregisterMessage(DiscordUserInfo.class); + discordEnabled = false; } @Subscribe diff --git a/runelite-client/src/main/java/net/runelite/client/plugins/runeliteplus/RuneLitePlusConfig.java b/runelite-client/src/main/java/net/runelite/client/plugins/runeliteplus/RuneLitePlusConfig.java new file mode 100644 index 0000000000..ee93e4abb7 --- /dev/null +++ b/runelite-client/src/main/java/net/runelite/client/plugins/runeliteplus/RuneLitePlusConfig.java @@ -0,0 +1,46 @@ +/* + * + * Copyright (c) 2019, Zeruth + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * + * 1. Redistributions of source code must retain the above copyright notice, this + * list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright notice, + * this list of conditions and the following disclaimer in the documentation + * and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED + * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE + * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR + * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES + * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; + * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND + * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS + * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * + */ +package net.runelite.client.plugins.runeliteplus; + +import net.runelite.client.config.Config; +import net.runelite.client.config.ConfigGroup; +import net.runelite.client.config.ConfigItem; + +import java.awt.*; + +@ConfigGroup("runeliteplus") +public interface RuneLitePlusConfig extends Config +{ + @ConfigItem( + position = 0, + keyName = "customPresence", + name = "RL+ Presence", + description = "Represent RL+ with a custom icon and discord presence." + ) + default boolean customPresence() { return false; } + +} diff --git a/runelite-client/src/main/java/net/runelite/client/plugins/runeliteplus/RuneLitePlusPlugin.java b/runelite-client/src/main/java/net/runelite/client/plugins/runeliteplus/RuneLitePlusPlugin.java new file mode 100644 index 0000000000..9a69468a17 --- /dev/null +++ b/runelite-client/src/main/java/net/runelite/client/plugins/runeliteplus/RuneLitePlusPlugin.java @@ -0,0 +1,130 @@ +/* + * + * Copyright (c) 2019, Zeruth + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * + * 1. Redistributions of source code must retain the above copyright notice, this + * list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright notice, + * this list of conditions and the following disclaimer in the documentation + * and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED + * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE + * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR + * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES + * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; + * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND + * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS + * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * + */ +package net.runelite.client.plugins.runeliteplus; + + +import com.google.inject.Provides; +import lombok.extern.slf4j.Slf4j; +import net.runelite.api.Client; +import net.runelite.api.events.ConfigChanged; +import net.runelite.client.RuneLite; +import net.runelite.client.RuneLiteProperties; +import net.runelite.client.config.ConfigManager; +import net.runelite.client.discord.DiscordPresence; +import net.runelite.client.discord.DiscordService; +import net.runelite.client.eventbus.Subscribe; +import net.runelite.client.plugins.Plugin; +import net.runelite.client.plugins.PluginDescriptor; +import net.runelite.client.plugins.PluginType; +import net.runelite.client.plugins.discord.DiscordPlugin; +import net.runelite.client.ui.ClientUI; +import net.runelite.client.ui.overlay.OverlayManager; + +import javax.inject.Inject; + +@PluginDescriptor( + + loadWhenOutdated = true, // prevent users from disabling + hidden = true, // prevent users from disabling + name = "RuneLitePlus", + description = "Configures various aspects of RuneLitePlus", + type = PluginType.EXTERNAL +) + +@Slf4j +public class RuneLitePlusPlugin extends Plugin +{ + public static boolean customPresenceEnabled = false; + public static String rlPlusDiscordApp = "560644885250572289"; + public static String rlDiscordApp = "409416265891971072"; + @Inject + public RuneLitePlusConfig config; + @Inject + private OverlayManager overlayManager; + @Inject + private ConfigManager configManager; + @Inject + public DiscordService discordService; + + @Inject + private Client client; + + @Provides + RuneLitePlusConfig getConfig(ConfigManager configManager) + { + return configManager.getConfig(RuneLitePlusConfig.class); + } + + @Override + protected void startUp() throws Exception + { + if (getConfig(configManager).customPresence()) { + ClientUI.currentPresenceName = ("RuneLitePlus"); + ClientUI.frame.setTitle(ClientUI.currentPresenceName); + } + + if (config.customPresence()) { + RuneLiteProperties.discordAppID = rlPlusDiscordApp; + discordService.close(); + discordService.init(); + } else { + RuneLiteProperties.discordAppID = rlDiscordApp; + discordService.close(); + discordService.init(); + } + } + + @Subscribe + protected void onConfigChanged(ConfigChanged event) { + if (event.getKey().equals("customPresence")) { + if (config.customPresence()) { + ClientUI.currentPresenceName = ("RuneLitePlus"); + ClientUI.frame.setTitle(ClientUI.currentPresenceName); + } else { + ClientUI.currentPresenceName = ("RuneLite"); + ClientUI.frame.setTitle(ClientUI.currentPresenceName); + } + + if (config.customPresence()) { + RuneLiteProperties.discordAppID = rlPlusDiscordApp; + discordService.close(); + discordService.init(); + } else { + RuneLiteProperties.discordAppID = rlDiscordApp; + discordService.close(); + discordService.init(); + } + } + } + + @Override + protected void shutDown() throws Exception + { + + } + +} diff --git a/runelite-client/src/main/java/net/runelite/client/ui/ClientUI.java b/runelite-client/src/main/java/net/runelite/client/ui/ClientUI.java index 66653e63cb..ad3686ce81 100644 --- a/runelite-client/src/main/java/net/runelite/client/ui/ClientUI.java +++ b/runelite-client/src/main/java/net/runelite/client/ui/ClientUI.java @@ -106,6 +106,7 @@ public class ClientUI private static final int CLIENT_WELL_HIDDEN_MARGIN = 160; private static final int CLIENT_WELL_HIDDEN_MARGIN_TOP = 10; public static boolean allowInput = false; + public static String currentPresenceName = "RuneLite"; public static final BufferedImage ICON = ImageUtil.getResourceStreamFromClass(ClientUI.class, "/runelite.png"); @Getter @@ -286,7 +287,7 @@ public class ClientUI return false; } - frame.setTitle(properties.getTitle() + " - " + name); + frame.setTitle(currentPresenceName + " - " + name); return true; }); } @@ -309,7 +310,7 @@ public class ClientUI // Try to enable fullscreen on OSX OSXUtil.tryEnableFullscreen(frame); - frame.setTitle(properties.getTitle()); + frame.setTitle(ClientUI.currentPresenceName); frame.setIconImage(ICON); frame.getLayeredPane().setCursor(Cursor.getDefaultCursor()); // Prevent substance from using a resize cursor for pointing frame.setLocationRelativeTo(frame.getOwner()); @@ -832,12 +833,12 @@ public class ClientUI if (player != null && player.getName() != null) { - frame.setTitle(properties.getTitle() + " - " + player.getName()); + frame.setTitle(currentPresenceName + " - " + player.getName()); } } else { - frame.setTitle(properties.getTitle()); + frame.setTitle(currentPresenceName); } if (frame.isAlwaysOnTopSupported()) diff --git a/runelite-client/src/main/resources/net/runelite/client/runelite.properties b/runelite-client/src/main/resources/net/runelite/client/runelite.properties index afeed8517f..1867b78407 100644 --- a/runelite-client/src/main/resources/net/runelite/client/runelite.properties +++ b/runelite-client/src/main/resources/net/runelite/client/runelite.properties @@ -2,7 +2,7 @@ runelite.title=RuneLite runelite.version=${project.version} runescape.version=${rs.version} runelite.discord.appid=409416265891971072 -runelite.discord.invite=https://discord.gg/R4BQ8tU -runelite.github.link=https://github.com/runelite -runelite.wiki.link=https://github.com/runelite/runelite/wiki -runelite.patreon.link=https://www.patreon.com/runelite \ No newline at end of file +runelite.discord.invite=https://discord.gg/HN5gf3m +runelite.github.link=https://github.com/runelite-extended/runelite +runelite.wiki.link=https://github.com/runelite-extended/runelite/wiki +runelite.patreon.link=https://www.patreon.com/RuneLitePlus \ No newline at end of file