mirror of
https://github.com/PaperMC/Paper.git
synced 2024-12-30 16:19:03 +01:00
Improve compatibility of new DamageSource API
By: md_5 <git@md-5.net>
This commit is contained in:
parent
e32cdbcc1c
commit
5c89ccf428
4 changed files with 35 additions and 0 deletions
|
@ -395,7 +395,9 @@ public interface Entity extends Metadatable, CommandSender, Nameable, Persistent
|
|||
* Record the last {@link EntityDamageEvent} inflicted on this entity
|
||||
*
|
||||
* @param event a {@link EntityDamageEvent}
|
||||
* @deprecated method is for internal use only and will be removed
|
||||
*/
|
||||
@Deprecated(forRemoval = true)
|
||||
public void setLastDamageCause(@Nullable EntityDamageEvent event);
|
||||
|
||||
/**
|
||||
|
|
|
@ -4,6 +4,7 @@ import com.google.common.base.Function;
|
|||
import java.util.Map;
|
||||
import org.bukkit.block.Block;
|
||||
import org.bukkit.damage.DamageSource;
|
||||
import org.bukkit.damage.DamageType;
|
||||
import org.bukkit.entity.Entity;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
@ -14,11 +15,21 @@ import org.jetbrains.annotations.Nullable;
|
|||
public class EntityDamageByBlockEvent extends EntityDamageEvent {
|
||||
private final Block damager;
|
||||
|
||||
@Deprecated(forRemoval = true)
|
||||
public EntityDamageByBlockEvent(@Nullable final Block damager, @NotNull final Entity damagee, @NotNull final DamageCause cause, final double damage) {
|
||||
this(damager, damagee, cause, (damager != null) ? DamageSource.builder(DamageType.GENERIC).withDamageLocation(damager.getLocation()).build() : DamageSource.builder(DamageType.GENERIC).build(), damage);
|
||||
}
|
||||
|
||||
public EntityDamageByBlockEvent(@Nullable final Block damager, @NotNull final Entity damagee, @NotNull final DamageCause cause, @NotNull final DamageSource damageSource, final double damage) {
|
||||
super(damagee, cause, damageSource, damage);
|
||||
this.damager = damager;
|
||||
}
|
||||
|
||||
@Deprecated(forRemoval = true)
|
||||
public EntityDamageByBlockEvent(@Nullable final Block damager, @NotNull final Entity damagee, @NotNull final DamageCause cause, @NotNull final Map<DamageModifier, Double> modifiers, @NotNull final Map<DamageModifier, ? extends Function<? super Double, Double>> modifierFunctions) {
|
||||
this(damager, damagee, cause, (damager != null) ? DamageSource.builder(DamageType.GENERIC).withDamageLocation(damager.getLocation()).build() : DamageSource.builder(DamageType.GENERIC).build(), modifiers, modifierFunctions);
|
||||
}
|
||||
|
||||
public EntityDamageByBlockEvent(@Nullable final Block damager, @NotNull final Entity damagee, @NotNull final DamageCause cause, @NotNull final DamageSource damageSource, @NotNull final Map<DamageModifier, Double> modifiers, @NotNull final Map<DamageModifier, ? extends Function<? super Double, Double>> modifierFunctions) {
|
||||
super(damagee, cause, damageSource, modifiers, modifierFunctions);
|
||||
this.damager = damager;
|
||||
|
|
|
@ -3,6 +3,7 @@ package org.bukkit.event.entity;
|
|||
import com.google.common.base.Function;
|
||||
import java.util.Map;
|
||||
import org.bukkit.damage.DamageSource;
|
||||
import org.bukkit.damage.DamageType;
|
||||
import org.bukkit.entity.Entity;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
|
@ -12,11 +13,21 @@ import org.jetbrains.annotations.NotNull;
|
|||
public class EntityDamageByEntityEvent extends EntityDamageEvent {
|
||||
private final Entity damager;
|
||||
|
||||
@Deprecated(forRemoval = true)
|
||||
public EntityDamageByEntityEvent(@NotNull final Entity damager, @NotNull final Entity damagee, @NotNull final DamageCause cause, final double damage) {
|
||||
this(damager, damagee, cause, DamageSource.builder(DamageType.GENERIC).withCausingEntity(damager).withDirectEntity(damager).build(), damage);
|
||||
}
|
||||
|
||||
public EntityDamageByEntityEvent(@NotNull final Entity damager, @NotNull final Entity damagee, @NotNull final DamageCause cause, @NotNull final DamageSource damageSource, final double damage) {
|
||||
super(damagee, cause, damageSource, damage);
|
||||
this.damager = damager;
|
||||
}
|
||||
|
||||
@Deprecated(forRemoval = true)
|
||||
public EntityDamageByEntityEvent(@NotNull final Entity damager, @NotNull final Entity damagee, @NotNull final DamageCause cause, @NotNull final Map<DamageModifier, Double> modifiers, @NotNull final Map<DamageModifier, ? extends Function<? super Double, Double>> modifierFunctions) {
|
||||
this(damager, damagee, cause, DamageSource.builder(DamageType.GENERIC).withCausingEntity(damager).withDirectEntity(damager).build(), modifiers, modifierFunctions);
|
||||
}
|
||||
|
||||
public EntityDamageByEntityEvent(@NotNull final Entity damager, @NotNull final Entity damagee, @NotNull final DamageCause cause, @NotNull final DamageSource damageSource, @NotNull final Map<DamageModifier, Double> modifiers, @NotNull final Map<DamageModifier, ? extends Function<? super Double, Double>> modifierFunctions) {
|
||||
super(damagee, cause, damageSource, modifiers, modifierFunctions);
|
||||
this.damager = damager;
|
||||
|
|
|
@ -10,6 +10,7 @@ import java.util.Objects;
|
|||
import org.bukkit.Material;
|
||||
import org.bukkit.WorldBorder;
|
||||
import org.bukkit.damage.DamageSource;
|
||||
import org.bukkit.damage.DamageType;
|
||||
import org.bukkit.entity.Entity;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.event.Cancellable;
|
||||
|
@ -30,10 +31,20 @@ public class EntityDamageEvent extends EntityEvent implements Cancellable {
|
|||
private final DamageCause cause;
|
||||
private final DamageSource damageSource;
|
||||
|
||||
@Deprecated(forRemoval = true)
|
||||
public EntityDamageEvent(@NotNull final Entity damagee, @NotNull final DamageCause cause, final double damage) {
|
||||
this(damagee, cause, DamageSource.builder(DamageType.GENERIC).build(), damage);
|
||||
}
|
||||
|
||||
public EntityDamageEvent(@NotNull final Entity damagee, @NotNull final DamageCause cause, @NotNull final DamageSource damageSource, final double damage) {
|
||||
this(damagee, cause, damageSource, new EnumMap<DamageModifier, Double>(ImmutableMap.of(DamageModifier.BASE, damage)), new EnumMap<DamageModifier, Function<? super Double, Double>>(ImmutableMap.of(DamageModifier.BASE, ZERO)));
|
||||
}
|
||||
|
||||
@Deprecated(forRemoval = true)
|
||||
public EntityDamageEvent(@NotNull final Entity damagee, @NotNull final DamageCause cause, @NotNull final Map<DamageModifier, Double> modifiers, @NotNull final Map<DamageModifier, ? extends Function<? super Double, Double>> modifierFunctions) {
|
||||
this(damagee, cause, DamageSource.builder(DamageType.GENERIC).build(), modifiers, modifierFunctions);
|
||||
}
|
||||
|
||||
public EntityDamageEvent(@NotNull final Entity damagee, @NotNull final DamageCause cause, @NotNull final DamageSource damageSource, @NotNull final Map<DamageModifier, Double> modifiers, @NotNull final Map<DamageModifier, ? extends Function<? super Double, Double>> modifierFunctions) {
|
||||
super(damagee);
|
||||
Preconditions.checkArgument(modifiers.containsKey(DamageModifier.BASE), "BASE DamageModifier missing");
|
||||
|
|
Loading…
Reference in a new issue