cn.nukkit.inventory.PlayerInventory Java Examples
The following examples show how to use
cn.nukkit.inventory.PlayerInventory.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: EntityItem.java From Jupiter with GNU General Public License v3.0 | 5 votes |
@Override public void onCollideWithPlayer(Player player) { if(this.getPickupDelay() > 0) { return; } Item item = this.getItem(); PlayerInventory playerInventory = player.getInventory(); if(!(item instanceof Item) || (player.isSurvival() && !playerInventory.canAddItem(item))) { return; } InventoryPickupItemEvent ev; this.server.getPluginManager().callEvent(ev = new InventoryPickupItemEvent(playerInventory, this)); if(ev.isCancelled()) { return; } TakeItemEntityPacket pk = new TakeItemEntityPacket(); pk.entityRuntimeId = player.getId(); pk.target = this.getId(); Server.broadcastPacket(this.getViewers().values(), pk); playerInventory.addItem(item); this.kill(); }
Example #2
Source File: EntityArrow.java From Jupiter with GNU General Public License v3.0 | 5 votes |
@Override public void onCollideWithPlayer(Player player) { if(!this.hadCollision) { return; } Item item = new Item(Item.ARROW, 0, 1); PlayerInventory playerInventory = player.getInventory(); if(player.isSurvival() && playerInventory.canAddItem(item)) { return; } InventoryPickupArrowEvent ev; this.server.getPluginManager().callEvent(ev = new InventoryPickupArrowEvent(playerInventory, this)); if(ev.isCancelled()) { return; } TakeItemEntityPacket pk = new TakeItemEntityPacket(); pk.entityRuntimeId = player.getId(); pk.target = this.getId(); Server.broadcastPacket(this.getViewers().values(), pk); playerInventory.addItem(item); this.kill(); }
Example #3
Source File: InventoryTransaction.java From Nukkit with GNU General Public License v3.0 | 5 votes |
protected void sendInventories() { for (Inventory inventory : this.inventories) { inventory.sendContents(this.source); if (inventory instanceof PlayerInventory) { ((PlayerInventory) inventory).sendArmorContents(this.source); } } }
Example #4
Source File: BrushListener.java From FastAsyncWorldedit with GNU General Public License v3.0 | 5 votes |
@EventHandler(priority = EventPriority.MONITOR, ignoreCancelled = true) public void onPlayerItemHoldEvent(final PlayerItemHeldEvent event) { Player nukkitPlayer = event.getPlayer(); if (nukkitPlayer.isSneaking()) { return; } FawePlayer<Object> fp = FawePlayer.wrap(nukkitPlayer); com.sk89q.worldedit.entity.Player player = fp.getPlayer(); LocalSession session = fp.getSession(); Tool tool = session.getTool(player); if (tool instanceof ScrollTool) { final int slot = event.getInventorySlot(); final int oldSlot = event.getSlot(); final int ri; if ((((slot - oldSlot) <= 4) && ((slot - oldSlot) > 0)) || (((slot - oldSlot) < -4))) { ri = 1; } else { ri = -1; } ScrollTool scrollable = (ScrollTool) tool; if (scrollable.increment(player, ri)) { final PlayerInventory inv = nukkitPlayer.getInventory(); final Item item = inv.getItem(slot); final Item newItem = inv.getItem(oldSlot); inv.setItem(slot, newItem); inv.setItem(oldSlot, item); inv.sendContents(nukkitPlayer); } } }
Example #5
Source File: NukkitPlayerBlockBag.java From FastAsyncWorldedit with GNU General Public License v3.0 | 5 votes |
/** * Loads inventory on first use. */ private void loadInventory() { if (items == null) { PlayerInventory inv = player.getInventory(); items = inv.getContents(); this.size = inv.getSize(); } }
Example #6
Source File: NukkitPlayer.java From FastAsyncWorldedit with GNU General Public License v3.0 | 5 votes |
@Override public BaseBlock getBlockInHand() throws WorldEditException { PlayerInventory inv = player.getInventory(); Item itemStack = inv.getItemInHand(); if (itemStack == null) { return EditSession.nullBlock; } return new BaseBlock(itemStack.getId(), itemStack.getMaxDurability() != 0 ? 0 : itemStack.getDamage()); }
Example #7
Source File: InventoryTransaction.java From Nukkit with GNU General Public License v3.0 | 5 votes |
protected void sendInventories() { for (Inventory inventory : this.inventories) { inventory.sendContents(this.source); if (inventory instanceof PlayerInventory) { ((PlayerInventory) inventory).sendArmorContents(this.source); } } }
Example #8
Source File: EntityHumanType.java From Jupiter with GNU General Public License v3.0 | 4 votes |
@Override public PlayerInventory getInventory() { return inventory; }
Example #9
Source File: EntityHumanType.java From Nukkit with GNU General Public License v3.0 | 4 votes |
@Override public PlayerInventory getInventory() { return inventory; }
Example #10
Source File: NukkitPlayer.java From FastAsyncWorldedit with GNU General Public License v3.0 | 4 votes |
@Override public int getItemInHand() { PlayerInventory inv = player.getInventory(); Item itemStack = inv.getItemInHand(); return itemStack != null ? itemStack.getId() : 0; }
Example #11
Source File: EntityHumanType.java From Nukkit with GNU General Public License v3.0 | 4 votes |
@Override public PlayerInventory getInventory() { return inventory; }