1. The forums will be archived and moved to a read only mode in about 2 weeks (mid march).

Get if a Leather Armor is red

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

  1. Ayzrix

    Ayzrix Witch

    Messages:
    66
    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:
    66
    GitHub:
    Ayzrix
  3. KielKing

    KielKing Zombie

    Messages:
    245
    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,548
    GitHub:
    muqsit
    Did you not get any errors? There are errors in your code.
     
    OnTheVerge likes this.
  5. KielKing

    KielKing Zombie

    Messages:
    245
    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 Slime

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

    Ayzrix Witch

    Messages:
    66
    GitHub:
    Ayzrix
    hmmm Yes CustomName ! Thanks to you :D
     
    Emirhan Akpınar likes this.
  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.