Beispiel #1
0
  @EventHandler
  public void onInventoryClick(InventoryClickEvent e) {
    Player player = (Player) e.getWhoClicked();
    Inventory inventory = e.getInventory();
    ItemStack currentItem = e.getCurrentItem();

    if (ArenaManager.getInstance().getArena(player) == null) {
      return;
    }

    Plot plot = ArenaManager.getInstance().getArena(player).getPlot(player);

    if (!inventory.getName().equals(ChatColor.GREEN + "Time selection")) {
      return;
    }
    if (currentItem.getType() != Material.WATCH) {
      return;
    }
    if (!currentItem.hasItemMeta()) {
      return;
    }
    if (!currentItem.getItemMeta().getDisplayName().equals(ChatColor.GREEN + "2 AM")) {
      return;
    }

    plot.setTime(Time.AM2);
    e.setCancelled(true);
  }
  @SuppressWarnings("deprecation")
  private void onLobbyInventoryClick(InventoryClickEvent ice, Player player, Game game) {
    Inventory inv = ice.getInventory();
    ItemStack clickedStack = ice.getCurrentItem();

    if (!inv.getTitle().equals(Main._l("lobby.chooseteam"))) {
      ice.setCancelled(true);
      return;
    }

    if (clickedStack == null) {
      ice.setCancelled(true);
      return;
    }

    if (clickedStack.getType() != Material.WOOL) {
      return;
    }

    ice.setCancelled(true);
    Team team = game.getTeamByDyeColor(DyeColor.getByData(clickedStack.getData().getData()));
    if (team == null) {
      return;
    }

    game.playerJoinTeam(player, team);
    player.closeInventory();
  }
  @SuppressWarnings("deprecation")
  @EventHandler
  public void onInventoryClick(InventoryClickEvent e) {
    Player player = (Player) e.getWhoClicked();
    Inventory inventory = e.getInventory();
    ItemStack currentItem = e.getCurrentItem();

    if (ArenaManager.getInstance().getArena(player) == null) {
      return;
    }

    Plot plot = ArenaManager.getInstance().getArena(player).getPlot(player);

    if (!inventory.getName().equals(ChatColor.GREEN + "Options menu")) {
      return;
    }
    if (currentItem.getType() != Material.HARD_CLAY) {
      return;
    }
    if (!currentItem.hasItemMeta()) {
      return;
    }
    if (!currentItem.getItemMeta().getDisplayName().equals(ChatColor.GREEN + "Floor block")) {
      return;
    }

    for (Block block : plot.getFloor().getAllBlocks()) {
      block.setType(e.getCursor().getType());
      block.setData(e.getCursor().getData().getData());
    }

    e.setCancelled(true);
  }
  @EventHandler
  public void onInventoryClick(InventoryClickEvent e) {
    Player player = (Player) e.getWhoClicked();
    Inventory inventory = e.getInventory();
    ItemStack currentItem = e.getCurrentItem();

    if (ArenaManager.getInstance().getArena(player) == null) {
      return;
    }

    Plot plot = ArenaManager.getInstance().getArena(player).getPlot(player);

    if (!inventory.getName().equals(ChatColor.GREEN + "Particles")) {
      return;
    }
    if (currentItem.getType() != Material.LAVA_BUCKET) {
      return;
    }
    if (!currentItem.hasItemMeta()) {
      return;
    }
    if (!currentItem.getItemMeta().getDisplayName().equals(ChatColor.GREEN + "Lava drip")) {
      return;
    }

    plot.addParticle(new Particle(player.getLocation(), ParticleType.LAVA_DRIP));
    e.setCancelled(true);
  }
 @Override
 protected void onInventoryClick(InventoryClickEvent event, Player player) {
   event.setCancelled(true);
   final int slot = event.getRawSlot();
   if (slot >= 0 && slot <= 7) {
     // handle changing sell stack size
     ItemStack item = event.getCurrentItem();
     if (item != null && item.getType() != Material.AIR) {
       int amount = item.getAmount();
       amount = this.getNewAmountAfterEditorClick(event, amount);
       if (amount <= 0) amount = 1;
       if (amount > item.getMaxStackSize()) amount = item.getMaxStackSize();
       item.setAmount(amount);
     }
   } else if ((slot >= 9 && slot <= 16) || (slot >= 18 && slot <= 25)) {
     if (((TradingPlayerShopkeeper) shopkeeper).clickedItem != null) {
       // placing item
       final Inventory inventory = event.getInventory();
       Bukkit.getScheduler()
           .runTaskLater(
               ShopkeepersPlugin.getInstance(),
               new Runnable() {
                 public void run() {
                   inventory.setItem(slot, ((TradingPlayerShopkeeper) shopkeeper).clickedItem);
                   ((TradingPlayerShopkeeper) shopkeeper).clickedItem = null;
                 }
               },
               1);
     } else {
       // changing stack size
       ItemStack item = event.getCurrentItem();
       if (item != null && item.getType() != Material.AIR) {
         int amount = item.getAmount();
         amount = this.getNewAmountAfterEditorClick(event, amount);
         if (amount <= 0) {
           event.getInventory().setItem(slot, null);
         } else {
           if (amount > item.getMaxStackSize()) amount = item.getMaxStackSize();
           item.setAmount(amount);
         }
       }
     }
   } else if (slot >= 27) {
     // clicking in player inventory
     if (event.isShiftClick() || !event.isLeftClick()) {
       return;
     }
     ItemStack cursor = event.getCursor();
     if (cursor != null && cursor.getType() != Material.AIR) {
       return;
     }
     ItemStack current = event.getCurrentItem();
     if (current != null && current.getType() != Material.AIR) {
       ((TradingPlayerShopkeeper) shopkeeper).clickedItem = current.clone();
       ((TradingPlayerShopkeeper) shopkeeper).clickedItem.setAmount(1);
     }
   } else {
     super.onInventoryClick(event, player);
   }
 }
 public static void onInventoryClick(InventoryClickEvent e) {
   if (!(e.getWhoClicked() instanceof Player)) return;
   Player p = (Player) e.getWhoClicked();
   if (gunBuilder.get(p) == true) {
     if (gunBuilderStep.get(p) >= 7) {
       e.setCancelled(true);
     }
   }
 }
Beispiel #7
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(',', '.'));
      }
    }
  }
  @EventHandler(ignoreCancelled = true, priority = EventPriority.NORMAL)
  public void onInventoryClick(InventoryClickEvent event) {
    if (!(event.getInventory().getHolder() instanceof Player)) return;
    Player p = (Player) event.getInventory().getHolder();
    ItemStack i = event.getCurrentItem();
    if (p == null) return;
    if (i == null) return;
    if (!p.hasPermission("orbia.keepitems") && !p.getGameMode().equals(GameMode.CREATIVE)) return;

    if (!itemHandler.isCustomItem(i) && remove.contains(i.getType())) p.getInventory().remove(i);
  }
  protected static List<Entry<ItemStack, Integer>> getChangesClick(InventoryClickEvent event) {
    // Create
    List<Entry<ItemStack, Integer>> ret = new MassiveList<>();

    // Fill
    final InventoryAlter alter = InventoryUtil.getAlter(event);
    final InventoryAction action = event.getAction();
    ItemStack item;
    int amount;

    // Give
    if (alter.isGiving()) {
      // Special > MOVE_TO_OTHER_INVENTORY
      if (action == InventoryAction.MOVE_TO_OTHER_INVENTORY) {
        item = event.getCurrentItem();

        ItemStack compare = item.clone();
        compare.setAmount(1);
        amount = InventoryUtil.roomLeft(event.getInventory(), compare, item.getAmount());
      }
      // Special > HOTBAR_SWAP
      else if (action == InventoryAction.HOTBAR_SWAP) {
        item = event.getView().getBottomInventory().getItem(event.getHotbarButton());

        amount = item.getAmount();
      }
      // Normal
      else {
        item = event.getCursor();

        amount = item.getAmount();
        if (action == InventoryAction.PLACE_ONE) {
          amount = 1;
        } else if (action == InventoryAction.PLACE_SOME) {
          int max = event.getCurrentItem().getType().getMaxStackSize();
          amount = max - event.getCurrentItem().getAmount();
        }
      }

      amount *= -1;
      ret.add(new SimpleEntry<ItemStack, Integer>(item, amount));
    }

    // Take
    if (alter.isTaking()) {
      item = event.getCurrentItem();

      amount = item.getAmount();
      if (action == InventoryAction.PICKUP_ONE) amount = 1;
      if (action == InventoryAction.PICKUP_HALF) amount = (int) Math.ceil(amount / 2.0);

      ret.add(new SimpleEntry<ItemStack, Integer>(item, amount));
    }

    // Return
    return ret;
  }
Beispiel #10
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 onInventoryClickEvent(InventoryClickEvent e) {
    Entity entity = e.getWhoClicked();

    if (entity instanceof Player) {
      Player p = (Player) entity;

      if (Commands.tmpArmor.containsKey(
          p)) { // Don't let them throw away out armor if we're storing theirs!
        e.setCancelled(true);
      }
    }
  }
Beispiel #12
0
 @ClickHandler(
     status = {
       tNpcStatus.SELL,
       tNpcStatus.BUY,
       tNpcStatus.SELL_AMOUNTS,
       tNpcStatus.MANAGE_BUY,
       tNpcStatus.MANAGE_SELL
     },
     shift = true,
     inventory = InventoryType.PLAYER)
 public void botShift(InventoryClickEvent e) {
   if (e.isShiftClick()) e.setCancelled(true);
 }
 @EventHandler
 public void onArmorSlot(InventoryClickEvent e) {
   if (e.getSlotType().equals(InventoryType.SlotType.ARMOR)) {
     HumanEntity entity = (HumanEntity) e.getWhoClicked();
     Player player = (Player) entity;
     String pn = player.getName();
     String kit = Main.getKit().get(pn);
     if (kit.equalsIgnoreCase("hidden")) {
       e.setCancelled(true);
     }
     return;
   }
   return;
 }
  @EventHandler(priority = EventPriority.NORMAL)
  public void onInventoryClick(InventoryClickEvent event) {

    if (!isItemInfoBook(event.getCursor())) {
      return;
    }

    if (!isPlace(event.getAction())) {
      return;
    }

    if (isInventory(event.getInventory())) {
      return;
    }

    if ((event.getRawSlot() - event.getView().getTopInventory().getSize()) >= 0) {
      return;
    }

    Module.sendMessage(
        "bInfoBooks",
        (Player) event.getWhoClicked(),
        "You can't store InfoBooks. Please drop the InfoBook to remove it from your inventory.");
    Module.sendMessage(
        "bInfoBooks",
        (Player) event.getWhoClicked(),
        "You can get another copy of the book via the '/book' command.");
    event.setResult(Result.DENY);
  }
Beispiel #15
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);
     }
   }
 }
Beispiel #16
0
 @EventHandler
 public void onInventoryClick(InventoryClickEvent event) {
   Inventory inventory = event.getInventory();
   if (inventory.getName().equals(i.getName())) {
     event.setCancelled(true);
     Player player = (Player) event.getWhoClicked();
     ItemStack stack = event.getCurrentItem();
     if (stack == null || !stack.hasItemMeta()) return;
     if (stack.getItemMeta().getDisplayName().equals("Une pomme g閚iale !")) {
       player.closeInventory();
       player.sendMessage(
           "Bravo, tu viens de cliquer sur " + stack.getItemMeta().getDisplayName() + " !");
       player.addPotionEffect(PotionEffectType.FIRE_RESISTANCE.createEffect(Integer.MAX_VALUE, 2));
     }
   }
 }
  @EventHandler
  public void ItemMoveEvent(InventoryClickEvent event) {
    Inventory inv = event.getClickedInventory();

    if (event.getClickedInventory() == null) {
      return;
    }
    if (!event
        .getClickedInventory()
        .getName()
        .equals(ChatColor.GREEN + "" + ChatColor.BOLD + "PLACE ITEMS BELOW")) {
      return;
    }

    trademanager.updateTradeInv((Player) event.getWhoClicked());
    // trademanager.loadNewInv(inv.getViewers());
  }
Beispiel #18
0
  @EventHandler
  public void handleClick(InventoryClickEvent event) {
    if (event.getInventory().getName().equals(name)) {
      event.setCancelled(true);

      int slot = event.getRawSlot();

      if (slot >= 0 && slot < size && items[slot] != null) {
        GUIClickEvent e = new GUIClickEvent(slot, (Player) event.getWhoClicked(), spawner);
        Bukkit.getPluginManager().callEvent(e);

        if (e.willClose()) {
          event.getWhoClicked().getOpenInventory().close();
        }
      }
    }
  }
 @EventHandler(ignoreCancelled = true)
 public void onPrefsMenuClick(InventoryClickEvent event) {
   Inventory inv = event.getInventory();
   String name = inv.getTitle();
   if (name.equals("§4TARDIS Key Prefs Menu")) {
     Player p = (Player) event.getWhoClicked();
     int slot = event.getRawSlot();
     if (slot >= 0 && slot < 27) {
       switch (slot) {
         case 0:
         case 1:
         case 2:
         case 3:
         case 4:
         case 5:
         case 6:
         case 7:
         case 8:
         case 10:
         case 12:
         case 14:
         case 16:
           event.setCancelled(true);
           // set display name of key in slot 18
           ItemStack key = inv.getItem(18);
           if (key == null || !key.getType().equals(Material.GOLD_NUGGET) || !key.hasItemMeta()) {
             return;
           }
           // get Display name of selected key
           ItemStack choice = inv.getItem(slot);
           ItemMeta choice_im = choice.getItemMeta();
           String choice_name = choice_im.getDisplayName();
           ItemMeta sonic_im = key.getItemMeta();
           sonic_im.setDisplayName(choice_name);
           key.setItemMeta(sonic_im);
           break;
         case 18:
           break;
         case 26:
           // close
           event.setCancelled(true);
           close(p);
           break;
         default:
           event.setCancelled(true);
           break;
       }
     } else {
       ClickType click = event.getClick();
       if (click.equals(ClickType.SHIFT_RIGHT) || click.equals(ClickType.SHIFT_LEFT)) {
         event.setCancelled(true);
       }
     }
   }
 }
	@EventHandler(priority = EventPriority.LOWEST)
	public void onInventoryClickEvent(final InventoryClickEvent event)
	{
		if (event.getView().getTopInventory().getType() == InventoryType.PLAYER)
		{
			final IUser user = userMap.getUser((Player)event.getWhoClicked());
			final InventoryHolder invHolder = event.getView().getTopInventory().getHolder();
			if (invHolder != null && invHolder instanceof Player)
			{
				final IUser invOwner = userMap.getUser((Player)invHolder);
				if (user.isInvSee() && (!Permissions.INVSEE_MODIFY.isAuthorized(user) || Permissions.INVSEE_PREVENT_MODIFY.isAuthorized(
										invOwner) || !invOwner.isOnline()))
				{
					event.setCancelled(true);
				}
			}
		}
		if (event.getView().getTopInventory().getType() == InventoryType.WORKBENCH)
		{
			final IUser user = userMap.getUser((Player)event.getWhoClicked());
			if (user.isRecipeSee())
			{
				event.setCancelled(true);
			}
		}
	}
Beispiel #21
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();
 }
  @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);
  }
Beispiel #23
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());
 }
Beispiel #24
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);
  }
  @Override
  public void clicked(InventoryClickEvent event) {
    int slot = event.getRawSlot();
    event.setCancelled(true);
    if (event.getSlotType() == InventoryType.SlotType.CONTAINER) {
      target = players.get(slot);
      Player player = target != null ? target.get() : null;
      if (player != null) {
        Mage mage = actionContext.getMage();
        mage.deactivateGUI();
        actionContext.setTargetEntity(player);
        actionContext.setTargetLocation(player.getLocation());
        actionContext.playEffects("player_selected");
      }

      players.clear();
      active = false;
    }
  }
Beispiel #26
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;
 }
Beispiel #27
0
  @EventHandler(priority = EventPriority.LOW)
  public void onInventoryClick(InventoryClickEvent event) {
    if (event.getWhoClicked() instanceof Player == false) {
      event.setCancelled(true);
      return;
    }

    Player player = (Player) event.getWhoClicked();
    Client client = Client.getClient(player);

    if ((client.isObserver() || !Rixor.getRotation().getSlot().getMatch().isCurrentlyRunning())
        && event.getInventory().getType() != InventoryType.PLAYER) {
      event.setCancelled(true);
      return;
    }

    if (!client.isObserver()) {
      /*Map map = Rixor.getRotation().getSlot().getMap();
       */
    }
  }
 private int findNewSlot(InventoryClickEvent event) {
   int from = -1, to = -2;
   switch (event.getSlotType()) {
     case QUICKBAR:
       from = 9;
       to = 35;
       break;
     case CONTAINER:
       from = 0;
       to = 8;
       break;
     default:
       break;
   }
   for (int i = from; i <= to; i++) {
     if (event.getWhoClicked().getInventory().getItem(i) == null) {
       return i;
     }
   }
   return -1;
 }
Beispiel #29
0
 @EventHandler
 public void onInventoryClick(InventoryClickEvent event) {
   Inventory inventory = event.getInventory();
   if (inventory.getHolder() instanceof dNPC) {
     dNPC npc = (dNPC) inventory.getHolder();
     npc.getInventory().setContents(inventory.getContents());
     Equipment equipment = npc.getEquipmentTrait();
     for (int i = 0; i < 5; i++) {
       equipment.set(i, inventory.getItem(i));
     }
   }
 }
Beispiel #30
0
  /**
   * This method will return the ItemStack the player is trying to equip. If the click event would
   * not result in equipping something null will be returned. Note that this algorithm is not
   * perfect. It's an adequate guess.
   *
   * @param event The InventoryClickEvent to analyze.
   * @return The ItemStack the player is trying to equip.
   */
  public static ItemStack isEquipping(InventoryClickEvent event) {
    boolean isShiftClick = event.isShiftClick();
    InventoryType inventoryType = event.getInventory().getType();
    SlotType slotType = event.getSlotType();
    ItemStack cursor = event.getCursor();
    ItemStack currentItem = event.getCurrentItem();

    if (isShiftClick) {
      if (inventoryType != InventoryType.CRAFTING) return null;
      if (slotType == SlotType.CRAFTING) return null;
      if (slotType == SlotType.ARMOR) return null;
      if (slotType == SlotType.RESULT) return null;
      if (currentItem.getType() == Material.AIR) return null;
      return currentItem;
    } else {
      if (slotType == SlotType.ARMOR) {
        return cursor;
      }
      return null;
    }
  }