1. Guest, as per the stickied thread, this forum has not been in use since 2014. All bugs and feature requests should be posted to JIRA.

Bug Failing to create a config with UUID and name support

Discussion in 'Bugs & Feature Requests' started by zDrakon, May 15, 2015.

  1. I need help. I am a nooby coder who is trying to make a config file that pastes UUID and username of a player that joins so that I can edit the aspects of my plugin specific to that player.

    Please help!

    Code (Text):
        @Override
        public void onEnable() {
            new ListenerClass(this);
            saveConfig();
        }

        @Override
        public void onDisable(){
            saveConfig();
        }

    @EventHandler
        public void onPlayerJoin(PlayerJoinEvent event){
            String name = event.getPlayer().getName(); //Get name
            String uuid = event.getPlayer().getUniqueId().toString(); //Get UUID
            this.getConfig().options().copyDefaults(true); //I have no idea what this does but apparently it is needed?

            this.getConfig().addDefault("Players.UUID", uuid); //Supposed to paste in uuid
            this.getConfig().addDefault("Player.UUID.name", name); //Supposed to paste in name
        }
     
    It creates a blank Config!

    I wish for it to look like this please help:

    Players:
    UUID: SomeUUID-here-1234-etc
    name: Username
    - feature
     
  2. You have no defaults to copy.

    Where your 'plugin.yml' is. Add a new file, named 'config.yml' and put in your default values. Then in your onEnable() method, use this.saveDefaultConfig(); which will add the provided config.yml if one is not present.

    However, the purpose of your config file will be lost. As it will look like this:

    Code (Text):
    Players:
      UUID: a-uuid-string-1234-5678
        name:  SomePlayer
    Which will get overwritten every time another player joins.
     
  3. How do I make it so that it will make new UUIDs and Names? Instead of overwriting it.
     

  4. Code (Text):
    @Override
        public static void onEnable(){
       
            this.getConfig().saveDefaultConfig();
       
        }

    @EventHandler
        public void onPlayerJoin(PlayerJoinEvent event){
       
       
            String name = event.getPlayer().getName(); //Get name
            String uuid = event.getPlayer().getUniqueId().toString();
            this.getConfig().setString("Players." + uuid  + ".Name", name);//this will basically track the names related to the UUID's of every player that joins.
            this.saveConfig();//saves the values you have set from memory
            this.reloadConfig();//makes the plugin use your new altered config


        }

    I don't have IDE on this computer.. so please excuse any typos. but that SHOULD do the job.

    And add a default config for it to load. just something like this:

    Code (Text):
    Players:
    Your resulting config after players starting logging in should look like this.

    Code (Text):
    Players:
      some-uuid-1234-5678:
        name: SomePlayer1
      some-uuid-1234-5679:
        name: SomePlayer2
      some-uuid-1234-5670:
        name: SomePlayer3
      some-uuid-1234-5671:
        name: SomePlayer4
     
  5. Code (Text):
        @Override
        public void onEnable() {
            new ListenerClass(this);
            this.getConfig().options().copyDefaults(true);
            this.getConfig().createSection("Players");
            saveConfig();
        }

        @Override
        public void onDisable() {
            saveConfig();
           
        }

        @EventHandler
        public void onPlayerJoin(PlayerJoinEvent event) {

            String name = event.getPlayer().getName(); // Get name
            String uuid = event.getPlayer().getUniqueId().toString();
            this.getConfig().set("Players." + uuid + ".Name", name);// this will
                                                                    // basically
                                                                    // track the
                                                                    // names related
                                                                    // to the UUID's
                                                                    // of every
                                                                    // player that
                                                                    // joins.
            this.saveConfig();// saves the values you have set from memory
            this.reloadConfig();// makes the plugin use your new altered config

        }
    Still doesnt work =/. did I do something wrong?
     
  6. you need to change your onEnable method to this:

    Code (Text):
    @Override
        public static void onEnable(){
     
            this.getConfig().saveDefaultConfig();
     
        }
    and include a default config in the same directory as your plugin.yml and it should be named 'config.yml'
     
  7. That method isnt correct but i made it in the on Enable method to have that similar method of saveConfig();
     
  8. how do I add config.yml to plugin.yml?
     
  9. Code (Text):
        @Override
        public void onEnable() {
            new ListenerClass(this);
            this.getConfig().options().copyDefaults(true);
            this.getConfig().createSection("Players");
            this.saveDefaultConfig();
        }

        @Override
        public void onDisable() {
            this.saveDefaultConfig();

        }
    Okay I made it so it does this.saveDefaultconfig();

    Will test if it works soon. -cross fingers-
     
  10. It does not work. Please help someone!
     
  11. Why wont this work!
    Code (Text):
        @EventHandler
        public void onPlayerJoin(PlayerJoinEvent event) {

            String name = event.getPlayer().getName(); // Get name
            String uuid = event.getPlayer().getUniqueId().toString();
            this.getConfig().addDefault("Players.UUID", uuid);
            this.getConfig().addDefault("Players.UUID.name", name);                      
                                                               
            this.saveConfig();// saves the values you have set from memory
            this.reloadConfig();// makes the plugin use your new altered config

        }

        @Override
        public void onEnable() {
            this.saveDefaultConfig();
            this.saveConfig();
           
            this.getConfig().options().copyDefaults(true);
        }

        @Override
        public void onDisable() {
            this.saveDefaultConfig();
            this.saveConfig();

        }