1212use pocketmine \utils \Config ;
1313
1414class TapToDo extends PluginBase implements CommandExecutor, Listener{
15- public $ s , $ b , $ config ;
15+ public $ s ;
16+ /** @var Config */
17+ public $ config ;
18+ public $ b ;
1619 public function onEnable (){
1720 @mkdir ($ this ->getDataFolder ());
1821 $ this ->s = [];
22+ $ this ->b = [];
23+ $ this ->saveResource ("blocks.yml " );
1924 $ this ->config = new Config ($ this ->getDataFolder () . "blocks.yml " , Config::YAML , array ());
25+ $ this ->config = (new ConfigUpdater ($ this ->config , $ this ))->checkConfig ();
2026 $ this ->getServer ()->getPluginManager ()->registerEvents ($ this , $ this );
2127 $ this ->parseBlockData ();
2228 }
@@ -90,8 +96,8 @@ public function onCommand(CommandSender $sender, Command $cmd, $label, array $ar
9096 }
9197 else {
9298 if ($ sender instanceof Player){
93- if (isset ($ args [1 ])){
94- if ($ sender ->hasPermission ("taptodo.command. " . $ args [1 ])){
99+ if (isset ($ args [0 ])){
100+ if ($ sender ->hasPermission ("taptodo.command. " . $ args [0 ])){
95101 $ this ->s [$ sender ->getName ()] = $ args ;
96102 $ sender ->sendMessage ("Tap a block to complete action... " );
97103 return true ;
@@ -208,7 +214,7 @@ public function getBlock($x, $y, $z, $level){
208214 }
209215 public function parseBlockData (){
210216 $ this ->b = [];
211- foreach ($ this ->config ->getAll ( ) as $ i => $ block ){
217+ foreach ($ this ->config ->get ( " blocks " ) as $ i => $ block ){
212218 if ($ this ->getServer ()->isLevelLoaded ($ block ["level " ])){
213219 $ pos = new Position ($ block ["x " ], $ block ["y " ], $ block ["z " ], $ this ->getServer ()->getLevelByName ($ block ["level " ]));
214220 if (isset ($ block ["name " ])) $ this ->b [$ pos ->__toString ()] = new Block ($ pos , $ block ["commands " ], $ this ->config , $ block ["name " ]);
@@ -220,19 +226,23 @@ public function parseBlockData(){
220226 }
221227 }
222228 public function removeBlock (Block $ block ){
223- $ this ->config ->remove ($ block ->id );
229+ $ blocks = $ this ->config ->get ("blocks " );
230+ unset($ blocks [$ block ->id ]);
231+ $ this ->config ->set ("blocks " , $ blocks );
224232 $ this ->config ->save ();
225233 $ this ->parseBlockData ();
226234 }
227235 public function addBlock (Position $ p , $ cmd ){
228- $ block = new Block (new Position ($ p ->getX (), $ p ->getY (), $ p ->getZ (), $ p ->getLevel ()), [$ cmd ], $ this , count ($ this ->config ->getAll ( )));
236+ $ block = new Block (new Position ($ p ->getX (), $ p ->getY (), $ p ->getZ (), $ p ->getLevel ()), [$ cmd ], $ this , count ($ this ->config ->get ( " blocks " )));
229237 $ this ->saveBlock ($ block );
230238 $ this ->config ->save ();
231239 return $ block ;
232240 }
233241 public function saveBlock (Block $ block ){
234242 $ this ->b [$ block ->getPos ()->getX () . ": " . $ block ->getPos ()->getY () . ": " . $ block ->getPos ()->getZ () . ": " . $ block ->getPos ()->getLevel ()->getName ()] = $ block ;
235- $ this ->config ->set ($ block ->id , $ block ->toArray ());
243+ $ blocks = $ this ->config ->get ("blocks " );
244+ $ blocks [$ block ->id ] = $ block ->toArray ();
245+ $ this ->config ->set ("blocks " , $ blocks );
236246 }
237247 public function onDisable (){
238248 $ this ->getLogger ()->info ("Saving blocks... " );
@@ -241,4 +251,19 @@ public function onDisable(){
241251 }
242252 $ this ->config ->save ();
243253 }
254+
255+ /**
256+ * @return mixed
257+ */
258+ public function getConfig (){
259+ return $ this ->config ;
260+ }
261+
262+ /**
263+ * @param mixed $config
264+ */
265+ public function setConfig ($ config ){
266+ $ this ->config = $ config ;
267+ }
268+
244269}
0 commit comments