{I Need help}!! :{ 5 second count down sent to targetplayer

Discussion in 'Plugin Development' started by coolmonkeyguy, Jun 3, 2013.

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

    coolmonkeyguy

    Hello I tried posting this before but never got a response, so ill try again.

    I need a command that when typed it sends a message to the targetplayer that says
    5....4....3....2....1

    But i need 1 second between each number so it does not just print on the screen at once.

    The code i have now works but does not have 1 second between each number:

    please help
    Code:
    public boolean onCommand(CommandSender sender, Command cmd, String CommandLabel, String[] args) {
         
          if (CommandLabel.equalsIgnoreCase("bbsword")) {
              }
                  if(args.length == 1) {
                        Player player = (Player) sender;
                        if(player.hasPermission("BBJailGuard.sword")){
                      Player targetPlayer = player.getServer().getPlayer(args[0]);
                    player.sendMessage(ChatColor.GREEN + "Message sent to" + " " + ChatColor.GRAY + targetPlayer);
                      targetPlayer.sendMessage(ChatColor.RED + "[BBJailGuard]"+ " " +  ChatColor.GOLD + "Please Give your Sword to " + player + ChatColor.GOLD + "You have 5 Seconds or Jail");
                      targetPlayer.sendMessage(ChatColor.RED + "[BBJailGuard]"+ " " + ChatColor.GOLD + " 5... " );
                      targetPlayer.sendMessage(" ");
                      targetPlayer.sendMessage(ChatColor.RED + "[BBJailGuard]"+ " " + ChatColor.GOLD + " 4... " );
                      targetPlayer.sendMessage(" ");
                      targetPlayer.sendMessage(ChatColor.RED + "[BBJailGuard]"+ " " + ChatColor.GOLD + " 3... " );
                      targetPlayer.sendMessage(" ");
                      targetPlayer.sendMessage(ChatColor.RED + "[BBJailGuard]"+ " " + ChatColor.GOLD + " 2... " );
                      targetPlayer.sendMessage(" ");
                      targetPlayer.sendMessage(ChatColor.RED + "[BBJailGuard]"+ " " + ChatColor.GOLD + " 1... " );
                     
                      player.sendMessage(ChatColor.GREEN + "Count down finished");
                     
                        }
     
  2. Online

    timtower Moderator Moderator

    coolmonkeyguy Create an bukkitrunnable that runs every 20 ticks, give it an variabele of number of seconds left, if the number is 0 then cancel itself so it dies
     
  3. Offline

    coolmonkeyguy

    How would i do this? could u possibly show the code and where to place it in my code?
     
  4. Offline

    zeeveener

    Pseudo: (Inside the runnable)


     
  5. Online

    timtower Moderator Moderator

    Give me couple sec ;)
    EDIT: See post above this one
     
  6. Offline

    CluelessDev



    Code:
    int taskID;// - This definition should be an attribute of the class you're working with.
     
    taskID = plugin.getServer().getScheduler().scheduleSyncRepeatingTask(plugin, new Runnable()
    {
        int count = 5;
        @Override
        public void run()
        {
            player.sendMessage(count + "...");
            count--;
            if(count == 0)
            {
                cancelTask();
            }
        }
    }, 0, 20);
     
    private void cancelTask()
    {
        plugin.getServer().getScheduler().cancelTask(taskID);
    }
    There's probably a more elegant way to do it, but this one at least works. Basically define int taskID as an attribute of the class that is handling your command, make the private cancel task method, and then use the taskID = plugin.getServer... section instead of all the messages.
     
  7. Offline

    goodstuff20

    coolmonkeyguy I always use the normal runnable from java - works fine for me - allot of people do complain though and say its wrong :D
     
  8. Offline

    coolmonkeyguy

    Ok so i got every thing to work but in my code targetPlayer shows in that chat as "Craftplayer{name=Coolmonkeyguy]" how do i make it simply say "Coolmonkeyguy" ?
     
  9. Offline

    zeeveener

    coolmonkeyguy

    Instead of passing "player" into the chat, pass "player.getName()"
     
Thread Status:
Not open for further replies.

Share This Page