Combine CombatNotifier and IdleNotifier plugins
This commit is contained in:
@@ -1,95 +0,0 @@
|
||||
/*
|
||||
* Copyright (c) 2017, Kronos <https://github.com/KronosDesign>
|
||||
* 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;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
@@ -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
|
||||
@@ -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;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -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
|
||||
@@ -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;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user