Solved Halp?

Discussion in 'Plugin Development' started by MordorKing78, Jul 23, 2016.

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

    MordorKing78

    Okay, what I'm trying to do is I'm trying to add a player to a StringList which works fine, but when I check if the player is in the stringlist it doesn't seem to work (after a reload it does), players can now spam it which I don't want them to be able to do.

    Any help is appreciated.

    Code:
        public void requestKingdom(Player p, String requestedKingdom){
            String Kingdom = plugin.config.getString(p.getUniqueId() + ".joinedKingdom");
    
            List<String> requests = plugin.getConfig().getStringList("Kingdoms." + requestedKingdom + ".playerRequests");
           
            if(Kingdom == null){
                if(!requests.contains(p.getName())){
                    requests.add(p.getName());
                    plugin.config.set("Kingdoms." + requestedKingdom + ".playerRequests", requests);
                    plugin.saveCustomYml(plugin.config, plugin.configYml);
                   
                    p.sendMessage(plugin.msg.messageRequestSent);
                    return;
                }else{
                    p.sendMessage(plugin.msg.messageAlreadyRequested);
                    return;
                }
            }else{
                p.sendMessage(plugin.msg.messageAlreadyInKingdom);
                return;
            }
        }
     
  2. @MordorKing78
    Your code seems like it should work, can you give us a bit more detailed description of what actually happens?

    Also, use UUID's for the list, player names can change, UUID's can't.
     
  3. Offline

    MordorKing78

    @AlvinB Well, it doesn't really matter if they change, the leader of the "Kingdom" can decline immediately if they want, but I would not really know what else I could give you, this is what happens:
    1. Player performs command
    2. Player clicks what kingdom they want to send a request to
    3. When clicked they will be added to the StringList and the list will save itself
    4. Now it should be so player can not send another request until they have been declined by the "leader"
    Step 4 does not seem to work.
     
  4. @MordorKing78
    If you do the command, and then go look in the config file, is your name there?

    Also, about the UUID thing, it's more about good practice than actual functionality.
     
  5. Offline

    MordorKing78

    @AlvinB correct, the name is there.

    Yeah, about the UUID, I'll change it in a few, I've already used UUID's for the leaders but I was way to lazy lol. Anyways the name is there but it still sends me the message..
     
  6. @MordorKing78
    What about looping through all the entries in the list when you've loaded it to see if your name is there?
     
  7. Offline

    MordorKing78

    @AlvinB omg, *facepalm*
    I was writing in the wrong config, it's been fixed now. sorry for the inconvenience.

    I'll mark this as solved, thanks for the help tho!
     
  8. Offline

    MordorKing78

  9. Offline

    MordorKing78

    @bwfcwalshy what's up with it? :p
    needs to be lowercase? never really understood the proper naming conventins since I've not had any strugles with them as of yet.
     
  10. @MordorKing78 Yep variables and methods to be camelCase classes need to be UpperCase
     
  11. @MordorKing78
    Variable and method names should be camelCase (first word lowercase, the rest capital letter). In class names, all words should be capital, and in package names everything should be lower case.

    The reason these are in place is that you (and others reading your code) should be able to easily figure out what is what. Example, following the naming conventions, myClass.aMethod() indicates that myClass is an instance of a class, while MyClass.aMethod() would indicate that aMethod() is static, and therefor MyClass is not an instance.
     
  12. Offline

    MordorKing78

Thread Status:
Not open for further replies.

Share This Page