Solved How to display in chat

Discussion in 'Spigot Plugin Development' started by Hortexel, Feb 11, 2020.

  1. Hi, i have a problem :/

    I would like to do a command that checks the configuration of each player
    The configuration looks like this:

    Code (YAML):

    NICK1
    :
      Location
    :
        world
    : world
        x
    : 183.90761971887937
        y
    : 72.0
        z
    : 89.03158433428143
        pitch
    : -29.70112
        yaw
    : 311.38776
    NICK2
    :
      Location
    :
        world
    : world
        x
    : 183.90761971887937
        y
    : 72.0
        z
    : 89.03158433428143
        pitch
    : -29.70112
        yaw
    : 311.38776

     
    I would like to ask how to do it after entering the /info <player>. The Location section has been displayed
     
  2. Code (Java):

    double x = yourFileConfiguration.getDouble(playerName + ".Location.x");
    double y = yourFileConfiguration.getDouble(playerName + ".Location.y");
    double z = yourFileConfiguration.getDouble(playerName + ".Location.z");
    float pitch = yourFileConfiguration.getFloat(playerName + ".Location.pitch");
    float yaw = yourFileConfiguration.getFloat(playerName + ".Location.yaw");
    World world = Bukkit.getWorld(yourFileConfiguration.getString(playerName + ".Location.world"));
     
    Something like that will work
    Also, Location implements ConfigurationSerializable so you can use yourFileConfiguration.set(path, location) and yourFileConfiguration.getLocation(path)
    Another thing, you shuld use the player UUID and not the name because the player name can change, the UUID no. To do that you just would have to do
    Code (Java):


    String playerUUID = null;
    for(String key : yourFileConfiguration.getConfigurationSection("").getKeys(false){
        if(Bukkit.getOfflinePlayer(UUID.fromString(key)).getName().equals(playerName){
            playerUUID = key;
            break;
        }
    }

    if(playerUUID == null){
        sender.sendMessage("That player isn't in the data base");
        return;
    }

    double x = yourFileConfiguration.getDouble(playerUUID + ".Location.x");
    double y = yourFileConfiguration.getDouble(playerUUID + ".Location.y");
    double z = yourFileConfiguration.getDouble(playerUUID + ".Location.z");
    float pitch = yourFileConfiguration.getFloat(playerUUID + ".Location.pitch");
    float yaw = yourFileConfiguration.getFloat(playerUUID + ".Location.yaw");
    World world = Bukkit.getWorld(yourFileConfiguration.getString(playerUUID + ".Location.world"));

     
     
    • Agree Agree x 2