Group boost notifications (#47)

* Add option to group multiple boost notifications into one

* Show names of skills in the grouped notification

* Update style of for loop per feedback
This commit is contained in:
James
2019-04-22 12:02:04 -07:00
committed by Tyler Bochard
parent 92e362e5c9
commit 9a4461f7e9
2 changed files with 51 additions and 1 deletions

View File

@@ -103,4 +103,15 @@ public interface BoostsConfig extends Config
{
return 0;
}
@ConfigItem(
keyName = "groupNotifications",
name = "Group Notifications",
description = "Configures whether or not to group notifications for multiple skills into a single notification",
position = 7
)
default boolean groupNotifications()
{
return false;
}
}

View File

@@ -26,8 +26,10 @@ package net.runelite.client.plugins.boosts;
import com.google.common.collect.ImmutableSet;
import com.google.inject.Provides;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.HashSet;
import java.util.List;
import java.util.Set;
import javax.inject.Inject;
import javax.inject.Singleton;
@@ -100,6 +102,7 @@ public class BoostsPlugin extends Plugin
private int lastChangeUp = -1;
private boolean preserveBeenActive = false;
private long lastTickMillis;
private List<String> boostedSkillsChanged = new ArrayList<>();
@Provides
BoostsConfig provideConfig(ConfigManager configManager)
@@ -213,7 +216,14 @@ public class BoostsPlugin extends Plugin
int boost = cur - real;
if (boost <= boostThreshold && boostThreshold < lastBoost)
{
notifier.notify(skill.getName() + " level is getting low!");
if (config.groupNotifications())
{
boostedSkillsChanged.add(skill.getName());
}
else
{
notifier.notify(skill.getName() + " level is getting low!");
}
}
}
}
@@ -223,6 +233,35 @@ public class BoostsPlugin extends Plugin
{
lastTickMillis = System.currentTimeMillis();
if (config.groupNotifications() && !boostedSkillsChanged.isEmpty())
{
if (boostedSkillsChanged.size() == 1)
{
notifier.notify(boostedSkillsChanged.get(0) + " level is getting low!");
}
else
{
String notification = "";
for (int i = 0; i < boostedSkillsChanged.size(); i++)
{
if (i == 0)
{
notification = boostedSkillsChanged.get(i);
}
else if (i < boostedSkillsChanged.size() - 1)
{
notification = notification + ", " + boostedSkillsChanged.get(i);
}
else
{
notification = notification + " and " + boostedSkillsChanged.get(i) + " levels are getting low!";
notifier.notify(notification);
}
}
}
boostedSkillsChanged.clear();
}
if (getChangeUpTicks() <= 0)
{
switch (config.displayNextDebuffChange())