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:
Dylan K. Taylor
2020-09-26 14:31:56 +01:00
parent 75e3a0aa0f
commit 7b02cc3efd
12 changed files with 41 additions and 27 deletions

View File

@ -27,10 +27,10 @@ namespace pocketmine\event\entity;
* Called when an effect is removed from an entity.
*/
class EntityEffectRemoveEvent extends EntityEffectEvent{
public function setCancelled(bool $value = true) : void{
public function cancel() : void{
if($this->getEffect()->getDuration() <= 0){
throw new \InvalidStateException("Removal of expired effects cannot be cancelled");
}
parent::setCancelled($value);
parent::cancel();
}
}