Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package fr.godofcube.lobby.magic;
- import org.bukkit.Location;
- import org.bukkit.entity.Player;
- import org.bukkit.plugin.java.JavaPlugin;
- import org.bukkit.scheduler.BukkitRunnable;
- import org.bukkit.util.Vector;
- import fr.godofcube.lobby.NMS.ParticleEffect;
- import fr.godofcube.lobby.core.VectorUtils;
- public class Magic {
- static JavaPlugin pl;
- public Magic(JavaPlugin pl) {
- Magic.pl = pl;
- }
- public static void cone(Player player){
- final Location loc = player.getLocation();
- new BukkitRunnable() {
- double t = 0;
- double r = 1.5;
- @Override
- public void run() {
- t += Math.PI/8;
- r -= 0.1;
- double x = r*Math.cos(t);
- double y = 0.5*t;
- double z = r*Math.sin(t);
- double xb = -r*Math.cos(t);
- double zb = -r*Math.sin(t);
- double xc = r*Math.cos(t+Math.PI/2);
- double zc = r*Math.sin(t+Math.PI/2);
- double xd = -r*Math.cos(t+Math.PI/2);
- double zd = -r*Math.sin(t+Math.PI/2);
- loc.add(x, y, z);
- ParticleEffect.FIREWORKS_SPARK.display(0, 0, 0, 0, 5, loc, 100);
- loc.subtract(x, y, z);
- loc.add(xb, y, zb);
- ParticleEffect.FIREWORKS_SPARK.display(0, 0, 0, 0, 5, loc, 100);
- loc.subtract(xb, y, zb);
- loc.add(xc, y, zc);
- ParticleEffect.FIREWORKS_SPARK.display(0, 0, 0, 0, 5, loc, 100);
- loc.subtract(xc, y, zc);
- loc.add(xd, y, zd);
- ParticleEffect.FIREWORKS_SPARK.display(0, 0, 0, 0, 5, loc, 100);
- loc.subtract(xd, y, zd);
- if(r <= 0.4){
- this.cancel();
- }
- }
- }.runTaskTimer(pl, 0, 1);
- }
- public static void shoot(Player player){
- final Location loc = player.getEyeLocation();
- new BukkitRunnable() {
- Vector dir = loc.getDirection().normalize();
- double t = 0;
- @Override
- public void run() {
- t += 1;
- double x = t*dir.getX();
- double y = t*dir.getY();
- double z = t*dir.getZ();
- loc.add(x, y, z);
- ParticleEffect.LAVA.display(0, 0, 0, 0, 5, loc, 10000000);
- if(!loc.getBlock().isEmpty()){
- ParticleEffect.EXPLOSION_NORMAL.display(1, 1, 1, 0, 100, loc, 10000000);
- this.cancel();
- }
- loc.subtract(x, y, z);
- if(t > 100){
- this.cancel();
- }
- }
- }.runTaskTimer(pl, 0, 1);
- }
- public static void spiral(Player player){
- final Location loc = player.getLocation().add(0, 3, 0);
- new BukkitRunnable() {
- double t = 0;
- double r = 3;
- @Override
- public void run() {
- t += Math.PI/8;
- r -= 0.1;
- double x = r*Math.cos(t);
- double z = r*Math.sin(t);
- double xb = -r*Math.cos(t);
- double zb = -r*Math.sin(t);
- double xc = r*Math.cos(t+Math.PI/2);
- double zc = r*Math.sin(t+Math.PI/2);
- double xd = -r*Math.cos(t+Math.PI/2);
- double zd = -r*Math.sin(t+Math.PI/2);
- loc.add(x, 0, z);
- ParticleEffect.FLAME.display(0, 0, 0, 0, 5, loc, 100);
- loc.subtract(x, 0, z);
- loc.add(xb, 0, zb);
- ParticleEffect.FLAME.display(0, 0, 0, 0, 5, loc, 100);
- loc.subtract(xb, 0, zb);
- loc.add(xc, 0, zc);
- ParticleEffect.FLAME.display(0, 0, 0, 0, 5, loc, 100);
- loc.subtract(xc, 0, zc);
- loc.add(xd, 0, zd);
- ParticleEffect.FLAME.display(0, 0, 0, 0, 5, loc, 100);
- loc.subtract(xd, 0, zd);
- if(r <= 0){
- this.cancel();
- }
- }
- }.runTaskTimer(pl, 0, 1);
- }
- public static void tornado(Player player){
- final Location loc = player.getLocation();
- new BukkitRunnable() {
- double t = 0;
- double r = 0;
- @Override
- public void run() {
- t += Math.PI/32;
- r += 0.1;
- double xa = r*Math.cos(t);
- double ya = Math.pow(r, 2);
- double za = r*Math.sin(t);
- double xb = -r*Math.cos(t);
- double zb = -r*Math.sin(t);
- double xc = r*Math.cos(t+Math.PI/2);
- double zc = r*Math.sin(t+Math.PI/2);
- double xd = -r*Math.cos(t+Math.PI/2);
- double zd = -r*Math.sin(t+Math.PI/2);
- loc.add(xa, ya, za);
- ParticleEffect.FLAME.display(0, 0, 0, 0, 100, loc, 100);
- loc.subtract(xa, ya, za);
- loc.add(xb, ya, zb);
- ParticleEffect.FLAME.display(0, 0, 0, 0, 5, loc, 100);
- loc.subtract(xb, ya, zb);
- loc.add(xc, ya, zc);
- ParticleEffect.FLAME.display(0, 0, 0, 0, 5, loc, 100);
- loc.subtract(xc, ya, zc);
- loc.add(xd, ya, zd);
- ParticleEffect.FLAME.display(0, 0, 0, 0, 5, loc, 100);
- loc.subtract(xd, ya, zd);
- if(r > 4){
- this.cancel();
- }
- }
- }.runTaskTimer(pl, 0, 1);
- }
- public static void cover(Player player){
- final Location loc = player.getLocation().add(0, 1, 0);
- new BukkitRunnable() {
- double r = 0;
- @Override
- public void run() {
- r += 0.1*Math.PI;
- for (double theta = 0; theta <= 2*Math.PI; theta = theta + Math.PI/32){
- double x = r*Math.cos(theta);
- double y = 2*Math.exp(-0.1*r) * Math.sin(r) + 1.5;
- double z = r*Math.sin(theta);
- loc.add(x,y,z);
- ParticleEffect.PORTAL.display(0, 0, 0, 0, 1, loc, 100);
- loc.subtract(x,y,z);
- }
- if (r > Math.PI){
- this.cancel();
- }
- }
- }.runTaskTimer(pl, 0, 1);
- }
- public static void pot(Player player){
- final Location loc = player.getLocation();
- new BukkitRunnable() {
- double r = 0;
- @Override
- public void run() {
- r += 0.1;
- for(double theta = 0 ; theta<= Math.PI*2 ; theta += Math.PI/16){
- double x = r*Math.cos(theta);
- double y = Math.pow(r, 2);
- double z = r*Math.sin(theta);
- loc.add(x, y, z);
- ParticleEffect.REDSTONE.display(0, 0, 0, 0, 1, loc, 100);
- loc.subtract(x, y, z);
- }
- if(r > 4){
- this.cancel();
- }
- }
- }.runTaskTimer(pl, 0, 1);
- }
- public static void lookingRotation(Player player){
- final Location loc = player.getEyeLocation();
- final double pitch = Math.toRadians(loc.getPitch() +90.0F);
- final double yaw = Math.toRadians(loc.getYaw());
- new BukkitRunnable() {
- double t;
- double r = 1;
- double time = 0;
- @Override
- public void run() {
- t += Math.PI/8;
- time++;
- double y = 0.5*t;
- double xa = r*Math.cos(t);
- double za = r*Math.sin(t);
- double xb = -r*Math.cos(t);
- double zb = -r*Math.sin(t);
- double xc = r*Math.cos(t+Math.PI/2);
- double zc = r*Math.sin(t+Math.PI/2);
- double xd = -r*Math.cos(t+Math.PI/2);
- double zd = -r*Math.sin(t+Math.PI/2);
- Vector va = new Vector(xa, y, za);
- Vector vb = new Vector(xb, y, zb);
- Vector vc = new Vector(xc, y, zc);
- Vector vd = new Vector(xd, y, zd);
- va = VectorUtils.rotateAroundAxisX(va, pitch);
- va = VectorUtils.rotateAroundAxisY(va, -yaw);
- vb = VectorUtils.rotateAroundAxisX(vb, pitch);
- vb = VectorUtils.rotateAroundAxisY(vb, -yaw);
- vc = VectorUtils.rotateAroundAxisX(vc, pitch);
- vc = VectorUtils.rotateAroundAxisY(vc, -yaw);
- vd = VectorUtils.rotateAroundAxisX(vd, pitch);
- vd = VectorUtils.rotateAroundAxisY(vd, -yaw);
- ParticleEffect.FLAME.display(0, 0, 0, 0, 1, loc.clone().add(va), 10000);
- ParticleEffect.FLAME.display(0, 0, 0, 0, 1, loc.clone().add(vb), 10000);
- ParticleEffect.FLAME.display(0, 0, 0, 0, 1, loc.clone().add(vc), 10000);
- ParticleEffect.FLAME.display(0, 0, 0, 0, 1, loc.clone().add(vd), 10000);
- if(time > 100){
- this.cancel();
- }
- }
- }.runTaskTimer(pl, 0, 1);
- }
- public static void specialBeam(Player player){
- final Location loc = player.getEyeLocation();
- final Vector dir = player.getLocation().getDirection().normalize().multiply(0.2 /* 1 is the speed. */);
- final double pitch = Math.toRadians(loc.getPitch() +90.0F);
- final double yaw = Math.toRadians(loc.getYaw());
- new BukkitRunnable() {
- double t;
- int time = 0;
- @Override
- public void run() {
- double radius = Math.sin(t); // if you want the radius to be bigger simply multiply this by the maximum radius.
- for (double angle = 0; angle < Math.PI * 2; angle += Math.PI / 8) {
- double x = Math.sin(angle) * radius;
- double z = Math.cos(angle) * radius;
- Vector v = new Vector(x, 0, z);
- v = VectorUtils.rotateAroundAxisX(v, pitch); // we have to add 90 to the pitch because, well yeah, for some reason it's coded like that.
- 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.
- ParticleEffect.FIREWORKS_SPARK.display(0, 0, 0, 0, 1, loc.clone().add(v), 1000);
- }
- t += Math.PI / 8;
- time++;
- if (t > Math.PI * 2) t = 0; loc.add(dir);
- if(time > 100){
- this.cancel();
- }
- }
- }.runTaskTimer(pl, 0, 1);
- }
- public static final void startCup(Player player){
- tornado(player);
- pot(player);
- }
- public static final void startGalaxy(Player player){
- cone(player);
- spiral(player);
- cover(player);
- }
- public static final void beam(Player player){
- lookingRotation(player);
- specialBeam(player);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment