public InventoryView openWorkbench(Location location, boolean force) { if (!force) { Block block = location.getBlock(); if (block.getType() != Material.WORKBENCH) { return null; } } if (location == null) { location = getLocation(); } getHandle().displayGUIWorkbench(location.getBlockX(), location.getBlockY(), location.getBlockZ()); if (force) { getHandle().openContainer.checkReachable = false; } return getHandle().openContainer.getBukkitView(); }
public InventoryView openEnchanting(Location location, boolean force) { if (!force) { Block block = location.getBlock(); if (block.getType() != Material.ENCHANTMENT_TABLE) { return null; } } if (location == null) { location = getLocation(); } getHandle().displayGUIEnchantment(location.getBlockX(), location.getBlockY(), location.getBlockZ(), null); if (force) { getHandle().openContainer.checkReachable = false; } return getHandle().openContainer.getBukkitView(); }
public CraftContainer(final Inventory inventory, final HumanEntity player, int id) { this(new InventoryView() { @Override public Inventory getTopInventory() { return inventory; } @Override public Inventory getBottomInventory() { return player.getInventory(); } @Override public HumanEntity getPlayer() { return player; } @Override public InventoryType getType() { return inventory.getType(); } }, id); }
/** * Register the given {@link WindowListener} to receive notifications about the given {@link InventoryView}. */ public InventoryView registerWindow(WindowListener listener, InventoryView window) { final Player player = (Player) window.getPlayer(); final View old = views.get(player); if(old == null || !old.window.equals(window)) { if(old != null) { old.notifyClose(); } final View view = new View(player, window, listener); views.put(player, view); view.notifyOpen(); } return window; }
@EventHandler(priority = EventPriority.MONITOR) public void afterEquipChange(final InventoryDragEvent event) { final Player player = (Player) event.getWhoClicked(); if (!InventoryManager.playerIsLoaded(player)) { return; } new BukkitRunnable() { @Override public void run() { InventoryView inventoryView = event.getView(); for (int slot : event.getRawSlots()) { ItemStack item = inventoryView.getItem(slot); if (CustomItem.isCustomItem(item)) { ItemManager.updateStats((Player) event.getWhoClicked()); } } } }.runTaskLater(RPGInventory.getInstance(), 1); }
@Override public void run() { AgarMC plugin = AgarMC.get(); if (plugin.getGame().getPlayers().isEmpty()) return ; if(plugin.getGame().getVirus().size() < plugin.getGame().getMaxVirus()) { VirusCell virus = new VirusCell(Utils.randomLocation(plugin.getGame().getOrigin().getX(), plugin.getGame().getDimensions()), Utils.randomLocation(plugin.getGame().getOrigin().getZ(), plugin.getGame().getDimensions())); plugin.getGame().addVirus(virus); } for (CPlayer player : plugin.getGame().getPlayers()) { player.getPlayer().getInventory().setItem(1, updateColorBlock(player.getPlayer().getInventory().getItem(1))); InventoryView iv = player.getPlayer().getOpenInventory(); if (iv == null) continue ; Inventory i = iv.getTopInventory(); if (i == null || !i.getName().equals(MenuGui.INV_NAME)) continue ; i.setItem(0, updateColorBlock(i.getItem(0))); } }
@EventHandler public void onRepair(InventoryClickEvent event) { if(event.isCancelled() || !(event.getWhoClicked() instanceof Player) || !(event.getInventory() instanceof AnvilInventory)) return; InventoryView view = event.getView(); int rawSlot = event.getRawSlot(); if(rawSlot != view.convertSlot(rawSlot) || rawSlot != 2) return; ItemStack item = event.getInventory().getItem(0); if(!plugin.getAbilityManager().hasAbility(item) || !plugin.getAbilityManager().isTemporaryItem(item)) return; Ability ability = plugin.getAbilityManager().getAbility(item); event.getInventory().setItem(0, plugin.getAbilityManager().removeItemLore(item, ability)); event.setCancelled(true); }
public InventoryDragEvent(InventoryView what, ItemStack newCursor, ItemStack oldCursor, boolean right, Map<Integer, ItemStack> slots) { super(what); Validate.notNull(oldCursor); Validate.notNull(slots); type = right ? DragType.SINGLE : DragType.EVEN; this.newCursor = newCursor; this.oldCursor = oldCursor; this.addedItems = slots; ImmutableSet.Builder<Integer> b = ImmutableSet.builder(); for (Integer slot : slots.keySet()) { b.add(what.convertSlot(slot)); } this.containerSlots = b.build(); }
public static InventoryView showPerkMenu(BPPlayer bpPlayer) { Player player = bpPlayer.getPlayer(); List<Perk> perks = bpPlayer.getPerks(); if(perks.size() <= 0) { player.sendMessage(MessageType.MENU_PERKS_EMPTY.getTranslation().getValue()); return null; } int rows = bpPlayer.getPerkInventoryRows(); Inventory inv = Bukkit.getServer().createInventory(player, 9 * rows, MENU_TITLE); equipMenu(bpPlayer, inv); player.closeInventory(); return player.openInventory(inv); }
public InventoryView openWorkbench(Location location, boolean force) { if (!force) { Block block = location.getBlock(); if (block.getType() != Material.WORKBENCH) { return null; } } if (location == null) { location = getLocation(); } getHandle().openTileEntity(new BlockWorkbench.TileEntityContainerWorkbench(getHandle().world, new BlockPosition(location.getBlockX(), location.getBlockY(), location.getBlockZ()))); if (force) { getHandle().activeContainer.checkReachable = false; } return getHandle().activeContainer.getBukkitView(); }
public InventoryView openWorkbench(Location location, boolean force) { if (!force) { Block block = location.getBlock(); if (block.getType() != Material.WORKBENCH) { return null; } } if (location == null) { location = getLocation(); } getHandle().startCrafting(location.getBlockX(), location.getBlockY(), location.getBlockZ()); if (force) { getHandle().activeContainer.checkReachable = false; } return getHandle().activeContainer.getBukkitView(); }
public InventoryView openEnchanting(Location location, boolean force) { if (!force) { Block block = location.getBlock(); if (block.getType() != Material.ENCHANTMENT_TABLE) { return null; } } if (location == null) { location = getLocation(); } getHandle().startEnchanting(location.getBlockX(), location.getBlockY(), location.getBlockZ(), null); if (force) { getHandle().activeContainer.checkReachable = false; } return getHandle().activeContainer.getBukkitView(); }
@Override public boolean isOpenFor(Player p) { InventoryView iview = p.getOpenInventory(); if(null == iview) return false; Inventory inv = iview.getTopInventory(); if(null == inv) return false; InventoryHolder holder = inv.getHolder(); if(!(holder instanceof BusyHolder)) return false; IBusyMenu menu = ((BusyHolder)holder).getMenu(); if(!menu.equals(this)) return false; return true; }
/** * If a BusyMenu is opened for the target player, this method will reload * the menu for the player. * * @see {@link IBusyMenu#reload} * * @param p * Target player * @return true if and only if the menu is reloaded. Otherwise false(for * example the player didn't open an inventory or the inventory * isn't a menu) */ public static boolean reloadFor(Player p) { InventoryView iview = p.getOpenInventory(); if(null == iview) return false; Inventory inv = iview.getTopInventory(); if(null == inv) return false; InventoryHolder holder = inv.getHolder(); if(!(holder instanceof BusyHolder)) return false; ((BusyHolder)holder).getMenu().updateFor(p); p.updateInventory(); return true; }
public void clearInventory(Player p) { PlayerInventory inv = p.getInventory(); inv.clear(); inv.setHelmet(null); inv.setChestplate(null); inv.setLeggings(null); inv.setBoots(null); InventoryView view = p.getOpenInventory(); if (view != null) { view.setCursor(null); Inventory i = view.getTopInventory(); if (i != null) { i.clear(); } } }
public CraftContainer(InventoryView view, int id) { this.view = view; this.windowId = id; // TODO: Do we need to check that it really is a CraftInventory? net.minecraft.inventory.IInventory top = ((CraftInventory)view.getTopInventory()).getInventory(); net.minecraft.inventory.IInventory bottom = ((CraftInventory)view.getBottomInventory()).getInventory(); cachedType = view.getType(); cachedTitle = view.getTitle(); cachedSize = getSize(); setupSlots(top, bottom); }