mirror of
https://github.com/mcMMO-Dev/mcMMO.git
synced 2024-11-22 05:06:45 +01:00
Add McMMOEntityDamageByRuptureEvent (#4498)
This commit is contained in:
parent
394e9e5110
commit
6d0fe4fb58
@ -1,9 +1,9 @@
|
||||
package com.gmail.nossr50.events.fake;
|
||||
|
||||
import com.google.common.base.Function;
|
||||
import com.google.common.base.Functions;
|
||||
import org.bukkit.entity.Entity;
|
||||
import org.bukkit.event.entity.EntityDamageByEntityEvent;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
import java.util.EnumMap;
|
||||
import java.util.Map;
|
||||
@ -13,21 +13,21 @@ import java.util.Map;
|
||||
*/
|
||||
public class FakeEntityDamageByEntityEvent extends EntityDamageByEntityEvent implements FakeEvent {
|
||||
|
||||
public FakeEntityDamageByEntityEvent(Entity damager, Entity damagee, DamageCause cause, final Map<DamageModifier, Double> modifiers) {
|
||||
public FakeEntityDamageByEntityEvent(@NotNull Entity damager, @NotNull Entity damagee, @NotNull DamageCause cause, @NotNull final Map<DamageModifier, Double> modifiers) {
|
||||
super(damager, damagee, cause, modifiers, getFunctionModifiers(modifiers));
|
||||
}
|
||||
|
||||
@Deprecated
|
||||
public FakeEntityDamageByEntityEvent(Entity damager, Entity damagee, DamageCause cause, double damage) {
|
||||
public FakeEntityDamageByEntityEvent(@NotNull Entity damager, @NotNull Entity damagee, @NotNull DamageCause cause, double damage) {
|
||||
super(damager, damagee, cause, damage);
|
||||
}
|
||||
|
||||
public static EnumMap<DamageModifier, Function<? super Double, Double>> getFunctionModifiers(Map<DamageModifier, Double> modifiers) {
|
||||
@NotNull
|
||||
public static EnumMap<DamageModifier, Function<? super Double, Double>> getFunctionModifiers(@NotNull Map<DamageModifier, Double> modifiers) {
|
||||
EnumMap<DamageModifier, Function<? super Double, Double>> modifierFunctions = new EnumMap<>(DamageModifier.class);
|
||||
Function<? super Double, Double> ZERO = Functions.constant(-0.0);
|
||||
|
||||
for (DamageModifier modifier : modifiers.keySet()) {
|
||||
modifierFunctions.put(modifier, ZERO);
|
||||
modifierFunctions.put(modifier, (o -> -0.0));
|
||||
}
|
||||
|
||||
return modifierFunctions;
|
||||
|
@ -0,0 +1,23 @@
|
||||
package com.gmail.nossr50.events.skills.rupture;
|
||||
|
||||
import com.gmail.nossr50.datatypes.player.McMMOPlayer;
|
||||
import com.google.common.collect.ImmutableMap;
|
||||
import org.bukkit.entity.Entity;
|
||||
import org.bukkit.event.entity.EntityDamageByEntityEvent;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
import java.util.EnumMap;
|
||||
|
||||
public class McMMOEntityDamageByRuptureEvent extends EntityDamageByEntityEvent {
|
||||
private final McMMOPlayer mcMMODamager;
|
||||
|
||||
public McMMOEntityDamageByRuptureEvent(@NotNull McMMOPlayer damager, @NotNull Entity damagee, double damage) {
|
||||
super(damager.getPlayer(), damagee, DamageCause.CUSTOM, new EnumMap<>(ImmutableMap.of(DamageModifier.BASE, damage)), new EnumMap<>(ImmutableMap.of(DamageModifier.BASE, (o -> -0.0))));
|
||||
this.mcMMODamager = damager;
|
||||
}
|
||||
|
||||
@NotNull
|
||||
public McMMOPlayer getMcMMODamager() {
|
||||
return mcMMODamager;
|
||||
}
|
||||
}
|
@ -8,6 +8,7 @@ import com.gmail.nossr50.datatypes.skills.subskills.interfaces.InteractType;
|
||||
import com.gmail.nossr50.events.fake.FakeEntityDamageByEntityEvent;
|
||||
import com.gmail.nossr50.events.fake.FakeEntityDamageEvent;
|
||||
import com.gmail.nossr50.events.fake.FakeEntityTameEvent;
|
||||
import com.gmail.nossr50.events.skills.rupture.McMMOEntityDamageByRuptureEvent;
|
||||
import com.gmail.nossr50.mcMMO;
|
||||
import com.gmail.nossr50.party.PartyManager;
|
||||
import com.gmail.nossr50.skills.archery.Archery;
|
||||
@ -290,7 +291,7 @@ public class EntityListener implements Listener {
|
||||
*/
|
||||
@EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true)
|
||||
public void onEntityDamageByEntity(EntityDamageByEntityEvent event) {
|
||||
if (event instanceof FakeEntityDamageByEntityEvent) {
|
||||
if (event instanceof FakeEntityDamageByEntityEvent || event instanceof McMMOEntityDamageByRuptureEvent) {
|
||||
return;
|
||||
}
|
||||
|
||||
|
@ -1,6 +1,7 @@
|
||||
package com.gmail.nossr50.runnables.skills;
|
||||
|
||||
import com.gmail.nossr50.datatypes.player.McMMOPlayer;
|
||||
import com.gmail.nossr50.events.skills.rupture.McMMOEntityDamageByRuptureEvent;
|
||||
import com.gmail.nossr50.mcMMO;
|
||||
import com.gmail.nossr50.util.skills.ParticleEffectUtils;
|
||||
import com.google.common.base.Objects;
|
||||
@ -45,18 +46,25 @@ public class RuptureTask extends BukkitRunnable {
|
||||
if(ruptureTick < expireTick) {
|
||||
//Is it time to damage?
|
||||
if(damageTickTracker >= DAMAGE_TICK_INTERVAL) {
|
||||
damageTickTracker = 0; //Reset
|
||||
ParticleEffectUtils.playBleedEffect(targetEntity); //Animate
|
||||
|
||||
if(targetEntity.getHealth() > 0.01) {
|
||||
damageTickTracker = 0; //Reset timer
|
||||
double healthBeforeRuptureIsApplied = targetEntity.getHealth();
|
||||
double damagedHealth = healthBeforeRuptureIsApplied - calculateAdjustedTickDamage();
|
||||
|
||||
if(damagedHealth <= 0) {
|
||||
mcMMO.p.getLogger().severe("DEBUG: Miscalculating Rupture tick damage");
|
||||
} else {
|
||||
targetEntity.setHealth(damagedHealth); //Hurt entity without the unwanted side effects of damage()
|
||||
}
|
||||
//Ensure victim has health
|
||||
if (healthBeforeRuptureIsApplied > 0.01) {
|
||||
//Send a fake damage event
|
||||
McMMOEntityDamageByRuptureEvent event = new McMMOEntityDamageByRuptureEvent(ruptureSource, targetEntity, calculateAdjustedTickDamage());
|
||||
mcMMO.p.getServer().getPluginManager().callEvent(event);
|
||||
|
||||
//Ensure the event wasn't cancelled and damage is still greater than 0
|
||||
double damage = event.getFinalDamage();
|
||||
if (event.isCancelled() || damage <= 0 || healthBeforeRuptureIsApplied - damage <= 0)
|
||||
return;
|
||||
|
||||
ParticleEffectUtils.playBleedEffect(targetEntity); //Animate
|
||||
double damagedHealth = healthBeforeRuptureIsApplied - damage;
|
||||
|
||||
targetEntity.setHealth(damagedHealth); //Hurt entity without the unwanted side effects of damage()}
|
||||
}
|
||||
}
|
||||
} else {
|
||||
|
Loading…
Reference in New Issue
Block a user