├── .github └── workflows │ └── build.yml ├── .gitignore ├── LICENSE ├── README.md ├── build.gradle ├── gradle.properties ├── gradle └── wrapper │ ├── gradle-wrapper.jar │ └── gradle-wrapper.properties ├── gradlew ├── gradlew.bat ├── settings.gradle └── src └── main ├── java └── com │ └── jnngl │ └── framedimage │ ├── FrameDisplay.java │ ├── FramedImage.java │ ├── command │ ├── FiCommand.java │ ├── SubCommand.java │ ├── SubCommandExecutor.java │ └── fi │ │ ├── CreateSubcommand.java │ │ ├── ReloadSubcommand.java │ │ └── RemoveSubcommand.java │ ├── config │ ├── Config.java │ ├── Frames.java │ └── Messages.java │ ├── injection │ ├── ChannelInjectionHandler.java │ ├── ChannelInjector.java │ ├── InjectionException.java │ └── Injector.java │ ├── listener │ ├── DisconnectHandler.java │ ├── HandshakeListener.java │ ├── LoginListener.java │ ├── MoveListener.java │ └── PlayerListener.java │ ├── protocol │ ├── IdMapping.java │ ├── MinecraftVersion.java │ ├── Packet.java │ ├── PacketEncoder.java │ ├── ProtocolUtils.java │ ├── data │ │ ├── EntityMetadata.java │ │ ├── Facing.java │ │ ├── FilledMap.java │ │ ├── ItemFrame.java │ │ └── nbt │ │ │ ├── Nbt.java │ │ │ ├── NbtTag.java │ │ │ ├── TagCompound.java │ │ │ └── TagInt.java │ └── packets │ │ ├── DestroyEntity.java │ │ ├── MapData.java │ │ ├── SetMetadata.java │ │ └── SpawnEntity.java │ ├── scheduler │ ├── BukkitTaskScheduler.java │ ├── CancellableTask.java │ ├── FoliaTaskScheduler.java │ └── TaskScheduler.java │ └── util │ ├── BlockUtil.java │ ├── GifReader.java │ ├── ImageUtil.java │ └── SectionUtil.java └── resources └── plugin.yml /.github/workflows/build.yml: -------------------------------------------------------------------------------- 1 | name: Java CI with Gradle 2 | 3 | on: [ push, pull_request ] 4 | 5 | jobs: 6 | build: 7 | runs-on: ubuntu-latest 8 | steps: 9 | - name: Checkout 10 | uses: actions/checkout@v3.0.1 11 | - name: Set up JDK 17 12 | uses: actions/setup-java@v3.1.1 13 | with: 14 | distribution: temurin 15 | java-version: 17 16 | - name: Build 17 | run: ./gradlew build 18 | - name: Upload artifact 19 | uses: actions/upload-artifact@v3.0.0 20 | with: 21 | name: framedImage 22 | path: build/libs/framedimage*.jar -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | # User-specific stuff 2 | .idea/ 3 | 4 | *.iml 5 | *.ipr 6 | *.iws 7 | 8 | # IntelliJ 9 | out/ 10 | # mpeltonen/sbt-idea plugin 11 | .idea_modules/ 12 | 13 | # JIRA plugin 14 | atlassian-ide-plugin.xml 15 | 16 | # Compiled class file 17 | *.class 18 | 19 | # Log file 20 | *.log 21 | 22 | # BlueJ files 23 | *.ctxt 24 | 25 | # Package Files # 26 | *.jar 27 | *.war 28 | *.nar 29 | *.ear 30 | *.zip 31 | *.tar.gz 32 | *.rar 33 | 34 | # virtual machine crash logs, see http://www.java.com/en/download/help/error_hotspot.xml 35 | hs_err_pid* 36 | 37 | *~ 38 | 39 | # temporary files which can be created if a process still has a handle open of a deleted file 40 | .fuse_hidden* 41 | 42 | # KDE directory preferences 43 | .directory 44 | 45 | # Linux trash folder which might appear on any partition or disk 46 | .Trash-* 47 | 48 | # .nfs files are created when an open file is removed but is still being accessed 49 | .nfs* 50 | 51 | # General 52 | .DS_Store 53 | .AppleDouble 54 | .LSOverride 55 | 56 | # Icon must end with two \r 57 | Icon 58 | 59 | # Thumbnails 60 | ._* 61 | 62 | # Files that might appear in the root of a volume 63 | .DocumentRevisions-V100 64 | .fseventsd 65 | .Spotlight-V100 66 | .TemporaryItems 67 | .Trashes 68 | .VolumeIcon.icns 69 | .com.apple.timemachine.donotpresent 70 | 71 | # Directories potentially created on remote AFP share 72 | .AppleDB 73 | .AppleDesktop 74 | Network Trash Folder 75 | Temporary Items 76 | .apdisk 77 | 78 | # Windows thumbnail cache files 79 | Thumbs.db 80 | Thumbs.db:encryptable 81 | ehthumbs.db 82 | ehthumbs_vista.db 83 | 84 | # Dump file 85 | *.stackdump 86 | 87 | # Folder config file 88 | [Dd]esktop.ini 89 | 90 | # Recycle Bin used on file shares 91 | $RECYCLE.BIN/ 92 | 93 | # Windows Installer files 94 | *.cab 95 | *.msi 96 | *.msix 97 | *.msm 98 | *.msp 99 | 100 | # Windows shortcuts 101 | *.lnk 102 | 103 | .gradle 104 | build/ 105 | 106 | # Ignore Gradle GUI config 107 | gradle-app.setting 108 | 109 | # Cache of project 110 | .gradletasknamecache 111 | 112 | **/build/ 113 | 114 | # Common working directory 115 | run/ 116 | 117 | # Avoid ignoring Gradle wrapper jar file (.jar files are usually ignored) 118 | !gradle-wrapper.jar 119 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | GNU GENERAL PUBLIC LICENSE 2 | Version 3, 29 June 2007 3 | 4 | Copyright (C) 2007 Free Software Foundation, Inc. 5 | Everyone is permitted to copy and distribute verbatim copies 6 | of this license document, but changing it is not allowed. 7 | 8 | Preamble 9 | 10 | The GNU General Public License is a free, copyleft license for 11 | software and other kinds of works. 12 | 13 | The licenses for most software and other practical works are designed 14 | to take away your freedom to share and change the works. By contrast, 15 | the GNU General Public License is intended to guarantee your freedom to 16 | share and change all versions of a program--to make sure it remains free 17 | software for all its users. We, the Free Software Foundation, use the 18 | GNU General Public License for most of our software; it applies also to 19 | any other work released this way by its authors. You can apply it to 20 | your programs, too. 21 | 22 | When we speak of free software, we are referring to freedom, not 23 | price. Our General Public Licenses are designed to make sure that you 24 | have the freedom to distribute copies of free software (and charge for 25 | them if you wish), that you receive source code or can get it if you 26 | want it, that you can change the software or use pieces of it in new 27 | free programs, and that you know you can do these things. 28 | 29 | To protect your rights, we need to prevent others from denying you 30 | these rights or asking you to surrender the rights. Therefore, you have 31 | certain responsibilities if you distribute copies of the software, or if 32 | you modify it: responsibilities to respect the freedom of others. 33 | 34 | For example, if you distribute copies of such a program, whether 35 | gratis or for a fee, you must pass on to the recipients the same 36 | freedoms that you received. You must make sure that they, too, receive 37 | or can get the source code. And you must show them these terms so they 38 | know their rights. 39 | 40 | Developers that use the GNU GPL protect your rights with two steps: 41 | (1) assert copyright on the software, and (2) offer you this License 42 | giving you legal permission to copy, distribute and/or modify it. 43 | 44 | For the developers' and authors' protection, the GPL clearly explains 45 | that there is no warranty for this free software. For both users' and 46 | authors' sake, the GPL requires that modified versions be marked as 47 | changed, so that their problems will not be attributed erroneously to 48 | authors of previous versions. 49 | 50 | Some devices are designed to deny users access to install or run 51 | modified versions of the software inside them, although the manufacturer 52 | can do so. This is fundamentally incompatible with the aim of 53 | protecting users' freedom to change the software. The systematic 54 | pattern of such abuse occurs in the area of products for individuals to 55 | use, which is precisely where it is most unacceptable. Therefore, we 56 | have designed this version of the GPL to prohibit the practice for those 57 | products. If such problems arise substantially in other domains, we 58 | stand ready to extend this provision to those domains in future versions 59 | of the GPL, as needed to protect the freedom of users. 60 | 61 | Finally, every program is threatened constantly by software patents. 62 | States should not allow patents to restrict development and use of 63 | software on general-purpose computers, but in those that do, we wish to 64 | avoid the special danger that patents applied to a free program could 65 | make it effectively proprietary. To prevent this, the GPL assures that 66 | patents cannot be used to render the program non-free. 67 | 68 | The precise terms and conditions for copying, distribution and 69 | modification follow. 70 | 71 | TERMS AND CONDITIONS 72 | 73 | 0. Definitions. 74 | 75 | "This License" refers to version 3 of the GNU General Public License. 76 | 77 | "Copyright" also means copyright-like laws that apply to other kinds of 78 | works, such as semiconductor masks. 79 | 80 | "The Program" refers to any copyrightable work licensed under this 81 | License. Each licensee is addressed as "you". "Licensees" and 82 | "recipients" may be individuals or organizations. 83 | 84 | To "modify" a work means to copy from or adapt all or part of the work 85 | in a fashion requiring copyright permission, other than the making of an 86 | exact copy. The resulting work is called a "modified version" of the 87 | earlier work or a work "based on" the earlier work. 88 | 89 | A "covered work" means either the unmodified Program or a work based 90 | on the Program. 91 | 92 | To "propagate" a work means to do anything with it that, without 93 | permission, would make you directly or secondarily liable for 94 | infringement under applicable copyright law, except executing it on a 95 | computer or modifying a private copy. Propagation includes copying, 96 | distribution (with or without modification), making available to the 97 | public, and in some countries other activities as well. 98 | 99 | To "convey" a work means any kind of propagation that enables other 100 | parties to make or receive copies. Mere interaction with a user through 101 | a computer network, with no transfer of a copy, is not conveying. 102 | 103 | An interactive user interface displays "Appropriate Legal Notices" 104 | to the extent that it includes a convenient and prominently visible 105 | feature that (1) displays an appropriate copyright notice, and (2) 106 | tells the user that there is no warranty for the work (except to the 107 | extent that warranties are provided), that licensees may convey the 108 | work under this License, and how to view a copy of this License. If 109 | the interface presents a list of user commands or options, such as a 110 | menu, a prominent item in the list meets this criterion. 111 | 112 | 1. Source Code. 113 | 114 | The "source code" for a work means the preferred form of the work 115 | for making modifications to it. "Object code" means any non-source 116 | form of a work. 117 | 118 | A "Standard Interface" means an interface that either is an official 119 | standard defined by a recognized standards body, or, in the case of 120 | interfaces specified for a particular programming language, one that 121 | is widely used among developers working in that language. 122 | 123 | The "System Libraries" of an executable work include anything, other 124 | than the work as a whole, that (a) is included in the normal form of 125 | packaging a Major Component, but which is not part of that Major 126 | Component, and (b) serves only to enable use of the work with that 127 | Major Component, or to implement a Standard Interface for which an 128 | implementation is available to the public in source code form. A 129 | "Major Component", in this context, means a major essential component 130 | (kernel, window system, and so on) of the specific operating system 131 | (if any) on which the executable work runs, or a compiler used to 132 | produce the work, or an object code interpreter used to run it. 133 | 134 | The "Corresponding Source" for a work in object code form means all 135 | the source code needed to generate, install, and (for an executable 136 | work) run the object code and to modify the work, including scripts to 137 | control those activities. However, it does not include the work's 138 | System Libraries, or general-purpose tools or generally available free 139 | programs which are used unmodified in performing those activities but 140 | which are not part of the work. For example, Corresponding Source 141 | includes interface definition files associated with source files for 142 | the work, and the source code for shared libraries and dynamically 143 | linked subprograms that the work is specifically designed to require, 144 | such as by intimate data communication or control flow between those 145 | subprograms and other parts of the work. 146 | 147 | The Corresponding Source need not include anything that users 148 | can regenerate automatically from other parts of the Corresponding 149 | Source. 150 | 151 | The Corresponding Source for a work in source code form is that 152 | same work. 153 | 154 | 2. Basic Permissions. 155 | 156 | All rights granted under this License are granted for the term of 157 | copyright on the Program, and are irrevocable provided the stated 158 | conditions are met. This License explicitly affirms your unlimited 159 | permission to run the unmodified Program. The output from running a 160 | covered work is covered by this License only if the output, given its 161 | content, constitutes a covered work. This License acknowledges your 162 | rights of fair use or other equivalent, as provided by copyright law. 163 | 164 | You may make, run and propagate covered works that you do not 165 | convey, without conditions so long as your license otherwise remains 166 | in force. You may convey covered works to others for the sole purpose 167 | of having them make modifications exclusively for you, or provide you 168 | with facilities for running those works, provided that you comply with 169 | the terms of this License in conveying all material for which you do 170 | not control copyright. Those thus making or running the covered works 171 | for you must do so exclusively on your behalf, under your direction 172 | and control, on terms that prohibit them from making any copies of 173 | your copyrighted material outside their relationship with you. 174 | 175 | Conveying under any other circumstances is permitted solely under 176 | the conditions stated below. Sublicensing is not allowed; section 10 177 | makes it unnecessary. 178 | 179 | 3. Protecting Users' Legal Rights From Anti-Circumvention Law. 180 | 181 | No covered work shall be deemed part of an effective technological 182 | measure under any applicable law fulfilling obligations under article 183 | 11 of the WIPO copyright treaty adopted on 20 December 1996, or 184 | similar laws prohibiting or restricting circumvention of such 185 | measures. 186 | 187 | When you convey a covered work, you waive any legal power to forbid 188 | circumvention of technological measures to the extent such circumvention 189 | is effected by exercising rights under this License with respect to 190 | the covered work, and you disclaim any intention to limit operation or 191 | modification of the work as a means of enforcing, against the work's 192 | users, your or third parties' legal rights to forbid circumvention of 193 | technological measures. 194 | 195 | 4. Conveying Verbatim Copies. 196 | 197 | You may convey verbatim copies of the Program's source code as you 198 | receive it, in any medium, provided that you conspicuously and 199 | appropriately publish on each copy an appropriate copyright notice; 200 | keep intact all notices stating that this License and any 201 | non-permissive terms added in accord with section 7 apply to the code; 202 | keep intact all notices of the absence of any warranty; and give all 203 | recipients a copy of this License along with the Program. 204 | 205 | You may charge any price or no price for each copy that you convey, 206 | and you may offer support or warranty protection for a fee. 207 | 208 | 5. Conveying Modified Source Versions. 209 | 210 | You may convey a work based on the Program, or the modifications to 211 | produce it from the Program, in the form of source code under the 212 | terms of section 4, provided that you also meet all of these conditions: 213 | 214 | a) The work must carry prominent notices stating that you modified 215 | it, and giving a relevant date. 216 | 217 | b) The work must carry prominent notices stating that it is 218 | released under this License and any conditions added under section 219 | 7. This requirement modifies the requirement in section 4 to 220 | "keep intact all notices". 221 | 222 | c) You must license the entire work, as a whole, under this 223 | License to anyone who comes into possession of a copy. This 224 | License will therefore apply, along with any applicable section 7 225 | additional terms, to the whole of the work, and all its parts, 226 | regardless of how they are packaged. This License gives no 227 | permission to license the work in any other way, but it does not 228 | invalidate such permission if you have separately received it. 229 | 230 | d) If the work has interactive user interfaces, each must display 231 | Appropriate Legal Notices; however, if the Program has interactive 232 | interfaces that do not display Appropriate Legal Notices, your 233 | work need not make them do so. 234 | 235 | A compilation of a covered work with other separate and independent 236 | works, which are not by their nature extensions of the covered work, 237 | and which are not combined with it such as to form a larger program, 238 | in or on a volume of a storage or distribution medium, is called an 239 | "aggregate" if the compilation and its resulting copyright are not 240 | used to limit the access or legal rights of the compilation's users 241 | beyond what the individual works permit. Inclusion of a covered work 242 | in an aggregate does not cause this License to apply to the other 243 | parts of the aggregate. 244 | 245 | 6. Conveying Non-Source Forms. 246 | 247 | You may convey a covered work in object code form under the terms 248 | of sections 4 and 5, provided that you also convey the 249 | machine-readable Corresponding Source under the terms of this License, 250 | in one of these ways: 251 | 252 | a) Convey the object code in, or embodied in, a physical product 253 | (including a physical distribution medium), accompanied by the 254 | Corresponding Source fixed on a durable physical medium 255 | customarily used for software interchange. 256 | 257 | b) Convey the object code in, or embodied in, a physical product 258 | (including a physical distribution medium), accompanied by a 259 | written offer, valid for at least three years and valid for as 260 | long as you offer spare parts or customer support for that product 261 | model, to give anyone who possesses the object code either (1) a 262 | copy of the Corresponding Source for all the software in the 263 | product that is covered by this License, on a durable physical 264 | medium customarily used for software interchange, for a price no 265 | more than your reasonable cost of physically performing this 266 | conveying of source, or (2) access to copy the 267 | Corresponding Source from a network server at no charge. 268 | 269 | c) Convey individual copies of the object code with a copy of the 270 | written offer to provide the Corresponding Source. This 271 | alternative is allowed only occasionally and noncommercially, and 272 | only if you received the object code with such an offer, in accord 273 | with subsection 6b. 274 | 275 | d) Convey the object code by offering access from a designated 276 | place (gratis or for a charge), and offer equivalent access to the 277 | Corresponding Source in the same way through the same place at no 278 | further charge. You need not require recipients to copy the 279 | Corresponding Source along with the object code. If the place to 280 | copy the object code is a network server, the Corresponding Source 281 | may be on a different server (operated by you or a third party) 282 | that supports equivalent copying facilities, provided you maintain 283 | clear directions next to the object code saying where to find the 284 | Corresponding Source. Regardless of what server hosts the 285 | Corresponding Source, you remain obligated to ensure that it is 286 | available for as long as needed to satisfy these requirements. 287 | 288 | e) Convey the object code using peer-to-peer transmission, provided 289 | you inform other peers where the object code and Corresponding 290 | Source of the work are being offered to the general public at no 291 | charge under subsection 6d. 292 | 293 | A separable portion of the object code, whose source code is excluded 294 | from the Corresponding Source as a System Library, need not be 295 | included in conveying the object code work. 296 | 297 | A "User Product" is either (1) a "consumer product", which means any 298 | tangible personal property which is normally used for personal, family, 299 | or household purposes, or (2) anything designed or sold for incorporation 300 | into a dwelling. In determining whether a product is a consumer product, 301 | doubtful cases shall be resolved in favor of coverage. For a particular 302 | product received by a particular user, "normally used" refers to a 303 | typical or common use of that class of product, regardless of the status 304 | of the particular user or of the way in which the particular user 305 | actually uses, or expects or is expected to use, the product. A product 306 | is a consumer product regardless of whether the product has substantial 307 | commercial, industrial or non-consumer uses, unless such uses represent 308 | the only significant mode of use of the product. 309 | 310 | "Installation Information" for a User Product means any methods, 311 | procedures, authorization keys, or other information required to install 312 | and execute modified versions of a covered work in that User Product from 313 | a modified version of its Corresponding Source. The information must 314 | suffice to ensure that the continued functioning of the modified object 315 | code is in no case prevented or interfered with solely because 316 | modification has been made. 317 | 318 | If you convey an object code work under this section in, or with, or 319 | specifically for use in, a User Product, and the conveying occurs as 320 | part of a transaction in which the right of possession and use of the 321 | User Product is transferred to the recipient in perpetuity or for a 322 | fixed term (regardless of how the transaction is characterized), the 323 | Corresponding Source conveyed under this section must be accompanied 324 | by the Installation Information. But this requirement does not apply 325 | if neither you nor any third party retains the ability to install 326 | modified object code on the User Product (for example, the work has 327 | been installed in ROM). 328 | 329 | The requirement to provide Installation Information does not include a 330 | requirement to continue to provide support service, warranty, or updates 331 | for a work that has been modified or installed by the recipient, or for 332 | the User Product in which it has been modified or installed. Access to a 333 | network may be denied when the modification itself materially and 334 | adversely affects the operation of the network or violates the rules and 335 | protocols for communication across the network. 336 | 337 | Corresponding Source conveyed, and Installation Information provided, 338 | in accord with this section must be in a format that is publicly 339 | documented (and with an implementation available to the public in 340 | source code form), and must require no special password or key for 341 | unpacking, reading or copying. 342 | 343 | 7. Additional Terms. 344 | 345 | "Additional permissions" are terms that supplement the terms of this 346 | License by making exceptions from one or more of its conditions. 347 | Additional permissions that are applicable to the entire Program shall 348 | be treated as though they were included in this License, to the extent 349 | that they are valid under applicable law. If additional permissions 350 | apply only to part of the Program, that part may be used separately 351 | under those permissions, but the entire Program remains governed by 352 | this License without regard to the additional permissions. 353 | 354 | When you convey a copy of a covered work, you may at your option 355 | remove any additional permissions from that copy, or from any part of 356 | it. (Additional permissions may be written to require their own 357 | removal in certain cases when you modify the work.) You may place 358 | additional permissions on material, added by you to a covered work, 359 | for which you have or can give appropriate copyright permission. 360 | 361 | Notwithstanding any other provision of this License, for material you 362 | add to a covered work, you may (if authorized by the copyright holders of 363 | that material) supplement the terms of this License with terms: 364 | 365 | a) Disclaiming warranty or limiting liability differently from the 366 | terms of sections 15 and 16 of this License; or 367 | 368 | b) Requiring preservation of specified reasonable legal notices or 369 | author attributions in that material or in the Appropriate Legal 370 | Notices displayed by works containing it; or 371 | 372 | c) Prohibiting misrepresentation of the origin of that material, or 373 | requiring that modified versions of such material be marked in 374 | reasonable ways as different from the original version; or 375 | 376 | d) Limiting the use for publicity purposes of names of licensors or 377 | authors of the material; or 378 | 379 | e) Declining to grant rights under trademark law for use of some 380 | trade names, trademarks, or service marks; or 381 | 382 | f) Requiring indemnification of licensors and authors of that 383 | material by anyone who conveys the material (or modified versions of 384 | it) with contractual assumptions of liability to the recipient, for 385 | any liability that these contractual assumptions directly impose on 386 | those licensors and authors. 387 | 388 | All other non-permissive additional terms are considered "further 389 | restrictions" within the meaning of section 10. If the Program as you 390 | received it, or any part of it, contains a notice stating that it is 391 | governed by this License along with a term that is a further 392 | restriction, you may remove that term. If a license document contains 393 | a further restriction but permits relicensing or conveying under this 394 | License, you may add to a covered work material governed by the terms 395 | of that license document, provided that the further restriction does 396 | not survive such relicensing or conveying. 397 | 398 | If you add terms to a covered work in accord with this section, you 399 | must place, in the relevant source files, a statement of the 400 | additional terms that apply to those files, or a notice indicating 401 | where to find the applicable terms. 402 | 403 | Additional terms, permissive or non-permissive, may be stated in the 404 | form of a separately written license, or stated as exceptions; 405 | the above requirements apply either way. 406 | 407 | 8. Termination. 408 | 409 | You may not propagate or modify a covered work except as expressly 410 | provided under this License. Any attempt otherwise to propagate or 411 | modify it is void, and will automatically terminate your rights under 412 | this License (including any patent licenses granted under the third 413 | paragraph of section 11). 414 | 415 | However, if you cease all violation of this License, then your 416 | license from a particular copyright holder is reinstated (a) 417 | provisionally, unless and until the copyright holder explicitly and 418 | finally terminates your license, and (b) permanently, if the copyright 419 | holder fails to notify you of the violation by some reasonable means 420 | prior to 60 days after the cessation. 421 | 422 | Moreover, your license from a particular copyright holder is 423 | reinstated permanently if the copyright holder notifies you of the 424 | violation by some reasonable means, this is the first time you have 425 | received notice of violation of this License (for any work) from that 426 | copyright holder, and you cure the violation prior to 30 days after 427 | your receipt of the notice. 428 | 429 | Termination of your rights under this section does not terminate the 430 | licenses of parties who have received copies or rights from you under 431 | this License. If your rights have been terminated and not permanently 432 | reinstated, you do not qualify to receive new licenses for the same 433 | material under section 10. 434 | 435 | 9. Acceptance Not Required for Having Copies. 436 | 437 | You are not required to accept this License in order to receive or 438 | run a copy of the Program. Ancillary propagation of a covered work 439 | occurring solely as a consequence of using peer-to-peer transmission 440 | to receive a copy likewise does not require acceptance. However, 441 | nothing other than this License grants you permission to propagate or 442 | modify any covered work. These actions infringe copyright if you do 443 | not accept this License. Therefore, by modifying or propagating a 444 | covered work, you indicate your acceptance of this License to do so. 445 | 446 | 10. Automatic Licensing of Downstream Recipients. 447 | 448 | Each time you convey a covered work, the recipient automatically 449 | receives a license from the original licensors, to run, modify and 450 | propagate that work, subject to this License. You are not responsible 451 | for enforcing compliance by third parties with this License. 452 | 453 | An "entity transaction" is a transaction transferring control of an 454 | organization, or substantially all assets of one, or subdividing an 455 | organization, or merging organizations. If propagation of a covered 456 | work results from an entity transaction, each party to that 457 | transaction who receives a copy of the work also receives whatever 458 | licenses to the work the party's predecessor in interest had or could 459 | give under the previous paragraph, plus a right to possession of the 460 | Corresponding Source of the work from the predecessor in interest, if 461 | the predecessor has it or can get it with reasonable efforts. 462 | 463 | You may not impose any further restrictions on the exercise of the 464 | rights granted or affirmed under this License. For example, you may 465 | not impose a license fee, royalty, or other charge for exercise of 466 | rights granted under this License, and you may not initiate litigation 467 | (including a cross-claim or counterclaim in a lawsuit) alleging that 468 | any patent claim is infringed by making, using, selling, offering for 469 | sale, or importing the Program or any portion of it. 470 | 471 | 11. Patents. 472 | 473 | A "contributor" is a copyright holder who authorizes use under this 474 | License of the Program or a work on which the Program is based. The 475 | work thus licensed is called the contributor's "contributor version". 476 | 477 | A contributor's "essential patent claims" are all patent claims 478 | owned or controlled by the contributor, whether already acquired or 479 | hereafter acquired, that would be infringed by some manner, permitted 480 | by this License, of making, using, or selling its contributor version, 481 | but do not include claims that would be infringed only as a 482 | consequence of further modification of the contributor version. For 483 | purposes of this definition, "control" includes the right to grant 484 | patent sublicenses in a manner consistent with the requirements of 485 | this License. 486 | 487 | Each contributor grants you a non-exclusive, worldwide, royalty-free 488 | patent license under the contributor's essential patent claims, to 489 | make, use, sell, offer for sale, import and otherwise run, modify and 490 | propagate the contents of its contributor version. 491 | 492 | In the following three paragraphs, a "patent license" is any express 493 | agreement or commitment, however denominated, not to enforce a patent 494 | (such as an express permission to practice a patent or covenant not to 495 | sue for patent infringement). To "grant" such a patent license to a 496 | party means to make such an agreement or commitment not to enforce a 497 | patent against the party. 498 | 499 | If you convey a covered work, knowingly relying on a patent license, 500 | and the Corresponding Source of the work is not available for anyone 501 | to copy, free of charge and under the terms of this License, through a 502 | publicly available network server or other readily accessible means, 503 | then you must either (1) cause the Corresponding Source to be so 504 | available, or (2) arrange to deprive yourself of the benefit of the 505 | patent license for this particular work, or (3) arrange, in a manner 506 | consistent with the requirements of this License, to extend the patent 507 | license to downstream recipients. "Knowingly relying" means you have 508 | actual knowledge that, but for the patent license, your conveying the 509 | covered work in a country, or your recipient's use of the covered work 510 | in a country, would infringe one or more identifiable patents in that 511 | country that you have reason to believe are valid. 512 | 513 | If, pursuant to or in connection with a single transaction or 514 | arrangement, you convey, or propagate by procuring conveyance of, a 515 | covered work, and grant a patent license to some of the parties 516 | receiving the covered work authorizing them to use, propagate, modify 517 | or convey a specific copy of the covered work, then the patent license 518 | you grant is automatically extended to all recipients of the covered 519 | work and works based on it. 520 | 521 | A patent license is "discriminatory" if it does not include within 522 | the scope of its coverage, prohibits the exercise of, or is 523 | conditioned on the non-exercise of one or more of the rights that are 524 | specifically granted under this License. You may not convey a covered 525 | work if you are a party to an arrangement with a third party that is 526 | in the business of distributing software, under which you make payment 527 | to the third party based on the extent of your activity of conveying 528 | the work, and under which the third party grants, to any of the 529 | parties who would receive the covered work from you, a discriminatory 530 | patent license (a) in connection with copies of the covered work 531 | conveyed by you (or copies made from those copies), or (b) primarily 532 | for and in connection with specific products or compilations that 533 | contain the covered work, unless you entered into that arrangement, 534 | or that patent license was granted, prior to 28 March 2007. 535 | 536 | Nothing in this License shall be construed as excluding or limiting 537 | any implied license or other defenses to infringement that may 538 | otherwise be available to you under applicable patent law. 539 | 540 | 12. No Surrender of Others' Freedom. 541 | 542 | If conditions are imposed on you (whether by court order, agreement or 543 | otherwise) that contradict the conditions of this License, they do not 544 | excuse you from the conditions of this License. If you cannot convey a 545 | covered work so as to satisfy simultaneously your obligations under this 546 | License and any other pertinent obligations, then as a consequence you may 547 | not convey it at all. For example, if you agree to terms that obligate you 548 | to collect a royalty for further conveying from those to whom you convey 549 | the Program, the only way you could satisfy both those terms and this 550 | License would be to refrain entirely from conveying the Program. 551 | 552 | 13. Use with the GNU Affero General Public License. 553 | 554 | Notwithstanding any other provision of this License, you have 555 | permission to link or combine any covered work with a work licensed 556 | under version 3 of the GNU Affero General Public License into a single 557 | combined work, and to convey the resulting work. The terms of this 558 | License will continue to apply to the part which is the covered work, 559 | but the special requirements of the GNU Affero General Public License, 560 | section 13, concerning interaction through a network will apply to the 561 | combination as such. 562 | 563 | 14. Revised Versions of this License. 564 | 565 | The Free Software Foundation may publish revised and/or new versions of 566 | the GNU General Public License from time to time. Such new versions will 567 | be similar in spirit to the present version, but may differ in detail to 568 | address new problems or concerns. 569 | 570 | Each version is given a distinguishing version number. If the 571 | Program specifies that a certain numbered version of the GNU General 572 | Public License "or any later version" applies to it, you have the 573 | option of following the terms and conditions either of that numbered 574 | version or of any later version published by the Free Software 575 | Foundation. If the Program does not specify a version number of the 576 | GNU General Public License, you may choose any version ever published 577 | by the Free Software Foundation. 578 | 579 | If the Program specifies that a proxy can decide which future 580 | versions of the GNU General Public License can be used, that proxy's 581 | public statement of acceptance of a version permanently authorizes you 582 | to choose that version for the Program. 583 | 584 | Later license versions may give you additional or different 585 | permissions. However, no additional obligations are imposed on any 586 | author or copyright holder as a result of your choosing to follow a 587 | later version. 588 | 589 | 15. Disclaimer of Warranty. 590 | 591 | THERE IS NO WARRANTY FOR THE PROGRAM, TO THE EXTENT PERMITTED BY 592 | APPLICABLE LAW. EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT 593 | HOLDERS AND/OR OTHER PARTIES PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY 594 | OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, 595 | THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 596 | PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE PROGRAM 597 | IS WITH YOU. SHOULD THE PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF 598 | ALL NECESSARY SERVICING, REPAIR OR CORRECTION. 599 | 600 | 16. Limitation of Liability. 601 | 602 | IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING 603 | WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MODIFIES AND/OR CONVEYS 604 | THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, INCLUDING ANY 605 | GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE 606 | USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED TO LOSS OF 607 | DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD 608 | PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER PROGRAMS), 609 | EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF 610 | SUCH DAMAGES. 611 | 612 | 17. Interpretation of Sections 15 and 16. 613 | 614 | If the disclaimer of warranty and limitation of liability provided 615 | above cannot be given local legal effect according to their terms, 616 | reviewing courts shall apply local law that most closely approximates 617 | an absolute waiver of all civil liability in connection with the 618 | Program, unless a warranty or assumption of liability accompanies a 619 | copy of the Program in return for a fee. 620 | 621 | END OF TERMS AND CONDITIONS 622 | 623 | How to Apply These Terms to Your New Programs 624 | 625 | If you develop a new program, and you want it to be of the greatest 626 | possible use to the public, the best way to achieve this is to make it 627 | free software which everyone can redistribute and change under these terms. 628 | 629 | To do so, attach the following notices to the program. It is safest 630 | to attach them to the start of each source file to most effectively 631 | state the exclusion of warranty; and each file should have at least 632 | the "copyright" line and a pointer to where the full notice is found. 633 | 634 | 635 | Copyright (C) 636 | 637 | This program is free software: you can redistribute it and/or modify 638 | it under the terms of the GNU General Public License as published by 639 | the Free Software Foundation, either version 3 of the License, or 640 | (at your option) any later version. 641 | 642 | This program is distributed in the hope that it will be useful, 643 | but WITHOUT ANY WARRANTY; without even the implied warranty of 644 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 645 | GNU General Public License for more details. 646 | 647 | You should have received a copy of the GNU General Public License 648 | along with this program. If not, see . 649 | 650 | Also add information on how to contact you by electronic and paper mail. 651 | 652 | If the program does terminal interaction, make it output a short 653 | notice like this when it starts in an interactive mode: 654 | 655 | Copyright (C) 656 | This program comes with ABSOLUTELY NO WARRANTY; for details type `show w'. 657 | This is free software, and you are welcome to redistribute it 658 | under certain conditions; type `show c' for details. 659 | 660 | The hypothetical commands `show w' and `show c' should show the appropriate 661 | parts of the General Public License. Of course, your program's commands 662 | might be different; for a GUI interface, you would use an "about box". 663 | 664 | You should also get your employer (if you work as a programmer) or school, 665 | if any, to sign a "copyright disclaimer" for the program, if necessary. 666 | For more information on this, and how to apply and follow the GNU GPL, see 667 | . 668 | 669 | The GNU General Public License does not permit incorporating your program 670 | into proprietary programs. If your program is a subroutine library, you 671 | may consider it more useful to permit linking proprietary applications with 672 | the library. If this is what you want to do, use the GNU Lesser General 673 | Public License instead of this License. But first, please read 674 | . -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | ## FramedImage 2 | 3 | High performance Bukkit/Folia plugin for map-arts. 4 | 5 | Features: 6 |
    7 |
  • Performance. The plugin inserts thousands of frames in just a few seconds (during testing, the plugin inserted ~3000 frames in 2 seconds)
  • 8 |
  • Dithering. With dithering transitions look smoother and a small number of colors in the palette of maps becomes almost invisible.
  • 9 |
  • Adaptive palette. The player will always see images with the palette relevant to his version, regardless of the server version.
  • 10 |
  • Client-side. The frames are sent to the players directly and are never created on the server itself.
  • 11 |
  • GIF support.
  • 12 |
  • Glowing item frame support. Works on 1.17+ clients, regardless of the server version.
  • 13 |
14 | 15 | Commands: 16 |
    17 |
  • /fi create

    Inserts an image from the link on the block where the cursor points. (Frames go right and up)

  • 18 |
  • /fi remove

    Deletes the image that the cursor points to.

  • 19 |
  • /fi reload

    Reloads the config and all images

  • 20 |
21 | 22 | Permissions: 23 |
    24 |
  • framedimage.command

    Access to the plugin command

  • 25 |
  • framedimage.subcommand.create

    Ability to create images

  • 26 |
  • framedimage.subcommand.remove

    Ability to delete images

  • 27 |
  • framedimage.subcommand.reload

    Ability to reload the plugin

  • 28 |
29 | -------------------------------------------------------------------------------- /build.gradle: -------------------------------------------------------------------------------- 1 | plugins { 2 | id 'java' 3 | id 'com.github.johnrengelman.shadow' version '7.1.2' 4 | } 5 | 6 | group = 'com.jnngl' 7 | version = '1.8.0' 8 | 9 | repositories { 10 | mavenCentral() 11 | maven { 12 | name = 'papermc-repo' 13 | url = 'https://repo.papermc.io/repository/maven-public/' 14 | } 15 | maven { 16 | name = 'elytrium-repo' 17 | url = 'https://maven.elytrium.net/repo' 18 | } 19 | } 20 | 21 | dependencies { 22 | implementation 'net.elytrium:elytrium-java-commons:1.0.8' 23 | implementation 'com.jnngl:mapcolor:1.0.1' 24 | implementation 'org.bstats:bstats-bukkit:3.0.0' 25 | 26 | compileOnly 'dev.folia:folia-api:1.19.4-R0.1-SNAPSHOT' 27 | 28 | compileOnly 'io.netty:netty-all:4.1.85.Final' 29 | } 30 | 31 | def targetJavaVersion = 17 32 | java { 33 | def javaVersion = JavaVersion.toVersion(targetJavaVersion) 34 | sourceCompatibility = javaVersion 35 | targetCompatibility = javaVersion 36 | if (JavaVersion.current() < javaVersion) { 37 | toolchain.languageVersion = JavaLanguageVersion.of(targetJavaVersion) 38 | } 39 | } 40 | 41 | tasks.withType(JavaCompile).configureEach { 42 | if (targetJavaVersion >= 10 || JavaVersion.current().isJava10Compatible()) { 43 | options.release = targetJavaVersion 44 | } 45 | } 46 | 47 | processResources { 48 | def props = [version: version] 49 | inputs.properties props 50 | filteringCharset 'UTF-8' 51 | filesMatching('plugin.yml') { 52 | expand props 53 | } 54 | } 55 | 56 | shadowJar { 57 | getArchiveClassifier() set '' 58 | 59 | relocate 'org.bstats', 'com.jnngl.framedimage.thirdparty.org.bstats' 60 | } 61 | 62 | assemble.dependsOn shadowJar -------------------------------------------------------------------------------- /gradle.properties: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/JNNGL/framedImage/0ba271f1786c98a767106a551378d56a9cc173a4/gradle.properties -------------------------------------------------------------------------------- /gradle/wrapper/gradle-wrapper.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/JNNGL/framedImage/0ba271f1786c98a767106a551378d56a9cc173a4/gradle/wrapper/gradle-wrapper.jar -------------------------------------------------------------------------------- /gradle/wrapper/gradle-wrapper.properties: -------------------------------------------------------------------------------- 1 | distributionBase=GRADLE_USER_HOME 2 | distributionPath=wrapper/dists 3 | distributionUrl=https\://services.gradle.org/distributions/gradle-7.5.1-bin.zip 4 | zipStoreBase=GRADLE_USER_HOME 5 | zipStorePath=wrapper/dists 6 | -------------------------------------------------------------------------------- /gradlew: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | 3 | # 4 | # Copyright © 2015-2021 the original authors. 5 | # 6 | # Licensed under the Apache License, Version 2.0 (the "License"); 7 | # you may not use this file except in compliance with the License. 8 | # You may obtain a copy of the License at 9 | # 10 | # https://www.apache.org/licenses/LICENSE-2.0 11 | # 12 | # Unless required by applicable law or agreed to in writing, software 13 | # distributed under the License is distributed on an "AS IS" BASIS, 14 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 | # See the License for the specific language governing permissions and 16 | # limitations under the License. 17 | # 18 | 19 | ############################################################################## 20 | # 21 | # Gradle start up script for POSIX generated by Gradle. 22 | # 23 | # Important for running: 24 | # 25 | # (1) You need a POSIX-compliant shell to run this script. If your /bin/sh is 26 | # noncompliant, but you have some other compliant shell such as ksh or 27 | # bash, then to run this script, type that shell name before the whole 28 | # command line, like: 29 | # 30 | # ksh Gradle 31 | # 32 | # Busybox and similar reduced shells will NOT work, because this script 33 | # requires all of these POSIX shell features: 34 | # * functions; 35 | # * expansions «$var», «${var}», «${var:-default}», «${var+SET}», 36 | # «${var#prefix}», «${var%suffix}», and «$( cmd )»; 37 | # * compound commands having a testable exit status, especially «case»; 38 | # * various built-in commands including «command», «set», and «ulimit». 39 | # 40 | # Important for patching: 41 | # 42 | # (2) This script targets any POSIX shell, so it avoids extensions provided 43 | # by Bash, Ksh, etc; in particular arrays are avoided. 44 | # 45 | # The "traditional" practice of packing multiple parameters into a 46 | # space-separated string is a well documented source of bugs and security 47 | # problems, so this is (mostly) avoided, by progressively accumulating 48 | # options in "$@", and eventually passing that to Java. 49 | # 50 | # Where the inherited environment variables (DEFAULT_JVM_OPTS, JAVA_OPTS, 51 | # and GRADLE_OPTS) rely on word-splitting, this is performed explicitly; 52 | # see the in-line comments for details. 53 | # 54 | # There are tweaks for specific operating systems such as AIX, CygWin, 55 | # Darwin, MinGW, and NonStop. 56 | # 57 | # (3) This script is generated from the Groovy template 58 | # https://github.com/gradle/gradle/blob/master/subprojects/plugins/src/main/resources/org/gradle/api/internal/plugins/unixStartScript.txt 59 | # within the Gradle project. 60 | # 61 | # You can find Gradle at https://github.com/gradle/gradle/. 62 | # 63 | ############################################################################## 64 | 65 | # Attempt to set APP_HOME 66 | 67 | # Resolve links: $0 may be a link 68 | app_path=$0 69 | 70 | # Need this for daisy-chained symlinks. 71 | while 72 | APP_HOME=${app_path%"${app_path##*/}"} # leaves a trailing /; empty if no leading path 73 | [ -h "$app_path" ] 74 | do 75 | ls=$( ls -ld "$app_path" ) 76 | link=${ls#*' -> '} 77 | case $link in #( 78 | /*) app_path=$link ;; #( 79 | *) app_path=$APP_HOME$link ;; 80 | esac 81 | done 82 | 83 | APP_HOME=$( cd "${APP_HOME:-./}" && pwd -P ) || exit 84 | 85 | APP_NAME="Gradle" 86 | APP_BASE_NAME=${0##*/} 87 | 88 | # Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. 89 | DEFAULT_JVM_OPTS='"-Xmx64m" "-Xms64m"' 90 | 91 | # Use the maximum available, or set MAX_FD != -1 to use that value. 92 | MAX_FD=maximum 93 | 94 | warn () { 95 | echo "$*" 96 | } >&2 97 | 98 | die () { 99 | echo 100 | echo "$*" 101 | echo 102 | exit 1 103 | } >&2 104 | 105 | # OS specific support (must be 'true' or 'false'). 106 | cygwin=false 107 | msys=false 108 | darwin=false 109 | nonstop=false 110 | case "$( uname )" in #( 111 | CYGWIN* ) cygwin=true ;; #( 112 | Darwin* ) darwin=true ;; #( 113 | MSYS* | MINGW* ) msys=true ;; #( 114 | NONSTOP* ) nonstop=true ;; 115 | esac 116 | 117 | CLASSPATH=$APP_HOME/gradle/wrapper/gradle-wrapper.jar 118 | 119 | 120 | # Determine the Java command to use to start the JVM. 121 | if [ -n "$JAVA_HOME" ] ; then 122 | if [ -x "$JAVA_HOME/jre/sh/java" ] ; then 123 | # IBM's JDK on AIX uses strange locations for the executables 124 | JAVACMD=$JAVA_HOME/jre/sh/java 125 | else 126 | JAVACMD=$JAVA_HOME/bin/java 127 | fi 128 | if [ ! -x "$JAVACMD" ] ; then 129 | die "ERROR: JAVA_HOME is set to an invalid directory: $JAVA_HOME 130 | 131 | Please set the JAVA_HOME variable in your environment to match the 132 | location of your Java installation." 133 | fi 134 | else 135 | JAVACMD=java 136 | which java >/dev/null 2>&1 || die "ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. 137 | 138 | Please set the JAVA_HOME variable in your environment to match the 139 | location of your Java installation." 140 | fi 141 | 142 | # Increase the maximum file descriptors if we can. 143 | if ! "$cygwin" && ! "$darwin" && ! "$nonstop" ; then 144 | case $MAX_FD in #( 145 | max*) 146 | MAX_FD=$( ulimit -H -n ) || 147 | warn "Could not query maximum file descriptor limit" 148 | esac 149 | case $MAX_FD in #( 150 | '' | soft) :;; #( 151 | *) 152 | ulimit -n "$MAX_FD" || 153 | warn "Could not set maximum file descriptor limit to $MAX_FD" 154 | esac 155 | fi 156 | 157 | # Collect all arguments for the java command, stacking in reverse order: 158 | # * args from the command line 159 | # * the main class name 160 | # * -classpath 161 | # * -D...appname settings 162 | # * --module-path (only if needed) 163 | # * DEFAULT_JVM_OPTS, JAVA_OPTS, and GRADLE_OPTS environment variables. 164 | 165 | # For Cygwin or MSYS, switch paths to Windows format before running java 166 | if "$cygwin" || "$msys" ; then 167 | APP_HOME=$( cygpath --path --mixed "$APP_HOME" ) 168 | CLASSPATH=$( cygpath --path --mixed "$CLASSPATH" ) 169 | 170 | JAVACMD=$( cygpath --unix "$JAVACMD" ) 171 | 172 | # Now convert the arguments - kludge to limit ourselves to /bin/sh 173 | for arg do 174 | if 175 | case $arg in #( 176 | -*) false ;; # don't mess with options #( 177 | /?*) t=${arg#/} t=/${t%%/*} # looks like a POSIX filepath 178 | [ -e "$t" ] ;; #( 179 | *) false ;; 180 | esac 181 | then 182 | arg=$( cygpath --path --ignore --mixed "$arg" ) 183 | fi 184 | # Roll the args list around exactly as many times as the number of 185 | # args, so each arg winds up back in the position where it started, but 186 | # possibly modified. 187 | # 188 | # NB: a `for` loop captures its iteration list before it begins, so 189 | # changing the positional parameters here affects neither the number of 190 | # iterations, nor the values presented in `arg`. 191 | shift # remove old arg 192 | set -- "$@" "$arg" # push replacement arg 193 | done 194 | fi 195 | 196 | # Collect all arguments for the java command; 197 | # * $DEFAULT_JVM_OPTS, $JAVA_OPTS, and $GRADLE_OPTS can contain fragments of 198 | # shell script including quotes and variable substitutions, so put them in 199 | # double quotes to make sure that they get re-expanded; and 200 | # * put everything else in single quotes, so that it's not re-expanded. 201 | 202 | set -- \ 203 | "-Dorg.gradle.appname=$APP_BASE_NAME" \ 204 | -classpath "$CLASSPATH" \ 205 | org.gradle.wrapper.GradleWrapperMain \ 206 | "$@" 207 | 208 | # Use "xargs" to parse quoted args. 209 | # 210 | # With -n1 it outputs one arg per line, with the quotes and backslashes removed. 211 | # 212 | # In Bash we could simply go: 213 | # 214 | # readarray ARGS < <( xargs -n1 <<<"$var" ) && 215 | # set -- "${ARGS[@]}" "$@" 216 | # 217 | # but POSIX shell has neither arrays nor command substitution, so instead we 218 | # post-process each arg (as a line of input to sed) to backslash-escape any 219 | # character that might be a shell metacharacter, then use eval to reverse 220 | # that process (while maintaining the separation between arguments), and wrap 221 | # the whole thing up as a single "set" statement. 222 | # 223 | # This will of course break if any of these variables contains a newline or 224 | # an unmatched quote. 225 | # 226 | 227 | eval "set -- $( 228 | printf '%s\n' "$DEFAULT_JVM_OPTS $JAVA_OPTS $GRADLE_OPTS" | 229 | xargs -n1 | 230 | sed ' s~[^-[:alnum:]+,./:=@_]~\\&~g; ' | 231 | tr '\n' ' ' 232 | )" '"$@"' 233 | 234 | exec "$JAVACMD" "$@" 235 | -------------------------------------------------------------------------------- /gradlew.bat: -------------------------------------------------------------------------------- 1 | @rem 2 | @rem Copyright 2015 the original author or authors. 3 | @rem 4 | @rem Licensed under the Apache License, Version 2.0 (the "License"); 5 | @rem you may not use this file except in compliance with the License. 6 | @rem You may obtain a copy of the License at 7 | @rem 8 | @rem https://www.apache.org/licenses/LICENSE-2.0 9 | @rem 10 | @rem Unless required by applicable law or agreed to in writing, software 11 | @rem distributed under the License is distributed on an "AS IS" BASIS, 12 | @rem WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | @rem See the License for the specific language governing permissions and 14 | @rem limitations under the License. 15 | @rem 16 | 17 | @if "%DEBUG%" == "" @echo off 18 | @rem ########################################################################## 19 | @rem 20 | @rem Gradle startup script for Windows 21 | @rem 22 | @rem ########################################################################## 23 | 24 | @rem Set local scope for the variables with windows NT shell 25 | if "%OS%"=="Windows_NT" setlocal 26 | 27 | set DIRNAME=%~dp0 28 | if "%DIRNAME%" == "" set DIRNAME=. 29 | set APP_BASE_NAME=%~n0 30 | set APP_HOME=%DIRNAME% 31 | 32 | @rem Resolve any "." and ".." in APP_HOME to make it shorter. 33 | for %%i in ("%APP_HOME%") do set APP_HOME=%%~fi 34 | 35 | @rem Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. 36 | set DEFAULT_JVM_OPTS="-Xmx64m" "-Xms64m" 37 | 38 | @rem Find java.exe 39 | if defined JAVA_HOME goto findJavaFromJavaHome 40 | 41 | set JAVA_EXE=java.exe 42 | %JAVA_EXE% -version >NUL 2>&1 43 | if "%ERRORLEVEL%" == "0" goto execute 44 | 45 | echo. 46 | echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. 47 | echo. 48 | echo Please set the JAVA_HOME variable in your environment to match the 49 | echo location of your Java installation. 50 | 51 | goto fail 52 | 53 | :findJavaFromJavaHome 54 | set JAVA_HOME=%JAVA_HOME:"=% 55 | set JAVA_EXE=%JAVA_HOME%/bin/java.exe 56 | 57 | if exist "%JAVA_EXE%" goto execute 58 | 59 | echo. 60 | echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME% 61 | echo. 62 | echo Please set the JAVA_HOME variable in your environment to match the 63 | echo location of your Java installation. 64 | 65 | goto fail 66 | 67 | :execute 68 | @rem Setup the command line 69 | 70 | set CLASSPATH=%APP_HOME%\gradle\wrapper\gradle-wrapper.jar 71 | 72 | 73 | @rem Execute Gradle 74 | "%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" org.gradle.wrapper.GradleWrapperMain %* 75 | 76 | :end 77 | @rem End local scope for the variables with windows NT shell 78 | if "%ERRORLEVEL%"=="0" goto mainEnd 79 | 80 | :fail 81 | rem Set variable GRADLE_EXIT_CONSOLE if you need the _script_ return code instead of 82 | rem the _cmd.exe /c_ return code! 83 | if not "" == "%GRADLE_EXIT_CONSOLE%" exit 1 84 | exit /b 1 85 | 86 | :mainEnd 87 | if "%OS%"=="Windows_NT" endlocal 88 | 89 | :omega 90 | -------------------------------------------------------------------------------- /settings.gradle: -------------------------------------------------------------------------------- 1 | rootProject.name = 'framedimage' 2 | -------------------------------------------------------------------------------- /src/main/java/com/jnngl/framedimage/FrameDisplay.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2022 JNNGL 3 | * 4 | * This program is free software: you can redistribute it and/or modify 5 | * it under the terms of the GNU General Public License as published by 6 | * the Free Software Foundation, either version 3 of the License, or 7 | * (at your option) any later version. 8 | * 9 | * This program is distributed in the hope that it will be useful, 10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 | * GNU General Public License for more details. 13 | * 14 | * You should have received a copy of the GNU General Public License 15 | * along with this program. If not, see . 16 | */ 17 | 18 | package com.jnngl.framedimage; 19 | 20 | import com.jnngl.framedimage.protocol.packets.DestroyEntity; 21 | import com.jnngl.framedimage.protocol.packets.MapData; 22 | import com.jnngl.framedimage.protocol.packets.SetMetadata; 23 | import com.jnngl.framedimage.protocol.packets.SpawnEntity; 24 | import com.jnngl.framedimage.util.SectionUtil; 25 | import com.jnngl.mapcolor.palette.Palette; 26 | import org.bukkit.Location; 27 | import org.bukkit.block.BlockFace; 28 | import com.jnngl.framedimage.config.Config; 29 | import com.jnngl.framedimage.protocol.Packet; 30 | import com.jnngl.framedimage.protocol.data.Facing; 31 | import com.jnngl.framedimage.protocol.data.ItemFrame; 32 | 33 | import java.awt.*; 34 | import java.awt.image.BufferedImage; 35 | import java.util.*; 36 | import java.util.List; 37 | import java.util.stream.Collectors; 38 | 39 | public class FrameDisplay { 40 | 41 | private static final BlockFace[] OFFSET_FACES = new BlockFace[]{ 42 | BlockFace.WEST, BlockFace.NORTH, BlockFace.EAST, BlockFace.SOUTH 43 | }; 44 | 45 | private static final Facing[] FACINGS = new Facing[]{ 46 | Facing.NORTH, Facing.EAST, Facing.SOUTH, Facing.WEST 47 | }; 48 | 49 | private static int EID_COUNTER = 0; 50 | private static int MAP_COUNTER = -1; 51 | 52 | private final List> framePackets; 53 | private final List spawnPackets = new ArrayList<>(); 54 | private final List destroyPackets = new ArrayList<>(); 55 | private final Location location; 56 | private final BlockFace face; 57 | private final BlockFace offsetFace; 58 | private final int width; 59 | private final int height; 60 | private final List frames; 61 | private final UUID uuid; 62 | private Iterator> framePacketsIterator; 63 | private List sections; 64 | 65 | private static BufferedImage resizeIfNeeded(BufferedImage image, int width, int height) { 66 | if (image.getWidth() != width || image.getHeight() != height) { 67 | BufferedImage resized = new BufferedImage(width, height, BufferedImage.TYPE_INT_RGB); 68 | 69 | Graphics2D graphics = resized.createGraphics(); 70 | graphics.drawImage(image.getScaledInstance(width, height, Image.SCALE_SMOOTH), 0, 0, null); 71 | graphics.dispose(); 72 | 73 | return resized; 74 | } else { 75 | return image; 76 | } 77 | } 78 | 79 | public FrameDisplay(FramedImage plugin, Location location, BlockFace face, 80 | int width, int height, List frames, UUID uuid) { 81 | frames = frames.stream() 82 | .map(image -> resizeIfNeeded(image, width * 128, height * 128)) 83 | .collect(Collectors.toList()); 84 | 85 | this.location = location; 86 | this.face = face; 87 | this.width = width; 88 | this.height = height; 89 | this.frames = frames; 90 | this.uuid = uuid; 91 | 92 | framePackets = frames.stream() 93 | .map(frame -> new ArrayList()) 94 | .collect(Collectors.toList()); 95 | 96 | offsetFace = OFFSET_FACES[face.ordinal()]; 97 | Facing facing = FACINGS[face.ordinal()]; 98 | 99 | for (int x = 0; x < width; x++) { 100 | for (int y = 0; y < height; y++) { 101 | int blockX = location.getBlockX() + offsetFace.getModX() * x; 102 | int blockY = location.getBlockY() + y; 103 | int blockZ = location.getBlockZ() + offsetFace.getModZ() * x; 104 | 105 | int eid = --EID_COUNTER; 106 | 107 | spawnPackets.add( 108 | new SpawnEntity( 109 | eid, 110 | UUID.randomUUID(), 111 | Config.IMP.GLOW 112 | ? ItemFrame::getGlowingID 113 | : ItemFrame::getID, 114 | blockX, blockY, blockZ, 115 | 0, facing.getYaw(), 0, 116 | facing::getID, 117 | 0, 0, 0 118 | ) 119 | ); 120 | 121 | for (int i = 0; i < frames.size(); i++) { 122 | BufferedImage frame = frames.get(i); 123 | BufferedImage part = frame.getSubimage(x * 128, (height - 1 - y) * 128, 128, 128); 124 | 125 | int mapId = --MAP_COUNTER; 126 | 127 | if (Config.IMP.CACHE_MAPS) { 128 | Map data = new HashMap<>(); 129 | for (Palette palette : Palette.ALL_PALETTES) { 130 | data.put(palette, plugin.getColorMatchers().get(palette).matchImage(part)); 131 | } 132 | 133 | spawnPackets.add(new MapData(mapId, (byte) 0, data::get)); 134 | } else { 135 | spawnPackets.add( 136 | new MapData( 137 | mapId, 138 | (byte) 0, 139 | palette -> 140 | plugin 141 | .getColorMatchers() 142 | .get(palette) 143 | .matchImage(part) 144 | ) 145 | ); 146 | } 147 | 148 | framePackets.get(i).add(new SetMetadata(eid, version -> ItemFrame.createMapMetadata(version, mapId))); 149 | } 150 | 151 | destroyPackets.add(new DestroyEntity(eid)); 152 | } 153 | } 154 | 155 | framePacketsIterator = framePackets.iterator(); 156 | } 157 | 158 | public FrameDisplay(FramedImage plugin, Location location, BlockFace face, 159 | int width, int height, List frames) { 160 | this(plugin, location, face, width, height, frames, UUID.randomUUID()); 161 | } 162 | 163 | public List getNextFramePackets() { 164 | synchronized (framePackets) { 165 | if (!framePacketsIterator.hasNext()) { 166 | framePacketsIterator = framePackets.iterator(); 167 | } 168 | 169 | return framePacketsIterator.next(); 170 | } 171 | } 172 | 173 | public List getSections() { 174 | if (sections != null) { 175 | return sections; 176 | } 177 | 178 | int centerX = location.getBlockX(); 179 | int centerZ = location.getBlockZ(); 180 | int radius = (Config.IMP.DYNAMIC_FRAME_SPAWN.GRID_SIZE - 1) / 2; 181 | int offset = 1 << Config.IMP.DYNAMIC_FRAME_SPAWN.SECTION_SHIFT; 182 | 183 | sections = new ArrayList<>(); 184 | for (int x = -radius; x <= radius; x++) { 185 | for (int z = -radius; z <= radius; z++) { 186 | sections.add(SectionUtil.getSectionIndex(centerX + x * offset, centerZ + z * offset)); 187 | } 188 | } 189 | 190 | return sections = Collections.unmodifiableList(sections); 191 | } 192 | 193 | public int getNumFrames() { 194 | return frames.size(); 195 | } 196 | 197 | public Location getLocation() { 198 | return location; 199 | } 200 | 201 | public BlockFace getFace() { 202 | return face; 203 | } 204 | 205 | public BlockFace getOffsetFace() { 206 | return offsetFace; 207 | } 208 | 209 | public int getWidth() { 210 | return width; 211 | } 212 | 213 | public int getHeight() { 214 | return height; 215 | } 216 | 217 | public List getFrames() { 218 | return frames; 219 | } 220 | 221 | public UUID getUUID() { 222 | return uuid; 223 | } 224 | 225 | public List getSpawnPackets() { 226 | return spawnPackets; 227 | } 228 | 229 | public List getDestroyPackets() { 230 | return destroyPackets; 231 | } 232 | 233 | @Override 234 | public boolean equals(Object obj) { 235 | if (!(obj instanceof FrameDisplay)) { 236 | return false; 237 | } 238 | 239 | return uuid.equals(((FrameDisplay) obj).getUUID()); 240 | } 241 | 242 | @Override 243 | public int hashCode() { 244 | return uuid.hashCode(); 245 | } 246 | } 247 | -------------------------------------------------------------------------------- /src/main/java/com/jnngl/framedimage/FramedImage.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2022 JNNGL 3 | * 4 | * This program is free software: you can redistribute it and/or modify 5 | * it under the terms of the GNU General Public License as published by 6 | * the Free Software Foundation, either version 3 of the License, or 7 | * (at your option) any later version. 8 | * 9 | * This program is distributed in the hope that it will be useful, 10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 | * GNU General Public License for more details. 13 | * 14 | * You should have received a copy of the GNU General Public License 15 | * along with this program. If not, see . 16 | */ 17 | 18 | package com.jnngl.framedimage; 19 | 20 | import com.jnngl.framedimage.injection.Injector; 21 | import com.jnngl.framedimage.listener.MoveListener; 22 | import com.jnngl.framedimage.scheduler.BukkitTaskScheduler; 23 | import com.jnngl.framedimage.scheduler.CancellableTask; 24 | import com.jnngl.framedimage.scheduler.FoliaTaskScheduler; 25 | import com.jnngl.framedimage.scheduler.TaskScheduler; 26 | import com.jnngl.framedimage.util.SectionUtil; 27 | import com.jnngl.mapcolor.ColorMatcher; 28 | import com.jnngl.mapcolor.matchers.BufferedImageMatcher; 29 | import com.jnngl.mapcolor.matchers.CachedColorMatcher; 30 | import com.jnngl.mapcolor.palette.Palette; 31 | import io.netty.channel.Channel; 32 | import io.netty.channel.ChannelHandler; 33 | import io.netty.channel.ChannelHandlerContext; 34 | import org.bstats.bukkit.Metrics; 35 | import org.bstats.charts.SimplePie; 36 | import org.bukkit.Bukkit; 37 | import org.bukkit.Location; 38 | import org.bukkit.World; 39 | import org.bukkit.entity.Player; 40 | import org.bukkit.event.HandlerList; 41 | import org.bukkit.plugin.java.JavaPlugin; 42 | import com.jnngl.framedimage.command.FiCommand; 43 | import com.jnngl.framedimage.config.Config; 44 | import com.jnngl.framedimage.config.Frames; 45 | import com.jnngl.framedimage.config.Messages; 46 | import com.jnngl.framedimage.listener.PlayerListener; 47 | import com.jnngl.framedimage.listener.HandshakeListener; 48 | import com.jnngl.framedimage.protocol.Packet; 49 | 50 | import java.io.File; 51 | import java.io.IOException; 52 | import java.util.*; 53 | import java.util.concurrent.ConcurrentHashMap; 54 | 55 | public final class FramedImage extends JavaPlugin { 56 | 57 | private final Injector injector = new Injector(); 58 | private final File configFile = new File(getDataFolder(), "config.yml"); 59 | private final File messagesFile = new File(getDataFolder(), "messages.yml"); 60 | private final File framesFile = new File(getDataFolder(), "frames.yml"); 61 | private final Map>> sectionDisplays = new ConcurrentHashMap<>(); 62 | private final Map> playerDisplays = new ConcurrentHashMap<>(); 63 | private final Map playerChannels = new ConcurrentHashMap<>(); 64 | private final Map> displays = new ConcurrentHashMap<>(); 65 | private final Map colorMatchers = new ConcurrentHashMap<>(); 66 | private final Map updatableDisplays = new ConcurrentHashMap<>(); 67 | private final Set loggingPlayers = ConcurrentHashMap.newKeySet(); 68 | private final TaskScheduler scheduler; 69 | private String encoderContext = null; 70 | private MoveListener moveListener = null; 71 | 72 | { 73 | TaskScheduler scheduler; 74 | try { 75 | Class.forName("io.papermc.paper.threadedregions.scheduler.AsyncScheduler"); 76 | getLogger().info("Using folia scheduler"); 77 | scheduler = new FoliaTaskScheduler(); 78 | } catch (ClassNotFoundException e) { 79 | getLogger().info("Using bukkit scheduler"); 80 | scheduler = new BukkitTaskScheduler(); 81 | } 82 | 83 | this.scheduler = scheduler; 84 | } 85 | 86 | @Override 87 | public void onEnable() { 88 | injector.addInjector(channel -> 89 | channel.pipeline().addAfter("splitter", "framedimage:handshake", new HandshakeListener(this))); 90 | 91 | injector.inject(); 92 | getLogger().info("Successfully injected!"); 93 | 94 | scheduler.runDelayed(this, this::reload); 95 | 96 | Objects.requireNonNull(getCommand("fi")).setExecutor(new FiCommand(this)); 97 | getServer().getPluginManager().registerEvents(new PlayerListener(this), this); 98 | 99 | Metrics metrics = new Metrics(this, 16966); 100 | metrics.addCustomChart(new SimplePie("dithering", () -> String.valueOf(Config.IMP.DITHERING))); 101 | metrics.addCustomChart(new SimplePie("glow", () -> String.valueOf(Config.IMP.GLOW))); 102 | metrics.addCustomChart(new SimplePie("dynamic_frame_spawn", () -> String.valueOf(Config.IMP.DYNAMIC_FRAME_SPAWN.ENABLED))); 103 | metrics.addCustomChart(new SimplePie("scheduler", () -> this.scheduler.getClass().getSimpleName())); 104 | metrics.addCustomChart(new SimplePie("images_count", () -> String.valueOf(this.displays.values().stream().mapToInt(List::size).sum()))); 105 | } 106 | 107 | @Override 108 | public void onDisable() { 109 | removeAll(); 110 | playerChannels.clear(); 111 | } 112 | 113 | public Channel getPlayerChannel(String name) { 114 | return playerChannels.get(name); 115 | } 116 | 117 | public Channel getPlayerChannel(Player player) { 118 | return getPlayerChannel(player.getName()); 119 | } 120 | 121 | public Map getPlayerChannels() { 122 | return playerChannels; 123 | } 124 | 125 | public Map> getDisplays() { 126 | return displays; 127 | } 128 | 129 | public Set getLoggingPlayers() { 130 | return loggingPlayers; 131 | } 132 | 133 | public List getSectionDisplays(String world, long section) { 134 | Map> sectionMap = sectionDisplays.getOrDefault(world, Collections.emptyMap()); 135 | return sectionMap.getOrDefault(section, Collections.emptyList()); 136 | } 137 | 138 | public void writePacket(Channel channel, Packet packet) { 139 | ChannelHandlerContext context = 140 | encoderContext != null 141 | ? channel.pipeline().context(encoderContext) 142 | : null; 143 | 144 | if (context == null) { 145 | Iterator> handlerIterator = channel.pipeline().iterator(); 146 | do { 147 | if (!handlerIterator.hasNext()) { 148 | throw new IllegalStateException("Couldn't find encoder handler."); 149 | } 150 | } while (!handlerIterator.next().getKey().equals("framedimage:encoder")); 151 | 152 | encoderContext = handlerIterator.next().getKey(); 153 | 154 | writePacket(channel, packet); 155 | return; 156 | } 157 | 158 | context.writeAndFlush(packet); 159 | } 160 | 161 | public void displayNextFrame(FrameDisplay display) { 162 | Location location = display.getLocation(); 163 | Collection players = location.getNearbyPlayers(256); 164 | List packets = display.getNextFramePackets(); 165 | players.forEach(player -> { 166 | if (!loggingPlayers.contains(player.getName())) { 167 | Channel channel = getPlayerChannel(player); 168 | if (channel != null) { 169 | packets.forEach(packet -> writePacket(channel, packet)); 170 | } 171 | } 172 | }); 173 | } 174 | 175 | public void spawn(FrameDisplay display, Player player) { 176 | Channel channel = getPlayerChannel(player); 177 | if (channel != null) { 178 | display.getSpawnPackets().forEach(packet -> writePacket(channel, packet)); 179 | display.getNextFramePackets().forEach(packet -> writePacket(channel, packet)); 180 | } 181 | } 182 | 183 | public void spawn(FrameDisplay display) { 184 | World world = display.getLocation().getWorld(); 185 | if (world == null) { 186 | return; 187 | } 188 | 189 | List players = world.getPlayers(); 190 | players.forEach(player -> spawn(display, player)); 191 | } 192 | 193 | public void spawn(Player player) { 194 | World world = player.getLocation().getWorld(); 195 | if (world == null) { 196 | return; 197 | } 198 | 199 | if (Config.IMP.DYNAMIC_FRAME_SPAWN.ENABLED) { 200 | updateSection(player); 201 | return; 202 | } 203 | 204 | List displays = this.displays.get(world.getName()); 205 | if (displays != null) { 206 | displays.forEach(display -> spawn(display, player)); 207 | } 208 | } 209 | 210 | public void destroy(FrameDisplay display, Player player) { 211 | Channel channel = getPlayerChannel(player); 212 | if (channel != null) { 213 | display.getDestroyPackets().forEach(packet -> writePacket(channel, packet)); 214 | } 215 | } 216 | 217 | public void destroy(FrameDisplay display) { 218 | CancellableTask updater = updatableDisplays.remove(display); 219 | if (updater != null) { 220 | updater.cancel(); 221 | } 222 | 223 | World world = display.getLocation().getWorld(); 224 | if (world == null) { 225 | return; 226 | } 227 | 228 | List players = world.getPlayers(); 229 | if (Config.IMP.DYNAMIC_FRAME_SPAWN.ENABLED) { 230 | removeSections(display); 231 | players.forEach(this::updateSection); 232 | } else { 233 | players.forEach(player -> destroy(display, player)); 234 | } 235 | } 236 | 237 | public void destroyAll() { 238 | displays.values() 239 | .stream() 240 | .flatMap(List::stream) 241 | .forEach(this::destroy); 242 | } 243 | 244 | private void addSections(FrameDisplay display) { 245 | String worldName = display.getLocation().getWorld().getName(); 246 | Map> world = sectionDisplays.computeIfAbsent(worldName, key -> new ConcurrentHashMap<>()); 247 | display.getSections().forEach(section -> 248 | world.computeIfAbsent(section, key -> Collections.synchronizedList(new ArrayList<>())).add(display)); 249 | } 250 | 251 | private void removeSections(FrameDisplay display) { 252 | String worldName = display.getLocation().getWorld().getName(); 253 | Map> world = sectionDisplays.get(worldName); 254 | display.getSections().forEach(section -> { 255 | List displays = world.get(section); 256 | displays.remove(display); 257 | if (displays.isEmpty()) { 258 | world.remove(section); 259 | if (world.isEmpty()) { 260 | sectionDisplays.remove(worldName); 261 | } 262 | } 263 | }); 264 | } 265 | 266 | public void add(FrameDisplay display) { 267 | World world = display.getLocation().getWorld(); 268 | if (world == null) { 269 | return; 270 | } 271 | 272 | if (Config.IMP.DYNAMIC_FRAME_SPAWN.ENABLED) { 273 | addSections(display); 274 | world.getPlayers().forEach(this::updateSection); 275 | } else { 276 | spawn(display); 277 | } 278 | 279 | if (display.getNumFrames() > 1) { 280 | updatableDisplays.put( 281 | display, 282 | scheduler.runAtFixedRate( 283 | this, 284 | display.getLocation(), 285 | () -> displayNextFrame(display), 286 | 1L, 1L 287 | ) 288 | ); 289 | } 290 | 291 | displays.computeIfAbsent(world.getName(), k -> new ArrayList<>()).add(display); 292 | 293 | try { 294 | synchronized (Frames.class) { 295 | Frames.IMP.FRAMES.put(display.getUUID().toString(), new Frames.FrameNode(display, getDataFolder())); 296 | } 297 | } catch (IOException e) { 298 | throw new RuntimeException(e); 299 | } 300 | } 301 | 302 | public void remove(FrameDisplay display) { 303 | World world = display.getLocation().getWorld(); 304 | if (world == null) { 305 | return; 306 | } 307 | 308 | destroy(display); 309 | displays.get(world.getName()).remove(display); 310 | 311 | synchronized (Frames.class) { 312 | Frames.IMP.FRAMES.remove(display.getUUID().toString()); 313 | } 314 | } 315 | 316 | public void removeAll() { 317 | destroyAll(); 318 | displays.clear(); 319 | sectionDisplays.clear(); 320 | 321 | synchronized (Frames.class) { 322 | Frames.IMP.FRAMES.clear(); 323 | } 324 | } 325 | 326 | public void saveFrames() { 327 | Frames.IMP.save(framesFile); 328 | } 329 | 330 | public void reload() { 331 | removeAll(); 332 | 333 | Config.IMP.reload(configFile); 334 | Messages.IMP.reload(messagesFile); 335 | Frames.IMP.reload(framesFile); 336 | 337 | for (Palette palette : Palette.ALL_PALETTES) { 338 | colorMatchers.put( 339 | palette, 340 | Config.IMP.DITHERING 341 | ? new BufferedImageMatcher(palette) 342 | : new CachedColorMatcher(palette) 343 | ); 344 | } 345 | 346 | synchronized (Frames.class) { 347 | getLogger().info("Loading " + Frames.IMP.FRAMES.size() + " images."); 348 | 349 | Frames.IMP.FRAMES.forEach( 350 | (uuid, node) -> { 351 | try { 352 | add(node.createFrameDisplay(this, UUID.fromString(uuid))); 353 | } catch (IOException e) { 354 | throw new RuntimeException(e); 355 | } 356 | } 357 | ); 358 | } 359 | 360 | saveFrames(); 361 | 362 | if (moveListener != null) { 363 | HandlerList.unregisterAll(moveListener); 364 | moveListener = null; 365 | } 366 | 367 | if (Config.IMP.DYNAMIC_FRAME_SPAWN.ENABLED) { 368 | moveListener = new MoveListener(this); 369 | Bukkit.getPluginManager().registerEvents(moveListener, this); 370 | } 371 | } 372 | 373 | public void updateSection(Player player, String world, long section) { 374 | Set currentlyLoaded = playerDisplays 375 | .computeIfAbsent(player.getName(), key -> ConcurrentHashMap.newKeySet()); 376 | List sectionDisplays = getSectionDisplays(world, section); 377 | 378 | for (FrameDisplay display : sectionDisplays) { 379 | if (!currentlyLoaded.remove(display)) { 380 | spawn(display, player); 381 | } 382 | } 383 | 384 | for (FrameDisplay display : currentlyLoaded) { 385 | destroy(display, player); 386 | currentlyLoaded.remove(display); 387 | } 388 | 389 | currentlyLoaded.addAll(sectionDisplays); 390 | } 391 | 392 | public void updateSection(Player player) { 393 | Location location = player.getLocation(); 394 | updateSection(player, location.getWorld().getName(), SectionUtil.getSectionIndex(location)); 395 | } 396 | 397 | public Map getColorMatchers() { 398 | return colorMatchers; 399 | } 400 | 401 | public Map>> getAllSectionDisplays() { 402 | return sectionDisplays; 403 | } 404 | 405 | public Map> getPlayerDisplays() { 406 | return playerDisplays; 407 | } 408 | 409 | public TaskScheduler getScheduler() { 410 | return scheduler; 411 | } 412 | } 413 | -------------------------------------------------------------------------------- /src/main/java/com/jnngl/framedimage/command/FiCommand.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2022 JNNGL 3 | * 4 | * This program is free software: you can redistribute it and/or modify 5 | * it under the terms of the GNU General Public License as published by 6 | * the Free Software Foundation, either version 3 of the License, or 7 | * (at your option) any later version. 8 | * 9 | * This program is distributed in the hope that it will be useful, 10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 | * GNU General Public License for more details. 13 | * 14 | * You should have received a copy of the GNU General Public License 15 | * along with this program. If not, see . 16 | */ 17 | 18 | package com.jnngl.framedimage.command; 19 | 20 | import com.jnngl.framedimage.FramedImage; 21 | import com.jnngl.framedimage.command.fi.CreateSubcommand; 22 | import com.jnngl.framedimage.command.fi.ReloadSubcommand; 23 | import com.jnngl.framedimage.command.fi.RemoveSubcommand; 24 | import org.bukkit.ChatColor; 25 | 26 | public class FiCommand extends SubCommandExecutor { 27 | 28 | public FiCommand(FramedImage plugin) { 29 | setPermission("framedimage.command"); 30 | setHelpHeader(ChatColor.GOLD + "framedImage v" + plugin.getDescription().getVersion()); 31 | register("create", new CreateSubcommand(plugin)); 32 | register("remove", new RemoveSubcommand(plugin)); 33 | register("reload", new ReloadSubcommand(plugin)); 34 | } 35 | } 36 | -------------------------------------------------------------------------------- /src/main/java/com/jnngl/framedimage/command/SubCommand.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2022 JNNGL 3 | * 4 | * This program is free software: you can redistribute it and/or modify 5 | * it under the terms of the GNU General Public License as published by 6 | * the Free Software Foundation, either version 3 of the License, or 7 | * (at your option) any later version. 8 | * 9 | * This program is distributed in the hope that it will be useful, 10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 | * GNU General Public License for more details. 13 | * 14 | * You should have received a copy of the GNU General Public License 15 | * along with this program. If not, see . 16 | */ 17 | 18 | package com.jnngl.framedimage.command; 19 | 20 | import java.util.List; 21 | import org.bukkit.command.CommandSender; 22 | 23 | public interface SubCommand { 24 | 25 | boolean execute(CommandSender commandSender, List args) throws Exception; 26 | 27 | String help(CommandSender commandSender); 28 | 29 | String usage(CommandSender commandSender, String name); 30 | } 31 | -------------------------------------------------------------------------------- /src/main/java/com/jnngl/framedimage/command/SubCommandExecutor.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2022 JNNGL 3 | * 4 | * This program is free software: you can redistribute it and/or modify 5 | * it under the terms of the GNU General Public License as published by 6 | * the Free Software Foundation, either version 3 of the License, or 7 | * (at your option) any later version. 8 | * 9 | * This program is distributed in the hope that it will be useful, 10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 | * GNU General Public License for more details. 13 | * 14 | * You should have received a copy of the GNU General Public License 15 | * along with this program. If not, see . 16 | */ 17 | 18 | package com.jnngl.framedimage.command; 19 | 20 | import java.util.ArrayList; 21 | import java.util.HashMap; 22 | import java.util.List; 23 | import java.util.Map; 24 | 25 | import net.elytrium.java.commons.config.Placeholders; 26 | import org.bukkit.ChatColor; 27 | import org.bukkit.command.Command; 28 | import org.bukkit.command.CommandExecutor; 29 | import org.bukkit.command.CommandSender; 30 | import com.jnngl.framedimage.config.Messages; 31 | import org.jetbrains.annotations.NotNull; 32 | 33 | public class SubCommandExecutor implements CommandExecutor { 34 | private final Map subcommands = new HashMap<>(); 35 | private String helpHeader = ChatColor.GOLD + "Help"; 36 | private String permission = null; 37 | 38 | public void register(String name, SubCommand subCommand) { 39 | subcommands.put(name, subCommand); 40 | } 41 | 42 | public void unregister(String name) { 43 | subcommands.remove(name); 44 | } 45 | 46 | @Override 47 | public boolean onCommand(@NotNull CommandSender commandSender, @NotNull Command command, @NotNull String s, String[] args) { 48 | if (permission != null && !commandSender.hasPermission(permission)) { 49 | commandSender.sendMessage(ChatColor.RED + Messages.IMP.MESSAGES.COMMAND.NOT_ENOUGH_PERMISSIONS); 50 | return true; 51 | } 52 | 53 | SubCommand subCommand = null; 54 | if (args.length >= 1) { 55 | subCommand = subcommands.get(args[0].toLowerCase()); 56 | } 57 | 58 | if (subCommand == null) { 59 | commandSender.sendMessage(helpHeader.split("\n")); 60 | subcommands.forEach((name, cmd) -> { 61 | String help = cmd.help(commandSender); 62 | if (help != null && !help.isBlank()) { 63 | commandSender.sendMessage(ChatColor.GOLD + "/" + s + " " + name + " " + ChatColor.DARK_GRAY + help); 64 | } 65 | }); 66 | } else { 67 | List parsedArgs = new ArrayList<>(); 68 | 69 | StringBuilder currentString = null; 70 | for (int i = 1; i < args.length; i++) { 71 | String arg = args[i]; 72 | String parsedArg = arg.replace("\\\"", "\""); 73 | 74 | if (arg.startsWith("\"") && arg.endsWith("\"") && !arg.endsWith("\\\"")) { 75 | parsedArgs.add(parsedArg.substring(1, parsedArg.length() - 1)); 76 | } else if (arg.startsWith("\"")) { 77 | currentString = new StringBuilder(parsedArg.substring(1)); 78 | } else if (arg.endsWith("\"") && !arg.endsWith("\\\"")) { 79 | if (currentString == null) { 80 | commandSender.sendMessage(ChatColor.RED + 81 | Placeholders.replace(Messages.IMP.MESSAGES.COMMAND.COULDNT_PARSE_ARGUMENT, parsedArg)); 82 | return true; 83 | } 84 | 85 | currentString.append(" ").append(parsedArg, 0, parsedArg.length() - 1); 86 | parsedArgs.add(currentString.toString()); 87 | currentString = null; 88 | } else { 89 | if (currentString != null) { 90 | currentString.append(" ").append(parsedArg); 91 | } else { 92 | parsedArgs.add(parsedArg); 93 | } 94 | } 95 | } 96 | 97 | if (currentString != null) { 98 | commandSender.sendMessage(ChatColor.RED + 99 | Placeholders.replace(Messages.IMP.MESSAGES.COMMAND.COULDNT_PARSE_ARGUMENT, currentString)); 100 | return true; 101 | } 102 | 103 | try { 104 | if (!subCommand.execute(commandSender, parsedArgs)) { 105 | String usage = subCommand.usage(commandSender, s); 106 | 107 | if (usage != null && !usage.isBlank()) { 108 | commandSender.sendMessage(ChatColor.GOLD + 109 | Placeholders.replace(Messages.IMP.MESSAGES.COMMAND.USAGE, ChatColor.DARK_GRAY + usage)); 110 | } 111 | } 112 | } catch (Exception e) { 113 | e.printStackTrace(); 114 | commandSender.sendMessage(ChatColor.RED + e.getClass().getName() + ": " + e.getMessage()); 115 | return true; 116 | } 117 | } 118 | 119 | return true; 120 | } 121 | 122 | public String getPermission() { 123 | return permission; 124 | } 125 | 126 | public void setPermission(String permission) { 127 | this.permission = permission; 128 | } 129 | 130 | public Map getSubcommands() { 131 | return subcommands; 132 | } 133 | 134 | public String getHelpHeader() { 135 | return helpHeader; 136 | } 137 | 138 | public void setHelpHeader(String helpHeader) { 139 | this.helpHeader = helpHeader; 140 | } 141 | } 142 | -------------------------------------------------------------------------------- /src/main/java/com/jnngl/framedimage/command/fi/CreateSubcommand.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2022 JNNGL 3 | * 4 | * This program is free software: you can redistribute it and/or modify 5 | * it under the terms of the GNU General Public License as published by 6 | * the Free Software Foundation, either version 3 of the License, or 7 | * (at your option) any later version. 8 | * 9 | * This program is distributed in the hope that it will be useful, 10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 | * GNU General Public License for more details. 13 | * 14 | * You should have received a copy of the GNU General Public License 15 | * along with this program. If not, see . 16 | */ 17 | 18 | package com.jnngl.framedimage.command.fi; 19 | 20 | import com.jnngl.framedimage.FrameDisplay; 21 | import com.jnngl.framedimage.FramedImage; 22 | import com.jnngl.framedimage.util.ImageUtil; 23 | import net.elytrium.java.commons.config.Placeholders; 24 | import org.bukkit.ChatColor; 25 | import org.bukkit.Location; 26 | import org.bukkit.block.Block; 27 | import org.bukkit.block.BlockFace; 28 | import org.bukkit.command.CommandSender; 29 | import org.bukkit.entity.Player; 30 | import com.jnngl.framedimage.command.SubCommand; 31 | import com.jnngl.framedimage.config.Messages; 32 | import com.jnngl.framedimage.util.BlockUtil; 33 | 34 | import java.awt.image.BufferedImage; 35 | import java.io.IOException; 36 | import java.util.List; 37 | 38 | public class CreateSubcommand implements SubCommand { 39 | 40 | private final FramedImage plugin; 41 | 42 | public CreateSubcommand(FramedImage plugin) { 43 | this.plugin = plugin; 44 | } 45 | 46 | @Override 47 | public boolean execute(CommandSender commandSender, List args) { 48 | if (!commandSender.hasPermission("framedimage.subcommand.create")) { 49 | commandSender.sendMessage(ChatColor.RED + Messages.IMP.MESSAGES.COMMAND.NOT_ENOUGH_PERMISSIONS); 50 | return true; 51 | } 52 | 53 | if (args.size() < 3) { 54 | commandSender.sendMessage(ChatColor.RED + Messages.IMP.MESSAGES.COMMAND.CREATE.TOO_FEW_ARGUMENTS); 55 | return false; 56 | } 57 | 58 | if (!(commandSender instanceof Player player)) { 59 | commandSender.sendMessage(ChatColor.RED + Messages.IMP.MESSAGES.COMMAND.CREATE.ONLY_PLAYERS_CAN_USE); 60 | return true; 61 | } 62 | 63 | int width = Integer.parseInt(args.get(0)); 64 | int height = Integer.parseInt(args.get(1)); 65 | String urlString = args.get(2); 66 | 67 | if (width <= 0 || height <= 0) { 68 | commandSender.sendMessage(ChatColor.RED + Messages.IMP.MESSAGES.COMMAND.CREATE.INVALID_ARGUMENTS); 69 | return false; 70 | } 71 | 72 | BlockFace blockFace = BlockUtil.getBlockFace(player.getLocation().getYaw()); 73 | 74 | Block block = player.getTargetBlock(null, 10); 75 | if (block.isEmpty()) { 76 | commandSender.sendMessage(ChatColor.RED + Messages.IMP.MESSAGES.COMMAND.CREATE.BLOCK_NOT_FOUND); 77 | return true; 78 | } 79 | 80 | Location location = BlockUtil.getNextBlockLocation(block.getLocation(), blockFace); 81 | 82 | plugin.getScheduler().runAsync(plugin, () -> { 83 | try { 84 | List frames = ImageUtil.readFrames(urlString); 85 | FrameDisplay frameDisplay = new FrameDisplay(plugin, location, blockFace, width, height, frames); 86 | plugin.add(frameDisplay); 87 | plugin.saveFrames(); 88 | } catch(IOException e) { 89 | commandSender.sendMessage(ChatColor.RED + e.getClass().getName() + ": " + e.getMessage()); 90 | } 91 | }); 92 | 93 | return true; 94 | } 95 | 96 | @Override 97 | public String help(CommandSender commandSender) { 98 | return Messages.IMP.MESSAGES.COMMAND.CREATE.HELP; 99 | } 100 | 101 | @Override 102 | public String usage(CommandSender commandSender, String name) { 103 | return Placeholders.replace(Messages.IMP.MESSAGES.COMMAND.CREATE.USAGE, name); 104 | } 105 | } 106 | -------------------------------------------------------------------------------- /src/main/java/com/jnngl/framedimage/command/fi/ReloadSubcommand.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2022 JNNGL 3 | * 4 | * This program is free software: you can redistribute it and/or modify 5 | * it under the terms of the GNU General Public License as published by 6 | * the Free Software Foundation, either version 3 of the License, or 7 | * (at your option) any later version. 8 | * 9 | * This program is distributed in the hope that it will be useful, 10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 | * GNU General Public License for more details. 13 | * 14 | * You should have received a copy of the GNU General Public License 15 | * along with this program. If not, see . 16 | */ 17 | 18 | package com.jnngl.framedimage.command.fi; 19 | 20 | import com.jnngl.framedimage.FramedImage; 21 | import org.bukkit.ChatColor; 22 | import org.bukkit.command.CommandSender; 23 | import com.jnngl.framedimage.command.SubCommand; 24 | import com.jnngl.framedimage.config.Messages; 25 | 26 | import java.util.List; 27 | 28 | public class ReloadSubcommand implements SubCommand { 29 | 30 | private final FramedImage plugin; 31 | 32 | public ReloadSubcommand(FramedImage plugin) { 33 | this.plugin = plugin; 34 | } 35 | 36 | @Override 37 | public boolean execute(CommandSender commandSender, List args) { 38 | if (!commandSender.hasPermission("framedimage.subcommand.reload")) { 39 | commandSender.sendMessage(ChatColor.RED + Messages.IMP.MESSAGES.COMMAND.NOT_ENOUGH_PERMISSIONS); 40 | return true; 41 | } 42 | 43 | plugin.reload(); 44 | commandSender.sendMessage(ChatColor.GOLD + Messages.IMP.MESSAGES.COMMAND.RELOAD.RELOADED); 45 | return true; 46 | } 47 | 48 | @Override 49 | public String help(CommandSender commandSender) { 50 | return Messages.IMP.MESSAGES.COMMAND.RELOAD.HELP; 51 | } 52 | 53 | @Override 54 | public String usage(CommandSender commandSender, String name) { 55 | return Messages.IMP.MESSAGES.COMMAND.RELOAD.USAGE; 56 | } 57 | } 58 | -------------------------------------------------------------------------------- /src/main/java/com/jnngl/framedimage/command/fi/RemoveSubcommand.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2022 JNNGL 3 | * 4 | * This program is free software: you can redistribute it and/or modify 5 | * it under the terms of the GNU General Public License as published by 6 | * the Free Software Foundation, either version 3 of the License, or 7 | * (at your option) any later version. 8 | * 9 | * This program is distributed in the hope that it will be useful, 10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 | * GNU General Public License for more details. 13 | * 14 | * You should have received a copy of the GNU General Public License 15 | * along with this program. If not, see . 16 | */ 17 | 18 | package com.jnngl.framedimage.command.fi; 19 | 20 | import com.jnngl.framedimage.FrameDisplay; 21 | import com.jnngl.framedimage.FramedImage; 22 | import org.bukkit.ChatColor; 23 | import org.bukkit.Location; 24 | import org.bukkit.block.BlockFace; 25 | import org.bukkit.command.CommandSender; 26 | import org.bukkit.entity.Player; 27 | import com.jnngl.framedimage.command.SubCommand; 28 | import com.jnngl.framedimage.config.Messages; 29 | import org.bukkit.util.Vector; 30 | 31 | import java.util.List; 32 | 33 | public class RemoveSubcommand implements SubCommand { 34 | 35 | private final FramedImage plugin; 36 | 37 | public RemoveSubcommand(FramedImage plugin) { 38 | this.plugin = plugin; 39 | } 40 | 41 | @Override 42 | public boolean execute(CommandSender commandSender, List args) { 43 | if (!commandSender.hasPermission("framedimage.subcommand.remove")) { 44 | commandSender.sendMessage(ChatColor.RED + Messages.IMP.MESSAGES.COMMAND.NOT_ENOUGH_PERMISSIONS); 45 | return true; 46 | } 47 | 48 | if (!(commandSender instanceof Player player)) { 49 | commandSender.sendMessage(ChatColor.RED + Messages.IMP.MESSAGES.COMMAND.REMOVE.ONLY_PLAYERS_CAN_USE); 50 | return true; 51 | } 52 | 53 | List displays = plugin.getDisplays().get(player.getWorld().getName()); 54 | if (displays == null) { 55 | commandSender.sendMessage(ChatColor.RED + Messages.IMP.MESSAGES.COMMAND.REMOVE.IMAGE_NOT_FOUND); 56 | return true; 57 | } 58 | 59 | Vector origin = player.getEyeLocation().toVector(); 60 | Vector direction = player.getLocation().getDirection(); 61 | 62 | FrameDisplay targetDisplay = null; 63 | double nearest = Double.MAX_VALUE; 64 | 65 | for (FrameDisplay display : displays) { 66 | Location location = display.getLocation(); 67 | if (location.distanceSquared(player.getLocation()) > 50 * 50) { 68 | continue; 69 | } 70 | 71 | int width = display.getWidth(); 72 | int height = display.getHeight(); 73 | BlockFace offsetFace = display.getOffsetFace(); 74 | 75 | Vector offsetVector = switch(offsetFace) { 76 | case SOUTH -> new Vector(1, 0, 0); 77 | case NORTH -> new Vector(0, 0, 1); 78 | case WEST -> new Vector(1, 0, 1); 79 | default -> new Vector(); 80 | }; 81 | 82 | Vector point1 = location.toVector().add(offsetVector); 83 | Vector point2 = location.toVector().add( 84 | new Vector( 85 | width * offsetFace.getModX() + -0.1 * offsetFace.getModZ(), 86 | height, 87 | width * offsetFace.getModZ() + 0.1 * offsetFace.getModX() 88 | ) 89 | ).add(offsetVector); 90 | 91 | Vector min = Vector.getMinimum(point1, point2); 92 | point2 = Vector.getMaximum(point1, point2); 93 | point1 = min; 94 | 95 | point1.subtract(origin).divide(direction); 96 | point2.subtract(origin).divide(direction); 97 | Vector near = Vector.getMinimum(point1, point2); 98 | Vector far = Vector.getMaximum(point1, point2); 99 | double nearDistance = Math.max(Math.max(near.getX(), near.getY()), near.getZ()); 100 | double farDistance = Math.min(Math.min(far.getX(), far.getY()), far.getZ()); 101 | 102 | if (nearDistance <= farDistance && nearDistance < nearest) { 103 | targetDisplay = display; 104 | nearest = nearDistance; 105 | } 106 | } 107 | 108 | if (targetDisplay == null) { 109 | commandSender.sendMessage(ChatColor.RED + Messages.IMP.MESSAGES.COMMAND.REMOVE.IMAGE_NOT_FOUND); 110 | return true; 111 | } 112 | 113 | plugin.remove(targetDisplay); 114 | plugin.saveFrames(); 115 | 116 | return true; 117 | } 118 | 119 | @Override 120 | public String help(CommandSender commandSender) { 121 | return Messages.IMP.MESSAGES.COMMAND.REMOVE.HELP; 122 | } 123 | 124 | @Override 125 | public String usage(CommandSender commandSender, String name) { 126 | return Messages.IMP.MESSAGES.COMMAND.REMOVE.USAGE; 127 | } 128 | } 129 | -------------------------------------------------------------------------------- /src/main/java/com/jnngl/framedimage/config/Config.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2022 JNNGL 3 | * 4 | * This program is free software: you can redistribute it and/or modify 5 | * it under the terms of the GNU General Public License as published by 6 | * the Free Software Foundation, either version 3 of the License, or 7 | * (at your option) any later version. 8 | * 9 | * This program is distributed in the hope that it will be useful, 10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 | * GNU General Public License for more details. 13 | * 14 | * You should have received a copy of the GNU General Public License 15 | * along with this program. If not, see . 16 | */ 17 | 18 | package com.jnngl.framedimage.config; 19 | 20 | import net.elytrium.java.commons.config.YamlConfig; 21 | 22 | public class Config extends YamlConfig { 23 | 24 | @Ignore 25 | public static final Config IMP = new Config(); 26 | 27 | public boolean DITHERING = true; 28 | public boolean GLOW = false; 29 | public boolean CACHE_MAPS = true; 30 | 31 | @Create 32 | public DYNAMIC_FRAME_SPAWN DYNAMIC_FRAME_SPAWN; 33 | 34 | public static class DYNAMIC_FRAME_SPAWN { 35 | 36 | @Comment("Frames will only be sent when the player gets closer to them.") 37 | public boolean ENABLED = true; 38 | public int SECTION_SHIFT = 7; 39 | public int GRID_SIZE = 3; 40 | } 41 | } 42 | -------------------------------------------------------------------------------- /src/main/java/com/jnngl/framedimage/config/Frames.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2022 JNNGL 3 | * 4 | * This program is free software: you can redistribute it and/or modify 5 | * it under the terms of the GNU General Public License as published by 6 | * the Free Software Foundation, either version 3 of the License, or 7 | * (at your option) any later version. 8 | * 9 | * This program is distributed in the hope that it will be useful, 10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 | * GNU General Public License for more details. 13 | * 14 | * You should have received a copy of the GNU General Public License 15 | * along with this program. If not, see . 16 | */ 17 | 18 | package com.jnngl.framedimage.config; 19 | 20 | import com.jnngl.framedimage.FrameDisplay; 21 | import com.jnngl.framedimage.FramedImage; 22 | import net.elytrium.java.commons.config.YamlConfig; 23 | import org.bukkit.Bukkit; 24 | import org.bukkit.Location; 25 | import org.bukkit.block.BlockFace; 26 | 27 | import javax.imageio.ImageIO; 28 | import java.awt.image.BufferedImage; 29 | import java.io.File; 30 | import java.io.IOException; 31 | import java.nio.file.Files; 32 | import java.nio.file.Path; 33 | import java.util.ArrayList; 34 | import java.util.Collections; 35 | import java.util.HashMap; 36 | import java.util.List; 37 | import java.util.Map; 38 | import java.util.UUID; 39 | 40 | public class Frames extends YamlConfig { 41 | 42 | @Ignore 43 | public static final Frames IMP = new Frames(); 44 | 45 | public Map FRAMES = new HashMap<>(); 46 | 47 | @NodeSequence 48 | public static class FrameNode { 49 | 50 | public String WORLD; 51 | public int X; 52 | public int Y; 53 | public int Z; 54 | public int WIDTH; 55 | public int HEIGHT; 56 | public String FACE; 57 | public String IMAGE = ""; // For backward compatibility 58 | public List FRAMES; 59 | 60 | public FrameNode(FrameDisplay display, File dataFolder) throws IOException { 61 | Location location = display.getLocation(); 62 | WORLD = location.getWorld().getName(); 63 | X = location.getBlockX(); 64 | Y = location.getBlockY(); 65 | Z = location.getBlockZ(); 66 | WIDTH = display.getWidth(); 67 | HEIGHT = display.getHeight(); 68 | FACE = display.getFace().toString(); 69 | FRAMES = new ArrayList<>(); 70 | 71 | for (int i = 0; i < display.getNumFrames(); i++) { 72 | Path path = Path.of(dataFolder.getPath(), "images/" + display.getUUID() + "_" + i + ".png"); 73 | File file = path.toFile(); 74 | 75 | if (Files.notExists(path)) { 76 | Files.createDirectories(path.getParent()); 77 | ImageIO.write(display.getFrames().get(i), "PNG", file); 78 | } 79 | 80 | FRAMES.add(file.getPath().replace(File.separatorChar, '/')); 81 | } 82 | } 83 | 84 | public FrameNode() { 85 | 86 | } 87 | 88 | public FrameDisplay createFrameDisplay(FramedImage plugin, UUID uuid) throws IOException { 89 | Location location = new Location( 90 | Bukkit.getWorld(WORLD), 91 | X, Y, Z 92 | ); 93 | 94 | BlockFace face = BlockFace.valueOf(FACE); 95 | 96 | List frames; 97 | if (IMAGE != null && !IMAGE.isBlank()) { 98 | frames = Collections.singletonList(ImageIO.read(new File(IMAGE))); 99 | } else { 100 | frames = new ArrayList<>(); 101 | for (String frame : FRAMES) { 102 | frames.add(ImageIO.read(new File(frame))); 103 | } 104 | } 105 | 106 | return new FrameDisplay(plugin, location, face, WIDTH, HEIGHT, frames, uuid); 107 | } 108 | } 109 | } 110 | -------------------------------------------------------------------------------- /src/main/java/com/jnngl/framedimage/config/Messages.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2022 JNNGL 3 | * 4 | * This program is free software: you can redistribute it and/or modify 5 | * it under the terms of the GNU General Public License as published by 6 | * the Free Software Foundation, either version 3 of the License, or 7 | * (at your option) any later version. 8 | * 9 | * This program is distributed in the hope that it will be useful, 10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 | * GNU General Public License for more details. 13 | * 14 | * You should have received a copy of the GNU General Public License 15 | * along with this program. If not, see . 16 | */ 17 | 18 | package com.jnngl.framedimage.config; 19 | 20 | import net.elytrium.java.commons.config.YamlConfig; 21 | 22 | public class Messages extends YamlConfig { 23 | 24 | @Ignore 25 | public static final Messages IMP = new Messages(); 26 | 27 | @Create 28 | public MESSAGES MESSAGES; 29 | 30 | public static class MESSAGES { 31 | 32 | @Create 33 | public COMMAND COMMAND; 34 | 35 | public static class COMMAND { 36 | 37 | public String NOT_ENOUGH_PERMISSIONS = "Not enough permissions."; 38 | @Placeholders("{ARGUMENT}") 39 | public String COULDNT_PARSE_ARGUMENT = "Couldn't parse argument: {ARGUMENT}"; 40 | @Placeholders("{USAGE}") 41 | public String USAGE = "Usage: {USAGE}"; 42 | 43 | @Create 44 | public CREATE CREATE; 45 | 46 | public static class CREATE { 47 | 48 | public String HELP = "Creates an image on the block where the cursor is pointing. (Frames go right and up)"; 49 | @Placeholders("{COMMAND}") 50 | public String USAGE = "/{COMMAND} create "; 51 | public String BLOCK_NOT_FOUND = "Can't find block."; 52 | public String TOO_FEW_ARGUMENTS = "Too few arguments."; 53 | public String ONLY_PLAYERS_CAN_USE = "Only players can use this command."; 54 | public String INVALID_ARGUMENTS = "Invalid arguments."; 55 | } 56 | 57 | @Create 58 | public REMOVE REMOVE; 59 | 60 | public static class REMOVE { 61 | 62 | public String HELP = "Deletes the image the cursor is pointing to."; 63 | @Placeholders("{COMMAND}") 64 | public String USAGE = "/{COMMAND} remove"; 65 | @Deprecated 66 | public String BLOCK_NOT_FOUND = "Can't find block."; 67 | public String ONLY_PLAYERS_CAN_USE = "Only players can use this command."; 68 | public String IMAGE_NOT_FOUND = "Can't find image."; 69 | } 70 | 71 | @Create 72 | public RELOAD RELOAD; 73 | 74 | public static class RELOAD { 75 | 76 | public String HELP = "Reloads the config and images."; 77 | @Placeholders("{COMMAND}") 78 | public String USAGE = "/{COMMAND} reload"; 79 | public String RELOADED = "Config and images has been successfully reloaded."; 80 | } 81 | } 82 | } 83 | } 84 | -------------------------------------------------------------------------------- /src/main/java/com/jnngl/framedimage/injection/ChannelInjectionHandler.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2022 JNNGL 3 | * 4 | * This program is free software: you can redistribute it and/or modify 5 | * it under the terms of the GNU General Public License as published by 6 | * the Free Software Foundation, either version 3 of the License, or 7 | * (at your option) any later version. 8 | * 9 | * This program is distributed in the hope that it will be useful, 10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 | * GNU General Public License for more details. 13 | * 14 | * You should have received a copy of the GNU General Public License 15 | * along with this program. If not, see . 16 | */ 17 | 18 | package com.jnngl.framedimage.injection; 19 | 20 | import io.netty.channel.Channel; 21 | import io.netty.channel.ChannelDuplexHandler; 22 | import io.netty.channel.ChannelHandler; 23 | import io.netty.channel.ChannelHandlerContext; 24 | import io.netty.channel.ChannelInboundHandlerAdapter; 25 | import io.netty.channel.ChannelInitializer; 26 | import io.netty.channel.ChannelPromise; 27 | import org.jetbrains.annotations.NotNull; 28 | 29 | import java.util.List; 30 | 31 | @ChannelHandler.Sharable 32 | public class ChannelInjectionHandler extends ChannelInboundHandlerAdapter { 33 | 34 | private final List injectors; 35 | 36 | public ChannelInjectionHandler(List injectors) { 37 | this.injectors = injectors; 38 | } 39 | 40 | @Override 41 | public void channelRead(@NotNull ChannelHandlerContext ctx, @NotNull Object msg) throws Exception { 42 | Channel channel = (Channel) msg; 43 | 44 | channel.pipeline().addLast(new ChannelInitializer<>() { 45 | 46 | @Override 47 | protected void initChannel(@NotNull Channel ch) { 48 | channel.pipeline().addLast(new ChannelDuplexHandler() { 49 | 50 | @Override 51 | public void channelRead(@NotNull ChannelHandlerContext ctx, @NotNull Object msg) throws Exception { 52 | ctx.pipeline().remove(this); 53 | inject(ctx.channel()); 54 | 55 | super.channelRead(ctx, msg); 56 | } 57 | 58 | @Override 59 | public void write(ChannelHandlerContext ctx, Object msg, ChannelPromise promise) throws Exception { 60 | ctx.pipeline().remove(this); 61 | inject(ctx.channel()); 62 | 63 | super.write(ctx, msg, promise); 64 | } 65 | }); 66 | } 67 | }); 68 | 69 | super.channelRead(ctx, msg); 70 | } 71 | 72 | private void inject(Channel channel) { 73 | injectors.forEach(injector -> injector.inject(channel)); 74 | } 75 | } 76 | -------------------------------------------------------------------------------- /src/main/java/com/jnngl/framedimage/injection/ChannelInjector.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2022 JNNGL 3 | * 4 | * This program is free software: you can redistribute it and/or modify 5 | * it under the terms of the GNU General Public License as published by 6 | * the Free Software Foundation, either version 3 of the License, or 7 | * (at your option) any later version. 8 | * 9 | * This program is distributed in the hope that it will be useful, 10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 | * GNU General Public License for more details. 13 | * 14 | * You should have received a copy of the GNU General Public License 15 | * along with this program. If not, see . 16 | */ 17 | 18 | package com.jnngl.framedimage.injection; 19 | 20 | import io.netty.channel.Channel; 21 | 22 | public interface ChannelInjector { 23 | 24 | void inject(Channel channel); 25 | } 26 | -------------------------------------------------------------------------------- /src/main/java/com/jnngl/framedimage/injection/InjectionException.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2022 JNNGL 3 | * 4 | * This program is free software: you can redistribute it and/or modify 5 | * it under the terms of the GNU General Public License as published by 6 | * the Free Software Foundation, either version 3 of the License, or 7 | * (at your option) any later version. 8 | * 9 | * This program is distributed in the hope that it will be useful, 10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 | * GNU General Public License for more details. 13 | * 14 | * You should have received a copy of the GNU General Public License 15 | * along with this program. If not, see . 16 | */ 17 | 18 | package com.jnngl.framedimage.injection; 19 | 20 | public class InjectionException extends RuntimeException { 21 | 22 | public InjectionException(String message) { 23 | super(message); 24 | } 25 | 26 | public InjectionException(Throwable cause) { 27 | super(cause); 28 | } 29 | } 30 | -------------------------------------------------------------------------------- /src/main/java/com/jnngl/framedimage/injection/Injector.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2022 JNNGL 3 | * 4 | * This program is free software: you can redistribute it and/or modify 5 | * it under the terms of the GNU General Public License as published by 6 | * the Free Software Foundation, either version 3 of the License, or 7 | * (at your option) any later version. 8 | * 9 | * This program is distributed in the hope that it will be useful, 10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 | * GNU General Public License for more details. 13 | * 14 | * You should have received a copy of the GNU General Public License 15 | * along with this program. If not, see . 16 | */ 17 | 18 | package com.jnngl.framedimage.injection; 19 | 20 | import io.netty.channel.Channel; 21 | import io.netty.channel.ChannelFuture; 22 | import org.bukkit.Bukkit; 23 | import org.bukkit.Server; 24 | 25 | import java.lang.reflect.Field; 26 | import java.lang.reflect.ParameterizedType; 27 | import java.lang.reflect.Type; 28 | import java.util.ArrayList; 29 | import java.util.Collection; 30 | import java.util.Collections; 31 | import java.util.List; 32 | import java.util.function.Predicate; 33 | 34 | public class Injector { 35 | 36 | private final class InjectedList extends ArrayList { 37 | 38 | private InjectedList(List originalList) { 39 | super(originalList); 40 | } 41 | 42 | @Override 43 | public boolean add(ChannelFuture channelFuture) { 44 | inject(channelFuture.channel()); 45 | return super.add(channelFuture); 46 | } 47 | 48 | @Override 49 | public void add(int index, ChannelFuture element) { 50 | inject(element.channel()); 51 | super.add(index, element); 52 | } 53 | 54 | @Override 55 | public boolean addAll(Collection c) { 56 | c.forEach(channelFuture -> inject(channelFuture.channel())); 57 | return super.addAll(c); 58 | } 59 | 60 | @Override 61 | public boolean addAll(int index, Collection c) { 62 | c.forEach(channelFuture -> inject(channelFuture.channel())); 63 | return super.addAll(index, c); 64 | } 65 | } 66 | 67 | private static Field findField(Class cls, Predicate predicate) throws NoSuchMethodException { 68 | for (Field field : cls.getDeclaredFields()) { 69 | if (predicate.test(field)) { 70 | field.setAccessible(true); 71 | return field; 72 | } 73 | } 74 | 75 | Class superclass = cls.getSuperclass(); 76 | if (superclass != null) { 77 | return findField(superclass, predicate); 78 | } else { 79 | throw new NoSuchMethodException("in class " + cls.getName()); 80 | } 81 | } 82 | 83 | private final List injectors = Collections.synchronizedList(new ArrayList<>()); 84 | private final ChannelInjectionHandler injectionHandler = new ChannelInjectionHandler(injectors); 85 | private final Field openChannelsField; 86 | private final Object connection; 87 | private List openChannels; 88 | 89 | @SuppressWarnings("unchecked") 90 | public Injector() { 91 | try { 92 | Server server = Bukkit.getServer(); 93 | Field consoleField = server.getClass().getDeclaredField("console"); 94 | consoleField.setAccessible(true); 95 | Object minecraftServer = consoleField.get(server); 96 | Field connectionField = findField(minecraftServer.getClass(), 97 | field -> field.getType().getSimpleName().startsWith("ServerConnection")); 98 | connection = connectionField.get(minecraftServer); 99 | 100 | for (Field field : connection.getClass().getDeclaredFields()) { 101 | Type genericType = field.getGenericType(); 102 | if (!(genericType instanceof ParameterizedType type)) { 103 | continue; 104 | } 105 | 106 | if (type.getRawType() != List.class) { 107 | continue; 108 | } 109 | 110 | Type firstParameter = type.getActualTypeArguments()[0]; 111 | if (!firstParameter.getTypeName().endsWith("ChannelFuture")) { 112 | continue; 113 | } 114 | 115 | field.setAccessible(true); 116 | openChannelsField = field; 117 | openChannels = (List) field.get(connection); 118 | return; 119 | } 120 | 121 | throw new InjectionException("Couldn't inject."); 122 | } catch (ReflectiveOperationException e) { 123 | throw new InjectionException(e); 124 | } 125 | } 126 | 127 | public void inject() { 128 | ensureNotInjected(); 129 | openChannels = Collections.synchronizedList(new InjectedList(openChannels)); 130 | openChannels.forEach(channelFuture -> inject(channelFuture.channel())); 131 | 132 | try { 133 | openChannelsField.set(connection, openChannels); 134 | } catch (ReflectiveOperationException e) { 135 | throw new InjectionException(e); 136 | } 137 | } 138 | 139 | private void inject(Channel channel) { 140 | channel.pipeline().addFirst(injectionHandler); 141 | } 142 | 143 | public void addInjector(ChannelInjector injector) { 144 | ensureNotInjected(); 145 | injectors.add(injector); 146 | } 147 | 148 | public void removeInjector(ChannelInjector injector) { 149 | ensureNotInjected(); 150 | injectors.remove(injector); 151 | } 152 | 153 | public List getInjectors() { 154 | return injectors; 155 | } 156 | 157 | public List getOpenChannels() { 158 | return openChannels; 159 | } 160 | 161 | private void ensureNotInjected() { 162 | if (openChannels instanceof InjectedList) { 163 | throw new InjectionException("Already injected."); 164 | } 165 | } 166 | } 167 | -------------------------------------------------------------------------------- /src/main/java/com/jnngl/framedimage/listener/DisconnectHandler.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2022 JNNGL 3 | * 4 | * This program is free software: you can redistribute it and/or modify 5 | * it under the terms of the GNU General Public License as published by 6 | * the Free Software Foundation, either version 3 of the License, or 7 | * (at your option) any later version. 8 | * 9 | * This program is distributed in the hope that it will be useful, 10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 | * GNU General Public License for more details. 13 | * 14 | * You should have received a copy of the GNU General Public License 15 | * along with this program. If not, see . 16 | */ 17 | 18 | package com.jnngl.framedimage.listener; 19 | 20 | import com.jnngl.framedimage.FramedImage; 21 | import io.netty.channel.ChannelHandlerContext; 22 | import io.netty.channel.ChannelInboundHandlerAdapter; 23 | import org.jetbrains.annotations.NotNull; 24 | 25 | public class DisconnectHandler extends ChannelInboundHandlerAdapter { 26 | 27 | private final FramedImage plugin; 28 | private final String name; 29 | 30 | public DisconnectHandler(FramedImage plugin, String name) { 31 | this.plugin = plugin; 32 | this.name = name; 33 | } 34 | 35 | @Override 36 | public void channelInactive(@NotNull ChannelHandlerContext ctx) throws Exception { 37 | plugin.getLoggingPlayers().remove(name); 38 | plugin.getPlayerChannels().remove(name); 39 | plugin.getPlayerDisplays().remove(name); 40 | super.channelInactive(ctx); 41 | } 42 | } 43 | -------------------------------------------------------------------------------- /src/main/java/com/jnngl/framedimage/listener/HandshakeListener.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2022 JNNGL 3 | * 4 | * This program is free software: you can redistribute it and/or modify 5 | * it under the terms of the GNU General Public License as published by 6 | * the Free Software Foundation, either version 3 of the License, or 7 | * (at your option) any later version. 8 | * 9 | * This program is distributed in the hope that it will be useful, 10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 | * GNU General Public License for more details. 13 | * 14 | * You should have received a copy of the GNU General Public License 15 | * along with this program. If not, see . 16 | */ 17 | 18 | package com.jnngl.framedimage.listener; 19 | 20 | import com.jnngl.framedimage.FramedImage; 21 | import io.netty.buffer.ByteBuf; 22 | import io.netty.channel.ChannelHandlerContext; 23 | import io.netty.channel.ChannelInboundHandlerAdapter; 24 | import com.jnngl.framedimage.protocol.ProtocolUtils; 25 | import org.jetbrains.annotations.NotNull; 26 | 27 | public class HandshakeListener extends ChannelInboundHandlerAdapter { 28 | 29 | private final FramedImage plugin; 30 | 31 | public HandshakeListener(FramedImage plugin) { 32 | this.plugin = plugin; 33 | } 34 | 35 | @Override 36 | public void channelRead(@NotNull ChannelHandlerContext ctx, @NotNull Object msg) throws Exception { 37 | if (msg instanceof ByteBuf buf) { 38 | int ridx = buf.readerIndex(); 39 | 40 | if (ProtocolUtils.readVarInt(buf) == 0) { 41 | int protocol = ProtocolUtils.readVarInt(buf); 42 | LoginListener loginListener = new LoginListener(plugin, protocol); 43 | 44 | ProtocolUtils.readString(buf); 45 | buf.readShort(); 46 | 47 | if (ProtocolUtils.readVarInt(buf) == 2) { 48 | ctx.pipeline().addBefore("framedimage:handshake", "framedimage:login", loginListener); 49 | } 50 | 51 | ctx.pipeline().remove(this); 52 | } 53 | 54 | buf.readerIndex(ridx); 55 | } 56 | 57 | super.channelRead(ctx, msg); 58 | } 59 | } 60 | -------------------------------------------------------------------------------- /src/main/java/com/jnngl/framedimage/listener/LoginListener.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2022 JNNGL 3 | * 4 | * This program is free software: you can redistribute it and/or modify 5 | * it under the terms of the GNU General Public License as published by 6 | * the Free Software Foundation, either version 3 of the License, or 7 | * (at your option) any later version. 8 | * 9 | * This program is distributed in the hope that it will be useful, 10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 | * GNU General Public License for more details. 13 | * 14 | * You should have received a copy of the GNU General Public License 15 | * along with this program. If not, see . 16 | */ 17 | 18 | package com.jnngl.framedimage.listener; 19 | 20 | import com.jnngl.framedimage.FramedImage; 21 | import io.netty.buffer.ByteBuf; 22 | import io.netty.channel.ChannelHandlerContext; 23 | import io.netty.channel.ChannelInboundHandlerAdapter; 24 | import com.jnngl.framedimage.protocol.MinecraftVersion; 25 | import com.jnngl.framedimage.protocol.PacketEncoder; 26 | import com.jnngl.framedimage.protocol.ProtocolUtils; 27 | import org.jetbrains.annotations.NotNull; 28 | 29 | public class LoginListener extends ChannelInboundHandlerAdapter { 30 | 31 | private final FramedImage plugin; 32 | private final int protocol; 33 | 34 | public LoginListener(FramedImage plugin, int protocol) { 35 | this.plugin = plugin; 36 | this.protocol = protocol; 37 | } 38 | 39 | @Override 40 | public void channelRead(@NotNull ChannelHandlerContext ctx, @NotNull Object msg) throws Exception { 41 | if (msg instanceof ByteBuf buf) { 42 | int ridx = buf.readerIndex(); 43 | 44 | if (ProtocolUtils.readVarInt(buf) == 0) { 45 | String name = ProtocolUtils.readString(buf); 46 | MinecraftVersion version = MinecraftVersion.fromPVN(protocol); 47 | 48 | plugin.getLoggingPlayers().add(name); 49 | plugin.getPlayerChannels().put(name, ctx.channel()); 50 | 51 | plugin.getLogger().info(name + " has connected with protocol " + protocol + " (" + version.getVersionName() + ")"); 52 | 53 | ctx.pipeline().addAfter("prepender", "framedimage:encoder", new PacketEncoder(version)); 54 | ctx.pipeline().addFirst("framedimage:disconnect", new DisconnectHandler(plugin, name)); 55 | 56 | ctx.pipeline().remove(this); 57 | } 58 | 59 | buf.readerIndex(ridx); 60 | } 61 | 62 | super.channelRead(ctx, msg); 63 | } 64 | } 65 | -------------------------------------------------------------------------------- /src/main/java/com/jnngl/framedimage/listener/MoveListener.java: -------------------------------------------------------------------------------- 1 | package com.jnngl.framedimage.listener; 2 | 3 | import com.jnngl.framedimage.FramedImage; 4 | import com.jnngl.framedimage.util.SectionUtil; 5 | import org.bukkit.event.EventHandler; 6 | import org.bukkit.event.Listener; 7 | import org.bukkit.event.player.PlayerMoveEvent; 8 | import org.bukkit.event.player.PlayerTeleportEvent; 9 | 10 | public class MoveListener implements Listener { 11 | 12 | private final FramedImage plugin; 13 | 14 | public MoveListener(FramedImage plugin) { 15 | this.plugin = plugin; 16 | } 17 | 18 | @EventHandler 19 | public void onMove(PlayerMoveEvent event) { 20 | if (event.getFrom().getChunk() == event.getTo().getChunk()) { 21 | return; 22 | } 23 | 24 | long fromSection = SectionUtil.getSectionIndex(event.getFrom()); 25 | long toSection = SectionUtil.getSectionIndex(event.getTo()); 26 | 27 | if (fromSection == toSection && event.getFrom().getWorld() == event.getTo().getWorld()) { 28 | return; 29 | } 30 | 31 | plugin.updateSection(event.getPlayer(), event.getTo().getWorld().getName(), toSection); 32 | } 33 | 34 | @EventHandler 35 | public void onTeleport(PlayerTeleportEvent event) { 36 | onMove(event); 37 | } 38 | } 39 | -------------------------------------------------------------------------------- /src/main/java/com/jnngl/framedimage/listener/PlayerListener.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2022 JNNGL 3 | * 4 | * This program is free software: you can redistribute it and/or modify 5 | * it under the terms of the GNU General Public License as published by 6 | * the Free Software Foundation, either version 3 of the License, or 7 | * (at your option) any later version. 8 | * 9 | * This program is distributed in the hope that it will be useful, 10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 | * GNU General Public License for more details. 13 | * 14 | * You should have received a copy of the GNU General Public License 15 | * along with this program. If not, see . 16 | */ 17 | 18 | package com.jnngl.framedimage.listener; 19 | 20 | import com.jnngl.framedimage.FramedImage; 21 | import io.netty.channel.Channel; 22 | import io.netty.channel.ChannelHandler; 23 | import org.bukkit.entity.Player; 24 | import org.bukkit.event.EventHandler; 25 | import org.bukkit.event.Listener; 26 | import org.bukkit.event.player.PlayerChangedWorldEvent; 27 | import org.bukkit.event.player.PlayerJoinEvent; 28 | import org.bukkit.event.player.PlayerRespawnEvent; 29 | 30 | public class PlayerListener implements Listener { 31 | 32 | private final FramedImage plugin; 33 | 34 | public PlayerListener(FramedImage plugin) { 35 | this.plugin = plugin; 36 | } 37 | 38 | @EventHandler 39 | public void onJoin(PlayerJoinEvent event) { 40 | plugin.getScheduler().runDelayed(plugin, () -> { 41 | Player player = event.getPlayer(); 42 | plugin.getLoggingPlayers().remove(player.getName()); 43 | Channel channel = plugin.getPlayerChannel(player); 44 | 45 | if (channel != null) { 46 | if (channel.pipeline().get("compress") != null) { 47 | ChannelHandler handler = channel.pipeline().get("framedimage:encoder"); 48 | channel.pipeline().remove(handler); 49 | channel.pipeline().addAfter("compress", "framedimage:encoder", handler); 50 | } 51 | 52 | plugin.spawn(player); 53 | } 54 | }, 10L); 55 | } 56 | 57 | @EventHandler 58 | public void onRespawn(PlayerRespawnEvent event) { 59 | Player player = event.getPlayer(); 60 | plugin.getPlayerDisplays().remove(player.getName()); 61 | if (player.getLocation().getWorld() == event.getRespawnLocation().getWorld()) { 62 | plugin.getScheduler().runDelayed(plugin, () -> plugin.spawn(player), 10L); 63 | } 64 | } 65 | 66 | @EventHandler 67 | public void onChangeDimension(PlayerChangedWorldEvent event) { 68 | Player player = event.getPlayer(); 69 | plugin.getPlayerDisplays().remove(player.getName()); 70 | plugin.spawn(player); 71 | } 72 | } 73 | -------------------------------------------------------------------------------- /src/main/java/com/jnngl/framedimage/protocol/IdMapping.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2022 JNNGL 3 | * 4 | * This program is free software: you can redistribute it and/or modify 5 | * it under the terms of the GNU General Public License as published by 6 | * the Free Software Foundation, either version 3 of the License, or 7 | * (at your option) any later version. 8 | * 9 | * This program is distributed in the hope that it will be useful, 10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 | * GNU General Public License for more details. 13 | * 14 | * You should have received a copy of the GNU General Public License 15 | * along with this program. If not, see . 16 | */ 17 | 18 | package com.jnngl.framedimage.protocol; 19 | 20 | import java.util.HashMap; 21 | import java.util.Map; 22 | 23 | public class IdMapping { 24 | 25 | private final int[] ids = new int[MinecraftVersion.values().length]; 26 | private Map tempIDs = new HashMap<>(); 27 | 28 | public IdMapping add(MinecraftVersion version, int id) { 29 | tempIDs.put(version, id); 30 | return this; 31 | } 32 | 33 | public IdMapping build() { 34 | int lastID = -1; 35 | for (MinecraftVersion version : MinecraftVersion.values()) { 36 | ids[version.ordinal()] = lastID = tempIDs.getOrDefault(version, lastID); 37 | } 38 | 39 | tempIDs = null; 40 | return this; 41 | } 42 | 43 | public int getID(MinecraftVersion version) { 44 | return ids[version.ordinal()]; 45 | } 46 | } 47 | -------------------------------------------------------------------------------- /src/main/java/com/jnngl/framedimage/protocol/MinecraftVersion.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2022 JNNGL 3 | * 4 | * This program is free software: you can redistribute it and/or modify 5 | * it under the terms of the GNU General Public License as published by 6 | * the Free Software Foundation, either version 3 of the License, or 7 | * (at your option) any later version. 8 | * 9 | * This program is distributed in the hope that it will be useful, 10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 | * GNU General Public License for more details. 13 | * 14 | * You should have received a copy of the GNU General Public License 15 | * along with this program. If not, see . 16 | */ 17 | 18 | package com.jnngl.framedimage.protocol; 19 | 20 | import java.util.HashMap; 21 | import java.util.Map; 22 | 23 | public enum MinecraftVersion { 24 | UNDEFINED(0), 25 | MINECRAFT_1_7_2(4), 26 | MINECRAFT_1_7_6(5), 27 | MINECRAFT_1_8(47), 28 | MINECRAFT_1_9(107), 29 | MINECRAFT_1_9_1(108), 30 | MINECRAFT_1_9_2(109), 31 | MINECRAFT_1_9_4(110), 32 | MINECRAFT_1_10(210), 33 | MINECRAFT_1_11(315), 34 | MINECRAFT_1_11_1(316), 35 | MINECRAFT_1_12(335), 36 | MINECRAFT_1_12_1(338), 37 | MINECRAFT_1_12_2(340), 38 | MINECRAFT_1_13(393), 39 | MINECRAFT_1_13_1(401), 40 | MINECRAFT_1_13_2(404), 41 | MINECRAFT_1_14(477), 42 | MINECRAFT_1_14_1(480), 43 | MINECRAFT_1_14_2(485), 44 | MINECRAFT_1_14_3(490), 45 | MINECRAFT_1_14_4(498), 46 | MINECRAFT_1_15(573), 47 | MINECRAFT_1_15_1(575), 48 | MINECRAFT_1_15_2(578), 49 | MINECRAFT_1_16(735), 50 | MINECRAFT_1_16_1(736), 51 | MINECRAFT_1_16_2(751), 52 | MINECRAFT_1_16_3(753), 53 | MINECRAFT_1_16_4(754), 54 | MINECRAFT_1_17(755), 55 | MINECRAFT_1_17_1(756), 56 | MINECRAFT_1_18(757), 57 | MINECRAFT_1_18_2(758), 58 | MINECRAFT_1_19(759), 59 | MINECRAFT_1_19_1(760), 60 | MINECRAFT_1_19_3(761), 61 | MINECRAFT_1_19_4(762), 62 | MINECRAFT_1_20(763), 63 | MINECRAFT_1_20_2(764), 64 | MINECRAFT_1_20_3(765), 65 | MINECRAFT_1_20_5(766), 66 | MINECRAFT_1_21(767); 67 | 68 | public static final MinecraftVersion MINIMUM_VERSION = MINECRAFT_1_7_2; 69 | public static final MinecraftVersion MAXIMUM_VERSION = values()[values().length - 1]; 70 | 71 | private static final Map PVN_MAP = new HashMap<>(); 72 | 73 | static { 74 | int pvn = MINIMUM_VERSION.getProtocolVersion(); 75 | MinecraftVersion currentVersion = UNDEFINED; 76 | 77 | while (currentVersion != MAXIMUM_VERSION) { 78 | currentVersion = currentVersion.next(); 79 | for (; pvn <= currentVersion.getProtocolVersion(); pvn++) { 80 | PVN_MAP.put(pvn, currentVersion); 81 | } 82 | } 83 | } 84 | 85 | public static MinecraftVersion fromPVN(int pvn) { 86 | return PVN_MAP.getOrDefault(pvn, UNDEFINED); 87 | } 88 | 89 | final int protocolVersion; 90 | 91 | MinecraftVersion(int protocolVersion) { 92 | this.protocolVersion = protocolVersion; 93 | } 94 | 95 | public int getProtocolVersion() { 96 | return protocolVersion; 97 | } 98 | 99 | public MinecraftVersion next() { 100 | if (this == MAXIMUM_VERSION) { 101 | return MAXIMUM_VERSION; 102 | } else { 103 | return values()[ordinal() + 1]; 104 | } 105 | } 106 | 107 | public MinecraftVersion previous() { 108 | if (this == MINIMUM_VERSION) { 109 | return MINIMUM_VERSION; 110 | } else { 111 | return values()[ordinal() - 1]; 112 | } 113 | } 114 | 115 | public String getVersionName() { 116 | return toString().substring(10).replace('_', '.'); 117 | } 118 | } 119 | -------------------------------------------------------------------------------- /src/main/java/com/jnngl/framedimage/protocol/Packet.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2022 JNNGL 3 | * 4 | * This program is free software: you can redistribute it and/or modify 5 | * it under the terms of the GNU General Public License as published by 6 | * the Free Software Foundation, either version 3 of the License, or 7 | * (at your option) any later version. 8 | * 9 | * This program is distributed in the hope that it will be useful, 10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 | * GNU General Public License for more details. 13 | * 14 | * You should have received a copy of the GNU General Public License 15 | * along with this program. If not, see . 16 | */ 17 | 18 | package com.jnngl.framedimage.protocol; 19 | 20 | import io.netty.buffer.ByteBuf; 21 | 22 | public interface Packet { 23 | 24 | void encode(ByteBuf buf, MinecraftVersion version); 25 | 26 | int getID(MinecraftVersion version); 27 | } 28 | -------------------------------------------------------------------------------- /src/main/java/com/jnngl/framedimage/protocol/PacketEncoder.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2022 JNNGL 3 | * 4 | * This program is free software: you can redistribute it and/or modify 5 | * it under the terms of the GNU General Public License as published by 6 | * the Free Software Foundation, either version 3 of the License, or 7 | * (at your option) any later version. 8 | * 9 | * This program is distributed in the hope that it will be useful, 10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 | * GNU General Public License for more details. 13 | * 14 | * You should have received a copy of the GNU General Public License 15 | * along with this program. If not, see . 16 | */ 17 | 18 | package com.jnngl.framedimage.protocol; 19 | 20 | import io.netty.buffer.ByteBuf; 21 | import io.netty.channel.ChannelHandler; 22 | import io.netty.channel.ChannelHandlerContext; 23 | import io.netty.handler.codec.MessageToByteEncoder; 24 | 25 | @ChannelHandler.Sharable 26 | public class PacketEncoder extends MessageToByteEncoder { 27 | 28 | private final MinecraftVersion version; 29 | 30 | public PacketEncoder(MinecraftVersion version) { 31 | this.version = version; 32 | } 33 | 34 | @Override 35 | protected void encode(ChannelHandlerContext ctx, Packet msg, ByteBuf out) throws Exception { 36 | ProtocolUtils.writeVarInt(out, msg.getID(version)); 37 | msg.encode(out, version); 38 | } 39 | } 40 | -------------------------------------------------------------------------------- /src/main/java/com/jnngl/framedimage/protocol/ProtocolUtils.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2022 JNNGL 3 | * 4 | * This program is free software: you can redistribute it and/or modify 5 | * it under the terms of the GNU General Public License as published by 6 | * the Free Software Foundation, either version 3 of the License, or 7 | * (at your option) any later version. 8 | * 9 | * This program is distributed in the hope that it will be useful, 10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 | * GNU General Public License for more details. 13 | * 14 | * You should have received a copy of the GNU General Public License 15 | * along with this program. If not, see . 16 | */ 17 | 18 | package com.jnngl.framedimage.protocol; 19 | 20 | import io.netty.buffer.ByteBuf; 21 | 22 | import java.nio.charset.StandardCharsets; 23 | import java.util.UUID; 24 | 25 | public class ProtocolUtils { 26 | 27 | private static final int SEGMENT_BITS = 0x7F; 28 | private static final int CONTINUE_BIT = 0x80; 29 | 30 | public static String readString(ByteBuf buf) { 31 | byte[] bytes = new byte[readVarInt(buf)]; 32 | buf.readBytes(bytes); 33 | return new String(bytes, StandardCharsets.UTF_8); 34 | } 35 | 36 | public static int readVarInt(ByteBuf buf) { 37 | int value = 0; 38 | int position = 0; 39 | byte currentByte; 40 | 41 | while (true) { 42 | currentByte = buf.readByte(); 43 | value |= (currentByte & SEGMENT_BITS) << position; 44 | 45 | if ((currentByte & CONTINUE_BIT) == 0) break; 46 | 47 | position += 7; 48 | 49 | if (position >= 32) throw new RuntimeException("VarInt is too big"); 50 | } 51 | 52 | return value; 53 | } 54 | 55 | public static void writeVarInt(ByteBuf buf, int value) { 56 | while (true) { 57 | if ((value & ~SEGMENT_BITS) == 0) { 58 | buf.writeByte(value); 59 | return; 60 | } 61 | 62 | buf.writeByte((value & SEGMENT_BITS) | CONTINUE_BIT); 63 | value >>>= 7; 64 | } 65 | } 66 | 67 | public static void writeUUID(ByteBuf buf, UUID uuid) { 68 | buf.writeLong(uuid.getMostSignificantBits()); 69 | buf.writeLong(uuid.getLeastSignificantBits()); 70 | } 71 | } 72 | -------------------------------------------------------------------------------- /src/main/java/com/jnngl/framedimage/protocol/data/EntityMetadata.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2022 JNNGL 3 | * 4 | * This program is free software: you can redistribute it and/or modify 5 | * it under the terms of the GNU General Public License as published by 6 | * the Free Software Foundation, either version 3 of the License, or 7 | * (at your option) any later version. 8 | * 9 | * This program is distributed in the hope that it will be useful, 10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 | * GNU General Public License for more details. 13 | * 14 | * You should have received a copy of the GNU General Public License 15 | * along with this program. If not, see . 16 | */ 17 | 18 | package com.jnngl.framedimage.protocol.data; 19 | 20 | import com.jnngl.framedimage.protocol.data.nbt.Nbt; 21 | import com.jnngl.framedimage.protocol.data.nbt.NbtTag; 22 | import io.netty.buffer.ByteBuf; 23 | import com.jnngl.framedimage.protocol.MinecraftVersion; 24 | import com.jnngl.framedimage.protocol.ProtocolUtils; 25 | 26 | import java.util.Map; 27 | import java.util.function.Function; 28 | 29 | public class EntityMetadata { 30 | 31 | public interface Entry { 32 | 33 | void encode(ByteBuf buf, MinecraftVersion protocolVersion); 34 | 35 | int getType(MinecraftVersion protocolVersion); 36 | } 37 | 38 | public static class SlotEntry implements Entry { 39 | 40 | private final boolean present; 41 | private final Function item; 42 | private final int count; 43 | private final int data; 44 | private final NbtTag nbt; 45 | 46 | public SlotEntry(boolean present, Function item, int count, int data, NbtTag nbt) { 47 | this.present = present; 48 | this.item = item; 49 | this.count = count; 50 | this.data = data; 51 | this.nbt = nbt; 52 | } 53 | 54 | public SlotEntry(Function item, int count, int data, NbtTag nbt) { 55 | this(true, item, count, data, nbt); 56 | } 57 | 58 | public SlotEntry() { 59 | this(false, null, 0, 0, null); 60 | } 61 | 62 | @Override 63 | public void encode(ByteBuf buf, MinecraftVersion protocolVersion) { 64 | if (protocolVersion.compareTo(MinecraftVersion.MINECRAFT_1_20_5) >= 0) { 65 | ProtocolUtils.writeVarInt(buf, 1); 66 | ProtocolUtils.writeVarInt(buf, item.apply(protocolVersion)); 67 | ProtocolUtils.writeVarInt(buf, 1); 68 | ProtocolUtils.writeVarInt(buf, 0); 69 | ProtocolUtils.writeVarInt(buf, 26); 70 | ProtocolUtils.writeVarInt(buf, this.data); 71 | return; 72 | } 73 | 74 | if (protocolVersion.compareTo(MinecraftVersion.MINECRAFT_1_13_2) >= 0) { 75 | buf.writeBoolean(present); 76 | } 77 | 78 | if (!present && protocolVersion.compareTo(MinecraftVersion.MINECRAFT_1_13_2) < 0) { 79 | buf.writeShort(-1); 80 | } 81 | 82 | if (present) { 83 | if (protocolVersion.compareTo(MinecraftVersion.MINECRAFT_1_13_2) < 0) { 84 | buf.writeShort(item.apply(protocolVersion)); 85 | } else { 86 | ProtocolUtils.writeVarInt(buf, item.apply(protocolVersion)); 87 | } 88 | buf.writeByte(count); 89 | if (protocolVersion.compareTo(MinecraftVersion.MINECRAFT_1_13) < 0) { 90 | buf.writeShort(data & ~Short.MIN_VALUE); 91 | } 92 | 93 | if (nbt == null) { 94 | if (protocolVersion.compareTo(MinecraftVersion.MINECRAFT_1_8) < 0) { 95 | buf.writeShort(-1); 96 | } else { 97 | buf.writeByte(0); 98 | } 99 | } else { 100 | Nbt.write(buf, nbt, protocolVersion.compareTo(MinecraftVersion.MINECRAFT_1_20_2) >= 0); 101 | } 102 | } 103 | } 104 | 105 | @Override 106 | public int getType(MinecraftVersion protocolVersion) { 107 | if (protocolVersion.compareTo(MinecraftVersion.MINECRAFT_1_12_2) <= 0) { 108 | return 5; 109 | } else if (protocolVersion.compareTo(MinecraftVersion.MINECRAFT_1_19_1) <= 0) { 110 | return 6; 111 | } else { 112 | return 7; 113 | } 114 | } 115 | } 116 | 117 | private final Map entries; 118 | 119 | public EntityMetadata(Map entries) { 120 | this.entries = entries; 121 | } 122 | 123 | public void encode(ByteBuf buf, MinecraftVersion protocolVersion) { 124 | if (protocolVersion.compareTo(MinecraftVersion.MINECRAFT_1_8) <= 0) { 125 | entries.forEach((index, value) -> { 126 | buf.writeByte((index & 0x1F) | (value.getType(protocolVersion) << 5)); 127 | value.encode(buf, protocolVersion); 128 | }); 129 | buf.writeByte(0x7F); 130 | } else { 131 | entries.forEach((index, value) -> { 132 | buf.writeByte(index); 133 | ProtocolUtils.writeVarInt(buf, value.getType(protocolVersion)); 134 | value.encode(buf, protocolVersion); 135 | }); 136 | buf.writeByte(0xFF); 137 | } 138 | } 139 | } 140 | -------------------------------------------------------------------------------- /src/main/java/com/jnngl/framedimage/protocol/data/Facing.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2022 JNNGL 3 | * 4 | * This program is free software: you can redistribute it and/or modify 5 | * it under the terms of the GNU General Public License as published by 6 | * the Free Software Foundation, either version 3 of the License, or 7 | * (at your option) any later version. 8 | * 9 | * This program is distributed in the hope that it will be useful, 10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 | * GNU General Public License for more details. 13 | * 14 | * You should have received a copy of the GNU General Public License 15 | * along with this program. If not, see . 16 | */ 17 | 18 | package com.jnngl.framedimage.protocol.data; 19 | 20 | import com.jnngl.framedimage.protocol.MinecraftVersion; 21 | 22 | public enum Facing { 23 | DOWN(0, 2, 0), 24 | UP(0, 2, 0), 25 | NORTH(2, 2, 180), 26 | SOUTH(3, 0, 0), 27 | WEST(4, 1, 90), 28 | EAST(5, 3, 270); 29 | 30 | final int modernID; 31 | final int legacyID; 32 | final float yaw; 33 | 34 | Facing(int modernID, int legacyID, float yaw) { 35 | this.modernID = modernID; 36 | this.legacyID = legacyID; 37 | this.yaw = yaw; 38 | } 39 | 40 | public int getModernID() { 41 | return modernID; 42 | } 43 | 44 | public int getLegacyID() { 45 | return legacyID; 46 | } 47 | 48 | public float getYaw() { 49 | return yaw; 50 | } 51 | 52 | public int getID(MinecraftVersion version) { 53 | if (version.compareTo(MinecraftVersion.MINECRAFT_1_13) >= 0) { 54 | return modernID; 55 | } else { 56 | return legacyID; 57 | } 58 | } 59 | } 60 | -------------------------------------------------------------------------------- /src/main/java/com/jnngl/framedimage/protocol/data/FilledMap.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2022 JNNGL 3 | * 4 | * This program is free software: you can redistribute it and/or modify 5 | * it under the terms of the GNU General Public License as published by 6 | * the Free Software Foundation, either version 3 of the License, or 7 | * (at your option) any later version. 8 | * 9 | * This program is distributed in the hope that it will be useful, 10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 | * GNU General Public License for more details. 13 | * 14 | * You should have received a copy of the GNU General Public License 15 | * along with this program. If not, see . 16 | */ 17 | 18 | package com.jnngl.framedimage.protocol.data; 19 | 20 | import com.jnngl.framedimage.protocol.IdMapping; 21 | import com.jnngl.framedimage.protocol.MinecraftVersion; 22 | 23 | public class FilledMap { 24 | 25 | private static final IdMapping ID_MAPPING = 26 | new IdMapping() 27 | .add(MinecraftVersion.MINIMUM_VERSION, 358) 28 | .add(MinecraftVersion.MINECRAFT_1_13, 608) 29 | .add(MinecraftVersion.MINECRAFT_1_13_2, 613) 30 | .add(MinecraftVersion.MINECRAFT_1_14, 671) 31 | .add(MinecraftVersion.MINECRAFT_1_16, 733) 32 | .add(MinecraftVersion.MINECRAFT_1_17, 847) 33 | .add(MinecraftVersion.MINECRAFT_1_19, 886) 34 | .add(MinecraftVersion.MINECRAFT_1_19_3, 914) 35 | .add(MinecraftVersion.MINECRAFT_1_19_4, 937) 36 | .add(MinecraftVersion.MINECRAFT_1_20, 941) 37 | .add(MinecraftVersion.MINECRAFT_1_20_3, 979) 38 | .add(MinecraftVersion.MINECRAFT_1_20_5, 982) 39 | .build(); 40 | 41 | public static int getID(MinecraftVersion version) { 42 | return ID_MAPPING.getID(version); 43 | } 44 | 45 | } 46 | -------------------------------------------------------------------------------- /src/main/java/com/jnngl/framedimage/protocol/data/ItemFrame.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2022 JNNGL 3 | * 4 | * This program is free software: you can redistribute it and/or modify 5 | * it under the terms of the GNU General Public License as published by 6 | * the Free Software Foundation, either version 3 of the License, or 7 | * (at your option) any later version. 8 | * 9 | * This program is distributed in the hope that it will be useful, 10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 | * GNU General Public License for more details. 13 | * 14 | * You should have received a copy of the GNU General Public License 15 | * along with this program. If not, see . 16 | */ 17 | 18 | package com.jnngl.framedimage.protocol.data; 19 | 20 | import com.jnngl.framedimage.protocol.data.nbt.TagCompound; 21 | import com.jnngl.framedimage.protocol.data.nbt.TagInt; 22 | import com.jnngl.framedimage.protocol.IdMapping; 23 | import com.jnngl.framedimage.protocol.MinecraftVersion; 24 | 25 | import java.util.Collections; 26 | import java.util.Map; 27 | 28 | public class ItemFrame { 29 | 30 | private static final IdMapping ID_MAPPING = 31 | new IdMapping() 32 | .add(MinecraftVersion.MINIMUM_VERSION, 71) 33 | .add(MinecraftVersion.MINECRAFT_1_14, 35) 34 | .add(MinecraftVersion.MINECRAFT_1_15, 36) 35 | .add(MinecraftVersion.MINECRAFT_1_16, 38) 36 | .add(MinecraftVersion.MINECRAFT_1_17, 42) 37 | .add(MinecraftVersion.MINECRAFT_1_19, 45) 38 | .add(MinecraftVersion.MINECRAFT_1_19_3, 46) 39 | .add(MinecraftVersion.MINECRAFT_1_19_4, 56) 40 | .add(MinecraftVersion.MINECRAFT_1_20_3, 57) 41 | .add(MinecraftVersion.MINECRAFT_1_20_5, 60) 42 | .build(); 43 | 44 | private static final IdMapping GLOWING_ID_MAPPING = 45 | new IdMapping() 46 | .add(MinecraftVersion.MINIMUM_VERSION, 71) 47 | .add(MinecraftVersion.MINECRAFT_1_14, 35) 48 | .add(MinecraftVersion.MINECRAFT_1_15, 36) 49 | .add(MinecraftVersion.MINECRAFT_1_16, 38) 50 | .add(MinecraftVersion.MINECRAFT_1_17, 32) 51 | .add(MinecraftVersion.MINECRAFT_1_19, 35) 52 | .add(MinecraftVersion.MINECRAFT_1_19_3, 36) 53 | .add(MinecraftVersion.MINECRAFT_1_19_4, 43) 54 | .add(MinecraftVersion.MINECRAFT_1_20_3, 44) 55 | .add(MinecraftVersion.MINECRAFT_1_20_5, 47) 56 | .build(); 57 | 58 | private static final IdMapping METADATA_INDEX_MAPPING = 59 | new IdMapping() 60 | .add(MinecraftVersion.MINIMUM_VERSION, 2) 61 | .add(MinecraftVersion.MINECRAFT_1_8, 8) 62 | .add(MinecraftVersion.MINECRAFT_1_9, 5) 63 | .add(MinecraftVersion.MINECRAFT_1_10, 6) 64 | .add(MinecraftVersion.MINECRAFT_1_14, 7) 65 | .add(MinecraftVersion.MINECRAFT_1_17, 8) 66 | .build(); 67 | 68 | public static int getID(MinecraftVersion protocolVersion) { 69 | return ID_MAPPING.getID(protocolVersion); 70 | } 71 | 72 | public static int getGlowingID(MinecraftVersion protocolVersion) { 73 | return GLOWING_ID_MAPPING.getID(protocolVersion); 74 | } 75 | 76 | public static byte getMetadataIndex(MinecraftVersion protocolVersion) { 77 | return (byte) METADATA_INDEX_MAPPING.getID(protocolVersion); 78 | } 79 | 80 | public static EntityMetadata createMapMetadata(MinecraftVersion protocolVersion, int mapId) { 81 | if (protocolVersion.compareTo(MinecraftVersion.MINECRAFT_1_12_2) <= 0) { 82 | return new EntityMetadata( 83 | Map.of( 84 | getMetadataIndex(protocolVersion), 85 | new EntityMetadata.SlotEntry(FilledMap::getID, 1, mapId, null) 86 | ) 87 | ); 88 | } else { 89 | return new EntityMetadata( 90 | Map.of( 91 | getMetadataIndex(protocolVersion), 92 | new EntityMetadata.SlotEntry(FilledMap::getID, 1, mapId, 93 | new TagCompound("", 94 | Collections.singleton(new TagInt("map", mapId)) 95 | ) 96 | ) 97 | ) 98 | ); 99 | } 100 | } 101 | } 102 | -------------------------------------------------------------------------------- /src/main/java/com/jnngl/framedimage/protocol/data/nbt/Nbt.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2022 JNNGL 3 | * 4 | * This program is free software: you can redistribute it and/or modify 5 | * it under the terms of the GNU General Public License as published by 6 | * the Free Software Foundation, either version 3 of the License, or 7 | * (at your option) any later version. 8 | * 9 | * This program is distributed in the hope that it will be useful, 10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 | * GNU General Public License for more details. 13 | * 14 | * You should have received a copy of the GNU General Public License 15 | * along with this program. If not, see . 16 | */ 17 | 18 | package com.jnngl.framedimage.protocol.data.nbt; 19 | 20 | import io.netty.buffer.ByteBuf; 21 | 22 | import java.nio.charset.StandardCharsets; 23 | 24 | public class Nbt { 25 | 26 | public static void write(ByteBuf buf, NbtTag nbtTag, boolean rootTag) { 27 | if (nbtTag == null) { 28 | buf.writeByte(0); 29 | return; 30 | } 31 | 32 | buf.writeByte(nbtTag.getTypeID()); 33 | 34 | if (!rootTag) { 35 | byte[] nameBytes = nbtTag.getName().getBytes(StandardCharsets.UTF_8); 36 | buf.writeShort(nameBytes.length); 37 | buf.writeBytes(nameBytes); 38 | } 39 | 40 | nbtTag.encode(buf); 41 | } 42 | } 43 | -------------------------------------------------------------------------------- /src/main/java/com/jnngl/framedimage/protocol/data/nbt/NbtTag.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2022 JNNGL 3 | * 4 | * This program is free software: you can redistribute it and/or modify 5 | * it under the terms of the GNU General Public License as published by 6 | * the Free Software Foundation, either version 3 of the License, or 7 | * (at your option) any later version. 8 | * 9 | * This program is distributed in the hope that it will be useful, 10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 | * GNU General Public License for more details. 13 | * 14 | * You should have received a copy of the GNU General Public License 15 | * along with this program. If not, see . 16 | */ 17 | 18 | package com.jnngl.framedimage.protocol.data.nbt; 19 | 20 | import io.netty.buffer.ByteBuf; 21 | 22 | public abstract class NbtTag { 23 | 24 | private String name; 25 | 26 | public NbtTag(String name) { 27 | this.name = name; 28 | } 29 | 30 | public abstract int getTypeID(); 31 | public abstract void encode(ByteBuf buf); 32 | 33 | public String getName() { 34 | return name; 35 | } 36 | 37 | public void setName(String name) { 38 | this.name = name; 39 | } 40 | } 41 | -------------------------------------------------------------------------------- /src/main/java/com/jnngl/framedimage/protocol/data/nbt/TagCompound.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2022 JNNGL 3 | * 4 | * This program is free software: you can redistribute it and/or modify 5 | * it under the terms of the GNU General Public License as published by 6 | * the Free Software Foundation, either version 3 of the License, or 7 | * (at your option) any later version. 8 | * 9 | * This program is distributed in the hope that it will be useful, 10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 | * GNU General Public License for more details. 13 | * 14 | * You should have received a copy of the GNU General Public License 15 | * along with this program. If not, see . 16 | */ 17 | 18 | package com.jnngl.framedimage.protocol.data.nbt; 19 | 20 | import io.netty.buffer.ByteBuf; 21 | 22 | import java.util.Iterator; 23 | import java.util.Map; 24 | import java.util.Set; 25 | import java.util.function.Function; 26 | import java.util.stream.Collectors; 27 | 28 | public class TagCompound extends NbtTag implements Iterable { 29 | 30 | private Map value; 31 | 32 | public TagCompound(String name, Set value) { 33 | super(name); 34 | setValue(value); 35 | } 36 | 37 | public TagCompound(String name) { 38 | super(name); 39 | } 40 | 41 | @Override 42 | public int getTypeID() { 43 | return 10; 44 | } 45 | 46 | @Override 47 | public void encode(ByteBuf buf) { 48 | if (value != null) { 49 | value.values().forEach(tag -> Nbt.write(buf, tag, false)); 50 | } 51 | 52 | buf.writeByte(0); 53 | } 54 | 55 | public Map getValue() { 56 | return value; 57 | } 58 | 59 | public NbtTag get(String key) { 60 | return value.get(key); 61 | } 62 | 63 | public void setValue(Set value) { 64 | this.value = value.stream().collect(Collectors.toMap(NbtTag::getName, Function.identity())); 65 | } 66 | 67 | public void set(NbtTag tag) { 68 | value.put(tag.getName(), tag); 69 | } 70 | 71 | @Override 72 | public String toString() { 73 | String[] values = value.values().stream().map(NbtTag::toString).toArray(String[]::new); 74 | String valueString = String.join("\n", values); 75 | String withName = "Compound('" + getName() + "'): \n" + valueString; 76 | return withName.replace("\n", "\n "); 77 | } 78 | 79 | @Override 80 | public Iterator iterator() { 81 | return value.values().iterator(); 82 | } 83 | } 84 | -------------------------------------------------------------------------------- /src/main/java/com/jnngl/framedimage/protocol/data/nbt/TagInt.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2022 JNNGL 3 | * 4 | * This program is free software: you can redistribute it and/or modify 5 | * it under the terms of the GNU General Public License as published by 6 | * the Free Software Foundation, either version 3 of the License, or 7 | * (at your option) any later version. 8 | * 9 | * This program is distributed in the hope that it will be useful, 10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 | * GNU General Public License for more details. 13 | * 14 | * You should have received a copy of the GNU General Public License 15 | * along with this program. If not, see . 16 | */ 17 | 18 | package com.jnngl.framedimage.protocol.data.nbt; 19 | 20 | import io.netty.buffer.ByteBuf; 21 | 22 | public class TagInt extends NbtTag { 23 | 24 | private int value; 25 | 26 | public TagInt(String name, int value) { 27 | super(name); 28 | this.value = value; 29 | } 30 | 31 | public TagInt(String name) { 32 | super(name); 33 | } 34 | 35 | @Override 36 | public int getTypeID() { 37 | return 3; 38 | } 39 | 40 | @Override 41 | public void encode(ByteBuf buf) { 42 | buf.writeInt(value); 43 | } 44 | 45 | public int getValue() { 46 | return value; 47 | } 48 | 49 | public void setValue(int value) { 50 | this.value = value; 51 | } 52 | 53 | @Override 54 | public String toString() { 55 | return "Int('" + getName() + "') -> " + value; 56 | } 57 | } 58 | -------------------------------------------------------------------------------- /src/main/java/com/jnngl/framedimage/protocol/packets/DestroyEntity.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2022 JNNGL 3 | * 4 | * This program is free software: you can redistribute it and/or modify 5 | * it under the terms of the GNU General Public License as published by 6 | * the Free Software Foundation, either version 3 of the License, or 7 | * (at your option) any later version. 8 | * 9 | * This program is distributed in the hope that it will be useful, 10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 | * GNU General Public License for more details. 13 | * 14 | * You should have received a copy of the GNU General Public License 15 | * along with this program. If not, see . 16 | */ 17 | 18 | package com.jnngl.framedimage.protocol.packets; 19 | 20 | import io.netty.buffer.ByteBuf; 21 | import com.jnngl.framedimage.protocol.MinecraftVersion; 22 | import com.jnngl.framedimage.protocol.Packet; 23 | import com.jnngl.framedimage.protocol.IdMapping; 24 | import com.jnngl.framedimage.protocol.ProtocolUtils; 25 | 26 | public class DestroyEntity implements Packet { 27 | 28 | private static final IdMapping ID_MAPPING = 29 | new IdMapping() 30 | .add(MinecraftVersion.MINIMUM_VERSION, 0x13) 31 | .add(MinecraftVersion.MINECRAFT_1_9, 0x30) 32 | .add(MinecraftVersion.MINECRAFT_1_12, 0x31) 33 | .add(MinecraftVersion.MINECRAFT_1_12_1, 0x32) 34 | .add(MinecraftVersion.MINECRAFT_1_13, 0x35) 35 | .add(MinecraftVersion.MINECRAFT_1_14, 0x37) 36 | .add(MinecraftVersion.MINECRAFT_1_15, 0x38) 37 | .add(MinecraftVersion.MINECRAFT_1_16, 0x36) 38 | .add(MinecraftVersion.MINECRAFT_1_17, 0x3A) 39 | .add(MinecraftVersion.MINECRAFT_1_19, 0x38) 40 | .add(MinecraftVersion.MINECRAFT_1_19_1, 0x3B) 41 | .add(MinecraftVersion.MINECRAFT_1_19_3, 0x3A) 42 | .add(MinecraftVersion.MINECRAFT_1_19_4, 0x3E) 43 | .add(MinecraftVersion.MINECRAFT_1_20_2, 0x40) 44 | .add(MinecraftVersion.MINECRAFT_1_20_5, 0x42) 45 | .build(); 46 | 47 | private final int entity; 48 | 49 | public DestroyEntity(int entity) { 50 | this.entity = entity; 51 | } 52 | 53 | @Override 54 | public void encode(ByteBuf buf, MinecraftVersion version) { 55 | if (version.compareTo(MinecraftVersion.MINECRAFT_1_17) != 0) { 56 | buf.writeByte(1); 57 | } 58 | 59 | if (version.compareTo(MinecraftVersion.MINECRAFT_1_8) >= 0) { 60 | ProtocolUtils.writeVarInt(buf, entity); 61 | } else { 62 | buf.writeInt(entity); 63 | } 64 | } 65 | 66 | @Override 67 | public int getID(MinecraftVersion version) { 68 | return ID_MAPPING.getID(version); 69 | } 70 | } 71 | -------------------------------------------------------------------------------- /src/main/java/com/jnngl/framedimage/protocol/packets/MapData.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2022 JNNGL 3 | * 4 | * This program is free software: you can redistribute it and/or modify 5 | * it under the terms of the GNU General Public License as published by 6 | * the Free Software Foundation, either version 3 of the License, or 7 | * (at your option) any later version. 8 | * 9 | * This program is distributed in the hope that it will be useful, 10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 | * GNU General Public License for more details. 13 | * 14 | * You should have received a copy of the GNU General Public License 15 | * along with this program. If not, see . 16 | */ 17 | 18 | package com.jnngl.framedimage.protocol.packets; 19 | 20 | import com.jnngl.mapcolor.palette.Palette; 21 | import io.netty.buffer.ByteBuf; 22 | import com.jnngl.framedimage.protocol.MinecraftVersion; 23 | import com.jnngl.framedimage.protocol.Packet; 24 | import com.jnngl.framedimage.protocol.IdMapping; 25 | import com.jnngl.framedimage.protocol.ProtocolUtils; 26 | 27 | import java.util.function.Function; 28 | 29 | public class MapData implements Packet { 30 | 31 | private static final IdMapping ID_MAPPING = 32 | new IdMapping() 33 | .add(MinecraftVersion.MINIMUM_VERSION, 0x34) 34 | .add(MinecraftVersion.MINECRAFT_1_9, 0x24) 35 | .add(MinecraftVersion.MINECRAFT_1_13, 0x26) 36 | .add(MinecraftVersion.MINECRAFT_1_15, 0x27) 37 | .add(MinecraftVersion.MINECRAFT_1_16, 0x26) 38 | .add(MinecraftVersion.MINECRAFT_1_16_2, 0x25) 39 | .add(MinecraftVersion.MINECRAFT_1_17, 0x27) 40 | .add(MinecraftVersion.MINECRAFT_1_19, 0x24) 41 | .add(MinecraftVersion.MINECRAFT_1_19_1, 0x26) 42 | .add(MinecraftVersion.MINECRAFT_1_19_3, 0x25) 43 | .add(MinecraftVersion.MINECRAFT_1_19_4, 0x29) 44 | .add(MinecraftVersion.MINECRAFT_1_20_2, 0x2A) 45 | .add(MinecraftVersion.MINECRAFT_1_20_5, 0x2C) 46 | .build(); 47 | 48 | private final int mapID; 49 | private final byte scale; 50 | private final int columns; 51 | private final int rows; 52 | private final int posX; 53 | private final int posY; 54 | private final Function data; 55 | 56 | public MapData(int mapID, byte scale, int columns, int rows, int posX, int posY, Function data) { 57 | this.mapID = mapID; 58 | this.scale = scale; 59 | this.columns = columns; 60 | this.rows = rows; 61 | this.posX = posX; 62 | this.posY = posY; 63 | this.data = data; 64 | } 65 | 66 | public MapData(int mapID, byte scale, int posX, Function data) { 67 | this(mapID, scale, 128, 128, posX, 0, data); 68 | } 69 | 70 | public MapData(int mapID, byte scale, Function data) { 71 | this(mapID, scale, 0, data); 72 | } 73 | 74 | @Override 75 | public void encode(ByteBuf buf, MinecraftVersion version) { 76 | byte[] data = this.data.apply(Palette.getPaletteForProtocol(version.getProtocolVersion())); 77 | 78 | if (version.compareTo(MinecraftVersion.MINECRAFT_1_12_2) <= 0) { 79 | ProtocolUtils.writeVarInt(buf, mapID & ~Short.MIN_VALUE); 80 | } else { 81 | ProtocolUtils.writeVarInt(buf, mapID); 82 | } 83 | 84 | if (version.compareTo(MinecraftVersion.MINECRAFT_1_8) < 0) { 85 | buf.writeShort(data.length + 3); 86 | buf.writeByte(0); 87 | buf.writeByte(posX); 88 | buf.writeByte(posY); 89 | 90 | buf.writeBytes(data); 91 | } else { 92 | buf.writeByte(this.scale); 93 | 94 | if (version.compareTo(MinecraftVersion.MINECRAFT_1_9) >= 0 && version.compareTo(MinecraftVersion.MINECRAFT_1_17) < 0) { 95 | buf.writeBoolean(false); 96 | } 97 | 98 | if (version.compareTo(MinecraftVersion.MINECRAFT_1_14) >= 0) { 99 | buf.writeBoolean(false); 100 | } 101 | 102 | if (version.compareTo(MinecraftVersion.MINECRAFT_1_17) >= 0) { 103 | buf.writeBoolean(false); 104 | } else { 105 | ProtocolUtils.writeVarInt(buf, 0); 106 | } 107 | 108 | buf.writeByte(columns); 109 | buf.writeByte(rows); 110 | buf.writeByte(posX); 111 | buf.writeByte(posY); 112 | 113 | ProtocolUtils.writeVarInt(buf, data.length); 114 | buf.writeBytes(data); 115 | } 116 | } 117 | 118 | @Override 119 | public int getID(MinecraftVersion version) { 120 | return ID_MAPPING.getID(version); 121 | } 122 | } 123 | -------------------------------------------------------------------------------- /src/main/java/com/jnngl/framedimage/protocol/packets/SetMetadata.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2022 JNNGL 3 | * 4 | * This program is free software: you can redistribute it and/or modify 5 | * it under the terms of the GNU General Public License as published by 6 | * the Free Software Foundation, either version 3 of the License, or 7 | * (at your option) any later version. 8 | * 9 | * This program is distributed in the hope that it will be useful, 10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 | * GNU General Public License for more details. 13 | * 14 | * You should have received a copy of the GNU General Public License 15 | * along with this program. If not, see . 16 | */ 17 | 18 | package com.jnngl.framedimage.protocol.packets; 19 | 20 | import io.netty.buffer.ByteBuf; 21 | import com.jnngl.framedimage.protocol.MinecraftVersion; 22 | import com.jnngl.framedimage.protocol.Packet; 23 | import com.jnngl.framedimage.protocol.IdMapping; 24 | import com.jnngl.framedimage.protocol.ProtocolUtils; 25 | import com.jnngl.framedimage.protocol.data.EntityMetadata; 26 | 27 | import java.util.function.Function; 28 | 29 | public class SetMetadata implements Packet { 30 | 31 | private static final IdMapping ID_MAPPING = 32 | new IdMapping() 33 | .add(MinecraftVersion.MINIMUM_VERSION, 0x1C) 34 | .add(MinecraftVersion.MINECRAFT_1_9, 0x39) 35 | .add(MinecraftVersion.MINECRAFT_1_12, 0x3B) 36 | .add(MinecraftVersion.MINECRAFT_1_12_1, 0x3C) 37 | .add(MinecraftVersion.MINECRAFT_1_14, 0x43) 38 | .add(MinecraftVersion.MINECRAFT_1_15, 0x44) 39 | .add(MinecraftVersion.MINECRAFT_1_17, 0x4D) 40 | .add(MinecraftVersion.MINECRAFT_1_19_1, 0x50) 41 | .add(MinecraftVersion.MINECRAFT_1_19_3, 0x4E) 42 | .add(MinecraftVersion.MINECRAFT_1_19_4, 0x52) 43 | .add(MinecraftVersion.MINECRAFT_1_20_2, 0x54) 44 | .add(MinecraftVersion.MINECRAFT_1_20_3, 0x56) 45 | .add(MinecraftVersion.MINECRAFT_1_20_5, 0x58) 46 | .build(); 47 | 48 | private final int entityId; 49 | private final Function metadata; 50 | 51 | public SetMetadata(int entityId, Function metadata) { 52 | this.entityId = entityId; 53 | this.metadata = metadata; 54 | } 55 | 56 | @Override 57 | public void encode(ByteBuf buf, MinecraftVersion protocolVersion) { 58 | if (protocolVersion.compareTo(MinecraftVersion.MINECRAFT_1_7_6) <= 0) { 59 | buf.writeInt(this.entityId); 60 | } else { 61 | ProtocolUtils.writeVarInt(buf, this.entityId); 62 | } 63 | this.metadata.apply(protocolVersion).encode(buf, protocolVersion); 64 | } 65 | 66 | @Override 67 | public int getID(MinecraftVersion version) { 68 | return ID_MAPPING.getID(version); 69 | } 70 | } 71 | -------------------------------------------------------------------------------- /src/main/java/com/jnngl/framedimage/protocol/packets/SpawnEntity.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2022 JNNGL 3 | * 4 | * This program is free software: you can redistribute it and/or modify 5 | * it under the terms of the GNU General Public License as published by 6 | * the Free Software Foundation, either version 3 of the License, or 7 | * (at your option) any later version. 8 | * 9 | * This program is distributed in the hope that it will be useful, 10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 | * GNU General Public License for more details. 13 | * 14 | * You should have received a copy of the GNU General Public License 15 | * along with this program. If not, see . 16 | */ 17 | 18 | package com.jnngl.framedimage.protocol.packets; 19 | 20 | import io.netty.buffer.ByteBuf; 21 | import com.jnngl.framedimage.protocol.IdMapping; 22 | import com.jnngl.framedimage.protocol.MinecraftVersion; 23 | import com.jnngl.framedimage.protocol.Packet; 24 | import com.jnngl.framedimage.protocol.ProtocolUtils; 25 | 26 | import java.util.UUID; 27 | import java.util.function.Function; 28 | 29 | public class SpawnEntity implements Packet { 30 | 31 | private static final IdMapping ID_MAPPING = 32 | new IdMapping() 33 | .add(MinecraftVersion.MINIMUM_VERSION, 0x0E) 34 | .add(MinecraftVersion.MINECRAFT_1_9, 0x00) 35 | .add(MinecraftVersion.MINECRAFT_1_19_4, 0x01) 36 | .build(); 37 | 38 | private final int id; 39 | private final UUID uuid; 40 | private final Function type; 41 | private final double positionX; 42 | private final double positionY; 43 | private final double positionZ; 44 | private final float pitch; 45 | private final float yaw; 46 | private final float headYaw; 47 | private final Function data; 48 | private final float velocityX; 49 | private final float velocityY; 50 | private final float velocityZ; 51 | 52 | public SpawnEntity(int id, UUID uuid, Function type, double positionX, double positionY, 53 | double positionZ, float pitch, float yaw, float headYaw, Function data, 54 | float velocityX, float velocityY, float velocityZ) { 55 | this.id = id; 56 | this.uuid = uuid; 57 | this.type = type; 58 | this.positionX = positionX; 59 | this.positionY = positionY; 60 | this.positionZ = positionZ; 61 | this.pitch = pitch; 62 | this.yaw = yaw; 63 | this.headYaw = headYaw; 64 | this.data = data; 65 | this.velocityX = velocityX; 66 | this.velocityY = velocityY; 67 | this.velocityZ = velocityZ; 68 | } 69 | 70 | @Override 71 | public void encode(ByteBuf buf, MinecraftVersion protocolVersion) { 72 | ProtocolUtils.writeVarInt(buf, id); 73 | if (protocolVersion.compareTo(MinecraftVersion.MINECRAFT_1_8) > 0) { 74 | ProtocolUtils.writeUUID(buf, uuid); 75 | if (protocolVersion.compareTo(MinecraftVersion.MINECRAFT_1_13_2) > 0) { 76 | ProtocolUtils.writeVarInt(buf, type.apply(protocolVersion)); 77 | } else { 78 | buf.writeByte(type.apply(protocolVersion)); 79 | } 80 | buf.writeDouble(positionX); 81 | buf.writeDouble(positionY); 82 | buf.writeDouble(positionZ); 83 | } else { 84 | buf.writeByte(type.apply(protocolVersion)); 85 | buf.writeInt((int) (positionX * 32.0)); 86 | buf.writeInt((int) (positionY * 32.0)); 87 | buf.writeInt((int) (positionZ * 32.0)); 88 | } 89 | buf.writeByte((int) (pitch * (256.0F / 360.0F))); 90 | buf.writeByte((int) (yaw * (256.0F / 360.0F))); 91 | if (protocolVersion.compareTo(MinecraftVersion.MINECRAFT_1_18_2) > 0) { 92 | buf.writeByte((int) (headYaw * (256.0F / 360.0F))); 93 | ProtocolUtils.writeVarInt(buf, data.apply(protocolVersion)); 94 | } else { 95 | buf.writeInt(data.apply(protocolVersion)); 96 | } 97 | buf.writeShort((int) (velocityX * 8000.0F)); 98 | buf.writeShort((int) (velocityY * 8000.0F)); 99 | buf.writeShort((int) (velocityZ * 8000.0F)); 100 | } 101 | 102 | @Override 103 | public int getID(MinecraftVersion version) { 104 | return ID_MAPPING.getID(version); 105 | } 106 | } 107 | -------------------------------------------------------------------------------- /src/main/java/com/jnngl/framedimage/scheduler/BukkitTaskScheduler.java: -------------------------------------------------------------------------------- 1 | package com.jnngl.framedimage.scheduler; 2 | 3 | import com.jnngl.framedimage.FramedImage; 4 | import org.bukkit.Bukkit; 5 | import org.bukkit.Location; 6 | 7 | public class BukkitTaskScheduler implements TaskScheduler { 8 | 9 | @Override 10 | public void runAsync(FramedImage plugin, Runnable task) { 11 | Bukkit.getScheduler().runTaskAsynchronously(plugin, task); 12 | } 13 | 14 | @Override 15 | public void runDelayed(FramedImage plugin, Runnable task, long delay) { 16 | Bukkit.getScheduler().runTaskLater(plugin, task, delay); 17 | } 18 | 19 | @Override 20 | public CancellableTask runAtFixedRate(FramedImage plugin, Location location, Runnable task, long delay, long period) { 21 | return Bukkit.getScheduler().runTaskTimer(plugin, task, delay, period)::cancel; 22 | } 23 | } 24 | -------------------------------------------------------------------------------- /src/main/java/com/jnngl/framedimage/scheduler/CancellableTask.java: -------------------------------------------------------------------------------- 1 | package com.jnngl.framedimage.scheduler; 2 | 3 | public interface CancellableTask { 4 | 5 | void cancel(); 6 | } 7 | -------------------------------------------------------------------------------- /src/main/java/com/jnngl/framedimage/scheduler/FoliaTaskScheduler.java: -------------------------------------------------------------------------------- 1 | package com.jnngl.framedimage.scheduler; 2 | 3 | import com.jnngl.framedimage.FramedImage; 4 | import org.bukkit.Bukkit; 5 | import org.bukkit.Location; 6 | 7 | public class FoliaTaskScheduler implements TaskScheduler { 8 | 9 | @Override 10 | public void runAsync(FramedImage plugin, Runnable task) { 11 | Bukkit.getServer().getAsyncScheduler().runNow(plugin, scheduledTask -> task.run()); 12 | } 13 | 14 | @Override 15 | public void runDelayed(FramedImage plugin, Runnable task, long delay) { 16 | Bukkit.getServer().getGlobalRegionScheduler().runDelayed(plugin, scheduledTask -> task.run(), delay); 17 | } 18 | 19 | @Override 20 | public CancellableTask runAtFixedRate(FramedImage plugin, Location location, Runnable task, long delay, long period) { 21 | return Bukkit.getServer().getRegionScheduler() 22 | .runAtFixedRate(plugin, location, scheduledTask -> task.run(), delay, period)::cancel; 23 | } 24 | } 25 | -------------------------------------------------------------------------------- /src/main/java/com/jnngl/framedimage/scheduler/TaskScheduler.java: -------------------------------------------------------------------------------- 1 | package com.jnngl.framedimage.scheduler; 2 | 3 | import com.jnngl.framedimage.FramedImage; 4 | import org.bukkit.Location; 5 | 6 | public interface TaskScheduler { 7 | 8 | void runAsync(FramedImage plugin, Runnable task); 9 | 10 | void runDelayed(FramedImage plugin, Runnable task, long delay); 11 | 12 | default void runDelayed(FramedImage plugin, Runnable task) { 13 | runDelayed(plugin, task, 1); 14 | } 15 | 16 | CancellableTask runAtFixedRate(FramedImage plugin, Location location, Runnable task, long delay, long period); 17 | } 18 | -------------------------------------------------------------------------------- /src/main/java/com/jnngl/framedimage/util/BlockUtil.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2022 JNNGL 3 | * 4 | * This program is free software: you can redistribute it and/or modify 5 | * it under the terms of the GNU General Public License as published by 6 | * the Free Software Foundation, either version 3 of the License, or 7 | * (at your option) any later version. 8 | * 9 | * This program is distributed in the hope that it will be useful, 10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 | * GNU General Public License for more details. 13 | * 14 | * You should have received a copy of the GNU General Public License 15 | * along with this program. If not, see . 16 | */ 17 | 18 | package com.jnngl.framedimage.util; 19 | 20 | import org.bukkit.Location; 21 | import org.bukkit.block.BlockFace; 22 | 23 | public class BlockUtil { 24 | 25 | private static final BlockFace[] AXIS = new BlockFace[] { 26 | BlockFace.NORTH, BlockFace.EAST, BlockFace.SOUTH, BlockFace.WEST 27 | }; 28 | 29 | public static BlockFace getBlockFace(float entityYaw) { 30 | return AXIS[Math.round(entityYaw / 90.0F) & 0x03]; 31 | } 32 | 33 | public static Location getNextBlockLocation(Location location, BlockFace blockFace) { 34 | return new Location( 35 | location.getWorld(), 36 | location.getBlockX() + blockFace.getModX(), 37 | location.getBlockY() + blockFace.getModY(), 38 | location.getBlockZ() + blockFace.getModZ() 39 | ); 40 | } 41 | } 42 | -------------------------------------------------------------------------------- /src/main/java/com/jnngl/framedimage/util/GifReader.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2022 JNNGL 3 | * 4 | * This program is free software: you can redistribute it and/or modify 5 | * it under the terms of the GNU General Public License as published by 6 | * the Free Software Foundation, either version 3 of the License, or 7 | * (at your option) any later version. 8 | * 9 | * This program is distributed in the hope that it will be useful, 10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 | * GNU General Public License for more details. 13 | * 14 | * You should have received a copy of the GNU General Public License 15 | * along with this program. If not, see . 16 | */ 17 | 18 | package com.jnngl.framedimage.util; 19 | 20 | import org.w3c.dom.NamedNodeMap; 21 | import org.w3c.dom.Node; 22 | import org.w3c.dom.NodeList; 23 | 24 | import javax.imageio.ImageIO; 25 | import javax.imageio.ImageReader; 26 | import javax.imageio.metadata.IIOMetadata; 27 | import javax.imageio.metadata.IIOMetadataNode; 28 | import javax.imageio.stream.ImageInputStream; 29 | import java.awt.*; 30 | import java.awt.image.BufferedImage; 31 | import java.awt.image.ColorModel; 32 | import java.awt.image.WritableRaster; 33 | import java.io.IOException; 34 | import java.util.ArrayList; 35 | import java.util.List; 36 | 37 | public class GifReader { 38 | 39 | public static List read(ImageInputStream inputStream) throws IOException { 40 | List frames = new ArrayList<>(); 41 | List disposals = new ArrayList<>(); 42 | 43 | ImageReader reader = ImageIO.getImageReadersByFormatName("gif").next(); 44 | reader.setInput(inputStream); 45 | 46 | int lastX = 0; 47 | int lastY = 0; 48 | int width = -1; 49 | int height = -1; 50 | 51 | IIOMetadata metadata = reader.getStreamMetadata(); 52 | Color background = null; 53 | 54 | if (metadata != null) { 55 | IIOMetadataNode globalRoot = (IIOMetadataNode) metadata.getAsTree(metadata.getNativeMetadataFormatName()); 56 | 57 | NodeList globalColorTable = globalRoot.getElementsByTagName("GlobalColorTable"); 58 | NodeList globalScreenDescriptor = globalRoot.getElementsByTagName("LogicalScreenDescriptor"); 59 | 60 | if (globalScreenDescriptor.getLength() > 0) { 61 | IIOMetadataNode screenDescriptor = (IIOMetadataNode) globalScreenDescriptor.item(0); 62 | 63 | if (screenDescriptor != null) { 64 | width = Integer.parseInt(screenDescriptor.getAttribute("logicalScreenWidth")); 65 | height = Integer.parseInt(screenDescriptor.getAttribute("logicalScreenHeight")); 66 | } 67 | } 68 | 69 | if (globalColorTable.getLength() > 0) { 70 | IIOMetadataNode colorTable = (IIOMetadataNode) globalColorTable.item(0); 71 | 72 | if (colorTable != null) { 73 | String backgroundIndex = colorTable.getAttribute("backgroundColorIndex"); 74 | 75 | IIOMetadataNode colorEntry = (IIOMetadataNode) colorTable.getFirstChild(); 76 | while (colorEntry != null) { 77 | if (colorEntry.getAttribute("index").equals(backgroundIndex)) { 78 | int red = Integer.parseInt(colorEntry.getAttribute("red")); 79 | int green = Integer.parseInt(colorEntry.getAttribute("green")); 80 | int blue = Integer.parseInt(colorEntry.getAttribute("blue")); 81 | 82 | background = new Color(red, green, blue); 83 | break; 84 | } 85 | 86 | colorEntry = (IIOMetadataNode) colorEntry.getNextSibling(); 87 | } 88 | } 89 | } 90 | } 91 | 92 | BufferedImage master = null; 93 | boolean hasBackground = false; 94 | 95 | for (int frameIndex = 0; frameIndex < reader.getNumImages(true); frameIndex++) { 96 | BufferedImage image = reader.read(frameIndex); 97 | 98 | if (width == -1 || height == -1) { 99 | width = image.getWidth(); 100 | height = image.getHeight(); 101 | } 102 | 103 | IIOMetadataNode root = (IIOMetadataNode) reader.getImageMetadata(frameIndex).getAsTree("javax_imageio_gif_image_1.0"); 104 | IIOMetadataNode gce = (IIOMetadataNode) root.getElementsByTagName("GraphicControlExtension").item(0); 105 | NodeList children = root.getChildNodes(); 106 | 107 | String disposal = gce.getAttribute("disposalMethod"); 108 | 109 | if (master == null) { 110 | master = new BufferedImage(width, height, BufferedImage.TYPE_INT_ARGB); 111 | Graphics2D graphics = master.createGraphics(); 112 | graphics.setColor(background); 113 | graphics.fillRect(0, 0, master.getWidth(), master.getHeight()); 114 | graphics.drawImage(image, 0, 0, null); 115 | graphics.dispose(); 116 | 117 | hasBackground = image.getWidth() == width && image.getHeight() == height; 118 | } else { 119 | int x = 0; 120 | int y = 0; 121 | 122 | for (int nodeIndex = 0; nodeIndex < children.getLength(); nodeIndex++) { 123 | Node nodeItem = children.item(nodeIndex); 124 | 125 | if (nodeItem.getNodeName().equals("ImageDescriptor")) { 126 | NamedNodeMap map = nodeItem.getAttributes(); 127 | 128 | x = Integer.parseInt(map.getNamedItem("imageLeftPosition").getNodeValue()); 129 | y = Integer.parseInt(map.getNamedItem("imageTopPosition").getNodeValue()); 130 | } 131 | } 132 | 133 | if (disposal.equals("restoreToPrevious")) { 134 | BufferedImage from = null; 135 | for (int i = frameIndex - 1; i >= 0; i--) { 136 | if (!disposals.get(i).equals("restoreToPrevious")) { 137 | from = frames.get(i); 138 | break; 139 | } 140 | } 141 | 142 | if (from != null) { 143 | ColorModel model = from.getColorModel(); 144 | boolean alpha = from.isAlphaPremultiplied(); 145 | WritableRaster raster = from.copyData(null); 146 | master = new BufferedImage(model, raster, alpha, null); 147 | } 148 | } else if (disposal.equals("restoreToBackgroundColor") && background != null) { 149 | if (!hasBackground || frameIndex > 1) { 150 | Graphics2D graphics = master.createGraphics(); 151 | BufferedImage previous = frames.get(frameIndex - 1); 152 | graphics.fillRect(lastX, lastY, previous.getWidth(), previous.getHeight()); 153 | graphics.dispose(); 154 | } 155 | } 156 | 157 | Graphics2D graphics = master.createGraphics(); 158 | graphics.drawImage(image, x, y, null); 159 | graphics.dispose(); 160 | 161 | lastX = x; 162 | lastY = y; 163 | } 164 | 165 | ColorModel model = master.getColorModel(); 166 | boolean alpha = model.isAlphaPremultiplied(); 167 | WritableRaster raster = master.copyData(null); 168 | BufferedImage copy = new BufferedImage(model, raster, alpha, null); 169 | 170 | frames.add(copy); 171 | disposals.add(disposal); 172 | 173 | master.flush(); 174 | } 175 | 176 | reader.dispose(); 177 | 178 | return frames; 179 | } 180 | } 181 | -------------------------------------------------------------------------------- /src/main/java/com/jnngl/framedimage/util/ImageUtil.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2022 JNNGL 3 | * 4 | * This program is free software: you can redistribute it and/or modify 5 | * it under the terms of the GNU General Public License as published by 6 | * the Free Software Foundation, either version 3 of the License, or 7 | * (at your option) any later version. 8 | * 9 | * This program is distributed in the hope that it will be useful, 10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 | * GNU General Public License for more details. 13 | * 14 | * You should have received a copy of the GNU General Public License 15 | * along with this program. If not, see . 16 | */ 17 | 18 | package com.jnngl.framedimage.util; 19 | 20 | import javax.imageio.ImageIO; 21 | import javax.imageio.ImageReader; 22 | import javax.imageio.stream.ImageInputStream; 23 | import java.awt.image.BufferedImage; 24 | import java.io.IOException; 25 | import java.net.URL; 26 | import java.net.URLConnection; 27 | import java.util.ArrayList; 28 | import java.util.Collections; 29 | import java.util.List; 30 | 31 | public class ImageUtil { 32 | 33 | public static List readFrames(String urlString) throws IOException { 34 | URL url = new URL(urlString); 35 | String type = URLConnection.guessContentTypeFromName(urlString); 36 | 37 | if (type == null) { 38 | return Collections.singletonList(ImageIO.read(url)); 39 | } 40 | 41 | try (ImageInputStream stream = ImageIO.createImageInputStream(url.openStream())) { 42 | if (type.equals("image/gif")) { 43 | return GifReader.read(stream); 44 | } else { 45 | ImageReader imageReader = ImageIO.getImageReadersByMIMEType(type).next(); 46 | imageReader.setInput(stream); 47 | 48 | int frameCount = imageReader.getNumImages(true); 49 | 50 | List frames = new ArrayList<>(frameCount); 51 | for (int i = 0; i < frameCount; i++) { 52 | frames.add(imageReader.read(i)); 53 | } 54 | 55 | return frames; 56 | } 57 | } 58 | } 59 | } 60 | -------------------------------------------------------------------------------- /src/main/java/com/jnngl/framedimage/util/SectionUtil.java: -------------------------------------------------------------------------------- 1 | package com.jnngl.framedimage.util; 2 | 3 | import com.jnngl.framedimage.config.Config; 4 | import org.bukkit.Location; 5 | 6 | public class SectionUtil { 7 | 8 | public static long getSectionIndex(int x, int z) { 9 | int sectionShift = Config.IMP.DYNAMIC_FRAME_SPAWN.SECTION_SHIFT; 10 | int shiftedX = x >>> sectionShift; 11 | int shiftedZ = z >>> sectionShift; 12 | return (long) shiftedZ << 32 | shiftedX; 13 | } 14 | 15 | public static long getSectionIndex(Location location) { 16 | return getSectionIndex(location.getBlockX(), location.getBlockZ()); 17 | } 18 | } 19 | -------------------------------------------------------------------------------- /src/main/resources/plugin.yml: -------------------------------------------------------------------------------- 1 | name: FramedImage 2 | version: '${version}' 3 | main: com.jnngl.framedimage.FramedImage 4 | api-version: 1.13 5 | folia-supported: true 6 | 7 | commands: 8 | fi: {} 9 | 10 | permissions: 11 | framedimage.command: 12 | default: op 13 | framedimage.subcommand.create: 14 | default: op 15 | framedimage.subcommand.remove: 16 | default: op 17 | framedimage.subcommand.reload: 18 | default: op --------------------------------------------------------------------------------