Removed EntityInventoryChangeEvent and EntityArmorChangeEvent

there is nothing that these events do that can't be fulfilled by transactions. They complicate the internal implementation and produce unexpected behaviour for plugins when cancelled.

TL;DR: Use transactions. That's what they are there for.
This commit is contained in:
Dylan K. Taylor
2019-05-19 16:02:03 +01:00
parent 67affcea32
commit dec6c9f49b
6 changed files with 7 additions and 144 deletions

View File

@ -28,12 +28,10 @@ use pocketmine\entity\effect\EffectInstance;
use pocketmine\entity\projectile\ProjectileSource;
use pocketmine\entity\utils\ExperienceUtils;
use pocketmine\event\entity\EntityDamageEvent;
use pocketmine\event\entity\EntityInventoryChangeEvent;
use pocketmine\event\entity\EntityRegainHealthEvent;
use pocketmine\event\player\PlayerExhaustEvent;
use pocketmine\event\player\PlayerExperienceChangeEvent;
use pocketmine\inventory\EnderChestInventory;
use pocketmine\inventory\Inventory;
use pocketmine\inventory\InventoryHolder;
use pocketmine\inventory\PlayerInventory;
use pocketmine\item\Consumable;
@ -648,16 +646,6 @@ class Human extends Creature implements ProjectileSource, InventoryHolder{
$this->inventory->setHeldItemIndex($nbt->getInt("SelectedInventorySlot", 0), false);
$this->inventory->setSlotChangeListener(function(Inventory $inventory, int $slot, Item $oldItem, Item $newItem) : ?Item{
$ev = new EntityInventoryChangeEvent($this, $oldItem, $newItem, $slot);
$ev->call();
if($ev->isCancelled()){
return null;
}
return $ev->getNewItem();
});
$this->setFood((float) $nbt->getInt("foodLevel", (int) $this->getFood(), true));
$this->setExhaustion($nbt->getFloat("foodExhaustionLevel", $this->getExhaustion(), true));
$this->setSaturation($nbt->getFloat("foodSaturationLevel", $this->getSaturation(), true));

View File

@ -26,7 +26,6 @@ namespace pocketmine\entity;
use pocketmine\block\Block;
use pocketmine\entity\effect\Effect;
use pocketmine\entity\effect\EffectInstance;
use pocketmine\event\entity\EntityArmorChangeEvent;
use pocketmine\event\entity\EntityDamageByChildEntityEvent;
use pocketmine\event\entity\EntityDamageByEntityEvent;
use pocketmine\event\entity\EntityDamageEvent;
@ -34,7 +33,6 @@ use pocketmine\event\entity\EntityDeathEvent;
use pocketmine\event\entity\EntityEffectAddEvent;
use pocketmine\event\entity\EntityEffectRemoveEvent;
use pocketmine\inventory\ArmorInventory;
use pocketmine\inventory\Inventory;
use pocketmine\item\Armor;
use pocketmine\item\Consumable;
use pocketmine\item\Durable;
@ -96,15 +94,6 @@ abstract class Living extends Entity implements Damageable{
$this->armorInventory = new ArmorInventory($this);
//TODO: load/save armor inventory contents
$this->armorInventory->setSlotChangeListener(function(Inventory $inventory, int $slot, Item $oldItem, Item $newItem) : ?Item{
$ev = new EntityArmorChangeEvent($this, $oldItem, $newItem, $slot);
$ev->call();
if($ev->isCancelled()){
return null;
}
return $ev->getNewItem();
});
$health = $this->getMaxHealth();