Advertisement
Guest User

Untitled

a guest
Nov 23rd, 2017
68
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 2.64 KB | None | 0 0
  1. package de.mario52.atomiccraft.explosioncontrol;
  2.  
  3. import java.util.ArrayList;
  4. import java.util.Arrays;
  5. import java.util.List;
  6.  
  7. import org.bukkit.Bukkit;
  8. import org.bukkit.Effect;
  9. import org.bukkit.Location;
  10. import org.bukkit.Particle;
  11. import org.bukkit.entity.Player;
  12. import org.bukkit.plugin.Plugin;
  13. import org.bukkit.potion.PotionEffect;
  14. import org.bukkit.potion.PotionEffectType;
  15.  
  16. import project.particle.handle.ParticleHandler;
  17.  
  18. public class BombExplosion
  19. {
  20.     Location loc;
  21.     int time;
  22.     String sender;
  23.     int countdown_id;
  24.     int shockwave;
  25.     Plugin pl;
  26.     double shockw_radius = 0;
  27.    
  28.     public BombExplosion(Location loc, int time, String sender, Plugin pl)
  29.     {
  30.         this.loc = loc;
  31.         this.time = time;
  32.         this.sender = sender;
  33.         this.pl = pl;
  34.        
  35.     }
  36.    
  37.     @SuppressWarnings("deprecation")
  38.     public void launch()
  39.     {
  40.         Bukkit.broadcastMessage("§4§l" + sender + " placed a NUKE at X" + loc.getBlockX() + ", Y" + loc.getBlockY() + ", Z" + loc.getBlockZ());
  41.         countdown_id = Bukkit.getScheduler().scheduleSyncRepeatingTask(pl, new Runnable() {
  42.  
  43.             @Override
  44.             public void run() {
  45.                 Bukkit.broadcastMessage("§4" + time + " seconds left");
  46.                 time--;
  47.                 if(time == 9)
  48.                 {
  49.                     Bukkit.getScheduler().cancelTask(countdown_id);
  50.                     detonate();
  51.                 }
  52.                
  53.             }
  54.            
  55.            
  56.            
  57.         }, 20, 20);
  58.     }
  59.    
  60.     @SuppressWarnings("deprecation")
  61.     private void detonate()
  62.     {
  63.         for(Player p :Bukkit.getOnlinePlayers())
  64.         {
  65.             p.addPotionEffect(new PotionEffect(PotionEffectType.BLINDNESS, 10, 10));
  66.            
  67.         }
  68.        
  69.         shockwave = Bukkit.getScheduler().scheduleSyncRepeatingTask(pl, new Runnable() {
  70.  
  71.             @Override
  72.             public void run() {
  73.                
  74.                 if(shockw_radius <= 35)
  75.                 {
  76.                     spawnShockwaveCircles(Bukkit.getOnlinePlayers().iterator().next(),loc, shockw_radius);
  77.                     shockw_radius = shockw_radius + 0.5;
  78.                 }else
  79.                 {
  80.                     Bukkit.getScheduler().cancelTask(shockwave);
  81.                 }
  82.                
  83.             }
  84.            
  85.            
  86.            
  87.         }, 0, 1);
  88.        
  89.        
  90.     }
  91.     private List<Double> t = Arrays.asList(-0.2,0.0,0.2,0.4);
  92.     @SuppressWarnings("deprecation")
  93.     private void spawnShockwaveCircles(Player p, Location location, double radius)
  94.     {
  95.         for (double radians = 0;radians < (2*Math.PI); radians+=(Math.PI/180))
  96.         {
  97.             final double radians2 = radians;
  98.             t.parallelStream().forEach((Double t) -> {
  99.                
  100.                 double x = Math.cos(radians2) * (radius - t);
  101.                 double z = Math.sin(radians2)* (radius - t);
  102.                
  103.                
  104.                 location.add(x,0,z);
  105.                 ParticleHandler.send(ParticleHandler.getParameter(Particle.SMOKE_NORMAL, 1, 0, 0, 0),p,(float) location.getX(),(float)location.getY(),(float) location.getZ());
  106.                 location.subtract(x,0,z);
  107.                
  108.             });
  109.            
  110.            
  111.         }
  112.        
  113.        
  114.     }
  115. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement