From a3acb6379a16beb0b812090a792c72148e8ca5cb Mon Sep 17 00:00:00 2001 From: MagmaGuy Date: Sun, 10 Jul 2022 06:19:47 +0100 Subject: [PATCH 01/39] Create LICENSE --- LICENSE | 674 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 674 insertions(+) create mode 100644 LICENSE 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 +. From 51ec126956296f4139971cf5130a1e19bb6e95a4 Mon Sep 17 00:00:00 2001 From: BuildTools Date: Thu, 21 Jul 2022 21:30:39 +0100 Subject: [PATCH 02/39] Version 1.1.0 - [New] Changed the randomization system to allow admins to customize build frequency per scanner, that option is now available in the config.yml configuration file - [New] Changed the debug teleport message to run a built-in command for teleportation, avoiding conflicts with other plugins - [New] Added a warning message informing admins when their betterstructures version is outdated --- .../betterstructures/BetterStructures.java | 3 + .../buildingfitter/FitAnything.java | 2 +- .../commands/CommandHandler.java | 24 +++- .../config/DefaultConfig.java | 35 ++++++ .../listeners/NewChunkLoadEvent.java | 33 ++++-- .../betterstructures/util/InfoMessage.java | 9 ++ .../betterstructures/util/VersionChecker.java | 105 ++++++++++++++++++ 7 files changed, 199 insertions(+), 12 deletions(-) create mode 100644 src/main/java/com/magmaguy/betterstructures/util/InfoMessage.java create mode 100644 src/main/java/com/magmaguy/betterstructures/util/VersionChecker.java diff --git a/src/main/java/com/magmaguy/betterstructures/BetterStructures.java b/src/main/java/com/magmaguy/betterstructures/BetterStructures.java index 6b61ada..df50934 100644 --- a/src/main/java/com/magmaguy/betterstructures/BetterStructures.java +++ b/src/main/java/com/magmaguy/betterstructures/BetterStructures.java @@ -7,6 +7,7 @@ import com.magmaguy.betterstructures.config.schematics.SchematicConfig; import com.magmaguy.betterstructures.listeners.NewChunkLoadEvent; import com.magmaguy.betterstructures.schematics.SchematicContainer; +import com.magmaguy.betterstructures.util.VersionChecker; import org.bukkit.Bukkit; import org.bukkit.plugin.java.JavaPlugin; @@ -21,6 +22,7 @@ public void onEnable() { Bukkit.getLogger().info("[BetterStructures] Initialized!"); 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) { @@ -31,6 +33,7 @@ public void onEnable() { new GeneratorConfig(); new SchematicConfig(); new CommandHandler(); + VersionChecker.checkPluginVersion(); } @Override diff --git a/src/main/java/com/magmaguy/betterstructures/buildingfitter/FitAnything.java b/src/main/java/com/magmaguy/betterstructures/buildingfitter/FitAnything.java index e9ab678..4e6f4b9 100644 --- a/src/main/java/com/magmaguy/betterstructures/buildingfitter/FitAnything.java +++ b/src/main/java/com/magmaguy/betterstructures/buildingfitter/FitAnything.java @@ -151,7 +151,7 @@ public void run() { 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()) + "/betterstructures teleporttocoords " + location.getWorld().getName() + " " + location.getBlockX() + " " + location.getBlockY() + " " + location.getBlockZ()) ); } for (BlockVector3 blockVector3 : barrierBlocks) { diff --git a/src/main/java/com/magmaguy/betterstructures/commands/CommandHandler.java b/src/main/java/com/magmaguy/betterstructures/commands/CommandHandler.java index fa3d4ca..f1ec35e 100644 --- a/src/main/java/com/magmaguy/betterstructures/commands/CommandHandler.java +++ b/src/main/java/com/magmaguy/betterstructures/commands/CommandHandler.java @@ -11,7 +11,6 @@ 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.generators.GeneratorConfigFields; import com.magmaguy.betterstructures.schematics.SchematicContainer; @@ -19,6 +18,9 @@ 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; @@ -144,6 +146,26 @@ public void constructCommands() { .handler(commandContext -> { lootify(commandContext.get("generator"), commandContext.get("minAmount"), commandContext.get("maxAmount"), commandContext.get("chance"), (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!"); + } + }) + ); } private void placeSchematic(String schematicFile, String schematicType, Player player) { diff --git a/src/main/java/com/magmaguy/betterstructures/config/DefaultConfig.java b/src/main/java/com/magmaguy/betterstructures/config/DefaultConfig.java index b18665c..fec68b1 100644 --- a/src/main/java/com/magmaguy/betterstructures/config/DefaultConfig.java +++ b/src/main/java/com/magmaguy/betterstructures/config/DefaultConfig.java @@ -29,6 +29,28 @@ private DefaultConfig() { private static int endAirBuildMinAltitude; @Getter private static int endAirBuildMaxAltitude; + /* + @Getter + private static double airStructureRarityMultiplier; + @Getter + private static double surfaceStructureRarityMultiplier; + @Getter + private static double shallowUndergroundStructureRarityMultiplier; + @Getter + private static double deepUndergroundStructureRarityMultiplier; + @Getter + private static double liquidSurfaceStructureRarityMultiplier; + */ + @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; public static void initializeConfig() { @@ -44,6 +66,19 @@ public static void initializeConfig() { normalCustomAirBuildingMaxAltitude = ConfigurationEngine.setInt(fileConfiguration, "normalCustomAirBuildingMaxAltitude", 120); endAirBuildMinAltitude = ConfigurationEngine.setInt(fileConfiguration, "endAirBuildMinAltitude", 80); endAirBuildMaxAltitude = ConfigurationEngine.setInt(fileConfiguration, "endAirBuildMaxAltitude", 120); + /* + airStructureRarityMultiplier = ConfigurationEngine.setDouble(fileConfiguration, "airStructureRarityMultiplier", 1.5D); + surfaceStructureRarityMultiplier = ConfigurationEngine.setDouble(fileConfiguration, "surfaceStructureRarityMultiplier", .5D); + shallowUndergroundStructureRarityMultiplier = ConfigurationEngine.setDouble(fileConfiguration, "shallowUndergroundStructureRarityMultiplier", .5D); + deepUndergroundStructureRarityMultiplier = ConfigurationEngine.setDouble(fileConfiguration, "deepUndergroundStructureRarityMultiplier", .5D); + liquidSurfaceStructureRarityMultiplier = ConfigurationEngine.setDouble(fileConfiguration, "liquidSurfaceStructureRarityMultiplier", 11D); + */ + 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); + ConfigurationEngine.fileSaverOnlyDefaults(fileConfiguration, file); } } diff --git a/src/main/java/com/magmaguy/betterstructures/listeners/NewChunkLoadEvent.java b/src/main/java/com/magmaguy/betterstructures/listeners/NewChunkLoadEvent.java index 8b88568..572e2b6 100644 --- a/src/main/java/com/magmaguy/betterstructures/listeners/NewChunkLoadEvent.java +++ b/src/main/java/com/magmaguy/betterstructures/listeners/NewChunkLoadEvent.java @@ -6,10 +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; @@ -20,6 +20,7 @@ import java.util.HashSet; import java.util.Random; +import java.util.concurrent.ThreadLocalRandom; public class NewChunkLoadEvent implements Listener { @@ -46,12 +47,15 @@ public void run() { if (!ValidWorldsConfig.isValidWorld(event.getWorld())) return; Bukkit.getScheduler().runTaskAsynchronously(MetadataHandler.PLUGIN, bukkitTask -> { if (random == null) { + random = new Random(); + /* 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()); @@ -63,41 +67,50 @@ public void run() { private void surfaceScanner(Chunk chunk) { if (SchematicContainer.getSchematics().get(GeneratorConfigFields.StructureType.SURFACE).isEmpty()) return; - if (!seededSimplexRandomization(chunk, 0.95, surfaceOffset)) return; + //if (!seededSimplexRandomization(chunk, .99, surfaceOffset, DefaultConfig.getSurfaceStructureRarityMultiplier())) 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 (!seededSimplexRandomization(chunk, .99, shallowUndergroundOffset, DefaultConfig.getShallowUndergroundStructureRarityMultiplier())) 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 (!seededSimplexRandomization(chunk, .99, deepUndergroundOffset, DefaultConfig.getDeepUndergroundStructureRarityMultiplier())) 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 (!seededSimplexRandomization(chunk, .99, airOffset, DefaultConfig.getAirStructureRarityMultiplier())) 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 (!seededSimplexRandomization(chunk, .99, liquidOffset, DefaultConfig.getLiquidSurfaceStructureRarityMultiplier())) return; + 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); +/* this has issues when you try to integrate customization options + private boolean seededSimplexRandomization(Chunk chunk, double strictness, int offset, double rarityMultiplier) { + return (SimplexNoise.noise(rarityMultiplier * chunk.getX() + (double) offset, rarityMultiplier * chunk.getZ() + (double) offset) > strictness); } - + */ } 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..f14ce76 --- /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("[EliteMobs] " + message); + } +} 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..2bc7db9 --- /dev/null +++ b/src/main/java/com/magmaguy/betterstructures/util/VersionChecker.java @@ -0,0 +1,105 @@ +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); + } + + 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); + + } + } + +} From db302b3f266d4c890771c38966575225615b0e82 Mon Sep 17 00:00:00 2001 From: BuildTools Date: Sun, 7 Aug 2022 08:14:57 +0100 Subject: [PATCH 03/39] Version 1.2.0 - [New] Added more default underground generators for the exploration pack --- build.gradle | 2 +- .../GeneratorUndergroundDripstoneConfig.java | 15 +++++++++++++++ .../premade/GeneratorUndergroundLushConfig.java | 15 +++++++++++++++ src/main/resources/plugin.yml | 2 +- 4 files changed, 32 insertions(+), 2 deletions(-) create mode 100644 src/main/java/com/magmaguy/betterstructures/config/generators/premade/GeneratorUndergroundDripstoneConfig.java create mode 100644 src/main/java/com/magmaguy/betterstructures/config/generators/premade/GeneratorUndergroundLushConfig.java diff --git a/build.gradle b/build.gradle index cb93632..a7a7b4c 100644 --- a/build.gradle +++ b/build.gradle @@ -6,7 +6,7 @@ plugins { } group = 'com.magmaguy' -version = '1.1.0' +version = '1.2.0' repositories { mavenCentral() 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..e546fdb --- /dev/null +++ b/src/main/java/com/magmaguy/betterstructures/config/generators/premade/GeneratorUndergroundDripstoneConfig.java @@ -0,0 +1,15 @@ +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; + +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)); + setChestEntries(DefaultChestContents.overworldUndergroundContents()); + } +} 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..0a34c00 --- /dev/null +++ b/src/main/java/com/magmaguy/betterstructures/config/generators/premade/GeneratorUndergroundLushConfig.java @@ -0,0 +1,15 @@ +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; + +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)); + setChestEntries(DefaultChestContents.overworldUndergroundContents()); + } +} diff --git a/src/main/resources/plugin.yml b/src/main/resources/plugin.yml index 4634fbb..ad10109 100644 --- a/src/main/resources/plugin.yml +++ b/src/main/resources/plugin.yml @@ -1,5 +1,5 @@ name: BetterStructures -version: '1.1.0' +version: '1.2.0' main: com.magmaguy.betterstructures.BetterStructures api-version: 1.14 depend: [ WorldEdit ] From 3f706e375f1309b79c2f68544802406cee134db8 Mon Sep 17 00:00:00 2001 From: BuildTools Date: Mon, 15 Aug 2022 14:43:46 +0100 Subject: [PATCH 04/39] Version 1.3.0 - [New] Treasure in chests was remade! - Added the "chests" config folder - Added default treasure configs in the chests folder - Generators now refer to specific treasure files in the config folder instead of containing their own individual lists of treasure - The lootify command now also adds an "info" section with a human-readable value to help understand what item the entry is for - Configurations for schematics can override their generator's treasure config by setting the treasure file in the schematic's configuration - Lootify command now writes to the treasure configs - Lootify command should now fully work - [New] Ender crystals no longer show the bottom pedestal --- .../betterstructures/BetterStructures.java | 2 + .../buildingfitter/FitAnything.java | 8 ++-- .../chests/ChestContents.java | 9 ++-- .../commands/CommandHandler.java | 22 ++++++---- .../generators/GeneratorConfigFields.java | 39 ++++++++---------- .../premade/GeneratorLiquidNether.java | 2 +- .../premade/GeneratorLiquidOverworld.java | 2 +- .../premade/GeneratorSkyBarrenConfig.java | 2 +- .../GeneratorSkyCrimsonForestConfig.java | 2 +- .../premade/GeneratorSkyDesertConfig.java | 2 +- .../premade/GeneratorSkyEndConfig.java | 2 +- .../premade/GeneratorSkyGlobal.java | 2 +- .../premade/GeneratorSkyGrasslandConfig.java | 2 +- .../premade/GeneratorSkyNetherConfig.java | 2 +- .../GeneratorSkyNetherWastesConfig.java | 2 +- .../premade/GeneratorSkySnowyConfig.java | 2 +- .../premade/GeneratorSkySoulSandConfig.java | 2 +- .../GeneratorSkyWarpedForestConfig.java | 2 +- .../premade/GeneratorSurfaceBarrenConfig.java | 2 +- .../premade/GeneratorSurfaceDesertConfig.java | 2 +- .../premade/GeneratorSurfaceEndConfig.java | 2 +- .../premade/GeneratorSurfaceGlobalConfig.java | 2 +- .../GeneratorSurfaceGrasslandConfig.java | 2 +- .../premade/GeneratorSurfaceNetherConfig.java | 2 +- .../premade/GeneratorSurfaceSnowyConfig.java | 2 +- .../GeneratorUndergroundDeepConfig.java | 3 +- .../GeneratorUndergroundDripstoneConfig.java | 3 +- .../GeneratorUndergroundEndConfig.java | 2 +- .../GeneratorUndergroundLushConfig.java | 2 +- .../GeneratorUndergroundNetherConfig.java | 2 +- .../GeneratorUndergroundNetherDeep.java | 2 +- .../GeneratorUndergroundNetherShallow.java | 2 +- .../GeneratorUndergroundShallowConfig.java | 2 +- .../UndergroundGeneratorGlobalConfig.java | 2 +- .../config/treasures/TreasureConfig.java | 22 ++++++++++ .../treasures/TreasureConfigFields.java | 41 +++++++++++++++++++ .../treasures/premade/EndTreasureConfig.java | 11 +++++ .../premade/NetherTreasureConfig.java | 11 +++++ .../OverworldSurfaceTreasureConfig.java | 11 +++++ .../OverworldUndergroundTreasureConfig.java | 11 +++++ .../util/DefaultChestContents.java | 8 ++-- src/main/resources/plugin.yml | 2 +- 42 files changed, 186 insertions(+), 71 deletions(-) create mode 100644 src/main/java/com/magmaguy/betterstructures/config/treasures/TreasureConfig.java create mode 100644 src/main/java/com/magmaguy/betterstructures/config/treasures/TreasureConfigFields.java create mode 100644 src/main/java/com/magmaguy/betterstructures/config/treasures/premade/EndTreasureConfig.java create mode 100644 src/main/java/com/magmaguy/betterstructures/config/treasures/premade/NetherTreasureConfig.java create mode 100644 src/main/java/com/magmaguy/betterstructures/config/treasures/premade/OverworldSurfaceTreasureConfig.java create mode 100644 src/main/java/com/magmaguy/betterstructures/config/treasures/premade/OverworldUndergroundTreasureConfig.java diff --git a/src/main/java/com/magmaguy/betterstructures/BetterStructures.java b/src/main/java/com/magmaguy/betterstructures/BetterStructures.java index df50934..5e5a00b 100644 --- a/src/main/java/com/magmaguy/betterstructures/BetterStructures.java +++ b/src/main/java/com/magmaguy/betterstructures/BetterStructures.java @@ -5,6 +5,7 @@ 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.listeners.NewChunkLoadEvent; import com.magmaguy.betterstructures.schematics.SchematicContainer; import com.magmaguy.betterstructures.util.VersionChecker; @@ -30,6 +31,7 @@ public void onEnable() { } DefaultConfig.initializeConfig(); ValidWorldsConfig.initializeConfig(); + new TreasureConfig(); new GeneratorConfig(); new SchematicConfig(); new CommandHandler(); diff --git a/src/main/java/com/magmaguy/betterstructures/buildingfitter/FitAnything.java b/src/main/java/com/magmaguy/betterstructures/buildingfitter/FitAnything.java index 4e6f4b9..45a1301 100644 --- a/src/main/java/com/magmaguy/betterstructures/buildingfitter/FitAnything.java +++ b/src/main/java/com/magmaguy/betterstructures/buildingfitter/FitAnything.java @@ -22,9 +22,7 @@ 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.entity.*; import org.bukkit.scheduler.BukkitRunnable; import org.bukkit.util.Vector; @@ -285,6 +283,10 @@ private void spawnEntities() { if (entity instanceof LivingEntity) { ((LivingEntity) entity).setRemoveWhenFarAway(false); } + if (entity.getType().equals(EntityType.ENDER_CRYSTAL)){ + EnderCrystal enderCrystal = (EnderCrystal) entity; + enderCrystal.setShowingBottom(false); + } } } diff --git a/src/main/java/com/magmaguy/betterstructures/chests/ChestContents.java b/src/main/java/com/magmaguy/betterstructures/chests/ChestContents.java index 96c3e9a..8fc9ae7 100644 --- a/src/main/java/com/magmaguy/betterstructures/chests/ChestContents.java +++ b/src/main/java/com/magmaguy/betterstructures/chests/ChestContents.java @@ -4,9 +4,7 @@ import com.magmaguy.betterstructures.util.ItemStackSerialization; import com.magmaguy.betterstructures.util.WarningMessage; import lombok.Getter; -import org.bukkit.Bukkit; import org.bukkit.Material; -import org.bukkit.block.Chest; import org.bukkit.block.Container; import org.bukkit.inventory.ItemStack; @@ -22,6 +20,7 @@ public class ChestContents { Entry format: - material=MATERIAL:amount=AMOUNT_MIN-AMOUNT_MAX:chance=CHANCE */ public ChestContents(List rawContents, GeneratorConfigFields generatorConfigFields) { + if (rawContents == null) return; for (String string : rawContents) { String[] sections = string.split(":"); Material material = null; @@ -41,9 +40,10 @@ public ChestContents(List rawContents, GeneratorConfigFields generatorCo break; case "serialized": try { - itemStack = ItemStackSerialization.itemStackArrayFromBase64(subsection[1]); + itemStack = ItemStackSerialization.itemStackArrayFromBase64(section.replace("serialized=", "")); } catch (Exception ex) { new WarningMessage("Invalid serialized value detected for generator " + generatorConfigFields.getFilename() + " ! Problematic entry: " + subsection[0]); + ex.printStackTrace(); continue; } break; @@ -68,6 +68,9 @@ public ChestContents(List rawContents, GeneratorConfigFields generatorCo new WarningMessage("Invalid chance detected for generator " + generatorConfigFields.getFilename() + " ! Problematic entry: " + subsection[0]); } break; + case "info": + //This is purely visual, helps document serialized entries! + break; default: new WarningMessage("Failed to parse chest entry for generator " + generatorConfigFields.getFilename() + " ! Problematic entry: " + subsection[0]); } diff --git a/src/main/java/com/magmaguy/betterstructures/commands/CommandHandler.java b/src/main/java/com/magmaguy/betterstructures/commands/CommandHandler.java index f1ec35e..2216a1c 100644 --- a/src/main/java/com/magmaguy/betterstructures/commands/CommandHandler.java +++ b/src/main/java/com/magmaguy/betterstructures/commands/CommandHandler.java @@ -11,8 +11,9 @@ import cloud.commandframework.minecraft.extras.MinecraftHelp; import com.magmaguy.betterstructures.MetadataHandler; import com.magmaguy.betterstructures.buildingfitter.FitAnything; -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.schematics.SchematicContainer; import com.magmaguy.betterstructures.util.ItemStackSerialization; import com.magmaguy.betterstructures.util.WarningMessage; @@ -131,12 +132,12 @@ 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")) .meta(CommandMeta.DESCRIPTION, "Adds a held item to the loot settings of a generator") .argument(StringArgument.newBuilder("minAmount")) @@ -196,8 +197,8 @@ 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) { + TreasureConfigFields treasureConfigFields = TreasureConfig.getConfigFields(generator); + if (treasureConfigFields == null) { player.sendMessage("[BetterStructures] Not a valid generator! Try again."); return; } @@ -239,7 +240,14 @@ 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(); + String configString = "serialized=" + ItemStackSerialization.toBase64(itemStack) + ":amount=" + minAmount + "-" + maxAmount + ":chance=" + chance + ":info=" + info; + treasureConfigFields.addChestEntry(configString, player); } } 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..5edc1c4 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,18 @@ 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 + List chestEntries = null; @Getter private ChestContents chestContents = null; @@ -73,22 +76,14 @@ public void processConfigFields() { this.validWorlds = processWorldList("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); - } - - 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; + this.treasureFilename = processString("treasureFilename", treasureFilename, null, false); + TreasureConfigFields treasureConfig = TreasureConfig.getConfigFields(treasureFilename); + if (treasureConfig != null) { + this.chestEntries = treasureConfig.getRawLoot(); + chestContents = new ChestContents(chestEntries, this); } - MetadataHandler.PLUGIN.onDisable(); - MetadataHandler.PLUGIN.onLoad(); - MetadataHandler.PLUGIN.onEnable(); - player.sendMessage("[BetterStructures] Reloaded plugin to add chest entry! It should now be live."); + else new WarningMessage("No valid treasure config file found for generator " + filename + " ! This will not spawn loot in chests until fixed."); + } + } 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..8a98d6f 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 @@ -10,6 +10,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..8445a0e 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 @@ -10,6 +10,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..38c6ed9 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 @@ -16,6 +16,6 @@ public GeneratorSkyBarrenConfig(){ Biome.WINDSWEPT_SAVANNA, Biome.MUSHROOM_FIELDS )); - 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..5337c0f 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 @@ -10,6 +10,6 @@ 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()); + 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..bdb1782 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 @@ -12,6 +12,6 @@ public GeneratorSkyDesertConfig(){ setValidBiomes(Arrays.asList( Biome.DESERT )); - 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..271eb7c 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 @@ -10,6 +10,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..6ce7af4 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 @@ -8,6 +8,6 @@ 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..b4a54a9 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 @@ -25,6 +25,6 @@ public GeneratorSkyGrasslandConfig(){ Biome.WINDSWEPT_FOREST, Biome.WINDSWEPT_HILLS )); - 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..0654190 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 @@ -10,6 +10,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..40c9b88 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 @@ -10,6 +10,6 @@ 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()); + 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..6a21e09 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 @@ -16,6 +16,6 @@ public GeneratorSkySnowyConfig(){ Biome.SNOWY_SLOPES, Biome.ICE_SPIKES )); - 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..18b7f1f 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 @@ -10,6 +10,6 @@ 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()); + 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..ce05af3 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 @@ -10,6 +10,6 @@ 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()); + 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..cad1d40 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 @@ -16,6 +16,6 @@ public GeneratorSurfaceBarrenConfig(){ Biome.WINDSWEPT_SAVANNA, Biome.MUSHROOM_FIELDS )); - 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..1b37eef 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 @@ -12,6 +12,6 @@ public GeneratorSurfaceDesertConfig() { setValidBiomes(Arrays.asList( Biome.DESERT )); - 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..0b18b72 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 @@ -10,6 +10,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_nether.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..7649027 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 @@ -10,6 +10,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..3e600c2 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 @@ -25,6 +25,6 @@ public GeneratorSurfaceGrasslandConfig(){ Biome.WINDSWEPT_FOREST, Biome.WINDSWEPT_HILLS )); - 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..64ba83a 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 @@ -10,6 +10,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..6213912 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 @@ -16,6 +16,6 @@ public GeneratorSurfaceSnowyConfig() { Biome.SNOWY_SLOPES, Biome.ICE_SPIKES )); - 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..de101a9 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 @@ -9,7 +9,6 @@ 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 index e546fdb..e29cce1 100644 --- a/src/main/java/com/magmaguy/betterstructures/config/generators/premade/GeneratorUndergroundDripstoneConfig.java +++ b/src/main/java/com/magmaguy/betterstructures/config/generators/premade/GeneratorUndergroundDripstoneConfig.java @@ -9,7 +9,6 @@ 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)); - setChestEntries(DefaultChestContents.overworldUndergroundContents()); + 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..f846553 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 @@ -10,6 +10,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 index 0a34c00..5a65e17 100644 --- a/src/main/java/com/magmaguy/betterstructures/config/generators/premade/GeneratorUndergroundLushConfig.java +++ b/src/main/java/com/magmaguy/betterstructures/config/generators/premade/GeneratorUndergroundLushConfig.java @@ -10,6 +10,6 @@ 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)); - setChestEntries(DefaultChestContents.overworldUndergroundContents()); + 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..931b870 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 @@ -10,6 +10,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..13bef16 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 @@ -10,6 +10,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..80c4140 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 @@ -10,6 +10,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..3ccffe1 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 @@ -10,7 +10,7 @@ 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..6e5c8af 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 @@ -10,6 +10,6 @@ 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/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..aed19c0 --- /dev/null +++ b/src/main/java/com/magmaguy/betterstructures/config/treasures/TreasureConfigFields.java @@ -0,0 +1,41 @@ +package com.magmaguy.betterstructures.config.treasures; + +import com.magmaguy.betterstructures.MetadataHandler; +import com.magmaguy.betterstructures.config.CustomConfigFields; +import lombok.Getter; +import lombok.Setter; +import org.bukkit.entity.Player; + +import java.util.List; + +public class TreasureConfigFields extends CustomConfigFields { + + @Getter + @Setter + private List rawLoot = null; + + public TreasureConfigFields(String filename, boolean isEnabled) { + super(filename, isEnabled); + } + + @Override + public void processConfigFields() { + this.isEnabled = processBoolean("isEnabled", isEnabled, true, true); + this.rawLoot = processStringList("loot", rawLoot, null, true); + } + + public void addChestEntry(String entry, Player player) { + rawLoot.add(entry); + fileConfiguration.set("loot", rawLoot); + 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/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/util/DefaultChestContents.java b/src/main/java/com/magmaguy/betterstructures/util/DefaultChestContents.java index 1db84c4..3088d09 100644 --- a/src/main/java/com/magmaguy/betterstructures/util/DefaultChestContents.java +++ b/src/main/java/com/magmaguy/betterstructures/util/DefaultChestContents.java @@ -6,9 +6,9 @@ import java.util.List; public class DefaultChestContents { - private static double normalChance = 0.02; - private static double lowChance = 0.01; - private static double extraRare = 0.002; + public static double normalChance = 0.02; + public static double lowChance = 0.01; + public static double extraRare = 0.002; public static List overworldContents() { List list = new ArrayList<>(); @@ -237,7 +237,7 @@ public static List endContents() { } - private static String generateEntry(Material material, int minAmount, int maxAmount, double chance) { + public static String generateEntry(Material material, int minAmount, int maxAmount, double chance) { return "material=" + material.toString() + ":amount=" + minAmount + "-" + maxAmount + ":chance=" + chance; } } diff --git a/src/main/resources/plugin.yml b/src/main/resources/plugin.yml index ad10109..4815138 100644 --- a/src/main/resources/plugin.yml +++ b/src/main/resources/plugin.yml @@ -1,5 +1,5 @@ name: BetterStructures -version: '1.2.0' +version: '1.3.0' main: com.magmaguy.betterstructures.BetterStructures api-version: 1.14 depend: [ WorldEdit ] From 0a1f2c08a2c73520242dcd0fc1aaf14c2a4d8689 Mon Sep 17 00:00:00 2001 From: BuildTools Date: Mon, 15 Aug 2022 17:11:31 +0100 Subject: [PATCH 05/39] Version 1.3.1 - [Fix] Hotfix for errors in 1.3.1 related to some config changes, apologies for the inconvenience --- build.gradle | 2 +- .../betterstructures/schematics/SchematicContainer.java | 8 ++++++-- src/main/resources/plugin.yml | 2 +- 3 files changed, 8 insertions(+), 4 deletions(-) diff --git a/build.gradle b/build.gradle index a7a7b4c..c4c4de5 100644 --- a/build.gradle +++ b/build.gradle @@ -6,7 +6,7 @@ plugins { } group = 'com.magmaguy' -version = '1.2.0' +version = '1.3.1' repositories { mavenCentral() diff --git a/src/main/java/com/magmaguy/betterstructures/schematics/SchematicContainer.java b/src/main/java/com/magmaguy/betterstructures/schematics/SchematicContainer.java index f6c710a..b748df4 100644 --- a/src/main/java/com/magmaguy/betterstructures/schematics/SchematicContainer.java +++ b/src/main/java/com/magmaguy/betterstructures/schematics/SchematicContainer.java @@ -108,11 +108,15 @@ public SchematicContainer(Clipboard clipboard, String clipboardFilename, Schemat } 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) { diff --git a/src/main/resources/plugin.yml b/src/main/resources/plugin.yml index 4815138..93afc02 100644 --- a/src/main/resources/plugin.yml +++ b/src/main/resources/plugin.yml @@ -1,5 +1,5 @@ name: BetterStructures -version: '1.3.0' +version: '1.3.1' main: com.magmaguy.betterstructures.BetterStructures api-version: 1.14 depend: [ WorldEdit ] From d21daeff91285a4db1decc323f7bd131aa3c1c7a Mon Sep 17 00:00:00 2001 From: BuildTools Date: Tue, 16 Aug 2022 18:40:05 +0100 Subject: [PATCH 06/39] Version 1.3.2 - [New] Added the following API events: - BuildPlaceEvent : called once the location of a build has been decided, but before it gets pasted. Cancellable. - ChestFillEvent : called once the loot of a chest has been decided, but before it gets placed. Cancellable. - [New] Added the treasure_special treasure file for high value dungeons, currently empty - [New] Schematic configs can now correctly hold their own configurations for treasure - [Refactor] Converted system internals to work better with the new treasure file-based loot system --- build.gradle | 2 +- .../betterstructures/api/BuildPlaceEvent.java | 43 +++++++++++++++++ .../betterstructures/api/ChestFillEvent.java | 48 +++++++++++++++++++ .../buildingfitter/FitAnything.java | 33 ++++++++++--- .../chests/ChestContents.java | 37 +++++++++----- .../generators/GeneratorConfigFields.java | 11 ++--- .../schematics/SchematicConfigField.java | 24 ++++++++++ .../treasures/TreasureConfigFields.java | 5 ++ .../premade/SpecialTreasureConfig.java | 9 ++++ .../schematics/SchematicContainer.java | 15 ++++++ src/main/resources/plugin.yml | 2 +- 11 files changed, 201 insertions(+), 28 deletions(-) create mode 100644 src/main/java/com/magmaguy/betterstructures/api/BuildPlaceEvent.java create mode 100644 src/main/java/com/magmaguy/betterstructures/api/ChestFillEvent.java create mode 100644 src/main/java/com/magmaguy/betterstructures/config/treasures/premade/SpecialTreasureConfig.java diff --git a/build.gradle b/build.gradle index c4c4de5..0b3fd65 100644 --- a/build.gradle +++ b/build.gradle @@ -6,7 +6,7 @@ plugins { } group = 'com.magmaguy' -version = '1.3.1' +version = '1.3.2' repositories { mavenCentral() 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..bf902a5 --- /dev/null +++ b/src/main/java/com/magmaguy/betterstructures/api/BuildPlaceEvent.java @@ -0,0 +1,43 @@ +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; + } + +} 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..e041739 --- /dev/null +++ b/src/main/java/com/magmaguy/betterstructures/api/ChestFillEvent.java @@ -0,0 +1,48 @@ +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; + } + +} diff --git a/src/main/java/com/magmaguy/betterstructures/buildingfitter/FitAnything.java b/src/main/java/com/magmaguy/betterstructures/buildingfitter/FitAnything.java index 45a1301..0386bf6 100644 --- a/src/main/java/com/magmaguy/betterstructures/buildingfitter/FitAnything.java +++ b/src/main/java/com/magmaguy/betterstructures/buildingfitter/FitAnything.java @@ -1,6 +1,8 @@ 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; @@ -15,6 +17,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; @@ -31,6 +34,7 @@ import java.util.Set; public class FitAnything { + @Getter protected SchematicContainer schematicContainer; protected final double startingScore = 100; protected final int searchRadius = 1; @@ -39,6 +43,7 @@ public class FitAnything { 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; public static void commandBasedCreation(Chunk chunk, GeneratorConfigFields.StructureType structureType, SchematicContainer container) { @@ -71,6 +76,9 @@ protected void setSchematicFilename(Location location, GeneratorConfigFields.Str protected void paste(Location location) { + BuildPlaceEvent buildPlaceEvent = new BuildPlaceEvent(this); + if (buildPlaceEvent.isCancelled()) return; + FitAnything fitAnything = this; new BukkitRunnable() { @Override @@ -149,7 +157,7 @@ public void run() { player.spigot().sendMessage( SpigotMessage.commandHoverMessage("[BetterStructures] New building generated! Click to teleport.", "Click to teleport to " + location.toString(), - "/betterstructures teleporttocoords " + location.getWorld().getName() + " " + location.getBlockX() + " " + location.getBlockY() + " " + location.getBlockZ()) + "/betterstructures teleporttocoords " + location.getWorld().getName() + " " + location.getBlockX() + " " + location.getBlockY() + " " + location.getBlockZ()) ); } for (BlockVector3 blockVector3 : barrierBlocks) { @@ -266,10 +274,21 @@ 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); + Container container = (Container) chestLocation.getBlock().getState(); + + 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() { @@ -277,13 +296,13 @@ 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.clone().add(new Vector(0.5, 0, 0.5)); Entity entity = signLocation.getWorld().spawnEntity(signLocation, schematicContainer.getVanillaSpawns().get(entityPosition)); entity.setPersistent(true); if (entity instanceof LivingEntity) { ((LivingEntity) entity).setRemoveWhenFarAway(false); } - if (entity.getType().equals(EntityType.ENDER_CRYSTAL)){ + if (entity.getType().equals(EntityType.ENDER_CRYSTAL)) { EnderCrystal enderCrystal = (EnderCrystal) entity; enderCrystal.setShowingBottom(false); } diff --git a/src/main/java/com/magmaguy/betterstructures/chests/ChestContents.java b/src/main/java/com/magmaguy/betterstructures/chests/ChestContents.java index 8fc9ae7..76f31d4 100644 --- a/src/main/java/com/magmaguy/betterstructures/chests/ChestContents.java +++ b/src/main/java/com/magmaguy/betterstructures/chests/ChestContents.java @@ -1,13 +1,15 @@ 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 lombok.Getter; +import org.bukkit.Bukkit; import org.bukkit.Material; import org.bukkit.block.Container; import org.bukkit.inventory.ItemStack; +import java.nio.Buffer; import java.util.ArrayList; import java.util.List; @@ -19,9 +21,15 @@ public class ChestContents { /* Entry format: - material=MATERIAL:amount=AMOUNT_MIN-AMOUNT_MAX:chance=CHANCE */ - public ChestContents(List rawContents, GeneratorConfigFields generatorConfigFields) { - if (rawContents == null) return; - for (String string : rawContents) { + public ChestContents(TreasureConfigFields treasureConfigFields) { + if (treasureConfigFields.getRawLoot() == null) return; + if (!processEntries(treasureConfigFields.getRawLoot())) + new WarningMessage("Treasure file " + treasureConfigFields.getFilename() + " has invalid treasure entries!"); + } + + private boolean processEntries(List rawChestEntries) { + boolean noProblems = true; + for (String string : rawChestEntries) { String[] sections = string.split(":"); Material material = null; ItemStack itemStack = null; @@ -35,16 +43,17 @@ public ChestContents(List rawContents, GeneratorConfigFields generatorCo try { material = Material.getMaterial(subsection[1]); } catch (Exception exception) { - new WarningMessage("Invalid material detected for generator " + generatorConfigFields.getFilename() + " ! Problematic entry: " + subsection[0]); + new WarningMessage("Invalid material detected! Problematic entry: " + subsection[0]); + noProblems = false; } break; case "serialized": try { itemStack = ItemStackSerialization.itemStackArrayFromBase64(section.replace("serialized=", "")); } catch (Exception ex) { - new WarningMessage("Invalid serialized value detected for generator " + generatorConfigFields.getFilename() + " ! Problematic entry: " + subsection[0]); + new WarningMessage("Invalid serialized value detected! Problematic entry: " + subsection[0]); ex.printStackTrace(); - continue; + noProblems = false; } break; case "amount": @@ -58,21 +67,25 @@ public ChestContents(List rawContents, GeneratorConfigFields generatorCo amountMax = amountMin; } } catch (Exception exception) { - new WarningMessage("Invalid amount detected for generator " + generatorConfigFields.getFilename() + " ! Problematic entry: " + subsection[0]); + new WarningMessage("Invalid amount detected! Problematic entry: " + subsection[0]); + noProblems = false; } 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]); + new WarningMessage("Invalid chance detected! Problematic entry: " + subsection[0]); + noProblems = false; } break; case "info": //This is purely visual, helps document serialized entries! break; - default: - new WarningMessage("Failed to parse chest entry for generator " + generatorConfigFields.getFilename() + " ! Problematic entry: " + subsection[0]); + default: { + new WarningMessage("Failed to parse chest entry! Problematic entry: " + subsection[0]); + noProblems = false; + } } } @@ -81,6 +94,7 @@ public ChestContents(List rawContents, GeneratorConfigFields generatorCo chestEntries.add(chestEntry); } } + return noProblems; } public void rollChestContents(Container chest) { @@ -88,7 +102,6 @@ public void rollChestContents(Container chest) { ItemStack itemStack = chestEntry.rollEntry(); if (itemStack == null) continue; chest.getSnapshotInventory().addItem(itemStack); - chest.update(true); } } } 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 5edc1c4..9b14d8d 100644 --- a/src/main/java/com/magmaguy/betterstructures/config/generators/GeneratorConfigFields.java +++ b/src/main/java/com/magmaguy/betterstructures/config/generators/GeneratorConfigFields.java @@ -47,8 +47,6 @@ public enum StructureType { @Setter private String treasureFilename = null; @Getter - List chestEntries = null; - @Getter private ChestContents chestContents = null; @@ -78,11 +76,10 @@ public void processConfigFields() { this.validBiomes = processEnumList("validBiomes", validBiomes, new ArrayList<>(), Biome.class, false); this.treasureFilename = processString("treasureFilename", treasureFilename, null, false); TreasureConfigFields treasureConfig = TreasureConfig.getConfigFields(treasureFilename); - if (treasureConfig != null) { - this.chestEntries = treasureConfig.getRawLoot(); - chestContents = new ChestContents(chestEntries, this); - } - else new WarningMessage("No valid treasure config file found for generator " + filename + " ! This will not spawn loot in chests until fixed."); + 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."); } 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..47b0e4b 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; /** @@ -41,5 +51,19 @@ public void processConfigFields() { this.pedestalMaterial = processEnum("pedestalMaterial", pedestalMaterial, null, Material.class, false); this.generatorConfigFilename = processString("generatorConfigFilename", generatorConfigFilename, null, 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."); + 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/TreasureConfigFields.java b/src/main/java/com/magmaguy/betterstructures/config/treasures/TreasureConfigFields.java index aed19c0..08ee0de 100644 --- a/src/main/java/com/magmaguy/betterstructures/config/treasures/TreasureConfigFields.java +++ b/src/main/java/com/magmaguy/betterstructures/config/treasures/TreasureConfigFields.java @@ -1,6 +1,7 @@ package com.magmaguy.betterstructures.config.treasures; import com.magmaguy.betterstructures.MetadataHandler; +import com.magmaguy.betterstructures.chests.ChestContents; import com.magmaguy.betterstructures.config.CustomConfigFields; import lombok.Getter; import lombok.Setter; @@ -13,6 +14,9 @@ public class TreasureConfigFields extends CustomConfigFields { @Getter @Setter private List rawLoot = null; + @Getter + @Setter + private ChestContents chestContents = null; public TreasureConfigFields(String filename, boolean isEnabled) { super(filename, isEnabled); @@ -22,6 +26,7 @@ public TreasureConfigFields(String filename, boolean isEnabled) { public void processConfigFields() { this.isEnabled = processBoolean("isEnabled", isEnabled, true, true); this.rawLoot = processStringList("loot", rawLoot, null, true); + chestContents = new ChestContents(this); } public void addChestEntry(String entry, Player player) { 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/schematics/SchematicContainer.java b/src/main/java/com/magmaguy/betterstructures/schematics/SchematicContainer.java index b748df4..4bdd2ca 100644 --- a/src/main/java/com/magmaguy/betterstructures/schematics/SchematicContainer.java +++ b/src/main/java/com/magmaguy/betterstructures/schematics/SchematicContainer.java @@ -1,8 +1,11 @@ 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.sk89q.worldedit.bukkit.BukkitAdapter; import com.sk89q.worldedit.extent.clipboard.Clipboard; @@ -42,6 +45,8 @@ public static void shutdown() { private final List chestLocations = new ArrayList<>(); @Getter private final HashMap vanillaSpawns = new HashMap<>(); + @Getter + private ChestContents chestContents = null; public SchematicContainer(Clipboard clipboard, String clipboardFilename, SchematicConfigField schematicConfigField, String configFilename) { this.clipboard = clipboard; @@ -55,6 +60,7 @@ public SchematicContainer(Clipboard clipboard, String clipboardFilename, Schemat 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++) @@ -105,6 +111,15 @@ public SchematicContainer(Clipboard clipboard, String clipboardFilename, Schemat } } } + 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(); + } } public boolean isValidEnvironment(World.Environment environment) { diff --git a/src/main/resources/plugin.yml b/src/main/resources/plugin.yml index 93afc02..add4a22 100644 --- a/src/main/resources/plugin.yml +++ b/src/main/resources/plugin.yml @@ -1,5 +1,5 @@ name: BetterStructures -version: '1.3.1' +version: '1.3.2' main: com.magmaguy.betterstructures.BetterStructures api-version: 1.14 depend: [ WorldEdit ] From bd28dd2b450fd860a5e5650479f76807f0da77fe Mon Sep 17 00:00:00 2001 From: BuildTools Date: Sat, 20 Aug 2022 07:17:36 +0100 Subject: [PATCH 07/39] Version 1.3.3 - [New] Added the /betterstructures version command with the permission betterstructures.version - [Fix] Fixed issue where by default the surface end generator was using the nether loot table --- build.gradle | 2 +- .../buildingfitter/FitAnything.java | 1 + .../buildingfitter/util/TerrainAdequacy.java | 2 ++ .../commands/CommandHandler.java | 11 ++++++ .../premade/GeneratorSurfaceEndConfig.java | 2 +- .../util/ChunkLocationChecker.java | 34 +++++++++++++++++++ src/main/resources/plugin.yml | 2 +- 7 files changed, 51 insertions(+), 3 deletions(-) create mode 100644 src/main/java/com/magmaguy/betterstructures/util/ChunkLocationChecker.java diff --git a/build.gradle b/build.gradle index 0b3fd65..26b8bbd 100644 --- a/build.gradle +++ b/build.gradle @@ -6,7 +6,7 @@ plugins { } group = 'com.magmaguy' -version = '1.3.2' +version = '1.3.3' repositories { mavenCentral() diff --git a/src/main/java/com/magmaguy/betterstructures/buildingfitter/FitAnything.java b/src/main/java/com/magmaguy/betterstructures/buildingfitter/FitAnything.java index 0386bf6..bc09bb5 100644 --- a/src/main/java/com/magmaguy/betterstructures/buildingfitter/FitAnything.java +++ b/src/main/java/com/magmaguy/betterstructures/buildingfitter/FitAnything.java @@ -8,6 +8,7 @@ import com.magmaguy.betterstructures.buildingfitter.util.SchematicPicker; import com.magmaguy.betterstructures.config.generators.GeneratorConfigFields; import com.magmaguy.betterstructures.schematics.SchematicContainer; +import com.magmaguy.betterstructures.util.ChunkLocationChecker; import com.magmaguy.betterstructures.util.SpigotMessage; import com.magmaguy.betterstructures.util.SurfaceMaterials; import com.magmaguy.betterstructures.util.WarningMessage; diff --git a/src/main/java/com/magmaguy/betterstructures/buildingfitter/util/TerrainAdequacy.java b/src/main/java/com/magmaguy/betterstructures/buildingfitter/util/TerrainAdequacy.java index 68d4f58..4294c9c 100644 --- a/src/main/java/com/magmaguy/betterstructures/buildingfitter/util/TerrainAdequacy.java +++ b/src/main/java/com/magmaguy/betterstructures/buildingfitter/util/TerrainAdequacy.java @@ -1,9 +1,11 @@ package com.magmaguy.betterstructures.buildingfitter.util; +import com.magmaguy.betterstructures.util.ChunkLocationChecker; import com.magmaguy.betterstructures.util.SurfaceMaterials; import com.sk89q.worldedit.bukkit.BukkitAdapter; import com.sk89q.worldedit.extent.clipboard.Clipboard; import com.sk89q.worldedit.math.BlockVector3; +import org.bukkit.Bukkit; import org.bukkit.Location; import org.bukkit.Material; import org.bukkit.util.Vector; diff --git a/src/main/java/com/magmaguy/betterstructures/commands/CommandHandler.java b/src/main/java/com/magmaguy/betterstructures/commands/CommandHandler.java index 2216a1c..79b6339 100644 --- a/src/main/java/com/magmaguy/betterstructures/commands/CommandHandler.java +++ b/src/main/java/com/magmaguy/betterstructures/commands/CommandHandler.java @@ -15,6 +15,7 @@ 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; @@ -167,6 +168,16 @@ public void constructCommands() { } }) ); + // /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())))); } private void placeSchematic(String schematicFile, String schematicType, Player player) { 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 0b18b72..c8dc6d1 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 @@ -10,6 +10,6 @@ public class GeneratorSurfaceEndConfig extends GeneratorConfigFields { public GeneratorSurfaceEndConfig() { super("generator_surface_end", true, Arrays.asList(StructureType.SURFACE)); setValidWorldEnvironments(Arrays.asList(World.Environment.THE_END)); - setTreasureFilename("treasure_nether.yml"); + setTreasureFilename("treasure_end.yml"); } } 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..6e23541 --- /dev/null +++ b/src/main/java/com/magmaguy/betterstructures/util/ChunkLocationChecker.java @@ -0,0 +1,34 @@ +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) { + if (!chunk.getWorld().equals(location.getWorld())) return false; + double chunkX = chunk.getX() * 16; + double locationX = location.getX(); + double chunkZ = chunk.getZ() * 16; + double locationZ = location.getZ(); + if (!(chunkX <= locationX && chunkX + 16 >= locationX)) + return false; + + return chunkZ <= locationZ && chunkZ + 16 >= locationZ; + } + + /* + Checks if a given location is loaded + */ + public static boolean locationIsLoaded(Location location) { + return location != null && location.getWorld() != null && + location.getWorld().isChunkLoaded(location.getBlock().getX() >> 4, location.getBlock().getZ() >> 4); + } + +} + diff --git a/src/main/resources/plugin.yml b/src/main/resources/plugin.yml index add4a22..c30a5d7 100644 --- a/src/main/resources/plugin.yml +++ b/src/main/resources/plugin.yml @@ -1,5 +1,5 @@ name: BetterStructures -version: '1.3.2' +version: '1.3.3' main: com.magmaguy.betterstructures.BetterStructures api-version: 1.14 depend: [ WorldEdit ] From 926d12ac09af5c78be519cadd63ca8d00d28d9ac Mon Sep 17 00:00:00 2001 From: mastermc05 <63639746+mastermc05@users.noreply.github.com> Date: Sat, 20 Aug 2022 17:56:18 +0300 Subject: [PATCH 08/39] Improve ChunkLocationChecker 1. reduced calculations to check chunk 2. reduced CraftBlock alocations 3. removed posibility of NPE you can just copy paste this into your next release if you want, just some advices --- .../util/ChunkLocationChecker.java | 15 ++++----------- 1 file changed, 4 insertions(+), 11 deletions(-) diff --git a/src/main/java/com/magmaguy/betterstructures/util/ChunkLocationChecker.java b/src/main/java/com/magmaguy/betterstructures/util/ChunkLocationChecker.java index 6e23541..4ef35fc 100644 --- a/src/main/java/com/magmaguy/betterstructures/util/ChunkLocationChecker.java +++ b/src/main/java/com/magmaguy/betterstructures/util/ChunkLocationChecker.java @@ -11,15 +11,9 @@ private ChunkLocationChecker() { Checks if a location is in a given chunk */ public static boolean chunkLocationCheck(Location location, Chunk chunk) { - if (!chunk.getWorld().equals(location.getWorld())) return false; - double chunkX = chunk.getX() * 16; - double locationX = location.getX(); - double chunkZ = chunk.getZ() * 16; - double locationZ = location.getZ(); - if (!(chunkX <= locationX && chunkX + 16 >= locationX)) - return false; - - return chunkZ <= locationZ && chunkZ + 16 >= locationZ; + return chunk.getWorld().equals(location.getWorld()) //location.getWorld() can return null + && chunk.getX() == location.getBlockX() >> 4 + && chunk.getZ() == location.getBlockZ() >> 4; } /* @@ -27,8 +21,7 @@ public static boolean chunkLocationCheck(Location location, Chunk chunk) { */ public static boolean locationIsLoaded(Location location) { return location != null && location.getWorld() != null && - location.getWorld().isChunkLoaded(location.getBlock().getX() >> 4, location.getBlock().getZ() >> 4); + location.getWorld().isChunkLoaded(location.getBlockX() >> 4, location.getBlockZ() >> 4); } - } From 8702a9f75147611dab63edc33cdded270fa663a3 Mon Sep 17 00:00:00 2001 From: BuildTools Date: Tue, 30 Aug 2022 23:56:17 +0100 Subject: [PATCH 09/39] Version 1.3.3 - [Fix] Fixed API events, allowing other plugins to correctly modify place / chest fill behavior as needed - [Removal] Removed at best ineffective async implementation, will be replaced with a better pasting solution --- build.gradle | 2 +- .../betterstructures/api/BuildPlaceEvent.java | 4 + .../betterstructures/api/ChestFillEvent.java | 4 + .../buildingfitter/FitAnything.java | 217 +++++++++--------- .../listeners/NewChunkLoadEvent.java | 30 +-- src/main/resources/plugin.yml | 2 +- 6 files changed, 125 insertions(+), 134 deletions(-) diff --git a/build.gradle b/build.gradle index 26b8bbd..6795e85 100644 --- a/build.gradle +++ b/build.gradle @@ -6,7 +6,7 @@ plugins { } group = 'com.magmaguy' -version = '1.3.3' +version = '1.3.4' repositories { mavenCentral() diff --git a/src/main/java/com/magmaguy/betterstructures/api/BuildPlaceEvent.java b/src/main/java/com/magmaguy/betterstructures/api/BuildPlaceEvent.java index bf902a5..d6a2824 100644 --- a/src/main/java/com/magmaguy/betterstructures/api/BuildPlaceEvent.java +++ b/src/main/java/com/magmaguy/betterstructures/api/BuildPlaceEvent.java @@ -40,4 +40,8 @@ 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 index e041739..c47e6bb 100644 --- a/src/main/java/com/magmaguy/betterstructures/api/ChestFillEvent.java +++ b/src/main/java/com/magmaguy/betterstructures/api/ChestFillEvent.java @@ -45,4 +45,8 @@ public Container getContainer() { return container; } + public static HandlerList getHandlerList() { + return handlers; + } + } diff --git a/src/main/java/com/magmaguy/betterstructures/buildingfitter/FitAnything.java b/src/main/java/com/magmaguy/betterstructures/buildingfitter/FitAnything.java index bc09bb5..0f31fe0 100644 --- a/src/main/java/com/magmaguy/betterstructures/buildingfitter/FitAnything.java +++ b/src/main/java/com/magmaguy/betterstructures/buildingfitter/FitAnything.java @@ -1,6 +1,5 @@ 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; @@ -8,7 +7,6 @@ import com.magmaguy.betterstructures.buildingfitter.util.SchematicPicker; import com.magmaguy.betterstructures.config.generators.GeneratorConfigFields; import com.magmaguy.betterstructures.schematics.SchematicContainer; -import com.magmaguy.betterstructures.util.ChunkLocationChecker; import com.magmaguy.betterstructures.util.SpigotMessage; import com.magmaguy.betterstructures.util.SurfaceMaterials; import com.magmaguy.betterstructures.util.WarningMessage; @@ -27,7 +25,6 @@ import org.bukkit.block.Container; import org.bukkit.block.data.BlockData; import org.bukkit.entity.*; -import org.bukkit.scheduler.BukkitRunnable; import org.bukkit.util.Vector; import java.util.HashMap; @@ -79,128 +76,124 @@ protected void setSchematicFilename(Location location, GeneratorConfigFields.Str protected void paste(Location location) { BuildPlaceEvent buildPlaceEvent = new BuildPlaceEvent(this); if (buildPlaceEvent.isCancelled()) return; + Bukkit.getServer().getPluginManager().callEvent(buildPlaceEvent); 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(), - "/betterstructures teleporttocoords " + location.getWorld().getName() + " " + 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); - } - } - 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); - } + 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(), + "/betterstructures teleporttocoords " + location.getWorld().getName() + " " + location.getBlockX() + " " + location.getBlockY() + " " + location.getBlockZ()) + ); + } + 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); + } + } + + 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); + } } diff --git a/src/main/java/com/magmaguy/betterstructures/listeners/NewChunkLoadEvent.java b/src/main/java/com/magmaguy/betterstructures/listeners/NewChunkLoadEvent.java index 572e2b6..620cc6b 100644 --- a/src/main/java/com/magmaguy/betterstructures/listeners/NewChunkLoadEvent.java +++ b/src/main/java/com/magmaguy/betterstructures/listeners/NewChunkLoadEvent.java @@ -10,7 +10,6 @@ import com.magmaguy.betterstructures.config.ValidWorldsConfig; import com.magmaguy.betterstructures.config.generators.GeneratorConfigFields; import com.magmaguy.betterstructures.schematics.SchematicContainer; -import org.bukkit.Bukkit; import org.bukkit.Chunk; import org.bukkit.event.EventHandler; import org.bukkit.event.EventPriority; @@ -45,24 +44,15 @@ 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(); - /* - 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) { @@ -102,7 +92,7 @@ private void skyScanner(Chunk chunk) { private void liquidSurfaceScanner(Chunk chunk) { if (SchematicContainer.getSchematics().get(GeneratorConfigFields.StructureType.LIQUID_SURFACE).isEmpty()) return; - // if (!seededSimplexRandomization(chunk, .99, liquidOffset, DefaultConfig.getLiquidSurfaceStructureRarityMultiplier())) return; + // if (!seededSimplexRandomization(chunk, .99, liquidOffset, DefaultConfig.getLiquidSurfaceStructureRarityMultiplier())) return; if (ThreadLocalRandom.current().nextDouble() > DefaultConfig.getOceanStructuresPerThousandChunks() / 1000D) return; new FitLiquidBuilding(chunk); diff --git a/src/main/resources/plugin.yml b/src/main/resources/plugin.yml index c30a5d7..53ba2ce 100644 --- a/src/main/resources/plugin.yml +++ b/src/main/resources/plugin.yml @@ -1,5 +1,5 @@ name: BetterStructures -version: '1.3.3' +version: '1.3.4' main: com.magmaguy.betterstructures.BetterStructures api-version: 1.14 depend: [ WorldEdit ] From 38c6bc1e42466f4efdd87eb5779e8eb3e012a88b Mon Sep 17 00:00:00 2001 From: BuildTools Date: Thu, 8 Sep 2022 21:08:49 +0100 Subject: [PATCH 10/39] Version 1.3.5 - [New] Added maven repository for BetterStructures - [Fix] Fixed issue that seems to happen for some versions of FAWE and potentially WorldEdit --- build.gradle | 53 ++++++++++++++++++- .../schematics/SchematicContainer.java | 1 + src/main/resources/plugin.yml | 2 +- 3 files changed, 53 insertions(+), 3 deletions(-) diff --git a/build.gradle b/build.gradle index 6795e85..bdca41f 100644 --- a/build.gradle +++ b/build.gradle @@ -6,7 +6,7 @@ plugins { } group = 'com.magmaguy' -version = '1.3.4' +version = '1.3.5-SNAPSHOT' repositories { mavenCentral() @@ -89,4 +89,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/schematics/SchematicContainer.java b/src/main/java/com/magmaguy/betterstructures/schematics/SchematicContainer.java index 4bdd2ca..e5d7868 100644 --- a/src/main/java/com/magmaguy/betterstructures/schematics/SchematicContainer.java +++ b/src/main/java/com/magmaguy/betterstructures/schematics/SchematicContainer.java @@ -68,6 +68,7 @@ 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) || diff --git a/src/main/resources/plugin.yml b/src/main/resources/plugin.yml index 53ba2ce..ea088c2 100644 --- a/src/main/resources/plugin.yml +++ b/src/main/resources/plugin.yml @@ -1,5 +1,5 @@ name: BetterStructures -version: '1.3.4' +version: '1.3.5' main: com.magmaguy.betterstructures.BetterStructures api-version: 1.14 depend: [ WorldEdit ] From b4b2152fb4459c6fcad78ba08220a6f7ca9fc50d Mon Sep 17 00:00:00 2001 From: BuildTools Date: Thu, 8 Sep 2022 21:09:50 +0100 Subject: [PATCH 11/39] Version 1.3.5 - [New] Added maven repository for BetterStructures - [Fix] Fixed issue that seems to happen for some versions of FAWE and potentially WorldEdit --- src/main/resources/schematics/ReadMe.txt | 87 +----------------------- 1 file changed, 2 insertions(+), 85 deletions(-) diff --git a/src/main/resources/schematics/ReadMe.txt b/src/main/resources/schematics/ReadMe.txt index f61cf8d..cc1d47f 100644 --- a/src/main/resources/schematics/ReadMe.txt +++ b/src/main/resources/schematics/ReadMe.txt @@ -1,86 +1,3 @@ -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. +BetterStructures is a Spigot plugin that aims to place structures in any world gen! +Detailed instructions are available in the GitHub wiki. \ No newline at end of file From ce6bf319449bb48ed7d704b95fe06de05bb22ce2 Mon Sep 17 00:00:00 2001 From: BuildTools Date: Sun, 29 Jan 2023 18:29:27 +0000 Subject: [PATCH 12/39] Version 1.4.0 - [New] Added the imports folder and reconverted all existing build packs to use the import system, same as for EliteMobs just put a zipped folder in there and /bs reload! - [New] Import system for BetterStructures can import into EliteMobs - [New] Improved error logging - [New] Updated documentation - [New] Schematics can now adequately be turned off - [New] Added EliteMobs integration! [elitemobs] on the first line of a sign, all other lines can be used to write the filename as one continuous entry - [New] Added WorldGuard compatibility! Zones with elites will automatically be protected until the bosses are killed. These protections do not persist after uninstalling BetterStructures. - [New] Added configuration setting to disable new building warnings - [New] Added the /bettestructures silent command to disable build wanrings from in-game without permissions - [New] Added configuration setting in ValidWorlds.yml to disable structure spawning in new worlds - [Optimization] Lowered the amount of checks for terrain adequacy - [Tweak] Fixed issue that was causing entities to not spawn in the center of blocks, sometimes leading to suffocation - [Fix] Changed generator_underground_shallow.yml to only be used in normal type worlds - [Fix] Fixed issue where underground dripstone generators would not actually spawn builds in underground dripstone biomes --- build.gradle | 10 +- .../betterstructures/BetterStructures.java | 19 +++ .../buildingfitter/FitAirBuilding.java | 2 + .../buildingfitter/FitAnything.java | 59 +++++-- .../buildingfitter/FitLiquidBuilding.java | 3 +- .../buildingfitter/FitSurfaceBuilding.java | 9 ++ .../FitUndergroundBuilding.java | 9 +- .../buildingfitter/util/SchematicPicker.java | 1 - .../buildingfitter/util/TerrainAdequacy.java | 2 - .../chests/ChestContents.java | 2 - .../betterstructures/chests/ChestEntry.java | 1 - .../commands/CommandHandler.java | 10 ++ .../betterstructures/config/CustomConfig.java | 1 - .../config/DefaultConfig.java | 40 +++-- .../config/ValidWorldsConfig.java | 2 +- .../config/generators/GeneratorConfig.java | 1 - .../premade/GeneratorLiquidNether.java | 1 - .../premade/GeneratorLiquidOverworld.java | 1 - .../premade/GeneratorSkyBarrenConfig.java | 1 - .../GeneratorSkyCrimsonForestConfig.java | 1 - .../premade/GeneratorSkyDesertConfig.java | 1 - .../premade/GeneratorSkyEndConfig.java | 1 - .../premade/GeneratorSkyGlobal.java | 1 - .../premade/GeneratorSkyGrasslandConfig.java | 1 - .../premade/GeneratorSkyNetherConfig.java | 1 - .../GeneratorSkyNetherWastesConfig.java | 1 - .../premade/GeneratorSkySnowyConfig.java | 1 - .../premade/GeneratorSkySoulSandConfig.java | 1 - .../GeneratorSkyWarpedForestConfig.java | 1 - .../premade/GeneratorSurfaceBarrenConfig.java | 1 - .../premade/GeneratorSurfaceDesertConfig.java | 1 - .../premade/GeneratorSurfaceEndConfig.java | 1 - .../premade/GeneratorSurfaceGlobalConfig.java | 1 - .../GeneratorSurfaceGrasslandConfig.java | 1 - .../premade/GeneratorSurfaceNetherConfig.java | 1 - .../premade/GeneratorSurfaceSnowyConfig.java | 1 - .../GeneratorUndergroundDeepConfig.java | 2 +- .../GeneratorUndergroundDripstoneConfig.java | 3 +- .../GeneratorUndergroundEndConfig.java | 1 - .../GeneratorUndergroundLushConfig.java | 1 - .../GeneratorUndergroundNetherConfig.java | 1 - .../GeneratorUndergroundNetherDeep.java | 1 - .../GeneratorUndergroundNetherShallow.java | 1 - .../GeneratorUndergroundShallowConfig.java | 2 - .../UndergroundGeneratorGlobalConfig.java | 1 - .../config/schematics/SchematicConfig.java | 3 +- .../configurationimporter/Import.java | 148 ++++++++++++++++++ .../listeners/NewChunkLoadEvent.java | 16 -- .../schematics/AbstractBlock.java | 11 ++ .../schematics/SchematicContainer.java | 21 ++- .../thirdparty/EliteMobs.java | 41 +++++ .../thirdparty/WorldGuard.java | 119 ++++++++++++++ .../util/WeighedProbability.java | 1 - .../betterstructures/util/ZipFile.java | 136 ++++++++++++++++ src/main/resources/plugin.yml | 5 +- src/main/resources/schematics/ReadMe.txt | 7 +- 56 files changed, 610 insertions(+), 102 deletions(-) create mode 100644 src/main/java/com/magmaguy/betterstructures/configurationimporter/Import.java create mode 100644 src/main/java/com/magmaguy/betterstructures/schematics/AbstractBlock.java create mode 100644 src/main/java/com/magmaguy/betterstructures/thirdparty/EliteMobs.java create mode 100644 src/main/java/com/magmaguy/betterstructures/thirdparty/WorldGuard.java create mode 100644 src/main/java/com/magmaguy/betterstructures/util/ZipFile.java diff --git a/build.gradle b/build.gradle index bdca41f..6a6bea7 100644 --- a/build.gradle +++ b/build.gradle @@ -6,7 +6,7 @@ plugins { } group = 'com.magmaguy' -version = '1.3.5-SNAPSHOT' +version = '1.4.0-SNAPSHOT' repositories { mavenCentral() @@ -27,6 +27,8 @@ repositories { //CloudCommands maven { url = 'https://oss.sonatype.org/content/repositories/snapshots' } + //EliteMobs + maven { url = 'https://s01.oss.sonatype.org/content/repositories/snapshots' } } dependencies { @@ -34,7 +36,9 @@ dependencies { //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.13' //lombok compileOnly 'org.projectlombok:lombok:1.18.22' annotationProcessor 'org.projectlombok:lombok:1.18.22' @@ -50,6 +54,8 @@ 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' } diff --git a/src/main/java/com/magmaguy/betterstructures/BetterStructures.java b/src/main/java/com/magmaguy/betterstructures/BetterStructures.java index 5e5a00b..b68cd85 100644 --- a/src/main/java/com/magmaguy/betterstructures/BetterStructures.java +++ b/src/main/java/com/magmaguy/betterstructures/BetterStructures.java @@ -6,8 +6,11 @@ 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.bukkit.Bukkit; import org.bukkit.plugin.java.JavaPlugin; @@ -24,6 +27,8 @@ public void onEnable() { Bukkit.getPluginManager().registerEvents(new NewChunkLoadEvent(), this); Bukkit.getPluginManager().registerEvents(new ValidWorldsConfig.ValidWorldsConfigEvents(), this); Bukkit.getPluginManager().registerEvents(new VersionChecker.VersionCheckerEvents(), this); + //Creates import folder if one doesn't exist, imports any content inside + Import.initialize(); try { this.getConfig().save("config.yml"); } catch (IOException e) { @@ -36,6 +41,20 @@ public void onEnable() { new SchematicConfig(); new CommandHandler(); VersionChecker.checkPluginVersion(); + if (Bukkit.getPluginManager().getPlugin("WorldGuard") != null) + Bukkit.getPluginManager().registerEvents(new WorldGuard(), this); + } + + @Override + public void onLoad() { + try { + if (Bukkit.getPluginManager().getPlugin("WorldGuard") != 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/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 0f31fe0..69669f4 100644 --- a/src/main/java/com/magmaguy/betterstructures/buildingfitter/FitAnything.java +++ b/src/main/java/com/magmaguy/betterstructures/buildingfitter/FitAnything.java @@ -5,8 +5,11 @@ 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.WorldGuard; import com.magmaguy.betterstructures.util.SpigotMessage; import com.magmaguy.betterstructures.util.SurfaceMaterials; import com.magmaguy.betterstructures.util.WarningMessage; @@ -34,7 +37,7 @@ public class FitAnything { @Getter protected SchematicContainer schematicContainer; - protected final double startingScore = 100; + protected double startingScore = 100; protected final int searchRadius = 1; protected final int scanStep = 3; protected Clipboard schematicClipboard = null; @@ -43,6 +46,7 @@ public class FitAnything { protected double highestScore = 10; @Getter protected Location location = null; + protected GeneratorConfigFields.StructureType structureType; public static void commandBasedCreation(Chunk chunk, GeneratorConfigFields.StructureType structureType, SchematicContainer container) { switch (structureType) { @@ -148,14 +152,17 @@ protected void paste(Location location) { 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(), - "/betterstructures teleporttocoords " + location.getWorld().getName() + " " + location.getBlockX() + " " + location.getBlockY() + " " + location.getBlockZ()) - ); + 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()) + ); } + for (BlockVector3 blockVector3 : barrierBlocks) { try { schematicClipboard.setBlock(blockVector3, BukkitAdapter.adapt(barrierBlock)); @@ -176,23 +183,27 @@ protected void paste(Location location) { try { addPedestal(location); } catch (Exception exception) { - new WarningMessage("Failed to correctly assign pedestal material!", true); + new WarningMessage("Failed to correctly assign pedestal material!"); + exception.printStackTrace(); } try { clearTrees(location); } catch (Exception exception) { - new WarningMessage("Failed to correctly clear trees!", true); + new WarningMessage("Failed to correctly clear trees!"); + exception.printStackTrace(); } } try { fillChests(); } catch (Exception exception) { - new WarningMessage("Failed to correctly fill chests!", true); + new WarningMessage("Failed to correctly fill chests!"); + exception.printStackTrace(); } try { spawnEntities(); } catch (Exception exception) { - new WarningMessage("Failed to correctly spawn entities!", true); + new WarningMessage("Failed to correctly spawn entities!"); + //exception.printStackTrace(); } } @@ -290,7 +301,7 @@ 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)); Entity entity = signLocation.getWorld().spawnEntity(signLocation, schematicContainer.getVanillaSpawns().get(entityPosition)); entity.setPersistent(true); if (entity instanceof LivingEntity) { @@ -301,6 +312,28 @@ private void spawnEntities() { 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 (Bukkit.getPluginManager().getPlugin("WorldGuard") != null) { + WorldGuard.Protect( + BlockVector3.at(lowestCorner.getX(), lowestCorner.getY(), lowestCorner.getZ()), + BlockVector3.at(highestCorner.getX(), highestCorner.getY(), highestCorner.getZ()), + 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."); + } + } + } } + public static boolean worldGuardWarn = false; } 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..fdf7482 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; diff --git a/src/main/java/com/magmaguy/betterstructures/buildingfitter/util/TerrainAdequacy.java b/src/main/java/com/magmaguy/betterstructures/buildingfitter/util/TerrainAdequacy.java index 4294c9c..68d4f58 100644 --- a/src/main/java/com/magmaguy/betterstructures/buildingfitter/util/TerrainAdequacy.java +++ b/src/main/java/com/magmaguy/betterstructures/buildingfitter/util/TerrainAdequacy.java @@ -1,11 +1,9 @@ package com.magmaguy.betterstructures.buildingfitter.util; -import com.magmaguy.betterstructures.util.ChunkLocationChecker; import com.magmaguy.betterstructures.util.SurfaceMaterials; import com.sk89q.worldedit.bukkit.BukkitAdapter; import com.sk89q.worldedit.extent.clipboard.Clipboard; import com.sk89q.worldedit.math.BlockVector3; -import org.bukkit.Bukkit; import org.bukkit.Location; import org.bukkit.Material; import org.bukkit.util.Vector; diff --git a/src/main/java/com/magmaguy/betterstructures/chests/ChestContents.java b/src/main/java/com/magmaguy/betterstructures/chests/ChestContents.java index 76f31d4..557f3b8 100644 --- a/src/main/java/com/magmaguy/betterstructures/chests/ChestContents.java +++ b/src/main/java/com/magmaguy/betterstructures/chests/ChestContents.java @@ -4,12 +4,10 @@ import com.magmaguy.betterstructures.util.ItemStackSerialization; import com.magmaguy.betterstructures.util.WarningMessage; import lombok.Getter; -import org.bukkit.Bukkit; import org.bukkit.Material; import org.bukkit.block.Container; import org.bukkit.inventory.ItemStack; -import java.nio.Buffer; import java.util.ArrayList; import java.util.List; diff --git a/src/main/java/com/magmaguy/betterstructures/chests/ChestEntry.java b/src/main/java/com/magmaguy/betterstructures/chests/ChestEntry.java index d23346d..7af7b8d 100644 --- a/src/main/java/com/magmaguy/betterstructures/chests/ChestEntry.java +++ b/src/main/java/com/magmaguy/betterstructures/chests/ChestEntry.java @@ -1,6 +1,5 @@ package com.magmaguy.betterstructures.chests; -import org.bukkit.Bukkit; import org.bukkit.Material; import org.bukkit.inventory.ItemStack; diff --git a/src/main/java/com/magmaguy/betterstructures/commands/CommandHandler.java b/src/main/java/com/magmaguy/betterstructures/commands/CommandHandler.java index 79b6339..b6c8f85 100644 --- a/src/main/java/com/magmaguy/betterstructures/commands/CommandHandler.java +++ b/src/main/java/com/magmaguy/betterstructures/commands/CommandHandler.java @@ -11,6 +11,7 @@ import cloud.commandframework.minecraft.extras.MinecraftHelp; import com.magmaguy.betterstructures.MetadataHandler; import com.magmaguy.betterstructures.buildingfitter.FitAnything; +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; @@ -178,6 +179,15 @@ public void constructCommands() { 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() + "!")); + })); } private void placeSchematic(String schematicFile, String schematicType, Player player) { 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/DefaultConfig.java b/src/main/java/com/magmaguy/betterstructures/config/DefaultConfig.java index fec68b1..dffcefb 100644 --- a/src/main/java/com/magmaguy/betterstructures/config/DefaultConfig.java +++ b/src/main/java/com/magmaguy/betterstructures/config/DefaultConfig.java @@ -29,18 +29,6 @@ private DefaultConfig() { private static int endAirBuildMinAltitude; @Getter private static int endAirBuildMaxAltitude; - /* - @Getter - private static double airStructureRarityMultiplier; - @Getter - private static double surfaceStructureRarityMultiplier; - @Getter - private static double shallowUndergroundStructureRarityMultiplier; - @Getter - private static double deepUndergroundStructureRarityMultiplier; - @Getter - private static double liquidSurfaceStructureRarityMultiplier; - */ @Getter private static double airStructuresPerThousandChunks; @Getter @@ -51,11 +39,18 @@ private DefaultConfig() { private static double shallowUndergroundStructuresPerThousandChunks; @Getter private static double deepUndergroundStructuresPerThousandChunks; + @Getter + private static boolean newBuildingWarn; + @Getter + private static String regionProtectedMessage; + + private static File file; + private static FileConfiguration fileConfiguration; 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); @@ -66,19 +61,22 @@ public static void initializeConfig() { normalCustomAirBuildingMaxAltitude = ConfigurationEngine.setInt(fileConfiguration, "normalCustomAirBuildingMaxAltitude", 120); endAirBuildMinAltitude = ConfigurationEngine.setInt(fileConfiguration, "endAirBuildMinAltitude", 80); endAirBuildMaxAltitude = ConfigurationEngine.setInt(fileConfiguration, "endAirBuildMaxAltitude", 120); - /* - airStructureRarityMultiplier = ConfigurationEngine.setDouble(fileConfiguration, "airStructureRarityMultiplier", 1.5D); - surfaceStructureRarityMultiplier = ConfigurationEngine.setDouble(fileConfiguration, "surfaceStructureRarityMultiplier", .5D); - shallowUndergroundStructureRarityMultiplier = ConfigurationEngine.setDouble(fileConfiguration, "shallowUndergroundStructureRarityMultiplier", .5D); - deepUndergroundStructureRarityMultiplier = ConfigurationEngine.setDouble(fileConfiguration, "deepUndergroundStructureRarityMultiplier", .5D); - liquidSurfaceStructureRarityMultiplier = ConfigurationEngine.setDouble(fileConfiguration, "liquidSurfaceStructureRarityMultiplier", 11D); - */ 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!"); 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/premade/GeneratorLiquidNether.java b/src/main/java/com/magmaguy/betterstructures/config/generators/premade/GeneratorLiquidNether.java index 8a98d6f..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; 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 8445a0e..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; 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 38c6ed9..01371b2 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; 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 5337c0f..2dc4965 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; 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 bdb1782..afba027 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; 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 271eb7c..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; 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 6ce7af4..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,7 +1,6 @@ package com.magmaguy.betterstructures.config.generators.premade; import com.magmaguy.betterstructures.config.generators.GeneratorConfigFields; -import com.magmaguy.betterstructures.util.DefaultChestContents; import java.util.Arrays; 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 b4a54a9..d64f106 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; 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 0654190..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; 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 40c9b88..2383c2a 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; 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 6a21e09..58581be 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; 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 18b7f1f..750a565 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; 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 ce05af3..96febd0 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; 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 cad1d40..a6567a0 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; 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 1b37eef..7842f5c 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; 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 c8dc6d1..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; 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 7649027..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; 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 3e600c2..98d3770 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; 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 64ba83a..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; 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 6213912..e30cba2 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; 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 de101a9..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,6 +8,7 @@ public class GeneratorUndergroundDeepConfig extends GeneratorConfigFields { public GeneratorUndergroundDeepConfig(){ super("generator_underground_deep", true, Arrays.asList(StructureType.UNDERGROUND_DEEP)); + 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 index e29cce1..4dd5787 100644 --- a/src/main/java/com/magmaguy/betterstructures/config/generators/premade/GeneratorUndergroundDripstoneConfig.java +++ b/src/main/java/com/magmaguy/betterstructures/config/generators/premade/GeneratorUndergroundDripstoneConfig.java @@ -1,7 +1,7 @@ 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 org.bukkit.block.Biome; import java.util.Arrays; @@ -9,6 +9,7 @@ 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)); 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 f846553..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; 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 index 5a65e17..6c91887 100644 --- a/src/main/java/com/magmaguy/betterstructures/config/generators/premade/GeneratorUndergroundLushConfig.java +++ b/src/main/java/com/magmaguy/betterstructures/config/generators/premade/GeneratorUndergroundLushConfig.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; 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 931b870..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; 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 13bef16..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; 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 80c4140..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; 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 3ccffe1..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,10 +1,8 @@ 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 { 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 6e5c8af..7262210 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; 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/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 620cc6b..22bc1c6 100644 --- a/src/main/java/com/magmaguy/betterstructures/listeners/NewChunkLoadEvent.java +++ b/src/main/java/com/magmaguy/betterstructures/listeners/NewChunkLoadEvent.java @@ -25,11 +25,6 @@ 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) { @@ -57,7 +52,6 @@ public void run() { private void surfaceScanner(Chunk chunk) { if (SchematicContainer.getSchematics().get(GeneratorConfigFields.StructureType.SURFACE).isEmpty()) return; - //if (!seededSimplexRandomization(chunk, .99, surfaceOffset, DefaultConfig.getSurfaceStructureRarityMultiplier())) return; if (ThreadLocalRandom.current().nextDouble() > DefaultConfig.getLandStructuresPerThousandChunks() / 1000D) return; new FitSurfaceBuilding(chunk); @@ -66,7 +60,6 @@ private void surfaceScanner(Chunk chunk) { private void shallowUndergroundScanner(Chunk chunk) { if (SchematicContainer.getSchematics().get(GeneratorConfigFields.StructureType.UNDERGROUND_SHALLOW).isEmpty()) return; - //if (!seededSimplexRandomization(chunk, .99, shallowUndergroundOffset, DefaultConfig.getShallowUndergroundStructureRarityMultiplier())) return; if (ThreadLocalRandom.current().nextDouble() > DefaultConfig.getShallowUndergroundStructuresPerThousandChunks() / 1000D) return; FitUndergroundShallowBuilding.fit(chunk); @@ -75,7 +68,6 @@ private void shallowUndergroundScanner(Chunk chunk) { private void deepUndergroundScanner(Chunk chunk) { if (SchematicContainer.getSchematics().get(GeneratorConfigFields.StructureType.UNDERGROUND_DEEP).isEmpty()) return; - //if (!seededSimplexRandomization(chunk, .99, deepUndergroundOffset, DefaultConfig.getDeepUndergroundStructureRarityMultiplier())) return; if (ThreadLocalRandom.current().nextDouble() > DefaultConfig.getDeepUndergroundStructuresPerThousandChunks() / 1000D) return; FitUndergroundDeepBuilding.fit(chunk); @@ -83,7 +75,6 @@ private void deepUndergroundScanner(Chunk chunk) { private void skyScanner(Chunk chunk) { if (SchematicContainer.getSchematics().get(GeneratorConfigFields.StructureType.SKY).isEmpty()) return; - //if (!seededSimplexRandomization(chunk, .99, airOffset, DefaultConfig.getAirStructureRarityMultiplier())) return; if (ThreadLocalRandom.current().nextDouble() > DefaultConfig.getAirStructuresPerThousandChunks() / 1000D) return; new FitAirBuilding(chunk); @@ -92,15 +83,8 @@ private void skyScanner(Chunk chunk) { private void liquidSurfaceScanner(Chunk chunk) { if (SchematicContainer.getSchematics().get(GeneratorConfigFields.StructureType.LIQUID_SURFACE).isEmpty()) return; - // if (!seededSimplexRandomization(chunk, .99, liquidOffset, DefaultConfig.getLiquidSurfaceStructureRarityMultiplier())) return; if (ThreadLocalRandom.current().nextDouble() > DefaultConfig.getOceanStructuresPerThousandChunks() / 1000D) return; new FitLiquidBuilding(chunk); } - -/* this has issues when you try to integrate customization options - private boolean seededSimplexRandomization(Chunk chunk, double strictness, int offset, double rarityMultiplier) { - return (SimplexNoise.noise(rarityMultiplier * chunk.getX() + (double) offset, rarityMultiplier * 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 e5d7868..d041888 100644 --- a/src/main/java/com/magmaguy/betterstructures/schematics/SchematicContainer.java +++ b/src/main/java/com/magmaguy/betterstructures/schematics/SchematicContainer.java @@ -46,7 +46,11 @@ public static void shutdown() { @Getter private final HashMap vanillaSpawns = new HashMap<>(); @Getter + private final HashMap eliteMobsSpawns = new HashMap<>(); + @Getter private ChestContents chestContents = null; + @Getter + List abstractBlocks = new ArrayList<>(); public SchematicContainer(Clipboard clipboard, String clipboardFilename, SchematicConfigField schematicConfigField, String configFilename) { this.clipboard = clipboard; @@ -108,7 +112,11 @@ public SchematicContainer(Clipboard clipboard, String clipboardFilename, Schemat } vanillaSpawns.put(new Vector(x, y, z), entityType); } else if (line1.toLowerCase().contains("[elitemobs]")) { - //todo: elitemobs integration goes here + String filename = ""; + for (int i = 2; i < 5; i++) + filename += baseBlock.getNbtData().getString("Text" + i) + .split(":")[1].replace("\"", "").replace("}", ""); + eliteMobsSpawns.put(new Vector(x, y, z), filename); } } } @@ -123,6 +131,17 @@ public SchematicContainer(Clipboard clipboard, String clipboardFilename, Schemat } } + /* todo: coming soon + private void initializeAbstractBlocks() { + BlockVector3 dimensions = clipboard.getDimensions(); + for (int x = 0; x < dimensions.getX(); x++) + for (int y = 0; y < dimensions.getY(); y++) + for (int z = 0; z < dimensions.getZ(); z++) + new AbstractBlock(clipboard.getFullBlock().toBaseBlock().applyBlock()) + } + + */ + public boolean isValidEnvironment(World.Environment environment) { return generatorConfigFields.getValidWorldEnvironments() == null || generatorConfigFields.getValidWorldEnvironments().isEmpty() || 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/WorldGuard.java b/src/main/java/com/magmaguy/betterstructures/thirdparty/WorldGuard.java new file mode 100644 index 0000000..4abd33d --- /dev/null +++ b/src/main/java/com/magmaguy/betterstructures/thirdparty/WorldGuard.java @@ -0,0 +1,119 @@ +package com.magmaguy.betterstructures.thirdparty; + +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; + +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"); + } + } + + 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) { + 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/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/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 ea088c2..59c9854 100644 --- a/src/main/resources/plugin.yml +++ b/src/main/resources/plugin.yml @@ -1,8 +1,11 @@ name: BetterStructures -version: '1.3.5' +version: '1.4.0' main: com.magmaguy.betterstructures.BetterStructures api-version: 1.14 depend: [ WorldEdit ] +softdepend: + - EliteMobs + - WorldGuard 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 cc1d47f..ba2166c 100644 --- a/src/main/resources/schematics/ReadMe.txt +++ b/src/main/resources/schematics/ReadMe.txt @@ -1,3 +1,4 @@ -BetterStructures is a Spigot plugin that aims to place structures in any world gen! - -Detailed instructions are available in the GitHub wiki. \ No newline at end of file +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 From c4d674b745af05088277f1a0b5610ef7b44362fd Mon Sep 17 00:00:00 2001 From: BuildTools Date: Sun, 29 Jan 2023 19:34:57 +0000 Subject: [PATCH 13/39] Version 1.4.1 - [Hotfix] Fixed issue where brand new installs would not generate default files correctly --- build.gradle | 2 +- .../java/com/magmaguy/betterstructures/BetterStructures.java | 5 +++-- src/main/resources/plugin.yml | 2 +- 3 files changed, 5 insertions(+), 4 deletions(-) diff --git a/build.gradle b/build.gradle index 6a6bea7..75975e0 100644 --- a/build.gradle +++ b/build.gradle @@ -6,7 +6,7 @@ plugins { } group = 'com.magmaguy' -version = '1.4.0-SNAPSHOT' +version = '1.4.1-SNAPSHOT' repositories { mavenCentral() diff --git a/src/main/java/com/magmaguy/betterstructures/BetterStructures.java b/src/main/java/com/magmaguy/betterstructures/BetterStructures.java index b68cd85..896c08e 100644 --- a/src/main/java/com/magmaguy/betterstructures/BetterStructures.java +++ b/src/main/java/com/magmaguy/betterstructures/BetterStructures.java @@ -27,8 +27,6 @@ public void onEnable() { Bukkit.getPluginManager().registerEvents(new NewChunkLoadEvent(), this); Bukkit.getPluginManager().registerEvents(new ValidWorldsConfig.ValidWorldsConfigEvents(), this); Bukkit.getPluginManager().registerEvents(new VersionChecker.VersionCheckerEvents(), this); - //Creates import folder if one doesn't exist, imports any content inside - Import.initialize(); try { this.getConfig().save("config.yml"); } catch (IOException e) { @@ -36,6 +34,9 @@ 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(); diff --git a/src/main/resources/plugin.yml b/src/main/resources/plugin.yml index 59c9854..0e32d72 100644 --- a/src/main/resources/plugin.yml +++ b/src/main/resources/plugin.yml @@ -1,5 +1,5 @@ name: BetterStructures -version: '1.4.0' +version: '1.4.1' main: com.magmaguy.betterstructures.BetterStructures api-version: 1.14 depend: [ WorldEdit ] From 56dc13b099afe473d0ee254534a941ef43b9af5e Mon Sep 17 00:00:00 2001 From: BuildTools Date: Tue, 7 Feb 2023 19:07:26 +0000 Subject: [PATCH 14/39] Version 1.4.2 - [New] BetterStructures will only remove a protected region when a boss that is set to be removed after death is killed - [Fix] Fixed edge case where in some operating systems the path for the imports would not work as expected - [Fix] Fixed warning that would incorrectly show up when elitemobs wasn't installed - [Tweak] Tweaked treasure_special.yml to work with the lootify command --- build.gradle | 2 +- .../com/magmaguy/betterstructures/BetterStructures.java | 6 ++++-- .../betterstructures/buildingfitter/FitAnything.java | 3 ++- .../betterstructures/config/ConfigurationEngine.java | 4 +++- .../betterstructures/config/generators/GeneratorConfig.java | 1 + .../config/schematics/SchematicConfigField.java | 5 +++-- .../config/treasures/TreasureConfigFields.java | 5 +++-- .../magmaguy/betterstructures/thirdparty/WorldGuard.java | 1 + src/main/resources/plugin.yml | 2 +- 9 files changed, 19 insertions(+), 10 deletions(-) diff --git a/build.gradle b/build.gradle index 75975e0..c8b75ad 100644 --- a/build.gradle +++ b/build.gradle @@ -6,7 +6,7 @@ plugins { } group = 'com.magmaguy' -version = '1.4.1-SNAPSHOT' +version = '1.4.2-SNAPSHOT' repositories { mavenCentral() diff --git a/src/main/java/com/magmaguy/betterstructures/BetterStructures.java b/src/main/java/com/magmaguy/betterstructures/BetterStructures.java index 896c08e..6f822fb 100644 --- a/src/main/java/com/magmaguy/betterstructures/BetterStructures.java +++ b/src/main/java/com/magmaguy/betterstructures/BetterStructures.java @@ -42,14 +42,16 @@ public void onEnable() { new SchematicConfig(); new CommandHandler(); VersionChecker.checkPluginVersion(); - if (Bukkit.getPluginManager().getPlugin("WorldGuard") != null) + if (Bukkit.getPluginManager().getPlugin("WorldGuard") != null && + Bukkit.getPluginManager().getPlugin("EliteMobs") != null) Bukkit.getPluginManager().registerEvents(new WorldGuard(), this); } @Override public void onLoad() { try { - if (Bukkit.getPluginManager().getPlugin("WorldGuard") != null) + 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."); diff --git a/src/main/java/com/magmaguy/betterstructures/buildingfitter/FitAnything.java b/src/main/java/com/magmaguy/betterstructures/buildingfitter/FitAnything.java index 69669f4..bed9133 100644 --- a/src/main/java/com/magmaguy/betterstructures/buildingfitter/FitAnything.java +++ b/src/main/java/com/magmaguy/betterstructures/buildingfitter/FitAnything.java @@ -321,7 +321,8 @@ private void spawnEntities() { 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 (Bukkit.getPluginManager().getPlugin("WorldGuard") != null) { + if (Bukkit.getPluginManager().getPlugin("WorldGuard") != null && + Bukkit.getPluginManager().getPlugin("EliteMobs") != null) { WorldGuard.Protect( BlockVector3.at(lowestCorner.getX(), lowestCorner.getY(), lowestCorner.getZ()), BlockVector3.at(highestCorner.getX(), highestCorner.getY(), highestCorner.getZ()), 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/generators/GeneratorConfig.java b/src/main/java/com/magmaguy/betterstructures/config/generators/GeneratorConfig.java index ff72ed2..3a4fbd6 100644 --- a/src/main/java/com/magmaguy/betterstructures/config/generators/GeneratorConfig.java +++ b/src/main/java/com/magmaguy/betterstructures/config/generators/GeneratorConfig.java @@ -1,6 +1,7 @@ package com.magmaguy.betterstructures.config.generators; import com.magmaguy.betterstructures.config.CustomConfig; +import com.magmaguy.elitemobs.utils.Developer; import lombok.Getter; import java.util.HashMap; 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 47b0e4b..cb61ba4 100644 --- a/src/main/java/com/magmaguy/betterstructures/config/schematics/SchematicConfigField.java +++ b/src/main/java/com/magmaguy/betterstructures/config/schematics/SchematicConfigField.java @@ -7,6 +7,7 @@ import com.magmaguy.betterstructures.config.treasures.TreasureConfig; import com.magmaguy.betterstructures.config.treasures.TreasureConfigFields; import com.magmaguy.betterstructures.util.WarningMessage; +import com.magmaguy.elitemobs.utils.Developer; import lombok.Getter; import lombok.Setter; import org.bukkit.Material; @@ -49,11 +50,11 @@ 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."); + new WarningMessage("Failed to assign a valid generator to " + filename + "! This will not spawn. Generator config name: " + generatorConfigFilename); return; } this.chestContents = generatorConfigFields.getChestContents(); diff --git a/src/main/java/com/magmaguy/betterstructures/config/treasures/TreasureConfigFields.java b/src/main/java/com/magmaguy/betterstructures/config/treasures/TreasureConfigFields.java index 08ee0de..59860b5 100644 --- a/src/main/java/com/magmaguy/betterstructures/config/treasures/TreasureConfigFields.java +++ b/src/main/java/com/magmaguy/betterstructures/config/treasures/TreasureConfigFields.java @@ -7,13 +7,14 @@ import lombok.Setter; import org.bukkit.entity.Player; +import java.util.ArrayList; import java.util.List; public class TreasureConfigFields extends CustomConfigFields { @Getter @Setter - private List rawLoot = null; + private List rawLoot = new ArrayList<>(); @Getter @Setter private ChestContents chestContents = null; @@ -25,7 +26,7 @@ public TreasureConfigFields(String filename, boolean isEnabled) { @Override public void processConfigFields() { this.isEnabled = processBoolean("isEnabled", isEnabled, true, true); - this.rawLoot = processStringList("loot", rawLoot, null, true); + this.rawLoot = processStringList("loot", rawLoot, new ArrayList<>(), true); chestContents = new ChestContents(this); } diff --git a/src/main/java/com/magmaguy/betterstructures/thirdparty/WorldGuard.java b/src/main/java/com/magmaguy/betterstructures/thirdparty/WorldGuard.java index 4abd33d..33a766a 100644 --- a/src/main/java/com/magmaguy/betterstructures/thirdparty/WorldGuard.java +++ b/src/main/java/com/magmaguy/betterstructures/thirdparty/WorldGuard.java @@ -74,6 +74,7 @@ public static void Protect(BlockVector3 corner1, BlockVector3 corner2, String bo } 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( diff --git a/src/main/resources/plugin.yml b/src/main/resources/plugin.yml index 0e32d72..a6af51b 100644 --- a/src/main/resources/plugin.yml +++ b/src/main/resources/plugin.yml @@ -1,5 +1,5 @@ name: BetterStructures -version: '1.4.1' +version: '1.4.2' main: com.magmaguy.betterstructures.BetterStructures api-version: 1.14 depend: [ WorldEdit ] From d75583edc1a346110b002499c2bc70cd17c9efe5 Mon Sep 17 00:00:00 2001 From: carm Date: Mon, 3 Apr 2023 00:18:01 +0800 Subject: [PATCH 15/39] feat(third-party): Support for MMOItems and MythicMobs. --- build.gradle | 17 ++++++ .../buildingfitter/FitAnything.java | 29 +++++++++++ .../chests/ChestContents.java | 22 ++++++++ .../schematics/SchematicContainer.java | 2 + .../thirdparty/MythicMobs.java | 52 +++++++++++++++++++ 5 files changed, 122 insertions(+) create mode 100644 src/main/java/com/magmaguy/betterstructures/thirdparty/MythicMobs.java diff --git a/build.gradle b/build.gradle index c8b75ad..1c4a798 100644 --- a/build.gradle +++ b/build.gradle @@ -29,6 +29,13 @@ repositories { 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 { @@ -57,6 +64,16 @@ dependencies { //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.1-SNAPSHOT' + //MMOItems + compileOnly group: 'net.Indyuce', name: 'MMOItems-API', version: '6.9.2-SNAPSHOT' + // carm end - Support MMOItems and MythicMobs + } artifacts { // task 'build' runs generates uberjar diff --git a/src/main/java/com/magmaguy/betterstructures/buildingfitter/FitAnything.java b/src/main/java/com/magmaguy/betterstructures/buildingfitter/FitAnything.java index bed9133..307fe26 100644 --- a/src/main/java/com/magmaguy/betterstructures/buildingfitter/FitAnything.java +++ b/src/main/java/com/magmaguy/betterstructures/buildingfitter/FitAnything.java @@ -9,6 +9,7 @@ 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; @@ -32,6 +33,7 @@ import java.util.HashMap; import java.util.HashSet; +import java.util.Map; import java.util.Set; public class FitAnything { @@ -334,6 +336,33 @@ private void spawnEntities() { } } } + + // carm start - Support for MythicMobs + for (Map.Entry entry : schematicContainer.getMythicMobsSpawns().entrySet()) { + Location mobLocation = LocationProjector.project(location, schematicOffset, entry.getKey()).clone(); + String conf = entry.getValue(); + + //If the spawn fails then don't continue + if (!MythicMobs.Spawn(mobLocation, conf)) 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 (Bukkit.getPluginManager().getPlugin("WorldGuard") != null && + Bukkit.getPluginManager().getPlugin("MythicMobs") != null) { + WorldGuard.Protect( + BlockVector3.at(lowestCorner.getX(), lowestCorner.getY(), lowestCorner.getZ()), + BlockVector3.at(highestCorner.getX(), highestCorner.getY(), highestCorner.getZ()), + conf, mobLocation); + } 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 end - Support for MythicMobs + } public static boolean worldGuardWarn = false; diff --git a/src/main/java/com/magmaguy/betterstructures/chests/ChestContents.java b/src/main/java/com/magmaguy/betterstructures/chests/ChestContents.java index 557f3b8..7b9a934 100644 --- a/src/main/java/com/magmaguy/betterstructures/chests/ChestContents.java +++ b/src/main/java/com/magmaguy/betterstructures/chests/ChestContents.java @@ -4,6 +4,9 @@ import com.magmaguy.betterstructures.util.ItemStackSerialization; import com.magmaguy.betterstructures.util.WarningMessage; import lombok.Getter; +import net.Indyuce.mmoitems.MMOItems; +import net.Indyuce.mmoitems.api.item.mmoitem.MMOItem; +import org.bukkit.Bukkit; import org.bukkit.Material; import org.bukkit.block.Container; import org.bukkit.inventory.ItemStack; @@ -54,6 +57,25 @@ private boolean processEntries(List rawChestEntries) { noProblems = false; } break; + + + case "mmoitems": // carm start - Support for MMOItems + if (Bukkit.getPluginManager().getPlugin("MMOItems") == null) { + new WarningMessage("MMOItems plugin not found! Problematic entry: " + subsection[0]); + noProblems = false; + break; + } + try { + String[] args = subsection[1].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"); + itemStack = mmoitem.newBuilder().build(); + } catch (Exception ex) { + new WarningMessage("Invalid mmo item detected! Problematic entry: " + subsection[0]); + noProblems = false; + } + // carm end - Support for MMOItems case "amount": try { if (subsection[1].contains("-")) { diff --git a/src/main/java/com/magmaguy/betterstructures/schematics/SchematicContainer.java b/src/main/java/com/magmaguy/betterstructures/schematics/SchematicContainer.java index d041888..33097c2 100644 --- a/src/main/java/com/magmaguy/betterstructures/schematics/SchematicContainer.java +++ b/src/main/java/com/magmaguy/betterstructures/schematics/SchematicContainer.java @@ -48,6 +48,8 @@ public static void shutdown() { @Getter private final HashMap eliteMobsSpawns = new HashMap<>(); @Getter + private final HashMap mythicMobsSpawns = new HashMap<>(); // carm - Support for MythicMobs + @Getter private ChestContents chestContents = null; @Getter List abstractBlocks = new ArrayList<>(); 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; + + } + +} From 6e9ffb18a6c6ba581e62c0f73a8a69775458548a Mon Sep 17 00:00:00 2001 From: carm Date: Mon, 3 Apr 2023 00:19:31 +0800 Subject: [PATCH 16/39] chore(conf): Removed unnecessary imports. Removed `com.magmaguy.elitemobs.utils.Developer` which has none usage. --- .../betterstructures/config/schematics/SchematicConfigField.java | 1 - 1 file changed, 1 deletion(-) 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 cb61ba4..1222d5f 100644 --- a/src/main/java/com/magmaguy/betterstructures/config/schematics/SchematicConfigField.java +++ b/src/main/java/com/magmaguy/betterstructures/config/schematics/SchematicConfigField.java @@ -7,7 +7,6 @@ import com.magmaguy.betterstructures.config.treasures.TreasureConfig; import com.magmaguy.betterstructures.config.treasures.TreasureConfigFields; import com.magmaguy.betterstructures.util.WarningMessage; -import com.magmaguy.elitemobs.utils.Developer; import lombok.Getter; import lombok.Setter; import org.bukkit.Material; From 981f8ceb32171346aef123cc38da1660940904dd Mon Sep 17 00:00:00 2001 From: carm Date: Mon, 3 Apr 2023 00:32:25 +0800 Subject: [PATCH 17/39] chore(mmoitems): Changed the delimiter of "type" and "item" --- .../magmaguy/betterstructures/chests/ChestContents.java | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/src/main/java/com/magmaguy/betterstructures/chests/ChestContents.java b/src/main/java/com/magmaguy/betterstructures/chests/ChestContents.java index 7b9a934..7061712 100644 --- a/src/main/java/com/magmaguy/betterstructures/chests/ChestContents.java +++ b/src/main/java/com/magmaguy/betterstructures/chests/ChestContents.java @@ -57,16 +57,15 @@ private boolean processEntries(List rawChestEntries) { noProblems = false; } break; - - - case "mmoitems": // carm start - Support for MMOItems + case "mmoitem": // carm start - Support for MMOItems + case "mmoitems": if (Bukkit.getPluginManager().getPlugin("MMOItems") == null) { new WarningMessage("MMOItems plugin not found! Problematic entry: " + subsection[0]); noProblems = false; break; } try { - String[] args = subsection[1].split(":"); + String[] args = subsection[1].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"); From f5738393a5d149fc8d18b581e26cf56aceee7569 Mon Sep 17 00:00:00 2001 From: carm Date: Mon, 3 Apr 2023 19:25:28 +0800 Subject: [PATCH 18/39] fix(guard): Removed unhandled WorldGuard protections. --- .../buildingfitter/FitAnything.java | 13 ------------- 1 file changed, 13 deletions(-) diff --git a/src/main/java/com/magmaguy/betterstructures/buildingfitter/FitAnything.java b/src/main/java/com/magmaguy/betterstructures/buildingfitter/FitAnything.java index 307fe26..5ccae2a 100644 --- a/src/main/java/com/magmaguy/betterstructures/buildingfitter/FitAnything.java +++ b/src/main/java/com/magmaguy/betterstructures/buildingfitter/FitAnything.java @@ -347,19 +347,6 @@ private void spawnEntities() { 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 (Bukkit.getPluginManager().getPlugin("WorldGuard") != null && - Bukkit.getPluginManager().getPlugin("MythicMobs") != null) { - WorldGuard.Protect( - BlockVector3.at(lowestCorner.getX(), lowestCorner.getY(), lowestCorner.getZ()), - BlockVector3.at(highestCorner.getX(), highestCorner.getY(), highestCorner.getZ()), - conf, mobLocation); - } 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 end - Support for MythicMobs From c78e240483c7d93b17ac0c8524e25a29175afef8 Mon Sep 17 00:00:00 2001 From: carm Date: Mon, 3 Apr 2023 21:35:32 +0800 Subject: [PATCH 19/39] feat(third-party): Support sign generates for MythicMobs. --- .../betterstructures/schematics/SchematicContainer.java | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/src/main/java/com/magmaguy/betterstructures/schematics/SchematicContainer.java b/src/main/java/com/magmaguy/betterstructures/schematics/SchematicContainer.java index 33097c2..39bb03a 100644 --- a/src/main/java/com/magmaguy/betterstructures/schematics/SchematicContainer.java +++ b/src/main/java/com/magmaguy/betterstructures/schematics/SchematicContainer.java @@ -119,7 +119,11 @@ public SchematicContainer(Clipboard clipboard, String clipboardFilename, Schemat filename += baseBlock.getNbtData().getString("Text" + i) .split(":")[1].replace("\"", "").replace("}", ""); eliteMobsSpawns.put(new Vector(x, y, z), filename); - } + }else if (line1.toLowerCase().contains("[mythicmobs]")) { // carm start - Support MythicMobs + String mob = baseBlock.getNbtData().getString("Text2").split(":")[1].replace("\"", "").replace("}", ""); + String level = baseBlock.getNbtData().getString("Text3").split(":")[1].replace("\"", "").replace("}", ""); + mythicMobsSpawns.put(new Vector(x, y, z), mob + (level.isEmpty() ? "" : ":" + level)); + } // carm end - Support MythicMobs } } chestContents = generatorConfigFields.getChestContents(); From ef5363278d285b2782059e97dfc3e3b8da4bd81b Mon Sep 17 00:00:00 2001 From: carm Date: Mon, 3 Apr 2023 23:52:30 +0800 Subject: [PATCH 20/39] fix(block): Fixed the problem that the sign generates MythicMobs not removed. --- .../magmaguy/betterstructures/buildingfitter/FitAnything.java | 1 + 1 file changed, 1 insertion(+) diff --git a/src/main/java/com/magmaguy/betterstructures/buildingfitter/FitAnything.java b/src/main/java/com/magmaguy/betterstructures/buildingfitter/FitAnything.java index 5ccae2a..97510f5 100644 --- a/src/main/java/com/magmaguy/betterstructures/buildingfitter/FitAnything.java +++ b/src/main/java/com/magmaguy/betterstructures/buildingfitter/FitAnything.java @@ -340,6 +340,7 @@ private void spawnEntities() { // 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); String conf = entry.getValue(); //If the spawn fails then don't continue From c92be3404edb6e03acccaa9c29505130756f090d Mon Sep 17 00:00:00 2001 From: carm Date: Mon, 3 Apr 2023 23:54:00 +0800 Subject: [PATCH 21/39] chore: Removed unnecessary params. --- .../betterstructures/buildingfitter/FitAnything.java | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-) diff --git a/src/main/java/com/magmaguy/betterstructures/buildingfitter/FitAnything.java b/src/main/java/com/magmaguy/betterstructures/buildingfitter/FitAnything.java index 97510f5..299f312 100644 --- a/src/main/java/com/magmaguy/betterstructures/buildingfitter/FitAnything.java +++ b/src/main/java/com/magmaguy/betterstructures/buildingfitter/FitAnything.java @@ -341,13 +341,9 @@ private void spawnEntities() { for (Map.Entry entry : schematicContainer.getMythicMobsSpawns().entrySet()) { Location mobLocation = LocationProjector.project(location, schematicOffset, entry.getKey()).clone(); mobLocation.getBlock().setType(Material.AIR); - String conf = entry.getValue(); //If the spawn fails then don't continue - if (!MythicMobs.Spawn(mobLocation, conf)) 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 (!MythicMobs.Spawn(mobLocation, entry.getValue())) return; } // carm end - Support for MythicMobs From 9509552b8bd3f5b7348e1eef41e3439989e46129 Mon Sep 17 00:00:00 2001 From: carm Date: Thu, 6 Apr 2023 19:51:10 +0800 Subject: [PATCH 22/39] fix(item): Add the "break" statement. --- .../java/com/magmaguy/betterstructures/chests/ChestContents.java | 1 + 1 file changed, 1 insertion(+) diff --git a/src/main/java/com/magmaguy/betterstructures/chests/ChestContents.java b/src/main/java/com/magmaguy/betterstructures/chests/ChestContents.java index 7061712..8040f20 100644 --- a/src/main/java/com/magmaguy/betterstructures/chests/ChestContents.java +++ b/src/main/java/com/magmaguy/betterstructures/chests/ChestContents.java @@ -74,6 +74,7 @@ private boolean processEntries(List rawChestEntries) { new WarningMessage("Invalid mmo item detected! Problematic entry: " + subsection[0]); noProblems = false; } + break; // carm end - Support for MMOItems case "amount": try { From 4df9557ab1b5af95f6585ad618c36685a9c29b19 Mon Sep 17 00:00:00 2001 From: carm Date: Tue, 2 May 2023 15:51:40 +0800 Subject: [PATCH 23/39] fix(event): fixed the issues of "BuildPlaceEvent can not be cancelled" (#19) --- .../magmaguy/betterstructures/buildingfitter/FitAnything.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/java/com/magmaguy/betterstructures/buildingfitter/FitAnything.java b/src/main/java/com/magmaguy/betterstructures/buildingfitter/FitAnything.java index 299f312..a7b7562 100644 --- a/src/main/java/com/magmaguy/betterstructures/buildingfitter/FitAnything.java +++ b/src/main/java/com/magmaguy/betterstructures/buildingfitter/FitAnything.java @@ -81,8 +81,8 @@ protected void setSchematicFilename(Location location, GeneratorConfigFields.Str protected void paste(Location location) { BuildPlaceEvent buildPlaceEvent = new BuildPlaceEvent(this); - if (buildPlaceEvent.isCancelled()) return; Bukkit.getServer().getPluginManager().callEvent(buildPlaceEvent); + if (buildPlaceEvent.isCancelled()) return; FitAnything fitAnything = this; //Set pedestal material before the paste so bedrock blocks get replaced correctly From 86a76a2a90b704bccedc7454de00728020c4a3bc Mon Sep 17 00:00:00 2001 From: BuildTools Date: Tue, 9 May 2023 22:50:04 +0100 Subject: [PATCH 24/39] Version 1.5.0 - [New] Merging from CarmJos, adding MythicMobs and MMOItems compatibility! --- build.gradle | 4 ++-- .../betterstructures/schematics/SchematicContainer.java | 5 ++++- src/main/resources/plugin.yml | 2 +- 3 files changed, 7 insertions(+), 4 deletions(-) diff --git a/build.gradle b/build.gradle index 1c4a798..9a91f8a 100644 --- a/build.gradle +++ b/build.gradle @@ -6,7 +6,7 @@ plugins { } group = 'com.magmaguy' -version = '1.4.2-SNAPSHOT' +version = '1.5.0-SNAPSHOT' repositories { mavenCentral() @@ -69,7 +69,7 @@ dependencies { //MythicMobs compileOnly group: 'io.lumine', name: 'Mythic-Dist', version: '5.2.1' //MythicLib - compileOnly group: 'io.lumine', name: 'MythicLib-dist', version: '1.5.1-SNAPSHOT' + 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 diff --git a/src/main/java/com/magmaguy/betterstructures/schematics/SchematicContainer.java b/src/main/java/com/magmaguy/betterstructures/schematics/SchematicContainer.java index 39bb03a..5818ede 100644 --- a/src/main/java/com/magmaguy/betterstructures/schematics/SchematicContainer.java +++ b/src/main/java/com/magmaguy/betterstructures/schematics/SchematicContainer.java @@ -7,6 +7,7 @@ import com.magmaguy.betterstructures.config.treasures.TreasureConfig; import com.magmaguy.betterstructures.config.treasures.TreasureConfigFields; import com.magmaguy.betterstructures.util.WarningMessage; +import com.magmaguy.elitemobs.utils.Developer; import com.sk89q.worldedit.bukkit.BukkitAdapter; import com.sk89q.worldedit.extent.clipboard.Clipboard; import com.sk89q.worldedit.math.BlockVector3; @@ -115,9 +116,11 @@ public SchematicContainer(Clipboard clipboard, String clipboardFilename, Schemat vanillaSpawns.put(new Vector(x, y, z), entityType); } else if (line1.toLowerCase().contains("[elitemobs]")) { String filename = ""; - for (int i = 2; i < 5; i++) + for (int i = 2; i < 5; i++) { + Developer.message("Raw text: " + baseBlock.getNbtData().getString("Text" + i)); filename += baseBlock.getNbtData().getString("Text" + i) .split(":")[1].replace("\"", "").replace("}", ""); + } eliteMobsSpawns.put(new Vector(x, y, z), filename); }else if (line1.toLowerCase().contains("[mythicmobs]")) { // carm start - Support MythicMobs String mob = baseBlock.getNbtData().getString("Text2").split(":")[1].replace("\"", "").replace("}", ""); diff --git a/src/main/resources/plugin.yml b/src/main/resources/plugin.yml index a6af51b..bb3e332 100644 --- a/src/main/resources/plugin.yml +++ b/src/main/resources/plugin.yml @@ -1,5 +1,5 @@ name: BetterStructures -version: '1.4.2' +version: '1.5.0' main: com.magmaguy.betterstructures.BetterStructures api-version: 1.14 depend: [ WorldEdit ] From f26063a20aabd7c4806889e995b9cae19c89ee16 Mon Sep 17 00:00:00 2001 From: BuildTools Date: Mon, 15 May 2023 03:22:00 +0100 Subject: [PATCH 25/39] Version 1.5.1 - [New] Added adequate warnings and safeguards when trying to use elitemobs or mythicmobs builds without having those plugins installed. - [Fix] Fixed forgotten debug message that was causing errors for people trying to run elitemobs builds without having elitemobs installed! --- build.gradle | 2 +- .../schematics/SchematicContainer.java | 43 +++++++++---------- src/main/resources/plugin.yml | 2 +- 3 files changed, 23 insertions(+), 24 deletions(-) diff --git a/build.gradle b/build.gradle index 9a91f8a..444703b 100644 --- a/build.gradle +++ b/build.gradle @@ -6,7 +6,7 @@ plugins { } group = 'com.magmaguy' -version = '1.5.0-SNAPSHOT' +version = '1.5.1-SNAPSHOT' repositories { mavenCentral() diff --git a/src/main/java/com/magmaguy/betterstructures/schematics/SchematicContainer.java b/src/main/java/com/magmaguy/betterstructures/schematics/SchematicContainer.java index 5818ede..4789b88 100644 --- a/src/main/java/com/magmaguy/betterstructures/schematics/SchematicContainer.java +++ b/src/main/java/com/magmaguy/betterstructures/schematics/SchematicContainer.java @@ -7,13 +7,13 @@ import com.magmaguy.betterstructures.config.treasures.TreasureConfig; import com.magmaguy.betterstructures.config.treasures.TreasureConfigFields; import com.magmaguy.betterstructures.util.WarningMessage; -import com.magmaguy.elitemobs.utils.Developer; 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; @@ -27,11 +27,6 @@ public class SchematicContainer { @Getter private static final ArrayListMultimap schematics = ArrayListMultimap.create(); - - public static void shutdown() { - schematics.clear(); - } - @Getter private final Clipboard clipboard; @Getter @@ -51,9 +46,11 @@ public static void shutdown() { @Getter private final HashMap mythicMobsSpawns = new HashMap<>(); // carm - Support for MythicMobs @Getter + List abstractBlocks = new ArrayList<>(); + @Getter private ChestContents chestContents = null; @Getter - List abstractBlocks = new ArrayList<>(); + private boolean valid = true; public SchematicContainer(Clipboard clipboard, String clipboardFilename, SchematicConfigField schematicConfigField, String configFilename) { this.clipboard = clipboard; @@ -61,10 +58,6 @@ 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; @@ -115,14 +108,25 @@ public SchematicContainer(Clipboard clipboard, String clipboardFilename, Schemat } vanillaSpawns.put(new Vector(x, y, z), entityType); } else if (line1.toLowerCase().contains("[elitemobs]")) { + 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++) { - Developer.message("Raw text: " + baseBlock.getNbtData().getString("Text" + i)); filename += baseBlock.getNbtData().getString("Text" + i) .split(":")[1].replace("\"", "").replace("}", ""); } eliteMobsSpawns.put(new Vector(x, y, z), filename); - }else if (line1.toLowerCase().contains("[mythicmobs]")) { // carm start - Support MythicMobs + } 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 = baseBlock.getNbtData().getString("Text2").split(":")[1].replace("\"", "").replace("}", ""); String level = baseBlock.getNbtData().getString("Text3").split(":")[1].replace("\"", "").replace("}", ""); mythicMobsSpawns.put(new Vector(x, y, z), mob + (level.isEmpty() ? "" : ":" + level)); @@ -138,19 +142,14 @@ public SchematicContainer(Clipboard clipboard, String clipboardFilename, Schemat } chestContents = schematicConfigField.getChestContents(); } + if (valid) + generatorConfigFields.getStructureTypes().forEach(structureType -> schematics.put(structureType, this)); } - /* todo: coming soon - private void initializeAbstractBlocks() { - BlockVector3 dimensions = clipboard.getDimensions(); - for (int x = 0; x < dimensions.getX(); x++) - for (int y = 0; y < dimensions.getY(); y++) - for (int z = 0; z < dimensions.getZ(); z++) - new AbstractBlock(clipboard.getFullBlock().toBaseBlock().applyBlock()) + public static void shutdown() { + schematics.clear(); } - */ - public boolean isValidEnvironment(World.Environment environment) { return generatorConfigFields.getValidWorldEnvironments() == null || generatorConfigFields.getValidWorldEnvironments().isEmpty() || diff --git a/src/main/resources/plugin.yml b/src/main/resources/plugin.yml index bb3e332..4caa834 100644 --- a/src/main/resources/plugin.yml +++ b/src/main/resources/plugin.yml @@ -1,5 +1,5 @@ name: BetterStructures -version: '1.5.0' +version: '1.5.1' main: com.magmaguy.betterstructures.BetterStructures api-version: 1.14 depend: [ WorldEdit ] From acc145e47d712ead60afcd5416270674e2979a86 Mon Sep 17 00:00:00 2001 From: BuildTools Date: Tue, 15 Aug 2023 18:50:03 +0100 Subject: [PATCH 26/39] Version 1.6.0 - [New] Official 1.20+ compatibility - [New] 101 premium shrines package has been updated to fix a number of issues reported by people - [New] Complete loot system remake based on feedback! - Now using gaussian distribution to guarantee a consistent amount of items in chests (usually around 5) - Now using rarity tables to categorize how rare items should be and weights to pick how rare items are within those tables - Added a customizable system which randomized enchantments for items that appear in the chests - Completely remade loot tables themselves, cut content that people found boring or uninteresting and generally increased the quality and quantity of items players can find - Added items from 1.18, 1.19 and 1.20 to the loot tables - Improved theming of loot based on environment (overground, underground, nether, end) - [New] Made it so by default custom biomes get populated by all relevant generators, skipping the need for admins running custom world generators to do this in their servers - [New] Metrics are now actually working - [Fix] Fixed info messages --- build.gradle | 4 +- .../betterstructures/BetterStructures.java | 9 +- .../chests/ChestContents.java | 220 ++-- .../betterstructures/chests/ChestEntry.java | 40 +- .../commands/CommandHandler.java | 21 +- .../config/CustomConfigFields.java | 19 +- .../premade/GeneratorSkyBarrenConfig.java | 3 +- .../GeneratorSkyCrimsonForestConfig.java | 4 +- .../premade/GeneratorSkyDesertConfig.java | 3 +- .../premade/GeneratorSkyGrasslandConfig.java | 3 +- .../GeneratorSkyNetherWastesConfig.java | 4 +- .../premade/GeneratorSkySnowyConfig.java | 3 +- .../premade/GeneratorSkySoulSandConfig.java | 4 +- .../GeneratorSkyWarpedForestConfig.java | 4 +- .../premade/GeneratorSurfaceBarrenConfig.java | 3 +- .../premade/GeneratorSurfaceDesertConfig.java | 3 +- .../GeneratorSurfaceGrasslandConfig.java | 3 +- .../premade/GeneratorSurfaceSnowyConfig.java | 3 +- .../GeneratorUndergroundDripstoneConfig.java | 4 +- .../GeneratorUndergroundLushConfig.java | 4 +- .../UndergroundGeneratorGlobalConfig.java | 1 + .../treasures/TreasureConfigFields.java | 98 +- .../premade/NetherTreasureConfig.java | 1 + .../util/DefaultChestContents.java | 1044 +++++++++++++---- .../betterstructures/util/InfoMessage.java | 2 +- .../betterstructures/util/VersionChecker.java | 28 + src/main/resources/plugin.yml | 2 +- 27 files changed, 1188 insertions(+), 349 deletions(-) diff --git a/build.gradle b/build.gradle index 444703b..74aa6c5 100644 --- a/build.gradle +++ b/build.gradle @@ -6,7 +6,7 @@ plugins { } group = 'com.magmaguy' -version = '1.5.1-SNAPSHOT' +version = '1.6.0-SNAPSHOT' repositories { mavenCentral() @@ -39,7 +39,7 @@ repositories { } dependencies { - compileOnly 'org.spigotmc:spigot-api:1.19-R0.1-SNAPSHOT' + compileOnly 'org.spigotmc:spigot-api:1.20-R0.1-SNAPSHOT' //BStats API implementation group: 'org.bstats', name: 'bstats-bukkit', version: '2.2.1' //WorldGuard API diff --git a/src/main/java/com/magmaguy/betterstructures/BetterStructures.java b/src/main/java/com/magmaguy/betterstructures/BetterStructures.java index 6f822fb..3c13be7 100644 --- a/src/main/java/com/magmaguy/betterstructures/BetterStructures.java +++ b/src/main/java/com/magmaguy/betterstructures/BetterStructures.java @@ -12,6 +12,7 @@ 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; @@ -22,8 +23,13 @@ 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); @@ -45,6 +51,7 @@ public void onEnable() { if (Bukkit.getPluginManager().getPlugin("WorldGuard") != null && Bukkit.getPluginManager().getPlugin("EliteMobs") != null) Bukkit.getPluginManager().registerEvents(new WorldGuard(), this); + new Metrics(this, 19523); } @Override diff --git a/src/main/java/com/magmaguy/betterstructures/chests/ChestContents.java b/src/main/java/com/magmaguy/betterstructures/chests/ChestContents.java index 8040f20..1d1ffa1 100644 --- a/src/main/java/com/magmaguy/betterstructures/chests/ChestContents.java +++ b/src/main/java/com/magmaguy/betterstructures/chests/ChestContents.java @@ -3,125 +3,181 @@ 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 net.Indyuce.mmoitems.MMOItems; import net.Indyuce.mmoitems.api.item.mmoitem.MMOItem; -import org.bukkit.Bukkit; import org.bukkit.Material; 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(TreasureConfigFields treasureConfigFields) { + this.treasureConfigFields = treasureConfigFields; if (treasureConfigFields.getRawLoot() == null) return; - if (!processEntries(treasureConfigFields.getRawLoot())) - new WarningMessage("Treasure file " + treasureConfigFields.getFilename() + " has invalid treasure entries!"); + processRarities(treasureConfigFields.getRawLoot()); } - private boolean processEntries(List rawChestEntries) { - boolean noProblems = true; - for (String string : rawChestEntries) { - String[] sections = string.split(":"); + 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(String string) { + try { + return ItemStackSerialization.itemStackArrayFromBase64(string.replace("serialized=", "")); + } 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! Problematic entry: " + subsection[0]); - noProblems = false; - } - break; - case "serialized": - try { - itemStack = ItemStackSerialization.itemStackArrayFromBase64(section.replace("serialized=", "")); - } catch (Exception ex) { - new WarningMessage("Invalid serialized value detected! Problematic entry: " + subsection[0]); - ex.printStackTrace(); - noProblems = false; - } - break; - case "mmoitem": // carm start - Support for MMOItems - case "mmoitems": - if (Bukkit.getPluginManager().getPlugin("MMOItems") == null) { - new WarningMessage("MMOItems plugin not found! Problematic entry: " + subsection[0]); - noProblems = false; - break; - } - try { - String[] args = subsection[1].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"); - itemStack = mmoitem.newBuilder().build(); - } catch (Exception ex) { - new WarningMessage("Invalid mmo item detected! Problematic entry: " + subsection[0]); - noProblems = false; - } - break; - // carm end - Support for MMOItems - 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! Problematic entry: " + subsection[0]); - noProblems = false; - } - break; - case "chance": - try { - chance = Double.parseDouble(subsection[1]); - } catch (Exception exception) { - new WarningMessage("Invalid chance detected! Problematic entry: " + subsection[0]); - noProblems = false; + new WarningMessage("Invalid amount detected! Problematic entry: " + value + " in file " + treasureConfigFields.getFilename()); } - break; - case "info": - //This is purely visual, helps document serialized entries! - break; - default: { - new WarningMessage("Failed to parse chest entry! Problematic entry: " + subsection[0]); - noProblems = false; } + case "weight" -> weight = getWeight(value); + //Support for MMOItems - og code by Carm + case "mmoitem", "mmoitems" -> itemStack = getMMOItemsItemStack(value); + case "serialized" -> itemStack = getSerializedItemStack(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 noProblems; + return chestEntries; } public void rollChestContents(Container chest) { - for (ChestEntry chestEntry : chestEntries) { - ItemStack itemStack = chestEntry.rollEntry(); - if (itemStack == null) continue; - chest.getSnapshotInventory().addItem(itemStack); + 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) chest.getSnapshotInventory().addItem(itemStack); + } + } + + 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 7af7b8d..e94e071 100644 --- a/src/main/java/com/magmaguy/betterstructures/chests/ChestEntry.java +++ b/src/main/java/com/magmaguy/betterstructures/chests/ChestEntry.java @@ -1,32 +1,52 @@ package com.magmaguy.betterstructures.chests; +import com.magmaguy.betterstructures.config.treasures.TreasureConfigFields; +import lombok.Getter; import org.bukkit.Material; +import org.bukkit.enchantments.Enchantment; 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 b6c8f85..753fd1f 100644 --- a/src/main/java/com/magmaguy/betterstructures/commands/CommandHandler.java +++ b/src/main/java/com/magmaguy/betterstructures/commands/CommandHandler.java @@ -31,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; @@ -141,13 +143,15 @@ public void constructCommands() { .argument(StringArgument.newBuilder("generator") .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")) .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("chance"), (Player) commandContext.getSender()); })); manager.command(builder.literal("teleporttocoords") @@ -217,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) { + private void lootify(String generator, String rarity, String minAmount, String maxAmount, String chance, 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); @@ -268,7 +277,11 @@ else if (itemStack.hasItemMeta() && itemStack.getItemMeta().hasLocalizedName()) info = itemStack.getItemMeta().getLocalizedName(); else info = itemStack.getType().toString(); - String configString = "serialized=" + ItemStackSerialization.toBase64(itemStack) + ":amount=" + minAmount + "-" + maxAmount + ":chance=" + chance + ":info=" + info; - treasureConfigFields.addChestEntry(configString, player); + Map configMap = new HashMap<>(); + configMap.put("serialized", ItemStackSerialization.toBase64(itemStack)); + configMap.put("amount", minAmount +"-"+maxAmount); + configMap.put("weight", chanceDouble); + configMap.put("info", info); + treasureConfigFields.addChestEntry(configMap, rarity, player); } } diff --git a/src/main/java/com/magmaguy/betterstructures/config/CustomConfigFields.java b/src/main/java/com/magmaguy/betterstructures/config/CustomConfigFields.java index daba911..b32de59 100644 --- a/src/main/java/com/magmaguy/betterstructures/config/CustomConfigFields.java +++ b/src/main/java/com/magmaguy/betterstructures/config/CustomConfigFields.java @@ -5,15 +5,14 @@ import com.magmaguy.betterstructures.util.WarningMessage; import org.bukkit.Bukkit; import org.bukkit.World; +import org.bukkit.configuration.ConfigurationSection; import org.bukkit.configuration.file.FileConfiguration; import org.bukkit.inventory.ItemStack; 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.io.IOException; +import java.util.*; public class CustomConfigFields implements CustomConfigFieldsInterface { @@ -260,7 +259,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 +272,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/generators/premade/GeneratorSkyBarrenConfig.java b/src/main/java/com/magmaguy/betterstructures/config/generators/premade/GeneratorSkyBarrenConfig.java index 01371b2..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 @@ -13,7 +13,8 @@ public GeneratorSkyBarrenConfig(){ Biome.SAVANNA, Biome.SAVANNA_PLATEAU, Biome.WINDSWEPT_SAVANNA, - Biome.MUSHROOM_FIELDS + Biome.MUSHROOM_FIELDS, + Biome.CUSTOM )); 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 2dc4965..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 @@ -8,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)); + 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 afba027..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 @@ -9,7 +9,8 @@ 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 )); 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 d64f106..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 @@ -22,7 +22,8 @@ public GeneratorSkyGrasslandConfig(){ Biome.OLD_GROWTH_BIRCH_FOREST, Biome.SUNFLOWER_PLAINS, Biome.WINDSWEPT_FOREST, - Biome.WINDSWEPT_HILLS + Biome.WINDSWEPT_HILLS, + Biome.CUSTOM )); setTreasureFilename("treasure_overworld_surface.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 2383c2a..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 @@ -8,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)); + 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 58581be..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 @@ -13,7 +13,8 @@ public GeneratorSkySnowyConfig(){ Biome.SNOWY_BEACH, Biome.SNOWY_PLAINS, Biome.SNOWY_SLOPES, - Biome.ICE_SPIKES + Biome.ICE_SPIKES, + Biome.CUSTOM )); 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 750a565..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 @@ -8,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)); + 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 96febd0..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 @@ -8,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)); + 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 a6567a0..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 @@ -13,7 +13,8 @@ public GeneratorSurfaceBarrenConfig(){ Biome.SAVANNA, Biome.SAVANNA_PLATEAU, Biome.WINDSWEPT_SAVANNA, - Biome.MUSHROOM_FIELDS + Biome.MUSHROOM_FIELDS, + Biome.CUSTOM )); 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 7842f5c..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 @@ -9,7 +9,8 @@ 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 )); 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 98d3770..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 @@ -22,7 +22,8 @@ public GeneratorSurfaceGrasslandConfig(){ Biome.OLD_GROWTH_BIRCH_FOREST, Biome.SUNFLOWER_PLAINS, Biome.WINDSWEPT_FOREST, - Biome.WINDSWEPT_HILLS + Biome.WINDSWEPT_HILLS, + Biome.CUSTOM )); setTreasureFilename("treasure_overworld_surface.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 e30cba2..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 @@ -13,7 +13,8 @@ public GeneratorSurfaceSnowyConfig() { Biome.SNOWY_BEACH, Biome.SNOWY_PLAINS, Biome.SNOWY_SLOPES, - Biome.ICE_SPIKES + Biome.ICE_SPIKES, + Biome.CUSTOM )); setTreasureFilename("treasure_overworld_surface.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 index 4dd5787..70360a6 100644 --- a/src/main/java/com/magmaguy/betterstructures/config/generators/premade/GeneratorUndergroundDripstoneConfig.java +++ b/src/main/java/com/magmaguy/betterstructures/config/generators/premade/GeneratorUndergroundDripstoneConfig.java @@ -9,7 +9,9 @@ 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)); + 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/GeneratorUndergroundLushConfig.java b/src/main/java/com/magmaguy/betterstructures/config/generators/premade/GeneratorUndergroundLushConfig.java index 6c91887..98d8be3 100644 --- a/src/main/java/com/magmaguy/betterstructures/config/generators/premade/GeneratorUndergroundLushConfig.java +++ b/src/main/java/com/magmaguy/betterstructures/config/generators/premade/GeneratorUndergroundLushConfig.java @@ -8,7 +8,9 @@ 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)); + 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/UndergroundGeneratorGlobalConfig.java b/src/main/java/com/magmaguy/betterstructures/config/generators/premade/UndergroundGeneratorGlobalConfig.java index 7262210..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 @@ -12,3 +12,4 @@ public UndergroundGeneratorGlobalConfig() { setTreasureFilename("treasure_overworld_underground.yml"); } } + diff --git a/src/main/java/com/magmaguy/betterstructures/config/treasures/TreasureConfigFields.java b/src/main/java/com/magmaguy/betterstructures/config/treasures/TreasureConfigFields.java index 59860b5..9a2d48c 100644 --- a/src/main/java/com/magmaguy/betterstructures/config/treasures/TreasureConfigFields.java +++ b/src/main/java/com/magmaguy/betterstructures/config/treasures/TreasureConfigFields.java @@ -3,21 +3,42 @@ 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.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<>(); + @Getter + @Setter + private Map rawLoot = new HashMap(); @Setter - private List rawLoot = new ArrayList<>(); + 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); @@ -26,13 +47,60 @@ public TreasureConfigFields(String filename, boolean isEnabled) { @Override public void processConfigFields() { this.isEnabled = processBoolean("isEnabled", isEnabled, true, true); - this.rawLoot = processStringList("loot", rawLoot, new ArrayList<>(), 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(); } - public void addChestEntry(String entry, Player player) { - rawLoot.add(entry); - fileConfiguration.set("loot", rawLoot); + 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) { + new WarningMessage("Failed to get valid enchantment from key " + enchantmentsEntry.getKey() + " in configuration file " + filename); + 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 + "items", mapList); + HashMap map = new HashMap(); + map.put("items", mapList); + fileConfiguration.createSection("items." + rarity, map); try { fileConfiguration.save(file); } catch (Exception ex) { @@ -44,4 +112,24 @@ public void addChestEntry(String entry, Player player) { 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); + itemMeta.addEnchant(enchantment, level, true); + } + } } 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 index 9d0aaaa..8bebdad 100644 --- a/src/main/java/com/magmaguy/betterstructures/config/treasures/premade/NetherTreasureConfig.java +++ b/src/main/java/com/magmaguy/betterstructures/config/treasures/premade/NetherTreasureConfig.java @@ -1,5 +1,6 @@ package com.magmaguy.betterstructures.config.treasures.premade; +import com.magmaguy.betterstructures.config.DefaultConfig; import com.magmaguy.betterstructures.config.treasures.TreasureConfigFields; import com.magmaguy.betterstructures.util.DefaultChestContents; diff --git a/src/main/java/com/magmaguy/betterstructures/util/DefaultChestContents.java b/src/main/java/com/magmaguy/betterstructures/util/DefaultChestContents.java index 3088d09..18ebe05 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.configuration.file.FileConfiguration; +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 { - public static double normalChance = 0.02; - public static double lowChance = 0.01; - public 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(1, 20)) + 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(1, 19)) + 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(1, 18)) + 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)); + 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; } - public 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 index f14ce76..ac602b6 100644 --- a/src/main/java/com/magmaguy/betterstructures/util/InfoMessage.java +++ b/src/main/java/com/magmaguy/betterstructures/util/InfoMessage.java @@ -4,6 +4,6 @@ public class InfoMessage { public InfoMessage(String message) { - Bukkit.getLogger().info("[EliteMobs] " + message); + Bukkit.getLogger().info("[BetterStructures] " + message); } } diff --git a/src/main/java/com/magmaguy/betterstructures/util/VersionChecker.java b/src/main/java/com/magmaguy/betterstructures/util/VersionChecker.java index 2bc7db9..e7f0b8f 100644 --- a/src/main/java/com/magmaguy/betterstructures/util/VersionChecker.java +++ b/src/main/java/com/magmaguy/betterstructures/util/VersionChecker.java @@ -66,6 +66,34 @@ public void run() { }.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(), diff --git a/src/main/resources/plugin.yml b/src/main/resources/plugin.yml index 4caa834..320c43e 100644 --- a/src/main/resources/plugin.yml +++ b/src/main/resources/plugin.yml @@ -1,5 +1,5 @@ name: BetterStructures -version: '1.5.1' +version: '1.6.0' main: com.magmaguy.betterstructures.BetterStructures api-version: 1.14 depend: [ WorldEdit ] From ab0485e8496c47e1a95572e27acd151794049aaa Mon Sep 17 00:00:00 2001 From: BuildTools Date: Fri, 18 Aug 2023 16:15:15 +0100 Subject: [PATCH 27/39] Version 1.6.1 - [Fix] Fixed issue where the plugin would generate materials not compatible with older MC versions, now only generates adequate content for each version --- build.gradle | 2 +- .../betterstructures/util/DefaultChestContents.java | 6 +++--- src/main/resources/plugin.yml | 2 +- 3 files changed, 5 insertions(+), 5 deletions(-) diff --git a/build.gradle b/build.gradle index 74aa6c5..f3aabbd 100644 --- a/build.gradle +++ b/build.gradle @@ -6,7 +6,7 @@ plugins { } group = 'com.magmaguy' -version = '1.6.0-SNAPSHOT' +version = '1.6.1-SNAPSHOT' repositories { mavenCentral() diff --git a/src/main/java/com/magmaguy/betterstructures/util/DefaultChestContents.java b/src/main/java/com/magmaguy/betterstructures/util/DefaultChestContents.java index 18ebe05..940a831 100644 --- a/src/main/java/com/magmaguy/betterstructures/util/DefaultChestContents.java +++ b/src/main/java/com/magmaguy/betterstructures/util/DefaultChestContents.java @@ -39,7 +39,7 @@ public static Map overworldContents() { 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(1, 20)) + 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)); @@ -89,7 +89,7 @@ public static Map overworldContents() { 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(1, 19)) + 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)); @@ -99,7 +99,7 @@ public static Map overworldContents() { 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(1, 18)) + 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)); diff --git a/src/main/resources/plugin.yml b/src/main/resources/plugin.yml index 320c43e..e0d8e60 100644 --- a/src/main/resources/plugin.yml +++ b/src/main/resources/plugin.yml @@ -1,5 +1,5 @@ name: BetterStructures -version: '1.6.0' +version: '1.6.1' main: com.magmaguy.betterstructures.BetterStructures api-version: 1.14 depend: [ WorldEdit ] From 990e5c4c5206d729fc0f1495a7778a5aa6e80828 Mon Sep 17 00:00:00 2001 From: BuildTools Date: Sun, 20 Aug 2023 17:20:13 +0100 Subject: [PATCH 28/39] Version 1.6.2 - [Fix] Fixed loot table for versions older than 1.19 --- build.gradle | 2 +- .../magmaguy/betterstructures/util/DefaultChestContents.java | 3 ++- src/main/resources/plugin.yml | 2 +- 3 files changed, 4 insertions(+), 3 deletions(-) diff --git a/build.gradle b/build.gradle index f3aabbd..f9e8620 100644 --- a/build.gradle +++ b/build.gradle @@ -6,7 +6,7 @@ plugins { } group = 'com.magmaguy' -version = '1.6.1-SNAPSHOT' +version = '1.6.2-SNAPSHOT' repositories { mavenCentral() diff --git a/src/main/java/com/magmaguy/betterstructures/util/DefaultChestContents.java b/src/main/java/com/magmaguy/betterstructures/util/DefaultChestContents.java index 940a831..51e41a3 100644 --- a/src/main/java/com/magmaguy/betterstructures/util/DefaultChestContents.java +++ b/src/main/java/com/magmaguy/betterstructures/util/DefaultChestContents.java @@ -343,7 +343,8 @@ public static Map overworldUndergroundContents() { 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)); - epicList.add(generateEntry(Material.SCULK, 1, 6, normalWeight)); //1.19 + 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)); diff --git a/src/main/resources/plugin.yml b/src/main/resources/plugin.yml index e0d8e60..b9fb1df 100644 --- a/src/main/resources/plugin.yml +++ b/src/main/resources/plugin.yml @@ -1,5 +1,5 @@ name: BetterStructures -version: '1.6.1' +version: '1.6.2' main: com.magmaguy.betterstructures.BetterStructures api-version: 1.14 depend: [ WorldEdit ] From ee4a998588e2925faa33b5e72b97b1bf4f4d141b Mon Sep 17 00:00:00 2001 From: BuildTools Date: Thu, 21 Sep 2023 13:15:20 +0100 Subject: [PATCH 29/39] Version 1.6.3 - [New] Contents in chests are now placed randomly in chests - [Fix] Fixed issue where the valid worlds setting for the generators was not working - [Fix] Fixed issue where spawn signs weren't working - [Fix] Fixed issue where lootify was removing loot table weights --- build.gradle | 5 +- .../buildingfitter/FitAnything.java | 18 +++-- .../buildingfitter/util/SchematicPicker.java | 3 +- .../chests/ChestContents.java | 12 +++- .../config/generators/GeneratorConfig.java | 1 - .../generators/GeneratorConfigFields.java | 4 +- .../treasures/TreasureConfigFields.java | 13 +++- .../schematics/SchematicContainer.java | 70 +++++++++++++++---- src/main/resources/plugin.yml | 2 +- 9 files changed, 95 insertions(+), 33 deletions(-) diff --git a/build.gradle b/build.gradle index f9e8620..7fcfa1f 100644 --- a/build.gradle +++ b/build.gradle @@ -6,7 +6,7 @@ plugins { } group = 'com.magmaguy' -version = '1.6.2-SNAPSHOT' +version = '1.6.3-SNAPSHOT' repositories { mavenCentral() @@ -45,7 +45,7 @@ dependencies { //WorldGuard API 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.13' + 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' @@ -64,7 +64,6 @@ dependencies { //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' diff --git a/src/main/java/com/magmaguy/betterstructures/buildingfitter/FitAnything.java b/src/main/java/com/magmaguy/betterstructures/buildingfitter/FitAnything.java index a7b7562..2cda66f 100644 --- a/src/main/java/com/magmaguy/betterstructures/buildingfitter/FitAnything.java +++ b/src/main/java/com/magmaguy/betterstructures/buildingfitter/FitAnything.java @@ -37,11 +37,12 @@ import java.util.Set; public class FitAnything { + public static boolean worldGuardWarn = false; + protected final int searchRadius = 1; + protected final int scanStep = 3; @Getter protected SchematicContainer schematicContainer; protected double startingScore = 100; - protected final int searchRadius = 1; - protected final int scanStep = 3; protected Clipboard schematicClipboard = null; protected Vector schematicOffset; //At 10% it is assumed a fit is so bad it's better just to skip @@ -49,6 +50,7 @@ public class FitAnything { @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) { @@ -78,7 +80,6 @@ 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); @@ -152,7 +153,6 @@ protected void paste(Location location) { } } - Schematic.paste(schematicClipboard, location); if (DefaultConfig.isNewBuildingWarn()) { String structureTypeString = fitAnything.structureType.toString().toLowerCase().replace("_", " "); @@ -210,8 +210,6 @@ protected void paste(Location location) { } - Material pedestalMaterial = null; - private void assignPedestalMaterial(Location location) { if (this instanceof FitAirBuilding) return; pedestalMaterial = schematicContainer.getSchematicConfigField().getPedestalMaterial(); @@ -262,7 +260,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; @@ -284,7 +281,10 @@ private void fillChests() { if (schematicContainer.getGeneratorConfigFields().getChestContents() != null) for (Vector chestPosition : schematicContainer.getChestLocations()) { Location chestLocation = LocationProjector.project(location, schematicOffset, chestPosition); - Container container = (Container) chestLocation.getBlock().getState(); + 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); @@ -348,6 +348,4 @@ private void spawnEntities() { // carm end - Support for MythicMobs } - - public static boolean worldGuardWarn = false; } 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 fdf7482..3ceeed3 100644 --- a/src/main/java/com/magmaguy/betterstructures/buildingfitter/util/SchematicPicker.java +++ b/src/main/java/com/magmaguy/betterstructures/buildingfitter/util/SchematicPicker.java @@ -14,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 1d1ffa1..ba4ad10 100644 --- a/src/main/java/com/magmaguy/betterstructures/chests/ChestContents.java +++ b/src/main/java/com/magmaguy/betterstructures/chests/ChestContents.java @@ -160,7 +160,17 @@ public void rollChestContents(Container chest) { for (int i = 0; i < amount; i++) { ItemStack itemStack = chestRarities.get(WeighedProbability.pickWeighedProbability(weightsMap)).rollLoot(); - if (itemStack != null) chest.getSnapshotInventory().addItem(itemStack); + 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++; + } + } } } 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 3a4fbd6..ff72ed2 100644 --- a/src/main/java/com/magmaguy/betterstructures/config/generators/GeneratorConfig.java +++ b/src/main/java/com/magmaguy/betterstructures/config/generators/GeneratorConfig.java @@ -1,7 +1,6 @@ package com.magmaguy.betterstructures.config.generators; import com.magmaguy.betterstructures.config.CustomConfig; -import com.magmaguy.elitemobs.utils.Developer; import lombok.Getter; 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 9b14d8d..403ea8d 100644 --- a/src/main/java/com/magmaguy/betterstructures/config/generators/GeneratorConfigFields.java +++ b/src/main/java/com/magmaguy/betterstructures/config/generators/GeneratorConfigFields.java @@ -36,7 +36,7 @@ public enum StructureType { private int highestYLevel = 320; @Getter @Setter - private List validWorlds = null; + private List validWorlds = null; @Getter @Setter private List validWorldEnvironments = null; @@ -71,7 +71,7 @@ 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.treasureFilename = processString("treasureFilename", treasureFilename, null, false); diff --git a/src/main/java/com/magmaguy/betterstructures/config/treasures/TreasureConfigFields.java b/src/main/java/com/magmaguy/betterstructures/config/treasures/TreasureConfigFields.java index 9a2d48c..96047d0 100644 --- a/src/main/java/com/magmaguy/betterstructures/config/treasures/TreasureConfigFields.java +++ b/src/main/java/com/magmaguy/betterstructures/config/treasures/TreasureConfigFields.java @@ -4,6 +4,7 @@ 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; @@ -39,6 +40,7 @@ public class TreasureConfigFields extends CustomConfigFields { @Getter @Setter private double standardDeviation = 3; + private final List seenInvalidKeys = new ArrayList<>(); public TreasureConfigFields(String filename, boolean isEnabled) { super(filename, isEnabled); @@ -66,8 +68,14 @@ private void parseEnchantmentSettings() { Map enchantments = ((MemorySection) stringObjectEntry.getValue()).getValues(false); for (Map.Entry enchantmentsEntry : enchantments.entrySet()) { Enchantment enchantment = Enchantment.getByKey(NamespacedKey.minecraft(enchantmentsEntry.getKey())); - if (enchantment == null) { - new WarningMessage("Failed to get valid enchantment from key " + enchantmentsEntry.getKey() + " in configuration file " + filename); + 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; @@ -101,6 +109,7 @@ public void addChestEntry(Map entry, String rarity, Player playe HashMap map = new HashMap(); map.put("items", mapList); fileConfiguration.createSection("items." + rarity, map); + fileConfiguration.set("items." + rarity, Map.of("weight", ((ConfigurationSection) rawLoot.get(rarity)).getDouble("weight"))); try { fileConfiguration.save(file); } catch (Exception ex) { diff --git a/src/main/java/com/magmaguy/betterstructures/schematics/SchematicContainer.java b/src/main/java/com/magmaguy/betterstructures/schematics/SchematicContainer.java index 4789b88..ade499f 100644 --- a/src/main/java/com/magmaguy/betterstructures/schematics/SchematicContainer.java +++ b/src/main/java/com/magmaguy/betterstructures/schematics/SchematicContainer.java @@ -7,6 +7,7 @@ import com.magmaguy.betterstructures.config.treasures.TreasureConfig; import com.magmaguy.betterstructures.config.treasures.TreasureConfigFields; import com.magmaguy.betterstructures.util.WarningMessage; +import com.sk89q.jnbt.ListTag; import com.sk89q.worldedit.bukkit.BukkitAdapter; import com.sk89q.worldedit.extent.clipboard.Clipboard; import com.sk89q.worldedit.math.BlockVector3; @@ -23,6 +24,7 @@ import java.util.ArrayList; import java.util.HashMap; import java.util.List; +import java.util.Map; public class SchematicContainer { @Getter @@ -93,17 +95,16 @@ public SchematicContainer(Clipboard clipboard, String clipboardFilename, Schemat minecraftMaterial.equals(Material.WARPED_WALL_SIGN)) { 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 = 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 = getLine(baseBlock, 2).toUpperCase(); 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); @@ -115,10 +116,7 @@ public SchematicContainer(Clipboard clipboard, String clipboardFilename, Schemat return; } String filename = ""; - for (int i = 2; i < 5; i++) { - filename += baseBlock.getNbtData().getString("Text" + i) - .split(":")[1].replace("\"", "").replace("}", ""); - } + for (int i = 2; i < 5; i++) filename += 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) { @@ -127,8 +125,8 @@ public SchematicContainer(Clipboard clipboard, String clipboardFilename, Schemat valid = false; return; } - String mob = baseBlock.getNbtData().getString("Text2").split(":")[1].replace("\"", "").replace("}", ""); - String level = baseBlock.getNbtData().getString("Text3").split(":")[1].replace("\"", "").replace("}", ""); + String mob = getLine(baseBlock, 2); + String level = getLine(baseBlock, 3); mythicMobsSpawns.put(new Vector(x, y, z), mob + (level.isEmpty() ? "" : ":" + level)); } // carm end - Support MythicMobs } @@ -146,6 +144,48 @@ public SchematicContainer(Clipboard clipboard, String clipboardFilename, Schemat generatorConfigFields.getStructureTypes().forEach(structureType -> schematics.put(structureType, this)); } + /** + * As of Minecraft 1.20 Minecraft / WorldEdit have changed the format for the signs. This just bruteforces it. + * + * @param line + * @return + */ + private static String getLine(BaseBlock baseBlock, int line) { + String finalLine = ""; + try { + finalLine = cleanLine(baseBlock.getNbtData().getString("Text" + line)); + } catch (Exception e) { + //meh + } + if (!finalLine.isEmpty()) return finalLine; + + try { + finalLine = cleanLine(((ListTag) ((Map) baseBlock.getNbtData().getValue().get("front_text").getValue()).get("messages")).getString(line - 1)); + } catch (Exception e) { + //meh + } + if (!finalLine.isEmpty()) return finalLine; + + try { + finalLine = cleanLine(((ListTag) ((Map) baseBlock.getNbtData().getValue().get("back_text").getValue()).get("messages")).getString(line)); + } catch (Exception e) { + //meh + } + + return finalLine; + } + + /** + * Removes the JSON formatting + * + * @param jsonLine String to clean + * @return A value that can be read directly + */ + private static String cleanLine(String jsonLine) { + if (jsonLine.split(":").length < 2) return ""; + return jsonLine.split(":")[1].replace("\"", "").replace("}", ""); + } + public static void shutdown() { schematics.clear(); } @@ -165,4 +205,10 @@ public boolean isValidBiome(Biome 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/resources/plugin.yml b/src/main/resources/plugin.yml index b9fb1df..621f125 100644 --- a/src/main/resources/plugin.yml +++ b/src/main/resources/plugin.yml @@ -1,5 +1,5 @@ name: BetterStructures -version: '1.6.2' +version: '1.6.3' main: com.magmaguy.betterstructures.BetterStructures api-version: 1.14 depend: [ WorldEdit ] From 65ebafb5534e4793cbc5c9a5fe1647a0daa85f06 Mon Sep 17 00:00:00 2001 From: BuildTools Date: Tue, 28 Nov 2023 03:18:15 +0000 Subject: [PATCH 30/39] BetterStructures 1.6.4 changelog: - [New] Added a way to turn protecting EliteMobs-related structures off - [Fix] Fixed issue with the lootify command breaking loot tables - [Tweak] Lowered the spam of warning messages related to seen invalid enchantments --- build.gradle | 2 +- .../buildingfitter/FitAnything.java | 3 ++- .../commands/CommandHandler.java | 18 +++++++----------- .../betterstructures/config/DefaultConfig.java | 11 +++++------ .../config/treasures/TreasureConfigFields.java | 17 ++++------------- src/main/resources/plugin.yml | 2 +- 6 files changed, 20 insertions(+), 33 deletions(-) diff --git a/build.gradle b/build.gradle index 7fcfa1f..89c1623 100644 --- a/build.gradle +++ b/build.gradle @@ -6,7 +6,7 @@ plugins { } group = 'com.magmaguy' -version = '1.6.3-SNAPSHOT' +version = '1.6.4-SNAPSHOT' repositories { mavenCentral() diff --git a/src/main/java/com/magmaguy/betterstructures/buildingfitter/FitAnything.java b/src/main/java/com/magmaguy/betterstructures/buildingfitter/FitAnything.java index 2cda66f..ed3ecb4 100644 --- a/src/main/java/com/magmaguy/betterstructures/buildingfitter/FitAnything.java +++ b/src/main/java/com/magmaguy/betterstructures/buildingfitter/FitAnything.java @@ -323,7 +323,8 @@ private void spawnEntities() { 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 (Bukkit.getPluginManager().getPlugin("WorldGuard") != null && + if (DefaultConfig.isProtectEliteMobsRegions() && + Bukkit.getPluginManager().getPlugin("WorldGuard") != null && Bukkit.getPluginManager().getPlugin("EliteMobs") != null) { WorldGuard.Protect( BlockVector3.at(lowestCorner.getX(), lowestCorner.getY(), lowestCorner.getZ()), diff --git a/src/main/java/com/magmaguy/betterstructures/commands/CommandHandler.java b/src/main/java/com/magmaguy/betterstructures/commands/CommandHandler.java index 753fd1f..a8e7bed 100644 --- a/src/main/java/com/magmaguy/betterstructures/commands/CommandHandler.java +++ b/src/main/java/com/magmaguy/betterstructures/commands/CommandHandler.java @@ -148,10 +148,10 @@ public void constructCommands() { .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("rarity"),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") @@ -221,7 +221,7 @@ private void placeSchematic(String schematicFile, String schematicType, Player p } } - private void lootify(String generator, String rarity, String minAmount, String maxAmount, String chance, Player player) { + 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."); @@ -254,15 +254,11 @@ private void lootify(String generator, String rarity, String minAmount, String m 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(); @@ -280,7 +276,7 @@ else if (itemStack.hasItemMeta() && itemStack.getItemMeta().hasLocalizedName()) Map configMap = new HashMap<>(); configMap.put("serialized", ItemStackSerialization.toBase64(itemStack)); configMap.put("amount", minAmount +"-"+maxAmount); - configMap.put("weight", chanceDouble); + configMap.put("weight", weightDouble); configMap.put("info", info); treasureConfigFields.addChestEntry(configMap, rarity, player); } diff --git a/src/main/java/com/magmaguy/betterstructures/config/DefaultConfig.java b/src/main/java/com/magmaguy/betterstructures/config/DefaultConfig.java index dffcefb..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 @@ -43,10 +40,12 @@ private DefaultConfig() { 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 = ConfigurationEngine.fileCreator("config.yml"); @@ -68,7 +67,7 @@ public static void initializeConfig() { 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); } diff --git a/src/main/java/com/magmaguy/betterstructures/config/treasures/TreasureConfigFields.java b/src/main/java/com/magmaguy/betterstructures/config/treasures/TreasureConfigFields.java index 96047d0..0c4b86d 100644 --- a/src/main/java/com/magmaguy/betterstructures/config/treasures/TreasureConfigFields.java +++ b/src/main/java/com/magmaguy/betterstructures/config/treasures/TreasureConfigFields.java @@ -26,6 +26,7 @@ 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(); @@ -40,7 +41,6 @@ public class TreasureConfigFields extends CustomConfigFields { @Getter @Setter private double standardDeviation = 3; - private final List seenInvalidKeys = new ArrayList<>(); public TreasureConfigFields(String filename, boolean isEnabled) { super(filename, isEnabled); @@ -69,12 +69,7 @@ private void parseEnchantmentSettings() { 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."); + 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; } @@ -105,11 +100,7 @@ private void parseEnchantmentSettings() { public void addChestEntry(Map entry, String rarity, Player player) { List> mapList = ((ConfigurationSection) rawLoot.get(rarity)).getMapList("items"); mapList.add(entry); - //fileConfiguration.set("items." + rarity + "items", mapList); - HashMap map = new HashMap(); - map.put("items", mapList); - fileConfiguration.createSection("items." + rarity, map); - fileConfiguration.set("items." + rarity, Map.of("weight", ((ConfigurationSection) rawLoot.get(rarity)).getDouble("weight"))); + fileConfiguration.set("items." + rarity, Map.of("weight", ((ConfigurationSection) rawLoot.get(rarity)).getDouble("weight"), "items", mapList)); try { fileConfiguration.save(file); } catch (Exception ex) { @@ -138,7 +129,7 @@ public ConfigurationEnchantment(Enchantment enchantment, int minLevel, int maxLe public void rollEnchantment(ItemMeta itemMeta) { if (ThreadLocalRandom.current().nextDouble() >= chance) return; int level = ThreadLocalRandom.current().nextInt(minLevel, maxLevel + 1); - itemMeta.addEnchant(enchantment, level, true); + if (itemMeta != null && enchantment != null) itemMeta.addEnchant(enchantment, level, true); } } } diff --git a/src/main/resources/plugin.yml b/src/main/resources/plugin.yml index 621f125..2a722d1 100644 --- a/src/main/resources/plugin.yml +++ b/src/main/resources/plugin.yml @@ -1,5 +1,5 @@ name: BetterStructures -version: '1.6.3' +version: '1.6.4' main: com.magmaguy.betterstructures.BetterStructures api-version: 1.14 depend: [ WorldEdit ] From 9350b4615abaf933960b79a8dbf1b56171a32ed5 Mon Sep 17 00:00:00 2001 From: Nikita Ermilov Date: Wed, 17 Jan 2024 06:20:49 +0300 Subject: [PATCH 31/39] + fixed bug with mob spawning for signs from 1.20.4 --- .../schematics/SchematicContainer.java | 55 ++--------- .../betterstructures/util/WorldEditUtils.java | 94 +++++++++++++++++++ 2 files changed, 100 insertions(+), 49 deletions(-) diff --git a/src/main/java/com/magmaguy/betterstructures/schematics/SchematicContainer.java b/src/main/java/com/magmaguy/betterstructures/schematics/SchematicContainer.java index ade499f..9df96d0 100644 --- a/src/main/java/com/magmaguy/betterstructures/schematics/SchematicContainer.java +++ b/src/main/java/com/magmaguy/betterstructures/schematics/SchematicContainer.java @@ -7,7 +7,7 @@ import com.magmaguy.betterstructures.config.treasures.TreasureConfig; import com.magmaguy.betterstructures.config.treasures.TreasureConfigFields; import com.magmaguy.betterstructures.util.WarningMessage; -import com.sk89q.jnbt.ListTag; +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; @@ -24,7 +24,6 @@ import java.util.ArrayList; import java.util.HashMap; import java.util.List; -import java.util.Map; public class SchematicContainer { @Getter @@ -95,11 +94,11 @@ public SchematicContainer(Clipboard clipboard, String clipboardFilename, Schemat minecraftMaterial.equals(Material.WARPED_WALL_SIGN)) { 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 = getLine(baseBlock, 1); + String line1 = WorldEditUtils.getLine(baseBlock, 1); //Case for spawning a vanilla mob if (line1.toLowerCase().contains("[spawn]")) { - String line2 = getLine(baseBlock, 2).toUpperCase(); + String line2 = WorldEditUtils.getLine(baseBlock, 2).toUpperCase(); EntityType entityType; try { entityType = EntityType.valueOf(line2); @@ -116,7 +115,7 @@ public SchematicContainer(Clipboard clipboard, String clipboardFilename, Schemat return; } String filename = ""; - for (int i = 2; i < 5; i++) filename += getLine(baseBlock, i); + 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) { @@ -125,8 +124,8 @@ public SchematicContainer(Clipboard clipboard, String clipboardFilename, Schemat valid = false; return; } - String mob = getLine(baseBlock, 2); - String level = getLine(baseBlock, 3); + 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 } @@ -144,48 +143,6 @@ public SchematicContainer(Clipboard clipboard, String clipboardFilename, Schemat generatorConfigFields.getStructureTypes().forEach(structureType -> schematics.put(structureType, this)); } - /** - * As of Minecraft 1.20 Minecraft / WorldEdit have changed the format for the signs. This just bruteforces it. - * - * @param line - * @return - */ - private static String getLine(BaseBlock baseBlock, int line) { - String finalLine = ""; - try { - finalLine = cleanLine(baseBlock.getNbtData().getString("Text" + line)); - } catch (Exception e) { - //meh - } - if (!finalLine.isEmpty()) return finalLine; - - try { - finalLine = cleanLine(((ListTag) ((Map) baseBlock.getNbtData().getValue().get("front_text").getValue()).get("messages")).getString(line - 1)); - } catch (Exception e) { - //meh - } - if (!finalLine.isEmpty()) return finalLine; - - try { - finalLine = cleanLine(((ListTag) ((Map) baseBlock.getNbtData().getValue().get("back_text").getValue()).get("messages")).getString(line)); - } catch (Exception e) { - //meh - } - - return finalLine; - } - - /** - * Removes the JSON formatting - * - * @param jsonLine String to clean - * @return A value that can be read directly - */ - private static String cleanLine(String jsonLine) { - if (jsonLine.split(":").length < 2) return ""; - return jsonLine.split(":")[1].replace("\"", "").replace("}", ""); - } - public static void shutdown() { schematics.clear(); } diff --git a/src/main/java/com/magmaguy/betterstructures/util/WorldEditUtils.java b/src/main/java/com/magmaguy/betterstructures/util/WorldEditUtils.java index e64bdbb..5d38bb9 100644 --- a/src/main/java/com/magmaguy/betterstructures/util/WorldEditUtils.java +++ b/src/main/java/com/magmaguy/betterstructures/util/WorldEditUtils.java @@ -1,12 +1,106 @@ package com.magmaguy.betterstructures.util; +import com.sk89q.jnbt.CompoundTag; +import com.sk89q.jnbt.ListTag; import com.sk89q.worldedit.extent.clipboard.Clipboard; +import com.sk89q.worldedit.world.block.BaseBlock; +import org.bukkit.Bukkit; +import org.bukkit.plugin.Plugin; import org.bukkit.util.Vector; +import org.checkerframework.checker.index.qual.Positive; +import org.jetbrains.annotations.NotNull; + +import java.util.*; +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()); } + + /** + *

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

+ *

Compatibility with version 1.20.4 has been added.

+ */ + public static String getLine(@NotNull BaseBlock baseBlock, @Positive int line) { + values.clear(); + if (baseBlock.getNbtData() == null) { + return ""; + } + CompoundTag data = baseBlock.getNbtData(); + Optional fawe = Arrays.stream(Bukkit.getPluginManager().getPlugins()) + .filter(pl -> pl.getName().contains("FastAsyncWorldEdit")) + .findFirst(); + if (fawe.isPresent()) { + return getLineFawe(data, line); + } + return getLineWe(data, line); + } + + /** + *

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

+ *

Compatibility with version 1.20.4 has been added.

+ */ + private static String getLineWe(@NotNull CompoundTag data, @Positive int line) { + List lines = data.toString().lines().toList(); + + for (String s : lines) { + s = s.trim().replace("{\"text\":", "").replace("}", ""); // support for versions below 1.20.4 + + if (s.startsWith("TAG_String(\"") && !s.equals("TAG_String(\"\")")) { + values.add(s.replace("TAG_String(\"", "").replace("\")", "")); + } + } + // lines in versions below 1.20.4 duplicated twice + if (data.toString().contains("{\"text\":")) { + for (int i = (values.size() / 2); i != values.size();) { + if (values.size() == 2) break; + values.remove(i); + } + Collections.reverse(values); + } + + if (line <= values.size()) { + return values.get(line - 1); + } + return ""; + } + + /** + *

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

+ *

Compatibility with version 1.20.4 has been added.

+ */ + private static String getLineFawe(@NotNull CompoundTag data, @Positive int line) { + // 1.20.4 have a different format of NBT + String str = data.toString() + .replace("{\\\\\"text\\\\\":", "") + .replace("}", ""); + + Matcher matcher = Pattern.compile("value=\"\\\\\\\\\"(.*?)\\\\\\\\\"\"") + .matcher(str); + + while (values.size() < 2 && matcher.find()) { + String match = matcher.group(1); + if (match.isEmpty()) continue; + values.add(match); + } + // versions below 1.20.4 have reversed order of the lines (from 4 to 1) + if (data.toString().contains("{\\\\\"text\\\\\":")) { + Collections.reverse(values); + } + + if (line <= values.size()) { + return values.get(line - 1); + } + return ""; + } } From 0482fe59ff00c565dba7569fe2c09736559e0f37 Mon Sep 17 00:00:00 2001 From: BuildTools Date: Thu, 18 Jan 2024 08:38:51 +0000 Subject: [PATCH 32/39] BetterStructures 1.6.5 changelog: - Updated to work with schematics generated in 1.20.4 (thanks to contribution) - Exposing more API endpoints for developers (schematicClipboard and schematicOffset) - Added generateProtectedRegion(FitAnything fitAnything, String regionName) for easy API use by other developers --- build.gradle | 2 +- .../buildingfitter/FitAnything.java | 7 +++---- .../betterstructures/chests/ChestEntry.java | 1 - .../config/CustomConfigFields.java | 2 -- .../GeneratorUndergroundDripstoneConfig.java | 1 - .../premade/NetherTreasureConfig.java | 1 - .../thirdparty/WorldGuard.java | 19 +++++++++++++++++++ .../util/DefaultChestContents.java | 1 - .../betterstructures/util/WorldEditUtils.java | 13 +++++++------ src/main/resources/plugin.yml | 2 +- 10 files changed, 31 insertions(+), 18 deletions(-) diff --git a/build.gradle b/build.gradle index 89c1623..508427e 100644 --- a/build.gradle +++ b/build.gradle @@ -6,7 +6,7 @@ plugins { } group = 'com.magmaguy' -version = '1.6.4-SNAPSHOT' +version = '1.6.5-SNAPSHOT' repositories { mavenCentral() diff --git a/src/main/java/com/magmaguy/betterstructures/buildingfitter/FitAnything.java b/src/main/java/com/magmaguy/betterstructures/buildingfitter/FitAnything.java index ed3ecb4..e138acc 100644 --- a/src/main/java/com/magmaguy/betterstructures/buildingfitter/FitAnything.java +++ b/src/main/java/com/magmaguy/betterstructures/buildingfitter/FitAnything.java @@ -43,7 +43,9 @@ public class FitAnything { @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; @@ -326,10 +328,7 @@ private void spawnEntities() { if (DefaultConfig.isProtectEliteMobsRegions() && Bukkit.getPluginManager().getPlugin("WorldGuard") != null && Bukkit.getPluginManager().getPlugin("EliteMobs") != null) { - WorldGuard.Protect( - BlockVector3.at(lowestCorner.getX(), lowestCorner.getY(), lowestCorner.getZ()), - BlockVector3.at(highestCorner.getX(), highestCorner.getY(), highestCorner.getZ()), - bossFilename, eliteLocation); + WorldGuard.Protect(lowestCorner, highestCorner, bossFilename, eliteLocation); } else { if (!worldGuardWarn) { worldGuardWarn = true; diff --git a/src/main/java/com/magmaguy/betterstructures/chests/ChestEntry.java b/src/main/java/com/magmaguy/betterstructures/chests/ChestEntry.java index e94e071..a2b25c8 100644 --- a/src/main/java/com/magmaguy/betterstructures/chests/ChestEntry.java +++ b/src/main/java/com/magmaguy/betterstructures/chests/ChestEntry.java @@ -3,7 +3,6 @@ import com.magmaguy.betterstructures.config.treasures.TreasureConfigFields; import lombok.Getter; import org.bukkit.Material; -import org.bukkit.enchantments.Enchantment; import org.bukkit.inventory.ItemStack; import org.bukkit.inventory.meta.ItemMeta; diff --git a/src/main/java/com/magmaguy/betterstructures/config/CustomConfigFields.java b/src/main/java/com/magmaguy/betterstructures/config/CustomConfigFields.java index b32de59..de28d81 100644 --- a/src/main/java/com/magmaguy/betterstructures/config/CustomConfigFields.java +++ b/src/main/java/com/magmaguy/betterstructures/config/CustomConfigFields.java @@ -5,13 +5,11 @@ import com.magmaguy.betterstructures.util.WarningMessage; import org.bukkit.Bukkit; import org.bukkit.World; -import org.bukkit.configuration.ConfigurationSection; import org.bukkit.configuration.file.FileConfiguration; import org.bukkit.inventory.ItemStack; import org.bukkit.util.Vector; import java.io.File; -import java.io.IOException; import java.util.*; public class CustomConfigFields implements CustomConfigFieldsInterface { 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 index 70360a6..acbfcae 100644 --- a/src/main/java/com/magmaguy/betterstructures/config/generators/premade/GeneratorUndergroundDripstoneConfig.java +++ b/src/main/java/com/magmaguy/betterstructures/config/generators/premade/GeneratorUndergroundDripstoneConfig.java @@ -1,7 +1,6 @@ package com.magmaguy.betterstructures.config.generators.premade; import com.magmaguy.betterstructures.config.generators.GeneratorConfigFields; -import org.bukkit.World; import org.bukkit.block.Biome; import java.util.Arrays; 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 index 8bebdad..9d0aaaa 100644 --- a/src/main/java/com/magmaguy/betterstructures/config/treasures/premade/NetherTreasureConfig.java +++ b/src/main/java/com/magmaguy/betterstructures/config/treasures/premade/NetherTreasureConfig.java @@ -1,6 +1,5 @@ package com.magmaguy.betterstructures.config.treasures.premade; -import com.magmaguy.betterstructures.config.DefaultConfig; import com.magmaguy.betterstructures.config.treasures.TreasureConfigFields; import com.magmaguy.betterstructures.util.DefaultChestContents; diff --git a/src/main/java/com/magmaguy/betterstructures/thirdparty/WorldGuard.java b/src/main/java/com/magmaguy/betterstructures/thirdparty/WorldGuard.java index 33a766a..488d24f 100644 --- a/src/main/java/com/magmaguy/betterstructures/thirdparty/WorldGuard.java +++ b/src/main/java/com/magmaguy/betterstructures/thirdparty/WorldGuard.java @@ -1,5 +1,6 @@ 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; @@ -25,6 +26,7 @@ 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; @@ -62,6 +64,23 @@ public static void initializeFlag() { } } + /** + * 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())); diff --git a/src/main/java/com/magmaguy/betterstructures/util/DefaultChestContents.java b/src/main/java/com/magmaguy/betterstructures/util/DefaultChestContents.java index 51e41a3..787043f 100644 --- a/src/main/java/com/magmaguy/betterstructures/util/DefaultChestContents.java +++ b/src/main/java/com/magmaguy/betterstructures/util/DefaultChestContents.java @@ -1,7 +1,6 @@ package com.magmaguy.betterstructures.util; import org.bukkit.Material; -import org.bukkit.configuration.file.FileConfiguration; import org.bukkit.enchantments.Enchantment; import org.bukkit.inventory.ItemStack; diff --git a/src/main/java/com/magmaguy/betterstructures/util/WorldEditUtils.java b/src/main/java/com/magmaguy/betterstructures/util/WorldEditUtils.java index 5d38bb9..c4a09ac 100644 --- a/src/main/java/com/magmaguy/betterstructures/util/WorldEditUtils.java +++ b/src/main/java/com/magmaguy/betterstructures/util/WorldEditUtils.java @@ -1,7 +1,6 @@ package com.magmaguy.betterstructures.util; import com.sk89q.jnbt.CompoundTag; -import com.sk89q.jnbt.ListTag; import com.sk89q.worldedit.extent.clipboard.Clipboard; import com.sk89q.worldedit.world.block.BaseBlock; import org.bukkit.Bukkit; @@ -59,12 +58,14 @@ private static String getLineWe(@NotNull CompoundTag data, @Positive int line) { values.add(s.replace("TAG_String(\"", "").replace("\")", "")); } } - // lines in versions below 1.20.4 duplicated twice + // lines in versions below 1.20.4 duplicated twice - note this is just for versions prior to 1.20.4 if (data.toString().contains("{\"text\":")) { - for (int i = (values.size() / 2); i != values.size();) { - if (values.size() == 2) break; - values.remove(i); - } + //todo: this code was contributed but it doens't seem to check out, is this dependent on a specific WE version or something? remove later if not +// for (int i = (values.size() / 2); i != values.size();) { +// if (values.size() == 2) break; +// values.remove(i); +// } + Collections.reverse(values); } diff --git a/src/main/resources/plugin.yml b/src/main/resources/plugin.yml index 2a722d1..a0b262a 100644 --- a/src/main/resources/plugin.yml +++ b/src/main/resources/plugin.yml @@ -1,5 +1,5 @@ name: BetterStructures -version: '1.6.4' +version: '1.6.5' main: com.magmaguy.betterstructures.BetterStructures api-version: 1.14 depend: [ WorldEdit ] From 86a90312572b0d2b09430116456c9c53a01c2f5a Mon Sep 17 00:00:00 2001 From: BuildTools Date: Fri, 19 Jan 2024 14:56:48 +0000 Subject: [PATCH 33/39] BetterStructures 1.6.6 changelog: - [Fix] Fixed spawn signs not working for FAWE - [Fix] Fixed spawn signs not working for the WorldEdit beta when using legacy formats (I think) - [Tweak] Attempted to improve FAWE overall spawn reliability --- build.gradle | 2 +- .../buildingfitter/FitAnything.java | 2 ++ .../betterstructures/util/WorldEditUtils.java | 13 ++++++------- src/main/resources/plugin.yml | 2 +- 4 files changed, 10 insertions(+), 9 deletions(-) diff --git a/build.gradle b/build.gradle index 508427e..c56b259 100644 --- a/build.gradle +++ b/build.gradle @@ -6,7 +6,7 @@ plugins { } group = 'com.magmaguy' -version = '1.6.5-SNAPSHOT' +version = '1.6.6-SNAPSHOT' repositories { mavenCentral() diff --git a/src/main/java/com/magmaguy/betterstructures/buildingfitter/FitAnything.java b/src/main/java/com/magmaguy/betterstructures/buildingfitter/FitAnything.java index e138acc..3d39a7a 100644 --- a/src/main/java/com/magmaguy/betterstructures/buildingfitter/FitAnything.java +++ b/src/main/java/com/magmaguy/betterstructures/buildingfitter/FitAnything.java @@ -306,6 +306,8 @@ private void spawnEntities() { signLocation.getBlock().setType(Material.AIR); //If mobs spawn in corners they might choke on adjacent walls 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) { diff --git a/src/main/java/com/magmaguy/betterstructures/util/WorldEditUtils.java b/src/main/java/com/magmaguy/betterstructures/util/WorldEditUtils.java index c4a09ac..2571f0c 100644 --- a/src/main/java/com/magmaguy/betterstructures/util/WorldEditUtils.java +++ b/src/main/java/com/magmaguy/betterstructures/util/WorldEditUtils.java @@ -60,12 +60,11 @@ private static String getLineWe(@NotNull CompoundTag data, @Positive int line) { } // lines in versions below 1.20.4 duplicated twice - note this is just for versions prior to 1.20.4 if (data.toString().contains("{\"text\":")) { - //todo: this code was contributed but it doens't seem to check out, is this dependent on a specific WE version or something? remove later if not -// for (int i = (values.size() / 2); i != values.size();) { -// if (values.size() == 2) break; -// values.remove(i); -// } - + Matcher matcher = Pattern.compile("Text[1-4]=LinStringTag\\[\\{\"text\":\"(.*?)\"").matcher(data.toString()); + while (matcher.find()) { + if (!matcher.group(1).isEmpty() && !matcher.group(1).isBlank()) + values.add(matcher.group(1)); + } Collections.reverse(values); } @@ -89,7 +88,7 @@ private static String getLineFawe(@NotNull CompoundTag data, @Positive int line) Matcher matcher = Pattern.compile("value=\"\\\\\\\\\"(.*?)\\\\\\\\\"\"") .matcher(str); - while (values.size() < 2 && matcher.find()) { + while (values.size() < 5 && matcher.find()) { String match = matcher.group(1); if (match.isEmpty()) continue; values.add(match); diff --git a/src/main/resources/plugin.yml b/src/main/resources/plugin.yml index a0b262a..8668030 100644 --- a/src/main/resources/plugin.yml +++ b/src/main/resources/plugin.yml @@ -1,5 +1,5 @@ name: BetterStructures -version: '1.6.5' +version: '1.6.6' main: com.magmaguy.betterstructures.BetterStructures api-version: 1.14 depend: [ WorldEdit ] From f3612780f825526bdab214616333d63fa70f389d Mon Sep 17 00:00:00 2001 From: BuildTools Date: Mon, 29 Jan 2024 01:42:22 +0000 Subject: [PATCH 34/39] BetterStructures 1.6.7 changelog: - [Fix] Fixed issue specific to running worldedit pre-beta in 1.20.4+ servers --- build.gradle | 2 +- .../com/magmaguy/betterstructures/util/WorldEditUtils.java | 6 +++--- src/main/resources/plugin.yml | 2 +- 3 files changed, 5 insertions(+), 5 deletions(-) diff --git a/build.gradle b/build.gradle index c56b259..1dca5a5 100644 --- a/build.gradle +++ b/build.gradle @@ -6,7 +6,7 @@ plugins { } group = 'com.magmaguy' -version = '1.6.6-SNAPSHOT' +version = '1.6.7-SNAPSHOT' repositories { mavenCentral() diff --git a/src/main/java/com/magmaguy/betterstructures/util/WorldEditUtils.java b/src/main/java/com/magmaguy/betterstructures/util/WorldEditUtils.java index 2571f0c..9daadd2 100644 --- a/src/main/java/com/magmaguy/betterstructures/util/WorldEditUtils.java +++ b/src/main/java/com/magmaguy/betterstructures/util/WorldEditUtils.java @@ -54,16 +54,16 @@ private static String getLineWe(@NotNull CompoundTag data, @Positive int line) { for (String s : lines) { s = s.trim().replace("{\"text\":", "").replace("}", ""); // support for versions below 1.20.4 - if (s.startsWith("TAG_String(\"") && !s.equals("TAG_String(\"\")")) { + if (s.startsWith("TAG_String(\"")) { values.add(s.replace("TAG_String(\"", "").replace("\")", "")); + if (values.size() > 3) break; } } // lines in versions below 1.20.4 duplicated twice - note this is just for versions prior to 1.20.4 if (data.toString().contains("{\"text\":")) { Matcher matcher = Pattern.compile("Text[1-4]=LinStringTag\\[\\{\"text\":\"(.*?)\"").matcher(data.toString()); while (matcher.find()) { - if (!matcher.group(1).isEmpty() && !matcher.group(1).isBlank()) - values.add(matcher.group(1)); + values.add(matcher.group(1)); } Collections.reverse(values); } diff --git a/src/main/resources/plugin.yml b/src/main/resources/plugin.yml index 8668030..6c8db94 100644 --- a/src/main/resources/plugin.yml +++ b/src/main/resources/plugin.yml @@ -1,5 +1,5 @@ name: BetterStructures -version: '1.6.6' +version: '1.6.7' main: com.magmaguy.betterstructures.BetterStructures api-version: 1.14 depend: [ WorldEdit ] From 20f62a2008e91aa28ddbd6b0a60fba2e966bf351 Mon Sep 17 00:00:00 2001 From: BuildTools Date: Mon, 29 Jan 2024 03:12:04 +0000 Subject: [PATCH 35/39] BetterStructures 1.6.7 changelog: - [Fix] Changed the way signs get interpreted by BetterStructures, should fix all signs regardless of WorldEdit version, FastAsyncWorldEdit version and Minecraft version. --- build.gradle | 2 +- .../betterstructures/util/WorldEditUtils.java | 71 +++++-------------- src/main/resources/plugin.yml | 2 +- 3 files changed, 19 insertions(+), 56 deletions(-) diff --git a/build.gradle b/build.gradle index 1dca5a5..183c0ed 100644 --- a/build.gradle +++ b/build.gradle @@ -6,7 +6,7 @@ plugins { } group = 'com.magmaguy' -version = '1.6.7-SNAPSHOT' +version = '1.6.8-SNAPSHOT' repositories { mavenCentral() diff --git a/src/main/java/com/magmaguy/betterstructures/util/WorldEditUtils.java b/src/main/java/com/magmaguy/betterstructures/util/WorldEditUtils.java index 9daadd2..dbeed62 100644 --- a/src/main/java/com/magmaguy/betterstructures/util/WorldEditUtils.java +++ b/src/main/java/com/magmaguy/betterstructures/util/WorldEditUtils.java @@ -1,7 +1,9 @@ package com.magmaguy.betterstructures.util; import com.sk89q.jnbt.CompoundTag; +import com.sk89q.jnbt.StringTag; import com.sk89q.worldedit.extent.clipboard.Clipboard; +import com.sk89q.worldedit.internal.expression.ExpressionException; import com.sk89q.worldedit.world.block.BaseBlock; import org.bukkit.Bukkit; import org.bukkit.plugin.Plugin; @@ -9,7 +11,10 @@ import org.checkerframework.checker.index.qual.Positive; import org.jetbrains.annotations.NotNull; -import java.util.*; +import java.util.ArrayList; +import java.util.Arrays; +import java.util.Collections; +import java.util.Optional; import java.util.regex.Matcher; import java.util.regex.Pattern; @@ -34,12 +39,6 @@ public static String getLine(@NotNull BaseBlock baseBlock, @Positive int line) { return ""; } CompoundTag data = baseBlock.getNbtData(); - Optional fawe = Arrays.stream(Bukkit.getPluginManager().getPlugins()) - .filter(pl -> pl.getName().contains("FastAsyncWorldEdit")) - .findFirst(); - if (fawe.isPresent()) { - return getLineFawe(data, line); - } return getLineWe(data, line); } @@ -49,58 +48,22 @@ public static String getLine(@NotNull BaseBlock baseBlock, @Positive int line) { *

Compatibility with version 1.20.4 has been added.

*/ private static String getLineWe(@NotNull CompoundTag data, @Positive int line) { - List lines = data.toString().lines().toList(); + try { + String text = ((StringTag) data.getValue().get("Text"+line)).getValue(); - for (String s : lines) { - s = s.trim().replace("{\"text\":", "").replace("}", ""); // support for versions below 1.20.4 + Pattern pattern = Pattern.compile("\\{\"text\":\"(.*?)\"\\}"); + Matcher matcher = pattern.matcher(text); - if (s.startsWith("TAG_String(\"")) { - values.add(s.replace("TAG_String(\"", "").replace("\")", "")); - if (values.size() > 3) break; - } - } - // lines in versions below 1.20.4 duplicated twice - note this is just for versions prior to 1.20.4 - if (data.toString().contains("{\"text\":")) { - Matcher matcher = Pattern.compile("Text[1-4]=LinStringTag\\[\\{\"text\":\"(.*?)\"").matcher(data.toString()); - while (matcher.find()) { - values.add(matcher.group(1)); + if (matcher.find()) { + String extractedText = matcher.group(1); + return extractedText; + } else { + throw new Exception(); } - Collections.reverse(values); + } catch (Exception ex) { + Bukkit.getLogger().warning("Unexpected sign format!" + data); } - if (line <= values.size()) { - return values.get(line - 1); - } - return ""; - } - - /** - *

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

- *

Compatibility with version 1.20.4 has been added.

- */ - private static String getLineFawe(@NotNull CompoundTag data, @Positive int line) { - // 1.20.4 have a different format of NBT - String str = data.toString() - .replace("{\\\\\"text\\\\\":", "") - .replace("}", ""); - - Matcher matcher = Pattern.compile("value=\"\\\\\\\\\"(.*?)\\\\\\\\\"\"") - .matcher(str); - - while (values.size() < 5 && matcher.find()) { - String match = matcher.group(1); - if (match.isEmpty()) continue; - values.add(match); - } - // versions below 1.20.4 have reversed order of the lines (from 4 to 1) - if (data.toString().contains("{\\\\\"text\\\\\":")) { - Collections.reverse(values); - } - - if (line <= values.size()) { - return values.get(line - 1); - } return ""; } } diff --git a/src/main/resources/plugin.yml b/src/main/resources/plugin.yml index 6c8db94..4f04eca 100644 --- a/src/main/resources/plugin.yml +++ b/src/main/resources/plugin.yml @@ -1,5 +1,5 @@ name: BetterStructures -version: '1.6.7' +version: '1.6.8' main: com.magmaguy.betterstructures.BetterStructures api-version: 1.14 depend: [ WorldEdit ] From e7f000514751a8043f0bc661f24a0a7d557b49e2 Mon Sep 17 00:00:00 2001 From: BuildTools Date: Sun, 17 Mar 2024 07:59:10 +0000 Subject: [PATCH 36/39] BetterStructures 1.6.9 changelog: - [New] Properly updated to use the new WorldEdit 1.20.4+ schematic format --- build.gradle | 2 +- .../schematics/SchematicContainer.java | 2 +- .../betterstructures/util/WorldEditUtils.java | 54 ++++++++++++++----- src/main/resources/plugin.yml | 2 +- 4 files changed, 44 insertions(+), 16 deletions(-) diff --git a/build.gradle b/build.gradle index 183c0ed..2acb020 100644 --- a/build.gradle +++ b/build.gradle @@ -6,7 +6,7 @@ plugins { } group = 'com.magmaguy' -version = '1.6.8-SNAPSHOT' +version = '1.6.9-SNAPSHOT' repositories { mavenCentral() diff --git a/src/main/java/com/magmaguy/betterstructures/schematics/SchematicContainer.java b/src/main/java/com/magmaguy/betterstructures/schematics/SchematicContainer.java index 9df96d0..cef5d54 100644 --- a/src/main/java/com/magmaguy/betterstructures/schematics/SchematicContainer.java +++ b/src/main/java/com/magmaguy/betterstructures/schematics/SchematicContainer.java @@ -98,7 +98,7 @@ public SchematicContainer(Clipboard clipboard, String clipboardFilename, Schemat //Case for spawning a vanilla mob if (line1.toLowerCase().contains("[spawn]")) { - String line2 = WorldEditUtils.getLine(baseBlock, 2).toUpperCase(); + String line2 = WorldEditUtils.getLine(baseBlock, 2).toUpperCase().replaceAll("\"", ""); EntityType entityType; try { entityType = EntityType.valueOf(line2); diff --git a/src/main/java/com/magmaguy/betterstructures/util/WorldEditUtils.java b/src/main/java/com/magmaguy/betterstructures/util/WorldEditUtils.java index dbeed62..caa8109 100644 --- a/src/main/java/com/magmaguy/betterstructures/util/WorldEditUtils.java +++ b/src/main/java/com/magmaguy/betterstructures/util/WorldEditUtils.java @@ -1,20 +1,16 @@ 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.internal.expression.ExpressionException; import com.sk89q.worldedit.world.block.BaseBlock; import org.bukkit.Bukkit; -import org.bukkit.plugin.Plugin; import org.bukkit.util.Vector; import org.checkerframework.checker.index.qual.Positive; import org.jetbrains.annotations.NotNull; import java.util.ArrayList; -import java.util.Arrays; -import java.util.Collections; -import java.util.Optional; import java.util.regex.Matcher; import java.util.regex.Pattern; @@ -23,15 +19,12 @@ 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.

- *

Compatibility with version 1.20.4 has been added.

*/ public static String getLine(@NotNull BaseBlock baseBlock, @Positive int line) { values.clear(); @@ -45,11 +38,25 @@ public static String getLine(@NotNull BaseBlock baseBlock, @Positive int line) { /** *

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

- *

Compatibility with version 1.20.4 has been added.

*/ private static String getLineWe(@NotNull CompoundTag data, @Positive int line) { try { - String text = ((StringTag) data.getValue().get("Text"+line)).getValue(); + 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); @@ -61,9 +68,30 @@ private static String getLineWe(@NotNull CompoundTag data, @Positive int line) { throw new Exception(); } } catch (Exception ex) { - Bukkit.getLogger().warning("Unexpected sign format!" + data); + Bukkit.getLogger().warning("Unexpected sign format in legacy read!\n" + data); } + return null; + } - return ""; + private static String getNewWEFormat(@NotNull CompoundTag data, @Positive int line) { + try { + Bukkit.getLogger().warning("Attempting modern read"); + //Get front text + CompoundTag frontText = (CompoundTag) data.getValue().get("front_text"); + Bukkit.getLogger().warning("Attempting modern read 2"); + //Get messages + ListTag messages = (ListTag) frontText.getValue().get("messages"); + Bukkit.getLogger().warning("Attempting modern read 3"); + //Get the line + String text = messages.getString(line-1); + Bukkit.getLogger().warning("Attempting modern read 4"); + + Bukkit.getLogger().warning("text: " + text); + return text; + + } catch (Exception ex) { + Bukkit.getLogger().warning("Unexpected sign format in new read!\n" + data); + } + return null; } } diff --git a/src/main/resources/plugin.yml b/src/main/resources/plugin.yml index 4f04eca..70fb91a 100644 --- a/src/main/resources/plugin.yml +++ b/src/main/resources/plugin.yml @@ -1,5 +1,5 @@ name: BetterStructures -version: '1.6.8' +version: '1.6.9' main: com.magmaguy.betterstructures.BetterStructures api-version: 1.14 depend: [ WorldEdit ] From 253647e9766fa22d2db31f3c767c818f09fa7c7d Mon Sep 17 00:00:00 2001 From: BuildTools Date: Tue, 19 Mar 2024 09:03:13 +0000 Subject: [PATCH 37/39] BetterStructures 1.6.10 changelog: - [Fix] Fixed signs made in 1.20.4+ not working for EliteMobs and MythicMobs - [Fix] Removed debug messages --- build.gradle | 2 +- .../schematics/SchematicContainer.java | 12 ++++++------ .../betterstructures/util/WorldEditUtils.java | 11 +++++------ src/main/resources/plugin.yml | 2 +- 4 files changed, 13 insertions(+), 14 deletions(-) diff --git a/build.gradle b/build.gradle index 2acb020..74e5014 100644 --- a/build.gradle +++ b/build.gradle @@ -6,7 +6,7 @@ plugins { } group = 'com.magmaguy' -version = '1.6.9-SNAPSHOT' +version = '1.6.10-SNAPSHOT' repositories { mavenCentral() diff --git a/src/main/java/com/magmaguy/betterstructures/schematics/SchematicContainer.java b/src/main/java/com/magmaguy/betterstructures/schematics/SchematicContainer.java index cef5d54..70bdd75 100644 --- a/src/main/java/com/magmaguy/betterstructures/schematics/SchematicContainer.java +++ b/src/main/java/com/magmaguy/betterstructures/schematics/SchematicContainer.java @@ -118,12 +118,12 @@ public SchematicContainer(Clipboard clipboard, String clipboardFilename, Schemat 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; - } +// 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)); diff --git a/src/main/java/com/magmaguy/betterstructures/util/WorldEditUtils.java b/src/main/java/com/magmaguy/betterstructures/util/WorldEditUtils.java index caa8109..7e19645 100644 --- a/src/main/java/com/magmaguy/betterstructures/util/WorldEditUtils.java +++ b/src/main/java/com/magmaguy/betterstructures/util/WorldEditUtils.java @@ -75,18 +75,17 @@ private static String getOldWEFormat(@NotNull CompoundTag data, @Positive int li private static String getNewWEFormat(@NotNull CompoundTag data, @Positive int line) { try { - Bukkit.getLogger().warning("Attempting modern read"); //Get front text CompoundTag frontText = (CompoundTag) data.getValue().get("front_text"); - Bukkit.getLogger().warning("Attempting modern read 2"); //Get messages ListTag messages = (ListTag) frontText.getValue().get("messages"); - Bukkit.getLogger().warning("Attempting modern read 3"); //Get the line - String text = messages.getString(line-1); - Bukkit.getLogger().warning("Attempting modern read 4"); + 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); - Bukkit.getLogger().warning("text: " + text); return text; } catch (Exception ex) { diff --git a/src/main/resources/plugin.yml b/src/main/resources/plugin.yml index 70fb91a..a7faf09 100644 --- a/src/main/resources/plugin.yml +++ b/src/main/resources/plugin.yml @@ -1,5 +1,5 @@ name: BetterStructures -version: '1.6.9' +version: '1.6.10' main: com.magmaguy.betterstructures.BetterStructures api-version: 1.14 depend: [ WorldEdit ] From cbd81887d76d2313fe0fcadd2513a47300ff5041 Mon Sep 17 00:00:00 2001 From: BuildTools Date: Tue, 25 Jun 2024 17:19:04 +0100 Subject: [PATCH 38/39] [BetterStructures 1.6.11 changelog: - [New] Now compatible with Minecraft 1.21 - [New] Upon user request, no longer using base64 for the lootify command, meaning that lootified entries can now easily be read by admins. Note: this breaks all previously added loot via the lootify command, which Minecraft 1.21 also partially broke regardless. The new method should be easier to maintain in the long run. --- build.gradle | 4 +- .../buildingfitter/FitAnything.java | 5 ++- .../chests/ChestContents.java | 6 +-- .../commands/CommandHandler.java | 2 +- .../schematics/SchematicContainer.java | 12 +++--- .../util/ItemStackSerialization.java | 42 ++++--------------- .../util/SurfaceMaterials.java | 6 ++- src/main/resources/plugin.yml | 3 +- 8 files changed, 32 insertions(+), 48 deletions(-) diff --git a/build.gradle b/build.gradle index 74e5014..13c8cbb 100644 --- a/build.gradle +++ b/build.gradle @@ -6,7 +6,7 @@ plugins { } group = 'com.magmaguy' -version = '1.6.10-SNAPSHOT' +version = '1.6.11-SNAPSHOT' repositories { mavenCentral() @@ -39,7 +39,7 @@ repositories { } dependencies { - compileOnly 'org.spigotmc:spigot-api:1.20-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 diff --git a/src/main/java/com/magmaguy/betterstructures/buildingfitter/FitAnything.java b/src/main/java/com/magmaguy/betterstructures/buildingfitter/FitAnything.java index 3d39a7a..5a461f9 100644 --- a/src/main/java/com/magmaguy/betterstructures/buildingfitter/FitAnything.java +++ b/src/main/java/com/magmaguy/betterstructures/buildingfitter/FitAnything.java @@ -13,6 +13,7 @@ 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; @@ -313,7 +314,9 @@ private void spawnEntities() { if (entity instanceof LivingEntity) { ((LivingEntity) entity).setRemoveWhenFarAway(false); } - if (entity.getType().equals(EntityType.ENDER_CRYSTAL)) { + + if (!VersionChecker.serverVersionOlderThan(21,0) && + entity.getType().equals(EntityType.END_CRYSTAL)) { EnderCrystal enderCrystal = (EnderCrystal) entity; enderCrystal.setShowingBottom(false); } diff --git a/src/main/java/com/magmaguy/betterstructures/chests/ChestContents.java b/src/main/java/com/magmaguy/betterstructures/chests/ChestContents.java index ba4ad10..a68a304 100644 --- a/src/main/java/com/magmaguy/betterstructures/chests/ChestContents.java +++ b/src/main/java/com/magmaguy/betterstructures/chests/ChestContents.java @@ -72,9 +72,9 @@ private void processRarities(Map rawChestEntries) { } } - private ItemStack getSerializedItemStack(String string) { + private ItemStack getSerializedItemStack(Map deserializedItemStack, String string) { try { - return ItemStackSerialization.itemStackArrayFromBase64(string.replace("serialized=", "")); + return ItemStackSerialization.serializeItem(deserializedItemStack); } catch (Exception ex) { new WarningMessage("Invalid serialized value detected! Problematic entry: " + string + " for configuration file " + treasureConfigFields.getFilename()); ex.printStackTrace(); @@ -135,7 +135,7 @@ private List processEntries(List> rawChestEntries) { case "weight" -> weight = getWeight(value); //Support for MMOItems - og code by Carm case "mmoitem", "mmoitems" -> itemStack = getMMOItemsItemStack(value); - case "serialized" -> itemStack = getSerializedItemStack(value); + case "serialized" -> itemStack = getSerializedItemStack((Map) entry.getValue(), value); case "procedurallygenerateenchantments" -> procedurallyGeneratedEnchantments = getProcedurallyGeneratedEnchantments(value); case "info" -> { } diff --git a/src/main/java/com/magmaguy/betterstructures/commands/CommandHandler.java b/src/main/java/com/magmaguy/betterstructures/commands/CommandHandler.java index a8e7bed..d5be5df 100644 --- a/src/main/java/com/magmaguy/betterstructures/commands/CommandHandler.java +++ b/src/main/java/com/magmaguy/betterstructures/commands/CommandHandler.java @@ -274,7 +274,7 @@ else if (itemStack.hasItemMeta() && itemStack.getItemMeta().hasLocalizedName()) else info = itemStack.getType().toString(); Map configMap = new HashMap<>(); - configMap.put("serialized", ItemStackSerialization.toBase64(itemStack)); + configMap.put("serialized", ItemStackSerialization.deserializeItem(itemStack)); configMap.put("amount", minAmount +"-"+maxAmount); configMap.put("weight", weightDouble); configMap.put("info", info); diff --git a/src/main/java/com/magmaguy/betterstructures/schematics/SchematicContainer.java b/src/main/java/com/magmaguy/betterstructures/schematics/SchematicContainer.java index 70bdd75..cef5d54 100644 --- a/src/main/java/com/magmaguy/betterstructures/schematics/SchematicContainer.java +++ b/src/main/java/com/magmaguy/betterstructures/schematics/SchematicContainer.java @@ -118,12 +118,12 @@ public SchematicContainer(Clipboard clipboard, String clipboardFilename, Schemat 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; -// } + 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)); 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/resources/plugin.yml b/src/main/resources/plugin.yml index a7faf09..1bf4e88 100644 --- a/src/main/resources/plugin.yml +++ b/src/main/resources/plugin.yml @@ -1,11 +1,12 @@ name: BetterStructures -version: '1.6.10' +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 From 8e444deb9129485f8467c24dc918367babd3d7c2 Mon Sep 17 00:00:00 2001 From: Kylepoops <62238380+Kylepoops@users.noreply.github.com> Date: Sat, 13 Jul 2024 22:53:43 +0800 Subject: [PATCH 39/39] Fix mob spawning --- .../schematics/SchematicContainer.java | 23 ++++++------------- 1 file changed, 7 insertions(+), 16 deletions(-) diff --git a/src/main/java/com/magmaguy/betterstructures/schematics/SchematicContainer.java b/src/main/java/com/magmaguy/betterstructures/schematics/SchematicContainer.java index cef5d54..0fef2e5 100644 --- a/src/main/java/com/magmaguy/betterstructures/schematics/SchematicContainer.java +++ b/src/main/java/com/magmaguy/betterstructures/schematics/SchematicContainer.java @@ -22,6 +22,7 @@ import org.bukkit.util.Vector; import java.util.ArrayList; +import java.util.Arrays; import java.util.HashMap; import java.util.List; @@ -53,6 +54,10 @@ public class SchematicContainer { @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; this.clipboardFilename = clipboardFilename; @@ -76,22 +81,8 @@ public SchematicContainer(Clipboard clipboard, String clipboardFilename, Schemat 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 = WorldEditUtils.getLine(baseBlock, 1);