本文整理匯總了Java中org.bukkit.event.entity.EntityRegainHealthEvent.getRegainReason方法的典型用法代碼示例。如果您正苦於以下問題:Java EntityRegainHealthEvent.getRegainReason方法的具體用法?Java EntityRegainHealthEvent.getRegainReason怎麽用?Java EntityRegainHealthEvent.getRegainReason使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類org.bukkit.event.entity.EntityRegainHealthEvent
的用法示例。
在下文中一共展示了EntityRegainHealthEvent.getRegainReason方法的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: 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());
}
}
}
示例4: 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);
}
}
}
示例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);
}
}
}
示例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()));
}
}
}
}
示例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);
}
示例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);
}
}
}
示例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);
}
示例10: 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);
}
}
示例11: 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);
}
}
示例12: 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);
}
}
示例13: 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());
}
}
}
示例14: onEntityRegainHealth
import org.bukkit.event.entity.EntityRegainHealthEvent; //導入方法依賴的package包/類
@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);
}
}
示例15: onHealthRegain
import org.bukkit.event.entity.EntityRegainHealthEvent; //導入方法依賴的package包/類
@EventHandler
public void onHealthRegain(EntityRegainHealthEvent event) {
if(event.getRegainReason() == EntityRegainHealthEvent.RegainReason.SATIATED) {
event.setCancelled(true);
}
}