Skip to content

Commit

Permalink
Refactored effects handling, split up concerns of effect types and in…
Browse files Browse the repository at this point in the history
…stances

Removed json insanity for effects

Split up effect types and effect instances

Saturation is an instant effect
  • Loading branch information
dktapps committed Mar 7, 2018
1 parent c7f8796 commit dc3bf85
Show file tree
Hide file tree
Showing 17 changed files with 441 additions and 452 deletions.
23 changes: 23 additions & 0 deletions src/pocketmine/Player.php
Expand Up @@ -29,6 +29,7 @@
use pocketmine\command\Command;
use pocketmine\command\CommandSender;
use pocketmine\entity\Effect;
use pocketmine\entity\EffectInstance;
use pocketmine\entity\Entity;
use pocketmine\entity\Human;
use pocketmine\entity\Item as DroppedItem;
Expand Down Expand Up @@ -114,6 +115,7 @@
use pocketmine\network\mcpe\protocol\LevelEventPacket;
use pocketmine\network\mcpe\protocol\LevelSoundEventPacket;
use pocketmine\network\mcpe\protocol\LoginPacket;
use pocketmine\network\mcpe\protocol\MobEffectPacket;
use pocketmine\network\mcpe\protocol\MobEquipmentPacket;
use pocketmine\network\mcpe\protocol\MovePlayerPacket;
use pocketmine\network\mcpe\protocol\PlayerActionPacket;
Expand Down Expand Up @@ -1722,6 +1724,27 @@ public function canBreathe() : bool{
return $this->isCreative() or parent::canBreathe();
}

protected function sendEffectAdd(EffectInstance $effect, bool $replacesOldEffect) : void{
$pk = new MobEffectPacket();
$pk->entityRuntimeId = $this->getId();
$pk->eventId = $replacesOldEffect ? MobEffectPacket::EVENT_MODIFY : MobEffectPacket::EVENT_ADD;
$pk->effectId = $effect->getId();
$pk->amplifier = $effect->getAmplifier();
$pk->particles = $effect->isVisible();
$pk->duration = $effect->getDuration();

$this->dataPacket($pk);
}

protected function sendEffectRemove(EffectInstance $effect) : void{
$pk = new MobEffectPacket();
$pk->entityRuntimeId = $this->getId();
$pk->eventId = MobEffectPacket::EVENT_REMOVE;
$pk->effectId = $effect->getId();

$this->dataPacket($pk);
}

public function checkNetwork(){
if(!$this->isOnline()){
return;
Expand Down
4 changes: 2 additions & 2 deletions src/pocketmine/block/Cake.php
Expand Up @@ -23,7 +23,7 @@

namespace pocketmine\block;

use pocketmine\entity\Effect;
use pocketmine\entity\EffectInstance;
use pocketmine\entity\Living;
use pocketmine\item\FoodSource;
use pocketmine\item\Item;
Expand Down Expand Up @@ -127,7 +127,7 @@ public function getResidue(){
}

/**
* @return Effect[]
* @return EffectInstance[]
*/
public function getAdditionalEffects() : array{
return [];
Expand Down
13 changes: 7 additions & 6 deletions src/pocketmine/command/defaults/EffectCommand.php
Expand Up @@ -26,6 +26,7 @@
use pocketmine\command\CommandSender;
use pocketmine\command\utils\InvalidCommandSyntaxException;
use pocketmine\entity\Effect;
use pocketmine\entity\EffectInstance;
use pocketmine\lang\TranslationContainer;
use pocketmine\utils\TextFormat;

Expand Down Expand Up @@ -81,7 +82,7 @@ public function execute(CommandSender $sender, string $commandLabel, array $args
if(count($args) >= 3){
$duration = ((int) $args[2]) * 20; //ticks
}else{
$duration = $effect->getDefaultDuration();
$duration = null;
}

if(count($args) >= 4){
Expand All @@ -95,10 +96,11 @@ public function execute(CommandSender $sender, string $commandLabel, array $args
}
}

$visible = true;
if(count($args) >= 5){
$v = strtolower($args[4]);
if($v === "on" or $v === "true" or $v === "t" or $v === "1"){
$effect->setVisible(false);
$visible = false;
}
}

Expand All @@ -115,10 +117,9 @@ public function execute(CommandSender $sender, string $commandLabel, array $args
$player->removeEffect($effect->getId());
$sender->sendMessage(new TranslationContainer("commands.effect.success.removed", [$effect->getName(), $player->getDisplayName()]));
}else{
$effect->setDuration($duration)->setAmplifier($amplification);

$player->addEffect($effect);
self::broadcastCommandMessage($sender, new TranslationContainer("%commands.effect.success", [$effect->getName(), $effect->getAmplifier(), $player->getDisplayName(), $effect->getDuration() / 20, $effect->getId()]));
$instance = new EffectInstance($effect, $duration, $amplification, $visible);
$player->addEffect($instance);
self::broadcastCommandMessage($sender, new TranslationContainer("%commands.effect.success", [$effect->getName(), $instance->getAmplifier(), $player->getDisplayName(), $instance->getDuration() / 20, $effect->getId()]));
}


Expand Down

0 comments on commit dc3bf85

Please sign in to comment.