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

Solved BlockBreakEvent not working :(

Discussion in 'Development' started by OnTheVerge, Dec 19, 2017.

  1. OnTheVerge

    OnTheVerge Spider Jockey

    Messages:
    46
    Hello there,
    To everyone who clicked this thread to help me, I thank you so much. Please bare with me if I made so many stupid mistakes. I just began getting into plugin development a few days ago :)

    My objective of this plugin was to make it so that whenever someone breaks a random amount of stone blocks between 1-30 it would drop a chest that had a custom name called "Relic" and then send a Message but, Unfortunately an error occurs :(

    Error:

    Relics v1.0.1
    19.12 12:38:56 [Server] Server thread/CRITICAL ParseError: "syntax error, unexpected ' ' (T_STRING)" (EXCEPTION) in "Relics/src/Relics/Main" at line 31



    My code was:

    PHP:
    <?php

    namespace Relics;

    use 
    pocketmine\plugin\PluginBase;
    use 
    pocketmine\event\Listener;
    use 
    pocketmine\player\Inventory;
    use 
    pocketmine\item\Item;
    use 
    pocketmine\event\block\BlockBreakEvent;
    use 
    pocketmine\block\Block;

    class 
    Main extends PluginBase implements Listener{

      public function 
    onEnable(){
    $this->getServer()->getPluginManager()->registerEvents($this$this);
    $this->getServer()->getLogger()->info("Relics enabled");
    }

      public function 
    onDisable(){
    $this->getServer()->getLogger()->info("Relics disabled");
    }

      public function 
    onBreak(BlockBreakEvent $event){
      
    $block $event->getId();
      
    $player $event->getPlayer();
      
    $chance mt_rand(130);
      
    $drops $event->getItem();
      
    $drops Item::get(5401);
      
    $drops->setCustomName("§cRelic");

      if(
    $event->getBlock()->getId() === 1) {
        if(
    mt_rand(1,30) === 15){
    $player->sendMessage("§6You Found a Relic!");
    $event->setDrops($drops);


          }
        }
      }
    }
    Any help at all will be very much appreciated! :D
     
    Last edited: Dec 19, 2017
  2. Kyd

    Kyd Zombie Pigman

    Messages:
    678
    GitHub:
    boi1216
    armagadon159753 likes this.
  3. OnTheVerge

    OnTheVerge Spider Jockey

    Messages:
    46
    Ty.... it still didn't help as much tho :( I still have the error
     
  4. armagadon159753

    armagadon159753 Zombie

    Messages:
    217
    GitHub:
    armagadon159753
    Try that
    PHP:
    <?php

    namespace Relics;

    use 
    pocketmine\plugin\PluginBase;
    use 
    pocketmine\event\Listener;
    use 
    pocketmine\player\Inventory;
    use 
    pocketmine\item\Item;
    use 
    pocketmine\event\block\BlockBreakEvent;
    use 
    pocketmine\block\Block;

    class 
    Main extends PluginBase implements Listener{
       
        public function 
    onEnable(){
            
    $this->getServer()->getPluginManager()->registerEvents($this$this);
            
    $this->getServer()->getLogger()->info("Relics enabled");
        }
       
        public function 
    onDisable(){
            
    $this->getServer()->getLogger()->info("Relics disabled");
        }
       
        public function 
    onBreak(BlockBreakEvent $event){
            
    $block $event->getId();
            
    $player $event->getPlayer();
            
    $chance mt_rand(130);
            
    $drops $event->getItem();
            
    $drops Item::get(5401);
            
    $drops->setCustomName("§cRelic");
            if(
    $event->getBlock()->getId() === 1) {
                
    $player->sendMessage("§6You Found a Relic!");
                
    $event->setDrops($drops);
            }
        }
    }
     
    OnTheVerge likes this.
  5. OnTheVerge

    OnTheVerge Spider Jockey

    Messages:
    46
    Hey, Thank you but now it gives a strange error


    19.12 15:07:09 [Server] Server thread/INFO Loading source plugin Relics v1.0.1 19.12 15:07:09 [Server] Server thread/CRITICAL ParseError: "syntax error, unexpected '{'" (EXCEPTION) in "Relics/src/Relics/Main" at line 14
     
  6. Kenn Fatt

    Kenn Fatt Slime

    Messages:
    82
    GitHub:
    kennfatt
    You can change this world by reading http://php.net/manual/en/index.php
     
  7. OnTheVerge

    OnTheVerge Spider Jockey

    Messages:
    46
    Isn't really helping :( I've used that website before....this error is strange to me, do you mind telling me why this error occurs?
     
  8. Thunder33345

    Thunder33345 Moderator Staff Member

    Messages:
    2,137
    GitHub:
    Thunder33345
    we cant just spoon feed you to recognize syntax errors
    syntax error just means something in the syntax is not right
    "like this sentence without a comma and the period and the capital l at the start! and an unexpected exclamation mark"
    therefore it would be like
    SYNTAX ERROR: Expecting capital letter, encounter "l" at line 1
    SYNTAX ERROR: Unexpected "!" at line 1
     
  9. Kenn Fatt

    Kenn Fatt Slime

    Messages:
    82
    GitHub:
    kennfatt
    Have you try to google it? You're jus missing '{' at line 14. I hope you can find where is line 14 located at.
     
    Levi and OnTheVerge like this.
  10. OnTheVerge

    OnTheVerge Spider Jockey

    Messages:
    46
    TYSM!
     
  11. QuiverlyRivalry

    QuiverlyRivalry Zombie Pigman

    Messages:
    491
    GitHub:
    quiverlyrivalry
    pls use ide
     
  12. OnTheVerge

    OnTheVerge Spider Jockey

    Messages:
    46
    I have one dont worry xD :)
     
  13. QuiverlyRivalry

    QuiverlyRivalry Zombie Pigman

    Messages:
    491
    GitHub:
    quiverlyrivalry
    mk, it usually should correct ur syntax errors
     
  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.