Skip to content

Commit

Permalink
Merge pull request #54 from DuoIncure/stable
Browse files Browse the repository at this point in the history
Update to 1.19.30 and fix outstanding bugs
  • Loading branch information
Vecnavium authored Oct 6, 2022
2 parents 04adc15 + 7695961 commit 9c04800
Show file tree
Hide file tree
Showing 11 changed files with 39 additions and 54 deletions.
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: [Vecnavium, jojoe77777]
version: 2.1.1
version: 2.1.2
description: Slapper, the NPC plugin for PocketMine-MP
main: slapper\Main
api: 4.0.0
mcpe-protocol: 544
mcpe-protocol: 554

commands:
slapper:
Expand Down
1 change: 0 additions & 1 deletion src/slapper/CheckUpdateTask.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
use pocketmine\scheduler\AsyncTask;
use pocketmine\Server;
use pocketmine\utils\Internet;
use function is_array;
use function json_decode;
use function version_compare;
use function vsprintf;
Expand Down
41 changes: 17 additions & 24 deletions src/slapper/Main.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,6 @@
use pocketmine\block\BlockFactory;
use pocketmine\command\Command;
use pocketmine\command\CommandSender;
use pocketmine\command\ConsoleCommandSender;
use pocketmine\entity\Entity;
use pocketmine\entity\EntityDataHelper;
use pocketmine\entity\EntityFactory;
use pocketmine\entity\Human;
Expand All @@ -26,13 +24,9 @@
use pocketmine\utils\AssumptionFailedError;
use pocketmine\utils\TextFormat;
use pocketmine\utils\Utils;
use pocketmine\world\Location;
use pocketmine\world\World;
use slapper\entities\other\SlapperBoat;
use slapper\entities\SlapperBoat;
use slapper\entities\SlapperEndCrystal;
use slapper\entities\other\SlapperFallingSand;
use slapper\entities\other\SlapperMinecart;
use slapper\entities\other\SlapperPrimedTNT;
use slapper\entities\SlapperBat;
use slapper\entities\SlapperBlaze;
use slapper\entities\SlapperCaveSpider;
Expand All @@ -45,6 +39,7 @@
use slapper\entities\SlapperEndermite;
use slapper\entities\SlapperEntity;
use slapper\entities\SlapperEvoker;
use slapper\entities\SlapperFallingSand;
use slapper\entities\SlapperGhast;
use slapper\entities\SlapperGuardian;
use slapper\entities\SlapperHorse;
Expand All @@ -53,12 +48,14 @@
use slapper\entities\SlapperHusk;
use slapper\entities\SlapperLavaSlime;
use slapper\entities\SlapperLlama;
use slapper\entities\SlapperMinecart;
use slapper\entities\SlapperMule;
use slapper\entities\SlapperMushroomCow;
use slapper\entities\SlapperOcelot;
use slapper\entities\SlapperPig;
use slapper\entities\SlapperPigZombie;
use slapper\entities\SlapperPolarBear;
use slapper\entities\SlapperPrimedTNT;
use slapper\entities\SlapperRabbit;
use slapper\entities\SlapperSheep;
use slapper\entities\SlapperShulker;
Expand Down Expand Up @@ -140,7 +137,7 @@ class Main extends PluginBase implements Listener {
"remove: /slapper remove [id]",
"version: /slapper version",
"cancel: /slapper cancel",
"entitys: /slapper entitys",
"entities: /slapper entities",
];
/** @var string[] */
public $editArgs = [
Expand Down Expand Up @@ -210,7 +207,6 @@ public function registerEntities(): void {
}

public function checkUpdate(bool $isRetry = false): void {

$this->getServer()->getAsyncPool()->submitTask(new CheckUpdateTask($this->getDescription()->getName(), $this->getDescription()->getVersion()));
}

Expand All @@ -236,12 +232,11 @@ public function onCommand(CommandSender $sender, Command $command, string $label
$player = $this->getServer()->getPlayerByPrefix(array_shift($args));
if ($player instanceof Player) {
$this->getServer()->dispatchCommand($player, trim(implode(" ", $args)));
return true;
} else {
} else {
$sender->sendMessage($this->prefix . "Player not found.");
return true;
}
case "slapper":
}
return true;
case "slapper":
if ($sender instanceof Player) {
if (!isset($args[0])) {
$sender->sendMessage($this->prefix . "Please type '/slapper help'.");
Expand Down Expand Up @@ -273,13 +268,13 @@ public function onCommand(CommandSender $sender, Command $command, string $label
$sender->sendMessage($this->prefix . "Cancelled.");
return true;
case "list":
case "entitys":
case "entities":
if (!$sender->hasPermission("slapper.list")) {
$sender->sendMessage($this->noperm);
return true;
}
$sender->sendMessage($this->prefix . "Entity List."
. TextFormat::BLUE . "Creeper, Bat, Sheep, PigZombie, Ghast, Blaze, IronGolem, Snowman, Ocelot, ZombieVillager, Cow, Zombie, Squid, Villager, Spider, Pig, MushroomCow, Wolf, LavaSlime, Silverfish, Skeleton, Slime, Chicken, Enderman, CaveSpider, Boat, Minecart, Mule, Witch, PrimedTNT, Horse, Donkey, SkeletonHorse, ZombieHorse, Rabbit, Stray, Husk, WitherSkeleton, FallingSand, ElderGuardian, Endermite, Evoker, Guardian, Llama, PolarBear, Shulker, Vex, Vindicator, Wither, EndCrystal");
. TextFormat::BLUE . "Bat, Blaze, Boat, CaveSpider, Chicken, Cow, Creeper, Donkey, ElderGuardian, EndCrystal, Enderman, Endermite, Evoker, FallingSand, Ghast, Guardian, Horse, Human, Husk, IronGolem, LavaSlime, Llama, Minecart, Mule, MushroomCow, Ocelot, Pig, PigZombie, PolarBear, PrimedTNT, Rabbit, Sheep, Shulker, Silverfish, Skeleton, SkeletonHorse, Slime, Snowman, Spider, Squid, Stray, Vex, Villager, Vindicator, Witch, Wither, WitherSkeleton, Wolf, Zombie, ZombieHorse, ZombieVillager");
return true;
case "remove":
if (!$sender->hasPermission("slapper.remove")) {
Expand Down Expand Up @@ -558,7 +553,7 @@ public function onCommand(CommandSender $sender, Command $command, string $label
return true;
case "scale":
case "size":
if (isset($args[2])) {
if (isset($args[2]) && (float)$args[2] > 0) {
$scale = (float) $args[2];
$entity->setScale($scale);
$sender->sendMessage($this->prefix . "Updated scale.");
Expand All @@ -583,15 +578,14 @@ public function onCommand(CommandSender $sender, Command $command, string $label
} else {
$sender->sendMessage($this->prefix . "Entity does not exist.");
}
return true;
} else {
} else {
$sender->sendMessage($this->helpHeader);
foreach ($this->editArgs as $msgArg) {
$sender->sendMessage(TextFormat::GREEN . " - " . $msgArg . "\n");
}
return true;
}
case "help":
}
return true;
case "help":
case "?":
$sender->sendMessage($this->helpHeader);
foreach ($this->mainArgs as $msgArg) {
Expand Down Expand Up @@ -633,8 +627,7 @@ public function onCommand(CommandSender $sender, Command $command, string $label
return true;
}

/** @var class-string $slapperClass */
$slapperClass = __NAMESPACE__ . "\\entities\\Slapper$chosenType";
$slapperClass = __NAMESPACE__ . "\\entities\\Slapper$chosenType";
Utils::testValidInstance($slapperClass, SlapperInterface::class);

$location = $sender->getLocation();
Expand Down
2 changes: 0 additions & 2 deletions src/slapper/SlapperInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,6 @@

namespace slapper;

use slapper;

interface SlapperInterface
{

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,10 @@

declare(strict_types=1);

namespace slapper\entities\other;
namespace slapper\entities;

use pocketmine\data\bedrock\EntityLegacyIds;

use slapper\entities\SlapperEntity;

class SlapperBoat extends SlapperEntity {

const TYPE_ID = EntityLegacyIds::BOAT;
Expand Down
15 changes: 6 additions & 9 deletions src/slapper/entities/SlapperEntity.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,12 @@

use pocketmine\data\bedrock\LegacyEntityIdToStringIdMap;
use pocketmine\entity\Entity;
use pocketmine\entity\Human;
use pocketmine\entity\EntitySizeInfo;
use pocketmine\entity\Location;
use pocketmine\nbt\NBT;
use pocketmine\nbt\tag\CompoundTag;
use pocketmine\nbt\tag\ListTag;
use pocketmine\nbt\tag\StringTag;
use pocketmine\network\mcpe\protocol\types\entity\EntityIds;
use pocketmine\network\mcpe\protocol\types\entity\EntityMetadataCollection;
use pocketmine\network\mcpe\protocol\types\entity\EntityMetadataProperties;
use pocketmine\network\mcpe\protocol\types\entity\MetadataProperty;
Expand Down Expand Up @@ -60,22 +58,20 @@ public function initEntity(CompoundTag $nbt): void {
$this->setImmobile(true);
$this->setNameTagVisible(false);

if($nbt->getTag("Scale") !== null){
$this->setScale($nbt->getFloat("Scale"));
}
$this->setScale($nbt->getFloat('Scale', 1));
}

//For backwards-compatibility
public function saveNBT(): CompoundTag{
$nbt = parent::saveNBT();
$nbt = $nbt->merge($this->namedTagHack);
$nbt = $nbt->merge($this->namedTagHack);
$commandsTag = new ListTag([], NBT::TAG_String);
$nbt->setTag('Commands', $commandsTag);
foreach($this->commands as $command => $bool){
$commandsTag->push(new StringTag($command));
}
$nbt->setString('SlapperVersion', $this->version);
$nbt->setFloat("Scale", $this->scale);
$nbt->setFloat('Scale', $this->getScale());
$nbt->setString('SlapperVersion', $this->version);
$nbt->setTag('Commands', $commandsTag);
return $nbt;
}

Expand Down Expand Up @@ -144,6 +140,7 @@ public function __set(string $name, mixed $value): void{
throw new \TypeError('Typed property ' . get_class($this) . "::\$namedtag must be " . CompoundTag::class . ", " . gettype($value) . "used");
}
$this->namedTagHack = $value;
return;
}
throw new \ErrorException("Undefined property: " . get_class($this) . "::\$" . $name);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,19 +2,19 @@

declare(strict_types=1);

namespace slapper\entities\other;
namespace slapper\entities;

use pocketmine\block\Block;
use pocketmine\block\BlockFactory;
use pocketmine\block\BlockLegacyIds;
use pocketmine\data\bedrock\EntityLegacyIds;
use pocketmine\entity\object\FallingBlock;
use pocketmine\nbt\tag\CompoundTag;
use pocketmine\nbt\tag\IntTag;
use pocketmine\network\mcpe\convert\RuntimeBlockMapping;
use pocketmine\network\mcpe\protocol\types\entity\EntityMetadataCollection;
use pocketmine\network\mcpe\protocol\types\entity\EntityMetadataProperties;

use slapper\entities\SlapperEntity;

class SlapperFallingSand extends SlapperEntity {

const TYPE_ID = EntityLegacyIds::FALLING_BLOCK;
Expand All @@ -26,7 +26,8 @@ public function initEntity(CompoundTag $nbt): void{
parent::initEntity($nbt);

$blockFactory = BlockFactory::getInstance();
if(($blockIdTag = $nbt->getTag("BlockID")) === null){
if(($blockIdTag = $nbt->getTag("TileID")) === null){
$nbt->setTag("TileID", new IntTag(BlockLegacyIds::SAND));
$this->block = FallingBlock::parseBlockNBT($blockFactory, $nbt);
}else{
$this->block = $blockFactory->get($blockIdTag->getValue(), 0);
Expand Down
7 changes: 5 additions & 2 deletions src/slapper/entities/SlapperHuman.php
Original file line number Diff line number Diff line change
Expand Up @@ -41,18 +41,20 @@ public function initEntity(CompoundTag $nbt): void{
}
$this->version = $nbt->getString('SlapperVersion', '');
$this->setNameTagAlwaysVisible(true);
$this->setScale($nbt->getFloat('Scale', 1));
}

public function saveNBT(): CompoundTag {
$nbt = parent::saveNBT();
$nbt = $nbt->merge($this->namedTagHack);
$nbt->setString('MenuName', $this->menuName);
$commandsTag = new ListTag([], NBT::TAG_String);
$nbt->setTag('Commands', $commandsTag);
foreach($this->commands as $command => $bool){
$commandsTag->push(new StringTag($command));
}
$nbt->setString('SlapperVersion', $this->version);
$nbt->setFloat('Scale', $this->getScale());
$nbt->setString('SlapperVersion', $this->version);
$nbt->setTag('Commands', $commandsTag);
return $nbt;
}

Expand Down Expand Up @@ -104,6 +106,7 @@ public function __set(string $name, mixed $value) : void {
throw new \TypeError('Typed property ' . get_class($this) . "::\$namedtag must be " . CompoundTag::class . ', ' . gettype($value) . 'used');
}
$this->namedTagHack = $value;
return;
}
throw new \ErrorException('Undefined property: ' . get_class($this) . "::\$" . $name);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,10 @@

declare(strict_types=1);

namespace slapper\entities\other;
namespace slapper\entities;

use pocketmine\data\bedrock\EntityLegacyIds;

use slapper\entities\SlapperEntity;

class SlapperMinecart extends SlapperEntity {

const TYPE_ID = EntityLegacyIds::MINECART;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,10 @@

declare(strict_types=1);

namespace slapper\entities\other;
namespace slapper\entities;

use pocketmine\data\bedrock\EntityLegacyIds;

use slapper\entities\SlapperEntity;

class SlapperPrimedTNT extends SlapperEntity {

const TYPE_ID = EntityLegacyIds::TNT;
Expand Down
2 changes: 1 addition & 1 deletion src/slapper/events/SlapperCreationEvent.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ class SlapperCreationEvent extends EntityEvent {
* @param Player|null $creator
* @param int $cause
*/
public function __construct(Entity $entity, $type, Player $creator = null, $cause = self::CAUSE_COMMAND) {
public function __construct(Entity $entity, string $type, Player $creator = null, int $cause = self::CAUSE_COMMAND) {
$this->entity = $entity;
$this->type = $type;
$this->creator = $creator;
Expand Down

0 comments on commit 9c04800

Please sign in to comment.