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


Java EntityRegainHealthEvent.setCancelled方法代碼示例

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


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

示例1: onRegen

import org.bukkit.event.entity.EntityRegainHealthEvent; //導入方法依賴的package包/類
@EventHandler
public void onRegen(EntityRegainHealthEvent event) {
    if (event.getEntityType() != EntityType.PLAYER || event.getRegainReason() != EntityRegainHealthEvent.RegainReason.SATIATED) return;
    event.setCancelled(true);

    Player player = (Player) event.getEntity();
    long currentTime = System.currentTimeMillis() / 1000;

    if (currentTime - getLastHealTime(player) < 3)
        return;

    double maxHealth = player.getAttribute(Attribute.GENERIC_MAX_HEALTH).getValue();

    if (player.getHealth() < maxHealth) {
        player.setHealth(clamp(player.getHealth() + 1, 0.0, maxHealth));
        healTimes.put(player.getUniqueId(), currentTime);
    }

    float exhToApply = (float) 3;

    Bukkit.getScheduler().runTaskLater(TGM.get(), () -> {
        //This is because bukkit doesn't stop the exhaustion change when cancelling the event
        player.setExhaustion(player.getExhaustion() + exhToApply);
        //debug("Exhaustion before: " + previousExh + " Now: " + p.getExhaustion() + "Saturation: " + p.getSaturation(), p);
    }, 1L);
}
 
開發者ID:WarzoneMC,項目名稱:Warzone,代碼行數:27,代碼來源:RegenModule.java

示例2: onRegen

import org.bukkit.event.entity.EntityRegainHealthEvent; //導入方法依賴的package包/類
@EventHandler(priority = EventPriority.HIGHEST)
public void onRegen(EntityRegainHealthEvent event) {
    Entity entity = event.getEntity();
    if (!(entity instanceof Player)) {
        return;
    }

    Player player = (Player) entity;
    EntityRegainHealthEvent.RegainReason reason = event.getRegainReason();
    if (reason == EntityRegainHealthEvent.RegainReason.SATIATED) {
        FightData data = FightData.getData(player);
        boolean canCheckRegeneration = CHECK_MANAGER.canCheckPlayer(player, CheckType.REGENERATION);
        if (canCheckRegeneration) {
            event.setCancelled(REGENERATION.check(player, data));
            data.setLastHealthEvent(System.currentTimeMillis());
        }
    }

}
 
開發者ID:Vrekt,項目名稱:Arc-v2,代碼行數:20,代碼來源:FightListener.java

示例3: onEntityRegainHealth

import org.bukkit.event.entity.EntityRegainHealthEvent; //導入方法依賴的package包/類
/**
 * On entity regain health.
 *
 * @param event the event
 */
@EventHandler(priority = EventPriority.NORMAL, ignoreCancelled = true)
public void onEntityRegainHealth(EntityRegainHealthEvent event) {
	
	Entity entity = event.getEntity();
	Player player;
	IPlayerConfEntry entry;
	
	if(entity != null && event.getEntity() instanceof Player
			&& (event.getRegainReason() == RegainReason.REGEN
			|| event.getRegainReason() == RegainReason.SATIATED)
			&& (entry = playerConf.get((player = (Player) event.getEntity()))) != null
			&& !entry.isAdminMod()) {
	
		IDummyLand land = Factoid.getThisPlugin().iLands().getLandOrOutsideArea(player.getLocation());
		
		if (!checkPermission(land, player, PermissionList.FOOD_HEAL.getPermissionType())) {
			event.setCancelled(true);
		}
	}
}
 
開發者ID:Tabinol,項目名稱:Factoid,代碼行數:26,代碼來源:PlayerListener.java

示例4: onHealthChange

import org.bukkit.event.entity.EntityRegainHealthEvent; //導入方法依賴的package包/類
@EventHandler
public void onHealthChange(EntityRegainHealthEvent event){
	if(Minigame.getCurrentMinigame()!=null){
		switch(Minigame.getCurrentMinigame().getMap().getType()){
		case CIRCLE_OF_BOOM:
			if(event.getEntity() instanceof Player){
				if(((CircleOfBoom)Minigame.getCurrentMinigame()).isUhc()){
					event.setCancelled(true);
				}
			}
			break;
		case KEY_QUEST:
			break;
		case WATER_THE_MONUMENT:
			break;
		default:
			break;
		}
	}
}
 
開發者ID:tatanpoker09,項目名稱:TCMinigames,代碼行數:21,代碼來源:PlayerListener.java

示例5: onEntityRegainHealth

import org.bukkit.event.entity.EntityRegainHealthEvent; //導入方法依賴的package包/類
@EventHandler
public void onEntityRegainHealth(EntityRegainHealthEvent event) {
	if (!(event.getEntity() instanceof Player)) {
		return;
	}
	
	if (event.getRegainReason() != RegainReason.SATIATED) {
		return;
	}
	
	Player player = (Player) event.getEntity();
	int proteinValue = plugin.getValueManager().getValue(FoodType.PROTEIN, player);
	
	Random ran = new Random();
	if (proteinValue <= -7) {
		if (ran.nextInt(2) == 0) {
			event.setCancelled(true);
		}
	} else if (proteinValue <= -6) {
		if (ran.nextInt(4) > 0) {
			event.setCancelled(true);
		}
	}
	
}
 
開發者ID:SugarCaney,項目名稱:FoodBalance,代碼行數:26,代碼來源:RegenListener.java

示例6: onEnderDragonRegainHealth

import org.bukkit.event.entity.EntityRegainHealthEvent; //導入方法依賴的package包/類
/**
 * Handle EnderDragon regen
 *
 * @param event an EntityRegainHealthEvent
 */
@EventHandler(priority = EventPriority.NORMAL, ignoreCancelled = true)
public void onEnderDragonRegainHealth(final EntityRegainHealthEvent event) {
    if (event.getEntityType() == EntityType.ENDER_DRAGON && event.getRegainReason() == RegainReason.ENDER_CRYSTAL) {
        final EndWorldHandler handler = this.plugin.getHandler(StringUtil.toLowerCamelCase(event.getEntity().getLocation().getWorld().getName()));
        if (handler != null) {
            final float rate = handler.getConfig().getEcHealthRegainRate();
            if (rate < 1.0) {
                if (RANDOM.nextFloat() >= rate) {
                    event.setCancelled(true);
                }
            } else if (rate > 1.0) {
                event.setAmount((int)(rate * event.getAmount()));
            }
        }
    }
}
 
開發者ID:Ribesg,項目名稱:NPlugins,代碼行數:22,代碼來源:EnderDragonListener.java

示例7: onEntityRegainHealth

import org.bukkit.event.entity.EntityRegainHealthEvent; //導入方法依賴的package包/類
/**
 * Cancelling natural regeneration
 *
 * @param event Event
 */
@EventHandler
public void onEntityRegainHealth(EntityRegainHealthEvent event)
{
    if (event.getRegainReason() == EntityRegainHealthEvent.RegainReason.EATING || event.getRegainReason() == EntityRegainHealthEvent.RegainReason.SATIATED)
        event.setCancelled(true);
}
 
開發者ID:SamaGames,項目名稱:SurvivalAPI,代碼行數:12,代碼來源:NaturalListener.java

示例8: onEntityRegainHealth

import org.bukkit.event.entity.EntityRegainHealthEvent; //導入方法依賴的package包/類
@EventHandler
@SuppressWarnings("unused")
public void onEntityRegainHealth(EntityRegainHealthEvent e) {
    if(!(e.getEntity() instanceof Player)) {
        return;
    }
    Player player = (Player) e.getEntity();
    if(e.getRegainReason() == EntityRegainHealthEvent.RegainReason.SATIATED) {
        boolean hacking = DACManager.getBackend().checkRegen(player);
        if(hacking) {
            e.setCancelled(true);
        }
    }
}
 
開發者ID:Notoh,項目名稱:DynamicAC,代碼行數:15,代碼來源:PlayerListener.java

示例9: onRegen

import org.bukkit.event.entity.EntityRegainHealthEvent; //導入方法依賴的package包/類
@EventHandler(priority = EventPriority.HIGHEST)
public void onRegen(EntityRegainHealthEvent e) {

    if (e.getEntityType() != EntityType.PLAYER || e.getRegainReason() != EntityRegainHealthEvent.RegainReason.SATIATED)
        return;

    final Player p = (Player) e.getEntity();

    if (!isEnabled(p.getWorld())) return;

    e.setCancelled(true);

    long currentTime = System.currentTimeMillis() / 1000;
    long lastHealTime = getLastHealTime(p);

    if(currentTime - lastHealTime < module().getLong("frequency"))
        return;

    double maxHealth = p.getAttribute(Attribute.GENERIC_MAX_HEALTH).getValue();

    if (p.getHealth() < maxHealth) {
        p.setHealth(MathHelper.clamp(p.getHealth() + module().getInt("amount"), 0.0, maxHealth));
        healTimes.put(p.getUniqueId(), currentTime);
    }
    
    final float PREVIOUS_EXHAUSTION = p.getExhaustion();
    final float EXHAUSTION_TO_APPLY = (float) module().getDouble("exhaustion");
    	
    Bukkit.getScheduler().runTaskLater(plugin, () -> {
        //This is because bukkit doesn't stop the exhaustion change when cancelling the event
        p.setExhaustion(PREVIOUS_EXHAUSTION + EXHAUSTION_TO_APPLY);
        debug("Exhaustion before: " + PREVIOUS_EXHAUSTION + " Now: " + p.getExhaustion() + " Saturation: " + p.getSaturation(), p);
    },1L);
}
 
開發者ID:gvlfm78,項目名稱:BukkitOldCombatMechanics,代碼行數:35,代碼來源:ModulePlayerRegen.java

示例10: healthRegen

import org.bukkit.event.entity.EntityRegainHealthEvent; //導入方法依賴的package包/類
@EventHandler
public void healthRegen(EntityRegainHealthEvent event){
	if(event.getRegainReason().equals(RegainReason.SATIATED)){
		event.setCancelled(true);
	}
	if(event.getRegainReason().equals(RegainReason.REGEN)){
		event.setCancelled(true);
	}
}
 
開發者ID:DamoclesProject,項目名稱:Damocles,代碼行數:10,代碼來源:EventCanceller.java

示例11: onEntityRegainHealth

import org.bukkit.event.entity.EntityRegainHealthEvent; //導入方法依賴的package包/類
@EventHandler(priority = EventPriority.LOWEST)
public void onEntityRegainHealth(EntityRegainHealthEvent event) {
	if (!usingBeeLoginMod)
		return;
	Entity entity = event.getEntity();
	if (entity instanceof Player) {
		if (!loginStatus.get(((Player) entity).getName().toLowerCase())) {
			event.setCancelled(true);
		}
	}
}
 
開發者ID:lj2000lj,項目名稱:BeeLogin,代碼行數:12,代碼來源:EventCanceler.java

示例12: applyHealthRegen

import org.bukkit.event.entity.EntityRegainHealthEvent; //導入方法依賴的package包/類
@EventHandler(priority = EventPriority.NORMAL)
public void applyHealthRegen(EntityRegainHealthEvent event) {
    if (event.isCancelled()) {
        return;
    }
    if (((event.getEntity() instanceof Player)) &&
            (event.getRegainReason() == EntityRegainHealthEvent.RegainReason.SATIATED)) {
        event.setAmount(event.getAmount() + LoreAttributes.loreManager.getRegenBonus((LivingEntity) event.getEntity()));

        if (event.getAmount() <= 0.0D)
            event.setCancelled(true);
    }
}
 
開發者ID:SettingDust,項目名稱:Lore-Attributes-Reloaded,代碼行數:14,代碼來源:LoreEvents.java

示例13: onHealthRegen

import org.bukkit.event.entity.EntityRegainHealthEvent; //導入方法依賴的package包/類
@EventHandler
public void onHealthRegen(EntityRegainHealthEvent erhe)
{
    if(!isEnabled()) {
        return;
    }

    //If its a player regen
    if(erhe.getEntityType() != EntityType.PLAYER) {
        return;
    }


    //If its just standard health regen
    if(erhe.getRegainReason() != EntityRegainHealthEvent.RegainReason.SATIATED) {
        return;
    }

    Player p = (Player) erhe.getEntity();

    if(p.hasPermission(NO_HEALTH_REGEN)) {

        //this is a special addition due to a bukkit bug where it adds exhuastion even if the healing is cancelled
        if(p.getFoodLevel() >= FOOD_LEVEL && p.getHealth() > PLAYER_DEAD_HEALTH && p.getHealth() < p.getMaxHealth()) {
            p.setExhaustion(p.getExhaustion() - EXHAUSTION_OFFSET);
        }

        //Cancel the event to stop the regen
        erhe.setCancelled(true);
    }
}
 
開發者ID:Eluinhost,項目名稱:ultrahardcore,代碼行數:32,代碼來源:RegenFeature.java

示例14: onPlayerAutoHeal

import org.bukkit.event.entity.EntityRegainHealthEvent; //導入方法依賴的package包/類
@EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true)
private void onPlayerAutoHeal(EntityRegainHealthEvent event) {
    if (event.getRegainReason() != RegainReason.REGEN &&
            event.getRegainReason() != RegainReason.MAGIC_REGEN &&
            event.getRegainReason() != RegainReason.SATIATED)
        return;

    if (!(event.getEntity() instanceof Player))
        return;

    Player p = (Player)event.getEntity();
    IArenaPlayer player = ArenaPlayer.get(p);
    if (player == null)
        return;

    IArena arena = player.getArena();
    if (arena == null)
        return;

    // get settings
    IContextSettings settings = player.getContextSettings();
    if (settings == null)
        return;

    // prevent auto heal
    if (!settings.isAutoHealEnabled()) {
        event.setCancelled(true);
    }
}
 
開發者ID:JCThePants,項目名稱:PV-Star,代碼行數:30,代碼來源:PlayerEventListener.java

示例15: onEntityRegainHealth

import org.bukkit.event.entity.EntityRegainHealthEvent; //導入方法依賴的package包/類
@EventHandler
public void onEntityRegainHealth(EntityRegainHealthEvent event) {
    if (event.getEntity() instanceof Player) {
        if (event.getRegainReason() == EntityRegainHealthEvent.RegainReason.SATIATED) {
            event.setCancelled(true);
        } else {
            plugin.getActiveCharacter((Player) event.getEntity()).setHealth(((Player) event.getEntity()).getHealth());
        }
    }
}
 
開發者ID:WaywardRealms,項目名稱:Wayward,代碼行數:11,代碼來源:EntityRegainHealthListener.java


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