├── .gitignore ├── LICENSE.txt ├── README.md ├── bungee.yml ├── cncp_lists.txt ├── libs ├── CMIAPI7.6.2.0.jar ├── GravityTubes.jar └── mcMMO-2.1.158.jar ├── plugin.yml ├── pom.xml └── src └── me └── asofold └── bpl └── cncp ├── ClientVersion └── ClientVersionListener.java ├── CompatNoCheatPlus.java ├── bedrock └── BedrockPlayerListener.java ├── bungee └── CompatNoCheatPlus.java ├── config ├── Settings.java └── compatlayer │ ├── AbstractConfig.java │ ├── AbstractNewConfig.java │ ├── CompatConfig.java │ ├── CompatConfigFactory.java │ ├── ConfigUtil.java │ └── NewConfig.java ├── hooks ├── AbstractConfigurableHook.java ├── AbstractHook.java ├── CMI │ └── HookCMI.java ├── GravityTubes │ ├── HookFacadeImpl.java │ └── HookGravityTubes.java ├── Hook.java ├── citizens2 │ └── HookCitizens2.java ├── generic │ ├── ClassExemptionHook.java │ ├── ConfigurableHook.java │ ├── ExemptionManager.java │ ├── HookBlockBreak.java │ ├── HookBlockPlace.java │ ├── HookEntityDamageByEntity.java │ ├── HookInstaBreak.java │ ├── HookPlayerClass.java │ ├── HookPlayerInteract.java │ └── HookSetSpeed.java ├── magicspells │ └── HookMagicSpells.java └── mcmmo │ ├── HookFacadeImpl.java │ └── HookmcMMO.java └── utils ├── ActionFrequency.java ├── PluginGetter.java ├── TickTask2.java └── Utils.java /.gitignore: -------------------------------------------------------------------------------- 1 | /target/ 2 | .classpath 3 | .DS_Store 4 | .project 5 | .settings/org.eclipse.core.resources.prefs 6 | *.prefs 7 | -------------------------------------------------------------------------------- /LICENSE.txt: -------------------------------------------------------------------------------- 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 | . -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | 2 | CompatNoCheatPlus 3 | --------- 4 | CompatNoCheatPlus (cncp) provides compatibility between the anti cheat plugin NoCheatPlus and other plugins that add game mechanics different to the vanilla game behavior, such as mcMMO or plugins that add npcs such as Citizens and protocol hack like Geyser for cross-platform to play with. 5 | -------------------------------------------------------------------------------- /bungee.yml: -------------------------------------------------------------------------------- 1 | name: CompatNoCheatPlus 2 | main: me.asofold.bpl.cncp.bungee.CompatNoCheatPlus 3 | version: ${project.version}-${buildDescription} 4 | author: asofold, xaw3ep -------------------------------------------------------------------------------- /cncp_lists.txt: -------------------------------------------------------------------------------- 1 | CompatNoCheatPlus lists file 2 | ------------------------------------------------------- 3 | 4 | Compatibility hooks for NoCheatPlus! 5 | 6 | LICENSE 7 | ------------------------- 8 | LICENSE.txt (Same as NoCheatPlus). 9 | 10 | 11 | STACK 12 | --------- 13 | ?(add) more intricate load order stuff ? [best would be to force managelisteners with ncp] 14 | 15 | *** 16 | !(add) reload command 17 | 18 | ? another sequence number (for standard events) 19 | 20 | *** ADD MORE GENERIC HOOKS 21 | 22 | !add check type and permission hooks, also for worldguard regions. 23 | 24 | Citizens2 / Player class: make configurable (hidden) Or do internally: List of checks to use , exclude moving if possible. 25 | 26 | Generic abstract class for the mcMMO style cancelling of next x events + ticks alive etc 27 | 28 | add stats hook ? 29 | 30 | add a good mechanism for adding external configurable hooks (read automatically from the cncp config). 31 | 32 | 33 | !(add) Use some exemption mechanism for npcs (generic player class hook + citizens). 34 | !consider remove: clearing the VL ? => probably not, needs redesign to also monitor block break. + only clear the necessary bits (not frequency) 35 | 36 | ! try: insta break: keep exemption (unless cancelled) for next block break event (!). -> maybe ncp 37 | 38 | 39 | ? HookInstaBreak : add static method to sset check types to exempt from for next break ? 40 | 41 | cncp: check at least for logs / leaves for skill specific block types 42 | 43 | 44 | hookiinstabreak: let hooks fail completely if listeners are failing to register ? 45 | 46 | 47 | *** CLEANUP THIS, BETTER METHODS, INTEGRATE SOME INTO NCP MAYBE 48 | 49 | * Auto detection of unknown events + log on disable + info command. 50 | ? analysis tools like event-Mirror ? 51 | 52 | * More generic hooks, clean methods! 53 | 54 | ! Strip down mcMMO hook to add a new one / integrate into instabreak 55 | ! Clean up hooks, use TickTask and "next" to confine fuzzy unexemption to a minimum. 56 | 57 | -------------------------- 58 | 59 | support for instant spells ? [internalName or name ? <- guess: name] 60 | 61 | ? register listeners with NCP directly? also use annotations ? 62 | 63 | ! Smarter way to enable / disable PlayerClassHoook (disable by default for now). 64 | ! if SpoutPlugin is present: add blocks to ignorepassable automatically / adjust flags ? [generic block setup] 65 | 66 | ? add info command: show all hooks and so on. 67 | 68 | 69 | add class-name inspection methods (!). 70 | 71 | set-speed: per world options ? [per world config concept] 72 | set-speed: add option to set speed to default speed on player quit/kick 73 | -------------------------------------------------------------------------------- /libs/CMIAPI7.6.2.0.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Updated-NoCheatPlus/CompatNoCheatPlus/c6c88d4807aa23e1771d2e2203667e4c0b8c2d97/libs/CMIAPI7.6.2.0.jar -------------------------------------------------------------------------------- /libs/GravityTubes.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Updated-NoCheatPlus/CompatNoCheatPlus/c6c88d4807aa23e1771d2e2203667e4c0b8c2d97/libs/GravityTubes.jar -------------------------------------------------------------------------------- /libs/mcMMO-2.1.158.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Updated-NoCheatPlus/CompatNoCheatPlus/c6c88d4807aa23e1771d2e2203667e4c0b8c2d97/libs/mcMMO-2.1.158.jar -------------------------------------------------------------------------------- /plugin.yml: -------------------------------------------------------------------------------- 1 | name: CompatNoCheatPlus 2 | main: me.asofold.bpl.cncp.CompatNoCheatPlus 3 | version: ${project.version}-${buildDescription} 4 | dev-url: http://dev.bukkit.org/server-mods/compatnocheatplus-cncp/ 5 | api-version: 1.13 6 | folia-supported: true 7 | 8 | loadbefore: 9 | - NoCheatPlus 10 | softdepend: 11 | - mcMMO 12 | - Citizens 13 | - MagicSpells 14 | 15 | commands: 16 | compatnocheatplus: 17 | description: 'Show general version information of cncp and dependencies.' 18 | usage: '/' 19 | permission: 'cncp.cmd.info' 20 | aliases: 21 | - cncp 22 | -------------------------------------------------------------------------------- /pom.xml: -------------------------------------------------------------------------------- 1 | 2 | 4.0.0 3 | CompatNoCheatPlus 4 | CompatNoCheatPlus 5 | 6.6.7-SNAPSHOT 6 | CompatNoCheatPlus 7 | 8 | 9 | 10 | 11 | scm:git:git@github.com:asofold/${project.name}.git 12 | scm:git:git://github.com/asofold/${project.name}.git 13 | https://github.com/asofold/${project.name} 14 | 15 | 16 | 17 | 18 | 19 | opencollab-snapshot-repo 20 | https://repo.opencollab.dev/maven-snapshots/ 21 | 22 | false 23 | 24 | 25 | true 26 | 27 | 28 | 29 | jitpack.io 30 | https://jitpack.io 31 | 32 | 33 | viaversion-repo 34 | https://repo.viaversion.com 35 | 36 | 37 | bungeecord-repo 38 | https://oss.sonatype.org/content/repositories/snapshots 39 | 40 | 41 | 42 | 43 | 44 | 45 | org.spigotmc 46 | spigot 47 | 1.8.8-R0.1-SNAPSHOT 48 | provided 49 | 50 | 51 | com.gmail.nossr50.mcMMO 52 | mcMMO 53 | 2.1.158 54 | system 55 | ${basedir}/libs/mcMMO-2.1.158.jar 56 | 57 | 58 | net.citizensnpcs 59 | citizensapi 60 | 2.0.26-SNAPSHOT 61 | provided 62 | 63 | 64 | com.benzoft.gravitytubes 65 | gravitytubes 66 | 1.0 67 | system 68 | ${basedir}/libs/GravityTubes.jar 69 | 70 | 71 | com.Zrips.CMI 72 | CMI 73 | 1.0 74 | system 75 | ${basedir}/libs/CMIAPI7.6.2.0.jar 76 | 77 | 78 | com.github.updated-nocheatplus.nocheatplus 79 | nocheatplus 80 | -SNAPSHOT 81 | 82 | 83 | org.geysermc 84 | connector 85 | 1.4.2-SNAPSHOT 86 | provided 87 | 88 | 89 | org.geysermc.floodgate 90 | api 91 | 2.0-SNAPSHOT 92 | provided 93 | 94 | 95 | net.md-5 96 | bungeecord-api 97 | 1.19-R0.1-SNAPSHOT 98 | 99 | 100 | com.viaversion 101 | viaversion-api 102 | LATEST 103 | 104 | 105 | net.md-5 106 | bungeecord-event 107 | 1.19-R0.1-SNAPSHOT 108 | 109 | 110 | 111 | 112 | 113 | 114 | timestamp 115 | 116 | 117 | !env.BUILD_NUMBER 118 | 119 | 120 | 121 | ${maven.build.timestamp} 122 | 123 | 124 | 125 | dynamic_build_number 126 | 127 | 128 | env.BUILD_NUMBER 129 | 130 | 131 | 132 | b${env.BUILD_NUMBER} 133 | 134 | 135 | 136 | 137 | 138 | 139 | clean package 140 | ${basedir}/src 141 | 142 | 143 | . 144 | true 145 | ${basedir} 146 | 147 | plugin.yml 148 | LICENSE.txt 149 | bungee.yml 150 | 151 | 152 | 153 | 154 | 155 | org.apache.maven.plugins 156 | maven-compiler-plugin 157 | 2.5.1 158 | 159 | 1.8 160 | 1.8 161 | 162 | 163 | 164 | org.apache.maven.plugins 165 | maven-jar-plugin 166 | 2.4 167 | 168 | cncp 169 | 170 | false 171 | false 172 | 173 | false 174 | false 175 | 176 | 177 | 178 | 179 | 180 | 181 | 182 | 183 | 184 | UTF-8 185 | yyyy_MM_dd-HH_mm 186 | 187 | 188 | -------------------------------------------------------------------------------- /src/me/asofold/bpl/cncp/ClientVersion/ClientVersionListener.java: -------------------------------------------------------------------------------- 1 | package me.asofold.bpl.cncp.ClientVersion; 2 | 3 | import java.lang.reflect.Method; 4 | 5 | import org.bukkit.Bukkit; 6 | import org.bukkit.entity.Player; 7 | import org.bukkit.event.EventHandler; 8 | import org.bukkit.event.EventPriority; 9 | import org.bukkit.event.Listener; 10 | import org.bukkit.event.player.PlayerJoinEvent; 11 | import org.bukkit.plugin.Plugin; 12 | 13 | import com.viaversion.viaversion.api.Via; 14 | import fr.neatmonster.nocheatplus.compat.Folia; 15 | import fr.neatmonster.nocheatplus.players.DataManager; 16 | import fr.neatmonster.nocheatplus.players.IPlayerData; 17 | import fr.neatmonster.nocheatplus.utilities.ReflectionUtil; 18 | import me.asofold.bpl.cncp.CompatNoCheatPlus; 19 | 20 | public class ClientVersionListener implements Listener { 21 | 22 | private Plugin ViaVersion = Bukkit.getPluginManager().getPlugin("ViaVersion"); 23 | private Plugin ProtocolSupport = Bukkit.getPluginManager().getPlugin("ProtocolSupport"); 24 | private final Class ProtocolSupportAPIClass = ReflectionUtil.getClass("protocolsupport.api.ProtocolSupportAPI"); 25 | private final Class ProtocolVersionClass = ReflectionUtil.getClass("protocolsupport.api.ProtocolVersion"); 26 | private final Method getProtocolVersion = ProtocolSupportAPIClass == null ? null : ReflectionUtil.getMethod(ProtocolSupportAPIClass, "getProtocolVersion", Player.class); 27 | 28 | @SuppressWarnings("unchecked") 29 | @EventHandler(priority = EventPriority.MONITOR) 30 | public void onPlayerJoin(PlayerJoinEvent event) { 31 | final Player player = event.getPlayer(); 32 | Folia.runSyncDelayedTask(CompatNoCheatPlus.getInstance(), (arg) -> { 33 | final IPlayerData pData = DataManager.getPlayerData(player); 34 | if (pData != null) { 35 | if (ViaVersion != null && ViaVersion.isEnabled()) { 36 | // Give precedence to ViaVersion 37 | pData.setClientVersionID(Via.getAPI().getPlayerVersion(player)); 38 | } 39 | else if (ProtocolSupport != null && getProtocolVersion != null && ProtocolSupport.isEnabled()) { 40 | // Fallback to PS (reflectively, due to PS not having a valid mvn repo) 41 | Object protocolVersion = ReflectionUtil.invokeMethod(getProtocolVersion, null, player); 42 | Method getId = ReflectionUtil.getMethodNoArgs(ProtocolVersionClass, "getId", int.class); 43 | int version = (int) ReflectionUtil.invokeMethodNoArgs(getId, protocolVersion); 44 | pData.setClientVersionID(version); 45 | } 46 | // (Client version stays unknown (-1)) 47 | } 48 | }, 20); // Wait 20 ticks before setting client data 49 | } 50 | } 51 | -------------------------------------------------------------------------------- /src/me/asofold/bpl/cncp/CompatNoCheatPlus.java: -------------------------------------------------------------------------------- 1 | package me.asofold.bpl.cncp; 2 | 3 | import java.io.File; 4 | import java.util.HashSet; 5 | import java.util.LinkedHashSet; 6 | import java.util.LinkedList; 7 | import java.util.List; 8 | import java.util.Set; 9 | import java.util.logging.Level; 10 | import java.util.logging.Logger; 11 | 12 | import org.bukkit.Bukkit; 13 | import org.bukkit.Server; 14 | import org.bukkit.command.Command; 15 | import org.bukkit.command.CommandSender; 16 | import org.bukkit.configuration.file.YamlConfiguration; 17 | import org.bukkit.event.EventHandler; 18 | import org.bukkit.event.EventPriority; 19 | import org.bukkit.event.Listener; 20 | import org.bukkit.event.server.PluginEnableEvent; 21 | import org.bukkit.plugin.Plugin; 22 | import org.bukkit.plugin.PluginDescriptionFile; 23 | import org.bukkit.plugin.PluginManager; 24 | import org.bukkit.plugin.java.JavaPlugin; 25 | import org.bukkit.scheduler.BukkitScheduler; 26 | import fr.neatmonster.nocheatplus.NCPAPIProvider; 27 | import fr.neatmonster.nocheatplus.compat.Folia; 28 | import fr.neatmonster.nocheatplus.components.registry.feature.IDisableListener; 29 | import fr.neatmonster.nocheatplus.hooks.NCPHook; 30 | import fr.neatmonster.nocheatplus.hooks.NCPHookManager; 31 | import me.asofold.bpl.cncp.bedrock.BedrockPlayerListener; 32 | import me.asofold.bpl.cncp.ClientVersion.ClientVersionListener; 33 | import me.asofold.bpl.cncp.config.Settings; 34 | import me.asofold.bpl.cncp.config.compatlayer.CompatConfig; 35 | import me.asofold.bpl.cncp.config.compatlayer.NewConfig; 36 | import me.asofold.bpl.cncp.hooks.Hook; 37 | import me.asofold.bpl.cncp.hooks.generic.ConfigurableHook; 38 | import me.asofold.bpl.cncp.hooks.generic.HookBlockBreak; 39 | import me.asofold.bpl.cncp.hooks.generic.HookBlockPlace; 40 | import me.asofold.bpl.cncp.hooks.generic.HookEntityDamageByEntity; 41 | import me.asofold.bpl.cncp.hooks.generic.HookInstaBreak; 42 | import me.asofold.bpl.cncp.hooks.generic.HookPlayerClass; 43 | import me.asofold.bpl.cncp.hooks.generic.HookPlayerInteract; 44 | import me.asofold.bpl.cncp.utils.TickTask2; 45 | import me.asofold.bpl.cncp.utils.Utils; 46 | 47 | /** 48 | * Quick attempt to provide compatibility to NoCheatPlus (by NeatMonster) for some other plugins that change the vanilla game mechanichs, for instance by fast block breaking. 49 | * @author mc_dev 50 | * 51 | */ 52 | public class CompatNoCheatPlus extends JavaPlugin implements Listener { 53 | 54 | private static CompatNoCheatPlus instance = null; 55 | 56 | private final Settings settings = new Settings(); 57 | 58 | private boolean bungee; 59 | 60 | /** Hooks registered with cncp */ 61 | private static final Set registeredHooks = new HashSet(); 62 | 63 | private final List builtinHooks = new LinkedList(); 64 | 65 | /** 66 | * Flag if plugin is enabled. 67 | */ 68 | private static boolean enabled = false; 69 | 70 | /** 71 | * Experimental: static method to enable this plugin, only enables if it is not already enabled. 72 | * @return 73 | */ 74 | public static boolean enableCncp(){ 75 | if (enabled) return true; 76 | return enablePlugin("CompatNoCheatPlus"); 77 | } 78 | 79 | /** 80 | * Static method to enable a plugin (might also be useful for hooks). 81 | * @param plgName 82 | * @return 83 | */ 84 | public static boolean enablePlugin(String plgName) { 85 | PluginManager pm = Bukkit.getPluginManager(); 86 | Plugin plugin = pm.getPlugin(plgName); 87 | if (plugin == null) return false; 88 | if (pm.isPluginEnabled(plugin)) return true; 89 | pm.enablePlugin(plugin); 90 | return true; 91 | } 92 | 93 | /** 94 | * Static method to disable a plugin (might also be useful for hooks). 95 | * @param plgName 96 | * @return 97 | */ 98 | public static boolean disablePlugin(String plgName){ 99 | PluginManager pm = Bukkit.getPluginManager(); 100 | Plugin plugin = pm.getPlugin(plgName); 101 | if (plugin == null) return false; 102 | if (!pm.isPluginEnabled(plugin)) return true; 103 | pm.disablePlugin(plugin); 104 | return true; 105 | } 106 | 107 | /** 108 | * Get the plugin instance. 109 | * @return 110 | */ 111 | public static CompatNoCheatPlus getInstance(){ 112 | return instance; 113 | } 114 | 115 | /** 116 | * API to add a hook. Adds the hook AND registers listeners if enabled. Also respects the configuration for preventing hooks.
117 | * If you want to not register the listeners use NCPHookManager. 118 | * @param hook 119 | * @return 120 | */ 121 | public static boolean addHook(Hook hook){ 122 | if (Settings.preventAddHooks.contains(hook.getHookName())){ 123 | Bukkit.getLogger().info("[CompatNoCheatPlus] Prevented adding hook: "+hook.getHookName() + " / " + hook.getHookVersion()); 124 | return false; 125 | } 126 | registeredHooks.add(hook); 127 | if (enabled) registerListeners(hook); 128 | boolean added = checkAddNCPHook(hook); // Add if plugin is present, otherwise queue for adding. 129 | Bukkit.getLogger().info("[CompatNoCheatPlus] Registered hook"+(added?"":"(NCPHook might get added later)")+": "+hook.getHookName() + " / " + hook.getHookVersion()); 130 | return true; 131 | } 132 | 133 | /** 134 | * If already added to NCP 135 | * @param hook 136 | * @return 137 | */ 138 | private static boolean checkAddNCPHook(Hook hook) { 139 | PluginManager pm = Bukkit.getPluginManager(); 140 | Plugin plugin = pm.getPlugin("NoCheatPlus"); 141 | if (plugin == null || !pm.isPluginEnabled(plugin)) 142 | return false; 143 | NCPHook ncpHook = hook.getNCPHook(); 144 | if (ncpHook != null) 145 | NCPHookManager.addHook(hook.getCheckTypes(), ncpHook); 146 | return true; 147 | } 148 | 149 | /** 150 | * Conveniently register the listeners, do not use if you add/added the hook with addHook. 151 | * @param hook 152 | * @return 153 | */ 154 | public static boolean registerListeners(Hook hook) { 155 | if (!enabled) return false; 156 | Listener[] listeners = hook.getListeners(); 157 | if (listeners != null){ 158 | // attempt to register events: 159 | PluginManager pm = Bukkit.getPluginManager(); 160 | Plugin plg = pm.getPlugin("CompatNoCheatPlus"); 161 | if (plg == null) return false; 162 | for (Listener listener : listeners) { 163 | pm.registerEvents(listener, plg); 164 | } 165 | } 166 | return true; 167 | } 168 | 169 | /** 170 | * Called before loading settings, adds available hooks into a list, so they will be able to read config. 171 | */ 172 | private void setupBuiltinHooks() { 173 | builtinHooks.clear(); 174 | // Might-fail hooks: 175 | // Set speed 176 | try { 177 | builtinHooks.add(new me.asofold.bpl.cncp.hooks.generic.HookSetSpeed()); 178 | } 179 | catch (Throwable t) {} 180 | // Citizens 2 181 | try { 182 | builtinHooks.add(new me.asofold.bpl.cncp.hooks.citizens2.HookCitizens2()); 183 | } 184 | catch (Throwable t) {} 185 | // mcMMO 186 | try { 187 | builtinHooks.add(new me.asofold.bpl.cncp.hooks.mcmmo.HookmcMMO()); 188 | } 189 | catch (Throwable t) {} 190 | // GravityTubes 191 | try { 192 | builtinHooks.add(new me.asofold.bpl.cncp.hooks.GravityTubes.HookGravityTubes()); 193 | } 194 | catch (Throwable t) {} 195 | // CMI 196 | try { 197 | builtinHooks.add(new me.asofold.bpl.cncp.hooks.CMI.HookCMI()); 198 | } 199 | catch (Throwable t){} 200 | // // MagicSpells 201 | // try{ 202 | // builtinHooks.add(new me.asofold.bpl.cncp.hooks.magicspells.HookMagicSpells()); 203 | // } 204 | // catch (Throwable t){} 205 | // Simple generic hooks 206 | for (Hook hook : new Hook[]{ 207 | new HookPlayerClass(), 208 | new HookBlockBreak(), 209 | new HookBlockPlace(), 210 | new HookInstaBreak(), 211 | new HookEntityDamageByEntity(), 212 | new HookPlayerInteract() 213 | }){ 214 | builtinHooks.add(hook); 215 | } 216 | } 217 | 218 | /** 219 | * Add standard hooks if enabled. 220 | */ 221 | private void addAvailableHooks() { 222 | 223 | // Add built in hooks: 224 | for (Hook hook : builtinHooks){ 225 | boolean add = true; 226 | if (hook instanceof ConfigurableHook){ 227 | if (!((ConfigurableHook)hook).isEnabled()) add = false; 228 | } 229 | if (add){ 230 | try{ 231 | addHook(hook); 232 | } 233 | catch (Throwable t){} 234 | } 235 | } 236 | } 237 | 238 | @Override 239 | public void onEnable() { 240 | enabled = false; // make sure 241 | instance = this; 242 | // (no cleanup) 243 | 244 | // Settings: 245 | settings.clear(); 246 | setupBuiltinHooks(); 247 | loadSettings(); 248 | // Register own listener: 249 | final PluginManager pm = getServer().getPluginManager(); 250 | pm.registerEvents(this, this); 251 | pm.registerEvents(new BedrockPlayerListener(), this); 252 | pm.registerEvents(new ClientVersionListener(), this); 253 | getServer().getMessenger().registerIncomingPluginChannel(this, "cncp:geyser", new BedrockPlayerListener()); 254 | try { 255 | bungee = getServer().spigot().getConfig().getBoolean("settings.bungeecord"); 256 | 257 | // sometimes not work, try the hard way 258 | if (!bungee) { 259 | bungee = YamlConfiguration.loadConfiguration(new File("spigot.yml")).getBoolean("settings.bungeecord"); 260 | } 261 | } catch (Throwable t) { 262 | bungee = false; 263 | } 264 | super.onEnable(); 265 | 266 | // Add Hooks: 267 | addAvailableHooks(); // add before enable is set to not yet register listeners. 268 | enabled = true; 269 | 270 | // register all listeners: 271 | for (Hook hook : registeredHooks){ 272 | registerListeners(hook); 273 | } 274 | 275 | // Start ticktask 2 276 | Folia.runSyncRepatingTask(this, (arg) -> new TickTask2().run(), 1, 1); 277 | 278 | // Check for the NoCheatPlus plugin. 279 | Plugin plugin = pm.getPlugin("NoCheatPlus"); 280 | if (plugin == null) { 281 | getLogger().severe("[CompatNoCheatPlus] The NoCheatPlus plugin is not present."); 282 | } 283 | else if (plugin.isEnabled()) { 284 | getLogger().severe("[CompatNoCheatPlus] The NoCheatPlus plugin already is enabled, this might break several hooks."); 285 | } 286 | 287 | // Finished. 288 | getLogger().info(getDescription().getFullName() + " is enabled. Some hooks might get registered with NoCheatPlus later on."); 289 | } 290 | 291 | public boolean loadSettings() { 292 | final Set oldForceEnableLater = new LinkedHashSet(); 293 | oldForceEnableLater.addAll(settings.forceEnableLater); 294 | // Read and apply config to settings: 295 | File file = new File(getDataFolder() , "cncp.yml"); 296 | CompatConfig cfg = new NewConfig(file); 297 | cfg.load(); 298 | boolean changed = false; 299 | // General settings: 300 | if (Settings.addDefaults(cfg)) changed = true; 301 | settings.fromConfig(cfg); 302 | // Settings for builtin hooks: 303 | for (Hook hook : builtinHooks){ 304 | if (hook instanceof ConfigurableHook){ 305 | try{ 306 | ConfigurableHook cfgHook = (ConfigurableHook) hook; 307 | if (cfgHook.updateConfig(cfg, "hooks.")) changed = true; 308 | cfgHook.applyConfig(cfg, "hooks."); 309 | } 310 | catch (Throwable t){ 311 | getLogger().severe("[CompatNoCheatPlus] Hook failed to process config ("+hook.getHookName() +" / " + hook.getHookVersion()+"): " + t.getClass().getSimpleName() + ": "+t.getMessage()); 312 | t.printStackTrace(); 313 | } 314 | } 315 | } 316 | // save back config if changed: 317 | if (changed) cfg.save(); 318 | 319 | 320 | 321 | // Re-enable plugins that were not yet on the list: 322 | Server server = getServer(); 323 | Logger logger = server.getLogger(); 324 | for (String plgName : settings.loadPlugins){ 325 | try{ 326 | if (CompatNoCheatPlus.enablePlugin(plgName)){ 327 | System.out.println("[CompatNoCheatPlus] Ensured that the following plugin is enabled: " + plgName); 328 | } 329 | } 330 | catch (Throwable t){ 331 | logger.severe("[CompatNoCheatPlus] Failed to enable the plugin: " + plgName); 332 | logger.severe(Utils.toString(t)); 333 | } 334 | } 335 | BukkitScheduler sched = server.getScheduler(); 336 | for (String plgName : settings.forceEnableLater){ 337 | if (!oldForceEnableLater.remove(plgName)) oldForceEnableLater.add(plgName); 338 | } 339 | if (!oldForceEnableLater.isEmpty()){ 340 | System.out.println("[CompatNoCheatPlus] Schedule task to re-enable plugins later..."); 341 | sched.scheduleSyncDelayedTask(this, new Runnable() { 342 | @Override 343 | public void run() { 344 | // (Later maybe re-enabling this plugin could be added.) 345 | // TODO: log levels ! 346 | for (String plgName : oldForceEnableLater){ 347 | try{ 348 | if (disablePlugin(plgName)){ 349 | if (enablePlugin(plgName)) System.out.println("[CompatNoCheatPlus] Re-enabled plugin: " + plgName); 350 | else System.out.println("[CompatNoCheatPlus] Could not re-enable plugin: "+plgName); 351 | } 352 | else{ 353 | System.out.println("[CompatNoCheatPlus] Could not disable plugin (already disabled?): "+plgName); 354 | } 355 | } 356 | catch (Throwable t){ 357 | // TODO: maybe log ? 358 | } 359 | } 360 | } 361 | }); 362 | } 363 | 364 | return true; 365 | } 366 | 367 | @Override 368 | public void onDisable() { 369 | unregisterNCPHooks(); // Just in case. 370 | enabled = false; 371 | instance = null; // Set last. 372 | getServer().getMessenger().unregisterIncomingPluginChannel(this, "cncp:geyser"); 373 | super.onDisable(); 374 | } 375 | 376 | protected int unregisterNCPHooks() { 377 | // TODO: Clear list here !? Currently done externally... 378 | int n = 0; 379 | for (Hook hook : registeredHooks) { 380 | String hookDescr = null; 381 | try { 382 | NCPHook ncpHook = hook.getNCPHook(); 383 | if (ncpHook != null){ 384 | hookDescr = ncpHook.getHookName() + ": " + ncpHook.getHookVersion(); 385 | NCPHookManager.removeHook(ncpHook); 386 | n ++; 387 | } 388 | } catch (Throwable e) 389 | { 390 | if (hookDescr != null) { 391 | // Some error with removing a hook. 392 | getLogger().log(Level.WARNING, "Failed to unregister hook: " + hookDescr, e); 393 | } 394 | } 395 | } 396 | getLogger().info("[CompatNoCheatPlus] Removed "+n+" registered hooks from NoCheatPlus."); 397 | registeredHooks.clear(); 398 | return n; 399 | } 400 | 401 | private int registerHooks() { 402 | int n = 0; 403 | for (Hook hook : registeredHooks){ 404 | // TODO: try catch 405 | NCPHook ncpHook = hook.getNCPHook(); 406 | if (ncpHook == null) continue; 407 | NCPHookManager.addHook(hook.getCheckTypes(), ncpHook); 408 | n ++; 409 | } 410 | getLogger().info("[CompatNoCheatPlus] Added "+n+" registered hooks to NoCheatPlus."); 411 | return n; 412 | } 413 | 414 | @EventHandler(priority = EventPriority.NORMAL) 415 | void onPluginEnable(PluginEnableEvent event){ 416 | Plugin plugin = event.getPlugin(); 417 | if (!plugin.getName().equals("NoCheatPlus")) { 418 | return; 419 | } 420 | // Register to remove hooks when NCP is disabling. 421 | NCPAPIProvider.getNoCheatPlusAPI().addComponent(new IDisableListener(){ 422 | @Override 423 | public void onDisable() { 424 | // Remove all registered cncp hooks: 425 | unregisterNCPHooks(); 426 | } 427 | }); 428 | if (registeredHooks.isEmpty()) { 429 | return; 430 | } 431 | registerHooks(); 432 | } 433 | 434 | /* (non-Javadoc) 435 | * @see org.bukkit.plugin.java.JavaPlugin#onCommand(org.bukkit.command.CommandSender, org.bukkit.command.Command, java.lang.String, java.lang.String[]) 436 | */ 437 | @Override 438 | public boolean onCommand(CommandSender sender, Command command, String label, String[] args) { 439 | // Permission has already been checked. 440 | sendInfo(sender); 441 | return true; 442 | } 443 | 444 | /** 445 | * Send general version and hooks info. 446 | * @param sender 447 | */ 448 | private void sendInfo(CommandSender sender) { 449 | List infos = new LinkedList(); 450 | infos.add("---- Version infomation ----"); 451 | // Server 452 | infos.add("#### Server ####"); 453 | infos.add(getServer().getVersion()); 454 | // Core plugins (NCP + cncp) 455 | infos.add("#### Core plugins ####"); 456 | infos.add(getDescription().getFullName()); 457 | String temp = getOtherVersion("NoCheatPlus"); 458 | infos.add(temp.isEmpty() ? "NoCheatPlus is missing or not yet enabled." : temp); 459 | infos.add("#### Typical plugin dependencies ####"); 460 | for (String pluginName : new String[]{ 461 | "mcMMO", "Citizens", "MachinaCraft", "MagicSpells", "ViaVersion", "ProtocolSupport", "GravityTubes", "Geyser-Spigot", "floodgate", "CMI", "Geyser-BungeeCord" 462 | }){ 463 | temp = getOtherVersion(pluginName); 464 | if (!temp.isEmpty()) infos.add(temp); 465 | } 466 | // Hooks 467 | infos.add("#### Registered hooks (cncp) ###"); 468 | for (final Hook hook : registeredHooks){ 469 | temp = hook.getHookName() + ": " + hook.getHookVersion(); 470 | if (hook instanceof ConfigurableHook){ 471 | temp += ((ConfigurableHook) hook).isEnabled() ? " (enabled)" : " (disabled)"; 472 | } 473 | infos.add(temp); 474 | } 475 | // TODO: Registered hooks (ncp) ? 476 | infos.add("#### Registered hooks (ncp) ####"); 477 | for (final NCPHook hook : NCPHookManager.getAllHooks()){ 478 | infos.add(hook.getHookName() + ": " + hook.getHookVersion()); 479 | } 480 | final String[] a = new String[infos.size()]; 481 | infos.toArray(a); 482 | sender.sendMessage(a); 483 | } 484 | 485 | /** 486 | * 487 | * @param pluginName Empty string or "name: version". 488 | */ 489 | private String getOtherVersion(String pluginName){ 490 | Plugin plg = getServer().getPluginManager().getPlugin(pluginName); 491 | if (plg == null) return ""; 492 | PluginDescriptionFile pdf = plg.getDescription(); 493 | return pdf.getFullName(); 494 | } 495 | 496 | public Settings getSettings() { 497 | return settings; 498 | } 499 | 500 | public boolean isBungeeEnabled() { 501 | return bungee; 502 | } 503 | } 504 | -------------------------------------------------------------------------------- /src/me/asofold/bpl/cncp/bedrock/BedrockPlayerListener.java: -------------------------------------------------------------------------------- 1 | package me.asofold.bpl.cncp.bedrock; 2 | 3 | import org.bukkit.Bukkit; 4 | import org.bukkit.entity.Player; 5 | import org.bukkit.event.EventHandler; 6 | import org.bukkit.event.EventPriority; 7 | import org.bukkit.event.Listener; 8 | import org.bukkit.event.player.PlayerJoinEvent; 9 | import org.bukkit.plugin.Plugin; 10 | import org.bukkit.plugin.messaging.PluginMessageListener; 11 | import org.geysermc.connector.GeyserConnector; 12 | import org.geysermc.connector.network.session.GeyserSession; 13 | import org.geysermc.floodgate.api.FloodgateApi; 14 | import com.google.common.io.ByteArrayDataInput; 15 | import com.google.common.io.ByteStreams; 16 | 17 | import fr.neatmonster.nocheatplus.checks.CheckType; 18 | import fr.neatmonster.nocheatplus.players.DataManager; 19 | import fr.neatmonster.nocheatplus.players.IPlayerData; 20 | import me.asofold.bpl.cncp.CompatNoCheatPlus; 21 | import me.asofold.bpl.cncp.config.Settings; 22 | 23 | public class BedrockPlayerListener implements Listener, PluginMessageListener { 24 | 25 | private Plugin floodgate = Bukkit.getPluginManager().getPlugin("floodgate"); 26 | private Plugin geyser = Bukkit.getPluginManager().getPlugin("Geyser-Spigot"); 27 | private final Settings settings = CompatNoCheatPlus.getInstance().getSettings(); 28 | 29 | @EventHandler(priority = EventPriority.MONITOR) 30 | public void onPlayerJoin(PlayerJoinEvent event) { 31 | final Player player = event.getPlayer(); 32 | if (floodgate != null && floodgate.isEnabled()) { 33 | if (FloodgateApi.getInstance().isFloodgatePlayer(player.getUniqueId())) { 34 | processExemption(player); 35 | } 36 | } 37 | else if (geyser != null && geyser.isEnabled()) { 38 | try { 39 | GeyserSession session = GeyserConnector.getInstance().getPlayerByUuid(player.getUniqueId()); 40 | if (session != null) processExemption(player); 41 | } 42 | catch (NullPointerException e) {} 43 | } 44 | } 45 | 46 | private void processExemption(final Player player) { 47 | final IPlayerData pData = DataManager.getPlayerData(player); 48 | if (pData != null) { 49 | for (CheckType check : settings.extemptChecks) pData.exempt(check); 50 | pData.setBedrockPlayer(true); 51 | } 52 | } 53 | 54 | private void processExemption(final String playername) { 55 | final IPlayerData pData = DataManager.getPlayerData(playername); 56 | if (pData != null) { 57 | for (CheckType check : settings.extemptChecks) pData.exempt(check); 58 | pData.setBedrockPlayer(true); 59 | } 60 | } 61 | 62 | @Override 63 | public void onPluginMessageReceived(String channel, Player player, byte[] data) { 64 | if (CompatNoCheatPlus.getInstance().isBungeeEnabled() && channel.equals("cncp:geyser")) { 65 | geyser = null; 66 | floodgate = null; 67 | ByteArrayDataInput input = ByteStreams.newDataInput(data); 68 | String playerName = input.readUTF(); 69 | processExemption(playerName); 70 | } 71 | } 72 | } 73 | -------------------------------------------------------------------------------- /src/me/asofold/bpl/cncp/bungee/CompatNoCheatPlus.java: -------------------------------------------------------------------------------- 1 | package me.asofold.bpl.cncp.bungee; 2 | import java.io.ByteArrayOutputStream; 3 | import java.io.DataOutputStream; 4 | import java.io.IOException; 5 | import java.util.concurrent.TimeUnit; 6 | 7 | import org.geysermc.connector.GeyserConnector; 8 | import org.geysermc.connector.network.session.GeyserSession; 9 | import org.geysermc.floodgate.api.FloodgateApi; 10 | 11 | import net.md_5.bungee.api.ProxyServer; 12 | import net.md_5.bungee.api.connection.ProxiedPlayer; 13 | import net.md_5.bungee.api.connection.Server; 14 | import net.md_5.bungee.api.event.PluginMessageEvent; 15 | import net.md_5.bungee.api.event.ServerSwitchEvent; 16 | import net.md_5.bungee.api.plugin.Listener; 17 | import net.md_5.bungee.api.plugin.Plugin; 18 | import net.md_5.bungee.event.EventHandler; 19 | 20 | public class CompatNoCheatPlus extends Plugin implements Listener { 21 | private boolean floodgate; 22 | private boolean geyser; 23 | 24 | @Override 25 | public void onEnable() { 26 | geyser = checkGeyser(); 27 | floodgate = checkFloodgate(); 28 | getLogger().info("Registering listeners"); 29 | getProxy().getPluginManager().registerListener(this, this); 30 | getProxy().registerChannel("cncp:geyser"); 31 | getLogger().info("cncp Bungee mode with Geyser : " + geyser + ", Floodgate : " + floodgate); 32 | } 33 | 34 | @EventHandler 35 | public void onMessageReceive(PluginMessageEvent event) { 36 | if (event.getTag().equalsIgnoreCase("cncp:geyser")) { 37 | // Message sent from client, cancel it 38 | if (event.getSender() instanceof ProxiedPlayer) { 39 | event.setCancelled(true); 40 | } 41 | } 42 | } 43 | 44 | private boolean checkFloodgate() { 45 | return ProxyServer.getInstance().getPluginManager().getPlugin("floodgate") != null; 46 | } 47 | 48 | private boolean checkGeyser() { 49 | return ProxyServer.getInstance().getPluginManager().getPlugin("Geyser-BungeeCord") != null; 50 | } 51 | 52 | @SuppressWarnings("deprecation") 53 | private boolean isBedrockPlayer(ProxiedPlayer player) { 54 | if (floodgate) { 55 | return FloodgateApi.getInstance().isFloodgatePlayer(player.getUniqueId()); 56 | } 57 | if (geyser) { 58 | try { 59 | GeyserSession session = GeyserConnector.getInstance().getPlayerByUuid(player.getUniqueId()); 60 | return session != null; 61 | } catch (NullPointerException e) { 62 | return false; 63 | } 64 | } 65 | return false; 66 | } 67 | 68 | @EventHandler 69 | public void onChangeServer(ServerSwitchEvent event) { 70 | ProxiedPlayer player = event.getPlayer(); 71 | Server server = player.getServer(); 72 | 73 | if (!isBedrockPlayer(player)) return; 74 | 75 | ByteArrayOutputStream outputStream = new ByteArrayOutputStream(); 76 | DataOutputStream dataOutputStream = new DataOutputStream(outputStream); 77 | try { 78 | dataOutputStream.writeUTF(player.getName()); 79 | } catch (IOException e) { 80 | e.printStackTrace(); 81 | } 82 | getProxy().getScheduler().schedule(this, () -> { 83 | server.sendData("cncp:geyser", outputStream.toByteArray()); 84 | }, 1L, TimeUnit.SECONDS); 85 | } 86 | } 87 | -------------------------------------------------------------------------------- /src/me/asofold/bpl/cncp/config/Settings.java: -------------------------------------------------------------------------------- 1 | package me.asofold.bpl.cncp.config; 2 | 3 | import java.util.HashSet; 4 | import java.util.LinkedHashSet; 5 | import java.util.LinkedList; 6 | import java.util.Set; 7 | 8 | import org.bukkit.Bukkit; 9 | 10 | import fr.neatmonster.nocheatplus.checks.CheckType; 11 | import me.asofold.bpl.cncp.config.compatlayer.CompatConfig; 12 | import me.asofold.bpl.cncp.config.compatlayer.ConfigUtil; 13 | import me.asofold.bpl.cncp.config.compatlayer.NewConfig; 14 | 15 | public class Settings { 16 | public static final int configVersion = 2; 17 | 18 | public Set forceEnableLater = new LinkedHashSet(); 19 | public Set loadPlugins = new LinkedHashSet(); 20 | public Set extemptChecks = new LinkedHashSet(); 21 | 22 | public static Set preventAddHooks = new HashSet(); 23 | 24 | public static CompatConfig getDefaultConfig(){ 25 | CompatConfig cfg = new NewConfig(null); 26 | cfg.set("plugins.force-enable-later", new LinkedList()); // ConfigUtil.asList(new String[]{ "NoCheatPlus" })); 27 | cfg.set("plugins.ensure-enable", new LinkedList()); // ConfigUtil.asList(new String[]{ "WorldGuard" })); 28 | cfg.set("plugins.bedrock-extempt-checks", ConfigUtil.asList(new String[]{ 29 | "ALL", 30 | "BLOCKINTERACT_VISIBLE", 31 | "BLOCKINTERACT_DIRECTION", 32 | "BLOCKINTERACT_REACH", 33 | "BLOCKBREAK_DIRECTION", 34 | "BLOCKBREAK_NOSWING", 35 | "BLOCKBREAK_REACH", 36 | "BLOCKPLACE_NOSWING", 37 | "BLOCKPLACE_DIRECTION", 38 | "BLOCKPLACE_REACH", 39 | "BLOCKPLACE_SCAFFOLD", 40 | "FIGHT_DIRECTION", 41 | })); 42 | cfg.set("hooks.prevent-add", new LinkedList()); 43 | cfg.set("configversion", configVersion); 44 | return cfg; 45 | } 46 | 47 | public static boolean addDefaults(CompatConfig cfg){ 48 | boolean changed = false; 49 | if (cfg.getInt("configversion", 0) == 0){ 50 | cfg.remove("plugins"); 51 | cfg.set("configversion", configVersion); 52 | changed = true; 53 | } 54 | if (cfg.getInt("configversion", 0) <= 1){ 55 | if (cfg.getDouble("hooks.set-speed.fly-speed", 0.1) != 0.1){ 56 | changed = true; 57 | cfg.set("hooks.set-speed.fly-speed", 0.1); 58 | Bukkit.getLogger().warning("[CompatNoCheatPlus] Reset fly-speed for the set-speed hook to 0.1 (default) as a safety measure."); 59 | } 60 | if (cfg.getDouble("hooks.set-speed.walk-speed", 0.2) != 0.2){ 61 | changed = true; 62 | cfg.set("hooks.set-speed.walk-speed", 0.2); 63 | Bukkit.getLogger().warning("[CompatNoCheatPlus] Reset walk-speed for the set-speed hook to 0.2 (default) as a safety measure."); 64 | } 65 | } 66 | if (ConfigUtil.forceDefaults(getDefaultConfig(), cfg)) changed = true; 67 | if (cfg.getInt("configversion", 0) != configVersion){ 68 | cfg.set("configversion", configVersion); 69 | changed = true; 70 | } 71 | return changed; 72 | } 73 | 74 | public boolean fromConfig(CompatConfig cfg){ 75 | // Settings ref = new Settings(); 76 | 77 | // plugins to force enabling after this plugin. 78 | ConfigUtil.readStringSetFromList(cfg, "plugins.force-enable-later", forceEnableLater, true, true, false); 79 | ConfigUtil.readStringSetFromList(cfg, "plugins.ensure-enable", loadPlugins, true, true, false); 80 | 81 | ConfigUtil.readCheckTypeSetFromList(cfg, "plugins.bedrock-extempt-checks", extemptChecks, true, true, true); 82 | 83 | // General 84 | ConfigUtil.readStringSetFromList(cfg, "hooks.prevent-add", preventAddHooks, true, true, false); 85 | return true; 86 | } 87 | 88 | public void clear() { 89 | forceEnableLater.clear(); 90 | } 91 | 92 | } 93 | -------------------------------------------------------------------------------- /src/me/asofold/bpl/cncp/config/compatlayer/AbstractConfig.java: -------------------------------------------------------------------------------- 1 | package me.asofold.bpl.cncp.config.compatlayer; 2 | 3 | import java.util.HashSet; 4 | import java.util.LinkedList; 5 | import java.util.List; 6 | import java.util.Map; 7 | import java.util.Set; 8 | 9 | 10 | /** 11 | * Some generic checks and stuff using getString, hasEntry, getStringList, ... 12 | * @author mc_dev 13 | * 14 | */ 15 | public abstract class AbstractConfig implements CompatConfig { 16 | 17 | protected char sep = '.'; 18 | 19 | @Override 20 | public Boolean getBoolean(String path, Boolean defaultValue) { 21 | String val = getString(path, null); 22 | if ( val == null ) return defaultValue; 23 | try{ 24 | // return Boolean.parseBoolean(val); 25 | String t = val.trim().toLowerCase(); 26 | if ( t.equals("true")) return true; 27 | else if ( t.equals("false")) return false; 28 | else return defaultValue; 29 | } catch( NumberFormatException exc){ 30 | return defaultValue; 31 | } 32 | } 33 | 34 | @Override 35 | public Double getDouble(String path, Double defaultValue) { 36 | String val = getString(path, null); 37 | if ( val == null ) return defaultValue; 38 | try{ 39 | return Double.parseDouble(val); 40 | } catch( NumberFormatException exc){ 41 | return defaultValue; 42 | } 43 | } 44 | 45 | @Override 46 | public Long getLong(String path, Long defaultValue) { 47 | String val = getString(path, null); 48 | if ( val == null ) return defaultValue; 49 | try{ 50 | return Long.parseLong(val); 51 | } catch( NumberFormatException exc){ 52 | return defaultValue; 53 | } 54 | } 55 | 56 | @Override 57 | public Integer getInt(String path, Integer defaultValue) { 58 | String val = getString(path, null); 59 | if ( val == null ) return defaultValue; 60 | try{ 61 | return Integer.parseInt(val); 62 | } catch( NumberFormatException exc){ 63 | return defaultValue; 64 | } 65 | } 66 | 67 | @Override 68 | public List getIntList(String path, List defaultValue){ 69 | if ( !hasEntry(path) ) return defaultValue; 70 | List strings = getStringList(path, null); 71 | if ( strings == null ) return defaultValue; 72 | List out = new LinkedList(); 73 | for ( String s : strings){ 74 | try{ 75 | out.add(Integer.parseInt(s)); 76 | } catch(NumberFormatException exc){ 77 | // ignore 78 | } 79 | } 80 | return out; 81 | } 82 | 83 | @Override 84 | public List getDoubleList(String path, List defaultValue) { 85 | if ( !hasEntry(path) ) return defaultValue; 86 | List strings = getStringList(path, null); 87 | if ( strings == null ) return defaultValue; 88 | List out = new LinkedList(); 89 | for ( String s : strings){ 90 | try{ 91 | out.add(Double.parseDouble(s)); 92 | } catch(NumberFormatException exc){ 93 | // ignore 94 | } 95 | } 96 | return out; 97 | } 98 | 99 | @Override 100 | public Set getStringKeys(String path, boolean deep) { 101 | if (deep) return getStringKeysDeep(path); 102 | Set keys = new HashSet(); 103 | keys.addAll(getStringKeys(path)); 104 | return keys; 105 | 106 | } 107 | 108 | @Override 109 | public Set getStringKeysDeep(String path) { 110 | // NOTE: pretty inefficient, but aimed at seldomly read sections. 111 | Map values = getValuesDeep(); 112 | Set out = new HashSet(); 113 | final int len = path.length(); 114 | for (String key : values.keySet()){ 115 | if (!key.startsWith(path)) continue; 116 | else if (key.length() == len) continue; 117 | else if (key.charAt(len) == sep) out.add(key); 118 | } 119 | return out; 120 | } 121 | 122 | @Override 123 | public Object get(String path, Object defaultValue) { 124 | return getProperty(path, defaultValue); 125 | } 126 | 127 | @Override 128 | public void set(String path, Object value) { 129 | setProperty(path, value); 130 | } 131 | 132 | @Override 133 | public void remove(String path) { 134 | removeProperty(path); 135 | } 136 | 137 | @Override 138 | public Boolean getBoolean(String path) { 139 | return getBoolean(path, null); 140 | } 141 | 142 | @Override 143 | public Double getDouble(String path) { 144 | return getDouble(path, null); 145 | } 146 | 147 | @Override 148 | public List getDoubleList(String path) { 149 | return getDoubleList(path, null); 150 | } 151 | 152 | @Override 153 | public Integer getInt(String path) { 154 | return getInt(path, null); 155 | } 156 | 157 | @Override 158 | public List getIntList(String path) { 159 | return getIntList(path, null); 160 | } 161 | 162 | @Override 163 | public Integer getInteger(String path) { 164 | return getInt(path, null); 165 | } 166 | 167 | @Override 168 | public List getIntegerList(String path) { 169 | return getIntList(path, null); 170 | } 171 | 172 | @Override 173 | public String getString(String path) { 174 | return getString(path, null); 175 | } 176 | 177 | @Override 178 | public List getStringList(String path) { 179 | return getStringList(path, null); 180 | } 181 | 182 | @Override 183 | public Object get(String path) { 184 | return getProperty(path, null); 185 | } 186 | 187 | @Override 188 | public Object getProperty(String path) { 189 | return getProperty(path, null); 190 | } 191 | 192 | @Override 193 | public boolean contains(String path) { 194 | return hasEntry(path); 195 | } 196 | 197 | @Override 198 | public Integer getInteger(String path, Integer defaultValue) { 199 | return getInt(path, defaultValue); 200 | } 201 | 202 | @Override 203 | public List getIntegerList(String path, List defaultValue) { 204 | return getIntList(path, defaultValue); 205 | } 206 | 207 | @Override 208 | public Long getLong(String path) { 209 | return getLong(path, null); 210 | } 211 | 212 | 213 | } 214 | -------------------------------------------------------------------------------- /src/me/asofold/bpl/cncp/config/compatlayer/AbstractNewConfig.java: -------------------------------------------------------------------------------- 1 | package me.asofold.bpl.cncp.config.compatlayer; 2 | 3 | import java.io.File; 4 | import java.util.LinkedList; 5 | import java.util.List; 6 | import java.util.Map; 7 | import java.util.Set; 8 | 9 | import org.bukkit.configuration.Configuration; 10 | import org.bukkit.configuration.ConfigurationOptions; 11 | import org.bukkit.configuration.ConfigurationSection; 12 | import org.bukkit.configuration.MemoryConfiguration; 13 | 14 | public abstract class AbstractNewConfig extends AbstractConfig { 15 | File file = null; 16 | MemoryConfiguration config = null; 17 | 18 | public AbstractNewConfig(File file){ 19 | setFile(file); 20 | } 21 | 22 | public void setFile(File file) { 23 | this.file = file; 24 | this.config = new MemoryConfiguration(); 25 | setOptions(config); 26 | } 27 | 28 | @Override 29 | public boolean hasEntry(String path) { 30 | return config.contains(path) || (config.get(path) != null); 31 | } 32 | 33 | 34 | 35 | 36 | @Override 37 | public String getString(String path, String defaultValue) { 38 | if (!hasEntry(path)) return defaultValue; 39 | return config.getString(path, defaultValue); 40 | } 41 | 42 | 43 | 44 | @Override 45 | public List getStringKeys(String path) { 46 | // TODO policy: only strings or all keys as strings ? 47 | List out = new LinkedList(); 48 | List keys = getKeys(path); 49 | if ( keys == null ) return out; 50 | for ( Object obj : keys){ 51 | if ( obj instanceof String ) out.add((String) obj); 52 | else{ 53 | try{ 54 | out.add(obj.toString()); 55 | } catch ( Throwable t){ 56 | // ignore. 57 | } 58 | } 59 | } 60 | return out; 61 | } 62 | 63 | @Override 64 | public List getKeys(String path) { 65 | List out = new LinkedList(); 66 | Set keys; 67 | if ( path == null) keys = config.getKeys(false); 68 | else{ 69 | ConfigurationSection sec = config.getConfigurationSection(path); 70 | if (sec == null) return out; 71 | keys = sec.getKeys(false); 72 | } 73 | if ( keys == null) return out; 74 | out.addAll(keys); 75 | return out; 76 | } 77 | 78 | @Override 79 | public List getKeys() { 80 | return getKeys(null); 81 | } 82 | 83 | @Override 84 | public Object getProperty(String path, Object defaultValue) { 85 | Object obj = config.get(path); 86 | if ( obj == null ) return defaultValue; 87 | else return obj; 88 | } 89 | 90 | @Override 91 | public List getStringKeys() { 92 | return getStringKeys(null); 93 | } 94 | 95 | @Override 96 | public void setProperty(String path, Object obj) { 97 | config.set(path, obj); 98 | } 99 | 100 | @Override 101 | public List getStringList(String path, List defaultValue) { 102 | if ( !hasEntry(path)) return defaultValue; 103 | List out = new LinkedList(); 104 | List entries = config.getStringList(path); 105 | if ( entries == null ) return defaultValue; 106 | for ( String entry : entries){ 107 | if ( entry instanceof String) out.add(entry); 108 | else{ 109 | try{ 110 | out.add(entry.toString()); 111 | } catch (Throwable t){ 112 | // ignore 113 | } 114 | } 115 | } 116 | return out; 117 | } 118 | 119 | @Override 120 | public void removeProperty(String path) { 121 | if (path.startsWith(".")) path = path.substring(1); 122 | // VERY EXPENSIVE 123 | MemoryConfiguration temp = new MemoryConfiguration(); 124 | setOptions(temp); 125 | Map values = config.getValues(true); 126 | if (values.containsKey(path)) values.remove(path); 127 | else{ 128 | final String altPath = "."+path; 129 | if (values.containsKey(altPath)) values.remove(altPath); 130 | } 131 | for ( String _p : values.keySet()){ 132 | Object v = values.get(_p); 133 | if (v == null) continue; 134 | else if (v instanceof ConfigurationSection) continue; 135 | String p; 136 | if (_p.startsWith(".")) p = _p.substring(1); 137 | else p = _p; 138 | if (p.startsWith(path)) continue; 139 | temp.set(p, v); 140 | } 141 | config = temp; 142 | } 143 | 144 | 145 | @Override 146 | public Boolean getBoolean(String path, Boolean defaultValue) { 147 | if (!config.contains(path)) return defaultValue; 148 | String val = config.getString(path, null); 149 | if (val != null){ 150 | if (val.equalsIgnoreCase("true")) return true; 151 | else if (val.equalsIgnoreCase("false")) return false; 152 | else return defaultValue; 153 | } 154 | Boolean res = defaultValue; 155 | if ( val == null ){ 156 | if ( defaultValue == null) defaultValue = false; 157 | res = config.getBoolean(path, defaultValue); 158 | } 159 | return res; 160 | } 161 | 162 | 163 | 164 | 165 | @Override 166 | public Double getDouble(String path, Double defaultValue) { 167 | if (!config.contains(path)) return defaultValue; 168 | Double res = super.getDouble(path, null); 169 | if ( res == null ) res = config.getDouble(path, ConfigUtil.canaryDouble); 170 | if ( res == ConfigUtil.canaryDouble) return defaultValue; 171 | return res; 172 | } 173 | 174 | 175 | 176 | 177 | @Override 178 | public Long getLong(String path, Long defaultValue) { 179 | if (!config.contains(path)) return defaultValue; 180 | Long res = super.getLong(path, null); 181 | if ( res == null ) res = config.getLong(path, ConfigUtil.canaryLong); 182 | if ( res == ConfigUtil.canaryLong) return defaultValue; 183 | return res; 184 | } 185 | 186 | 187 | 188 | 189 | @Override 190 | public Integer getInt(String path, Integer defaultValue) { 191 | if (!config.contains(path)) return defaultValue; 192 | Integer res = super.getInt(path, null); 193 | if ( res == null ) res = config.getInt(path, ConfigUtil.canaryInt); 194 | if ( res == ConfigUtil.canaryInt) return defaultValue; 195 | return res; 196 | } 197 | 198 | 199 | 200 | 201 | @Override 202 | public List getIntList(String path, List defaultValue) { 203 | // TODO Auto-generated method stub 204 | return super.getIntList(path, defaultValue); 205 | } 206 | 207 | 208 | 209 | 210 | @Override 211 | public List getDoubleList(String path, List defaultValue) { 212 | // TODO Auto-generated method stub 213 | return super.getDoubleList(path, defaultValue); 214 | } 215 | 216 | 217 | void addAll(Configuration source, Configuration target){ 218 | Map all = source.getValues(true); 219 | for ( String path: all.keySet()){ 220 | target.set(path, source.get(path)); 221 | } 222 | } 223 | 224 | void setOptions(Configuration cfg){ 225 | ConfigurationOptions opt = cfg.options(); 226 | opt.pathSeparator(this.sep); 227 | //opt.copyDefaults(true); 228 | } 229 | 230 | @Override 231 | public boolean setPathSeparatorChar(char sep) { 232 | this.sep = sep; 233 | setOptions(config); 234 | return true; 235 | } 236 | 237 | } 238 | -------------------------------------------------------------------------------- /src/me/asofold/bpl/cncp/config/compatlayer/CompatConfig.java: -------------------------------------------------------------------------------- 1 | package me.asofold.bpl.cncp.config.compatlayer; 2 | 3 | 4 | import java.util.List; 5 | import java.util.Map; 6 | import java.util.Set; 7 | 8 | /** 9 | * CONVENTIONS: 10 | * - Return strings if objects can be made strings. 11 | * - No exceptions, rather leave elements out of lists. 12 | * - Lists of length 0 and null can not always be distinguished (?->extra safe wrapper ?) 13 | * - All contents are treated alike, even if given as a string (!): true and 'true', 1 and '1' 14 | * @author mc_dev 15 | * 16 | */ 17 | public interface CompatConfig { 18 | 19 | // Boolean 20 | /** 21 | * Only accepts true and false , 'true' and 'false'. 22 | * @param path 23 | * @param defaultValue 24 | * @return 25 | */ 26 | public Boolean getBoolean(String path, Boolean defaultValue); 27 | public Boolean getBoolean(String path); 28 | 29 | // Long 30 | public Long getLong(String path); 31 | public Long getLong(String path, Long defaultValue); 32 | 33 | // Double 34 | public Double getDouble(String path); 35 | public Double getDouble(String path, Double defaultValue); 36 | public List getDoubleList(String path); 37 | public List getDoubleList(String path , List defaultValue); 38 | 39 | // Integer (abbreviation) 40 | public Integer getInt(String path); 41 | public Integer getInt(String path, Integer defaultValue); 42 | public List getIntList(String path); 43 | public List getIntList(String path, List defaultValue); 44 | // Integer (full name) 45 | public Integer getInteger(String path); 46 | public Integer getInteger(String path, Integer defaultValue); 47 | public List getIntegerList(String path); 48 | public List getIntegerList(String path, List defaultValue); 49 | 50 | // String 51 | public String getString(String path); 52 | public String getString(String path, String defaultValue); 53 | public List getStringList(String path); 54 | public List getStringList(String path, List defaultValue); 55 | 56 | // Generic methods: 57 | public Object get(String path); 58 | public Object get(String path, Object defaultValue); 59 | public Object getProperty(String path); 60 | public Object getProperty(String path, Object defaultValue); 61 | public void set(String path, Object value); 62 | public void setProperty(String path, Object value); 63 | 64 | /** 65 | * Remove a path (would also remove sub sections, unless for path naming problems). 66 | * @param path 67 | */ 68 | public void remove(String path); 69 | 70 | /** 71 | * Works same as remove(path): removes properties and sections alike. 72 | * @param path 73 | */ 74 | public void removeProperty(String path); 75 | 76 | // Contains/has 77 | public boolean hasEntry(String path); 78 | public boolean contains(String path); 79 | 80 | // Keys (Object): [possibly deprecated] 81 | /** 82 | * @deprecated Seems not to be supported anymore by new configuration, use getStringKeys(String path); 83 | * @param path 84 | * @return 85 | */ 86 | public List getKeys(String path); 87 | /** 88 | * @deprecated Seems not to be supported anymore by new configuration, use getStringKeys(); 89 | * @return 90 | */ 91 | public List getKeys(); 92 | 93 | // Keys (String): 94 | /** 95 | * 96 | * @return never null 97 | */ 98 | public List getStringKeys(); 99 | 100 | public List getStringKeys(String path); 101 | 102 | /** 103 | * Get all keys from the section (deep or shallow). 104 | * @param path 105 | * @param deep 106 | * @return Never null. 107 | */ 108 | public Set getStringKeys(String path, boolean deep); 109 | 110 | /** 111 | * convenience method. 112 | * @param path 113 | * @return never null 114 | * 115 | */ 116 | public Set getStringKeysDeep(String path); 117 | 118 | // Values: 119 | /** 120 | * Equivalent to new config: values(true) 121 | * @return 122 | */ 123 | public Map getValuesDeep(); 124 | 125 | // Technical / IO: 126 | /** 127 | * False if not supported. 128 | * @param sep 129 | * @return 130 | */ 131 | public boolean setPathSeparatorChar(char sep); 132 | 133 | public void load(); 134 | 135 | public boolean save(); 136 | 137 | /** 138 | * Clear all contents. 139 | */ 140 | public void clear(); 141 | 142 | /** 143 | * Return a YAML-String representation of the contents, null if not supported. 144 | * @return null if not supported. 145 | */ 146 | public String getYAMLString(); 147 | 148 | /** 149 | * Add all entries from the YAML-String representation to the configuration, forget or clear all previous entries. 150 | * @return 151 | */ 152 | public boolean fromYamlString(String input); 153 | 154 | 155 | } 156 | -------------------------------------------------------------------------------- /src/me/asofold/bpl/cncp/config/compatlayer/CompatConfigFactory.java: -------------------------------------------------------------------------------- 1 | package me.asofold.bpl.cncp.config.compatlayer; 2 | 3 | import java.io.File; 4 | 5 | public class CompatConfigFactory { 6 | 7 | public static final String version = "0.8.1"; 8 | 9 | /** 10 | * Attempt to get a working file configuration.
11 | * This is not fit for fast processing.
12 | * Use getDBConfig to use this with a database.
13 | * @param file May be null (then memory is used). 14 | * @return null if fails. 15 | */ 16 | public static final CompatConfig getConfig(File file){ 17 | CompatConfig out = null; 18 | // TODO: add more (latest API) 19 | // try{ 20 | // return new OldConfig(file); 21 | // } catch (Throwable t){ 22 | // } 23 | try{ 24 | return new NewConfig(file); 25 | } catch (Throwable t){ 26 | 27 | } 28 | return out; 29 | } 30 | 31 | // public static final CompatConfig getOldConfig(File file){ 32 | // return new OldConfig(file); 33 | // } 34 | 35 | public static final CompatConfig getNewConfig(File file){ 36 | return new NewConfig(file); 37 | } 38 | 39 | // /** 40 | // * Get a ebeans based database config (!). 41 | // * @param file 42 | // * @return 43 | // */ 44 | // public static final CompatConfig getDBConfig(EbeanServer server, String dbKey){ 45 | // try{ 46 | // return new SnakeDBConfig(server, dbKey); 47 | // } catch (Throwable t){ 48 | // 49 | // } 50 | // return new DBConfig(server, dbKey); 51 | // } 52 | 53 | 54 | // TODO: add setup helpers (!) 55 | // TODO: add conversion helpers (!) 56 | } 57 | -------------------------------------------------------------------------------- /src/me/asofold/bpl/cncp/config/compatlayer/ConfigUtil.java: -------------------------------------------------------------------------------- 1 | package me.asofold.bpl.cncp.config.compatlayer; 2 | 3 | import java.util.ArrayList; 4 | import java.util.List; 5 | import java.util.Map; 6 | import java.util.Set; 7 | 8 | import fr.neatmonster.nocheatplus.checks.CheckType; 9 | 10 | public class ConfigUtil { 11 | 12 | public static final int canaryInt = Integer.MIN_VALUE +7; 13 | public static final long canaryLong = Long.MIN_VALUE + 7L; 14 | public static final double canaryDouble = -Double.MAX_VALUE + 1.2593; 15 | 16 | public static String stringPath( String path){ 17 | return stringPath(path, '.'); 18 | } 19 | 20 | public static String stringPath( String path , char sep ){ 21 | String useSep = (sep=='.')?"\\.":""+sep; 22 | String[] split = path.split(useSep); 23 | StringBuilder builder = new StringBuilder(); 24 | builder.append(stringPart(split[0])); 25 | for (int i = 1; i all = defaults.getValuesDeep(); 89 | boolean changed = false; 90 | for ( String path : all.keySet()){ 91 | if ( !config.hasEntry(path)){ 92 | config.setProperty(path, defaults.getProperty(path, null)); 93 | changed = true; 94 | } 95 | } 96 | return changed; 97 | } 98 | 99 | /** 100 | * Add StringList entries to a set. 101 | * @param cfg 102 | * @param path 103 | * @param set 104 | * @param clear If to clear the set. 105 | * @param trim 106 | * @param lowerCase 107 | */ 108 | public static void readStringSetFromList(CompatConfig cfg, String path, Set set, boolean clear, boolean trim, boolean lowerCase){ 109 | if (clear) set.clear(); 110 | List tempList = cfg.getStringList(path , null); 111 | if (tempList != null){ 112 | for (String entry : tempList){ 113 | if (trim) entry = entry.trim(); 114 | if (lowerCase) entry = entry.toLowerCase(); 115 | set.add(entry); 116 | } 117 | } 118 | } 119 | 120 | /** 121 | * Add StringList entries to a set. 122 | * @param cfg 123 | * @param path 124 | * @param set 125 | * @param clear If to clear the set. 126 | * @param trim 127 | * @param upperCase 128 | */ 129 | public static void readCheckTypeSetFromList(CompatConfig cfg, String path, Set set, boolean clear, boolean trim, boolean upperCase){ 130 | if (clear) set.clear(); 131 | List tempList = cfg.getStringList(path , null); 132 | if (tempList != null){ 133 | for (String entry : tempList) { 134 | if (trim) entry = entry.trim(); 135 | if (upperCase) entry = entry.toUpperCase(); 136 | try { 137 | final CheckType checkType = CheckType.valueOf(entry); 138 | set.add(checkType); 139 | } catch (Exception e) { 140 | System.out.println("[CompatNoCheatPlus] Unknown check " + entry + ". Skipping."); 141 | } 142 | } 143 | } 144 | } 145 | 146 | /** 147 | * Return an ArrayList. 148 | * @param input 149 | * @return 150 | */ 151 | public static final List asList(final T[] input){ 152 | final List out = new ArrayList(input.length); 153 | for (int i = 0; i < input.length; i++){ 154 | out.add(input[i]); 155 | } 156 | return out; 157 | } 158 | 159 | /** 160 | * Return an ArrayList. 161 | * @param input 162 | * @return 163 | */ 164 | public static final List asList(final int[] input){ 165 | final List out = new ArrayList(input.length); 166 | for (int i = 0; i < input.length; i++){ 167 | out.add(input[i]); 168 | } 169 | return out; 170 | } 171 | 172 | /** 173 | * Return an ArrayList. 174 | * @param input 175 | * @return 176 | */ 177 | public static final List asList(final long[] input){ 178 | final List out = new ArrayList(input.length); 179 | for (int i = 0; i < input.length; i++){ 180 | out.add(input[i]); 181 | } 182 | return out; 183 | } 184 | 185 | /** 186 | * Return an ArrayList. 187 | * @param input 188 | * @return 189 | */ 190 | public static final List asList(final double[] input){ 191 | final List out = new ArrayList(input.length); 192 | for (int i = 0; i < input.length; i++){ 193 | out.add(input[i]); 194 | } 195 | return out; 196 | } 197 | 198 | /** 199 | * Return an ArrayList. 200 | * @param input 201 | * @return 202 | */ 203 | public static final List asList(final float[] input){ 204 | final List out = new ArrayList(input.length); 205 | for (int i = 0; i < input.length; i++){ 206 | out.add(input[i]); 207 | } 208 | return out; 209 | } 210 | 211 | /** 212 | * Return an ArrayList. 213 | * @param input 214 | * @return 215 | */ 216 | public static final List asList(final boolean[] input){ 217 | final List out = new ArrayList(input.length); 218 | for (int i = 0; i < input.length; i++){ 219 | out.add(input[i]); 220 | } 221 | return out; 222 | } 223 | 224 | } 225 | -------------------------------------------------------------------------------- /src/me/asofold/bpl/cncp/config/compatlayer/NewConfig.java: -------------------------------------------------------------------------------- 1 | package me.asofold.bpl.cncp.config.compatlayer; 2 | 3 | import java.io.File; 4 | import java.util.Map; 5 | 6 | import org.bukkit.configuration.InvalidConfigurationException; 7 | import org.bukkit.configuration.MemoryConfiguration; 8 | import org.bukkit.configuration.file.FileConfiguration; 9 | import org.bukkit.configuration.file.YamlConfiguration; 10 | 11 | public class NewConfig extends AbstractNewConfig{ 12 | 13 | 14 | public NewConfig(File file) { 15 | super(file); 16 | } 17 | 18 | 19 | @Override 20 | public void load(){ 21 | config = new MemoryConfiguration(); 22 | setOptions(config); 23 | FileConfiguration cfg = YamlConfiguration.loadConfiguration(file); 24 | setOptions(cfg); 25 | addAll(cfg, config); 26 | } 27 | 28 | 29 | @Override 30 | public boolean save(){ 31 | YamlConfiguration cfg = new YamlConfiguration(); 32 | setOptions(cfg); 33 | addAll(config, cfg); 34 | try{ 35 | cfg.save(file); 36 | return true; 37 | } catch (Throwable t){ 38 | return false; 39 | } 40 | } 41 | 42 | 43 | @Override 44 | public Map getValuesDeep() { 45 | return config.getValues(true); 46 | } 47 | 48 | 49 | @Override 50 | public void clear() { 51 | setFile(file); 52 | } 53 | 54 | 55 | @Override 56 | public String getYAMLString() { 57 | final YamlConfiguration temp = new YamlConfiguration(); 58 | addAll(config, temp); 59 | return temp.saveToString(); 60 | } 61 | 62 | 63 | @Override 64 | public boolean fromYamlString(String input) { 65 | final YamlConfiguration temp = new YamlConfiguration(); 66 | try { 67 | clear(); 68 | temp.loadFromString(input); 69 | addAll(temp, config); 70 | return true; 71 | } catch (InvalidConfigurationException e) { 72 | e.printStackTrace(); 73 | return false; 74 | } 75 | } 76 | 77 | 78 | } 79 | -------------------------------------------------------------------------------- /src/me/asofold/bpl/cncp/hooks/AbstractConfigurableHook.java: -------------------------------------------------------------------------------- 1 | package me.asofold.bpl.cncp.hooks; 2 | 3 | import me.asofold.bpl.cncp.config.compatlayer.CompatConfig; 4 | import me.asofold.bpl.cncp.config.compatlayer.CompatConfigFactory; 5 | import me.asofold.bpl.cncp.config.compatlayer.ConfigUtil; 6 | import me.asofold.bpl.cncp.hooks.generic.ConfigurableHook; 7 | 8 | /** 9 | * Reads an enabled flag from the config (true by default). The prefix given will be something like "hooks.", so add your hook name to the path like:
10 | * prefix + "myhook.extra-config" 11 | * @author mc_dev 12 | * 13 | */ 14 | public class AbstractConfigurableHook extends AbstractHook implements 15 | ConfigurableHook { 16 | 17 | protected final String configPrefix; 18 | protected final String hookName, hookVersion; 19 | 20 | protected boolean enabled = true; 21 | 22 | public AbstractConfigurableHook(String hookName, String hookVersion, String configPrefix){ 23 | this.configPrefix = configPrefix; 24 | this.hookName = hookName; 25 | this.hookVersion = hookVersion; 26 | } 27 | 28 | @Override 29 | public String getHookName() { 30 | return hookName; 31 | } 32 | 33 | @Override 34 | public String getHookVersion() { 35 | return hookVersion; 36 | } 37 | 38 | @Override 39 | public void applyConfig(CompatConfig cfg, String prefix) { 40 | enabled = cfg.getBoolean(prefix + configPrefix + "enabled", true); 41 | } 42 | 43 | @Override 44 | public boolean updateConfig(CompatConfig cfg, String prefix) { 45 | CompatConfig defaults = CompatConfigFactory.getConfig(null); 46 | defaults.set(prefix + configPrefix + "enabled", true); 47 | return ConfigUtil.forceDefaults(defaults, cfg); 48 | } 49 | 50 | @Override 51 | public boolean isEnabled() { 52 | return enabled; 53 | } 54 | 55 | 56 | } 57 | -------------------------------------------------------------------------------- /src/me/asofold/bpl/cncp/hooks/AbstractHook.java: -------------------------------------------------------------------------------- 1 | package me.asofold.bpl.cncp.hooks; 2 | 3 | import org.bukkit.Bukkit; 4 | import org.bukkit.event.Listener; 5 | 6 | import fr.neatmonster.nocheatplus.checks.CheckType; 7 | import fr.neatmonster.nocheatplus.hooks.NCPHook; 8 | 9 | /** 10 | * Extend this to make sure that future changes will not break your hooks.
11 | * Probable changes:
12 | * - Adding onReload method. 13 | * @author mc_dev 14 | * 15 | */ 16 | public abstract class AbstractHook implements Hook{ 17 | 18 | @Override 19 | public CheckType[] getCheckTypes() { 20 | // Handle all CheckEvents (improbable). 21 | return null; 22 | } 23 | 24 | @Override 25 | public Listener[] getListeners() { 26 | // No listeners to register with cncp. 27 | return null; 28 | } 29 | 30 | 31 | 32 | @Override 33 | public NCPHook getNCPHook() { 34 | // No hooks to add to NCP. 35 | return null; 36 | } 37 | 38 | /** 39 | * Throw a runtime exception if the plugin is not present. 40 | * @param pluginName 41 | */ 42 | protected void assertPluginPresent(String pluginName){ 43 | if (Bukkit.getPluginManager().getPlugin(pluginName) == null) throw new RuntimeException("Assertion, " + getHookName() + ": Plugin " + pluginName + " is not present."); 44 | } 45 | 46 | } 47 | -------------------------------------------------------------------------------- /src/me/asofold/bpl/cncp/hooks/CMI/HookCMI.java: -------------------------------------------------------------------------------- 1 | package me.asofold.bpl.cncp.hooks.CMI; 2 | 3 | import org.bukkit.entity.Player; 4 | import org.bukkit.event.EventHandler; 5 | import org.bukkit.event.EventPriority; 6 | import org.bukkit.event.Listener; 7 | import org.bukkit.event.block.BlockBreakEvent; 8 | import org.bukkit.event.block.BlockPlaceEvent; 9 | import com.Zrips.CMI.CMI; 10 | import fr.neatmonster.nocheatplus.checks.CheckType; 11 | import fr.neatmonster.nocheatplus.checks.access.IViolationInfo; 12 | import fr.neatmonster.nocheatplus.hooks.NCPHook; 13 | import me.asofold.bpl.cncp.CompatNoCheatPlus; 14 | import me.asofold.bpl.cncp.config.compatlayer.CompatConfig; 15 | import me.asofold.bpl.cncp.config.compatlayer.CompatConfigFactory; 16 | import me.asofold.bpl.cncp.config.compatlayer.ConfigUtil; 17 | import me.asofold.bpl.cncp.hooks.AbstractHook; 18 | import me.asofold.bpl.cncp.hooks.generic.ConfigurableHook; 19 | import me.asofold.bpl.cncp.hooks.generic.ExemptionManager; 20 | import me.asofold.bpl.cncp.utils.TickTask2; 21 | 22 | public class HookCMI extends AbstractHook implements Listener, ConfigurableHook { 23 | 24 | protected Object ncpHook = null; 25 | 26 | protected boolean enabled = true; 27 | 28 | protected String configPrefix = "cmi."; 29 | 30 | protected final ExemptionManager exMan = new ExemptionManager(); 31 | 32 | protected final CheckType[] exemptBreakMany = new CheckType[]{ 33 | CheckType.BLOCKBREAK, CheckType.COMBINED_IMPROBABLE, 34 | }; 35 | 36 | protected final CheckType[] exemptPlaceMany = new CheckType[]{ 37 | CheckType.BLOCKPLACE, CheckType.COMBINED_IMPROBABLE, 38 | }; 39 | 40 | public HookCMI(){ 41 | assertPluginPresent("CMI"); 42 | } 43 | 44 | @Override 45 | public String getHookName() { 46 | return "CMI(default)"; 47 | } 48 | 49 | @Override 50 | public String getHookVersion() { 51 | return "1.0"; 52 | } 53 | 54 | @Override 55 | public Listener[] getListeners() { 56 | return new Listener[]{ 57 | this 58 | }; 59 | } 60 | 61 | @Override 62 | public NCPHook getNCPHook() { 63 | if (ncpHook == null){ 64 | ncpHook = new NCPHook() { 65 | @Override 66 | public String getHookName() { 67 | return "CMI(cncp)"; 68 | } 69 | 70 | @Override 71 | public String getHookVersion() { 72 | return "1.0"; 73 | } 74 | 75 | @Override 76 | public boolean onCheckFailure(CheckType checkType, Player player, IViolationInfo info) { 77 | return false; 78 | } 79 | }; 80 | } 81 | return (NCPHook) ncpHook; 82 | } 83 | 84 | @EventHandler(priority=EventPriority.MONITOR) 85 | //@RegisterMethodWithOrder(tag = CompatNoCheatPlus.tagLateFeature, afterTag = CompatNoCheatPlus.afterTagLateFeature) 86 | public final void onMirrorBreakMonitor(final BlockBreakEvent event){ 87 | removeExemption(event.getPlayer(), exemptBreakMany); 88 | } 89 | 90 | @EventHandler(priority=EventPriority.LOWEST) 91 | //@RegisterMethodWithOrder(tag = CompatNoCheatPlus.tagEarlyFeature, beforeTag = CompatNoCheatPlus.beforeTagEarlyFeature) 92 | public final void onMirrorBreakLowest(final BlockBreakEvent event){ 93 | if (CMI.getInstance().getMirrorManager().isMirroring(event.getPlayer())) { 94 | addExemption(event.getPlayer(), exemptBreakMany); 95 | } 96 | } 97 | 98 | @EventHandler(priority=EventPriority.MONITOR) 99 | //@RegisterMethodWithOrder(tag = CompatNoCheatPlus.tagLateFeature, afterTag = CompatNoCheatPlus.afterTagLateFeature) 100 | public final void onMirrorPlaceMonitor(final BlockPlaceEvent event){ 101 | removeExemption(event.getPlayer(), exemptPlaceMany); 102 | } 103 | 104 | @EventHandler(priority=EventPriority.LOWEST) 105 | //@RegisterMethodWithOrder(tag = CompatNoCheatPlus.tagEarlyFeature, beforeTag = CompatNoCheatPlus.beforeTagEarlyFeature) 106 | public final void onMirrorPlaceLowest(final BlockPlaceEvent event){ 107 | if (CMI.getInstance().getMirrorManager().isMirroring(event.getPlayer())) { 108 | addExemption(event.getPlayer(), exemptPlaceMany); 109 | } 110 | } 111 | 112 | public void addExemption(final Player player, final CheckType[] types){ 113 | for (final CheckType type : types){ 114 | exMan.addExemption(player, type); 115 | TickTask2.addUnexemptions(player, types); 116 | } 117 | } 118 | 119 | public void removeExemption(final Player player, final CheckType[] types){ 120 | for (final CheckType type : types){ 121 | exMan.removeExemption(player, type); 122 | } 123 | } 124 | 125 | @Override 126 | public void applyConfig(CompatConfig cfg, String prefix) { 127 | enabled = cfg.getBoolean(prefix + configPrefix + "enabled", true); 128 | } 129 | 130 | @Override 131 | public boolean updateConfig(CompatConfig cfg, String prefix) { 132 | CompatConfig defaults = CompatConfigFactory.getConfig(null); 133 | defaults.set(prefix + configPrefix + "enabled", true); 134 | return ConfigUtil.forceDefaults(defaults, cfg); 135 | } 136 | 137 | @Override 138 | public boolean isEnabled() { 139 | return enabled; 140 | } 141 | 142 | } 143 | -------------------------------------------------------------------------------- /src/me/asofold/bpl/cncp/hooks/GravityTubes/HookFacadeImpl.java: -------------------------------------------------------------------------------- 1 | package me.asofold.bpl.cncp.hooks.GravityTubes; 2 | 3 | import org.bukkit.GameMode; 4 | import org.bukkit.Location; 5 | import org.bukkit.entity.Player; 6 | import org.bukkit.event.player.PlayerMoveEvent; 7 | import org.bukkit.permissions.Permissible; 8 | 9 | import com.benzoft.gravitytubes.GTPerm; 10 | import com.benzoft.gravitytubes.GravityTube; 11 | import com.benzoft.gravitytubes.files.ConfigFile; 12 | import com.benzoft.gravitytubes.files.GravityTubesFile; 13 | 14 | import fr.neatmonster.nocheatplus.checks.CheckType; 15 | import fr.neatmonster.nocheatplus.checks.access.IViolationInfo; 16 | import fr.neatmonster.nocheatplus.checks.moving.MovingData; 17 | import fr.neatmonster.nocheatplus.hooks.NCPHook; 18 | import fr.neatmonster.nocheatplus.players.DataManager; 19 | import fr.neatmonster.nocheatplus.players.IPlayerData; 20 | import fr.neatmonster.nocheatplus.utilities.location.TrigUtil; 21 | import me.asofold.bpl.cncp.hooks.GravityTubes.HookGravityTubes.HookFacade; 22 | 23 | public class HookFacadeImpl implements HookFacade, NCPHook { 24 | 25 | public HookFacadeImpl(){} 26 | 27 | @Override 28 | public String getHookName() { 29 | return "GravityTubes(cncp)"; 30 | } 31 | 32 | @Override 33 | public String getHookVersion() { 34 | return "1.1"; 35 | } 36 | 37 | @Override 38 | public final boolean onCheckFailure(final CheckType checkType, final Player player, final IViolationInfo info) { 39 | //if (checkType == CheckType.MOVING_CREATIVEFLY && !ConfigFile.getInstance().isSneakToFall() ) 40 | if (player.getGameMode() == GameMode.SPECTATOR) return false; 41 | if ((checkType == CheckType.MOVING_CREATIVEFLY || checkType == CheckType.MOVING_SURVIVALFLY) && GTPerm.USE.checkPermission((Permissible)player)) { 42 | final GravityTube tube = GravityTubesFile.getInstance().getTubes().stream().filter(gravityTube -> isInTube(gravityTube, player, true, true)).findFirst().orElse(null); 43 | if (tube != null) { 44 | return true; 45 | } 46 | } 47 | return false; 48 | } 49 | 50 | private boolean isInTube(GravityTube tube, Player p, boolean longerH, boolean extendxz) { 51 | final int tubePower = tube.getPower(); 52 | int power = tubePower > 171 ? 4 : tubePower > 80 ? 3 : tubePower > 25 ? 2 : 1; 53 | final Location pLoc = p.getLocation(); 54 | final Location tLoc = tube.getSourceLocation(); 55 | final boolean b1 = p.getWorld().equals(tLoc.getWorld()) && pLoc.getY() >= tLoc.getBlockY() && pLoc.getY() <= tLoc.getBlockY() + tube.getHeight() + (longerH ? power : 0); 56 | if (!extendxz) 57 | return b1 && pLoc.getBlockX() == tLoc.getBlockX() && pLoc.getBlockZ() == tLoc.getBlockZ(); 58 | return b1 && isTubeNearby(pLoc.getBlockX(), pLoc.getBlockZ(), tLoc.getBlockX(), tLoc.getBlockZ()); 59 | } 60 | 61 | private boolean isTubeNearby(int x1, int z1, int x2, int z2) { 62 | return TrigUtil.distance(x1,z1,x2,z2) < 1.5; 63 | } 64 | 65 | @Override 66 | public void onMoveLowest(PlayerMoveEvent event) { 67 | final Player p = event.getPlayer(); 68 | if (p.getGameMode() == GameMode.SPECTATOR) return; 69 | final double hDist = TrigUtil.xzDistance(event.getFrom(), event.getTo()); 70 | final double vDist = event.getFrom().getY() - event.getTo().getY(); 71 | if (GTPerm.USE.checkPermission((Permissible)p) 72 | && vDist > 0 && hDist < 0.35 73 | && ConfigFile.getInstance().isDisableFallDamage() && p.isSneaking()) { 74 | final GravityTube tube = GravityTubesFile.getInstance().getTubes().stream().filter(gravityTube -> isInTube(gravityTube, p, false, false)).findFirst().orElse(null); 75 | final IPlayerData pData = DataManager.getPlayerData(p); 76 | if (tube != null && pData != null) { 77 | final MovingData mData = pData.getGenericInstance(MovingData.class); 78 | mData.clearNoFallData(); 79 | } 80 | } 81 | } 82 | } 83 | -------------------------------------------------------------------------------- /src/me/asofold/bpl/cncp/hooks/GravityTubes/HookGravityTubes.java: -------------------------------------------------------------------------------- 1 | package me.asofold.bpl.cncp.hooks.GravityTubes; 2 | 3 | import org.bukkit.event.EventHandler; 4 | import org.bukkit.event.EventPriority; 5 | import org.bukkit.event.Listener; 6 | import org.bukkit.event.player.PlayerMoveEvent; 7 | import fr.neatmonster.nocheatplus.hooks.NCPHook; 8 | import me.asofold.bpl.cncp.config.compatlayer.CompatConfig; 9 | import me.asofold.bpl.cncp.config.compatlayer.CompatConfigFactory; 10 | import me.asofold.bpl.cncp.config.compatlayer.ConfigUtil; 11 | import me.asofold.bpl.cncp.hooks.AbstractHook; 12 | import me.asofold.bpl.cncp.hooks.generic.ConfigurableHook; 13 | 14 | public class HookGravityTubes extends AbstractHook implements Listener, ConfigurableHook { 15 | 16 | public static interface HookFacade{ 17 | public void onMoveLowest(PlayerMoveEvent event); 18 | } 19 | 20 | protected HookFacade ncpHook = null; 21 | 22 | protected boolean enabled = true; 23 | 24 | protected String configPrefix = "gravitytubes."; 25 | 26 | public HookGravityTubes(){ 27 | assertPluginPresent("GravityTubes"); 28 | } 29 | 30 | @Override 31 | public String getHookName() { 32 | return "GravityTubes(default)"; 33 | } 34 | 35 | @Override 36 | public String getHookVersion() { 37 | return "1.0"; 38 | } 39 | 40 | @Override 41 | public Listener[] getListeners() { 42 | return new Listener[]{ 43 | this 44 | }; 45 | } 46 | 47 | @Override 48 | public NCPHook getNCPHook() { 49 | if (ncpHook == null){ 50 | ncpHook = new HookFacadeImpl(); 51 | } 52 | return (NCPHook) ncpHook; 53 | } 54 | 55 | @EventHandler(priority=EventPriority.LOWEST) 56 | //@RegisterMethodWithOrder(tag = CompatNoCheatPlus.tagEarlyFeature, beforeTag = CompatNoCheatPlus.beforeTagEarlyFeature) 57 | public final void onMoveLowest(final PlayerMoveEvent event){ 58 | ncpHook.onMoveLowest(event); 59 | } 60 | 61 | @Override 62 | public void applyConfig(CompatConfig cfg, String prefix) { 63 | enabled = cfg.getBoolean(prefix + configPrefix + "enabled", true); 64 | } 65 | 66 | @Override 67 | public boolean updateConfig(CompatConfig cfg, String prefix) { 68 | CompatConfig defaults = CompatConfigFactory.getConfig(null); 69 | defaults.set(prefix + configPrefix + "enabled", true); 70 | return ConfigUtil.forceDefaults(defaults, cfg); 71 | } 72 | 73 | @Override 74 | public boolean isEnabled() { 75 | return enabled; 76 | } 77 | } 78 | -------------------------------------------------------------------------------- /src/me/asofold/bpl/cncp/hooks/Hook.java: -------------------------------------------------------------------------------- 1 | package me.asofold.bpl.cncp.hooks; 2 | 3 | import org.bukkit.event.Listener; 4 | 5 | import fr.neatmonster.nocheatplus.checks.CheckType; 6 | import fr.neatmonster.nocheatplus.hooks.NCPHook; 7 | 8 | /** 9 | * Interface for hooking into another plugin.
10 | * NOTE: You also have to implement the methods described in NCPHook.
11 | * If you do not use listeners or don't want the prevent-hooks configuration feature 12 | * to take effect, you can also register directly with NCPHookManager. 13 | * 14 | * @author mc_dev 15 | * 16 | */ 17 | public interface Hook{ 18 | 19 | /** 20 | * 21 | * @return 22 | */ 23 | public String getHookName(); 24 | 25 | /** 26 | * 27 | * @return 28 | */ 29 | public String getHookVersion(); 30 | 31 | /** 32 | * The check types to register for, see NCPHookManager for reference, you can use ALL, 33 | */ 34 | public CheckType[] getCheckTypes(); 35 | 36 | /** 37 | * Get listener instances to be registered with cncp. 38 | * @return null if unused. 39 | */ 40 | public Listener[] getListeners(); 41 | 42 | /** 43 | * Get the hook to be registered with NCP, the registration will take place after NoCheatPlus has been enabled. 44 | * @return Should always return the same hook or null if not used. 45 | */ 46 | public NCPHook getNCPHook(); 47 | 48 | } 49 | -------------------------------------------------------------------------------- /src/me/asofold/bpl/cncp/hooks/citizens2/HookCitizens2.java: -------------------------------------------------------------------------------- 1 | package me.asofold.bpl.cncp.hooks.citizens2; 2 | 3 | import me.asofold.bpl.cncp.config.compatlayer.CompatConfig; 4 | import me.asofold.bpl.cncp.config.compatlayer.CompatConfigFactory; 5 | import me.asofold.bpl.cncp.config.compatlayer.ConfigUtil; 6 | import me.asofold.bpl.cncp.hooks.AbstractHook; 7 | import me.asofold.bpl.cncp.hooks.generic.ConfigurableHook; 8 | import net.citizensnpcs.api.CitizensAPI; 9 | 10 | import org.bukkit.entity.Player; 11 | 12 | import fr.neatmonster.nocheatplus.checks.CheckType; 13 | import fr.neatmonster.nocheatplus.checks.access.IViolationInfo; 14 | import fr.neatmonster.nocheatplus.hooks.NCPHook; 15 | 16 | public class HookCitizens2 extends AbstractHook implements ConfigurableHook{ 17 | 18 | protected Object ncpHook = null; 19 | 20 | protected boolean enabled = true; 21 | 22 | protected String configPrefix = "citizens2."; 23 | 24 | public HookCitizens2(){ 25 | assertPluginPresent("Citizens"); 26 | CitizensAPI.getNPCRegistry(); // to let it fail for old versions. 27 | } 28 | 29 | @Override 30 | public String getHookName() { 31 | return "Citizens2(default)"; 32 | } 33 | 34 | @Override 35 | public String getHookVersion() { 36 | return "2.2"; 37 | } 38 | 39 | @Override 40 | public NCPHook getNCPHook() { 41 | if (ncpHook == null){ 42 | ncpHook = new NCPHook() { 43 | @Override 44 | public final boolean onCheckFailure(final CheckType checkType, final Player player, IViolationInfo info) { 45 | return CitizensAPI.getNPCRegistry().isNPC(player); 46 | } 47 | 48 | @Override 49 | public final String getHookVersion() { 50 | return "2.0"; 51 | } 52 | 53 | @Override 54 | public final String getHookName() { 55 | return "Citizens2(cncp)"; 56 | } 57 | }; 58 | } 59 | return (NCPHook) ncpHook; 60 | } 61 | 62 | @Override 63 | public void applyConfig(CompatConfig cfg, String prefix) { 64 | enabled = cfg.getBoolean(prefix + configPrefix + "enabled", true); 65 | } 66 | 67 | @Override 68 | public boolean updateConfig(CompatConfig cfg, String prefix) { 69 | CompatConfig defaults = CompatConfigFactory.getConfig(null); 70 | defaults.set(prefix + configPrefix + "enabled", true); 71 | return ConfigUtil.forceDefaults(defaults, cfg); 72 | } 73 | 74 | @Override 75 | public boolean isEnabled() { 76 | return enabled; 77 | } 78 | 79 | } 80 | -------------------------------------------------------------------------------- /src/me/asofold/bpl/cncp/hooks/generic/ClassExemptionHook.java: -------------------------------------------------------------------------------- 1 | package me.asofold.bpl.cncp.hooks.generic; 2 | 3 | import java.util.Collection; 4 | import java.util.LinkedHashSet; 5 | import java.util.LinkedList; 6 | import java.util.List; 7 | 8 | import me.asofold.bpl.cncp.config.compatlayer.CompatConfig; 9 | import me.asofold.bpl.cncp.config.compatlayer.CompatConfigFactory; 10 | import me.asofold.bpl.cncp.config.compatlayer.ConfigUtil; 11 | import me.asofold.bpl.cncp.hooks.AbstractHook; 12 | 13 | import org.bukkit.entity.Player; 14 | 15 | import fr.neatmonster.nocheatplus.checks.CheckType; 16 | 17 | /** 18 | * Exempting players by class names for some class. 19 | * @author mc_dev 20 | * 21 | */ 22 | public abstract class ClassExemptionHook extends AbstractHook implements ConfigurableHook{ 23 | 24 | protected final ExemptionManager man = new ExemptionManager(); 25 | 26 | protected final List defaultClasses = new LinkedList(); 27 | protected final LinkedHashSet classes = new LinkedHashSet(); 28 | 29 | protected boolean defaultEnabled = true; 30 | protected boolean enabled = true; 31 | 32 | protected final String configPrefix; 33 | 34 | public ClassExemptionHook(String configPrefix){ 35 | this.configPrefix = configPrefix; 36 | } 37 | 38 | public void setClasses(final Collection classes){ 39 | this.classes.clear(); 40 | this.classes.addAll(classes); 41 | } 42 | 43 | /** 44 | * Check if a player is to be exempted and exempt for the check type. 45 | * @param player 46 | * @param clazz 47 | * @param checkType 48 | * @return If exempted. 49 | */ 50 | public boolean checkExempt(final Player player, final Class clazz, final CheckType checkType){ 51 | if (!classes.contains(clazz.getSimpleName())) return false; 52 | return man.addExemption(player, checkType); 53 | } 54 | 55 | /** 56 | * 57 | * @param player 58 | * @param checkType 59 | * @return If the player is still exempted. 60 | */ 61 | public boolean checkUnexempt(final Player player, final Class clazz, final CheckType checkType){ 62 | if (!classes.contains(clazz.getSimpleName())) return false; 63 | return man.removeExemption(player, checkType); 64 | } 65 | 66 | @Override 67 | public void applyConfig(CompatConfig cfg, String prefix) { 68 | enabled = cfg.getBoolean(prefix + configPrefix + "enabled", defaultEnabled); 69 | ConfigUtil.readStringSetFromList(cfg, prefix + configPrefix + "exempt-names", classes, true, true, false); 70 | } 71 | 72 | @Override 73 | public boolean updateConfig(CompatConfig cfg, String prefix) { 74 | CompatConfig defaults = CompatConfigFactory.getConfig(null); 75 | defaults.set(prefix + configPrefix + "enabled", defaultEnabled); 76 | defaults.set(prefix + configPrefix + "exempt-names", defaultClasses); 77 | return ConfigUtil.forceDefaults(defaults, cfg); 78 | } 79 | 80 | @Override 81 | public boolean isEnabled() { 82 | return enabled; 83 | } 84 | 85 | } 86 | -------------------------------------------------------------------------------- /src/me/asofold/bpl/cncp/hooks/generic/ConfigurableHook.java: -------------------------------------------------------------------------------- 1 | package me.asofold.bpl.cncp.hooks.generic; 2 | 3 | import me.asofold.bpl.cncp.config.compatlayer.CompatConfig; 4 | 5 | /** 6 | * A hook that is using configuration. 7 | * @author mc_dev 8 | * 9 | */ 10 | public interface ConfigurableHook { 11 | 12 | /** 13 | * Adjust internals to the given configuration. 14 | * @param cfg 15 | * @param prefix 16 | */ 17 | public void applyConfig(CompatConfig cfg, String prefix); 18 | 19 | /** 20 | * Update the given configuration with defaults where / if necessary (no blunt overwrite, it is a users config). 21 | * @param cfg 22 | * @param prefix 23 | * @return If the configuration was changed. 24 | */ 25 | public boolean updateConfig(CompatConfig cfg, String prefix); 26 | 27 | /** 28 | * If the hook is enabled by configuration or not. 29 | * @return 30 | */ 31 | public boolean isEnabled(); 32 | } 33 | -------------------------------------------------------------------------------- /src/me/asofold/bpl/cncp/hooks/generic/ExemptionManager.java: -------------------------------------------------------------------------------- 1 | package me.asofold.bpl.cncp.hooks.generic; 2 | 3 | import java.util.HashMap; 4 | import java.util.Map; 5 | 6 | import org.bukkit.entity.Player; 7 | 8 | import fr.neatmonster.nocheatplus.checks.CheckType; 9 | import fr.neatmonster.nocheatplus.hooks.NCPExemptionManager; 10 | 11 | /** 12 | * Auxiliary methods and data structure to handle simple sort of exemption.
13 | * NOTE: Not thread safe. 14 | * 15 | * @deprecated: Buggy / outdated concept - should not rely on nested stuff, use TickTask2 to unexempt timely if in doubt. 16 | * 17 | * @author mc_dev 18 | * 19 | */ 20 | public class ExemptionManager{ 21 | 22 | public static enum Status{ 23 | EXEMPTED, 24 | NOT_EXEMPTED, 25 | NEEDS_EXEMPTION, 26 | NEEDS_UNEXEMPTION, 27 | } 28 | 29 | public static class ExemptionInfo{ 30 | public static class CheckEntry{ 31 | public int skip = 0; 32 | public int exempt = 0; 33 | } 34 | /** Counts per type, for players being exempted already, to prevent unexempting. */ 35 | public final Map entries = new HashMap(); 36 | /** 37 | * If empty, it can get removed. 38 | * @return 39 | */ 40 | public boolean isEmpty(){ 41 | return entries.isEmpty(); 42 | } 43 | /** 44 | * 45 | * @param type 46 | * @param isExempted If the player is currently exempted, to be filled in with NCPHookManager.isExempted(player, type) 47 | * @return EXEMPTED or NEEDS_EXEMPTION. The latter means the player has to be exempted. 48 | */ 49 | public Status increase(final CheckType type, final boolean isExempted){ 50 | final CheckEntry entry = entries.get(type); 51 | if (entry == null){ 52 | final CheckEntry newEntry = new CheckEntry(); 53 | entries.put(type, newEntry); 54 | if (isExempted){ 55 | newEntry.skip = 1; 56 | return Status.EXEMPTED; 57 | } 58 | else{ 59 | newEntry.exempt = 1; 60 | return Status.NEEDS_EXEMPTION; 61 | } 62 | } 63 | if (entry.skip > 0){ 64 | if (isExempted){ 65 | entry.skip ++; 66 | return Status.EXEMPTED; 67 | } 68 | else{ 69 | entry.exempt = entry.skip + 1; 70 | entry.skip = 0; 71 | return Status.NEEDS_EXEMPTION; 72 | } 73 | 74 | } 75 | else{ 76 | // entry.exempt > 0 77 | entry.exempt ++; 78 | return isExempted ? Status.EXEMPTED : Status.NEEDS_EXEMPTION; 79 | } 80 | } 81 | 82 | /** 83 | * 84 | * @param type 85 | * @param isExempted If the player is currently exempted, to be filled in with NCPHookManager.isExempted(player, type) 86 | * @return Status, if NEEDS_EXEMPTION the player has to be exempted. If NEEDS_UNEXEMPTION, the player has to be unexempted. 87 | */ 88 | public Status decrease(final CheckType type, final boolean isExempted){ 89 | final CheckEntry info = entries.get(type); 90 | if (info == null) return isExempted ? Status.EXEMPTED : Status.NOT_EXEMPTED; 91 | if (info.skip > 0){ 92 | info.skip --; 93 | if (info.skip == 0){ 94 | entries.remove(type); 95 | return isExempted ? Status.EXEMPTED : Status.NOT_EXEMPTED; 96 | } 97 | else if (isExempted) return Status.EXEMPTED; 98 | else{ 99 | info.exempt = info.skip; 100 | info.skip = 0; 101 | return Status.NEEDS_EXEMPTION; 102 | } 103 | } 104 | else{ 105 | info.exempt --; 106 | if (info.exempt == 0){ 107 | entries.remove(type); 108 | return isExempted ? Status.NEEDS_UNEXEMPTION : Status.NOT_EXEMPTED; 109 | } 110 | else{ 111 | return isExempted ? Status.EXEMPTED : Status.NEEDS_EXEMPTION; 112 | } 113 | } 114 | } 115 | } 116 | 117 | /** Exact player name -> ExemptionInfo */ 118 | protected final Map exemptions; 119 | 120 | 121 | public ExemptionManager(){ 122 | this(30, 0.75f); 123 | } 124 | 125 | /** 126 | * 127 | * @param initialCapacity For the exemption HashMap. 128 | * @param loadFactor For the exemption HashMap. 129 | */ 130 | public ExemptionManager(int initialCapacity, float loadFactor) { 131 | exemptions = new HashMap(initialCapacity, loadFactor); 132 | } 133 | 134 | /** 135 | * Add exemption count and exempt, if necessary. 136 | * @param player 137 | * @param type 138 | * @return If the player was exempted already. 139 | */ 140 | public boolean addExemption(final Player player, final CheckType type){ 141 | final Status status = addExemption(player.getName(), type, NCPExemptionManager.isExempted(player, type)); 142 | if (status == Status.NEEDS_EXEMPTION) NCPExemptionManager.exemptPermanently(player, type); 143 | // System.out.println("add: " + type.toString() + " -> " + status); 144 | return status == Status.EXEMPTED; 145 | } 146 | 147 | /** 148 | * Increment exemption count. 149 | * @param name 150 | * @return If exemption is needed (NEEDS_EXEMPTION). 151 | */ 152 | public Status addExemption(final String name, final CheckType type, boolean isExempted){ 153 | final ExemptionInfo info = exemptions.get(name); 154 | final Status status; 155 | if (info == null){ 156 | final ExemptionInfo newInfo = new ExemptionInfo(); 157 | status = newInfo.increase(type, isExempted); 158 | exemptions.put(name, newInfo); 159 | } 160 | else{ 161 | status = info.increase(type, isExempted); 162 | } 163 | 164 | return status; 165 | } 166 | 167 | /** 168 | * Decrement exemption count, exempt or unexempt if necessary. 169 | * @param player 170 | * @param type 171 | * @return If the player is still exempted. 172 | */ 173 | public boolean removeExemption(final Player player, final CheckType type){ 174 | final Status status = removeExemption(player.getName(), type, NCPExemptionManager.isExempted(player, type)); 175 | if (status == Status.NEEDS_EXEMPTION) NCPExemptionManager.exemptPermanently(player, type); 176 | else if (status == Status.NEEDS_UNEXEMPTION) NCPExemptionManager.unexempt(player, type); 177 | // System.out.println("remove: " + type.toString() + " -> " + status); 178 | return status == Status.EXEMPTED || status == Status.NEEDS_EXEMPTION; 179 | } 180 | 181 | /** 182 | * Decrement exemption count. 183 | * @param name 184 | * @return Status, NEEDS_EXEMPTION and NEEDS_UNEXEMPTION make it necessary to call NCP API. 185 | */ 186 | public Status removeExemption(final String name, final CheckType type, boolean isExempted){ 187 | final ExemptionInfo info = exemptions.get(name); 188 | if (info == null) return isExempted ? Status.EXEMPTED : Status.NOT_EXEMPTED; 189 | final Status status = info.decrease(type, isExempted); 190 | if (info.isEmpty()) exemptions.remove(name); 191 | return status; 192 | } 193 | 194 | /** 195 | * Check if the player should be exempted right now according to stored info. 196 | * @param name 197 | * @param type 198 | * @return 199 | */ 200 | public boolean shouldBeExempted(final String name, final CheckType type){ 201 | final ExemptionInfo info = exemptions.get(name); 202 | if (info == null) return false; 203 | return !info.isEmpty(); 204 | } 205 | 206 | /** 207 | * Hides the API access from listeners potentially. 208 | * @param player 209 | * @param checkType 210 | */ 211 | public void exempt(final Player player, final CheckType checkType){ 212 | NCPExemptionManager.exemptPermanently(player, checkType); 213 | } 214 | 215 | /** 216 | * Hides the API access from listeners potentially. 217 | * @param player 218 | * @param checkType 219 | */ 220 | public void unexempt(final Player player, final CheckType checkType){ 221 | NCPExemptionManager.unexempt(player, checkType); 222 | } 223 | 224 | } 225 | -------------------------------------------------------------------------------- /src/me/asofold/bpl/cncp/hooks/generic/HookBlockBreak.java: -------------------------------------------------------------------------------- 1 | package me.asofold.bpl.cncp.hooks.generic; 2 | 3 | import java.util.Arrays; 4 | 5 | import me.asofold.bpl.cncp.config.compatlayer.CompatConfig; 6 | 7 | import org.bukkit.event.EventHandler; 8 | import org.bukkit.event.EventPriority; 9 | import org.bukkit.event.Listener; 10 | import org.bukkit.event.block.BlockBreakEvent; 11 | 12 | import fr.neatmonster.nocheatplus.checks.CheckType; 13 | 14 | /** 15 | * Wrap block break events to exempt players from checks by comparison of event class names. 16 | * @author mc_dev 17 | * 18 | */ 19 | public class HookBlockBreak extends ClassExemptionHook implements Listener { 20 | 21 | public HookBlockBreak() { 22 | super("block-break."); 23 | defaultClasses.addAll(Arrays.asList(new String[]{ 24 | // MachinaCraft 25 | "ArtificialBlockBreakEvent", 26 | // mcMMO 27 | "FakeBlockBreakEvent", 28 | // MagicSpells 29 | "MagicSpellsBlockBreakEvent" 30 | })); 31 | } 32 | 33 | @Override 34 | public String getHookName() { 35 | return "BlockBreak(default)"; 36 | } 37 | 38 | @Override 39 | public String getHookVersion() { 40 | return "1.1"; 41 | } 42 | 43 | @Override 44 | public Listener[] getListeners() { 45 | return new Listener[]{this}; 46 | } 47 | 48 | @Override 49 | public void applyConfig(CompatConfig cfg, String prefix) { 50 | super.applyConfig(cfg, prefix); 51 | if (classes.isEmpty()) enabled = false; 52 | } 53 | 54 | @EventHandler(priority = EventPriority.LOWEST) 55 | final void onBlockBreakLowest(final BlockBreakEvent event){ 56 | checkExempt(event.getPlayer(), event.getClass(), CheckType.BLOCKBREAK); 57 | } 58 | 59 | @EventHandler(priority = EventPriority.MONITOR) 60 | final void onBlockBreakMonitor(final BlockBreakEvent event){ 61 | checkUnexempt(event.getPlayer(), event.getClass(), CheckType.BLOCKBREAK); 62 | } 63 | 64 | } 65 | -------------------------------------------------------------------------------- /src/me/asofold/bpl/cncp/hooks/generic/HookBlockPlace.java: -------------------------------------------------------------------------------- 1 | package me.asofold.bpl.cncp.hooks.generic; 2 | 3 | import java.util.Arrays; 4 | 5 | import me.asofold.bpl.cncp.config.compatlayer.CompatConfig; 6 | 7 | import org.bukkit.event.EventHandler; 8 | import org.bukkit.event.EventPriority; 9 | import org.bukkit.event.Listener; 10 | import org.bukkit.event.block.BlockPlaceEvent; 11 | 12 | import fr.neatmonster.nocheatplus.checks.CheckType; 13 | 14 | /** 15 | * Wrap block place events to exempt players from checks by comparison of event class names. 16 | * @author mc_dev 17 | * 18 | */ 19 | public class HookBlockPlace extends ClassExemptionHook implements Listener{ 20 | 21 | public HookBlockPlace() { 22 | super("block-place."); 23 | defaultClasses.addAll(Arrays.asList(new String[]{ 24 | // MachinaCraft 25 | "ArtificialBlockPlaceEvent", 26 | // MagicSpells 27 | "MagicSpellsBlockPlaceEvent" 28 | })); 29 | } 30 | 31 | @Override 32 | public String getHookName() { 33 | return "BlockPlace(default)"; 34 | } 35 | 36 | @Override 37 | public String getHookVersion() { 38 | return "1.0"; 39 | } 40 | 41 | @Override 42 | public Listener[] getListeners() { 43 | return new Listener[]{this}; 44 | } 45 | 46 | @Override 47 | public void applyConfig(CompatConfig cfg, String prefix) { 48 | super.applyConfig(cfg, prefix); 49 | if (classes.isEmpty()) enabled = false; 50 | } 51 | 52 | @EventHandler(priority = EventPriority.LOWEST) 53 | final void onBlockPlaceLowest(final BlockPlaceEvent event){ 54 | checkExempt(event.getPlayer(), event.getClass(), CheckType.BLOCKPLACE); 55 | } 56 | 57 | @EventHandler(priority = EventPriority.MONITOR) 58 | final void onBlockPlaceMonitor(final BlockPlaceEvent event){ 59 | checkUnexempt(event.getPlayer(), event.getClass(), CheckType.BLOCKPLACE); 60 | } 61 | 62 | } 63 | -------------------------------------------------------------------------------- /src/me/asofold/bpl/cncp/hooks/generic/HookEntityDamageByEntity.java: -------------------------------------------------------------------------------- 1 | package me.asofold.bpl.cncp.hooks.generic; 2 | 3 | import java.util.Arrays; 4 | 5 | import me.asofold.bpl.cncp.config.compatlayer.CompatConfig; 6 | 7 | import org.bukkit.entity.Entity; 8 | import org.bukkit.entity.Player; 9 | import org.bukkit.event.EventHandler; 10 | import org.bukkit.event.EventPriority; 11 | import org.bukkit.event.Listener; 12 | import org.bukkit.event.entity.EntityDamageByEntityEvent; 13 | 14 | import fr.neatmonster.nocheatplus.checks.CheckType; 15 | 16 | public class HookEntityDamageByEntity extends ClassExemptionHook implements 17 | Listener { 18 | 19 | public HookEntityDamageByEntity() { 20 | super("entity-damage-by-entity."); 21 | defaultClasses.addAll(Arrays.asList(new String[] { 22 | // CrackShot 23 | "WeaponDamageEntityEvent", 24 | // MagicSpells 25 | "MagicSpellsEntityDamageByEntityEvent" })); 26 | } 27 | 28 | @Override 29 | public String getHookName() { 30 | return "EntityDamageByEntity(default)"; 31 | } 32 | 33 | @Override 34 | public String getHookVersion() { 35 | return "0.0"; 36 | } 37 | 38 | @Override 39 | public Listener[] getListeners() { 40 | return new Listener[] { this }; 41 | } 42 | 43 | @Override 44 | public void applyConfig(CompatConfig cfg, String prefix) { 45 | super.applyConfig(cfg, prefix); 46 | if (classes.isEmpty()) 47 | enabled = false; 48 | } 49 | 50 | @EventHandler(priority = EventPriority.LOWEST) 51 | final void onDamageLowest(final EntityDamageByEntityEvent event) { 52 | final Entity damager = event.getDamager(); 53 | if (damager instanceof Player) { 54 | checkExempt((Player) damager, event.getClass(), CheckType.FIGHT); 55 | } 56 | } 57 | 58 | @EventHandler(priority = EventPriority.MONITOR) 59 | final void onDamageMonitor(final EntityDamageByEntityEvent event) { 60 | final Entity damager = event.getDamager(); 61 | if (damager instanceof Player) { 62 | checkUnexempt((Player) damager, event.getClass(), CheckType.FIGHT); 63 | } 64 | } 65 | 66 | } 67 | -------------------------------------------------------------------------------- /src/me/asofold/bpl/cncp/hooks/generic/HookInstaBreak.java: -------------------------------------------------------------------------------- 1 | package me.asofold.bpl.cncp.hooks.generic; 2 | 3 | import java.util.HashSet; 4 | import java.util.Iterator; 5 | import java.util.LinkedList; 6 | import java.util.List; 7 | import java.util.Set; 8 | 9 | import me.asofold.bpl.cncp.config.compatlayer.CompatConfig; 10 | import me.asofold.bpl.cncp.config.compatlayer.CompatConfigFactory; 11 | import me.asofold.bpl.cncp.config.compatlayer.ConfigUtil; 12 | import me.asofold.bpl.cncp.hooks.AbstractHook; 13 | 14 | import org.bukkit.entity.Player; 15 | import org.bukkit.event.EventHandler; 16 | import org.bukkit.event.EventPriority; 17 | import org.bukkit.event.Listener; 18 | import org.bukkit.event.block.BlockBreakEvent; 19 | import org.bukkit.event.block.BlockDamageEvent; 20 | 21 | import fr.neatmonster.nocheatplus.checks.CheckType; 22 | import fr.neatmonster.nocheatplus.utilities.TickTask; 23 | 24 | public class HookInstaBreak extends AbstractHook implements ConfigurableHook, Listener { 25 | 26 | public static interface InstaExemption{ 27 | public void addExemptNext(CheckType[] types); 28 | public Set getExemptNext(); 29 | } 30 | 31 | public static class StackEntry{ 32 | public final CheckType[] checkTypes; 33 | public final int tick; 34 | public final Player player; 35 | public boolean used = false; 36 | public StackEntry(final Player player , final CheckType[] checkTypes){ 37 | this.player = player; 38 | this.checkTypes = checkTypes; 39 | tick = TickTask.getTick(); 40 | } 41 | public boolean isOutdated(final int tick){ 42 | return tick != this.tick; 43 | } 44 | } 45 | 46 | protected static InstaExemption runtime = null; 47 | 48 | public static void addExemptNext(final CheckType[] types){ 49 | runtime.addExemptNext(types); 50 | } 51 | 52 | protected final ExemptionManager exMan = new ExemptionManager(); 53 | 54 | protected boolean enabled = true; 55 | 56 | protected final List stack = new LinkedList(); 57 | 58 | @Override 59 | public String getHookName() { 60 | return "InstaBreak(default)"; 61 | } 62 | 63 | @Override 64 | public String getHookVersion() { 65 | return "1.0"; 66 | } 67 | 68 | @Override 69 | public void applyConfig(CompatConfig cfg, String prefix) { 70 | enabled = cfg.getBoolean(prefix + "insta-break.enabled", true); 71 | } 72 | 73 | @Override 74 | public boolean updateConfig(CompatConfig cfg, String prefix) { 75 | CompatConfig defaults = CompatConfigFactory.getConfig(null); 76 | defaults.set(prefix + "insta-break.enabled", true); 77 | return ConfigUtil.forceDefaults(defaults, cfg); 78 | } 79 | 80 | @Override 81 | public boolean isEnabled() { 82 | return enabled; 83 | } 84 | 85 | @Override 86 | public CheckType[] getCheckTypes() { 87 | return null; 88 | } 89 | 90 | @Override 91 | public Listener[] getListeners() { 92 | runtime = new InstaExemption() { 93 | protected final Set types = new HashSet(); 94 | @Override 95 | public final void addExemptNext(final CheckType[] types) { 96 | for (int i = 0; i < types.length; i++){ 97 | this.types.add(types[i]); 98 | } 99 | } 100 | @Override 101 | public Set getExemptNext() { 102 | return types; 103 | } 104 | }; 105 | return new Listener[]{this}; 106 | } 107 | 108 | protected CheckType[] fetchTypes(){ 109 | final Set types = runtime.getExemptNext(); 110 | final CheckType[] a = new CheckType[types.size()]; 111 | if (!types.isEmpty()) types.toArray(a); 112 | types.clear(); 113 | return a; 114 | } 115 | 116 | @EventHandler(priority = EventPriority.MONITOR, ignoreCancelled = false) 117 | public void onBlockDamage(final BlockDamageEvent event){ 118 | checkStack(); 119 | if (!event.isCancelled() && event.getInstaBreak()){ 120 | stack.add(new StackEntry(event.getPlayer(), fetchTypes())); 121 | } 122 | else{ 123 | runtime.getExemptNext().clear(); 124 | } 125 | } 126 | 127 | @EventHandler(priority = EventPriority.LOWEST, ignoreCancelled = false) 128 | public void onBlockBreakLowest(final BlockBreakEvent event){ 129 | checkStack(); 130 | if (!stack.isEmpty()){ 131 | final Player player = event.getPlayer(); 132 | final StackEntry entry = stack.get(stack.size() - 1); 133 | if (player.equals(entry.player)) addExemption(entry); 134 | } 135 | } 136 | 137 | @EventHandler(priority = EventPriority.MONITOR, ignoreCancelled = false) 138 | public void onBlockBreakMONITOR(final BlockBreakEvent event){ 139 | if (!stack.isEmpty()){ 140 | final Player player = event.getPlayer(); 141 | final StackEntry entry = stack.get(stack.size() - 1); 142 | if (player.equals(entry.player)) removeExemption(stack.remove(stack.size() - 1)); 143 | } 144 | } 145 | 146 | public void addExemption(final StackEntry entry){ 147 | entry.used = true; 148 | for (int i = 0; i < entry.checkTypes.length; i++){ 149 | exMan.addExemption(entry.player, entry.checkTypes[i]); 150 | } 151 | } 152 | 153 | public void removeExemption(final StackEntry entry){ 154 | if (!entry.used) return; 155 | for (int i = 0; i < entry.checkTypes.length; i++){ 156 | exMan.removeExemption(entry.player, entry.checkTypes[i]); 157 | } 158 | } 159 | 160 | public void checkStack(){ 161 | if (stack.isEmpty()) return; 162 | Iterator it = stack.iterator(); 163 | final int tick = TickTask.getTick(); 164 | while (it.hasNext()){ 165 | final StackEntry entry = it.next(); 166 | if (entry.isOutdated(tick)) it.remove(); 167 | if (entry.used) removeExemption(entry); 168 | } 169 | } 170 | 171 | } 172 | -------------------------------------------------------------------------------- /src/me/asofold/bpl/cncp/hooks/generic/HookPlayerClass.java: -------------------------------------------------------------------------------- 1 | package me.asofold.bpl.cncp.hooks.generic; 2 | 3 | import java.util.Arrays; 4 | import java.util.HashSet; 5 | import java.util.LinkedList; 6 | import java.util.Set; 7 | 8 | import me.asofold.bpl.cncp.config.compatlayer.CompatConfig; 9 | import me.asofold.bpl.cncp.config.compatlayer.CompatConfigFactory; 10 | import me.asofold.bpl.cncp.config.compatlayer.ConfigUtil; 11 | import me.asofold.bpl.cncp.hooks.AbstractHook; 12 | 13 | import org.bukkit.entity.Player; 14 | 15 | import fr.neatmonster.nocheatplus.checks.CheckType; 16 | import fr.neatmonster.nocheatplus.checks.access.IViolationInfo; 17 | import fr.neatmonster.nocheatplus.hooks.NCPHook; 18 | 19 | public final class HookPlayerClass extends AbstractHook implements ConfigurableHook { 20 | 21 | private static final boolean defaultEnabled = false; 22 | 23 | protected final Set classNames = new HashSet(); 24 | 25 | protected boolean exemptAll = true; 26 | 27 | protected boolean checkSuperClass = true; 28 | 29 | protected Object ncpHook = null; 30 | 31 | protected boolean enabled = defaultEnabled; 32 | 33 | /** 34 | * Normal class name. 35 | */ 36 | protected Set playerClassNames = new HashSet(); 37 | 38 | public HookPlayerClass(){ 39 | // TODO: Might need cleanup. 40 | this.playerClassNames.addAll(Arrays.asList(new String[]{"CraftPlayer", "SpoutCraftPlayer", "SpoutPlayer", "SpoutClientPlayer", "SpoutPlayerSnapshot"})); 41 | } 42 | 43 | @Override 44 | public final String getHookName() { 45 | return "PlayerClass(default)"; 46 | } 47 | 48 | @Override 49 | public final String getHookVersion() { 50 | return "2.3"; 51 | } 52 | 53 | @Override 54 | public NCPHook getNCPHook() { 55 | if (ncpHook == null){ 56 | ncpHook = new NCPHook() { 57 | @Override 58 | public final boolean onCheckFailure(final CheckType checkType, final Player player, final IViolationInfo info) { 59 | if (exemptAll && !playerClassNames.contains(player.getClass().getSimpleName())) return true; 60 | else { 61 | if (classNames.isEmpty()) return false; 62 | final Class clazz = player.getClass(); 63 | final String name = clazz.getSimpleName(); 64 | if (classNames.contains(name)) return true; 65 | else if (checkSuperClass){ 66 | while (true){ 67 | final Class superClass = clazz.getSuperclass(); 68 | if (superClass == null) return false; 69 | else{ 70 | final String superName = superClass.getSimpleName(); 71 | if (superName.equals("Object")) return false; 72 | else if (classNames.contains(superName)){ 73 | return true; 74 | } 75 | } 76 | } 77 | } 78 | } 79 | return false; // ECLIPSE 80 | } 81 | 82 | @Override 83 | public String getHookVersion() { 84 | return "3.1"; 85 | } 86 | 87 | @Override 88 | public String getHookName() { 89 | return "PlayerClass(cncp)"; 90 | } 91 | }; 92 | } 93 | return (NCPHook) ncpHook; 94 | } 95 | 96 | @Override 97 | public void applyConfig(CompatConfig cfg, String prefix) { 98 | enabled = cfg.getBoolean(prefix + "player-class.enabled", defaultEnabled); 99 | ConfigUtil.readStringSetFromList(cfg, prefix + "player-class.exempt-names", classNames, true, true, false); 100 | exemptAll = cfg.getBoolean(prefix + "player-class.exempt-all", true); 101 | ConfigUtil.readStringSetFromList(cfg, prefix + "player-class.class-names", playerClassNames, true, true, false); 102 | checkSuperClass = cfg.getBoolean(prefix + "player-class.super-class", true); 103 | } 104 | 105 | @Override 106 | public boolean updateConfig(CompatConfig cfg, String prefix) { 107 | CompatConfig defaults = CompatConfigFactory.getConfig(null); 108 | defaults.set(prefix + "player-class.enabled", defaultEnabled); 109 | defaults.set(prefix + "player-class.exempt-names", new LinkedList()); 110 | defaults.set(prefix + "player-class.exempt-all", true); 111 | defaults.set(prefix + "player-class.class-names", new LinkedList(playerClassNames)); 112 | defaults.set(prefix + "player-class.super-class", true); 113 | return ConfigUtil.forceDefaults(defaults, cfg); 114 | } 115 | 116 | @Override 117 | public boolean isEnabled() { 118 | return enabled; 119 | } 120 | 121 | } 122 | -------------------------------------------------------------------------------- /src/me/asofold/bpl/cncp/hooks/generic/HookPlayerInteract.java: -------------------------------------------------------------------------------- 1 | package me.asofold.bpl.cncp.hooks.generic; 2 | 3 | import fr.neatmonster.nocheatplus.checks.CheckType; 4 | import me.asofold.bpl.cncp.config.compatlayer.CompatConfig; 5 | import org.bukkit.event.EventHandler; 6 | import org.bukkit.event.EventPriority; 7 | import org.bukkit.event.Listener; 8 | import org.bukkit.event.player.PlayerInteractEvent; 9 | 10 | import java.util.Arrays; 11 | 12 | /** 13 | * Wrap player interact events to exempt players from checks by comparison of event class names. 14 | * Uses mc_dev's format for exemption based upon class names. 15 | * 16 | */ 17 | public class HookPlayerInteract extends ClassExemptionHook implements Listener{ 18 | 19 | public HookPlayerInteract() { 20 | super("player-interact."); 21 | defaultClasses.addAll(Arrays.asList(new String[]{ 22 | // MagicSpells 23 | "MagicSpellsPlayerInteractEvent" 24 | })); 25 | } 26 | 27 | @Override 28 | public String getHookName() { 29 | return "Interact(default)"; 30 | } 31 | 32 | @Override 33 | public String getHookVersion() { 34 | return "1.0"; 35 | } 36 | 37 | @Override 38 | public Listener[] getListeners() { 39 | return new Listener[]{this}; 40 | } 41 | 42 | @Override 43 | public void applyConfig(CompatConfig cfg, String prefix) { 44 | super.applyConfig(cfg, prefix); 45 | if (classes.isEmpty()) enabled = false; 46 | } 47 | 48 | @EventHandler(priority = EventPriority.LOWEST) 49 | final void onPlayerInteractLowest(final PlayerInteractEvent event){ 50 | checkExempt(event.getPlayer(), event.getClass(), CheckType.BLOCKINTERACT); 51 | } 52 | 53 | @EventHandler(priority = EventPriority.MONITOR) 54 | final void onPlayerInteractMonitor(final PlayerInteractEvent event){ 55 | checkUnexempt(event.getPlayer(), event.getClass(), CheckType.BLOCKINTERACT); 56 | } 57 | 58 | } 59 | -------------------------------------------------------------------------------- /src/me/asofold/bpl/cncp/hooks/generic/HookSetSpeed.java: -------------------------------------------------------------------------------- 1 | package me.asofold.bpl.cncp.hooks.generic; 2 | 3 | import me.asofold.bpl.cncp.config.compatlayer.CompatConfig; 4 | import me.asofold.bpl.cncp.config.compatlayer.CompatConfigFactory; 5 | import me.asofold.bpl.cncp.config.compatlayer.ConfigUtil; 6 | import me.asofold.bpl.cncp.hooks.AbstractHook; 7 | 8 | import org.bukkit.Bukkit; 9 | import org.bukkit.entity.Player; 10 | import org.bukkit.event.EventHandler; 11 | import org.bukkit.event.EventPriority; 12 | import org.bukkit.event.Listener; 13 | import org.bukkit.event.player.PlayerJoinEvent; 14 | 15 | import fr.neatmonster.nocheatplus.checks.CheckType; 16 | 17 | public class HookSetSpeed extends AbstractHook implements Listener, ConfigurableHook{ 18 | 19 | private static final float defaultFlySpeed = 0.1f; 20 | private static final float defaultWalkSpeed = 0.2f; 21 | 22 | protected float flySpeed = defaultFlySpeed; 23 | protected float walkSpeed = defaultWalkSpeed; 24 | 25 | protected boolean enabled = false; 26 | 27 | // private String allowFlightPerm = "cncp.allow-flight"; 28 | 29 | public HookSetSpeed() throws SecurityException, NoSuchMethodException{ 30 | Player.class.getDeclaredMethod("setFlySpeed", float.class); 31 | } 32 | 33 | public void init(){ 34 | for (final Player player : Bukkit.getOnlinePlayers()){ 35 | setSpeed(player); 36 | } 37 | } 38 | 39 | @Override 40 | public String getHookName() { 41 | return "SetSpeed(default)"; 42 | } 43 | 44 | @Override 45 | public String getHookVersion() { 46 | return "2.2"; 47 | } 48 | 49 | @Override 50 | public CheckType[] getCheckTypes() { 51 | return new CheckType[0]; 52 | } 53 | 54 | @Override 55 | public Listener[] getListeners() { 56 | try{ 57 | // Initialize here, at the end of enable. 58 | init(); 59 | } 60 | catch (Throwable t){} 61 | return new Listener[]{this} ; 62 | } 63 | 64 | public final void setSpeed(final Player player){ 65 | // if (allowFlightPerm.equals("") || player.hasPermission(allowFlightPerm)) player.setAllowFlight(true); 66 | player.setWalkSpeed(walkSpeed); 67 | player.setFlySpeed(flySpeed); 68 | } 69 | 70 | @EventHandler(priority=EventPriority.LOWEST) 71 | public final void onPlayerJoin(final PlayerJoinEvent event){ 72 | setSpeed(event.getPlayer()); 73 | } 74 | 75 | @Override 76 | public void applyConfig(CompatConfig cfg, String prefix) { 77 | enabled = cfg.getBoolean(prefix + "set-speed.enabled", false); 78 | flySpeed = cfg.getDouble(prefix + "set-speed.fly-speed", (double) defaultFlySpeed).floatValue(); 79 | walkSpeed = cfg.getDouble(prefix + "set-speed.walk-speed", (double) defaultWalkSpeed).floatValue(); 80 | // allowFlightPerm = cfg.getString(prefix + "set-speed.allow-flight-permission", ref.allowFlightPerm); 81 | } 82 | 83 | @Override 84 | public boolean updateConfig(CompatConfig cfg, String prefix) { 85 | CompatConfig defaults = CompatConfigFactory.getConfig(null); 86 | defaults.set(prefix + "set-speed.enabled", false); 87 | defaults.set(prefix + "set-speed.fly-speed", defaultFlySpeed); 88 | defaults.set(prefix + "set-speed.walk-speed", defaultWalkSpeed); 89 | // cfg.set(prefix + "set-speed.allow-flight-permission", ref.allowFlightPerm); 90 | return ConfigUtil.forceDefaults(defaults, cfg); 91 | } 92 | 93 | @Override 94 | public boolean isEnabled() { 95 | return enabled; 96 | } 97 | 98 | // public String getAllowFlightPerm() { 99 | // return allowFlightPerm; 100 | // } 101 | 102 | // public void setAllowFlightPerm(String allowFlightPerm) { 103 | // this.allowFlightPerm = allowFlightPerm; 104 | // } 105 | 106 | } 107 | -------------------------------------------------------------------------------- /src/me/asofold/bpl/cncp/hooks/magicspells/HookMagicSpells.java: -------------------------------------------------------------------------------- 1 | package me.asofold.bpl.cncp.hooks.magicspells; 2 | 3 | import java.util.HashMap; 4 | import java.util.HashSet; 5 | import java.util.List; 6 | import java.util.Map; 7 | import java.util.Set; 8 | 9 | import me.asofold.bpl.cncp.config.compatlayer.CompatConfig; 10 | import me.asofold.bpl.cncp.config.compatlayer.CompatConfigFactory; 11 | import me.asofold.bpl.cncp.config.compatlayer.ConfigUtil; 12 | import me.asofold.bpl.cncp.hooks.AbstractConfigurableHook; 13 | 14 | import org.bukkit.Bukkit; 15 | import org.bukkit.event.Listener; 16 | 17 | import fr.neatmonster.nocheatplus.checks.CheckType; 18 | 19 | public class HookMagicSpells extends AbstractConfigurableHook implements Listener{ 20 | 21 | protected final Map spellMap = new HashMap(); 22 | 23 | public HookMagicSpells(){ 24 | super("MagicSpells(default)", "1.0", "magicspells."); 25 | assertPluginPresent("MagicSpells"); 26 | } 27 | 28 | @Override 29 | public Listener[] getListeners() { 30 | return new Listener[]{ 31 | this 32 | }; 33 | } 34 | 35 | // @EventHandler(priority = EventPriority.MONITOR, ignoreCancelled = true) 36 | // public void onSpellCast(final SpellCastEvent event){ 37 | // if (event.getSpellCastState() != SpellCastState.NORMAL) return; 38 | // exempt(event.getCaster(), event.getSpell()); 39 | // } 40 | // 41 | // @EventHandler(priority = EventPriority.MONITOR, ignoreCancelled = true) 42 | // public void onSpellCasted(final SpellCastedEvent event){ 43 | // unexempt(event.getCaster(), event.getSpell()); 44 | // } 45 | // 46 | // private void exempt(final Player player, final Spell spell) { 47 | // final CheckType[] types = getCheckTypes(spell); 48 | // if (types == null) return; 49 | // for (final CheckType type : types){ 50 | // NCPExemptionManager.exemptPermanently(player, type); 51 | // // Safety fall-back: 52 | // // TODO: Might interfere with "slow" effects of spells ? [might add config for this.] 53 | // TickTask2.addUnexemptions(player, types); 54 | // } 55 | // } 56 | // 57 | // private void unexempt(final Player player, final Spell spell) { 58 | // final CheckType[] types = getCheckTypes(spell); 59 | // if (types == null) return; 60 | // for (final CheckType type : types){ 61 | // NCPExemptionManager.unexempt(player, type); 62 | // } 63 | // } 64 | // 65 | // protected CheckType[] getCheckTypes(final Spell spell){ 66 | // return spellMap.get(spell.getName()); 67 | // } 68 | 69 | /* (non-Javadoc) 70 | * @see me.asofold.bpl.cncp.hooks.AbstractConfigurableHook#applyConfig(me.asofold.bpl.cncp.config.compatlayer.CompatConfig, java.lang.String) 71 | */ 72 | @Override 73 | public void applyConfig(CompatConfig cfg, String prefix) { 74 | super.applyConfig(cfg, prefix); 75 | prefix += this.configPrefix; 76 | List keys = cfg.getStringKeys(prefix + "exempt-spells"); 77 | for (String key : keys){ 78 | String fullKey = ConfigUtil.bestPath(cfg, prefix + "exempt-spells." + key); 79 | String types = cfg.getString(fullKey); 80 | if (types == null) continue; 81 | String[] split = types.split(","); 82 | Set checkTypes = new HashSet(); 83 | for (String input : split){ 84 | input = input.trim().toUpperCase().replace('-', '_').replace(' ', '_').replace('.', '_'); 85 | CheckType type = null; 86 | try{ 87 | type = CheckType.valueOf(input); 88 | } 89 | catch(Throwable t){ 90 | } 91 | if (type == null){ 92 | Bukkit.getLogger().warning("[CompatNoCheatPlus] HookMagicSpells: Bad check type at " + fullKey + ": " + input); 93 | } 94 | else checkTypes.add(type); 95 | } 96 | if (checkTypes.isEmpty()){ 97 | Bukkit.getLogger().warning("[CompatNoCheatPlus] HookMagicSpells: No CheckType entries at: " + fullKey); 98 | } 99 | else{ 100 | CheckType[] a = new CheckType[checkTypes.size()]; 101 | checkTypes.toArray(a); 102 | spellMap.put(key, a); 103 | } 104 | } 105 | } 106 | 107 | /* (non-Javadoc) 108 | * @see me.asofold.bpl.cncp.hooks.AbstractConfigurableHook#updateConfig(me.asofold.bpl.cncp.config.compatlayer.CompatConfig, java.lang.String) 109 | */ 110 | @Override 111 | public boolean updateConfig(CompatConfig cfg, String prefix) { 112 | super.updateConfig(cfg, prefix); 113 | CompatConfig defaults = CompatConfigFactory.getConfig(null); 114 | prefix += this.configPrefix; 115 | // TODO: Write default section. 116 | defaults.set(prefix + "NOTE", "MagicSpells support is experimental, only instant spells can be added here."); 117 | defaults.set(prefix + "exempt-spells.NameOfExampleSpell", "COMBINED_MUNCHHAUSEN, UNKNOWN, BLOCKPLACE_NOSWING"); 118 | return ConfigUtil.forceDefaults(defaults, cfg); 119 | } 120 | 121 | } 122 | -------------------------------------------------------------------------------- /src/me/asofold/bpl/cncp/hooks/mcmmo/HookFacadeImpl.java: -------------------------------------------------------------------------------- 1 | package me.asofold.bpl.cncp.hooks.mcmmo; 2 | 3 | import java.util.HashMap; 4 | import java.util.LinkedList; 5 | import java.util.List; 6 | import java.util.Map; 7 | import java.util.Map.Entry; 8 | 9 | import org.bukkit.Bukkit; 10 | import org.bukkit.entity.Player; 11 | import org.bukkit.inventory.ItemStack; 12 | 13 | import fr.neatmonster.nocheatplus.checks.CheckType; 14 | import fr.neatmonster.nocheatplus.checks.access.IViolationInfo; 15 | import fr.neatmonster.nocheatplus.compat.Bridge1_9; 16 | import fr.neatmonster.nocheatplus.compat.Folia; 17 | import fr.neatmonster.nocheatplus.hooks.NCPHook; 18 | import fr.neatmonster.nocheatplus.players.DataManager; 19 | import fr.neatmonster.nocheatplus.utilities.map.BlockProperties; 20 | import fr.neatmonster.nocheatplus.utilities.map.BlockProperties.ToolProps; 21 | import fr.neatmonster.nocheatplus.utilities.map.BlockProperties.ToolType; 22 | import me.asofold.bpl.cncp.CompatNoCheatPlus; 23 | import me.asofold.bpl.cncp.hooks.generic.ExemptionManager; 24 | import me.asofold.bpl.cncp.hooks.generic.HookInstaBreak; 25 | import me.asofold.bpl.cncp.hooks.mcmmo.HookmcMMO.HookFacade; 26 | import me.asofold.bpl.cncp.utils.ActionFrequency; 27 | import me.asofold.bpl.cncp.utils.TickTask2; 28 | 29 | @SuppressWarnings("deprecation") 30 | public class HookFacadeImpl implements HookFacade, NCPHook { 31 | 32 | 33 | protected final ExemptionManager exMan = new ExemptionManager(); 34 | 35 | /** Normal click per block skills. */ 36 | protected final CheckType[] exemptBreakNormal = new CheckType[]{ 37 | CheckType.BLOCKBREAK_FASTBREAK, CheckType.BLOCKBREAK_FREQUENCY, 38 | CheckType.BLOCKBREAK_NOSWING, 39 | CheckType.BLOCKBREAK_WRONGBLOCK, // Not optimal but ok. 40 | }; 41 | 42 | 43 | protected final CheckType[] exemptBreakMany = new CheckType[]{ 44 | CheckType.BLOCKBREAK, CheckType.COMBINED_IMPROBABLE, 45 | }; 46 | 47 | /** Fighting damage of effects such as bleeding or area (potentially). */ 48 | protected final CheckType[] exemptFightEffect = new CheckType[]{ 49 | CheckType.FIGHT_SPEED, CheckType.FIGHT_DIRECTION, 50 | CheckType.FIGHT_ANGLE, CheckType.FIGHT_NOSWING, 51 | CheckType.FIGHT_REACH, CheckType.COMBINED_IMPROBABLE, 52 | }; 53 | 54 | // Presets for after failure exemption. 55 | protected final Map cancelChecksBlockBreak = new HashMap(); 56 | // protected final Map cancelChecksBlockDamage = new HashMap(); 57 | // protected final Map cancelChecksDamage = new HashMap(); 58 | 59 | protected boolean useInstaBreakHook; 60 | protected int clicksPerSecond; 61 | protected String cancel = null; 62 | protected long cancelTicks = 0; 63 | 64 | protected final Map cancelChecks = new HashMap(); 65 | 66 | /** 67 | * Last block breaking time 68 | */ 69 | protected final Map lastBreak = new HashMap(50); 70 | 71 | /** Counter for nested events to cancel break counting. */ 72 | protected int breakCancel = 0; 73 | 74 | protected int lastBreakAddCount = 0; 75 | protected long lastBreakCleanup = 0; 76 | 77 | public HookFacadeImpl(boolean useInstaBreakHook, int clicksPerSecond){ 78 | this.useInstaBreakHook = useInstaBreakHook; 79 | this.clicksPerSecond = clicksPerSecond; 80 | cancelChecksBlockBreak.put(CheckType.BLOCKBREAK_NOSWING, 1); 81 | cancelChecksBlockBreak.put(CheckType.BLOCKBREAK_FASTBREAK, 1); 82 | // 83 | // cancelChecksBlockDamage.put(CheckType.BLOCKBREAK_FASTBREAK, 1); 84 | // 85 | // cancelChecksDamage.put(CheckType.FIGHT_ANGLE, 1); 86 | // cancelChecksDamage.put(CheckType.FIGHT_SPEED, 1); 87 | } 88 | 89 | @Override 90 | public String getHookName() { 91 | return "mcMMO(cncp)"; 92 | } 93 | 94 | @Override 95 | public String getHookVersion() { 96 | return "2.3"; 97 | } 98 | 99 | @Override 100 | public final boolean onCheckFailure(final CheckType checkType, final Player player, final IViolationInfo info) { 101 | // System.out.println(player.getName() + " -> " + checkType + "---------------------------"); 102 | // Somewhat generic canceling mechanism (within the same tick). 103 | // Might later fail, if block break event gets scheduled after block damage having set insta break, instead of letting them follow directly. 104 | if (cancel == null){ 105 | return false; 106 | } 107 | 108 | final String name = player.getName(); 109 | if (cancel.equals(name)){ 110 | 111 | if (player.getTicksLived() != cancelTicks){ 112 | cancel = null; 113 | } 114 | else{ 115 | final Integer n = cancelChecks.get(checkType); 116 | if (n == null){ 117 | return false; 118 | } 119 | else if (n > 0){ 120 | if (n == 1) cancelChecks.remove(checkType); 121 | else cancelChecks.put(checkType, n - 1); 122 | } 123 | return true; 124 | } 125 | } 126 | return false; 127 | } 128 | 129 | private final void setPlayer(final Player player, Map cancelChecks){ 130 | cancel = player.getName(); 131 | cancelTicks = player.getTicksLived(); 132 | this.cancelChecks.clear(); 133 | this.cancelChecks.putAll(cancelChecks); 134 | } 135 | 136 | public ToolProps getToolProps(final ItemStack stack){ 137 | if (stack == null) return BlockProperties.noTool; 138 | else return BlockProperties.getToolProps(stack); 139 | } 140 | 141 | public void addExemption(final Player player, final CheckType[] types){ 142 | for (final CheckType type : types){ 143 | exMan.addExemption(player, type); 144 | TickTask2.addUnexemptions(player, types); 145 | } 146 | } 147 | 148 | public void removeExemption(final Player player, final CheckType[] types){ 149 | for (final CheckType type : types){ 150 | exMan.removeExemption(player, type); 151 | } 152 | } 153 | 154 | @Override 155 | public final void damageLowest(final Player player) { 156 | // System.out.println("damage lowest"); 157 | // setPlayer(player, cancelChecksDamage); 158 | addExemption(player, exemptFightEffect); 159 | } 160 | 161 | @Override 162 | public final void blockDamageLowest(final Player player) { 163 | // System.out.println("block damage lowest"); 164 | // setPlayer(player, cancelChecksBlockDamage); 165 | if (getToolProps(Bridge1_9.getItemInMainHand(player)).toolType == ToolType.AXE) addExemption(player, exemptBreakMany); 166 | else addExemption(player, exemptBreakNormal); 167 | } 168 | 169 | @Override 170 | public final boolean blockBreakLowest(final Player player) { 171 | // System.out.println("block break lowest"); 172 | final boolean isAxe = getToolProps(Bridge1_9.getItemInMainHand(player)).toolType == ToolType.AXE; 173 | if (breakCancel > 0){ 174 | breakCancel ++; 175 | return true; 176 | } 177 | final String name = player.getName(); 178 | ActionFrequency freq = lastBreak.get(name); 179 | final long now = System.currentTimeMillis(); 180 | if (freq == null){ 181 | freq = new ActionFrequency(3, 333); 182 | freq.add(now, 1f); 183 | lastBreak.put(name, freq); 184 | lastBreakAddCount ++; 185 | if (lastBreakAddCount > 100){ 186 | lastBreakAddCount = 0; 187 | cleanupLastBreaks(); 188 | } 189 | } 190 | else if (!isAxe){ 191 | freq.add(now, 1f); 192 | if (freq.score(1f) > (float) clicksPerSecond){ 193 | breakCancel ++; 194 | return true; 195 | } 196 | } 197 | 198 | addExemption(player, exemptBreakNormal); 199 | if (useInstaBreakHook){ 200 | HookInstaBreak.addExemptNext(exemptBreakNormal); 201 | TickTask2.addUnexemptions(player, exemptBreakNormal); 202 | } 203 | else if (!isAxe){ 204 | setPlayer(player, cancelChecksBlockBreak); 205 | Folia.runSyncTask(CompatNoCheatPlus.getInstance(), (arg) -> DataManager.removeData(player.getName(), CheckType.BLOCKBREAK_FASTBREAK)); 206 | } 207 | return false; 208 | } 209 | 210 | protected void cleanupLastBreaks() { 211 | final long ts = System.currentTimeMillis(); 212 | if (ts - lastBreakCleanup < 30000 && ts > lastBreakCleanup) return; 213 | lastBreakCleanup = ts; 214 | final List rem = new LinkedList(); 215 | if (ts >= lastBreakCleanup){ 216 | for (final Entry entry : lastBreak.entrySet()){ 217 | if (entry.getValue().score(1f) == 0f) rem.add(entry.getKey()); 218 | } 219 | } 220 | else{ 221 | rem.addAll(lastBreak.keySet()); 222 | } 223 | for (final String key :rem){ 224 | lastBreak.remove(key); 225 | } 226 | } 227 | 228 | @Override 229 | public void damageMonitor(Player player) { 230 | // System.out.println("damage monitor"); 231 | removeExemption(player, exemptFightEffect); 232 | } 233 | 234 | @Override 235 | public void blockDamageMonitor(Player player) { 236 | // System.out.println("block damage monitor"); 237 | if (getToolProps(player.getItemInHand()).toolType == ToolType.AXE) addExemption(player, exemptBreakMany); 238 | else removeExemption(player, exemptBreakNormal); 239 | } 240 | 241 | @Override 242 | public void blockBreakMontitor(Player player) { 243 | if (breakCancel > 0){ 244 | breakCancel --; 245 | return; 246 | } 247 | // System.out.println("block break monitor"); 248 | removeExemption(player, exemptBreakNormal); 249 | } 250 | 251 | 252 | 253 | } 254 | -------------------------------------------------------------------------------- /src/me/asofold/bpl/cncp/hooks/mcmmo/HookmcMMO.java: -------------------------------------------------------------------------------- 1 | package me.asofold.bpl.cncp.hooks.mcmmo; 2 | 3 | import me.asofold.bpl.cncp.config.compatlayer.CompatConfig; 4 | import me.asofold.bpl.cncp.config.compatlayer.CompatConfigFactory; 5 | import me.asofold.bpl.cncp.config.compatlayer.ConfigUtil; 6 | import me.asofold.bpl.cncp.hooks.AbstractHook; 7 | import me.asofold.bpl.cncp.hooks.generic.ConfigurableHook; 8 | import me.asofold.bpl.cncp.utils.PluginGetter; 9 | 10 | import org.bukkit.entity.Entity; 11 | import org.bukkit.entity.Player; 12 | import org.bukkit.event.EventHandler; 13 | import org.bukkit.event.EventPriority; 14 | import org.bukkit.event.Listener; 15 | 16 | import com.gmail.nossr50.mcMMO; 17 | import com.gmail.nossr50.events.fake.FakeBlockBreakEvent; 18 | import com.gmail.nossr50.events.fake.FakeBlockDamageEvent; 19 | import com.gmail.nossr50.events.fake.FakeEntityDamageByEntityEvent; 20 | 21 | import fr.neatmonster.nocheatplus.checks.CheckType; 22 | import fr.neatmonster.nocheatplus.hooks.NCPHook; 23 | 24 | public final class HookmcMMO extends AbstractHook implements Listener, ConfigurableHook { 25 | 26 | /** 27 | * To let the listener access this. 28 | * @author mc_dev 29 | * 30 | */ 31 | public static interface HookFacade{ 32 | public void damageLowest(Player player); 33 | public void damageMonitor(Player player); 34 | public void blockDamageLowest(Player player); 35 | public void blockDamageMonitor(Player player); 36 | /** 37 | * If to cancel the event. 38 | * @param player 39 | * @return 40 | */ 41 | public boolean blockBreakLowest(Player player); 42 | public void blockBreakMontitor(Player player); 43 | } 44 | 45 | protected HookFacade ncpHook = null; 46 | 47 | protected boolean enabled = true; 48 | 49 | protected String configPrefix = "mcmmo."; 50 | 51 | protected boolean useInstaBreakHook = true; 52 | 53 | 54 | public HookmcMMO(){ 55 | assertPluginPresent("mcMMO"); 56 | } 57 | 58 | 59 | protected final PluginGetter fetch = new PluginGetter("mcMMO"); 60 | 61 | protected int blocksPerSecond = 30; 62 | 63 | 64 | 65 | @Override 66 | public String getHookName() { 67 | return "mcMMO(default)"; 68 | } 69 | 70 | @Override 71 | public String getHookVersion() { 72 | return "2.1"; 73 | } 74 | 75 | @Override 76 | public CheckType[] getCheckTypes() { 77 | return new CheckType[]{ 78 | CheckType.BLOCKBREAK_FASTBREAK, CheckType.BLOCKBREAK_NOSWING, // old ones 79 | 80 | // CheckType.BLOCKBREAK_DIRECTION, CheckType.BLOCKBREAK_FREQUENCY, 81 | // CheckType.BLOCKBREAK_WRONGBLOCK, CheckType.BLOCKBREAK_REACH, 82 | // 83 | // CheckType.FIGHT_ANGLE, CheckType.FIGHT_SPEED, // old ones 84 | // 85 | // CheckType.FIGHT_DIRECTION, CheckType.FIGHT_NOSWING, 86 | // CheckType.FIGHT_REACH, 87 | }; 88 | } 89 | 90 | @Override 91 | public Listener[] getListeners() { 92 | fetch.fetchPlugin(); 93 | return new Listener[]{this, fetch}; 94 | } 95 | 96 | @Override 97 | public NCPHook getNCPHook() { 98 | if (ncpHook == null){ 99 | ncpHook = new HookFacadeImpl(useInstaBreakHook, blocksPerSecond); 100 | } 101 | return (NCPHook) ncpHook; 102 | } 103 | 104 | /////////////////////////// 105 | // Damage (fight) 106 | ////////////////////////// 107 | 108 | @EventHandler(priority=EventPriority.LOWEST) 109 | final void onDamageLowest(final FakeEntityDamageByEntityEvent event){ 110 | final Entity entity = event.getDamager(); 111 | if (entity instanceof Player) 112 | ncpHook.damageLowest((Player) entity); 113 | } 114 | 115 | @EventHandler(priority=EventPriority.MONITOR) 116 | final void onDamageMonitor(final FakeEntityDamageByEntityEvent event){ 117 | final Entity entity = event.getDamager(); 118 | if (entity instanceof Player) 119 | ncpHook.damageMonitor((Player) entity); 120 | } 121 | 122 | /////////////////////////// 123 | // Block damage 124 | ////////////////////////// 125 | 126 | @EventHandler(priority=EventPriority.LOWEST) 127 | final void onBlockDamageLowest(final FakeBlockDamageEvent event){ 128 | ncpHook.blockDamageLowest(event.getPlayer()); 129 | } 130 | 131 | @EventHandler(priority=EventPriority.LOWEST) 132 | final void onBlockDamageMonitor(final FakeBlockDamageEvent event){ 133 | ncpHook.blockDamageMonitor(event.getPlayer()); 134 | } 135 | 136 | /////////////////////////// 137 | // Block break 138 | ////////////////////////// 139 | 140 | @EventHandler(priority=EventPriority.LOWEST) 141 | final void onBlockBreakLowest(final FakeBlockBreakEvent event){ 142 | if (ncpHook.blockBreakLowest(event.getPlayer())){ 143 | event.setCancelled(true); 144 | // System.out.println("Cancelled for frequency."); 145 | } 146 | } 147 | 148 | @EventHandler(priority=EventPriority.MONITOR) 149 | final void onBlockBreakLMonitor(final FakeBlockBreakEvent event){ 150 | ncpHook.blockBreakMontitor(event.getPlayer()); 151 | } 152 | 153 | ///////////////////////////////// 154 | // Config 155 | ///////////////////////////////// 156 | 157 | @Override 158 | public void applyConfig(CompatConfig cfg, String prefix) { 159 | enabled = cfg.getBoolean(prefix + configPrefix + "enabled", true); 160 | useInstaBreakHook = cfg.getBoolean(prefix + configPrefix + "use-insta-break-hook", true); 161 | blocksPerSecond = cfg.getInt(prefix + configPrefix + "clickspersecond", 20); 162 | } 163 | 164 | @Override 165 | public boolean updateConfig(CompatConfig cfg, String prefix) { 166 | CompatConfig defaults = CompatConfigFactory.getConfig(null); 167 | defaults.set(prefix + configPrefix + "enabled", true); 168 | defaults.set(prefix + configPrefix + "use-insta-break-hook", true); 169 | defaults.set(prefix + configPrefix + "clickspersecond", 20); 170 | return ConfigUtil.forceDefaults(defaults, cfg); 171 | } 172 | 173 | @Override 174 | public boolean isEnabled() { 175 | return enabled; 176 | } 177 | 178 | } 179 | -------------------------------------------------------------------------------- /src/me/asofold/bpl/cncp/utils/ActionFrequency.java: -------------------------------------------------------------------------------- 1 | package me.asofold.bpl.cncp.utils; 2 | 3 | /** 4 | * Keep track of frequency of some action, 5 | * put weights into buckets, which represent intervals of time.
6 | * (Taken from NoCheatPlus.) 7 | * @author mc_dev 8 | * 9 | */ 10 | public class ActionFrequency { 11 | 12 | /** Reference time for the transition from the first to the second bucket. */ 13 | private long time = 0; 14 | /** 15 | * Time of last update (add). Should be the "time of the last event" for the 16 | * usual case. 17 | */ 18 | private long lastUpdate = 0; 19 | private final boolean noAutoReset; 20 | 21 | /** 22 | * Buckets to fill weights in, each represents an interval of durBucket duration, 23 | * index 0 is the latest, highest index is the oldest. 24 | * Weights will get filled into the next buckets with time passed. 25 | */ 26 | private final float[] buckets; 27 | 28 | /** Duration in milliseconds that one bucket covers. */ 29 | private final long durBucket; 30 | 31 | /** 32 | * This constructor will set noAutoReset to false, optimized for short term 33 | * accounting. 34 | * 35 | * @param nBuckets 36 | * @param durBucket 37 | */ 38 | public ActionFrequency(final int nBuckets, final long durBucket) { 39 | this(nBuckets, durBucket, false); 40 | } 41 | 42 | /** 43 | * 44 | * @param nBuckets 45 | * @param durBucket 46 | * @param noAutoReset 47 | * Set to true, to prevent auto-resetting with 48 | * "time ran backwards". Setting this to true is recommended if 49 | * larger time frames are monitored, to prevent data loss. 50 | */ 51 | public ActionFrequency(final int nBuckets, final long durBucket, final boolean noAutoReset) { 52 | this.buckets = new float[nBuckets]; 53 | this.durBucket = durBucket; 54 | this.noAutoReset = noAutoReset; 55 | } 56 | 57 | /** 58 | * Update and add (updates reference and update time). 59 | * @param now 60 | * @param amount 61 | */ 62 | public final void add(final long now, final float amount) { 63 | update(now); 64 | buckets[0] += amount; 65 | } 66 | 67 | /** 68 | * Unchecked addition of amount to the first bucket. 69 | * @param amount 70 | */ 71 | public final void add(final float amount) { 72 | buckets[0] += amount; 73 | } 74 | 75 | /** 76 | * Update without adding, also updates reference and update time. Detects 77 | * time running backwards. 78 | * 79 | * @param now 80 | */ 81 | public final void update(final long now) { 82 | final long diff = now - time; 83 | if (now < lastUpdate) { 84 | // Time ran backwards. 85 | if (noAutoReset) { 86 | // Only update time and lastUpdate. 87 | time = lastUpdate = now; 88 | } else { 89 | // Clear all. 90 | clear(now); 91 | return; 92 | } 93 | } 94 | else if (diff >= durBucket * buckets.length) { 95 | // Clear (beyond range). 96 | clear(now); 97 | return; 98 | } 99 | else if (diff < durBucket) { 100 | // No changes (first bucket). 101 | } 102 | else { 103 | final int shift = (int) ((float) diff / (float) durBucket); 104 | // Update buckets. 105 | for (int i = 0; i < buckets.length - shift; i++) { 106 | buckets[buckets.length - (i + 1)] = buckets[buckets.length - (i + 1 + shift)]; 107 | } 108 | for (int i = 0; i < shift; i++) { 109 | buckets[i] = 0; 110 | } 111 | // Set time according to bucket duration (!). 112 | time += durBucket * shift; 113 | } 114 | // Ensure lastUpdate is set. 115 | lastUpdate = now; 116 | } 117 | 118 | /** 119 | * Clear all counts, reset reference and update time. 120 | * @param now 121 | */ 122 | public final void clear(final long now) { 123 | for (int i = 0; i < buckets.length; i++) { 124 | buckets[i] = 0f; 125 | } 126 | time = lastUpdate = now; 127 | } 128 | 129 | /** 130 | * @deprecated Use instead: score(float). 131 | * @param factor 132 | * @return 133 | */ 134 | public final float getScore(final float factor) { 135 | return score(factor); 136 | } 137 | 138 | /** 139 | * @deprecated Use instead: score(float). 140 | * @param factor 141 | * @return 142 | */ 143 | public final float getScore(final int bucket) { 144 | return bucketScore(bucket); 145 | } 146 | 147 | /** 148 | * Get a weighted sum score, weight for bucket i: w(i) = factor^i. 149 | * @param factor 150 | * @return 151 | */ 152 | public final float score(final float factor) { 153 | return sliceScore(0, buckets.length, factor); 154 | } 155 | 156 | /** 157 | * Get score of a certain bucket. At own risk. 158 | * @param bucket 159 | * @return 160 | */ 161 | public final float bucketScore(final int bucket) { 162 | return buckets[bucket]; 163 | } 164 | 165 | /** 166 | * Get score of first end buckets, with factor. 167 | * @param end Number of buckets including start. The end is not included. 168 | * @param factor 169 | * @return 170 | */ 171 | public final float leadingScore(final int end, float factor) { 172 | return sliceScore(0, end, factor); 173 | } 174 | 175 | /** 176 | * Get score from start on, with factor. 177 | * @param start This is included. 178 | * @param factor 179 | * @return 180 | */ 181 | public final float trailingScore(final int start, float factor) { 182 | return sliceScore(start, buckets.length, factor); 183 | } 184 | 185 | /** 186 | * Get score from start on, until before end, with factor. 187 | * @param start This is included. 188 | * @param end This is not included. 189 | * @param factor 190 | * @return 191 | */ 192 | public final float sliceScore(final int start, final int end, float factor) { 193 | float score = buckets[start]; 194 | float cf = factor; 195 | for (int i = start + 1; i < end; i++) { 196 | score += buckets[i] * cf; 197 | cf *= factor; 198 | } 199 | return score; 200 | } 201 | 202 | /** 203 | * Set the value for a buckt. 204 | * @param n 205 | * @param value 206 | */ 207 | public final void setBucket(final int n, final float value) { 208 | buckets[n] = value; 209 | } 210 | 211 | /** 212 | * Set the reference time and last update time. 213 | * @param time 214 | */ 215 | public final void setTime(final long time) { 216 | this.time = time; 217 | this.lastUpdate = time; 218 | } 219 | 220 | /** 221 | * Get the reference time for the transition from the first to the second bucket. 222 | * @return 223 | */ 224 | public final long lastAccess() { // TODO: Should rename this. 225 | return time; 226 | } 227 | 228 | /** 229 | * Get the last time when update was called (adding). 230 | * @return 231 | */ 232 | public final long lastUpdate() { 233 | return lastUpdate; 234 | } 235 | 236 | /** 237 | * Get the number of buckets. 238 | * @return 239 | */ 240 | public final int numberOfBuckets() { 241 | return buckets.length; 242 | } 243 | 244 | /** 245 | * Get the duration of a bucket in milliseconds. 246 | * @return 247 | */ 248 | public final long bucketDuration() { 249 | return durBucket; 250 | } 251 | 252 | /** 253 | * Serialize to a String line. 254 | * @return 255 | */ 256 | public final String toLine() { 257 | // TODO: Backwards-compatible lastUpdate ? 258 | final StringBuilder buffer = new StringBuilder(50); 259 | buffer.append(buckets.length + ","+durBucket+","+time); 260 | for (int i = 0; i < buckets.length; i++) { 261 | buffer.append("," + buckets[i]); 262 | } 263 | return buffer.toString(); 264 | } 265 | 266 | /** 267 | * Deserialize from a string. 268 | * @param line 269 | * @return 270 | */ 271 | public static ActionFrequency fromLine(final String line) { 272 | // TODO: Backwards-compatible lastUpdate ? 273 | String[] split = line.split(","); 274 | if (split.length < 3) throw new RuntimeException("Bad argument length."); // TODO 275 | final int n = Integer.parseInt(split[0]); 276 | final long durBucket = Long.parseLong(split[1]); 277 | final long time = Long.parseLong(split[2]); 278 | final float[] buckets = new float[split.length -3]; 279 | if (split.length - 3 != buckets.length) throw new RuntimeException("Bad argument length."); // TODO 280 | for (int i = 3; i < split.length; i ++) { 281 | buckets[i - 3] = Float.parseFloat(split[i]); 282 | } 283 | ActionFrequency freq = new ActionFrequency(n, durBucket); 284 | freq.setTime(time); 285 | for (int i = 0; i < buckets.length; i ++) { 286 | freq.setBucket(i, buckets[i]); 287 | } 288 | return freq; 289 | } 290 | } 291 | -------------------------------------------------------------------------------- /src/me/asofold/bpl/cncp/utils/PluginGetter.java: -------------------------------------------------------------------------------- 1 | package me.asofold.bpl.cncp.utils; 2 | 3 | import org.bukkit.Bukkit; 4 | import org.bukkit.event.Listener; 5 | import org.bukkit.event.server.PluginEnableEvent; 6 | import org.bukkit.plugin.Plugin; 7 | 8 | /** 9 | * Simple plugin fetching. 10 | * @author mc_dev 11 | * 12 | * @param 13 | */ 14 | public final class PluginGetter implements Listener{ 15 | private T plugin = null; 16 | private final String pluginName; 17 | public PluginGetter(final String pluginName){ 18 | this.pluginName = pluginName; 19 | fetchPlugin(); 20 | } 21 | 22 | /** 23 | * Fetch from Bukkit and set , might set to null, though. 24 | */ 25 | @SuppressWarnings("unchecked") 26 | public final void fetchPlugin() { 27 | final Plugin ref = Bukkit.getPluginManager().getPlugin(pluginName); 28 | plugin = (T) ref; 29 | } 30 | 31 | @SuppressWarnings("unchecked") 32 | final void onPluginEnable(final PluginEnableEvent event){ 33 | final Plugin ref = event.getPlugin(); 34 | if (plugin.getName().equals(pluginName)) plugin = (T) ref; 35 | } 36 | 37 | /** 38 | * For convenience with chaining: getX = new PluginGetter("X").registerEvents(this); 39 | * @param other 40 | * @return 41 | */ 42 | public final PluginGetter registerEvents(final Plugin other){ 43 | Bukkit.getPluginManager().registerEvents(this, plugin); 44 | return this; 45 | } 46 | 47 | public final T getPlugin(){ 48 | return plugin; 49 | } 50 | } 51 | -------------------------------------------------------------------------------- /src/me/asofold/bpl/cncp/utils/TickTask2.java: -------------------------------------------------------------------------------- 1 | package me.asofold.bpl.cncp.utils; 2 | 3 | import java.util.HashSet; 4 | import java.util.LinkedHashMap; 5 | import java.util.Map; 6 | import java.util.Map.Entry; 7 | import java.util.Set; 8 | 9 | import org.bukkit.entity.Player; 10 | 11 | import fr.neatmonster.nocheatplus.checks.CheckType; 12 | import fr.neatmonster.nocheatplus.hooks.NCPExemptionManager; 13 | 14 | public class TickTask2 implements Runnable { 15 | 16 | 17 | protected static Map> exemptions = new LinkedHashMap>(40); 18 | 19 | /** 20 | * Quick fix, meant for sync access (!). 21 | * @param player 22 | * @param checkTypes 23 | */ 24 | public static void addUnexemptions(final Player player, final CheckType[] checkTypes){ 25 | for (int i = 0; i < checkTypes.length; i ++){ 26 | final CheckType type = checkTypes[i]; 27 | Set set = exemptions.get(type); 28 | if (set == null){ 29 | set = new HashSet(); 30 | exemptions.put(type, set); 31 | } 32 | set.add(player); 33 | } 34 | } 35 | 36 | @Override 37 | public void run() { 38 | for (final Entry> entry : exemptions.entrySet()){ 39 | final Set set = entry.getValue(); 40 | final CheckType type = entry.getKey(); 41 | for (final Player player : set){ 42 | NCPExemptionManager.unexempt(player, type); 43 | } 44 | } 45 | exemptions.clear(); 46 | } 47 | 48 | } 49 | -------------------------------------------------------------------------------- /src/me/asofold/bpl/cncp/utils/Utils.java: -------------------------------------------------------------------------------- 1 | package me.asofold.bpl.cncp.utils; 2 | 3 | import java.io.PrintWriter; 4 | import java.io.StringWriter; 5 | import java.io.Writer; 6 | 7 | public class Utils { 8 | 9 | public static final String toString(final Throwable t) { 10 | final Writer buf = new StringWriter(500); 11 | final PrintWriter writer = new PrintWriter(buf); 12 | t.printStackTrace(writer); 13 | return buf.toString(); 14 | } 15 | 16 | } 17 | --------------------------------------------------------------------------------