本文整理汇总了Java中org.bukkit.event.entity.EntityDamageEvent.getCause方法的典型用法代码示例。如果您正苦于以下问题:Java EntityDamageEvent.getCause方法的具体用法?Java EntityDamageEvent.getCause怎么用?Java EntityDamageEvent.getCause使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.bukkit.event.entity.EntityDamageEvent
的用法示例。
在下文中一共展示了EntityDamageEvent.getCause方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: onDamageWhenPlayerNotLoaded
import org.bukkit.event.entity.EntityDamageEvent; //导入方法依赖的package包/类
@EventHandler(ignoreCancelled = true, priority = EventPriority.LOW)
public void onDamageWhenPlayerNotLoaded(EntityDamageEvent event) {
if (event.getEntityType() != EntityType.PLAYER) {
return;
}
Player player = (Player) event.getEntity();
if (InventoryManager.playerIsLoaded(player)) {
return;
}
if (event.getCause() == EntityDamageEvent.DamageCause.FALL) {
PlayerLoader.setDamageForPlayer(player, event.getFinalDamage());
}
event.setCancelled(true);
}
示例2: call
import org.bukkit.event.entity.EntityDamageEvent; //导入方法依赖的package包/类
@Override
public void call(Event event) {
if (event instanceof EntityDamageEvent) {
final EntityDamageEvent ede = (EntityDamageEvent) event;
final DamageCause cause = ede.getCause();
if (cause == DamageCause.FIRE || cause == DamageCause.CONTACT) {
final Player player = profile.getPlayer();
if (cause == DamageCause.FIRE && player.getFoodLevel() < 20) {
// The AntiFire cheat only works when the hunger bar is
// full.
return;
}
final double previousHealth = player.getHealth();
// Check a little later.
Bukkit.getScheduler().runTaskLater(Crescent.getInstance(), () -> {
if (player.getHealth() > previousHealth - ede.getDamage()) {
callback(true);
}
}, 2L);
}
}
}
示例3: onEntityDamage
import org.bukkit.event.entity.EntityDamageEvent; //导入方法依赖的package包/类
@EventHandler
public void onEntityDamage(EntityDamageEvent event)
{
event.setCancelled(true);
if (event.getEntity().getType() != EntityType.PLAYER)
return;
if (event.getCause() == EntityDamageEvent.DamageCause.VOID)
{
if (this.hub.getParkourManager().getPlayerParkour(event.getEntity().getUniqueId()) != null)
this.hub.getParkourManager().getPlayerParkour(event.getEntity().getUniqueId()).failPlayer((Player) event.getEntity());
else
event.getEntity().teleport(this.hub.getPlayerManager().getSpawn());
}
}
示例4: resolve
import org.bukkit.event.entity.EntityDamageEvent; //导入方法依赖的package包/类
public @Nonnull
DamageInfo resolve(@Nonnull LivingEntity entity, @Nonnull Lifetime lifetime, @Nonnull EntityDamageEvent damageEvent) {
DamageInfo info = null;
for(ResolverEntry entry : this.resolvers) {
DamageInfo resolvedInfo = entry.resolver.resolve(entity, lifetime, damageEvent);
if(resolvedInfo != null) {
info = resolvedInfo;
}
}
if(info == null) {
info = new BukkitDamageInfo(damageEvent.getCause());
}
return info;
}
示例5: onPlayerDamage
import org.bukkit.event.entity.EntityDamageEvent; //导入方法依赖的package包/类
@EventHandler(ignoreCancelled = true, priority = EventPriority.HIGH)
public void onPlayerDamage(EntityDamageEvent event) {
if (event.getCause() == EntityDamageEvent.DamageCause.VOID) {
Entity entity = event.getEntity();
if (entity instanceof Player) {
// Allow players to die by VOID in the END
if (entity.getWorld().getEnvironment() == World.Environment.THE_END) {
return;
}
Location destination = BukkitUtils.getHighestLocation(entity.getLocation());
if (destination == null)
return;
if (entity.teleport(destination, PlayerTeleportEvent.TeleportCause.PLUGIN)) {
event.setCancelled(true);
((Player) entity).sendMessage(ChatColor.YELLOW + "You were saved from the void.");
}
}
}
}
示例6: resolve
import org.bukkit.event.entity.EntityDamageEvent; //导入方法依赖的package包/类
public @Nullable
DamageInfo resolve(@Nonnull LivingEntity entity, @Nonnull Lifetime lifetime, @Nonnull EntityDamageEvent damageEvent) {
if(damageEvent instanceof EntityDamageByEntityEvent && damageEvent.getCause() == DamageCause.ENTITY_ATTACK) {
EntityDamageByEntityEvent entityEvent = (EntityDamageByEntityEvent) damageEvent;
if(entityEvent.getDamager() instanceof LivingEntity) {
LivingEntity attacker = (LivingEntity) entityEvent.getDamager();
Material weaponMaterial;
ItemStack held = attacker.getEquipment().getItemInMainHand();
if(held != null) {
weaponMaterial = held.getType();
} else {
weaponMaterial = Material.AIR;
}
return new SimpleMeleeDamageInfo(attacker, weaponMaterial);
}
}
return null;
}
示例7: onEntityDamage
import org.bukkit.event.entity.EntityDamageEvent; //导入方法依赖的package包/类
@EventHandler
public void onEntityDamage(EntityDamageEvent event) {
if(event.getCause() == EntityDamageEvent.DamageCause.CUSTOM) return;
if(Arcadia.getPlugin(Arcadia.class).getAPI().getGameManager().getGameState() != GameState.INGAME) {
event.setCancelled(true);
} else {
if(!Arcadia.getPlugin(Arcadia.class).getAPI().getGameManager().getCurrentGame().allowPVP) event.setCancelled(true);
}
if(!event.isCancelled() && event.getEntity() instanceof Player) {
Player player = (Player) event.getEntity();
if((player.getHealth()-event.getDamage()) <= 0) {
event.setDamage(0);
if(Arcadia.getPlugin(Arcadia.class).getAPI().getGameManager().isAlive(player)) {
Arcadia.getPlugin(Arcadia.class).getAPI().getGameManager().setAlive(player, false);
}
}
}
}
示例8: onEvent
import org.bukkit.event.entity.EntityDamageEvent; //导入方法依赖的package包/类
void onEvent(EntityDamageEvent event) {
if(event.getEntity() == player.getBukkit()) {
// Player took damage
mutateStamina(options.mutators.injury);
} else if(event.getCause() == EntityDamageEvent.DamageCause.ENTITY_ATTACK &&
event instanceof EntityDamageByEntityEvent &&
((EntityDamageByEntityEvent) event).getDamager() == player.getBukkit()) {
// Player is damager and attack is melee
swinging = false;
for(StaminaSymptom symptom : getActiveSymptoms()) {
symptom.onAttack(event);
}
mutateStamina(options.mutators.meleeHit);
}
}
示例9: onPlayerDamage
import org.bukkit.event.entity.EntityDamageEvent; //导入方法依赖的package包/类
@EventHandler
public void onPlayerDamage(EntityDamageEvent event) {
if (!(event.getEntity() instanceof Player))
return;
event.setCancelled(true);
if (event.getCause()==DamageCause.VOID) {
Location l = event.getEntity().getWorld().getSpawnLocation();
l.setX(14.5);
l.setY(10.5);
l.setZ(-795.5);
l.setPitch(0.5F);
l.setYaw(90 * RandomUtil.between(1, 4));
event.getEntity().teleport(l);
}
}
示例10: onDamage
import org.bukkit.event.entity.EntityDamageEvent; //导入方法依赖的package包/类
@EventHandler(priority = EventPriority.LOWEST)
public void onDamage(EntityDamageEvent evt) { // Teleport a player out if they lose.
if (evt.getCause() == EntityDamageEvent.DamageCause.LAVA && evt.getEntity() instanceof Player) {
evt.getEntity().playEffect(EntityEffect.HURT);
removePlayer((Player) evt.getEntity());
Bukkit.getScheduler().runTask(Core.getInstance(), () -> evt.getEntity().setFireTicks(0)); // Must run a tick late.
}
}
示例11: resolve
import org.bukkit.event.entity.EntityDamageEvent; //导入方法依赖的package包/类
public @Nullable
DamageInfo resolve(@Nonnull LivingEntity entity, @Nonnull Lifetime lifetime, @Nonnull EntityDamageEvent damageEvent) {
if(damageEvent.getCause() == DamageCause.LAVA) {
return new SimpleLavaDamageInfo(null);
}
return null;
}
示例12: resolve
import org.bukkit.event.entity.EntityDamageEvent; //导入方法依赖的package包/类
public @Nullable
DamageInfo resolve(@Nonnull LivingEntity entity, @Nonnull Lifetime lifetime, @Nonnull EntityDamageEvent damageEvent) {
if(damageEvent.getCause() == DamageCause.FALL) {
float fallDistance = Math.max(0, entity.getFallDistance());
return new SimpleFallDamageInfo(null, fallDistance);
}
return null;
}
示例13: onEntityDamage
import org.bukkit.event.entity.EntityDamageEvent; //导入方法依赖的package包/类
@EventHandler
public void onEntityDamage(EntityDamageEvent event) {
if (event.getEntity() instanceof Player) {
Gamer g = Gamer.get((Player) event.getEntity());
if (g.getVariable("spectator") != null)
return;
Kit kit = (Kit) g.getVariable("kit");
if (kit.getName().equals("scout") && event.getCause() == DamageCause.FALL) {
event.setDamage(0);
}
}
}
示例14: onEntityDamageEvent
import org.bukkit.event.entity.EntityDamageEvent; //导入方法依赖的package包/类
@EventHandler
public void onEntityDamageEvent(EntityDamageEvent event) {
if (event.getCause() == DamageCause.VOID && event.getEntity() instanceof Player) {
if (lastVoid.containsKey(((Player) event.getEntity()).getName()) && System.currentTimeMillis() - lastVoid.get(((Player) event.getEntity()).getName()) < 5000)
return;
((Player) event.getEntity()).sendMessage(ChatColor.RED + "Woah! Careful there, pal!");
event.getEntity().setFallDistance(0);
event.getEntity().teleport(event.getEntity().getWorld().getSpawnLocation());
event.getEntity().setFallDistance(0);
} else if (event.getCause() == DamageCause.VOID && MobManager.spawnedMobs.get(event.getEntity().getUniqueId()) != null) {
MobData md = MobManager.spawnedMobs.get(event.getEntity().getUniqueId());
event.getEntity().teleport(md.ai.originalLoc);
}
}
示例15: onEntityDamage
import org.bukkit.event.entity.EntityDamageEvent; //导入方法依赖的package包/类
/**
* Set Potion Effect SLOWNESS I when player takes fall damage
* @param event Entity Damage Event
*/
@EventHandler
public void onEntityDamage(EntityDamageEvent event)
{
if (event.getEntity() instanceof Player && event.getCause() == EntityDamageEvent.DamageCause.FALL && !event.isCancelled())
((Player) event.getEntity()).addPotionEffect(PotionEffectType.SLOW.createEffect((int) this.moduleConfiguration.get("penalty-time") * 20, 1));
}