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

Code is bad

Discussion in 'Development' started by Flsmers, Dec 3, 2016.

  1. Flsmers

    Flsmers Creeper

    Messages:
    5
    Hay, i have plugin on drop in stone.
    My code iś crash on line (rand)
    PHP:
    <?php

    namespace Flsmers;

    use 
    pocketmine\plugin\PluginBase as P;
    use 
    pocketmine\event\Listener as L;
    use 
    pocketmine\utils\TextFormat;
    use 
    pocketmine\utils\MainLogger;
    use 
    pocketmine\event\block\BlockBreakEvent;
    use 
    pocketmine\block\Block;
    use 
    pocketmine\math\Vector3;
    use 
    pocketmine\item\Item;

    class 
    Main extends implements L{
       
        public function 
    onEnable(){
            
    $this->getServer()->getPluginManager()->registerEvents($this,$this);
            
    $this->saveDefaultConfig();
            
    $this->getServer()->getLogger()->info("Włączono - Drop");
        }

       
        public function 
    onBreak(BlockBreakEvent $e){
            
    $p $e->getPlayer();
            
    $block $e->getBlock();
            
    $gracz $e->getPlayer()->getName();
            if(
    $e->getBlock()->getId() == 1){
                switch(
    rand(1,80) == 80)){
             
    $p->sendMessage(" • [DROP] Znalazłeś - (1) Węgiel • ");
             
    $p->setDrops(array(Item:get(2,2))); 
             break;
                }
            }
            else{
            }
            if(
    $e->getBlock()->getId() == 1){
                switch(
    rand(1,80) == 80)){
           
    $p $e->getPlayer();
             
    $p->sendMessage(" • [DROP] Znalazłeś - (3) Węgiel • ");
             
    $p->setDrops(array(Item:get(2,4))); 
             break;
                }
            }
            else{
            }
     
  2. InspectorGadget

    InspectorGadget Zombie Pigman

    Messages:
    462
    GitHub:
    InspectorGadget
    Edited
    PHP:

    <?php

    namespace Flsmers;

    use 
    pocketmine\plugin\PluginBase// why not try the easy way
    use pocketmine\event\Listener// why not try the easy way
    use pocketmine\utils\TextFormat;
    use 
    pocketmine\utils\MainLogger// no such thing, use this:
    // use pocketmine\Server;
    use pocketmine\event\block\BlockBreakEvent;
    use 
    pocketmine\block\Block;
    use 
    pocketmine\math\Vector3;
    use 
    pocketmine\item\Item;

    class 
    Main extends PluginBase implements Listener{
     
        public function 
    onEnable(){
            
    $this->getServer()->getPluginManager()->registerEvents($this,$this);
            
    $this->saveDefaultConfig();
            
    $this->getServer()->getLogger()->info("Włączono - Drop");
        }

     
        public function 
    onBreak(BlockBreakEvent $e){
            
    $p $e->getPlayer();
            
    $block $e->getBlock();
            
    $gracz $e->getPlayer()->getName();

            if(
    $e->getBlock()->getId() == 1){
                switch(
    rand(1,80) == 80)){
             
    $p->sendMessage(" • [DROP] Znalazłeś - (1) Węgiel • ");
             
    $p->setDrops(array(Item:get(2,2)));
             break;
                }
            }
            else{
            }
            if(
    $e->getBlock()->getId() == 1){
                switch(
    rand(1,80) == 80)){
           
    $p $e->getPlayer();
             
    $p->sendMessage(" • [DROP] Znalazłeś - (3) Węgiel • ");
             
    $p->setDrops(array(Item:get(2,4)));
             break;
                }
            }
            else{
            }
        } 
    // you forgot to close this
    // closes Class
     
  3. SOFe

    SOFe Administrator Staff Member PMMP Team Poggit Admin

    Messages:
    1,968
    GitHub:
    sof3
    Using aliases is not a difficult way. It may make classes less readable, but this makes it easier to read and to write for the person who wrote it.
     
    Primus likes this.
  4. InspectorGadget

    InspectorGadget Zombie Pigman

    Messages:
    462
    GitHub:
    InspectorGadget
    So is that a good thing or a bad thing ?
     
  5. Primus

    Primus Zombie Pigman

    Messages:
    749
    That varies from perspective.
     
  6. SOFe

    SOFe Administrator Staff Member PMMP Team Poggit Admin

    Messages:
    1,968
    GitHub:
    sof3
    Not bad enough to be corrected and call it a "fix".
     
  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.