slayer plugin: fix getting -1 count left on tasks
Don't readd a new infobox for each kill due to config update triggers
This commit is contained in:
@@ -109,7 +109,7 @@ public class SlayerPlugin extends Plugin
|
|||||||
@Override
|
@Override
|
||||||
protected void shutDown() throws Exception
|
protected void shutDown() throws Exception
|
||||||
{
|
{
|
||||||
infoBoxManager.removeIf(t -> t instanceof TaskCounter);
|
removeCounter();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@@ -282,21 +282,33 @@ public class SlayerPlugin extends Plugin
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
infoBoxManager.removeIf(t -> t instanceof TaskCounter);
|
boolean enabled = config.enabled() && config.showInfobox();
|
||||||
if (config.enabled() && config.showInfobox() && counter != null)
|
if (enabled && counter == null)
|
||||||
{
|
{
|
||||||
infoBoxManager.addInfoBox(counter);
|
addCounter();
|
||||||
|
}
|
||||||
|
else if (!enabled && counter != null)
|
||||||
|
{
|
||||||
|
removeCounter();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private void killedOne()
|
private void killedOne()
|
||||||
{
|
{
|
||||||
|
if (amount == 0)
|
||||||
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
amount--;
|
amount--;
|
||||||
save();
|
config.amount(amount); // save changed value
|
||||||
|
|
||||||
if (!config.showInfobox())
|
if (!config.showInfobox())
|
||||||
{
|
{
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// update counter
|
||||||
counter.setText(String.valueOf(amount));
|
counter.setText(String.valueOf(amount));
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -306,13 +318,18 @@ public class SlayerPlugin extends Plugin
|
|||||||
amount = amt;
|
amount = amt;
|
||||||
save();
|
save();
|
||||||
|
|
||||||
infoBoxManager.removeIf(t -> t instanceof TaskCounter);
|
removeCounter();
|
||||||
|
|
||||||
if (taskName.isEmpty() || !config.showInfobox())
|
if (taskName.isEmpty() || !config.showInfobox())
|
||||||
{
|
{
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
addCounter();
|
||||||
|
}
|
||||||
|
|
||||||
|
private void addCounter()
|
||||||
|
{
|
||||||
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)
|
||||||
@@ -332,6 +349,12 @@ public class SlayerPlugin extends Plugin
|
|||||||
infoBoxManager.addInfoBox(counter);
|
infoBoxManager.addInfoBox(counter);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private void removeCounter()
|
||||||
|
{
|
||||||
|
infoBoxManager.removeInfoBox(counter);
|
||||||
|
counter = null;
|
||||||
|
}
|
||||||
|
|
||||||
//Getters
|
//Getters
|
||||||
@Override
|
@Override
|
||||||
public Overlay getOverlay()
|
public Overlay getOverlay()
|
||||||
|
|||||||
Reference in New Issue
Block a user