├── .poggit.yml ├── LICENSE.md ├── README.md ├── plugin.yml ├── resources └── config.yml └── src └── BlockHorizons └── BlockQuests ├── BlockQuests.php ├── commands ├── BlockQuestsCommand.php ├── QuestCommand.php └── quest_parameters │ ├── BaseParameter.php │ ├── QuestCheckParameter.php │ ├── QuestCreateParameter.php │ ├── QuestDeleteParameter.php │ ├── QuestEditParameter.php │ ├── QuestHelpParameter.php │ └── QuestResetParameter.php ├── configurable └── BlockQuestsConfig.php ├── database ├── BaseDatabase.php └── SQLiteQuestDatabase.php ├── gui ├── BaseGui.php ├── GuiHandler.php ├── GuiUtils.php └── types │ ├── QuestCreatingGui.php │ └── QuestEditingGui.php ├── listeners ├── EventListener.php └── GuiListener.php └── quests ├── Quest.php ├── QuestManager.php ├── QuestValidator.php └── storage ├── JsonQuestStorage.php ├── QuestStorage.php └── YamlQuestStorage.php /.poggit.yml: -------------------------------------------------------------------------------- 1 | --- # Poggit-CI Manifest. Open the CI at https://poggit.pmmp.io/ci/BlockHorizons/BlockQuests 2 | branches: 3 | - master 4 | projects: 5 | BlockQuests: 6 | path: "" 7 | ... 8 | -------------------------------------------------------------------------------- /LICENSE.md: -------------------------------------------------------------------------------- 1 | Apache License 2 | Version 2.0, January 2004 3 | http://www.apache.org/licenses/ 4 | 5 | TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION 6 | 7 | 1. Definitions. 8 | 9 | "License" shall mean the terms and conditions for use, reproduction, 10 | and distribution as defined by Sections 1 through 9 of this document. 11 | 12 | "Licensor" shall mean the copyright owner or entity authorized by 13 | the copyright owner that is granting the License. 14 | 15 | "Legal Entity" shall mean the union of the acting entity and all 16 | other entities that control, are controlled by, or are under common 17 | control with that entity. For the purposes of this definition, 18 | "control" means (i) the power, direct or indirect, to cause the 19 | direction or management of such entity, whether by contract or 20 | otherwise, or (ii) ownership of fifty percent (50%) or more of the 21 | outstanding shares, or (iii) beneficial ownership of such entity. 22 | 23 | "You" (or "Your") shall mean an individual or Legal Entity 24 | exercising permissions granted by this License. 25 | 26 | "Source" form shall mean the preferred form for making modifications, 27 | including but not limited to software source code, documentation 28 | source, and configuration files. 29 | 30 | "Object" form shall mean any form resulting from mechanical 31 | transformation or translation of a Source form, including but 32 | not limited to compiled object code, generated documentation, 33 | and conversions to other media types. 34 | 35 | "Work" shall mean the work of authorship, whether in Source or 36 | Object form, made available under the License, as indicated by a 37 | copyright notice that is included in or attached to the work 38 | (an example is provided in the Appendix below). 39 | 40 | "Derivative Works" shall mean any work, whether in Source or Object 41 | form, that is based on (or derived from) the Work and for which the 42 | editorial revisions, annotations, elaborations, or other modifications 43 | represent, as a whole, an original work of authorship. For the purposes 44 | of this License, Derivative Works shall not include works that remain 45 | separable from, or merely link (or bind by name) to the interfaces of, 46 | the Work and Derivative Works thereof. 47 | 48 | "Contribution" shall mean any work of authorship, including 49 | the original version of the Work and any modifications or additions 50 | to that Work or Derivative Works thereof, that is intentionally 51 | submitted to Licensor for inclusion in the Work by the copyright owner 52 | or by an individual or Legal Entity authorized to submit on behalf of 53 | the copyright owner. For the purposes of this definition, "submitted" 54 | means any form of electronic, verbal, or written communication sent 55 | to the Licensor or its representatives, including but not limited to 56 | communication on electronic mailing lists, source code control systems, 57 | and issue tracking systems that are managed by, or on behalf of, the 58 | Licensor for the purpose of discussing and improving the Work, but 59 | excluding communication that is conspicuously marked or otherwise 60 | designated in writing by the copyright owner as "Not a Contribution." 61 | 62 | "Contributor" shall mean Licensor and any individual or Legal Entity 63 | on behalf of whom a Contribution has been received by Licensor and 64 | subsequently incorporated within the Work. 65 | 66 | 2. Grant of Copyright License. Subject to the terms and conditions of 67 | this License, each Contributor hereby grants to You a perpetual, 68 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable 69 | copyright license to reproduce, prepare Derivative Works of, 70 | publicly display, publicly perform, sublicense, and distribute the 71 | Work and such Derivative Works in Source or Object form. 72 | 73 | 3. Grant of Patent License. Subject to the terms and conditions of 74 | this License, each Contributor hereby grants to You a perpetual, 75 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable 76 | (except as stated in this section) patent license to make, have made, 77 | use, offer to sell, sell, import, and otherwise transfer the Work, 78 | where such license applies only to those patent claims licensable 79 | by such Contributor that are necessarily infringed by their 80 | Contribution(s) alone or by combination of their Contribution(s) 81 | with the Work to which such Contribution(s) was submitted. If You 82 | institute patent litigation against any entity (including a 83 | cross-claim or counterclaim in a lawsuit) alleging that the Work 84 | or a Contribution incorporated within the Work constitutes direct 85 | or contributory patent infringement, then any patent licenses 86 | granted to You under this License for that Work shall terminate 87 | as of the date such litigation is filed. 88 | 89 | 4. Redistribution. You may reproduce and distribute copies of the 90 | Work or Derivative Works thereof in any medium, with or without 91 | modifications, and in Source or Object form, provided that You 92 | meet the following conditions: 93 | 94 | (a) You must give any other recipients of the Work or 95 | Derivative Works a copy of this License; and 96 | 97 | (b) You must cause any modified files to carry prominent notices 98 | stating that You changed the files; and 99 | 100 | (c) You must retain, in the Source form of any Derivative Works 101 | that You distribute, all copyright, patent, trademark, and 102 | attribution notices from the Source form of the Work, 103 | excluding those notices that do not pertain to any part of 104 | the Derivative Works; and 105 | 106 | (d) If the Work includes a "NOTICE" text file as part of its 107 | distribution, then any Derivative Works that You distribute must 108 | include a readable copy of the attribution notices contained 109 | within such NOTICE file, excluding those notices that do not 110 | pertain to any part of the Derivative Works, in at least one 111 | of the following places: within a NOTICE text file distributed 112 | as part of the Derivative Works; within the Source form or 113 | documentation, if provided along with the Derivative Works; or, 114 | within a display generated by the Derivative Works, if and 115 | wherever such third-party notices normally appear. The contents 116 | of the NOTICE file are for informational purposes only and 117 | do not modify the License. You may add Your own attribution 118 | notices within Derivative Works that You distribute, alongside 119 | or as an addendum to the NOTICE text from the Work, provided 120 | that such additional attribution notices cannot be construed 121 | as modifying the License. 122 | 123 | You may add Your own copyright statement to Your modifications and 124 | may provide additional or different license terms and conditions 125 | for use, reproduction, or distribution of Your modifications, or 126 | for any such Derivative Works as a whole, provided Your use, 127 | reproduction, and distribution of the Work otherwise complies with 128 | the conditions stated in this License. 129 | 130 | 5. Submission of Contributions. Unless You explicitly state otherwise, 131 | any Contribution intentionally submitted for inclusion in the Work 132 | by You to the Licensor shall be under the terms and conditions of 133 | this License, without any additional terms or conditions. 134 | Notwithstanding the above, nothing herein shall supersede or modify 135 | the terms of any separate license agreement you may have executed 136 | with Licensor regarding such Contributions. 137 | 138 | 6. Trademarks. This License does not grant permission to use the trade 139 | names, trademarks, service marks, or product names of the Licensor, 140 | except as required for reasonable and customary use in describing the 141 | origin of the Work and reproducing the content of the NOTICE file. 142 | 143 | 7. Disclaimer of Warranty. Unless required by applicable law or 144 | agreed to in writing, Licensor provides the Work (and each 145 | Contributor provides its Contributions) on an "AS IS" BASIS, 146 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or 147 | implied, including, without limitation, any warranties or conditions 148 | of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A 149 | PARTICULAR PURPOSE. You are solely responsible for determining the 150 | appropriateness of using or redistributing the Work and assume any 151 | risks associated with Your exercise of permissions under this License. 152 | 153 | 8. Limitation of Liability. In no event and under no legal theory, 154 | whether in tort (including negligence), contract, or otherwise, 155 | unless required by applicable law (such as deliberate and grossly 156 | negligent acts) or agreed to in writing, shall any Contributor be 157 | liable to You for damages, including any direct, indirect, special, 158 | incidental, or consequential damages of any character arising as a 159 | result of this License or out of the use or inability to use the 160 | Work (including but not limited to damages for loss of goodwill, 161 | work stoppage, computer failure or malfunction, or any and all 162 | other commercial damages or losses), even if such Contributor 163 | has been advised of the possibility of such damages. 164 | 165 | 9. Accepting Warranty or Additional Liability. While redistributing 166 | the Work or Derivative Works thereof, You may choose to offer, 167 | and charge a fee for, acceptance of support, warranty, indemnity, 168 | or other liability obligations and/or rights consistent with this 169 | License. However, in accepting such obligations, You may act only 170 | on Your own behalf and on Your sole responsibility, not on behalf 171 | of any other Contributor, and only if You agree to indemnify, 172 | defend, and hold each Contributor harmless for any liability 173 | incurred by, or claims asserted against, such Contributor by reason 174 | of your accepting any such warranty or additional liability. 175 | 176 | END OF TERMS AND CONDITIONS 177 | 178 | APPENDIX: How to apply the Apache License to your work. 179 | 180 | To apply the Apache License to your work, attach the following 181 | boilerplate notice, with the fields enclosed by brackets "{}" 182 | replaced with your own identifying information. (Don't include 183 | the brackets!) The text should be enclosed in the appropriate 184 | comment syntax for the file format. We also recommend that a 185 | file or class name and description of purpose be included on the 186 | same "printed page" as the copyright notice for easier 187 | identification within third-party archives. 188 | 189 | Copyright 2017 BlockHorizons 190 | 191 | Licensed under the Apache License, Version 2.0 (the "License"); 192 | you may not use this file except in compliance with the License. 193 | You may obtain a copy of the License at 194 | 195 | http://www.apache.org/licenses/LICENSE-2.0 196 | 197 | Unless required by applicable law or agreed to in writing, software 198 | distributed under the License is distributed on an "AS IS" BASIS, 199 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 200 | See the License for the specific language governing permissions and 201 | limitations under the License. 202 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # BlockQuests 2 | 3 | [![Join the chat at https://gitter.im/BlockHorizons/BlockQuests](https://badges.gitter.im/BlockHorizons/BlockQuests.svg)](https://gitter.im/BlockHorizons/BlockQuests?utm_source=badge&utm_medium=badge&utm_campaign=pr-badge&utm_content=badge)

4 | A user-friendly quest plugin for PocketMine-MP, a Minecraft PE server software written in PHP. Implements highly configurable quests opening up lots of new possibilities for servers. 5 | 6 | > Third party versions, forks or spoons of PocketMine-MP are **not** supported. 7 | > 8 | > Issues caused by other server softwares than PocketMine-MP will be closed immediately. 9 | 10 | ### Installation 11 | Stable releases of BlockQuests will be drafted at the Release tab with a pre-built phar file, and can be found on the Poggit website once released. Alternatively, you can grab a development build from the Poggit button below. 12 | To install: 13 | - Download one of the pre-built phar files from either releases or the Poggit button below. 14 | - Drop the phar file in the plugins folder of your server. 15 | - Restart the server, and enjoy.

16 | [![Poggit-CI](https://poggit.pmmp.io/ci.shield/BlockHorizons/BlockQuests/BlockQuests)](https://poggit.pmmp.io/ci/BlockHorizons/BlockQuests/BlockQuests)
17 | 18 | ### Commands and Permissions 19 | BlockQuests has permissions for every command. The most up to date list of permissions can be found in the [plugin.yml file](https://github.com/BlockHorizons/BlockQuests/blob/master/plugin.yml)
20 | 21 | > BlockQuests contains a hand full of commands to check, create and remove quests. These commands can be found using the /blockquests(bq) \ command. This command will list all BlockQuests parameters. 22 | -------------------------------------------------------------------------------- /plugin.yml: -------------------------------------------------------------------------------- 1 | --- 2 | name: "BlockQuests" 3 | author: "BlockHorizons" 4 | version: 1.0.0 5 | main: BlockHorizons\BlockQuests\BlockQuests 6 | api: 7 | - 3.0.0-ALPHA7 8 | - 3.0.0-ALPHA8 9 | - 3.0.0-ALPHA9 10 | - 3.0.0-ALPHA10 11 | 12 | permissions: 13 | blockquests: 14 | default: false 15 | description: "Allows access to all BlockQuest features." 16 | children: 17 | blockquests.command: 18 | default: false 19 | description: "Allows access to all BlockQuest commands." 20 | children: 21 | blockquests.command.create: 22 | default: op 23 | description: "Allows access to creating a quest." 24 | blockquests.command.edit: 25 | default: op 26 | description: "Allows access to editing a quest." 27 | blockquests.command.delete: 28 | default: op 29 | description: "Allows access to deleting an existing quest." 30 | blockquests.command.check: 31 | default: true 32 | description: "Allows access to starting an existing quest." 33 | blockquests.command.reset: 34 | default: false 35 | description: "Allows resetting all quests data." 36 | children: 37 | blockquests.command.reset.self: 38 | default: true 39 | description: "Allows resetting your own quests data." 40 | blockquests.command.reset.others: 41 | default: op 42 | description: "Allows resetting quests data of other players." 43 | blockquests.command.help: 44 | default: false 45 | description: "Allows usage of the help command." 46 | children: 47 | blockquests.command.help.default: 48 | default: true 49 | description: "Allows listing the blockquests help page for normal players." 50 | blockquests.command.help.others: 51 | default: op 52 | description: "Allows listing the blockquests help page of operators." 53 | ... 54 | -------------------------------------------------------------------------------- /resources/config.yml: -------------------------------------------------------------------------------- 1 | --- 2 | # Configuration file for BlockQuests, a quests plugin by BlockHorizons. 3 | 4 | # File saving format for quest saving. 5 | # Available providers: 6 | # - yaml 7 | # - json 8 | Quest-Saving-Data-Provider: yaml 9 | 10 | # Player quest data storage database. 11 | # Available databases: 12 | # SQLite 13 | Player-Quests-Database: SQLite 14 | 15 | # The format used when starting a new quest. 16 | # {STARTING_MESSAGE}: The message set when creating/editing the quest. 17 | # {QUEST_NAME}: The name of the quest set when creating/editing the quest. 18 | # {QUEST_DESCRIPTION}: The description of the quest also set when creating/editing the quest. 19 | Quest-Starting-Format: "{STARTING_MESSAGE}\nQuest Started: {QUEST_NAME}\n{QUEST_DESCRIPTION}" 20 | ... 21 | -------------------------------------------------------------------------------- /src/BlockHorizons/BlockQuests/BlockQuests.php: -------------------------------------------------------------------------------- 1 | saveDefaultConfig(); 36 | if(!is_dir($this->getDataFolder() . "quests/")) { 37 | mkdir($this->getDataFolder() . "quests/"); 38 | } 39 | $this->bqConfig = new BlockQuestsConfig($this); 40 | $this->registerCommands(); 41 | $this->registerListeners(); 42 | 43 | $this->guiHandler = new GuiHandler($this); 44 | $this->questManager = new QuestManager($this); 45 | $this->initializeStorage(); 46 | $this->initializeDatabase(); 47 | } 48 | 49 | public function registerCommands(): void { 50 | $commands = [ 51 | new QuestCommand($this) 52 | ]; 53 | /** @var BlockQuestsCommand $command */ 54 | foreach($commands as $command) { 55 | $this->getServer()->getCommandMap()->register($command->getName(), $command); 56 | } 57 | } 58 | 59 | public function registerListeners(): void { 60 | $listeners = [ 61 | new GuiListener($this), 62 | new EventListener($this) 63 | ]; 64 | foreach($listeners as $listener) { 65 | $this->getServer()->getPluginManager()->registerEvents($listener, $this); 66 | } 67 | } 68 | 69 | /** 70 | * @return QuestStorage 71 | */ 72 | public function initializeStorage(): QuestStorage { 73 | switch($this->getBlockQuestsConfig()->getQuestDataStorage()) { 74 | default: 75 | case "yaml": 76 | case "yml": 77 | $this->questStorage = new YamlQuestStorage($this); 78 | break; 79 | case "json": 80 | $this->questStorage = new JsonQuestStorage($this); 81 | break; 82 | } 83 | return $this->questStorage; 84 | } 85 | 86 | /** 87 | * @return BlockQuestsConfig 88 | */ 89 | public function getBlockQuestsConfig(): BlockQuestsConfig { 90 | return $this->bqConfig; 91 | } 92 | 93 | /** 94 | * @return BaseDatabase 95 | */ 96 | public function initializeDatabase(): BaseDatabase { 97 | switch($this->getBlockQuestsConfig()->getPlayerDataStorage()) { 98 | default: 99 | case "sqlite": 100 | case "sqlite3": 101 | $this->playerStorage = new SQLiteQuestDatabase($this); 102 | break; 103 | } 104 | return $this->playerStorage; 105 | } 106 | 107 | /** 108 | * @return BaseDatabase 109 | */ 110 | public function getPlayerDatabase(): BaseDatabase { 111 | return $this->playerStorage; 112 | } 113 | 114 | /** 115 | * @return GuiHandler 116 | */ 117 | public function getGuiHandler(): GuiHandler { 118 | return $this->guiHandler; 119 | } 120 | 121 | /** 122 | * @return QuestStorage 123 | */ 124 | public function getQuestStorage(): QuestStorage { 125 | return $this->questStorage; 126 | } 127 | 128 | /** 129 | * @return QuestManager 130 | */ 131 | public function getQuestManager(): QuestManager { 132 | return $this->questManager; 133 | } 134 | } -------------------------------------------------------------------------------- /src/BlockHorizons/BlockQuests/commands/BlockQuestsCommand.php: -------------------------------------------------------------------------------- 1 | plugin = $plugin; 20 | } 21 | 22 | /** 23 | * @return BlockQuests 24 | */ 25 | public function getPlugin(): Plugin { 26 | return $this->plugin; 27 | } 28 | } -------------------------------------------------------------------------------- /src/BlockHorizons/BlockQuests/commands/QuestCommand.php: -------------------------------------------------------------------------------- 1 | sendMessage(TextFormat::RED . "[Usage] " . $this->getUsage()); 33 | return true; 34 | } 35 | switch($args[0]) { 36 | case "create": 37 | case "make": 38 | case "new": 39 | return (new QuestCreateParameter($this->getPlugin(), $sender, $args))->perform(); 40 | case "edit": 41 | case "modify": 42 | return (new QuestEditParameter($this->getPlugin(), $sender, $args))->perform(); 43 | case "delete": 44 | case "remove": 45 | return (new QuestDeleteParameter($this->getPlugin(), $sender, $args))->perform(); 46 | case "check": 47 | return (new QuestCheckParameter($this->getPlugin(), $sender, $args))->perform(); 48 | case "reset": 49 | case "clear": 50 | return (new QuestResetParameter($this->getPlugin(), $sender, $args))->perform(); 51 | case "help": 52 | return (new QuestHelpParameter($this->getPlugin(), $sender, $args))->perform(); 53 | } 54 | return false; 55 | } 56 | } -------------------------------------------------------------------------------- /src/BlockHorizons/BlockQuests/commands/quest_parameters/BaseParameter.php: -------------------------------------------------------------------------------- 1 | sender = $sender; 21 | $this->args = $args; 22 | $this->plugin = $plugin; 23 | } 24 | 25 | /** 26 | * @return CommandSender 27 | */ 28 | public function getSender(): CommandSender { 29 | return $this->sender; 30 | } 31 | 32 | /** 33 | * @return BlockQuests 34 | */ 35 | public function getPlugin(): BlockQuests { 36 | return $this->plugin; 37 | } 38 | 39 | /** 40 | * @return bool 41 | */ 42 | public abstract function perform(): bool; 43 | } -------------------------------------------------------------------------------- /src/BlockHorizons/BlockQuests/commands/quest_parameters/QuestCheckParameter.php: -------------------------------------------------------------------------------- 1 | sender instanceof Player) { 23 | $this->sender->sendMessage(TextFormat::RED . "[Error] This command can only be executed as a player."); 24 | return true; 25 | } 26 | if(!$this->sender->hasPermission("blockquests.command.check")) { 27 | $this->sender->sendMessage(TextFormat::RED . "[Error] You do not have permission to use this command."); 28 | return true; 29 | } 30 | if(count($this->args) < 2 || count($this->args) > 2) { 31 | $this->sender->sendMessage(TextFormat::RED . "[Usage] /quest check "); 32 | return true; 33 | } 34 | if(!is_numeric($this->args[1])) { 35 | $this->sender->sendMessage(TextFormat::RED . "[Error] The quest ID should be numeric."); 36 | return true; 37 | } 38 | if(!$this->getPlugin()->getQuestManager()->questExists((int) $this->args[1])) { 39 | $this->sender->sendMessage(TextFormat::RED . "[Error] A quest with that quest ID does not exist."); 40 | return true; 41 | } 42 | $quest = $this->getPlugin()->getQuestManager()->getQuestById((int) $this->args[1]); 43 | if(!$this->getPlugin()->getPlayerDatabase()->hasQuestStarted($this->sender, $quest->getId()) && !$this->getPlugin()->getPlayerDatabase()->hasQuestFinished($this->sender, $quest->getId())) { 44 | if(!$quest->checkStartingExperience($this->sender)) { 45 | $this->sender->sendMessage(TextFormat::RED . $quest->getInsufficientStartExperienceMessage()); 46 | return true; 47 | } 48 | if(!$quest->checkStartingItems($this->sender)) { 49 | $this->sender->sendMessage(TextFormat::RED . $quest->getMissingStartItemsMessage()); 50 | return true; 51 | } 52 | foreach($quest->getStartRequiredItems() as $item) { 53 | $this->sender->getInventory()->removeItem($item); 54 | } 55 | $this->getPlugin()->getQuestManager()->startQuest($quest, $this->sender); 56 | } elseif($this->getPlugin()->getPlayerDatabase()->hasQuestStarted($this->sender, $quest->getId())) { 57 | if(!$quest->checkFinishingItems($this->sender)) { 58 | $this->sender->sendMessage(TextFormat::YELLOW . $quest->getStartedMessage()); 59 | return true; 60 | } 61 | foreach($quest->getFinishRequiredItems() as $item) { 62 | $this->sender->getInventory()->removeItem($item); 63 | } 64 | $this->getPlugin()->getQuestManager()->finishQuest($quest, $this->sender); 65 | } else { 66 | $this->sender->sendMessage($quest->getFinishedMessage()); 67 | } 68 | 69 | return true; 70 | } 71 | } -------------------------------------------------------------------------------- /src/BlockHorizons/BlockQuests/commands/quest_parameters/QuestCreateParameter.php: -------------------------------------------------------------------------------- 1 | sender instanceof Player) { 24 | $this->sender->sendMessage(TextFormat::RED . "[Error] This command can only be executed as a player."); 25 | return true; 26 | } 27 | if(!$this->sender->hasPermission("blockquests.command.create")) { 28 | $this->sender->sendMessage(TextFormat::RED . "[Error] You do not have permission to use this command."); 29 | return true; 30 | } 31 | if(count($this->args) < 2 || count($this->args) > 2) { 32 | $this->sender->sendMessage(TextFormat::RED . "[Usage] /quest create "); 33 | return true; 34 | } 35 | if(!is_numeric($this->args[1])) { 36 | $this->sender->sendMessage(TextFormat::RED . "[Error] The quest ID should be numeric."); 37 | return true; 38 | } 39 | if($this->getPlugin()->getGuiHandler()->isUsingGui($this->sender)) { 40 | $this->sender->sendMessage(TextFormat::RED . "[Error] You are already creating a quest."); 41 | return true; 42 | } 43 | if($this->getPlugin()->getQuestManager()->questExists((int) $this->args[1])) { 44 | $this->sender->sendMessage(TextFormat::RED . "[Error] A quest with that quest ID already exists. Use '/quest edit " . $this->args[1] . "' to edit it."); 45 | return true; 46 | } 47 | $gui = new QuestCreatingGui($this->getPlugin(), $this->sender, (int) $this->args[1]); 48 | $gui->openGui(); 49 | return true; 50 | } 51 | } -------------------------------------------------------------------------------- /src/BlockHorizons/BlockQuests/commands/quest_parameters/QuestDeleteParameter.php: -------------------------------------------------------------------------------- 1 | sender->hasPermission("blockquests.command.delete")) { 22 | $this->sender->sendMessage(TextFormat::RED . "[Error] You do not have permission to use this command."); 23 | return true; 24 | } 25 | if(count($this->args) < 2 || count($this->args) > 2) { 26 | $this->sender->sendMessage(TextFormat::RED . "[Usage] /quest delete "); 27 | return true; 28 | } 29 | if(!is_numeric($this->args[1])) { 30 | $this->sender->sendMessage(TextFormat::RED . "[Error] The quest ID should be numeric."); 31 | return true; 32 | } 33 | $this->getPlugin()->getQuestManager()->deleteQuest((int) $this->args[1]); 34 | $this->sender->sendMessage(TextFormat::GREEN . "Quest with ID " . TextFormat::AQUA . (string) $this->args[1] . TextFormat::GREEN . " successfully deleted."); 35 | return true; 36 | } 37 | } -------------------------------------------------------------------------------- /src/BlockHorizons/BlockQuests/commands/quest_parameters/QuestEditParameter.php: -------------------------------------------------------------------------------- 1 | sender instanceof Player) { 24 | $this->sender->sendMessage(TextFormat::RED . "[Error] This command can only be executed as a player."); 25 | return true; 26 | } 27 | if(!$this->sender->hasPermission("blockquests.command.edit")) { 28 | $this->sender->sendMessage(TextFormat::RED . "[Error] You do not have permission to use this command."); 29 | return true; 30 | } 31 | if(count($this->args) < 2 || count($this->args) > 2) { 32 | $this->sender->sendMessage(TextFormat::RED . "[Usage] /quest edit "); 33 | return true; 34 | } 35 | if(!is_numeric($this->args[1])) { 36 | $this->sender->sendMessage(TextFormat::RED . "[Error] The quest ID should be numeric."); 37 | return true; 38 | } 39 | if($this->getPlugin()->getGuiHandler()->isUsingGui($this->sender)) { 40 | $this->sender->sendMessage(TextFormat::RED . "[Error] You are already editing a quest."); 41 | return true; 42 | } 43 | if(!$this->getPlugin()->getQuestManager()->questExists((int) $this->args[1])) { 44 | $this->sender->sendMessage(TextFormat::RED . "[Error] A quest with that quest ID does not exist. Use '/quest create " . $this->args[1] . "' to create it."); 45 | return true; 46 | } 47 | $gui = new QuestEditingGui($this->getPlugin(), $this->sender, (int) $this->args[1]); 48 | $gui->openGui(); 49 | return true; 50 | } 51 | } -------------------------------------------------------------------------------- /src/BlockHorizons/BlockQuests/commands/quest_parameters/QuestHelpParameter.php: -------------------------------------------------------------------------------- 1 | sender->hasPermission("blockquests.command.help.default")) { 22 | $this->sender->sendMessage(TF::RED . "[Error] You do not have permission to use this command."); 23 | return true; 24 | } 25 | if($this->sender->hasPermission("blockquests.command.help.operator")) { 26 | $this->sender->sendMessage( 27 | TF::GREEN . "/bq check : " . TF::YELLOW . "Checks the given quest to start or end it if possible." . PHP_EOL . 28 | TF::GREEN . "/bq create : " . TF::YELLOW . "Creates a new quest with the given ID and opens up the GUI." . PHP_EOL . 29 | TF::GREEN . "/bq delete : " . TF::YELLOW . "Deletes a quest with the given ID." . PHP_EOL . 30 | TF::GREEN . "/bq edit : " . TF::YELLOW . "Reopens the GUI of a quest to start editing it." . PHP_EOL . 31 | TF::GREEN . "/bq reset [Player]: " . TF::YELLOW . "Resets your quest data, or the data of a given player." 32 | ); 33 | } else { 34 | $this->sender->sendMessage( 35 | TF::GREEN . "/bq check : " . TF::YELLOW . "Checks the given quest to start or end it if possible." . PHP_EOL . 36 | TF::GREEN . "/bq reset: " . TF::YELLOW . "Resets your quest data." 37 | ); 38 | } 39 | return true; 40 | } 41 | } -------------------------------------------------------------------------------- /src/BlockHorizons/BlockQuests/commands/quest_parameters/QuestResetParameter.php: -------------------------------------------------------------------------------- 1 | sender->hasPermission("blockquests.command.reset.self")) { 22 | $this->sender->sendMessage(TextFormat::RED . "[Error] You do not have permission to use this command."); 23 | return true; 24 | } 25 | if(count($this->args) < 1 || count($this->args) > 2) { 26 | $this->sender->sendMessage(TextFormat::RED . "[Usage] /quest reset [player]"); 27 | return true; 28 | } 29 | $player = $this->sender; 30 | if(isset($this->args[1])) { 31 | if(($player = $this->getPlugin()->getServer()->getPlayer($this->args[1])) === null) { 32 | $this->sender->sendMessage(TextFormat::RED . "[Error] The given player could not be found."); 33 | return true; 34 | } 35 | if(!$this->sender->hasPermission("blockquests.command.reset.others")) { 36 | $this->sender->sendMessage(TextFormat::RED . "[Error] You don't have permission to reset the quest data of other players."); 37 | return true; 38 | } 39 | } 40 | $this->getPlugin()->getPlayerDatabase()->clearData($player); 41 | $this->getPlugin()->getPlayerDatabase()->addPlayer($player); 42 | $this->sender->sendMessage(TextFormat::GREEN . "Quest data " . ($player !== $this->sender ? "of " . $player->getName() : null) . " reset successfully."); 43 | return true; 44 | } 45 | } -------------------------------------------------------------------------------- /src/BlockHorizons/BlockQuests/configurable/BlockQuestsConfig.php: -------------------------------------------------------------------------------- 1 | plugin = $plugin; 18 | $plugin->saveDefaultConfig(); 19 | $this->collectPreferences(); 20 | } 21 | 22 | public function collectPreferences(): void { 23 | $data = yaml_parse_file($this->getPlugin()->getDataFolder() . "config.yml"); 24 | $this->settings = $data; 25 | } 26 | 27 | /** 28 | * @return BlockQuests 29 | */ 30 | public function getPlugin(): BlockQuests { 31 | return $this->plugin; 32 | } 33 | 34 | /** 35 | * @return string 36 | */ 37 | public function getQuestDataStorage(): string { 38 | return $this->settings["Quest-Saving-Data-Provider"] ?? "yaml"; 39 | } 40 | 41 | /** 42 | * @return string 43 | */ 44 | public function getPlayerDataStorage(): string { 45 | return $this->settings["Player-Quests-Database"] ?? "sqlite"; 46 | } 47 | 48 | /** 49 | * @return string 50 | */ 51 | public function getQuestStartingFormat(): string { 52 | return $this->settings["Quest-Starting-Format"] ?? "{STARTING_MESSAGE}\nQuest Started: {QUEST_NAME}\n{QUEST_DESCRIPTION}"; 53 | } 54 | } -------------------------------------------------------------------------------- /src/BlockHorizons/BlockQuests/database/BaseDatabase.php: -------------------------------------------------------------------------------- 1 | plugin = $plugin; 18 | 19 | $this->prepare(); 20 | } 21 | 22 | /** 23 | * @return bool 24 | */ 25 | public abstract function prepare(): bool; 26 | 27 | /** 28 | * @return BlockQuests 29 | */ 30 | public function getPlugin(): BlockQuests { 31 | return $this->plugin; 32 | } 33 | 34 | /** 35 | * @param string $string 36 | * 37 | * @return string 38 | */ 39 | public abstract function escape(string $string): string; 40 | 41 | /** 42 | * @param IPlayer $player 43 | * @param int $questId 44 | * 45 | * @return bool 46 | */ 47 | public function startQuest(IPlayer $player, int $questId): bool { 48 | $startedQuestIds = []; 49 | foreach($this->getStartedQuests($player) as $quest) { 50 | $startedQuestIds[] = $quest->getId(); 51 | } 52 | $startedQuestIds[] = $questId; 53 | return $this->updateStartedQuests($player, serialize($startedQuestIds)); 54 | } 55 | 56 | /** 57 | * @param IPlayer $player 58 | * 59 | * @return Quest[] 60 | */ 61 | public function getStartedQuests(IPlayer $player): array { 62 | $quests = []; 63 | if(empty($this->getPlayerData($player)["StartedQuests"])) { 64 | return []; 65 | } 66 | foreach($this->getPlayerData($player)["StartedQuests"] as $questId) { 67 | $quests = []; 68 | foreach($this->getFinishedQuests($player) as $quest) { 69 | $quests[] = $quest->getId(); 70 | } 71 | if(in_array($questId, $quests)) { 72 | continue; 73 | } 74 | $quests[] = $this->plugin->getQuestStorage()->fetch($questId); 75 | } 76 | foreach($quests as $key => $quest) { 77 | if(!$quest instanceof Quest) { 78 | unset($quests[$key]); 79 | } 80 | } 81 | return $quests; 82 | } 83 | 84 | /** 85 | * @param IPlayer $player 86 | * 87 | * @return array 88 | */ 89 | public abstract function getPlayerData(IPlayer $player): array; 90 | 91 | /** 92 | * @param IPlayer $player 93 | * 94 | * @return Quest[] 95 | */ 96 | public function getFinishedQuests(IPlayer $player): array { 97 | $quests = []; 98 | if(empty($this->getPlayerData($player)["FinishedQuests"])) { 99 | return []; 100 | } 101 | foreach($this->getPlayerData($player)["FinishedQuests"] as $questId) { 102 | $quests[] = $this->plugin->getQuestStorage()->fetch($questId); 103 | } 104 | foreach($quests as $key => $quest) { 105 | if(!$quest instanceof Quest) { 106 | unset($quests[$key]); 107 | } 108 | } 109 | return $quests; 110 | } 111 | 112 | /** 113 | * @param IPlayer $player 114 | * @param string $serializedData 115 | * 116 | * @return bool 117 | */ 118 | public abstract function updateStartedQuests(IPlayer $player, string $serializedData): bool; 119 | 120 | /** 121 | * @param IPlayer $player 122 | * @param int $questId 123 | * 124 | * @return bool 125 | */ 126 | public function finishQuest(IPlayer $player, int $questId): bool { 127 | $finishedQuestIds = []; 128 | foreach($this->getFinishedQuests($player) as $quest) { 129 | $finishedQuestIds[] = $quest->getId(); 130 | } 131 | $finishedQuestIds[] = $questId; 132 | return $this->updateFinishedQuests($player, serialize($finishedQuestIds)); 133 | } 134 | 135 | /** 136 | * @param IPlayer $player 137 | * @param string $serializedData 138 | * 139 | * @return bool 140 | */ 141 | public abstract function updateFinishedQuests(IPlayer $player, string $serializedData): bool; 142 | 143 | /** 144 | * @param IPlayer $player 145 | * 146 | * @return bool 147 | */ 148 | public abstract function playerExists(IPlayer $player): bool; 149 | 150 | /** 151 | * @param IPlayer $player 152 | * 153 | * @return bool 154 | */ 155 | public abstract function addPlayer(IPlayer $player): bool; 156 | 157 | /** 158 | * @param IPlayer $player 159 | * 160 | * @return bool 161 | */ 162 | public abstract function clearData(IPlayer $player): bool; 163 | 164 | /** 165 | * @param IPlayer $player 166 | * @param int $questId 167 | * 168 | * @return bool 169 | */ 170 | public abstract function hasQuestStarted(IPlayer $player, int $questId): bool; 171 | 172 | /** 173 | * @param IPlayer $player 174 | * @param int $questId 175 | * 176 | * @return bool 177 | */ 178 | public abstract function hasQuestFinished(IPlayer $player, int $questId): bool; 179 | 180 | public function __destruct() { 181 | $this->close(); 182 | } 183 | 184 | /** 185 | * @return bool 186 | */ 187 | public abstract function close(): bool; 188 | } -------------------------------------------------------------------------------- /src/BlockHorizons/BlockQuests/database/SQLiteQuestDatabase.php: -------------------------------------------------------------------------------- 1 | getPlugin()->getDataFolder() . "quest_stats.sqlite3")) { 24 | file_put_contents($path, ""); 25 | } 26 | $this->database = new \SQLite3($path); 27 | $query = "CREATE TABLE IF NOT EXISTS QuestStats( 28 | Player VARCHAR(16) PRIMARY KEY, 29 | StartedQuests VARCHAR, 30 | FinishedQuests VARCHAR 31 | )"; 32 | return $this->database->exec($query); 33 | } 34 | 35 | /** 36 | * @return bool 37 | */ 38 | public function close(): bool { 39 | if($this->database instanceof \SQLite3) { 40 | $this->database->close(); 41 | return true; 42 | } 43 | return false; 44 | } 45 | 46 | /** 47 | * @param IPlayer $player 48 | * 49 | * @return array 50 | */ 51 | public function getPlayerData(IPlayer $player): array { 52 | $player = strtolower($player->getName()); 53 | $query = "SELECT * FROM QuestStats WHERE Player = '" . $this->escape($player) . "'"; 54 | 55 | $results = $this->database->query($query)->fetchArray(SQLITE3_ASSOC); 56 | foreach($results as $key => $result) { 57 | if($key === "Player") { 58 | continue; 59 | } 60 | if(empty($result) || $result === 0) { 61 | continue; 62 | } 63 | $results[$key] = unserialize($result); 64 | } 65 | return $results; 66 | } 67 | 68 | /** 69 | * @param string $string 70 | * 71 | * @return string 72 | */ 73 | public function escape(string $string): string { 74 | return \SQLite3::escapeString($string); 75 | } 76 | 77 | /** 78 | * @param IPlayer $player 79 | * 80 | * @return bool 81 | */ 82 | public function addPlayer(IPlayer $player): bool { 83 | if($this->playerExists($player)) { 84 | return false; 85 | } 86 | $player = strtolower($player->getName()); 87 | $query = "INSERT INTO QuestStats(Player, StartedQuests, FinishedQuests) VALUES ('" . $this->escape($player) . "', 0, 0)"; 88 | return $this->database->exec($query); 89 | } 90 | 91 | /** 92 | * @param IPlayer $player 93 | * 94 | * @return bool 95 | */ 96 | public function playerExists(IPlayer $player): bool { 97 | $player = strtolower($player->getName()); 98 | $query = "SELECT * FROM QuestStats WHERE Player = '" . $this->escape($player) . "'"; 99 | 100 | $result = $this->database->query($query)->fetchArray(SQLITE3_ASSOC); 101 | if(empty($result)) { 102 | return false; 103 | } 104 | return true; 105 | } 106 | 107 | /** 108 | * @param IPlayer $player 109 | * @param string $serializedData 110 | * 111 | * @return bool 112 | */ 113 | public function updateStartedQuests(IPlayer $player, string $serializedData): bool { 114 | if(!$this->playerExists($player)) { 115 | return false; 116 | } 117 | $player = strtolower($player->getName()); 118 | $query = "UPDATE QuestStats SET StartedQuests = '" . $this->escape($serializedData) . "' WHERE Player = '" . $this->escape($player) . "'"; 119 | return $this->database->exec($query); 120 | } 121 | 122 | /** 123 | * @param IPlayer $player 124 | * @param string $serializedData 125 | * 126 | * @return bool 127 | */ 128 | public function updateFinishedQuests(IPlayer $player, string $serializedData): bool { 129 | if(!$this->playerExists($player)) { 130 | return false; 131 | } 132 | $player = strtolower($player->getName()); 133 | $query = "UPDATE QuestStats SET FinishedQuests = '" . $this->escape($serializedData) . "' WHERE Player = '" . $this->escape($player) . "'"; 134 | return $this->database->exec($query); 135 | } 136 | 137 | /** 138 | * @param IPlayer $player 139 | * 140 | * @return bool 141 | */ 142 | public function clearData(IPlayer $player): bool { 143 | if(!$this->playerExists($player)) { 144 | return false; 145 | } 146 | $player = strtolower($player->getName()); 147 | $query = "DELETE FROM QuestStats WHERE Player = '" . $this->escape($player) . "'"; 148 | return $this->database->exec($query); 149 | } 150 | 151 | /** 152 | * @param IPlayer $player 153 | * @param int $questId 154 | * 155 | * @return bool 156 | */ 157 | public function hasQuestFinished(IPlayer $player, int $questId): bool { 158 | if(!$this->playerExists($player)) { 159 | return false; 160 | } 161 | foreach($this->getFinishedQuests($player) as $quest) { 162 | if($quest->getId() === $questId) { 163 | return true; 164 | } 165 | } 166 | return false; 167 | } 168 | 169 | /** 170 | * @param IPlayer $player 171 | * @param int $questId 172 | * 173 | * @return bool 174 | */ 175 | public function hasQuestStarted(IPlayer $player, int $questId): bool { 176 | if(!$this->playerExists($player)) { 177 | return false; 178 | } 179 | foreach($this->getStartedQuests($player) as $quest) { 180 | if($quest->getId() === $questId) { 181 | return true; 182 | } 183 | } 184 | return false; 185 | } 186 | } -------------------------------------------------------------------------------- /src/BlockHorizons/BlockQuests/gui/BaseGui.php: -------------------------------------------------------------------------------- 1 | questId = $questId; 39 | $this->plugin = $plugin; 40 | $this->player = $player; 41 | } 42 | 43 | /** 44 | * @return string 45 | */ 46 | public function getInitializeMessage(): string { 47 | return $this->initMessage; 48 | } 49 | 50 | /** 51 | * @return string 52 | */ 53 | public function getFinalizeMessage(): string { 54 | return $this->finishMessage; 55 | } 56 | 57 | /** 58 | * @return Player 59 | */ 60 | public function getPlayer(): Player { 61 | return $this->player; 62 | } 63 | 64 | /** 65 | * @return int 66 | */ 67 | public function getPage(): int { 68 | return $this->page; 69 | } 70 | 71 | /** 72 | * @param int $pageNumber 73 | * 74 | * @return bool 75 | */ 76 | public function goToPage(int $pageNumber): bool { 77 | if($pageNumber < 1 || $pageNumber > count($this->defaults["dynamic"])) { 78 | return false; 79 | } 80 | $this->getPlugin()->getGuiHandler()->allowInventoryChange = true; 81 | foreach($this->defaults["dynamic"][$pageNumber - 1] as $slot => $item) { 82 | $this->player->getInventory()->setItem($slot, $item); 83 | } 84 | $this->getPlugin()->getGuiHandler()->allowInventoryChange = false; 85 | $this->page = $pageNumber; 86 | $this->player->sendTip(TextFormat::GREEN . TextFormat::BOLD . "[" . $pageNumber . "/" . count($this->defaults["dynamic"]) . "]"); 87 | return true; 88 | } 89 | 90 | /** 91 | * @return BlockQuests 92 | */ 93 | public function getPlugin(): BlockQuests { 94 | return $this->plugin; 95 | } 96 | 97 | public function openGui(): void { 98 | $this->sendInitial(); 99 | $this->player->sendTip($this->initMessage); 100 | $this->player->sendMessage($this->initMessage); 101 | $this->getPlugin()->getGuiHandler()->setUsingGui($this->player, true, $this); 102 | } 103 | 104 | protected function sendInitial(): void { 105 | $this->previousContents = $this->player->getInventory()->getContents(); 106 | $this->player->getInventory()->clearAll(); 107 | 108 | foreach($this->defaults["static"] as $slot => $item) { 109 | $this->player->getInventory()->setItem($slot, $item); 110 | } 111 | foreach($this->defaults["dynamic"][0] as $slot => $item) { 112 | $this->player->getInventory()->setItem($slot, $item); 113 | } 114 | } 115 | 116 | /** 117 | * @param bool $cancelled 118 | */ 119 | public function closeGui(bool $cancelled = true): void { 120 | $this->player->getInventory()->setContents($this->previousContents); 121 | 122 | if(!$cancelled && isset($this->quest)) { 123 | $this->quest->store(); 124 | } 125 | $this->player->sendTip($this->finishMessage); 126 | } 127 | 128 | /** 129 | * @param Item $item 130 | * @param mixed $value 131 | * 132 | * @return bool 133 | */ 134 | public function callBackGuiItem(Item $item, $value): bool { 135 | if(!isset($this->quest)) { 136 | $this->quest = new Quest($this->questId); 137 | } 138 | if($item->getNamedTag()->bqGuiInputMode->getValue() === "") { 139 | return false; 140 | } 141 | $this->quest->{$item->getNamedTag()->bqGuiInputMode->getValue()} = $value; 142 | return true; 143 | } 144 | } 145 | -------------------------------------------------------------------------------- /src/BlockHorizons/BlockQuests/gui/GuiHandler.php: -------------------------------------------------------------------------------- 1 | plugin = $plugin; 21 | } 22 | 23 | /** 24 | * @return BlockQuests 25 | */ 26 | public function getPlugin(): BlockQuests { 27 | return $this->plugin; 28 | } 29 | 30 | /** 31 | * @param Player $player 32 | * @param bool $value 33 | * @param BaseGui $gui 34 | * @param bool $finishCancelled 35 | */ 36 | public function setUsingGui(Player $player, bool $value = true, BaseGui $gui, bool $finishCancelled = true): void { 37 | $this->usingGui[$player->getId()] = $value; 38 | 39 | if($value === true) { 40 | $this->gui[] = $gui; 41 | } else { 42 | $gui = $this->gui[$this->getGuiIdByPlayer($player)]; 43 | if($gui instanceof BaseGui) { 44 | $gui->closeGui($finishCancelled); 45 | } 46 | unset($this->gui[$this->getGuiIdByPlayer($player)]); 47 | } 48 | } 49 | 50 | /** 51 | * @param Player $player 52 | * 53 | * @return int 54 | */ 55 | public function getGuiIdByPlayer(Player $player): ?int { 56 | /** 57 | * @var int $id 58 | * @var BaseGui $gui 59 | */ 60 | foreach($this->gui as $id => $gui) { 61 | if($gui->getPlayer()->getName() === $player->getName()) { 62 | return $id; 63 | } 64 | } 65 | return null; 66 | } 67 | 68 | /** 69 | * @param Player $player 70 | * 71 | * @return bool 72 | */ 73 | public function isUsingGui(Player $player): bool { 74 | return isset($this->usingGui[$player->getId()]) && $this->usingGui[$player->getId()] === true; 75 | } 76 | 77 | /** 78 | * @param Player $player 79 | * 80 | * @return BaseGui|null 81 | */ 82 | public function getGui(Player $player): ?BaseGui { 83 | return $this->getGuiById($this->getGuiIdByPlayer($player)); 84 | } 85 | 86 | /** 87 | * @param int $id 88 | * 89 | * @return BaseGui|null 90 | */ 91 | public function getGuiById(int $id): ?BaseGui { 92 | return isset($this->gui[$id]) ? $this->gui[$id] : null; 93 | } 94 | } -------------------------------------------------------------------------------- /src/BlockHorizons/BlockQuests/gui/GuiUtils.php: -------------------------------------------------------------------------------- 1 | setCustomName(TextFormat::GREEN . $customName); 69 | } 70 | if(!empty($lore)) { 71 | $item->setLore($lore); 72 | } 73 | $nbt = $item->getNamedTag() ?? new CompoundTag("", []); 74 | $nbt->bqGuiInputType = new IntTag("bqGuiInputType", $type); 75 | $nbt->bqGuiInputMode = new StringTag("bqGuiInputMode", $mode); 76 | $item->setNamedTag($nbt); 77 | return $item; 78 | } 79 | } -------------------------------------------------------------------------------- /src/BlockHorizons/BlockQuests/gui/types/QuestCreatingGui.php: -------------------------------------------------------------------------------- 1 | defaults = [ 22 | "static" => [ 23 | 0 => GuiUtils::item(GuiUtils::RED, "Cancel", ["Cancels the progress of creating this quest"], GuiUtils::TYPE_CANCEL), 24 | 1 => GuiUtils::item(GuiUtils::LIME, "Finalize", ["Finalizes this quest to process all input data"], GuiUtils::TYPE_FINALIZE), 25 | 2 => Item::get(Item::AIR), 26 | 3 => GuiUtils::item(GuiUtils::WHITE, "Previous", ["Goes to the previous page"], GuiUtils::TYPE_PREVIOUS), 27 | 8 => GuiUtils::item(GuiUtils::WHITE, "Next", ["Goes to the next page"], GuiUtils::TYPE_NEXT) 28 | ], 29 | "dynamic" => [ 30 | 0 => [ 31 | 4 => GuiUtils::item(GuiUtils::CYAN, "Quest Name", ["The name the quest will have"], GuiUtils::TYPE_ENTER_TEXT, GuiUtils::MODE_QUEST_NAME), 32 | 5 => GuiUtils::item(GuiUtils::ORANGE, "Quest Description", ["The description of the quest"], GuiUtils::TYPE_ENTER_TEXT, GuiUtils::MODE_QUEST_DESCRIPTION), 33 | 6 => GuiUtils::item(GuiUtils::GREEN, "Starting Message", ["The message shown on initial quest start"], GuiUtils::TYPE_ENTER_TEXT, GuiUtils::MODE_STARTING_MESSAGE), 34 | 7 => GuiUtils::item(GuiUtils::BLUE, "Started Message", ["The message shown when this quest has already been started"], GuiUtils::TYPE_ENTER_TEXT, GuiUtils::MODE_STARTED_MESSAGE) 35 | ], 36 | 1 => [ 37 | 4 => GuiUtils::item(GuiUtils::GREEN, "Finishing Message", ["The message shown when finishing this quest"], GuiUtils::TYPE_ENTER_TEXT, GuiUtils::MODE_FINISHING_MESSAGE), 38 | 5 => GuiUtils::item(GuiUtils::MAGENTA, "Finished Message", ["The message shown when this quest has already been finished"], GuiUtils::TYPE_ENTER_TEXT, GuiUtils::MODE_FINISHED_MESSAGE), 39 | 6 => GuiUtils::item(GuiUtils::YELLOW, "Required Starting Experience", ["The required experience level a player needs to start this quest"], GuiUtils::TYPE_ENTER_INT, GuiUtils::MODE_START_EXPERIENCE_LEVEL), 40 | 7 => GuiUtils::item(GuiUtils::ORANGE, "Required Starting Items", ["The items required to start this quest"], GuiUtils::TYPE_ENTER_ITEMS, GuiUtils::MODE_START_REQUIRED_ITEMS) 41 | ], 42 | 2 => [ 43 | 4 => GuiUtils::item(GuiUtils::PINK, "Required Finishing Items", ["The items required to finish this quest"], GuiUtils::TYPE_ENTER_ITEMS, GuiUtils::MODE_FINISH_REQUIRED_ITEMS), 44 | 5 => GuiUtils::item(GuiUtils::LIGHT_BLUE, "Reward Commands", ["The commands executed when finishing this quest"], GuiUtils::TYPE_ENTER_COMMANDS, GuiUtils::MODE_REWARD_COMMANDS), 45 | 6 => GuiUtils::item(GuiUtils::ORANGE, "Insufficient Experience Message", ["The message sent if the player has too little experience to start"], GuiUtils::TYPE_ENTER_TEXT, GuiUtils::MODE_INSUFFICIENT_START_EXPERIENCE_MESSAGE), 46 | 7 => GuiUtils::item(GuiUtils::LIME, "Missing Starting Items Message", ["The message sent if the player does not have the required starting items"], GuiUtils::TYPE_ENTER_TEXT, GuiUtils::MODE_MISSING_START_ITEMS_MESSAGE) 47 | ] 48 | ] 49 | ]; 50 | } 51 | } -------------------------------------------------------------------------------- /src/BlockHorizons/BlockQuests/gui/types/QuestEditingGui.php: -------------------------------------------------------------------------------- 1 | quest = $this->getPlugin()->getQuestStorage()->fetch($questId); 20 | $this->defaults["static"][0] = GuiUtils::item(GuiUtils::RED, "Cancel", ["Cancels the editing of this quest"], GuiUtils::TYPE_CANCEL); 21 | $this->defaults["static"][1] = GuiUtils::item(GuiUtils::LIME, "Save", ["Saves this quest and finalizes input data"], GuiUtils::TYPE_FINALIZE); 22 | } 23 | } -------------------------------------------------------------------------------- /src/BlockHorizons/BlockQuests/listeners/EventListener.php: -------------------------------------------------------------------------------- 1 | plugin = $plugin; 17 | } 18 | 19 | /** 20 | * @param PlayerJoinEvent $event 21 | */ 22 | public function onJoin(PlayerJoinEvent $event): void { 23 | $this->getPlugin()->getPlayerDatabase()->addPlayer($event->getPlayer()); 24 | } 25 | 26 | /** 27 | * @return BlockQuests 28 | */ 29 | public function getPlugin(): BlockQuests { 30 | return $this->plugin; 31 | } 32 | } -------------------------------------------------------------------------------- /src/BlockHorizons/BlockQuests/listeners/GuiListener.php: -------------------------------------------------------------------------------- 1 | plugin = $plugin; 25 | } 26 | 27 | /** 28 | * @param PlayerChatEvent $event 29 | */ 30 | public function onChat(PlayerChatEvent $event): void { 31 | if($this->getPlugin()->getGuiHandler()->isUsingGui($event->getPlayer())) { 32 | $output = null; 33 | $gui = $this->getPlugin()->getGuiHandler()->getGui($event->getPlayer()); 34 | $item = $event->getPlayer()->getInventory()->getItemInHand(); 35 | $input = $event->getMessage(); 36 | if(isset($item->getNamedTag()->bqGuiInputType)) { 37 | switch($item->getNamedTag()->bqGuiInputType->getValue()) { 38 | case GuiUtils::TYPE_ENTER_ITEMS: 39 | $nameList = []; 40 | $inputRaw = explode(",", $input); 41 | $inputItems = []; 42 | foreach($inputRaw as $inputItem) { 43 | if(is_numeric($inputItem)) { 44 | $inputItems[] = Item::get((int) $inputItem); 45 | } else { 46 | $inputItems[] = Item::fromString($inputItem); 47 | } 48 | } 49 | foreach($inputItems as $inputItem) { 50 | $nameList[] = $inputItem->getName(); 51 | $output[] = (string) $inputItem->getId() . ":" . (string) $inputItem->getDamage() . ":" . (string) $inputItem->getCount(); 52 | } 53 | $event->getPlayer()->sendMessage(TextFormat::GREEN . "Input Items: " . TextFormat::AQUA . implode(", ", $nameList)); 54 | break; 55 | case GuiUtils::TYPE_ENTER_INT: 56 | if(!is_numeric($input)) { 57 | $output = 0; 58 | } else { 59 | $output = (int) $input; 60 | } 61 | $event->getPlayer()->sendMessage(TextFormat::GREEN . "Input Integer: " . TextFormat::AQUA . (string) $output); 62 | break; 63 | case GuiUtils::TYPE_ENTER_TEXT: 64 | $output = (string) $input; 65 | $event->getPlayer()->sendMessage(TextFormat::GREEN . "Input Text: " . TextFormat::AQUA . $output); 66 | break; 67 | case GuiUtils::TYPE_ENTER_COMMANDS: 68 | $inputCommands = explode(",", $input); 69 | $event->getPlayer()->sendMessage(TextFormat::GREEN . "Input Commands: " . TextFormat::AQUA . "/" . implode(", /", $inputCommands)); 70 | foreach($inputCommands as $inputCommand) { 71 | $output[] = $inputCommand; 72 | } 73 | break; 74 | } 75 | } 76 | $gui->callBackGuiItem($item, $output); 77 | $event->setCancelled(); 78 | } 79 | } 80 | 81 | /** 82 | * @return BlockQuests 83 | */ 84 | public function getPlugin(): BlockQuests { 85 | return $this->plugin; 86 | } 87 | 88 | /** 89 | * @param PlayerItemHeldEvent $event 90 | */ 91 | public function onItemHeld(PlayerItemHeldEvent $event): void { 92 | if($this->getPlugin()->getGuiHandler()->isUsingGui($event->getPlayer())) { 93 | if(!isset($event->getItem()->getNamedTag()->bqGuiInputType)) { 94 | return; 95 | } 96 | switch($event->getItem()->getNamedTag()->bqGuiInputType->getValue()) { 97 | default: 98 | case GuiUtils::TYPE_CANCEL: 99 | $message = TextFormat::GREEN . "Tap the ground to cancel."; 100 | break; 101 | case GuiUtils::TYPE_FINALIZE: 102 | $message = TextFormat::GREEN . "Tap the ground to finalize."; 103 | break; 104 | case GuiUtils::TYPE_NEXT: 105 | $message = TextFormat::GREEN . "Tap the ground to go to the next page."; 106 | break; 107 | case GuiUtils::TYPE_PREVIOUS: 108 | $message = TextFormat::GREEN . "Tap the ground to go to the previous page."; 109 | break; 110 | case GuiUtils::TYPE_ENTER_ITEMS: 111 | $message = TextFormat::GREEN . "Enter an item in the chat. Separate multiple with commas."; 112 | break; 113 | case GuiUtils::TYPE_ENTER_INT: 114 | $message = TextFormat::GREEN . "Enter a numeric value in the chat."; 115 | break; 116 | case GuiUtils::TYPE_ENTER_TEXT: 117 | $message = TextFormat::GREEN . "Enter a text in the chat."; 118 | break; 119 | case GuiUtils::TYPE_ENTER_COMMANDS: 120 | $message = TextFormat::GREEN . "Enter a command in the chat without slash. Separate multiple with commas."; 121 | break; 122 | } 123 | $event->getPlayer()->sendTip($message); 124 | } 125 | } 126 | 127 | /** 128 | * @param EntityInventoryChangeEvent $event 129 | */ 130 | public function onInventoryChange(EntityInventoryChangeEvent $event): void { 131 | $player = $event->getEntity(); 132 | if($player instanceof Player) { 133 | if($this->getPlugin()->getGuiHandler()->isUsingGui($player)) { 134 | if($this->getPlugin()->getGuiHandler()->allowInventoryChange) { 135 | return; 136 | } 137 | $event->setCancelled(); 138 | } 139 | } 140 | } 141 | 142 | /** 143 | * @param PlayerQuitEvent $event 144 | */ 145 | public function onQuit(PlayerQuitEvent $event): void { 146 | if($this->getPlugin()->getGuiHandler()->isUsingGui($event->getPlayer())) { 147 | $this->getPlugin()->getGuiHandler()->setUsingGui($event->getPlayer(), false, $this->getPlugin()->getGuiHandler()->getGui($event->getPlayer())); 148 | } 149 | } 150 | 151 | /** 152 | * @param PlayerInteractEvent $event 153 | */ 154 | public function onInteract(PlayerInteractEvent $event): void { 155 | if($this->getPlugin()->getGuiHandler()->isUsingGui($event->getPlayer())) { 156 | $gui = $this->getPlugin()->getGuiHandler()->getGui($event->getPlayer()); 157 | switch($event->getItem()->getNamedTag()->bqGuiInputType->getValue()) { 158 | case GuiUtils::TYPE_CANCEL: 159 | $this->getPlugin()->getGuiHandler()->setUsingGui($event->getPlayer(), false, $gui, true); 160 | break; 161 | case GuiUtils::TYPE_FINALIZE: 162 | $this->getPlugin()->getGuiHandler()->setUsingGui($event->getPlayer(), false, $gui, false); 163 | break; 164 | case GuiUtils::TYPE_NEXT: 165 | $this->getPlugin()->getGuiHandler()->getGui($event->getPlayer())->goToPage($gui->getPage() + 1); 166 | break; 167 | case GuiUtils::TYPE_PREVIOUS: 168 | $this->getPlugin()->getGuiHandler()->getGui($event->getPlayer())->goToPage($gui->getPage() - 1); 169 | break; 170 | } 171 | $event->setCancelled(); 172 | } 173 | } 174 | } -------------------------------------------------------------------------------- /src/BlockHorizons/BlockQuests/quests/Quest.php: -------------------------------------------------------------------------------- 1 | id = $id; 52 | foreach($data as $key => $value) { 53 | $this->{$key} = $value; 54 | } 55 | } 56 | 57 | /** 58 | * @return int 59 | */ 60 | public function getId(): int { 61 | return $this->id; 62 | } 63 | 64 | /** 65 | * @return string 66 | */ 67 | public function getQuestName(): string { 68 | return $this->questName; 69 | } 70 | 71 | /** 72 | * @param string $name 73 | */ 74 | public function setQuestName(string $name): void { 75 | $this->questName = $name; 76 | } 77 | 78 | /** 79 | * @return string 80 | */ 81 | public function getQuestDescription(): string { 82 | return $this->questDescription; 83 | } 84 | 85 | /** 86 | * @param string $description 87 | */ 88 | public function setQuestDescription(string $description): void { 89 | $this->questDescription = $description; 90 | } 91 | 92 | /** 93 | * @return int 94 | */ 95 | public function getStartExperienceLevel(): int { 96 | return $this->startExperienceLevel; 97 | } 98 | 99 | /** 100 | * @param int $level 101 | */ 102 | public function setStartExperienceLevel(int $level): void { 103 | $this->startExperienceLevel = $level; 104 | } 105 | 106 | /** 107 | * @return string[] 108 | */ 109 | public function getRewardCommands(): array { 110 | return $this->rewardCommands; 111 | } 112 | 113 | /** 114 | * @param string[] $commands 115 | */ 116 | public function setRewardCommands(array $commands): void { 117 | $this->rewardCommands = $commands; 118 | } 119 | 120 | /** 121 | * @return string 122 | */ 123 | public function getStartingMessage(): string { 124 | return $this->startingMessage; 125 | } 126 | 127 | /** 128 | * @param string $message 129 | */ 130 | public function setStartingMessage(string $message): void { 131 | $this->startingMessage = $message; 132 | } 133 | 134 | /** 135 | * @return string 136 | */ 137 | public function getFinishingMessage(): string { 138 | return $this->finishingMessage; 139 | } 140 | 141 | /** 142 | * @param string $message 143 | */ 144 | public function setFinishingMessage(string $message): void { 145 | $this->finishingMessage = $message; 146 | } 147 | 148 | /** 149 | * @return string 150 | */ 151 | public function getStartedMessage(): string { 152 | return $this->startedMessage; 153 | } 154 | 155 | /** 156 | * @param string $message 157 | */ 158 | public function setStartedMessage(string $message): void { 159 | $this->startedMessage = $message; 160 | } 161 | 162 | /** 163 | * @return string 164 | */ 165 | public function getFinishedMessage(): string { 166 | return $this->finishedMessage; 167 | } 168 | 169 | /** 170 | * @param string $message 171 | */ 172 | public function setFinishedMessage(string $message): void { 173 | $this->finishedMessage = $message; 174 | } 175 | 176 | /** 177 | * @return string 178 | */ 179 | public function getMissingStartItemsMessage(): string { 180 | return $this->missingStartItemsMessage; 181 | } 182 | 183 | /** 184 | * @param string $message 185 | */ 186 | public function setMissingStartItemsMessage(string $message): void { 187 | $this->missingStartItemsMessage = $message; 188 | } 189 | 190 | /** 191 | * @return string 192 | */ 193 | public function getInsufficientStartExperienceMessage(): string { 194 | return $this->insufficientStartExperienceMessage; 195 | } 196 | 197 | /** 198 | * @param string $message 199 | */ 200 | public function setInsufficientStartExperienceMessage(string $message): void { 201 | $this->insufficientStartExperienceMessage = $message; 202 | } 203 | 204 | /** 205 | * @return bool 206 | */ 207 | public function store(): bool { 208 | /** @var BlockQuests $plugin */ 209 | $plugin = Server::getInstance()->getPluginManager()->getPlugin("BlockQuests"); 210 | $plugin->getQuestStorage()->store($this); 211 | return true; 212 | } 213 | 214 | /** 215 | * @return array 216 | */ 217 | public function parse(): array { 218 | $data = []; 219 | foreach($this as $key => $value) { 220 | if($key === "id") { 221 | continue; 222 | } 223 | $data[$key] = $value; 224 | } 225 | return $data; 226 | } 227 | 228 | /** 229 | * @param Player $player 230 | * 231 | * @return bool 232 | */ 233 | public function checkStartingExperience(Player $player): bool { 234 | if($player->getXpLevel() >= $this->startExperienceLevel) { 235 | return true; 236 | } 237 | return false; 238 | } 239 | 240 | /** 241 | * @param Player $player 242 | * 243 | * @return bool 244 | */ 245 | public function checkStartingItems(Player $player): bool { 246 | foreach($this->getStartRequiredItems() as $item) { 247 | if(!$player->getInventory()->contains($item)) { 248 | return false; 249 | } 250 | } 251 | return true; 252 | } 253 | 254 | /** 255 | * @return Item[] 256 | */ 257 | public function getStartRequiredItems(): array { 258 | $items = []; 259 | foreach($this->startRequiredItems as $item) { 260 | $items[] = Item::fromString($item); 261 | } 262 | return $items; 263 | } 264 | 265 | /** 266 | * @param string[] $items 267 | */ 268 | public function setStartRequiredItems(array $items): void { 269 | $this->startRequiredItems = $items; 270 | } 271 | 272 | /** 273 | * @param Player $player 274 | * 275 | * @return bool 276 | */ 277 | public function checkFinishingItems(Player $player): bool { 278 | foreach($this->getFinishRequiredItems() as $item) { 279 | if(!$player->getInventory()->contains($item)) { 280 | return false; 281 | } 282 | } 283 | return true; 284 | } 285 | 286 | /** 287 | * @return Item[] 288 | */ 289 | public function getFinishRequiredItems(): array { 290 | $items = []; 291 | foreach($this->finishRequiredItems as $item) { 292 | $items[] = Item::fromString($item); 293 | } 294 | return $items; 295 | } 296 | 297 | /** 298 | * @param string[] $items 299 | */ 300 | public function setFinishRequiredItems(array $items): void { 301 | $this->finishRequiredItems = $items; 302 | } 303 | } -------------------------------------------------------------------------------- /src/BlockHorizons/BlockQuests/quests/QuestManager.php: -------------------------------------------------------------------------------- 1 | plugin = $plugin; 21 | } 22 | 23 | /** 24 | * @return Quest[] 25 | */ 26 | public function getQuestList(): array { 27 | $quests = []; 28 | foreach(scandir($this->plugin->getDataFolder() . "quests/") as $quest) { 29 | $path = $this->plugin->getDataFolder() . "quests/" . $quest; 30 | if($quest === "." || $quest === "..") { 31 | continue; 32 | } 33 | $questId = explode(".", $quest)[0]; 34 | if(!is_file($path) || !is_numeric($questId)) { 35 | continue; 36 | } 37 | $data = yaml_parse_file($path); 38 | if((new QuestValidator($data))->getResult() === false) { 39 | $this->plugin->getLogger()->debug("Invalid quest content file '" . $quest . "' found. Skipping..."); 40 | continue; 41 | } 42 | $quests[] = $this->getQuestById((int) $questId); 43 | } 44 | return $quests; 45 | } 46 | 47 | /** 48 | * @param int $id 49 | * 50 | * @return Quest 51 | */ 52 | public function getQuestById(int $id): Quest { 53 | if(!isset($this->quests[$id])) { 54 | $this->quests[$id] = $this->plugin->getQuestStorage()->fetch($id); 55 | } 56 | return $this->quests[$id]; 57 | } 58 | 59 | /** 60 | * @param Quest $quest 61 | * @param Player $player 62 | * 63 | * @return bool 64 | */ 65 | public function startQuest(Quest $quest, Player $player): bool { 66 | $message = $this->getPlugin()->getBlockQuestsConfig()->getQuestStartingFormat(); 67 | $processedMessage = str_replace("{STARTING_MESSAGE}", $quest->getStartingMessage() . TF::GREEN . TF::BOLD, str_replace("{QUEST_NAME}", TF::RESET . TF::AQUA . $quest->getQuestName(), str_replace("{QUEST_DESCRIPTION}", TF::GRAY . $quest->getQuestDescription(), $message))); 68 | $player->sendMessage(TF::GREEN . $processedMessage); 69 | $this->getPlugin()->getPlayerDatabase()->startQuest($player, $quest->getId()); 70 | return true; 71 | } 72 | 73 | /** 74 | * @return BlockQuests 75 | */ 76 | public function getPlugin(): BlockQuests { 77 | return $this->plugin; 78 | } 79 | 80 | /** 81 | * @param Quest $quest 82 | * @param Player $player 83 | * 84 | * @return bool 85 | */ 86 | public function finishQuest(Quest $quest, Player $player): bool { 87 | $player->sendMessage(TF::GREEN . $quest->getFinishingMessage()); 88 | $this->getPlugin()->getPlayerDatabase()->finishQuest($player, $quest->getId()); 89 | foreach($quest->getRewardCommands() as $command) { 90 | $this->getPlugin()->getServer()->dispatchCommand(new ConsoleCommandSender(), str_replace("{PLAYER}", $player->getName(), $command)); 91 | } 92 | return true; 93 | } 94 | 95 | /** 96 | * @param int $id 97 | * 98 | * @return bool 99 | */ 100 | public function questExists(int $id): bool { 101 | return $this->getPlugin()->getQuestStorage()->exists($id); 102 | } 103 | 104 | /** 105 | * @param int $id 106 | * 107 | * @return bool 108 | */ 109 | public function deleteQuest(int $id): bool { 110 | unset($this->quests[$id]); 111 | if($this->getPlugin()->getQuestStorage()->exists($id)) { 112 | $this->getPlugin()->getQuestStorage()->delete($id); 113 | return true; 114 | } 115 | return false; 116 | } 117 | } -------------------------------------------------------------------------------- /src/BlockHorizons/BlockQuests/quests/QuestValidator.php: -------------------------------------------------------------------------------- 1 | result = false; 27 | } else { 28 | $this->result = true; 29 | } 30 | } 31 | 32 | public function getResult(): bool { 33 | return $this->result; 34 | } 35 | } -------------------------------------------------------------------------------- /src/BlockHorizons/BlockQuests/quests/storage/JsonQuestStorage.php: -------------------------------------------------------------------------------- 1 | exists($quest->getId())) { 19 | $return = true; 20 | } 21 | $folder = $this->getPlugin()->getDataFolder(); 22 | file_put_contents($folder . "quests/" . (string) $quest->getId() . ".json", json_encode($quest->parse())); 23 | return $return; 24 | } 25 | 26 | /** 27 | * @param int $questId 28 | * 29 | * @return bool 30 | */ 31 | public function exists(int $questId): bool { 32 | if(file_exists($this->getPlugin()->getDataFolder() . "quests/" . (string) $questId . ".json")) { 33 | return true; 34 | } 35 | return false; 36 | } 37 | 38 | /** 39 | * @param int $questId 40 | * 41 | * @return Quest 42 | */ 43 | public function fetch(int $questId): Quest { 44 | if(!$this->exists($questId)) { 45 | return new Quest($questId); 46 | } 47 | $folder = $this->getPlugin()->getDataFolder(); 48 | $data = json_decode(file_get_contents($folder . "quests/" . (string) $questId . ".json"), true); 49 | return new Quest($questId, $data); 50 | } 51 | 52 | /** 53 | * @param int $questId 54 | * 55 | * @return bool 56 | */ 57 | public function delete(int $questId): bool { 58 | if(!$this->exists($questId)) { 59 | return false; 60 | } 61 | unlink($this->getPlugin()->getDataFolder() . "quests/" . (string) $questId . ".json"); 62 | return true; 63 | } 64 | } -------------------------------------------------------------------------------- /src/BlockHorizons/BlockQuests/quests/storage/QuestStorage.php: -------------------------------------------------------------------------------- 1 | plugin = $plugin; 16 | } 17 | 18 | /** 19 | * @return BlockQuests 20 | */ 21 | public function getPlugin(): BlockQuests { 22 | return $this->plugin; 23 | } 24 | 25 | /** 26 | * @param Quest $quest 27 | * 28 | * @return bool 29 | */ 30 | public abstract function store(Quest $quest): bool; 31 | 32 | /** 33 | * @param int $questId 34 | * 35 | * @return Quest 36 | */ 37 | public abstract function fetch(int $questId): Quest; 38 | 39 | /** 40 | * @param int $questId 41 | * 42 | * @return bool 43 | */ 44 | public abstract function delete(int $questId): bool; 45 | 46 | /** 47 | * @param int $questId 48 | * 49 | * @return bool 50 | */ 51 | public abstract function exists(int $questId): bool; 52 | } -------------------------------------------------------------------------------- /src/BlockHorizons/BlockQuests/quests/storage/YamlQuestStorage.php: -------------------------------------------------------------------------------- 1 | exists($quest->getId())) { 19 | $return = true; 20 | } 21 | $folder = $this->getPlugin()->getDataFolder(); 22 | yaml_emit_file($folder . "quests/" . (string) $quest->getId() . ".yml", $quest->parse()); 23 | return $return; 24 | } 25 | 26 | /** 27 | * @param int $questId 28 | * 29 | * @return bool 30 | */ 31 | public function exists(int $questId): bool { 32 | if(file_exists($this->getPlugin()->getDataFolder() . "quests/" . (string) $questId . ".yml")) { 33 | return true; 34 | } 35 | return false; 36 | } 37 | 38 | /** 39 | * @param int $questId 40 | * 41 | * @return Quest 42 | */ 43 | public function fetch(int $questId): Quest { 44 | if(!$this->exists($questId)) { 45 | return new Quest($questId); 46 | } 47 | $folder = $this->getPlugin()->getDataFolder(); 48 | $data = yaml_parse_file($folder . "quests/" . (string) $questId . ".yml"); 49 | return new Quest($questId, $data); 50 | } 51 | 52 | /** 53 | * @param int $questId 54 | * 55 | * @return bool 56 | */ 57 | public function delete(int $questId): bool { 58 | if(!$this->exists($questId)) { 59 | return false; 60 | } 61 | unlink($this->getPlugin()->getDataFolder() . "quests/" . (string) $questId . ".yml"); 62 | return true; 63 | } 64 | } --------------------------------------------------------------------------------