diff --git a/LICENSE b/LICENSE new file mode 100644 index 0000000..f288702 --- /dev/null +++ b/LICENSE @@ -0,0 +1,674 @@ + GNU GENERAL PUBLIC LICENSE + Version 3, 29 June 2007 + + Copyright (C) 2007 Free Software Foundation, Inc. + Everyone is permitted to copy and distribute verbatim copies + of this license document, but changing it is not allowed. + + Preamble + + The GNU General Public License is a free, copyleft license for +software and other kinds of works. + + The licenses for most software and other practical works are designed +to take away your freedom to share and change the works. By contrast, +the GNU General Public License is intended to guarantee your freedom to +share and change all versions of a program--to make sure it remains free +software for all its users. We, the Free Software Foundation, use the +GNU General Public License for most of our software; it applies also to +any other work released this way by its authors. You can apply it to +your programs, too. + + When we speak of free software, we are referring to freedom, not +price. Our General Public Licenses are designed to make sure that you +have the freedom to distribute copies of free software (and charge for +them if you wish), that you receive source code or can get it if you +want it, that you can change the software or use pieces of it in new +free programs, and that you know you can do these things. + + To protect your rights, we need to prevent others from denying you +these rights or asking you to surrender the rights. Therefore, you have +certain responsibilities if you distribute copies of the software, or if +you modify it: responsibilities to respect the freedom of others. + + For example, if you distribute copies of such a program, whether +gratis or for a fee, you must pass on to the recipients the same +freedoms that you received. You must make sure that they, too, receive +or can get the source code. And you must show them these terms so they +know their rights. + + Developers that use the GNU GPL protect your rights with two steps: +(1) assert copyright on the software, and (2) offer you this License +giving you legal permission to copy, distribute and/or modify it. + + For the developers' and authors' protection, the GPL clearly explains +that there is no warranty for this free software. For both users' and +authors' sake, the GPL requires that modified versions be marked as +changed, so that their problems will not be attributed erroneously to +authors of previous versions. + + Some devices are designed to deny users access to install or run +modified versions of the software inside them, although the manufacturer +can do so. This is fundamentally incompatible with the aim of +protecting users' freedom to change the software. The systematic +pattern of such abuse occurs in the area of products for individuals to +use, which is precisely where it is most unacceptable. Therefore, we +have designed this version of the GPL to prohibit the practice for those +products. If such problems arise substantially in other domains, we +stand ready to extend this provision to those domains in future versions +of the GPL, as needed to protect the freedom of users. + + Finally, every program is threatened constantly by software patents. +States should not allow patents to restrict development and use of +software on general-purpose computers, but in those that do, we wish to +avoid the special danger that patents applied to a free program could +make it effectively proprietary. To prevent this, the GPL assures that +patents cannot be used to render the program non-free. + + The precise terms and conditions for copying, distribution and +modification follow. + + TERMS AND CONDITIONS + + 0. Definitions. + + "This License" refers to version 3 of the GNU General Public License. + + "Copyright" also means copyright-like laws that apply to other kinds of +works, such as semiconductor masks. + + "The Program" refers to any copyrightable work licensed under this +License. Each licensee is addressed as "you". "Licensees" and +"recipients" may be individuals or organizations. + + To "modify" a work means to copy from or adapt all or part of the work +in a fashion requiring copyright permission, other than the making of an +exact copy. The resulting work is called a "modified version" of the +earlier work or a work "based on" the earlier work. + + A "covered work" means either the unmodified Program or a work based +on the Program. + + To "propagate" a work means to do anything with it that, without +permission, would make you directly or secondarily liable for +infringement under applicable copyright law, except executing it on a +computer or modifying a private copy. Propagation includes copying, +distribution (with or without modification), making available to the +public, and in some countries other activities as well. + + To "convey" a work means any kind of propagation that enables other +parties to make or receive copies. Mere interaction with a user through +a computer network, with no transfer of a copy, is not conveying. + + An interactive user interface displays "Appropriate Legal Notices" +to the extent that it includes a convenient and prominently visible +feature that (1) displays an appropriate copyright notice, and (2) +tells the user that there is no warranty for the work (except to the +extent that warranties are provided), that licensees may convey the +work under this License, and how to view a copy of this License. If +the interface presents a list of user commands or options, such as a +menu, a prominent item in the list meets this criterion. + + 1. Source Code. + + The "source code" for a work means the preferred form of the work +for making modifications to it. "Object code" means any non-source +form of a work. + + A "Standard Interface" means an interface that either is an official +standard defined by a recognized standards body, or, in the case of +interfaces specified for a particular programming language, one that +is widely used among developers working in that language. + + The "System Libraries" of an executable work include anything, other +than the work as a whole, that (a) is included in the normal form of +packaging a Major Component, but which is not part of that Major +Component, and (b) serves only to enable use of the work with that +Major Component, or to implement a Standard Interface for which an +implementation is available to the public in source code form. A +"Major Component", in this context, means a major essential component +(kernel, window system, and so on) of the specific operating system +(if any) on which the executable work runs, or a compiler used to +produce the work, or an object code interpreter used to run it. + + The "Corresponding Source" for a work in object code form means all +the source code needed to generate, install, and (for an executable +work) run the object code and to modify the work, including scripts to +control those activities. However, it does not include the work's +System Libraries, or general-purpose tools or generally available free +programs which are used unmodified in performing those activities but +which are not part of the work. For example, Corresponding Source +includes interface definition files associated with source files for +the work, and the source code for shared libraries and dynamically +linked subprograms that the work is specifically designed to require, +such as by intimate data communication or control flow between those +subprograms and other parts of the work. + + The Corresponding Source need not include anything that users +can regenerate automatically from other parts of the Corresponding +Source. + + The Corresponding Source for a work in source code form is that +same work. + + 2. Basic Permissions. + + All rights granted under this License are granted for the term of +copyright on the Program, and are irrevocable provided the stated +conditions are met. This License explicitly affirms your unlimited +permission to run the unmodified Program. The output from running a +covered work is covered by this License only if the output, given its +content, constitutes a covered work. This License acknowledges your +rights of fair use or other equivalent, as provided by copyright law. + + You may make, run and propagate covered works that you do not +convey, without conditions so long as your license otherwise remains +in force. You may convey covered works to others for the sole purpose +of having them make modifications exclusively for you, or provide you +with facilities for running those works, provided that you comply with +the terms of this License in conveying all material for which you do +not control copyright. Those thus making or running the covered works +for you must do so exclusively on your behalf, under your direction +and control, on terms that prohibit them from making any copies of +your copyrighted material outside their relationship with you. + + Conveying under any other circumstances is permitted solely under +the conditions stated below. Sublicensing is not allowed; section 10 +makes it unnecessary. + + 3. Protecting Users' Legal Rights From Anti-Circumvention Law. + + No covered work shall be deemed part of an effective technological +measure under any applicable law fulfilling obligations under article +11 of the WIPO copyright treaty adopted on 20 December 1996, or +similar laws prohibiting or restricting circumvention of such +measures. + + When you convey a covered work, you waive any legal power to forbid +circumvention of technological measures to the extent such circumvention +is effected by exercising rights under this License with respect to +the covered work, and you disclaim any intention to limit operation or +modification of the work as a means of enforcing, against the work's +users, your or third parties' legal rights to forbid circumvention of +technological measures. + + 4. Conveying Verbatim Copies. + + You may convey verbatim copies of the Program's source code as you +receive it, in any medium, provided that you conspicuously and +appropriately publish on each copy an appropriate copyright notice; +keep intact all notices stating that this License and any +non-permissive terms added in accord with section 7 apply to the code; +keep intact all notices of the absence of any warranty; and give all +recipients a copy of this License along with the Program. + + You may charge any price or no price for each copy that you convey, +and you may offer support or warranty protection for a fee. + + 5. Conveying Modified Source Versions. + + You may convey a work based on the Program, or the modifications to +produce it from the Program, in the form of source code under the +terms of section 4, provided that you also meet all of these conditions: + + a) The work must carry prominent notices stating that you modified + it, and giving a relevant date. + + b) The work must carry prominent notices stating that it is + released under this License and any conditions added under section + 7. This requirement modifies the requirement in section 4 to + "keep intact all notices". + + c) You must license the entire work, as a whole, under this + License to anyone who comes into possession of a copy. This + License will therefore apply, along with any applicable section 7 + additional terms, to the whole of the work, and all its parts, + regardless of how they are packaged. This License gives no + permission to license the work in any other way, but it does not + invalidate such permission if you have separately received it. + + d) If the work has interactive user interfaces, each must display + Appropriate Legal Notices; however, if the Program has interactive + interfaces that do not display Appropriate Legal Notices, your + work need not make them do so. + + A compilation of a covered work with other separate and independent +works, which are not by their nature extensions of the covered work, +and which are not combined with it such as to form a larger program, +in or on a volume of a storage or distribution medium, is called an +"aggregate" if the compilation and its resulting copyright are not +used to limit the access or legal rights of the compilation's users +beyond what the individual works permit. Inclusion of a covered work +in an aggregate does not cause this License to apply to the other +parts of the aggregate. + + 6. Conveying Non-Source Forms. + + You may convey a covered work in object code form under the terms +of sections 4 and 5, provided that you also convey the +machine-readable Corresponding Source under the terms of this License, +in one of these ways: + + a) Convey the object code in, or embodied in, a physical product + (including a physical distribution medium), accompanied by the + Corresponding Source fixed on a durable physical medium + customarily used for software interchange. + + b) Convey the object code in, or embodied in, a physical product + (including a physical distribution medium), accompanied by a + written offer, valid for at least three years and valid for as + long as you offer spare parts or customer support for that product + model, to give anyone who possesses the object code either (1) a + copy of the Corresponding Source for all the software in the + product that is covered by this License, on a durable physical + medium customarily used for software interchange, for a price no + more than your reasonable cost of physically performing this + conveying of source, or (2) access to copy the + Corresponding Source from a network server at no charge. + + c) Convey individual copies of the object code with a copy of the + written offer to provide the Corresponding Source. This + alternative is allowed only occasionally and noncommercially, and + only if you received the object code with such an offer, in accord + with subsection 6b. + + d) Convey the object code by offering access from a designated + place (gratis or for a charge), and offer equivalent access to the + Corresponding Source in the same way through the same place at no + further charge. You need not require recipients to copy the + Corresponding Source along with the object code. If the place to + copy the object code is a network server, the Corresponding Source + may be on a different server (operated by you or a third party) + that supports equivalent copying facilities, provided you maintain + clear directions next to the object code saying where to find the + Corresponding Source. Regardless of what server hosts the + Corresponding Source, you remain obligated to ensure that it is + available for as long as needed to satisfy these requirements. + + e) Convey the object code using peer-to-peer transmission, provided + you inform other peers where the object code and Corresponding + Source of the work are being offered to the general public at no + charge under subsection 6d. + + A separable portion of the object code, whose source code is excluded +from the Corresponding Source as a System Library, need not be +included in conveying the object code work. + + A "User Product" is either (1) a "consumer product", which means any +tangible personal property which is normally used for personal, family, +or household purposes, or (2) anything designed or sold for incorporation +into a dwelling. In determining whether a product is a consumer product, +doubtful cases shall be resolved in favor of coverage. For a particular +product received by a particular user, "normally used" refers to a +typical or common use of that class of product, regardless of the status +of the particular user or of the way in which the particular user +actually uses, or expects or is expected to use, the product. A product +is a consumer product regardless of whether the product has substantial +commercial, industrial or non-consumer uses, unless such uses represent +the only significant mode of use of the product. + + "Installation Information" for a User Product means any methods, +procedures, authorization keys, or other information required to install +and execute modified versions of a covered work in that User Product from +a modified version of its Corresponding Source. The information must +suffice to ensure that the continued functioning of the modified object +code is in no case prevented or interfered with solely because +modification has been made. + + If you convey an object code work under this section in, or with, or +specifically for use in, a User Product, and the conveying occurs as +part of a transaction in which the right of possession and use of the +User Product is transferred to the recipient in perpetuity or for a +fixed term (regardless of how the transaction is characterized), the +Corresponding Source conveyed under this section must be accompanied +by the Installation Information. But this requirement does not apply +if neither you nor any third party retains the ability to install +modified object code on the User Product (for example, the work has +been installed in ROM). + + The requirement to provide Installation Information does not include a +requirement to continue to provide support service, warranty, or updates +for a work that has been modified or installed by the recipient, or for +the User Product in which it has been modified or installed. Access to a +network may be denied when the modification itself materially and +adversely affects the operation of the network or violates the rules and +protocols for communication across the network. + + Corresponding Source conveyed, and Installation Information provided, +in accord with this section must be in a format that is publicly +documented (and with an implementation available to the public in +source code form), and must require no special password or key for +unpacking, reading or copying. + + 7. Additional Terms. + + "Additional permissions" are terms that supplement the terms of this +License by making exceptions from one or more of its conditions. +Additional permissions that are applicable to the entire Program shall +be treated as though they were included in this License, to the extent +that they are valid under applicable law. If additional permissions +apply only to part of the Program, that part may be used separately +under those permissions, but the entire Program remains governed by +this License without regard to the additional permissions. + + When you convey a copy of a covered work, you may at your option +remove any additional permissions from that copy, or from any part of +it. (Additional permissions may be written to require their own +removal in certain cases when you modify the work.) You may place +additional permissions on material, added by you to a covered work, +for which you have or can give appropriate copyright permission. + + Notwithstanding any other provision of this License, for material you +add to a covered work, you may (if authorized by the copyright holders of +that material) supplement the terms of this License with terms: + + a) Disclaiming warranty or limiting liability differently from the + terms of sections 15 and 16 of this License; or + + b) Requiring preservation of specified reasonable legal notices or + author attributions in that material or in the Appropriate Legal + Notices displayed by works containing it; or + + c) Prohibiting misrepresentation of the origin of that material, or + requiring that modified versions of such material be marked in + reasonable ways as different from the original version; or + + d) Limiting the use for publicity purposes of names of licensors or + authors of the material; or + + e) Declining to grant rights under trademark law for use of some + trade names, trademarks, or service marks; or + + f) Requiring indemnification of licensors and authors of that + material by anyone who conveys the material (or modified versions of + it) with contractual assumptions of liability to the recipient, for + any liability that these contractual assumptions directly impose on + those licensors and authors. + + All other non-permissive additional terms are considered "further +restrictions" within the meaning of section 10. If the Program as you +received it, or any part of it, contains a notice stating that it is +governed by this License along with a term that is a further +restriction, you may remove that term. If a license document contains +a further restriction but permits relicensing or conveying under this +License, you may add to a covered work material governed by the terms +of that license document, provided that the further restriction does +not survive such relicensing or conveying. + + If you add terms to a covered work in accord with this section, you +must place, in the relevant source files, a statement of the +additional terms that apply to those files, or a notice indicating +where to find the applicable terms. + + Additional terms, permissive or non-permissive, may be stated in the +form of a separately written license, or stated as exceptions; +the above requirements apply either way. + + 8. Termination. + + You may not propagate or modify a covered work except as expressly +provided under this License. Any attempt otherwise to propagate or +modify it is void, and will automatically terminate your rights under +this License (including any patent licenses granted under the third +paragraph of section 11). + + However, if you cease all violation of this License, then your +license from a particular copyright holder is reinstated (a) +provisionally, unless and until the copyright holder explicitly and +finally terminates your license, and (b) permanently, if the copyright +holder fails to notify you of the violation by some reasonable means +prior to 60 days after the cessation. + + Moreover, your license from a particular copyright holder is +reinstated permanently if the copyright holder notifies you of the +violation by some reasonable means, this is the first time you have +received notice of violation of this License (for any work) from that +copyright holder, and you cure the violation prior to 30 days after +your receipt of the notice. + + Termination of your rights under this section does not terminate the +licenses of parties who have received copies or rights from you under +this License. If your rights have been terminated and not permanently +reinstated, you do not qualify to receive new licenses for the same +material under section 10. + + 9. Acceptance Not Required for Having Copies. + + You are not required to accept this License in order to receive or +run a copy of the Program. Ancillary propagation of a covered work +occurring solely as a consequence of using peer-to-peer transmission +to receive a copy likewise does not require acceptance. However, +nothing other than this License grants you permission to propagate or +modify any covered work. These actions infringe copyright if you do +not accept this License. Therefore, by modifying or propagating a +covered work, you indicate your acceptance of this License to do so. + + 10. Automatic Licensing of Downstream Recipients. + + Each time you convey a covered work, the recipient automatically +receives a license from the original licensors, to run, modify and +propagate that work, subject to this License. You are not responsible +for enforcing compliance by third parties with this License. + + An "entity transaction" is a transaction transferring control of an +organization, or substantially all assets of one, or subdividing an +organization, or merging organizations. If propagation of a covered +work results from an entity transaction, each party to that +transaction who receives a copy of the work also receives whatever +licenses to the work the party's predecessor in interest had or could +give under the previous paragraph, plus a right to possession of the +Corresponding Source of the work from the predecessor in interest, if +the predecessor has it or can get it with reasonable efforts. + + You may not impose any further restrictions on the exercise of the +rights granted or affirmed under this License. For example, you may +not impose a license fee, royalty, or other charge for exercise of +rights granted under this License, and you may not initiate litigation +(including a cross-claim or counterclaim in a lawsuit) alleging that +any patent claim is infringed by making, using, selling, offering for +sale, or importing the Program or any portion of it. + + 11. Patents. + + A "contributor" is a copyright holder who authorizes use under this +License of the Program or a work on which the Program is based. The +work thus licensed is called the contributor's "contributor version". + + A contributor's "essential patent claims" are all patent claims +owned or controlled by the contributor, whether already acquired or +hereafter acquired, that would be infringed by some manner, permitted +by this License, of making, using, or selling its contributor version, +but do not include claims that would be infringed only as a +consequence of further modification of the contributor version. For +purposes of this definition, "control" includes the right to grant +patent sublicenses in a manner consistent with the requirements of +this License. + + Each contributor grants you a non-exclusive, worldwide, royalty-free +patent license under the contributor's essential patent claims, to +make, use, sell, offer for sale, import and otherwise run, modify and +propagate the contents of its contributor version. + + In the following three paragraphs, a "patent license" is any express +agreement or commitment, however denominated, not to enforce a patent +(such as an express permission to practice a patent or covenant not to +sue for patent infringement). To "grant" such a patent license to a +party means to make such an agreement or commitment not to enforce a +patent against the party. + + If you convey a covered work, knowingly relying on a patent license, +and the Corresponding Source of the work is not available for anyone +to copy, free of charge and under the terms of this License, through a +publicly available network server or other readily accessible means, +then you must either (1) cause the Corresponding Source to be so +available, or (2) arrange to deprive yourself of the benefit of the +patent license for this particular work, or (3) arrange, in a manner +consistent with the requirements of this License, to extend the patent +license to downstream recipients. "Knowingly relying" means you have +actual knowledge that, but for the patent license, your conveying the +covered work in a country, or your recipient's use of the covered work +in a country, would infringe one or more identifiable patents in that +country that you have reason to believe are valid. + + If, pursuant to or in connection with a single transaction or +arrangement, you convey, or propagate by procuring conveyance of, a +covered work, and grant a patent license to some of the parties +receiving the covered work authorizing them to use, propagate, modify +or convey a specific copy of the covered work, then the patent license +you grant is automatically extended to all recipients of the covered +work and works based on it. + + A patent license is "discriminatory" if it does not include within +the scope of its coverage, prohibits the exercise of, or is +conditioned on the non-exercise of one or more of the rights that are +specifically granted under this License. You may not convey a covered +work if you are a party to an arrangement with a third party that is +in the business of distributing software, under which you make payment +to the third party based on the extent of your activity of conveying +the work, and under which the third party grants, to any of the +parties who would receive the covered work from you, a discriminatory +patent license (a) in connection with copies of the covered work +conveyed by you (or copies made from those copies), or (b) primarily +for and in connection with specific products or compilations that +contain the covered work, unless you entered into that arrangement, +or that patent license was granted, prior to 28 March 2007. + + Nothing in this License shall be construed as excluding or limiting +any implied license or other defenses to infringement that may +otherwise be available to you under applicable patent law. + + 12. No Surrender of Others' Freedom. + + If conditions are imposed on you (whether by court order, agreement or +otherwise) that contradict the conditions of this License, they do not +excuse you from the conditions of this License. If you cannot convey a +covered work so as to satisfy simultaneously your obligations under this +License and any other pertinent obligations, then as a consequence you may +not convey it at all. For example, if you agree to terms that obligate you +to collect a royalty for further conveying from those to whom you convey +the Program, the only way you could satisfy both those terms and this +License would be to refrain entirely from conveying the Program. + + 13. Use with the GNU Affero General Public License. + + Notwithstanding any other provision of this License, you have +permission to link or combine any covered work with a work licensed +under version 3 of the GNU Affero General Public License into a single +combined work, and to convey the resulting work. The terms of this +License will continue to apply to the part which is the covered work, +but the special requirements of the GNU Affero General Public License, +section 13, concerning interaction through a network will apply to the +combination as such. + + 14. Revised Versions of this License. + + The Free Software Foundation may publish revised and/or new versions of +the GNU General Public License from time to time. Such new versions will +be similar in spirit to the present version, but may differ in detail to +address new problems or concerns. + + Each version is given a distinguishing version number. If the +Program specifies that a certain numbered version of the GNU General +Public License "or any later version" applies to it, you have the +option of following the terms and conditions either of that numbered +version or of any later version published by the Free Software +Foundation. If the Program does not specify a version number of the +GNU General Public License, you may choose any version ever published +by the Free Software Foundation. + + If the Program specifies that a proxy can decide which future +versions of the GNU General Public License can be used, that proxy's +public statement of acceptance of a version permanently authorizes you +to choose that version for the Program. + + Later license versions may give you additional or different +permissions. However, no additional obligations are imposed on any +author or copyright holder as a result of your choosing to follow a +later version. + + 15. Disclaimer of Warranty. + + THERE IS NO WARRANTY FOR THE PROGRAM, TO THE EXTENT PERMITTED BY +APPLICABLE LAW. EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT +HOLDERS AND/OR OTHER PARTIES PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY +OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, +THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR +PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE PROGRAM +IS WITH YOU. SHOULD THE PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF +ALL NECESSARY SERVICING, REPAIR OR CORRECTION. + + 16. Limitation of Liability. + + IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING +WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MODIFIES AND/OR CONVEYS +THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, INCLUDING ANY +GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE +USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED TO LOSS OF +DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD +PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER PROGRAMS), +EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF +SUCH DAMAGES. + + 17. Interpretation of Sections 15 and 16. + + If the disclaimer of warranty and limitation of liability provided +above cannot be given local legal effect according to their terms, +reviewing courts shall apply local law that most closely approximates +an absolute waiver of all civil liability in connection with the +Program, unless a warranty or assumption of liability accompanies a +copy of the Program in return for a fee. + + END OF TERMS AND CONDITIONS + + How to Apply These Terms to Your New Programs + + If you develop a new program, and you want it to be of the greatest +possible use to the public, the best way to achieve this is to make it +free software which everyone can redistribute and change under these terms. + + To do so, attach the following notices to the program. It is safest +to attach them to the start of each source file to most effectively +state the exclusion of warranty; and each file should have at least +the "copyright" line and a pointer to where the full notice is found. + + + Copyright (C) + + This program is free software: you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation, either version 3 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program. If not, see . + +Also add information on how to contact you by electronic and paper mail. + + If the program does terminal interaction, make it output a short +notice like this when it starts in an interactive mode: + + Copyright (C) + This program comes with ABSOLUTELY NO WARRANTY; for details type `show w'. + This is free software, and you are welcome to redistribute it + under certain conditions; type `show c' for details. + +The hypothetical commands `show w' and `show c' should show the appropriate +parts of the General Public License. Of course, your program's commands +might be different; for a GUI interface, you would use an "about box". + + You should also get your employer (if you work as a programmer) or school, +if any, to sign a "copyright disclaimer" for the program, if necessary. +For more information on this, and how to apply and follow the GNU GPL, see +. + + The GNU General Public License does not permit incorporating your program +into proprietary programs. If your program is a subroutine library, you +may consider it more useful to permit linking proprietary applications with +the library. If this is what you want to do, use the GNU Lesser General +Public License instead of this License. But first, please read +. diff --git a/build.gradle b/build.gradle index cb93632..13c8cbb 100644 --- a/build.gradle +++ b/build.gradle @@ -6,7 +6,7 @@ plugins { } group = 'com.magmaguy' -version = '1.1.0' +version = '1.6.11-SNAPSHOT' repositories { mavenCentral() @@ -27,14 +27,25 @@ repositories { //CloudCommands maven { url = 'https://oss.sonatype.org/content/repositories/snapshots' } + //EliteMobs + maven { url = 'https://s01.oss.sonatype.org/content/repositories/snapshots' } + + // carm start - Support MMOItems and MythicMobs + //MMOItems + maven { url = 'https://nexus.phoenixdevt.fr/repository/maven-public/' } + //MythicMobs + maven { url = 'https://mvn.lumine.io/repository/maven-public/' } + // carm end - Support MMOItems and MythicMobs } dependencies { - compileOnly 'org.spigotmc:spigot-api:1.19-R0.1-SNAPSHOT' + compileOnly 'org.spigotmc:spigot-api:1.21-R0.1-SNAPSHOT' //BStats API implementation group: 'org.bstats', name: 'bstats-bukkit', version: '2.2.1' //WorldGuard API - compileOnly group: 'com.sk89q.worldedit', name: 'worldedit-bukkit', version: '7.2.10' + compileOnly group: 'com.sk89q.worldguard', name: 'worldguard-bukkit', version: '7.0.7' + //WorldEdit API + compileOnly group: 'com.sk89q.worldedit', name: 'worldedit-bukkit', version: '7.2.14' //lombok compileOnly 'org.projectlombok:lombok:1.18.22' annotationProcessor 'org.projectlombok:lombok:1.18.22' @@ -50,6 +61,17 @@ dependencies { implementation 'org.apache.commons:commons-lang3:3.9' //reflections - used for config initialization implementation group: 'org.reflections', name: 'reflections', version: '0.9.12' + //EliteMobs + compileOnly group: 'com.magmaguy', name: 'EliteMobs', version: '8.3.12-SNAPSHOT' + + // carm start - Support MMOItems and MythicMobs + //MythicMobs + compileOnly group: 'io.lumine', name: 'Mythic-Dist', version: '5.2.1' + //MythicLib + compileOnly group: 'io.lumine', name: 'MythicLib-dist', version: '1.5.2-SNAPSHOT' + //MMOItems + compileOnly group: 'net.Indyuce', name: 'MMOItems-API', version: '6.9.2-SNAPSHOT' + // carm end - Support MMOItems and MythicMobs } @@ -89,4 +111,53 @@ ext { processResources { filter org.apache.tools.ant.filters.ReplaceTokens, tokens: resourceTokens -} \ No newline at end of file +} + +//sonatype repo +task javadocJar(type: Jar) { + classifier = 'javadoc' + from javadoc +} + +task sourcesJar(type: Jar) { + classifier = 'sources' + from sourceSets.main.allSource +} + +artifacts { + archives javadocJar, sourcesJar +} + +ext.isReleaseVersion = !version.endsWith("SNAPSHOT") + +publishing { + repositories { + maven { + def releaseRepo = "https://s01.oss.sonatype.org/service/local/staging/deploy/maven2/" + def snapshotRepo = "https://s01.oss.sonatype.org/content/repositories/snapshots/" + url = isReleaseVersion ? releaseRepo : snapshotRepo + credentials { + username = project.hasProperty('ossrhUsername') ? ossrhUsername : "Unknown user" + password = project.hasProperty('ossrhPassword') ? ossrhPassword : "Unknown password" + } + } + } + + publications { + mavenJava(MavenPublication) { + pom { + groupId = 'com.magmaguy' + name = 'betterstructures' + description = 'BetterStructures repo' + url = 'https://example.com/' + from components.java + licenses { + license { + name = 'GPLV3' + url = 'https://www.gnu.org/licenses/gpl-3.0.en.html' + } + } + } + } + } +} diff --git a/src/main/java/com/magmaguy/betterstructures/BetterStructures.java b/src/main/java/com/magmaguy/betterstructures/BetterStructures.java index 6b61ada..3c13be7 100644 --- a/src/main/java/com/magmaguy/betterstructures/BetterStructures.java +++ b/src/main/java/com/magmaguy/betterstructures/BetterStructures.java @@ -5,8 +5,14 @@ import com.magmaguy.betterstructures.config.ValidWorldsConfig; import com.magmaguy.betterstructures.config.generators.GeneratorConfig; import com.magmaguy.betterstructures.config.schematics.SchematicConfig; +import com.magmaguy.betterstructures.config.treasures.TreasureConfig; +import com.magmaguy.betterstructures.configurationimporter.Import; import com.magmaguy.betterstructures.listeners.NewChunkLoadEvent; import com.magmaguy.betterstructures.schematics.SchematicContainer; +import com.magmaguy.betterstructures.thirdparty.WorldGuard; +import com.magmaguy.betterstructures.util.InfoMessage; +import com.magmaguy.betterstructures.util.VersionChecker; +import org.bstats.bukkit.Metrics; import org.bukkit.Bukkit; import org.bukkit.plugin.java.JavaPlugin; @@ -17,10 +23,16 @@ public final class BetterStructures extends JavaPlugin { @Override public void onEnable() { MetadataHandler.PLUGIN = this; + new InfoMessage(" ____ __ __ _____ __ __ "); + new InfoMessage(" / __ )___ / /_/ /____ _____/ ___// /________ _______/ /___ __________ _____"); + new InfoMessage(" / __ / _ \\/ __/ __/ _ \\/ ___/\\__ \\/ __/ ___/ / / / ___/ __/ / / / ___/ _ \\/ ___/"); + new InfoMessage(" / /_/ / __/ /_/ /_/ __/ / ___/ / /_/ / / /_/ / /__/ /_/ /_/ / / / __(__ ) "); + new InfoMessage("/_____/\\___/\\__/\\__/\\___/_/ /____/\\__/_/ \\__,_/\\___/\\__/\\__,_/_/ \\___/____/"); // Plugin startup logic - Bukkit.getLogger().info("[BetterStructures] Initialized!"); + Bukkit.getLogger().info("[BetterStructures] Initialized version " + this.getDescription().getVersion() + "!"); Bukkit.getPluginManager().registerEvents(new NewChunkLoadEvent(), this); Bukkit.getPluginManager().registerEvents(new ValidWorldsConfig.ValidWorldsConfigEvents(), this); + Bukkit.getPluginManager().registerEvents(new VersionChecker.VersionCheckerEvents(), this); try { this.getConfig().save("config.yml"); } catch (IOException e) { @@ -28,9 +40,31 @@ public void onEnable() { } DefaultConfig.initializeConfig(); ValidWorldsConfig.initializeConfig(); + //Creates import folder if one doesn't exist, imports any content inside + Import.initialize(); + + new TreasureConfig(); new GeneratorConfig(); new SchematicConfig(); new CommandHandler(); + VersionChecker.checkPluginVersion(); + if (Bukkit.getPluginManager().getPlugin("WorldGuard") != null && + Bukkit.getPluginManager().getPlugin("EliteMobs") != null) + Bukkit.getPluginManager().registerEvents(new WorldGuard(), this); + new Metrics(this, 19523); + } + + @Override + public void onLoad() { + try { + if (Bukkit.getPluginManager().getPlugin("WorldGuard") != null && + Bukkit.getPluginManager().getPlugin("EliteMobs") != null) + WorldGuard.initializeFlag(); + else + new InfoMessage("WorldGuard is not enabled! WorldGuard is recommended when using the EliteMobs integration."); + } catch (Exception ex) { + new InfoMessage("WorldGuard could not be detected! Some BetterStructures features use WorldGuard, and they will not work until it is installed."); + } } @Override diff --git a/src/main/java/com/magmaguy/betterstructures/api/BuildPlaceEvent.java b/src/main/java/com/magmaguy/betterstructures/api/BuildPlaceEvent.java new file mode 100644 index 0000000..d6a2824 --- /dev/null +++ b/src/main/java/com/magmaguy/betterstructures/api/BuildPlaceEvent.java @@ -0,0 +1,47 @@ +package com.magmaguy.betterstructures.api; + +import com.magmaguy.betterstructures.buildingfitter.FitAnything; +import org.bukkit.event.Cancellable; +import org.bukkit.event.Event; +import org.bukkit.event.HandlerList; +import org.jetbrains.annotations.NotNull; + +public class BuildPlaceEvent extends Event implements Cancellable { + private static final HandlerList handlers = new HandlerList(); + private boolean isCancelled = false; + private final FitAnything fitAnything; + + public BuildPlaceEvent(FitAnything fitAnything) { + this.fitAnything = fitAnything; + } + + @NotNull + @Override + public HandlerList getHandlers() { + return handlers; + } + + @Override + public boolean isCancelled() { + return this.isCancelled; + } + + @Override + public void setCancelled(boolean b) { + this.isCancelled = b; + } + + /** + * {@FitAnything} contains all of the data related to the schematic that is about to get pasted. + * + * @return The key object involved. + */ + public FitAnything getFitAnything() { + return fitAnything; + } + + public static HandlerList getHandlerList() { + return handlers; + } + +} diff --git a/src/main/java/com/magmaguy/betterstructures/api/ChestFillEvent.java b/src/main/java/com/magmaguy/betterstructures/api/ChestFillEvent.java new file mode 100644 index 0000000..c47e6bb --- /dev/null +++ b/src/main/java/com/magmaguy/betterstructures/api/ChestFillEvent.java @@ -0,0 +1,52 @@ +package com.magmaguy.betterstructures.api; + +import org.bukkit.block.Container; +import org.bukkit.event.Cancellable; +import org.bukkit.event.Event; +import org.bukkit.event.HandlerList; +import org.jetbrains.annotations.NotNull; + +public class ChestFillEvent extends Event implements Cancellable { + + private static final HandlerList handlers = new HandlerList(); + private boolean isCancelled = false; + private Container container; + + public ChestFillEvent(Container container) { + this.container = container; + } + + @NotNull + @Override + public HandlerList getHandlers() { + return handlers; + } + + @Override + public boolean isCancelled() { + return this.isCancelled; + } + + @Override + public void setCancelled(boolean b) { + this.isCancelled = b; + } + + /** + * Returns the container in this event. This chest has the inventory snapshot modified, and if the + * event is not cancelled it will force an update. + *

+ * If you want to modify the chest contents, simply #addItem(itemStack) or #removeItem(itemStack) to the + * Inventory.getSnapshotInventory() + * + * @return The container to be filled + */ + public Container getContainer() { + return container; + } + + public static HandlerList getHandlerList() { + return handlers; + } + +} diff --git a/src/main/java/com/magmaguy/betterstructures/buildingfitter/FitAirBuilding.java b/src/main/java/com/magmaguy/betterstructures/buildingfitter/FitAirBuilding.java index 12a4140..2087ac7 100644 --- a/src/main/java/com/magmaguy/betterstructures/buildingfitter/FitAirBuilding.java +++ b/src/main/java/com/magmaguy/betterstructures/buildingfitter/FitAirBuilding.java @@ -15,12 +15,14 @@ public class FitAirBuilding extends FitAnything { public FitAirBuilding(Chunk chunk, SchematicContainer schematicContainer) { + super.structureType = GeneratorConfigFields.StructureType.SKY; this.schematicContainer = schematicContainer; this.schematicClipboard = schematicContainer.getClipboard(); scan(chunk); } public FitAirBuilding(Chunk chunk) { + super.structureType = GeneratorConfigFields.StructureType.SKY; scan(chunk); } diff --git a/src/main/java/com/magmaguy/betterstructures/buildingfitter/FitAnything.java b/src/main/java/com/magmaguy/betterstructures/buildingfitter/FitAnything.java index e9ab678..5a461f9 100644 --- a/src/main/java/com/magmaguy/betterstructures/buildingfitter/FitAnything.java +++ b/src/main/java/com/magmaguy/betterstructures/buildingfitter/FitAnything.java @@ -1,13 +1,19 @@ package com.magmaguy.betterstructures.buildingfitter; -import com.magmaguy.betterstructures.MetadataHandler; +import com.magmaguy.betterstructures.api.BuildPlaceEvent; +import com.magmaguy.betterstructures.api.ChestFillEvent; import com.magmaguy.betterstructures.buildingfitter.util.FitUndergroundDeepBuilding; import com.magmaguy.betterstructures.buildingfitter.util.LocationProjector; import com.magmaguy.betterstructures.buildingfitter.util.SchematicPicker; +import com.magmaguy.betterstructures.config.DefaultConfig; import com.magmaguy.betterstructures.config.generators.GeneratorConfigFields; import com.magmaguy.betterstructures.schematics.SchematicContainer; +import com.magmaguy.betterstructures.thirdparty.EliteMobs; +import com.magmaguy.betterstructures.thirdparty.MythicMobs; +import com.magmaguy.betterstructures.thirdparty.WorldGuard; import com.magmaguy.betterstructures.util.SpigotMessage; import com.magmaguy.betterstructures.util.SurfaceMaterials; +import com.magmaguy.betterstructures.util.VersionChecker; import com.magmaguy.betterstructures.util.WarningMessage; import com.magmaguy.betterstructures.worldedit.Schematic; import com.sk89q.worldedit.WorldEditException; @@ -15,6 +21,7 @@ import com.sk89q.worldedit.extent.clipboard.Clipboard; import com.sk89q.worldedit.math.BlockVector3; import com.sk89q.worldedit.world.block.BlockState; +import lombok.Getter; import org.bukkit.Bukkit; import org.bukkit.Chunk; import org.bukkit.Location; @@ -22,26 +29,31 @@ import org.bukkit.block.Block; import org.bukkit.block.Container; import org.bukkit.block.data.BlockData; -import org.bukkit.entity.Entity; -import org.bukkit.entity.LivingEntity; -import org.bukkit.entity.Player; -import org.bukkit.scheduler.BukkitRunnable; +import org.bukkit.entity.*; import org.bukkit.util.Vector; import java.util.HashMap; import java.util.HashSet; +import java.util.Map; import java.util.Set; public class FitAnything { - protected SchematicContainer schematicContainer; - protected final double startingScore = 100; + public static boolean worldGuardWarn = false; protected final int searchRadius = 1; protected final int scanStep = 3; + @Getter + protected SchematicContainer schematicContainer; + protected double startingScore = 100; + @Getter protected Clipboard schematicClipboard = null; + @Getter protected Vector schematicOffset; //At 10% it is assumed a fit is so bad it's better just to skip protected double highestScore = 10; + @Getter protected Location location = null; + protected GeneratorConfigFields.StructureType structureType; + Material pedestalMaterial = null; public static void commandBasedCreation(Chunk chunk, GeneratorConfigFields.StructureType structureType, SchematicContainer container) { switch (structureType) { @@ -71,133 +83,135 @@ protected void setSchematicFilename(Location location, GeneratorConfigFields.Str schematicClipboard = schematicContainer.getClipboard(); } - protected void paste(Location location) { + BuildPlaceEvent buildPlaceEvent = new BuildPlaceEvent(this); + Bukkit.getServer().getPluginManager().callEvent(buildPlaceEvent); + if (buildPlaceEvent.isCancelled()) return; + FitAnything fitAnything = this; - new BukkitRunnable() { - @Override - public void run() { - //Set pedestal material before the paste so bedrock blocks get replaced correctly - assignPedestalMaterial(location); - if (pedestalMaterial == null) - switch (location.getWorld().getEnvironment()) { - case NORMAL: - case CUSTOM: - pedestalMaterial = Material.STONE; - break; - case NETHER: - pedestalMaterial = Material.NETHERRACK; - break; - case THE_END: - pedestalMaterial = Material.END_STONE; - break; - default: - pedestalMaterial = Material.STONE; - } + //Set pedestal material before the paste so bedrock blocks get replaced correctly + assignPedestalMaterial(location); + if (pedestalMaterial == null) + switch (location.getWorld().getEnvironment()) { + case NORMAL: + case CUSTOM: + pedestalMaterial = Material.STONE; + break; + case NETHER: + pedestalMaterial = Material.NETHERRACK; + break; + case THE_END: + pedestalMaterial = Material.END_STONE; + break; + default: + pedestalMaterial = Material.STONE; + } - //These blocks are dynamic and get replaced with world contents, need to be replaced back after the paste to preserve the mechanic - Set barrierBlocks = new HashSet<>(); - Set bedrockBlocks = new HashSet<>(); - BlockData barrierBlock = null; - BlockData bedrockBlock = null; + //These blocks are dynamic and get replaced with world contents, need to be replaced back after the paste to preserve the mechanic + Set barrierBlocks = new HashSet<>(); + Set bedrockBlocks = new HashSet<>(); + BlockData barrierBlock = null; + BlockData bedrockBlock = null; - //adjusts the offset just for the prescan, not needed for worldedit as that figures it out on its own - Location adjustedLocation = location.clone().add(schematicOffset); - for (int x = 0; x < schematicClipboard.getDimensions().getX(); x++) - for (int y = 0; y < schematicClipboard.getDimensions().getY(); y++) - for (int z = 0; z < schematicClipboard.getDimensions().getZ(); z++) { - BlockVector3 adjustedClipboardLocation = BlockVector3.at( - x + schematicClipboard.getMinimumPoint().getX(), - y + schematicClipboard.getMinimumPoint().getY(), - z + schematicClipboard.getMinimumPoint().getZ()); - BlockState blockState = schematicClipboard.getBlock(adjustedClipboardLocation); - Material material = BukkitAdapter.adapt(blockState.getBlockType()); - Block worldBlock = adjustedLocation.clone().add(new Vector(x, y, z)).getBlock(); - if (material == Material.BARRIER) { - //special behavior: do not replace - try { - if (barrierBlock == null) - barrierBlock = BukkitAdapter.adapt(schematicClipboard.getBlock(adjustedClipboardLocation)); - schematicClipboard.setBlock(adjustedClipboardLocation, BukkitAdapter.adapt(worldBlock.getBlockData())); - barrierBlocks.add(adjustedClipboardLocation); - } catch (WorldEditException e) { - throw new RuntimeException(e); - } - } else if (material == Material.BEDROCK) { - //special behavior: replace if air - try { - if (bedrockBlock == null) - bedrockBlock = BukkitAdapter.adapt(schematicClipboard.getBlock(adjustedClipboardLocation)); + //adjusts the offset just for the prescan, not needed for worldedit as that figures it out on its own + Location adjustedLocation = location.clone().add(schematicOffset); + for (int x = 0; x < schematicClipboard.getDimensions().getX(); x++) + for (int y = 0; y < schematicClipboard.getDimensions().getY(); y++) + for (int z = 0; z < schematicClipboard.getDimensions().getZ(); z++) { + BlockVector3 adjustedClipboardLocation = BlockVector3.at( + x + schematicClipboard.getMinimumPoint().getX(), + y + schematicClipboard.getMinimumPoint().getY(), + z + schematicClipboard.getMinimumPoint().getZ()); + BlockState blockState = schematicClipboard.getBlock(adjustedClipboardLocation); + Material material = BukkitAdapter.adapt(blockState.getBlockType()); + Block worldBlock = adjustedLocation.clone().add(new Vector(x, y, z)).getBlock(); + if (material == Material.BARRIER) { + //special behavior: do not replace + try { + if (barrierBlock == null) + barrierBlock = BukkitAdapter.adapt(schematicClipboard.getBlock(adjustedClipboardLocation)); + schematicClipboard.setBlock(adjustedClipboardLocation, BukkitAdapter.adapt(worldBlock.getBlockData())); + barrierBlocks.add(adjustedClipboardLocation); + } catch (WorldEditException e) { + throw new RuntimeException(e); + } + } else if (material == Material.BEDROCK) { + //special behavior: replace if air + try { + if (bedrockBlock == null) + bedrockBlock = BukkitAdapter.adapt(schematicClipboard.getBlock(adjustedClipboardLocation)); - worldBlock = adjustedLocation.clone().add(new Vector(x, y, z)).getBlock(); - if (worldBlock.getType().isAir() || worldBlock.isLiquid()) { - //Case for air - replace with filler block - worldBlock.setType(pedestalMaterial); - } - //Case for any solid block - do not replace world block - schematicClipboard.setBlock(adjustedClipboardLocation, BukkitAdapter.adapt(worldBlock.getBlockData())); - bedrockBlocks.add(adjustedClipboardLocation); - } catch (WorldEditException e) { - throw new RuntimeException(e); - } + worldBlock = adjustedLocation.clone().add(new Vector(x, y, z)).getBlock(); + if (worldBlock.getType().isAir() || worldBlock.isLiquid()) { + //Case for air - replace with filler block + worldBlock.setType(pedestalMaterial); } + //Case for any solid block - do not replace world block + schematicClipboard.setBlock(adjustedClipboardLocation, BukkitAdapter.adapt(worldBlock.getBlockData())); + bedrockBlocks.add(adjustedClipboardLocation); + } catch (WorldEditException e) { + throw new RuntimeException(e); } - - - Schematic.paste(schematicClipboard, location); - for (Player player : Bukkit.getOnlinePlayers()) { - if (player.hasPermission("betterstructures.warn")) - player.spigot().sendMessage( - SpigotMessage.commandHoverMessage("[BetterStructures] New building generated! Click to teleport.", - "Click to teleport to " + location.toString(), - "/tp " + location.getBlockX() + " " + location.getBlockY() + " " + location.getBlockZ()) - ); - } - for (BlockVector3 blockVector3 : barrierBlocks) { - try { - schematicClipboard.setBlock(blockVector3, BukkitAdapter.adapt(barrierBlock)); - } catch (WorldEditException e) { - throw new RuntimeException(e); } } - for (BlockVector3 blockVector3 : bedrockBlocks) { - try { - schematicClipboard.setBlock(blockVector3, BukkitAdapter.adapt(bedrockBlock)); - } catch (WorldEditException e) { - throw new RuntimeException(e); - } - } + Schematic.paste(schematicClipboard, location); + if (DefaultConfig.isNewBuildingWarn()) { + String structureTypeString = fitAnything.structureType.toString().toLowerCase().replace("_", " "); + for (Player player : Bukkit.getOnlinePlayers()) + if (player.hasPermission("betterstructures.warn")) + player.spigot().sendMessage( + SpigotMessage.commandHoverMessage("[BetterStructures] New " + structureTypeString + " building generated! Click to teleport. Do \"/betterstructures silent\" to stop getting warnings!", + "Click to teleport to " + location.getWorld().getName() + ", " + location.getBlockX() + ", " + location.getBlockY() + ", " + location.getBlockZ() + "\n Schem name: " + schematicContainer.getConfigFilename(), + "/betterstructures teleporttocoords " + location.getWorld().getName() + " " + location.getBlockX() + " " + location.getBlockY() + " " + location.getBlockZ()) + ); + } - if (!(fitAnything instanceof FitAirBuilding)) { - try { - addPedestal(location); - } catch (Exception exception) { - new WarningMessage("Failed to correctly assign pedestal material!", true); - } - try { - clearTrees(location); - } catch (Exception exception) { - new WarningMessage("Failed to correctly clear trees!", true); - } - } - try { - fillChests(); - } catch (Exception exception) { - new WarningMessage("Failed to correctly fill chests!", true); - } - try { - spawnEntities(); - } catch (Exception exception) { - new WarningMessage("Failed to correctly spawn entities!", true); - } + for (BlockVector3 blockVector3 : barrierBlocks) { + try { + schematicClipboard.setBlock(blockVector3, BukkitAdapter.adapt(barrierBlock)); + } catch (WorldEditException e) { + throw new RuntimeException(e); } - }.runTaskLater(MetadataHandler.PLUGIN, 0); + } - } + for (BlockVector3 blockVector3 : bedrockBlocks) { + try { + schematicClipboard.setBlock(blockVector3, BukkitAdapter.adapt(bedrockBlock)); + } catch (WorldEditException e) { + throw new RuntimeException(e); + } + } - Material pedestalMaterial = null; + if (!(fitAnything instanceof FitAirBuilding)) { + try { + addPedestal(location); + } catch (Exception exception) { + new WarningMessage("Failed to correctly assign pedestal material!"); + exception.printStackTrace(); + } + try { + clearTrees(location); + } catch (Exception exception) { + new WarningMessage("Failed to correctly clear trees!"); + exception.printStackTrace(); + } + } + try { + fillChests(); + } catch (Exception exception) { + new WarningMessage("Failed to correctly fill chests!"); + exception.printStackTrace(); + } + try { + spawnEntities(); + } catch (Exception exception) { + new WarningMessage("Failed to correctly spawn entities!"); + //exception.printStackTrace(); + } + + } private void assignPedestalMaterial(Location location) { if (this instanceof FitAirBuilding) return; @@ -249,7 +263,6 @@ private void addPedestal(Location location) { } } - private void clearTrees(Location location) { Location highestCorner = location.clone().add(schematicOffset).add(new Vector(0, schematicClipboard.getDimensions().getY(), 0)); boolean detectedTreeElement = true; @@ -268,10 +281,24 @@ private void clearTrees(Location location) { } private void fillChests() { - for (Vector chestPosition : schematicContainer.getChestLocations()) { - Location chestLocation = LocationProjector.project(location, schematicOffset, chestPosition); - schematicContainer.getGeneratorConfigFields().getChestContents().rollChestContents((Container) chestLocation.getBlock().getState()); - } + if (schematicContainer.getGeneratorConfigFields().getChestContents() != null) + for (Vector chestPosition : schematicContainer.getChestLocations()) { + Location chestLocation = LocationProjector.project(location, schematicOffset, chestPosition); + if (!(chestLocation.getBlock().getState() instanceof Container container)) { + new WarningMessage("Expected a container for " + chestLocation.getBlock().getType() + " but didn't get it. Skipping this loot!"); + continue; + } + + if (schematicContainer.getChestContents() != null) + schematicContainer.getChestContents().rollChestContents(container); + else + schematicContainer.getGeneratorConfigFields().getChestContents().rollChestContents(container); + + ChestFillEvent chestFillEvent = new ChestFillEvent(container); + Bukkit.getServer().getPluginManager().callEvent(chestFillEvent); + if (!chestFillEvent.isCancelled()) + container.update(true); + } } private void spawnEntities() { @@ -279,13 +306,51 @@ private void spawnEntities() { Location signLocation = LocationProjector.project(location, schematicOffset, entityPosition).clone(); signLocation.getBlock().setType(Material.AIR); //If mobs spawn in corners they might choke on adjacent walls - signLocation.clone().add(new Vector(0.5,0,0.5)); + signLocation.add(new Vector(0.5, 0, 0.5)); + //I think FAWE is messing with this + signLocation.getChunk().load(); Entity entity = signLocation.getWorld().spawnEntity(signLocation, schematicContainer.getVanillaSpawns().get(entityPosition)); entity.setPersistent(true); if (entity instanceof LivingEntity) { ((LivingEntity) entity).setRemoveWhenFarAway(false); } + + if (!VersionChecker.serverVersionOlderThan(21,0) && + entity.getType().equals(EntityType.END_CRYSTAL)) { + EnderCrystal enderCrystal = (EnderCrystal) entity; + enderCrystal.setShowingBottom(false); + } } - } + for (Vector elitePosition : schematicContainer.getEliteMobsSpawns().keySet()) { + Location eliteLocation = LocationProjector.project(location, schematicOffset, elitePosition).clone(); + eliteLocation.getBlock().setType(Material.AIR); + eliteLocation.add(new Vector(0.5, 0, 0.5)); + String bossFilename = schematicContainer.getEliteMobsSpawns().get(elitePosition); + //If the spawn fails then don't continue + if (!EliteMobs.Spawn(eliteLocation, bossFilename)) return; + Location lowestCorner = location.clone().add(schematicOffset); + Location highestCorner = lowestCorner.clone().add(new Vector(schematicClipboard.getRegion().getWidth() - 1, schematicClipboard.getRegion().getHeight(), schematicClipboard.getRegion().getLength() - 1)); + if (DefaultConfig.isProtectEliteMobsRegions() && + Bukkit.getPluginManager().getPlugin("WorldGuard") != null && + Bukkit.getPluginManager().getPlugin("EliteMobs") != null) { + WorldGuard.Protect(lowestCorner, highestCorner, bossFilename, eliteLocation); + } else { + if (!worldGuardWarn) { + worldGuardWarn = true; + new WarningMessage("You are not using WorldGuard, so BetterStructures could not protect a boss arena! Using WorldGuard is recommended to guarantee a fair combat experience."); + } + } + } + + // carm start - Support for MythicMobs + for (Map.Entry entry : schematicContainer.getMythicMobsSpawns().entrySet()) { + Location mobLocation = LocationProjector.project(location, schematicOffset, entry.getKey()).clone(); + mobLocation.getBlock().setType(Material.AIR); + //If the spawn fails then don't continue + if (!MythicMobs.Spawn(mobLocation, entry.getValue())) return; + } + // carm end - Support for MythicMobs + + } } diff --git a/src/main/java/com/magmaguy/betterstructures/buildingfitter/FitLiquidBuilding.java b/src/main/java/com/magmaguy/betterstructures/buildingfitter/FitLiquidBuilding.java index e7035fb..d4d03d8 100644 --- a/src/main/java/com/magmaguy/betterstructures/buildingfitter/FitLiquidBuilding.java +++ b/src/main/java/com/magmaguy/betterstructures/buildingfitter/FitLiquidBuilding.java @@ -4,7 +4,6 @@ import com.magmaguy.betterstructures.config.generators.GeneratorConfigFields; import com.magmaguy.betterstructures.schematics.SchematicContainer; import com.magmaguy.betterstructures.util.WorldEditUtils; -import org.bukkit.Bukkit; import org.bukkit.Chunk; import org.bukkit.Location; import org.bukkit.Material; @@ -14,12 +13,14 @@ public class FitLiquidBuilding extends FitAnything { //For commands public FitLiquidBuilding(Chunk chunk, SchematicContainer schematicContainer) { + super.structureType = GeneratorConfigFields.StructureType.LIQUID_SURFACE; this.schematicContainer = schematicContainer; this.schematicClipboard = schematicContainer.getClipboard(); scan(chunk); } public FitLiquidBuilding(Chunk chunk) { + super.structureType = GeneratorConfigFields.StructureType.LIQUID_SURFACE; scan(chunk); } diff --git a/src/main/java/com/magmaguy/betterstructures/buildingfitter/FitSurfaceBuilding.java b/src/main/java/com/magmaguy/betterstructures/buildingfitter/FitSurfaceBuilding.java index cc0e176..78568df 100644 --- a/src/main/java/com/magmaguy/betterstructures/buildingfitter/FitSurfaceBuilding.java +++ b/src/main/java/com/magmaguy/betterstructures/buildingfitter/FitSurfaceBuilding.java @@ -7,18 +7,21 @@ import com.magmaguy.betterstructures.util.WorldEditUtils; import org.bukkit.Chunk; import org.bukkit.Location; +import org.bukkit.World; import org.bukkit.util.Vector; public class FitSurfaceBuilding extends FitAnything { //For commands public FitSurfaceBuilding(Chunk chunk, SchematicContainer schematicContainer) { + super.structureType = GeneratorConfigFields.StructureType.SURFACE; this.schematicContainer = schematicContainer; this.schematicClipboard = schematicContainer.getClipboard(); scan(chunk); } public FitSurfaceBuilding(Chunk chunk) { + super.structureType = GeneratorConfigFields.StructureType.SURFACE; scan(chunk); } @@ -38,6 +41,11 @@ private void scan(Chunk chunk) { if (highestScore < 50) for (int chunkX = -searchRadius; chunkX < searchRadius + 1; chunkX++) { for (int chunkZ = -searchRadius; chunkZ < searchRadius + 1; chunkZ++) { + //Relief measure: instead of doing a 3x3 grid, this does a "+" shaped pattern search - may want to remove this some day, if not optimal + if (chunkX == -1 && chunkZ == -1 || + chunkX == 1 && chunkZ == 1 || + chunkX == -1 && chunkZ == 1 || + chunkX == 1 && chunkZ == -1) continue; chunkScan(originalLocation, chunkX, chunkZ); if (highestScore > 50) break; } @@ -57,6 +65,7 @@ private void scan(Chunk chunk) { private void chunkScan(Location originalLocation, int chunkX, int chunkZ) { Location iteratedLocation = originalLocation.clone().add(new Vector(chunkX * 16, 0, chunkZ * 16)); + if (originalLocation.getWorld().getEnvironment().equals(World.Environment.NETHER)) startingScore = 200; double score = Topology.scan(startingScore, scanStep, schematicClipboard, iteratedLocation, schematicOffset); //Continue to the next scan in case of poor fit diff --git a/src/main/java/com/magmaguy/betterstructures/buildingfitter/FitUndergroundBuilding.java b/src/main/java/com/magmaguy/betterstructures/buildingfitter/FitUndergroundBuilding.java index 78cd451..e178647 100644 --- a/src/main/java/com/magmaguy/betterstructures/buildingfitter/FitUndergroundBuilding.java +++ b/src/main/java/com/magmaguy/betterstructures/buildingfitter/FitUndergroundBuilding.java @@ -5,7 +5,10 @@ import com.magmaguy.betterstructures.config.generators.GeneratorConfigFields; import com.magmaguy.betterstructures.schematics.SchematicContainer; import com.magmaguy.betterstructures.util.WorldEditUtils; -import org.bukkit.*; +import org.bukkit.Chunk; +import org.bukkit.Location; +import org.bukkit.Material; +import org.bukkit.World; import org.bukkit.util.Vector; import java.util.concurrent.ThreadLocalRandom; @@ -14,19 +17,19 @@ public class FitUndergroundBuilding extends FitAnything { private int lowestY; private int highestY; - private GeneratorConfigFields.StructureType structureType; //For commands public FitUndergroundBuilding(Chunk chunk, SchematicContainer schematicContainer, int lowestY, int highestY, GeneratorConfigFields.StructureType structureType) { + super.structureType = structureType; this.lowestY = lowestY; this.highestY = highestY; this.schematicContainer = schematicContainer; this.schematicClipboard = schematicContainer.getClipboard(); - this.structureType = structureType; scan(chunk); } public FitUndergroundBuilding(Chunk chunk, int lowestY, int highestY, GeneratorConfigFields.StructureType structureType) { + super.structureType = structureType; this.lowestY = lowestY; this.highestY = highestY; this.structureType = structureType; diff --git a/src/main/java/com/magmaguy/betterstructures/buildingfitter/util/SchematicPicker.java b/src/main/java/com/magmaguy/betterstructures/buildingfitter/util/SchematicPicker.java index b678b6b..3ceeed3 100644 --- a/src/main/java/com/magmaguy/betterstructures/buildingfitter/util/SchematicPicker.java +++ b/src/main/java/com/magmaguy/betterstructures/buildingfitter/util/SchematicPicker.java @@ -3,7 +3,6 @@ import com.magmaguy.betterstructures.config.generators.GeneratorConfigFields; import com.magmaguy.betterstructures.schematics.SchematicContainer; import com.magmaguy.betterstructures.util.WeighedProbability; -import org.bukkit.Bukkit; import org.bukkit.Location; import java.util.ArrayList; @@ -15,7 +14,8 @@ public static SchematicContainer pick(Location naiveAnchorLocation, GeneratorCon List schematicContainers = new ArrayList<>(SchematicContainer.getSchematics().get(structureType)); if (schematicContainers.isEmpty()) return null; schematicContainers.removeIf(schematicContainer -> - !schematicContainer.isValidEnvironment(naiveAnchorLocation.getWorld().getEnvironment()) || + !schematicContainer.isValidWorld(naiveAnchorLocation.getWorld().getName()) || + !schematicContainer.isValidEnvironment(naiveAnchorLocation.getWorld().getEnvironment()) || !schematicContainer.isValidBiome(naiveAnchorLocation.getBlock().getBiome()) || !schematicContainer.isValidYLevel(naiveAnchorLocation.getBlockY())); if (schematicContainers.isEmpty()) return null; diff --git a/src/main/java/com/magmaguy/betterstructures/chests/ChestContents.java b/src/main/java/com/magmaguy/betterstructures/chests/ChestContents.java index 96c3e9a..a68a304 100644 --- a/src/main/java/com/magmaguy/betterstructures/chests/ChestContents.java +++ b/src/main/java/com/magmaguy/betterstructures/chests/ChestContents.java @@ -1,91 +1,193 @@ package com.magmaguy.betterstructures.chests; -import com.magmaguy.betterstructures.config.generators.GeneratorConfigFields; +import com.magmaguy.betterstructures.config.treasures.TreasureConfigFields; import com.magmaguy.betterstructures.util.ItemStackSerialization; import com.magmaguy.betterstructures.util.WarningMessage; +import com.magmaguy.betterstructures.util.WeighedProbability; import lombok.Getter; -import org.bukkit.Bukkit; +import net.Indyuce.mmoitems.MMOItems; +import net.Indyuce.mmoitems.api.item.mmoitem.MMOItem; import org.bukkit.Material; -import org.bukkit.block.Chest; import org.bukkit.block.Container; +import org.bukkit.configuration.MemorySection; import org.bukkit.inventory.ItemStack; import java.util.ArrayList; +import java.util.HashMap; import java.util.List; +import java.util.Map; +import java.util.concurrent.ThreadLocalRandom; public class ChestContents { @Getter - private List chestEntries = new ArrayList<>(); + private final List chestRarities = new ArrayList<>(); + private final TreasureConfigFields treasureConfigFields; /* - Entry format: - material=MATERIAL:amount=AMOUNT_MIN-AMOUNT_MAX:chance=CHANCE + Entry format: + - material: MATERIAL + amount: min-max + chance: chance + mmoitem: mmoitem entry goes here + serialized: serialized string goes here + info: information about the item goes here. Useful for a human-readable explanation of what the entry is if serialized */ - public ChestContents(List rawContents, GeneratorConfigFields generatorConfigFields) { - for (String string : rawContents) { - String[] sections = string.split(":"); + public ChestContents(TreasureConfigFields treasureConfigFields) { + this.treasureConfigFields = treasureConfigFields; + if (treasureConfigFields.getRawLoot() == null) return; + processRarities(treasureConfigFields.getRawLoot()); + } + + private Material getMaterial(String string) { + try { + return Material.getMaterial(string.toUpperCase()); + } catch (Exception exception) { + new WarningMessage("Invalid material detected! Problematic entry: " + string + " in configuration file " + treasureConfigFields.getFilename()); + return null; + } + } + + private double getWeight(String string) { + try { + return Double.parseDouble(string); + } catch (Exception exception) { + new WarningMessage("Invalid double value detected! Problematic entry: " + string + " in configuration file " + treasureConfigFields.getFilename()); + return -1; + } + } + + private void processRarities(Map rawChestEntries) { + for (Map.Entry entry : rawChestEntries.entrySet()) { + double weight = -1; + List chestEntries = null; + for (Map.Entry innerEntry : ((MemorySection) entry.getValue()).getValues(false).entrySet()) { + switch (innerEntry.getKey().toLowerCase()) { + case "weight" -> weight = getWeight(innerEntry.getValue().toString()); + case "items" -> chestEntries = processEntries((List>) innerEntry.getValue()); + default -> new WarningMessage("Failed to read key " + innerEntry.getKey() + " for configuration file " + treasureConfigFields.getFilename()); + } + } + if (weight > 0 && chestEntries != null) chestRarities.add(new ChestRarity(weight, chestEntries)); + } + } + + private ItemStack getSerializedItemStack(Map deserializedItemStack, String string) { + try { + return ItemStackSerialization.serializeItem(deserializedItemStack); + } catch (Exception ex) { + new WarningMessage("Invalid serialized value detected! Problematic entry: " + string + " for configuration file " + treasureConfigFields.getFilename()); + ex.printStackTrace(); + return null; + } + } + + private boolean getProcedurallyGeneratedEnchantments(String string) { + try { + return Boolean.parseBoolean(string); + } catch (Exception ex) { + new WarningMessage("Invalid boolean value detected! Problematic entry: " + string + " for configuration file " + treasureConfigFields.getFilename()); + ex.printStackTrace(); + return false; + } + } + + private ItemStack getMMOItemsItemStack(String string) { + try { + String[] args = string.split("@"); + MMOItems mmo = MMOItems.plugin; + MMOItem mmoitem = mmo.getMMOItem(mmo.getTypes().get(args[0]), args[1]); + if (mmoitem == null) throw new NullPointerException("mmo item is null"); + return mmoitem.newBuilder().build(); + } catch (Exception ex) { + new WarningMessage("Invalid mmo item detected! Problematic entry: " + string + " in " + treasureConfigFields.getFilename()); + return null; + } + } + + private List processEntries(List> rawChestEntries) { + List chestEntries = new ArrayList<>(); + for (Map rawChestEntry : rawChestEntries) { Material material = null; + int minAmount = -1; + int maxAmount = -1; + double weight = -1; + boolean procedurallyGeneratedEnchantments = false; ItemStack itemStack = null; - int amountMin = 1; - int amountMax = 1; - double chance = 1; - for (String section : sections) { - String[] subsection = section.split("="); - switch (subsection[0].toLowerCase()) { - case "material": + for (Map.Entry entry : rawChestEntry.entrySet()) { + String value = entry.getValue().toString(); + switch (entry.getKey().toLowerCase()) { + case "material" -> material = getMaterial(value); + case "amount" -> { try { - material = Material.getMaterial(subsection[1]); - } catch (Exception exception) { - new WarningMessage("Invalid material detected for generator " + generatorConfigFields.getFilename() + " ! Problematic entry: " + subsection[0]); - } - break; - case "serialized": - try { - itemStack = ItemStackSerialization.itemStackArrayFromBase64(subsection[1]); - } catch (Exception ex) { - new WarningMessage("Invalid serialized value detected for generator " + generatorConfigFields.getFilename() + " ! Problematic entry: " + subsection[0]); - continue; - } - break; - case "amount": - try { - if (subsection[1].contains("-")) { - String[] amounts = subsection[1].split("-"); - amountMin = Integer.parseInt(amounts[0]); - amountMax = Integer.parseInt(amounts[1]); + if (value.contains("-")) { + String[] amounts = value.split("-"); + minAmount = Integer.parseInt(amounts[0]); + maxAmount = Integer.parseInt(amounts[1]); } else { - amountMin = Integer.parseInt(subsection[1]); - amountMax = amountMin; + minAmount = Integer.parseInt(value); + maxAmount = minAmount; } } catch (Exception exception) { - new WarningMessage("Invalid amount detected for generator " + generatorConfigFields.getFilename() + " ! Problematic entry: " + subsection[0]); + new WarningMessage("Invalid amount detected! Problematic entry: " + value + " in file " + treasureConfigFields.getFilename()); } - break; - case "chance": - try { - chance = Double.parseDouble(subsection[1]); - } catch (Exception exception) { - new WarningMessage("Invalid chance detected for generator " + generatorConfigFields.getFilename() + " ! Problematic entry: " + subsection[0]); - } - break; - default: - new WarningMessage("Failed to parse chest entry for generator " + generatorConfigFields.getFilename() + " ! Problematic entry: " + subsection[0]); + } + case "weight" -> weight = getWeight(value); + //Support for MMOItems - og code by Carm + case "mmoitem", "mmoitems" -> itemStack = getMMOItemsItemStack(value); + case "serialized" -> itemStack = getSerializedItemStack((Map) entry.getValue(), value); + case "procedurallygenerateenchantments" -> procedurallyGeneratedEnchantments = getProcedurallyGeneratedEnchantments(value); + case "info" -> { + } + default -> new WarningMessage("Failed to read key " + entry.getKey() + " for configuration file " + treasureConfigFields.getFilename()); } } - if (material != null || itemStack != null) { - ChestEntry chestEntry = new ChestEntry(material, chance, amountMin, amountMax, itemStack); + ChestEntry chestEntry = new ChestEntry(material, weight, minAmount, maxAmount, itemStack, procedurallyGeneratedEnchantments, treasureConfigFields); chestEntries.add(chestEntry); } } + return chestEntries; } public void rollChestContents(Container chest) { - for (ChestEntry chestEntry : chestEntries) { - ItemStack itemStack = chestEntry.rollEntry(); - if (itemStack == null) continue; - chest.getSnapshotInventory().addItem(itemStack); - chest.update(true); + int amount = (int) Math.max(Math.ceil(ThreadLocalRandom.current().nextGaussian(treasureConfigFields.getMean(), treasureConfigFields.getStandardDeviation())), 0); + //Guarantee that at least one item will drop + amount++; + HashMap weightsMap = new HashMap<>(); + for (int i = chestRarities.size() - 1; i >= 0; i--) + weightsMap.put(i, chestRarities.get(i).chestWeight); + + for (int i = 0; i < amount; i++) { + ItemStack itemStack = chestRarities.get(WeighedProbability.pickWeighedProbability(weightsMap)).rollLoot(); + if (itemStack != null) { + int counter = 0; + while (counter < 100) { + int randomizedIndex = ThreadLocalRandom.current().nextInt(0, chest.getSnapshotInventory().getSize()); + if (chest.getSnapshotInventory().getItem(randomizedIndex) == null) { + chest.getSnapshotInventory().setItem(randomizedIndex, itemStack); + break; + } + counter++; + } + } + } + } + + private class ChestRarity { + private final double chestWeight; + private final List chestEntries; + + public ChestRarity(double chestWeight, List chestEntries) { + this.chestEntries = chestEntries; + this.chestWeight = chestWeight; + } + + public ItemStack rollLoot() { + HashMap weightsMap = new HashMap<>(); + for (int i = chestEntries.size() - 1; i >= 0; i--) + weightsMap.put(i, chestEntries.get(i).getWeight()); + return chestEntries.get(WeighedProbability.pickWeighedProbability(weightsMap)).rollEntry(); } } } diff --git a/src/main/java/com/magmaguy/betterstructures/chests/ChestEntry.java b/src/main/java/com/magmaguy/betterstructures/chests/ChestEntry.java index d23346d..a2b25c8 100644 --- a/src/main/java/com/magmaguy/betterstructures/chests/ChestEntry.java +++ b/src/main/java/com/magmaguy/betterstructures/chests/ChestEntry.java @@ -1,33 +1,51 @@ package com.magmaguy.betterstructures.chests; -import org.bukkit.Bukkit; +import com.magmaguy.betterstructures.config.treasures.TreasureConfigFields; +import lombok.Getter; import org.bukkit.Material; import org.bukkit.inventory.ItemStack; +import org.bukkit.inventory.meta.ItemMeta; +import java.util.List; import java.util.concurrent.ThreadLocalRandom; public class ChestEntry { - private Material material; - private double chance; - private int minAmount; - private int maxAmount; - private ItemStack itemStack; + private final Material material; + @Getter + private final double weight; + private final int minAmount; + private final int maxAmount; + private final ItemStack itemStack; + private boolean procedurallyGeneratedEnchantments; + private TreasureConfigFields treasureConfigFields; - public ChestEntry(Material material, double chance, int minAmount, int maxAmount, ItemStack itemStack) { + public ChestEntry(Material material, double chance, int minAmount, int maxAmount, ItemStack itemStack, boolean procedurallyGeneratedEnchantments, TreasureConfigFields treasureConfigFields) { this.material = material; - this.chance = chance; + this.weight = chance; this.minAmount = minAmount; this.maxAmount = maxAmount; this.itemStack = itemStack; + this.procedurallyGeneratedEnchantments = procedurallyGeneratedEnchantments; + this.treasureConfigFields = treasureConfigFields; } public ItemStack rollEntry() { - if (ThreadLocalRandom.current().nextDouble() > chance) return null; int amount; if (minAmount != maxAmount) amount = ThreadLocalRandom.current().nextInt(minAmount, maxAmount + 1); else amount = minAmount; - if (material != null) - return new ItemStack(material, amount); + if (material != null) { + ItemStack itemStack = new ItemStack(material, amount); + if (!procedurallyGeneratedEnchantments) + return itemStack; + List configurationEnchantmentList = treasureConfigFields.getEnchantmentSettings().get(material); + if (configurationEnchantmentList == null || configurationEnchantmentList.isEmpty()) return itemStack; + ItemMeta itemMeta = itemStack.getItemMeta(); + for (TreasureConfigFields.ConfigurationEnchantment configurationEnchantment : configurationEnchantmentList) { + configurationEnchantment.rollEnchantment(itemMeta); + } + itemStack.setItemMeta(itemMeta); + return itemStack; + } ItemStack finalItemStack = itemStack.clone(); finalItemStack.setAmount(amount); return finalItemStack; diff --git a/src/main/java/com/magmaguy/betterstructures/commands/CommandHandler.java b/src/main/java/com/magmaguy/betterstructures/commands/CommandHandler.java index fa3d4ca..d5be5df 100644 --- a/src/main/java/com/magmaguy/betterstructures/commands/CommandHandler.java +++ b/src/main/java/com/magmaguy/betterstructures/commands/CommandHandler.java @@ -11,14 +11,19 @@ import cloud.commandframework.minecraft.extras.MinecraftHelp; import com.magmaguy.betterstructures.MetadataHandler; import com.magmaguy.betterstructures.buildingfitter.FitAnything; -import com.magmaguy.betterstructures.buildingfitter.FitSurfaceBuilding; -import com.magmaguy.betterstructures.config.generators.GeneratorConfig; +import com.magmaguy.betterstructures.config.DefaultConfig; import com.magmaguy.betterstructures.config.generators.GeneratorConfigFields; +import com.magmaguy.betterstructures.config.treasures.TreasureConfig; +import com.magmaguy.betterstructures.config.treasures.TreasureConfigFields; import com.magmaguy.betterstructures.schematics.SchematicContainer; +import com.magmaguy.betterstructures.util.ChatColorConverter; import com.magmaguy.betterstructures.util.ItemStackSerialization; import com.magmaguy.betterstructures.util.WarningMessage; import net.kyori.adventure.platform.bukkit.BukkitAudiences; import net.kyori.adventure.text.format.NamedTextColor; +import org.bukkit.Bukkit; +import org.bukkit.Location; +import org.bukkit.World; import org.bukkit.command.CommandSender; import org.bukkit.entity.Player; import org.bukkit.inventory.ItemStack; @@ -26,6 +31,8 @@ import java.lang.reflect.Method; import java.util.ArrayList; import java.util.Arrays; +import java.util.HashMap; +import java.util.Map; import java.util.function.Function; import static net.kyori.adventure.text.Component.text; @@ -129,20 +136,61 @@ public void constructCommands() { commandContext.getSender().sendMessage("[BetterStructures] Reload attempted. This may not 100% work. Restart instead if it didn't!!"); })); - ArrayList generators = new ArrayList<>(GeneratorConfig.getGeneratorConfigurations().keySet()); + ArrayList treasures = new ArrayList<>(TreasureConfig.getTreasureConfigurations().keySet()); manager.command(builder.literal("lootify") .senderType(Player.class) .argument(StringArgument.newBuilder("generator") - .withSuggestionsProvider(((objectCommandContext, s) -> generators)), + .withSuggestionsProvider(((objectCommandContext, s) -> treasures)), ArgumentDescription.of("File name of the generator")) + .argument(StringArgument.newBuilder("rarity"), + ArgumentDescription.of("Name of the rarity in the loot table")) .meta(CommandMeta.DESCRIPTION, "Adds a held item to the loot settings of a generator") .argument(StringArgument.newBuilder("minAmount")) .argument(StringArgument.newBuilder("maxAmount")) - .argument(StringArgument.newBuilder("chance")) + .argument(StringArgument.newBuilder("weight")) .permission("betterstructures.*") .handler(commandContext -> { - lootify(commandContext.get("generator"), commandContext.get("minAmount"), commandContext.get("maxAmount"), commandContext.get("chance"), (Player) commandContext.getSender()); + lootify(commandContext.get("generator"), commandContext.get("rarity"),commandContext.get("minAmount"), commandContext.get("maxAmount"), commandContext.get("weight"), (Player) commandContext.getSender()); + })); + + manager.command(builder.literal("teleporttocoords") + .senderType(Player.class) + .argument(StringArgument.newBuilder("worldname")) + .argument(StringArgument.newBuilder("x")) + .argument(StringArgument.newBuilder("y")) + .argument(StringArgument.newBuilder("z")) + .permission("betterstructures.*") + .handler(commandContext -> { + try { + World world = Bukkit.getWorld((String) commandContext.get("worldname")); + double x = Double.parseDouble(commandContext.get("x")); + double y = Double.parseDouble(commandContext.get("y")); + double z = Double.parseDouble(commandContext.get("z")); + ((Player) commandContext.getSender()).teleport(new Location(world, x, y, z)); + } catch (Exception ex) { + commandContext.getSender().sendMessage("[BetterStructures] Failed to teleport to location because the location wasn't valid!"); + } + }) + ); + // /bs version + manager.command(builder.literal("version") + .meta(CommandMeta.DESCRIPTION, "Gets the version of the plugin") + .senderType(CommandSender.class) + .permission("betterstructures.version") + .handler(commandContext -> + commandContext.getSender().sendMessage( + ChatColorConverter.convert("&8[BetterStructures] &aVersion " + + Bukkit.getPluginManager().getPlugin( + MetadataHandler.PLUGIN.getName()).getDescription().getVersion())))); + // /bs silent + manager.command(builder.literal("silent") + .meta(CommandMeta.DESCRIPTION, "Silences warning admins about new builds") + .senderType(CommandSender.class) + .permission("betterstructures.*") + .handler(commandContext -> { + commandContext.getSender().sendMessage( + ChatColorConverter.convert("&8[BetterStructures] &2Toggled build warnings to " + DefaultConfig.toggleWarnings() + "!")); })); } @@ -173,12 +221,17 @@ private void placeSchematic(String schematicFile, String schematicType, Player p } } - private void lootify(String generator, String minAmount, String maxAmount, String chance, Player player) { - GeneratorConfigFields generatorConfigFields = GeneratorConfig.getConfigFields(generator); - if (generatorConfigFields == null) { + private void lootify(String generator, String rarity, String minAmount, String maxAmount, String weight, Player player) { + TreasureConfigFields treasureConfigFields = TreasureConfig.getConfigFields(generator); + if (treasureConfigFields == null) { player.sendMessage("[BetterStructures] Not a valid generator! Try again."); return; } + //Verify loot table + if (treasureConfigFields.getRawLoot().get(rarity) == null) { + player.sendMessage("[BetterStructures] Not a valid rarity! Try again."); + return; + } int minAmountInt; try { minAmountInt = Integer.parseInt(minAmount); @@ -201,15 +254,11 @@ private void lootify(String generator, String minAmount, String maxAmount, Strin player.sendMessage("[BetterStructures] Maximum amount should not be more than 64! If you want more than one stack, make multiple entries. This value will not be saved."); return; } - double chanceDouble; + double weightDouble; try { - chanceDouble = Double.parseDouble(chance); + weightDouble = Double.parseDouble(weight); } catch (Exception exception) { - player.sendMessage("[BetterStructures] Not a valid chance! Try again."); - return; - } - if (chanceDouble > 1) { - player.sendMessage("[BetterStructures] Chance should never be higher than 1.0! 1.0 is 100%, 0.0 is 0%, 0.5 is 50%! This value will not be saved."); + player.sendMessage("[BetterStructures] Not a valid weight! Try again."); return; } ItemStack itemStack = player.getInventory().getItemInMainHand(); @@ -217,7 +266,18 @@ private void lootify(String generator, String minAmount, String maxAmount, Strin player.sendMessage("[BetterStructures] You need to be holding an item in order to register the item you're holding! This value will not be saved."); return; } - String configString = "serialized=" + ItemStackSerialization.toBase64(itemStack) + ":amount=" + minAmount + "-" + maxAmount + ":chance=" + chance; - generatorConfigFields.addChestEntry(configString, player); + String info; + if (itemStack.hasItemMeta() && itemStack.getItemMeta().hasDisplayName()) + info = itemStack.getItemMeta().getDisplayName().replace(" ", "_"); + else if (itemStack.hasItemMeta() && itemStack.getItemMeta().hasLocalizedName()) + info = itemStack.getItemMeta().getLocalizedName(); + else + info = itemStack.getType().toString(); + Map configMap = new HashMap<>(); + configMap.put("serialized", ItemStackSerialization.deserializeItem(itemStack)); + configMap.put("amount", minAmount +"-"+maxAmount); + configMap.put("weight", weightDouble); + configMap.put("info", info); + treasureConfigFields.addChestEntry(configMap, rarity, player); } } diff --git a/src/main/java/com/magmaguy/betterstructures/config/ConfigurationEngine.java b/src/main/java/com/magmaguy/betterstructures/config/ConfigurationEngine.java index 7aecd73..0fc8a7c 100644 --- a/src/main/java/com/magmaguy/betterstructures/config/ConfigurationEngine.java +++ b/src/main/java/com/magmaguy/betterstructures/config/ConfigurationEngine.java @@ -29,7 +29,9 @@ public static File fileCreator(File file) { file.getParentFile().mkdirs(); file.createNewFile(); } catch (IOException ex) { - Bukkit.getLogger().warning("[EliteMobs] Error generating the plugin file: " + file.getName()); + Bukkit.getLogger().warning("[BetterStructures] Error generating the plugin file: " + file.getName()); + Bukkit.getLogger().warning("[BetterStructures] Path: " + file.getAbsolutePath()); + ex.printStackTrace(); } return file; diff --git a/src/main/java/com/magmaguy/betterstructures/config/CustomConfig.java b/src/main/java/com/magmaguy/betterstructures/config/CustomConfig.java index 4d3c4e3..fdfef07 100644 --- a/src/main/java/com/magmaguy/betterstructures/config/CustomConfig.java +++ b/src/main/java/com/magmaguy/betterstructures/config/CustomConfig.java @@ -3,7 +3,6 @@ import com.magmaguy.betterstructures.MetadataHandler; import com.magmaguy.betterstructures.util.WarningMessage; -import org.bukkit.Bukkit; import org.bukkit.configuration.file.FileConfiguration; import org.bukkit.configuration.file.YamlConfiguration; import org.reflections.Reflections; diff --git a/src/main/java/com/magmaguy/betterstructures/config/CustomConfigFields.java b/src/main/java/com/magmaguy/betterstructures/config/CustomConfigFields.java index daba911..de28d81 100644 --- a/src/main/java/com/magmaguy/betterstructures/config/CustomConfigFields.java +++ b/src/main/java/com/magmaguy/betterstructures/config/CustomConfigFields.java @@ -10,10 +10,7 @@ import org.bukkit.util.Vector; import java.io.File; -import java.util.ArrayList; -import java.util.Collections; -import java.util.List; -import java.util.Objects; +import java.util.*; public class CustomConfigFields implements CustomConfigFieldsInterface { @@ -260,7 +257,7 @@ public > T processEnum(String path, T value, T pluginDefault, return value; } try { - return (T) Enum.valueOf(enumClass, fileConfiguration.getString(path).toUpperCase()); + return Enum.valueOf(enumClass, fileConfiguration.getString(path).toUpperCase()); } catch (Exception ex) { new WarningMessage("File " + filename + " has an incorrect entry for " + path); new WarningMessage("Entry: " + value); @@ -273,6 +270,16 @@ private String itemStackDeserializer(ItemStack itemStack) { return itemStack.getType().toString(); } + public Map processMap(String path, Map value) { + if (!configHas(path) && value != null) { + fileConfiguration.addDefault(path, value); + fileConfiguration.createSection(path, value); + } + if (fileConfiguration.get(path) == null) + return Collections.emptyMap(); + return fileConfiguration.getConfigurationSection(path).getValues(false); + } + protected org.bukkit.util.Vector processVector(String path, org.bukkit.util.Vector value, org.bukkit.util.Vector pluginDefault, boolean forceWriteDefault) { if (!configHas(path)) { if (forceWriteDefault || !Objects.equals(value, pluginDefault)) diff --git a/src/main/java/com/magmaguy/betterstructures/config/DefaultConfig.java b/src/main/java/com/magmaguy/betterstructures/config/DefaultConfig.java index b18665c..725f52c 100644 --- a/src/main/java/com/magmaguy/betterstructures/config/DefaultConfig.java +++ b/src/main/java/com/magmaguy/betterstructures/config/DefaultConfig.java @@ -6,9 +6,6 @@ import java.io.File; public class DefaultConfig { - private DefaultConfig() { - } - @Getter private static int lowestYNormalCustom; @Getter @@ -29,11 +26,30 @@ private DefaultConfig() { private static int endAirBuildMinAltitude; @Getter private static int endAirBuildMaxAltitude; - + @Getter + private static double airStructuresPerThousandChunks; + @Getter + private static double oceanStructuresPerThousandChunks; + @Getter + private static double landStructuresPerThousandChunks; + @Getter + private static double shallowUndergroundStructuresPerThousandChunks; + @Getter + private static double deepUndergroundStructuresPerThousandChunks; + @Getter + private static boolean newBuildingWarn; + @Getter + private static String regionProtectedMessage; + @Getter + private static boolean protectEliteMobsRegions; + private static File file; + private static FileConfiguration fileConfiguration; + private DefaultConfig() { + } public static void initializeConfig() { - File file = ConfigurationEngine.fileCreator("config.yml"); - FileConfiguration fileConfiguration = ConfigurationEngine.fileConfigurationCreator(file); + file = ConfigurationEngine.fileCreator("config.yml"); + fileConfiguration = ConfigurationEngine.fileConfigurationCreator(file); lowestYNormalCustom = ConfigurationEngine.setInt(fileConfiguration, "lowestYNormalCustom", -60); highestYNormalCustom = ConfigurationEngine.setInt(fileConfiguration, "highestYNormalCustom", 320); lowestYNether = ConfigurationEngine.setInt(fileConfiguration, "lowestYNether", 4); @@ -44,6 +60,22 @@ public static void initializeConfig() { normalCustomAirBuildingMaxAltitude = ConfigurationEngine.setInt(fileConfiguration, "normalCustomAirBuildingMaxAltitude", 120); endAirBuildMinAltitude = ConfigurationEngine.setInt(fileConfiguration, "endAirBuildMinAltitude", 80); endAirBuildMaxAltitude = ConfigurationEngine.setInt(fileConfiguration, "endAirBuildMaxAltitude", 120); + airStructuresPerThousandChunks = ConfigurationEngine.setDouble(fileConfiguration, "airStructuresPerThousandChunks", 0.5); + oceanStructuresPerThousandChunks = ConfigurationEngine.setDouble(fileConfiguration, "oceanStructuresPerThousandChunks", 0.5); + landStructuresPerThousandChunks = ConfigurationEngine.setDouble(fileConfiguration, "landStructuresPerThousandChunks", 2.0); + shallowUndergroundStructuresPerThousandChunks = ConfigurationEngine.setDouble(fileConfiguration, "shallowUndergroundStructuresPerThousandChunks", 2.0); + deepUndergroundStructuresPerThousandChunks = ConfigurationEngine.setDouble(fileConfiguration, "deepUndergroundStructuresPerThousandChunks", 2.0); + newBuildingWarn = ConfigurationEngine.setBoolean(fileConfiguration, "warnAdminsAboutNewBuildings", true); + regionProtectedMessage = ConfigurationEngine.setString(fileConfiguration, "regionProtectedMessage", "&8[BetterStructures] &cDefeat the zone's bosses to edit blocks!"); + protectEliteMobsRegions = ConfigurationEngine.setBoolean(fileConfiguration, "protectEliteMobsRegions", true); ConfigurationEngine.fileSaverOnlyDefaults(fileConfiguration, file); } + + public static boolean toggleWarnings() { + newBuildingWarn = !newBuildingWarn; + ConfigurationEngine.writeValue(newBuildingWarn, file, fileConfiguration, "warnAdminsAboutNewBuildings"); + return newBuildingWarn; + } + } + diff --git a/src/main/java/com/magmaguy/betterstructures/config/ValidWorldsConfig.java b/src/main/java/com/magmaguy/betterstructures/config/ValidWorldsConfig.java index a1c37ed..410ed2f 100644 --- a/src/main/java/com/magmaguy/betterstructures/config/ValidWorldsConfig.java +++ b/src/main/java/com/magmaguy/betterstructures/config/ValidWorldsConfig.java @@ -31,7 +31,7 @@ public static void initializeConfig() { file = ConfigurationEngine.fileCreator("ValidWorlds.yml"); fileConfiguration = ConfigurationEngine.fileConfigurationCreator(file); - whitelistNewWorlds = true; + whitelistNewWorlds = ConfigurationEngine.setBoolean(fileConfiguration, "New worlds spawn structures", true); for (World world : Bukkit.getWorlds()) ConfigurationEngine.setBoolean(fileConfiguration, "Valid worlds." + world.getName(), true); diff --git a/src/main/java/com/magmaguy/betterstructures/config/generators/GeneratorConfig.java b/src/main/java/com/magmaguy/betterstructures/config/generators/GeneratorConfig.java index bd9c2d4..ff72ed2 100644 --- a/src/main/java/com/magmaguy/betterstructures/config/generators/GeneratorConfig.java +++ b/src/main/java/com/magmaguy/betterstructures/config/generators/GeneratorConfig.java @@ -2,7 +2,6 @@ import com.magmaguy.betterstructures.config.CustomConfig; import lombok.Getter; -import org.bukkit.Bukkit; import java.util.HashMap; diff --git a/src/main/java/com/magmaguy/betterstructures/config/generators/GeneratorConfigFields.java b/src/main/java/com/magmaguy/betterstructures/config/generators/GeneratorConfigFields.java index a66e5fe..403ea8d 100644 --- a/src/main/java/com/magmaguy/betterstructures/config/generators/GeneratorConfigFields.java +++ b/src/main/java/com/magmaguy/betterstructures/config/generators/GeneratorConfigFields.java @@ -1,13 +1,14 @@ package com.magmaguy.betterstructures.config.generators; -import com.magmaguy.betterstructures.MetadataHandler; import com.magmaguy.betterstructures.chests.ChestContents; import com.magmaguy.betterstructures.config.CustomConfigFields; +import com.magmaguy.betterstructures.config.treasures.TreasureConfig; +import com.magmaguy.betterstructures.config.treasures.TreasureConfigFields; +import com.magmaguy.betterstructures.util.WarningMessage; import lombok.Getter; import lombok.Setter; import org.bukkit.World; import org.bukkit.block.Biome; -import org.bukkit.entity.Player; import java.util.ArrayList; import java.util.Arrays; @@ -35,16 +36,16 @@ public enum StructureType { private int highestYLevel = 320; @Getter @Setter - private List validWorlds = new ArrayList<>(); + private List validWorlds = null; @Getter @Setter - private List validWorldEnvironments = new ArrayList<>(); + private List validWorldEnvironments = null; @Getter @Setter - private List validBiomes = new ArrayList<>(); + private List validBiomes = null; @Getter @Setter - List chestEntries = new ArrayList<>(); + private String treasureFilename = null; @Getter private ChestContents chestContents = null; @@ -70,25 +71,16 @@ public void processConfigFields() { this.structureTypes = processEnumList("structureType", structureTypes, Arrays.asList(StructureType.UNDEFINED), StructureType.class, true); this.lowestYLevel = processInt("lowestYLevel", lowestYLevel, -59, false); this.highestYLevel = processInt("highestYLevel", highestYLevel, 320, false); - this.validWorlds = processWorldList("validWorlds", validWorlds, new ArrayList<>(), false); + this.validWorlds = processStringList("validWorlds", validWorlds, new ArrayList<>(), false); this.validWorldEnvironments = processEnumList("validWorldEnvironments", validWorldEnvironments, null, World.Environment.class, false); this.validBiomes = processEnumList("validBiomes", validBiomes, new ArrayList<>(), Biome.class, false); - this.chestEntries = processStringList("chestEntries", chestEntries, new ArrayList<>(), false); - chestContents = new ChestContents(chestEntries, this); - } + this.treasureFilename = processString("treasureFilename", treasureFilename, null, false); + TreasureConfigFields treasureConfig = TreasureConfig.getConfigFields(treasureFilename); + if (treasureConfig != null) + this.chestContents = new ChestContents(treasureConfig); + else + new WarningMessage("No valid treasure config file found for generator " + filename + " ! This will not spawn loot in chests until fixed."); - public void addChestEntry(String entry, Player player) { - chestEntries.add(entry); - fileConfiguration.set("chestEntries", chestEntries); - try { - fileConfiguration.save(file); - } catch (Exception ex) { - player.sendMessage("[BetterStructures] Failed to save entry to file! Report this to the developer."); - return; - } - MetadataHandler.PLUGIN.onDisable(); - MetadataHandler.PLUGIN.onLoad(); - MetadataHandler.PLUGIN.onEnable(); - player.sendMessage("[BetterStructures] Reloaded plugin to add chest entry! It should now be live."); } + } diff --git a/src/main/java/com/magmaguy/betterstructures/config/generators/premade/GeneratorLiquidNether.java b/src/main/java/com/magmaguy/betterstructures/config/generators/premade/GeneratorLiquidNether.java index f37e1ae..cb556d0 100644 --- a/src/main/java/com/magmaguy/betterstructures/config/generators/premade/GeneratorLiquidNether.java +++ b/src/main/java/com/magmaguy/betterstructures/config/generators/premade/GeneratorLiquidNether.java @@ -1,7 +1,6 @@ package com.magmaguy.betterstructures.config.generators.premade; import com.magmaguy.betterstructures.config.generators.GeneratorConfigFields; -import com.magmaguy.betterstructures.util.DefaultChestContents; import org.bukkit.World; import java.util.Arrays; @@ -10,6 +9,6 @@ public class GeneratorLiquidNether extends GeneratorConfigFields { public GeneratorLiquidNether() { super("generator_liquid_nether", true, Arrays.asList(StructureType.LIQUID_SURFACE)); setValidWorldEnvironments(Arrays.asList(World.Environment.NETHER)); - setChestEntries(DefaultChestContents.netherContents()); + setTreasureFilename("treasure_nether.yml"); } } diff --git a/src/main/java/com/magmaguy/betterstructures/config/generators/premade/GeneratorLiquidOverworld.java b/src/main/java/com/magmaguy/betterstructures/config/generators/premade/GeneratorLiquidOverworld.java index b9e1562..612ef75 100644 --- a/src/main/java/com/magmaguy/betterstructures/config/generators/premade/GeneratorLiquidOverworld.java +++ b/src/main/java/com/magmaguy/betterstructures/config/generators/premade/GeneratorLiquidOverworld.java @@ -1,7 +1,6 @@ package com.magmaguy.betterstructures.config.generators.premade; import com.magmaguy.betterstructures.config.generators.GeneratorConfigFields; -import com.magmaguy.betterstructures.util.DefaultChestContents; import org.bukkit.World; import java.util.Arrays; @@ -10,6 +9,6 @@ public class GeneratorLiquidOverworld extends GeneratorConfigFields { public GeneratorLiquidOverworld() { super("generator_liquid_overworld", true, Arrays.asList(StructureType.LIQUID_SURFACE)); setValidWorldEnvironments(Arrays.asList(World.Environment.NORMAL, World.Environment.CUSTOM)); - setChestEntries(DefaultChestContents.overworldContents()); + setTreasureFilename("treasure_overworld_underground.yml"); } } diff --git a/src/main/java/com/magmaguy/betterstructures/config/generators/premade/GeneratorSkyBarrenConfig.java b/src/main/java/com/magmaguy/betterstructures/config/generators/premade/GeneratorSkyBarrenConfig.java index 6753ca1..3d8ce6f 100644 --- a/src/main/java/com/magmaguy/betterstructures/config/generators/premade/GeneratorSkyBarrenConfig.java +++ b/src/main/java/com/magmaguy/betterstructures/config/generators/premade/GeneratorSkyBarrenConfig.java @@ -1,7 +1,6 @@ package com.magmaguy.betterstructures.config.generators.premade; import com.magmaguy.betterstructures.config.generators.GeneratorConfigFields; -import com.magmaguy.betterstructures.util.DefaultChestContents; import org.bukkit.block.Biome; import java.util.Arrays; @@ -14,8 +13,9 @@ public GeneratorSkyBarrenConfig(){ Biome.SAVANNA, Biome.SAVANNA_PLATEAU, Biome.WINDSWEPT_SAVANNA, - Biome.MUSHROOM_FIELDS + Biome.MUSHROOM_FIELDS, + Biome.CUSTOM )); - setChestEntries(DefaultChestContents.overworldContents()); + setTreasureFilename("treasure_overworld_surface.yml"); } } diff --git a/src/main/java/com/magmaguy/betterstructures/config/generators/premade/GeneratorSkyCrimsonForestConfig.java b/src/main/java/com/magmaguy/betterstructures/config/generators/premade/GeneratorSkyCrimsonForestConfig.java index 6f45e35..2dc6c09 100644 --- a/src/main/java/com/magmaguy/betterstructures/config/generators/premade/GeneratorSkyCrimsonForestConfig.java +++ b/src/main/java/com/magmaguy/betterstructures/config/generators/premade/GeneratorSkyCrimsonForestConfig.java @@ -1,7 +1,6 @@ package com.magmaguy.betterstructures.config.generators.premade; import com.magmaguy.betterstructures.config.generators.GeneratorConfigFields; -import com.magmaguy.betterstructures.util.DefaultChestContents; import org.bukkit.block.Biome; import java.util.Arrays; @@ -9,7 +8,9 @@ public class GeneratorSkyCrimsonForestConfig extends GeneratorConfigFields { public GeneratorSkyCrimsonForestConfig(){ super("generator_sky_crimson_forest", true, Arrays.asList(StructureType.SKY)); - setValidBiomes(Arrays.asList(Biome.CRIMSON_FOREST)); - setChestEntries(DefaultChestContents.netherContents()); + setValidBiomes(Arrays.asList( + Biome.CRIMSON_FOREST, + Biome.CUSTOM)); + setTreasureFilename("treasure_nether.yml"); } } diff --git a/src/main/java/com/magmaguy/betterstructures/config/generators/premade/GeneratorSkyDesertConfig.java b/src/main/java/com/magmaguy/betterstructures/config/generators/premade/GeneratorSkyDesertConfig.java index 4f182e7..214a0bc 100644 --- a/src/main/java/com/magmaguy/betterstructures/config/generators/premade/GeneratorSkyDesertConfig.java +++ b/src/main/java/com/magmaguy/betterstructures/config/generators/premade/GeneratorSkyDesertConfig.java @@ -1,7 +1,6 @@ package com.magmaguy.betterstructures.config.generators.premade; import com.magmaguy.betterstructures.config.generators.GeneratorConfigFields; -import com.magmaguy.betterstructures.util.DefaultChestContents; import org.bukkit.block.Biome; import java.util.Arrays; @@ -10,8 +9,9 @@ public class GeneratorSkyDesertConfig extends GeneratorConfigFields { public GeneratorSkyDesertConfig(){ super("generator_sky_desert", true, Arrays.asList(StructureType.SKY)); setValidBiomes(Arrays.asList( - Biome.DESERT + Biome.DESERT, + Biome.CUSTOM )); - setChestEntries(DefaultChestContents.overworldContents()); + setTreasureFilename("treasure_overworld_surface.yml"); } } diff --git a/src/main/java/com/magmaguy/betterstructures/config/generators/premade/GeneratorSkyEndConfig.java b/src/main/java/com/magmaguy/betterstructures/config/generators/premade/GeneratorSkyEndConfig.java index dbff717..ab9504e 100644 --- a/src/main/java/com/magmaguy/betterstructures/config/generators/premade/GeneratorSkyEndConfig.java +++ b/src/main/java/com/magmaguy/betterstructures/config/generators/premade/GeneratorSkyEndConfig.java @@ -1,7 +1,6 @@ package com.magmaguy.betterstructures.config.generators.premade; import com.magmaguy.betterstructures.config.generators.GeneratorConfigFields; -import com.magmaguy.betterstructures.util.DefaultChestContents; import org.bukkit.World; import java.util.Arrays; @@ -10,6 +9,6 @@ public class GeneratorSkyEndConfig extends GeneratorConfigFields { public GeneratorSkyEndConfig(){ super("generator_sky_end", true, Arrays.asList(StructureType.SKY)); setValidWorldEnvironments(Arrays.asList(World.Environment.THE_END)); - setChestEntries(DefaultChestContents.endContents()); + setTreasureFilename("treasure_end.yml"); } } diff --git a/src/main/java/com/magmaguy/betterstructures/config/generators/premade/GeneratorSkyGlobal.java b/src/main/java/com/magmaguy/betterstructures/config/generators/premade/GeneratorSkyGlobal.java index 1b3728b..55642f2 100644 --- a/src/main/java/com/magmaguy/betterstructures/config/generators/premade/GeneratorSkyGlobal.java +++ b/src/main/java/com/magmaguy/betterstructures/config/generators/premade/GeneratorSkyGlobal.java @@ -1,13 +1,12 @@ package com.magmaguy.betterstructures.config.generators.premade; import com.magmaguy.betterstructures.config.generators.GeneratorConfigFields; -import com.magmaguy.betterstructures.util.DefaultChestContents; import java.util.Arrays; public class GeneratorSkyGlobal extends GeneratorConfigFields { public GeneratorSkyGlobal() { super("generator_sky_global", true, Arrays.asList(StructureType.SKY)); - setChestEntries(DefaultChestContents.overworldContents()); + setTreasureFilename("treasure_overworld_surface.yml"); } } diff --git a/src/main/java/com/magmaguy/betterstructures/config/generators/premade/GeneratorSkyGrasslandConfig.java b/src/main/java/com/magmaguy/betterstructures/config/generators/premade/GeneratorSkyGrasslandConfig.java index 1f2b22c..89991e7 100644 --- a/src/main/java/com/magmaguy/betterstructures/config/generators/premade/GeneratorSkyGrasslandConfig.java +++ b/src/main/java/com/magmaguy/betterstructures/config/generators/premade/GeneratorSkyGrasslandConfig.java @@ -1,7 +1,6 @@ package com.magmaguy.betterstructures.config.generators.premade; import com.magmaguy.betterstructures.config.generators.GeneratorConfigFields; -import com.magmaguy.betterstructures.util.DefaultChestContents; import org.bukkit.block.Biome; import java.util.Arrays; @@ -23,8 +22,9 @@ public GeneratorSkyGrasslandConfig(){ Biome.OLD_GROWTH_BIRCH_FOREST, Biome.SUNFLOWER_PLAINS, Biome.WINDSWEPT_FOREST, - Biome.WINDSWEPT_HILLS + Biome.WINDSWEPT_HILLS, + Biome.CUSTOM )); - setChestEntries(DefaultChestContents.overworldContents()); + setTreasureFilename("treasure_overworld_surface.yml"); } } diff --git a/src/main/java/com/magmaguy/betterstructures/config/generators/premade/GeneratorSkyNetherConfig.java b/src/main/java/com/magmaguy/betterstructures/config/generators/premade/GeneratorSkyNetherConfig.java index 836527f..03883c5 100644 --- a/src/main/java/com/magmaguy/betterstructures/config/generators/premade/GeneratorSkyNetherConfig.java +++ b/src/main/java/com/magmaguy/betterstructures/config/generators/premade/GeneratorSkyNetherConfig.java @@ -1,7 +1,6 @@ package com.magmaguy.betterstructures.config.generators.premade; import com.magmaguy.betterstructures.config.generators.GeneratorConfigFields; -import com.magmaguy.betterstructures.util.DefaultChestContents; import org.bukkit.World; import java.util.Arrays; @@ -10,6 +9,6 @@ public class GeneratorSkyNetherConfig extends GeneratorConfigFields { public GeneratorSkyNetherConfig(){ super("generator_sky_nether", true, Arrays.asList(StructureType.SKY)); setValidWorldEnvironments(Arrays.asList(World.Environment.NETHER)); - setChestEntries(DefaultChestContents.netherContents()); + setTreasureFilename("treasure_nether.yml"); } } diff --git a/src/main/java/com/magmaguy/betterstructures/config/generators/premade/GeneratorSkyNetherWastesConfig.java b/src/main/java/com/magmaguy/betterstructures/config/generators/premade/GeneratorSkyNetherWastesConfig.java index b46769a..edbb5a3 100644 --- a/src/main/java/com/magmaguy/betterstructures/config/generators/premade/GeneratorSkyNetherWastesConfig.java +++ b/src/main/java/com/magmaguy/betterstructures/config/generators/premade/GeneratorSkyNetherWastesConfig.java @@ -1,7 +1,6 @@ package com.magmaguy.betterstructures.config.generators.premade; import com.magmaguy.betterstructures.config.generators.GeneratorConfigFields; -import com.magmaguy.betterstructures.util.DefaultChestContents; import org.bukkit.block.Biome; import java.util.Arrays; @@ -9,7 +8,9 @@ public class GeneratorSkyNetherWastesConfig extends GeneratorConfigFields { public GeneratorSkyNetherWastesConfig(){ super("generator_sky_nether_wastes", true, Arrays.asList(StructureType.SKY)); - setValidBiomes(Arrays.asList(Biome.NETHER_WASTES)); - setChestEntries(DefaultChestContents.netherContents()); + setValidBiomes(Arrays.asList( + Biome.NETHER_WASTES, + Biome.CUSTOM)); + setTreasureFilename("treasure_nether.yml"); } } diff --git a/src/main/java/com/magmaguy/betterstructures/config/generators/premade/GeneratorSkySnowyConfig.java b/src/main/java/com/magmaguy/betterstructures/config/generators/premade/GeneratorSkySnowyConfig.java index 87f764a..6c16fe0 100644 --- a/src/main/java/com/magmaguy/betterstructures/config/generators/premade/GeneratorSkySnowyConfig.java +++ b/src/main/java/com/magmaguy/betterstructures/config/generators/premade/GeneratorSkySnowyConfig.java @@ -1,7 +1,6 @@ package com.magmaguy.betterstructures.config.generators.premade; import com.magmaguy.betterstructures.config.generators.GeneratorConfigFields; -import com.magmaguy.betterstructures.util.DefaultChestContents; import org.bukkit.block.Biome; import java.util.Arrays; @@ -14,8 +13,9 @@ public GeneratorSkySnowyConfig(){ Biome.SNOWY_BEACH, Biome.SNOWY_PLAINS, Biome.SNOWY_SLOPES, - Biome.ICE_SPIKES + Biome.ICE_SPIKES, + Biome.CUSTOM )); - setChestEntries(DefaultChestContents.overworldContents()); + setTreasureFilename("treasure_overworld_surface.yml"); } } diff --git a/src/main/java/com/magmaguy/betterstructures/config/generators/premade/GeneratorSkySoulSandConfig.java b/src/main/java/com/magmaguy/betterstructures/config/generators/premade/GeneratorSkySoulSandConfig.java index a45e3a6..c126719 100644 --- a/src/main/java/com/magmaguy/betterstructures/config/generators/premade/GeneratorSkySoulSandConfig.java +++ b/src/main/java/com/magmaguy/betterstructures/config/generators/premade/GeneratorSkySoulSandConfig.java @@ -1,7 +1,6 @@ package com.magmaguy.betterstructures.config.generators.premade; import com.magmaguy.betterstructures.config.generators.GeneratorConfigFields; -import com.magmaguy.betterstructures.util.DefaultChestContents; import org.bukkit.block.Biome; import java.util.Arrays; @@ -9,7 +8,9 @@ public class GeneratorSkySoulSandConfig extends GeneratorConfigFields { public GeneratorSkySoulSandConfig() { super("generator_sky_soul_sand", true, Arrays.asList(StructureType.SKY)); - setValidBiomes(Arrays.asList(Biome.SOUL_SAND_VALLEY)); - setChestEntries(DefaultChestContents.netherContents()); + setValidBiomes(Arrays.asList( + Biome.SOUL_SAND_VALLEY, + Biome.CUSTOM)); + setTreasureFilename("treasure_nether.yml"); } } diff --git a/src/main/java/com/magmaguy/betterstructures/config/generators/premade/GeneratorSkyWarpedForestConfig.java b/src/main/java/com/magmaguy/betterstructures/config/generators/premade/GeneratorSkyWarpedForestConfig.java index f01e611..04dd27a 100644 --- a/src/main/java/com/magmaguy/betterstructures/config/generators/premade/GeneratorSkyWarpedForestConfig.java +++ b/src/main/java/com/magmaguy/betterstructures/config/generators/premade/GeneratorSkyWarpedForestConfig.java @@ -1,7 +1,6 @@ package com.magmaguy.betterstructures.config.generators.premade; import com.magmaguy.betterstructures.config.generators.GeneratorConfigFields; -import com.magmaguy.betterstructures.util.DefaultChestContents; import org.bukkit.block.Biome; import java.util.Arrays; @@ -9,7 +8,9 @@ public class GeneratorSkyWarpedForestConfig extends GeneratorConfigFields { public GeneratorSkyWarpedForestConfig() { super("generator_sky_warped_forest", true, Arrays.asList(StructureType.SKY)); - setValidBiomes(Arrays.asList(Biome.WARPED_FOREST)); - setChestEntries(DefaultChestContents.netherContents()); + setValidBiomes(Arrays.asList( + Biome.WARPED_FOREST, + Biome.CUSTOM)); + setTreasureFilename("treasure_nether.yml"); } } diff --git a/src/main/java/com/magmaguy/betterstructures/config/generators/premade/GeneratorSurfaceBarrenConfig.java b/src/main/java/com/magmaguy/betterstructures/config/generators/premade/GeneratorSurfaceBarrenConfig.java index 2c68e99..8c63e6b 100644 --- a/src/main/java/com/magmaguy/betterstructures/config/generators/premade/GeneratorSurfaceBarrenConfig.java +++ b/src/main/java/com/magmaguy/betterstructures/config/generators/premade/GeneratorSurfaceBarrenConfig.java @@ -1,7 +1,6 @@ package com.magmaguy.betterstructures.config.generators.premade; import com.magmaguy.betterstructures.config.generators.GeneratorConfigFields; -import com.magmaguy.betterstructures.util.DefaultChestContents; import org.bukkit.block.Biome; import java.util.Arrays; @@ -14,8 +13,9 @@ public GeneratorSurfaceBarrenConfig(){ Biome.SAVANNA, Biome.SAVANNA_PLATEAU, Biome.WINDSWEPT_SAVANNA, - Biome.MUSHROOM_FIELDS + Biome.MUSHROOM_FIELDS, + Biome.CUSTOM )); - setChestEntries(DefaultChestContents.overworldContents()); + setTreasureFilename("treasure_overworld_surface.yml"); } } diff --git a/src/main/java/com/magmaguy/betterstructures/config/generators/premade/GeneratorSurfaceDesertConfig.java b/src/main/java/com/magmaguy/betterstructures/config/generators/premade/GeneratorSurfaceDesertConfig.java index 7a3d96e..feec7f9 100644 --- a/src/main/java/com/magmaguy/betterstructures/config/generators/premade/GeneratorSurfaceDesertConfig.java +++ b/src/main/java/com/magmaguy/betterstructures/config/generators/premade/GeneratorSurfaceDesertConfig.java @@ -1,7 +1,6 @@ package com.magmaguy.betterstructures.config.generators.premade; import com.magmaguy.betterstructures.config.generators.GeneratorConfigFields; -import com.magmaguy.betterstructures.util.DefaultChestContents; import org.bukkit.block.Biome; import java.util.Arrays; @@ -10,8 +9,9 @@ public class GeneratorSurfaceDesertConfig extends GeneratorConfigFields { public GeneratorSurfaceDesertConfig() { super("generator_surface_desert", true, Arrays.asList(StructureType.SURFACE)); setValidBiomes(Arrays.asList( - Biome.DESERT + Biome.DESERT, + Biome.CUSTOM )); - setChestEntries(DefaultChestContents.overworldContents()); + setTreasureFilename("treasure_overworld_surface.yml"); } } diff --git a/src/main/java/com/magmaguy/betterstructures/config/generators/premade/GeneratorSurfaceEndConfig.java b/src/main/java/com/magmaguy/betterstructures/config/generators/premade/GeneratorSurfaceEndConfig.java index a90fe3b..4f37b2e 100644 --- a/src/main/java/com/magmaguy/betterstructures/config/generators/premade/GeneratorSurfaceEndConfig.java +++ b/src/main/java/com/magmaguy/betterstructures/config/generators/premade/GeneratorSurfaceEndConfig.java @@ -1,7 +1,6 @@ package com.magmaguy.betterstructures.config.generators.premade; import com.magmaguy.betterstructures.config.generators.GeneratorConfigFields; -import com.magmaguy.betterstructures.util.DefaultChestContents; import org.bukkit.World; import java.util.Arrays; @@ -10,6 +9,6 @@ public class GeneratorSurfaceEndConfig extends GeneratorConfigFields { public GeneratorSurfaceEndConfig() { super("generator_surface_end", true, Arrays.asList(StructureType.SURFACE)); setValidWorldEnvironments(Arrays.asList(World.Environment.THE_END)); - setChestEntries(DefaultChestContents.endContents()); + setTreasureFilename("treasure_end.yml"); } } diff --git a/src/main/java/com/magmaguy/betterstructures/config/generators/premade/GeneratorSurfaceGlobalConfig.java b/src/main/java/com/magmaguy/betterstructures/config/generators/premade/GeneratorSurfaceGlobalConfig.java index 8b7be99..b4dc603 100644 --- a/src/main/java/com/magmaguy/betterstructures/config/generators/premade/GeneratorSurfaceGlobalConfig.java +++ b/src/main/java/com/magmaguy/betterstructures/config/generators/premade/GeneratorSurfaceGlobalConfig.java @@ -1,7 +1,6 @@ package com.magmaguy.betterstructures.config.generators.premade; import com.magmaguy.betterstructures.config.generators.GeneratorConfigFields; -import com.magmaguy.betterstructures.util.DefaultChestContents; import org.bukkit.World; import java.util.Arrays; @@ -10,6 +9,6 @@ public class GeneratorSurfaceGlobalConfig extends GeneratorConfigFields { public GeneratorSurfaceGlobalConfig() { super("generator_surface_global", true, Arrays.asList(StructureType.SURFACE)); setValidWorldEnvironments(Arrays.asList(World.Environment.NORMAL, World.Environment.CUSTOM)); - setChestEntries(DefaultChestContents.overworldContents()); + setTreasureFilename("treasure_overworld_surface.yml"); } } diff --git a/src/main/java/com/magmaguy/betterstructures/config/generators/premade/GeneratorSurfaceGrasslandConfig.java b/src/main/java/com/magmaguy/betterstructures/config/generators/premade/GeneratorSurfaceGrasslandConfig.java index 0f6cf90..7dc001d 100644 --- a/src/main/java/com/magmaguy/betterstructures/config/generators/premade/GeneratorSurfaceGrasslandConfig.java +++ b/src/main/java/com/magmaguy/betterstructures/config/generators/premade/GeneratorSurfaceGrasslandConfig.java @@ -1,7 +1,6 @@ package com.magmaguy.betterstructures.config.generators.premade; import com.magmaguy.betterstructures.config.generators.GeneratorConfigFields; -import com.magmaguy.betterstructures.util.DefaultChestContents; import org.bukkit.block.Biome; import java.util.Arrays; @@ -23,8 +22,9 @@ public GeneratorSurfaceGrasslandConfig(){ Biome.OLD_GROWTH_BIRCH_FOREST, Biome.SUNFLOWER_PLAINS, Biome.WINDSWEPT_FOREST, - Biome.WINDSWEPT_HILLS + Biome.WINDSWEPT_HILLS, + Biome.CUSTOM )); - setChestEntries(DefaultChestContents.overworldContents()); + setTreasureFilename("treasure_overworld_surface.yml"); } } diff --git a/src/main/java/com/magmaguy/betterstructures/config/generators/premade/GeneratorSurfaceNetherConfig.java b/src/main/java/com/magmaguy/betterstructures/config/generators/premade/GeneratorSurfaceNetherConfig.java index 209b9b2..5491f1d 100644 --- a/src/main/java/com/magmaguy/betterstructures/config/generators/premade/GeneratorSurfaceNetherConfig.java +++ b/src/main/java/com/magmaguy/betterstructures/config/generators/premade/GeneratorSurfaceNetherConfig.java @@ -1,7 +1,6 @@ package com.magmaguy.betterstructures.config.generators.premade; import com.magmaguy.betterstructures.config.generators.GeneratorConfigFields; -import com.magmaguy.betterstructures.util.DefaultChestContents; import org.bukkit.World; import java.util.Arrays; @@ -10,6 +9,6 @@ public class GeneratorSurfaceNetherConfig extends GeneratorConfigFields { public GeneratorSurfaceNetherConfig() { super("generator_surface_nether", true, Arrays.asList(StructureType.SURFACE)); setValidWorldEnvironments(Arrays.asList(World.Environment.NETHER)); - setChestEntries(DefaultChestContents.netherContents()); + setTreasureFilename("treasure_nether.yml"); } } diff --git a/src/main/java/com/magmaguy/betterstructures/config/generators/premade/GeneratorSurfaceSnowyConfig.java b/src/main/java/com/magmaguy/betterstructures/config/generators/premade/GeneratorSurfaceSnowyConfig.java index da5c9fe..73d76df 100644 --- a/src/main/java/com/magmaguy/betterstructures/config/generators/premade/GeneratorSurfaceSnowyConfig.java +++ b/src/main/java/com/magmaguy/betterstructures/config/generators/premade/GeneratorSurfaceSnowyConfig.java @@ -1,7 +1,6 @@ package com.magmaguy.betterstructures.config.generators.premade; import com.magmaguy.betterstructures.config.generators.GeneratorConfigFields; -import com.magmaguy.betterstructures.util.DefaultChestContents; import org.bukkit.block.Biome; import java.util.Arrays; @@ -14,8 +13,9 @@ public GeneratorSurfaceSnowyConfig() { Biome.SNOWY_BEACH, Biome.SNOWY_PLAINS, Biome.SNOWY_SLOPES, - Biome.ICE_SPIKES + Biome.ICE_SPIKES, + Biome.CUSTOM )); - setChestEntries(DefaultChestContents.overworldContents()); + setTreasureFilename("treasure_overworld_surface.yml"); } } diff --git a/src/main/java/com/magmaguy/betterstructures/config/generators/premade/GeneratorUndergroundDeepConfig.java b/src/main/java/com/magmaguy/betterstructures/config/generators/premade/GeneratorUndergroundDeepConfig.java index c3228b6..84de01e 100644 --- a/src/main/java/com/magmaguy/betterstructures/config/generators/premade/GeneratorUndergroundDeepConfig.java +++ b/src/main/java/com/magmaguy/betterstructures/config/generators/premade/GeneratorUndergroundDeepConfig.java @@ -1,7 +1,6 @@ package com.magmaguy.betterstructures.config.generators.premade; import com.magmaguy.betterstructures.config.generators.GeneratorConfigFields; -import com.magmaguy.betterstructures.util.DefaultChestContents; import org.bukkit.World; import java.util.Arrays; @@ -9,7 +8,7 @@ public class GeneratorUndergroundDeepConfig extends GeneratorConfigFields { public GeneratorUndergroundDeepConfig(){ super("generator_underground_deep", true, Arrays.asList(StructureType.UNDERGROUND_DEEP)); - setChestEntries(DefaultChestContents.overworldUndergroundContents()); setValidWorldEnvironments(Arrays.asList(World.Environment.NORMAL, World.Environment.CUSTOM)); + setTreasureFilename("treasure_overworld_underground.yml"); } } diff --git a/src/main/java/com/magmaguy/betterstructures/config/generators/premade/GeneratorUndergroundDripstoneConfig.java b/src/main/java/com/magmaguy/betterstructures/config/generators/premade/GeneratorUndergroundDripstoneConfig.java new file mode 100644 index 0000000..acbfcae --- /dev/null +++ b/src/main/java/com/magmaguy/betterstructures/config/generators/premade/GeneratorUndergroundDripstoneConfig.java @@ -0,0 +1,16 @@ +package com.magmaguy.betterstructures.config.generators.premade; + +import com.magmaguy.betterstructures.config.generators.GeneratorConfigFields; +import org.bukkit.block.Biome; + +import java.util.Arrays; + +public class GeneratorUndergroundDripstoneConfig extends GeneratorConfigFields { + public GeneratorUndergroundDripstoneConfig(){ + super("generator_underground_dripstone", true, Arrays.asList(StructureType.UNDERGROUND_SHALLOW, StructureType.UNDERGROUND_DEEP)); + setValidBiomes(Arrays.asList( + Biome.DRIPSTONE_CAVES, + Biome.CUSTOM)); + setTreasureFilename("treasure_overworld_underground.yml"); + } +} diff --git a/src/main/java/com/magmaguy/betterstructures/config/generators/premade/GeneratorUndergroundEndConfig.java b/src/main/java/com/magmaguy/betterstructures/config/generators/premade/GeneratorUndergroundEndConfig.java index acbd143..205774f 100644 --- a/src/main/java/com/magmaguy/betterstructures/config/generators/premade/GeneratorUndergroundEndConfig.java +++ b/src/main/java/com/magmaguy/betterstructures/config/generators/premade/GeneratorUndergroundEndConfig.java @@ -1,7 +1,6 @@ package com.magmaguy.betterstructures.config.generators.premade; import com.magmaguy.betterstructures.config.generators.GeneratorConfigFields; -import com.magmaguy.betterstructures.util.DefaultChestContents; import org.bukkit.World; import java.util.Arrays; @@ -10,6 +9,6 @@ public class GeneratorUndergroundEndConfig extends GeneratorConfigFields { public GeneratorUndergroundEndConfig() { super("generator_underground_end", true, Arrays.asList(StructureType.UNDERGROUND_SHALLOW)); setValidWorldEnvironments(Arrays.asList(World.Environment.THE_END)); - setChestEntries(DefaultChestContents.overworldUndergroundContents()); + setTreasureFilename("treasure_end.yml"); } } diff --git a/src/main/java/com/magmaguy/betterstructures/config/generators/premade/GeneratorUndergroundLushConfig.java b/src/main/java/com/magmaguy/betterstructures/config/generators/premade/GeneratorUndergroundLushConfig.java new file mode 100644 index 0000000..98d8be3 --- /dev/null +++ b/src/main/java/com/magmaguy/betterstructures/config/generators/premade/GeneratorUndergroundLushConfig.java @@ -0,0 +1,16 @@ +package com.magmaguy.betterstructures.config.generators.premade; + +import com.magmaguy.betterstructures.config.generators.GeneratorConfigFields; +import org.bukkit.block.Biome; + +import java.util.Arrays; + +public class GeneratorUndergroundLushConfig extends GeneratorConfigFields { + public GeneratorUndergroundLushConfig() { + super("generator_underground_lush", true, Arrays.asList(StructureType.UNDERGROUND_SHALLOW, StructureType.UNDERGROUND_DEEP)); + setValidBiomes(Arrays.asList( + Biome.LUSH_CAVES, + Biome.CUSTOM)); + setTreasureFilename("treasure_overworld_underground.yml"); + } +} diff --git a/src/main/java/com/magmaguy/betterstructures/config/generators/premade/GeneratorUndergroundNetherConfig.java b/src/main/java/com/magmaguy/betterstructures/config/generators/premade/GeneratorUndergroundNetherConfig.java index c8fda8b..8cec3f0 100644 --- a/src/main/java/com/magmaguy/betterstructures/config/generators/premade/GeneratorUndergroundNetherConfig.java +++ b/src/main/java/com/magmaguy/betterstructures/config/generators/premade/GeneratorUndergroundNetherConfig.java @@ -1,7 +1,6 @@ package com.magmaguy.betterstructures.config.generators.premade; import com.magmaguy.betterstructures.config.generators.GeneratorConfigFields; -import com.magmaguy.betterstructures.util.DefaultChestContents; import org.bukkit.World; import java.util.Arrays; @@ -10,6 +9,6 @@ public class GeneratorUndergroundNetherConfig extends GeneratorConfigFields { public GeneratorUndergroundNetherConfig(){ super("generator_underground_nether", true, Arrays.asList(StructureType.UNDERGROUND_DEEP, StructureType.UNDERGROUND_SHALLOW)); setValidWorldEnvironments(Arrays.asList(World.Environment.NETHER)); - setChestEntries(DefaultChestContents.netherContents()); + setTreasureFilename("treasure_nether.yml"); } } diff --git a/src/main/java/com/magmaguy/betterstructures/config/generators/premade/GeneratorUndergroundNetherDeep.java b/src/main/java/com/magmaguy/betterstructures/config/generators/premade/GeneratorUndergroundNetherDeep.java index 9d36c79..e5f6251 100644 --- a/src/main/java/com/magmaguy/betterstructures/config/generators/premade/GeneratorUndergroundNetherDeep.java +++ b/src/main/java/com/magmaguy/betterstructures/config/generators/premade/GeneratorUndergroundNetherDeep.java @@ -1,7 +1,6 @@ package com.magmaguy.betterstructures.config.generators.premade; import com.magmaguy.betterstructures.config.generators.GeneratorConfigFields; -import com.magmaguy.betterstructures.util.DefaultChestContents; import org.bukkit.World; import java.util.Arrays; @@ -10,6 +9,6 @@ public class GeneratorUndergroundNetherDeep extends GeneratorConfigFields { public GeneratorUndergroundNetherDeep() { super("generator_underground_nether_deep", true, Arrays.asList(StructureType.UNDERGROUND_DEEP)); setValidWorldEnvironments(Arrays.asList(World.Environment.NETHER)); - setChestEntries(DefaultChestContents.netherContents()); + setTreasureFilename("treasure_nether.yml"); } } diff --git a/src/main/java/com/magmaguy/betterstructures/config/generators/premade/GeneratorUndergroundNetherShallow.java b/src/main/java/com/magmaguy/betterstructures/config/generators/premade/GeneratorUndergroundNetherShallow.java index d1e7ac7..8bf42c3 100644 --- a/src/main/java/com/magmaguy/betterstructures/config/generators/premade/GeneratorUndergroundNetherShallow.java +++ b/src/main/java/com/magmaguy/betterstructures/config/generators/premade/GeneratorUndergroundNetherShallow.java @@ -1,7 +1,6 @@ package com.magmaguy.betterstructures.config.generators.premade; import com.magmaguy.betterstructures.config.generators.GeneratorConfigFields; -import com.magmaguy.betterstructures.util.DefaultChestContents; import org.bukkit.World; import java.util.Arrays; @@ -10,6 +9,6 @@ public class GeneratorUndergroundNetherShallow extends GeneratorConfigFields { public GeneratorUndergroundNetherShallow() { super("generator_underground_nether_shallow", true, Arrays.asList(StructureType.UNDERGROUND_SHALLOW)); setValidWorldEnvironments(Arrays.asList(World.Environment.NETHER)); - setChestEntries(DefaultChestContents.netherContents()); + setTreasureFilename("treasure_nether.yml"); } } diff --git a/src/main/java/com/magmaguy/betterstructures/config/generators/premade/GeneratorUndergroundShallowConfig.java b/src/main/java/com/magmaguy/betterstructures/config/generators/premade/GeneratorUndergroundShallowConfig.java index 94aff8a..7ab225d 100644 --- a/src/main/java/com/magmaguy/betterstructures/config/generators/premade/GeneratorUndergroundShallowConfig.java +++ b/src/main/java/com/magmaguy/betterstructures/config/generators/premade/GeneratorUndergroundShallowConfig.java @@ -1,16 +1,14 @@ package com.magmaguy.betterstructures.config.generators.premade; import com.magmaguy.betterstructures.config.generators.GeneratorConfigFields; -import com.magmaguy.betterstructures.util.DefaultChestContents; import org.bukkit.World; -import java.util.ArrayList; import java.util.Arrays; public class GeneratorUndergroundShallowConfig extends GeneratorConfigFields { public GeneratorUndergroundShallowConfig(){ super("generator_underground_shallow", true, Arrays.asList(StructureType.UNDERGROUND_SHALLOW)); - setChestEntries(DefaultChestContents.overworldUndergroundContents()); setValidWorldEnvironments(Arrays.asList(World.Environment.NORMAL, World.Environment.CUSTOM)); + setTreasureFilename("treasure_overworld_underground.yml"); } } diff --git a/src/main/java/com/magmaguy/betterstructures/config/generators/premade/UndergroundGeneratorGlobalConfig.java b/src/main/java/com/magmaguy/betterstructures/config/generators/premade/UndergroundGeneratorGlobalConfig.java index b40986e..0e91046 100644 --- a/src/main/java/com/magmaguy/betterstructures/config/generators/premade/UndergroundGeneratorGlobalConfig.java +++ b/src/main/java/com/magmaguy/betterstructures/config/generators/premade/UndergroundGeneratorGlobalConfig.java @@ -1,7 +1,6 @@ package com.magmaguy.betterstructures.config.generators.premade; import com.magmaguy.betterstructures.config.generators.GeneratorConfigFields; -import com.magmaguy.betterstructures.util.DefaultChestContents; import org.bukkit.World; import java.util.Arrays; @@ -10,6 +9,7 @@ public class UndergroundGeneratorGlobalConfig extends GeneratorConfigFields { public UndergroundGeneratorGlobalConfig() { super("generator_underground_global", true, Arrays.asList(StructureType.UNDERGROUND_DEEP, StructureType.UNDERGROUND_SHALLOW)); setValidWorldEnvironments(Arrays.asList(World.Environment.NORMAL, World.Environment.CUSTOM)); - setChestEntries(DefaultChestContents.overworldUndergroundContents()); + setTreasureFilename("treasure_overworld_underground.yml"); } } + diff --git a/src/main/java/com/magmaguy/betterstructures/config/schematics/SchematicConfig.java b/src/main/java/com/magmaguy/betterstructures/config/schematics/SchematicConfig.java index dd35148..d15042d 100644 --- a/src/main/java/com/magmaguy/betterstructures/config/schematics/SchematicConfig.java +++ b/src/main/java/com/magmaguy/betterstructures/config/schematics/SchematicConfig.java @@ -36,7 +36,8 @@ public SchematicConfig() { String configurationName = convertFromSchematicFilename(file.getName()); SchematicConfigField schematicConfigField = new SchematicConfigField(configurationName, true); new CustomConfig(file.getParent().replace(MetadataHandler.PLUGIN.getDataFolder().getAbsolutePath() + File.separatorChar, ""), SchematicConfigField.class, schematicConfigField); - schematicConfigurations.put(configurationName, schematicConfigField); + if (schematicConfigField.isEnabled()) + schematicConfigurations.put(configurationName, schematicConfigField); } for (SchematicConfigField schematicConfigField : schematicConfigurations.values()) { diff --git a/src/main/java/com/magmaguy/betterstructures/config/schematics/SchematicConfigField.java b/src/main/java/com/magmaguy/betterstructures/config/schematics/SchematicConfigField.java index bf2107f..1222d5f 100644 --- a/src/main/java/com/magmaguy/betterstructures/config/schematics/SchematicConfigField.java +++ b/src/main/java/com/magmaguy/betterstructures/config/schematics/SchematicConfigField.java @@ -1,8 +1,12 @@ package com.magmaguy.betterstructures.config.schematics; +import com.magmaguy.betterstructures.chests.ChestContents; import com.magmaguy.betterstructures.config.CustomConfigFields; import com.magmaguy.betterstructures.config.generators.GeneratorConfig; import com.magmaguy.betterstructures.config.generators.GeneratorConfigFields; +import com.magmaguy.betterstructures.config.treasures.TreasureConfig; +import com.magmaguy.betterstructures.config.treasures.TreasureConfigFields; +import com.magmaguy.betterstructures.util.WarningMessage; import lombok.Getter; import lombok.Setter; import org.bukkit.Material; @@ -22,6 +26,12 @@ public class SchematicConfigField extends CustomConfigFields { @Getter @Setter private Material pedestalMaterial = null; + @Getter + @Setter + private String treasureFile = null; + @Getter + @Setter + private ChestContents chestContents = null; /** @@ -39,7 +49,21 @@ public void processConfigFields() { this.isEnabled = processBoolean("isEnabled", isEnabled, true, true); this.weight = processDouble("weight", weight, 1, true); this.pedestalMaterial = processEnum("pedestalMaterial", pedestalMaterial, null, Material.class, false); - this.generatorConfigFilename = processString("generatorConfigFilename", generatorConfigFilename, null, true); + this.generatorConfigFilename = processString("generatorConfigFilename", generatorConfigFilename, generatorConfigFilename, true); this.generatorConfigFields = GeneratorConfig.getConfigFields(generatorConfigFilename); + this.treasureFile = processString("treasureFile", treasureFile, null, false); + if (generatorConfigFields == null) { + new WarningMessage("Failed to assign a valid generator to " + filename + "! This will not spawn. Generator config name: " + generatorConfigFilename); + return; + } + this.chestContents = generatorConfigFields.getChestContents(); + if (treasureFile != null && !treasureFile.isEmpty()) { + TreasureConfigFields treasureConfigFields = TreasureConfig.getConfigFields(treasureFile); + if (treasureConfigFields == null) { + new WarningMessage("Failed to get treasure config file " + treasureFile + " for schematic configuration " + filename + " ! Defaulting to the generator treasure."); + return; + } + this.chestContents = treasureConfigFields.getChestContents(); + } } } diff --git a/src/main/java/com/magmaguy/betterstructures/config/treasures/TreasureConfig.java b/src/main/java/com/magmaguy/betterstructures/config/treasures/TreasureConfig.java new file mode 100644 index 0000000..2c92bcc --- /dev/null +++ b/src/main/java/com/magmaguy/betterstructures/config/treasures/TreasureConfig.java @@ -0,0 +1,22 @@ +package com.magmaguy.betterstructures.config.treasures; + +import com.magmaguy.betterstructures.config.CustomConfig; +import lombok.Getter; + +import java.util.HashMap; + +public class TreasureConfig extends CustomConfig { + @Getter + private static HashMap treasureConfigurations = new HashMap<>(); + + public TreasureConfig() { + super("treasures", "com.magmaguy.betterstructures.config.treasures.premade", TreasureConfigFields.class); + for (String key : super.getCustomConfigFieldsHashMap().keySet()) { + treasureConfigurations.put(key, (TreasureConfigFields) super.getCustomConfigFieldsHashMap().get(key)); + } + } + + public static TreasureConfigFields getConfigFields(String configurationFilename) { + return treasureConfigurations.get(configurationFilename); + } +} diff --git a/src/main/java/com/magmaguy/betterstructures/config/treasures/TreasureConfigFields.java b/src/main/java/com/magmaguy/betterstructures/config/treasures/TreasureConfigFields.java new file mode 100644 index 0000000..0c4b86d --- /dev/null +++ b/src/main/java/com/magmaguy/betterstructures/config/treasures/TreasureConfigFields.java @@ -0,0 +1,135 @@ +package com.magmaguy.betterstructures.config.treasures; + +import com.magmaguy.betterstructures.MetadataHandler; +import com.magmaguy.betterstructures.chests.ChestContents; +import com.magmaguy.betterstructures.config.CustomConfigFields; +import com.magmaguy.betterstructures.util.DefaultChestContents; +import com.magmaguy.betterstructures.util.InfoMessage; +import com.magmaguy.betterstructures.util.WarningMessage; +import lombok.Getter; +import lombok.Setter; +import org.bukkit.Material; +import org.bukkit.NamespacedKey; +import org.bukkit.configuration.ConfigurationSection; +import org.bukkit.configuration.MemorySection; +import org.bukkit.enchantments.Enchantment; +import org.bukkit.entity.Player; +import org.bukkit.inventory.meta.ItemMeta; + +import java.util.ArrayList; +import java.util.HashMap; +import java.util.List; +import java.util.Map; +import java.util.concurrent.ThreadLocalRandom; + +public class TreasureConfigFields extends CustomConfigFields { + + @Getter + private final Map> enchantmentSettings = new HashMap<>(); + private final List seenInvalidKeys = new ArrayList<>(); + @Getter + @Setter + private Map rawLoot = new HashMap(); + @Setter + private Map rawEnchantmentSettings = new HashMap<>(); + @Getter + @Setter + private ChestContents chestContents = null; + @Getter + @Setter + private double mean = 4; + @Getter + @Setter + private double standardDeviation = 3; + + public TreasureConfigFields(String filename, boolean isEnabled) { + super(filename, isEnabled); + } + + @Override + public void processConfigFields() { + this.isEnabled = processBoolean("isEnabled", isEnabled, true, true); + this.rawLoot = processMap("items", rawLoot); + this.rawEnchantmentSettings = processMap("procedurallyGeneratedItemSettings", DefaultChestContents.generateProcedurallyGeneratedItems()); + this.mean = processDouble("mean", mean, 4, true); + this.standardDeviation = processDouble("standardDeviation", standardDeviation, 3, true); + chestContents = new ChestContents(this); + parseEnchantmentSettings(); + } + + private void parseEnchantmentSettings() { + for (Map.Entry stringObjectEntry : rawEnchantmentSettings.entrySet()) { + Material material = Material.matchMaterial(stringObjectEntry.getKey()); + if (material == null) { + new WarningMessage("Incorrect material entry for enchantment settings of the configuration file " + filename); + continue; + } + List configurationEnchantments = new ArrayList<>(); + Map enchantments = ((MemorySection) stringObjectEntry.getValue()).getValues(false); + for (Map.Entry enchantmentsEntry : enchantments.entrySet()) { + Enchantment enchantment = Enchantment.getByKey(NamespacedKey.minecraft(enchantmentsEntry.getKey())); + if (enchantment == null && !seenInvalidKeys.contains(enchantmentsEntry.getKey())) { + new InfoMessage("Failed to get valid enchantment from key " + enchantmentsEntry.getKey() + " in configuration file " + filename + " ! This is almost certainly because another plugin " + "is using enchantments that are pretending to be vanilla Minecraft enchantments, when they aren't, " + "and doing so in a way that doesn't allow items to be enchanted via normal means. This enchantment " + "will be ignored for generating items, you can ignore this warning if you didn't plan to use this " + "enchantment in the first place. Warnings about this specific enchantment will now be suppressed."); + seenInvalidKeys.add(enchantmentsEntry.getKey()); + continue; + } + int minLevel = 1; + int maxLevel = 1; + double chance = 0; + for (Map.Entry enchantmentValue : ((ConfigurationSection) (enchantmentsEntry.getValue())).getValues(false).entrySet()) { + switch (enchantmentValue.getKey().toLowerCase()) { + case "minlevel": + minLevel = Integer.parseInt(enchantmentValue.getValue().toString()); + break; + case "maxlevel": + maxLevel = Integer.parseInt(enchantmentValue.getValue().toString()); + break; + case "chance": + chance = Double.parseDouble(enchantmentValue.getValue().toString()); + break; + default: + new WarningMessage("Invalid key for setting " + enchantmentValue.getKey() + " in file " + filename); + } + } + configurationEnchantments.add(new ConfigurationEnchantment(enchantment, minLevel, maxLevel, chance)); + } + enchantmentSettings.put(material, configurationEnchantments); + } + } + + public void addChestEntry(Map entry, String rarity, Player player) { + List> mapList = ((ConfigurationSection) rawLoot.get(rarity)).getMapList("items"); + mapList.add(entry); + fileConfiguration.set("items." + rarity, Map.of("weight", ((ConfigurationSection) rawLoot.get(rarity)).getDouble("weight"), "items", mapList)); + try { + fileConfiguration.save(file); + } catch (Exception ex) { + player.sendMessage("[BetterStructures] Failed to save entry to file! Report this to the developer."); + return; + } + MetadataHandler.PLUGIN.onDisable(); + MetadataHandler.PLUGIN.onLoad(); + MetadataHandler.PLUGIN.onEnable(); + player.sendMessage("[BetterStructures] Reloaded plugin to add chest entry! It should now be live."); + } + + public class ConfigurationEnchantment { + private final Enchantment enchantment; + private final int minLevel; + private final int maxLevel; + private final double chance; + + public ConfigurationEnchantment(Enchantment enchantment, int minLevel, int maxLevel, double chance) { + this.enchantment = enchantment; + this.minLevel = minLevel; + this.maxLevel = maxLevel; + this.chance = chance; + } + + public void rollEnchantment(ItemMeta itemMeta) { + if (ThreadLocalRandom.current().nextDouble() >= chance) return; + int level = ThreadLocalRandom.current().nextInt(minLevel, maxLevel + 1); + if (itemMeta != null && enchantment != null) itemMeta.addEnchant(enchantment, level, true); + } + } +} diff --git a/src/main/java/com/magmaguy/betterstructures/config/treasures/premade/EndTreasureConfig.java b/src/main/java/com/magmaguy/betterstructures/config/treasures/premade/EndTreasureConfig.java new file mode 100644 index 0000000..2472508 --- /dev/null +++ b/src/main/java/com/magmaguy/betterstructures/config/treasures/premade/EndTreasureConfig.java @@ -0,0 +1,11 @@ +package com.magmaguy.betterstructures.config.treasures.premade; + +import com.magmaguy.betterstructures.config.treasures.TreasureConfigFields; +import com.magmaguy.betterstructures.util.DefaultChestContents; + +public class EndTreasureConfig extends TreasureConfigFields { + public EndTreasureConfig() { + super("treasure_end", true); + setRawLoot(DefaultChestContents.endContents()); + } +} diff --git a/src/main/java/com/magmaguy/betterstructures/config/treasures/premade/NetherTreasureConfig.java b/src/main/java/com/magmaguy/betterstructures/config/treasures/premade/NetherTreasureConfig.java new file mode 100644 index 0000000..9d0aaaa --- /dev/null +++ b/src/main/java/com/magmaguy/betterstructures/config/treasures/premade/NetherTreasureConfig.java @@ -0,0 +1,11 @@ +package com.magmaguy.betterstructures.config.treasures.premade; + +import com.magmaguy.betterstructures.config.treasures.TreasureConfigFields; +import com.magmaguy.betterstructures.util.DefaultChestContents; + +public class NetherTreasureConfig extends TreasureConfigFields { + public NetherTreasureConfig() { + super("treasure_nether", true); + setRawLoot(DefaultChestContents.netherContents()); + } +} diff --git a/src/main/java/com/magmaguy/betterstructures/config/treasures/premade/OverworldSurfaceTreasureConfig.java b/src/main/java/com/magmaguy/betterstructures/config/treasures/premade/OverworldSurfaceTreasureConfig.java new file mode 100644 index 0000000..f8259e0 --- /dev/null +++ b/src/main/java/com/magmaguy/betterstructures/config/treasures/premade/OverworldSurfaceTreasureConfig.java @@ -0,0 +1,11 @@ +package com.magmaguy.betterstructures.config.treasures.premade; + +import com.magmaguy.betterstructures.config.treasures.TreasureConfigFields; +import com.magmaguy.betterstructures.util.DefaultChestContents; + +public class OverworldSurfaceTreasureConfig extends TreasureConfigFields { + public OverworldSurfaceTreasureConfig() { + super("treasure_overworld_surface", true); + super.setRawLoot(DefaultChestContents.overworldContents()); + } +} diff --git a/src/main/java/com/magmaguy/betterstructures/config/treasures/premade/OverworldUndergroundTreasureConfig.java b/src/main/java/com/magmaguy/betterstructures/config/treasures/premade/OverworldUndergroundTreasureConfig.java new file mode 100644 index 0000000..5ef1703 --- /dev/null +++ b/src/main/java/com/magmaguy/betterstructures/config/treasures/premade/OverworldUndergroundTreasureConfig.java @@ -0,0 +1,11 @@ +package com.magmaguy.betterstructures.config.treasures.premade; + +import com.magmaguy.betterstructures.config.treasures.TreasureConfigFields; +import com.magmaguy.betterstructures.util.DefaultChestContents; + +public class OverworldUndergroundTreasureConfig extends TreasureConfigFields { + public OverworldUndergroundTreasureConfig() { + super("treasure_overworld_underground", true); + setRawLoot(DefaultChestContents.overworldUndergroundContents()); + } +} diff --git a/src/main/java/com/magmaguy/betterstructures/config/treasures/premade/SpecialTreasureConfig.java b/src/main/java/com/magmaguy/betterstructures/config/treasures/premade/SpecialTreasureConfig.java new file mode 100644 index 0000000..9baecd1 --- /dev/null +++ b/src/main/java/com/magmaguy/betterstructures/config/treasures/premade/SpecialTreasureConfig.java @@ -0,0 +1,9 @@ +package com.magmaguy.betterstructures.config.treasures.premade; + +import com.magmaguy.betterstructures.config.treasures.TreasureConfigFields; + +public class SpecialTreasureConfig extends TreasureConfigFields { + public SpecialTreasureConfig() { + super("treasure_special", true); + } +} diff --git a/src/main/java/com/magmaguy/betterstructures/configurationimporter/Import.java b/src/main/java/com/magmaguy/betterstructures/configurationimporter/Import.java new file mode 100644 index 0000000..cd8c0bb --- /dev/null +++ b/src/main/java/com/magmaguy/betterstructures/configurationimporter/Import.java @@ -0,0 +1,148 @@ +package com.magmaguy.betterstructures.configurationimporter; + +import com.magmaguy.betterstructures.MetadataHandler; +import com.magmaguy.betterstructures.thirdparty.EliteMobs; +import com.magmaguy.betterstructures.util.InfoMessage; +import com.magmaguy.betterstructures.util.WarningMessage; +import com.magmaguy.betterstructures.util.ZipFile; +import org.bukkit.Bukkit; + +import java.io.File; +import java.nio.file.Files; +import java.nio.file.Path; +import java.nio.file.Paths; +import java.nio.file.StandardCopyOption; + +public class Import { + //let's get some files + private static File importFolder; + private static File schematicsFolder; + private static File generatorsFolder; + private static File treasuresFolder; + private static File eliteMobsBossFolder; + + + public static void initialize() { + String importFolderDirectory = MetadataHandler.PLUGIN.getDataFolder().getAbsolutePath() + File.separatorChar + "imports"; + String schematicsFolderDirectory = MetadataHandler.PLUGIN.getDataFolder().getAbsolutePath() + File.separatorChar + "schematics"; + String generatorsFolderDirectory = MetadataHandler.PLUGIN.getDataFolder().getAbsolutePath() + File.separatorChar + "generators"; + String treasuresFolderDirectory = MetadataHandler.PLUGIN.getDataFolder().getAbsolutePath() + File.separatorChar + "treasures"; + + String eliteMobsBossFolderDirectory = MetadataHandler.PLUGIN.getDataFolder().getParentFile().getAbsolutePath() + File.separatorChar + "EliteMobs" + File.separatorChar; + + importFolder = new File(importFolderDirectory); + //Create imports folder if there isn't one yet + if (!importFolder.exists()) importFolder.mkdir(); + + //BetterStructures files are already initialized at this point + schematicsFolder = new File(schematicsFolderDirectory); + generatorsFolder = new File(generatorsFolderDirectory); + treasuresFolder = new File(treasuresFolderDirectory); + + //EliteMobs may not be installed, but if content is installed that uses its files a directory will be created as a placeholder in preparation for EliteMobs + eliteMobsBossFolder = new File(eliteMobsBossFolderDirectory); + + //Time to import + importPackages(); + } + + private static void importPackages() { + boolean eliteFilesFound = false; + for (File zippedFile : importFolder.listFiles()) { + File unzippedFile; + try { + if (zippedFile.getName().contains(".zip")) + unzippedFile = ZipFile.unzip(zippedFile.getName()); + else unzippedFile = zippedFile; + } catch (Exception e) { + new WarningMessage("Failed to unzip config file " + zippedFile.getName() + " ! Tell the dev!"); + e.printStackTrace(); + continue; + } + try { + for (File file : unzippedFile.listFiles()) { + switch (file.getName()) { + case "schematics": + moveDirectory(file, schematicsFolder.toPath(), false); + break; + case "generators": + moveDirectory(file, generatorsFolder.toPath(), false); + break; + case "treasures": + moveDirectory(file, treasuresFolder.toPath(), false); + break; + case "elitemobs": + if (!eliteMobsBossFolder.exists()) eliteMobsBossFolder.mkdirs(); + moveDirectory(file, eliteMobsBossFolder.toPath(), false); + eliteFilesFound = true; + break; + default: + new WarningMessage("Directory " + file.getName() + " for zipped file " + zippedFile.getName() + " was not a recognized directory for the file import system! Was the zipped file packaged correctly?"); + } + deleteDirectory(file); + } + } catch (Exception e) { + new WarningMessage("Failed to move files from " + zippedFile.getName() + " ! Tell the dev!"); + e.printStackTrace(); + continue; + } + try { + unzippedFile.delete(); + zippedFile.delete(); + } catch (Exception ex) { + new WarningMessage("Failed to delete zipped file " + zippedFile.getName() + "! Tell the dev!"); + ex.printStackTrace(); + } + } + + //Reload EliteMobs to use the newly imported files + if (eliteFilesFound && Bukkit.getPluginManager().getPlugin("EliteMobs") != null) + EliteMobs.Reload(); + } + + private static void deleteDirectory(File file) { + if (file == null) + return; + if (file.isDirectory()) + for (File iteratedFile : file.listFiles()) + if (iteratedFile != null) + deleteDirectory(iteratedFile); + new InfoMessage("Cleaning up " + file.getPath()); + file.delete(); + } + + + private static void moveDirectory(File unzippedDirectory, Path targetPath, boolean force) { + for (File file : unzippedDirectory.listFiles()) + try { + new InfoMessage("Adding " + file.getCanonicalPath()); + moveFile(file, targetPath, force); + } catch (Exception exception) { + new WarningMessage("Failed to move directories for " + file.getName() + "! Tell the dev!"); + exception.printStackTrace(); + } + } + + private static void moveFile(File file, Path targetPath, boolean force) { + try { + if (file.isDirectory()) { + if (Paths.get(targetPath + "" + File.separatorChar + file.getName()).toFile().exists()) + for (File iteratedFile : file.listFiles()) + moveFile(iteratedFile, Paths.get(targetPath + "" + File.separatorChar + file.getName()), force); + else + Files.move(file.toPath(), Paths.get(targetPath + "" + File.separatorChar + file.getName()), StandardCopyOption.REPLACE_EXISTING); + } else if (targetPath.toFile().exists()) + Files.move(file.toPath(), Paths.get(targetPath + "" + File.separatorChar + file.getName()), StandardCopyOption.REPLACE_EXISTING); + else if (!Paths.get(targetPath + "" + File.separatorChar + file.getName()).toFile().exists() && force) { + File newFile = Paths.get(targetPath + "" + File.separatorChar + file.getName()).toFile(); + newFile.mkdirs(); + newFile.createNewFile(); + Files.move(file.toPath(), newFile.toPath(), StandardCopyOption.REPLACE_EXISTING); + } + } catch (Exception exception) { + new WarningMessage("Failed to move directories for " + file.getName() + "! Tell the dev!"); + exception.printStackTrace(); + } + } +} + diff --git a/src/main/java/com/magmaguy/betterstructures/listeners/NewChunkLoadEvent.java b/src/main/java/com/magmaguy/betterstructures/listeners/NewChunkLoadEvent.java index 8b88568..22bc1c6 100644 --- a/src/main/java/com/magmaguy/betterstructures/listeners/NewChunkLoadEvent.java +++ b/src/main/java/com/magmaguy/betterstructures/listeners/NewChunkLoadEvent.java @@ -6,11 +6,10 @@ import com.magmaguy.betterstructures.buildingfitter.FitSurfaceBuilding; import com.magmaguy.betterstructures.buildingfitter.FitUndergroundShallowBuilding; import com.magmaguy.betterstructures.buildingfitter.util.FitUndergroundDeepBuilding; +import com.magmaguy.betterstructures.config.DefaultConfig; import com.magmaguy.betterstructures.config.ValidWorldsConfig; import com.magmaguy.betterstructures.config.generators.GeneratorConfigFields; import com.magmaguy.betterstructures.schematics.SchematicContainer; -import com.magmaguy.betterstructures.util.SimplexNoise; -import org.bukkit.Bukkit; import org.bukkit.Chunk; import org.bukkit.event.EventHandler; import org.bukkit.event.EventPriority; @@ -20,16 +19,12 @@ import java.util.HashSet; import java.util.Random; +import java.util.concurrent.ThreadLocalRandom; public class NewChunkLoadEvent implements Listener { private static HashSet loadingChunks = new HashSet<>(); private static Random random = null; - private static int surfaceOffset; - private static int shallowUndergroundOffset; - private static int deepUndergroundOffset; - private static int airOffset; - private static int liquidOffset; @EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true) public void onChunkLoad(ChunkLoadEvent event) { @@ -44,60 +39,52 @@ public void run() { } }.runTaskLater(MetadataHandler.PLUGIN, 20L); if (!ValidWorldsConfig.isValidWorld(event.getWorld())) return; - Bukkit.getScheduler().runTaskAsynchronously(MetadataHandler.PLUGIN, bukkitTask -> { - if (random == null) { - random = new Random(event.getChunk().getWorld().getSeed()); - surfaceOffset = random.nextInt(1, 1000000); - shallowUndergroundOffset = random.nextInt(1, 100000); - deepUndergroundOffset = random.nextInt(1, 10000); - airOffset = random.nextInt(1, 1000); - liquidOffset = random.nextInt(1, 100); - } - surfaceScanner(event.getChunk()); - shallowUndergroundScanner(event.getChunk()); - deepUndergroundScanner(event.getChunk()); - skyScanner(event.getChunk()); - liquidSurfaceScanner(event.getChunk()); - }); + if (random == null) { + random = new Random(); + } + surfaceScanner(event.getChunk()); + shallowUndergroundScanner(event.getChunk()); + deepUndergroundScanner(event.getChunk()); + skyScanner(event.getChunk()); + liquidSurfaceScanner(event.getChunk()); + } private void surfaceScanner(Chunk chunk) { if (SchematicContainer.getSchematics().get(GeneratorConfigFields.StructureType.SURFACE).isEmpty()) return; - if (!seededSimplexRandomization(chunk, 0.95, surfaceOffset)) return; + if (ThreadLocalRandom.current().nextDouble() > DefaultConfig.getLandStructuresPerThousandChunks() / 1000D) + return; new FitSurfaceBuilding(chunk); } private void shallowUndergroundScanner(Chunk chunk) { if (SchematicContainer.getSchematics().get(GeneratorConfigFields.StructureType.UNDERGROUND_SHALLOW).isEmpty()) return; - if (!seededSimplexRandomization(chunk, 0.95, shallowUndergroundOffset)) return; + if (ThreadLocalRandom.current().nextDouble() > DefaultConfig.getShallowUndergroundStructuresPerThousandChunks() / 1000D) + return; FitUndergroundShallowBuilding.fit(chunk); } private void deepUndergroundScanner(Chunk chunk) { if (SchematicContainer.getSchematics().get(GeneratorConfigFields.StructureType.UNDERGROUND_DEEP).isEmpty()) return; - if (!seededSimplexRandomization(chunk, 0.95, deepUndergroundOffset)) return; + if (ThreadLocalRandom.current().nextDouble() > DefaultConfig.getDeepUndergroundStructuresPerThousandChunks() / 1000D) + return; FitUndergroundDeepBuilding.fit(chunk); } private void skyScanner(Chunk chunk) { if (SchematicContainer.getSchematics().get(GeneratorConfigFields.StructureType.SKY).isEmpty()) return; - if (!seededSimplexRandomization(chunk, 0.99, airOffset)) return; + if (ThreadLocalRandom.current().nextDouble() > DefaultConfig.getAirStructuresPerThousandChunks() / 1000D) + return; new FitAirBuilding(chunk); } private void liquidSurfaceScanner(Chunk chunk) { if (SchematicContainer.getSchematics().get(GeneratorConfigFields.StructureType.LIQUID_SURFACE).isEmpty()) return; - if (!seededSimplexRandomization(chunk, 0.99, liquidOffset)) + if (ThreadLocalRandom.current().nextDouble() > DefaultConfig.getOceanStructuresPerThousandChunks() / 1000D) return; new FitLiquidBuilding(chunk); } - - - private boolean seededSimplexRandomization(Chunk chunk, double strictness, int offset) { - return (SimplexNoise.noise(chunk.getX() + (double) offset, chunk.getZ() + (double) offset) > strictness); - } - } diff --git a/src/main/java/com/magmaguy/betterstructures/schematics/AbstractBlock.java b/src/main/java/com/magmaguy/betterstructures/schematics/AbstractBlock.java new file mode 100644 index 0000000..deb1fef --- /dev/null +++ b/src/main/java/com/magmaguy/betterstructures/schematics/AbstractBlock.java @@ -0,0 +1,11 @@ +package com.magmaguy.betterstructures.schematics; + +import org.bukkit.Material; + +import java.util.Vector; + +public class AbstractBlock { + public AbstractBlock(Vector offset, Material material){ + + } +} diff --git a/src/main/java/com/magmaguy/betterstructures/schematics/SchematicContainer.java b/src/main/java/com/magmaguy/betterstructures/schematics/SchematicContainer.java index f6c710a..0fef2e5 100644 --- a/src/main/java/com/magmaguy/betterstructures/schematics/SchematicContainer.java +++ b/src/main/java/com/magmaguy/betterstructures/schematics/SchematicContainer.java @@ -1,15 +1,20 @@ package com.magmaguy.betterstructures.schematics; import com.google.common.collect.ArrayListMultimap; +import com.magmaguy.betterstructures.chests.ChestContents; import com.magmaguy.betterstructures.config.generators.GeneratorConfigFields; import com.magmaguy.betterstructures.config.schematics.SchematicConfigField; +import com.magmaguy.betterstructures.config.treasures.TreasureConfig; +import com.magmaguy.betterstructures.config.treasures.TreasureConfigFields; import com.magmaguy.betterstructures.util.WarningMessage; +import com.magmaguy.betterstructures.util.WorldEditUtils; import com.sk89q.worldedit.bukkit.BukkitAdapter; import com.sk89q.worldedit.extent.clipboard.Clipboard; import com.sk89q.worldedit.math.BlockVector3; import com.sk89q.worldedit.world.block.BaseBlock; import com.sk89q.worldedit.world.block.BlockState; import lombok.Getter; +import org.bukkit.Bukkit; import org.bukkit.Material; import org.bukkit.World; import org.bukkit.block.Biome; @@ -17,17 +22,13 @@ import org.bukkit.util.Vector; import java.util.ArrayList; +import java.util.Arrays; import java.util.HashMap; import java.util.List; public class SchematicContainer { @Getter private static final ArrayListMultimap schematics = ArrayListMultimap.create(); - - public static void shutdown() { - schematics.clear(); - } - @Getter private final Clipboard clipboard; @Getter @@ -42,6 +43,20 @@ public static void shutdown() { private final List chestLocations = new ArrayList<>(); @Getter private final HashMap vanillaSpawns = new HashMap<>(); + @Getter + private final HashMap eliteMobsSpawns = new HashMap<>(); + @Getter + private final HashMap mythicMobsSpawns = new HashMap<>(); // carm - Support for MythicMobs + @Getter + List abstractBlocks = new ArrayList<>(); + @Getter + private ChestContents chestContents = null; + @Getter + private boolean valid = true; + + private List signs = Arrays.stream(Material.values()).parallel() + .filter(it -> it.name().endsWith("SIGN")) + .toList(); public SchematicContainer(Clipboard clipboard, String clipboardFilename, SchematicConfigField schematicConfigField, String configFilename) { this.clipboard = clipboard; @@ -49,12 +64,9 @@ public SchematicContainer(Clipboard clipboard, String clipboardFilename, Schemat this.schematicConfigField = schematicConfigField; this.configFilename = configFilename; generatorConfigFields = schematicConfigField.getGeneratorConfigFields(); - if (generatorConfigFields != null) - generatorConfigFields.getStructureTypes().forEach(structureType -> schematics.put(structureType, this)); - else - schematics.put(GeneratorConfigFields.StructureType.UNDEFINED, this); if (generatorConfigFields == null) { new WarningMessage("Failed to assign generator for configuration of schematic " + schematicConfigField.getFilename() + " ! This means this structure will not appear in the world."); + return; } for (int x = 0; x <= clipboard.getDimensions().getX(); x++) for (int y = 0; y <= clipboard.getDimensions().getY(); y++) @@ -62,60 +74,89 @@ public SchematicContainer(Clipboard clipboard, String clipboardFilename, Schemat BlockVector3 translatedLocation = BlockVector3.at(x, y, z).add(clipboard.getMinimumPoint()); BlockState weBlockState = clipboard.getBlock(translatedLocation); Material minecraftMaterial = BukkitAdapter.adapt(weBlockState.getBlockType()); + if (minecraftMaterial == null) continue; //register chest location if (minecraftMaterial.equals(Material.CHEST) || minecraftMaterial.equals(Material.TRAPPED_CHEST) || minecraftMaterial.equals(Material.SHULKER_BOX)) { chestLocations.add(new Vector(x, y, z)); } - if (minecraftMaterial.equals(Material.ACACIA_SIGN) || - minecraftMaterial.equals(Material.ACACIA_WALL_SIGN) || - minecraftMaterial.equals(Material.SPRUCE_SIGN) || - minecraftMaterial.equals(Material.SPRUCE_WALL_SIGN) || - minecraftMaterial.equals(Material.BIRCH_SIGN) || - minecraftMaterial.equals(Material.BIRCH_WALL_SIGN) || - minecraftMaterial.equals(Material.CRIMSON_SIGN) || - minecraftMaterial.equals(Material.CRIMSON_WALL_SIGN) || - minecraftMaterial.equals(Material.DARK_OAK_SIGN) || - minecraftMaterial.equals(Material.DARK_OAK_WALL_SIGN) || - minecraftMaterial.equals(Material.JUNGLE_SIGN) || - minecraftMaterial.equals(Material.JUNGLE_WALL_SIGN) || - minecraftMaterial.equals(Material.OAK_SIGN) || - minecraftMaterial.equals(Material.OAK_WALL_SIGN) || - minecraftMaterial.equals(Material.WARPED_SIGN) || - minecraftMaterial.equals(Material.WARPED_WALL_SIGN)) { + + if (signs.contains(minecraftMaterial)) { BaseBlock baseBlock = clipboard.getFullBlock(translatedLocation); //For future reference, I don't know how to get the data in any other way than parsing the string. Sorry! - String line1 = baseBlock.getNbtData().getString("Text1"); + String line1 = WorldEditUtils.getLine(baseBlock, 1); + //Case for spawning a vanilla mob if (line1.toLowerCase().contains("[spawn]")) { - String line2 = baseBlock.getNbtData().getString("Text2"); - line2 = line2.toUpperCase(); - String value = line2.split(":")[1].replace("\"", "").replace("}", ""); + String line2 = WorldEditUtils.getLine(baseBlock, 2).toUpperCase().replaceAll("\"", ""); EntityType entityType; try { - entityType = EntityType.valueOf(value); + entityType = EntityType.valueOf(line2); } catch (Exception ex) { - new WarningMessage("Failed to determine entity type for sign! Entry was " + value + " in schematic " + clipboardFilename + " ! Fix this by inputting a valid entity type!"); + new WarningMessage("Failed to determine entity type for sign! Entry was " + line2 + " in schematic " + clipboardFilename + " ! Fix this by inputting a valid entity type!"); continue; } vanillaSpawns.put(new Vector(x, y, z), entityType); } else if (line1.toLowerCase().contains("[elitemobs]")) { - //todo: elitemobs integration goes here - } + if (Bukkit.getPluginManager().getPlugin("EliteMobs") == null) { + Bukkit.getLogger().warning("[BetterStructures] " + configFilename + " uses EliteMobs bosses but you do not have EliteMobs installed! BetterStructures does not require EliteMobs to work, but if you want cool EliteMobs boss fights you will have to install EliteMobs here: https://www.spigotmc.org/resources/%E2%9A%94elitemobs%E2%9A%94.40090/"); + Bukkit.getLogger().warning("[BetterStructures] Since EliteMobs is not installed, " + configFilename + " will not be used."); + valid = false; + return; + } + String filename = ""; + for (int i = 2; i < 5; i++) filename += WorldEditUtils.getLine(baseBlock, i); + eliteMobsSpawns.put(new Vector(x, y, z), filename); + } else if (line1.toLowerCase().contains("[mythicmobs]")) { // carm start - Support MythicMobs + if (Bukkit.getPluginManager().getPlugin("MythicMobs") == null) { + Bukkit.getLogger().warning("[BetterStructures] " + configFilename + " uses MythicMobs bosses but you do not have MythicMobs installed! BetterStructures does not require MythicMobs to work, but if you want MythicMobs boss fights you will have to install MythicMobs."); + Bukkit.getLogger().warning("[BetterStructures] Since MythicMobs is not installed, " + configFilename + " will not be used."); + valid = false; + return; + } + String mob = WorldEditUtils.getLine(baseBlock, 2); + String level = WorldEditUtils.getLine(baseBlock, 3); + mythicMobsSpawns.put(new Vector(x, y, z), mob + (level.isEmpty() ? "" : ":" + level)); + } // carm end - Support MythicMobs } } + chestContents = generatorConfigFields.getChestContents(); + if (schematicConfigField.getTreasureFile() != null && !schematicConfigField.getTreasureFile().isEmpty()) { + TreasureConfigFields treasureConfigFields = TreasureConfig.getConfigFields(schematicConfigField.getFilename()); + if (treasureConfigFields == null) { + new WarningMessage("Failed to get treasure configuration " + schematicConfigField.getTreasureFile()); + return; + } + chestContents = schematicConfigField.getChestContents(); + } + if (valid) + generatorConfigFields.getStructureTypes().forEach(structureType -> schematics.put(structureType, this)); + } + + public static void shutdown() { + schematics.clear(); } public boolean isValidEnvironment(World.Environment environment) { - return generatorConfigFields.getValidWorldEnvironments().isEmpty() || generatorConfigFields.getValidWorldEnvironments().contains(environment); + return generatorConfigFields.getValidWorldEnvironments() == null || + generatorConfigFields.getValidWorldEnvironments().isEmpty() || + generatorConfigFields.getValidWorldEnvironments().contains(environment); } public boolean isValidBiome(Biome biome) { - return generatorConfigFields.getValidBiomes().isEmpty() || generatorConfigFields.getValidBiomes().contains(biome); + return generatorConfigFields.getValidBiomes() == null || + generatorConfigFields.getValidBiomes().isEmpty() || + generatorConfigFields.getValidBiomes().contains(biome); } public boolean isValidYLevel(int yLevel) { return generatorConfigFields.getLowestYLevel() <= yLevel && generatorConfigFields.getHighestYLevel() >= yLevel; } + + public boolean isValidWorld(String worldName) { + return generatorConfigFields.getValidWorlds() == null || + generatorConfigFields.getValidWorlds().isEmpty() || + generatorConfigFields.getValidWorlds().contains(worldName); + } } diff --git a/src/main/java/com/magmaguy/betterstructures/thirdparty/EliteMobs.java b/src/main/java/com/magmaguy/betterstructures/thirdparty/EliteMobs.java new file mode 100644 index 0000000..1dda6ef --- /dev/null +++ b/src/main/java/com/magmaguy/betterstructures/thirdparty/EliteMobs.java @@ -0,0 +1,41 @@ +package com.magmaguy.betterstructures.thirdparty; + +import com.magmaguy.betterstructures.util.ChatColorConverter; +import com.magmaguy.betterstructures.util.WarningMessage; +import com.magmaguy.elitemobs.commands.admin.ReloadCommand; +import com.magmaguy.elitemobs.mobconstructor.custombosses.RegionalBossEntity; +import org.bukkit.Bukkit; +import org.bukkit.Location; +import org.bukkit.entity.Player; + +public class EliteMobs { + /** + * Spawns a 1-time regional boss at the set location + * + * @param location Location where the boss should spawn + * @param filename Filename of the boss, as set in the EliteMobs custombosses configuration folder + */ + public static boolean Spawn(Location location, String filename) { + if (Bukkit.getPluginManager().getPlugin("EliteMobs") != null) { + RegionalBossEntity regionalBossEntity = RegionalBossEntity.SpawnRegionalBoss(filename, location); + if (regionalBossEntity == null) { + new WarningMessage("Failed to spawn regional boss " + filename + "! The filename for this boss probably does not match the filename that should be in ~/plugins/EliteMobs/custombosses/"); + return false; + } else { + regionalBossEntity.spawn(false); + return true; + } + } else { + for (Player player : Bukkit.getOnlinePlayers()) + if (player.hasPermission("betterstructures.*")) + player.sendMessage(ChatColorConverter.convert( + "&8[BetterStructures] &cOne of your packs uses the EliteMobs plugin &4but EliteMobs is not currently installed on your server&c!" + + " &2You can download it here: &9https://www.spigotmc.org/resources/%E2%9A%94elitemobs%E2%9A%94.40090/")); + return false; + } + } + + public static void Reload() { + ReloadCommand.reload(Bukkit.getConsoleSender()); + } +} diff --git a/src/main/java/com/magmaguy/betterstructures/thirdparty/MythicMobs.java b/src/main/java/com/magmaguy/betterstructures/thirdparty/MythicMobs.java new file mode 100644 index 0000000..51e305c --- /dev/null +++ b/src/main/java/com/magmaguy/betterstructures/thirdparty/MythicMobs.java @@ -0,0 +1,52 @@ +package com.magmaguy.betterstructures.thirdparty; + +import com.magmaguy.betterstructures.util.ChatColorConverter; +import com.magmaguy.betterstructures.util.WarningMessage; +import io.lumine.mythic.api.mobs.MythicMob; +import io.lumine.mythic.bukkit.BukkitAdapter; +import io.lumine.mythic.bukkit.MythicBukkit; +import org.bukkit.Bukkit; +import org.bukkit.Location; +import org.bukkit.entity.Player; + +/** + * Support for MythicMobs, configuration format is "MobID[:level]" + * + * @author CarmJos + */ +public class MythicMobs { + + public static boolean Spawn(Location location, String filename) { + if (Bukkit.getPluginManager().getPlugin("MythicMobs") == null) { + for (Player player : Bukkit.getOnlinePlayers()) { + if (player.hasPermission("betterstructures.*")) { + player.sendMessage(ChatColorConverter.convert( + "&8[BetterStructures] &cOne of your packs uses the MythicMobs plugin &4but MythicMobs is not currently installed on your server&c!" + + " &2You can download it here: &9https://www.spigotmc.org/resources/%E2%9A%94-mythicmobs-free-version-%E2%96%BAthe-1-custom-mob-creator%E2%97%84.5702/")); + } + } + return false; + } + + String[] args = filename.split(":"); + + + MythicMob mob = MythicBukkit.inst().getMobManager().getMythicMob(args[0]).orElse(null); + if (mob == null) { + new WarningMessage("Failed to spawn regional boss " + args[0] + "! The filename for this boss probably does not match the mob that should be in ~/plugins/MythicMobs/Mobs/"); + return false; + } + + double level; + try { + level = Double.parseDouble(args[1]); + } catch (Exception e) { + new WarningMessage("Failed to parse level for mob " + filename + "!"); + return false; + } + mob.spawn(BukkitAdapter.adapt(location), Math.max(1, level)); + return true; + + } + +} diff --git a/src/main/java/com/magmaguy/betterstructures/thirdparty/WorldGuard.java b/src/main/java/com/magmaguy/betterstructures/thirdparty/WorldGuard.java new file mode 100644 index 0000000..488d24f --- /dev/null +++ b/src/main/java/com/magmaguy/betterstructures/thirdparty/WorldGuard.java @@ -0,0 +1,139 @@ +package com.magmaguy.betterstructures.thirdparty; + +import com.magmaguy.betterstructures.buildingfitter.FitAnything; +import com.magmaguy.betterstructures.config.DefaultConfig; +import com.magmaguy.betterstructures.util.InfoMessage; +import com.magmaguy.elitemobs.api.EliteMobDeathEvent; +import com.magmaguy.elitemobs.mobconstructor.custombosses.CustomBossEntity; +import com.magmaguy.elitemobs.mobconstructor.custombosses.RegionalBossEntity; +import com.magmaguy.elitemobs.utils.WarningMessage; +import com.sk89q.worldedit.bukkit.BukkitAdapter; +import com.sk89q.worldedit.math.BlockVector3; +import com.sk89q.worldguard.protection.ApplicableRegionSet; +import com.sk89q.worldguard.protection.flags.Flags; +import com.sk89q.worldguard.protection.flags.StateFlag; +import com.sk89q.worldguard.protection.flags.registry.FlagConflictException; +import com.sk89q.worldguard.protection.flags.registry.FlagRegistry; +import com.sk89q.worldguard.protection.managers.RegionManager; +import com.sk89q.worldguard.protection.regions.ProtectedCuboidRegion; +import com.sk89q.worldguard.protection.regions.ProtectedRegion; +import com.sk89q.worldguard.protection.regions.RegionContainer; +import com.sk89q.worldguard.protection.regions.RegionQuery; +import org.bukkit.Bukkit; +import org.bukkit.Location; +import org.bukkit.entity.Player; +import org.bukkit.event.EventHandler; +import org.bukkit.event.Listener; +import org.bukkit.event.block.BlockBreakEvent; +import org.bukkit.event.block.BlockPlaceEvent; +import org.bukkit.util.Vector; + +public class WorldGuard implements Listener { + private static StateFlag BETTERSTRUCTURES_PROTECTED = null; + private static final StateFlag.State allow = StateFlag.State.ALLOW; + private static final StateFlag.State deny = StateFlag.State.DENY; + + + public static void initializeFlag() { + //Enable WorldGuard + if (Bukkit.getPluginManager().getPlugin("WorldGuard") == null) + return; + + FlagRegistry registry = null; + try { + registry = com.sk89q.worldguard.WorldGuard.getInstance().getFlagRegistry(); + } catch (Exception ex) { + new WarningMessage("Something went wrong while loading WorldGuard. Are you using the right WorldGuard version?"); + return; + } + + if (BETTERSTRUCTURES_PROTECTED != null) { + new InfoMessage("Flag betterstructures-protect is already registered, this is normal if the plugin or server have just been reloaded."); + return; + } + + Bukkit.getLogger().info("[BetterStructures] Enabling flags:"); + try { + BETTERSTRUCTURES_PROTECTED = new StateFlag("betterstructures-protect", false); + registry.register(BETTERSTRUCTURES_PROTECTED); + Bukkit.getLogger().info("[BetteStructures] - betterstructures-protect"); + } catch (FlagConflictException | IllegalStateException e) { + //e.printStackTrace(); + Bukkit.getLogger().warning("[EliteMobs] Warning: flag betterstructures-protect already exists! This is normal if you've just now reloaded BetterStructures."); + BETTERSTRUCTURES_PROTECTED = (StateFlag) registry.get("betterstructures-protect"); + } + } + + /** + * Creates and returns a WorldGuard region, useful for API purposes + */ + public static ProtectedRegion generateProtectedRegion(FitAnything fitAnything, String regionName){ + Location lowestCorner = fitAnything.getLocation().clone().add(fitAnything.getSchematicOffset()); + Location highestCorner = lowestCorner.clone().add(new Vector(fitAnything.getSchematicClipboard().getRegion().getWidth() - 1, fitAnything.getSchematicClipboard().getRegion().getHeight(), fitAnything.getSchematicClipboard().getRegion().getLength() - 1)); + BlockVector3 min = BlockVector3.at(lowestCorner.getX(), lowestCorner.getY(), lowestCorner.getZ()); + BlockVector3 max = BlockVector3.at(highestCorner.getX(), highestCorner.getY(), highestCorner.getZ()); + return new ProtectedCuboidRegion(regionName, min, max); + } + + public static void Protect(Location lowestCorner, Location highestCorner, String bossFilename, Location spawnLocation) { + BlockVector3 min = BlockVector3.at(lowestCorner.getX(), lowestCorner.getY(), lowestCorner.getZ()); + BlockVector3 max = BlockVector3.at(highestCorner.getX(), highestCorner.getY(), highestCorner.getZ()); + Protect(min, max, bossFilename, spawnLocation); + } + + public static void Protect(BlockVector3 corner1, BlockVector3 corner2, String bossFilename, Location spawnLocation) { + RegionContainer regionContainer = com.sk89q.worldguard.WorldGuard.getInstance().getPlatform().getRegionContainer(); + RegionManager regionManager = regionContainer.get(BukkitAdapter.adapt(spawnLocation.getWorld())); + BlockVector3 min = corner1; + BlockVector3 max = corner2; + ProtectedRegion region = new ProtectedCuboidRegion(regionIDGenerator(bossFilename, spawnLocation), min, max); + region.setFlag(BETTERSTRUCTURES_PROTECTED, allow); + region.setFlag(Flags.PASSTHROUGH, allow); + regionManager.addRegion(region); + } + + public static void Unprotect(CustomBossEntity customBossEntity) { + if (!customBossEntity.getCustomBossesConfigFields().isRemoveAfterDeath()) return; + ProtectedRegion protectedRegion = com.sk89q.worldguard.WorldGuard.getInstance().getPlatform().getRegionContainer() + .get(BukkitAdapter.adapt(customBossEntity.getLocation().getWorld())).getRegion( + regionIDGenerator( + customBossEntity.getCustomBossesConfigFields().getFilename(), + customBossEntity.getSpawnLocation())); + if (protectedRegion == null) return; + com.sk89q.worldguard.WorldGuard.getInstance().getPlatform().getRegionContainer() + .get(BukkitAdapter.adapt(customBossEntity.getLocation().getWorld())).removeRegion(regionIDGenerator( + customBossEntity.getCustomBossesConfigFields().getFilename(), + customBossEntity.getSpawnLocation())); + } + + public static boolean checkArea(Location location, Player player) { + com.sk89q.worldedit.util.Location wgLocation = BukkitAdapter.adapt(location); + RegionContainer container = com.sk89q.worldguard.WorldGuard.getInstance().getPlatform().getRegionContainer(); + RegionQuery query = container.createQuery(); + ApplicableRegionSet set = query.getApplicableRegions(wgLocation); + if (set.testState(null, BETTERSTRUCTURES_PROTECTED)) { + player.sendMessage(DefaultConfig.getRegionProtectedMessage()); + return true; + } + return false; + } + + private static String regionIDGenerator(String bossFilename, Location spawnLocation) { + return "betterstructures_autoprotected_" + bossFilename.replace(".yml", "") + "_" + spawnLocation.getBlockX() + "_" + spawnLocation.getBlockY() + "_" + spawnLocation.getBlockZ(); + } + + @EventHandler + public void onEliteDeath(EliteMobDeathEvent event) { + if (event.getEliteEntity() instanceof RegionalBossEntity) Unprotect((CustomBossEntity) event.getEliteEntity()); + } + + @EventHandler(ignoreCancelled = true) + public void onBlockBreak(BlockBreakEvent event) { + if (checkArea(event.getBlock().getLocation(), event.getPlayer())) event.setCancelled(true); + } + + @EventHandler(ignoreCancelled = true) + public void onBlockPlace(BlockPlaceEvent event) { + if (checkArea(event.getBlock().getLocation(), event.getPlayer())) event.setCancelled(true); + } +} diff --git a/src/main/java/com/magmaguy/betterstructures/util/ChunkLocationChecker.java b/src/main/java/com/magmaguy/betterstructures/util/ChunkLocationChecker.java new file mode 100644 index 0000000..4ef35fc --- /dev/null +++ b/src/main/java/com/magmaguy/betterstructures/util/ChunkLocationChecker.java @@ -0,0 +1,27 @@ +package com.magmaguy.betterstructures.util; + +import org.bukkit.Chunk; +import org.bukkit.Location; + +public class ChunkLocationChecker { + private ChunkLocationChecker() { + } + + /* + Checks if a location is in a given chunk + */ + public static boolean chunkLocationCheck(Location location, Chunk chunk) { + return chunk.getWorld().equals(location.getWorld()) //location.getWorld() can return null + && chunk.getX() == location.getBlockX() >> 4 + && chunk.getZ() == location.getBlockZ() >> 4; + } + + /* + Checks if a given location is loaded + */ + public static boolean locationIsLoaded(Location location) { + return location != null && location.getWorld() != null && + location.getWorld().isChunkLoaded(location.getBlockX() >> 4, location.getBlockZ() >> 4); + } +} + diff --git a/src/main/java/com/magmaguy/betterstructures/util/DefaultChestContents.java b/src/main/java/com/magmaguy/betterstructures/util/DefaultChestContents.java index 1db84c4..787043f 100644 --- a/src/main/java/com/magmaguy/betterstructures/util/DefaultChestContents.java +++ b/src/main/java/com/magmaguy/betterstructures/util/DefaultChestContents.java @@ -1,243 +1,839 @@ package com.magmaguy.betterstructures.util; import org.bukkit.Material; +import org.bukkit.enchantments.Enchantment; +import org.bukkit.inventory.ItemStack; import java.util.ArrayList; +import java.util.HashMap; import java.util.List; +import java.util.Map; public class DefaultChestContents { - private static double normalChance = 0.02; - private static double lowChance = 0.01; - private static double extraRare = 0.002; - - public static List overworldContents() { - List list = new ArrayList<>(); - list.add(generateEntry(Material.COAL, 2, 5, normalChance)); - list.add(generateEntry(Material.BONE, 2, 5, normalChance)); - list.add(generateEntry(Material.BOOK, 1, 3, normalChance)); - list.add(generateEntry(Material.CANDLE, 1, 5, normalChance)); - list.add(generateEntry(Material.EXPERIENCE_BOTTLE, 1, 2, normalChance)); - list.add(generateEntry(Material.ENCHANTED_GOLDEN_APPLE, 1, 1, extraRare)); - //list.add(generateEntry(Material.MUSIC_DISC_5, 1, 1, normalChance)); - list.add(generateEntry(Material.MUSIC_DISC_11, 1, 1, normalChance)); - list.add(generateEntry(Material.MUSIC_DISC_13, 1, 1, normalChance)); - list.add(generateEntry(Material.MUSIC_DISC_BLOCKS, 1, 1, normalChance)); - list.add(generateEntry(Material.MUSIC_DISC_CAT, 1, 1, normalChance)); - list.add(generateEntry(Material.MUSIC_DISC_CHIRP, 1, 1, normalChance)); - list.add(generateEntry(Material.MUSIC_DISC_FAR, 1, 1, normalChance)); - list.add(generateEntry(Material.MUSIC_DISC_MALL, 1, 1, normalChance)); - list.add(generateEntry(Material.MUSIC_DISC_MELLOHI, 1, 1, normalChance)); - list.add(generateEntry(Material.MUSIC_DISC_OTHERSIDE, 1, 1, normalChance)); - list.add(generateEntry(Material.MUSIC_DISC_PIGSTEP, 1, 1, normalChance)); - list.add(generateEntry(Material.MUSIC_DISC_STAL, 1, 1, normalChance)); - list.add(generateEntry(Material.MUSIC_DISC_STRAD, 1, 1, normalChance)); - list.add(generateEntry(Material.MUSIC_DISC_WAIT, 1, 1, normalChance)); - list.add(generateEntry(Material.MUSIC_DISC_WARD, 1, 1, normalChance)); - list.add(generateEntry(Material.HEART_OF_THE_SEA, 1, 1, normalChance)); - list.add(generateEntry(Material.LODESTONE, 1, 1, normalChance)); - //list.add(generateEntry(Material.GOAT_HORN, 1, 1, normalChance)); - list.add(generateEntry(Material.SNOWBALL, 5, 20, normalChance)); - list.add(generateEntry(Material.PAPER, 5, 10, normalChance)); - list.add(generateEntry(Material.APPLE, 2, 5, normalChance)); - list.add(generateEntry(Material.CACTUS, 1, 3, normalChance)); - list.add(generateEntry(Material.PACKED_ICE, 1, 3, normalChance)); - list.add(generateEntry(Material.COOKED_COD, 2, 4, normalChance)); - list.add(generateEntry(Material.COOKED_BEEF, 2, 4, normalChance)); - list.add(generateEntry(Material.COOKED_CHICKEN, 2, 4, normalChance)); - list.add(generateEntry(Material.COOKED_MUTTON, 2, 4, normalChance)); - list.add(generateEntry(Material.COOKED_PORKCHOP, 2, 4, normalChance)); - list.add(generateEntry(Material.COOKED_RABBIT, 2, 4, normalChance)); - list.add(generateEntry(Material.COOKED_SALMON, 2, 4, normalChance)); - list.add(generateEntry(Material.WOODEN_AXE, 1, 1, normalChance)); - list.add(generateEntry(Material.WOODEN_PICKAXE, 1, 1, normalChance)); - list.add(generateEntry(Material.LEATHER_HELMET, 1, 1, normalChance)); - list.add(generateEntry(Material.LEATHER_CHESTPLATE, 1, 1, normalChance)); - list.add(generateEntry(Material.LEATHER_LEGGINGS, 1, 1, normalChance)); - list.add(generateEntry(Material.LEATHER_BOOTS, 1, 1, normalChance)); - list.add(generateEntry(Material.IRON_SWORD, 1, 1, normalChance)); - list.add(generateEntry(Material.IRON_AXE, 1, 1, normalChance)); - list.add(generateEntry(Material.ACACIA_SAPLING, 1, 1, normalChance)); - list.add(generateEntry(Material.BIRCH_SAPLING, 1, 1, normalChance)); - list.add(generateEntry(Material.BAMBOO_SAPLING, 1, 1, normalChance)); - list.add(generateEntry(Material.JUNGLE_SAPLING, 1, 1, normalChance)); - list.add(generateEntry(Material.DARK_OAK_SAPLING, 1, 1, normalChance)); - list.add(generateEntry(Material.OAK_SAPLING, 1, 1, normalChance)); - list.add(generateEntry(Material.ROTTEN_FLESH, 2, 6, normalChance)); - list.add(generateEntry(Material.OAK_PLANKS, 3, 10, normalChance)); - list.add(generateEntry(Material.ACACIA_PLANKS, 3, 10, normalChance)); - list.add(generateEntry(Material.BIRCH_PLANKS, 3, 10, normalChance)); - list.add(generateEntry(Material.JUNGLE_PLANKS, 3, 10, normalChance)); - list.add(generateEntry(Material.DARK_OAK_PLANKS, 3, 10, normalChance)); - //list.add(generateEntry(Material.MANGROVE_PLANKS, 3, 10, normalChance)); - list.add(generateEntry(Material.SPRUCE_PLANKS, 3, 10, normalChance)); - list.add(generateEntry(Material.STICK, 3, 15, normalChance)); - list.add(generateEntry(Material.TORCH, 2, 5, normalChance)); - list.add(generateEntry(Material.TNT, 1, 4, normalChance)); - list.add(generateEntry(Material.BREAD, 1, 6, normalChance)); - list.add(generateEntry(Material.SALMON, 2, 5, normalChance)); - list.add(generateEntry(Material.FEATHER, 2, 8, normalChance)); - list.add(generateEntry(Material.EMERALD, 1, 6, normalChance)); - list.add(generateEntry(Material.GUNPOWDER, 1, 6, normalChance)); - list.add(generateEntry(Material.SAND, 1, 10, normalChance)); - list.add(generateEntry(Material.WHEAT_SEEDS, 1, 4, normalChance)); - list.add(generateEntry(Material.CARROT, 1, 4, normalChance)); - list.add(generateEntry(Material.POTATO, 1, 4, normalChance)); - list.add(generateEntry(Material.WHITE_WOOL, 1, 6, normalChance)); - list.add(generateEntry(Material.BLACK_WOOL, 1, 6, normalChance)); - list.add(generateEntry(Material.BLUE_WOOL, 1, 6, normalChance)); - list.add(generateEntry(Material.BROWN_WOOL, 1, 6, normalChance)); - list.add(generateEntry(Material.CYAN_WOOL, 1, 6, normalChance)); - list.add(generateEntry(Material.GRAY_WOOL, 1, 6, normalChance)); - list.add(generateEntry(Material.GREEN_WOOL, 1, 6, normalChance)); - list.add(generateEntry(Material.LIGHT_BLUE_WOOL, 1, 6, normalChance)); - list.add(generateEntry(Material.LIGHT_GRAY_WOOL, 1, 6, normalChance)); - list.add(generateEntry(Material.LIME_WOOL, 1, 6, normalChance)); - list.add(generateEntry(Material.MAGENTA_WOOL, 1, 6, normalChance)); - list.add(generateEntry(Material.ORANGE_WOOL, 1, 6, normalChance)); - list.add(generateEntry(Material.PINK_WOOL, 1, 6, normalChance)); - list.add(generateEntry(Material.PURPLE_WOOL, 1, 6, normalChance)); - list.add(generateEntry(Material.RED_WOOL, 1, 6, normalChance)); - list.add(generateEntry(Material.YELLOW_WOOL, 1, 6, normalChance)); - list.add(generateEntry(Material.BAKED_POTATO, 1, 5, normalChance)); - list.add(generateEntry(Material.GOLDEN_CARROT, 1, 3, extraRare)); - list.add(generateEntry(Material.SUSPICIOUS_STEW, 1, 3, lowChance)); - list.add(generateEntry(Material.BAMBOO, 2, 7, normalChance)); - list.add(generateEntry(Material.BEEF, 2, 5, normalChance)); - list.add(generateEntry(Material.MUTTON, 2, 5, normalChance)); - list.add(generateEntry(Material.ARROW, 1, 7, normalChance)); - list.add(generateEntry(Material.SPECTRAL_ARROW, 1, 3, normalChance)); - list.add(generateEntry(Material.IRON_NUGGET, 1, 16, normalChance)); - list.add(generateEntry(Material.GOLD_NUGGET, 1, 16, lowChance)); - list.add(generateEntry(Material.STRING, 1, 5, normalChance)); - list.add(generateEntry(Material.LEATHER, 1, 4, normalChance)); - list.add(generateEntry(Material.FLINT, 1, 4, normalChance)); - list.add(generateEntry(Material.FIRE_CHARGE, 1, 3, lowChance)); - list.add(generateEntry(Material.COD, 1, 4, normalChance)); - list.add(generateEntry(Material.POISONOUS_POTATO, 1, 3, normalChance)); - list.add(generateEntry(Material.BAKED_POTATO, 1, 5, normalChance)); - list.add(generateEntry(Material.MOSS_BLOCK, 1, 5, normalChance)); - list.add(generateEntry(Material.IRON_SHOVEL, 1, 1, normalChance)); - list.add(generateEntry(Material.SWEET_BERRIES, 1, 3, normalChance)); - list.add(generateEntry(Material.STONE, 1, 32, normalChance)); - list.add(generateEntry(Material.STONE_BRICKS, 1, 16, normalChance)); - list.add(generateEntry(Material.SNOW_BLOCK, 1, 32, normalChance)); - list.add(generateEntry(Material.WHEAT_SEEDS, 1, 16, normalChance)); - list.add(generateEntry(Material.TRIPWIRE_HOOK, 1, 3, normalChance)); - list.add(generateEntry(Material.SPIDER_EYE, 1, 5, normalChance)); - list.add(generateEntry(Material.REDSTONE, 5, 32, normalChance)); - list.add(generateEntry(Material.ACACIA_LOG, 1, 5, normalChance)); - list.add(generateEntry(Material.BIRCH_LOG, 1, 5, normalChance)); - list.add(generateEntry(Material.DARK_OAK_LOG, 1, 5, normalChance)); - list.add(generateEntry(Material.JUNGLE_LOG, 1, 5, normalChance)); - //list.add(generateEntry(Material.MANGROVE_LOG, 1, 5, normalChance)); - list.add(generateEntry(Material.OAK_LOG, 1, 5, normalChance)); - list.add(generateEntry(Material.SPRUCE_LOG, 1, 5, normalChance)); - list.add(generateEntry(Material.STONE_AXE, 1, 1, normalChance)); - list.add(generateEntry(Material.STONE_PICKAXE, 1, 1, normalChance)); - list.add(generateEntry(Material.CHAIN, 1, 8, normalChance)); - list.add(generateEntry(Material.OBSIDIAN, 1, 5, lowChance)); - list.add(generateEntry(Material.BONE_BLOCK, 1, 4, normalChance)); - list.add(generateEntry(Material.PORKCHOP, 1, 5, normalChance)); - list.add(generateEntry(Material.BARREL, 1, 5, normalChance)); - list.add(generateEntry(Material.WATER_BUCKET, 1, 1, normalChance)); - list.add(generateEntry(Material.EGG, 1, 6, normalChance)); - list.add(generateEntry(Material.ENDER_PEARL, 1, 3, lowChance)); - list.add(generateEntry(Material.DANDELION, 1, 3, normalChance)); - list.add(generateEntry(Material.DIAMOND_HOE, 1, 1, extraRare)); - list.add(generateEntry(Material.FISHING_ROD, 1, 1, normalChance)); - list.add(generateEntry(Material.FLOWER_POT, 1, 1, normalChance)); - list.add(generateEntry(Material.SMOOTH_STONE, 1, 6, normalChance)); - list.add(generateEntry(Material.GOLDEN_HOE, 1, 1, lowChance)); - list.add(generateEntry(Material.GOLDEN_PICKAXE, 1, 1, lowChance)); - list.add(generateEntry(Material.GOLDEN_SHOVEL, 1, 1, lowChance)); - list.add(generateEntry(Material.GOLDEN_SWORD, 1, 1, lowChance)); - list.add(generateEntry(Material.GOLDEN_HELMET, 1, 1, lowChance)); - list.add(generateEntry(Material.GOLDEN_CHESTPLATE, 1, 1, lowChance)); - list.add(generateEntry(Material.GOLDEN_LEGGINGS, 1, 1, lowChance)); - list.add(generateEntry(Material.GOLDEN_BOOTS, 1, 1, lowChance)); - list.add(generateEntry(Material.FLINT_AND_STEEL, 1, 1, normalChance)); - list.add(generateEntry(Material.DIAMOND_HELMET, 1, 1, extraRare)); - list.add(generateEntry(Material.DIAMOND_LEGGINGS, 1, 1, extraRare)); - list.add(generateEntry(Material.DIAMOND_BOOTS, 1, 1, extraRare)); - list.add(generateEntry(Material.DIAMOND_SWORD, 1, 1, extraRare)); - list.add(generateEntry(Material.DIAMOND_AXE, 1, 1, extraRare)); - list.add(generateEntry(Material.CHAINMAIL_HELMET, 1, 1, lowChance)); - list.add(generateEntry(Material.CHAINMAIL_CHESTPLATE, 1, 1, lowChance)); - list.add(generateEntry(Material.CHAINMAIL_LEGGINGS, 1, 1, lowChance)); - list.add(generateEntry(Material.CHAINMAIL_BOOTS, 1, 1, lowChance)); - list.add(generateEntry(Material.LAPIS_LAZULI, 1, 6, normalChance)); - list.add(generateEntry(Material.PUMPKIN, 1, 3, normalChance)); - list.add(generateEntry(Material.CLAY_BALL, 1, 16, normalChance)); - list.add(generateEntry(Material.YELLOW_DYE, 1, 3, normalChance)); - list.add(generateEntry(Material.BLACK_DYE, 1, 3, normalChance)); - list.add(generateEntry(Material.BLUE_DYE, 1, 3, normalChance)); - list.add(generateEntry(Material.BROWN_DYE, 1, 3, normalChance)); - list.add(generateEntry(Material.CYAN_DYE, 1, 3, normalChance)); - list.add(generateEntry(Material.GRAY_DYE, 1, 3, normalChance)); - list.add(generateEntry(Material.GREEN_DYE, 1, 3, normalChance)); - list.add(generateEntry(Material.LIGHT_BLUE_DYE, 1, 8, normalChance)); - list.add(generateEntry(Material.LIGHT_GRAY_DYE, 1, 8, normalChance)); - list.add(generateEntry(Material.MAGENTA_DYE, 1, 8, normalChance)); - list.add(generateEntry(Material.ORANGE_DYE, 1, 8, normalChance)); - list.add(generateEntry(Material.PINK_DYE, 1, 8, normalChance)); - list.add(generateEntry(Material.PURPLE_DYE, 1, 8, normalChance)); - list.add(generateEntry(Material.RED_DYE, 1, 8, normalChance)); - list.add(generateEntry(Material.WHITE_DYE, 1, 8, normalChance)); - list.add(generateEntry(Material.DIAMOND_HORSE_ARMOR, 1, 1, extraRare)); - list.add(generateEntry(Material.GOLDEN_HORSE_ARMOR, 1, 1, lowChance)); - list.add(generateEntry(Material.IRON_HORSE_ARMOR, 1, 1, normalChance)); - list.add(generateEntry(Material.LEATHER_HORSE_ARMOR, 1, 1, normalChance)); - list.add(generateEntry(Material.LEATHER_HORSE_ARMOR, 1, 1, normalChance)); - list.add(generateEntry(Material.IRON_HELMET, 1, 1, normalChance)); - list.add(generateEntry(Material.IRON_CHESTPLATE, 1, 1, normalChance)); - list.add(generateEntry(Material.IRON_LEGGINGS, 1, 1, normalChance)); - list.add(generateEntry(Material.IRON_BOOTS, 1, 1, normalChance)); - list.add(generateEntry(Material.IRON_INGOT, 1, 6, lowChance)); - list.add(generateEntry(Material.GOLD_INGOT, 1, 6, extraRare)); - list.add(generateEntry(Material.CRYING_OBSIDIAN, 1, 4, normalChance)); - list.add(generateEntry(Material.CROSSBOW, 1, 1, normalChance)); - list.add(generateEntry(Material.ARROW, 1, 6, normalChance)); - list.add(generateEntry(Material.BOW, 1, 1, normalChance)); - list.add(generateEntry(Material.IRON_HELMET, 1, 1, normalChance)); - list.add(generateEntry(Material.STONE_SWORD, 1, 1, normalChance)); - list.add(generateEntry(Material.GOLDEN_APPLE, 1, 4, lowChance)); - list.add(generateEntry(Material.PUMPKIN_PIE, 1, 3, normalChance)); - list.add(generateEntry(Material.MAP, 1, 3, normalChance)); - list.add(generateEntry(Material.GLISTERING_MELON_SLICE, 1, 3, extraRare)); - list.add(generateEntry(Material.CLOCK, 1, 1, lowChance)); - list.add(generateEntry(Material.LIGHT_WEIGHTED_PRESSURE_PLATE, 1, 1, lowChance)); - list.add(generateEntry(Material.IRON_PICKAXE, 1, 1, normalChance)); - list.add(generateEntry(Material.BELL, 1, 1, lowChance)); - list.add(generateEntry(Material.NAME_TAG, 1, 3, normalChance)); - return list; + public static double normalWeight = 6; + public static double rareWeight = 3; + public static double extraRareWeight = 1; + + public static Map overworldContents() { + Map items = new HashMap<>(); + Map commonItems = new HashMap<>(); + Map rareItems = new HashMap<>(); + Map epicItems = new HashMap<>(); + List> commonList = new ArrayList<>(); + List> rareList = new ArrayList<>(); + List> epicList = new ArrayList<>(); + + commonList.add(generateEntry(Material.ARROW, 16, 32, normalWeight)); + commonList.add(generateEntry(Material.BAKED_POTATO, 8, 16, normalWeight)); + commonList.add(generateEntry(Material.BAMBOO, 2, 7, normalWeight)); + commonList.add(generateEntry(Material.BAMBOO_SAPLING, 1, 1, normalWeight)); + commonList.add(generateEntry(Material.BEEF, 4, 8, normalWeight)); + commonList.add(generateEntry(Material.BELL, 1, 1, rareWeight)); + commonList.add(generateEntry(Material.BLACK_DYE, 1, 3, normalWeight)); + commonList.add(generateEntry(Material.BLACK_WOOL, 1, 6, normalWeight)); + commonList.add(generateEntry(Material.BLUE_DYE, 1, 3, normalWeight)); + commonList.add(generateEntry(Material.BLUE_WOOL, 1, 6, normalWeight)); + commonList.add(generateEntry(Material.BONE, 2, 5, normalWeight)); + commonList.add(generateEntry(Material.BONE_BLOCK, 1, 4, normalWeight)); + commonList.add(generateEntry(Material.BOOK, 1, 3, normalWeight)); + commonList.add(generateEntry(Material.BOW, 1, 1, normalWeight, true)); + commonList.add(generateEntry(Material.BREAD, 8, 16, normalWeight)); + if (!VersionChecker.serverVersionOlderThan(20, 0)) + commonList.add(generateEntry(Material.BRUSH, 1, 1, extraRareWeight)); + commonList.add(generateEntry(Material.BROWN_DYE, 1, 3, normalWeight)); + commonList.add(generateEntry(Material.BROWN_WOOL, 1, 6, normalWeight)); + commonList.add(generateEntry(Material.CANDLE, 1, 5, normalWeight)); + commonList.add(generateEntry(Material.CARROT, 8, 16, normalWeight)); + commonList.add(generateEntry(Material.CARROT_ON_A_STICK, 1, 1, rareWeight)); + commonList.add(generateEntry(Material.CHAIN, 1, 8, normalWeight)); + commonList.add(generateEntry(Material.CHEST, 1, 6, normalWeight)); + commonList.add(generateEntry(Material.CLAY_BALL, 1, 16, normalWeight)); + commonList.add(generateEntry(Material.CLOCK, 1, 1, rareWeight)); + commonList.add(generateEntry(Material.COAL, 2, 5, normalWeight)); + commonList.add(generateEntry(Material.COPPER_INGOT, 3, 9, extraRareWeight)); + commonList.add(generateEntry(Material.COCOA_BEANS, 4, 12, normalWeight)); + commonList.add(generateEntry(Material.COOKED_BEEF, 8, 16, normalWeight)); + commonList.add(generateEntry(Material.COOKED_CHICKEN, 8, 16, normalWeight)); + commonList.add(generateEntry(Material.COOKED_COD, 8, 16, normalWeight)); + commonList.add(generateEntry(Material.COOKED_MUTTON, 8, 16, normalWeight)); + commonList.add(generateEntry(Material.COOKED_PORKCHOP, 8, 16, normalWeight)); + commonList.add(generateEntry(Material.COOKED_RABBIT, 8, 16, normalWeight)); + commonList.add(generateEntry(Material.COOKED_SALMON, 8, 16, normalWeight)); + commonList.add(generateEntry(Material.COOKIE, 32, 64, extraRareWeight)); + commonList.add(generateEntry(Material.COMPASS, 1, 4, normalWeight)); + commonList.add(generateEntry(Material.CYAN_DYE, 1, 3, normalWeight)); + commonList.add(generateEntry(Material.CYAN_WOOL, 1, 6, normalWeight)); + commonList.add(generateEntry(Material.DRIED_KELP, 8, 48, normalWeight)); + commonList.add(generateEntry(Material.EMERALD, 1, 6, normalWeight)); + commonList.add(generateEntry(Material.EXPERIENCE_BOTTLE, 1, 2, normalWeight)); + commonList.add(generateEntry(Material.FEATHER, 2, 16, normalWeight)); + commonList.add(generateEntry(Material.FISHING_ROD, 1, 1, normalWeight, true)); + commonList.add(generateEntry(Material.FLINT, 1, 8, normalWeight)); + commonList.add(generateEntry(Material.FLINT_AND_STEEL, 1, 1, normalWeight)); + commonList.add(generateEntry(Material.FLOWER_POT, 1, 1, normalWeight)); + commonList.add(generateEntry(Material.ORANGE_DYE, 1, 3, normalWeight)); + commonList.add(generateEntry(Material.GLISTERING_MELON_SLICE, 1, 4, extraRareWeight)); + commonList.add(generateEntry(Material.GRAY_DYE, 1, 3, normalWeight)); + commonList.add(generateEntry(Material.GREEN_DYE, 1, 3, normalWeight)); + commonList.add(generateEntry(Material.PINK_DYE, 1, 3, normalWeight)); + commonList.add(generateEntry(Material.PURPLE_DYE, 1, 3, normalWeight)); + commonList.add(generateEntry(Material.LEATHER_BOOTS, 1, 1, normalWeight)); + commonList.add(generateEntry(Material.LEATHER_HELMET, 1, 1, normalWeight)); + commonList.add(generateEntry(Material.LEATHER_LEGGINGS, 1, 1, normalWeight)); + commonList.add(generateEntry(Material.LEATHER_CHESTPLATE, 1, 1, normalWeight)); + commonList.add(generateEntry(Material.LEATHER_BOOTS, 1, 1, rareWeight, true)); + commonList.add(generateEntry(Material.LEATHER_HELMET, 1, 1, rareWeight, true)); + commonList.add(generateEntry(Material.LEATHER_HORSE_ARMOR, 1, 1, extraRareWeight)); + commonList.add(generateEntry(Material.LEATHER_LEGGINGS, 1, 1, rareWeight, true)); + commonList.add(generateEntry(Material.LEATHER_CHESTPLATE, 1, 1, rareWeight, true)); + commonList.add(generateEntry(Material.LIME_DYE, 1, 3, normalWeight)); + commonList.add(generateEntry(Material.MAGENTA_DYE, 1, 3, normalWeight)); + if (!VersionChecker.serverVersionOlderThan(19, 0)) + commonList.add(generateEntry(Material.MUSIC_DISC_5, 1, 1, extraRareWeight)); //1.19 + commonList.add(generateEntry(Material.MUSIC_DISC_11, 1, 1, extraRareWeight)); + commonList.add(generateEntry(Material.MUSIC_DISC_13, 1, 1, extraRareWeight)); + commonList.add(generateEntry(Material.MUSIC_DISC_BLOCKS, 1, 1, extraRareWeight)); + commonList.add(generateEntry(Material.MUSIC_DISC_CAT, 1, 1, extraRareWeight)); + commonList.add(generateEntry(Material.MUSIC_DISC_CHIRP, 1, 1, extraRareWeight)); + commonList.add(generateEntry(Material.MUSIC_DISC_FAR, 1, 1, extraRareWeight)); + commonList.add(generateEntry(Material.MUSIC_DISC_MALL, 1, 1, extraRareWeight)); + commonList.add(generateEntry(Material.MUSIC_DISC_MELLOHI, 1, 1, extraRareWeight)); + if (!VersionChecker.serverVersionOlderThan(18, 0)) + commonList.add(generateEntry(Material.MUSIC_DISC_OTHERSIDE, 1, 1, extraRareWeight)); //1.18 + commonList.add(generateEntry(Material.MUSIC_DISC_PIGSTEP, 1, 1, extraRareWeight)); + commonList.add(generateEntry(Material.MUSIC_DISC_STAL, 1, 1, extraRareWeight)); + commonList.add(generateEntry(Material.MUSIC_DISC_STRAD, 1, 1, extraRareWeight)); + commonList.add(generateEntry(Material.MUSIC_DISC_WAIT, 1, 1, extraRareWeight)); + commonList.add(generateEntry(Material.MUSIC_DISC_WARD, 1, 1, extraRareWeight)); + commonList.add(generateEntry(Material.YELLOW_DYE, 1, 3, normalWeight)); + commonList.add(generateEntry(Material.SADDLE, 1, 1, normalWeight)); + commonList.add(generateEntry(Material.LEAD, 3, 9, normalWeight)); + commonList.add(generateEntry(Material.SHEARS, 1, 1, extraRareWeight)); + commonList.add(generateEntry(Material.STONE_AXE, 1, 1, extraRareWeight)); + commonList.add(generateEntry(Material.STONE_HOE, 1, 1, extraRareWeight)); + commonList.add(generateEntry(Material.STONE_PICKAXE, 1, 1, extraRareWeight)); + commonList.add(generateEntry(Material.STONE_SHOVEL, 1, 1, extraRareWeight)); + commonList.add(generateEntry(Material.STONE_SWORD, 1, 1, extraRareWeight)); + commonList.add(generateEntry(Material.STONE_AXE, 1, 1, extraRareWeight, true)); + commonList.add(generateEntry(Material.STONE_HOE, 1, 1, extraRareWeight, true)); + commonList.add(generateEntry(Material.STONE_PICKAXE, 1, 1, extraRareWeight, true)); + commonList.add(generateEntry(Material.STONE_SHOVEL, 1, 1, extraRareWeight, true)); + commonList.add(generateEntry(Material.STONE_SWORD, 1, 1, extraRareWeight, true)); + commonList.add(generateEntry(Material.NAME_TAG, 3, 9, normalWeight)); + commonList.add(generateEntry(Material.HEART_OF_THE_SEA, 1, 1, rareWeight)); + commonList.add(generateEntry(Material.HONEYCOMB, 2, 5, rareWeight)); + commonList.add(generateEntry(Material.WHITE_DYE, 1, 3, normalWeight)); + commonList.add(generateEntry(Material.WOODEN_AXE, 1, 1, normalWeight)); + commonList.add(generateEntry(Material.WOODEN_HOE, 1, 1, normalWeight)); + commonList.add(generateEntry(Material.WOODEN_PICKAXE, 1, 1, normalWeight)); + commonList.add(generateEntry(Material.WOODEN_SHOVEL, 1, 1, normalWeight)); + commonList.add(generateEntry(Material.WOODEN_SWORD, 1, 1, normalWeight)); + commonList.add(generateEntry(Material.WOODEN_AXE, 1, 1, rareWeight, true)); + commonList.add(generateEntry(Material.WOODEN_HOE, 1, 1, rareWeight, true)); + commonList.add(generateEntry(Material.WOODEN_PICKAXE, 1, 1, rareWeight, true)); + commonList.add(generateEntry(Material.WOODEN_SHOVEL, 1, 1, rareWeight, true)); + commonList.add(generateEntry(Material.WOODEN_SWORD, 1, 1, rareWeight, true)); + commonList.add(generateEntry(Material.BOW, 1, 1, normalWeight)); + commonList.add(generateEntry(Material.CROSSBOW, 1, 1, normalWeight)); + commonList.add(generateEntry(Material.TRIDENT, 1, 1, normalWeight)); + commonList.add(generateEntry(Material.TURTLE_HELMET, 1, 1, normalWeight)); + rareList.add(generateEntry(Material.ANVIL, 1, 1, normalWeight)); + rareList.add(generateEntry(Material.BEETROOT, 1, 6, normalWeight)); + rareList.add(generateEntry(Material.TURTLE_HELMET, 1, 1, normalWeight, true)); + rareList.add(generateEntry(Material.BEETROOT_SEEDS, 1, 6, normalWeight)); + rareList.add(generateEntry(Material.BONE_MEAL, 2, 12, normalWeight)); + rareList.add(generateEntry(Material.CROSSBOW, 1, 1, normalWeight, true)); + rareList.add(generateEntry(Material.CHAINMAIL_BOOTS, 1, 1, rareWeight)); + rareList.add(generateEntry(Material.CHAINMAIL_CHESTPLATE, 1, 1, rareWeight)); + rareList.add(generateEntry(Material.CHAINMAIL_HELMET, 1, 1, rareWeight)); + rareList.add(generateEntry(Material.CHAINMAIL_LEGGINGS, 1, 1, rareWeight)); + rareList.add(generateEntry(Material.CHAINMAIL_BOOTS, 1, 1, rareWeight, true)); + rareList.add(generateEntry(Material.CHAINMAIL_CHESTPLATE, 1, 1, rareWeight, true)); + rareList.add(generateEntry(Material.CHAINMAIL_HELMET, 1, 1, rareWeight, true)); + rareList.add(generateEntry(Material.CHAINMAIL_LEGGINGS, 1, 1, rareWeight, true)); + rareList.add(generateEntry(Material.DIAMOND_HORSE_ARMOR, 1, 1, rareWeight)); + rareList.add(generateEntry(Material.IRON_AXE, 1, 1, normalWeight)); + rareList.add(generateEntry(Material.IRON_BOOTS, 1, 1, normalWeight)); + rareList.add(generateEntry(Material.IRON_CHESTPLATE, 1, 1, normalWeight)); + rareList.add(generateEntry(Material.IRON_HELMET, 1, 1, normalWeight)); + rareList.add(generateEntry(Material.IRON_HOE, 1, 1, normalWeight)); + rareList.add(generateEntry(Material.IRON_LEGGINGS, 1, 1, normalWeight)); + rareList.add(generateEntry(Material.IRON_PICKAXE, 1, 1, normalWeight)); + rareList.add(generateEntry(Material.IRON_SHOVEL, 1, 1, normalWeight)); + rareList.add(generateEntry(Material.IRON_SWORD, 1, 1, normalWeight)); + rareList.add(generateEntry(Material.IRON_AXE, 1, 1, extraRareWeight, true)); + rareList.add(generateEntry(Material.IRON_BOOTS, 1, 1, extraRareWeight, true)); + rareList.add(generateEntry(Material.IRON_CHESTPLATE, 1, 1, extraRareWeight, true)); + rareList.add(generateEntry(Material.IRON_HELMET, 1, 1, extraRareWeight, true)); + rareList.add(generateEntry(Material.IRON_HOE, 1, 1, extraRareWeight, true)); + rareList.add(generateEntry(Material.IRON_HORSE_ARMOR, 1, 1, extraRareWeight)); + rareList.add(generateEntry(Material.IRON_INGOT, 3, 9, extraRareWeight)); + rareList.add(generateEntry(Material.IRON_LEGGINGS, 1, 1, extraRareWeight, true)); + rareList.add(generateEntry(Material.IRON_PICKAXE, 1, 1, extraRareWeight, true)); + rareList.add(generateEntry(Material.IRON_SHOVEL, 1, 1, extraRareWeight, true)); + rareList.add(generateEntry(Material.IRON_SWORD, 1, 1, extraRareWeight, true)); + rareList.add(generateEntry(Material.SHIELD, 1, 1, rareWeight, true)); + rareList.add(generateEntry(Material.GLASS_BOTTLE, 2, 8, rareWeight)); + rareList.add(generateEntry(Material.GLOW_BERRIES, 1, 3, normalWeight)); + rareList.add(generateEntry(Material.GOLDEN_APPLE, 3, 9, extraRareWeight)); + rareList.add(generateEntry(Material.GOLDEN_CARROT, 3, 9, rareWeight)); + rareList.add(generateEntry(Material.SPYGLASS, 1, 1, normalWeight)); + rareList.add(generateEntry(Material.MUSHROOM_STEW, 3, 9, normalWeight)); + rareList.add(generateEntry(Material.WRITABLE_BOOK, 1, 8, rareWeight)); + rareList.add(generateEntry(Material.BUNDLE, 1, 1, rareWeight)); + epicList.add(generateEntry(Material.DIAMOND, 2, 10, extraRareWeight)); + epicList.add(generateEntry(Material.DIAMOND_AXE, 1, 1, normalWeight)); + epicList.add(generateEntry(Material.DIAMOND_BOOTS, 1, 1, normalWeight)); + epicList.add(generateEntry(Material.DIAMOND_HELMET, 1, 1, normalWeight)); + epicList.add(generateEntry(Material.DIAMOND_HOE, 1, 1, normalWeight)); + epicList.add(generateEntry(Material.DIAMOND_LEGGINGS, 1, 1, normalWeight)); + epicList.add(generateEntry(Material.DIAMOND_SWORD, 1, 1, normalWeight)); + epicList.add(generateEntry(Material.DIAMOND_PICKAXE, 1, 1, normalWeight)); + epicList.add(generateEntry(Material.DIAMOND_SHOVEL, 1, 1, normalWeight)); + epicList.add(generateEntry(Material.DIAMOND_AXE, 1, 1, normalWeight, true)); + epicList.add(generateEntry(Material.DIAMOND_BOOTS, 1, 1, normalWeight, true)); + epicList.add(generateEntry(Material.DIAMOND_HELMET, 1, 1, normalWeight, true)); + epicList.add(generateEntry(Material.DIAMOND_HOE, 1, 1, normalWeight, true)); + epicList.add(generateEntry(Material.DIAMOND_LEGGINGS, 1, 1, normalWeight, true)); + epicList.add(generateEntry(Material.DIAMOND_SWORD, 1, 1, normalWeight, true)); + epicList.add(generateEntry(Material.DIAMOND_PICKAXE, 1, 1, normalWeight, true)); + epicList.add(generateEntry(Material.DIAMOND_SHOVEL, 1, 1, normalWeight, true)); + epicList.add(generateEntry(Material.SPECTRAL_ARROW, 8, 16, normalWeight, true)); + epicList.add(generateEntry(Material.SLIME_BALL, 16, 32, normalWeight, true)); + epicList.add(generateEntry(Material.MAP, 1, 6, normalWeight)); + epicList.add(generateEntry(Material.ENCHANTED_GOLDEN_APPLE, 1, 6, extraRareWeight)); + epicList.add(generateEntry(Material.PUMPKIN_PIE, 3, 9, normalWeight)); + epicList.add(generateEntry(Material.RABBIT_STEW, 3, 9, extraRareWeight)); + epicList.add(generateEntry(Material.GLOW_INK_SAC, 8, 16, extraRareWeight)); + epicList.add(generateEntry(Material.TOTEM_OF_UNDYING, 1, 1, extraRareWeight)); + epicList.add(generateEntry(Material.TRIDENT, 1, 1, normalWeight, true)); + epicList.add(generateEntry(Material.HONEY_BOTTLE, 1, 4, normalWeight)); + + commonItems.put("weight", 60); + commonItems.put("items", commonList); + rareItems.put("weight", 30); + rareItems.put("items", rareList); + epicItems.put("weight", 10); + epicItems.put("items", epicList); + items.put("common", commonItems); + items.put("rare", rareItems); + items.put("epic", epicItems); + return items; } - public static List overworldUndergroundContents() { - List list = new ArrayList<>(overworldContents()); - list.add(generateEntry(Material.RAIL, 2, 5, normalChance)); - list.add(generateEntry(Material.ACTIVATOR_RAIL, 1, 3, lowChance)); - list.add(generateEntry(Material.POWERED_RAIL, 1, 5, lowChance)); - list.add(generateEntry(Material.IRON_BLOCK, 1, 3, lowChance)); - return list; + public static Map overworldUndergroundContents() { + //Clones the list from above ground + Map items = new HashMap<>(overworldContents()); + Map commonItems = new HashMap<>(); + Map rareItems = new HashMap<>(); + Map epicItems = new HashMap<>(); + List> commonList = new ArrayList<>(); + List> rareList = new ArrayList<>(); + List> epicList = new ArrayList<>(); + + commonList.add(generateEntry(Material.RAIL, 2, 5, normalWeight)); + commonList.add(generateEntry(Material.PISTON, 3, 9, extraRareWeight)); + commonList.add(generateEntry(Material.TNT, 2, 6, extraRareWeight)); + commonList.add(generateEntry(Material.MINECART, 1, 1, normalWeight)); + commonList.add(generateEntry(Material.MINECART, 1, 1, normalWeight)); + commonList.add(generateEntry(Material.ACTIVATOR_RAIL, 1, 3, rareWeight)); + commonList.add(generateEntry(Material.POWERED_RAIL, 1, 5, rareWeight)); + commonList.add(generateEntry(Material.LAPIS_LAZULI, 1, 16, normalWeight)); + commonList.add(generateEntry(Material.IRON_BLOCK, 1, 3, rareWeight)); + commonList.add(generateEntry(Material.ARROW, 16, 32, normalWeight)); + commonList.add(generateEntry(Material.BREAD, 8, 16, normalWeight)); + commonList.add(generateEntry(Material.CHAIN, 1, 8, normalWeight)); + commonList.add(generateEntry(Material.CHEST, 1, 6, normalWeight)); + commonList.add(generateEntry(Material.CLAY_BALL, 1, 16, normalWeight)); + commonList.add(generateEntry(Material.COOKED_BEEF, 8, 16, normalWeight)); + commonList.add(generateEntry(Material.COOKED_PORKCHOP, 8, 16, normalWeight)); + commonList.add(generateEntry(Material.COMPASS, 1, 4, normalWeight)); + commonList.add(generateEntry(Material.EMERALD, 1, 6, normalWeight)); + commonList.add(generateEntry(Material.EXPERIENCE_BOTTLE, 1, 2, normalWeight)); + commonList.add(generateEntry(Material.FLINT, 1, 8, normalWeight)); + commonList.add(generateEntry(Material.FLINT_AND_STEEL, 1, 1, normalWeight)); + commonList.add(generateEntry(Material.GLISTERING_MELON_SLICE, 1, 4, extraRareWeight)); + commonList.add(generateEntry(Material.LEATHER_BOOTS, 1, 1, normalWeight)); + commonList.add(generateEntry(Material.LEATHER_HELMET, 1, 1, normalWeight)); + commonList.add(generateEntry(Material.LEATHER_LEGGINGS, 1, 1, normalWeight)); + commonList.add(generateEntry(Material.LEATHER_CHESTPLATE, 1, 1, normalWeight)); + commonList.add(generateEntry(Material.LEATHER_HELMET, 1, 1, rareWeight, true)); + commonList.add(generateEntry(Material.LEATHER_HORSE_ARMOR, 1, 1, extraRareWeight)); + commonList.add(generateEntry(Material.LEATHER_LEGGINGS, 1, 1, rareWeight, true)); + commonList.add(generateEntry(Material.LEATHER_CHESTPLATE, 1, 1, rareWeight, true)); + commonList.add(generateEntry(Material.MUSIC_DISC_11, 1, 1, extraRareWeight)); + commonList.add(generateEntry(Material.MUSIC_DISC_13, 1, 1, extraRareWeight)); + commonList.add(generateEntry(Material.MUSIC_DISC_BLOCKS, 1, 1, extraRareWeight)); + commonList.add(generateEntry(Material.MUSIC_DISC_CAT, 1, 1, extraRareWeight)); + commonList.add(generateEntry(Material.MUSIC_DISC_CHIRP, 1, 1, extraRareWeight)); + commonList.add(generateEntry(Material.MUSIC_DISC_FAR, 1, 1, extraRareWeight)); + commonList.add(generateEntry(Material.MUSIC_DISC_MALL, 1, 1, extraRareWeight)); + commonList.add(generateEntry(Material.MUSIC_DISC_MELLOHI, 1, 1, extraRareWeight)); + commonList.add(generateEntry(Material.MUSIC_DISC_PIGSTEP, 1, 1, extraRareWeight)); + commonList.add(generateEntry(Material.MUSIC_DISC_STAL, 1, 1, extraRareWeight)); + commonList.add(generateEntry(Material.MUSIC_DISC_STRAD, 1, 1, extraRareWeight)); + commonList.add(generateEntry(Material.MUSIC_DISC_WAIT, 1, 1, extraRareWeight)); + commonList.add(generateEntry(Material.MUSIC_DISC_WARD, 1, 1, extraRareWeight)); + commonList.add(generateEntry(Material.STONE_AXE, 1, 1, extraRareWeight)); + commonList.add(generateEntry(Material.STONE_HOE, 1, 1, extraRareWeight)); + commonList.add(generateEntry(Material.STONE_PICKAXE, 1, 1, extraRareWeight)); + commonList.add(generateEntry(Material.STONE_SHOVEL, 1, 1, extraRareWeight)); + commonList.add(generateEntry(Material.STONE_SWORD, 1, 1, extraRareWeight)); + commonList.add(generateEntry(Material.STONE_AXE, 1, 1, extraRareWeight, true)); + commonList.add(generateEntry(Material.STONE_HOE, 1, 1, extraRareWeight, true)); + commonList.add(generateEntry(Material.STONE_PICKAXE, 1, 1, extraRareWeight, true)); + commonList.add(generateEntry(Material.STONE_SHOVEL, 1, 1, extraRareWeight, true)); + commonList.add(generateEntry(Material.STONE_SWORD, 1, 1, extraRareWeight, true)); + commonList.add(generateEntry(Material.WOODEN_AXE, 1, 1, normalWeight)); + commonList.add(generateEntry(Material.WOODEN_HOE, 1, 1, normalWeight)); + commonList.add(generateEntry(Material.WOODEN_PICKAXE, 1, 1, normalWeight)); + commonList.add(generateEntry(Material.WOODEN_SHOVEL, 1, 1, normalWeight)); + commonList.add(generateEntry(Material.WOODEN_SWORD, 1, 1, normalWeight)); + commonList.add(generateEntry(Material.WOODEN_AXE, 1, 1, rareWeight, true)); + commonList.add(generateEntry(Material.WOODEN_HOE, 1, 1, rareWeight, true)); + commonList.add(generateEntry(Material.WOODEN_PICKAXE, 1, 1, rareWeight, true)); + commonList.add(generateEntry(Material.WOODEN_SHOVEL, 1, 1, rareWeight, true)); + commonList.add(generateEntry(Material.WOODEN_SWORD, 1, 1, rareWeight, true)); + commonList.add(generateEntry(Material.BOW, 1, 1, normalWeight)); + commonList.add(generateEntry(Material.CROSSBOW, 1, 1, normalWeight)); + commonList.add(generateEntry(Material.TRIDENT, 1, 1, normalWeight)); + commonList.add(generateEntry(Material.TURTLE_HELMET, 1, 1, normalWeight)); + rareList.add(generateEntry(Material.CHEST_MINECART, 1, 1, normalWeight)); + rareList.add(generateEntry(Material.DIAMOND, 2, 10, extraRareWeight)); + rareList.add(generateEntry(Material.LANTERN, 3, 9, extraRareWeight)); + rareList.add(generateEntry(Material.TURTLE_HELMET, 1, 1, normalWeight, true)); + rareList.add(generateEntry(Material.CROSSBOW, 1, 1, normalWeight, true)); + rareList.add(generateEntry(Material.BONE_MEAL, 2, 12, normalWeight)); + rareList.add(generateEntry(Material.CHAINMAIL_BOOTS, 1, 1, rareWeight)); + rareList.add(generateEntry(Material.CHAINMAIL_CHESTPLATE, 1, 1, rareWeight)); + rareList.add(generateEntry(Material.CHAINMAIL_HELMET, 1, 1, rareWeight)); + rareList.add(generateEntry(Material.CHAINMAIL_LEGGINGS, 1, 1, rareWeight)); + rareList.add(generateEntry(Material.CHAINMAIL_BOOTS, 1, 1, rareWeight, true)); + rareList.add(generateEntry(Material.CHAINMAIL_CHESTPLATE, 1, 1, rareWeight, true)); + rareList.add(generateEntry(Material.CHAINMAIL_HELMET, 1, 1, rareWeight, true)); + rareList.add(generateEntry(Material.CHAINMAIL_LEGGINGS, 1, 1, rareWeight, true)); + rareList.add(generateEntry(Material.DIAMOND_HORSE_ARMOR, 1, 1, rareWeight)); + rareList.add(generateEntry(Material.IRON_AXE, 1, 1, normalWeight)); + rareList.add(generateEntry(Material.IRON_BOOTS, 1, 1, normalWeight)); + rareList.add(generateEntry(Material.IRON_CHESTPLATE, 1, 1, normalWeight)); + rareList.add(generateEntry(Material.IRON_HELMET, 1, 1, normalWeight)); + rareList.add(generateEntry(Material.IRON_HOE, 1, 1, normalWeight)); + rareList.add(generateEntry(Material.IRON_LEGGINGS, 1, 1, normalWeight)); + rareList.add(generateEntry(Material.IRON_PICKAXE, 1, 1, normalWeight)); + rareList.add(generateEntry(Material.IRON_SHOVEL, 1, 1, normalWeight)); + rareList.add(generateEntry(Material.IRON_SWORD, 1, 1, normalWeight)); + rareList.add(generateEntry(Material.IRON_AXE, 1, 1, extraRareWeight, true)); + rareList.add(generateEntry(Material.IRON_BOOTS, 1, 1, extraRareWeight, true)); + rareList.add(generateEntry(Material.IRON_CHESTPLATE, 1, 1, extraRareWeight, true)); + rareList.add(generateEntry(Material.IRON_HELMET, 1, 1, extraRareWeight, true)); + rareList.add(generateEntry(Material.IRON_HOE, 1, 1, extraRareWeight, true)); + rareList.add(generateEntry(Material.IRON_HORSE_ARMOR, 1, 1, extraRareWeight)); + rareList.add(generateEntry(Material.IRON_INGOT, 3, 9, extraRareWeight)); + rareList.add(generateEntry(Material.IRON_LEGGINGS, 1, 1, extraRareWeight, true)); + rareList.add(generateEntry(Material.IRON_PICKAXE, 1, 1, extraRareWeight, true)); + rareList.add(generateEntry(Material.IRON_SHOVEL, 1, 1, extraRareWeight, true)); + rareList.add(generateEntry(Material.IRON_SWORD, 1, 1, extraRareWeight, true)); + rareList.add(generateEntry(Material.SHIELD, 1, 1, rareWeight, true)); + rareList.add(generateEntry(Material.GLASS_BOTTLE, 2, 8, rareWeight)); + rareList.add(generateEntry(Material.GOLDEN_APPLE, 3, 9, extraRareWeight)); + rareList.add(generateEntry(Material.GOLDEN_CARROT, 3, 9, rareWeight)); + rareList.add(generateEntry(Material.SPYGLASS, 1, 1, normalWeight)); + rareList.add(generateEntry(Material.MUSHROOM_STEW, 3, 9, normalWeight)); + rareList.add(generateEntry(Material.BUNDLE, 1, 1, rareWeight)); + epicList.add(generateEntry(Material.KNOWLEDGE_BOOK, 1, 1, extraRareWeight)); //Reveals all recipes + epicList.add(generateEntry(Material.TNT_MINECART, 1, 1, normalWeight)); + if (!VersionChecker.serverVersionOlderThan(19, 0)) + epicList.add(generateEntry(Material.SCULK, 1, 6, normalWeight)); //1.19 + epicList.add(generateEntry(Material.TOTEM_OF_UNDYING, 1, 1, normalWeight)); + epicList.add(generateEntry(Material.DIAMOND_AXE, 1, 1, normalWeight)); + epicList.add(generateEntry(Material.DIAMOND_BOOTS, 1, 1, normalWeight)); + epicList.add(generateEntry(Material.DIAMOND_HELMET, 1, 1, normalWeight)); + epicList.add(generateEntry(Material.DIAMOND_HOE, 1, 1, normalWeight)); + epicList.add(generateEntry(Material.DIAMOND_LEGGINGS, 1, 1, normalWeight)); + epicList.add(generateEntry(Material.DIAMOND_SWORD, 1, 1, normalWeight)); + epicList.add(generateEntry(Material.DIAMOND_PICKAXE, 1, 1, normalWeight)); + epicList.add(generateEntry(Material.DIAMOND_SHOVEL, 1, 1, normalWeight)); + epicList.add(generateEntry(Material.DIAMOND, 2, 10, extraRareWeight)); + epicList.add(generateEntry(Material.DIAMOND_AXE, 1, 1, normalWeight, true)); + epicList.add(generateEntry(Material.DIAMOND_BOOTS, 1, 1, normalWeight, true)); + epicList.add(generateEntry(Material.DIAMOND_HELMET, 1, 1, normalWeight, true)); + epicList.add(generateEntry(Material.DIAMOND_HOE, 1, 1, normalWeight, true)); + epicList.add(generateEntry(Material.DIAMOND_LEGGINGS, 1, 1, normalWeight, true)); + epicList.add(generateEntry(Material.DIAMOND_SWORD, 1, 1, normalWeight, true)); + epicList.add(generateEntry(Material.DIAMOND_PICKAXE, 1, 1, normalWeight, true)); + epicList.add(generateEntry(Material.DIAMOND_SHOVEL, 1, 1, normalWeight, true)); + epicList.add(generateEntry(Material.SPECTRAL_ARROW, 8, 16, normalWeight, true)); + epicList.add(generateEntry(Material.SLIME_BALL, 16, 32, normalWeight, true)); + epicList.add(generateEntry(Material.ENCHANTED_GOLDEN_APPLE, 1, 6, extraRareWeight)); + epicList.add(generateEntry(Material.PUMPKIN_PIE, 3, 9, normalWeight)); + epicList.add(generateEntry(Material.TOTEM_OF_UNDYING, 1, 1, extraRareWeight)); + epicList.add(generateEntry(Material.TRIDENT, 1, 1, normalWeight, true)); + + commonItems.put("weight", 60); + commonItems.put("items", commonList); + rareItems.put("weight", 30); + rareItems.put("items", rareList); + epicItems.put("weight", 10); + epicItems.put("items", epicList); + items.put("common", commonItems); + items.put("rare", rareItems); + items.put("epic", epicItems); + return items; } - public static List netherContents() { - List list = new ArrayList<>(overworldContents()); - list.add(generateEntry(Material.GOLD_BLOCK, 1, 3, extraRare)); - list.add(generateEntry(Material.GILDED_BLACKSTONE, 1, 6, lowChance)); - list.add(generateEntry(Material.NETHERITE_SCRAP, 1, 6, lowChance)); - list.add(generateEntry(Material.ANCIENT_DEBRIS, 1, 5, lowChance)); - list.add(generateEntry(Material.MAGMA_CREAM, 1, 5, normalChance)); - return list; + public static Map netherContents() { + Map items = new HashMap<>(); + Map commonItems = new HashMap<>(); + Map rareItems = new HashMap<>(); + Map epicItems = new HashMap<>(); + List> commonList = new ArrayList<>(); + List> rareList = new ArrayList<>(); + List> epicList = new ArrayList<>(); + + commonList.add(generateEntry(Material.GILDED_BLACKSTONE, 1, 6, rareWeight)); + commonList.add(generateEntry(Material.GHAST_TEAR, 1, 1, rareWeight)); + commonList.add(generateEntry(Material.NETHERITE_SCRAP, 1, 6, rareWeight)); + commonList.add(generateEntry(Material.IRON_NUGGET, 3, 9, extraRareWeight)); + commonList.add(generateEntry(Material.ANCIENT_DEBRIS, 1, 5, rareWeight)); + commonList.add(generateEntry(Material.MAGMA_CREAM, 1, 5, normalWeight)); + commonList.add(generateEntry(Material.GOLD_NUGGET, 3, 9, normalWeight)); + commonList.add(generateEntry(Material.GOLDEN_AXE, 1, 1, extraRareWeight)); + commonList.add(generateEntry(Material.GOLDEN_BOOTS, 1, 1, extraRareWeight)); + commonList.add(generateEntry(Material.GOLDEN_CHESTPLATE, 1, 1, extraRareWeight)); + commonList.add(generateEntry(Material.GOLDEN_HELMET, 1, 1, extraRareWeight)); + commonList.add(generateEntry(Material.GOLDEN_HOE, 1, 1, extraRareWeight)); + commonList.add(generateEntry(Material.GOLDEN_LEGGINGS, 1, 1, extraRareWeight)); + commonList.add(generateEntry(Material.GOLDEN_PICKAXE, 1, 1, extraRareWeight)); + commonList.add(generateEntry(Material.GOLDEN_SHOVEL, 1, 1, extraRareWeight)); + commonList.add(generateEntry(Material.GOLDEN_SWORD, 1, 1, extraRareWeight)); + commonList.add(generateEntry(Material.GOLDEN_AXE, 1, 1, extraRareWeight, true)); + commonList.add(generateEntry(Material.GOLDEN_BOOTS, 1, 1, extraRareWeight, true)); + commonList.add(generateEntry(Material.GOLDEN_CHESTPLATE, 1, 1, extraRareWeight, true)); + commonList.add(generateEntry(Material.GOLDEN_HELMET, 1, 1, extraRareWeight, true)); + commonList.add(generateEntry(Material.GOLDEN_HOE, 1, 1, extraRareWeight, true)); + commonList.add(generateEntry(Material.GOLDEN_HORSE_ARMOR, 1, 1, extraRareWeight)); + commonList.add(generateEntry(Material.GOLDEN_LEGGINGS, 1, 1, extraRareWeight, true)); + commonList.add(generateEntry(Material.GOLDEN_PICKAXE, 1, 1, extraRareWeight, true)); + commonList.add(generateEntry(Material.GOLDEN_SHOVEL, 1, 1, extraRareWeight, true)); + commonList.add(generateEntry(Material.GOLDEN_SWORD, 1, 1, extraRareWeight, true)); + commonList.add(generateEntry(Material.ARROW, 16, 32, normalWeight)); + commonList.add(generateEntry(Material.BREAD, 8, 16, normalWeight)); + commonList.add(generateEntry(Material.CHAIN, 1, 8, normalWeight)); + commonList.add(generateEntry(Material.CHEST, 1, 6, normalWeight)); + commonList.add(generateEntry(Material.CLAY_BALL, 1, 16, normalWeight)); + commonList.add(generateEntry(Material.COOKED_BEEF, 8, 16, normalWeight)); + commonList.add(generateEntry(Material.COOKED_PORKCHOP, 8, 16, normalWeight)); + commonList.add(generateEntry(Material.COMPASS, 1, 4, normalWeight)); + commonList.add(generateEntry(Material.EMERALD, 1, 6, normalWeight)); + commonList.add(generateEntry(Material.EXPERIENCE_BOTTLE, 1, 2, normalWeight)); + commonList.add(generateEntry(Material.FLINT, 1, 8, normalWeight)); + commonList.add(generateEntry(Material.FLINT_AND_STEEL, 1, 1, normalWeight)); + commonList.add(generateEntry(Material.GLISTERING_MELON_SLICE, 1, 4, extraRareWeight)); + commonList.add(generateEntry(Material.LEATHER_BOOTS, 1, 1, normalWeight)); + commonList.add(generateEntry(Material.LEATHER_HELMET, 1, 1, normalWeight)); + commonList.add(generateEntry(Material.LEATHER_LEGGINGS, 1, 1, normalWeight)); + commonList.add(generateEntry(Material.LEATHER_CHESTPLATE, 1, 1, normalWeight)); + commonList.add(generateEntry(Material.LEATHER_HELMET, 1, 1, rareWeight, true)); + commonList.add(generateEntry(Material.LEATHER_HORSE_ARMOR, 1, 1, extraRareWeight)); + commonList.add(generateEntry(Material.LEATHER_LEGGINGS, 1, 1, rareWeight, true)); + commonList.add(generateEntry(Material.LEATHER_CHESTPLATE, 1, 1, rareWeight, true)); + commonList.add(generateEntry(Material.MUSIC_DISC_11, 1, 1, extraRareWeight)); + commonList.add(generateEntry(Material.MUSIC_DISC_13, 1, 1, extraRareWeight)); + commonList.add(generateEntry(Material.MUSIC_DISC_BLOCKS, 1, 1, extraRareWeight)); + commonList.add(generateEntry(Material.MUSIC_DISC_CAT, 1, 1, extraRareWeight)); + commonList.add(generateEntry(Material.MUSIC_DISC_CHIRP, 1, 1, extraRareWeight)); + commonList.add(generateEntry(Material.MUSIC_DISC_FAR, 1, 1, extraRareWeight)); + commonList.add(generateEntry(Material.MUSIC_DISC_MALL, 1, 1, extraRareWeight)); + commonList.add(generateEntry(Material.MUSIC_DISC_MELLOHI, 1, 1, extraRareWeight)); + commonList.add(generateEntry(Material.MUSIC_DISC_PIGSTEP, 1, 1, extraRareWeight)); + commonList.add(generateEntry(Material.MUSIC_DISC_STAL, 1, 1, extraRareWeight)); + commonList.add(generateEntry(Material.MUSIC_DISC_STRAD, 1, 1, extraRareWeight)); + commonList.add(generateEntry(Material.MUSIC_DISC_WAIT, 1, 1, extraRareWeight)); + commonList.add(generateEntry(Material.MUSIC_DISC_WARD, 1, 1, extraRareWeight)); + commonList.add(generateEntry(Material.STONE_AXE, 1, 1, extraRareWeight)); + commonList.add(generateEntry(Material.STONE_HOE, 1, 1, extraRareWeight)); + commonList.add(generateEntry(Material.STONE_PICKAXE, 1, 1, extraRareWeight)); + commonList.add(generateEntry(Material.STONE_SHOVEL, 1, 1, extraRareWeight)); + commonList.add(generateEntry(Material.STONE_SWORD, 1, 1, extraRareWeight)); + commonList.add(generateEntry(Material.STONE_AXE, 1, 1, extraRareWeight, true)); + commonList.add(generateEntry(Material.STONE_HOE, 1, 1, extraRareWeight, true)); + commonList.add(generateEntry(Material.STONE_PICKAXE, 1, 1, extraRareWeight, true)); + commonList.add(generateEntry(Material.STONE_SHOVEL, 1, 1, extraRareWeight, true)); + commonList.add(generateEntry(Material.STONE_SWORD, 1, 1, extraRareWeight, true)); + commonList.add(generateEntry(Material.WOODEN_AXE, 1, 1, normalWeight)); + commonList.add(generateEntry(Material.WOODEN_HOE, 1, 1, normalWeight)); + commonList.add(generateEntry(Material.WOODEN_PICKAXE, 1, 1, normalWeight)); + commonList.add(generateEntry(Material.WOODEN_SHOVEL, 1, 1, normalWeight)); + commonList.add(generateEntry(Material.WOODEN_SWORD, 1, 1, normalWeight)); + commonList.add(generateEntry(Material.WOODEN_AXE, 1, 1, rareWeight, true)); + commonList.add(generateEntry(Material.WOODEN_HOE, 1, 1, rareWeight, true)); + commonList.add(generateEntry(Material.WOODEN_PICKAXE, 1, 1, rareWeight, true)); + commonList.add(generateEntry(Material.WOODEN_SHOVEL, 1, 1, rareWeight, true)); + commonList.add(generateEntry(Material.WOODEN_SWORD, 1, 1, rareWeight, true)); + commonList.add(generateEntry(Material.BOW, 1, 1, normalWeight)); + commonList.add(generateEntry(Material.CROSSBOW, 1, 1, normalWeight)); + commonList.add(generateEntry(Material.TRIDENT, 1, 1, normalWeight)); + commonList.add(generateEntry(Material.TURTLE_HELMET, 1, 1, normalWeight)); + rareList.add(generateEntry(Material.BLAZE_ROD, 3, 9, normalWeight)); + rareList.add(generateEntry(Material.DIAMOND, 2, 10, extraRareWeight)); + rareList.add(generateEntry(Material.GOLD_INGOT, 1, 3, normalWeight)); + rareList.add(generateEntry(Material.GOLD_INGOT, 6, 12, extraRareWeight)); + rareList.add(generateEntry(Material.FIRE_CHARGE, 1, 3, extraRareWeight)); + rareList.add(generateEntry(Material.NETHER_QUARTZ_ORE, 6, 27, rareWeight)); + rareList.add(generateEntry(Material.TURTLE_HELMET, 1, 1, normalWeight, true)); + rareList.add(generateEntry(Material.CROSSBOW, 1, 1, normalWeight, true)); + rareList.add(generateEntry(Material.BONE_MEAL, 2, 12, normalWeight)); + rareList.add(generateEntry(Material.CHAINMAIL_BOOTS, 1, 1, rareWeight)); + rareList.add(generateEntry(Material.CHAINMAIL_CHESTPLATE, 1, 1, rareWeight)); + rareList.add(generateEntry(Material.CHAINMAIL_HELMET, 1, 1, rareWeight)); + rareList.add(generateEntry(Material.CHAINMAIL_LEGGINGS, 1, 1, rareWeight)); + rareList.add(generateEntry(Material.CHAINMAIL_BOOTS, 1, 1, rareWeight, true)); + rareList.add(generateEntry(Material.CHAINMAIL_CHESTPLATE, 1, 1, rareWeight, true)); + rareList.add(generateEntry(Material.CHAINMAIL_HELMET, 1, 1, rareWeight, true)); + rareList.add(generateEntry(Material.CHAINMAIL_LEGGINGS, 1, 1, rareWeight, true)); + rareList.add(generateEntry(Material.DIAMOND_HORSE_ARMOR, 1, 1, rareWeight)); + rareList.add(generateEntry(Material.IRON_AXE, 1, 1, normalWeight)); + rareList.add(generateEntry(Material.IRON_BOOTS, 1, 1, normalWeight)); + rareList.add(generateEntry(Material.IRON_CHESTPLATE, 1, 1, normalWeight)); + rareList.add(generateEntry(Material.IRON_HELMET, 1, 1, normalWeight)); + rareList.add(generateEntry(Material.IRON_HOE, 1, 1, normalWeight)); + rareList.add(generateEntry(Material.IRON_LEGGINGS, 1, 1, normalWeight)); + rareList.add(generateEntry(Material.IRON_PICKAXE, 1, 1, normalWeight)); + rareList.add(generateEntry(Material.IRON_SHOVEL, 1, 1, normalWeight)); + rareList.add(generateEntry(Material.IRON_SWORD, 1, 1, normalWeight)); + rareList.add(generateEntry(Material.IRON_AXE, 1, 1, extraRareWeight, true)); + rareList.add(generateEntry(Material.IRON_BOOTS, 1, 1, extraRareWeight, true)); + rareList.add(generateEntry(Material.IRON_CHESTPLATE, 1, 1, extraRareWeight, true)); + rareList.add(generateEntry(Material.IRON_HELMET, 1, 1, extraRareWeight, true)); + rareList.add(generateEntry(Material.IRON_HOE, 1, 1, extraRareWeight, true)); + rareList.add(generateEntry(Material.IRON_HORSE_ARMOR, 1, 1, extraRareWeight)); + rareList.add(generateEntry(Material.IRON_INGOT, 3, 9, extraRareWeight)); + rareList.add(generateEntry(Material.IRON_LEGGINGS, 1, 1, extraRareWeight, true)); + rareList.add(generateEntry(Material.IRON_PICKAXE, 1, 1, extraRareWeight, true)); + rareList.add(generateEntry(Material.IRON_SHOVEL, 1, 1, extraRareWeight, true)); + rareList.add(generateEntry(Material.IRON_SWORD, 1, 1, extraRareWeight, true)); + rareList.add(generateEntry(Material.SHIELD, 1, 1, rareWeight, true)); + rareList.add(generateEntry(Material.GLASS_BOTTLE, 2, 8, rareWeight)); + rareList.add(generateEntry(Material.GOLDEN_APPLE, 3, 9, extraRareWeight)); + rareList.add(generateEntry(Material.GOLDEN_CARROT, 3, 9, rareWeight)); + rareList.add(generateEntry(Material.SPYGLASS, 1, 1, normalWeight)); + rareList.add(generateEntry(Material.MUSHROOM_STEW, 3, 9, normalWeight)); + rareList.add(generateEntry(Material.BUNDLE, 1, 1, rareWeight)); + epicList.add(generateEntry(Material.BLAZE_POWDER, 3, 9, normalWeight)); + epicList.add(generateEntry(Material.GOLD_BLOCK, 2, 4, extraRareWeight)); + epicList.add(generateEntry(Material.NETHERITE_AXE, 1, 1, normalWeight)); + epicList.add(generateEntry(Material.NETHERITE_BOOTS, 1, 1, normalWeight)); + epicList.add(generateEntry(Material.NETHERITE_CHESTPLATE, 1, 1, normalWeight)); + epicList.add(generateEntry(Material.NETHERITE_HELMET, 1, 1, normalWeight)); + epicList.add(generateEntry(Material.NETHERITE_HOE, 1, 1, normalWeight)); + epicList.add(generateEntry(Material.NETHERITE_LEGGINGS, 1, 1, normalWeight)); + epicList.add(generateEntry(Material.NETHERITE_PICKAXE, 1, 1, normalWeight)); + epicList.add(generateEntry(Material.NETHERITE_SHOVEL, 1, 1, normalWeight)); + epicList.add(generateEntry(Material.NETHERITE_SWORD, 1, 1, normalWeight)); + epicList.add(generateEntry(Material.NETHERITE_AXE, 1, 1, normalWeight, true)); + epicList.add(generateEntry(Material.NETHERITE_BOOTS, 1, 1, normalWeight, true)); + epicList.add(generateEntry(Material.NETHERITE_CHESTPLATE, 1, 1, normalWeight, true)); + epicList.add(generateEntry(Material.NETHERITE_HELMET, 1, 1, normalWeight, true)); + epicList.add(generateEntry(Material.NETHERITE_HOE, 1, 1, normalWeight, true)); + epicList.add(generateEntry(Material.NETHERITE_LEGGINGS, 1, 1, normalWeight, true)); + epicList.add(generateEntry(Material.NETHERITE_INGOT, 3, 9, normalWeight)); + epicList.add(generateEntry(Material.NETHERITE_PICKAXE, 1, 1, normalWeight, true)); + epicList.add(generateEntry(Material.NETHERITE_SHOVEL, 1, 1, normalWeight, true)); + epicList.add(generateEntry(Material.NETHERITE_SWORD, 1, 1, normalWeight, true)); + epicList.add(generateEntry(Material.POISONOUS_POTATO, 32, 64, extraRareWeight)); + epicList.add(generateEntry(Material.NETHER_STAR, 1, 1, extraRareWeight)); + epicList.add(generateEntry(Material.DIAMOND_AXE, 1, 1, normalWeight)); + epicList.add(generateEntry(Material.DIAMOND_BOOTS, 1, 1, normalWeight)); + epicList.add(generateEntry(Material.DIAMOND_HELMET, 1, 1, normalWeight)); + epicList.add(generateEntry(Material.DIAMOND_HOE, 1, 1, normalWeight)); + epicList.add(generateEntry(Material.DIAMOND_LEGGINGS, 1, 1, normalWeight)); + epicList.add(generateEntry(Material.DIAMOND_SWORD, 1, 1, normalWeight)); + epicList.add(generateEntry(Material.DIAMOND_PICKAXE, 1, 1, normalWeight)); + epicList.add(generateEntry(Material.DIAMOND_SHOVEL, 1, 1, normalWeight)); + epicList.add(generateEntry(Material.DIAMOND_BLOCK, 1, 1, extraRareWeight)); + epicList.add(generateEntry(Material.DIAMOND, 2, 10, extraRareWeight)); + epicList.add(generateEntry(Material.DIAMOND_AXE, 1, 1, normalWeight, true)); + epicList.add(generateEntry(Material.DIAMOND_BOOTS, 1, 1, normalWeight, true)); + epicList.add(generateEntry(Material.DIAMOND_HELMET, 1, 1, normalWeight, true)); + epicList.add(generateEntry(Material.DIAMOND_HOE, 1, 1, normalWeight, true)); + epicList.add(generateEntry(Material.DIAMOND_LEGGINGS, 1, 1, normalWeight, true)); + epicList.add(generateEntry(Material.DIAMOND_SWORD, 1, 1, normalWeight, true)); + epicList.add(generateEntry(Material.DIAMOND_PICKAXE, 1, 1, normalWeight, true)); + epicList.add(generateEntry(Material.DIAMOND_SHOVEL, 1, 1, normalWeight, true)); + epicList.add(generateEntry(Material.SPECTRAL_ARROW, 8, 16, normalWeight, true)); + epicList.add(generateEntry(Material.SLIME_BALL, 16, 32, normalWeight, true)); + epicList.add(generateEntry(Material.ENCHANTED_GOLDEN_APPLE, 1, 6, extraRareWeight)); + epicList.add(generateEntry(Material.PUMPKIN_PIE, 3, 9, normalWeight)); + epicList.add(generateEntry(Material.TOTEM_OF_UNDYING, 1, 1, extraRareWeight)); + epicList.add(generateEntry(Material.TRIDENT, 1, 1, normalWeight, true)); + + commonItems.put("weight", 60); + commonItems.put("items", commonList); + rareItems.put("weight", 30); + rareItems.put("items", rareList); + epicItems.put("weight", 10); + epicItems.put("items", epicList); + items.put("common", commonItems); + items.put("rare", rareItems); + items.put("epic", epicItems); + return items; } - public static List endContents() { - List list = new ArrayList<>(overworldContents()); - return list; + public static Map endContents() { + Map items = new HashMap<>(); + Map commonItems = new HashMap<>(); + Map rareItems = new HashMap<>(); + Map epicItems = new HashMap<>(); + List> commonList = new ArrayList<>(); + List> rareList = new ArrayList<>(); + List> epicList = new ArrayList<>(); + + commonList.add(generateEntry(Material.CHORUS_FRUIT, 1, 16, rareWeight)); + commonList.add(generateEntry(Material.SOUL_LANTERN, 1, 3, extraRareWeight)); + commonList.add(generateEntry(Material.CRYING_OBSIDIAN, 1, 4, normalWeight)); + commonList.add(generateEntry(Material.ARROW, 16, 32, normalWeight)); + commonList.add(generateEntry(Material.BREAD, 8, 16, normalWeight)); + commonList.add(generateEntry(Material.CHAIN, 1, 8, normalWeight)); + commonList.add(generateEntry(Material.CHEST, 1, 6, normalWeight)); + commonList.add(generateEntry(Material.CLAY_BALL, 1, 16, normalWeight)); + commonList.add(generateEntry(Material.COOKED_BEEF, 8, 16, normalWeight)); + commonList.add(generateEntry(Material.COOKED_PORKCHOP, 8, 16, normalWeight)); + commonList.add(generateEntry(Material.COMPASS, 1, 4, normalWeight)); + commonList.add(generateEntry(Material.EMERALD, 1, 6, normalWeight)); + commonList.add(generateEntry(Material.EXPERIENCE_BOTTLE, 1, 2, normalWeight)); + commonList.add(generateEntry(Material.FLINT, 1, 8, normalWeight)); + commonList.add(generateEntry(Material.FLINT_AND_STEEL, 1, 1, normalWeight)); + commonList.add(generateEntry(Material.GLISTERING_MELON_SLICE, 1, 4, extraRareWeight)); + commonList.add(generateEntry(Material.LEATHER_BOOTS, 1, 1, normalWeight)); + commonList.add(generateEntry(Material.LEATHER_HELMET, 1, 1, normalWeight)); + commonList.add(generateEntry(Material.LEATHER_LEGGINGS, 1, 1, normalWeight)); + commonList.add(generateEntry(Material.LEATHER_CHESTPLATE, 1, 1, normalWeight)); + commonList.add(generateEntry(Material.LEATHER_HELMET, 1, 1, rareWeight, true)); + commonList.add(generateEntry(Material.LEATHER_HORSE_ARMOR, 1, 1, extraRareWeight)); + commonList.add(generateEntry(Material.LEATHER_LEGGINGS, 1, 1, rareWeight, true)); + commonList.add(generateEntry(Material.LEATHER_CHESTPLATE, 1, 1, rareWeight, true)); + commonList.add(generateEntry(Material.MUSIC_DISC_11, 1, 1, extraRareWeight)); + commonList.add(generateEntry(Material.MUSIC_DISC_13, 1, 1, extraRareWeight)); + commonList.add(generateEntry(Material.MUSIC_DISC_BLOCKS, 1, 1, extraRareWeight)); + commonList.add(generateEntry(Material.MUSIC_DISC_CAT, 1, 1, extraRareWeight)); + commonList.add(generateEntry(Material.MUSIC_DISC_CHIRP, 1, 1, extraRareWeight)); + commonList.add(generateEntry(Material.MUSIC_DISC_FAR, 1, 1, extraRareWeight)); + commonList.add(generateEntry(Material.MUSIC_DISC_MALL, 1, 1, extraRareWeight)); + commonList.add(generateEntry(Material.MUSIC_DISC_MELLOHI, 1, 1, extraRareWeight)); + commonList.add(generateEntry(Material.MUSIC_DISC_PIGSTEP, 1, 1, extraRareWeight)); + commonList.add(generateEntry(Material.MUSIC_DISC_STAL, 1, 1, extraRareWeight)); + commonList.add(generateEntry(Material.MUSIC_DISC_STRAD, 1, 1, extraRareWeight)); + commonList.add(generateEntry(Material.MUSIC_DISC_WAIT, 1, 1, extraRareWeight)); + commonList.add(generateEntry(Material.MUSIC_DISC_WARD, 1, 1, extraRareWeight)); + commonList.add(generateEntry(Material.STONE_AXE, 1, 1, extraRareWeight)); + commonList.add(generateEntry(Material.STONE_HOE, 1, 1, extraRareWeight)); + commonList.add(generateEntry(Material.STONE_PICKAXE, 1, 1, extraRareWeight)); + commonList.add(generateEntry(Material.STONE_SHOVEL, 1, 1, extraRareWeight)); + commonList.add(generateEntry(Material.STONE_SWORD, 1, 1, extraRareWeight)); + commonList.add(generateEntry(Material.STONE_AXE, 1, 1, extraRareWeight, true)); + commonList.add(generateEntry(Material.STONE_HOE, 1, 1, extraRareWeight, true)); + commonList.add(generateEntry(Material.STONE_PICKAXE, 1, 1, extraRareWeight, true)); + commonList.add(generateEntry(Material.STONE_SHOVEL, 1, 1, extraRareWeight, true)); + commonList.add(generateEntry(Material.STONE_SWORD, 1, 1, extraRareWeight, true)); + commonList.add(generateEntry(Material.WOODEN_AXE, 1, 1, normalWeight)); + commonList.add(generateEntry(Material.WOODEN_HOE, 1, 1, normalWeight)); + commonList.add(generateEntry(Material.WOODEN_PICKAXE, 1, 1, normalWeight)); + commonList.add(generateEntry(Material.WOODEN_SHOVEL, 1, 1, normalWeight)); + commonList.add(generateEntry(Material.WOODEN_SWORD, 1, 1, normalWeight)); + commonList.add(generateEntry(Material.WOODEN_AXE, 1, 1, rareWeight, true)); + commonList.add(generateEntry(Material.WOODEN_HOE, 1, 1, rareWeight, true)); + commonList.add(generateEntry(Material.WOODEN_PICKAXE, 1, 1, rareWeight, true)); + commonList.add(generateEntry(Material.WOODEN_SHOVEL, 1, 1, rareWeight, true)); + commonList.add(generateEntry(Material.WOODEN_SWORD, 1, 1, rareWeight, true)); + commonList.add(generateEntry(Material.BOW, 1, 1, normalWeight)); + commonList.add(generateEntry(Material.CROSSBOW, 1, 1, normalWeight)); + commonList.add(generateEntry(Material.TRIDENT, 1, 1, normalWeight)); + commonList.add(generateEntry(Material.TURTLE_HELMET, 1, 1, normalWeight)); + rareList.add(generateEntry(Material.DIAMOND, 2, 10, rareWeight)); + rareList.add(generateEntry(Material.ENDER_CHEST, 1, 1, rareWeight)); + rareList.add(generateEntry(Material.TURTLE_HELMET, 1, 1, normalWeight, true)); + rareList.add(generateEntry(Material.CROSSBOW, 1, 1, normalWeight, true)); + rareList.add(generateEntry(Material.BONE_MEAL, 2, 12, normalWeight)); + rareList.add(generateEntry(Material.CHAINMAIL_BOOTS, 1, 1, rareWeight)); + rareList.add(generateEntry(Material.CHAINMAIL_CHESTPLATE, 1, 1, rareWeight)); + rareList.add(generateEntry(Material.CHAINMAIL_HELMET, 1, 1, rareWeight)); + rareList.add(generateEntry(Material.CHAINMAIL_LEGGINGS, 1, 1, rareWeight)); + rareList.add(generateEntry(Material.CHAINMAIL_BOOTS, 1, 1, rareWeight, true)); + rareList.add(generateEntry(Material.CHAINMAIL_CHESTPLATE, 1, 1, rareWeight, true)); + rareList.add(generateEntry(Material.CHAINMAIL_HELMET, 1, 1, rareWeight, true)); + rareList.add(generateEntry(Material.CHAINMAIL_LEGGINGS, 1, 1, rareWeight, true)); + rareList.add(generateEntry(Material.DIAMOND_HORSE_ARMOR, 1, 1, rareWeight)); + rareList.add(generateEntry(Material.IRON_AXE, 1, 1, normalWeight)); + rareList.add(generateEntry(Material.IRON_BOOTS, 1, 1, normalWeight)); + rareList.add(generateEntry(Material.IRON_CHESTPLATE, 1, 1, normalWeight)); + rareList.add(generateEntry(Material.IRON_HELMET, 1, 1, normalWeight)); + rareList.add(generateEntry(Material.IRON_HOE, 1, 1, normalWeight)); + rareList.add(generateEntry(Material.IRON_LEGGINGS, 1, 1, normalWeight)); + rareList.add(generateEntry(Material.IRON_PICKAXE, 1, 1, normalWeight)); + rareList.add(generateEntry(Material.IRON_SHOVEL, 1, 1, normalWeight)); + rareList.add(generateEntry(Material.IRON_SWORD, 1, 1, normalWeight)); + rareList.add(generateEntry(Material.IRON_AXE, 1, 1, extraRareWeight, true)); + rareList.add(generateEntry(Material.IRON_BOOTS, 1, 1, extraRareWeight, true)); + rareList.add(generateEntry(Material.IRON_CHESTPLATE, 1, 1, extraRareWeight, true)); + rareList.add(generateEntry(Material.IRON_HELMET, 1, 1, extraRareWeight, true)); + rareList.add(generateEntry(Material.IRON_HOE, 1, 1, extraRareWeight, true)); + rareList.add(generateEntry(Material.IRON_HORSE_ARMOR, 1, 1, extraRareWeight)); + rareList.add(generateEntry(Material.IRON_INGOT, 3, 9, extraRareWeight)); + rareList.add(generateEntry(Material.IRON_LEGGINGS, 1, 1, extraRareWeight, true)); + rareList.add(generateEntry(Material.IRON_PICKAXE, 1, 1, extraRareWeight, true)); + rareList.add(generateEntry(Material.IRON_SHOVEL, 1, 1, extraRareWeight, true)); + rareList.add(generateEntry(Material.IRON_SWORD, 1, 1, extraRareWeight, true)); + rareList.add(generateEntry(Material.SHIELD, 1, 1, rareWeight, true)); + rareList.add(generateEntry(Material.GLASS_BOTTLE, 2, 8, rareWeight)); + rareList.add(generateEntry(Material.GOLDEN_APPLE, 3, 9, extraRareWeight)); + rareList.add(generateEntry(Material.GOLDEN_CARROT, 3, 9, rareWeight)); + rareList.add(generateEntry(Material.SPYGLASS, 1, 1, normalWeight)); + rareList.add(generateEntry(Material.MUSHROOM_STEW, 3, 9, normalWeight)); + rareList.add(generateEntry(Material.BUNDLE, 1, 1, rareWeight)); + epicList.add(generateEntry(Material.ELYTRA, 1, 1, extraRareWeight)); + epicList.add(generateEntry(Material.ENDER_PEARL, 2, 4, rareWeight)); + epicList.add(generateEntry(Material.GRAY_SHULKER_BOX, 1, 1, rareWeight)); + epicList.add(generateEntry(Material.ENDER_EYE, 1, 1, extraRareWeight)); + epicList.add(generateEntry(Material.DIAMOND_AXE, 1, 1, normalWeight)); + epicList.add(generateEntry(Material.DIAMOND_BOOTS, 1, 1, normalWeight)); + epicList.add(generateEntry(Material.DIAMOND_HELMET, 1, 1, normalWeight)); + epicList.add(generateEntry(Material.DIAMOND_HOE, 1, 1, normalWeight)); + epicList.add(generateEntry(Material.DIAMOND_LEGGINGS, 1, 1, normalWeight)); + epicList.add(generateEntry(Material.DIAMOND_SWORD, 1, 1, normalWeight)); + epicList.add(generateEntry(Material.DIAMOND_PICKAXE, 1, 1, normalWeight)); + epicList.add(generateEntry(Material.DIAMOND_SHOVEL, 1, 1, normalWeight)); + epicList.add(generateEntry(Material.DIAMOND_BLOCK, 1, 2, extraRareWeight)); + epicList.add(generateEntry(Material.DIAMOND, 2, 10, extraRareWeight)); + epicList.add(generateEntry(Material.DIAMOND_AXE, 1, 1, normalWeight, true)); + epicList.add(generateEntry(Material.DIAMOND_BOOTS, 1, 1, normalWeight, true)); + epicList.add(generateEntry(Material.DIAMOND_HELMET, 1, 1, normalWeight, true)); + epicList.add(generateEntry(Material.DIAMOND_HOE, 1, 1, normalWeight, true)); + epicList.add(generateEntry(Material.DIAMOND_LEGGINGS, 1, 1, normalWeight, true)); + epicList.add(generateEntry(Material.DIAMOND_SWORD, 1, 1, normalWeight, true)); + epicList.add(generateEntry(Material.DIAMOND_PICKAXE, 1, 1, normalWeight, true)); + epicList.add(generateEntry(Material.DIAMOND_SHOVEL, 1, 1, normalWeight, true)); + epicList.add(generateEntry(Material.SPECTRAL_ARROW, 8, 16, normalWeight, true)); + epicList.add(generateEntry(Material.SLIME_BALL, 16, 32, normalWeight, true)); + epicList.add(generateEntry(Material.ENCHANTED_GOLDEN_APPLE, 1, 6, extraRareWeight)); + epicList.add(generateEntry(Material.PUMPKIN_PIE, 3, 9, normalWeight)); + epicList.add(generateEntry(Material.TOTEM_OF_UNDYING, 1, 1, extraRareWeight)); + epicList.add(generateEntry(Material.TRIDENT, 1, 1, normalWeight, true)); + + commonItems.put("weight", 60); + commonItems.put("items", commonList); + rareItems.put("weight", 30); + rareItems.put("items", rareList); + epicItems.put("weight", 10); + epicItems.put("items", epicList); + items.put("common", commonItems); + items.put("rare", rareItems); + items.put("epic", epicItems); + return items; } - private static String generateEntry(Material material, int minAmount, int maxAmount, double chance) { - return "material=" + material.toString() + ":amount=" + minAmount + "-" + maxAmount + ":chance=" + chance; + public static Map generateEntry(Material material, int minAmount, int maxAmount, double weight) { + return generateEntry(material, minAmount, maxAmount, weight, false); + } + + public static Map generateEntry(Material material, int minAmount, int maxAmount, double weight, boolean procedurallyGeneratedEnchantments) { + HashMap entry = new HashMap<>(); + entry.put("material", material.toString()); + entry.put("amount", minAmount + "-" + maxAmount); + entry.put("weight", weight); + if (procedurallyGeneratedEnchantments) + entry.put("procedurallyGenerateEnchantments", true); + return entry; } + + public static Map generateProcedurallyGeneratedItems() { + /*This is the top level. + procedurallyGeneratedItems: <- you are here + WOODEN_SWORD: + SHARPNESS: + minLevel: 1 + maxLevel: 5 + chance: .1 + */ + Map procedurallyGeneratedEnchantments = new HashMap<>(); + List enchantableItems = List.of( + Material.FISHING_ROD, + Material.SHIELD, + Material.TRIDENT, + Material.CROSSBOW, + Material.BOW, + Material.TURTLE_HELMET, + Material.WOODEN_AXE, + Material.WOODEN_PICKAXE, + Material.WOODEN_HOE, + Material.WOODEN_SHOVEL, + Material.WOODEN_SWORD, + Material.STONE_AXE, + Material.STONE_PICKAXE, + Material.STONE_HOE, + Material.STONE_SHOVEL, + Material.STONE_SWORD, + Material.GOLDEN_AXE, + Material.GOLDEN_PICKAXE, + Material.GOLDEN_HOE, + Material.GOLDEN_SHOVEL, + Material.GOLDEN_SWORD, + Material.GOLDEN_HELMET, + Material.GOLDEN_CHESTPLATE, + Material.GOLDEN_LEGGINGS, + Material.GOLDEN_BOOTS, + Material.CHAINMAIL_HELMET, + Material.CHAINMAIL_CHESTPLATE, + Material.CHAINMAIL_LEGGINGS, + Material.CHAINMAIL_BOOTS, + Material.LEATHER_HELMET, + Material.LEATHER_CHESTPLATE, + Material.LEATHER_LEGGINGS, + Material.LEATHER_BOOTS, + Material.IRON_AXE, + Material.IRON_PICKAXE, + Material.IRON_HOE, + Material.IRON_SHOVEL, + Material.IRON_SWORD, + Material.IRON_HELMET, + Material.IRON_CHESTPLATE, + Material.IRON_LEGGINGS, + Material.IRON_BOOTS, + Material.DIAMOND_AXE, + Material.DIAMOND_PICKAXE, + Material.DIAMOND_HOE, + Material.DIAMOND_SHOVEL, + Material.DIAMOND_SWORD, + Material.DIAMOND_HELMET, + Material.DIAMOND_CHESTPLATE, + Material.DIAMOND_LEGGINGS, + Material.DIAMOND_BOOTS, + Material.NETHERITE_AXE, + Material.NETHERITE_PICKAXE, + Material.NETHERITE_HOE, + Material.NETHERITE_SHOVEL, + Material.NETHERITE_SWORD, + Material.NETHERITE_HELMET, + Material.NETHERITE_CHESTPLATE, + Material.NETHERITE_LEGGINGS, + Material.NETHERITE_BOOTS); + + for (Material enchantableItem : enchantableItems) { + Map> enchantmentMap = new HashMap<>(); + for (Enchantment enchantment : Enchantment.values()) { + if (!enchantment.canEnchantItem(new ItemStack(enchantableItem))) continue; + Map enchantmentSettingsMap = new HashMap<>(); + int minLevel = enchantment.getStartLevel(); + int maxLevel = enchantment.getMaxLevel(); + double chance = 0.2; + enchantmentSettingsMap.put("minLevel", minLevel); + enchantmentSettingsMap.put("maxLevel", maxLevel); + enchantmentSettingsMap.put("chance", chance); + enchantmentMap.put(enchantment.getKey().getKey(), enchantmentSettingsMap); + } + procedurallyGeneratedEnchantments.put(enchantableItem.getKey().getKey(), enchantmentMap); + } + return procedurallyGeneratedEnchantments; + } + } diff --git a/src/main/java/com/magmaguy/betterstructures/util/InfoMessage.java b/src/main/java/com/magmaguy/betterstructures/util/InfoMessage.java new file mode 100644 index 0000000..ac602b6 --- /dev/null +++ b/src/main/java/com/magmaguy/betterstructures/util/InfoMessage.java @@ -0,0 +1,9 @@ +package com.magmaguy.betterstructures.util; + +import org.bukkit.Bukkit; + +public class InfoMessage { + public InfoMessage(String message) { + Bukkit.getLogger().info("[BetterStructures] " + message); + } +} diff --git a/src/main/java/com/magmaguy/betterstructures/util/ItemStackSerialization.java b/src/main/java/com/magmaguy/betterstructures/util/ItemStackSerialization.java index 6849d80..13514b9 100644 --- a/src/main/java/com/magmaguy/betterstructures/util/ItemStackSerialization.java +++ b/src/main/java/com/magmaguy/betterstructures/util/ItemStackSerialization.java @@ -1,45 +1,21 @@ package com.magmaguy.betterstructures.util; import org.bukkit.inventory.ItemStack; -import org.bukkit.util.io.BukkitObjectInputStream; -import org.bukkit.util.io.BukkitObjectOutputStream; -import org.yaml.snakeyaml.external.biz.base64Coder.Base64Coder; -import java.io.ByteArrayInputStream; -import java.io.ByteArrayOutputStream; -import java.io.IOException; +import java.util.Map; public class ItemStackSerialization { - /** - * @param itemStack to serialize - * @return Base64 string of the provided inventory - * @throws IllegalStateException - */ - public static String toBase64(ItemStack itemStack) throws IllegalStateException { - try { - ByteArrayOutputStream outputStream = new ByteArrayOutputStream(); - BukkitObjectOutputStream dataOutput = new BukkitObjectOutputStream(outputStream); - dataOutput.writeObject(itemStack); - dataOutput.close(); - return Base64Coder.encodeLines(outputStream.toByteArray()); - } catch (Exception e) { - throw new IllegalStateException("Unable to save item stacks.", e); - } + private ItemStackSerialization() { + } + + public static Map deserializeItem(ItemStack itemStack) throws IllegalStateException { + return itemStack.serialize(); } - /** - * @param data Base64 string to convert to ItemStack. - * @return ItemStack array created from the Base64 string. - * @throws IOException - */ - public static ItemStack itemStackArrayFromBase64(String data) throws IOException { + public static ItemStack serializeItem(Map deserializedItemStack) { try { - ByteArrayInputStream inputStream = new ByteArrayInputStream(Base64Coder.decodeLines(data)); - BukkitObjectInputStream dataInput = new BukkitObjectInputStream(inputStream); - return (ItemStack) dataInput.readObject(); - } catch (ClassNotFoundException e) { - throw new IOException("Unable to decode class type.", e); - } catch (IOException e) { + return ItemStack.deserialize(deserializedItemStack); + }catch (Exception e) { throw new RuntimeException(e); } } diff --git a/src/main/java/com/magmaguy/betterstructures/util/SurfaceMaterials.java b/src/main/java/com/magmaguy/betterstructures/util/SurfaceMaterials.java index cbe51a4..964ead3 100644 --- a/src/main/java/com/magmaguy/betterstructures/util/SurfaceMaterials.java +++ b/src/main/java/com/magmaguy/betterstructures/util/SurfaceMaterials.java @@ -115,7 +115,6 @@ public static boolean ignorable(Material material) { case WARPED_FENCE: case WARPED_FENCE_GATE: case FERN: - case GRASS: case LILAC: case SNOW_BLOCK: case POWDER_SNOW: @@ -142,6 +141,11 @@ public static boolean ignorable(Material material) { case LARGE_FERN: return true; default: + if (!VersionChecker.serverVersionOlderThan(21,0) && material.equals(Material.GRASS_BLOCK)) + return true; + else if (material.getKey().getKey().contains("grass")) + //GRASS_BLOCK used to be GRASS, this is a bit of a hack to try to make it backwards compatible + return true; return false; } } diff --git a/src/main/java/com/magmaguy/betterstructures/util/VersionChecker.java b/src/main/java/com/magmaguy/betterstructures/util/VersionChecker.java new file mode 100644 index 0000000..e7f0b8f --- /dev/null +++ b/src/main/java/com/magmaguy/betterstructures/util/VersionChecker.java @@ -0,0 +1,133 @@ +package com.magmaguy.betterstructures.util; + +import com.magmaguy.betterstructures.MetadataHandler; +import org.bukkit.Bukkit; +import org.bukkit.event.EventHandler; +import org.bukkit.event.Listener; +import org.bukkit.event.player.PlayerJoinEvent; +import org.bukkit.scheduler.BukkitRunnable; + +import java.io.IOException; +import java.net.URL; +import java.nio.charset.StandardCharsets; +import java.util.Scanner; + +public class VersionChecker { + private static boolean pluginIsUpToDate = true; + + public static void checkPluginVersion() { + new BukkitRunnable() { + @Override + public void run() { + String currentVersion = MetadataHandler.PLUGIN.getDescription().getVersion(); + boolean snapshot = false; + if (currentVersion.contains("SNAPSHOT")) { + snapshot = true; + currentVersion = currentVersion.split("-")[0]; + } + String publicVersion = ""; + + try { + Bukkit.getLogger().info("[BetterStructures] Latest public release is " + VersionChecker.readStringFromURL("https://api.spigotmc.org/legacy/update.php?resource=103241")); + Bukkit.getLogger().info("[BetterStructures] Your version is " + MetadataHandler.PLUGIN.getDescription().getVersion()); + publicVersion = VersionChecker.readStringFromURL("https://api.spigotmc.org/legacy/update.php?resource=103241"); + } catch (IOException e) { + Bukkit.getLogger().warning("[BetterStructures] Couldn't check latest version"); + return; + } + + if (Double.parseDouble(currentVersion.split("\\.")[0]) < Double.parseDouble(publicVersion.split("\\.")[0])) { + outOfDateHandler(); + return; + } + + if (Double.parseDouble(currentVersion.split("\\.")[0]) == Double.parseDouble(publicVersion.split("\\.")[0])) { + + if (Double.parseDouble(currentVersion.split("\\.")[1]) < Double.parseDouble(publicVersion.split("\\.")[1])) { + outOfDateHandler(); + return; + } + + if (Double.parseDouble(currentVersion.split("\\.")[1]) == Double.parseDouble(publicVersion.split("\\.")[1])) { + if (Double.parseDouble(currentVersion.split("\\.")[2]) < Double.parseDouble(publicVersion.split("\\.")[2])) { + outOfDateHandler(); + return; + } + } + } + + if (!snapshot) + Bukkit.getLogger().info("[BetterStructures] You are running the latest version!"); + else + new InfoMessage("You are running a snapshot version! You can check for updates in the #releases channel on the BetterStructures Discord!"); + + pluginIsUpToDate = true; + } + }.runTaskAsynchronously(MetadataHandler.PLUGIN); + } + + /** + * Compares a Minecraft version with the current version on the server. Returns true if the version on the server is older. + * + * @param majorVersion Target major version to compare (i.e. 1.>>>17<<<.0) + * @param minorVersion Target minor version to compare (i.e. 1.17.>>>0<<<) + * @return Whether the version is under the value to be compared + */ + public static boolean serverVersionOlderThan(int majorVersion, int minorVersion) { + + String[] splitVersion = Bukkit.getBukkitVersion().split("[.]"); + + int actualMajorVersion = Integer.parseInt(splitVersion[1].split("-")[0]); + + int actualMinorVersion = 0; + if (splitVersion.length > 2) + actualMinorVersion = Integer.parseInt(splitVersion[2].split("-")[0]); + + if (actualMajorVersion < majorVersion) + return true; + + if (splitVersion.length > 2) + return actualMajorVersion == majorVersion && actualMinorVersion < minorVersion; + + return false; + + } + + + private static String readStringFromURL(String url) throws IOException { + + try (Scanner scanner = new Scanner(new URL(url).openStream(), + StandardCharsets.UTF_8.toString())) { + scanner.useDelimiter("\\A"); + return scanner.hasNext() ? scanner.next() : ""; + } + + } + + private static void outOfDateHandler() { + + new WarningMessage("[BetterStructures] A newer version of this plugin is available for download!"); + pluginIsUpToDate = false; + + } + + public static class VersionCheckerEvents implements Listener { + @EventHandler + public void onPlayerLogin(PlayerJoinEvent event) { + + if (!event.getPlayer().hasPermission("betterstructures.versionnotification")) return; + + new BukkitRunnable() { + @Override + public void run() { + if (!event.getPlayer().isOnline()) return; + if (!pluginIsUpToDate) + event.getPlayer().sendMessage(ChatColorConverter.convert("&a[BetterStructures] &cYour version of BetterStructures is outdated." + + " &aYou can download the latest version from &3&n&ohttps://www.spigotmc.org/resources/betterstructures.103241/")); + } + }.runTaskLater(MetadataHandler.PLUGIN, 20L * 3); + + } + } + +} diff --git a/src/main/java/com/magmaguy/betterstructures/util/WeighedProbability.java b/src/main/java/com/magmaguy/betterstructures/util/WeighedProbability.java index bf065ac..577d3dd 100644 --- a/src/main/java/com/magmaguy/betterstructures/util/WeighedProbability.java +++ b/src/main/java/com/magmaguy/betterstructures/util/WeighedProbability.java @@ -1,6 +1,5 @@ package com.magmaguy.betterstructures.util; -import java.util.HashMap; import java.util.Map; public class WeighedProbability { diff --git a/src/main/java/com/magmaguy/betterstructures/util/WorldEditUtils.java b/src/main/java/com/magmaguy/betterstructures/util/WorldEditUtils.java index e64bdbb..7e19645 100644 --- a/src/main/java/com/magmaguy/betterstructures/util/WorldEditUtils.java +++ b/src/main/java/com/magmaguy/betterstructures/util/WorldEditUtils.java @@ -1,12 +1,96 @@ package com.magmaguy.betterstructures.util; +import com.sk89q.jnbt.CompoundTag; +import com.sk89q.jnbt.ListTag; +import com.sk89q.jnbt.StringTag; import com.sk89q.worldedit.extent.clipboard.Clipboard; +import com.sk89q.worldedit.world.block.BaseBlock; +import org.bukkit.Bukkit; import org.bukkit.util.Vector; +import org.checkerframework.checker.index.qual.Positive; +import org.jetbrains.annotations.NotNull; + +import java.util.ArrayList; +import java.util.regex.Matcher; +import java.util.regex.Pattern; public class WorldEditUtils { + + private static final ArrayList values = new ArrayList<>(); + public static Vector getSchematicOffset(Clipboard clipboard) { - return new Vector(clipboard.getMinimumPoint().getX() - clipboard.getOrigin().getX(), - clipboard.getMinimumPoint().getY() - clipboard.getOrigin().getY(), - clipboard.getMinimumPoint().getZ() - clipboard.getOrigin().getZ()); + return new Vector(clipboard.getMinimumPoint().getX() - clipboard.getOrigin().getX(), clipboard.getMinimumPoint().getY() - clipboard.getOrigin().getY(), clipboard.getMinimumPoint().getZ() - clipboard.getOrigin().getZ()); + } + + /** + *

Parses data from a sign's NBT and returns the specified line number. + * Tested with WorldEdit and FastAsyncWorldEdit NBT format.

+ */ + public static String getLine(@NotNull BaseBlock baseBlock, @Positive int line) { + values.clear(); + if (baseBlock.getNbtData() == null) { + return ""; + } + CompoundTag data = baseBlock.getNbtData(); + return getLineWe(data, line); + } + + /** + *

Parses data from a sign's NBT and returns the specified line number. + * Designed for WorldEdit NBT format.

+ */ + private static String getLineWe(@NotNull CompoundTag data, @Positive int line) { + try { + if (data.getValue().containsKey("Text" + line)) { + return getOldWEFormat(data, line); + } else { + return getNewWEFormat(data, line); + } + + } catch (Exception ex) { + Bukkit.getLogger().warning("Unexpected sign format!" + data); + } + + return ""; + } + + private static String getOldWEFormat(@NotNull CompoundTag data, @Positive int line) { + try { + String text = ((StringTag) data.getValue().get("Text" + line)).getValue(); + + Pattern pattern = Pattern.compile("\\{\"text\":\"(.*?)\"\\}"); + Matcher matcher = pattern.matcher(text); + + if (matcher.find()) { + String extractedText = matcher.group(1); + return extractedText; + } else { + throw new Exception(); + } + } catch (Exception ex) { + Bukkit.getLogger().warning("Unexpected sign format in legacy read!\n" + data); + } + return null; + } + + private static String getNewWEFormat(@NotNull CompoundTag data, @Positive int line) { + try { + //Get front text + CompoundTag frontText = (CompoundTag) data.getValue().get("front_text"); + //Get messages + ListTag messages = (ListTag) frontText.getValue().get("messages"); + //Get the line + String text = messages.getString(line - 1); + + if (text.contains("\"text\":")) text = text.split("text\":\"")[1].split("\"")[0]; + text = text.replaceAll("\"", ""); + if (text.contains("test")) Bukkit.getLogger().warning("boss name:" + text); + + return text; + + } catch (Exception ex) { + Bukkit.getLogger().warning("Unexpected sign format in new read!\n" + data); + } + return null; } } diff --git a/src/main/java/com/magmaguy/betterstructures/util/ZipFile.java b/src/main/java/com/magmaguy/betterstructures/util/ZipFile.java new file mode 100644 index 0000000..eca46b3 --- /dev/null +++ b/src/main/java/com/magmaguy/betterstructures/util/ZipFile.java @@ -0,0 +1,136 @@ +package com.magmaguy.betterstructures.util; + +import com.magmaguy.betterstructures.MetadataHandler; + +import java.io.*; +import java.util.zip.ZipEntry; +import java.util.zip.ZipInputStream; +import java.util.zip.ZipOutputStream; + +public class ZipFile { + private ZipFile() { + } + + public static boolean zip(File directory, String targetZipPath) { + if (!directory.exists()) { + new WarningMessage("Failed to zip directory " + directory.getPath() + " because it does not exist!"); + return false; + } + + try { + ZipFile.ZipUtility.zip(directory, targetZipPath); + return true; + } catch (IOException e) { + e.printStackTrace(); + return false; + } + } + + public static File unzip(String zippedFileName) throws IOException { + String mainDirectory = MetadataHandler.PLUGIN.getDataFolder().getAbsolutePath() + "/imports/"; + String fileZip = mainDirectory + zippedFileName; + File finalDirectory = new File(mainDirectory + zippedFileName.replace(".zip", "")); + byte[] buffer = new byte[1024]; + ZipInputStream zipInputStream = new ZipInputStream(new FileInputStream(fileZip)); + ZipEntry zipEntry = zipInputStream.getNextEntry(); + while (zipEntry != null) { + File newFile = newFile(finalDirectory, zipEntry); + if (zipEntry.isDirectory()) { + if (!newFile.isDirectory() && !newFile.mkdirs()) { + throw new IOException("Failed to create directory " + newFile); + } + } else { + // fix for Windows-created archives + File parent = newFile.getParentFile(); + if (!parent.isDirectory() && !parent.mkdirs()) { + throw new IOException("Failed to create directory " + parent); + } + + // write file content + FileOutputStream fileOutputStream = new FileOutputStream(newFile); + int len; + while ((len = zipInputStream.read(buffer)) > 0) { + fileOutputStream.write(buffer, 0, len); + } + fileOutputStream.close(); + } + zipEntry = zipInputStream.getNextEntry(); + } + zipInputStream.closeEntry(); + zipInputStream.close(); + return finalDirectory; + } + + private static File newFile(File destinationDir, ZipEntry zipEntry) throws IOException { + File destFile = new File(destinationDir, zipEntry.getName()); + + String destDirPath = destinationDir.getCanonicalPath(); + String destFilePath = destFile.getCanonicalPath(); + + if (!destFilePath.startsWith(destDirPath + File.separatorChar)) { + throw new IOException("Entry is outside of the target dir: " + zipEntry.getName()); + } + + return destFile; + } + + public static class ZipUtility { + private static final int BUFFER_SIZE = 4096; + + public ZipUtility() { + } + + public static void zip(File file, String destZipFile) throws FileNotFoundException, IOException { + ZipOutputStream zos = new ZipOutputStream(new FileOutputStream(destZipFile)); + //This slight tweak avoids making the directory zipped be in the zipped file when what we are looking for is to + //zip the contents of the directory, outside of the directory itself + if (file.isDirectory()) { + for (File file1 : file.listFiles()) { + if (file1.isDirectory()) + zipDirectory(file1, file1.getName(), zos); + else + zipFile(file1, zos); + } + } else { + zipFile(file, zos); + } + zos.flush(); + zos.close(); + } + + private static void zipDirectory(File folder, String parentFolder, + ZipOutputStream zos) throws FileNotFoundException, IOException { + for (File file : folder.listFiles()) { + if (file.isDirectory()) { + zipDirectory(file, parentFolder + "/" + file.getName(), zos); + continue; + } + zos.putNextEntry(new ZipEntry(parentFolder + "/" + file.getName())); + BufferedInputStream bis = new BufferedInputStream(new FileInputStream(file)); + long bytesRead = 0; + byte[] bytesIn = new byte[BUFFER_SIZE]; + int read = 0; + while ((read = bis.read(bytesIn)) != -1) { + zos.write(bytesIn, 0, read); + bytesRead += read; + } + zos.closeEntry(); + } + } + + private static void zipFile(File file, ZipOutputStream zos) + throws FileNotFoundException, IOException { + zos.putNextEntry(new ZipEntry(file.getName())); + BufferedInputStream bis = new BufferedInputStream(new FileInputStream( + file)); + long bytesRead = 0; + byte[] bytesIn = new byte[BUFFER_SIZE]; + int read = 0; + while ((read = bis.read(bytesIn)) != -1) { + zos.write(bytesIn, 0, read); + bytesRead += read; + } + zos.closeEntry(); + } + } +} diff --git a/src/main/resources/plugin.yml b/src/main/resources/plugin.yml index 4634fbb..1bf4e88 100644 --- a/src/main/resources/plugin.yml +++ b/src/main/resources/plugin.yml @@ -1,8 +1,12 @@ name: BetterStructures -version: '1.1.0' +version: '1.6.11' main: com.magmaguy.betterstructures.BetterStructures api-version: 1.14 depend: [ WorldEdit ] +softdepend: + - EliteMobs + - WorldGuard + - WorldEdit authors: [ MagmaGuy ] description: A plugin that adds random structures to your Minecraft world! website: magmaguy.com diff --git a/src/main/resources/schematics/ReadMe.txt b/src/main/resources/schematics/ReadMe.txt index f61cf8d..ba2166c 100644 --- a/src/main/resources/schematics/ReadMe.txt +++ b/src/main/resources/schematics/ReadMe.txt @@ -1,86 +1,4 @@ -Thank you for downloading BetterStructures! - -Made with caffeine by MagmaGuy thanks to the Patreon supporters at https://www.patreon.com/magmaguy ! - -The following covers basic information about the plugin. If the information seems outdated, try deleting this file - it only updates when you delete it! - -Index: -a) Basic information -b) Normal users - 1) Plugin requirements - 2) Installing pre-made content -c) Advanced users - 1) Debugging - 1.1) Commands - 1.2) Permissions - 2) Customizing content - 2.1) Editing schematics - 2.2) Editing schematic configuration files - 2.3) Editing generators -d) Creators - 1) Creating schematics - 1.1) Special blocks - 1.2) Chests - 1.3) Mobs - 2) Creating generators - 2.1) Creating chest content - 2.2) Creating mobs - -a) Basic information - -BetterStructures is a plugin which aims to fit custom pre-made structures in any world generation. These builds can be downloaded, edited and created by anyone. Premade structures are provided in https://magmaguy.itch.io/ and https://www.patreon.com/magmaguy . At the time of writing this there is a pack of 100 free builds you can download from itch right now, on top of premium ones. - -These builds can be put in the air, on liquids (regular oceans and lava oceans), fit on terrain surfaces and placed underground. BetterStructures divides the underground into two sections - shallow underground and deep underground. It also works for any generator - normal, end and nether, and most "normal" minecraft world generators (skygrid is the only known exception). - -The inner workings of the plugin are described on section c.2) Customizing content. - -b) Basic users - -1) Plugin requirements - -BetterStructures relies on WorldEdit in order to paste builds (in a schematic file format) into your world. When downloading WorldEdit make sure you download the correct version for your server - it is very picky about which version you use! - -That is the only requirement. - -2) Installing pre-made content - -Due to the size of schematic files, BetterStructures does not come with builds pre-packaged. However, default builds are distributed for free on https://magmaguy.itch.io/ (there is a 100 default BetterStructures pack), and further builds are distributed not only there but also on https://www.patreon.com/magmaguy . - -You can also use other existing schematics (you may want to customize them a bit, refer to section C of this guide) or download unofficial packages - or even make your own! - -To install the content, unzip the folder you download and move its contents to the schematics folder in ~/plugins/BetterStructures/schematics . You should be able to do /betterstructures reload in order to get it running! - -c) Advanced users - -1) Debugging - -BetterStructures has two main commands and one optional permission which help with debugging. - -1.1) Commands - -The only commands on BetterStructures are /betterstructures reload (or /bs reload) and /betterstructures place (or /bs place ). - -Reloading allows you to add or remove structures after modifying the files in the schematic folder, or apply generator edits to the generators folder. - -Placing allows you to see how a build gets placed in the world. This can be useful to see how well it fits, if it has any specific issues and to test chest loot or mob spawning, among other things. - -1.2) Permissions - -Currently, there is only one permission in BetterStructures - betterstructures.warn . This permission is made for admins and notifies admins when a build gets placed by the plugin. Admins can click on this notification to teleport to the build. This is the best way of testing generator settings and build placement. - -2) Customizing content - -Everything distributed in BetterStructures is editable. You are able to modify any schematic files and generator settings to your liking. - -Before you edit content, it is important you understand how the plugin fundamentally works. - -BetterStructures fundamentally has three types of files: schematic files, schematic configuration files and generator files. - -Schematic files contain the blocks in a build (you can think of it as containing the entire build) and are generated by WorldEdit using their schematic system. - -Schematic configuration files contain the configuration settings for the build. This determines basic things about the build such as whether the build is enabled (if it will be used), the build's weight (how frequently it will appear) and the generator it uses. More on that later. - -Generators contain advanced settings about where the build should spawn. This is where you set if you want the build to be placed in the air or underground or on liquids (like oceans) or on the surface of the world, what kind of biome, lists of valid worlds, world types (nether / end...) and so on. Generators also have the settings for the chest loot that gets randomized. More on these later. - -Pro-tip: The reason generators contain all of this advanced data is because you can use the same generator for several builds, and this is recommended. It is very easy to create a few generators for hundreds or even thousands of builds. - +Don't forget to download or make build packages! +You can download them in the following locations: +https://magmaguy.itch.io/ +https://www.patreon.com/magmaguy \ No newline at end of file