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


Java PlayerInventory.getItemInMainHand方法代碼示例

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


在下文中一共展示了PlayerInventory.getItemInMainHand方法的11個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的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: onPlayerInteract

import org.bukkit.inventory.PlayerInventory; //導入方法依賴的package包/類
@EventHandler
public void onPlayerInteract(PlayerInteractEvent event) {
    Player player = event.getPlayer();
    PlayerInventory playerInv = event.getPlayer().getInventory();
    ItemStack torch = playerInv.getItemInMainHand();
    if ((event.getAction() == Action.RIGHT_CLICK_AIR) &&
            (torch.hasItemMeta()) &&
            (torch.getItemMeta().getDisplayName() != null) &&
            (torch.getItemMeta().getDisplayName().equals(ChatColor.DARK_AQUA + "[" + ChatColor.WHITE + "Flashlight" + ChatColor.DARK_AQUA + "]"))) {
        togglePlayer(player);
    }
}
 
開發者ID:MattJBrowning,項目名稱:FlashlightPlus,代碼行數:13,代碼來源:EventListener.java

示例7: onPlayerPlace

import org.bukkit.inventory.PlayerInventory; //導入方法依賴的package包/類
@EventHandler
public void onPlayerPlace(PlayerInteractEvent event) {
    PlayerInventory playerInv = event.getPlayer().getInventory();
    ItemStack torch = playerInv.getItemInMainHand();
    if ((event.getAction() == Action.RIGHT_CLICK_BLOCK) &&
            (torch.hasItemMeta()) &&
            (torch.getItemMeta().getDisplayName() != null) &&
            (torch.getItemMeta().getDisplayName().equals(ChatColor.DARK_AQUA + "[" + ChatColor.WHITE + "Flashlight" + ChatColor.DARK_AQUA + "]"))) {
        event.setCancelled(true);
    }

}
 
開發者ID:MattJBrowning,項目名稱:FlashlightPlus,代碼行數:13,代碼來源:EventListener.java

示例8: check

import org.bukkit.inventory.PlayerInventory; //導入方法依賴的package包/類
@SuppressWarnings("deprecation")
   @Override
public boolean check(String playerID) {
	PlayerInventory inv = PlayerConverter.getPlayer(playerID).getInventory();
	ItemStack item = null;
	try {
	    item = (!offhand) ? inv.getItemInMainHand() : inv.getItemInOffHand();
	} catch (LinkageError e) {
	    item = inv.getItemInHand();
	}
	if (questItem.compare(item)) {
		return true;
	}
	return false;
}
 
開發者ID:Co0sh,項目名稱:BetonQuest,代碼行數:16,代碼來源:HandCondition.java

示例9: update

import org.bukkit.inventory.PlayerInventory; //導入方法依賴的package包/類
public void update(final Player player) {
    final PlayerInventory inv = player.getInventory();
    final ItemData[] updated = new ItemData[equipped.length];
    for (int i = 0; i < updated.length; i++) {
        final ItemStack item = i < slots.length ? inv.getItem(slots[i]) : inv.getItemInMainHand();
        updated[i] = ItemData.from(item);
    }
    swap(player, updated);
}
 
開發者ID:Eniripsa96,項目名稱:EnchantmentAPI,代碼行數:10,代碼來源:PlayerEquips.java

示例10: 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

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