Java Code Examples for org.bukkit.entity.HumanEntity#closeInventory()

The following examples show how to use org.bukkit.entity.HumanEntity#closeInventory() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: InventoryGui.java    From InventoryGui with MIT License 6 votes vote down vote up
@EventHandler(priority = EventPriority.MONITOR)
public void onInventoryClose(InventoryCloseEvent event) {
    Inventory inventory = getInventory(event.getPlayer());
    if (event.getInventory().equals(inventory)) {
        // go back. that checks if the player is in gui and has history
        if (gui.equals(getOpen(event.getPlayer()))) {
            if (closeAction == null || closeAction.onClose(new Close(event.getPlayer(), gui, event))) {
                goBack(event.getPlayer());
            } else {
                clearHistory(event.getPlayer());
            }
        }
        if (inventories.size() <= 1) {
            destroy(false);
        } else {
            inventory.clear();
            for (HumanEntity viewer : inventory.getViewers()) {
                if (viewer != event.getPlayer()) {
                    viewer.closeInventory();
                }
            }
            inventories.remove(event.getPlayer().getUniqueId());
        }
    }
}
 
Example 2
Source File: GuiListener.java    From IF with The Unlicense 6 votes vote down vote up
/**
   * Handles the disabling of the plugin
   *
   * @param event the event fired
   * @since 0.5.19
   */
  @EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true)
  public void onPluginDisable(@NotNull PluginDisableEvent event) {
      Plugin thisPlugin = JavaPlugin.getProvidingPlugin(getClass());
      if (event.getPlugin() != thisPlugin) {
          return;
      }

      int counter = 0; //callbacks might open GUIs, eg. in nested menus
int maxCount = 10;
      while (!activeGuiInstances.isEmpty() && counter++ < maxCount) {
          for (Gui gui : new ArrayList<>(activeGuiInstances)) {
              for (HumanEntity viewer : gui.getViewers()) {
                  viewer.closeInventory();
              }
          }
      }

      if (counter == maxCount) {
	thisPlugin.getLogger().warning("Unable to close GUIs on plugin disable: they keep getting opened "
			+ "(tried: " + maxCount + " times)");
}
  }
 
Example 3
Source File: GUI.java    From MineTinker with GNU General Public License v3.0 5 votes vote down vote up
/**
 * this will close the Listener section of the GUI
 * show() will throw Exception when called after close()
 * can be used to micro manage the performance of the GUIs
 */
public void close() {
	synchronized (this) {
		if (isClosed) {
			return;
		}

		isClosed = true;
		for (Window w : windows) {
			for (HumanEntity humanEntity : new ArrayList<>(w.getInventory().getViewers())) {
				//new ArrayList is required as of ModificationException
				humanEntity.closeInventory();
			}

			for (GUI.Window.Button button : w.buttonMap) {
				if (button == null) continue;
				for (ButtonAction action : button.actions.values()) {
					if (action instanceof ButtonAction.PAGE_GOTO) {
						GUI other = ((ButtonAction.PAGE_GOTO) action).window.gui;
						if (!other.equals(this)) { //Close other GUIs
							other.close();
						}
					}
				}
			}
		}

		HandlerList.unregisterAll(this);
	}
}
 
Example 4
Source File: InventoryPreview.java    From QuickShop-Reremake with GNU General Public License v3.0 5 votes vote down vote up
public void close() {
    if (inventory == null) {
        return;
    }
    for (HumanEntity player : inventory.getViewers()) {
        player.closeInventory();
    }
    inventory = null; // Destory
}
 
Example 5
Source File: InventoryGui.java    From InventoryGui with MIT License 5 votes vote down vote up
/**
 * Close the GUI for everyone viewing it
 * @param clearHistory  Whether or not to close the GUI completely (by clearing the history)
 */
public void close(boolean clearHistory) {
    for (Inventory inventory : inventories.values()) {
        for (HumanEntity viewer : new ArrayList<>(inventory.getViewers())) {
            if (clearHistory) {
                clearHistory(viewer);
            }
            viewer.closeInventory();
        }
    }
}
 
Example 6
Source File: IconInventory.java    From UHC with MIT License 5 votes vote down vote up
@Override
public void onPluginShutdown() {
    for (final HumanEntity viewer : getCurrentViewers()) {
        viewer.closeInventory();
    }

    openedInventories.clear();
}
 
Example 7
Source File: CustomInventory.java    From NBTEditor with GNU General Public License v3.0 5 votes vote down vote up
public final void close() {
	if (_owner != null) {
		for (HumanEntity human : _inventory.getViewers().toArray(new HumanEntity[0])) {
			human.closeInventory();
		}
	}
}
 
Example 8
Source File: IconInventory.java    From UHC with MIT License 4 votes vote down vote up
protected void reopenForCurrentViewers() {
    for (final HumanEntity viewer : getCurrentViewers()) {
        viewer.closeInventory();
        showTo(viewer);
    }
}
 
Example 9
Source File: DirtyChestMenu.java    From Slimefun4 with GNU General Public License v3.0 4 votes vote down vote up
public void close() {
    for (HumanEntity human : new ArrayList<>(toInventory().getViewers())) {
        human.closeInventory();
    }
}
 
Example 10
Source File: PaginatedGUI.java    From SpigotPaginatedGUI with MIT License 2 votes vote down vote up
/**
 * Simply an alias that executes {@link HumanEntity#closeInventory()} and then
 * {@link HumanEntity#openInventory(Inventory)}.
 *
 * @param holder The HumanEntity that you wish to refresh the inventory for.
 */
public void refreshInventory(HumanEntity holder){
    holder.closeInventory();
    holder.openInventory(getInventory());
}
 
Example 11
Source File: PaginatedGUI.java    From Statz with GNU General Public License v3.0 2 votes vote down vote up
/**
 * Simply an alias that executes {@link HumanEntity#closeInventory()} and then
 * {@link HumanEntity#openInventory(Inventory)}.
 *
 * @param holder The HumanEntity that you wish to refresh the inventory for.
 */
public void refreshInventory(HumanEntity holder) {
    holder.closeInventory();
    holder.openInventory(getInventory());
}