Java Code Examples for org.bukkit.inventory.InventoryView#getInventory()

The following examples show how to use org.bukkit.inventory.InventoryView#getInventory() . 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: GuiListener.java    From IF with The Unlicense 5 votes vote down vote up
/**
 * Handles clicks in inventories
 *
 * @param event the event fired
 * @since 0.5.4
 */
@EventHandler(ignoreCancelled = true)
public void onInventoryClick(@NotNull InventoryClickEvent event) {
    if (!(event.getInventory().getHolder() instanceof Gui)) {
        return;
    }

    Gui gui = (Gui) event.getInventory().getHolder();
    InventoryView view = event.getView();
    Inventory inventory = view.getInventory(event.getRawSlot());

    if (inventory == null) {
        gui.callOnOutsideClick(event);
        return;
    }

    gui.callOnGlobalClick(event);
    if (inventory.equals(view.getTopInventory())) {
        gui.callOnTopClick(event);
    } else {
        gui.callOnBottomClick(event);
    }

    if ((inventory.equals(view.getBottomInventory()) && gui.getState() == Gui.State.TOP) ||
        event.getCurrentItem() == null) {
        return;
    }

    List<Pane> panes = gui.getPanes();

    //loop through the panes reverse, because the pane with the highest priority (last in list) is most likely to have the correct item
    for (int i = panes.size() - 1; i >= 0; i--) {
        if (panes.get(i).click(gui, event, 0, 0, 9, gui.getRows() + 4))
            break;
    }
}
 
Example 2
Source File: MasonryPane.java    From IF with The Unlicense 5 votes vote down vote up
@Override
public boolean click(@NotNull Gui gui, @NotNull InventoryClickEvent event, int paneOffsetX, int paneOffsetY,
                     int maxLength, int maxHeight) {
    int length = Math.min(this.length, maxLength);
    int height = Math.min(this.height, maxHeight);

    int slot = event.getSlot();
    InventoryView view = event.getView();
    Inventory inventory = view.getInventory(event.getRawSlot());

    int x, y;

    if (inventory != null && inventory.equals(view.getBottomInventory())) {
        x = (slot % 9) - getX() - paneOffsetX;
        y = ((slot / 9) + gui.getRows() - 1) - getY() - paneOffsetY;

        if (slot / 9 == 0) {
            y = (gui.getRows() + 3) - getY() - paneOffsetY;
        }
    } else {
        x = (slot % 9) - getX() - paneOffsetX;
        y = (slot / 9) - getY() - paneOffsetY;
    }

    if (x < 0 || x >= length || y < 0 || y >= height)
        return false;

    callOnClick(event);

    boolean success = false;

    for (Pane pane : panes) {
        success = success || pane.click(gui, event, paneOffsetX + getX(),
            paneOffsetY + getY(), length, height);
    }

    return success;
}
 
Example 3
Source File: PercentageBar.java    From IF with The Unlicense 5 votes vote down vote up
@Override
public boolean click(@NotNull Gui gui, @NotNull InventoryClickEvent event, int paneOffsetX, int paneOffsetY,
                     int maxLength, int maxHeight) {
    int length = Math.min(this.length, maxLength);
    int height = Math.min(this.height, maxHeight);

    int slot = event.getSlot();
    InventoryView view = event.getView();
    Inventory inventory = view.getInventory(event.getRawSlot());

    int x, y;

    if (inventory != null && inventory.equals(view.getBottomInventory())) {
        x = (slot % 9) - getX() - paneOffsetX;
        y = ((slot / 9) + gui.getRows() - 1) - getY() - paneOffsetY;

        if (slot / 9 == 0) {
            y = (gui.getRows() + 3) - getY() - paneOffsetY;
        }
    } else {
        x = (slot % 9) - getX() - paneOffsetX;
        y = (slot / 9) - getY() - paneOffsetY;
    }

    if (x < 0 || x >= length || y < 0 || y >= height) {
        return false;
    }

    callOnClick(event);

    event.setCancelled(true);

    int newPaneOffsetX = paneOffsetX + getX();
    int newPaneOffsetY = paneOffsetY + getY();

    return this.fillPane.click(gui, event, newPaneOffsetX, newPaneOffsetY, length, height) ||
        this.backgroundPane.click(gui, event, newPaneOffsetX, newPaneOffsetY, length, height);
}
 
Example 4
Source File: PaginatedPane.java    From IF with The Unlicense 4 votes vote down vote up
@Override
  public boolean click(@NotNull Gui gui, @NotNull InventoryClickEvent event, int paneOffsetX, int paneOffsetY, int maxLength,
                       int maxHeight) {
      int length = Math.min(this.length, maxLength);
      int height = Math.min(this.height, maxHeight);

      int slot = event.getSlot();
      InventoryView view = event.getView();
      Inventory inventory = view.getInventory(event.getRawSlot());

      int x, y;

      if (inventory != null && inventory.equals(view.getBottomInventory())) {
          x = (slot % 9) - getX() - paneOffsetX;
          y = ((slot / 9) + gui.getRows() - 1) - getY() - paneOffsetY;

          if (slot / 9 == 0) {
              y = (gui.getRows() + 3) - getY() - paneOffsetY;
          }
      } else {
          x = (slot % 9) - getX() - paneOffsetX;
          y = (slot / 9) - getY() - paneOffsetY;
      }

      //this isn't our item
      if (x < 0 || x >= length || y < 0 || y >= height) {
          return false;
      }

callOnClick(event);

      List<Pane> panes = this.panes.get(page);

      if (panes == null) {
          return false;
      }

      boolean success = false;

      for (Pane pane : panes) {
          success = success || pane.click(gui, event, paneOffsetX + getX(),
              paneOffsetY + getY(), length, height);
      }

      return success;
  }
 
Example 5
Source File: StaticPane.java    From IF with The Unlicense 4 votes vote down vote up
@Override
public boolean click(@NotNull Gui gui, @NotNull InventoryClickEvent event, int paneOffsetX, int paneOffsetY,
                        int maxLength, int maxHeight) {
	int length = Math.min(this.length, maxLength);
	int height = Math.min(this.height, maxHeight);

	int slot = event.getSlot();
       InventoryView view = event.getView();
       Inventory inventory = view.getInventory(event.getRawSlot());

       int x, y;

       if (inventory != null && inventory.equals(view.getBottomInventory())) {
           x = (slot % 9) - getX() - paneOffsetX;
           y = ((slot / 9) + gui.getRows() - 1) - getY() - paneOffsetY;

           if (slot / 9 == 0) {
               y = (gui.getRows() + 3) - getY() - paneOffsetY;
           }
       } else {
           x = (slot % 9) - getX() - paneOffsetX;
           y = (slot / 9) - getY() - paneOffsetY;
       }

	//this isn't our item
	if (x < 0 || x >= length || y < 0 || y >= height)
		return false;

	callOnClick(event);

       ItemStack itemStack = event.getCurrentItem();

       if (itemStack == null) {
           return false;
       }

       GuiItem clickedItem = findMatchingItem(items.values(), itemStack);

       if (clickedItem == null) {
           return false;
       }

       clickedItem.callAction(event);

       return true;
}
 
Example 6
Source File: OutlinePane.java    From IF with The Unlicense 4 votes vote down vote up
@Override
public boolean click(@NotNull Gui gui, @NotNull InventoryClickEvent event, int paneOffsetX, int paneOffsetY,
                     int maxLength, int maxHeight) {
    int length = Math.min(this.length, maxLength);
    int height = Math.min(this.height, maxHeight);

    int slot = event.getSlot();
    InventoryView inventoryView = event.getView();
    Inventory inventory = inventoryView.getInventory(event.getRawSlot());

    int x, y;

    if (inventory != null && inventory.equals(inventoryView.getBottomInventory())) {
        x = (slot % 9) - getX() - paneOffsetX;
        y = ((slot / 9) + gui.getRows() - 1) - getY() - paneOffsetY;

        if (slot / 9 == 0) {
            y = (gui.getRows() + 3) - getY() - paneOffsetY;
        }
    } else {
        x = (slot % 9) - getX() - paneOffsetX;
        y = (slot / 9) - getY() - paneOffsetY;
    }

    //this isn't our item
    if (x < 0 || x >= length || y < 0 || y >= height)
        return false;

    callOnClick(event);

    ItemStack itemStack = event.getCurrentItem();

    if (itemStack == null) {
        return false;
    }

    GuiItem item = findMatchingItem(items, itemStack);

    if (item == null) {
        return false;
    }

    item.callAction(event);

    return true;
}
 
Example 7
Source File: Slider.java    From IF with The Unlicense 4 votes vote down vote up
@Override
public boolean click(@NotNull Gui gui, @NotNull InventoryClickEvent event, int paneOffsetX, int paneOffsetY,
                     int maxLength, int maxHeight) {
    int length = Math.min(this.length, maxLength);
    int height = Math.min(this.height, maxHeight);

    int slot = event.getSlot();
    InventoryView view = event.getView();
    Inventory inventory = view.getInventory(event.getRawSlot());

    int x, y;

    if (inventory != null && inventory.equals(view.getBottomInventory())) {
        x = (slot % 9) - getX() - paneOffsetX;
        y = ((slot / 9) + gui.getRows() - 1) - getY() - paneOffsetY;

        if (slot / 9 == 0) {
            y = (gui.getRows() + 3) - getY() - paneOffsetY;
        }
    } else {
        x = (slot % 9) - getX() - paneOffsetX;
        y = (slot / 9) - getY() - paneOffsetY;
    }

    if (x < 0 || x >= length || y < 0 || y >= height) {
        return false;
    }

    callOnClick(event);

    int newPaneOffsetX = paneOffsetX + getX();
    int newPaneOffsetY = paneOffsetY + getY();

    boolean success = this.fillPane.click(gui, event, newPaneOffsetX, newPaneOffsetY, length, height) ||
        this.backgroundPane.click(gui, event, newPaneOffsetX, newPaneOffsetY, length, height);

    if (orientation == Orientation.HORIZONTAL) {
        setValue((float) (x + 1) / length);
    } else if (orientation == Orientation.VERTICAL) {
        setValue((float) (y + 1) / height);
    } else {
        throw new UnsupportedOperationException("Unknown orientation");
    }

    gui.update();

    return success;
}
 
Example 8
Source File: CycleButton.java    From IF with The Unlicense 4 votes vote down vote up
@Override
public boolean click(@NotNull Gui gui, @NotNull InventoryClickEvent event, int paneOffsetX, int paneOffsetY,
                     int maxLength, int maxHeight) {
    int length = Math.min(this.length, maxLength);
    int height = Math.min(this.height, maxHeight);

    int slot = event.getSlot();
    InventoryView view = event.getView();
    Inventory inventory = view.getInventory(event.getRawSlot());

    int x, y;

    if (inventory != null && inventory.equals(view.getBottomInventory())) {
        x = (slot % 9) - getX() - paneOffsetX;
        y = ((slot / 9) + gui.getRows() - 1) - getY() - paneOffsetY;

        if (slot / 9 == 0) {
            y = (gui.getRows() + 3) - getY() - paneOffsetY;
        }
    } else {
        x = (slot % 9) - getX() - paneOffsetX;
        y = (slot / 9) - getY() - paneOffsetY;
    }

    //this isn't our item
    if (x < 0 || x >= length || y < 0 || y >= height) {
        return false;
    }

    callOnClick(event);

    panes.get(position).click(gui, event, paneOffsetX + x, paneOffsetY + y, length, height);

    position++;

    if (position == panes.size()) {
        position = 0;
    }

    gui.update();

    return true;
}
 
Example 9
Source File: ToggleButton.java    From IF with The Unlicense 4 votes vote down vote up
@Override
public boolean click(@NotNull Gui gui, @NotNull InventoryClickEvent event, int paneOffsetX, int paneOffsetY,
                     int maxLength, int maxHeight) {
    int length = Math.min(this.length, maxLength);
    int height = Math.min(this.height, maxHeight);

    int slot = event.getSlot();
    InventoryView view = event.getView();
    Inventory inventory = view.getInventory(event.getRawSlot());

    int x, y;

    if (inventory != null && inventory.equals(view.getBottomInventory())) {
        x = (slot % 9) - getX() - paneOffsetX;
        y = ((slot / 9) + gui.getRows() - 1) - getY() - paneOffsetY;

        if (slot / 9 == 0) {
            y = (gui.getRows() + 3) - getY() - paneOffsetY;
        }
    } else {
        x = (slot % 9) - getX() - paneOffsetX;
        y = (slot / 9) - getY() - paneOffsetY;
    }

    //this isn't our item
    if (x < 0 || x >= length || y < 0 || y >= height) {
        return false;
    }

    callOnClick(event);

    int newX = paneOffsetX + x;
    int newY = paneOffsetY + y;

    if (enabled) {
        enabledPane.click(gui, event, newX, newY, length, height);
    } else {
        disabledPane.click(gui, event, newX, newY, length, height);
    }

    toggle();

    gui.update();

    return true;
}