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

Deregistering Listeners

Comments in 'Plugin Development' started by Tethered_, Jun 6, 2015.

  1. Tethered_
    Offline

    Tethered_ Active Member Plugin Developer

    Joined:
    Jun 24, 2014
    Posts:
    178
    Plugins:
    2
    Minecraft User:
    Frostbyte58
    I've got a plugin structure where each class has an $isRunning, and each plugin implements Listener and gets registered in my Main file. I have certain events that pretty much look like this:
    PHP:
    public function onBlockBreak(BlockBreakEvent $event)
    {
          if(
    $this->isRunning())
          {
                 
    //some stuff here
          
    }
    }
    I feel like its not a good idea to have a bunch of events that trigger that line of code every time, so is there a way to deregister an event?
  2. PEMapModder
    Offline

    PEMapModder Notable Member Plugin Developer

    Joined:
    Oct 9, 2013
    Posts:
    7,306
    Plugins:
    11
    Minecraft User:
    PEMapModder
    Calling just one getter function is minimal lag (unless it is not a simple getter function), so that wouldn't really matter, I think. But if you are handling events like DataPacketReceiveEvent or PlayerMoveEvent, those that may get called thousands times a second, you should probably avoid even registering them in the first case.
  3. Tethered_
    Offline

    Tethered_ Active Member Plugin Developer

    Joined:
    Jun 24, 2014
    Posts:
    178
    Plugins:
    2
    Minecraft User:
    Frostbyte58
    I was using player move event but to avoid lag, I just used a schedulerepeatingtask instead
    PEMapModder likes this.

Share This Page

Advertisement