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


Java PlayerInventory.setItemInMainHand方法代碼示例

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


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

示例1: onInteract

import org.bukkit.inventory.PlayerInventory; //導入方法依賴的package包/類
@EventHandler(ignoreCancelled = true, priority = EventPriority.HIGH)
public void onInteract(PlayerInteractEvent clickEvent) {
    Player player = clickEvent.getPlayer();
    PlayerInventory inventory = player.getInventory();

    ItemStack mainHandItem;
    if (mainHandSupported) {
        mainHandItem = inventory.getItemInMainHand();
    } else {
        mainHandItem = inventory.getItemInHand();
    }

    if (isOurGraph(mainHandItem)) {
        inventory.setItemInMainHand(new ItemStack(Material.AIR));
    }
}
 
開發者ID:games647,項目名稱:LagMonitor,代碼行數:17,代碼來源:GraphListener.java

示例2: commandUse

import org.bukkit.inventory.PlayerInventory; //導入方法依賴的package包/類
public boolean commandUse(CommandSender sender, String[] args) {
    Variables var = Necessities.getVar();
    if (sender instanceof Player) {
        Player p = (Player) sender;
        PlayerInventory inv = p.getInventory();
        ItemStack hand = inv.getItemInMainHand();
        ItemStack pants = inv.getLeggings();
        if (hand.getType() != Material.AIR) {
            inv.setLeggings(hand);
            inv.setItemInMainHand(pants);
            p.sendMessage(var.getMessages() + "Pants equipped.");
        } else {
            if (pants != null)
                inv.setItemInMainHand(pants);
            inv.setLeggings(new ItemStack(Material.AIR));
            p.sendMessage(var.getMessages() + "Pants removed.");
        }
    } else
        sender.sendMessage(var.getEr() + "Error: " + var.getErMsg() + "You do not have armor.");
    return true;
}
 
開發者ID:pupnewfster,項目名稱:Necessities,代碼行數:22,代碼來源:CmdPants.java

示例3: commandUse

import org.bukkit.inventory.PlayerInventory; //導入方法依賴的package包/類
public boolean commandUse(CommandSender sender, String[] args) {
    Variables var = Necessities.getVar();
    if (sender instanceof Player) {
        Player p = (Player) sender;
        PlayerInventory inv = p.getInventory();
        ItemStack hand = inv.getItemInMainHand();
        ItemStack hat = inv.getHelmet();
        if (hand.getType() != Material.AIR) {
            inv.setHelmet(hand);
            inv.setItemInMainHand(hat);
            p.sendMessage(var.getMessages() + "Hat equipped.");
        } else {
            if (hat != null)
                inv.setItemInMainHand(hat);
            inv.setHelmet(new ItemStack(Material.AIR));
            p.sendMessage(var.getMessages() + "Hat removed.");
        }
    } else
        sender.sendMessage(var.getEr() + "Error: " + var.getErMsg() + "You do not have armor.");
    return true;
}
 
開發者ID:pupnewfster,項目名稱:Necessities,代碼行數:22,代碼來源:CmdBlockHat.java

示例4: commandUse

import org.bukkit.inventory.PlayerInventory; //導入方法依賴的package包/類
public boolean commandUse(CommandSender sender, String[] args) {
    Variables var = Necessities.getVar();
    if (sender instanceof Player) {
        Player p = (Player) sender;
        PlayerInventory inv = p.getInventory();
        ItemStack hand = inv.getItemInMainHand();
        ItemStack chestplate = inv.getChestplate();
        if (hand.getType() != Material.AIR) {
            inv.setChestplate(hand);
            inv.setItemInMainHand(chestplate);
            p.sendMessage(var.getMessages() + "Chestplate equipped.");
        } else {
            if (chestplate != null)
                inv.setItemInMainHand(chestplate);
            inv.setChestplate(new ItemStack(Material.AIR));
            p.sendMessage(var.getMessages() + "Chestplate removed.");
        }
    } else
        sender.sendMessage(var.getEr() + "Error: " + var.getErMsg() + "You do not have armor.");
    return true;
}
 
開發者ID:pupnewfster,項目名稱:Necessities,代碼行數:22,代碼來源:CmdChest.java

示例5: commandUse

import org.bukkit.inventory.PlayerInventory; //導入方法依賴的package包/類
public boolean commandUse(CommandSender sender, String[] args) {
    Variables var = Necessities.getVar();
    if (sender instanceof Player) {
        Player p = (Player) sender;
        PlayerInventory inv = p.getInventory();
        ItemStack hand = inv.getItemInMainHand();
        ItemStack boots = inv.getBoots();
        if (hand.getType() != Material.AIR) {
            inv.setBoots(hand);
            inv.setItemInMainHand(boots);
            p.sendMessage(var.getMessages() + "Boots equipped.");
        } else {
            if (boots != null)
                inv.setItemInMainHand(boots);
            inv.setBoots(new ItemStack(Material.AIR));
            p.sendMessage(var.getMessages() + "Boots removed.");
        }
    } else
        sender.sendMessage(var.getEr() + "Error: " + var.getErMsg() + "You do not have armor.");
    return true;
}
 
開發者ID:pupnewfster,項目名稱:Necessities,代碼行數:22,代碼來源:CmdBoots.java

示例6: removeSingleSignFromHand

import org.bukkit.inventory.PlayerInventory; //導入方法依賴的package包/類
private void removeSingleSignFromHand(Player player) {
    if (player.getGameMode() == GameMode.CREATIVE) {
        return;
    }

    PlayerInventory inventory = player.getInventory();
    if (isOfType(inventory.getItemInMainHand(), Material.SIGN)) {
        inventory.setItemInMainHand(removeOneItem(inventory.getItemInMainHand()));
    } else if (isOfType(inventory.getItemInOffHand(), Material.SIGN)) {
        inventory.setItemInOffHand(removeOneItem(inventory.getItemInOffHand()));
    }
}
 
開發者ID:rutgerkok,項目名稱:BlockLocker,代碼行數:13,代碼來源:InteractListener.java

示例7: onBrewingClick

import org.bukkit.inventory.PlayerInventory; //導入方法依賴的package包/類
@EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true)
public void onBrewingClick(PlayerInteractEvent event) {
	if (event.getAction() != Action.RIGHT_CLICK_BLOCK) {
		return;
	}

	ItemStack itemstack = event.getItem();
	if ((itemstack == null) || (itemstack.getType() != Material.BLAZE_POWDER)) {
		return;
	}
	itemstack = itemstack.clone();

	Block clicked = event.getClickedBlock();
	BlockState state = clicked.getState();
	if (!(state instanceof BrewingStand)) {
		return;
	}
	BrewingStand stand = (BrewingStand) state;

	ItemStack existing = stand.getInventory().getFuel();
	if (existing != null) {
		existing = existing.clone();
	}

	PlayerInventory inventory = event.getPlayer().getInventory();
	switch (event.getHand()) {
		case HAND: {
			inventory.setItemInMainHand(existing);
			break;
		}
		case OFF_HAND: {
			inventory.setItemInOffHand(existing);
			break;
		}
		default: {
			throw new IllegalArgumentException("Unexpected hand slot in interaction: " + event.getHand());
		}
	}
	stand.getInventory().setFuel(itemstack);
	event.setCancelled(true);
}
 
開發者ID:ProtocolSupport,項目名稱:ProtocolSupportLegacySupport,代碼行數:42,代碼來源:BrewingStandFuelHandler.java

示例8: onPlayerInteract

import org.bukkit.inventory.PlayerInventory; //導入方法依賴的package包/類
/**
 * Handle player interactions:
 * <ul>
 * <li>Launch TNT if permitted and gliding.</li>
 * <li>Set gliding if player right clicks a rocket while in the air and
 * wearing elytra, to compensate for NCP's interference.</li>
 * </ul>
 */
@EventHandler
public void onPlayerInteract(PlayerInteractEvent event) {
    Player player = event.getPlayer();

    // Only handle left and right click air events
    Action action = event.getAction();
    if (action != Action.LEFT_CLICK_AIR && action != Action.RIGHT_CLICK_AIR) {
        return;
    }

    // Assisted takeoff if wearing unbroken elytra.
    // NOTE: event.getItem() allows off hand use.
    if (action == Action.RIGHT_CLICK_AIR &&
        event.getItem().getType() == Material.FIREWORK &&
        !player.isOnGround() &&
        player.getVehicle() == null &&
        isWearingElytra(player, true)) {

        Block feetBlock = player.getLocation().getBlock();
        if (feetBlock != null && canAssistedTakeOffFrom(feetBlock.getType())) {
            PlayerState state = getState(player);
            state.setTakingOff();
            player.setGliding(true);
        }
    }

    // Only throw TNT if permitted, gliding and holding TNT.
    PlayerInventory inventory = player.getInventory();
    ItemStack stack = inventory.getItemInMainHand();
    if (!player.hasPermission("wingcommander.tnt") ||
        !player.isGliding() ||
        stack.getType() != Material.TNT) {
        return;
    }

    // Use up a TNT.
    int amount = stack.getAmount() - 1;
    if (amount > 1) {
        stack.setAmount(amount);
    } else {
        inventory.setItemInMainHand(null);
    }

    // Spawn TNT.
    Entity tnt = player.getWorld().spawnEntity(player.getLocation(), EntityType.PRIMED_TNT);

    if (action == Action.LEFT_CLICK_AIR) {
        // Throw the TNT forward.
        Vector TNTVelocity = player.getLocation().getDirection();
        TNTVelocity.normalize();
        TNTVelocity.multiply(WingCommander.CONFIG.TNT_THROW_SPEED);
        TNTVelocity.add(player.getVelocity());
        tnt.setVelocity(TNTVelocity);
    } else if (action == Action.RIGHT_CLICK_AIR) {
        // Drop the TNT with current velocity.
        tnt.setVelocity(player.getVelocity());
    }
}
 
開發者ID:NerdNu,項目名稱:WingCommander,代碼行數:67,代碼來源:WingCommander.java

示例9: onPlayerShoot

import org.bukkit.inventory.PlayerInventory; //導入方法依賴的package包/類
@EventHandler(priority = EventPriority.HIGHEST)
public void onPlayerShoot(PlayerInteractEvent e) {

	Action action = e.getAction();

	if(action != Action.RIGHT_CLICK_AIR && action != Action.RIGHT_CLICK_BLOCK) return;

	Player player = e.getPlayer();

	if(!isEnabled(player.getWorld())) return;

	if(e.getMaterial() != Material.ENDER_PEARL) return;

	if (e.isCancelled()) return;

	e.setCancelled(true);

	EnderPearl pearl = player.launchProjectile(EnderPearl.class);

	pearl.setVelocity(player.getEyeLocation().getDirection().multiply(2));

	GameMode mode = player.getGameMode();

	if(mode == GameMode.ADVENTURE || mode == GameMode.SURVIVAL) {
		PlayerInventory inv = player.getInventory();

		boolean isInOffhand = true;
		ItemStack hand = inv.getItemInOffHand();

		if(hand.getType() != Material.ENDER_PEARL) {
			hand = inv.getItemInMainHand();
			isInOffhand = false;
		}

		hand.setAmount(hand.getAmount() - 1);

		if(isInOffhand)
			inv.setItemInOffHand(hand);
		else
			inv.setItemInMainHand(hand);
	}
}
 
開發者ID:gvlfm78,項目名稱:BukkitOldCombatMechanics,代碼行數:43,代碼來源:ModuleDisableEnderpearlCooldown.java


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