Jump to content
View in the app

A better way to browse. Learn more.

OSBot :: 2007 OSRS Botting

A full-screen app on your home screen with push notifications, badges and more.

To install this app on iOS and iPadOS
  1. Tap the Share icon in Safari
  2. Scroll the menu and tap Add to Home Screen.
  3. Tap Add in the top-right corner.
To install this app on Android
  1. Tap the 3-dot menu (⋮) in the top-right corner of the browser.
  2. Tap Add to Home screen or Install app.
  3. Confirm by tapping Install.

Widget Action Filter

Featured Replies

import org.osbot.rs07.api.filter.Filter;
import org.osbot.rs07.api.ui.RS2Widget;

public final class WidgetActionFilter implements Filter<RS2Widget> {

    private final String[] actions;

    public WidgetActionFilter(final String... actions) {
        this.actions = actions;
    }

    @Override
    public final boolean match(final RS2Widget rs2Widget) {
        if (rs2Widget == null || !rs2Widget.isVisible() || rs2Widget.getInteractActions() == null) {
            return false;
        }
        for (final String widgetAction : rs2Widget.getInteractActions()) {
            for (final String matchAction : actions) {
                if (matchAction.equals(widgetAction)) {
                    return true;
                }
            }
        }
        return false;
    }
}

 

Edited by Explv

noooooooooooooooooooooooooooooooooooooooooooooooooooo

  • Author

Updated the code here, previously could cause NPE if RS2Widget.getInteractActions() contains a null value.

Changed

if (widgetAction.equals(matchAction))

To

if (matchAction.equals(widgetAction))

Thanks for the bug report @The Undefeated 

  • Only valid widgets would be passed into the match function, so you don't need to check for that.
  • Be sure to check the array length to make sure it's not an empty array.
  • You should only have one return statement in a function.
  • You should store the widget actions in a variable and reuse them.
@Override
public final boolean match(RS2Widget widget) {
	boolean match = false;
	String widgetActions = rs2Widget.getInteractActions();
		if (widgetActions != null && widgetActions.length > 0) {
		for (String action : actions) {
			for (String widgetAction : widgetActions) {
				if (widgetAction.equals(action)) {
					match = true;
					break;
				}
			}
		}
	}
	return match;
}

 

  • Author
45 minutes ago, liverare said:
  • Only valid widgets would be passed into the match function, so you don't need to check for that.
  • Be sure to check the array length to make sure it's not an empty array.
  • You should only have one return statement in a function.
  • You should store the widget actions in a variable and reuse them.

@Override
public final boolean match(RS2Widget widget) {
	boolean match = false;
	String widgetActions = rs2Widget.getInteractActions();
		if (widgetActions != null && widgetActions.length > 0) {
		for (String action : actions) {
			for (String widgetAction : widgetActions) {
				if (widgetAction.equals(action)) {
					match = true;
					break;
				}
			}
		}
	}
	return match;
}

 

 

1. Not necessarily true, you could call the match function yourself with an invalid widget outside of the OSBot methods

2. I am using a foreach loop, I don't need to check if the array is empty

3. I personally think that this convention is purely personal preference and ancient history. I find code much more legible if I have early return conditions.

If your code has many many return statements in a single function, then probably it is not as object oriented as it should be, in this case I do not think it applies.

4. If you look at how my loops are structured I only loop the widget's actions once, and the match actions are stored in a variable.

Create an account or sign in to comment

Recently Browsing 0

  • No registered users viewing this page.

Account

Navigation

Search

Configure browser push notifications

Chrome (Android)
  1. Tap the lock icon next to the address bar.
  2. Tap Permissions → Notifications.
  3. Adjust your preference.
Chrome (Desktop)
  1. Click the padlock icon in the address bar.
  2. Select Site settings.
  3. Find Notifications and adjust your preference.