-
Notifications
You must be signed in to change notification settings - Fork 5
desht edited this page Aug 5, 2011
·
13 revisions
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:
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");
}
}
}
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
}
try {
smsHandler.deleteMenu("mymenu");
} catch (SMSException e) {
// e.getMessage() contains an error message
}
if (smsHandler.checkMenu("mymenu")) {
// ....
}
try {
SMSMenu = smsHandler.getMenu("mymenu");
} catch (SMSException e) {
// e.getMessage() contains an error message - probably no such menu
}
for (SMSMenu menu : smsHandler.listMenus()) {
// ...
}
String menuName = smsHandler.getTargetedMenuSign(player, false);
if (menuName != null) {
// ...
}
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);