How to create pending invitation? Need little help.

Discussion in 'Plugin Development' started by Ibas, May 24, 2013.

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

    Ibas

    Hello,

    I have created command /invite [nick] and I have little question, how to create pending invitation? If admin would write /invite [nick] then player called [nick] would have 1 minute to write /no or /yes
     
  2. Offline

    Malikk

    I would keep a hashset (or map depending on if what you're inviting them to is single instance or if you would need more information stored) of player names who have been invited with a command. Then when a player accepts the invitation, remove them from the list and do whatever.

    As for making it time out, you could either run a scheduler that clears names after the allotted time, or save what time they were invited and check to make sure it's still valid when they try to accept it. Probably the second way is better for server load

    Something this simple you should not have to be spoon fed.

    Here's some basics on hashSets
    Code:
    //Create a new HashSet
    HashSet<String> invites = new HashSet<String>();
     
    //Add an element
    invites.add("nick");
     
    //Check if it contains an element
    boolean invitedNick = invites.contains("nick");
     
    //remove an element
    invites.remove("nick");
    
    So, when you want to invite a player you would add them to the HashSet.

    When a player attempts to respond to an invitation, you would check if they are in the set.

    And once you're finished with them you would remove them from the set.

    If you have any specific questions, let me know. I'm watching this thread so you don't have to PM me. Posting your own code is much better than me doing this from scratch.

    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
    Last edited by a moderator: Jun 1, 2016
Thread Status:
Not open for further replies.

Share This Page