mirror of
https://github.com/IntellectualSites/PlotSquared.git
synced 2024-11-22 05:06:44 +01:00
Avoid creating EntityDamageByEntityEvent (#4332)
This commit is contained in:
parent
a2e3274215
commit
0de6887526
@ -56,6 +56,7 @@ import org.bukkit.entity.Player;
|
|||||||
import org.bukkit.entity.Projectile;
|
import org.bukkit.entity.Projectile;
|
||||||
import org.bukkit.entity.TNTPrimed;
|
import org.bukkit.entity.TNTPrimed;
|
||||||
import org.bukkit.entity.Vehicle;
|
import org.bukkit.entity.Vehicle;
|
||||||
|
import org.bukkit.event.Cancellable;
|
||||||
import org.bukkit.event.EventHandler;
|
import org.bukkit.event.EventHandler;
|
||||||
import org.bukkit.event.EventPriority;
|
import org.bukkit.event.EventPriority;
|
||||||
import org.bukkit.event.Listener;
|
import org.bukkit.event.Listener;
|
||||||
@ -98,37 +99,25 @@ public class EntityEventListener implements Listener {
|
|||||||
|
|
||||||
@EventHandler(priority = EventPriority.HIGHEST)
|
@EventHandler(priority = EventPriority.HIGHEST)
|
||||||
public void onEntityCombustByEntity(EntityCombustByEntityEvent event) {
|
public void onEntityCombustByEntity(EntityCombustByEntityEvent event) {
|
||||||
EntityDamageByEntityEvent eventChange =
|
onEntityDamageByEntityCommon(event.getCombuster(), event.getEntity(), EntityDamageEvent.DamageCause.FIRE_TICK, event);
|
||||||
new EntityDamageByEntityEvent(
|
|
||||||
event.getCombuster(),
|
|
||||||
event.getEntity(),
|
|
||||||
EntityDamageEvent.DamageCause.FIRE_TICK,
|
|
||||||
event.getDuration()
|
|
||||||
);
|
|
||||||
onEntityDamageByEntityEvent(eventChange);
|
|
||||||
if (eventChange.isCancelled()) {
|
|
||||||
event.setCancelled(true);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@EventHandler(priority = EventPriority.HIGHEST)
|
@EventHandler(priority = EventPriority.HIGHEST)
|
||||||
public void onEntityDamageByEntityEvent(EntityDamageByEntityEvent event) {
|
public void onEntityDamageByEntityEvent(EntityDamageByEntityEvent event) {
|
||||||
Entity damager = event.getDamager();
|
onEntityDamageByEntityCommon(event.getDamager(), event.getEntity(), event.getCause(), event);
|
||||||
|
}
|
||||||
|
|
||||||
|
private void onEntityDamageByEntityCommon(
|
||||||
|
final Entity damager,
|
||||||
|
final Entity victim,
|
||||||
|
final EntityDamageEvent.DamageCause cause,
|
||||||
|
final Cancellable event
|
||||||
|
) {
|
||||||
Location location = BukkitUtil.adapt(damager.getLocation());
|
Location location = BukkitUtil.adapt(damager.getLocation());
|
||||||
if (!this.plotAreaManager.hasPlotArea(location.getWorldName())) {
|
if (!this.plotAreaManager.hasPlotArea(location.getWorldName())) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
Entity victim = event.getEntity();
|
if (!BukkitEntityUtil.entityDamage(damager, victim, cause)) {
|
||||||
/*
|
|
||||||
if (victim.getType().equals(EntityType.ITEM_FRAME)) {
|
|
||||||
Plot plot = BukkitUtil.getLocation(victim).getPlot();
|
|
||||||
if (plot != null && !plot.isAdded(damager.getUniqueId())) {
|
|
||||||
event.setCancelled(true);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
*/
|
|
||||||
if (!BukkitEntityUtil.entityDamage(damager, victim, event.getCause())) {
|
|
||||||
if (event.isCancelled()) {
|
if (event.isCancelled()) {
|
||||||
if (victim instanceof Ageable ageable) {
|
if (victim instanceof Ageable ageable) {
|
||||||
if (ageable.getAge() == -24000) {
|
if (ageable.getAge() == -24000) {
|
||||||
|
Loading…
Reference in New Issue
Block a user