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


Java FoodLevelChangeEvent.getFoodLevel方法代码示例

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


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

示例1: onEat

import org.bukkit.event.entity.FoodLevelChangeEvent; //导入方法依赖的package包/类
@EventHandler
public void onEat(FoodLevelChangeEvent event)
{
	if (event.getEntityType() == EntityType.PLAYER)
	{	
		Player player = (Player)event.getEntity();
		int foodLevelAdded = player.getFoodLevel() - event.getFoodLevel();
		
		// Monitor added food level (food consumed) only
		if (foodLevelAdded < 0)
		{
			MagicDataService magicDataService = MagicDataService.getInstance();
			PlayerMagicData data = magicDataService.getMagicData(player.getName());
			
			if (player.getFoodLevel() < MagicDataService.MAX_FOOD_LEVEL)
			{				
				data.addFoodLevelsToRegen(foodLevelAdded);		
			}
			else // Reached maximum, make sure it doesn't regenerate for any reason
			{
				data.setFoodLevelsToRegen(0);
				data.setLastTimeRegenerated(0);
			}
		}
	}
}
 
开发者ID:Allov,项目名称:world-of-icerealm,代码行数:27,代码来源:MagicFoodLevelEvent.java

示例2: onHungerChange

import org.bukkit.event.entity.FoodLevelChangeEvent; //导入方法依赖的package包/类
/**
 * Prevents changing of hunger while having a special permission and being on your island
 * @param e
 */
@EventHandler(priority = EventPriority.LOW, ignoreCancelled = true)
public void onHungerChange(final FoodLevelChangeEvent e) {
    if (DEBUG) {
        plugin.getLogger().info(e.getEventName() + " food level = " + ((Player)e.getEntity()).getFoodLevel() + " new food level = " + e.getFoodLevel());

    }
    // Allow food increases
    if (e.getFoodLevel() - ((Player)e.getEntity()).getFoodLevel() > 0) {
        return;
    }
    if (e.getEntity().hasPermission(Settings.PERMPREFIX + "nohunger")) {
        if(plugin.getGrid().playerIsOnIsland((Player) e.getEntity())) {
            e.setCancelled(true);
        }
    }
}
 
开发者ID:tastybento,项目名称:acidisland,代码行数:21,代码来源:PlayerEvents.java

示例3: onFoodRegen

import org.bukkit.event.entity.FoodLevelChangeEvent; //导入方法依赖的package包/类
@EventHandler(priority=EventPriority.HIGH)
public void onFoodRegen(FoodLevelChangeEvent e){
	if(e.getEntity() instanceof Player){
		Player p = (Player) e.getEntity();
		
		Game g = GameManager.getInstance().getGame(p);
		
		if(g != null){
			if(g.gs == GameStage.Lobby || g.gs == GameStage.Build){
				if(e.getFoodLevel() != 20){
					e.setFoodLevel(20);
				}
			}
		}
	}
}
 
开发者ID:WeaselBuilds,项目名称:WeaselsWalls,代码行数:17,代码来源:FoodRegen.java

示例4: onEntityEat

import org.bukkit.event.entity.FoodLevelChangeEvent; //导入方法依赖的package包/类
@EventHandler
@SuppressWarnings("unused")
public void onEntityEat(FoodLevelChangeEvent e) {
    if (e.getEntity() instanceof Player) {
        Player player = (Player) e.getEntity();
        if (player.getFoodLevel() < e.getFoodLevel()) {
            DACManager.getBackend().checkFastEat(player);
        }
    }
}
 
开发者ID:Notoh,项目名称:DynamicAC,代码行数:11,代码来源:PlayerListener.java

示例5: onPlayerFoodLevelChange

import org.bukkit.event.entity.FoodLevelChangeEvent; //导入方法依赖的package包/类
@EventHandler(priority = EventPriority.NORMAL)
public void onPlayerFoodLevelChange(FoodLevelChangeEvent evt) {
	
	if (evt.getEntity() instanceof Player) {
		Player player = (Player)evt.getEntity();
		
		if (perkService.playerHasPerk(player, SurvivorTree.ExplorerId)) {
			
			if (player.getFoodLevel() > evt.getFoodLevel() && new Random(Calendar.getInstance().getTimeInMillis()).nextInt(2) == 1) {
				evt.setCancelled(true);
			}
		}
	}
}
 
开发者ID:Allov,项目名称:world-of-icerealm,代码行数:15,代码来源:ExplorerPerk.java

示例6: onFoodLevelChange

import org.bukkit.event.entity.FoodLevelChangeEvent; //导入方法依赖的package包/类
@EventHandler(priority = EventPriority.HIGH)
public void onFoodLevelChange(FoodLevelChangeEvent e) {
    try {
        if (e.getEntity() instanceof Player && config.getBoolean("InvisibilityFeatures.DisableHunger")) {
            Player p = (Player) e.getEntity();
            if (plugin.getVanishStateMgr().isVanished(p.getUniqueId())
                    && e.getFoodLevel() <= p.getFoodLevel())
                e.setCancelled(true);
        }
    } catch (Exception er) {
        plugin.logException(er);
    }
}
 
开发者ID:MyzelYam,项目名称:SuperVanish,代码行数:14,代码来源:GeneralEventHandler.java

示例7: onFoodLevelChange

import org.bukkit.event.entity.FoodLevelChangeEvent; //导入方法依赖的package包/类
@EventHandler(ignoreCancelled = true, priority = EventPriority.HIGHEST)
public void onFoodLevelChange(FoodLevelChangeEvent e) {
    plugin.tm.cancelSpectator(e);
    if (e.getEntity() instanceof Player == true && !e.isCancelled()) {
        Player player = (Player) e.getEntity();
        TeamManager.TeamId ti = plugin.pm.getTeamId(player);
        if (ti != null && player.getFoodLevel() > e.getFoodLevel()) {
            if ((Math.random() * ((10) + 1)) > 4) {
                e.setCancelled(true);
            }
        }
    }
}
 
开发者ID:ddonofrio,项目名称:libelula,代码行数:14,代码来源:EventManager.java

示例8: onPlayerFoodChange

import org.bukkit.event.entity.FoodLevelChangeEvent; //导入方法依赖的package包/类
@EventHandler(priority = EventPriority.NORMAL)
public void onPlayerFoodChange(final FoodLevelChangeEvent event) {
    if (event.getEntity() instanceof Player && plugin.isSkyWorld(event.getEntity().getWorld())) {
        Player hungerman = (Player) event.getEntity();
        float randomNum = RANDOM.nextFloat();
        if (plugin.isSkyWorld(hungerman.getWorld()) && hungerman.getFoodLevel() > event.getFoodLevel() && plugin.playerIsOnIsland(hungerman)) {
            Perk perk = plugin.getPerkLogic().getPerk(hungerman);
            if (randomNum <= perk.getHungerReduction()) {
                event.setCancelled(true);
                return;
            }
        }
    }
}
 
开发者ID:rlf,项目名称:uSkyBlock,代码行数:15,代码来源:PlayerEvents.java

示例9: onStarve

import org.bukkit.event.entity.FoodLevelChangeEvent; //导入方法依赖的package包/类
@EventHandler
public void onStarve(FoodLevelChangeEvent e) {
	if (e.getFoodLevel() < ((Player) e.getEntity()).getFoodLevel()) {
		Player p = (Player) e.getEntity();
		for (ItemStack item: p.getInventory().getContents()) {
			if (SlimefunManager.isItemSimiliar(item, SlimefunItem.getItem("COOLER"), false)) {
				Inventory inv = Backpacks.getInventory(p, item);
				if (inv != null) {
					ItemStack drink = null;
					for (ItemStack i: inv.getContents()) {
						if (i != null && i.getType() == Material.POTION && i.hasItemMeta()) {
							drink = i;
							break;
						}
					}
					if (drink != null) {
						PotionMeta im = (PotionMeta) drink.getItemMeta();
						for (PotionEffect effect: im.getCustomEffects()) {
							p.addPotionEffect(effect);
						}
						p.setSaturation(6F);
						p.playSound(p.getLocation(), Sound.ENTITY_GENERIC_DRINK, 1F, 1F);
						inv.removeItem(drink);
						Backpacks.saveBackpack(inv, item);
						break;
					}
				}
			}
		}
	}
}
 
开发者ID:TheBusyBiscuit,项目名称:Slimefun4,代码行数:32,代码来源:CoolerListener.java

示例10: foodControl

import org.bukkit.event.entity.FoodLevelChangeEvent; //导入方法依赖的package包/类
@EventHandler(priority = EventPriority.LOW)
public void foodControl(FoodLevelChangeEvent event) {
    if(pl.getConfig().getBoolean(Settings.FOODCONTROL.getPath())) {
        if(pl.getJailManager().isPlayerJailed(event.getEntity().getUniqueId())) {
            int min = pl.getConfig().getInt(Settings.FOODCONTROLMIN.getPath());
            int max = pl.getConfig().getInt(Settings.FOODCONTROLMAX.getPath());

            if (event.getFoodLevel() <  min) {
                event.setFoodLevel(min);
            }else {
                event.setFoodLevel(max);
            }
        }
    }
}
 
开发者ID:graywolf336,项目名称:Jail,代码行数:16,代码来源:PlayerListener.java

示例11: onPlayerEat

import org.bukkit.event.entity.FoodLevelChangeEvent; //导入方法依赖的package包/类
@EventHandler
public void onPlayerEat(PlayerItemConsumeEvent e) {
	if (!QuestManagerPlugin.questManagerPlugin.getPluginConfiguration().getWorlds()
			.contains(e.getPlayer().getWorld().getName())) {
		return;
	}
	
	e.setCancelled(true);
	
	if (foodBlacklist.contains(e.getItem().getType())) {
		e.getPlayer().sendMessage(BLACKLIST_MESSAGE);
		return;
	}
	
	ItemStack inHand = e.getItem();
	FoodItem food = FoodItem.wrapItem(inHand.clone());
	
	//make sure not raw food
	if (inHand.hasItemMeta() && inHand.getItemMeta().hasLore()) {
		boolean qlevel = false, flevel = false;
		for (String line : inHand.getItemMeta().getLore()) {
			if (line.toLowerCase().contains("quality:"))
				qlevel = true;
			else if (line.toLowerCase().contains("food level:"))
				flevel = true;
		}
		
		if (qlevel && !flevel)
			return;
	}
	 
	
	inHand.setAmount(inHand.getAmount() - 1);
	if (inHand.getAmount() == 0)
		inHand = null;
	
	if (e.getItem().isSimilar(e.getPlayer().getInventory().getItemInMainHand()))
		e.getPlayer().getInventory().setItemInMainHand(inHand);
	else
		e.getPlayer().getInventory().setItemInOffHand(inHand);		
	
	double qualityDifference = food.getQuality() - 1.0;
	qualityDifference = qualityDifference * hungerRate;
	int newLevel = Math.min(20, e.getPlayer().getFoodLevel()
	//		+ (int) Math.round(food.getFoodLevel() * (1 + qualityDifference)));
			+ (int) Math.round(food.getFoodLevel()));
	
	FoodLevelChangeEvent event = new FoodLevelChangeEvent(e.getPlayer(), newLevel);
	Bukkit.getPluginManager().callEvent(event);
	if (event.isCancelled()) {
		return;
	}
	
	newLevel = event.getFoodLevel();
	
	e.getPlayer().setSaturation(e.getPlayer().getSaturation() + food.getFoodLevel());
	e.getPlayer().setFoodLevel(newLevel);
	e.getPlayer().getWorld().playSound(e.getPlayer().getLocation(), Sound.ENTITY_PLAYER_BURP, 1,1);
	
}
 
开发者ID:Dove-Bren,项目名称:QuestManager,代码行数:61,代码来源:CookingSkill.java

示例12: onFoodLevelChange

import org.bukkit.event.entity.FoodLevelChangeEvent; //导入方法依赖的package包/类
/**
 * Handle FoodLevelChange events that involve modifying the event.
 *
 * @param event The event to modify
 */
@EventHandler(priority = EventPriority.LOW, ignoreCancelled = true)
public void onFoodLevelChange(FoodLevelChangeEvent event) {
    Entity entity = event.getEntity();

    if (!(entity instanceof Player)) {
        return;
    }

    Player player = (Player) entity;

    if (!UserManager.hasPlayerDataKey(player)) {
        return;
    }

    int currentFoodLevel = player.getFoodLevel();
    int newFoodLevel = event.getFoodLevel();
    int foodChange = newFoodLevel - currentFoodLevel;

    if (foodChange <= 0) {
        return;
    }

    /*
     * Some foods have 3 ranks
     * Some foods have 5 ranks
     * The number of ranks is based on how 'common' the item is
     * We can adjust this quite easily if we find something is giving too much of a bonus
     */
    switch (player.getItemInHand().getType()) {
        case BAKED_POTATO:  /* RESTORES 3 HUNGER - RESTORES 5 1/2 HUNGER @ 1000 */
        case BREAD:         /* RESTORES 2 1/2 HUNGER - RESTORES 5 HUNGER @ 1000 */
        case CARROT_ITEM:   /* RESTORES 2 HUNGER - RESTORES 4 1/2 HUNGER @ 1000 */
        case GOLDEN_CARROT: /* RESTORES 3 HUNGER - RESTORES 5 1/2 HUNGER @ 1000 */
        case MUSHROOM_SOUP: /* RESTORES 4 HUNGER - RESTORES 6 1/2 HUNGER @ 1000 */
        case PUMPKIN_PIE:   /* RESTORES 4 HUNGER - RESTORES 6 1/2 HUNGER @ 1000 */
            if (Permissions.secondaryAbilityEnabled(player, SecondaryAbility.FARMERS_DIET)) {
                event.setFoodLevel(UserManager.getPlayer(player).getHerbalismManager().farmersDiet(Herbalism.farmersDietRankLevel1, newFoodLevel));
            }
            return;

        case COOKIE:           /* RESTORES 1/2 HUNGER - RESTORES 2 HUNGER @ 1000 */
        case MELON:            /* RESTORES 1 HUNGER - RESTORES 2 1/2 HUNGER @ 1000 */
        case POISONOUS_POTATO: /* RESTORES 1 HUNGER - RESTORES 2 1/2 HUNGER @ 1000 */
        case POTATO_ITEM:      /* RESTORES 1/2 HUNGER - RESTORES 2 HUNGER @ 1000 */
            if (Permissions.secondaryAbilityEnabled(player, SecondaryAbility.FARMERS_DIET)) {
                event.setFoodLevel(UserManager.getPlayer(player).getHerbalismManager().farmersDiet(Herbalism.farmersDietRankLevel2, newFoodLevel));
            }
            return;

        case COOKED_FISH: /* RESTORES 2 1/2 HUNGER - RESTORES 5 HUNGER @ 1000 */
            if (Permissions.secondaryAbilityEnabled(player, SecondaryAbility.FISHERMANS_DIET)) {
                event.setFoodLevel(UserManager.getPlayer(player).getFishingManager().handleFishermanDiet(Fishing.fishermansDietRankLevel1, newFoodLevel));
            }
            return;

        case RAW_FISH:    /* RESTORES 1 HUNGER - RESTORES 2 1/2 HUNGER @ 1000 */
            if (Permissions.secondaryAbilityEnabled(player, SecondaryAbility.FISHERMANS_DIET)) {
                event.setFoodLevel(UserManager.getPlayer(player).getFishingManager().handleFishermanDiet(Fishing.fishermansDietRankLevel2, newFoodLevel));
            }
            return;

        default:
            return;
    }
}
 
开发者ID:Pershonkey,项目名称:McMMOPlus,代码行数:71,代码来源:EntityListener.java


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