Solved Getting node from yml

Discussion in 'Spigot Plugin Development' started by Flaquito, Feb 9, 2020.

Thread Status:
Not open for further replies.
  1. Hello. I have a problem. I made a code that create a yml file and put some information about user (like a system login). But now, I save the location when the player die (converting to string, etc.). But, when I press a command to go to that place, it detects as null. When I reload the server it detects the string save it in the yml file.

    Code (Java):
    public Location getStringToLocation(String uuid) {
            if(Config().get(uuid+".m") != null) {
                String key = Config().getString(uuid+".m");
                String[] split = key.split(", ");
                if (split.length == 4){
                    World world = Bukkit.getWorld(split[0]);
                    double x = Double.parseDouble(split[1]);
                    double y = Double.parseDouble(split[2]);
                    double z = Double.parseDouble(split[3]);
                    Location loc = new Location(world, x, y, z);
                    return loc;
                } else {
                    return null;
            }else {
                return null;
    It detects as null, when it really is not null, because it has the location save. When I reload the server, it detects it good and when the player die it detects again as null. Just works when I reload the server and the player has not die again.
  2. drives_a_ford


    First of all, you can just set the Location and use ConfigurationSection#getLocation to get it. No need to reinvent the wheel by creating your own serialization.

    Secondly, it's impossible to tell what's happening since it's not clear what the Config class is. But in any case, you probably don't want to create a new instance of it every time like you're doing here. Just create one instance and use it.

    And finally, to check if a config path has been set, just use ConfigurationSection#isSet. You can also get (and display if you like) the entire section with ConfigurationSection#getConfigurationSection.
    • Agree Agree x 1
Thread Status:
Not open for further replies.