[SOLVED] I need help with making a config supporting UUID and name!

Discussion in 'Spigot Help' started by zDrakon, May 19, 2015.

  1. Code (Text):
    @Override
        public void onEnable() {
            this.saveConfig();
            this.getConfig();
        }

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

        }  

    @EventHandler
        public void onJoin(PlayerJoinEvent p) {
            this.getConfig().set("UUID." + p.getPlayer().getUniqueId() + ".Name", p.getPlayer().getName());
        }
    thats my current code. It gives me a blank config even if I /stop my server and check on it! IT DOESNT REFRESH WITH THE PROPER CONFIG OF UUIDs! HELP PLEASE!!!
     
  2. Bump please! help!
     
  3. someone please help me... Im a noob at coding idk i could be making such a simple mistake!
     
  4. bump im in need of desperate help =/
     
  5. Don't forget to convert the UUID to a string with
    .toString()
     
  6. I added .toString() at the end but it still doesn't work.
    Code (Text):
    @EventHandler
        public void onJoin(PlayerJoinEvent p) {
            this.getConfig().set("UUID." + p.getPlayer().getUniqueId() + ".Name", p.getPlayer().getName());
        }
     
  7. Not on that code.
     
  8. Heres my entire code.

    Code (Text):
    package drakoncraft.killstreak;

    import org.bukkit.command.Command;
    import org.bukkit.command.CommandSender;
    import org.bukkit.entity.Player;
    import org.bukkit.event.EventHandler;
    import org.bukkit.event.player.PlayerJoinEvent;
    import org.bukkit.plugin.java.JavaPlugin;

    public class Main extends JavaPlugin {
        @Override
        public void onEnable() {
            getConfig().options().copyDefaults(true);
            saveConfig();
        }

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

        }

        @EventHandler
        public void onJoin(PlayerJoinEvent e) {
            Player p = e.getPlayer();
           
            getConfig().set("UUID." + p.getUniqueId().toString() + ".Name", p.getName());
        }

        public boolean onCommand(CommandSender sender, Command cmd, String label,
                String[] args) {
            if (cmd.getName().equalsIgnoreCase("uuid")) { // If the player typed
                 Player player = (Player) sender;                                  
                 player.sendMessage(getConfig().getString("UUID."));
                return true;
            }
            return false;
        }
    }
     
     
  9. Now i did sorry. How does my code looks so far? I need UUID to work ;_;
     
  10. Think it looks good. Try it out.
     
  11. I tried it... its giving me a blank config still.
     
  12. Working for setting other things in the config?
     
  13. try adding
    Code (Text):
    this.saveConfig();
    after the
    Code (Text):
    getConfig().set()
     
    • Agree Agree x 1
  14. didnt work ;_;
     
  15. Which didn't?
     
  16. How you do this.
    Code (Text):
    import java.util.List;

    import org.bukkit.entity.Player;
    import org.bukkit.event.EventHandler;
    import org.bukkit.event.Listener;
    import org.bukkit.event.player.PlayerJoinEvent;
    import org.bukkit.plugin.java.JavaPlugin;

    public class Main extends JavaPlugin implements Listener {
        @Override
        public void onEnable() {
            this.getServer().getPluginManager().registerEvents(this, this);
            this.saveDefaultConfig();
        }

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

        @EventHandler
        public void onJoin(PlayerJoinEvent e) {

            Player player = e.getPlayer();

            if (player instanceof Player) {
               
                this.getConfig().addDefault("Test", 1); //Here I added something to test.

                List<String> ids = this.getConfig().getStringList("UUIDs");

                this.getConfig().set("UUIDs", ids);
                ids.add(player.getName().toString() + ": " + player.getUniqueId().toString());
                this.getConfig().set("UUIDs", ids);
                this.saveConfig();


            }

        }

    }
    BIG SHOUT OUT TO JKMODZ WHO HELPED WITH THIS ON PM FOR ME! THANK YOU SO MUCH IT WORKS!!!
     
  17. wow just noticed that you never registered your events in your 1st and 2nd
     
  18. Add a "this.saveDefaultConfig();" before the copyDefaults statement in your onEnable method.
     
  19. Crap totally zoomed over the fact that you forgot to register stuff.
     
  20. after all this time... it finally works ;_;