├── .github └── ISSUE_TEMPLATE │ ├── bug-report.md │ ├── error.md │ ├── feature-request.md │ ├── incompatibility.md │ └── perfomance-issue.md ├── .gitignore ├── LICENSE ├── README.md ├── ResourceWorld.iml ├── img ├── CoffeeLoversLogo-BIG.png ├── Commands.png ├── Information.png ├── Installation.png ├── PayPal-Donate-Button-284-x-136.jpg ├── Permissions.png ├── RW-LOGO.jpg └── iconrw.png ├── pom.xml ├── src └── main │ ├── java │ └── me │ │ └── nik │ │ └── resourceworld │ │ ├── ResourceWorld.java │ │ ├── api │ │ └── ResourceWorldType.java │ │ ├── commands │ │ ├── CommandManager.java │ │ ├── SubCommand.java │ │ └── subcommands │ │ │ ├── Menu.java │ │ │ ├── Reload.java │ │ │ ├── Reset.java │ │ │ └── Teleport.java │ │ ├── files │ │ ├── Config.java │ │ ├── Data.java │ │ ├── Lang.java │ │ └── commentedfiles │ │ │ ├── CommentedConfigurationSection.java │ │ │ ├── CommentedFileConfiguration.java │ │ │ └── CommentedFileConfigurationHelper.java │ │ ├── gui │ │ ├── GuiListener.java │ │ ├── Menu.java │ │ ├── PlayerMenu.java │ │ └── menus │ │ │ ├── MainGui.java │ │ │ └── WorldsGui.java │ │ ├── managers │ │ ├── MsgType.java │ │ ├── PapiHook.java │ │ ├── Permissions.java │ │ ├── UpdateChecker.java │ │ └── custom │ │ │ ├── CustomWorld.java │ │ │ └── ResourceWorldException.java │ │ ├── metrics │ │ └── MetricsLite.java │ │ ├── modules │ │ ├── ListenerModule.java │ │ └── impl │ │ │ ├── DisabledCommands.java │ │ │ ├── LeaveWorld.java │ │ │ ├── Portals.java │ │ │ └── Suffocation.java │ │ ├── tasks │ │ ├── AlwaysDay.java │ │ ├── ResetEndWorld.java │ │ ├── ResetNetherWorld.java │ │ └── ResetWorld.java │ │ └── utils │ │ ├── ChatUtils.java │ │ ├── LocationFinder.java │ │ ├── MiscUtils.java │ │ ├── TaskUtils.java │ │ └── custom │ │ ├── ExpiringMap.java │ │ └── Pair.java │ └── resources │ └── plugin.yml └── version.txt /.github/ISSUE_TEMPLATE/bug-report.md: -------------------------------------------------------------------------------- 1 | --- 2 | name: Bug Report 3 | about: Make a bug report. 4 | title: "[BUG]" 5 | labels: Bug 6 | assignees: NikV2 7 | 8 | --- 9 | 10 | **Describe the bug** 11 | A clear and concise description of what the bug is. 12 | 13 | **To Reproduce** 14 | Steps to reproduce the behavior. 15 | 16 | **Does the issue still persist on the default config?** 17 | Yes/No 18 | 19 | **Is the plugin up to date?** 20 | Yes/No 21 | 22 | **Server Environment & Version** 23 | Your server software (ie Paper 1.12.2) 24 | 25 | **Additional Information (Optional)** 26 | -------------------------------------------------------------------------------- /.github/ISSUE_TEMPLATE/error.md: -------------------------------------------------------------------------------- 1 | --- 2 | name: Error 3 | about: Report an error. 4 | title: "[ERROR]" 5 | labels: Error 6 | assignees: NikV2 7 | 8 | --- 9 | 10 | **Error(s)** 11 | Provide a Pastebin link with your error. 12 | 13 | **Does the issue still persist on the default config?** 14 | Yes/No 15 | 16 | **Is the plugin up to date?** 17 | Yes/No 18 | 19 | **Server Environment & Version** 20 | Your server software (ie Paper 1.12.2) 21 | 22 | **Additional Information (Optional)** 23 | -------------------------------------------------------------------------------- /.github/ISSUE_TEMPLATE/feature-request.md: -------------------------------------------------------------------------------- 1 | --- 2 | name: Feature Request 3 | about: Request a feature. 4 | title: "[REQUEST]" 5 | labels: Request 6 | assignees: NikV2 7 | 8 | --- 9 | 10 | **What feature would you like to be added and why?** 11 | -------------------------------------------------------------------------------- /.github/ISSUE_TEMPLATE/incompatibility.md: -------------------------------------------------------------------------------- 1 | --- 2 | name: Incompatibility 3 | about: Report a plugin that does not run well with this one. 4 | title: "[INCOMPATIBILITY]" 5 | labels: Incompatibility 6 | assignees: NikV2 7 | 8 | --- 9 | 10 | **Does the issue still persist on the default config?** 11 | Yes/No 12 | 13 | **Is the incompatible plugin up to date?** 14 | Yes/No 15 | 16 | **Server Environment & Version** 17 | Your server software (ie Paper 1.12.2) 18 | 19 | **Incompatible Plugin** 20 | Provide a link where we can find the plugin. 21 | 22 | **Information** 23 | Describe the incompatibility issue. 24 | -------------------------------------------------------------------------------- /.github/ISSUE_TEMPLATE/perfomance-issue.md: -------------------------------------------------------------------------------- 1 | --- 2 | name: Perfomance Issue 3 | about: The plugin is causing Perfomance Issues 4 | title: "[PERFOMANCE]" 5 | labels: Perfomance 6 | assignees: NikV2 7 | 8 | --- 9 | 10 | **Timings** 11 | Provide your server's timings report 12 | 13 | **Is the plugin up to date?** 14 | Yes/No 15 | 16 | **Server Environment & Version** 17 | Your server software (ie Paper 1.12.2) 18 | 19 | **Additional Information (Optional)** 20 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | /target/ 2 | /.idea/ 3 | -------------------------------------------------------------------------------- /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 622 | 623 | How to Apply These Terms to Your New Programs 624 | 625 | If you develop a new program, and you want it to be of the greatest 626 | possible use to the public, the best way to achieve this is to make it 627 | free software which everyone can redistribute and change under these terms. 628 | 629 | To do so, attach the following notices to the program. It is safest 630 | to attach them to the start of each source file to most effectively 631 | state the exclusion of warranty; and each file should have at least 632 | the "copyright" line and a pointer to where the full notice is found. 633 | 634 | 635 | Copyright (C) 636 | 637 | This program is free software: you can redistribute it and/or modify 638 | it under the terms of the GNU General Public License as published by 639 | the Free Software Foundation, either version 3 of the License, or 640 | (at your option) any later version. 641 | 642 | This program is distributed in the hope that it will be useful, 643 | but WITHOUT ANY WARRANTY; without even the implied warranty of 644 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 645 | GNU General Public License for more details. 646 | 647 | You should have received a copy of the GNU General Public License 648 | along with this program. If not, see . 649 | 650 | Also add information on how to contact you by electronic and paper mail. 651 | 652 | If the program does terminal interaction, make it output a short 653 | notice like this when it starts in an interactive mode: 654 | 655 | Copyright (C) 656 | This program comes with ABSOLUTELY NO WARRANTY; for details type `show w'. 657 | This is free software, and you are welcome to redistribute it 658 | under certain conditions; type `show c' for details. 659 | 660 | The hypothetical commands `show w' and `show c' should show the appropriate 661 | parts of the General Public License. Of course, your program's commands 662 | might be different; for a GUI interface, you would use an "about box". 663 | 664 | You should also get your employer (if you work as a programmer) or school, 665 | if any, to sign a "copyright disclaimer" for the program, if necessary. 666 | For more information on this, and how to apply and follow the GNU GPL, see 667 | . 668 | 669 | The GNU General Public License does not permit incorporating your program 670 | into proprietary programs. If your program is a subroutine library, you 671 | may consider it more useful to permit linking proprietary applications with 672 | the library. If this is what you want to do, use the GNU Lesser General 673 | Public License instead of this License. But first, please read 674 | . 675 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # ✅ Resource World ✅ ~ Never run out of Resources ! 2 | 3 | ⋙ Don't let your Wilderness get depleted, Set up an Automatically resetting Resource World. ⋘ 4 | 5 | ## License 6 | 7 | ``` 8 | This Project is Licensed under the GNU General Public License v3.0 9 | ``` 10 | 11 | ![bStats](https://bstats.org/signatures/bukkit/ResourceWorld.svg) 12 | -------------------------------------------------------------------------------- /ResourceWorld.iml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | SPIGOT 8 | BUKKIT 9 | 10 | 11 | 12 | 13 | -------------------------------------------------------------------------------- /img/CoffeeLoversLogo-BIG.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/NikV2/ResourceWorld/174d2267114501c9e20f2d61320f97d7f9be12a5/img/CoffeeLoversLogo-BIG.png -------------------------------------------------------------------------------- /img/Commands.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/NikV2/ResourceWorld/174d2267114501c9e20f2d61320f97d7f9be12a5/img/Commands.png -------------------------------------------------------------------------------- /img/Information.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/NikV2/ResourceWorld/174d2267114501c9e20f2d61320f97d7f9be12a5/img/Information.png -------------------------------------------------------------------------------- /img/Installation.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/NikV2/ResourceWorld/174d2267114501c9e20f2d61320f97d7f9be12a5/img/Installation.png -------------------------------------------------------------------------------- /img/PayPal-Donate-Button-284-x-136.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/NikV2/ResourceWorld/174d2267114501c9e20f2d61320f97d7f9be12a5/img/PayPal-Donate-Button-284-x-136.jpg -------------------------------------------------------------------------------- /img/Permissions.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/NikV2/ResourceWorld/174d2267114501c9e20f2d61320f97d7f9be12a5/img/Permissions.png -------------------------------------------------------------------------------- /img/RW-LOGO.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/NikV2/ResourceWorld/174d2267114501c9e20f2d61320f97d7f9be12a5/img/RW-LOGO.jpg -------------------------------------------------------------------------------- /img/iconrw.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/NikV2/ResourceWorld/174d2267114501c9e20f2d61320f97d7f9be12a5/img/iconrw.png -------------------------------------------------------------------------------- /pom.xml: -------------------------------------------------------------------------------- 1 | 2 | 5 | 4.0.0 6 | 7 | me.nik 8 | ResourceWorld 9 | 2.1.0 10 | jar 11 | 12 | ResourceWorld 13 | 14 | Unlimited resources! 15 | 16 | 1.8 17 | UTF-8 18 | 19 | https://discord.gg/m7j2Y9H 20 | 21 | 22 | clean package 23 | 24 | 25 | org.apache.maven.plugins 26 | maven-compiler-plugin 27 | 3.8.1 28 | 29 | ${java.version} 30 | ${java.version} 31 | 32 | 33 | 34 | org.apache.maven.plugins 35 | maven-shade-plugin 36 | 3.2.4 37 | 38 | 39 | package 40 | 41 | shade 42 | 43 | 44 | false 45 | 46 | 47 | io.papermc.lib 48 | resourceworld_libs.paperlib 49 | 50 | 51 | 52 | 53 | 54 | 55 | 56 | 57 | 58 | src/main/resources 59 | true 60 | 61 | 62 | 63 | 64 | 65 | 66 | 67 | spigotmc-repo 68 | https://hub.spigotmc.org/nexus/content/repositories/snapshots/ 69 | 70 | 71 | 72 | sonatype 73 | https://oss.sonatype.org/content/groups/public/ 74 | 75 | 76 | 77 | papermc 78 | https://papermc.io/repo/repository/maven-public/ 79 | 80 | 81 | 82 | placeholderapi 83 | https://repo.extendedclip.com/content/repositories/placeholderapi/ 84 | 85 | 86 | 87 | jitpack.io 88 | https://jitpack.io 89 | 90 | 91 | 92 | 93 | 94 | 95 | 96 | io.papermc 97 | paperlib 98 | 1.0.8 99 | compile 100 | 101 | 102 | 103 | org.spigotmc 104 | spigot-api 105 | 1.21.4-R0.1-SNAPSHOT 106 | provided 107 | 108 | 109 | 110 | me.clip 111 | placeholderapi 112 | 2.11.6 113 | provided 114 | 115 | 116 | 117 | com.github.MilkBowl 118 | VaultAPI 119 | 1.7.1 120 | provided 121 | 122 | 123 | 124 | -------------------------------------------------------------------------------- /src/main/java/me/nik/resourceworld/ResourceWorld.java: -------------------------------------------------------------------------------- 1 | package me.nik.resourceworld; 2 | 3 | import me.nik.resourceworld.api.ResourceWorldType; 4 | import me.nik.resourceworld.commands.CommandManager; 5 | import me.nik.resourceworld.files.Config; 6 | import me.nik.resourceworld.files.Data; 7 | import me.nik.resourceworld.files.Lang; 8 | import me.nik.resourceworld.files.commentedfiles.CommentedFileConfiguration; 9 | import me.nik.resourceworld.gui.GuiListener; 10 | import me.nik.resourceworld.managers.PapiHook; 11 | import me.nik.resourceworld.managers.UpdateChecker; 12 | import me.nik.resourceworld.managers.custom.CustomWorld; 13 | import me.nik.resourceworld.metrics.MetricsLite; 14 | import me.nik.resourceworld.modules.ListenerModule; 15 | import me.nik.resourceworld.modules.impl.DisabledCommands; 16 | import me.nik.resourceworld.modules.impl.LeaveWorld; 17 | import me.nik.resourceworld.modules.impl.Portals; 18 | import me.nik.resourceworld.modules.impl.Suffocation; 19 | import me.nik.resourceworld.tasks.AlwaysDay; 20 | import me.nik.resourceworld.tasks.ResetEndWorld; 21 | import me.nik.resourceworld.tasks.ResetNetherWorld; 22 | import me.nik.resourceworld.tasks.ResetWorld; 23 | import org.bukkit.Bukkit; 24 | import org.bukkit.ChatColor; 25 | import org.bukkit.Difficulty; 26 | import org.bukkit.World; 27 | import org.bukkit.WorldType; 28 | import org.bukkit.configuration.file.FileConfiguration; 29 | import org.bukkit.event.HandlerList; 30 | import org.bukkit.plugin.java.JavaPlugin; 31 | 32 | import java.util.ArrayList; 33 | import java.util.Arrays; 34 | import java.util.HashMap; 35 | import java.util.List; 36 | import java.util.Map; 37 | 38 | public final class ResourceWorld extends JavaPlugin { 39 | 40 | private static ResourceWorld plugin; 41 | 42 | private final Config config = new Config(this); 43 | private final Data data = new Data(); 44 | private final Lang lang = new Lang(); 45 | private final String[] STARTUP_MESSAGE = { 46 | " ", 47 | ChatColor.GREEN + "Resource World v" + this.getDescription().getVersion(), 48 | " ", 49 | ChatColor.WHITE + " Author: Nik", 50 | " " 51 | }; 52 | private final Map resourceWorlds = new HashMap<>(); 53 | private final List listenerModules = new ArrayList<>(); 54 | 55 | public static ResourceWorld getInstance() { 56 | return plugin; 57 | } 58 | 59 | @Override 60 | public void onDisable() { 61 | 62 | //DisInitialize modules 63 | this.listenerModules.forEach(ListenerModule::shutdown); 64 | 65 | //Store Time Left 66 | if (Config.Setting.WORLD_RESETS_ENABLED.getBoolean() && Config.Setting.WORLD_ENABLED.getBoolean() && Config.Setting.WORLD_STORE_TIME.getBoolean()) { 67 | this.data.get().set("world.timer", Config.Setting.WORLD_RESETS_INTERVAL.getInt() * 72000L 68 | - (System.currentTimeMillis() - this.data.get().getLong("world.millis")) / 1000D * 20D); 69 | } 70 | if (Config.Setting.NETHER_RESETS_ENABLED.getBoolean() && Config.Setting.NETHER_ENABLED.getBoolean() && Config.Setting.NETHER_STORE_TIME.getBoolean()) { 71 | this.data.get().set("nether.timer", Config.Setting.NETHER_RESETS_INTERVAL.getInt() * 72000L 72 | - (System.currentTimeMillis() - this.data.get().getLong("nether.millis")) / 1000D * 20D); 73 | } 74 | if (Config.Setting.END_RESETS_ENABLED.getBoolean() && Config.Setting.END_ENABLED.getBoolean() && Config.Setting.END_STORE_TIME.getBoolean()) { 75 | this.data.get().set("end.timer", Config.Setting.END_RESETS_INTERVAL.getInt() * 72000L 76 | - (System.currentTimeMillis() - this.data.get().getLong("end.millis")) / 1000D * 20D); 77 | } 78 | 79 | this.data.save(); 80 | 81 | //Reload Files 82 | this.config.reset(); 83 | this.lang.reload(); 84 | this.lang.save(); 85 | 86 | HandlerList.unregisterAll(this); 87 | this.getServer().getScheduler().cancelTasks(this); 88 | plugin = null; 89 | } 90 | 91 | public Map getResourceWorlds() { 92 | return resourceWorlds; 93 | } 94 | 95 | @Override 96 | public void onEnable() { 97 | plugin = this; 98 | 99 | //Startup Message 100 | this.getServer().getConsoleSender().sendMessage(STARTUP_MESSAGE); 101 | 102 | //Load Files 103 | this.config.setup(); 104 | 105 | this.lang.setup(this); 106 | this.lang.addDefaults(); 107 | this.lang.get().options().copyDefaults(true); 108 | this.lang.save(); 109 | 110 | this.data.setup(this); 111 | this.data.addDefaults(); 112 | this.data.get().options().copyDefaults(true); 113 | this.data.save(); 114 | 115 | getCommand("resource").setExecutor(new CommandManager(this)); 116 | 117 | //Load listener modules 118 | this.listenerModules.addAll(Arrays.asList( 119 | new LeaveWorld(this), 120 | new Suffocation(this), 121 | new Portals(this), 122 | new DisabledCommands(this) 123 | )); 124 | 125 | //Initialize them 126 | this.listenerModules.forEach(ListenerModule::load); 127 | 128 | //Don't be an idiot Nik, Always register this Listener 129 | Bukkit.getPluginManager().registerEvents(new GuiListener(), this); 130 | 131 | //Handle resource worlds 132 | this.resourceWorlds.clear(); 133 | 134 | if (Config.Setting.WORLD_ENABLED.getBoolean()) { 135 | this.resourceWorlds.put( 136 | ResourceWorldType.RESOURCE_WORLD, 137 | new CustomWorld(Config.Setting.WORLD_NAME.getString(), 138 | Difficulty.valueOf(Config.Setting.WORLD_DIFFICULTY.getString()), 139 | WorldType.valueOf(Config.Setting.WORLD_TYPE.getString()), 140 | World.Environment.valueOf(Config.Setting.WORLD_ENVIRONMENT.getString()), 141 | Config.Setting.WORLD_GENERATE_STRUCTURES.getBoolean(), 142 | Config.Setting.WORLD_SEED_ENABLED.getBoolean(), 143 | Config.Setting.WORLD_SEED.getLong(), 144 | Config.Setting.WORLD_BORDER_ENABLED.getBoolean(), 145 | Config.Setting.WORLD_BORDER_SIZE.getInt(), 146 | Config.Setting.WORLD_PVP.getBoolean(), 147 | Config.Setting.WORLD_KEEP_INVENTORY.getBoolean(), 148 | ResourceWorldType.RESOURCE_WORLD).generate()); 149 | } 150 | 151 | if (Config.Setting.NETHER_ENABLED.getBoolean()) { 152 | this.resourceWorlds.put( 153 | ResourceWorldType.RESOURCE_NETHER, 154 | new CustomWorld(Config.Setting.NETHER_NAME.getString(), 155 | Difficulty.valueOf(Config.Setting.NETHER_DIFFICULTY.getString()), 156 | WorldType.valueOf(Config.Setting.NETHER_TYPE.getString()), 157 | World.Environment.valueOf(Config.Setting.NETHER_ENVIRONMENT.getString()), 158 | Config.Setting.NETHER_GENERATE_STRUCTURES.getBoolean(), 159 | Config.Setting.NETHER_SEED_ENABLED.getBoolean(), 160 | Config.Setting.NETHER_SEED.getLong(), 161 | Config.Setting.NETHER_BORDER_ENABLED.getBoolean(), 162 | Config.Setting.NETHER_BORDER_SIZE.getInt(), 163 | Config.Setting.NETHER_PVP.getBoolean(), 164 | Config.Setting.NETHER_KEEP_INVENTORY.getBoolean(), 165 | ResourceWorldType.RESOURCE_NETHER).generate()); 166 | } 167 | 168 | if (Config.Setting.END_ENABLED.getBoolean()) { 169 | this.resourceWorlds.put( 170 | ResourceWorldType.RESOURCE_END, 171 | new CustomWorld(Config.Setting.END_NAME.getString(), 172 | Difficulty.valueOf(Config.Setting.END_DIFFICULTY.getString()), 173 | WorldType.valueOf(Config.Setting.END_TYPE.getString()), 174 | World.Environment.valueOf(Config.Setting.END_ENVIRONMENT.getString()), 175 | Config.Setting.END_GENERATE_STRUCTURES.getBoolean(), 176 | Config.Setting.END_SEED_ENABLED.getBoolean(), 177 | Config.Setting.END_SEED.getLong(), 178 | Config.Setting.END_BORDER_ENABLED.getBoolean(), 179 | Config.Setting.END_BORDER_SIZE.getInt(), 180 | Config.Setting.END_PVP.getBoolean(), 181 | Config.Setting.END_KEEP_INVENTORY.getBoolean(), 182 | ResourceWorldType.RESOURCE_END).generate()); 183 | } 184 | 185 | //Handle timestamps 186 | 187 | if (Config.Setting.WORLD_ENABLED.getBoolean() && Config.Setting.WORLD_STORE_TIME.getBoolean() && this.data.get().getLong("world.millis") <= 0) { 188 | this.data.get().set("world.millis", System.currentTimeMillis()); 189 | this.data.save(); 190 | this.data.reload(); 191 | } 192 | if (Config.Setting.NETHER_ENABLED.getBoolean() && Config.Setting.NETHER_STORE_TIME.getBoolean() && this.data.get().getLong("nether.millis") <= 0) { 193 | this.data.get().set("nether.millis", System.currentTimeMillis()); 194 | this.data.save(); 195 | this.data.reload(); 196 | } 197 | if (Config.Setting.END_ENABLED.getBoolean() && Config.Setting.END_STORE_TIME.getBoolean() && this.data.get().getLong("end.millis") <= 0) { 198 | this.data.get().set("end.millis", System.currentTimeMillis()); 199 | this.data.save(); 200 | this.data.reload(); 201 | } 202 | 203 | this.data.get().set("world.papi", System.currentTimeMillis()); 204 | this.data.get().set("nether.papi", System.currentTimeMillis()); 205 | this.data.get().set("end.papi", System.currentTimeMillis()); 206 | 207 | //Initialize tasks 208 | 209 | if (Config.Setting.WORLD_ENABLED.getBoolean() && Config.Setting.WORLD_RESETS_ENABLED.getBoolean()) { 210 | 211 | long timer; 212 | 213 | if (!Config.Setting.WORLD_STORE_TIME.getBoolean()) { 214 | timer = Config.Setting.WORLD_RESETS_INTERVAL.getLong() * 72000L; 215 | } else if (this.data.get().getLong("world.timer") <= 0) { 216 | timer = Config.Setting.WORLD_RESETS_INTERVAL.getLong() * 72000L; 217 | } else { 218 | timer = this.data.get().getLong("world.timer"); 219 | } 220 | 221 | new ResetWorld(this).runTaskTimer(this, 222 | timer, 223 | Config.Setting.WORLD_RESETS_INTERVAL.getLong() * 72000L); 224 | } 225 | 226 | if (Config.Setting.NETHER_ENABLED.getBoolean() && Config.Setting.NETHER_RESETS_ENABLED.getBoolean()) { 227 | 228 | long timer; 229 | 230 | if (!Config.Setting.NETHER_STORE_TIME.getBoolean()) { 231 | timer = Config.Setting.NETHER_RESETS_INTERVAL.getLong() * 72000L; 232 | } else if (this.data.get().getLong("nether.timer") <= 0) { 233 | timer = Config.Setting.NETHER_RESETS_INTERVAL.getLong() * 72000L; 234 | } else { 235 | timer = this.data.get().getLong("nether.timer"); 236 | } 237 | 238 | new ResetNetherWorld(this).runTaskTimer(this, 239 | timer, 240 | Config.Setting.NETHER_RESETS_INTERVAL.getLong() * 72000L); 241 | } 242 | 243 | if (Config.Setting.END_ENABLED.getBoolean() && Config.Setting.END_RESETS_ENABLED.getBoolean()) { 244 | 245 | long timer; 246 | 247 | if (!Config.Setting.END_STORE_TIME.getBoolean()) { 248 | timer = Config.Setting.END_RESETS_INTERVAL.getLong() * 72000L; 249 | } else if (this.data.get().getLong("end.timer") <= 0) { 250 | timer = Config.Setting.END_RESETS_INTERVAL.getLong() * 72000L; 251 | } else { 252 | timer = this.data.get().getLong("end.timer"); 253 | } 254 | 255 | new ResetEndWorld(this).runTaskTimer(this, 256 | timer, 257 | Config.Setting.END_RESETS_INTERVAL.getLong() * 72000L); 258 | } 259 | 260 | if (Config.Setting.WORLD_ALWAYS_DAY.getBoolean()) new AlwaysDay().runTaskTimer(this, 1200L, 1200L); 261 | 262 | //Check for updates 263 | if (Config.Setting.SETTINGS_CHECK_FOR_UPDATES.getBoolean()) { 264 | new UpdateChecker(this).runTaskAsynchronously(this); 265 | } 266 | 267 | //PlaceholderAPI 268 | if (this.getServer().getPluginManager().getPlugin("PlaceholderAPI") != null) { 269 | new PapiHook(this).register(); 270 | } 271 | 272 | //BStats 273 | new MetricsLite(this, 6981); 274 | } 275 | 276 | public CustomWorld getResourceWorld(ResourceWorldType type) { 277 | return this.resourceWorlds.get(type); 278 | } 279 | 280 | public CommentedFileConfiguration getConfiguration() { 281 | return config.getConfig(); 282 | } 283 | 284 | public FileConfiguration getLang() { 285 | return lang.get(); 286 | } 287 | 288 | public FileConfiguration getData() { 289 | return data.get(); 290 | } 291 | 292 | public void saveData() { 293 | data.save(); 294 | } 295 | 296 | public void reloadData() { 297 | data.reload(); 298 | } 299 | } -------------------------------------------------------------------------------- /src/main/java/me/nik/resourceworld/api/ResourceWorldType.java: -------------------------------------------------------------------------------- 1 | package me.nik.resourceworld.api; 2 | 3 | public enum ResourceWorldType { 4 | RESOURCE_WORLD, 5 | RESOURCE_NETHER, 6 | RESOURCE_END 7 | } -------------------------------------------------------------------------------- /src/main/java/me/nik/resourceworld/commands/CommandManager.java: -------------------------------------------------------------------------------- 1 | package me.nik.resourceworld.commands; 2 | 3 | import me.nik.resourceworld.ResourceWorld; 4 | import me.nik.resourceworld.commands.subcommands.Menu; 5 | import me.nik.resourceworld.commands.subcommands.Reload; 6 | import me.nik.resourceworld.commands.subcommands.Reset; 7 | import me.nik.resourceworld.commands.subcommands.Teleport; 8 | import me.nik.resourceworld.managers.MsgType; 9 | import org.bukkit.ChatColor; 10 | import org.bukkit.command.Command; 11 | import org.bukkit.command.CommandSender; 12 | import org.bukkit.command.ConsoleCommandSender; 13 | import org.bukkit.command.TabExecutor; 14 | 15 | import java.util.ArrayList; 16 | import java.util.List; 17 | 18 | public class CommandManager implements TabExecutor { 19 | 20 | private static final String INFO_MESSAGE = MsgType.PREFIX.getMessage() 21 | + ChatColor.GRAY + "You're running " + ChatColor.WHITE 22 | + ResourceWorld.getInstance().getDescription().getName() + ChatColor.GRAY + " version " 23 | + ChatColor.GREEN + "v" + ResourceWorld.getInstance().getDescription().getVersion() 24 | + ChatColor.GRAY + " by" + ChatColor.WHITE + " Nik"; 25 | private final List subcommands = new ArrayList<>(); 26 | 27 | public CommandManager(ResourceWorld plugin) { 28 | subcommands.add(new Teleport()); 29 | subcommands.add(new Reload(plugin)); 30 | subcommands.add(new Menu(plugin)); 31 | subcommands.add(new Reset(plugin)); 32 | } 33 | 34 | public List getSubcommands() { 35 | return subcommands; 36 | } 37 | 38 | @Override 39 | public List onTabComplete(CommandSender sender, Command command, String alias, String[] args) { 40 | if (args.length == 1) { 41 | ArrayList subcommandsArgs = new ArrayList<>(); 42 | for (int i = 0; i < getSubcommands().size(); i++) { 43 | subcommandsArgs.add(getSubcommands().get(i).getName()); 44 | } 45 | return subcommandsArgs; 46 | } else if (args.length == 2) { 47 | for (int i = 0; i < getSubcommands().size(); i++) { 48 | if (args[0].equalsIgnoreCase(getSubcommands().get(i).getName())) { 49 | return getSubcommands().get(i).getSubcommandArguments(sender, args); 50 | } 51 | } 52 | } 53 | return null; 54 | } 55 | 56 | private void helpMessage(CommandSender sender) { 57 | sender.sendMessage(""); 58 | sender.sendMessage(MsgType.PREFIX.getMessage() + ChatColor.GRAY + "Available Commands"); 59 | sender.sendMessage(""); 60 | this.subcommands.stream().filter(subCommand -> sender.hasPermission(subCommand.getPermission())) 61 | .forEach(subCommand -> sender.sendMessage(ChatColor.GREEN 62 | + subCommand.getSyntax() 63 | + ChatColor.DARK_GRAY + " - " 64 | + ChatColor.GRAY + subCommand.getDescription())); 65 | sender.sendMessage(""); 66 | } 67 | 68 | @Override 69 | public boolean onCommand(CommandSender sender, Command command, String label, String[] args) { 70 | if (args.length > 0) { 71 | 72 | for (int i = 0; i < getSubcommands().size(); i++) { 73 | 74 | final SubCommand subCommand = getSubcommands().get(i); 75 | 76 | if (args[0].equalsIgnoreCase(subCommand.getName())) { 77 | 78 | if (!subCommand.canConsoleExecute() && sender instanceof ConsoleCommandSender) { 79 | 80 | sender.sendMessage(MsgType.CONSOLE_MESSAGE.getMessage()); 81 | 82 | return true; 83 | } 84 | 85 | if (!sender.hasPermission(subCommand.getPermission())) { 86 | 87 | sender.sendMessage(MsgType.NO_PERMISSION.getMessage()); 88 | 89 | return true; 90 | } 91 | 92 | if (args.length < subCommand.maxArguments()) { 93 | 94 | helpMessage(sender); 95 | 96 | return true; 97 | } 98 | 99 | subCommand.perform(sender, args); 100 | 101 | return true; 102 | } 103 | 104 | if (args[0].equalsIgnoreCase("help")) { 105 | 106 | helpMessage(sender); 107 | 108 | return true; 109 | } 110 | } 111 | 112 | } else { 113 | 114 | sender.sendMessage(INFO_MESSAGE); 115 | 116 | return true; 117 | } 118 | 119 | helpMessage(sender); 120 | 121 | return true; 122 | } 123 | } -------------------------------------------------------------------------------- /src/main/java/me/nik/resourceworld/commands/SubCommand.java: -------------------------------------------------------------------------------- 1 | package me.nik.resourceworld.commands; 2 | 3 | import org.bukkit.command.CommandSender; 4 | 5 | import java.util.List; 6 | 7 | public abstract class SubCommand { 8 | 9 | protected abstract String getName(); 10 | 11 | protected abstract String getDescription(); 12 | 13 | protected abstract String getSyntax(); 14 | 15 | protected abstract String getPermission(); 16 | 17 | protected abstract int maxArguments(); 18 | 19 | protected abstract boolean canConsoleExecute(); 20 | 21 | protected abstract void perform(CommandSender sender, String[] args); 22 | 23 | protected abstract List getSubcommandArguments(CommandSender sender, String[] args); 24 | } -------------------------------------------------------------------------------- /src/main/java/me/nik/resourceworld/commands/subcommands/Menu.java: -------------------------------------------------------------------------------- 1 | package me.nik.resourceworld.commands.subcommands; 2 | 3 | import me.nik.resourceworld.ResourceWorld; 4 | import me.nik.resourceworld.commands.SubCommand; 5 | import me.nik.resourceworld.gui.PlayerMenu; 6 | import me.nik.resourceworld.gui.menus.MainGui; 7 | import me.nik.resourceworld.managers.Permissions; 8 | import org.bukkit.command.CommandSender; 9 | import org.bukkit.entity.Player; 10 | 11 | import java.util.List; 12 | 13 | public class Menu extends SubCommand { 14 | 15 | private final ResourceWorld plugin; 16 | 17 | public Menu(ResourceWorld plugin) { 18 | this.plugin = plugin; 19 | } 20 | 21 | @Override 22 | public String getName() { 23 | return "menu"; 24 | } 25 | 26 | @Override 27 | public String getDescription() { 28 | return "Open the Resource World Menu!"; 29 | } 30 | 31 | @Override 32 | public String getSyntax() { 33 | return "/resource menu"; 34 | } 35 | 36 | @Override 37 | public String getPermission() { 38 | return Permissions.ADMIN.getPermission(); 39 | } 40 | 41 | @Override 42 | protected int maxArguments() { 43 | return 1; 44 | } 45 | 46 | @Override 47 | public boolean canConsoleExecute() { 48 | return false; 49 | } 50 | 51 | @Override 52 | public void perform(CommandSender sender, String[] args) { 53 | new MainGui(new PlayerMenu((Player) sender), plugin).open(); 54 | } 55 | 56 | @Override 57 | public List getSubcommandArguments(CommandSender sender, String[] args) { 58 | return null; 59 | } 60 | } -------------------------------------------------------------------------------- /src/main/java/me/nik/resourceworld/commands/subcommands/Reload.java: -------------------------------------------------------------------------------- 1 | package me.nik.resourceworld.commands.subcommands; 2 | 3 | import me.nik.resourceworld.ResourceWorld; 4 | import me.nik.resourceworld.commands.SubCommand; 5 | import me.nik.resourceworld.managers.MsgType; 6 | import me.nik.resourceworld.managers.Permissions; 7 | import org.bukkit.command.CommandSender; 8 | 9 | import java.util.List; 10 | 11 | public class Reload extends SubCommand { 12 | 13 | private final ResourceWorld plugin; 14 | 15 | public Reload(ResourceWorld plugin) { 16 | this.plugin = plugin; 17 | } 18 | 19 | @Override 20 | public String getName() { 21 | return "reload"; 22 | } 23 | 24 | @Override 25 | public String getDescription() { 26 | return "Reload the plugin"; 27 | } 28 | 29 | @Override 30 | public String getSyntax() { 31 | return "/resource reload"; 32 | } 33 | 34 | @Override 35 | public String getPermission() { 36 | return Permissions.ADMIN.getPermission(); 37 | } 38 | 39 | @Override 40 | protected int maxArguments() { 41 | return 1; 42 | } 43 | 44 | @Override 45 | public boolean canConsoleExecute() { 46 | return true; 47 | } 48 | 49 | @Override 50 | public void perform(CommandSender sender, String[] args) { 51 | plugin.onDisable(); 52 | plugin.onEnable(); 53 | sender.sendMessage(MsgType.RELOADED.getMessage()); 54 | } 55 | 56 | @Override 57 | public List getSubcommandArguments(CommandSender sender, String[] args) { 58 | return null; 59 | } 60 | } -------------------------------------------------------------------------------- /src/main/java/me/nik/resourceworld/commands/subcommands/Reset.java: -------------------------------------------------------------------------------- 1 | package me.nik.resourceworld.commands.subcommands; 2 | 3 | import me.nik.resourceworld.ResourceWorld; 4 | import me.nik.resourceworld.api.ResourceWorldType; 5 | import me.nik.resourceworld.commands.SubCommand; 6 | import me.nik.resourceworld.files.Config; 7 | import me.nik.resourceworld.managers.MsgType; 8 | import me.nik.resourceworld.managers.Permissions; 9 | import me.nik.resourceworld.managers.custom.CustomWorld; 10 | import org.bukkit.Bukkit; 11 | import org.bukkit.command.CommandSender; 12 | 13 | import java.util.ArrayList; 14 | import java.util.List; 15 | 16 | public class Reset extends SubCommand { 17 | 18 | private final ResourceWorld plugin; 19 | 20 | private long lastResetMillis; 21 | 22 | public Reset(ResourceWorld plugin) { 23 | this.plugin = plugin; 24 | } 25 | 26 | @Override 27 | public String getName() { 28 | return "reset"; 29 | } 30 | 31 | @Override 32 | public String getDescription() { 33 | return "Reset the Resource World!"; 34 | } 35 | 36 | @Override 37 | public String getSyntax() { 38 | return "/resource reset "; 39 | } 40 | 41 | @Override 42 | public String getPermission() { 43 | return Permissions.ADMIN.getPermission(); 44 | } 45 | 46 | @Override 47 | protected int maxArguments() { 48 | return 1; 49 | } 50 | 51 | @Override 52 | public boolean canConsoleExecute() { 53 | return true; 54 | } 55 | 56 | @Override 57 | public void perform(CommandSender sender, String[] args) { 58 | 59 | //General check to make sure they don't try to mess with this. 60 | if (System.currentTimeMillis() - this.lastResetMillis < 10000L) return; 61 | 62 | this.lastResetMillis = System.currentTimeMillis(); 63 | 64 | CustomWorld resourceWorld = null; 65 | 66 | switch (args.length) { 67 | 68 | case 1: 69 | 70 | resourceWorld = this.plugin.getResourceWorld(ResourceWorldType.RESOURCE_WORLD); 71 | 72 | break; 73 | 74 | case 2: 75 | 76 | switch (args[1].toLowerCase()) { 77 | 78 | case "nether": 79 | 80 | resourceWorld = this.plugin.getResourceWorld(ResourceWorldType.RESOURCE_NETHER); 81 | 82 | break; 83 | 84 | case "end": 85 | 86 | resourceWorld = this.plugin.getResourceWorld(ResourceWorldType.RESOURCE_END); 87 | 88 | break; 89 | } 90 | 91 | break; 92 | } 93 | 94 | if (resourceWorld == null) { 95 | 96 | sender.sendMessage(MsgType.NOT_EXIST.getMessage()); 97 | 98 | } else resourceWorld.reset(); 99 | } 100 | 101 | @Override 102 | public List getSubcommandArguments(CommandSender sender, String[] args) { 103 | 104 | if (args.length == 2) { 105 | 106 | List worlds = new ArrayList<>(); 107 | 108 | if (Bukkit.getWorld(Config.Setting.NETHER_NAME.getString()) != null) { 109 | worlds.add("nether"); 110 | } 111 | 112 | if (Bukkit.getWorld(Config.Setting.END_NAME.getString()) != null) { 113 | worlds.add("end"); 114 | } 115 | 116 | return worlds; 117 | } 118 | 119 | return null; 120 | } 121 | } -------------------------------------------------------------------------------- /src/main/java/me/nik/resourceworld/commands/subcommands/Teleport.java: -------------------------------------------------------------------------------- 1 | package me.nik.resourceworld.commands.subcommands; 2 | 3 | import me.nik.resourceworld.commands.SubCommand; 4 | import me.nik.resourceworld.files.Config; 5 | import me.nik.resourceworld.managers.MsgType; 6 | import me.nik.resourceworld.managers.Permissions; 7 | import me.nik.resourceworld.utils.LocationFinder; 8 | import me.nik.resourceworld.utils.TaskUtils; 9 | import me.nik.resourceworld.utils.custom.ExpiringMap; 10 | import net.milkbowl.vault.economy.Economy; 11 | import net.milkbowl.vault.economy.EconomyResponse; 12 | import org.bukkit.Bukkit; 13 | import org.bukkit.World; 14 | import org.bukkit.command.CommandSender; 15 | import org.bukkit.entity.Player; 16 | import org.bukkit.plugin.RegisteredServiceProvider; 17 | 18 | import java.util.ArrayList; 19 | import java.util.List; 20 | import java.util.UUID; 21 | 22 | public class Teleport extends SubCommand { 23 | 24 | private final Economy economy; 25 | /* 26 | Clear outdated cache automatically. 27 | */ 28 | private final ExpiringMap cooldown = new ExpiringMap<>(600000); 29 | private final LocationFinder locationFinder = new LocationFinder(); 30 | 31 | public Teleport() { 32 | 33 | //Load Vault if found 34 | if (Bukkit.getPluginManager().getPlugin("Vault") != null) { 35 | 36 | RegisteredServiceProvider rsp = Bukkit.getServer().getServicesManager().getRegistration(Economy.class); 37 | 38 | if (rsp != null) { 39 | this.economy = rsp.getProvider(); 40 | return; 41 | } 42 | } 43 | 44 | this.economy = null; 45 | } 46 | 47 | @Override 48 | public String getName() { 49 | return "tp"; 50 | } 51 | 52 | @Override 53 | public String getDescription() { 54 | return "Randomly Teleport To The Resource World!"; 55 | } 56 | 57 | @Override 58 | public String getSyntax() { 59 | return "/resource tp "; 60 | } 61 | 62 | @Override 63 | public String getPermission() { 64 | return Permissions.TELEPORT.getPermission(); 65 | } 66 | 67 | @Override 68 | protected int maxArguments() { 69 | return 1; 70 | } 71 | 72 | @Override 73 | public boolean canConsoleExecute() { 74 | return false; 75 | } 76 | 77 | @Override 78 | public void perform(CommandSender sender, String[] args) { 79 | 80 | Player player = (Player) sender; 81 | 82 | UUID uuid = player.getUniqueId(); 83 | 84 | long currentTime = System.currentTimeMillis(); 85 | 86 | if (this.cooldown.containsKey(uuid)) { 87 | 88 | long secondsleft = ((this.cooldown.get(uuid) / 1000L) + Config.Setting.TELEPORT_COOLDOWN.getLong()) - (currentTime / 1000L); 89 | 90 | if (secondsleft <= 0L) { 91 | 92 | this.cooldown.remove(uuid); 93 | 94 | } else { 95 | 96 | player.sendMessage(MsgType.COOLDOWN_MESSAGE.getMessage().replaceAll("%seconds%", String.valueOf(secondsleft))); 97 | 98 | return; 99 | } 100 | } 101 | 102 | World world = null; 103 | 104 | switch (args.length) { 105 | 106 | case 1: { 107 | 108 | world = Bukkit.getWorld(Config.Setting.WORLD_NAME.getString()); 109 | 110 | break; 111 | } 112 | 113 | case 2: { 114 | 115 | switch (args[1].toLowerCase()) { 116 | 117 | case "nether": 118 | 119 | if (!player.hasPermission(Permissions.TELEPORT_NETHER.getPermission())) { 120 | 121 | player.sendMessage(MsgType.NO_PERMISSION.getMessage()); 122 | 123 | return; 124 | } 125 | 126 | world = Bukkit.getWorld(Config.Setting.NETHER_NAME.getString()); 127 | 128 | break; 129 | 130 | case "end": 131 | 132 | if (!player.hasPermission(Permissions.TELEPORT_END.getPermission())) { 133 | 134 | player.sendMessage(MsgType.NO_PERMISSION.getMessage()); 135 | 136 | return; 137 | } 138 | 139 | world = Bukkit.getWorld(Config.Setting.END_NAME.getString()); 140 | 141 | break; 142 | } 143 | } 144 | } 145 | 146 | if (world == null) return; 147 | 148 | boolean notBypassing = !player.hasPermission(Permissions.ADMIN.getPermission()); 149 | 150 | //Handle vault 151 | if (this.economy != null && Config.Setting.TELEPORT_PRICE.getDouble() > 0D && notBypassing) { 152 | 153 | EconomyResponse res = this.economy.withdrawPlayer(player, Config.Setting.TELEPORT_PRICE.getDouble()); 154 | 155 | if (res.transactionSuccess()) { 156 | 157 | player.sendMessage(MsgType.TELEPORT_PAID.getMessage().replace("%price%", this.economy.format(res.amount))); 158 | 159 | } else { 160 | 161 | player.sendMessage(MsgType.TELEPORT_ERROR.getMessage()); 162 | 163 | return; 164 | } 165 | } 166 | 167 | //Add to cooldown 168 | if (notBypassing && Config.Setting.TELEPORT_COOLDOWN.getLong() > 0L) { 169 | 170 | this.cooldown.put(player.getUniqueId(), System.currentTimeMillis()); 171 | } 172 | 173 | //Finally teleport 174 | if (Config.Setting.TELEPORT_DELAY.getLong() <= 0L) { 175 | 176 | this.locationFinder.teleportSafely(player, world); 177 | 178 | } else { 179 | 180 | player.sendMessage(MsgType.TELEPORT_DELAY.getMessage().replaceAll("%seconds%", String.valueOf(Config.Setting.TELEPORT_DELAY.getLong()))); 181 | 182 | World finalWorld = world; 183 | TaskUtils.taskLater(() -> this.locationFinder.teleportSafely(player, finalWorld), Config.Setting.TELEPORT_DELAY.getLong() * 20L); 184 | } 185 | } 186 | 187 | @Override 188 | public List getSubcommandArguments(CommandSender sender, String[] args) { 189 | 190 | if (args.length == 2) { 191 | 192 | List worlds = new ArrayList<>(); 193 | 194 | if (Bukkit.getWorld(Config.Setting.NETHER_NAME.getString()) != null) { 195 | worlds.add("nether"); 196 | } 197 | 198 | if (Bukkit.getWorld(Config.Setting.END_NAME.getString()) != null) { 199 | worlds.add("end"); 200 | } 201 | 202 | return worlds; 203 | } 204 | 205 | return null; 206 | } 207 | } -------------------------------------------------------------------------------- /src/main/java/me/nik/resourceworld/files/Config.java: -------------------------------------------------------------------------------- 1 | package me.nik.resourceworld.files; 2 | 3 | import me.nik.resourceworld.ResourceWorld; 4 | import me.nik.resourceworld.files.commentedfiles.CommentedFileConfiguration; 5 | 6 | import java.io.File; 7 | import java.util.Arrays; 8 | import java.util.List; 9 | import java.util.stream.Collectors; 10 | import java.util.stream.Stream; 11 | 12 | public class Config { 13 | 14 | private static final String[] HEADER = new String[]{ 15 | "+----------------------------------------------------------------------------------------------+", 16 | "| |", 17 | "| Resource World |", 18 | "| |", 19 | "| Discord: https://discord.gg/m7j2Y9H |", 20 | "| |", 21 | "| Author: Nik |", 22 | "| |", 23 | "+----------------------------------------------------------------------------------------------+" 24 | }; 25 | private static boolean exists; 26 | private final ResourceWorld plugin; 27 | private CommentedFileConfiguration configuration; 28 | 29 | public Config(ResourceWorld plugin) { 30 | this.plugin = plugin; 31 | } 32 | 33 | public void setup() { 34 | File configFile = new File(this.plugin.getDataFolder(), "config.yml"); 35 | 36 | exists = configFile.exists(); 37 | 38 | boolean setHeaderFooter = !exists; 39 | 40 | boolean changed = setHeaderFooter; 41 | 42 | this.configuration = CommentedFileConfiguration.loadConfiguration(this.plugin, configFile); 43 | 44 | if (setHeaderFooter) { 45 | this.configuration.addComments(HEADER); 46 | } 47 | 48 | for (Setting setting : Setting.values()) { 49 | setting.reset(); 50 | changed |= setting.setIfNotExists(this.configuration); 51 | } 52 | 53 | if (changed) { 54 | this.configuration.save(); 55 | } 56 | } 57 | 58 | public void reset() { 59 | for (Setting setting : Setting.values()) 60 | setting.reset(); 61 | } 62 | 63 | /** 64 | * @return the config.yml as a CommentedFileConfiguration 65 | */ 66 | public CommentedFileConfiguration getConfig() { 67 | return this.configuration; 68 | } 69 | 70 | public enum Setting { 71 | SETTINGS("settings", "", "General plugin settings"), 72 | SETTINGS_CHECK_FOR_UPDATES("settings.check_for_updates", true, "Should we check for updates on startup?"), 73 | SETTINGS_SPAWN_WORLD("settings.main_spawn_world", "world", "The world that the player will Teleport to once a Reset Happens"), 74 | SETTINGS_TELEPORT_TO_SPAWN("settings.teleport_to_spawn_on_quit", true, "If a player quits inside a resource world, Should we teleport him to spawn?"), 75 | SETTINGS_RESET_FORMAT("settings.reset_format", "%days% days %hours% hours %minutes% minutes %seconds% seconds", "Sets the format of the remaining time."), 76 | 77 | WORLD("world", "", "Overworld Settings"), 78 | WORLD_ENABLED("world.enabled", true, "Should we enable this?"), 79 | WORLD_NAME("world.world_name", "resource_world", "What should the Resource World be named?"), 80 | WORLD_GENERATE_STRUCTURES("world.generate_structures", true, "Should this world have structures? (Villages e.t.c)"), 81 | WORLD_TYPE("world.world_type", "NORMAL", "Available World Types: NORMAL , FLAT , LARGE_BIOMES , AMPLIFIED"), 82 | WORLD_ENVIRONMENT("world.environment", "NORMAL", "Available Environments: NORMAL , NETHER , THE_END"), 83 | WORLD_CUSTOM_SEED("world.custom_seed", "", "Seed Properties"), 84 | WORLD_SEED_ENABLED("world.custom_seed.enabled", false, "Should we use a custom seed?"), 85 | WORLD_SEED("world.custom_seed.seed", -686298914, "The seed to use"), 86 | WORLD_BORDER("world.world_border", "", "World Border Properties"), 87 | WORLD_BORDER_ENABLED("world.world_border.enabled", true, "Should we enable this?"), 88 | WORLD_BORDER_SIZE("world.world_border.size", 4500, "The border size (Note that if you set the World Border for example to 2000, It will be 1000 in one side and 1000 in the opposite one)"), 89 | WORLD_PVP("world.allow_pvp", true, "Should PvP be enabled?"), 90 | WORLD_ALWAYS_DAY("world.always_day", false, "Should it always be day in the Resource World?"), 91 | WORLD_DISABLE_SUFFOCATION("world.disable_suffocation_damage", true, "Should we disable suffocation damage?"), 92 | WORLD_DIFFICULTY("world.difficulty", "NORMAL", "Options: EASY , NORMAL , HARD , PEACEFUL"), 93 | WORLD_KEEP_INVENTORY("world.keep_inventory_on_death", false, "Should players keep their Inventory items if they die inside the Resource World?"), 94 | WORLD_RESETS("world.automated_resets", "", "World Reset Properties"), 95 | WORLD_RESETS_ENABLED("world.automated_resets.enabled", false, "Would you like the Resource World to Automatically Reset?"), 96 | WORLD_RESETS_INTERVAL("world.automated_resets.interval", 8, "The Interval between Resource World Resets. (In Hours)"), 97 | WORLD_STORE_TIME("world.automated_resets.store_time_on_shutdown", true, "Do you wan't the plugin to store the remaining reset time once the server shuts down? and use the remaining time once it starts up again?"), 98 | WORLD_COMMANDS("world.commands_after_reset", "", "Execute specific commands after the world generates"), 99 | WORLD_COMMANDS_ENABLED("world.commands_after_reset.enabled", true, "Should we enable this?"), 100 | WORLD_COMMANDS_COMMANDS("world.commands_after_reset.commands", Arrays.asList("title @p title {\\\"text\\\":\\\"The Resource World\\\",\\\"color\\\":\\\"green\\\"}", "title @p subtitle {\\\"text\\\":\\\"Has been Reset!\\\",\\\"color\\\":\\\"green\\\"}"), "Commands listed below will be executed upon reset"), 101 | WORLD_DISABLED_COMMANDS("world.disabled_commands", "", "Disabled Commands Settings"), 102 | WORLD_DISABLED_COMMANDS_ENABLED("world.disabled_commands.enabled", false, "Should we enable this?"), 103 | WORLD_DISABLED_COMMANDS_LIST("world.disabled_commands.commands", Arrays.asList("/sethome", "/claim", "/setwarp", "/tpahere"), "Commands listed below will be Disabled if they're executed inside this World"), 104 | 105 | NETHER("nether", "", "Nether Settings"), 106 | NETHER_ENABLED("nether.enabled", false, "Should we enable this?"), 107 | NETHER_NAME("nether.world_name", "resource_nether", "What should the Resource World be named?"), 108 | NETHER_GENERATE_STRUCTURES("nether.generate_structures", true, "Should this world have structures? (Villages e.t.c)"), 109 | NETHER_PORTALS("nether.portals", "", "Portal Properties"), 110 | NETHER_PORTALS_ENABLED("nether.portals.override", false, "Would you like to sync your portals with the Resource Worlds? For example if a player goes into a Nether Portal he'll get to the Nether Resource World instead of the default one"), 111 | NETHER_PORTALS_VANILLA_RATIO("nether.portals.vanilla_portal_ratio", true, "Makes Portal Location Behavior work simularly to the Vanilla one"), 112 | NETHER_PORTALS_PORTALWORLD("nether.portals.portal_world", "world", "The world where you wan't your players to be teleported to After they enter a Nether Portal inside the Nether."), 113 | NETHER_PORTALS_ONLY_RESOURCE("nether.portals.only_resource", true, "If false, When a player enters a nether portal from any world, He is going to be teleported to the Resource Nether. If true, He will only be able to get to the Resource Nether if he enters a portal from the Resource World"), 114 | NETHER_TYPE("nether.world_type", "NORMAL", "Available World Types: NORMAL , FLAT , LARGE_BIOMES , AMPLIFIED"), 115 | NETHER_ENVIRONMENT("nether.environment", "NETHER", "Available Environments: NORMAL , NETHER , THE_END"), 116 | NETHER_CUSTOM_SEED("nether.custom_seed", "", "Seed Properties"), 117 | NETHER_SEED_ENABLED("nether.custom_seed.enabled", false, "Should we use a custom seed?"), 118 | NETHER_SEED("nether.custom_seed.seed", -686298914, "The seed to use"), 119 | NETHER_BORDER("nether.world_border", "", "World Border Properties"), 120 | NETHER_BORDER_ENABLED("nether.world_border.enabled", true, "Should we enable this?"), 121 | NETHER_BORDER_SIZE("nether.world_border.size", 4500, "The border size (Note that if you set the World Border for example to 2000, It will be 1000 in one side and 1000 in the opposite one)"), 122 | NETHER_PVP("nether.allow_pvp", true, "Should PvP be enabled?"), 123 | NETHER_DISABLE_SUFFOCATION("nether.disable_suffocation_damage", true, "Should we disable suffocation damage?"), 124 | NETHER_DIFFICULTY("nether.difficulty", "NORMAL", "Options: EASY , NORMAL , HARD , PEACEFUL"), 125 | NETHER_KEEP_INVENTORY("nether.keep_inventory_on_death", false, "Should players keep their Inventory items if they die inside the Resource World?"), 126 | NETHER_RESETS("nether.automated_resets", "", "World Reset Properties"), 127 | NETHER_RESETS_ENABLED("nether.automated_resets.enabled", false, "Would you like the Resource World to Automatically Reset?"), 128 | NETHER_RESETS_INTERVAL("nether.automated_resets.interval", 4, "The Interval between Resource World Resets. (In Hours)"), 129 | NETHER_STORE_TIME("nether.automated_resets.store_time_on_shutdown", true, "Do you wan't the plugin to store the remaining reset time once the server shuts down? and use the remaining time once it starts up again?"), 130 | NETHER_COMMANDS("nether.commands_after_reset", "", "Execute specific commands after the world generates"), 131 | NETHER_COMMANDS_ENABLED("nether.commands_after_reset.enabled", true, "Should we enable this?"), 132 | NETHER_COMMANDS_COMMANDS("nether.commands_after_reset.commands", Arrays.asList("title @p title {\\\"text\\\":\\\"The Resource Nether\\\",\\\"color\\\":\\\"green\\\"}", "title @p subtitle {\\\"text\\\":\\\"Has been Reset!\\\",\\\"color\\\":\\\"green\\\"}"), "Commands listed below will be executed upon reset"), 133 | NETHER_DISABLED_COMMANDS("nether.disabled_commands", "", "Disabled Commands Settings"), 134 | NETHER_DISABLED_COMMANDS_ENABLED("nether.disabled_commands.enabled", false, "Should we enable this?"), 135 | NETHER_DISABLED_COMMANDS_LIST("nether.disabled_commands.commands", Arrays.asList("/sethome", "/claim", "/setwarp", "/tpahere"), "Commands listed below will be Disabled if they're executed inside this World"), 136 | 137 | END("end", "", "End Settings"), 138 | END_ENABLED("end.enabled", false, "Should we enable this?"), 139 | END_NAME("end.world_name", "resource_end", "What should the Resource World be named?"), 140 | END_GENERATE_STRUCTURES("end.generate_structures", true, "Should this world have structures? (Villages e.t.c)"), 141 | END_PORTALS("end.portals", "", "Portal Properties"), 142 | END_PORTALS_ENABLED("end.portals.override", false, "Would you like to sync your portals with the Resource Worlds? For example if a player goes into a Nether Portal he'll get to the Nether Resource World instead of the default one"), 143 | END_PORTALS_PORTALWORLD("end.portals.portal_world", "world", "The world where you wan't your players to be teleported to After they enter a End Portal inside the End."), 144 | END_PORTALS_ONLY_RESOURCE("end.portals.only_resource", true, "If false, When a player enters a end portal from any world, He is going to be teleported to the Resource End. If true, He will only be able to get to the Resource End if he enters a portal from the Resource World"), 145 | END_TYPE("end.world_type", "NORMAL", "Available World Types: NORMAL , FLAT , LARGE_BIOMES , AMPLIFIED"), 146 | END_ENVIRONMENT("end.environment", "THE_END", "Available Environments: NORMAL , NETHER , THE_END"), 147 | END_CUSTOM_SEED("end.custom_seed", "", "Seed Properties"), 148 | END_SEED_ENABLED("end.custom_seed.enabled", false, "Should we use a custom seed?"), 149 | END_SEED("end.custom_seed.seed", -686298914, "The seed to use"), 150 | END_BORDER("end.world_border", "", "World Border Properties"), 151 | END_BORDER_ENABLED("end.world_border.enabled", true, "Should we enable this?"), 152 | END_BORDER_SIZE("end.world_border.size", 4500, "The border size (Note that if you set the World Border for example to 2000, It will be 1000 in one side and 1000 in the opposite one)"), 153 | END_PVP("end.allow_pvp", true, "Should PvP be enabled?"), 154 | END_DISABLE_SUFFOCATION("end.disable_suffocation_damage", true, "Should we disable suffocation damage?"), 155 | END_DIFFICULTY("end.difficulty", "NORMAL", "Options: EASY , NORMAL , HARD , PEACEFUL"), 156 | END_KEEP_INVENTORY("end.keep_inventory_on_death", false, "Should players keep their Inventory items if they die inside the Resource World?"), 157 | END_RESETS("end.automated_resets", "", "World Reset Properties"), 158 | END_RESETS_ENABLED("end.automated_resets.enabled", false, "Would you like the Resource World to Automatically Reset?"), 159 | END_RESETS_INTERVAL("end.automated_resets.interval", 6, "The Interval between Resource World Resets. (In Hours)"), 160 | END_STORE_TIME("end.automated_resets.store_time_on_shutdown", true, "Do you wan't the plugin to store the remaining reset time once the server shuts down? and use the remaining time once it starts up again?"), 161 | END_COMMANDS("end.commands_after_reset", "", "Execute specific commands after the world generates"), 162 | END_COMMANDS_ENABLED("end.commands_after_reset.enabled", true, "Should we enable this?"), 163 | END_COMMANDS_COMMANDS("end.commands_after_reset.commands", Arrays.asList("title @p title {\\\"text\\\":\\\"The Resource End\\\",\\\"color\\\":\\\"green\\\"}", "title @p subtitle {\\\"text\\\":\\\"Has been Reset!\\\",\\\"color\\\":\\\"green\\\"}"), "Commands listed below will be executed upon reset"), 164 | END_DISABLED_COMMANDS("end.disabled_commands", "", "Disabled Commands Settings"), 165 | END_DISABLED_COMMANDS_ENABLED("end.disabled_commands.enabled", false, "Should we enable this?"), 166 | END_DISABLED_COMMANDS_LIST("end.disabled_commands.commands", Arrays.asList("/sethome", "/claim", "/setwarp", "/tpahere"), "Commands listed below will be Disabled if they're executed inside this World"), 167 | 168 | TELEPORT("teleport_settings", "", "Teleport Settings"), 169 | TELEPORT_PRICE("teleport_settings.price", 0, "The price needed for a player to Teleport to a Resource World (Requires Vault)"), 170 | TELEPORT_COOLDOWN("teleport_settings.cooldown", 30, "The cooldown between teleportations"), 171 | TELEPORT_DELAY("teleport_settings.delay", 3, "The delay between teleportations"), 172 | TELEPORT_WORLD_MAX_RANGE("teleport_settings.world_max_teleport_range", 800, "The maximum X, Z The player will be teleported in the Resource World", "DO NOT Set this value higher than your World Border"), 173 | TELEPORT_NETHER_MAX_RANGE("teleport_settings.nether_max_teleport_range", 800, "The maximum X, Z The player will be teleported in the Resource Nether", "DO NOT Set this value higher than your World Border"), 174 | TELEPORT_END_MAX_RANGE("teleport_settings.end_max_teleport_range", 800, "The maximum X, Z The player will be teleported in the Resource End", "DO NOT Set this value higher than your World Border"), 175 | TELEPORT_EFFECTS("teleport_settings.effects", "", "Effect Properties"), 176 | TELEPORT_EFFECTS_ENABLED("teleport_settings.effects.enabled", true, "Would you like the player to get an effect after teleporting?"), 177 | TELEPORT_EFFECT("teleport_settings.effects.effect", "ABSORPTION", "Available Effects: https://hub.spigotmc.org/javadocs/spigot/org/bukkit/potion/PotionEffectType.html"), 178 | TELEPORT_EFFECT_DURATION("teleport_settings.effects.duration", 5, "The duration of the Effect"), 179 | TELEPORT_EFFECT_AMPLIFIER("teleport_settings.effects.amplifier", 2, "The amplifier of the Effect"), 180 | TELEPORT_SOUNDS("teleport_settings.sounds", "", "Sound Properties"), 181 | TELEPORT_SOUND_ENABLED("teleport_settings.sounds.enabled", true, "Would you like it to play a sound after a player teleports?"), 182 | TELEPORT_SOUND("teleport_settings.sounds.sound", "ENTITY_ENDERMAN_TELEPORT", "You should pick a sound that exists on the Spigot API", "https://hub.spigotmc.org/javadocs/spigot/org/bukkit/Sound.html"); 183 | 184 | private final String key; 185 | private final Object defaultValue; 186 | private final String[] comments; 187 | private boolean excluded; 188 | private Object value = null; 189 | 190 | Setting(String key, Object defaultValue, String... comments) { 191 | this.key = key; 192 | this.defaultValue = defaultValue; 193 | this.comments = comments != null ? comments : new String[0]; 194 | } 195 | 196 | Setting(String key, Object defaultValue, boolean excluded, String... comments) { 197 | this.key = key; 198 | this.defaultValue = defaultValue; 199 | this.excluded = excluded; 200 | this.comments = comments != null ? comments : new String[0]; 201 | } 202 | 203 | /** 204 | * Gets the setting as a boolean 205 | * 206 | * @return The setting as a boolean 207 | */ 208 | public boolean getBoolean() { 209 | this.loadValue(); 210 | return (boolean) this.value; 211 | } 212 | 213 | public String getKey() { 214 | return this.key; 215 | } 216 | 217 | /** 218 | * @return the setting as an int 219 | */ 220 | public int getInt() { 221 | this.loadValue(); 222 | return (int) this.getNumber(); 223 | } 224 | 225 | /** 226 | * @return the setting as a long 227 | */ 228 | public long getLong() { 229 | this.loadValue(); 230 | return (long) this.getNumber(); 231 | } 232 | 233 | /** 234 | * @return the setting as a double 235 | */ 236 | public double getDouble() { 237 | this.loadValue(); 238 | return this.getNumber(); 239 | } 240 | 241 | /** 242 | * @return the setting as a float 243 | */ 244 | public float getFloat() { 245 | this.loadValue(); 246 | return (float) this.getNumber(); 247 | } 248 | 249 | /** 250 | * @return the setting as a String 251 | */ 252 | public String getString() { 253 | this.loadValue(); 254 | return String.valueOf(this.value); 255 | } 256 | 257 | private double getNumber() { 258 | if (this.value instanceof Integer) { 259 | return (int) this.value; 260 | } else if (this.value instanceof Short) { 261 | return (short) this.value; 262 | } else if (this.value instanceof Byte) { 263 | return (byte) this.value; 264 | } else if (this.value instanceof Float) { 265 | return (float) this.value; 266 | } else if (this.value instanceof Long) { 267 | return (long) this.value; 268 | } 269 | 270 | return (double) this.value; 271 | } 272 | 273 | /** 274 | * @return the setting as a string list 275 | */ 276 | @SuppressWarnings("unchecked") 277 | public List getStringList() { 278 | this.loadValue(); 279 | return (List) this.value; 280 | } 281 | 282 | private boolean setIfNotExists(CommentedFileConfiguration fileConfiguration) { 283 | this.loadValue(); 284 | 285 | if (exists && this.excluded) return false; 286 | 287 | if (fileConfiguration.get(this.key) == null) { 288 | List comments = Stream.of(this.comments).collect(Collectors.toList()); 289 | if (this.defaultValue != null) { 290 | fileConfiguration.set(this.key, this.defaultValue, comments.toArray(new String[0])); 291 | } else { 292 | fileConfiguration.addComments(comments.toArray(new String[0])); 293 | } 294 | 295 | return true; 296 | } 297 | 298 | return false; 299 | } 300 | 301 | /** 302 | * Resets the cached value 303 | */ 304 | public void reset() { 305 | this.value = null; 306 | } 307 | 308 | /** 309 | * @return true if this setting is only a section and doesn't contain an actual value 310 | */ 311 | public boolean isSection() { 312 | return this.defaultValue == null; 313 | } 314 | 315 | /** 316 | * Loads the value from the config and caches it if it isn't set yet 317 | */ 318 | private void loadValue() { 319 | if (this.value != null) return; 320 | this.value = ResourceWorld.getInstance().getConfiguration().get(this.key); 321 | } 322 | } 323 | } -------------------------------------------------------------------------------- /src/main/java/me/nik/resourceworld/files/Data.java: -------------------------------------------------------------------------------- 1 | package me.nik.resourceworld.files; 2 | 3 | import org.bukkit.configuration.file.FileConfiguration; 4 | import org.bukkit.configuration.file.YamlConfiguration; 5 | import org.bukkit.plugin.java.JavaPlugin; 6 | 7 | import java.io.File; 8 | import java.io.IOException; 9 | 10 | public class Data { 11 | private File file; 12 | private FileConfiguration data; 13 | 14 | public void setup(JavaPlugin plugin) { 15 | file = new File(plugin.getDataFolder(), "data.yml"); 16 | if (!file.exists()) { 17 | try { 18 | file.createNewFile(); 19 | } catch (IOException ignored) { 20 | } 21 | } 22 | data = YamlConfiguration.loadConfiguration(file); 23 | } 24 | 25 | public FileConfiguration get() { 26 | return data; 27 | } 28 | 29 | public void save() { 30 | try { 31 | data.save(file); 32 | } catch (IOException ignored) { 33 | } 34 | } 35 | 36 | public void reload() { 37 | data = YamlConfiguration.loadConfiguration(file); 38 | } 39 | 40 | public void addDefaults() { 41 | get().options().header("+----------------------------------------------------------------------------------------------+" + "\n" + "| |" + "\n" + "| Resource World |" + "\n" + "| |" + "\n" + "| Discord: https://discord.gg/m7j2Y9H |" + "\n" + "| |" + "\n" + "| Author: Nik |" + "\n" + "| |" + "\n" + "+----------------------------------------------------------------------------------------------+" + "\n"); 42 | get().addDefault("world.timer", 0); 43 | get().addDefault("world.millis", 0); 44 | get().addDefault("world.papi", 0); 45 | get().addDefault("nether.timer", 0); 46 | get().addDefault("nether.millis", 0); 47 | get().addDefault("nether.papi", 0); 48 | get().addDefault("end.timer", 0); 49 | get().addDefault("end.millis", 0); 50 | get().addDefault("end.papi", 0); 51 | } 52 | } -------------------------------------------------------------------------------- /src/main/java/me/nik/resourceworld/files/Lang.java: -------------------------------------------------------------------------------- 1 | package me.nik.resourceworld.files; 2 | 3 | import org.bukkit.configuration.file.FileConfiguration; 4 | import org.bukkit.configuration.file.YamlConfiguration; 5 | import org.bukkit.plugin.java.JavaPlugin; 6 | 7 | import java.io.File; 8 | import java.io.IOException; 9 | 10 | public class Lang { 11 | private File file; 12 | private FileConfiguration lang; 13 | 14 | public void setup(JavaPlugin plugin) { 15 | file = new File(plugin.getDataFolder(), "lang.yml"); 16 | if (!file.exists()) { 17 | try { 18 | file.createNewFile(); 19 | } catch (IOException ignored) { 20 | } 21 | } 22 | lang = YamlConfiguration.loadConfiguration(file); 23 | } 24 | 25 | public FileConfiguration get() { 26 | return lang; 27 | } 28 | 29 | public void save() { 30 | try { 31 | lang.save(file); 32 | } catch (IOException ignored) { 33 | } 34 | } 35 | 36 | public void reload() { 37 | lang = YamlConfiguration.loadConfiguration(file); 38 | } 39 | 40 | public void addDefaults() { 41 | get().options().header("+----------------------------------------------------------------------------------------------+" + "\n" + "| |" + "\n" + "| Resource World |" + "\n" + "| |" + "\n" + "| Discord: https://discord.gg/m7j2Y9H |" + "\n" + "| |" + "\n" + "| Author: Nik |" + "\n" + "| |" + "\n" + "+----------------------------------------------------------------------------------------------+" + "\n"); 42 | get().addDefault("prefix", "&a&l[&2Resource World&a&l]&f&l: "); 43 | get().addDefault("update_found", "&aThere is an Update available, Your version &f%current%&a new version &f%new%"); 44 | get().addDefault("disabled_command", "&cSorry, You can't use that Command in this World!"); 45 | get().addDefault("resetting_the_world", "&fCleaning up the Resource World, This may cause Lag!"); 46 | get().addDefault("resetting_the_nether", "&fCleaning up the Nether World, This may cause Lag!"); 47 | get().addDefault("resetting_the_end", "&fCleaning up the End World, This may cause Lag!"); 48 | get().addDefault("world_has_been_reset", "&fThe Resource World has been Reset!"); 49 | get().addDefault("nether_has_been_reset", "&fThe Nether World has been Reset!"); 50 | get().addDefault("end_has_been_reset", "&fThe End World has been Reset!"); 51 | get().addDefault("console_message", "&f&lThis command cannot be executed through the Console :("); 52 | get().addDefault("no_perm", "&cYou do not have permission to execute this command!"); 53 | get().addDefault("cooldown_message", "&cYou can teleport to the Resource World again in %seconds% seconds."); 54 | get().addDefault("cooldown_spawn", "&cYou can teleport to spawn again in %seconds% seconds."); 55 | get().addDefault("reloaded", "&fYou have successfully reloaded the plugin!"); 56 | get().addDefault("teleport_delay", "&aTeleporting to the Resource World in %seconds% seconds."); 57 | get().addDefault("gui_name", "&2&lResource World Menu"); 58 | get().addDefault("worlds_gui_name", "&2&lReset A Resource World"); 59 | get().addDefault("teleported_message", "&fYou have been Teleported back to spawn!"); 60 | get().addDefault("not_exist", "&cThe Resource World is currently under Maintenance, Please try again later!"); 61 | get().addDefault("teleport_paid", "&a%price% &fHave been taken from your balance."); 62 | get().addDefault("teleport_error", "&cYou do not have enough money to Teleport to the Resource World."); 63 | get().addDefault("teleported_players", "&aTeleported all the players back to spawn!"); 64 | get().addDefault("update_not_found", "&f&lYou're running the Latest Version &c&l<3"); 65 | } 66 | } -------------------------------------------------------------------------------- /src/main/java/me/nik/resourceworld/files/commentedfiles/CommentedConfigurationSection.java: -------------------------------------------------------------------------------- 1 | package me.nik.resourceworld.files.commentedfiles; 2 | 3 | import org.bukkit.Color; 4 | import org.bukkit.Location; 5 | import org.bukkit.OfflinePlayer; 6 | import org.bukkit.configuration.Configuration; 7 | import org.bukkit.configuration.ConfigurationSection; 8 | import org.bukkit.configuration.serialization.ConfigurationSerializable; 9 | import org.bukkit.inventory.ItemStack; 10 | import org.bukkit.util.Vector; 11 | import org.jetbrains.annotations.NotNull; 12 | import org.jetbrains.annotations.Nullable; 13 | 14 | import java.util.List; 15 | import java.util.Map; 16 | import java.util.Set; 17 | 18 | public class CommentedConfigurationSection implements ConfigurationSection { 19 | 20 | protected ConfigurationSection config; 21 | 22 | public CommentedConfigurationSection(ConfigurationSection configuration) { 23 | this.config = configuration; 24 | } 25 | 26 | /** 27 | * Gets a defaulted boolean value. These accept values of either "default", true, or false 28 | * 29 | * @param path The value key 30 | * @return null for "default", otherwise true or false 31 | */ 32 | public Boolean getDefaultedBoolean(String path) { 33 | if (this.isBoolean(path)) { 34 | return this.getBoolean(path); 35 | } else if (this.isString(path)) { 36 | String stringValue = this.getString(path); 37 | if (stringValue != null && stringValue.equalsIgnoreCase("default")) 38 | return null; 39 | } 40 | 41 | return null; 42 | } 43 | 44 | /** 45 | * Gets a defaulted boolean value. These accept values of either "default", true, or false 46 | * 47 | * @param path The value key 48 | * @param def The value to return if the key is not found 49 | * @return null for "default", otherwise true or false 50 | */ 51 | public Boolean getDefaultedBoolean(String path, Boolean def) { 52 | Object value = this.get(path); 53 | if (value instanceof Boolean) { 54 | return (Boolean) value; 55 | } else if (value instanceof String) { 56 | String stringValue = (String) value; 57 | if (stringValue.equalsIgnoreCase("default")) 58 | return null; 59 | } 60 | 61 | if (value == null) 62 | return def; 63 | 64 | return null; 65 | } 66 | 67 | @Override 68 | public Set getKeys(boolean b) { 69 | return this.config.getKeys(b); 70 | } 71 | 72 | @Override 73 | public Map getValues(boolean b) { 74 | return this.config.getValues(b); 75 | } 76 | 77 | @Override 78 | public boolean contains(String s) { 79 | return this.config.contains(s); 80 | } 81 | 82 | @Override 83 | public boolean contains(String s, boolean b) { 84 | return this.config.contains(s, b); 85 | } 86 | 87 | @Override 88 | public boolean isSet(String s) { 89 | return this.config.isSet(s); 90 | } 91 | 92 | @Override 93 | public String getCurrentPath() { 94 | return this.config.getCurrentPath(); 95 | } 96 | 97 | @Override 98 | public String getName() { 99 | return this.config.getName(); 100 | } 101 | 102 | @Override 103 | public Configuration getRoot() { 104 | return this.config.getRoot(); 105 | } 106 | 107 | @Override 108 | public ConfigurationSection getParent() { 109 | return this.config.getParent(); 110 | } 111 | 112 | @Override 113 | public Object get(String s) { 114 | return this.config.get(s); 115 | } 116 | 117 | @Override 118 | public Object get(String s, Object o) { 119 | return this.config.get(s, o); 120 | } 121 | 122 | @Override 123 | public void set(String s, Object o) { 124 | this.config.set(s, o); 125 | } 126 | 127 | @Override 128 | public CommentedConfigurationSection createSection(String s) { 129 | return new CommentedConfigurationSection(this.config.createSection(s)); 130 | } 131 | 132 | @Override 133 | public CommentedConfigurationSection createSection(String s, Map map) { 134 | return new CommentedConfigurationSection(this.config.createSection(s, map)); 135 | } 136 | 137 | @Override 138 | public String getString(String s) { 139 | return this.config.getString(s); 140 | } 141 | 142 | @Override 143 | public String getString(String s, String s1) { 144 | return this.config.getString(s, s1); 145 | } 146 | 147 | @Override 148 | public boolean isString(String s) { 149 | return this.config.isString(s); 150 | } 151 | 152 | @Override 153 | public int getInt(String s) { 154 | return this.config.getInt(s); 155 | } 156 | 157 | @Override 158 | public int getInt(String s, int i) { 159 | return this.config.getInt(s, i); 160 | } 161 | 162 | @Override 163 | public boolean isInt(String s) { 164 | return this.config.isInt(s); 165 | } 166 | 167 | @Override 168 | public boolean getBoolean(String s) { 169 | return this.config.getBoolean(s); 170 | } 171 | 172 | @Override 173 | public boolean getBoolean(String s, boolean b) { 174 | return this.config.getBoolean(s, b); 175 | } 176 | 177 | @Override 178 | public boolean isBoolean(String s) { 179 | return this.config.isBoolean(s); 180 | } 181 | 182 | @Override 183 | public double getDouble(String s) { 184 | return this.config.getDouble(s); 185 | } 186 | 187 | @Override 188 | public double getDouble(String s, double v) { 189 | return this.config.getDouble(s, v); 190 | } 191 | 192 | @Override 193 | public boolean isDouble(String s) { 194 | return this.config.isDouble(s); 195 | } 196 | 197 | @Override 198 | public long getLong(String s) { 199 | return this.config.getLong(s); 200 | } 201 | 202 | @Override 203 | public long getLong(String s, long l) { 204 | return this.config.getLong(s, l); 205 | } 206 | 207 | @Override 208 | public boolean isLong(String s) { 209 | return this.config.isLong(s); 210 | } 211 | 212 | @Override 213 | public List getList(String s) { 214 | return this.config.getList(s); 215 | } 216 | 217 | @Override 218 | public List getList(String s, List list) { 219 | return this.config.getList(s, list); 220 | } 221 | 222 | @Override 223 | public boolean isList(String s) { 224 | return this.config.isList(s); 225 | } 226 | 227 | @Override 228 | public List getStringList(String s) { 229 | return this.config.getStringList(s); 230 | } 231 | 232 | @Override 233 | public List getIntegerList(String s) { 234 | return this.config.getIntegerList(s); 235 | } 236 | 237 | @Override 238 | public List getBooleanList(String s) { 239 | return this.config.getBooleanList(s); 240 | } 241 | 242 | @Override 243 | public List getDoubleList(String s) { 244 | return this.config.getDoubleList(s); 245 | } 246 | 247 | @Override 248 | public List getFloatList(String s) { 249 | return this.config.getFloatList(s); 250 | } 251 | 252 | @Override 253 | public List getLongList(String s) { 254 | return this.config.getLongList(s); 255 | } 256 | 257 | @Override 258 | public List getByteList(String s) { 259 | return this.config.getByteList(s); 260 | } 261 | 262 | @Override 263 | public List getCharacterList(String s) { 264 | return this.config.getCharacterList(s); 265 | } 266 | 267 | @Override 268 | public List getShortList(String s) { 269 | return this.config.getShortList(s); 270 | } 271 | 272 | @Override 273 | public List> getMapList(String s) { 274 | return this.config.getMapList(s); 275 | } 276 | 277 | @Override 278 | public T getObject(String s, Class aClass) { 279 | return this.config.getObject(s, aClass); 280 | } 281 | 282 | @Override 283 | public T getObject(String s, Class aClass, T t) { 284 | return this.config.getObject(s, aClass, t); 285 | } 286 | 287 | @Override 288 | public T getSerializable(String s, Class aClass) { 289 | return this.config.getSerializable(s, aClass); 290 | } 291 | 292 | @Override 293 | public T getSerializable(String s, Class aClass, T t) { 294 | return this.config.getSerializable(s, aClass, t); 295 | } 296 | 297 | @Override 298 | public Vector getVector(String s) { 299 | return this.config.getVector(s); 300 | } 301 | 302 | @Override 303 | public Vector getVector(String s, Vector vector) { 304 | return this.config.getVector(s, vector); 305 | } 306 | 307 | @Override 308 | public boolean isVector(String s) { 309 | return this.config.isVector(s); 310 | } 311 | 312 | @Override 313 | public OfflinePlayer getOfflinePlayer(String s) { 314 | return this.config.getOfflinePlayer(s); 315 | } 316 | 317 | @Override 318 | public OfflinePlayer getOfflinePlayer(String s, OfflinePlayer offlinePlayer) { 319 | return this.config.getOfflinePlayer(s, offlinePlayer); 320 | } 321 | 322 | @Override 323 | public boolean isOfflinePlayer(String s) { 324 | return this.config.isOfflinePlayer(s); 325 | } 326 | 327 | @Override 328 | public ItemStack getItemStack(String s) { 329 | return this.config.getItemStack(s); 330 | } 331 | 332 | @Override 333 | public ItemStack getItemStack(String s, ItemStack itemStack) { 334 | return this.config.getItemStack(s, itemStack); 335 | } 336 | 337 | @Override 338 | public boolean isItemStack(String s) { 339 | return this.config.isItemStack(s); 340 | } 341 | 342 | @Override 343 | public Color getColor(String s) { 344 | return this.config.getColor(s); 345 | } 346 | 347 | @Override 348 | public Color getColor(String s, Color color) { 349 | return this.config.getColor(s, color); 350 | } 351 | 352 | @Override 353 | public boolean isColor(String s) { 354 | return this.config.isColor(s); 355 | } 356 | 357 | @Override 358 | public Location getLocation(String path) { 359 | return this.getSerializable(path, Location.class); 360 | } 361 | 362 | @Override 363 | public Location getLocation(String path, Location def) { 364 | return this.getSerializable(path, Location.class, def); 365 | } 366 | 367 | @Override 368 | public boolean isLocation(String path) { 369 | return this.getSerializable(path, Location.class) != null; 370 | } 371 | 372 | @Override 373 | public CommentedConfigurationSection getConfigurationSection(String s) { 374 | ConfigurationSection section = this.config.getConfigurationSection(s); 375 | if (section == null) 376 | return this.createSection(s); 377 | 378 | return new CommentedConfigurationSection(section); 379 | } 380 | 381 | @Override 382 | public boolean isConfigurationSection(String s) { 383 | return this.config.isConfigurationSection(s); 384 | } 385 | 386 | @Override 387 | public CommentedConfigurationSection getDefaultSection() { 388 | return new CommentedConfigurationSection(this.config.getDefaultSection()); 389 | } 390 | 391 | @Override 392 | public void addDefault(String s, Object o) { 393 | this.config.addDefault(s, o); 394 | } 395 | 396 | @NotNull 397 | @Override 398 | public List getComments(@NotNull String path) { 399 | return null; 400 | } 401 | 402 | @NotNull 403 | @Override 404 | public List getInlineComments(@NotNull String path) { 405 | return null; 406 | } 407 | 408 | @Override 409 | public void setComments(@NotNull String path, @Nullable List comments) { 410 | } 411 | 412 | @Override 413 | public void setInlineComments(@NotNull String path, @Nullable List comments) { 414 | } 415 | } -------------------------------------------------------------------------------- /src/main/java/me/nik/resourceworld/files/commentedfiles/CommentedFileConfiguration.java: -------------------------------------------------------------------------------- 1 | package me.nik.resourceworld.files.commentedfiles; 2 | 3 | import org.bukkit.configuration.file.YamlConfiguration; 4 | import org.bukkit.plugin.java.JavaPlugin; 5 | import org.yaml.snakeyaml.DumperOptions; 6 | 7 | import java.io.File; 8 | import java.io.Reader; 9 | import java.lang.reflect.Field; 10 | import java.util.stream.Stream; 11 | 12 | public class CommentedFileConfiguration extends CommentedConfigurationSection { 13 | 14 | private final CommentedFileConfigurationHelper helper; 15 | private final File file; 16 | private int comments; 17 | 18 | public CommentedFileConfiguration(Reader configStream, File configFile, int comments, JavaPlugin plugin) { 19 | super(YamlConfiguration.loadConfiguration(configStream)); 20 | this.comments = comments; 21 | this.helper = new CommentedFileConfigurationHelper(plugin); 22 | this.file = configFile; 23 | } 24 | 25 | public static CommentedFileConfiguration loadConfiguration(JavaPlugin plugin, File file) { 26 | return new CommentedFileConfigurationHelper(plugin).getNewConfig(file); 27 | } 28 | 29 | public void set(String path, Object value, String... comments) { 30 | if (!this.contains(path)) { 31 | int subpathIndex = path.lastIndexOf('.'); 32 | String subpath = subpathIndex == -1 ? "" : path.substring(0, subpathIndex) + '.'; 33 | 34 | for (String comment : comments) { 35 | this.set(subpath + this.helper.getPluginName() + "_COMMENT_" + this.comments, " " + comment); 36 | this.comments++; 37 | } 38 | } 39 | 40 | this.set(path, value); 41 | } 42 | 43 | public void addComments(String... comments) { 44 | for (String comment : comments) { 45 | this.set(this.helper.getPluginName() + "_COMMENT_" + this.comments, " " + comment); 46 | this.comments++; 47 | } 48 | } 49 | 50 | public void reloadConfig() { 51 | this.config = YamlConfiguration.loadConfiguration(this.helper.getConfigContent(this.file)); 52 | } 53 | 54 | public void save() { 55 | this.save(false); 56 | } 57 | 58 | public void save(boolean compactLines) { 59 | String config = this.getConfigAsString(); 60 | this.helper.saveConfig(config, this.file, compactLines); 61 | } 62 | 63 | public void save(File file) { 64 | this.save(file, false); 65 | } 66 | 67 | public void save(File file, boolean compactLines) { 68 | String config = this.getConfigAsString(); 69 | this.helper.saveConfig(config, file, compactLines); 70 | } 71 | 72 | private String getConfigAsString() { 73 | if (!(this.config instanceof YamlConfiguration)) 74 | throw new UnsupportedOperationException("Cannot get config string of non-YamlConfiguration"); 75 | 76 | YamlConfiguration yamlConfiguration = (YamlConfiguration) this.config; 77 | 78 | // Edit the configuration to how we want it 79 | try { 80 | Field field_yamlOptions; 81 | try { 82 | field_yamlOptions = YamlConfiguration.class.getDeclaredField("yamlOptions"); 83 | } catch (NoSuchFieldException e) { // This is used for 1.18.1+ 84 | field_yamlOptions = YamlConfiguration.class.getDeclaredField("yamlDumperOptions"); 85 | } 86 | 87 | field_yamlOptions.setAccessible(true); 88 | DumperOptions yamlOptions = (DumperOptions) field_yamlOptions.get(yamlConfiguration); 89 | yamlOptions.setWidth(Integer.MAX_VALUE); 90 | 91 | if (Stream.of(DumperOptions.class.getDeclaredMethods()).anyMatch(x -> x.getName().equals("setIndicatorIndent"))) 92 | yamlOptions.setIndicatorIndent(2); 93 | 94 | if (Stream.of(DumperOptions.class.getDeclaredMethods()).anyMatch(x -> x.getName().equals("setProcessComments"))) 95 | yamlOptions.setProcessComments(false); 96 | 97 | if (Stream.of(DumperOptions.class.getDeclaredMethods()).anyMatch(x -> x.getName().equals("setSplitLines"))) 98 | yamlOptions.setSplitLines(false); 99 | } catch (ReflectiveOperationException e) { 100 | e.printStackTrace(); 101 | } 102 | 103 | return yamlConfiguration.saveToString(); 104 | } 105 | 106 | } -------------------------------------------------------------------------------- /src/main/java/me/nik/resourceworld/files/commentedfiles/CommentedFileConfigurationHelper.java: -------------------------------------------------------------------------------- 1 | package me.nik.resourceworld.files.commentedfiles; 2 | 3 | import org.bukkit.plugin.java.JavaPlugin; 4 | 5 | import java.io.BufferedReader; 6 | import java.io.BufferedWriter; 7 | import java.io.ByteArrayInputStream; 8 | import java.io.File; 9 | import java.io.IOException; 10 | import java.io.InputStreamReader; 11 | import java.io.Reader; 12 | import java.io.StringReader; 13 | import java.nio.charset.StandardCharsets; 14 | import java.nio.file.Files; 15 | import java.nio.file.Paths; 16 | import java.util.Scanner; 17 | import java.util.regex.Matcher; 18 | import java.util.regex.Pattern; 19 | 20 | public class CommentedFileConfigurationHelper { 21 | 22 | private final JavaPlugin plugin; 23 | 24 | /** 25 | * Manage custom configurations and files 26 | * 27 | * @param plugin The JavaPlugin the configuration is for 28 | */ 29 | public CommentedFileConfigurationHelper(JavaPlugin plugin) { 30 | this.plugin = plugin; 31 | } 32 | 33 | /** 34 | * Get new configuration 35 | * 36 | * @param file - Path to file 37 | * @return - New SimpleConfig 38 | */ 39 | public CommentedFileConfiguration getNewConfig(File file) { 40 | if (!this.plugin.getDataFolder().exists()) 41 | this.plugin.getDataFolder().mkdir(); 42 | 43 | if (!file.exists()) { 44 | try { 45 | file.createNewFile(); 46 | } catch (IOException e) { 47 | e.printStackTrace(); 48 | } 49 | } 50 | 51 | return new CommentedFileConfiguration(this.getConfigContent(file), file, this.getCommentsNum(file), this.plugin); 52 | } 53 | 54 | /** 55 | * Read file and make comments SnakeYAML friendly 56 | * 57 | * @param file - Path to file 58 | * @return - File as Input Stream 59 | */ 60 | public Reader getConfigContent(File file) { 61 | if (!file.exists()) 62 | return new InputStreamReader(new ByteArrayInputStream(new byte[0])); 63 | 64 | try { 65 | int commentNum = 0; 66 | 67 | String pluginName = this.getPluginName(); 68 | 69 | StringBuilder whole = new StringBuilder(); 70 | BufferedReader reader = Files.newBufferedReader(Paths.get(file.getAbsolutePath()), StandardCharsets.UTF_8); 71 | 72 | String currentLine; 73 | while ((currentLine = reader.readLine()) != null) { 74 | // Convert comments into keys 75 | if (currentLine.trim().startsWith("#")) { 76 | String addLine = currentLine.replaceAll(Pattern.quote("'"), Matcher.quoteReplacement("''")) 77 | .replaceFirst("#", pluginName + "_COMMENT_" + commentNum++ + ": '") + "'"; 78 | whole.append(addLine).append("\n"); 79 | } else { 80 | whole.append(currentLine).append("\n"); 81 | } 82 | } 83 | 84 | String config = whole.toString(); 85 | Reader configStream = new StringReader(config); 86 | 87 | reader.close(); 88 | return configStream; 89 | } catch (IOException e) { 90 | e.printStackTrace(); 91 | return null; 92 | } 93 | } 94 | 95 | /** 96 | * Get comments from file 97 | * 98 | * @param file - File 99 | * @return - Comments number 100 | */ 101 | private int getCommentsNum(File file) { 102 | if (!file.exists()) 103 | return 0; 104 | 105 | try { 106 | int comments = 0; 107 | String currentLine; 108 | 109 | BufferedReader reader = Files.newBufferedReader(Paths.get(file.getAbsolutePath()), StandardCharsets.UTF_8); 110 | 111 | while ((currentLine = reader.readLine()) != null) 112 | if (currentLine.trim().startsWith("#")) 113 | comments++; 114 | 115 | reader.close(); 116 | return comments; 117 | } catch (IOException e) { 118 | e.printStackTrace(); 119 | return 0; 120 | } 121 | } 122 | 123 | private String prepareConfigString(String configString) { 124 | boolean lastLine = false; 125 | 126 | String[] lines = configString.split("\n"); 127 | StringBuilder config = new StringBuilder(); 128 | 129 | for (String line : lines) { 130 | if (line.trim().startsWith(this.getPluginName() + "_COMMENT")) { 131 | int whitespaceIndex = line.indexOf(line.trim()); 132 | String comment = line.substring(0, whitespaceIndex) + "#" + line.substring(line.indexOf(":") + 3, line.length() - 1); 133 | 134 | String normalComment; 135 | if (comment.trim().startsWith("#'")) { 136 | normalComment = comment.substring(0, comment.length() - 1).replaceFirst("#'", "# "); 137 | } else { 138 | normalComment = comment; 139 | } 140 | 141 | normalComment = normalComment.replaceAll("''", "'"); 142 | 143 | if (!lastLine) { 144 | config.append(normalComment).append("\n"); 145 | } else { 146 | config.append("\n").append(normalComment).append("\n"); 147 | } 148 | 149 | lastLine = false; 150 | } else { 151 | config.append(line).append("\n"); 152 | lastLine = true; 153 | } 154 | } 155 | 156 | return config.toString(); 157 | } 158 | 159 | /** 160 | * Saves configuration to file 161 | * 162 | * @param configString - Config string 163 | * @param file - Config file 164 | * @param compactLines - If lines should forcefully be separated by only one newline character 165 | */ 166 | public void saveConfig(String configString, File file, boolean compactLines) { 167 | String configuration = this.prepareConfigString(configString).replaceAll("\n\n", "\n"); 168 | 169 | // Apply post-processing to config string to make it pretty 170 | StringBuilder stringBuilder = new StringBuilder(); 171 | try (Scanner scanner = new Scanner(configuration)) { 172 | boolean lastLineHadContent = false; 173 | int lastCommentSpacing = -1; 174 | int lastLineSpacing = -1; 175 | boolean forceCompact = false; 176 | 177 | while (scanner.hasNextLine()) { 178 | String line = scanner.nextLine(); 179 | 180 | boolean lineHadContent = false; 181 | boolean lineWasComment = false; 182 | int commentSpacing = -1; 183 | int lineSpacing = line.indexOf(line.trim()); 184 | 185 | if (line.trim().startsWith("#")) { 186 | lineWasComment = true; 187 | String trimmed = line.trim().replaceFirst("#", ""); 188 | commentSpacing = trimmed.indexOf(trimmed.trim()); 189 | } else if (!line.trim().isEmpty()) { 190 | lineHadContent = true; 191 | 192 | if (line.trim().startsWith("-")) 193 | forceCompact = true; 194 | } 195 | 196 | if (!compactLines && !forceCompact && ( 197 | (lastLineSpacing != -1 && lineSpacing != lastLineSpacing) 198 | || (commentSpacing != -1 && commentSpacing < lastCommentSpacing) 199 | || (lastLineHadContent && lineHadContent) 200 | || (lineWasComment && lastLineHadContent)) 201 | && !(lastLineHadContent && !lineWasComment)) { 202 | stringBuilder.append('\n'); 203 | } 204 | 205 | stringBuilder.append(line).append('\n'); 206 | 207 | lastLineHadContent = lineHadContent; 208 | lastCommentSpacing = commentSpacing; 209 | lastLineSpacing = lineSpacing; 210 | forceCompact = false; 211 | } 212 | } 213 | 214 | try (BufferedWriter writer = Files.newBufferedWriter(Paths.get(file.getAbsolutePath()), StandardCharsets.UTF_8)) { 215 | writer.write(stringBuilder.toString()); 216 | writer.flush(); 217 | } catch (IOException e) { 218 | e.printStackTrace(); 219 | } 220 | } 221 | 222 | public String getPluginName() { 223 | return this.plugin.getDescription().getName(); 224 | } 225 | 226 | } -------------------------------------------------------------------------------- /src/main/java/me/nik/resourceworld/gui/GuiListener.java: -------------------------------------------------------------------------------- 1 | package me.nik.resourceworld.gui; 2 | 3 | import org.bukkit.Material; 4 | import org.bukkit.event.EventHandler; 5 | import org.bukkit.event.Listener; 6 | import org.bukkit.event.inventory.InventoryClickEvent; 7 | import org.bukkit.inventory.InventoryHolder; 8 | import org.bukkit.inventory.ItemStack; 9 | 10 | public class GuiListener implements Listener { 11 | 12 | @EventHandler 13 | public void onClick(InventoryClickEvent e) { 14 | 15 | InventoryHolder holder = e.getInventory().getHolder(); 16 | 17 | ItemStack item = e.getCurrentItem(); 18 | 19 | if (!(holder instanceof Menu) || item == null || item.getType() == Material.AIR) return; 20 | 21 | e.setCancelled(true); 22 | 23 | Menu menu = (Menu) holder; 24 | menu.handleMenu(e); 25 | } 26 | } -------------------------------------------------------------------------------- /src/main/java/me/nik/resourceworld/gui/Menu.java: -------------------------------------------------------------------------------- 1 | package me.nik.resourceworld.gui; 2 | 3 | import me.nik.resourceworld.ResourceWorld; 4 | import me.nik.resourceworld.utils.ChatUtils; 5 | import org.bukkit.Bukkit; 6 | import org.bukkit.Material; 7 | import org.bukkit.event.inventory.InventoryClickEvent; 8 | import org.bukkit.inventory.Inventory; 9 | import org.bukkit.inventory.InventoryHolder; 10 | import org.bukkit.inventory.ItemStack; 11 | import org.bukkit.inventory.meta.ItemMeta; 12 | 13 | import java.util.ArrayList; 14 | import java.util.List; 15 | 16 | public abstract class Menu implements InventoryHolder { 17 | 18 | protected final ResourceWorld plugin; 19 | 20 | protected Inventory inventory; 21 | 22 | protected PlayerMenu playerMenu; 23 | 24 | public Menu(PlayerMenu playerMenu, ResourceWorld plugin) { 25 | this.playerMenu = playerMenu; 26 | this.plugin = plugin; 27 | } 28 | 29 | protected abstract String getMenuName(); 30 | 31 | protected abstract int getSlots(); 32 | 33 | public abstract void handleMenu(InventoryClickEvent e); 34 | 35 | protected abstract void setMenuItems(); 36 | 37 | public void open() { 38 | inventory = Bukkit.createInventory(this, getSlots(), getMenuName()); 39 | 40 | this.setMenuItems(); 41 | 42 | playerMenu.getOwner().openInventory(inventory); 43 | } 44 | 45 | protected ItemStack makeItem(Material material, int amount, String displayName, List lore) { 46 | 47 | ItemStack item = new ItemStack(material, amount); 48 | ItemMeta itemMeta = item.getItemMeta(); 49 | itemMeta.setDisplayName(ChatUtils.format(displayName)); 50 | if (lore != null) { 51 | List loreList = new ArrayList<>(); 52 | for (String l : lore) { 53 | loreList.add(ChatUtils.format(l)); 54 | } 55 | itemMeta.setLore(loreList); 56 | } 57 | item.setItemMeta(itemMeta); 58 | 59 | return item; 60 | } 61 | 62 | @Override 63 | public Inventory getInventory() { 64 | return inventory; 65 | } 66 | } -------------------------------------------------------------------------------- /src/main/java/me/nik/resourceworld/gui/PlayerMenu.java: -------------------------------------------------------------------------------- 1 | package me.nik.resourceworld.gui; 2 | 3 | import org.bukkit.entity.Player; 4 | 5 | public class PlayerMenu { 6 | 7 | private Player owner; 8 | 9 | public PlayerMenu(Player owner) { 10 | this.owner = owner; 11 | } 12 | 13 | public Player getOwner() { 14 | return owner; 15 | } 16 | 17 | public void setOwner(Player owner) { 18 | this.owner = owner; 19 | } 20 | } -------------------------------------------------------------------------------- /src/main/java/me/nik/resourceworld/gui/menus/MainGui.java: -------------------------------------------------------------------------------- 1 | package me.nik.resourceworld.gui.menus; 2 | 3 | import me.nik.resourceworld.ResourceWorld; 4 | import me.nik.resourceworld.files.Config; 5 | import me.nik.resourceworld.gui.Menu; 6 | import me.nik.resourceworld.gui.PlayerMenu; 7 | import me.nik.resourceworld.managers.MsgType; 8 | import me.nik.resourceworld.managers.custom.CustomWorld; 9 | import org.bukkit.Bukkit; 10 | import org.bukkit.ChatColor; 11 | import org.bukkit.Material; 12 | import org.bukkit.entity.Player; 13 | import org.bukkit.event.inventory.InventoryClickEvent; 14 | import org.bukkit.inventory.ItemStack; 15 | 16 | import java.util.ArrayList; 17 | import java.util.List; 18 | import java.util.stream.Collectors; 19 | 20 | public class MainGui extends Menu { 21 | public MainGui(PlayerMenu playerMenu, ResourceWorld plugin) { 22 | super(playerMenu, plugin); 23 | } 24 | 25 | @Override 26 | protected String getMenuName() { 27 | return MsgType.GUI_NAME.getMessage(); 28 | } 29 | 30 | @Override 31 | protected int getSlots() { 32 | return 54; 33 | } 34 | 35 | @Override 36 | public void handleMenu(InventoryClickEvent e) { 37 | Player p = (Player) e.getWhoClicked(); 38 | switch (e.getSlot()) { 39 | case 13: 40 | 41 | List worlds = this.plugin.getResourceWorlds().values().stream().map(CustomWorld::getName).collect(Collectors.toList()); 42 | 43 | Bukkit.getOnlinePlayers() 44 | .stream() 45 | .filter(player -> worlds.stream().anyMatch(world -> player.getWorld().getName().equals(world))) 46 | .forEach(player -> { 47 | player.teleport(Bukkit.getWorld(Config.Setting.SETTINGS_SPAWN_WORLD.getString()).getSpawnLocation()); 48 | player.sendMessage(MsgType.TELEPORTED_MESSAGE.getMessage()); 49 | }); 50 | 51 | p.sendMessage(MsgType.TELEPORTED_PLAYERS.getMessage()); 52 | break; 53 | case 15: 54 | p.closeInventory(); 55 | plugin.onDisable(); 56 | plugin.onEnable(); 57 | p.sendMessage(MsgType.RELOADED.getMessage()); 58 | break; 59 | case 30: 60 | p.closeInventory(); 61 | p.sendMessage(ChatColor.BLUE + ">> " + ChatColor.WHITE + "https://github.com/NikV2/ResourceWorld/issues/new/choose" + ChatColor.BLUE + " <<"); 62 | break; 63 | case 49: 64 | p.closeInventory(); 65 | break; 66 | case 32: 67 | p.closeInventory(); 68 | new WorldsGui(playerMenu, plugin).open(); 69 | break; 70 | } 71 | } 72 | 73 | @Override 74 | protected void setMenuItems() { 75 | ArrayList teleportLore = new ArrayList<>(); 76 | teleportLore.add(""); 77 | teleportLore.add("&7Teleport all the"); 78 | teleportLore.add("&7Players that are in"); 79 | teleportLore.add("&7The Resource Worlds"); 80 | teleportLore.add("&7Back to spawn."); 81 | ItemStack teleport = makeItem(Material.ENDER_PEARL, 1, "&aTeleport All", teleportLore); 82 | 83 | ArrayList reloadLore = new ArrayList<>(); 84 | reloadLore.add(" "); 85 | reloadLore.add("&7WARNING!"); 86 | reloadLore.add(" "); 87 | reloadLore.add("&7Reloading may cause issues."); 88 | ItemStack reload = makeItem(Material.REDSTONE, 1, "&aReload", reloadLore); 89 | 90 | ItemStack support = makeItem(Material.DIAMOND, 1, "&aLooking for Support?", null); 91 | ItemStack exit = makeItem(Material.BARRIER, 1, "&cExit", null); 92 | 93 | ArrayList resetLore = new ArrayList<>(); 94 | resetLore.add(""); 95 | resetLore.add("&7Would you like to reset"); 96 | resetLore.add("&7The Resource World?"); 97 | ItemStack reset = makeItem(Material.EMERALD, 1, "&aReset", resetLore); 98 | 99 | inventory.setItem(13, teleport); 100 | inventory.setItem(15, reload); 101 | inventory.setItem(30, support); 102 | inventory.setItem(32, reset); 103 | inventory.setItem(49, exit); 104 | } 105 | } -------------------------------------------------------------------------------- /src/main/java/me/nik/resourceworld/gui/menus/WorldsGui.java: -------------------------------------------------------------------------------- 1 | package me.nik.resourceworld.gui.menus; 2 | 3 | import me.nik.resourceworld.ResourceWorld; 4 | import me.nik.resourceworld.api.ResourceWorldType; 5 | import me.nik.resourceworld.gui.Menu; 6 | import me.nik.resourceworld.gui.PlayerMenu; 7 | import me.nik.resourceworld.managers.MsgType; 8 | import org.bukkit.Material; 9 | import org.bukkit.entity.Player; 10 | import org.bukkit.event.inventory.InventoryClickEvent; 11 | import org.bukkit.inventory.ItemStack; 12 | 13 | public class WorldsGui extends Menu { 14 | public WorldsGui(PlayerMenu playerMenu, ResourceWorld plugin) { 15 | super(playerMenu, plugin); 16 | } 17 | 18 | @Override 19 | protected String getMenuName() { 20 | return MsgType.WORLDS_GUI_NAME.getMessage(); 21 | } 22 | 23 | @Override 24 | protected int getSlots() { 25 | return 36; 26 | } 27 | 28 | @Override 29 | public void handleMenu(InventoryClickEvent e) { 30 | Player p = (Player) e.getWhoClicked(); 31 | switch (e.getSlot()) { 32 | case 13: 33 | this.plugin.getResourceWorld(ResourceWorldType.RESOURCE_WORLD).reset(); 34 | p.closeInventory(); 35 | break; 36 | case 11: 37 | this.plugin.getResourceWorld(ResourceWorldType.RESOURCE_NETHER).reset(); 38 | p.closeInventory(); 39 | break; 40 | case 15: 41 | this.plugin.getResourceWorld(ResourceWorldType.RESOURCE_END).reset(); 42 | p.closeInventory(); 43 | break; 44 | case 31: 45 | p.closeInventory(); 46 | new MainGui(playerMenu, plugin).open(); 47 | break; 48 | } 49 | } 50 | 51 | @Override 52 | protected void setMenuItems() { 53 | ItemStack resource = makeItem(Material.DIRT, 1, "&aResource World", null); 54 | ItemStack nether = makeItem(Material.NETHERRACK, 1, "&cNether World", null); 55 | ItemStack end = makeItem(Material.OBSIDIAN, 1, "&9End World", null); 56 | ItemStack back = makeItem(Material.BARRIER, 1, "&cBack", null); 57 | 58 | inventory.setItem(11, nether); 59 | inventory.setItem(13, resource); 60 | inventory.setItem(15, end); 61 | inventory.setItem(31, back); 62 | } 63 | } -------------------------------------------------------------------------------- /src/main/java/me/nik/resourceworld/managers/MsgType.java: -------------------------------------------------------------------------------- 1 | package me.nik.resourceworld.managers; 2 | 3 | import me.nik.resourceworld.ResourceWorld; 4 | import me.nik.resourceworld.utils.ChatUtils; 5 | 6 | public enum MsgType { 7 | PREFIX(ChatUtils.format(ResourceWorld.getInstance().getLang().getString("prefix"))), 8 | UPDATE_FOUND(PREFIX.getMessage() + ChatUtils.format(ResourceWorld.getInstance().getLang().getString("update_found"))), 9 | DISABLED_COMMAND(PREFIX.getMessage() + ChatUtils.format(ResourceWorld.getInstance().getLang().getString("disabled_command"))), 10 | RESETTING_THE_WORLD(PREFIX.getMessage() + ChatUtils.format(ResourceWorld.getInstance().getLang().getString("resetting_the_world"))), 11 | RESETTING_THE_NETHER(PREFIX.getMessage() + ChatUtils.format(ResourceWorld.getInstance().getLang().getString("resetting_the_nether"))), 12 | RESETTING_THE_END(PREFIX.getMessage() + ChatUtils.format(ResourceWorld.getInstance().getLang().getString("resetting_the_end"))), 13 | WORLD_HAS_BEEN_RESET(PREFIX.getMessage() + ChatUtils.format(ResourceWorld.getInstance().getLang().getString("world_has_been_reset"))), 14 | NETHER_HAS_BEEN_RESET(PREFIX.getMessage() + ChatUtils.format(ResourceWorld.getInstance().getLang().getString("nether_has_been_reset"))), 15 | END_HAS_BEEN_RESET(PREFIX.getMessage() + ChatUtils.format(ResourceWorld.getInstance().getLang().getString("end_has_been_reset"))), 16 | CONSOLE_MESSAGE(PREFIX.getMessage() + ChatUtils.format(ResourceWorld.getInstance().getLang().getString("console_message"))), 17 | NO_PERMISSION(PREFIX.getMessage() + ChatUtils.format(ResourceWorld.getInstance().getLang().getString("no_perm"))), 18 | COOLDOWN_MESSAGE(PREFIX.getMessage() + ChatUtils.format(ResourceWorld.getInstance().getLang().getString("cooldown_message"))), 19 | RELOADED(PREFIX.getMessage() + ChatUtils.format(ResourceWorld.getInstance().getLang().getString("reloaded"))), 20 | TELEPORT_DELAY(PREFIX.getMessage() + ChatUtils.format(ResourceWorld.getInstance().getLang().getString("teleport_delay"))), 21 | GUI_NAME(ChatUtils.format(ResourceWorld.getInstance().getLang().getString("gui_name"))), 22 | WORLDS_GUI_NAME(ChatUtils.format(ResourceWorld.getInstance().getLang().getString("worlds_gui_name"))), 23 | TELEPORTED_MESSAGE(PREFIX.getMessage() + ChatUtils.format(ResourceWorld.getInstance().getLang().getString("teleported_message"))), 24 | NOT_EXIST(PREFIX.getMessage() + ChatUtils.format(ResourceWorld.getInstance().getLang().getString("not_exist"))), 25 | TELEPORT_PAID(PREFIX.getMessage() + ChatUtils.format(ResourceWorld.getInstance().getLang().getString("teleport_paid"))), 26 | TELEPORT_ERROR(PREFIX.getMessage() + ChatUtils.format(ResourceWorld.getInstance().getLang().getString("teleport_error"))), 27 | TELEPORTED_PLAYERS(PREFIX.getMessage() + ChatUtils.format(ResourceWorld.getInstance().getLang().getString("teleported_players"))), 28 | UPDATE_NOT_FOUND(PREFIX.getMessage() + ChatUtils.format(ResourceWorld.getInstance().getLang().getString("update_not_found"))); 29 | 30 | private final String message; 31 | 32 | MsgType(String message) { 33 | this.message = message; 34 | } 35 | 36 | public String getMessage() { 37 | return message; 38 | } 39 | } -------------------------------------------------------------------------------- /src/main/java/me/nik/resourceworld/managers/PapiHook.java: -------------------------------------------------------------------------------- 1 | package me.nik.resourceworld.managers; 2 | 3 | import me.clip.placeholderapi.expansion.PlaceholderExpansion; 4 | import me.nik.resourceworld.ResourceWorld; 5 | import me.nik.resourceworld.files.Config; 6 | import me.nik.resourceworld.utils.MiscUtils; 7 | import org.bukkit.OfflinePlayer; 8 | 9 | public class PapiHook extends PlaceholderExpansion { 10 | 11 | private final ResourceWorld plugin; 12 | 13 | public PapiHook(ResourceWorld plugin) { 14 | this.plugin = plugin; 15 | } 16 | 17 | @Override 18 | public String getIdentifier() { 19 | return "rw"; 20 | } 21 | 22 | @Override 23 | public String getAuthor() { 24 | return plugin.getDescription().getAuthors().toString(); 25 | } 26 | 27 | @Override 28 | public String getVersion() { 29 | return plugin.getDescription().getVersion(); 30 | } 31 | 32 | @Override 33 | public boolean canRegister() { 34 | return true; 35 | } 36 | 37 | @Override 38 | public boolean persist() { 39 | return true; 40 | } 41 | 42 | @Override 43 | public String onRequest(OfflinePlayer player, String identifier) { 44 | 45 | switch (identifier) { 46 | case "world": 47 | if (!Config.Setting.WORLD_ENABLED.getBoolean() && !Config.Setting.WORLD_RESETS_ENABLED.getBoolean()) 48 | return ""; 49 | if (Config.Setting.WORLD_STORE_TIME.getBoolean()) { 50 | return MiscUtils.getDurationBreakdown((Config.Setting.WORLD_RESETS_INTERVAL.getInt() * 3600000L + plugin.getData().getLong("world.millis")) - System.currentTimeMillis()); 51 | } else { 52 | return MiscUtils.getDurationBreakdown((Config.Setting.WORLD_RESETS_INTERVAL.getInt() * 3600000L + plugin.getData().getLong("world.papi")) - System.currentTimeMillis()); 53 | } 54 | case "nether": 55 | if (!Config.Setting.NETHER_ENABLED.getBoolean() && !Config.Setting.NETHER_RESETS_ENABLED.getBoolean()) 56 | return ""; 57 | if (Config.Setting.NETHER_STORE_TIME.getBoolean()) { 58 | return MiscUtils.getDurationBreakdown((Config.Setting.NETHER_RESETS_INTERVAL.getInt() * 3600000L + plugin.getData().getLong("nether.millis")) - System.currentTimeMillis()); 59 | } else { 60 | return MiscUtils.getDurationBreakdown((Config.Setting.NETHER_RESETS_INTERVAL.getInt() * 3600000L + plugin.getData().getLong("nether.papi")) - System.currentTimeMillis()); 61 | } 62 | case "end": 63 | if (!Config.Setting.END_ENABLED.getBoolean() && !Config.Setting.END_RESETS_ENABLED.getBoolean()) 64 | return ""; 65 | if (Config.Setting.END_STORE_TIME.getBoolean()) { 66 | return MiscUtils.getDurationBreakdown((Config.Setting.END_RESETS_INTERVAL.getInt() * 3600000L + plugin.getData().getLong("end.millis")) - System.currentTimeMillis()); 67 | } else { 68 | return MiscUtils.getDurationBreakdown((Config.Setting.END_RESETS_INTERVAL.getInt() * 3600000L + plugin.getData().getLong("end.papi")) - System.currentTimeMillis()); 69 | } 70 | } 71 | return null; 72 | } 73 | } -------------------------------------------------------------------------------- /src/main/java/me/nik/resourceworld/managers/Permissions.java: -------------------------------------------------------------------------------- 1 | package me.nik.resourceworld.managers; 2 | 3 | public enum Permissions { 4 | ADMIN("rw.admin"), 5 | TELEPORT("rw.tp"), 6 | TELEPORT_NETHER("rw.tp.nether"), 7 | TELEPORT_END("rw.tp.end"); 8 | 9 | private final String permission; 10 | 11 | Permissions(String permission) { 12 | this.permission = permission; 13 | } 14 | 15 | public String getPermission() { 16 | return this.permission; 17 | } 18 | } -------------------------------------------------------------------------------- /src/main/java/me/nik/resourceworld/managers/UpdateChecker.java: -------------------------------------------------------------------------------- 1 | package me.nik.resourceworld.managers; 2 | 3 | import me.nik.resourceworld.ResourceWorld; 4 | import me.nik.resourceworld.utils.ChatUtils; 5 | import org.bukkit.Bukkit; 6 | import org.bukkit.entity.Player; 7 | import org.bukkit.event.EventHandler; 8 | import org.bukkit.event.EventPriority; 9 | import org.bukkit.event.Listener; 10 | import org.bukkit.event.player.PlayerJoinEvent; 11 | import org.bukkit.scheduler.BukkitRunnable; 12 | 13 | import java.io.BufferedReader; 14 | import java.io.IOException; 15 | import java.io.InputStreamReader; 16 | import java.net.URL; 17 | import java.net.URLConnection; 18 | 19 | public class UpdateChecker extends BukkitRunnable implements Listener { 20 | 21 | private final ResourceWorld plugin; 22 | private String newVersion; 23 | 24 | public UpdateChecker(ResourceWorld plugin) { 25 | this.plugin = plugin; 26 | } 27 | 28 | @Override 29 | public void run() { 30 | 31 | try { 32 | 33 | URLConnection connection = new URL("https://raw.githubusercontent.com/NikV2/ResourceWorld/master/version.txt").openConnection(); 34 | 35 | connection.addRequestProperty("User-Agent", "Mozilla/4.0"); 36 | 37 | BufferedReader reader = new BufferedReader(new InputStreamReader(connection.getInputStream())); 38 | 39 | this.newVersion = reader.readLine(); 40 | 41 | reader.close(); 42 | 43 | } catch (IOException e) { 44 | ChatUtils.consoleMessage("Couldn't check for updates, Is the server connected to the internet?"); 45 | return; 46 | } 47 | 48 | if (!this.plugin.getDescription().getVersion().equals(this.newVersion)) { 49 | 50 | Bukkit.getServer().getConsoleSender().sendMessage( 51 | MsgType.UPDATE_FOUND.getMessage() 52 | .replace("%current%", this.plugin.getDescription().getVersion()) 53 | .replace("%new%", this.newVersion) 54 | ); 55 | 56 | Bukkit.getPluginManager().registerEvents(this, this.plugin); 57 | 58 | } else Bukkit.getServer().getConsoleSender().sendMessage(MsgType.UPDATE_NOT_FOUND.getMessage()); 59 | } 60 | 61 | @EventHandler(priority = EventPriority.MONITOR, ignoreCancelled = true) 62 | public void onJoin(PlayerJoinEvent e) { 63 | 64 | Player player = e.getPlayer(); 65 | 66 | if (player.hasPermission(Permissions.ADMIN.getPermission())) { 67 | 68 | player.sendMessage(MsgType.UPDATE_FOUND.getMessage() 69 | .replace("%current%", this.plugin.getDescription().getVersion()) 70 | .replace("%new%", this.newVersion)); 71 | } 72 | } 73 | } -------------------------------------------------------------------------------- /src/main/java/me/nik/resourceworld/managers/custom/CustomWorld.java: -------------------------------------------------------------------------------- 1 | package me.nik.resourceworld.managers.custom; 2 | 3 | import me.nik.resourceworld.ResourceWorld; 4 | import me.nik.resourceworld.api.ResourceWorldType; 5 | import me.nik.resourceworld.files.Config; 6 | import me.nik.resourceworld.managers.MsgType; 7 | import me.nik.resourceworld.utils.ChatUtils; 8 | import me.nik.resourceworld.utils.MiscUtils; 9 | import me.nik.resourceworld.utils.TaskUtils; 10 | import org.bukkit.Bukkit; 11 | import org.bukkit.Difficulty; 12 | import org.bukkit.GameRule; 13 | import org.bukkit.World; 14 | import org.bukkit.WorldBorder; 15 | import org.bukkit.WorldCreator; 16 | import org.bukkit.WorldType; 17 | import org.bukkit.event.EventHandler; 18 | import org.bukkit.event.EventPriority; 19 | import org.bukkit.event.HandlerList; 20 | import org.bukkit.event.Listener; 21 | import org.bukkit.event.player.PlayerTeleportEvent; 22 | 23 | public class CustomWorld implements Listener { 24 | 25 | private final ResourceWorldType resourceWorldType; 26 | private final String name; 27 | private final Difficulty difficulty; 28 | private final WorldType type; 29 | private final World.Environment environment; 30 | private final boolean structures; 31 | private final boolean useSeed; 32 | private final long seed; 33 | private final boolean useBorder; 34 | private final int borderSize; 35 | private final boolean pvp; 36 | private final boolean keepInventory; 37 | 38 | public CustomWorld(String name, Difficulty difficulty, WorldType type, World.Environment environment, boolean structures, boolean useSeed, long seed, boolean useBorder, int borderSize, boolean pvp, boolean keepInventory, ResourceWorldType resourceWorldType) { 39 | this.name = name; 40 | this.difficulty = difficulty; 41 | this.type = type; 42 | this.environment = environment; 43 | this.structures = structures; 44 | this.useSeed = useSeed; 45 | this.seed = seed; 46 | this.useBorder = useBorder; 47 | this.borderSize = borderSize; 48 | this.pvp = pvp; 49 | this.keepInventory = keepInventory; 50 | this.resourceWorldType = resourceWorldType; 51 | } 52 | 53 | public String getName() { 54 | return name; 55 | } 56 | 57 | public CustomWorld generate() { 58 | 59 | WorldCreator wc = new WorldCreator(this.name); 60 | 61 | wc.type(this.type); 62 | 63 | wc.generateStructures(this.structures); 64 | 65 | wc.environment(this.environment); 66 | 67 | if (this.useSeed) wc.seed(this.seed); 68 | 69 | wc.createWorld(); 70 | 71 | World rw = Bukkit.getWorld(this.name); 72 | 73 | if (this.useBorder) { 74 | 75 | WorldBorder wb = rw.getWorldBorder(); 76 | 77 | wb.setCenter(0, 0); 78 | 79 | wb.setSize(this.borderSize); 80 | 81 | } 82 | 83 | rw.setPVP(this.pvp); 84 | 85 | rw.setDifficulty(this.difficulty); 86 | 87 | Bukkit.getWorlds().add(rw); 88 | 89 | if (!MiscUtils.isLegacy() && this.keepInventory) rw.setGameRule(GameRule.KEEP_INVENTORY, true); 90 | 91 | return this; 92 | } 93 | 94 | public void reset() { 95 | 96 | ChatUtils.consoleMessage("Executing world reset..."); 97 | 98 | //Phase 1 99 | 100 | World world = Bukkit.getWorld(this.name); 101 | 102 | if (world == null) return; 103 | 104 | Bukkit.getOnlinePlayers().stream().filter(player -> player.getWorld().getUID().equals(world.getUID())).forEach(player -> { 105 | 106 | player.teleport(Bukkit.getWorld(Config.Setting.SETTINGS_SPAWN_WORLD.getString()).getSpawnLocation()); 107 | 108 | player.sendMessage(MsgType.TELEPORTED_MESSAGE.getMessage()); 109 | }); 110 | 111 | ResourceWorld plugin = ResourceWorld.getInstance(); 112 | 113 | Bukkit.getPluginManager().registerEvents(this, plugin); 114 | 115 | ChatUtils.consoleMessage("Phase 1 completed..."); 116 | 117 | //Phase 2 118 | TaskUtils.taskLater(() -> { 119 | 120 | switch (this.resourceWorldType) { 121 | 122 | case RESOURCE_END: 123 | 124 | Bukkit.broadcastMessage(MsgType.RESETTING_THE_END.getMessage()); 125 | 126 | if (Config.Setting.END_STORE_TIME.getBoolean()) { 127 | plugin.getData().set("end.millis", System.currentTimeMillis()); 128 | } 129 | 130 | plugin.getData().set("end.papi", System.currentTimeMillis()); 131 | 132 | break; 133 | 134 | case RESOURCE_WORLD: 135 | 136 | Bukkit.broadcastMessage(MsgType.RESETTING_THE_WORLD.getMessage()); 137 | 138 | if (Config.Setting.WORLD_STORE_TIME.getBoolean()) { 139 | plugin.getData().set("world.millis", System.currentTimeMillis()); 140 | } 141 | 142 | plugin.getData().set("world.papi", System.currentTimeMillis()); 143 | 144 | break; 145 | 146 | case RESOURCE_NETHER: 147 | 148 | Bukkit.broadcastMessage(MsgType.RESETTING_THE_NETHER.getMessage()); 149 | 150 | if (Config.Setting.NETHER_STORE_TIME.getBoolean()) { 151 | plugin.getData().set("nether.millis", System.currentTimeMillis()); 152 | } 153 | 154 | plugin.getData().set("nether.papi", System.currentTimeMillis()); 155 | 156 | break; 157 | } 158 | 159 | plugin.saveData(); 160 | plugin.reloadData(); 161 | plugin.saveData(); 162 | 163 | Bukkit.unloadWorld(world, false); 164 | 165 | MiscUtils.deleteDirectory(world.getWorldFolder()); 166 | 167 | ChatUtils.consoleMessage("Phase 2 completed..."); 168 | 169 | //Phase 3 170 | TaskUtils.taskLater(() -> { 171 | 172 | generate(); 173 | 174 | ChatUtils.consoleMessage("Phase 3 completed..."); 175 | 176 | //Phase 4 177 | TaskUtils.taskLater(() -> { 178 | 179 | switch (this.resourceWorldType) { 180 | 181 | case RESOURCE_END: 182 | 183 | if (Config.Setting.END_COMMANDS_ENABLED.getBoolean()) { 184 | 185 | for (String cmd : Config.Setting.END_COMMANDS_COMMANDS.getStringList()) { 186 | 187 | Bukkit.dispatchCommand(Bukkit.getConsoleSender(), cmd); 188 | } 189 | } 190 | 191 | Bukkit.broadcastMessage(MsgType.END_HAS_BEEN_RESET.getMessage()); 192 | 193 | break; 194 | 195 | case RESOURCE_WORLD: 196 | if (Config.Setting.WORLD_COMMANDS_ENABLED.getBoolean()) { 197 | for (String cmd : Config.Setting.WORLD_COMMANDS_COMMANDS.getStringList()) { 198 | Bukkit.dispatchCommand(Bukkit.getConsoleSender(), cmd); 199 | } 200 | } 201 | 202 | Bukkit.broadcastMessage(MsgType.WORLD_HAS_BEEN_RESET.getMessage()); 203 | 204 | break; 205 | case RESOURCE_NETHER: 206 | 207 | if (Config.Setting.NETHER_COMMANDS_ENABLED.getBoolean()) { 208 | 209 | for (String cmd : Config.Setting.NETHER_COMMANDS_COMMANDS.getStringList()) { 210 | Bukkit.dispatchCommand(Bukkit.getConsoleSender(), cmd); 211 | } 212 | } 213 | 214 | Bukkit.broadcastMessage(MsgType.NETHER_HAS_BEEN_RESET.getMessage()); 215 | 216 | break; 217 | } 218 | 219 | HandlerList.unregisterAll(this); 220 | 221 | ChatUtils.consoleMessage("All phases completed!"); 222 | 223 | }, 160L); 224 | 225 | }, 80L); 226 | 227 | }, 80L); 228 | } 229 | 230 | @EventHandler(priority = EventPriority.LOWEST) 231 | public void onWorldTeleport(PlayerTeleportEvent e) { 232 | if (e.getTo().getWorld().getName().equals(this.name)) e.setCancelled(true); 233 | } 234 | } -------------------------------------------------------------------------------- /src/main/java/me/nik/resourceworld/managers/custom/ResourceWorldException.java: -------------------------------------------------------------------------------- 1 | package me.nik.resourceworld.managers.custom; 2 | 3 | public class ResourceWorldException extends RuntimeException { 4 | public ResourceWorldException(String message) { 5 | super(message); 6 | } 7 | } -------------------------------------------------------------------------------- /src/main/java/me/nik/resourceworld/metrics/MetricsLite.java: -------------------------------------------------------------------------------- 1 | package me.nik.resourceworld.metrics; 2 | 3 | import com.google.gson.JsonArray; 4 | import com.google.gson.JsonObject; 5 | import com.google.gson.JsonParser; 6 | import org.bukkit.Bukkit; 7 | import org.bukkit.configuration.file.YamlConfiguration; 8 | import org.bukkit.entity.Player; 9 | import org.bukkit.plugin.Plugin; 10 | import org.bukkit.plugin.RegisteredServiceProvider; 11 | import org.bukkit.plugin.ServicePriority; 12 | 13 | import javax.net.ssl.HttpsURLConnection; 14 | import java.io.BufferedReader; 15 | import java.io.ByteArrayOutputStream; 16 | import java.io.DataOutputStream; 17 | import java.io.File; 18 | import java.io.IOException; 19 | import java.io.InputStreamReader; 20 | import java.lang.reflect.InvocationTargetException; 21 | import java.lang.reflect.Method; 22 | import java.net.URL; 23 | import java.nio.charset.StandardCharsets; 24 | import java.util.Collection; 25 | import java.util.Timer; 26 | import java.util.TimerTask; 27 | import java.util.UUID; 28 | import java.util.logging.Level; 29 | import java.util.zip.GZIPOutputStream; 30 | 31 | /** 32 | * bStats collects some data for plugin authors. 33 | *

34 | * Check out https://bStats.org/ to learn more about bStats! 35 | */ 36 | @SuppressWarnings({"WeakerAccess", "unused"}) 37 | public class MetricsLite { 38 | 39 | // The version of this bStats class 40 | public static final int B_STATS_VERSION = 1; 41 | // The url to which the data is sent 42 | private static final String URL = "https://bStats.org/submitData/bukkit"; 43 | // Should failed requests be logged? 44 | private static boolean logFailedRequests; 45 | // Should the sent data be logged? 46 | private static boolean logSentData; 47 | // Should the response text be logged? 48 | private static boolean logResponseStatusText; 49 | // The uuid of the server 50 | private static String serverUUID; 51 | 52 | static { 53 | // You can use the property to disable the check in your test environment 54 | if (System.getProperty("bstats.relocatecheck") == null || !System.getProperty("bstats.relocatecheck").equals("false")) { 55 | // Maven's Relocate is clever and changes strings, too. So we have to use this little "trick" ... :D 56 | final String defaultPackage = new String( 57 | new byte[]{'o', 'r', 'g', '.', 'b', 's', 't', 'a', 't', 's', '.', 'b', 'u', 'k', 'k', 'i', 't'}); 58 | final String examplePackage = new String(new byte[]{'y', 'o', 'u', 'r', '.', 'p', 'a', 'c', 'k', 'a', 'g', 'e'}); 59 | // We want to make sure nobody just copy & pastes the example and use the wrong package names 60 | if (MetricsLite.class.getPackage().getName().equals(defaultPackage) || MetricsLite.class.getPackage().getName().equals(examplePackage)) { 61 | throw new IllegalStateException("bStats Metrics class has not been relocated correctly!"); 62 | } 63 | } 64 | } 65 | 66 | // Is bStats enabled on this server? 67 | private final boolean enabled; 68 | // The plugin 69 | private final Plugin plugin; 70 | 71 | // The plugin id 72 | private final int pluginId; 73 | 74 | /** 75 | * Class constructor. 76 | * 77 | * @param plugin The plugin which stats should be submitted. 78 | * @param pluginId The id of the plugin. 79 | * It can be found at What is my plugin id? 80 | */ 81 | public MetricsLite(Plugin plugin, int pluginId) { 82 | if (plugin == null) { 83 | throw new IllegalArgumentException("Plugin cannot be null!"); 84 | } 85 | this.plugin = plugin; 86 | this.pluginId = pluginId; 87 | 88 | // Get the config file 89 | File bStatsFolder = new File(plugin.getDataFolder().getParentFile(), "bStats"); 90 | File configFile = new File(bStatsFolder, "config.yml"); 91 | YamlConfiguration config = YamlConfiguration.loadConfiguration(configFile); 92 | 93 | // Check if the config file exists 94 | if (!config.isSet("serverUuid")) { 95 | 96 | // Add default values 97 | config.addDefault("enabled", true); 98 | // Every server gets it's unique random id. 99 | config.addDefault("serverUuid", UUID.randomUUID().toString()); 100 | // Should failed request be logged? 101 | config.addDefault("logFailedRequests", false); 102 | // Should the sent data be logged? 103 | config.addDefault("logSentData", false); 104 | // Should the response text be logged? 105 | config.addDefault("logResponseStatusText", false); 106 | 107 | // Inform the server owners about bStats 108 | config.options().header( 109 | "bStats collects some data for plugin authors like how many servers are using their plugins.\n" + 110 | "To honor their work, you should not disable it.\n" + 111 | "This has nearly no effect on the server performance!\n" + 112 | "Check out https://bStats.org/ to learn more :)" 113 | ).copyDefaults(true); 114 | try { 115 | config.save(configFile); 116 | } catch (IOException ignored) { 117 | } 118 | } 119 | 120 | // Load the data 121 | serverUUID = config.getString("serverUuid"); 122 | logFailedRequests = config.getBoolean("logFailedRequests", false); 123 | enabled = config.getBoolean("enabled", true); 124 | logSentData = config.getBoolean("logSentData", false); 125 | logResponseStatusText = config.getBoolean("logResponseStatusText", false); 126 | if (enabled) { 127 | boolean found = false; 128 | // Search for all other bStats Metrics classes to see if we are the first one 129 | for (Class service : Bukkit.getServicesManager().getKnownServices()) { 130 | try { 131 | service.getField("B_STATS_VERSION"); // Our identifier :) 132 | found = true; // We aren't the first 133 | break; 134 | } catch (NoSuchFieldException ignored) { 135 | } 136 | } 137 | // Register our service 138 | Bukkit.getServicesManager().register(MetricsLite.class, this, plugin, ServicePriority.Normal); 139 | if (!found) { 140 | // We are the first! 141 | startSubmitting(); 142 | } 143 | } 144 | } 145 | 146 | /** 147 | * Sends the data to the bStats server. 148 | * 149 | * @param plugin Any plugin. It's just used to get a logger instance. 150 | * @param data The data to send. 151 | * @throws Exception If the request failed. 152 | */ 153 | private static void sendData(Plugin plugin, JsonObject data) throws Exception { 154 | if (data == null) { 155 | throw new IllegalArgumentException("Data cannot be null!"); 156 | } 157 | if (Bukkit.isPrimaryThread()) { 158 | throw new IllegalAccessException("This method must not be called from the main thread!"); 159 | } 160 | if (logSentData) { 161 | plugin.getLogger().info("Sending data to bStats: " + data); 162 | } 163 | HttpsURLConnection connection = (HttpsURLConnection) new URL(URL).openConnection(); 164 | 165 | // Compress the data to save bandwidth 166 | byte[] compressedData = compress(data.toString()); 167 | 168 | // Add headers 169 | connection.setRequestMethod("POST"); 170 | connection.addRequestProperty("Accept", "application/json"); 171 | connection.addRequestProperty("Connection", "close"); 172 | connection.addRequestProperty("Content-Encoding", "gzip"); // We gzip our request 173 | connection.addRequestProperty("Content-Length", String.valueOf(compressedData.length)); 174 | connection.setRequestProperty("Content-Type", "application/json"); // We send our data in JSON format 175 | connection.setRequestProperty("User-Agent", "MC-Server/" + B_STATS_VERSION); 176 | 177 | // Send data 178 | connection.setDoOutput(true); 179 | try (DataOutputStream outputStream = new DataOutputStream(connection.getOutputStream())) { 180 | outputStream.write(compressedData); 181 | } 182 | 183 | StringBuilder builder = new StringBuilder(); 184 | try (BufferedReader bufferedReader = new BufferedReader(new InputStreamReader(connection.getInputStream()))) { 185 | String line; 186 | while ((line = bufferedReader.readLine()) != null) { 187 | builder.append(line); 188 | } 189 | } 190 | 191 | if (logResponseStatusText) { 192 | plugin.getLogger().info("Sent data to bStats and received response: " + builder); 193 | } 194 | } 195 | 196 | /** 197 | * Gzips the given String. 198 | * 199 | * @param str The string to gzip. 200 | * @return The gzipped String. 201 | * @throws IOException If the compression failed. 202 | */ 203 | private static byte[] compress(final String str) throws IOException { 204 | if (str == null) { 205 | return null; 206 | } 207 | ByteArrayOutputStream outputStream = new ByteArrayOutputStream(); 208 | try (GZIPOutputStream gzip = new GZIPOutputStream(outputStream)) { 209 | gzip.write(str.getBytes(StandardCharsets.UTF_8)); 210 | } 211 | return outputStream.toByteArray(); 212 | } 213 | 214 | /** 215 | * Checks if bStats is enabled. 216 | * 217 | * @return Whether bStats is enabled or not. 218 | */ 219 | public boolean isEnabled() { 220 | return enabled; 221 | } 222 | 223 | /** 224 | * Starts the Scheduler which submits our data every 30 minutes. 225 | */ 226 | private void startSubmitting() { 227 | final Timer timer = new Timer(true); // We use a timer cause the Bukkit scheduler is affected by server lags 228 | timer.scheduleAtFixedRate(new TimerTask() { 229 | @Override 230 | public void run() { 231 | if (!plugin.isEnabled()) { // Plugin was disabled 232 | timer.cancel(); 233 | return; 234 | } 235 | // Nevertheless we want our code to run in the Bukkit main thread, so we have to use the Bukkit scheduler 236 | // Don't be afraid! The connection to the bStats server is still async, only the stats collection is sync ;) 237 | Bukkit.getScheduler().runTask(plugin, () -> submitData()); 238 | } 239 | }, 1000 * 60 * 5, 1000 * 60 * 30); 240 | // Submit the data every 30 minutes, first time after 5 minutes to give other plugins enough time to start 241 | // WARNING: Changing the frequency has no effect but your plugin WILL be blocked/deleted! 242 | // WARNING: Just don't do it! 243 | } 244 | 245 | /** 246 | * Gets the plugin specific data. 247 | * This method is called using Reflection. 248 | * 249 | * @return The plugin specific data. 250 | */ 251 | public JsonObject getPluginData() { 252 | JsonObject data = new JsonObject(); 253 | 254 | String pluginName = plugin.getDescription().getName(); 255 | String pluginVersion = plugin.getDescription().getVersion(); 256 | 257 | data.addProperty("pluginName", pluginName); // Append the name of the plugin 258 | data.addProperty("id", pluginId); // Append the id of the plugin 259 | data.addProperty("pluginVersion", pluginVersion); // Append the version of the plugin 260 | data.add("customCharts", new JsonArray()); 261 | 262 | return data; 263 | } 264 | 265 | /** 266 | * Gets the server specific data. 267 | * 268 | * @return The server specific data. 269 | */ 270 | private JsonObject getServerData() { 271 | // Minecraft specific data 272 | int playerAmount; 273 | try { 274 | // Around MC 1.8 the return type was changed to a collection from an array, 275 | // This fixes java.lang.NoSuchMethodError: org.bukkit.Bukkit.getOnlinePlayers()Ljava/util/Collection; 276 | Method onlinePlayersMethod = Class.forName("org.bukkit.Server").getMethod("getOnlinePlayers"); 277 | playerAmount = onlinePlayersMethod.getReturnType().equals(Collection.class) 278 | ? ((Collection) onlinePlayersMethod.invoke(Bukkit.getServer())).size() 279 | : ((Player[]) onlinePlayersMethod.invoke(Bukkit.getServer())).length; 280 | } catch (Exception e) { 281 | playerAmount = Bukkit.getOnlinePlayers().size(); // Just use the new method if the Reflection failed 282 | } 283 | int onlineMode = Bukkit.getOnlineMode() ? 1 : 0; 284 | String bukkitVersion = Bukkit.getVersion(); 285 | String bukkitName = Bukkit.getName(); 286 | 287 | // OS/Java specific data 288 | String javaVersion = System.getProperty("java.version"); 289 | String osName = System.getProperty("os.name"); 290 | String osArch = System.getProperty("os.arch"); 291 | String osVersion = System.getProperty("os.version"); 292 | int coreCount = Runtime.getRuntime().availableProcessors(); 293 | 294 | JsonObject data = new JsonObject(); 295 | 296 | data.addProperty("serverUUID", serverUUID); 297 | 298 | data.addProperty("playerAmount", playerAmount); 299 | data.addProperty("onlineMode", onlineMode); 300 | data.addProperty("bukkitVersion", bukkitVersion); 301 | data.addProperty("bukkitName", bukkitName); 302 | 303 | data.addProperty("javaVersion", javaVersion); 304 | data.addProperty("osName", osName); 305 | data.addProperty("osArch", osArch); 306 | data.addProperty("osVersion", osVersion); 307 | data.addProperty("coreCount", coreCount); 308 | 309 | return data; 310 | } 311 | 312 | /** 313 | * Collects the data and sends it afterwards. 314 | */ 315 | private void submitData() { 316 | final JsonObject data = getServerData(); 317 | 318 | JsonArray pluginData = new JsonArray(); 319 | // Search for all other bStats Metrics classes to get their plugin data 320 | for (Class service : Bukkit.getServicesManager().getKnownServices()) { 321 | try { 322 | service.getField("B_STATS_VERSION"); // Our identifier :) 323 | 324 | for (RegisteredServiceProvider provider : Bukkit.getServicesManager().getRegistrations(service)) { 325 | try { 326 | Object plugin = provider.getService().getMethod("getPluginData").invoke(provider.getProvider()); 327 | if (plugin instanceof JsonObject) { 328 | pluginData.add((JsonObject) plugin); 329 | } else { // old bstats version compatibility 330 | try { 331 | Class jsonObjectJsonSimple = Class.forName("org.json.simple.JSONObject"); 332 | if (plugin.getClass().isAssignableFrom(jsonObjectJsonSimple)) { 333 | Method jsonStringGetter = jsonObjectJsonSimple.getDeclaredMethod("toJSONString"); 334 | jsonStringGetter.setAccessible(true); 335 | String jsonString = (String) jsonStringGetter.invoke(plugin); 336 | JsonObject object = new JsonParser().parse(jsonString).getAsJsonObject(); 337 | pluginData.add(object); 338 | } 339 | } catch (ClassNotFoundException e) { 340 | // minecraft version 1.14+ 341 | if (logFailedRequests) { 342 | this.plugin.getLogger().log(Level.SEVERE, "Encountered unexpected exception ", e); 343 | } 344 | } 345 | } 346 | } catch (NullPointerException | NoSuchMethodException | IllegalAccessException | 347 | InvocationTargetException ignored) { 348 | } 349 | } 350 | } catch (NoSuchFieldException ignored) { 351 | } 352 | } 353 | 354 | data.add("plugins", pluginData); 355 | 356 | // Create a new thread for the connection to the bStats server 357 | new Thread(() -> { 358 | try { 359 | // Send the data 360 | sendData(plugin, data); 361 | } catch (Exception e) { 362 | // Something went wrong! :( 363 | if (logFailedRequests) { 364 | plugin.getLogger().log(Level.WARNING, "Could not submit plugin stats of " + plugin.getName(), e); 365 | } 366 | } 367 | }).start(); 368 | } 369 | } -------------------------------------------------------------------------------- /src/main/java/me/nik/resourceworld/modules/ListenerModule.java: -------------------------------------------------------------------------------- 1 | package me.nik.resourceworld.modules; 2 | 3 | import me.nik.resourceworld.ResourceWorld; 4 | import org.bukkit.event.HandlerList; 5 | import org.bukkit.event.Listener; 6 | 7 | public abstract class ListenerModule implements Listener { 8 | 9 | protected final ResourceWorld plugin; 10 | private final boolean enabled; 11 | 12 | public ListenerModule(boolean enabled, ResourceWorld plugin) { 13 | this.enabled = enabled; 14 | this.plugin = plugin; 15 | } 16 | 17 | public void load() { 18 | if (!this.enabled) return; 19 | this.plugin.getServer().getPluginManager().registerEvents(this, this.plugin); 20 | } 21 | 22 | public void shutdown() { 23 | if (!this.enabled) return; 24 | HandlerList.unregisterAll(this); 25 | } 26 | } -------------------------------------------------------------------------------- /src/main/java/me/nik/resourceworld/modules/impl/DisabledCommands.java: -------------------------------------------------------------------------------- 1 | package me.nik.resourceworld.modules.impl; 2 | 3 | import me.nik.resourceworld.ResourceWorld; 4 | import me.nik.resourceworld.files.Config; 5 | import me.nik.resourceworld.managers.MsgType; 6 | import me.nik.resourceworld.managers.Permissions; 7 | import me.nik.resourceworld.modules.ListenerModule; 8 | import org.bukkit.entity.Player; 9 | import org.bukkit.event.EventHandler; 10 | import org.bukkit.event.EventPriority; 11 | import org.bukkit.event.player.PlayerCommandPreprocessEvent; 12 | 13 | import java.util.List; 14 | 15 | public class DisabledCommands extends ListenerModule { 16 | 17 | public DisabledCommands(ResourceWorld plugin) { 18 | super((Config.Setting.WORLD_DISABLED_COMMANDS_ENABLED.getBoolean() 19 | || Config.Setting.NETHER_DISABLED_COMMANDS_ENABLED.getBoolean() 20 | || Config.Setting.END_DISABLED_COMMANDS_ENABLED.getBoolean()), plugin); 21 | } 22 | 23 | @EventHandler(priority = EventPriority.HIGHEST) 24 | public void disableWorldCommands(PlayerCommandPreprocessEvent e) { 25 | 26 | Player player = e.getPlayer(); 27 | 28 | if (player.hasPermission(Permissions.ADMIN.getPermission()) || e.getMessage().equals("/")) return; 29 | 30 | String world = player.getWorld().getName(); 31 | 32 | String message = e.getMessage(); 33 | 34 | if (world.equals(Config.Setting.WORLD_NAME.getString())) { 35 | 36 | e.setCancelled( 37 | Config.Setting.WORLD_DISABLED_COMMANDS_ENABLED.getBoolean() 38 | && isDisabledCommand(Config.Setting.WORLD_DISABLED_COMMANDS_LIST.getStringList(), message) 39 | ); 40 | 41 | } else if (world.equals(Config.Setting.NETHER_NAME.getString())) { 42 | 43 | e.setCancelled( 44 | Config.Setting.NETHER_DISABLED_COMMANDS_ENABLED.getBoolean() 45 | && isDisabledCommand(Config.Setting.NETHER_DISABLED_COMMANDS_LIST.getStringList(), message) 46 | ); 47 | 48 | } else if (world.equals(Config.Setting.END_NAME.getString())) { 49 | 50 | e.setCancelled( 51 | Config.Setting.END_DISABLED_COMMANDS_ENABLED.getBoolean() 52 | && isDisabledCommand(Config.Setting.END_DISABLED_COMMANDS_LIST.getStringList(), message) 53 | ); 54 | } 55 | 56 | if (e.isCancelled()) { 57 | player.sendMessage(MsgType.DISABLED_COMMAND.getMessage()); 58 | } 59 | } 60 | 61 | private boolean isDisabledCommand(List list, String cmd) { 62 | return list.stream().anyMatch(cmd::contains); 63 | } 64 | } -------------------------------------------------------------------------------- /src/main/java/me/nik/resourceworld/modules/impl/LeaveWorld.java: -------------------------------------------------------------------------------- 1 | package me.nik.resourceworld.modules.impl; 2 | 3 | import me.nik.resourceworld.ResourceWorld; 4 | import me.nik.resourceworld.files.Config; 5 | import me.nik.resourceworld.modules.ListenerModule; 6 | import org.bukkit.Bukkit; 7 | import org.bukkit.entity.Player; 8 | import org.bukkit.event.EventHandler; 9 | import org.bukkit.event.EventPriority; 10 | import org.bukkit.event.player.PlayerQuitEvent; 11 | 12 | public class LeaveWorld extends ListenerModule { 13 | 14 | public LeaveWorld(ResourceWorld plugin) { 15 | super(Config.Setting.SETTINGS_TELEPORT_TO_SPAWN.getBoolean(), plugin); 16 | } 17 | 18 | @EventHandler(priority = EventPriority.LOWEST) 19 | public void onLeave(PlayerQuitEvent e) { 20 | 21 | Player player = e.getPlayer(); 22 | 23 | if (this.plugin.getResourceWorlds() 24 | .values() 25 | .stream() 26 | .anyMatch(rw -> rw.getName().equals(player.getWorld().getName()))) { 27 | player.teleport(Bukkit.getWorld(Config.Setting.SETTINGS_SPAWN_WORLD.getString()).getSpawnLocation()); 28 | } 29 | } 30 | } -------------------------------------------------------------------------------- /src/main/java/me/nik/resourceworld/modules/impl/Portals.java: -------------------------------------------------------------------------------- 1 | package me.nik.resourceworld.modules.impl; 2 | 3 | import me.nik.resourceworld.ResourceWorld; 4 | import me.nik.resourceworld.files.Config; 5 | import me.nik.resourceworld.modules.ListenerModule; 6 | import org.bukkit.Bukkit; 7 | import org.bukkit.Location; 8 | import org.bukkit.World; 9 | import org.bukkit.event.EventHandler; 10 | import org.bukkit.event.EventPriority; 11 | import org.bukkit.event.player.PlayerPortalEvent; 12 | 13 | public class Portals extends ListenerModule { 14 | 15 | public Portals(ResourceWorld plugin) { 16 | super(Config.Setting.NETHER_PORTALS_ENABLED.getBoolean() || Config.Setting.END_PORTALS_ENABLED.getBoolean(), plugin); 17 | } 18 | 19 | private void handleEndPortal(PlayerPortalEvent e) { 20 | //Overworld -> End 21 | if (e.getFrom().getWorld().getEnvironment() == World.Environment.NORMAL) { 22 | 23 | if (!Config.Setting.END_PORTALS_ONLY_RESOURCE.getBoolean() && e.getFrom().getWorld().getName().equals(Config.Setting.WORLD_NAME.getString())) { 24 | 25 | World world = Bukkit.getWorld(Config.Setting.END_NAME.getString()); 26 | 27 | if (world == null) return; 28 | 29 | Location to = e.getTo(); 30 | 31 | try { 32 | 33 | e.setTo(new Location(world, to.getX(), to.getY(), to.getZ())); 34 | 35 | } catch (NullPointerException ignored) { 36 | 37 | /* 38 | I don't know why i did this, this is from two years ago. 39 | I'm guessing there's a good reason for it? 40 | */ 41 | Location loc = world.getHighestBlockAt(world.getSpawnLocation()).getLocation(); 42 | 43 | e.setTo(new Location(world, loc.getX(), loc.getY(), loc.getZ())); 44 | } 45 | } 46 | //End -> Overworld 47 | } else if (e.getFrom().getWorld().getName().equals(Config.Setting.END_NAME.getString())) { 48 | 49 | Location from = e.getFrom(); 50 | 51 | e.setTo(new Location(Bukkit.getWorld(Config.Setting.END_PORTALS_PORTALWORLD.getString()), from.getX(), from.getY(), from.getZ())); 52 | } 53 | } 54 | 55 | private void handleNetherPortal(PlayerPortalEvent e) { 56 | //Overworld -> Nether 57 | if (e.getFrom().getWorld().getEnvironment() == World.Environment.NORMAL) { 58 | 59 | if (Config.Setting.NETHER_PORTALS_ONLY_RESOURCE.getBoolean() && !e.getFrom().getWorld().getName().equals(Config.Setting.WORLD_NAME.getString())) 60 | return; 61 | 62 | World world = Bukkit.getWorld(Config.Setting.NETHER_NAME.getString()); 63 | 64 | if (world == null) return; 65 | 66 | Location from = e.getFrom(); 67 | 68 | double x, y, z; 69 | 70 | if (Config.Setting.NETHER_PORTALS_VANILLA_RATIO.getBoolean()) { 71 | 72 | x = from.getX() / 8; 73 | y = from.getY() / 8; 74 | z = from.getZ() / 8; 75 | 76 | } else { 77 | 78 | x = from.getX(); 79 | y = from.getY(); 80 | z = from.getZ(); 81 | } 82 | 83 | e.setTo(new Location(world, x, y, z)); 84 | 85 | //End -> Overworld 86 | } else if (e.getFrom().getWorld().getName().equals(Config.Setting.NETHER_NAME.getString())) { 87 | 88 | Location from = e.getFrom(); 89 | 90 | e.setTo(new Location(Bukkit.getWorld(Config.Setting.NETHER_PORTALS_PORTALWORLD.getString()), from.getX(), from.getY(), from.getZ())); 91 | } 92 | } 93 | 94 | @EventHandler(priority = EventPriority.MONITOR) 95 | public void onPortalEnd(PlayerPortalEvent e) { 96 | switch (e.getCause()) { 97 | case NETHER_PORTAL: 98 | handleNetherPortal(e); 99 | break; 100 | case END_PORTAL: 101 | handleEndPortal(e); 102 | break; 103 | } 104 | } 105 | } -------------------------------------------------------------------------------- /src/main/java/me/nik/resourceworld/modules/impl/Suffocation.java: -------------------------------------------------------------------------------- 1 | package me.nik.resourceworld.modules.impl; 2 | 3 | import me.nik.resourceworld.ResourceWorld; 4 | import me.nik.resourceworld.files.Config; 5 | import me.nik.resourceworld.modules.ListenerModule; 6 | import org.bukkit.entity.Player; 7 | import org.bukkit.event.EventHandler; 8 | import org.bukkit.event.entity.EntityDamageEvent; 9 | 10 | public class Suffocation extends ListenerModule { 11 | 12 | public Suffocation(ResourceWorld plugin) { 13 | super((Config.Setting.WORLD_DISABLE_SUFFOCATION.getBoolean() 14 | || Config.Setting.NETHER_DISABLE_SUFFOCATION.getBoolean() 15 | || Config.Setting.END_DISABLE_SUFFOCATION.getBoolean()), plugin); 16 | } 17 | 18 | @EventHandler 19 | public void onDamage(EntityDamageEvent e) { 20 | if (!(e.getEntity() instanceof Player) || !(e.getCause() == EntityDamageEvent.DamageCause.SUFFOCATION)) return; 21 | 22 | String world = e.getEntity().getWorld().getName(); 23 | 24 | if (world.equals(Config.Setting.WORLD_NAME.getString())) { 25 | e.setCancelled(Config.Setting.WORLD_DISABLE_SUFFOCATION.getBoolean()); 26 | } else if (world.equals(Config.Setting.NETHER_NAME.getString())) { 27 | e.setCancelled(Config.Setting.NETHER_DISABLE_SUFFOCATION.getBoolean()); 28 | } else if (world.equals(Config.Setting.END_NAME.getString())) { 29 | e.setCancelled(Config.Setting.END_DISABLE_SUFFOCATION.getBoolean()); 30 | } 31 | } 32 | } -------------------------------------------------------------------------------- /src/main/java/me/nik/resourceworld/tasks/AlwaysDay.java: -------------------------------------------------------------------------------- 1 | package me.nik.resourceworld.tasks; 2 | 3 | import me.nik.resourceworld.files.Config; 4 | import org.bukkit.Bukkit; 5 | import org.bukkit.scheduler.BukkitRunnable; 6 | 7 | public class AlwaysDay extends BukkitRunnable { 8 | 9 | @Override 10 | public void run() { 11 | Bukkit.getWorld(Config.Setting.WORLD_NAME.getString()).setTime(1000L); 12 | } 13 | } -------------------------------------------------------------------------------- /src/main/java/me/nik/resourceworld/tasks/ResetEndWorld.java: -------------------------------------------------------------------------------- 1 | package me.nik.resourceworld.tasks; 2 | 3 | import me.nik.resourceworld.ResourceWorld; 4 | import me.nik.resourceworld.api.ResourceWorldType; 5 | import org.bukkit.scheduler.BukkitRunnable; 6 | 7 | public class ResetEndWorld extends BukkitRunnable { 8 | 9 | private final ResourceWorld plugin; 10 | 11 | public ResetEndWorld(ResourceWorld plugin) { 12 | this.plugin = plugin; 13 | } 14 | 15 | @Override 16 | public void run() { 17 | this.plugin.getResourceWorld(ResourceWorldType.RESOURCE_END).reset(); 18 | } 19 | } -------------------------------------------------------------------------------- /src/main/java/me/nik/resourceworld/tasks/ResetNetherWorld.java: -------------------------------------------------------------------------------- 1 | package me.nik.resourceworld.tasks; 2 | 3 | import me.nik.resourceworld.ResourceWorld; 4 | import me.nik.resourceworld.api.ResourceWorldType; 5 | import org.bukkit.scheduler.BukkitRunnable; 6 | 7 | public class ResetNetherWorld extends BukkitRunnable { 8 | 9 | private final ResourceWorld plugin; 10 | 11 | public ResetNetherWorld(ResourceWorld plugin) { 12 | this.plugin = plugin; 13 | } 14 | 15 | @Override 16 | public void run() { 17 | this.plugin.getResourceWorld(ResourceWorldType.RESOURCE_NETHER).reset(); 18 | } 19 | } -------------------------------------------------------------------------------- /src/main/java/me/nik/resourceworld/tasks/ResetWorld.java: -------------------------------------------------------------------------------- 1 | package me.nik.resourceworld.tasks; 2 | 3 | import me.nik.resourceworld.ResourceWorld; 4 | import me.nik.resourceworld.api.ResourceWorldType; 5 | import org.bukkit.scheduler.BukkitRunnable; 6 | 7 | public class ResetWorld extends BukkitRunnable { 8 | 9 | private final ResourceWorld plugin; 10 | 11 | public ResetWorld(ResourceWorld plugin) { 12 | this.plugin = plugin; 13 | } 14 | 15 | @Override 16 | public void run() { 17 | this.plugin.getResourceWorld(ResourceWorldType.RESOURCE_WORLD).reset(); 18 | } 19 | } -------------------------------------------------------------------------------- /src/main/java/me/nik/resourceworld/utils/ChatUtils.java: -------------------------------------------------------------------------------- 1 | package me.nik.resourceworld.utils; 2 | 3 | import me.nik.resourceworld.managers.custom.ResourceWorldException; 4 | import org.bukkit.Bukkit; 5 | import org.bukkit.ChatColor; 6 | 7 | public class ChatUtils { 8 | 9 | private ChatUtils() { 10 | throw new ResourceWorldException("This is a static class dummy!"); 11 | } 12 | 13 | /** 14 | * @param msg The message to format 15 | * @return The formatted message 16 | */ 17 | public static String format(String msg) { 18 | return ChatColor.translateAlternateColorCodes('&', msg); 19 | } 20 | 21 | /** 22 | * @param message The message to send to the console 23 | */ 24 | public static void consoleMessage(String message) { 25 | Bukkit.getServer().getConsoleSender().sendMessage(message); 26 | } 27 | } -------------------------------------------------------------------------------- /src/main/java/me/nik/resourceworld/utils/LocationFinder.java: -------------------------------------------------------------------------------- 1 | package me.nik.resourceworld.utils; 2 | 3 | import io.papermc.lib.PaperLib; 4 | import me.nik.resourceworld.files.Config; 5 | import org.bukkit.Chunk; 6 | import org.bukkit.Location; 7 | import org.bukkit.Sound; 8 | import org.bukkit.World; 9 | import org.bukkit.block.Block; 10 | import org.bukkit.block.BlockFace; 11 | import org.bukkit.entity.Player; 12 | import org.bukkit.potion.PotionEffect; 13 | import org.bukkit.potion.PotionEffectType; 14 | 15 | import java.util.Random; 16 | import java.util.concurrent.CompletableFuture; 17 | 18 | public class LocationFinder { 19 | 20 | private static final Random random = new Random(); 21 | 22 | public void teleportSafely(Player player, World world) { 23 | 24 | final World.Environment environment = world.getEnvironment(); 25 | 26 | int x, z; 27 | final boolean nether; 28 | 29 | switch (environment) { 30 | 31 | case NETHER: 32 | 33 | x = randomInt(Config.Setting.TELEPORT_NETHER_MAX_RANGE.getInt()); 34 | z = randomInt(Config.Setting.TELEPORT_NETHER_MAX_RANGE.getInt()); 35 | nether = true; 36 | 37 | break; 38 | 39 | case THE_END: 40 | 41 | x = randomInt(Config.Setting.TELEPORT_END_MAX_RANGE.getInt()); 42 | z = randomInt(Config.Setting.TELEPORT_END_MAX_RANGE.getInt()); 43 | nether = false; 44 | 45 | break; 46 | 47 | default: 48 | 49 | x = randomInt(Config.Setting.TELEPORT_WORLD_MAX_RANGE.getInt()); 50 | z = randomInt(Config.Setting.TELEPORT_WORLD_MAX_RANGE.getInt()); 51 | nether = false; 52 | 53 | break; 54 | } 55 | 56 | Location location = new Location(world, x, (world.getHighestBlockYAt(x, z) + 1), z); 57 | 58 | //Load the chunk. 59 | CompletableFuture chunk = PaperLib.getChunkAtAsync(location); 60 | 61 | //Once it's grabbed, execute the following action. 62 | chunk.thenRunAsync(() -> { 63 | 64 | //Special things we need to account for the nether world. 65 | if (nether) { 66 | 67 | //Usually the best height. 68 | location.setY(80); 69 | 70 | //Keep subtracting until we reach the ground. 71 | while (world.getBlockAt(location).isEmpty()) { 72 | location.subtract(0, 1, 0); 73 | } 74 | 75 | //Add one to make sure the player teleports on top of the block. 76 | location.add(0, 1, 0); 77 | } 78 | 79 | //If the location is safe, proceed otherwise just look for another location. 80 | if (isLocationSafe(location, world, environment)) { 81 | 82 | //Finally teleport and apply effects on the main thread. 83 | TaskUtils.task(() -> { 84 | 85 | PaperLib.teleportAsync(player, location); 86 | 87 | //Idiot proof 88 | try { 89 | 90 | if (Config.Setting.TELEPORT_EFFECTS_ENABLED.getBoolean()) { 91 | player.addPotionEffect( 92 | new PotionEffect( 93 | PotionEffectType.getByName(Config.Setting.TELEPORT_EFFECT.getString()), 94 | Config.Setting.TELEPORT_EFFECT_DURATION.getInt() * 20, 95 | Config.Setting.TELEPORT_EFFECT_AMPLIFIER.getInt())); 96 | } 97 | 98 | if (Config.Setting.TELEPORT_SOUND_ENABLED.getBoolean()) { 99 | player.playSound(player.getLocation(), Sound.valueOf(Config.Setting.TELEPORT_SOUND.getString()), 2, 2); 100 | } 101 | 102 | } catch (IllegalArgumentException ignored) { 103 | } 104 | }); 105 | 106 | } else teleportSafely(player, world); //Repeat 107 | }); 108 | } 109 | 110 | private boolean isLocationSafe(Location location, World world, World.Environment environment) { 111 | 112 | int blockX = location.getBlockX(); 113 | int blockY = location.getBlockY(); 114 | int blockZ = location.getBlockZ(); 115 | 116 | final Block feet = world.getBlockAt(blockX, blockY, blockZ); 117 | 118 | if (!feet.getRelative(BlockFace.UP).isEmpty()) return false; 119 | 120 | switch (environment) { 121 | 122 | case NETHER: 123 | 124 | for (int x = (blockX - 1); x <= (blockX + 1); x++) { 125 | for (int y = (blockY - 1); y <= (blockY + 1); y++) { 126 | for (int z = (blockZ - 1); z <= (blockZ + 1); z++) { 127 | //Make sure no liquid (Lava) is nearby. 128 | if (world.getBlockAt(x, y, z).isLiquid()) return false; 129 | } 130 | } 131 | } 132 | 133 | return true; 134 | 135 | case THE_END: 136 | //Make sure the player is not floating 137 | return !feet.getRelative(BlockFace.DOWN, 2).isEmpty(); 138 | } 139 | 140 | //Return false on liquid otherwise the player will only teleport in the sea. 141 | return !feet.getRelative(BlockFace.DOWN).isLiquid(); 142 | } 143 | 144 | private int randomInt(int value) { 145 | 146 | int min = -value; 147 | 148 | return random.nextInt((value - min) + 1) + min; 149 | } 150 | } -------------------------------------------------------------------------------- /src/main/java/me/nik/resourceworld/utils/MiscUtils.java: -------------------------------------------------------------------------------- 1 | package me.nik.resourceworld.utils; 2 | 3 | import me.nik.resourceworld.files.Config; 4 | import me.nik.resourceworld.managers.custom.ResourceWorldException; 5 | import org.bukkit.Bukkit; 6 | import org.bukkit.Location; 7 | import org.bukkit.World; 8 | 9 | import java.io.File; 10 | import java.util.concurrent.TimeUnit; 11 | 12 | public class MiscUtils { 13 | 14 | private static final boolean LEGACY = Bukkit.getVersion().contains("1.8") 15 | || Bukkit.getVersion().contains("1.9") 16 | || Bukkit.getVersion().contains("1.10") 17 | || Bukkit.getVersion().contains("1.11") 18 | || Bukkit.getVersion().contains("1.12"); 19 | 20 | private MiscUtils() { 21 | throw new ResourceWorldException("This is a static class dummy!"); 22 | } 23 | 24 | public static void deleteDirectory(File directory) { 25 | if (directory.exists()) { 26 | File[] files = directory.listFiles(); 27 | if (files != null) 28 | for (File file : files) { 29 | if (file.isDirectory()) { 30 | deleteDirectory(file); 31 | } else { 32 | file.delete(); 33 | } 34 | } 35 | } 36 | } 37 | 38 | /** 39 | * Convert a millisecond duration to a string format 40 | * 41 | * @param millis A duration to convert to a string form 42 | * @return A string of the form "X Days Y Hours Z Minutes A Seconds". 43 | */ 44 | public static String getDurationBreakdown(long millis) { 45 | 46 | final long days = TimeUnit.MILLISECONDS.toDays(millis); 47 | millis -= TimeUnit.DAYS.toMillis(days); 48 | 49 | final long hours = TimeUnit.MILLISECONDS.toHours(millis); 50 | millis -= TimeUnit.HOURS.toMillis(hours); 51 | 52 | final long minutes = TimeUnit.MILLISECONDS.toMinutes(millis); 53 | millis -= TimeUnit.MINUTES.toMillis(minutes); 54 | 55 | final long seconds = TimeUnit.MILLISECONDS.toSeconds(millis); 56 | 57 | String format = Config.Setting.SETTINGS_RESET_FORMAT.getString(); 58 | 59 | if (days > 0) { 60 | 61 | format = format.replace("%days%", String.valueOf(days)); 62 | 63 | } else { 64 | 65 | format = format.replace("%days%", String.valueOf(0)); 66 | } 67 | 68 | if (hours > 0) { 69 | 70 | format = format.replace("%hours%", String.valueOf(hours)); 71 | 72 | } else { 73 | 74 | format = format.replace("%hours%", String.valueOf(0)); 75 | } 76 | 77 | if (minutes > 0) { 78 | 79 | format = format.replace("%minutes%", String.valueOf(minutes)); 80 | 81 | } else { 82 | 83 | format = format.replace("%minutes%", String.valueOf(0)); 84 | } 85 | 86 | if (seconds > 0) { 87 | 88 | format = format.replace("%seconds%", String.valueOf(seconds)); 89 | 90 | } else { 91 | 92 | format = format.replace("%seconds%", String.valueOf(0)); 93 | } 94 | 95 | return ChatUtils.format(format); 96 | } 97 | 98 | /** 99 | * Convert a location to a string seperated by a comma 100 | * So you can later grab it and convert it to a location by splitting the comma 101 | * 102 | * @param location The location 103 | * @return The location as a string 104 | */ 105 | public static String locationToString(final Location location) { 106 | return location.getX() + "," + 107 | location.getY() + "," + 108 | location.getZ() + "," + 109 | location.getWorld().getName(); 110 | } 111 | 112 | /** 113 | * Convert a string to a location 114 | * 115 | * @param location The location as a string 116 | * @return The bukkit location 117 | */ 118 | public static Location stringToLocation(final String location) { 119 | final String[] data = location.split(","); 120 | 121 | try { 122 | final double x = Double.parseDouble(data[0]); 123 | final double y = Double.parseDouble(data[1]); 124 | final double z = Double.parseDouble(data[2]); 125 | final World world = Bukkit.getWorld(data[3]); 126 | 127 | return new Location(world, x, y, z); 128 | } catch (NumberFormatException | NullPointerException e) { 129 | e.printStackTrace(); 130 | } 131 | 132 | return null; 133 | } 134 | 135 | public static boolean isLegacy() { 136 | return LEGACY; 137 | } 138 | } -------------------------------------------------------------------------------- /src/main/java/me/nik/resourceworld/utils/TaskUtils.java: -------------------------------------------------------------------------------- 1 | package me.nik.resourceworld.utils; 2 | 3 | import me.nik.resourceworld.ResourceWorld; 4 | import me.nik.resourceworld.managers.custom.ResourceWorldException; 5 | import org.bukkit.Bukkit; 6 | import org.bukkit.scheduler.BukkitTask; 7 | 8 | public final class TaskUtils { 9 | 10 | private TaskUtils() { 11 | throw new ResourceWorldException("This is a static class dummy!"); 12 | } 13 | 14 | public static BukkitTask task(Runnable runnable) { 15 | return Bukkit.getScheduler().runTask(ResourceWorld.getInstance(), runnable); 16 | } 17 | 18 | public static BukkitTask taskLater(Runnable runnable, long delay) { 19 | return Bukkit.getScheduler().runTaskLater(ResourceWorld.getInstance(), runnable, delay); 20 | } 21 | } -------------------------------------------------------------------------------- /src/main/java/me/nik/resourceworld/utils/custom/ExpiringMap.java: -------------------------------------------------------------------------------- 1 | package me.nik.resourceworld.utils.custom; 2 | 3 | import java.util.HashMap; 4 | import java.util.Map; 5 | 6 | public class ExpiringMap extends HashMap { 7 | 8 | private final long expireMillis; 9 | 10 | private final Map> map = new HashMap<>(); 11 | 12 | public ExpiringMap(long expireMillis) { 13 | this.expireMillis = expireMillis; 14 | } 15 | 16 | @Override 17 | public V get(Object key) { 18 | 19 | validate(); 20 | 21 | for (Pair pair : this.map.values()) { 22 | 23 | if (pair.getKey() == key) return pair.getValue(); 24 | } 25 | 26 | return null; 27 | } 28 | 29 | public V removeOrDefault(Object key, V defaultValue) { 30 | 31 | validate(); 32 | 33 | Pair pair = null; 34 | 35 | for (Pair kvPair : this.map.values()) { 36 | 37 | if (kvPair.getKey() != key) continue; 38 | 39 | pair = kvPair; 40 | } 41 | 42 | if (pair != null) { 43 | 44 | this.map.values().remove(pair); 45 | 46 | return pair.getValue(); 47 | } 48 | 49 | return defaultValue; 50 | } 51 | 52 | @Override 53 | public V getOrDefault(Object key, V defaultValue) { 54 | 55 | validate(); 56 | 57 | V v = null; 58 | 59 | for (Pair pair : this.map.values()) { 60 | 61 | if (pair.getKey() != key) continue; 62 | 63 | v = pair.getValue(); 64 | } 65 | 66 | return v != null ? v : defaultValue; 67 | } 68 | 69 | @Override 70 | public V put(K key, V value) { 71 | 72 | validate(); 73 | 74 | this.map.put(System.currentTimeMillis(), new Pair<>(key, value)); 75 | 76 | return value; 77 | } 78 | 79 | @Override 80 | public V putIfAbsent(K key, V value) { 81 | 82 | validate(); 83 | 84 | V v = null; 85 | 86 | for (Pair pair : this.map.values()) { 87 | 88 | if (pair.getKey() != key) continue; 89 | 90 | v = pair.getValue(); 91 | } 92 | 93 | if (v == null) v = this.put(key, value); 94 | 95 | return v; 96 | } 97 | 98 | @Override 99 | public int size() { 100 | 101 | validate(); 102 | 103 | return this.map.size(); 104 | } 105 | 106 | @Override 107 | public boolean containsKey(Object key) { 108 | 109 | validate(); 110 | 111 | for (Pair pair : this.map.values()) { 112 | 113 | if (pair.getKey() == key) return true; 114 | } 115 | 116 | return false; 117 | } 118 | 119 | @Override 120 | public boolean containsValue(Object value) { 121 | 122 | validate(); 123 | 124 | for (Pair pair : this.map.values()) { 125 | 126 | if (pair.getValue() == value) return true; 127 | } 128 | 129 | return false; 130 | } 131 | 132 | @Override 133 | public void clear() { 134 | this.map.clear(); 135 | } 136 | 137 | private void validate() { 138 | this.map.keySet().removeIf(timeStamp -> System.currentTimeMillis() - timeStamp > this.expireMillis); 139 | } 140 | } -------------------------------------------------------------------------------- /src/main/java/me/nik/resourceworld/utils/custom/Pair.java: -------------------------------------------------------------------------------- 1 | package me.nik.resourceworld.utils.custom; 2 | 3 | public class Pair { 4 | 5 | private T key; 6 | private Y value; 7 | 8 | public Pair(T key, Y value) { 9 | this.key = key; 10 | this.value = value; 11 | } 12 | 13 | public Pair(Pair pair) { 14 | this.key = pair.key; 15 | this.value = pair.value; 16 | } 17 | 18 | public T getKey() { 19 | return key; 20 | } 21 | 22 | public void setKey(T key) { 23 | this.key = key; 24 | } 25 | 26 | public Y getValue() { 27 | return value; 28 | } 29 | 30 | public void setValue(Y value) { 31 | this.value = value; 32 | } 33 | 34 | @Override 35 | public String toString() { 36 | return "Pair{" + 37 | "key=" + key + 38 | ", value=" + value + 39 | '}'; 40 | } 41 | } -------------------------------------------------------------------------------- /src/main/resources/plugin.yml: -------------------------------------------------------------------------------- 1 | name: ResourceWorld 2 | version: ${project.version} 3 | main: me.nik.resourceworld.ResourceWorld 4 | api-version: 1.13 5 | authors: [ Nik ] 6 | description: ${project.description} 7 | website: https://discord.gg/m7j2Y9H 8 | softdepend: [ PlaceholderAPI, Vault ] 9 | commands: 10 | resource: 11 | description: Unlimited resources! 12 | aliases: [ resourceworld, rw ] 13 | permissions: 14 | rw.tp: 15 | description: Randomly Teleport To The Resource World! 16 | default: true 17 | rw.tp.nether: 18 | description: Randomly Teleport To The Nether Resource World! 19 | rw.tp.end: 20 | description: Randomly Teleport To The End Resource World! 21 | rw.tp.*: 22 | description: Access To Teleport To All The Resource Worlds! 23 | default: op 24 | children: 25 | rw.tp: true 26 | rw.tp.nether: true 27 | rw.tp.end: true 28 | rw.admin: 29 | description: Access to the Resource World admin commands! 30 | default: op -------------------------------------------------------------------------------- /version.txt: -------------------------------------------------------------------------------- 1 | 2.1.0 --------------------------------------------------------------------------------