Merge pull request #202 from devinfrench/idlenotifier
Update IdleNotifier plugin
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,57 +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 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"
|
|
||||||
)
|
|
||||||
public interface CombatNotifierConfig
|
|
||||||
{
|
|
||||||
@ConfigItem(
|
|
||||||
keyName = "enabled",
|
|
||||||
name = "Enabled",
|
|
||||||
description = "Toggles out of combat notifications"
|
|
||||||
)
|
|
||||||
default boolean isEnabled()
|
|
||||||
{
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
@ConfigItem(
|
|
||||||
keyName = "timeout",
|
|
||||||
name = "Idle Timeout (ms)",
|
|
||||||
description = "The notification delay after the player is out of combat"
|
|
||||||
)
|
|
||||||
default int getTimeout()
|
|
||||||
{
|
|
||||||
return 10000;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,5 +1,6 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright (c) 2016-2017, Abel Briggs
|
* Copyright (c) 2016-2017, Abel Briggs
|
||||||
|
* Copyright (c) 2017, Kronos <https://github.com/KronosDesign>
|
||||||
* All rights reserved.
|
* All rights reserved.
|
||||||
*
|
*
|
||||||
* Redistribution and use in source and binary forms, with or without
|
* Redistribution and use in source and binary forms, with or without
|
||||||
@@ -29,27 +30,37 @@ import java.time.Duration;
|
|||||||
import java.time.Instant;
|
import java.time.Instant;
|
||||||
import java.time.temporal.ChronoUnit;
|
import java.time.temporal.ChronoUnit;
|
||||||
import static net.runelite.api.AnimationID.*;
|
import static net.runelite.api.AnimationID.*;
|
||||||
|
|
||||||
|
import net.runelite.api.Actor;
|
||||||
import net.runelite.api.Client;
|
import net.runelite.api.Client;
|
||||||
import net.runelite.api.GameState;
|
import net.runelite.api.GameState;
|
||||||
import net.runelite.api.Player;
|
import net.runelite.api.Player;
|
||||||
|
import net.runelite.api.Skill;
|
||||||
import net.runelite.client.RuneLite;
|
import net.runelite.client.RuneLite;
|
||||||
import net.runelite.client.events.AnimationChanged;
|
import net.runelite.client.events.AnimationChanged;
|
||||||
|
import net.runelite.client.events.GameStateChanged;
|
||||||
import net.runelite.client.plugins.Plugin;
|
import net.runelite.client.plugins.Plugin;
|
||||||
import net.runelite.client.plugins.PluginDescriptor;
|
import net.runelite.client.plugins.PluginDescriptor;
|
||||||
import net.runelite.client.task.Schedule;
|
import net.runelite.client.task.Schedule;
|
||||||
|
import net.runelite.client.ui.ClientUI;
|
||||||
|
|
||||||
@PluginDescriptor(
|
@PluginDescriptor(
|
||||||
name = "Idle notifier"
|
name = "Idle notifier"
|
||||||
)
|
)
|
||||||
public class IdleNotifier extends Plugin
|
public class IdleNotifier extends Plugin
|
||||||
{
|
{
|
||||||
private static final Duration WAIT_DURATION = Duration.ofMillis(2500L);
|
|
||||||
|
|
||||||
private final Client client = RuneLite.getClient();
|
private final Client client = RuneLite.getClient();
|
||||||
private final RuneLite runelite = RuneLite.getRunelite();
|
private final RuneLite runelite = RuneLite.getRunelite();
|
||||||
|
private final IdleNotifierConfig config = runelite.getConfigManager().getConfig(IdleNotifierConfig.class);
|
||||||
|
private final ClientUI gui = runelite.getGui();
|
||||||
|
|
||||||
private Instant lastAnimating;
|
private Instant lastAnimating;
|
||||||
|
private Instant lastInteracting;
|
||||||
|
private Instant lastHitpoints;
|
||||||
|
private Instant lastPrayer;
|
||||||
private boolean notifyIdle = false;
|
private boolean notifyIdle = false;
|
||||||
|
private boolean notifyHitpoints = true;
|
||||||
|
private boolean notifyPrayer = true;
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void startUp() throws Exception
|
protected void startUp() throws Exception
|
||||||
@@ -64,7 +75,7 @@ public class IdleNotifier extends Plugin
|
|||||||
@Subscribe
|
@Subscribe
|
||||||
public void onAnimationChanged(AnimationChanged event)
|
public void onAnimationChanged(AnimationChanged event)
|
||||||
{
|
{
|
||||||
if (client.getGameState() != GameState.LOGGED_IN)
|
if (!config.isEnabled() || client.getGameState() != GameState.LOGGED_IN)
|
||||||
{
|
{
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@@ -110,6 +121,7 @@ public class IdleNotifier extends Plugin
|
|||||||
/* Smithing(Anvil, Furnace, Cannonballs */
|
/* Smithing(Anvil, Furnace, Cannonballs */
|
||||||
case SMITHING_ANVIL:
|
case SMITHING_ANVIL:
|
||||||
case SMITHING_SMELTING:
|
case SMITHING_SMELTING:
|
||||||
|
case SMITHING_CANNONBALL:
|
||||||
/* Fishing */
|
/* Fishing */
|
||||||
case FISHING_NET:
|
case FISHING_NET:
|
||||||
case FISHING_HARPOON:
|
case FISHING_HARPOON:
|
||||||
@@ -143,19 +155,92 @@ public class IdleNotifier extends Plugin
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Subscribe
|
||||||
|
public void onGameStateChanged(GameStateChanged gameStateChanged)
|
||||||
|
{
|
||||||
|
lastInteracting = null;
|
||||||
|
}
|
||||||
|
|
||||||
@Schedule(
|
@Schedule(
|
||||||
period = 2,
|
period = 1,
|
||||||
unit = ChronoUnit.SECONDS
|
unit = ChronoUnit.SECONDS
|
||||||
)
|
)
|
||||||
public void checkIdle()
|
public void checkIdle()
|
||||||
{
|
{
|
||||||
|
if (!config.isEnabled() || client.getGameState() != GameState.LOGGED_IN)
|
||||||
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
Duration waitDuration = Duration.ofMillis(config.getTimeout());
|
||||||
Player local = client.getLocalPlayer();
|
Player local = client.getLocalPlayer();
|
||||||
if (notifyIdle && local.getAnimation() == IDLE
|
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!");
|
sendNotification("[" + local.getName() + "] is now idle!");
|
||||||
notifyIdle = false;
|
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)
|
||||||
|
{
|
||||||
|
sendNotification("[" + local.getName() + "] is now out of combat!");
|
||||||
|
lastInteracting = null;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (client.getRealSkillLevel(Skill.HITPOINTS) > config.getHitpointsThreshold())
|
||||||
|
{
|
||||||
|
if (client.getBoostedSkillLevel(Skill.HITPOINTS) <= config.getHitpointsThreshold())
|
||||||
|
{
|
||||||
|
if (!notifyHitpoints && Instant.now().compareTo(lastHitpoints.plus(waitDuration)) >= 0)
|
||||||
|
{
|
||||||
|
sendNotification("[" + local.getName() + "] has low hitpoints!");
|
||||||
|
notifyHitpoints = true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
lastHitpoints = Instant.now();
|
||||||
|
notifyHitpoints = false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (client.getRealSkillLevel(Skill.PRAYER) > config.getPrayerThreshold())
|
||||||
|
{
|
||||||
|
if (client.getBoostedSkillLevel(Skill.PRAYER) <= config.getPrayerThreshold())
|
||||||
|
{
|
||||||
|
if (!notifyPrayer && Instant.now().compareTo(lastPrayer.plus(waitDuration)) >= 0)
|
||||||
|
{
|
||||||
|
sendNotification("[" + local.getName() + "] has low prayer!");
|
||||||
|
notifyPrayer = true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
lastPrayer = Instant.now();
|
||||||
|
notifyPrayer = false;
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private void sendNotification(String message)
|
||||||
|
{
|
||||||
|
if (!config.alertWhenFocused() && gui.isFocused())
|
||||||
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
if (config.requestFocus())
|
||||||
|
{
|
||||||
|
gui.requestFocus();
|
||||||
|
}
|
||||||
|
if (config.sendTrayNotification())
|
||||||
|
{
|
||||||
|
runelite.notify(message);
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -0,0 +1,113 @@
|
|||||||
|
/*
|
||||||
|
* 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.
|
||||||
|
* 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.idlenotifier;
|
||||||
|
|
||||||
|
import net.runelite.client.config.ConfigGroup;
|
||||||
|
import net.runelite.client.config.ConfigItem;
|
||||||
|
|
||||||
|
@ConfigGroup(
|
||||||
|
keyName = "idlenotifier",
|
||||||
|
name = "Idle Notifier",
|
||||||
|
description = "Configuration for the idle notifier plugin"
|
||||||
|
)
|
||||||
|
public interface IdleNotifierConfig
|
||||||
|
{
|
||||||
|
@ConfigItem(
|
||||||
|
keyName = "enabled",
|
||||||
|
name = "Enabled",
|
||||||
|
description = "Toggles idle notifications",
|
||||||
|
position = 1
|
||||||
|
)
|
||||||
|
default boolean isEnabled()
|
||||||
|
{
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
@ConfigItem(
|
||||||
|
keyName = "tray",
|
||||||
|
name = "Send Tray Notification",
|
||||||
|
description = "Toggles tray notifications",
|
||||||
|
position = 2
|
||||||
|
)
|
||||||
|
default boolean sendTrayNotification()
|
||||||
|
{
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
@ConfigItem(
|
||||||
|
keyName = "focused",
|
||||||
|
name = "Alert When Focused",
|
||||||
|
description = "Toggles idle notifications for when the client is focused",
|
||||||
|
position = 3
|
||||||
|
)
|
||||||
|
default boolean alertWhenFocused()
|
||||||
|
{
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
@ConfigItem(
|
||||||
|
keyName = "request",
|
||||||
|
name = "Request Window Focus",
|
||||||
|
description = "Toggles window focus request",
|
||||||
|
position = 4
|
||||||
|
)
|
||||||
|
default boolean requestFocus()
|
||||||
|
{
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
@ConfigItem(
|
||||||
|
keyName = "timeout",
|
||||||
|
name = "Idle Timeout (ms)",
|
||||||
|
description = "The notification delay after the player is idle",
|
||||||
|
position = 5
|
||||||
|
)
|
||||||
|
default int getTimeout()
|
||||||
|
{
|
||||||
|
return 5000;
|
||||||
|
}
|
||||||
|
|
||||||
|
@ConfigItem(
|
||||||
|
keyName = "hitpoints",
|
||||||
|
name = "Hitpoints Threshold",
|
||||||
|
description = "The amount of hitpoints to send a notification at",
|
||||||
|
position = 6
|
||||||
|
)
|
||||||
|
default int getHitpointsThreshold()
|
||||||
|
{
|
||||||
|
return 15;
|
||||||
|
}
|
||||||
|
|
||||||
|
@ConfigItem(
|
||||||
|
keyName = "prayer",
|
||||||
|
name = "Prayer Threshold",
|
||||||
|
description = "The amount of prayer points to send a notification at",
|
||||||
|
position = 7
|
||||||
|
)
|
||||||
|
default int getPrayerThreshold()
|
||||||
|
{
|
||||||
|
return 15;
|
||||||
|
}
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user