Actually cancel projectile hit events (#3154)

Co-authored-by: NotMyFault <mc.cache@web.de>
This commit is contained in:
Traks 2021-07-13 10:57:12 +02:00 committed by GitHub
parent a797d748ea
commit cc60d50dd2
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -62,18 +62,6 @@ public class ProjectileEventListener implements Listener {
this.plotAreaManager = plotAreaManager; this.plotAreaManager = plotAreaManager;
} }
@EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true)
public void onPotionSplash(LingeringPotionSplashEvent event) {
Projectile entity = event.getEntity();
Location location = BukkitUtil.adapt(entity.getLocation());
if (!this.plotAreaManager.hasPlotArea(location.getWorldName())) {
return;
}
if (!this.onProjectileHit(event)) {
event.setCancelled(true);
}
}
@EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true) @EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true)
public void onPotionSplash(PotionSplashEvent event) { public void onPotionSplash(PotionSplashEvent event) {
ThrownPotion damager = event.getPotion(); ThrownPotion damager = event.getPotion();
@ -88,7 +76,7 @@ public class ProjectileEventListener implements Listener {
count++; count++;
} }
} }
if ((count > 0 && count == event.getAffectedEntities().size()) || !onProjectileHit(event)) { if (count > 0 && count == event.getAffectedEntities().size()) {
event.setCancelled(true); event.setCancelled(true);
} }
} }
@ -115,17 +103,16 @@ public class ProjectileEventListener implements Listener {
} }
} }
@SuppressWarnings({"BooleanMethodIsAlwaysInverted", "cos it's not... dum IntelliJ"})
@EventHandler @EventHandler
public boolean onProjectileHit(ProjectileHitEvent event) { public void onProjectileHit(ProjectileHitEvent event) {
Projectile entity = event.getEntity(); Projectile entity = event.getEntity();
Location location = BukkitUtil.adapt(entity.getLocation()); Location location = BukkitUtil.adapt(entity.getLocation());
if (!this.plotAreaManager.hasPlotArea(location.getWorldName())) { if (!this.plotAreaManager.hasPlotArea(location.getWorldName())) {
return true; return;
} }
PlotArea area = location.getPlotArea(); PlotArea area = location.getPlotArea();
if (area == null) { if (area == null) {
return true; return;
} }
Plot plot = area.getPlot(location); Plot plot = area.getPlot(location);
ProjectileSource shooter = entity.getShooter(); ProjectileSource shooter = entity.getShooter();
@ -134,35 +121,38 @@ public class ProjectileEventListener implements Listener {
if (plot == null) { if (plot == null) {
if (!Permissions.hasPermission(pp, Permission.PERMISSION_PROJECTILE_UNOWNED)) { if (!Permissions.hasPermission(pp, Permission.PERMISSION_PROJECTILE_UNOWNED)) {
entity.remove(); entity.remove();
return false; event.setCancelled(true);
} }
return true; return;
} }
if (plot.isAdded(pp.getUUID()) || Permissions if (plot.isAdded(pp.getUUID()) || Permissions
.hasPermission(pp, Permission.PERMISSION_PROJECTILE_OTHER)) { .hasPermission(pp, Permission.PERMISSION_PROJECTILE_OTHER)) {
return true; return;
} }
entity.remove(); entity.remove();
return false; event.setCancelled(true);
return;
} }
if (!(shooter instanceof Entity) && shooter != null) { if (!(shooter instanceof Entity) && shooter != null) {
if (plot == null) { if (plot == null) {
entity.remove(); entity.remove();
return false; event.setCancelled(true);
return;
} }
Location sLoc = Location sLoc =
BukkitUtil.adapt(((BlockProjectileSource) shooter).getBlock().getLocation()); BukkitUtil.adapt(((BlockProjectileSource) shooter).getBlock().getLocation());
if (!area.contains(sLoc.getX(), sLoc.getZ())) { if (!area.contains(sLoc.getX(), sLoc.getZ())) {
entity.remove(); entity.remove();
return false; event.setCancelled(true);
return;
} }
Plot sPlot = area.getOwnedPlotAbs(sLoc); Plot sPlot = area.getOwnedPlotAbs(sLoc);
if (sPlot == null || !PlotHandler.sameOwners(plot, sPlot)) { if (sPlot == null || !PlotHandler.sameOwners(plot, sPlot)) {
entity.remove(); entity.remove();
return false; event.setCancelled(true);
return;
} }
} }
return true;
} }
} }