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
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.
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 // Command stuff here, involving /friend and /friend accept// Lets pretend your yml file variable is named friends public void addFriend(String name1, String name2) {reloadFriends();String[] blank = {};if(friends.getStringList(name1) == null) {friends.set(name1 + ".Friends", Arrays.asList(blank);}if(friends.getStringList(name2) == null) {friends.set(name2 + ".Friends", Arrays.asList(blank);} List<String> name1Friends = friends.get(name1 + ".Friends");name1Friends.add(name2);friends.set(name1 + ".Friends", name1Friends); List<String> name2Friends = friends.get(name2 + ".Friends");name2Friends.add(name1);friends.set(name2 + ".Friends", name2Friends); saveFriends();} Might have to tweak a little, in a hurry and wrote it off the top of my head.
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."
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)