├── .github └── ISSUE_TEMPLATE │ ├── bug_report.md │ └── feature_request.md ├── .gitignore ├── LICENSE ├── README.md ├── build.gradle.kts ├── gradle.properties ├── gradle ├── libs.versions.toml └── wrapper │ └── gradle-wrapper.properties ├── settings.gradle.kts └── src └── main ├── java └── me │ └── asleepp │ └── SkriptItemsAdder │ ├── SkriptItemsAdder.java │ ├── aliases │ ├── AliasesGenerator.java │ └── CustomItemType.java │ ├── elements │ ├── conditions │ │ ├── CondHUDExists.java │ │ ├── CondHUDIsVisible.java │ │ ├── CondIsCustomBlock.java │ │ ├── CondIsCustomEntity.java │ │ ├── CondIsCustomItem.java │ │ └── CondIsFullyGrown.java │ ├── effects │ │ ├── EffDamageEffect.java │ │ ├── EffMakeEntityPlayAnimation.java │ │ ├── EffOpenCustomInventory.java │ │ ├── EffPlayBreakEffect.java │ │ ├── EffPlayIATotemAnimation.java │ │ ├── EffPlayerEmote.java │ │ ├── EffSendIAResourcePack.java │ │ ├── EffSetInventoryIASlot.java │ │ ├── EffSpawnCustomEntity.java │ │ ├── EffUpdateHUD.java │ │ ├── blocks │ │ │ ├── EffPlaceBlockOrCrop.java │ │ │ ├── EffReplaceBlock.java │ │ │ └── EffSetBlocksBetween.java │ │ └── furniture │ │ │ ├── EffPlaceCustomFurniture.java │ │ │ └── EffRemoveCustomFurniture.java │ ├── events │ │ ├── blocks │ │ │ ├── EvtCustomBlockBreak.java │ │ │ ├── EvtCustomBlockInteract.java │ │ │ └── EvtCustomBlockPlace.java │ │ ├── furniture │ │ │ ├── EvtCustomFurnitureBreak.java │ │ │ ├── EvtCustomFurnitureInteract.java │ │ │ ├── EvtCustomFurniturePlace.java │ │ │ └── EvtCustomFurnitureSuccessEvent.java │ │ └── other │ │ │ ├── EvtCustomEntityDeath.java │ │ │ ├── EvtEmote.java │ │ │ └── EvtResourcePackSendEvent.java │ ├── expressions │ │ ├── ExprCropAge.java │ │ ├── ExprGetCustomItem.java │ │ ├── ExprGetFontImage.java │ │ ├── ExprGetHash.java │ │ ├── ExprGetID.java │ │ ├── ExprGetURL.java │ │ └── ExprLastCreatedIAGui.java │ ├── sections │ │ └── SecCreateCustomInventory.java │ └── types │ │ └── Types.java │ ├── listeners │ └── ItemsAdderEventListener.java │ └── util │ ├── Metrics.java │ ├── SkriptItemsAdderCommand.java │ ├── UpdateChecker.java │ └── Util.java └── resources ├── aliases.yml ├── config.yml ├── lang └── english.lang └── plugin.yml /.github/ISSUE_TEMPLATE/bug_report.md: -------------------------------------------------------------------------------- 1 | --- 2 | name: Bug report 3 | about: Create a report to help us improve 4 | title: "[BUG]" 5 | labels: bug 6 | assignees: Asleeepp 7 | 8 | --- 9 | 10 | **Describe the bug** 11 | A clear and concise description of what the bug is. 12 | 13 | **To Reproduce** 14 | Steps to reproduce the behavior: 15 | 1. 16 | 2. 17 | 3. 18 | 4. 19 | 20 | **Expected behavior** 21 | A clear and concise description of what you expected to happen. 22 | 23 | **Screenshots** 24 | If applicable, add screenshots to help explain your problem. 25 | 26 | **Server Version (/version):** 27 | - 28 | 29 | **Skript and skript-itemadder version:** 30 | - Skript: 31 | - skript-itemsadder: 32 | 33 | 34 | **Additional context** 35 | Add any other context about the problem here. 36 | -------------------------------------------------------------------------------- /.github/ISSUE_TEMPLATE/feature_request.md: -------------------------------------------------------------------------------- 1 | --- 2 | name: Feature request 3 | about: Suggest an idea for this project 4 | title: "[FEATURE REQUEST]" 5 | labels: enhancement 6 | assignees: Asleeepp 7 | 8 | --- 9 | 10 | **Is your feature request related to a problem? Please describe.** 11 | A clear and concise description of what the problem is. Ex. I'm always frustrated when [...] 12 | 13 | **Describe the solution you'd like** 14 | A clear and concise description of what you want to happen. 15 | 16 | **Describe alternatives you've considered** 17 | A clear and concise description of any alternative solutions or features you've considered. 18 | 19 | **Additional context** 20 | Add any other context or screenshots about the feature request here. 21 | -------------------------------------------------------------------------------- /.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 | . 675 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # skript-itemsadder 2 | 3 | ### Archiving 4 | 5 | This addon has been archived as I no longer feel the spark to continue to work on this addon, especially now that I am starting to move away, (and basically have entirely moved away) from Skript myself, and the fact that I no longer even use the plugin that this addon is based around (ItemsAdder), This started off as just an addon that would connect some ItemsAdder stuff to skript syntax for easy use instead of messing with skript-reflect shenanigans, personal use, I then released it in case anyone wanted to use it for themselves, as the built in Skript API for ItemsAdder was quite bare bones. 6 | 7 | Thank you for the great learning experience skript-itemsadder 🫡 8 | 9 | ------------------------------------------------------------------------------------------------------------------------------------ 10 | 11 | skript-itemsadder, an addon to replace the existing, but lackluster Skript API ItemsAdder has. (2 expressions and 1 condition) 12 | 13 | skript-itemsadder more then septuples the amount of features then that Skript API! 14 | 15 | Please make an issue in the Issues tracker if you encounter any issue, or want something to be added! 16 | 17 | Docs: 18 | [![SkriptHubViewTheDocs](http://skripthub.net/static/addon/ViewTheDocsButton.png)](http://skripthub.net/docs/?addon=skript-itemsadder) 19 | -------------------------------------------------------------------------------- /build.gradle.kts: -------------------------------------------------------------------------------- 1 | import org.apache.tools.ant.filters.ReplaceTokens 2 | 3 | plugins { 4 | `java-library` 5 | `maven-publish` 6 | alias(libs.plugins.shadow) 7 | alias(libs.plugins.run.paper) 8 | } 9 | 10 | repositories { 11 | mavenLocal() 12 | mavenCentral() 13 | maven("https://repo.papermc.io/repository/maven-public/") 14 | maven("https://repo.skriptlang.org/releases") 15 | maven("https://jitpack.io") 16 | } 17 | 18 | java { 19 | disableAutoTargetJvm() 20 | toolchain.languageVersion = JavaLanguageVersion.of(21) 21 | } 22 | 23 | description = "A skript addon that aims to bring more to linking ItemsAdder and Skript" 24 | group = "me.asleepp" 25 | version = "1.6.1" 26 | 27 | dependencies { 28 | compileOnly(libs.paper.api) 29 | compileOnly(libs.lombok) 30 | compileOnly(libs.itemsadder) 31 | compileOnly(libs.skript) 32 | annotationProcessor(libs.lombok) 33 | } 34 | 35 | 36 | tasks { 37 | jar { 38 | enabled = false 39 | } 40 | 41 | shadowJar { 42 | archiveFileName = "${rootProject.name}-${project.version}.jar" 43 | archiveClassifier = null 44 | 45 | manifest { 46 | attributes["Implementation-Version"] = rootProject.version 47 | } 48 | 49 | configurations = listOf(project.configurations.shadow.get()) 50 | minimize() 51 | } 52 | 53 | assemble { 54 | dependsOn(shadowJar) 55 | } 56 | 57 | withType { 58 | options.encoding = Charsets.UTF_8.name() 59 | options.release = 17 60 | } 61 | 62 | withType() { 63 | options.encoding = Charsets.UTF_8.name() 64 | } 65 | 66 | processResources { 67 | filter("tokens" to mapOf("version" to project.version)) 68 | inputs.property("version", project.version) 69 | 70 | filesMatching("plugin.yml") { 71 | expand( 72 | "version" to rootProject.version, 73 | ) 74 | } 75 | } 76 | 77 | defaultTasks("build") 78 | 79 | // 1.8.8 - 1.16.5 = Java 8 80 | // 1.17 = Java 16 81 | // 1.18 - 1.20.4 = Java 17 82 | // 1-20.5+ = Java 21 83 | val version = "1.20.4" 84 | val javaVersion = JavaLanguageVersion.of(17) 85 | 86 | val jvmArgsExternal = listOf( 87 | "-Dcom.mojang.eula.agree=true" 88 | ) 89 | 90 | runServer { 91 | minecraftVersion(version) 92 | runDirectory = rootDir.resolve("run/paper/$version") 93 | 94 | javaLauncher = project.javaToolchains.launcherFor { 95 | languageVersion = javaVersion 96 | } 97 | 98 | downloadPlugins { 99 | url("https://download.luckperms.net/1552/bukkit/loader/LuckPerms-Bukkit-5.4.137.jar") 100 | url("https://github.com/SkriptLang/Skript/releases/download/2.9.1/Skript-2.9.1.jar") 101 | url("https://github.com/dmulloy2/ProtocolLib/releases/download/5.2.0/ProtocolLib.jar") 102 | url("https://github.com/LoneDev6/SpigotUtilities/raw/master/LoneLibs.jar") 103 | } 104 | 105 | jvmArgs = jvmArgsExternal 106 | } 107 | } 108 | 109 | -------------------------------------------------------------------------------- /gradle.properties: -------------------------------------------------------------------------------- 1 | org.gradle.parallel=true 2 | org.gradle.caching=true 3 | org.gradle.daemon=true -------------------------------------------------------------------------------- /gradle/libs.versions.toml: -------------------------------------------------------------------------------- 1 | [versions] 2 | paper-api = "1.21-R0.1-SNAPSHOT" 3 | lombok = "1.18.34" 4 | shadow = "8.1.8" 5 | run-paper = "2.3.0" 6 | skript = "2.7.1" 7 | itemsadder = "3.6.1" 8 | 9 | [libraries] 10 | paper-api = { module = "io.papermc.paper:paper-api", version.ref = "paper-api" } 11 | lombok = { group = "org.projectlombok", name = "lombok", version.ref = "lombok" } 12 | skript = { group = "com.github.SkriptLang", name = "Skript", version.ref = "skript"} 13 | itemsadder = { group = "com.github.LoneDev6", name = "API-ItemsAdder", version.ref = "itemsadder"} 14 | 15 | [plugins] 16 | run-paper = { id = "xyz.jpenilla.run-paper", version.ref = "run-paper" } 17 | shadow = { id = "io.github.goooler.shadow", version.ref = "shadow" } 18 | -------------------------------------------------------------------------------- /gradle/wrapper/gradle-wrapper.properties: -------------------------------------------------------------------------------- 1 | distributionBase=GRADLE_USER_HOME 2 | distributionPath=wrapper/dists 3 | distributionUrl=https\://services.gradle.org/distributions/gradle-8.5-bin.zip 4 | networkTimeout=10000 5 | validateDistributionUrl=true 6 | zipStoreBase=GRADLE_USER_HOME 7 | zipStorePath=wrapper/dists 8 | -------------------------------------------------------------------------------- /settings.gradle.kts: -------------------------------------------------------------------------------- 1 | pluginManagement { 2 | repositories { 3 | mavenCentral() 4 | gradlePluginPortal() 5 | } 6 | } 7 | 8 | plugins { 9 | id("org.gradle.toolchains.foojay-resolver-convention") version "0.8.0" 10 | } 11 | 12 | rootProject.name = "skript-itemsadder" -------------------------------------------------------------------------------- /src/main/java/me/asleepp/SkriptItemsAdder/SkriptItemsAdder.java: -------------------------------------------------------------------------------- 1 | package me.asleepp.SkriptItemsAdder; 2 | 3 | import java.io.IOException; 4 | 5 | import ch.njol.skript.util.Version; 6 | import lombok.Getter; 7 | import me.asleepp.SkriptItemsAdder.aliases.AliasesGenerator; 8 | import me.asleepp.SkriptItemsAdder.listeners.ItemsAdderEventListener; 9 | import me.asleepp.SkriptItemsAdder.util.Metrics; 10 | import me.asleepp.SkriptItemsAdder.util.SkriptItemsAdderCommand; 11 | import me.asleepp.SkriptItemsAdder.util.UpdateChecker; 12 | import me.asleepp.SkriptItemsAdder.util.Util; 13 | import org.bukkit.plugin.Plugin; 14 | import org.bukkit.plugin.PluginManager; 15 | import org.bukkit.plugin.java.JavaPlugin; 16 | 17 | import ch.njol.skript.Skript; 18 | import ch.njol.skript.SkriptAddon; 19 | 20 | import javax.annotation.Nullable; 21 | 22 | public class SkriptItemsAdder extends JavaPlugin { 23 | 24 | private static SkriptAddon addon; 25 | private static SkriptItemsAdder instance; 26 | @Getter 27 | private AliasesGenerator aliasesGenerator; 28 | 29 | @Nullable 30 | public static SkriptItemsAdder getInstance() { 31 | return instance; 32 | } 33 | 34 | @Nullable 35 | public static SkriptAddon getAddonInstance() { 36 | return addon; 37 | } 38 | 39 | private final PluginManager manager = this.getServer().getPluginManager(); 40 | 41 | @Override 42 | public void onEnable() { 43 | // Let's get this show on the road. 44 | long start = System.currentTimeMillis(); 45 | final Plugin skript = manager.getPlugin("Skript"); 46 | if (skript == null || !skript.isEnabled()) { 47 | getLogger().severe("Could not find Skript! Disabling..."); 48 | manager.disablePlugin(this); 49 | return; 50 | } else if (Skript.getVersion().isSmallerThan(new Version(2, 7, 0))) { 51 | getLogger().severe("You are running an unsupported version of Skript. Disabling..."); 52 | manager.disablePlugin(this); 53 | return; 54 | } 55 | if (!Skript.isAcceptRegistrations()) { 56 | getLogger().severe("The plugin can't load when it's already loaded! Disabling..."); 57 | manager.disablePlugin(this); 58 | return; 59 | } 60 | 61 | final Plugin itemsadder = manager.getPlugin("ItemsAdder"); 62 | if (itemsadder == null || !itemsadder.isEnabled()) { 63 | getLogger().severe("Could not find ItemsAdder! Disabling..."); 64 | manager.disablePlugin(this); 65 | return; 66 | } 67 | 68 | this.aliasesGenerator = new AliasesGenerator(this); 69 | 70 | final SkriptItemsAdder plugin = this; 71 | 72 | // Pass the aliasesGenerator to the event listener 73 | ItemsAdderEventListener eventListener = new ItemsAdderEventListener(plugin, aliasesGenerator); 74 | manager.registerEvents(eventListener, plugin); 75 | 76 | int pluginId = 20971; 77 | Metrics metrics = new Metrics(this, pluginId); 78 | metrics.addCustomChart(new Metrics.SimplePie("skript_version", () -> Skript.getVersion().toString())); 79 | metrics.addCustomChart(new Metrics.SimplePie("itemsadder_version", () -> Util.getPluginVersion("ItemsAdder"))); 80 | instance = this; 81 | addon = Skript.registerAddon(this); 82 | addon.setLanguageFileDirectory("lang"); 83 | new SkriptItemsAdderCommand(this); 84 | 85 | saveDefaultConfig(); 86 | 87 | try { 88 | addon.loadClasses("me.asleepp.SkriptItemsAdder", "elements"); 89 | } catch (IOException error) { 90 | error.printStackTrace(); 91 | manager.disablePlugin(this); 92 | return; 93 | } 94 | 95 | if (getConfig().getBoolean("check-for-updates", true)) 96 | new UpdateChecker(this); 97 | 98 | long finish = System.currentTimeMillis() - start; 99 | getLogger().info("Successfully loaded skript-itemsadder in " + finish + "ms!"); 100 | eventListener.generateAliases(); 101 | } 102 | 103 | @Override 104 | public void onDisable() { 105 | } 106 | } 107 | -------------------------------------------------------------------------------- /src/main/java/me/asleepp/SkriptItemsAdder/aliases/AliasesGenerator.java: -------------------------------------------------------------------------------- 1 | package me.asleepp.SkriptItemsAdder.aliases; 2 | 3 | import ch.njol.skript.Skript; 4 | import ch.njol.skript.aliases.Aliases; 5 | import ch.njol.skript.aliases.AliasesProvider; 6 | import ch.njol.skript.aliases.InvalidMinecraftIdException; 7 | import dev.lone.itemsadder.api.CustomStack; 8 | import dev.lone.itemsadder.api.ItemsAdder; 9 | import lombok.Getter; 10 | import me.asleepp.SkriptItemsAdder.SkriptItemsAdder; 11 | import org.bukkit.configuration.file.FileConfiguration; 12 | import org.bukkit.configuration.file.YamlConfiguration; 13 | import org.bukkit.scheduler.BukkitRunnable; 14 | 15 | import java.io.File; 16 | import java.io.IOException; 17 | import java.util.*; 18 | import java.util.concurrent.ConcurrentHashMap; 19 | import java.util.stream.Collectors; 20 | 21 | public class AliasesGenerator { 22 | 23 | private final SkriptItemsAdder plugin; 24 | private final File aliasesFile; 25 | private FileConfiguration aliasesConfig; 26 | private final Map itemAliases = new ConcurrentHashMap<>(); 27 | @Getter 28 | private final Set generatedAliases = ConcurrentHashMap.newKeySet(); 29 | 30 | public AliasesGenerator(SkriptItemsAdder plugin) { 31 | this.plugin = plugin; 32 | this.aliasesFile = new File(plugin.getDataFolder(), "aliases.yml"); 33 | loadAliasesFile(); 34 | loadAliasesFromFile(); 35 | //watchAliasesFile(); 36 | } 37 | 38 | public void loadAliasesFile() { 39 | if (!aliasesFile.exists()) { 40 | aliasesFile.getParentFile().mkdirs(); 41 | plugin.saveResource("aliases.yml", false); 42 | } 43 | aliasesConfig = YamlConfiguration.loadConfiguration(aliasesFile); 44 | } 45 | 46 | public void loadAliasesFromFile() { 47 | if (aliasesConfig.contains("items")) { 48 | for (String key : aliasesConfig.getConfigurationSection("items").getKeys(false)) { 49 | itemAliases.put(key, aliasesConfig.getString("items." + key)); 50 | } 51 | } 52 | } 53 | 54 | private void saveAliasesToFile() { 55 | new BukkitRunnable() { 56 | @Override 57 | public void run() { 58 | for (Map.Entry entry : itemAliases.entrySet()) { 59 | aliasesConfig.set("items." + entry.getKey(), entry.getValue()); 60 | } 61 | try { 62 | aliasesConfig.save(aliasesFile); 63 | } catch (IOException e) { 64 | e.printStackTrace(); 65 | } 66 | } 67 | }.runTaskAsynchronously(plugin); 68 | } 69 | 70 | private String generateUniqueAlias(String baseAlias) { 71 | String uniqueAlias = baseAlias; 72 | int counter = 1; 73 | while (itemAliases.containsKey(uniqueAlias)) { 74 | uniqueAlias = baseAlias + "_" + counter; 75 | counter++; 76 | } 77 | return uniqueAlias; 78 | } 79 | 80 | private String generateAliasForItem(CustomStack item) { 81 | String baseAlias = item.getId().toLowerCase().replace("_", " "); 82 | if (itemAliases.containsValue(baseAlias)) { 83 | return generateUniqueAlias(baseAlias); 84 | } 85 | return baseAlias; 86 | } 87 | 88 | private void registerAlias(String alias, String namespacedId) { 89 | itemAliases.put(alias, namespacedId); 90 | generatedAliases.add(alias); 91 | 92 | AliasesProvider addonProvider = Aliases.getAddonProvider(Skript.getAddonInstance()); 93 | AliasesProvider.AliasName aliasName = new AliasesProvider.AliasName(alias, alias, 0); 94 | try { 95 | addonProvider.addAlias(aliasName, namespacedId, null, new HashMap<>()); 96 | } catch (InvalidMinecraftIdException ignored) { 97 | } 98 | } 99 | 100 | public void generateAliasesForAllItems() { 101 | new BukkitRunnable() { 102 | @Override 103 | public void run() { 104 | List allItems = ItemsAdder.getAllItems(); 105 | 106 | Set currentNamespaces = allItems.stream() 107 | .map(CustomStack::getNamespacedID) 108 | .collect(Collectors.toSet()); 109 | 110 | boolean allAliasesExist = currentNamespaces.stream() 111 | .allMatch(itemAliases::containsValue); 112 | 113 | if (allAliasesExist && currentNamespaces.size() == itemAliases.size()) { 114 | return; 115 | } 116 | 117 | for (CustomStack item : allItems) { 118 | String namespacedId = item.getNamespacedID(); 119 | if (!itemAliases.containsValue(namespacedId)) { 120 | String alias = generateAliasForItem(item); 121 | registerAlias(alias, namespacedId); 122 | } 123 | } 124 | 125 | Set unusedAliases = itemAliases.keySet().stream() 126 | .filter(alias -> !generatedAliases.contains(alias)) 127 | .collect(Collectors.toSet()); 128 | for (String unusedAlias : unusedAliases) { 129 | itemAliases.remove(unusedAlias); 130 | } 131 | 132 | // Save asynchronously 133 | saveAliases(); 134 | } 135 | }.runTaskAsynchronously(plugin); 136 | } 137 | 138 | public void syncAliasesWithProvider() { 139 | AliasesProvider addonProvider = Aliases.getAddonProvider(Skript.getAddonInstance()); 140 | addonProvider.clearAliases(); 141 | 142 | for (Map.Entry entry : itemAliases.entrySet()) { 143 | AliasesProvider.AliasName aliasName = new AliasesProvider.AliasName(entry.getKey(), entry.getKey(), 0); 144 | try { 145 | addonProvider.addAlias(aliasName, entry.getValue(), null, new HashMap<>()); 146 | } catch (InvalidMinecraftIdException ignored) { 147 | } 148 | } 149 | } 150 | 151 | 152 | public String getNamespacedId(String alias) { 153 | return itemAliases.get(alias); 154 | } 155 | 156 | public void saveAliases() { 157 | saveAliasesToFile(); 158 | } 159 | } 160 | -------------------------------------------------------------------------------- /src/main/java/me/asleepp/SkriptItemsAdder/aliases/CustomItemType.java: -------------------------------------------------------------------------------- 1 | package me.asleepp.SkriptItemsAdder.aliases; 2 | 3 | import lombok.Getter; 4 | import lombok.Setter; 5 | import org.bukkit.event.Event; 6 | 7 | import java.util.Objects; 8 | import java.util.function.Function; 9 | 10 | @Setter 11 | @Getter 12 | public class CustomItemType { 13 | 14 | private String namespacedID; 15 | 16 | public CustomItemType() { } 17 | 18 | public CustomItemType(String namespacedID) { 19 | this.namespacedID = namespacedID; 20 | } 21 | 22 | @Override 23 | public boolean equals(Object o) { 24 | if (this == o) return true; 25 | if (o == null || getClass() != o.getClass()) return false; 26 | CustomItemType that = (CustomItemType) o; 27 | return namespacedID.equals(that.namespacedID); 28 | } 29 | 30 | @Override 31 | public int hashCode() { 32 | return Objects.hash(namespacedID); 33 | } 34 | 35 | @Override 36 | public String toString() { 37 | return namespacedID; 38 | } 39 | 40 | 41 | public static CustomItemType fromEvent(Event event, AliasesGenerator aliasesGenerator, Function idExtractor) { 42 | String namespacedID = idExtractor.apply(event); 43 | String alias = aliasesGenerator.getNamespacedId(namespacedID); 44 | return alias != null ? new CustomItemType(alias) : null; 45 | } 46 | 47 | } 48 | -------------------------------------------------------------------------------- /src/main/java/me/asleepp/SkriptItemsAdder/elements/conditions/CondHUDExists.java: -------------------------------------------------------------------------------- 1 | package me.asleepp.SkriptItemsAdder.elements.conditions; 2 | 3 | import ch.njol.skript.Skript; 4 | import ch.njol.skript.lang.Condition; 5 | import ch.njol.skript.lang.Expression; 6 | import ch.njol.skript.lang.SkriptParser; 7 | import ch.njol.util.Kleenean; 8 | import dev.lone.itemsadder.api.FontImages.PlayerHudWrapper; 9 | import dev.lone.itemsadder.api.FontImages.PlayerHudsHolderWrapper; 10 | import org.bukkit.entity.Player; 11 | import org.bukkit.event.Event; 12 | 13 | import javax.annotation.Nullable; 14 | 15 | public class CondHUDExists extends Condition { 16 | 17 | private Expression players; 18 | private Expression hudID; 19 | 20 | static { 21 | Skript.registerCondition(CondHUDExists.class, "[custom] (ia|itemsadder) hud %string% [of %players%] exists"); 22 | } 23 | 24 | @Override 25 | public boolean init(Expression[] exprs, int i, Kleenean kleenean, SkriptParser.ParseResult parseResult) { 26 | hudID = (Expression) exprs[0]; 27 | players = (Expression) exprs[1]; 28 | return true; 29 | } 30 | 31 | @Override 32 | public boolean check(Event event) { 33 | String id = hudID.getSingle(event); 34 | Player[] playersArray = players != null ? players.getArray(event) : new Player[]{}; 35 | 36 | if (id != null) { 37 | for (Player player : playersArray) { 38 | PlayerHudsHolderWrapper hudHolder = new PlayerHudsHolderWrapper(player); 39 | PlayerHudWrapper hudWrapper = new PlayerHudWrapper(hudHolder, id); 40 | if (!hudWrapper.exists()) { 41 | return false; 42 | } 43 | } 44 | return true; 45 | } 46 | return false; 47 | } 48 | 49 | @Override 50 | public String toString(@Nullable Event event, boolean debug) { 51 | return "itemsadder hud " + hudID.toString(event, debug) + " of players " + (players != null ? players.toString(event, debug) : "all players") + " exists"; 52 | } 53 | } 54 | -------------------------------------------------------------------------------- /src/main/java/me/asleepp/SkriptItemsAdder/elements/conditions/CondHUDIsVisible.java: -------------------------------------------------------------------------------- 1 | package me.asleepp.SkriptItemsAdder.elements.conditions; 2 | 3 | import ch.njol.skript.Skript; 4 | import ch.njol.skript.doc.Description; 5 | import ch.njol.skript.doc.Examples; 6 | import ch.njol.skript.doc.Name; 7 | import ch.njol.skript.doc.RequiredPlugins; 8 | import ch.njol.skript.doc.Since; 9 | import ch.njol.skript.lang.Condition; 10 | import ch.njol.skript.lang.Expression; 11 | import ch.njol.skript.lang.SkriptParser; 12 | import ch.njol.util.Kleenean; 13 | import dev.lone.itemsadder.api.FontImages.PlayerHudWrapper; 14 | import dev.lone.itemsadder.api.FontImages.PlayerHudsHolderWrapper; 15 | import org.bukkit.entity.Player; 16 | import org.bukkit.event.Event; 17 | 18 | import javax.annotation.Nullable; 19 | 20 | @Name("HUD Is Visible") 21 | @Description("Determines whether players can see a hud/if a hud is active.") 22 | @Examples("if player can see itemsadder hud \"namespaced:id\"") 23 | @Since("1.6") 24 | @RequiredPlugins("ItemsAdder") 25 | public class CondHUDIsVisible extends Condition { 26 | 27 | private Expression players; 28 | private Expression hudID; 29 | 30 | static { 31 | Skript.registerCondition(CondHUDIsVisible.class, "%players% can (see|view) [custom] (ia|itemsadder) hud %string%"); 32 | } 33 | 34 | @Override 35 | public boolean init(Expression[] exprs, int i, Kleenean kleenean, SkriptParser.ParseResult parseResult) { 36 | players = (Expression) exprs[0]; 37 | hudID = (Expression) exprs[1]; 38 | return true; 39 | } 40 | 41 | @Override 42 | public boolean check(Event event) { 43 | Player[] p = players.getArray(event); 44 | String id = hudID.getSingle(event); 45 | 46 | if (id != null) { 47 | for (Player players : p) { 48 | PlayerHudsHolderWrapper hudsHolder = new PlayerHudsHolderWrapper(players); 49 | PlayerHudWrapper hudWrapper = new PlayerHudWrapper(hudsHolder, id); 50 | return hudWrapper.isVisible(); 51 | } 52 | return false; 53 | } 54 | return false; 55 | } 56 | 57 | @Override 58 | public String toString(@Nullable Event event, boolean debug) { 59 | return players.toString(event, debug) + "can view itemsadder hud " + hudID.toString(event, debug); 60 | } 61 | } 62 | -------------------------------------------------------------------------------- /src/main/java/me/asleepp/SkriptItemsAdder/elements/conditions/CondIsCustomBlock.java: -------------------------------------------------------------------------------- 1 | package me.asleepp.SkriptItemsAdder.elements.conditions; 2 | 3 | import ch.njol.skript.Skript; 4 | import ch.njol.skript.doc.Description; 5 | import ch.njol.skript.doc.Examples; 6 | import ch.njol.skript.doc.Name; 7 | import ch.njol.skript.doc.RequiredPlugins; 8 | import ch.njol.skript.doc.Since; 9 | import ch.njol.skript.lang.Condition; 10 | import ch.njol.skript.lang.Expression; 11 | import ch.njol.skript.lang.SkriptParser; 12 | import ch.njol.util.Kleenean; 13 | import dev.lone.itemsadder.api.CustomBlock; 14 | import me.asleepp.SkriptItemsAdder.aliases.CustomItemType; 15 | import org.bukkit.block.Block; 16 | import org.bukkit.event.Event; 17 | 18 | import javax.annotation.Nullable; 19 | import java.util.List; 20 | import java.util.stream.Collectors; 21 | 22 | @Name("Is ItemsAdder Block") 23 | @Description({"Checks if the block is an ItemsAdder block."}) 24 | @Examples({ 25 | "on break:", 26 | "\tif event-block is a custom block with id \"iasurvival:ruby_block\":", 27 | "\t\tkill player", 28 | "\telse if event-block isn't a custom block:", 29 | "\t\tsend \"Good Job!\" to player" 30 | }) 31 | @Since("1.0, 1.5 (Negative Comparison)") 32 | @RequiredPlugins("ItemsAdder") 33 | public class CondIsCustomBlock extends Condition { 34 | private Expression blocks; 35 | private Expression ids; 36 | private boolean negated; 37 | 38 | static { 39 | Skript.registerCondition(CondIsCustomBlock.class, 40 | "%blocks% (is [a[n]]|are) [custom] (ia|itemsadder) block[s] [[with id] %-customitemtypes/strings%]", 41 | "%blocks% (isn't|is not|aren't|are not) [a] [custom] (ia|itemsadder) block[s] [[with id] %-customitemtypes/strings%]"); 42 | } 43 | 44 | @SuppressWarnings("unchecked") 45 | @Override 46 | public boolean init(Expression[] expressions, int matchedPattern, Kleenean isDelayed, SkriptParser.ParseResult parseResult) { 47 | blocks = (Expression) expressions[0]; 48 | ids = (Expression) expressions[1]; 49 | negated = matchedPattern == 1; 50 | return true; 51 | } 52 | 53 | @Override 54 | public boolean check(Event event) { 55 | List expectedIds = ids.stream(event) 56 | .map(id -> { 57 | if (id instanceof CustomItemType) { 58 | return ((CustomItemType) id).getNamespacedID(); 59 | } else if (id instanceof String) { 60 | return (String) id; 61 | } 62 | return null; 63 | }) 64 | .filter(id -> id != null) 65 | .collect(Collectors.toList()); 66 | 67 | boolean allMatch = blocks.getArray(event).length > 0; 68 | for (Block block : blocks.getArray(event)) { 69 | CustomBlock customBlock = CustomBlock.byAlreadyPlaced(block); 70 | boolean matches = customBlock != null && expectedIds.contains(customBlock.getId()); 71 | if (negated && matches || !negated && !matches) { 72 | allMatch = false; 73 | break; 74 | } 75 | } 76 | return allMatch; 77 | } 78 | 79 | @Override 80 | public String toString(@Nullable Event event, boolean debug) { 81 | String blockString = blocks.toString(event, debug); 82 | String idString = ids.toString(event, debug); 83 | return blockString + (negated ? " isn't" : " is") + " a custom block" + (idString != null ? " with id " + idString : ""); 84 | } 85 | } 86 | -------------------------------------------------------------------------------- /src/main/java/me/asleepp/SkriptItemsAdder/elements/conditions/CondIsCustomEntity.java: -------------------------------------------------------------------------------- 1 | package me.asleepp.SkriptItemsAdder.elements.conditions; 2 | 3 | import ch.njol.skript.Skript; 4 | import ch.njol.skript.doc.Description; 5 | import ch.njol.skript.doc.Examples; 6 | import ch.njol.skript.doc.Name; 7 | import ch.njol.skript.doc.RequiredPlugins; 8 | import ch.njol.skript.doc.Since; 9 | import ch.njol.skript.lang.Condition; 10 | import ch.njol.skript.lang.Expression; 11 | import ch.njol.skript.lang.SkriptParser; 12 | import ch.njol.util.Kleenean; 13 | import dev.lone.itemsadder.api.CustomEntity; 14 | import org.bukkit.entity.Entity; 15 | import org.bukkit.event.Event; 16 | 17 | import javax.annotation.Nullable; 18 | @Name("Is ItemsAdder Entity") 19 | @Description({"Checks if the entity is an ItemsAdder entity."}) 20 | @Examples({ 21 | "on damage:", 22 | "\tif event-entity is an itemsadder entity:", 23 | "\t\tsend \"how could you?\" to player", 24 | "\telse if event-entity is not an itemsadder entity:", 25 | "\t\t send \"Incredible!\" to player "}) 26 | @Since("1.0, 1.5 (Negative Comparison)") 27 | @RequiredPlugins("ItemsAdder") 28 | public class CondIsCustomEntity extends Condition { 29 | 30 | private Expression entities; 31 | private Expression entityId; 32 | 33 | static { 34 | Skript.registerCondition(CondIsCustomEntity.class, "%entities% (is [a[n]]|are) [custom] (ia|itemsadder) entit(y|ies) [[with id] %-string%]", "%entities% (is[n't| not]) [a] [custom] (ia|itemsadder) entit(y|ies) [[with id] %-string%]"); 35 | } 36 | 37 | @SuppressWarnings("unchecked") 38 | @Override 39 | public boolean init(Expression[] exprs, int matchedPattern, Kleenean isDelayed, SkriptParser.ParseResult parseResult) { 40 | entities = (Expression) exprs[0]; 41 | entityId = (Expression) exprs[1]; 42 | setNegated(matchedPattern == 1); 43 | return true; 44 | } 45 | 46 | @Override 47 | public boolean check(Event e) { 48 | for (Entity entity : entities.getArray(e)) { 49 | CustomEntity customEntity = CustomEntity.byAlreadySpawned(entity); 50 | if (customEntity == null) { 51 | return isNegated(); 52 | } 53 | if (entityId != null) { 54 | String id = entityId.getSingle(e); 55 | if (id == null || !customEntity.getId().equals(id)) { 56 | return isNegated(); 57 | } 58 | } 59 | } 60 | return !isNegated(); 61 | } 62 | 63 | @Override 64 | public String toString(@Nullable Event e, boolean debug) { 65 | return entities.toString(e, debug) + (isNegated() ? " isn't" : " is") + " a custom entity" + (entityId != null ? " with id " + entityId.toString(e, debug) : ""); 66 | } 67 | } -------------------------------------------------------------------------------- /src/main/java/me/asleepp/SkriptItemsAdder/elements/conditions/CondIsCustomItem.java: -------------------------------------------------------------------------------- 1 | package me.asleepp.SkriptItemsAdder.elements.conditions; 2 | 3 | import ch.njol.skript.Skript; 4 | import ch.njol.skript.doc.Description; 5 | import ch.njol.skript.doc.Examples; 6 | import ch.njol.skript.doc.Name; 7 | import ch.njol.skript.doc.RequiredPlugins; 8 | import ch.njol.skript.doc.Since; 9 | import ch.njol.skript.lang.Condition; 10 | import ch.njol.skript.lang.Expression; 11 | import ch.njol.skript.lang.SkriptParser; 12 | import ch.njol.util.Kleenean; 13 | import org.bukkit.event.Event; 14 | import org.bukkit.inventory.ItemStack; 15 | import dev.lone.itemsadder.api.CustomStack; 16 | import me.asleepp.SkriptItemsAdder.aliases.CustomItemType; 17 | 18 | import javax.annotation.Nullable; 19 | import java.util.Arrays; 20 | import java.util.List; 21 | import java.util.stream.Collectors; 22 | 23 | @Name("Is ItemsAdder Item") 24 | @Description({"Checks if the item is an ItemsAdder item."}) 25 | @Examples({ 26 | "if player's tool is a custom item", 27 | "if player's tool is a custom item \"icon_arrow_chest\"" 28 | }) 29 | @Since("1.0, 1.5 (Negative comparison)") 30 | @RequiredPlugins("ItemsAdder") 31 | public class CondIsCustomItem extends Condition { 32 | 33 | private Expression items; 34 | private Expression ids; 35 | private boolean negated; 36 | 37 | static { 38 | Skript.registerCondition(CondIsCustomItem.class, 39 | "%itemstacks% (is [a[n]]|are) [custom] (ia|itemsadder) item[s] [[with id] %-customitemtypes/strings%]", 40 | "%itemstacks% (is[n't| not]) [a] [custom] (ia|itemsadder) item[s] [[with id] %-customitemtypes/strings%]"); 41 | } 42 | 43 | @SuppressWarnings("unchecked") 44 | @Override 45 | public boolean init(Expression[] expressions, int matchedPattern, Kleenean isDelayed, SkriptParser.ParseResult parseResult) { 46 | items = (Expression) expressions[0]; 47 | ids = (Expression) expressions[1]; 48 | negated = matchedPattern == 1; 49 | return true; 50 | } 51 | 52 | @Override 53 | public boolean check(Event event) { 54 | List expectedIds = Arrays.stream(ids.getArray(event)) 55 | .map(id -> { 56 | if (id instanceof CustomItemType) { 57 | return ((CustomItemType) id).getNamespacedID(); 58 | } else if (id instanceof String) { 59 | return (String) id; 60 | } 61 | return null; 62 | }) 63 | .filter(id -> id != null) 64 | .collect(Collectors.toList()); 65 | 66 | boolean allMatch = items.getArray(event).length > 0; 67 | for (ItemStack itemStack : items.getArray(event)) { 68 | CustomStack customStack = CustomStack.byItemStack(itemStack); 69 | boolean matches = customStack != null && expectedIds.contains(customStack.getId()); 70 | if (negated && matches || !negated && !matches) { 71 | allMatch = false; 72 | break; 73 | } 74 | } 75 | return allMatch; 76 | } 77 | 78 | @Override 79 | public String toString(@Nullable Event event, boolean debug) { 80 | String itemString = items.toString(event, debug); 81 | String idString = ids.toString(event, debug); 82 | return itemString + (negated ? " isn't" : " is") + " a custom item" + (idString != null ? " with id " + idString : ""); 83 | } 84 | } 85 | -------------------------------------------------------------------------------- /src/main/java/me/asleepp/SkriptItemsAdder/elements/conditions/CondIsFullyGrown.java: -------------------------------------------------------------------------------- 1 | package me.asleepp.SkriptItemsAdder.elements.conditions; 2 | 3 | import ch.njol.skript.Skript; 4 | import ch.njol.skript.lang.Condition; 5 | import ch.njol.skript.lang.Expression; 6 | import ch.njol.skript.lang.SkriptParser; 7 | import ch.njol.util.Kleenean; 8 | import dev.lone.itemsadder.api.CustomCrop; 9 | import org.bukkit.block.Block; 10 | import org.bukkit.event.Event; 11 | 12 | import javax.annotation.Nullable; 13 | 14 | public class CondIsFullyGrown extends Condition { 15 | 16 | private Expression blocks; 17 | 18 | static { 19 | Skript.registerCondition(CondIsFullyGrown.class, 20 | "[the] [custom] (ia|itemsadder) %blocks% (is|are) full[y] grown", 21 | "[the] [custom] (ia|itemsadder) %blocks% (isn't|is not|aren't|are not) full[y] grown"); 22 | } 23 | 24 | @Override 25 | public boolean init(Expression[] exprs, int matchedPattern, Kleenean isDelayed, SkriptParser.ParseResult parseResult) { 26 | blocks = (Expression) exprs[0]; 27 | setNegated(matchedPattern == 1); 28 | return true; 29 | } 30 | 31 | @Override 32 | public boolean check(Event e) { 33 | return blocks.check(e, block -> { 34 | CustomCrop crop = CustomCrop.byAlreadyPlaced(block); 35 | return crop != null && crop.isFullyGrown(); 36 | }, isNegated()); 37 | } 38 | 39 | @Override 40 | public String toString(@Nullable Event e, boolean debug) { 41 | return blocks.toString(e, debug) + (isNegated() ? " is not" : " is") + " fully grown"; 42 | } 43 | } 44 | -------------------------------------------------------------------------------- /src/main/java/me/asleepp/SkriptItemsAdder/elements/effects/EffDamageEffect.java: -------------------------------------------------------------------------------- 1 | package me.asleepp.SkriptItemsAdder.elements.effects; 2 | 3 | import ch.njol.skript.Skript; 4 | import ch.njol.skript.doc.Examples; 5 | import ch.njol.skript.doc.RequiredPlugins; 6 | import ch.njol.skript.doc.Since; 7 | import ch.njol.skript.lang.Effect; 8 | import ch.njol.skript.lang.Expression; 9 | import ch.njol.skript.lang.SkriptParser; 10 | import ch.njol.util.Kleenean; 11 | import dev.lone.itemsadder.api.CustomEntity; 12 | import jdk.jfr.Description; 13 | import jdk.jfr.Name; 14 | import org.bukkit.entity.Entity; 15 | import org.bukkit.event.Event; 16 | 17 | import javax.annotation.Nullable; 18 | 19 | @Name("Damage Effect") 20 | @Description("Play the red damage effect on an ItemsAdder entity.") 21 | @Examples("play damage effect on custom itemsadder entity {_iaentity}") 22 | @Since("1.6") 23 | @RequiredPlugins("ItemsAdder") 24 | public class EffDamageEffect extends Effect { 25 | 26 | private Expression entitiesExpr; 27 | 28 | static { 29 | Skript.registerEffect(EffDamageEffect.class, "(show|play) [the] damage effect on [custom] (itemsadder|ia) entit[y|ies] %entities%"); 30 | } 31 | 32 | @Override 33 | public boolean init(Expression[] exprs, int i, Kleenean kleenean, SkriptParser.ParseResult parseResult) { 34 | entitiesExpr = (Expression) exprs[0]; 35 | return true; 36 | } 37 | 38 | @Override 39 | protected void execute(Event event) { 40 | Entity[] entities = entitiesExpr.getArray(event); 41 | 42 | for (Entity entity : entities) { 43 | CustomEntity customEntity = CustomEntity.byAlreadySpawned(entity); 44 | if (!(customEntity == null)) { 45 | customEntity.playDamageEffect(false); 46 | } 47 | 48 | } 49 | } 50 | 51 | @Override 52 | public String toString(@Nullable Event event, boolean debug) { 53 | return "show damage effect on itemsadder entity " + entitiesExpr.toString(event, debug); 54 | } 55 | } 56 | -------------------------------------------------------------------------------- /src/main/java/me/asleepp/SkriptItemsAdder/elements/effects/EffMakeEntityPlayAnimation.java: -------------------------------------------------------------------------------- 1 | package me.asleepp.SkriptItemsAdder.elements.effects; 2 | 3 | import ch.njol.skript.Skript; 4 | import ch.njol.skript.doc.Description; 5 | import ch.njol.skript.doc.Examples; 6 | import ch.njol.skript.doc.Name; 7 | import ch.njol.skript.doc.RequiredPlugins; 8 | import ch.njol.skript.doc.Since; 9 | import ch.njol.skript.lang.Effect; 10 | import ch.njol.skript.lang.Expression; 11 | import ch.njol.skript.lang.SkriptParser; 12 | import ch.njol.util.Kleenean; 13 | import dev.lone.itemsadder.api.CustomEntity; 14 | import org.bukkit.entity.Entity; 15 | import org.bukkit.event.Event; 16 | 17 | import javax.annotation.Nullable; 18 | @Name("Make Entity Play Animation") 19 | @Description({"Makes an ItemsAdder entity play an animation."}) 20 | @Examples({ 21 | "on right click:", 22 | "\tif clicked entity is an itemsadder entity", 23 | "\t\tmake clicked entity play itemsadder animation \"fortnite:default_dance\""}) 24 | @Since("1.0") 25 | @RequiredPlugins("ItemsAdder") 26 | public class EffMakeEntityPlayAnimation extends Effect { 27 | 28 | private Expression entityExpr; 29 | private Expression animationIdExpr; 30 | 31 | 32 | static { 33 | Skript.registerEffect(EffMakeEntityPlayAnimation.class, "(make|force) %entities% [to] play [custom] (ia|itemsadder) (anim[ation]) %string%"); 34 | } 35 | 36 | @Override 37 | public boolean init(Expression[] exprs, int matchedPattern, Kleenean isDelayed, SkriptParser.ParseResult parseResult) { 38 | entityExpr = (Expression) exprs[0]; 39 | animationIdExpr = (Expression) exprs[1]; 40 | return true; 41 | } 42 | 43 | @Override 44 | protected void execute(Event e) { 45 | Entity[] entities = entityExpr.getArray(e); 46 | String animationId = animationIdExpr.getSingle(e); 47 | 48 | if (entities == null || animationId == null) { 49 | return; 50 | } 51 | 52 | for (Entity entity : entities) { 53 | CustomEntity customEntity = CustomEntity.byAlreadySpawned(entity); 54 | if (customEntity != null) { 55 | customEntity.playAnimation(animationId); 56 | } 57 | } 58 | } 59 | 60 | 61 | @Override 62 | public String toString(@Nullable Event e, boolean debug) { 63 | return "make " + entityExpr.toString(e, debug) + " play animation " + animationIdExpr.toString(e, debug); 64 | } 65 | 66 | 67 | } 68 | -------------------------------------------------------------------------------- /src/main/java/me/asleepp/SkriptItemsAdder/elements/effects/EffOpenCustomInventory.java: -------------------------------------------------------------------------------- 1 | package me.asleepp.SkriptItemsAdder.elements.effects; 2 | 3 | import ch.njol.skript.Skript; 4 | import ch.njol.skript.doc.Description; 5 | import ch.njol.skript.doc.Examples; 6 | import ch.njol.skript.doc.Name; 7 | import ch.njol.skript.doc.RequiredPlugins; 8 | import ch.njol.skript.doc.Since; 9 | import ch.njol.skript.lang.Effect; 10 | import ch.njol.skript.lang.Expression; 11 | import ch.njol.skript.lang.SkriptParser; 12 | import ch.njol.util.Kleenean; 13 | import dev.lone.itemsadder.api.FontImages.TexturedInventoryWrapper; 14 | import org.bukkit.entity.Player; 15 | import org.bukkit.event.Event; 16 | 17 | import javax.annotation.Nullable; 18 | @Name("Open ItemsAdder Inventory") 19 | @Description("Opens an ItemsAdder inventory to a player(s), made using the ItemsAdder inventory section.") 20 | @Examples("open custom itemsadder inventory {votegui} to all players") 21 | @Since("1.5") 22 | @RequiredPlugins("ItemsAdder") 23 | public class EffOpenCustomInventory extends Effect { 24 | 25 | private Expression players; 26 | private Expression inventory; 27 | 28 | static { 29 | Skript.registerEffect(EffOpenCustomInventory.class, "(show|open) [a[n]|the] [custom] (ia|itemsadder) [inventory] %texturedinventorywrapper% to %players%"); 30 | } 31 | 32 | @Override 33 | protected void execute(Event e) { 34 | Player[] ps = players.getArray(e); 35 | TexturedInventoryWrapper inventory = this.inventory.getSingle(e); 36 | if (ps != null && inventory != null) { 37 | for (Player p : ps) { 38 | inventory.showInventory(p); 39 | } 40 | } 41 | } 42 | 43 | @Override 44 | public String toString(@Nullable Event e, boolean debug) { 45 | return "open " + inventory.toString(e, debug) + " to " + players.toString(e, debug); 46 | } 47 | 48 | @Override 49 | public boolean init(Expression[] exprs, int matchedPattern, Kleenean isDelayed, SkriptParser.ParseResult parseResult) { 50 | inventory = (Expression) exprs[0]; 51 | players = (Expression) exprs[1]; 52 | return true; 53 | } 54 | } 55 | -------------------------------------------------------------------------------- /src/main/java/me/asleepp/SkriptItemsAdder/elements/effects/EffPlayBreakEffect.java: -------------------------------------------------------------------------------- 1 | package me.asleepp.SkriptItemsAdder.elements.effects; 2 | 3 | import ch.njol.skript.Skript; 4 | import ch.njol.skript.doc.Description; 5 | import ch.njol.skript.doc.Examples; 6 | import ch.njol.skript.doc.Name; 7 | import ch.njol.skript.doc.RequiredPlugins; 8 | import ch.njol.skript.doc.Since; 9 | import ch.njol.skript.lang.Effect; 10 | import ch.njol.skript.lang.Expression; 11 | import ch.njol.skript.lang.SkriptParser; 12 | import ch.njol.util.Kleenean; 13 | import dev.lone.itemsadder.api.CustomBlock; 14 | 15 | import org.bukkit.block.Block; 16 | import org.bukkit.event.Event; 17 | 18 | import javax.annotation.Nullable; 19 | 20 | @Name("Play Break Effect") 21 | @Description("Plays the breaking effect on an ItemsAdder block, (not the cracking in case you were wondering.)") 22 | @Examples("play break effect on target block") 23 | @Since("1.5") 24 | @RequiredPlugins("ItemsAdder") 25 | public class EffPlayBreakEffect extends Effect { 26 | 27 | private Expression blocks; 28 | 29 | static { 30 | Skript.registerEffect(EffPlayBreakEffect.class, "(show|play) break[ing] effect on [custom] (ia|itemsadder) %blocks%"); 31 | } 32 | 33 | @SuppressWarnings("unchecked") 34 | @Override 35 | public boolean init(Expression[] exprs, int matchedPattern, Kleenean isDelayed, SkriptParser.ParseResult parseResult) { 36 | blocks = (Expression) exprs[0]; 37 | return true; 38 | } 39 | 40 | @Override 41 | protected void execute(Event e) { 42 | Block[] blocksArray = blocks.getArray(e); 43 | for (Block block : blocksArray) { 44 | CustomBlock customBlock = CustomBlock.byAlreadyPlaced(block); 45 | if (customBlock != null) { 46 | customBlock.playBreakEffect(block); 47 | } 48 | } 49 | } 50 | 51 | @Override 52 | public String toString(@Nullable Event e, boolean debug) { 53 | return "(show|play) break[ing] effect on " + blocks.toString(e, debug); 54 | } 55 | } 56 | -------------------------------------------------------------------------------- /src/main/java/me/asleepp/SkriptItemsAdder/elements/effects/EffPlayIATotemAnimation.java: -------------------------------------------------------------------------------- 1 | package me.asleepp.SkriptItemsAdder.elements.effects; 2 | 3 | import ch.njol.skript.Skript; 4 | import ch.njol.skript.doc.Description; 5 | import ch.njol.skript.doc.Examples; 6 | import ch.njol.skript.doc.Name; 7 | import ch.njol.skript.doc.RequiredPlugins; 8 | import ch.njol.skript.doc.Since; 9 | import ch.njol.skript.lang.Effect; 10 | import ch.njol.skript.lang.Expression; 11 | import ch.njol.skript.lang.SkriptParser; 12 | import ch.njol.util.Kleenean; 13 | import dev.lone.itemsadder.api.ItemsAdder; 14 | import org.bukkit.entity.Player; 15 | import org.bukkit.event.Event; 16 | 17 | import javax.annotation.Nullable; 18 | @Name("Play ItemsAdder Totem Animation") 19 | @Description({"Play a custom Totem Animation to players."}) 20 | @Examples({"play the custom totem animation \"celebrations:you_win\" to player"}) 21 | @Since("1.0") 22 | @RequiredPlugins("ItemsAdder") 23 | public class EffPlayIATotemAnimation extends Effect { 24 | 25 | private Expression players; 26 | private Expression totem; 27 | 28 | static { 29 | Skript.registerEffect(EffPlayIATotemAnimation.class, "(play|make) [the] [custom] (ia|itemsadder) totem [anim|animation] %string% to %players%"); 30 | } 31 | 32 | @SuppressWarnings("unchecked") 33 | @Override 34 | public boolean init(Expression[] exprs, int matchedPattern, Kleenean isDelayed, SkriptParser.ParseResult parseResult) { 35 | totem = (Expression) exprs[0]; 36 | players = (Expression) exprs[1]; 37 | return true; 38 | } 39 | 40 | @Override 41 | protected void execute(Event e) { 42 | Player[] ps = players.getArray(e); 43 | String totemName = totem.getSingle(e); 44 | 45 | if (ps != null && totemName != null) { 46 | for (Player p : ps) { 47 | ItemsAdder.playTotemAnimation(p, totemName); 48 | } 49 | } 50 | } 51 | 52 | @Override 53 | public String toString(@Nullable Event e, boolean debug) { 54 | return "play the custom totem animation " + totem.toString(e, debug) + " to " + players.toString(e, debug); 55 | } 56 | } 57 | -------------------------------------------------------------------------------- /src/main/java/me/asleepp/SkriptItemsAdder/elements/effects/EffPlayerEmote.java: -------------------------------------------------------------------------------- 1 | package me.asleepp.SkriptItemsAdder.elements.effects; 2 | 3 | import ch.njol.skript.Skript; 4 | import ch.njol.skript.doc.Description; 5 | import ch.njol.skript.doc.Examples; 6 | import ch.njol.skript.doc.Name; 7 | import ch.njol.skript.doc.RequiredPlugins; 8 | import ch.njol.skript.doc.Since; 9 | import ch.njol.skript.lang.Effect; 10 | import ch.njol.skript.lang.Expression; 11 | import ch.njol.skript.lang.SkriptParser; 12 | import ch.njol.util.Kleenean; 13 | import dev.lone.itemsadder.api.CustomPlayer; 14 | import org.bukkit.entity.Player; 15 | import org.bukkit.event.Event; 16 | 17 | import javax.annotation.Nullable; 18 | @Name("Make Player Emote/Stop Emoting") 19 | @Description({"Force player to emote/stop emoting"}) 20 | @Examples({"force all players to perform emote \"fortnite:default_dance\""}) 21 | @Since("1.0, 1.5 (slight syntax update)") 22 | @RequiredPlugins("ItemsAdder") 23 | public class EffPlayerEmote extends Effect { 24 | private Expression players; 25 | private Expression emote; 26 | private int pattern; 27 | 28 | static { 29 | Skript.registerEffect(EffPlayerEmote.class, 30 | "(make|force) %players% to perform [custom] [ia|itemsadder] (emote|dance|animation) %string%", 31 | "(make|force) %players% [to] stop [current] emot[e|ing]"); 32 | } 33 | @Override 34 | public boolean init(Expression[] exprs, int matchedPattern, Kleenean isDelayed, SkriptParser.ParseResult parseResult) { 35 | players = (Expression) exprs[0]; 36 | pattern = matchedPattern; 37 | if (matchedPattern == 0) { 38 | emote = (Expression) exprs[1]; 39 | } 40 | return true; 41 | } 42 | protected void execute(Event e) { 43 | Player[] ps = players.getArray(e); 44 | 45 | if (ps != null) { 46 | if (pattern == 0) { 47 | String emoteName = emote.getSingle(e); 48 | if (emoteName != null) { 49 | for (Player p : ps) { 50 | CustomPlayer.playEmote(p, emoteName); 51 | } 52 | } 53 | } else if (pattern == 1) { 54 | for (Player p : ps) { 55 | CustomPlayer.stopEmote(p); 56 | } 57 | } 58 | } 59 | } 60 | 61 | @Override 62 | public String toString(@Nullable Event e, boolean debug) { 63 | return pattern == 0 ? "make " + players.toString(e, debug) + " play animation " + emote.toString(e, debug) 64 | : "make " + players.toString(e, debug) + " stop emoting"; 65 | } 66 | } 67 | -------------------------------------------------------------------------------- /src/main/java/me/asleepp/SkriptItemsAdder/elements/effects/EffSendIAResourcePack.java: -------------------------------------------------------------------------------- 1 | package me.asleepp.SkriptItemsAdder.elements.effects; 2 | 3 | import ch.njol.skript.Skript; 4 | import ch.njol.skript.doc.Description; 5 | import ch.njol.skript.doc.Examples; 6 | import ch.njol.skript.doc.Name; 7 | import ch.njol.skript.doc.RequiredPlugins; 8 | import ch.njol.skript.doc.Since; 9 | import ch.njol.skript.lang.Effect; 10 | import ch.njol.skript.lang.Expression; 11 | import ch.njol.skript.lang.SkriptParser; 12 | import ch.njol.util.Kleenean; 13 | import dev.lone.itemsadder.api.ItemsAdder; 14 | import org.bukkit.entity.Player; 15 | import org.bukkit.event.Event; 16 | 17 | import javax.annotation.Nullable; 18 | @Name("Send ItemsAdder Resource Pack") 19 | @Description({"Sends the most recently generated ItemsAdder resource pack to players."}) 20 | @Examples({"send current itemsadder resource pack to all players"}) 21 | @Since("1.0") 22 | @RequiredPlugins("ItemsAdder") 23 | public class EffSendIAResourcePack extends Effect { 24 | 25 | private Expression players; 26 | 27 | static { 28 | Skript.registerEffect(EffSendIAResourcePack.class, "(send|apply) [current] [custom] (ia|itemsadder) (texture|resource) pack to %players%"); 29 | } 30 | @Override 31 | public boolean init(Expression[] exprs, int matchedPattern, Kleenean isDelayed, SkriptParser.ParseResult parseResult) { 32 | players = (Expression) exprs[0]; 33 | return true; 34 | } 35 | @Override 36 | protected void execute(Event e) { 37 | Player[] ps = players.getArray(e); 38 | 39 | if (ps != null) { 40 | for (Player p : ps) { 41 | ItemsAdder.applyResourcepack(p); 42 | } 43 | } 44 | } 45 | 46 | @Override 47 | public String toString(@Nullable Event e, boolean debug) { 48 | return "Apply ItemsAdder resource pack to " + players.toString(e, debug); 49 | } 50 | } 51 | -------------------------------------------------------------------------------- /src/main/java/me/asleepp/SkriptItemsAdder/elements/effects/EffSetInventoryIASlot.java: -------------------------------------------------------------------------------- 1 | package me.asleepp.SkriptItemsAdder.elements.effects; 2 | 3 | import ch.njol.skript.Skript; 4 | import ch.njol.skript.doc.Description; 5 | import ch.njol.skript.doc.Examples; 6 | import ch.njol.skript.doc.Name; 7 | import ch.njol.skript.doc.RequiredPlugins; 8 | import ch.njol.skript.doc.Since; 9 | import ch.njol.skript.lang.Effect; 10 | import ch.njol.skript.lang.Expression; 11 | import ch.njol.skript.lang.SkriptParser; 12 | import ch.njol.util.Kleenean; 13 | import dev.lone.itemsadder.api.FontImages.TexturedInventoryWrapper; 14 | import org.bukkit.event.Event; 15 | import org.bukkit.inventory.ItemStack; 16 | 17 | import javax.annotation.Nullable; 18 | 19 | @Name("Set Custom Inventory Slot") 20 | @Description("Set a slot of an ItemsAdder custom inventory, works like the regular Skript syntax.") 21 | @Examples("set slot 2 of custom {_g} to cooked beef # {_g} is the gui, stored in a variable, like Vanilla GUIs") 22 | @Since("1.5") 23 | @RequiredPlugins("ItemsAdder") 24 | public class EffSetInventoryIASlot extends Effect { 25 | 26 | private Expression inventory; 27 | private Expression slots; 28 | private Expression items; 29 | 30 | static { 31 | Skript.registerEffect(EffSetInventoryIASlot.class, "set slot[s] %integers% of [custom] (ia|itemsadder) %texturedinventorywrapper% to %itemstacks%"); 32 | } 33 | 34 | @Override 35 | public boolean init(Expression[] expressions, int matchedPattern, Kleenean isDelayed, SkriptParser.ParseResult parseResult) { 36 | slots = (Expression) expressions[0]; 37 | inventory = (Expression) expressions[1]; 38 | items = (Expression) expressions[2]; 39 | return true; 40 | } 41 | @Override 42 | protected void execute(Event e) { 43 | Integer[] slotArray = this.slots.getArray(e); 44 | TexturedInventoryWrapper inventory = this.inventory.getSingle(e); 45 | ItemStack[] itemArray = this.items.getArray(e); 46 | for (int i = 0; i < slotArray.length && i < itemArray.length; i++) { 47 | inventory.getInternal().setItem(slotArray[i], itemArray[i]); 48 | } 49 | } 50 | 51 | @Override 52 | public String toString(@Nullable Event e, boolean debug) { 53 | return "set slot " + slots.toString(e, debug) + " of " + inventory.toString(e, debug) + " to " + items.toString(e, debug); 54 | } 55 | 56 | } 57 | -------------------------------------------------------------------------------- /src/main/java/me/asleepp/SkriptItemsAdder/elements/effects/EffSpawnCustomEntity.java: -------------------------------------------------------------------------------- 1 | package me.asleepp.SkriptItemsAdder.elements.effects; 2 | 3 | import ch.njol.skript.Skript; 4 | import ch.njol.skript.doc.Description; 5 | import ch.njol.skript.doc.Examples; 6 | import ch.njol.skript.doc.Name; 7 | import ch.njol.skript.doc.RequiredPlugins; 8 | import ch.njol.skript.doc.Since; 9 | import ch.njol.skript.lang.Effect; 10 | import ch.njol.skript.lang.Expression; 11 | import ch.njol.skript.lang.SkriptParser; 12 | import ch.njol.util.Kleenean; 13 | import dev.lone.itemsadder.api.CustomEntity; 14 | import org.bukkit.Location; 15 | import org.bukkit.event.Event; 16 | 17 | import javax.annotation.Nullable; 18 | @Name("Spawn ItemsAdder Entity") 19 | @Description({"Spawns an ItemsAdder entity."}) 20 | @Examples({"spawn itemsadder entity \"bosses:john_wick\" at player's location"}) 21 | @Since("1.0") 22 | @RequiredPlugins("ItemsAdder") 23 | public class EffSpawnCustomEntity extends Effect { 24 | 25 | private Expression entityIdExpr; 26 | private Expression locationExpr; 27 | 28 | static { 29 | Skript.registerEffect(EffSpawnCustomEntity.class, "(spawn|summon) [the] [custom] (ia|itemsadder) (entity|mob) %string% at %locations%"); 30 | } 31 | 32 | @Override 33 | public boolean init(Expression[] exprs, int matchedPattern, Kleenean isDelayed, SkriptParser.ParseResult parseResult) { 34 | entityIdExpr = (Expression) exprs[0]; 35 | locationExpr = (Expression) exprs[1]; 36 | return true; 37 | } 38 | 39 | @Override 40 | protected void execute(Event e) { 41 | String entityId = entityIdExpr.getSingle(e); 42 | Location[] locations = locationExpr.getArray(e); 43 | 44 | if (entityId == null || locations == null) { 45 | return; 46 | } 47 | 48 | for (Location location : locations) { 49 | CustomEntity customEntity = CustomEntity.spawn(entityId, location); 50 | if (customEntity == null) { 51 | Skript.error("Please provide a valid CustomEntity ID."); 52 | return; 53 | } 54 | } 55 | } 56 | 57 | @Override 58 | public String toString(@Nullable Event e, boolean debug) { 59 | return "spawn custom entity " + entityIdExpr.toString(e, debug) + " at " + locationExpr.toString(e, debug); 60 | } 61 | } 62 | -------------------------------------------------------------------------------- /src/main/java/me/asleepp/SkriptItemsAdder/elements/effects/EffUpdateHUD.java: -------------------------------------------------------------------------------- 1 | package me.asleepp.SkriptItemsAdder.elements.effects; 2 | 3 | import ch.njol.skript.Skript; 4 | import ch.njol.skript.doc.Description; 5 | import ch.njol.skript.doc.Examples; 6 | import ch.njol.skript.doc.Name; 7 | import ch.njol.skript.doc.RequiredPlugins; 8 | import ch.njol.skript.doc.Since; 9 | import ch.njol.skript.lang.Effect; 10 | import ch.njol.skript.lang.Expression; 11 | import ch.njol.skript.lang.SkriptParser; 12 | import ch.njol.util.Kleenean; 13 | import dev.lone.itemsadder.api.FontImages.PlayerHudsHolderWrapper; 14 | import org.bukkit.entity.Player; 15 | import org.bukkit.event.Event; 16 | 17 | import javax.annotation.Nullable; 18 | 19 | @Name("Update HUD") 20 | @Description("Update the player's currently enabled HUD.") 21 | @Examples("update player's current itemsadder hud") 22 | @Since("1.6") 23 | @RequiredPlugins("ItemsAdder") 24 | public class EffUpdateHUD extends Effect { 25 | 26 | private Expression players; 27 | 28 | static { 29 | Skript.registerEffect(EffUpdateHUD.class, "(update|refresh) %players%'[s] [current] [custom] (itemsadder|ia) hud"); 30 | } 31 | 32 | @Override 33 | public boolean init(Expression[] exprs, int i, Kleenean kleenean, SkriptParser.ParseResult parseResult) { 34 | players = (Expression) exprs[0]; 35 | return true; 36 | } 37 | 38 | @Override 39 | protected void execute(Event event) { 40 | Player[] p = players.getArray(event); 41 | 42 | if (p != null) { 43 | for (Player players : p) { 44 | PlayerHudsHolderWrapper playerHudsHolderWrapper = new PlayerHudsHolderWrapper(players); 45 | if (playerHudsHolderWrapper.exists()) { 46 | playerHudsHolderWrapper.sendUpdate(); 47 | } 48 | } 49 | } 50 | } 51 | 52 | @Override 53 | public String toString(@Nullable Event event, boolean debug) { 54 | return "update " + players.toString(event, debug) + " hud"; 55 | } 56 | 57 | } 58 | -------------------------------------------------------------------------------- /src/main/java/me/asleepp/SkriptItemsAdder/elements/effects/blocks/EffPlaceBlockOrCrop.java: -------------------------------------------------------------------------------- 1 | package me.asleepp.SkriptItemsAdder.elements.effects.blocks; 2 | 3 | import ch.njol.skript.Skript; 4 | import ch.njol.skript.doc.Description; 5 | import ch.njol.skript.doc.Examples; 6 | import ch.njol.skript.doc.Name; 7 | import ch.njol.skript.doc.RequiredPlugins; 8 | import ch.njol.skript.doc.Since; 9 | import ch.njol.skript.lang.Effect; 10 | import ch.njol.skript.lang.Expression; 11 | import ch.njol.skript.lang.SkriptParser; 12 | import ch.njol.skript.util.Direction; 13 | import ch.njol.util.Kleenean; 14 | import dev.lone.itemsadder.api.CustomBlock; 15 | import dev.lone.itemsadder.api.CustomCrop; 16 | import me.asleepp.SkriptItemsAdder.util.Util; 17 | import org.bukkit.Location; 18 | import org.bukkit.event.Event; 19 | 20 | import javax.annotation.Nullable; 21 | import java.util.ArrayList; 22 | import java.util.List; 23 | 24 | @Name("Place Custom Block/Crop") 25 | @Description({"Places a custom block or crop at a location."}) 26 | @Examples({ 27 | "set block at player's location to itemsadder block \"iasurvival:ruby_block\"", 28 | "set block at player's location to custom itemsadder crop best seed"}) 29 | @Since("1.0, 1.5 (Placing Crops & Syntax rework)") 30 | @RequiredPlugins("ItemsAdder") 31 | public class EffPlaceBlockOrCrop extends Effect { 32 | private Expression locations; 33 | private Expression blockNames; 34 | private boolean isCrop; 35 | 36 | static { 37 | Skript.registerEffect(EffPlaceBlockOrCrop.class, 38 | "(set|place) [custom] (ia|itemsadder) (block|:crop) %customitemtypes/strings% [%directions% %locations%]", 39 | "set block at [%directions% %locations%] to [custom] (ia|itemsadder) (block|:crop) %customitemtypes/strings%"); 40 | } 41 | 42 | @Override 43 | public boolean init(Expression[] exprs, int matchedPattern, Kleenean isDelayed, SkriptParser.ParseResult parseResult) { 44 | if (matchedPattern == 0) { 45 | blockNames = exprs[0]; 46 | locations = Direction.combine((Expression) exprs[1], (Expression) exprs[2]); 47 | } else { 48 | blockNames = exprs[2]; 49 | locations = Direction.combine((Expression) exprs[0], (Expression) exprs[1]); 50 | } 51 | isCrop = parseResult.hasTag("crop"); 52 | return true; 53 | } 54 | 55 | @Override 56 | protected void execute(Event e) { 57 | if (locations == null || blockNames == null) { 58 | return; 59 | } 60 | 61 | List customBlockIds = new ArrayList<>(); 62 | if (blockNames.isSingle()) { 63 | Object itemType = blockNames.getSingle(e); 64 | customBlockIds.add(Util.getCustomBlockId(itemType)); 65 | } else { 66 | for (Object itemType : blockNames.getArray(e)) { 67 | customBlockIds.add(Util.getCustomBlockId(itemType)); 68 | } 69 | } 70 | 71 | for (Location location : locations.getArray(e)) { 72 | for (String customBlockId : customBlockIds) { 73 | if (customBlockId == null) { 74 | Skript.error("Invalid custom block ID."); 75 | continue; 76 | } 77 | 78 | try { 79 | if (isCrop) { 80 | CustomCrop.place(customBlockId, location); 81 | } else { 82 | CustomBlock existingBlock = CustomBlock.byAlreadyPlaced(location.getBlock()); 83 | if (existingBlock != null) { 84 | existingBlock.remove(); 85 | } 86 | CustomBlock block = CustomBlock.getInstance(customBlockId); 87 | if (block != null) { 88 | block.place(location); 89 | } else { 90 | Skript.error("Failed to get CustomBlock instance for ID: " + customBlockId); 91 | } 92 | } 93 | } catch (Exception ex) { 94 | Skript.error("An error occurred while placing custom block/crop: " + ex.getMessage()); 95 | ex.printStackTrace(); 96 | } 97 | } 98 | } 99 | } 100 | 101 | @Override 102 | public String toString(@Nullable Event e, boolean debug) { 103 | String itemTypeString = blockNames.toString(e, debug); 104 | String type = isCrop ? "crop" : "block"; 105 | return "place custom " + type + " " + itemTypeString + " at " + locations.toString(e, debug); 106 | } 107 | } 108 | -------------------------------------------------------------------------------- /src/main/java/me/asleepp/SkriptItemsAdder/elements/effects/blocks/EffReplaceBlock.java: -------------------------------------------------------------------------------- 1 | package me.asleepp.SkriptItemsAdder.elements.effects.blocks; 2 | 3 | import ch.njol.skript.Skript; 4 | import ch.njol.skript.doc.Description; 5 | import ch.njol.skript.doc.Examples; 6 | import ch.njol.skript.doc.Name; 7 | import ch.njol.skript.doc.RequiredPlugins; 8 | import ch.njol.skript.doc.Since; 9 | import ch.njol.skript.lang.Effect; 10 | import ch.njol.skript.lang.Expression; 11 | import ch.njol.skript.lang.SkriptParser; 12 | import ch.njol.util.Kleenean; 13 | import org.bukkit.event.Event; 14 | import dev.lone.itemsadder.api.CustomBlock; 15 | import org.bukkit.Location; 16 | 17 | import javax.annotation.Nullable; 18 | @Name("Replace Custom Block") 19 | @Description({"If there is a custom block at a location, this effect will remove it and place the one you specify."}) 20 | @Examples({"replace custom block \"diamond_tiles\" at player's location"}) 21 | @Since("1.4") 22 | @RequiredPlugins("ItemsAdder") 23 | public class EffReplaceBlock extends Effect { 24 | 25 | private Expression blockId; 26 | private Expression location; 27 | 28 | static { 29 | Skript.registerEffect(EffReplaceBlock.class, "replace [custom] (ia|itemsadder) block %string% at %location%"); 30 | } 31 | 32 | @Override 33 | protected void execute(Event e) { 34 | String id = blockId.getSingle(e); 35 | Location loc = location.getSingle(e); 36 | 37 | if (id != null && loc != null) { 38 | CustomBlock existingBlock = CustomBlock.byAlreadyPlaced(loc.getBlock()); 39 | 40 | if (existingBlock != null) { 41 | existingBlock.remove(); 42 | } 43 | CustomBlock.place(id, loc); 44 | } 45 | } 46 | 47 | @Override 48 | public String toString(@Nullable Event e, boolean debug) { 49 | return "replace itemsadder block " + blockId.toString(e, debug) + " at " + location.toString(e, debug); 50 | } 51 | 52 | @Override 53 | public boolean init(Expression[] exprs, int matchedPattern, Kleenean isDelayed, SkriptParser.ParseResult parseResult) { 54 | blockId = (Expression) exprs[0]; 55 | location = (Expression) exprs[1]; 56 | return true; 57 | } 58 | } 59 | -------------------------------------------------------------------------------- /src/main/java/me/asleepp/SkriptItemsAdder/elements/effects/blocks/EffSetBlocksBetween.java: -------------------------------------------------------------------------------- 1 | package me.asleepp.SkriptItemsAdder.elements.effects.blocks; 2 | 3 | import ch.njol.skript.Skript; 4 | import ch.njol.skript.doc.Description; 5 | import ch.njol.skript.doc.Examples; 6 | import ch.njol.skript.doc.Name; 7 | import ch.njol.skript.doc.RequiredPlugins; 8 | import ch.njol.skript.doc.Since; 9 | import ch.njol.skript.lang.Effect; 10 | import ch.njol.skript.lang.Expression; 11 | import ch.njol.skript.lang.SkriptParser; 12 | import ch.njol.util.Kleenean; 13 | import dev.lone.itemsadder.api.CustomBlock; 14 | import me.asleepp.SkriptItemsAdder.SkriptItemsAdder; 15 | import me.asleepp.SkriptItemsAdder.aliases.AliasesGenerator; 16 | import me.asleepp.SkriptItemsAdder.util.Util; 17 | import org.bukkit.Location; 18 | import org.bukkit.event.Event; 19 | 20 | import javax.annotation.Nullable; 21 | import java.util.ArrayList; 22 | import java.util.Arrays; 23 | import java.util.List; 24 | import java.util.stream.Collectors; 25 | 26 | @Name("Set Custom Blocks Within") 27 | @Description({"Sets the blocks within 2 locations to ItemsAdder custom blocks."}) 28 | @Examples({"set all blocks within location(0, 100, 0) and player's location to itemsadder block \"iasurvival:ruby_block\""}) 29 | @Since("1.0") 30 | @RequiredPlugins("ItemsAdder") 31 | public class EffSetBlocksBetween extends Effect { 32 | private Expression location1Expr; 33 | private Expression location2Expr; 34 | private Expression customBlockIdExpr; 35 | private AliasesGenerator aliasesGenerator = SkriptItemsAdder.getInstance().getAliasesGenerator(); 36 | 37 | static { 38 | Skript.registerEffect(EffSetBlocksBetween.class, "(set|place) [all] blocks within %location% and %location% to [custom] (ia|itemsadder) block %customitemtypes/strings%"); 39 | } 40 | 41 | @Override 42 | public boolean init(Expression[] exprs, int matchedPattern, Kleenean isDelayed, SkriptParser.ParseResult parseResult) { 43 | location1Expr = (Expression) exprs[0]; 44 | location2Expr = (Expression) exprs[1]; 45 | customBlockIdExpr = exprs[2]; 46 | return true; 47 | } 48 | 49 | @Override 50 | protected void execute(Event e) { 51 | Location location1 = location1Expr.getSingle(e); 52 | Location location2 = location2Expr.getSingle(e); 53 | Object customBlockIdObj = customBlockIdExpr.getSingle(e); 54 | String customBlockId = Util.getCustomBlockId(customBlockIdObj); 55 | 56 | List customBlockIds = new ArrayList<>(); 57 | if (customBlockIdExpr.isSingle()) { 58 | Object itemType = customBlockIdExpr.getSingle(e); 59 | customBlockIds.add(Util.getCustomBlockId(itemType)); 60 | } else { 61 | for (Object itemType : customBlockIdExpr.getArray(e)) { 62 | customBlockIds.add(Util.getCustomBlockId(itemType)); 63 | } 64 | } 65 | 66 | if (location1 == null || location2 == null || customBlockId == null) { 67 | return; 68 | } 69 | 70 | int minX = Math.min(location1.getBlockX(), location2.getBlockX()); 71 | int minY = Math.min(location1.getBlockY(), location2.getBlockY()); 72 | int minZ = Math.min(location1.getBlockZ(), location2.getBlockZ()); 73 | int maxX = Math.max(location1.getBlockX(), location2.getBlockX()); 74 | int maxY = Math.max(location1.getBlockY(), location2.getBlockY()); 75 | int maxZ = Math.max(location1.getBlockZ(), location2.getBlockZ()); 76 | 77 | for (int x = minX; x <= maxX; x++) { 78 | for (int y = minY; y <= maxY; y++) { 79 | for (int z = minZ; z <= maxZ; z++) { 80 | Location location = new Location(location1.getWorld(), x, y, z); 81 | CustomBlock customBlock = CustomBlock.getInstance(customBlockId); 82 | if (customBlock != null) { 83 | customBlock.place(location); 84 | } 85 | } 86 | } 87 | } 88 | } 89 | 90 | @Override 91 | public String toString(@Nullable Event e, boolean debug) { 92 | return "place custom block " + customBlockIdExpr.toString(e, debug) + " between locations " + location1Expr.toString(e, debug) + " and " + location2Expr.toString(e, debug); 93 | } 94 | } 95 | -------------------------------------------------------------------------------- /src/main/java/me/asleepp/SkriptItemsAdder/elements/effects/furniture/EffPlaceCustomFurniture.java: -------------------------------------------------------------------------------- 1 | package me.asleepp.SkriptItemsAdder.elements.effects.furniture; 2 | 3 | import ch.njol.skript.Skript; 4 | import ch.njol.skript.doc.Description; 5 | import ch.njol.skript.doc.Examples; 6 | import ch.njol.skript.doc.Name; 7 | import ch.njol.skript.doc.RequiredPlugins; 8 | import ch.njol.skript.doc.Since; 9 | import ch.njol.skript.lang.Effect; 10 | import ch.njol.skript.lang.Expression; 11 | import ch.njol.skript.lang.SkriptParser; 12 | import ch.njol.util.Kleenean; 13 | import dev.lone.itemsadder.api.CustomFurniture; 14 | import me.asleepp.SkriptItemsAdder.util.Util; 15 | import org.bukkit.Location; 16 | import org.bukkit.entity.Entity; 17 | import org.bukkit.event.Event; 18 | import org.bukkit.plugin.java.JavaPlugin; 19 | import org.bukkit.scheduler.BukkitRunnable; 20 | 21 | import javax.annotation.Nullable; 22 | import java.util.ArrayList; 23 | import java.util.List; 24 | 25 | @Name("Place Custom Furniture") 26 | @Description({ 27 | "Place a custom furniture at a location.", 28 | "If there is a furniture at the same location, this effect will replace it." 29 | }) 30 | @Examples({"place itemsadder furniture \"coolfurniture:comfy_chair\" at player's location"}) 31 | @Since("1.3, 1.6 (Replacing)") 32 | @RequiredPlugins("ItemsAdder") 33 | public class EffPlaceCustomFurniture extends Effect { 34 | 35 | private Expression furnitureIdExpr; 36 | private Expression locationExpr; 37 | private JavaPlugin plugin; 38 | 39 | static { 40 | Skript.registerEffect(EffPlaceCustomFurniture.class, "(set|place) [custom] (ia|itemsadder) furniture %customitemtypes/strings% at %location%"); 41 | } 42 | 43 | @Override 44 | public boolean init(Expression[] exprs, int matchedPattern, Kleenean isDelayed, SkriptParser.ParseResult parseResult) { 45 | furnitureIdExpr = exprs[0]; 46 | locationExpr = (Expression) exprs[1]; 47 | return true; 48 | } 49 | 50 | @Override 51 | protected void execute(Event e) { 52 | if (furnitureIdExpr == null || locationExpr == null) { 53 | return; 54 | } 55 | 56 | List furnitureIds = new ArrayList<>(); 57 | if (furnitureIdExpr.isSingle()) { 58 | Object itemType = furnitureIdExpr.getSingle(e); 59 | furnitureIds.add(Util.getCustomBlockId(itemType)); 60 | } else { 61 | for (Object itemType : furnitureIdExpr.getArray(e)) { 62 | furnitureIds.add(Util.getCustomBlockId(itemType)); 63 | } 64 | } 65 | 66 | Location location = locationExpr.getSingle(e); 67 | if (location == null) { 68 | return; 69 | } 70 | 71 | for (String furnitureId : furnitureIds) { 72 | if (furnitureId == null) { 73 | Skript.error("Invalid custom furniture ID."); 74 | continue; 75 | } 76 | 77 | CustomFurniture customFurniture = CustomFurniture.byAlreadySpawned(location.getBlock()); 78 | if (customFurniture == null) { 79 | CustomFurniture.spawn(furnitureId, location.getBlock()); 80 | } else { 81 | Entity armorStand = customFurniture.getArmorstand(); 82 | if (armorStand != null) { 83 | Location originalLocation = armorStand.getLocation(); 84 | customFurniture.remove(false); 85 | new BukkitRunnable() { 86 | @Override 87 | public void run() { 88 | CustomFurniture.spawn(furnitureId, originalLocation.getBlock()); 89 | } 90 | }.runTaskLater(plugin, 3); 91 | } 92 | } 93 | } 94 | } 95 | 96 | @Override 97 | public String toString(@Nullable Event e, boolean debug) { 98 | return "(set|place) [custom] (ia|itemsadder) furniture " + furnitureIdExpr.toString(e, debug) + " at " + locationExpr.toString(e, debug); 99 | } 100 | 101 | } 102 | -------------------------------------------------------------------------------- /src/main/java/me/asleepp/SkriptItemsAdder/elements/effects/furniture/EffRemoveCustomFurniture.java: -------------------------------------------------------------------------------- 1 | package me.asleepp.SkriptItemsAdder.elements.effects.furniture; 2 | 3 | import ch.njol.skript.Skript; 4 | import ch.njol.skript.doc.Description; 5 | import ch.njol.skript.doc.Examples; 6 | import ch.njol.skript.doc.Name; 7 | import ch.njol.skript.doc.RequiredPlugins; 8 | import ch.njol.skript.doc.Since; 9 | import ch.njol.skript.lang.Effect; 10 | import ch.njol.skript.lang.Expression; 11 | import ch.njol.skript.lang.SkriptParser; 12 | import ch.njol.util.Kleenean; 13 | import dev.lone.itemsadder.api.CustomFurniture; 14 | import me.asleepp.SkriptItemsAdder.util.Util; 15 | import org.bukkit.Location; 16 | import org.bukkit.event.Event; 17 | 18 | import javax.annotation.Nullable; 19 | import java.util.ArrayList; 20 | import java.util.List; 21 | 22 | @Name("Remove Custom Furniture") 23 | @Description({"If there is furniture at a location, this effect will remove it."}) 24 | @Examples({"remove itemsadder furniture at player's location"}) 25 | @Since("1.4") 26 | @RequiredPlugins("ItemsAdder") 27 | public class EffRemoveCustomFurniture extends Effect { 28 | 29 | static { 30 | Skript.registerEffect(EffRemoveCustomFurniture.class, "(remove|delete) [custom] (ia|itemsadder) furniture [%customitemtypes/strings%] at %locations%"); 31 | } 32 | 33 | private Expression furnitureId; 34 | private Expression locations; 35 | 36 | @SuppressWarnings("unchecked") 37 | @Override 38 | public boolean init(Expression[] exprs, int matchedPattern, Kleenean isDelayed, SkriptParser.ParseResult parseResult) { 39 | furnitureId = (Expression) exprs[0]; 40 | locations = (Expression) exprs[1]; 41 | return true; 42 | } 43 | 44 | @Override 45 | protected void execute(Event e) { 46 | Location[] locs = locations.getAll(e); 47 | List customFurnitureIds = new ArrayList<>(); 48 | 49 | if (furnitureId != null) { 50 | if (furnitureId.isSingle()) { 51 | Object itemType = furnitureId.getSingle(e); 52 | customFurnitureIds.add(Util.getCustomBlockId(itemType)); 53 | } else { 54 | for (Object itemType : furnitureId.getArray(e)) { 55 | customFurnitureIds.add(Util.getCustomBlockId(itemType)); 56 | } 57 | } 58 | } 59 | 60 | for (Location loc : locs) { 61 | for (String id : customFurnitureIds) { 62 | if (id != null && loc != null) { 63 | CustomFurniture existingFurniture = CustomFurniture.byAlreadySpawned(loc.getBlock()); 64 | 65 | if (existingFurniture != null) { 66 | existingFurniture.remove(false); 67 | } 68 | } 69 | } 70 | } 71 | } 72 | 73 | @Override 74 | public String toString(@Nullable Event e, boolean debug) { 75 | return "remove custom furniture " + (furnitureId != null ? furnitureId.toString(e, debug) : "") + " at " + locations.toString(e, debug); 76 | } 77 | } 78 | -------------------------------------------------------------------------------- /src/main/java/me/asleepp/SkriptItemsAdder/elements/events/blocks/EvtCustomBlockBreak.java: -------------------------------------------------------------------------------- 1 | package me.asleepp.SkriptItemsAdder.elements.events.blocks; 2 | 3 | import ch.njol.skript.Skript; 4 | import ch.njol.skript.lang.Literal; 5 | import ch.njol.skript.lang.SkriptEvent; 6 | import ch.njol.skript.lang.SkriptParser; 7 | import ch.njol.skript.registrations.EventValues; 8 | import ch.njol.skript.util.Getter; 9 | import dev.lone.itemsadder.api.CustomBlock; 10 | import dev.lone.itemsadder.api.Events.CustomBlockBreakEvent; 11 | import me.asleepp.SkriptItemsAdder.SkriptItemsAdder; 12 | import me.asleepp.SkriptItemsAdder.aliases.AliasesGenerator; 13 | import me.asleepp.SkriptItemsAdder.util.Util; 14 | import org.bukkit.Location; 15 | import org.bukkit.event.Event; 16 | 17 | import javax.annotation.Nullable; 18 | import java.util.Arrays; 19 | import java.util.List; 20 | import java.util.stream.Collectors; 21 | import java.util.stream.Stream; 22 | 23 | public class EvtCustomBlockBreak extends SkriptEvent { 24 | 25 | private Literal[] blockNames; 26 | private List aliases; 27 | private AliasesGenerator aliasesGenerator = SkriptItemsAdder.getInstance().getAliasesGenerator(); 28 | 29 | static { 30 | Skript.registerEvent("Custom Block Break", EvtCustomBlockBreak.class, CustomBlockBreakEvent.class, "break [of] [custom] (ia|itemsadder) block[s] [%customitemtypes/strings%]") 31 | .description("Fires when a ItemsAdder block gets broken.") 32 | .examples( 33 | "on break of itemsadder block \"namespace:ruby_block\":", 34 | "on break of itemsadder block ruby block:" 35 | ) 36 | .since("1.0") 37 | .requiredPlugins("ItemsAdder"); 38 | EventValues.registerEventValue(CustomBlockBreakEvent.class, CustomBlock.class, new Getter() { 39 | @Override 40 | public CustomBlock get(CustomBlockBreakEvent event) { 41 | return CustomBlock.byAlreadyPlaced(event.getBlock()); 42 | } 43 | }, 0); 44 | EventValues.registerEventValue(CustomBlockBreakEvent.class, Location.class, new Getter() { 45 | @Override 46 | public Location get(CustomBlockBreakEvent event) { 47 | return event.getBlock().getLocation(); 48 | } 49 | }, 0); 50 | } 51 | 52 | @SuppressWarnings("unchecked") 53 | @Override 54 | public boolean init(Literal[] args, int matchedPattern, SkriptParser.ParseResult parseResult) { 55 | blockNames = args; 56 | if (blockNames != null) { 57 | aliases = Arrays.stream(blockNames) 58 | .flatMap(literal -> { 59 | if (literal != null) { 60 | return Arrays.stream(literal.getArray()) 61 | .map(Util::getCustomBlockId); 62 | } 63 | return Stream.empty(); 64 | }) 65 | .filter(name -> name != null) 66 | .collect(Collectors.toList()); 67 | } 68 | return true; 69 | } 70 | 71 | @Override 72 | public boolean check(Event event) { 73 | if (!(event instanceof CustomBlockBreakEvent)) { 74 | return false; 75 | } 76 | 77 | CustomBlockBreakEvent customEvent = (CustomBlockBreakEvent) event; 78 | if (customEvent.isCancelled()) { 79 | return false; 80 | } 81 | 82 | // Check block name 83 | if (aliases != null && !aliases.isEmpty()) { 84 | String actualBlockName = Util.getCustomBlockId(customEvent.getNamespacedID()); 85 | return aliases.contains(actualBlockName); 86 | } 87 | 88 | return true; 89 | } 90 | 91 | @Override 92 | public String toString(@Nullable Event e, boolean debug) { 93 | return "Custom Block Break event"; 94 | } 95 | } 96 | -------------------------------------------------------------------------------- /src/main/java/me/asleepp/SkriptItemsAdder/elements/events/blocks/EvtCustomBlockInteract.java: -------------------------------------------------------------------------------- 1 | package me.asleepp.SkriptItemsAdder.elements.events.blocks; 2 | 3 | import ch.njol.skript.Skript; 4 | import ch.njol.skript.lang.Literal; 5 | import ch.njol.skript.lang.SkriptEvent; 6 | import ch.njol.skript.lang.SkriptParser; 7 | import ch.njol.skript.registrations.EventValues; 8 | import ch.njol.skript.util.Getter; 9 | import dev.lone.itemsadder.api.CustomBlock; 10 | import dev.lone.itemsadder.api.Events.CustomBlockInteractEvent; 11 | import me.asleepp.SkriptItemsAdder.SkriptItemsAdder; 12 | import me.asleepp.SkriptItemsAdder.aliases.AliasesGenerator; 13 | import me.asleepp.SkriptItemsAdder.util.Util; 14 | import org.bukkit.Location; 15 | import org.bukkit.block.BlockFace; 16 | import org.bukkit.event.Event; 17 | import org.bukkit.event.block.Action; 18 | 19 | import javax.annotation.Nullable; 20 | import java.util.Arrays; 21 | import java.util.List; 22 | import java.util.stream.Collectors; 23 | import java.util.stream.Stream; 24 | 25 | 26 | public class EvtCustomBlockInteract extends SkriptEvent { 27 | 28 | private Literal[] blockNames; 29 | private List aliases; 30 | private AliasesGenerator aliasesGenerator = SkriptItemsAdder.getInstance().getAliasesGenerator(); 31 | 32 | static { 33 | Skript.registerEvent("Custom Block Interact", EvtCustomBlockInteract.class, CustomBlockInteractEvent.class, "interact with [custom] (ia|itemsadder) block[s] [%customitemtypes/strings%]") 34 | .description("Fires when a ItemsAdder block gets interacted with.") 35 | .examples("on interact with itemsadder block:") 36 | .since("1.0") 37 | .requiredPlugins("ItemsAdder"); 38 | EventValues.registerEventValue(CustomBlockInteractEvent.class, CustomBlock.class, new Getter() { 39 | @Override 40 | public CustomBlock get(CustomBlockInteractEvent event) { 41 | return CustomBlock.byAlreadyPlaced(event.getBlockClicked()); 42 | } 43 | }, EventValues.TIME_NOW); 44 | EventValues.registerEventValue(CustomBlockInteractEvent.class, Location.class, new Getter() { 45 | @Override 46 | public Location get(CustomBlockInteractEvent event) { 47 | return event.getBlockClicked().getLocation(); 48 | } 49 | }, EventValues.TIME_NOW); 50 | EventValues.registerEventValue(CustomBlockInteractEvent.class, Action.class, new Getter() { 51 | @Override 52 | public Action get(CustomBlockInteractEvent customBlockInteractEvent) { 53 | return customBlockInteractEvent.getAction(); 54 | } 55 | }, EventValues.TIME_NOW); 56 | EventValues.registerEventValue(CustomBlockInteractEvent.class, BlockFace.class, new Getter() { 57 | @Override 58 | public BlockFace get(CustomBlockInteractEvent customBlockInteractEvent) { 59 | return customBlockInteractEvent.getBlockFace(); 60 | } 61 | }, EventValues.TIME_NOW); 62 | } 63 | 64 | @SuppressWarnings("unchecked") 65 | @Override 66 | public boolean init(Literal[] args, int matchedPattern, SkriptParser.ParseResult parseResult) { 67 | blockNames = args; 68 | if (blockNames != null) { 69 | aliases = Arrays.stream(blockNames) 70 | .flatMap(literal -> { 71 | if (literal != null) { 72 | return Arrays.stream(literal.getArray()) 73 | .map(Util::getCustomBlockId); 74 | } 75 | return Stream.empty(); 76 | }) 77 | .filter(name -> name != null) 78 | .collect(Collectors.toList()); 79 | } 80 | return true; 81 | } 82 | 83 | @Override 84 | public boolean check(Event event) { 85 | if (!(event instanceof CustomBlockInteractEvent)) { 86 | return false; 87 | } 88 | 89 | CustomBlockInteractEvent customEvent = (CustomBlockInteractEvent) event; 90 | if (customEvent.isCancelled()) { 91 | return false; 92 | } 93 | 94 | // Check block name 95 | if (aliases != null && !aliases.isEmpty()) { 96 | String actualBlockName = Util.getCustomBlockId(customEvent.getNamespacedID()); 97 | return aliases.contains(actualBlockName); 98 | } 99 | 100 | return true; 101 | } 102 | 103 | @Override 104 | public String toString(@Nullable Event e, boolean debug) { 105 | return "Custom Block Interact event"; 106 | } 107 | } 108 | -------------------------------------------------------------------------------- /src/main/java/me/asleepp/SkriptItemsAdder/elements/events/blocks/EvtCustomBlockPlace.java: -------------------------------------------------------------------------------- 1 | package me.asleepp.SkriptItemsAdder.elements.events.blocks; 2 | 3 | import ch.njol.skript.Skript; 4 | import ch.njol.skript.lang.Literal; 5 | import ch.njol.skript.lang.SkriptEvent; 6 | import ch.njol.skript.lang.SkriptParser; 7 | import ch.njol.skript.registrations.EventValues; 8 | import ch.njol.skript.util.Getter; 9 | import dev.lone.itemsadder.api.CustomBlock; 10 | import dev.lone.itemsadder.api.Events.CustomBlockPlaceEvent; 11 | import me.asleepp.SkriptItemsAdder.SkriptItemsAdder; 12 | import me.asleepp.SkriptItemsAdder.aliases.AliasesGenerator; 13 | import me.asleepp.SkriptItemsAdder.util.Util; 14 | import org.bukkit.Location; 15 | import org.bukkit.event.Event; 16 | 17 | import javax.annotation.Nullable; 18 | import java.util.Arrays; 19 | import java.util.List; 20 | import java.util.stream.Collectors; 21 | import java.util.stream.Stream; 22 | 23 | public class EvtCustomBlockPlace extends SkriptEvent { 24 | 25 | private Literal[] blockNames; 26 | private List aliases; 27 | private final AliasesGenerator aliasesGenerator = SkriptItemsAdder.getInstance().getAliasesGenerator(); 28 | 29 | static { 30 | Skript.registerEvent("Custom Block Place", EvtCustomBlockPlace.class, CustomBlockPlaceEvent.class, "place [of] [custom] (ia|itemsadder) block[s] [%customitemtypes/strings%]") 31 | .description("Fires when a ItemsAdder block gets placed.") 32 | .examples("on place of itemsadder block:") 33 | .since("1.0") 34 | .requiredPlugins("ItemsAdder"); 35 | EventValues.registerEventValue(CustomBlockPlaceEvent.class, CustomBlock.class, new Getter() { 36 | @Override 37 | public CustomBlock get(CustomBlockPlaceEvent event) { 38 | return CustomBlock.byAlreadyPlaced(event.getBlock()); 39 | } 40 | }, 0); 41 | EventValues.registerEventValue(CustomBlockPlaceEvent.class, Location.class, new Getter() { 42 | @Override 43 | public Location get(CustomBlockPlaceEvent event) { 44 | return event.getBlock().getLocation(); 45 | } 46 | }, 0); 47 | } 48 | 49 | @SuppressWarnings("unchecked") 50 | @Override 51 | public boolean init(Literal[] args, int matchedPattern, SkriptParser.ParseResult parseResult) { 52 | blockNames = args; 53 | if (blockNames != null) { 54 | aliases = Arrays.stream(blockNames) 55 | .flatMap(literal -> { 56 | if (literal != null) { 57 | return Arrays.stream(literal.getArray()) 58 | .map(Util::getCustomBlockId); 59 | } 60 | return Stream.empty(); 61 | }) 62 | .filter(name -> name != null) 63 | .collect(Collectors.toList()); 64 | } 65 | return true; 66 | } 67 | 68 | @Override 69 | public boolean check(Event event) { 70 | if (!(event instanceof CustomBlockPlaceEvent)) { 71 | return false; 72 | } 73 | 74 | CustomBlockPlaceEvent customEvent = (CustomBlockPlaceEvent) event; 75 | if (customEvent.isCancelled()) { 76 | return false; 77 | } 78 | 79 | // Check block name 80 | if (aliases != null && !aliases.isEmpty()) { 81 | String actualBlockName = Util.getCustomBlockId(customEvent.getNamespacedID()); 82 | return aliases.contains(actualBlockName); 83 | } 84 | 85 | return true; 86 | } 87 | 88 | @Override 89 | public String toString(@Nullable Event e, boolean debug) { 90 | return "Custom Block Place event"; 91 | } 92 | } 93 | -------------------------------------------------------------------------------- /src/main/java/me/asleepp/SkriptItemsAdder/elements/events/furniture/EvtCustomFurnitureBreak.java: -------------------------------------------------------------------------------- 1 | package me.asleepp.SkriptItemsAdder.elements.events.furniture; 2 | 3 | import ch.njol.skript.Skript; 4 | import ch.njol.skript.lang.Literal; 5 | import ch.njol.skript.lang.SkriptEvent; 6 | import ch.njol.skript.lang.SkriptParser; 7 | import ch.njol.skript.registrations.EventValues; 8 | import ch.njol.skript.util.Getter; 9 | import dev.lone.itemsadder.api.CustomFurniture; 10 | import dev.lone.itemsadder.api.Events.FurnitureBreakEvent; 11 | import me.asleepp.SkriptItemsAdder.SkriptItemsAdder; 12 | import me.asleepp.SkriptItemsAdder.aliases.AliasesGenerator; 13 | import me.asleepp.SkriptItemsAdder.util.Util; 14 | import org.bukkit.Location; 15 | import org.bukkit.event.Event; 16 | 17 | import javax.annotation.Nullable; 18 | import java.util.Arrays; 19 | import java.util.List; 20 | import java.util.stream.Collectors; 21 | import java.util.stream.Stream; 22 | 23 | public class EvtCustomFurnitureBreak extends SkriptEvent { 24 | 25 | private Literal[] furnitureIDs; 26 | private List aliases; 27 | private AliasesGenerator aliasesGenerator = SkriptItemsAdder.getInstance().getAliasesGenerator(); 28 | 29 | static { 30 | Skript.registerEvent("Custom Furniture Break", EvtCustomFurnitureBreak.class, FurnitureBreakEvent.class, "break of [custom] (ia|itemsadder) furniture [%customitemtypes/strings%]") 31 | .description("Fires when a ItemsAdder furniture gets broken.") 32 | .examples("on break of itemsadder furniture:") 33 | .since("1.0") 34 | .requiredPlugins("ItemsAdder"); 35 | EventValues.registerEventValue(FurnitureBreakEvent.class, Location.class, new Getter() { 36 | @Override 37 | public @Nullable Location get(FurnitureBreakEvent event) { 38 | return event.getBukkitEntity().getLocation(); 39 | } 40 | }, 0); 41 | EventValues.registerEventValue(FurnitureBreakEvent.class, CustomFurniture.class, new Getter() { 42 | @Override 43 | public @Nullable CustomFurniture get(FurnitureBreakEvent event) { 44 | return event.getFurniture(); 45 | } 46 | }, 0); 47 | } 48 | 49 | @SuppressWarnings("unchecked") 50 | @Override 51 | public boolean init(Literal[] args, int matchedPattern, SkriptParser.ParseResult parseResult) { 52 | furnitureIDs = args; 53 | if (furnitureIDs != null) { 54 | aliases = Arrays.stream(furnitureIDs) 55 | .flatMap(literal -> { 56 | if (literal != null) { 57 | return Arrays.stream(literal.getArray()) 58 | .map(Util::getCustomBlockId); 59 | } 60 | return Stream.empty(); 61 | }) 62 | .filter(name -> name != null) 63 | .collect(Collectors.toList()); 64 | } 65 | return true; 66 | } 67 | 68 | @Override 69 | public boolean check(Event event) { 70 | if (event instanceof FurnitureBreakEvent furnEvent) { 71 | if (aliases != null && !aliases.isEmpty()) { 72 | String actualFurnitureName = Util.getCustomBlockId(furnEvent.getNamespacedID()); 73 | return aliases.contains(actualFurnitureName); 74 | } 75 | 76 | return !furnEvent.isCancelled(); 77 | } 78 | return false; 79 | } 80 | 81 | @Override 82 | public String toString(@Nullable Event e, boolean debug) { 83 | return "ItemsAdder custom furniture " + (furnitureIDs != null ? furnitureIDs.toString() : "") + " break"; 84 | } 85 | } 86 | -------------------------------------------------------------------------------- /src/main/java/me/asleepp/SkriptItemsAdder/elements/events/furniture/EvtCustomFurnitureInteract.java: -------------------------------------------------------------------------------- 1 | package me.asleepp.SkriptItemsAdder.elements.events.furniture; 2 | 3 | import ch.njol.skript.Skript; 4 | import ch.njol.skript.lang.Literal; 5 | import ch.njol.skript.lang.SkriptEvent; 6 | import ch.njol.skript.lang.SkriptParser; 7 | import ch.njol.skript.registrations.EventValues; 8 | import ch.njol.skript.util.Getter; 9 | import dev.lone.itemsadder.api.CustomFurniture; 10 | import dev.lone.itemsadder.api.Events.FurnitureBreakEvent; 11 | import dev.lone.itemsadder.api.Events.FurnitureInteractEvent; 12 | import me.asleepp.SkriptItemsAdder.SkriptItemsAdder; 13 | import me.asleepp.SkriptItemsAdder.aliases.AliasesGenerator; 14 | import me.asleepp.SkriptItemsAdder.util.Util; 15 | import org.bukkit.Location; 16 | import org.bukkit.event.Event; 17 | 18 | import javax.annotation.Nullable; 19 | import java.util.Arrays; 20 | import java.util.List; 21 | import java.util.stream.Collectors; 22 | import java.util.stream.Stream; 23 | 24 | public class EvtCustomFurnitureInteract extends SkriptEvent { 25 | 26 | private Literal[] furnitureIDs; 27 | private List aliases; 28 | private AliasesGenerator aliasesGenerator = SkriptItemsAdder.getInstance().getAliasesGenerator(); 29 | 30 | static { 31 | Skript.registerEvent("Custom Furniture Interact", EvtCustomFurnitureInteract.class, FurnitureInteractEvent.class, "interact with [custom] (ia|itemsadder) furniture [%customitemtypes/strings%]") 32 | .description("Fires when a ItemsAdder furniture gets interacted with.") 33 | .examples("on interact with itemsadder furniture:") 34 | .since("1.0") 35 | .requiredPlugins("ItemsAdder"); 36 | EventValues.registerEventValue(FurnitureInteractEvent.class, Location.class, new Getter() { 37 | @Override 38 | public @Nullable Location get(FurnitureInteractEvent event) { 39 | return event.getBukkitEntity().getLocation(); 40 | } 41 | }, 0); 42 | EventValues.registerEventValue(FurnitureInteractEvent.class, CustomFurniture.class, new Getter() { 43 | @Override 44 | public @Nullable CustomFurniture get(FurnitureInteractEvent event) { 45 | return event.getFurniture(); 46 | } 47 | }, 0); 48 | } 49 | 50 | @SuppressWarnings("unchecked") 51 | @Override 52 | public boolean init(Literal[] args, int matchedPattern, SkriptParser.ParseResult parseResult) { 53 | furnitureIDs = args; 54 | if (furnitureIDs != null) { 55 | aliases = Arrays.stream(furnitureIDs) 56 | .flatMap(literal -> { 57 | if (literal != null) { 58 | return Arrays.stream(literal.getArray()) 59 | .map(Util::getCustomBlockId); 60 | } 61 | return Stream.empty(); 62 | }) 63 | .filter(name -> name != null) 64 | .collect(Collectors.toList()); 65 | } 66 | return true; 67 | } 68 | 69 | @Override 70 | public boolean check(Event event) { 71 | if (event instanceof FurnitureBreakEvent furnEvent) { 72 | if (aliases != null && !aliases.isEmpty()) { 73 | String actualFurnitureName = Util.getCustomBlockId(furnEvent.getNamespacedID()); 74 | return aliases.contains(actualFurnitureName); 75 | } 76 | 77 | return !furnEvent.isCancelled(); 78 | } 79 | return false; 80 | } 81 | 82 | @Override 83 | public String toString(@Nullable Event e, boolean debug) { 84 | return "ItemsAdder custom furniture " + (furnitureIDs != null ? furnitureIDs.toString() : "") + " interact"; 85 | } 86 | } 87 | -------------------------------------------------------------------------------- /src/main/java/me/asleepp/SkriptItemsAdder/elements/events/furniture/EvtCustomFurniturePlace.java: -------------------------------------------------------------------------------- 1 | package me.asleepp.SkriptItemsAdder.elements.events.furniture; 2 | 3 | import ch.njol.skript.Skript; 4 | import ch.njol.skript.lang.Literal; 5 | import ch.njol.skript.lang.SkriptEvent; 6 | import ch.njol.skript.lang.SkriptParser; 7 | import dev.lone.itemsadder.api.Events.FurnitureBreakEvent; 8 | import dev.lone.itemsadder.api.Events.FurniturePlaceEvent; 9 | import me.asleepp.SkriptItemsAdder.SkriptItemsAdder; 10 | import me.asleepp.SkriptItemsAdder.aliases.AliasesGenerator; 11 | import me.asleepp.SkriptItemsAdder.util.Util; 12 | import org.bukkit.event.Event; 13 | 14 | import javax.annotation.Nullable; 15 | import java.util.Arrays; 16 | import java.util.List; 17 | import java.util.stream.Collectors; 18 | import java.util.stream.Stream; 19 | 20 | public class EvtCustomFurniturePlace extends SkriptEvent { 21 | 22 | private Literal[] furnitureIDs; 23 | private List aliases; 24 | private AliasesGenerator aliasesGenerator = SkriptItemsAdder.getInstance().getAliasesGenerator(); 25 | 26 | static { 27 | Skript.registerEvent("Custom Furniture Place", EvtCustomFurniturePlace.class, FurniturePlaceEvent.class, "place [of] [custom] (ia|itemsadder) furniture [%customitemtypes/strings%]") 28 | .description("Fires when a ItemsAdder furniture gets placed.") 29 | .examples("on place of itemsadder furniture:") 30 | .since("1.0") 31 | .requiredPlugins("ItemsAdder"); 32 | } 33 | 34 | @SuppressWarnings("unchecked") 35 | @Override 36 | public boolean init(Literal[] args, int matchedPattern, SkriptParser.ParseResult parseResult) { 37 | furnitureIDs = args; 38 | if (furnitureIDs != null) { 39 | aliases = Arrays.stream(furnitureIDs) 40 | .flatMap(literal -> { 41 | if (literal != null) { 42 | return Arrays.stream(literal.getArray()) 43 | .map(Util::getCustomBlockId); 44 | } 45 | return Stream.empty(); 46 | }) 47 | .filter(name -> name != null) 48 | .collect(Collectors.toList()); 49 | } 50 | return true; 51 | } 52 | 53 | @Override 54 | public boolean check(Event event) { 55 | if (event instanceof FurnitureBreakEvent furnEvent) { 56 | if (aliases != null && !aliases.isEmpty()) { 57 | String actualFurnitureName = Util.getCustomBlockId(furnEvent.getNamespacedID()); 58 | return aliases.contains(actualFurnitureName); 59 | } 60 | 61 | return !furnEvent.isCancelled(); 62 | } 63 | 64 | return true; 65 | } 66 | 67 | @Override 68 | public String toString(@Nullable Event e, boolean debug) { 69 | return "Custom Furniture Place event"; 70 | } 71 | } 72 | -------------------------------------------------------------------------------- /src/main/java/me/asleepp/SkriptItemsAdder/elements/events/furniture/EvtCustomFurnitureSuccessEvent.java: -------------------------------------------------------------------------------- 1 | package me.asleepp.SkriptItemsAdder.elements.events.furniture; 2 | 3 | import ch.njol.skript.Skript; 4 | import ch.njol.skript.lang.Literal; 5 | import ch.njol.skript.lang.SkriptEvent; 6 | import ch.njol.skript.lang.SkriptParser; 7 | import ch.njol.skript.registrations.EventValues; 8 | import ch.njol.skript.util.Getter; 9 | import dev.lone.itemsadder.api.CustomFurniture; 10 | import dev.lone.itemsadder.api.Events.FurnitureBreakEvent; 11 | import dev.lone.itemsadder.api.Events.FurniturePlaceSuccessEvent; 12 | import me.asleepp.SkriptItemsAdder.SkriptItemsAdder; 13 | import me.asleepp.SkriptItemsAdder.aliases.AliasesGenerator; 14 | import me.asleepp.SkriptItemsAdder.util.Util; 15 | import org.bukkit.Location; 16 | import org.bukkit.event.Event; 17 | 18 | import javax.annotation.Nullable; 19 | import java.util.Arrays; 20 | import java.util.List; 21 | import java.util.stream.Collectors; 22 | import java.util.stream.Stream; 23 | 24 | public class EvtCustomFurnitureSuccessEvent extends SkriptEvent { 25 | 26 | private Literal[] furnitureIDs; 27 | private List aliases; 28 | private AliasesGenerator aliasesGenerator = SkriptItemsAdder.getInstance().getAliasesGenerator(); 29 | 30 | static { 31 | Skript.registerEvent("Custom Furniture Success", EvtCustomFurnitureSuccessEvent.class, FurniturePlaceSuccessEvent.class, 32 | "success[fully] plac(e|ing) [a] [custom] (ia|itemsadder) furniture [%customitemtypes/strings%]", 33 | "place success [of] [custom] (ia|itemsadder) furniture [%customitemtypes/strings%]") 34 | .description("This event is called when a furniture is successfully placed into the world, use this event instead if you would like to know the location.") 35 | .examples( 36 | "on place success of custom itemsadder furniture:", 37 | "on successfully placing a custom itemsadder furniture:" 38 | ) 39 | .since("1.5") 40 | .requiredPlugins("ItemsAdder"); 41 | EventValues.registerEventValue(FurniturePlaceSuccessEvent.class, Location.class, new Getter() { 42 | @Override 43 | public Location get(FurniturePlaceSuccessEvent arg) { 44 | return arg.getBukkitEntity().getLocation(); 45 | } 46 | }, 0); 47 | EventValues.registerEventValue(FurniturePlaceSuccessEvent.class, CustomFurniture.class, new Getter() { 48 | @Override 49 | public @Nullable CustomFurniture get(FurniturePlaceSuccessEvent event) { 50 | return event.getFurniture(); 51 | } 52 | }, 0); 53 | } 54 | 55 | @SuppressWarnings("unchecked") 56 | @Override 57 | public boolean init(Literal[] args, int matchedPattern, SkriptParser.ParseResult parseResult) { 58 | furnitureIDs = args; 59 | if (furnitureIDs != null) { 60 | aliases = Arrays.stream(furnitureIDs) 61 | .flatMap(literal -> { 62 | if (literal != null) { 63 | return Arrays.stream(literal.getArray()) 64 | .map(Util::getCustomBlockId); 65 | } 66 | return Stream.empty(); 67 | }) 68 | .filter(name -> name != null) 69 | .collect(Collectors.toList()); 70 | } 71 | return true; 72 | } 73 | 74 | @Override 75 | public boolean check(Event event) { 76 | if (event instanceof FurnitureBreakEvent furnEvent) { 77 | if (aliases != null && !aliases.isEmpty()) { 78 | String actualFurnitureName = Util.getCustomBlockId(furnEvent.getNamespacedID()); 79 | return aliases.contains(actualFurnitureName); 80 | } 81 | 82 | return !furnEvent.isCancelled(); 83 | } 84 | return false; 85 | } 86 | 87 | @Override 88 | public String toString(@Nullable Event e, boolean debug) { 89 | return "Furniture Place Success event" + (furnitureIDs != null ? " with id " + Arrays.toString(furnitureIDs) : ""); 90 | } 91 | } 92 | -------------------------------------------------------------------------------- /src/main/java/me/asleepp/SkriptItemsAdder/elements/events/other/EvtCustomEntityDeath.java: -------------------------------------------------------------------------------- 1 | package me.asleepp.SkriptItemsAdder.elements.events.other; 2 | 3 | import ch.njol.skript.Skript; 4 | import ch.njol.skript.doc.Description; 5 | import ch.njol.skript.doc.Examples; 6 | import ch.njol.skript.doc.Name; 7 | import ch.njol.skript.doc.RequiredPlugins; 8 | import ch.njol.skript.doc.Since; 9 | import ch.njol.skript.lang.Literal; 10 | import ch.njol.skript.lang.SkriptEvent; 11 | import ch.njol.skript.lang.SkriptParser; 12 | import ch.njol.skript.registrations.EventValues; 13 | import ch.njol.skript.util.Getter; 14 | import dev.lone.itemsadder.api.Events.CustomEntityDeathEvent; 15 | import org.bukkit.Location; 16 | import org.bukkit.entity.Entity; 17 | import org.bukkit.event.Event; 18 | 19 | import javax.annotation.Nullable; 20 | @Name("On Custom Entity Death") 21 | @Description({"Fires when a ItemsAdder Entity dies."}) 22 | @Examples({"on custom entity death:"}) 23 | @Since("1.0") 24 | @RequiredPlugins("ItemsAdder") 25 | public class EvtCustomEntityDeath extends SkriptEvent { 26 | private Literal mobID; 27 | 28 | static { 29 | Skript.registerEvent("Custom Entity Death", EvtCustomEntityDeath.class, CustomEntityDeathEvent.class, "[custom] (ia|itemsadder) entity death [of %string%]") 30 | .description("Fires when a ItemsAdder Entity dies.") 31 | .examples("on itemsadder entity death:") 32 | .since("1.0") 33 | .requiredPlugins("ItemsAdder"); 34 | EventValues.registerEventValue(CustomEntityDeathEvent.class, Entity.class, new Getter() { 35 | @Override 36 | public @Nullable Entity get(CustomEntityDeathEvent customEntityDeathEvent) { 37 | return customEntityDeathEvent.getEntity(); 38 | } 39 | }, 0); 40 | EventValues.registerEventValue(CustomEntityDeathEvent.class, Location.class, new Getter() { 41 | @Override 42 | public @Nullable Location get(CustomEntityDeathEvent customEntityDeathEvent) { 43 | return customEntityDeathEvent.getEntity().getLocation(); 44 | } 45 | },0); 46 | EventValues.registerEventValue(CustomEntityDeathEvent.class, Entity.class, new Getter() { 47 | @Override 48 | public @Nullable Entity get(CustomEntityDeathEvent customEntityDeathEvent) { 49 | return customEntityDeathEvent.getKiller(); 50 | } 51 | }, 0); 52 | } 53 | 54 | @SuppressWarnings("unchecked") 55 | @Override 56 | public boolean init(Literal[] args, int matchedPattern, SkriptParser.ParseResult parseResult) { 57 | mobID = (Literal) args[0]; 58 | return true; 59 | } 60 | 61 | @Override 62 | public boolean check(Event e) { 63 | if (e instanceof CustomEntityDeathEvent) { 64 | CustomEntityDeathEvent event = (CustomEntityDeathEvent) e; 65 | if (mobID == null) { 66 | return true; 67 | } else { 68 | String id = event.getNamespacedID(); 69 | return id.equals(mobID.getSingle(e)); 70 | } 71 | } 72 | return false; 73 | } 74 | 75 | @Override 76 | public String toString(@Nullable Event e, boolean debug) { 77 | return "ItemsAdder custom entity " + (mobID != null ? mobID.toString(e, debug) : "") + " death"; 78 | } 79 | } 80 | -------------------------------------------------------------------------------- /src/main/java/me/asleepp/SkriptItemsAdder/elements/events/other/EvtEmote.java: -------------------------------------------------------------------------------- 1 | package me.asleepp.SkriptItemsAdder.elements.events.other; 2 | 3 | import ch.njol.skript.Skript; 4 | import ch.njol.skript.lang.Literal; 5 | import ch.njol.skript.lang.SkriptEvent; 6 | import ch.njol.skript.lang.SkriptParser; 7 | import ch.njol.util.coll.CollectionUtils; 8 | import dev.lone.itemsadder.api.Events.PlayerEmoteEndEvent; 9 | import dev.lone.itemsadder.api.Events.PlayerEmotePlayEvent; 10 | import org.bukkit.event.Event; 11 | 12 | import javax.annotation.Nullable; 13 | 14 | public class EvtEmote extends SkriptEvent { 15 | 16 | private Literal id; 17 | private PlayerEmoteEndEvent.Cause cause; 18 | private boolean checkCause; 19 | private int integer; 20 | 21 | static { 22 | Skript.registerEvent("Emote Play/Stop", EvtEmote.class, CollectionUtils.array(PlayerEmotePlayEvent.class, PlayerEmoteEndEvent.class), 23 | "(perform|play[ing]) [of] [custom] (ia|itemsadder) emote [%strings%]", 24 | "(stop|cancel[ing]) [of] [custom] (ia|itemsadder) emote [%strings%] [due to (:stop[ped]|:finish[ed]) [emote]]") 25 | .description("Called when a player begins to perform an emote.") 26 | .examples("on perform custom itemsadder emote:") 27 | .since("1.6") 28 | .requiredPlugins("ItemsAdder"); 29 | } 30 | 31 | @Override 32 | public boolean init(Literal[] args, int matchedPattern, SkriptParser.ParseResult parseResult) { 33 | this.integer = matchedPattern; 34 | this.id = (Literal) args[0]; 35 | if (parseResult.hasTag("stop")) { 36 | cause = PlayerEmoteEndEvent.Cause.STOP; 37 | checkCause = true; 38 | } else if (parseResult.hasTag("finish")) { 39 | cause = PlayerEmoteEndEvent.Cause.FINISHED; 40 | checkCause = true; 41 | } else { 42 | checkCause = false; 43 | } 44 | return true; 45 | } 46 | 47 | @Override 48 | public boolean check(Event event) { 49 | String emoteName = null; 50 | if (integer == 0 && event instanceof PlayerEmotePlayEvent) { 51 | emoteName = ((PlayerEmotePlayEvent) event).getEmoteName(); 52 | } else if (integer == 1 && event instanceof PlayerEmoteEndEvent) { 53 | PlayerEmoteEndEvent endEvent = (PlayerEmoteEndEvent) event; 54 | emoteName = endEvent.getEmoteName(); 55 | if (checkCause && endEvent.getCause() != cause) { 56 | return false; 57 | } 58 | } 59 | if (emoteName != null) { 60 | if (id != null) { 61 | for (String id : this.id.getArray(event)) { 62 | if (emoteName.equals(id)) { 63 | return true; 64 | } 65 | } 66 | } else { 67 | return true; 68 | } 69 | } 70 | return false; 71 | } 72 | 73 | @Override 74 | public String toString(@Nullable Event event, boolean debug) { 75 | return this.integer == 0 ? "perform emote" : "stop emote" + (id != null ? id.toString(event, debug) : ""); 76 | } 77 | } 78 | -------------------------------------------------------------------------------- /src/main/java/me/asleepp/SkriptItemsAdder/elements/events/other/EvtResourcePackSendEvent.java: -------------------------------------------------------------------------------- 1 | package me.asleepp.SkriptItemsAdder.elements.events.other; 2 | 3 | import ch.njol.skript.Skript; 4 | import ch.njol.skript.doc.Description; 5 | import ch.njol.skript.doc.Examples; 6 | import ch.njol.skript.doc.Name; 7 | import ch.njol.skript.doc.RequiredPlugins; 8 | import ch.njol.skript.doc.Since; 9 | import ch.njol.skript.lang.Literal; 10 | import ch.njol.skript.lang.SkriptEvent; 11 | import ch.njol.skript.lang.SkriptParser; 12 | import dev.lone.itemsadder.api.Events.ResourcePackSendEvent; 13 | import org.bukkit.event.Event; 14 | 15 | import javax.annotation.Nullable; 16 | 17 | public class EvtResourcePackSendEvent extends SkriptEvent { 18 | 19 | private boolean isItemsAdderPack; 20 | 21 | static { 22 | Skript.registerEvent("ItemsAdder Resource Pack Send Event", EvtResourcePackSendEvent.class, ResourcePackSendEvent.class, "[custom] [ia|itemsadder] (texture|resource) pack send") 23 | .description("Fires when a Resource pack from ItemsAdder gets sent to the player.") 24 | .examples( 25 | "on resource pack send:", 26 | "on ia resource pack send:" 27 | ) 28 | .since("1.0") 29 | .requiredPlugins("ItemsAdder"); 30 | } 31 | 32 | @Override 33 | public boolean init(Literal[] args, int matchedPattern, SkriptParser.ParseResult parseResult) { 34 | isItemsAdderPack = matchedPattern == 0; 35 | return true; 36 | } 37 | 38 | @Override 39 | public boolean check(Event event) { 40 | if (event instanceof ResourcePackSendEvent) { 41 | ResourcePackSendEvent rpEvent = (ResourcePackSendEvent) event; 42 | return isItemsAdderPack == rpEvent.isItemsAdderPack(); 43 | } 44 | return false; 45 | } 46 | 47 | @Override 48 | public String toString(@Nullable Event e, boolean debug) { 49 | return "Resource Pack Send Event"; 50 | } 51 | } 52 | -------------------------------------------------------------------------------- /src/main/java/me/asleepp/SkriptItemsAdder/elements/expressions/ExprCropAge.java: -------------------------------------------------------------------------------- 1 | package me.asleepp.SkriptItemsAdder.elements.expressions; 2 | 3 | import ch.njol.skript.Skript; 4 | import ch.njol.skript.classes.Changer; 5 | import ch.njol.skript.doc.Examples; 6 | import ch.njol.skript.doc.RequiredPlugins; 7 | import ch.njol.skript.doc.Since; 8 | import ch.njol.skript.lang.Expression; 9 | import ch.njol.skript.lang.ExpressionType; 10 | import ch.njol.skript.lang.SkriptParser; 11 | import ch.njol.skript.lang.util.SimpleExpression; 12 | import ch.njol.util.Kleenean; 13 | import dev.lone.itemsadder.api.CustomCrop; 14 | import jdk.jfr.Description; 15 | import jdk.jfr.Name; 16 | import org.bukkit.block.Block; 17 | import org.bukkit.event.Event; 18 | 19 | import javax.annotation.Nullable; 20 | 21 | @Name("Crop Age") 22 | @Description("Get or Set the age of a crop, or get the maximum age of one.") 23 | @Examples("send maximum age of custom itemsadder block {_crop}") 24 | @Since("1.6") 25 | @RequiredPlugins("ItemsAdder") 26 | 27 | public class ExprCropAge extends SimpleExpression { 28 | 29 | private Expression block; 30 | private boolean maxAge; 31 | 32 | static { 33 | Skript.registerExpression(ExprCropAge.class, Number.class, ExpressionType.SIMPLE, 34 | "[the] [:max[imum]] age of [custom] (ia|itemsadder) %blocks%", 35 | "[custom] (ia|itemsadder) %blocks%'[s] [:max[imum]] age"); 36 | } 37 | 38 | @Override 39 | public boolean init(Expression[] exprs, int matchedPattern, Kleenean isDelayed, SkriptParser.ParseResult parseResult) { 40 | block = (Expression) exprs[0]; 41 | maxAge = parseResult.hasTag("max"); 42 | return true; 43 | } 44 | 45 | @Nullable 46 | @Override 47 | protected Number[] get(Event e) { 48 | Block[] bs = block.getArray(e); 49 | Number[] ages = new Number[bs.length]; 50 | for (int i = 0; i < bs.length; i++) { 51 | CustomCrop crop = CustomCrop.byAlreadyPlaced(bs[i]); 52 | if (crop != null) { 53 | ages[i] = maxAge ? crop.getMaxAge() : crop.getAge(); 54 | } 55 | } 56 | return ages; 57 | } 58 | 59 | @Override 60 | public boolean isSingle() { 61 | return false; 62 | } 63 | 64 | @Override 65 | public Class getReturnType() { 66 | return Number.class; 67 | } 68 | 69 | @Override 70 | public String toString(@Nullable Event e, boolean debug) { 71 | return "age of " + block.toString(e, debug); 72 | } 73 | 74 | @Override 75 | public Class[] acceptChange(Changer.ChangeMode mode) { 76 | if (mode == Changer.ChangeMode.SET || mode == Changer.ChangeMode.ADD || mode == Changer.ChangeMode.REMOVE) 77 | return new Class[]{Number.class}; 78 | return null; 79 | } 80 | 81 | @Override 82 | public void change(Event e, Object[] delta, Changer.ChangeMode mode) { 83 | if (delta.length != 0) { 84 | int age = ((Number) delta[0]).intValue(); 85 | Block[] bs = block.getArray(e); 86 | for (Block b : bs) { 87 | CustomCrop crop = CustomCrop.byAlreadyPlaced(b); 88 | if (crop != null) { 89 | switch (mode) { 90 | case SET: 91 | crop.setAge(age); 92 | break; 93 | case ADD: 94 | crop.setAge(crop.getAge() + age); 95 | break; 96 | case REMOVE: 97 | crop.setAge(crop.getAge() - age); 98 | break; 99 | } 100 | } 101 | } 102 | } 103 | } 104 | } 105 | -------------------------------------------------------------------------------- /src/main/java/me/asleepp/SkriptItemsAdder/elements/expressions/ExprGetCustomItem.java: -------------------------------------------------------------------------------- 1 | package me.asleepp.SkriptItemsAdder.elements.expressions; 2 | 3 | import ch.njol.skript.Skript; 4 | import ch.njol.skript.aliases.ItemType; 5 | import ch.njol.skript.doc.Description; 6 | import ch.njol.skript.doc.Examples; 7 | import ch.njol.skript.doc.Name; 8 | import ch.njol.skript.doc.RequiredPlugins; 9 | import ch.njol.skript.doc.Since; 10 | import ch.njol.skript.lang.Expression; 11 | import ch.njol.skript.lang.ExpressionType; 12 | import ch.njol.skript.lang.SkriptParser; 13 | import ch.njol.skript.lang.util.SimpleExpression; 14 | import ch.njol.util.Kleenean; 15 | import dev.lone.itemsadder.api.CustomStack; 16 | import dev.lone.itemsadder.api.ItemsAdder; 17 | import me.asleepp.SkriptItemsAdder.aliases.CustomItemType; 18 | import org.bukkit.Material; 19 | import org.bukkit.event.Event; 20 | import org.bukkit.inventory.ItemStack; 21 | 22 | import javax.annotation.Nullable; 23 | import java.util.ArrayList; 24 | import java.util.List; 25 | 26 | @Name("ItemsAdder Item") 27 | @Description({"Gets an ItemsAdder item, or items."}) 28 | @Examples({ 29 | "give player itemsadder item \"_iainternal:icon_arrow_chest\"", 30 | "give player itemsadder items \"_iainternal:icon_back_orange\" and \"_iainternal:icon_cancel\"", 31 | "send all itemsadder items to player", 32 | "set {_paperItems::*} to all itemsadder items that uses material paper" 33 | }) 34 | @Since("1.0, 1.5 (multiple items)") 35 | @RequiredPlugins("ItemsAdder") 36 | public class ExprGetCustomItem extends SimpleExpression { 37 | 38 | private Expression itemTypes; 39 | private Expression itemStacks; 40 | private boolean usesItemMaterial; 41 | 42 | static { 43 | Skript.registerExpression(ExprGetCustomItem.class, ItemType.class, ExpressionType.COMBINED, 44 | "[custom] (ia|itemsadder) item[s] %customitemtypes/strings%", 45 | "(all [[of] the]) [custom] (ia|itemsadder) item[s] [1:(that uses|using) [item[s]|material[s]] %-itemstacks%]"); 46 | } 47 | 48 | @Override 49 | public boolean init(Expression[] exprs, int matchedPattern, Kleenean isDelayed, SkriptParser.ParseResult parseResult) { 50 | if (matchedPattern == 1) { 51 | usesItemMaterial = parseResult.mark == 1; 52 | if (usesItemMaterial) { 53 | itemStacks = (Expression) exprs[0]; 54 | } else { 55 | itemTypes = (Expression) exprs[0]; 56 | } 57 | } else { 58 | itemTypes = (Expression) exprs[0]; 59 | } 60 | return true; 61 | } 62 | 63 | @Override 64 | protected ItemType[] get(Event e) { 65 | List items = new ArrayList<>(); 66 | if (itemTypes != null) { 67 | if (itemTypes.isSingle()) { 68 | Object itemType = itemTypes.getSingle(e); 69 | if (itemType != null) { 70 | CustomStack customStack = getCustomStack(itemType); 71 | if (customStack != null) { 72 | items.add(new ItemType(customStack.getItemStack())); 73 | } 74 | } 75 | } else { 76 | for (Object itemType : itemTypes.getArray(e)) { 77 | CustomStack customStack = getCustomStack(itemType); 78 | if (customStack != null) { 79 | items.add(new ItemType(customStack.getItemStack())); 80 | } 81 | } 82 | } 83 | } else if (itemStacks != null) { 84 | for (ItemStack itemStack : itemStacks.getArray(e)) { 85 | Material material = itemStack.getType(); 86 | List customStacks = ItemsAdder.getAllItems(material); 87 | for (CustomStack customStack : customStacks) { 88 | items.add(new ItemType(customStack.getItemStack())); 89 | } 90 | } 91 | } else { 92 | List customStacks = ItemsAdder.getAllItems(); 93 | for (CustomStack customStack : customStacks) { 94 | items.add(new ItemType(customStack.getItemStack())); 95 | } 96 | } 97 | return items.toArray(new ItemType[0]); 98 | } 99 | 100 | private CustomStack getCustomStack(Object itemType) { 101 | if (itemType instanceof CustomItemType) { 102 | return CustomStack.getInstance(((CustomItemType) itemType).getNamespacedID()); 103 | } else if (itemType instanceof String) { 104 | return CustomStack.getInstance((String) itemType); 105 | } 106 | return null; 107 | } 108 | 109 | @Override 110 | public boolean isSingle() { 111 | return itemTypes != null && itemTypes.isSingle(); 112 | } 113 | 114 | @Override 115 | public Class getReturnType() { 116 | return ItemType.class; 117 | } 118 | 119 | @Override 120 | public String toString(@Nullable Event e, boolean debug) { 121 | if (usesItemMaterial) { 122 | return "ItemsAdder items that use item material " + itemStacks.toString(e, debug); 123 | } else { 124 | return "ItemsAdder items " + itemTypes.toString(e, debug); 125 | } 126 | } 127 | } 128 | -------------------------------------------------------------------------------- /src/main/java/me/asleepp/SkriptItemsAdder/elements/expressions/ExprGetFontImage.java: -------------------------------------------------------------------------------- 1 | package me.asleepp.SkriptItemsAdder.elements.expressions; 2 | 3 | import ch.njol.skript.Skript; 4 | import ch.njol.skript.doc.Description; 5 | import ch.njol.skript.doc.Examples; 6 | import ch.njol.skript.doc.Name; 7 | import ch.njol.skript.doc.RequiredPlugins; 8 | import ch.njol.skript.doc.Since; 9 | import ch.njol.skript.lang.Expression; 10 | import ch.njol.skript.lang.ExpressionType; 11 | import ch.njol.skript.lang.SkriptParser; 12 | import ch.njol.skript.lang.util.SimpleExpression; 13 | import ch.njol.util.Kleenean; 14 | import dev.lone.itemsadder.api.FontImages.FontImageWrapper; 15 | import org.bukkit.event.Event; 16 | import org.jetbrains.annotations.NotNull; 17 | import org.jetbrains.annotations.Nullable; 18 | 19 | import java.util.ArrayList; 20 | import java.util.List; 21 | 22 | @Name("Get ItemsAdder Font Image") 23 | @Description({"Gets ItemsAdder font image(s) with optional offset"}) 24 | @Examples({ 25 | "send font image \"emojis:crying_emoji\"", 26 | "set {_t::*} to font images \"emojis:laughing_emoji\" and \"emojis:crying_emoji\" with x offset 2" 27 | }) 28 | @Since("1.0, 1.5 (Multiple Images), 1.6 (With Offset)") 29 | @RequiredPlugins("ItemsAdder") 30 | public class ExprGetFontImage extends SimpleExpression { 31 | private Expression fontImageNames; 32 | private Expression offset; 33 | 34 | static { 35 | Skript.registerExpression(ExprGetFontImage.class, String.class, ExpressionType.SIMPLE, "[font|custom|ia|itemsadder] image[s] %strings% [with [x] offset %-integer%]"); 36 | } 37 | 38 | @Override 39 | public boolean init(Expression[] exprs, int matchedPattern, Kleenean isDelayed, SkriptParser.ParseResult parseResult) { 40 | fontImageNames = (Expression) exprs[0]; 41 | offset = (Expression) exprs[1]; 42 | return true; 43 | } 44 | 45 | @Nullable 46 | @Override 47 | protected String[] get(@NotNull Event e) { 48 | if (fontImageNames == null || fontImageNames.getArray(e) == null) { 49 | return null; 50 | } 51 | String[] strArray = fontImageNames.getArray(e); 52 | Integer offsetValue = offset != null ? offset.getSingle(e) : 0; 53 | List fontImages = new ArrayList<>(); 54 | for (String str : strArray) { 55 | FontImageWrapper fontImageWrapper = new FontImageWrapper(str); 56 | if (!fontImageWrapper.exists()) { 57 | continue; 58 | } 59 | fontImages.add(fontImageWrapper.applyPixelsOffset(offsetValue)); 60 | } 61 | return fontImages.toArray(new String[0]); 62 | } 63 | 64 | @NotNull 65 | @Override 66 | public Class getReturnType() { 67 | return String.class; 68 | } 69 | 70 | @Override 71 | public boolean isSingle() { 72 | return fontImageNames.isSingle(); 73 | } 74 | 75 | @NotNull 76 | @Override 77 | public String toString(@Nullable Event e, boolean debug) { 78 | return "font images " + fontImageNames.toString(e, debug) + (offset != null ? " with offset " + offset.toString(e, debug) : ""); 79 | } 80 | } 81 | -------------------------------------------------------------------------------- /src/main/java/me/asleepp/SkriptItemsAdder/elements/expressions/ExprGetHash.java: -------------------------------------------------------------------------------- 1 | package me.asleepp.SkriptItemsAdder.elements.expressions; 2 | 3 | import ch.njol.skript.Skript; 4 | import ch.njol.skript.doc.Description; 5 | import ch.njol.skript.doc.Examples; 6 | import ch.njol.skript.doc.Name; 7 | import ch.njol.skript.doc.RequiredPlugins; 8 | import ch.njol.skript.doc.Since; 9 | import ch.njol.skript.lang.ExpressionType; 10 | import ch.njol.skript.lang.Expression; 11 | import ch.njol.skript.lang.SkriptParser; 12 | import ch.njol.skript.lang.util.SimpleExpression; 13 | import ch.njol.util.Kleenean; 14 | import dev.lone.itemsadder.api.Events.ResourcePackSendEvent; 15 | import org.bukkit.event.Event; 16 | 17 | import javax.annotation.Nullable; 18 | 19 | @Name("Get Hash of Resource Pack") 20 | @Description({"Gets the hash of a resource pack."}) 21 | @Examples({"set {_t} to resource pack hash"}) 22 | @Since("1.0") 23 | @RequiredPlugins("ItemsAdder") 24 | public class ExprGetHash extends SimpleExpression { 25 | 26 | static { 27 | Skript.registerExpression(ExprGetHash.class, String.class, ExpressionType.SIMPLE, "[the] [ia|itemsadder] (texture|resource) pack hash"); 28 | } 29 | 30 | @Override 31 | protected String[] get(Event e) { 32 | if (e instanceof ResourcePackSendEvent) { 33 | ResourcePackSendEvent rpEvent = (ResourcePackSendEvent) e; 34 | return new String[]{rpEvent.getHash()}; 35 | } 36 | return null; 37 | } 38 | 39 | @Override 40 | public boolean isSingle() { 41 | return true; 42 | } 43 | 44 | @Override 45 | public Class getReturnType() { 46 | return String.class; 47 | } 48 | 49 | @Override 50 | public String toString(@Nullable Event e, boolean debug) { 51 | return "resource pack hash"; 52 | } 53 | 54 | @Override 55 | public boolean init(Expression[] exprs, int matchedPattern, Kleenean isDelayed, SkriptParser.ParseResult parseResult) { 56 | return true; 57 | } 58 | } 59 | -------------------------------------------------------------------------------- /src/main/java/me/asleepp/SkriptItemsAdder/elements/expressions/ExprGetID.java: -------------------------------------------------------------------------------- 1 | package me.asleepp.SkriptItemsAdder.elements.expressions; 2 | 3 | import ch.njol.skript.Skript; 4 | import ch.njol.skript.doc.Examples; 5 | import ch.njol.skript.doc.RequiredPlugins; 6 | import ch.njol.skript.doc.Since; 7 | import ch.njol.skript.lang.Expression; 8 | import ch.njol.skript.lang.ExpressionType; 9 | import ch.njol.skript.lang.SkriptParser; 10 | import ch.njol.skript.lang.util.SimpleExpression; 11 | import ch.njol.util.Kleenean; 12 | import dev.lone.itemsadder.api.CustomBlock; 13 | import dev.lone.itemsadder.api.CustomEntity; 14 | import dev.lone.itemsadder.api.CustomStack; 15 | import jdk.jfr.Description; 16 | import jdk.jfr.Name; 17 | import org.bukkit.block.Block; 18 | import org.bukkit.entity.Entity; 19 | import org.bukkit.event.Event; 20 | import org.bukkit.inventory.ItemStack; 21 | 22 | import javax.annotation.Nullable; 23 | import java.util.ArrayList; 24 | import java.util.List; 25 | 26 | @Name("Get ID") 27 | @Description("Gets the Namespaced:ID of your blocks, furnitures, or items.") 28 | @Examples("send id of itemsadder item player's tool") 29 | @Since("1.6") 30 | @RequiredPlugins("ItemsAdder") 31 | public class ExprGetID extends SimpleExpression { 32 | 33 | private Expression expr; 34 | 35 | static { 36 | Skript.registerExpression(ExprGetID.class, String.class, ExpressionType.SIMPLE, "id of [custom] (ia|itemsadder) [item|block|furniture] %itemstacks/blocks/entities%"); 37 | } 38 | 39 | @Override 40 | public boolean init(Expression[] exprs, int matchedPattern, Kleenean isDelayed, SkriptParser.ParseResult parseResult) { 41 | expr = exprs[0]; 42 | return true; 43 | } 44 | 45 | @Override 46 | protected String[] get(Event event) { 47 | Object[] objects = expr.getArray(event); 48 | List ids = new ArrayList<>(); 49 | for (Object object : objects) { 50 | if (object instanceof ItemStack) { 51 | CustomStack customStack = CustomStack.byItemStack((ItemStack) object); 52 | if (customStack != null) { 53 | ids.add(customStack.getNamespacedID()); 54 | } 55 | } else if (object instanceof Block) { 56 | CustomBlock customBlock = CustomBlock.byAlreadyPlaced((Block) object); 57 | if (customBlock != null) { 58 | ids.add(customBlock.getNamespacedID()); 59 | } 60 | } else if (object instanceof Entity) { 61 | CustomEntity customEntity = CustomEntity.byAlreadySpawned((Entity) object); 62 | if (customEntity != null) { 63 | ids.add(customEntity.getNamespacedID()); 64 | } 65 | } 66 | } 67 | return ids.toArray(new String[0]); 68 | } 69 | 70 | @Override 71 | public boolean isSingle() { 72 | return expr.isSingle(); 73 | } 74 | 75 | @Override 76 | public Class getReturnType() { 77 | return String.class; 78 | } 79 | 80 | @Override 81 | public String toString(@Nullable Event e, boolean debug) { 82 | return "id of [custom] (ia|itemsadder) " + expr.toString(e, debug); 83 | } 84 | } 85 | -------------------------------------------------------------------------------- /src/main/java/me/asleepp/SkriptItemsAdder/elements/expressions/ExprGetURL.java: -------------------------------------------------------------------------------- 1 | package me.asleepp.SkriptItemsAdder.elements.expressions; 2 | 3 | import ch.njol.skript.doc.Description; 4 | import ch.njol.skript.doc.Examples; 5 | import ch.njol.skript.doc.Name; 6 | import ch.njol.skript.doc.RequiredPlugins; 7 | import ch.njol.skript.doc.Since; 8 | import ch.njol.skript.lang.ExpressionType; 9 | import ch.njol.skript.Skript; 10 | import ch.njol.skript.lang.Expression; 11 | import ch.njol.skript.lang.SkriptParser; 12 | import ch.njol.skript.lang.util.SimpleExpression; 13 | import ch.njol.util.Kleenean; 14 | import dev.lone.itemsadder.api.Events.ResourcePackSendEvent; 15 | import org.bukkit.event.Event; 16 | 17 | import javax.annotation.Nullable; 18 | @Name("Get URL of Resource Pack") 19 | @Description({"Gets the URL of a resource pack."}) 20 | @Examples("set {_t} to resource pack url") 21 | @Since("1.0") 22 | @RequiredPlugins("ItemsAdder") 23 | public class ExprGetURL extends SimpleExpression { 24 | 25 | static { 26 | Skript.registerExpression(ExprGetURL.class, String.class, ExpressionType.SIMPLE, "[the] [ia|itemsadder] (texture|resource) pack (url|URL)"); 27 | } 28 | 29 | @Override 30 | protected String[] get(Event e) { 31 | if (e instanceof ResourcePackSendEvent) { 32 | ResourcePackSendEvent rpEvent = (ResourcePackSendEvent) e; 33 | return new String[]{rpEvent.getUrl()}; 34 | } 35 | return null; 36 | } 37 | 38 | @Override 39 | public boolean isSingle() { 40 | return true; 41 | } 42 | 43 | @Override 44 | public Class getReturnType() { 45 | return String.class; 46 | } 47 | 48 | @Override 49 | public String toString(@Nullable Event e, boolean debug) { 50 | return "resource pack url"; 51 | } 52 | 53 | @Override 54 | public boolean init(Expression[] exprs, int matchedPattern, Kleenean isDelayed, SkriptParser.ParseResult parseResult) { 55 | return true; 56 | } 57 | } 58 | -------------------------------------------------------------------------------- /src/main/java/me/asleepp/SkriptItemsAdder/elements/expressions/ExprLastCreatedIAGui.java: -------------------------------------------------------------------------------- 1 | package me.asleepp.SkriptItemsAdder.elements.expressions; 2 | 3 | import ch.njol.skript.Skript; 4 | import ch.njol.skript.doc.Description; 5 | import ch.njol.skript.doc.Examples; 6 | import ch.njol.skript.doc.Name; 7 | import ch.njol.skript.doc.RequiredPlugins; 8 | import ch.njol.skript.doc.Since; 9 | import ch.njol.skript.lang.Expression; 10 | import ch.njol.skript.lang.ExpressionType; 11 | import ch.njol.skript.lang.SkriptParser; 12 | import ch.njol.skript.lang.util.SimpleExpression; 13 | import ch.njol.util.Kleenean; 14 | import dev.lone.itemsadder.api.FontImages.TexturedInventoryWrapper; 15 | import me.asleepp.SkriptItemsAdder.elements.sections.SecCreateCustomInventory; 16 | import org.bukkit.event.Event; 17 | 18 | import javax.annotation.Nullable; 19 | @Name("Last Created ItemsAdder Gui") 20 | @Description("Gets the last created ItemsAdder inventory by the Create ItemsAdder Inventory section.") 21 | @Examples({ 22 | "create a new custom itemsadder inventory:", 23 | "\ttitle: \"Auction House\"", 24 | "\trows: 6", 25 | "\ttexture: \"inventory:auction_house\"", 26 | "set {_g} to last created ia gui"}) 27 | @Since("1.5") 28 | @RequiredPlugins("ItemsAdder") 29 | public class ExprLastCreatedIAGui extends SimpleExpression { 30 | 31 | static { 32 | Skript.registerExpression(ExprLastCreatedIAGui.class, TexturedInventoryWrapper.class, ExpressionType.SIMPLE, "last created [custom] (ia|itemsadder) gui"); 33 | } 34 | 35 | @Override 36 | public boolean init(Expression[] exprs, int matchedPattern, Kleenean isDelayed, SkriptParser.ParseResult parseResult) { 37 | return true; 38 | } 39 | 40 | @Override 41 | @Nullable 42 | protected TexturedInventoryWrapper[] get(Event event) { 43 | if (SecCreateCustomInventory.lastCreatedGui != null) { 44 | return new TexturedInventoryWrapper[]{SecCreateCustomInventory.lastCreatedGui}; 45 | } else { 46 | return null; 47 | } 48 | } 49 | 50 | 51 | @Override 52 | public boolean isSingle() { 53 | return true; 54 | } 55 | 56 | @Override 57 | public Class getReturnType() { 58 | return TexturedInventoryWrapper.class; 59 | } 60 | 61 | @Override 62 | public String toString(@Nullable Event e, boolean debug) { 63 | return "last created gui"; 64 | } 65 | } 66 | 67 | -------------------------------------------------------------------------------- /src/main/java/me/asleepp/SkriptItemsAdder/elements/sections/SecCreateCustomInventory.java: -------------------------------------------------------------------------------- 1 | package me.asleepp.SkriptItemsAdder.elements.sections; 2 | 3 | import ch.njol.skript.Skript; 4 | import ch.njol.skript.config.SectionNode; 5 | import ch.njol.skript.doc.Description; 6 | import ch.njol.skript.doc.Examples; 7 | import ch.njol.skript.doc.Name; 8 | import ch.njol.skript.doc.RequiredPlugins; 9 | import ch.njol.skript.doc.Since; 10 | import ch.njol.skript.lang.Expression; 11 | import ch.njol.skript.lang.Section; 12 | import ch.njol.skript.lang.SkriptParser.ParseResult; 13 | import ch.njol.skript.lang.TriggerItem; 14 | import ch.njol.skript.lang.util.SimpleLiteral; 15 | import ch.njol.util.Kleenean; 16 | import dev.lone.itemsadder.api.FontImages.FontImageWrapper; 17 | import dev.lone.itemsadder.api.FontImages.TexturedInventoryWrapper; 18 | import me.asleepp.SkriptItemsAdder.elements.types.Types; 19 | import org.bukkit.event.Event; 20 | import org.jetbrains.annotations.Nullable; 21 | import org.skriptlang.skript.lang.entry.EntryContainer; 22 | import org.skriptlang.skript.lang.entry.EntryValidator; 23 | import org.skriptlang.skript.lang.entry.util.ExpressionEntryData; 24 | 25 | import java.util.List; 26 | import java.util.UUID; 27 | 28 | @Name("Create Custom Inventory") 29 | @Description({ 30 | "Creates a new ItemsAdder inventory with the following properties:", 31 | "- Title: The title of the inventory. This will be displayed at the top of the inventory GUI.", 32 | "- Rows: The number of rows in the inventory. Each row corresponds to 9 slots, so an inventory with 3 rows would have 26 slots. You start at slot 0, so thats why its 26, not 27.)", 33 | "- Texture: The texture of the inventory. This should be the name of a texture defined in your ItemsAdder configuration. You may also have multple strings/textures here.", 34 | "- Title Offset: The horizontal offset of the title in pixels. This can be used to adjust the position of the title relative to the top of the inventory GUI.", 35 | "- Texture Offset: The horizontal offset of the texture in pixels. This can be used to adjust the position of the texture relative to the top of the inventory GUI.", 36 | "The last created inventory can be accessed using the 'Last Created Gui' expression.", 37 | "To create an Inventory, you need a Texture, everything else is optional. See Examples for a demonstration." 38 | }) 39 | @Examples({ 40 | "create a new custom itemsadder inventory:", 41 | "\ttitle: \"Shop\"", 42 | "\trows: 5", 43 | "\ttexture: \"inventory:shop\" and \"inventory:shop_extras\"", 44 | "\ttitle offset: 150", 45 | "\ttexture offset: 0", 46 | "set {_shop} to last created ia gui", 47 | "show custom {_gui} to all players"}) 48 | @Since("1.5") 49 | @RequiredPlugins("ItemsAdder") 50 | public class SecCreateCustomInventory extends Section { 51 | @Nullable 52 | public static TexturedInventoryWrapper lastCreatedGui; 53 | private Expression title; 54 | private Expression rows; 55 | private Expression texture; 56 | private Expression titleOffset; 57 | private Expression textureOffset; 58 | 59 | private static final EntryValidator validator = EntryValidator.builder() 60 | .addEntryData(new ExpressionEntryData<>("title", null, true, String.class)) 61 | .addEntryData(new ExpressionEntryData<>("rows", new SimpleLiteral<>(3, false), true, Integer.class)) 62 | .addEntryData(new ExpressionEntryData<>("texture", null, false, String.class)) // texture is required 63 | .addEntryData(new ExpressionEntryData<>("title offset", null, true, Integer.class)) 64 | .addEntryData(new ExpressionEntryData<>("texture offset", null, true, Integer.class)) 65 | .build(); 66 | 67 | static { 68 | Skript.registerSection(SecCreateCustomInventory.class, "create [a] [new] [custom] (ia|itemsadder) [chest] inventory"); 69 | } 70 | 71 | @Override 72 | public boolean init(Expression[] expressions, int matchedPattern, Kleenean isDelayed, ParseResult parseResult, SectionNode sectionNode, List triggerItems) { 73 | @Nullable EntryContainer entryContainer = validator.validate(sectionNode); 74 | if (entryContainer == null) 75 | return false; 76 | 77 | // Use getOptional to get the expressions 78 | this.title = (Expression) entryContainer.getOptional("title", true); 79 | if (this.title == null) return false; 80 | this.rows = (Expression) entryContainer.getOptional("rows", true); 81 | if (this.rows == null) return false; 82 | this.texture = (Expression) entryContainer.getOptional("texture", false); 83 | if (this.texture == null) return false; 84 | this.titleOffset = (Expression) entryContainer.getOptional("title offset", true); 85 | if (this.titleOffset == null) return false; 86 | this.textureOffset = (Expression) entryContainer.getOptional("texture offset", true); 87 | if (this.textureOffset == null) return false; 88 | 89 | if (this.texture == null) { 90 | Skript.error("A texture is required for creating an ItemsAdder inventory. If you'd like to create a normal inventory, please use the Skript inventory syntax, or another addon's syntax."); 91 | return false; 92 | } 93 | 94 | return true; 95 | } 96 | 97 | 98 | protected void execute(Event e) { 99 | String title = this.title.getSingle(e); 100 | int rows = this.rows.getSingle(e); 101 | String textures[] = this.texture.getArray(e); 102 | int titleOffset = this.titleOffset != null ? this.titleOffset.getSingle(e) : 0; 103 | int textureOffset = this.textureOffset != null ? this.textureOffset.getSingle(e) : 0; 104 | 105 | FontImageWrapper[] fontTextures = new FontImageWrapper[textures.length]; 106 | for (int i = 0; i < textures.length; i++) { 107 | fontTextures[i] = new FontImageWrapper(textures[i]); 108 | if (!fontTextures[i].exists()) { 109 | Skript.error("The specified texture does not exist: " + textures[i]); 110 | return; 111 | } 112 | } 113 | 114 | TexturedInventoryWrapper inventory = new TexturedInventoryWrapper(null, rows * 9, title, titleOffset, textureOffset, fontTextures); 115 | if (inventory != null) { 116 | String id = UUID.randomUUID().toString(); // uuid for storing inventory 117 | Types.inventoryMap.put(id, inventory); 118 | lastCreatedGui = inventory; 119 | } 120 | } 121 | 122 | 123 | 124 | @Override 125 | protected @Nullable TriggerItem walk(Event event) { 126 | debug(event, true); 127 | execute(event); 128 | return getNext(); 129 | } 130 | 131 | 132 | @Override 133 | public String toString(@Nullable Event e, boolean debug) { 134 | return "create a new itemsadder inventory"; 135 | } 136 | } 137 | 138 | 139 | -------------------------------------------------------------------------------- /src/main/java/me/asleepp/SkriptItemsAdder/elements/types/Types.java: -------------------------------------------------------------------------------- 1 | package me.asleepp.SkriptItemsAdder.elements.types; 2 | 3 | import ch.njol.skript.classes.ClassInfo; 4 | import ch.njol.skript.classes.EnumClassInfo; 5 | import ch.njol.skript.classes.Parser; 6 | import ch.njol.skript.classes.Serializer; 7 | import ch.njol.skript.lang.ParseContext; 8 | import ch.njol.skript.registrations.Classes; 9 | import ch.njol.yggdrasil.Fields; 10 | import dev.lone.itemsadder.api.FontImages.TexturedInventoryWrapper; 11 | import me.asleepp.SkriptItemsAdder.SkriptItemsAdder; 12 | import me.asleepp.SkriptItemsAdder.aliases.AliasesGenerator; 13 | import me.asleepp.SkriptItemsAdder.aliases.CustomItemType; 14 | import org.bukkit.block.BlockFace; 15 | import org.bukkit.event.block.Action; 16 | import org.jetbrains.annotations.NotNull; 17 | 18 | import javax.annotation.Nullable; 19 | import java.io.StreamCorruptedException; 20 | import java.util.HashMap; 21 | import java.util.Map; 22 | 23 | public class Types { 24 | 25 | public static Map inventoryMap = new HashMap<>(); 26 | 27 | static { 28 | Classes.registerClass(new ClassInfo<>(CustomItemType.class, "customitemtype") 29 | .user("customitemtypes?") 30 | .name("Custom Item Type") 31 | .description("Represents a custom item type using aliases.") 32 | .serializer(new Serializer() { 33 | private static final String FIELD_NAME = "namespacedID"; 34 | 35 | @Override 36 | public @NotNull Fields serialize(CustomItemType customItemType) { 37 | Fields fields = new Fields(); 38 | fields.putObject(FIELD_NAME, customItemType.getNamespacedID()); 39 | return fields; 40 | } 41 | 42 | @Override 43 | public void deserialize(CustomItemType customItemType, @NotNull Fields fields) { 44 | try { 45 | String namespacedID = (String) fields.getObject(FIELD_NAME); 46 | if (namespacedID != null) { 47 | customItemType.setNamespacedID(namespacedID); 48 | } 49 | } catch (StreamCorruptedException e) { 50 | e.printStackTrace(); 51 | } 52 | } 53 | 54 | @Override 55 | public @Nullable CustomItemType deserialize(@NotNull Fields fields) { 56 | try { 57 | String namespacedID = (String) fields.getObject(FIELD_NAME); 58 | return namespacedID != null ? new CustomItemType(namespacedID) : null; 59 | } catch (StreamCorruptedException e) { 60 | e.printStackTrace(); 61 | return null; 62 | } 63 | } 64 | 65 | @Override 66 | public boolean mustSyncDeserialization() { 67 | return true; 68 | } 69 | 70 | @Override 71 | public boolean canBeInstantiated() { 72 | return true; 73 | } 74 | }) 75 | .parser(new Parser() { 76 | @Override 77 | @Nullable 78 | public CustomItemType parse(@NotNull String s, @NotNull ParseContext context) { 79 | AliasesGenerator aliasesGenerator = SkriptItemsAdder.getInstance().getAliasesGenerator(); 80 | String namespacedID = aliasesGenerator.getNamespacedId(s.toLowerCase().replace("_", " ")); 81 | return namespacedID == null ? null : new CustomItemType(namespacedID); 82 | } 83 | 84 | @Override 85 | public @NotNull String toString(CustomItemType customItemType, int flags) { 86 | return customItemType.getNamespacedID(); 87 | } 88 | 89 | @Override 90 | public @NotNull String toVariableNameString(CustomItemType customItemType) { 91 | return customItemType.getNamespacedID(); 92 | } 93 | 94 | public String getVariableNamePattern() { 95 | return ".+"; 96 | } 97 | }) 98 | ); 99 | 100 | Classes.registerClass(new ClassInfo<>(TexturedInventoryWrapper.class, "texturedinventorywrapper") 101 | .user("texturedinventorywrappers?") 102 | .name("Textured Inventory Wrapper") 103 | .description("Represents a TexturedInventoryWrapper.") 104 | .since("1.0") 105 | .parser(new Parser() { 106 | 107 | @Override 108 | public TexturedInventoryWrapper parse(@NotNull String s, @NotNull ParseContext context) { 109 | return inventoryMap.get(s); 110 | } 111 | 112 | @Override 113 | public String toString(TexturedInventoryWrapper texturedInventoryWrapper, int flags) { 114 | for (Map.Entry entry : inventoryMap.entrySet()) { 115 | if (entry.getValue().equals(texturedInventoryWrapper)) { 116 | return entry.getKey(); 117 | } 118 | } 119 | return ""; 120 | } 121 | 122 | @Override 123 | public @NotNull String toVariableNameString(TexturedInventoryWrapper texturedInventoryWrapper) { 124 | return toString(texturedInventoryWrapper, 0); 125 | } 126 | 127 | public String getVariableNamePattern() { 128 | return ".+"; 129 | } 130 | })); 131 | if (Classes.getExactClassInfo(Action.class) == null) { 132 | Classes.registerClass(new EnumClassInfo<>(Action.class, "action", "actions") 133 | .user("actions?") 134 | .name("Action") 135 | .description("The action taken in an event.") 136 | .since("1.6")); 137 | } 138 | if (Classes.getExactClassInfo(BlockFace.class) == null) { 139 | Classes.registerClass(new EnumClassInfo<>(BlockFace.class, "blockface", "block faces") 140 | .user("block ?faces?") 141 | .name("Block faces") 142 | .description("The block face clicked in an event.") 143 | .since("1.6")); 144 | } 145 | } 146 | } 147 | -------------------------------------------------------------------------------- /src/main/java/me/asleepp/SkriptItemsAdder/listeners/ItemsAdderEventListener.java: -------------------------------------------------------------------------------- 1 | package me.asleepp.SkriptItemsAdder.listeners; 2 | 3 | import dev.lone.itemsadder.api.Events.ItemsAdderLoadDataEvent; 4 | import me.asleepp.SkriptItemsAdder.SkriptItemsAdder; 5 | import me.asleepp.SkriptItemsAdder.aliases.AliasesGenerator; 6 | import org.bukkit.Bukkit; 7 | import org.bukkit.event.EventHandler; 8 | import org.bukkit.event.Listener; 9 | 10 | public class ItemsAdderEventListener implements Listener { 11 | private final SkriptItemsAdder plugin; 12 | private final AliasesGenerator aliasesGenerator; 13 | 14 | public ItemsAdderEventListener(SkriptItemsAdder plugin, AliasesGenerator aliasesGenerator) { 15 | this.plugin = plugin; 16 | this.aliasesGenerator = aliasesGenerator; 17 | } 18 | 19 | @EventHandler 20 | public void onItemsAdderLoadData(ItemsAdderLoadDataEvent event) { 21 | // run alias generation async 22 | generateAliases(); 23 | } 24 | 25 | public void generateAliases() { 26 | Bukkit.getScheduler().runTaskAsynchronously(plugin, () -> { 27 | aliasesGenerator.generateAliasesForAllItems(); 28 | aliasesGenerator.saveAliases(); 29 | }); 30 | } 31 | 32 | } 33 | -------------------------------------------------------------------------------- /src/main/java/me/asleepp/SkriptItemsAdder/util/SkriptItemsAdderCommand.java: -------------------------------------------------------------------------------- 1 | package me.asleepp.SkriptItemsAdder.util; 2 | 3 | import ch.njol.skript.Skript; 4 | import dev.lone.itemsadder.api.ItemsAdder; 5 | import me.asleepp.SkriptItemsAdder.SkriptItemsAdder; 6 | import me.asleepp.SkriptItemsAdder.aliases.AliasesGenerator; 7 | import org.bukkit.Bukkit; 8 | import org.bukkit.command.Command; 9 | import org.bukkit.command.CommandExecutor; 10 | import org.bukkit.command.CommandSender; 11 | import org.bukkit.command.TabCompleter; 12 | import org.bukkit.scheduler.BukkitRunnable; 13 | import org.jetbrains.annotations.NotNull; 14 | import org.jetbrains.annotations.Nullable; 15 | 16 | import java.util.Collections; 17 | import java.util.List; 18 | 19 | public class SkriptItemsAdderCommand implements CommandExecutor, TabCompleter { 20 | 21 | private SkriptItemsAdder plugin = SkriptItemsAdder.getInstance(); 22 | private final AliasesGenerator aliasesGenerator = new AliasesGenerator(plugin); 23 | 24 | public SkriptItemsAdderCommand(SkriptItemsAdder plugin) { 25 | this.plugin = plugin; 26 | plugin.getCommand("skriptitemsadder").setExecutor(this); 27 | plugin.getCommand("skriptitemsadder").setTabCompleter(this); 28 | } 29 | 30 | @Override 31 | public boolean onCommand(@NotNull CommandSender sender, @NotNull Command command, @NotNull String s, @NotNull String[] args) { 32 | if (args.length == 0) { 33 | Util.sendMiniMessage(sender, true, "Please provide an argument!"); 34 | return false; 35 | } 36 | if (args[0].equalsIgnoreCase("reload")) { 37 | switch (args[1]) { 38 | case "all": 39 | Util.sendMiniMessage(sender, true, "Reloading aliases and configuration..."); 40 | 41 | new BukkitRunnable() { 42 | @Override 43 | public void run() { 44 | aliasesGenerator.loadAliasesFile(); 45 | aliasesGenerator.loadAliasesFromFile(); 46 | aliasesGenerator.generateAliasesForAllItems(); 47 | aliasesGenerator.saveAliases(); 48 | aliasesGenerator.syncAliasesWithProvider(); 49 | sender.sendMessage("Aliases have been reloaded."); 50 | } 51 | }.runTaskAsynchronously(plugin); 52 | 53 | plugin.reloadConfig(); 54 | break; 55 | case "config": 56 | Util.sendMiniMessage(sender, true, "Reloading the configuration..."); 57 | plugin.reloadConfig(); 58 | Util.sendMiniMessage(sender, true, "Reloaded the configuration..."); 59 | break; 60 | case "aliases": 61 | Util.sendMiniMessage(sender, true, "Reloading aliases..."); 62 | 63 | new BukkitRunnable() { 64 | @Override 65 | public void run() { 66 | aliasesGenerator.loadAliasesFile(); 67 | aliasesGenerator.loadAliasesFromFile(); 68 | aliasesGenerator.generateAliasesForAllItems(); 69 | aliasesGenerator.saveAliases(); 70 | aliasesGenerator.syncAliasesWithProvider(); 71 | Util.sendMiniMessage(sender, true, "Aliases have been reloaded."); 72 | } 73 | }.runTaskAsynchronously(plugin); 74 | break; 75 | } 76 | 77 | } 78 | 79 | if (args[0].equalsIgnoreCase("info")) { 80 | Util.sendMiniMessage(sender, ""); 81 | Util.sendMiniMessage(sender, "-----------= INFO =-----------"); 82 | Util.sendMiniMessage(sender, ""); 83 | Util.sendMiniMessage(sender, "Total Items registered with ItemsAdder: " + ItemsAdder.getAllItems().size()); 84 | Util.sendMiniMessage(sender, "Total aliases registered with skript-itemsadder: " + aliasesGenerator.getGeneratedAliases().size()); 85 | Util.sendMiniMessage(sender, "Update Checker: " + plugin.getConfig().getString("check-for-updates")); 86 | Util.sendMiniMessage(sender, ""); 87 | Util.sendMiniMessage(sender, "-----------= MISC =-----------"); 88 | Util.sendMiniMessage(sender, ""); 89 | Util.sendMiniMessage(sender, "Server Version: " + Bukkit.getVersion()); 90 | Util.sendMiniMessage(sender, "ItemsAdder Version: " + Util.getPluginVersion("ItemsAdder")); 91 | Util.sendMiniMessage(sender, "LoneLibs Version: " + Util.getPluginVersion("LoneLibs")); 92 | Util.sendMiniMessage(sender, "ProtocolLib Version: " + Util.getPluginVersion("ProtocolLib")); 93 | Util.sendMiniMessage(sender, "Skript Version: " + Skript.getVersion()); 94 | Util.sendMiniMessage(sender, ""); 95 | Util.sendMiniMessage(sender, "If you find any issues with skript-itemsadder, please report it to the GitHub: CLICK ME"); 96 | Util.sendMiniMessage(sender, ""); 97 | return true; 98 | } 99 | return true; 100 | } 101 | 102 | @Override 103 | public @Nullable List onTabComplete(@NotNull CommandSender commandSender, @NotNull Command command, @NotNull String s, @NotNull String[] args) { 104 | if (args.length == 1) { 105 | return List.of("reload", "info"); 106 | } else if (args.length == 2) { 107 | return List.of("all", "config", "aliases"); 108 | } 109 | return Collections.emptyList(); 110 | } 111 | } 112 | -------------------------------------------------------------------------------- /src/main/java/me/asleepp/SkriptItemsAdder/util/UpdateChecker.java: -------------------------------------------------------------------------------- 1 | package me.asleepp.SkriptItemsAdder.util; 2 | 3 | import com.google.gson.Gson; 4 | import com.google.gson.JsonObject; 5 | import me.asleepp.SkriptItemsAdder.SkriptItemsAdder; 6 | import org.bukkit.Bukkit; 7 | import org.bukkit.entity.Player; 8 | import org.bukkit.event.EventHandler; 9 | import org.bukkit.event.Listener; 10 | import org.bukkit.event.player.PlayerJoinEvent; 11 | import org.bukkit.plugin.java.JavaPlugin; 12 | 13 | import java.net.URI; 14 | import java.net.http.HttpClient; 15 | import java.net.http.HttpRequest; 16 | import java.net.http.HttpResponse; 17 | import java.util.concurrent.CompletableFuture; 18 | 19 | public class UpdateChecker implements Listener { 20 | 21 | private final JavaPlugin plugin; 22 | private final String currentVersion; 23 | private String latestVersion; 24 | 25 | public UpdateChecker(JavaPlugin plugin) { 26 | this.plugin = plugin; 27 | this.currentVersion = plugin.getDescription().getVersion(); 28 | Bukkit.getPluginManager().registerEvents(this, plugin); 29 | checkForUpdate(); 30 | } 31 | 32 | @EventHandler 33 | public void onPlayerJoin(PlayerJoinEvent event) { 34 | Player player = event.getPlayer(); 35 | if (player.hasPermission("skript-itemsadder.update.check") && latestVersion != null) { 36 | if (!currentVersion.equals(latestVersion)) { 37 | player.sendMessage(" "); 38 | player.sendRichMessage("[skript-itemsadder] skript-itemsadder is OUTDATED!"); 39 | player.sendRichMessage("[skript-itemsadder] New version: " + latestVersion); 40 | player.sendRichMessage("[skript-itemsadder] Download Click here to get the latest version!'>here!"); 41 | player.sendMessage(" "); 42 | } 43 | } 44 | } 45 | 46 | private void checkForUpdate() { 47 | HttpClient httpClient = HttpClient.newHttpClient(); 48 | HttpRequest request = HttpRequest.newBuilder() 49 | .uri(URI.create("https://api.github.com/repos/asleeepp/skript-itemsadder/releases/latest")) 50 | .build(); 51 | 52 | CompletableFuture> responseFuture = httpClient.sendAsync(request, HttpResponse.BodyHandlers.ofString()); 53 | 54 | responseFuture.thenApply(HttpResponse::body) 55 | .thenAccept(body -> { 56 | JsonObject jsonResponse = new Gson().fromJson(body, JsonObject.class); 57 | if (jsonResponse != null && jsonResponse.has("tag_name")) { 58 | latestVersion = jsonResponse.get("tag_name").getAsString(); 59 | 60 | if (!currentVersion.equals(latestVersion)) { 61 | SkriptItemsAdder.getInstance().getLogger().warning("An update for skript-itemsadder is available: " + latestVersion + " (current version: " + currentVersion + ")"); 62 | } else { 63 | SkriptItemsAdder.getInstance().getLogger().info("skript-itemsadder is up to date!"); 64 | } 65 | } else { 66 | SkriptItemsAdder.getInstance().getLogger().severe("Failed to check for updates: Unexpected JSON format."); 67 | } 68 | }) 69 | .exceptionally(e -> { 70 | SkriptItemsAdder.getInstance().getLogger().severe("Failed to check for updates: " + e.getMessage()); 71 | return null; 72 | }); 73 | } 74 | 75 | } -------------------------------------------------------------------------------- /src/main/java/me/asleepp/SkriptItemsAdder/util/Util.java: -------------------------------------------------------------------------------- 1 | package me.asleepp.SkriptItemsAdder.util; 2 | 3 | import dev.lone.itemsadder.api.CustomBlock; 4 | import me.asleepp.SkriptItemsAdder.aliases.CustomItemType; 5 | import net.kyori.adventure.text.minimessage.MiniMessage; 6 | import org.bukkit.Bukkit; 7 | import org.bukkit.plugin.Plugin; 8 | import org.bukkit.command.CommandSender; 9 | import org.bukkit.entity.Player; 10 | 11 | public class Util { 12 | 13 | private static final String prefix = "skript-itemsadder ➜"; 14 | 15 | public static void sendMiniMessage(Player player, String message) { 16 | player.sendMessage(MiniMessage.miniMessage().deserialize(message)); 17 | } 18 | 19 | public static void sendMiniMessage(Player player, boolean usePrefix, String message) { 20 | String fullMessage = usePrefix ? prefix + " " + message : message; 21 | player.sendMessage(MiniMessage.miniMessage().deserialize(fullMessage)); 22 | } 23 | 24 | public static void sendMiniMessage(CommandSender sender, String message) { 25 | if (sender instanceof Player) { 26 | sendMiniMessage((Player) sender, message); 27 | } else { 28 | sender.sendMessage(MiniMessage.miniMessage().deserialize(message)); 29 | } 30 | } 31 | 32 | public static void sendMiniMessage(CommandSender sender, boolean usePrefix, String message) { 33 | String fullMessage = usePrefix ? prefix + " " + message : message; 34 | if (sender instanceof Player) { 35 | sendMiniMessage((Player) sender, fullMessage); 36 | } else { 37 | sender.sendMessage(MiniMessage.miniMessage().deserialize(fullMessage)); 38 | } 39 | } 40 | 41 | public static String getPluginVersion(String pluginName) { 42 | Plugin plugin = Bukkit.getPluginManager().getPlugin(pluginName); 43 | if (plugin != null) { 44 | return plugin.getPluginMeta().getVersion(); 45 | } else { 46 | return "Unknown"; 47 | } 48 | } 49 | 50 | public static String getCustomBlockId(Object itemType) { 51 | if (itemType == null) { 52 | return null; 53 | } 54 | if (itemType instanceof CustomItemType customItemType) { 55 | return customItemType.getNamespacedID(); 56 | } else if (itemType instanceof String stringItemType) { 57 | CustomBlock customBlock = CustomBlock.getInstance(stringItemType); 58 | return customBlock != null ? stringItemType : null; 59 | } 60 | return null; 61 | } 62 | 63 | 64 | } 65 | -------------------------------------------------------------------------------- /src/main/resources/aliases.yml: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Asleeepp/skript-itemsadder/3d6f6c72f2cd4db55b12a6bd3a7ddade79e376df/src/main/resources/aliases.yml -------------------------------------------------------------------------------- /src/main/resources/config.yml: -------------------------------------------------------------------------------- 1 | # Enable or disable the Update Checker. 2 | check-for-updates: true -------------------------------------------------------------------------------- /src/main/resources/lang/english.lang: -------------------------------------------------------------------------------- 1 | version: @version@ 2 | 3 | types: 4 | texturedinventorywrapper: texturedinventorywrapper 5 | customitemtype: custom item type 6 | action: action|s 7 | blockface: block face|s 8 | 9 | actions: 10 | left_click_air: left click air 11 | right_click_air: right click air 12 | left_click_block: left click block 13 | right_click_block: right click block 14 | physical: physical 15 | 16 | block faces: 17 | down: down 18 | east: east 19 | east_north_east: east north east 20 | east_south_east: east south east 21 | north: north 22 | north_east: north east 23 | north_north_east: north north east 24 | north_north_west: north north west 25 | north_west: north west 26 | self: self 27 | south: south 28 | south_east: south east 29 | south_south_east: south south east 30 | south_south_west: south south west 31 | south_west: south west 32 | up: up 33 | west: west 34 | west_north_west: west north west 35 | west_south_west: west south west -------------------------------------------------------------------------------- /src/main/resources/plugin.yml: -------------------------------------------------------------------------------- 1 | name: skript-itemsadder 2 | authors: [Asleepp] 3 | description: A Skript Addon that adds useful syntax to be used in conjunction with ItemsAdder 4 | api-version: 1.13 5 | version: ${version} 6 | main: me.asleepp.SkriptItemsAdder.SkriptItemsAdder 7 | depend: [Skript, ItemsAdder] 8 | 9 | 10 | commands: 11 | skriptitemsadder: 12 | description: Reload the plugin's config or see information --------------------------------------------------------------------------------