本文整理汇总了Java中org.bukkit.event.entity.EntityRegainHealthEvent类的典型用法代码示例。如果您正苦于以下问题:Java EntityRegainHealthEvent类的具体用法?Java EntityRegainHealthEvent怎么用?Java EntityRegainHealthEvent使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
EntityRegainHealthEvent类属于org.bukkit.event.entity包,在下文中一共展示了EntityRegainHealthEvent类的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);
}
示例2: call
import org.bukkit.event.entity.EntityRegainHealthEvent; //导入依赖的package包/类
@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();
}
}
}
示例3: updateMonitoredHealth
import org.bukkit.event.entity.EntityRegainHealthEvent; //导入依赖的package包/类
@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());
}
}
示例4: 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());
}
}
}
示例5: onPlayerRegen
import org.bukkit.event.entity.EntityRegainHealthEvent; //导入依赖的package包/类
@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;
}
}
}
示例6: onRegainHealth
import org.bukkit.event.entity.EntityRegainHealthEvent; //导入依赖的package包/类
@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);
}
}
示例7: onHeal
import org.bukkit.event.entity.EntityRegainHealthEvent; //导入依赖的package包/类
@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);
}
}
}
}
}
示例8: 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);
}
}
}
示例9: onHealthRegain
import org.bukkit.event.entity.EntityRegainHealthEvent; //导入依赖的package包/类
@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();
}
}
}
示例10: 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;
}
}
}
示例11: 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);
}
}
}
示例12: 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()));
}
}
}
}
示例13: onHealthRegen
import org.bukkit.event.entity.EntityRegainHealthEvent; //导入依赖的package包/类
@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);
}
}
}
}
}
示例14: heal
import org.bukkit.event.entity.EntityRegainHealthEvent; //导入依赖的package包/类
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;
}
}
示例15: onEntityRegainHealth
import org.bukkit.event.entity.EntityRegainHealthEvent; //导入依赖的package包/类
@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);
}