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


Java PlayerItemConsumeEvent.getItem方法代碼示例

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


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

示例1: onItemConsume

import org.bukkit.event.player.PlayerItemConsumeEvent; //導入方法依賴的package包/類
@EventHandler
public void onItemConsume(PlayerItemConsumeEvent e){
    Player p = e.getPlayer();
    ItemStack item = e.getItem();
    Material type = item != null ? item.getType() : Material.AIR;
    int thirst = p.getLevel();

    if (type == Material.POTION && item.getDurability() == 0 && p.getInventory().getItemInMainHand().isSimilar(item)){
        p.getInventory().getItemInMainHand().setType(Material.AIR);

        for (ItemStack i : p.getInventory().getContents()){
            if (i.getType() == Material.GLASS_BOTTLE){
                i.setType(Material.AIR);
            }
        }

        p.setLevel(0);
        if (thirst + 256 >= 1000){
            p.setLevel(1000);
            return;
        }
        p.setLevel(thirst + 256);
        p.sendMessage(p.getLevel() + " // " + thirst + 256);
    }
}
 
開發者ID:cadox8,項目名稱:WC,代碼行數:26,代碼來源:Thirst.java

示例2: onPlayerItemConsume

import org.bukkit.event.player.PlayerItemConsumeEvent; //導入方法依賴的package包/類
@EventHandler
public void onPlayerItemConsume(PlayerItemConsumeEvent event) {
	Player player = event.getPlayer();
	ItemStack item = event.getItem();
	
	// if the item is not a potion we don't want to care.
	if (item == null || item.getType() != Material.POTION) {
		return;
	}
	
	// if the potion has the durability of a strength 2 potion, tell them and cancel.
	if (item.getDurability() == 8233) {
		player.sendMessage(ChatColor.RED + "Strength II is disabled.");
		event.setCancelled(true);
	}
}
 
開發者ID:LeonTG,項目名稱:NoStrengthII,代碼行數:17,代碼來源:DrinkListener.java

示例3: onConsume

import org.bukkit.event.player.PlayerItemConsumeEvent; //導入方法依賴的package包/類
@EventHandler
public void onConsume(PlayerItemConsumeEvent e){
    if(e.getItem() == null){
        return;
    }
    
	Player p = e.getPlayer();
    //deny potion
	if (p == null){
		return;
	}
    
    Region r = RedProtect.get().rm.getTopRegion(p.getLocation());
    if (r != null && e.getItem().getType().equals(Material.CHORUS_FRUIT) && !r.canTeleport(p)){
    	RPLang.sendMessage(p, "playerlistener.region.cantuse");
    	e.setCancelled(true);
    }
}
 
開發者ID:FabioZumbi12,項目名稱:RedProtect,代碼行數:19,代碼來源:RPMine19.java

示例4: onConsume

import org.bukkit.event.player.PlayerItemConsumeEvent; //導入方法依賴的package包/類
@EventHandler
  public void onConsume(PlayerItemConsumeEvent e){
      if(e.getItem() == null){
          return;
      }
      
      Player p = e.getPlayer();
      Location l = p.getLocation();
      
      Region r = RedProtect.get().rm.getTopRegion(l);

//deny item usage
List<String> items = RPConfig.getGlobalFlagList(p.getWorld().getName()+".deny-item-usage.items");
  	if (e.getItem() != null && items.contains(e.getItem().getType().name())){
  		if (r != null && ((!RPConfig.getGlobalFlagBool(p.getWorld().getName()+".deny-item-usage.allow-on-claimed-rps") && r.canBuild(p)) || 
  				(RPConfig.getGlobalFlagBool(p.getWorld().getName()+".deny-item-usage.allow-on-claimed-rps") && !r.canBuild(p)))){
  			RPLang.sendMessage(p, "playerlistener.region.cantuse");
  			e.setCancelled(true);  
  			return;
  		}
  		if (r == null && !RPConfig.getGlobalFlagBool(p.getWorld().getName()+".deny-item-usage.allow-on-wilderness") && !RedProtect.get().ph.hasPerm(p, "redprotect.bypass.world")){
  			RPLang.sendMessage(p, "playerlistener.region.cantuse");
  			e.setCancelled(true);
	}
      }
  }
 
開發者ID:FabioZumbi12,項目名稱:RedProtect,代碼行數:27,代碼來源:RPGlobalListener.java

示例5: onConsume

import org.bukkit.event.player.PlayerItemConsumeEvent; //導入方法依賴的package包/類
@EventHandler
public void onConsume(PlayerItemConsumeEvent e){
    if(e.getItem() == null){
        return;
    }
    
	Player p = e.getPlayer();
    //deny potion
	if (p == null){
		return;
	}
	
    if(RPUtil.denyPotion(e.getItem(), p)){
    	e.setCancelled(true);                    
    }
}
 
開發者ID:FabioZumbi12,項目名稱:RedProtect,代碼行數:17,代碼來源:RPPlayerListener.java

示例6: OnPlayerConsumeEvent

import org.bukkit.event.player.PlayerItemConsumeEvent; //導入方法依賴的package包/類
@EventHandler(priority = EventPriority.HIGHEST)
public void OnPlayerConsumeEvent(PlayerItemConsumeEvent event) {
	ItemStack stack = event.getItem();

	/* Disable notch apples */
	if (ItemManager.getId(event.getItem()) == ItemManager.getId(Material.GOLDEN_APPLE)) {
		if (event.getItem().getDurability() == (short)0x1) {
			CivMessage.sendError(event.getPlayer(), "You cannot use notch apples. Sorry.");
			event.setCancelled(true);
			return;
		}
	}	

	if (stack.getType().equals(Material.POTION)) {
		int effect = event.getItem().getDurability() & 0x000F;			
		if (effect == 0xE) {
			event.setCancelled(true);
			CivMessage.sendError(event.getPlayer(), "You cannot use invisibility potions for now... Sorry.");
			return;
		}
	}
}
 
開發者ID:netizen539,項目名稱:civcraft,代碼行數:23,代碼來源:BlockListener.java

示例7: onPlayerEat

import org.bukkit.event.player.PlayerItemConsumeEvent; //導入方法依賴的package包/類
@EventHandler
public void onPlayerEat(PlayerItemConsumeEvent e) {
    final Player player = e.getPlayer();
    ItemStack itemConsumed = e.getItem();
    if (itemConsumed.isSimilar(CraftingAndRecipes.redstoneApple())) {
        player.setVelocity(player.getVelocity().setY(0.4));
        player.sendMessage(ChatColor.RED + "[CPU] You just got shocked by eating a redstone apple!");
        player.sendMessage(ChatColor.RED + "[CPU] You can't move that well!");
        CPUPlugin.bukkitScheduler.scheduleSyncDelayedTask(CPUPlugin.plugin, new BukkitRunnable() {
            @Override
            public void run() {
                player.addPotionEffect(new PotionEffect(PotionEffectType.SLOW, 2000, 1));
                player.addPotionEffect(new PotionEffect(PotionEffectType.CONFUSION, 2000, 4));
            }
        }, 60);
    }
}
 
開發者ID:waicool20,項目名稱:CPU,代碼行數:18,代碼來源:EatsRedstoneApple.java

示例8: onUseHealItem

import org.bukkit.event.player.PlayerItemConsumeEvent; //導入方法依賴的package包/類
@EventHandler
public void onUseHealItem(PlayerItemConsumeEvent e) {
    final Player p = e.getPlayer();
    if (!RUtils.isInInfectedWorld(p)) return;
    final ItemStack hand = e.getItem();
    if (hand == null || hand.getType() != Material.MELON || hand.getDurability() != (short) 14) return;
    if (p.getMaxHealth() == p.getHealth() && p.getFoodLevel() >= 20) {
        e.setCancelled(true); // don't waste medpacks - should never happen, though
        return;
    }
    double newHealth = p.getHealth() + 8D;
    int newFood = p.getFoodLevel() + 8;
    if (newHealth > p.getMaxHealth()) newHealth = p.getMaxHealth();
    if (newFood > 20) newFood = 20;
    p.setHealth(newHealth);
    p.setFoodLevel(newFood);
}
 
開發者ID:RoyalDev,項目名稱:RoyalSurvivors,代碼行數:18,代碼來源:SurvivorsListener.java

示例9: onDrinky

import org.bukkit.event.player.PlayerItemConsumeEvent; //導入方法依賴的package包/類
@EventHandler
public void onDrinky(PlayerItemConsumeEvent e) {
    final Player p = e.getPlayer();
    final ItemStack hand = e.getItem();
    if (hand == null || hand.getType() != Material.POTION || hand.getDurability() != (short) 0 || !RUtils.isInInfectedWorld(p))
        return;
    PConfManager pcm = PConfManager.getPConfManager(p);
    float thirst = pcm.getFloat("thirst");
    if (!pcm.isSet("thirst")) thirst = 1F;
    if (thirst >= 1F) {
        e.setCancelled(true); // let's not waste water bottles
        return;
    }
    thirst += Config.thirstRestorePercent / 100F;
    if (thirst > 1F) thirst = 1F;
    pcm.set("thirst", thirst);
    pcm.set("thirstSaturation", (float) Config.thirstSaturationMax);
    p.setExp(thirst);
}
 
開發者ID:RoyalDev,項目名稱:RoyalSurvivors,代碼行數:20,代碼來源:ThirstListener.java

示例10: onPlayerItemConsume

import org.bukkit.event.player.PlayerItemConsumeEvent; //導入方法依賴的package包/類
/**
 * Delete the ItemStack
 *
 * @param event Event
 */
@EventHandler
public void onPlayerItemConsume(PlayerItemConsumeEvent event)
{
    if(event.getItem() == null)
        return;

    ItemStack stack = event.getItem();

    if(stack.getType().equals(Material.MUSHROOM_SOUP))
        Bukkit.getScheduler().runTask(this.plugin, () -> event.getPlayer().getInventory().remove(Material.BOWL));
}
 
開發者ID:SamaGames,項目名稱:SurvivalAPI,代碼行數:17,代碼來源:RemoveItemOnUseModule.java

示例11: onPlayerConsume

import org.bukkit.event.player.PlayerItemConsumeEvent; //導入方法依賴的package包/類
@EventHandler(ignoreCancelled = true, priority = EventPriority.MONITOR)
public void onPlayerConsume(PlayerItemConsumeEvent event) {
    ItemStack stack = event.getItem();
    if (stack != null && stack.getType() == Material.GOLDEN_APPLE && stack.getDurability() == 1) {
        Player player = event.getPlayer();
        if (setCooldown(player, player.getUniqueId(), defaultCooldown, false, new Predicate<Long>() {
            @Override
            public boolean apply(@Nullable Long value) {
                return false;
            }
        })) {

            player.sendMessage(ChatColor.translateAlternateColorCodes('&', "&c\u2588\u2588\u2588\u2588\u2588&c\u2588\u2588\u2588"));
            player.sendMessage(ChatColor.translateAlternateColorCodes('&', "&c\u2588\u2588\u2588&e\u2588\u2588&c\u2588\u2588\u2588"));
            player.sendMessage(ChatColor.translateAlternateColorCodes('&', ("&c\u2588\u2588\u2588&e\u2588&c\u2588\u2588\u2588\u2588 &6&l " + this.name + ": ")));
            player.sendMessage(ChatColor.translateAlternateColorCodes('&', "&c\u2588\u2588&6\u2588\u2588\u2588\u2588&c\u2588\u2588 &7  Consumed"));
            player.sendMessage(ChatColor.translateAlternateColorCodes('&', "&c\u2588&6\u2588\u2588&f\u2588&6\u2588&6\u2588\u2588&c\u2588"));
            player.sendMessage(ChatColor.translateAlternateColorCodes('&', "&c\u2588&6\u2588&f\u2588&6\u2588&6\u2588&6\u2588\u2588&c\u2588 &6 Cooldown Remaining:"));
            player.sendMessage(ChatColor.translateAlternateColorCodes('&', ("&c\u2588&6\u2588\u2588&6\u2588&6\u2588&6\u2588\u2588&c\u2588 &7  " + DurationFormatter.getRemaining(getRemaining(player), true, false))));
            player.sendMessage(ChatColor.translateAlternateColorCodes('&', "&c\u2588&6\u2588\u2588&6\u2588&6\u2588&6\u2588\u2588&c\u2588"));
            player.sendMessage(ChatColor.translateAlternateColorCodes('&', "&c\u2588\u2588&6\u2588\u2588\u2588\u2588&c\u2588\u2588"));
            player.sendMessage(ChatColor.translateAlternateColorCodes('&', "&c\u2588\u2588\u2588\u2588\u2588&c\u2588\u2588\u2588"));
        } else {
            event.setCancelled(true);
            player.sendMessage(ChatColor.RED + "You still have a " + getDisplayName() + ChatColor.RED + " cooldown for another " + ChatColor.BOLD
                    + DurationFormatter.getRemaining(getRemaining(player), true, false) + ChatColor.RED + '.');
        }
    }
}
 
開發者ID:funkemunky,項目名稱:HCFCore,代碼行數:30,代碼來源:GappleTimer.java

示例12: onEat

import org.bukkit.event.player.PlayerItemConsumeEvent; //導入方法依賴的package包/類
@EventHandler
public void onEat(PlayerItemConsumeEvent event){
	String type = MinecraftUtils.getExtraType(event.getItem());
	FoodStatus food = ExtraManager.foods.get(type);
	if( food == null )
	if(event.getItem().getType() == Material.GOLDEN_APPLE){
		if(event.getItem().getDurability() == 1){
			type = "napple";
		}else{
			type = "apple";
		}
		food = ExtraManager.foods.get(type);
	}
	if( food == null )
		return;
	event.setCancelled(true);
	VPPlayer playerPlus = VanillaPlusCore.getPlayerManager().getPlayer(event.getPlayer());
	VPPConsumeFoodEvent e = new VPPConsumeFoodEvent(playerPlus, food, type);
	Bukkit.getServer().getPluginManager().callEvent(e);
	if(e.isCancelled())
		return;
	ItemStack item = event.getItem();
	if(item.getAmount() == 1)
		event.getPlayer().setItemInHand(null);
	else{
		item.setAmount(item.getAmount()-1);
		event.getPlayer().setItemInHand(item);
	}
	food.apply(e.getPlayer());
	
}
 
開發者ID:dracnis,項目名稱:VanillaPlus,代碼行數:32,代碼來源:ExtraManager.java

示例13: onConsumeMilk

import org.bukkit.event.player.PlayerItemConsumeEvent; //導入方法依賴的package包/類
@EventHandler
public void onConsumeMilk(PlayerItemConsumeEvent event) {
    Player player = event.getPlayer();
    ItemStack milk = new ItemStack(event.getItem());
    if (milk.getType().equals(Material.MILK_BUCKET) && API.getFlashLightToggle().contains(player.getName())) {
        event.setCancelled(true);
        player.getActivePotionEffects().stream().filter(effect -> !(player.getActivePotionEffects() == PotionEffectType.NIGHT_VISION)).forEach(effect -> player.removePotionEffect(effect.getType()));
        player.addPotionEffect(new PotionEffect(PotionEffectType.NIGHT_VISION, Integer.MAX_VALUE, 0, true, false));
    }
}
 
開發者ID:MattJBrowning,項目名稱:FlashlightPlus,代碼行數:11,代碼來源:EventListener.java

示例14: onEat

import org.bukkit.event.player.PlayerItemConsumeEvent; //導入方法依賴的package包/類
@EventHandler
public void onEat(PlayerItemConsumeEvent e) {
	if (e.getItem() != null) {
		final Player p = e.getPlayer();
		ItemStack item = e.getItem();
		if (Slimefun.hasUnlocked(p, item, true)) {
			if (SlimefunManager.isItemSimiliar(item, SlimefunItems.MONSTER_JERKY, true)) {
				e.setCancelled(true);
				if (SlimefunManager.isItemSimiliar(p.getInventory().getItemInOffHand(), SlimefunItems.MONSTER_JERKY, true)) {
					p.getInventory().setItemInOffHand(InvUtils.decreaseItem(p.getInventory().getItemInOffHand(), 1));
				}
				else{
					p.getInventory().setItemInMainHand(InvUtils.decreaseItem(p.getInventory().getItemInMainHand(), 1));
				}
				PlayerInventory.update(p);
				p.addPotionEffect(new PotionEffect(PotionEffectType.SATURATION, 5, 0));
			}
			else if (SlimefunManager.isItemSimiliar(item, SlimefunItems.FORTUNE_COOKIE, true)) p.sendMessage(ChatColor.translateAlternateColorCodes('&', Messages.local.getTranslation("messages.fortune-cookie").get(CSCoreLib.randomizer().nextInt(Messages.local.getTranslation("messages.fortune-cookie").size()))));
			else if (SlimefunManager.isItemSimiliar(item, SlimefunItems.BEEF_JERKY, true)) p.setSaturation((Integer) Slimefun.getItemValue("BEEF_JERKY", "Saturation"));
			else if (SlimefunManager.isItemSimiliar(item, SlimefunItems.MEDICINE, true)) {
				if (p.hasPotionEffect(PotionEffectType.POISON)) p.removePotionEffect(PotionEffectType.POISON);
				if (p.hasPotionEffect(PotionEffectType.WITHER)) p.removePotionEffect(PotionEffectType.WITHER);
				if (p.hasPotionEffect(PotionEffectType.SLOW)) p.removePotionEffect(PotionEffectType.SLOW);
				if (p.hasPotionEffect(PotionEffectType.SLOW_DIGGING)) p.removePotionEffect(PotionEffectType.SLOW_DIGGING);
				if (p.hasPotionEffect(PotionEffectType.WEAKNESS)) p.removePotionEffect(PotionEffectType.WEAKNESS);
				if (p.hasPotionEffect(PotionEffectType.CONFUSION)) p.removePotionEffect(PotionEffectType.CONFUSION);
				if (p.hasPotionEffect(PotionEffectType.BLINDNESS)) p.removePotionEffect(PotionEffectType.BLINDNESS);
				p.setFireTicks(0);
			}
			else if (item.getType() == Material.POTION) {
				SlimefunItem sfItem = SlimefunItem.getByItem(item);
				if (sfItem != null && sfItem instanceof Juice) {
					int mode = 0;
					
					if (SlimefunManager.isItemSimiliar(item, p.getInventory().getItemInMainHand(), true)) {
						if (p.getInventory().getItemInMainHand().getAmount() == 1) {
							mode = 0;
						}
						else {
							mode = 2;
						}
					}
					else if (SlimefunManager.isItemSimiliar(item, p.getInventory().getItemInOffHand(), true)) {
						if (p.getInventory().getItemInOffHand().getAmount() == 1) {
							mode = 1;
						}
						else {
							mode = 2;
						}
					}
					
					final int m = mode;
					
					Bukkit.getScheduler().scheduleSyncDelayedTask(SlimefunStartup.instance, new Runnable() {
						
						
		                @Override
		                public void run() {
		                    if (m == 0) {
		                    	p.getInventory().setItemInMainHand(null);
		                    }
		                    else if (m == 1) {
		                    	p.getInventory().setItemInOffHand(null);
		                    }
		                    else if (m == 2) {
		                    	p.getInventory().removeItem(new ItemStack(Material.GLASS_BOTTLE, 1));
		                    }
		                }
		                
		            }, 1L);
				}
			}
		}
		else e.setCancelled(true);
	}
}
 
開發者ID:StarWishsama,項目名稱:Slimefun4-Chinese-Version,代碼行數:77,代碼來源:ItemListener.java

示例15: onPotionConsume

import org.bukkit.event.player.PlayerItemConsumeEvent; //導入方法依賴的package包/類
@EventHandler
public void onPotionConsume(PlayerItemConsumeEvent event){
	ItemStack consumed = event.getItem();
	if(consumed.getType().equals(Material.POTION)){
		Potion potion = new Potion(consumed);
		Account player = new Account(event.getPlayer());
		ca.damocles.accountsystem.Character character = player.getLoadedCharacter();
		
		switch(potion.getType()){
		case SOUL:
			if(character.getSouls() != 5)
				character.setSouls(character.getSouls() + 1);
			return;
		case HARM:
			character.setHealth(character.getHealth() - (4*potion.getAmplifier()));
			return;
		case HEAL:
			character.setHealth(character.getHealth() + (4*potion.getAmplifier()));
			return;
		case MANA:
			character.setMana(character.getMana() + (5*potion.getAmplifier()));
			return;
		case BLIND:
			event.getPlayer().addPotionEffect(new PotionEffect(PotionEffectType.BLINDNESS, potion.getDuration(), potion.getAmplifier()));
			return;
		case EXPLOSION:
			event.getPlayer().getWorld().createExplosion(event.getPlayer().getLocation(), potion.getAmplifier());
			return;
		case FIRE:
			event.getPlayer().setFireTicks(potion.getDuration());
			return;
		case FIRE_RESIST:
			event.getPlayer().addPotionEffect(new PotionEffect(PotionEffectType.FIRE_RESISTANCE, potion.getDuration(), potion.getAmplifier()));
			return;
		case HUNGER:
			event.getPlayer().addPotionEffect(new PotionEffect(PotionEffectType.HUNGER, potion.getDuration(), potion.getAmplifier()));
			return;
		case JUMP:
			event.getPlayer().addPotionEffect(new PotionEffect(PotionEffectType.JUMP, potion.getDuration(), potion.getAmplifier()));
			return;
		case LIGHTNING:
			event.getPlayer().getWorld().strikeLightning(event.getPlayer().getLocation());
			return;
		case NAUSEA:
			event.getPlayer().addPotionEffect(new PotionEffect(PotionEffectType.CONFUSION, potion.getDuration(), potion.getAmplifier()));
			return;
		case NONE:
			return;
		case POISON:
			event.getPlayer().addPotionEffect(new PotionEffect(PotionEffectType.POISON, potion.getDuration(), potion.getAmplifier()));
			return;
		case REGEN:
			event.getPlayer().addPotionEffect(new PotionEffect(PotionEffectType.REGENERATION, potion.getDuration(), potion.getAmplifier()));
			return;
		case RESISTANCE:
			event.getPlayer().addPotionEffect(new PotionEffect(PotionEffectType.DAMAGE_RESISTANCE, potion.getDuration(), potion.getAmplifier()));
			return;
		case SLOW:
			event.getPlayer().addPotionEffect(new PotionEffect(PotionEffectType.SLOW, potion.getDuration(), potion.getAmplifier()));
			return;
		case SPEED:
			event.getPlayer().addPotionEffect(new PotionEffect(PotionEffectType.SPEED, potion.getDuration(), potion.getAmplifier()));
			return;
		case WEAKNESS:
			event.getPlayer().addPotionEffect(new PotionEffect(PotionEffectType.WEAKNESS, potion.getDuration(), potion.getAmplifier()));
			return;
		case WITHER:
			event.getPlayer().addPotionEffect(new PotionEffect(PotionEffectType.WITHER, potion.getDuration(), potion.getAmplifier()));
			return;
		default:
			return;
		}
		
	}
	
}
 
開發者ID:DamoclesProject,項目名稱:Damocles,代碼行數:77,代碼來源:PotionHandler.java


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