From dfb467f6336646e9f53e0582061b19bf51bb8fbb Mon Sep 17 00:00:00 2001 From: Devin Date: Tue, 7 Nov 2017 17:29:22 -0800 Subject: [PATCH] Combine CombatNotifier and IdleNotifier plugins --- .../combatnotifier/CombatNotifier.java | 95 ------------------- .../plugins/idlenotifier/IdleNotifier.java | 36 ++++++- .../IdleNotifierConfig.java} | 25 +++-- 3 files changed, 44 insertions(+), 112 deletions(-) delete mode 100644 runelite-client/src/main/java/net/runelite/client/plugins/combatnotifier/CombatNotifier.java rename runelite-client/src/main/java/net/runelite/client/plugins/{combatnotifier/CombatNotifierConfig.java => idlenotifier/IdleNotifierConfig.java} (70%) diff --git a/runelite-client/src/main/java/net/runelite/client/plugins/combatnotifier/CombatNotifier.java b/runelite-client/src/main/java/net/runelite/client/plugins/combatnotifier/CombatNotifier.java deleted file mode 100644 index f7e6bcb866..0000000000 --- a/runelite-client/src/main/java/net/runelite/client/plugins/combatnotifier/CombatNotifier.java +++ /dev/null @@ -1,95 +0,0 @@ -/* - * Copyright (c) 2017, Kronos - * 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.combatnotifier; - -import com.google.common.eventbus.Subscribe; -import java.time.Duration; -import java.time.Instant; -import java.time.temporal.ChronoUnit; -import net.runelite.api.Actor; -import net.runelite.api.Client; -import net.runelite.api.GameState; -import net.runelite.api.Player; -import net.runelite.client.RuneLite; -import net.runelite.client.events.GameStateChanged; -import net.runelite.client.plugins.Plugin; -import net.runelite.client.plugins.PluginDescriptor; -import net.runelite.client.task.Schedule; - -@PluginDescriptor( - name = "Combat notifier" -) -public class CombatNotifier extends Plugin -{ - private final Client client = RuneLite.getClient(); - private final RuneLite runelite = RuneLite.getRunelite(); - private final CombatNotifierConfig config = runelite.getConfigManager() - .getConfig(CombatNotifierConfig.class); - - private Instant lastInteracting; - - @Override - protected void startUp() throws Exception - { - } - - @Override - protected void shutDown() throws Exception - { - } - - @Subscribe - public void onGameStateChanged(GameStateChanged gameStateChanged) - { - lastInteracting = null; - } - - @Schedule( - period = 1, - unit = ChronoUnit.SECONDS - ) - public void checkIdle() - { - if (client.getGameState() != GameState.LOGGED_IN || !config.isEnabled()) - { - return; - } - - Player local = client.getLocalPlayer(); - Actor opponent = local.getInteracting(); - if (opponent != null && opponent.getCombatLevel() > 0) - { - lastInteracting = Instant.now(); - } - - Duration waitDuration = Duration.ofMillis(config.getTimeout()); - if (lastInteracting != null && Instant.now().compareTo(lastInteracting.plus(waitDuration)) >= 0) - { - runelite.notify("[" + local.getName() + "] is now out of combat!"); - lastInteracting = null; - } - } - -} diff --git a/runelite-client/src/main/java/net/runelite/client/plugins/idlenotifier/IdleNotifier.java b/runelite-client/src/main/java/net/runelite/client/plugins/idlenotifier/IdleNotifier.java index 54b6c6f393..745da7255b 100644 --- a/runelite-client/src/main/java/net/runelite/client/plugins/idlenotifier/IdleNotifier.java +++ b/runelite-client/src/main/java/net/runelite/client/plugins/idlenotifier/IdleNotifier.java @@ -1,5 +1,6 @@ /* * Copyright (c) 2016-2017, Abel Briggs + * Copyright (c) 2017, Kronos * All rights reserved. * * Redistribution and use in source and binary forms, with or without @@ -29,11 +30,14 @@ import java.time.Duration; import java.time.Instant; import java.time.temporal.ChronoUnit; import static net.runelite.api.AnimationID.*; + +import net.runelite.api.Actor; import net.runelite.api.Client; import net.runelite.api.GameState; import net.runelite.api.Player; import net.runelite.client.RuneLite; import net.runelite.client.events.AnimationChanged; +import net.runelite.client.events.GameStateChanged; import net.runelite.client.plugins.Plugin; import net.runelite.client.plugins.PluginDescriptor; import net.runelite.client.task.Schedule; @@ -43,12 +47,12 @@ import net.runelite.client.task.Schedule; ) public class IdleNotifier extends Plugin { - private static final Duration WAIT_DURATION = Duration.ofMillis(2500L); - private final Client client = RuneLite.getClient(); private final RuneLite runelite = RuneLite.getRunelite(); + private final IdleNotifierConfig config = runelite.getConfigManager().getConfig(IdleNotifierConfig.class); private Instant lastAnimating; + private Instant lastInteracting; private boolean notifyIdle = false; @Override @@ -64,7 +68,7 @@ public class IdleNotifier extends Plugin @Subscribe public void onAnimationChanged(AnimationChanged event) { - if (client.getGameState() != GameState.LOGGED_IN) + if (!config.isEnabled() || client.getGameState() != GameState.LOGGED_IN) { return; } @@ -144,19 +148,43 @@ public class IdleNotifier extends Plugin } } + @Subscribe + public void onGameStateChanged(GameStateChanged gameStateChanged) + { + lastInteracting = null; + } + @Schedule( period = 2, unit = ChronoUnit.SECONDS ) public void checkIdle() { + if (!config.isEnabled() || client.getGameState() != GameState.LOGGED_IN) + { + return; + } + + Duration waitDuration = Duration.ofMillis(config.getTimeout()); Player local = client.getLocalPlayer(); if (notifyIdle && local.getAnimation() == IDLE - && Instant.now().compareTo(lastAnimating.plus(WAIT_DURATION)) >= 0) + && Instant.now().compareTo(lastAnimating.plus(waitDuration)) >= 0) { runelite.notify("[" + local.getName() + "] is now idle!"); notifyIdle = false; } + + Actor opponent = local.getInteracting(); + if (opponent != null && opponent.getCombatLevel() > 0) + { + lastInteracting = Instant.now(); + } + + if (lastInteracting != null && Instant.now().compareTo(lastInteracting.plus(waitDuration)) >= 0) + { + runelite.notify("[" + local.getName() + "] is now out of combat!"); + lastInteracting = null; + } } } diff --git a/runelite-client/src/main/java/net/runelite/client/plugins/combatnotifier/CombatNotifierConfig.java b/runelite-client/src/main/java/net/runelite/client/plugins/idlenotifier/IdleNotifierConfig.java similarity index 70% rename from runelite-client/src/main/java/net/runelite/client/plugins/combatnotifier/CombatNotifierConfig.java rename to runelite-client/src/main/java/net/runelite/client/plugins/idlenotifier/IdleNotifierConfig.java index 1c9d14429e..167d9a2b4a 100644 --- a/runelite-client/src/main/java/net/runelite/client/plugins/combatnotifier/CombatNotifierConfig.java +++ b/runelite-client/src/main/java/net/runelite/client/plugins/idlenotifier/IdleNotifierConfig.java @@ -1,15 +1,15 @@ /* - * Copyright (c) 2017, Kronos + * Copyright (c) 2017, Devin French * 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. + * 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 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 @@ -22,23 +22,22 @@ * (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.combatnotifier; +package net.runelite.client.plugins.idlenotifier; import net.runelite.client.config.ConfigGroup; import net.runelite.client.config.ConfigItem; @ConfigGroup( - keyName = "combatnotifier", - name = "Combat Notifier", - description = "Notifies when the player is out of combat" + keyName = "idlenotifier", + name = "Idle Notifier", + description = "Configuration for the idle notifier plugin" ) -public interface CombatNotifierConfig +public interface IdleNotifierConfig { @ConfigItem( keyName = "enabled", name = "Enabled", - description = "Toggles out of combat notifications" + description = "Toggles idle notifications" ) default boolean isEnabled() { @@ -48,10 +47,10 @@ public interface CombatNotifierConfig @ConfigItem( keyName = "timeout", name = "Idle Timeout (ms)", - description = "The notification delay after the player is out of combat" + description = "The notification delay after the player is idle" ) default int getTimeout() { - return 10000; + return 5000; } }