当前位置: 首页>>代码示例>>Java>>正文


Java PlayerInteractEvent.hasItem方法代码示例

本文整理汇总了Java中org.bukkit.event.player.PlayerInteractEvent.hasItem方法的典型用法代码示例。如果您正苦于以下问题:Java PlayerInteractEvent.hasItem方法的具体用法?Java PlayerInteractEvent.hasItem怎么用?Java PlayerInteractEvent.hasItem使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在org.bukkit.event.player.PlayerInteractEvent的用法示例。


在下文中一共展示了PlayerInteractEvent.hasItem方法的13个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: onInteract

import org.bukkit.event.player.PlayerInteractEvent; //导入方法依赖的package包/类
@EventHandler(priority = EventPriority.LOW)
public void onInteract(PlayerInteractEvent event) {
    if(!event.hasItem()) return;

    final ClickType click;
    switch(event.getAction()) {
        case LEFT_CLICK_AIR:
        case LEFT_CLICK_BLOCK:
            click = ClickType.LEFT;
            break;

        case RIGHT_CLICK_AIR:
        case RIGHT_CLICK_BLOCK:
            click = ClickType.RIGHT;
            break;

        default:
            return;
    }

    if(onButtonClick(event.getItem(), event.getActor(), click, event)) {
        event.setUseItemInHand(Event.Result.DENY);
        event.setUseInteractedBlock(Event.Result.DENY);
    }
}
 
开发者ID:OvercastNetwork,项目名称:ProjectAres,代码行数:26,代码来源:ButtonManager.java

示例2: onUseBackpack

import org.bukkit.event.player.PlayerInteractEvent; //导入方法依赖的package包/类
@SuppressWarnings("deprecation")
@EventHandler(priority = EventPriority.LOWEST)
public void onUseBackpack(PlayerInteractEvent event) {
    ItemStack item = event.getItem();
    if (!event.hasItem() || !ItemUtils.hasTag(item, ItemUtils.BACKPACK_TAG)) {
        return;
    }

    Player player = event.getPlayer();
    Action action = event.getAction();
    if ((action == Action.RIGHT_CLICK_AIR || action == Action.RIGHT_CLICK_BLOCK)
            && InventoryManager.isQuickSlot(player.getInventory().getHeldItemSlot())) {
        BackpackManager.open(player, item);
    }

    event.setCancelled(true);
    player.updateInventory();
}
 
开发者ID:EndlessCodeGroup,项目名称:RPGInventory,代码行数:19,代码来源:BackpackListener.java

示例3: onPlayerInteract

import org.bukkit.event.player.PlayerInteractEvent; //导入方法依赖的package包/类
@EventHandler(ignoreCancelled = true, priority = EventPriority.NORMAL)
public void onPlayerInteract(PlayerInteractEvent event) {
    if (event.getAction() == Action.RIGHT_CLICK_BLOCK && event.hasItem() && event.getItem().getType() == Material.ENDER_PEARL) {
        Block block = event.getClickedBlock();
        // Don't prevent opening chests, etc, as these won't throw the Enderpearls anyway
        if (block.getType().isSolid() && !(block.getState() instanceof InventoryHolder)) {
            Faction factionAt = HCF.getPlugin().getFactionManager().getFactionAt(block.getLocation());
            if (!(factionAt instanceof ClaimableFaction)) {
                return;
            }

            event.setCancelled(true);
            Player player = event.getPlayer();
            player.setItemInHand(event.getItem()); // required to update Enderpearl count
        }
    }
}
 
开发者ID:funkemunky,项目名称:HCFCore,代码行数:18,代码来源:PearlGlitchListener.java

示例4: onPlayerInteract

import org.bukkit.event.player.PlayerInteractEvent; //导入方法依赖的package包/类
@EventHandler(ignoreCancelled = true, priority = EventPriority.HIGH)
public void onPlayerInteract(PlayerInteractEvent event) {
    if (event.getAction() == Action.LEFT_CLICK_BLOCK && event.hasItem()) {
        // The player didn't click an enchantment table, Creative players will instantly destroy.
        Player player = event.getPlayer();
        if (event.getClickedBlock().getType() == Material.ENCHANTMENT_TABLE && player.getGameMode() != GameMode.CREATIVE) {

            // The player didn't click with an enchanted book.
            ItemStack stack = event.getItem();
            if (stack != null && stack.getType() == Material.ENCHANTED_BOOK) {
                ItemMeta meta = stack.getItemMeta();
                if (meta instanceof EnchantmentStorageMeta) {
                    EnchantmentStorageMeta enchantmentStorageMeta = (EnchantmentStorageMeta) meta;
                    for (Enchantment enchantment : enchantmentStorageMeta.getStoredEnchants().keySet()) {
                        enchantmentStorageMeta.removeStoredEnchant(enchantment);
                    }

                    event.setCancelled(true);
                    player.setItemInHand(EMPTY_BOOK);
                    player.sendMessage(ChatColor.GREEN + "You reverted this item to its original form.");
                }
            }
        }
    }
}
 
开发者ID:funkemunky,项目名称:HCFCore,代码行数:26,代码来源:BookDeenchantListener.java

示例5: onPlayerInteract

import org.bukkit.event.player.PlayerInteractEvent; //导入方法依赖的package包/类
@EventHandler(ignoreCancelled = true, priority = EventPriority.MONITOR)
public void onPlayerInteract(PlayerInteractEvent event) {
    if (event.hasItem() && event.getItem().getType() == Material.GOLDEN_CARROT) {
        Player player = event.getPlayer();
        if (plugin.getPvpClassManager().getEquippedClass(player) == this) {
            long timestamp = cooldowns.get(player.getUniqueId());
            long millis = System.currentTimeMillis();
            long remaining = timestamp == cooldowns.getNoEntryValue() ? 0L : timestamp - millis;
            if (remaining > 0L) {
                player.sendMessage(ChatColor.RED + "Cooldown still for " + DurationFormatUtils.formatDurationWords(remaining, true, true) + ".");
                return;
            }

            cooldowns.put(player.getUniqueId(), millis + 15000L);
            plugin.getEffectRestorer().setRestoreEffect(player, new PotionEffect(PotionEffectType.SPEED, 100, 4));
            plugin.getEffectRestorer().setRestoreEffect(player, new PotionEffect(PotionEffectType.INVISIBILITY, 100, 0));
        }
    }
}
 
开发者ID:funkemunky,项目名称:HCFCore,代码行数:20,代码来源:AssassinClass.java

示例6: onItemUse

import org.bukkit.event.player.PlayerInteractEvent; //导入方法依赖的package包/类
@EventHandler
public void onItemUse(PlayerInteractEvent event) {
    Player player = event.getPlayer();

    if (!event.hasItem() || !InventoryManager.playerIsLoaded(player)) {
        return;
    }

    Inventory inventory = InventoryManager.get(player).getInventory();
    ItemStack petItem = event.getItem();

    if (player.getGameMode() == GameMode.CREATIVE && PetManager.isPetItem(petItem)) {
        petItem = PetManager.toPetItem(petItem);
        player.getEquipment().setItemInMainHand(petItem);
    }

    if (PetType.isPetItem(petItem)
            && (event.getAction() == Action.RIGHT_CLICK_BLOCK || event.getAction() == Action.RIGHT_CLICK_AIR)) {
        Slot petSlot = SlotManager.instance().getPetSlot();
        if (petSlot != null && petSlot.isCup(inventory.getItem(PetManager.getPetSlotId()))
                && ItemManager.allowedForPlayer(player, petItem, false)) {
            inventory.setItem(PetManager.getPetSlotId(), event.getItem());
            PetManager.spawnPet(player, petItem);
            player.getEquipment().setItemInMainHand(null);
        }

        event.setCancelled(true);
    }
}
 
开发者ID:EndlessCodeGroup,项目名称:RPGInventory,代码行数:30,代码来源:PetListener.java

示例7: onArcherSpeedClick

import org.bukkit.event.player.PlayerInteractEvent; //导入方法依赖的package包/类
@EventHandler(ignoreCancelled=false, priority=EventPriority.HIGH)
public void onArcherSpeedClick(PlayerInteractEvent event)
{
    Action action = event.getAction();
    if (((action == Action.RIGHT_CLICK_AIR) || (action == Action.RIGHT_CLICK_BLOCK)) &&
            (event.hasItem()) && (event.getItem().getType() == Material.SUGAR))
    {
        if (this.plugin.getPvpClassManager().getEquippedClass(event.getPlayer()) != this) {
            return;
        }
        Player player = event.getPlayer();
        UUID uuid = player.getUniqueId();
        long timestamp = this.archerSpeedCooldowns.get(uuid);
        long millis = System.currentTimeMillis();
        long remaining = timestamp == this.archerSpeedCooldowns.getNoEntryValue() ? -1L : timestamp - millis;
        if (remaining > 0L)
        {
            player.sendMessage(ChatColor.RED + "Cannot use Speed Boost for another " + DurationFormatUtils.formatDurationWords(remaining, true, true) + ".");
        }
        else
        {
            ItemStack stack = player.getItemInHand();
            if (stack.getAmount() == 1) {
                player.setItemInHand(new ItemStack(Material.AIR, 1));
            } else {
                stack.setAmount(stack.getAmount() - 1);
            }
            player.sendMessage(ChatColor.GREEN + "Speed 4 activated for 7 seconds.");

            this.plugin.getEffectRestorer().setRestoreEffect(player, ARCHER_SPEED_EFFECT);
            this.archerSpeedCooldowns.put(event.getPlayer().getUniqueId(), System.currentTimeMillis() + ARCHER_SPEED_COOLDOWN_DELAY);
        }
    }
}
 
开发者ID:funkemunky,项目名称:HCFCore,代码行数:35,代码来源:ArcherClass.java

示例8: onArcherJumpClick

import org.bukkit.event.player.PlayerInteractEvent; //导入方法依赖的package包/类
@EventHandler(ignoreCancelled=false, priority=EventPriority.HIGH)
public void onArcherJumpClick(PlayerInteractEvent event)
{
    Action action = event.getAction();
    if (((action == Action.RIGHT_CLICK_AIR) || (action == Action.RIGHT_CLICK_BLOCK)) &&
            (event.hasItem()) && (event.getItem().getType() == Material.FEATHER))
    {
        if (this.plugin.getPvpClassManager().getEquippedClass(event.getPlayer()) != this) {
            return;
        }
        Player player = event.getPlayer();
        UUID uuid = player.getUniqueId();
        long timestamp = this.archerJumpCooldowns.get(uuid);
        long millis = System.currentTimeMillis();
        long remaining = timestamp == this.archerJumpCooldowns.getNoEntryValue() ? -1L : timestamp - millis;
        if (remaining > 0L)
        {
            player.sendMessage(ChatColor.RED + "Cannot use Jump Boost for another " + DurationFormatUtils.formatDurationWords(remaining, true, true) + ".");
        }
        else
        {
            ItemStack stack = player.getItemInHand();
            if (stack.getAmount() == 1) {
                player.setItemInHand(new ItemStack(Material.AIR, 1));
            } else {
                stack.setAmount(stack.getAmount() - 1);
            }
            player.sendMessage(ChatColor.GREEN + "Jump Boost 4 activated for 7 seconds.");

            this.plugin.getEffectRestorer().setRestoreEffect(player, ARCHER_JUMP_EFFECT);
            this.archerJumpCooldowns.put(event.getPlayer().getUniqueId(), System.currentTimeMillis() + ARCHER_JUMP_COOLDOWN_DELAY);
        }
    }
}
 
开发者ID:funkemunky,项目名称:HCFCore,代码行数:35,代码来源:ArcherClass.java

示例9: onMinerSpeedClick

import org.bukkit.event.player.PlayerInteractEvent; //导入方法依赖的package包/类
/**
 * Applies the {@link MinerClass} invisibility {@link PotionEffect} depending on the {@link Player}s {@link Location}.
 *
 * @param player
 *            the {@link Player} to apply for
 * @param from
 *            the from {@link Location}
 * @param to
 *            the to {@link Location}
 */

@EventHandler(ignoreCancelled=false, priority=EventPriority.HIGH)
public void onMinerSpeedClick(PlayerInteractEvent event)
{
    Action action = event.getAction();
    if (((action == Action.RIGHT_CLICK_AIR) || (action == Action.RIGHT_CLICK_BLOCK)) &&
            (event.hasItem()) && (event.getItem().getType() == Material.SUGAR))
    {
        if (this.plugin.getPvpClassManager().getEquippedClass(event.getPlayer()) != this) {
            return;
        }
        Player player = event.getPlayer();
        UUID uuid = player.getUniqueId();
        long timestamp = this.minerSpeedCooldowns.get(uuid);
        long millis = System.currentTimeMillis();
        long remaining = timestamp == this.minerSpeedCooldowns.getNoEntryValue() ? -1L : timestamp - millis;
        if (remaining > 0L)
        {
            player.sendMessage(ChatColor.RED + "Cannot use Speed Boost for another " + DurationFormatUtils.formatDurationWords(remaining, true, true) + ".");
        }
        else
        {
            ItemStack stack = player.getItemInHand();
            if (stack.getAmount() == 1) {
                player.setItemInHand(new ItemStack(Material.AIR, 1));
            } else {
                stack.setAmount(stack.getAmount() - 1);
            }
            player.sendMessage(ChatColor.GREEN + "Speed 3 activated for 10 seconds.");

            this.plugin.getEffectRestorer().setRestoreEffect(player, MINER_SPEED_EFFECT);
            this.minerSpeedCooldowns.put(event.getPlayer().getUniqueId(), System.currentTimeMillis() + MINER_SPEED_COOLDOWN_DELAY);
        }
    }
}
 
开发者ID:funkemunky,项目名称:HCFCore,代码行数:46,代码来源:MinerClass.java

示例10: onInteract

import org.bukkit.event.player.PlayerInteractEvent; //导入方法依赖的package包/类
@EventHandler(ignoreCancelled = true, priority = EventPriority.NORMAL)
public void onInteract(PlayerInteractEvent event) {
    if ((event.getAction() == Action.RIGHT_CLICK_BLOCK) && (event.hasItem()) && (event.getItem().getType() == Material.ENDER_PEARL)) {
        Block block = event.getClickedBlock();

        if ((block.getType().isSolid()) && (!(block.getState() instanceof InventoryHolder))) {
            event.setCancelled(true);
            Player player = event.getPlayer();
            player.setItemInHand(event.getItem());
        }
    }
}
 
开发者ID:ijoeleoli,项目名称:ZorahPractice,代码行数:13,代码来源:PearlFix.java

示例11: onItemClick

import org.bukkit.event.player.PlayerInteractEvent; //导入方法依赖的package包/类
@SuppressWarnings("deprecation")
@EventHandler(priority = EventPriority.HIGHEST)
public void onItemClick(PlayerInteractEvent event)
{
	if(event.isCancelled()) return;
	if(event.hasItem())
	{
		Player player = event.getPlayer();
		if(player.getGameMode() == GameMode.SURVIVAL || player.getGameMode() == GameMode.ADVENTURE)
		{
			ItemStack mainItem = player.getInventory().getItemInMainHand();
			if(mainItem.getType() == Material.GLASS_BOTTLE)
			{
				if(event.getAction() == Action.RIGHT_CLICK_BLOCK)
				{
					if(event.getClickedBlock().getType() == Material.CAULDRON && event.getClickedBlock().getData() != (byte)0)
					{
						Block fire = event.getClickedBlock().getRelative(BlockFace.DOWN);
						event.setCancelled(true);
						
						event.getClickedBlock().setData((byte)((int)event.getClickedBlock().getData() - 1));
						
						ItemStack waterBottle = new ItemStack(Material.POTION, 1);
						
						net.minecraft.server.v1_12_R1.ItemStack nmsStack_bottle = CraftItemStack.asNMSCopy(waterBottle);
				        NBTTagCompound compound_bottle = nmsStack_bottle.getTag();
				        compound_bottle.setString("Potion","minecraft:water");
				        compound_bottle.setInt("HideFlags", 32);
				        nmsStack_bottle.setTag(compound_bottle);
				        waterBottle = CraftItemStack.asBukkitCopy(nmsStack_bottle);
				        
						ItemMeta meta = waterBottle.getItemMeta();

						if(fire != null && fire.getType() == Material.FIRE)
						{
							List<String> lore = Arrays.asList
							(
								ChatColor.RESET + "" + ChatColor.GRAY + Survival.Words.get("Purified")
							);
							meta.setLore(lore);
						}
						waterBottle.setItemMeta(meta);
						
						if(mainItem.getAmount() > 1)
						{
							mainItem.setAmount(mainItem.getAmount() - 1);
							if(player.getInventory().firstEmpty() != -1)
								player.getInventory().addItem(waterBottle);
							else
								player.getWorld().dropItem(player.getLocation(), waterBottle);
						}
						else
						{
							player.getInventory().setItemInMainHand(waterBottle);
						}
					}
				}
			}
		}
	}
}
 
开发者ID:FattyMieo,项目名称:SurvivalPlus,代码行数:62,代码来源:CauldronWaterBottle.java

示例12: onSelfClick

import org.bukkit.event.player.PlayerInteractEvent; //导入方法依赖的package包/类
@SuppressWarnings("deprecation")
@EventHandler
public void onSelfClick(PlayerInteractEvent event)
{
	if(event.hasItem() && (event.getAction() == Action.RIGHT_CLICK_AIR || event.getAction() == Action.RIGHT_CLICK_BLOCK))
	{
		final Player player = event.getPlayer();
		ItemStack mainItem = player.getInventory().getItemInMainHand();
		if(mainItem != null && mainItem.getType() == Material.WATCH)
		{
			if(healing.getScore(player).getScore() <= 0)
			{
				if(player.isSneaking())
				{
					healing.getScore(player).setScore(1);
					player.sendMessage(Survival.Words.get("�aHealing �ryourself") + Survival.Words.get("�a, keep ") + ChatColor.DARK_GREEN + Survival.Words.get("Medical Kit") + Survival.Words.get("�a on hand"));
					
					healTimes.getScore(player).setScore(5);
					final Runnable task = new Runnable()
					{
						public void run()
						{
							int times = healTimes.getScore(player).getScore();
							if(player.getInventory().getItemInMainHand().getType() == Material.WATCH && healing.getScore(player).getScore() > 0)
							{
								if(times-- > 0)
								{													
									Random rand = new Random();
									
									player.removePotionEffect(PotionEffectType.SLOW);
			                        player.addPotionEffect(new PotionEffect(PotionEffectType.SLOW, 20, 6, true, false));
			                        player.removePotionEffect(PotionEffectType.JUMP);
			                        player.addPotionEffect(new PotionEffect(PotionEffectType.JUMP, 20, 199, true, false));
			                        
			                        player.getWorld().playSound(player.getLocation(), Sound.ENTITY_LEASHKNOT_PLACE, 1.0F, rand.nextFloat() * 0.4F + 0.8F);
									player.addPotionEffect(new PotionEffect(PotionEffectType.HEAL, 1, 0));
									
									Location particleLoc = player.getLocation();
			                        particleLoc.setY(particleLoc.getY() + 1);
			                        ParticleEffect.VILLAGER_HAPPY.display(0.5f, 0.5f, 0.5f, 0, 10, particleLoc, 64);

									Bukkit.getServer().getScheduler().scheduleSyncDelayedTask(Survival.instance, this, 20L);
									healTimes.getScore(player).setScore(times);
								}

								else
								{
									healing.getScore(player).setScore(0);
									
									player.sendMessage(ChatColor.DARK_GREEN + Survival.Words.get("Healing complete"));
									
									player.getInventory().removeItem(i_MedicKit());
								}
							}
							else
							{
								healing.getScore(player).setScore(0);
								
								player.sendMessage(ChatColor.DARK_RED + Survival.Words.get("Healing interrupted"));
								
								player.getInventory().removeItem(i_MedicKit());
							}
						}
					};
					
					Bukkit.getServer().getScheduler().scheduleSyncDelayedTask(Survival.instance, task, -1L);
				}
			}
		}
	}
}
 
开发者ID:FattyMieo,项目名称:SurvivalPlus,代码行数:72,代码来源:MedicKit.java

示例13: onPlayerInteract

import org.bukkit.event.player.PlayerInteractEvent; //导入方法依赖的package包/类
@EventHandler(ignoreCancelled = false, priority = EventPriority.HIGH)
public void onPlayerInteract(PlayerInteractEvent event) {
    Action action = event.getAction();
    if (event.hasItem() && (action == Action.RIGHT_CLICK_AIR || (action == Action.RIGHT_CLICK_BLOCK && !event.isCancelled()))) {
        ItemStack stack = event.getItem();
        if (!isBottledExperience(stack)) {
            return;
        }

        ItemMeta meta = stack.getItemMeta();
        List<String> lore = meta.getLore();

        Integer amount = null;
        for (String loreLine : lore) {
            if ((amount = JavaUtils.tryParseInt(ChatColor.stripColor(loreLine).split(" ")[0])) != null) {
                break;
            }
        }

        if (amount != null) {
            event.setCancelled(true);

            Player player = event.getPlayer();
            int previousLevel = player.getLevel();
            new ExperienceManager(player).changeExp(amount);

            // Play a fancy sound if they earned 5 exp levels.
            if ((player.getLevel() - previousLevel) > 5) {
                player.playSound(player.getLocation(), Sound.ORB_PICKUP, 1.0F, 1.0F);
            }

            // If the hand is more than 1, decrease by 1
            // otherwise remove. To prevent user error.
            if (stack.getAmount() > 1) {
                stack.setAmount(stack.getAmount() - 1);
            } else {
                player.setItemInHand(new ItemStack(Material.GLASS_BOTTLE, 1));
            }
        }
    }
}
 
开发者ID:funkemunky,项目名称:HCFCore,代码行数:42,代码来源:BottledExpListener.java


注:本文中的org.bukkit.event.player.PlayerInteractEvent.hasItem方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。