From 3984a96052afcc8bf722a770dbd0d455f51ff6e4 Mon Sep 17 00:00:00 2001 From: jviguy Date: Tue, 1 Dec 2020 22:28:45 -0500 Subject: [PATCH 1/7] Update to 1.16.100 protocol and change up some usages and phpdocs --- plugin.yml | 2 +- src/slapper/Main.php | 90 ++++++++++----------- src/slapper/SlapperTrait.php | 4 +- src/slapper/events/SlapperCreationEvent.php | 8 +- src/slapper/events/SlapperHitEvent.php | 2 +- 5 files changed, 53 insertions(+), 53 deletions(-) diff --git a/plugin.yml b/plugin.yml index 3a0a6e0..5d07ac9 100755 --- a/plugin.yml +++ b/plugin.yml @@ -4,7 +4,7 @@ version: 1.6.1 description: Slapper, the NPC plugin for PocketMine-MP main: slapper\Main api: 3.13.0 -mcpe-protocol: [361, 388, 389, 390, 407, 408] +mcpe-protocol: [361, 388, 389, 390, 407, 408, 419] website: https://github.com/jojoe77777/Slapper commands: diff --git a/src/slapper/Main.php b/src/slapper/Main.php index 0e02ec5..d6e9277 100755 --- a/src/slapper/Main.php +++ b/src/slapper/Main.php @@ -22,22 +22,10 @@ use pocketmine\plugin\PluginBase; use pocketmine\utils\TextFormat; +use slapper\entities\SlapperEntity; +use slapper\entities\SlapperHuman; use slapper\entities\other\{ - SlapperBoat, SlapperFallingSand, SlapperMinecart, SlapperPrimedTNT -}; -use slapper\entities\{ - SlapperBat, SlapperBlaze, SlapperCaveSpider, SlapperChicken, - SlapperCow, SlapperCreeper, SlapperDonkey, SlapperElderGuardian, - SlapperEnderman, SlapperEndermite, SlapperEntity, SlapperEvoker, - SlapperGhast, SlapperGuardian, SlapperHorse, SlapperHuman, - SlapperHusk, SlapperIronGolem, SlapperLavaSlime, SlapperLlama, - SlapperMule, SlapperMushroomCow, SlapperOcelot, SlapperPig, - SlapperPigZombie, SlapperPolarBear, SlapperRabbit, SlapperSheep, - SlapperShulker, SlapperSilverfish, SlapperSkeleton, SlapperSkeletonHorse, - SlapperSlime, SlapperSnowman, SlapperSpider, SlapperSquid, - SlapperStray, SlapperVex, SlapperVillager, SlapperVindicator, - SlapperWitch, SlapperWither, SlapperWitherSkeleton, SlapperWolf, - SlapperZombie, SlapperZombieHorse, SlapperZombieVillager + SlapperFallingSand }; use slapper\events\SlapperCreationEvent; @@ -91,9 +79,10 @@ class Main extends PluginBase implements Listener { TextFormat::GREEN . "[" . TextFormat::YELLOW . "Slapper Help" . TextFormat::GREEN . "] " . TextFormat::YELLOW . "----------"; - /** @var string[] */ + /** @var string[] $mainArgs */ public $mainArgs = [ "help: /slapper help", + /** @lang text */ "spawn: /slapper spawn [name]", "edit: /slapper edit [id] [args...]", "id: /slapper id", @@ -101,21 +90,37 @@ class Main extends PluginBase implements Listener { "version: /slapper version", "cancel: /slapper cancel", ]; - /** @var string[] */ + /** + * @var string[] $editArgs + */ public $editArgs = [ + /** @lang text */ "helmet: /slapper edit helmet ", + /** @lang text */ "chestplate: /slapper edit chestplate ", + /** @lang text */ "leggings: /slapper edit leggings ", + /** @lang text */ "boots: /slapper edit boots ", + /** @lang text */ "skin: /slapper edit skin", + /** @lang text */ "name: /slapper edit name ", + /** @lang text */ "addcommand: /slapper edit addcommand ", - "delcommand: /slapper edit delcommand ", + /** @lang text */ + "delcommand: /slapper edit delcommand ", + /** @lang text */ "listcommands: /slapper edit listcommands", + /** @lang text */ "blockid: /slapper edit block ", + /** @lang text */ "scale: /slapper edit scale ", + /** @lang text */ "tphere: /slapper edit tphere", + /** @lang text */ "tpto: /slapper edit tpto", + /** @lang text */ "menuname: /slapper edit menuname " ]; @@ -123,27 +128,16 @@ class Main extends PluginBase implements Listener { * @return void */ public function onEnable(): void { - foreach ([ - SlapperCreeper::class, SlapperBat::class, SlapperSheep::class, - SlapperPigZombie::class, SlapperGhast::class, SlapperBlaze::class, - SlapperIronGolem::class, SlapperSnowman::class, SlapperOcelot::class, - SlapperZombieVillager::class, SlapperHuman::class, SlapperCow::class, - SlapperZombie::class, SlapperSquid::class, SlapperVillager::class, - SlapperSpider::class, SlapperPig::class, SlapperMushroomCow::class, - SlapperWolf::class, SlapperLavaSlime::class, SlapperSilverfish::class, - SlapperSkeleton::class, SlapperSlime::class, SlapperChicken::class, - SlapperEnderman::class, SlapperCaveSpider::class, SlapperBoat::class, - SlapperMinecart::class, SlapperMule::class, SlapperWitch::class, - SlapperPrimedTNT::class, SlapperHorse::class, SlapperDonkey::class, - SlapperSkeletonHorse::class, SlapperZombieHorse::class, SlapperRabbit::class, - SlapperStray::class, SlapperHusk::class, SlapperWitherSkeleton::class, - SlapperFallingSand::class, SlapperElderGuardian::class, SlapperEndermite::class, - SlapperEvoker::class, SlapperGuardian::class, SlapperLlama::class, - SlapperPolarBear::class, SlapperShulker::class, SlapperVex::class, - SlapperVindicator::class, SlapperWither::class - ] as $className) { - Entity::registerEntity($className, true); + //all the entities classified as a general SlapperEntity + $entities = glob(__DIR__."/entities/*.php"); + //all the entities classified as other + $other = glob(__DIR__."/entities/other/*.php"); + foreach ($entities as $className) { + Entity::registerEntity("slapper\\entities\\".basename($className,".php"), true); } + foreach ($other as $className) { + Entity::registerEntity("slapper\\entities\\other\\".basename($className,".php"), true); + } $this->getServer()->getPluginManager()->registerEvents($this, $this); } @@ -221,7 +215,8 @@ public function onCommand(CommandSender $sender, Command $command, string $label $entity = $sender->getLevel()->getEntity((int) $args[0]); if ($entity !== null) { if ($entity instanceof SlapperEntity || $entity instanceof SlapperHuman) { - $this->getServer()->getPluginManager()->callEvent(new SlapperDeletionEvent($entity)); + $event = new SlapperDeletionEvent($entity); + $event->call(); $entity->close(); $sender->sendMessage($this->prefix . "Entity removed."); } else { @@ -436,6 +431,7 @@ public function onCommand(CommandSender $sender, Command $command, string $label if (isset($args[2])) { if ($entity instanceof SlapperFallingSand) { $data = explode(":", $args[2]); + //TODO: Can we somehow find a new way cause there has to be one //haxx: we shouldn't use toStaticRuntimeId() because it's internal, but there isn't really any better option at the moment $entity->getDataPropertyManager()->setInt(Entity::DATA_VARIANT, BlockFactory::toStaticRuntimeId((int) ($data[0] ?? 1), (int) ($data[1] ?? 0))); $entity->sendData($entity->getViewers()); @@ -547,9 +543,10 @@ public function onCommand(CommandSender $sender, Command $command, string $label $nbt = $this->makeNBT($chosenType, $sender, $name); /** @var SlapperEntity $entity */ $entity = Entity::createEntity("Slapper" . $chosenType, $sender->getLevel(), $nbt); - $this->getServer()->getPluginManager()->callEvent(new SlapperCreationEvent($entity, "Slapper" . $chosenType, $sender, SlapperCreationEvent::CAUSE_COMMAND)); - $entity->spawnToAll(); - $sender->sendMessage($this->prefix . $chosenType . " entity spawned with name " . TextFormat::WHITE . "\"" . TextFormat::BLUE . $name . TextFormat::WHITE . "\"" . TextFormat::GREEN . " and entity ID " . TextFormat::BLUE . $entity->getId()); + $ev = new SlapperCreationEvent($entity, "Slapper" . $chosenType, $sender, SlapperCreationEvent::CAUSE_COMMAND); + $ev->call(); + $entity->spawnToAll(); + $sender->sendMessage($this->prefix . $chosenType . " entity spawned with name " . TextFormat::WHITE . "\"" . TextFormat::BLUE . $name . TextFormat::WHITE . "\"" . TextFormat::GREEN . " and entity ID " . TextFormat::BLUE . $entity->getId()); return true; default: $sender->sendMessage($this->prefix . "Unknown command. Type '/slapper help' for help."); @@ -570,7 +567,7 @@ public function onCommand(CommandSender $sender, Command $command, string $label * * @return CompoundTag */ - private function makeNBT($type, Player $player, string $name): CompoundTag { + private function makeNBT(string $type, Player $player, string $name): CompoundTag { $nbt = Entity::createBaseNBT($player, null, $player->getYaw(), $player->getPitch()); $nbt->setShort("Health", 1); $nbt->setTag(new CompoundTag("Commands", [])); @@ -609,7 +606,8 @@ public function onEntityDamage(EntityDamageEvent $event): void { if (!$damager instanceof Player) { return; } - $this->getServer()->getPluginManager()->callEvent($event = new SlapperHitEvent($entity, $damager)); + $event = new SlapperHitEvent($entity, $damager); + $event->call(); if ($event->isCancelled()) { return; } @@ -642,13 +640,15 @@ public function onEntityDamage(EntityDamageEvent $event): void { /** * @param EntitySpawnEvent $ev * + * @noinspection ALL + * * @return void */ public function onEntitySpawn(EntitySpawnEvent $ev): void { $entity = $ev->getEntity(); if ($entity instanceof SlapperEntity || $entity instanceof SlapperHuman) { $clearLagg = $this->getServer()->getPluginManager()->getPlugin("ClearLagg"); - if ($clearLagg !== null) { + if ($clearLagg !== null && $clearLagg instanceof ClearLagg\Loader) { $clearLagg->exemptEntity($entity); } } diff --git a/src/slapper/SlapperTrait.php b/src/slapper/SlapperTrait.php index 6a5527c..acfd4bf 100644 --- a/src/slapper/SlapperTrait.php +++ b/src/slapper/SlapperTrait.php @@ -8,7 +8,6 @@ use pocketmine\entity\Entity; use pocketmine\nbt\tag\CompoundTag; use pocketmine\nbt\tag\FloatTag; -use pocketmine\nbt\tag\IntTag; use pocketmine\network\mcpe\protocol\SetActorDataPacket as SetEntityDataPacket; use pocketmine\Player; @@ -16,7 +15,8 @@ * Trait containing methods used in various Slappers. */ trait SlapperTrait { - /** @var CompoundTag */ + + /** @var CompoundTag $namedtag */ public $namedtag; /** diff --git a/src/slapper/events/SlapperCreationEvent.php b/src/slapper/events/SlapperCreationEvent.php index e06a52f..d3a9662 100755 --- a/src/slapper/events/SlapperCreationEvent.php +++ b/src/slapper/events/SlapperCreationEvent.php @@ -12,13 +12,13 @@ class SlapperCreationEvent extends EntityEvent { const CAUSE_COMMAND = 0; - /** @var Entity */ + /** @var Entity $entity */ protected $entity; - /** @var string */ + /** @var string $type */ private $type; - /** @var Player|null */ + /** @var Player|null $creator */ private $creator; - /** @var int */ + /** @var int $cause */ private $cause; diff --git a/src/slapper/events/SlapperHitEvent.php b/src/slapper/events/SlapperHitEvent.php index 94b5e95..487b8cd 100755 --- a/src/slapper/events/SlapperHitEvent.php +++ b/src/slapper/events/SlapperHitEvent.php @@ -11,7 +11,7 @@ class SlapperHitEvent extends EntityEvent implements Cancellable { - /** @var Player */ + /** @var Player $damager */ private $damager; public function __construct(Entity $entity, Player $damager) { From d445007b8f8be02d1fd623101652cabbb44329ee Mon Sep 17 00:00:00 2001 From: jviguy Date: Tue, 1 Dec 2020 22:39:57 -0500 Subject: [PATCH 2/7] fix up malformed class path and hide phpstan from a lint function --- src/slapper/Main.php | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/slapper/Main.php b/src/slapper/Main.php index d6e9277..6951ad5 100755 --- a/src/slapper/Main.php +++ b/src/slapper/Main.php @@ -640,6 +640,8 @@ public function onEntityDamage(EntityDamageEvent $event): void { /** * @param EntitySpawnEvent $ev * + * @phpstan ignore + * * @noinspection ALL * * @return void @@ -648,7 +650,7 @@ public function onEntitySpawn(EntitySpawnEvent $ev): void { $entity = $ev->getEntity(); if ($entity instanceof SlapperEntity || $entity instanceof SlapperHuman) { $clearLagg = $this->getServer()->getPluginManager()->getPlugin("ClearLagg"); - if ($clearLagg !== null && $clearLagg instanceof ClearLagg\Loader) { + if ($clearLagg !== null && $clearLagg instanceof \ClearLagg\Loader) { $clearLagg->exemptEntity($entity); } } From a06141a4c6a8c6d8bd6888b7f796564ea788083a Mon Sep 17 00:00:00 2001 From: jviguy Date: Tue, 1 Dec 2020 22:43:39 -0500 Subject: [PATCH 3/7] trying to fix up the lints because I have ocd about that stuff --- src/slapper/Main.php | 3 +++ 1 file changed, 3 insertions(+) diff --git a/src/slapper/Main.php b/src/slapper/Main.php index 6951ad5..9fd3b49 100755 --- a/src/slapper/Main.php +++ b/src/slapper/Main.php @@ -642,6 +642,8 @@ public function onEntityDamage(EntityDamageEvent $event): void { * * @phpstan ignore * + * @phpstan-ignore-next-line + * * @noinspection ALL * * @return void @@ -650,6 +652,7 @@ public function onEntitySpawn(EntitySpawnEvent $ev): void { $entity = $ev->getEntity(); if ($entity instanceof SlapperEntity || $entity instanceof SlapperHuman) { $clearLagg = $this->getServer()->getPluginManager()->getPlugin("ClearLagg"); + /** @phpstan-ignore-next-line */ if ($clearLagg !== null && $clearLagg instanceof \ClearLagg\Loader) { $clearLagg->exemptEntity($entity); } From e663481b329ed96d1beeffbe082283ec5b8fc245 Mon Sep 17 00:00:00 2001 From: jviguy Date: Tue, 1 Dec 2020 22:45:48 -0500 Subject: [PATCH 4/7] Fixed lints --- src/slapper/Main.php | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/src/slapper/Main.php b/src/slapper/Main.php index 9fd3b49..eabf561 100755 --- a/src/slapper/Main.php +++ b/src/slapper/Main.php @@ -639,10 +639,6 @@ public function onEntityDamage(EntityDamageEvent $event): void { /** * @param EntitySpawnEvent $ev - * - * @phpstan ignore - * - * @phpstan-ignore-next-line * * @noinspection ALL * @@ -654,6 +650,7 @@ public function onEntitySpawn(EntitySpawnEvent $ev): void { $clearLagg = $this->getServer()->getPluginManager()->getPlugin("ClearLagg"); /** @phpstan-ignore-next-line */ if ($clearLagg !== null && $clearLagg instanceof \ClearLagg\Loader) { + /** @phpstan-ignore-next-line */ $clearLagg->exemptEntity($entity); } } From 307b8561b439b410073ca4a31484ae0f4fe37db5 Mon Sep 17 00:00:00 2001 From: jviguy Date: Tue, 1 Dec 2020 22:52:41 -0500 Subject: [PATCH 5/7] i forgot to up the version fixed now --- plugin.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/plugin.yml b/plugin.yml index 5d07ac9..d5001f2 100755 --- a/plugin.yml +++ b/plugin.yml @@ -1,6 +1,6 @@ name: Slapper author: jojoe77777 -version: 1.6.1 +version: 1.6.2 description: Slapper, the NPC plugin for PocketMine-MP main: slapper\Main api: 3.13.0 From e4f1dfbf4222486d869f0ec57b4e7ab194871fa7 Mon Sep 17 00:00:00 2001 From: jviguy Date: Tue, 1 Dec 2020 22:55:03 -0500 Subject: [PATCH 6/7] lints randomly appeared again --- src/slapper/Main.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/slapper/Main.php b/src/slapper/Main.php index eabf561..f3059f1 100755 --- a/src/slapper/Main.php +++ b/src/slapper/Main.php @@ -650,7 +650,7 @@ public function onEntitySpawn(EntitySpawnEvent $ev): void { $clearLagg = $this->getServer()->getPluginManager()->getPlugin("ClearLagg"); /** @phpstan-ignore-next-line */ if ($clearLagg !== null && $clearLagg instanceof \ClearLagg\Loader) { - /** @phpstan-ignore-next-line */ + /** @phpstan-ignore-next-line */ $clearLagg->exemptEntity($entity); } } From c991f70a6e26981c88021231f9e8077f08ca87b3 Mon Sep 17 00:00:00 2001 From: Jviguy <62412449+Jviguy@users.noreply.github.com> Date: Sat, 12 Dec 2020 18:23:16 -0500 Subject: [PATCH 7/7] Update to latest protocol --- plugin.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/plugin.yml b/plugin.yml index d5001f2..ec67737 100755 --- a/plugin.yml +++ b/plugin.yml @@ -4,7 +4,7 @@ version: 1.6.2 description: Slapper, the NPC plugin for PocketMine-MP main: slapper\Main api: 3.13.0 -mcpe-protocol: [361, 388, 389, 390, 407, 408, 419] +mcpe-protocol: [361, 388, 389, 390, 407, 408, 419, 422] website: https://github.com/jojoe77777/Slapper commands: