Vinetos

CREER UN PLUGIN BUKKIT #13 - Feux d'artifices

Dec 21st, 2014
525
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.22 KB | None | 0 0
  1. package ep13;
  2.  
  3.  
  4. import java.util.ArrayList;
  5.  
  6. import org.bukkit.Bukkit;
  7. import org.bukkit.Color;
  8. import org.bukkit.FireworkEffect;
  9. import org.bukkit.FireworkEffect.Type;
  10. import org.bukkit.command.Command;
  11. import org.bukkit.command.CommandSender;
  12. import org.bukkit.entity.Firework;
  13. import org.bukkit.entity.Player;
  14. import org.bukkit.inventory.meta.FireworkMeta;
  15. import org.bukkit.plugin.java.JavaPlugin;
  16.  
  17. public class Main extends JavaPlugin{
  18.  
  19. /*Voir Episode 8 sur le timer*/
  20. public int tache;
  21. public ArrayList<String> joueurs = new ArrayList <String>();/* On stock un String (chaîne de caractère) qui sera le nom du joueur.*/
  22.  
  23. @SuppressWarnings("deprecation")//On surpime les ligne jaune (avertissement)
  24. public void timer()
  25. {
  26. tache = Bukkit.getServer().getScheduler().scheduleAsyncRepeatingTask(this, new Runnable() {
  27. @Override
  28. public void run() {
  29. for (String s : joueurs){
  30. Player p1 = Bukkit.getPlayer(s);
  31. Firework f = (Firework) p1.getWorld().spawn(p1.getLocation(), Firework.class);
  32. FireworkMeta fm = f.getFireworkMeta();
  33.  
  34. fm.addEffect(FireworkEffect.builder()
  35. .flicker(false)
  36. .trail(true)
  37. .with(Type.BALL_LARGE)
  38. .withColor(Color.AQUA)
  39. .withColor(Color.WHITE)
  40. .withColor(Color.AQUA)
  41. .withColor(Color.WHITE)
  42. .build());
  43. fm.setPower(0);
  44. f.setFireworkMeta(fm);
  45. }
  46.  
  47.  
  48.  
  49. }
  50. }, 0L, 20L);
  51. }
  52.  
  53. @Override
  54. public boolean onCommand(CommandSender sender, Command cmd, String label, String[] args) {
  55. Player p = (Player) sender;
  56. if(cmd.getName().equalsIgnoreCase("f")){
  57. if(!(args.length == 1)){//Si il ya plus ou moin d'un argument
  58. p.sendMessage("§cErreur: §6/f <on/off>: §fPermet d'activer ou désactiver les feux d'artifices.");
  59. return true;
  60. }else{
  61. if(args[0].equalsIgnoreCase("on")){
  62. p.sendMessage("§3Feux d'artifices activés !");
  63. joueurs.add(p.getName());/*On ajoute le joueur a L'ArrayList*/
  64. timer();/*On lance le timer (voir ep8)*/
  65. return true;
  66. }else if(args[0].equalsIgnoreCase("off")){
  67. p.sendMessage("§3Feux d'artifices stopés !");
  68. joueurs.remove(p.getName());
  69. return true;
  70. }
  71. }
  72. }
  73. return true;
  74. }
  75. }
Advertisement
Add Comment
Please, Sign In to add comment