@Override public MCItem dropItem(MCLocation l, MCItemStack is) { return new BukkitMCItem(w.dropItem(((BukkitMCLocation) l).l, ((BukkitMCItemStack) is).is)); }
@Override public void run() { try { spawnLocation.getWorld().dropItem(spawnLocation, item); } catch (NullPointerException exception) { cancel(); } } }.runTaskTimer(plugin, period, period);
/** * Drops a {@code Collection<ItemStack>} of items on a specified block. * * @param block The block to drop items on. * @param items The items to drop. */ public static void dropItems(final Block block, final Collection<ItemStack> items) { for (final ItemStack item : items) { block.getWorld().dropItem(block.getLocation(), item); } }
@Override public SpellResult perform(CastContext context) { if (item == null) { return SpellResult.FAIL; } context.getTargetLocation().getWorld().dropItem(context.getTargetLocation(), item); return SpellResult.CAST; }
public void dropIngots(final Location loc, final int amount) { final Item i = this.player.getWorld().dropItem(loc, new ItemStack(Material.IRON_INGOT, amount)); i.setPickupDelay(61); }
private static void awardDrop(Player winningPlayer, ItemStack drop) { if (winningPlayer.getInventory().addItem(drop).size() != 0) { winningPlayer.getWorld().dropItem(winningPlayer.getLocation(), drop); } winningPlayer.updateInventory(); } }
@Override public void run(String playerID) throws QuestRuntimeException { Player p = PlayerConverter.getPlayer(playerID); ItemStack[] brews = new ItemStack[amount]; for(int i = 0; i < amount; i++){ brews[i] = recipe.create(quality); } Collection<ItemStack> remaining = p.getInventory().addItem(brews).values(); for(ItemStack item : remaining) { p.getWorld().dropItem(p.getLocation(), item); } } }
@Override public void onTrigger() { final Location spawnLocation = getSign().getLocation().add(0.5, 0, 0.5); if (interval < 0) { getSign().getWorld().dropItem(spawnLocation, item); } else { long period = (long) interval * 20; new BukkitRunnable() { @Override public void run() { try { spawnLocation.getWorld().dropItem(spawnLocation, item); } catch (NullPointerException exception) { cancel(); } } }.runTaskTimer(plugin, period, period); } }
private void generate(Player p, ItemStack sonic, int cost) { // check they have enough Artron energy ResultSetTardisArtron rs = new ResultSetTardisArtron(plugin); if (rs.fromUUID(p.getUniqueId().toString())) { int level = rs.getArtronLevel(); if (cost < level) { ItemStack is = sonic.clone(); Location loc = location.clone().add(0.5d, 0.75d, 0.5d); Entity drop = location.getWorld().dropItem(loc, is); drop.setVelocity(new Vector(0, 0, 0)); plugin.getTrackerKeeper().getSonicGenerators().remove(p.getUniqueId()); // remove the Artron energy HashMap<String, Object> where = new HashMap<>(); where.put("uuid", p.getUniqueId().toString()); new QueryFactory(plugin).alterEnergyLevel("tardis", -cost, where, p); } else { TARDISMessage.send(p, "UPGRADE_ABORT_ENERGY"); } } close(p); }
@Override public boolean onBreak(Player p, Block b, SlimefunItem item, UnregisterReason reason) { Item stack = AncientAltarListener.findItem(b); if (stack != null) { stack.removeMetadata("item_placed", SlimefunStartup.instance); b.getWorld().dropItem(b.getLocation(), AncientAltarListener.fixItemStack(stack.getItemStack(), stack.getCustomName())); stack.remove(); } return true; } });
/** * Gives an item reward to a player. * * @param player * @param item * @return the reward text to display to the player */ private String rewardItem(Player player, ItemStack item) { if (player.getInventory().firstEmpty() != -1) { player.getInventory().addItem(item); } else { player.getWorld().dropItem(player.getLocation(), item); } String name = item.getItemMeta().getDisplayName(); if (name == null || name.isEmpty()) { name = rewardParser.getItemName(item); } return langItemRewardReceived + name; }
@Override public void trigger() { org.bukkit.entity.Vehicle vehicle = this.getVehicle(); // we eject the passenger vehicle.eject(); // we drop items if (ByteCart.myPlugin.keepItems()) { org.bukkit.inventory.Inventory inventory; if (vehicle instanceof InventoryHolder) { inventory = ((InventoryHolder) vehicle).getInventory(); World world = this.getBlock().getWorld(); org.bukkit.Location loc = this.getBlock().getRelative(BlockFace.UP, 2).getLocation(); ListIterator<ItemStack> it = inventory.iterator(); while (it.hasNext()) { ItemStack stack = it.next(); if (stack != null) world.dropItem(loc, stack); } } } vehicle.remove(); } }
player.getInventory().addItem(book); } else { player.getWorld().dropItem(player.getLocation(), book);
/** * Drop an item at a given location. * * @param location The location to drop the item at * @param itemStack The item to drop * @return Dropped Item entity or null if invalid or cancelled */ public static Item dropItem(Location location, ItemStack itemStack) { if (itemStack.getType() == Material.AIR) { return null; } // We can't get the item until we spawn it and we want to make it cancellable, so we have a custom event. McMMOItemSpawnEvent event = new McMMOItemSpawnEvent(location, itemStack); mcMMO.p.getServer().getPluginManager().callEvent(event); if (event.isCancelled()) { return null; } return location.getWorld().dropItem(location, itemStack); }
@Override public void giveItem(int item, int amount) { if (bukkitPlayer.getInventory().firstEmpty() == -1) { bukkitPlayer.getLocation().getWorld().dropItem(bukkitPlayer.getLocation(), new ItemStack(item, amount)); } else { bukkitPlayer.getInventory().addItem(new ItemStack(item, amount)); } }
private void cook() { final ItemStack cooked = this.getCooked(this.player.getInventory().getItemInMainHand()); final HashMap<Integer, ItemStack> cantFit = this.player.getInventory().addItem(cooked); for (final int id : cantFit.keySet()) { this.player.getWorld().dropItem(this.player.getEyeLocation(), cantFit.get(id)); } final int amount = this.player.getInventory().getItemInMainHand().getAmount(); if (amount == 1) { this.player.getInventory().clear(this.player.getInventory().getHeldItemSlot()); } else { this.player.getInventory().getItemInMainHand().setAmount(amount - 1); } }
@Override public void run(String playerID) throws QuestRuntimeException { Block block = loc.getLocation(playerID).getBlock(); InventoryHolder chest; try { chest = (InventoryHolder) block.getState(); } catch (ClassCastException e) { throw new QuestRuntimeException("Trying to put items in chest, but there's no chest! Location: X" + block.getX() + " Y" + block.getY() + " Z" + block.getZ()); } for (Item theItem : questItems) { QuestItem questItem = theItem.getItem(); int amount = theItem.getAmount().getInt(playerID); while (amount > 0) { int stackSize; if (amount > 64) { stackSize = 64; } else { stackSize = amount; } ItemStack item = questItem.generate(stackSize); HashMap<Integer, ItemStack> left = chest.getInventory().addItem(item); for (Integer leftNumber : left.keySet()) { ItemStack itemStack = left.get(leftNumber); block.getWorld().dropItem(block.getLocation(), itemStack); } amount = amount - stackSize; } } }
private void insertItem(Player p, Block b) { final ItemStack stack = p.getInventory().getItemInMainHand(); if (stack != null) { PlayerInventory.consumeItemInHand(p); String nametag = StringUtils.formatItemName(stack, false); Item entity = b.getWorld().dropItem(b.getLocation().add(0.5, 1.2, 0.5), new CustomItem(new CustomItem(stack, 1), "&5&dALTAR &3Probe - &e" + System.nanoTime())); entity.setVelocity(new Vector(0, 0.1, 0)); entity.setMetadata("no_pickup", new FixedMetadataValue(SlimefunStartup.instance, "altar_item")); entity.setCustomNameVisible(true); entity.setCustomName(nametag); p.playSound(b.getLocation(), Sound.ENTITY_ITEM_PICKUP, 0.3F, 0.3F); } }
@EventHandler(priority = EventPriority.HIGHEST) public void onWorldChange(PlayerChangedWorldEvent e){ Player p = e.getPlayer(); World w = p.getWorld(); if(!isEnabled(w)) return; PlayerInventory inv = p.getInventory(); ItemStack chestplate = inv.getChestplate(); if(chestplate == null || chestplate.getType() != Material.ELYTRA) return; inv.setChestplate(new ItemStack(Material.AIR)); if(inv.firstEmpty() != -1) inv.addItem(chestplate); else w.dropItem(p.getLocation(), chestplate); } }
public void convertHorse(Horse horse, TagCompound properties) { byte type = (byte) horse.getVariant().ordinal(); int style = horse.getStyle().ordinal(); int color = horse.getColor().ordinal(); int variant = color & 255 | style << 8; if (horse.getInventory().getArmor() != null) { TagCompound armor = MyPetApi.getPlatformHelper().itemStackToCompund(horse.getInventory().getArmor()); properties.getCompoundData().put("Armor", armor); } if (horse.getInventory().getSaddle() != null) { TagCompound saddle = MyPetApi.getPlatformHelper().itemStackToCompund(horse.getInventory().getSaddle()); properties.getCompoundData().put("Saddle", saddle); } properties.getCompoundData().put("Type", new TagByte(type)); properties.getCompoundData().put("Variant", new TagInt(variant)); properties.getCompoundData().put("Chest", new TagByte(horse.isCarryingChest())); properties.getCompoundData().put("Age", new TagInt(horse.getAge())); if (horse.isCarryingChest()) { ItemStack[] contents = horse.getInventory().getContents(); for (int i = 2; i < contents.length; i++) { ItemStack item = contents[i]; if (item != null) { horse.getWorld().dropItem(horse.getLocation(), item); } } } }