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

What is CallbackTask and what is the alternative for it?

Comments in 'Plugin Development' started by Thunder33345, Jun 2, 2016.

  1. Thunder33345
    Offline

    Thunder33345 Notable Member

    Joined:
    Apr 3, 2014
    Posts:
    755
    Minecraft User:
    Thunder33345
    Before you type anything yes i get it you shouldn't be using it but i am just curious what it [is] does(even tho it no longer exist),
    what is the [replacement] alternative for it
    I assume just use scheduler and the type you want with new ClassName($param)
    and why it is removed(curious about it)?
    Suppert12 likes this.
  2. HotFireyDeath
    Offline

    HotFireyDeath Notable Member Plugin Developer

    Joined:
    Mar 19, 2015
    Posts:
    328
    Plugins:
    1
    Minecraft User:
    HotFireyDeath
    I have not used CallbackTask myself, but callback is a parameter passed into a method, and the method will eventually call the callback method (or in this case, class) you passed in.

    I believe today there is a onComplete() method in standard tasks, which removes the purpose of providing a CallbackTask when you can run what you need inside the onComplete() method, which serves the same purpose.
    Legoboy0215 likes this.
  3. Legoboy0215
    Offline

    Legoboy0215 Notable Member

    Joined:
    Nov 1, 2014
    Posts:
    1,724
    Minecraft User:
    Legoboy0215
    TBH, CallbackTask is for lazy people.
    CrazedMiner likes this.
  4. Thunder33345
    Offline

    Thunder33345 Notable Member

    Joined:
    Apr 3, 2014
    Posts:
    755
    Minecraft User:
    Thunder33345
    *make a call back task for my plugins in a class because i am THAT lazy*
  5. CraftYourBukkit
    Offline

    CraftYourBukkit Notable Member Plugin Developer

    Joined:
    Jan 20, 2015
    Posts:
    1,022
    Plugins:
    2
    Minecraft User:
    CraftYourBukkit
    Might or might not be true, but how does that answer his question?
    But, I would say the same as @HotFireyDeath. Haven't used them ever, though.
  6. Tim // robske Büba
    Offline

    Tim // robske Büba Notable Member

    Joined:
    Feb 26, 2014
    Posts:
    606
    Minecraft User:
    robske_110
    I think it simply got replaced with DelayedTask and or scheudledTask during some early versions of the new API or even got removed while converting from old api to new api
  7. SOFe
    Offline

    SOFe Banned

    Joined:
    May 28, 2016
    Posts:
    386
    Minecraft User:
    Herobrine
    CallbackTask extends Task. scheduleDelayedTask and scheduleRepeatingTask are methods, not tasks.

    CallbackTask was first introduced here, but it never got widely used.

    There is no relationship between a CallbackTask and the AsyncTask::onCompletion() method.
    Last edited: Jun 3, 2016
  8. AndrewBit
    Offline

    AndrewBit Notable Member

    Joined:
    Jun 18, 2015
    Posts:
    435
    Minecraft User:
    AndrewBit4
    You can simply use a RepeatingTask calling the method.
    PHP:
    public function onRun($currentTick) {
            
    $this->classInstance->tick();
    }
  9. SOFe
    Offline

    SOFe Banned

    Joined:
    May 28, 2016
    Posts:
    386
    Minecraft User:
    Herobrine
    The concept of a RepeatingTask doesn't exist. It can be a repeating Task, but "RepeatingTask" used as one word shows that you have incorrect understanding on the scheduler system.
    Thunder33345 likes this.
  10. CrazedMiner
    Offline

    CrazedMiner Notable Member Plugin Developer

    Joined:
    Jan 31, 2015
    Posts:
    348
    Plugins:
    2
    Minecraft User:
    CrazedMinerYT
    Every single post you've made on this forum shows you have no understanding of PocketMine or how it works.

    A call back task quite literally 'calls back'. When you initiate a call back task it requires you to define a callable function along with its class that is called upon execution.

    Basically using a callback task is bad practise now days cus #BlameShogi. We could either repeat the same task over again with a repeating task or continue to schedule delayed tasks to achieve the same result.
  11. SOFe
    Offline

    SOFe Banned

    Joined:
    May 28, 2016
    Posts:
    386
    Minecraft User:
    Herobrine
    Yes, I know what a callable is. And you don't need to define a callable function along with its class. These are all callables:
    PHP:
    assert(is_callable("strlen"));
    assert(is_callable("Phar::running"));
    assert(is_callable(["Phar""running"]));
    assert(is_callable([new ReflectionClass("Phar"), "getShortName"]));
    assert(is_callable(function(){ echo "I am a closure"; }));
    (This is PHP knowledge btw)
    Yet, a Task is a Task. A CallbackTask is also a Task. A Task is essentially like the java.lang.Runnable interface in Java (fine, it is an abstract class, and with other virtual methods such as onCancel() and actual methods like getTaskId(), happy now?), except that it also manages a TaskHandler.
    In my post above, I mentioned that there doesn't exist something in PocketMine called "RepeatingTask", only a scheduleRepeatingTask function. If you say "RepeatingTask", it implies that there exist something called RepeatingTask, while there doesn't. You can schedule a task and make it repeat, but from the PocketMine scheduler's perspective, a (delayed-) repeating task and a delayed task have no difference, as they are both tasks. Actually, the Task itself doesn't even directly store information about whether it is delayed or repeating. You can say that you can schedule a repeating task, but by saying "use a RepeatingTask", it sounds like there is actually something called RepeatingTask.

    There may be partial error in some of my posts, but if you think that every post that I make is wrong, please, I urge you to point out your evidence rather than meaninglessly claiming that it is ignorant. I may be a new member on the forums, but that doesn't mean that you can discriminate me as a noob on understanding PocketMine.
  12. minebuilder0110
    Offline

    minebuilder0110 Notable Member

    Joined:
    Dec 8, 2014
    Posts:
    485
    Minecraft User:
    Apparitional
    I recall that PEMapModder once saying that it's better not to know about CallBackTask at all... Can't find that post though.
  13. SOFe
    Offline

    SOFe Banned

    Joined:
    May 28, 2016
    Posts:
    386
    Minecraft User:
    Herobrine
    I don't agree that CallbackTask is that evil. If you work with PocketMine core code, it is actually useful if you want to test something fast.
    Also, you could create a PluginCallbackTask yourself, such as https://github.com/PocketMine/PocketMine-MP/pull/2943

    PHP 7 introduces anonymous classes. You can now schedule a delayed task like this:
    PHP:
    assert($plugin instanceof \pocketmine\plugin\Plugin);
    $plugin->scheduleDelayedTask(new class($plugin) extends PluginTask{
      public function 
    onRun($ticks){
        
    // code
      
    }
    }, 
    1);
  14. CrazedMiner
    Offline

    CrazedMiner Notable Member Plugin Developer

    Joined:
    Jan 31, 2015
    Posts:
    348
    Plugins:
    2
    Minecraft User:
    CrazedMinerYT
    'Implying'. 'Understanding'.

    If I were to make a class that extends PocketMine's Task class I would probably write the task to either be repeated or delayed, this is why us humans of higher knowledge refer to tasks as either 'delayed tasks' or 'repeating tasks'. My point is that you're most likely going to be writing a task that is either going to be 'run' with a delay or the same instance will be 'run' repeatedly as it's very rare a task is made to be both delayed and repeated. PocketMine's task scheduler runs on a time based system, it records the next tick a task should be 'run' and 'runs' it whenever that next tick becomes the present tick.
  15. SOFe
    Offline

    SOFe Banned

    Joined:
    May 28, 2016
    Posts:
    386
    Minecraft User:
    Herobrine
    What?
    Delaying a task or repeating a task is an action. When a task is scheduled to be repeated, it is a repeating task from plugin's perspective. If a task is scheduled to be delayed, it is a delayed task from plugin's perspective. But if you put "DelayedTask" as one word, it implies that there exists a term, or more frequently in object-oriented programmers' practice, a type name, called "DelayedTask". And there is no such type or term called DelayedTask in PocketMine. A delayed task can be scheduled as a repeating task anytime, and a repeating task can be cancelled anytime and scheduled as a delayed task anytime. If it were a type name, you can't "change" its type.

    Also, scheduling tasks is one of the most fundamental elements in PocketMine plugin development. Even though I am very new, at least I know that scheduling tasks is just one level above the basic plugin.yml and PluginBase stuff. Commands, events and scheduling tasks are the three elements of plugin triggering. Without them, a plugin is basically useless. (Two exceptions I can think of: 1) a plugin that merely does something on enable or disable, such as triggering a webhook to notify that the server is started/stopped; 2) a thread-based plugin like Volt by @Falk). It is certainly not something that only "humans of higher knowledge" would refer to. Instead, "humans of higher knowledge" should treat the myriad things in programming the same. A programmer of advanced knowledge about computer science can treat a certain memory byte from another process and manipulate it the same way as a certain memory byte from their own process (this is called hacking). Even if we humans of lower knowledge, at least we should treat instances of the same type the same, much less the same instance. We don't need to be a sage in programming to regard the same instance to be the same thing.
    Also note, a very high level of programming is that the level of understanding of data such that every memory byte, every memory unit, every file can be regarded as straw dogs (hacking), and the same memory unit can be treated as everything from a byte, an integer, a string, to an IP address. (the simple concept of a union in C/C++) This is also similar to this extract:
    Acting is not acting. By not acting you act.
    https://github.com/search?q=pocketmine scheduleDelayedRepeatingTask&type=Code
    I know that you won't be satisfied with this answer, as it is actually a repeating task that starts repeating at a delayed time. But as explained above, there is no problem and very reasonable if a repeating task gets cancelled and a delayed task of 1-tick delay
    No. It is not time-based. It is server-tick-based. Server ticking is based on a TPS-based process sleeping loop.
    Difference between time-based and server-tick-based:
    Time-based: As long as the server has enough load, a per-second task is run three times in three seconds. If we look at them as musical notes, normally it should have been three crotchets, but you may end up having a minim, then two quavers.
    Server-tick-based: If there is lag in the first second, even though there is plenty of server load to execute the tick again in the second and third seconds, the per-second task will only be run with the minimum interval of one second. That is, in terms of musical notes, it is one minim, then two crotchets, exceeding the three-times limit of the bar while the server has enough CPU to execute the third time within the three-times bar.
    HotFireyDeath likes this.
  16. Tim // robske Büba
    Offline

    Tim // robske Büba Notable Member

    Joined:
    Feb 26, 2014
    Posts:
    606
    Minecraft User:
    robske_110
    Also, scheduling tasks is one of the most fundamental elements in PocketMine plugin development. Even though I am very new, at least I know that scheduling tasks is just one level above the basic plugin.yml and PluginBase stuff. Commands, events and scheduling tasks are the three elements of plugin triggering. Without them, a plugin is basically useless. (Two exceptions I can think of: 1) a plugin that merely does something on enable or disable, such as triggering a webhook to notify that the server is started/stopped; 2) a thread-based plugin like Volt by @@Falk). It is certainly not something that only "humans of higher knowledge" would refer to. Instead, "humans of higher knowledge" should treat the myriad things in programming the same. A programmer of advanced knowledge about computer science can treat a certain memory byte from another process and manipulate it the same way as a certain memory byte from their own process (this is called hacking). Even if we humans of lower knowledge, at least we should treat instances of the same type the same, much less the same instance. We don't need to be a sage in programming to regard the same instance to be the same thing.


    --->Scheduling tasks is not the base of a plugin. The most plugins are listeners, wich are mostly more lightweight, although i do not use player moveevent (always scheduled task for that) But even my SSS(SignServerStats) wich has a thread, is using a repeating task to start the thread (And no, I'm not dumb I'm checking if the thread has finished)
  17. SOFe
    Offline

    SOFe Banned

    Joined:
    May 28, 2016
    Posts:
    386
    Minecraft User:
    Herobrine
    The only trouble about creating a task is that you need to make another task. I mentioned it is "elementary" as "level 2", where the word "level" is a level-upon-level system. For example, the Minecraft PE protocol is (was) built upon the RakNet protocol layer , and the RakNet protocol level is built upon the UDP level, and the UDP level is built upon the IP level, and IP upon the Ethernet level. Level upon level, that is how programming works.
    Here is a hierarchy of my understanding of the levels of understanding of plugin development:
    1. Creating a dummy plugin
    2. Commands, event listeners, scheduling tasks. These are the three basic things that you need to understand so as to actually make a plugin work, and you can learn any one of them without knowing the other two.
    3. Optimized use of API functions, rather than stupidly asking the machine to do things again and again
    4. Proper usage of threading in PocketMine for optimization
    5. Identifying inter-plugin dependencies and clashes.
    6. Resolving the problems identified in 5. Resolving is much harder than identifying.
    PHP knowledge does not depend on the understanding of PocketMine plugin development.
  18. Tim // robske Büba
    Offline

    Tim // robske Büba Notable Member

    Joined:
    Feb 26, 2014
    Posts:
    606
    Minecraft User:
    robske_110
    Totally agreed

Share This Page

Advertisement