Solved Name of Entity

Discussion in 'Plugin Development' started by mahbbazci, Nov 25, 2017.

Thread Status:
Not open for further replies.
  1. Offline

    mahbbazci

    if i use "event.getEntity().getCustomName()", return null(same if a entity have a custom name), but if i use in a "new BukkitRunnable / runTaskLater(this, 2)", return a correct custom name! but BukkitRunnable don't has a return option!

    what do i do?

    (i use a google translate :p )
     
  2. Online

    timtower Administrator Administrator Moderator

    @mahbbazci What are you trying to do? Which event?
     
  3. Offline

    mahbbazci

    @timtower CreatureSpawnEvent
     
  4. Online

    timtower Administrator Administrator Moderator

    @mahbbazci And what are you trying to do?
    What is changing the name, when does it change the name?
     
  5. Offline

    mahbbazci

    I am not changing the name, I want to check if the entity has a custom name (other than null), if it is null I delete it, but even those that spawn with custom name are returning null in "getEntity (). getCustomName () "
     
  6. Online

    timtower Administrator Administrator Moderator

    @mahbbazci What has set the custom name then?
     
  7. Offline

    mahbbazci

    Code:
    public void onSpawn(CreatureSpawnEvent event){
        Entity entid = event.getEntity();
        String nome = entid.getCustomName()+"";
        Bukkit.broadcastMessage(nome);
        if(nome.equalsIgnoreCase("null")){
                    event.setCancelled(true);
            }
    }
    
    //Ever return "null"
    Code:
    public void onSpawn(CreatureSpawnEvent event){
        Entity entid = event.getEntity();
        Delayer(entid);
     //if(nome.equalsIgnoreCase("null")){
     //            event.setCancelled(true);
     //}
    }
    
    private void Delayer(Entity entity){
        new BukkitRunnable(){
            @Override
            public void run(){
                String nome = entid.getCustomName()+"";
                Bukkit.broadcastMessage(nome);
            }
        }.runTaskLater(this, 2);
    }
    
    //say a correct name, but don't return to onSpawm
    [​IMG]

    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
    Last edited by a moderator: Nov 25, 2017
  8. Online

    timtower Administrator Administrator Moderator

    @mahbbazci And what if you listen on priority MONITOR?
     
  9. Offline

    mahbbazci

    I did not understand, my English is not good and google translated it into a meaningless phrase for me
     
  10. Online

    timtower Administrator Administrator Moderator

    @mahbbazci Your code runs before the code that is changing the name.
    Changing the priority of your handler might fix that.
     
  11. Offline

    mahbbazci

    i do no make it...
     
  12. Online

    timtower Administrator Administrator Moderator

    @mahbbazci That is why YOUR handler should run after it.
    Set the priority to MONITOR to see if the name is correct there.
     
  13. Offline

    mahbbazci

    I still do not know, can I get an example code?
     
  14. Online

    timtower Administrator Administrator Moderator

  15. Offline

    mahbbazci

  16. Online

    timtower Administrator Administrator Moderator

    @mahbbazci Then you need to do everything from the BukkitRunnable
     
  17. Offline

    mahbbazci

    new FixedMetadataValue don't work in runnable
     
  18. Online

    timtower Administrator Administrator Moderator

    Define "does not work"
     
  19. Offline

    mahbbazci

    My error, i use "this"(runnable), but's a Main :p
     
Thread Status:
Not open for further replies.

Share This Page