Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- /*
- __PocketMine Plugin__
- name=TrustPlayer
- description=You can't place or break anything if the admin don't accept you on the server.
- version=0.0.4
- apiversion=6,7
- author=InusualZ
- class=TrustPlayer
- */
- class TrustPlayer implements Plugin{
- private $api, $config, $sqli;
- public function __construct(ServerAPI $api, $server = false){
- $this->api = $api;
- }
- public function init()
- {
- //Adding Handler
- $this->api->addhandler('player.block.touch', array($this, 'handler'), 15);
- //Adding Commands and Alias
- $this->api->console->register('trust', '[TrustPlayer] Trust a player.', array($this, 'command'));
- $this->api->console->register('detrust', '[TrustPlayer] Destrust a player.', array($this, 'command'));
- $this->api->console->alias("tpl", "trust");
- $this->api->console->alias("dpl","detrust");
- //Creating Configuration File
- $this->config = new Config($this->api->plugin->configPath($this) . "config.yml", CONFIG_YAML, array(
- "send-msg" => true,
- "msg-break" => "[TrustPlayer] You can't break block, you are not a trust player.",
- "msg-place" => "[TrustPlayer] You can't place block, you are not a trust payer.",
- "msg-pickup" => "[TrustPlayer] You can't pickup anything, you are not a trust payer.",
- "msg-default" => "[TrustPlayer] You are not a trust player."
- ));
- //Creating SQLite Database and Table
- $this->sqli = new SQLite3($this->api->plugin->configPath($this) . 'trustplayer.db');
- $this->sqli->exec("CREATE TABLE IF NOT EXISTS Players (id INTEGER PRIMARY KEY, username TEXT)");
- }
- public function __destruct()
- {
- //Closing file and connection when finish.
- $this->sqli->close();
- }
- public function handler(&$data, $event)
- {
- switch ($event)
- {
- case "player.block.touch":
- if (!$this->usernameExist($data['player']))//Checking if username exist on the database.
- {
- if ($this->config->get("send-msg"))// If send-msg variable is true send the message.
- {
- switch ($data["type"])
- {
- case "place":
- $this->api->player->get($data["player"])->eventHandler($this->config->get("msg-place"), "server.chat");
- break;
- case "break":
- $this->api->player->get($data["player"])->eventHandler($this->config->get("msg-break"), "server.chat");
- break;
- case "pickup":
- $this->api->player->get($data["player"])->eventHandler($this->config->get("msg-pickup"), "server.chat");
- break;
- case "active":
- $this->api->player->get($data["player"])->eventHandler($this->config->get("msg-default"), "server.chat");
- break;
- }
- }
- return false;
- }
- break;
- }
- }
- public function command($cmd, $params)
- {
- switch ($cmd)
- {
- case "trust":
- $username = array_shift($params);
- if(empty($username) || $username == NULL)
- {
- console('[INFO] Usage: /trust <player>');
- }
- else
- {
- if($this->usernameExist($username))
- {
- console('[TrustPlayer] Username already exist.');
- }
- else
- {
- $this->trust($username);
- }
- }
- break;
- case "detrust":
- $username = array_shift($params);
- if(empty($username) || $username == NULL)
- {
- console('[INFO] Usage: /detrust <player>');
- }
- else
- {
- if($this->usernameExist($username))
- {
- $this->detrust($username);
- console('[TrustPlayer] The username has been deleted.');
- }
- else
- {
- console("[TrustPlayer] Username don't exist");
- }
- }
- break;
- }
- }
- public function trust($username)
- {
- console("[TrustPlayer] Inserting username on database...");
- return $this->sqli->query("INSERT OR REPLACE INTO Players (username) VALUES ('$username')");
- }
- public function detrust($username)
- {
- if($this->usernameExist($username))//Checking if username exists on the database
- {
- console("[TrustPlayer] Detrusting player...");
- return $this->sqli->query("DELETE FROM Players WHERE username = '$username'");
- }
- else
- {
- console("[TrustPlayer] Username don't exist on the database");
- return false;
- }
- }
- public function usernameExist($name)
- {
- $result = $this->sqli->query("SELECT count(username) AS count FROM Players WHERE username = '$name'");
- console("[TrustPlayer] Checking if username exists");
- if($result !== NULL OR $result !== FALSE OR $result !== TRUE)
- {
- $result = $result->fetchArray(SQLITE3_ASSOC);
- return $result['count'];
- }
- else
- {
- return false;
- }
- }
- }
- ?>
Advertisement
Add Comment
Please, Sign In to add comment