From af39b4d925b4cec1db65df194973ce0e0c592eb8 Mon Sep 17 00:00:00 2001 From: Adam Date: Sat, 24 Feb 2018 16:29:52 -0500 Subject: [PATCH] hiscore plugin: add config for player option --- .../client/plugins/hiscore/HiscoreConfig.java | 48 +++++++++++++++++++ .../client/plugins/hiscore/HiscorePlugin.java | 31 +++++++++++- 2 files changed, 78 insertions(+), 1 deletion(-) create mode 100644 runelite-client/src/main/java/net/runelite/client/plugins/hiscore/HiscoreConfig.java diff --git a/runelite-client/src/main/java/net/runelite/client/plugins/hiscore/HiscoreConfig.java b/runelite-client/src/main/java/net/runelite/client/plugins/hiscore/HiscoreConfig.java new file mode 100644 index 0000000000..606930be35 --- /dev/null +++ b/runelite-client/src/main/java/net/runelite/client/plugins/hiscore/HiscoreConfig.java @@ -0,0 +1,48 @@ +/* + * Copyright (c) 2018, Adam + * 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.hiscore; + +import net.runelite.client.config.Config; +import net.runelite.client.config.ConfigGroup; +import net.runelite.client.config.ConfigItem; + +@ConfigGroup( + keyName = "hiscore", + name = "Hiscore", + description = "Configuration for the hiscore plugin" +) +public interface HiscoreConfig extends Config +{ + @ConfigItem( + position = 1, + keyName = "playerOption", + name = "Player option", + description = "Add Lookup option to players" + ) + default boolean playerOption() + { + return true; + } +} diff --git a/runelite-client/src/main/java/net/runelite/client/plugins/hiscore/HiscorePlugin.java b/runelite-client/src/main/java/net/runelite/client/plugins/hiscore/HiscorePlugin.java index dad30e9fa9..c41fad6eae 100644 --- a/runelite-client/src/main/java/net/runelite/client/plugins/hiscore/HiscorePlugin.java +++ b/runelite-client/src/main/java/net/runelite/client/plugins/hiscore/HiscorePlugin.java @@ -25,12 +25,15 @@ package net.runelite.client.plugins.hiscore; import com.google.common.eventbus.Subscribe; +import com.google.inject.Provides; import java.lang.reflect.InvocationTargetException; import java.util.concurrent.ScheduledExecutorService; import javax.imageio.ImageIO; import javax.inject.Inject; import javax.swing.SwingUtilities; +import net.runelite.api.events.ConfigChanged; import net.runelite.api.events.PlayerMenuOptionClicked; +import net.runelite.client.config.ConfigManager; import net.runelite.client.menus.MenuManager; import net.runelite.client.plugins.Plugin; import net.runelite.client.plugins.PluginDescriptor; @@ -54,9 +57,18 @@ public class HiscorePlugin extends Plugin @Inject private ScheduledExecutorService executor; + @Inject + private HiscoreConfig config; + private NavigationButton navButton; private HiscorePanel hiscorePanel; + @Provides + HiscoreConfig provideConfig(ConfigManager configManager) + { + return configManager.getConfig(HiscoreConfig.class); + } + @Override protected void startUp() throws Exception { @@ -68,7 +80,10 @@ public class HiscorePlugin extends Plugin ui.getPluginToolbar().addNavigation(navButton); - menuManager.addPlayerMenuItem(LOOKUP); + if (config.playerOption()) + { + menuManager.addPlayerMenuItem(LOOKUP); + } } @Override @@ -79,6 +94,20 @@ public class HiscorePlugin extends Plugin menuManager.removePlayerMenuItem(LOOKUP); } + @Subscribe + public void onConfigChanged(ConfigChanged event) + { + if (event.getGroup().equals("hiscore")) + { + menuManager.removePlayerMenuItem(LOOKUP); + + if (config.playerOption()) + { + menuManager.addPlayerMenuItem(LOOKUP); + } + } + } + @Subscribe public void onLookupMenuClicked(PlayerMenuOptionClicked event) {