Skip to content

Commit

Permalink
Combine CombatNotifier and IdleNotifier plugins
Browse files Browse the repository at this point in the history
  • Loading branch information
devinfrench committed Nov 8, 2017
1 parent 46e7a24 commit dfb467f
Show file tree
Hide file tree
Showing 3 changed files with 44 additions and 112 deletions.

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
/*
* Copyright (c) 2016-2017, Abel Briggs
* Copyright (c) 2017, Kronos <https://github.com/KronosDesign>
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
Expand Down Expand Up @@ -29,11 +30,14 @@
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;
Expand All @@ -43,12 +47,12 @@
)
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
Expand All @@ -64,7 +68,7 @@ protected void shutDown() throws Exception
@Subscribe
public void onAnimationChanged(AnimationChanged event)
{
if (client.getGameState() != GameState.LOGGED_IN)
if (!config.isEnabled() || client.getGameState() != GameState.LOGGED_IN)
{
return;
}
Expand Down Expand Up @@ -144,19 +148,43 @@ public void onAnimationChanged(AnimationChanged event)
}
}

@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;
}
}

}
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
/*
* Copyright (c) 2017, Kronos <https://github.com/KronosDesign>
* Copyright (c) 2017, Devin French <https://github.com/devinfrench>
* 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
Expand All @@ -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()
{
Expand All @@ -48,10 +47,10 @@ default boolean isEnabled()
@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;
}
}

0 comments on commit dfb467f

Please sign in to comment.