Vinetos

Bukkit Dev' | #8 - Timers & Sons

Oct 25th, 2014
854
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.27 KB | None | 0 0
  1. import org.bukkit.Bukkit;
  2. import org.bukkit.ChatColor;
  3. import org.bukkit.Sound;
  4. import org.bukkit.World;
  5. import org.bukkit.command.Command;
  6. import org.bukkit.command.CommandSender;
  7. import org.bukkit.entity.Player;
  8. import org.bukkit.plugin.java.JavaPlugin;
  9.  
  10. public class JaiLaClass extends JavaPlugin {
  11. //Timer
  12.  
  13. public int tache;//Nom de la tache
  14. public int compte = 10;//Compte de la tache
  15. @SuppressWarnings("deprecation")//On enlever les soulignements jaunes!
  16. public void timer()
  17. {
  18. tache = Bukkit.getServer().getScheduler().scheduleAsyncRepeatingTask(this, new Runnable() {
  19.  
  20. @Override
  21. public void run() {
  22. if(compte <= 0){//Si le compte est a zero ou plus petit
  23. Bukkit.broadcastMessage("§2Le timer est §cterminé §2!");//On envoie un message aux joueurs
  24. Bukkit.getServer().getScheduler().cancelTask(tache);//On stop la tache.
  25. }else{
  26. Bukkit.broadcastMessage("§2Le timer est à "+ChatColor.RED+compte+" §2secondes !"); //On envoie un message a
  27. //tous le serveur pour dire combien de temps il reste!
  28. compte--;// On enleve 1 a compte | On peut enlever plus avec "compte -= Nombre;"
  29. }
  30.  
  31.  
  32. }
  33. }, 20L, 20L);//Temps (en ticks) de declanchement , Temps (en ticks) de repetition! 20ticks = 1 Secondes
  34. }
  35.  
  36.  
  37.  
  38.  
  39. //Commandes
  40. public boolean onCommand(CommandSender sender, Command cmd, String label, String[]args)
  41. {
  42. Player p = (Player) sender;
  43. World w = p.getWorld();//On recupere le monde du joueur
  44.  
  45. if(cmd.getName().equalsIgnoreCase("timer"))
  46. {
  47. timer();//On lance le timer
  48.  
  49. }else if(cmd.getName().equalsIgnoreCase("pling"))
  50. {
  51. w.playSound(p.getLocation(), Sound.NOTE_PLING, 10, 1);//On joue un son au joueur qui tape la commande
  52. //le nombre "1" a la fin defini la hauteur du son (do, ré, mi, fa, sol...)
  53. }else if(cmd.getName().equalsIgnoreCase("ender"))
  54. {
  55. w.playSound(p.getLocation(), Sound.ENDERMAN_TELEPORT, 10, 1);
  56.  
  57. }else if(cmd.getName().equalsIgnoreCase("piano"))
  58. {
  59. w.playSound(p.getLocation(), Sound.NOTE_PIANO, 10, 1);
  60.  
  61. }else if(cmd.getName().equalsIgnoreCase("loup"))
  62. {
  63. w.playSound(p.getLocation(), Sound.WOLF_WHINE, 10, 1);
  64. }
  65. return true;//On retourne true pour dir que les commandes sont fini et réinitialisées!
  66. }
  67.  
  68.  
  69. }
Advertisement
Add Comment
Please, Sign In to add comment