Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- /*
- __PocketMine Plugin__
- name=TapToDo
- description=A simple plugin to automate commands
- version=0.3
- author=Falk
- class=tapdo
- apiversion=10,11
- */
- /*
- _Change Log_
- 0.1 - Intial release
- 0.2 -
- *Added new /tapcmd command
- *Added :user:
- *Code format improvements
- 0.3 -
- *Added multiple commands!
- *Removed support for setcmd
- *Chnaged :player: to @player
- */
- class tapdo implements Plugin{
- private $api;
- private $picked;
- private $config;
- public function __construct(ServerAPI $api, $server = false){
- $this->api = $api;
- $this->picked = array();
- }
- public function init(){
- $this->api->addHandler("player.block.touch", array($this,"eventHandle"),50);
- $this->api->console->register("tapcmd", "Sets the tap cmd for the block you click", array($this, "command"));
- $path = $this->api->plugin->configPath($this);
- $this->config = new Config($path."blocks.yml");
- $this->config->save();
- }
- public function __destruct(){}
- public function command($cmd, $params, $issuer, $alias, $args, $issuer){
- switch ($cmd) {
- case "tapcmd":
- $cmd = implode(" ", $params);
- $this->picked[$issuer->username] = $cmd;
- $issuer->sendChat("Tap a block to add the command!");
- break;
- default:
- $issuer->sendChat("Error!");
- }
- }
- public function eventHandle($data, $event) {
- if (isset($this->picked[$data["player"]->username])) {
- $block = $data["target"];
- $x = $block->x;
- $y = $block->y;
- $z = $block->z;
- $level = $block->level->getName();
- $id = $x . "!" . $y . "!" . $z . "!" . $level;
- $blockConfig = $this->config->get($id);
- if ($blockConfig === false)
- $blockConfig = array();
- $blockConfig[] = $this->picked[$data["player"]->username];
- $this->config->set($id, $blockConfig);
- $this->config->save();
- unset($this->picked[$data["player"]->username]);
- $data["player"]->sendChat("Command added to block!");
- } else {
- $block = $data["target"];
- $x = $block->x;
- $y = $block->y;
- $z = $block->z;
- $level = $block->level->getName();
- $search = $x . "!" . $y . "!" . $z . "!" . $level;
- $blockConfig = $this->config->get($search);
- if ($blockConfig !== false) {
- foreach ($blockConfig as $command) {
- $command = str_replace("@player", $data["player"]->username, $command);
- $this->api->console->run($command);
- }
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement