[Solved]Help with Getting config file path

Discussion in 'Spigot Plugin Development' started by SammySpicer, Jul 10, 2015.

  1. Hello,
    I'm having a little bit of trouble with getting the paths of entries inside my config.
    This is what it looks like:
    Code (Text):
    config:
      yml: {}
    CraftPlayer{name=SammySpicer}Points: 5
    CraftPlayer{name=Xdrasimo}Points: 2
    I need to know the path so I can load the Points for each player when they log in.
    The current path that I'm using executes the else statement in my conditional.
    This is the current code:

    Code (Text):
        @EventHandler
        public void onJoin(PlayerJoinEvent e) {
            String p = e.getPlayer().toString();

            if (!Rating.containsKey(p)) {  
                    if (getConfig().contains(p)) {
                        Rating.put(p, getConfig().getInt(p));
                    }else {
                        Rating.put(p, 2);
                    }

            }
                    }
    Any help would be much appreciated.

    Edit:
    [Solved] -
    Code (Text):
        public void onJoin(PlayerJoinEvent e) {

            String p = e.getPlayer().toString();




            if (!Rating.containsKey(p)) {  

                    if (getConfig().contains("config.yml." + p)) {

                        Rating.put(p, getConfig().getInt("config.yml." + p));

                    }else {

                        Rating.put(p, 2);

                    }




            }
     
    #1 SammySpicer, Jul 10, 2015
    Last edited: Jul 11, 2015
  2. What I would recommend to do, is instead of saving the name you save the uuid (name changes and stuff), so instead of setting p =
    e.getPlayer().toString();
    set it to
    e.getPlayer().getUniqueId().toString();
    and use that also when saving and it should work.
     
    • Agree Agree x 1