Friend Requesting

Discussion in 'Plugin Development' started by Giorgio, Dec 4, 2012.

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

    Giorgio

    Hello everyone, If you don't know a lot about Bukkit Coding don't waste your time reading this

    Question: If a player sends another player a request to be there friends for example /friend <user>. The user who is receiving the request will then be asked to be friends with this person. How would I be able to do so? I know it has to do with Hash maps, but say if the user that is sending the requested wants to send it to another user. How would I be able to add multiple hash maps for each user then send a request to?

    Example: Sender: /friend giorgio408
    Reciever: /friendaccept giorgio408
    Reciever: /frienddenied giorgio408

    NOTE: I'm more of a Visual Learner
     
  2. Offline

    Tirelessly

    Code:
    HashMap<String, Set<String>> requests = new HashMap<String, Set<String>>();
    
    Then get their set when they get added and put it in their set, or something like that.
     
  3. Offline

    Giorgio

    Tirelessly

    I said i know how to define a hash map, and what you said made no sense?
     
  4. Offline

    Tirelessly

    When someone gets added.... Get their set<string>.... and add the requesters name to it...
     
  5. Offline

    Tehmaker

    Hashmaps however reset upon a reload, or a restart...
     
  6. Offline

    ZeusAllMighty11 Retired Staff


    Easy solution just use the YAML api bukkit has to store it to a file, nice and clean too.
     
  7. Offline

    Tehmaker

    Yeah, I was just pointing it out for him :p
     
  8. Offline

    RealDope

    I suggest storing it in a string list in a yml so it doesn't reset on reloads / restarts.
    Use this guide to setup the basic parts of yml:
    http://wiki.bukkit.org/Configuration_API_Reference

    Then once you have that setup, do this:

    Code:JAVA
    1.  
    2. // Command stuff here, involving /friend and /friend accept
    3. // Lets pretend your yml file variable is named friends
    4.  
    5. public void addFriend(String name1, String name2) {
    6. reloadFriends();
    7. String[] blank = {};
    8. if(friends.getStringList(name1) == null) {
    9. friends.set(name1 + ".Friends", Arrays.asList(blank);
    10. }
    11. if(friends.getStringList(name2) == null) {
    12. friends.set(name2 + ".Friends", Arrays.asList(blank);
    13. }
    14.  
    15. List<String> name1Friends = friends.get(name1 + ".Friends");
    16. name1Friends.add(name2);
    17. friends.set(name1 + ".Friends", name1Friends);
    18.  
    19. List<String> name2Friends = friends.get(name2 + ".Friends");
    20. name2Friends.add(name1);
    21. friends.set(name2 + ".Friends", name2Friends);
    22.  
    23. saveFriends();
    24. }
    25.  


    Might have to tweak a little, in a hurry and wrote it off the top of my head.
     
  9. Offline

    Tirelessly

    Or you can just save the map onDisable...
     
  10. Offline

    Giorgio

    Well what im planning on doing is, just using hashmap as a way for the player not to spam other players, a friend request. Once the request has been confirmed it will then store it in the senders yml data, categorized under "friends: ." When I get better with coding i will then simply add Database features.

    This is for a new plugin I'm making called "Facebook."
     
  11. Offline

    Terradominik

    Because i read you other thread i think i know what you want...

    Just add a field called "Friend-Requests" or something like that in the config of the player. So if playerA sends playerB a friend request, playerA's name is saved in playerB's "Friend-Requests"-field, if playerB is online ihe also get a message or something like that. If playerB enters the acceptrequest command, it will check if there is a request in his file and if there is one with the same on it will delete it and write the players name in the friends field.

    I think this is the only efficiant way with not losing the requests on each restart and its also simpler (unless you are working with databases)
     
  12. Offline

    Giorgio

    Terradominik

    I agree, but I do not know how to use this type of method.
     
Thread Status:
Not open for further replies.

Share This Page