axicer

Magic

Feb 27th, 2016
83
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 9.10 KB | None | 0 0
  1. package fr.godofcube.lobby.magic;
  2.  
  3. import org.bukkit.Location;
  4. import org.bukkit.entity.Player;
  5. import org.bukkit.plugin.java.JavaPlugin;
  6. import org.bukkit.scheduler.BukkitRunnable;
  7. import org.bukkit.util.Vector;
  8.  
  9. import fr.godofcube.lobby.NMS.ParticleEffect;
  10. import fr.godofcube.lobby.core.VectorUtils;
  11.  
  12. public class Magic {
  13.     static JavaPlugin pl;
  14.     public Magic(JavaPlugin pl) {
  15.         Magic.pl = pl;
  16.     }
  17.     public static void cone(Player player){
  18.         final Location loc = player.getLocation();
  19.         new BukkitRunnable() {
  20.             double t = 0;
  21.             double r = 1.5;
  22.             @Override
  23.             public void run() {
  24.                 t += Math.PI/8;
  25.                 r -= 0.1;
  26.                 double x = r*Math.cos(t);
  27.                 double y = 0.5*t;
  28.                 double z = r*Math.sin(t);
  29.                 double xb = -r*Math.cos(t);
  30.                 double zb = -r*Math.sin(t);
  31.                 double xc = r*Math.cos(t+Math.PI/2);
  32.                 double zc = r*Math.sin(t+Math.PI/2);
  33.                 double xd = -r*Math.cos(t+Math.PI/2);
  34.                 double zd = -r*Math.sin(t+Math.PI/2);
  35.                 loc.add(x, y, z);
  36.                 ParticleEffect.FIREWORKS_SPARK.display(0, 0, 0, 0, 5, loc, 100);
  37.                 loc.subtract(x, y, z);
  38.                 loc.add(xb, y, zb);
  39.                 ParticleEffect.FIREWORKS_SPARK.display(0, 0, 0, 0, 5, loc, 100);
  40.                 loc.subtract(xb, y, zb);
  41.                 loc.add(xc, y, zc);
  42.                 ParticleEffect.FIREWORKS_SPARK.display(0, 0, 0, 0, 5, loc, 100);
  43.                 loc.subtract(xc, y, zc);
  44.                 loc.add(xd, y, zd);
  45.                 ParticleEffect.FIREWORKS_SPARK.display(0, 0, 0, 0, 5, loc, 100);
  46.                 loc.subtract(xd, y, zd);
  47.                 if(r <= 0.4){
  48.                     this.cancel();
  49.                 }
  50.             }
  51.         }.runTaskTimer(pl, 0, 1);
  52.     }
  53.     public static void shoot(Player player){
  54.         final Location loc = player.getEyeLocation();
  55.         new BukkitRunnable() {
  56.             Vector dir = loc.getDirection().normalize();
  57.             double t = 0;
  58.             @Override
  59.             public void run() {
  60.                 t += 1;
  61.                 double x = t*dir.getX();
  62.                 double y = t*dir.getY();
  63.                 double z = t*dir.getZ();
  64.                 loc.add(x, y, z);
  65.                 ParticleEffect.LAVA.display(0, 0, 0, 0, 5, loc, 10000000);
  66.                 if(!loc.getBlock().isEmpty()){
  67.                     ParticleEffect.EXPLOSION_NORMAL.display(1, 1, 1, 0, 100, loc, 10000000);
  68.                     this.cancel();
  69.                 }
  70.                 loc.subtract(x, y, z);
  71.                 if(t > 100){
  72.                     this.cancel();
  73.                 }
  74.             }
  75.         }.runTaskTimer(pl, 0, 1);
  76.     }
  77.     public static void spiral(Player player){
  78.         final Location loc = player.getLocation().add(0, 3, 0);
  79.         new BukkitRunnable() {
  80.             double t = 0;
  81.             double r = 3;
  82.             @Override
  83.             public void run() {
  84.                 t += Math.PI/8;
  85.                 r -= 0.1;
  86.                 double x = r*Math.cos(t);
  87.                 double z = r*Math.sin(t);
  88.                 double xb = -r*Math.cos(t);
  89.                 double zb = -r*Math.sin(t);
  90.                 double xc = r*Math.cos(t+Math.PI/2);
  91.                 double zc = r*Math.sin(t+Math.PI/2);
  92.                 double xd = -r*Math.cos(t+Math.PI/2);
  93.                 double zd = -r*Math.sin(t+Math.PI/2);
  94.                 loc.add(x, 0, z);
  95.                 ParticleEffect.FLAME.display(0, 0, 0, 0, 5, loc, 100);
  96.                 loc.subtract(x, 0, z);
  97.                 loc.add(xb, 0, zb);
  98.                 ParticleEffect.FLAME.display(0, 0, 0, 0, 5, loc, 100);
  99.                 loc.subtract(xb, 0, zb);
  100.                 loc.add(xc, 0, zc);
  101.                 ParticleEffect.FLAME.display(0, 0, 0, 0, 5, loc, 100);
  102.                 loc.subtract(xc, 0, zc);
  103.                 loc.add(xd, 0, zd);
  104.                 ParticleEffect.FLAME.display(0, 0, 0, 0, 5, loc, 100);
  105.                 loc.subtract(xd, 0, zd);
  106.                 if(r <= 0){
  107.                     this.cancel();
  108.                 }
  109.             }
  110.         }.runTaskTimer(pl, 0, 1);
  111.     }
  112.     public static void tornado(Player player){
  113.         final Location loc = player.getLocation();
  114.         new BukkitRunnable() {
  115.             double t = 0;
  116.             double r = 0;
  117.             @Override
  118.             public void run() {
  119.                 t += Math.PI/32;
  120.                 r += 0.1;
  121.                 double xa = r*Math.cos(t);
  122.                 double ya = Math.pow(r, 2);
  123.                 double za = r*Math.sin(t);
  124.                 double xb = -r*Math.cos(t);
  125.                 double zb = -r*Math.sin(t);
  126.                 double xc = r*Math.cos(t+Math.PI/2);
  127.                 double zc = r*Math.sin(t+Math.PI/2);
  128.                 double xd = -r*Math.cos(t+Math.PI/2);
  129.                 double zd = -r*Math.sin(t+Math.PI/2);
  130.                 loc.add(xa, ya, za);
  131.                 ParticleEffect.FLAME.display(0, 0, 0, 0, 100, loc, 100);
  132.                 loc.subtract(xa, ya, za);
  133.                 loc.add(xb, ya, zb);
  134.                 ParticleEffect.FLAME.display(0, 0, 0, 0, 5, loc, 100);
  135.                 loc.subtract(xb, ya, zb);
  136.                 loc.add(xc, ya, zc);
  137.                 ParticleEffect.FLAME.display(0, 0, 0, 0, 5, loc, 100);
  138.                 loc.subtract(xc, ya, zc);
  139.                 loc.add(xd, ya, zd);
  140.                 ParticleEffect.FLAME.display(0, 0, 0, 0, 5, loc, 100);
  141.                 loc.subtract(xd, ya, zd);
  142.                 if(r > 4){
  143.                     this.cancel();
  144.                 }
  145.             }
  146.         }.runTaskTimer(pl, 0, 1);
  147.     }
  148.     public static void cover(Player player){
  149.         final Location loc = player.getLocation().add(0, 1, 0);
  150.         new BukkitRunnable() {
  151.             double r = 0;
  152.             @Override
  153.             public void run() {
  154.                 r += 0.1*Math.PI;
  155.                 for (double theta = 0; theta <= 2*Math.PI; theta = theta + Math.PI/32){
  156.                         double x = r*Math.cos(theta);
  157.                         double y = 2*Math.exp(-0.1*r) * Math.sin(r) + 1.5;
  158.                         double z = r*Math.sin(theta);
  159.                         loc.add(x,y,z);
  160.                         ParticleEffect.PORTAL.display(0, 0, 0, 0, 1, loc, 100);
  161.                         loc.subtract(x,y,z);
  162.                 }
  163.                 if (r > Math.PI){
  164.                     this.cancel();
  165.                 }
  166.             }
  167.         }.runTaskTimer(pl, 0, 1);
  168.     }
  169.     public static void pot(Player player){
  170.         final Location loc = player.getLocation();
  171.         new BukkitRunnable() {
  172.             double r = 0;
  173.             @Override
  174.             public void run() {
  175.                 r += 0.1;
  176.                 for(double theta = 0 ; theta<= Math.PI*2 ; theta += Math.PI/16){
  177.                     double x = r*Math.cos(theta);
  178.                     double y = Math.pow(r, 2);
  179.                     double z = r*Math.sin(theta);
  180.                     loc.add(x, y, z);
  181.                     ParticleEffect.REDSTONE.display(0, 0, 0, 0, 1, loc, 100);
  182.                     loc.subtract(x, y, z);
  183.                 }
  184.                 if(r > 4){
  185.                     this.cancel();
  186.                 }
  187.             }
  188.         }.runTaskTimer(pl, 0, 1);
  189.     }
  190.     public static void lookingRotation(Player player){
  191.         final Location loc = player.getEyeLocation();
  192.         final double pitch = Math.toRadians(loc.getPitch() +90.0F);
  193.         final double yaw = Math.toRadians(loc.getYaw());
  194.         new BukkitRunnable() {
  195.             double t;
  196.             double r = 1;
  197.             double time = 0;
  198.             @Override
  199.             public void run() {
  200.                 t += Math.PI/8;
  201.                 time++;
  202.                 double y = 0.5*t;
  203.                 double xa = r*Math.cos(t);
  204.                 double za = r*Math.sin(t);
  205.                 double xb = -r*Math.cos(t);
  206.                 double zb = -r*Math.sin(t);
  207.                 double xc = r*Math.cos(t+Math.PI/2);
  208.                 double zc = r*Math.sin(t+Math.PI/2);
  209.                 double xd = -r*Math.cos(t+Math.PI/2);
  210.                 double zd = -r*Math.sin(t+Math.PI/2);
  211.                 Vector va = new Vector(xa, y, za);
  212.                 Vector vb = new Vector(xb, y, zb);
  213.                 Vector vc = new Vector(xc, y, zc);
  214.                 Vector vd = new Vector(xd, y, zd);
  215.                
  216.                 va = VectorUtils.rotateAroundAxisX(va, pitch);
  217.                 va = VectorUtils.rotateAroundAxisY(va, -yaw);
  218.                
  219.                 vb = VectorUtils.rotateAroundAxisX(vb, pitch);
  220.                 vb = VectorUtils.rotateAroundAxisY(vb, -yaw);
  221.                
  222.                 vc = VectorUtils.rotateAroundAxisX(vc, pitch);
  223.                 vc = VectorUtils.rotateAroundAxisY(vc, -yaw);
  224.                
  225.                 vd = VectorUtils.rotateAroundAxisX(vd, pitch);
  226.                 vd = VectorUtils.rotateAroundAxisY(vd, -yaw);
  227.                
  228.                 ParticleEffect.FLAME.display(0, 0, 0, 0, 1, loc.clone().add(va), 10000);
  229.                 ParticleEffect.FLAME.display(0, 0, 0, 0, 1, loc.clone().add(vb), 10000);
  230.                 ParticleEffect.FLAME.display(0, 0, 0, 0, 1, loc.clone().add(vc), 10000);
  231.                 ParticleEffect.FLAME.display(0, 0, 0, 0, 1, loc.clone().add(vd), 10000);
  232.                 if(time > 100){
  233.                     this.cancel();
  234.                 }
  235.             }
  236.         }.runTaskTimer(pl, 0, 1);
  237.     }
  238.     public static void specialBeam(Player player){
  239.         final Location loc = player.getEyeLocation();
  240.         final Vector dir = player.getLocation().getDirection().normalize().multiply(0.2 /* 1 is the speed. */);
  241.         final double pitch = Math.toRadians(loc.getPitch() +90.0F);
  242.         final double yaw = Math.toRadians(loc.getYaw());
  243.         new BukkitRunnable() {
  244.             double t;
  245.             int time = 0;
  246.             @Override
  247.             public void run() {
  248.                 double radius = Math.sin(t); // if you want the radius to be bigger simply multiply this by the maximum radius.
  249.                 for (double angle = 0; angle < Math.PI * 2; angle += Math.PI / 8) {
  250.                     double x = Math.sin(angle) * radius;
  251.                     double z = Math.cos(angle) * radius;
  252.                     Vector v = new Vector(x, 0, z);
  253.                     v = VectorUtils.rotateAroundAxisX(v, pitch); // we have to add 90 to the pitch because, well yeah, for some reason it's coded like that.
  254.                     v = VectorUtils.rotateAroundAxisY(v, -yaw); // we put the - there because otherwise the animation doesn't work properly :p there might be                                                                                  // another way but I simply do that.
  255.                     ParticleEffect.FIREWORKS_SPARK.display(0, 0, 0, 0, 1, loc.clone().add(v), 1000);
  256.                 }
  257.                 t += Math.PI / 8;
  258.                 time++;
  259.                 if (t > Math.PI * 2) t = 0; loc.add(dir);
  260.                 if(time > 100){
  261.                     this.cancel();
  262.                 }
  263.             }
  264.         }.runTaskTimer(pl, 0, 1);
  265.     }
  266.     public static final void startCup(Player player){
  267.         tornado(player);
  268.         pot(player);
  269.     }
  270.     public static final void startGalaxy(Player player){
  271.         cone(player);
  272.         spiral(player);
  273.         cover(player);
  274.     }
  275.     public static final void beam(Player player){
  276.         lookingRotation(player);
  277.         specialBeam(player);
  278.     }
  279. }
Advertisement
Add Comment
Please, Sign In to add comment