Last active
September 30, 2021 04:24
-
-
Save Omattyao/5330752 to your computer and use it in GitHub Desktop.
3.0.0
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
/* | |
__PocketMine Plugin__ | |
name=SignConsole | |
description=Run commands with a sign. | |
version=3.0.0 | |
apiversion=9,10 | |
author=Omattyao | |
class=SignConsole | |
*/ | |
class SignConsole implements Plugin{ | |
private $api, $interval; | |
public function __construct(ServerAPI $api, $server = false){ | |
$this->api = $api; | |
$this->interval = array(); | |
} | |
public function init(){ | |
$this->api->event('player.block.touch', array($this, 'handle')); | |
} | |
public function __destruct(){ | |
} | |
public function handle(&$data, $event) { | |
switch ($event) { | |
case "player.block.touch": | |
if ($data['type'] !== "place" or $data['item']->getID() == 323) break; | |
$player = $data["player"]; | |
$position = new Position ($data["target"], false, false, $data["target"]->level); | |
$sign = $this->api->tile->get($position); | |
if (($sign instanceof Tile) and $sign->class === TILE_SIGN){ | |
$strings = $sign->data['Text1'].$sign->data['Text2'].$sign->data['Text3'].$sign->data['Text4']; | |
if (strpos($strings, '//') !== false) { | |
if (!$this->checkInterval($player)) return false; | |
preg_match("/^\/\/(.+[^\s])/", $strings, $line); | |
$line = $line[1]; | |
$this->api->console->run($line, $player); | |
$this->setInterval($player); | |
} | |
} | |
break; | |
} | |
} | |
public function checkInterval($player) { | |
if (!isset($this->interval[$player->username])) return true; | |
if (time() < $this->interval[$player->username]) { | |
return false; | |
} else { | |
return true; | |
} | |
} | |
public function setInterval($player) { | |
$time = time() + 2; | |
$this->interval[$player->username] = $time; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment