Advertisement
JackOUT

Untitled

Dec 14th, 2021
187
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.29 KB | None | 0 0
  1. package games.coob.skywars.model;
  2.  
  3. import org.bukkit.Bukkit;
  4. import org.bukkit.Location;
  5. import org.bukkit.Material;
  6. import org.bukkit.block.Block;
  7. import org.bukkit.block.BlockFace;
  8. import org.bukkit.entity.Entity;
  9. import org.bukkit.entity.EntityType;
  10. import org.bukkit.entity.LivingEntity;
  11. import org.bukkit.entity.Player;
  12. import org.bukkit.event.EventHandler;
  13. import org.bukkit.event.EventPriority;
  14. import org.bukkit.event.Listener;
  15. import org.bukkit.event.entity.EntityDamageEvent;
  16. import org.bukkit.event.entity.EntityExplodeEvent;
  17. import org.mineacademy.fo.Common;
  18.  
  19. import java.util.List;
  20.  
  21. public class ExplosionEvent implements Listener {
  22.  
  23.  
  24. @EventHandler(priority = EventPriority.LOWEST, ignoreCancelled = false)
  25. public void Explosion(final EntityExplodeEvent event) {
  26. final Location loc = event.getLocation();
  27.  
  28. final double radius = SettingsStorage.getInstance().TNT_RANGE;
  29.  
  30. if (loc.getWorld() == null) {
  31. return;
  32.  
  33. }
  34. final List<Entity> nearbyEntities = (List<Entity>) loc.getWorld().getNearbyEntities(loc, radius, radius, radius);
  35. if (event.getEntityType() == EntityType.PRIMED_TNT) {
  36. final double hf = SettingsStorage.getInstance().TNT_HEIGHT / 2;
  37. final double rf = SettingsStorage.getInstance().TNT_RANGE_FORCE / 2;
  38.  
  39.  
  40. for (final Entity entity : nearbyEntities) {
  41. if (entity instanceof Player) {
  42.  
  43. pushAway((LivingEntity) entity, loc, hf, rf, event);
  44. Common.broadcast("You are pushed");
  45. return;
  46. }
  47. }
  48. }
  49.  
  50.  
  51. }
  52.  
  53. void pushAway(final LivingEntity player, final Location l, final double hf, final double rf, final EntityExplodeEvent e) {
  54. final Location playerLocation = player.getLocation();
  55. final Block behindBlock = playerLocation.getBlock().getRelative(BlockFace.SOUTH);
  56.  
  57. if (behindBlock.getType() != Material.AIR)
  58. return;
  59.  
  60. double distance = e.getYield() * 8.0f;
  61. distance *= 1;
  62.  
  63. final double hf1 = Math.max(-4, Math.min(4, hf));
  64. final double rf1 = Math.max(-4, Math.min(4, -1 * rf));
  65.  
  66. player.setVelocity(l.toVector().subtract(loc.toVector()).normalize().multiply(rf1).setY(hf1));
  67.  
  68. final EntityDamageEvent DamageEvent = new EntityDamageEvent(player, EntityDamageEvent.DamageCause.BLOCK_EXPLOSION, distance - loc.distance(player.getLocation()));
  69. Bukkit.getPluginManager().callEvent(DamageEvent);
  70. }
  71. }
  72.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement