From 9a811b17d5a92f1e6abb9b87a3933f2f913590ad Mon Sep 17 00:00:00 2001 From: DaPigGuy Date: Mon, 29 Jun 2020 21:52:02 -0700 Subject: [PATCH 1/7] PMMP 4.0 --- .github/workflows/main.yml | 6 +- .poggit.yml | 6 +- plugin.yml | 2 +- .../PiggyCustomEnchantsShop/EventListener.php | 76 ++++++++----------- .../PiggyCustomEnchantsShop.php | 10 +-- .../commands/CustomEnchantShopCommand.php | 2 +- .../commands/subcommands/AddSubCommand.php | 9 +-- .../tasks/CheckUpdatesTask.php | 7 +- .../tiles/ShopSignTile.php | 12 +-- 9 files changed, 59 insertions(+), 71 deletions(-) diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index 5123625..fb593dc 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -17,15 +17,15 @@ jobs: - name: wget virions, FormAPI uses: wei/wget@v1 with: - args: -O vendor/FormAPI.phar https://poggit.pmmp.io/r/54589/FormApi_dev-9.phar + args: -O vendor/FormAPI.phar https://poggit.pmmp.io/r/77082/FormAPI_dev-1.phar - name: wget virions, libPiggyEconomy uses: wei/wget@v1 with: - args: -O vendor/libPiggyEconomy.phar https://poggit.pmmp.io/r/86214/libPiggyEconomy_dev-9.phar + args: -O vendor/libPiggyEconomy.phar https://poggit.pmmp.io/r/94380/libPiggyEconomy_dev-10.phar - name: wget virions, Commando uses: wei/wget@v1 with: - args: -O vendor/Commando.phar https://poggit.pmmp.io/r/89644/Commando_dev-13.phar + args: -O vendor/Commando.phar https://poggit.pmmp.io/r/90966/Commando_dev-2.phar - name: Run PHPStan uses: nxtlvlsoftware/pmmp-phpstan-action@3 with: diff --git a/.poggit.yml b/.poggit.yml index 4ca3c66..7072b93 100644 --- a/.poggit.yml +++ b/.poggit.yml @@ -1,16 +1,18 @@ --- # Poggit-CI Manifest. Open the CI at https://poggit.pmmp.io/ci/DaPigGuy/PiggyCustomEnchantsShop branches: - master + - pmmp-4.0.0 projects: PiggyCustomEnchantsShop: path: "" libs: - - src: jojoe77777/FormAPI/libFormAPI + - src: DaPigGuy/FormAPI-4.0.0/libFormAPI version: ^1.3 - - src: ParoxityTeam/Commando/Commando + - src: DaPigGuy/Commando-4.0.0/Commando version: ^2.1.0 - src: DaPigGuy/libPiggyEconomy/libPiggyEconomy version: ^2.0.0 + branch: "pmmp-4.0.0" lint: phpstan: false ... \ No newline at end of file diff --git a/plugin.yml b/plugin.yml index b1ef4eb..f82d7af 100644 --- a/plugin.yml +++ b/plugin.yml @@ -1,7 +1,7 @@ name: PiggyCustomEnchantsShop main: DaPigGuy\PiggyCustomEnchantsShop\PiggyCustomEnchantsShop version: 1.3.5 -api: 3.2.0 +api: 4.0.0 load: POSTWORLD author: DaPigGuy depend: ["PiggyCustomEnchants"] diff --git a/src/DaPigGuy/PiggyCustomEnchantsShop/EventListener.php b/src/DaPigGuy/PiggyCustomEnchantsShop/EventListener.php index ba62269..e2469f4 100644 --- a/src/DaPigGuy/PiggyCustomEnchantsShop/EventListener.php +++ b/src/DaPigGuy/PiggyCustomEnchantsShop/EventListener.php @@ -7,14 +7,13 @@ use DaPigGuy\PiggyCustomEnchants\CustomEnchantManager; use DaPigGuy\PiggyCustomEnchantsShop\enchants\PlaceholderEnchant; use DaPigGuy\PiggyCustomEnchantsShop\tiles\ShopSignTile; +use pocketmine\block\tile\Sign; +use pocketmine\block\utils\SignText; use pocketmine\event\block\BlockBreakEvent; use pocketmine\event\block\SignChangeEvent; use pocketmine\event\Listener; use pocketmine\event\player\PlayerInteractEvent; use pocketmine\item\enchantment\Enchantment; -use pocketmine\level\Level; -use pocketmine\tile\Sign; -use pocketmine\tile\Tile; use pocketmine\utils\Config; use pocketmine\utils\TextFormat; @@ -35,9 +34,8 @@ public function onBreak(BlockBreakEvent $event): void { $player = $event->getPlayer(); $block = $event->getBlock(); - /** @var Level $level */ - $level = $block->getLevel(); - if ($level->getTile($block) instanceof ShopSignTile) { + $world = $block->getPos()->getWorld(); + if ($world->getTile($block->getPos()) instanceof ShopSignTile) { if (!$player->hasPermission("piggycustomenchantsshop.sign.break")) { $player->sendMessage(TextFormat::RED . "You are not allowed to do this."); $event->setCancelled(); @@ -49,9 +47,8 @@ public function onInteract(PlayerInteractEvent $event): void { $player = $event->getPlayer(); $block = $event->getBlock(); - /** @var Level $level */ - $level = $block->getLevel(); - $tile = $level->getTile($block); + $world = $block->getPos()->getWorld(); + $tile = $world->getTile($block->getPos()); if ($tile instanceof ShopSignTile) { if (!$player->hasPermission("piggycustomenchantsshop.sign.use")) return; if (($enchant = $tile->getEnchantment()) instanceof PlaceholderEnchant) { @@ -81,7 +78,7 @@ public function onInteract(PlayerInteractEvent $event): void */ if (file_exists($this->plugin->getDataFolder() . "signs/shops.yml")) { $oldSignShops = new Config($this->plugin->getDataFolder() . "signs/shops.yml"); - if ($oldSignShops->exists($tile->x . "," . $tile->y . "," . $tile->z . "," . $level->getName())) { + if ($oldSignShops->exists($tile->getPos()->x . "," . $tile->getPos()->y . "," . $tile->getPos()->z . "," . $world->getFolderName())) { $enchantment = CustomEnchantManager::getEnchantmentByName($lines[1]); if ($enchantment === null) { $player->sendMessage(TextFormat::RED . "Could not convert legacy sign; enchantment not found."); @@ -90,17 +87,16 @@ public function onInteract(PlayerInteractEvent $event): void $enchantmentLevel = (int)str_replace("Level: ", "", $lines[2]); $price = (int)str_replace("Price: ", "", $lines[3]); - $nbt = $tile->getSpawnCompound(); - $nbt->setInt("Enchantment", $enchantment->getId()); - $nbt->setInt("EnchantmentLevel", $enchantmentLevel); - $nbt->setInt("Price", $price); - - /** @var ShopSignTile $newTile */ - $newTile = Tile::createTile("ShopSignTile", $level, $nbt); - $newTile->setLine(0, str_replace(["&", "{enchantment}", "{level}", "{price}"], [TextFormat::ESCAPE, ucfirst($enchantment->getName()), $enchantmentLevel, $price], $this->plugin->getConfig()->getNested("shop-types.sign.format.line-one"))); - $newTile->setLine(1, str_replace(["&", "{enchantment}", "{level}", "{price}"], [TextFormat::ESCAPE, ucfirst($enchantment->getName()), $enchantmentLevel, $price], $this->plugin->getConfig()->getNested("shop-types.sign.format.line-two"))); - $newTile->setLine(2, str_replace(["&", "{enchantment}", "{level}", "{price}"], [TextFormat::ESCAPE, ucfirst($enchantment->getName()), $enchantmentLevel, $price], $this->plugin->getConfig()->getNested("shop-types.sign.format.line-three"))); - $newTile->setLine(3, str_replace(["&", "{enchantment}", "{level}", "{price}"], [TextFormat::ESCAPE, ucfirst($enchantment->getName()), $enchantmentLevel, $price], $this->plugin->getConfig()->getNested("shop-types.sign.format.line-four"))); + $newTile = new ShopSignTile($world, $block->getPos()); + $newTile->setEnchantment($enchantment); + $newTile->setEnchantmentLevel($enchantmentLevel); + $newTile->setPrice($price); + $newTile->setText(new SignText([ + str_replace(["&", "{enchantment}", "{world}", "{price}"], [TextFormat::ESCAPE, ucfirst($enchantment->getName()), $enchantmentLevel, $price], $this->plugin->getConfig()->getNested("shop-types.sign.format.line-one")), + str_replace(["&", "{enchantment}", "{world}", "{price}"], [TextFormat::ESCAPE, ucfirst($enchantment->getName()), $enchantmentLevel, $price], $this->plugin->getConfig()->getNested("shop-types.sign.format.line-two")), + str_replace(["&", "{enchantment}", "{world}", "{price}"], [TextFormat::ESCAPE, ucfirst($enchantment->getName()), $enchantmentLevel, $price], $this->plugin->getConfig()->getNested("shop-types.sign.format.line-three")), + str_replace(["&", "{enchantment}", "{world}", "{price}"], [TextFormat::ESCAPE, ucfirst($enchantment->getName()), $enchantmentLevel, $price], $this->plugin->getConfig()->getNested("shop-types.sign.format.line-four")) + ])); $tile->close(); } } @@ -110,35 +106,32 @@ public function onInteract(PlayerInteractEvent $event): void public function onSignChange(SignChangeEvent $event): void { $player = $event->getPlayer(); - /** @var Level $level */ - $level = $event->getBlock()->getLevel(); + $level = $event->getBlock()->getPos()->getWorld(); /** @var Sign $tile */ - $tile = $level->getTile($event->getBlock()); - $lines = $event->getLines(); + $tile = $level->getTile($event->getBlock()->getPos()); + $lines = $event->getNewText()->getLines(); if ($this->plugin->getConfig()->getNested("shop-types.sign.enabled")) { $lines[0] = strtolower($lines[0]); if ($lines[0] === "ce" || $lines[0] === "[ce]") { if (!$player->hasPermission("piggycustomenchantsshop.sign.create")) { - $event->setLines([TextFormat::RED . "You are not", TextFormat::RED . "allowed to do", TextFormat::RED . "this.", ""]); + $event->setNewText(new SignText([TextFormat::RED . "You are not", TextFormat::RED . "allowed to do", TextFormat::RED . "this.", ""])); if ($tile instanceof ShopSignTile) $event->setCancelled(); return; } - if (($enchantment = CustomEnchantManager::getEnchantmentByName($lines[1])) === null && ($enchantment = Enchantment::getEnchantmentByName($lines[1])) === null) { - if (is_numeric($lines[1]) && (($enchantment = CustomEnchantManager::getEnchantment((int)$lines[1])) !== null || ($enchantment = Enchantment::getEnchantment((int)$lines[1])) !== null)) { - $event->setLine(1, $enchantment->getName()); - } else { - $event->setLine(1, TextFormat::RED . "Invalid enchantment."); + if (($enchantment = CustomEnchantManager::getEnchantmentByName($lines[1])) === null && ($enchantment = Enchantment::fromString($lines[1])) === null) { + if (!is_numeric($lines[1]) || (($enchantment = CustomEnchantManager::getEnchantment((int)$lines[1])) === null && ($enchantment = Enchantment::get((int)$lines[1])) === null)) { + $event->setNewText(new SignText([$lines[0], TextFormat::RED . "Invalid enchantment.", $lines[2], $lines[3]])); if ($tile instanceof ShopSignTile) $event->setCancelled(); return; } } if (!is_numeric($lines[2])) { - $event->setLine(2, TextFormat::RED . "Invalid value."); + $event->setNewText(new SignText([$lines[0], $lines[1], TextFormat::RED . "Invalid value.", $lines[3]])); if ($tile instanceof ShopSignTile) $event->setCancelled(); return; } if (!is_numeric($lines[3])) { - $event->setLine(3, TextFormat::RED . "Invalid value."); + $event->setNewText(new SignText([$lines[0], $lines[1], $lines[2], TextFormat::RED . "Invalid value."])); if ($tile instanceof ShopSignTile) $event->setCancelled(); return; } @@ -146,20 +139,17 @@ public function onSignChange(SignChangeEvent $event): void $newTile = $tile; if ($tile instanceof Sign) { - $nbt = $tile->getSpawnCompound(); - $nbt->setInt("Enchantment", $enchantment->getId()); - $nbt->setInt("EnchantmentLevel", (int)$lines[2]); - $nbt->setInt("Price", (int)$lines[3]); - /** @var ShopSignTile $newTile */ - $newTile = Tile::createTile("ShopSignTile", $level, $nbt); + $newTile = new ShopSignTile($tile->getPos()->getWorld(), $tile->getPos()); $tile->close(); } $enchantmentName = PiggyCustomEnchantsShop::$vanillaEnchantmentNames[$enchantment->getName()] ?? $enchantment->getName(); - $newTile->setLine(0, str_replace(["&", "{enchantment}", "{level}", "{price}"], [TextFormat::ESCAPE, $enchantmentName, $lines[2], $lines[3]], $this->plugin->getConfig()->getNested("shop-types.sign.format.line-one"))); - $newTile->setLine(1, str_replace(["&", "{enchantment}", "{level}", "{price}"], [TextFormat::ESCAPE, $enchantmentName, $lines[2], $lines[3]], $this->plugin->getConfig()->getNested("shop-types.sign.format.line-two"))); - $newTile->setLine(2, str_replace(["&", "{enchantment}", "{level}", "{price}"], [TextFormat::ESCAPE, $enchantmentName, $lines[2], $lines[3]], $this->plugin->getConfig()->getNested("shop-types.sign.format.line-three"))); - $newTile->setLine(3, str_replace(["&", "{enchantment}", "{level}", "{price}"], [TextFormat::ESCAPE, $enchantmentName, $lines[2], $lines[3]], $this->plugin->getConfig()->getNested("shop-types.sign.format.line-four"))); + $newTile->setText(new SignText([ + str_replace(["&", "{enchantment}", "{level}", "{price}"], [TextFormat::ESCAPE, $enchantmentName, $lines[2], $lines[3]], $this->plugin->getConfig()->getNested("shop-types.sign.format.line-one")), + str_replace(["&", "{enchantment}", "{level}", "{price}"], [TextFormat::ESCAPE, $enchantmentName, $lines[2], $lines[3]], $this->plugin->getConfig()->getNested("shop-types.sign.format.line-two")), + str_replace(["&", "{enchantment}", "{level}", "{price}"], [TextFormat::ESCAPE, $enchantmentName, $lines[2], $lines[3]], $this->plugin->getConfig()->getNested("shop-types.sign.format.line-three")), + str_replace(["&", "{enchantment}", "{level}", "{price}"], [TextFormat::ESCAPE, $enchantmentName, $lines[2], $lines[3]], $this->plugin->getConfig()->getNested("shop-types.sign.format.line-four")) + ])); $newTile->setEnchantment($enchantment); $newTile->setEnchantmentLevel((int)$lines[2]); diff --git a/src/DaPigGuy/PiggyCustomEnchantsShop/PiggyCustomEnchantsShop.php b/src/DaPigGuy/PiggyCustomEnchantsShop/PiggyCustomEnchantsShop.php index c7effeb..7271443 100644 --- a/src/DaPigGuy/PiggyCustomEnchantsShop/PiggyCustomEnchantsShop.php +++ b/src/DaPigGuy/PiggyCustomEnchantsShop/PiggyCustomEnchantsShop.php @@ -5,10 +5,7 @@ namespace DaPigGuy\PiggyCustomEnchantsShop; use CortexPE\Commando\BaseCommand; -use CortexPE\Commando\exception\HookAlreadyRegistered; use CortexPE\Commando\PacketHooker; -use DaPigGuy\libPiggyEconomy\exceptions\MissingProviderDependencyException; -use DaPigGuy\libPiggyEconomy\exceptions\UnknownProviderException; use DaPigGuy\libPiggyEconomy\libPiggyEconomy; use DaPigGuy\libPiggyEconomy\providers\EconomyProvider; use DaPigGuy\PiggyCustomEnchantsShop\commands\CustomEnchantShopCommand; @@ -17,12 +14,11 @@ use DaPigGuy\PiggyCustomEnchantsShop\tiles\ShopSignTile; use DaPigGuy\PiggyCustomEnchantsShop\utils\Utils; use jojoe77777\FormAPI\Form; +use pocketmine\block\tile\TileFactory; use pocketmine\item\enchantment\Enchantment; use pocketmine\plugin\PluginBase; -use pocketmine\tile\Tile; use pocketmine\utils\Config; use ReflectionClass; -use ReflectionException; class PiggyCustomEnchantsShop extends PluginBase { @@ -59,7 +55,7 @@ public function onEnable(): void foreach ($reflection->getConstants() as $name => $id) { $lastEnchantmentId++; if ($id !== $lastEnchantmentId) break; - $enchantment = Enchantment::getEnchantment($id); + $enchantment = Enchantment::get($id); if ($enchantment instanceof Enchantment) { self::$vanillaEnchantmentNames[$enchantment->getName()] = ucwords(strtolower(str_replace("_", " ", $name))); } @@ -78,7 +74,7 @@ public function onEnable(): void if (!PacketHooker::isRegistered()) PacketHooker::register($this); $this->getServer()->getCommandMap()->register("piggycustomenchantsshop", new CustomEnchantShopCommand($this, "customenchantshop", "Opens enchantment shop menu", ["ceshop"])); } - Tile::registerTile(ShopSignTile::class); + TileFactory::getInstance()->register(ShopSignTile::class); $this->getServer()->getPluginManager()->registerEvents(new EventListener($this), $this); $this->getServer()->getAsyncPool()->submitTask(new CheckUpdatesTask()); diff --git a/src/DaPigGuy/PiggyCustomEnchantsShop/commands/CustomEnchantShopCommand.php b/src/DaPigGuy/PiggyCustomEnchantsShop/commands/CustomEnchantShopCommand.php index 437838b..8a3d0b4 100644 --- a/src/DaPigGuy/PiggyCustomEnchantsShop/commands/CustomEnchantShopCommand.php +++ b/src/DaPigGuy/PiggyCustomEnchantsShop/commands/CustomEnchantShopCommand.php @@ -15,7 +15,7 @@ use jojoe77777\FormAPI\SimpleForm; use pocketmine\command\CommandSender; use pocketmine\item\enchantment\EnchantmentInstance; -use pocketmine\Player; +use pocketmine\player\Player; class CustomEnchantShopCommand extends BaseCommand { diff --git a/src/DaPigGuy/PiggyCustomEnchantsShop/commands/subcommands/AddSubCommand.php b/src/DaPigGuy/PiggyCustomEnchantsShop/commands/subcommands/AddSubCommand.php index 6e68d59..94df245 100644 --- a/src/DaPigGuy/PiggyCustomEnchantsShop/commands/subcommands/AddSubCommand.php +++ b/src/DaPigGuy/PiggyCustomEnchantsShop/commands/subcommands/AddSubCommand.php @@ -14,8 +14,7 @@ use jojoe77777\FormAPI\CustomForm; use pocketmine\command\CommandSender; use pocketmine\item\enchantment\Enchantment; -use pocketmine\Player; -use pocketmine\utils\TextFormat; +use pocketmine\player\Player; class AddSubCommand extends BaseSubCommand { @@ -32,7 +31,7 @@ public function onRun(CommandSender $sender, string $aliasUsed, array $args): vo if (count($args) >= 3) { if ( ($enchantment = CustomEnchantManager::getEnchantmentByName($args["enchantment"])) === null && - ($enchantment = Enchantment::getEnchantmentByName($args["enchantment"])) === null && + ($enchantment = Enchantment::fromString($args["enchantment"])) === null && (!is_numeric($args["enchantment"]) || (($enchantment = CustomEnchantManager::getEnchantment((int)$args["enchantment"])) === null && ($enchantment = Enchantment::getEnchantment((int)$args["enchantment"])) === null)) ) { $sender->sendMessage($this->plugin->getMessage("menu.add.invalid-enchantment")); @@ -54,8 +53,8 @@ public function onRun(CommandSender $sender, string $aliasUsed, array $args): vo if ($data !== null) { if ( ($enchantment = CustomEnchantManager::getEnchantmentByName($data[0])) === null && - ($enchantment = Enchantment::getEnchantmentByName($data[0])) === null && - (!is_numeric($data[0]) || (($enchantment = CustomEnchantManager::getEnchantment((int)$data[0])) === null && ($enchantment = Enchantment::getEnchantment((int)$data[0])) === null)) + ($enchantment = Enchantment::fromString($data[0])) === null && + (!is_numeric($data[0]) || (($enchantment = CustomEnchantManager::getEnchantment((int)$data[0])) === null && ($enchantment = Enchantment::get((int)$data[0])) === null)) ) { $player->sendMessage($this->plugin->getMessage("menu.add.invalid-enchantment")); return; diff --git a/src/DaPigGuy/PiggyCustomEnchantsShop/tasks/CheckUpdatesTask.php b/src/DaPigGuy/PiggyCustomEnchantsShop/tasks/CheckUpdatesTask.php index 733aa2e..325d33b 100644 --- a/src/DaPigGuy/PiggyCustomEnchantsShop/tasks/CheckUpdatesTask.php +++ b/src/DaPigGuy/PiggyCustomEnchantsShop/tasks/CheckUpdatesTask.php @@ -6,6 +6,7 @@ use DaPigGuy\PiggyCustomEnchantsShop\PiggyCustomEnchantsShop; use Exception; +use pocketmine\plugin\ApiVersion; use pocketmine\scheduler\AsyncTask; use pocketmine\Server; use pocketmine\utils\Internet; @@ -17,10 +18,10 @@ public function onRun(): void $this->setResult([Internet::getURL("https://poggit.pmmp.io/releases.json?name=PiggyCustomEnchantsShop", 10, [], $error), $error]); } - public function onCompletion(Server $server): void + public function onCompletion(): void { /** @var PiggyCustomEnchantsShop $plugin */ - $plugin = $server->getPluginManager()->getPlugin("PiggyCustomEnchantsShop"); + $plugin = Server::getInstance()->getPluginManager()->getPlugin("PiggyCustomEnchantsShop"); try { if ($plugin->isEnabled()) { $results = $this->getResult(); @@ -30,7 +31,7 @@ public function onCompletion(Server $server): void $data = json_decode($results[0], true); if (version_compare($plugin->getDescription()->getVersion(), $data[0]["version"]) === -1) { - if ($server->getPluginManager()->isCompatibleApi($data[0]["api"][0]["from"])) { + if (ApiVersion::isCompatible($plugin->getServer()->getApiVersion(), $data[0]["api"][0]["from"])) { $plugin->getLogger()->info("PiggyCustomEnchantsShop v" . $data[0]["version"] . " is available for download at " . $data[0]["artifact_url"] . "/PiggyCustomEnchantsShop.phar"); } } diff --git a/src/DaPigGuy/PiggyCustomEnchantsShop/tiles/ShopSignTile.php b/src/DaPigGuy/PiggyCustomEnchantsShop/tiles/ShopSignTile.php index 6f7c28a..58f71c3 100644 --- a/src/DaPigGuy/PiggyCustomEnchantsShop/tiles/ShopSignTile.php +++ b/src/DaPigGuy/PiggyCustomEnchantsShop/tiles/ShopSignTile.php @@ -8,12 +8,12 @@ use DaPigGuy\PiggyCustomEnchants\utils\Utils; use DaPigGuy\PiggyCustomEnchantsShop\enchants\PlaceholderEnchant; use DaPigGuy\PiggyCustomEnchantsShop\PiggyCustomEnchantsShop; +use pocketmine\block\tile\Sign; use pocketmine\item\enchantment\Enchantment; use pocketmine\item\enchantment\EnchantmentInstance; use pocketmine\nbt\tag\CompoundTag; -use pocketmine\nbt\tag\NamedTag; -use pocketmine\Player; -use pocketmine\tile\Sign; +use pocketmine\nbt\tag\Tag; +use pocketmine\player\Player; use pocketmine\utils\TextFormat; class ShopSignTile extends Sign @@ -73,12 +73,12 @@ public function purchaseItem(PiggyCustomEnchantsShop $plugin, Player $player): v $player->sendMessage(TextFormat::GREEN . "Item has successfully been enchanted."); } - protected function readSaveData(CompoundTag $nbt): void + public function readSaveData(CompoundTag $nbt): void { parent::readSaveData($nbt); - $this->enchantment = CustomEnchantManager::getEnchantment($nbt->getInt("Enchantment")) ?? Enchantment::getEnchantment($nbt->getInt("Enchantment")) ?? new PlaceholderEnchant($nbt->getInt("Enchantment")); + $this->enchantment = CustomEnchantManager::getEnchantment($nbt->getInt("Enchantment")) ?? Enchantment::get($nbt->getInt("Enchantment")) ?? new PlaceholderEnchant($nbt->getInt("Enchantment")); $this->enchantmentLevel = $nbt->getInt("EnchantmentLevel"); - $this->price = (float)$nbt->getTagValue("Price", NamedTag::class); + $this->price = (float)$nbt->getTagValue("Price", Tag::class); } From 1ac52e26fc79dee78de651edcb99235a30759475 Mon Sep 17 00:00:00 2001 From: DaPigGuy Date: Mon, 29 Jun 2020 21:53:37 -0700 Subject: [PATCH 2/7] Change PHPStan to use 4.0 tag --- .github/workflows/main.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index fb593dc..61e8f16 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -27,6 +27,6 @@ jobs: with: args: -O vendor/Commando.phar https://poggit.pmmp.io/r/90966/Commando_dev-2.phar - name: Run PHPStan - uses: nxtlvlsoftware/pmmp-phpstan-action@3 + uses: nxtlvlsoftware/pmmp-phpstan-action@4 with: phpstan-config: phpstan.neon.dist \ No newline at end of file From 526c41c8894597c2ef73350f915b3c052966d279 Mon Sep 17 00:00:00 2001 From: DaPigGuy Date: Mon, 29 Jun 2020 21:55:39 -0700 Subject: [PATCH 3/7] PMMP 4.0: Fix PHPStan --- src/DaPigGuy/PiggyCustomEnchantsShop/EventListener.php | 2 +- .../commands/subcommands/AddSubCommand.php | 2 +- src/DaPigGuy/PiggyCustomEnchantsShop/shops/UIShopsManager.php | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/src/DaPigGuy/PiggyCustomEnchantsShop/EventListener.php b/src/DaPigGuy/PiggyCustomEnchantsShop/EventListener.php index e2469f4..40ac336 100644 --- a/src/DaPigGuy/PiggyCustomEnchantsShop/EventListener.php +++ b/src/DaPigGuy/PiggyCustomEnchantsShop/EventListener.php @@ -72,7 +72,7 @@ public function onInteract(PlayerInteractEvent $event): void $tile->purchaseItem($this->plugin, $player); } elseif ($tile instanceof Sign) { - $lines = $tile->getText(); + $lines = $tile->getText()->getLines(); /** * Converts signs from pre 1.3.0 */ diff --git a/src/DaPigGuy/PiggyCustomEnchantsShop/commands/subcommands/AddSubCommand.php b/src/DaPigGuy/PiggyCustomEnchantsShop/commands/subcommands/AddSubCommand.php index 94df245..0c13b15 100644 --- a/src/DaPigGuy/PiggyCustomEnchantsShop/commands/subcommands/AddSubCommand.php +++ b/src/DaPigGuy/PiggyCustomEnchantsShop/commands/subcommands/AddSubCommand.php @@ -32,7 +32,7 @@ public function onRun(CommandSender $sender, string $aliasUsed, array $args): vo if ( ($enchantment = CustomEnchantManager::getEnchantmentByName($args["enchantment"])) === null && ($enchantment = Enchantment::fromString($args["enchantment"])) === null && - (!is_numeric($args["enchantment"]) || (($enchantment = CustomEnchantManager::getEnchantment((int)$args["enchantment"])) === null && ($enchantment = Enchantment::getEnchantment((int)$args["enchantment"])) === null)) + (!is_numeric($args["enchantment"]) || (($enchantment = CustomEnchantManager::getEnchantment((int)$args["enchantment"])) === null && ($enchantment = Enchantment::get((int)$args["enchantment"])) === null)) ) { $sender->sendMessage($this->plugin->getMessage("menu.add.invalid-enchantment")); return; diff --git a/src/DaPigGuy/PiggyCustomEnchantsShop/shops/UIShopsManager.php b/src/DaPigGuy/PiggyCustomEnchantsShop/shops/UIShopsManager.php index f19e8e5..1b49cde 100644 --- a/src/DaPigGuy/PiggyCustomEnchantsShop/shops/UIShopsManager.php +++ b/src/DaPigGuy/PiggyCustomEnchantsShop/shops/UIShopsManager.php @@ -31,7 +31,7 @@ public function __construct(PiggyCustomEnchantsShop $plugin) public function initShops(): void { foreach ($this->file->getAll() as $key => $value) { - $this->shops[$key] = new UIShop((int)str_replace("id:", "", (string)$key), CustomEnchantManager::getEnchantmentByName($value[0]) ?? Enchantment::getEnchantmentByName($value[0]) ?? new PlaceholderEnchant(0, $value[0]), $value[1], $value[2]); + $this->shops[$key] = new UIShop((int)str_replace("id:", "", (string)$key), CustomEnchantManager::getEnchantmentByName($value[0]) ?? Enchantment::fromString($value[0]) ?? new PlaceholderEnchant(0, $value[0]), $value[1], $value[2]); } } From 3f0072d3701fe9e7ad4bd8f487b0146e71ba15a8 Mon Sep 17 00:00:00 2001 From: DaPigGuy Date: Mon, 29 Jun 2020 22:07:04 -0700 Subject: [PATCH 4/7] PMMP 4.0: Fixed sign shops --- src/DaPigGuy/PiggyCustomEnchantsShop/EventListener.php | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/DaPigGuy/PiggyCustomEnchantsShop/EventListener.php b/src/DaPigGuy/PiggyCustomEnchantsShop/EventListener.php index 40ac336..7781aff 100644 --- a/src/DaPigGuy/PiggyCustomEnchantsShop/EventListener.php +++ b/src/DaPigGuy/PiggyCustomEnchantsShop/EventListener.php @@ -97,6 +97,7 @@ public function onInteract(PlayerInteractEvent $event): void str_replace(["&", "{enchantment}", "{world}", "{price}"], [TextFormat::ESCAPE, ucfirst($enchantment->getName()), $enchantmentLevel, $price], $this->plugin->getConfig()->getNested("shop-types.sign.format.line-three")), str_replace(["&", "{enchantment}", "{world}", "{price}"], [TextFormat::ESCAPE, ucfirst($enchantment->getName()), $enchantmentLevel, $price], $this->plugin->getConfig()->getNested("shop-types.sign.format.line-four")) ])); + $world->addTile($newTile); $tile->close(); } } @@ -139,8 +140,8 @@ public function onSignChange(SignChangeEvent $event): void $newTile = $tile; if ($tile instanceof Sign) { - /** @var ShopSignTile $newTile */ $newTile = new ShopSignTile($tile->getPos()->getWorld(), $tile->getPos()); + $tile->getPos()->getWorld()->addTile($newTile); $tile->close(); } $enchantmentName = PiggyCustomEnchantsShop::$vanillaEnchantmentNames[$enchantment->getName()] ?? $enchantment->getName(); From 052297c5769b8aef677122e9ed87cf221fcaec3e Mon Sep 17 00:00:00 2001 From: DaPigGuy Date: Thu, 23 Jul 2020 02:09:29 -0700 Subject: [PATCH 5/7] PMMP 4.0: Fix potential update check crash --- src/DaPigGuy/PiggyCustomEnchantsShop/tasks/CheckUpdatesTask.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/DaPigGuy/PiggyCustomEnchantsShop/tasks/CheckUpdatesTask.php b/src/DaPigGuy/PiggyCustomEnchantsShop/tasks/CheckUpdatesTask.php index 325d33b..a18b897 100644 --- a/src/DaPigGuy/PiggyCustomEnchantsShop/tasks/CheckUpdatesTask.php +++ b/src/DaPigGuy/PiggyCustomEnchantsShop/tasks/CheckUpdatesTask.php @@ -31,7 +31,7 @@ public function onCompletion(): void $data = json_decode($results[0], true); if (version_compare($plugin->getDescription()->getVersion(), $data[0]["version"]) === -1) { - if (ApiVersion::isCompatible($plugin->getServer()->getApiVersion(), $data[0]["api"][0]["from"])) { + if (ApiVersion::isCompatible($plugin->getServer()->getApiVersion(), $data[0]["api"][0])) { $plugin->getLogger()->info("PiggyCustomEnchantsShop v" . $data[0]["version"] . " is available for download at " . $data[0]["artifact_url"] . "/PiggyCustomEnchantsShop.phar"); } } From 0af6b2a3d3b70cbde06afc1d4c37ab1aebf9282b Mon Sep 17 00:00:00 2001 From: DaPigGuy Date: Mon, 21 Feb 2022 16:48:08 -0800 Subject: [PATCH 6/7] Use PHP8 Typed Properties --- .../PiggyCustomEnchantsShop/EventListener.php | 9 +++------ .../PiggyCustomEnchantsShop.php | 13 +++++-------- .../commands/CustomEnchantShopCommand.php | 3 --- .../PiggyCustomEnchantsShop/shops/UIShop.php | 16 +--------------- .../shops/UIShopsManager.php | 11 +++-------- .../tiles/ShopSignTile.php | 9 +++------ 6 files changed, 15 insertions(+), 46 deletions(-) diff --git a/src/DaPigGuy/PiggyCustomEnchantsShop/EventListener.php b/src/DaPigGuy/PiggyCustomEnchantsShop/EventListener.php index 7781aff..9f058a4 100644 --- a/src/DaPigGuy/PiggyCustomEnchantsShop/EventListener.php +++ b/src/DaPigGuy/PiggyCustomEnchantsShop/EventListener.php @@ -19,13 +19,10 @@ class EventListener implements Listener { - /** @var PiggyCustomEnchantsShop */ - private $plugin; + /** @var int[] */ + private array $lastTap; - /** @var array */ - private $lastTap; - - public function __construct(PiggyCustomEnchantsShop $plugin) + public function __construct(private PiggyCustomEnchantsShop $plugin) { $this->plugin = $plugin; } diff --git a/src/DaPigGuy/PiggyCustomEnchantsShop/PiggyCustomEnchantsShop.php b/src/DaPigGuy/PiggyCustomEnchantsShop/PiggyCustomEnchantsShop.php index 7271443..95c3387 100644 --- a/src/DaPigGuy/PiggyCustomEnchantsShop/PiggyCustomEnchantsShop.php +++ b/src/DaPigGuy/PiggyCustomEnchantsShop/PiggyCustomEnchantsShop.php @@ -22,17 +22,14 @@ class PiggyCustomEnchantsShop extends PluginBase { - /** @var Config */ - private $messages; + private Config $messages; - /** @var EconomyProvider */ - public $economyProvider; + public EconomyProvider $economyProvider; - /** @var UIShopsManager */ - public $uiShopManager = null; + public ?UIShopsManager $uiShopManager = null; - /** @var array */ - public static $vanillaEnchantmentNames = []; + /** @var string[] */ + public static array $vanillaEnchantmentNames = []; public function onEnable(): void { diff --git a/src/DaPigGuy/PiggyCustomEnchantsShop/commands/CustomEnchantShopCommand.php b/src/DaPigGuy/PiggyCustomEnchantsShop/commands/CustomEnchantShopCommand.php index 8a3d0b4..e162e2f 100644 --- a/src/DaPigGuy/PiggyCustomEnchantsShop/commands/CustomEnchantShopCommand.php +++ b/src/DaPigGuy/PiggyCustomEnchantsShop/commands/CustomEnchantShopCommand.php @@ -22,9 +22,6 @@ class CustomEnchantShopCommand extends BaseCommand /** @var PiggyCustomEnchantsShop */ protected $plugin; - /** - * @param array $args - */ public function onRun(CommandSender $sender, string $aliasUsed, array $args): void { if (!$sender instanceof Player) { diff --git a/src/DaPigGuy/PiggyCustomEnchantsShop/shops/UIShop.php b/src/DaPigGuy/PiggyCustomEnchantsShop/shops/UIShop.php index 6274f6f..bcbbde5 100644 --- a/src/DaPigGuy/PiggyCustomEnchantsShop/shops/UIShop.php +++ b/src/DaPigGuy/PiggyCustomEnchantsShop/shops/UIShop.php @@ -8,22 +8,8 @@ class UIShop { - /** @var int */ - private $id; - - /** @var Enchantment */ - private $enchantment; - /** @var int */ - private $enchantmentLevel; - /** @var float */ - private $price; - - public function __construct(int $id, Enchantment $enchantment, int $enchantmentLevel, float $price) + public function __construct(private int $id, private Enchantment $enchantment, private int $enchantmentLevel, private float $price) { - $this->id = $id; - $this->enchantment = $enchantment; - $this->enchantmentLevel = $enchantmentLevel; - $this->price = $price; } public function getId(): int diff --git a/src/DaPigGuy/PiggyCustomEnchantsShop/shops/UIShopsManager.php b/src/DaPigGuy/PiggyCustomEnchantsShop/shops/UIShopsManager.php index 1b49cde..dd60b1b 100644 --- a/src/DaPigGuy/PiggyCustomEnchantsShop/shops/UIShopsManager.php +++ b/src/DaPigGuy/PiggyCustomEnchantsShop/shops/UIShopsManager.php @@ -12,18 +12,13 @@ class UIShopsManager { - /** @var PiggyCustomEnchantsShop */ - private $plugin; - /** @var Config */ - private $file; + private Config $file; /** @var UIShop[] */ - private $shops = []; + private array $shops = []; - public function __construct(PiggyCustomEnchantsShop $plugin) + public function __construct(private PiggyCustomEnchantsShop $plugin) { - $this->plugin = $plugin; - @mkdir($this->plugin->getDataFolder() . "ui"); $this->file = new Config($this->plugin->getDataFolder() . "ui/shops.yml"); } diff --git a/src/DaPigGuy/PiggyCustomEnchantsShop/tiles/ShopSignTile.php b/src/DaPigGuy/PiggyCustomEnchantsShop/tiles/ShopSignTile.php index 58f71c3..8f2405f 100644 --- a/src/DaPigGuy/PiggyCustomEnchantsShop/tiles/ShopSignTile.php +++ b/src/DaPigGuy/PiggyCustomEnchantsShop/tiles/ShopSignTile.php @@ -18,12 +18,9 @@ class ShopSignTile extends Sign { - /** @var Enchantment */ - public $enchantment; - /** @var int */ - public $enchantmentLevel = 1; - /** @var float */ - public $price = 1; + public Enchantment $enchantment; + public int $enchantmentLevel = 1; + public float $price = 1; public function getEnchantment(): Enchantment { From 7a39f1186bc44743d55c609a75800a85b3a9a714 Mon Sep 17 00:00:00 2001 From: DaPigGuy Date: Thu, 17 Mar 2022 22:41:53 -0700 Subject: [PATCH 7/7] Switch to BedrockEconomy as the default economy provider --- resources/config.yml | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/resources/config.yml b/resources/config.yml index 576f0c1..b846fd0 100644 --- a/resources/config.yml +++ b/resources/config.yml @@ -1,7 +1,5 @@ economy: - provider: EconomyS - # This is used for the MultiEconomy provider - multieconomy-currency: "" + provider: bedrockeconomy currency-format: "${amount}" enchant-limit: -1 shop-types: