3030use pocketmine \network \mcpe \protocol \ModalFormRequestPacket ;
3131use pocketmine \network \mcpe \protocol \ModalFormResponsePacket ;
3232use pocketmine \form \Form ;
33+ use Anders \PlayerJoinSettings \API \ModalForm ;
34+ use Anders \PlayerJoinSettings \API \RootUIAPI ;
3335
3436class Main extends PluginBase implements Listener, Form{
3537
@@ -40,7 +42,9 @@ public function onEnable(){//Plugin enabled
4042
4143 public function onLoad (){//Plugin Load
4244 @mkdir ($ this ->getDataFolder (),0777 ,true );
43- $ this ->saveResource ('config.yml ' , false );
45+ if (!file_exists ($ this ->getDataFolder ()."config.yml " )){
46+ $ this ->saveResource ("config.yml " );
47+ }
4448 $ this ->config = new Config ($ this ->getDataFolder ().'config.yml ' , Config::YAML );
4549 }
4650
@@ -96,43 +100,50 @@ public function onPlayerJoin(PlayerJoinEvent $event):void{//Try to send a messag
96100 $ content = str_replace ("{max_online} " , $ Max_online , $ content );
97101 $ button1 = str_replace ("& " , "§ " , strval ($ this ->config ->get ("UIformbutton1 " )));
98102 $ button2 = str_replace ("& " , "§ " , strval ($ this ->config ->get ("UIformbutton2 " )));
99- $ data = ["type " => "modal " ,"title " => $ title ,"content " => $ content ,"button1 " => $ button1 ,"button2 " => $ button2 ];
100- $ packet = new ModalFormRequestPacket ();
101- $ packet ->formId = 9527 ;
102- $ packet ->formData = json_encode ($ data , JSON_PRETTY_PRINT | JSON_BIGINT_AS_STRING | JSON_UNESCAPED_UNICODE );
103- $ player ->dataPacket ($ packet );
103+ $ UI = new ModalForm (9527 );
104+ $ UI ->setTitle ($ title );
105+ $ UI ->setContent ($ content );
106+ $ UI ->setButton1 ($ button1 );
107+ $ UI ->setButton2 ($ button2 );
108+ $ UI ->sendToPlayer ($ player );
104109 }
105110 }
106-
111+
112+ public function jsonSerialize () : void {
113+ }
114+
115+ public function handleResponse (Player $ player , $ data ) : void {
116+ }
117+
107118 public function onDataPacketReceive (DataPacketReceiveEvent $ event ): void {
108- $ packet = $ event ->getPacket ();
109- $ player = $ event ->getPlayer ();
110- $ name = $ player ->getName ();
111- if ($ packet instanceof ModalFormResponsePacket) {
112- $ id = $ packet ->formId ;
113- $ data = $ packet ->formData ;
114- $ result = json_decode ($ data );
115- if ($ data == "null \n" ){
116- } else {
117- if ($ id === 9527 ) {
118- if ($ result == true ){
119- if ($ this ->config ->get ("ButtonCommand " ) == true ){//Add some switches
120- $ ButtonCommand = $ this ->config ->get ("UIformbutton1cmd " );
121- $ ButtonCommand = str_replace ("{name} " , '" ' . $ name . '" ' , $ ButtonCommand );
122- $ this ->getServer ()->dispatchCommand (new consoleCommandSender (), $ ButtonCommand );
123- }
124- }else {
125- if ($ this ->config ->get ("ButtonCommand " ) == true ){//Add some switches
126- $ ButtonCommand = $ this ->config ->get ("UIformbutton2cmd " );
127- $ ButtonCommand = str_replace ("{name} " , '" ' . $ name . '" ' , $ ButtonCommand );
128- $ this ->getServer ()->dispatchCommand (new consoleCommandSender () ,$ ButtonCommand );
129- }
130- }
131- }
132- }
133- }
119+ $ packet = $ event ->getPacket ();
120+ $ player = $ event ->getPlayer ();
121+ $ name = $ player ->getName ();
122+ if ($ packet instanceof ModalFormResponsePacket) {
123+ $ id = $ packet ->formId ;
124+ $ data = $ packet ->formData ;
125+ $ result = json_decode ($ data );
126+ if ($ data == "null \n" ){
127+ } else {
128+ if ($ id === 9527 ) {
129+ if ($ result == true ){
130+ if ($ this ->config ->get ("ButtonCommand " ) == true ){//Add some switches
131+ $ ButtonCommand = $ this ->config ->get ("UIformbutton1cmd " );
132+ $ ButtonCommand = str_replace ("{name} " , '" ' . $ name . '" ' , $ ButtonCommand );
133+ $ this ->getServer ()->dispatchCommand (new consoleCommandSender (), $ ButtonCommand );
134+ }
135+ }else {
136+ if ($ this ->config ->get ("ButtonCommand " ) == true ){//Add some switches
137+ $ ButtonCommand = $ this ->config ->get ("UIformbutton2cmd " );
138+ $ ButtonCommand = str_replace ("{name} " , '" ' . $ name . '" ' , $ ButtonCommand );
139+ $ this ->getServer ()->dispatchCommand (new consoleCommandSender () ,$ ButtonCommand );
140+ }
141+ }
142+ }
143+ }
144+ }
134145 }
135-
146+
136147 public function onPlayerQuit (PlayerQuitEvent $ event ):void {
137148 $ player = $ event ->getPlayer ();
138149 $ name = $ player ->getName ();
0 commit comments