From 4432e34dff07b4ae88b8a0c8a1f7e3af847ed670 Mon Sep 17 00:00:00 2001 From: impera Date: Sat, 1 Mar 2025 20:44:49 -0300 Subject: [PATCH 01/72] Due to the new custom components, this cheat is no longer necessary! --- .../item/traits/ItemRarityTrait.php | 32 ------------------- 1 file changed, 32 deletions(-) delete mode 100644 src/imperazim/components/item/traits/ItemRarityTrait.php diff --git a/src/imperazim/components/item/traits/ItemRarityTrait.php b/src/imperazim/components/item/traits/ItemRarityTrait.php deleted file mode 100644 index cb0cf13..0000000 --- a/src/imperazim/components/item/traits/ItemRarityTrait.php +++ /dev/null @@ -1,32 +0,0 @@ -rarity; - } - - /** @param string|null $rarity */ - public function setRarity(?string $rarity): void { - $this->rarity = $rarity; - } - -} \ No newline at end of file From bf8ac946309d5877a95c9a521561104903072985 Mon Sep 17 00:00:00 2001 From: impera Date: Sat, 1 Mar 2025 20:45:06 -0300 Subject: [PATCH 02/72] Due to the new custom components, this cheat is no longer necessary! --- README.md | 2 +- .../customies/item/ItemComponentsTrait.php | 54 ++++++++++++------- .../item/component/AttackDamageComponent.php | 25 +++++++++ .../item/component/RarityComponent.php | 32 +++++++++++ 4 files changed, 92 insertions(+), 21 deletions(-) create mode 100644 src/imperazim/vendor/customies/item/component/AttackDamageComponent.php create mode 100644 src/imperazim/vendor/customies/item/component/RarityComponent.php diff --git a/README.md b/README.md index e8e74a8..8c842a8 100644 --- a/README.md +++ b/README.md @@ -14,7 +14,7 @@ _The `EasyLibrary` is a powerful plugin for PocketMine-MP that serves as a colle To use EasyLibrary's features you can do it in 2 ways, use the one you find most interesting, I recommend using it as a plug for greater ease! - **As a plugin:** Being the simplest way where you just need to add EasyLibrary.phar to your server and it will start all the library components, you can modify which components you want to keep active in the plugin's `config.yml` if you want! -- **As a inyernal library:** You must add it inside the plugin's src, keeping it in the root src folder for everything to work normally. Using this method, you will have to start the components yourself in your main. +- **As a internal library:** You must add it inside the plugin's src, keeping it in the root src folder for everything to work normally. Using this method, you will have to start the components yourself in your main. ### Examples diff --git a/src/imperazim/vendor/customies/item/ItemComponentsTrait.php b/src/imperazim/vendor/customies/item/ItemComponentsTrait.php index 5baf048..4bc612f 100644 --- a/src/imperazim/vendor/customies/item/ItemComponentsTrait.php +++ b/src/imperazim/vendor/customies/item/ItemComponentsTrait.php @@ -3,36 +3,40 @@ namespace imperazim\vendor\customies\item; -use imperazim\vendor\customies\item\component\AllowOffHandComponent; -use imperazim\vendor\customies\item\component\ArmorComponent; -use imperazim\vendor\customies\item\component\CanDestroyInCreativeComponent; -use imperazim\vendor\customies\item\component\CooldownComponent; -use imperazim\vendor\customies\item\component\CreativeCategoryComponent; -use imperazim\vendor\customies\item\component\CreativeGroupComponent; -use imperazim\vendor\customies\item\component\DisplayNameComponent; -use imperazim\vendor\customies\item\component\DurabilityComponent; +use imperazim\vendor\customies\util\NBT; use imperazim\vendor\customies\item\component\FoodComponent; use imperazim\vendor\customies\item\component\FuelComponent; -use imperazim\vendor\customies\item\component\HandEquippedComponent; use imperazim\vendor\customies\item\component\IconComponent; use imperazim\vendor\customies\item\component\ItemComponent; -use imperazim\vendor\customies\item\component\MaxStackSizeComponent; -use imperazim\vendor\customies\item\component\ProjectileComponent; -use imperazim\vendor\customies\item\component\RenderOffsetsComponent; +use imperazim\vendor\customies\item\component\ArmorComponent; +use imperazim\vendor\customies\item\component\CooldownComponent; +use imperazim\vendor\customies\item\component\WearableComponent; use imperazim\vendor\customies\item\component\ThrowableComponent; -use imperazim\vendor\customies\item\component\UseAnimationComponent; +use imperazim\vendor\customies\item\component\ProjectileComponent; +use imperazim\vendor\customies\item\component\DurabilityComponent; use imperazim\vendor\customies\item\component\UseDurationComponent; -use imperazim\vendor\customies\item\component\WearableComponent; +use imperazim\vendor\customies\item\component\DisplayNameComponent; +use imperazim\vendor\customies\item\component\HandEquippedComponent; +use imperazim\vendor\customies\item\component\MaxStackSizeComponent; +use imperazim\vendor\customies\item\component\AttackDamageComponent; +use imperazim\vendor\customies\item\component\AllowOffHandComponent; +use imperazim\vendor\customies\item\component\UseAnimationComponent; +use imperazim\vendor\customies\item\component\RenderOffsetsComponent; +use imperazim\vendor\customies\item\component\CreativeGroupComponent; use imperazim\vendor\customies\item\component\LockInInventoryComponent; -use imperazim\vendor\customies\util\NBT; -use pocketmine\entity\Consumable; -use pocketmine\inventory\ArmorInventory; +use imperazim\vendor\customies\item\component\CreativeCategoryComponent; +use imperazim\vendor\customies\item\component\CanDestroyInCreativeComponent; + +use RuntimeException; +use pocketmine\item\Food; +use pocketmine\item\Tool; use pocketmine\item\Armor; +use pocketmine\item\Sword; use pocketmine\item\Durable; -use pocketmine\item\Food; use pocketmine\item\ProjectileItem; +use pocketmine\entity\Consumable; use pocketmine\nbt\tag\CompoundTag; -use RuntimeException; +use pocketmine\inventory\ArmorInventory; trait ItemComponentsTrait { @@ -70,7 +74,7 @@ public function getComponents(): CompoundTag { * Initializes the item with default components that are required for the item to function correctly. */ protected function initComponent(string $texture, ?CreativeInventoryInfo $creativeInfo = null): void { - $creativeInfo ??= CreativeInventoryInfo::DEFAULT(); + $creativeInfo ?? = CreativeInventoryInfo::DEFAULT(); $this->addComponent(new CreativeCategoryComponent($creativeInfo)); $this->addComponent(new CreativeGroupComponent($creativeInfo)); $this->addComponent(new CanDestroyInCreativeComponent()); @@ -113,6 +117,16 @@ protected function initComponent(string $texture, ?CreativeInventoryInfo $creati if ($this->getFuelTime() > 0) { $this->addComponent(new FuelComponent($this->getFuelTime())); } + if ($this->getAttackPoints() > 0) { + $this->addComponent(new AttackDamageComponent($this->getAttackPoints() - 1)); + } + + if ($this instanceof Tool) { + $this->addComponent(new HandEquippedComponent()); + if ($this instanceof Sword) { + $this->addComponent(new CanDestroyInCreativeComponent(false)); + } + } } /** diff --git a/src/imperazim/vendor/customies/item/component/AttackDamageComponent.php b/src/imperazim/vendor/customies/item/component/AttackDamageComponent.php new file mode 100644 index 0000000..b6b87e9 --- /dev/null +++ b/src/imperazim/vendor/customies/item/component/AttackDamageComponent.php @@ -0,0 +1,25 @@ +damage = $damage; + } + + public function getName(): string { + return "damage"; + } + + public function getValue(): int { + return $this->damage; + } + + public function isProperty(): bool { + return true; + } +} \ No newline at end of file diff --git a/src/imperazim/vendor/customies/item/component/RarityComponent.php b/src/imperazim/vendor/customies/item/component/RarityComponent.php new file mode 100644 index 0000000..d62205c --- /dev/null +++ b/src/imperazim/vendor/customies/item/component/RarityComponent.php @@ -0,0 +1,32 @@ +rarity = $rarity; + } + + public function getName(): string { + return "minecraft:rarity"; + } + + public function getValue(): array { + return [ + "value" => $this->rarity + ]; + } + + public function isProperty(): bool { + return false; + } +} \ No newline at end of file From 764b89a555309fd760d9b13de88862e63e1044ac Mon Sep 17 00:00:00 2001 From: impera Date: Sat, 1 Mar 2025 20:49:12 -0300 Subject: [PATCH 03/72] Fixes the icon texture not showing up --- src/imperazim/vendor/customies/item/component/IconComponent.php | 1 + 1 file changed, 1 insertion(+) diff --git a/src/imperazim/vendor/customies/item/component/IconComponent.php b/src/imperazim/vendor/customies/item/component/IconComponent.php index 0e90464..5e7c41e 100644 --- a/src/imperazim/vendor/customies/item/component/IconComponent.php +++ b/src/imperazim/vendor/customies/item/component/IconComponent.php @@ -17,6 +17,7 @@ public function getName(): string { public function getValue(): array { return [ + "texture" => $this->texture, "textures" => [ "default" => $this->texture ] From 0020ce9efcb49c9d24d983f8cfcdf9704db76850 Mon Sep 17 00:00:00 2001 From: impera Date: Sat, 1 Mar 2025 20:51:54 -0300 Subject: [PATCH 04/72] Modifiera component added. --- .../item/component/UseModifiersComponent.php | 24 +++++++++++++++++++ 1 file changed, 24 insertions(+) create mode 100644 src/imperazim/vendor/customies/item/component/UseModifiersComponent.php diff --git a/src/imperazim/vendor/customies/item/component/UseModifiersComponent.php b/src/imperazim/vendor/customies/item/component/UseModifiersComponent.php new file mode 100644 index 0000000..7b1cb488 --- /dev/null +++ b/src/imperazim/vendor/customies/item/component/UseModifiersComponent.php @@ -0,0 +1,24 @@ + $this->movementModifier, + "use_duration" => $this->useDuration + ]; + } + + public function isProperty(): bool { + return false; + } +} \ No newline at end of file From c721455ed7b73d6b6ea88b7cafcc87bbdb435313 Mon Sep 17 00:00:00 2001 From: impera Date: Sat, 1 Mar 2025 20:52:22 -0300 Subject: [PATCH 05/72] Modifiers component added. --- .../vendor/customies/item/component/UseModifiersComponent.php | 1 + 1 file changed, 1 insertion(+) diff --git a/src/imperazim/vendor/customies/item/component/UseModifiersComponent.php b/src/imperazim/vendor/customies/item/component/UseModifiersComponent.php index 7b1cb488..2fb32c3 100644 --- a/src/imperazim/vendor/customies/item/component/UseModifiersComponent.php +++ b/src/imperazim/vendor/customies/item/component/UseModifiersComponent.php @@ -21,4 +21,5 @@ public function getValue(): array { public function isProperty(): bool { return false; } + } \ No newline at end of file From c4b7f2e81d557d7b8de2b594727a56efe0dd85cc Mon Sep 17 00:00:00 2001 From: impera Date: Sat, 1 Mar 2025 21:57:50 -0300 Subject: [PATCH 06/72] BundleInteractionComponent Added. --- .../component/BundleInteractionComponent.php | 32 +++++++++++++++++++ 1 file changed, 32 insertions(+) create mode 100644 src/imperazim/vendor/customies/item/component/BundleInteractionComponent.php diff --git a/src/imperazim/vendor/customies/item/component/BundleInteractionComponent.php b/src/imperazim/vendor/customies/item/component/BundleInteractionComponent.php new file mode 100644 index 0000000..29f2bef --- /dev/null +++ b/src/imperazim/vendor/customies/item/component/BundleInteractionComponent.php @@ -0,0 +1,32 @@ +numViewableSlots = $numViewableSlots; + } + + public function getName(): string { + return "minecraft:bundle_interaction"; + } + + public function getValue(): array { + return [ + "num_viewable_slots" => $this->numViewableSlots + ]; + } + + public function isProperty(): bool { + return false; + } +} \ No newline at end of file From 04ec08798b4db03aac91ae2cca347a00b84a99ae Mon Sep 17 00:00:00 2001 From: impera Date: Sat, 1 Mar 2025 21:58:39 -0300 Subject: [PATCH 07/72] DamageAbsorptionComponent Added. --- .../component/DamageAbsorptionComponent.php | 32 +++++++++++++++++++ 1 file changed, 32 insertions(+) create mode 100644 src/imperazim/vendor/customies/item/component/DamageAbsorptionComponent.php diff --git a/src/imperazim/vendor/customies/item/component/DamageAbsorptionComponent.php b/src/imperazim/vendor/customies/item/component/DamageAbsorptionComponent.php new file mode 100644 index 0000000..cb2fa15 --- /dev/null +++ b/src/imperazim/vendor/customies/item/component/DamageAbsorptionComponent.php @@ -0,0 +1,32 @@ +absorbableCauses = $absorbableCauses; + } + + public function getName(): string { + return "minecraft:damage_absorption"; + } + + public function getValue(): array { + return [ + "absorbable_causes" => $this->absorbableCauses + ]; + } + + public function isProperty(): bool { + return false; + } +} \ No newline at end of file From 6dad8b10594e54c6b3cdb328cf2a1db972907f45 Mon Sep 17 00:00:00 2001 From: impera Date: Sat, 1 Mar 2025 21:59:19 -0300 Subject: [PATCH 08/72] DamageComponent Added. --- .../item/component/DamageComponent.php | 29 +++++++++++++++++++ 1 file changed, 29 insertions(+) create mode 100644 src/imperazim/vendor/customies/item/component/DamageComponent.php diff --git a/src/imperazim/vendor/customies/item/component/DamageComponent.php b/src/imperazim/vendor/customies/item/component/DamageComponent.php new file mode 100644 index 0000000..016647c --- /dev/null +++ b/src/imperazim/vendor/customies/item/component/DamageComponent.php @@ -0,0 +1,29 @@ +damage = $damage; + } + + public function getName(): string { + return "damage"; + } + + public function getValue(): int { + return $this->damage; + } + + public function isProperty(): bool { + return true; + } +} \ No newline at end of file From ec745053406c3b529b2885e1345ae462907ff742 Mon Sep 17 00:00:00 2001 From: impera Date: Sat, 1 Mar 2025 21:59:44 -0300 Subject: [PATCH 09/72] DyeableComponent Added. --- .../item/component/DyeableComponent.php | 31 +++++++++++++++++++ 1 file changed, 31 insertions(+) create mode 100644 src/imperazim/vendor/customies/item/component/DyeableComponent.php diff --git a/src/imperazim/vendor/customies/item/component/DyeableComponent.php b/src/imperazim/vendor/customies/item/component/DyeableComponent.php new file mode 100644 index 0000000..912dd8c --- /dev/null +++ b/src/imperazim/vendor/customies/item/component/DyeableComponent.php @@ -0,0 +1,31 @@ +hex = $hex; + } + + public function getName(): string { + return "minecraft:dyeable"; + } + + public function getValue(): array { + return [ + "default_color" => $this->hex + ]; + } + + public function isProperty(): bool { + return false; + } +} \ No newline at end of file From 4cdb2c58e4e3ca8b2d6e59b53faea2992eab33eb Mon Sep 17 00:00:00 2001 From: impera Date: Sat, 1 Mar 2025 22:03:54 -0300 Subject: [PATCH 10/72] EnchantableSlotComponent Added. --- .../component/EnchantableSlotComponent.php | 48 +++++++++++++++++++ 1 file changed, 48 insertions(+) create mode 100644 src/imperazim/vendor/customies/item/component/EnchantableSlotComponent.php diff --git a/src/imperazim/vendor/customies/item/component/EnchantableSlotComponent.php b/src/imperazim/vendor/customies/item/component/EnchantableSlotComponent.php new file mode 100644 index 0000000..337f1ec --- /dev/null +++ b/src/imperazim/vendor/customies/item/component/EnchantableSlotComponent.php @@ -0,0 +1,48 @@ +slot = $slot; + } + + public function getName(): string { + return "enchantable_slot"; + } + + public function getValue(): string { + return $this->slot; + } + + public function isProperty(): bool { + return true; + } +} \ No newline at end of file From 40e3743a16c27e5444c77d82e93b835d7637d960 Mon Sep 17 00:00:00 2001 From: impera Date: Sat, 1 Mar 2025 22:04:35 -0300 Subject: [PATCH 11/72] EnchantableValueComponent Added. --- .../component/EnchantableValueComponent.php | 47 +++++++++++++++++++ 1 file changed, 47 insertions(+) create mode 100644 src/imperazim/vendor/customies/item/component/EnchantableValueComponent.php diff --git a/src/imperazim/vendor/customies/item/component/EnchantableValueComponent.php b/src/imperazim/vendor/customies/item/component/EnchantableValueComponent.php new file mode 100644 index 0000000..6654df1 --- /dev/null +++ b/src/imperazim/vendor/customies/item/component/EnchantableValueComponent.php @@ -0,0 +1,47 @@ +value = $value; + } + + public function getName(): string { + return "enchantable_value"; + } + + public function getValue(): int { + return $this->value; + } + + public function isProperty(): bool { + return true; + } +} \ No newline at end of file From 72b2cea1e1f60a775c91b9f22e2d8ab2a64e1ac9 Mon Sep 17 00:00:00 2001 From: impera Date: Sat, 1 Mar 2025 22:05:42 -0300 Subject: [PATCH 12/72] GlintComponent Added. --- .../item/component/GlintComponent.php | 29 +++++++++++++++++++ 1 file changed, 29 insertions(+) create mode 100644 src/imperazim/vendor/customies/item/component/GlintComponent.php diff --git a/src/imperazim/vendor/customies/item/component/GlintComponent.php b/src/imperazim/vendor/customies/item/component/GlintComponent.php new file mode 100644 index 0000000..0dda1f7 --- /dev/null +++ b/src/imperazim/vendor/customies/item/component/GlintComponent.php @@ -0,0 +1,29 @@ +glint = $glint; + } + + public function getName(): string { + return "foil"; + } + + public function getValue(): bool { + return $this->glint; + } + + public function isProperty(): bool { + return true; + } +} \ No newline at end of file From 3405d0c6c9bc6d59b73d26dd2ee1ddb3f13a045f Mon Sep 17 00:00:00 2001 From: impera Date: Sat, 1 Mar 2025 22:06:11 -0300 Subject: [PATCH 13/72] HoverTextColorComponent Added. --- .../component/HoverTextColorComponent.php | 30 +++++++++++++++++++ 1 file changed, 30 insertions(+) create mode 100644 src/imperazim/vendor/customies/item/component/HoverTextColorComponent.php diff --git a/src/imperazim/vendor/customies/item/component/HoverTextColorComponent.php b/src/imperazim/vendor/customies/item/component/HoverTextColorComponent.php new file mode 100644 index 0000000..f29750b --- /dev/null +++ b/src/imperazim/vendor/customies/item/component/HoverTextColorComponent.php @@ -0,0 +1,30 @@ +hoverTextColor = $hoverTextColor; + } + + public function getName(): string { + return "hover_text_color"; + } + + public function getValue(): string { + return $this->hoverTextColor; + } + + public function isProperty(): bool { + return true; + } +} \ No newline at end of file From b55c892a487a4ddd0eef63e6d5c339fa3d06f0ef Mon Sep 17 00:00:00 2001 From: impera Date: Sat, 1 Mar 2025 22:06:41 -0300 Subject: [PATCH 14/72] InteractButtonComponent Added. --- .../component/InteractButtonComponent.php | 36 +++++++++++++++++++ 1 file changed, 36 insertions(+) create mode 100644 src/imperazim/vendor/customies/item/component/InteractButtonComponent.php diff --git a/src/imperazim/vendor/customies/item/component/InteractButtonComponent.php b/src/imperazim/vendor/customies/item/component/InteractButtonComponent.php new file mode 100644 index 0000000..7d08de1 --- /dev/null +++ b/src/imperazim/vendor/customies/item/component/InteractButtonComponent.php @@ -0,0 +1,36 @@ +interactButton = "action.interact.use"; + } else { + $this->interactButton = (string) $interactButton; + } + } + + public function getName(): string { + return "minecraft:interact_button"; + } + + public function getValue(): array { + return [ + "interact_text" => (string) $this->interactButton, + "requires_interact" => 1 + ]; + } + + public function isProperty(): bool { + return false; + } +} \ No newline at end of file From b7b59991d2a951b6af8001b18b94aab975e5c377 Mon Sep 17 00:00:00 2001 From: impera Date: Sat, 1 Mar 2025 22:07:17 -0300 Subject: [PATCH 15/72] LiquidClippedComponent Added. --- .../item/component/LiquidClippedComponent.php | 29 +++++++++++++++++++ 1 file changed, 29 insertions(+) create mode 100644 src/imperazim/vendor/customies/item/component/LiquidClippedComponent.php diff --git a/src/imperazim/vendor/customies/item/component/LiquidClippedComponent.php b/src/imperazim/vendor/customies/item/component/LiquidClippedComponent.php new file mode 100644 index 0000000..fef848f --- /dev/null +++ b/src/imperazim/vendor/customies/item/component/LiquidClippedComponent.php @@ -0,0 +1,29 @@ +liquidClipped = $liquidClipped; + } + + public function getName(): string { + return "liquid_clipped"; + } + + public function getValue(): bool { + return $this->liquidClipped; + } + + public function isProperty(): bool { + return true; + } +} \ No newline at end of file From 5b53fb6b0ed1382b811f3d0dcc28d9057fdb9153 Mon Sep 17 00:00:00 2001 From: impera Date: Sat, 1 Mar 2025 22:07:52 -0300 Subject: [PATCH 16/72] RecordComponent Added. --- .../item/component/RecordComponent.php | 39 +++++++++++++++++++ 1 file changed, 39 insertions(+) create mode 100644 src/imperazim/vendor/customies/item/component/RecordComponent.php diff --git a/src/imperazim/vendor/customies/item/component/RecordComponent.php b/src/imperazim/vendor/customies/item/component/RecordComponent.php new file mode 100644 index 0000000..59a9d33 --- /dev/null +++ b/src/imperazim/vendor/customies/item/component/RecordComponent.php @@ -0,0 +1,39 @@ +comparatorSignal = $comparatorSignal; + $this->duration = $duration; + $this->soundEvent = $soundEvent; + } + + public function getName(): string { + return "minecraft:record"; + } + + public function getValue(): array { + return [ + "comparator_signal" => $this->comparatorSignal, + "duration" => $this->duration, + "sound_event" => $this->soundEvent + ]; + } + + public function isProperty(): bool { + return false; + } +} \ No newline at end of file From 17b5e5f7980fd928c3268dd8076dcd636f30e657 Mon Sep 17 00:00:00 2001 From: impera Date: Sat, 1 Mar 2025 22:08:16 -0300 Subject: [PATCH 17/72] ShooterComponent Added. --- .../item/component/ShooterComponent.php | 61 +++++++++++++++++++ 1 file changed, 61 insertions(+) create mode 100644 src/imperazim/vendor/customies/item/component/ShooterComponent.php diff --git a/src/imperazim/vendor/customies/item/component/ShooterComponent.php b/src/imperazim/vendor/customies/item/component/ShooterComponent.php new file mode 100644 index 0000000..61b1a2c --- /dev/null +++ b/src/imperazim/vendor/customies/item/component/ShooterComponent.php @@ -0,0 +1,61 @@ +item = $item; + $this->useOffhand = $useOffhand; + $this->searchInventory = $searchInventory; + $this->useInCreative = $useInCreative; + $this->chargeOnDraw = $chargeOnDraw; + $this->maxDrawDuration = $maxDrawDuration; + $this->scalePowerByDrawDuration = $scalePowerByDrawDuration; + } + + public function getName(): string { + return "minecraft:shooter"; + } + + public function getValue(): array { + return [ + "ammunition" => [ + [ + "item" => $this->item, + "use_offhand" => $this->useOffhand, + "search_inventory" => $this->searchInventory, + "use_in_creative" => $this->useInCreative + ] + ], + "charge_on_draw" => $this->chargeOnDraw, + "max_draw_duration" => $this->maxDrawDuration, + "scale_power_by_draw_duration" => $this->scalePowerByDrawDuration + ]; + } + + public function isProperty(): bool { + return false; + } +} \ No newline at end of file From 293ee7e70afde60c4ad85b0b80e6509a7b097989 Mon Sep 17 00:00:00 2001 From: impera Date: Sat, 1 Mar 2025 22:08:45 -0300 Subject: [PATCH 18/72] ShouldDespawnComponent Added. --- .../item/component/ShouldDespawnComponent.php | 29 +++++++++++++++++++ 1 file changed, 29 insertions(+) create mode 100644 src/imperazim/vendor/customies/item/component/ShouldDespawnComponent.php diff --git a/src/imperazim/vendor/customies/item/component/ShouldDespawnComponent.php b/src/imperazim/vendor/customies/item/component/ShouldDespawnComponent.php new file mode 100644 index 0000000..efe57a4 --- /dev/null +++ b/src/imperazim/vendor/customies/item/component/ShouldDespawnComponent.php @@ -0,0 +1,29 @@ +shouldDespawn = $shouldDespawn; + } + + public function getName(): string { + return "should_despawn"; + } + + public function getValue(): bool { + return $this->shouldDespawn; + } + + public function isProperty(): bool { + return true; + } +} \ No newline at end of file From df9d5aa4b618adf073f447970e34b001b8d70990 Mon Sep 17 00:00:00 2001 From: impera Date: Sat, 1 Mar 2025 22:09:14 -0300 Subject: [PATCH 19/72] StackedByDataComponent Added. --- .../item/component/StackedByDataComponent.php | 30 +++++++++++++++++++ 1 file changed, 30 insertions(+) create mode 100644 src/imperazim/vendor/customies/item/component/StackedByDataComponent.php diff --git a/src/imperazim/vendor/customies/item/component/StackedByDataComponent.php b/src/imperazim/vendor/customies/item/component/StackedByDataComponent.php new file mode 100644 index 0000000..3b21434 --- /dev/null +++ b/src/imperazim/vendor/customies/item/component/StackedByDataComponent.php @@ -0,0 +1,30 @@ +stackedByData = $stackedByData; + } + + public function getName(): string { + return "stacked_by_data"; + } + + public function getValue(): bool { + return $this->stackedByData; + } + + public function isProperty(): bool { + return true; + } +} \ No newline at end of file From f2f8a7ca5eb6299751ffe83e21418d1cb5eee7a7 Mon Sep 17 00:00:00 2001 From: impera Date: Sat, 1 Mar 2025 22:10:09 -0300 Subject: [PATCH 20/72] RenderOffsetsComponent Removed. --- .../item/component/RenderOffsetsComponent.php | 42 ------------------- 1 file changed, 42 deletions(-) delete mode 100644 src/imperazim/vendor/customies/item/component/RenderOffsetsComponent.php diff --git a/src/imperazim/vendor/customies/item/component/RenderOffsetsComponent.php b/src/imperazim/vendor/customies/item/component/RenderOffsetsComponent.php deleted file mode 100644 index 8e9cce4..0000000 --- a/src/imperazim/vendor/customies/item/component/RenderOffsetsComponent.php +++ /dev/null @@ -1,42 +0,0 @@ -textureWidth = $textureWidth; - $this->textureHeight = $textureHeight; - $this->handEquipped = $handEquipped; - } - - public function getName(): string { - return "minecraft:render_offsets"; - } - - public function getValue(): array { - $horizontal = ($this->handEquipped ? 0.075 : 0.1) / ($this->textureWidth / 16); - $vertical = ($this->handEquipped ? 0.125 : 0.1) / ($this->textureHeight / 16); - $perspectives = [ - "first_person" => [ - "scale" => [$horizontal, $vertical, $horizontal], - ], - "third_person" => [ - "scale" => [$horizontal, $vertical, $horizontal] - ] - ]; - return [ - "main_hand" => $perspectives, - "off_hand" => $perspectives - ]; - } - - public function isProperty(): bool { - return false; - } -} \ No newline at end of file From 7f6f85b467423b27a9609850d122cbb583b4fd8e Mon Sep 17 00:00:00 2001 From: impera Date: Sat, 1 Mar 2025 22:10:51 -0300 Subject: [PATCH 21/72] KnockbackResistanceComponent Removed. --- .../KnockbackResistanceComponent.php | 27 ------------------- 1 file changed, 27 deletions(-) delete mode 100644 src/imperazim/vendor/customies/item/component/KnockbackResistanceComponent.php diff --git a/src/imperazim/vendor/customies/item/component/KnockbackResistanceComponent.php b/src/imperazim/vendor/customies/item/component/KnockbackResistanceComponent.php deleted file mode 100644 index 7177882..0000000 --- a/src/imperazim/vendor/customies/item/component/KnockbackResistanceComponent.php +++ /dev/null @@ -1,27 +0,0 @@ -protection = $protection; - } - - public function getName(): string { - return "minecraft:knockback_resistance"; - } - - public function getValue(): array { - return [ - "protection" => $this->protection - ]; - } - - public function isProperty(): bool { - return false; - } -} \ No newline at end of file From ff6c0090436e8e20862e52870d0c57f4983af67e Mon Sep 17 00:00:00 2001 From: impera Date: Sat, 1 Mar 2025 22:11:32 -0300 Subject: [PATCH 22/72] FoilComponent Removed. --- .../item/component/FoilComponent.php | 25 ------------------- 1 file changed, 25 deletions(-) delete mode 100644 src/imperazim/vendor/customies/item/component/FoilComponent.php diff --git a/src/imperazim/vendor/customies/item/component/FoilComponent.php b/src/imperazim/vendor/customies/item/component/FoilComponent.php deleted file mode 100644 index ff340a6..0000000 --- a/src/imperazim/vendor/customies/item/component/FoilComponent.php +++ /dev/null @@ -1,25 +0,0 @@ -foil = $foil; - } - - public function getName(): string { - return "foil"; - } - - public function getValue(): bool { - return $this->foil; - } - - public function isProperty(): bool { - return true; - } -} \ No newline at end of file From 8e95b9c474290c55169d26a75d0608976a10d99a Mon Sep 17 00:00:00 2001 From: impera Date: Sat, 1 Mar 2025 22:12:03 -0300 Subject: [PATCH 23/72] ArmorComponent Removed. --- .../item/component/ArmorComponent.php | 40 ------------------- 1 file changed, 40 deletions(-) delete mode 100644 src/imperazim/vendor/customies/item/component/ArmorComponent.php diff --git a/src/imperazim/vendor/customies/item/component/ArmorComponent.php b/src/imperazim/vendor/customies/item/component/ArmorComponent.php deleted file mode 100644 index 8c14a2d..0000000 --- a/src/imperazim/vendor/customies/item/component/ArmorComponent.php +++ /dev/null @@ -1,40 +0,0 @@ -protection = $protection; - $this->textureType = $textureType; - } - - public function getName(): string { - return "minecraft:armor"; - } - - public function getValue(): array { - return [ - "protection" => $this->protection, - "texture_type" => $this->textureType - ]; - } - - public function isProperty(): bool { - return false; - } -} \ No newline at end of file From 4e858b782944db44175f160761ce71c61bcca27b Mon Sep 17 00:00:00 2001 From: impera Date: Sat, 1 Mar 2025 22:12:34 -0300 Subject: [PATCH 24/72] AttackDamageComponent Removed. --- .../item/component/AttackDamageComponent.php | 25 ------------------- 1 file changed, 25 deletions(-) delete mode 100644 src/imperazim/vendor/customies/item/component/AttackDamageComponent.php diff --git a/src/imperazim/vendor/customies/item/component/AttackDamageComponent.php b/src/imperazim/vendor/customies/item/component/AttackDamageComponent.php deleted file mode 100644 index b6b87e9..0000000 --- a/src/imperazim/vendor/customies/item/component/AttackDamageComponent.php +++ /dev/null @@ -1,25 +0,0 @@ -damage = $damage; - } - - public function getName(): string { - return "damage"; - } - - public function getValue(): int { - return $this->damage; - } - - public function isProperty(): bool { - return true; - } -} \ No newline at end of file From 497c0d5bc6bad547a0d6d236942bbbefc1d1cac3 Mon Sep 17 00:00:00 2001 From: impera Date: Sat, 1 Mar 2025 22:13:01 -0300 Subject: [PATCH 25/72] ChargeableComponent Removed. --- .../item/component/ChargeableComponent.php | 27 ------------------- 1 file changed, 27 deletions(-) delete mode 100644 src/imperazim/vendor/customies/item/component/ChargeableComponent.php diff --git a/src/imperazim/vendor/customies/item/component/ChargeableComponent.php b/src/imperazim/vendor/customies/item/component/ChargeableComponent.php deleted file mode 100644 index f64bd1a..0000000 --- a/src/imperazim/vendor/customies/item/component/ChargeableComponent.php +++ /dev/null @@ -1,27 +0,0 @@ -movementModifier = $movementModifier; - } - - public function getName(): string { - return "minecraft:chargeable"; - } - - public function getValue(): array { - return [ - "movement_modifier" => $this->movementModifier - ]; - } - - public function isProperty(): bool { - return false; - } -} \ No newline at end of file From f0c1514b3f73d7724704c32fdb8077560e8c405c Mon Sep 17 00:00:00 2001 From: impera Date: Sat, 1 Mar 2025 22:19:48 -0300 Subject: [PATCH 26/72] ItemComponentsTrait Modified. --- .../customies/item/ItemComponentsTrait.php | 24 ++++--------------- 1 file changed, 5 insertions(+), 19 deletions(-) diff --git a/src/imperazim/vendor/customies/item/ItemComponentsTrait.php b/src/imperazim/vendor/customies/item/ItemComponentsTrait.php index 4bc612f..3e1ffce 100644 --- a/src/imperazim/vendor/customies/item/ItemComponentsTrait.php +++ b/src/imperazim/vendor/customies/item/ItemComponentsTrait.php @@ -8,7 +8,7 @@ use imperazim\vendor\customies\item\component\FuelComponent; use imperazim\vendor\customies\item\component\IconComponent; use imperazim\vendor\customies\item\component\ItemComponent; -use imperazim\vendor\customies\item\component\ArmorComponent; +use imperazim\vendor\customies\item\component\DamageComponent; use imperazim\vendor\customies\item\component\CooldownComponent; use imperazim\vendor\customies\item\component\WearableComponent; use imperazim\vendor\customies\item\component\ThrowableComponent; @@ -18,10 +18,8 @@ use imperazim\vendor\customies\item\component\DisplayNameComponent; use imperazim\vendor\customies\item\component\HandEquippedComponent; use imperazim\vendor\customies\item\component\MaxStackSizeComponent; -use imperazim\vendor\customies\item\component\AttackDamageComponent; use imperazim\vendor\customies\item\component\AllowOffHandComponent; use imperazim\vendor\customies\item\component\UseAnimationComponent; -use imperazim\vendor\customies\item\component\RenderOffsetsComponent; use imperazim\vendor\customies\item\component\CreativeGroupComponent; use imperazim\vendor\customies\item\component\LockInInventoryComponent; use imperazim\vendor\customies\item\component\CreativeCategoryComponent; @@ -74,7 +72,7 @@ public function getComponents(): CompoundTag { * Initializes the item with default components that are required for the item to function correctly. */ protected function initComponent(string $texture, ?CreativeInventoryInfo $creativeInfo = null): void { - $creativeInfo ?? = CreativeInventoryInfo::DEFAULT(); + $creativeInfo ??= CreativeInventoryInfo::DEFAULT(); $this->addComponent(new CreativeCategoryComponent($creativeInfo)); $this->addComponent(new CreativeGroupComponent($creativeInfo)); $this->addComponent(new CanDestroyInCreativeComponent()); @@ -89,8 +87,7 @@ protected function initComponent(string $texture, ?CreativeInventoryInfo $creati ArmorInventory::SLOT_FEET => WearableComponent::SLOT_ARMOR_FEET, default => WearableComponent::SLOT_ARMOR }; - $this->addComponent(new ArmorComponent($this->getDefensePoints())); - $this->addComponent(new WearableComponent($slot)); + $this->addComponent(new WearableComponent($slot, $this->getDefensePoints())); } if ($this instanceof Consumable) { @@ -106,7 +103,7 @@ protected function initComponent(string $texture, ?CreativeInventoryInfo $creati } if ($this instanceof ProjectileItem) { - $this->addComponent(new ProjectileComponent("projectile")); + $this->addComponent(new ProjectileComponent(1.25, "projectile")); $this->addComponent(new ThrowableComponent(true)); } @@ -118,7 +115,7 @@ protected function initComponent(string $texture, ?CreativeInventoryInfo $creati $this->addComponent(new FuelComponent($this->getFuelTime())); } if ($this->getAttackPoints() > 0) { - $this->addComponent(new AttackDamageComponent($this->getAttackPoints() - 1)); + $this->addComponent(new DamageComponent($this->getAttackPoints() - 1)); } if ($this instanceof Tool) { @@ -129,17 +126,6 @@ protected function initComponent(string $texture, ?CreativeInventoryInfo $creati } } - /** - * When a custom item has a texture that is not 16x16, the item will scale when held in a hand based on the size of - * the texture. This method adds the minecraft:render_offsets component with the correct data for the provided width - * and height of a texture to make the item scale correctly. An optional bool for hand equipped can be used if the - * item is something like a tool or weapon. - */ - protected function setupRenderOffsets(int $width, int $height, bool $handEquipped = false): void { - $this->addComponent(new HandEquippedComponent($handEquipped)); - $this->addComponent(new RenderOffsetsComponent($width, $height, $handEquipped)); - } - /** * Change if you want to allow the item to be placed in a player's off-hand or not. This is set to false by default, * so it only needs to be set if you want to allow it. From f72db4e81799834f54b28662c34f635ad1fda446 Mon Sep 17 00:00:00 2001 From: impera Date: Sat, 1 Mar 2025 22:19:48 -0300 Subject: [PATCH 27/72] AllowOffHand Modified. --- .../item/component/AllowOffHandComponent.php | 32 +++++++++++-------- 1 file changed, 18 insertions(+), 14 deletions(-) diff --git a/src/imperazim/vendor/customies/item/component/AllowOffHandComponent.php b/src/imperazim/vendor/customies/item/component/AllowOffHandComponent.php index 8df56ef..07538ae 100644 --- a/src/imperazim/vendor/customies/item/component/AllowOffHandComponent.php +++ b/src/imperazim/vendor/customies/item/component/AllowOffHandComponent.php @@ -1,25 +1,29 @@ offHand = $offHand; - } + /** + * Determine whether an item can be placed in the off-hand slot of the inventory. + * @param bool $offHand Default is set to `true` + */ + public function __construct(bool $offHand = true) { + $this->offHand = $offHand; + } - public function getName(): string { - return "allow_off_hand"; - } + public function getName(): string { + return "allow_off_hand"; + } - public function getValue(): bool { - return $this->offHand; - } + public function getValue(): bool { + return $this->offHand; + } - public function isProperty(): bool { - return true; - } + public function isProperty(): bool { + return true; + } } \ No newline at end of file From 06111828469a9db06c74e5b4d5544d1ce8df02c0 Mon Sep 17 00:00:00 2001 From: impera Date: Sat, 1 Mar 2025 22:19:49 -0300 Subject: [PATCH 28/72] BlockPlacer Modified. --- .../item/component/BlockPlacerComponent.php | 63 ++++++++++++------- 1 file changed, 40 insertions(+), 23 deletions(-) diff --git a/src/imperazim/vendor/customies/item/component/BlockPlacerComponent.php b/src/imperazim/vendor/customies/item/component/BlockPlacerComponent.php index fd22f01..1222cc5 100644 --- a/src/imperazim/vendor/customies/item/component/BlockPlacerComponent.php +++ b/src/imperazim/vendor/customies/item/component/BlockPlacerComponent.php @@ -1,32 +1,49 @@ blockIdentifier = $blockIdentifier; - $this->useBlockDescription = $useBlockDescription; - } - - public function getName(): string { - return "minecraft:block_placer"; - } - - public function getValue(): array { - return [ - "block" => $this->blockIdentifier, - "use_block_description" => $this->useBlockDescription - ]; - } - - public function isProperty(): bool { - return false; + private Block $block; + private array $useOn = []; + + /** + * Sets the item as a Planter item component for blocks. Items with this component will place a block when used. + * @param Block $block + */ + public function __construct(Block $block) { + $this->block = $block; + } + + public function getName(): string { + return "minecraft:block_placer"; + } + + public function getValue(): array { + return [ + "block" => GlobalBlockStateHandlers::getSerializer()->serialize($this->block->getStateId())->getName(), + "use_on" => $this->useOn + ]; + } + + public function isProperty(): bool { + return false; + } + + /** + * Add blocks to the `use_on` array in the required format. + * @param Block ...$blocks + */ + public function useOn(Block ...$blocks): self { + foreach ($blocks as $block) { + $this->useOn[] = [ + "name" => GlobalBlockStateHandlers::getSerializer()->serialize($block->getStateId())->getName() + ]; } -} + return $this; + } +} \ No newline at end of file From 17d8d5bd90f4cd0de8d195bdbf76540be7ff027a Mon Sep 17 00:00:00 2001 From: impera Date: Sat, 1 Mar 2025 22:19:49 -0300 Subject: [PATCH 29/72] Cooldown Modified. --- .../item/component/CooldownComponent.php | 50 ++++++++++++------- 1 file changed, 31 insertions(+), 19 deletions(-) diff --git a/src/imperazim/vendor/customies/item/component/CooldownComponent.php b/src/imperazim/vendor/customies/item/component/CooldownComponent.php index 038cf63..8f3caeb 100644 --- a/src/imperazim/vendor/customies/item/component/CooldownComponent.php +++ b/src/imperazim/vendor/customies/item/component/CooldownComponent.php @@ -1,30 +1,42 @@ category = $category; - $this->duration = $duration; - } + private string $category; + private float $duration; - public function getName(): string { - return "minecraft:cooldown"; - } + /** + * Sets an item's "Cooldown" time. + * After using an item, it becomes unusable for the duration specified by the `duration` setting of this component. + * @param string $category The type of cool down for this item. All items with a cool down component with the same category are put on cool down when one is used + * @param float $duration The duration of time (in seconds) items with a matching category will spend cooling down before becoming usable again + */ + public function __construct(string $category, float $duration) { + $this->category = $category; + $this->duration = $duration; + } - public function getValue(): array { - return [ - "category" => $this->category, - "duration" => $this->duration - ]; - } + public function getName(): string { + return "minecraft:cooldown"; + } - public function isProperty(): bool { - return false; - } + public function getValue(): array { + return [ + "category" => $this->category, + "duration" => $this->duration + ]; + } + + public function isProperty(): bool { + return false; + } } \ No newline at end of file From fae20d75770fc0364a1335aa55273d9c969a9eec Mon Sep 17 00:00:00 2001 From: impera Date: Sat, 1 Mar 2025 22:19:49 -0300 Subject: [PATCH 30/72] Digger Modified. --- .../item/component/DiggerComponent.php | 98 +++++++++++-------- 1 file changed, 59 insertions(+), 39 deletions(-) diff --git a/src/imperazim/vendor/customies/item/component/DiggerComponent.php b/src/imperazim/vendor/customies/item/component/DiggerComponent.php index 5d3521d..c5fb654 100644 --- a/src/imperazim/vendor/customies/item/component/DiggerComponent.php +++ b/src/imperazim/vendor/customies/item/component/DiggerComponent.php @@ -1,5 +1,5 @@ $this->destroySpeeds - ]; - } - - public function isProperty(): bool { - return false; - } - - public function withBlocks(int $speed, Block ...$blocks): DiggerComponent { - foreach($blocks as $block){ - $this->destroySpeeds[] = [ - "block" => [ - "name" => GlobalBlockStateHandlers::getSerializer()->serialize($block->getStateId())->getName() - ], - "speed" => $speed - ]; - } - return $this; - } - - public function withTags(int $speed, string ...$tags): DiggerComponent { - $query = implode(",", array_map(fn($tag) => "'" . $tag . "'", $tags)); - $this->destroySpeeds[] = [ - "block" => [ - "tags" => "query.any_tag(" . $query . ")" - ], - "speed" => $speed - ]; - return $this; - } + private array $destroySpeeds; + private bool $useEfficiency; + + /** + * Allows a creator to determine how quickly an item can dig specific blocks. + * @param bool $useEfficiency Determines whether the item should be impacted if the `efficiency` enchant is applied to it. + */ + public function __construct(bool $useEfficiency) { + $this->useEfficiency = $useEfficiency; + } + + public function getName(): string { + return "minecraft:digger"; + } + + public function getValue(): array { + return [ + "destroy_speeds" => $this->destroySpeeds, + "use_efficiency" => $this->useEfficiency, + ]; + } + + public function isProperty(): bool { + return false; + } + + /** + * Add blocks to the `destroy_speeds` array in the required format. + * @param int $speed Digging speed for the correlating block(s) + * @param Block ...$blocks A list of blocks to dig with correlating speeds of digging + */ + public function withBlocks(int $speed, Block ...$blocks): DiggerComponent { + foreach ($blocks as $block) { + $this->destroySpeeds[] = [ + "block" => [ + "name" => GlobalBlockStateHandlers::getSerializer()->serialize($block->getStateId())->getName() + ], + "speed" => $speed + ]; + } + return $this; + } + + /** + * Add blocks to the `destroy_speeds` array in the required format. + * @param int $speed Digging speed for the correlating block(s) + * @param string ...$tags A list of blocks to dig with correlating speeds of digging + */ + public function withTags(int $speed, string ...$tags): DiggerComponent { + $query = implode(",", array_map(fn($tag) => "'" . $tag . "'", $tags)); + $this->destroySpeeds[] = [ + "block" => [ + "tags" => "query.any_tag(" . $query . ")" + ], + "speed" => $speed + ]; + return $this; + } } \ No newline at end of file From d6827e95511e9616548b4b8b731dd4927ef94315 Mon Sep 17 00:00:00 2001 From: impera Date: Sat, 1 Mar 2025 22:19:50 -0300 Subject: [PATCH 31/72] DisplayName Modified. --- .../item/component/DisplayNameComponent.php | 37 +++++++++++-------- 1 file changed, 21 insertions(+), 16 deletions(-) diff --git a/src/imperazim/vendor/customies/item/component/DisplayNameComponent.php b/src/imperazim/vendor/customies/item/component/DisplayNameComponent.php index 67838bf..afea1d0 100644 --- a/src/imperazim/vendor/customies/item/component/DisplayNameComponent.php +++ b/src/imperazim/vendor/customies/item/component/DisplayNameComponent.php @@ -1,27 +1,32 @@ name = $name; - } + /** + * Sets the item display name within Minecraft: Bedrock Edition. + * This component may also be used to pull from the localization file by referencing a key from it. + * @param string $name Name shown for an item + */ + public function __construct(string $name) { + $this->name = $name; + } - public function getName(): string { - return "minecraft:display_name"; - } + public function getName(): string { + return "minecraft:display_name"; + } - public function getValue(): array { - return [ - "value" => $this->name - ]; - } + public function getValue(): array { + return [ + "value" => $this->name + ]; + } - public function isProperty(): bool { - return false; - } + public function isProperty(): bool { + return false; + } } \ No newline at end of file From 2b03c5368642a1d140aadf1baaed50df25bee27d Mon Sep 17 00:00:00 2001 From: impera Date: Sat, 1 Mar 2025 22:19:50 -0300 Subject: [PATCH 32/72] Durability Modified. --- .../item/component/DurabilityComponent.php | 46 ++++++++++++------- 1 file changed, 30 insertions(+), 16 deletions(-) diff --git a/src/imperazim/vendor/customies/item/component/DurabilityComponent.php b/src/imperazim/vendor/customies/item/component/DurabilityComponent.php index 1bfeec7..cc2a5f0 100644 --- a/src/imperazim/vendor/customies/item/component/DurabilityComponent.php +++ b/src/imperazim/vendor/customies/item/component/DurabilityComponent.php @@ -1,27 +1,41 @@ maxDurability = $maxDurability; - } + /** + * Sets how much damage the item can take before breaking, and allows the item to be combined at an anvil, grindstone, or crafting table. + * @param int $maxDurability Max durability is the amount of damage that this item can take before breaking + * @param int $minDamageChance Specifies the percentage minimum chance for durability to take damage. Range: [0, 100]. Default is set to `100` + * @param int $maxDamageChance Specifies the percentage maximum chance for durability to take damage. Range: [0, 100]. Default is set to `100` + */ + public function __construct(int $maxDurability, int $minDamageChance = 100, int $maxDamageChance = 100) { + $this->maxDurability = $maxDurability; + $this->minDamageChance = $minDamageChance; + $this->maxDamageChance = $maxDamageChance; + } - public function getName(): string { - return "minecraft:durability"; - } + public function getName(): string { + return "minecraft:durability"; + } - public function getValue(): array { - return [ - "max_durability" => $this->maxDurability - ]; - } + public function getValue(): array { + return [ + "damage_chance" => [ + "min" => $this->minDamageChance, + "max" => $this->maxDamageChance + ], + "max_durability" => $this->maxDurability + ]; + } - public function isProperty(): bool { - return false; - } + public function isProperty(): bool { + return false; + } } \ No newline at end of file From a39624f96434d81b2208b11fa4308b2749d3d47e Mon Sep 17 00:00:00 2001 From: impera Date: Sat, 1 Mar 2025 22:19:51 -0300 Subject: [PATCH 33/72] Food Modified. --- .../item/component/FoodComponent.php | 50 +++++++++++++------ 1 file changed, 34 insertions(+), 16 deletions(-) diff --git a/src/imperazim/vendor/customies/item/component/FoodComponent.php b/src/imperazim/vendor/customies/item/component/FoodComponent.php index c7e9993..06b887d 100644 --- a/src/imperazim/vendor/customies/item/component/FoodComponent.php +++ b/src/imperazim/vendor/customies/item/component/FoodComponent.php @@ -1,27 +1,45 @@ canAlwaysEat = $canAlwaysEat; - } + /** + * Sets the item as a food component, allowing it to be edible to the player. + * @param bool $canAlwaysEat If true you can always eat this item (even when not hungry) + * @param int $nutrition Value that is added to the entity's nutrition when the item is used + * @param float $saturationModifier + * @param string $usingConvertsTo When used, converts to the item specified by the string in this field. Default does not convert item + */ + public function __construct(bool $canAlwaysEat = false, int $nutrition = 0, float $saturationModifier = 0.6, string $usingConvertsTo = "") { + $this->canAlwaysEat = $canAlwaysEat; + $this->nutrition = $nutrition; + $this->saturationModifier = $saturationModifier; + $this->usingConvertsTo = $usingConvertsTo; + } - public function getName(): string { - return "minecraft:food"; - } + public function getName(): string { + return "minecraft:food"; + } - public function getValue(): array { - return [ - "can_always_eat" => $this->canAlwaysEat - ]; - } + public function getValue(): array { + return [ + "can_always_eat" => $this->canAlwaysEat, + "nutrition" => $this->nutrition, + "saturation_modifier" => $this->saturationModifier, + "using_converts_to" => [ + "name" => $this->usingConvertsTo + ] + ]; + } - public function isProperty(): bool { - return false; - } + public function isProperty(): bool { + return false; + } } \ No newline at end of file From bee9a64dea651df76ccea5e9b401cec2e176d967 Mon Sep 17 00:00:00 2001 From: impera Date: Sat, 1 Mar 2025 22:19:51 -0300 Subject: [PATCH 34/72] Fuel Modified. --- .../item/component/FuelComponent.php | 36 ++++++++++--------- 1 file changed, 20 insertions(+), 16 deletions(-) diff --git a/src/imperazim/vendor/customies/item/component/FuelComponent.php b/src/imperazim/vendor/customies/item/component/FuelComponent.php index ebf09a4..8f43e50 100644 --- a/src/imperazim/vendor/customies/item/component/FuelComponent.php +++ b/src/imperazim/vendor/customies/item/component/FuelComponent.php @@ -1,27 +1,31 @@ duration = $duration; - } + /** + * Allows this item to be used as fuel in a furnace to 'cook' other items. + * @param float $duration Amount of time, in seconds, this fuel will cook items + */ + public function __construct(float $duration) { + $this->duration = $duration; + } - public function getName(): string { - return "minecraft:fuel"; - } + public function getName(): string { + return "minecraft:fuel"; + } - public function getValue(): array { - return [ - "duration" => $this->duration - ]; - } + public function getValue(): array { + return [ + "duration" => $this->duration + ]; + } - public function isProperty(): bool { - return false; - } + public function isProperty(): bool { + return false; + } } \ No newline at end of file From cdae091f16b3380028bc17e541b7236b0d2a649f Mon Sep 17 00:00:00 2001 From: impera Date: Sat, 1 Mar 2025 22:19:52 -0300 Subject: [PATCH 35/72] HandEquipped Modified. --- .../item/component/HandEquippedComponent.php | 32 +++++++++++-------- 1 file changed, 18 insertions(+), 14 deletions(-) diff --git a/src/imperazim/vendor/customies/item/component/HandEquippedComponent.php b/src/imperazim/vendor/customies/item/component/HandEquippedComponent.php index 36d6110..07d66b9 100644 --- a/src/imperazim/vendor/customies/item/component/HandEquippedComponent.php +++ b/src/imperazim/vendor/customies/item/component/HandEquippedComponent.php @@ -1,25 +1,29 @@ handEquipped = $handEquipped; - } + /** + * Determines if an item is rendered like a tool while in-hand. + * @param bool $handEquipped Default is set to `true` + */ + public function __construct(bool $handEquipped = true) { + $this->handEquipped = $handEquipped; + } - public function getName(): string { - return "hand_equipped"; - } + public function getName(): string { + return "hand_equipped"; + } - public function getValue(): bool { - return $this->handEquipped; - } + public function getValue(): bool { + return $this->handEquipped; + } - public function isProperty(): bool { - return true; - } + public function isProperty(): bool { + return true; + } } \ No newline at end of file From 1f265ecc1da62e8ddf26a6c88c11f2c454075d83 Mon Sep 17 00:00:00 2001 From: impera Date: Sat, 1 Mar 2025 22:19:53 -0300 Subject: [PATCH 36/72] Icon Modified. --- .../item/component/IconComponent.php | 22 ++++++++++++++----- 1 file changed, 17 insertions(+), 5 deletions(-) diff --git a/src/imperazim/vendor/customies/item/component/IconComponent.php b/src/imperazim/vendor/customies/item/component/IconComponent.php index 5e7c41e..3dc8b2a 100644 --- a/src/imperazim/vendor/customies/item/component/IconComponent.php +++ b/src/imperazim/vendor/customies/item/component/IconComponent.php @@ -5,10 +5,20 @@ final class IconComponent implements ItemComponent { - private string $texture; + private string $default_texture; + private string $dyed_texture; + private string $trim_texture; - public function __construct(string $texture) { - $this->texture = $texture; + /** + * Determines the icon to represent the item in the UI and elsewhere. + * @param string $default_texture the texture name should same as the `resource_pack/textures/item_texture.json` `texture_data` + * @param string $dyed_texture Default is set to `None` + * @param string $trim_texture Default is set to `None` + */ + public function __construct(string $default_texture, string $dyed_texture = "", string $trim_texture = "") { + $this->default_texture = $default_texture; + $this->dyed_texture = $dyed_texture; + $this->trim_texture = $trim_texture; } public function getName(): string { @@ -17,9 +27,11 @@ public function getName(): string { public function getValue(): array { return [ - "texture" => $this->texture, + "texture" => $this->default_texture, "textures" => [ - "default" => $this->texture + "default" => $this->default_texture, + "dyed" => $this->dyed_texture, + "icon_trim" => $this->trim_texture ] ]; } From 69ecae0e46df25b8ac92a5408a2af3543706bab0 Mon Sep 17 00:00:00 2001 From: impera Date: Sat, 1 Mar 2025 22:19:53 -0300 Subject: [PATCH 37/72] MaxStackSize Modified. --- .../item/component/MaxStackSizeComponent.php | 32 +++++++++++-------- 1 file changed, 18 insertions(+), 14 deletions(-) diff --git a/src/imperazim/vendor/customies/item/component/MaxStackSizeComponent.php b/src/imperazim/vendor/customies/item/component/MaxStackSizeComponent.php index 52e86bd..4f5df55 100644 --- a/src/imperazim/vendor/customies/item/component/MaxStackSizeComponent.php +++ b/src/imperazim/vendor/customies/item/component/MaxStackSizeComponent.php @@ -1,25 +1,29 @@ maxStackSize = $maxStackSize; - } + /** + * Determines how many of an item can be stacked together. + * @param int $maxStackSize Max Size, Default is set to `64` + */ + public function __construct(int $maxStackSize = 64) { + $this->maxStackSize = $maxStackSize; + } - public function getName(): string { - return "max_stack_size"; - } + public function getName(): string { + return "max_stack_size"; + } - public function getValue(): int { - return $this->maxStackSize; - } + public function getValue(): int { + return $this->maxStackSize; + } - public function isProperty(): bool { - return true; - } + public function isProperty(): bool { + return true; + } } \ No newline at end of file From 427b28f32ed5a146a6faa19dab1d34bc7c8526d3 Mon Sep 17 00:00:00 2001 From: impera Date: Sat, 1 Mar 2025 22:19:54 -0300 Subject: [PATCH 38/72] Projectile Modified. --- .../item/component/ProjectileComponent.php | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/src/imperazim/vendor/customies/item/component/ProjectileComponent.php b/src/imperazim/vendor/customies/item/component/ProjectileComponent.php index 574d93e..089645a 100644 --- a/src/imperazim/vendor/customies/item/component/ProjectileComponent.php +++ b/src/imperazim/vendor/customies/item/component/ProjectileComponent.php @@ -4,10 +4,19 @@ namespace imperazim\vendor\customies\item\component; final class ProjectileComponent implements ItemComponent { - + + private float $minimumCriticalPower; private string $projectileEntity; - public function __construct(string $projectileEntity) { + /** + * Projectile Component compels the item to shoot, similarly to an arrow. + * Items with projectile component can be shot from dispensers or used as ammunition for items with the shooter item component. + * Additionally, this component sets the entity that is spawned for items that also contain the throwable component. + * @param float $minimumCriticalPower Specifies how long a player must charge a projectile for it to critically hit + * @param string $projectileEntity Which entity is to be fired as a projectile + */ + public function __construct(float $minimumCriticalPower, string $projectileEntity) { + $this->minimumCriticalPower = $minimumCriticalPower; $this->projectileEntity = $projectileEntity; } @@ -17,6 +26,7 @@ public function getName(): string { public function getValue(): array { return [ + "minimum_critical_power" => $this->minimumCriticalPower, "projectile_entity" => $this->projectileEntity ]; } From f68bc1cf6666de225c8e1c3aa2a1771f100f6b7c Mon Sep 17 00:00:00 2001 From: impera Date: Sat, 1 Mar 2025 22:19:54 -0300 Subject: [PATCH 39/72] Rarity Modified. --- .../vendor/customies/item/component/RarityComponent.php | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/src/imperazim/vendor/customies/item/component/RarityComponent.php b/src/imperazim/vendor/customies/item/component/RarityComponent.php index d62205c..704c8a1 100644 --- a/src/imperazim/vendor/customies/item/component/RarityComponent.php +++ b/src/imperazim/vendor/customies/item/component/RarityComponent.php @@ -12,7 +12,12 @@ final class RarityComponent implements ItemComponent { private string $rarity; - public function __construct(string $rarity) { + /** + * Rarity Component enables the specifying of the base rarity of an item. + * The rarity of the item will determine which color it uses for its name, unless the item has a HoverTextColor component specified, in which case that hover text color will take priority and be used instead of the rarity color. + * @param string $type Sets the base rarity of the item. The rarity of an item automatically increases when enchanted, either to Rare when the base rarity is Common or Uncommon, or Epic when the base rarity is Rare + */ + public function __construct(string $rarity = self::COMMON) { $this->rarity = $rarity; } From 157e276e9408a4ecd963ea84b41338056a66093a Mon Sep 17 00:00:00 2001 From: impera Date: Sat, 1 Mar 2025 22:19:55 -0300 Subject: [PATCH 40/72] Throwable Modified. --- .../item/component/ThrowableComponent.php | 56 +++++++++++++------ 1 file changed, 40 insertions(+), 16 deletions(-) diff --git a/src/imperazim/vendor/customies/item/component/ThrowableComponent.php b/src/imperazim/vendor/customies/item/component/ThrowableComponent.php index df58a9d..97bc401 100644 --- a/src/imperazim/vendor/customies/item/component/ThrowableComponent.php +++ b/src/imperazim/vendor/customies/item/component/ThrowableComponent.php @@ -1,27 +1,51 @@ doSwingAnimation = $doSwingAnimation; - } + /** + * Sets the throwable item component. + * @param bool $doSwingAnimation Determines whether the item should use the swing animation when thrown + * @param float $launchPowerScale The scale at which the power of the throw increases + * @param float $maxDrawDuration The maximum duration to draw a throwable item + * @param float $maxLaunchPower The maximum power to launch the throwable item + * @param float $minDrawDuration The minimum duration to draw a throwable item + * @param bool $scalePowerByDrawDuration Whether or not the power of the throw increases with duration charged + */ + public function __construct(bool $doSwingAnimation = false, float $launchPowerScale = 1.0, float $maxDrawDuration = 0.0, float $maxLaunchPower = 1.0, float $minDrawDuration = 0.0, bool $scalePowerByDrawDuration = false) { + $this->doSwingAnimation = $doSwingAnimation; + $this->launchPowerScale = $launchPowerScale; + $this->maxDrawDuration = $maxDrawDuration; + $this->maxLaunchPower = $maxLaunchPower; + $this->minDrawDuration = $minDrawDuration; + $this->scalePowerByDrawDuration = $scalePowerByDrawDuration; + } - public function getName(): string { - return "minecraft:throwable"; - } + public function getName(): string { + return "minecraft:throwable"; + } - public function getValue(): array { - return [ - "do_swing_animation" => $this->doSwingAnimation - ]; - } + public function getValue(): array { + return [ + "do_swing_animation" => $this->doSwingAnimation, + "launch_power_scale" => $this->launchPowerScale, + "max_draw_duration" => $this->maxDrawDuration, + "max_launch_power" => $this->maxLaunchPower, + "min_draw_duration" => $this->minDrawDuration, + "scale_power_by_draw_duration" => $this->scalePowerByDrawDuration + ]; + } - public function isProperty(): bool { - return false; - } + public function isProperty(): bool { + return false; + } } \ No newline at end of file From 3e6ee29e9c5351624c3f90ce4c101c566870ac97 Mon Sep 17 00:00:00 2001 From: impera Date: Sat, 1 Mar 2025 22:19:56 -0300 Subject: [PATCH 41/72] UseAnimation Modified. --- .../item/component/UseAnimationComponent.php | 54 +++++++++++-------- 1 file changed, 33 insertions(+), 21 deletions(-) diff --git a/src/imperazim/vendor/customies/item/component/UseAnimationComponent.php b/src/imperazim/vendor/customies/item/component/UseAnimationComponent.php index f45e59d..1d58458 100644 --- a/src/imperazim/vendor/customies/item/component/UseAnimationComponent.php +++ b/src/imperazim/vendor/customies/item/component/UseAnimationComponent.php @@ -1,28 +1,40 @@ animation = $animation; - } - - public function getName(): string { - return "use_animation"; - } - - public function getValue(): int { - return $this->animation; - } - - public function isProperty(): bool { - return true; - } + public const ANIMATION_NONE = 0; + public const ANIMATION_EAT = 1; + public const ANIMATION_DRINK = 2; + public const ANIMATION_BLOCK = 3; + public const ANIMATION_BOW = 4; + public const ANIMATION_CAMERA = 5; + public const ANIMATION_SPEAR = 6; + public const ANIMATION_CROSSBOW = 9; + public const ANIMATION_SPYGLASS = 10; + public const ANIMATION_BRUSH = 12; + + private int $animation; + + /** + * Determines which animation plays when using an item. + * @param int $animation Specifies which animation to play when the the item is used, Default is set to `0` + */ + public function __construct(int $animation) { + $this->animation = $animation; + } + + public function getName(): string { + return "use_animation"; + } + + public function getValue(): int { + return $this->animation; + } + + public function isProperty(): bool { + return true; + } } \ No newline at end of file From c8edd145701db25af2c88a361617e0f587818815 Mon Sep 17 00:00:00 2001 From: impera Date: Sat, 1 Mar 2025 22:19:56 -0300 Subject: [PATCH 42/72] UseDuration Modified. --- .../item/component/UseDurationComponent.php | 32 +++++++++++-------- 1 file changed, 18 insertions(+), 14 deletions(-) diff --git a/src/imperazim/vendor/customies/item/component/UseDurationComponent.php b/src/imperazim/vendor/customies/item/component/UseDurationComponent.php index 3acad91..ab755bb 100644 --- a/src/imperazim/vendor/customies/item/component/UseDurationComponent.php +++ b/src/imperazim/vendor/customies/item/component/UseDurationComponent.php @@ -1,25 +1,29 @@ duration = $duration; - } + /** + * How long the item takes to use in seconds. + * @param int $duration Default is set to `20` (`20` means `1` seconds) so (`32` means `1.6` seconds) + */ + public function __construct(int $duration = 20) { + $this->duration = $duration; + } - public function getName(): string { - return "use_duration"; - } + public function getName(): string { + return "use_duration"; + } - public function getValue(): int { - return $this->duration; - } + public function getValue(): int { + return $this->duration; + } - public function isProperty(): bool { - return true; - } + public function isProperty(): bool { + return true; + } } \ No newline at end of file From 99ae8620e2c5c84c9c5fddb0acc570c5d0f4fa5f Mon Sep 17 00:00:00 2001 From: impera Date: Sat, 1 Mar 2025 22:19:57 -0300 Subject: [PATCH 43/72] UseModifiers Modified. --- .../item/component/UseModifiersComponent.php | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/src/imperazim/vendor/customies/item/component/UseModifiersComponent.php b/src/imperazim/vendor/customies/item/component/UseModifiersComponent.php index 2fb32c3..2a0397a 100644 --- a/src/imperazim/vendor/customies/item/component/UseModifiersComponent.php +++ b/src/imperazim/vendor/customies/item/component/UseModifiersComponent.php @@ -5,7 +5,18 @@ final class UseModifiersComponent implements ItemComponent { - public function __construct(private float $movementModifier, private float $useDuration) {} + private float $useDuration; + private float $movementModifier; + + /** + * Determines how long an item takes to use in combination with components such as Shooter, Throwable, or Food. + * @param float $useDuration How long the item takes to use in seconds + * @param float $movementModifier Modifier value to scale the players movement speed when item is in use + */ + public function __construct(float $movementModifier, float $useDuration = 0) { + $this->useDuration = $useDuration; + $this->movementModifier = $movementModifier; + } public function getName(): string { return "minecraft:use_modifiers"; @@ -21,5 +32,4 @@ public function getValue(): array { public function isProperty(): bool { return false; } - } \ No newline at end of file From 5a8d8c5971e671f6e07c6a56a33cb66ad1429a93 Mon Sep 17 00:00:00 2001 From: impera Date: Sat, 1 Mar 2025 22:19:57 -0300 Subject: [PATCH 44/72] Wearable Modified. --- .../item/component/WearableComponent.php | 79 +++++++++++-------- 1 file changed, 46 insertions(+), 33 deletions(-) diff --git a/src/imperazim/vendor/customies/item/component/WearableComponent.php b/src/imperazim/vendor/customies/item/component/WearableComponent.php index 9c47731..8aae31b 100644 --- a/src/imperazim/vendor/customies/item/component/WearableComponent.php +++ b/src/imperazim/vendor/customies/item/component/WearableComponent.php @@ -1,42 +1,55 @@ slot = $slot; - } - - public function getName(): string { - return "minecraft:wearable"; - } - - public function getValue(): array { - return [ - "slot" => $this->slot + public const SLOT_ARMOR = "slot.armor"; + public const SLOT_ARMOR_CHEST = "slot.armor.chest"; + public const SLOT_ARMOR_FEET = "slot.armor.feet"; + public const SLOT_ARMOR_HEAD = "slot.armor.head"; + public const SLOT_ARMOR_LEGS = "slot.armor.legs"; + public const SLOT_CHEST = "slot.chest"; + public const SLOT_ENDERCHEST = "slot.enderchest"; + public const SLOT_EQUIPPABLE = "slot.equippable"; + public const SLOT_HOTBAR = "slot.hotbar"; + public const SLOT_INVENTORY = "slot.inventory"; + public const SLOT_NONE = "none"; + public const SLOT_SADDLE = "slot.saddle"; + public const SLOT_WEAPON_MAIN_HAND = "slot.weapon.mainhand"; + public const SLOT_WEAPON_OFF_HAND = "slot.weapon.offhand"; + + private string $slot; + + private int $protection; + private bool $dispensable; + + /** + * Sets the wearable item component. + * @param string $slot Specifies where the item can be worn + * @param int $protection How much protection the wearable item provides + * @param bool $dispensable Whether the wearable item can be dispensed + */ + public function __construct(string $slot, int $protection = 0, bool $dispensable = true) { + $this->slot = $slot; + $this->protection = $protection; + $this->dispensable = $dispensable; + } + + public function getName(): string { + return "minecraft:wearable"; + } + + public function getValue(): array { + return [ + "slot" => $this->slot, + "protection" => $this->protection, + "dispensable" => $this->dispensable ]; - } + } - public function isProperty(): bool { - return false; - } + public function isProperty(): bool { + return false; + } } \ No newline at end of file From a0ec1b6a992af2749d66e0ba4041f58046f779b1 Mon Sep 17 00:00:00 2001 From: impera Date: Sun, 2 Mar 2025 19:48:16 -0300 Subject: [PATCH 45/72] Update changelogs --- changelogs/1.3.md | 53 ++++++++++++++++++++++++++++++++++++++++++----- 1 file changed, 48 insertions(+), 5 deletions(-) diff --git a/changelogs/1.3.md b/changelogs/1.3.md index ec697e3..430f589 100644 --- a/changelogs/1.3.md +++ b/changelogs/1.3.md @@ -1,12 +1,14 @@ -# 1.3.0 +**Versions:** [1.3.0](https://github.com/ImperaZim/EasyLibrary/blob/development/changelogs/1.3.md#13) | [1.3.1](https://github.com/ImperaZim/EasyLibrary/blob/development/changelogs/1.3.md#131) | [1.3.2](https://github.com/ImperaZim/EasyLibrary/blob/development/changelogs/1.3.md#132) + +# 1.3 Released February 14, 2025 -**For PocketMine-MP 5.24.0** +**For PocketMine-MP 5.24.X** -1.3.0 is a major feature update to EasyLibrary, including support for PocketMine-MP 5.24.0 plugins, bringing a large list of features and improvements over the previous version. +1.3.0 is a major feature update to EasyLibrary, including support for PocketMine-MP 5.24.X plugins, bringing a large list of features and improvements over the previous version. -It is **not** compatible with plugins written for version 1.2.0 or lower, and plugins may require code changes to work with it. +It is **not** compatible with plugins written for version 1.2.X or lower, and plugins may require code changes to work with it. **As this changelog is quite large, its accuracy and completeness cannot be guaranteed. Make sure you're looking at the [latest revision](https://github.com/ImperaZim/EasyLibrary/blob/development/changelogs/1.3.md), as it may be amended after relatest** @@ -912,8 +914,49 @@ echo "Current time: " . TimeUtils::GetCurrentTime(); --- # 1.3.1 -**For PocketMine-MP 5.25.0** +**For PocketMine-MP 5.25.X** This is an update to fix changes made and bugs caused by PocketMine-MP 5.25x. It is not compatible with plugins written for version 1.3.0 or lower, and plugins may require code changes to work with it. + + +# 1.3.2 +**For PocketMine-MP 5.25.X** + +### Added Components + +- **`StackedByDataComponent`**: + - Determines if the same item with different aux values can stack. + - Additionally, this component defines whether the item actors can merge while floating in the world. +- **`ShouldDespawnComponent`**: + - Determines if an item should despawn while floating in the world. +- **`ShooterComponent`**: + - Shooter component compels an item to shoot projectiles, similarly to a bow or crossbow. + - Must have the use_modifiers component in order to function properly. +- **`RecordComponent`**: + - Record Component used by record items to play music. +- **`LiquidClippedComponent`**: + - Determines whether an item interacts with liquid blocks on use. +- **`InteractButtonComponent`**: + - Ineract Button is a boolean or string that determines if the interact button is shown in touch controls, and what text is displayed on the button. When set to 'true', the default 'Use Item' text will be used. +- **`HoverTextColorComponent`**: + - Determines the color of the item name when hovering over it. +- **`GlintComponent`**: + - Determines whether the item has the enchanted glint render effect on it. +- **`EnchantableValueComponent`**: + - The value of the enchantment +- **`EnchantableSlotComponent`**: + - What enchantments can be applied (ex. Using bow would allow this item to be enchanted as if it were a bow). +- **`DyeableComponent`**: + - Allows the item to be dyed by cauldron water. Once dyed, the item will display the `dyed` texture defined in the `minecraft:icon` component rather than `default`. +- **`DamageComponent`**: + - Determines how much extra damage an item does on attack. Note that this must be a positive value. +- **`DamageAbsorptionComponent`**: + - Causes the item to absorb damage that would otherwise be dealt to its wearer. + - For this to happen, the item needs to have the durability component and be equipped in an armor slot. +- **`BundleInteractionComponent`**: + - `minecraft:bundle_interaction` enables the bundle-specific interaction scheme and tooltip for an item. + - To use this component, the item must have a `minecraft:storage_item` item component defined. +- **`UseModifiersComponent`**: + - Determines how long an item takes to use in combination with components such as Shooter, Throwable, or Food. \ No newline at end of file From 41ac6e56e1fbde1d4a531cf6dd3001b43d7e09e3 Mon Sep 17 00:00:00 2001 From: impera Date: Mon, 3 Mar 2025 10:28:46 -0300 Subject: [PATCH 46/72] New Trigger: ItemTrigger --- changelogs/1.3.md | 102 +++++++++++------- .../components/trigger/ItemTrigger.php | 42 ++++++++ .../components/trigger/TriggerTypes.php | 1 + 3 files changed, 109 insertions(+), 36 deletions(-) create mode 100644 src/imperazim/components/trigger/ItemTrigger.php diff --git a/changelogs/1.3.md b/changelogs/1.3.md index 430f589..0abf711 100644 --- a/changelogs/1.3.md +++ b/changelogs/1.3.md @@ -924,39 +924,69 @@ It is not compatible with plugins written for version 1.3.0 or lower, and plugin # 1.3.2 **For PocketMine-MP 5.25.X** -### Added Components - -- **`StackedByDataComponent`**: - - Determines if the same item with different aux values can stack. - - Additionally, this component defines whether the item actors can merge while floating in the world. -- **`ShouldDespawnComponent`**: - - Determines if an item should despawn while floating in the world. -- **`ShooterComponent`**: - - Shooter component compels an item to shoot projectiles, similarly to a bow or crossbow. - - Must have the use_modifiers component in order to function properly. -- **`RecordComponent`**: - - Record Component used by record items to play music. -- **`LiquidClippedComponent`**: - - Determines whether an item interacts with liquid blocks on use. -- **`InteractButtonComponent`**: - - Ineract Button is a boolean or string that determines if the interact button is shown in touch controls, and what text is displayed on the button. When set to 'true', the default 'Use Item' text will be used. -- **`HoverTextColorComponent`**: - - Determines the color of the item name when hovering over it. -- **`GlintComponent`**: - - Determines whether the item has the enchanted glint render effect on it. -- **`EnchantableValueComponent`**: - - The value of the enchantment -- **`EnchantableSlotComponent`**: - - What enchantments can be applied (ex. Using bow would allow this item to be enchanted as if it were a bow). -- **`DyeableComponent`**: - - Allows the item to be dyed by cauldron water. Once dyed, the item will display the `dyed` texture defined in the `minecraft:icon` component rather than `default`. -- **`DamageComponent`**: - - Determines how much extra damage an item does on attack. Note that this must be a positive value. -- **`DamageAbsorptionComponent`**: - - Causes the item to absorb damage that would otherwise be dealt to its wearer. - - For this to happen, the item needs to have the durability component and be equipped in an armor slot. -- **`BundleInteractionComponent`**: - - `minecraft:bundle_interaction` enables the bundle-specific interaction scheme and tooltip for an item. - - To use this component, the item must have a `minecraft:storage_item` item component defined. -- **`UseModifiersComponent`**: - - Determines how long an item takes to use in combination with components such as Shooter, Throwable, or Food. \ No newline at end of file +## Components + +### General + +### `imperazim\components\trigger` + +- **`ItemTrigger:`** Creates a trigger that executes an action for players who have a specific item in their inventory. + Example usage: + ```php + use imperazim\components\trigger\ItemTrigger; + use pocketmine\item\GoldenApple; + + // Automatically checks if the player has the item and executes the action + $itemTrigger = new ItemTrigger( + GoldenApple::class, + function(Player $player, PlayerInventory $inventory): void { + $player->sendMessage("You have a golden apple in your inventory!"); + // Optional: Interact with the inventory + $inventory->removeItem($inventory->getItem(0)); // Removes first slot item + } + ); + ``` + No need to manually write item-checking conditions - simply provide the item class and callback. + +**Key Features:** +- No manual condition checks required +- Direct access to `Player` and `PlayerInventory` in callbacks + + +## Vendor + +### `imperazim\vendor\customies\item` + +### Core Mechanics +- `StackedByDataComponent`: Controls item stacking behavior for variants with different aux values +- `ShouldDespawnComponent`: Toggles item despawn mechanics for floating entities +- `ShooterComponent`: Enables projectile launching (requires `UseModifiersComponent`) +- `RecordComponent`: Adds music playback functionality to items + +### Visual & Interaction +- `HoverTextColorComponent`: Sets custom color for item name hover text +- `GlintComponent`: Toggles enchantment glow effect +- `InteractButtonComponent`: Configures touch control interaction button (supports custom text) +- `LiquidClippedComponent`: Defines liquid block interaction behavior + +### Item Customization +- `DyeableComponent`: Enables cauldron-based dyeing (requires `dyed` texture definition) +- `EnchantableSlotComponent`: Restricts applicable enchantment types (e.g., bow-only enchants) +- `EnchantableValueComponent`: Sets base enchantment strength + +### Combat & Durability +- `DamageComponent`: Increases attack damage (positive values only) +- `DamageAbsorptionComponent`: Reduces incoming damage when equipped as armor (requires durability) + +### Specialized Systems +- `BundleInteractionComponent`: Enables bundle storage mechanics (requires `storage_item` component) +- `UseModifiersComponent`: Configures item usage timing for food/throwable/shooter items +``` + +**Key Improvements:** +- Structured hierarchy with clear section separation +- Component grouping by functional category +- Consistent formatting for code blocks and component names +- Concise yet descriptive explanations +- Explicit dependency warnings +- Removed redundant technical jargon \ No newline at end of file diff --git a/src/imperazim/components/trigger/ItemTrigger.php b/src/imperazim/components/trigger/ItemTrigger.php new file mode 100644 index 0000000..98f196e --- /dev/null +++ b/src/imperazim/components/trigger/ItemTrigger.php @@ -0,0 +1,42 @@ +getInventory(); + + // Functional approach: Check if any item matches the class + $hasItem = count(array_filter( + $inventory->getContents(), + fn(Item $item) => $item instanceof $itemClass + )) > 0; + + if ($hasItem) { + $callback($player, $inventory); // Pass both player and inventory + return true; + } + return false; + }; + + parent::__construct($condition, fn(Player $player) => $callback($player, $player->getInventory())); + } +} \ No newline at end of file diff --git a/src/imperazim/components/trigger/TriggerTypes.php b/src/imperazim/components/trigger/TriggerTypes.php index 6c44ba7..4bc902f 100644 --- a/src/imperazim/components/trigger/TriggerTypes.php +++ b/src/imperazim/components/trigger/TriggerTypes.php @@ -12,5 +12,6 @@ final class TriggerTypes { const GLOBAL = 0; const PER_PLAYER = 1; + const ITEM = 2; } \ No newline at end of file From ad46c55fdf7707a22bdc96cc896f3977240748cd Mon Sep 17 00:00:00 2001 From: impera Date: Mon, 3 Mar 2025 10:30:23 -0300 Subject: [PATCH 47/72] New Customies ItemComponent: ItemTaskComponent --- changelogs/1.3.md | 1 + .../vendor/customies/CustomiesManager.php | 17 +++-- .../item/component/ItemTaskComponent.php | 68 +++++++++++++++++++ .../vendor/customies/task/ItemTask.php | 26 +++++++ 4 files changed, 107 insertions(+), 5 deletions(-) create mode 100644 src/imperazim/vendor/customies/item/component/ItemTaskComponent.php create mode 100644 src/imperazim/vendor/customies/task/ItemTask.php diff --git a/changelogs/1.3.md b/changelogs/1.3.md index 0abf711..a62abb2 100644 --- a/changelogs/1.3.md +++ b/changelogs/1.3.md @@ -962,6 +962,7 @@ It is not compatible with plugins written for version 1.3.0 or lower, and plugin - `ShouldDespawnComponent`: Toggles item despawn mechanics for floating entities - `ShooterComponent`: Enables projectile launching (requires `UseModifiersComponent`) - `RecordComponent`: Adds music playback functionality to items +- `ItemTaskComponent`: Creates a new ItemTaskComponent to define a task that checks for specific items in a player's inventory. ### Visual & Interaction - `HoverTextColorComponent`: Sets custom color for item name hover text diff --git a/src/imperazim/vendor/customies/CustomiesManager.php b/src/imperazim/vendor/customies/CustomiesManager.php index bd78af2..2697ea8 100644 --- a/src/imperazim/vendor/customies/CustomiesManager.php +++ b/src/imperazim/vendor/customies/CustomiesManager.php @@ -72,11 +72,18 @@ public static function init(PluginToolkit $plugin): array { new self() ], self::SCHEDULER_COMPONENT => [ - 'type' => 'delayed', - 'class' => new ClosureTask(static function () use ($cachePath): void { - CustomiesBlockFactory::getInstance()->addWorkerInitHook($cachePath); - }), - 'sleep' => 0 + [ + 'type' => 'delayed', + 'class' => new ClosureTask(static function () use ($cachePath): void { + CustomiesBlockFactory::getInstance()->addWorkerInitHook($cachePath); + }), + 'sleep' => 0 + ], + [ + 'type' => 'repeating', + 'class' => new ItemTask(), + 'sleep' => 20 + ] ] ]; } diff --git a/src/imperazim/vendor/customies/item/component/ItemTaskComponent.php b/src/imperazim/vendor/customies/item/component/ItemTaskComponent.php new file mode 100644 index 0000000..1b5fb59 --- /dev/null +++ b/src/imperazim/vendor/customies/item/component/ItemTaskComponent.php @@ -0,0 +1,68 @@ +itemClass = $itemClass; + $this->callback = $callback; + $this->filter = $filter; + } + + public function getName(): string { + return "minecraft:item_task"; + } + + public function getValue(): array { + return [ + 'item_class' => $this->itemClass, + 'filter' => $this->filter, + ]; + } + + public function isProperty(): bool { + return false; + } + + public function checkCondition(Player $player): ?Item { + $inventory = $player->getInventory(); + switch ($this->filter) { + case self::FILTER_HAND: + $item = $inventory->getItemInHand(); + return $item instanceof $this->itemClass ? $item : null; + default: + foreach ($inventory->getContents() as $item) { + if ($item instanceof $this->itemClass) { + return $item; + } + } + return null; + } + } + + public function execute(Player $player, Item $item): void { + ($this->callback)($player, $item); + } +} \ No newline at end of file diff --git a/src/imperazim/vendor/customies/task/ItemTask.php b/src/imperazim/vendor/customies/task/ItemTask.php new file mode 100644 index 0000000..eb6a687 --- /dev/null +++ b/src/imperazim/vendor/customies/task/ItemTask.php @@ -0,0 +1,26 @@ +getOnlinePlayers() as $player) { + foreach (CustomiesItemFactory::getInstance()->getItemRegisteredList() as $itemData) { + $item = $itemData['item']; + if (!$item->hasComponent("minecraft:item_task")) continue; + + /** @var \imperazim\vendor\customies\item\component\ItemTaskComponent $component */ + $component = $item->getComponent("minecraft:item_task"); + if ($itemInstance = $component->checkCondition($player)) { + $component->execute($player, $itemInstance); + } + } + } + } +} \ No newline at end of file From 87fb0b5442d75822be6345ff1623fbb6b079cc0b Mon Sep 17 00:00:00 2001 From: impera Date: Mon, 3 Mar 2025 10:59:04 -0300 Subject: [PATCH 48/72] changelogs update --- changelogs/1.3.md | 126 +++++++++++++++++++++++++++++++++++----------- 1 file changed, 97 insertions(+), 29 deletions(-) diff --git a/changelogs/1.3.md b/changelogs/1.3.md index a62abb2..8b6bac4 100644 --- a/changelogs/1.3.md +++ b/changelogs/1.3.md @@ -948,46 +948,114 @@ It is not compatible with plugins written for version 1.3.0 or lower, and plugin ``` No need to manually write item-checking conditions - simply provide the item class and callback. -**Key Features:** -- No manual condition checks required -- Direct access to `Player` and `PlayerInventory` in callbacks - ## Vendor ### `imperazim\vendor\customies\item` ### Core Mechanics -- `StackedByDataComponent`: Controls item stacking behavior for variants with different aux values -- `ShouldDespawnComponent`: Toggles item despawn mechanics for floating entities -- `ShooterComponent`: Enables projectile launching (requires `UseModifiersComponent`) -- `RecordComponent`: Adds music playback functionality to items -- `ItemTaskComponent`: Creates a new ItemTaskComponent to define a task that checks for specific items in a player's inventory. +- **`StackedByDataComponent`**: Controls item stacking behavior for variants with different aux values. + **Example:** + ```php + $item->addComponent(new StackedByDataComponent(true)); // Allows stacking of items with different aux values + ``` + +- **`ShouldDespawnComponent`**: Toggles item despawn mechanics for floating entities. + **Example:** + ```php + $item->addComponent(new ShouldDespawnComponent(false)); // Prevents the item from despawning + ``` + +- **`ShooterComponent`**: Enables projectile launching (requires `UseModifiersComponent`). + **Example:** + ```php + $item->addComponent(new ShooterComponent("arrow", ...view component)); // Shoots arrows with a speed of 1.5 + ``` + +- **`RecordComponent`**: Adds music playback functionality to items. + **Example:** + ```php + $item->addComponent(new RecordComponent(1, 60, "record.song")); // Plays a specific music record + ``` + +- **`ItemTaskComponent`**: Creates a new ItemTaskComponent to define a task that checks for specific items in a player's inventory. + **Example:** + ```php + $item->addComponent(new ItemTaskComponent( + DiamondSword::class, + function(Player $player, Item $item): void { + $player->sendMessage("You are holding a Diamond Sword!"); + }, + ItemTaskComponent::FILTER_HAND + )); + ``` ### Visual & Interaction -- `HoverTextColorComponent`: Sets custom color for item name hover text -- `GlintComponent`: Toggles enchantment glow effect -- `InteractButtonComponent`: Configures touch control interaction button (supports custom text) -- `LiquidClippedComponent`: Defines liquid block interaction behavior +- **`HoverTextColorComponent`**: Sets custom color for item name hover text. + **Example:** + ```php + $item->addComponent(new HoverTextColorComponent("color")); // Sets hover text color to red. See: https://minecraft.wiki/w/Formatting_codes#Color_codes + ``` + +- **`GlintComponent`**: Toggles enchantment glow effect. + **Example:** + ```php + $item->addComponent(new GlintComponent(true)); // Adds an enchantment glow to the item + ``` + +- **`InteractButtonComponent`**: Configures touch control interaction button (supports custom text). + **Example:** + ```php + $item->addComponent(new InteractButtonComponent("Use Item")); // Displays "Use Item" on the interact button + ``` + +- **`LiquidClippedComponent`**: Defines liquid block interaction behavior. + **Example:** + ```php + $item->addComponent(new LiquidClippedComponent(true)); // Allows interaction with liquid blocks + ``` ### Item Customization -- `DyeableComponent`: Enables cauldron-based dyeing (requires `dyed` texture definition) -- `EnchantableSlotComponent`: Restricts applicable enchantment types (e.g., bow-only enchants) -- `EnchantableValueComponent`: Sets base enchantment strength +- **`DyeableComponent`**: Enables cauldron-based dyeing (requires `dyed` texture definition). + **Example:** + ```php + $item->addComponent(new DyeableComponent("#hex")); // Allows the item to be dyed in a cauldron + ``` + +- **`EnchantableSlotComponent`**: Restricts applicable enchantment types (e.g., bow-only enchants). + **Example:** + ```php + $item->addComponent(new EnchantableSlotComponent(self::SLOT_NAME)); // Allows only slot_name enchantments + ``` + +- **`EnchantableValueComponent`**: Sets base enchantment strength. + **Example:** + ```php + $item->addComponent(new EnchantableValueComponent(10)); // Sets base enchantment strength to 10 + ``` ### Combat & Durability -- `DamageComponent`: Increases attack damage (positive values only) -- `DamageAbsorptionComponent`: Reduces incoming damage when equipped as armor (requires durability) +- **`DamageComponent`**: Increases attack damage (positive values only). + **Example:** + ```php + $item->addComponent(new DamageComponent(5)); // Adds 5 extra damage to the item + ``` + +- **`DamageAbsorptionComponent`**: Reduces incoming damage when equipped as armor (requires durability). + **Example:** + ```php + $item->addComponent(new DamageAbsorptionComponent(3)); // Absorbs 3 points of damage + ``` ### Specialized Systems -- `BundleInteractionComponent`: Enables bundle storage mechanics (requires `storage_item` component) -- `UseModifiersComponent`: Configures item usage timing for food/throwable/shooter items -``` - -**Key Improvements:** -- Structured hierarchy with clear section separation -- Component grouping by functional category -- Consistent formatting for code blocks and component names -- Concise yet descriptive explanations -- Explicit dependency warnings -- Removed redundant technical jargon \ No newline at end of file +- **`BundleInteractionComponent`**: Enables bundle storage mechanics (requires `storage_item` component). + **Example:** + ```php + $item->addComponent(new BundleInteractionComponent(4)); // Enables Bundle Interactions with 4 slots + ``` + +- **`UseModifiersComponent`**: Configures item usage timing for food/throwable/shooter items. + **Example:** + ```php + $item->addComponent(new UseModifiersComponent(1.0, 1.5)); // Sets item usage modifiers +1.0 with duration to 1.5 seconds + ``` \ No newline at end of file From 8134b600910c0bc8f97b1e02f6de044ee2478773 Mon Sep 17 00:00:00 2001 From: impera Date: Mon, 3 Mar 2025 17:32:28 -0300 Subject: [PATCH 49/72] This is a bugfix update. --- changelogs/1.3.md | 2 +- .../vendor/customies/CustomiesManager.php | 20 ++++++++ .../item/component/OnHitEffectComponent.php | 50 +++++++++++++++++++ 3 files changed, 71 insertions(+), 1 deletion(-) create mode 100644 src/imperazim/vendor/customies/item/component/OnHitEffectComponent.php diff --git a/changelogs/1.3.md b/changelogs/1.3.md index 8b6bac4..cd02b5c 100644 --- a/changelogs/1.3.md +++ b/changelogs/1.3.md @@ -982,7 +982,7 @@ It is not compatible with plugins written for version 1.3.0 or lower, and plugin **Example:** ```php $item->addComponent(new ItemTaskComponent( - DiamondSword::class, + self::class, function(Player $player, Item $item): void { $player->sendMessage("You are holding a Diamond Sword!"); }, diff --git a/src/imperazim/vendor/customies/CustomiesManager.php b/src/imperazim/vendor/customies/CustomiesManager.php index 2697ea8..b2d10a6 100644 --- a/src/imperazim/vendor/customies/CustomiesManager.php +++ b/src/imperazim/vendor/customies/CustomiesManager.php @@ -10,6 +10,7 @@ use pocketmine\scheduler\ClosureTask; use pocketmine\event\player\PlayerDropItemEvent; use pocketmine\event\player\PlayerInteractEvent; +use pocketmine\event\entity\EntityDamageByEntityEvent; use pocketmine\event\server\DataPacketSendEvent; use pocketmine\network\mcpe\protocol\StartGamePacket; use pocketmine\network\mcpe\protocol\ItemRegistryPacket; @@ -32,6 +33,7 @@ use imperazim\components\plugin\PluginComponent; use imperazim\components\plugin\traits\PluginComponentsTrait; +use imperazim\vendor\customies\task\ItemTask; use imperazim\vendor\customies\item\ItemComponents; use imperazim\vendor\customies\item\CustomiesItemFactory; use imperazim\vendor\customies\block\CustomiesBlockFactory; @@ -165,4 +167,22 @@ public function onTitle(InventoryTransactionEvent $event) : void { } } + public function onEntityDamage(EntityDamageByEntityEvent $event): void { + $damager = $event->getDamager(); + $entity = $event->getEntity(); + + // Verifica se o agressor e a vítima são jogadores + if ($damager instanceof Player && $entity instanceof Player) { + $item = $damager->getInventory()->getItemInHand(); + + // Verifica se o item tem o cjogadores + if ($item instanceof ItemComponents) { + $component = $item->getComponents()['minecraft:on_hit_effect']; + if ($item->hasComponent($component->getName())) { + $component->applyEffect($entity); + } + } + } + } + } \ No newline at end of file diff --git a/src/imperazim/vendor/customies/item/component/OnHitEffectComponent.php b/src/imperazim/vendor/customies/item/component/OnHitEffectComponent.php new file mode 100644 index 0000000..9f0f838 --- /dev/null +++ b/src/imperazim/vendor/customies/item/component/OnHitEffectComponent.php @@ -0,0 +1,50 @@ +plugin = $plugin; + $this->effect = $effect; + $this->plugin->getServer()->getPluginManager()->registerEvents($this, $plugin); + } + + public function getName(): string { + return "minecraft:on_hit_effect"; + } + + public function getValue(): array { + return [ + 'effect_id' => $this->effect->getType()->getId(), + 'effect_duration' => $this->effect->getDuration(), + 'effect_amplifier' => $this->effect->getAmplifier(), + ]; + } + + public function isProperty(): bool { + return false; + } + + public function applyEffect(Player $entity): void { + $entity->getEffects()->add($this->effect); + } +} \ No newline at end of file From 05c8de1bc24b2713305be1aabc3e50b235593960 Mon Sep 17 00:00:00 2001 From: impera Date: Mon, 3 Mar 2025 17:42:41 -0300 Subject: [PATCH 50/72] Removed component. --- src/imperazim/vendor/customies/task/ItemTask.php | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/src/imperazim/vendor/customies/task/ItemTask.php b/src/imperazim/vendor/customies/task/ItemTask.php index eb6a687..f0e87c7 100644 --- a/src/imperazim/vendor/customies/task/ItemTask.php +++ b/src/imperazim/vendor/customies/task/ItemTask.php @@ -11,8 +11,7 @@ final class ItemTask extends Task { public function onRun(): void { foreach (Server::getInstance()->getOnlinePlayers() as $player) { - foreach (CustomiesItemFactory::getInstance()->getItemRegisteredList() as $itemData) { - $item = $itemData['item']; + foreach ($player->getInventory()->getContents() as $item) { if (!$item->hasComponent("minecraft:item_task")) continue; /** @var \imperazim\vendor\customies\item\component\ItemTaskComponent $component */ From cdd23d8bea245b24871889dacf342f290034ba0a Mon Sep 17 00:00:00 2001 From: impera Date: Mon, 3 Mar 2025 18:16:34 -0300 Subject: [PATCH 51/72] Item tasks have been optimized. --- .../vendor/customies/task/ItemTask.php | 24 ++++++++++++------- 1 file changed, 15 insertions(+), 9 deletions(-) diff --git a/src/imperazim/vendor/customies/task/ItemTask.php b/src/imperazim/vendor/customies/task/ItemTask.php index f0e87c7..832055d 100644 --- a/src/imperazim/vendor/customies/task/ItemTask.php +++ b/src/imperazim/vendor/customies/task/ItemTask.php @@ -3,21 +3,27 @@ namespace imperazim\vendor\customies\task; -use imperazim\vendor\customies\item\CustomiesItemFactory; -use pocketmine\scheduler\Task; use pocketmine\Server; +use pocketmine\scheduler\Task; +use imperazim\vendor\customies\item\ItemComponents; +use imperazim\vendor\customies\item\CustomiesItemFactory; final class ItemTask extends Task { public function onRun(): void { - foreach (Server::getInstance()->getOnlinePlayers() as $player) { - foreach ($player->getInventory()->getContents() as $item) { - if (!$item->hasComponent("minecraft:item_task")) continue; + $server = Server::getInstance(); + + foreach ($server->getOnlinePlayers() as $player) { + $inventory = $player->getInventory(); + + foreach ($inventory->getContents() as $item) { + if ($item instanceof ItemComponents && $item->hasComponent("minecraft:item_task")) { + /** @var \imperazim\vendor\customies\item\component\ItemTaskComponent $component */ + $component = $item->getComponent("minecraft:item_task"); - /** @var \imperazim\vendor\customies\item\component\ItemTaskComponent $component */ - $component = $item->getComponent("minecraft:item_task"); - if ($itemInstance = $component->checkCondition($player)) { - $component->execute($player, $itemInstance); + if ($itemInstance = $component->checkCondition($player)) { + $component->execute($player, $itemInstance); + } } } } From 84da94f515746524f0429fd8b91a2b9f35aa289c Mon Sep 17 00:00:00 2001 From: impera Date: Sat, 8 Mar 2025 19:44:34 -0300 Subject: [PATCH 52/72] RFC Command: PluginsCommand --- .../components/command/CommandManager.php | 2 + .../command/defaults/PluginsCommand.php | 96 +++++++++++++++++++ 2 files changed, 98 insertions(+) create mode 100644 src/imperazim/components/command/defaults/PluginsCommand.php diff --git a/src/imperazim/components/command/CommandManager.php b/src/imperazim/components/command/CommandManager.php index 55aa1a8..39fed73 100644 --- a/src/imperazim/components/command/CommandManager.php +++ b/src/imperazim/components/command/CommandManager.php @@ -9,6 +9,7 @@ use imperazim\components\plugin\traits\PluginComponentsTrait; use imperazim\components\command\defaults\VersionCommand; +use imperazim\components\command\defaults\PluginsCommand; use imperazim\components\command\defaults\GeneratePluginCommand; /** @@ -26,6 +27,7 @@ public static function init(PluginToolkit $plugin): array { self::setPlugin(plugin: $plugin); $plugin->overwriteCommands($plugin, [ 'version' => VersionCommand::class, + 'plugins' => PluginsCommand::class, 'genplugin' => GeneratePluginCommand::class, ]); return []; diff --git a/src/imperazim/components/command/defaults/PluginsCommand.php b/src/imperazim/components/command/defaults/PluginsCommand.php new file mode 100644 index 0000000..e5e1bba --- /dev/null +++ b/src/imperazim/components/command/defaults/PluginsCommand.php @@ -0,0 +1,96 @@ +getServer()->getPluginManager()->getPlugins(); + $enabled = count(array_filter($plugins, fn(Plugin $p) => $p->isEnabled())); + + $sender->sendMessage(TextFormat::BOLD . TextFormat::GOLD . "===== PLUGINS (" . count($plugins) . ") ====="); + $sender->sendMessage(TextFormat::GRAY . "Enabled: " . TextFormat::GREEN . $enabled . TextFormat::GRAY . " | Disabled: " . TextFormat::RED . (count($plugins) - $enabled)); + + $list = array_map(function(Plugin $plugin): string { + return ($plugin->isEnabled() ? TextFormat::GREEN : TextFormat::RED) . $plugin->getDescription()->getFullName(); + }, $plugins); + sort($list, SORT_STRING); + + $sender->sendMessage(TextFormat::RESET . implode("\n", $list)); + $sender->sendMessage(TextFormat::BOLD . TextFormat::GOLD . "=============================="); + } else { + $pluginName = implode(" ", $args); + $exactPlugin = $sender->getServer()->getPluginManager()->getPlugin($pluginName); + + if ($exactPlugin instanceof Plugin) { + $this->describePlugin($exactPlugin, $sender); + return; + } + + $found = false; + $lowerName = strtolower($pluginName); + foreach ($sender->getServer()->getPluginManager()->getPlugins() as $p) { + if (stripos($p->getName(), $lowerName) !== false) { + $this->describePlugin($p, $sender); + $found = true; + } + } + + if (!$found) { + $sender->sendMessage(TextFormat::RED . "No plugin found matching '" . $pluginName . "'."); + } + } + } catch (\Throwable $e) { + new \crashdump($e); + } + } + + private function describePlugin(Plugin $plugin, mixed $sender): void { + $desc = $plugin->getDescription(); + $status = $plugin->isEnabled() ? TextFormat::GREEN . "Enabled" : TextFormat::RED . "Disabled"; + + $sender->sendMessage(TextFormat::BOLD . TextFormat::DARK_AQUA . "===== " . $desc->getName() . " ====="); + $sender->sendMessage(TextFormat::YELLOW . "Version: " . TextFormat::WHITE . $desc->getVersion()); + $sender->sendMessage(TextFormat::YELLOW . "Status: " . $status); + + if ($desc->getDescription() !== "") { + $sender->sendMessage(TextFormat::YELLOW . "Description: " . TextFormat::GRAY . $desc->getDescription()); + } + if ($desc->getWebsite() !== "") { + $sender->sendMessage(TextFormat::YELLOW . "Website: " . TextFormat::BLUE . $desc->getWebsite()); + } + if (count($authors = $desc->getAuthors()) > 0) { + $sender->sendMessage(TextFormat::YELLOW . "Authors: " . TextFormat::GOLD . implode(", ", $authors)); + } + $sender->sendMessage(TextFormat::BOLD . TextFormat::DARK_AQUA . "======================" . str_repeat("=", strlen($desc->getName()))); + } + +} \ No newline at end of file From 06748d79ae4337b351d722d045e82440feb7c84c Mon Sep 17 00:00:00 2001 From: impera Date: Thu, 17 Apr 2025 02:00:38 -0300 Subject: [PATCH 53/72] [BETA] All types are accepted in the file class, but not all accept set/get functions. --- src/imperazim/components/filesystem/File.php | 9 ++++----- src/imperazim/components/filesystem/Path.php | 8 +++++--- .../filesystem/traits/FileExtensionTypes.php | 18 ++++++++++++++---- .../components/plugin/PluginToolkit.php | 2 +- 4 files changed, 24 insertions(+), 13 deletions(-) diff --git a/src/imperazim/components/filesystem/File.php b/src/imperazim/components/filesystem/File.php index a507a0c..18d0e6c 100644 --- a/src/imperazim/components/filesystem/File.php +++ b/src/imperazim/components/filesystem/File.php @@ -43,9 +43,6 @@ public function __construct( } else { $directory = str_replace('//', '/', $directoryOrConfig . '/'); } - if (!in_array($fileType, self::getTypes())) { - throw new FileSystemException("Invalid file type: $fileType"); - } $this->directoryOrConfig = $directory; $this->fileName = $fileName ?? ''; $this->fileType = $fileType ?? self::TYPE_YML; @@ -136,8 +133,9 @@ public static function serializeContent(string $extension, array $data): string 'txt' => self::writeList(array_keys($data)), 'ini' => self::writeIniFile($data) }; + } else { + return self::writeList(array_keys($data)); } - throw new FileSystemException("Unsupported file type: {$extension}"); } /** @@ -156,8 +154,9 @@ public static function deserializeContent(string $extension, string $fileContent 'txt' => array_fill_keys(self::parseList($fileContent), true), 'ini' => parse_ini_string($fileContent, true) }; + } else { + return array_fill_keys(self::parseList($fileContent), true); } - throw new FileSystemException("Unsupported file type: {$extension}"); } /** diff --git a/src/imperazim/components/filesystem/Path.php b/src/imperazim/components/filesystem/Path.php index baff19b..97ed253 100644 --- a/src/imperazim/components/filesystem/Path.php +++ b/src/imperazim/components/filesystem/Path.php @@ -270,11 +270,13 @@ public static function getRecursiveFiles(string $folder): array { foreach ($files as $file) { if ($file->isFile()) { + $extension = $file->getExtension(); + $fileType = File::getTypeByExtension($extension); $filesInfo[] = [ 'directory' => $file->getPath(), - 'fileName' => $file->getBasename(), - 'fileType' => File::getTypeByExtension($file->getExtension()), - 'content' => File::deserializeContent($file->getExtension(), file_get_contents($file->getRealPath())) + 'fileName' => $file->getBasename('.' . $extension), + 'fileType' => $fileType, + 'content' => File::deserializeContent($extension, file_get_contents($file->getRealPath())) ]; } } diff --git a/src/imperazim/components/filesystem/traits/FileExtensionTypes.php b/src/imperazim/components/filesystem/traits/FileExtensionTypes.php index 8a41b92..8fce184 100644 --- a/src/imperazim/components/filesystem/traits/FileExtensionTypes.php +++ b/src/imperazim/components/filesystem/traits/FileExtensionTypes.php @@ -58,7 +58,10 @@ public static function getExtensions(): array { public static function getTypeByExtension(string $extension): ?string { $extension = strtolower($extension); $type = array_search($extension, self::$typeToExtension, true); - return $type !== false ? $type : null; + if ($type !== false) { + return $type; + } + return 'file:' . $extension; } /** @@ -68,8 +71,15 @@ public static function getTypeByExtension(string $extension): ?string { * @return string|null */ public static function getExtensionByType(string $type, bool $withPoint = false): ?string { - $extension = self::$typeToExtension[$type] ?? null; - return $extension !== null ? ($withPoint ? '.' . $extension : $extension) : null; + if (isset(self::$typeToExtension[$type])) { + $extension = self::$typeToExtension[$type]; + return $withPoint ? '.' . $extension : $extension; + } + if (str_starts_with($type, 'file:')) { + $extension = substr($type, 5); + return $withPoint ? '.' . $extension : $extension; + } + return null; } - + } \ No newline at end of file diff --git a/src/imperazim/components/plugin/PluginToolkit.php b/src/imperazim/components/plugin/PluginToolkit.php index 526365a..c961f8e 100644 --- a/src/imperazim/components/plugin/PluginToolkit.php +++ b/src/imperazim/components/plugin/PluginToolkit.php @@ -351,7 +351,7 @@ public function saveRecursiveResources(?string $loadType = '--merge'): ?array { private function processFile(array $file, ?string $loadType): ?File { try { $fileName = $file['fileName'] ?? null; - $fileType = $file['fileType'] ?? null; + $fileType = $file['fileType'] ?? 'file:unknown'; $fileContent = $file['content'] ?? null; $fileDirectory = $file['directory'] ?? null; From 4875ed818eae80da3f21af9d680b8a6d91e5b61a Mon Sep 17 00:00:00 2001 From: impera Date: Mon, 19 May 2025 00:04:16 -0300 Subject: [PATCH 54/72] Starting refactoring of the forms sub library. --- src/imperazim/vendor/libform/Form.php | 72 ------- .../vendor/libform/elements/Button.php | 119 ----------- .../vendor/libform/elements/Content.php | 50 ----- .../vendor/libform/elements/Dropdown.php | 31 --- .../vendor/libform/elements/Element.php | 53 ----- .../libform/elements/ElementWithValue.php | 43 ---- .../vendor/libform/elements/Image.php | 74 ------- .../vendor/libform/elements/Input.php | 61 ------ .../vendor/libform/elements/Label.php | 51 ----- .../vendor/libform/elements/ModalButton.php | 73 ------- .../vendor/libform/elements/Selector.php | 62 ------ .../vendor/libform/elements/Slider.php | 84 -------- .../vendor/libform/elements/StepSlider.php | 33 --- .../vendor/libform/elements/Title.php | 50 ----- .../vendor/libform/elements/Toggle.php | 66 ------ .../libform/interaction/ButtonResponse.php | 32 --- .../interaction/CustomElementsResponse.php | 79 ------- .../interaction/ModalButtonResponse.php | 31 --- .../libform/traits/IdentifiableElement.php | 32 --- .../vendor/libform/types/CustomForm.php | 199 ------------------ .../vendor/libform/types/LongForm.php | 141 ------------- .../vendor/libform/types/ModalForm.php | 138 ------------ 22 files changed, 1574 deletions(-) delete mode 100644 src/imperazim/vendor/libform/Form.php delete mode 100644 src/imperazim/vendor/libform/elements/Button.php delete mode 100644 src/imperazim/vendor/libform/elements/Content.php delete mode 100644 src/imperazim/vendor/libform/elements/Dropdown.php delete mode 100644 src/imperazim/vendor/libform/elements/Element.php delete mode 100644 src/imperazim/vendor/libform/elements/ElementWithValue.php delete mode 100644 src/imperazim/vendor/libform/elements/Image.php delete mode 100644 src/imperazim/vendor/libform/elements/Input.php delete mode 100644 src/imperazim/vendor/libform/elements/Label.php delete mode 100644 src/imperazim/vendor/libform/elements/ModalButton.php delete mode 100644 src/imperazim/vendor/libform/elements/Selector.php delete mode 100644 src/imperazim/vendor/libform/elements/Slider.php delete mode 100644 src/imperazim/vendor/libform/elements/StepSlider.php delete mode 100644 src/imperazim/vendor/libform/elements/Title.php delete mode 100644 src/imperazim/vendor/libform/elements/Toggle.php delete mode 100644 src/imperazim/vendor/libform/interaction/ButtonResponse.php delete mode 100644 src/imperazim/vendor/libform/interaction/CustomElementsResponse.php delete mode 100644 src/imperazim/vendor/libform/interaction/ModalButtonResponse.php delete mode 100644 src/imperazim/vendor/libform/traits/IdentifiableElement.php delete mode 100644 src/imperazim/vendor/libform/types/CustomForm.php delete mode 100644 src/imperazim/vendor/libform/types/LongForm.php delete mode 100644 src/imperazim/vendor/libform/types/ModalForm.php diff --git a/src/imperazim/vendor/libform/Form.php b/src/imperazim/vendor/libform/Form.php deleted file mode 100644 index 2b9ebe0..0000000 --- a/src/imperazim/vendor/libform/Form.php +++ /dev/null @@ -1,72 +0,0 @@ -title; - } - - /** - * Sets the title of the form. - * @param Title $title The new title of the form. - */ - public function setTitle(?Title $title = new Title('')): void { - $this->title = $title; - } - - /** - * Sends the form to the specified player. - * @param Player $player The player to send the form to. - */ - public function sendTo(Player $player): void { - $player->sendForm($this); - } - - /** - * Serializes the form data to an array. - * @return array The serialized form data. - */ - final public function jsonSerialize(): array { - $data = $this->serializeFormData(); - $data['type'] = $this->getType(); - $data['title'] = $this->getTitle()->getText(); - return $data; - } - - /** - * Serializes specific form data to an array. - * @return array The serialized specific form data. - */ - abstract protected function serializeFormData(): array; - - /** - * Gets the type of the form. - * @return string The type of the form. - */ - abstract protected function getType(): string; - -} \ No newline at end of file diff --git a/src/imperazim/vendor/libform/elements/Button.php b/src/imperazim/vendor/libform/elements/Button.php deleted file mode 100644 index 4d7f20b..0000000 --- a/src/imperazim/vendor/libform/elements/Button.php +++ /dev/null @@ -1,119 +0,0 @@ -setIdentifier($identifier); - } - - /** - * Defines the text of the button. - * @param string|array $text The new text for the button. - * @return self Returns the current instance for method chaining. - */ - public function setText(string|array $text): self { - $this->text = $text; - return $this; - } - - /** - * Gets the text of the button. - * @return string The text of the button. - */ - public function getText(): string { - return is_array($this->text) ? implode("§r\n", $this->text) : $this->text; - } - - /** - * Defines the image of the button. - * @param Image $image The new image for the button. - * @return self Returns the current instance for method chaining. - */ - public function setImage(Image $image): self { - $this->image = $image; - return $this; - } - - /** - * Gets the image of the button. - * @return Image|null The image of the button. - */ - public function getImage(): ?Image { - return $this->image; - } - - /** - * Defines the response function of the button. - * @param ButtonResponse $response The new response function for the button. - * @return self Returns the current instance for method chaining. - */ - public function setResponse(ButtonResponse $response): self { - $this->response = $response; - return $this; - } - - /** - * Gets the response function of the button. - * @return ButtonResponse|null The response function of the button. - */ - public function getResponse(): ?ButtonResponse { - return $this->response; - } - - /** - * Defines whether to reopen. - * @param bool $reopen The new value for should reopen. - * @return self Returns result whether to reopen. - */ - public function setShouldReopen(bool $reopen): self { - $this->reopen = $reopen; - return $this; - } - - /** - * Gets result whether to reopen - * @return bool Gets result whether to reopen - */ - public function getShouldReopen(): bool { - return $this->reopen; - } - - /** - * Serializes the button to an array for JSON encoding. - * @return array The serialized data of the button. - */ - public function jsonSerialize(): array { - $data = [ - "text" => $this->getText() - ]; - if ($this->image !== null) { - $data["image"] = $this->image; - } - return $data; - } -} \ No newline at end of file diff --git a/src/imperazim/vendor/libform/elements/Content.php b/src/imperazim/vendor/libform/elements/Content.php deleted file mode 100644 index 63c54bc..0000000 --- a/src/imperazim/vendor/libform/elements/Content.php +++ /dev/null @@ -1,50 +0,0 @@ -text = $text; - return $this; - } - - /** - * Gets the text of the content. - * @return string The text of the content. - */ - public function getText(): string { - return is_array($this->text) ? implode("§r\n", $this->text) : $this->text; - } - - /** - * Serializes the content to an array for JSON encoding. - * @return array The serialized data of the content. - */ - public function jsonSerialize(): array { - $data = [ - "text" => $this->getText() - ]; - return $data; - } -} \ No newline at end of file diff --git a/src/imperazim/vendor/libform/elements/Dropdown.php b/src/imperazim/vendor/libform/elements/Dropdown.php deleted file mode 100644 index 8903e4d..0000000 --- a/src/imperazim/vendor/libform/elements/Dropdown.php +++ /dev/null @@ -1,31 +0,0 @@ - The serialized specific element data. - */ - protected function serializeElementData(): array { - return [ - "options" => $this->options, - "default" => $this->default, - ]; - } - } \ No newline at end of file diff --git a/src/imperazim/vendor/libform/elements/Element.php b/src/imperazim/vendor/libform/elements/Element.php deleted file mode 100644 index 0d253a2..0000000 --- a/src/imperazim/vendor/libform/elements/Element.php +++ /dev/null @@ -1,53 +0,0 @@ - The serialized data of the element. - */ - final public function jsonSerialize(): array { - $data = $this->serializeElementData(); - $data["type"] = $this->getType(); - $data["text"] = $this->text; - return $data; - } - - /** - * Serializes specific element data to an array. - * @return array The serialized specific element data. - */ - abstract protected function serializeElementData(): array; - - /** - * Gets the type of the element. - * @return string The type of the element. - */ - abstract protected function getType(): string; - - /** - * Validates the value for the element. - * @param mixed $value The value to validate. - */ - abstract protected function validateValue(mixed $value): void; - -} \ No newline at end of file diff --git a/src/imperazim/vendor/libform/elements/ElementWithValue.php b/src/imperazim/vendor/libform/elements/ElementWithValue.php deleted file mode 100644 index 1433a3e..0000000 --- a/src/imperazim/vendor/libform/elements/ElementWithValue.php +++ /dev/null @@ -1,43 +0,0 @@ -value ?? throw new \UnexpectedValueException("Trying to access an uninitialized value"); - } - - /** - * Sets the value of the element. - * @param TValue $value The new value of the element. - */ - public function setValue(mixed $value): void { - $this->validateValue($value); - $this->value = $value; - } - -} \ No newline at end of file diff --git a/src/imperazim/vendor/libform/elements/Image.php b/src/imperazim/vendor/libform/elements/Image.php deleted file mode 100644 index cc7a97b..0000000 --- a/src/imperazim/vendor/libform/elements/Image.php +++ /dev/null @@ -1,74 +0,0 @@ - new self(explode('|', $data)[1], $type), - 'path' => new self(explode('|', $data)[1], $type), - 'null' => null, - default => null - }; - } - - /** - * Returns a null value indicating no image. - * @return null Returns null to indicate no image. - */ - public static function null(): null { - return null; - } - - /** - * Serializes the image data to an array for JSON encoding. - * @return array The serialized data of the image. - */ - public function jsonSerialize(): array { - return [ - "type" => $this->type, - "data" => $this->data, - ]; - } -} \ No newline at end of file diff --git a/src/imperazim/vendor/libform/elements/Input.php b/src/imperazim/vendor/libform/elements/Input.php deleted file mode 100644 index d304272..0000000 --- a/src/imperazim/vendor/libform/elements/Input.php +++ /dev/null @@ -1,61 +0,0 @@ -setIdentifier($identifier); - } - - /** - * Gets the type of the element. - * @return string The type of the element. - */ - protected function getType(): string { - return "input"; - } - - /** - * Validates the value for the input element. - * @param mixed $value The value to validate. - * @throws FormValidationException if the value is not a string. - */ - protected function validateValue(mixed $value): void { - if (!is_string($value)) { - throw new FormValidationException("Expected string, got " . gettype($value)); - } - } - - /** - * Serializes specific element data to an array. - * @return array The serialized specific element data. - */ - protected function serializeElementData(): array { - return [ - "placeholder" => $this->placeholder, - "default" => $this->default, - ]; - } -} \ No newline at end of file diff --git a/src/imperazim/vendor/libform/elements/Label.php b/src/imperazim/vendor/libform/elements/Label.php deleted file mode 100644 index 779a9a9..0000000 --- a/src/imperazim/vendor/libform/elements/Label.php +++ /dev/null @@ -1,51 +0,0 @@ - The serialized specific element data. - */ - protected function serializeElementData(): array { - return []; - } -} \ No newline at end of file diff --git a/src/imperazim/vendor/libform/elements/ModalButton.php b/src/imperazim/vendor/libform/elements/ModalButton.php deleted file mode 100644 index b177086..0000000 --- a/src/imperazim/vendor/libform/elements/ModalButton.php +++ /dev/null @@ -1,73 +0,0 @@ -text = $text; - return $this; - } - - /** - * Gets the text of the button. - * @return string The text of the button. - */ - public function getText(): string { - return $this->text; - } - - /** - * Defines the response function of the button. - * @param ModalButtonResponse $onclick The new response function for the button. - * @return self Returns the current instance for method chaining. - */ - public function setResponse(ModalButtonResponse $onclick): self { - $this->onclick = $onclick; - return $this; - } - - /** - * Gets the response function of the button. - * @return ModalButtonResponse|null The response function of the button. - */ - public function getResponse(): ?ModalButtonResponse { - return $this->onclick; - } - - /** - * Serializes the button to an array for JSON encoding. - * @return array The serialized data of the button. - */ - public function jsonSerialize(): array { - $data = [ - "text" => $this->getText() - ]; - return $data; - } -} \ No newline at end of file diff --git a/src/imperazim/vendor/libform/elements/Selector.php b/src/imperazim/vendor/libform/elements/Selector.php deleted file mode 100644 index 1159989..0000000 --- a/src/imperazim/vendor/libform/elements/Selector.php +++ /dev/null @@ -1,62 +0,0 @@ - $options The list of options for the selector. - * @param int $default The default selected index. - * @param string|null $identifier The elemment identifier. - */ - public function __construct( - public string $text, - public array $options, - public int $default = 0, - public ?string $identifier = null - ) { - parent::__construct($text, $default); - $this->setIdentifier($identifier); - } - - /** - * Gets the index of the selected option. - * @return int The index of the selected option. - */ - public function getSelectedIndex(): int { - return $this->getValue(); - } - - /** - * Gets the selected option text. - * @return string The text of the selected option. - */ - public function getSelectedOption(): string { - return $this->options[$this->getValue()]; - } - - /** - * Validates the value for the selector. - * @param mixed $value The value to validate. - * @throws FormValidationException if the value is not an integer or does not exist in options. - */ - protected function validateValue(mixed $value): void { - if (!is_int($value)) { - throw new FormValidationException("Expected int, got " . gettype($value)); - } - if (!isset($this->options[$value])) { - throw new FormValidationException("Option $value does not exist"); - } - } - -} \ No newline at end of file diff --git a/src/imperazim/vendor/libform/elements/Slider.php b/src/imperazim/vendor/libform/elements/Slider.php deleted file mode 100644 index a4928ce..0000000 --- a/src/imperazim/vendor/libform/elements/Slider.php +++ /dev/null @@ -1,84 +0,0 @@ -setIdentifier($identifier); - if ($min > $max) { - throw new \InvalidArgumentException("Slider min value should be less than max value"); - } - if ($default === null) { - $this->default = $min; - } else { - if ($default > $max || $default < $min) { - throw new \InvalidArgumentException("Default must be in range $min ... $max"); - } - } - if ($step <= 0) { - throw new \InvalidArgumentException("Step must be greater than zero"); - } - } - - /** - * Gets the type of the element. - * @return string The type of the element. - */ - protected function getType(): string { - return "slider"; - } - - /** - * Validates the value for the slider element. - * @param mixed $value The value to validate. - * @throws FormValidationException if the value is not a float or an int, or if it's out of bounds. - */ - protected function validateValue(mixed $value): void { - if (!is_float($value) && !is_int($value)) { - throw new FormValidationException("Expected float or int, got " . gettype($value)); - } - if ($value < $this->min || $value > $this->max) { - throw new FormValidationException("Value $value is out of bounds (min $this->min, max $this->max)"); - } - } - - /** - * Serializes specific element data to an array. - * @return array The serialized specific element data. - */ - protected function serializeElementData(): array { - return [ - "min" => $this->min, - "max" => $this->max, - "step" => $this->step, - "default" => $this->default, - ]; - } -} \ No newline at end of file diff --git a/src/imperazim/vendor/libform/elements/StepSlider.php b/src/imperazim/vendor/libform/elements/StepSlider.php deleted file mode 100644 index f10587f..0000000 --- a/src/imperazim/vendor/libform/elements/StepSlider.php +++ /dev/null @@ -1,33 +0,0 @@ - The serialized specific element data. - */ - protected function serializeElementData(): array { - return [ - "steps" => $this->options, - "default" => $this->default - ]; - } -} \ No newline at end of file diff --git a/src/imperazim/vendor/libform/elements/Title.php b/src/imperazim/vendor/libform/elements/Title.php deleted file mode 100644 index 2d7f6b2..0000000 --- a/src/imperazim/vendor/libform/elements/Title.php +++ /dev/null @@ -1,50 +0,0 @@ -text = $text; - return $this; - } - - /** - * Gets the text of the title. - * @return string The text of the title. - */ - public function getText(): string { - return is_array($this->text) ? implode("§r\n", $this->text) : $this->text; - } - - /** - * Serializes the title to an array for JSON encoding. - * @return array The serialized data of the title. - */ - public function jsonSerialize(): array { - $data = [ - "text" => $this->getText() - ]; - return $data; - } -} \ No newline at end of file diff --git a/src/imperazim/vendor/libform/elements/Toggle.php b/src/imperazim/vendor/libform/elements/Toggle.php deleted file mode 100644 index 23e5869..0000000 --- a/src/imperazim/vendor/libform/elements/Toggle.php +++ /dev/null @@ -1,66 +0,0 @@ -setIdentifier($identifier); - } - - /** - * Checks if the value has changed from the default. - * @return bool True if the value has changed, false otherwise. - */ - public function hasChanged(): bool { - return $this->default !== $this->getValue(); - } - - /** - * Gets the type of the element. - * @return string The type of the element. - */ - protected function getType(): string { - return 'toggle'; - } - - /** - * Validates the value for the toggle element. - * @param mixed $value The value to validate. - * @throws FormValidationException if the value is not a boolean. - */ - protected function validateValue(mixed $value): void { - if (!is_bool($value)) { - throw new FormValidationException('Expected bool, got ' . gettype($value)); - } - } - - /** - * Serializes specific element data to an array. - * @return array The serialized specific element data. - */ - protected function serializeElementData(): array { - return [ - 'default' => $this->default, - ]; - } -} \ No newline at end of file diff --git a/src/imperazim/vendor/libform/interaction/ButtonResponse.php b/src/imperazim/vendor/libform/interaction/ButtonResponse.php deleted file mode 100644 index e7773d6..0000000 --- a/src/imperazim/vendor/libform/interaction/ButtonResponse.php +++ /dev/null @@ -1,32 +0,0 @@ -callback)($player, $button); - } - -} \ No newline at end of file diff --git a/src/imperazim/vendor/libform/interaction/CustomElementsResponse.php b/src/imperazim/vendor/libform/interaction/CustomElementsResponse.php deleted file mode 100644 index ff91764..0000000 --- a/src/imperazim/vendor/libform/interaction/CustomElementsResponse.php +++ /dev/null @@ -1,79 +0,0 @@ - $element->getValue(), $this->getNonLabelElements()); - } - - /** - * Get all elements - * @return Element[] - */ - public function getElements(): array { - return $this->getNonLabelElements(); - } - - /** - * Get specific element by your identifier - * @param string $id - * @return Element|null - */ - public function getElement(string $id): ?Element { - foreach ($this->elements as $element) { - if ($element->getIdentifier() === $id) { - return $element; - } - } - return null; - } - - /** - * Get result from elements by identifier, excluding labels. - * @param int|null $index - * @return mixed - */ - public function getElementResult(?int $index = null): mixed { - $values = array_map(fn(Element $element) => $element, $this->getNonLabelElements()); - if ($index == null) { - return $values; - } - return $values[$index] ?? null; - } - - /** - * Get all non-label elements from the response. - * @return Element[] - */ - private function getNonLabelElements(): array { - return array_filter($this->elements, fn(Element $element) => !$element instanceof Label); - } -} \ No newline at end of file diff --git a/src/imperazim/vendor/libform/interaction/ModalButtonResponse.php b/src/imperazim/vendor/libform/interaction/ModalButtonResponse.php deleted file mode 100644 index 7884c41..0000000 --- a/src/imperazim/vendor/libform/interaction/ModalButtonResponse.php +++ /dev/null @@ -1,31 +0,0 @@ -callback)($player); - } - -} \ No newline at end of file diff --git a/src/imperazim/vendor/libform/traits/IdentifiableElement.php b/src/imperazim/vendor/libform/traits/IdentifiableElement.php deleted file mode 100644 index 5f80dcb..0000000 --- a/src/imperazim/vendor/libform/traits/IdentifiableElement.php +++ /dev/null @@ -1,32 +0,0 @@ -identifier; - } - - /** - * Sets the identifier of the element. - * @param mixed $identifier The new identifier of the element. - */ - public function setIdentifier(mixed $identifier): void { - $this->identifier = $identifier; - } - -} \ No newline at end of file diff --git a/src/imperazim/vendor/libform/types/CustomForm.php b/src/imperazim/vendor/libform/types/CustomForm.php deleted file mode 100644 index be36d70..0000000 --- a/src/imperazim/vendor/libform/types/CustomForm.php +++ /dev/null @@ -1,199 +0,0 @@ -onSubmit = $closure; - } - - /** - * Set the callback to be executed when the form is closed. - * @param Closure(Player): void $closure - */ - public function onClose(Closure $closure): void { - $this->onClose = $closure; - } - - /** - * Add a dropdown element to the form. - * @param string $text - * @param string[] $options - * @param int $default - */ - public function addDropdown(string $text, array $options, int $default = 0): void { - $this->appendElements(new Dropdown($text, $options, $default)); - } - - /** - * Append multiple elements to the form. - * @param Element ...$elements @phpstan-param Element&ElementWithValue ...$elements - */ - public function appendElements(Element ...$elements): void { - foreach ($elements as $element) { - $this->elements[] = $element; - } - } - - /** - * Add an input element to the form. - * @param string $text - * @param string $placeholder - * @param string $value - */ - public function addInput(string $text, string $placeholder = '', string $value = ''): void { - $this->appendElements(new Input($text, $placeholder, $value)); - } - - /** - * Add a slider element to the form. - * @param string $text - * @param int $min - * @param int $max - * @param int $step - * @param int $default - */ - public function addSlider(string $text, int $min, int $max, int $step = -1, int $default = -1): void { - $this->appendElements(new Slider($text, $min, $max, $step, $default)); - } - - /** - * Add a step slider element to the form. - * @param string $text - * @param string[] $steps - * @param int $index - */ - public function addStepSlider(string $text, array $steps, int $index = -1): void { - $this->appendElements(new StepSlider($text, $steps, $index)); - } - - /** - * Add a toggle element to the form. - * @param string $text - * @param bool $default - */ - public function addToggle(string $text, bool $default = false): void { - $this->appendElements(new Toggle($text, $default)); - } - - /** - * Add a label element to the form. - * - * @param string $text - */ - public function addLabel(string $text): void { - $this->appendElements(new Label($text)); - } - - /** - * Handle the response from the form. - * @param Player $player - * @param mixed $data - * @throws FormValidationException - */ - final public function handleResponse(Player $player, mixed $data): void { - if (is_null($data)) { - if ($this->onClose !== null) { - ($this->onClose)($player); - } - } elseif (is_array($data)) { - $this->validateElements($player, $data); - } else { - throw new FormValidationException('Expected array or null, got ' . gettype($data)); - } - } - - /** - * Validate the elements in the form. - * @param Player $player - * @param array $data - * @throws FormValidationException - */ - private function validateElements(Player $player, array $data): void { - if (($actual = count($data)) !== ($expected = count($this->elements))) { - throw new FormValidationException('Expected ' . $expected . ' result data, got ' . $actual); - } - - foreach ($data as $index => $value) { - $element = $this->elements[$index] ?? throw new FormValidationException("Element at offset $index does not exist"); - try { - $element->setValue($value); - } catch (FormValidationException $e) { - throw new FormValidationException('Validation failed for element ' . $element::class . ': ' . $e->getMessage(), 0, $e); - } - } - - if ($this->onSubmit !== null) { - ($this->onSubmit)($player, new CustomElementsResponse($this->elements)); - } - } - - /** - * Get the type of the form. - * @return string - */ - protected function getType(): string { - return 'custom_form'; - } - - /** - * Serialize the form data for transmission. - * @return array - */ - protected function serializeFormData(): array { - return [ - 'content' => $this->elements, - ]; - } - -} \ No newline at end of file diff --git a/src/imperazim/vendor/libform/types/LongForm.php b/src/imperazim/vendor/libform/types/LongForm.php deleted file mode 100644 index 9c32cb6..0000000 --- a/src/imperazim/vendor/libform/types/LongForm.php +++ /dev/null @@ -1,141 +0,0 @@ -onClose = $closure; - } - - /** - * Get the content of the form. - * @return Content|null - */ - public function getContent(): ?Content { - return $this->content; - } - - /** - * Set the content of the form. - * @param Content $content - * @return self - */ - public function setContent(?Content $content = new Content('')): self { - $this->content = $content; - return $this; - } - - /** - * Get the buttons of the form. - * @return array - */ - public function getButtons(): array { - return $this->buttons; - } - - /** - * Get a button by its index. - * @param int $identifier - * @return Button - * @throws FormValidationException - */ - private function getButton(int $identifier): Button { - if (!isset($this->buttons[$identifier])) { - throw new FormValidationException("Button at index $identifier does not exist."); - } - return $this->buttons[$identifier]; - } - - /** - * Add a button to the form. - * @param string $text - * @param Image|null $image - * @param string|null $identifier - * @return self - */ - public function addButton(string $text, ?Image $image = null, ?string $identifier = null, ?ButtonResponse $response = null): self { - $button = new Button($text, $image, $identifier, $response); - $this->buttons[] = $button; - return $this; - } - - /** - * Handle the response from the form. - * @param Player $player - * @param mixed $data - */ - final public function handleResponse(Player $player, mixed $data): void { - if (is_null($data)) { - if ($this->onClose !== null) { - ($this->onClose)($player); - } - } else { - $button = $this->getButton($data); - $buttonResponse = $button->getResponse(); - if ($buttonResponse !== null) { - $buttonResponse->runAt($player, $button); - } - if ($button->getShouldReopen()) { - $this->sendTo($player); - } - } - } - - /** - * Get the type of the form. - * @return string - */ - protected function getType(): string { - return 'form'; - } - - /** - * Serialize the form data for transmission. - * @return array - */ - protected function serializeFormData(): array { - return [ - 'buttons' => $this->getButtons(), - 'content' => $this->getContent()->getText(), - ]; - } - -} \ No newline at end of file diff --git a/src/imperazim/vendor/libform/types/ModalForm.php b/src/imperazim/vendor/libform/types/ModalForm.php deleted file mode 100644 index d438460..0000000 --- a/src/imperazim/vendor/libform/types/ModalForm.php +++ /dev/null @@ -1,138 +0,0 @@ -content; - } - - /** - * Set the content of the form. - * @param Content|null $content - * @return self - */ - public function setContent(?Content $content = new Content('')): self { - $this->content = $content; - return $this; - } - - /** - * Get the button Yes. - * @return ModalButton - */ - public function getButtonYes(): ModalButton { - return $this->buttonYes; - } - - /** - * Set the button Yes. - * @param ModalButton $buttonYes - * @return self - */ - public function setButtonYes(?ModalButton $buttonYes = new ModalButton('gui.yes')): self { - $this->buttonYes = $buttonYes; - return $this; - } - - /** - * Get the button No. - * @return ModalButton - */ - public function getButtonNo(): ModalButton { - return $this->buttonNo; - } - - /** - * Set the button No. - * @param ModalButton $buttself - * @return self - */ - public function setButtonNo(?ModalButton $buttonNo = new ModalButton('gui.no')): self { - $this->buttonNo = $buttonNo; - return $this; - } - - /** - * Handle the response from the form. - * @param Player $player - * @param mixed $data - * @throws FormValidationException - */ - final public function handleResponse(Player $player, - mixed $data): void { - if (!is_bool($data)) { - // It is possible to separate the callback from onClose here but it made me lazy. :) - return; - } - if ($data) { - $button = $this->getButtonYes(); - $buttonResponse = $button->getResponse(); - if ($buttonResponse !== null) { - $buttonResponse->runAt($player); - } - } else { - $button = $this->getButtonNo(); - $buttonResponse = $button->getResponse(); - if ($buttonResponse !== null) { - $buttonResponse->runAt($player); - } - } - } - - /** - * Get the type of the form. - * @return - */ - protected function getType(): string { - return 'modal'; - } - - /** - * Serialize the form data for transmission. - * @return array - */ - protected function serializeFormData(): array { - return [ - 'content' => $this->getContent()->getText(), - 'button1' => $this->getButtonYes()->getText(), - 'button2' => $this->getButtonNo()->getText(), - ]; - } - -} \ No newline at end of file From 0e6ad5669e60abd7dbbc1724ac851f3cc4bf4ae9 Mon Sep 17 00:00:00 2001 From: impera Date: Sun, 25 May 2025 01:43:08 -0300 Subject: [PATCH 55/72] Patch files moved into vendor. --- src/LibraryComponents.php | 2 +- src/imperazim/{bugfixes => vendor/fix}/BugFixesListener.php | 4 ++-- src/imperazim/{bugfixes => vendor/fix}/BugFixesManager.php | 4 ++-- 3 files changed, 5 insertions(+), 5 deletions(-) rename src/imperazim/{bugfixes => vendor/fix}/BugFixesListener.php (96%) rename src/imperazim/{bugfixes => vendor/fix}/BugFixesManager.php (90%) diff --git a/src/LibraryComponents.php b/src/LibraryComponents.php index 7eae745..598f5d9 100644 --- a/src/LibraryComponents.php +++ b/src/LibraryComponents.php @@ -2,7 +2,7 @@ declare(strict_types = 1); -use imperazim\bugfixes\BugFixesManager; +use imperazim\vendor\fix\BugFixesManager; use imperazim\components\filesystem\File; use imperazim\components\world\WorldManager; diff --git a/src/imperazim/bugfixes/BugFixesListener.php b/src/imperazim/vendor/fix/BugFixesListener.php similarity index 96% rename from src/imperazim/bugfixes/BugFixesListener.php rename to src/imperazim/vendor/fix/BugFixesListener.php index aabaeb0..579c997 100644 --- a/src/imperazim/bugfixes/BugFixesListener.php +++ b/src/imperazim/vendor/fix/BugFixesListener.php @@ -2,7 +2,7 @@ declare(strict_types = 1); -namespace imperazim\bugfixes; +namespace imperazim\vendor\fix; use pocketmine\math\Facing; use pocketmine\player\Player; @@ -17,7 +17,7 @@ * Specifically, it listens for suffocation events and tries to prevent the player * from taking damage by checking if there is space for the player to move. * -* @package imperazim\bugfixes +* @package imperazim\vendor\fix */ final class BugFixesListener implements Listener { diff --git a/src/imperazim/bugfixes/BugFixesManager.php b/src/imperazim/vendor/fix/BugFixesManager.php similarity index 90% rename from src/imperazim/bugfixes/BugFixesManager.php rename to src/imperazim/vendor/fix/BugFixesManager.php index f9d7803..2715cda 100644 --- a/src/imperazim/bugfixes/BugFixesManager.php +++ b/src/imperazim/vendor/fix/BugFixesManager.php @@ -2,7 +2,7 @@ declare(strict_types = 1); -namespace imperazim\bugfixes; +namespace imperazim\vendor\fix; use imperazim\components\plugin\PluginToolkit; use imperazim\components\plugin\PluginComponent; @@ -10,7 +10,7 @@ /** * Class BugFixesManager -* @package imperazim\bugfixes +* @package imperazim\vendor\fix */ final class BugFixesManager extends PluginComponent { use PluginComponentsTrait; From 91c0d98cadfcf895c3c50b5808f00509a2264a38 Mon Sep 17 00:00:00 2001 From: impera Date: Tue, 3 Jun 2025 14:04:37 -0300 Subject: [PATCH 56/72] LibForm has been removed from the source to a single repository. --- src/imperazim/components/ui/Form.php | 30 ---------------------------- 1 file changed, 30 deletions(-) delete mode 100644 src/imperazim/components/ui/Form.php diff --git a/src/imperazim/components/ui/Form.php b/src/imperazim/components/ui/Form.php deleted file mode 100644 index a1c1160..0000000 --- a/src/imperazim/components/ui/Form.php +++ /dev/null @@ -1,30 +0,0 @@ - Date: Tue, 3 Jun 2025 16:05:52 -0300 Subject: [PATCH 57/72] Squashed 'src/imperazim/form/' content from commit f42701b git-subtree-dir: src/imperazim/form git-subtree-split: f42701b06ea02ce60f0a0380493f8d1e0d08fab6 --- Form.php | 80 +++++++++ FormData.php | 109 +++++++++++++ FormResult.php | 16 ++ LibForm.php | 12 ++ base/elements/Content.php | 17 ++ base/elements/TextElement.php | 35 ++++ base/elements/Title.php | 17 ++ custom/CustomForm.php | 189 ++++++++++++++++++++++ custom/DynamicCustomForm.php | 153 ++++++++++++++++++ custom/elements/Dropdown.php | 120 ++++++++++++++ custom/elements/Element.php | 56 +++++++ custom/elements/ElementCollection.php | 106 ++++++++++++ custom/elements/Input.php | 39 +++++ custom/elements/Label.php | 40 +++++ custom/elements/Option.php | 37 +++++ custom/elements/Slider.php | 45 ++++++ custom/elements/StepSlider.php | 120 ++++++++++++++ custom/elements/Toggle.php | 36 +++++ custom/response/CustomResponse.php | 223 ++++++++++++++++++++++++++ custom/response/SelectedOption.php | 48 ++++++ long/DynamicLongForm.php | 219 +++++++++++++++++++++++++ long/LongForm.php | 124 ++++++++++++++ long/elements/Button.php | 64 ++++++++ long/elements/ButtonCollection.php | 107 ++++++++++++ long/elements/ButtonTexture.php | 63 ++++++++ long/response/ButtonResponse.php | 28 ++++ modal/DynamicModalForm.php | 161 +++++++++++++++++++ modal/ModalForm.php | 156 ++++++++++++++++++ modal/elements/ModalButton.php | 59 +++++++ modal/response/ModalResponse.php | 54 +++++++ modal/result/ModalResult.php | 16 ++ 31 files changed, 2549 insertions(+) create mode 100644 Form.php create mode 100644 FormData.php create mode 100644 FormResult.php create mode 100644 LibForm.php create mode 100644 base/elements/Content.php create mode 100644 base/elements/TextElement.php create mode 100644 base/elements/Title.php create mode 100644 custom/CustomForm.php create mode 100644 custom/DynamicCustomForm.php create mode 100644 custom/elements/Dropdown.php create mode 100644 custom/elements/Element.php create mode 100644 custom/elements/ElementCollection.php create mode 100644 custom/elements/Input.php create mode 100644 custom/elements/Label.php create mode 100644 custom/elements/Option.php create mode 100644 custom/elements/Slider.php create mode 100644 custom/elements/StepSlider.php create mode 100644 custom/elements/Toggle.php create mode 100644 custom/response/CustomResponse.php create mode 100644 custom/response/SelectedOption.php create mode 100644 long/DynamicLongForm.php create mode 100644 long/LongForm.php create mode 100644 long/elements/Button.php create mode 100644 long/elements/ButtonCollection.php create mode 100644 long/elements/ButtonTexture.php create mode 100644 long/response/ButtonResponse.php create mode 100644 modal/DynamicModalForm.php create mode 100644 modal/ModalForm.php create mode 100644 modal/elements/ModalButton.php create mode 100644 modal/response/ModalResponse.php create mode 100644 modal/result/ModalResult.php diff --git a/Form.php b/Form.php new file mode 100644 index 0000000..7a9bc0b --- /dev/null +++ b/Form.php @@ -0,0 +1,80 @@ +title = $title; + } + + /** + * Gets form title. + * + * @return Title Title element + */ + public function getTitle(): Title { + return $this->title; + } + + /** + * Sets form title. + * + * @param Title $title New title + */ + public function setTitle(Title $title): void { + $this->title = $title; + } + + /** + * Sends form to player. + * + * @param Player $player Target player + */ + public function sendTo(Player $player): void { + $player->sendForm($this); + } + + /** + * Serializes form for JSON. + * + * @return array Serialized data + */ + final public function jsonSerialize(): array { + return [ + 'type' => $this->getFormType(), + 'title' => $this->title->getText(), + ...$this->serializeFormData() + ]; + } + + /** + * Serializes form-specific data. + * + * @return array Form data + */ + abstract protected function serializeFormData(): array; + + /** + * Gets form type identifier. + * + * @return string Form type + */ + abstract protected function getFormType(): string; +} \ No newline at end of file diff --git a/FormData.php b/FormData.php new file mode 100644 index 0000000..fea7ace --- /dev/null +++ b/FormData.php @@ -0,0 +1,109 @@ + +* @implements IteratorAggregate +*/ +final class FormData implements ArrayAccess, IteratorAggregate, Countable { + /** @var array Data storage */ + private array $data; + + /** + * @param array $data Initial data + */ + public function __construct(array $data = []) { + $this->data = $data; + } + + /** + * Checks if offset exists. + * + * @param mixed $offset Offset to check + * @return bool Existence status + */ + public function offsetExists(mixed $offset): bool { + return isset($this->data[$offset]); + } + + /** + * Gets value by offset. + * + * @param mixed $offset Data key + * @return mixed Value or null + */ + public function offsetGet(mixed $offset): mixed { + return $this->data[$offset] ?? null; + } + + /** + * Sets value by offset. + * + * @param mixed $offset Data key + * @param mixed $value Value to set + */ + public function offsetSet(mixed $offset, mixed $value): void { + if ($offset === null) { + $this->data[] = $value; + } else { + $this->data[$offset] = $value; + } + } + + /** + * Unsets value by offset. + * + * @param mixed $offset Data key + */ + public function offsetUnset(mixed $offset): void { + unset($this->data[$offset]); + } + + /** + * Gets data iterator. + * + * @return Traversable Data iterator + */ + public function getIterator(): Traversable { + return new ArrayIterator($this->data); + } + + /** + * Counts data items. + * + * @return int Item count + */ + public function count(): int { + return count($this->data); + } + + /** + * Gets value by key. + * + * @param string|int $key Data key + * @return mixed Value or null + */ + public function get(string|int $key): mixed { + return $this->offsetGet($key); + } + + /** + * Converts data to array. + * + * @return array Data array + */ + public function toArray(): array { + return $this->data; + } +} \ No newline at end of file diff --git a/FormResult.php b/FormResult.php new file mode 100644 index 0000000..9736ea7 --- /dev/null +++ b/FormResult.php @@ -0,0 +1,16 @@ +text; + } + + /** + * Serializes the element to a string. + * + * @return string Serialized text + */ + public function jsonSerialize(): string { + return $this->text; + } +} \ No newline at end of file diff --git a/base/elements/Title.php b/base/elements/Title.php new file mode 100644 index 0000000..8f1fa6f --- /dev/null +++ b/base/elements/Title.php @@ -0,0 +1,17 @@ +player = $player; + $this->force = $force; + $this->formData = $data instanceof FormData ? $data : new FormData($data); + + parent::__construct($this->title($player, $this->formData)); + + if ($force) { + $this->sendTo($player); + } + } + + /** + * Gets form title. + * + * @param Player $player Viewing player + * @param FormData $data Form data + * @return Title Title element + */ + abstract protected function title(Player $player, FormData $data): Title; + + /** + * Gets form elements. + * + * @param Player $player Viewing player + * @param FormData $data Form data + * @return ElementCollection Elements collection + */ + abstract protected function elements(Player $player, FormData $data): ElementCollection; + + /** + * Handles form submission. + * + * @param Player $player Submitting player + * @param CustomResponse $response Form response + * @return FormResult Action result + */ + abstract protected function onSubmit( + Player $player, + CustomResponse $response + ): FormResult; + + /** + * Handles form closure. + * + * @param Player $player Closing player + * @param FormData $data Form data + * @return FormResult Action result + */ + abstract protected function onClose( + Player $player, + FormData $data + ): FormResult; + + /** + * Handles form response. + * + * @param Player $player Responding player + * @param mixed $raw Raw response data + */ + public function handleResponse(Player $player, $raw): void { + if ($raw !== null && !is_array($raw)) { + throw new InvalidArgumentException("Response data must be array or null."); + } + + $elements = $this->getCachedElements($player, $this->formData); + $idMap = []; + $elementMap = []; + + if (is_array($raw)) { + foreach ($elements as $idx => $element) { + $elementMap[$element->getId()] = $element; + + if ($element->hasValue() && array_key_exists($idx, $raw)) { + $idMap[$element->getId()] = $raw[$idx]; + } + } + } + + if ($raw === null) { + $result = $this->onClose($player, $this->formData); + } else { + $response = new CustomResponse( + $this->formData, + $raw, + $idMap, + $elementMap + ); + + if (!$this->force && count($response->getElementsRaw()) !== count($elements)) { + throw new InvalidArgumentException("Invalid number of fields."); + } + + $result = $this->onSubmit($player, $response); + } + + if ($result === FormResult::KEEP) { + $this->sendTo($player); + } + } + + /** + * Serializes form data. + * + * @return array Serialized data + */ + protected function serializeFormData(): array { + $elements = $this->getCachedElements($this->player, $this->formData); + return [ + 'content' => array_map( + fn(JsonSerializable $e) => $e->jsonSerialize(), + $elements + ) + ]; + } + + /** + * Gets form type. + * + * @return string Form type identifier + */ + protected function getFormType(): string { + return 'custom_form'; + } + + /** + * Gets and validates cached elements. + * + * @param Player $player Viewing player + * @param FormData $data Form data + * @return array Validated elements + * @throws InvalidArgumentException If elements lack IDs + */ + private function getCachedElements(Player $player, FormData $data): array { + if ($this->elementsCache === null) { + $this->elementsCache = $this->elements($player, $data); + + foreach ($this->elementsCache as $element) { + if (!$element->hasId()) { + throw new InvalidArgumentException("All elements must have an ID."); + } + } + } + return iterator_to_array($this->elementsCache); + } +} \ No newline at end of file diff --git a/custom/DynamicCustomForm.php b/custom/DynamicCustomForm.php new file mode 100644 index 0000000..a669a1f --- /dev/null +++ b/custom/DynamicCustomForm.php @@ -0,0 +1,153 @@ +elements = new ElementCollection(); + $this->onSubmit = fn(Player $p, CustomResponse $r): FormResult => FormResult::CLOSE; + $this->onClose = fn(Player $p): FormResult => FormResult::CLOSE; + } + + /** + * Creates a new form instance. + * + * @param string|Title $title Form title + * @return self New instance + */ + final public static function create(string|Title $title): self { + return new self($title instanceof Title ? $title : new Title($title)); + } + + /** + * Builds a form using configuration closure. + * + * @param string|Title $title Form title + * @param Closure $configurator Configuration callback + * @return self Configured instance + */ + final public static function build(string|Title $title, Closure $configurator): self { + $form = self::create($title); + $configurator($form); + return $form; + } + + /** + * Adds an element to the form. + * + * @param Element $element Form element + * @return self + */ + public function addElement(Element $element): self { + $this->elements->add($element); + return $this; + } + + /** + * Sets submission handler. + * + * @param Closure $handler Submission handler + * @return self + */ + public function setOnSubmit(Closure $handler): self { + $this->onSubmit = $handler; + return $this; + } + + /** + * Sets close handler. + * + * @param Closure $handler Close handler + * @return self + */ + public function setOnClose(Closure $handler): self { + $this->onClose = $handler; + return $this; + } + + /** + * Serializes form data. + * + * @return array Serialized data + */ + protected function serializeFormData(): array { + return [ + 'content' => array_map( + fn(JsonSerializable $e) => $e->jsonSerialize(), + iterator_to_array($this->elements) + ) + ]; + } + + /** + * Gets form type. + * + * @return string Form type identifier + */ + protected function getFormType(): string { + return 'custom_form'; + } + + /** + * Handles form response. + * + * @param Player $player Responding player + * @param mixed $raw Raw response data + */ + public function handleResponse(Player $player, $raw): void { + if ($raw === null) { + $result = ($this->onClose)($player); + } elseif (is_array($raw)) { + $idMap = []; + $elementMap = []; + + foreach ($this->elements as $idx => $element) { + $elementMap[$element->getId()] = $element; + + if ($element->hasValue() && array_key_exists($idx, $raw)) { + $idMap[$element->getId()] = $raw[$idx]; + } + } + + $response = new CustomResponse(new FormData([]), $raw, $idMap, $elementMap); + $result = ($this->onSubmit)($player, $response); + } else { + throw new InvalidArgumentException("Invalid response data type"); + } + + if ($result === FormResult::KEEP) { + $this->sendTo($player); + } + } +} \ No newline at end of file diff --git a/custom/elements/Dropdown.php b/custom/elements/Dropdown.php new file mode 100644 index 0000000..0ed7505 --- /dev/null +++ b/custom/elements/Dropdown.php @@ -0,0 +1,120 @@ +options = $this->normalizeOptions($options); + $this->defaultIndex = $this->findOptionIndex($default); + } + + /** + * Normalizes options array. + * + * @param array $options Raw options + * @return Option[] Normalized options + */ + private function normalizeOptions(array $options): array { + $normalized = []; + foreach ($options as $key => $value) { + if ($value instanceof Option) { + $normalized[] = $value; + } elseif (is_array($value)) { + $normalized[] = new Option( + (string)($value['id'] ?? $key), + (string)($value['text'] ?? '') + ); + } else { + $normalized[] = new Option((string)$key, (string)$value); + } + } + return $normalized; + } + + /** + * Finds option index by ID or value. + * + * @param string|int $default Default identifier + * @return int Option index + */ + private function findOptionIndex(string|int $default): int { + if (is_int($default)) { + return $default; + } + + foreach ($this->options as $index => $option) { + if ($option->getId() === $default) { + return $index; + } + } + return 0; + } + + /** + * Serializes element for JSON. + * + * @return array Serialized data + */ + public function jsonSerialize(): array { + return [ + 'type' => 'dropdown', + 'text' => $this->text, + 'options' => array_map(fn(Option $o) => $o->getText(), $this->options), + 'default' => $this->defaultIndex + ]; + } + + /** + * Gets option by index. + * + * @param int $index Option position + * @return Option|null Option or null + */ + public function getOptionByIndex(int $index): ?Option { + return $this->options[$index] ?? null; + } + + /** + * Gets selected option. + * + * @param int $index Selected index + * @return SelectedOption|null Selected option or null + */ + public function getSelectedOption(int $index): ?SelectedOption { + $option = $this->getOptionByIndex($index); + if ($option === null) { + return null; + } + + return new SelectedOption( + $index, + $option->getId(), + $option->getText() + ); + } +} \ No newline at end of file diff --git a/custom/elements/Element.php b/custom/elements/Element.php new file mode 100644 index 0000000..9fca74e --- /dev/null +++ b/custom/elements/Element.php @@ -0,0 +1,56 @@ +id === null) { + throw new InvalidArgumentException("Element has no ID."); + } + return $this->id; + } + + /** + * Checks if element has an ID. + * + * @return bool True if has ID + */ + public function hasId(): bool { + return $this->id !== null; + } + + /** + * Checks if element holds a value. + * + * @return bool True if element has value + */ + public function hasValue(): bool { + return true; + } + + /** + * Serializes element for JSON. + * + * @return array Serialized data + */ + abstract public function jsonSerialize(): array; +} \ No newline at end of file diff --git a/custom/elements/ElementCollection.php b/custom/elements/ElementCollection.php new file mode 100644 index 0000000..3937124 --- /dev/null +++ b/custom/elements/ElementCollection.php @@ -0,0 +1,106 @@ +elements[] = $element; + } + + /** + * Creates collection from array. + * + * @param Element[] $elements Elements array + * @return self New collection + */ + public static function fromArray(array $elements): self { + $collection = new self(); + $collection->elements = $elements; + return $collection; + } + + /** + * Gets element by index. + * + * @param int $index Element position + * @return Element|null Element or null + */ + public function getByIndex(int $index): ?Element { + return $this->elements[$index] ?? null; + } + + /** + * Counts elements in collection. + * + * @return int Element count + */ + public function count(): int { + return count($this->elements); + } + + /** + * Gets iterator for elements. + * + * @return Traversable Element iterator + */ + public function getIterator(): Traversable { + yield from $this->elements; + } + + /** + * Checks if offset exists. + * + * @param mixed $offset Offset to check + * @return bool Existence status + */ + public function offsetExists(mixed $offset): bool { + return isset($this->elements[$offset]); + } + + /** + * Gets element by offset. + * + * @param mixed $offset Element position + * @return Element|null Element or null + */ + public function offsetGet(mixed $offset): ?Element { + return $this->elements[$offset] ?? null; + } + + /** + * Disabled setter (immutable). + * + * @throws RuntimeException Always + */ + public function offsetSet(mixed $offset, mixed $value): void { + throw new RuntimeException('ElementCollection is immutable'); + } + + /** + * Disabled unsetter (immutable). + * + * @throws RuntimeException Always + */ + public function offsetUnset(mixed $offset): void { + throw new RuntimeException('ElementCollection is immutable'); + } +} \ No newline at end of file diff --git a/custom/elements/Input.php b/custom/elements/Input.php new file mode 100644 index 0000000..d6f15bf --- /dev/null +++ b/custom/elements/Input.php @@ -0,0 +1,39 @@ + 'input', + 'text' => $this->text, + 'placeholder' => $this->placeholder, + 'default' => $this->default + ]; + } + } \ No newline at end of file diff --git a/custom/elements/Label.php b/custom/elements/Label.php new file mode 100644 index 0000000..4407a47 --- /dev/null +++ b/custom/elements/Label.php @@ -0,0 +1,40 @@ +toString()); + } + + /** + * Checks if element holds a value. + * + * @return bool Always false for labels + */ + public function hasValue(): bool { + return false; + } + + /** + * Serializes element for JSON. + * + * @return array Serialized data + */ + public function jsonSerialize(): array { + return [ + 'type' => 'label', + 'text' => $this->text + ]; + } +} \ No newline at end of file diff --git a/custom/elements/Option.php b/custom/elements/Option.php new file mode 100644 index 0000000..c7a25fd --- /dev/null +++ b/custom/elements/Option.php @@ -0,0 +1,37 @@ +id; + } + + /** + * Gets display text. + * + * @return string Display text + */ + public function getText(): string { + return $this->text; + } +} \ No newline at end of file diff --git a/custom/elements/Slider.php b/custom/elements/Slider.php new file mode 100644 index 0000000..3b63681 --- /dev/null +++ b/custom/elements/Slider.php @@ -0,0 +1,45 @@ + 'slider', + 'text' => $this->text, + 'min' => $this->min, + 'max' => $this->max, + 'step' => $this->step, + 'default' => $this->default + ]; + } + } \ No newline at end of file diff --git a/custom/elements/StepSlider.php b/custom/elements/StepSlider.php new file mode 100644 index 0000000..aa0c1fb --- /dev/null +++ b/custom/elements/StepSlider.php @@ -0,0 +1,120 @@ +steps = $this->normalizeSteps($steps); + $this->defaultIndex = $this->findStepIndex($default); + } + + /** + * Normalizes steps array. + * + * @param array $steps Raw steps + * @return Option[] Normalized steps + */ + private function normalizeSteps(array $steps): array { + $normalized = []; + foreach ($steps as $key => $value) { + if ($value instanceof Option) { + $normalized[] = $value; + } elseif (is_array($value)) { + $normalized[] = new Option( + (string)($value['id'] ?? $key), + (string)($value['text'] ?? '') + ); + } else { + $normalized[] = new Option((string)$key, (string)$value); + } + } + return $normalized; + } + + /** + * Finds step index by ID or value. + * + * @param string|int $default Default identifier + * @return int Step index + */ + private function findStepIndex(string|int $default): int { + if (is_int($default)) { + return $default; + } + + foreach ($this->steps as $index => $step) { + if ($step->getId() === $default) { + return $index; + } + } + return 0; + } + + /** + * Serializes element for JSON. + * + * @return array Serialized data + */ + public function jsonSerialize(): array { + return [ + 'type' => 'step_slider', + 'text' => $this->text, + 'steps' => array_map(fn(Option $s) => $s->getText(), $this->steps), + 'default' => $this->defaultIndex + ]; + } + + /** + * Gets step by index. + * + * @param int $index Step position + * @return Option|null Step or null + */ + public function getStepByIndex(int $index): ?Option { + return $this->steps[$index] ?? null; + } + + /** + * Gets selected step. + * + * @param int $index Selected index + * @return SelectedOption|null Selected step or null + */ + public function getSelectedStep(int $index): ?SelectedOption { + $step = $this->getStepByIndex($index); + if ($step === null) { + return null; + } + + return new SelectedOption( + $index, + $step->getId(), + $step->getText() + ); + } +} \ No newline at end of file diff --git a/custom/elements/Toggle.php b/custom/elements/Toggle.php new file mode 100644 index 0000000..88ed47d --- /dev/null +++ b/custom/elements/Toggle.php @@ -0,0 +1,36 @@ + 'toggle', + 'text' => $this->text, + 'default' => $this->default + ]; + } + } \ No newline at end of file diff --git a/custom/response/CustomResponse.php b/custom/response/CustomResponse.php new file mode 100644 index 0000000..99c9aaf --- /dev/null +++ b/custom/response/CustomResponse.php @@ -0,0 +1,223 @@ + $raw Raw response data + * @param array $idMap ID-value mapping + * @param array $elementMap Element mapping + */ + public function __construct( + private FormData $data, + private array $raw, + private array $idMap = [], + private array $elementMap = [] + ) { + if (empty($raw)) { + throw new InvalidArgumentException("Raw data must be array"); + } + } + + /** + * Gets form data. + * + * @return FormData Requested data + */ + public function getFormData(): FormData { + return $this->data; + } + + /** + * Gets element value by ID. + * + * @param string $id Element ID + * @return mixed Element value + * @throws InvalidArgumentException If ID not found + */ + public function getElement(string $id): mixed { + if (!array_key_exists($id, $this->idMap)) { + throw new InvalidArgumentException("ID '{$id}' not found."); + } + return $this->idMap[$id]; + } + + /** + * Gets raw response data. + * + * @return array Raw data + */ + public function getElementsRaw(): array { + return $this->raw; + } + + /** + * Gets string value. + * + * @param string $id Element ID + * @param string|null $default Default value + * @return string|null String value or default + */ + public function getString(string $id, ?string $default = null): ?string { + try { + $value = $this->getElement($id); + return $value === null ? $default : (string)$value; + } catch (InvalidArgumentException) { + return $default; + } + } + + /** + * Gets integer value. + * + * @param string $id Element ID + * @param int|null $default Default value + * @return int|null Integer value or default + */ + public function getInt(string $id, ?int $default = null): ?int { + try { + $value = $this->getElement($id); + return $value === null ? $default : (int)$value; + } catch (InvalidArgumentException) { + return $default; + } + } + + /** + * Gets boolean value. + * + * @param string $id Element ID + * @param bool|null $default Default value + * @return bool|null Boolean value or default + */ + public function getBool(string $id, ?bool $default = null): ?bool { + try { + $value = $this->getElement($id); + return $value === null ? $default : (bool)$value; + } catch (InvalidArgumentException) { + return $default; + } + } + + /** + * Gets float value. + * + * @param string $id Element ID + * @param float|null $default Default value + * @return float|null Float value or default + */ + public function getFloat(string $id, ?float $default = null): ?float { + try { + $value = $this->getElement($id); + return $value === null ? $default : (float)$value; + } catch (InvalidArgumentException) { + return $default; + } + } + + /** + * Gets array value. + * + * @param string $id Element ID + * @param array|null $default Default value + * @return array|null Array value or default + */ + public function getArray(string $id, ?array $default = null): ?array { + try { + $value = $this->getElement($id); + return is_array($value) ? $value : $default; + } catch (InvalidArgumentException) { + return $default; + } + } + + /** + * Gets toggle value. + * + * @param string $id Element ID + * @return bool Toggle value + */ + public function getToggle(string $id): bool { + return (bool) $this->getElement($id); + } + + /** + * Gets input value. + * + * @param string $id Element ID + * @return string Input value + */ + public function getInput(string $id): string { + return (string) $this->getElement($id); + } + + /** + * Gets slider value. + * + * @param string $id Element ID + * @return float Slider value + */ + public function getSlider(string $id): float { + return (float) $this->getElement($id); + } + + /** + * Gets dropdown selection. + * + * @param string $id Element ID + * @return SelectedOption Selected option + * @throws InvalidArgumentException If element not dropdown + */ + public function getDropdown(string $id): SelectedOption { + $index = (int) $this->getElement($id); + $element = $this->elementMap[$id] ?? null; + + if (!$element instanceof Dropdown) { + throw new InvalidArgumentException("Element with ID {$id} is not a Dropdown."); + } + + $selected = $element->getSelectedOption($index); + return $selected ?? new SelectedOption($index, (string)$index, 'Unknown'); + } + + /** + * Gets step slider selection. + * + * @param string $id Element ID + * @return SelectedOption Selected step + * @throws InvalidArgumentException If element not step slider + */ + public function getStepSlider(string $id): SelectedOption { + $index = (int) $this->getElement($id); + $element = $this->elementMap[$id] ?? null; + + if (!$element instanceof StepSlider) { + throw new InvalidArgumentException("Element with ID {$id} is not a StepSlider."); + } + + $selected = $element->getSelectedStep($index); + return $selected ?? new SelectedOption($index, (string)$index, 'Unknown'); + } + + /** + * Checks if element exists in response. + * + * @param string $id Element ID + * @return bool True if exists + */ + public function has(string $id): bool { + return array_key_exists($id, $this->idMap); + } +} \ No newline at end of file diff --git a/custom/response/SelectedOption.php b/custom/response/SelectedOption.php new file mode 100644 index 0000000..b87942c --- /dev/null +++ b/custom/response/SelectedOption.php @@ -0,0 +1,48 @@ +index; + } + + /** + * Gets option ID. + * + * @return string Option ID + */ + public function getId(): string { + return $this->id; + } + + /** + * Gets display text. + * + * @return string Display text + */ + public function getText(): string { + return $this->text; + } +} \ No newline at end of file diff --git a/long/DynamicLongForm.php b/long/DynamicLongForm.php new file mode 100644 index 0000000..e165ce8 --- /dev/null +++ b/long/DynamicLongForm.php @@ -0,0 +1,219 @@ +content = new Content(""); + $this->buttons = new ButtonCollection(); + $this->onClose = fn(Player $player) => FormResult::CLOSE; + } + + /** + * Creates a new form instance. + * + * @param string|Title $title Form title + * @return self New form instance + */ + final public static function create(string|Title $title): self { + return new self($title instanceof Title ? $title : new Title($title)); + } + + /** + * Builds a form using a configuration closure. + * + * @param string|Title $title Form title + * @param Closure $configurator Configuration callback + * @return self Configured form instance + */ + final public static function build(string|Title $title, Closure $configurator): self { + $form = self::create($title); + $configurator($form); + return $form; + } + + /** + * Sets form content. + * + * @param string|Content $content Form content + * @return self + */ + public function setContent(string|Content $content): self { + $this->content = $content instanceof Content ? $content : new Content($content); + return $this; + } + + /** + * Gets current content. + * + * @return Content Current content + */ + public function getContent(): Content { + return $this->content; + } + + /** + * Sets button collection. + * + * @param ButtonCollection $buttons Button collection + * @return self + */ + public function setButtons(ButtonCollection $buttons): self { + $this->buttons = $buttons; + return $this; + } + + /** + * Gets button collection. + * + * @return ButtonCollection Current buttons + */ + public function getButtons(): ButtonCollection { + return $this->buttons; + } + + /** + * Adds a button to the form. + * + * @param Button|string $button Button instance or text + * @param ButtonTexture|string|array|null $image Button image + * @param Closure|null $handler Click handler + * @return self + */ + public function addButton( + Button|string $button, + ButtonTexture|string|array|null $image = null, + ?Closure $handler = null + ): self { + if ($button instanceof Button) { + $this->buttons->add($button); + return $this; + } + + $img = $this->processImage($image); + $response = new ButtonResponse($handler ?? fn(Player $p) => FormResult::CLOSE); + $this->buttons->add(new Button($button, $img, $response)); + + return $this; + } + + /** + * Processes image parameter. + * + * @param ButtonTexture|string|array|null $image Image data + * @return ButtonTexture Processed texture + */ + private function processImage(ButtonTexture|string|array|null $image): ButtonTexture { + if ($image instanceof ButtonTexture) { + return $image; + } + + $type = ButtonTexture::PATH; + $data = ''; + + if (is_array($image)) { + $type = $image['type'] ?? $type; + $data = $image['data'] ?? $data; + } elseif (is_string($image)) { + $data = $image; + $type = filter_var($data, FILTER_VALIDATE_URL) ? ButtonTexture::URL : ButtonTexture::PATH; + } + + return new ButtonTexture($data, $type); + } + + /** + * Sets close handler. + * + * @param Closure $handler Close handler + * @return self + */ + public function setOnClose(Closure $handler): self { + $this->onClose = $handler; + return $this; + } + + /** + * Gets close handler. + * + * @return Closure Current handler + */ + public function getOnClose(): Closure { + return $this->onClose; + } + + /** + * Gets form type. + * + * @return string Form type identifier + */ + protected function getFormType(): string { + return "form"; + } + + /** + * Serializes form data. + * + * @return array Serialized form data + */ + protected function serializeFormData(): array { + return [ + 'content' => $this->content->getText(), + 'buttons' => array_map( + fn($button) => $button->jsonSerialize(), + iterator_to_array($this->buttons) + ) + ]; + } + + /** + * Handles form response. + * + * @param Player $player Responding player + * @param mixed $data Response data + */ + public function handleResponse(Player $player, $data): void { + if ($data === null) { + $result = ($this->onClose)($player); + } elseif (is_int($data) && ($button = $this->buttons[$data] ?? null)) { + $result = $button->getResponse()->handle($player); + } else { + $result = FormResult::CLOSE; + } + + if ($result === FormResult::KEEP) { + $this->sendTo($player); + } + } +} \ No newline at end of file diff --git a/long/LongForm.php b/long/LongForm.php new file mode 100644 index 0000000..60c9995 --- /dev/null +++ b/long/LongForm.php @@ -0,0 +1,124 @@ +formData = $data instanceof FormData ? $data : new FormData($data); + parent::__construct($this->title($player, $this->formData)); + + if ($force) { + $this->sendTo($player); + } + } + + /** + * Gets the form title. + * + * @param Player $player The player viewing the form. + * @param FormData $data Form data container. + * @return Title The title element. + */ + abstract protected function title(Player $player, FormData $data): Title; + + /** + * Gets the form content. + * + * @param Player $player The player viewing the form. + * @param FormData $data Form data container. + * @return Content The content element. + */ + abstract protected function content(Player $player, FormData $data): Content; + + /** + * Gets the button collection. + * + * @param Player $player The player viewing the form. + * @param FormData $data Form data container. + * @return ButtonCollection The button collection. + */ + abstract protected function buttons(Player $player, FormData $data): ButtonCollection; + + /** + * Handles form closure. + * + * @param Player $player The player who closed the form. + * @param FormData $data Form data container. + * @return FormResult The result controlling form behavior. + */ + protected function onClose(Player $player, FormData $data): FormResult { + return FormResult::CLOSE; + } + + /** + * Returns the form type. + * + * @return string The form type identifier. + */ + protected function getFormType(): string { + return "form"; + } + + /** + * Serializes form data for UI rendering. + * + * @return array The serialized form data. + */ + protected function serializeFormData(): array { + return [ + 'content' => $this->content($this->player, $this->formData)->getText(), + 'buttons' => array_map( + fn($button) => $button->jsonSerialize(), + iterator_to_array($this->buttons($this->player, $this->formData)) + ) + ]; + } + + /** + * Handles form responses. + * + * @param Player $player The responding player. + * @param mixed $raw The raw response data. + */ + public function handleResponse(Player $player, $raw): void { + if ($raw === null) { + $result = $this->onClose($player, $this->formData); + } elseif (is_int($raw)) { + $button = $this->buttons($player, $this->formData)[$raw] ?? null; + $result = $button ? $button->getResponse()->handle($player) : FormResult::CLOSE; + } else { + return; + } + + if ($result === FormResult::KEEP) { + $this->sendTo($player); + } + } +} \ No newline at end of file diff --git a/long/elements/Button.php b/long/elements/Button.php new file mode 100644 index 0000000..7b93b2b --- /dev/null +++ b/long/elements/Button.php @@ -0,0 +1,64 @@ +text; + } + + /** + * Gets button texture. + * + * @return ButtonTexture Button image + */ + public function getTexture(): ButtonTexture { + return $this->image; + } + + /** + * Gets button response handler. + * + * @return ButtonResponse Response handler + */ + public function getResponse(): ButtonResponse { + return $this->response; + } + + /** + * Serializes button for JSON. + * + * @return array Serialized button data + */ + public function jsonSerialize(): array { + return [ + 'text' => $this->text, + 'image' => $this->image->jsonSerialize() + ]; + } +} \ No newline at end of file diff --git a/long/elements/ButtonCollection.php b/long/elements/ButtonCollection.php new file mode 100644 index 0000000..4097ad2 --- /dev/null +++ b/long/elements/ButtonCollection.php @@ -0,0 +1,107 @@ +buttons[] = $button; + } + + /** + * Creates collection from array. + * + * @param Button[] $buttons Button array + * @return self New collection + */ + public static function fromArray(array $buttons): self { + $collection = new self(); + $collection->buttons = $buttons; + return $collection; + } + + /** + * Gets button by index. + * + * @param int $index Button position + * @return Button|null Button or null + */ + public function getByIndex(int $index): ?Button { + return $this->buttons[$index] ?? null; + } + + /** + * Counts buttons in collection. + * + * @return int Number of buttons + */ + public function count(): int { + return count($this->buttons); + } + + /** + * Gets iterator for buttons. + * + * @return Traversable