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