diff --git a/.poggit.yml b/.poggit.yml deleted file mode 100644 index aa19eee..0000000 --- a/.poggit.yml +++ /dev/null @@ -1,9 +0,0 @@ ---- # Poggit-CI Manifest. Open the CI at https://poggit.pmmp.io/ci/ItsRealNise/EnchantUI -build-by-default: true -branches: -- main -projects: - EnchantUI: - path: "" - icon: logo.png -... diff --git a/README.md b/README.md index 8e66e99..a789a45 100644 --- a/README.md +++ b/README.md @@ -1,6 +1,22 @@ # EnchantedUI -A simple enchant shop ui +A simple enchant shop ui updated by HosseinYT
+



+Plugin Icon -# Required: +# Depends: +• **EconomyAPI** by **onebone** updated by **mathchat900** [EconomyAPI PM5](https://github.com/mathchat900/EconomyAPI-PM5) -• EconomyAPI by onebone +# How Install ? +1. Download .phar file from [release](https://github.com/HosseinYT-PM/EnchantedUI/releases). +2. Dwonload Depend [EconomyAPI](https://github.com/mathchat900/EconomyAPI-PM5) +3. Put plugins to your server plugin folder +4. Hold the item and execute `/eshop` and select your enchant + +# SoftDepends: +• **CustomEnchants** by **DaPigGuy** updated by **zsfell** [CustomEnchants PM5](https://github.com/zsfell/PiggyCustomEnchants-PM5) + +# ChangeLogs: +• Update Namespaces
+• Update Libs
+• Update API Plugin Form 4.0.0 To 5.0.0
+• Fix Bugs And Others
diff --git a/plugin.yml b/plugin.yml index 2ab152a..a1ee5b3 100644 --- a/plugin.yml +++ b/plugin.yml @@ -2,9 +2,14 @@ name: EnchantedUI main: ItsRealNise\EnchantedUI\Main version: "1.0" -api: 4.0.0 +api: 5.0.0 load: POSTWORLD -author: ItsRealNise +author: ItsRealNise updated by HosseinYT +depends: FormAPI +commands: + eshop: + description: Enchant Menu + permission: eshop.command permissions: eshop.command: default: true diff --git a/resources/Shop.yml b/resources/Shop.yml index c67774f..9baa876 100644 --- a/resources/Shop.yml +++ b/resources/Shop.yml @@ -1,11 +1,7 @@ --- -#Don't Change this -version: "1.0" - -#send EnchantUI to the player when he interacts with the Enchanting-table +version: "0.5" enchanting-table: true - -#EnchantUI version 0.5 +piggycustomenchants: false Title: "§cEnchantment Shop" Button: "§3{NAME} §a{PRICE}$" slider-title: "§5Level" @@ -16,18 +12,38 @@ messages: paid-success: "§aYou bought {NAME} level {LEVEL} for {PRICE}$" hold-item: "§cPlease hold an item that can be enchanted" no-perm: "§cYou don't have permission to use this command" - incompatible-enchantment: - -#WARNING: Use only Enchantment ID at incompatible-enchantments example [1,10,13] + incompatible-enchantment: "§cThis enchantment is incompatible with an existing enchantment on your item" + shop: -- name: "Fire Protection" - enchantment: fire_protection - price: 100 - max-level: 2 - incompatible-enchantments: [] -- name: "Protection" - enchantment: 1 - price: 100 - max-level: 3 - incompatible-enchantments: [] -... + # Vanilla enchantments (use numeric IDs) + - name: "Protection" + enchantment: 0 + price: 100 + max-level: 4 + incompatible-enchantments: [] + + - name: "Fire Protection" + enchantment: 1 + price: 150 + max-level: 4 + incompatible-enchantments: [] + + - name: "Sharpness" + enchantment: 9 + price: 200 + max-level: 5 + incompatible-enchantments: [] + +customenchantsshop: + # PiggyCustomEnchants (use exact enchantment names as strings) + - name: "Lightning" + enchantment: "lightning" + price: 500 + max-level: 3 + incompatible-enchantments: [] + + - name: "Poison" + enchantment: "poison" + price: 400 + max-level: 2 + incompatible-enchantments: [] diff --git a/src/ItsRealNise/EnchantedUI/Commands/ShopCommand.php b/src/ItsRealNise/EnchantedUI/Commands/ShopCommand.php deleted file mode 100644 index 5a659bc..0000000 --- a/src/ItsRealNise/EnchantedUI/Commands/ShopCommand.php +++ /dev/null @@ -1,54 +0,0 @@ -plugin = $plugin; - } - - /** - * @param CommandSender $sender - * @param string $commandLabel - * @param array $args - * - * @return bool - */ - public function execute(CommandSender $sender, string $commandLabel, array $args): bool{ - if(!$sender->hasPermission("eshop.command")){ - $sender->sendMessage($this->plugin->shop->getNested('messages.no-perm')); - return true; - } - /**if(!$sender instanceof Player){ - $sender->sendMessage("Please use this in-game."); - return true; - }*/ - $this->plugin->listForm($sender); - return true; - } - - public function getOwningPlugin(): Plugin { - return $this->plugin; - } -} diff --git a/src/ItsRealNise/EnchantedUI/EventListener.php b/src/ItsRealNise/EnchantedUI/EventListener.php index c12f6c3..65ae212 100644 --- a/src/ItsRealNise/EnchantedUI/EventListener.php +++ b/src/ItsRealNise/EnchantedUI/EventListener.php @@ -22,7 +22,7 @@ public function __construct(Main $plugin){ /** * @param PlayerInteractEvent $ev */ - public function onInteract(PlayerInteractEvent $ev){ + public function onInteract(PlayerInteractEvent $ev): void { if($ev->getAction() !== PlayerInteractEvent::RIGHT_CLICK_BLOCK) return; $table = $this->plugin->shop->getNested('enchanting-table'); if($table and $ev->getBlock() instanceof EnchantingTable){ diff --git a/src/ItsRealNise/EnchantedUI/Main.php b/src/ItsRealNise/EnchantedUI/Main.php index b4a93d5..ea39556 100644 --- a/src/ItsRealNise/EnchantedUI/Main.php +++ b/src/ItsRealNise/EnchantedUI/Main.php @@ -2,39 +2,32 @@ namespace ItsRealNise\EnchantedUI; -use pocketmine\Server; -use pocketmine\player\Player; -use pocketmine\item\{ - Item, - Tool, - Armor, - enchantment\Enchantment, - enchantment\EnchantmentInstance -}; -use pocketmine\utils\Config; -use ItsRealNise\EnchantedUI\libs\jojoe77777\FormAPI\{ - CustomForm, - SimpleForm -}; +use jojoe77777\FormAPI\{CustomForm, SimpleForm}; +use onebone\economyapi\EconomyAPI; +use pocketmine\command\Command; +use pocketmine\command\CommandSender; use pocketmine\data\bedrock\EnchantmentIdMap; +use pocketmine\item\{Armor, enchantment\EnchantmentInstance, Tool}; +use pocketmine\player\Player; use pocketmine\plugin\PluginBase; -use onebone\economyapi\EconomyAPI; -use DaPigGuy\PiggyCustomEnchants\CustomEnchants\CustomEnchants; -use ItsRealNise\EnchantedUI\Commands\ShopCommand; +use pocketmine\utils\Config; /** * Class Main * @package ItsRealNise\EnchantUI */ -class Main extends PluginBase{ +class Main extends PluginBase +{ /** @var Config $shop */ public $shop; - public $piggyCE; public $eco; + public $piggyCE; + public $usePiggyCE; - public function onEnable(): void{ + public function onEnable(): void + { if (is_null($this->getServer()->getPluginManager()->getPlugin("EconomyAPI"))) { $this->getLogger()->error("in order to use EnchantUI you need to install EconomyAPI."); $this->getServer()->getPluginManager()->disablePlugin($this); @@ -45,27 +38,45 @@ public function onEnable(): void{ $this->UpdateConfig(); $this->saveDefaultConfig(); $this->getServer()->getPluginManager()->registerEvents(new EventListener($this), $this); - $this->getServer()->getCommandMap()->register("enchantui", new ShopCommand($this)); - $this->piggyCE = $this->getServer()->getPluginManager()->getPlugin("PiggyCustomEnchants"); - $this->eco = $this->getServer()->getPluginManager()->getPlugin("EconomyAPI"); + $this->eco = EconomyAPI::getInstance(); + + // Check if PiggyCustomEnchants should be used + $this->usePiggyCE = $this->shop->getNested('piggycustomenchants', false); + + // Load PiggyCustomEnchants if enabled in config and available + if ($this->usePiggyCE) { + $this->piggyCE = $this->getServer()->getPluginManager()->getPlugin("PiggyCustomEnchants"); + if ($this->piggyCE !== null) { + $this->getLogger()->info("PiggyCustomEnchants support enabled!"); + } else { + $this->getLogger()->warning("PiggyCustomEnchants is enabled in config but not installed!"); + $this->usePiggyCE = false; + } + } } - public function UpdateConfig(): void{ - if(is_null($this->shop->getNested('version'))){ - file_put_contents($this->getDataFolder() . "Shop.yml",$this->getResource("Shop.yml")); + public function UpdateConfig(): void + { + if (is_null($this->shop->getNested('version'))) { + file_put_contents($this->getDataFolder() . "Shop.yml", $this->getResource("Shop.yml")); $this->shop->reload(); $this->getLogger()->notice("plugin config has been updated"); return; } - if($this->shop->getNested('version') != '0.5'){ + if ($this->shop->getNested('version') != '0.5') { $shop = $this->shop->getAll(); $shop['version'] = '0.5'; $shop['enchanting-table'] = true; + $shop['piggycustomenchants'] = false; // Add default value $shop['messages']['incompatible-enchantment'] = ''; - foreach($shop['shop'] as $list => $data){ + foreach ($shop['shop'] as $list => $data) { $data['incompatible-enchantments'] = array(); $shop['shop'][$list] = $data; } + // Initialize custom enchantments shop if not exists + if (!isset($shop['customenchantsshop'])) { + $shop['customenchantsshop'] = []; + } $this->shop->setAll($shop); $this->shop->save(); $this->shop->reload(); @@ -74,136 +85,306 @@ public function UpdateConfig(): void{ } } - /** - * @param Player $player - */ - public function listForm(Player $player): void{ - $form = new SimpleForm(function (Player $player, $data = null){ - if ($data === null){ - $this->sendNote($player , $this->shop->getNested('messages.thanks')); + public function onCommand(CommandSender $sender, Command $command, string $label, array $args): bool + { + if ($command->getName() === "eshop") { + if (!$sender->hasPermission("eshop.command")) { + $sender->sendMessage($this->shop->getNested('messages.no-perm', "§cYou don't have permission.")); + return true; + } + if (!$sender instanceof Player) { + $sender->sendMessage("§cPlease use this command in-game."); + return true; + } + $this->listForm($sender); + } + return false; + } + + public function listForm(Player $player): void + { + $shopData = $this->shop->getNested('shop', []); + $customShopData = $this->usePiggyCE ? $this->shop->getNested('customenchantsshop', []) : []; + + // اضافه کردن کلید 'custom' برای تشخیص آیتم‌های سفارشی + foreach ($customShopData as $key => $item) { + $customShopData[$key]['custom'] = true; + } + foreach ($shopData as $key => $item) { + $shopData[$key]['custom'] = false; + } + + $allItems = array_merge($shopData, $customShopData); + + $form = new SimpleForm(function (Player $player, $data = null) use ($allItems) { + if ($data === null) { + $this->sendNote($player, $this->shop->getNested('messages.thanks')); return; } - $this->buyForm($player, $data); + + $selectedItem = $allItems[$data] ?? null; + if ($selectedItem === null) return; + + if ($selectedItem['custom']) { + $this->buyCustomForm($player, $data); + } else { + $this->buyForm($player, $data); + } }); - foreach($this->shop->getNested('shop') as $name){ - $var = array( - "NAME" => $name['name'], - "PRICE" => $name['price'] - ); - $form->addButton($this->replace($this->shop->getNested('Button'), $var)); - } + $form->setTitle($this->shop->getNested('Title')); + + // اضافه کردن دکمه‌ها + foreach ($allItems as $item) { + $var = [ + "NAME" => $item['name'], + "PRICE" => $item['price'] + ]; + $buttonText = $item['custom'] ? "§6[CUSTOM] " . $this->replace($this->shop->getNested('Button'), $var) + : $this->replace($this->shop->getNested('Button'), $var); + + $form->addButton($buttonText); + } + $player->sendForm($form); } + + /** + * @param Player $player + * @param null|mixed|string $msg + * @param array $var + */ + public function sendNote(Player $player, $msg, array $var = []): void + { + if (!is_null($msg)) $player->sendMessage($this->replace($msg, $var)); + } + + /** + * @param string $message + * @param array $keys + * + * @return string + */ + public function replace(string $message, array $keys): string + { + foreach ($keys as $word => $value) { + $message = str_replace("{" . $word . "}", $value, $message); + } + return $message; + } + /** * @param Player $player * @param int $id */ - public function buyForm(Player $player,int $id): void{ + public function buyForm(Player $player, int $id): void + { $array = $this->shop->getNested('shop'); - $form = new CustomForm(function (Player $player, $data = null) use ($array, $id){ - if($data === null) { + if (!isset($array[$id])) { + $player->sendMessage("§cEnchantment not found!"); + return; + } + + $form = new CustomForm(function (Player $player, $data = null) use ($array, $id) { + if ($data === null) { return false; } + + $incompatible = $this->isCompatible($player, $array[$id]['incompatible-enchantments']); $var = array( "NAME" => $array[$id]['name'], "PRICE" => $array[$id]['price'] * $data[1], "LEVEL" => $data[1], "MONEY" => $this->eco->myMoney($player), - "INCOMPATIBLE" => $incompatible = $this->isCompatible($player, $array[$id]['incompatible-enchantments']) + "INCOMPATIBLE" => $incompatible ); - if ($data == null){ - $this->listForm($player); - return; - } - if(!$player->getInventory()->getItemInHand() instanceof Tool and !$player->getInventory()->getItemInHand() instanceof Armor){ - $this->sendNote($player ,$this->shop->getNested('messages.hold-item'), $var); - return; + + if (!$player->getInventory()->getItemInHand() instanceof Tool && !$player->getInventory()->getItemInHand() instanceof Armor) { + $this->sendNote($player, $this->shop->getNested('messages.hold-item'), $var); + return false; } - if(!is_null($incompatible)){ - $this->sendNote($player , $this->shop->getNested('messages.incompatible-enchantment'), $var); - return; + + if ($incompatible !== false) { + $this->sendNote($player, $this->shop->getNested('messages.incompatible-enchantment'), $var); + return false; } - if($data[1] > $array[$id]['max-level'] or $data[1] < 1){ - return; + + if ($data[1] > $array[$id]['max-level'] || $data[1] < 1) { + $player->sendMessage("§cInvalid enchantment level!"); + return false; } - if($this->eco->myMoney($player) > $c = $array[$id]['price'] * $data[1]){ - $this->eco->reduceMoney($player, $c); + + $cost = $array[$id]['price'] * $data[1]; + if ($this->eco->myMoney($player) >= $cost) { + $this->eco->reduceMoney($player, $cost); $this->enchantItem($player, $data[1], $array[$id]['enchantment']); - $this->sendNote($player ,$this->shop->getNested('messages.paid-success'), $var); - }else{ - $this->sendNote($player , $this->shop->getNested('messages.not-enough-money'), $var); + $this->sendNote($player, $this->shop->getNested('messages.paid-success'), $var); + } else { + $this->sendNote($player, $this->shop->getNested('messages.not-enough-money'), $var); } - } - ); - $form->addLabel($this->replace($this->shop->getNested('messages.label'),["PRICE" => $array[$id]['price']])); + return false; + }); + $form->setTitle($this->shop->getNested('Title')); - $form->addSlider($this->shop->getNested('slider-title'), 1, $array[$id]['max-level'], 1, -1); + $form->addLabel($this->replace($this->shop->getNested('messages.label'), ["PRICE" => $array[$id]['price']])); + $form->addSlider($this->shop->getNested('slider-title'), 1, $array[$id]['max-level'], 1, 1); $player->sendForm($form); } /** * @param Player $player - * @param null|mixed|string $msg + * @param int $id */ - public function sendNote(Player $player, $msg, array $var = []): void{ - if(!is_null($msg)) $player->sendMessage($this->replace($msg, $var)); + public function buyCustomForm(Player $player, int $id): void + { + if (!$this->usePiggyCE) { + $player->sendMessage("§cCustom enchantments are disabled!"); + return; + } + + $array = $this->shop->getNested('customenchantsshop'); + if (!isset($array[$id])) { + $player->sendMessage("§cCustom enchantment not found!"); + return; + } + + $form = new CustomForm(function (Player $player, $data = null) use ($array, $id) { + if ($data === null) { + return false; + } + + $incompatible = $this->isCustomCompatible($player, $array[$id]['incompatible-enchantments']); + $var = array( + "NAME" => $array[$id]['name'], + "PRICE" => $array[$id]['price'] * $data[1], + "LEVEL" => $data[1], + "MONEY" => $this->eco->myMoney($player), + "INCOMPATIBLE" => $incompatible + ); + + if (!$player->getInventory()->getItemInHand() instanceof Tool && !$player->getInventory()->getItemInHand() instanceof Armor) { + $this->sendNote($player, $this->shop->getNested('messages.hold-item'), $var); + return false; + } + + if ($incompatible !== false) { + $this->sendNote($player, $this->shop->getNested('messages.incompatible-enchantment'), $var); + return false; + } + + if ($data[1] > $array[$id]['max-level'] || $data[1] < 1) { + $player->sendMessage("§cInvalid enchantment level!"); + return false; + } + + $cost = $array[$id]['price'] * $data[1]; + if ($this->eco->myMoney($player) >= $cost) { + $this->eco->reduceMoney($player, $cost); + $this->enchantItem($player, $data[1], $array[$id]['enchantment']); + $this->sendNote($player, $this->shop->getNested('messages.paid-success'), $var); + } else { + $this->sendNote($player, $this->shop->getNested('messages.not-enough-money'), $var); + } + return false; + }); + + $form->setTitle("§6Custom " . $this->shop->getNested('Title')); + $form->addLabel($this->replace($this->shop->getNested('messages.label'), ["PRICE" => $array[$id]['price']])); + $form->addSlider($this->shop->getNested('slider-title'), 1, $array[$id]['max-level'], 1, 1); + $player->sendForm($form); } /** * @param Player $player - * @param int $level - * @param int|String $enchantment + * @param array $incompatibleEnchantments + * + * @return int|false */ - public function enchantItem(Player $player, int $level, $enchantment): void{ + public function isCompatible(Player $player, array $incompatibleEnchantments) + { $item = $player->getInventory()->getItemInHand(); - if(is_string($enchantment)){ - $ench = EnchantmentIdMap::getInstance()->fromId((string) $enchantment); - if($this->piggyCE !== null && $ench === null){ - $ench = CustomEnchants::getEnchantmentByName((string) $enchantment); - } - if($this->piggyCE !== null && $ench instanceof CustomEnchants){ - $this->piggyCE->addEnchantment($item, $ench->getName(), (int) $level); - }else{ - $item->addEnchantment(new EnchantmentInstance($ench, (int) $level)); - } + + if (empty($incompatibleEnchantments)) { + return false; } - if(is_int($enchantment)){ - $ench = EnchantmentIdMap::getInstance()->fromId($enchantment); - $item->addEnchantment(new EnchantmentInstance($ench, (int) $level)); + + foreach ($item->getEnchantments() as $enchantmentInstance) { + $enchantmentId = EnchantmentIdMap::getInstance()->toId($enchantmentInstance->getType()); + + if (in_array($enchantmentId, $incompatibleEnchantments)) { + return $enchantmentId; + } } - $player->getInventory()->setItemInHand($item); + + return false; + } + + /** + * Check compatibility for custom enchantments + */ + public function isCustomCompatible(Player $player, array $incompatibleEnchantments): bool + { + // For custom enchantments, we'll need a different approach + // This is a placeholder - you might need to implement custom compatibility checking + return false; } /** * @param Player $player - * @param array $array - * - * @return int|mixed|null + * @param int $level + * @param int|string $enchantment */ - public function isCompatible(Player $player,array $array){ + public function enchantItem(Player $player, int $level, $enchantment): void + { $item = $player->getInventory()->getItemInHand(); - //TODO: the ability to use strings - foreach($array as $enchantment){ - if($item->hasEnchantment($enchantment)){ - $id = $enchantment; - return $id; - } + + // Handle PiggyCustomEnchants if available and enchantment is a string + if ($this->usePiggyCE && $this->piggyCE !== null && is_string($enchantment)) { + $this->applyCustomEnchantment($player, $item, $level, $enchantment); + return; } + + // Handle vanilla enchantments + $this->applyVanillaEnchantment($player, $item, $level, $enchantment); } /** - * @param string $message - * @param array $keys - * - * @return string + * Apply vanilla Minecraft enchantment */ - public function replace(string $message, array $keys): string{ - foreach($keys as $word => $value){ - $message = str_replace("{".$word."}", $value, $message); + private function applyVanillaEnchantment(Player $player, $item, int $level, $enchantment): void + { + $enchantmentId = is_numeric($enchantment) ? (int)$enchantment : $enchantment; + $ench = EnchantmentIdMap::getInstance()->fromId($enchantmentId); + + if ($ench !== null) { + $enchantmentInstance = new EnchantmentInstance($ench, $level); + $item->addEnchantment($enchantmentInstance); + $player->getInventory()->setItemInHand($item); + } else { + $player->sendMessage("§cFailed to apply enchantment: Invalid enchantment ID"); } - return $message; } -} + /** + * Apply PiggyCustomEnchants enchantment + */ + private function applyCustomEnchantment(Player $player, $item, int $level, string $enchantmentName): void + { + try { + $reflectionClass = new \ReflectionClass($this->piggyCE); + + if ($reflectionClass->hasMethod('addEnchantment')) { + $method = $reflectionClass->getMethod('addEnchantment'); + $method->invoke($this->piggyCE, $item, $enchantmentName, $level); + $player->getInventory()->setItemInHand($item); + return; + } + + $player->sendMessage("§cFailed to apply custom enchantment"); + + } catch (\ReflectionException $e) { + $player->sendMessage("§cError applying custom enchantment"); + } + } +} diff --git a/src/ItsRealNise/EnchantedUI/libs/jojoe77777/FormAPI/CustomForm.php b/src/ItsRealNise/EnchantedUI/libs/jojoe77777/FormAPI/CustomForm.php deleted file mode 100644 index 58d5eb6..0000000 --- a/src/ItsRealNise/EnchantedUI/libs/jojoe77777/FormAPI/CustomForm.php +++ /dev/null @@ -1,132 +0,0 @@ -data["type"] = "custom_form"; - $this->data["title"] = ""; - $this->data["content"] = []; - } - - public function processData(&$data) : void { - if(is_array($data)) { - $new = []; - foreach ($data as $i => $v) { - $new[$this->labelMap[$i]] = $v; - } - $data = $new; - } - } - - /** - * @param string $title - */ - public function setTitle(string $title) : void { - $this->data["title"] = $title; - } - - /** - * @return string - */ - public function getTitle() : string { - return $this->data["title"]; - } - - /** - * @param string $text - * @param string|null $label - */ - public function addLabel(string $text, ?string $label = null) : void { - $this->addContent(["type" => "label", "text" => $text]); - $this->labelMap[] = $label ?? count($this->labelMap); - } - - /** - * @param string $text - * @param bool|null $default - * @param string|null $label - */ - public function addToggle(string $text, bool $default = null, ?string $label = null) : void { - $content = ["type" => "toggle", "text" => $text]; - if($default !== null) { - $content["default"] = $default; - } - $this->addContent($content); - $this->labelMap[] = $label ?? count($this->labelMap); - } - - /** - * @param string $text - * @param int $min - * @param int $max - * @param int $step - * @param int $default - * @param string|null $label - */ - public function addSlider(string $text, int $min, int $max, int $step = -1, int $default = -1, ?string $label = null) : void { - $content = ["type" => "slider", "text" => $text, "min" => $min, "max" => $max]; - if($step !== -1) { - $content["step"] = $step; - } - if($default !== -1) { - $content["default"] = $default; - } - $this->addContent($content); - $this->labelMap[] = $label ?? count($this->labelMap); - } - - /** - * @param string $text - * @param array $steps - * @param int $defaultIndex - * @param string|null $label - */ - public function addStepSlider(string $text, array $steps, int $defaultIndex = -1, ?string $label = null) : void { - $content = ["type" => "step_slider", "text" => $text, "steps" => $steps]; - if($defaultIndex !== -1) { - $content["default"] = $defaultIndex; - } - $this->addContent($content); - $this->labelMap[] = $label ?? count($this->labelMap); - } - - /** - * @param string $text - * @param array $options - * @param int $default - * @param string|null $label - */ - public function addDropdown(string $text, array $options, int $default = null, ?string $label = null) : void { - $this->addContent(["type" => "dropdown", "text" => $text, "options" => $options, "default" => $default]); - $this->labelMap[] = $label ?? count($this->labelMap); - } - - /** - * @param string $text - * @param string $placeholder - * @param string $default - * @param string|null $label - */ - public function addInput(string $text, string $placeholder = "", string $default = null, ?string $label = null) : void { - $this->addContent(["type" => "input", "text" => $text, "placeholder" => $placeholder, "default" => $default]); - $this->labelMap[] = $label ?? count($this->labelMap); - } - - /** - * @param array $content - */ - private function addContent(array $content) : void { - $this->data["content"][] = $content; - } - -} diff --git a/src/ItsRealNise/EnchantedUI/libs/jojoe77777/FormAPI/Form.php b/src/ItsRealNise/EnchantedUI/libs/jojoe77777/FormAPI/Form.php deleted file mode 100644 index 0dcc6f8..0000000 --- a/src/ItsRealNise/EnchantedUI/libs/jojoe77777/FormAPI/Form.php +++ /dev/null @@ -1,56 +0,0 @@ -callable = $callable; - } - - /** - * @deprecated - * @see Player::sendForm() - * - * @param Player $player - */ - public function sendToPlayer(Player $player) : void { - $player->sendForm($this); - } - - public function getCallable() : ?callable { - return $this->callable; - } - - public function setCallable(?callable $callable) { - $this->callable = $callable; - } - - public function handleResponse(Player $player, $data) : void { - $this->processData($data); - $callable = $this->getCallable(); - if($callable !== null) { - $callable($player, $data); - } - } - - public function processData(&$data) : void { - } - - public function jsonSerialize(){ - return $this->data; - } -} diff --git a/src/ItsRealNise/EnchantedUI/libs/jojoe77777/FormAPI/FormAPI.php b/src/ItsRealNise/EnchantedUI/libs/jojoe77777/FormAPI/FormAPI.php deleted file mode 100644 index 1993dec..0000000 --- a/src/ItsRealNise/EnchantedUI/libs/jojoe77777/FormAPI/FormAPI.php +++ /dev/null @@ -1,40 +0,0 @@ -data["type"] = "modal"; - $this->data["title"] = ""; - $this->data["content"] = $this->content; - $this->data["button1"] = ""; - $this->data["button2"] = ""; - } - - /** - * @param string $title - */ - public function setTitle(string $title) : void { - $this->data["title"] = $title; - } - - /** - * @return string - */ - public function getTitle() : string { - return $this->data["title"]; - } - - /** - * @return string - */ - public function getContent() : string { - return $this->data["content"]; - } - - /** - * @param string $content - */ - public function setContent(string $content) : void { - $this->data["content"] = $content; - } - - /** - * @param string $text - */ - public function setButton1(string $text) : void { - $this->data["button1"] = $text; - } - - /** - * @return string - */ - public function getButton1() : string { - return $this->data["button1"]; - } - - /** - * @param string $text - */ - public function setButton2(string $text) : void { - $this->data["button2"] = $text; - } - - /** - * @return string - */ - public function getButton2() : string { - return $this->data["button2"]; - } -} diff --git a/src/ItsRealNise/EnchantedUI/libs/jojoe77777/FormAPI/SimpleForm.php b/src/ItsRealNise/EnchantedUI/libs/jojoe77777/FormAPI/SimpleForm.php deleted file mode 100644 index 6358d8e..0000000 --- a/src/ItsRealNise/EnchantedUI/libs/jojoe77777/FormAPI/SimpleForm.php +++ /dev/null @@ -1,75 +0,0 @@ -data["type"] = "form"; - $this->data["title"] = ""; - $this->data["content"] = $this->content; - } - - public function processData(&$data) : void { - $data = $this->labelMap[$data] ?? null; - } - - /** - * @param string $title - */ - public function setTitle(string $title) : void { - $this->data["title"] = $title; - } - - /** - * @return string - */ - public function getTitle() : string { - return $this->data["title"]; - } - - /** - * @return string - */ - public function getContent() : string { - return $this->data["content"]; - } - - /** - * @param string $content - */ - public function setContent(string $content) : void { - $this->data["content"] = $content; - } - - /** - * @param string $text - * @param int $imageType - * @param string $imagePath - * @param string $label - */ - public function addButton(string $text, int $imageType = -1, string $imagePath = "", ?string $label = null) : void { - $content = ["text" => $text]; - if($imageType !== -1) { - $content["image"]["type"] = $imageType === 0 ? "path" : "url"; - $content["image"]["data"] = $imagePath; - } - $this->data["buttons"][] = $content; - $this->labelMap[] = $label ?? count($this->labelMap); - } - -}