Get if a Leather Armor is red

Discussion in 'Development' started by Ayzrix, Jul 27, 2019.

  1. Ayzrix

    Ayzrix Witch

    Messages:
    53
    GitHub:
    Ayzrix
    Hello, could someone help me? I managed to give myself a red armor, but not to know if the armor was red, here is my code


    PHP:
      public function onArmorChange(EntityArmorChangeEvent $ev){
        
    $player $ev->getEntity();
        
    $Nid $ev->getNewItem()->getID();
        
    $Oid $ev->getOldItem()->getID();
     
       if(
    $player instanceof Player){


       if(
    $Nid == 298 and $Nid->getCustomColor() == Color(25500)){

      
    $eff = new EffectInstance(Effect::getEffect(Effect::NIGHT_VISION) , 9999990true);
      
    $player->addEffect($eff);
          
     }elseif(
    $Oid == 298 and $Nid->getCustomColor() == Color(25500)){
     
     
    $player->removeEffect(16);
     
       }
         }
          }
     
  2. Ayzrix

    Ayzrix Witch

    Messages:
    53
    GitHub:
    Ayzrix
  3. KielKing

    KielKing Zombie

    Messages:
    271
    GitHub:
    kielking
    the idea you provided is correct, but i suggest you use NBT if you need to difference your special item from all the regular items
     
    Last edited: Jul 31, 2019
    OnTheVerge likes this.
  4. Muqsit

    Muqsit Chicken

    Messages:
    1,555
    GitHub:
    muqsit
    Did you not get any errors? There are errors in your code.
     
    OnTheVerge likes this.
  5. KielKing

    KielKing Zombie

    Messages:
    271
    GitHub:
    kielking
    it is not a good practice to use hard coded values for item IDs because they can change at any time
    you are calling a function on an int
    you forgot the `new` keyword to make a new instance of Color
     
    OnTheVerge likes this.
  6. Emirhan Akpınar

    Emirhan Akpınar Witch

    Messages:
    59
    GitHub:
    EmirhanWSD
    Use different method for checking armor is red. Example: customName, nbt
     
  7. Ayzrix

    Ayzrix Witch

    Messages:
    53
    GitHub:
    Ayzrix
    hmmm Yes CustomName ! Thanks to you :D
     
    Emirhan Akpınar likes this.

Share This Page

  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.