本文整理汇总了Java中org.bukkit.event.entity.EntityDamageEvent类的典型用法代码示例。如果您正苦于以下问题:Java EntityDamageEvent类的具体用法?Java EntityDamageEvent怎么用?Java EntityDamageEvent使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
EntityDamageEvent类属于org.bukkit.event.entity包,在下文中一共展示了EntityDamageEvent类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: 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);
}
}
}
示例2: onDamage
import org.bukkit.event.entity.EntityDamageEvent; //导入依赖的package包/类
@EventHandler
public void onDamage(EntityDamageEvent e){
if(!(e.getEntity() instanceof Player)) return;
Player p = (Player) e.getEntity();
if (plugin.getGm().isInLobby()) e.setCancelled(true);
switch (e.getCause()) {
case LAVA:
e.setCancelled(true);
p.teleport(plugin.getAm().getRandomSpawn());
//RageGames.getPlayer(p).resetPlayer();
p.setHealth(20d);
p.setFireTicks(0);
break;
case FALL:
e.setCancelled(true);
break;
}
}
示例3: damage
import org.bukkit.event.entity.EntityDamageEvent; //导入依赖的package包/类
@Override
public void damage(double amount)
{
Map<DamageModifier, Double> modifiers = new EnumMap<>(DamageModifier.class);
modifiers.put(DamageModifier.BASE, 1.0);
Map<DamageModifier, Function<Double, Double>> modifierFunctions = new EnumMap<>(DamageModifier.class);
modifierFunctions.put(DamageModifier.BASE, damage -> damage);
EntityDamageEvent event = new EntityDamageEvent(this, DamageCause.CUSTOM, modifiers, modifierFunctions);
event.setDamage(amount);
Bukkit.getPluginManager().callEvent(event);
if (!event.isCancelled())
{
setHealth(health - amount);
}
}
示例4: inflictDamage
import org.bukkit.event.entity.EntityDamageEvent; //导入依赖的package包/类
/**
* Inflicts the given damage on an entity.
*
* This method will call the appropriate damage method and fire an {@link EntityDamageEvent}.
*
* @param entity Entity to inflict damage upon
* @param damage Amount of half-hearts of damage to inflict
* @param info {@link DamageInfo} object that details the type of damage
* @return the final {@link Damage} object (never null)
*
* @throws NullPointerException if entity or info is null
* throws IllegalArgumentExcpetion if hearts is less than zero
*/
public static @Nonnull
Damage inflictDamage(@Nonnull LivingEntity entity, int damage, @Nonnull DamageInfo info) {
Preconditions.checkNotNull(entity, "living entity");
Preconditions.checkArgument(damage >= 0, "damage must be greater than or equal to zero");
Preconditions.checkNotNull(info, "damage info");
DamageAPIHelper helper = DamageAPIHelper.get();
EntityDamageEvent event = new EntityDamageEvent(entity, DamageCause.CUSTOM, damage);
helper.setEventDamageInfo(event, info);
Bukkit.getPluginManager().callEvent(event);
if(event.isCancelled()) {
return null;
}
entity.damage(event.getDamage());
helper.setEventDamageInfo(event, null);
return helper.getOurEvent(event).toDamageObject();
}
示例5: getCausingFall
import org.bukkit.event.entity.EntityDamageEvent; //导入依赖的package包/类
/**
* Get the Fall that caused the given damage to the given player,
* or null if the damage was not caused by a Fall.
*/
public Fall getCausingFall(Player victim, EntityDamageEvent.DamageCause damageCause) {
Fall fall = this.falls.get(victim);
if (fall == null || !fall.isFalling) {
return null;
}
// Do an extra check to see if the fall should be cancelled
this.checkFallCancelled(fall);
if (!this.falls.containsKey(victim)) {
return null;
}
switch (damageCause) {
case VOID:
case FALL:
case LAVA:
case SUICIDE:
return fall;
case FIRE_TICK:
return fall.isInLava ? fall : null;
default:
return null;
}
}
示例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) {
EntityDamageByEntityEvent event = (EntityDamageByEntityEvent) damageEvent;
if(event.getDamager() instanceof Projectile) {
Projectile projectile = (Projectile) event.getDamager();
Location launchLocation = this.projectileDistanceTracker.getLaunchLocation(projectile);
Double projectileDistance = null;
if(launchLocation != null) projectileDistance = event.getEntity().getLocation().distance(launchLocation);
if(projectile.getShooter() instanceof LivingEntity) {
return new ProjectileDamageInfo(projectile, (LivingEntity) projectile.getShooter(), projectileDistance);
}
}
}
return null;
}
示例7: 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) {
EntityDamageByEntityEvent event = (EntityDamageByEntityEvent) damageEvent;
if(event.getDamager() instanceof Projectile) {
Projectile projectile = (Projectile) event.getDamager();
Location launchLocation = this.projectileDistanceTracker.getLaunchLocation(projectile);
Double projectileDistance = null;
OfflinePlayer dispenserOwner = dispenserTracker.getOwner(projectile);
if(launchLocation != null) projectileDistance = event.getEntity().getLocation().distance(launchLocation);
if(projectile.getShooter() instanceof LivingEntity) {
return new DispensedProjectileDamageInfo(projectile, (LivingEntity) projectile.getShooter(), projectileDistance, dispenserOwner);
}
}
}
return null;
}
示例8: resolve
import org.bukkit.event.entity.EntityDamageEvent; //导入依赖的package包/类
public DamageInfo resolve(LivingEntity entity, Lifetime lifetime, EntityDamageEvent damageEvent) {
if(damageEvent instanceof EntityDamageByEntityEvent) {
EntityDamageByEntityEvent event = (EntityDamageByEntityEvent) damageEvent;
if(event.getDamager() instanceof FallingBlock) {
FallingBlock anvil = (FallingBlock) event.getDamager();
OfflinePlayer offlineOwner = this.anvilTracker.getOwner(anvil);
Player onlineOwner = null;
if(offlineOwner != null) onlineOwner = offlineOwner.getPlayer();
return new AnvilDamageInfo(anvil, onlineOwner, offlineOwner);
}
}
return null;
}
示例9: onPlayerDamage
import org.bukkit.event.entity.EntityDamageEvent; //导入依赖的package包/类
@EventHandler(ignoreCancelled = true) // Prevent players from being damaged in the party world unless in a game.
public void onPlayerDamage(EntityDamageEvent evt) {
if (!isParty(evt.getEntity()))
return;
if (!(evt.getEntity() instanceof LivingEntity))
evt.setCancelled(true); // Default to no damage, if the entity isn't alive.
if (!(evt.getEntity() instanceof Player))
return; // If the damaged isn't a player, ignore this next bit that may uncancel it.
Player p = (Player) evt.getEntity();
evt.setCancelled(!checkParty(p, PartyGame::allowDamage));
if (evt instanceof EntityDamageByEntityEvent) { // Handle combat differently.
EntityDamageByEntityEvent dmg = (EntityDamageByEntityEvent) evt;
boolean isMob = evt.getEntity() instanceof Creature;
boolean isPlayer = dmg.getEntity() instanceof Player && dmg.getDamager() instanceof Player;
evt.setCancelled((!checkParty(p, PartyGame::allowMobCombat) && isMob) || (!checkParty(p, PartyGame::allowPlayerCombat) && isPlayer));
}
}
示例10: onHit
import org.bukkit.event.entity.EntityDamageEvent; //导入依赖的package包/类
@EventHandler(priority = EventPriority.HIGHEST)
public void onHit(EntityDamageEvent event)
{
if(event.isCancelled()) return;
Entity hitTarget = event.getEntity();
if(hitTarget != null && hitTarget instanceof ArmorStand && hitTarget.getCustomName() == "Chair")
// Chair entity is immune to damage.
event.setCancelled(true);
else if(hitTarget != null && hitTarget instanceof Player && hitTarget.getVehicle() != null)
{
// Let players stand up if receiving damage.
Entity vehicle = hitTarget.getVehicle();
if(vehicle != null && vehicle instanceof ArmorStand && vehicle.getCustomName() == "Chair")
vehicle.remove();
}
}
示例11: 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);
}
}
}
}
示例12: 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);
}
}
示例13: onDeath
import org.bukkit.event.entity.EntityDamageEvent; //导入依赖的package包/类
@EventHandler
public void onDeath(PlayerDeathEvent e) {
Player pl = e.getEntity();
Player p = e.getEntity().getKiller();
if (pl.getLastDamageCause().getCause() == EntityDamageEvent.DamageCause.ENTITY_EXPLOSION) {
//Para los logros
}
death = true;
plugin.getServer().getScheduler().runTaskLater(plugin, () -> death = false, 20 * 5);
if (manager.isInPvP(p)) {
manager.removeCooldown(p);
manager.removeCooldown(pl);
p.sendMessage(Utils.colorize(PAData.SURVIVAL.getPrefix() + ChatColor.DARK_GREEN + " Ya no estás en pvp, puedes desconectarte."));
pl.sendMessage(Utils.colorize(PAData.SURVIVAL.getPrefix() + ChatColor.DARK_GREEN + " Ya no estás en pvp, puedes desconectarte."));
}
pl.sendMessage(ChatColor.GREEN + "");
}
示例14: onEntityDamage
import org.bukkit.event.entity.EntityDamageEvent; //导入依赖的package包/类
@EventHandler(priority = EventPriority.MONITOR, ignoreCancelled = true)
public void onEntityDamage(final EntityDamageEvent event) {
if(event.getEntity() instanceof Player) {
Player victim = (Player) event.getEntity();
Location location = victim.getBoundingBox().center().toLocation(match.getWorld());
if(event.getDamage() > 0 && location.getY() >= 0 && !victim.hasPotionEffect(PotionEffectType.INVISIBILITY)) {
EntityUtils.entities(match.getWorld(), Player.class)
.filter(player -> settings.getManager(player).getValue(Settings.BLOOD, Boolean.class, false))
.forEach(player -> {
if(event instanceof EntityDamageByEntityEvent) {
player.playEffect(location, Effect.STEP_SOUND, Material.REDSTONE_WIRE);
} else {
player.playEffect(location, Effect.STEP_SOUND, Material.LAVA);
}
});
}
}
}
示例15: onTarget
import org.bukkit.event.entity.EntityDamageEvent; //导入依赖的package包/类
@EventHandler(ignoreCancelled = true)
public void onTarget(EntityTargetEvent event) {
if(!(event.getEntity() instanceof ExperienceOrb)) {
ParticipantState victimState = null;
if(event.getTarget() instanceof Player) {
// Don't target allies
MatchPlayer victim = getVictim(event.getTarget());
if(victim == null) return;
victimState = victim.getParticipantState();
} else if(event.getTarget() != null) {
// Don't target other mobs owned by allies
victimState = entityResolver.getOwner(event.getTarget());
}
if(victimState == null) return;
DamageInfo damageInfo = damageResolver.resolveDamage(EntityDamageEvent.DamageCause.ENTITY_ATTACK, event.getTarget(), event.getEntity());
if(queryHostile(event, victimState, damageInfo).isDenied()) {
event.setCancelled(true);
}
}
}