Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

PMMP 4.0.0 #43

Draft
wants to merge 7 commits into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
6 changes: 4 additions & 2 deletions .poggit.yml
Original file line number Diff line number Diff line change
@@ -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
...
2 changes: 1 addition & 1 deletion plugin.yml
Original file line number Diff line number Diff line change
@@ -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"]
Expand Down
4 changes: 1 addition & 3 deletions resources/config.yml
Original file line number Diff line number Diff line change
@@ -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:
Expand Down
90 changes: 39 additions & 51 deletions src/DaPigGuy/PiggyCustomEnchantsShop/EventListener.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand All @@ -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();
Expand All @@ -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) {
Expand All @@ -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.");
Expand All @@ -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();
}
}
Expand All @@ -110,56 +104,50 @@ 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;
}
$event->setCancelled();

$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]);
Expand Down
23 changes: 8 additions & 15 deletions src/DaPigGuy/PiggyCustomEnchantsShop/PiggyCustomEnchantsShop.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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
{
Expand All @@ -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)));
}
Expand All @@ -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());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
{
Expand All @@ -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;
Expand All @@ -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;
Expand Down
Loading
Loading