configurable slayer infobox expiry timer
Add an option in plugin config to set a time for the infobox to expire Infobox appears on getting task, checking task, killing slayer monster, initial log in
This commit is contained in:
@@ -65,6 +65,16 @@ public interface SlayerConfig extends Config
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ConfigItem(
|
||||||
|
keyName = "statTimeout",
|
||||||
|
name = "InfoBox Expiry (minutes)",
|
||||||
|
description = "Set the time until the InfoBox expires"
|
||||||
|
)
|
||||||
|
default int statTimeout()
|
||||||
|
{
|
||||||
|
return 5;
|
||||||
|
}
|
||||||
|
|
||||||
// Stored data
|
// Stored data
|
||||||
@ConfigItem(
|
@ConfigItem(
|
||||||
keyName = "taskName",
|
keyName = "taskName",
|
||||||
|
|||||||
@@ -27,6 +27,8 @@ package net.runelite.client.plugins.slayer;
|
|||||||
import com.google.common.eventbus.Subscribe;
|
import com.google.common.eventbus.Subscribe;
|
||||||
import com.google.inject.Provides;
|
import com.google.inject.Provides;
|
||||||
import java.awt.image.BufferedImage;
|
import java.awt.image.BufferedImage;
|
||||||
|
import java.time.Instant;
|
||||||
|
import java.time.Duration;
|
||||||
import java.time.temporal.ChronoUnit;
|
import java.time.temporal.ChronoUnit;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
@@ -100,6 +102,8 @@ public class SlayerPlugin extends Plugin
|
|||||||
private int streak;
|
private int streak;
|
||||||
private int points;
|
private int points;
|
||||||
private int cachedXp;
|
private int cachedXp;
|
||||||
|
private Instant infoTimer;
|
||||||
|
private boolean loginFlag;
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void startUp() throws Exception
|
protected void startUp() throws Exception
|
||||||
@@ -134,11 +138,15 @@ public class SlayerPlugin extends Plugin
|
|||||||
cachedXp = 0;
|
cachedXp = 0;
|
||||||
taskName = "";
|
taskName = "";
|
||||||
amount = 0;
|
amount = 0;
|
||||||
|
loginFlag = true;
|
||||||
break;
|
break;
|
||||||
case LOGGED_IN:
|
case LOGGED_IN:
|
||||||
if (config.amount() != -1 && !config.taskName().isEmpty())
|
if (config.amount() != -1
|
||||||
|
&& !config.taskName().isEmpty()
|
||||||
|
&& loginFlag == true)
|
||||||
{
|
{
|
||||||
setTask(config.taskName(), config.amount());
|
setTask(config.taskName(), config.amount());
|
||||||
|
loginFlag = false;
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
@@ -189,6 +197,17 @@ public class SlayerPlugin extends Plugin
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (infoTimer != null)
|
||||||
|
{
|
||||||
|
Duration timeSinceInfobox = Duration.between(infoTimer, Instant.now());
|
||||||
|
Duration statTimeout = Duration.ofMinutes(config.statTimeout());
|
||||||
|
|
||||||
|
if (timeSinceInfobox.compareTo(statTimeout) >= 0)
|
||||||
|
{
|
||||||
|
removeCounter();
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Subscribe
|
@Subscribe
|
||||||
@@ -311,8 +330,10 @@ public class SlayerPlugin extends Plugin
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
// update counter
|
// add and update counter, set timer
|
||||||
|
addCounter();
|
||||||
counter.setText(String.valueOf(amount));
|
counter.setText(String.valueOf(amount));
|
||||||
|
infoTimer = Instant.now();
|
||||||
}
|
}
|
||||||
|
|
||||||
private void setTask(String name, int amt)
|
private void setTask(String name, int amt)
|
||||||
@@ -322,6 +343,7 @@ public class SlayerPlugin extends Plugin
|
|||||||
save();
|
save();
|
||||||
removeCounter();
|
removeCounter();
|
||||||
addCounter();
|
addCounter();
|
||||||
|
infoTimer = Instant.now();
|
||||||
}
|
}
|
||||||
|
|
||||||
private void addCounter()
|
private void addCounter()
|
||||||
|
|||||||
Reference in New Issue
Block a user