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

PlayerItemHeldEvent error

Discussion in 'Development' started by CookieCode, Dec 30, 2017.

  1. CookieCode

    CookieCode Silverfish

    Messages:
    20
    GitHub:
    CookieCode
    Hi, I would like to create a plugin to change the name of the items, but since two days, it shows an error in the console :

    ParseError: "syntax error, unexpected 'public function onHeld' (T_STRING), expecting function (T_FUNCTION) or const (T_CONST)" (EXCEPTION) in "plugins/FoodEffect-master/src/CookieCode/CustomArmor/Loader" at line 26.

    My Code a the line 26 :
    PHP:
    public function onHeld(PlayerItemHeldEvent $e){
    If (
    $e->getItem ()->getId () === 302){
    $e->getItem()->setCustomName("Alpha Helmet");
       }
    }
    Please help me :(
     
    Last edited by a moderator: Dec 30, 2017
  2. armagadon159753

    armagadon159753 Zombie

    Messages:
    217
    GitHub:
    armagadon159753
    PHP:
    public function onHeld(PlayerItemHeldEvent $e){
       if (
    $e->getItem ()->getId () === 302){
       
    $e->getItem()->setCustomName("Alpha Helmet");
    }
    }
    the console indicates that this function is not accepted because there is an error.
    can you send me the function that precedes it
     
  3. LewBr

    LewBr Zombie

    Messages:
    385
    GitHub:
    lewbr
    perhap
    maybe he has another function upstairs missing some ; or }
     
  4. armagadon159753

    armagadon159753 Zombie

    Messages:
    217
    GitHub:
    armagadon159753
    have can not confirm it if we had no integrity of the code but hey that said a syntax error is not very nasty
     
  5. CookieCode

    CookieCode Silverfish

    Messages:
    20
    GitHub:
    CookieCode
    PHP:
    <?php
    namespace CookieCode\CustomArmor;

    use 
    pocketmine\Player;
    use 
    pocketmine\item\ItemFactory;
    use 
    pocketmine\item\Item;
    use 
    pocketmine\plugin\PluginBase;
    use 
    pocketmine\event\Listener;
    use 
    pocketmine\event\player\PlayerItemHeldEvent;
    use 
    pocketmine\utils\{TextFormat as TFConfig};
    use 
    pocketmine\event\Event;
    use 
    pocketmine\inventory\PlayerInventory;

    class 
    Loader extends PluginBase implements Listener{
        
        public function 
    onEnable() {
             
    $this->getServer()->getPluginManager()->registerEvents($this$this);
            
    $this->getServer()->getLogger()->info(TF::GREEN "[FoodEffect]" TF::YELLOW " Plugin enabled by CookieCode");
        
    $this->saveDefaultConfig();
        }

        public function 
    onLoad(){
            
    $this->saveResource("config.yml");
    }

    public function 
    onHeld(PlayerItemHeldEvent $e){
    If (
    $e->getItem ()->getId () === 305){
    $e->getItem()->setCustomName ("The lonely stone");
    }
    }
    }
     
  6. armagadon159753

    armagadon159753 Zombie

    Messages:
    217
    GitHub:
    armagadon159753
    Try that with correct syntaxe :D
    PHP:
    <?php

    namespace CookieCode\CustomArmor;

    use 
    pocketmine\Player;
    use 
    pocketmine\item\ItemFactory;
    use 
    pocketmine\item\Item;
    use 
    pocketmine\plugin\PluginBase;
    use 
    pocketmine\event\Listener;
    use 
    pocketmine\event\player\PlayerItemHeldEvent;
    use 
    pocketmine\utils\{TextFormat as TFConfig};
    use 
    pocketmine\event\Event;
    use 
    pocketmine\inventory\PlayerInventory;

    class 
    Loader extends PluginBase implements Listener{
       
        public function 
    onEnable() {
            
    $this->getServer()->getPluginManager()->registerEvents($this$this);
            
    $this->getServer()->getLogger()->info(TF::GREEN "[FoodEffect]" TF::YELLOW " Plugin enabled by ArmTheDev");
            
    $this->saveDefaultConfig();
        }
       
        public function 
    onLoad(){
            
    $this->saveResource("config.yml");
        }
       
        public function 
    onHeld(PlayerItemHeldEvent $e){
            if(
    $e->getItem ()->getId () === 305){
                
    $e->getItem()->setCustomName ("The lonely stone");
            }
        }
    }
     
  7. CookieCode

    CookieCode Silverfish

    Messages:
    20
    GitHub:
    CookieCode
    Code:
    ParseError: "syntax error, unexpected '{'" (EXCEPTION) in "plugins/FoodEffect-master/src/CookieCode/FoodEffect/Loader" at line 16
    My console show me that...
     
  8. armagadon159753

    armagadon159753 Zombie

    Messages:
    217
    GitHub:
    armagadon159753
    Fixed, now you can add SOLVED tag to your thread :D
     
    OnTheVerge 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.