mirror of
https://github.com/pmmp/PocketMine-MP.git
synced 2025-06-11 22:15:30 +00:00
Fixed some inventory events not firing on players
This commit is contained in:
parent
da4334f06b
commit
75c0d8324c
@ -140,7 +140,7 @@ class Player extends Human implements CommandSender, InventoryHolder, IPlayer{
|
||||
|
||||
protected $sendIndex = 0;
|
||||
|
||||
public $blocked = true;
|
||||
public $blocked = false;
|
||||
public $achievements = [];
|
||||
public $lastCorrect;
|
||||
/** @var SimpleTransactionGroup */
|
||||
@ -625,13 +625,6 @@ class Player extends Human implements CommandSender, InventoryHolder, IPlayer{
|
||||
$this->level->requestChunk($X, $Z, $this, LevelProvider::ORDER_ZXY);
|
||||
}
|
||||
|
||||
|
||||
if(count($this->usedChunks) < 16 and $this->spawned === true){
|
||||
$this->blocked = true;
|
||||
}elseif($this->spawned === true){
|
||||
$this->blocked = false; //TODO: reason of block to revert
|
||||
}
|
||||
|
||||
if(count($this->usedChunks) >= 56 and $this->spawned === false){
|
||||
$spawned = 0;
|
||||
foreach($this->usedChunks as $d){
|
||||
@ -646,8 +639,6 @@ class Player extends Human implements CommandSender, InventoryHolder, IPlayer{
|
||||
|
||||
$this->spawned = true;
|
||||
|
||||
$this->blocked = false;
|
||||
|
||||
$pk = new SetTimePacket();
|
||||
$pk->time = $this->level->getTime();
|
||||
$pk->started = $this->level->stopTime == false;
|
||||
@ -1255,7 +1246,7 @@ class Player extends Human implements CommandSender, InventoryHolder, IPlayer{
|
||||
}
|
||||
}
|
||||
|
||||
if($this->nextChunkOrderRun-- <= 0){
|
||||
if($this->nextChunkOrderRun-- <= 0 or $this->chunk === null){
|
||||
$this->orderChunks();
|
||||
}
|
||||
|
||||
@ -1561,7 +1552,7 @@ class Player extends Human implements CommandSender, InventoryHolder, IPlayer{
|
||||
}
|
||||
break;
|
||||
case ProtocolInfo::USE_ITEM_PACKET:
|
||||
if($this->spawned === false or $this->dead === true){
|
||||
if($this->spawned === false or $this->dead === true or $this->blocked){
|
||||
break;
|
||||
}
|
||||
|
||||
@ -1569,7 +1560,7 @@ class Player extends Human implements CommandSender, InventoryHolder, IPlayer{
|
||||
|
||||
$this->craftingType = 0;
|
||||
|
||||
if(($this->spawned === false or $this->blocked === true or $this->dead === true) and $packet->face >= 0 and $packet->face <= 5){
|
||||
if($packet->face >= 0 and $packet->face <= 5){
|
||||
$target = $this->level->getBlock($blockVector);
|
||||
$block = $target->getSide($packet->face);
|
||||
|
||||
@ -1798,7 +1789,7 @@ class Player extends Human implements CommandSender, InventoryHolder, IPlayer{
|
||||
break;
|
||||
|
||||
case ProtocolInfo::INTERACT_PACKET:
|
||||
if($this->spawned === false or $this->dead === true){
|
||||
if($this->spawned === false or $this->dead === true or $this->blocked){
|
||||
break;
|
||||
}
|
||||
|
||||
@ -1816,7 +1807,7 @@ class Player extends Human implements CommandSender, InventoryHolder, IPlayer{
|
||||
$cancelled = true;
|
||||
}
|
||||
|
||||
if($target instanceof Entity and $this->getGamemode() !== Player::VIEW and $this->blocked === false and $this->dead !== true and $target->dead !== true){
|
||||
if($target instanceof Entity and $this->getGamemode() !== Player::VIEW and $this->dead !== true and $target->dead !== true){
|
||||
if($target instanceof DroppedItem or $target instanceof Arrow){
|
||||
$this->kick("Attempting to attack an invalid entity");
|
||||
$this->server->getLogger()->warning("Player ". $this->getName() ." tried to attack an invalid entity");
|
||||
|
@ -738,7 +738,9 @@ abstract class Entity extends Location implements Metadatable{
|
||||
}
|
||||
|
||||
$this->level->removeEntity($this);
|
||||
$this->chunk->removeEntity($this);
|
||||
if($this->chunk !== null){
|
||||
$this->chunk->removeEntity($this);
|
||||
}
|
||||
$this->despawnFromAll();
|
||||
if($this instanceof Player){
|
||||
foreach($this->usedChunks as $index => $d){
|
||||
|
@ -235,7 +235,7 @@ abstract class BaseInventory implements Inventory{
|
||||
for($i = 0; $i < $this->getSize(); ++$i){
|
||||
$item = $this->getItem($i);
|
||||
foreach($slots as $index => $slot){
|
||||
if($item->getID() === Item::AIR){
|
||||
if($item->getID() === Item::AIR or $item->getCount() <= 0){
|
||||
$amount = min($slot->getMaxStackSize(), $slot->getCount(), $this->getMaxStackSize());
|
||||
$slot->setCount($slot->getCount() - $amount);
|
||||
$item = clone $slot;
|
||||
|
@ -23,6 +23,7 @@ namespace pocketmine\inventory;
|
||||
|
||||
use pocketmine\entity\Human;
|
||||
use pocketmine\event\entity\EntityArmorChangeEvent;
|
||||
use pocketmine\event\entity\EntityInventoryChangeEvent;
|
||||
use pocketmine\event\player\PlayerItemHeldEvent;
|
||||
use pocketmine\item\Item;
|
||||
use pocketmine\network\protocol\ContainerSetContentPacket;
|
||||
@ -200,6 +201,8 @@ class PlayerInventory extends BaseInventory{
|
||||
public function setItem($index, Item $item, $source = null){
|
||||
if($index < 0 or $index >= $this->size){
|
||||
return false;
|
||||
}elseif($item->getID() === 0){
|
||||
$this->clear($index, $source);
|
||||
}
|
||||
|
||||
if($index >= $this->getSize()){ //Armor change
|
||||
@ -211,15 +214,21 @@ class PlayerInventory extends BaseInventory{
|
||||
return false;
|
||||
}
|
||||
$item = $ev->getNewItem();
|
||||
}else{
|
||||
Server::getInstance()->getPluginManager()->callEvent($ev = new EntityInventoryChangeEvent($this->getHolder(), $this->getItem($index), $item, $index));
|
||||
if($ev->isCancelled()){
|
||||
$this->sendArmorContents($this->getViewers());
|
||||
$this->sendContents($this->getViewers());
|
||||
|
||||
return false;
|
||||
}
|
||||
$item = $ev->getNewItem();
|
||||
}
|
||||
|
||||
if($item->getID() === 0){
|
||||
$this->clear($index, $source);
|
||||
}else{
|
||||
$old = $this->getItem($index);
|
||||
$this->slots[$index] = clone $item;
|
||||
$this->onSlotChange($index, $old, $source);
|
||||
}
|
||||
|
||||
$old = $this->getItem($index);
|
||||
$this->slots[$index] = clone $item;
|
||||
$this->onSlotChange($index, $old, $source);
|
||||
|
||||
return true;
|
||||
}
|
||||
@ -234,7 +243,16 @@ class PlayerInventory extends BaseInventory{
|
||||
$this->sendArmorContents($this->getViewers());
|
||||
$this->sendContents($this->getViewers());
|
||||
|
||||
return;
|
||||
return false;
|
||||
}
|
||||
$item = $ev->getNewItem();
|
||||
}else{
|
||||
Server::getInstance()->getPluginManager()->callEvent($ev = new EntityInventoryChangeEvent($this->getHolder(), $old, $item, $index));
|
||||
if($ev->isCancelled()){
|
||||
$this->sendArmorContents($this->getViewers());
|
||||
$this->sendContents($this->getViewers());
|
||||
|
||||
return false;
|
||||
}
|
||||
$item = $ev->getNewItem();
|
||||
}
|
||||
@ -246,6 +264,8 @@ class PlayerInventory extends BaseInventory{
|
||||
|
||||
$this->onSlotChange($index, $old, $source);
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
|
Loading…
x
Reference in New Issue
Block a user