idlenotifier: Refactor switch fallthrough and abstractions

This commit is contained in:
Owain van Brakel
2019-08-11 21:31:59 +02:00
parent 02cf62b881
commit d5c2ec5e42

View File

@@ -25,6 +25,7 @@
*/
package net.runelite.client.plugins.idlenotifier;
import com.google.common.collect.ImmutableSet;
import com.google.inject.Provides;
import java.awt.TrayIcon;
import java.time.Duration;
@@ -33,6 +34,7 @@ import java.util.ArrayList;
import java.util.Arrays;
import java.util.EnumSet;
import java.util.List;
import java.util.Set;
import javax.inject.Inject;
import javax.inject.Singleton;
import lombok.AccessLevel;
@@ -74,10 +76,6 @@ import net.runelite.client.plugins.Plugin;
import net.runelite.client.plugins.PluginDescriptor;
import net.runelite.client.util.PvPUtil;
//import java.io.IOException;
//import javax.sound.sampled.LineUnavailableException;
//import javax.sound.sampled.UnsupportedAudioFileException;
@PluginDescriptor(
name = "Idle Notifier",
description = "Send a notification when going idle, or when HP/Prayer reaches a threshold",
@@ -97,6 +95,133 @@ public class IdleNotifierPlugin extends Plugin
private static final String FISHING_SPOT = "Fishing spot";
private static final Set<Integer> nominalAnimations = new ImmutableSet.Builder<Integer>()
.addAll(
Arrays.asList(
/* Woodcutting */
WOODCUTTING_BRONZE,
WOODCUTTING_IRON,
WOODCUTTING_STEEL,
WOODCUTTING_BLACK,
WOODCUTTING_MITHRIL,
WOODCUTTING_ADAMANT,
WOODCUTTING_RUNE,
WOODCUTTING_DRAGON,
WOODCUTTING_INFERNAL,
WOODCUTTING_3A_AXE,
WOODCUTTING_CRYSTAL,
/* Cooking(Fire, Range) */
COOKING_FIRE,
COOKING_RANGE,
COOKING_WINE,
/* Crafting(Gem Cutting, Glassblowing, Spinning, Battlestaves, Pottery) */
GEM_CUTTING_OPAL,
GEM_CUTTING_JADE,
GEM_CUTTING_REDTOPAZ,
GEM_CUTTING_SAPPHIRE,
GEM_CUTTING_EMERALD,
GEM_CUTTING_RUBY,
GEM_CUTTING_DIAMOND,
GEM_CUTTING_AMETHYST,
CRAFTING_GLASSBLOWING,
CRAFTING_SPINNING,
CRAFTING_BATTLESTAVES,
CRAFTING_LEATHER,
CRAFTING_POTTERS_WHEEL,
CRAFTING_POTTERY_OVEN,
/* Fletching(Cutting, Stringing, Adding feathers and heads) */
FLETCHING_BOW_CUTTING,
FLETCHING_STRING_NORMAL_SHORTBOW,
FLETCHING_STRING_OAK_SHORTBOW,
FLETCHING_STRING_WILLOW_SHORTBOW,
FLETCHING_STRING_MAPLE_SHORTBOW,
FLETCHING_STRING_YEW_SHORTBOW,
FLETCHING_STRING_MAGIC_SHORTBOW,
FLETCHING_STRING_NORMAL_LONGBOW,
FLETCHING_STRING_OAK_LONGBOW,
FLETCHING_STRING_WILLOW_LONGBOW,
FLETCHING_STRING_MAPLE_LONGBOW,
FLETCHING_STRING_YEW_LONGBOW,
FLETCHING_STRING_MAGIC_LONGBOW,
FLETCHING_ATTACH_FEATHERS_TO_ARROWSHAFT,
FLETCHING_ATTACH_HEADS,
/* Smithing(Anvil, Furnace, Cannonballs */
SMITHING_ANVIL,
SMITHING_SMELTING,
SMITHING_CANNONBALL,
/* Fishing */
FISHING_CRUSHING_INFERNAL_EELS,
FISHING_CUTTING_SACRED_EELS,
FISHING_BIG_NET,
FISHING_NET,
FISHING_POLE_CAST,
FISHING_CAGE,
FISHING_HARPOON,
FISHING_BARBTAIL_HARPOON,
FISHING_DRAGON_HARPOON,
FISHING_INFERNAL_HARPOON,
FISHING_OILY_ROD,
FISHING_KARAMBWAN,
FISHING_BAREHAND,
/* Mining(Normal) */
MINING_BRONZE_PICKAXE,
MINING_IRON_PICKAXE,
MINING_STEEL_PICKAXE,
MINING_BLACK_PICKAXE,
MINING_MITHRIL_PICKAXE,
MINING_ADAMANT_PICKAXE,
MINING_RUNE_PICKAXE,
MINING_DRAGON_PICKAXE,
MINING_DRAGON_PICKAXE_UPGRADED,
MINING_DRAGON_PICKAXE_OR,
MINING_INFERNAL_PICKAXE,
MINING_3A_PICKAXE,
MINING_CRYSTAL_PICKAXE,
DENSE_ESSENCE_CHIPPING,
DENSE_ESSENCE_CHISELING,
/* Mining(Motherlode) */
MINING_MOTHERLODE_BRONZE,
MINING_MOTHERLODE_IRON,
MINING_MOTHERLODE_STEEL,
MINING_MOTHERLODE_BLACK,
MINING_MOTHERLODE_MITHRIL,
MINING_MOTHERLODE_ADAMANT,
MINING_MOTHERLODE_RUNE,
MINING_MOTHERLODE_DRAGON,
MINING_MOTHERLODE_DRAGON_UPGRADED,
MINING_MOTHERLODE_DRAGON_OR,
MINING_MOTHERLODE_INFERNAL,
MINING_MOTHERLODE_3A,
MINING_MOTHERLODE_CRYSTAL,
/* Herblore */
HERBLORE_PESTLE_AND_MORTAR,
HERBLORE_POTIONMAKING,
HERBLORE_MAKE_TAR,
/* Magic */
MAGIC_CHARGING_ORBS,
MAGIC_LUNAR_PLANK_MAKE,
MAGIC_LUNAR_STRING_JEWELRY,
MAGIC_MAKE_TABLET,
MAGIC_ENCHANTING_JEWELRY,
MAGIC_ENCHANTING_AMULET_1,
MAGIC_ENCHANTING_AMULET_2,
MAGIC_ENCHANTING_AMULET_3,
/* Prayer */
USING_GILDED_ALTAR,
/* Farming */
FARMING_MIX_ULTRACOMPOST,
FARMING_HARVEST_BUSH,
FARMING_HARVEST_HERB,
FARMING_HARVEST_FRUIT_TREE,
FARMING_HARVEST_FLOWER,
FARMING_HARVEST_ALLOTMENT,
/* Misc */
PISCARILIUS_CRANE_REPAIR,
HOME_MAKE_TABLET,
SAND_COLLECTION
)
).build();
@Inject
private Notifier notifier;
@@ -182,151 +307,26 @@ public class IdleNotifierPlugin extends Plugin
int graphic = localPlayer.getSpotAnimation();
int animation = localPlayer.getAnimation();
switch (animation)
if (nominalAnimations.contains(animation) || (animation == MAGIC_LUNAR_SHARED && graphic == GraphicID.BAKE_PIE))
{
/* Woodcutting */
case WOODCUTTING_BRONZE:
case WOODCUTTING_IRON:
case WOODCUTTING_STEEL:
case WOODCUTTING_BLACK:
case WOODCUTTING_MITHRIL:
case WOODCUTTING_ADAMANT:
case WOODCUTTING_RUNE:
case WOODCUTTING_DRAGON:
case WOODCUTTING_INFERNAL:
case WOODCUTTING_3A_AXE:
case WOODCUTTING_CRYSTAL:
/* Cooking(Fire, Range) */
case COOKING_FIRE:
case COOKING_RANGE:
case COOKING_WINE:
/* Crafting(Gem Cutting, Glassblowing, Spinning, Battlestaves, Pottery) */
case GEM_CUTTING_OPAL:
case GEM_CUTTING_JADE:
case GEM_CUTTING_REDTOPAZ:
case GEM_CUTTING_SAPPHIRE:
case GEM_CUTTING_EMERALD:
case GEM_CUTTING_RUBY:
case GEM_CUTTING_DIAMOND:
case GEM_CUTTING_AMETHYST:
case CRAFTING_GLASSBLOWING:
case CRAFTING_SPINNING:
case CRAFTING_BATTLESTAVES:
case CRAFTING_LEATHER:
case CRAFTING_POTTERS_WHEEL:
case CRAFTING_POTTERY_OVEN:
/* Fletching(Cutting, Stringing, Adding feathers and heads) */
case FLETCHING_BOW_CUTTING:
case FLETCHING_STRING_NORMAL_SHORTBOW:
case FLETCHING_STRING_OAK_SHORTBOW:
case FLETCHING_STRING_WILLOW_SHORTBOW:
case FLETCHING_STRING_MAPLE_SHORTBOW:
case FLETCHING_STRING_YEW_SHORTBOW:
case FLETCHING_STRING_MAGIC_SHORTBOW:
case FLETCHING_STRING_NORMAL_LONGBOW:
case FLETCHING_STRING_OAK_LONGBOW:
case FLETCHING_STRING_WILLOW_LONGBOW:
case FLETCHING_STRING_MAPLE_LONGBOW:
case FLETCHING_STRING_YEW_LONGBOW:
case FLETCHING_STRING_MAGIC_LONGBOW:
case FLETCHING_ATTACH_FEATHERS_TO_ARROWSHAFT:
case FLETCHING_ATTACH_HEADS:
/* Smithing(Anvil, Furnace, Cannonballs */
case SMITHING_ANVIL:
case SMITHING_SMELTING:
case SMITHING_CANNONBALL:
/* Fishing */
case FISHING_CRUSHING_INFERNAL_EELS:
case FISHING_CUTTING_SACRED_EELS:
case FISHING_BIG_NET:
case FISHING_NET:
case FISHING_POLE_CAST:
case FISHING_CAGE:
case FISHING_HARPOON:
case FISHING_BARBTAIL_HARPOON:
case FISHING_DRAGON_HARPOON:
case FISHING_INFERNAL_HARPOON:
case FISHING_OILY_ROD:
case FISHING_KARAMBWAN:
case FISHING_BAREHAND:
/* Mining(Normal) */
case MINING_BRONZE_PICKAXE:
case MINING_IRON_PICKAXE:
case MINING_STEEL_PICKAXE:
case MINING_BLACK_PICKAXE:
case MINING_MITHRIL_PICKAXE:
case MINING_ADAMANT_PICKAXE:
case MINING_RUNE_PICKAXE:
case MINING_DRAGON_PICKAXE:
case MINING_DRAGON_PICKAXE_UPGRADED:
case MINING_DRAGON_PICKAXE_OR:
case MINING_INFERNAL_PICKAXE:
case MINING_3A_PICKAXE:
case MINING_CRYSTAL_PICKAXE:
case DENSE_ESSENCE_CHIPPING:
case DENSE_ESSENCE_CHISELING:
/* Mining(Motherlode) */
case MINING_MOTHERLODE_BRONZE:
case MINING_MOTHERLODE_IRON:
case MINING_MOTHERLODE_STEEL:
case MINING_MOTHERLODE_BLACK:
case MINING_MOTHERLODE_MITHRIL:
case MINING_MOTHERLODE_ADAMANT:
case MINING_MOTHERLODE_RUNE:
case MINING_MOTHERLODE_DRAGON:
case MINING_MOTHERLODE_DRAGON_UPGRADED:
case MINING_MOTHERLODE_DRAGON_OR:
case MINING_MOTHERLODE_INFERNAL:
case MINING_MOTHERLODE_3A:
case MINING_MOTHERLODE_CRYSTAL:
/* Herblore */
case HERBLORE_PESTLE_AND_MORTAR:
case HERBLORE_POTIONMAKING:
case HERBLORE_MAKE_TAR:
/* Magic */
case MAGIC_CHARGING_ORBS:
case MAGIC_LUNAR_PLANK_MAKE:
case MAGIC_LUNAR_STRING_JEWELRY:
case MAGIC_MAKE_TABLET:
case MAGIC_ENCHANTING_JEWELRY:
case MAGIC_ENCHANTING_AMULET_1:
case MAGIC_ENCHANTING_AMULET_2:
case MAGIC_ENCHANTING_AMULET_3:
/* Prayer */
case USING_GILDED_ALTAR:
/* Farming */
case FARMING_MIX_ULTRACOMPOST:
case FARMING_HARVEST_BUSH:
case FARMING_HARVEST_HERB:
case FARMING_HARVEST_FRUIT_TREE:
case FARMING_HARVEST_FLOWER:
case FARMING_HARVEST_ALLOTMENT:
/* Misc */
case PISCARILIUS_CRANE_REPAIR:
case HOME_MAKE_TABLET:
case SAND_COLLECTION:
resetTimers();
lastAnimation = animation;
lastAnimating = Instant.now();
interactingNotified = false;
break;
case MAGIC_LUNAR_SHARED:
if (graphic == GraphicID.BAKE_PIE)
{
resetTimers();
lastAnimation = animation;
lastAnimating = Instant.now();
interactingNotified = false;
break;
}
case IDLE:
lastAnimating = Instant.now();
interactingNotified = false;
break;
default:
// On unknown animation simply assume the animation is invalid and dont throw notification
lastAnimation = IDLE;
lastAnimating = null;
resetTimers();
lastAnimation = animation;
lastAnimating = Instant.now();
interactingNotified = false;
}
else if (animation == IDLE)
{
lastAnimating = Instant.now();
interactingNotified = false;
}
// On unknown animation simply assume the animation is invalid and dont throw notification
else
{
lastAnimation = IDLE;
lastAnimating = null;
}
}
@@ -555,17 +555,17 @@ public class IdleNotifierPlugin extends Plugin
if (this.logoutIdle && checkIdleLogout())
{
notifier.notify("[" + local.getName() + "] is about to log out from idling too long!");
notifyWith(local, "is about to log out from idling too long!");
}
if (check6hrLogout())
{
notifier.notify("[" + local.getName() + "] is about to log out from being online for 6 hours!");
notifyWith(local, "is about to log out from being online for 6 hours!");
}
if (this.outOfItemsIdle && checkOutOfItemsIdle(waitDuration))
{
notifier.notify("[" + local.getName() + "] has run out of items!");
notifyWith(local, "has run out of items!");
// If this triggers, don't also trigger animation idle notification afterwards.
lastAnimation = IDLE;
}
@@ -574,7 +574,7 @@ public class IdleNotifierPlugin extends Plugin
{
if (lastInteractWasCombat)
{
notifier.notify("[" + local.getName() + "] is now out of combat!");
notifyWith(local, "is now out of combat!");
if (this.outOfCombatSound)
{
soundManager.playSound(Sound.OUT_OF_COMBAT);
@@ -582,7 +582,7 @@ public class IdleNotifierPlugin extends Plugin
}
else
{
notifier.notify("[" + local.getName() + "] is now idle!");
notifyWith(local, "is now idle!");
if (this.interactionIdleSound)
{
soundManager.playSound(Sound.IDLE);
@@ -593,7 +593,7 @@ public class IdleNotifierPlugin extends Plugin
if (this.animationIdle && checkAnimationIdle(waitDuration, local))
{
notifier.notify("[" + local.getName() + "] is now idle!");
notifyWith(local, "is now idle!");
if (this.animationIdleSound)
{
soundManager.playSound(Sound.IDLE);
@@ -602,7 +602,7 @@ public class IdleNotifierPlugin extends Plugin
if (checkLowHitpoints())
{
notifier.notify("[" + local.getName() + "] has low hitpoints!");
notifyWith(local, "has low hitpoints!");
if (this.getPlayHealthSound)
{
soundManager.playSound(Sound.LOW_HEATLH);
@@ -611,7 +611,7 @@ public class IdleNotifierPlugin extends Plugin
if (checkLowPrayer())
{
notifier.notify("[" + local.getName() + "] has low prayer!");
notifyWith(local, "has low prayer!");
if (this.getPlayPrayerSound)
{
soundManager.playSound(Sound.LOW_PRAYER);
@@ -620,12 +620,12 @@ public class IdleNotifierPlugin extends Plugin
if (checkLowOxygen())
{
notifier.notify("[" + local.getName() + "] has low oxygen!");
notifyWith(local, "has low oxygen!");
}
if (checkFullSpecEnergy())
{
notifier.notify("[" + local.getName() + "] has restored spec energy!");
notifyWith(local, "has restored spec energy!");
if (this.getSpecSound)
{
soundManager.playSound(Sound.RESTORED_SPECIAL_ATTACK);
@@ -895,11 +895,11 @@ public class IdleNotifierPlugin extends Plugin
{
if (this.showSkullNotification && lastTickSkull == null && currentTickSkull == SkullIcon.SKULL)
{
notifier.notify("[" + local.getName() + "] is now skulled!");
notifyWith(local, "is now skulled!");
}
else if (this.showUnskullNotification && lastTickSkull == SkullIcon.SKULL && currentTickSkull == null)
{
notifier.notify("[" + local.getName() + "] is now unskulled!");
notifyWith(local, "is now unskulled!");
}
}
else
@@ -911,6 +911,10 @@ public class IdleNotifierPlugin extends Plugin
}
}
private void notifyWith(Player local, String message) {
notifier.notify("[" + local.getName() + "] " + message);
}
@Override
protected void startUp() throws Exception
{