Coding a cooldown using bukkit server time?

Discussion in 'Plugin Development' started by Gawdzahh, Jan 22, 2013.

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

    Gawdzahh

    I'm trying to code a feature where the player can only choose a class every 12 hrs but I dont know how I could do this :p
    My Attempt
    Code:
    if(plugin.getConfig().getLong("players." + player.getDisplayName() + ".lastvote") - plugin.getServer().getWorld("world").getTime() < 864000 && plugin.getConfig().get("players." + player.getDisplayName() + ".lastvote") != null){
                            API.setClass(player, classname);
                            player.sendMessage(ChatColor.GOLD + "" + ChatColor.BOLD + "You have selected the class " + classname + ", You can now spawn into the game!");
                        }else{
                            player.sendMessage(ChatColor.DARK_GREEN + "" + ChatColor.BOLD + "You must vote for the server for this feature! battle-craft.org/vote - battle-craft.org/vote2");
                        }
     
  2. Offline

    camyono

    Dont create threads... Makes no sense. Store the data as metadata / list or in a file and check when the player is doing the event whether the cooldown is gone. :)
     
  3. Offline

    Gawdzahh

    No I'm not going to create a scheduler event for each player :p The way I've done it and i think its working is stored the time the player clicked the time the first time add 12hrs onto it, then check if its greater then the server time.
    Like this
    Code:
    if(plugin.getConfig().getLong("players." + player.getDisplayName() + ".lastvote") + 864000 > plugin.getServer().getWorld("world").getTime() && plugin.getConfig().get("players." + player.getDisplayName() + ".lastvote") != null){
                            API.setClass(player, classname);
                            player.sendMessage(ChatColor.GOLD + "" + ChatColor.BOLD + "You have selected the class " + classname + ", You can now spawn into the game!");
                        }else{
                            player.sendMessage(ChatColor.DARK_GREEN + "" + ChatColor.BOLD + "You must vote for the server for this feature! battle-craft.org/vote - battle-craft.org/vote2");
                        }
     
  4. Offline

    camyono

    Gawdzahh you mean 43200000ms / 43200s / 12h
     
  5. Offline

    gomeow

Thread Status:
Not open for further replies.

Share This Page