/** * Sets one item in this inventory view by its raw slot ID. * <p> * Note: If slot ID -999 is chosen, it may be expected that the item is * dropped on the ground. This is not required behaviour, however. * * @param slot The ID as returned by InventoryClickEvent.getRawSlot() * @param item The new item to put in the slot, or null to clear it. */ public void setItem(int slot, ItemStack item) { if (slot != OUTSIDE) { if (slot < getTopInventory().getSize()) { getTopInventory().setItem(convertSlot(slot),item); } else { getBottomInventory().setItem(convertSlot(slot),item); } } else { getPlayer().getWorld().dropItemNaturally(getPlayer().getLocation(), item); } }
@EventHandler public void onClose(InventoryCloseEvent e) { if (Variables.enchanting.containsKey(e.getPlayer().getUniqueId())) Variables.enchanting.remove(e.getPlayer().getUniqueId()); if (Variables.backpack.containsKey(e.getPlayer().getUniqueId())) { ((Player) e.getPlayer()).playSound(e.getPlayer().getLocation(), Sound.ENTITY_HORSE_ARMOR, 1F, 1F); Backpacks.saveBackpack(e.getInventory(), Variables.backpack.get(e.getPlayer().getUniqueId())); Variables.backpack.remove(e.getPlayer().getUniqueId()); } }
/** * Sets one item in this inventory view by its raw slot ID. * <p> * Note: If slot ID -999 is chosen, it may be expected that the item is * dropped on the ground. This is not required behaviour, however. * * @param slot The ID as returned by InventoryClickEvent.getRawSlot() * @param item The new item to put in the slot, or null to clear it. */ public void setItem(int slot, ItemStack item) { if (slot != OUTSIDE) { if (slot < getTopInventory().getSize()) { getTopInventory().setItem(convertSlot(slot),item); } else { getBottomInventory().setItem(convertSlot(slot),item); } } else { getPlayer().getWorld().dropItemNaturally(getPlayer().getLocation(), item); } }
@EventHandler public void inventoryClick(InventoryClickEvent e) { if (e.getInventory().getHolder() instanceof SoundLibraryHolder) { e.setCancelled(true); if (e.getCurrentItem() == null || e.getCurrentItem().getType().equals(Material.AIR) || e.getRawSlot() >= e.getInventory().getSize()) { return; } SoundLibraryHolder soundLibraryHolder = ((SoundLibraryHolder) e.getInventory().getHolder()); int i = e.getRawSlot(); if (i == 47) { openInventory((Player) e.getWhoClicked(), soundLibraryHolder.PAGE - 1, soundLibraryHolder.SEARCH); } else if (i == 51) { openInventory((Player) e.getWhoClicked(), soundLibraryHolder.PAGE + 1, soundLibraryHolder.SEARCH); } else { Sound sound = soundLibraryHolder.SOUNDS_DATA.get(e.getRawSlot()); if (e.getClick().isKeyboardClick()) { ((Player) e.getWhoClicked()).playSound(e.getWhoClicked().getLocation(), sound, 1f, 0f); } else if (e.getClick().isLeftClick()) { ((Player) e.getWhoClicked()).playSound(e.getWhoClicked().getLocation(), sound, 1f, 1f); } else if (e.getClick().isRightClick()) { ((Player) e.getWhoClicked()).playSound(e.getWhoClicked().getLocation(), sound, 1f, 2f); } else if (e.getClick().isCreativeAction()) { TLocale.sendTo(e.getWhoClicked(), "COMMANDS.TABOOLIB.SOUNDS.RESULT.COPY", sound.name()); } } } }
@EventHandler(ignoreCancelled = true) public void onInventoryClick(InventoryClickEvent event) { HumanEntity entity = event.getWhoClicked(); Inventory inventory = event.getInventory(); ItemStack item = event.getCurrentItem(); if (item != null && inventory != null && inventory.getHolder() != null && entity instanceof Player) { Player player = (Player) entity; ConfigurationManager cfg = WorldGuard.getInstance().getPlatform().getGlobalStateManager(); WorldConfiguration wcfg = cfg.get(BukkitAdapter.adapt(entity.getWorld())); LocalPlayer localPlayer = getPlugin().wrapPlayer(player); if (wcfg.getBlacklist() != null && !wcfg.getBlacklist().check( new ItemAcquireBlacklistEvent(localPlayer, BukkitAdapter.asBlockVector(entity.getLocation()), createTarget(item)), false, false)) { event.setCancelled(true); if (inventory.getHolder().equals(player)) { event.setCurrentItem(null); } } } }
@EventHandler(ignoreCancelled = true) public void onInventoryCreative(InventoryCreativeEvent event) { HumanEntity entity = event.getWhoClicked(); ItemStack item = event.getCursor(); if (item != null && entity instanceof Player) { Player player = (Player) entity; ConfigurationManager cfg = WorldGuard.getInstance().getPlatform().getGlobalStateManager(); WorldConfiguration wcfg = cfg.get(BukkitAdapter.adapt(entity.getWorld())); LocalPlayer localPlayer = getPlugin().wrapPlayer(player); if (wcfg.getBlacklist() != null && !wcfg.getBlacklist().check( new ItemAcquireBlacklistEvent(localPlayer, BukkitAdapter.asBlockVector(entity.getLocation()), createTarget(item)), false, false)) { event.setCancelled(true); event.setCursor(null); } } }
location = ((Entity) holder).getLocation(); } else { location = event.getPlayer().getLocation();