Advertisement
  1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.

Unsure coding

Comments in 'Plugin Development' started by FlamingGenius, Mar 11, 2016.

  1. FlamingGenius
    Offline

    FlamingGenius Active Member

    Joined:
    Sep 23, 2015
    Posts:
    173
    Minecraft User:
    FlamingGenius
    Just finished coding this up not sure if I used the best practices and such hopefully everything is correct I am specifically worried about these two areas of code can anyone shed some light on weather everything is correct or not. I currently do not have a server to test this on

    PHP:
        private function signQuestion(SignChangeEvent $event){
            if(
    $event->getBlock()->getId() == 68 || $event->getBlock()->getId() == 63){
                
    $sign $event->getPlayer()->getLevel()->getTile($event->getBlock());
                
    $sign $event->getLines();
                if(
    $sign[1] === "Children"){
                    
    $msg $this->getQuestion("children-questions");
                    
    $this->getServer()->broadcastMessage($msg);
                } elseif(
    $sign[1] === "Adult"){
                    
    $msg $this->getQuestion("adult-questions");
                    
    $this->getServer()->broadcastMessage($msg);
                } elseif(
    $sign[1] === "Funny"){
                    
    $msg $this->getQuestion("funny-questions");
                    
    $this->getServer()->broadcastMessage($msg);
                } elseif(
    $sign[1] === "Hard"){
                    
    $msg $this->getQuestion("hard-questions");
                    
    $this->getServer()->broadcastMessage($msg);
                }
            }
        }

    PHP:
        public function onSignTouch(PlayerInteractEvent $event){
            
    $this->signQuestion();
        }

    PHP:
    <?
    namespace 
    FlamingGenius\wyr;

    use 
    pocketmine\plugin\PluginBase;
    use 
    pocketmine\event\Listener;
    use 
    pocketmine\command\Command;
    use 
    pocketmine\command\CommandSender;\
    use 
    pocketmine\utils\Config;
    use 
    pocketmine\tile\Sign;
    use 
    pocketmine\event\block\SignChangeEvent;
    use 
    pocketmine\event\Event;
    use 
    pocketmine\event\Player\PlayerInteractEvent;

    class 
    main extends PluginBase implements Listener{
        public function 
    onEnable(){
            
    $this->saveDefaultConfig();
            
    $this->getServer()->getPluginManager()->registerEvents($this,$this);
        }
      
        private function 
    getQuestion($type){
            
    $questions $this->getConfig()->get($type);
            
    $draw array_rand($questions);
            
    $question $questions[$draw];
          
            return 
    $question;
        }
      
        private function 
    signQuestion(SignChangeEvent $event){
            if(
    $event->getBlock()->getId() == 68 || $event->getBlock()->getId() == 63){
                
    $sign $event->getPlayer()->getLevel()->getTile($event->getBlock());
                
    $sign $event->getLines();
                if(
    $sign[1] === "Children"){
                    
    $msg $this->getQuestion("children-questions");
                    
    $this->getServer()->broadcastMessage($msg);
                } elseif(
    $sign[1] === "Adult"){
                    
    $msg $this->getQuestion("adult-questions");
                    
    $this->getServer()->broadcastMessage($msg);
                } elseif(
    $sign[1] === "Funny"){
                    
    $msg $this->getQuestion("funny-questions");
                    
    $this->getServer()->broadcastMessage($msg);
                } elseif(
    $sign[1] === "Hard"){
                    
    $msg $this->getQuestion("hard-questions");
                    
    $this->getServer()->broadcastMessage($msg);
                }
            }
        }
      
        public function 
    onSignCreate(SignChangeEvent $event){
            if(
    $event->getBlock()->getId() == 68 || $event->getBlock()->getId() == 63){
                
    $sign $event->getPlayer()->getLevel()->getTile($event->getBlock());
                
    $sign $event->getLines();
                if(
    $sign[0] === "[WYR]"){
                    if(
    $sign[1] === "children"){
                        
    $event->setLines(0,"[WYR]");
                        
    $event->setLines(1,"Children");
                    } elseif(
    $sign[1] === "adult"){
                        
    $event->setLines(0,"[WYR]");
                        
    $event->setLines(1,"Adult");
                    } elseif(
    $sign[1] === "funny"){
                        
    $event->setLines(0,"[WYR]");
                        
    $event->setLines(1,"Funny");
                    } elseif(
    $sign[1] === "hard"){
                        
    $event->setLines(0,"[WYR]");
                        
    $event->setLines(1,"Hard");
                    }
                }
            }
        }
      
        public function 
    onSignTouch(PlayerInteractEvent $event){
            
    $this->signQuestion();
        }
      
        public function 
    onCommand(CommandSender $sender,Command $command,$label,array $args){
            
    $cmd $command->getName();
            if(
    $cmd == "wyr"){
                if(!isset(
    $args[0])){
                    
    $sender->sendMessage("/wyr <type>");
                    return;
                } else{
                    switch(
    $args[0]){
                        case 
    "help":
                            
    $sender->sendMessage("Types:");
                            
    $sender->sendMessage("children");
                            
    $sender->sendMessage("adult");
                            
    $sender->sendMessage("funny");
                            
    $sender->sendMessage("hard");
                        break;
                        case 
    "children":
                            
    $getQuestion $this->getQuestion("children-questions");
                            
    $this->getServer()->broadcastMessage($getQuestion);
                        break;
                        case 
    "adult":
                            
    $getQuestion $this->getQuestion("adult-questions");
                            
    $this->getServer()->broadcastMessage($getQuestion);
                        break;
                        case 
    "funny":
                            
    $getQuestion $this->getQuestion("funny-questions");
                            
    $this->getServer()->broadcastMessage($getQuestion);
                        break;
                        case 
    "hard":
                            
    $getQuestion $this->getQuestion("hard-questions");
                            
    $this->getServer()->broadcastMessage($getQuestion);
                        break;
                    }
                }
            }
        }
    }
    ?>
    Last edited: Mar 12, 2016
  2. Lambo
    Offline

    Lambo Notable Member Plugin Developer

    Joined:
    Sep 14, 2013
    Posts:
    431
    Plugins:
    4
    Minecraft User:
    Lambo
    If you don't know PHP, you should probably learn some and then come back here to ask your questions.
    Last edited: Mar 12, 2016
  3. FlamingGenius
    Offline

    FlamingGenius Active Member

    Joined:
    Sep 23, 2015
    Posts:
    173
    Minecraft User:
    FlamingGenius
    *facepalm* you read it wrong I know PHP I just dont know if I can add parameters like that when using SignChangeEvent
  4. Hotshot_9930
    Offline

    Hotshot_9930 Notable Member Plugin Developer

    Joined:
    May 26, 2014
    Posts:
    665
    Plugins:
    2
    Minecraft User:
    HotshotHD
    You should host a server locally to test your plugins.
    applqpak likes this.
  5. PEMapModder
    Offline

    PEMapModder Notable Member Plugin Developer

    Joined:
    Oct 9, 2013
    Posts:
    7,294
    Plugins:
    11
    Minecraft User:
    PEMapModder
    Parameters like what?
  6. FlamingGenius
    Offline

    FlamingGenius Active Member

    Joined:
    Sep 23, 2015
    Posts:
    173
    Minecraft User:
    FlamingGenius
    i changed the code from what it was when I originally posted this cause I went ahead and coded what I wanted not sure if its correct I believe it is but who knows somebody usually tells me im wrong XD

Share This Page

Advertisement