Can't get string from custom config

Discussion in 'Plugin Development' started by shohouku, Apr 24, 2014.

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

    shohouku

    I'm trying to get the players message and if the players message already exists in the custom configuration it will send the player a message that it already exists.

    This code here isn't working properly... any ideas? I'v been trying to figure this out for almost 4 hours now.

    Code:java
    1. if(message.equals(guildplayers.get(".Guild", message))) { //not working, not getting the message from the configuration



    Code:java
    1. @EventHandler
    2. public void onPlayerChat(AsyncPlayerChatEvent event) {
    3. String message = event.getMessage();
    4. Player p = event.getPlayer();
    5.  
    6.  
    7. if(buyingguildplayer.contains(p.getName())) {
    8. if(!(message.length() > 6)){
    9. if(message.equals(guildplayers.get(".Guild", message))) {
    10. p.sendMessage(ChatColor.BOLD + "Guild already exists!");
    11. } else {
    12. guildplayers.set(p.getName() + ".Guild", message);
    13. buyingguildplayer.set(p.getName(), null);
    14. p.sendMessage(ChatColor.BOLD + "Your guild has been successfully created!");
    15. takeZen(p, 10500);
    16. }
    17. }else{
    18. p.sendMessage(ChatColor.BOLD + "Guild names can be no longer than 12 characters!");
    19. }
    20.  
    21.  
    22. }
    23.  
    24. }
    25.  
    26.  
     
  2. Offline

    BillyBobJoe168

    It's getConfig().getString("Guild"); Also, you shouldn't have the period in front of Guild.
     
  3. Offline

    shohouku


    Doesn't work :(

    Code:java
    1. if(guildplayers.getString("Guild") != null) {
     
  4. Offline

    BillyBobJoe168

    You sure you are making the confit correctly? It should be getguildplayers() if I am not mistaken. Also, null does not mean empty. Null checkes if the section is there. If you tried just setting guild to null you will find that the section guild will not be there anymore XD
     
  5. Offline

    shohouku


    I will get an error without null. And guildplayers is my custom configuration.

    Code:java
    1. final File Guilds = new File("plugins/PlayerMenu/Guilds.yml");
    2. final FileConfiguration guildplayers = YamlConfiguration.loadConfiguration(Guilds);
     
  6. Offline

    BillyBobJoe168

    Well null doesn't work either..I suggest that right after creating that section, set the string to "empty" or "none" or something like that. Then just check if the string is not "empty" or "none".
     
  7. Offline

    shohouku


    How would that work.......? lol ><

    When the player creates the guild, it will set his name and his string like this:

    TestUser:
    Guild: GodOfKings
     
  8. Offline

    EgyptianKing

    Hey can you paste all of your code?

    If you would post it on pastebin or any other code paste tool that's be great!
    Also give me a paste of your config?
     
  9. Offline

    shohouku


    Full code:

    http://pastebin.com/Zur7Sbkc

    And my config just looks like this:

    Code:java
    1. TestUser:
    2. *SPACE*Guild: GodOfKings
     
Thread Status:
Not open for further replies.

Share This Page