mirror of
https://github.com/pmmp/PocketMine-MP.git
synced 2025-06-11 14:05:35 +00:00
Posibility of changing data for handlers, and canceling it
This commit is contained in:
parent
bf24a937b2
commit
504b37cfaa
@ -39,9 +39,9 @@ class BlockAPI{
|
|||||||
}
|
}
|
||||||
|
|
||||||
public function init(){
|
public function init(){
|
||||||
$this->server->addHandler("world.block.update", array($this, "updateBlockRemote"));
|
$this->server->addHandler("world.block.update", array($this, "updateBlockRemote"), 1);
|
||||||
$this->server->addHandler("player.block.break", array($this, "blockBreak"));
|
$this->server->addHandler("player.block.break", array($this, "blockBreak"), 1);
|
||||||
$this->server->addHandler("player.block.action", array($this, "blockAction"));
|
$this->server->addHandler("player.block.action", array($this, "blockAction"), 1);
|
||||||
}
|
}
|
||||||
|
|
||||||
public function blockBreak($data, $event){
|
public function blockBreak($data, $event){
|
||||||
|
@ -29,7 +29,7 @@ class EntityAPI{
|
|||||||
private $server;
|
private $server;
|
||||||
function __construct($server){
|
function __construct($server){
|
||||||
$this->server = $server;
|
$this->server = $server;
|
||||||
$this->server->addHandler("onPlayerDeath", array($this, "handle"), 1);
|
$this->server->addHandler("player.death", array($this, "handle"), 1);
|
||||||
}
|
}
|
||||||
|
|
||||||
public function init(){
|
public function init(){
|
||||||
@ -38,7 +38,7 @@ class EntityAPI{
|
|||||||
|
|
||||||
public function handle($data, $event){
|
public function handle($data, $event){
|
||||||
switch($event){
|
switch($event){
|
||||||
case "onPlayerDeath":
|
case "player.death":
|
||||||
$message = $data["name"];
|
$message = $data["name"];
|
||||||
if(is_numeric($data["cause"]) and isset($this->entities[$data["cause"]])){
|
if(is_numeric($data["cause"]) and isset($this->entities[$data["cause"]])){
|
||||||
$e = $this->api->entity->get($data["cause"]);
|
$e = $this->api->entity->get($data["cause"]);
|
||||||
|
@ -57,10 +57,10 @@ class PluginAPI extends stdClass{
|
|||||||
}
|
}
|
||||||
$info[$i] = $v;
|
$info[$i] = $v;
|
||||||
}
|
}
|
||||||
if(!isset($info["name"]) or !isset($info["version"]) or !isset($info["class"])){
|
if(!isset($info["name"]) or !isset($info["version"]) or !isset($info["class"]) or !isset($info["author"])){
|
||||||
console("[ERROR] [PluginAPI] Failed parsing of ".basename($file));
|
console("[ERROR] [PluginAPI] Failed parsing of ".basename($file));
|
||||||
}
|
}
|
||||||
console("[INFO] [PluginAPI] Loading plugin \"".$info["name"]."\" ".$info["version"]);
|
console("[INFO] [PluginAPI] Loading plugin \"".$info["name"]."\" ".$info["version"]." by ".$info["author"]);
|
||||||
if(eval($content) === false or !class_exists($info["class"])){
|
if(eval($content) === false or !class_exists($info["class"])){
|
||||||
console("[ERROR] [PluginAPI] Failed loading plugin");
|
console("[ERROR] [PluginAPI] Failed loading plugin");
|
||||||
}
|
}
|
||||||
|
@ -220,7 +220,7 @@ class Entity extends stdClass{
|
|||||||
if($this->health <= 0 and $this->dead === false){
|
if($this->health <= 0 and $this->dead === false){
|
||||||
$this->dead = true;
|
$this->dead = true;
|
||||||
if($this->player !== false){
|
if($this->player !== false){
|
||||||
$this->server->handle("onPlayerDeath", array("name" => $this->name, "cause" => $cause));
|
$this->server->handle("player.death", array("name" => $this->name, "cause" => $cause));
|
||||||
}
|
}
|
||||||
}elseif($this->health > 0){
|
}elseif($this->health > 0){
|
||||||
$this->dead = false;
|
$this->dead = false;
|
||||||
|
@ -300,12 +300,13 @@ class Player{
|
|||||||
$this->server->trigger("entity.move", $this->eid);
|
$this->server->trigger("entity.move", $this->eid);
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
case MC_PLAYER_EQUIPMENT:
|
case MC_PLAYER_EQUIPMENT:
|
||||||
console("[DEBUG] EID ".$this->eid." has now ".$data["block"].":".$data["meta"]." in their hands!", true, true, 2);
|
|
||||||
$data["eid"] = $this->eid;
|
$data["eid"] = $this->eid;
|
||||||
$this->equipment[0] = $data["block"];
|
if($this->server->handle("player.equipment.change", $data) !== false){
|
||||||
$this->equipment[1] = $data["meta"];
|
$this->equipment[0] = $data["block"];
|
||||||
$this->server->trigger("player.equipment.change", $data);
|
$this->equipment[1] = $data["meta"];
|
||||||
|
console("[DEBUG] EID ".$this->eid." has now ".$data["block"].":".$data["meta"]." in their hands!", true, true, 2);
|
||||||
|
}
|
||||||
break;
|
break;
|
||||||
case MC_REQUEST_CHUNK:
|
case MC_REQUEST_CHUNK:
|
||||||
$this->actionQueue('
|
$this->actionQueue('
|
||||||
|
@ -192,20 +192,25 @@ class PocketMinecraftServer extends stdClass{
|
|||||||
return $this->handCnt++;
|
return $this->handCnt++;
|
||||||
}
|
}
|
||||||
|
|
||||||
public function handle($event, $data){
|
public function handle($event, &$data){
|
||||||
$this->preparedSQL->selectHandlers->reset();
|
$this->preparedSQL->selectHandlers->reset();
|
||||||
$this->preparedSQL->selectHandlers->clear();
|
$this->preparedSQL->selectHandlers->clear();
|
||||||
$this->preparedSQL->selectHandlers->bindValue(":name", $event, SQLITE3_TEXT);
|
$this->preparedSQL->selectHandlers->bindValue(":name", $event, SQLITE3_TEXT);
|
||||||
$handlers = $this->preparedSQL->selectHandlers->execute();
|
$handlers = $this->preparedSQL->selectHandlers->execute();
|
||||||
if($handlers === false or $handlers === true){
|
|
||||||
return $this->trigger($event, $data);
|
|
||||||
}
|
|
||||||
$result = true;
|
$result = true;
|
||||||
while(false !== ($hn = $handlers->fetchArray(SQLITE3_ASSOC)) and $result !== false){
|
if($handlers !== false and $handlers !== true){
|
||||||
$hnid = (int) $hn["ID"];
|
while(false !== ($hn = $handlers->fetchArray(SQLITE3_ASSOC)) and $result !== false){
|
||||||
$result = call_user_func($this->handlers[$hnid], $data, $event);
|
$handler = $this->handlers[(int) $hn["ID"]];
|
||||||
|
if(is_array($handler)){
|
||||||
|
$method = $handler[1];
|
||||||
|
$result = $handler[0]->$method($data, $event);
|
||||||
|
}else{
|
||||||
|
$result = $handler($data, $event);
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
$handlers->finalize();
|
$handlers->finalize();
|
||||||
|
$this->trigger($event, $data);
|
||||||
return $result;
|
return $result;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
45
example/ReactorAsWater.php
Normal file
45
example/ReactorAsWater.php
Normal file
@ -0,0 +1,45 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
/*
|
||||||
|
__PocketMine Plugin__
|
||||||
|
name=Reactor As Water
|
||||||
|
description=Replaces the Nether Reactor with Water
|
||||||
|
version=0.0.1
|
||||||
|
author=shoghicp
|
||||||
|
class=ReactorAsWater
|
||||||
|
api=false
|
||||||
|
*/
|
||||||
|
|
||||||
|
|
||||||
|
class ReactorAsWater{
|
||||||
|
private $api, $server;
|
||||||
|
public function __construct($api, $server = false){
|
||||||
|
$this->api = $api;
|
||||||
|
$this->server = $server;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function init(){
|
||||||
|
$this->server->addHandler("player.block.action", array($this, "handle"), 15); //Priority higher that API
|
||||||
|
$this->server->addHandler("player.equipment.change", array($this, "handle"));
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
public function handle(&$data, $event){
|
||||||
|
switch($event){
|
||||||
|
case "player.equipment.change":
|
||||||
|
if($data["block"] === 247){
|
||||||
|
$this->api->player->getByEID($data["eid"])->eventHandler("[ReactorAsWater] You'll place water with the Nether Reactor", "server.chat");
|
||||||
|
$data["block"] = 9;
|
||||||
|
$data["meta"] = 0;
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
case "player.block.action":
|
||||||
|
if($data["block"] === 247){ //nether reactor
|
||||||
|
$data["block"] = 9; //water source
|
||||||
|
$data["meta"] = 0;
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
Loading…
x
Reference in New Issue
Block a user