diff --git a/plugin.yml b/plugin.yml index 06cd041..b29cc3b 100644 --- a/plugin.yml +++ b/plugin.yml @@ -1,9 +1,9 @@ name: NaviCompass authors: [Vecnavium, Xenophilicy] -version: 3.0.4 +version: 3.0.5 main: Xenophilicy\NaviCompass\NaviCompass -api: 4.0.0 -mcpe-protocol: [527] +api: 5.0.0 +mcpe-protocol: [589] #Why use this now? description: View all your servers or worlds in a list using FormAPI! commands: navicompass: @@ -12,3 +12,5 @@ commands: permissions: navicompass.info: default: true + navicompass.use: + default: true diff --git a/resources/config.yml b/resources/config.yml index 7cf9b5a..27409ce 100644 --- a/resources/config.yml +++ b/resources/config.yml @@ -65,13 +65,6 @@ Command: # This is the command's description shown in the command window Description: "Open the server list!" - Permission: - # Choose whether to require players to have permission to use the command - Enabled: false - - # This is the command's usage permission - Node: "navicompass.use" - Selector: # Choose whether the selector item should be enabled Enabled: true diff --git a/src/Xenophilicy/NaviCompass/NaviCompass.php b/src/Xenophilicy/NaviCompass/NaviCompass.php index 0b15629..589371d 100644 --- a/src/Xenophilicy/NaviCompass/NaviCompass.php +++ b/src/Xenophilicy/NaviCompass/NaviCompass.php @@ -23,7 +23,6 @@ use pocketmine\event\inventory\InventoryTransactionEvent; use pocketmine\event\Listener; use pocketmine\event\player\{PlayerDeathEvent, - PlayerInteractEvent, PlayerItemUseEvent, PlayerJoinEvent, PlayerQuitEvent, @@ -31,11 +30,11 @@ use pocketmine\inventory\transaction\action\{DropItemAction, SlotChangeAction}; use pocketmine\item\enchantment\{Enchantment, EnchantmentInstance, ItemFlags, Rarity}; use pocketmine\item\Item; -use pocketmine\item\ItemFactory; use pocketmine\network\mcpe\protocol\PlaySoundPacket; use pocketmine\player\Player; use pocketmine\plugin\PluginBase; use pocketmine\utils\TextFormat as TF; +use pocketmine\world\format\io\GlobalItemDataHandlers; use Xenophilicy\NaviCompass\libs\jojoe77777\FormAPI\SimpleForm; use Xenophilicy\NaviCompass\Task\CompassCooldownTask; use Xenophilicy\NaviCompass\Task\QueryTaskCaller; @@ -88,9 +87,8 @@ public function onEnable(): void { } else { $cmd = new PluginCommand($cmdName, $this, $this); $cmd->setDescription(self::$settings["Command"]["Description"]); - if (self::$settings["Command"]["Permission"]["Enabled"]) { - $cmd->setPermission(self::$settings["Command"]["Permission"]["Node"]); - } + $cmd->setPermission("navicompass.use"); + $this->getServer()->getCommandMap()->register("NaviCompass", $cmd, $cmdName); } } else { @@ -348,18 +346,10 @@ private function sendActions(string $type, Player $player): void { $player->sendTitle(self::$settings["Titles"][$type]); } } - - public function onJoin(PlayerJoinEvent $event): void { - if (self::$settings["Selector"]["Enabled"]) { - $player = $event->getPlayer(); - $item = ItemFactory::getInstance()->get(self::$settings["Selector"]["Item"]); - $item->setCustomName(self::$settings["Selector"]["Name"]); - $item->setLore([self::$settings["Selector"]["Lore"]]); - $item->addEnchantment($this->enchInst); - $slot = self::$settings["Selector"]["Slot"]; - $player->getInventory()->setItem($slot, $item); - } - } + + public function onJoin(PlayerJoinEvent $event) : void{ + $this->giveItemToPlayer($event->getPlayer()); + } public function onQuit(PlayerQuitEvent $event): void { $player = $event->getPlayer(); @@ -370,15 +360,17 @@ public function onQuit(PlayerQuitEvent $event): void { } } } - - private function isSelectorItem(Item $item): bool { - if (self::$settings["Selector"]["Enabled"]) { - if ($item->getCustomName() == self::$settings["Selector"]["Name"] && $item->getId() == self::$settings["Selector"]["Item"] && $item->getLore() == [self::$settings["Selector"]["Lore"]]) { - return true; - } - } - return false; - } + + private function isSelectorItem(Item $item) : bool{ + if(self::$settings["Selector"]["Enabled"]){ + $savedData = GlobalItemDataHandlers::getUpgrader()->upgradeItemTypeDataInt(self::$settings["Selector"]["Item"], 0, 1, null); + $typeId = GlobalItemDataHandlers::getDeserializer()->deserializeStack($savedData)->getTypeId(); + if($item->getCustomName() == self::$settings["Selector"]["Name"] && $item->getTypeId() == $typeId && $item->getLore() == [self::$settings["Selector"]["Lore"]]){ + return true; + } + } + return false; + } public function onInteract(PlayerItemUseEvent $event): void { if (self::$settings["Selector"]["Enabled"]) { @@ -419,16 +411,24 @@ public function onDeath(PlayerDeathEvent $event) { $event->setDrops(array_diff($player->getInventory()->getContents(), [$player->getInventory()->getItem(self::$settings["Selector"]["Slot"])])); } - public function onRespawn(PlayerRespawnEvent $event) { - if (self::$settings["Selector"]["Enabled"]) { - $player = $event->getPlayer(); - $item = ItemFactory::getInstance()->get(self::$settings["Selector"]["Item"]); - $item->setCustomName(self::$settings["Selector"]["Name"]); - $item->setLore([self::$settings["Selector"]["Lore"]]); - $item->addEnchantment($this->enchInst); - $slot = self::$settings["Selector"]["Slot"]; - $player->getInventory()->setItem($slot, $item, true); - } - } + public function onRespawn(PlayerRespawnEvent $event) : void{ + $this->giveItemToPlayer($event->getPlayer()); + } + + /** + * @param Player $player + * @return void + */ + public function giveItemToPlayer(Player $player) : void{ + if(self::$settings["Selector"]["Enabled"]){ + $savedData = GlobalItemDataHandlers::getUpgrader()->upgradeItemTypeDataInt(self::$settings["Selector"]["Item"], 0, 1, null); + $item = GlobalItemDataHandlers::getDeserializer()->deserializeStack($savedData); + $item->setCustomName(self::$settings["Selector"]["Name"]); + $item->setLore([self::$settings["Selector"]["Lore"]]); + $item->addEnchantment($this->enchInst); + $slot = self::$settings["Selector"]["Slot"]; + $player->getInventory()->setItem($slot, $item); + } + } } diff --git a/src/Xenophilicy/NaviCompass/libs/jojoe77777/FormAPI/Form.php b/src/Xenophilicy/NaviCompass/libs/jojoe77777/FormAPI/Form.php index a760a78..bef3b2f 100644 --- a/src/Xenophilicy/NaviCompass/libs/jojoe77777/FormAPI/Form.php +++ b/src/Xenophilicy/NaviCompass/libs/jojoe77777/FormAPI/Form.php @@ -6,6 +6,7 @@ use pocketmine\form\Form as IForm; use pocketmine\player\Player; +use ReturnTypeWillChange; /** * Class Form @@ -64,9 +65,9 @@ public function setCallable(?callable $callable) { } /** - * @return array|mixed - */ - public function jsonSerialize() { + * @return array + */ + #[ReturnTypeWillChange] public function jsonSerialize() : array{ return $this->data; } }