Responding to a Command via Command

Discussion in 'Plugin Development' started by FlipSide_Mike, Jan 6, 2015.

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

    FlipSide_Mike

    I am working on a duel plugin for a friend where if a player does /duel [Name] (Obviously there are other arguments needed), and it sends the target player a message saying "Notch is attempting to duel you, type '/duel accept Notch' to accept" and it expires in 60 seconds.

    I don't know how to set up /duel accept name, I know how to make the command, just not check if the target player typed it in time as well as even respond to the original command!
     
  2. Offline

    bobthefish

    You could maybe add the players to a hashmap or something of the sort when the first player does the command, then when the second player does the command check to see if there is a value in the hashmap for the first player and check to see if it equals the second player, just remember to store player names and not players
     
  3. you forgot about the time

    make a scheduler and the boolean to check if the request is in time
    Code:
        //set the boolean to check if the request is active
        public boolean inTime = false;
        //starts the scheduler
        public void startRequest(){
            //inTime boolean is now true
            inTime = true;
            //after 60 seconds inTime will be false again
            Bukkit.getScheduler().runTaskLater(this, new Runnable(){
    
                @Override
    
                public void run() {
    
                    inTime = false;
    
                }
    
            }, 20*60);
    
        }
    
    just start the startRequest(); void in your command
    for example
    Code:
            if(cmd.getName().equalsIgnoreCase("duel")){
    
                this.startScheduler();
    
            }
    
    in the request command you only have to ask for the "inTime" boolean if its true:
    Code:
    if(inTime == true){
        //do want you want when the request is active
    }
    
    hope this helps :)

    cheers
    sn1cko
     
  4. @sn1cko inTime wouldn't need to be public, you'd want a collection instead of just a boolean - otherwise only one request can be done at a time, and it'll interfere with others, and you don't need to do if(boolean == boolean), if(boolean) is the same thing :)
     
  5. oh thanks (again ;) ) forgot that it's for more than one player haha

    so another method would be to use an arraylist/hashmap and add/remove the player with the scheduler
     
Thread Status:
Not open for further replies.

Share This Page