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

Solved SignChangeEvent / $event->setLine() Problem

Comments in 'Plugin Development' started by Jazzwhistle, May 10, 2016.

  1. Jazzwhistle
    Offline

    Jazzwhistle Notable Member

    Joined:
    Dec 27, 2014
    Posts:
    364
    Minecraft User:
    Awzaw
    Hi, I'm trying to fix a problem with my Parkour plugin where sign text is sometimes not updated properly by my plugin after making a sign. I've noticed that when this happens the SignChangeEvent is actually being thrown twice when the sign is created (usually only once), and print_r shows the $event properties to be as expected and the same for both calls. I've tried a flag to intercept the second call and ignore it while the first is already dealing with changing the signtext, but it seems that isn't the problem. Any ideas?

    I'm waiting for the plugin to be accepted, i github as soon as it is... the code boils down to hooking into SignChangeEvent, get the text using $event->getLine(1) etc, check if the player has perms to make parkour... then $event->setLine(1, TextFormat::GREEN . $data[1]) etc to rewrite the sign in color.

    Sometimes I can even see a flicker of color with the correct sign text before it reverts to black and the new colours and the new text are lost. As I said, everything else in the code before and after writing the sign is executed fine, but twice.

    Thanks for any ideas you might have on this - I'm leaning towards a Pocketmine sign glitch related to (or identical to?) that which resets sign text to blank or ignores colours which also seemingly happens at random.

    PocketMine-MP version 1.6dev-24 "[REDACTED]" (API 2.0.0)
    No other plugins
    Last edited: May 10, 2016
  2. JackboyPlay
    Offline

    JackboyPlay Active Member

    Joined:
    Apr 25, 2015
    Posts:
    507
    Minecraft User:
    JackboyPlay
    Jazzwhistle likes this.
  3. Primus
    Offline

    Primus Notable Member

    Joined:
    Apr 7, 2015
    Posts:
    1,470
    Minecraft User:
    PrimusLV
    PHP:
    /**
     * @param SignChangeEvent $event
     * @priority MONITOR
     * @ignoreCancelled false
     */

    Jazzwhistle likes this.
  4. Jazzwhistle
    Offline

    Jazzwhistle Notable Member

    Joined:
    Dec 27, 2014
    Posts:
    364
    Minecraft User:
    Awzaw
    I thought you were not supposed to use Monitor if you change anything or cancel the event? Should I set to HIGH?
  5. Primus
    Offline

    Primus Notable Member

    Joined:
    Apr 7, 2015
    Posts:
    1,470
    Minecraft User:
    PrimusLV
    Test it ;)

    I usually set it to low. I want other plugins to be able to cancel the event before my plugin does anything.
    Last edited: May 10, 2016
  6. Jazzwhistle
    Offline

    Jazzwhistle Notable Member

    Joined:
    Dec 27, 2014
    Posts:
    364
    Minecraft User:
    Awzaw
    I'm reading up about using @priority, I'm new to PHP and plugin development so learning on the job! Thank a lot, that seems promising although I suppose it also might mean a conflict with EssentialsTP since that's the only other plugin I've installed to test parkour...

    UPDATE:

    I've got this at the start of the file

    class Main extends PluginBase implements Listener {

    /**
    * @param SignChangeEvent $event
    * @priority MONITOR
    * @ignoreCancelled false
    */

    not sure if that's correct, but with every setting from HIGH to MONITOR, and no other plugins at all I'm still seeing this behaviour :-(
    Last edited: May 10, 2016
  7. Jazzwhistle
    Offline

    Jazzwhistle Notable Member

    Joined:
    Dec 27, 2014
    Posts:
    364
    Minecraft User:
    Awzaw
    I'm trying tasks now... thanks for the suggestion
  8. Jazzwhistle
    Offline

    Jazzwhistle Notable Member

    Joined:
    Dec 27, 2014
    Posts:
    364
    Minecraft User:
    Awzaw
    Updating the signs by getting the tile directly (instead of using the event) and setting the text in a scheduleDelayedTask 20 ticks later works nearly perfectly, but it seems like a hack to me :-/
    Last edited: May 11, 2016

Share This Page

Advertisement