diff --git a/runelite-client/src/main/java/net/runelite/client/plugins/statusbars/StatusBarsConfig.java b/runelite-client/src/main/java/net/runelite/client/plugins/statusbars/StatusBarsConfig.java index c3a05b05db..e869f0e010 100644 --- a/runelite-client/src/main/java/net/runelite/client/plugins/statusbars/StatusBarsConfig.java +++ b/runelite-client/src/main/java/net/runelite/client/plugins/statusbars/StatusBarsConfig.java @@ -1,63 +1,84 @@ -/* - * Copyright (c) 2018, Jos - * 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.statusbars; - -import net.runelite.client.config.Config; -import net.runelite.client.config.ConfigGroup; -import net.runelite.client.config.ConfigItem; - -@ConfigGroup("statusbars") -public interface StatusBarsConfig extends Config -{ - @ConfigItem( - keyName = "enableCounter", - name = "Show hitpoints & prayer counter", - description = "Shows current amount of hitpoints & prayer on the status bars" - ) - default boolean enableCounter() - { - return false; - } - - @ConfigItem( - keyName = "enableSkillIcon", - name = "Show hitpoints & prayer icons", - description = "Adds skill icons at the top of the bars." - ) - default boolean enableSkillIcon() - { - return true; - } - - @ConfigItem( - keyName = "enableRestorationBars", - name = "Show amount of hitpoints and prayer restored", - description = "Visually shows how much a food or prayer will heal/restore you on the bars." - ) - default boolean enableRestorationBars() - { - return true; - } -} +/* + * Copyright (c) 2018, Jos + * 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.statusbars; + +import net.runelite.client.config.Config; +import net.runelite.client.config.ConfigGroup; +import net.runelite.client.config.ConfigItem; + +@ConfigGroup("statusbars") +public interface StatusBarsConfig extends Config +{ + @ConfigItem( + keyName = "enableCounter", + name = "Show hitpoints & prayer counter", + description = "Shows current amount of hitpoints & prayer on the status bars" + ) + default boolean enableCounter() + { + return false; + } + + @ConfigItem( + keyName = "enableSkillIcon", + name = "Show hitpoints & prayer icons", + description = "Adds skill icons at the top of the bars." + ) + default boolean enableSkillIcon() + { + return true; + } + + @ConfigItem( + keyName = "enableRestorationBars", + name = "Show amount of hitpoints and prayer restored", + description = "Visually shows how much a food or prayer will heal/restore you on the bars." + ) + default boolean enableRestorationBars() + { + return true; + } + + @ConfigItem( + keyName = "hideStatusBarDelay", + name = "Delay (seconds)", + description = "Number of seconds after combat to hide the status bars." + ) + default int hideStatusBarDelay() + { + return 3; + } + + @ConfigItem( + keyName = "toggleRestorationBars", + name = "Toggle to Hide when not in Combat", + description = "Visually hides the Status Bars when player is out of combat." + ) + default boolean toggleRestorationBars() + { + return true; + } + +} diff --git a/runelite-client/src/main/java/net/runelite/client/plugins/statusbars/StatusBarsPlugin.java b/runelite-client/src/main/java/net/runelite/client/plugins/statusbars/StatusBarsPlugin.java index cb36b42d0d..3c163a5b18 100644 --- a/runelite-client/src/main/java/net/runelite/client/plugins/statusbars/StatusBarsPlugin.java +++ b/runelite-client/src/main/java/net/runelite/client/plugins/statusbars/StatusBarsPlugin.java @@ -24,9 +24,21 @@ */ package net.runelite.client.plugins.statusbars; +import java.time.Duration; +import java.time.Instant; +import java.util.Arrays; +import java.util.List; import javax.inject.Inject; import com.google.inject.Provides; +import lombok.AccessLevel; +import lombok.Getter; +import net.runelite.api.Actor; +import net.runelite.api.Client; +import net.runelite.api.NPC; +import net.runelite.api.NPCComposition; +import net.runelite.api.events.GameTick; import net.runelite.client.config.ConfigManager; +import net.runelite.client.eventbus.Subscribe; import net.runelite.client.plugins.Plugin; import net.runelite.client.plugins.PluginDependency; import net.runelite.client.plugins.PluginDescriptor; @@ -47,10 +59,56 @@ public class StatusBarsPlugin extends Plugin @Inject private OverlayManager overlayManager; + @Inject + private Client client; + + @Inject + private StatusBarsConfig config; + + @Getter(AccessLevel.PACKAGE) + private Instant lastCombatAction; + @Override protected void startUp() throws Exception { - overlayManager.add(overlay); + } + + void updateLastCombatAction() + { + this.lastCombatAction = Instant.now(); + } + + @Subscribe + public void onGameTick(GameTick gameTick) + { + final Actor interacting = client.getLocalPlayer().getInteracting(); + final boolean isNpc = interacting instanceof NPC; + final int COMBAT_TIMEOUT = config.hideStatusBarDelay(); + + if (!config.toggleRestorationBars()) + { + overlayManager.add(overlay); + return; + } + + if (isNpc) + { + final NPC npc = (NPC) interacting; + final NPCComposition npcComposition = npc.getComposition(); + final List npcMenuActions = Arrays.asList(npcComposition.getActions()); + if (npcMenuActions.contains("Attack")) + { + updateLastCombatAction(); + overlayManager.add(overlay); + } + } + else if (lastCombatAction != null) + { + if (Duration.between(getLastCombatAction(), Instant.now()).getSeconds() > COMBAT_TIMEOUT) + { + overlayManager.remove(overlay); + } + } } @Override