*-= cooldown help! =-*

Discussion in 'Plugin Development' started by BeastCraft3, Nov 17, 2014.

Thread Status:
Not open for further replies.
  1. Offline

    BeastCraft3

    Greetings People, I've made the start of this plugin, now I need help with something. I'm making a plugin which enable pvp for 15 minutes then disable it again.
    the problem is that when they type /pvp start
    i want it to display a cooldown that goes like this:
    1 minute until pvp is enabled!
    30 seconds until pvp is enabled!
    15 seconds until pvp is enabled!
    3 seconds until pvp is enabled!
    then it get enabled for 15 minutes.
    After those minutes it get disabled.
    To enable and disable pvp am using the Bukkit.getConsoleSender().dispatchCommand("Region flag __global__ -w world pvp allow");

    Hope you understand why I need help ;P.
    This is how far I've comed:
    Code:java
    1. package com.DrBeast.PrisonPurge;
    2.  
    3. import java.util.ArrayList;
    4.  
    5. import org.bukkit.Bukkit;
    6. import org.bukkit.command.Command;
    7. import org.bukkit.command.CommandSender;
    8. import org.bukkit.entity.Player;
    9. import org.bukkit.plugin.java.JavaPlugin;
    10.  
    11. public class PrisonPurge extends JavaPlugin{
    12.  
    13. ArrayList<Player> cooldown = new ArrayList<Player>();
    14.  
    15. public void onEnalbe(){
    16.  
    17. }
    18.  
    19. public void onDisable(){
    20.  
    21. }
    22.  
    23. public boolean onCommand(CommandSender sender, Command cmd, String label, String[] args){
    24. if(!(sender instanceof Player)) {
    25. sender.sendMessage("§conly players can use this command");
    26. return true;
    27. }
    28. Player p = (Player) sender;
    29. final Player p2 = (Player) sender;
    30. if(p.getName().equalsIgnoreCase("purge")){
    31. if(p.hasPermission("Purge.start")) {
    32. if(args.length == 0) {
    33. p.sendMessage("§4§m§l|------( §r§6Purge Help §4§m§l)------| ");
    34. p.sendMessage("§8/purge start");
    35. p.sendMessage("§7this command will enable pvp everywhere for 15 minutes.");
    36. p.sendMessage("§4§m§l|------( §r§6Purge Help §4§m§l)------| ");
    37. }else if(args.length < 1) {
    38. if(args[0].equalsIgnoreCase("start")){
    39. if(cooldown.contains(p2)){
    40. p2.sendMessage("§cThis purge is already running!");
    41. } else {
    42. cooldown.add(p2);
    43. Bukkit.getServer().getScheduler().scheduleSyncDelayedTask(this, new Runnable() {
    44. public void run() {
    45. cooldown.remove(p2);
    46. }
    47. }, 18000);
    48.  
    49. }
    50. }
    51. }
    52. }
    53. }
    54. return false;
    55. }
    56.  
    57.  
    58.  
    59. }
    60.  
     
  2. Offline

    mythbusterma

    BeastCraft3

    So uh...make the countdown. I would recommend a state machine inside a repeating runnable, but that's just me.
     
  3. Offline

    BeastCraft3

    mythbusterma
    emm, never heard of it. its a reason why I don't know what to do.
     
  4. Offline

    mythbusterma

  5. Offline

    BeastCraft3

    mythbusterma
    I've read most of the links there. I can't really find any easy solution to my issue. Anyone else can help me?
     
  6. Offline

    mythbusterma

Thread Status:
Not open for further replies.

Share This Page