Solved Null (Im not really sure why)

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

  1. Offline

    Ahrigumi

    So... i have null and i dont know why :D

    Code:
    Horses:
      ba04c878-7a1a-4c35-828a-e545a5e8cf8d:   <---- Player UUID
        test:                                                                      <---- Horse Name
          UUID: e114bbfa-03be-49ff-9786-dd162d10f0a7          <----- Horse UUID
          Name: test
          Owner: Shilodabing
          ID: 88
          Health: 21.0
          Jump: 1.8
    
    Here the code to print on chat

    Code:
        @EventHandler
        public void stats(EntityDamageByEntityEvent event) {
            Player player = (Player) event.getDamager();
            Horse caballo = (Horse) event.getEntity();
            String playerUUID = caballo.getOwner().getName();
            String nameHorse = caballo.getCustomName();
            System.out.print(main.dueñosConfig.getString("Horses." + playerUUID + "." + nameHorse + "Owner"));
            if((player instanceof Player) && (caballo != null) && (caballo instanceof Horse)){
                if(main.stats.contains(player.getName())) {
                    player.sendMessage(ChatColor.GREEN + "]--(Stats)--[");
                    player.sendMessage((ChatColor.DARK_AQUA + "Owner: " ) + main.dueñosConfig.getString("Horses." + playerUUID + "." + nameHorse + "Owner"));
                    player.sendMessage((ChatColor.DARK_AQUA + "Name: " ) + main.dueñosConfig.getString("Horses." + playerUUID + "." + nameHorse + "Name"));
                    player.sendMessage((ChatColor.DARK_AQUA + "Id: ") + main.dueñosConfig.getString("Horses." + playerUUID + "." + nameHorse + "ID"));
                    player.sendMessage((ChatColor.DARK_AQUA + "Health: ") + main.dueñosConfig.getString("Horses." + playerUUID + "." + nameHorse + "Health"));
                    player.sendMessage((ChatColor.DARK_AQUA + "Jump: ") + main.dueñosConfig.getString("Horses." + playerUUID + "." + nameHorse + "Jump"));
                    player.sendMessage(main.dueñosConfig.getString(("Horses." + playerUUID + "." + nameHorse + "UUID")));
                    player.sendMessage(ChatColor.GREEN + "]----------[");
                    event.setCancelled(true);
                    player.playSound(player.getLocation(), Sound.ENTITY_EXPERIENCE_ORB_PICKUP, 10, 1);
                }
            }
        }
    
    And the problem is, when the code is executed, appear on chat

    Owner: null
    Name: null

    etc,etc,etc

    Im 90% sure, the problem is when i call the string from the config using an incorrect syntax, but... D:
     
  2. Offline

    KarimAKL

    @Ahrigumi Change this:
    Code:
    nameHorse + "Owner"
    To this:
    Code:
    nameHorse + ".Owner"
    etc.
     
  3. Offline

    Ahrigumi

    wait....

    Nope, is still null

    P.D: Im trying to test, what is null and the playerUUID and nameHorse strings are null??? , I dont understand
     
    Last edited: Jun 11, 2019
  4. Offline

    Tango_

    Can you show your updated code?
     
  5. Offline

    Kars

    Karim is right. By the looks of it you are missing the period between nameHorse and the rest.
    Either that or .getOwner and .getCustomName are not working. I have no experience with the Horse class but i'd say debug that.
     
    Last edited by a moderator: Jun 12, 2019
  6. Offline

    Ahrigumi

    So my code updated is this
    Code:
        @EventHandler
        public void stats(EntityDamageByEntityEvent event) {
            Player player = (Player) event.getDamager();
            Horse caballo = (Horse) event.getEntity();
            String playerUUID = caballo.getOwner().getName();
            String nameHorse = caballo.getCustomName();
            UUID horseUUID = caballo.getUniqueId();
            System.out.print(main.dueñosConfig.getString("Horses." + playerUUID + "." + nameHorse + ".Owner"));
            System.out.print(main.dueñosConfig.getString(playerUUID));
            System.out.print(main.dueñosConfig.getString(nameHorse));
            System.out.print(horseUUID);
            if((player instanceof Player) && (caballo != null) && (caballo instanceof Horse)){
                if(main.stats.contains(player.getName())) {
                    player.sendMessage(ChatColor.GREEN + "]--(Stats)--[");
                    player.sendMessage((ChatColor.DARK_AQUA + "Owner: " ) + main.dueñosConfig.getString("Horses." + playerUUID + "." + nameHorse + ".Owner"));
                    player.sendMessage((ChatColor.DARK_AQUA + "Name: " ) + main.dueñosConfig.getString("Horses." + playerUUID + "." + nameHorse + ".Name"));
                    player.sendMessage((ChatColor.DARK_AQUA + "Id: ") + main.dueñosConfig.getInt("Horses." + playerUUID + "." + nameHorse + ".ID"));
                    player.sendMessage((ChatColor.DARK_AQUA + "Health: ") + main.dueñosConfig.getInt("Horses." + playerUUID + "." + nameHorse + ".Health"));
                    player.sendMessage((ChatColor.DARK_AQUA + "Jump: ") + main.dueñosConfig.getInt("Horses." + playerUUID + "." + nameHorse + ".Jump"));
                    player.sendMessage(main.dueñosConfig.getString(("Horses." + playerUUID + "." + nameHorse + "UUID")));
                    player.sendMessage(ChatColor.GREEN + "]----------[");
                    event.setCancelled(true);
                    player.playSound(player.getLocation(), Sound.ENTITY_EXPERIENCE_ORB_PICKUP, 10, 1);
                }
            }
        }
    
     
  7. Offline

    Tango_

    At the bottom this part: ("Horses." + playerUUID + "." + nameHorse + "UUID")))
    Needs to become: ("Horses." + playerUUID + "." + nameHorse + ".UUID")))
     
  8. Offline

    Ahrigumi

    Solved! , the problem was one wrong variable hehe
     

Share This Page