public static void debug(InventoryClickEvent event) {
   System.out.println("===== DEBUG START =====");
   System.out.println("event.getAction() " + event.getAction());
   System.out.println("event.isLeftClick() " + event.isLeftClick());
   System.out.println("event.isRightClick() " + event.isRightClick());
   System.out.println("event.isShiftClick() " + event.isShiftClick());
   System.out.println("event.getClick() " + event.getClick());
   System.out.println("event.getCurrentItem() " + event.getCurrentItem());
   System.out.println("event.getCursor() " + event.getCursor());
   System.out.println("event.getHotbarButton() " + event.getHotbarButton());
   System.out.println("getInventory().getType() " + event.getInventory().getType());
   System.out.println("event.getRawSlot() " + event.getRawSlot());
   System.out.println("event.getResult() " + event.getResult());
   System.out.println("event.getSlot() " + event.getSlot());
   System.out.println("event.getSlotType() " + event.getSlotType());
   System.out.println(
       "getView().getTopInventory().getType() " + event.getView().getTopInventory().getType());
   System.out.println("getView().getType() " + event.getView().getType());
   System.out.println(
       "getView().getBottomInventory().getType() "
           + event.getView().getBottomInventory().getType());
   System.out.println("event.getWhoClicked() " + event.getWhoClicked());
   System.out.println("-----");
   System.out.println("isOutside(event) " + isOutside(event));
   System.out.println("isTopInventory(event) " + isTopInventory(event));
   System.out.println("isBottomInventory(event) " + isBottomInventory(event));
   System.out.println("getAlter(event) " + getAlter(event));
   System.out.println("isAltering(event) " + isAltering(event));
   System.out.println("isEquipping(event) " + isEquipping(event));
   System.out.println("===== DEBUG END =====");
 }
  /**
   * Handles attribute menu interaction
   *
   * @param event event details
   */
  @EventHandler
  public void onClick(InventoryClickEvent event) {
    // Class selection
    if (InventoryManager.isMatching(event.getInventory(), MENU_KEY)) {
      // Do nothing when clicking outside the inventory
      if (event.getSlot() == -999) {
        return;
      }

      boolean top = event.getRawSlot() < event.getView().getTopInventory().getSize();
      AttributeManager manager = SkillAPI.getAttributeManager();

      // Interact with the skill tree when clicking in the top region
      if (top) {
        if (event.getSlot() < manager.getKeys().size() || event.getCursor() != null) {
          event.setCancelled(true);

          PlayerData data = SkillAPI.getPlayerData((Player) event.getWhoClicked());
          if (event.isRightClick() && SkillAPI.getSettings().isAttributesDowngrade()) {
            data.refundAttribute(manager.getKeys().toArray()[event.getSlot()].toString());
          } else if (event.isLeftClick()) {

            Object[] keys = manager.getKeys().toArray();
            data.upAttribute(keys[event.getSlot()].toString());
          }
          data.openAttributeMenu();
        }
      }

      // Do not allow shift clicking items into the inventory
      else if (event.isShiftClick()) {
        event.setCancelled(true);
      }
    }
  }
Beispiel #3
0
 @EventHandler(ignoreCancelled = true, priority = EventPriority.HIGHEST)
 public void onInventoryClick(InventoryClickEvent e) {
   if (useLocaleInv && e.getView() instanceof LocaleInventory) {
     LocaleInventory inv = (LocaleInventory) e.getView();
     InventoryClickEvent clickEvent =
         new InventoryClickEvent(
             inv.getView(), e.getSlotType(), e.getRawSlot(), e.isRightClick(), e.isShiftClick());
     Bukkit.getServer().getPluginManager().callEvent(clickEvent);
     if (clickEvent.isCancelled()) {
       e.setCancelled(true);
     } else {
       switch (clickEvent.getResult()) {
         case DEFAULT: // Can't really do this with current events
         case ALLOW:
           System.out.println("ok...");
           System.out.println(inv.getView().getItem(e.getRawSlot()));
           inv.getView().setItem(e.getRawSlot(), clickEvent.getCursor());
           System.out.println(inv.getView().getItem(e.getRawSlot()));
           break;
         case DENY:
           break;
       }
     }
     for (LocaleInventory localeInv : localeInventories) {
       if (localeInv != inv) localeInv.reload();
     }
   }
 }
 @Override
 public void onClicked(InventoryClickEvent event) {
   int newValue = value;
   if (event.isLeftClick()) {
     newValue -= event.isShiftClick() ? altIncr : incr;
   } else if (event.isRightClick()) {
     newValue += event.isShiftClick() ? altIncr : incr;
   }
   newValue = Math.max(Math.min(newValue, range.getMaximumInteger()), range.getMinimumInteger());
   if (newValue != value && callback.run(newValue)) {
     value = newValue;
     event.setCurrentItem(getTexture());
   } else {
     // vetoed by the block!
     if (event.getWhoClicked() instanceof Player) {
       STBUtil.complain((Player) event.getWhoClicked());
     }
   }
 }
Beispiel #5
0
  @EventHandler(priority = EventPriority.LOWEST)
  public void onMenuItemClicked(InventoryClickEvent event) {
    Inventory inventory = event.getInventory();

    if (inventory.getHolder() instanceof InventoryMenu) {
      InventoryMenu menu = (InventoryMenu) inventory.getHolder();

      if (event.getWhoClicked() instanceof Player) {
        Player player = (Player) event.getWhoClicked();
        int index = event.getRawSlot();

        if (index >= 0 && index < inventory.getSize()) {
          menu.selectItem(player, index, event.isRightClick(), event.isShiftClick());
        }
      }

      event.setCancelled(true);
    }
  }
Beispiel #6
0
  /**
   * Price managing for manager stock, this allows you to change prices for all items in your
   * traders stock
   *
   * @param e
   */
  @ClickHandler(
      status = {tNpcStatus.MANAGE_PRICE},
      inventory = InventoryType.TRADER)
  public void managePrices(InventoryClickEvent e) {
    // debug info
    dB.info("Price managing click event");

    // select the item that should have the price changed
    if (selectAndCheckItem(e.getSlot())) {
      // show the current price in chat, if cursor is AIR
      if (e.getCursor().getTypeId() == 0) {
        // sends the message
        locale.sendMessage(
            player, "key-value", "key", "#price", "value", getSelectedItem().getPriceFormated());
      } else {
        // adds the price attribute to the item
        Price price = getSelectedItem().getPriceAttr();

        // adds value to the current price
        if (e.isLeftClick()) {
          // increases the price using specialBlockValue*cursorAmount
          price.increase(Settings.getBlockValue(e.getCursor()) * e.getCursor().getAmount());

          // sends a message
          locale.sendMessage(
              player, "key-change", "key", "#price", "value", getSelectedItem().getPriceFormated());
        } else
        // remove value from the current price
        if (e.isRightClick()) {
          // decreases the price using specialBlockValue*cursorAmount
          price.decrease(Settings.getBlockValue(e.getCursor()) * e.getCursor().getAmount());

          // sends a message
          locale.sendMessage(
              player, "key-change", "key", "#price", "value", getSelectedItem().getPriceFormated());
        }
      }
    }
    e.setCancelled(true);
  }
 @Override
 public void onClick(Player player, InventoryClickEvent event) {
   if (event.getCurrentItem() != null && !event.getCurrentItem().getType().equals(Material.AIR)) {
     if (event.getRawSlot() <= event.getSlot()) {
       int slot = event.getSlot();
       PlayerShopOffer offer = shop.getOffers().get(slot);
       if (offer != null) {
         if (event.isLeftClick()) {
           if (player.getName().equalsIgnoreCase(shop.getOwnerName())) {
             handleOfferEdit(player, event, offer);
           } else {
             handleTrade(player, event, offer);
           }
         } else if (event.isRightClick()) {
           if (getSession().getPermissionsProvider().has(player, ASPermissionKey.MANAGER)) {
             handleOfferEdit(player, event, offer);
           }
         }
       }
     }
   }
 }