Added SignChangeEvent

This commit is contained in:
Shoghi Cervantes 2014-08-16 12:58:16 +02:00
parent 8725ad522f
commit 7e4a191593
3 changed files with 108 additions and 8 deletions

View File

@ -27,6 +27,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;
@ -2016,18 +2017,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);
}
}
}

View File

@ -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;
}

View 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;
}
}