Advertisement
  1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.

get player from entity?

Comments in 'Plugin Development' started by BalAnce, Jun 9, 2015.

  1. BalAnce
    Offline

    BalAnce Active Member

    Joined:
    Mar 10, 2015
    Posts:
    125
    Minecraft User:
    BalAnce
    How would i send a message to a player on EntityArmorChangeEvent? Or how to do i get the player from entity? If that makes sense.
  2. aliuly
    Offline

    aliuly Notable Member Plugin Developer

    Joined:
    Feb 8, 2014
    Posts:
    1,086
    Plugins:
    17
    PHP has weak typing. So you can start using the entity as a player. You do need to make sure that it is a Player though (instanceof) because if you try to call a Player function on an entity the server will crash.
    BalAnce and Falk like this.
  3. BalAnce
    Offline

    BalAnce Active Member

    Joined:
    Mar 10, 2015
    Posts:
    125
    Minecraft User:
    BalAnce
    Wait so i tried this and it did not do anything. Im not sure if that is what you were saying.
    PHP:
    public function ArmorChange (EntityArmorChangeEvent $ev){
            if (
    $ev->getEntity() instanceof Player){
                
    //what do i do here

            
    }
        }
    i tried $ev->getEntity()->sendMessage("Test"); but got nothing

    EDIT
    nvm figure what i didnt do. If anyone wanted to know what worked:
    PHP:
    public function ArmorChange (EntityArmorChangeEvent $ev){
            
    $entity $ev->getEntity()
            if (
    $entity instanceof Player){
                
    $entity->sendMessage("Hello");

            }
        }
    Last edited: Jun 10, 2015
  4. PEMapModder
    Offline

    PEMapModder Notable Member Plugin Developer

    Joined:
    Oct 9, 2013
    Posts:
    7,294
    Plugins:
    11
    Minecraft User:
    PEMapModder
    How does nonstrict typing relate to this issue? In many type-strict languages, class inheritance allows that anyway.
  5. aliuly
    Offline

    aliuly Notable Member Plugin Developer

    Joined:
    Feb 8, 2014
    Posts:
    1,086
    Plugins:
    17
    If you have strict typing then you should only be able to access the methods declared in Entity, not in Player. Yes, Player can override Entity's implementations, but shouldn't be adding new methods.
    PEMapModder likes this.
  6. PEMapModder
    Offline

    PEMapModder Notable Member Plugin Developer

    Joined:
    Oct 9, 2013
    Posts:
    7,294
    Plugins:
    11
    Minecraft User:
    PEMapModder
    Oh you mean casting.

Share This Page

Advertisement