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


Java Player.setItemOnCursor方法代碼示例

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


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

示例1: reset

import org.bukkit.entity.Player; //導入方法依賴的package包/類
public static void reset(Player player, boolean heal) {
    if (heal) player.setHealth(player.getAttribute(Attribute.GENERIC_MAX_HEALTH).getValue());
    player.setFoodLevel(20);
    player.setSaturation(20);
    player.getInventory().clear();
    player.getInventory().setArmorContents(new ItemStack[]{new ItemStack(Material.AIR), new ItemStack(Material.AIR), new ItemStack(Material.AIR), new ItemStack(Material.AIR)});
    player.setItemOnCursor(new ItemStack(Material.AIR));

    player.getActivePotionEffects().forEach(potionEffect -> {
        try {
            player.removePotionEffect(potionEffect.getType());
        } catch (NullPointerException ignored) {}
    });

    player.setFireTicks(0);
    player.setFallDistance(0);
    player.setTotalExperience(0);
    player.setExp(0);
    player.setLevel(0);
    player.setWalkSpeed(0.2F);
    player.setFlySpeed(0.1F);

    player.setSneaking(false);
    player.setInvulnerable(false);
    player.setCanPickupItems(true);
    player.setCollidable(true);
    player.setFlying(false);
    player.setAllowFlight(false);

    player.resetTitle();

    for (Attribute attribute : Attribute.values()) {
        if (player.getAttribute(attribute) == null) continue;
        for (AttributeModifier modifier : player.getAttribute(attribute).getModifiers()) {
            player.getAttribute(attribute).removeModifier(modifier);
        }
    }
    player.getAttribute(Attribute.GENERIC_ATTACK_SPEED).addModifier(new AttributeModifier(UUID.randomUUID(), "generic.attackSpeed", 24.000D, AttributeModifier.Operation.ADD_SCALAR));

    player.updateInventory();
}
 
開發者ID:WarzoneMC,項目名稱:Warzone,代碼行數:42,代碼來源:Players.java

示例2: updateInventory

import org.bukkit.entity.Player; //導入方法依賴的package包/類
private static void updateInventory(
        @NotNull Player player,
        @NotNull Inventory inventory,
        int slot,
        InventoryType.SlotType slotType,
        InventoryAction action,
        ItemStack currentItem,
        ItemStack cursorItem
) {
    if (ActionType.getTypeOfAction(action) == ActionType.DROP) {
        return;
    }

    if (action == InventoryAction.PLACE_ALL) {
        if (ItemUtils.isEmpty(currentItem)) {
            currentItem = cursorItem.clone();
        } else {
            currentItem.setAmount(currentItem.getAmount() + cursorItem.getAmount());
        }

        cursorItem = null;
    } else if (action == InventoryAction.PLACE_ONE) {
        if (ItemUtils.isEmpty(currentItem)) {
            currentItem = cursorItem.clone();
            currentItem.setAmount(1);
            cursorItem.setAmount(cursorItem.getAmount() - 1);
        } else if (currentItem.getMaxStackSize() < currentItem.getAmount() + 1) {
            currentItem.setAmount(currentItem.getAmount() + 1);
            cursorItem.setAmount(cursorItem.getAmount() - 1);
        }
    } else if (action == InventoryAction.PLACE_SOME) {
        cursorItem.setAmount(currentItem.getMaxStackSize() - currentItem.getAmount());
        currentItem.setAmount(currentItem.getMaxStackSize());
    } else if (action == InventoryAction.SWAP_WITH_CURSOR) {
        ItemStack tempItem = cursorItem.clone();
        cursorItem = currentItem.clone();
        currentItem = tempItem;
    } else if (action == InventoryAction.PICKUP_ALL) {
        cursorItem = currentItem.clone();
        currentItem = null;
    } else if (action == InventoryAction.PICKUP_HALF) {
        ItemStack item = currentItem.clone();
        if (currentItem.getAmount() % 2 == 0) {
            item.setAmount(item.getAmount() / 2);
            currentItem = item.clone();
            cursorItem = item.clone();
        } else {
            currentItem = item.clone();
            currentItem.setAmount(item.getAmount() / 2);
            cursorItem = item.clone();
            cursorItem.setAmount(item.getAmount() / 2 + 1);
        }
    } else if (action == InventoryAction.MOVE_TO_OTHER_INVENTORY) {
        player.getInventory().addItem(currentItem);
        currentItem = null;
    }

    if (slotType == InventoryType.SlotType.QUICKBAR) {
        if (slot < 9) { // Exclude shield
            player.getInventory().setItem(slot, currentItem);
        }
    } else {
        inventory.setItem(slot, currentItem);
    }

    player.setItemOnCursor(cursorItem);
    player.updateInventory();
}
 
開發者ID:EndlessCodeGroup,項目名稱:RPGInventory,代碼行數:69,代碼來源:InventoryManager.java

示例3: onArmorSlotClick

import org.bukkit.entity.Player; //導入方法依賴的package包/類
/**
 * It happens when player click on armor slot
 */
private void onArmorSlotClick(InventoryClickEvent event, PlayerWrapper playerWrapper, final Slot slot,
                              ItemStack cursor, ItemStack currentItem) {
    final Player player = playerWrapper.getPlayer().getPlayer();
    final Inventory inventory = event.getInventory();
    final int rawSlot = event.getRawSlot();
    InventoryAction action = event.getAction();
    ActionType actionType = ActionType.getTypeOfAction(action);

    if (InventoryManager.validateArmor(player, action, slot, cursor) && playerWrapper.getInventoryView() != null) {
        // Event of equip armor
        InventoryClickEvent fakeEvent = new InventoryClickEvent(playerWrapper.getInventoryView(),
                InventoryType.SlotType.ARMOR, InventoryUtils.getArmorSlotId(slot), event.getClick(), action);
        Bukkit.getPluginManager().callEvent(fakeEvent);

        if (fakeEvent.isCancelled()) {
            event.setCancelled(true);
            return;
        }

        InventoryManager.updateArmor(player, inventory, slot, rawSlot, action, currentItem, cursor);

        if (actionType == ActionType.GET) {
            inventory.setItem(rawSlot, slot.getCup());
        } else if (slot.isCup(currentItem)) {
            player.setItemOnCursor(new ItemStack(Material.AIR));
        }

        player.updateInventory();
    }

    if (actionType == ActionType.DROP) {
        new BukkitRunnable() {
            @Override
            public void run() {
                inventory.setItem(rawSlot, slot.getCup());
                player.updateInventory();
            }
        }.runTaskLater(RPGInventory.getInstance(), 1);
    } else {
        event.setCancelled(true);
    }
}
 
開發者ID:EndlessCodeGroup,項目名稱:RPGInventory,代碼行數:46,代碼來源:InventoryListener.java


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