Example #1
0
 @SuppressWarnings("deprecation")
 @EventHandler
 public void click(InventoryClickEvent event) {
   Player player = (Player) event.getView().getPlayer();
   OpenQuestLog oql = getOpenQuestLog(player);
   if (oql == null) return;
   event.setCancelled(true);
   if (event.getView() != oql.getInventoryView()) {
     player.updateInventory();
     return;
   }
   if (event.getCurrentItem() == null) {
     player.updateInventory();
     return;
   }
   Quest sel = oql.getSelected();
   if (sel == null) {
     if (event.getSlot() == 27) {
       oql.setViewingCompleted(!oql.isViewingCompleted());
       oql.update();
     } else {
       int index = (oql.getPage() - 1) * 27 + event.getSlot();
       Quest[] q =
           oql.isViewingCompleted() ? oql.getCurrentCompletedList() : oql.getCurrentQuestList();
       if (index < q.length) {
         oql.setSelected(q[index]);
         oql.update();
       }
     }
   } else if (event.getSlot() == 27) {
     oql.setSelected(null);
     oql.update();
   }
   player.updateInventory();
 }
  /**
   * 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);
      }
    }
  }
Example #3
0
 @EventHandler(priority = EventPriority.HIGHEST)
 private void preventArmor(InventoryClickEvent evt) {
   // plugin.getLogger().info(evt.getView().getType().getDefaultTitle());
   if (evt.getView().getType() == InventoryType.CRAFTING) {
     // plugin.getLogger().info("inventory click " + evt.getSlot());
     if (evt.getSlot() == 39
         || evt.getSlot() == 38
         || evt.getSlot() == 37
         || evt.getSlot() == 36) {
       evt.setCancelled(true);
     }
   }
 }
  @EventHandler
  public void onInterfaceInteract(InventoryClickEvent event) {
    if (event.getView() != this) return;

    ItemStack itemClicked = event.getCurrentItem();
    if (itemClicked == null || itemClicked.getType() == Material.AIR) return;

    event.setCancelled(true);

    // If not right or left-click.
    if (!(event.getClick() == ClickType.RIGHT || event.getClick() == ClickType.LEFT)) return;

    if (this.ACCEPT_OBJECT.equals(itemClicked)) {
      onAcceptPressed();
      return;
    }

    if (this.BACK_OBJECT.equals(itemClicked)) {
      if (onBackPressed()) scheduleCloseOfInventory();
      return;
    }

    int rawSlot = event.getRawSlot();
    int slotNumber = event.getSlot();
    boolean usedTopInv = rawSlot < getTopInventory().getSize();

    if (usedTopInv) onSelectionItemPressed(slotNumber, itemClicked);
    else onControlItemPressed(slotNumber, itemClicked);
  }
Example #5
0
 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 =====");
 }
Example #6
0
  @ClickHandler(
      status = {tNpcStatus.SELL_AMOUNTS},
      inventory = InventoryType.TRADER)
  public void sellAmountsItems(InventoryClickEvent e) {
    e.setCancelled(true);
    // check permission
    if (!perms.has(player, "dtl.trader.sell")) return;

    int slot = e.getSlot();
    if (stock.isUiSlot(slot)) return;

    if (checkItemAmount(slot)) {
      if (handleClick(e.getRawSlot())) {
        if (!inventoryHasPlace(slot)) {
          // send message
          locale.sendMessage(player, "trader-transaction-failed-inventory");
        } else if (!sellTransaction(slot)) {
          // send message
          locale.sendMessage(player, "trader-transaction-failed-player-money");
        } else {
          addToInventory(slot);

          // send message
          locale.sendMessage(
              player,
              "trader-transaction-success",
              "trader",
              getNPC().getName(),
              "player",
              player.getName(),
              "action",
              "#bought",
              "item",
              getSelectedItem().getName(),
              "amount",
              String.valueOf(getSelectedItem().getAmount()),
              "price",
              String.format("%.2f", stock.parsePrice(getSelectedItem(), slot)).replace(',', '.'));

          // update inventory - lore
          updatePlayerInventory();
        }
      } else {
        // informations about the item some1 wants to buy
        locale.sendMessage(
            player,
            "trader-transaction-item",
            "item",
            getSelectedItem().getName(),
            "amount",
            String.valueOf(getSelectedItem().getAmount()),
            "price",
            String.format("%.2f", stock.parsePrice(getSelectedItem(), slot)).replace(',', '.'));
      }
    }
  }
 @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);
           }
         }
       }
     }
   }
 }
 @SuppressWarnings("deprecation")
 @EventHandler(priority = EventPriority.LOWEST)
 public void onFurnaceInsert(InventoryClickEvent e) {
   if (e.getInventory().getType() == InventoryType.FURNACE
       && e.getCursor() != null
       && (e.getRawSlot() == 0 || e.getSlot() == 1)) {
     if (!e.isShiftClick()) {
       ItemStack item = e.getCurrentItem();
       e.setCurrentItem(e.getCursor());
       e.setCursor(item);
       e.setCancelled(true);
       PlayerInventory.update((Player) e.getWhoClicked());
     }
   }
 }
Example #9
0
 @EventHandler
 protected static void onInventoryClickEvent(InventoryClickEvent event) {
   if (event.getInventory().getName().equals(GUI_NAME)) {
     event.setCancelled(true);
     Player clicker = (Player) event.getWhoClicked();
     ItemStack button = event.getClickedInventory().getItem(event.getSlot());
     if (button.getType() == Material.REDSTONE_BLOCK)
       clicker.sendMessage(ChatColor.RED + "Error! This lobby is inactive at the moment!");
     else {
       int lobbyID = Integer.parseInt(button.getItemMeta().getDisplayName().replace("Lobby ", ""));
       Lobby lobby = Lobby.getLobbies().get(lobbyID - 1);
       clicker.sendMessage(ChatColor.GREEN + "Joining lobby " + lobbyID + "...");
       lobby.join(clicker);
     }
   }
 }
Example #10
0
 @ClickHandler(
     status = {
       tNpcStatus.SELL,
       tNpcStatus.BUY,
       tNpcStatus.SELL_AMOUNTS,
       tNpcStatus.MANAGE_SELL,
       tNpcStatus.MANAGE_BUY,
       tNpcStatus.MANAGE_AMOUNTS,
       tNpcStatus.MANAGE_PRICE,
       tNpcStatus.MANAGE_LIMIT
     },
     shift = true,
     inventory = InventoryType.PLAYER)
 public void botDebug(InventoryClickEvent e) {
   // debug info
   dB.info("Inventory click, by: ", player.getName(), ", status: ", status.name().toLowerCase());
   dB.info("slot: ", e.getSlot(), ", left: ", e.isLeftClick(), ", shift: ", e.isShiftClick());
 }
Example #11
0
  @ClickHandler(
      status = {tNpcStatus.SELL, tNpcStatus.BUY, tNpcStatus.SELL_AMOUNTS},
      inventory = InventoryType.TRADER)
  public void generalUI(InventoryClickEvent e) {
    // debug info
    dB.info("General UI checking");

    int slot = e.getSlot();
    if (stock.isUiSlot(slot)) {
      // debug info
      dB.info("Hit tests");

      if (hitTest(slot, "buy")) {
        // debug low
        dB.low("Buy stock hit test");

        // send message
        locale.sendMessage(player, "trader-stock-toggled", "stock", "#stock-buy");

        // change status
        parseStatus(tNpcStatus.BUY);
      } else if (hitTest(slot, "sell")) {
        // debug low
        dB.low("Sell stock hit test");

        // send message
        locale.sendMessage(player, "trader-stock-toggled", "stock", "#stock-sell");

        // change status
        parseStatus(tNpcStatus.SELL);
      } else if (hitTest(slot, "back")) {
        // debug low
        dB.low("Babck to stock hit test");

        // send message
        locale.sendMessage(player, "trader-stock-back");

        // change status
        parseStatus(tNpcStatus.SELL);
      }
      stock.setInventory(inventory, getStatus());
    }
    e.setCancelled(true);
  }
Example #12
0
 @Override
 public boolean onClick(InventoryClickEvent event) {
   if (event.getInventory() == null
       || event.getInventory().getTitle() == null
       || !stripFormatting(event.getInventory().getTitle())
           .contains(stripFormatting(getTitle()))) {
     return false;
   }
   if (event.getSlotType() != InventoryType.SlotType.CONTAINER) {
     return true;
   }
   Player player = (Player) event.getWhoClicked();
   Inventory menu = event.getInventory();
   ItemStack returnItem = menu.getItem(getIndex(5, 0));
   String configName = returnItem.getItemMeta().getLore().get(0);
   String path = returnItem.getItemMeta().getLore().get(1);
   int page = getPage(returnItem.getItemMeta().getLore().get(2));
   int slot = event.getSlot();
   int row = slot / 9;
   int col = slot % 9;
   ItemStack clickedItem = event.getCurrentItem();
   if (slot >= getIndex(3, 0) && slot <= getIndex(3, 8)) {
     // increment buttons
     YmlConfiguration config = FileUtil.getYmlConfiguration(configName);
     int value = config.getInt(path, 0);
     int increment = getDisplayNameAsInt(clickedItem);
     if (event.getClick() == ClickType.LEFT) {
       value += increment;
     } else if (event.getClick() == ClickType.RIGHT) {
       value = increment;
     }
     config.set(path, value);
     config.set("dirty", true);
   }
   if (slot != getIndex(5, 0)) {
     player.openInventory(createEditMenu(configName, path, page));
   } else {
     player.openInventory(parent.createEditMenu(configName, path, page));
   }
   return true;
 }
Example #13
0
  @ClickHandler(
      status = {tNpcStatus.MANAGE_SELL, tNpcStatus.MANAGE_BUY},
      inventory = InventoryType.TRADER,
      shift = true)
  public void itemsAttribs(InventoryClickEvent e) {
    // debug info
    dB.info("Item managing click event");

    // select the item that should have the price changed
    if (selectAndCheckItem(e.getSlot())) {
      if (e.isShiftClick()) {
        if (e.isLeftClick()) {
          stock.setAmountsInventory(inventory, status, getSelectedItem());
          parseStatus(tNpcStatus.MANAGE_AMOUNTS);
        } else // if it's a shift rightclick
        {

        }
      } else // no shift click
      {
        if (e.isLeftClick()) {
          if (getSelectedItem().hasFlag(StackPrice.class))
            getSelectedItem().removeFlag(StackPrice.class);
          else getSelectedItem().addFlag(".sp");

          locale.sendMessage(
              player,
              "key-change",
              "key",
              "#stack-price",
              "value",
              String.valueOf(getSelectedItem().hasFlag(StackPrice.class)));
        } else // if it's a shift rightclick
        {

        }
      }
    }
    e.setCancelled(true);
  }
Example #14
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);
  }
Example #15
0
  @EventHandler
  public void on(InventoryClickEvent event) {
    if (!(event.getWhoClicked() instanceof Player)) {
      return;
    }
    Player player = (Player) event.getWhoClicked();
    if (this.hasOpen(player)) {
      int slot = event.getSlot();
      if (slot >= this.getSize()) {
        return;
      }

      event.setCancelled(true);
      getComponent(slot)
          .ifPresent(
              component -> {
                Position pos = this.components.get(component);
                Position xy = Position.toPosition(this, slot);
                component.onClick(player, event.getClick(), xy.x - pos.x, xy.y - pos.y);
              });
    }
  }
  @EventHandler
  public void onClickInventory(InventoryClickEvent ev) {
    if (ev.getInventory().getType() == InventoryType.HOPPER
        && ev.getInventory().getTitle().equalsIgnoreCase("Network Creator")) {
      if (ev.getCurrentItem() == null) {
        return;
      }
      if (ev.isShiftClick()) {
        ev.setCancelled(true);
        return;
      }
      if ((ev.getSlot() == 0 || ev.getSlot() == 1)
          && !CardNetworkListener.isModifier(ev.getCursor())
          && ev.getCursor().getType() != Material.AIR) {
        ev.setCancelled(true);
        return;
      }
      if (ev.getSlot() == 3
          && !pl.isCardNetwork(ev.getCursor())
          && ev.getCursor().getType() != Material.AIR) {
        ev.setCancelled(true);
        return;
      }

      Player p = (Player) ev.getWhoClicked();
      Inventory inv = ev.getInventory();

      if (ev.getCurrentItem().getType() == Material.ENDER_PORTAL_FRAME
          && ev.getCurrentItem().hasItemMeta()
          && ev.getCurrentItem().getItemMeta().hasDisplayName()
          && ev.getCurrentItem().getItemMeta().getDisplayName().equalsIgnoreCase("§rDéassablage")) {
        ev.setCancelled(true);

        List<String> lore = ev.getCurrentItem().getItemMeta().getLore();
        String[] cs = lore.get(0).split("/");

        Block b =
            new Location(
                    ev.getWhoClicked().getWorld(),
                    Integer.parseInt(cs[0]),
                    Integer.parseInt(cs[1]),
                    Integer.parseInt(cs[2]))
                .getBlock();

        b.setType(Material.AIR);
        pl.bs.remove(b);
        b.getWorld().dropItemNaturally(b.getLocation(), pl.nc);

        p.closeInventory();

        return;
      }

      if (ev.getSlot() == 2
          && ev.getCurrentItem().getType() == Material.STAINED_GLASS_PANE
          && ev.getCurrentItem().getDurability() == 15
          && ev.getCurrentItem().hasItemMeta()
          && ev.getCurrentItem().getItemMeta().hasDisplayName()
          && ev.getCurrentItem().getItemMeta().getDisplayName().equalsIgnoreCase("§r--->")) {
        ev.setCancelled(true);

        if (inv.getItem(0) == null && inv.getItem(1) == null && inv.getItem(3) == null) return;
        if (CardNetworkListener.whatNetwork(inv.getItem(3)) != null) return;

        ItemStack item;
        ItemStack m1 = inv.getItem(0);
        ItemStack m2 = inv.getItem(1);

        if (m1 != null || m2 != null) {
          item = inv.getItem(3);
          ItemMeta im = item.getItemMeta();
          List<String> lore = im.getLore();

          lore.add(" ");
          lore.add(ChatColor.GRAY + "Modifier :");

          if (m1 != null) {
            lore.add(ChatColor.GRAY + "- " + CardNetworkListener.whatModifier(m1));
            inv.setItem(0, new ItemStack(Material.AIR));
          }
          if (m2 != null && !m2.isSimilar(m1)) {
            lore.add(ChatColor.GRAY + "- " + CardNetworkListener.whatModifier(m2));
            inv.setItem(1, new ItemStack(Material.AIR));
          }

          im.setLore(lore);
          item.setItemMeta(im);

          inv.setItem(3, item);
        }

        p.playSound(p.getLocation(), Sound.WOOD_CLICK, 1, 1);

        Inventory icn = pl.getServer().createInventory(null, InventoryType.HOPPER, "NC");
        icn.setContents(inv.getContents());
        inv.clear();

        new ChatInventory(pl, p, null, ChatEtat.CREATE_NETWORK, icn);
        p.closeInventory();

        p.sendMessage(ChatColor.GRAY + "Entré le nom du réseau");

        return;
      }
    }
  }
Example #17
0
  @ClickHandler(
      status = {tNpcStatus.SELL, tNpcStatus.BUY},
      inventory = InventoryType.PLAYER)
  public void buyItems(InventoryClickEvent e) {
    e.setCancelled(true);
    // check permission
    if (!perms.has(player, "dtl.trader.buy")) return;

    clearSelection();
    int slot = e.getSlot();
    if (e.isLeftClick()) {
      if (selectAndCheckItem(e.getCurrentItem(), "buy")) {
        int scale = e.getCurrentItem().getAmount() / getSelectedItem().getAmount();
        if (scale == 0) return;

        if (handleClick(e.getRawSlot())) {
          if (!buyTransaction(scale)) {
            // send message
            locale.sendMessage(
                player,
                "trader-transaction-failed-trader-money",
                "npc",
                settings.getNPC().getName());
          } else {
            // remove the amount from inventory
            removeFromInventory(slot, scale);

            // send the transaction success message
            locale.sendMessage(
                player,
                "trader-transaction-success",
                "trader",
                getNPC().getName(),
                "player",
                player.getName(),
                "action",
                "#sold",
                "item",
                getSelectedItem().getName(),
                "amount",
                String.valueOf(getSelectedItem().getAmount() * scale),
                "price",
                String.valueOf(stock.parsePrice(getSelectedItem(), 0) * scale));

            // update the inventory lore
            updatePlayerInventory();
          }
        } else {
          // send the information message
          locale.sendMessage(
              player,
              "trader-transaction-item",
              "item",
              getSelectedItem().getName(),
              "amount",
              String.valueOf(getSelectedItem().getAmount()),
              "price",
              String.valueOf(stock.parsePrice(getSelectedItem(), 0)));
        }
      }
    } else {
      if (selectAndCheckItem(e.getCurrentItem(), "buy")) {
        int scale = e.getCurrentItem().getAmount() / getSelectedItem().getAmount();
        if (scale == 0) return;

        if (handleClick(e.getRawSlot())) {
          if (!buyTransaction()) {
            // send message
            locale.sendMessage(
                player,
                "trader-transaction-failed-trader-money",
                "npc",
                settings.getNPC().getName());
          } else {
            // remove the amount from inventory
            removeFromInventory(slot);

            // send the transaction success message
            locale.sendMessage(
                player,
                "trader-transaction-success",
                "trader",
                getNPC().getName(),
                "player",
                player.getName(),
                "action",
                "#sold",
                "item",
                getSelectedItem().getName(),
                "amount",
                String.valueOf(getSelectedItem().getAmount()),
                "price",
                String.valueOf(stock.parsePrice(getSelectedItem(), 0)));

            // update the inventory lore
            updatePlayerInventory();
          }
        } else {
          // send the information message
          locale.sendMessage(
              player,
              "trader-transaction-item",
              "item",
              getSelectedItem().getName(),
              "amount",
              String.valueOf(getSelectedItem().getAmount()),
              "price",
              String.valueOf(stock.parsePrice(getSelectedItem(), 0)));
        }
      }
    }
  }
Example #18
0
  @ClickHandler(
      status = {tNpcStatus.SELL},
      inventory = InventoryType.TRADER)
  public void sellItems(InventoryClickEvent e) {
    e.setCancelled(true);
    // check permission
    if (!perms.has(player, "dtl.trader.sell")) return;

    int slot = e.getSlot();
    if (stock.isUiSlot(slot)) return;

    if (e.isLeftClick()) {
      if (selectAndCheckItem(slot)) {
        if (getSelectedItem().hasMultipleAmounts()) {
          // send message
          locale.sendMessage(player, "trader-stock-toggled", "stock", "#stock-amounts");

          // change status
          status = tNpcStatus.SELL_AMOUNTS;
          stock.setAmountsInventory(inventory, status, getSelectedItem());
        } else if (handleClick(e.getRawSlot())) {
          if (!inventoryHasPlace()) {
            // send message
            locale.sendMessage(player, "trader-transaction-failed-inventory");
          } else if (!sellTransaction()) {
            // send message
            locale.sendMessage(player, "trader-transaction-failed-player-money");
          } else {
            addToInventory();

            // send message
            locale.sendMessage(
                player,
                "trader-transaction-success",
                "trader",
                getNPC().getName(),
                "player",
                player.getName(),
                "action",
                "#bought",
                "item",
                getSelectedItem().getName(),
                "amount",
                String.valueOf(getSelectedItem().getAmount()),
                "price",
                String.valueOf(getSelectedItem().getPrice()));

            // update inventory - lore
            updatePlayerInventory();
          }
        } else {
          // informations about the item some1 wants to buy
          locale.sendMessage(
              player,
              "trader-transaction-item",
              "item",
              getSelectedItem().getName(),
              "amount",
              String.valueOf(getSelectedItem().getAmount()),
              "price",
              String.valueOf(getSelectedItem().getPrice()));
        }
      }
    } else {
      if (selectAndCheckItem(slot)) {
        if (handleClick(e.getRawSlot())) {
          if (!inventoryHasPlace()) {
            // send message
            locale.sendMessage(player, "trader-transaction-failed-inventory");
          } else if (!sellTransaction()) {
            // send message
            locale.sendMessage(player, "trader-transaction-failed-player-money");
          } else {
            addToInventory();

            // send message
            locale.sendMessage(
                player,
                "trader-transaction-success",
                "trader",
                getNPC().getName(),
                "player",
                player.getName(),
                "action",
                "#bought",
                "item",
                getSelectedItem().getName(),
                "amount",
                String.valueOf(getSelectedItem().getAmount()),
                "price",
                String.valueOf(getSelectedItem().getPrice()));

            // update inventory - lore
            updatePlayerInventory();
          }
        } else {
          // informations about the item some1 wants to buy
          locale.sendMessage(
              player,
              "trader-transaction-item",
              "item",
              getSelectedItem().getName(),
              "amount",
              String.valueOf(getSelectedItem().getAmount()),
              "price",
              String.valueOf(getSelectedItem().getPrice()));
        }
      }
    }
  }
Example #19
0
  @EventHandler(priority = EventPriority.HIGHEST)
  public void inventoryMenu(final InventoryClickEvent event) {

    // -------Armor wear handling--------
    if (event.getSlotType() == SlotType.ARMOR && event.getClick() != ClickType.DOUBLE_CLICK) {
      CEventHandler.handleArmor(
          (Player) event.getWhoClicked(), event.getCurrentItem(), true, event);
      CEventHandler.handleArmor((Player) event.getWhoClicked(), event.getCursor(), false, event);
      if (event.getCursor() == null)
        CEventHandler.handleArmor(
            (Player) event.getWhoClicked(), event.getCurrentItem(), false, event);

    } else if (event.getClick() == ClickType.SHIFT_LEFT) {
      ItemStack current = event.getCurrentItem();
      String typeS = current.getType().toString();
      PlayerInventory inv = event.getWhoClicked().getInventory();
      if ((typeS.endsWith("HELMET") && inv.getHelmet() == null)
          || (typeS.endsWith("CHESTPLATE") && inv.getChestplate() == null)
          || (typeS.endsWith("LEGGINGS") && inv.getLeggings() == null)
          || (typeS.endsWith("BOOTS") && inv.getBoots() == null))
        CEventHandler.handleArmor(
            (Player) event.getWhoClicked(), event.getCurrentItem(), false, event);
    }
    // ---------------------------------

    if (event.getCurrentItem() == null
        || event.getCurrentItem().getType() == Material.AIR
        || event.getRawSlot() < -1) {
      return;
    }
    if (event.getView().getTopInventory().getTitle().startsWith("CE")) {
      Inventory topInv = event.getView().getTopInventory();
      final Player p = (Player) event.getWhoClicked();
      ItemStack clickedItem = event.getCurrentItem();
      event.setResult(Result.ALLOW);

      event.setCancelled(true);

      // This is the back-button, located in the very last spot of each inventory
      if ((event.getRawSlot() == topInv.getSize() - 1)
          && event.getCurrentItem().getType() != Material.AIR) {
        p.closeInventory();
        p.openInventory(Tools.getPreviousInventory(topInv.getTitle()));
        return;
      }

      if (event.getRawSlot() < topInv.getSize()) {

        // Opens the clicked Enchantments inventory and loads the permissions if needed
        if (topInv.getTitle().equals(Tools.prefix + "Enchantments")) {
          p.closeInventory();
          p.openInventory(Tools.getEnchantmentMenu(p, clickedItem.getItemMeta().getDisplayName()));
          return;
        }

        // Opens the item inventory and loads the permissions if needed
        if (topInv.getTitle().equals(Tools.prefix + "Main Menu") && event.getRawSlot() == 4) {
          p.closeInventory();
          p.openInventory(Tools.getItemMenu(p));
          return;
        }

        // These are the specific menus, clicking one of them will lead to the enchanting menu,
        // which needs to be 'notified' of the enchantment to give and it's cost
        if (topInv.getTitle().equals(Tools.prefix + "Global")
            || topInv.getTitle().equals(Tools.prefix + "Bow")
            || topInv.getTitle().equals(Tools.prefix + "Armor")
            || topInv.getTitle().equals(Tools.prefix + "Helmet")
            || topInv.getTitle().equals(Tools.prefix + "Boots")
            || topInv.getTitle().equals(Tools.prefix + "Tool"))
          if (p.isOp()
              || Tools.checkPermission(
                  Tools.getEnchantmentByDisplayname(clickedItem.getItemMeta().getDisplayName()),
                  p)) {
            Inventory enchantingMenu = Main.CEEnchantingMenu;
            enchantingMenu.setItem(0, clickedItem);
            p.closeInventory();
            p.openInventory(enchantingMenu);
            return;
          } else {
            p.sendMessage(
                ChatColor.RED + "[CE] You do not have permission to buy this Enchantment.");
            return;
          }

        // This opens the Item Creation Menu
        if (topInv.getTitle().equals(Tools.prefix + "Items"))
          if (p.isOp()
              || Tools.checkPermission(
                  Tools.getItemByDisplayname(clickedItem.getItemMeta().getDisplayName()), p)) {

            Inventory approveMenu = Main.CEApproveMenu;
            approveMenu.setItem(0, clickedItem);
            p.closeInventory();
            p.openInventory(approveMenu);
            return;
          } else {
            p.sendMessage(ChatColor.RED + "[CE] You do not have permission to buy this Item.");
            return;
          }
      }

      if (topInv.getTitle().equals(Tools.prefix + "Enchanting")
          || topInv.getTitle().equals(Tools.prefix + "Item Creation")) {
        double cost = 0;
        ItemStack item = clickedItem;
        ItemMeta im = item.getItemMeta();
        String type = "";
        String successString = "";
        Boolean itemSet = false; // TODO: Solve this by adding item-types
        // Swimsuit swimsuit = (Swimsuit) Main.items.get(9);

        if (topInv.getTitle().equals(Tools.prefix + "Enchanting")) {
          if (event.getRawSlot() > topInv.getSize() && event.isLeftClick()) {
            CEnchantment ce =
                Tools.getEnchantmentByDisplayname(
                    topInv.getContents()[0].getItemMeta().getDisplayName());
            cost = ce.getCost();
            type = "enchantment " + ce.getDisplayName();
            if (!ce.getApplication().equals(Application.GLOBAL)
                && !Tools.isApplicationCorrect(ce.getApplication(), clickedItem.getType())) {
              String appS = ce.getApplication().toString().toLowerCase();
              p.sendMessage(
                  ChatColor.RED
                      + "[CE] This enchantment can only be applied to "
                      + ChatColor.GRAY
                      + (appS.endsWith("s") ? appS : appS + "s")
                      + ChatColor.RED
                      + ".");
              return;
            }
            List<String> lore = new ArrayList<String>();
            if (clickedItem.getItemMeta().hasLore()) {
              lore = clickedItem.getItemMeta().getLore();
              int number = 0;
              for (String s : lore) {
                CEnchantment c = Tools.getEnchantmentByDisplayname(s);
                if (c != null && c.originalName == ce.originalName) {
                  p.sendMessage(ChatColor.RED + "[CE] This item already has this enchantment!");
                  return;
                }
                if (c != null) number++;
              }
              if (Main.maxEnchants > 0 && number >= Main.maxEnchants) {
                p.sendMessage(
                    ChatColor.RED
                        + "[CE] This item has already reached the maximum of "
                        + ChatColor.GRAY
                        + Main.maxEnchants
                        + ChatColor.RED
                        + " enchantments.");
                return;
              }
            }

            lore.add(ce.getDisplayName());
            im.setLore(lore);
            item.setItemMeta(im);
          } else return;

        } else if (topInv.getTitle().equals(Tools.prefix + "Item Creation")) {
          item = topInv.getContents()[0];
          cost = Tools.getItemByDisplayname(item.getItemMeta().getDisplayName()).getCost();
          //					if(item.hasItemMeta() && item.getItemMeta().hasDisplayName() &&
          // item.getItemMeta().getDisplayName().equals(swimsuit.getDisplayName())) { //TODO: Always
          // keep the position of the Swimsuit updated
          //
          //
          //						itemSet = true;
          //
          //						int count = 0;
          //
          //						for(ItemStack i : event.getView().getBottomInventory())
          //							if(i == null || i.getType().equals(Material.AIR))
          //								count++;
          //
          //						if(count < 4) {
          //							p.sendMessage(ChatColor.RED + "[CE] Your Inventory is full!");
          //							return;
          //						}
          //
          //
          //					} else {

          if (event.getView().getBottomInventory().firstEmpty() < 0) {
            p.sendMessage(ChatColor.RED + "[CE] Your Inventory is full!");
            return;
          }

          //					}

          ItemMeta itemIm = item.getItemMeta();
          List<String> lore = itemIm.getLore();
          lore.remove(lore.size() - 1);
          itemIm.setLore(lore);
          item.setItemMeta(itemIm);
          type = "item " + itemIm.getDisplayName();
        }

        // TODO: Fix the cost for items
        //      rewrite the whole section to check which enchantment or item is selected

        successString =
            (ChatColor.GREEN + "[CE] You have created the " + type + ChatColor.GREEN + ".");

        if (!p.isOp() && cost != 0) {
          if (Main.econ.getBalance(p.getName()) >= cost) {
            EconomyResponse ecr = Main.econ.withdrawPlayer(p.getName(), cost);
            if (ecr.transactionSuccess())
              successString =
                  (ChatColor.GREEN
                      + "[CE] Purchased "
                      + type
                      + ChatColor.GREEN
                      + " for "
                      + cost
                      + " "
                      + ((cost == 1)
                          ? Main.econ.currencyNameSingular()
                          : Main.econ.currencyNamePlural()));
            else {
              Bukkit.getConsoleSender()
                  .sendMessage(ChatColor.RED + "[CE] An economy error has occured:");
              Bukkit.getConsoleSender().sendMessage(ChatColor.RED + ecr.errorMessage);
              p.closeInventory();
              return;
            }
          } else {
            p.sendMessage(ChatColor.RED + "[CE] You do not have enough money to buy this!");
            p.closeInventory();
            return;
          }
        }
        if (item != null) {
          if (!itemSet)
            if (type.startsWith("item") && event.getRawSlot() < topInv.getSize())
              p.setItemInHand(item);
            else p.getInventory().setItem(event.getSlot(), item);
          //					else {
          //						ItemStack cp = item.clone();
          //						ItemStack le = item.clone();
          //						ItemStack bo = item.clone();
          //
          //						String[] parts = swimsuit.parts;
          //
          //						cp.setType(Material.IRON_CHESTPLATE);
          //						le.setType(Material.IRON_LEGGINGS);
          //						bo.setType(Material.IRON_BOOTS);
          //
          //						im.setDisplayName(parts[1]);
          //						cp.setItemMeta(im);
          //						im.setDisplayName(parts[2]);
          //						le.setItemMeta(im);
          //						im.setDisplayName(parts[3]);
          //						bo.setItemMeta(im);
          //
          //						p.getInventory().addItem(item);
          //						p.getInventory().addItem(cp);
          //						p.getInventory().addItem(le);
          //						p.getInventory().addItem(bo);
          //
          //					}
        }
        p.closeInventory();
        p.sendMessage(successString);
        return;
      }

      if (event.getRawSlot() < topInv.getSize()) {

        p.closeInventory();
        try {
          p.openInventory(Tools.getNextInventory(clickedItem.getItemMeta().getDisplayName()));
        } catch (Exception e) {
          p.sendMessage(ChatColor.RED + "[CE] This feature is disabled.");
        }
      }
    }
  }
Example #20
0
  @SuppressWarnings("static-access")
  @ClickHandler(
      status = {
        tNpcStatus.MANAGE_SELL,
        tNpcStatus.MANAGE_BUY,
        tNpcStatus.MANAGE_UNLOCKED,
        tNpcStatus.MANAGE_AMOUNTS,
        tNpcStatus.MANAGE_PRICE,
        tNpcStatus.MANAGE_LIMIT
      },
      inventory = InventoryType.TRADER)
  public void manageUI(InventoryClickEvent e) {
    int slot = e.getSlot();
    if (stock.isUiSlot(slot)) {
      if (hitTest(slot, "buy")) {
        // send message
        locale.sendMessage(player, "trader-managermode-toggled", "mode", "#stock-buy");

        // change status
        parseStatus(tNpcStatus.MANAGE_BUY);
      } else if (hitTest(slot, "sell")) {
        // send message
        locale.sendMessage(player, "trader-managermode-toggled", "mode", "#stock-sell");

        // change status
        parseStatus(tNpcStatus.MANAGE_SELL);
      } else if (hitTest(slot, "back")) {
        // if its backing from amounts managing save those amounts
        if (status.equals(tNpcStatus.MANAGE_AMOUNTS))
          stock.saveNewAmounts(inventory, getSelectedItem());

        // send message
        locale.sendMessage(player, "trader-managermode-toggled", "mode", "#stock");

        // change status
        parseStatus(baseStatus);
      } else if (hitTest(slot, "price")) {
        // send message
        locale.sendMessage(player, "trader-managermode-toggled", "mode", "#price");

        // change status
        parseStatus(tNpcStatus.MANAGE_PRICE);
      } else if (hitTest(slot, "lock")) {
        // send message
        locale.sendMessage(player, "trader-managermode-stock-locked");

        // change status
        parseStatus(baseStatus);
        saveItemsUpponLocking();
      } else if (hitTest(slot, "unlock")) {
        // send message
        locale.sendMessage(player, "trader-managermode-stock-unlocked");

        // change status
        parseStatus(tNpcStatus.MANAGE_UNLOCKED);
      } else if (hitTest(slot, "limit")) {
        // send message
        locale.sendMessage(player, "trader-managermode-toggled", "mode", "#limit");

        // change status
        parseStatus(tNpcStatus.MANAGE_LIMIT);
      }
      stock.setManagementInventory(inventory, baseStatus, status);

      // TODO add lores to special blocks
      setSpecialBlockPrices();

      e.setCancelled(true);
    }
  }
  @EventHandler
  public void onInventoryClick(InventoryClickEvent e) {
    DataContainer dataContainer = plugin.getDataContainer();
    Player player = (Player) e.getWhoClicked();

    String name = ChatColor.stripColor(e.getInventory().getName());

    if (name.equalsIgnoreCase("Title categories")) {
      e.setCancelled(true);
      if (e.getCurrentItem() == null
          || e.getCurrentItem().getType() == Material.AIR
          || !e.getCurrentItem().hasItemMeta()) {
        player.closeInventory();
        return;
      }

      if (e.getCurrentItem().getData() instanceof Wool) {

        // All unlocked titles of player
        if (e.getCurrentItem().getItemMeta().getDisplayName().equalsIgnoreCase("Unlocked")) {
          player.openInventory(constructInventory(plugin, player, null, true));
          return;
        }

        // open Titles in category
        player.openInventory(
            constructInventory(
                plugin,
                player,
                Utils.strip(Utils.setColors(e.getCurrentItem().getItemMeta().getDisplayName())),
                false));
      }
    } else if (name.equalsIgnoreCase("Titles in category")
        || name.equalsIgnoreCase("Unlocked Titles")) {
      e.setCancelled(true);
      if (e.getCurrentItem() == null
          || e.getCurrentItem().getType() == Material.AIR
          || !e.getCurrentItem().hasItemMeta()) {
        player.closeInventory();
        return;
      }

      // back button
      if (e.getCurrentItem().getItemMeta().getDisplayName().equalsIgnoreCase("Back")) {
        player.openInventory(constructInventory(plugin, player, null, false));
        return;
      }

      String category = null;
      String[] split = e.getCurrentItem().getItemMeta().getLore().get(1).split(" ");
      if (split.length == 2) category = split[1];

      if (e.getCurrentItem().getData() instanceof Wool) {
        DyeColor color = ((Wool) e.getCurrentItem().getData()).getColor();
        Title title =
            dataContainer.getTitle(
                Utils.strip(
                    Utils.setColors(
                        e.getCurrentItem().getItemMeta().getDisplayName().toLowerCase())));
        Inventory inv = e.getInventory();
        ItemMeta im = e.getCurrentItem().getItemMeta();
        int slot = e.getSlot();
        if (name.equalsIgnoreCase("Titles in category")) {
          switch (color) {
            case RED:
              // Request title.
              if (player.hasPermission(plugin.makeRequestsPerm)) {
                if (RequestCommands.submitRequest(dataContainer, player, title.getId())) {
                  Utils.sendMsg(
                      player,
                      "Your request for "
                          + ChatColor.ITALIC
                          + title.getName()
                          + ChatColor.RESET
                          + " has been submitted.");
                  handleBlock(inv, im, DyeColor.ORANGE, "Pending", slot);
                } else
                  Utils.sendError(
                      player, "You already have a pending request or that title doesn't exist.");
              } else Utils.sendError(player, "You don't have permission to do that.");
              break;
            case LIME:
              // Disable current title.
              if (player.hasPermission(plugin.setTitlePerm)) {
                if (SetCommands.disableTitle(dataContainer, player)) {
                  Utils.sendMsg(player, "Title disabled.");
                  handleBlock(inv, im, DyeColor.GREEN, "Unlocked", slot);
                } else Utils.sendError(player, "Player doesn't have that title active.");
              } else Utils.sendError(player, "You don't have permission to do that.");
              break;
            case GREEN:
              // Set title as current.
              if (player.hasPermission(plugin.setTitlePerm)) {
                if (SetCommands.setTitle(dataContainer, player, title.getId())) {
                  Utils.sendMsg(
                      player,
                      String.format(
                          "Title set to %s" + title.getName() + "%s.",
                          ChatColor.ITALIC,
                          ChatColor.RESET));
                  handleBlock(inv, im, DyeColor.LIME, "Current", slot);
                  if (category == null) player.closeInventory();
                  else player.openInventory(constructInventory(plugin, player, category, false));

                } else
                  Utils.sendError(player, "Player doesn't own that title or it doesn't exist.");
              } else Utils.sendError(player, "You don't have permission to do that.");
              break;
            case ORANGE:
              // Retract request.
              if (player.hasPermission(plugin.makeRequestsPerm)) {
                if (RequestCommands.retractRequest(dataContainer, player)) {
                  Utils.sendMsg(player, "Your request has successfully been retracted.");
                  handleBlock(inv, im, DyeColor.RED, "Locked", slot);
                } else Utils.sendError(player, "You don't have a pending request.");
              } else Utils.sendError(player, "You don't have permission to do that.");
              break;
          }

        } else if (name.equalsIgnoreCase("Unlocked Titles")) {
          switch (color) {
            case LIME:
              // Disable current title.
              if (player.hasPermission(plugin.setTitlePerm)) {
                if (SetCommands.disableTitle(dataContainer, player)) {
                  Utils.sendMsg(player, "Title disabled.");
                  handleBlock(inv, im, DyeColor.GREEN, "Unlocked", slot);
                } else Utils.sendError(player, "Player doesn't have that title active.");
              } else Utils.sendError(player, "You don't have permission to do that.");
              break;
            case GREEN:
              // Set title as current.
              if (player.hasPermission(plugin.setTitlePerm)) {
                if (SetCommands.setTitle(dataContainer, player, title.getId())) {
                  Utils.sendMsg(
                      player,
                      String.format(
                          "Title set to %s" + title.getName() + "%s.",
                          ChatColor.ITALIC,
                          ChatColor.RESET));
                  handleBlock(inv, im, DyeColor.LIME, "Current", slot);
                  if (category == null) player.closeInventory();
                  else player.openInventory(constructInventory(plugin, player, category, false));

                } else
                  Utils.sendError(player, "Player doesn't own that title or it doesn't exist.");
              } else Utils.sendError(player, "You don't have permission to do that.");
              break;
          }
        }
      }
    }
  }
Example #22
0
  @EventHandler(priority = EventPriority.MONITOR)
  public void guiClick(InventoryClickEvent event) {

    invetaryname = event.getInventory().getName();
    p = ((Player) event.getWhoClicked());

    if (!invetaryname.contains("§6\u2739 §d§lCommande Générales §6\u2739")) return;
    if ((event.getSlot() < 0) || (event.getSlot() > 53)) return;
    event.setCancelled(true);

    if ((event.getCurrentItem().getType() == Material.STAINED_GLASS)
        && (event.getCurrentItem().getDurability() == 0)) {

      ByteArrayOutputStream b = new ByteArrayOutputStream();
      DataOutputStream out = new DataOutputStream(b);
      p.closeInventory();
      try {
        out.writeUTF("Connect");
        out.writeUTF("lobby");
      } catch (IOException ex) {
      }
      p.sendPluginMessage(crea.plugin, "BungeeCord", b.toByteArray());
    }

    if ((event.getCurrentItem().getType() == Material.STAINED_GLASS)
        && (event.getCurrentItem().getDurability() == 1)) {
      p.closeInventory();
      p.performCommand("spawn");
    }

    if ((event.getCurrentItem().getType() == Material.STAINED_GLASS)
        && (event.getCurrentItem().getDurability() == 2)) {
      p.closeInventory();
      p.performCommand("list");
    }

    if ((event.getCurrentItem().getType() == Material.STAINED_GLASS)
        && (event.getCurrentItem().getDurability() == 3)) {
      p.closeInventory();
      p.performCommand("stats");
    }

    if ((event.getCurrentItem().getType() == Material.STAINED_GLASS)
        && (event.getCurrentItem().getDurability() == 4)) {
      p.closeInventory();
      p.performCommand("ci");
    }

    if ((event.getCurrentItem().getType() == Material.STAINED_GLASS)
        && (event.getCurrentItem().getDurability() == 5)) {
      p.closeInventory();
      if (p.hasPermission("crea.journuit"))
        crea.plugin
            .getServer()
            .dispatchCommand(
                crea.plugin.getServer().getConsoleSender(), "ptime day " + p.getName());
      else p.sendMessage("§cVous devez avoir le grade Maçon ou +");
    }

    if ((event.getCurrentItem().getType() == Material.STAINED_GLASS)
        && (event.getCurrentItem().getDurability() == 6)) {
      p.closeInventory();
      if (p.hasPermission("crea.journuit"))
        crea.plugin
            .getServer()
            .dispatchCommand(
                crea.plugin.getServer().getConsoleSender(), "ptime night " + p.getName());
      else p.sendMessage("§cVous devez avoir le grade Maçon ou +");
    }

    if ((event.getCurrentItem().getType() == Material.STAINED_GLASS)
        && (event.getCurrentItem().getDurability() == 7)) {
      p.closeInventory();
      if (p.hasPermission("crea.speed"))
        crea.plugin
            .getServer()
            .dispatchCommand(
                crea.plugin.getServer().getConsoleSender(), "speed fly 2 " + p.getName());
      else p.sendMessage("§cVous devez avoir le grade Décorateur ou +");
    }

    if ((event.getCurrentItem().getType() == Material.STAINED_GLASS)
        && (event.getCurrentItem().getDurability() == 8)) {
      p.closeInventory();
      p.performCommand("tpyes");
    }

    if ((event.getCurrentItem().getType() == Material.STAINED_GLASS)
        && (event.getCurrentItem().getDurability() == 9)) {
      p.closeInventory();
      p.performCommand("tpno");
    }

    if ((event.getCurrentItem().getType() == Material.STAINED_GLASS)
        && (event.getCurrentItem().getDurability() == 10)) {
      // p.closeInventory();
      // p.performCommand("");
    }

    if ((event.getCurrentItem().getType() == Material.STAINED_GLASS)
        && (event.getCurrentItem().getDurability() == 11)) {
      // p.closeInventory();
      // p.performCommand("");
    }

    if ((event.getCurrentItem().getType() == Material.STAINED_GLASS)
        && (event.getCurrentItem().getDurability() == 12)) {
      p.closeInventory();
      p.performCommand("back");
    }

    if ((event.getCurrentItem().getType() == Material.STAINED_GLASS)
        && (event.getCurrentItem().getDurability() == 13)) {
      // p.closeInventory();
      // p.performCommand("");
    }

    if ((event.getCurrentItem().getType() == Material.STAINED_GLASS)
        && (event.getCurrentItem().getDurability() == 14)) {
      // p.closeInventory();
      // p.performCommand("");
    }

    if (event.getCurrentItem().getType() == Material.WOOD_DOOR) {
      p.playSound(p.getLocation(), Sound.DOOR_OPEN, 2.0F, 13.0F);
      p.closeInventory();
      p.openInventory(menu.displayGUImenu());
    }
  }
  @SuppressWarnings("deprecation")
  @EventHandler
  public void onInventoryClick(InventoryClickEvent event) {
    // controller.getLogger().info("CLICK: " + event.getAction() + ", " + event.getClick() + " on "
    // + event.getSlotType() + " in "+ event.getInventory().getType() + " slots: " + event.getSlot()
    // + ":" + event.getRawSlot());

    if (event.isCancelled()) return;
    if (!(event.getWhoClicked() instanceof Player)) return;

    Player player = (Player) event.getWhoClicked();
    Mage apiMage = controller.getMage(player);

    if (!(apiMage instanceof com.elmakers.mine.bukkit.magic.Mage)) return;
    final com.elmakers.mine.bukkit.magic.Mage mage = (com.elmakers.mine.bukkit.magic.Mage) apiMage;

    GUIAction gui = mage.getActiveGUI();
    if (gui != null) {
      gui.clicked(event);
      return;
    }

    // Check for temporary items and skill items
    InventoryAction action = event.getAction();
    InventoryType inventoryType = event.getInventory().getType();
    ItemStack clickedItem = event.getCurrentItem();

    boolean isDrop =
        event.getClick() == ClickType.DROP || event.getClick() == ClickType.CONTROL_DROP;
    boolean isSkill = clickedItem != null && Wand.isSkill(clickedItem);

    // Preventing putting skills in containers
    if (isSkill && inventoryType != InventoryType.CRAFTING) {
      if (!isDrop) {
        event.setCancelled(true);
      }
      return;
    }

    // Check for right-click-to-use
    if (isSkill && action == InventoryAction.PICKUP_HALF) {
      Spell spell = mage.getSpell(Wand.getSpell(clickedItem));
      if (spell != null) {
        spell.cast();
      }
      player.closeInventory();
      event.setCancelled(true);
      return;
    }

    if (clickedItem != null && NMSUtils.isTemporary(clickedItem)) {
      String message = NMSUtils.getTemporaryMessage(clickedItem);
      if (message != null && message.length() > 1) {
        mage.sendMessage(message);
      }
      ItemStack replacement = NMSUtils.getReplacement(clickedItem);
      event.setCurrentItem(replacement);
      event.setCancelled(true);
      return;
    }

    // Check for wearing spells
    ItemStack heldItem = event.getCursor();
    if (heldItem != null && event.getSlotType() == InventoryType.SlotType.ARMOR) {
      if (Wand.isSpell(heldItem)) {
        event.setCancelled(true);
        return;
      }
      if (Wand.isWand(clickedItem) || Wand.isWand(heldItem)) {
        controller.onArmorUpdated(mage);
      }
    }
    boolean isHotbar =
        event.getAction() == InventoryAction.HOTBAR_SWAP
            || event.getAction() == InventoryAction.HOTBAR_MOVE_AND_READD;
    if (isHotbar && event.getSlotType() == InventoryType.SlotType.ARMOR) {
      int slot = event.getHotbarButton();
      ItemStack item = mage.getPlayer().getInventory().getItem(slot);
      if (item != null && Wand.isSpell(item)) {
        event.setCancelled(true);
        return;
      }
      controller.onArmorUpdated(mage);
    }

    Wand activeWand = mage.getActiveWand();

    boolean isChest =
        inventoryType == InventoryType.CHEST
            || inventoryType == InventoryType.HOPPER
            || inventoryType == InventoryType.DISPENSER
            || inventoryType == InventoryType.DROPPER;
    boolean clickedWand = Wand.isWand(clickedItem);
    boolean isContainerSlot = event.getSlot() == event.getRawSlot();

    if (activeWand != null && activeWand.isInventoryOpen()) {
      // Kind of a hack to avoid hotbar items with 0 amounts disappearing :(
      Inventory inventory = player.getInventory();
      for (int i = 0; i < 8; i++) {
        ItemStack item = inventory.getItem(i);
        if (item != null && item.getAmount() == 0) {
          item.setAmount(1);
        }
      }

      // Don't allow the offhand slot to be messed with while the spell inventory is open
      if (event.getRawSlot() == 45) {
        event.setCancelled(true);
        return;
      }

      if (Wand.isSpell(clickedItem) && clickedItem.getAmount() != 1) {
        clickedItem.setAmount(1);
      }
      if (clickedWand) {
        event.setCancelled(true);
        if (dropChangesPages) {
          activeWand.cycleInventory();
        } else {
          activeWand.cycleHotbar(1);
        }
        return;
      }

      // So many ways to try and move the wand around, that we have to watch for!
      if (isHotbar && Wand.isWand(player.getInventory().getItem(event.getHotbarButton()))) {
        event.setCancelled(true);
        return;
      }

      // Can't wear spells
      if (event.getAction() == InventoryAction.MOVE_TO_OTHER_INVENTORY && clickedItem != null) {
        if (controller.isWearable(clickedItem)) {
          event.setCancelled(true);
          return;
        }
      }

      // Safety check for something that ought not to be possible
      // but perhaps happens with lag?
      if (Wand.isWand(event.getCursor())) {
        activeWand.closeInventory();
        event.setCursor(null);
        event.setCancelled(true);
        return;
      }
    } else if (activeWand != null) {
      // Check for changes that could have been made to the active wand
      Integer activeSlot = player.getInventory().getHeldItemSlot();
      if (activeSlot != null
          && (event.getSlot() == activeSlot
              || (event.getAction() == InventoryAction.HOTBAR_SWAP
                  && event.getHotbarButton() == activeSlot))) {
        mage.checkWand();
        activeWand = mage.getActiveWand();
      }
    } else if (clickedWand
        && Wand.Undroppable
        && !player.hasPermission("Magic.wand.override_drop")
        && isChest
        && !isContainerSlot) {
      Wand wand = new Wand(controller, clickedItem);
      if (wand.isUndroppable()) {
        event.setCancelled(true);
        return;
      }
    }

    // Check for armor changing
    if (event.getAction() == InventoryAction.MOVE_TO_OTHER_INVENTORY && clickedItem != null) {
      if (controller.isWearable(clickedItem)) {
        controller.onArmorUpdated(mage);
      }
    }

    // Check for dropping items out of a wand's inventory
    // or dropping undroppable wands
    if (isDrop) {
      if (clickedWand) {
        Wand wand = new Wand(controller, clickedItem);
        if (wand.isUndroppable()) {
          event.setCancelled(true);
          if (activeWand != null) {
            if (activeWand.getHotbarCount() > 1) {
              activeWand.cycleHotbar(1);
            } else {
              activeWand.closeInventory();
            }
          }
          return;
        }
      }
      if (activeWand != null && activeWand.isInventoryOpen()) {

        ItemStack droppedItem = clickedItem;

        if (!Wand.isSpell(droppedItem)) {
          mage.giveItem(droppedItem);
          event.setCurrentItem(null);
          event.setCancelled(true);
          return;
        }

        // This is a hack to deal with spells on cooldown disappearing,
        // Since the event handler doesn't match the zero-count itemstacks
        Integer slot = event.getSlot();
        int heldSlot = player.getInventory().getHeldItemSlot();
        Inventory hotbar = activeWand.getHotbar();
        if (hotbar != null
            && slot >= 0
            && slot <= hotbar.getSize()
            && slot != heldSlot
            && activeWand.getMode() == WandMode.INVENTORY) {
          if (slot > heldSlot) slot--;
          if (slot < hotbar.getSize()) {
            droppedItem = hotbar.getItem(slot);
          } else {
            slot = null;
          }
        } else {
          slot = null;
        }

        if (!controller.isSpellDroppingEnabled()) {
          player.closeInventory();
          String spellName = Wand.getSpell(droppedItem);
          if (spellName != null && !activeWand.isManualQuickCastDisabled()) {
            Spell spell = mage.getSpell(spellName);
            if (spell != null) {
              activeWand.cast(spell);
              // Just in case a spell has levelled up... jeez!
              if (hotbar != null && slot != null) {
                droppedItem = hotbar.getItem(slot);
              }
            }
          }
          event.setCancelled(true);

          // This is needed to avoid spells on cooldown disappearing from the hotbar
          if (hotbar != null && slot != null && mage.getActiveGUI() == null) {
            player.getInventory().setItem(event.getSlot(), droppedItem);
            player.updateInventory();
          }

          return;
        }
        ItemStack newDrop = controller.removeItemFromWand(activeWand, droppedItem);

        if (newDrop != null) {
          Location location = player.getLocation();
          Item item = location.getWorld().dropItem(location, newDrop);
          item.setVelocity(location.getDirection().normalize());
        } else {
          event.setCancelled(true);
        }
      }
      return;
    }

    // Check for wand cycling with active inventory
    if (activeWand != null) {
      WandMode wandMode = activeWand.getMode();
      if ((wandMode == WandMode.INVENTORY && inventoryType == InventoryType.CRAFTING)
          || (wandMode == WandMode.CHEST && inventoryType == InventoryType.CHEST)) {
        if (activeWand.isInventoryOpen()) {
          if (event.getAction() == InventoryAction.NOTHING) {
            int direction = event.getClick() == ClickType.LEFT ? 1 : -1;
            activeWand.cycleInventory(direction);
            event.setCancelled(true);
            return;
          }

          if (event.getSlotType() == InventoryType.SlotType.ARMOR) {
            event.setCancelled(true);
            return;
          }

          // Chest mode falls back to selection from here.
          if (event.getAction() == InventoryAction.PICKUP_HALF || wandMode == WandMode.CHEST) {
            controller.onPlayerActivateIcon(mage, activeWand, clickedItem);
            player.closeInventory();
            event.setCancelled(true);
          }
        }
      }
    }
  }
Example #24
0
  @EventHandler(priority = EventPriority.MONITOR)
  public void guiClick(InventoryClickEvent e) {

    invetaryname = e.getInventory().getName();
    p = ((Player) e.getWhoClicked());

    if (!invetaryname.contains("§6\u2663 Epées \u2663")) return;
    if ((e.getSlot() < 0) || (e.getSlot() > 53)) return;
    e.setCancelled(true);
    if (e.getSlotType() != InventoryType.SlotType.CONTAINER) {
      p.closeInventory();
      return;
    }

    if (e.getSlot() == 0) {
      if (Fct.CheckMoneyArmes(p, 100, e)) {
        currentarmeItem = new ItemStack(Material.IRON_SWORD);
        ItemStack attributes = Fct.AddAtrib(currentarmeItem, 13.5, -1, 0, 0);
        ItemMeta meta0 = attributes.getItemMeta();
        meta0.setDisplayName("§7Dague d'assassin");
        lores.add("§bDégât: §214,5");
        lores.add("§bPV Max: §c-1");
        meta0.setLore(lores);
        attributes.setItemMeta(meta0);
        p.getInventory().addItem(ItemLores.addGlow(attributes));
        lores.clear();
        p.closeInventory();
      } else Fct.closeNo(p);
    }

    if (e.getSlot() == 1) {
      if (Fct.CheckMoneyArmes(p, 100, e)) {
        currentarmeItem = new ItemStack(Material.IRON_SWORD);
        ItemStack attributes = Fct.AddAtrib(currentarmeItem, 12.5, 1, 0, 0);
        ItemMeta meta1 = attributes.getItemMeta();
        meta1.setDisplayName("§7Couteau de boucher");
        lores.add("§bDégât: §213,5");
        lores.add("§bPV Max: §2+1");
        meta1.setLore(lores);
        attributes.setItemMeta(meta1);
        p.getInventory().addItem(ItemLores.addGlow(attributes));
        lores.clear();
        p.closeInventory();
      } else Fct.closeNo(p);
    }

    ///////////////////////////////////////// ligne 2////////////////////////////////////////////

    if (e.getSlot() == 9) {
      if (Fct.CheckMoneyArmes(p, 200, e)) {
        currentarmeItem = new ItemStack(Material.IRON_SWORD);
        ItemStack attributes = Fct.AddAtrib(currentarmeItem, 13.5, 0, -0.05, 0);
        ItemMeta meta9 = attributes.getItemMeta();
        meta9.setDisplayName("§1Rapière française");
        lores.add("§bDégât: §214,5");
        lores.add("§bVitesse: §c-5%");
        meta9.setLore(lores);
        attributes.setItemMeta(meta9);
        p.getInventory().addItem(ItemLores.addGlow(attributes));
        lores.clear();
        p.closeInventory();
      } else Fct.closeNo(p);
    }

    if (e.getSlot() == 10) {
      if (Fct.CheckMoneyArmes(p, 200, e)) {
        currentarmeItem = new ItemStack(Material.IRON_SWORD);
        ItemStack attributes = Fct.AddAtrib(currentarmeItem, 11.5, 0, 0.05, 0);
        ItemMeta meta10 = attributes.getItemMeta();
        meta10.setDisplayName("§1Lame de voleur");
        lores.add("§bDégât: §212,5");
        lores.add("§bVitesse: §2+5%");
        lores.add("§bPickpocket: §e50%");
        meta10.setLore(lores);
        attributes.setItemMeta(meta10);
        p.getInventory().addItem(ItemLores.addGlow(attributes));
        lores.clear();
        p.closeInventory();
      } else Fct.closeNo(p);
    }

    if (e.getSlot() == 11) {
      if (Fct.CheckMoneyArmes(p, 200, e)) {
        currentarmeItem = new ItemStack(Material.IRON_SWORD);
        ItemStack attributes = Fct.AddAtrib(currentarmeItem, 12.5, 0, 0.05, 0);
        ItemMeta meta11 = attributes.getItemMeta();
        meta11.setDisplayName("§1Sabre Syrien");
        lores.add("§bDégât: §213,5");
        lores.add("§bVitesse: §2+5%");
        meta11.setLore(lores);
        attributes.setItemMeta(meta11);
        p.getInventory().addItem(ItemLores.addGlow(attributes));
        lores.clear();
        p.closeInventory();
      } else Fct.closeNo(p);
    }

    //////////////////////////////////////// ligne 3
    // /////////////////////////////////////////////////////////

    if (e.getSlot() == 18) {
      if (Fct.CheckMoneyArmes(p, 500, e)) {
        currentarmeItem = new ItemStack(Material.DIAMOND_SWORD);
        ItemStack attributes = Fct.AddAtrib(currentarmeItem, 13.5, -1, 0, 0);
        ItemMeta meta18 = attributes.getItemMeta();
        meta18.setDisplayName("§aLame solaire");
        lores.add("§bDégât: §214,5");
        lores.add("§bPV Max: §c-1");
        lores.add("§eFeu: §250%");
        meta18.setLore(lores);
        attributes.setItemMeta(meta18);
        p.getInventory().addItem(ItemLores.addGlow(attributes));
        lores.clear();
        p.closeInventory();
      } else Fct.closeNo(p);
    }

    if (e.getSlot() == 19) {
      if (Fct.CheckMoneyArmes(p, 500, e)) {
        currentarmeItem = new ItemStack(Material.DIAMOND_SWORD);
        ItemStack attributes = Fct.AddAtrib(currentarmeItem, 13.5, -1, 0, 0);
        ItemMeta meta19 = attributes.getItemMeta();
        meta19.setDisplayName("§aLame du néant");
        lores.add("§bDégât: §214,5");
        lores.add("§bPV Max: §c-1");
        lores.add("§eInvisibilité: §250%");
        meta19.setLore(lores);
        attributes.setItemMeta(meta19);
        p.getInventory().addItem(ItemLores.addGlow(attributes));
        lores.clear();
        p.closeInventory();
      } else Fct.closeNo(p);
    }

    if (e.getSlot() == 20) {
      if (Fct.CheckMoneyArmes(p, 500, e)) {
        currentarmeItem = new ItemStack(Material.DIAMOND_SWORD);
        ItemStack attributes = Fct.AddAtrib(currentarmeItem, 12.5, 2, 0, 0.1);
        ItemMeta meta20 = attributes.getItemMeta();
        meta20.setDisplayName("§aFauchon Vénitien");
        lores.add("§bDégât: §213,5");
        lores.add("§bPV Max: §2+2");
        lores.add("§bknockback Resistance: §2+10%");
        meta20.setLore(lores);
        attributes.setItemMeta(meta20);
        p.getInventory().addItem(ItemLores.addGlow(attributes));
        lores.clear();
        p.closeInventory();
      } else Fct.closeNo(p);
    }

    if (e.getSlot() == 21) {
      if (Fct.CheckMoneyArmes(p, 500, e)) {
        currentarmeItem = new ItemStack(Material.DIAMOND_SWORD);
        ItemStack attributes = Fct.AddAtrib(currentarmeItem, 12.5, 2, 0.07, 0);
        ItemMeta meta21 = attributes.getItemMeta();
        meta21.setDisplayName("§aÉpée Milanaise");
        lores.add("§bDégât: §213,5");
        lores.add("§bPV Max: §2+2");
        lores.add("§bVitesse: §2+7%");
        meta21.setLore(lores);
        attributes.setItemMeta(meta21);
        p.getInventory().addItem(ItemLores.addGlow(attributes));
        lores.clear();
        p.closeInventory();
      } else Fct.closeNo(p);
    }

    ////////////////////////////////////////////////////////// ligne
    // 4//////////////////////////////////////////////////////

    if (e.getSlot() == 27) {
      if (Fct.CheckMoneyArmes(p, 700, e)) {
        currentarmeItem = new ItemStack(Material.DIAMOND_SWORD);
        ItemStack attributes = Fct.AddAtrib(currentarmeItem, 14.5, 0, 0.07, 0);
        ItemMeta meta27 = attributes.getItemMeta();
        meta27.setDisplayName("§6Rapière Sicilienne");
        lores.add("§bDégât: §215,5");
        lores.add("§bVitesse: §2+7%");
        lores.add("§eCécité: §250%");
        meta27.setLore(lores);
        attributes.setItemMeta(meta27);
        p.getInventory().addItem(ItemLores.addGlow(attributes));
        lores.clear();
        p.closeInventory();
      } else Fct.closeNo(p);
    }

    if (e.getSlot() == 28) {
      if (Fct.CheckMoneyArmes(p, 700, e)) {
        currentarmeItem = new ItemStack(Material.DIAMOND_SWORD);
        ItemStack attributes = Fct.AddAtrib(currentarmeItem, 15.5, 2, 0, 0);
        ItemMeta meta28 = attributes.getItemMeta();
        meta28.setDisplayName("§6Coutelas français");
        lores.add("§bDégât: §216,5");
        lores.add("§bPV Max: §2+2");
        lores.add("§eLenteur: §250%");
        meta28.setLore(lores);
        attributes.setItemMeta(meta28);
        p.getInventory().addItem(ItemLores.addGlow(attributes));
        lores.clear();
        p.closeInventory();
      } else Fct.closeNo(p);
    }

    if (e.getSlot() == 29) {
      if (Fct.CheckMoneyArmes(p, 700, e)) {
        currentarmeItem = new ItemStack(Material.DIAMOND_SWORD);
        ItemStack attributes = Fct.AddAtrib(currentarmeItem, 14, 3, 0, 0);
        ItemMeta meta29 = attributes.getItemMeta();
        meta29.setDisplayName("§6Épée d'officier");
        lores.add("§bDégât: §215");
        lores.add("§bPV Max: §2+3");
        lores.add("§eFaiblesse: §250%");
        meta29.setLore(lores);
        attributes.setItemMeta(meta29);
        p.getInventory().addItem(ItemLores.addGlow(attributes));
        lores.clear();
        p.closeInventory();
      } else Fct.closeNo(p);
    }

    if (e.getSlot() == 30) {
      if (Fct.CheckMoneyArmes(p, 700, e)) {
        currentarmeItem = new ItemStack(Material.DIAMOND_SWORD);
        ItemStack attributes = Fct.AddAtrib(currentarmeItem, 15, -1, 0, 0);
        ItemMeta meta30 = attributes.getItemMeta();
        meta30.setDisplayName("§6Épée de capitaine");
        lores.add("§bDégât: §216");
        lores.add("§bPV Max: §c-1");
        lores.add("§eVol de vie: §250%");
        meta30.setLore(lores);
        attributes.setItemMeta(meta30);
        p.getInventory().addItem(ItemLores.addGlow(attributes));
        lores.clear();
        p.closeInventory();
      } else Fct.closeNo(p);
    }

    if (e.getSlot() == 31) {
      if (Fct.CheckMoneyArmes(p, 700, e)) {
        currentarmeItem = new ItemStack(Material.DIAMOND_SWORD);
        ItemStack attributes = Fct.AddAtrib(currentarmeItem, 14, 2, 0, 0);
        ItemMeta meta31 = attributes.getItemMeta();
        meta31.setDisplayName("§6Épée d'Anaklusmos");
        lores.add("§bDégât: §215");
        lores.add("§bPV Max: §2+2");
        lores.add("§eNausée: §250%");
        meta31.setLore(lores);
        attributes.setItemMeta(meta31);
        p.getInventory().addItem(ItemLores.addGlow(attributes));
        lores.clear();
        p.closeInventory();
      } else Fct.closeNo(p);
    }

    if (e.getSlot() == 36
        || e.getSlot() == 37
        || e.getSlot() == 38
        || e.getSlot() == 39
        || e.getSlot() == 40
        || e.getSlot() == 41) {
      p.sendMessage("§4rupture de stock!");
      p.closeInventory();
    }
  }
  @EventHandler
  public void onInventoryClick(InventoryClickEvent event) {
    if (PlayerManager.getArena(event.getWhoClicked().getUniqueId()) != null) {
      event.setCancelled(true);
    }
    if (GuiInventory.getLastCreatedInventoryType(event.getWhoClicked().getUniqueId())
        == GuiInventory.JOIN) {
      if (compare(
          event.getWhoClicked().getOpenInventory().getTopInventory(),
          GuiInventory.getLastCreatedInventory(event.getWhoClicked().getUniqueId()))) {
        event.setCancelled(true);
        if (compare(
            event.getClickedInventory(),
            GuiInventory.getLastCreatedInventory(event.getWhoClicked().getUniqueId()))) {
          SpleefArena arena = GuiInventory.getArena(event.getSlot());
          if (arena != null) {
            Player player = (Player) event.getWhoClicked();
            try {
              arena.join(player);
            } catch (SpleefArenaNotWaitingForPlayersException e) {
              player.sendMessage(
                  Language.CAN_NOT_JOIN_GAME_ACTIVE.toString().replace("%arena%", arena.getName()));
            } catch (SpleefArenaIsFullException e) {
              player.sendMessage(
                  Language.CAN_NOT_JOIN_ARENA_FULL.toString().replace("%arena%", arena.getName()));
            } catch (SpleefArenaIsDisabledException e) {
              player.sendMessage(
                  Language.CAN_NOT_JOIN_ARENA_DISABLED
                      .toString()
                      .replace("%arena%", arena.getName()));
            } catch (SpleefArenaMisconfiguredException e) {
              player.sendMessage(
                  Language.CAN_NOT_JOIN_ARENA_MISCONFIGURED
                      .toString()
                      .replace("%arena%", arena.getName()));
            } catch (TooLateToJoinException e) {
              player.sendMessage(
                  Language.CAN_NOT_JOIN_TOO_LATE.toString().replace("%arena%", arena.getName()));
            }
          }
        }
      }
    }
    if (GuiInventory.getLastCreatedInventoryType(event.getWhoClicked().getUniqueId())
        == GuiInventory.STATISTICS) {
      if (compare(
          event.getWhoClicked().getOpenInventory().getTopInventory(),
          GuiInventory.getLastCreatedInventory(event.getWhoClicked().getUniqueId()))) {
        event.setCancelled(true);
      }
    }
    if (GuiInventory.getLastCreatedInventoryType(event.getWhoClicked().getUniqueId())
        == GuiInventory.SHOP) {
      if (compare(
          event.getWhoClicked().getOpenInventory().getTopInventory(),
          GuiInventory.getLastCreatedInventory(event.getWhoClicked().getUniqueId()))) {
        event.setCancelled(true);
        if (event.getCurrentItem() != null) {
          final Particle PARTICLE = Particle.getParticle(event.getCurrentItem());
          if (PARTICLE != null) {
            final Player PLAYER = (Player) event.getWhoClicked();
            SpleefPlayer.getPlayer(
                PLAYER.getUniqueId(),
                new FutureCallback<SpleefPlayer>() {
                  @Override
                  public void onSuccess(SpleefPlayer spleefPlayer) {
                    if (spleefPlayer.hasBought(PARTICLE)) {
                      if (ParticleCreatorTask.getParticleEffect(PLAYER)
                          == PARTICLE) { // if the player already selected the particle remove it
                        ParticleCreatorTask.removePlayer(PLAYER);
                        PLAYER.closeInventory();
                      } else {
                        ParticleCreatorTask.addPlayer(PLAYER, PARTICLE);
                        PLAYER.closeInventory();
                      }
                    } else {
                      if (spleefPlayer.getTotalPoints() < PARTICLE.getPrice()) {
                        PLAYER.sendMessage(Language.NOT_ENOUGH_POINTS_TO_BUY_PARTICLE.toString());
                      } else {
                        spleefPlayer.setTotalPoints(
                            spleefPlayer.getTotalPoints() - PARTICLE.getPrice());
                        spleefPlayer.addEffect(PARTICLE);
                        ParticleCreatorTask.addPlayer(PLAYER, PARTICLE);
                        PLAYER.closeInventory();
                        PLAYER.playSound(PLAYER.getLocation(), Sound.LEVEL_UP, 1F, 1F);
                        SpleefArena arena = PlayerManager.getArena(PLAYER.getUniqueId());
                        if (arena != null) { // update the scoreboard
                          arena.setScoreboard(PLAYER);
                        }
                      }
                    }
                  }

                  @Override
                  public void onFailure(Throwable t) {
                    SpleefMain.getInstance()
                        .log(
                            Level.SEVERE,
                            "Couldn't access player database... :/ (player: " + PLAYER.getName());
                    t.printStackTrace();
                  }
                });
          }
        }
      }
    }
  }
Example #26
0
File: Shop.java Project: Elicis/LoM
 @SuppressWarnings("deprecation")
 @EventHandler
 public void onInventoryClick(InventoryClickEvent event) {
   Player player = (Player) event.getWhoClicked();
   if (LoM_API.isInArena(player)) {
     event.setCancelled(true);
   }
   if (isShopInventory(event.getInventory())) {
     event.setCancelled(true);
     if (!event.getInventory().getName().equalsIgnoreCase(sites.get(0).getName())) {
       if (event.getCurrentItem() != null) {
         if (event.getCurrentItem().getType() != Material.AIR) {
           if (!(event.getSlot() >= 53)) {
             ShopItem item =
                 proxy.getItem(this.getInventoryId(event.getInventory()), event.getSlot());
             ShopBuyEvent event1 = new ShopBuyEvent(player, item, item.getPrice(player));
             if (!event1.isCancelled()) {
               if (LoM_API.isInArena(player)) {
                 Arena a = LoM_API.getArenaP(player);
                 if (a.isActive()) {
                   Champion champ = a.getChamps().get(player.getName());
                   if ((champ.getMoney() - event1.getPrice()) >= 0) {
                     champ.setMoney(champ.getMoney() - event1.getPrice());
                     player.getInventory().addItem(item.getItemStack());
                     player.updateInventory();
                     for (ShopItemType type : item.getItemType()) {
                       int eff = item.getEffects().get(item.getItemType().indexOf(type));
                       switch (type) {
                         case ARMOR:
                           champ.setitemDefense(champ.getItemArmor() + eff);
                           break;
                         case DAMAGE:
                           champ.setitemDamage(champ.getItemDamage() + eff);
                           break;
                         case HEALTH:
                           champ.setitemHealth(champ.getItemHealth() + eff);
                           break;
                         case MAGICRESISTANCE:
                           champ.setitemMagicResist(champ.getitemMagicResist() + eff);
                           break;
                         case MANA:
                           champ.setitemMana(champ.getItemMana() + eff);
                           break;
                         default:
                           break;
                       }
                     }
                   }
                 }
               }
             }
           } else {
             if (event.getSlot() == 53) {
               player.openInventory(sites.get(0));
             }
           }
         }
       }
     } else {
       ItemStack item = event.getCurrentItem();
       switch (item.getType()) {
         case REDSTONE_BLOCK:
           player.openInventory(sites.get(1));
           break;
         case IRON_CHESTPLATE:
           player.openInventory(sites.get(2));
           break;
         case LEATHER_CHESTPLATE:
           player.openInventory(sites.get(3));
           break;
         case IRON_SWORD:
           player.openInventory(sites.get(4));
           break;
         case DIAMOND_HOE:
           player.openInventory(sites.get(5));
           break;
         case LAPIS_BLOCK:
           player.openInventory(sites.get(7));
           break;
         case POTION:
           player.openInventory(sites.get(6));
           break;
         default:
           player.openInventory(sites.get(0));
           break;
       }
     }
   }
 }