mirror of
https://github.com/pmmp/PocketMine-MP.git
synced 2025-04-20 16:00:20 +00:00
Merge pull request #1906 from PocketMine/MoreEvents
Added more events, API 1.3.0
This commit is contained in:
commit
daf1a8266d
@ -28,6 +28,7 @@ use pocketmine\entity\DroppedItem;
|
||||
use pocketmine\entity\Entity;
|
||||
use pocketmine\entity\Human;
|
||||
use pocketmine\entity\Living;
|
||||
use pocketmine\event\block\SignChangeEvent;
|
||||
use pocketmine\event\entity\EntityDamageByEntityEvent;
|
||||
use pocketmine\event\entity\EntityDamageEvent;
|
||||
use pocketmine\event\inventory\InventoryCloseEvent;
|
||||
@ -1986,18 +1987,28 @@ class Player extends Human implements CommandSender, InventoryHolder, IPlayer{
|
||||
}
|
||||
$this->craftingType = 0;
|
||||
|
||||
$t = $this->getLevel()->getTile(new Vector3($packet->x, $packet->y, $packet->z));
|
||||
$t = $this->getLevel()->getTile($v = new Vector3($packet->x, $packet->y, $packet->z));
|
||||
if($t instanceof Sign){
|
||||
if(!isset($t->namedtag->Creator) or $t->namedtag["Creator"] !== $this->username){
|
||||
$nbt = new NBT(NBT::LITTLE_ENDIAN);
|
||||
$nbt->read($packet->namedtag);
|
||||
$nbt = $nbt->getData();
|
||||
if($nbt["id"] !== Tile::SIGN){
|
||||
$t->spawnTo($this);
|
||||
}else{
|
||||
$nbt = new NBT(NBT::LITTLE_ENDIAN);
|
||||
$nbt->read($packet->namedtag);
|
||||
$nbt = $nbt->getData();
|
||||
if($nbt["id"] !== Tile::SIGN){
|
||||
$t->spawnTo($this);
|
||||
$ev = new SignChangeEvent($this->getLevel()->getBlock($v), $this, [
|
||||
$nbt["Text1"], $nbt["Text2"], $nbt["Text3"], $nbt["Text4"]
|
||||
]);
|
||||
|
||||
if(!isset($t->namedtag->Creator) or $t->namedtag["Creator"] !== $this->username){
|
||||
$ev->setCancelled(true);
|
||||
}
|
||||
|
||||
$this->server->getPluginManager()->callEvent($ev);
|
||||
|
||||
if(!$ev->isCancelled()){
|
||||
$t->setText($ev->getLine(0), $ev->getLine(1), $ev->getLine(2), $ev->getLine(3));
|
||||
}else{
|
||||
$t->setText($nbt["Text1"], $nbt["Text2"], $nbt["Text3"], $nbt["Text4"]);
|
||||
$t->spawnTo($this);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -74,10 +74,9 @@ namespace pocketmine {
|
||||
use raklib\RakLib;
|
||||
|
||||
const VERSION = "Alpha_1.4dev";
|
||||
const API_VERSION = "1.2.1";
|
||||
const API_VERSION = "1.3.0";
|
||||
const CODENAME = "絶好(Zekkou)ケーキ(Cake)";
|
||||
const MINECRAFT_VERSION = "v0.9.5 alpha";
|
||||
const PHP_VERSION = "5.5";
|
||||
|
||||
if(\Phar::running(true) !== ""){
|
||||
@define("pocketmine\\PATH", \Phar::running(true) . "/");
|
||||
|
@ -1668,10 +1668,9 @@ class Server{
|
||||
Timings::$serverCommandTimer->startTiming();
|
||||
if(($line = $this->console->getLine()) !== null){
|
||||
$this->pluginManager->callEvent($ev = new ServerCommandEvent($this->consoleSender, $line));
|
||||
if($ev->isCancelled()){
|
||||
return;
|
||||
if(!$ev->isCancelled()){
|
||||
$this->dispatchCommand($ev->getSender(), $ev->getCommand());
|
||||
}
|
||||
$this->dispatchCommand($this->consoleSender, $ev->getCommand());
|
||||
}
|
||||
Timings::$serverCommandTimer->stopTiming();
|
||||
}
|
||||
@ -2002,7 +2001,7 @@ class Server{
|
||||
"os" => Utils::getOS(),
|
||||
"memory_total" => $this->getConfigString("memory-limit"),
|
||||
"memory_usage" => memory_get_usage(),
|
||||
"php_version" => \pocketmine\PHP_VERSION,
|
||||
"php_version" => PHP_VERSION,
|
||||
"version" => $version->get(false),
|
||||
"build" => $version->getBuild(),
|
||||
"mc_version" => \pocketmine\MINECRAFT_VERSION,
|
||||
|
@ -24,12 +24,20 @@
|
||||
*/
|
||||
namespace pocketmine\event\block;
|
||||
|
||||
use pocketmine\block\Block;
|
||||
use pocketmine\event\Event;
|
||||
|
||||
abstract class BlockEvent extends Event{
|
||||
/** @var \pocketmine\block\Block */
|
||||
protected $block;
|
||||
|
||||
/**
|
||||
* @param Block $block
|
||||
*/
|
||||
protected function __construct(Block $block){
|
||||
$this->block = $block;
|
||||
}
|
||||
|
||||
public function getBlock(){
|
||||
return $this->block;
|
||||
}
|
||||
|
81
src/pocketmine/event/block/SignChangeEvent.php
Normal file
81
src/pocketmine/event/block/SignChangeEvent.php
Normal file
@ -0,0 +1,81 @@
|
||||
<?php
|
||||
|
||||
/*
|
||||
*
|
||||
* ____ _ _ __ __ _ __ __ ____
|
||||
* | _ \ ___ ___| | _____| |_| \/ (_)_ __ ___ | \/ | _ \
|
||||
* | |_) / _ \ / __| |/ / _ \ __| |\/| | | '_ \ / _ \_____| |\/| | |_) |
|
||||
* | __/ (_) | (__| < __/ |_| | | | | | | | __/_____| | | | __/
|
||||
* |_| \___/ \___|_|\_\___|\__|_| |_|_|_| |_|\___| |_| |_|_|
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Lesser General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* @author PocketMine Team
|
||||
* @link http://www.pocketmine.net/
|
||||
*
|
||||
*
|
||||
*/
|
||||
|
||||
namespace pocketmine\event\block;
|
||||
|
||||
use pocketmine\block\Block;
|
||||
use pocketmine\event\Cancellable;
|
||||
use pocketmine\item\Item;
|
||||
use pocketmine\Player;
|
||||
|
||||
/**
|
||||
* Called when a sign is changed by a player.
|
||||
*/
|
||||
class SignChangeEvent extends BlockEvent implements Cancellable{
|
||||
public static $handlerList = null;
|
||||
|
||||
/** @var \pocketmine\Player */
|
||||
private $player;
|
||||
/** @var string[] */
|
||||
private $lines = [];
|
||||
|
||||
/**
|
||||
* @param Block $theBlock
|
||||
* @param Player $thePlayer
|
||||
* @param string[] $theLines
|
||||
*/
|
||||
public function __construct(Block $theBlock, Player $thePlayer, array $theLines){
|
||||
parent::__construct($theBlock);
|
||||
$this->player = $thePlayer;
|
||||
$this->lines = $theLines;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return Player
|
||||
*/
|
||||
public function getPlayer(){
|
||||
return $this->player;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return string[]
|
||||
*/
|
||||
public function getLines(){
|
||||
return $this->lines;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param int $index 0-3
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function getLine($index){
|
||||
return $this->lines[$index];
|
||||
}
|
||||
|
||||
/**
|
||||
* @param int $index 0-3
|
||||
* @param string $line
|
||||
*/
|
||||
public function setLine($index, $line){
|
||||
$this->lines[$index] = $line;
|
||||
}
|
||||
}
|
40
src/pocketmine/event/server/RemoteServerCommandEvent.php
Normal file
40
src/pocketmine/event/server/RemoteServerCommandEvent.php
Normal file
@ -0,0 +1,40 @@
|
||||
<?php
|
||||
|
||||
/*
|
||||
*
|
||||
* ____ _ _ __ __ _ __ __ ____
|
||||
* | _ \ ___ ___| | _____| |_| \/ (_)_ __ ___ | \/ | _ \
|
||||
* | |_) / _ \ / __| |/ / _ \ __| |\/| | | '_ \ / _ \_____| |\/| | |_) |
|
||||
* | __/ (_) | (__| < __/ |_| | | | | | | | __/_____| | | | __/
|
||||
* |_| \___/ \___|_|\_\___|\__|_| |_|_|_| |_|\___| |_| |_|_|
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Lesser General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* @author PocketMine Team
|
||||
* @link http://www.pocketmine.net/
|
||||
*
|
||||
*
|
||||
*/
|
||||
|
||||
namespace pocketmine\event\server;
|
||||
|
||||
use pocketmine\command\CommandSender;
|
||||
|
||||
/**
|
||||
* This event is called when a command is received over RCON.
|
||||
*/
|
||||
class RemoteServerCommandEvent extends ServerCommandEvent{
|
||||
public static $handlerList = null;
|
||||
|
||||
/**
|
||||
* @param CommandSender $sender
|
||||
* @param string $command
|
||||
*/
|
||||
public function __construct(CommandSender $sender, $command){
|
||||
parent::__construct($sender, $command);
|
||||
}
|
||||
|
||||
}
|
@ -26,6 +26,7 @@
|
||||
namespace pocketmine\network\rcon;
|
||||
|
||||
use pocketmine\command\RemoteConsoleCommandSender;
|
||||
use pocketmine\event\server\RemoteServerCommandEvent;
|
||||
use pocketmine\scheduler\CallbackTask;
|
||||
use pocketmine\Server;
|
||||
use pocketmine\utils\MainLogger;
|
||||
@ -90,7 +91,16 @@ class RCON{
|
||||
$thread->notify();
|
||||
}, $this->workers[$n]);
|
||||
}else{
|
||||
$this->server->dispatchCommand($response = new RemoteConsoleCommandSender(), $this->workers[$n]->cmd);
|
||||
|
||||
$response = new RemoteConsoleCommandSender();
|
||||
$command = $this->workers[$n]->cmd;
|
||||
|
||||
$this->server->getPluginManager()->callEvent($ev = new RemoteServerCommandEvent($response, $command));
|
||||
|
||||
if(!$ev->isCancelled()){
|
||||
$this->server->dispatchCommand($ev->getSender(), $ev->getCommand());
|
||||
}
|
||||
|
||||
$this->workers[$n]->response = TextFormat::clean($response->getMessage());
|
||||
$this->workers[$n]->synchronized(function(RCONInstance $thread){
|
||||
$thread->notify();
|
||||
|
Loading…
x
Reference in New Issue
Block a user