Merge pull request #412 from deathbeam/fix-anim-idle
Fix idle notifications for animation changes
This commit is contained in:
@@ -94,20 +94,19 @@ import com.google.common.eventbus.Subscribe;
|
|||||||
import com.google.inject.Provides;
|
import com.google.inject.Provides;
|
||||||
import java.time.Duration;
|
import java.time.Duration;
|
||||||
import java.time.Instant;
|
import java.time.Instant;
|
||||||
import java.time.temporal.ChronoUnit;
|
|
||||||
import javax.inject.Inject;
|
import javax.inject.Inject;
|
||||||
import net.runelite.api.Actor;
|
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.api.Skill;
|
||||||
import net.runelite.client.Notifier;
|
|
||||||
import net.runelite.client.config.ConfigManager;
|
|
||||||
import net.runelite.api.events.AnimationChanged;
|
import net.runelite.api.events.AnimationChanged;
|
||||||
import net.runelite.api.events.GameStateChanged;
|
import net.runelite.api.events.GameStateChanged;
|
||||||
|
import net.runelite.api.events.GameTick;
|
||||||
|
import net.runelite.client.Notifier;
|
||||||
|
import net.runelite.client.config.ConfigManager;
|
||||||
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.ui.ClientUI;
|
import net.runelite.client.ui.ClientUI;
|
||||||
|
|
||||||
@PluginDescriptor(
|
@PluginDescriptor(
|
||||||
@@ -242,7 +241,7 @@ public class IdleNotifierPlugin extends Plugin
|
|||||||
/* Magic */
|
/* Magic */
|
||||||
case MAGIC_CHARGING_ORBS:
|
case MAGIC_CHARGING_ORBS:
|
||||||
notifyIdle = true;
|
notifyIdle = true;
|
||||||
lastAnimating = Instant.now();
|
lastAnimating = null;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -271,54 +270,94 @@ public class IdleNotifierPlugin extends Plugin
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Schedule(
|
@Subscribe
|
||||||
period = 1,
|
public void onGameTick(GameTick event)
|
||||||
unit = ChronoUnit.SECONDS
|
|
||||||
)
|
|
||||||
public void checkIdle()
|
|
||||||
{
|
{
|
||||||
Player local = client.getLocalPlayer();
|
final Player local = client.getLocalPlayer();
|
||||||
|
final Duration waitDuration = Duration.ofMillis(config.getTimeout());
|
||||||
|
|
||||||
if (!config.isEnabled() || client.getGameState() != GameState.LOGGED_IN || local == null)
|
if (!config.isEnabled() || client.getGameState() != GameState.LOGGED_IN || local == null)
|
||||||
{
|
{
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (client.getMouseIdleTicks() > LOGOUT_WARNING_AFTER_TICKS
|
if (checkIdleLogout())
|
||||||
&& client.getKeyboardIdleTicks() > LOGOUT_WARNING_AFTER_TICKS)
|
|
||||||
{
|
{
|
||||||
if (notifyIdleLogout)
|
sendNotification("[" + local.getName() + "] is about to log out from idling too long!");
|
||||||
{
|
|
||||||
sendNotification("[" + local.getName() + "] is about to log out from idling too long!");
|
|
||||||
notifyIdleLogout = false;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
notifyIdleLogout = true;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (Instant.now().compareTo(sixHourWarningTime) >= 0)
|
if (check6hrLogout())
|
||||||
{
|
{
|
||||||
if (notify6HourLogout)
|
sendNotification("[" + local.getName() + "] is about to log out from being online for 6 hours!");
|
||||||
{
|
|
||||||
sendNotification("[" + local.getName() + "] is about to log out from being online for 6 hours!");
|
|
||||||
notify6HourLogout = false;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
notify6HourLogout = true;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
Duration waitDuration = Duration.ofMillis(config.getTimeout());
|
if (checkAnimationIdle(waitDuration, local))
|
||||||
if (notifyIdle && local.getAnimation() == IDLE
|
|
||||||
&& Instant.now().compareTo(lastAnimating.plus(waitDuration)) >= 0)
|
|
||||||
{
|
{
|
||||||
sendNotification("[" + local.getName() + "] is now idle!");
|
sendNotification("[" + local.getName() + "] is now idle!");
|
||||||
notifyIdle = false;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (checkOutOfCombat(waitDuration, local))
|
||||||
|
{
|
||||||
|
sendNotification("[" + local.getName() + "] is now out of combat!");
|
||||||
|
}
|
||||||
|
|
||||||
|
if (checkLowHitpoints(waitDuration))
|
||||||
|
{
|
||||||
|
sendNotification("[" + local.getName() + "] has low hitpoints!");
|
||||||
|
}
|
||||||
|
|
||||||
|
if (checkLowPrayer(waitDuration))
|
||||||
|
{
|
||||||
|
sendNotification("[" + local.getName() + "] has low prayer!");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private boolean checkLowHitpoints(Duration waitDuration)
|
||||||
|
{
|
||||||
|
if (client.getRealSkillLevel(Skill.HITPOINTS) > config.getHitpointsThreshold())
|
||||||
|
{
|
||||||
|
if (client.getBoostedSkillLevel(Skill.HITPOINTS) <= config.getHitpointsThreshold())
|
||||||
|
{
|
||||||
|
if (!notifyHitpoints && Instant.now().compareTo(lastHitpoints.plus(waitDuration)) >= 0)
|
||||||
|
{
|
||||||
|
notifyHitpoints = true;
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
lastHitpoints = Instant.now();
|
||||||
|
notifyHitpoints = false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
private boolean checkLowPrayer(Duration waitDuration)
|
||||||
|
{
|
||||||
|
if (client.getRealSkillLevel(Skill.PRAYER) > config.getPrayerThreshold())
|
||||||
|
{
|
||||||
|
if (client.getBoostedSkillLevel(Skill.PRAYER) <= config.getPrayerThreshold())
|
||||||
|
{
|
||||||
|
if (!notifyPrayer && Instant.now().compareTo(lastPrayer.plus(waitDuration)) >= 0)
|
||||||
|
{
|
||||||
|
notifyPrayer = true;
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
lastPrayer = Instant.now();
|
||||||
|
notifyPrayer = false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
private boolean checkOutOfCombat(Duration waitDuration, Player local)
|
||||||
|
{
|
||||||
Actor opponent = local.getInteracting();
|
Actor opponent = local.getInteracting();
|
||||||
boolean isPlayer = opponent instanceof Player;
|
boolean isPlayer = opponent instanceof Player;
|
||||||
|
|
||||||
@@ -341,43 +380,70 @@ public class IdleNotifierPlugin extends Plugin
|
|||||||
|
|
||||||
if (lastInteracting != null && Instant.now().compareTo(lastInteracting.plus(waitDuration)) >= 0)
|
if (lastInteracting != null && Instant.now().compareTo(lastInteracting.plus(waitDuration)) >= 0)
|
||||||
{
|
{
|
||||||
sendNotification("[" + local.getName() + "] is now out of combat!");
|
|
||||||
lastInteracting = null;
|
lastInteracting = null;
|
||||||
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (client.getRealSkillLevel(Skill.HITPOINTS) > config.getHitpointsThreshold())
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
private boolean checkIdleLogout()
|
||||||
|
{
|
||||||
|
if (client.getMouseIdleTicks() > LOGOUT_WARNING_AFTER_TICKS
|
||||||
|
&& client.getKeyboardIdleTicks() > LOGOUT_WARNING_AFTER_TICKS)
|
||||||
{
|
{
|
||||||
if (client.getBoostedSkillLevel(Skill.HITPOINTS) <= config.getHitpointsThreshold())
|
if (notifyIdleLogout)
|
||||||
{
|
{
|
||||||
if (!notifyHitpoints && Instant.now().compareTo(lastHitpoints.plus(waitDuration)) >= 0)
|
notifyIdleLogout = false;
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
notifyIdleLogout = true;
|
||||||
|
}
|
||||||
|
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
private boolean check6hrLogout()
|
||||||
|
{
|
||||||
|
if (Instant.now().compareTo(sixHourWarningTime) >= 0)
|
||||||
|
{
|
||||||
|
if (notify6HourLogout)
|
||||||
|
{
|
||||||
|
notify6HourLogout = false;
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
notify6HourLogout = true;
|
||||||
|
}
|
||||||
|
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
private boolean checkAnimationIdle(Duration waitDuration, Player local)
|
||||||
|
{
|
||||||
|
if (notifyIdle)
|
||||||
|
{
|
||||||
|
if (lastAnimating != null)
|
||||||
|
{
|
||||||
|
if (Instant.now().compareTo(lastAnimating.plus(waitDuration)) >= 0)
|
||||||
{
|
{
|
||||||
sendNotification("[" + local.getName() + "] has low hitpoints!");
|
notifyIdle = false;
|
||||||
notifyHitpoints = true;
|
lastAnimating = null;
|
||||||
|
return true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else
|
else if (local.getAnimation() == IDLE)
|
||||||
{
|
{
|
||||||
lastHitpoints = Instant.now();
|
lastAnimating = Instant.now();
|
||||||
notifyHitpoints = false;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (client.getRealSkillLevel(Skill.PRAYER) > config.getPrayerThreshold())
|
return false;
|
||||||
{
|
|
||||||
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)
|
private void sendNotification(String message)
|
||||||
|
|||||||
Reference in New Issue
Block a user