Skip to content
desht edited this page Aug 5, 2011 · 13 revisions

API

ScrollingMenuSign exposes an API to allow other plugins to query and manipulate its menus.

JavaDoc API reference can be found here

Here are some examples of using the API:

Set up the handler object

    import me.desht.scrollingmenusign.SMSHandler;
    import me.desht.scrollingmenusign.SMSMenu;
    import me.desht.scrollingmenusign.SMSException;
    import me.desht.scrollingmenusign.ScrollingMenuSign;

    SMSHandler smsHandler;

    // you would call something like this from your onEnable() method
    static void setup() {
            if (smsHandler == null) {
                    Plugin p = Bukkit.getServer().getPluginManager().getPlugin("ScrollingMenuSign");
                    if (p != null && p instanceof ScrollingMenuSign) {
                            ScrollingMenuSign sms = (ScrollingMenuSign) p;
                            smsHandler = sms.getHandler();
                            ChessCraftLogger.info("ScrollingMenuSign integration is enabled");
                    } else {
                            ChessCraftLogger.info("ScrollingMenuSign integration is not enabled");
                    }
            }
    }

Create a new menu

    SMSMenu menu = smsHandler.createMenu("mymenu", "&1My Title", "owner-name");
    if (menu != null) {
            menu.addItem("Day", "/time day", "It's day time!");
            menu.addItem("Night", "/time night", "It's night time!");
            menu.addItem("Compass", "/compass", "");
    } else {
            // should never get here
    }

Delete a menu

    try {
            smsHandler.deleteMenu("mymenu");
    } catch (SMSException e) {
            // e.getMessage() contains an error message
    }

Check if a menu exists

    if (smsHandler.checkMenu("mymenu")) {
            // ....
    }

Retrieve a menu by name

    try {
            SMSMenu = smsHandler.getMenu("mymenu");
    } catch (SMSException e) {
            // e.getMessage() contains an error message - probably no such menu
    }

Iterate through all known menus

    for (SMSMenu menu : smsHandler.listMenus()) {
            // ...
    }

Get the name of the menu which owns the sign the player is looking at

    String menuName = smsHandler.getTargetedMenuSign(player, false);
    if (menuName != null) {
            // ...
    }

Some useful menu operations

    SMSMenu menu = smsHandler.getMenu("mymenu");

    // add an item
    menu.addItem("Day", "/time day", "It's day time");

    // remove an item
    menu.removeItem(1);             // by numeric index
    menu.removeItem("Day");       // by label

    // connect a sign at <loc> to the menu (exception thrown if no sign there)
    Location loc = new Location(world, x, y, z);
    menu.addSign(loc);

    // sort the menu
    menu.sortItems();
    // set the menu to autosort
    menu.setAutosort(true);

    // scroll the sign at <loc> up or down
    menu.nextItem(loc);
    menu.prevItem(loc);

    // get the specified item
    SMSMenuItem item = menu.getItem(1);     // by numeric index
    SMSMenuItem item = menu.getItem("day"); // by label

    // get the currently selected item on the given sign
    SMSMenuItem item = menu.getCurentItem(loc);

    /* 
     * A repaint is always needed after any of the above operations - repaints
     * are not done automatically.
     */

    // repaint all the menu's signs
    menu.updateSigns();

    // repaint one of the menu's signs
    menu.updateSign(loc);
Clone this wiki locally