Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions plugin.yml
Original file line number Diff line number Diff line change
@@ -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:
Expand Down
94 changes: 48 additions & 46 deletions src/slapper/Main.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -91,59 +79,65 @@ 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 <type> [name]",
"edit: /slapper edit [id] [args...]",
"id: /slapper id",
"remove: /slapper remove [id]",
"version: /slapper version",
"cancel: /slapper cancel",
];
/** @var string[] */
/**
* @var string[] $editArgs
*/
public $editArgs = [
/** @lang text */
"helmet: /slapper edit <eid> helmet <id>",
/** @lang text */
"chestplate: /slapper edit <eid> chestplate <id>",
/** @lang text */
"leggings: /slapper edit <eid> leggings <id>",
/** @lang text */
"boots: /slapper edit <eid> boots <id>",
/** @lang text */
"skin: /slapper edit <eid> skin",
/** @lang text */
"name: /slapper edit <eid> name <name>",
/** @lang text */
"addcommand: /slapper edit <eid> addcommand <command>",
"delcommand: /slapper edit <eid> delcommand <command>",
/** @lang text */
"delcommand: /slapper edit <eid> delcommand <command>",
/** @lang text */
"listcommands: /slapper edit <eid> listcommands",
/** @lang text */
"blockid: /slapper edit <eid> block <id[:meta]>",
/** @lang text */
"scale: /slapper edit <eid> scale <size>",
/** @lang text */
"tphere: /slapper edit <eid> tphere",
/** @lang text */
"tpto: /slapper edit <eid> tpto",
/** @lang text */
"menuname: /slapper edit <eid> menuname <name/remove>"
];

/**
* @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);
}

Expand Down Expand Up @@ -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 {
Expand Down Expand Up @@ -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());
Expand Down Expand Up @@ -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.");
Expand All @@ -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", []));
Expand Down Expand Up @@ -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;
}
Expand Down Expand Up @@ -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);
}
}
Expand Down
4 changes: 2 additions & 2 deletions src/slapper/SlapperTrait.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,15 +8,15 @@
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;

/**
* Trait containing methods used in various Slappers.
*/
trait SlapperTrait {
/** @var CompoundTag */

/** @var CompoundTag $namedtag */
public $namedtag;

/**
Expand Down
8 changes: 4 additions & 4 deletions src/slapper/events/SlapperCreationEvent.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;


Expand Down
2 changes: 1 addition & 1 deletion src/slapper/events/SlapperHitEvent.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@

class SlapperHitEvent extends EntityEvent implements Cancellable {

/** @var Player */
/** @var Player $damager */
private $damager;

public function __construct(Entity $entity, Player $damager) {
Expand Down