├── .github └── ISSUE_TEMPLATE │ ├── bug_report.md │ └── suggestion.md ├── .gitignore ├── .poggit.yml ├── LICENSE ├── README.md ├── composer.json ├── composer.lock ├── icon.png ├── phpstan.neon.dist ├── plugin.yml ├── resources ├── config.yml ├── help_eng.txt ├── help_fra.txt ├── help_spa.txt ├── messages.yml └── provider │ ├── mysql.sql │ └── sqlite.sql └── src ├── Arena.php ├── CommandHandler.php ├── EventHandler.php ├── Events ├── ArenaAddPlayerEvent.php ├── ArenaCreateEvent.php ├── ArenaDeleteEvent.php ├── ArenaEndEvent.php ├── ArenaPreStartEvent.php ├── ArenaRemovePlayerEvent.php ├── ArenaStartEvent.php └── KothEvent.php ├── Main.php ├── Particles └── FloatingText.php ├── Providers ├── BaseProvider.php └── SqlProvider.php ├── Tasks ├── CheckUpdate.php ├── GameTimer.php └── StartCountdown.php └── Utils.php /.github/ISSUE_TEMPLATE/bug_report.md: -------------------------------------------------------------------------------- 1 | --- 2 | name: Bug report 3 | about: Create a report to help us improve/fix a issue. 4 | title: "[Bug Report] IssueNameHere" 5 | labels: 'Status: Unconfirmed, Type: Bug/Issue' 6 | assignees: '' 7 | 8 | --- 9 | 10 | **Describe the bug in detail** 11 | A clear and in depth description of the bug. 12 | 13 | **To Reproduce** 14 | Steps to reproduce the behaviour: 15 | 1. Go to '...' 16 | 2. Click on '....' 17 | 3. Server crash 18 | 4. See error 19 | etc. 20 | 21 | **Expected behaviour** 22 | A clear and concise description of what you expected to happen. 23 | 24 | **Actual behaviour** 25 | What actually happens. 26 | 27 | **Screenshots** 28 | Add screenshots to help explain your problem. 29 | 30 | **Host (please complete the following information):** 31 | - OS: [e.g. Windows10] 32 | - PocketMine Version: [e.g. 3.9.0] 33 | - Plugin Version [e.g. 1.0.0-Beta3] 34 | 35 | **Player Device (If applicable | please complete the following information):** 36 | - Device: [e.g. iPhone6] 37 | - OS: [e.g. iOS12.1] 38 | - MCPE Version [e.g. 1.12.0] 39 | 40 | **Server Log (IMPORTANT)** 41 | Please have both pmmp's debug option set to '2' and koth's debug option enabled. 42 | Please paste your server.log content using https://pastebin.com 43 | 44 | **Additional context/notes** 45 | Add any other context/notes about the problem here. 46 | -------------------------------------------------------------------------------- /.github/ISSUE_TEMPLATE/suggestion.md: -------------------------------------------------------------------------------- 1 | --- 2 | name: Suggestion 3 | about: Suggest an idea for this project 4 | title: "[Suggestion]" 5 | labels: 'Type: Suggestion' 6 | assignees: '' 7 | 8 | --- 9 | 10 | **Is your feature request related to a problem? Please describe.** 11 | A clear and concise description of what the problem is. Ex. I'm always frustrated when [...] so please add [...] 12 | 13 | **Describe the solution you'd like** 14 | A clear and concise description of what you want to happen. 15 | 16 | **Describe alternatives you've considered** 17 | A clear and concise description of any alternative solutions or features you've considered. 18 | 19 | **Additional context** 20 | Add any other context or screenshots about the feature request here. 21 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | .idea/* 2 | /vendor/ 3 | /dist/ 4 | -------------------------------------------------------------------------------- /.poggit.yml: -------------------------------------------------------------------------------- 1 | --- 2 | build-by-default: true 3 | branches: 4 | - stable 5 | projects: 6 | KOTH: 7 | path: "" 8 | icon: "icon.png" 9 | libs: 10 | - src: poggit/libasynql/libasynql 11 | version: ^4 12 | ... 13 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | GNU GENERAL PUBLIC LICENSE 2 | Version 3, 29 June 2007 3 | 4 | Copyright (C) 2007 Free Software Foundation, Inc. 5 | Everyone is permitted to copy and distribute verbatim copies 6 | of this license document, but changing it is not allowed. 7 | 8 | Preamble 9 | 10 | The GNU General Public License is a free, copyleft license for 11 | software and other kinds of works. 12 | 13 | The licenses for most software and other practical works are designed 14 | to take away your freedom to share and change the works. By contrast, 15 | the GNU General Public License is intended to guarantee your freedom to 16 | share and change all versions of a program--to make sure it remains free 17 | software for all its users. We, the Free Software Foundation, use the 18 | GNU General Public License for most of our software; it applies also to 19 | any other work released this way by its authors. You can apply it to 20 | your programs, too. 21 | 22 | When we speak of free software, we are referring to freedom, not 23 | price. Our General Public Licenses are designed to make sure that you 24 | have the freedom to distribute copies of free software (and charge for 25 | them if you wish), that you receive source code or can get it if you 26 | want it, that you can change the software or use pieces of it in new 27 | free programs, and that you know you can do these things. 28 | 29 | To protect your rights, we need to prevent others from denying you 30 | these rights or asking you to surrender the rights. Therefore, you have 31 | certain responsibilities if you distribute copies of the software, or if 32 | you modify it: responsibilities to respect the freedom of others. 33 | 34 | For example, if you distribute copies of such a program, whether 35 | gratis or for a fee, you must pass on to the recipients the same 36 | freedoms that you received. You must make sure that they, too, receive 37 | or can get the source code. And you must show them these terms so they 38 | know their rights. 39 | 40 | Developers that use the GNU GPL protect your rights with two steps: 41 | (1) assert copyright on the software, and (2) offer you this License 42 | giving you legal permission to copy, distribute and/or modify it. 43 | 44 | For the developers' and authors' protection, the GPL clearly explains 45 | that there is no warranty for this free software. For both users' and 46 | authors' sake, the GPL requires that modified versions be marked as 47 | changed, so that their problems will not be attributed erroneously to 48 | authors of previous versions. 49 | 50 | Some devices are designed to deny users access to install or run 51 | modified versions of the software inside them, although the manufacturer 52 | can do so. This is fundamentally incompatible with the aim of 53 | protecting users' freedom to change the software. The systematic 54 | pattern of such abuse occurs in the area of products for individuals to 55 | use, which is precisely where it is most unacceptable. Therefore, we 56 | have designed this version of the GPL to prohibit the practice for those 57 | products. If such problems arise substantially in other domains, we 58 | stand ready to extend this provision to those domains in future versions 59 | of the GPL, as needed to protect the freedom of users. 60 | 61 | Finally, every program is threatened constantly by software patents. 62 | States should not allow patents to restrict development and use of 63 | software on general-purpose computers, but in those that do, we wish to 64 | avoid the special danger that patents applied to a free program could 65 | make it effectively proprietary. To prevent this, the GPL assures that 66 | patents cannot be used to render the program non-free. 67 | 68 | The precise terms and conditions for copying, distribution and 69 | modification follow. 70 | 71 | TERMS AND CONDITIONS 72 | 73 | 0. Definitions. 74 | 75 | "This License" refers to version 3 of the GNU General Public License. 76 | 77 | "Copyright" also means copyright-like laws that apply to other kinds of 78 | works, such as semiconductor masks. 79 | 80 | "The Program" refers to any copyrightable work licensed under this 81 | License. Each licensee is addressed as "you". "Licensees" and 82 | "recipients" may be individuals or organizations. 83 | 84 | To "modify" a work means to copy from or adapt all or part of the work 85 | in a fashion requiring copyright permission, other than the making of an 86 | exact copy. The resulting work is called a "modified version" of the 87 | earlier work or a work "based on" the earlier work. 88 | 89 | A "covered work" means either the unmodified Program or a work based 90 | on the Program. 91 | 92 | To "propagate" a work means to do anything with it that, without 93 | permission, would make you directly or secondarily liable for 94 | infringement under applicable copyright law, except executing it on a 95 | computer or modifying a private copy. Propagation includes copying, 96 | distribution (with or without modification), making available to the 97 | public, and in some countries other activities as well. 98 | 99 | To "convey" a work means any kind of propagation that enables other 100 | parties to make or receive copies. Mere interaction with a user through 101 | a computer network, with no transfer of a copy, is not conveying. 102 | 103 | An interactive user interface displays "Appropriate Legal Notices" 104 | to the extent that it includes a convenient and prominently visible 105 | feature that (1) displays an appropriate copyright notice, and (2) 106 | tells the user that there is no warranty for the work (except to the 107 | extent that warranties are provided), that licensees may convey the 108 | work under this License, and how to view a copy of this License. If 109 | the interface presents a list of user commands or options, such as a 110 | menu, a prominent item in the list meets this criterion. 111 | 112 | 1. Source Code. 113 | 114 | The "source code" for a work means the preferred form of the work 115 | for making modifications to it. "Object code" means any non-source 116 | form of a work. 117 | 118 | A "Standard Interface" means an interface that either is an official 119 | standard defined by a recognized standards body, or, in the case of 120 | interfaces specified for a particular programming language, one that 121 | is widely used among developers working in that language. 122 | 123 | The "System Libraries" of an executable work include anything, other 124 | than the work as a whole, that (a) is included in the normal form of 125 | packaging a Major Component, but which is not part of that Major 126 | Component, and (b) serves only to enable use of the work with that 127 | Major Component, or to implement a Standard Interface for which an 128 | implementation is available to the public in source code form. A 129 | "Major Component", in this context, means a major essential component 130 | (kernel, window system, and so on) of the specific operating system 131 | (if any) on which the executable work runs, or a compiler used to 132 | produce the work, or an object code interpreter used to run it. 133 | 134 | The "Corresponding Source" for a work in object code form means all 135 | the source code needed to generate, install, and (for an executable 136 | work) run the object code and to modify the work, including scripts to 137 | control those activities. However, it does not include the work's 138 | System Libraries, or general-purpose tools or generally available free 139 | programs which are used unmodified in performing those activities but 140 | which are not part of the work. For example, Corresponding Source 141 | includes interface definition files associated with source files for 142 | the work, and the source code for shared libraries and dynamically 143 | linked subprograms that the work is specifically designed to require, 144 | such as by intimate data communication or control flow between those 145 | subprograms and other parts of the work. 146 | 147 | The Corresponding Source need not include anything that users 148 | can regenerate automatically from other parts of the Corresponding 149 | Source. 150 | 151 | The Corresponding Source for a work in source code form is that 152 | same work. 153 | 154 | 2. Basic Permissions. 155 | 156 | All rights granted under this License are granted for the term of 157 | copyright on the Program, and are irrevocable provided the stated 158 | conditions are met. This License explicitly affirms your unlimited 159 | permission to run the unmodified Program. The output from running a 160 | covered work is covered by this License only if the output, given its 161 | content, constitutes a covered work. This License acknowledges your 162 | rights of fair use or other equivalent, as provided by copyright law. 163 | 164 | You may make, run and propagate covered works that you do not 165 | convey, without conditions so long as your license otherwise remains 166 | in force. You may convey covered works to others for the sole purpose 167 | of having them make modifications exclusively for you, or provide you 168 | with facilities for running those works, provided that you comply with 169 | the terms of this License in conveying all material for which you do 170 | not control copyright. Those thus making or running the covered works 171 | for you must do so exclusively on your behalf, under your direction 172 | and control, on terms that prohibit them from making any copies of 173 | your copyrighted material outside their relationship with you. 174 | 175 | Conveying under any other circumstances is permitted solely under 176 | the conditions stated below. Sublicensing is not allowed; section 10 177 | makes it unnecessary. 178 | 179 | 3. Protecting Users' Legal Rights From Anti-Circumvention Law. 180 | 181 | No covered work shall be deemed part of an effective technological 182 | measure under any applicable law fulfilling obligations under article 183 | 11 of the WIPO copyright treaty adopted on 20 December 1996, or 184 | similar laws prohibiting or restricting circumvention of such 185 | measures. 186 | 187 | When you convey a covered work, you waive any legal power to forbid 188 | circumvention of technological measures to the extent such circumvention 189 | is effected by exercising rights under this License with respect to 190 | the covered work, and you disclaim any intention to limit operation or 191 | modification of the work as a means of enforcing, against the work's 192 | users, your or third parties' legal rights to forbid circumvention of 193 | technological measures. 194 | 195 | 4. Conveying Verbatim Copies. 196 | 197 | You may convey verbatim copies of the Program's source code as you 198 | receive it, in any medium, provided that you conspicuously and 199 | appropriately publish on each copy an appropriate copyright notice; 200 | keep intact all notices stating that this License and any 201 | non-permissive terms added in accord with section 7 apply to the code; 202 | keep intact all notices of the absence of any warranty; and give all 203 | recipients a copy of this License along with the Program. 204 | 205 | You may charge any price or no price for each copy that you convey, 206 | and you may offer support or warranty protection for a fee. 207 | 208 | 5. Conveying Modified Source Versions. 209 | 210 | You may convey a work based on the Program, or the modifications to 211 | produce it from the Program, in the form of source code under the 212 | terms of section 4, provided that you also meet all of these conditions: 213 | 214 | a) The work must carry prominent notices stating that you modified 215 | it, and giving a relevant date. 216 | 217 | b) The work must carry prominent notices stating that it is 218 | released under this License and any conditions added under section 219 | 7. This requirement modifies the requirement in section 4 to 220 | "keep intact all notices". 221 | 222 | c) You must license the entire work, as a whole, under this 223 | License to anyone who comes into possession of a copy. This 224 | License will therefore apply, along with any applicable section 7 225 | additional terms, to the whole of the work, and all its parts, 226 | regardless of how they are packaged. This License gives no 227 | permission to license the work in any other way, but it does not 228 | invalidate such permission if you have separately received it. 229 | 230 | d) If the work has interactive user interfaces, each must display 231 | Appropriate Legal Notices; however, if the Program has interactive 232 | interfaces that do not display Appropriate Legal Notices, your 233 | work need not make them do so. 234 | 235 | A compilation of a covered work with other separate and independent 236 | works, which are not by their nature extensions of the covered work, 237 | and which are not combined with it such as to form a larger program, 238 | in or on a volume of a storage or distribution medium, is called an 239 | "aggregate" if the compilation and its resulting copyright are not 240 | used to limit the access or legal rights of the compilation's users 241 | beyond what the individual works permit. Inclusion of a covered work 242 | in an aggregate does not cause this License to apply to the other 243 | parts of the aggregate. 244 | 245 | 6. Conveying Non-Source Forms. 246 | 247 | You may convey a covered work in object code form under the terms 248 | of sections 4 and 5, provided that you also convey the 249 | machine-readable Corresponding Source under the terms of this License, 250 | in one of these ways: 251 | 252 | a) Convey the object code in, or embodied in, a physical product 253 | (including a physical distribution medium), accompanied by the 254 | Corresponding Source fixed on a durable physical medium 255 | customarily used for software interchange. 256 | 257 | b) Convey the object code in, or embodied in, a physical product 258 | (including a physical distribution medium), accompanied by a 259 | written offer, valid for at least three years and valid for as 260 | long as you offer spare parts or customer support for that product 261 | model, to give anyone who possesses the object code either (1) a 262 | copy of the Corresponding Source for all the software in the 263 | product that is covered by this License, on a durable physical 264 | medium customarily used for software interchange, for a price no 265 | more than your reasonable cost of physically performing this 266 | conveying of source, or (2) access to copy the 267 | Corresponding Source from a network server at no charge. 268 | 269 | c) Convey individual copies of the object code with a copy of the 270 | written offer to provide the Corresponding Source. This 271 | alternative is allowed only occasionally and noncommercially, and 272 | only if you received the object code with such an offer, in accord 273 | with subsection 6b. 274 | 275 | d) Convey the object code by offering access from a designated 276 | place (gratis or for a charge), and offer equivalent access to the 277 | Corresponding Source in the same way through the same place at no 278 | further charge. You need not require recipients to copy the 279 | Corresponding Source along with the object code. If the place to 280 | copy the object code is a network server, the Corresponding Source 281 | may be on a different server (operated by you or a third party) 282 | that supports equivalent copying facilities, provided you maintain 283 | clear directions next to the object code saying where to find the 284 | Corresponding Source. Regardless of what server hosts the 285 | Corresponding Source, you remain obligated to ensure that it is 286 | available for as long as needed to satisfy these requirements. 287 | 288 | e) Convey the object code using peer-to-peer transmission, provided 289 | you inform other peers where the object code and Corresponding 290 | Source of the work are being offered to the general public at no 291 | charge under subsection 6d. 292 | 293 | A separable portion of the object code, whose source code is excluded 294 | from the Corresponding Source as a System Library, need not be 295 | included in conveying the object code work. 296 | 297 | A "User Product" is either (1) a "consumer product", which means any 298 | tangible personal property which is normally used for personal, family, 299 | or household purposes, or (2) anything designed or sold for incorporation 300 | into a dwelling. In determining whether a product is a consumer product, 301 | doubtful cases shall be resolved in favor of coverage. For a particular 302 | product received by a particular user, "normally used" refers to a 303 | typical or common use of that class of product, regardless of the status 304 | of the particular user or of the way in which the particular user 305 | actually uses, or expects or is expected to use, the product. A product 306 | is a consumer product regardless of whether the product has substantial 307 | commercial, industrial or non-consumer uses, unless such uses represent 308 | the only significant mode of use of the product. 309 | 310 | "Installation Information" for a User Product means any methods, 311 | procedures, authorization keys, or other information required to install 312 | and execute modified versions of a covered work in that User Product from 313 | a modified version of its Corresponding Source. The information must 314 | suffice to ensure that the continued functioning of the modified object 315 | code is in no case prevented or interfered with solely because 316 | modification has been made. 317 | 318 | If you convey an object code work under this section in, or with, or 319 | specifically for use in, a User Product, and the conveying occurs as 320 | part of a transaction in which the right of possession and use of the 321 | User Product is transferred to the recipient in perpetuity or for a 322 | fixed term (regardless of how the transaction is characterized), the 323 | Corresponding Source conveyed under this section must be accompanied 324 | by the Installation Information. But this requirement does not apply 325 | if neither you nor any third party retains the ability to install 326 | modified object code on the User Product (for example, the work has 327 | been installed in ROM). 328 | 329 | The requirement to provide Installation Information does not include a 330 | requirement to continue to provide support service, warranty, or updates 331 | for a work that has been modified or installed by the recipient, or for 332 | the User Product in which it has been modified or installed. Access to a 333 | network may be denied when the modification itself materially and 334 | adversely affects the operation of the network or violates the rules and 335 | protocols for communication across the network. 336 | 337 | Corresponding Source conveyed, and Installation Information provided, 338 | in accord with this section must be in a format that is publicly 339 | documented (and with an implementation available to the public in 340 | source code form), and must require no special password or key for 341 | unpacking, reading or copying. 342 | 343 | 7. Additional Terms. 344 | 345 | "Additional permissions" are terms that supplement the terms of this 346 | License by making exceptions from one or more of its conditions. 347 | Additional permissions that are applicable to the entire Program shall 348 | be treated as though they were included in this License, to the extent 349 | that they are valid under applicable law. If additional permissions 350 | apply only to part of the Program, that part may be used separately 351 | under those permissions, but the entire Program remains governed by 352 | this License without regard to the additional permissions. 353 | 354 | When you convey a copy of a covered work, you may at your option 355 | remove any additional permissions from that copy, or from any part of 356 | it. (Additional permissions may be written to require their own 357 | removal in certain cases when you modify the work.) You may place 358 | additional permissions on material, added by you to a covered work, 359 | for which you have or can give appropriate copyright permission. 360 | 361 | Notwithstanding any other provision of this License, for material you 362 | add to a covered work, you may (if authorized by the copyright holders of 363 | that material) supplement the terms of this License with terms: 364 | 365 | a) Disclaiming warranty or limiting liability differently from the 366 | terms of sections 15 and 16 of this License; or 367 | 368 | b) Requiring preservation of specified reasonable legal notices or 369 | author attributions in that material or in the Appropriate Legal 370 | Notices displayed by works containing it; or 371 | 372 | c) Prohibiting misrepresentation of the origin of that material, or 373 | requiring that modified versions of such material be marked in 374 | reasonable ways as different from the original version; or 375 | 376 | d) Limiting the use for publicity purposes of names of licensors or 377 | authors of the material; or 378 | 379 | e) Declining to grant rights under trademark law for use of some 380 | trade names, trademarks, or service marks; or 381 | 382 | f) Requiring indemnification of licensors and authors of that 383 | material by anyone who conveys the material (or modified versions of 384 | it) with contractual assumptions of liability to the recipient, for 385 | any liability that these contractual assumptions directly impose on 386 | those licensors and authors. 387 | 388 | All other non-permissive additional terms are considered "further 389 | restrictions" within the meaning of section 10. If the Program as you 390 | received it, or any part of it, contains a notice stating that it is 391 | governed by this License along with a term that is a further 392 | restriction, you may remove that term. If a license document contains 393 | a further restriction but permits relicensing or conveying under this 394 | License, you may add to a covered work material governed by the terms 395 | of that license document, provided that the further restriction does 396 | not survive such relicensing or conveying. 397 | 398 | If you add terms to a covered work in accord with this section, you 399 | must place, in the relevant source files, a statement of the 400 | additional terms that apply to those files, or a notice indicating 401 | where to find the applicable terms. 402 | 403 | Additional terms, permissive or non-permissive, may be stated in the 404 | form of a separately written license, or stated as exceptions; 405 | the above requirements apply either way. 406 | 407 | 8. Termination. 408 | 409 | You may not propagate or modify a covered work except as expressly 410 | provided under this License. Any attempt otherwise to propagate or 411 | modify it is void, and will automatically terminate your rights under 412 | this License (including any patent licenses granted under the third 413 | paragraph of section 11). 414 | 415 | However, if you cease all violation of this License, then your 416 | license from a particular copyright holder is reinstated (a) 417 | provisionally, unless and until the copyright holder explicitly and 418 | finally terminates your license, and (b) permanently, if the copyright 419 | holder fails to notify you of the violation by some reasonable means 420 | prior to 60 days after the cessation. 421 | 422 | Moreover, your license from a particular copyright holder is 423 | reinstated permanently if the copyright holder notifies you of the 424 | violation by some reasonable means, this is the first time you have 425 | received notice of violation of this License (for any work) from that 426 | copyright holder, and you cure the violation prior to 30 days after 427 | your receipt of the notice. 428 | 429 | Termination of your rights under this section does not terminate the 430 | licenses of parties who have received copies or rights from you under 431 | this License. If your rights have been terminated and not permanently 432 | reinstated, you do not qualify to receive new licenses for the same 433 | material under section 10. 434 | 435 | 9. Acceptance Not Required for Having Copies. 436 | 437 | You are not required to accept this License in order to receive or 438 | run a copy of the Program. Ancillary propagation of a covered work 439 | occurring solely as a consequence of using peer-to-peer transmission 440 | to receive a copy likewise does not require acceptance. However, 441 | nothing other than this License grants you permission to propagate or 442 | modify any covered work. These actions infringe copyright if you do 443 | not accept this License. Therefore, by modifying or propagating a 444 | covered work, you indicate your acceptance of this License to do so. 445 | 446 | 10. Automatic Licensing of Downstream Recipients. 447 | 448 | Each time you convey a covered work, the recipient automatically 449 | receives a license from the original licensors, to run, modify and 450 | propagate that work, subject to this License. You are not responsible 451 | for enforcing compliance by third parties with this License. 452 | 453 | An "entity transaction" is a transaction transferring control of an 454 | organization, or substantially all assets of one, or subdividing an 455 | organization, or merging organizations. If propagation of a covered 456 | work results from an entity transaction, each party to that 457 | transaction who receives a copy of the work also receives whatever 458 | licenses to the work the party's predecessor in interest had or could 459 | give under the previous paragraph, plus a right to possession of the 460 | Corresponding Source of the work from the predecessor in interest, if 461 | the predecessor has it or can get it with reasonable efforts. 462 | 463 | You may not impose any further restrictions on the exercise of the 464 | rights granted or affirmed under this License. For example, you may 465 | not impose a license fee, royalty, or other charge for exercise of 466 | rights granted under this License, and you may not initiate litigation 467 | (including a cross-claim or counterclaim in a lawsuit) alleging that 468 | any patent claim is infringed by making, using, selling, offering for 469 | sale, or importing the Program or any portion of it. 470 | 471 | 11. Patents. 472 | 473 | A "contributor" is a copyright holder who authorizes use under this 474 | License of the Program or a work on which the Program is based. The 475 | work thus licensed is called the contributor's "contributor version". 476 | 477 | A contributor's "essential patent claims" are all patent claims 478 | owned or controlled by the contributor, whether already acquired or 479 | hereafter acquired, that would be infringed by some manner, permitted 480 | by this License, of making, using, or selling its contributor version, 481 | but do not include claims that would be infringed only as a 482 | consequence of further modification of the contributor version. For 483 | purposes of this definition, "control" includes the right to grant 484 | patent sublicenses in a manner consistent with the requirements of 485 | this License. 486 | 487 | Each contributor grants you a non-exclusive, worldwide, royalty-free 488 | patent license under the contributor's essential patent claims, to 489 | make, use, sell, offer for sale, import and otherwise run, modify and 490 | propagate the contents of its contributor version. 491 | 492 | In the following three paragraphs, a "patent license" is any express 493 | agreement or commitment, however denominated, not to enforce a patent 494 | (such as an express permission to practice a patent or covenant not to 495 | sue for patent infringement). To "grant" such a patent license to a 496 | party means to make such an agreement or commitment not to enforce a 497 | patent against the party. 498 | 499 | If you convey a covered work, knowingly relying on a patent license, 500 | and the Corresponding Source of the work is not available for anyone 501 | to copy, free of charge and under the terms of this License, through a 502 | publicly available network server or other readily accessible means, 503 | then you must either (1) cause the Corresponding Source to be so 504 | available, or (2) arrange to deprive yourself of the benefit of the 505 | patent license for this particular work, or (3) arrange, in a manner 506 | consistent with the requirements of this License, to extend the patent 507 | license to downstream recipients. "Knowingly relying" means you have 508 | actual knowledge that, but for the patent license, your conveying the 509 | covered work in a country, or your recipient's use of the covered work 510 | in a country, would infringe one or more identifiable patents in that 511 | country that you have reason to believe are valid. 512 | 513 | If, pursuant to or in connection with a single transaction or 514 | arrangement, you convey, or propagate by procuring conveyance of, a 515 | covered work, and grant a patent license to some of the parties 516 | receiving the covered work authorizing them to use, propagate, modify 517 | or convey a specific copy of the covered work, then the patent license 518 | you grant is automatically extended to all recipients of the covered 519 | work and works based on it. 520 | 521 | A patent license is "discriminatory" if it does not include within 522 | the scope of its coverage, prohibits the exercise of, or is 523 | conditioned on the non-exercise of one or more of the rights that are 524 | specifically granted under this License. You may not convey a covered 525 | work if you are a party to an arrangement with a third party that is 526 | in the business of distributing software, under which you make payment 527 | to the third party based on the extent of your activity of conveying 528 | the work, and under which the third party grants, to any of the 529 | parties who would receive the covered work from you, a discriminatory 530 | patent license (a) in connection with copies of the covered work 531 | conveyed by you (or copies made from those copies), or (b) primarily 532 | for and in connection with specific products or compilations that 533 | contain the covered work, unless you entered into that arrangement, 534 | or that patent license was granted, prior to 28 March 2007. 535 | 536 | Nothing in this License shall be construed as excluding or limiting 537 | any implied license or other defenses to infringement that may 538 | otherwise be available to you under applicable patent law. 539 | 540 | 12. No Surrender of Others' Freedom. 541 | 542 | If conditions are imposed on you (whether by court order, agreement or 543 | otherwise) that contradict the conditions of this License, they do not 544 | excuse you from the conditions of this License. If you cannot convey a 545 | covered work so as to satisfy simultaneously your obligations under this 546 | License and any other pertinent obligations, then as a consequence you may 547 | not convey it at all. For example, if you agree to terms that obligate you 548 | to collect a royalty for further conveying from those to whom you convey 549 | the Program, the only way you could satisfy both those terms and this 550 | License would be to refrain entirely from conveying the Program. 551 | 552 | 13. Use with the GNU Affero General Public License. 553 | 554 | Notwithstanding any other provision of this License, you have 555 | permission to link or combine any covered work with a work licensed 556 | under version 3 of the GNU Affero General Public License into a single 557 | combined work, and to convey the resulting work. The terms of this 558 | License will continue to apply to the part which is the covered work, 559 | but the special requirements of the GNU Affero General Public License, 560 | section 13, concerning interaction through a network will apply to the 561 | combination as such. 562 | 563 | 14. Revised Versions of this License. 564 | 565 | The Free Software Foundation may publish revised and/or new versions of 566 | the GNU General Public License from time to time. Such new versions will 567 | be similar in spirit to the present version, but may differ in detail to 568 | address new problems or concerns. 569 | 570 | Each version is given a distinguishing version number. If the 571 | Program specifies that a certain numbered version of the GNU General 572 | Public License "or any later version" applies to it, you have the 573 | option of following the terms and conditions either of that numbered 574 | version or of any later version published by the Free Software 575 | Foundation. If the Program does not specify a version number of the 576 | GNU General Public License, you may choose any version ever published 577 | by the Free Software Foundation. 578 | 579 | If the Program specifies that a proxy can decide which future 580 | versions of the GNU General Public License can be used, that proxy's 581 | public statement of acceptance of a version permanently authorizes you 582 | to choose that version for the Program. 583 | 584 | Later license versions may give you additional or different 585 | permissions. However, no additional obligations are imposed on any 586 | author or copyright holder as a result of your choosing to follow a 587 | later version. 588 | 589 | 15. Disclaimer of Warranty. 590 | 591 | THERE IS NO WARRANTY FOR THE PROGRAM, TO THE EXTENT PERMITTED BY 592 | APPLICABLE LAW. EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT 593 | HOLDERS AND/OR OTHER PARTIES PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY 594 | OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, 595 | THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 596 | PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE PROGRAM 597 | IS WITH YOU. SHOULD THE PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF 598 | ALL NECESSARY SERVICING, REPAIR OR CORRECTION. 599 | 600 | 16. Limitation of Liability. 601 | 602 | IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING 603 | WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MODIFIES AND/OR CONVEYS 604 | THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, INCLUDING ANY 605 | GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE 606 | USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED TO LOSS OF 607 | DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD 608 | PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER PROGRAMS), 609 | EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF 610 | SUCH DAMAGES. 611 | 612 | 17. Interpretation of Sections 15 and 16. 613 | 614 | If the disclaimer of warranty and limitation of liability provided 615 | above cannot be given local legal effect according to their terms, 616 | reviewing courts shall apply local law that most closely approximates 617 | an absolute waiver of all civil liability in connection with the 618 | Program, unless a warranty or assumption of liability accompanies a 619 | copy of the Program in return for a fee. 620 | 621 | END OF TERMS AND CONDITIONS -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | Discord server 2 | 3 | 4 | # K.O.T.H 5 | King Of The Hill mini-game, Pocketmine-MP Plugin by JaxkDev. 6 | 7 | ## NOTICE'S 8 | *Just because it's the only plugin released, doesn't mean it's the best one.* 9 | 10 | *Please feel free to create a PR to modify/add new help files for different languages !* 11 | 12 | 13 | ## Features 14 | ### Implemented 15 | - Console has its own commands. 16 | - Enable/Disable arena's ! 17 | - Much more events for other developers to be able to customise the game EVEN MORE ! 18 | - Check for updates on server start ! - won't work on android (CURL) 19 | - Messages are customisable. 20 | - Multiple Arena's. 21 | - Custom spawn & hill points. 22 | - Supports Arena's in different worlds. 23 | - Custom player amount, and game time. 24 | - Block break/place disabled during in-game (optional). 25 | - Changing gamemode during a game is cancelled (optional). 26 | - Rewards given to king at end of game. 27 | - Leave a arena. 28 | - 'King' is displayed above player name. (nametag, optional) 29 | - Some values are in config.yml including a help file. 30 | - On death keep inventory. 31 | 32 | ### Upcoming 33 | - Change of game layout (different types will be extensions) - (check the extensions [repo](https://github.com/JaxkDev/Koth-Extensions) for more info) 34 | - Something extra for when winner is announced *wink* 35 | 36 | ### Permissions: 37 | ```yaml 38 | koth.command: 39 | description: "Allows player to use /koth" 40 | default: true 41 | koth.command.delete: 42 | description: "Allows player to delete an arena." 43 | default: op 44 | koth.command.create: 45 | description: "Allows player to create and setup an arena." 46 | default: op 47 | koth.command.enable: 48 | description: "Allows player to enable an arena." 49 | default: op 50 | koth.command.disable: 51 | description: "Allows player to disable an arena." 52 | default: op 53 | koth.command.rewards: 54 | description: "Allows player to modify the reward of an arena." 55 | default: op 56 | koth.command.info: 57 | description: "Allows player to see more details about an arena." 58 | default: true 59 | koth.command.list: 60 | description: "Allows player to see the Arena's and their current status." 61 | default: true 62 | koth.command.join: 63 | description: "Allows player to join a game." 64 | default: true 65 | koth.command.leave: 66 | description: "Allows player to chicken out of a game." 67 | default: true 68 | koth.command.start: 69 | description: "Allows player to start an arena." 70 | default: true 71 | koth.command.forcestart: 72 | description: "Allows player to force start an arena." 73 | default: op 74 | ``` 75 | ## About the game 76 | ### KOTH 77 | King.Of.The.Hill 78 | 79 | King of the hill is a mini-game most players will be familiar with, either through minecraft or by playing pretty much any other strategy game. 80 | 81 | The aim of king of the hill is to conquer the castle, fort or anything else in the middle of the arena, the arena is usually a large map of some sort with surrounding walls. 82 | The top point usually on a hill with a height advantage is the throne, castle, fort whatever you call it. 83 | 84 | players all spawn into the one map/arena, and then using the equipment/items on them, they take on position of king. 85 | They remain king for as long as they stay in the specified area/fort/castle if they die, another player in the area takes place as king or next person who goes there. 86 | 87 | The winner is announced at the end of the game (When a timer runs out), the king currently in power or the previous king will be winner. 88 | 89 | At the end the winner is given rewards and a *celebration* occurs (shortly). 90 | (This is not yet implemented - as of beta4) 91 | 92 | ### Joining a game 93 | To join a game/arena the arena must meet some criteria, 94 | 1. The arena cannot be full or not ready (you can check using `/koth list`) 95 | 2. The arena world must exist, cannot be deleted or re-named (if so you will have to reset the arena positions) 96 | 3. The arena must have spawn points. 97 | 98 | If the arena meets all the above you can join using `/koth join ` 99 | 100 | ### Starting a game 101 | The game will start the pregame counter when the minimum amount of players has joined. 102 | or if auto-start is disabled in config you can type `/koth forcestart` or `/koth start` 103 | the only difference is forcestart does not check the arena status whereas ^^^ only starts if status is `Ready` 104 | 105 | ### Leaving a game 106 | You can leave a game by using the command `/koth leave` or quiting the game. 107 | 108 | ### Winning a game 109 | **NOTICE: There is plans for different types of ways of winning a game, targeted for beta 4/5** 110 | 111 | The game runs on a timer, during which anyone can move, attack and kill the king. 112 | However, when the timer runs out the last standing king, or the previous king will be crowned. 113 | (And in future rewards and *other* things will be added) 114 | 115 | (Notice, players are frozen during 'presentations of the king') 116 | 117 | ## Setting up 118 | ### Creating/Removing arena(s) 119 | To create a new arena use the command `/koth create ` (No spaces are allowed in arena, for now) 120 | To remove an arena use the command `/koth delete ` (The arena cannot be in use when deleting) 121 | 122 | To check arena status type `/koth list` or `/koth info ` 123 | ### Setting positions/Values 124 | 1. `/koth setpos1 ` 125 | (Make sure you are standing on one corner of the throne/hill.) 126 | 2. `/koth setpos2 ` 127 | (Now stand on the opposite corner of the throne/hill.) 128 | 3. `/koth setspawn ` 129 | (This command can be used as many times as you like, again be standing on the spawn location you want to set.) 130 | 4. `/koth addreward ` 131 | example: `/koth addreward arena1 give {PLAYER} 20 1` <- this would give the winner 1 web. 132 | ### Editing Values 133 | If your provider is yaml feel free to edit the data file but any damaged caused is directly your fault. 134 | 135 | You can use commands to modify some but not all data (as of beta3) check /koth help 136 | - `/koth setpos1/2` (Can be re-used to overwrite old positions) 137 | - `/koth setspawn` (Can be used multiple times, `/koth remspawn` is in Beta4) 138 | 139 | ### Config: 140 | When the plugin is first run it will make a file in plugin_data/koth/ named config.yml 141 | in the file you will find a series of values feel free to change any of them except version 142 | 143 | For more info see the help file found in the same directory. 144 | 145 | ## Extensions: 146 | - 147 | To install extensions place the phar from the releases section into the plugins directory of your server and reboot server. 148 | Any issues should be reported in that repository if the extension crashes. 149 | 150 | ## Known Bugs: 151 | - Floating Text Particles will appear in every world but at same position, disable floating_text_particles if this is an issue for your server setup. 152 | 153 | To report bugs please make an issue over on [GitHub](https://github.com/JaxkDev/koth/issues/new) and please *follow the template!* 154 | 155 | ## Credits: 156 | _Developer:_ JaxkDev 157 | 158 | _Icon Creator:_ WowAssasin (WowAssasin#6608) 159 | 160 | _Requested Originally By:_ GOLDVAGE (GOLDVAGE#2712) (My Idea generator, hehe) 161 | -------------------------------------------------------------------------------- /composer.json: -------------------------------------------------------------------------------- 1 | { 2 | "license": "GPL-3.0", 3 | "authors": [ 4 | { 5 | "name": "JaxkDev", 6 | "email": "JaxkDev@gmail.com" 7 | } 8 | ], 9 | "autoload": { 10 | "psr-4": { 11 | "JaxkDev\\KOTH\\": "src" 12 | } 13 | }, 14 | "require": { 15 | "php": "^8.0.0", 16 | "ext-curl": "*", 17 | "ext-sqlite3": "*", 18 | "ext-yaml": "*" 19 | }, 20 | "require-dev": { 21 | "sof3/libasynql": "^4.1", 22 | "phpstan/phpstan": "^1.7", 23 | "pocketmine/pocketmine-mp": "^4" 24 | } 25 | } 26 | -------------------------------------------------------------------------------- /icon.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/JaxkDev/koth/79a9b81e2c6387311bc38a2d9b54a653d7e8169e/icon.png -------------------------------------------------------------------------------- /phpstan.neon.dist: -------------------------------------------------------------------------------- 1 | parameters: 2 | level: 8 3 | paths: 4 | - src 5 | excludePaths: 6 | analyse: 7 | - vendor -------------------------------------------------------------------------------- /plugin.yml: -------------------------------------------------------------------------------- 1 | --- 2 | name: KOTH 3 | author: JaxkDev 4 | version: 1.0.0-dev 5 | api: 4.0.0 6 | main: JaxkDev\KOTH\Main 7 | src-namespace-prefix: JaxkDev\KOTH 8 | website: "https://github.com/JaxkDev/KOTH" 9 | description: "King of The Hill, A mini-game plugin by JaxkDev" 10 | 11 | extensions: [sqlite3] 12 | 13 | commands: 14 | koth: 15 | description: "KOTH general command" 16 | permission: koth.command 17 | usage: /koth help 18 | permission-message: "You do not have permission to use this command." 19 | 20 | permissions: 21 | koth.command: 22 | description: "Allows player to use /koth" 23 | default: true 24 | koth.command.delete: 25 | description: "Allows player to delete an arena." 26 | default: op 27 | koth.command.create: 28 | description: "Allows player to create and setup an arena." 29 | default: op 30 | koth.command.enable: 31 | description: "Allows player to enable an arena." 32 | default: op 33 | koth.command.disable: 34 | description: "Allows player to disable an arena." 35 | default: op 36 | koth.command.rewards: 37 | description: "Allows player to modify the reward of an arena." 38 | default: op 39 | koth.command.info: 40 | description: "Allows player to see more details about an arena." 41 | default: true 42 | koth.command.list: 43 | description: "Allows player to see the Arena's and their current status." 44 | default: true 45 | koth.command.join: 46 | description: "Allows player to join a game." 47 | default: true 48 | koth.command.leave: 49 | description: "Allows player to chicken out of a game." 50 | default: true 51 | koth.command.start: 52 | description: "Allows player to start an arena." 53 | default: true 54 | koth.command.forcestart: 55 | description: "Allows player to force start an arena." 56 | default: op 57 | ... 58 | -------------------------------------------------------------------------------- /resources/config.yml: -------------------------------------------------------------------------------- 1 | --- 2 | version: 3 3 | 4 | general: 5 | debug: false 6 | check_updates: true 7 | 8 | database: 9 | # The database type. "sqlite" and "mysql" are supported. 10 | type: sqlite 11 | 12 | # Edit these settings only if you choose "sqlite". 13 | sqlite: 14 | # The file name of the database in the plugin data folder. 15 | # You can also put an absolute path here. 16 | file: data.sqlite 17 | # Edit these settings only if you choose "mysql". 18 | mysql: 19 | host: 127.0.0.1 20 | # Avoid using the "root" user for security reasons. 21 | username: root 22 | password: "" 23 | schema: your_schema 24 | # The maximum number of simultaneous SQL queries 25 | # Recommended: 1 for sqlite, 2 for MySQL. You may want to further increase this value if your MySQL connection is very slow. 26 | worker-limit: 1 27 | 28 | options: 29 | block_commands: true 30 | block_messages: true 31 | prevent_place: true 32 | prevent_break: true 33 | prevent_gamemode_change: true 34 | keep_inventory: true 35 | auto_start: true 36 | 37 | countdown: 38 | time: 30 39 | broadcast: 40 | enabled: true 41 | interval: 5 42 | serverwide: false 43 | 44 | start_bcast_serverwide: false 45 | end_bcast_serverwide: false 46 | 47 | particles: 48 | lobby: true 49 | king: true 50 | 51 | nametag: 52 | enabled: true 53 | format: "{RED}[ {GREEN}KING {RED}]" 54 | ... -------------------------------------------------------------------------------- /resources/help_eng.txt: -------------------------------------------------------------------------------- 1 | English help file 2 | 3 | Colour variables = {BLACK} {DARK_BLUE} {DARK_GREEN} {DARK_AQUA} {DARK_RED} {DARK_PURPLE} {GOLD} {GRAY} {DARK_GRAY} {BLUE} {GREEN} {AQUA} {RED} 4 | {LIGHT_PURPLE} {YELLOW} {WHITE} {OBFUSCATED} {BOLD} {STRIKETHROUGH} {UNDERLINE} {ITALIC} {RESET} 5 | 6 | ^^^ these can be put in any string messages often enclosed in " " ^^^ 7 | 8 | ========== CONFIG HELP ========= 9 | version: 1 <-- DONT EVER TOUCH THIS. (You have been warned) 10 | 11 | provider: "sqlite3" <-- Database provider, options: [Sqlite3]. (leave alone if unsure) 12 | 13 | debug: true <-- Show debug messages. (useful when encountering problems) (true/false) 14 | 15 | check_updates: true <-- Check for updates on server start. (true/false) 16 | 17 | block_commands: true <-- Obvious, Block commands in game except '/koth'. (true/false) (TODO beta4, block_commands_list) 18 | prevent_place: true <-- Obvious. (true/false) 19 | prevent_break: true <-- Obvious. (true/false) 20 | prevent_gamemode_change: true <-- Obvious. (true/false) 21 | keep_inventory: true <-- Keep inventory on death. (true/false) 22 | 23 | auto_start: true <-- Auto start server when minimum players have joined. (over-ridden by /koth forcestart) (if false use /koth start to start arena) 24 | 25 | countdown: 30 <-- Countdown in seconds until game starts. 26 | countdown_bcast: true <-- Broadcast countdown to arena players. (true/false) 27 | countdown_bcast_interval: 5 <-- Broadcast every X seconds. 28 | countdown_bcast_serverwide: false <-- Broadcast to whole server as well as arena players. (true/false) 29 | 30 | start_bcast_serverwide: false <-- Broadcast server start to whole server. (true/false) 31 | end_bcast_serverwide: false <-- Broadcast server end to whole server. (true/false) 32 | 33 | KingTextParticles: true <-- Enable/Disable current king being displayed in middle of arena hill positions. (Floating Text) (true/false) 34 | 35 | nametag_enabled: true <-- Enable custom nametag for king in power. (true/false) 36 | nametag_format: "{RED}[ {GREEN}KING {RED}]" <-- Format for nametag. 37 | ================================ 38 | 39 | 40 | ========== ARENA HELP ========== 41 | 42 | Arenas are saved and loaded from plugin_data so no need to manually save anything. 43 | 44 | Creating new arena's: 45 | 46 | - /koth new 47 | No spaces in name ^ ^ Numbers above 1 ^ ^ amount of seconds game runs for. (above 5) 48 | 49 | - /koth setpos1 50 | Stand on one corner of the king's area. (during this the world is auto-detected.) 51 | 52 | - /koth setpos2 53 | Stand on the opposite corner of the king's area (Height is important if there's nothing above it's advised to go a few blocks up to allow for jumping) 54 | 55 | - /koth setspawn 56 | Can be used any amount of times. (stand in the spawn location you wish to add) 57 | 58 | - /koth addreward 59 | Can be used any amount of times. (No way to remove rewards yet) 60 | 61 | If all went well, the arena status should become 'ready' (can be seen in /koth list or /koth info ) 62 | and you can then join the arena. 63 | 64 | Removing an Arena: 65 | - /koth rem 66 | 67 | You can only remove it if the arena is not in use. 68 | 69 | Joining an Arena: 70 | - /koth join 71 | 72 | You can only join an arena if its status is Ready or Started 73 | Status can be seen in /koth list (or /koth info ) 74 | 75 | Leaving an Game: 76 | - /koth leave 77 | 78 | The command will only work if your in an Arena, Alternatively leaving the server/mcpe will also make you leave the mini-game. 79 | 80 | Arena Info/Status: 81 | - /koth list 82 | Displays a list of all arena's created and their status. 83 | 84 | - /koth info 85 | Displays more information on one arena. 86 | (Players in game, Game time, Amount of spawns etc.) 87 | 88 | ================================ -------------------------------------------------------------------------------- /resources/help_fra.txt: -------------------------------------------------------------------------------- 1 | French help file 2 | Fichier d'aide en français 3 | 4 | Variables de couleur = {BLACK} {DARK_BLUE} {DARK_GREEN} {DARK_AQUA} {DARK_RED} {DARK_PURPLE} {GOLD} {GRAY} {DARK_GRAY} {BLUE} {GREEN} {AQUA} {RED} 5 | {LIGHT_PURPLE} {YELLOW} {WHITE} {OBFUSCATED} {BOLD} {STRIKETHROUGH} {UNDERLINE} {ITALIC} {RESET} 6 | 7 | ^^^ ceux-ci peuvent être placés dans tous les messages de chaîne souvent inclus entre "" ^^^ 8 | 9 | ========== CONFIG HELP ========== 10 | version: 1 <- NE JAMAIS TOUCHER CETTE. (Tu étais prévenu) 11 | 12 | provider: "sqlite3" <- Fournisseur de base de données, options: [Sqlite3]. (laisser seul en cas de doute) 13 | 14 | debug: true <- Afficher les messages de débogage. (utile en cas de problème) (vrai / faux) 15 | 16 | check_updates: true <- Recherchez les mises à jour au démarrage du serveur. (vrai faux) 17 | 18 | block_commands: true <- Évident, Blocage des commandes dans le jeu sauf '/ koth'. (true / false) (TODO beta4, block_commands_list) 19 | prevent_place: true <- évident. (vrai faux) 20 | prevent_break: true <- évident. (vrai faux) 21 | prevent_gamemode_change: true <- évident. (vrai faux) 22 | keep_inventory: true <- Conserve l'inventaire au décès. (vrai faux) 23 | 24 | auto_start: true <- Démarre automatiquement le serveur lorsque le nombre minimum de joueurs est rejoint. (écrasé par / koth forcestart) (si faux utiliser / koth commence à démarrer en arène) 25 | 26 | countdown: 30 <- Compte à rebours en secondes jusqu'au début du jeu. 27 | countdown_bcast: true <- diffuse le compte à rebours aux joueurs de l'aréna. (vrai faux) 28 | countdown_bcast_interval: 5 <- Diffusé toutes les X secondes. 29 | countdown_bcast_serverwide: false <- Diffuse sur le serveur entier ainsi que sur les joueurs d'arène. (vrai faux) 30 | 31 | start_bcast_serverwide: false <- Le serveur de diffusion démarre sur le serveur entier. (vrai faux) 32 | end_bcast_serverwide: false <- Diffuse le serveur de bout en bout. (vrai faux) 33 | 34 | KingTextParticles: true <- Activer / Désactiver le roi actuel affiché au milieu des positions de la colline de l'arène. (Texte flottant) (vrai / faux) 35 | 36 | nametag_enabled: true <- Permet d'activer l'étiquette d'identification personnalisée pour le roi au pouvoir. (vrai faux) 37 | nametag_format: "{RED} [{GREEN} KING {RED}]"<- Format de l'étiquette d'identification. 38 | ================================ 39 | 40 | 41 | ========== ARENA HELP =========== 42 | 43 | Les Arena sont sauvegardées et chargées depuis plugin_data, vous n'avez donc pas besoin de sauvegarder quoi que ce soit manuellement. 44 | 45 | Créer de nouvelles arènes: 46 | 47 | - / koth new 48 | Aucun espace dans le nom ^ ^ Nombre supérieur à 1 ^ ^ nombre de secondes pendant lesquelles le jeu est exécuté. (plus de 5) 49 | 50 | - / koth setpos1 51 | Tenez-vous sur un coin de la région des rois. (Pendant ce temps, le monde est détecté automatiquement.) 52 | 53 | - / koth setpos2 54 | Tenez-vous sur le coin opposé de la zone des rois (la hauteur est importante s'il n'y a rien au-dessus de sa conseillé de monter quelques pâtés de maisons pour permettre de sauter) 55 | 56 | - / koth setspawn 57 | Peut être utilisé n'importe quel nombre de fois. (placez-vous dans le lieu de ponte que vous souhaitez ajouter) 58 | 59 | - / koth addreward 60 | Peut être utilisé n'importe quel nombre de fois. (Pas encore possible de supprimer les récompenses) 61 | 62 | Si tout s'est bien passé, le statut de l'aréna devrait devenir «prêt» (visible dans / koth list ou / koth info ) 63 | et vous pouvez ensuite rejoindre l'arène. 64 | 65 | Enlever une arène: 66 | - / koth rem 67 | 68 | Vous ne pouvez l'enlever que si l'arène n'est pas utilisée. 69 | 70 | Rejoindre une arène: 71 | - / koth join 72 | 73 | Vous ne pouvez rejoindre une arène que si son statut est Prêt ou Démarré. 74 | Le statut peut être vu dans / koth list (ou / koth info ) 75 | 76 | Quitter un jeu: 77 | - / koth leave 78 | 79 | La commande ne fonctionnera que si vous êtes dans une arène. Sinon, quitter le serveur / mcpe vous obligera également à quitter le mini-jeu. 80 | 81 | Informations sur l'arène / statut: 82 | - / koth list 83 | Affiche une liste de toutes les arènes créées et leur statut. 84 | 85 | - / koth info 86 | Affiche plus d'informations sur une arène. 87 | (Joueurs dans le jeu, temps de jeu, nombre de spawns, etc.) 88 | 89 | ================================ -------------------------------------------------------------------------------- /resources/help_spa.txt: -------------------------------------------------------------------------------- 1 | Spanish help file 2 | Archivo de ayuda en español 3 | 4 | Variables de color = {BLACK} {DARK_BLUE} {DARK_GREEN} {DARK_AQUA} {DARK_RED} {DARK_PURPLE} {GOLD} {GRAY} {DARK_GRAY} {BLUE} {GREEN} {AQUA} {RED} 5 | {LIGHT_PURPLE} {YELLOW} {WHITE} {OBFUSCATED} {BOLD} {STRIKETHROUGH} {UNDERLINE} {ITALIC} {RESET} 6 | 7 | ^^^ estos se pueden poner en cualquier cadena de mensajes a menudo encerrados en "" ^^^ 8 | 9 | ========== CONFIG HELP ========= 10 | version: 1 <- NUNCA TOQUE ESTO. (Usted ha sido advertido) 11 | 12 | provider: "sqlite3" <- Proveedor de base de datos, opciones: [Sqlite3]. (dejar solo si no está seguro) 13 | 14 | debug: true <- Mostrar mensajes de depuración. (útil cuando se encuentran problemas) (verdadero / falso) 15 | 16 | check_updates: true <- Buscar actualizaciones en el inicio del servidor. (verdadero Falso) 17 | 18 | block_commands: true <- Obvio, Bloquea los comandos en el juego excepto '/ koth'. (verdadero / falso) 19 | prevent_place: true <- Obvio. (verdadero Falso) 20 | prevent_break: true <- Obvious. (verdadero Falso) 21 | prevent_gamemode_change: true <- Obvious. (verdadero Falso) 22 | keep_inventory: true <- Mantener el inventario de la muerte. (verdadero Falso) 23 | 24 | auto_start: true <- Iniciar automáticamente el servidor cuando se hayan unido al mínimo los jugadores. (sobrepasado por / koth forcestart) (si es falso, use / koth start para iniciar arena) 25 | 26 | countdown: 30 <- Cuenta atrás en segundos hasta que comience el juego. 27 | countdown_bcast: true <- Transmite la cuenta regresiva a los jugadores de la arena. (verdadero Falso) 28 | countdown_bcast_interval: 5 <- Transmisión cada X segundos. 29 | countdown_bcast_serverwide: false <- Difunde a todo el servidor así como a los jugadores de la arena. (verdadero Falso) 30 | 31 | start_bcast_serverwide: false <- El servidor de difusión comienza en todo el servidor. (verdadero Falso) 32 | end_bcast_serverwide: false <- El servidor de difusión finaliza a todo el servidor. (verdadero Falso) 33 | 34 | KingTextParticles: true <- Habilita / deshabilita el rey actual que se muestra en medio de las posiciones de arena de la colina. (Texto flotante) (verdadero / falso) 35 | 36 | nametag_enabled: true <- Habilita una etiqueta personalizada para el rey en el poder. (verdadero Falso) 37 | nametag_format: "{RED} [{GREEN} KING {RED}]"<- Formato para la etiqueta de nombre. 38 | ================================ 39 | 40 | 41 | ========== AYUDA DE ARENA ========== 42 | 43 | Las arenas se guardan y se cargan desde plugin_data, por lo que no es necesario guardar nada manualmente. 44 | 45 | Creando nuevas arenas: 46 | 47 | - /koth new 48 | No hay espacios en el nombre ^ ^ Números por encima de 1 ^ ^ de segundos de ejecución del juego. (por encima de 5) 49 | 50 | - /koth setpos1 51 | Párese en una esquina de la zona de los reyes. (Durante esto, el mundo se detecta automáticamente.) 52 | 53 | - /koth setpos2 54 | Párese en la esquina opuesta del área de los reyes (la altura es importante si no hay nada por encima de lo que se recomienda subir unas cuantas cuadras para permitir el salto) 55 | 56 | - /koth setspawn 57 | Se puede utilizar cualquier cantidad de veces. (párese en la ubicación de engendro que desea agregar) 58 | 59 | - /koth addreward 60 | Se puede utilizar cualquier cantidad de veces. (No hay manera de eliminar recompensas todavía) 61 | 62 | Si todo salió bien, el estado de la arena debería estar "listo" (se puede ver en / koth list o / koth info ) 63 | y luego puedes unirte a la arena. 64 | 65 | Eliminando una arena: 66 | - /koth rem 67 | 68 | Solo puedes eliminarlo si la arena no está en uso. 69 | 70 | Uniéndose a una arena: 71 | - /koth join 72 | 73 | Solo puedes unirte a una arena si su estado es Listo o Iniciado 74 | El estado se puede ver en / koth list (o / koth info ) 75 | 76 | Dejando un juego: 77 | - /koth leave 78 | 79 | El comando solo funcionará si estás en una Arena, Alternativamente, al dejar el servidor / mcpe también te hará salir del mini-juego. 80 | 81 | Información de la Arena / Estado: 82 | - / koth list 83 | Muestra una lista de todos los espacios creados y su estado. 84 | 85 | - / koth info 86 | Muestra más información en una arena. 87 | (Jugadores en juego, tiempo de juego, cantidad de engendros, etc.) 88 | 89 | ================================ -------------------------------------------------------------------------------- /resources/messages.yml: -------------------------------------------------------------------------------- 1 | --- 2 | colour_codes: "All colour codes: {PREFIX} {BLACK} {DARK_BLUE} {DARK_GREEN} {DARK_AQUA} {DARK_RED} {DARK_PURPLE} {GOLD} {GRAY} {DARK_GRAY} {BLUE} {GREEN} {AQUA} {RED} {LIGHT_PURPLE} {YELLOW} {WHITE} {OBFUSCATED} {BOLD} {STRIKETHROUGH} {UNDERLINE} {ITALIC} {RESET}" 3 | version: 0 4 | 5 | general: 6 | debug_format: "{GRAY}[KOTH | DEBUG] : {MSG}" 7 | provider: "Provider was set to: {NAME}" 8 | 9 | arenas: 10 | loaded: "{AMOUNT} Arena(s) loaded." 11 | leave_message: "Chickened Out." 12 | 13 | commands: 14 | unknown: "{PREFIX}{RED}Unknown command, try /koth help" 15 | no_perms: "{PREFIX}{RED}You do not have permission to use this command!" 16 | in_game: "{PREFIX}{RED}Commands can only be run in-game." 17 | usage: "{PREFIX}{RED}Usage incorrect, {USAGE}" 18 | not_exist: "{PREFIX}{RED}The specified arena does not exist." 19 | not_while_running: "{PREFIX}{RED}That arena is currently running, please stop it first." 20 | not_in_game_leave: "{PREFIX}{RED}Your not in a game, so how can you leave a game..." 21 | in_game_join: "{PREFIX}{RED}Your currently in a game, please leave the game using /koth leave to join another one." 22 | 23 | broadcasts: 24 | winner: "{PREFIX}{GOLD}{PLAYER} Has won the game in the {ARENA} Arena !" 25 | no_winner: "{PREFIX}{RED}GAME OVER, No one managed to claim the hill and win the game. Better luck next time." 26 | fallen_king: "{PREFIX}{RED}The king {AQUA}'{PLAYER}'{RED} has fallen." 27 | new_king: "{PREFIX}{GOLD}{PLAYER} {GREEN}Has claimed the throne, how long will it last..." 28 | player_quit: "{PREFIX}{GOLD}{PLAYER} {AQUA}Has left the game, reason: {RED}{REASON}" 29 | player_join: "{PREFIX}{GOLD}{PLAYER} {GREEN}Has joined the game !" 30 | 31 | countdown: "{PREFIX}{GOLD}[{AQUA}{ARENA} | {RED}COUNTDOWN{GOLD}] {RED}: {GREEN}{TIME}" 32 | start: "{PREFIX}{GOLD}[{ARENA}] {GREEN}Has Started !" 33 | end: "{PREFIX}{GOLD}[{ARENA}] {GREEN}Has Ended." 34 | ... -------------------------------------------------------------------------------- /resources/provider/mysql.sql: -------------------------------------------------------------------------------- 1 | -- TODO 2 | -------------------------------------------------------------------------------- /resources/provider/sqlite.sql: -------------------------------------------------------------------------------- 1 | -- #! sqlite 2 | 3 | -- #{ arena 4 | 5 | -- # { init 6 | CREATE TABLE IF NOT EXISTS arena( 7 | name TEXT NOT NULL, 8 | min_players INT UNSIGNED NOT NULL, 9 | max_players INT UNSIGNED NOT NULL, 10 | hill TEXT NOT NULL, 11 | spawns TEXT NOT NULL, 12 | rewards TEXT NOT NULL, 13 | world TEXT NOT NULL, 14 | PRIMARY KEY(name) 15 | ); 16 | -- # } 17 | 18 | -- # { create 19 | -- # :name string 20 | -- # :min int 21 | -- # :max int 22 | -- # :hill string 23 | -- # :spawns string 24 | -- # :rewards string 25 | -- # :world string 26 | INSERT INTO arena ( 27 | name, 28 | min_players, 29 | max_players, 30 | hill, 31 | spawns, 32 | rewards, 33 | world 34 | ) VALUES ( 35 | :name, 36 | :min, 37 | :max, 38 | :hill, 39 | :spawns, 40 | :rewards, 41 | :world 42 | ); 43 | -- # } 44 | 45 | -- # { update 46 | -- # :name string 47 | -- # :min int 48 | -- # :max int 49 | -- # :hill string 50 | -- # :spawns string 51 | -- # :rewards string 52 | -- # :world string 53 | UPDATE arena SET 54 | min_players = :min, 55 | max_players = :max, 56 | hill = :hill, 57 | spawns = :spawns, 58 | rewards = :rewards, 59 | world = :world 60 | WHERE name = :name; 61 | -- # } 62 | 63 | -- # { delete 64 | -- # :name string 65 | DELETE FROM arena WHERE name = :name; 66 | -- # } 67 | 68 | -- # { all 69 | SELECT * FROM arena; 70 | -- # } 71 | 72 | -- #} -------------------------------------------------------------------------------- /src/Arena.php: -------------------------------------------------------------------------------- 1 | . 19 | * 20 | * Twitter :: @JaxkDev 21 | * Discord :: JaxkDev#2698 22 | * Email :: JaxkDev@gmail.com 23 | */ 24 | 25 | namespace JaxkDev\KOTH; 26 | 27 | use Exception; 28 | use InvalidArgumentException; 29 | use JaxkDev\KOTH\Events\ArenaAddPlayerEvent; 30 | use JaxkDev\KOTH\Events\ArenaEndEvent; 31 | use JaxkDev\KOTH\Events\ArenaPreStartEvent; 32 | use JaxkDev\KOTH\Events\ArenaRemovePlayerEvent; 33 | use JaxkDev\KOTH\Events\ArenaStartEvent; 34 | use JaxkDev\KOTH\Particles\FloatingText; 35 | use JaxkDev\KOTH\Tasks\StartCountdown; 36 | use JaxkDev\KOTH\Tasks\GameTimer; 37 | use pocketmine\console\ConsoleCommandSender; 38 | use pocketmine\lang\Language; 39 | use pocketmine\player\GameMode; 40 | use pocketmine\player\Player; 41 | use pocketmine\math\Vector3; 42 | use pocketmine\Server; 43 | use pocketmine\scheduler\TaskHandler; 44 | use pocketmine\utils\TextFormat as C; 45 | use pocketmine\world\Position; 46 | use TypeError; 47 | 48 | /* 49 | NOTES: 50 | - so if king dies out of box or goes out of box, its race to the box, 51 | if killed in box from someone inside box that killer is king 52 | if someone outside the box kills him next to box is king 53 | 54 | - EventHandler handles all events from pmmp, then passed here, or handled by values obtained from here. 55 | */ 56 | 57 | class Arena{ 58 | public const STATUS_NOT_READY = 0; 59 | public const STATUS_READY = 1; 60 | public const STATUS_STARTED = 2; 61 | public const STATUS_FULL = 3; 62 | public const STATUS_INVALID = 4; 63 | public const STATUS_DISABLED = 7; 64 | public const STATUS_UNKNOWN = 9; 65 | 66 | /** @var array */ 67 | public array $statusList = [ 68 | self::STATUS_NOT_READY => "Not Ready/Setup", 69 | self::STATUS_READY => "Ready", 70 | self::STATUS_STARTED => "Started", 71 | self::STATUS_FULL => "Full", 72 | self::STATUS_INVALID => "Invalid Setup", #Used when arena was set up correctly but external causes means it's no longer compatible. 73 | self::STATUS_DISABLED => "Disabled", 74 | self::STATUS_UNKNOWN => "Unknown" 75 | ]; 76 | 77 | private Main $plugin; 78 | /** @var float[][]|int[][] */ 79 | private array $spawns; 80 | private int $spawnCounter; 81 | /** @var float[][]|int[][] */ 82 | private array $hill; 83 | /** @var string[] */ 84 | private array $players = []; 85 | /** @var array */ 86 | private array $playerOldPositions = []; 87 | /** @var array */ 88 | private array $playerOldNameTags = []; 89 | private int $minPlayers; 90 | private int $maxPlayers; 91 | private string $name; 92 | private bool $started = false; 93 | private int $time; 94 | private int $countDown; 95 | private string $world; 96 | /** @var string[] */ 97 | private array $rewards; 98 | 99 | private ?string $oldKing = null; 100 | private ?string $king = null; 101 | /** @var string[] */ 102 | private array $playersInBox = []; 103 | 104 | private ?TaskHandler $timerTask = null; 105 | 106 | private int $status = self::STATUS_UNKNOWN; 107 | 108 | private ?FloatingText $currentKingParticle = null; 109 | 110 | /** 111 | * @param Main $plugin 112 | * @param string $name 113 | * @param int $min 114 | * @param int $max 115 | * @param int $time 116 | * @param float[][]|int[][] $hill 117 | * @param float[][]|int[][] $spawns 118 | * @param string[] $rewards 119 | * @param string $world 120 | * @throws Exception 121 | */ 122 | public function __construct(Main $plugin, string $name, int $min, int $max, int $time, array $hill, array $spawns, array $rewards, string $world){ 123 | $this->plugin = $plugin; 124 | $this->hill = $hill; 125 | $this->minPlayers = $min; 126 | $this->maxPlayers = $max; 127 | $this->name = $name; 128 | $this->spawns = $spawns; 129 | $this->time = $time; 130 | $this->countDown = (int)$plugin->getConfig()->get("countdown", 30); 131 | $this->world = $world; 132 | $this->rewards = $rewards; 133 | $this->spawnCounter = 0; 134 | 135 | $this->checkStatus(); 136 | 137 | $this->plugin->getLogger()->debug($this->getName()." - Arena Constructed, status: ".$this->getFriendlyStatus()); 138 | } 139 | 140 | public function getFriendlyStatus(): string{ 141 | return $this->statusList[$this->status]??$this->statusList[$this::STATUS_UNKNOWN]; 142 | } 143 | 144 | public function getStatus(): int{ 145 | return $this->status; 146 | } 147 | 148 | public function getName(): string{ 149 | return $this->name; 150 | } 151 | 152 | public function enable(): bool{ 153 | if($this->status !== $this::STATUS_DISABLED){ 154 | $this->plugin->getLogger()->debug("Failed to enable arena '".$this->getName()."', already enabled."); 155 | return false; 156 | } 157 | $this->status = $this::STATUS_UNKNOWN; 158 | $this->checkStatus(); 159 | if($this->status !== $this::STATUS_DISABLED) $this->plugin->getLogger()->debug("Enabled arena '".$this->getName()."'"); 160 | else $this->plugin->getLogger()->debug("Failed to enable arena '".$this->getName()."'"); 161 | return true; 162 | } 163 | 164 | public function disable(): bool{ 165 | if($this->status === $this::STATUS_DISABLED){ 166 | $this->plugin->getLogger()->debug("Failed to disable arena '".$this->getName()."', already disabled."); 167 | return false; 168 | } 169 | if($this->status === $this::STATUS_STARTED or count($this->players) > 0){ 170 | $this->plugin->getLogger()->debug("Failed to disable arena '".$this->getName()."', players are currently in the arena."); 171 | return false; 172 | } 173 | $this->status = $this::STATUS_DISABLED; 174 | $this->timerTask?->cancel(); 175 | $this->reset(); 176 | $this->plugin->getLogger()->debug("Disabled arena '".$this->getName()."'"); 177 | return true; 178 | } 179 | 180 | /** 181 | * @param string $msg 182 | */ 183 | public function broadcastMessage(string $msg): void{ 184 | $this->plugin->getLogger()->debug("Broadcasting message '".$msg."' to '".count($this->players)."' Players in arena '".$this->getName()."'"); 185 | foreach($this->players as $player){ 186 | $this->plugin->getServer()->getPlayerExact($player)?->sendMessage($msg); 187 | } 188 | } 189 | 190 | public function broadcastWinner(string $player): void{ 191 | $this->broadcastMessage(str_replace(["{ARENA}", "{PLAYER}"], [$this->name, $player], $this->plugin->utils->colourise((string)$this->plugin->getMessages()->getNested("broadcasts.winner", "{PREFIX}{GOLD}{PLAYER} Has won the game in the {ARENA} Arena !")))); 192 | } 193 | 194 | public function broadcastQuit(Player $player, string $reason): void{ 195 | $this->broadcastMessage(str_replace(["{REASON}", "{PLAYER}"], [$reason, strtolower($player->getName())], $this->plugin->utils->colourise((string)$this->plugin->getMessages()->getNested("broadcasts.player_quit", "{PREFIX}{GOLD}{PLAYER} {AQUA}Has left the game, reason: {RED}{REASON}")))); 196 | } 197 | 198 | public function broadcastJoin(Player $player): void{ 199 | $this->broadcastMessage(str_replace("{PLAYER}", strtolower($player->getName()), $this->plugin->utils->colourise((string)$this->plugin->getMessages()->getNested("broadcasts.player_join", "{PREFIX}{GOLD}{PLAYER} {GREEN}Has joined the game !")))); 200 | } 201 | 202 | public function checkStatus(bool $save = true): void{ 203 | $this->plugin->getLogger()->debug("Checking status in arena '".$this->getName()."', save: ".($save ? "yes" : "no")); 204 | $world = Utils::getWorldByName($this->world); 205 | if($this->status === $this::STATUS_DISABLED) return; 206 | if(count($this->hill) === 2 and count($this->spawns) >= 1 and $world !== null){ 207 | $this->status = self::STATUS_READY; 208 | }else{ 209 | $this->status = self::STATUS_NOT_READY; 210 | if($world === null){ 211 | $this->plugin->getLogger()->warning(C::RED."World '".$this->world."' couldn't be loaded/found, Arena '".$this->getName()."' Will not be playable."); 212 | $this->status = self::STATUS_INVALID; 213 | $this->currentKingParticle = null; 214 | } 215 | if($world !== null){ 216 | $this->world = $world->getFolderName(); 217 | } 218 | if($save === true){ 219 | $this->plugin->updateArena($this); 220 | } 221 | $this->plugin->getLogger()->debug("Setting status to '".$this->getFriendlyStatus()."'. (Arena: '".$this->getName()."')"); 222 | return; 223 | } 224 | if($this->started === true){ 225 | $this->status = self::STATUS_STARTED; 226 | } 227 | if(count($this->players) >= $this->maxPlayers){ 228 | $this->status = self::STATUS_FULL; 229 | if($save === true){ 230 | $this->plugin->updateArena($this); 231 | } 232 | $this->plugin->getLogger()->debug("Setting status to '".$this->getFriendlyStatus()."'. (Arena: '".$this->getName()."')"); 233 | return; 234 | } 235 | if($save === true){ 236 | $this->plugin->updateArena($this); 237 | } 238 | $this->plugin->getLogger()->debug("Setting status to '".$this->getFriendlyStatus()."'. (Arena: '".$this->getName()."')"); 239 | } 240 | 241 | private function createKingTextParticle(): void{ 242 | $this->plugin->getLogger()->debug("Creating KT particle for arena '".$this->getName()."'"); 243 | if($this->plugin->getConfig()->get("king_text_particles", true) === false) return; 244 | $this->checkStatus(); //Double check it's ready, also used to get exact world name. 245 | if(($this->status !== $this::STATUS_NOT_READY and $this->status !== $this::STATUS_INVALID) and $this->currentKingParticle === null){ 246 | $this->plugin->getLogger()->debug("KT Particle being created... ('".$this->getName()."')"); 247 | $pos = new Vector3(($this->hill[0][0]+$this->hill[1][0])/2,($this->hill[0][1]+$this->hill[1][1])/2,($this->hill[0][2]+$this->hill[1][2])/2); 248 | $world = Utils::getWorldByName($this->world); 249 | if($world !== null){ 250 | $this->currentKingParticle = new FloatingText($world, $pos, C::RED."-"); 251 | }else{ 252 | //Should never reach here due to checkStatus() above. 253 | throw new Exception("World '".$this->world."' couldn't be loaded/found, Arena '".$this->getName()."' Will not be playable."); 254 | } 255 | }else{ 256 | $this->plugin->getLogger()->debug("Arena '".$this->getName()."' doesnt satisfy the requirements needed to create the KT particle."); 257 | } 258 | } 259 | 260 | public function updateKingTextParticle(): void{ 261 | $this->plugin->getLogger()->debug("Updating KT particle in arena '".$this->getName()."'"); 262 | if($this->currentKingParticle !== null){ 263 | $this->currentKingParticle->setInvisible(false); //fix restarting games. 264 | $text = C::RED."Arena: '".$this->name."' | ".count($this->players)."/".$this->maxPlayers." Players waiting."; 265 | if($this->status === self::STATUS_STARTED){ 266 | $text = C::RED.($this->king === null ? "No King!" : "King: ".C::GOLD.$this->king); 267 | } 268 | $this->currentKingParticle->setText($text); 269 | }else{ 270 | $this->createKingTextParticle(); //keep trying to create it in case the scenario changes and its now able. 271 | $this->updateKingTextParticle(); 272 | } 273 | //set name tags, its own function so others can run it without updating Particles. 274 | $this->updateNameTags(); 275 | } 276 | 277 | public function removeKingTextParticles(): void{ 278 | $this->currentKingParticle?->setInvisible(); 279 | $this->updateNameTags(); //here to revert to original. 280 | } 281 | 282 | public function updateNameTags(): void{ 283 | //this makes plugins that modify your tag based on things like health,lvl etc. not work while in game. 284 | if($this->plugin->getConfig()->get("nametag_enabled", true) === true){ 285 | $format = $this->plugin->utils->colourise((string)$this->plugin->getConfig()->get("nametag_format", "{RED}[ {GREEN}KING {RED}]")); 286 | if($this->king !== null){ 287 | $player = $this->plugin->getServer()->getPlayerExact($this->king); 288 | if($player === null){ 289 | $this->plugin->getLogger()->warning("Player '".$this->king."' couldn't be found, nametag for arena '".$this->getName()."' couldn't be updated."); 290 | return; 291 | } 292 | if(array_key_exists($this->king,$this->playerOldNameTags) !== true){ 293 | $this->playerOldNameTags[$this->king] = $player->getNameTag(); 294 | } 295 | $old = $this->playerOldNameTags[strtolower($player->getName())]; 296 | $player->setNameTag($format."\n".$old); 297 | if($this->oldKing !== null and $this->oldKing !== $this->king){ 298 | //remove nametag. 299 | $old = $this->playerOldNameTags[$this->oldKing]; 300 | $p = $this->plugin->getServer()->getPlayerExact($this->oldKing); 301 | $p?->setNameTag($old); 302 | } 303 | }else{ 304 | if($this->oldKing !== null){ 305 | $player = $this->plugin->getServer()->getPlayerExact($this->oldKing); 306 | if($player === null) return; 307 | $player->setNameTag($this->playerOldNameTags[strtolower($player->getName())]); 308 | } 309 | } 310 | } 311 | } 312 | 313 | private function spawnPlayer(Player $player): bool{ 314 | $world = Utils::getWorldByName($this->world); 315 | if($world === null){ 316 | $player->sendMessage(Main::PREFIX.C::RED."World set for '".$this->name."' does not exist"); 317 | $this->plugin->getLogger()->debug("World not found, '".$this->world."' for arena '".$this->getName()."'"); 318 | return false; 319 | } 320 | $spawn = $this->getSpawn(); 321 | if($spawn === null){ 322 | $player->sendMessage(Main::PREFIX.C::RED."Spawn not set for '".$this->name."'"); 323 | $this->plugin->getLogger()->error("Spawn not set for arena '".$this->getName()."' but player tried spawning."); 324 | return false; 325 | } 326 | $spawn = $spawn->asVector3(); 327 | if($player->getWorld()->getId() !== $world->getId()){ 328 | if(!$this->plugin->getServer()->getWorldManager()->isWorldLoaded($world->getFolderName())){ 329 | $this->plugin->getServer()->getWorldManager()->loadWorld($world->getFolderName()); 330 | $this->plugin->getLogger()->debug("Loaded world '".$world->getFolderName()."' So '".$player->getName()."' can join."); 331 | } 332 | } 333 | $this->plugin->getLogger()->debug("Teleporting '".$player->getName()."' to (".$spawn->x.",".$spawn->y.",".$spawn->z.")' in level '".$world->getFolderName()."'"); 334 | $player->teleport($spawn); 335 | return true; 336 | } 337 | 338 | public function getSpawn(bool $random = false): ?Position{ 339 | $world = Utils::getWorldByName($this->world); 340 | if($world === null){ 341 | $this->plugin->getLogger()->debug("World '".$this->world."' Not found !!!, Failed to get random position in arena '".$this->getName()."'"); 342 | throw new TypeError("World '".$this->world."' Not found, Failed to get random position in arena '".$this->getName()."'"); 343 | } 344 | if(count($this->spawns) === 0) return null; 345 | if($random === false){ 346 | $this->spawnCounter++; 347 | if($this->spawnCounter >= count($this->spawns)){ 348 | $this->spawnCounter = 0; 349 | } 350 | $old = $this->spawns[$this->spawnCounter]; 351 | }else{ 352 | $old = $this->spawns[array_rand($this->spawns)]; 353 | } 354 | return new Position($old[0], $old[1], $old[2], $this->plugin->getServer()->getWorldManager()->getWorldByName($this->world)); 355 | } 356 | 357 | public function freezeAll(bool $freeze): void{ 358 | $this->plugin->getLogger()->debug("Setting players in arena '".$this->name."' ".($freeze ? "immobile" : "mobile")); 359 | foreach($this->players as $name){ 360 | $this->plugin->getServer()->getPlayerExact($name)?->setImmobile($freeze); 361 | } 362 | } 363 | 364 | public function startTimer(bool $force = false): ?string{ 365 | if((count($this->players) < $this->minPlayers) and !$force){ 366 | return "Not enough players to start arena"; 367 | } 368 | $event = new ArenaPreStartEvent($this->plugin, $this); 369 | $event->call(); 370 | 371 | if($event->isCancelled()){ 372 | return $event->getReason(); 373 | } 374 | $this->timerTask = $this->plugin->getScheduler()->scheduleRepeatingTask(new StartCountdown($this->plugin, $this, $event->getCountDown()),20); 375 | $this->plugin->getLogger()->debug("Started Prestart task for arena '".$this->name."'."); 376 | return null; 377 | } 378 | 379 | public function startGame(): void{ 380 | $event = new ArenaStartEvent($this->plugin, $this); 381 | $event->call(); 382 | 383 | if($event->isCancelled()){ 384 | $this->plugin->getLogger()->warning(Main::PREFIX.C::RED."Cant start game in Arena '".$this->getName()."' because: ".$event->getReason()); 385 | return; 386 | } 387 | $this->plugin->getLogger()->debug("Starting arena '".$this->name."'..."); 388 | $this->timerTask?->cancel(); 389 | $this->started = true; 390 | $this->freezeAll(false); 391 | $this->checkStatus(); 392 | $msg = str_replace("{ARENA}", $this->name, $this->plugin->utils->colourise((string)$this->plugin->getMessages()->getNested("broadcasts.start", "{PREFIX}{GOLD}[{ARENA}] {GREEN}Has Started !"))); 393 | if($this->plugin->getConfig()->get("start_bcast_serverwide", true) === true){ 394 | $this->plugin->getServer()->broadcastMessage($msg); 395 | }else{ 396 | $this->broadcastMessage($msg); 397 | } 398 | $this->updateKingTextParticle(); //Set king message. 399 | $this->timerTask = $this->plugin->getScheduler()->scheduleRepeatingTask(new GameTimer($this),10); 400 | $this->plugin->getLogger()->debug("Started arena '".$this->name."'."); 401 | } 402 | 403 | public function reset(): void{ 404 | $this->removeKingTextParticles(); 405 | 406 | $this->started = false; 407 | $this->king = null; 408 | $this->oldKing = null; 409 | $this->timerTask = null; 410 | 411 | foreach($this->players as $name){ 412 | $player = $this->plugin->getServer()->getPlayerExact($name); 413 | if($player !== null){ 414 | $this->removePlayer($player, "Game over", true); 415 | }else{ 416 | throw new Exception("Player '".$name."' not found from server in arena '".$this->name."'"); 417 | } 418 | } 419 | 420 | $this->players = []; 421 | $this->playerOldPositions = []; 422 | $this->playerOldNameTags = []; 423 | $this->checkStatus(); 424 | } 425 | 426 | public function endGame(): void{ 427 | $event = new ArenaEndEvent($this->plugin, $this); 428 | $event->call(); 429 | 430 | if($event->isCancelled() and $this->timerTask !== null){ 431 | /** @var GameTimer $tsk */ 432 | $tsk = $this->timerTask->getTask(); 433 | $tsk->secondsLeft = $event->getSecondsLeft(); 434 | $this->plugin->getLogger()->warning(Main::PREFIX.C::RED."Arena '".$this->name."' not ended, reason: ".$event->getReason()); 435 | return; 436 | } 437 | $msg = str_replace("{ARENA}", $this->name, $this->plugin->utils->colourise((string)$this->plugin->getMessages()->getNested("broadcasts.end", "{PREFIX}{GOLD}[{ARENA}] {GREEN}Has Ended."))); 438 | if($this->plugin->getConfig()->get("end_bcast_serverwide", true) === true){ 439 | $this->plugin->getServer()->broadcastMessage($msg); 440 | }else{ 441 | $this->broadcastMessage($msg); 442 | } 443 | $this->plugin->getLogger()->debug("Arena '".$this->name."' ended."); 444 | $this->freezeAll(true); 445 | $this->timerTask?->cancel(); 446 | if($this->king !== null){ 447 | $king = $this->king; 448 | }else{ 449 | $king = $this->oldKing; 450 | } 451 | $this->setWinner($king); 452 | $this->reset(); 453 | $this->checkStatus(); 454 | } 455 | 456 | public function setWinner(?string $king): void{ 457 | if($king === null){ 458 | $this->broadcastMessage($this->plugin->utils->colourise((string)$this->plugin->getMessages()->getNested("broadcasts.no_winner", "{PREFIX}{RED}GAME OVER, No one managed to claim the hill and win the game. Better luck next time."))); 459 | $this->freezeAll(false); 460 | return; 461 | } 462 | $this->broadcastWinner($king); 463 | //TODO Remove. 464 | $console = new ConsoleCommandSender(Server::getInstance(), new Language(Language::FALLBACK_LANGUAGE)); 465 | foreach($this->rewards as $reward){ 466 | $reward = str_replace("{PLAYER}", $king, $reward); 467 | if($this->plugin->getServer()->getCommandMap()->dispatch($console, $reward) === false){ 468 | $this->plugin->getLogger()->warning("Reward/command (".$reward.") failed to execute."); 469 | } 470 | 471 | } 472 | //todo particles fireworks and more for king? 473 | $this->freezeAll(false); 474 | } 475 | 476 | /** 477 | * @return string[] 478 | */ 479 | public function getPlayers(): array{ 480 | return $this->players; 481 | } 482 | 483 | /** 484 | * @return string[] 485 | */ 486 | public function getPlayersInBox(): array{ 487 | $pos1 = []; 488 | $pos1["x"] = $this->hill[0][0]; 489 | $pos1["y"] = $this->hill[0][1]; 490 | $pos1["z"] = $this->hill[0][2]; 491 | $pos2 = []; 492 | $pos2["x"] = $this->hill[1][0]; 493 | $pos2["y"] = $this->hill[1][1]; 494 | $pos2["z"] = $this->hill[1][2]; 495 | $minX = min($pos2["x"],$pos1["x"]); 496 | $maxX = max($pos2["x"],$pos1["x"]); 497 | $minY = min($pos2["y"],$pos1["y"]); 498 | $maxY = max($pos2["y"],$pos1["y"]); 499 | $minZ = min($pos2["z"],$pos1["z"]); 500 | $maxZ = max($pos2["z"],$pos1["z"]); 501 | $this->playersInBox = []; 502 | 503 | if($minY == $maxY){ 504 | $maxY += 1.51; 505 | } //To allow jumping, shouldn't affect whatsoever. 506 | 507 | foreach($this->players as $playerName){ 508 | $player = $this->plugin->getServer()->getPlayerExact($playerName); 509 | if($player === null) continue; 510 | $player = $player->getLocation(); 511 | if(($minX <= $player->getX() && $player->getX() <= $maxX && $minY <= $player->getY() && $player->getY() <= $maxY && $minZ <= $player->getZ() && $player->getZ() <= $maxZ)){ 512 | $this->playersInBox[] = $playerName; 513 | } 514 | } 515 | return $this->playersInBox; 516 | } 517 | 518 | public function getKing(): ?string{ 519 | return $this->king; 520 | } 521 | 522 | public function removeKing(): void{ 523 | if($this->king === null) return; 524 | $this->broadcastMessage(str_replace("{PLAYER}", $this->king, $this->plugin->utils->colourise((string)$this->plugin->getMessages()->getNested("broadcasts.fallen_king", "{PREFIX}{RED}The king {AQUA}'{PLAYER}'{RED} has fallen.")))); 525 | $this->changeking(); 526 | } 527 | 528 | public function changeKing(): void{ 529 | if($this->king !== null){ 530 | $this->oldKing = $this->king; 531 | $this->king = null; 532 | } 533 | $this->updateKingTextParticle(); 534 | } 535 | 536 | /** 537 | * @return bool 538 | */ 539 | public function checkNewKing(): bool{ 540 | if(count($this->getPlayersInBox()) === 0){ 541 | return false; 542 | }else{ 543 | $player = $this->playersInBox[array_rand($this->playersInBox)]; 544 | $this->broadcastMessage(str_replace("{PLAYER}", $player, $this->plugin->utils->colourise((string)$this->plugin->getMessages()->getNested("broadcasts.new_king", "{PREFIX}{GOLD}{PLAYER} {GREEN}Has claimed the throne, how long will it last...")))); 545 | $this->king = $player; 546 | $this->updateKingTextParticle(); 547 | return true; 548 | } 549 | } 550 | 551 | 552 | /** 553 | * @param Player $player 554 | * @param string $reason 555 | * @param bool $silent 556 | * 557 | * @return void 558 | */ 559 | public function removePlayer(Player $player, string $reason, bool $silent = false): void{ 560 | $event = new ArenaRemovePlayerEvent($this->plugin, $this, $player, $reason, $silent); 561 | $event->call(); 562 | if($event->isCancelled()){ 563 | if(!$player->isConnected()){ 564 | //Player is leaving server. 565 | $this->plugin->getLogger()->warning(Main::PREFIX . C::RED . "Event cancelled, but player is leaving server so will be removed anyway."); 566 | }else{ 567 | $player->sendMessage(Main::PREFIX.C::RED."Cannot leave the arena, reason: ".$event->getReason()); 568 | return; 569 | } 570 | } 571 | if($silent === false){ 572 | $this->broadcastQuit($player, $reason); 573 | } 574 | unset($this->players[array_search(strtolower($player->getName()), $this->players)]); 575 | if($this->king === strtolower($player->getName())){ 576 | $this->removeKing(); 577 | } 578 | $this->checkStatus(); 579 | $this->updateKingTextParticle(); 580 | if($player->isOnline() and $player->spawned !== false){ //check to avoid tp if player left server. 581 | $pos = new Position((float)$this->playerOldPositions[strtolower($player->getName())][1], (float)$this->playerOldPositions[strtolower($player->getName())][2], (float)$this->playerOldPositions[strtolower($player->getName())][3], $this->plugin->getServer()->getWorldManager()->getWorldByName((string)$this->playerOldPositions[strtolower($player->getName())][0])); 582 | $player->teleport($pos); 583 | $player->setImmobile(false); 584 | unset($this->playerOldPositions[strtolower($player->getName())]); 585 | } 586 | } 587 | 588 | /** 589 | * Returns false if player cannot join. 590 | * 591 | * @param Player $player 592 | * 593 | * @return bool 594 | */ 595 | public function addPlayer(Player $player): bool{ 596 | if($this->plugin->getArenaByPlayer(strtolower($player->getName())) !== null){ 597 | $player->sendMessage(Main::PREFIX.C::RED."You are in a arena, type /koth leave before joining another one."); 598 | return false; 599 | } 600 | switch($this->status){ 601 | case self::STATUS_NOT_READY: 602 | $player->sendMessage(Main::PREFIX.C::RED."This arena has not been setup."); 603 | return false; 604 | case self::STATUS_FULL: 605 | $player->sendMessage(Main::PREFIX.C::RED."This arena is full."); 606 | return false; 607 | case self::STATUS_INVALID: 608 | $player->sendMessage(Main::PREFIX.C::RED."This arena has been setup in a place that no longer exists."); 609 | return false; 610 | case self::STATUS_UNKNOWN: 611 | $player->sendMessage(Main::PREFIX.C::RED."This arena has a unknown status."); 612 | return false; 613 | } 614 | $event = new ArenaAddPlayerEvent($this->plugin, $this, $player); 615 | $event->call(); 616 | if($event->isCancelled()){ 617 | $player->sendMessage(Main::PREFIX.C::RED."Unable to join arena, reason: ".$event->getReason()); 618 | return false; 619 | } 620 | 621 | $this->playerOldPositions[strtolower($player->getName())] = [$player->getWorld()->getDisplayName(), $player->getLocation()->getX(), $player->getLocation()->getY(), $player->getLocation()->getZ()]; 622 | if(!$this->spawnPlayer($player)){ 623 | unset($this->playerOldPositions[strtolower($player->getName())]); 624 | return false; 625 | } 626 | $player->setGamemode(GameMode::SURVIVAL()); //todo Beta4 configurable. 627 | $player->setImmobile(true); 628 | $this->players[] = strtolower($player->getName()); 629 | $this->updateKingTextParticle(); 630 | $this->broadcastJoin($player); 631 | if(count($this->players) >= $this->minPlayers && $this->timerTask === null && $this->plugin->getConfig()->get("auto_start", true) === true){ 632 | $this->startTimer(); 633 | } 634 | $this->checkStatus(); 635 | return true; 636 | } 637 | 638 | public function getTime(): int{ 639 | return $this->time; 640 | } 641 | 642 | /** 643 | * @return string[] 644 | */ 645 | public function getRewards(): array{ 646 | return $this->rewards; 647 | } 648 | 649 | /** 650 | * @return float[][]|int[][] 651 | */ 652 | public function getHill(): array{ 653 | return $this->hill; 654 | } 655 | 656 | public function setWorld(string $worldName): void{ 657 | $this->world = $worldName; 658 | } 659 | 660 | /** 661 | * @param float[][]|int[][] $hill 662 | * @return void 663 | */ 664 | public function setHill(array $hill): void{ 665 | foreach($hill as $point){ 666 | if(count($point) !== 3){ 667 | throw new InvalidArgumentException("Invalid hill point, must be an array of length 3."); 668 | } 669 | foreach($point as $value){ 670 | if(!is_numeric($value)){ 671 | throw new InvalidArgumentException("Invalid hill point, must be an array of 3 floats or ints."); 672 | } 673 | } 674 | } 675 | $this->hill = $hill; 676 | } 677 | 678 | /** 679 | * @return float[][]|int[][] 680 | */ 681 | public function getSpawns(): array{ 682 | return $this->spawns; 683 | } 684 | 685 | /** 686 | * @param float[][]|int[][] $spawns 687 | * @return void 688 | */ 689 | public function setSpawns(array $spawns): void{ 690 | foreach($spawns as $spawn){ 691 | if(count($spawn) !== 3){ 692 | throw new InvalidArgumentException("Invalid spawn point, must be an array of length 3."); 693 | } 694 | foreach($spawn as $value){ 695 | if(!is_numeric($value)){ 696 | throw new InvalidArgumentException("Invalid spawn point, must be an array of 3 floats or ints."); 697 | } 698 | } 699 | } 700 | $this->spawns = $spawns; 701 | } 702 | 703 | /** 704 | * @param string[] $rewards 705 | * @return void 706 | */ 707 | public function setRewards(array $rewards): void{ 708 | $this->rewards = $rewards; 709 | } 710 | 711 | public function getCountDown(): int{ 712 | return $this->countDown; 713 | } 714 | 715 | public function getMinPlayers(): int{ 716 | return $this->minPlayers; 717 | } 718 | 719 | public function getMaxPlayers(): int{ 720 | return $this->maxPlayers; 721 | } 722 | 723 | public function getWorld(): string{ 724 | return $this->world; 725 | } 726 | } -------------------------------------------------------------------------------- /src/CommandHandler.php: -------------------------------------------------------------------------------- 1 | . 19 | * 20 | * Twitter :: @JaxkDev 21 | * Discord :: JaxkDev#2698 22 | * Email :: JaxkDev@gmail.com 23 | */ 24 | 25 | namespace JaxkDev\KOTH; 26 | 27 | use JaxkDev\KOTH\Events\ArenaCreateEvent; 28 | use JaxkDev\KOTH\Events\ArenaDeleteEvent; 29 | use pocketmine\console\ConsoleCommandSender; 30 | use pocketmine\player\Player; 31 | use pocketmine\utils\TextFormat as C; 32 | 33 | class CommandHandler{ 34 | private Main $plugin; 35 | 36 | public function __construct(Main $plugin){ 37 | $this->plugin = $plugin; 38 | } 39 | 40 | /** 41 | * @param Player|ConsoleCommandSender $player 42 | * @param string[] $args 43 | * @return void 44 | */ 45 | public function handleCommand(Player|ConsoleCommandSender $player, array $args): void{ 46 | switch($args[0]??"help"){ 47 | case 'help': 48 | $player->sendMessage(C::YELLOW."[".C::AQUA."KOTH ".C::RED."-".C::GREEN."CONSOLE HELP".C::YELLOW."]"); 49 | $player->sendMessage(C::GOLD."/koth help ".C::RESET."- Sends help :)"); 50 | $player->sendMessage(C::GOLD."/koth credits ".C::RESET."- Display the credits."); 51 | if(!$player instanceof Player){ 52 | $player->sendMessage(C::GOLD."/koth list ".C::RESET."- List all arena's setup and ready to play !"); 53 | $player->sendMessage(C::GOLD."/koth info (arena name) ".C::RESET."- Get more info on one arena."); 54 | $player->sendMessage(C::GOLD."/koth start (arena name) ".C::RESET."- Starts a arena if game requirements are met."); 55 | $player->sendMessage(C::GOLD."/koth forcestart (arena name) ".C::RESET."- Forces a arena/game to start the countdown to begin."); 56 | $player->sendMessage(C::GOLD."/koth enable (arena name)".C::RESET." - Enables a disabled arena, when enabled players can join etc."); 57 | $player->sendMessage(C::GOLD."/koth disable (arena name".C::RESET." - Disable a arena, when disabled no one can use it at all."); 58 | }else{ 59 | if($player->hasPermission("koth.command.list")) $player->sendMessage(C::GOLD."/koth list ".C::RESET."- List all arena's setup and ready to play !"); 60 | if($player->hasPermission("koth.command.info")) $player->sendMessage(C::GOLD."/koth info (arena name) ".C::RESET."- Get more info on one arena."); 61 | if($player->hasPermission("koth.command.join")) $player->sendMessage(C::GOLD."/koth join (arena name)".C::RESET." - Join a game."); 62 | if($player->hasPermission("koth.command.leave")) $player->sendMessage(C::GOLD."/koth leave ".C::RESET."- Leave a game you'r currently in."); 63 | if($player->hasPermission("koth.command.start")) $player->sendMessage(C::GOLD."/koth start (arena name - optional) ".C::RESET."- Starts a arena if game requirements are met."); 64 | if($player->hasPermission("koth.command.forcestart")) $player->sendMessage(C::GOLD."/koth forcestart (arena name - optional) ".C::RESET."- Forces a arena/game to start the countdown to begin."); 65 | if($player->hasPermission("koth.command.create")){ 66 | $player->sendMessage(C::GOLD."/koth create (arena name - no spaces) (min players) (max players) (gametime in seconds)".C::RESET." - Start the setup process of making a new arena."); 67 | $player->sendMessage(C::GOLD."/koth setspawn (arena name) ".C::RESET."- Set a spawn point for a arena."); 68 | $player->sendMessage(C::GOLD."/koth setpos1 (arena name) or /koth setpos2 (arena name> ".C::RESET."- Set king area corner to corner."); 69 | } 70 | if($player->hasPermission("koth.command.delete")) $player->sendMessage(C::GOLD."/koth delete (arena name)".C::RESET." - Delete a area that has been setup."); 71 | if($player->hasPermission("koth.command.enable")) $player->sendMessage(C::GOLD."/koth enable (arena name)".C::RESET." - Enables a disabled arena, when enabled players can join etc."); 72 | if($player->hasPermission("koth.command.disable")) $player->sendMessage(C::GOLD."/koth disable (arena name".C::RESET." - Disable a arena, when disabled no one can use it at all."); 73 | if($player->hasPermission("koth.command.rewards")) $player->sendMessage(C::GOLD."/koth addreward (arena name) (command eg. /give {PLAYER} 20 1)".C::RESET." - Add a command to execute when winner is announced"); 74 | } 75 | return; 76 | case 'credits': 77 | $player->sendMessage(C::YELLOW."[".C::AQUA."KOTH ".C::RED."-".C::GREEN." CREDITS".C::YELLOW."]"); 78 | $player->sendMessage(C::AQUA."Developer: ".C::GOLD."JaxkDev"); 79 | $player->sendMessage(C::AQUA."Icon creator: ".C::GOLD."WowAssasin#6608"); 80 | return; 81 | case 'list': 82 | if(!$player->hasPermission("koth.command.list")){ 83 | $player->sendMessage($this->plugin->utils->colourise((string)$this->plugin->getMessages()->getNested("commands.no_perms", "{PREFIX}{RED}You do not have permission to use this command!"))); 84 | return; 85 | } 86 | $this->listArenas($player); 87 | return; 88 | case 'remove': 89 | case 'delete': 90 | if($player instanceof ConsoleCommandSender){ 91 | $player->sendMessage($this->plugin->utils->colourise((string)$this->plugin->getMessages()->getNested("commands.in_game", "{PREFIX}{RED}Commands can only be run in-game."))); 92 | return; 93 | } 94 | if(!$player->hasPermission("koth.command.delete")){ 95 | $player->sendMessage($this->plugin->utils->colourise((string)$this->plugin->getMessages()->getNested("commands.no_perms", "{PREFIX}{RED}You do not have permission to use this command!"))); 96 | return; 97 | } 98 | $this->deleteArena($player, $args); 99 | return; 100 | case 'create': 101 | case 'new': 102 | if($player instanceof ConsoleCommandSender){ 103 | $player->sendMessage($this->plugin->utils->colourise((string)$this->plugin->getMessages()->getNested("commands.in_game", "{PREFIX}{RED}Commands can only be run in-game."))); 104 | return; 105 | } 106 | if(!$player->hasPermission("koth.command.create")){ 107 | $player->sendMessage($this->plugin->utils->colourise((string)$this->plugin->getMessages()->getNested("commands.no_perms", "{PREFIX}{RED}You do not have permission to use this command!"))); 108 | return; 109 | } 110 | $this->createArena($player, $args); 111 | return; 112 | 113 | case 'quit': 114 | case 'exit': 115 | case 'leave': 116 | if($player instanceof ConsoleCommandSender){ 117 | $player->sendMessage($this->plugin->utils->colourise((string)$this->plugin->getMessages()->getNested("commands.in_game", "{PREFIX}{RED}Commands can only be run in-game."))); 118 | return; 119 | } 120 | if(!$player->hasPermission("koth.command.leave")){ 121 | $player->sendMessage($this->plugin->utils->colourise((string)$this->plugin->getMessages()->getNested("commands.no_perms", "{PREFIX}{RED}You do not have permission to use this command!"))); 122 | return; 123 | } 124 | $arena = $this->plugin->getArenaByPlayer(strtolower($player->getName())); 125 | if($arena === null){ 126 | $player->sendMessage($this->plugin->utils->colourise((string)$this->plugin->getMessages()->getNested("commands.not_in_game_leave", "{PREFIX}{RED}Your not in a game, so how can you leave a game..."))); 127 | return; 128 | } 129 | $arena->removePlayer($player, $this->plugin->utils->colourise((string)$this->plugin->getMessages()->getNested("arenas.leave_message", "Chickened Out."))); 130 | return; 131 | 132 | case 'join': 133 | if($player instanceof ConsoleCommandSender){ 134 | $player->sendMessage($this->plugin->utils->colourise((string)$this->plugin->getMessages()->getNested("commands.in_game", "{PREFIX}{RED}Commands can only be run in-game."))); 135 | return; 136 | } 137 | if(!$player->hasPermission("koth.command.join")){ 138 | $player->sendMessage($this->plugin->utils->colourise((string)$this->plugin->getMessages()->getNested("commands.no_perms", "{PREFIX}{RED}You do not have permission to use this command!"))); 139 | return; 140 | } 141 | if($this->plugin->getArenaByPlayer(strtolower($player->getName())) !== null){ 142 | $player->sendMessage($this->plugin->utils->colourise((string)$this->plugin->getMessages()->getNested("commands.in_game_join", "{PREFIX}{RED}Your currently in a game, please leave the game using /koth leave to join another one."))); 143 | return; 144 | } 145 | if(count($args) !== 2){ 146 | $player->sendMessage(str_replace("{USAGE}", "/koth join (arena name)", $this->plugin->utils->colourise((string)$this->plugin->getMessages()->getNested("commands.usage", "{PREFIX}{RED}Usage Incorrect, {USAGE}")))); 147 | return; 148 | } 149 | $arena = $this->plugin->getArenaByName($args[1]); 150 | if($arena === null){ 151 | $player->sendMessage($this->plugin->utils->colourise((string)$this->plugin->getMessages()->getNested("commands.not_exist", "{PREFIX}{RED}The specified arena does not exist."))); 152 | return; 153 | } 154 | $arena->addPlayer($player); 155 | return; 156 | 157 | case 'details': 158 | case 'info': 159 | if(!$player->hasPermission("koth.command.info")){ 160 | $player->sendMessage($this->plugin->utils->colourise((string)$this->plugin->getMessages()->getNested("commands.no_perms", "{PREFIX}{RED}You do not have permission to use this command!"))); 161 | return; 162 | } 163 | if(count($args) !== 2){ 164 | $player->sendMessage(str_replace("{USAGE}", "/koth info (arena name)", $this->plugin->utils->colourise((string)$this->plugin->getMessages()->getNested("commands.usage", "{PREFIX}{RED}Usage Incorrect, {USAGE}")))); 165 | return; 166 | } 167 | 168 | $arena = $this->plugin->getArenaByName($args[1]); 169 | if($arena === null){ 170 | $player->sendMessage($this->plugin->utils->colourise((string)$this->plugin->getMessages()->getNested("commands.not_exist", "{PREFIX}{RED}The specified arena does not exist."))); 171 | return; 172 | } 173 | $name = $arena->getName(); 174 | $status = $arena->getFriendlyStatus(); 175 | $players = count($arena->getPlayers()); 176 | $spawns = count($arena->getSpawns()); 177 | $rewards = $arena->getRewards(); 178 | $gameTime = $arena->getTime(); 179 | 180 | $player->sendMessage(Main::PREFIX.C::AQUA.$name." Info:"); 181 | $player->sendMessage(C::GREEN."Status : ".C::BLUE.$status); 182 | $player->sendMessage(C::GREEN."Gametime: ".C::BLUE.$gameTime." Seconds."); 183 | $player->sendMessage(C::GREEN."Players : ".C::BLUE.$players); 184 | $player->sendMessage(C::GREEN."Spawns : ".C::BLUE.$spawns); 185 | $player->sendMessage(C::GREEN."Rewards :"); 186 | foreach($rewards as $reward){ 187 | $player->sendMessage("- ".C::AQUA.$reward); 188 | } 189 | return; 190 | 191 | case 'start': 192 | if(!$player->hasPermission("koth.command.start")){ 193 | $player->sendMessage($this->plugin->utils->colourise((string)$this->plugin->getMessages()->getNested("commands.no_perms", "{PREFIX}{RED}You do not have permission to use this command!"))); 194 | return; 195 | } 196 | if(count($args) < 2 and $this->plugin->getArenaByPlayer(strtolower($player->getName())) === null){ 197 | $player->sendMessage(str_replace("{USAGE}", "/koth start (arena name)", $this->plugin->utils->colourise((string)$this->plugin->getMessages()->getNested("commands.usage", "{PREFIX}{RED}Usage Incorrect, {USAGE}")))); 198 | return; 199 | } 200 | $arena = $this->plugin->getArenaByPlayer(strtolower($player->getName())); 201 | if($arena === null){ 202 | $arena = $this->plugin->getArenaByName($args[1]); 203 | } 204 | if($arena === null){ 205 | $player->sendMessage($this->plugin->utils->colourise((string)$this->plugin->getMessages()->getNested("commands.not_exist", "{PREFIX}{RED}The specified arena does not exist."))); 206 | return; 207 | } 208 | if($arena->getStatus() === Arena::STATUS_STARTED){ 209 | $player->sendMessage(Main::PREFIX.C::RED."Arena already started."); 210 | return; 211 | } 212 | if($arena->getStatus() !== $arena::STATUS_READY){ 213 | $player->sendMessage(Main::PREFIX.C::RED."Arena is not 'ready' and so cannot be started."); 214 | return; 215 | } 216 | $result = $arena->startTimer(); 217 | if($result !== null){ 218 | $player->sendMessage(Main::PREFIX.C::RED."Arena not started because: ".C::RESET.$result); 219 | return; 220 | } 221 | $player->sendMessage(Main::PREFIX.C::GREEN."Arena starting now..."); 222 | return; 223 | 224 | case 'forcestart': 225 | if(!$player->hasPermission("koth.command.forcestart")){ 226 | $player->sendMessage($this->plugin->utils->colourise((string)$this->plugin->getMessages()->getNested("commands.no_perms", "{PREFIX}{RED}You do not have permission to use this command!"))); 227 | return; 228 | } 229 | if(count($args) < 2){ 230 | $player->sendMessage(str_replace("{USAGE}", "/koth forcestart (arena name)", $this->plugin->utils->colourise((string)$this->plugin->getMessages()->getNested("commands.usage", "{PREFIX}{RED}Usage Incorrect, {USAGE}")))); 231 | return; 232 | } 233 | 234 | $arena = $this->plugin->getArenaByName($args[1]); 235 | if($arena === null){ 236 | $player->sendMessage($this->plugin->utils->colourise((string)$this->plugin->getMessages()->getNested("commands.not_exist", "{PREFIX}{RED}The specified arena does not exist."))); 237 | return; 238 | } 239 | if($arena->getStatus() === Arena::STATUS_STARTED){ 240 | $player->sendMessage(Main::PREFIX.C::RED."Arena already started."); 241 | return; 242 | } 243 | if($arena->getStatus() === $arena::STATUS_DISABLED or $arena->getStatus() === $arena::STATUS_INVALID){ 244 | $player->sendMessage(Main::PREFIX.C::RED."Cannot force a disabled/invalid arena."); 245 | return; 246 | } 247 | $result = $arena->startTimer(true); 248 | if($result !== null){ 249 | $player->sendMessage(Main::PREFIX.C::RED."Arena not started because: ".C::RESET.$result); 250 | return; 251 | } 252 | $player->sendMessage(Main::PREFIX.C::GREEN."Arena starting now..."); 253 | return; 254 | 255 | case 'enable': 256 | if(!$player->hasPermission("koth.command.enable")){ 257 | $player->sendMessage($this->plugin->utils->colourise((string)$this->plugin->getMessages()->getNested("commands.no_perms", "{PREFIX}{RED}You do not have permission to use this command!"))); 258 | return; 259 | } 260 | if(count($args) < 2){ 261 | $player->sendMessage(str_replace("{USAGE}", "/koth enable (arena name)", $this->plugin->utils->colourise((string)$this->plugin->getMessages()->getNested("commands.usage", "{PREFIX}{RED}Usage Incorrect, {USAGE}")))); 262 | return; 263 | } 264 | 265 | $arena = $this->plugin->getArenaByName($args[1]); 266 | if($arena === null){ 267 | $player->sendMessage($this->plugin->utils->colourise((string)$this->plugin->getMessages()->getNested("commands.not_exist", "{PREFIX}{RED}The specified arena does not exist."))); 268 | return; 269 | } 270 | if($arena->getStatus() !== $arena::STATUS_DISABLED){ 271 | $player->sendMessage(Main::PREFIX.C::RED."Arena is not disabled so how can you enable it..."); 272 | return; 273 | } 274 | if($arena->enable()) $player->sendMessage(Main::PREFIX.C::GREEN."Arena has been enabled."); 275 | else $player->sendMessage(Main::PREFIX.C::RED."Arena could not be enabled."); 276 | return; 277 | 278 | case 'disable': 279 | if(!$player->hasPermission("koth.command.disable")){ 280 | $player->sendMessage($this->plugin->utils->colourise((string)$this->plugin->getMessages()->getNested("commands.no_perms", "{PREFIX}{RED}You do not have permission to use this command!"))); 281 | return; 282 | } 283 | if(count($args) < 2){ 284 | $player->sendMessage(str_replace("{USAGE}", "/koth disable (arena name)", $this->plugin->utils->colourise((string)$this->plugin->getMessages()->getNested("commands.usage", "{PREFIX}{RED}Usage Incorrect, {USAGE}")))); 285 | return; 286 | } 287 | 288 | $arena = $this->plugin->getArenaByName($args[1]); 289 | if($arena === null){ 290 | $player->sendMessage($this->plugin->utils->colourise((string)$this->plugin->getMessages()->getNested("commands.not_exist", "{PREFIX}{RED}The specified arena does not exist."))); 291 | return; 292 | } 293 | if($arena->getStatus() === $arena::STATUS_DISABLED){ 294 | $player->sendMessage(Main::PREFIX.C::RED."Arena is not enabled so how can you enable it..."); 295 | return; 296 | } 297 | if($arena->disable()) $player->sendMessage(Main::PREFIX.C::GREEN."Arena has been disabled."); 298 | else $player->sendMessage(Main::PREFIX.C::RED."Arena could not be disabled, make sure its empty and its not running before disabling."); 299 | //TODO force enable/disable. 300 | return; 301 | 302 | //////-----Arena Setup------/////// 303 | case 'setpos1': 304 | if($player instanceof ConsoleCommandSender){ 305 | $player->sendMessage($this->plugin->utils->colourise((string)$this->plugin->getMessages()->getNested("commands.in_game", "{PREFIX}{RED}Commands can only be run in-game."))); 306 | return; 307 | } 308 | //Set position one of the hill. 309 | if(!$player->hasPermission("koth.command.create")){ 310 | $player->sendMessage($this->plugin->utils->colourise((string)$this->plugin->getMessages()->getNested("commands.no_perms", "{PREFIX}{RED}You do not have permission to use this command!"))); 311 | return; 312 | } 313 | $pos = $player->getPosition(); 314 | $point = [$pos->x, $pos->y, $pos->z]; 315 | if(count($args) !== 2){ 316 | $player->sendMessage(str_replace("{USAGE}", "/koth setpos1 (arena name)", $this->plugin->utils->colourise((string)$this->plugin->getMessages()->getNested("commands.usage", "{PREFIX}{RED}Usage Incorrect, {USAGE}")))); 317 | return; 318 | } 319 | $arena = $this->plugin->getArenaByName($args[1]); 320 | if($arena === null){ 321 | $player->sendMessage($this->plugin->utils->colourise((string)$this->plugin->getMessages()->getNested("commands.not_exist", "{PREFIX}{RED}The specified arena does not exist."))); 322 | return; 323 | } 324 | $hill = $arena->getHill(); 325 | $hill[0] = $point; 326 | if(isset($arena->getHill()[0])){ 327 | $arena->setHill($hill); 328 | $arena->setWorld($player->getWorld()->getDisplayName()); 329 | $player->sendMessage(Main::PREFIX.C::GREEN."Position 1 Re-set"); 330 | return; 331 | } 332 | $arena->setHill($hill); 333 | $arena->setWorld($player->getWorld()->getDisplayName()); 334 | $player->sendMessage(Main::PREFIX.C::GREEN."Position 1 set, be sure to do /koth setpos2 ".$arena->getName()); 335 | return; 336 | 337 | case 'setpos2': 338 | if($player instanceof ConsoleCommandSender){ 339 | $player->sendMessage($this->plugin->utils->colourise((string)$this->plugin->getMessages()->getNested("commands.in_game", "{PREFIX}{RED}Commands can only be run in-game."))); 340 | return; 341 | } 342 | if(!$player->hasPermission("koth.command.create")){ 343 | $player->sendMessage($this->plugin->utils->colourise((string)$this->plugin->getMessages()->getNested("commands.no_perms", "{PREFIX}{RED}You do not have permission to use this command!"))); 344 | return; 345 | } 346 | $pos = $player->getPosition(); 347 | $point = [$pos->x, $pos->y, $pos->z]; 348 | if(count($args) !== 2){ 349 | $player->sendMessage(str_replace("{USAGE}", "/koth setpos2 (arena name)", $this->plugin->utils->colourise((string)$this->plugin->getMessages()->getNested("commands.usage", "{PREFIX}{RED}Usage Incorrect, {USAGE}")))); 350 | return; 351 | } 352 | $arena = $this->plugin->getArenaByName($args[1]); 353 | if($arena === null){ 354 | $player->sendMessage($this->plugin->utils->colourise((string)$this->plugin->getMessages()->getNested("commands.not_exist", "{PREFIX}{RED}The specified arena does not exist."))); 355 | return; 356 | } 357 | $hill = $arena->getHill(); 358 | $hill[1] = $point; 359 | if(count($arena->getHill()) === 2){ 360 | $arena->setHill($hill); 361 | $player->sendMessage(Main::PREFIX.C::GREEN."Position 2 re-set"); 362 | return; 363 | } 364 | if(count($arena->getHill()) === 0){ 365 | $arena->setHill($hill); 366 | $player->sendMessage(Main::PREFIX.C::RED."Position 2 set, please use /koth setpos1 ".$arena->getName()." as well !"); 367 | return; 368 | } 369 | $arena->setHill($hill); 370 | $arena->checkStatus(); 371 | $player->sendMessage(Main::PREFIX.C::GREEN."Position 2 set, be sure to setup some spawn point '/koth setspawn ".$arena->getName()); 372 | return; 373 | 374 | case 'setspawn': 375 | //Set a spawn position 376 | if($player instanceof ConsoleCommandSender){ 377 | $player->sendMessage($this->plugin->utils->colourise((string)$this->plugin->getMessages()->getNested("commands.in_game", "{PREFIX}{RED}Commands can only be run in-game."))); 378 | return; 379 | } 380 | if(!$player->hasPermission("koth.command.create")){ 381 | $player->sendMessage($this->plugin->utils->colourise((string)$this->plugin->getMessages()->getNested("commands.no_perms", "{PREFIX}{RED}You do not have permission to use this command!"))); 382 | return; 383 | } 384 | $pos = $player->getPosition(); 385 | $point = [$pos->x, $pos->y, $pos->z]; 386 | if(count($args) !== 2){ 387 | $player->sendMessage(str_replace("{USAGE}", "/koth setspawn (arena name)", $this->plugin->utils->colourise((string)$this->plugin->getMessages()->getNested("commands.usage", "{PREFIX}{RED}Usage Incorrect, {USAGE}")))); 388 | return; 389 | } 390 | $arena = $this->plugin->getArenaByName($args[1]); 391 | if($arena === null){ 392 | $player->sendMessage($this->plugin->utils->colourise((string)$this->plugin->getMessages()->getNested("commands.not_exist", "{PREFIX}{RED}The specified arena does not exist."))); 393 | return; 394 | } 395 | $spawns = $arena->getSpawns(); 396 | $spawns[] = $point; 397 | $arena->setSpawns($spawns); 398 | $arena->checkStatus(); 399 | $player->sendMessage(Main::PREFIX.C::GREEN."Spawn position added."); 400 | return; 401 | 402 | case 'addreward': 403 | if(!$player->hasPermission("koth.command.rewards")){ 404 | $player->sendMessage($this->plugin->utils->colourise((string)$this->plugin->getMessages()->getNested("commands.no_perms", "{PREFIX}{RED}You do not have permission to use this command!"))); 405 | return; 406 | } 407 | if(count($args) <= 2){ 408 | $player->sendMessage(str_replace("{USAGE}", " /koth addreward (arena name) (command eg. give {PLAYER} 20 1)", $this->plugin->utils->colourise((string)$this->plugin->getMessages()->getNested("commands.usage", "{PREFIX}{RED}Usage Incorrect, {USAGE}")))); 409 | return; 410 | } 411 | $arena = $this->plugin->getArenaByName($args[1]); 412 | if($arena === null){ 413 | $player->sendMessage($this->plugin->utils->colourise((string)$this->plugin->getMessages()->getNested("commands.not_exist", "{PREFIX}{RED}The specified arena does not exist."))); 414 | return; 415 | } 416 | if($args[2][0] === "/"){ 417 | $args[2] = substr($args[2], 1); 418 | } 419 | unset($args[0]); 420 | unset($args[1]); 421 | $cmd = array_values($args); 422 | $rewards = $arena->getRewards(); 423 | $rewards[] = implode(" ", $cmd); 424 | $arena->setRewards($rewards); 425 | $this->plugin->updateArena($arena); 426 | $player->sendMessage(Main::PREFIX.C::GREEN."Reward added to the ".$arena->getName()." Arena."); 427 | return; 428 | } 429 | $player->sendMessage($this->plugin->utils->colourise((string)$this->plugin->getMessages()->getNested("commands.unknown", "{PREFIX}{RED}Unknown command, try /koth help"))); 430 | } 431 | 432 | private function listArenas(Player|ConsoleCommandSender $player): void{ 433 | $list = $this->plugin->getAllArenas(); 434 | if(count($list) === 0){ 435 | $player->sendMessage(Main::PREFIX.C::RED."There are no arena's"); 436 | return; 437 | } 438 | $player->sendMessage(Main::PREFIX.C::RED.count($list).C::GOLD." Arena(s) - ".C::RED."Arena Name | Arena Status"); 439 | foreach($list as $arena){ 440 | $player->sendMessage(C::GREEN.$arena->getName().C::RED." | ".C::AQUA.$arena->getFriendlyStatus()); 441 | } 442 | } 443 | 444 | 445 | /** 446 | * @param Player|ConsoleCommandSender $player 447 | * @param string[] $args 448 | * @return void 449 | */ 450 | protected function deleteArena(Player|ConsoleCommandSender $player, array $args): void{ 451 | if(count($args) !== 2){ 452 | $player->sendMessage(str_replace("{USAGE}", "/koth delete (arena name)", $this->plugin->utils->colourise((string)$this->plugin->getMessages()->getNested("commands.usage", "{PREFIX}{RED}Usage Incorrect, {USAGE}")))); 453 | return; 454 | } 455 | $arena = $this->plugin->getArenaByName($args[1]); 456 | if($arena === null){ 457 | $player->sendMessage($this->plugin->utils->colourise((string)$this->plugin->getMessages()->getNested("commands.not_exist", "{PREFIX}{RED}The specified arena does not exist."))); 458 | return; 459 | } 460 | if($arena->getStatus() === Arena::STATUS_STARTED){ 461 | $player->sendMessage($this->plugin->utils->colourise((string)$this->plugin->getMessages()->getNested("commands.not_while_running", "{PREFIX}{RED}That arena is currently running, please stop it first."))); 462 | return; 463 | } 464 | 465 | $event = new ArenaDeleteEvent($this->plugin, $player, $arena); 466 | $event->call(); 467 | 468 | if($event->isCancelled()){ 469 | $player->sendMessage(Main::PREFIX.C::RED."Arena not removed, reason: ".$event->getReason()); 470 | return; 471 | } 472 | 473 | $this->plugin->deleteArena($arena); 474 | $player->sendMessage(Main::PREFIX.C::GREEN."Arena Removed."); 475 | } 476 | 477 | /** 478 | * @param Player|ConsoleCommandSender $player 479 | * @param string[] $args 480 | * @return void 481 | */ 482 | protected function createArena(Player|ConsoleCommandSender $player, array $args): void{ 483 | $usage = "/koth create (arena name - no spaces) (min players) (max players) (gametime in seconds)"; 484 | 485 | if(count($args) !== 5){ 486 | $player->sendMessage(str_replace("{USAGE}", $usage, $this->plugin->utils->colourise((string)$this->plugin->getMessages()->getNested("commands.usage", "{PREFIX}{RED}Usage Incorrect, {USAGE}")))); 487 | return; 488 | } 489 | 490 | $name = $args[1]; 491 | $min = $args[2]; 492 | $max = $args[3]; 493 | $gameTime = $args[4]; 494 | 495 | if($this->plugin->getArenaByName($name) !== null){ 496 | $player->sendMessage(Main::PREFIX.C::RED."A arena with that name already exists."); 497 | return; 498 | } 499 | if(!is_numeric($min)){ 500 | $player->sendMessage(Main::PREFIX.C::RED."Min value must be a number."); 501 | return; 502 | } 503 | if(intval($min) < 2){ 504 | $player->sendMessage(Main::PREFIX.C::RED."minimum value must be above 2."); 505 | return; 506 | } 507 | if(!is_numeric($max)){ 508 | $player->sendMessage(Main::PREFIX.C::RED."Max value must be a number."); 509 | return; 510 | } 511 | if(intval($max) <= intval($min)){ 512 | $player->sendMessage(Main::PREFIX.C::RED."Cant play with 1 player, make sure max value is bigger then min."); 513 | return; 514 | } 515 | 516 | if(!is_numeric($gameTime)){ 517 | $player->sendMessage(Main::PREFIX.C::RED."Game time must be a number."); 518 | return; 519 | } 520 | if(intval($gameTime) < 5){ 521 | $player->sendMessage(Main::PREFIX.C::RED."Game time has to be above 5 seconds."); 522 | return; 523 | } 524 | 525 | $event = new ArenaCreateEvent($this->plugin, $player, $name, intval($min), intval($max), intval($gameTime)); 526 | $event->call(); 527 | 528 | if($event->isCancelled()){ 529 | $player->sendMessage(Main::PREFIX.C::RED."Arena not created, reason: ".$event->getReason()); 530 | return; 531 | } 532 | 533 | $arena = new Arena($this->plugin, $event->getName(), $event->getMinPlayers(), $event->getMaxPlayers(), $event->getGameTime(), $event->getHillPositions(), $event->getSpawnPositions(), $event->getRewards(), $event->getWorld()); 534 | $this->plugin->createArena($arena); 535 | 536 | $player->sendMessage(Main::PREFIX.C::GREEN."Nice one, ".$name." arena is almost fully setup, to complete the arena setup be sure to do '/koth setpos1 (arena name)' when standing on pos 1, and '/koth setpos2 (arena name)' when standing in the opposite corner."); 537 | $player->sendMessage(C::GREEN."You then setup spawn points, any amount of spawn points, set one by using the command '/koth setspawn (arena name)' when standing on the spawn point."); 538 | } 539 | } -------------------------------------------------------------------------------- /src/EventHandler.php: -------------------------------------------------------------------------------- 1 | . 19 | * 20 | * Twitter :: @JaxkDev 21 | * Discord :: JaxkDev#2698 22 | * Email :: JaxkDev@gmail.com 23 | */ 24 | 25 | namespace JaxkDev\KOTH; 26 | 27 | use pocketmine\event\Listener; 28 | use pocketmine\event\server\CommandEvent; 29 | use pocketmine\utils\TextFormat as C; 30 | use pocketmine\event\block\BlockBreakEvent; 31 | use pocketmine\event\block\BlockPlaceEvent; 32 | use pocketmine\event\player\PlayerChatEvent; 33 | use pocketmine\event\player\PlayerDeathEvent; 34 | use pocketmine\event\player\PlayerRespawnEvent; 35 | use pocketmine\event\player\PlayerQuitEvent; 36 | use pocketmine\event\player\PlayerGameModeChangeEvent; 37 | use RuntimeException; 38 | 39 | 40 | class EventHandler implements Listener{ 41 | private Main $plugin; 42 | 43 | public function __construct(Main $plugin){ 44 | $this->plugin = $plugin; 45 | } 46 | 47 | public function onQuit(PlayerQuitEvent $event): void{ 48 | $player = $event->getPlayer(); 49 | $playerName = strtolower($player->getName()); 50 | if(($arena = $this->plugin->getArenaByPlayer($playerName)) !== null){ 51 | $this->plugin->getLogger()->debug($playerName." has left the game, informing arena..."); 52 | $arena->removePlayer($event->getPlayer(), "Disconnected from server."); 53 | } 54 | } 55 | 56 | public function onRespawn(PlayerRespawnEvent $event): void{ 57 | $player = $event->getPlayer(); 58 | $playerName = strtolower($player->getName()); 59 | if(($arena = $this->plugin->getArenaByPlayer($playerName)) !== null){ 60 | $this->plugin->getLogger()->debug($playerName." was re-spawned."); 61 | $spawn = $arena->getSpawn(true); 62 | if($spawn !== null){ 63 | $event->setRespawnPosition($spawn); 64 | }else{ 65 | throw new RuntimeException("No spawns found when player in arena on respawn."); 66 | } 67 | } 68 | } 69 | 70 | public function onDeath(PlayerDeathEvent $event): void{ 71 | $player = $event->getPlayer(); 72 | $playerName = strtolower($player->getName()); 73 | if($this->plugin->getArenaByPlayer($playerName) !== null and $this->plugin->getConfig()->get("keep_inventory", true) === true){ 74 | $this->plugin->getLogger()->debug($playerName."'s inventory was not reset (death)"); 75 | $event->setKeepInventory(true); 76 | } 77 | } 78 | 79 | /*public function onLevelChange(EntityLevelChangeEvent $event): void{ 80 | $targetLevel = $event->getTarget(); 81 | //todo hack for per world FTP (decide how to handle this :/ ) (Beta4) 82 | }*/ 83 | 84 | public function onCommand(CommandEvent $event): void{ 85 | $player = $event->getSender(); 86 | $playerName = strtolower($player->getName()); 87 | if($this->plugin->getArenaByPlayer($playerName) !== null){ 88 | if($this->plugin->getConfig()->get("block_commands", true) === true and !str_starts_with($event->getCommand(), "koth")){ 89 | $this->plugin->getLogger()->debug($player->getName() . " tried to use command '/" . $event->getCommand() . "' but was cancelled."); 90 | $event->cancel(); 91 | $player->sendMessage(Main::PREFIX.C::RED."You are not allowed to use commands in-game except: /koth");//TODO messages.yml 92 | } 93 | } 94 | } 95 | 96 | public function onChat(PlayerChatEvent $event): void{ 97 | $player = $event->getPlayer(); 98 | $playerName = strtolower($player->getName()); 99 | if($this->plugin->getArenaByPlayer($playerName) !== null){ 100 | if($this->plugin->getConfig()->get("block_messages", true) === true){ 101 | $this->plugin->getLogger()->debug($player->getName() . " tried to send '".$event->getMessage()."' globally, but was cancelled."); 102 | $player->sendMessage(Main::PREFIX.C::RED."You are not allowed to chat while in-game.");//TODO messages.yml 103 | $event->cancel(); 104 | } 105 | } 106 | } 107 | 108 | public function onPlayerGameModeChange(PlayerGameModeChangeEvent $event): void{ 109 | $player = $event->getPlayer(); 110 | $playerName = strtolower($player->getName()); 111 | if($this->plugin->getArenaByPlayer($playerName) !== null){ 112 | if($this->plugin->getConfig()->get("prevent_gamemode_change", true) === true){ 113 | $this->plugin->getLogger()->debug($playerName." attempted to change gamemode but was stopped."); 114 | $player->sendMessage(Main::PREFIX.C::RED."You are not allowed to changed gamemode while in game.");//TODO messages.yml 115 | $event->cancel(); 116 | } 117 | } 118 | } 119 | 120 | public function onBlockBreak(BlockBreakEvent $event): void{ 121 | $player = $event->getPlayer(); 122 | $playerName = strtolower($player->getName()); 123 | if($this->plugin->getArenaByPlayer($playerName) !== null and $this->plugin->getConfig()->get("prevent_break", true) === true){ 124 | $this->plugin->getLogger()->debug($playerName." attempted to break a block but was stopped."); 125 | $player->sendMessage(Main::PREFIX.C::RED."You are not allowed to break things while in game.");//TODO messages.yml 126 | $event->cancel(); 127 | } 128 | } 129 | 130 | public function onBlockPlace(BlockPlaceEvent $event): void{ 131 | $player = $event->getPlayer(); 132 | $playerName = strtolower($player->getName()); 133 | if($this->plugin->getArenaByPlayer($playerName) !== null and $this->plugin->getConfig()->get("prevent_place", true) === true){ 134 | $this->plugin->getLogger()->debug($playerName." attempted to place a block but was stopped."); 135 | $player->sendMessage(Main::PREFIX.C::RED."You are not allowed to place things while in game.");//TODO messages.yml 136 | $event->cancel(); 137 | } 138 | } 139 | } -------------------------------------------------------------------------------- /src/Events/ArenaAddPlayerEvent.php: -------------------------------------------------------------------------------- 1 | . 19 | * 20 | * Twitter :: @JaxkDev 21 | * Discord :: JaxkDev#2698 22 | * Email :: JaxkDev@gmail.com 23 | */ 24 | 25 | namespace JaxkDev\KOTH\Events; 26 | 27 | use JaxkDev\KOTH\Arena; 28 | use JaxkDev\KOTH\Main; 29 | use pocketmine\player\Player; 30 | 31 | class ArenaAddPlayerEvent extends KothEvent{ 32 | private Arena $arena; 33 | private Player $player; 34 | 35 | public function __construct(Main $plugin, Arena $arena, Player $player){ 36 | $this->arena = $arena; 37 | $this->player = $player; 38 | parent::__construct($plugin); 39 | } 40 | 41 | public function getArena(): Arena{ 42 | return $this->arena; 43 | } 44 | 45 | public function getPlayer(): Player{ 46 | return $this->player; 47 | } 48 | } -------------------------------------------------------------------------------- /src/Events/ArenaCreateEvent.php: -------------------------------------------------------------------------------- 1 | . 19 | * 20 | * Twitter :: @JaxkDev 21 | * Discord :: JaxkDev#2698 22 | * Email :: JaxkDev@gmail.com 23 | */ 24 | 25 | namespace JaxkDev\KOTH\Events; 26 | 27 | use InvalidArgumentException; 28 | use JaxkDev\KOTH\Main; 29 | use pocketmine\console\ConsoleCommandSender; 30 | use pocketmine\player\Player; 31 | 32 | class ArenaCreateEvent extends KothEvent{ 33 | 34 | private Player|ConsoleCommandSender|null $creator; 35 | private string $name; 36 | private string $world; 37 | private int $minPlayers; 38 | private int $maxPlayers; 39 | private int $gameTime; 40 | 41 | /** @var float[][]|int[][] */ 42 | private array $hill; 43 | /** @var float[][]|int[][] */ 44 | private array $spawns; 45 | /** @var string[] */ 46 | private array $rewards; 47 | 48 | /** 49 | * @param Main $plugin 50 | * @param Player|ConsoleCommandSender|null $creator 51 | * @param string $name 52 | * @param int $min_players 53 | * @param int $max_players 54 | * @param int $gameTime 55 | * @param float[][]|int[][] $hill 56 | * @param float[][]|int[][] $spawns 57 | * @param string[] $rewards 58 | * @param string $world 59 | */ 60 | public function __construct(Main $plugin, Player|ConsoleCommandSender|null $creator, string $name, int $min_players, int $max_players, int $gameTime, array $hill = [], array $spawns = [], array $rewards = [], string $world = "null"){ 61 | $this->creator = $creator; 62 | $this->name = $name; 63 | $this->minPlayers = $min_players; 64 | $this->maxPlayers = $max_players; 65 | $this->gameTime = $gameTime; 66 | $this->hill = $hill; 67 | $this->spawns = $spawns; 68 | $this->rewards = $rewards; 69 | $this->world = $world; 70 | parent::__construct($plugin); 71 | } 72 | 73 | public function getCreator(): Player|ConsoleCommandSender|null{ 74 | return $this->creator; 75 | } 76 | 77 | public function getName(): string{ 78 | return $this->name; 79 | } 80 | 81 | public function setName(string $name): void{ 82 | $this->name = $name; 83 | } 84 | 85 | public function getMinPlayers(): int{ 86 | return $this->minPlayers; 87 | } 88 | 89 | public function setMinPlayers(int $amount): void{ 90 | if($amount < 2){ 91 | throw new InvalidArgumentException("Min players must be above 2"); 92 | } 93 | if($amount >= $this->maxPlayers){ 94 | throw new InvalidArgumentException("Min players must be below max players"); 95 | } 96 | $this->minPlayers = $amount; 97 | } 98 | 99 | public function getMaxPlayers(): int{ 100 | return $this->maxPlayers; 101 | } 102 | 103 | public function setMaxPlayers(int $amount): void{ 104 | if($amount <= $this->minPlayers){ 105 | throw new InvalidArgumentException("Max players cannot be less than or equal to min players"); 106 | } 107 | $this->maxPlayers = $amount; 108 | } 109 | 110 | public function getGameTime(): int{ 111 | return $this->gameTime; 112 | } 113 | 114 | public function setGameTime(int $amount): void{ 115 | $this->gameTime = $amount; 116 | } 117 | 118 | /** 119 | * @return float[][]|int[][] 120 | */ 121 | public function getHillPositions(): array{ 122 | return $this->hill; 123 | } 124 | 125 | /** 126 | * @param float[][]|int[][] $hill 127 | * @return void 128 | */ 129 | public function setHillPositions(array $hill): void{ 130 | $this->hill = $hill; 131 | } 132 | 133 | /** 134 | * @return float[][]|int[][] 135 | */ 136 | public function getSpawnPositions(): array{ 137 | return $this->spawns; 138 | } 139 | 140 | /** 141 | * @param float[][]|int[][] $spawns 142 | * @return void 143 | */ 144 | public function setSpawnPositions(array $spawns): void{ 145 | $this->spawns = $spawns; 146 | } 147 | 148 | /** 149 | * @return string[] 150 | */ 151 | public function getRewards(): array{ 152 | return $this->rewards; 153 | } 154 | 155 | /** 156 | * @param string[] $rewards 157 | * @return void 158 | */ 159 | public function setRewards(array $rewards): void{ 160 | $this->rewards = $rewards; 161 | } 162 | 163 | public function getWorld(): string{ 164 | return $this->world; 165 | } 166 | 167 | public function setWorld(string $worldName): void{ 168 | $this->world = $worldName; 169 | } 170 | } -------------------------------------------------------------------------------- /src/Events/ArenaDeleteEvent.php: -------------------------------------------------------------------------------- 1 | . 19 | * 20 | * Twitter :: @JaxkDev 21 | * Discord :: JaxkDev#2698 22 | * Email :: JaxkDev@gmail.com 23 | */ 24 | 25 | namespace JaxkDev\KOTH\Events; 26 | 27 | use JaxkDev\KOTH\Arena; 28 | use JaxkDev\KOTH\Main; 29 | use pocketmine\console\ConsoleCommandSender; 30 | use pocketmine\player\Player; 31 | 32 | /* 33 | * Note: The event is only used when the command /koth remove/delete is used, 34 | * NOT when the plugins removeArena is called (so it will not work if plugins call the function) 35 | * 36 | * You have been warned. 37 | */ 38 | 39 | class ArenaDeleteEvent extends KothEvent{ 40 | private ConsoleCommandSender|Player|null $destroyer; 41 | private Arena $arena; 42 | 43 | public function __construct(Main $plugin, ConsoleCommandSender|Player|null $destroyer, Arena $arena){ 44 | $this->destroyer = $destroyer; 45 | $this->arena = $arena; 46 | parent::__construct($plugin); 47 | } 48 | 49 | public function getDestroyer(): ConsoleCommandSender|Player|null{ 50 | return $this->destroyer; 51 | } 52 | 53 | public function getArena(): Arena{ 54 | return $this->arena; 55 | } 56 | } -------------------------------------------------------------------------------- /src/Events/ArenaEndEvent.php: -------------------------------------------------------------------------------- 1 | . 19 | * 20 | * Twitter :: @JaxkDev 21 | * Discord :: JaxkDev#2698 22 | * Email :: JaxkDev@gmail.com 23 | */ 24 | 25 | namespace JaxkDev\KOTH\Events; 26 | 27 | use JaxkDev\KOTH\Arena; 28 | use JaxkDev\KOTH\Main; 29 | 30 | class ArenaEndEvent extends KothEvent{ 31 | private Arena $arena; 32 | private int $secondsLeft; 33 | 34 | public function __construct(Main $plugin, Arena $arena){ 35 | $this->arena = $arena; 36 | $this->secondsLeft = $arena->getTime(); 37 | parent::__construct($plugin); 38 | } 39 | 40 | public function getArena(): Arena{ 41 | return $this->arena; 42 | } 43 | 44 | public function getSecondsLeft(): int{ 45 | return $this->secondsLeft; 46 | } 47 | 48 | /** 49 | * @param int $seconds 50 | * Notice: Cancels the event if seconds left is changed to a positive int (basically extra time.) 51 | */ 52 | public function setSecondsLeft(int $seconds): void{ 53 | $this->secondsLeft = $seconds; 54 | if($seconds > 0){ 55 | $this->cancel(); //Just in-case developers don't... 56 | } 57 | } 58 | } -------------------------------------------------------------------------------- /src/Events/ArenaPreStartEvent.php: -------------------------------------------------------------------------------- 1 | . 19 | * 20 | * Twitter :: @JaxkDev 21 | * Discord :: JaxkDev#2698 22 | * Email :: JaxkDev@gmail.com 23 | */ 24 | 25 | namespace JaxkDev\KOTH\Events; 26 | 27 | use JaxkDev\KOTH\Arena; 28 | use JaxkDev\KOTH\Main; 29 | 30 | class ArenaPreStartEvent extends KothEvent{ 31 | private Arena $arena; 32 | public int $countdown; 33 | 34 | public function __construct(Main $plugin, Arena $arena){ 35 | $this->arena = $arena; 36 | $this->countdown = $arena->getCountDown(); 37 | parent::__construct($plugin); 38 | } 39 | 40 | public function getCountdown(): int{ 41 | return $this->countdown; 42 | } 43 | 44 | /** 45 | * Notice, Does not change Arena->countDown (the countdown for future starts) 46 | */ 47 | public function setCountdown(int $countdown): void{ 48 | $this->countdown = $countdown; 49 | } 50 | 51 | public function getArena(): Arena{ 52 | return $this->arena; 53 | } 54 | } -------------------------------------------------------------------------------- /src/Events/ArenaRemovePlayerEvent.php: -------------------------------------------------------------------------------- 1 | . 19 | * 20 | * Twitter :: @JaxkDev 21 | * Discord :: JaxkDev#2698 22 | * Email :: JaxkDev@gmail.com 23 | */ 24 | 25 | namespace JaxkDev\KOTH\Events; 26 | 27 | use JaxkDev\KOTH\Arena; 28 | use JaxkDev\KOTH\Main; 29 | use pocketmine\player\Player; 30 | 31 | /* 32 | * NOTICE: This event may be cancellable however, if player is leaving server (e.g. closed Minecraft) 33 | * then the event will not matter unless messages like leaveReason and silent are changed. 34 | * whether cancelled or not the player will be removed if leaving the server. 35 | */ 36 | 37 | class ArenaRemovePlayerEvent extends KothEvent{ 38 | private Arena $arena; 39 | private Player $player; 40 | private string $leaveReason; 41 | private bool $silent; 42 | 43 | public function __construct(Main $plugin, Arena $arena, Player $player, string $leaveReason, bool $silent){ 44 | $this->arena = $arena; 45 | $this->player = $player; 46 | $this->silent = $silent; 47 | $this->leaveReason = $leaveReason; 48 | parent::__construct($plugin); 49 | } 50 | 51 | public function setSilent(bool $silent): void{ 52 | $this->silent = $silent; 53 | } 54 | 55 | public function isSilent(): bool{ 56 | return $this->silent; 57 | } 58 | 59 | public function getLeaveReason(): string{ 60 | return $this->leaveReason; 61 | } 62 | 63 | public function setLeaveReason(string $leaveReason): void{ 64 | $this->leaveReason = $leaveReason; 65 | } 66 | 67 | public function getArena(): Arena{ 68 | return $this->arena; 69 | } 70 | 71 | public function getPlayer(): Player 72 | { 73 | return $this->player; 74 | } 75 | } -------------------------------------------------------------------------------- /src/Events/ArenaStartEvent.php: -------------------------------------------------------------------------------- 1 | . 19 | * 20 | * Twitter :: @JaxkDev 21 | * Discord :: JaxkDev#2698 22 | * Email :: JaxkDev@gmail.com 23 | */ 24 | 25 | namespace JaxkDev\KOTH\Events; 26 | 27 | use JaxkDev\KOTH\Arena; 28 | use JaxkDev\KOTH\Main; 29 | 30 | class ArenaStartEvent extends KothEvent{ 31 | private Arena $arena; 32 | 33 | public function __construct(Main $plugin, Arena $arena){ 34 | $this->arena = $arena; 35 | parent::__construct($plugin); 36 | } 37 | 38 | public function getArena(): Arena{ 39 | return $this->arena; 40 | } 41 | } -------------------------------------------------------------------------------- /src/Events/KothEvent.php: -------------------------------------------------------------------------------- 1 | . 19 | * 20 | * Twitter :: @JaxkDev 21 | * Discord :: JaxkDev#2698 22 | * Email :: JaxkDev@gmail.com 23 | */ 24 | 25 | namespace JaxkDev\KOTH\Events; 26 | 27 | use JaxkDev\KOTH\Main; 28 | use pocketmine\event\Cancellable; 29 | use pocketmine\event\CancellableTrait; 30 | use pocketmine\event\plugin\PluginEvent; 31 | 32 | abstract class KothEvent extends PluginEvent implements Cancellable{ 33 | use CancellableTrait; 34 | 35 | private string $reason = "Event Cancelled"; 36 | private Main $plugin; 37 | 38 | public function __construct(Main $plugin){ 39 | $this->plugin = $plugin; 40 | $this->plugin->getLogger()->debug("Event '".$this->getEventName()."' is being constructed..."); 41 | parent::__construct($plugin); 42 | } 43 | 44 | public function getReason(): string{ 45 | return $this->reason; 46 | } 47 | 48 | public function setReason(string $reason): void{ 49 | $this->reason = $reason; 50 | } 51 | 52 | public function call(): void{ 53 | $this->plugin->getLogger()->debug("Event '".$this->getEventName()."' Called."); 54 | parent::call(); 55 | } 56 | } -------------------------------------------------------------------------------- /src/Main.php: -------------------------------------------------------------------------------- 1 | . 19 | * 20 | * Twitter :: @JaxkDev 21 | * Discord :: JaxkDev#2698 22 | * Email :: JaxkDev@gmail.com 23 | */ 24 | 25 | namespace JaxkDev\KOTH; 26 | 27 | use Exception; 28 | use JaxkDev\KOTH\Providers\BaseProvider; 29 | use JaxkDev\KOTH\Providers\SqlProvider; 30 | use JaxkDev\KOTH\Tasks\CheckUpdate; 31 | use JaxkDev\KOTH\Utils as PluginUtils; 32 | use Phar; 33 | use pocketmine\console\ConsoleCommandSender; 34 | use pocketmine\player\Player; 35 | use pocketmine\utils\Config; 36 | use pocketmine\event\Listener; 37 | use pocketmine\command\Command; 38 | use pocketmine\plugin\PluginBase; 39 | use pocketmine\command\CommandSender; 40 | use pocketmine\utils\TextFormat as C; 41 | 42 | class Main extends PluginBase implements Listener{ 43 | public const CONFIG_VER = 3; 44 | public const MESSAGE_VER = 0; 45 | 46 | /** @var Arena[] */ 47 | private array $arenas = []; 48 | private CommandHandler $commandHandler; 49 | private BaseProvider $db; 50 | private Config $config; 51 | private Config $messages; 52 | 53 | public Utils $utils; 54 | 55 | public const PREFIX = C::YELLOW . "[" . C::AQUA . "KOTH" . C::YELLOW . "] " . C::RESET; 56 | 57 | private function loadArenas(): void{ 58 | $this->db = new SqlProvider($this); 59 | $this->db->open(function(){ 60 | $this->db->loadAllArenas(function(array $arenas){ 61 | $this->arenas = $arenas; 62 | $this->getLogger()->debug(str_replace("{AMOUNT}", (string)count($this->arenas), $this->utils->colourise((string)$this->messages->getNested("arenas.loaded", "{AMOUNT} Arena(s) loaded.")))); 63 | }); 64 | }); 65 | } 66 | 67 | public function onDisable(): void{ 68 | $this->db->close(); 69 | } 70 | 71 | public function onLoad(): void{ 72 | if(Phar::running() === ""){ 73 | throw new Exception("Cannot be run from source."); 74 | } 75 | 76 | $this->saveResource("config.yml"); 77 | $this->config = new Config($this->getDataFolder() . "config.yml", Config::YAML); 78 | 79 | $this->saveResource("messages.yml"); 80 | $this->messages = new Config($this->getDataFolder() . "messages.yml", Config::YAML); 81 | 82 | if($this->messages->get("version", 1) !== $this::MESSAGE_VER){ 83 | // TODO UPDATE 84 | $this->getLogger()->debug("Message file is outdated, attempting to update."); 85 | } 86 | if($this->config->get("version", 1) !== $this::CONFIG_VER){ 87 | if($this->config->exists("start_countdown")){ 88 | $this->config->set("countdown", $this->config->get("start_countdown")); 89 | $this->config->remove("start_countdown"); 90 | }else{ 91 | if(!$this->config->exists("countdown")){ 92 | $this->config->set("countdown", 30); 93 | } 94 | } 95 | if(!$this->config->exists("countdown_bcast")) $this->config->set("countdown_bcast", true); 96 | if(!$this->config->exists("countdown_bcast_interval")) $this->config->set("countdown_bcast_interval", 5); 97 | if(!$this->config->exists("countdown_bcast_serverwide")) $this->config->set("countdown_bcast_serverwide", false); 98 | if(!$this->config->exists("start_bcast_serverwide")) $this->config->set("start_bcast_serverwide", false); 99 | if(!$this->config->exists("end_bcast_serverwide")) $this->config->set("end_bcast_serverwide", false); 100 | if(!$this->config->exists("provider")) $this->config->set("provider", "sqlite3"); 101 | if(!$this->config->exists("block_messages")) $this->config->set("block_messages", true); 102 | if(!$this->config->exists("block_commands")) $this->config->set("block_commands", true); 103 | if(!$this->config->exists("prevent_place")) $this->config->set("prevent_place", true); 104 | if(!$this->config->exists("prevent_break")) $this->config->set("prevent_break", true); 105 | if(!$this->config->exists("prevent_gamemode_change")) $this->config->set("prevent_gamemode_change", true); 106 | if(!$this->config->exists("keep_inventory")) $this->config->set("keep_inventory", true); 107 | if(!$this->config->exists("check_updates")) $this->config->set("check_updates", true); 108 | $this->config->remove("show_updates"); 109 | $this->config->remove("language"); 110 | $this->config->remove("download_updates"); 111 | $this->config->set("version", self::CONFIG_VER); 112 | $this->saveConfig(); 113 | } 114 | 115 | foreach(["eng","spa","fra"] as $language){ 116 | @unlink($this->getDataFolder()."help_".$language.".txt"); 117 | $this->saveResource("help_" . $language . ".txt"); 118 | } 119 | } 120 | 121 | public function onEnable(): void{ 122 | $this->commandHandler = new CommandHandler($this); 123 | $this->utils = new PluginUtils($this); 124 | $this->arenas = []; 125 | $this->loadArenas(); 126 | $this->getServer()->getPluginManager()->registerEvents(new EventHandler($this), $this); 127 | 128 | if($this->config->get("check_updates", true) === true){ 129 | $this->getLogger()->debug("Starting update check task..."); 130 | $this->getServer()->getAsyncPool()->submitTask(new CheckUpdate($this->getDescription()->getVersion())); 131 | } 132 | } 133 | 134 | public function onCommand(CommandSender $sender, Command $command, string $label, array $args): bool{ 135 | if($sender instanceof ConsoleCommandSender or $sender instanceof Player){ 136 | $this->commandHandler->handleCommand($sender, $args); 137 | }else{ 138 | //Lovely messages for people like RCON etc. 139 | $sender->sendMessage("Who are you... You're not a player or a console user!"); 140 | } 141 | return true; 142 | } 143 | 144 | public function updateArena(Arena $arena): void{ 145 | $this->db->updateArena($arena); 146 | } 147 | 148 | public function createArena(Arena $arena): void{ 149 | $this->arenas[] = $arena; 150 | $this->db->createArena($arena); 151 | } 152 | 153 | public function deleteArena(Arena $arena): void{ 154 | if(($key = array_search($arena, $this->arenas)) !== false){ 155 | unset($this->arenas[$key]); 156 | $this->db->deleteArena(strtolower($arena->getName())); 157 | } 158 | } 159 | 160 | public function deleteArenaByName(string $name): void{ 161 | $arena = $this->getArenaByName($name); 162 | if($arena !== null){ 163 | $this->deleteArena($arena); 164 | } 165 | } 166 | 167 | /** 168 | * @return Arena[] 169 | */ 170 | public function getAllArenas(): array{ 171 | return $this->arenas; 172 | } 173 | 174 | public function getArenaByPlayer(string $name): ?Arena{ 175 | foreach($this->arenas as $arena){ 176 | if(in_array(strtolower($name), $arena->getPlayers())){ 177 | return $arena; 178 | } 179 | } 180 | return null; 181 | } 182 | 183 | public function getArenaByName(string $name): ?Arena{ 184 | foreach($this->arenas as $arena){ 185 | if(strtolower($arena->getName()) === strtolower($name)){ 186 | return $arena; 187 | } 188 | } 189 | return null; 190 | } 191 | 192 | public function getMessages(): Config{ 193 | return $this->messages; 194 | } 195 | } -------------------------------------------------------------------------------- /src/Particles/FloatingText.php: -------------------------------------------------------------------------------- 1 | . 19 | * 20 | * Twitter :: @JaxkDev 21 | * Discord :: JaxkDev#2698 22 | * Email :: JaxkDev@gmail.com 23 | */ 24 | 25 | namespace JaxkDev\KOTH\Particles; 26 | 27 | use pocketmine\world\World; 28 | use pocketmine\math\Vector3; 29 | use pocketmine\world\particle\FloatingTextParticle; 30 | 31 | /** 32 | * Class FloatingText 33 | * 34 | * This class's sole purpose is to update every time its changed. 35 | */ 36 | 37 | class FloatingText extends FloatingTextParticle{ 38 | 39 | private World $world; 40 | private Vector3 $position; 41 | 42 | public function __construct(World $world, Vector3 $position, string $text, string $title = ""){ 43 | parent::__construct($text, $title); 44 | $this->world = $world; 45 | $this->position = $position; 46 | } 47 | 48 | public function setText(string $text): void{ 49 | $this->text = $text; 50 | $this->update(); 51 | } 52 | 53 | public function setTitle(string $title): void{ 54 | $this->title = $title; 55 | $this->update(); 56 | } 57 | 58 | public function setInvisible(bool $value = true): void{ 59 | $this->invisible = $value; 60 | $this->update(); 61 | } 62 | 63 | public function update(): void{ 64 | $this->world->addParticle($this->position, $this); 65 | } 66 | } -------------------------------------------------------------------------------- /src/Providers/BaseProvider.php: -------------------------------------------------------------------------------- 1 | . 19 | * 20 | * Twitter :: @JaxkDev 21 | * Discord :: JaxkDev#2698 22 | * Email :: JaxkDev@gmail.com 23 | */ 24 | 25 | namespace JaxkDev\KOTH\Providers; 26 | 27 | use JaxkDev\KOTH\Main; 28 | use JaxkDev\KOTH\Arena; 29 | 30 | interface BaseProvider{ 31 | public function __construct(Main $plugin); 32 | 33 | public function getName(): string; 34 | 35 | /** 36 | * @param callable $callable (): void 37 | */ 38 | public function open(callable $callable): void; 39 | 40 | public function close(): void; 41 | 42 | public function createArena(Arena $arena): void; 43 | 44 | public function updateArena(Arena $arena): void; 45 | 46 | public function deleteArena(string $arena): void; 47 | 48 | /** 49 | * @param callable $callback (Arena[] $arenas): void 50 | */ 51 | public function loadAllArenas(callable $callback): void; 52 | } -------------------------------------------------------------------------------- /src/Providers/SqlProvider.php: -------------------------------------------------------------------------------- 1 | . 19 | * 20 | * Twitter :: @JaxkDev 21 | * Discord :: JaxkDev#2698 22 | * Email :: JaxkDev@gmail.com 23 | */ 24 | 25 | namespace JaxkDev\KOTH\Providers; 26 | 27 | use JaxkDev\KOTH\Main; 28 | use JaxkDev\KOTH\Arena; 29 | use poggit\libasynql\DataConnector; 30 | use poggit\libasynql\libasynql; 31 | use poggit\libasynql\SqlError; 32 | 33 | class SqlProvider implements BaseProvider{ 34 | 35 | private Main $plugin; 36 | private DataConnector $db; 37 | 38 | public function __construct(Main $plugin){ 39 | $this->plugin = $plugin; 40 | } 41 | 42 | public function getName(): string{ 43 | return "SQL"; 44 | } 45 | 46 | /** 47 | * @throws SqlError 48 | */ 49 | public function open(callable $callable): void{ 50 | $this->db = libasynql::create($this->plugin, $this->plugin->getConfig()->get("database"), [ 51 | "sqlite" => "provider/sqlite.sql", 52 | //"mysql" => "provider/mysql.sql" 53 | ]); 54 | 55 | $this->db->executeGeneric("arena.init", [], function() use($callable): void{ 56 | $this->plugin->getLogger()->debug("[DB] Tables checked/created."); 57 | $callable(); 58 | }, function(SqlError $error): void{ 59 | $this->plugin->getLogger()->error("[DB] Failed to create/check tables - '".$error->getErrorMessage()."'."); 60 | throw $error; 61 | }); 62 | } 63 | 64 | public function close(): void{ 65 | if(isset($this->db)){ 66 | $this->db->close(); 67 | } 68 | $this->plugin->getLogger()->debug("[DB] Connector closed."); 69 | } 70 | 71 | /** 72 | * @throws SqlError 73 | */ 74 | public function createArena(Arena $arena): void{ 75 | $this->db->executeInsert("arena.create", [ 76 | "name" => $arena->getName(), 77 | "min" => $arena->getMinPlayers(), 78 | "max" => $arena->getMaxPlayers(), 79 | "hill" => json_encode($arena->getHill()), 80 | "spawns" => json_encode($arena->getSpawns()), 81 | "rewards" => json_encode($arena->getRewards()), 82 | "world" => $arena->getWorld() 83 | ], function(int $insertId, int $affectedRows) use($arena): void{ 84 | if($affectedRows === 1){ 85 | $this->plugin->getLogger()->debug("[DB] Arena '".$arena->getName()."' created."); 86 | }else{ 87 | $this->plugin->getLogger()->error("[DB] Failed to create arena '".$arena->getName()."' - no affected rows."); 88 | } 89 | }, function(SqlError $error) use($arena): void{ 90 | $this->plugin->getLogger()->error("[DB] Arena '".$arena->getName()."' failed to update - '".$error->getErrorMessage()."'."); 91 | throw $error; 92 | }); 93 | } 94 | 95 | /** 96 | * @throws SqlError 97 | */ 98 | public function updateArena(Arena $arena): void{ 99 | $this->db->executeChange("arena.update", [ 100 | "name" => $arena->getName(), 101 | "min" => $arena->getMinPlayers(), 102 | "max" => $arena->getMaxPlayers(), 103 | "hill" => json_encode($arena->getHill()), 104 | "spawns" => json_encode($arena->getSpawns()), 105 | "rewards" => json_encode($arena->getRewards()), 106 | "world" => $arena->getWorld() 107 | ], function(int $affectedRows) use($arena): void{ 108 | if($affectedRows === 1){ 109 | $this->plugin->getLogger()->debug("[DB] Arena '".$arena->getName()."' updated."); 110 | }else{ 111 | $this->plugin->getLogger()->warning("[DB] Arena '".$arena->getName()."' failed to update - no affected rows."); 112 | } 113 | }, function(SqlError $error) use($arena): void{ 114 | $this->plugin->getLogger()->error("[DB] Arena '".$arena->getName()."' failed to update - '".$error->getErrorMessage()."'."); 115 | throw $error; 116 | }); 117 | } 118 | 119 | /** 120 | * @throws SqlError 121 | */ 122 | public function deleteArena(string $arena): void{ 123 | $this->db->executeChange("arena.delete", [ 124 | "name" => $arena 125 | ], function(int $affectedRows) use($arena): void{ 126 | if($affectedRows === 1){ 127 | $this->plugin->getLogger()->debug("[DB] Arena '".$arena."' deleted."); 128 | }else{ 129 | $this->plugin->getLogger()->warning("[DB] Arena '".$arena."' failed to delete - no affected rows."); 130 | } 131 | }, function(SqlError $error) use($arena): void{ 132 | $this->plugin->getLogger()->error("[DB] Arena '".$arena."' failed to delete - '".$error->getErrorMessage()."'."); 133 | throw $error; 134 | }); 135 | } 136 | 137 | /** 138 | * @throws SqlError 139 | */ 140 | public function loadAllArenas(callable $callback): void{ 141 | $this->db->executeSelect("arena.all", [], function(array $rows) use($callback): void{ 142 | $arenas = []; 143 | foreach($rows as $row){ 144 | $arenas[] = new Arena($this->plugin, $row["name"], $row["min_players"], $row["max_players"], $row["time"], json_decode($row["hill"], true), json_decode($row["spawns"], true), json_decode($row["rewards"], true), $row["world"]); 145 | } 146 | $callback($arenas); 147 | }, function(SqlError $error): void{ 148 | $this->plugin->getLogger()->error("[DB] Failed to load all arenas - '".$error->getErrorMessage()."'."); 149 | throw $error; 150 | }); 151 | } 152 | } -------------------------------------------------------------------------------- /src/Tasks/CheckUpdate.php: -------------------------------------------------------------------------------- 1 | . 19 | * 20 | * Twitter :: @JaxkDev 21 | * Discord :: JaxkDev#2698 22 | * Email :: JaxkDev@gmail.com 23 | */ 24 | 25 | namespace JaxkDev\KOTH\Tasks; 26 | 27 | use Error; 28 | use JaxkDev\KOTH\Utils; 29 | use pocketmine\scheduler\AsyncTask; 30 | use pocketmine\Server; 31 | 32 | class CheckUpdate extends AsyncTask{ 33 | 34 | private string $version; 35 | 36 | public function __construct(string $version){ 37 | $this->version = $version; 38 | } 39 | 40 | public function onRun(): void{ 41 | $ch = curl_init("https://poggit.pmmp.io/plugins.min.json?name=KOTH"); 42 | if($ch === false){ 43 | throw new Error("Failed to initialize cURL"); 44 | } 45 | curl_setopt($ch, CURLOPT_TIMEOUT, 30); //give it 30 secs. 46 | curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); 47 | curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true); 48 | curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false); 49 | $data = curl_exec($ch); 50 | if(curl_errno($ch)){ 51 | throw new Error(curl_error($ch)); 52 | } 53 | if($data === false){ 54 | throw new Error("Failed to get data from poggit."); 55 | } 56 | $data = json_decode((string)$data, true); 57 | if($data === false){ 58 | throw new Error("Failed to decode data from poggit."); 59 | } 60 | curl_close($ch); 61 | $this->setResult($data[0]); 62 | } 63 | 64 | public function onCompletion(): void{ 65 | /** @var string[] $data */ 66 | $data = $this->getResult(); 67 | if(Utils::compareVersions($this->version, $data["version"])){ 68 | Server::getInstance()->getLogger()->notice("[KOTH] A new version of KOTH is available on poggit! (Version: {$data["version"]})"); 69 | }else{ 70 | Server::getInstance()->getLogger()->debug("[KOTH] Latest version of KOTH is already installed."); 71 | } 72 | } 73 | } 74 | -------------------------------------------------------------------------------- /src/Tasks/GameTimer.php: -------------------------------------------------------------------------------- 1 | . 19 | * 20 | * Twitter :: @JaxkDev 21 | * Discord :: JaxkDev#2698 22 | * Email :: JaxkDev@gmail.com 23 | */ 24 | 25 | namespace JaxkDev\KOTH\Tasks; 26 | 27 | use pocketmine\scheduler\Task; 28 | use JaxkDev\KOTH\Arena; 29 | 30 | class GameTimer extends Task{ 31 | private Arena $arena; 32 | public float $secondsLeft; 33 | 34 | public function __construct(Arena $arena){ 35 | $this->arena = $arena; 36 | $this->secondsLeft = $arena->getTime(); 37 | } 38 | 39 | public function onRun(): void{ 40 | $this->secondsLeft -= 0.5; 41 | $inBox = $this->arena->getPlayersInBox(); 42 | if($this->arena->getKing() === null){ 43 | $this->arena->checkNewKing(); 44 | }else{ 45 | if(!in_array($this->arena->getKing(), $inBox)){ 46 | $this->arena->removeKing(); 47 | } 48 | } 49 | 50 | if($this->secondsLeft <= 0){ 51 | $this->arena->endGame(); 52 | } 53 | } 54 | } -------------------------------------------------------------------------------- /src/Tasks/StartCountdown.php: -------------------------------------------------------------------------------- 1 | . 19 | * 20 | * Twitter :: @JaxkDev 21 | * Discord :: JaxkDev#2698 22 | * Email :: JaxkDev@gmail.com 23 | */ 24 | 25 | namespace JaxkDev\KOTH\Tasks; 26 | 27 | use JaxkDev\KOTH\Utils; 28 | use pocketmine\scheduler\Task; 29 | use JaxkDev\KOTH\Main; 30 | use JaxkDev\KOTH\Arena; 31 | 32 | class StartCountdown extends Task{ 33 | 34 | private Main $plugin; 35 | private Arena $arena; 36 | 37 | private int $countDown; 38 | private bool $serverBcast; 39 | 40 | public function __construct(Main $plugin, Arena $arena, int $count){ 41 | $this->plugin = $plugin; 42 | $this->arena = $arena; 43 | $this->countDown = $count; 44 | $this->serverBcast = ($plugin->getConfig()->get("countdown_bcast_serverwide", true) === true); 45 | } 46 | 47 | public function onRun(): void{ 48 | if($this->countDown === 0){ 49 | $this->arena->startGame(); 50 | return; 51 | } 52 | if($this->plugin->getConfig()->get("countdown_bcast", true) === true){ 53 | $msg = str_replace(["{TIME}","{ARENA}"], [Utils::secToHR($this->countDown), $this->arena->getName()], $this->plugin->utils->colourise((string)$this->plugin->getMessages()->getNested("broadcasts.countdown", "{PREFIX}{GOLD}[{AQUA}{ARENA} | {RED}COUNTDOWN{GOLD}] {RED}: {GREEN}{TIME}"))); 54 | if($this->countDown <= 5){ 55 | if(!$this->serverBcast){ 56 | $this->arena->broadcastMessage($msg); 57 | } else{ 58 | $this->plugin->getServer()->broadcastMessage($msg); 59 | } 60 | }else{ 61 | if(($this->countDown % (int)$this->plugin->getConfig()->get("countdown_bcast_interval", 5)) === 0){ 62 | if(!$this->serverBcast){ 63 | $this->arena->broadcastMessage($msg); 64 | }else{ 65 | $this->plugin->getServer()->broadcastMessage($msg); 66 | } 67 | } 68 | } 69 | } 70 | $this->countDown--; 71 | } 72 | } -------------------------------------------------------------------------------- /src/Utils.php: -------------------------------------------------------------------------------- 1 | plugin = $plugin; 14 | } 15 | 16 | /** 17 | * Credit to https://gist.githubusercontent.com/LeoLopesWeb/a3e0bba7fe66a6af1e50eef3d231f2da/raw/16edbd69a709ca21d24f2774af5ccf68297aa97d/.php 18 | * Slightly modified for our use. 19 | */ 20 | public static function secToHR(int $seconds): string{ 21 | $days = floor($seconds / 86400); 22 | $hours = floor(($seconds / 3600) % 24); 23 | $minutes = floor(($seconds / 60) % 60); 24 | $seconds = $seconds % 60; 25 | return $days > 0 ? "$days days, $hours hours, $minutes minutes" : ($hours > 0 ? "$hours hours, $minutes minutes" : ($minutes > 0 ? "$minutes minutes, $seconds seconds" : "$seconds seconds")); 26 | } 27 | 28 | public static function compareVersions(string $base, string $new): int{ 29 | $baseParts = explode(".",$base); 30 | $baseParts[2] = explode("-beta",$baseParts[2])[0]; 31 | if(sizeof(explode("-beta",explode(".",$base)[2])) >1){ 32 | $baseParts[3] = explode("-beta",explode(".",$base)[2])[1]; 33 | } 34 | $newParts = explode(".",$new); 35 | $newParts[2] = explode("-beta",$newParts[2])[0]; 36 | if(sizeof(explode("-beta",explode(".",$new)[2])) >1){ 37 | $newParts[3] = explode("-beta",explode(".",$new)[2])[1]; 38 | } 39 | if(intval($newParts[0]) > intval($baseParts[0])){ 40 | return 1; 41 | } 42 | if(intval($newParts[0]) < intval($baseParts[0])){ 43 | return -1; 44 | } 45 | if(intval($newParts[1]) > intval($baseParts[1])){ 46 | return 1; 47 | } 48 | if(intval($newParts[1]) < intval($baseParts[1])){ 49 | return -1; 50 | } 51 | if(intval($newParts[2]) > intval($baseParts[2])){ 52 | return 1; 53 | } 54 | if(intval($newParts[2]) < intval($baseParts[2])){ 55 | return -1; 56 | } 57 | if(isset($baseParts[3])){ 58 | if(isset($newParts[3])){ 59 | if(intval($baseParts[3]) > intval($newParts[3])){ 60 | return -1; 61 | } 62 | if(intval($baseParts[3]) < intval($newParts[3])){ 63 | return 1; 64 | } 65 | }else{ 66 | return 1; 67 | } 68 | } 69 | return 0; 70 | } 71 | 72 | /** 73 | * Modified version of world managers, but checks both display name and folder name. 74 | * @param string $name 75 | * @return World|null 76 | */ 77 | public static function getWorldByName(string $name): ?World{ 78 | $server = Server::getInstance(); 79 | foreach($server->getWorldManager()->getWorlds() as $world){ 80 | if(strtolower($world->getFolderName()) === strtolower($name) or strtolower($world->getDisplayName()) === strtolower($name)){ 81 | return $world; 82 | } 83 | } 84 | if($server->getWorldManager()->loadWorld($name) === false){ 85 | return null; 86 | } 87 | return self::getWorldByName($name); 88 | } 89 | 90 | public function colourise(string $msg): string{ 91 | $colour = ["{PREFIX}","{BLACK}","{DARK_BLUE}","{DARK_GREEN}","{DARK_AQUA}","{DARK_RED}","{DARK_PURPLE}","{GOLD}","{GRAY}","{DARK_GRAY}","{BLUE}","{GREEN}","{AQUA}","{RED}","{LIGHT_PURPLE}","{YELLOW}","{WHITE}","{OBFUSCATED}","{BOLD}","{STRIKETHROUGH}","{UNDERLINE}","{ITALIC}","{RESET}"]; 92 | $keys = [Main::PREFIX, C::BLACK, C::DARK_BLUE, C::DARK_GREEN, C::DARK_AQUA, C::DARK_RED, C::DARK_PURPLE, C::GOLD, C::GRAY, C::DARK_GRAY, C::BLUE, C::GREEN, C::AQUA, C::RED, C::LIGHT_PURPLE, C::YELLOW, C::WHITE, C::OBFUSCATED, C::BOLD, C::STRIKETHROUGH, C::UNDERLINE, C::ITALIC, C::RESET]; 93 | return str_replace( 94 | $colour, 95 | $keys, 96 | $msg 97 | ); 98 | } 99 | } 100 | --------------------------------------------------------------------------------