当前位置: 首页>>代码示例>>Java>>正文


Java World.dropItemNaturally方法代码示例

本文整理汇总了Java中org.bukkit.World.dropItemNaturally方法的典型用法代码示例。如果您正苦于以下问题:Java World.dropItemNaturally方法的具体用法?Java World.dropItemNaturally怎么用?Java World.dropItemNaturally使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在org.bukkit.World的用法示例。


在下文中一共展示了World.dropItemNaturally方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: onMobDie

import org.bukkit.World; //导入方法依赖的package包/类
@EventHandler
public void onMobDie(EntityDeathEvent e){
    AllItems items = new AllItems();
    Location l = e.getEntity().getLocation();
    World w = l.getWorld();

    e.getDrops().clear();
    e.setDroppedExp(0);

    if (e.getEntity() instanceof Zombie){
        if (new Random().nextInt(5) >= 3){
            w.dropItemNaturally(l, new ItemMaker(Material.EMERALD).setAmount(new Random().nextInt(4) + 1).build());
            if (new Random().nextBoolean()){
                w.dropItemNaturally(l, items.weapons.get(new Random().nextInt(items.weapons.size())));
            } else {
                w.dropItemNaturally(l, items.health.get(new Random().nextInt(items.health.size())));
            }
        }
    }

    if (e.getEntity() instanceof Giant){
        if (new Random().nextInt(5) > 3){
            w.dropItemNaturally(l, new ItemMaker(Material.NETHER_STAR).setAmount(new Random().nextInt(4) + 1).build());
        }
    }
}
 
开发者ID:cadox8,项目名称:WC,代码行数:27,代码来源:WorldInteract.java

示例2: handleWinner

import org.bukkit.World; //导入方法依赖的package包/类
/**
 * Handles the winner for this event.
 *
 * @param winner
 *            the {@link Player} that won
 */
public void handleWinner(Player winner) {
    if (this.eventFaction == null)
        return;

    PlayerFaction playerFaction = plugin.getFactionManager().getPlayerFaction(winner);
    Bukkit.broadcastMessage(ChatColor.GOLD + "[" + "WIN" + "] " + ChatColor.RED + winner.getName() + ChatColor.AQUA
            + ChatColor.YELLOW + " has captured " + ChatColor.RED + this.eventFaction.getName()
            + ChatColor.YELLOW + " after " + ChatColor.RED + DurationFormatUtils.formatDurationWords(getUptime(), true, true) + " of up-time" + ChatColor.YELLOW + '.');

    EventType eventType = this.eventFaction.getEventType();
    World world = winner.getWorld();
    Location location = winner.getLocation();
    EventKey eventKey = plugin.getKeyManager().getEventKey();
    Collection<Inventory> inventories = eventKey.getInventories(eventType);
    ItemStack keyStack = eventKey.getItemStack(new EventKey.EventKeyData(eventType, inventories.isEmpty() ? 1 : plugin.getRandom().nextInt(inventories.size()) + 1));
    Map<Integer, ItemStack> excess = winner.getInventory().addItem(keyStack, EventSignListener.getEventSign(eventFaction.getName(), winner.getName()));
    for (ItemStack entry : excess.values()) {
        world.dropItemNaturally(location, entry);
    }

    this.clearCooldown(); // must always be cooled last as this nulls some variables.
}
 
开发者ID:funkemunky,项目名称:HCFCore,代码行数:29,代码来源:EventTimer.java

示例3: onBlockBreak

import org.bukkit.World; //导入方法依赖的package包/类
@EventHandler(ignoreCancelled=true, priority=EventPriority.HIGHEST)
public void onBlockBreak(BlockBreakEvent event)
{
  Block block = event.getBlock();
  if (isEventSign(block))
  {
    BlockState state = block.getState();
    Sign sign = (Sign)state;
    ItemStack stack = new ItemStack(Material.SIGN, 1);
    ItemMeta meta = stack.getItemMeta();
    meta.setDisplayName(EVENT_SIGN_ITEM_NAME);
    meta.setLore(Arrays.asList(sign.getLines()));
    stack.setItemMeta(meta);
    
    Player player = event.getPlayer();
    World world = player.getWorld();
    Location blockLocation = block.getLocation();
    if ((player.getGameMode() != GameMode.CREATIVE) && (world.isGameRule("doTileDrops"))) {
      world.dropItemNaturally(blockLocation, stack);
    }
    event.setCancelled(true);
    block.setType(Material.AIR);
    state.update();
  }
}
 
开发者ID:funkemunky,项目名称:HCFCore,代码行数:26,代码来源:EventSignListener.java

示例4: onBlockBreak

import org.bukkit.World; //导入方法依赖的package包/类
@EventHandler(ignoreCancelled = true, priority = EventPriority.HIGHEST)
public void onBlockBreak(final BlockBreakEvent event) {
    Player player = event.getPlayer();
    if (player.getGameMode() != GameMode.CREATIVE) {
        if (player.hasPermission("hcf.listener.autosmeltore")) {
            ItemStack stack = player.getItemInHand();
            if (stack != null && stack.getType() != Material.AIR
                    && !stack.containsEnchantment(Enchantment.SILK_TOUCH)) {
                Block block = event.getBlock();
                Material dropType = null;
                switch (block.getType()) {
                    case IRON_ORE: {
                        dropType = Material.IRON_INGOT;
                        break;
                    }
                    case GOLD_ORE: {
                        dropType = Material.GOLD_INGOT;
                        break;
                    }
                    default: {
                        return;
                    }
                }
                 Location location = block.getLocation();
                 World world = location.getWorld();
                 ItemStack drop = new ItemStack(dropType, 1);
                world.dropItemNaturally(location, drop);
                block.setType(Material.AIR);
                block.getState().update();
            }
        }
    }
}
 
开发者ID:funkemunky,项目名称:HCFCore,代码行数:34,代码来源:AutoSmeltOreListener.java

示例5: onPlayerInteract

import org.bukkit.World; //导入方法依赖的package包/类
@EventHandler(ignoreCancelled = false, priority = EventPriority.HIGH)
public void onPlayerInteract(PlayerInteractEvent event) {
    if (event.getAction() == Action.RIGHT_CLICK_BLOCK) {
        Block block = event.getClickedBlock();
        BlockState state = block.getState();
        if (state instanceof Sign) {
            Sign sign = (Sign) state;
            String[] lines = sign.getLines();

            Integer quantity = JavaUtils.tryParseInt(lines[2]);
            if (quantity == null)
                return;

            Integer price = JavaUtils.tryParseInt(ALPHANUMERIC_REMOVER.matcher(lines[3]).replaceAll(""));
            if (price == null)
                return;

            ItemStack stack;
            if (lines[1].equalsIgnoreCase("Crowbar")) {
                stack = new Crowbar().getItemIfPresent();
            } else if ((stack = BasePlugin.getPlugin().getItemDb().getItem(ALPHANUMERIC_REMOVER.matcher(lines[1]).replaceAll(""), quantity)) == null) {
                return;
            }

            // Final handling of shop.
            Player player = event.getPlayer();
            String[] fakeLines = Arrays.copyOf(sign.getLines(), 4);
            if (lines[0].contains("Sell") && lines[0].contains(ChatColor.RED.toString())) {
                int sellQuantity = Math.min(quantity, InventoryUtils.countAmount(player.getInventory(), stack.getType(), stack.getDurability()));
                if (sellQuantity <= 0) {
                    fakeLines[0] = ChatColor.RED + "Not carrying any";
                    fakeLines[2] = ChatColor.RED + "on you.";
                    fakeLines[3] = "";
                } else {
                    // Recalculate the price.
                    int newPrice = (int) (((double) price / (double) quantity) * (double) sellQuantity);
                    fakeLines[0] = ChatColor.GREEN + "Sold " + sellQuantity;
                    fakeLines[3] = ChatColor.GREEN + "for " + EconomyManager.ECONOMY_SYMBOL + newPrice;

                    plugin.getEconomyManager().addBalance(player.getUniqueId(), newPrice);
                    InventoryUtils.removeItem(player.getInventory(), stack.getType(), stack.getData().getData(), sellQuantity);
                    player.updateInventory();
                }
            } else if (lines[0].contains("Buy") && lines[0].contains(ChatColor.GREEN.toString())) {
                if (price > plugin.getEconomyManager().getBalance(player.getUniqueId())) {
                    fakeLines[0] = ChatColor.RED + "Cannot afford";
                } else {
                    fakeLines[0] = ChatColor.GREEN + "Item bought";
                    fakeLines[3] = ChatColor.GREEN + "for " + EconomyManager.ECONOMY_SYMBOL + price;
                    plugin.getEconomyManager().subtractBalance(player.getUniqueId(), price);

                    World world = player.getWorld();
                    Location location = player.getLocation();
                    Map<Integer, ItemStack> excess = player.getInventory().addItem(stack);
                    for (Map.Entry<Integer, ItemStack> excessItemStack : excess.entrySet()) {
                        world.dropItemNaturally(location, excessItemStack.getValue());
                    }

                    player.setItemInHand(player.getItemInHand()); // resend held item packet.
                }
            } else {
                return;
            }

            event.setCancelled(true);
            BasePlugin.getPlugin().getSignHandler().showLines(player, sign, fakeLines, SIGN_TEXT_REVERT_TICKS, true);
        }
    }
}
 
开发者ID:funkemunky,项目名称:HCFCore,代码行数:70,代码来源:ShopSignListener.java


注:本文中的org.bukkit.World.dropItemNaturally方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。