mirror of
https://github.com/pmmp/PocketMine-MP.git
synced 2025-09-06 17:59:48 +00:00
Implemented #3836: Replace setCancelled() in events with cancel() and uncancel()
The motivation for this is to prevent passing a dynamic argument to cancellation, which in almost all cases is a bug in user code. This same mistake also appears in a few places in the PM core (as seen in this commit), but in those cases the mistakes were mostly harmless since they were taking place before the event was actually called. closes #3836
This commit is contained in:
@ -1428,7 +1428,7 @@ class Player extends Human implements CommandSender, ChunkListener, IPlayer{
|
||||
|
||||
$ev = new PlayerItemUseEvent($this, $item, $directionVector);
|
||||
if($this->hasItemCooldown($item) or $this->isSpectator()){
|
||||
$ev->setCancelled();
|
||||
$ev->cancel();
|
||||
}
|
||||
|
||||
$ev->call();
|
||||
@ -1462,7 +1462,7 @@ class Player extends Human implements CommandSender, ChunkListener, IPlayer{
|
||||
if($slot instanceof ConsumableItem){
|
||||
$ev = new PlayerItemConsumeEvent($this, $slot);
|
||||
if($this->hasItemCooldown($slot)){
|
||||
$ev->setCancelled();
|
||||
$ev->cancel();
|
||||
}
|
||||
$ev->call();
|
||||
|
||||
@ -1521,7 +1521,7 @@ class Player extends Human implements CommandSender, ChunkListener, IPlayer{
|
||||
$ev = new PlayerBlockPickEvent($this, $block, $item);
|
||||
$existingSlot = $this->inventory->first($item);
|
||||
if($existingSlot === -1 and $this->hasFiniteResources()){
|
||||
$ev->setCancelled();
|
||||
$ev->cancel();
|
||||
}
|
||||
$ev->call();
|
||||
|
||||
@ -1563,7 +1563,7 @@ class Player extends Human implements CommandSender, ChunkListener, IPlayer{
|
||||
|
||||
$ev = new PlayerInteractEvent($this, $this->inventory->getItemInHand(), $target, null, $face, PlayerInteractEvent::LEFT_CLICK_BLOCK);
|
||||
if($this->isSpectator()){
|
||||
$ev->setCancelled();
|
||||
$ev->cancel();
|
||||
}
|
||||
$ev->call();
|
||||
if($ev->isCancelled()){
|
||||
@ -1669,7 +1669,7 @@ class Player extends Human implements CommandSender, ChunkListener, IPlayer{
|
||||
|
||||
$ev = new EntityDamageByEntityEvent($this, $entity, EntityDamageEvent::CAUSE_ENTITY_ATTACK, $heldItem->getAttackPoints());
|
||||
if($this->isSpectator() or !$this->canInteract($entity->getLocation(), 8) or ($entity instanceof Player and !$this->server->getConfigGroup()->getConfigBool("pvp"))){
|
||||
$ev->setCancelled();
|
||||
$ev->cancel();
|
||||
}
|
||||
|
||||
$meleeEnchantmentDamage = 0;
|
||||
@ -1751,7 +1751,9 @@ class Player extends Human implements CommandSender, ChunkListener, IPlayer{
|
||||
|
||||
public function toggleFlight(bool $fly) : bool{
|
||||
$ev = new PlayerToggleFlightEvent($this, $fly);
|
||||
$ev->setCancelled(!$this->allowFlight);
|
||||
if(!$this->allowFlight){
|
||||
$ev->cancel();
|
||||
}
|
||||
$ev->call();
|
||||
if($ev->isCancelled()){
|
||||
return false;
|
||||
@ -2175,9 +2177,9 @@ class Player extends Human implements CommandSender, ChunkListener, IPlayer{
|
||||
and $source->getCause() !== EntityDamageEvent::CAUSE_SUICIDE
|
||||
and $source->getCause() !== EntityDamageEvent::CAUSE_VOID
|
||||
){
|
||||
$source->setCancelled();
|
||||
$source->cancel();
|
||||
}elseif($this->allowFlight and $source->getCause() === EntityDamageEvent::CAUSE_FALL){
|
||||
$source->setCancelled();
|
||||
$source->cancel();
|
||||
}
|
||||
|
||||
parent::attack($source);
|
||||
|
Reference in New Issue
Block a user