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

Solved RepeatingTask Critical

Comments in 'Plugin Development' started by Taha_The_Hacker, Sep 20, 2015.

  1. PocketKiller
    Offline

    PocketKiller Notable Member

    Joined:
    Jul 20, 2015
    Posts:
    741
    Hi,

    I just tried to use RepeatingTask But it doesn't work. here are some info:
    Code:
    "Could not pass event 'pocketmine\event\block\SignChangeEvent' to 'Anvil v2.3': Argument 1 passed to TahaTheHacker\Anvil\Timer::__construct() must be an instance of TahaTheHacker\Anvil\Timer, instance of TahaTheHacker\Anvil\Main given, called in phar://C:/Users/somewhere/Desktop/somewhere/somewhere/somewhere/plugins/phar_Anvil-master (96)_z6KJL3QYx1D4Fw6.phar/src/TahaTheHacker/Anvil/Main.php on line 76 and defined on TahaTheHacker\Anvil\Main
    

    PHP:
        public function onSignCreate(SignChangeEvent $event){
            
    $player $event->getPlayer(); //Get the player
        
    $this->getServer()->getScheduler()->scheduleRepeatingTask(new Timer($this ,$event ,$player), 60);//line 76
            
    $line_0 $event->getLine(0); //The sign's line 1 (Despite the number)
            
    $line_1 $event->getLine(1); //The sign's line 2
            
    if(strtolower($line_0) === "[sg]" && !empty($line_1)){ //Check if the line 1 is equal to [sg] (Since strtolower) and if line 1 is not empty
                
    $level $this->getServer()->getLevelByName($line_1); //Get the level object with the name of $line_1
                
    if(!$this->getServer()->isLevelGenerated($line_1)){ //Check if level is generated
                    
    $player->sendMessage("Failed, Not found."); //LOL
                    
    return false//Return a boolean value of false
                
    }
                
    $player->sendMessage("Created!"); //AGAIN LOL
                    
    $event->setLine(0"§c[§l§6SG§r§c]""[" count($level->getPlayers()) . "/10]""§l§aTap To Join"); //Set the text. BTW, better use TextFormat::**
                    
    $event->setLine(1"Map :§l§a" $line_1);
                    
    $event->setLine(2"§l§b[" count($level->getPlayers($line_1)) . "/10]");
                    
    $event->setLine(3"§l§6Tap To Join");
            }
        }

    PHP:
    <?php
    namespace TahaTheHacker\Anvil;
    use 
    pocketmine\scheduler\PluginTask;
    use 
    pocketmine\level\Level;
    use 
    pocketmine\Player;
    use 
    pocketmine\Server;
    use 
    pocketmine\event\block\SignChangeEvent;
    use 
    pocketmine\item\item;
    use 
    pocketmine\tile\Sign;
    use 
    pocketmine\scheduler\ServerScheduler;
    use 
    pocketmine\level\Position;
    class 
    Timer extends PluginTask {
    public function 
    __construct(Timer $plugin$player){//line 18
    $this->plugin $plugin;
    $this->player $player;
    parent::__construct($plugin);
    }
    public function 
    onRun($tick) {
    $this->plugin->onSignCreate();
    }
    }
    //Class

    I was on the computer 5 hours searching about it in pocketmine's search bar.
  2. Kvetinac97
    Offline

    Kvetinac97 Active Member Plugin Developer

    Joined:
    Nov 17, 2014
    Posts:
    276
    Plugins:
    1
    Minecraft User:
    Kvetinac97
    PHP:
    public function __construct(Main $something$ev$player){
  3. PocketKiller
    Offline

    PocketKiller Notable Member

    Joined:
    Jul 20, 2015
    Posts:
    741
    Thanks lemme try
  4. PocketKiller
    Offline

    PocketKiller Notable Member

    Joined:
    Jul 20, 2015
    Posts:
    741
    Didn't work.
  5. Gamecrafter
    Offline

    Gamecrafter

    Joined:
    Nov 20, 2014
    Posts:
    978
    Plugins:
    9
    Look at plugins with tasks and learn from them.
  6. Hotshot_9930
    Offline

    Hotshot_9930 Notable Member Plugin Developer

    Joined:
    May 26, 2014
    Posts:
    665
    Plugins:
    2
    Minecraft User:
    HotshotHD
    PHP:
    public function __construct(Main $pluginPlayer $player) {
    parent::__construct($plugin$player);
    $this->plugin $plugin;
    $this->player $player;
    }
    "Main" has to be the name of your main class
  7. PocketKiller
    Offline

    PocketKiller Notable Member

    Joined:
    Jul 20, 2015
    Posts:
    741
    didn't work.
  8. Hotshot_9930
    Offline

    Hotshot_9930 Notable Member Plugin Developer

    Joined:
    May 26, 2014
    Posts:
    665
    Plugins:
    2
    Minecraft User:
    HotshotHD
    PHP:
    $this->getServer()->getScheduler()->scheduleRepeatingTask(new Timer($this ,$event ,$player), 60);
    Should be:
    PHP:
    $this->getServer()->getScheduler()->scheduleRepeatingTask(new Timer($this$player), 60);
  9. Gamecrafter
    Offline

    Gamecrafter

    Joined:
    Nov 20, 2014
    Posts:
    978
    Plugins:
    9
    Look at EasyMessages v1.1.0, I think it'd be pretty simple to understand the concept.
    Taha_The_Hacker likes this.
  10. PocketKiller
    Offline

    PocketKiller Notable Member

    Joined:
    Jul 20, 2015
    Posts:
    741
    Worked :)

    Thanks for helping :)

    sorry for all that, i am a beginner on PHP that's why.
  11. MCPEPIG
    Offline

    MCPEPIG Notable Member

    Joined:
    Jun 22, 2014
    Posts:
    349
    Minecraft User:
    MCPEPIG
    I think you mean You don't know PHP at ALL.
    thebigsmileXD likes this.
  12. Gamecrafter
    Offline

    Gamecrafter

    Joined:
    Nov 20, 2014
    Posts:
    978
    Plugins:
    9
    Everybody has beginnings, and stop talking like you're a whole lot better than him, because you aren't. This guy is still learning, he's only been here for 3 months.
  13. MCPEPIG
    Offline

    MCPEPIG Notable Member

    Joined:
    Jun 22, 2014
    Posts:
    349
    Minecraft User:
    MCPEPIG
    You can look at his code for yourself... I think he copy and pasted it from how it looks. https://github.com/TahaTheHacker/Anvil
  14. Gamecrafter
    Offline

    Gamecrafter

    Joined:
    Nov 20, 2014
    Posts:
    978
    Plugins:
    9
    I can already tell he didn't completely code it on his own, but that still doesn't mean you can be rude to him. Still remember me a little more than half a year ago? If you remember me then and look at me now, you'll notice how much I've changed.
  15. MCPEPIG
    Offline

    MCPEPIG Notable Member

    Joined:
    Jun 22, 2014
    Posts:
    349
    Minecraft User:
    MCPEPIG
    You mean when you attempted to make iCore? :3
    jojoe77777 likes this.
  16. Gamecrafter
    Offline

    Gamecrafter

    Joined:
    Nov 20, 2014
    Posts:
    978
    Plugins:
    9
    Precisely. And also mind that I didn't have any knowledge of the PHP language, so I copied other's code. But I actually took the initiative to learn PHP and cut the habit of copying code. You should encourage him to learn PHP, not put him down. ;)
  17. Hotshot_9930
    Offline

    Hotshot_9930 Notable Member Plugin Developer

    Joined:
    May 26, 2014
    Posts:
    665
    Plugins:
    2
    Minecraft User:
    HotshotHD
    Well copying and pasting isnt all that bad sometimes. If he really does care about learning php and pm api, he would study the code he copies and try to understand what it does + copy and pasting other people's code will help him to find new methods of doing things and sparking new ideas for him.
    Yes, copying and pasting is frowned upon but as beginners i think almost everyone copy and pasted something before. Its just natural.
    So we should support him while he's learning and eventually he would be able to code without copy and paste(Hopefully).
    Taha_The_Hacker likes this.
  18. Legoboy0215
    Offline

    Legoboy0215 Notable Member

    Joined:
    Nov 1, 2014
    Posts:
    1,724
    Minecraft User:
    Legoboy0215
    You sometimes do that too :p
  19. aliuly
    Offline

    aliuly Notable Member Plugin Developer

    Joined:
    Feb 8, 2014
    Posts:
    1,086
    Plugins:
    17
    I don't mind if people copy / paste my code. It is all in GPL, so you are welcome to it.
    What do I mind is when people then break something (that they did) and expect me to fix it. As the GPL clearly states, the code comes without warranty. So if you break it, you get to keep both pieces.
  20. PocketKiller
    Offline

    PocketKiller Notable Member

    Joined:
    Jul 20, 2015
    Posts:
    741
    i really copy and paste codes from plugins, but i always try to know how it works, because if i didn't, my plugin will ever work, because some use $ev instead of $event. and variables, tags, arguments...

Share This Page

Advertisement