Vinetos

CREER UN PLUGIN BUKKIT #12 - Les Cooldowns

Dec 10th, 2014
756
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.35 KB | None | 0 0
  1. package ep12;
  2.  
  3. import java.util.HashMap;
  4.  
  5. import org.bukkit.Material;
  6. import org.bukkit.Sound;
  7. import org.bukkit.World;
  8. import org.bukkit.command.Command;
  9. import org.bukkit.command.CommandSender;
  10. import org.bukkit.entity.Player;
  11. import org.bukkit.inventory.Inventory;
  12. import org.bukkit.inventory.ItemStack;
  13. import org.bukkit.plugin.java.JavaPlugin;
  14.  
  15. public class Main extends JavaPlugin{
  16.  
  17. public HashMap<String, Long> cooldowns = new HashMap <String, Long>();
  18. public int cooldown = 120;
  19.  
  20. public void add(Player p){
  21. cooldowns.put(p.getName(), System.currentTimeMillis());
  22. }
  23.  
  24.  
  25. public boolean has(Player p){
  26. return cooldowns.containsKey(p.getName()) ? true : false;
  27. }
  28.  
  29.  
  30. public void remove(Player p){
  31. cooldowns.remove(p.getName());
  32. }
  33.  
  34.  
  35. public Long scnd(Player p){
  36. long scndleft = ((cooldowns.get (p.getName()) /1000) + cooldown) - System.currentTimeMillis() / 1000;
  37.  
  38. /* /12 > Ajouter a l'HashMap avec NAME + TEMPS 1
  39. * On recupere le NAME + TEMPS 1
  40. * On ajoute le temps d'attente (cooldown) auquel on suprime le TEMPS 2 (temps actuel)
  41. *
  42. * Name + Temps 1 + Temps d'attente
  43. * Vinetos + 08:29:00 + 120 - 08:30:00 = 1
  44. */
  45. return scndleft;
  46. }
  47.  
  48.  
  49. public Long min(Player p){
  50. long minleft = ((((cooldowns.get (p.getName()) /1000) + cooldown) - System.currentTimeMillis() / 1000) / 60) +1;
  51. return minleft;
  52. }
  53.  
  54.  
  55. public boolean onCommand(CommandSender send, Command cmd, String label, String[] args){
  56. if(!(send instanceof Player)){
  57. send.sendMessage("§cTu dois etre un joueur pour effectuer cette commande !");
  58. }
  59.  
  60. Player p = (Player) send;
  61. Inventory inv = p.getInventory();
  62. ItemStack is = new ItemStack(Material.OBSIDIAN);
  63. World w = p.getWorld();
  64.  
  65. if(cmd.getName().equalsIgnoreCase("12")||send.isOp()){
  66. if(has(p)){
  67. if(scnd(p) <= 0){
  68. remove(p);
  69. return true;
  70. }
  71. if(scnd(p) >= 60){
  72. p.sendMessage("§2Vous devez patientez§4 "+min(p)+" minutes §2!");
  73. return true;
  74. }
  75. if(scnd(p) <= 59){
  76. p.sendMessage("§2Vous devez patientez§4 "+scnd(p)+" secondes §2!");
  77. return true;
  78. }
  79. }else{
  80. inv.addItem(is);
  81. p.sendMessage("§2Vous avez recus un block d'obsidienne !");
  82. w.playSound(p.getLocation(), Sound.ITEM_PICKUP, 10, 1);
  83. add(p);
  84. }
  85.  
  86.  
  87. }
  88.  
  89. return false;
  90.  
  91. }
  92.  
  93. }
Advertisement
Add Comment
Please, Sign In to add comment