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

What Wrong My Code ?!

Comments in 'Plugin Development' started by DevWars, Dec 12, 2015.

  1. DevWars
    Offline

    DevWars Banned

    Joined:
    Nov 7, 2015
    Posts:
    28
    Minecraft User:
    PmServer
    PHP:
    public function PlayerMsg(Player $player) {
            
    $this->seconds $this->seconds 1;
            
    $player->sendPopup("آ§eThe game will start in $this->seconds second(s)!");
        }
    }
    class 
    AutoTask extends PluginTask
    {
        public function 
    __construct(Plugin $owner) {
            
    parent::__construct($owner);
        }
        public function 
    onRun($currentTick){
           
           
            
    $this->getOwner()->PlayerMsg();
        }}
  2. CraftYourBukkit
    Offline

    CraftYourBukkit Notable Member Plugin Developer

    Joined:
    Jan 20, 2015
    Posts:
    1,022
    Plugins:
    2
    Minecraft User:
    CraftYourBukkit
    PHP:
    class AutoTask extends PluginTask {

        public 
    $prefix;
        public 
    $sec 10;

        public function 
    __construct($pluginPlayer $player) {
            
    $this->plugin $plugin;
            
    $this->player $player;
            
    parent::__construct($plugin);
        }

        public function 
    onRun($tick) {
            
    $this->sec--;
            if (
    $this->sec != 0) {
                
    $this->player->sendPopup(TextFormat::YELLOW "The game will start in $this->seconds " . ($this->sec === 1) ? "second" "seconds" "!");
            } else {
                
    $this->player->sendPopup(TextFormat::YELLOW "The game started!");
            }
        }

    }
  3. Dinokiller
    Offline

    Dinokiller Notable Member

    Joined:
    Sep 22, 2013
    Posts:
    376
    Minecraft User:
    Dinokiller_
    What's wrong with your code? Meh, everything.
    applqpak and Gamecrafter like this.
  4. DevWars
    Offline

    DevWars Banned

    Joined:
    Nov 7, 2015
    Posts:
    28
    Minecraft User:
    PmServer
    PHP:
    <?php

    namespace TimeTask;

    use 
    pocketmine\plugin\PluginBase;
    use 
    pocketmine\scheduler\PluginTask;
    use 
    pocketmine\event\Listener;
    use 
    pocketmine\Player;
    use 
    pocketmine\utils\TextFormat as Color;

    class 
    Main extends PluginBase implements Listener{
      public 
    $min 20;
    public function 
    onEnable(){
        
    $this->getServer()->getScheduler()->scheduleRepeatingTask(new Timer($this), 60);
            
    $this->getLogger()->info(Color::GREEN."Has Enable !");
          
        }
      
    }
    class 
    Timer extends PluginTask{
      public function 
    __construct($plugin){
        
    $this->plugin $plugin;
        
    parent::__construct($plugin);
      }

      public function 
    onRun($tick){ //every minute the "timer" runs this function
        
    $this->plugin->min $this->plugin->min 1;
          foreach(
    $this->plugin->getServer()->getOnlinePlayers() as $p){
            
    $p->sendPopup("Game starts in ".$this->plugin->min." minutes");
        if(
    $this->plugin->min === 0){
          
    $p->sendMessage("Game Is End !");
        }
      }
    }}
    ^ What Wrong This !
  5. PocketKiller
    Offline

    PocketKiller Notable Member

    Joined:
    Jul 20, 2015
    Posts:
    741
    :facepalm: he created a Task class, no need for a file, he created the class on the main file.
  6. TutoGamerWalid
    Offline

    TutoGamerWalid Active Member

    Joined:
    Jun 11, 2015
    Posts:
    69
    Minecraft User:
    TutoGamerWalid
    PHP:
    public function __construct(Main $plugin){ //add Main x)
    xiaoq and iDirtPlayzMC like this.

Share This Page

Advertisement