當前位置: 首頁>>代碼示例>>Java>>正文


Java PlayerInventory.removeItem方法代碼示例

本文整理匯總了Java中org.bukkit.inventory.PlayerInventory.removeItem方法的典型用法代碼示例。如果您正苦於以下問題:Java PlayerInventory.removeItem方法的具體用法?Java PlayerInventory.removeItem怎麽用?Java PlayerInventory.removeItem使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在org.bukkit.inventory.PlayerInventory的用法示例。


在下文中一共展示了PlayerInventory.removeItem方法的4個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: processGreenTerra

import org.bukkit.inventory.PlayerInventory; //導入方法依賴的package包/類
/**
 * Process the Green Terra ability.
 *
 * @param blockState The {@link BlockState} to check ability activation for
 * @return true if the ability was successful, false otherwise
 */
public boolean processGreenTerra(BlockState blockState) {
    Player player = getPlayer();

    if (!Permissions.greenThumbBlock(player, blockState.getType())) {
        return false;
    }

    PlayerInventory playerInventory = player.getInventory();
    ItemStack seed = new ItemStack(Material.SEEDS);

    if (!playerInventory.containsAtLeast(seed, 1)) {
        player.sendMessage(LocaleLoader.getString("Herbalism.Ability.GTe.NeedMore"));
        return false;
    }

    playerInventory.removeItem(seed);
    player.updateInventory(); // Needed until replacement available

    return Herbalism.convertGreenTerraBlocks(blockState);
}
 
開發者ID:Pershonkey,項目名稱:McMMOPlus,代碼行數:27,代碼來源:HerbalismManager.java

示例2: processShroomThumb

import org.bukkit.inventory.PlayerInventory; //導入方法依賴的package包/類
/**
 * Process the Shroom Thumb ability.
 *
 * @param blockState The {@link BlockState} to check ability activation for
 * @return true if the ability was successful, false otherwise
 */
public boolean processShroomThumb(BlockState blockState) {
    Player player = getPlayer();
    PlayerInventory playerInventory = player.getInventory();

    if (!playerInventory.contains(Material.BROWN_MUSHROOM)) {
        player.sendMessage(LocaleLoader.getString("Skills.NeedMore", StringUtils.getPrettyItemString(Material.BROWN_MUSHROOM)));
        return false;
    }

    if (!playerInventory.contains(Material.RED_MUSHROOM)) {
        player.sendMessage(LocaleLoader.getString("Skills.NeedMore", StringUtils.getPrettyItemString(Material.RED_MUSHROOM)));
        return false;
    }

    playerInventory.removeItem(new ItemStack(Material.BROWN_MUSHROOM));
    playerInventory.removeItem(new ItemStack(Material.RED_MUSHROOM));
    player.updateInventory();

    if (!SkillUtils.activationSuccessful(SecondaryAbility.SHROOM_THUMB, getPlayer(), getSkillLevel(), activationChance)) {
        player.sendMessage(LocaleLoader.getString("Herbalism.Ability.ShroomThumb.Fail"));
        return false;
    }

    return Herbalism.convertShroomThumb(blockState);
}
 
開發者ID:Pershonkey,項目名稱:McMMOPlus,代碼行數:32,代碼來源:HerbalismManager.java

示例3: onClickOnObsidian

import org.bukkit.inventory.PlayerInventory; //導入方法依賴的package包/類
@EventHandler(priority = EventPriority.NORMAL)
public void onClickOnObsidian(final PlayerInteractEvent event) {
    if (!plugin.isSkyWorld(event.getPlayer().getWorld())) {
        return;
    }
    long now = System.currentTimeMillis();
    Player player = event.getPlayer();
    PlayerInventory inventory = player != null ? player.getInventory() : null;
    Block block = event.getClickedBlock();
    Long lastClick = obsidianClick.get(player.getUniqueId());
    if (lastClick != null && (lastClick + OBSIDIAN_SPAM) >= now) {
        plugin.notifyPlayer(player, tr("\u00a74You can only convert obsidian once every 10 seconds"));
        return;
    }
    if (Settings.extras_obsidianToLava && plugin.playerIsOnIsland(player)
            && plugin.isSkyWorld(player.getWorld())
            && event.getAction() == Action.RIGHT_CLICK_BLOCK
            && player.getItemInHand() != null
            && player.getItemInHand().getType() == Material.BUCKET
            && block != null
            && block.getType() == Material.OBSIDIAN
            && !testForObsidian(block)) {
        if (inventory.firstEmpty() != -1) {
            obsidianClick.put(player.getUniqueId(), now);
            player.sendMessage(tr("\u00a7eChanging your obsidian back into lava. Be careful!"));
            inventory.removeItem(new ItemStack(Material.BUCKET, 1));
            inventory.addItem(new ItemStack(Material.LAVA_BUCKET, 1));
            player.updateInventory();
            block.setType(Material.AIR);
            event.setCancelled(true); // Don't execute the click anymore (since that would re-place the lava).
        } else {
            player.sendMessage(tr("\u00a7eYour inventory must have another empty space!"));
        }
    }
}
 
開發者ID:rlf,項目名稱:uSkyBlock,代碼行數:36,代碼來源:PlayerEvents.java

示例4: processGreenThumbPlants

import org.bukkit.inventory.PlayerInventory; //導入方法依賴的package包/類
/**
 * Process the Green Thumb ability for plants.
 *
 * @param blockState The {@link BlockState} to check ability activation for
 * @param greenTerra boolean to determine if greenTerra is active or not
 */
private void processGreenThumbPlants(BlockState blockState, boolean greenTerra) {
    Player player = getPlayer();
    PlayerInventory playerInventory = player.getInventory();
    ItemStack seed = null;

    switch (blockState.getType()) {
        case CARROT:
            seed = new ItemStack(Material.CARROT_ITEM);
            break;

        case CROPS:
            seed = new ItemStack(Material.SEEDS);
            break;

        case NETHER_WARTS:
            seed = new ItemStack(Material.NETHER_STALK);
            break;

        case POTATO:
            seed = new ItemStack(Material.POTATO_ITEM);
            break;

        default:
            break;
    }

    if (!playerInventory.containsAtLeast(seed, 1)) {
        return;
    }

    if (!greenTerra && !SkillUtils.activationSuccessful(SecondaryAbility.GREEN_THUMB_PLANT, getPlayer(), getSkillLevel(), activationChance)) {
        return;
    }

    if (!handleBlockState(blockState, greenTerra)) {
        return;
    }

    playerInventory.removeItem(seed);
    player.updateInventory(); // Needed until replacement available
    new HerbalismBlockUpdaterTask(blockState).runTaskLater(mcMMO.p, 0);
}
 
開發者ID:Pershonkey,項目名稱:McMMOPlus,代碼行數:49,代碼來源:HerbalismManager.java


注:本文中的org.bukkit.inventory.PlayerInventory.removeItem方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。