Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package games.coob.skywars.model;
- import org.bukkit.Bukkit;
- import org.bukkit.Location;
- import org.bukkit.Material;
- import org.bukkit.block.Block;
- import org.bukkit.block.BlockFace;
- import org.bukkit.entity.Entity;
- import org.bukkit.entity.EntityType;
- import org.bukkit.entity.LivingEntity;
- import org.bukkit.entity.Player;
- import org.bukkit.event.EventHandler;
- import org.bukkit.event.EventPriority;
- import org.bukkit.event.Listener;
- import org.bukkit.event.entity.EntityDamageEvent;
- import org.bukkit.event.entity.EntityExplodeEvent;
- import org.mineacademy.fo.Common;
- import java.util.List;
- public class ExplosionEvent implements Listener {
- @EventHandler(priority = EventPriority.LOWEST, ignoreCancelled = false)
- public void Explosion(final EntityExplodeEvent event) {
- final Location loc = event.getLocation();
- final double radius = SettingsStorage.getInstance().TNT_RANGE;
- if (loc.getWorld() == null) {
- return;
- }
- final List<Entity> nearbyEntities = (List<Entity>) loc.getWorld().getNearbyEntities(loc, radius, radius, radius);
- if (event.getEntityType() == EntityType.PRIMED_TNT) {
- final double hf = SettingsStorage.getInstance().TNT_HEIGHT / 2;
- final double rf = SettingsStorage.getInstance().TNT_RANGE_FORCE / 2;
- for (final Entity entity : nearbyEntities) {
- if (entity instanceof Player) {
- pushAway((LivingEntity) entity, loc, hf, rf, event);
- Common.broadcast("You are pushed");
- return;
- }
- }
- }
- }
- void pushAway(final LivingEntity player, final Location l, final double hf, final double rf, final EntityExplodeEvent e) {
- final Location playerLocation = player.getLocation();
- final Block behindBlock = playerLocation.getBlock().getRelative(BlockFace.SOUTH);
- if (behindBlock.getType() != Material.AIR)
- return;
- double distance = e.getYield() * 8.0f;
- distance *= 1;
- final double hf1 = Math.max(-4, Math.min(4, hf));
- final double rf1 = Math.max(-4, Math.min(4, -1 * rf));
- player.setVelocity(l.toVector().subtract(loc.toVector()).normalize().multiply(rf1).setY(hf1));
- final EntityDamageEvent DamageEvent = new EntityDamageEvent(player, EntityDamageEvent.DamageCause.BLOCK_EXPLOSION, distance - loc.distance(player.getLocation()));
- Bukkit.getPluginManager().callEvent(DamageEvent);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement