From ca33dab3b4acc71106d1b7392392fc49cb040a7e Mon Sep 17 00:00:00 2001 From: Hossein Rezaee Date: Wed, 9 Apr 2025 12:57:53 +0330 Subject: [PATCH 01/21] Update README.md Update README.md --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 8e66e99..577d9b8 100644 --- a/README.md +++ b/README.md @@ -3,4 +3,4 @@ A simple enchant shop ui # Required: -• EconomyAPI by onebone +• EconomyAPI by onebone(https://github.com/mathchat900/EconomyAPI-PM5) From 1f996c12e0a51e6c477bd775c319e2721948dac1 Mon Sep 17 00:00:00 2001 From: Hossein Rezaee Date: Wed, 9 Apr 2025 12:58:32 +0330 Subject: [PATCH 02/21] Update README.md Update README.md --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 577d9b8..8ff9245 100644 --- a/README.md +++ b/README.md @@ -3,4 +3,4 @@ A simple enchant shop ui # Required: -• EconomyAPI by onebone(https://github.com/mathchat900/EconomyAPI-PM5) +• EconomyAPI by onebone [EconomyAPI PM](https://github.com/mathchat900/EconomyAPI-PM5) From 4d4330b68117b8d837d3f79dfaaa2f9100dbd25e Mon Sep 17 00:00:00 2001 From: Hossein Rezaee Date: Wed, 9 Apr 2025 13:27:58 +0330 Subject: [PATCH 03/21] Update plugin.yml Update plugin.yml to PM5 --- plugin.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/plugin.yml b/plugin.yml index 2ab152a..33fd4aa 100644 --- a/plugin.yml +++ b/plugin.yml @@ -2,9 +2,9 @@ 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 permissions: eshop.command: default: true From c6183c2adad6441580be60cbf0d22f39207799f5 Mon Sep 17 00:00:00 2001 From: Hossein Rezaee Date: Wed, 9 Apr 2025 13:28:34 +0330 Subject: [PATCH 04/21] Update README.md Update README.md --- README.md | 22 +++++++++++++++++++--- 1 file changed, 19 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index 8ff9245..14d03e2 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
+



+![Screenshot of a comment on a GitHub issue showing an image, added in the Markdown, of an Octocat smiling and raising a tentacle.](logo.png) -# Required: +# Depends: +• **EconomyAPI** by **onebone** updated by **mathchat900** [EconomyAPI PM5](https://github.com/mathchat900/EconomyAPI-PM5) -• EconomyAPI by onebone [EconomyAPI PM](https://github.com/mathchat900/EconomyAPI-PM5) +# 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
From 7c2f34913dcc088d360e8595e075c9bfbafc3675 Mon Sep 17 00:00:00 2001 From: Hossein Rezaee Date: Wed, 9 Apr 2025 13:31:41 +0330 Subject: [PATCH 05/21] Update README.md Update README.md --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 14d03e2..06bbe57 100644 --- a/README.md +++ b/README.md @@ -1,7 +1,7 @@ # EnchantedUI A simple enchant shop ui updated by HosseinYT




-![Screenshot of a comment on a GitHub issue showing an image, added in the Markdown, of an Octocat smiling and raising a tentacle.](logo.png) +Discord server # Depends: • **EconomyAPI** by **onebone** updated by **mathchat900** [EconomyAPI PM5](https://github.com/mathchat900/EconomyAPI-PM5) From ba71bf275a0a79a0f71e69911a06cdf1af3fd4fd Mon Sep 17 00:00:00 2001 From: Hossein Rezaee Date: Wed, 9 Apr 2025 13:33:52 +0330 Subject: [PATCH 06/21] Update README.md Update README.md --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 06bbe57..a789a45 100644 --- a/README.md +++ b/README.md @@ -1,7 +1,7 @@ # EnchantedUI A simple enchant shop ui updated by HosseinYT




-Discord server +Plugin Icon # Depends: • **EconomyAPI** by **onebone** updated by **mathchat900** [EconomyAPI PM5](https://github.com/mathchat900/EconomyAPI-PM5) From fc63640bfdba3850fa6cd36bd75d10a6d48cbc00 Mon Sep 17 00:00:00 2001 From: Hossein Rezaee Date: Wed, 9 Apr 2025 13:37:13 +0330 Subject: [PATCH 07/21] Delete .poggit.yml Delete .poggit.yml --- .poggit.yml | 9 --------- 1 file changed, 9 deletions(-) delete mode 100644 .poggit.yml 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 -... From a11bbaef49de93f39fe3c648f50917028758ba6f Mon Sep 17 00:00:00 2001 From: Hossein Rezaee Date: Wed, 9 Apr 2025 13:38:12 +0330 Subject: [PATCH 08/21] Update Main.php Update Main.php --- src/ItsRealNise/EnchantedUI/Main.php | 21 +++++++++++---------- 1 file changed, 11 insertions(+), 10 deletions(-) diff --git a/src/ItsRealNise/EnchantedUI/Main.php b/src/ItsRealNise/EnchantedUI/Main.php index b4a93d5..b35d978 100644 --- a/src/ItsRealNise/EnchantedUI/Main.php +++ b/src/ItsRealNise/EnchantedUI/Main.php @@ -73,17 +73,14 @@ public function UpdateConfig(): void{ return; } } - - /** - * @param Player $player - */ - public function listForm(Player $player): void{ + public function listForm(Player $player): SimpleForm { $form = new SimpleForm(function (Player $player, $data = null){ if ($data === null){ $this->sendNote($player , $this->shop->getNested('messages.thanks')); - return; + return false; } $this->buyForm($player, $data); + return false; }); foreach($this->shop->getNested('shop') as $name){ $var = array( @@ -94,6 +91,7 @@ public function listForm(Player $player): void{ } $form->setTitle($this->shop->getNested('Title')); $player->sendForm($form); + return $form; } /** @@ -115,18 +113,18 @@ public function buyForm(Player $player,int $id): void{ ); if ($data == null){ $this->listForm($player); - return; + return false; } if(!$player->getInventory()->getItemInHand() instanceof Tool and !$player->getInventory()->getItemInHand() instanceof Armor){ $this->sendNote($player ,$this->shop->getNested('messages.hold-item'), $var); - return; + return false; } if(!is_null($incompatible)){ $this->sendNote($player , $this->shop->getNested('messages.incompatible-enchantment'), $var); - return; + return false; } if($data[1] > $array[$id]['max-level'] or $data[1] < 1){ - return; + return false; } if($this->eco->myMoney($player) > $c = $array[$id]['price'] * $data[1]){ $this->eco->reduceMoney($player, $c); @@ -135,6 +133,7 @@ public function buyForm(Player $player,int $id): void{ }else{ $this->sendNote($player , $this->shop->getNested('messages.not-enough-money'), $var); } + return false; } ); $form->addLabel($this->replace($this->shop->getNested('messages.label'),["PRICE" => $array[$id]['price']])); @@ -146,6 +145,7 @@ public function buyForm(Player $player,int $id): void{ /** * @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)); @@ -191,6 +191,7 @@ public function isCompatible(Player $player,array $array){ return $id; } } + return false; } /** From ec4a4f933f67a2714d8d011c02e4d2dfadd572af Mon Sep 17 00:00:00 2001 From: Hossein Rezaee Date: Wed, 9 Apr 2025 13:38:31 +0330 Subject: [PATCH 09/21] Update EventListener.php Update EventListener.php --- src/ItsRealNise/EnchantedUI/EventListener.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) 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){ From 81e00c97af93d11aa4ae9c8f04b9b4e2f450b89e Mon Sep 17 00:00:00 2001 From: Hossein Rezaee Date: Wed, 9 Apr 2025 13:38:56 +0330 Subject: [PATCH 10/21] Update ShopCommand.php Update ShopCommand.php --- src/ItsRealNise/EnchantedUI/Commands/ShopCommand.php | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/src/ItsRealNise/EnchantedUI/Commands/ShopCommand.php b/src/ItsRealNise/EnchantedUI/Commands/ShopCommand.php index 5a659bc..38c8636 100644 --- a/src/ItsRealNise/EnchantedUI/Commands/ShopCommand.php +++ b/src/ItsRealNise/EnchantedUI/Commands/ShopCommand.php @@ -1,6 +1,7 @@ sendMessage("Please use this in-game."); return true; - }*/ - $this->plugin->listForm($sender); + }*/ + if ($sender instanceof Player) { + $this->plugin->listForm($sender); + } return true; } From f5f35d39fa44929a97a74a1666454ec8d6a11b41 Mon Sep 17 00:00:00 2001 From: Hossein Rezaee Date: Wed, 9 Apr 2025 13:39:46 +0330 Subject: [PATCH 11/21] Delete src/ItsRealNise/EnchantedUI/libs directory Delete src/ItsRealNise/EnchantedUI/libs directory --- .../libs/jojoe77777/FormAPI/CustomForm.php | 132 ------------------ .../libs/jojoe77777/FormAPI/Form.php | 56 -------- .../libs/jojoe77777/FormAPI/FormAPI.php | 40 ------ .../libs/jojoe77777/FormAPI/ModalForm.php | 79 ----------- .../libs/jojoe77777/FormAPI/SimpleForm.php | 75 ---------- 5 files changed, 382 deletions(-) delete mode 100644 src/ItsRealNise/EnchantedUI/libs/jojoe77777/FormAPI/CustomForm.php delete mode 100644 src/ItsRealNise/EnchantedUI/libs/jojoe77777/FormAPI/Form.php delete mode 100644 src/ItsRealNise/EnchantedUI/libs/jojoe77777/FormAPI/FormAPI.php delete mode 100644 src/ItsRealNise/EnchantedUI/libs/jojoe77777/FormAPI/ModalForm.php delete mode 100644 src/ItsRealNise/EnchantedUI/libs/jojoe77777/FormAPI/SimpleForm.php 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); - } - -} From 32a364c1238e5d6d749aa125fef212e9b9623089 Mon Sep 17 00:00:00 2001 From: Hossein Rezaee Date: Wed, 9 Apr 2025 13:40:50 +0330 Subject: [PATCH 12/21] Update FormAPI Update FormAPI --- .../libs/jojoe77777/FormAPI/CustomForm.php | 170 ++++++++++++++++++ .../libs/jojoe77777/FormAPI/Form.php | 57 ++++++ .../libs/jojoe77777/FormAPI/FormAPI.php | 11 ++ .../libs/jojoe77777/FormAPI/ModalForm.php | 95 ++++++++++ .../libs/jojoe77777/FormAPI/SimpleForm.php | 93 ++++++++++ 5 files changed, 426 insertions(+) create mode 100644 src/ItsRealNise/EnchantedUI/libs/jojoe77777/FormAPI/CustomForm.php create mode 100644 src/ItsRealNise/EnchantedUI/libs/jojoe77777/FormAPI/Form.php create mode 100644 src/ItsRealNise/EnchantedUI/libs/jojoe77777/FormAPI/FormAPI.php create mode 100644 src/ItsRealNise/EnchantedUI/libs/jojoe77777/FormAPI/ModalForm.php create mode 100644 src/ItsRealNise/EnchantedUI/libs/jojoe77777/FormAPI/SimpleForm.php diff --git a/src/ItsRealNise/EnchantedUI/libs/jojoe77777/FormAPI/CustomForm.php b/src/ItsRealNise/EnchantedUI/libs/jojoe77777/FormAPI/CustomForm.php new file mode 100644 index 0000000..4a86620 --- /dev/null +++ b/src/ItsRealNise/EnchantedUI/libs/jojoe77777/FormAPI/CustomForm.php @@ -0,0 +1,170 @@ +data["type"] = "custom_form"; + $this->data["title"] = ""; + $this->data["content"] = []; + } + + public function processData(&$data) : void { + if($data !== null && !is_array($data)) { + throw new FormValidationException("Expected an array response, got " . gettype($data)); + } + if(is_array($data)) { + if(count($data) !== count($this->validationMethods)) { + throw new FormValidationException("Expected an array response with the size " . count($this->validationMethods) . ", got " . count($data)); + } + $new = []; + foreach($data as $i => $v) { + $validationMethod = $this->validationMethods[$i] ?? null; + if($validationMethod === null) { + throw new FormValidationException("Invalid element " . $i); + } + if(!$validationMethod($v)) { + throw new FormValidationException("Invalid type given for element " . $this->labelMap[$i]); + } + $new[$this->labelMap[$i]] = $v; + } + $data = $new; + } + } + + /** + * @param string $title + * @return $this + */ + public function setTitle(string $title) : self { + $this->data["title"] = $title; + return $this; + } + + /** + * @return string + */ + public function getTitle() : string { + return $this->data["title"]; + } + + /** + * @param string $text + * @param string|null $label + * @return $this + */ + public function addLabel(string $text, ?string $label = null) : self { + $this->addContent(["type" => "label", "text" => $text]); + $this->labelMap[] = $label ?? count($this->labelMap); + $this->validationMethods[] = static fn($v) => $v === null; + return $this; + } + + /** + * @param string $text + * @param bool|null $default + * @param string|null $label + * @return $this + */ + public function addToggle(string $text, bool $default = null, ?string $label = null) : self { + $content = ["type" => "toggle", "text" => $text]; + if($default !== null) { + $content["default"] = $default; + } + $this->addContent($content); + $this->labelMap[] = $label ?? count($this->labelMap); + $this->validationMethods[] = static fn($v) => is_bool($v); + return $this; + } + + /** + * @param string $text + * @param int $min + * @param int $max + * @param int $step + * @param int $default + * @param string|null $label + * @return $this + */ + public function addSlider(string $text, int $min, int $max, int $step = -1, int $default = -1, ?string $label = null) : self { + $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); + $this->validationMethods[] = static fn($v) => (is_float($v) || is_int($v)) && $v >= $min && $v <= $max; + return $this; + } + + /** + * @param string $text + * @param array $steps + * @param int $defaultIndex + * @param string|null $label + * @return $this + */ + public function addStepSlider(string $text, array $steps, int $defaultIndex = -1, ?string $label = null) : self { + $content = ["type" => "step_slider", "text" => $text, "steps" => $steps]; + if($defaultIndex !== -1) { + $content["default"] = $defaultIndex; + } + $this->addContent($content); + $this->labelMap[] = $label ?? count($this->labelMap); + $this->validationMethods[] = static fn($v) => is_int($v) && isset($steps[$v]); + return $this; + } + + /** + * @param string $text + * @param array $options + * @param int|null $default + * @param string|null $label + * @return $this + */ + public function addDropdown(string $text, array $options, int $default = null, ?string $label = null) : self { + $this->addContent(["type" => "dropdown", "text" => $text, "options" => $options, "default" => $default]); + $this->labelMap[] = $label ?? count($this->labelMap); + $this->validationMethods[] = static fn($v) => is_int($v) && isset($options[$v]); + return $this; + } + + /** + * @param string $text + * @param string $placeholder + * @param string|null $default + * @param string|null $label + * @return $this + */ + public function addInput(string $text, string $placeholder = "", string $default = null, ?string $label = null) : self { + $this->addContent(["type" => "input", "text" => $text, "placeholder" => $placeholder, "default" => $default]); + $this->labelMap[] = $label ?? count($this->labelMap); + $this->validationMethods[] = static fn($v) => is_string($v); + return $this; + } + + /** + * @param array $content + * @return $this + */ + private function addContent(array $content) : self { + $this->data["content"][] = $content; + return $this; + } + +} diff --git a/src/ItsRealNise/EnchantedUI/libs/jojoe77777/FormAPI/Form.php b/src/ItsRealNise/EnchantedUI/libs/jojoe77777/FormAPI/Form.php new file mode 100644 index 0000000..dd3c992 --- /dev/null +++ b/src/ItsRealNise/EnchantedUI/libs/jojoe77777/FormAPI/Form.php @@ -0,0 +1,57 @@ +callable = $callable; + } + + /** + * @param Player $player + * @throws InvalidArgumentException + * @deprecated + * @see Player::sendForm() + */ + 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() : array { + return $this->data; + } +} diff --git a/src/ItsRealNise/EnchantedUI/libs/jojoe77777/FormAPI/FormAPI.php b/src/ItsRealNise/EnchantedUI/libs/jojoe77777/FormAPI/FormAPI.php new file mode 100644 index 0000000..1b54003 --- /dev/null +++ b/src/ItsRealNise/EnchantedUI/libs/jojoe77777/FormAPI/FormAPI.php @@ -0,0 +1,11 @@ +data["type"] = "modal"; + $this->data["title"] = ""; + $this->data["content"] = $this->content; + $this->data["button1"] = ""; + $this->data["button2"] = ""; + } + + public function processData(&$data) : void { + if(!is_bool($data)) { + throw new FormValidationException("Expected a boolean response, got " . gettype($data)); + } + } + + /** + * @param string $title + * @return $this + */ + public function setTitle(string $title) : self { + $this->data["title"] = $title; + return $this; + } + + /** + * @return string + */ + public function getTitle() : string { + return $this->data["title"]; + } + + /** + * @return string + */ + public function getContent() : string { + return $this->data["content"]; + } + + /** + * @param string $content + * @return $this + */ + public function setContent(string $content) : self { + $this->data["content"] = $content; + return $this; + } + + /** + * @param string $text + * @return $this + */ + public function setButton1(string $text) : self { + $this->data["button1"] = $text; + return $this; + } + + /** + * @return string + */ + public function getButton1() : string { + return $this->data["button1"]; + } + + /** + * @param string $text + * @return $this + */ + public function setButton2(string $text) : self { + $this->data["button2"] = $text; + return $this; + } + + /** + * @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 new file mode 100644 index 0000000..490ce39 --- /dev/null +++ b/src/ItsRealNise/EnchantedUI/libs/jojoe77777/FormAPI/SimpleForm.php @@ -0,0 +1,93 @@ +data["type"] = "form"; + $this->data["title"] = ""; + $this->data["content"] = $this->content; + $this->data["buttons"] = []; + } + + public function processData(&$data) : void { + if($data !== null) { + if(!is_int($data)) { + throw new FormValidationException("Expected an integer response, got " . gettype($data)); + } + $count = count($this->data["buttons"]); + if($data >= $count || $data < 0) { + throw new FormValidationException("Button $data does not exist"); + } + $data = $this->labelMap[$data] ?? null; + } + } + + /** + * @param string $title + * @return $this + */ + public function setTitle(string $title) : self { + $this->data["title"] = $title; + return $this; + } + + /** + * @return string + */ + public function getTitle() : string { + return $this->data["title"]; + } + + /** + * @return string + */ + public function getContent() : string { + return $this->data["content"]; + } + + /** + * @param string $content + * @return $this + */ + public function setContent(string $content) : self { + $this->data["content"] = $content; + return $this; + } + + /** + * @param string $text + * @param int $imageType + * @param string $imagePath + * @param string|null $label + * @return $this + */ + public function addButton(string $text, int $imageType = -1, string $imagePath = "", ?string $label = null) : self { + $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); + return $this; + } + +} From be1adae7715bd949dec482ec9afac5887a204022 Mon Sep 17 00:00:00 2001 From: Hossein Rezaee Date: Wed, 9 Apr 2025 13:41:46 +0330 Subject: [PATCH 13/21] Update Shop.yml Update Shop.yml From 2ed9a35c0953e464d1abfcec32e9ad61dacae221 Mon Sep 17 00:00:00 2001 From: Hossein Rezaee Date: Sun, 14 Sep 2025 22:22:11 +0330 Subject: [PATCH 14/21] Add files via upload --- plugin.yml | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/plugin.yml b/plugin.yml index 33fd4aa..50058a4 100644 --- a/plugin.yml +++ b/plugin.yml @@ -5,6 +5,10 @@ version: "1.0" api: 5.0.0 load: POSTWORLD author: ItsRealNise updated by HosseinYT +commands: + eshop: + description: Enchant Menu + permission: eshop.command permissions: eshop.command: default: true From 37f6881de64ee16a05b4399a00a5ac110485cc76 Mon Sep 17 00:00:00 2001 From: Hossein Rezaee Date: Sun, 14 Sep 2025 22:23:00 +0330 Subject: [PATCH 15/21] Delete src/ItsRealNise/EnchantedUI/Commands directory --- .../EnchantedUI/Commands/ShopCommand.php | 56 ------------------- 1 file changed, 56 deletions(-) delete mode 100644 src/ItsRealNise/EnchantedUI/Commands/ShopCommand.php diff --git a/src/ItsRealNise/EnchantedUI/Commands/ShopCommand.php b/src/ItsRealNise/EnchantedUI/Commands/ShopCommand.php deleted file mode 100644 index 38c8636..0000000 --- a/src/ItsRealNise/EnchantedUI/Commands/ShopCommand.php +++ /dev/null @@ -1,56 +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; - }*/ - if ($sender instanceof Player) { - $this->plugin->listForm($sender); - } - return true; - } - - public function getOwningPlugin(): Plugin { - return $this->plugin; - } -} From a19901161abf2368e26ab69bdcbd353d8eb0c74a Mon Sep 17 00:00:00 2001 From: Hossein Rezaee Date: Sun, 14 Sep 2025 22:23:18 +0330 Subject: [PATCH 16/21] Delete src/ItsRealNise/EnchantedUI/libs/jojoe77777/FormAPI directory --- .../libs/jojoe77777/FormAPI/CustomForm.php | 170 ------------------ .../libs/jojoe77777/FormAPI/Form.php | 57 ------ .../libs/jojoe77777/FormAPI/FormAPI.php | 11 -- .../libs/jojoe77777/FormAPI/ModalForm.php | 95 ---------- .../libs/jojoe77777/FormAPI/SimpleForm.php | 93 ---------- 5 files changed, 426 deletions(-) delete mode 100644 src/ItsRealNise/EnchantedUI/libs/jojoe77777/FormAPI/CustomForm.php delete mode 100644 src/ItsRealNise/EnchantedUI/libs/jojoe77777/FormAPI/Form.php delete mode 100644 src/ItsRealNise/EnchantedUI/libs/jojoe77777/FormAPI/FormAPI.php delete mode 100644 src/ItsRealNise/EnchantedUI/libs/jojoe77777/FormAPI/ModalForm.php delete mode 100644 src/ItsRealNise/EnchantedUI/libs/jojoe77777/FormAPI/SimpleForm.php 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 4a86620..0000000 --- a/src/ItsRealNise/EnchantedUI/libs/jojoe77777/FormAPI/CustomForm.php +++ /dev/null @@ -1,170 +0,0 @@ -data["type"] = "custom_form"; - $this->data["title"] = ""; - $this->data["content"] = []; - } - - public function processData(&$data) : void { - if($data !== null && !is_array($data)) { - throw new FormValidationException("Expected an array response, got " . gettype($data)); - } - if(is_array($data)) { - if(count($data) !== count($this->validationMethods)) { - throw new FormValidationException("Expected an array response with the size " . count($this->validationMethods) . ", got " . count($data)); - } - $new = []; - foreach($data as $i => $v) { - $validationMethod = $this->validationMethods[$i] ?? null; - if($validationMethod === null) { - throw new FormValidationException("Invalid element " . $i); - } - if(!$validationMethod($v)) { - throw new FormValidationException("Invalid type given for element " . $this->labelMap[$i]); - } - $new[$this->labelMap[$i]] = $v; - } - $data = $new; - } - } - - /** - * @param string $title - * @return $this - */ - public function setTitle(string $title) : self { - $this->data["title"] = $title; - return $this; - } - - /** - * @return string - */ - public function getTitle() : string { - return $this->data["title"]; - } - - /** - * @param string $text - * @param string|null $label - * @return $this - */ - public function addLabel(string $text, ?string $label = null) : self { - $this->addContent(["type" => "label", "text" => $text]); - $this->labelMap[] = $label ?? count($this->labelMap); - $this->validationMethods[] = static fn($v) => $v === null; - return $this; - } - - /** - * @param string $text - * @param bool|null $default - * @param string|null $label - * @return $this - */ - public function addToggle(string $text, bool $default = null, ?string $label = null) : self { - $content = ["type" => "toggle", "text" => $text]; - if($default !== null) { - $content["default"] = $default; - } - $this->addContent($content); - $this->labelMap[] = $label ?? count($this->labelMap); - $this->validationMethods[] = static fn($v) => is_bool($v); - return $this; - } - - /** - * @param string $text - * @param int $min - * @param int $max - * @param int $step - * @param int $default - * @param string|null $label - * @return $this - */ - public function addSlider(string $text, int $min, int $max, int $step = -1, int $default = -1, ?string $label = null) : self { - $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); - $this->validationMethods[] = static fn($v) => (is_float($v) || is_int($v)) && $v >= $min && $v <= $max; - return $this; - } - - /** - * @param string $text - * @param array $steps - * @param int $defaultIndex - * @param string|null $label - * @return $this - */ - public function addStepSlider(string $text, array $steps, int $defaultIndex = -1, ?string $label = null) : self { - $content = ["type" => "step_slider", "text" => $text, "steps" => $steps]; - if($defaultIndex !== -1) { - $content["default"] = $defaultIndex; - } - $this->addContent($content); - $this->labelMap[] = $label ?? count($this->labelMap); - $this->validationMethods[] = static fn($v) => is_int($v) && isset($steps[$v]); - return $this; - } - - /** - * @param string $text - * @param array $options - * @param int|null $default - * @param string|null $label - * @return $this - */ - public function addDropdown(string $text, array $options, int $default = null, ?string $label = null) : self { - $this->addContent(["type" => "dropdown", "text" => $text, "options" => $options, "default" => $default]); - $this->labelMap[] = $label ?? count($this->labelMap); - $this->validationMethods[] = static fn($v) => is_int($v) && isset($options[$v]); - return $this; - } - - /** - * @param string $text - * @param string $placeholder - * @param string|null $default - * @param string|null $label - * @return $this - */ - public function addInput(string $text, string $placeholder = "", string $default = null, ?string $label = null) : self { - $this->addContent(["type" => "input", "text" => $text, "placeholder" => $placeholder, "default" => $default]); - $this->labelMap[] = $label ?? count($this->labelMap); - $this->validationMethods[] = static fn($v) => is_string($v); - return $this; - } - - /** - * @param array $content - * @return $this - */ - private function addContent(array $content) : self { - $this->data["content"][] = $content; - return $this; - } - -} 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 dd3c992..0000000 --- a/src/ItsRealNise/EnchantedUI/libs/jojoe77777/FormAPI/Form.php +++ /dev/null @@ -1,57 +0,0 @@ -callable = $callable; - } - - /** - * @param Player $player - * @throws InvalidArgumentException - * @deprecated - * @see Player::sendForm() - */ - 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() : array { - 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 1b54003..0000000 --- a/src/ItsRealNise/EnchantedUI/libs/jojoe77777/FormAPI/FormAPI.php +++ /dev/null @@ -1,11 +0,0 @@ -data["type"] = "modal"; - $this->data["title"] = ""; - $this->data["content"] = $this->content; - $this->data["button1"] = ""; - $this->data["button2"] = ""; - } - - public function processData(&$data) : void { - if(!is_bool($data)) { - throw new FormValidationException("Expected a boolean response, got " . gettype($data)); - } - } - - /** - * @param string $title - * @return $this - */ - public function setTitle(string $title) : self { - $this->data["title"] = $title; - return $this; - } - - /** - * @return string - */ - public function getTitle() : string { - return $this->data["title"]; - } - - /** - * @return string - */ - public function getContent() : string { - return $this->data["content"]; - } - - /** - * @param string $content - * @return $this - */ - public function setContent(string $content) : self { - $this->data["content"] = $content; - return $this; - } - - /** - * @param string $text - * @return $this - */ - public function setButton1(string $text) : self { - $this->data["button1"] = $text; - return $this; - } - - /** - * @return string - */ - public function getButton1() : string { - return $this->data["button1"]; - } - - /** - * @param string $text - * @return $this - */ - public function setButton2(string $text) : self { - $this->data["button2"] = $text; - return $this; - } - - /** - * @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 490ce39..0000000 --- a/src/ItsRealNise/EnchantedUI/libs/jojoe77777/FormAPI/SimpleForm.php +++ /dev/null @@ -1,93 +0,0 @@ -data["type"] = "form"; - $this->data["title"] = ""; - $this->data["content"] = $this->content; - $this->data["buttons"] = []; - } - - public function processData(&$data) : void { - if($data !== null) { - if(!is_int($data)) { - throw new FormValidationException("Expected an integer response, got " . gettype($data)); - } - $count = count($this->data["buttons"]); - if($data >= $count || $data < 0) { - throw new FormValidationException("Button $data does not exist"); - } - $data = $this->labelMap[$data] ?? null; - } - } - - /** - * @param string $title - * @return $this - */ - public function setTitle(string $title) : self { - $this->data["title"] = $title; - return $this; - } - - /** - * @return string - */ - public function getTitle() : string { - return $this->data["title"]; - } - - /** - * @return string - */ - public function getContent() : string { - return $this->data["content"]; - } - - /** - * @param string $content - * @return $this - */ - public function setContent(string $content) : self { - $this->data["content"] = $content; - return $this; - } - - /** - * @param string $text - * @param int $imageType - * @param string $imagePath - * @param string|null $label - * @return $this - */ - public function addButton(string $text, int $imageType = -1, string $imagePath = "", ?string $label = null) : self { - $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); - return $this; - } - -} From ac43313a18d19cdff3d74458a8e2dbc324095fc5 Mon Sep 17 00:00:00 2001 From: Hossein Rezaee Date: Sun, 14 Sep 2025 22:23:39 +0330 Subject: [PATCH 17/21] Add files via upload --- src/ItsRealNise/EnchantedUI/Main.php | 194 +++++++++++++++------------ 1 file changed, 105 insertions(+), 89 deletions(-) diff --git a/src/ItsRealNise/EnchantedUI/Main.php b/src/ItsRealNise/EnchantedUI/Main.php index b35d978..5c6cbb1 100644 --- a/src/ItsRealNise/EnchantedUI/Main.php +++ b/src/ItsRealNise/EnchantedUI/Main.php @@ -2,31 +2,23 @@ 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 DaPigGuy\PiggyCustomEnchants\CustomEnchants\CustomEnchants; +use ItsRealNise\EnchantedUI\libs\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; @@ -34,7 +26,8 @@ class Main extends PluginBase{ public $piggyCE; public $eco; - 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,24 +38,24 @@ 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"); } - 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['messages']['incompatible-enchantment'] = ''; - foreach($shop['shop'] as $list => $data){ + foreach ($shop['shop'] as $list => $data) { $data['incompatible-enchantments'] = array(); $shop['shop'][$list] = $data; } @@ -73,16 +66,34 @@ public function UpdateConfig(): void{ return; } } - public function listForm(Player $player): SimpleForm { - $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): SimpleForm + { + $form = new SimpleForm(function (Player $player, $data = null) { + if ($data === null) { + $this->sendNote($player, $this->shop->getNested('messages.thanks')); return false; } $this->buyForm($player, $data); return false; }); - foreach($this->shop->getNested('shop') as $name){ + foreach ($this->shop->getNested('shop') as $name) { $var = array( "NAME" => $name['name'], "PRICE" => $name['price'] @@ -94,14 +105,39 @@ public function listForm(Player $player): SimpleForm { return $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) { + $form = new CustomForm(function (Player $player, $data = null) use ($array, $id) { + if ($data === null) { return false; } $var = array( @@ -111,82 +147,49 @@ public function buyForm(Player $player,int $id): void{ "MONEY" => $this->eco->myMoney($player), "INCOMPATIBLE" => $incompatible = $this->isCompatible($player, $array[$id]['incompatible-enchantments']) ); - if ($data == null){ + if ($data == null) { $this->listForm($player); return false; } - if(!$player->getInventory()->getItemInHand() instanceof Tool and !$player->getInventory()->getItemInHand() instanceof Armor){ - $this->sendNote($player ,$this->shop->getNested('messages.hold-item'), $var); + if (!$player->getInventory()->getItemInHand() instanceof Tool and !$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); + if (!is_null($incompatible)) { + $this->sendNote($player, $this->shop->getNested('messages.incompatible-enchantment'), $var); return false; } - if($data[1] > $array[$id]['max-level'] or $data[1] < 1){ + if ($data[1] > $array[$id]['max-level'] or $data[1] < 1) { return false; } - if($this->eco->myMoney($player) > $c = $array[$id]['price'] * $data[1]){ + if ($this->eco->myMoney($player) > $c = $array[$id]['price'] * $data[1]) { $this->eco->reduceMoney($player, $c); $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); } return false; } ); - $form->addLabel($this->replace($this->shop->getNested('messages.label'),["PRICE" => $array[$id]['price']])); + $form->addLabel($this->replace($this->shop->getNested('messages.label'), ["PRICE" => $array[$id]['price']])); $form->setTitle($this->shop->getNested('Title')); $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 array $var - */ - public function sendNote(Player $player, $msg, array $var = []): void{ - if(!is_null($msg)) $player->sendMessage($this->replace($msg, $var)); - } - - /** - * @param Player $player - * @param int $level - * @param int|String $enchantment - */ - public function enchantItem(Player $player, int $level, $enchantment): void{ - $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(is_int($enchantment)){ - $ench = EnchantmentIdMap::getInstance()->fromId($enchantment); - $item->addEnchantment(new EnchantmentInstance($ench, (int) $level)); - } - $player->getInventory()->setItemInHand($item); - } - /** * @param Player $player * @param array $array * * @return int|mixed|null */ - public function isCompatible(Player $player,array $array){ + public function isCompatible(Player $player, array $array) + { $item = $player->getInventory()->getItemInHand(); //TODO: the ability to use strings - foreach($array as $enchantment){ - if($item->hasEnchantment($enchantment)){ + foreach ($array as $enchantment) { + if ($item->hasEnchantment($enchantment)) { $id = $enchantment; return $id; } @@ -195,16 +198,29 @@ public function isCompatible(Player $player,array $array){ } /** - * @param string $message - * @param array $keys - * - * @return string + * @param Player $player + * @param int $level + * @param int|String $enchantment */ - public function replace(string $message, array $keys): string{ - foreach($keys as $word => $value){ - $message = str_replace("{".$word."}", $value, $message); + public function enchantItem(Player $player, int $level, $enchantment): void + { + $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)); + } } - return $message; + if (is_int($enchantment)) { + $ench = EnchantmentIdMap::getInstance()->fromId($enchantment); + $item->addEnchantment(new EnchantmentInstance($ench, (int)$level)); + } + $player->getInventory()->setItemInHand($item); } } From c914b804df30db0524715cf395765984b3720e3f Mon Sep 17 00:00:00 2001 From: Hossein Rezaee Date: Tue, 16 Sep 2025 13:04:55 +0330 Subject: [PATCH 18/21] Update Main.php --- src/ItsRealNise/EnchantedUI/Main.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/ItsRealNise/EnchantedUI/Main.php b/src/ItsRealNise/EnchantedUI/Main.php index 5c6cbb1..125f144 100644 --- a/src/ItsRealNise/EnchantedUI/Main.php +++ b/src/ItsRealNise/EnchantedUI/Main.php @@ -3,7 +3,7 @@ namespace ItsRealNise\EnchantedUI; use DaPigGuy\PiggyCustomEnchants\CustomEnchants\CustomEnchants; -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; From 02b938fe7e5a9febd5a8349f74559e823fc67a8f Mon Sep 17 00:00:00 2001 From: Hossein Rezaee Date: Tue, 16 Sep 2025 13:05:31 +0330 Subject: [PATCH 19/21] Update plugin.yml --- plugin.yml | 1 + 1 file changed, 1 insertion(+) diff --git a/plugin.yml b/plugin.yml index 50058a4..a1ee5b3 100644 --- a/plugin.yml +++ b/plugin.yml @@ -5,6 +5,7 @@ version: "1.0" api: 5.0.0 load: POSTWORLD author: ItsRealNise updated by HosseinYT +depends: FormAPI commands: eshop: description: Enchant Menu From 3e128c8db143710e923e542efb68604d48dec3f7 Mon Sep 17 00:00:00 2001 From: Hossein Rezaee Date: Fri, 19 Sep 2025 18:21:13 +0330 Subject: [PATCH 20/21] Update Shop.yml --- resources/Shop.yml | 56 +++++++++++++++++++++++++++++----------------- 1 file changed, 36 insertions(+), 20 deletions(-) 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: [] From 807f9091add33feb2411e6c06257fc3051948445 Mon Sep 17 00:00:00 2001 From: Hossein Rezaee Date: Fri, 19 Sep 2025 18:21:42 +0330 Subject: [PATCH 21/21] Update Main.php --- src/ItsRealNise/EnchantedUI/Main.php | 270 +++++++++++++++++++++------ 1 file changed, 217 insertions(+), 53 deletions(-) diff --git a/src/ItsRealNise/EnchantedUI/Main.php b/src/ItsRealNise/EnchantedUI/Main.php index 125f144..ea39556 100644 --- a/src/ItsRealNise/EnchantedUI/Main.php +++ b/src/ItsRealNise/EnchantedUI/Main.php @@ -2,7 +2,6 @@ namespace ItsRealNise\EnchantedUI; -use DaPigGuy\PiggyCustomEnchants\CustomEnchants\CustomEnchants; use jojoe77777\FormAPI\{CustomForm, SimpleForm}; use onebone\economyapi\EconomyAPI; use pocketmine\command\Command; @@ -23,8 +22,9 @@ class Main extends PluginBase /** @var Config $shop */ public $shop; - public $piggyCE; public $eco; + public $piggyCE; + public $usePiggyCE; public function onEnable(): void { @@ -38,8 +38,21 @@ public function onEnable(): void $this->UpdateConfig(); $this->saveDefaultConfig(); $this->getServer()->getPluginManager()->registerEvents(new EventListener($this), $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 @@ -54,11 +67,16 @@ public function UpdateConfig(): void $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) { $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(); @@ -83,28 +101,55 @@ public function onCommand(CommandSender $sender, Command $command, string $label return false; } - public function listForm(Player $player): SimpleForm + public function listForm(Player $player): void { - $form = new SimpleForm(function (Player $player, $data = null) { + $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 false; + return; + } + + $selectedItem = $allItems[$data] ?? null; + if ($selectedItem === null) return; + + if ($selectedItem['custom']) { + $this->buyCustomForm($player, $data); + } else { + $this->buyForm($player, $data); } - $this->buyForm($player, $data); - return false; }); - 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); - return $form; } + /** * @param Player $player * @param null|mixed|string $msg @@ -136,91 +181,210 @@ public function replace(string $message, array $keys): string public function buyForm(Player $player, int $id): void { $array = $this->shop->getNested('shop'); + 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); + + 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($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 $id + */ + 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; } - if (!$player->getInventory()->getItemInHand() instanceof Tool and !$player->getInventory()->getItemInHand() instanceof Armor) { + + $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 (!is_null($incompatible)) { + + 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) { + + 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); } return false; - } - ); + }); + + $form->setTitle("§6Custom " . $this->shop->getNested('Title')); $form->addLabel($this->replace($this->shop->getNested('messages.label'), ["PRICE" => $array[$id]['price']])); - $form->setTitle($this->shop->getNested('Title')); - $form->addSlider($this->shop->getNested('slider-title'), 1, $array[$id]['max-level'], 1, -1); + $form->addSlider($this->shop->getNested('slider-title'), 1, $array[$id]['max-level'], 1, 1); $player->sendForm($form); } /** * @param Player $player - * @param array $array + * @param array $incompatibleEnchantments * - * @return int|mixed|null + * @return int|false */ - public function isCompatible(Player $player, array $array) + public function isCompatible(Player $player, array $incompatibleEnchantments) { $item = $player->getInventory()->getItemInHand(); - //TODO: the ability to use strings - foreach ($array as $enchantment) { - if ($item->hasEnchantment($enchantment)) { - $id = $enchantment; - return $id; + + if (empty($incompatibleEnchantments)) { + return false; + } + + foreach ($item->getEnchantments() as $enchantmentInstance) { + $enchantmentId = EnchantmentIdMap::getInstance()->toId($enchantmentInstance->getType()); + + if (in_array($enchantmentId, $incompatibleEnchantments)) { + return $enchantmentId; } } + + 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 int $level - * @param int|String $enchantment + * @param int|string $enchantment */ public function enchantItem(Player $player, int $level, $enchantment): void { $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)); - } + + // 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); + } + + /** + * Apply vanilla Minecraft enchantment + */ + 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"); } - if (is_int($enchantment)) { - $ench = EnchantmentIdMap::getInstance()->fromId($enchantment); - $item->addEnchantment(new EnchantmentInstance($ench, (int)$level)); + } + + /** + * 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"); } - $player->getInventory()->setItemInHand($item); } } -