From a0edd992e0a0b75336be8a242549713a7169d824 Mon Sep 17 00:00:00 2001 From: aericio <16523741+Aericio@users.noreply.github.com> Date: Sun, 16 Jul 2023 11:16:21 -1000 Subject: [PATCH 01/23] Update virions --- .github/workflows/main.yml | 8 ++++---- .poggit.yml | 7 +++---- phpstan.neon.dist | 2 +- plugin.yml | 4 ++-- src/DaPigGuy/PiggyCustomEnchants/PiggyCustomEnchants.php | 4 ++-- .../commands/CustomEnchantsCommand.php | 2 +- .../commands/subcommands/AboutSubCommand.php | 2 +- .../commands/subcommands/EnchantSubCommand.php | 2 +- .../commands/subcommands/InfoSubCommand.php | 4 ++-- .../commands/subcommands/ListSubCommand.php | 2 +- .../commands/subcommands/RemoveSubCommand.php | 2 +- src/DaPigGuy/PiggyCustomEnchants/utils/Utils.php | 2 +- 12 files changed, 20 insertions(+), 21 deletions(-) diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index 86338a75..b8e7e74c 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -13,10 +13,10 @@ jobs: run: mkdir vendor - name: Download Virion Dependencies run: | - wget -O vendor/libFormAPI.phar https://poggit.pmmp.io/r/207248/libFormAPI_dev-4.phar - wget -O vendor/Commando.phar https://poggit.pmmp.io/r/162923/Commando_dev-30.phar - wget -O vendor/libPiggyUpdateChecker.phar https://poggit.pmmp.io/r/163495/libPiggyUpdateChecker_dev-1.phar + wget -O vendor/FormsUI.phar https://poggit.pmmp.io/r/209836/FormsUI_dev-20.phar + wget -O vendor/Commando.phar https://poggit.pmmp.io/r/216831/Commando_dev-34.phar + wget -O vendor/libPiggyUpdateChecker.phar https://poggit.pmmp.io/r/211732/libPiggyUpdateChecker_dev-2.phar - name: Run PHPStan - uses: paroxity/pmmp-phpstan-action@4.21.0 + uses: paroxity/pmmp-phpstan-action@5.3.0 with: phpstan-config: phpstan.neon.dist \ No newline at end of file diff --git a/.poggit.yml b/.poggit.yml index a8f2deca..2db8d592 100644 --- a/.poggit.yml +++ b/.poggit.yml @@ -1,16 +1,15 @@ --- # Poggit-CI Manifest. Open the CI at https://poggit.pmmp.io/ci/DaPigGuy/PiggyCustomEnchants branches: - master - - pmmp-4.0.0 projects: PiggyCustomEnchants: path: "" icon: "resources/PCE_Icon.png" libs: - - src: jojoe77777/FormAPI/libFormAPI - version: ^2.1.1 + - src: Vecnavium/FormsUI/FormsUI + version: ^1.1.3 - src: Paroxity/Commando/Commando - version: ^3.0.0 + version: ^3.1.0 - src: DaPigGuy/libPiggyUpdateChecker/libPiggyUpdateChecker version: ^1.0.0 lint: false diff --git a/phpstan.neon.dist b/phpstan.neon.dist index d6ec58a0..fff547f4 100644 --- a/phpstan.neon.dist +++ b/phpstan.neon.dist @@ -5,7 +5,7 @@ parameters: bootstrapFiles: - phar:///pocketmine/PocketMine-MP.phar/vendor/autoload.php scanDirectories: - - phar:///source/vendor/libFormAPI.phar/src/ + - phar:///source/vendor/FormsUI.phar/src/ - phar:///source/vendor/Commando.phar/src/ - phar:///source/vendor/libPiggyUpdateChecker.phar/src/ excludePaths: diff --git a/plugin.yml b/plugin.yml index 876134d9..6119d8c2 100644 --- a/plugin.yml +++ b/plugin.yml @@ -1,7 +1,7 @@ name: PiggyCustomEnchants main: DaPigGuy\PiggyCustomEnchants\PiggyCustomEnchants -version: 3.0.12 -api: 4.21.0 +version: 3.1.0 +api: 5.3.0 load: POSTWORLD author: DaPigGuy website: "https://github.com/DaPigGuy/PiggyCustomEnchants/" diff --git a/src/DaPigGuy/PiggyCustomEnchants/PiggyCustomEnchants.php b/src/DaPigGuy/PiggyCustomEnchants/PiggyCustomEnchants.php index ab8c3674..0051c7a1 100644 --- a/src/DaPigGuy/PiggyCustomEnchants/PiggyCustomEnchants.php +++ b/src/DaPigGuy/PiggyCustomEnchants/PiggyCustomEnchants.php @@ -20,7 +20,6 @@ use DaPigGuy\PiggyCustomEnchants\entities\PigProjectile; use DaPigGuy\PiggyCustomEnchants\tasks\CheckDisabledEnchantsTask; use DaPigGuy\PiggyCustomEnchants\tasks\TickEnchantmentsTask; -use jojoe77777\FormAPI\Form; use pocketmine\block\BlockFactory; use pocketmine\color\Color; use pocketmine\data\bedrock\EffectIdMap; @@ -31,6 +30,7 @@ use pocketmine\plugin\PluginBase; use pocketmine\utils\Config; use pocketmine\world\World; +use Vecnavium\FormsUI\Form; class PiggyCustomEnchants extends PluginBase { @@ -44,7 +44,7 @@ public function onEnable(): void foreach ( [ "Commando" => BaseCommand::class, - "libformapi" => Form::class, + "FormsUI" => Form::class, "libPiggyUpdateChecker" => libPiggyUpdateChecker::class ] as $virion => $class ) { diff --git a/src/DaPigGuy/PiggyCustomEnchants/commands/CustomEnchantsCommand.php b/src/DaPigGuy/PiggyCustomEnchants/commands/CustomEnchantsCommand.php index b2751ecf..a9b48fcd 100644 --- a/src/DaPigGuy/PiggyCustomEnchants/commands/CustomEnchantsCommand.php +++ b/src/DaPigGuy/PiggyCustomEnchants/commands/CustomEnchantsCommand.php @@ -13,10 +13,10 @@ use DaPigGuy\PiggyCustomEnchants\commands\subcommands\NBTSubCommand; use DaPigGuy\PiggyCustomEnchants\commands\subcommands\RemoveSubCommand; use DaPigGuy\PiggyCustomEnchants\PiggyCustomEnchants; -use jojoe77777\FormAPI\SimpleForm; use pocketmine\command\CommandSender; use pocketmine\player\Player; use pocketmine\utils\TextFormat; +use Vecnavium\FormsUI\SimpleForm; class CustomEnchantsCommand extends BaseCommand { diff --git a/src/DaPigGuy/PiggyCustomEnchants/commands/subcommands/AboutSubCommand.php b/src/DaPigGuy/PiggyCustomEnchants/commands/subcommands/AboutSubCommand.php index d0fd581d..c7d79a21 100644 --- a/src/DaPigGuy/PiggyCustomEnchants/commands/subcommands/AboutSubCommand.php +++ b/src/DaPigGuy/PiggyCustomEnchants/commands/subcommands/AboutSubCommand.php @@ -6,10 +6,10 @@ use CortexPE\Commando\BaseSubCommand; use DaPigGuy\PiggyCustomEnchants\PiggyCustomEnchants; -use jojoe77777\FormAPI\SimpleForm; use pocketmine\command\CommandSender; use pocketmine\player\Player; use pocketmine\utils\TextFormat; +use Vecnavium\FormsUI\SimpleForm; class AboutSubCommand extends BaseSubCommand { diff --git a/src/DaPigGuy/PiggyCustomEnchants/commands/subcommands/EnchantSubCommand.php b/src/DaPigGuy/PiggyCustomEnchants/commands/subcommands/EnchantSubCommand.php index 4e728048..217aa7d1 100644 --- a/src/DaPigGuy/PiggyCustomEnchants/commands/subcommands/EnchantSubCommand.php +++ b/src/DaPigGuy/PiggyCustomEnchants/commands/subcommands/EnchantSubCommand.php @@ -11,13 +11,13 @@ use DaPigGuy\PiggyCustomEnchants\CustomEnchantManager; use DaPigGuy\PiggyCustomEnchants\PiggyCustomEnchants; use DaPigGuy\PiggyCustomEnchants\utils\Utils; -use jojoe77777\FormAPI\CustomForm; use pocketmine\command\CommandSender; use pocketmine\item\enchantment\EnchantmentInstance; use pocketmine\item\ItemIds; use pocketmine\player\Player; use pocketmine\utils\TextFormat; use Ramsey\Uuid\Uuid; +use Vecnavium\FormsUI\CustomForm; class EnchantSubCommand extends BaseSubCommand { diff --git a/src/DaPigGuy/PiggyCustomEnchants/commands/subcommands/InfoSubCommand.php b/src/DaPigGuy/PiggyCustomEnchants/commands/subcommands/InfoSubCommand.php index 652e66f1..36473744 100644 --- a/src/DaPigGuy/PiggyCustomEnchants/commands/subcommands/InfoSubCommand.php +++ b/src/DaPigGuy/PiggyCustomEnchants/commands/subcommands/InfoSubCommand.php @@ -11,11 +11,11 @@ use DaPigGuy\PiggyCustomEnchants\enchants\CustomEnchant; use DaPigGuy\PiggyCustomEnchants\PiggyCustomEnchants; use DaPigGuy\PiggyCustomEnchants\utils\Utils; -use jojoe77777\FormAPI\CustomForm; -use jojoe77777\FormAPI\SimpleForm; use pocketmine\command\CommandSender; use pocketmine\player\Player; use pocketmine\utils\TextFormat; +use Vecnavium\FormsUI\CustomForm; +use Vecnavium\FormsUI\SimpleForm; class InfoSubCommand extends BaseSubCommand { diff --git a/src/DaPigGuy/PiggyCustomEnchants/commands/subcommands/ListSubCommand.php b/src/DaPigGuy/PiggyCustomEnchants/commands/subcommands/ListSubCommand.php index d9af1d68..7cbf2886 100644 --- a/src/DaPigGuy/PiggyCustomEnchants/commands/subcommands/ListSubCommand.php +++ b/src/DaPigGuy/PiggyCustomEnchants/commands/subcommands/ListSubCommand.php @@ -9,10 +9,10 @@ use DaPigGuy\PiggyCustomEnchants\enchants\CustomEnchant; use DaPigGuy\PiggyCustomEnchants\PiggyCustomEnchants; use DaPigGuy\PiggyCustomEnchants\utils\Utils; -use jojoe77777\FormAPI\SimpleForm; use pocketmine\command\CommandSender; use pocketmine\player\Player; use pocketmine\utils\TextFormat; +use Vecnavium\FormsUI\SimpleForm; class ListSubCommand extends BaseSubCommand { diff --git a/src/DaPigGuy/PiggyCustomEnchants/commands/subcommands/RemoveSubCommand.php b/src/DaPigGuy/PiggyCustomEnchants/commands/subcommands/RemoveSubCommand.php index d88a2fbb..82ebca68 100644 --- a/src/DaPigGuy/PiggyCustomEnchants/commands/subcommands/RemoveSubCommand.php +++ b/src/DaPigGuy/PiggyCustomEnchants/commands/subcommands/RemoveSubCommand.php @@ -10,10 +10,10 @@ use DaPigGuy\PiggyCustomEnchants\CustomEnchantManager; use DaPigGuy\PiggyCustomEnchants\PiggyCustomEnchants; use DaPigGuy\PiggyCustomEnchants\utils\Utils; -use jojoe77777\FormAPI\CustomForm; use pocketmine\command\CommandSender; use pocketmine\player\Player; use pocketmine\utils\TextFormat; +use Vecnavium\FormsUI\CustomForm; class RemoveSubCommand extends BaseSubCommand { diff --git a/src/DaPigGuy/PiggyCustomEnchants/utils/Utils.php b/src/DaPigGuy/PiggyCustomEnchants/utils/Utils.php index ea4fd11d..61dfa183 100644 --- a/src/DaPigGuy/PiggyCustomEnchants/utils/Utils.php +++ b/src/DaPigGuy/PiggyCustomEnchants/utils/Utils.php @@ -12,7 +12,6 @@ use DaPigGuy\PiggyCustomEnchants\entities\PiggyWitherSkull; use DaPigGuy\PiggyCustomEnchants\entities\PigProjectile; use InvalidArgumentException; -use jojoe77777\FormAPI\SimpleForm; use pocketmine\entity\Location; use pocketmine\entity\projectile\Arrow; use pocketmine\entity\projectile\Projectile; @@ -37,6 +36,7 @@ use pocketmine\player\Player; use pocketmine\plugin\PluginDescription; use pocketmine\utils\TextFormat; +use Vecnavium\FormsUI\SimpleForm; class Utils { From 85b19e6424ac908f0f0b981ec25368610e50734c Mon Sep 17 00:00:00 2001 From: aericio <16523741+Aericio@users.noreply.github.com> Date: Sun, 16 Jul 2023 13:36:44 -1000 Subject: [PATCH 02/23] Add entries for EnchantedBook and PiggyObsidian --- .../PiggyCustomEnchants.php | 50 ++++++++++++- .../blocks/PiggyObsidian.php | 74 ++++++------------- .../blocks/PiggyObsidianBlock.php | 66 +++++++++++++++++ .../items/EnchantedBook.php | 44 +++++++++++ 4 files changed, 181 insertions(+), 53 deletions(-) create mode 100644 src/DaPigGuy/PiggyCustomEnchants/blocks/PiggyObsidianBlock.php create mode 100644 src/DaPigGuy/PiggyCustomEnchants/items/EnchantedBook.php diff --git a/src/DaPigGuy/PiggyCustomEnchants/PiggyCustomEnchants.php b/src/DaPigGuy/PiggyCustomEnchants/PiggyCustomEnchants.php index 0051c7a1..d3555f62 100644 --- a/src/DaPigGuy/PiggyCustomEnchants/PiggyCustomEnchants.php +++ b/src/DaPigGuy/PiggyCustomEnchants/PiggyCustomEnchants.php @@ -8,6 +8,7 @@ use CortexPE\Commando\PacketHooker; use DaPigGuy\libPiggyUpdateChecker\libPiggyUpdateChecker; use DaPigGuy\PiggyCustomEnchants\blocks\PiggyObsidian; +use DaPigGuy\PiggyCustomEnchants\blocks\PiggyObsidianBlock; use DaPigGuy\PiggyCustomEnchants\commands\CustomEnchantsCommand; use DaPigGuy\PiggyCustomEnchants\enchants\CustomEnchant; use DaPigGuy\PiggyCustomEnchants\enchants\ToggleableEnchantment; @@ -18,17 +19,26 @@ use DaPigGuy\PiggyCustomEnchants\entities\PiggyTNT; use DaPigGuy\PiggyCustomEnchants\entities\PiggyWitherSkull; use DaPigGuy\PiggyCustomEnchants\entities\PigProjectile; +use DaPigGuy\PiggyCustomEnchants\items\EnchantedBook; use DaPigGuy\PiggyCustomEnchants\tasks\CheckDisabledEnchantsTask; use DaPigGuy\PiggyCustomEnchants\tasks\TickEnchantmentsTask; -use pocketmine\block\BlockFactory; +use pocketmine\block\Block; +use pocketmine\block\RuntimeBlockStateRegistry; use pocketmine\color\Color; +use pocketmine\data\bedrock\block\BlockTypeNames; use pocketmine\data\bedrock\EffectIdMap; +use pocketmine\data\bedrock\item\ItemTypeNames; +use pocketmine\data\bedrock\item\SavedItemData; use pocketmine\entity\effect\Effect; use pocketmine\entity\EntityDataHelper; use pocketmine\entity\EntityFactory; +use pocketmine\item\Item; +use pocketmine\item\StringToItemParser; use pocketmine\nbt\tag\CompoundTag; use pocketmine\plugin\PluginBase; use pocketmine\utils\Config; +use pocketmine\world\format\io\GlobalBlockStateHandlers; +use pocketmine\world\format\io\GlobalItemDataHandlers; use pocketmine\world\World; use Vecnavium\FormsUI\Form; @@ -65,9 +75,9 @@ public function onEnable(): void CustomEnchantManager::init($this); - BlockFactory::getInstance()->register(new PiggyObsidian(), true); + self::registerItemsAndBlocks(); - //TODO: Use real effect + // TODO: Use real effect self::$SLOW_FALL = new Effect("%potion.slowFalling", new Color(206, 255, 255)); EffectIdMap::getInstance()->register(27, self::$SLOW_FALL); @@ -149,4 +159,38 @@ public function areFormsEnabled(): bool { return $this->getConfig()->getNested("forms.enabled", true); } + + private static function registerItemsAndBlocks(): void + { + self::registerItem(ItemTypeNames::ENCHANTED_BOOK, EnchantedBook::ENCHANTED_BOOK(), ["enchanted_book"]); + self::registerBlock(BlockTypeNames::OBSIDIAN, PiggyObsidian::PIGGY_OBSIDIAN(), ["obsidian"]); + } + + /** + * @param string[] $stringToItemParserNames + */ + private static function registerBlock(string $id, Block $block, array $stringToItemParserNames): void + { + RuntimeBlockStateRegistry::getInstance()->register($block); + + GlobalBlockStateHandlers::getDeserializer()->mapSimple($id, fn() => clone $block); + GlobalBlockStateHandlers::getSerializer()->mapSimple($block, $id); + + foreach ($stringToItemParserNames as $name) { + StringToItemParser::getInstance()->registerBlock($name, fn() => clone $block); + } + } + + /** + * @param string[] $stringToItemParserNames + */ + private static function registerItem(string $id, Item $item, array $stringToItemParserNames): void + { + GlobalItemDataHandlers::getDeserializer()->map($id, fn() => clone $item); + GlobalItemDataHandlers::getSerializer()->map($item, fn() => new SavedItemData($id)); + + foreach ($stringToItemParserNames as $name) { + StringToItemParser::getInstance()->register($name, fn() => clone $item); + } + } } \ No newline at end of file diff --git a/src/DaPigGuy/PiggyCustomEnchants/blocks/PiggyObsidian.php b/src/DaPigGuy/PiggyCustomEnchants/blocks/PiggyObsidian.php index 2256fd50..c0be10ba 100644 --- a/src/DaPigGuy/PiggyCustomEnchants/blocks/PiggyObsidian.php +++ b/src/DaPigGuy/PiggyCustomEnchants/blocks/PiggyObsidian.php @@ -5,66 +5,40 @@ use pocketmine\block\Block; use pocketmine\block\BlockBreakInfo; use pocketmine\block\BlockIdentifier; -use pocketmine\block\BlockLegacyIds; -use pocketmine\block\VanillaBlocks; -use pocketmine\item\Item; -use pocketmine\player\Player; - -class PiggyObsidian extends Block +use pocketmine\block\BlockTypeIds; +use pocketmine\block\BlockTypeInfo; +use pocketmine\utils\CloningRegistryTrait; + +/** + * @method static PiggyObsidianBlock PIGGY_OBSIDIAN() + */ +final class PiggyObsidian { - private int $age = 0; - - public function __construct() - { - parent::__construct(new BlockIdentifier(BlockLegacyIds::OBSIDIAN, 15), "Magmawalker Obsidian", BlockBreakInfo::instant()); - } - - public function onScheduledUpdate(): void - { - if (mt_rand(0, 3) === 0 || $this->countNeighbors() < 4) { - $this->slightlyMelt(true); - } else { - $this->getPosition()->getWorld()->scheduleDelayedBlockUpdate($this->getPosition(), mt_rand(20, 40)); - } - } + use CloningRegistryTrait; - public function onBreak(Item $item, Player $player = null): bool + private function __construct() { - $this->getPosition()->getWorld()->setBlock($this->getPosition(), VanillaBlocks::LAVA()); - return true; + //NOOP } - public function getDrops(Item $item): array + protected static function register(string $name, Block $block): void { - return []; + self::_registryRegister($name, $block); } - public function countNeighbors(): int + /** + * @return Block[] + * @phpstan-return array + */ + public static function getAll(): array { - $i = 0; - foreach ($this->getAllSides() as $block) { - if ($block instanceof PiggyObsidian) { - $i++; - if ($i >= 4) return $i; - } - } - return $i; + /** @var Block[] $result */ + $result = self::_registryGetAll(); + return $result; } - public function slightlyMelt(bool $meltNeighbors): void + protected static function setup(): void { - if ($this->age < 3) { - $this->age++; - $this->getPosition()->getWorld()->scheduleDelayedBlockUpdate($this->getPosition(), mt_rand(20, 40)); - } else { - $this->getPosition()->getWorld()->useBreakOn($this->getPosition()); - if ($meltNeighbors) { - foreach ($this->getAllSides() as $block) { - if ($block instanceof PiggyObsidian) { - $block->slightlyMelt(false); - } - } - } - } + self::register("obsidian", new PiggyObsidianBlock(new BlockIdentifier(BlockTypeIds::newId(), 15), "Magmawalker Obsidian", new BlockTypeInfo(BlockBreakInfo::instant()))); } -} \ No newline at end of file +} diff --git a/src/DaPigGuy/PiggyCustomEnchants/blocks/PiggyObsidianBlock.php b/src/DaPigGuy/PiggyCustomEnchants/blocks/PiggyObsidianBlock.php new file mode 100644 index 00000000..911d1af1 --- /dev/null +++ b/src/DaPigGuy/PiggyCustomEnchants/blocks/PiggyObsidianBlock.php @@ -0,0 +1,66 @@ +countNeighbors() < 4) { + $this->slightlyMelt(true); + } else { + $this->getPosition()->getWorld()->scheduleDelayedBlockUpdate($this->getPosition(), mt_rand(20, 40)); + } + } + + public function onBreak(Item $item, ?Player $player = null, array &$returnedItems = []): bool + { + $world = $this->position->getWorld(); + if (($t = $world->getTile($this->position)) !== null) { + $t->onBlockDestroyed(); + } + $world->setBlock($this->position, VanillaBlocks::LAVA()); + return true; + } + + public function getDrops(Item $item): array + { + return []; + } + + public function countNeighbors(): int + { + $i = 0; + foreach ($this->getAllSides() as $block) { + if ($block instanceof PiggyObsidian) { + $i++; + if ($i >= 4) return $i; + } + } + return $i; + } + + public function slightlyMelt(bool $meltNeighbors): void + { + if ($this->age < 3) { + $this->age++; + $this->getPosition()->getWorld()->scheduleDelayedBlockUpdate($this->getPosition(), mt_rand(20, 40)); + } else { + $this->getPosition()->getWorld()->useBreakOn($this->getPosition()); + if ($meltNeighbors) { + foreach ($this->getAllSides() as $block) { + if ($block instanceof PiggyObsidianBlock) { + $block->slightlyMelt(false); + } + } + } + } + } +} \ No newline at end of file diff --git a/src/DaPigGuy/PiggyCustomEnchants/items/EnchantedBook.php b/src/DaPigGuy/PiggyCustomEnchants/items/EnchantedBook.php new file mode 100644 index 00000000..cb962a98 --- /dev/null +++ b/src/DaPigGuy/PiggyCustomEnchants/items/EnchantedBook.php @@ -0,0 +1,44 @@ + + */ + public static function getAll(): array + { + /** @var Item[] $result */ + $result = self::_registryGetAll(); + return $result; + } + + protected static function setup(): void + { + self::register("enchanted_book", new Item(new ItemIdentifier(ItemTypeIds::newId()), "Enchanted Book")); + } +} \ No newline at end of file From cf1d37d1b0e50914151da40a1dc38e3f74e64f42 Mon Sep 17 00:00:00 2001 From: aericio <16523741+Aericio@users.noreply.github.com> Date: Sun, 16 Jul 2023 14:02:04 -1000 Subject: [PATCH 03/23] Migrate entities --- .../entities/PigProjectile.php | 45 +++++++++++-------- .../entities/PiggyFireball.php | 7 +-- .../entities/PiggyLightning.php | 10 +++++ .../entities/PiggyProjectile.php | 10 +++++ .../entities/PiggyWitherSkull.php | 7 +-- 5 files changed, 49 insertions(+), 30 deletions(-) diff --git a/src/DaPigGuy/PiggyCustomEnchants/entities/PigProjectile.php b/src/DaPigGuy/PiggyCustomEnchants/entities/PigProjectile.php index f54e1be6..e6cbc533 100644 --- a/src/DaPigGuy/PiggyCustomEnchants/entities/PigProjectile.php +++ b/src/DaPigGuy/PiggyCustomEnchants/entities/PigProjectile.php @@ -4,14 +4,15 @@ namespace DaPigGuy\PiggyCustomEnchants\entities; +use pocketmine\block\BlockTypeIds; use pocketmine\entity\Attribute; use pocketmine\entity\Entity; use pocketmine\entity\EntitySizeInfo; use pocketmine\entity\Location; use pocketmine\entity\object\ItemEntity; use pocketmine\item\Item; -use pocketmine\item\ItemFactory; -use pocketmine\item\ItemIds; +use pocketmine\item\ItemTypeIds; +use pocketmine\item\VanillaItems; use pocketmine\math\Vector3; use pocketmine\nbt\tag\CompoundTag; use pocketmine\network\mcpe\protocol\AddActorPacket; @@ -27,22 +28,17 @@ class PigProjectile extends PiggyProjectile * @const array */ const PORK_LEVELS = [ - //level => [damage, dinnerbone, zombie, drop id, drop name] - 1 => [1, false, false, ItemIds::AIR, ""], - 2 => [2, false, false, ItemIds::RAW_PORKCHOP, "Mysterious Raw Pork"], - 3 => [2, false, false, ItemIds::COOKED_PORKCHOP, "Mysterious Cooked Pork"], - 4 => [3, true, false, ItemIds::COOKED_PORKCHOP, "Mysterious Cooked Pork"], - 5 => [5, false, true, ItemIds::ROTTEN_FLESH, "Mysterious Rotten Pork"], - 6 => [6, true, true, ItemIds::ROTTEN_FLESH, "Mysterious Rotten Pork"] + // level => [damage, dinnerbone, zombie, drop id, drop name] + 1 => [1, false, false, BlockTypeIds::AIR, ""], + 2 => [2, false, false, ItemTypeIds::RAW_PORKCHOP, "Mysterious Raw Pork"], + 3 => [2, false, false, ItemTypeIds::COOKED_PORKCHOP, "Mysterious Cooked Pork"], + 4 => [3, true, false, ItemTypeIds::COOKED_PORKCHOP, "Mysterious Cooked Pork"], + 5 => [5, false, true, ItemTypeIds::ROTTEN_FLESH, "Mysterious Rotten Pork"], + 6 => [6, true, true, ItemTypeIds::ROTTEN_FLESH, "Mysterious Rotten Pork"] ]; /** @var float */ - protected $drag = 0.01; - /** @var float */ - protected $gravity = 0.05; - - /** @var float */ - protected $damage = 1.5; + protected float $damage = 1.5; private int $porkLevel; private bool $zombie; @@ -96,9 +92,22 @@ public function isZombie(): bool public function getDrops(): array { $values = self::PORK_LEVELS[$this->getPorkLevel()]; - return [ - ItemFactory::getInstance()->get($values[3], 0, 1)->setCustomName(TextFormat::RESET . TextFormat::WHITE . $values[4]) - ]; + + switch ($values[3]) { + case ItemTypeIds::RAW_PORKCHOP: + $drop = VanillaItems::RAW_PORKCHOP(); + break; + case ItemTypeIds::COOKED_PORKCHOP: + $drop = VanillaItems::COOKED_PORKCHOP(); + break; + case ItemTypeIds::ROTTEN_FLESH: + $drop = VanillaItems::ROTTEN_FLESH(); + break; + default: + return []; + } + + return [$drop->setCount(1)->setCustomName(TextFormat::RESET . TextFormat::WHITE . $values[4])]; } protected function sendSpawnPacket(Player $player): void diff --git a/src/DaPigGuy/PiggyCustomEnchants/entities/PiggyFireball.php b/src/DaPigGuy/PiggyCustomEnchants/entities/PiggyFireball.php index e9fbdfe4..7318c9ca 100644 --- a/src/DaPigGuy/PiggyCustomEnchants/entities/PiggyFireball.php +++ b/src/DaPigGuy/PiggyCustomEnchants/entities/PiggyFireball.php @@ -17,12 +17,7 @@ class PiggyFireball extends PiggyProjectile { /** @var float */ - protected $drag = 0.01; - /** @var float */ - protected $gravity = 0.05; - - /** @var float */ - protected $damage = 5; + protected float $damage = 5; public function onHitEntity(Entity $entityHit, RayTraceResult $hitResult): void { diff --git a/src/DaPigGuy/PiggyCustomEnchants/entities/PiggyLightning.php b/src/DaPigGuy/PiggyCustomEnchants/entities/PiggyLightning.php index 470e2091..198c8883 100644 --- a/src/DaPigGuy/PiggyCustomEnchants/entities/PiggyLightning.php +++ b/src/DaPigGuy/PiggyCustomEnchants/entities/PiggyLightning.php @@ -54,4 +54,14 @@ protected function getInitialSizeInfo(): EntitySizeInfo { return new EntitySizeInfo(1.8, 0.3); } + + protected function getInitialDragMultiplier(): float + { + return 0; + } + + protected function getInitialGravity(): float + { + return 0; + } } \ No newline at end of file diff --git a/src/DaPigGuy/PiggyCustomEnchants/entities/PiggyProjectile.php b/src/DaPigGuy/PiggyCustomEnchants/entities/PiggyProjectile.php index 4694a95e..0c03c579 100644 --- a/src/DaPigGuy/PiggyCustomEnchants/entities/PiggyProjectile.php +++ b/src/DaPigGuy/PiggyCustomEnchants/entities/PiggyProjectile.php @@ -17,4 +17,14 @@ public function canSaveWithChunk(): bool { return false; } + + protected function getInitialDragMultiplier(): float + { + return 0.01; + } + + protected function getInitialGravity(): float + { + return 0.05; + } } \ No newline at end of file diff --git a/src/DaPigGuy/PiggyCustomEnchants/entities/PiggyWitherSkull.php b/src/DaPigGuy/PiggyCustomEnchants/entities/PiggyWitherSkull.php index a2a56a2f..fa03503b 100644 --- a/src/DaPigGuy/PiggyCustomEnchants/entities/PiggyWitherSkull.php +++ b/src/DaPigGuy/PiggyCustomEnchants/entities/PiggyWitherSkull.php @@ -17,12 +17,7 @@ class PiggyWitherSkull extends PiggyProjectile { /** @var float */ - protected $drag = 0.01; - /** @var float */ - protected $gravity = 0.05; - - /** @var float */ - protected $damage = 0; + protected float $damage = 0; public function onHitEntity(Entity $entityHit, RayTraceResult $hitResult): void { From f097de1ad4b02bfdaaf64a3c985b4fc81027fc78 Mon Sep 17 00:00:00 2001 From: aericio <16523741+Aericio@users.noreply.github.com> Date: Sun, 16 Jul 2023 14:08:45 -1000 Subject: [PATCH 04/23] Add missing type annotations --- .../PiggyCustomEnchants/PiggyCustomEnchants.php | 2 +- .../enchants/armor/AntiKnockbackEnchant.php | 2 +- .../enchants/armor/boots/JetpackEnchant.php | 11 ++++------- .../enchants/armor/helmet/ImplantsEnchant.php | 4 ++-- .../enchants/traits/ReactiveTrait.php | 2 +- .../enchants/weapons/DisarmingEnchant.php | 2 +- .../enchants/weapons/DisarmorEnchant.php | 2 +- .../enchants/weapons/HallucinationEnchant.php | 3 +-- src/DaPigGuy/PiggyCustomEnchants/utils/AllyChecks.php | 2 +- 9 files changed, 13 insertions(+), 17 deletions(-) diff --git a/src/DaPigGuy/PiggyCustomEnchants/PiggyCustomEnchants.php b/src/DaPigGuy/PiggyCustomEnchants/PiggyCustomEnchants.php index d3555f62..99f6c030 100644 --- a/src/DaPigGuy/PiggyCustomEnchants/PiggyCustomEnchants.php +++ b/src/DaPigGuy/PiggyCustomEnchants/PiggyCustomEnchants.php @@ -46,7 +46,7 @@ class PiggyCustomEnchants extends PluginBase { public static Effect $SLOW_FALL; - /** @var mixed[] */ + /** @var array */ private array $enchantmentData; public function onEnable(): void diff --git a/src/DaPigGuy/PiggyCustomEnchants/enchants/armor/AntiKnockbackEnchant.php b/src/DaPigGuy/PiggyCustomEnchants/enchants/armor/AntiKnockbackEnchant.php index f90a370e..9df90441 100644 --- a/src/DaPigGuy/PiggyCustomEnchants/enchants/armor/AntiKnockbackEnchant.php +++ b/src/DaPigGuy/PiggyCustomEnchants/enchants/armor/AntiKnockbackEnchant.php @@ -23,7 +23,7 @@ class AntiKnockbackEnchant extends ReactiveEnchantment public function react(Player $player, Item $item, Inventory $inventory, int $slot, Event $event, int $level, int $stack): void { if ($event instanceof EntityDamageByEntityEvent) { - $stack = $stack > 4 ? 4 : $stack; + $stack = min($stack, 4); $event->setKnockBack($event->getKnockBack() * (4 - $stack) / (5 - $stack)); } } diff --git a/src/DaPigGuy/PiggyCustomEnchants/enchants/armor/boots/JetpackEnchant.php b/src/DaPigGuy/PiggyCustomEnchants/enchants/armor/boots/JetpackEnchant.php index fbca2bc7..5e98bb8f 100644 --- a/src/DaPigGuy/PiggyCustomEnchants/enchants/armor/boots/JetpackEnchant.php +++ b/src/DaPigGuy/PiggyCustomEnchants/enchants/armor/boots/JetpackEnchant.php @@ -32,12 +32,10 @@ class JetpackEnchant extends ReactiveEnchantment public int $itemType = CustomEnchant::ITEM_TYPE_BOOTS; /** @var Player[] */ - public $activeJetpacks = []; + public array $activeJetpacks = []; - /** @var array */ - public $powerRemaining; - /** @var array */ - public $lastActivated; + public array $powerRemaining; + public array $lastActivated; public function getReagent(): array { @@ -102,7 +100,6 @@ public function powerActiveJetpack(Player $player, bool $power = true): void if ($power) { if (!isset($this->powerRemaining[$player->getName()])) { $this->powerRemaining[$player->getName()] = $this->extraData["power"]; - $this->activeJetpacks[$player->getName()] = $player; } else { $this->powerRemaining[$player->getName()] += (time() - $this->lastActivated[$player->getName()]) * $this->extraData["rechargeAmount"]; if ($this->powerRemaining[$player->getName()] > $this->extraData["power"]) $this->powerRemaining[$player->getName()] = $this->extraData["power"]; @@ -110,8 +107,8 @@ public function powerActiveJetpack(Player $player, bool $power = true): void $player->sendTip(TextFormat::RED . "Jetpack needs to charge up to " . $this->extraData["enableAmount"] . " before it can be re-enabled. (" . round(abs($this->powerRemaining[$player->getName()]), 2) . " / " . $this->extraData["power"] . ")"); return; } - $this->activeJetpacks[$player->getName()] = $player; } + $this->activeJetpacks[$player->getName()] = $player; } else { unset($this->activeJetpacks[$player->getName()]); $this->lastActivated[$player->getName()] = time(); diff --git a/src/DaPigGuy/PiggyCustomEnchants/enchants/armor/helmet/ImplantsEnchant.php b/src/DaPigGuy/PiggyCustomEnchants/enchants/armor/helmet/ImplantsEnchant.php index 060b6856..145c99b3 100644 --- a/src/DaPigGuy/PiggyCustomEnchants/enchants/armor/helmet/ImplantsEnchant.php +++ b/src/DaPigGuy/PiggyCustomEnchants/enchants/armor/helmet/ImplantsEnchant.php @@ -25,7 +25,7 @@ class ImplantsEnchant extends ReactiveEnchantment public int $itemType = CustomEnchant::ITEM_TYPE_HELMET; /** @var ClosureTask[] */ - public static $tasks; + public static array $tasks; public function getReagent(): array { @@ -52,7 +52,7 @@ public function react(Player $player, Item $item, Inventory $inventory, int $slo unset(self::$tasks[$player->getName()]); return; } - $player->setAirSupplyTicks($player->getAirSupplyTicks() + ($enchantment->getLevel() * $this->extraData["airTicksReplenishAmountMultiplier"]) > $player->getMaxAirSupplyTicks() ? $player->getMaxAirSupplyTicks() : $player->getAirSupplyTicks() + ($enchantment->getLevel() * $this->extraData["airTicksReplenishAmountMultiplier"])); + $player->setAirSupplyTicks(min($player->getAirSupplyTicks() + ($enchantment->getLevel() * $this->extraData["airTicksReplenishAmountMultiplier"]), $player->getMaxAirSupplyTicks())); } else { self::$tasks[$player->getName()]->getHandler()->cancel(); unset(self::$tasks[$player->getName()]); diff --git a/src/DaPigGuy/PiggyCustomEnchants/enchants/traits/ReactiveTrait.php b/src/DaPigGuy/PiggyCustomEnchants/enchants/traits/ReactiveTrait.php index 537f2613..dab8a2fc 100644 --- a/src/DaPigGuy/PiggyCustomEnchants/enchants/traits/ReactiveTrait.php +++ b/src/DaPigGuy/PiggyCustomEnchants/enchants/traits/ReactiveTrait.php @@ -23,7 +23,7 @@ trait ReactiveTrait protected PiggyCustomEnchants $plugin; /** @var float[] */ - public $chanceMultiplier; + public array $chanceMultiplier; public function canReact(): bool { diff --git a/src/DaPigGuy/PiggyCustomEnchants/enchants/weapons/DisarmingEnchant.php b/src/DaPigGuy/PiggyCustomEnchants/enchants/weapons/DisarmingEnchant.php index 2f97f2ca..0304a569 100644 --- a/src/DaPigGuy/PiggyCustomEnchants/enchants/weapons/DisarmingEnchant.php +++ b/src/DaPigGuy/PiggyCustomEnchants/enchants/weapons/DisarmingEnchant.php @@ -22,7 +22,7 @@ public function react(Player $player, Item $item, Inventory $inventory, int $slo if ($event instanceof EntityDamageByEntityEvent) { $entity = $event->getEntity(); if ($entity instanceof Player) { - if (count($contents = $entity->getInventory()->getContents(false)) > 0) { + if (count($contents = $entity->getInventory()->getContents()) > 0) { $item = $contents[array_rand($contents)]; $entity->getInventory()->removeItem($item); $entity->dropItem($item); diff --git a/src/DaPigGuy/PiggyCustomEnchants/enchants/weapons/DisarmorEnchant.php b/src/DaPigGuy/PiggyCustomEnchants/enchants/weapons/DisarmorEnchant.php index a8b9f604..4d0c6859 100644 --- a/src/DaPigGuy/PiggyCustomEnchants/enchants/weapons/DisarmorEnchant.php +++ b/src/DaPigGuy/PiggyCustomEnchants/enchants/weapons/DisarmorEnchant.php @@ -21,7 +21,7 @@ public function react(Player $player, Item $item, Inventory $inventory, int $slo if ($event instanceof EntityDamageByEntityEvent) { $entity = $event->getEntity(); if ($entity instanceof Player) { - if (count($armorContents = $entity->getArmorInventory()->getContents(false)) > 0) { + if (count($armorContents = $entity->getArmorInventory()->getContents()) > 0) { $item = $armorContents[array_rand($armorContents)]; $entity->getArmorInventory()->removeItem($item); $entity->dropItem($item); diff --git a/src/DaPigGuy/PiggyCustomEnchants/enchants/weapons/HallucinationEnchant.php b/src/DaPigGuy/PiggyCustomEnchants/enchants/weapons/HallucinationEnchant.php index 7e19493e..827911d2 100644 --- a/src/DaPigGuy/PiggyCustomEnchants/enchants/weapons/HallucinationEnchant.php +++ b/src/DaPigGuy/PiggyCustomEnchants/enchants/weapons/HallucinationEnchant.php @@ -32,8 +32,7 @@ class HallucinationEnchant extends ReactiveEnchantment public string $name = "Hallucination"; public int $rarity = Rarity::MYTHIC; - /** @var NetworkNbtSerializer */ - public $nbtWriter = null; + public ?NetworkNbtSerializer $nbtWriter = null; /** @var bool[] */ public static array $hallucinating; diff --git a/src/DaPigGuy/PiggyCustomEnchants/utils/AllyChecks.php b/src/DaPigGuy/PiggyCustomEnchants/utils/AllyChecks.php index 2d02aebe..1e8d8bad 100644 --- a/src/DaPigGuy/PiggyCustomEnchants/utils/AllyChecks.php +++ b/src/DaPigGuy/PiggyCustomEnchants/utils/AllyChecks.php @@ -11,7 +11,7 @@ class AllyChecks { - /** @var mixed[][] */ + /** @var array[] */ private static array $checks = []; /** From 0bc0ebd62e8c0fc0907d5daa2b5415b5c967df11 Mon Sep 17 00:00:00 2001 From: aericio <16523741+Aericio@users.noreply.github.com> Date: Sun, 16 Jul 2023 15:03:39 -1000 Subject: [PATCH 05/23] Update method calls --- .../PiggyCustomEnchants/EventListener.php | 20 +++++++----- .../PiggyCustomEnchants.php | 1 - .../subcommands/EnchantSubCommand.php | 7 +++-- .../enchants/armor/HeavyEnchant.php | 4 +-- .../enchants/armor/ReviveEnchant.php | 1 - .../enchants/armor/ShrinkEnchant.php | 8 ++--- .../enchants/armor/boots/JetpackEnchant.php | 1 - .../armor/boots/MagmaWalkerEnchant.php | 10 +++--- .../armor/chestplate/ParachuteEnchant.php | 6 ++-- .../enchants/armor/helmet/ImplantsEnchant.php | 1 - .../miscellaneous/AutoRepairEnchant.php | 4 +-- .../enchants/tools/axes/LumberjackEnchant.php | 14 ++++----- .../enchants/tools/hoe/FertilizerEnchant.php | 6 ++-- .../enchants/tools/pickaxe/JackpotEnchant.php | 31 +++++++++++++------ .../enchants/weapons/HallucinationEnchant.php | 16 +++++----- .../weapons/bows/BountyHunterEnchant.php | 18 +++++------ .../entities/PigProjectile.php | 19 ++++-------- .../tasks/TickEnchantmentsTask.php | 8 ++--- .../PiggyCustomEnchants/utils/Utils.php | 8 +++-- 19 files changed, 96 insertions(+), 87 deletions(-) diff --git a/src/DaPigGuy/PiggyCustomEnchants/EventListener.php b/src/DaPigGuy/PiggyCustomEnchants/EventListener.php index 914c1468..01a8dafe 100644 --- a/src/DaPigGuy/PiggyCustomEnchants/EventListener.php +++ b/src/DaPigGuy/PiggyCustomEnchants/EventListener.php @@ -11,9 +11,10 @@ use DaPigGuy\PiggyCustomEnchants\enchants\tools\DrillerEnchant; use DaPigGuy\PiggyCustomEnchants\entities\BombardmentTNT; use DaPigGuy\PiggyCustomEnchants\entities\PiggyTNT; +use DaPigGuy\PiggyCustomEnchants\items\EnchantedBook; use DaPigGuy\PiggyCustomEnchants\utils\ProjectileTracker; use DaPigGuy\PiggyCustomEnchants\utils\Utils; -use pocketmine\block\BlockLegacyIds; +use pocketmine\block\BlockTypeIds; use pocketmine\event\block\BlockBreakEvent; use pocketmine\event\entity\EntityBlockChangeEvent; use pocketmine\event\entity\EntityDamageByEntityEvent; @@ -40,7 +41,7 @@ use pocketmine\inventory\transaction\action\SlotChangeAction; use pocketmine\item\enchantment\EnchantmentInstance; use pocketmine\item\Item; -use pocketmine\item\ItemIds; +use pocketmine\item\ItemTypeIds; use pocketmine\item\VanillaItems; use pocketmine\network\mcpe\protocol\InventoryContentPacket; use pocketmine\network\mcpe\protocol\InventorySlotPacket; @@ -208,8 +209,8 @@ public function onJoin(PlayerJoinEvent $event): void $holder = $inventory->getHolder(); if ($holder instanceof Player) { if (!$oldItem->equals(($newItem = $inventory->getItem($slot)), !$inventory instanceof ArmorInventory)) { - if ($newItem->getId() === ItemIds::AIR || $inventory instanceof ArmorInventory) foreach ($oldItem->getEnchantments() as $oldEnchantment) ToggleableEnchantment::attemptToggle($holder, $oldItem, $oldEnchantment, $inventory, $slot, false); - if ($oldItem->getId() === ItemIds::AIR || $inventory instanceof ArmorInventory) foreach ($newItem->getEnchantments() as $newEnchantment) ToggleableEnchantment::attemptToggle($holder, $newItem, $newEnchantment, $inventory, $slot); + if ($newItem->getStateId() === BlockTypeIds::AIR || $inventory instanceof ArmorInventory) foreach ($oldItem->getEnchantments() as $oldEnchantment) ToggleableEnchantment::attemptToggle($holder, $oldItem, $oldEnchantment, $inventory, $slot, false); + if ($oldItem->getStateId() === BlockTypeIds::AIR || $inventory instanceof ArmorInventory) foreach ($newItem->getEnchantments() as $newEnchantment) ToggleableEnchantment::attemptToggle($holder, $newItem, $newEnchantment, $inventory, $slot); } } } @@ -235,7 +236,7 @@ public function onMove(PlayerMoveEvent $event): void { $player = $event->getPlayer(); if (!Utils::shouldTakeFallDamage($player)) { - if ($player->getWorld()->getBlock($player->getPosition()->floor()->subtract(0, 1, 0))->getId() !== BlockLegacyIds::AIR && Utils::getNoFallDamageDuration($player) <= 0) { + if ($player->getWorld()->getBlock($player->getPosition()->floor()->subtract(0, 1, 0))->getTypeId() !== BlockTypeIds::AIR && Utils::getNoFallDamageDuration($player) <= 0) { Utils::setShouldTakeFallDamage($player, true); } else { Utils::increaseNoFallDamageDuration($player); @@ -302,7 +303,10 @@ public function onTransaction(InventoryTransactionEvent $event): void $actions = array_values($transaction->getActions()); if (count($actions) === 2) { foreach ($actions as $i => $action) { - if ($action instanceof SlotChangeAction && ($otherAction = $actions[($i + 1) % 2]) instanceof SlotChangeAction && ($itemClickedWith = $action->getTargetItem())->getId() === ItemIds::ENCHANTED_BOOK && ($itemClicked = $action->getSourceItem())->getId() !== ItemIds::AIR && ($itemClicked->getId() !== ItemIds::ENCHANTED_BOOK || count($itemClicked->getEnchantments()) >= count($itemClickedWith->getEnchantments()))) { + if ($action instanceof SlotChangeAction && ($otherAction = $actions[($i + 1) % 2]) instanceof SlotChangeAction && + ($itemClickedWith = $action->getTargetItem())->getTypeId() === EnchantedBook::ENCHANTED_BOOK()->getTypeId() && + ($itemClicked = $action->getSourceItem())->getTypeId() !== BlockTypeIds::AIR && + ($itemClicked->getTypeId() !== EnchantedBook::ENCHANTED_BOOK()->getTypeId() || count($itemClicked->getEnchantments()) >= count($itemClickedWith->getEnchantments()))) { if (count($itemClickedWith->getEnchantments()) < 1) return; $enchantmentSuccessful = false; foreach ($itemClickedWith->getEnchantments() as $enchantment) { @@ -324,8 +328,8 @@ public function onTransaction(InventoryTransactionEvent $event): void ) || $itemClicked->getCount() !== 1 || $newLevel > $enchantmentType->getMaxLevel() || - ($itemClicked->getId() === ItemIds::ENCHANTED_BOOK && count($itemClicked->getEnchantments()) === 0) || - $itemClicked->getId() === ItemIds::BOOK + ($itemClicked->getTypeId() === EnchantedBook::ENCHANTED_BOOK()->getTypeId() && count($itemClicked->getEnchantments()) === 0) || + $itemClicked->getTypeId() === ItemTypeIds::BOOK ) continue; $itemClicked->addEnchantment(new EnchantmentInstance($enchantmentType, $newLevel)); if ($willChange) $enchantmentSuccessful = true; diff --git a/src/DaPigGuy/PiggyCustomEnchants/PiggyCustomEnchants.php b/src/DaPigGuy/PiggyCustomEnchants/PiggyCustomEnchants.php index 99f6c030..a81d33ef 100644 --- a/src/DaPigGuy/PiggyCustomEnchants/PiggyCustomEnchants.php +++ b/src/DaPigGuy/PiggyCustomEnchants/PiggyCustomEnchants.php @@ -8,7 +8,6 @@ use CortexPE\Commando\PacketHooker; use DaPigGuy\libPiggyUpdateChecker\libPiggyUpdateChecker; use DaPigGuy\PiggyCustomEnchants\blocks\PiggyObsidian; -use DaPigGuy\PiggyCustomEnchants\blocks\PiggyObsidianBlock; use DaPigGuy\PiggyCustomEnchants\commands\CustomEnchantsCommand; use DaPigGuy\PiggyCustomEnchants\enchants\CustomEnchant; use DaPigGuy\PiggyCustomEnchants\enchants\ToggleableEnchantment; diff --git a/src/DaPigGuy/PiggyCustomEnchants/commands/subcommands/EnchantSubCommand.php b/src/DaPigGuy/PiggyCustomEnchants/commands/subcommands/EnchantSubCommand.php index 217aa7d1..fe320887 100644 --- a/src/DaPigGuy/PiggyCustomEnchants/commands/subcommands/EnchantSubCommand.php +++ b/src/DaPigGuy/PiggyCustomEnchants/commands/subcommands/EnchantSubCommand.php @@ -9,11 +9,12 @@ use CortexPE\Commando\BaseSubCommand; use CortexPE\Commando\exception\ArgumentOrderException; use DaPigGuy\PiggyCustomEnchants\CustomEnchantManager; +use DaPigGuy\PiggyCustomEnchants\items\EnchantedBook; use DaPigGuy\PiggyCustomEnchants\PiggyCustomEnchants; use DaPigGuy\PiggyCustomEnchants\utils\Utils; use pocketmine\command\CommandSender; use pocketmine\item\enchantment\EnchantmentInstance; -use pocketmine\item\ItemIds; +use pocketmine\item\ItemTypeIds; use pocketmine\player\Player; use pocketmine\utils\TextFormat; use Ramsey\Uuid\Uuid; @@ -68,7 +69,7 @@ public function onRun(CommandSender $sender, string $aliasUsed, array $args): vo return; } } - if ($item->getId() === ItemIds::ENCHANTED_BOOK || $item->getId() === ItemIds::BOOK) { + if ($item->getTypeId() === EnchantedBook::ENCHANTED_BOOK()->getTypeId() || $item->getTypeId() === ItemTypeIds::BOOK) { $item->getNamedTag()->setString("PiggyCEBookUUID", Uuid::uuid4()->toString()); } $item->addEnchantment(new EnchantmentInstance($enchant, $args["level"])); @@ -114,7 +115,7 @@ public function onRunForm(CommandSender $sender, string $aliasUsed, array $args) return; } } - if ($item->getId() === ItemIds::ENCHANTED_BOOK || $item->getId() === ItemIds::BOOK) { + if ($item->getTypeId() === EnchantedBook::ENCHANTED_BOOK()->getTypeId() || $item->getTypeId() === ItemTypeIds::BOOK) { $item->getNamedTag()->setString("PiggyCEBookUUID", Uuid::uuid4()->toString()); } $item->addEnchantment(new EnchantmentInstance($enchant, (int)$data[1])); diff --git a/src/DaPigGuy/PiggyCustomEnchants/enchants/armor/HeavyEnchant.php b/src/DaPigGuy/PiggyCustomEnchants/enchants/armor/HeavyEnchant.php index 7844ec3b..23609be8 100644 --- a/src/DaPigGuy/PiggyCustomEnchants/enchants/armor/HeavyEnchant.php +++ b/src/DaPigGuy/PiggyCustomEnchants/enchants/armor/HeavyEnchant.php @@ -11,7 +11,7 @@ use pocketmine\event\Event; use pocketmine\inventory\Inventory; use pocketmine\item\Item; -use pocketmine\item\ItemIds; +use pocketmine\item\ItemTypeIds; use pocketmine\player\Player; class HeavyEnchant extends ReactiveEnchantment @@ -31,7 +31,7 @@ public function react(Player $player, Item $item, Inventory $inventory, int $slo if ($event instanceof EntityDamageByEntityEvent) { $damager = $event->getDamager(); if ($damager instanceof Player) { - if ($damager->getInventory()->getItemInHand()->getId() === ItemIds::BOW) { + if ($damager->getInventory()->getItemInHand()->getTypeId() === ItemTypeIds::BOW) { $event->setModifier(-($event->getFinalDamage() * $this->extraData["absorbedDamageMultiplier"] * $level), CustomEnchantIds::HEAVY); } } diff --git a/src/DaPigGuy/PiggyCustomEnchants/enchants/armor/ReviveEnchant.php b/src/DaPigGuy/PiggyCustomEnchants/enchants/armor/ReviveEnchant.php index 0106351e..5cd131f8 100644 --- a/src/DaPigGuy/PiggyCustomEnchants/enchants/armor/ReviveEnchant.php +++ b/src/DaPigGuy/PiggyCustomEnchants/enchants/armor/ReviveEnchant.php @@ -13,7 +13,6 @@ use pocketmine\event\entity\EntityDamageEvent; use pocketmine\event\Event; use pocketmine\inventory\Inventory; -use pocketmine\item\enchantment\Enchantment; use pocketmine\item\enchantment\EnchantmentInstance; use pocketmine\item\Item; use pocketmine\player\Player; diff --git a/src/DaPigGuy/PiggyCustomEnchants/enchants/armor/ShrinkEnchant.php b/src/DaPigGuy/PiggyCustomEnchants/enchants/armor/ShrinkEnchant.php index 534c0bf7..7534186a 100644 --- a/src/DaPigGuy/PiggyCustomEnchants/enchants/armor/ShrinkEnchant.php +++ b/src/DaPigGuy/PiggyCustomEnchants/enchants/armor/ShrinkEnchant.php @@ -38,10 +38,10 @@ class ShrinkEnchant extends ToggleableEnchantment /** @var bool[] */ public array $shiftCache; - /** - * @return class-string[] - */ - public function getReagent(): array + /** + * @return class-string[] + */ + public function getReagent(): array { return [PlayerToggleSneakEvent::class]; } diff --git a/src/DaPigGuy/PiggyCustomEnchants/enchants/armor/boots/JetpackEnchant.php b/src/DaPigGuy/PiggyCustomEnchants/enchants/armor/boots/JetpackEnchant.php index 5e98bb8f..799815a7 100644 --- a/src/DaPigGuy/PiggyCustomEnchants/enchants/armor/boots/JetpackEnchant.php +++ b/src/DaPigGuy/PiggyCustomEnchants/enchants/armor/boots/JetpackEnchant.php @@ -15,7 +15,6 @@ use pocketmine\event\Event; use pocketmine\event\player\PlayerToggleSneakEvent; use pocketmine\inventory\Inventory; -use pocketmine\item\enchantment\Enchantment; use pocketmine\item\Item; use pocketmine\player\Player; use pocketmine\utils\TextFormat; diff --git a/src/DaPigGuy/PiggyCustomEnchants/enchants/armor/boots/MagmaWalkerEnchant.php b/src/DaPigGuy/PiggyCustomEnchants/enchants/armor/boots/MagmaWalkerEnchant.php index e7f14da0..32ce4302 100644 --- a/src/DaPigGuy/PiggyCustomEnchants/enchants/armor/boots/MagmaWalkerEnchant.php +++ b/src/DaPigGuy/PiggyCustomEnchants/enchants/armor/boots/MagmaWalkerEnchant.php @@ -4,10 +4,10 @@ namespace DaPigGuy\PiggyCustomEnchants\enchants\armor\boots; +use DaPigGuy\PiggyCustomEnchants\blocks\PiggyObsidian; use DaPigGuy\PiggyCustomEnchants\enchants\CustomEnchant; use DaPigGuy\PiggyCustomEnchants\enchants\ReactiveEnchantment; -use pocketmine\block\BlockFactory; -use pocketmine\block\BlockLegacyIds; +use pocketmine\block\BlockTypeIds; use pocketmine\block\Lava; use pocketmine\event\Event; use pocketmine\event\player\PlayerMoveEvent; @@ -44,9 +44,9 @@ public function react(Player $player, Item $item, Inventory $inventory, int $slo for ($x = -$radius; $x <= $radius; $x++) { for ($z = -$radius; $z <= $radius; $z++) { $b = $world->getBlock($player->getPosition()->add($x, -1, $z)); - if ($world->getBlock($b->getPosition()->add(0, 1, 0))->getId() === BlockLegacyIds::AIR) { - if ($b instanceof Lava && $b->getMeta() === 0) { - $world->setBlock($b->getPosition()->asVector3(), BlockFactory::getInstance()->get(BlockLegacyIds::OBSIDIAN, 15)); + if ($world->getBlock($b->getPosition()->add(0, 1, 0))->getTypeId() === BlockTypeIds::AIR) { + if ($b instanceof Lava && $b->getStateId() === 0) { + $world->setBlock($b->getPosition()->asVector3(), PiggyObsidian::PIGGY_OBSIDIAN()); } } } diff --git a/src/DaPigGuy/PiggyCustomEnchants/enchants/armor/chestplate/ParachuteEnchant.php b/src/DaPigGuy/PiggyCustomEnchants/enchants/armor/chestplate/ParachuteEnchant.php index a83ba72e..0fe4ffed 100644 --- a/src/DaPigGuy/PiggyCustomEnchants/enchants/armor/chestplate/ParachuteEnchant.php +++ b/src/DaPigGuy/PiggyCustomEnchants/enchants/armor/chestplate/ParachuteEnchant.php @@ -11,7 +11,7 @@ use DaPigGuy\PiggyCustomEnchants\enchants\TickingEnchantment; use DaPigGuy\PiggyCustomEnchants\enchants\traits\ToggleTrait; use DaPigGuy\PiggyCustomEnchants\PiggyCustomEnchants; -use pocketmine\block\BlockLegacyIds; +use pocketmine\block\BlockTypeIds; use pocketmine\entity\effect\EffectInstance; use pocketmine\inventory\Inventory; use pocketmine\item\enchantment\Rarity; @@ -34,7 +34,7 @@ public function tick(Player $player, Item $item, Inventory $inventory, int $slot if ($this->isInAir($player) && !$player->getAllowFlight() && !$player->canClimbWalls() && (($enchantInstance = $player->getArmorInventory()->getBoots()->getEnchantment(CustomEnchantManager::getEnchantment(CustomEnchantIds::JETPACK))) === null || !($enchant = $enchantInstance->getType()) instanceof JetpackEnchant || !$enchant->hasActiveJetpack($player))) { $player->getEffects()->add(new EffectInstance(PiggyCustomEnchants::$SLOW_FALL, 2147483647, 1, false)); } elseif ($player->getEffects()->get(PiggyCustomEnchants::$SLOW_FALL) !== null) { - if ($this->isInAir($player) || $player->getWorld()->getBlock($player->getPosition()->subtract(0, 1, 0))->getId() !== BlockLegacyIds::AIR) $player->getEffects()->remove(PiggyCustomEnchants::$SLOW_FALL); + if ($this->isInAir($player) || $player->getWorld()->getBlock($player->getPosition()->subtract(0, 1, 0))->getTypeId() !== BlockTypeIds::AIR) $player->getEffects()->remove(PiggyCustomEnchants::$SLOW_FALL); } $player->resetFallDistance(); } @@ -49,7 +49,7 @@ public function toggle(Player $player, Item $item, Inventory $inventory, int $sl public function isInAir(Player $player): bool { for ($y = 1; $y <= 5; $y++) { - if ($player->getWorld()->getBlock($player->getPosition()->subtract(0, $y, 0))->getId() !== BlockLegacyIds::AIR) return false; + if ($player->getWorld()->getBlock($player->getPosition()->subtract(0, $y, 0))->getTypeId() !== BlockTypeIds::AIR) return false; } return true; } diff --git a/src/DaPigGuy/PiggyCustomEnchants/enchants/armor/helmet/ImplantsEnchant.php b/src/DaPigGuy/PiggyCustomEnchants/enchants/armor/helmet/ImplantsEnchant.php index 145c99b3..56910036 100644 --- a/src/DaPigGuy/PiggyCustomEnchants/enchants/armor/helmet/ImplantsEnchant.php +++ b/src/DaPigGuy/PiggyCustomEnchants/enchants/armor/helmet/ImplantsEnchant.php @@ -12,7 +12,6 @@ use pocketmine\event\Event; use pocketmine\event\player\PlayerMoveEvent; use pocketmine\inventory\Inventory; -use pocketmine\item\enchantment\Enchantment; use pocketmine\item\Item; use pocketmine\player\Player; use pocketmine\scheduler\ClosureTask; diff --git a/src/DaPigGuy/PiggyCustomEnchants/enchants/miscellaneous/AutoRepairEnchant.php b/src/DaPigGuy/PiggyCustomEnchants/enchants/miscellaneous/AutoRepairEnchant.php index 3d4e5927..c74993a1 100644 --- a/src/DaPigGuy/PiggyCustomEnchants/enchants/miscellaneous/AutoRepairEnchant.php +++ b/src/DaPigGuy/PiggyCustomEnchants/enchants/miscellaneous/AutoRepairEnchant.php @@ -34,8 +34,8 @@ public function getDefaultExtraData(): array public function react(Player $player, Item $item, Inventory $inventory, int $slot, Event $event, int $level, int $stack): void { - if (!$item instanceof Durable || $item->getMeta() === 0) return; - $newDir = $item->getMeta() - ((int)$this->extraData["baseRepair"] + ((int)$this->extraData["repairMultiplier"] * $level)); + if (!$item instanceof Durable || $item->getStateId() === 0) return; + $newDir = $item->getStateId() - ((int)$this->extraData["baseRepair"] + ((int)$this->extraData["repairMultiplier"] * $level)); if ($newDir < 0) { $item->setDamage(0); } else { diff --git a/src/DaPigGuy/PiggyCustomEnchants/enchants/tools/axes/LumberjackEnchant.php b/src/DaPigGuy/PiggyCustomEnchants/enchants/tools/axes/LumberjackEnchant.php index 2d26525d..3ab598b5 100644 --- a/src/DaPigGuy/PiggyCustomEnchants/enchants/tools/axes/LumberjackEnchant.php +++ b/src/DaPigGuy/PiggyCustomEnchants/enchants/tools/axes/LumberjackEnchant.php @@ -7,7 +7,7 @@ use DaPigGuy\PiggyCustomEnchants\enchants\CustomEnchant; use DaPigGuy\PiggyCustomEnchants\enchants\miscellaneous\RecursiveEnchant; use pocketmine\block\Block; -use pocketmine\block\BlockLegacyIds; +use pocketmine\block\BlockTypeIds; use pocketmine\event\block\BlockBreakEvent; use pocketmine\event\Event; use pocketmine\inventory\Inventory; @@ -21,6 +21,8 @@ class LumberjackEnchant extends RecursiveEnchant public int $itemType = CustomEnchant::ITEM_TYPE_AXE; + private const LOG_TYPES = [BlockTypeIds::ACACIA_LOG, BlockTypeIds::BIRCH_LOG, BlockTypeIds::CHERRY_LOG, BlockTypeIds::OAK_LOG, BlockTypeIds::DARK_OAK_LOG, BlockTypeIds::MANGROVE_LOG, BlockTypeIds::JUNGLE_LOG, BlockTypeIds::SPRUCE_LOG]; + public function getReagent(): array { return [BlockBreakEvent::class]; @@ -36,7 +38,7 @@ public function safeReact(Player $player, Item $item, Inventory $inventory, int if ($event instanceof BlockBreakEvent) { $block = $event->getBlock(); if ($player->isSneaking()) { - if ($block->getId() == BlockLegacyIds::LOG || $block->getId() == BlockLegacyIds::LOG2) { + if (in_array($block->getTypeId(), self::LOG_TYPES)) { $this->breakTree($block, $player); } } @@ -47,13 +49,9 @@ public function breakTree(Block $block, Player $player, int $mined = 0): void { $item = $player->getInventory()->getItemInHand(); for ($i = 0; $i <= 5; $i++) { - if ($mined > $this->extraData["limit"]) { - break; - } + if ($mined > $this->extraData["limit"]) break; $side = $block->getSide($i); - if ($side->getId() !== BlockLegacyIds::LOG && $side->getId() !== BlockLegacyIds::LOG2) { - continue; - } + if (in_array($side, self::LOG_TYPES)) continue; $player->getWorld()->useBreakOn($side->getPosition(), $item, $player); $mined++; $this->breakTree($side, $player, $mined); diff --git a/src/DaPigGuy/PiggyCustomEnchants/enchants/tools/hoe/FertilizerEnchant.php b/src/DaPigGuy/PiggyCustomEnchants/enchants/tools/hoe/FertilizerEnchant.php index e3bb6ca2..9f21550b 100644 --- a/src/DaPigGuy/PiggyCustomEnchants/enchants/tools/hoe/FertilizerEnchant.php +++ b/src/DaPigGuy/PiggyCustomEnchants/enchants/tools/hoe/FertilizerEnchant.php @@ -6,7 +6,7 @@ use DaPigGuy\PiggyCustomEnchants\enchants\CustomEnchant; use DaPigGuy\PiggyCustomEnchants\enchants\miscellaneous\RecursiveEnchant; -use pocketmine\block\BlockLegacyIds; +use pocketmine\block\BlockTypeIds; use pocketmine\event\Event; use pocketmine\event\player\PlayerInteractEvent; use pocketmine\inventory\Inventory; @@ -37,12 +37,12 @@ public function safeReact(Player $player, Item $item, Inventory $inventory, int { if ($event instanceof PlayerInteractEvent) { $block = $event->getBlock(); - if ($block->getId() === BlockLegacyIds::GRASS || ($block->getId() === BlockLegacyIds::DIRT && $block->getMeta() === 0)) { + if ($block->getTypeId() === BlockTypeIds::GRASS || ($block->getTypeId() === BlockTypeIds::DIRT && $block->getStateId() === 0)) { $radius = $level * $this->extraData["radiusMultiplier"]; for ($x = -$radius; $x <= $radius; $x++) { for ($z = -$radius; $z <= $radius; $z++) { $newBlock = $block->getPosition()->getWorld()->getBlock($block->getPosition()->add($x, 0, $z)); - if ($newBlock->getId() === BlockLegacyIds::GRASS || ($newBlock->getId() === BlockLegacyIds::DIRT && $newBlock->getMeta() === 0)) { + if ($newBlock->getTypeId() === BlockTypeIds::GRASS || ($newBlock->getTypeId() === BlockTypeIds::DIRT && $newBlock->getStateId() === 0)) { $block->getPosition()->getWorld()->useItemOn($newBlock->getPosition(), $item, Facing::UP, $newBlock->getPosition(), $player); } } diff --git a/src/DaPigGuy/PiggyCustomEnchants/enchants/tools/pickaxe/JackpotEnchant.php b/src/DaPigGuy/PiggyCustomEnchants/enchants/tools/pickaxe/JackpotEnchant.php index 9d51de8c..66b06af4 100644 --- a/src/DaPigGuy/PiggyCustomEnchants/enchants/tools/pickaxe/JackpotEnchant.php +++ b/src/DaPigGuy/PiggyCustomEnchants/enchants/tools/pickaxe/JackpotEnchant.php @@ -6,8 +6,8 @@ use DaPigGuy\PiggyCustomEnchants\enchants\CustomEnchant; use DaPigGuy\PiggyCustomEnchants\enchants\ReactiveEnchantment; -use pocketmine\block\BlockFactory; -use pocketmine\block\BlockLegacyIds; +use pocketmine\block\BlockTypeIds; +use pocketmine\block\VanillaBlocks; use pocketmine\event\block\BlockBreakEvent; use pocketmine\event\Event; use pocketmine\inventory\Inventory; @@ -24,11 +24,11 @@ class JackpotEnchant extends ReactiveEnchantment public int $itemType = CustomEnchant::ITEM_TYPE_PICKAXE; const ORE_TIERS = [ - BlockLegacyIds::COAL_ORE, - BlockLegacyIds::IRON_ORE, - BlockLegacyIds::GOLD_ORE, - BlockLegacyIds::DIAMOND_ORE, - BlockLegacyIds::EMERALD_ORE + BlockTypeIds::COAL_ORE, + BlockTypeIds::IRON_ORE, + BlockTypeIds::GOLD_ORE, + BlockTypeIds::DIAMOND_ORE, + BlockTypeIds::EMERALD_ORE ]; public function getReagent(): array @@ -39,7 +39,7 @@ public function getReagent(): array public function react(Player $player, Item $item, Inventory $inventory, int $slot, Event $event, int $level, int $stack): void { if ($event instanceof BlockBreakEvent) { - $key = array_search($event->getBlock()->getId(), self::ORE_TIERS, true); + $key = array_search($event->getBlock()->getTypeId(), self::ORE_TIERS, true); if ($key !== false) { if (isset(self::ORE_TIERS[$key + 1])) { $drops = $event->getDrops(); @@ -48,7 +48,7 @@ public function react(Player $player, Item $item, Inventory $inventory, int $slo unset($drops[$k]); } } - $drops = array_merge($drops, BlockFactory::getInstance()->get(self::ORE_TIERS[$key + 1], 0)->getDrops(VanillaItems::DIAMOND_PICKAXE())); + $drops = array_merge($drops, $this->getOreDrops(self::ORE_TIERS[$key + 1])); $event->setDrops($drops); } } @@ -59,4 +59,17 @@ public function getPriority(): int { return 3; } + + public function getOreDrops(int $tier): array + { + $drop = match ($tier) { + BlockTypeIds::COAL_ORE => VanillaBlocks::COAL_ORE(), + BlockTypeIds::IRON_ORE => VanillaBlocks::IRON_ORE(), + BlockTypeIds::GOLD_ORE => VanillaBlocks::GOLD_ORE(), + BlockTypeIds::DIAMOND_ORE => VanillaBlocks::DIAMOND_ORE(), + BlockTypeIds::EMERALD_ORE => VanillaBlocks::EMERALD_ORE(), + default => VanillaItems::AIR(), + }; + return $drop->getDrops(VanillaItems::DIAMOND_PICKAXE()); + } } diff --git a/src/DaPigGuy/PiggyCustomEnchants/enchants/weapons/HallucinationEnchant.php b/src/DaPigGuy/PiggyCustomEnchants/enchants/weapons/HallucinationEnchant.php index 827911d2..ad02dbf3 100644 --- a/src/DaPigGuy/PiggyCustomEnchants/enchants/weapons/HallucinationEnchant.php +++ b/src/DaPigGuy/PiggyCustomEnchants/enchants/weapons/HallucinationEnchant.php @@ -5,8 +5,6 @@ namespace DaPigGuy\PiggyCustomEnchants\enchants\weapons; use DaPigGuy\PiggyCustomEnchants\enchants\ReactiveEnchantment; -use pocketmine\block\BlockFactory; -use pocketmine\block\BlockLegacyIds; use pocketmine\block\tile\Sign; use pocketmine\block\tile\Tile; use pocketmine\block\VanillaBlocks; @@ -16,7 +14,8 @@ use pocketmine\item\enchantment\Rarity; use pocketmine\item\Item; use pocketmine\nbt\tag\CompoundTag; -use pocketmine\network\mcpe\convert\RuntimeBlockMapping; +use pocketmine\network\mcpe\convert\TypeConverter; +use pocketmine\network\mcpe\NetworkBroadcastUtils; use pocketmine\network\mcpe\protocol\BlockActorDataPacket; use pocketmine\network\mcpe\protocol\serializer\NetworkNbtSerializer; use pocketmine\network\mcpe\protocol\types\BlockPosition; @@ -53,7 +52,9 @@ public function react(Player $player, Item $item, Inventory $inventory, int $slo $block = VanillaBlocks::BEDROCK(); if ($position->equals($originalPosition)) $block = VanillaBlocks::LAVA(); if ($position->equals($originalPosition->add(0, 1, 0))) { - $block = BlockFactory::getInstance()->get(BlockLegacyIds::WALL_SIGN, 2); + // TODO: I have no idea what meta 2 means. + // BlockFactory::getInstance()->get(BlockLegacyIds::WALL_SIGN, 2); + $block = VanillaBlocks::OAK_SIGN(); if ($this->nbtWriter === null) $this->nbtWriter = new NetworkNbtSerializer(); $packets[] = BlockActorDataPacket::create(BlockPosition::fromVector3($position->floor()), new CacheableNbt( CompoundTag::create()-> @@ -67,11 +68,12 @@ public function react(Player $player, Item $item, Inventory $inventory, int $slo ]) ))); } - $packets[] = UpdateBlockPacket::create(BlockPosition::fromVector3($position->floor()), RuntimeBlockMapping::getInstance()->toRuntimeId($block->getFullId()), UpdateBlockPacket::FLAG_NETWORK, UpdateBlockPacket::DATA_LAYER_NORMAL); + $blockTranslator = TypeConverter::getInstance()->getBlockTranslator(); + $packets[] = UpdateBlockPacket::create(BlockPosition::fromVector3($position->floor()), $blockTranslator->internalIdToNetworkId($block->getStateId()), UpdateBlockPacket::FLAG_NETWORK, UpdateBlockPacket::DATA_LAYER_NORMAL); } } } - $entity->getServer()->broadcastPackets([$entity], $packets); + NetworkBroadcastUtils::broadcastPackets([$entity], $packets); })), 1); $this->plugin->getScheduler()->scheduleDelayedTask(new ClosureTask(function () use ($originalPosition, $entity, $task): void { $task->getHandler()->cancel(); @@ -83,7 +85,7 @@ public function react(Player $player, Item $item, Inventory $inventory, int $slo } } } - $entity->getServer()->broadcastPackets([$entity], $entity->getWorld()->createBlockUpdatePackets($blocks)); + NetworkBroadcastUtils::broadcastPackets([$entity], $entity->getWorld()->createBlockUpdatePackets($blocks)); unset(self::$hallucinating[$entity->getName()]); }), 20 * 60); } diff --git a/src/DaPigGuy/PiggyCustomEnchants/enchants/weapons/bows/BountyHunterEnchant.php b/src/DaPigGuy/PiggyCustomEnchants/enchants/weapons/bows/BountyHunterEnchant.php index c318cfe4..c0ffd5fc 100644 --- a/src/DaPigGuy/PiggyCustomEnchants/enchants/weapons/bows/BountyHunterEnchant.php +++ b/src/DaPigGuy/PiggyCustomEnchants/enchants/weapons/bows/BountyHunterEnchant.php @@ -11,8 +11,7 @@ use pocketmine\inventory\Inventory; use pocketmine\item\enchantment\Rarity; use pocketmine\item\Item; -use pocketmine\item\ItemFactory; -use pocketmine\item\ItemIds; +use pocketmine\item\VanillaItems; use pocketmine\player\Player; class BountyHunterEnchant extends ReactiveEnchantment @@ -37,29 +36,30 @@ public function react(Player $player, Item $item, Inventory $inventory, int $slo { if ($event instanceof EntityDamageByChildEntityEvent) { $bountyDrop = $this->getBounty(); - $player->getInventory()->addItem(ItemFactory::getInstance()->get($bountyDrop, 0, mt_rand(1, $this->extraData["base"] + $level * $this->extraData["multiplier"]))); + $bountyDrop->setCount(mt_rand(1, $this->extraData["base"] + $level * $this->extraData["multiplier"])); + $player->getInventory()->addItem($bountyDrop); } } - public function getBounty(): int + public function getBounty(): Item { $random = mt_rand(0, 75); $currentChance = 2.5; if ($random < $currentChance) { - return ItemIds::EMERALD; + return VanillaItems::EMERALD(); } $currentChance += 5; if ($random < $currentChance) { - return ItemIds::DIAMOND; + return VanillaItems::DIAMOND(); } $currentChance += 15; if ($random < $currentChance) { - return ItemIds::GOLD_INGOT; + return VanillaItems::GOLD_INGOT(); } $currentChance += 27.5; if ($random < $currentChance) { - return ItemIds::IRON_INGOT; + return VanillaItems::IRON_INGOT(); } - return ItemIds::COAL; + return VanillaItems::COAL(); } } \ No newline at end of file diff --git a/src/DaPigGuy/PiggyCustomEnchants/entities/PigProjectile.php b/src/DaPigGuy/PiggyCustomEnchants/entities/PigProjectile.php index e6cbc533..f6cfdc5b 100644 --- a/src/DaPigGuy/PiggyCustomEnchants/entities/PigProjectile.php +++ b/src/DaPigGuy/PiggyCustomEnchants/entities/PigProjectile.php @@ -93,19 +93,12 @@ public function getDrops(): array { $values = self::PORK_LEVELS[$this->getPorkLevel()]; - switch ($values[3]) { - case ItemTypeIds::RAW_PORKCHOP: - $drop = VanillaItems::RAW_PORKCHOP(); - break; - case ItemTypeIds::COOKED_PORKCHOP: - $drop = VanillaItems::COOKED_PORKCHOP(); - break; - case ItemTypeIds::ROTTEN_FLESH: - $drop = VanillaItems::ROTTEN_FLESH(); - break; - default: - return []; - } + $drop = match ($values[3]) { + ItemTypeIds::RAW_PORKCHOP => VanillaItems::RAW_PORKCHOP(), + ItemTypeIds::COOKED_PORKCHOP => VanillaItems::COOKED_PORKCHOP(), + ItemTypeIds::ROTTEN_FLESH => VanillaItems::ROTTEN_FLESH(), + default => VanillaItems::AIR(), + }; return [$drop->setCount(1)->setCustomName(TextFormat::RESET . TextFormat::WHITE . $values[4])]; } diff --git a/src/DaPigGuy/PiggyCustomEnchants/tasks/TickEnchantmentsTask.php b/src/DaPigGuy/PiggyCustomEnchants/tasks/TickEnchantmentsTask.php index 48e7ab51..e017f155 100644 --- a/src/DaPigGuy/PiggyCustomEnchants/tasks/TickEnchantmentsTask.php +++ b/src/DaPigGuy/PiggyCustomEnchants/tasks/TickEnchantmentsTask.php @@ -6,11 +6,11 @@ use DaPigGuy\PiggyCustomEnchants\enchants\CustomEnchant; use DaPigGuy\PiggyCustomEnchants\enchants\TickingEnchantment; +use DaPigGuy\PiggyCustomEnchants\items\EnchantedBook; use DaPigGuy\PiggyCustomEnchants\PiggyCustomEnchants; use DaPigGuy\PiggyCustomEnchants\utils\Utils; use pocketmine\item\Item; -use pocketmine\item\ItemFactory; -use pocketmine\item\ItemIds; +use pocketmine\item\ItemTypeIds; use pocketmine\scheduler\Task; use pocketmine\Server; use pocketmine\utils\TextFormat; @@ -27,9 +27,9 @@ public function onRun(): void foreach ($this->plugin->getServer()->getOnlinePlayers() as $player) { $successfulEnchantments = []; foreach ($player->getInventory()->getContents() as $slot => $content) { - if ($content->getId() === ItemIds::BOOK) { + if ($content->getTypeId() === ItemTypeIds::BOOK) { if (count($content->getEnchantments()) > 0) { - $enchantedBook = ItemFactory::getInstance()->get(ItemIds::ENCHANTED_BOOK, 0, $content->getCount(), $content->getNamedTag()); + $enchantedBook = EnchantedBook::ENCHANTED_BOOK()->setNamedTag($content->getNamedTag())->setCount($content->getCount()); $enchantedBook->setCustomName(TextFormat::RESET . TextFormat::YELLOW . "Enchanted Book" . TextFormat::RESET); $enchantedBook->addEnchantment(...$content->getEnchantments()); $player->getInventory()->setItem($slot, $enchantedBook); diff --git a/src/DaPigGuy/PiggyCustomEnchants/utils/Utils.php b/src/DaPigGuy/PiggyCustomEnchants/utils/Utils.php index 61dfa183..323c7b41 100644 --- a/src/DaPigGuy/PiggyCustomEnchants/utils/Utils.php +++ b/src/DaPigGuy/PiggyCustomEnchants/utils/Utils.php @@ -11,6 +11,7 @@ use DaPigGuy\PiggyCustomEnchants\entities\PiggyFireball; use DaPigGuy\PiggyCustomEnchants\entities\PiggyWitherSkull; use DaPigGuy\PiggyCustomEnchants\entities\PigProjectile; +use DaPigGuy\PiggyCustomEnchants\items\EnchantedBook; use InvalidArgumentException; use pocketmine\entity\Location; use pocketmine\entity\projectile\Arrow; @@ -25,7 +26,7 @@ use pocketmine\item\enchantment\Rarity; use pocketmine\item\Hoe; use pocketmine\item\Item; -use pocketmine\item\ItemIds; +use pocketmine\item\ItemTypeIds; use pocketmine\item\Pickaxe; use pocketmine\item\Shears; use pocketmine\item\Shovel; @@ -129,7 +130,7 @@ public static function isBoots(Item $item): bool public static function itemMatchesItemType(Item $item, int $itemType): bool { - if ($item->getId() === ItemIds::BOOK || $item->getId() === ItemIds::ENCHANTED_BOOK) return true; + if ($item->getTypeId() === ItemTypeIds::BOOK || $item->getTypeId() === EnchantedBook::ENCHANTED_BOOK()->getTypeId()) return true; return match ($itemType) { CustomEnchant::ITEM_TYPE_GLOBAL => true, CustomEnchant::ITEM_TYPE_DAMAGEABLE => $item instanceof Durable, @@ -141,7 +142,8 @@ public static function itemMatchesItemType(Item $item, int $itemType): bool CustomEnchant::ITEM_TYPE_AXE => $item instanceof Axe, CustomEnchant::ITEM_TYPE_SHOVEL => $item instanceof Shovel, CustomEnchant::ITEM_TYPE_HOE => $item instanceof Hoe, - CustomEnchant::ITEM_TYPE_ARMOR => $item instanceof Armor || $item->getId() === ItemIds::ELYTRA, + // TODO: $item->getTypeId() === ItemTypeIds::ELYTRA + CustomEnchant::ITEM_TYPE_ARMOR => $item instanceof Armor, CustomEnchant::ITEM_TYPE_HELMET => self::isHelmet($item), CustomEnchant::ITEM_TYPE_CHESTPLATE => self::isChestplate($item), CustomEnchant::ITEM_TYPE_LEGGINGS => self::isLeggings($item), From b15c1240a96b6ecc27419a3bfcd4be7cdd38fea0 Mon Sep 17 00:00:00 2001 From: aericio <16523741+Aericio@users.noreply.github.com> Date: Sun, 16 Jul 2023 15:07:34 -1000 Subject: [PATCH 06/23] Update Explosion calls --- src/DaPigGuy/PiggyCustomEnchants/entities/PiggyTNT.php | 6 +++--- src/DaPigGuy/PiggyCustomEnchants/utils/PiggyExplosion.php | 8 ++++---- 2 files changed, 7 insertions(+), 7 deletions(-) diff --git a/src/DaPigGuy/PiggyCustomEnchants/entities/PiggyTNT.php b/src/DaPigGuy/PiggyCustomEnchants/entities/PiggyTNT.php index b417cad9..ad6f185b 100644 --- a/src/DaPigGuy/PiggyCustomEnchants/entities/PiggyTNT.php +++ b/src/DaPigGuy/PiggyCustomEnchants/entities/PiggyTNT.php @@ -7,7 +7,7 @@ use DaPigGuy\PiggyCustomEnchants\utils\PiggyExplosion; use pocketmine\entity\Location; use pocketmine\entity\object\PrimedTNT; -use pocketmine\event\entity\ExplosionPrimeEvent; +use pocketmine\event\entity\EntityPreExplodeEvent; use pocketmine\nbt\tag\CompoundTag; use pocketmine\player\Player; use pocketmine\world\Position; @@ -28,11 +28,11 @@ public function explode(): void if (!$ownerEntity instanceof Player) { return; } - $ev = new ExplosionPrimeEvent($this, 4); + $ev = new EntityPreExplodeEvent($this, 4); $ev->setBlockBreaking($this->worldDamage); $ev->call(); if (!$ev->isCancelled()) { - $explosion = new PiggyExplosion(Position::fromObject($this->location->add(0, $this->size->getHeight() / 2, 0), $this->location->world), $ev->getForce(), $ownerEntity); + $explosion = new PiggyExplosion(Position::fromObject($this->location->add(0, $this->size->getHeight() / 2, 0), $this->location->world), $ev->getRadius(), $ownerEntity); if ($ev->isBlockBreaking()) $explosion->explodeA(); $explosion->explodeB(); } diff --git a/src/DaPigGuy/PiggyCustomEnchants/utils/PiggyExplosion.php b/src/DaPigGuy/PiggyCustomEnchants/utils/PiggyExplosion.php index 5e5a4a62..f7280608 100644 --- a/src/DaPigGuy/PiggyCustomEnchants/utils/PiggyExplosion.php +++ b/src/DaPigGuy/PiggyCustomEnchants/utils/PiggyExplosion.php @@ -21,15 +21,15 @@ class PiggyExplosion extends Explosion { - public function __construct(Position $center, float $size, protected Player $player, protected bool $entityDamage = true) + public function __construct(Position $center, float $radius, protected Player $player, protected bool $entityDamage = true) { - parent::__construct($center, $size, $this->player); + parent::__construct($center, $radius, $this->player); } public function explodeB(): bool { $source = (new Vector3($this->source->x, $this->source->y, $this->source->z))->floor(); - $yield = (1 / $this->size) * 100; + $yield = (1 / $this->radius) * 100; $ev = new EntityExplodeEvent($this->player, $this->source, $this->affectedBlocks, $yield); $ev->call(); @@ -39,7 +39,7 @@ public function explodeB(): bool $this->affectedBlocks = $ev->getBlockList(); } - $explosionSize = $this->size * 2; + $explosionSize = $this->radius * 2; $minX = (int)floor($this->source->x - $explosionSize - 1); $maxX = (int)ceil($this->source->x + $explosionSize + 1); $minY = (int)floor($this->source->y - $explosionSize - 1); From 0da2d79488d2073b13d06d515ba55b5de16be401 Mon Sep 17 00:00:00 2001 From: aericio <16523741+Aericio@users.noreply.github.com> Date: Sun, 16 Jul 2023 15:25:16 -1000 Subject: [PATCH 07/23] Fix incorrect methods --- src/DaPigGuy/PiggyCustomEnchants/blocks/PiggyObsidian.php | 2 +- src/DaPigGuy/PiggyCustomEnchants/blocks/PiggyObsidianBlock.php | 2 +- .../enchants/tools/pickaxe/JackpotEnchant.php | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/src/DaPigGuy/PiggyCustomEnchants/blocks/PiggyObsidian.php b/src/DaPigGuy/PiggyCustomEnchants/blocks/PiggyObsidian.php index c0be10ba..110fe384 100644 --- a/src/DaPigGuy/PiggyCustomEnchants/blocks/PiggyObsidian.php +++ b/src/DaPigGuy/PiggyCustomEnchants/blocks/PiggyObsidian.php @@ -39,6 +39,6 @@ public static function getAll(): array protected static function setup(): void { - self::register("obsidian", new PiggyObsidianBlock(new BlockIdentifier(BlockTypeIds::newId(), 15), "Magmawalker Obsidian", new BlockTypeInfo(BlockBreakInfo::instant()))); + self::register("obsidian", new PiggyObsidianBlock(new BlockIdentifier(BlockTypeIds::newId()), "Magmawalker Obsidian", new BlockTypeInfo(BlockBreakInfo::instant()))); } } diff --git a/src/DaPigGuy/PiggyCustomEnchants/blocks/PiggyObsidianBlock.php b/src/DaPigGuy/PiggyCustomEnchants/blocks/PiggyObsidianBlock.php index 911d1af1..1dd6ef4d 100644 --- a/src/DaPigGuy/PiggyCustomEnchants/blocks/PiggyObsidianBlock.php +++ b/src/DaPigGuy/PiggyCustomEnchants/blocks/PiggyObsidianBlock.php @@ -39,7 +39,7 @@ public function countNeighbors(): int { $i = 0; foreach ($this->getAllSides() as $block) { - if ($block instanceof PiggyObsidian) { + if ($block instanceof PiggyObsidianBlock) { $i++; if ($i >= 4) return $i; } diff --git a/src/DaPigGuy/PiggyCustomEnchants/enchants/tools/pickaxe/JackpotEnchant.php b/src/DaPigGuy/PiggyCustomEnchants/enchants/tools/pickaxe/JackpotEnchant.php index 66b06af4..7340f852 100644 --- a/src/DaPigGuy/PiggyCustomEnchants/enchants/tools/pickaxe/JackpotEnchant.php +++ b/src/DaPigGuy/PiggyCustomEnchants/enchants/tools/pickaxe/JackpotEnchant.php @@ -68,7 +68,7 @@ public function getOreDrops(int $tier): array BlockTypeIds::GOLD_ORE => VanillaBlocks::GOLD_ORE(), BlockTypeIds::DIAMOND_ORE => VanillaBlocks::DIAMOND_ORE(), BlockTypeIds::EMERALD_ORE => VanillaBlocks::EMERALD_ORE(), - default => VanillaItems::AIR(), + default => VanillaBlocks::AIR(), }; return $drop->getDrops(VanillaItems::DIAMOND_PICKAXE()); } From 938576d14bd6b68db1888ea65d48d9ff21d68ea6 Mon Sep 17 00:00:00 2001 From: aericio <16523741+Aericio@users.noreply.github.com> Date: Sun, 16 Jul 2023 15:34:04 -1000 Subject: [PATCH 08/23] Use legacy loader for chicken drops --- .../enchants/armor/chestplate/ChickenEnchant.php | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/src/DaPigGuy/PiggyCustomEnchants/enchants/armor/chestplate/ChickenEnchant.php b/src/DaPigGuy/PiggyCustomEnchants/enchants/armor/chestplate/ChickenEnchant.php index f6ad9437..959b29f5 100644 --- a/src/DaPigGuy/PiggyCustomEnchants/enchants/armor/chestplate/ChickenEnchant.php +++ b/src/DaPigGuy/PiggyCustomEnchants/enchants/armor/chestplate/ChickenEnchant.php @@ -9,10 +9,10 @@ use pocketmine\inventory\Inventory; use pocketmine\item\enchantment\Rarity; use pocketmine\item\Item; -use pocketmine\item\ItemFactory; use pocketmine\item\VanillaItems; use pocketmine\player\Player; use pocketmine\utils\TextFormat; +use pocketmine\world\format\io\GlobalItemDataHandlers; class ChickenEnchant extends TickingEnchantment { @@ -36,7 +36,11 @@ public function tick(Player $player, Item $item, Inventory $inventory, int $slot } $drop = array_rand($drops); $drop = explode(":", $drops[$drop]); - $item = count($drop) < 3 ? VanillaItems::GOLD_INGOT() : ItemFactory::getInstance()->get((int)$drop[0], (int)$drop[1], (int)$drop[2]); + + $itemify = GlobalItemDataHandlers::getUpgrader()->upgradeItemTypeDataInt((int)$drop[0], (int)$drop[1], (int)$drop[2], null); + $itemify = GlobalItemDataHandlers::getDeserializer()->deserializeStack($itemify); + + $item = count($drop) < 3 ? VanillaItems::GOLD_INGOT() : $itemify; $vowels = ["a", "e", "i", "o", "u"]; $player->getWorld()->dropItem($player->getPosition(), $item, $player->getDirectionVector()->multiply(-0.4)); $player->sendTip(TextFormat::GREEN . "You have laid a" . (in_array(strtolower($item->getName()[0]), $vowels) ? "n " : " ") . $item->getName() . "..."); From 596ccd68ca6e984b591d1d21bfc62bdab79a715a Mon Sep 17 00:00:00 2001 From: aericio <16523741+Aericio@users.noreply.github.com> Date: Sun, 16 Jul 2023 16:06:16 -1000 Subject: [PATCH 09/23] Register block under piggy_obsidian --- src/DaPigGuy/PiggyCustomEnchants/PiggyCustomEnchants.php | 2 +- src/DaPigGuy/PiggyCustomEnchants/blocks/PiggyObsidian.php | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/DaPigGuy/PiggyCustomEnchants/PiggyCustomEnchants.php b/src/DaPigGuy/PiggyCustomEnchants/PiggyCustomEnchants.php index a81d33ef..ace8726c 100644 --- a/src/DaPigGuy/PiggyCustomEnchants/PiggyCustomEnchants.php +++ b/src/DaPigGuy/PiggyCustomEnchants/PiggyCustomEnchants.php @@ -162,7 +162,7 @@ public function areFormsEnabled(): bool private static function registerItemsAndBlocks(): void { self::registerItem(ItemTypeNames::ENCHANTED_BOOK, EnchantedBook::ENCHANTED_BOOK(), ["enchanted_book"]); - self::registerBlock(BlockTypeNames::OBSIDIAN, PiggyObsidian::PIGGY_OBSIDIAN(), ["obsidian"]); + self::registerBlock(BlockTypeNames::OBSIDIAN, PiggyObsidian::PIGGY_OBSIDIAN(), ["piggy_obsidian"]); } /** diff --git a/src/DaPigGuy/PiggyCustomEnchants/blocks/PiggyObsidian.php b/src/DaPigGuy/PiggyCustomEnchants/blocks/PiggyObsidian.php index 110fe384..1e58c049 100644 --- a/src/DaPigGuy/PiggyCustomEnchants/blocks/PiggyObsidian.php +++ b/src/DaPigGuy/PiggyCustomEnchants/blocks/PiggyObsidian.php @@ -39,6 +39,6 @@ public static function getAll(): array protected static function setup(): void { - self::register("obsidian", new PiggyObsidianBlock(new BlockIdentifier(BlockTypeIds::newId()), "Magmawalker Obsidian", new BlockTypeInfo(BlockBreakInfo::instant()))); + self::register("piggy_obsidian", new PiggyObsidianBlock(new BlockIdentifier(BlockTypeIds::newId()), "Magmawalker Obsidian", new BlockTypeInfo(BlockBreakInfo::instant()))); } } From 965c785f1451403e9c037f6ac11b69903115350a Mon Sep 17 00:00:00 2001 From: aericio <16523741+Aericio@users.noreply.github.com> Date: Sun, 16 Jul 2023 19:22:38 -1000 Subject: [PATCH 10/23] Register base command permission --- src/DaPigGuy/PiggyCustomEnchants/PiggyCustomEnchants.php | 4 +--- .../PiggyCustomEnchants/commands/CustomEnchantsCommand.php | 2 ++ .../commands/subcommands/InfoSubCommand.php | 2 +- 3 files changed, 4 insertions(+), 4 deletions(-) diff --git a/src/DaPigGuy/PiggyCustomEnchants/PiggyCustomEnchants.php b/src/DaPigGuy/PiggyCustomEnchants/PiggyCustomEnchants.php index ace8726c..6d8d88a2 100644 --- a/src/DaPigGuy/PiggyCustomEnchants/PiggyCustomEnchants.php +++ b/src/DaPigGuy/PiggyCustomEnchants/PiggyCustomEnchants.php @@ -7,7 +7,6 @@ use CortexPE\Commando\BaseCommand; use CortexPE\Commando\PacketHooker; use DaPigGuy\libPiggyUpdateChecker\libPiggyUpdateChecker; -use DaPigGuy\PiggyCustomEnchants\blocks\PiggyObsidian; use DaPigGuy\PiggyCustomEnchants\commands\CustomEnchantsCommand; use DaPigGuy\PiggyCustomEnchants\enchants\CustomEnchant; use DaPigGuy\PiggyCustomEnchants\enchants\ToggleableEnchantment; @@ -24,7 +23,6 @@ use pocketmine\block\Block; use pocketmine\block\RuntimeBlockStateRegistry; use pocketmine\color\Color; -use pocketmine\data\bedrock\block\BlockTypeNames; use pocketmine\data\bedrock\EffectIdMap; use pocketmine\data\bedrock\item\ItemTypeNames; use pocketmine\data\bedrock\item\SavedItemData; @@ -162,7 +160,7 @@ public function areFormsEnabled(): bool private static function registerItemsAndBlocks(): void { self::registerItem(ItemTypeNames::ENCHANTED_BOOK, EnchantedBook::ENCHANTED_BOOK(), ["enchanted_book"]); - self::registerBlock(BlockTypeNames::OBSIDIAN, PiggyObsidian::PIGGY_OBSIDIAN(), ["piggy_obsidian"]); +// self::registerBlock(BlockTypeNames::OBSIDIAN, PiggyObsidian::PIGGY_OBSIDIAN(), ["piggy_obsidian"]); } /** diff --git a/src/DaPigGuy/PiggyCustomEnchants/commands/CustomEnchantsCommand.php b/src/DaPigGuy/PiggyCustomEnchants/commands/CustomEnchantsCommand.php index a9b48fcd..00855c43 100644 --- a/src/DaPigGuy/PiggyCustomEnchants/commands/CustomEnchantsCommand.php +++ b/src/DaPigGuy/PiggyCustomEnchants/commands/CustomEnchantsCommand.php @@ -44,6 +44,8 @@ public function onRun(CommandSender $sender, string $aliasUsed, array $args): vo public function prepare(): void { + $this->setPermission("piggycustomenchants.command.ce"); + $this->registerSubCommand(new AboutSubCommand($this->plugin, "about", "Displays basic information about the plugin")); $this->registerSubCommand(new EnchantSubCommand($this->plugin, "enchant", "Apply an enchantment on an item")); $this->registerSubCommand(new InfoSubCommand($this->plugin, "info", "Get info on a custom enchant")); diff --git a/src/DaPigGuy/PiggyCustomEnchants/commands/subcommands/InfoSubCommand.php b/src/DaPigGuy/PiggyCustomEnchants/commands/subcommands/InfoSubCommand.php index 36473744..937bbf88 100644 --- a/src/DaPigGuy/PiggyCustomEnchants/commands/subcommands/InfoSubCommand.php +++ b/src/DaPigGuy/PiggyCustomEnchants/commands/subcommands/InfoSubCommand.php @@ -77,7 +77,7 @@ public function showInfo(Player $player, CustomEnchant $enchantment): void */ public function prepare(): void { - $this->setPermission("piggycustomenchants.command.ce.list"); + $this->setPermission("piggycustomenchants.command.ce.info"); $this->registerArgument(0, new RawStringArgument("enchantment", true)); } } \ No newline at end of file From 5c16145b89ebdeed0584c58408a81550e56566a9 Mon Sep 17 00:00:00 2001 From: aericio <16523741+Aericio@users.noreply.github.com> Date: Sun, 16 Jul 2023 20:20:13 -1000 Subject: [PATCH 11/23] Fix accessing inventory before initialization --- .../PiggyCustomEnchants/enchants/traits/ReactiveTrait.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/DaPigGuy/PiggyCustomEnchants/enchants/traits/ReactiveTrait.php b/src/DaPigGuy/PiggyCustomEnchants/enchants/traits/ReactiveTrait.php index dab8a2fc..b7fff41d 100644 --- a/src/DaPigGuy/PiggyCustomEnchants/enchants/traits/ReactiveTrait.php +++ b/src/DaPigGuy/PiggyCustomEnchants/enchants/traits/ReactiveTrait.php @@ -94,7 +94,7 @@ public function shouldReactToDamaged(): bool public static function attemptReaction(Player $player, Event $event): void { - if ($player->getInventory() === null) return; + if (!$player->spawned) return; if ($event instanceof EntityDamageByChildEntityEvent || $event instanceof ProjectileHitBlockEvent) { $projectile = $event instanceof EntityDamageByEntityEvent ? $event->getChild() : $event->getEntity(); if ($projectile instanceof Projectile && ProjectileTracker::isTrackedProjectile($projectile)) { From ed42ee1fcfb65e75121834d8ad0a5a74ad3b7b79 Mon Sep 17 00:00:00 2001 From: aericio <16523741+Aericio@users.noreply.github.com> Date: Sun, 16 Jul 2023 20:38:07 -1000 Subject: [PATCH 12/23] Add missing not operator --- .../enchants/tools/axes/LumberjackEnchant.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/DaPigGuy/PiggyCustomEnchants/enchants/tools/axes/LumberjackEnchant.php b/src/DaPigGuy/PiggyCustomEnchants/enchants/tools/axes/LumberjackEnchant.php index 3ab598b5..b506c782 100644 --- a/src/DaPigGuy/PiggyCustomEnchants/enchants/tools/axes/LumberjackEnchant.php +++ b/src/DaPigGuy/PiggyCustomEnchants/enchants/tools/axes/LumberjackEnchant.php @@ -51,7 +51,7 @@ public function breakTree(Block $block, Player $player, int $mined = 0): void for ($i = 0; $i <= 5; $i++) { if ($mined > $this->extraData["limit"]) break; $side = $block->getSide($i); - if (in_array($side, self::LOG_TYPES)) continue; + if (!in_array($side->getTypeId(), self::LOG_TYPES)) continue; $player->getWorld()->useBreakOn($side->getPosition(), $item, $player); $mined++; $this->breakTree($side, $player, $mined); From e7615dc4bfa9cc655209fe9f99bf3d855a84977a Mon Sep 17 00:00:00 2001 From: aericio <16523741+Aericio@users.noreply.github.com> Date: Sun, 16 Jul 2023 20:39:11 -1000 Subject: [PATCH 13/23] Fix packet error crash from incorrect max stack size --- .../PiggyCustomEnchants/items/EnchantedBook.php | 2 +- .../PiggyCustomEnchants/items/EnchantedBookItem.php | 13 +++++++++++++ 2 files changed, 14 insertions(+), 1 deletion(-) create mode 100644 src/DaPigGuy/PiggyCustomEnchants/items/EnchantedBookItem.php diff --git a/src/DaPigGuy/PiggyCustomEnchants/items/EnchantedBook.php b/src/DaPigGuy/PiggyCustomEnchants/items/EnchantedBook.php index cb962a98..6791dee4 100644 --- a/src/DaPigGuy/PiggyCustomEnchants/items/EnchantedBook.php +++ b/src/DaPigGuy/PiggyCustomEnchants/items/EnchantedBook.php @@ -39,6 +39,6 @@ public static function getAll(): array protected static function setup(): void { - self::register("enchanted_book", new Item(new ItemIdentifier(ItemTypeIds::newId()), "Enchanted Book")); + self::register("enchanted_book", new EnchantedBookItem(new ItemIdentifier(ItemTypeIds::newId()), "Enchanted Book")); } } \ No newline at end of file diff --git a/src/DaPigGuy/PiggyCustomEnchants/items/EnchantedBookItem.php b/src/DaPigGuy/PiggyCustomEnchants/items/EnchantedBookItem.php new file mode 100644 index 00000000..0ad762a0 --- /dev/null +++ b/src/DaPigGuy/PiggyCustomEnchants/items/EnchantedBookItem.php @@ -0,0 +1,13 @@ + Date: Sun, 16 Jul 2023 21:22:51 -1000 Subject: [PATCH 14/23] Fix wrong method call for damage calc --- .../enchants/miscellaneous/AutoRepairEnchant.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/DaPigGuy/PiggyCustomEnchants/enchants/miscellaneous/AutoRepairEnchant.php b/src/DaPigGuy/PiggyCustomEnchants/enchants/miscellaneous/AutoRepairEnchant.php index c74993a1..909904e4 100644 --- a/src/DaPigGuy/PiggyCustomEnchants/enchants/miscellaneous/AutoRepairEnchant.php +++ b/src/DaPigGuy/PiggyCustomEnchants/enchants/miscellaneous/AutoRepairEnchant.php @@ -35,7 +35,7 @@ public function getDefaultExtraData(): array public function react(Player $player, Item $item, Inventory $inventory, int $slot, Event $event, int $level, int $stack): void { if (!$item instanceof Durable || $item->getStateId() === 0) return; - $newDir = $item->getStateId() - ((int)$this->extraData["baseRepair"] + ((int)$this->extraData["repairMultiplier"] * $level)); + $newDir = $item->getDamage() - ((int)$this->extraData["baseRepair"] + ((int)$this->extraData["repairMultiplier"] * $level)); if ($newDir < 0) { $item->setDamage(0); } else { From 185c3f2fad40e7572fcbfcc48c69d78ee58d5248 Mon Sep 17 00:00:00 2001 From: aericio <16523741+Aericio@users.noreply.github.com> Date: Sun, 16 Jul 2023 21:28:05 -1000 Subject: [PATCH 15/23] Remove unnecessary phpstan ignore --- phpstan.neon.dist | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/phpstan.neon.dist b/phpstan.neon.dist index fff547f4..71bb7bb7 100644 --- a/phpstan.neon.dist +++ b/phpstan.neon.dist @@ -11,6 +11,4 @@ parameters: excludePaths: analyse: - source/vendor - checkMissingIterableValueType: false - ignoreErrors: - - "#Strict comparison using === between pocketmine\\\\inventory\\\\PlayerInventory and null will always evaluate to false.#" \ No newline at end of file + checkMissingIterableValueType: false \ No newline at end of file From e88a082cddb6d358c597cd51997dc10feb51a874 Mon Sep 17 00:00:00 2001 From: Aericio <16523741+Aericio@users.noreply.github.com> Date: Mon, 17 Jul 2023 11:37:18 -1000 Subject: [PATCH 16/23] Apply bug fixes from code review Co-authored-by: DaPigGuy --- src/DaPigGuy/PiggyCustomEnchants/EventListener.php | 4 ++-- .../enchants/miscellaneous/AutoRepairEnchant.php | 2 +- .../enchants/weapons/HallucinationEnchant.php | 4 +--- src/DaPigGuy/PiggyCustomEnchants/entities/PiggyFireball.php | 1 - .../PiggyCustomEnchants/entities/PiggyWitherSkull.php | 1 - 5 files changed, 4 insertions(+), 8 deletions(-) diff --git a/src/DaPigGuy/PiggyCustomEnchants/EventListener.php b/src/DaPigGuy/PiggyCustomEnchants/EventListener.php index 01a8dafe..03e967a5 100644 --- a/src/DaPigGuy/PiggyCustomEnchants/EventListener.php +++ b/src/DaPigGuy/PiggyCustomEnchants/EventListener.php @@ -209,8 +209,8 @@ public function onJoin(PlayerJoinEvent $event): void $holder = $inventory->getHolder(); if ($holder instanceof Player) { if (!$oldItem->equals(($newItem = $inventory->getItem($slot)), !$inventory instanceof ArmorInventory)) { - if ($newItem->getStateId() === BlockTypeIds::AIR || $inventory instanceof ArmorInventory) foreach ($oldItem->getEnchantments() as $oldEnchantment) ToggleableEnchantment::attemptToggle($holder, $oldItem, $oldEnchantment, $inventory, $slot, false); - if ($oldItem->getStateId() === BlockTypeIds::AIR || $inventory instanceof ArmorInventory) foreach ($newItem->getEnchantments() as $newEnchantment) ToggleableEnchantment::attemptToggle($holder, $newItem, $newEnchantment, $inventory, $slot); + if ($newItem->getTypeId() === BlockTypeIds::AIR || $inventory instanceof ArmorInventory) foreach ($oldItem->getEnchantments() as $oldEnchantment) ToggleableEnchantment::attemptToggle($holder, $oldItem, $oldEnchantment, $inventory, $slot, false); + if ($oldItem->getTypeId() === BlockTypeIds::AIR || $inventory instanceof ArmorInventory) foreach ($newItem->getEnchantments() as $newEnchantment) ToggleableEnchantment::attemptToggle($holder, $newItem, $newEnchantment, $inventory, $slot); } } } diff --git a/src/DaPigGuy/PiggyCustomEnchants/enchants/miscellaneous/AutoRepairEnchant.php b/src/DaPigGuy/PiggyCustomEnchants/enchants/miscellaneous/AutoRepairEnchant.php index 909904e4..5ffb1c7d 100644 --- a/src/DaPigGuy/PiggyCustomEnchants/enchants/miscellaneous/AutoRepairEnchant.php +++ b/src/DaPigGuy/PiggyCustomEnchants/enchants/miscellaneous/AutoRepairEnchant.php @@ -34,7 +34,7 @@ public function getDefaultExtraData(): array public function react(Player $player, Item $item, Inventory $inventory, int $slot, Event $event, int $level, int $stack): void { - if (!$item instanceof Durable || $item->getStateId() === 0) return; + if (!$item instanceof Durable || $item->getDamage() === 0) return; $newDir = $item->getDamage() - ((int)$this->extraData["baseRepair"] + ((int)$this->extraData["repairMultiplier"] * $level)); if ($newDir < 0) { $item->setDamage(0); diff --git a/src/DaPigGuy/PiggyCustomEnchants/enchants/weapons/HallucinationEnchant.php b/src/DaPigGuy/PiggyCustomEnchants/enchants/weapons/HallucinationEnchant.php index ad02dbf3..c1a9abc0 100644 --- a/src/DaPigGuy/PiggyCustomEnchants/enchants/weapons/HallucinationEnchant.php +++ b/src/DaPigGuy/PiggyCustomEnchants/enchants/weapons/HallucinationEnchant.php @@ -52,9 +52,7 @@ public function react(Player $player, Item $item, Inventory $inventory, int $slo $block = VanillaBlocks::BEDROCK(); if ($position->equals($originalPosition)) $block = VanillaBlocks::LAVA(); if ($position->equals($originalPosition->add(0, 1, 0))) { - // TODO: I have no idea what meta 2 means. - // BlockFactory::getInstance()->get(BlockLegacyIds::WALL_SIGN, 2); - $block = VanillaBlocks::OAK_SIGN(); + $block = VanillaBlocks::OAK_WALL_SIGN(); if ($this->nbtWriter === null) $this->nbtWriter = new NetworkNbtSerializer(); $packets[] = BlockActorDataPacket::create(BlockPosition::fromVector3($position->floor()), new CacheableNbt( CompoundTag::create()-> diff --git a/src/DaPigGuy/PiggyCustomEnchants/entities/PiggyFireball.php b/src/DaPigGuy/PiggyCustomEnchants/entities/PiggyFireball.php index 7318c9ca..ddde3224 100644 --- a/src/DaPigGuy/PiggyCustomEnchants/entities/PiggyFireball.php +++ b/src/DaPigGuy/PiggyCustomEnchants/entities/PiggyFireball.php @@ -16,7 +16,6 @@ class PiggyFireball extends PiggyProjectile { - /** @var float */ protected float $damage = 5; public function onHitEntity(Entity $entityHit, RayTraceResult $hitResult): void diff --git a/src/DaPigGuy/PiggyCustomEnchants/entities/PiggyWitherSkull.php b/src/DaPigGuy/PiggyCustomEnchants/entities/PiggyWitherSkull.php index fa03503b..2135426a 100644 --- a/src/DaPigGuy/PiggyCustomEnchants/entities/PiggyWitherSkull.php +++ b/src/DaPigGuy/PiggyCustomEnchants/entities/PiggyWitherSkull.php @@ -16,7 +16,6 @@ class PiggyWitherSkull extends PiggyProjectile { - /** @var float */ protected float $damage = 0; public function onHitEntity(Entity $entityHit, RayTraceResult $hitResult): void From 60cde4bbc6e02480e29592f4843ef5e5f1cbf035 Mon Sep 17 00:00:00 2001 From: aericio <16523741+Aericio@users.noreply.github.com> Date: Thu, 28 Sep 2023 15:16:59 -1000 Subject: [PATCH 17/23] Use Customies for enchant book / magmawalker obsidian --- .github/workflows/main.yml | 1 + README.md | 7 +-- plugin.yml | 1 + .../PiggyCustomEnchants/EventListener.php | 8 +-- .../PiggyCustomEnchants.php | 52 +++++-------------- ...yObsidian.php => CustomBlocksRegistry.php} | 12 ++--- .../blocks/PiggyObsidianBlock.php | 2 +- .../subcommands/EnchantSubCommand.php | 6 +-- .../armor/boots/MagmaWalkerEnchant.php | 10 ++-- ...hantedBook.php => CustomItemsRegistry.php} | 10 ++-- .../items/EnchantedBookItem.php | 13 ----- .../items/PiggyEnchantedBookItem.php | 24 +++++++++ .../tasks/TickEnchantmentsTask.php | 4 +- .../PiggyCustomEnchants/utils/Utils.php | 4 +- 14 files changed, 72 insertions(+), 82 deletions(-) rename src/DaPigGuy/PiggyCustomEnchants/blocks/{PiggyObsidian.php => CustomBlocksRegistry.php} (62%) rename src/DaPigGuy/PiggyCustomEnchants/items/{EnchantedBook.php => CustomItemsRegistry.php} (69%) delete mode 100644 src/DaPigGuy/PiggyCustomEnchants/items/EnchantedBookItem.php create mode 100644 src/DaPigGuy/PiggyCustomEnchants/items/PiggyEnchantedBookItem.php diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index b8e7e74c..f4e6c67a 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -16,6 +16,7 @@ jobs: wget -O vendor/FormsUI.phar https://poggit.pmmp.io/r/209836/FormsUI_dev-20.phar wget -O vendor/Commando.phar https://poggit.pmmp.io/r/216831/Commando_dev-34.phar wget -O vendor/libPiggyUpdateChecker.phar https://poggit.pmmp.io/r/211732/libPiggyUpdateChecker_dev-2.phar + wget -O vendor/Customies.phar https://poggit.pmmp.io/r/216154/Customies.phar - name: Run PHPStan uses: paroxity/pmmp-phpstan-action@5.3.0 with: diff --git a/README.md b/README.md index cff0c2fb..74b52fa5 100644 --- a/README.md +++ b/README.md @@ -1,4 +1,4 @@ -# PiggyCustomEnchants [![Poggit-CI](https://poggit.pmmp.io/shield.dl/PiggyCustomEnchants)](https://poggit.pmmp.io/p/PiggyCustomEnchants) [![Discord](https://img.shields.io/discord/330850307607363585?logo=discord)](https://discord.gg/qmnDsSD) +# PiggyCustomEnchants [![Poggit-CI](https://poggit.pmmp.io/shield.dl.total/PiggyCustomEnchants)](https://poggit.pmmp.io/p/PiggyCustomEnchants) [![Discord](https://img.shields.io/discord/330850307607363585?logo=discord)](https://discord.gg/qmnDsSD) PiggyCustomEnchants is an open-sourced custom enchants plugin for [PocketMine-MP](https://github.com/pmmp/PocketMine-MP) featuring over 90 custom enchantments. @@ -13,7 +13,8 @@ PiggyCustomEnchants is an open-sourced custom enchants plugin for [PocketMine-MP ## Installation & Setup 1. Install the plugin from Poggit. -2. (Optional) Configure your PiggyCE +2. Install [Customies](https://poggit.pmmp.io/p/Customies) from Poggit. +3. (Optional) Configure your PiggyCE * Enchantment rarities, max levels, names, descriptions, & chances can be configured in their respective JSON files. * `chances.json`: Allows custom chance multipliers for any reactive enchantments. * Reaction chances are calculated by `chance multiplier * enchantment level`. @@ -39,7 +40,7 @@ PiggyCustomEnchants is an open-sourced custom enchants plugin for [PocketMine-MP - Jetpack ``` * `world-damage`: Toggles world damage for explosive enchantments -3. (Optional) Install additional plugins supporting PiggyCE: +4. (Optional) Install additional plugins supporting PiggyCE: * [PiggyCrates](https://poggit.pmmp.io/p/PiggyCrates) (Official) * [PiggyCustomEnchantsShop](https://poggit.pmmp.io/p/PiggyCustomEnchantsShop) (Official) * [PCEAllyChecks](https://poggit.pmmp.io/p/PCEAllyChecks) (Official) diff --git a/plugin.yml b/plugin.yml index 6119d8c2..f5003715 100644 --- a/plugin.yml +++ b/plugin.yml @@ -5,6 +5,7 @@ api: 5.3.0 load: POSTWORLD author: DaPigGuy website: "https://github.com/DaPigGuy/PiggyCustomEnchants/" +depend: ["Customies"] permissions: piggycustomenchants: default: false diff --git a/src/DaPigGuy/PiggyCustomEnchants/EventListener.php b/src/DaPigGuy/PiggyCustomEnchants/EventListener.php index 03e967a5..232df957 100644 --- a/src/DaPigGuy/PiggyCustomEnchants/EventListener.php +++ b/src/DaPigGuy/PiggyCustomEnchants/EventListener.php @@ -11,7 +11,7 @@ use DaPigGuy\PiggyCustomEnchants\enchants\tools\DrillerEnchant; use DaPigGuy\PiggyCustomEnchants\entities\BombardmentTNT; use DaPigGuy\PiggyCustomEnchants\entities\PiggyTNT; -use DaPigGuy\PiggyCustomEnchants\items\EnchantedBook; +use DaPigGuy\PiggyCustomEnchants\items\CustomItemsRegistry; use DaPigGuy\PiggyCustomEnchants\utils\ProjectileTracker; use DaPigGuy\PiggyCustomEnchants\utils\Utils; use pocketmine\block\BlockTypeIds; @@ -304,9 +304,9 @@ public function onTransaction(InventoryTransactionEvent $event): void if (count($actions) === 2) { foreach ($actions as $i => $action) { if ($action instanceof SlotChangeAction && ($otherAction = $actions[($i + 1) % 2]) instanceof SlotChangeAction && - ($itemClickedWith = $action->getTargetItem())->getTypeId() === EnchantedBook::ENCHANTED_BOOK()->getTypeId() && + ($itemClickedWith = $action->getTargetItem())->getTypeId() === CustomItemsRegistry::ENCHANTED_BOOK()->getTypeId() && ($itemClicked = $action->getSourceItem())->getTypeId() !== BlockTypeIds::AIR && - ($itemClicked->getTypeId() !== EnchantedBook::ENCHANTED_BOOK()->getTypeId() || count($itemClicked->getEnchantments()) >= count($itemClickedWith->getEnchantments()))) { + ($itemClicked->getTypeId() !== CustomItemsRegistry::ENCHANTED_BOOK()->getTypeId() || count($itemClicked->getEnchantments()) >= count($itemClickedWith->getEnchantments()))) { if (count($itemClickedWith->getEnchantments()) < 1) return; $enchantmentSuccessful = false; foreach ($itemClickedWith->getEnchantments() as $enchantment) { @@ -328,7 +328,7 @@ public function onTransaction(InventoryTransactionEvent $event): void ) || $itemClicked->getCount() !== 1 || $newLevel > $enchantmentType->getMaxLevel() || - ($itemClicked->getTypeId() === EnchantedBook::ENCHANTED_BOOK()->getTypeId() && count($itemClicked->getEnchantments()) === 0) || + ($itemClicked->getTypeId() === CustomItemsRegistry::ENCHANTED_BOOK()->getTypeId() && count($itemClicked->getEnchantments()) === 0) || $itemClicked->getTypeId() === ItemTypeIds::BOOK ) continue; $itemClicked->addEnchantment(new EnchantmentInstance($enchantmentType, $newLevel)); diff --git a/src/DaPigGuy/PiggyCustomEnchants/PiggyCustomEnchants.php b/src/DaPigGuy/PiggyCustomEnchants/PiggyCustomEnchants.php index 6d8d88a2..e272b929 100644 --- a/src/DaPigGuy/PiggyCustomEnchants/PiggyCustomEnchants.php +++ b/src/DaPigGuy/PiggyCustomEnchants/PiggyCustomEnchants.php @@ -6,7 +6,10 @@ use CortexPE\Commando\BaseCommand; use CortexPE\Commando\PacketHooker; +use customiesdevs\customies\block\CustomiesBlockFactory; +use customiesdevs\customies\item\CustomiesItemFactory; use DaPigGuy\libPiggyUpdateChecker\libPiggyUpdateChecker; +use DaPigGuy\PiggyCustomEnchants\blocks\PiggyObsidianBlock; use DaPigGuy\PiggyCustomEnchants\commands\CustomEnchantsCommand; use DaPigGuy\PiggyCustomEnchants\enchants\CustomEnchant; use DaPigGuy\PiggyCustomEnchants\enchants\ToggleableEnchantment; @@ -17,25 +20,21 @@ use DaPigGuy\PiggyCustomEnchants\entities\PiggyTNT; use DaPigGuy\PiggyCustomEnchants\entities\PiggyWitherSkull; use DaPigGuy\PiggyCustomEnchants\entities\PigProjectile; -use DaPigGuy\PiggyCustomEnchants\items\EnchantedBook; +use DaPigGuy\PiggyCustomEnchants\items\PiggyEnchantedBookItem; use DaPigGuy\PiggyCustomEnchants\tasks\CheckDisabledEnchantsTask; use DaPigGuy\PiggyCustomEnchants\tasks\TickEnchantmentsTask; -use pocketmine\block\Block; -use pocketmine\block\RuntimeBlockStateRegistry; +use pocketmine\block\BlockBreakInfo; +use pocketmine\block\BlockIdentifier; +use pocketmine\block\BlockTypeIds; +use pocketmine\block\BlockTypeInfo; use pocketmine\color\Color; use pocketmine\data\bedrock\EffectIdMap; -use pocketmine\data\bedrock\item\ItemTypeNames; -use pocketmine\data\bedrock\item\SavedItemData; use pocketmine\entity\effect\Effect; use pocketmine\entity\EntityDataHelper; use pocketmine\entity\EntityFactory; -use pocketmine\item\Item; -use pocketmine\item\StringToItemParser; use pocketmine\nbt\tag\CompoundTag; use pocketmine\plugin\PluginBase; use pocketmine\utils\Config; -use pocketmine\world\format\io\GlobalBlockStateHandlers; -use pocketmine\world\format\io\GlobalItemDataHandlers; use pocketmine\world\World; use Vecnavium\FormsUI\Form; @@ -159,35 +158,10 @@ public function areFormsEnabled(): bool private static function registerItemsAndBlocks(): void { - self::registerItem(ItemTypeNames::ENCHANTED_BOOK, EnchantedBook::ENCHANTED_BOOK(), ["enchanted_book"]); -// self::registerBlock(BlockTypeNames::OBSIDIAN, PiggyObsidian::PIGGY_OBSIDIAN(), ["piggy_obsidian"]); - } - - /** - * @param string[] $stringToItemParserNames - */ - private static function registerBlock(string $id, Block $block, array $stringToItemParserNames): void - { - RuntimeBlockStateRegistry::getInstance()->register($block); - - GlobalBlockStateHandlers::getDeserializer()->mapSimple($id, fn() => clone $block); - GlobalBlockStateHandlers::getSerializer()->mapSimple($block, $id); - - foreach ($stringToItemParserNames as $name) { - StringToItemParser::getInstance()->registerBlock($name, fn() => clone $block); - } - } - - /** - * @param string[] $stringToItemParserNames - */ - private static function registerItem(string $id, Item $item, array $stringToItemParserNames): void - { - GlobalItemDataHandlers::getDeserializer()->map($id, fn() => clone $item); - GlobalItemDataHandlers::getSerializer()->map($item, fn() => new SavedItemData($id)); - - foreach ($stringToItemParserNames as $name) { - StringToItemParser::getInstance()->register($name, fn() => clone $item); - } + CustomiesItemFactory::getInstance()->registerItem(PiggyEnchantedBookItem::class, "piggyce:enchanted_book", "Enchanted Book"); + CustomiesBlockFactory::getInstance()->registerBlock( + static fn() => new PiggyObsidianBlock(new BlockIdentifier(BlockTypeIds::newId()), "Magmawalker Obsidian", new BlockTypeInfo(BlockBreakInfo::instant())), + "piggyce:magmawalker_obsidian", + ); } } \ No newline at end of file diff --git a/src/DaPigGuy/PiggyCustomEnchants/blocks/PiggyObsidian.php b/src/DaPigGuy/PiggyCustomEnchants/blocks/CustomBlocksRegistry.php similarity index 62% rename from src/DaPigGuy/PiggyCustomEnchants/blocks/PiggyObsidian.php rename to src/DaPigGuy/PiggyCustomEnchants/blocks/CustomBlocksRegistry.php index 1e58c049..81ec84e8 100644 --- a/src/DaPigGuy/PiggyCustomEnchants/blocks/PiggyObsidian.php +++ b/src/DaPigGuy/PiggyCustomEnchants/blocks/CustomBlocksRegistry.php @@ -2,17 +2,14 @@ namespace DaPigGuy\PiggyCustomEnchants\blocks; +use customiesdevs\customies\block\CustomiesBlockFactory; use pocketmine\block\Block; -use pocketmine\block\BlockBreakInfo; -use pocketmine\block\BlockIdentifier; -use pocketmine\block\BlockTypeIds; -use pocketmine\block\BlockTypeInfo; use pocketmine\utils\CloningRegistryTrait; /** - * @method static PiggyObsidianBlock PIGGY_OBSIDIAN() + * @method static PiggyObsidianBlock OBSIDIAN() */ -final class PiggyObsidian +final class CustomBlocksRegistry { use CloningRegistryTrait; @@ -39,6 +36,7 @@ public static function getAll(): array protected static function setup(): void { - self::register("piggy_obsidian", new PiggyObsidianBlock(new BlockIdentifier(BlockTypeIds::newId()), "Magmawalker Obsidian", new BlockTypeInfo(BlockBreakInfo::instant()))); + $blockFactory = CustomiesBlockFactory::getInstance(); + self::register("obsidian", $blockFactory->get("piggyce:magmawalker_obsidian")); } } diff --git a/src/DaPigGuy/PiggyCustomEnchants/blocks/PiggyObsidianBlock.php b/src/DaPigGuy/PiggyCustomEnchants/blocks/PiggyObsidianBlock.php index 1dd6ef4d..3291c21f 100644 --- a/src/DaPigGuy/PiggyCustomEnchants/blocks/PiggyObsidianBlock.php +++ b/src/DaPigGuy/PiggyCustomEnchants/blocks/PiggyObsidianBlock.php @@ -7,7 +7,7 @@ use pocketmine\item\Item; use pocketmine\player\Player; -class PiggyObsidianBlock extends Opaque +final class PiggyObsidianBlock extends Opaque { private int $age = 0; diff --git a/src/DaPigGuy/PiggyCustomEnchants/commands/subcommands/EnchantSubCommand.php b/src/DaPigGuy/PiggyCustomEnchants/commands/subcommands/EnchantSubCommand.php index fe320887..8cad22d3 100644 --- a/src/DaPigGuy/PiggyCustomEnchants/commands/subcommands/EnchantSubCommand.php +++ b/src/DaPigGuy/PiggyCustomEnchants/commands/subcommands/EnchantSubCommand.php @@ -9,7 +9,7 @@ use CortexPE\Commando\BaseSubCommand; use CortexPE\Commando\exception\ArgumentOrderException; use DaPigGuy\PiggyCustomEnchants\CustomEnchantManager; -use DaPigGuy\PiggyCustomEnchants\items\EnchantedBook; +use DaPigGuy\PiggyCustomEnchants\items\CustomItemsRegistry; use DaPigGuy\PiggyCustomEnchants\PiggyCustomEnchants; use DaPigGuy\PiggyCustomEnchants\utils\Utils; use pocketmine\command\CommandSender; @@ -69,7 +69,7 @@ public function onRun(CommandSender $sender, string $aliasUsed, array $args): vo return; } } - if ($item->getTypeId() === EnchantedBook::ENCHANTED_BOOK()->getTypeId() || $item->getTypeId() === ItemTypeIds::BOOK) { + if ($item->getTypeId() === CustomItemsRegistry::ENCHANTED_BOOK()->getTypeId() || $item->getTypeId() === ItemTypeIds::BOOK) { $item->getNamedTag()->setString("PiggyCEBookUUID", Uuid::uuid4()->toString()); } $item->addEnchantment(new EnchantmentInstance($enchant, $args["level"])); @@ -115,7 +115,7 @@ public function onRunForm(CommandSender $sender, string $aliasUsed, array $args) return; } } - if ($item->getTypeId() === EnchantedBook::ENCHANTED_BOOK()->getTypeId() || $item->getTypeId() === ItemTypeIds::BOOK) { + if ($item->getTypeId() === CustomItemsRegistry::ENCHANTED_BOOK()->getTypeId() || $item->getTypeId() === ItemTypeIds::BOOK) { $item->getNamedTag()->setString("PiggyCEBookUUID", Uuid::uuid4()->toString()); } $item->addEnchantment(new EnchantmentInstance($enchant, (int)$data[1])); diff --git a/src/DaPigGuy/PiggyCustomEnchants/enchants/armor/boots/MagmaWalkerEnchant.php b/src/DaPigGuy/PiggyCustomEnchants/enchants/armor/boots/MagmaWalkerEnchant.php index 32ce4302..3f79be77 100644 --- a/src/DaPigGuy/PiggyCustomEnchants/enchants/armor/boots/MagmaWalkerEnchant.php +++ b/src/DaPigGuy/PiggyCustomEnchants/enchants/armor/boots/MagmaWalkerEnchant.php @@ -4,10 +4,14 @@ namespace DaPigGuy\PiggyCustomEnchants\enchants\armor\boots; -use DaPigGuy\PiggyCustomEnchants\blocks\PiggyObsidian; +use DaPigGuy\PiggyCustomEnchants\blocks\CustomBlocksRegistry; use DaPigGuy\PiggyCustomEnchants\enchants\CustomEnchant; use DaPigGuy\PiggyCustomEnchants\enchants\ReactiveEnchantment; +use pocketmine\block\Block; +use pocketmine\block\BlockBreakInfo; +use pocketmine\block\BlockIdentifier; use pocketmine\block\BlockTypeIds; +use pocketmine\block\BlockTypeInfo; use pocketmine\block\Lava; use pocketmine\event\Event; use pocketmine\event\player\PlayerMoveEvent; @@ -45,8 +49,8 @@ public function react(Player $player, Item $item, Inventory $inventory, int $slo for ($z = -$radius; $z <= $radius; $z++) { $b = $world->getBlock($player->getPosition()->add($x, -1, $z)); if ($world->getBlock($b->getPosition()->add(0, 1, 0))->getTypeId() === BlockTypeIds::AIR) { - if ($b instanceof Lava && $b->getStateId() === 0) { - $world->setBlock($b->getPosition()->asVector3(), PiggyObsidian::PIGGY_OBSIDIAN()); + if ($b instanceof Lava && $b->isSource()) { + $world->setBlock($b->getPosition()->asVector3(), CustomBlocksRegistry::OBSIDIAN()); } } } diff --git a/src/DaPigGuy/PiggyCustomEnchants/items/EnchantedBook.php b/src/DaPigGuy/PiggyCustomEnchants/items/CustomItemsRegistry.php similarity index 69% rename from src/DaPigGuy/PiggyCustomEnchants/items/EnchantedBook.php rename to src/DaPigGuy/PiggyCustomEnchants/items/CustomItemsRegistry.php index 6791dee4..75b29467 100644 --- a/src/DaPigGuy/PiggyCustomEnchants/items/EnchantedBook.php +++ b/src/DaPigGuy/PiggyCustomEnchants/items/CustomItemsRegistry.php @@ -4,15 +4,14 @@ namespace DaPigGuy\PiggyCustomEnchants\items; +use customiesdevs\customies\item\CustomiesItemFactory; use pocketmine\item\Item; -use pocketmine\item\ItemIdentifier; -use pocketmine\item\ItemTypeIds; use pocketmine\utils\CloningRegistryTrait; /** - * @method static Item ENCHANTED_BOOK() + * @method static PiggyEnchantedBookItem ENCHANTED_BOOK() */ -final class EnchantedBook +final class CustomItemsRegistry { use CloningRegistryTrait; @@ -39,6 +38,7 @@ public static function getAll(): array protected static function setup(): void { - self::register("enchanted_book", new EnchantedBookItem(new ItemIdentifier(ItemTypeIds::newId()), "Enchanted Book")); + $itemFactory = CustomiesItemFactory::getInstance(); + self::register("enchanted_book", $itemFactory->get("piggyce:enchanted_book")); } } \ No newline at end of file diff --git a/src/DaPigGuy/PiggyCustomEnchants/items/EnchantedBookItem.php b/src/DaPigGuy/PiggyCustomEnchants/items/EnchantedBookItem.php deleted file mode 100644 index 0ad762a0..00000000 --- a/src/DaPigGuy/PiggyCustomEnchants/items/EnchantedBookItem.php +++ /dev/null @@ -1,13 +0,0 @@ -initComponent("enchanted_book"); + } + + public function getMaxStackSize(): int + { + return 1; + } +} \ No newline at end of file diff --git a/src/DaPigGuy/PiggyCustomEnchants/tasks/TickEnchantmentsTask.php b/src/DaPigGuy/PiggyCustomEnchants/tasks/TickEnchantmentsTask.php index e017f155..e5a3b8cc 100644 --- a/src/DaPigGuy/PiggyCustomEnchants/tasks/TickEnchantmentsTask.php +++ b/src/DaPigGuy/PiggyCustomEnchants/tasks/TickEnchantmentsTask.php @@ -6,7 +6,7 @@ use DaPigGuy\PiggyCustomEnchants\enchants\CustomEnchant; use DaPigGuy\PiggyCustomEnchants\enchants\TickingEnchantment; -use DaPigGuy\PiggyCustomEnchants\items\EnchantedBook; +use DaPigGuy\PiggyCustomEnchants\items\CustomItemsRegistry; use DaPigGuy\PiggyCustomEnchants\PiggyCustomEnchants; use DaPigGuy\PiggyCustomEnchants\utils\Utils; use pocketmine\item\Item; @@ -29,7 +29,7 @@ public function onRun(): void foreach ($player->getInventory()->getContents() as $slot => $content) { if ($content->getTypeId() === ItemTypeIds::BOOK) { if (count($content->getEnchantments()) > 0) { - $enchantedBook = EnchantedBook::ENCHANTED_BOOK()->setNamedTag($content->getNamedTag())->setCount($content->getCount()); + $enchantedBook = CustomItemsRegistry::ENCHANTED_BOOK()->setNamedTag($content->getNamedTag())->setCount($content->getCount()); $enchantedBook->setCustomName(TextFormat::RESET . TextFormat::YELLOW . "Enchanted Book" . TextFormat::RESET); $enchantedBook->addEnchantment(...$content->getEnchantments()); $player->getInventory()->setItem($slot, $enchantedBook); diff --git a/src/DaPigGuy/PiggyCustomEnchants/utils/Utils.php b/src/DaPigGuy/PiggyCustomEnchants/utils/Utils.php index 323c7b41..2e7b694d 100644 --- a/src/DaPigGuy/PiggyCustomEnchants/utils/Utils.php +++ b/src/DaPigGuy/PiggyCustomEnchants/utils/Utils.php @@ -11,7 +11,7 @@ use DaPigGuy\PiggyCustomEnchants\entities\PiggyFireball; use DaPigGuy\PiggyCustomEnchants\entities\PiggyWitherSkull; use DaPigGuy\PiggyCustomEnchants\entities\PigProjectile; -use DaPigGuy\PiggyCustomEnchants\items\EnchantedBook; +use DaPigGuy\PiggyCustomEnchants\items\CustomItemsRegistry; use InvalidArgumentException; use pocketmine\entity\Location; use pocketmine\entity\projectile\Arrow; @@ -130,7 +130,7 @@ public static function isBoots(Item $item): bool public static function itemMatchesItemType(Item $item, int $itemType): bool { - if ($item->getTypeId() === ItemTypeIds::BOOK || $item->getTypeId() === EnchantedBook::ENCHANTED_BOOK()->getTypeId()) return true; + if ($item->getTypeId() === ItemTypeIds::BOOK || $item->getTypeId() === CustomItemsRegistry::ENCHANTED_BOOK()->getTypeId()) return true; return match ($itemType) { CustomEnchant::ITEM_TYPE_GLOBAL => true, CustomEnchant::ITEM_TYPE_DAMAGEABLE => $item instanceof Durable, From 4b6e44e7b2e56794b934c675c24008a6a99c79e0 Mon Sep 17 00:00:00 2001 From: aericio <16523741+Aericio@users.noreply.github.com> Date: Thu, 28 Sep 2023 15:21:05 -1000 Subject: [PATCH 18/23] Add customies to phpstan dirs --- phpstan.neon.dist | 1 + 1 file changed, 1 insertion(+) diff --git a/phpstan.neon.dist b/phpstan.neon.dist index 71bb7bb7..9624ef72 100644 --- a/phpstan.neon.dist +++ b/phpstan.neon.dist @@ -8,6 +8,7 @@ parameters: - phar:///source/vendor/FormsUI.phar/src/ - phar:///source/vendor/Commando.phar/src/ - phar:///source/vendor/libPiggyUpdateChecker.phar/src/ + - phar:///source/vendor/Customies.phar/src/ excludePaths: analyse: - source/vendor From bd18618d5ff4964b6ae4cffb7a7452fab9686f81 Mon Sep 17 00:00:00 2001 From: aericio <16523741+Aericio@users.noreply.github.com> Date: Thu, 28 Sep 2023 15:46:04 -1000 Subject: [PATCH 19/23] Fix disable-enchantment not working --- src/DaPigGuy/PiggyCustomEnchants/CustomEnchantManager.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/DaPigGuy/PiggyCustomEnchants/CustomEnchantManager.php b/src/DaPigGuy/PiggyCustomEnchants/CustomEnchantManager.php index 30eb007b..b1d2739b 100644 --- a/src/DaPigGuy/PiggyCustomEnchants/CustomEnchantManager.php +++ b/src/DaPigGuy/PiggyCustomEnchants/CustomEnchantManager.php @@ -230,13 +230,13 @@ public static function unregisterEnchantment(int|CustomEnchant $id): void self::$plugin->getLogger()->debug("Custom Enchantment '" . $enchant->getDisplayName() . "' unregistered with id " . $enchant->getId()); unset(self::$enchants[$id]); - $property = new ReflectionProperty(EnchantmentIdMap::class, "enchToId"); + $property = new ReflectionProperty(EnchantmentIdMap::class, "enumToId"); $property->setAccessible(true); $value = $property->getValue(EnchantmentIdMap::getInstance()); unset($value[spl_object_id(EnchantmentIdMap::getInstance()->fromId($id))]); $property->setValue(EnchantmentIdMap::getInstance(), $value); - $property = new ReflectionProperty(EnchantmentIdMap::class, "idToEnch"); + $property = new ReflectionProperty(EnchantmentIdMap::class, "idToEnum"); $property->setAccessible(true); $value = $property->getValue(EnchantmentIdMap::getInstance()); unset($value[$id]); From f2750c71506e056ca0d7f552cd208056b197a3c6 Mon Sep 17 00:00:00 2001 From: aericio <16523741+Aericio@users.noreply.github.com> Date: Thu, 28 Sep 2023 17:27:54 -1000 Subject: [PATCH 20/23] Fix effects not being reset after inventory change --- src/DaPigGuy/PiggyCustomEnchants/EventListener.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/DaPigGuy/PiggyCustomEnchants/EventListener.php b/src/DaPigGuy/PiggyCustomEnchants/EventListener.php index 232df957..24c577b7 100644 --- a/src/DaPigGuy/PiggyCustomEnchants/EventListener.php +++ b/src/DaPigGuy/PiggyCustomEnchants/EventListener.php @@ -209,8 +209,8 @@ public function onJoin(PlayerJoinEvent $event): void $holder = $inventory->getHolder(); if ($holder instanceof Player) { if (!$oldItem->equals(($newItem = $inventory->getItem($slot)), !$inventory instanceof ArmorInventory)) { - if ($newItem->getTypeId() === BlockTypeIds::AIR || $inventory instanceof ArmorInventory) foreach ($oldItem->getEnchantments() as $oldEnchantment) ToggleableEnchantment::attemptToggle($holder, $oldItem, $oldEnchantment, $inventory, $slot, false); - if ($oldItem->getTypeId() === BlockTypeIds::AIR || $inventory instanceof ArmorInventory) foreach ($newItem->getEnchantments() as $newEnchantment) ToggleableEnchantment::attemptToggle($holder, $newItem, $newEnchantment, $inventory, $slot); + if ($newItem->equals(VanillaItems::AIR()) || $inventory instanceof ArmorInventory) foreach ($oldItem->getEnchantments() as $oldEnchantment) ToggleableEnchantment::attemptToggle($holder, $oldItem, $oldEnchantment, $inventory, $slot, false); + if ($oldItem->equals(VanillaItems::AIR()) || $inventory instanceof ArmorInventory) foreach ($newItem->getEnchantments() as $newEnchantment) ToggleableEnchantment::attemptToggle($holder, $newItem, $newEnchantment, $inventory, $slot); } } } From d2fdb068d19770ff893f6059e490ff84571499ce Mon Sep 17 00:00:00 2001 From: aericio <16523741+Aericio@users.noreply.github.com> Date: Thu, 28 Sep 2023 20:01:21 -1000 Subject: [PATCH 21/23] Fix effects staying when items replaced in inventory, closes #397 --- src/DaPigGuy/PiggyCustomEnchants/EventListener.php | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/DaPigGuy/PiggyCustomEnchants/EventListener.php b/src/DaPigGuy/PiggyCustomEnchants/EventListener.php index 24c577b7..87a97cfa 100644 --- a/src/DaPigGuy/PiggyCustomEnchants/EventListener.php +++ b/src/DaPigGuy/PiggyCustomEnchants/EventListener.php @@ -208,9 +208,9 @@ public function onJoin(PlayerJoinEvent $event): void if ($inventory instanceof PlayerInventory || $inventory instanceof ArmorInventory) { $holder = $inventory->getHolder(); if ($holder instanceof Player) { - if (!$oldItem->equals(($newItem = $inventory->getItem($slot)), !$inventory instanceof ArmorInventory)) { - if ($newItem->equals(VanillaItems::AIR()) || $inventory instanceof ArmorInventory) foreach ($oldItem->getEnchantments() as $oldEnchantment) ToggleableEnchantment::attemptToggle($holder, $oldItem, $oldEnchantment, $inventory, $slot, false); - if ($oldItem->equals(VanillaItems::AIR()) || $inventory instanceof ArmorInventory) foreach ($newItem->getEnchantments() as $newEnchantment) ToggleableEnchantment::attemptToggle($holder, $newItem, $newEnchantment, $inventory, $slot); + if (!$oldItem->equals(($newItem = $inventory->getItem($slot)), false)) { + foreach ($oldItem->getEnchantments() as $oldEnchantment) ToggleableEnchantment::attemptToggle($holder, $oldItem, $oldEnchantment, $inventory, $slot, false); + foreach ($newItem->getEnchantments() as $newEnchantment) ToggleableEnchantment::attemptToggle($holder, $newItem, $newEnchantment, $inventory, $slot); } } } From 33c0a38fa2daf924394a983abd920ba8342f43fd Mon Sep 17 00:00:00 2001 From: aericio <16523741+Aericio@users.noreply.github.com> Date: Thu, 28 Sep 2023 20:01:42 -1000 Subject: [PATCH 22/23] Fix component texture for enchant book --- .../PiggyCustomEnchants/items/PiggyEnchantedBookItem.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/DaPigGuy/PiggyCustomEnchants/items/PiggyEnchantedBookItem.php b/src/DaPigGuy/PiggyCustomEnchants/items/PiggyEnchantedBookItem.php index 8c9119c8..efd52a6b 100644 --- a/src/DaPigGuy/PiggyCustomEnchants/items/PiggyEnchantedBookItem.php +++ b/src/DaPigGuy/PiggyCustomEnchants/items/PiggyEnchantedBookItem.php @@ -14,7 +14,7 @@ final class PiggyEnchantedBookItem extends Item implements ItemComponents public function __construct(ItemIdentifier $identifier, string $name = "Enchanted Book") { parent::__construct($identifier, $name); - $this->initComponent("enchanted_book"); + $this->initComponent("book_enchanted"); } public function getMaxStackSize(): int From b8159687662b120ad34551cb6cff0922b0aec9d9 Mon Sep 17 00:00:00 2001 From: Vega Nicholas S <142091702+nicholass003@users.noreply.github.com> Date: Sat, 6 Apr 2024 15:54:13 +0700 Subject: [PATCH 23/23] [FIX] : Shadowing on plugin property (#430) --- .github/workflows/main.yml | 2 +- .../PiggyCustomEnchants/commands/CustomEnchantsCommand.php | 3 ++- .../commands/subcommands/AboutSubCommand.php | 3 ++- .../commands/subcommands/EnchantSubCommand.php | 3 ++- .../commands/subcommands/InfoSubCommand.php | 3 ++- .../commands/subcommands/ListSubCommand.php | 3 ++- .../PiggyCustomEnchants/commands/subcommands/NBTSubCommand.php | 3 ++- .../commands/subcommands/RemoveSubCommand.php | 3 ++- 8 files changed, 15 insertions(+), 8 deletions(-) diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index f4e6c67a..4d707b85 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -14,7 +14,7 @@ jobs: - name: Download Virion Dependencies run: | wget -O vendor/FormsUI.phar https://poggit.pmmp.io/r/209836/FormsUI_dev-20.phar - wget -O vendor/Commando.phar https://poggit.pmmp.io/r/216831/Commando_dev-34.phar + wget -O vendor/Commando.phar https://poggit.pmmp.io/r/233076/Commando_dev-41.phar wget -O vendor/libPiggyUpdateChecker.phar https://poggit.pmmp.io/r/211732/libPiggyUpdateChecker_dev-2.phar wget -O vendor/Customies.phar https://poggit.pmmp.io/r/216154/Customies.phar - name: Run PHPStan diff --git a/src/DaPigGuy/PiggyCustomEnchants/commands/CustomEnchantsCommand.php b/src/DaPigGuy/PiggyCustomEnchants/commands/CustomEnchantsCommand.php index 00855c43..7bdb85b0 100644 --- a/src/DaPigGuy/PiggyCustomEnchants/commands/CustomEnchantsCommand.php +++ b/src/DaPigGuy/PiggyCustomEnchants/commands/CustomEnchantsCommand.php @@ -15,13 +15,14 @@ use DaPigGuy\PiggyCustomEnchants\PiggyCustomEnchants; use pocketmine\command\CommandSender; use pocketmine\player\Player; +use pocketmine\plugin\Plugin; use pocketmine\utils\TextFormat; use Vecnavium\FormsUI\SimpleForm; class CustomEnchantsCommand extends BaseCommand { /** @var PiggyCustomEnchants */ - protected $plugin; + protected Plugin $plugin; public function onRun(CommandSender $sender, string $aliasUsed, array $args): void { diff --git a/src/DaPigGuy/PiggyCustomEnchants/commands/subcommands/AboutSubCommand.php b/src/DaPigGuy/PiggyCustomEnchants/commands/subcommands/AboutSubCommand.php index c7d79a21..7e36ab24 100644 --- a/src/DaPigGuy/PiggyCustomEnchants/commands/subcommands/AboutSubCommand.php +++ b/src/DaPigGuy/PiggyCustomEnchants/commands/subcommands/AboutSubCommand.php @@ -8,13 +8,14 @@ use DaPigGuy\PiggyCustomEnchants\PiggyCustomEnchants; use pocketmine\command\CommandSender; use pocketmine\player\Player; +use pocketmine\plugin\Plugin; use pocketmine\utils\TextFormat; use Vecnavium\FormsUI\SimpleForm; class AboutSubCommand extends BaseSubCommand { /** @var PiggyCustomEnchants */ - protected $plugin; + protected Plugin $plugin; public function onRun(CommandSender $sender, string $aliasUsed, array $args): void { diff --git a/src/DaPigGuy/PiggyCustomEnchants/commands/subcommands/EnchantSubCommand.php b/src/DaPigGuy/PiggyCustomEnchants/commands/subcommands/EnchantSubCommand.php index 8cad22d3..66dcdc7b 100644 --- a/src/DaPigGuy/PiggyCustomEnchants/commands/subcommands/EnchantSubCommand.php +++ b/src/DaPigGuy/PiggyCustomEnchants/commands/subcommands/EnchantSubCommand.php @@ -16,6 +16,7 @@ use pocketmine\item\enchantment\EnchantmentInstance; use pocketmine\item\ItemTypeIds; use pocketmine\player\Player; +use pocketmine\plugin\Plugin; use pocketmine\utils\TextFormat; use Ramsey\Uuid\Uuid; use Vecnavium\FormsUI\CustomForm; @@ -23,7 +24,7 @@ class EnchantSubCommand extends BaseSubCommand { /** @var PiggyCustomEnchants */ - protected $plugin; + protected Plugin $plugin; public function onRun(CommandSender $sender, string $aliasUsed, array $args): void { diff --git a/src/DaPigGuy/PiggyCustomEnchants/commands/subcommands/InfoSubCommand.php b/src/DaPigGuy/PiggyCustomEnchants/commands/subcommands/InfoSubCommand.php index 937bbf88..881c27b6 100644 --- a/src/DaPigGuy/PiggyCustomEnchants/commands/subcommands/InfoSubCommand.php +++ b/src/DaPigGuy/PiggyCustomEnchants/commands/subcommands/InfoSubCommand.php @@ -13,6 +13,7 @@ use DaPigGuy\PiggyCustomEnchants\utils\Utils; use pocketmine\command\CommandSender; use pocketmine\player\Player; +use pocketmine\plugin\Plugin; use pocketmine\utils\TextFormat; use Vecnavium\FormsUI\CustomForm; use Vecnavium\FormsUI\SimpleForm; @@ -20,7 +21,7 @@ class InfoSubCommand extends BaseSubCommand { /** @var PiggyCustomEnchants */ - protected $plugin; + protected Plugin $plugin; public function onRun(CommandSender $sender, string $aliasUsed, array $args): void { diff --git a/src/DaPigGuy/PiggyCustomEnchants/commands/subcommands/ListSubCommand.php b/src/DaPigGuy/PiggyCustomEnchants/commands/subcommands/ListSubCommand.php index 7cbf2886..45d138a6 100644 --- a/src/DaPigGuy/PiggyCustomEnchants/commands/subcommands/ListSubCommand.php +++ b/src/DaPigGuy/PiggyCustomEnchants/commands/subcommands/ListSubCommand.php @@ -11,13 +11,14 @@ use DaPigGuy\PiggyCustomEnchants\utils\Utils; use pocketmine\command\CommandSender; use pocketmine\player\Player; +use pocketmine\plugin\Plugin; use pocketmine\utils\TextFormat; use Vecnavium\FormsUI\SimpleForm; class ListSubCommand extends BaseSubCommand { /** @var PiggyCustomEnchants */ - protected $plugin; + protected Plugin $plugin; public function onRun(CommandSender $sender, string $aliasUsed, array $args): void { diff --git a/src/DaPigGuy/PiggyCustomEnchants/commands/subcommands/NBTSubCommand.php b/src/DaPigGuy/PiggyCustomEnchants/commands/subcommands/NBTSubCommand.php index 5c06d8ee..f496029b 100644 --- a/src/DaPigGuy/PiggyCustomEnchants/commands/subcommands/NBTSubCommand.php +++ b/src/DaPigGuy/PiggyCustomEnchants/commands/subcommands/NBTSubCommand.php @@ -8,12 +8,13 @@ use DaPigGuy\PiggyCustomEnchants\PiggyCustomEnchants; use pocketmine\command\CommandSender; use pocketmine\player\Player; +use pocketmine\plugin\Plugin; use pocketmine\utils\TextFormat; class NBTSubCommand extends BaseSubCommand { /** @var PiggyCustomEnchants */ - protected $plugin; + protected Plugin $plugin; public function onRun(CommandSender $sender, string $aliasUsed, array $args): void { diff --git a/src/DaPigGuy/PiggyCustomEnchants/commands/subcommands/RemoveSubCommand.php b/src/DaPigGuy/PiggyCustomEnchants/commands/subcommands/RemoveSubCommand.php index 82ebca68..b2cc1a18 100644 --- a/src/DaPigGuy/PiggyCustomEnchants/commands/subcommands/RemoveSubCommand.php +++ b/src/DaPigGuy/PiggyCustomEnchants/commands/subcommands/RemoveSubCommand.php @@ -12,13 +12,14 @@ use DaPigGuy\PiggyCustomEnchants\utils\Utils; use pocketmine\command\CommandSender; use pocketmine\player\Player; +use pocketmine\plugin\Plugin; use pocketmine\utils\TextFormat; use Vecnavium\FormsUI\CustomForm; class RemoveSubCommand extends BaseSubCommand { /** @var PiggyCustomEnchants */ - protected $plugin; + protected Plugin $plugin; public function onRun(CommandSender $sender, string $aliasUsed, array $args): void {