Search in sources :

Example 1 with Schedule

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();
        }
    }
}
Also used : Matcher(java.util.regex.Matcher) Widget(net.runelite.api.widgets.Widget) Duration(java.time.Duration) Schedule(net.runelite.client.task.Schedule)

Example 2 with Schedule

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));
}
Also used : Player(net.runelite.api.Player) HashMap(java.util.HashMap) LinkedHashMap(java.util.LinkedHashMap) Map(java.util.Map) LinkedHashMap(java.util.LinkedHashMap) Schedule(net.runelite.client.task.Schedule)

Example 3 with Schedule

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();
        }
    }
}
Also used : Instant(java.time.Instant) Schedule(net.runelite.client.task.Schedule)

Example 4 with Schedule

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);
    }
}
Also used : ScheduledMethod(net.runelite.client.task.ScheduledMethod) Schedule(net.runelite.client.task.Schedule) Method(java.lang.reflect.Method) ScheduledMethod(net.runelite.client.task.ScheduledMethod)

Example 5 with Schedule

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();
    }
}
Also used : Instant(java.time.Instant) Duration(java.time.Duration) Schedule(net.runelite.client.task.Schedule)

Aggregations

Schedule (net.runelite.client.task.Schedule)6 Duration (java.time.Duration)2 Instant (java.time.Instant)2 Method (java.lang.reflect.Method)1 HashMap (java.util.HashMap)1 LinkedHashMap (java.util.LinkedHashMap)1 Map (java.util.Map)1 Matcher (java.util.regex.Matcher)1 Item (net.runelite.api.Item)1 Player (net.runelite.api.Player)1 Query (net.runelite.api.Query)1 WorldPoint (net.runelite.api.coords.WorldPoint)1 GameObjectQuery (net.runelite.api.queries.GameObjectQuery)1 InventoryItemQuery (net.runelite.api.queries.InventoryItemQuery)1 NPCQuery (net.runelite.api.queries.NPCQuery)1 Widget (net.runelite.api.widgets.Widget)1 ClueScroll (net.runelite.client.plugins.cluescrolls.clues.ClueScroll)1 EmoteClue (net.runelite.client.plugins.cluescrolls.clues.EmoteClue)1 NpcClueScroll (net.runelite.client.plugins.cluescrolls.clues.NpcClueScroll)1 ObjectClueScroll (net.runelite.client.plugins.cluescrolls.clues.ObjectClueScroll)1