public GUIImpl getFirstPage(Category category) { List<GUIImpl> guis = categoryMenus.get(category.getId()); if (guis == null) return null; return Iterables.getFirst(guis, null); }
@Override public void run() { categoryMenus.get(category.getId()).get(page + 1).open(player); } });
@Override public void run() { categoryMenus.get(category.getId()).get(page - 1).open(player); } });
public void update() { if (plugin.getApiClient() == null || plugin.getServerInformation() == null) { plugin.getLogger().warning("No secret key available (or no server information), so can't update inventories."); return; } Listing listing = plugin.getListingUpdateTask().getListing(); if (listing == null) { plugin.getLogger().warning("No listing found, so can't update inventories."); return; } List<Integer> foundIds = new ArrayList<>(); for (Category category : listing.getCategories()) { foundIds.add(category.getId()); for (Category category1 : category.getSubcategories()) { foundIds.add(category1.getId()); } } for (Iterator<Map.Entry<Integer, List<GUIImpl>>> it = categoryMenus.entrySet().iterator(); it.hasNext(); ) { Map.Entry<Integer, List<GUIImpl>> next = it.next(); if (!foundIds.contains(next.getKey())) { for (GUIImpl gui : next.getValue()) { gui.destroy(); } it.remove(); } } for (Category category : listing.getCategories()) { doUpdate(null, category); } }
private void doUpdate(Category parent, Category category) { List<GUIImpl> pages = categoryMenus.get(category.getId()); if (pages == null) { pages = new ArrayList<>(); categoryMenus.put(category.getId(), pages); for (int i = 0; i < calculatePages(category); i++) { GUIImpl gui = new GUIImpl(parent != null ? parent.getId() : null, i, category); plugin.getServer().getPluginManager().registerEvents(gui, plugin); pages.add(gui); int toAdd = -toRemove; for (int i = 0; i < toAdd; i++) { GUIImpl gui = new GUIImpl(parent != null ? parent.getId() : null, pages.size(), category); plugin.getServer().getPluginManager().registerEvents(gui, plugin); pages.add(gui); if (gui.requiresResize(category)) { HandlerList.unregisterAll(gui); GUIImpl tmpGui = new GUIImpl(parent != null ? parent.getId() : null, i, category); plugin.getServer().getPluginManager().registerEvents(tmpGui, plugin); pages.set(i, tmpGui);