public static void loadViews() { ViewManager vm = ScrollingMenuSign.getInstance().getViewManager(); for (SMSView view : vm.listViews()) { vm.deleteView(view, false); } for (File f : DirectoryStructure.getViewsFolder().listFiles(ymlFilter)) { Debugger.getInstance().debug(2, "loading view: " + f); YamlConfiguration conf = YamlConfiguration.loadConfiguration(f); SMSView view = vm.loadView(conf); if (view != null) { view.update(view.getNativeMenu(), new RepaintAction()); } } Debugger.getInstance().debug("Loaded " + vm.listViews().size() + " views from file."); }
@Override public boolean execute(ScrollingMenuSign plugin, Player player, String[] args) throws SMSException { SMSView view = null; SMSMenu menu = plugin.getHandler().getMenu(args[0]); if (args.length == 2 && args[1].equalsIgnoreCase("-spout")) { // spout view if (plugin.isSpoutEnabled()) view = SMSSpoutView.addSpoutViewToMenu(menu); else throw new SMSException("Server is not Spout-enabled"); } else if (args.length == 3 && args[1].equalsIgnoreCase("-sign")) { // sign view Location loc = MiscUtil.parseLocation(args[2], player); view = SMSSignView.addSignToMenu(menu, loc); } else if (args.length == 3 && args[1].equalsIgnoreCase("-redstone")) { // redstone view Location loc = MiscUtil.parseLocation(args[2], player); view = SMSRedstoneView.addRedstoneViewToMenu(menu, loc); } else if (args.length == 2 && (args[1].equalsIgnoreCase("-sign") || args[1].equalsIgnoreCase("-redstone"))) { // create a new view interactively notFromConsole(player); String type = args[1].substring(1); MiscUtil.statusMessage( player, "Left-click a block to add it as a &9" + type + "&- view on menu &e" + menu.getName() + "&-."); MiscUtil.statusMessage(player, "Right-click anywhere to cancel."); plugin.expecter.expectingResponse(player, new ExpectViewCreation(menu, args[1])); return true; } else if (args.length == 3 && args[1].equalsIgnoreCase("-map")) { // map view try { short mapId = Short.parseShort(args[2]); view = SMSMapView.addMapToMenu(menu, mapId); } catch (NumberFormatException e) { throw new SMSException(e.getMessage()); } } else if (args.length > 1) { MiscUtil.errorMessage(player, "Unknown view type: " + args[1]); return false; } if (view == null) { // see if we can get a view from what the player is looking at or holding notFromConsole(player); if (player.getItemInHand().getType() == Material.MAP) { // map view PermissionsUtils.requirePerms(player, "scrollingmenusign.use.map"); short mapId = player.getItemInHand().getDurability(); view = SMSMapView.addMapToMenu(menu, mapId); } else { try { Block b = player.getTargetBlock(null, 3); // sign view ? if (b.getType() == Material.WALL_SIGN || b.getType() == Material.SIGN_POST) { view = SMSSignView.addSignToMenu(menu, b.getLocation()); } } catch (IllegalStateException e) { // ignore } } } if (view != null) { MiscUtil.statusMessage( player, String.format( "Added &9%s&- view &e%s&- to menu &e%s&-.", view.getType(), view.getName(), menu.getName())); } else { throw new SMSException("Found nothing suitable to add as a menu view"); } return true; }