Advertisement
Guest User

Firework Command

a guest
Jul 31st, 2015
244
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.61 KB | None | 0 0
  1. package me.Metie.Command;
  2.  
  3. import java.util.Random;
  4.  
  5. import org.bukkit.Bukkit;
  6. import org.bukkit.Color;
  7. import org.bukkit.FireworkEffect;
  8. import org.bukkit.FireworkEffect.Type;
  9. import org.bukkit.Location;
  10. import org.bukkit.command.Command;
  11. import org.bukkit.command.CommandExecutor;
  12. import org.bukkit.command.CommandSender;
  13. import org.bukkit.entity.EntityType;
  14. import org.bukkit.entity.Firework;
  15. import org.bukkit.entity.Player;
  16. import org.bukkit.inventory.meta.FireworkMeta;
  17.  
  18. public class fireworkCommand implements CommandExecutor {
  19.  
  20. @SuppressWarnings("deprecation")
  21. public boolean onCommand(CommandSender sender, Command command, String label, String[] args) {
  22. if (args.length == 1)
  23. for (Player p : Bukkit.getOnlinePlayers())
  24. if (args[0].equals(p.getName())) {
  25. SpawnFirework(p.getLocation());
  26. return true;
  27. }
  28. return true;
  29. }
  30.  
  31. public static void SpawnFirework(Location loc) {
  32. Firework fw = (Firework) loc.getWorld().spawnEntity(loc, EntityType.FIREWORK);
  33. FireworkMeta fwm = fw.getFireworkMeta();
  34. Random r = new Random();
  35. FireworkEffect effect = FireworkEffect.builder().flicker(r.nextBoolean()).flicker(r.nextBoolean()).flicker(r.nextBoolean()).flicker(r.nextBoolean()).flicker(r.nextBoolean()).withColor(getColor()).withFade(getColor()).withColor(getColor()).withFade(getColor()).withColor(getColor()).withFade(getColor()).withColor(getColor()).withFade(getColor()).with(getType()).trail(r.nextBoolean()).with(getType()).trail(r.nextBoolean()).with(getType()).trail(r.nextBoolean()).with(getType()).trail(r.nextBoolean()).with(getType()).trail(r.nextBoolean()).build();
  36. fwm.addEffect(effect);
  37. fwm.setPower(1);
  38. fw.setFireworkMeta(fwm);
  39. }
  40.  
  41. private static Type getType() {
  42. int i = new Random().nextInt(5) + 1;
  43. if (i == 1) return Type.BALL;
  44. if (i == 2) return Type.BALL_LARGE;
  45. if (i == 3) return Type.BURST;
  46. if (i == 4) return Type.CREEPER;
  47. return Type.STAR;
  48. }
  49.  
  50. private static Color getColor() {
  51. int i = new Random().nextInt(16);
  52. if(i==1) return Color.AQUA;
  53. if(i==2) return Color.BLACK;
  54. if(i==3)return Color.BLUE;
  55. if(i==4) return Color.FUCHSIA;
  56. if(i==5) return Color.GRAY;
  57. if(i==6)return Color.GREEN;
  58. if(i==7)return Color.LIME;
  59. if(i==8)return Color.MAROON;
  60. if(i==9)return Color.NAVY;
  61. if(i==10)return Color.OLIVE;
  62. if(i==11)return Color.ORANGE;
  63. if(i==12)return Color.PURPLE;
  64. if(i==13)return Color.RED;
  65. if(i==14)return Color.SILVER;
  66. if(i==15)return Color.TEAL;
  67. if(i==16)return Color.WHITE;
  68. return Color.YELLOW;
  69. }
  70.  
  71.  
  72. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement