package Ġli rand . api . dsl . command . implementation . dispatcher Ċ Ċ import Ġcom . moj ang . b rig ad ier . Command Dispatcher Ċ import Ġcom . moj ang . b rig ad ier . tree . Command Node Ċ import Ġcom . moj ang . b rig ad ier . tree . Literal Command Node Ċ import Ġli rand . api . dsl . command . builders . Literal DSL Builder Ċ import Ġli rand . api . dsl . command . implementation . tree . Tree Walker Ċ import Ġli rand . api . dsl . command . implementation . tree . nodes . B rig ad ier Literal Ċ import Ġli rand . api . dsl . command . implementation . tree . nodes . B rig ad ier Root Ċ import Ġli rand . api . extensions . server . register Events Ċ import Ġli rand . api . extensions . server . server Ċ import Ġorg . bukkit . command . Command Sender Ċ import Ġorg . bukkit . command . Simple Command Map Ċ import Ġorg . bukkit . event . EventHandler Ċ import Ġorg . bukkit . event . Listener Ċ import Ġorg . bukkit . event . server . Server Load Event Ċ import Ġorg . bukkit . plugin . Plugin Ċ Ċ /** Ċ Ġ* ĠA Ġ[ Command Dispatcher ] Ġsubclass Ġthat Ġfacilities Ġthe Ġregistration Ġof Ġcommands Ċ Ġ* Ġbetween Ġa ĠSp ig ot Ġplugin Ġand Ġthe Ġserver . Ċ Ġ* Ċ Ġ* ĠThis Ġdispatcher Ġwill Ġ** not ** Ġautomatically Ġsynchronize Ġnewly Ġregistered Ġcommands Ċ Ġ* Ġexcept Ġwhen Ġthe Ġserver Ġis Ġstarted Ġor Ġre loaded Ġto Ġminimize Ġunnecessary Ġsynchron izations . Ċ Ġ* ĠAll Ġotherwise Ġregistered Ġcommands Ġmust Ġbe Ġmanually Ġsynchronized Ġvia Ġ[ update ]. Ċ Ġ* Ċ Ġ* Ġ** Implementation Ġdetails :** Ċ Ġ* ĠThis Ġdispatcher Ġholds Ġa Ġreference Ġto Ġthe Ġinternal Ġdispatcher Ġof Ġthe Ġserver . ĠThe Ċ Ġ* Ġinternal Ġdispatcher Ġis Ġfl ushed Ġafter Ġall Ġplugins Ġare Ġenabled Ġwhen Ġthe Ġserver Ċ Ġ* Ġis Ġeither Ġstarted Ġor Ġre loaded . ĠIn Ġboth Ġcases , Ġthis Ġdispatcher Ġand Ġthe Ġinternal Ċ Ġ* Ġdispatcher Ġare Ġsynchronized Ġautomatically . Ċ Ġ*/ Ċ open Ġclass ĠDispatcher Ġprotected Ġconstructor ( private Ġval Ġroot : ĠB rig ad ier Root ) Ġ: Ċ ĉ Command Dispatcher < Command Sender >( root ), ĠListener Ġ{ ĊĊ ĉ internal Ġval Ġwalk er : ĠTree Walker < Command Sender , ĠAny > Ġ= ĠTree Walker ( Ċĉ ĉ Sp ig ot Mapper ( this ) Ċ ĉ ) ĊĊ ĉ open Ġfun Ġregister ( nodes : ĠList < Command Node < Command Sender >>) Ġ{ Ċĉ ĉ for Ġ( node Ġin Ġnodes ) Ġ{ Ċĉĉ ĉ getRoot (). addChild ( node ) Ċĉ ĉ } Ċ ĉ } ĊĊ ĉ /** Ċĉ Ġ* ĠRegisters Ġthe Ġcommand Ġby Ġthe Ġgiven Ġnode . Ċĉ Ġ* Ċĉ Ġ* Ġ@ param Ġnode Ġthat Ġmust Ġbe Ġregistered Ċĉ Ġ*/ Ċ ĉ open Ġfun Ġregister ( node : ĠLiteral Command Node < Command Sender >) Ġ{ Ċĉ ĉ root . addChild ( node ) Ċ ĉ } ĊĊ ĉ /** Ċĉ Ġ* ĠRegisters Ġthe Ġcommand Ġbuilt Ġusing Ġthe Ġgiven Ġ[ builder ]. Ċĉ Ġ* Ċĉ Ġ* Ġ@ param Ġbuilder Ġthe Ġbuilder Ġused Ġto Ġbuild Ġthe Ġcommand Ġto Ġbe Ġregistered Ċĉ Ġ* Ġ@ return Ġthe Ġbuilt Ġnode Ġthat Ġwas Ġregistered Ċĉ Ġ*/ Ċ ĉ open Ġfun Ġregister ( builder : ĠLiteral DSL Builder ): ĠB rig ad ier Literal < Command Sender > Ġ{ Ċĉ ĉ val Ġliteral Ġ= Ġbuilder . build () Ċĉ ĉ register ( literal ) Ċĉ ĉ return Ġliteral Ċ ĉ } ĊĊ ĉ /** Ċĉ Ġ* ĠSynchron izes Ġthis Ġdispatcher Ġwith Ġthe Ġserver Ġand Ġclients . Ċĉ Ġ*/ Ċ ĉ open Ġfun Ġupdate () Ġ{ Ċĉ ĉ walker . prune ( command Dispatcher . root , Ġroot . children ) Ċĉ ĉ for Ġ( player Ġin Ġserver . online Players ) Ġ{ Ċĉĉ ĉ player . update Commands () Ċĉ ĉ } Ċ ĉ } ĊĊ ĉ override Ġfun Ġget Root (): ĠB rig ad ier Root Ġ{ Ċĉ ĉ return Ġroot Ċ ĉ } ĊĊ ĉ @ EventHandler Ċ ĉ private Ġfun Ġon Server Reload ( event : ĠServer Load Event ) Ġ{ Ċĉ ĉ command Dispatcher Ġ= Ġcommands Get Dispatcher Method . invoke ( Ċĉĉ ĉ server Get Command Dispatcher Method . invoke ( dedicated Server ) Ċĉ ĉ ) Ġas ĠCommand Dispatcher < Any > ĊĊĉ ĉ if Ġ( event . type Ġ== ĠServer Load Event . Load Type . START UP ) Ġ{ Ċĉĉ ĉ walker . prune ( command Dispatcher . root , Ġroot . children ) Ċĉ ĉ } Ċĉ ĉ else Ġ{ Ċĉĉ ĉ update () Ċĉ ĉ } Ċ ĉ } ĊĊ ĉ comp anion Ġobject Ġ{ ĊĊĉ ĉ private Ġlateinit Ġvar Ġcommand Dispatcher : ĠCommand Dispatcher < Any > ĊĊĉ ĉ private Ġval Ġdedicated Server Ġ= Ġserver :: class . java . getMethod (" getServer "). invoke ( server ) Ċĉ ĉ private Ġval Ġserver Get Command Map Method Ġ= Ġserver :: class . java . getMethod (" get Command Map ") Ċĉ ĉ private Ġval Ġserver Get Command Dispatcher Method Ġ= Ġdedicated Server :: class . java . methods Ċĉĉ ĉ . find Ġ{ Ġit . returnType . simple Name Ġ== Ġ" Command Dispatcher " Ġ&& Ġit . parameter Count Ġ== Ġ 0 Ġ} !! Ċĉ ĉ private Ġval Ġcommands Get Dispatcher Method Ġ= Ġserver Get Command Dispatcher Method . returnType . methods Ċĉĉ ĉ . find Ġ{ Ġit . returnType Ġ== ĠCommand Dispatcher :: class . java Ġ&& Ġit . parameter Count Ġ== Ġ 0 Ġ} !! ĊĊĊĉ ĉ private Ġval Ġ_ instances Ġ= Ġmutable Map Of < Plugin , ĠDispatcher >() Ċĉ ĉ val Ġinstances : ĠMap < Plugin , ĠDispatcher > Ġget () Ġ= Ġ_ instances ĊĊĉ ĉ fun Ġof ( plugin : ĠPlugin ): ĠDispatcher Ġ{ Ċĉĉ ĉ if Ġ( plugin Ġin Ġinstances ) Ġreturn Ġinstances [ plugin ] !! ĊĊĉĉ ĉ if Ġ(! Companion :: command Dispatcher . isInitialized ) Ġ{ Ċĉĉĉ ĉ val Ġcommands Ġ= Ġserver Get Command Dispatcher Method . invoke ( dedicated Server ) Ċĉĉĉ ĉ command Dispatcher Ġ= Ġcommands Get Dispatcher Method . invoke ( commands ) Ġas ĠCommand Dispatcher < Any > Ċĉĉ ĉ } ĊĊĉĉ ĉ val Ġprefix Ġ= Ġplugin . name . lowercase () Ċĉĉ ĉ val Ġmap Ġ= ĠSp ig ot Map ( prefix , Ġplugin , Ċĉĉĉ ĉ server Get Command Map Method . invoke ( server ) Ġas ĠSimple Command Map Ċĉĉ ĉ ) Ċĉĉ ĉ val Ġroot Ġ= ĠB rig ad ier Root ( prefix , Ġmap ) Ċĉĉ ĉ val Ġdispatcher Ġ= ĠDispatcher ( root ) Ċĉĉ ĉ map . dispatcher Ġ= Ġdispatcher ĊĊĉĉ ĉ _ instances [ plugin ] Ġ= Ġdispatcher ĊĊĉĉ ĉ plugin . register Events ( dispatcher ) ĊĊĉĉ ĉ return Ġdispatcher Ċĉ ĉ } Ċ ĉ } Ċ }