use of net.runelite.client.task.Schedule in project runelite by runelite.
the class SlayerPlugin method scheduledChecks.
@Schedule(period = 600, unit = ChronoUnit.MILLIS)
public void scheduledChecks() {
Widget NPCDialog = client.getWidget(WidgetInfo.DIALOG_NPC_TEXT);
if (NPCDialog != null) {
// remove color and linebreaks
String NPCText = Text.removeTags(NPCDialog.getText());
// number, name
Matcher mAssign = NPC_ASSIGN_MESSAGE.matcher(NPCText);
// name, number
Matcher mCurrent = NPC_CURRENT_MESSAGE.matcher(NPCText);
boolean found1 = mAssign.find();
boolean found2 = mCurrent.find();
if (!found1 && !found2) {
return;
}
String taskName = found1 ? mAssign.group(2) : mCurrent.group(1);
int amount = Integer.parseInt(found1 ? mAssign.group(1) : mCurrent.group(2));
setTask(taskName, amount);
}
Widget rewardsBarWidget = client.getWidget(WidgetInfo.SLAYER_REWARDS_TOPBAR);
if (rewardsBarWidget != null) {
for (Widget w : rewardsBarWidget.getDynamicChildren()) {
Matcher mPoints = REWARD_POINTS.matcher(w.getText());
if (mPoints.find()) {
points = Integer.parseInt(mPoints.group(1));
break;
}
}
}
if (infoTimer != null) {
Duration timeSinceInfobox = Duration.between(infoTimer, Instant.now());
Duration statTimeout = Duration.ofMinutes(config.statTimeout());
if (timeSinceInfobox.compareTo(statTimeout) >= 0) {
removeCounter();
}
}
}
use of net.runelite.client.task.Schedule in project runelite by runelite.
the class TeamCapesPlugin method update.
@Schedule(period = 1800, unit = ChronoUnit.MILLIS)
public void update() {
if (client.getGameState() != GameState.LOGGED_IN) {
return;
}
List<Player> players = client.getPlayers();
teams.clear();
for (Player player : players) {
int team = player.getTeam();
if (team > 0) {
if (teams.containsKey(team)) {
teams.put(team, teams.get(team) + 1);
} else {
teams.put(team, 1);
}
}
}
// Sort teams by value in descending order and then by key in ascending order, limited to 5 entries
teams = teams.entrySet().stream().sorted(Comparator.comparing(Map.Entry<Integer, Integer>::getValue, Comparator.reverseOrder()).thenComparingInt(Map.Entry::getKey)).limit(5).collect(Collectors.toMap(Map.Entry::getKey, Map.Entry::getValue, (e1, e2) -> e1, LinkedHashMap::new));
}
use of net.runelite.client.task.Schedule in project runelite by runelite.
the class XpGlobesPlugin method removeExpiredXpGlobes.
@Schedule(period = 1, unit = ChronoUnit.SECONDS)
public void removeExpiredXpGlobes() {
if (!xpGlobes.isEmpty()) {
Instant currentTime = Instant.now();
for (Iterator<XpGlobe> it = xpGlobes.iterator(); it.hasNext(); ) {
XpGlobe globe = it.next();
Instant globeCreationTime = globe.getTime();
if (currentTime.isBefore(globeCreationTime.plusSeconds(SECONDS_TO_SHOW_GLOBE))) {
// if a globe is not expired, stop checking newer globes
return;
}
it.remove();
}
}
}
use of net.runelite.client.task.Schedule in project runelite by runelite.
the class PluginManager method schedule.
private void schedule(Plugin plugin) {
for (Method method : plugin.getClass().getMethods()) {
Schedule schedule = method.getAnnotation(Schedule.class);
if (schedule == null) {
continue;
}
ScheduledMethod scheduledMethod = new ScheduledMethod(schedule, method, plugin);
log.debug("Scheduled task {}", scheduledMethod);
scheduler.addScheduledMethod(scheduledMethod);
}
}
use of net.runelite.client.task.Schedule in project runelite by runelite.
the class MotherlodePlugin method checkMining.
@Schedule(period = 1, unit = ChronoUnit.SECONDS)
public void checkMining() {
Instant lastPayDirtMined = session.getLastPayDirtMined();
if (lastPayDirtMined == null) {
return;
}
// reset recentPayDirtMined if you haven't mined anything recently
Duration statTimeout = Duration.ofMinutes(config.statTimeout());
Duration sinceMined = Duration.between(lastPayDirtMined, Instant.now());
if (sinceMined.compareTo(statTimeout) >= 0) {
session.resetRecent();
}
}
Aggregations