diff --git a/plugin.yml b/plugin.yml index 3a0a6e0..ec67737 100755 --- a/plugin.yml +++ b/plugin.yml @@ -1,10 +1,10 @@ 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 -mcpe-protocol: [361, 388, 389, 390, 407, 408] +mcpe-protocol: [361, 388, 389, 390, 407, 408, 419, 422] website: https://github.com/jojoe77777/Slapper commands: diff --git a/src/slapper/Main.php b/src/slapper/Main.php index 0e02ec5..f3059f1 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; } @@ -641,14 +639,18 @@ 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) { + /** @phpstan-ignore-next-line */ + if ($clearLagg !== null && $clearLagg instanceof \ClearLagg\Loader) { + /** @phpstan-ignore-next-line */ $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) {