Advertisement
Guest User

Untitled

a guest
Dec 13th, 2013
88
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 2.35 KB | None | 0 0
  1. <?php
  2. /*
  3. __PocketMine Plugin__
  4. name=TapToDo
  5. description=A simple plugin to automate commands
  6. version=0.3
  7. author=Falk
  8. class=tapdo
  9. apiversion=10,11
  10. */
  11. /*
  12. _Change Log_
  13. 0.1 - Intial release
  14. 0.2 -
  15.     *Added new /tapcmd command
  16.     *Added :user:
  17.     *Code format improvements
  18. 0.3 -
  19.     *Added multiple commands!
  20.     *Removed support for setcmd
  21.     *Chnaged :player: to @player
  22.  
  23. */
  24. class tapdo implements Plugin{
  25.     private $api;
  26.     private $picked;
  27.     private $config;
  28.  
  29.     public function __construct(ServerAPI $api, $server = false){
  30.         $this->api = $api;
  31.         $this->picked = array();
  32.     }
  33.  
  34.     public function init(){
  35.         $this->api->addHandler("player.block.touch", array($this,"eventHandle"),50);
  36.         $this->api->console->register("tapcmd", "Sets the tap cmd for the block you click", array($this, "command"));
  37.  
  38.  
  39.         $path = $this->api->plugin->configPath($this);
  40.         $this->config = new Config($path."blocks.yml");
  41.         $this->config->save();
  42.     }
  43.  
  44.     public function __destruct(){}
  45.     public function command($cmd, $params, $issuer, $alias, $args, $issuer){
  46.         switch ($cmd) {
  47.             case "tapcmd":
  48.             $cmd = implode(" ", $params);
  49.             $this->picked[$issuer->username] = $cmd;
  50.             $issuer->sendChat("Tap a block to add the command!");
  51.         break;
  52.         default:
  53.             $issuer->sendChat("Error!");
  54.         }
  55.     }
  56.  
  57.     public function eventHandle($data, $event) {
  58.         if (isset($this->picked[$data["player"]->username])) {
  59.             $block = $data["target"];
  60.                 $x = $block->x;
  61.             $y = $block->y;
  62.             $z = $block->z;
  63.             $level = $block->level->getName();
  64.             $id = $x . "!" . $y . "!" . $z . "!" . $level;
  65.             $blockConfig = $this->config->get($id);
  66.             if ($blockConfig === false)
  67.                 $blockConfig = array();
  68.             $blockConfig[] = $this->picked[$data["player"]->username];
  69.             $this->config->set($id, $blockConfig);
  70.             $this->config->save();
  71.             unset($this->picked[$data["player"]->username]);
  72.             $data["player"]->sendChat("Command added to block!");
  73.         } else {
  74.             $block = $data["target"];
  75.                 $x = $block->x;
  76.             $y = $block->y;
  77.             $z = $block->z;
  78.             $level = $block->level->getName();
  79.             $search = $x . "!" . $y . "!" . $z . "!" . $level;
  80.             $blockConfig = $this->config->get($search);
  81.             if ($blockConfig !== false) {
  82.                 foreach ($blockConfig as $command) {
  83.                     $command = str_replace("@player", $data["player"]->username, $command);
  84.                     $this->api->console->run($command);
  85.                 }
  86.             }
  87.         }
  88.     }
  89. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement