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

Solved What's wrong ?

Comments in 'Plugin Development' started by Asparanc, Oct 19, 2015.

  1. Asparanc
    Offline

    Asparanc Active Member

    Joined:
    Feb 20, 2015
    Posts:
    210
    Minecraft User:
    Asparanc
    Title say all.

    PHP:
    <?php
    namespace ER\Task;

    use 
    pocketmine\level\format\Chunk;
    use 
    pocketmine\level\Level;
    use 
    pocketmine\math\Vector3;
    use 
    pocketmine\scheduler\AsyncTask;
    use 
    pocketmine\Player;
    use 
    pocketmine\block\Block;
    use 
    pocketmine\Server;

    use 
    ER\Main;
    class 
    RestoreTask extends AsyncTask{
        public function 
    __construct(Main $plugin$arena){
           
    $this->plugin $plugin;

    $this->arena $arena;
        }
     
        public function 
    onRun(){


    $arena $this->arena;


    $this->plugin->getServer()->loadLevel($arena['level']);
    foreach(
    $arena["backup"] as $id => $b){
    $p $b['pos'];
    $this->plugin->getServer()->getLevelByName($arena['level'])->setBlock(new Vector3($p->getX(), $p->getY(), $p->getZ()), Block::get($b['id'], $b["damage"]));
    }



    $this->plugin->savee();

    $this->plugin->getServer()->broadcastMessage("§l§e[§2RUSH§e] §r§6Une arène à été réinitialisé et est de nouveau ouverte !");
        }
       
    }
    Error :
    Code:
    18.10 19:39:08 [Server] Server thread/CRITICAL Exception: "Serialization of 'Closure' is not allowed" (EXCEPTION) in "/EpicRush/src/ER/Task/RestoreTask" at line 16
    18.10 19:39:08 [Server] Server thread/CRITICAL Unhandled exception executing command 'rush restore Rush1' in rush: Serialization of 'Closure' is not allowed
  2. PocketKiller
    Offline

    PocketKiller Notable Member

    Joined:
    Jul 20, 2015
    Posts:
    741
    Well... add
    PHP:
        parent::__construct($plugin);
    in __construct
    SeifValkierks likes this.
  3. PocketKiller
    Offline

    PocketKiller Notable Member

    Joined:
    Jul 20, 2015
    Posts:
    741
    No.
  4. Asparanc
    Offline

    Asparanc Active Member

    Joined:
    Feb 20, 2015
    Posts:
    210
    Minecraft User:
    Asparanc
    PHP:
    case 'restore':


    $this->getServer()->getScheduler()->scheduleAsyncTask(new RestoreTask($this$this->arenas[$args[1]]));
    return 
    true;
    break;
    It's all what i can give you.
  5. PocketKiller
    Offline

    PocketKiller Notable Member

    Joined:
    Jul 20, 2015
    Posts:
    741
    There is no need to tell us. he was wrong.
  6. Asparanc
    Offline

    Asparanc Active Member

    Joined:
    Feb 20, 2015
    Posts:
    210
    Minecraft User:
    Asparanc
    Code:
    Error: Cannot call constructor
    File: /EpicRush/src/ER/Task/RestoreTask
    Line: 16
    Type: E_ERROR
    
    THIS CRASH WAS CAUSED BY A PLUGIN
    BAD PLUGIN: EpicRush v1.0.0
    
    Code:
    [7] use pocketmine\scheduler\AsyncTask;
    [8] use pocketmine\Player;
    [9] use pocketmine\block\Block;
    [10] use pocketmine\Server;
    [11]
    [12] use ER\Main;
    [13] class RestoreTask extends AsyncTask{
    [14]     public function __construct(Main $plugin, $arena){
    [15]        
    [16] $this->plugin = parent::__construct($plugin);
    [17]
    [18] $this->arena = parent::__construct($arena);
    [19]     }
    [20]  
    [21]     public function onRun(){
    [22]
    [23]
    [24] $arena = $this->arena;
    [25]
    [26]
    
    New error
  7. Gamecrafter
    Offline

    Gamecrafter

    Joined:
    Nov 20, 2014
    Posts:
    978
    Plugins:
    9
    Learn OOP. It should be just parent::__construct($plugin);, nothing else. Remove $this->arena = parent::__construct($arena) and $this->plugin =.
    Taha_The_Hacker likes this.
  8. Asparanc
    Offline

    Asparanc Active Member

    Joined:
    Feb 20, 2015
    Posts:
    210
    Minecraft User:
    Asparanc
    It work without parent::__construct in Repeating and delayed task :(
  9. PocketKiller
    Offline

    PocketKiller Notable Member

    Joined:
    Jul 20, 2015
    Posts:
    741
    it does, but to use $this->arena, $this->plugin is needed.
  10. Asparanc
    Offline

    Asparanc Active Member

    Joined:
    Feb 20, 2015
    Posts:
    210
    Minecraft User:
    Asparanc
    Oh yes that's true i've forgot this detail ^^ i've check my old Task in my others plugins ^^ i use it rarely ^^
  11. Asparanc
    Offline

    Asparanc Active Member

    Joined:
    Feb 20, 2015
    Posts:
    210
    Minecraft User:
    Asparanc
    PHP:
    <?php
    namespace ER\Task;

    use 
    pocketmine\level\format\Chunk;
    use 
    pocketmine\level\Level;
    use 
    pocketmine\math\Vector3;
    use 
    pocketmine\scheduler\AsyncTask;
    use 
    pocketmine\Player;
    use 
    pocketmine\block\Block;
    use 
    pocketmine\Server;

    use 
    ER\Main;
    class 
    RestoreTask extends AsyncTask{
    public function 
    __construct(Main $plugin$arena){
    parent::__construct($plugin);
    $this->plugin $plugin;
    $this->arena $arena;


    }


     
        public function 
    onRun(){


    $arena $this->arena;


    $this->plugin->getServer()->loadLevel($arena['level']);
    foreach(
    $arena["backup"] as $id => $b){
    $p $b['pos'];
    $this->plugin->getServer()->getLevelByName($arena['level'])->setBlock(new Vector3($p->getX(), $p->getY(), $p->getZ()), Block::get($b['id'], $b["damage"]));
    }



    $this->plugin->savee();

    $this->plugin->getServer()->broadcastMessage("§l§e[§2RUSH§e] §r§6Une arène à été réinitialisé et est de nouveau ouverte !");
        }
       
    }
    Code:
    Error: Cannot call constructor
    File: /EpicRush/src/ER/Task/RestoreTask
    Line: 16
    Type: E_ERROR
    
    THIS CRASH WAS CAUSED BY A PLUGIN
    BAD PLUGIN: EpicRush v1.0.0
    
    Code:
    [7] use pocketmine\scheduler\AsyncTask;
    [8] use pocketmine\Player;
    [9] use pocketmine\block\Block;
    [10] use pocketmine\Server;
    [11]
    [12] use ER\Main;
    [13] class RestoreTask extends AsyncTask{
    [14]     public function __construct(Main $plugin, $arena){
    [15]        
    [16] $this->plugin = parent::__construct($plugin);
    [17]
    [18] $this->arena = parent::__construct($arena);
    [19]     }
    [20]  
    [21]     public function onRun(){
    [22]
    [23]
    [24] $arena = $this->arena;
    [25]
    [26] 

    It's a joke ?--'
  12. Asparanc
    Offline

    Asparanc Active Member

    Joined:
    Feb 20, 2015
    Posts:
    210
    Minecraft User:
    Asparanc
    Code:
    Error: Cannot call constructor
    File: /EpicRush/src/ER/Task/RestoreTask
    Line: 15
    Type: E_ERROR
    
    THIS CRASH WAS CAUSED BY A PLUGIN
    BAD PLUGIN: EpicRush v1.0.0
    
    Code:
    [6] use pocketmine\math\Vector3;
    [7] use pocketmine\scheduler\AsyncTask;
    [8] use pocketmine\Player;
    [9] use pocketmine\block\Block;
    [10] use pocketmine\Server;
    [11]
    [12] use ER\Main;
    [13] class RestoreTask extends AsyncTask{
    [14] public function __construct(Main $plugin, $arena){
    [15] parent::__construct($plugin);
    [16] $this->plugin = $plugin;
    [17] $this->arena = $arena;
    [18]
    [19]
    [20] }
    [21]
    [22]
    [23]  
    [24]     public function onRun(){
    [25] 
  13. Gamecrafter
    Offline

    Gamecrafter

    Joined:
    Nov 20, 2014
    Posts:
    978
    Plugins:
    9
    Oh, I saw wrong. You're not supposed to have anything to do with the PocketMine API when using AsyncTask.
    Taha_The_Hacker and Legoboy0215 like this.
  14. Asparanc
    Offline

    Asparanc Active Member

    Joined:
    Feb 20, 2015
    Posts:
    210
    Minecraft User:
    Asparanc
    This is to restore the arena after match ended :(
  15. Legoboy0215
    Offline

    Legoboy0215 Notable Member

    Joined:
    Nov 1, 2014
    Posts:
    1,724
    Minecraft User:
    Legoboy0215
    Finally, you noticed :)
    What is line 16?
  16. Asparanc
    Offline

    Asparanc Active Member

    Joined:
    Feb 20, 2015
    Posts:
    210
    Minecraft User:
    Asparanc
    Look at line 14 :)
  17. Legoboy0215
    Offline

    Legoboy0215 Notable Member

    Joined:
    Nov 1, 2014
    Posts:
    1,724
    Minecraft User:
    Legoboy0215
    WTH is Closure? :confused:
  18. PEMapModder
    Offline

    PEMapModder Notable Member Plugin Developer

    Joined:
    Oct 9, 2013
    Posts:
    7,294
    Plugins:
    11
    Minecraft User:
    PEMapModder
    No objects can be shared between the main thread and AsyncTask.
  19. WillBoxGaming
    Offline

    WillBoxGaming New Member

    Joined:
    Aug 12, 2015
    Posts:
    9
    Minecraft User:
    WillBoxGaming
    First of all, i'm french ;3 so I can correct this ONLY thing for you.. (Lol)

    Une arène a été réinitialisée. Elle est de nouveau ouverte.

    For the code, I just don't know xD
  20. PEMapModder
    Offline

    PEMapModder Notable Member Plugin Developer

    Joined:
    Oct 9, 2013
    Posts:
    7,294
    Plugins:
    11
    Minecraft User:
    PEMapModder
    Wrong.
    You can actually share Threaded objects between them, but the Server object isn't Threaded, so you basically can't interact with the server and plugin, since most PocketMine objects (and your plugin) have reference to PocketMine.
    Normal objects can also be shared, but they will be serialized, so in the other threads they will act as clones of the objects, which will actually do nothing that affect the server.
    It doesn't matter if they are class fields or global variables or what. It only depends on the data types.
    jojoe77777 likes this.

Share This Page

Advertisement