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

PlayerMoveEvent

Discussion in 'Development' started by Teamblocket, May 1, 2017.

  1. Teamblocket

    Teamblocket Zombie

    Messages:
    301
    GitHub:
    teamblocket
    hey , so am making a plugin that involves PlayerMoveEvent , it works prefectly just that when the player moves with a helmet on called "Diamond Helmet \nGills I \nFeed I" it doesn't work but yet with the "Diamond Helmet \nGills I" it works .
    PHP:
         public function onHelmet(Player $player){
            
    $helmet $player->getInventory()->getHelmet(); // Getting Helmet
            
    $id $helmet->getId(); // Helmets ID
            
    $name $helmet->getCustomName(); // Helmets Name

             // Helmet with Feed I and Gills I
            
    if($id === 310 and $name === "§r§f§bDiamond Helmet \n§7Feed I \n§7Gills I"){
                
    $player->addEffect(Effect::getEffect(13)->setDuration(9999 20)->setAmplifier(1));
                
    $player->addEffect(Effect::getEffect(23)->setDuration(9999 20)->setAmplifier(1));
                     } else {
                
    $player->removeEffect(Effect::SATURATION);
                
    $player->removeEffect(Effect::WATER_BREATHING);
                  }

              
    //Helmet with Gills I and Feed I
              
    if($id === 310 and $name === "§r§f§bDiamond Helmet \n§7Gills I \n§7Feed I"){
                
    $player->addEffect(Effect::getEffect(13)->setDuration(9999 20)->setAmplifier(1));
                
    $player->addEffect(Effect::getEffect(23)->setDuration(9999 20)->setAmplifier(1));
                     } else {
                 
    $player->removeEffect(Effect::SATURATION);
                
    $player->removeEffect(Effect::WATER_BREATHING);       
            }
        }
     
  2. Daniktheboss

    Daniktheboss Baby Zombie

    Messages:
    144
    GitHub:
    daniktheboss
    Hacky way to do that using names.
    Why use on move event?

    PHP:
    public function onArmorEquipt(EntityArmorChangeEvent $e){//CustomEnchantment armor effect
        
    $i $e->getNewItem();//armor put on
        
    $o $e->getOldItem();//armor taken off
        
    $p $e->getEntity();//player
        //do whatver with the items, use nbt tags :D
    }
     
  3. Teamblocket

    Teamblocket Zombie

    Messages:
    301
    GitHub:
    teamblocket
    i tried that to thats why am using PlayerMoveEvent
     
  4. Teamblocket

    Teamblocket Zombie

    Messages:
    301
    GitHub:
    teamblocket
    its seems like every time i add or remove more then 2 effects it doesn't work
     
  5. Teamblocket

    Teamblocket Zombie

    Messages:
    301
    GitHub:
    teamblocket
    heres my code with your method
    PHP:
    public function onArmorEquipt(EntityArmorChangeEvent $e){//CustomEnchantment armor effect
        
    $i $e->getNewItem()->getCustomName();//armor put on
        
    $o $e->getOldItem();//armor taken off
        
    $player $e->getEntity();//player
        //do whatver with the items, use nbt tags :D

             // Helmet with Feed I and Gills I
            
    if($i === "§r§f§bDiamond Helmet \n§7Feed I \n§7Gills I"){
                
    $player->addEffect(Effect::getEffect(13)->setDuration(9999 20)->setAmplifier(1));
                
    $player->addEffect(Effect::getEffect(23)->setDuration(9999 20)->setAmplifier(1));
                     } else {
                
    $player->removeEffect(Effect::SATURATION);
                
    $player->removeEffect(Effect::WATER_BREATHING);
                  }

              
    //Helmet with Gills I and Feed I
              
    if($i === "§r§f§bDiamond Helmet \n§7Gills I \n§7Feed I"){
                
    $player->addEffect(Effect::getEffect(13)->setDuration(9999 20)->setAmplifier(1));
                
    $player->addEffect(Effect::getEffect(23)->setDuration(9999 20)->setAmplifier(1));
                     } else {
                 
    $player->removeEffect(Effect::SATURATION);
                
    $player->removeEffect(Effect::WATER_BREATHING);
             }

            
    // Helmet with Gills I
            
    if($i === "§r§f§bDiamond Helmet \n§7Gills I"){
                
    $player->addEffect(Effect::getEffect(13)->setDuration(9999 20)->setAmplifier(1));
            } else {
                
    $player->removeEffect(Effect::WATER_BREATHING);
            }

            
    // Helmet with Feed I
           
    if($i === "§r§f§bDiamond Helmet \n§7Feed I"){
                
    $player->addEffect(Effect::getEffect(23)->setDuration(9999 20)->setAmplifier(1));
            } else {
                
    $player->removeEffect(Effect::SATURATION);
             }       
            }
    doesn't work the same thing happens
     
  6. jasonwynn10

    jasonwynn10 Moderator Poggit Reviewer

    Messages:
    1,489
    GitHub:
    jasonwynn10
    The formatting of that code was triggering my OCD...
    PHP:
    public function onArmorEquipt(EntityArmorChangeEvent $e){
        
    $i $e->getNewItem()->getCustomName(); //name of new armor
        
    $player $e->getEntity();
        if(!
    $player instanceof Player) {
            
    $this->getLogger()->error("not a player?");
        }
        if(
    $i === "§r§f§bDiamond Helmet \n§7Feed I \n§7Gills I"
            
    $player->addEffect(Effect::getEffect(Effect::WATER_BREATHING)->setDuration(9999 20)->setAmplifier(1));
            
    $player->addEffect(Effect::getEffect(Effect::SATURATION)->setDuration(9999 20)->setAmplifier(1));
        } else {
            
    $player->removeEffect(Effect::SATURATION);
            
    $player->removeEffect(Effect::WATER_BREATHING);
        }
        if(
    $i === "§r§f§bDiamond Helmet \n§7Gills I \n§7Feed I"){
            
    $player->addEffect(Effect::getEffect(Effect::WATER_BREATHING)->setDuration(9999 20)->setAmplifier(1));
            
    $player->addEffect(Effect::getEffect(Effect::SATURATION)->setDuration(9999 20)->setAmplifier(1));
        } else {
            
    $player->removeEffect(Effect::SATURATION);
            
    $player->removeEffect(Effect::WATER_BREATHING);
        }
        if(
    $i === "§r§f§bDiamond Helmet \n§7Gills I"){
            
    $player->addEffect(Effect::getEffect(Effect::WATER_BREATHING)->setDuration(9999 20)->setAmplifier(1));
        } else {
            
    $player->removeEffect(Effect::WATER_BREATHING);
        }
        if(
    $i === "§r§f§bDiamond Helmet \n§7Feed I"){
            
    $player->addEffect(Effect::getEffect(Effect::SATURATION)->setDuration(9999 20)->setAmplifier(1));
        } else {
            
    $player->removeEffect(Effect::SATURATION);
        }
    }
    One possible solution is lowering the duration to ensure that you haven't passed the php maximum integer limit
     
    Muqsit likes this.
  7. Teamblocket

    Teamblocket Zombie

    Messages:
    301
    GitHub:
    teamblocket
    ok done , noting :(
     
  8. Thunder33345

    Thunder33345 Moderator Staff Member

    Messages:
    2,137
    GitHub:
    Thunder33345
    the idea of verifying items enchantments based on names just make me ask why am i even here
    the idea of using an AND crazes me even more
    so if i have a 3 enchantment you would need all possible enhancements order of 3 enchantment + all combinations of using only 2 and 1
    which would be a lot (wished i exactly split out the number there)
    only if you stored it in item NBT you could foreach all the enchantments way easier
    sorry, this just have to be said...
     
    jasonwynn10 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.