package Ġcn . ber ber man . em eral d . util Ċ Ċ import Ġcn . ber ber man . em eral d . dsl . event . event Listener Ċ import Ġcn . ber ber man . em eral d . events . player . Packet Event Ċ import Ġcn . ber ber man . em eral d . extension . to Craft Player Ċ import Ġio . netty . channel . Channel Dup lex Handler Ċ import Ġio . netty . channel . Channel HandlerContext Ċ import Ġio . netty . channel . Channel Promise Ċ import Ġorg . bukkit . entity . Player Ċ import Ġorg . bukkit . event . Event Priority Ċ import Ġorg . bukkit . event . player . Player Join Event Ċ import Ġorg . bukkit . event . player . Player Quit Event Ċ Ċ object ĠChannel Handler Ġ: ĠChannel Dup lex Handler () Ġ{ Ċ ĉ override Ġfun Ġchannel Read ( ctx : ĠChannel HandlerContext ?, Ġmsg : ĠAny ) Ġ{ Ċĉ ĉ Packet Event . Packet Play In Event ( msg ). also ( E mer ald Util . plugin Manager :: call Event ). let Ġ{ Ċĉĉ ĉ if Ġ(! it . is Cancelled ) Ċĉĉĉ ĉ super . channel Read ( ctx , Ġit . msg ) Ċĉ ĉ } Ċ ĉ } ĊĊ ĉ override Ġfun Ġwrite ( ctx : ĠChannel HandlerContext ?, Ġmsg : ĠAny , Ġpromise : ĠChannel Promise ?) Ġ{ Ċĉ ĉ Packet Event . Packet Play Out Event ( msg ). also ( E mer ald Util . plugin Manager :: call Event ). let Ġ{ Ċĉĉ ĉ if Ġ(! it . is Cancelled ) Ċĉĉĉ ĉ super . write ( ctx , Ġit . msg , Ġpromise ) Ċĉ ĉ } Ċ ĉ } ĊĊ ĉ private Ġfun Ġadd Channel Handler ( player : ĠPlayer ) Ġ{ Ċĉ ĉ player . to Craft Player (). get Handle () Ċĉĉĉ ĉ . player Connection . channel . pipeline () Ċĉĉĉ ĉ . add Before (" packet _ handler ", Ġplayer . name , Ġthis ) Ċ ĉ } ĊĊ ĉ private Ġfun Ġremove Channel Handler ( player : ĠPlayer ) Ġ{ Ċĉ ĉ player . to Craft Player (). get Handle () Ċĉĉĉ ĉ . player Connection . channel . let Ġ{ Ċĉĉ ĉ it . event Loop (). submit Ġ{ Ġit . pipeline (). remove ( player . name ) Ġ} Ċĉ ĉ } Ċ ĉ } ĊĊ ĉ internal Ġval Ġjoin Inject Ġ= Ġevent Listener < Player Join Event >( Event Priority . HIG HE ST , Ġtrue ) Ġ{ Ċĉ ĉ add Channel Handler ( player ) Ċ ĉ } Ċ ĉ internal Ġval Ġquit Inject Ġ= Ġevent Listener < Player Quit Event >( Event Priority . HIG HE ST , Ġtrue ) Ġ{ Ċĉ ĉ remove Channel Handler ( player ) Ċ ĉ } Ċ }