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


Java PlayerItemConsumeEvent.getPlayer方法代碼示例

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


在下文中一共展示了PlayerItemConsumeEvent.getPlayer方法的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: onConsume

import org.bukkit.event.player.PlayerItemConsumeEvent; //導入方法依賴的package包/類
@EventHandler(priority = EventPriority.HIGHEST)
public void onConsume(PlayerItemConsumeEvent event)
{
	if(event.isCancelled()) return;
	Player player = event.getPlayer();
	if(event.getItem().getType() == Material.POISONOUS_POTATO)
	{
		for (PotionEffect effect : player.getActivePotionEffects())
	        player.removePotionEffect(effect.getType());

		Random rand = new Random();
		if(rand.nextInt(10) + 1 <= 6)
		{
			player.addPotionEffect(new PotionEffect(PotionEffectType.POISON, 100, 0), true);
			player.addPotionEffect(new PotionEffect(PotionEffectType.CONFUSION, 200, 0), true);
		}
	}
}
 
開發者ID:FattyMieo,項目名稱:SurvivalPlus,代碼行數:19,代碼來源:PoisonousPotato.java

示例3: onConsume

import org.bukkit.event.player.PlayerItemConsumeEvent; //導入方法依賴的package包/類
@EventHandler(priority = EventPriority.HIGHEST)
public void onConsume(PlayerItemConsumeEvent event)
{
	if(event.isCancelled()) return;
	Player player = event.getPlayer();
	if(event.getItem().getType() == Material.BEETROOT)
	{
		int amp = 0;
		int dur = 200;
		for (PotionEffect effect : player.getActivePotionEffects())
		{
			if(effect.getType().equals(PotionEffectType.INCREASE_DAMAGE))
			{
				dur += effect.getDuration();
				if(dur > 600) dur = 600;
				player.removePotionEffect(effect.getType());
			}
		}
		player.addPotionEffect(new PotionEffect(PotionEffectType.INCREASE_DAMAGE, dur, amp));
	}
}
 
開發者ID:FattyMieo,項目名稱:SurvivalPlus,代碼行數:22,代碼來源:BeetrootStrength.java

示例4: onPlayerItemConsumeEvent

import org.bukkit.event.player.PlayerItemConsumeEvent; //導入方法依賴的package包/類
@EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true)
public void onPlayerItemConsumeEvent(PlayerItemConsumeEvent event)
{
	Player player = event.getPlayer();
	
	if (!WorldGuardUtils.hasBypass(player))
	{
		ItemMeta itemMeta = event.getItem().getItemMeta();
		if (itemMeta instanceof PotionMeta)
		{
			WorldGuardExtraFlagsPlugin.getWorldGuardPlugin().getSessionManager().get(player).getHandler(GiveEffectsFlag.class).drinkPotion(player, Potion.fromItemStack(event.getItem()).getEffects());
		}
		else
		{
			Material material = event.getItem().getType();
			if (material == Material.MILK_BUCKET)
			{
				WorldGuardExtraFlagsPlugin.getWorldGuardPlugin().getSessionManager().get(player).getHandler(GiveEffectsFlag.class).drinkMilk(player);
			}
		}
	}
}
 
開發者ID:isokissa3,項目名稱:WorldGuardExtraFlagsPlugin,代碼行數:23,代碼來源:PlayerListener.java

示例5: onEat

import org.bukkit.event.player.PlayerItemConsumeEvent; //導入方法依賴的package包/類
@EventHandler(priority = EventPriority.MONITOR, ignoreCancelled = true)
public void onEat(final PlayerItemConsumeEvent event) {

	final PlayerStat stat = PlayerStat.FOOD_EATEN;

	// Get player
	final Player player = event.getPlayer();

	// Do general check
	if (!plugin.doGeneralCheck(player, stat))
		return;

	final String foodName = StatzUtil.getFoodName(event.getItem());

	if (foodName == null)
		return;

	// Update value to new stat.
	plugin.getDataManager().setPlayerInfo(player.getUniqueId(), stat,
			StatzUtil.makeQuery("uuid", player.getUniqueId().toString(), "value", 1, "foodEaten", foodName, "world",
					player.getWorld().getName()));

}
 
開發者ID:Staartvin,項目名稱:Statz,代碼行數:24,代碼來源:FoodEatenListener.java

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

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

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

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

示例10: onPlayerItemConsume

import org.bukkit.event.player.PlayerItemConsumeEvent; //導入方法依賴的package包/類
/**
 * On player item consume.
 *
 * @param event the event
 */
@EventHandler(priority = EventPriority.NORMAL, ignoreCancelled = true)
public void onPlayerItemConsume(PlayerItemConsumeEvent event) {
	
	Player player = event.getPlayer();
	IPlayerConfEntry entry;
	
	if((entry = playerConf.get(player)) != null
			&& !entry.isAdminMod()) {
	
		IDummyLand land = Factoid.getThisPlugin().iLands().getLandOrOutsideArea(player.getLocation());
		
		if (!checkPermission(land, player, PermissionList.EAT.getPermissionType())) {
			messagePermission(player);
			event.setCancelled(true);
		}
	}
}
 
開發者ID:Tabinol,項目名稱:Factoid,代碼行數:23,代碼來源:PlayerListener.java

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

示例12: onItemConsume

import org.bukkit.event.player.PlayerItemConsumeEvent; //導入方法依賴的package包/類
/**
 * Fires when an item is consumed. As we are not altering the event,
 * but we do want to know if it is cancelled, we run it on the Monitor
 * priority.
 * 
 * @param event Event to handle.
 */
@EventHandler(priority = EventPriority.MONITOR, ignoreCancelled = true)
public void onItemConsume(PlayerItemConsumeEvent event) {
	if (event.getItem().getType() == Material.MILK_BUCKET) {
		// We don't want to cancel the event, but we want to re-apply darkness after the event
		// has completed - if needed, so that the player can't cheat using the milk.
		final Player player = event.getPlayer();
		getServer().getScheduler().scheduleSyncDelayedTask(this, new Runnable() {

			@Override
			public void run() {
				DarkerNights.checkBlindness(player);
			}
			
		});
	}
}
 
開發者ID:clienthax,項目名稱:DarkerNights,代碼行數:24,代碼來源:DarkerNights.java

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

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

示例15: onConsume

import org.bukkit.event.player.PlayerItemConsumeEvent; //導入方法依賴的package包/類
@EventHandler(priority = EventPriority.HIGHEST)
public void onConsume(PlayerItemConsumeEvent event)
{
	if(!Survival.settings.getBoolean("Mechanics.Thirst.Enabled"))
	{
		if(event.isCancelled()) return;
		Player player = event.getPlayer();
		if(event.getItem().getType() == Material.BEETROOT_SOUP)
		{
			event.setCancelled(true);
		}
	}
}
 
開發者ID:FattyMieo,項目名稱:SurvivalPlus,代碼行數:14,代碼來源:WaterBowl.java


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