Java 类org.bukkit.event.entity.EntityDamageEvent 实例源码
项目:Crescent
文件:AntiDamageA.java
@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);
}
}
}
项目:PA
文件:PlayerEvents.java
@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;
}
}
项目:MockBukkit
文件:PlayerMock.java
@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);
}
}
项目:Warzone
文件:DamageAPI.java
/**
* 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();
}
项目:Warzone
文件:SimpleGravityKillTracker.java
/**
* 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;
}
}
项目:Warzone
文件:ProjectileDamageResolver.java
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;
}
项目:Warzone
文件:DispensedProjectileDamageResolver.java
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;
}
项目:Warzone
文件:AnvilDamageResolver.java
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;
}
项目:Kineticraft
文件:Parties.java
@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));
}
}
项目:SurvivalPlus
文件:Chairs.java
@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();
}
}
项目:Arcadia-Spigot
文件:DamageListener.java
@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);
}
}
}
}
项目:ProjectAres
文件:PlayerStaminaState.java
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);
}
}
项目:PA
文件:PlayerEvents.java
@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 + "");
}
项目:ProjectAres
文件:BloodMatchModule.java
@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);
}
});
}
}
}
项目:ProjectAres
文件:DamageMatchModule.java
@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);
}
}
}
项目:SamaGamesCore
文件:CooldownModule.java
@EventHandler(priority = EventPriority.LOWEST)
public void onEntityDamageByEntity(EntityDamageByEntityEvent event)
{
if (api.getGameManager().isLegacyPvP()) {
Entity attacker = event.getDamager();
if (attacker instanceof Player) {
Player player = (Player) attacker;
ItemStack inHand = player.getInventory().getItemInMainHand();
if (inHand != null) {
double baseDamage = event.getDamage(EntityDamageEvent.DamageModifier.BASE);
double currentDamage = this.getCurrentDamage(inHand.getType());
if (currentDamage != 0.0D) {
double damageFactor = baseDamage / currentDamage;
double legacyDamage = this.getLegacyDamage(inHand.getType()) * damageFactor;
event.setDamage(EntityDamageEvent.DamageModifier.BASE, legacyDamage);
}
}
}
}
}
项目:WebSandboxMC
文件:WebPlayerBridge.java
public void notifyDied(String username, EntityDamageEvent.DamageCause cause) {
webSocketServerThread.log(Level.INFO, "web user "+username+"'s entity died from "+cause);
Channel channel = name2channel.get(username);
if (channel != null) {
String message = "T,You died from "+(cause == null ? "unknown causes" : cause);
if (!dieDisconnect) {
message += ", but remain connected to the server as a ghost";
}
webSocketServerThread.sendLine(channel, message);
if (dieDisconnect) {
channel.close();
clientDisconnected(channel);
}
}
}
项目:ProjectAres
文件:PotionDamageResolver.java
@Override
public @Nullable PotionInfo resolveDamage(EntityDamageEvent.DamageCause damageType, Entity victim, @Nullable PhysicalInfo damager) {
// If potion is already resolved (i.e. as a splash potion), leave it alone
if(damager instanceof PotionInfo ||
damager instanceof ProjectileInfo && ((ProjectileInfo) damager).getProjectile() instanceof PotionInfo) {
return null;
}
final PotionEffectType effect;
switch(damageType) {
case POISON: effect = PotionEffectType.POISON; break;
case WITHER: effect = PotionEffectType.WITHER; break;
case MAGIC: effect = PotionEffectType.HARM; break;
default: return null;
}
return new GenericPotionInfo(effect);
}
项目:Hub
文件:PlayerListener.java
@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());
}
}
项目:HCFCore
文件:VoidGlitchFixListener.java
@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.");
}
}
}
}
项目:mczone
文件:DamageEvents.java
@EventHandler
public void onEntityDamage(EntityDamageEvent event) {
if (event instanceof EntityDamageByEntityEvent)
return;
if (event.getEntity() instanceof Player == false)
return;
Player t = (Player) event.getEntity();
if (!damages.containsKey(t.getName()))
damages.put(t.getName(), new ArrayList<PlayerDamageEvent>());
PlayerDamageEvent callMe = new PlayerDamageEvent(t, event.getCause());
Bukkit.getPluginManager().callEvent(callMe);
event.setCancelled(callMe.isCancelled());
if (event.isCancelled() == false)
damages.get(t.getName()).add(callMe);
}
项目:mczone
文件:KitEvents.java
@EventHandler
public void Stomper(EntityDamageEvent e) {
if (e.getEntity() instanceof Player) {
Player p = (Player) e.getEntity();
if (Kit.getKit(p).getName().equalsIgnoreCase("stomper")) {
if (e.getCause() == DamageCause.FALL) {
List<Entity> nearbyEntities = e.getEntity()
.getNearbyEntities(5, 5, 5);
for (Entity target : nearbyEntities) {
if (target instanceof Player) {
Player t = (Player) target;
if (Team.getTeam(p) == Team.getTeam(t))
continue;
if (t.isSneaking())
t.damage(e.getDamage() / 2, e.getEntity());
else
t.damage(e.getDamage(), e.getEntity());
}
}
e.setDamage(0);
}
}
}
}
项目:Crescent
文件:DetectionListener.java
@EventHandler
public void onEntityDamage(EntityDamageEvent event) {
if (!(event.getEntity() instanceof Player)) {
return;
}
final Player player = (Player) event.getEntity();
getCheckVersion(player, CheckType.ANTIDAMAGE, "A").call(event);
}
项目:SurvivalAPI
文件:SuperheroesPlusModule.java
/**
* Cancel fall damages
*
* @param event Event instance
*/
@EventHandler
public void onDamage(EntityDamageEvent event)
{
if (event.getEntityType() == EntityType.PLAYER && event.getCause() == EntityDamageEvent.DamageCause.FALL)
{
event.setCancelled(true);
event.setDamage(0);
}
}
项目:CloudNet
文件:MobSelector.java
@EventHandler
public void entityDamage(EntityDamageEvent e)
{
MobImpl mob = CollectionWrapper.filter(mobs.values(), new Acceptable<MobImpl>() {
@Override
public boolean isAccepted(MobImpl value)
{
return e.getEntity().getEntityId() == value.getEntity().getEntityId();
}
});
if (mob != null)
{
e.setCancelled(true);
}
}
项目:kaosEssentials
文件:Core.java
@EventHandler(priority=EventPriority.LOWEST)
public void customDeathNonPlayerFallback(EntityDamageEvent e){
if(e.getCause().equals(DamageCause.FALL)) return;
if(e.getEntity() instanceof Player){
Player p = (Player) e.getEntity();
if(e.getCause().equals(DamageCause.ENTITY_ATTACK)){
// no need to do anything here, this part is controlled in the customDeath method
}else{
if(e.getFinalDamage() >= p.getHealth()){
e.setCancelled(true);
Bukkit.getServer().broadcastMessage(ChatColor.GRAY + p.getName() + " died");
// Set statistics
//p.setStatistic(Statistic.DEATHS, p.getStatistic(Statistic.DEATHS) + 1);
// Reset health, so they dont die
p.setHealth(p.getMaxHealth());
// Inventory clearing
p.getInventory().clear();
ItemStack air = new ItemStack(Material.AIR);
p.getInventory().setHelmet(air);
p.getInventory().setChestplate(air);
p.getInventory().setLeggings(air);
p.getInventory().setBoots(air);
// Clear potion effects
for(PotionEffect pe : p.getActivePotionEffects()){
p.removePotionEffect(pe.getType());
}
// Stop infinite kill glitch
p.setGameMode(GameMode.SPECTATOR);
p.setGameMode(GameMode.ADVENTURE);
// send them to the SPAWN of the world
p.teleport(p.getWorld().getSpawnLocation());
p.setFireTicks(0);
}
}
}
}
项目:Warzone
文件:BlitzModule.java
public void createDeath(EntityDamageEvent event) {
if (!(event.getEntity() instanceof Player)) return;
if (TGM.get().getApiManager().isStatsDisabled()) {
return;
}
Player player = (Player) event.getEntity();
List<ItemStack> drops = Arrays.asList(player.getInventory().getContents());
TGM.get().getGrave().getPlayerListener().onEntityDeath(new EntityDeathEvent(player, drops, player.getTotalExperience()));
}
项目:Warzone
文件:GravityDamageResolver.java
public @Nullable
DamageInfo resolve(@Nonnull LivingEntity entity, @Nonnull Lifetime lifetime, @Nonnull EntityDamageEvent damageEvent) {
if(!(entity instanceof Player)) return null;
Player victim = (Player) entity;
Fall fall = this.tracker.getCausingFall(victim, damageEvent.getCause());
if(fall != null) {
return new GravityDamageInfo(fall.attacker, fall.cause, fall.from);
} else {
return null;
}
}
项目:Warzone
文件:LavaDamageResolver.java
public @Nullable
DamageInfo resolve(@Nonnull LivingEntity entity, @Nonnull Lifetime lifetime, @Nonnull EntityDamageEvent damageEvent) {
if(damageEvent.getCause() == DamageCause.LAVA) {
return new SimpleLavaDamageInfo(null);
}
return null;
}
项目:VoxelGamesLibv2
文件:VoidTeleportFeature.java
@GameEvent
public void onVoidDamage(@Nonnull EntityDamageEvent event) {
if (event.getEntityType() != EntityType.PLAYER)
return;
if (event.getCause().equals(EntityDamageEvent.DamageCause.VOID)) {
Player player = (Player) event.getEntity();
player.teleport(getPhase().getFeature(SpawnFeature.class).getSpawn(player.getUniqueId()));
event.setCancelled(true);
}
}
项目:Warzone
文件:VoidDamageResolver.java
public @Nullable
DamageInfo resolve(@Nonnull LivingEntity entity, @Nonnull Lifetime lifetime, @Nonnull EntityDamageEvent damageEvent) {
if(damageEvent.getCause() == DamageCause.VOID) {
return new SimpleVoidDamageInfo(null);
}
return null;
}
项目:HCFCore
文件:StuckTimer.java
@EventHandler(ignoreCancelled=true, priority=EventPriority.MONITOR)
public void onPlayerDamage(EntityDamageEvent event)
{
Entity entity = event.getEntity();
if ((entity instanceof Player))
{
Player player = (Player)entity;
if (getRemaining(player) > 0L)
{
player.sendMessage(ChatColor.RED + "You were damaged, " + getDisplayName() + ChatColor.RED + " timer ended.");
clearCooldown(player);
}
}
}
项目:OMGPI
文件:OMGDamageEvent.java
public OMGDamageEvent(EntityDamageEvent e, OMGPlayer damaged, Entity damager, OMGDamageCause reason, float damage) {
super(e);
cancel = false;
this.damaged = damaged;
this.damager = damager;
this.reason = reason;
this.damage = damage;
OMGPI.g.event_player_damage(this);
}
项目:SurvivalAPI
文件:PyroTechnicsModule.java
/**
* Fire player on damage
* @param event Event
*/
@EventHandler(priority = EventPriority.LOWEST)
public void onDamage(EntityDamageEvent event)
{
if (((SurvivalGame) SamaGamesAPI.get().getGameManager().getGame()).isDamagesActivated()
&& event.getEntityType() == EntityType.PLAYER
&& event.getCause() != EntityDamageEvent.DamageCause.FIRE
&& event.getCause() != EntityDamageEvent.DamageCause.FIRE_TICK
&& event.getDamage() > 0
&& !event.isCancelled())
event.getEntity().setFireTicks((int) this.moduleConfiguration.get("fire-time") * 20);
}
项目:Arcadia-Spigot
文件:Freeze.java
@EventHandler
public void onEntityDamage(EntityDamageEvent event) {
if(event.getEntity().getUniqueId() == entity.getUniqueId())
event.setCancelled(true);
if(event.getEntity().getUniqueId() == player.getUniqueId())
event.setCancelled(true);
}
项目:bskyblock
文件:VisitorGuard.java
/**
* Prevents visitors from getting damage if invinciblevisitors option is set to TRUE
* @param e
*/
@EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true)
public void onVisitorReceiveDamage(EntityDamageEvent e){
if(!Settings.invincibleVisitor) return;
if(!(e.getEntity() instanceof Player)) return;
Player p = (Player) e.getEntity();
if (!Util.inWorld(p) || plugin.getIslands().locationIsOnIsland(p, p.getLocation())) return;
if (Settings.invincibleVisitorOptions.contains(e.getCause())) e.setCancelled(true);
else if(e.getCause().equals(DamageCause.VOID)) {
if(plugin.getPlayers().hasIsland(p.getUniqueId())) {
Location safePlace = plugin.getIslands().getSafeHomeLocation(p.getUniqueId(), 1);
if (safePlace != null) {
p.teleport(safePlace);
// Set their fall distance to zero otherwise they crash onto their island and die
p.setFallDistance(0);
e.setCancelled(true);
return;
}
}
// No island, or no safe spot on island
if (plugin.getIslands().getSpawn() != null) {
p.teleport(plugin.getIslands().getSpawnPoint());
// Set their fall distance to zero otherwise they crash onto their island and die
p.setFallDistance(0);
e.setCancelled(true);
return;
}
// No island spawn, try regular spawn
if (!p.performCommand("spawn")) {
// If this command doesn't work, let them die otherwise they may get trapped in the void forever
return;
}
// Set their fall distance to zero otherwise they crash onto their island and die
p.setFallDistance(0);
e.setCancelled(true);
}
}
项目:Absorption
文件:PlayerListener.java
@EventHandler
public void onEntityDamage(EntityDamageEvent e) {
if(e.getEntity() instanceof ArmorStand || e.getEntity() instanceof Item)
e.setCancelled(true);
if(e.getEntity() instanceof Player) {
e.setCancelled(true);
if(e.getCause() == DamageCause.FALL) {
GamePlayer player = Absorption.getPlayer((Player) e.getEntity());
if(player == null) return;
player.damage((int) e.getDamage());
}
}
}
项目:Slimefun4-Chinese-Version
文件:DamageListener.java
public void onArrowHit(EntityDamageEvent e)
{
if((e.getEntity() instanceof Player) && e.getCause() == org.bukkit.event.entity.EntityDamageEvent.DamageCause.FALL && Variables.damage.containsKey(e.getEntity().getUniqueId()))
{
e.setCancelled(true);
Variables.damage.remove(e.getEntity().getUniqueId());
}
}
项目:SuperiorCraft
文件:DamageIndicator.java
@EventHandler
public void onEntityDamageEvent(EntityDamageEvent e) {
if (!(e.getEntity() instanceof ArmorStand) && e.getEntityType() != EntityType.ARMOR_STAND && e.getEntityType() != EntityType.DROPPED_ITEM) {
Hologram h = new Hologram(ChatColor.RED + "-" + Double.toString(e.getDamage()) + " \u2764", e.getEntity().getLocation());
h.getHologram().addScoreboardTag("dindicator");
h.setKillTimer(2);
}
if (e.getEntity() instanceof Player) {
Player player = (Player) e.getEntity();
player.sendMessage(ChatColor.GRAY + "[DamageIndicator] " + e.getCause().name() + " did " + new DecimalFormat("#0.0").format(((double) Math.round(e.getDamage())) / 2) + ChatColor.RED + " \u2764");
}
}
项目:BlockBall
文件:GameListener.java
@EventHandler
public void onPlayerDamageEvent(EntityDamageEvent event) {
if (event.getEntity() instanceof Player) {
Game game;
if ((game = this.controller.getGameFromPlayer((Player) event.getEntity())) != null) {
if (!game.getArena().getTeamMeta().isDamageEnabled())
event.setCancelled(true);
} else if ((game = this.controller.isInGameLobby((Player) event.getEntity())) != null) {
if (!game.getArena().getTeamMeta().isDamageEnabled())
event.setCancelled(true);
}
}
}