Solved Get just the name and the player from a config

Discussion in 'Plugin Development' started by Ahrigumi, Jun 3, 2019.

  1. Offline

    Ahrigumi

    Hi guys, i know is a so noobie question, but i didnt remember how can i do this. I will explain myself.
    I want to get the name from an entity and compare that name from the config with the section "name".
    Better with an example:
    Code:
    ba04c878-7a1a-4c35-828a-e545a5e8cf8d:
      Name: test
      Owner: Ahrigumi
      Health: 21.0
    
    So.. i want to do a check-line to compare the display name with the string name of this config.
     
  2. Offline

    KarimAKL

    @Ahrigumi Is this solved? If not then do you want to get just the 'Name' and 'Owner'?
     
  3. config.getString("Name").equals(yourName) should do it. Obviously change config and yourName to whatever your variables are called.

    Hope this helps

    Sent from my SM-G903F using Tapatalk
     
  4. Offline

    KarimAKL

    @TheMinecraftKnight You would have to change the "Name" part to also have the UUID of the entity included.
    Code:Java
    1. config.getString(uuid+".Name")/*...*/;
     
  5. Ah yeah, I didn't notice that. Alternatively config could be getConfigurationSection(uuid)

    Sent from my SM-G903F using Tapatalk
     
    KarimAKL likes this.
  6. Offline

    KarimAKL

    TheMinecraftKnight likes this.
  7. Offline

    Ahrigumi

    @KarimAKL yes! Its solved :D , i used a better way, checking better and adding the uuid of the entity, thanks to all !
     
  8. Offline

    KarimAKL

    Could you let us know how you did that?
     
  9. Offline

    Ahrigumi

    Sure,
    Code:
    
            Player mensaje = event.getPlayer();
            Horse caballo = (Horse) event.getRightClicked();
            UUID uuid = caballo.getUniqueId();
            AnimalTamer propietario = (AnimalTamer) caballo.getOwner();
            String UUID = main.dueƱosConfig.getString("Horses." + mensaje.getUniqueId().toString() + "." + uuid + ".Owner");
            String caballoName = main.dueƱosConfig.getString("Horses." +  mensaje.getUniqueId().toString() + "." + uuid + ".Name");
    
    Code:
    
                }else if(caballo.getOwner() != null)  {
                    if(caballo instanceof Horse) {
                        if(((Tameable) caballo).isTamed()) {
                            if((main.color(caballo.getName()).equals(main.color(caballoName)))
                                        && (propietario.getName().equals(UUID))) {
                                    mensaje.sendMessage("You are the owner of " + main.color(caballoName));
                            }
                        } 
                    }
                }
    
    So, In the config i save the uuid of the player and the uuid of the horse and more information like the gender, jump, health, etc.
    So in this code im getting the uuid of the entity inside the uuid of the owner and doing an equals to check if the name and the uuid is the same to the information inside of the config.

    The config looks like this
    Code:
    Horses:
      ba04c878-7a1a-4c35-828a-e545a5e8cf8d:     <--- Player UUID
        35923aab-695b-4dd0-96f3-7023b7621349:    <---- Horse UUID
          Name: asd
          Owner: ahrigumi
          ID: 110
          Health: 18.0
          Jump: 2.4
        56275015-edec-4540-8359-7a3bcd804cf2:    <---- Horse UUID
          Name: asd
          Owner: ahrigumi
          ID: 89
          Health: 22.0
          Jump: 2.0
    
     
    Last edited: Jun 4, 2019
  10. Offline

    KarimAKL

    @Ahrigumi May i ask why you are doing this? If i understand what you are doing correctly, i can think of a few reasons to do this but i still wanna ask why. :7
    Also, a few other things i wanna mention:
    1. This is what we were saying before. 'ConfigurationSection#getString()'
    2. I haven't tested anything myself but i've heard it's faster to load all files onEnable and then get it from a collection or something, instead of loading a file everytime.
     
  11. Offline

    Ahrigumi

    why? , simple. I just only know this way to do it :/
     
  12. Offline

    KarimAKL

    @Ahrigumi I meant "why do you want to check if the two owners match?".
     
  13. Offline

    Ahrigumi

    To join in the horse or be ejected
     

Share This Page