diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index 5123625..61e8f16 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -17,16 +17,16 @@ 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 + uses: nxtlvlsoftware/pmmp-phpstan-action@4 with: phpstan-config: phpstan.neon.dist \ No newline at end of file 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/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: diff --git a/src/DaPigGuy/PiggyCustomEnchantsShop/EventListener.php b/src/DaPigGuy/PiggyCustomEnchantsShop/EventListener.php index ba62269..9f058a4 100644 --- a/src/DaPigGuy/PiggyCustomEnchantsShop/EventListener.php +++ b/src/DaPigGuy/PiggyCustomEnchantsShop/EventListener.php @@ -7,26 +7,22 @@ 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; 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; } @@ -35,9 +31,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 +44,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) { @@ -75,13 +69,13 @@ 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 */ 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 +84,17 @@ 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")) + ])); + $world->addTile($newTile); $tile->close(); } } @@ -110,35 +104,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 +137,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->getPos()->getWorld()->addTile($newTile); $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..95c3387 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,26 +14,22 @@ 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 { - /** @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 { @@ -59,7 +52,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 +71,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..e162e2f 100644 --- a/src/DaPigGuy/PiggyCustomEnchantsShop/commands/CustomEnchantShopCommand.php +++ b/src/DaPigGuy/PiggyCustomEnchantsShop/commands/CustomEnchantShopCommand.php @@ -15,16 +15,13 @@ use jojoe77777\FormAPI\SimpleForm; use pocketmine\command\CommandSender; use pocketmine\item\enchantment\EnchantmentInstance; -use pocketmine\Player; +use pocketmine\player\Player; 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/commands/subcommands/AddSubCommand.php b/src/DaPigGuy/PiggyCustomEnchantsShop/commands/subcommands/AddSubCommand.php index 6e68d59..0c13b15 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,8 +31,8 @@ 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 && - (!is_numeric($args["enchantment"]) || (($enchantment = CustomEnchantManager::getEnchantment((int)$args["enchantment"])) === null && ($enchantment = Enchantment::getEnchantment((int)$args["enchantment"])) === null)) + ($enchantment = Enchantment::fromString($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; @@ -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/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 f19e8e5..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"); } @@ -31,7 +26,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]); } } diff --git a/src/DaPigGuy/PiggyCustomEnchantsShop/tasks/CheckUpdatesTask.php b/src/DaPigGuy/PiggyCustomEnchantsShop/tasks/CheckUpdatesTask.php index 733aa2e..a18b897 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])) { $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..8f2405f 100644 --- a/src/DaPigGuy/PiggyCustomEnchantsShop/tiles/ShopSignTile.php +++ b/src/DaPigGuy/PiggyCustomEnchantsShop/tiles/ShopSignTile.php @@ -8,22 +8,19 @@ 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 { - /** @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 { @@ -73,12 +70,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); }