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

How create timer in function onInteract?

Comments in 'Plugin Development' started by TheMaks, Sep 11, 2015.

  1. TheMaks
    Offline

    TheMaks Active Member

    Joined:
    Jul 19, 2015
    Posts:
    58
    Minecraft User:
    TheMaks
    Help me please.
    I went timer for onInteract
  2. PEMapModder
    Offline

    PEMapModder Notable Member Plugin Developer

    Joined:
    Oct 9, 2013
    Posts:
    7,294
    Plugins:
    11
    Minecraft User:
    PEMapModder
    What does function onInteract mean?
  3. Primus
    Offline

    Primus Notable Member

    Joined:
    Apr 7, 2015
    Posts:
    1,470
    Minecraft User:
    PrimusLV
    on \pocketmine\event\player\PlayerInteractEvent
  4. Hotshot_9930
    Offline

    Hotshot_9930 Notable Member Plugin Developer

    Joined:
    May 26, 2014
    Posts:
    665
    Plugins:
    2
    Minecraft User:
    HotshotHD
    You should explain what you need help with some more.
  5. Primus
    Offline

    Primus Notable Member

    Joined:
    Apr 7, 2015
    Posts:
    1,470
    Minecraft User:
    PrimusLV
    He wants to trigger timer onInteract.
  6. PEMapModder
    Offline

    PEMapModder Notable Member Plugin Developer

    Joined:
    Oct 9, 2013
    Posts:
    7,294
    Plugins:
    11
    Minecraft User:
    PEMapModder
    Please note that onInteract isn't a standard name. If can be anything.
    CrazedMiner likes this.
  7. Gamecrafter
    Offline

    Gamecrafter

    Joined:
    Nov 20, 2014
    Posts:
    978
    Plugins:
    9
    No, you're just assuming. It could be anything. :p Example:
    PHP:
    function onInteract(PlayerMoveEvent $event){
       
    //see?
    }
    Taha_The_Hacker likes this.
  8. Kvetinac97
    Offline

    Kvetinac97 Active Member Plugin Developer

    Joined:
    Nov 17, 2014
    Posts:
    276
    Plugins:
    1
    Minecraft User:
    Kvetinac97
    He propably needs to schedule new delayed/repeating task:
    PHP:
    public function onInteract(PlayerInteractEvent $ev){
     
    $this->getServer()->getScheduler()->scheduleRepeatingTask(new Timer($this,$ev),1*20); //You can change scheduleRepeating to scheduleDelayed and you can replace 1*20 with other time (write it in ticks!)
    }
    PianoPlayer38 and TheKofola12 like this.
  9. PEMapModder
    Offline

    PEMapModder Notable Member Plugin Developer

    Joined:
    Oct 9, 2013
    Posts:
    7,294
    Plugins:
    11
    Minecraft User:
    PEMapModder
  10. Brutus
    Offline

    Brutus New Member

    Joined:
    Aug 31, 2015
    Posts:
    21
    I am going to take a shot in the dark and assume the OP is talking about anonymous classes, which would be commonly used in Bukkit for what he is trying to do: create an implementation of a PluginTask within his "onInteract()" method.

    Great news! Anonymous classes do not exist in PHP, hooray! At least not exactly. You cannot simply create a new anonymous instance of PluginTask inside of a method. You would have to make it its own real class MyTimer extends PluginTask.

    This appears to be a more detailed discussion of the issue: http://www.clock.co.uk/blog/mimicking-anonymous-classes-in-php-using-closures

Share This Page

Advertisement