├── .github └── workflows │ ├── maven-build.yml │ └── maven-deploy.yml ├── .gitignore ├── .gitlab-ci.yml ├── .mvn └── wrapper │ └── maven-wrapper.properties ├── CONTRIBUTING.md ├── LICENSE ├── README.md ├── mvnw ├── mvnw.cmd ├── pom.xml └── src └── main └── java ├── module-info.java └── org └── bspfsystems └── yamlconfiguration ├── configuration ├── Configuration.java ├── ConfigurationOptions.java ├── ConfigurationSection.java ├── InvalidConfigurationException.java ├── MemoryConfiguration.java ├── MemoryConfigurationOptions.java ├── MemorySection.java └── SectionPathData.java ├── file ├── FileConfiguration.java ├── FileConfigurationOptions.java ├── YamlConfiguration.java ├── YamlConfigurationOptions.java ├── YamlConstructor.java └── YamlRepresenter.java └── serialization ├── ConfigurationSerializable.java ├── ConfigurationSerialization.java ├── DelegateDeserialization.java └── SerializableAs.java /.github/workflows/maven-build.yml: -------------------------------------------------------------------------------- 1 | name: Build 2 | 3 | on: 4 | push: 5 | branches: 6 | - '**' 7 | workflow_dispatch: 8 | 9 | jobs: 10 | compile: 11 | runs-on: ubuntu-latest 12 | steps: 13 | - uses: actions/checkout@v4.2.2 14 | - name: Set Up JDK 17 15 | uses: actions/setup-java@v4.7.1 16 | with: 17 | java-version: '17' 18 | distribution: 'temurin' 19 | - name: Build with Maven 20 | run: mvn --batch-mode clean compile 21 | -------------------------------------------------------------------------------- /.github/workflows/maven-deploy.yml: -------------------------------------------------------------------------------- 1 | name: Deploy 2 | 3 | on: 4 | push: 5 | tags: 6 | - 'v**' 7 | workflow_dispatch: 8 | 9 | jobs: 10 | compile: 11 | runs-on: ubuntu-latest 12 | steps: 13 | - uses: actions/checkout@v4.2.2 14 | - name: Set Up JDK 17 15 | uses: actions/setup-java@v4.7.1 16 | with: 17 | java-version: '17' 18 | distribution: 'temurin' 19 | - name: Build with Maven 20 | run: mvn --batch-mode clean compile 21 | deploy: 22 | runs-on: ubuntu-latest 23 | needs: compile 24 | steps: 25 | - uses: actions/checkout@v4.2.2 26 | with: 27 | fetch-depth: 0 28 | - name: Install GPG Secret Key 29 | run: cat <(echo -e "${{ secrets.OSSRH_GPG_SECRET_KEY }}") | gpg --batch --import 30 | - name: Set Up JDK 17 31 | uses: actions/setup-java@v4.7.1 32 | with: 33 | java-version: '17' 34 | distribution: 'temurin' 35 | - name: Set Up Maven Settings 36 | uses: s4u/maven-settings-action@v3.1.0 37 | with: 38 | servers: | 39 | [{ 40 | "id": "central", 41 | "username": "${{ secrets.OSSRH_USERNAME }}", 42 | "password": "${{ secrets.OSSRH_TOKEN }}" 43 | }, 44 | { 45 | "id": "gpg.passphrase", 46 | "passphrase": "${{ secrets.OSSRH_GPG_SECRET_KEY_PASSWORD }}", 47 | "configuration": {} 48 | }] 49 | - name: Maven Verify 50 | run: mvn --batch-mode verify 51 | - name: Maven Deploy 52 | run: mvn --batch-mode -DskipTests=true deploy 53 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | target/ 2 | pom.xml.tag 3 | pom.xml.releaseBackup 4 | pom.xml.versionsBackup 5 | pom.xml.next 6 | release.properties 7 | dependency-reduced-pom.xml 8 | buildNumber.properties 9 | .mvn/timing.properties 10 | # https://github.com/takari/maven-wrapper#usage-without-binary-jar 11 | .mvn/wrapper/maven-wrapper.jar 12 | /bin/ 13 | libs/ 14 | .classpath 15 | .project 16 | .settings/ 17 | *.iml 18 | *.idea/ -------------------------------------------------------------------------------- /.gitlab-ci.yml: -------------------------------------------------------------------------------- 1 | include: 2 | - project: cicd-templates/common-templates 3 | ref: main 4 | file: maven/maven-build-17.yml 5 | -------------------------------------------------------------------------------- /.mvn/wrapper/maven-wrapper.properties: -------------------------------------------------------------------------------- 1 | # Licensed to the Apache Software Foundation (ASF) under one 2 | # or more contributor license agreements. See the NOTICE file 3 | # distributed with this work for additional information 4 | # regarding copyright ownership. The ASF licenses this file 5 | # to you under the Apache License, Version 2.0 (the 6 | # "License"); you may not use this file except in compliance 7 | # with the License. You may obtain a copy of the License at 8 | # 9 | # http://www.apache.org/licenses/LICENSE-2.0 10 | # 11 | # Unless required by applicable law or agreed to in writing, 12 | # software distributed under the License is distributed on an 13 | # "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 14 | # KIND, either express or implied. See the License for the 15 | # specific language governing permissions and limitations 16 | # under the License. 17 | distributionUrl=https://repo.maven.apache.org/maven2/org/apache/maven/apache-maven/3.9.9/apache-maven-3.9.9-bin.zip 18 | wrapperUrl=https://repo.maven.apache.org/maven2/org/apache/maven/wrapper/maven-wrapper/3.3.2/maven-wrapper-3.3.2.jar 19 | -------------------------------------------------------------------------------- /CONTRIBUTING.md: -------------------------------------------------------------------------------- 1 | # Contributions, Support, and Issues for YamlConfiguration 2 | 3 | Contributions to the project are welcome. YamlConfiguration is a free and open source software project, made open source with the hopes that the community would find ways to improve it. 4 | 5 | ## Contributing 6 | 7 | ### Pull Requests 8 | 9 | If you make any improvements or other enhancements to YamlConfiguration, we ask that you submit a Pull Request to merge the changes back upstream. We would enjoy the opportunity to give those improvements back to the wider community. 10 | 11 | Various types of contributions are welcome, including (but not limited to): 12 | - Security updates / patches 13 | - Bug fixes 14 | - Feature enhancements 15 | 16 | We reserve the right to not include a contribution in the project if the contribution does not add anything substantive or otherwise reduces the functionality of YamlConfiguration in a non-desirable way. That said, the idea of having free and open source software was that contributions would be accepted, and discussions over a potential contribution are welcome. 17 | 18 | For licensing questions, please see the Licensing section in [README.md](README.md). 19 | 20 | ### Project Layout 21 | 22 | YamlConfiguration somewhat follows the [Google Java Style Guide](https://google.github.io/styleguide/javaguide.html). This is not the definitive coding style of the project. Generally, it is best to try to copy the style of coding found in the class that you are editing. 23 | 24 | ## Support / Issues 25 | 26 | Issues can be reported [here in GitHub](https://github.com/bspfsystems/YamlConfiguration/issues/). 27 | 28 | ### First Steps 29 | 30 | Before creating an issue, please search to see if anyone else has reported the same issue. Don't forget to search the closed issues. It is much easier for us (and will get you a faster response) to handle a single issue that affects multiple users than it is to have to deal with duplicates. 31 | 32 | There is also a chance that your issue has been resolved previously. In this case, you can (ideally) find the answer to your problem without having to ask (new version of YamlConfiguration, configuration update, etc). 33 | 34 | ### Creating an Issue 35 | 36 | If no one has reported the issue previously, or the solution is not apparent, please open a new issue. When creating the issue, please give it a descriptive title (no "It's not working", please), and put as much detail into the description as possible. The more details you add, the easier it becomes for us to solve the issue. Helpful items may include: 37 | - A descriptive title for the issue 38 | - The version of YamlConfiguration you are using 39 | - Logs and/or stack traces 40 | - Any steps to reproducing the issue 41 | - Anything else that might be helpful in solving your issue. 42 | 43 | _Note:_ Please redact any Personally-Identifiable Information (PII) when you create your issue. These may appear in logs or stack traces. Examples include (but are not limited to): 44 | - Real names of people / companies 45 | - Usernames of accounts on computers (may appear in logs or stack traces) 46 | - IP addresses / hostnames 47 | - etc. 48 | 49 | If you are not sure, you can always redact or otherwise change the data. 50 | 51 | ### Non-Acceptable Issues 52 | 53 | Issues such as "I need help" or "It doesn't work" will not be addressed and/or will be closed with no assistance given. These type of issues do not have any meaningful details to properly address the problem. Other issues that will not be addressed and/or will be closed without help include (but are not limited to): 54 | - How to install YamlConfiguration (explained in (README.md)[README.md]) 55 | - How to use YamlConfiguration as a dependency (explained in (README.md)[README.md]) 56 | - How to create libraries 57 | - How to set up a development environment 58 | - How to install libraries 59 | - Other issues of similar nature... 60 | 61 | This is not a help forum for software development or associated issues. Other resources, such as [Google](https://www.google.com/), should have answers to most questions not related to YamlConfiguration. 62 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | GNU GENERAL PUBLIC LICENSE 2 | Version 3, 29 June 2007 3 | 4 | Copyright (C) 2007 Free Software Foundation, Inc. 5 | Everyone is permitted to copy and distribute verbatim copies 6 | of this license document, but changing it is not allowed. 7 | 8 | Preamble 9 | 10 | The GNU General Public License is a free, copyleft license for 11 | software and other kinds of works. 12 | 13 | The licenses for most software and other practical works are designed 14 | to take away your freedom to share and change the works. By contrast, 15 | the GNU General Public License is intended to guarantee your freedom to 16 | share and change all versions of a program--to make sure it remains free 17 | software for all its users. We, the Free Software Foundation, use the 18 | GNU General Public License for most of our software; it applies also to 19 | any other work released this way by its authors. You can apply it to 20 | your programs, too. 21 | 22 | When we speak of free software, we are referring to freedom, not 23 | price. Our General Public Licenses are designed to make sure that you 24 | have the freedom to distribute copies of free software (and charge for 25 | them if you wish), that you receive source code or can get it if you 26 | want it, that you can change the software or use pieces of it in new 27 | free programs, and that you know you can do these things. 28 | 29 | To protect your rights, we need to prevent others from denying you 30 | these rights or asking you to surrender the rights. Therefore, you have 31 | certain responsibilities if you distribute copies of the software, or if 32 | you modify it: responsibilities to respect the freedom of others. 33 | 34 | For example, if you distribute copies of such a program, whether 35 | gratis or for a fee, you must pass on to the recipients the same 36 | freedoms that you received. You must make sure that they, too, receive 37 | or can get the source code. And you must show them these terms so they 38 | know their rights. 39 | 40 | Developers that use the GNU GPL protect your rights with two steps: 41 | (1) assert copyright on the software, and (2) offer you this License 42 | giving you legal permission to copy, distribute and/or modify it. 43 | 44 | For the developers' and authors' protection, the GPL clearly explains 45 | that there is no warranty for this free software. For both users' and 46 | authors' sake, the GPL requires that modified versions be marked as 47 | changed, so that their problems will not be attributed erroneously to 48 | authors of previous versions. 49 | 50 | Some devices are designed to deny users access to install or run 51 | modified versions of the software inside them, although the manufacturer 52 | can do so. This is fundamentally incompatible with the aim of 53 | protecting users' freedom to change the software. The systematic 54 | pattern of such abuse occurs in the area of products for individuals to 55 | use, which is precisely where it is most unacceptable. Therefore, we 56 | have designed this version of the GPL to prohibit the practice for those 57 | products. If such problems arise substantially in other domains, we 58 | stand ready to extend this provision to those domains in future versions 59 | of the GPL, as needed to protect the freedom of users. 60 | 61 | Finally, every program is threatened constantly by software patents. 62 | States should not allow patents to restrict development and use of 63 | software on general-purpose computers, but in those that do, we wish to 64 | avoid the special danger that patents applied to a free program could 65 | make it effectively proprietary. To prevent this, the GPL assures that 66 | patents cannot be used to render the program non-free. 67 | 68 | The precise terms and conditions for copying, distribution and 69 | modification follow. 70 | 71 | TERMS AND CONDITIONS 72 | 73 | 0. Definitions. 74 | 75 | "This License" refers to version 3 of the GNU General Public License. 76 | 77 | "Copyright" also means copyright-like laws that apply to other kinds of 78 | works, such as semiconductor masks. 79 | 80 | "The Program" refers to any copyrightable work licensed under this 81 | License. Each licensee is addressed as "you". "Licensees" and 82 | "recipients" may be individuals or organizations. 83 | 84 | To "modify" a work means to copy from or adapt all or part of the work 85 | in a fashion requiring copyright permission, other than the making of an 86 | exact copy. The resulting work is called a "modified version" of the 87 | earlier work or a work "based on" the earlier work. 88 | 89 | A "covered work" means either the unmodified Program or a work based 90 | on the Program. 91 | 92 | To "propagate" a work means to do anything with it that, without 93 | permission, would make you directly or secondarily liable for 94 | infringement under applicable copyright law, except executing it on a 95 | computer or modifying a private copy. Propagation includes copying, 96 | distribution (with or without modification), making available to the 97 | public, and in some countries other activities as well. 98 | 99 | To "convey" a work means any kind of propagation that enables other 100 | parties to make or receive copies. Mere interaction with a user through 101 | a computer network, with no transfer of a copy, is not conveying. 102 | 103 | An interactive user interface displays "Appropriate Legal Notices" 104 | to the extent that it includes a convenient and prominently visible 105 | feature that (1) displays an appropriate copyright notice, and (2) 106 | tells the user that there is no warranty for the work (except to the 107 | extent that warranties are provided), that licensees may convey the 108 | work under this License, and how to view a copy of this License. If 109 | the interface presents a list of user commands or options, such as a 110 | menu, a prominent item in the list meets this criterion. 111 | 112 | 1. Source Code. 113 | 114 | The "source code" for a work means the preferred form of the work 115 | for making modifications to it. "Object code" means any non-source 116 | form of a work. 117 | 118 | A "Standard Interface" means an interface that either is an official 119 | standard defined by a recognized standards body, or, in the case of 120 | interfaces specified for a particular programming language, one that 121 | is widely used among developers working in that language. 122 | 123 | The "System Libraries" of an executable work include anything, other 124 | than the work as a whole, that (a) is included in the normal form of 125 | packaging a Major Component, but which is not part of that Major 126 | Component, and (b) serves only to enable use of the work with that 127 | Major Component, or to implement a Standard Interface for which an 128 | implementation is available to the public in source code form. A 129 | "Major Component", in this context, means a major essential component 130 | (kernel, window system, and so on) of the specific operating system 131 | (if any) on which the executable work runs, or a compiler used to 132 | produce the work, or an object code interpreter used to run it. 133 | 134 | The "Corresponding Source" for a work in object code form means all 135 | the source code needed to generate, install, and (for an executable 136 | work) run the object code and to modify the work, including scripts to 137 | control those activities. However, it does not include the work's 138 | System Libraries, or general-purpose tools or generally available free 139 | programs which are used unmodified in performing those activities but 140 | which are not part of the work. For example, Corresponding Source 141 | includes interface definition files associated with source files for 142 | the work, and the source code for shared libraries and dynamically 143 | linked subprograms that the work is specifically designed to require, 144 | such as by intimate data communication or control flow between those 145 | subprograms and other parts of the work. 146 | 147 | The Corresponding Source need not include anything that users 148 | can regenerate automatically from other parts of the Corresponding 149 | Source. 150 | 151 | The Corresponding Source for a work in source code form is that 152 | same work. 153 | 154 | 2. Basic Permissions. 155 | 156 | All rights granted under this License are granted for the term of 157 | copyright on the Program, and are irrevocable provided the stated 158 | conditions are met. This License explicitly affirms your unlimited 159 | permission to run the unmodified Program. The output from running a 160 | covered work is covered by this License only if the output, given its 161 | content, constitutes a covered work. This License acknowledges your 162 | rights of fair use or other equivalent, as provided by copyright law. 163 | 164 | You may make, run and propagate covered works that you do not 165 | convey, without conditions so long as your license otherwise remains 166 | in force. You may convey covered works to others for the sole purpose 167 | of having them make modifications exclusively for you, or provide you 168 | with facilities for running those works, provided that you comply with 169 | the terms of this License in conveying all material for which you do 170 | not control copyright. Those thus making or running the covered works 171 | for you must do so exclusively on your behalf, under your direction 172 | and control, on terms that prohibit them from making any copies of 173 | your copyrighted material outside their relationship with you. 174 | 175 | Conveying under any other circumstances is permitted solely under 176 | the conditions stated below. Sublicensing is not allowed; section 10 177 | makes it unnecessary. 178 | 179 | 3. Protecting Users' Legal Rights From Anti-Circumvention Law. 180 | 181 | No covered work shall be deemed part of an effective technological 182 | measure under any applicable law fulfilling obligations under article 183 | 11 of the WIPO copyright treaty adopted on 20 December 1996, or 184 | similar laws prohibiting or restricting circumvention of such 185 | measures. 186 | 187 | When you convey a covered work, you waive any legal power to forbid 188 | circumvention of technological measures to the extent such circumvention 189 | is effected by exercising rights under this License with respect to 190 | the covered work, and you disclaim any intention to limit operation or 191 | modification of the work as a means of enforcing, against the work's 192 | users, your or third parties' legal rights to forbid circumvention of 193 | technological measures. 194 | 195 | 4. Conveying Verbatim Copies. 196 | 197 | You may convey verbatim copies of the Program's source code as you 198 | receive it, in any medium, provided that you conspicuously and 199 | appropriately publish on each copy an appropriate copyright notice; 200 | keep intact all notices stating that this License and any 201 | non-permissive terms added in accord with section 7 apply to the code; 202 | keep intact all notices of the absence of any warranty; and give all 203 | recipients a copy of this License along with the Program. 204 | 205 | You may charge any price or no price for each copy that you convey, 206 | and you may offer support or warranty protection for a fee. 207 | 208 | 5. Conveying Modified Source Versions. 209 | 210 | You may convey a work based on the Program, or the modifications to 211 | produce it from the Program, in the form of source code under the 212 | terms of section 4, provided that you also meet all of these conditions: 213 | 214 | a) The work must carry prominent notices stating that you modified 215 | it, and giving a relevant date. 216 | 217 | b) The work must carry prominent notices stating that it is 218 | released under this License and any conditions added under section 219 | 7. This requirement modifies the requirement in section 4 to 220 | "keep intact all notices". 221 | 222 | c) You must license the entire work, as a whole, under this 223 | License to anyone who comes into possession of a copy. This 224 | License will therefore apply, along with any applicable section 7 225 | additional terms, to the whole of the work, and all its parts, 226 | regardless of how they are packaged. This License gives no 227 | permission to license the work in any other way, but it does not 228 | invalidate such permission if you have separately received it. 229 | 230 | d) If the work has interactive user interfaces, each must display 231 | Appropriate Legal Notices; however, if the Program has interactive 232 | interfaces that do not display Appropriate Legal Notices, your 233 | work need not make them do so. 234 | 235 | A compilation of a covered work with other separate and independent 236 | works, which are not by their nature extensions of the covered work, 237 | and which are not combined with it such as to form a larger program, 238 | in or on a volume of a storage or distribution medium, is called an 239 | "aggregate" if the compilation and its resulting copyright are not 240 | used to limit the access or legal rights of the compilation's users 241 | beyond what the individual works permit. Inclusion of a covered work 242 | in an aggregate does not cause this License to apply to the other 243 | parts of the aggregate. 244 | 245 | 6. Conveying Non-Source Forms. 246 | 247 | You may convey a covered work in object code form under the terms 248 | of sections 4 and 5, provided that you also convey the 249 | machine-readable Corresponding Source under the terms of this License, 250 | in one of these ways: 251 | 252 | a) Convey the object code in, or embodied in, a physical product 253 | (including a physical distribution medium), accompanied by the 254 | Corresponding Source fixed on a durable physical medium 255 | customarily used for software interchange. 256 | 257 | b) Convey the object code in, or embodied in, a physical product 258 | (including a physical distribution medium), accompanied by a 259 | written offer, valid for at least three years and valid for as 260 | long as you offer spare parts or customer support for that product 261 | model, to give anyone who possesses the object code either (1) a 262 | copy of the Corresponding Source for all the software in the 263 | product that is covered by this License, on a durable physical 264 | medium customarily used for software interchange, for a price no 265 | more than your reasonable cost of physically performing this 266 | conveying of source, or (2) access to copy the 267 | Corresponding Source from a network server at no charge. 268 | 269 | c) Convey individual copies of the object code with a copy of the 270 | written offer to provide the Corresponding Source. This 271 | alternative is allowed only occasionally and noncommercially, and 272 | only if you received the object code with such an offer, in accord 273 | with subsection 6b. 274 | 275 | d) Convey the object code by offering access from a designated 276 | place (gratis or for a charge), and offer equivalent access to the 277 | Corresponding Source in the same way through the same place at no 278 | further charge. You need not require recipients to copy the 279 | Corresponding Source along with the object code. If the place to 280 | copy the object code is a network server, the Corresponding Source 281 | may be on a different server (operated by you or a third party) 282 | that supports equivalent copying facilities, provided you maintain 283 | clear directions next to the object code saying where to find the 284 | Corresponding Source. Regardless of what server hosts the 285 | Corresponding Source, you remain obligated to ensure that it is 286 | available for as long as needed to satisfy these requirements. 287 | 288 | e) Convey the object code using peer-to-peer transmission, provided 289 | you inform other peers where the object code and Corresponding 290 | Source of the work are being offered to the general public at no 291 | charge under subsection 6d. 292 | 293 | A separable portion of the object code, whose source code is excluded 294 | from the Corresponding Source as a System Library, need not be 295 | included in conveying the object code work. 296 | 297 | A "User Product" is either (1) a "consumer product", which means any 298 | tangible personal property which is normally used for personal, family, 299 | or household purposes, or (2) anything designed or sold for incorporation 300 | into a dwelling. In determining whether a product is a consumer product, 301 | doubtful cases shall be resolved in favor of coverage. For a particular 302 | product received by a particular user, "normally used" refers to a 303 | typical or common use of that class of product, regardless of the status 304 | of the particular user or of the way in which the particular user 305 | actually uses, or expects or is expected to use, the product. A product 306 | is a consumer product regardless of whether the product has substantial 307 | commercial, industrial or non-consumer uses, unless such uses represent 308 | the only significant mode of use of the product. 309 | 310 | "Installation Information" for a User Product means any methods, 311 | procedures, authorization keys, or other information required to install 312 | and execute modified versions of a covered work in that User Product from 313 | a modified version of its Corresponding Source. The information must 314 | suffice to ensure that the continued functioning of the modified object 315 | code is in no case prevented or interfered with solely because 316 | modification has been made. 317 | 318 | If you convey an object code work under this section in, or with, or 319 | specifically for use in, a User Product, and the conveying occurs as 320 | part of a transaction in which the right of possession and use of the 321 | User Product is transferred to the recipient in perpetuity or for a 322 | fixed term (regardless of how the transaction is characterized), the 323 | Corresponding Source conveyed under this section must be accompanied 324 | by the Installation Information. But this requirement does not apply 325 | if neither you nor any third party retains the ability to install 326 | modified object code on the User Product (for example, the work has 327 | been installed in ROM). 328 | 329 | The requirement to provide Installation Information does not include a 330 | requirement to continue to provide support service, warranty, or updates 331 | for a work that has been modified or installed by the recipient, or for 332 | the User Product in which it has been modified or installed. Access to a 333 | network may be denied when the modification itself materially and 334 | adversely affects the operation of the network or violates the rules and 335 | protocols for communication across the network. 336 | 337 | Corresponding Source conveyed, and Installation Information provided, 338 | in accord with this section must be in a format that is publicly 339 | documented (and with an implementation available to the public in 340 | source code form), and must require no special password or key for 341 | unpacking, reading or copying. 342 | 343 | 7. Additional Terms. 344 | 345 | "Additional permissions" are terms that supplement the terms of this 346 | License by making exceptions from one or more of its conditions. 347 | Additional permissions that are applicable to the entire Program shall 348 | be treated as though they were included in this License, to the extent 349 | that they are valid under applicable law. If additional permissions 350 | apply only to part of the Program, that part may be used separately 351 | under those permissions, but the entire Program remains governed by 352 | this License without regard to the additional permissions. 353 | 354 | When you convey a copy of a covered work, you may at your option 355 | remove any additional permissions from that copy, or from any part of 356 | it. (Additional permissions may be written to require their own 357 | removal in certain cases when you modify the work.) You may place 358 | additional permissions on material, added by you to a covered work, 359 | for which you have or can give appropriate copyright permission. 360 | 361 | Notwithstanding any other provision of this License, for material you 362 | add to a covered work, you may (if authorized by the copyright holders of 363 | that material) supplement the terms of this License with terms: 364 | 365 | a) Disclaiming warranty or limiting liability differently from the 366 | terms of sections 15 and 16 of this License; or 367 | 368 | b) Requiring preservation of specified reasonable legal notices or 369 | author attributions in that material or in the Appropriate Legal 370 | Notices displayed by works containing it; or 371 | 372 | c) Prohibiting misrepresentation of the origin of that material, or 373 | requiring that modified versions of such material be marked in 374 | reasonable ways as different from the original version; or 375 | 376 | d) Limiting the use for publicity purposes of names of licensors or 377 | authors of the material; or 378 | 379 | e) Declining to grant rights under trademark law for use of some 380 | trade names, trademarks, or service marks; or 381 | 382 | f) Requiring indemnification of licensors and authors of that 383 | material by anyone who conveys the material (or modified versions of 384 | it) with contractual assumptions of liability to the recipient, for 385 | any liability that these contractual assumptions directly impose on 386 | those licensors and authors. 387 | 388 | All other non-permissive additional terms are considered "further 389 | restrictions" within the meaning of section 10. If the Program as you 390 | received it, or any part of it, contains a notice stating that it is 391 | governed by this License along with a term that is a further 392 | restriction, you may remove that term. If a license document contains 393 | a further restriction but permits relicensing or conveying under this 394 | License, you may add to a covered work material governed by the terms 395 | of that license document, provided that the further restriction does 396 | not survive such relicensing or conveying. 397 | 398 | If you add terms to a covered work in accord with this section, you 399 | must place, in the relevant source files, a statement of the 400 | additional terms that apply to those files, or a notice indicating 401 | where to find the applicable terms. 402 | 403 | Additional terms, permissive or non-permissive, may be stated in the 404 | form of a separately written license, or stated as exceptions; 405 | the above requirements apply either way. 406 | 407 | 8. Termination. 408 | 409 | You may not propagate or modify a covered work except as expressly 410 | provided under this License. Any attempt otherwise to propagate or 411 | modify it is void, and will automatically terminate your rights under 412 | this License (including any patent licenses granted under the third 413 | paragraph of section 11). 414 | 415 | However, if you cease all violation of this License, then your 416 | license from a particular copyright holder is reinstated (a) 417 | provisionally, unless and until the copyright holder explicitly and 418 | finally terminates your license, and (b) permanently, if the copyright 419 | holder fails to notify you of the violation by some reasonable means 420 | prior to 60 days after the cessation. 421 | 422 | Moreover, your license from a particular copyright holder is 423 | reinstated permanently if the copyright holder notifies you of the 424 | violation by some reasonable means, this is the first time you have 425 | received notice of violation of this License (for any work) from that 426 | copyright holder, and you cure the violation prior to 30 days after 427 | your receipt of the notice. 428 | 429 | Termination of your rights under this section does not terminate the 430 | licenses of parties who have received copies or rights from you under 431 | this License. If your rights have been terminated and not permanently 432 | reinstated, you do not qualify to receive new licenses for the same 433 | material under section 10. 434 | 435 | 9. Acceptance Not Required for Having Copies. 436 | 437 | You are not required to accept this License in order to receive or 438 | run a copy of the Program. Ancillary propagation of a covered work 439 | occurring solely as a consequence of using peer-to-peer transmission 440 | to receive a copy likewise does not require acceptance. However, 441 | nothing other than this License grants you permission to propagate or 442 | modify any covered work. These actions infringe copyright if you do 443 | not accept this License. Therefore, by modifying or propagating a 444 | covered work, you indicate your acceptance of this License to do so. 445 | 446 | 10. Automatic Licensing of Downstream Recipients. 447 | 448 | Each time you convey a covered work, the recipient automatically 449 | receives a license from the original licensors, to run, modify and 450 | propagate that work, subject to this License. You are not responsible 451 | for enforcing compliance by third parties with this License. 452 | 453 | An "entity transaction" is a transaction transferring control of an 454 | organization, or substantially all assets of one, or subdividing an 455 | organization, or merging organizations. If propagation of a covered 456 | work results from an entity transaction, each party to that 457 | transaction who receives a copy of the work also receives whatever 458 | licenses to the work the party's predecessor in interest had or could 459 | give under the previous paragraph, plus a right to possession of the 460 | Corresponding Source of the work from the predecessor in interest, if 461 | the predecessor has it or can get it with reasonable efforts. 462 | 463 | You may not impose any further restrictions on the exercise of the 464 | rights granted or affirmed under this License. For example, you may 465 | not impose a license fee, royalty, or other charge for exercise of 466 | rights granted under this License, and you may not initiate litigation 467 | (including a cross-claim or counterclaim in a lawsuit) alleging that 468 | any patent claim is infringed by making, using, selling, offering for 469 | sale, or importing the Program or any portion of it. 470 | 471 | 11. Patents. 472 | 473 | A "contributor" is a copyright holder who authorizes use under this 474 | License of the Program or a work on which the Program is based. The 475 | work thus licensed is called the contributor's "contributor version". 476 | 477 | A contributor's "essential patent claims" are all patent claims 478 | owned or controlled by the contributor, whether already acquired or 479 | hereafter acquired, that would be infringed by some manner, permitted 480 | by this License, of making, using, or selling its contributor version, 481 | but do not include claims that would be infringed only as a 482 | consequence of further modification of the contributor version. For 483 | purposes of this definition, "control" includes the right to grant 484 | patent sublicenses in a manner consistent with the requirements of 485 | this License. 486 | 487 | Each contributor grants you a non-exclusive, worldwide, royalty-free 488 | patent license under the contributor's essential patent claims, to 489 | make, use, sell, offer for sale, import and otherwise run, modify and 490 | propagate the contents of its contributor version. 491 | 492 | In the following three paragraphs, a "patent license" is any express 493 | agreement or commitment, however denominated, not to enforce a patent 494 | (such as an express permission to practice a patent or covenant not to 495 | sue for patent infringement). To "grant" such a patent license to a 496 | party means to make such an agreement or commitment not to enforce a 497 | patent against the party. 498 | 499 | If you convey a covered work, knowingly relying on a patent license, 500 | and the Corresponding Source of the work is not available for anyone 501 | to copy, free of charge and under the terms of this License, through a 502 | publicly available network server or other readily accessible means, 503 | then you must either (1) cause the Corresponding Source to be so 504 | available, or (2) arrange to deprive yourself of the benefit of the 505 | patent license for this particular work, or (3) arrange, in a manner 506 | consistent with the requirements of this License, to extend the patent 507 | license to downstream recipients. "Knowingly relying" means you have 508 | actual knowledge that, but for the patent license, your conveying the 509 | covered work in a country, or your recipient's use of the covered work 510 | in a country, would infringe one or more identifiable patents in that 511 | country that you have reason to believe are valid. 512 | 513 | If, pursuant to or in connection with a single transaction or 514 | arrangement, you convey, or propagate by procuring conveyance of, a 515 | covered work, and grant a patent license to some of the parties 516 | receiving the covered work authorizing them to use, propagate, modify 517 | or convey a specific copy of the covered work, then the patent license 518 | you grant is automatically extended to all recipients of the covered 519 | work and works based on it. 520 | 521 | A patent license is "discriminatory" if it does not include within 522 | the scope of its coverage, prohibits the exercise of, or is 523 | conditioned on the non-exercise of one or more of the rights that are 524 | specifically granted under this License. You may not convey a covered 525 | work if you are a party to an arrangement with a third party that is 526 | in the business of distributing software, under which you make payment 527 | to the third party based on the extent of your activity of conveying 528 | the work, and under which the third party grants, to any of the 529 | parties who would receive the covered work from you, a discriminatory 530 | patent license (a) in connection with copies of the covered work 531 | conveyed by you (or copies made from those copies), or (b) primarily 532 | for and in connection with specific products or compilations that 533 | contain the covered work, unless you entered into that arrangement, 534 | or that patent license was granted, prior to 28 March 2007. 535 | 536 | Nothing in this License shall be construed as excluding or limiting 537 | any implied license or other defenses to infringement that may 538 | otherwise be available to you under applicable patent law. 539 | 540 | 12. No Surrender of Others' Freedom. 541 | 542 | If conditions are imposed on you (whether by court order, agreement or 543 | otherwise) that contradict the conditions of this License, they do not 544 | excuse you from the conditions of this License. If you cannot convey a 545 | covered work so as to satisfy simultaneously your obligations under this 546 | License and any other pertinent obligations, then as a consequence you may 547 | not convey it at all. For example, if you agree to terms that obligate you 548 | to collect a royalty for further conveying from those to whom you convey 549 | the Program, the only way you could satisfy both those terms and this 550 | License would be to refrain entirely from conveying the Program. 551 | 552 | 13. Use with the GNU Affero General Public License. 553 | 554 | Notwithstanding any other provision of this License, you have 555 | permission to link or combine any covered work with a work licensed 556 | under version 3 of the GNU Affero General Public License into a single 557 | combined work, and to convey the resulting work. The terms of this 558 | License will continue to apply to the part which is the covered work, 559 | but the special requirements of the GNU Affero General Public License, 560 | section 13, concerning interaction through a network will apply to the 561 | combination as such. 562 | 563 | 14. Revised Versions of this License. 564 | 565 | The Free Software Foundation may publish revised and/or new versions of 566 | the GNU General Public License from time to time. Such new versions will 567 | be similar in spirit to the present version, but may differ in detail to 568 | address new problems or concerns. 569 | 570 | Each version is given a distinguishing version number. If the 571 | Program specifies that a certain numbered version of the GNU General 572 | Public License "or any later version" applies to it, you have the 573 | option of following the terms and conditions either of that numbered 574 | version or of any later version published by the Free Software 575 | Foundation. If the Program does not specify a version number of the 576 | GNU General Public License, you may choose any version ever published 577 | by the Free Software Foundation. 578 | 579 | If the Program specifies that a proxy can decide which future 580 | versions of the GNU General Public License can be used, that proxy's 581 | public statement of acceptance of a version permanently authorizes you 582 | to choose that version for the Program. 583 | 584 | Later license versions may give you additional or different 585 | permissions. However, no additional obligations are imposed on any 586 | author or copyright holder as a result of your choosing to follow a 587 | later version. 588 | 589 | 15. Disclaimer of Warranty. 590 | 591 | THERE IS NO WARRANTY FOR THE PROGRAM, TO THE EXTENT PERMITTED BY 592 | APPLICABLE LAW. EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT 593 | HOLDERS AND/OR OTHER PARTIES PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY 594 | OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, 595 | THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 596 | PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE PROGRAM 597 | IS WITH YOU. SHOULD THE PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF 598 | ALL NECESSARY SERVICING, REPAIR OR CORRECTION. 599 | 600 | 16. Limitation of Liability. 601 | 602 | IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING 603 | WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MODIFIES AND/OR CONVEYS 604 | THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, INCLUDING ANY 605 | GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE 606 | USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED TO LOSS OF 607 | DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD 608 | PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER PROGRAMS), 609 | EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF 610 | SUCH DAMAGES. 611 | 612 | 17. Interpretation of Sections 15 and 16. 613 | 614 | If the disclaimer of warranty and limitation of liability provided 615 | above cannot be given local legal effect according to their terms, 616 | reviewing courts shall apply local law that most closely approximates 617 | an absolute waiver of all civil liability in connection with the 618 | Program, unless a warranty or assumption of liability accompanies a 619 | copy of the Program in return for a fee. 620 | 621 | END OF TERMS AND CONDITIONS 622 | 623 | How to Apply These Terms to Your New Programs 624 | 625 | If you develop a new program, and you want it to be of the greatest 626 | possible use to the public, the best way to achieve this is to make it 627 | free software which everyone can redistribute and change under these terms. 628 | 629 | To do so, attach the following notices to the program. It is safest 630 | to attach them to the start of each source file to most effectively 631 | state the exclusion of warranty; and each file should have at least 632 | the "copyright" line and a pointer to where the full notice is found. 633 | 634 | 635 | Copyright (C) 636 | 637 | This program is free software: you can redistribute it and/or modify 638 | it under the terms of the GNU General Public License as published by 639 | the Free Software Foundation, either version 3 of the License, or 640 | (at your option) any later version. 641 | 642 | This program is distributed in the hope that it will be useful, 643 | but WITHOUT ANY WARRANTY; without even the implied warranty of 644 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 645 | GNU General Public License for more details. 646 | 647 | You should have received a copy of the GNU General Public License 648 | along with this program. If not, see . 649 | 650 | Also add information on how to contact you by electronic and paper mail. 651 | 652 | If the program does terminal interaction, make it output a short 653 | notice like this when it starts in an interactive mode: 654 | 655 | Copyright (C) 656 | This program comes with ABSOLUTELY NO WARRANTY; for details type `show w'. 657 | This is free software, and you are welcome to redistribute it 658 | under certain conditions; type `show c' for details. 659 | 660 | The hypothetical commands `show w' and `show c' should show the appropriate 661 | parts of the General Public License. Of course, your program's commands 662 | might be different; for a GUI interface, you would use an "about box". 663 | 664 | You should also get your employer (if you work as a programmer) or school, 665 | if any, to sign a "copyright disclaimer" for the program, if necessary. 666 | For more information on this, and how to apply and follow the GNU GPL, see 667 | . 668 | 669 | The GNU General Public License does not permit incorporating your program 670 | into proprietary programs. If your program is a subroutine library, you 671 | may consider it more useful to permit linking proprietary applications with 672 | the library. If this is what you want to do, use the GNU Lesser General 673 | Public License instead of this License. But first, please read 674 | . 675 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # YamlConfiguration 2 | 3 | YamlConfiguration is a library for creating and editing YAML files for configurations to be used in Java programs. In addition, it also provides the ability to use in-memory-only Configurations for internal functions, as needed. 4 | 5 | It is based off of [SpigotMC's Bukkit](https://hub.spigotmc.org/stash/projects/SPIGOT/repos/bukkit/browse/src/main/java/org/bukkit/configuration) configuration sub-project, which stems from the original [Bukkit Project](https://github.com/Bukkit/Bukkit/tree/master/src/main/java/org/bukkit/configuration/). 6 | 7 | ## Obtaining YamlConfiguration 8 | 9 | You can obtain a copy of YamlConfiguration via the following methods: 10 | - Download a pre-built copy from the [Releases page](https://github.com/bspfsystems/YamlConfiguration/releases/latest/). The latest version is release 3.0.2. 11 | - Build from source (see below). 12 | - Include it as a dependency in your project (see the Development API section). 13 | - 14 | ### Build from Source 15 | 16 | YamlConfiguration uses [Apache Maven](https://maven.apache.org/) to build and handle dependencies. 17 | 18 | #### Requirements 19 | 20 | - Java Development Kit (JDK) 17 or higher 21 | - Git 22 | - Apache Maven 23 | 24 | #### Compile / Build 25 | 26 | Run the following commands to build the library `.jar` file: 27 | ``` 28 | git clone https://github.com/bspfsystems/YamlConfiguration.git 29 | cd YamlConfiguration/ 30 | mvn clean install 31 | ``` 32 | 33 | The `.jar` file will be located in the `target/` folder. 34 | 35 | ## Developer API 36 | 37 | ### Add YamlConfiguration as a Dependency 38 | 39 | To add YamlConfiguration as a dependency to your project, use one of the following common methods (you may use others that exist, these are the common ones): 40 | 41 | **Maven:**
42 | Include the following in your `pom.xml` file:
43 | ``` 44 | 45 | 46 | sonatype-repo 47 | https://oss.sonatype.org/content/repositories/releases/ 48 | 49 | 50 | 51 | 52 | 53 | org.bspfsystems 54 | yamlconfiguration 55 | 3.0.2 56 | compile 57 | 58 | 59 | ``` 60 | 61 | **Gradle:**
62 | Include the following in your `build.gradle` file:
63 | ``` 64 | repositories { 65 | maven { 66 | url "https://oss.sonatype.org/content/repositories/releases/" 67 | } 68 | } 69 | 70 | dependencies { 71 | implementation "org.bspfsystems:yamlconfiguration:3.0.2" 72 | } 73 | ``` 74 | 75 | ### API Examples 76 | 77 | These are some basic usages of YamlConfiguration; for a full scope of what the library offers, please see the Javadocs section below. 78 | ``` 79 | // Load a file into memory 80 | YamlConfiguration config = new YamlConfiguration(); 81 | try { 82 | config.load(new File("config.yml")); 83 | } catch (IOException | InvalidConfigurationException e) { 84 | e.printStackTrace(); 85 | } 86 | 87 | // Set a few values in the configuration 88 | config.set("random_int", (new Random()).nextInt()); 89 | config.set("uuid", UUID.randomUUID().toString()); 90 | 91 | // Read a value 92 | System.out.println("UUID: " + config.getString("uuid")); 93 | 94 | // Save to a file 95 | try { 96 | config.save(new File("newconfig.yml")); 97 | } catch (IOException e) { 98 | e.printStackTrace(); 99 | } 100 | ``` 101 | 102 | ### Javadocs 103 | 104 | The API Javadocs can be found [here](https://bspfsystems.org/docs/yamlconfiguration/), kindly hosted by [javadoc.io](https://javadoc.io/). 105 | 106 | ## Contributing, Support, and Issues 107 | 108 | Please check out [CONTRIBUTING.md](CONTRIBUTING.md) for more information. 109 | 110 | ## Licensing 111 | 112 | YamlConfiguration uses the following licenses: 113 | - [The GNU General Public License, Version 3](https://www.gnu.org/licences/gpl-3.0.en.html) 114 | 115 | ### Contributions & Licensing 116 | 117 | Contributions to the project will remain licensed under the respective license, as defined by the particular license. Copyright/ownership of the contributions shall be governed by the license. The use of an open source license in the hopes that contributions to the project will have better clarity on legal rights of those contributions. 118 | 119 | _Please Note: This is not legal advice. If you are unsure on what your rights are, please consult a lawyer._ 120 | -------------------------------------------------------------------------------- /mvnw: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | # ---------------------------------------------------------------------------- 3 | # Licensed to the Apache Software Foundation (ASF) under one 4 | # or more contributor license agreements. See the NOTICE file 5 | # distributed with this work for additional information 6 | # regarding copyright ownership. The ASF licenses this file 7 | # to you under the Apache License, Version 2.0 (the 8 | # "License"); you may not use this file except in compliance 9 | # with the License. You may obtain a copy of the License at 10 | # 11 | # http://www.apache.org/licenses/LICENSE-2.0 12 | # 13 | # Unless required by applicable law or agreed to in writing, 14 | # software distributed under the License is distributed on an 15 | # "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 16 | # KIND, either express or implied. See the License for the 17 | # specific language governing permissions and limitations 18 | # under the License. 19 | # ---------------------------------------------------------------------------- 20 | 21 | # ---------------------------------------------------------------------------- 22 | # Apache Maven Wrapper startup batch script, version 3.2.0 23 | # 24 | # Required ENV vars: 25 | # ------------------ 26 | # JAVA_HOME - location of a JDK home dir 27 | # 28 | # Optional ENV vars 29 | # ----------------- 30 | # MAVEN_OPTS - parameters passed to the Java VM when running Maven 31 | # e.g. to debug Maven itself, use 32 | # set MAVEN_OPTS=-Xdebug -Xrunjdwp:transport=dt_socket,server=y,suspend=y,address=8000 33 | # MAVEN_SKIP_RC - flag to disable loading of mavenrc files 34 | # ---------------------------------------------------------------------------- 35 | 36 | if [ -z "$MAVEN_SKIP_RC" ] ; then 37 | 38 | if [ -f /usr/local/etc/mavenrc ] ; then 39 | . /usr/local/etc/mavenrc 40 | fi 41 | 42 | if [ -f /etc/mavenrc ] ; then 43 | . /etc/mavenrc 44 | fi 45 | 46 | if [ -f "$HOME/.mavenrc" ] ; then 47 | . "$HOME/.mavenrc" 48 | fi 49 | 50 | fi 51 | 52 | # OS specific support. $var _must_ be set to either true or false. 53 | cygwin=false; 54 | darwin=false; 55 | mingw=false 56 | case "$(uname)" in 57 | CYGWIN*) cygwin=true ;; 58 | MINGW*) mingw=true;; 59 | Darwin*) darwin=true 60 | # Use /usr/libexec/java_home if available, otherwise fall back to /Library/Java/Home 61 | # See https://developer.apple.com/library/mac/qa/qa1170/_index.html 62 | if [ -z "$JAVA_HOME" ]; then 63 | if [ -x "/usr/libexec/java_home" ]; then 64 | JAVA_HOME="$(/usr/libexec/java_home)"; export JAVA_HOME 65 | else 66 | JAVA_HOME="/Library/Java/Home"; export JAVA_HOME 67 | fi 68 | fi 69 | ;; 70 | esac 71 | 72 | if [ -z "$JAVA_HOME" ] ; then 73 | if [ -r /etc/gentoo-release ] ; then 74 | JAVA_HOME=$(java-config --jre-home) 75 | fi 76 | fi 77 | 78 | # For Cygwin, ensure paths are in UNIX format before anything is touched 79 | if $cygwin ; then 80 | [ -n "$JAVA_HOME" ] && 81 | JAVA_HOME=$(cygpath --unix "$JAVA_HOME") 82 | [ -n "$CLASSPATH" ] && 83 | CLASSPATH=$(cygpath --path --unix "$CLASSPATH") 84 | fi 85 | 86 | # For Mingw, ensure paths are in UNIX format before anything is touched 87 | if $mingw ; then 88 | [ -n "$JAVA_HOME" ] && [ -d "$JAVA_HOME" ] && 89 | JAVA_HOME="$(cd "$JAVA_HOME" || (echo "cannot cd into $JAVA_HOME."; exit 1); pwd)" 90 | fi 91 | 92 | if [ -z "$JAVA_HOME" ]; then 93 | javaExecutable="$(which javac)" 94 | if [ -n "$javaExecutable" ] && ! [ "$(expr "\"$javaExecutable\"" : '\([^ ]*\)')" = "no" ]; then 95 | # readlink(1) is not available as standard on Solaris 10. 96 | readLink=$(which readlink) 97 | if [ ! "$(expr "$readLink" : '\([^ ]*\)')" = "no" ]; then 98 | if $darwin ; then 99 | javaHome="$(dirname "\"$javaExecutable\"")" 100 | javaExecutable="$(cd "\"$javaHome\"" && pwd -P)/javac" 101 | else 102 | javaExecutable="$(readlink -f "\"$javaExecutable\"")" 103 | fi 104 | javaHome="$(dirname "\"$javaExecutable\"")" 105 | javaHome=$(expr "$javaHome" : '\(.*\)/bin') 106 | JAVA_HOME="$javaHome" 107 | export JAVA_HOME 108 | fi 109 | fi 110 | fi 111 | 112 | if [ -z "$JAVACMD" ] ; then 113 | if [ -n "$JAVA_HOME" ] ; then 114 | if [ -x "$JAVA_HOME/jre/sh/java" ] ; then 115 | # IBM's JDK on AIX uses strange locations for the executables 116 | JAVACMD="$JAVA_HOME/jre/sh/java" 117 | else 118 | JAVACMD="$JAVA_HOME/bin/java" 119 | fi 120 | else 121 | JAVACMD="$(\unset -f command 2>/dev/null; \command -v java)" 122 | fi 123 | fi 124 | 125 | if [ ! -x "$JAVACMD" ] ; then 126 | echo "Error: JAVA_HOME is not defined correctly." >&2 127 | echo " We cannot execute $JAVACMD" >&2 128 | exit 1 129 | fi 130 | 131 | if [ -z "$JAVA_HOME" ] ; then 132 | echo "Warning: JAVA_HOME environment variable is not set." 133 | fi 134 | 135 | # traverses directory structure from process work directory to filesystem root 136 | # first directory with .mvn subdirectory is considered project base directory 137 | find_maven_basedir() { 138 | if [ -z "$1" ] 139 | then 140 | echo "Path not specified to find_maven_basedir" 141 | return 1 142 | fi 143 | 144 | basedir="$1" 145 | wdir="$1" 146 | while [ "$wdir" != '/' ] ; do 147 | if [ -d "$wdir"/.mvn ] ; then 148 | basedir=$wdir 149 | break 150 | fi 151 | # workaround for JBEAP-8937 (on Solaris 10/Sparc) 152 | if [ -d "${wdir}" ]; then 153 | wdir=$(cd "$wdir/.." || exit 1; pwd) 154 | fi 155 | # end of workaround 156 | done 157 | printf '%s' "$(cd "$basedir" || exit 1; pwd)" 158 | } 159 | 160 | # concatenates all lines of a file 161 | concat_lines() { 162 | if [ -f "$1" ]; then 163 | # Remove \r in case we run on Windows within Git Bash 164 | # and check out the repository with auto CRLF management 165 | # enabled. Otherwise, we may read lines that are delimited with 166 | # \r\n and produce $'-Xarg\r' rather than -Xarg due to word 167 | # splitting rules. 168 | tr -s '\r\n' ' ' < "$1" 169 | fi 170 | } 171 | 172 | log() { 173 | if [ "$MVNW_VERBOSE" = true ]; then 174 | printf '%s\n' "$1" 175 | fi 176 | } 177 | 178 | BASE_DIR=$(find_maven_basedir "$(dirname "$0")") 179 | if [ -z "$BASE_DIR" ]; then 180 | exit 1; 181 | fi 182 | 183 | MAVEN_PROJECTBASEDIR=${MAVEN_BASEDIR:-"$BASE_DIR"}; export MAVEN_PROJECTBASEDIR 184 | log "$MAVEN_PROJECTBASEDIR" 185 | 186 | ########################################################################################## 187 | # Extension to allow automatically downloading the maven-wrapper.jar from Maven-central 188 | # This allows using the maven wrapper in projects that prohibit checking in binary data. 189 | ########################################################################################## 190 | wrapperJarPath="$MAVEN_PROJECTBASEDIR/.mvn/wrapper/maven-wrapper.jar" 191 | if [ -r "$wrapperJarPath" ]; then 192 | log "Found $wrapperJarPath" 193 | else 194 | log "Couldn't find $wrapperJarPath, downloading it ..." 195 | 196 | if [ -n "$MVNW_REPOURL" ]; then 197 | wrapperUrl="$MVNW_REPOURL/org/apache/maven/wrapper/maven-wrapper/3.2.0/maven-wrapper-3.2.0.jar" 198 | else 199 | wrapperUrl="https://repo.maven.apache.org/maven2/org/apache/maven/wrapper/maven-wrapper/3.2.0/maven-wrapper-3.2.0.jar" 200 | fi 201 | while IFS="=" read -r key value; do 202 | # Remove '\r' from value to allow usage on windows as IFS does not consider '\r' as a separator ( considers space, tab, new line ('\n'), and custom '=' ) 203 | safeValue=$(echo "$value" | tr -d '\r') 204 | case "$key" in (wrapperUrl) wrapperUrl="$safeValue"; break ;; 205 | esac 206 | done < "$MAVEN_PROJECTBASEDIR/.mvn/wrapper/maven-wrapper.properties" 207 | log "Downloading from: $wrapperUrl" 208 | 209 | if $cygwin; then 210 | wrapperJarPath=$(cygpath --path --windows "$wrapperJarPath") 211 | fi 212 | 213 | if command -v wget > /dev/null; then 214 | log "Found wget ... using wget" 215 | [ "$MVNW_VERBOSE" = true ] && QUIET="" || QUIET="--quiet" 216 | if [ -z "$MVNW_USERNAME" ] || [ -z "$MVNW_PASSWORD" ]; then 217 | wget $QUIET "$wrapperUrl" -O "$wrapperJarPath" || rm -f "$wrapperJarPath" 218 | else 219 | wget $QUIET --http-user="$MVNW_USERNAME" --http-password="$MVNW_PASSWORD" "$wrapperUrl" -O "$wrapperJarPath" || rm -f "$wrapperJarPath" 220 | fi 221 | elif command -v curl > /dev/null; then 222 | log "Found curl ... using curl" 223 | [ "$MVNW_VERBOSE" = true ] && QUIET="" || QUIET="--silent" 224 | if [ -z "$MVNW_USERNAME" ] || [ -z "$MVNW_PASSWORD" ]; then 225 | curl $QUIET -o "$wrapperJarPath" "$wrapperUrl" -f -L || rm -f "$wrapperJarPath" 226 | else 227 | curl $QUIET --user "$MVNW_USERNAME:$MVNW_PASSWORD" -o "$wrapperJarPath" "$wrapperUrl" -f -L || rm -f "$wrapperJarPath" 228 | fi 229 | else 230 | log "Falling back to using Java to download" 231 | javaSource="$MAVEN_PROJECTBASEDIR/.mvn/wrapper/MavenWrapperDownloader.java" 232 | javaClass="$MAVEN_PROJECTBASEDIR/.mvn/wrapper/MavenWrapperDownloader.class" 233 | # For Cygwin, switch paths to Windows format before running javac 234 | if $cygwin; then 235 | javaSource=$(cygpath --path --windows "$javaSource") 236 | javaClass=$(cygpath --path --windows "$javaClass") 237 | fi 238 | if [ -e "$javaSource" ]; then 239 | if [ ! -e "$javaClass" ]; then 240 | log " - Compiling MavenWrapperDownloader.java ..." 241 | ("$JAVA_HOME/bin/javac" "$javaSource") 242 | fi 243 | if [ -e "$javaClass" ]; then 244 | log " - Running MavenWrapperDownloader.java ..." 245 | ("$JAVA_HOME/bin/java" -cp .mvn/wrapper MavenWrapperDownloader "$wrapperUrl" "$wrapperJarPath") || rm -f "$wrapperJarPath" 246 | fi 247 | fi 248 | fi 249 | fi 250 | ########################################################################################## 251 | # End of extension 252 | ########################################################################################## 253 | 254 | # If specified, validate the SHA-256 sum of the Maven wrapper jar file 255 | wrapperSha256Sum="" 256 | while IFS="=" read -r key value; do 257 | case "$key" in (wrapperSha256Sum) wrapperSha256Sum=$value; break ;; 258 | esac 259 | done < "$MAVEN_PROJECTBASEDIR/.mvn/wrapper/maven-wrapper.properties" 260 | if [ -n "$wrapperSha256Sum" ]; then 261 | wrapperSha256Result=false 262 | if command -v sha256sum > /dev/null; then 263 | if echo "$wrapperSha256Sum $wrapperJarPath" | sha256sum -c > /dev/null 2>&1; then 264 | wrapperSha256Result=true 265 | fi 266 | elif command -v shasum > /dev/null; then 267 | if echo "$wrapperSha256Sum $wrapperJarPath" | shasum -a 256 -c > /dev/null 2>&1; then 268 | wrapperSha256Result=true 269 | fi 270 | else 271 | echo "Checksum validation was requested but neither 'sha256sum' or 'shasum' are available." 272 | echo "Please install either command, or disable validation by removing 'wrapperSha256Sum' from your maven-wrapper.properties." 273 | exit 1 274 | fi 275 | if [ $wrapperSha256Result = false ]; then 276 | echo "Error: Failed to validate Maven wrapper SHA-256, your Maven wrapper might be compromised." >&2 277 | echo "Investigate or delete $wrapperJarPath to attempt a clean download." >&2 278 | echo "If you updated your Maven version, you need to update the specified wrapperSha256Sum property." >&2 279 | exit 1 280 | fi 281 | fi 282 | 283 | MAVEN_OPTS="$(concat_lines "$MAVEN_PROJECTBASEDIR/.mvn/jvm.config") $MAVEN_OPTS" 284 | 285 | # For Cygwin, switch paths to Windows format before running java 286 | if $cygwin; then 287 | [ -n "$JAVA_HOME" ] && 288 | JAVA_HOME=$(cygpath --path --windows "$JAVA_HOME") 289 | [ -n "$CLASSPATH" ] && 290 | CLASSPATH=$(cygpath --path --windows "$CLASSPATH") 291 | [ -n "$MAVEN_PROJECTBASEDIR" ] && 292 | MAVEN_PROJECTBASEDIR=$(cygpath --path --windows "$MAVEN_PROJECTBASEDIR") 293 | fi 294 | 295 | # Provide a "standardized" way to retrieve the CLI args that will 296 | # work with both Windows and non-Windows executions. 297 | MAVEN_CMD_LINE_ARGS="$MAVEN_CONFIG $*" 298 | export MAVEN_CMD_LINE_ARGS 299 | 300 | WRAPPER_LAUNCHER=org.apache.maven.wrapper.MavenWrapperMain 301 | 302 | # shellcheck disable=SC2086 # safe args 303 | exec "$JAVACMD" \ 304 | $MAVEN_OPTS \ 305 | $MAVEN_DEBUG_OPTS \ 306 | -classpath "$MAVEN_PROJECTBASEDIR/.mvn/wrapper/maven-wrapper.jar" \ 307 | "-Dmaven.multiModuleProjectDirectory=${MAVEN_PROJECTBASEDIR}" \ 308 | ${WRAPPER_LAUNCHER} $MAVEN_CONFIG "$@" 309 | -------------------------------------------------------------------------------- /mvnw.cmd: -------------------------------------------------------------------------------- 1 | @REM ---------------------------------------------------------------------------- 2 | @REM Licensed to the Apache Software Foundation (ASF) under one 3 | @REM or more contributor license agreements. See the NOTICE file 4 | @REM distributed with this work for additional information 5 | @REM regarding copyright ownership. The ASF licenses this file 6 | @REM to you under the Apache License, Version 2.0 (the 7 | @REM "License"); you may not use this file except in compliance 8 | @REM with the License. You may obtain a copy of the License at 9 | @REM 10 | @REM http://www.apache.org/licenses/LICENSE-2.0 11 | @REM 12 | @REM Unless required by applicable law or agreed to in writing, 13 | @REM software distributed under the License is distributed on an 14 | @REM "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 15 | @REM KIND, either express or implied. See the License for the 16 | @REM specific language governing permissions and limitations 17 | @REM under the License. 18 | @REM ---------------------------------------------------------------------------- 19 | 20 | @REM ---------------------------------------------------------------------------- 21 | @REM Apache Maven Wrapper startup batch script, version 3.2.0 22 | @REM 23 | @REM Required ENV vars: 24 | @REM JAVA_HOME - location of a JDK home dir 25 | @REM 26 | @REM Optional ENV vars 27 | @REM MAVEN_BATCH_ECHO - set to 'on' to enable the echoing of the batch commands 28 | @REM MAVEN_BATCH_PAUSE - set to 'on' to wait for a keystroke before ending 29 | @REM MAVEN_OPTS - parameters passed to the Java VM when running Maven 30 | @REM e.g. to debug Maven itself, use 31 | @REM set MAVEN_OPTS=-Xdebug -Xrunjdwp:transport=dt_socket,server=y,suspend=y,address=8000 32 | @REM MAVEN_SKIP_RC - flag to disable loading of mavenrc files 33 | @REM ---------------------------------------------------------------------------- 34 | 35 | @REM Begin all REM lines with '@' in case MAVEN_BATCH_ECHO is 'on' 36 | @echo off 37 | @REM set title of command window 38 | title %0 39 | @REM enable echoing by setting MAVEN_BATCH_ECHO to 'on' 40 | @if "%MAVEN_BATCH_ECHO%" == "on" echo %MAVEN_BATCH_ECHO% 41 | 42 | @REM set %HOME% to equivalent of $HOME 43 | if "%HOME%" == "" (set "HOME=%HOMEDRIVE%%HOMEPATH%") 44 | 45 | @REM Execute a user defined script before this one 46 | if not "%MAVEN_SKIP_RC%" == "" goto skipRcPre 47 | @REM check for pre script, once with legacy .bat ending and once with .cmd ending 48 | if exist "%USERPROFILE%\mavenrc_pre.bat" call "%USERPROFILE%\mavenrc_pre.bat" %* 49 | if exist "%USERPROFILE%\mavenrc_pre.cmd" call "%USERPROFILE%\mavenrc_pre.cmd" %* 50 | :skipRcPre 51 | 52 | @setlocal 53 | 54 | set ERROR_CODE=0 55 | 56 | @REM To isolate internal variables from possible post scripts, we use another setlocal 57 | @setlocal 58 | 59 | @REM ==== START VALIDATION ==== 60 | if not "%JAVA_HOME%" == "" goto OkJHome 61 | 62 | echo. 63 | echo Error: JAVA_HOME not found in your environment. >&2 64 | echo Please set the JAVA_HOME variable in your environment to match the >&2 65 | echo location of your Java installation. >&2 66 | echo. 67 | goto error 68 | 69 | :OkJHome 70 | if exist "%JAVA_HOME%\bin\java.exe" goto init 71 | 72 | echo. 73 | echo Error: JAVA_HOME is set to an invalid directory. >&2 74 | echo JAVA_HOME = "%JAVA_HOME%" >&2 75 | echo Please set the JAVA_HOME variable in your environment to match the >&2 76 | echo location of your Java installation. >&2 77 | echo. 78 | goto error 79 | 80 | @REM ==== END VALIDATION ==== 81 | 82 | :init 83 | 84 | @REM Find the project base dir, i.e. the directory that contains the folder ".mvn". 85 | @REM Fallback to current working directory if not found. 86 | 87 | set MAVEN_PROJECTBASEDIR=%MAVEN_BASEDIR% 88 | IF NOT "%MAVEN_PROJECTBASEDIR%"=="" goto endDetectBaseDir 89 | 90 | set EXEC_DIR=%CD% 91 | set WDIR=%EXEC_DIR% 92 | :findBaseDir 93 | IF EXIST "%WDIR%"\.mvn goto baseDirFound 94 | cd .. 95 | IF "%WDIR%"=="%CD%" goto baseDirNotFound 96 | set WDIR=%CD% 97 | goto findBaseDir 98 | 99 | :baseDirFound 100 | set MAVEN_PROJECTBASEDIR=%WDIR% 101 | cd "%EXEC_DIR%" 102 | goto endDetectBaseDir 103 | 104 | :baseDirNotFound 105 | set MAVEN_PROJECTBASEDIR=%EXEC_DIR% 106 | cd "%EXEC_DIR%" 107 | 108 | :endDetectBaseDir 109 | 110 | IF NOT EXIST "%MAVEN_PROJECTBASEDIR%\.mvn\jvm.config" goto endReadAdditionalConfig 111 | 112 | @setlocal EnableExtensions EnableDelayedExpansion 113 | for /F "usebackq delims=" %%a in ("%MAVEN_PROJECTBASEDIR%\.mvn\jvm.config") do set JVM_CONFIG_MAVEN_PROPS=!JVM_CONFIG_MAVEN_PROPS! %%a 114 | @endlocal & set JVM_CONFIG_MAVEN_PROPS=%JVM_CONFIG_MAVEN_PROPS% 115 | 116 | :endReadAdditionalConfig 117 | 118 | SET MAVEN_JAVA_EXE="%JAVA_HOME%\bin\java.exe" 119 | set WRAPPER_JAR="%MAVEN_PROJECTBASEDIR%\.mvn\wrapper\maven-wrapper.jar" 120 | set WRAPPER_LAUNCHER=org.apache.maven.wrapper.MavenWrapperMain 121 | 122 | set WRAPPER_URL="https://repo.maven.apache.org/maven2/org/apache/maven/wrapper/maven-wrapper/3.2.0/maven-wrapper-3.2.0.jar" 123 | 124 | FOR /F "usebackq tokens=1,2 delims==" %%A IN ("%MAVEN_PROJECTBASEDIR%\.mvn\wrapper\maven-wrapper.properties") DO ( 125 | IF "%%A"=="wrapperUrl" SET WRAPPER_URL=%%B 126 | ) 127 | 128 | @REM Extension to allow automatically downloading the maven-wrapper.jar from Maven-central 129 | @REM This allows using the maven wrapper in projects that prohibit checking in binary data. 130 | if exist %WRAPPER_JAR% ( 131 | if "%MVNW_VERBOSE%" == "true" ( 132 | echo Found %WRAPPER_JAR% 133 | ) 134 | ) else ( 135 | if not "%MVNW_REPOURL%" == "" ( 136 | SET WRAPPER_URL="%MVNW_REPOURL%/org/apache/maven/wrapper/maven-wrapper/3.2.0/maven-wrapper-3.2.0.jar" 137 | ) 138 | if "%MVNW_VERBOSE%" == "true" ( 139 | echo Couldn't find %WRAPPER_JAR%, downloading it ... 140 | echo Downloading from: %WRAPPER_URL% 141 | ) 142 | 143 | powershell -Command "&{"^ 144 | "$webclient = new-object System.Net.WebClient;"^ 145 | "if (-not ([string]::IsNullOrEmpty('%MVNW_USERNAME%') -and [string]::IsNullOrEmpty('%MVNW_PASSWORD%'))) {"^ 146 | "$webclient.Credentials = new-object System.Net.NetworkCredential('%MVNW_USERNAME%', '%MVNW_PASSWORD%');"^ 147 | "}"^ 148 | "[Net.ServicePointManager]::SecurityProtocol = [Net.SecurityProtocolType]::Tls12; $webclient.DownloadFile('%WRAPPER_URL%', '%WRAPPER_JAR%')"^ 149 | "}" 150 | if "%MVNW_VERBOSE%" == "true" ( 151 | echo Finished downloading %WRAPPER_JAR% 152 | ) 153 | ) 154 | @REM End of extension 155 | 156 | @REM If specified, validate the SHA-256 sum of the Maven wrapper jar file 157 | SET WRAPPER_SHA_256_SUM="" 158 | FOR /F "usebackq tokens=1,2 delims==" %%A IN ("%MAVEN_PROJECTBASEDIR%\.mvn\wrapper\maven-wrapper.properties") DO ( 159 | IF "%%A"=="wrapperSha256Sum" SET WRAPPER_SHA_256_SUM=%%B 160 | ) 161 | IF NOT %WRAPPER_SHA_256_SUM%=="" ( 162 | powershell -Command "&{"^ 163 | "$hash = (Get-FileHash \"%WRAPPER_JAR%\" -Algorithm SHA256).Hash.ToLower();"^ 164 | "If('%WRAPPER_SHA_256_SUM%' -ne $hash){"^ 165 | " Write-Output 'Error: Failed to validate Maven wrapper SHA-256, your Maven wrapper might be compromised.';"^ 166 | " Write-Output 'Investigate or delete %WRAPPER_JAR% to attempt a clean download.';"^ 167 | " Write-Output 'If you updated your Maven version, you need to update the specified wrapperSha256Sum property.';"^ 168 | " exit 1;"^ 169 | "}"^ 170 | "}" 171 | if ERRORLEVEL 1 goto error 172 | ) 173 | 174 | @REM Provide a "standardized" way to retrieve the CLI args that will 175 | @REM work with both Windows and non-Windows executions. 176 | set MAVEN_CMD_LINE_ARGS=%* 177 | 178 | %MAVEN_JAVA_EXE% ^ 179 | %JVM_CONFIG_MAVEN_PROPS% ^ 180 | %MAVEN_OPTS% ^ 181 | %MAVEN_DEBUG_OPTS% ^ 182 | -classpath %WRAPPER_JAR% ^ 183 | "-Dmaven.multiModuleProjectDirectory=%MAVEN_PROJECTBASEDIR%" ^ 184 | %WRAPPER_LAUNCHER% %MAVEN_CONFIG% %* 185 | if ERRORLEVEL 1 goto error 186 | goto end 187 | 188 | :error 189 | set ERROR_CODE=1 190 | 191 | :end 192 | @endlocal & set ERROR_CODE=%ERROR_CODE% 193 | 194 | if not "%MAVEN_SKIP_RC%"=="" goto skipRcPost 195 | @REM check for post script, once with legacy .bat ending and once with .cmd ending 196 | if exist "%USERPROFILE%\mavenrc_post.bat" call "%USERPROFILE%\mavenrc_post.bat" 197 | if exist "%USERPROFILE%\mavenrc_post.cmd" call "%USERPROFILE%\mavenrc_post.cmd" 198 | :skipRcPost 199 | 200 | @REM pause the script if MAVEN_BATCH_PAUSE is set to 'on' 201 | if "%MAVEN_BATCH_PAUSE%"=="on" pause 202 | 203 | if "%MAVEN_TERMINATE_CMD%"=="on" exit %ERROR_CODE% 204 | 205 | cmd /C exit /B %ERROR_CODE% 206 | -------------------------------------------------------------------------------- /pom.xml: -------------------------------------------------------------------------------- 1 | 29 | 30 | 31 | 4.0.0 32 | 33 | org.bspfsystems 34 | yamlconfiguration 35 | 3.0.3 36 | jar 37 | 38 | YamlConfiguration 39 | Implementation of SnakeYAML to be easy to use with files. 40 | https://github.com/bspfsystems/YamlConfiguration/ 41 | 42 | BSPF Systems, LLC 43 | https://bspfsystems.org/ 44 | 45 | 46 | 47 | 48 | GNU General Public License, Version 3 49 | https://www.gnu.org/licenses/gpl-3.0.en.html 50 | 51 | 52 | 53 | 54 | 55 | The Bukkit Project 56 | https://bukkit.org/ 57 | 58 | 59 | md_5 60 | blog@md-5.net 61 | SpigotMC Pty. Ltd. 62 | https://www.spigotmc.org/ 63 | 64 | 65 | Matt Ciolkosz 66 | mciolkosz@bspfsystems.org 67 | BSPF Systems, LLC 68 | https://bspfsystems.org/ 69 | 70 | 71 | 72 | 73 | scm:git:https://github.com/bspfsystems/YamlConfiguration.git 74 | scm:git:https://github.com/bspfsystems/YamlConfiguration.git 75 | https://github.com/bspfsystems/YamlConfiguration.git 76 | 77 | 78 | 79 | GitHub 80 | https://github.com/bspfsystems/YamlConfiguration/issues/ 81 | 82 | 83 | 84 | 85 | 95 | 96 | 97 | 98 | maven-central 99 | https://repo.maven.apache.org/maven2/ 100 | 101 | 102 | 103 | 104 | 105 | org.jetbrains 106 | annotations 107 | 26.0.2 108 | compile 109 | 110 | 111 | org.slf4j 112 | slf4j-api 113 | 2.0.17 114 | compile 115 | 116 | 117 | org.yaml 118 | snakeyaml 119 | 2.4 120 | compile 121 | 122 | 123 | 124 | 125 | UTF-8 126 | UTF-8 127 | 128 | 129 | 130 | 131 | apache-maven-releases 132 | https://repository.apache.org/content/repositories/releases/ 133 | 134 | 135 | apache-maven-snapshots 136 | https://repository.apache.org/content/repositories/snapshots/ 137 | 138 | 139 | central-sonatype-releases 140 | https://central.sonatype.com/ 141 | 142 | 143 | central-sonatype-snapshots 144 | https://central.sonatype.com/repository/maven-snapshots/ 145 | 146 | 147 | 148 | 149 | 150 | 151 | org.apache.maven.plugins 152 | maven-compiler-plugin 153 | 3.14.0 154 | 155 | 17 156 | 17 157 | 158 | 159 | 160 | org.apache.maven.plugins 161 | maven-source-plugin 162 | 3.3.1 163 | 164 | 165 | attach-sources 166 | 167 | jar-no-fork 168 | 169 | 170 | 171 | 172 | 173 | org.apache.maven.plugins 174 | maven-javadoc-plugin 175 | 3.11.2 176 | 177 | src/main/java 178 | 179 | 180 | 181 | attach-javadocs 182 | 183 | jar 184 | 185 | 186 | 187 | 188 | 189 | org.apache.maven.plugins 190 | maven-gpg-plugin 191 | 3.2.7 192 | 193 | 194 | sign-artifacts 195 | verify 196 | 197 | sign 198 | 199 | 200 | 201 | --pinentry-mode 202 | loopback 203 | 204 | 205 | 206 | 207 | 208 | 209 | org.apache.maven.plugins 210 | maven-deploy-plugin 211 | 3.1.4 212 | 213 | false 214 | 215 | 216 | 217 | org.sonatype.central 218 | central-publishing-maven-plugin 219 | 0.7.0 220 | true 221 | 222 | true 223 | all 224 | published 225 | 226 | 227 | 228 | 229 | 230 | 231 | -------------------------------------------------------------------------------- /src/main/java/module-info.java: -------------------------------------------------------------------------------- 1 | /* 2 | * This file is part of YamlConfiguration. 3 | * 4 | * Implementation of SnakeYAML to be easy to use with files. 5 | * 6 | * Copyright (C) 2010-2014 The Bukkit Project (https://bukkit.org/) 7 | * Copyright (C) 2014-2024 SpigotMC Pty. Ltd. (https://www.spigotmc.org/) 8 | * Copyright (C) 2020-2025 BSPF Systems, LLC (https://bspfsystems.org/) 9 | * 10 | * Many of the files in this project are sourced from the Bukkit API as 11 | * part of The Bukkit Project (https://bukkit.org/), now maintained by 12 | * SpigotMC Pty. Ltd. (https://www.spigotmc.org/). These files can be found 13 | * at https://github.com/Bukkit/Bukkit/ and https://hub.spigotmc.org/stash/, 14 | * respectively. 15 | * 16 | * This program is free software: you can redistribute it and/or modify 17 | * it under the terms of the GNU General Public License as published by 18 | * the Free Software Foundation, either version 3 of the License, or 19 | * (at your option) any later version. 20 | * 21 | * This program is distributed in the hope that it will be useful, 22 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 23 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 24 | * GNU General Public License for more details. 25 | * 26 | * You should have received a copy of the GNU General Public License 27 | * along with this program. If not, see . 28 | */ 29 | 30 | /** 31 | * Declares the YAML configuration module and handles dependencies and exports. 32 | */ 33 | module org.bspfsystems.yamlconfiguration { 34 | 35 | // Requirements 36 | requires org.jetbrains.annotations; 37 | requires org.slf4j; 38 | requires org.yaml.snakeyaml; 39 | 40 | // Full Exports 41 | exports org.bspfsystems.yamlconfiguration.configuration; 42 | exports org.bspfsystems.yamlconfiguration.file; 43 | exports org.bspfsystems.yamlconfiguration.serialization; 44 | } 45 | -------------------------------------------------------------------------------- /src/main/java/org/bspfsystems/yamlconfiguration/configuration/Configuration.java: -------------------------------------------------------------------------------- 1 | /* 2 | * This file is part of YamlConfiguration. 3 | * 4 | * Implementation of SnakeYAML to be easy to use with files. 5 | * 6 | * Copyright (C) 2010-2014 The Bukkit Project (https://bukkit.org/) 7 | * Copyright (C) 2014-2024 SpigotMC Pty. Ltd. (https://www.spigotmc.org/) 8 | * Copyright (C) 2020-2025 BSPF Systems, LLC (https://bspfsystems.org/) 9 | * 10 | * Many of the files in this project are sourced from the Bukkit API as 11 | * part of The Bukkit Project (https://bukkit.org/), now maintained by 12 | * SpigotMC Pty. Ltd. (https://www.spigotmc.org/). These files can be found 13 | * at https://github.com/Bukkit/Bukkit/ and https://hub.spigotmc.org/stash/, 14 | * respectively. 15 | * 16 | * This program is free software: you can redistribute it and/or modify 17 | * it under the terms of the GNU General Public License as published by 18 | * the Free Software Foundation, either version 3 of the License, or 19 | * (at your option) any later version. 20 | * 21 | * This program is distributed in the hope that it will be useful, 22 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 23 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 24 | * GNU General Public License for more details. 25 | * 26 | * You should have received a copy of the GNU General Public License 27 | * along with this program. If not, see . 28 | */ 29 | 30 | package org.bspfsystems.yamlconfiguration.configuration; 31 | 32 | import java.util.Map; 33 | import org.jetbrains.annotations.NotNull; 34 | import org.jetbrains.annotations.Nullable; 35 | 36 | /** 37 | * Represents a source of configurable options and settings. 38 | *

39 | * Synchronized with the commit on 28-April-2019. 40 | */ 41 | public interface Configuration extends ConfigurationSection { 42 | 43 | /** 44 | * Sets the default value of the given path as provided. 45 | *

46 | * If no source configuration was provided as a default collection, then a 47 | * new memory configuration will be created to hold the given default value. 48 | *

49 | * If value is {@code null}, the value will be removed from the default 50 | * configuration source. 51 | * 52 | * @param path The path of the value to set. 53 | * @param value The value to set the default to. 54 | * @throws IllegalArgumentException Thrown if the path is {@code null}. 55 | */ 56 | @Override 57 | void addDefault(@NotNull final String path, @Nullable final Object value) throws IllegalArgumentException; 58 | 59 | /** 60 | * Sets the default values of the given paths as provided. 61 | *

62 | * If no source configuration was provided as a default collection, then a 63 | * new memory configuration will be created to hold the given default 64 | * values. 65 | * 66 | * @param defs A map of paths to values to add to the defaults. 67 | */ 68 | void addDefaults(@NotNull final Map defs); 69 | 70 | /** 71 | * Sets the default values of the given paths as provided. 72 | *

73 | * If no source configuration was provided as a default collection, then a 74 | * new memory configuration will be created to hold the given default 75 | * values. 76 | *

77 | * This method will not hold a reference to the given configuration, nor 78 | * will it automatically update if the given configuration ever changes. If 79 | * the automatic updates are required, please set the default source with 80 | * {@link Configuration#setDefaults(Configuration)}. 81 | * 82 | * @param defs A configuration holding a map of defaults to copy. 83 | */ 84 | void addDefaults(@NotNull final Configuration defs); 85 | 86 | /** 87 | * Sets the source of all default values for this configuration. 88 | *

89 | * If a previous source was set, or previous default values were defined, 90 | * then they will not be copied to the new source. 91 | * 92 | * @param defs New source of default values for this configuration. 93 | */ 94 | void setDefaults(@NotNull final Configuration defs); 95 | 96 | /** 97 | * Gets the default configuration for this configuration. 98 | *

99 | * If no configuration source was set, but default values were added, then 100 | * a memory configuration will be returned. If no source was set and no 101 | * defaults were set, then this method will return {@code null}. 102 | * 103 | * @return The configuration source for default values, or {@code null} if 104 | * none exist. 105 | */ 106 | @Nullable 107 | Configuration getDefaults(); 108 | 109 | /** 110 | * Gets the options for this configuration. 111 | *

112 | * All setters through this method are chainable. 113 | * 114 | * @return The options for this configuration. 115 | */ 116 | @NotNull 117 | ConfigurationOptions getOptions(); 118 | } 119 | -------------------------------------------------------------------------------- /src/main/java/org/bspfsystems/yamlconfiguration/configuration/ConfigurationOptions.java: -------------------------------------------------------------------------------- 1 | /* 2 | * This file is part of YamlConfiguration. 3 | * 4 | * Implementation of SnakeYAML to be easy to use with files. 5 | * 6 | * Copyright (C) 2010-2014 The Bukkit Project (https://bukkit.org/) 7 | * Copyright (C) 2014-2024 SpigotMC Pty. Ltd. (https://www.spigotmc.org/) 8 | * Copyright (C) 2020-2025 BSPF Systems, LLC (https://bspfsystems.org/) 9 | * 10 | * Many of the files in this project are sourced from the Bukkit API as 11 | * part of The Bukkit Project (https://bukkit.org/), now maintained by 12 | * SpigotMC Pty. Ltd. (https://www.spigotmc.org/). These files can be found 13 | * at https://github.com/Bukkit/Bukkit/ and https://hub.spigotmc.org/stash/, 14 | * respectively. 15 | * 16 | * This program is free software: you can redistribute it and/or modify 17 | * it under the terms of the GNU General Public License as published by 18 | * the Free Software Foundation, either version 3 of the License, or 19 | * (at your option) any later version. 20 | * 21 | * This program is distributed in the hope that it will be useful, 22 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 23 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 24 | * GNU General Public License for more details. 25 | * 26 | * You should have received a copy of the GNU General Public License 27 | * along with this program. If not, see . 28 | */ 29 | 30 | package org.bspfsystems.yamlconfiguration.configuration; 31 | 32 | import org.jetbrains.annotations.NotNull; 33 | 34 | /** 35 | * Represents the various settings for controlling the input and output of a 36 | * configuration. 37 | *

38 | * Synchronized with the commit on 13-March-2019. 39 | */ 40 | public class ConfigurationOptions { 41 | 42 | public static final char DEFAULT_PATH_SEPARATOR = '.'; 43 | public static final boolean DEFAULT_COPY_DEFAULTS = false; 44 | 45 | private final Configuration configuration; 46 | 47 | private char pathSeparator; 48 | private boolean copyDefaults; 49 | 50 | /** 51 | * Constructs a set of configuration options. 52 | * 53 | * @param configuration The configuration to create the options for. 54 | */ 55 | protected ConfigurationOptions(@NotNull final Configuration configuration) { 56 | this.configuration = configuration; 57 | this.pathSeparator = DEFAULT_PATH_SEPARATOR; 58 | this.copyDefaults = DEFAULT_COPY_DEFAULTS; 59 | } 60 | 61 | /** 62 | * Gets the configuration that these options controls. 63 | * 64 | * @return The configuration that these options controls. 65 | */ 66 | @NotNull 67 | public Configuration getConfiguration() { 68 | return this.configuration; 69 | } 70 | 71 | /** 72 | * Gets the {@code char} that will be used to separate configuration 73 | * sections. 74 | *

75 | * This value does not affect how the configuration is stored, only in how 76 | * you access the data. 77 | *

78 | * The default value is {@code .}. 79 | * 80 | * @return The {@code char} used to separate configuration sections. 81 | */ 82 | public final char getPathSeparator() { 83 | return this.pathSeparator; 84 | } 85 | 86 | /** 87 | * Sets the {@code char} that will be used to separate configuration 88 | * sections. 89 | *

90 | * This value does not affect how the configuration is stored, only in how 91 | * you access the data. 92 | *

93 | * The default value is {@code .}. 94 | * 95 | * @param pathSeparator The {@code char} used to separate configuration 96 | * sections. 97 | * @return These options, for chaining. 98 | */ 99 | @NotNull 100 | public ConfigurationOptions setPathSeparator(final char pathSeparator) { 101 | this.pathSeparator = pathSeparator; 102 | return this; 103 | } 104 | 105 | /** 106 | * Checks if the configuration should copy values from its default 107 | * configuration directly. 108 | *

109 | * If this is {@code true}, all values in the default configuration will be 110 | * directly copied, making it impossible to distinguish between values that 111 | * were set and values that are provided by default. As a result, 112 | * {@link ConfigurationSection#contains(String)} will always return the same 113 | * value as {@link ConfigurationSection#isSet(String)}. 114 | *

115 | * The default value is {@code false}. 116 | * 117 | * @return {@code true} if the default values should be copied, 118 | * {@code false} otherwise. 119 | */ 120 | public final boolean getCopyDefaults() { 121 | return this.copyDefaults; 122 | } 123 | 124 | /** 125 | * Sets if the configuration should copy values from its default 126 | * configuration directly. 127 | *

128 | * If this is {@code true}, all values in the default configuration will be 129 | * directly copied, making it impossible to distinguish between values that 130 | * were set and values that are provided by default. As a result, 131 | * {@link ConfigurationSection#contains(String)} will always return the same 132 | * value as {@link ConfigurationSection#isSet(String)}. 133 | *

134 | * The default value is {@code false}. 135 | * 136 | * @param copyDefaults {@code true} if the default values should be copied, 137 | * {@code false} otherwise. 138 | * @return These options, for chaining. 139 | */ 140 | @NotNull 141 | public ConfigurationOptions setCopyDefaults(final boolean copyDefaults) { 142 | this.copyDefaults = copyDefaults; 143 | return this; 144 | } 145 | } 146 | -------------------------------------------------------------------------------- /src/main/java/org/bspfsystems/yamlconfiguration/configuration/InvalidConfigurationException.java: -------------------------------------------------------------------------------- 1 | /* 2 | * This file is part of YamlConfiguration. 3 | * 4 | * Implementation of SnakeYAML to be easy to use with files. 5 | * 6 | * Copyright (C) 2010-2014 The Bukkit Project (https://bukkit.org/) 7 | * Copyright (C) 2014-2024 SpigotMC Pty. Ltd. (https://www.spigotmc.org/) 8 | * Copyright (C) 2020-2025 BSPF Systems, LLC (https://bspfsystems.org/) 9 | * 10 | * Many of the files in this project are sourced from the Bukkit API as 11 | * part of The Bukkit Project (https://bukkit.org/), now maintained by 12 | * SpigotMC Pty. Ltd. (https://www.spigotmc.org/). These files can be found 13 | * at https://github.com/Bukkit/Bukkit/ and https://hub.spigotmc.org/stash/, 14 | * respectively. 15 | * 16 | * This program is free software: you can redistribute it and/or modify 17 | * it under the terms of the GNU General Public License as published by 18 | * the Free Software Foundation, either version 3 of the License, or 19 | * (at your option) any later version. 20 | * 21 | * This program is distributed in the hope that it will be useful, 22 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 23 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 24 | * GNU General Public License for more details. 25 | * 26 | * You should have received a copy of the GNU General Public License 27 | * along with this program. If not, see . 28 | */ 29 | 30 | package org.bspfsystems.yamlconfiguration.configuration; 31 | 32 | import java.io.Serial; 33 | import org.jetbrains.annotations.NotNull; 34 | 35 | /** 36 | * An exception thrown when attempting to load an invalid configuration. 37 | *

38 | * Synchronized with the commit on 15-December-2013. 39 | */ 40 | public final class InvalidConfigurationException extends Exception { 41 | 42 | @Serial 43 | private static final long serialVersionUID = 685592388091335686L; 44 | 45 | /** 46 | * Constructs an exception without a message or cause. 47 | * 48 | * @see Exception#Exception() 49 | */ 50 | public InvalidConfigurationException() { 51 | super(); 52 | } 53 | 54 | /** 55 | * Constructs an exception with a message. 56 | * 57 | * @param message The details of the exception. 58 | * @see Exception#Exception(String) 59 | */ 60 | public InvalidConfigurationException(@NotNull final String message) { 61 | super(message); 62 | } 63 | 64 | /** 65 | * Constructs an exception with an upstream cause. 66 | * 67 | * @param cause The cause of the new exception. 68 | * @see Exception#Exception(Throwable) 69 | */ 70 | public InvalidConfigurationException(@NotNull final Throwable cause) { 71 | super(cause); 72 | } 73 | 74 | /** 75 | * Constructs an exception with a message and upstream cause. 76 | * 77 | * @param message The details of the exception. 78 | * @param cause The cause of the new exception. 79 | * @see Exception#Exception(String, Throwable) 80 | */ 81 | public InvalidConfigurationException(@NotNull final String message, @NotNull final Throwable cause) { 82 | super(message, cause); 83 | } 84 | } 85 | -------------------------------------------------------------------------------- /src/main/java/org/bspfsystems/yamlconfiguration/configuration/MemoryConfiguration.java: -------------------------------------------------------------------------------- 1 | /* 2 | * This file is part of YamlConfiguration. 3 | * 4 | * Implementation of SnakeYAML to be easy to use with files. 5 | * 6 | * Copyright (C) 2010-2014 The Bukkit Project (https://bukkit.org/) 7 | * Copyright (C) 2014-2024 SpigotMC Pty. Ltd. (https://www.spigotmc.org/) 8 | * Copyright (C) 2020-2025 BSPF Systems, LLC (https://bspfsystems.org/) 9 | * 10 | * Many of the files in this project are sourced from the Bukkit API as 11 | * part of The Bukkit Project (https://bukkit.org/), now maintained by 12 | * SpigotMC Pty. Ltd. (https://www.spigotmc.org/). These files can be found 13 | * at https://github.com/Bukkit/Bukkit/ and https://hub.spigotmc.org/stash/, 14 | * respectively. 15 | * 16 | * This program is free software: you can redistribute it and/or modify 17 | * it under the terms of the GNU General Public License as published by 18 | * the Free Software Foundation, either version 3 of the License, or 19 | * (at your option) any later version. 20 | * 21 | * This program is distributed in the hope that it will be useful, 22 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 23 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 24 | * GNU General Public License for more details. 25 | * 26 | * You should have received a copy of the GNU General Public License 27 | * along with this program. If not, see . 28 | */ 29 | 30 | package org.bspfsystems.yamlconfiguration.configuration; 31 | 32 | import java.util.Map; 33 | import org.jetbrains.annotations.NotNull; 34 | import org.jetbrains.annotations.Nullable; 35 | 36 | /** 37 | * Represents an implementation of a configuration that exists only in-memory. 38 | * This is useful for providing temporary storage and access to data and for 39 | * providing defaults. 40 | *

41 | * Synchronized with the commit on 07-June-2022. 42 | */ 43 | public class MemoryConfiguration extends MemorySection implements Configuration { 44 | 45 | protected Configuration defs; 46 | protected MemoryConfigurationOptions options; 47 | 48 | /** 49 | * Constructs an empty memory configuration with no default values. 50 | * 51 | * @see MemorySection#MemorySection() 52 | */ 53 | public MemoryConfiguration() { 54 | super(); 55 | } 56 | 57 | /** 58 | * Constructs an empty memory configuration using the given configuration as 59 | * a source for all default values. 60 | * 61 | * @param defs The default value provider configuration. 62 | * @see MemorySection#MemorySection() 63 | */ 64 | public MemoryConfiguration(@Nullable final Configuration defs) { 65 | super(); 66 | this.defs = defs; 67 | } 68 | 69 | /** 70 | * {@inheritDoc} 71 | */ 72 | @Override 73 | public final void addDefault(@NotNull final String path, @Nullable final Object value) { 74 | if (this.defs == null) { 75 | this.defs = new MemoryConfiguration(); 76 | } 77 | this.defs.set(path, value); 78 | } 79 | 80 | /** 81 | * {@inheritDoc} 82 | */ 83 | @Override 84 | public final void addDefaults(@NotNull final Map defs) { 85 | for (final Map.Entry entry : defs.entrySet()) { 86 | this.addDefault(entry.getKey(), entry.getValue()); 87 | } 88 | } 89 | 90 | /** 91 | * {@inheritDoc} 92 | */ 93 | @Override 94 | public final void addDefaults(@NotNull final Configuration defs) { 95 | for (final String key : defs.getKeys(true)) { 96 | if (!defs.isConfigurationSection(key)) { 97 | this.addDefault(key, defs.get(key)); 98 | } 99 | } 100 | } 101 | 102 | /** 103 | * {@inheritDoc} 104 | */ 105 | @Override 106 | public final void setDefaults(@NotNull final Configuration defs) { 107 | this.defs = defs; 108 | } 109 | 110 | /** 111 | * {@inheritDoc} 112 | */ 113 | @Override 114 | @Nullable 115 | public final Configuration getDefaults() { 116 | return this.defs; 117 | } 118 | 119 | /** 120 | * {@inheritDoc} 121 | */ 122 | @Override 123 | @Nullable 124 | public final ConfigurationSection getParent() { 125 | return null; 126 | } 127 | 128 | /** 129 | * {@inheritDoc} 130 | */ 131 | @Override 132 | @NotNull 133 | public MemoryConfigurationOptions getOptions() { 134 | if (this.options == null) { 135 | this.options = new MemoryConfigurationOptions(this); 136 | } 137 | return this.options; 138 | } 139 | } 140 | -------------------------------------------------------------------------------- /src/main/java/org/bspfsystems/yamlconfiguration/configuration/MemoryConfigurationOptions.java: -------------------------------------------------------------------------------- 1 | /* 2 | * This file is part of YamlConfiguration. 3 | * 4 | * Implementation of SnakeYAML to be easy to use with files. 5 | * 6 | * Copyright (C) 2010-2014 The Bukkit Project (https://bukkit.org/) 7 | * Copyright (C) 2014-2024 SpigotMC Pty. Ltd. (https://www.spigotmc.org/) 8 | * Copyright (C) 2020-2025 BSPF Systems, LLC (https://bspfsystems.org/) 9 | * 10 | * Many of the files in this project are sourced from the Bukkit API as 11 | * part of The Bukkit Project (https://bukkit.org/), now maintained by 12 | * SpigotMC Pty. Ltd. (https://www.spigotmc.org/). These files can be found 13 | * at https://github.com/Bukkit/Bukkit/ and https://hub.spigotmc.org/stash/, 14 | * respectively. 15 | * 16 | * This program is free software: you can redistribute it and/or modify 17 | * it under the terms of the GNU General Public License as published by 18 | * the Free Software Foundation, either version 3 of the License, or 19 | * (at your option) any later version. 20 | * 21 | * This program is distributed in the hope that it will be useful, 22 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 23 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 24 | * GNU General Public License for more details. 25 | * 26 | * You should have received a copy of the GNU General Public License 27 | * along with this program. If not, see . 28 | */ 29 | 30 | package org.bspfsystems.yamlconfiguration.configuration; 31 | 32 | import org.jetbrains.annotations.NotNull; 33 | 34 | /** 35 | * Represents the various settings for controlling the input and output of a 36 | * memory configuration. 37 | *

38 | * Synchronized with the commit on 13-March-2019. 39 | */ 40 | public class MemoryConfigurationOptions extends ConfigurationOptions { 41 | 42 | /** 43 | * Constructs a set of memory configuration options. 44 | * 45 | * @param configuration The memory configuration to create the options for. 46 | * @see ConfigurationOptions#ConfigurationOptions(Configuration) 47 | */ 48 | protected MemoryConfigurationOptions(@NotNull final MemoryConfiguration configuration) { 49 | super(configuration); 50 | } 51 | 52 | /** 53 | * {@inheritDoc} 54 | */ 55 | @Override 56 | @NotNull 57 | public MemoryConfiguration getConfiguration() { 58 | return (MemoryConfiguration) super.getConfiguration(); 59 | } 60 | 61 | /** 62 | * {@inheritDoc} 63 | */ 64 | @Override 65 | @NotNull 66 | public MemoryConfigurationOptions setPathSeparator(final char pathSeparator) { 67 | super.setPathSeparator(pathSeparator); 68 | return this; 69 | } 70 | 71 | /** 72 | * {@inheritDoc} 73 | */ 74 | @Override 75 | @NotNull 76 | public MemoryConfigurationOptions setCopyDefaults(final boolean copyDefaults) { 77 | super.setCopyDefaults(copyDefaults); 78 | return this; 79 | } 80 | } 81 | -------------------------------------------------------------------------------- /src/main/java/org/bspfsystems/yamlconfiguration/configuration/SectionPathData.java: -------------------------------------------------------------------------------- 1 | /* 2 | * This file is part of YamlConfiguration. 3 | * 4 | * Implementation of SnakeYAML to be easy to use with files. 5 | * 6 | * Copyright (C) 2010-2014 The Bukkit Project (https://bukkit.org/) 7 | * Copyright (C) 2014-2024 SpigotMC Pty. Ltd. (https://www.spigotmc.org/) 8 | * Copyright (C) 2020-2025 BSPF Systems, LLC (https://bspfsystems.org/) 9 | * 10 | * Many of the files in this project are sourced from the Bukkit API as 11 | * part of The Bukkit Project (https://bukkit.org/), now maintained by 12 | * SpigotMC Pty. Ltd. (https://www.spigotmc.org/). These files can be found 13 | * at https://github.com/Bukkit/Bukkit/ and https://hub.spigotmc.org/stash/, 14 | * respectively. 15 | * 16 | * This program is free software: you can redistribute it and/or modify 17 | * it under the terms of the GNU General Public License as published by 18 | * the Free Software Foundation, either version 3 of the License, or 19 | * (at your option) any later version. 20 | * 21 | * This program is distributed in the hope that it will be useful, 22 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 23 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 24 | * GNU General Public License for more details. 25 | * 26 | * You should have received a copy of the GNU General Public License 27 | * along with this program. If not, see . 28 | */ 29 | 30 | package org.bspfsystems.yamlconfiguration.configuration; 31 | 32 | import java.util.ArrayList; 33 | import java.util.Collections; 34 | import java.util.List; 35 | import org.jetbrains.annotations.NotNull; 36 | import org.jetbrains.annotations.Nullable; 37 | import org.jetbrains.annotations.UnmodifiableView; 38 | 39 | /** 40 | * Represents data that may be stored in a memory section/memory configuration, 41 | * along with any comments that may be associated with it. 42 | *

43 | * Synchronized with the commit on 20-December-2021. 44 | */ 45 | final class SectionPathData { 46 | 47 | private Object data; 48 | private List comments; 49 | private List inLineComments; 50 | 51 | /** 52 | * Constructs a basic section path data with the given data and no comments. 53 | * 54 | * @param data The data for the new section path data. 55 | */ 56 | SectionPathData(@Nullable final Object data) { 57 | this.data = data; 58 | this.comments = Collections.emptyList(); 59 | this.inLineComments = Collections.emptyList(); 60 | } 61 | 62 | /** 63 | * Gets the data stored in this section path data. 64 | * 65 | * @return The data stored in this section path data. 66 | */ 67 | @Nullable 68 | Object getData() { 69 | return this.data; 70 | } 71 | 72 | /** 73 | * Sets the data stored in this section path data. 74 | *

75 | * This will override any previously-set value, regardless of what it was. 76 | * 77 | * @param data The updated data to store. 78 | */ 79 | void setData(@Nullable final Object data) { 80 | this.data = data; 81 | } 82 | 83 | /** 84 | * Gets the comments on this section path data as a list of strings. If no 85 | * comments exist, an empty list will be returned. 86 | *

87 | * For the individual string entries in the list; a {@code null} entry 88 | * represents an empty line, whereas an empty string entry represents an 89 | * empty comment line ({@code #} and nothing else). Each entry in the list 90 | * represents 1 line of comments. 91 | *

92 | * The list cannot be modified. The returned list represents a snapshot of 93 | * the comments at the time the list was returned; any changes to the 94 | * actual comments will not be reflected in this list. 95 | * 96 | * @return The comments for this section path data, where each list entry 97 | * represents 1 line. 98 | */ 99 | @NotNull 100 | @UnmodifiableView 101 | List getComments() { 102 | return this.comments; 103 | } 104 | 105 | /** 106 | * Assigns the given comments to this section path data. If the given list 107 | * is {@code null}, an empty list will be assigned. 108 | *

109 | * For the individual string entries in the list; a {@code null} entry 110 | * represents an empty line, whereas an empty string entry represents an 111 | * empty comment line ({@code #} and nothing else). Each entry in the list 112 | * represents 1 line of comments. 113 | *

114 | * The given list will not be directly saved; instead, a snapshot will be 115 | * taken and used to create an unmodifiable copy internally. Further updates 116 | * to the given list will not result in changes to the comments stored in 117 | * this section path data after this method completes. 118 | *

119 | * Any existing comments will be replaced, regardless of their value(s) 120 | * compared to the new comments. 121 | * 122 | * @param comments The comments to assign to this section path data. 123 | */ 124 | void setComments(@Nullable final List comments) { 125 | this.comments = (comments == null) ? Collections.emptyList() : Collections.unmodifiableList(new ArrayList(comments)); 126 | } 127 | 128 | /** 129 | * Gets the inline comments on this section path data as a list of strings. 130 | * If no inline comments exist, an empty list will be returned. 131 | *

132 | * For the individual string entries in the list; a {@code null} entry 133 | * represents an empty line, whereas an empty string entry represents an 134 | * empty inline comment line ({@code #} and nothing else). Each entry in the 135 | * list represents 1 line of inline comments. 136 | *

137 | * The list cannot be modified. The returned list represents a snapshot of 138 | * the inline comments at the time the list was returned; any changes to the 139 | * actual inline comments will not be reflected in this list. 140 | * 141 | * @return The inline comments for this section path data, where each list 142 | * entry represents 1 line. 143 | */ 144 | @NotNull 145 | List getInlineComments() { 146 | return this.inLineComments; 147 | } 148 | 149 | /** 150 | * Assigns the given inline comments to this section path data. If the given 151 | * list is {@code null}, an empty list will be assigned. 152 | *

153 | * For the individual string entries in the list; a {@code null} entry 154 | * represents an empty line, whereas an empty string entry represents an 155 | * empty inline comment line ({@code #} and nothing else). Each entry in the 156 | * list represents 1 line of inline comments. 157 | *

158 | * The given list will not be directly saved; instead, a snapshot will be 159 | * taken and used to create an unmodifiable copy internally. Further updates 160 | * to the given list will not result in changes to the inline comments 161 | * stored in this section path data after this method completes. 162 | *

163 | * Any existing inline comments will be replaced, regardless of their 164 | * value(s) compared to the new inline comments. 165 | * 166 | * @param inLineComments The inline comments to assign to this section path 167 | * data. 168 | */ 169 | void setInlineComments(@Nullable final List inLineComments) { 170 | this.inLineComments = inLineComments == null ? Collections.emptyList() : Collections.unmodifiableList(new ArrayList(inLineComments)); 171 | } 172 | } 173 | -------------------------------------------------------------------------------- /src/main/java/org/bspfsystems/yamlconfiguration/file/FileConfiguration.java: -------------------------------------------------------------------------------- 1 | /* 2 | * This file is part of YamlConfiguration. 3 | * 4 | * Implementation of SnakeYAML to be easy to use with files. 5 | * 6 | * Copyright (C) 2010-2014 The Bukkit Project (https://bukkit.org/) 7 | * Copyright (C) 2014-2024 SpigotMC Pty. Ltd. (https://www.spigotmc.org/) 8 | * Copyright (C) 2020-2025 BSPF Systems, LLC (https://bspfsystems.org/) 9 | * 10 | * Many of the files in this project are sourced from the Bukkit API as 11 | * part of The Bukkit Project (https://bukkit.org/), now maintained by 12 | * SpigotMC Pty. Ltd. (https://www.spigotmc.org/). These files can be found 13 | * at https://github.com/Bukkit/Bukkit/ and https://hub.spigotmc.org/stash/, 14 | * respectively. 15 | * 16 | * This program is free software: you can redistribute it and/or modify 17 | * it under the terms of the GNU General Public License as published by 18 | * the Free Software Foundation, either version 3 of the License, or 19 | * (at your option) any later version. 20 | * 21 | * This program is distributed in the hope that it will be useful, 22 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 23 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 24 | * GNU General Public License for more details. 25 | * 26 | * You should have received a copy of the GNU General Public License 27 | * along with this program. If not, see . 28 | */ 29 | 30 | package org.bspfsystems.yamlconfiguration.file; 31 | 32 | import java.io.BufferedReader; 33 | import java.io.File; 34 | import java.io.IOException; 35 | import java.io.InputStreamReader; 36 | import java.io.OutputStreamWriter; 37 | import java.io.Reader; 38 | import java.io.Writer; 39 | import java.nio.charset.StandardCharsets; 40 | import java.nio.file.Files; 41 | import org.bspfsystems.yamlconfiguration.configuration.Configuration; 42 | import org.bspfsystems.yamlconfiguration.configuration.InvalidConfigurationException; 43 | import org.bspfsystems.yamlconfiguration.configuration.MemoryConfiguration; 44 | import org.jetbrains.annotations.NotNull; 45 | import org.jetbrains.annotations.Nullable; 46 | 47 | /** 48 | * Represents a base class for all file-based implementations of a memory 49 | * configuration. 50 | *

51 | * Synchronized with the commit on 24-November-2024. 52 | */ 53 | public abstract class FileConfiguration extends MemoryConfiguration { 54 | 55 | /** 56 | * Constructs an empty file configuration with no default values. 57 | * 58 | * @see MemoryConfiguration#MemoryConfiguration() 59 | */ 60 | protected FileConfiguration() { 61 | super(); 62 | } 63 | 64 | /** 65 | * Constructs an empty file configuration using the given configuration as a 66 | * source for all default values. 67 | * 68 | * @param defs The default value provider configuration. 69 | * @see MemoryConfiguration#MemoryConfiguration(Configuration) 70 | */ 71 | protected FileConfiguration(@Nullable final Configuration defs) { 72 | super(defs); 73 | } 74 | 75 | /** 76 | * Saves this file configuration to the given file. 77 | *

78 | * If the given file does not exist, it will attempt to be created. If it 79 | * already exists, any contents will be overwritten, regardless of the old 80 | * or new contents. If it cannot be created or overwritten, an I/O exception 81 | * will be thrown. 82 | *

83 | * This method will save using the UTF-8 charset. 84 | * 85 | * @param file The file to save to. 86 | * @throws IOException If this file configuration cannot be written. 87 | * @see FileConfiguration#saveToString() 88 | */ 89 | public final void save(@NotNull final File file) throws IOException { 90 | 91 | if (!file.exists()) { 92 | if (!file.createNewFile()) { 93 | throw new IOException("File has not been created at " + file.getPath()); 94 | } 95 | } 96 | 97 | final Writer writer = new OutputStreamWriter(Files.newOutputStream(file.toPath()), StandardCharsets.UTF_8); 98 | writer.write(this.saveToString()); 99 | writer.close(); 100 | } 101 | 102 | /** 103 | * Saves this file configuration to the given file. 104 | *

105 | * If the file at the given path does not exist, it will attempt to be 106 | * created. If it already exists, any contents will be overwritten, 107 | * regardless of the old or new contents. If it cannot be created or 108 | * overwritten, an I/O exception will be thrown. 109 | *

110 | * This method will save using the UTF-8 charset. 111 | * 112 | * @param path The path of the file to save to. 113 | * @throws IOException If this file configuration cannot be written. 114 | * @see FileConfiguration#save(File) 115 | */ 116 | public final void save(@NotNull final String path) throws IOException { 117 | this.save(new File(path)); 118 | } 119 | 120 | /** 121 | * Converts this file configuration to a string. 122 | * 123 | * @return A string representing this file configuration. 124 | */ 125 | @NotNull 126 | public abstract String saveToString(); 127 | 128 | /** 129 | * Loads this file configuration from the given reader. 130 | *

131 | * All values contained in-memory in this file configuration will be 132 | * removed, leaving only the file configuration options as well as any 133 | * defaults. The new values will be loaded into memory from the given 134 | * reader. 135 | * 136 | * @param reader The reader used to load this file configuration. 137 | * @throws IOException If the given reader encounters an error. 138 | * @throws InvalidConfigurationException If the data in the reader cannot be 139 | * parsed as a file configuration. 140 | * @see FileConfiguration#loadFromString(String) 141 | */ 142 | public final void load(@NotNull final Reader reader) throws IOException, InvalidConfigurationException { 143 | 144 | final BufferedReader bufferedReader = reader instanceof BufferedReader ? (BufferedReader) reader : new BufferedReader(reader); 145 | final StringBuilder builder = new StringBuilder(); 146 | 147 | try { 148 | String line; 149 | while ((line = bufferedReader.readLine()) != null) { 150 | builder.append(line).append('\n'); 151 | } 152 | } finally { 153 | bufferedReader.close(); 154 | } 155 | 156 | this.loadFromString(builder.toString()); 157 | } 158 | 159 | /** 160 | * Loads this file configuration from the given file. 161 | *

162 | * All values contained in-memory in this file configuration will be 163 | * removed, leaving only the file configuration options as well as any 164 | * defaults. The new values will be loaded into memory from the given file. 165 | * 166 | * @param file The file used to load this file configuration. 167 | * @throws IOException If the given file cannot be read. 168 | * @throws InvalidConfigurationException If the data in the file cannot be 169 | * parsed as a file configuration. 170 | * @see FileConfiguration#load(Reader) 171 | */ 172 | public final void load(@NotNull final File file) throws IOException, InvalidConfigurationException { 173 | this.load(new InputStreamReader(Files.newInputStream(file.toPath()), StandardCharsets.UTF_8)); 174 | } 175 | 176 | /** 177 | * Loads this file configuration from the file at the given path. 178 | *

179 | * All values contained in-memory in this file configuration will be 180 | * removed, leaving only the file configuration options as well as any 181 | * defaults. The new values will be loaded into memory from the file at the 182 | * given path. 183 | * 184 | * @param path The path of the file to load from. 185 | * @throws IOException If the file cannot be read. 186 | * @throws InvalidConfigurationException If the data in the file cannot be 187 | * parsed as a file configuration. 188 | * @see FileConfiguration#load(File) 189 | */ 190 | public final void load(@NotNull final String path) throws IOException, InvalidConfigurationException { 191 | this.load(new File(path)); 192 | } 193 | 194 | /** 195 | * Loads this file configuration from the given string. 196 | *

197 | * All values contained in-memory in this file configuration will be 198 | * removed, leaving only the file configuration options as well as any 199 | * defaults. The new values will be loaded into memory from the given 200 | * string. 201 | * 202 | * @param data The string representation of the file configuration data to 203 | * load. 204 | * @throws InvalidConfigurationException If the given string cannot be 205 | * parsed as a file configuration. 206 | */ 207 | public abstract void loadFromString(@NotNull final String data) throws InvalidConfigurationException; 208 | 209 | /** 210 | * {@inheritDoc} 211 | */ 212 | @Override 213 | @NotNull 214 | public FileConfigurationOptions getOptions() { 215 | if (this.options == null) { 216 | this.options = new FileConfigurationOptions(this); 217 | } 218 | return (FileConfigurationOptions) this.options; 219 | } 220 | } 221 | -------------------------------------------------------------------------------- /src/main/java/org/bspfsystems/yamlconfiguration/file/FileConfigurationOptions.java: -------------------------------------------------------------------------------- 1 | /* 2 | * This file is part of YamlConfiguration. 3 | * 4 | * Implementation of SnakeYAML to be easy to use with files. 5 | * 6 | * Copyright (C) 2010-2014 The Bukkit Project (https://bukkit.org/) 7 | * Copyright (C) 2014-2024 SpigotMC Pty. Ltd. (https://www.spigotmc.org/) 8 | * Copyright (C) 2020-2025 BSPF Systems, LLC (https://bspfsystems.org/) 9 | * 10 | * Many of the files in this project are sourced from the Bukkit API as 11 | * part of The Bukkit Project (https://bukkit.org/), now maintained by 12 | * SpigotMC Pty. Ltd. (https://www.spigotmc.org/). These files can be found 13 | * at https://github.com/Bukkit/Bukkit/ and https://hub.spigotmc.org/stash/, 14 | * respectively. 15 | * 16 | * This program is free software: you can redistribute it and/or modify 17 | * it under the terms of the GNU General Public License as published by 18 | * the Free Software Foundation, either version 3 of the License, or 19 | * (at your option) any later version. 20 | * 21 | * This program is distributed in the hope that it will be useful, 22 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 23 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 24 | * GNU General Public License for more details. 25 | * 26 | * You should have received a copy of the GNU General Public License 27 | * along with this program. If not, see . 28 | */ 29 | 30 | package org.bspfsystems.yamlconfiguration.file; 31 | 32 | import java.util.Collections; 33 | import java.util.List; 34 | import org.bspfsystems.yamlconfiguration.configuration.Configuration; 35 | import org.bspfsystems.yamlconfiguration.configuration.MemoryConfiguration; 36 | import org.bspfsystems.yamlconfiguration.configuration.MemoryConfigurationOptions; 37 | import org.jetbrains.annotations.NotNull; 38 | import org.jetbrains.annotations.Nullable; 39 | import org.jetbrains.annotations.UnmodifiableView; 40 | 41 | /** 42 | * Represents the various settings for controlling the input and output of a 43 | * file configuration. 44 | *

45 | * Synchronized with the commit on 24-November-2024. 46 | */ 47 | public class FileConfigurationOptions extends MemoryConfigurationOptions { 48 | 49 | public static final List DEFAULT_HEADER = Collections.emptyList(); 50 | public static final List DEFAULT_FOOTER = Collections.emptyList(); 51 | public static final boolean DEFAULT_PARSE_COMMENTS = true; 52 | 53 | private List header; 54 | private List footer; 55 | private boolean parseComments; 56 | 57 | /** 58 | * Constructs a set of file configuration options. 59 | * 60 | * @param configuration The file configuration to create the options for. 61 | * @see MemoryConfigurationOptions#MemoryConfigurationOptions(MemoryConfiguration) 62 | */ 63 | protected FileConfigurationOptions(@NotNull final MemoryConfiguration configuration) { 64 | super(configuration); 65 | this.header = DEFAULT_HEADER; 66 | this.footer = DEFAULT_FOOTER; 67 | this.parseComments = DEFAULT_PARSE_COMMENTS; 68 | } 69 | 70 | /** 71 | * {@inheritDoc} 72 | */ 73 | @Override 74 | @NotNull 75 | public FileConfiguration getConfiguration() { 76 | return (FileConfiguration) super.getConfiguration(); 77 | } 78 | 79 | /** 80 | * {@inheritDoc} 81 | */ 82 | @Override 83 | @NotNull 84 | public FileConfigurationOptions setPathSeparator(final char pathSeparator) { 85 | super.setPathSeparator(pathSeparator); 86 | return this; 87 | } 88 | 89 | /** 90 | * {@inheritDoc} 91 | */ 92 | @Override 93 | @NotNull 94 | public FileConfigurationOptions setCopyDefaults(final boolean copyDefaults) { 95 | super.setCopyDefaults(copyDefaults); 96 | return this; 97 | } 98 | 99 | /** 100 | * Gets the header comments that will be saved at the top of the output file 101 | * configuration. If no header comments exist, an empty list will be 102 | * returned. 103 | *

104 | * For the individual string entries in the list; a {@code null} entry 105 | * represents an empty line, whereas an empty string entry represents an 106 | * empty header comment line ({@code #} and nothing else). Each entry in the 107 | * list represents 1 line of header comments. 108 | *

109 | * The list cannot be modified. The returned list represents a snapshot of 110 | * the header comments at the time the list was returned; any changes to the 111 | * actual header comments will not be reflected in this list. 112 | * 113 | * @return The header comments for the file configuration controlled by this 114 | * file configuration options. 115 | */ 116 | @NotNull 117 | @UnmodifiableView 118 | public final List getHeader() { 119 | return this.header; 120 | } 121 | 122 | /** 123 | * Assigns the given header comments to these file configuration options. If 124 | * the given list is {@code null}, an empty list will be assigned. 125 | *

126 | * For the individual string entries in the list; a {@code null} entry 127 | * represents an empty line, whereas an empty string entry represents an 128 | * empty header comment line ({@code #} and nothing else). Each entry in the 129 | * list represents 1 line of header comments. 130 | *

131 | * The given list will not be directly saved; instead, a snapshot will be 132 | * taken and used to create an unmodifiable copy internally. Further updates 133 | * to the given list will not result in changes to the inline comments 134 | * stored in these file configuration options after this method completes. 135 | *

136 | * Any existing header comments will be replaced, regardless of their 137 | * value(s) compared to the new header comments. 138 | * 139 | * @param header The header comments to assign to these file configuration 140 | * options. 141 | * @return These file configuration options, for chaining. 142 | */ 143 | @NotNull 144 | public FileConfigurationOptions setHeader(@Nullable final List header) { 145 | this.header = (header == null) ? DEFAULT_HEADER : Collections.unmodifiableList(header); 146 | return this; 147 | } 148 | 149 | /** 150 | * Gets the footer comments that will be saved at the top of the output file 151 | * configuration. If no footer comments exist, an empty list will be 152 | * returned. 153 | *

154 | * For the individual string entries in the list; a {@code null} entry 155 | * represents an empty line, whereas an empty string entry represents an 156 | * empty footer comment line ({@code #} and nothing else). Each entry in the 157 | * list represents 1 line of footer comments. 158 | *

159 | * The list cannot be modified. The returned list represents a snapshot of 160 | * the footer comments at the time the list was returned; any changes to the 161 | * actual footer comments will not be reflected in this list. 162 | * 163 | * @return The footer comments for the file configuration controlled by this 164 | * file configuration options. 165 | */ 166 | @NotNull 167 | @UnmodifiableView 168 | public final List getFooter() { 169 | return this.footer; 170 | } 171 | 172 | /** 173 | * Assigns the given footer comments to these file configuration options. If 174 | * the given list is {@code null}, an empty list will be assigned. 175 | *

176 | * For the individual string entries in the list; a {@code null} entry 177 | * represents an empty line, whereas an empty string entry represents an 178 | * empty footer comment line ({@code #} and nothing else). Each entry in the 179 | * list represents 1 line of footer comments. 180 | *

181 | * The given list will not be directly saved; instead, a snapshot will be 182 | * taken and used to create an unmodifiable copy internally. Further updates 183 | * to the given list will not result in changes to the inline comments 184 | * stored in these file configuration options after this method completes. 185 | *

186 | * Any existing footer comments will be replaced, regardless of their 187 | * value(s) compared to the new footer comments. 188 | * 189 | * @param footer The footer comments to assign to these file configuration 190 | * options. 191 | * @return These file configuration options, for chaining. 192 | */ 193 | @NotNull 194 | public FileConfigurationOptions setFooter(@Nullable final List footer) { 195 | this.footer = (footer == null) ? DEFAULT_FOOTER : Collections.unmodifiableList(footer); 196 | return this; 197 | } 198 | 199 | /** 200 | * Gets whether the comments (header, block, inline, and/or footer) in a 201 | * file configuration should be loaded and saved. 202 | *

203 | * If this returns {@code true}, and if a default file configuration is 204 | * passed to {@link Configuration#setDefaults(Configuration)}, then upon 205 | * saving, the default comments will be parsed from the passed default file 206 | * configuration, instead of the ones provided in here. 207 | *

208 | * If no default is set on the configuration, or the default is not a file 209 | * configuration, or that configuration has no comments, then the comments 210 | * specified in the original configuration will be used. 211 | *

212 | * The default value is {@code true}. 213 | * 214 | * @return {@code true} if the comments are to be parsed, {@code false} 215 | * otherwise. 216 | */ 217 | public final boolean getParseComments() { 218 | return this.parseComments; 219 | } 220 | 221 | /** 222 | * Sets whether the comments (header, block, inline, and/or footer) in a 223 | * file configuration should be loaded and saved. 224 | *

225 | * If this is {@code true}, and if a default file configuration is passed to 226 | * {@link Configuration#setDefaults(Configuration)}, then upon saving, the 227 | * default comments will be parsed from the passed default file 228 | * configuration, instead of the ones provided in here. 229 | *

230 | * If no default is set on the configuration, or the default is not a file 231 | * configuration, or that configuration has no comments, then the comments 232 | * specified in the original configuration will be used. 233 | *

234 | * The default value is {@code true}. 235 | * 236 | * @param parseComments {@code true} if the comments are to be parsed, 237 | * {@code false} otherwise. 238 | * @return This file configuration options, for chaining. 239 | */ 240 | @NotNull 241 | public FileConfigurationOptions setParseComments(final boolean parseComments) { 242 | this.parseComments = parseComments; 243 | return this; 244 | } 245 | } 246 | -------------------------------------------------------------------------------- /src/main/java/org/bspfsystems/yamlconfiguration/file/YamlConfiguration.java: -------------------------------------------------------------------------------- 1 | /* 2 | * This file is part of YamlConfiguration. 3 | * 4 | * Implementation of SnakeYAML to be easy to use with files. 5 | * 6 | * Copyright (C) 2010-2014 The Bukkit Project (https://bukkit.org/) 7 | * Copyright (C) 2014-2024 SpigotMC Pty. Ltd. (https://www.spigotmc.org/) 8 | * Copyright (C) 2020-2025 BSPF Systems, LLC (https://bspfsystems.org/) 9 | * 10 | * Many of the files in this project are sourced from the Bukkit API as 11 | * part of The Bukkit Project (https://bukkit.org/), now maintained by 12 | * SpigotMC Pty. Ltd. (https://www.spigotmc.org/). These files can be found 13 | * at https://github.com/Bukkit/Bukkit/ and https://hub.spigotmc.org/stash/, 14 | * respectively. 15 | * 16 | * This program is free software: you can redistribute it and/or modify 17 | * it under the terms of the GNU General Public License as published by 18 | * the Free Software Foundation, either version 3 of the License, or 19 | * (at your option) any later version. 20 | * 21 | * This program is distributed in the hope that it will be useful, 22 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 23 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 24 | * GNU General Public License for more details. 25 | * 26 | * You should have received a copy of the GNU General Public License 27 | * along with this program. If not, see . 28 | */ 29 | 30 | package org.bspfsystems.yamlconfiguration.file; 31 | 32 | import java.io.ByteArrayInputStream; 33 | import java.io.File; 34 | import java.io.IOException; 35 | import java.io.Reader; 36 | import java.io.StringWriter; 37 | import java.nio.charset.StandardCharsets; 38 | import java.util.ArrayList; 39 | import java.util.LinkedList; 40 | import java.util.List; 41 | import java.util.Map; 42 | import org.bspfsystems.yamlconfiguration.configuration.Configuration; 43 | import org.bspfsystems.yamlconfiguration.configuration.ConfigurationSection; 44 | import org.bspfsystems.yamlconfiguration.configuration.InvalidConfigurationException; 45 | import org.bspfsystems.yamlconfiguration.serialization.ConfigurationSerialization; 46 | import org.jetbrains.annotations.NotNull; 47 | import org.jetbrains.annotations.Nullable; 48 | import org.slf4j.LoggerFactory; 49 | import org.yaml.snakeyaml.DumperOptions; 50 | import org.yaml.snakeyaml.LoaderOptions; 51 | import org.yaml.snakeyaml.Yaml; 52 | import org.yaml.snakeyaml.comments.CommentLine; 53 | import org.yaml.snakeyaml.comments.CommentType; 54 | import org.yaml.snakeyaml.error.YAMLException; 55 | import org.yaml.snakeyaml.nodes.AnchorNode; 56 | import org.yaml.snakeyaml.nodes.MappingNode; 57 | import org.yaml.snakeyaml.nodes.Node; 58 | import org.yaml.snakeyaml.nodes.NodeTuple; 59 | import org.yaml.snakeyaml.nodes.ScalarNode; 60 | import org.yaml.snakeyaml.nodes.SequenceNode; 61 | import org.yaml.snakeyaml.nodes.Tag; 62 | import org.yaml.snakeyaml.reader.UnicodeReader; 63 | 64 | /** 65 | * Represents an implementation of configuration which saves all files in valid 66 | * YAML format. Please note that this implementation is not synchronized. 67 | *

68 | * Synchronized with the commit on 24-November-2024. 69 | */ 70 | public final class YamlConfiguration extends FileConfiguration { 71 | 72 | private final YamlConstructor yamlConstructor; 73 | private final YamlRepresenter yamlRepresenter; 74 | private final DumperOptions dumperOptions; 75 | private final LoaderOptions loaderOptions; 76 | private final Yaml yaml; 77 | 78 | /** 79 | * Constructs an empty YAML configuration with no default values. 80 | * 81 | * @see FileConfiguration#FileConfiguration() 82 | */ 83 | public YamlConfiguration() { 84 | super(); 85 | 86 | this.dumperOptions = new DumperOptions(); 87 | this.dumperOptions.setDefaultFlowStyle(DumperOptions.FlowStyle.BLOCK); 88 | 89 | this.loaderOptions = new LoaderOptions(); 90 | 91 | this.yamlConstructor = new YamlConstructor(this.loaderOptions); 92 | 93 | this.yamlRepresenter = new YamlRepresenter(this.dumperOptions); 94 | this.yamlRepresenter.setDefaultFlowStyle(DumperOptions.FlowStyle.BLOCK); 95 | 96 | this.yaml = new Yaml(this.yamlConstructor, this.yamlRepresenter, this.dumperOptions, this.loaderOptions); 97 | } 98 | 99 | /** 100 | * Constructs an empty YAML configuration using the given configuration as a 101 | * source for all default values. 102 | * 103 | * @param defs The default value provider configuration 104 | * @see FileConfiguration#FileConfiguration(Configuration) 105 | */ 106 | public YamlConfiguration(@Nullable final Configuration defs) { 107 | super(defs); 108 | 109 | this.dumperOptions = new DumperOptions(); 110 | this.dumperOptions.setDefaultFlowStyle(DumperOptions.FlowStyle.BLOCK); 111 | 112 | this.loaderOptions = new LoaderOptions(); 113 | 114 | this.yamlConstructor = new YamlConstructor(this.loaderOptions); 115 | 116 | this.yamlRepresenter = new YamlRepresenter(this.dumperOptions); 117 | this.yamlRepresenter.setDefaultFlowStyle(DumperOptions.FlowStyle.BLOCK); 118 | 119 | this.yaml = new Yaml(this.yamlConstructor, this.yamlRepresenter, this.dumperOptions, this.loaderOptions); 120 | } 121 | 122 | /** 123 | * {@inheritDoc} 124 | */ 125 | @Override 126 | @NotNull 127 | public String saveToString() { 128 | 129 | this.dumperOptions.setIndent(this.getOptions().getIndent()); 130 | this.dumperOptions.setWidth(this.getOptions().getWidth()); 131 | this.dumperOptions.setProcessComments(this.getOptions().getParseComments()); 132 | 133 | final MappingNode mappingNode = this.toNodeTree(this); 134 | mappingNode.setBlockComments(this.getCommentLines(this.saveHeader(this.getOptions().getHeader()), CommentType.BLOCK)); 135 | mappingNode.setEndComments(this.getCommentLines(this.getOptions().getFooter(), CommentType.BLOCK)); 136 | 137 | final StringWriter writer = new StringWriter(); 138 | if (mappingNode.getBlockComments().isEmpty() && mappingNode.getEndComments().isEmpty() && mappingNode.getValue().isEmpty()) { 139 | writer.write(""); 140 | } else { 141 | if (mappingNode.getValue().isEmpty()) { 142 | mappingNode.setFlowStyle(DumperOptions.FlowStyle.FLOW); 143 | } 144 | this.yaml.serialize(mappingNode, writer); 145 | } 146 | 147 | return writer.toString(); 148 | } 149 | 150 | /** 151 | * Creates a mapping node containing a serialized representation of the data 152 | * in the given configuration section, and then returns the newly-generated 153 | * mapping node. 154 | * 155 | * @param section The configuration section to serialize. 156 | * @return The serialized configuration section as a mapping node. 157 | */ 158 | @NotNull 159 | private MappingNode toNodeTree(@NotNull final ConfigurationSection section) { 160 | 161 | final List nodeTuples = new ArrayList(); 162 | for (final Map.Entry entry : section.getValues(false).entrySet()) { 163 | 164 | final Node keyNode = this.yamlRepresenter.represent(entry.getKey()); 165 | final Node valueNode; 166 | if (entry.getValue() instanceof ConfigurationSection) { 167 | valueNode = this.toNodeTree((ConfigurationSection) entry.getValue()); 168 | } else { 169 | valueNode = this.yamlRepresenter.represent(entry.getValue()); 170 | } 171 | 172 | keyNode.setBlockComments(this.getCommentLines(section.getComments(entry.getKey()), CommentType.BLOCK)); 173 | if (valueNode instanceof MappingNode || valueNode instanceof SequenceNode) { 174 | keyNode.setInLineComments(this.getCommentLines(section.getInlineComments(entry.getKey()), CommentType.IN_LINE)); 175 | } else { 176 | valueNode.setInLineComments(this.getCommentLines(section.getInlineComments(entry.getKey()), CommentType.IN_LINE)); 177 | } 178 | 179 | nodeTuples.add(new NodeTuple(keyNode, valueNode)); 180 | } 181 | 182 | return new MappingNode(Tag.MAP, nodeTuples, DumperOptions.FlowStyle.BLOCK); 183 | } 184 | 185 | /** 186 | * Gets a list of comment lines that are represented by the given list of 187 | * strings and are of the given comment type. 188 | * 189 | * @param comments The list of strings to convert to comment lines. 190 | * @param commentType The type of comments to translate to. 191 | * @return A list of comment lines of the given type translated from the 192 | * given list of strings. 193 | */ 194 | @NotNull 195 | private List getCommentLines(@NotNull final List comments, @NotNull final CommentType commentType) { 196 | 197 | final List commentLines = new ArrayList(); 198 | for (final String comment : comments) { 199 | if (comment == null) { 200 | commentLines.add(new CommentLine(null, null, "", CommentType.BLANK_LINE)); 201 | } else { 202 | String line = comment; 203 | line = line.isEmpty() ? line : " " + line; 204 | commentLines.add(new CommentLine(null, null, line, commentType)); 205 | } 206 | } 207 | 208 | return commentLines; 209 | } 210 | 211 | /** 212 | * Adds an empty line at the end of the header to separate it from any 213 | * further comments. 214 | * 215 | * @param header The unformatted list of header comments (without the blank 216 | * line). 217 | * @return The formatted list of header comments (with the blank line). 218 | */ 219 | @NotNull 220 | private List saveHeader(@NotNull final List header) { 221 | 222 | final LinkedList formattedHeader = new LinkedList(header); 223 | if (!formattedHeader.isEmpty()) { 224 | formattedHeader.add(null); 225 | } 226 | return formattedHeader; 227 | } 228 | 229 | /** 230 | * {@inheritDoc} 231 | */ 232 | @Override 233 | public void loadFromString(@NotNull final String data) throws InvalidConfigurationException { 234 | 235 | this.loaderOptions.setMaxAliasesForCollections(this.getOptions().getMaxAliases()); 236 | this.loaderOptions.setCodePointLimit(this.getOptions().getCodePointLimit()); 237 | this.loaderOptions.setProcessComments(this.getOptions().getParseComments()); 238 | 239 | final MappingNode mappingNode; 240 | try (final Reader reader = new UnicodeReader(new ByteArrayInputStream(data.getBytes(StandardCharsets.UTF_8)))) { 241 | final Node rawNode = this.yaml.compose(reader); 242 | try { 243 | mappingNode = (MappingNode) rawNode; 244 | } catch (final ClassCastException e) { 245 | throw new InvalidConfigurationException("Top level is not a Map.", e); 246 | } 247 | } catch (final YAMLException | IOException | ClassCastException e) { 248 | throw new InvalidConfigurationException(e); 249 | } 250 | 251 | this.clear(); 252 | if (mappingNode != null) { 253 | 254 | this.adjustNodeComments(mappingNode); 255 | this.getOptions().setHeader(this.loadHeader(this.getCommentLines(mappingNode.getBlockComments()))); 256 | this.getOptions().setFooter(this.getCommentLines(mappingNode.getEndComments())); 257 | this.fromNodeTree(mappingNode, this); 258 | } 259 | } 260 | 261 | /** 262 | * This splits the header comments on the last empty line, and sets the 263 | * comments below the given mapping node line as comments for the first key 264 | * in the map. 265 | * 266 | * @param mappingNode The root {@link MappingNode} of the {@link Yaml}. 267 | */ 268 | private void adjustNodeComments(@NotNull final MappingNode mappingNode) { 269 | 270 | if (mappingNode.getBlockComments() == null && !mappingNode.getValue().isEmpty()) { 271 | final Node node = mappingNode.getValue().get(0).getKeyNode(); 272 | final List comments = node.getBlockComments(); 273 | if (comments != null) { 274 | int commentIndex = -1; 275 | for (int index = 0; index < comments.size(); index++) { 276 | if (comments.get(index).getCommentType() == CommentType.BLANK_LINE) { 277 | commentIndex = index; 278 | } 279 | } 280 | if (commentIndex != -1) { 281 | mappingNode.setBlockComments(comments.subList(0, commentIndex + 1)); 282 | node.setBlockComments(comments.subList(commentIndex + 1, comments.size())); 283 | } 284 | } 285 | } 286 | } 287 | 288 | /** 289 | * Gets a list of strings that represent the given list of comment lines. 290 | * 291 | * @param commentLines The list of comment lines to translate into strings. 292 | * @return A list of strings representing the given list of comment lines. 293 | */ 294 | @NotNull 295 | private List getCommentLines(@Nullable final List commentLines) { 296 | 297 | final List comments = new ArrayList(); 298 | if (commentLines == null) { 299 | return comments; 300 | } 301 | 302 | for (final CommentLine commentLine : commentLines) { 303 | if (commentLine.getCommentType() == CommentType.BLANK_LINE) { 304 | comments.add(null); 305 | } else { 306 | String comment = commentLine.getValue(); 307 | comment = comment.startsWith(" ") ? comment.substring(1) : comment; 308 | comments.add(comment); 309 | } 310 | } 311 | 312 | return comments; 313 | } 314 | 315 | /** 316 | * This removes the empty line at the end of the header that separates the 317 | * header from further comments. Additionally, it removes any empty lines at 318 | * the start of the header. 319 | * 320 | * @param formattedHeader The formatted list of header comments (with the 321 | * blank line). 322 | * @return The unformatted list of header comments (without the blank 323 | * line). 324 | */ 325 | @NotNull 326 | private List loadHeader(@NotNull final List formattedHeader) { 327 | 328 | final LinkedList header = new LinkedList(formattedHeader); 329 | if (!header.isEmpty()) { 330 | header.removeLast(); 331 | } 332 | while (!header.isEmpty() && header.peek() == null) { 333 | header.remove(); 334 | } 335 | return header; 336 | } 337 | 338 | /** 339 | * Fills the given configuration section with data, including applicable 340 | * children configuration sections, from the data in the given mapping node. 341 | * 342 | * @param mappingNode The mapping node containing the serialized data. 343 | * @param section The configuration section to fill. 344 | */ 345 | private void fromNodeTree(@NotNull final MappingNode mappingNode, @NotNull final ConfigurationSection section) { 346 | 347 | this.yamlConstructor.flattenMapping(mappingNode); 348 | for (final NodeTuple nodeTuple : mappingNode.getValue()) { 349 | 350 | final Node keyNode = nodeTuple.getKeyNode(); 351 | final String key = String.valueOf(this.yamlConstructor.construct(keyNode)); 352 | Node valueNode = nodeTuple.getValueNode(); 353 | 354 | while (valueNode instanceof AnchorNode) { 355 | valueNode = ((AnchorNode) valueNode).getRealNode(); 356 | } 357 | 358 | if (valueNode instanceof MappingNode && !this.hasSerializedTypeKey((MappingNode) valueNode)) { 359 | this.fromNodeTree((MappingNode) valueNode, section.createSection(key)); 360 | } else { 361 | section.set(key, this.yamlConstructor.construct(valueNode)); 362 | } 363 | 364 | section.setComments(key, this.getCommentLines(keyNode.getBlockComments())); 365 | if (valueNode instanceof MappingNode || valueNode instanceof SequenceNode) { 366 | section.setInlineComments(key, this.getCommentLines(keyNode.getInLineComments())); 367 | } else { 368 | section.setInlineComments(key, this.getCommentLines(valueNode.getInLineComments())); 369 | } 370 | } 371 | } 372 | 373 | /** 374 | * Checks if the given mapping node contains a configuration serializable, 375 | * and returns appropriately. 376 | * 377 | * @param mappingNode The mapping node whose data will be checked. 378 | * @return {@code true} if the given mapping node contains a configuration 379 | * serializable, {@code false} otherwise. 380 | */ 381 | private boolean hasSerializedTypeKey(@NotNull final MappingNode mappingNode) { 382 | 383 | for (final NodeTuple nodeTuple : mappingNode.getValue()) { 384 | final Node keyNode = nodeTuple.getKeyNode(); 385 | if (!(keyNode instanceof ScalarNode)) { 386 | continue; 387 | } 388 | final String key = ((ScalarNode) keyNode).getValue(); 389 | if (key.equals(ConfigurationSerialization.SERIALIZED_TYPE_KEY)) { 390 | return true; 391 | } 392 | } 393 | 394 | return false; 395 | } 396 | 397 | /** 398 | * {@inheritDoc} 399 | */ 400 | @Override 401 | @NotNull 402 | public YamlConfigurationOptions getOptions() { 403 | if (this.options == null) { 404 | this.options = new YamlConfigurationOptions(this); 405 | } 406 | return (YamlConfigurationOptions) this.options; 407 | } 408 | 409 | /** 410 | * Creates a new YAML configuration, loading from the given file. 411 | *

412 | * Any errors loading the YAML configuration will be logged and then 413 | * otherwise ignored. If the given input is not a valid YAML configuration, 414 | * an empty YAML configuration will be returned. 415 | *

416 | * This will only load up to the default number of aliases 417 | * ({@link YamlConfigurationOptions#getMaxAliases()}) to prevent a Billion 418 | * Laughs Attack. 419 | *

420 | * The encoding used may follow the system dependent default. 421 | * 422 | * @param file The file to load. 423 | * @return The loaded YAML configuration. 424 | */ 425 | @NotNull 426 | public static YamlConfiguration loadConfiguration(@NotNull final File file) { 427 | 428 | final YamlConfiguration config = new YamlConfiguration(); 429 | try { 430 | config.load(file); 431 | } catch (IOException | InvalidConfigurationException e) { 432 | LoggerFactory.getLogger(YamlConfiguration.class).error("Cannot load config from file: " + file.getPath(), e); 433 | } 434 | 435 | return config; 436 | } 437 | 438 | /** 439 | * Creates a new YAML configuration, loading from the given reader. 440 | *

441 | * Any errors loading the YAML configuration will be logged and then 442 | * otherwise ignored. If the given input is not a valid YAML configuration, 443 | * an empty YAML configuration will be returned. 444 | *

445 | * This will only load up to the default number of aliases 446 | * ({@link YamlConfigurationOptions#getMaxAliases()}) to prevent a Billion 447 | * Laughs Attack. 448 | *

449 | * The encoding used may follow the system dependent default. 450 | * 451 | * @param reader The reader to load. 452 | * @return The loaded YAML configuration. 453 | */ 454 | @NotNull 455 | public static YamlConfiguration loadConfiguration(@NotNull final Reader reader) { 456 | 457 | final YamlConfiguration config = new YamlConfiguration(); 458 | try { 459 | config.load(reader); 460 | } catch (IOException | InvalidConfigurationException e) { 461 | LoggerFactory.getLogger(YamlConfiguration.class).error("Cannot load config from reader.", e); 462 | } 463 | 464 | return config; 465 | } 466 | } 467 | -------------------------------------------------------------------------------- /src/main/java/org/bspfsystems/yamlconfiguration/file/YamlConfigurationOptions.java: -------------------------------------------------------------------------------- 1 | /* 2 | * This file is part of YamlConfiguration. 3 | * 4 | * Implementation of SnakeYAML to be easy to use with files. 5 | * 6 | * Copyright (C) 2010-2014 The Bukkit Project (https://bukkit.org/) 7 | * Copyright (C) 2014-2024 SpigotMC Pty. Ltd. (https://www.spigotmc.org/) 8 | * Copyright (C) 2020-2025 BSPF Systems, LLC (https://bspfsystems.org/) 9 | * 10 | * Many of the files in this project are sourced from the Bukkit API as 11 | * part of The Bukkit Project (https://bukkit.org/), now maintained by 12 | * SpigotMC Pty. Ltd. (https://www.spigotmc.org/). These files can be found 13 | * at https://github.com/Bukkit/Bukkit/ and https://hub.spigotmc.org/stash/, 14 | * respectively. 15 | * 16 | * This program is free software: you can redistribute it and/or modify 17 | * it under the terms of the GNU General Public License as published by 18 | * the Free Software Foundation, either version 3 of the License, or 19 | * (at your option) any later version. 20 | * 21 | * This program is distributed in the hope that it will be useful, 22 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 23 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 24 | * GNU General Public License for more details. 25 | * 26 | * You should have received a copy of the GNU General Public License 27 | * along with this program. If not, see . 28 | */ 29 | 30 | package org.bspfsystems.yamlconfiguration.file; 31 | 32 | import java.util.List; 33 | import org.bspfsystems.yamlconfiguration.configuration.MemoryConfiguration; 34 | import org.jetbrains.annotations.NotNull; 35 | import org.jetbrains.annotations.Nullable; 36 | 37 | /** 38 | * Represents the various settings for controlling the input and output of a 39 | * YAML configuration. 40 | *

41 | * Synchronized with the commit on 24-November-2024. 42 | */ 43 | public final class YamlConfigurationOptions extends FileConfigurationOptions { 44 | 45 | public static final int DEFAULT_INDENT = 2; 46 | public static final int DEFAULT_WIDTH = 80; 47 | public static final int DEFAULT_MAX_ALIASES = 50; 48 | public static final int DEFAULT_CODE_POINT_LIMIT = 3 * 1024 * 1024; // 3 MB 49 | 50 | private int indent; 51 | private int width; 52 | private int maxAliases; 53 | private int codePointLimit; 54 | 55 | /** 56 | * Constructs a set of YAML configuration options. 57 | * 58 | * @param configuration The YAML configuration to create the options for. 59 | * @see FileConfigurationOptions#FileConfigurationOptions(MemoryConfiguration) 60 | */ 61 | YamlConfigurationOptions(@NotNull final YamlConfiguration configuration) { 62 | super(configuration); 63 | this.indent = DEFAULT_INDENT; 64 | this.width = DEFAULT_WIDTH; 65 | this.maxAliases = DEFAULT_MAX_ALIASES; 66 | this.codePointLimit = DEFAULT_CODE_POINT_LIMIT; 67 | } 68 | 69 | /** 70 | * {@inheritDoc} 71 | */ 72 | @Override 73 | @NotNull 74 | public YamlConfiguration getConfiguration() { 75 | return (YamlConfiguration) super.getConfiguration(); 76 | } 77 | 78 | /** 79 | * {@inheritDoc} 80 | */ 81 | @Override 82 | @NotNull 83 | public YamlConfigurationOptions setPathSeparator(final char pathSeparator) { 84 | super.setPathSeparator(pathSeparator); 85 | return this; 86 | } 87 | 88 | /** 89 | * {@inheritDoc} 90 | */ 91 | @Override 92 | @NotNull 93 | public YamlConfigurationOptions setCopyDefaults(final boolean copyDefaults) { 94 | super.setCopyDefaults(copyDefaults); 95 | return this; 96 | } 97 | 98 | /** 99 | * {@inheritDoc} 100 | */ 101 | @Override 102 | @NotNull 103 | public YamlConfigurationOptions setHeader(@Nullable final List header) { 104 | super.setHeader(header); 105 | return this; 106 | } 107 | 108 | /** 109 | * {@inheritDoc} 110 | */ 111 | @Override 112 | @NotNull 113 | public YamlConfigurationOptions setFooter(@Nullable final List footer) { 114 | super.setFooter(footer); 115 | return this; 116 | } 117 | 118 | /** 119 | * {@inheritDoc} 120 | */ 121 | @Override 122 | @NotNull 123 | public YamlConfigurationOptions setParseComments(final boolean parseComments) { 124 | super.setParseComments(parseComments); 125 | return this; 126 | } 127 | 128 | /** 129 | * Gets the number of spaces used to represent an indent. 130 | *

131 | * The minimum value this may be is {@code 2}, and the maximum is {@code 9}. 132 | *

133 | * The default value is {@code 2}. 134 | * 135 | * @return The number of spaces used to represent an indent. 136 | */ 137 | public int getIndent() { 138 | return this.indent; 139 | } 140 | 141 | /** 142 | * Sets the number of spaces used to represent an indent. 143 | *

144 | * The minimum value this may be is {@code 2}, and the maximum is {@code 9}. 145 | *

146 | * The default value is {@code 2}. 147 | * 148 | * @param indent The number of spaces used to represent an indent. 149 | * @return These YAML configuration options, for chaining. 150 | * @throws IllegalArgumentException If the given value is less than 151 | * {@code 2} or greater than {@code 9}. 152 | */ 153 | @NotNull 154 | public YamlConfigurationOptions setIndent(final int indent) throws IllegalArgumentException { 155 | if (indent < 2) { 156 | throw new IllegalArgumentException("Indent must be at least 2 characters."); 157 | } 158 | if (indent > 9) { 159 | throw new IllegalArgumentException("Indent cannot be greater than 9 characters."); 160 | } 161 | this.indent = indent; 162 | return this; 163 | } 164 | 165 | /** 166 | * Gets how long a line can be before it gets split. 167 | *

168 | * The minimum value this may be is {@code 8}, and the maximum is 169 | * {@code 1000}. 170 | *

171 | * The default value is {@code 80}. 172 | * 173 | * @return The number of characters a line can be before it gets split. 174 | */ 175 | public int getWidth() { 176 | return this.width; 177 | } 178 | 179 | /** 180 | * Sets how long a line can be before it gets split. 181 | *

182 | * The minimum value this may be is {@code 8}, and the maximum is 183 | * {@code 1000}. 184 | *

185 | * The default value is {@code 80}. 186 | * 187 | * @param width The number of characters a line can be before it gets split. 188 | * @return These YAML configuration options, for chaining. 189 | * @throws IllegalArgumentException If the given value is less than 190 | * {@code 8} or greater than {@code 1000}. 191 | */ 192 | @NotNull 193 | public YamlConfigurationOptions setWidth(final int width) { 194 | if (width < 8) { 195 | throw new IllegalArgumentException("Width must be at least 8 characters."); 196 | } 197 | if (width > 1000) { 198 | throw new IllegalArgumentException("Width cannot be greater than 1000 characters."); 199 | } 200 | this.width = width; 201 | return this; 202 | } 203 | 204 | /** 205 | * Gets the maximum number of aliases for collections. 206 | *

207 | * The minimum value this may be is {@code 10}, and the maximum is 208 | * {@link Integer#MAX_VALUE}. 209 | *

210 | * The default value is {@code 50}. It is recommended to keep this value as 211 | * low as possible for your use case as to prevent a Denial-of-Service known 212 | * Billion Laughs Attack. 213 | * 214 | * @return The maximum number of aliases for collections. 215 | */ 216 | public int getMaxAliases() { 217 | return this.maxAliases; 218 | } 219 | 220 | /** 221 | * Sets the maximum number of aliases for collections. 222 | *

223 | * The minimum value this may be is {@code 10}, and the maximum is 224 | * {@link Integer#MAX_VALUE} (please use this wisely). 225 | *

226 | * A recommended value is {@code 50}. It is recommended to keep this value 227 | * as low as possible for your use case as to prevent a Denial-of-Service 228 | * known 229 | * Billion Laughs Attack. 230 | * 231 | * @param maxAliases The maximum number of aliases for collections. 232 | * @return These YAML configuration options, for chaining. 233 | * @throws IllegalArgumentException If the given value is less than {@code 10}. 234 | */ 235 | @NotNull 236 | public YamlConfigurationOptions setMaxAliases(final int maxAliases) throws IllegalArgumentException { 237 | if (maxAliases < 10) { 238 | throw new IllegalArgumentException("Max aliases must be at least 10."); 239 | } 240 | this.maxAliases = maxAliases; 241 | return this; 242 | } 243 | 244 | /** 245 | * Gets the maximum number of code points that can be loaded in at one time. 246 | *

247 | * The minimum is {@code 1kB (1024)}, and the maximum is 248 | * {@link Integer#MAX_VALUE} (please use this wisely). 249 | *

250 | * A recommended value is {@code 3 MB (1024 * 1024 * 3)}. 251 | * 252 | * @return The maximum number of code points. 253 | */ 254 | public int getCodePointLimit() { 255 | return this.codePointLimit; 256 | } 257 | 258 | /** 259 | * Sets the maximum number of code points that can be loaded in at one time. 260 | *

261 | * The minimum is {@code 1kB (1024)}, and the maximum is 262 | * {@link Integer#MAX_VALUE} (please use this wisely). 263 | *

264 | * A recommended value is {@code 3 MB (1024 * 1024 * 3)}. 265 | * 266 | * @param codePointLimit The maximum number of code points for loading. 267 | * @return These YAML configuration options, for chaining. 268 | * @throws IllegalArgumentException If the given value is less than 269 | * {@code 1kB (1024)}. 270 | */ 271 | @NotNull 272 | public YamlConfigurationOptions setCodePointLimit(final int codePointLimit) throws IllegalArgumentException { 273 | if (codePointLimit < 1024) { 274 | throw new IllegalArgumentException("Code point limit must be at least 1kB (1024)."); 275 | } 276 | this.codePointLimit = codePointLimit; 277 | return this; 278 | } 279 | } 280 | -------------------------------------------------------------------------------- /src/main/java/org/bspfsystems/yamlconfiguration/file/YamlConstructor.java: -------------------------------------------------------------------------------- 1 | /* 2 | * This file is part of YamlConfiguration. 3 | * 4 | * Implementation of SnakeYAML to be easy to use with files. 5 | * 6 | * Copyright (C) 2010-2014 The Bukkit Project (https://bukkit.org/) 7 | * Copyright (C) 2014-2024 SpigotMC Pty. Ltd. (https://www.spigotmc.org/) 8 | * Copyright (C) 2020-2025 BSPF Systems, LLC (https://bspfsystems.org/) 9 | * 10 | * Many of the files in this project are sourced from the Bukkit API as 11 | * part of The Bukkit Project (https://bukkit.org/), now maintained by 12 | * SpigotMC Pty. Ltd. (https://www.spigotmc.org/). These files can be found 13 | * at https://github.com/Bukkit/Bukkit/ and https://hub.spigotmc.org/stash/, 14 | * respectively. 15 | * 16 | * This program is free software: you can redistribute it and/or modify 17 | * it under the terms of the GNU General Public License as published by 18 | * the Free Software Foundation, either version 3 of the License, or 19 | * (at your option) any later version. 20 | * 21 | * This program is distributed in the hope that it will be useful, 22 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 23 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 24 | * GNU General Public License for more details. 25 | * 26 | * You should have received a copy of the GNU General Public License 27 | * along with this program. If not, see . 28 | */ 29 | 30 | package org.bspfsystems.yamlconfiguration.file; 31 | 32 | import java.util.LinkedHashMap; 33 | import java.util.Map; 34 | import org.bspfsystems.yamlconfiguration.serialization.ConfigurationSerialization; 35 | import org.jetbrains.annotations.NotNull; 36 | import org.jetbrains.annotations.Nullable; 37 | import org.yaml.snakeyaml.LoaderOptions; 38 | import org.yaml.snakeyaml.constructor.SafeConstructor; 39 | import org.yaml.snakeyaml.error.YAMLException; 40 | import org.yaml.snakeyaml.nodes.MappingNode; 41 | import org.yaml.snakeyaml.nodes.Node; 42 | import org.yaml.snakeyaml.nodes.Tag; 43 | 44 | /** 45 | * Represents a custom safe constructor for use with a YAML configuration. 46 | *

47 | * Synchronized with the commit on 24-November-2024. 48 | */ 49 | public final class YamlConstructor extends SafeConstructor { 50 | 51 | /** 52 | * Represents a custom construct YAML map for use with a YAML configuration. 53 | */ 54 | private final class ConstructCustomObject extends ConstructYamlMap { 55 | 56 | /** 57 | * Constructs an empty construct custom object. 58 | * 59 | * @see ConstructYamlMap#ConstructYamlMap() 60 | */ 61 | private ConstructCustomObject() { 62 | super(); 63 | } 64 | 65 | /** 66 | * Converts the given node into an object. 67 | * 68 | * @param node The node to convert. 69 | * @return The object converted from the given node. 70 | */ 71 | @Nullable 72 | @Override 73 | public Object construct(@NotNull final Node node) { 74 | 75 | if (node.isTwoStepsConstruction()) { 76 | throw new YAMLException("Unexpected referential mapping structure. Node: " + node); 77 | } 78 | 79 | final Map raw = (Map) super.construct(node); 80 | if (raw.containsKey(ConfigurationSerialization.SERIALIZED_TYPE_KEY)) { 81 | 82 | final Map typed = new LinkedHashMap(raw.size()); 83 | for (final Map.Entry entry : raw.entrySet()) { 84 | typed.put(entry.getKey().toString(), entry.getValue()); 85 | } 86 | 87 | try { 88 | return ConfigurationSerialization.deserializeObject(typed); 89 | } catch (IllegalArgumentException e) { 90 | throw new YAMLException("Could not deserialize object.", e); 91 | } 92 | } 93 | 94 | return raw; 95 | } 96 | 97 | /** 98 | * Disallows the 2nd step of constructing an object from a node. 99 | * 100 | * @param node The composed node. 101 | * @param object The object constructed earlier by the initial 102 | * construction step for the given node. 103 | */ 104 | @Override 105 | public void construct2ndStep(@NotNull final Node node, @NotNull final Object object) { 106 | throw new YAMLException("Unexpected referential mapping structure. Node: " + node); 107 | } 108 | } 109 | 110 | /** 111 | * Constructs a YAML constructor. 112 | * 113 | * @param loaderOptions The loader options used while loading YAML via the 114 | * new constructor. 115 | * @see SafeConstructor#SafeConstructor(LoaderOptions); 116 | */ 117 | YamlConstructor(@NotNull final LoaderOptions loaderOptions) { 118 | super(loaderOptions); 119 | this.yamlConstructors.put(Tag.MAP, new ConstructCustomObject()); 120 | } 121 | 122 | /** 123 | * Converts the given node into an object. 124 | * 125 | * @param node The node to convert. 126 | * @return The object converted from the given node. 127 | */ 128 | @Nullable 129 | Object construct(@NotNull final Node node) { 130 | return this.constructObject(node); 131 | } 132 | 133 | /** 134 | * {@inheritDoc} 135 | */ 136 | @Override 137 | protected void flattenMapping(@NotNull final MappingNode mappingNode) { 138 | super.flattenMapping(mappingNode); 139 | } 140 | } 141 | -------------------------------------------------------------------------------- /src/main/java/org/bspfsystems/yamlconfiguration/file/YamlRepresenter.java: -------------------------------------------------------------------------------- 1 | /* 2 | * This file is part of YamlConfiguration. 3 | * 4 | * Implementation of SnakeYAML to be easy to use with files. 5 | * 6 | * Copyright (C) 2010-2014 The Bukkit Project (https://bukkit.org/) 7 | * Copyright (C) 2014-2024 SpigotMC Pty. Ltd. (https://www.spigotmc.org/) 8 | * Copyright (C) 2020-2025 BSPF Systems, LLC (https://bspfsystems.org/) 9 | * 10 | * Many of the files in this project are sourced from the Bukkit API as 11 | * part of The Bukkit Project (https://bukkit.org/), now maintained by 12 | * SpigotMC Pty. Ltd. (https://www.spigotmc.org/). These files can be found 13 | * at https://github.com/Bukkit/Bukkit/ and https://hub.spigotmc.org/stash/, 14 | * respectively. 15 | * 16 | * This program is free software: you can redistribute it and/or modify 17 | * it under the terms of the GNU General Public License as published by 18 | * the Free Software Foundation, either version 3 of the License, or 19 | * (at your option) any later version. 20 | * 21 | * This program is distributed in the hope that it will be useful, 22 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 23 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 24 | * GNU General Public License for more details. 25 | * 26 | * You should have received a copy of the GNU General Public License 27 | * along with this program. If not, see . 28 | */ 29 | 30 | package org.bspfsystems.yamlconfiguration.file; 31 | 32 | import java.util.LinkedHashMap; 33 | import java.util.Map; 34 | import org.bspfsystems.yamlconfiguration.configuration.ConfigurationSection; 35 | import org.bspfsystems.yamlconfiguration.serialization.ConfigurationSerializable; 36 | import org.bspfsystems.yamlconfiguration.serialization.ConfigurationSerialization; 37 | import org.jetbrains.annotations.NotNull; 38 | import org.yaml.snakeyaml.DumperOptions; 39 | import org.yaml.snakeyaml.nodes.Node; 40 | import org.yaml.snakeyaml.representer.Representer; 41 | 42 | /** 43 | * Represents a representer that can work with configuration sections and 44 | * configuration serializables. 45 | *

46 | * Synchronized with the commit on 24-November-2024. 47 | */ 48 | public final class YamlRepresenter extends Representer { 49 | 50 | /** 51 | * Represents a represent map that works with configuration sections. 52 | */ 53 | private final class RepresentConfigurationSection extends RepresentMap { 54 | 55 | /** 56 | * Constructs a basic represent configuration section. 57 | * 58 | * @see RepresentMap#RepresentMap() 59 | */ 60 | private RepresentConfigurationSection() { 61 | super(); 62 | } 63 | 64 | /** 65 | * Converts the given object (known to be a configuration section) into 66 | * a node. 67 | * 68 | * @param object The object to represent. 69 | * @return The node converted from the given object. 70 | * @see RepresentMap#representData(Object) 71 | */ 72 | @NotNull 73 | @Override 74 | public Node representData(@NotNull final Object object) { 75 | return super.representData(((ConfigurationSection) object).getValues(false)); 76 | } 77 | } 78 | 79 | /** 80 | * Represents a represent map that works with configuration serializables. 81 | */ 82 | private class RepresentConfigurationSerializable extends RepresentMap { 83 | 84 | /** 85 | * Constructs a basic represent configuration serializable. 86 | * 87 | * @see RepresentMap#RepresentMap() 88 | */ 89 | private RepresentConfigurationSerializable() { 90 | super(); 91 | } 92 | 93 | /** 94 | * Converts the given object (known to be a configuration serializable) 95 | * into a node. 96 | * 97 | * @param object The object to represent. 98 | * @return The node converted from the given object. 99 | * @see RepresentMap#representData(Object) 100 | */ 101 | @NotNull 102 | @Override 103 | public Node representData(@NotNull final Object object) { 104 | 105 | final ConfigurationSerializable serializable = (ConfigurationSerializable) object; 106 | final Map values = new LinkedHashMap(); 107 | 108 | values.put(ConfigurationSerialization.SERIALIZED_TYPE_KEY, ConfigurationSerialization.getAlias(serializable.getClass())); 109 | values.putAll(serializable.serialize()); 110 | 111 | return super.representData(values); 112 | } 113 | } 114 | 115 | /** 116 | * Constructs a YAML representer that can represent configuration sections 117 | * and configuration serializables, while disallowing enums. 118 | * 119 | * @param dumperOptions The dumper options used while dumping YAML via the 120 | * new representer. 121 | */ 122 | YamlRepresenter(@NotNull final DumperOptions dumperOptions) { 123 | super(dumperOptions); 124 | 125 | this.multiRepresenters.put(ConfigurationSection.class, new RepresentConfigurationSection()); 126 | this.multiRepresenters.put(ConfigurationSerializable.class, new RepresentConfigurationSerializable()); 127 | this.multiRepresenters.remove(Enum.class); 128 | } 129 | } 130 | -------------------------------------------------------------------------------- /src/main/java/org/bspfsystems/yamlconfiguration/serialization/ConfigurationSerializable.java: -------------------------------------------------------------------------------- 1 | /* 2 | * This file is part of YamlConfiguration. 3 | * 4 | * Implementation of SnakeYAML to be easy to use with files. 5 | * 6 | * Copyright (C) 2010-2014 The Bukkit Project (https://bukkit.org/) 7 | * Copyright (C) 2014-2024 SpigotMC Pty. Ltd. (https://www.spigotmc.org/) 8 | * Copyright (C) 2020-2025 BSPF Systems, LLC (https://bspfsystems.org/) 9 | * 10 | * Many of the files in this project are sourced from the Bukkit API as 11 | * part of The Bukkit Project (https://bukkit.org/), now maintained by 12 | * SpigotMC Pty. Ltd. (https://www.spigotmc.org/). These files can be found 13 | * at https://github.com/Bukkit/Bukkit/ and https://hub.spigotmc.org/stash/, 14 | * respectively. 15 | * 16 | * This program is free software: you can redistribute it and/or modify 17 | * it under the terms of the GNU General Public License as published by 18 | * the Free Software Foundation, either version 3 of the License, or 19 | * (at your option) any later version. 20 | * 21 | * This program is distributed in the hope that it will be useful, 22 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 23 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 24 | * GNU General Public License for more details. 25 | * 26 | * You should have received a copy of the GNU General Public License 27 | * along with this program. If not, see . 28 | */ 29 | 30 | package org.bspfsystems.yamlconfiguration.serialization; 31 | 32 | import java.util.Map; 33 | import org.jetbrains.annotations.NotNull; 34 | 35 | /** 36 | * Represents an object that may be serialized. 37 | *

38 | * These objects MUST implement one of the following, in addition to the 39 | * methods as defined by this interface: 40 | *

    41 | *
  • A static method "deserialize" that accepts a single Map<String, 42 | * Object> and returns the class.
  • 43 | *
  • A static method "valueOf" that accepts a single Map<String, Object> 44 | * and returns the class.
  • 45 | *
  • A constructor that accepts a single Map<String, Object>.
  • 46 | *
47 | * In addition to implementing this interface, you must register the class 48 | * with {@link ConfigurationSerialization#registerClass(Class)}. 49 | *

50 | * * Synchronized with the commit on 23-April-2019. 51 | * 52 | * @see DelegateDeserialization 53 | * @see SerializableAs 54 | */ 55 | public interface ConfigurationSerializable { 56 | 57 | /** 58 | * Creates a map representation of this configuration serializable. 59 | *

60 | * This class must provide a method to restore this class, as defined in the 61 | * configuration serializable interface javadocs. 62 | *

63 | * The map cannot be modified. The map will also only represent a snapshot 64 | * of this configuration serializable when it was taken. 65 | * 66 | * @return A map containing the current state of this configuration 67 | * serializable. 68 | */ 69 | @NotNull 70 | Map serialize(); 71 | } 72 | -------------------------------------------------------------------------------- /src/main/java/org/bspfsystems/yamlconfiguration/serialization/ConfigurationSerialization.java: -------------------------------------------------------------------------------- 1 | /* 2 | * This file is part of YamlConfiguration. 3 | * 4 | * Implementation of SnakeYAML to be easy to use with files. 5 | * 6 | * Copyright (C) 2010-2014 The Bukkit Project (https://bukkit.org/) 7 | * Copyright (C) 2014-2024 SpigotMC Pty. Ltd. (https://www.spigotmc.org/) 8 | * Copyright (C) 2020-2025 BSPF Systems, LLC (https://bspfsystems.org/) 9 | * 10 | * Many of the files in this project are sourced from the Bukkit API as 11 | * part of The Bukkit Project (https://bukkit.org/), now maintained by 12 | * SpigotMC Pty. Ltd. (https://www.spigotmc.org/). These files can be found 13 | * at https://github.com/Bukkit/Bukkit/ and https://hub.spigotmc.org/stash/, 14 | * respectively. 15 | * 16 | * This program is free software: you can redistribute it and/or modify 17 | * it under the terms of the GNU General Public License as published by 18 | * the Free Software Foundation, either version 3 of the License, or 19 | * (at your option) any later version. 20 | * 21 | * This program is distributed in the hope that it will be useful, 22 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 23 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 24 | * GNU General Public License for more details. 25 | * 26 | * You should have received a copy of the GNU General Public License 27 | * along with this program. If not, see . 28 | */ 29 | 30 | package org.bspfsystems.yamlconfiguration.serialization; 31 | 32 | import java.lang.reflect.Constructor; 33 | import java.lang.reflect.InvocationTargetException; 34 | import java.lang.reflect.Method; 35 | import java.lang.reflect.Modifier; 36 | import java.util.HashMap; 37 | import java.util.Map; 38 | import org.jetbrains.annotations.NotNull; 39 | import org.jetbrains.annotations.Nullable; 40 | import org.slf4j.LoggerFactory; 41 | 42 | /** 43 | * A utility class for storing and retrieving classes for configurations. 44 | *

45 | * Synchronized with the commit on 19-November-2023. 46 | */ 47 | public final class ConfigurationSerialization { 48 | 49 | public static final String SERIALIZED_TYPE_KEY = "=="; 50 | 51 | private static final Map> ALIASES = new HashMap>(); 52 | 53 | private final Class clazz; 54 | 55 | /** 56 | * Constructs a configuration serialization for the given configuration 57 | * serializable. 58 | * 59 | * @param clazz The class of the configuration serializable. 60 | */ 61 | private ConfigurationSerialization(@NotNull final Class clazz) { 62 | this.clazz = clazz; 63 | } 64 | 65 | /** 66 | * Deserializes the given map into a configuration serializable. 67 | * 68 | * @param map The serialized data as a map. 69 | * @return The deserialized configuration serializable, or {@code null} if 70 | * the data cannot be deserialized. 71 | */ 72 | @Nullable 73 | private ConfigurationSerializable deserialize(@NotNull final Map map) { 74 | 75 | ConfigurationSerializable result = null; 76 | 77 | Method method = this.getMethod("deserialize"); 78 | if (method != null) { 79 | result = this.deserializeViaMethod(method, map); 80 | } 81 | 82 | if (result == null) { 83 | method = this.getMethod("valueOf"); 84 | if (method != null) { 85 | result = this.deserializeViaMethod(method, map); 86 | } 87 | } 88 | 89 | if (result == null) { 90 | final Constructor constructor = this.getConstructor(); 91 | if (constructor != null) { 92 | result = this.deserializeViaConstructor(constructor, map); 93 | } 94 | } 95 | 96 | return result; 97 | } 98 | 99 | /** 100 | * Gets the method of the configuration serializable that performs the 101 | * deserialization. If one cannot be found, {@code null} will be returned. 102 | * 103 | * @param name The name of the method to retrieve. 104 | * @return The method that performs the deserialization, or {@code null} if 105 | * one cannot be found. 106 | */ 107 | @Nullable 108 | private Method getMethod(@NotNull final String name) { 109 | 110 | try { 111 | final Method method = this.clazz.getDeclaredMethod(name, Map.class); 112 | 113 | if (!ConfigurationSerializable.class.isAssignableFrom(method.getReturnType())) { 114 | return null; 115 | } 116 | if (!Modifier.isStatic(method.getModifiers())) { 117 | return null; 118 | } 119 | 120 | return method; 121 | } catch (NoSuchMethodException | SecurityException e) { 122 | return null; 123 | } 124 | } 125 | 126 | /** 127 | * Deserializes the data in the given map via the given method. If any 128 | * throwable is thrown, {@code null} will be returned. 129 | * 130 | * @param method The method to use to deserialize the data. 131 | * @param map The data to deserialize. 132 | * @return The deserialized configuration serializable, or {@code null} if 133 | * an issue occurs during deserialization. 134 | */ 135 | @Nullable 136 | private ConfigurationSerializable deserializeViaMethod(@NotNull final Method method, @NotNull final Map map) { 137 | 138 | try { 139 | 140 | final ConfigurationSerializable result = (ConfigurationSerializable) method.invoke(null, map); 141 | if (result == null) { 142 | LoggerFactory.getLogger(ConfigurationSerialization.class).error("Could not call method '" + method.toString() + "' of " + this.clazz.getName() + " for deserialization: method returned null."); 143 | } else { 144 | return result; 145 | } 146 | } catch (final Throwable t) { 147 | LoggerFactory.getLogger(ConfigurationSerialization.class).error("Could not call method '" + method.toString() + "' of " + this.clazz.getName() + " for deserialization.", t instanceof InvocationTargetException ? t.getCause() : t); 148 | } 149 | 150 | return null; 151 | } 152 | 153 | /** 154 | * Gets the constructor of the configuration serializable that performs the 155 | * deserialization. If one cannot be found, {@code null} will be returned. 156 | * 157 | * @return The constructor that performs the deserialization, or 158 | * {@code null} if one cannot be found. 159 | */ 160 | @Nullable 161 | private Constructor getConstructor() { 162 | 163 | try { 164 | return this.clazz.getConstructor(Map.class); 165 | } catch (final NoSuchMethodException | SecurityException e) { 166 | return null; 167 | } 168 | } 169 | 170 | /** 171 | * Deserializes the data in the given map via the given constructor. If any 172 | * throwable is thrown, {@code null} will be returned. 173 | * 174 | * @param constructor The constructor to use to deserialize the data. 175 | * data. 176 | * @param map The data to deserialize. 177 | * @return The deserialized configuration serializable, or {@code null} if 178 | * an issue occurs during deserialization. 179 | */ 180 | @Nullable 181 | private ConfigurationSerializable deserializeViaConstructor(@NotNull final Constructor constructor, @NotNull final Map map) { 182 | 183 | try { 184 | return constructor.newInstance(map); 185 | } catch (final Throwable t) { 186 | LoggerFactory.getLogger(ConfigurationSerialization.class.getName()).error("Could not call constructor '" + constructor.toString() + "' of " + clazz + "for deserialization.", t instanceof InvocationTargetException ? t.getCause() : t); 187 | } 188 | 189 | return null; 190 | } 191 | 192 | /** 193 | * Attempts to deserialize the given map into a new instance of the given 194 | * class. 195 | *

196 | * The class must implement configuration serializable, including the extra 197 | * methods and/or constructor as specified in the javadocs of a 198 | * configuration serializable. 199 | *

200 | * If a new instance could not be made (an example being the class not fully 201 | * implementing the interface), {@code null} will be returned. 202 | * 203 | * @param map The map to deserialize. 204 | * @param clazz The class to deserialize into. 205 | * @return The new instance of the specified class. 206 | */ 207 | @Nullable 208 | public static ConfigurationSerializable deserializeObject(@NotNull final Map map, @NotNull final Class clazz) { 209 | return new ConfigurationSerialization(clazz).deserialize(map); 210 | } 211 | 212 | /** 213 | * Attempts to deserialize the given map into a new instance of any known 214 | * type of configuration serializable that may be indicated by the data 215 | * contained within the map itself. 216 | *

217 | * The class must implement configuration serializable, including the extra 218 | * methods and/or constructor as specified in the javadocs of a 219 | * configuration serializable. 220 | *

221 | * If a new instance could not be made (an example being the class not fully 222 | * implementing the interface), {@code null} will be returned. 223 | * 224 | * @param map The map to deserialize. 225 | * @return The new instance of the given data. 226 | */ 227 | @Nullable 228 | public static ConfigurationSerializable deserializeObject(@NotNull final Map map) { 229 | 230 | Class clazz = null; 231 | if (map.containsKey(ConfigurationSerialization.SERIALIZED_TYPE_KEY)) { 232 | 233 | try { 234 | final String alias = (String) map.get(ConfigurationSerialization.SERIALIZED_TYPE_KEY); 235 | if (alias == null) { 236 | throw new IllegalArgumentException("Cannot have null alias."); 237 | } 238 | clazz = ConfigurationSerialization.getClassByAlias(alias); 239 | if (clazz == null) { 240 | throw new IllegalArgumentException("The specified class does not exist ('" + alias + "')."); 241 | } 242 | } catch (final ClassCastException e) { 243 | e.fillInStackTrace(); 244 | throw e; 245 | } 246 | } else { 247 | throw new IllegalArgumentException("The map does not contain type key ('" + ConfigurationSerialization.SERIALIZED_TYPE_KEY + "')."); 248 | } 249 | 250 | return new ConfigurationSerialization(clazz).deserialize(map); 251 | } 252 | 253 | /** 254 | * Registers the given configuration serializable class by any and all 255 | * aliases/delegate deserializations. 256 | * 257 | * @param clazz The class to register. 258 | */ 259 | public static void registerClass(@NotNull final Class clazz) { 260 | 261 | final DelegateDeserialization delegate = clazz.getAnnotation(DelegateDeserialization.class); 262 | if (delegate == null) { 263 | ConfigurationSerialization.registerClass(clazz, getAlias(clazz)); 264 | ConfigurationSerialization.registerClass(clazz, clazz.getName()); 265 | } 266 | } 267 | 268 | /** 269 | * Registers the given alias to the given configuration serializable class. 270 | * 271 | * @param clazz The class to register. 272 | * @param alias Alias to register the class as. 273 | * @see SerializableAs 274 | */ 275 | public static void registerClass(@NotNull final Class clazz, @NotNull final String alias) { 276 | ConfigurationSerialization.ALIASES.put(alias, clazz); 277 | } 278 | 279 | /** 280 | * Unregisters the specified alias. 281 | * 282 | * @param alias The alias to unregister. 283 | */ 284 | public static void unregisterClass(@NotNull final String alias) { 285 | ConfigurationSerialization.ALIASES.remove(alias); 286 | } 287 | 288 | /** 289 | * Unregisters any aliases for the given configuration serializable class 290 | * 291 | * @param clazz The class to unregister. 292 | */ 293 | public static void unregisterClass(@NotNull final Class clazz) { 294 | ConfigurationSerialization.ALIASES.entrySet().removeIf(entry -> entry.getValue().equals(clazz)); 295 | } 296 | 297 | /** 298 | * Attempts to get a registered configuration serializable class by its 299 | * alias. 300 | * 301 | * @param alias The alias of the configuration serializable to retrieve. 302 | * @return The requested configuration serializable, or {@code null} if one 303 | * is not found. 304 | */ 305 | @Nullable 306 | public static Class getClassByAlias(@NotNull final String alias) { 307 | return ConfigurationSerialization.ALIASES.get(alias); 308 | } 309 | 310 | /** 311 | * Gets the primary alias for the given configuration serializable class. 312 | * 313 | * @param clazz The class to retrieve the primary alias of. 314 | * @return The primary alias of the given configuration serializable. 315 | */ 316 | @NotNull 317 | public static String getAlias(@NotNull final Class clazz) { 318 | 319 | DelegateDeserialization delegate = clazz.getAnnotation(DelegateDeserialization.class); 320 | if (delegate != null && delegate.value() != clazz) { 321 | return ConfigurationSerialization.getAlias(delegate.value()); 322 | } 323 | 324 | final SerializableAs alias = clazz.getAnnotation(SerializableAs.class); 325 | if (alias != null) { 326 | return alias.value(); 327 | } 328 | 329 | return clazz.getName(); 330 | } 331 | } 332 | -------------------------------------------------------------------------------- /src/main/java/org/bspfsystems/yamlconfiguration/serialization/DelegateDeserialization.java: -------------------------------------------------------------------------------- 1 | /* 2 | * This file is part of YamlConfiguration. 3 | * 4 | * Implementation of SnakeYAML to be easy to use with files. 5 | * 6 | * Copyright (C) 2010-2014 The Bukkit Project (https://bukkit.org/) 7 | * Copyright (C) 2014-2024 SpigotMC Pty. Ltd. (https://www.spigotmc.org/) 8 | * Copyright (C) 2020-2025 BSPF Systems, LLC (https://bspfsystems.org/) 9 | * 10 | * Many of the files in this project are sourced from the Bukkit API as 11 | * part of The Bukkit Project (https://bukkit.org/), now maintained by 12 | * SpigotMC Pty. Ltd. (https://www.spigotmc.org/). These files can be found 13 | * at https://github.com/Bukkit/Bukkit/ and https://hub.spigotmc.org/stash/, 14 | * respectively. 15 | * 16 | * This program is free software: you can redistribute it and/or modify 17 | * it under the terms of the GNU General Public License as published by 18 | * the Free Software Foundation, either version 3 of the License, or 19 | * (at your option) any later version. 20 | * 21 | * This program is distributed in the hope that it will be useful, 22 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 23 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 24 | * GNU General Public License for more details. 25 | * 26 | * You should have received a copy of the GNU General Public License 27 | * along with this program. If not, see . 28 | */ 29 | 30 | package org.bspfsystems.yamlconfiguration.serialization; 31 | 32 | import java.lang.annotation.ElementType; 33 | import java.lang.annotation.Retention; 34 | import java.lang.annotation.RetentionPolicy; 35 | import java.lang.annotation.Target; 36 | import org.jetbrains.annotations.NotNull; 37 | 38 | /** 39 | * Applies to a configuration serializable that will delegate all 40 | * deserialization to another configuration serializable. 41 | *

42 | * Synchronized with the commit on 23-April-2019. 43 | */ 44 | @Retention(RetentionPolicy.RUNTIME) 45 | @Target(ElementType.TYPE) 46 | public @interface DelegateDeserialization { 47 | 48 | /** 49 | * Gets the configuration serializable class that is delegated to. 50 | * 51 | * @return The delegated configuration serializable class. 52 | */ 53 | @NotNull 54 | Class value(); 55 | } 56 | -------------------------------------------------------------------------------- /src/main/java/org/bspfsystems/yamlconfiguration/serialization/SerializableAs.java: -------------------------------------------------------------------------------- 1 | /* 2 | * This file is part of YamlConfiguration. 3 | * 4 | * Implementation of SnakeYAML to be easy to use with files. 5 | * 6 | * Copyright (C) 2010-2014 The Bukkit Project (https://bukkit.org/) 7 | * Copyright (C) 2014-2024 SpigotMC Pty. Ltd. (https://www.spigotmc.org/) 8 | * Copyright (C) 2020-2025 BSPF Systems, LLC (https://bspfsystems.org/) 9 | * 10 | * Many of the files in this project are sourced from the Bukkit API as 11 | * part of The Bukkit Project (https://bukkit.org/), now maintained by 12 | * SpigotMC Pty. Ltd. (https://www.spigotmc.org/). These files can be found 13 | * at https://github.com/Bukkit/Bukkit/ and https://hub.spigotmc.org/stash/, 14 | * respectively. 15 | * 16 | * This program is free software: you can redistribute it and/or modify 17 | * it under the terms of the GNU General Public License as published by 18 | * the Free Software Foundation, either version 3 of the License, or 19 | * (at your option) any later version. 20 | * 21 | * This program is distributed in the hope that it will be useful, 22 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 23 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 24 | * GNU General Public License for more details. 25 | * 26 | * You should have received a copy of the GNU General Public License 27 | * along with this program. If not, see . 28 | */ 29 | 30 | package org.bspfsystems.yamlconfiguration.serialization; 31 | 32 | import java.lang.annotation.ElementType; 33 | import java.lang.annotation.Retention; 34 | import java.lang.annotation.RetentionPolicy; 35 | import java.lang.annotation.Target; 36 | import org.jetbrains.annotations.NotNull; 37 | 38 | /** 39 | * Represents an "alias" that a configuration serializable may be known as. 40 | *

41 | * If this annotation is no present on a configuration serializable class, the 42 | * class's fully-qualified name ({@link Class#getName()}) will be used. 43 | *

44 | * This value will be stored in the configuration serialization so that it can 45 | * determine what type it is during serialization and deserialization 46 | * operations. 47 | *

48 | * Using this annotation on a class that does not extend or implement a 49 | * configuration serializable will have no effect. 50 | *

51 | * Synchronized with the commit on 23-April-2019. 52 | * 53 | * @see ConfigurationSerialization#registerClass(Class, String) 54 | */ 55 | @Retention(RetentionPolicy.RUNTIME) 56 | @Target(ElementType.TYPE) 57 | public @interface SerializableAs { 58 | 59 | /** 60 | * This is the name the configuration serializable class will be known by. 61 | *

62 | * This name MUST be unique. It is recommended to use names such as 63 | * "MyApplicationThing" instead of "Thing". 64 | * 65 | * @return The name to serialize the class as. 66 | */ 67 | @NotNull 68 | String value(); 69 | } 70 | --------------------------------------------------------------------------------