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

Why cant you trust instanceof

Comments in 'Plugin Development' started by MyNameIsTriXz, Apr 21, 2016.

  1. MyNameIsTriXz
    Offline

    MyNameIsTriXz Notable Member

    Joined:
    Aug 17, 2015
    Posts:
    538
    Minecraft User:
    MyNameIsTriXz
    As example when I check if(!$event->getEntity() instanceof Player){ it kicks the player on EntityDamageEvent, the same when I check if a sign is instanceof Sign? Why is instanceof so buggy?
  2. Primus
    Offline

    Primus Notable Member

    Joined:
    Apr 7, 2015
    Posts:
    1,470
    Minecraft User:
    PrimusLV
    It isn't.

    make sure you import right class
    PHP:
    use pocketmine\block\Sign;
    # Or
    use pocketmine\tile\Sign;
    as for
    PHP:
    if(!condition)
    You can also do
    PHP:
    if($entity instanceof Player === false)
  3. HotFireyDeath
    Offline

    HotFireyDeath Notable Member Plugin Developer

    Joined:
    Mar 19, 2015
    Posts:
    328
    Plugins:
    1
    Minecraft User:
    HotFireyDeath
    Try this perhaps?
    PHP:
    if (!($event->getEntity() instanceof Player)) //
  4. Primus
    Offline

    Primus Notable Member

    Joined:
    Apr 7, 2015
    Posts:
    1,470
    Minecraft User:
    PrimusLV
    The same tho but should work as good as all other options

    As I said before 'instanceof' isn't buggy
    Muqsit and HotFireyDeath like this.
  5. Legoboy0215
    Offline

    Legoboy0215 Notable Member

    Joined:
    Nov 1, 2014
    Posts:
    1,724
    Minecraft User:
    Legoboy0215
    Instanceof works perfectly. Remember,it is also a coder's job to debug.
    HotFireyDeath likes this.

Share This Page

Advertisement