#my wonderful gamephase listeners

1 messages · Page 1 of 1 (latest)

red pivot
#
    override fun onStart() {
      bindListener(Listener(EntityDamageEvent::class) { it.isCancelled = true })
    }

uhh the Listener has a register() and an unregister() method, starting the method will cause all bound listeners to be registered until the end of the game, calling Phase#cancel() will cause the listeners to be unregistered.

i'll probably add a parameter so its
bindListener("some identifier", Listener(EntityDamageEvent::class) { it.isCancelled = true })
instead. so i can disable them later by identifier like
unbindListener("some identifier"). that cool?

#

=> hybrid between Toggles and phase-specific listeners

red pivot
#

Or ig i can do without the idemtifier and to disable it use smth like game.getPhase(PreparePregamePhase)?.getListener(PlayerJoinEvent::class)?.unregister()

frail sand
#

if it works it's good. They added the unregister method for a reason

red pivot
#

Ill add a TODO optimize and be done with it then :)