当前位置: 首页>>代码示例>>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;未经允许,请勿转载。