Fix slayer plugin task reset on config change

- Add checks for empty task name and null counter when adding counter
in SlayerPlugin
- Add checks for non null counter when removing counter in SlayerPlugin

Signed-off-by: Tomas Slusny <slusnucky@gmail.com>
This commit is contained in:
Tomas Slusny
2018-01-31 11:04:43 +01:00
parent 36c4ab3c15
commit bf9f190475

View File

@@ -35,6 +35,7 @@ import java.util.List;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
import javax.inject.Inject;
import joptsimple.internal.Strings;
import lombok.extern.slf4j.Slf4j;
import net.runelite.api.ChatMessageType;
import net.runelite.api.Client;
@@ -280,12 +281,11 @@ public class SlayerPlugin extends Plugin
return;
}
boolean enabled = config.showInfobox();
if (enabled && counter == null)
if (config.showInfobox())
{
addCounter();
}
else if (!enabled && counter != null)
else
{
removeCounter();
}
@@ -315,19 +315,17 @@ public class SlayerPlugin extends Plugin
taskName = name.toLowerCase();
amount = amt;
save();
removeCounter();
if (taskName.isEmpty() || !config.showInfobox())
{
return;
}
addCounter();
}
private void addCounter()
{
if (!config.showInfobox() || counter != null || Strings.isNullOrEmpty(taskName))
{
return;
}
Task task = Task.getTask(taskName);
int itemSpriteId = ItemID.ENCHANTED_GEM;
if (task == null)
@@ -349,6 +347,11 @@ public class SlayerPlugin extends Plugin
private void removeCounter()
{
if (counter == null)
{
return;
}
infoBoxManager.removeInfoBox(counter);
counter = null;
}