Java Code Examples for org.bukkit.event.entity.EntityRegainHealthEvent

The following are top voted examples for showing how to use org.bukkit.event.entity.EntityRegainHealthEvent. These examples are extracted from open source projects. You can vote up the examples you like and your votes will be used in our system to generate more good examples.
Example 1
Project: Warzone   File: RegenModule.java   View source code 7 votes vote down vote up
@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);
}
 
Example 2
Project: Crescent   File: FastHealA.java   View source code 6 votes vote down vote up
@Override
public void call(Event event) {
	if (event instanceof EntityRegainHealthEvent) {
		EntityRegainHealthEvent erhe = (EntityRegainHealthEvent) event;

		if (erhe.getRegainReason() == RegainReason.SATIATED) {
			/*
			 * Player is regenerating health because their hunger is full.
			 */

			final double health = profile.getPlayer().getHealth();

			if (!isAcceptable(health, erhe.getAmount())) {
				callback(true);
			}

			lastTime = System.currentTimeMillis();
		}
	}
}
 
Example 3
Project: Arc-v2   File: FightListener.java   View source code 6 votes vote down vote up
@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());
        }
    }

}
 
Example 4
Project: QuestManager   File: Party.java   View source code 6 votes vote down vote up
@EventHandler
public void onPlayerRegen(EntityRegainHealthEvent e) {
	if (e.isCancelled() || !(e.getEntity() instanceof Player)) {
		return;
	}
	
	Player p = (Player) e.getEntity();
	if (leader.getPlayer().getUniqueId().equals(p.getUniqueId())) {
		updateScoreboard(leader, (int) (p.getHealth() + e.getAmount()));
		return;
	}
	if (!members.isEmpty())
	for (QuestPlayer qp : members) {
		if (qp.getPlayer().getUniqueId().equals(p.getUniqueId())) {
			updateScoreboard(qp, (int) (p.getHealth() + e.getAmount()));
			return;
		}
	}
}
 
Example 5
Project: BedwarsRel   File: EntityListener.java   View source code 6 votes vote down vote up
@EventHandler(priority = EventPriority.HIGH)
public void onRegainHealth(EntityRegainHealthEvent rhe) {
  if (rhe.getEntityType() != EntityType.PLAYER) {
    return;
  }

  Player player = (Player) rhe.getEntity();
  Game game = BedwarsRel.getInstance().getGameManager().getGameOfPlayer(player);

  if (game == null) {
    return;
  }

  if (game.getState() != GameState.RUNNING) {
    return;
  }

  if (player.getHealth() >= player.getMaxHealth()) {
    game.setPlayerDamager(player, null);
  }
}
 
Example 6
Project: Tint-Health   File: PlayerListener.java   View source code 6 votes vote down vote up
@EventHandler(ignoreCancelled = true)
protected void onHeal(EntityRegainHealthEvent e) {
    if (isEnabled()) {
        if (!plugin.fade) {
            if (e.getEntity() instanceof Player) {
                Player p = (Player) e.getEntity();
                if (plugin.functions.isTintEnabled(p)) {
                    Damageable d = (Damageable) p;
                    double heal = e.getAmount();
                    int health = (int) (d.getHealth() + heal);
                    plugin.functions.sendBorder(p, health);
                }
            }
        }
    }
}
 
Example 7
Project: Factoid   File: PlayerListener.java   View source code 6 votes vote down vote up
/**
 * 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);
		}
	}
}
 
Example 8
Project: BukkitLib   File: Utilities.java   View source code 6 votes vote down vote up
@EventHandler(priority = EventPriority.MONITOR, ignoreCancelled = true)
public void onHealthRegain(final EntityRegainHealthEvent event){
	double regainAmountTicker = event.getAmount();
	Deque<DamageData> damagers = getDamageInformationDeque(event.getEntity().getUniqueId());
	while(regainAmountTicker > 0 && damagers.size() > 0){
		DamageData leastRecentDamage = damagers.getLast();
		if(leastRecentDamage.getDamageAmount() > regainAmountTicker){
			// Remove damage attribution from a specific source
			leastRecentDamage.regen += regainAmountTicker;
			regainAmountTicker = 0;
		}else if(Utilities.equals(leastRecentDamage.getDamageAmount(), regainAmountTicker)){
			// Just enough to remove the damage source
			damagers.removeLast();
			regainAmountTicker = 0;
		}else{
			// Damage amount of source is less than regain amount ticker, therefore we remove the last damage source and we decrement the regainer ticker
			regainAmountTicker -= damagers.removeLast().getDamageAmount();
		}
	}
	
}
 
Example 9
Project: TCMinigames   File: PlayerListener.java   View source code 6 votes vote down vote up
@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;
		}
	}
}
 
Example 10
Project: FoodBalance   File: RegenListener.java   View source code 6 votes vote down vote up
@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);
		}
	}
	
}
 
Example 11
Project: NPlugins   File: EnderDragonListener.java   View source code 6 votes vote down vote up
/**
 * 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()));
            }
        }
    }
}
 
Example 12
Project: WeaselsWalls   File: FoodRegen.java   View source code 6 votes vote down vote up
@EventHandler(priority=EventPriority.HIGH)
public void onHealthRegen(EntityRegainHealthEvent 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.getAmount() != 20D){
					e.setAmount(20D);
				}
			}
		}
	}
}
 
Example 13
Project: Craft-city   File: EntityLiving.java   View source code 6 votes vote down vote up
public void heal(int i, EntityRegainHealthEvent.RegainReason regainReason) {
    if (this.health > 0) {
        EntityRegainHealthEvent event = new EntityRegainHealthEvent(this.getBukkitEntity(), i, regainReason);
        this.world.getServer().getPluginManager().callEvent(event);

        if (!event.isCancelled()) {
            this.setHealth(this.getHealth() + event.getAmount());
        }

        // this.getMaxHealth() -> this.maxHealth
        if (this.health > this.maxHealth) {
            this.setHealth(this.maxHealth);
            // CraftBukkit end
        }

        this.noDamageTicks = this.maxNoDamageTicks / 2;
    }
}
 
Example 14
Project: Crescent   File: DetectionListener.java   View source code 5 votes vote down vote up
@EventHandler
public void onEntityRegainHealth(EntityRegainHealthEvent event) {
	if (!(event.getEntity() instanceof Player)) {
		return;
	}

	final Player player = (Player) event.getEntity();

	getCheckVersion(player, CheckType.FASTHEAL, "A").call(event);
}
 
Example 15
Project: ProjectAres   File: ViewInventoryMatchModule.java   View source code 5 votes vote down vote up
@EventHandler(priority = EventPriority.MONITOR, ignoreCancelled = true)
public void updateMonitoredHealth(final EntityRegainHealthEvent event) {
    if(event.getEntity() instanceof Player) {
        Player player = (Player) event.getEntity();
        if(player.getHealth() == player.getMaxHealth()) return;
        this.scheduleCheck((Player) event.getEntity());
    }
}
 
Example 16
Project: SurvivalAPI   File: NaturalListener.java   View source code 5 votes vote down vote up
/**
 * 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);
}
 
Example 17
Project: DynamicAC   File: PlayerListener.java   View source code 5 votes vote down vote up
@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);
        }
    }
}
 
Example 18
Project: BukkitOldCombatMechanics   File: ModulePlayerRegen.java   View source code 5 votes vote down vote up
@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);
}
 
Example 19
Project: Damocles   File: EventCanceller.java   View source code 5 votes vote down vote up
@EventHandler
public void healthRegen(EntityRegainHealthEvent event){
	if(event.getRegainReason().equals(RegainReason.SATIATED)){
		event.setCancelled(true);
	}
	if(event.getRegainReason().equals(RegainReason.REGEN)){
		event.setCancelled(true);
	}
}
 
Example 20
Project: BeeLogin   File: EventCanceler.java   View source code 5 votes vote down vote up
@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);
		}
	}
}
 
Example 21
Project: Lore-Attributes-Reloaded   File: LoreEvents.java   View source code 5 votes vote down vote up
@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);
    }
}
 
Example 22
Project: Janitor   File: Regen.java   View source code 5 votes vote down vote up
@EventHandler(ignoreCancelled=1, priority=EventPriority.MONITOR)
public void onHeal(EntityRegainHealthEvent event) {
    if (!event.getRegainReason().equals((Object)EntityRegainHealthEvent.RegainReason.SATIATED)) {
        return;
    }
    if (!(event.getEntity() instanceof Player)) {
        return;
    }
    Player player = (Player)event.getEntity();
    if (player.getWorld().getDifficulty().equals((Object)Difficulty.PEACEFUL)) {
        return;
    }
    int Count = 0;
    long Time = System.currentTimeMillis();
    if (this.FastHealTicks.containsKey(player.getUniqueId())) {
        Count = this.FastHealTicks.get(player.getUniqueId()).getKey();
        Time = this.FastHealTicks.get(player.getUniqueId()).getValue();
    }
    if (this.checkFastHeal(player)) {
        this.getJanitor().logCheat(this, player, null, new String[0]);
    }
    if (this.FastHealTicks.containsKey(player.getUniqueId()) && UtilTime.elapsed(Time, 60000)) {
        Count = 0;
        Time = UtilTime.nowlong();
    }
    this.LastHeal.put(player.getUniqueId(), System.currentTimeMillis());
    this.FastHealTicks.put(player.getUniqueId(), new AbstractMap.SimpleEntry<Integer, Long>(Count, Time));
}
 
Example 23
Project: Pokkit   File: EntityEvents.java   View source code 5 votes vote down vote up
@EventHandler(ignoreCancelled = false)
public void onEntityRegainHealth(cn.nukkit.event.entity.EntityRegainHealthEvent event) {
	if (canIgnore(PlayerInteractEvent.getHandlerList())) {
		return;
	}

	int reason = event.getRegainReason();
	RegainReason bukkitReason = RegainReason.EATING;

	switch (reason) {
	case cn.nukkit.event.entity.EntityRegainHealthEvent.CAUSE_MAGIC:
		bukkitReason = RegainReason.MAGIC;
		break;
	case cn.nukkit.event.entity.EntityRegainHealthEvent.CAUSE_CUSTOM:
		bukkitReason = RegainReason.CUSTOM;
		break;
	case cn.nukkit.event.entity.EntityRegainHealthEvent.CAUSE_EATING:
		bukkitReason = RegainReason.EATING;
		break;
	case cn.nukkit.event.entity.EntityRegainHealthEvent.CAUSE_REGEN:
		bukkitReason = RegainReason.REGEN;
		break;
	}

	EntityRegainHealthEvent bukkitEvent = new EntityRegainHealthEvent(PokkitEntity.toBukkit(event.getEntity()), event.getAmount(), bukkitReason);

	callCancellable(event, bukkitEvent);
}
 
Example 24
Project: LoreAttributes-reloaded   File: LoreEvents.java   View source code 5 votes vote down vote up
@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);
    }
}
 
Example 25
Project: CraftBukkit   File: EntityLiving.java   View source code 5 votes vote down vote up
public void heal(float f, EntityRegainHealthEvent.RegainReason regainReason) {
    float f1 = this.getHealth();

    if (f1 > 0.0F) {
        EntityRegainHealthEvent event = new EntityRegainHealthEvent(this.getBukkitEntity(), f, regainReason);
        this.world.getServer().getPluginManager().callEvent(event);

        if (!event.isCancelled()) {
            this.setHealth((float) (this.getHealth() + event.getAmount()));
        }
    }
}
 
Example 26
Project: sNoHax   File: Regen.java   View source code 5 votes vote down vote up
@EventHandler
public void onRegen(EntityRegainHealthEvent event) {
    if(event.getEntity() instanceof Player) {
        final Player player = (Player) event.getEntity();
        if(main.getConfig().getBoolean("hacks.regen")) {
            if(!player.hasPermission(Permission.REGEN_BYPASS)) {
                for(PotionEffect effect : player.getActivePotionEffects()) {
                    if(effect.getType() == PotionEffectType.REGENERATION) {return;}
                }
                if(!recentRegen.contains(player.getName())) {
                    recentRegen.add(player.getName());
                    Bukkit.getScheduler().runTaskLater(Main.getPlugin(), new Runnable() {
                        @Override
                        public void run() {
                            recentRegen.remove(player.getName());
                        }
                    }, 40);
                } else {
                    if(counter.get(player.getName()) != null) {
                        counter.put(player.getName(), counter.get(player.getName())+1);
                    } else {
                        counter.put(player.getName(), 1);
                    }
                    if(counter.get(player.getName())==25) {
                        AutoBan.getInstance().autobanPlayer(player, 15, HackType.REGEN);
                    }
                    Alerter.getInstance().alertHack(player, HackType.REGEN, counter.get(player.getName()));
                }
            }
        }
    }
}
 
Example 27
Project: Almura-Server   File: EntityLiving.java   View source code 5 votes vote down vote up
public void heal(float f, EntityRegainHealthEvent.RegainReason regainReason) {
    float f1 = this.getHealth();

    if (f1 > 0.0F) {
        EntityRegainHealthEvent event = new EntityRegainHealthEvent(this.getBukkitEntity(), f, regainReason);
        this.world.getServer().getPluginManager().callEvent(event);

        if (!event.isCancelled()) {
            this.setHealth((float) (this.getHealth() + event.getAmount()));
        }
    }
}
 
Example 28
Project: Almura-Server   File: EntityEnderDragon.java   View source code 5 votes vote down vote up
private void bJ() {
    if (this.bC != null) {
        if (this.bC.dead) {
            if (!this.world.isStatic) {
                this.a(this.bq, DamageSource.explosion((Explosion) null), 10.0F);
            }

            this.bC = null;
        } else if (this.ticksLived % 10 == 0 && this.getHealth() < this.getMaxHealth()) { // CraftBukkit - this.getMaxHealth() -> this.maxHealth
            // CraftBukkit start
            EntityRegainHealthEvent event = new EntityRegainHealthEvent(this.getBukkitEntity(), 1.0D, EntityRegainHealthEvent.RegainReason.ENDER_CRYSTAL);
            this.world.getServer().getPluginManager().callEvent(event);

            if (!event.isCancelled()) {
                this.setHealth((float) (this.getHealth() + event.getAmount()));
            }
            // CraftBukkit end
        }
    }

    if (this.random.nextInt(10) == 0) {
        float f = 32.0F;
        List list = this.world.a(EntityEnderCrystal.class, this.boundingBox.grow((double) f, (double) f, (double) f));
        EntityEnderCrystal entityendercrystal = null;
        double d0 = Double.MAX_VALUE;
        Iterator iterator = list.iterator();

        while (iterator.hasNext()) {
            EntityEnderCrystal entityendercrystal1 = (EntityEnderCrystal) iterator.next();
            double d1 = entityendercrystal1.e(this);

            if (d1 < d0) {
                d0 = d1;
                entityendercrystal = entityendercrystal1;
            }
        }

        this.bC = entityendercrystal;
    }
}
 
Example 29
Project: Tweakkit-Server   File: EntityLiving.java   View source code 5 votes vote down vote up
public void heal(float f, EntityRegainHealthEvent.RegainReason regainReason) {
    float f1 = this.getHealth();

    if (f1 > 0.0F) {
        EntityRegainHealthEvent event = new EntityRegainHealthEvent(this.getBukkitEntity(), f, regainReason);
        this.world.getServer().getPluginManager().callEvent(event);

        if (!event.isCancelled()) {
            this.setHealth((float) (this.getHealth() + event.getAmount()));
        }
    }
}
 
Example 30
Project: HoloAPI   File: IndicatorListener.java   View source code 5 votes vote down vote up
@EventHandler(priority = EventPriority.MONITOR, ignoreCancelled = true)
public void onEntityRegainHealth(EntityRegainHealthEvent event) {
    if (Settings.INDICATOR_ENABLE.getValue("gainHealth")) {
        if ((event.getEntity() instanceof Player && Settings.INDICATOR_SHOW_FOR_PLAYERS.getValue("gainHealth")) || Settings.INDICATOR_SHOW_FOR_MOBS.getValue("gainHealth")) {
            Location l = event.getEntity().getLocation().clone();
            l.setY(l.getY() + Settings.INDICATOR_Y_OFFSET.getValue("gainHealth"));
            HoloAPI.getManager().createSimpleHologram(l, Settings.INDICATOR_TIME_VISIBLE.getValue("gainHealth"), true, Settings.INDICATOR_FORMAT.getValue("gainHealth", "default") + "+" + event.getAmount() + " " + HEART_CHARACTER);
        }
    }
}
 
Example 31
Project: Cauldron   File: EntityLivingBase.java   View source code 5 votes vote down vote up
public void heal(float f, EntityRegainHealthEvent.RegainReason regainReason)
{
    float f1 = this.getHealth();

    if (f1 > 0.0F)
    {
        EntityRegainHealthEvent event = new EntityRegainHealthEvent(this.getBukkitEntity(), f, regainReason);
        this.worldObj.getServer().getPluginManager().callEvent(event);

        if (!event.isCancelled())
        {
            this.setHealth((float)(this.getHealth() + event.getAmount()));
        }
    }
}
 
Example 32
Project: ultrahardcore   File: RegenFeature.java   View source code 5 votes vote down vote up
@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);
    }
}
 
Example 33
Project: PV-Star   File: PlayerEventListener.java   View source code 5 votes vote down vote up
@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);
    }
}
 
Example 34
Project: Wayward   File: EntityRegainHealthListener.java   View source code 5 votes vote down vote up
@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());
        }
    }
}
 
Example 35
Project: CrazyLogin   File: DynamicPlayerListener.java   View source code 5 votes vote down vote up
@EventHandler(ignoreCancelled = true, priority = EventPriority.LOW)
public void PlayerHeal(final EntityRegainHealthEvent event)
{
	if (!(event.getEntity() instanceof Player))
		return;
	final Player player = (Player) event.getEntity();
	if (plugin.isLoggedIn(player))
		return;
	event.setCancelled(true);
}
 
Example 36
Project: SpigotSource   File: EntityLiving.java   View source code 5 votes vote down vote up
public void heal(float f, EntityRegainHealthEvent.RegainReason regainReason) {
    float f1 = this.getHealth();

    if (f1 > 0.0F) {
        EntityRegainHealthEvent event = new EntityRegainHealthEvent(this.getBukkitEntity(), f, regainReason);
        this.world.getServer().getPluginManager().callEvent(event);

        if (!event.isCancelled()) {
            this.setHealth((float) (this.getHealth() + event.getAmount()));
        }
        // CraftBukkit end
    }

}
 
Example 37
Project: SpigotSource   File: EntityEnderDragon.java   View source code 5 votes vote down vote up
private void cW() {
    if (this.currentEnderCrystal != null) {
        if (this.currentEnderCrystal.dead) {
            this.currentEnderCrystal = null;
        } else if (this.ticksLived % 10 == 0 && this.getHealth() < this.getMaxHealth()) {
            // CraftBukkit start
            EntityRegainHealthEvent event = new EntityRegainHealthEvent(this.getBukkitEntity(), 1.0F, EntityRegainHealthEvent.RegainReason.ENDER_CRYSTAL);
            this.world.getServer().getPluginManager().callEvent(event);

            if (!event.isCancelled()) {
                this.setHealth((float) (this.getHealth() + event.getAmount()));
            }
            // CraftBukkit end
        }
    }

    if (this.random.nextInt(10) == 0) {
        List list = this.world.a(EntityEnderCrystal.class, this.getBoundingBox().g(32.0D));
        EntityEnderCrystal entityendercrystal = null;
        double d0 = Double.MAX_VALUE;
        Iterator iterator = list.iterator();

        while (iterator.hasNext()) {
            EntityEnderCrystal entityendercrystal1 = (EntityEnderCrystal) iterator.next();
            double d1 = entityendercrystal1.h(this);

            if (d1 < d0) {
                d0 = d1;
                entityendercrystal = entityendercrystal1;
            }
        }

        this.currentEnderCrystal = entityendercrystal;
    }

}
 
Example 38
Project: KTP   File: UHPluginListener.java   View source code 5 votes vote down vote up
@EventHandler
public void onEntityRegainHealth(final EntityRegainHealthEvent ev) {
	if (ev.getRegainReason() == RegainReason.SATIATED) ev.setCancelled(true);
	if (ev.getEntity() instanceof Player) {
		Bukkit.getScheduler().runTaskLater(this.p, new BukkitRunnable() {
			
			@Override
			public void run() {
				p.updatePlayerListName((Player)ev.getEntity());
			}
		}, 1L);
	}
}
 
Example 39
Project: Bits   File: ConfigurationManager.java   View source code 5 votes vote down vote up
private static HashMap<String, Class> getEventClassAssociations()
	{
		HashMap<String, Class> classHashMap = new HashMap<String, Class>();
		classHashMap.put("block-break", BlockBreakEvent.class);
		classHashMap.put("block-place", BlockPlaceEvent.class);

//		classHashMap.put("entity-leash", PlayerLeashEntityEvent.class);
		classHashMap.put("entity-kill", EntityDeathEvent.class);
		classHashMap.put("entity-shear", PlayerShearEntityEvent.class);

		classHashMap.put("item-brew", BrewEvent.class);
		classHashMap.put("item-enchant", EnchantItemEvent.class);
		classHashMap.put("item-furnace", FurnaceExtractEvent.class);

		classHashMap.put("painting-create", HangingPlaceEvent.class);

		classHashMap.put("player-regenerate", EntityRegainHealthEvent.class);
		classHashMap.put("player-shoot", EntityShootBowEvent.class);
		classHashMap.put("player-chat", AsyncPlayerChatEvent.class);
		classHashMap.put("player-death", PlayerDeathEvent.class);
		classHashMap.put("player-sleep", PlayerBedEnterEvent.class);
		classHashMap.put("player-author", PlayerEditBookEvent.class);
		classHashMap.put("player-egg", PlayerEggThrowEvent.class);
		classHashMap.put("player-fish", PlayerFishEvent.class);
		classHashMap.put("player-eat", PlayerItemConsumeEvent.class);
		classHashMap.put("player-join", PlayerJoinEvent.class);
		classHashMap.put("player-move", PlayerMoveEvent.class);

		classHashMap.put("portal-create", PortalCreateEvent.class);

		classHashMap.put("vehicle-move", VehicleMoveEvent.class);

		classHashMap.put("world-change", PlayerChangedWorldEvent.class);

		return classHashMap;
	}
 
Example 40
Project: SpectatorPlus   File: GuiUpdatesListener.java   View source code 5 votes vote down vote up
@EventHandler (priority = EventPriority.MONITOR, ignoreCancelled = true)
public void onPlayerRegainHealth(EntityRegainHealthEvent ev)
{
	if (ev.getEntity() instanceof Player)
	{
		updatePlayerInventoryGUI();
	}
}