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: Crescent   File: FastHealA.java   Source Code and License 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 2
Project: ProjectAres   File: ViewInventoryMatchModule.java   Source Code and License 6 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 3
Project: Arc-v2   File: FightListener.java   Source Code and License 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   Source Code and License 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   Source Code and License 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   Source Code and License 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   Source Code and License 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   Source Code and License 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   Source Code and License 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   Source Code and License 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   Source Code and License 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   Source Code and License 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   Source Code and License 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   Source Code and License 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: SurvivalAPI   File: NaturalListener.java   Source Code and License 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 16
Project: DynamicAC   File: PlayerListener.java   Source Code and License 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 17
Project: BukkitOldCombatMechanics   File: ModulePlayerRegen.java   Source Code and License 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 18
Project: Damocles   File: EventCanceller.java   Source Code and License 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 19
Project: BeeLogin   File: EventCanceler.java   Source Code and License 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 20
Project: Lore-Attributes-Reloaded   File: LoreEvents.java   Source Code and License 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 21
Project: Janitor   File: Regen.java   Source Code and License 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 22
Project: Pokkit   File: EntityEvents.java   Source Code and License 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 23
Project: LoreAttributes-reloaded   File: LoreEvents.java   Source Code and License 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 24
Project: CraftBukkit   File: EntityLiving.java   Source Code and License 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 25
Project: sNoHax   File: Regen.java   Source Code and License 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 26
Project: Almura-Server   File: EntityLiving.java   Source Code and License 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 27
Project: Almura-Server   File: EntityEnderDragon.java   Source Code and License 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 28
Project: Tweakkit-Server   File: EntityLiving.java   Source Code and License 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 29
Project: HoloAPI   File: IndicatorListener.java   Source Code and License 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 30
Project: Cauldron   File: EntityLivingBase.java   Source Code and License 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 31
Project: ultrahardcore   File: RegenFeature.java   Source Code and License 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 32
Project: PV-Star   File: PlayerEventListener.java   Source Code and License 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 33
Project: Wayward   File: EntityRegainHealthListener.java   Source Code and License 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 34
Project: CrazyLogin   File: DynamicPlayerListener.java   Source Code and License 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 35
Project: SpigotSource   File: EntityLiving.java   Source Code and License 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 36
Project: SpigotSource   File: EntityEnderDragon.java   Source Code and License 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 37
Project: KTP   File: UHPluginListener.java   Source Code and License 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 38
Project: Bits   File: ConfigurationManager.java   Source Code and License 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 39
Project: SpectatorPlus   File: GuiUpdatesListener.java   Source Code and License 5 votes vote down vote up
@EventHandler (priority = EventPriority.MONITOR, ignoreCancelled = true)
public void onPlayerRegainHealth(EntityRegainHealthEvent ev)
{
	if (ev.getEntity() instanceof Player)
	{
		updatePlayerInventoryGUI();
	}
}
 
Example 40
Project: Romball   File: SnowballListener.java   Source Code and License 5 votes vote down vote up
@EventHandler
public void onPlayerRegen(EntityRegainHealthEvent e) {
	if (e.getEntity() instanceof Player) {
		Player p = (Player) e.getEntity();
		if (ArenaManager.getInstance().getArena(p) == null) return;
		e.setAmount(0.0);
		e.setCancelled(true);
	}
}
 
Example 41
Project: AuthMeReloaded   File: EntityListener.java   Source Code and License 5 votes vote down vote up
@EventHandler(ignoreCancelled = true, priority = EventPriority.LOWEST)
public void entityRegainHealthEvent(EntityRegainHealthEvent event) {
    if (listenerService.shouldCancelEvent(event)) {
        event.setAmount(0);
        event.setCancelled(true);
    }
}
 
Example 42
Project: AuthMeReloaded   File: EntityListenerTest.java   Source Code and License 5 votes vote down vote up
@Test
public void shouldCancelRegainHealthEvent() {
    // given
    EntityRegainHealthEvent event = mock(EntityRegainHealthEvent.class);
    given(listenerService.shouldCancelEvent(event)).willReturn(true);

    // when
    listener.entityRegainHealthEvent(event);

    // then
    verify(listenerService).shouldCancelEvent(event);
    verify(event).setCancelled(true);
    verify(event).setAmount(0);
}
 
Example 43
Project: AuthMeReloaded   File: EntityListenerTest.java   Source Code and License 5 votes vote down vote up
@Test
public void shouldNotCancelRegainedHealth() {
    // given
    EntityRegainHealthEvent event = mock(EntityRegainHealthEvent.class);
    given(listenerService.shouldCancelEvent(event)).willReturn(false);

    // when
    listener.entityRegainHealthEvent(event);

    // then
    verify(listenerService).shouldCancelEvent(event);
    verifyZeroInteractions(event);
}
 
Example 44
Project: Craft-city   File: EntityEnderDragon.java   Source Code and License 5 votes vote down vote up
private void h() {
    if (this.bS != null) {
        if (this.bS.dead) {
            if (!this.world.isStatic) {
                this.a(this.g, DamageSource.explosion((Explosion) null), 10);
            }

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

            if (!event.isCancelled()) {
                this.setHealth(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.bS = entityendercrystal;
    }
}
 
Example 45
Project: SwornRPG   File: EntityListener.java   Source Code and License 5 votes vote down vote up
@EventHandler(priority = EventPriority.MONITOR)
public void onEntityRegainHealth(EntityRegainHealthEvent event)
{
	if (event.isCancelled() || event.getAmount() <= 0.0D)
		return;

	Entity entity = event.getEntity();
	if (entity instanceof LivingEntity)
	{
		plugin.getHealthBarHandler().updateHealth((LivingEntity) entity);
	}
}
 
Example 46
Project: pogoball   File: SnowballListeners.java   Source Code and License 5 votes vote down vote up
@EventHandler
public void onPlayerRegen(EntityRegainHealthEvent e) {
	if (e.getEntity() instanceof Player) {
		Player p = (Player) e.getEntity();
		if (ArenaManager.getInstance().getArena(p) == null) return;
		e.setAmount(0.0);
		e.setCancelled(true);
	}
}
 
Example 47
Project: RoyalSurvivors   File: UHCListener.java   Source Code and License 5 votes vote down vote up
@EventHandler
public void onRegen(EntityRegainHealthEvent e) {
    if (!Config.uhcRegenOff || !(e.getEntity() instanceof Player)) return;
    final Player p = (Player) e.getEntity();
    if (!RUtils.isInInfectedWorld(p)) return;
    e.setCancelled(true);
}
 
Example 48
Project: ZentrelaRPG   File: EnvironmentManager.java   Source Code and License 4 votes vote down vote up
@EventHandler
public void onRegainHealth(EntityRegainHealthEvent event) {
    event.setCancelled(true);
}
 
Example 49
Project: Arcadia-Spigot   File: PotionDropGame.java   Source Code and License 4 votes vote down vote up
@EventHandler
public void onHealthRegain(EntityRegainHealthEvent event) {
    if(event.getRegainReason() == EntityRegainHealthEvent.RegainReason.SATIATED) {
        event.setCancelled(true);
    }
}
 
Example 50
Project: Absorption   File: PlayerListener.java   Source Code and License 4 votes vote down vote up
@EventHandler
public void onEntityRegainHealth(EntityRegainHealthEvent e) {
	e.setCancelled(true);
}
 
Example 51
Project: McPlayUHC   File: EntityRegainHealthListener.java   Source Code and License 4 votes vote down vote up
@EventHandler
public void EntityRegainHealthListener(EntityRegainHealthEvent e) {
	if (e.getRegainReason() == RegainReason.EATING) {
		e.setCancelled(true);
	}
}
 
Example 52
Project: GamePlate   File: InventoryViewModule.java   Source Code and License 4 votes vote down vote up
@EventHandler
public void onViewingEntityRegainHealth(EntityRegainHealthEvent event) {
    if (event.getEntity() instanceof Player) {
        refreshView(event.getEntity().getUniqueId());
    }
}
 
Example 53
Project: Arcade2   File: ObserverListeners.java   Source Code and License 4 votes vote down vote up
@EventHandler(priority = EventPriority.LOW, ignoreCancelled = true)
public void onEntityRegainHealth(EntityRegainHealthEvent event) {
    if (this.isObserving(event.getEntity())) {
        event.setCancelled(true);
    }
}
 
Example 54
Project: QuestManager   File: InnAction.java   Source Code and License 4 votes vote down vote up
@Override
public void onAction() {
	
	//check their money
	if (player.getMoney() >= cost) {
		//they have enough money
		
		//blindness for 3 seconds, title saying you're now rested?
		//don't forget to restore health, hunger
		//and take out some money
		
		if (!player.getPlayer().isOnline()) {
			System.out.println("Very bad InnAction error!!!!!!!!!!!!!");
			return;
		}
		
		player.addMoney(-cost);
		
		Player p = player.getPlayer().getPlayer();
		double amount = p.getMaxHealth() - p.getHealth();
		EntityRegainHealthEvent e = new EntityRegainHealthEvent(p, amount, RegainReason.CUSTOM);
		Bukkit.getPluginManager().callEvent(e);
		if (!e.isCancelled()) {
			p.setHealth(p.getMaxHealth());
		}
		
		player.regenMP(-100);
		
		p.setFoodLevel(20);
		p.setExhaustion(0f);
		p.setSaturation(20f);
		
		p.addPotionEffect(
				new PotionEffect(PotionEffectType.BLINDNESS, 60, 5));


		new TitleObject(ChatColor.GREEN + "Sweet Dreams" + ChatColor.RESET,
				ChatColor.BLUE + "Health and hunger have been restored")
				.setFadeIn(20).setFadeOut(20).setStay(40).send(p);
        
        p.playSound(p.getLocation(), Sound.ENTITY_PLAYER_LEVELUP, 1, .5f);
		
	} else {
		//not enough money
		//show them a menu, sorrow
					
		ChatMenu menu = new SimpleChatMenu(denial.getFormattedMessage());
		
		menu.show(player.getPlayer().getPlayer());
	}
	
}
 
Example 55
Project: CraftBukkit   File: EntityLiving.java   Source Code and License 4 votes vote down vote up
public void heal(float f) {
    heal(f, EntityRegainHealthEvent.RegainReason.CUSTOM);
}
 
Example 56
Project: CraftBukkit   File: EntityEnderDragon.java   Source Code and License 4 votes vote down vote up
private void bP() {
    if (this.bC != null) {
        if (this.bC.dead) {
            if (!this.world.isStatic) {
                CraftEventFactory.entityDamage = this.bC; // CraftBukkit
                this.a(this.bq, DamageSource.explosion((Explosion) null), 10.0F);
                CraftEventFactory.entityDamage = null; // CraftBukkit
            }

            this.bC = null;
        } else if (this.ticksLived % 10 == 0 && this.getHealth() < this.getMaxHealth()) {
            // 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.f(this);

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

        this.bC = entityendercrystal;
    }
}
 
Example 57
Project: Almura-Server   File: EntityLiving.java   Source Code and License 4 votes vote down vote up
public void heal(float f) {
    heal(f, EntityRegainHealthEvent.RegainReason.CUSTOM);
}
 
Example 58
Project: Tweakkit-Server   File: EntityLiving.java   Source Code and License 4 votes vote down vote up
public void heal(float f) {
    heal(f, EntityRegainHealthEvent.RegainReason.CUSTOM);
}
 
Example 59
Project: Tweakkit-Server   File: EntityEnderDragon.java   Source Code and License 4 votes vote down vote up
private void bP() {
    if (this.bC != null) {
        if (this.bC.dead) {
            if (!this.world.isStatic) {
                CraftEventFactory.entityDamage = this.bC; // CraftBukkit
                this.a(this.bq, DamageSource.explosion((Explosion) null), 10.0F);
                CraftEventFactory.entityDamage = null; // CraftBukkit
            }

            this.bC = null;
        } else if (this.ticksLived % 10 == 0 && this.getHealth() < this.getMaxHealth()) {
            // 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.f(this);

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

        this.bC = entityendercrystal;
    }
}
 
Example 60
Project: Cauldron   File: EntityLivingBase.java   Source Code and License 4 votes vote down vote up
public void heal(float p_70691_1_)
{
    heal(p_70691_1_, EntityRegainHealthEvent.RegainReason.CUSTOM);
}