├── .github
└── workflows
│ └── gradle.yml
├── .gitignore
├── .run
└── Build.run.xml
├── LICENSE
├── LevelTools Large Logo.png
├── LevelTools.png
├── README.md
├── build.gradle
├── gradle
└── wrapper
│ ├── gradle-wrapper.jar
│ └── gradle-wrapper.properties
├── gradlew
├── gradlew.bat
├── jitpack.yml
├── libs
└── folia-api-1.20.4-R0.1-SNAPSHOT.jar
├── settings.gradle
└── src
└── main
├── java
└── me
│ └── byteful
│ └── plugin
│ └── leveltools
│ ├── LevelToolsCommand.java
│ ├── LevelToolsPlaceholders.java
│ ├── LevelToolsPlugin.java
│ ├── api
│ ├── AnvilCombineMode.java
│ ├── RewardType.java
│ ├── block
│ │ ├── BlockDataManager.java
│ │ ├── BlockDataManagerFactory.java
│ │ ├── BlockPosition.java
│ │ └── impl
│ │ │ └── FileBlockDataManager.java
│ ├── event
│ │ ├── LevelToolsLevelIncreaseEvent.java
│ │ └── LevelToolsXPIncreaseEvent.java
│ ├── item
│ │ ├── LevelToolsItem.java
│ │ └── impl
│ │ │ ├── NBTLevelToolsItem.java
│ │ │ └── PDCLevelToolsItem.java
│ └── scheduler
│ │ ├── ScheduledTask.java
│ │ ├── Scheduler.java
│ │ └── impl
│ │ ├── bukkit
│ │ ├── BukkitScheduledTask.java
│ │ └── BukkitScheduler.java
│ │ └── folia
│ │ ├── FoliaScheduledTask.java
│ │ └── FoliaScheduler.java
│ ├── listeners
│ ├── AnvilListener.java
│ ├── BlockEventListener.java
│ ├── EntityEventListener.java
│ └── XPListener.java
│ ├── model
│ └── LevelAndXPModel.java
│ └── util
│ ├── LevelToolsUtil.java
│ ├── Text.java
│ ├── UpdateChecker.java
│ └── XPBooster.java
└── resources
├── config.yml
└── plugin.yml
/.github/workflows/gradle.yml:
--------------------------------------------------------------------------------
1 | # This workflow uses actions that are not certified by GitHub.
2 | # They are provided by a third-party and are governed by
3 | # separate terms of service, privacy policy, and support
4 | # documentation.
5 | # This workflow will build a Java project with Gradle and cache/restore any dependencies to improve the workflow execution time
6 | # For more information see: https://help.github.com/actions/language-and-framework-guides/building-and-testing-java-with-gradle
7 |
8 | name: Java CI with Gradle
9 |
10 | on:
11 | push:
12 | branches: [ master ]
13 | pull_request:
14 | branches: [ master ]
15 |
16 | jobs:
17 | build:
18 |
19 | runs-on: ubuntu-latest
20 |
21 | steps:
22 | - uses: actions/checkout@v2
23 | - name: Set up JDK 17
24 | uses: actions/setup-java@v2
25 | with:
26 | java-version: '17'
27 | distribution: 'adopt'
28 | - name: Change wrapper permissions
29 | run: chmod +x ./gradlew
30 | - name: Build with Gradle
31 | run: ./gradlew build
32 |
--------------------------------------------------------------------------------
/.gitignore:
--------------------------------------------------------------------------------
1 |
2 | # Created by https://www.toptal.com/developers/gitignore/api/gradle,java,intellij+all
3 | # Edit at https://www.toptal.com/developers/gitignore?templates=gradle,java,intellij+all
4 |
5 | ### Intellij+all ###
6 | # Covers JetBrains IDEs: IntelliJ, RubyMine, PhpStorm, AppCode, PyCharm, CLion, Android Studio, WebStorm and Rider
7 | # Reference: https://intellij-support.jetbrains.com/hc/en-us/articles/206544839
8 |
9 | # User-specific stuff
10 | .idea/**/workspace.xml
11 | .idea/**/tasks.xml
12 | .idea/**/usage.statistics.xml
13 | .idea/**/dictionaries
14 | .idea/**/shelf
15 |
16 | # AWS User-specific
17 | .idea/**/aws.xml
18 |
19 | # Generated files
20 | .idea/**/contentModel.xml
21 |
22 | # Sensitive or high-churn files
23 | .idea/**/dataSources/
24 | .idea/**/dataSources.ids
25 | .idea/**/dataSources.local.xml
26 | .idea/**/sqlDataSources.xml
27 | .idea/**/dynamic.xml
28 | .idea/**/uiDesigner.xml
29 | .idea/**/dbnavigator.xml
30 |
31 | # Gradle
32 | .idea/**/gradle.xml
33 | .idea/**/libraries
34 |
35 | # Gradle and Maven with auto-import
36 | # When using Gradle or Maven with auto-import, you should exclude module files,
37 | # since they will be recreated, and may cause churn. Uncomment if using
38 | # auto-import.
39 | # .idea/artifacts
40 | # .idea/compiler.xml
41 | # .idea/jarRepositories.xml
42 | # .idea/modules.xml
43 | # .idea/*.iml
44 | # .idea/modules
45 | # *.iml
46 | # *.ipr
47 |
48 | # CMake
49 | cmake-build-*/
50 |
51 | # Mongo Explorer plugin
52 | .idea/**/mongoSettings.xml
53 |
54 | # File-based project format
55 | *.iws
56 |
57 | # IntelliJ
58 | out/
59 |
60 | # mpeltonen/sbt-idea plugin
61 | .idea_modules/
62 |
63 | # JIRA plugin
64 | atlassian-ide-plugin.xml
65 |
66 | # Cursive Clojure plugin
67 | .idea/replstate.xml
68 |
69 | # Crashlytics plugin (for Android Studio and IntelliJ)
70 | com_crashlytics_export_strings.xml
71 | crashlytics.properties
72 | crashlytics-build.properties
73 | fabric.properties
74 |
75 | # Editor-based Rest Client
76 | .idea/httpRequests
77 |
78 | # Android studio 3.1+ serialized cache file
79 | .idea/caches/build_file_checksums.ser
80 |
81 | ### Intellij+all Patch ###
82 | # Ignores the whole .idea folder and all .iml files
83 | # See https://github.com/joeblau/gitignore.io/issues/186 and https://github.com/joeblau/gitignore.io/issues/360
84 |
85 | .idea/
86 |
87 | # Reason: https://github.com/joeblau/gitignore.io/issues/186#issuecomment-249601023
88 |
89 | *.iml
90 | modules.xml
91 | .idea/misc.xml
92 | *.ipr
93 |
94 | # Sonarlint plugin
95 | .idea/sonarlint
96 |
97 | ### Java ###
98 | # Compiled class file
99 | *.class
100 |
101 | # Log file
102 | *.log
103 |
104 | # BlueJ files
105 | *.ctxt
106 |
107 | # Mobile Tools for Java (J2ME)
108 | .mtj.tmp/
109 |
110 | # Package Files #
111 | *.jar
112 | *.war
113 | *.nar
114 | *.ear
115 | *.zip
116 | *.tar.gz
117 | *.rar
118 |
119 | # virtual machine crash logs, see http://www.java.com/en/download/help/error_hotspot.xml
120 | hs_err_pid*
121 |
122 | ### Gradle ###
123 | .gradle
124 | build/
125 |
126 | # Ignore Gradle GUI config
127 | gradle-app.setting
128 |
129 | # Avoid ignoring Gradle wrapper jar file (.jar files are usually ignored)
130 | !gradle-wrapper.jar
131 |
132 | # Cache of project
133 | .gradletasknamecache
134 |
135 | # # Work around https://youtrack.jetbrains.com/issue/IDEA-116898
136 | # gradle/wrapper/gradle-wrapper.properties
137 |
138 | ### Gradle Patch ###
139 | **/build/
140 |
141 | # Eclipse Gradle plugin generated files
142 | # Eclipse Core
143 | .project
144 | # JDT-specific (Eclipse Java Development Tools)
145 | .classpath
146 |
147 | # End of https://www.toptal.com/developers/gitignore/api/gradle,java,intellij+all
--------------------------------------------------------------------------------
/.run/Build.run.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
19 | true
20 | true
21 | false
22 | false
23 |
24 |
25 |
--------------------------------------------------------------------------------
/LICENSE:
--------------------------------------------------------------------------------
1 | GNU AFFERO GENERAL PUBLIC LICENSE
2 | Version 3, 19 November 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 Affero General Public License is a free, copyleft license for
11 | software and other kinds of works, specifically designed to ensure
12 | cooperation with the community in the case of network server software.
13 |
14 | The licenses for most software and other practical works are designed
15 | to take away your freedom to share and change the works. By contrast,
16 | our General Public Licenses are intended to guarantee your freedom to
17 | share and change all versions of a program--to make sure it remains free
18 | software for all its users.
19 |
20 | When we speak of free software, we are referring to freedom, not
21 | price. Our General Public Licenses are designed to make sure that you
22 | have the freedom to distribute copies of free software (and charge for
23 | them if you wish), that you receive source code or can get it if you
24 | want it, that you can change the software or use pieces of it in new
25 | free programs, and that you know you can do these things.
26 |
27 | Developers that use our General Public Licenses protect your rights
28 | with two steps: (1) assert copyright on the software, and (2) offer
29 | you this License which gives you legal permission to copy, distribute
30 | and/or modify the software.
31 |
32 | A secondary benefit of defending all users' freedom is that
33 | improvements made in alternate versions of the program, if they
34 | receive widespread use, become available for other developers to
35 | incorporate. Many developers of free software are heartened and
36 | encouraged by the resulting cooperation. However, in the case of
37 | software used on network servers, this result may fail to come about.
38 | The GNU General Public License permits making a modified version and
39 | letting the public access it on a server without ever releasing its
40 | source code to the public.
41 |
42 | The GNU Affero General Public License is designed specifically to
43 | ensure that, in such cases, the modified source code becomes available
44 | to the community. It requires the operator of a network server to
45 | provide the source code of the modified version running there to the
46 | users of that server. Therefore, public use of a modified version, on
47 | a publicly accessible server, gives the public access to the source
48 | code of the modified version.
49 |
50 | An older license, called the Affero General Public License and
51 | published by Affero, was designed to accomplish similar goals. This is
52 | a different license, not a version of the Affero GPL, but Affero has
53 | released a new version of the Affero GPL which permits relicensing under
54 | this license.
55 |
56 | The precise terms and conditions for copying, distribution and
57 | modification follow.
58 |
59 | TERMS AND CONDITIONS
60 |
61 | 0. Definitions.
62 |
63 | "This License" refers to version 3 of the GNU Affero General Public License.
64 |
65 | "Copyright" also means copyright-like laws that apply to other kinds of
66 | works, such as semiconductor masks.
67 |
68 | "The Program" refers to any copyrightable work licensed under this
69 | License. Each licensee is addressed as "you". "Licensees" and
70 | "recipients" may be individuals or organizations.
71 |
72 | To "modify" a work means to copy from or adapt all or part of the work
73 | in a fashion requiring copyright permission, other than the making of an
74 | exact copy. The resulting work is called a "modified version" of the
75 | earlier work or a work "based on" the earlier work.
76 |
77 | A "covered work" means either the unmodified Program or a work based
78 | on the Program.
79 |
80 | To "propagate" a work means to do anything with it that, without
81 | permission, would make you directly or secondarily liable for
82 | infringement under applicable copyright law, except executing it on a
83 | computer or modifying a private copy. Propagation includes copying,
84 | distribution (with or without modification), making available to the
85 | public, and in some countries other activities as well.
86 |
87 | To "convey" a work means any kind of propagation that enables other
88 | parties to make or receive copies. Mere interaction with a user through
89 | a computer network, with no transfer of a copy, is not conveying.
90 |
91 | An interactive user interface displays "Appropriate Legal Notices"
92 | to the extent that it includes a convenient and prominently visible
93 | feature that (1) displays an appropriate copyright notice, and (2)
94 | tells the user that there is no warranty for the work (except to the
95 | extent that warranties are provided), that licensees may convey the
96 | work under this License, and how to view a copy of this License. If
97 | the interface presents a list of user commands or options, such as a
98 | menu, a prominent item in the list meets this criterion.
99 |
100 | 1. Source Code.
101 |
102 | The "source code" for a work means the preferred form of the work
103 | for making modifications to it. "Object code" means any non-source
104 | form of a work.
105 |
106 | A "Standard Interface" means an interface that either is an official
107 | standard defined by a recognized standards body, or, in the case of
108 | interfaces specified for a particular programming language, one that
109 | is widely used among developers working in that language.
110 |
111 | The "System Libraries" of an executable work include anything, other
112 | than the work as a whole, that (a) is included in the normal form of
113 | packaging a Major Component, but which is not part of that Major
114 | Component, and (b) serves only to enable use of the work with that
115 | Major Component, or to implement a Standard Interface for which an
116 | implementation is available to the public in source code form. A
117 | "Major Component", in this context, means a major essential component
118 | (kernel, window system, and so on) of the specific operating system
119 | (if any) on which the executable work runs, or a compiler used to
120 | produce the work, or an object code interpreter used to run it.
121 |
122 | The "Corresponding Source" for a work in object code form means all
123 | the source code needed to generate, install, and (for an executable
124 | work) run the object code and to modify the work, including scripts to
125 | control those activities. However, it does not include the work's
126 | System Libraries, or general-purpose tools or generally available free
127 | programs which are used unmodified in performing those activities but
128 | which are not part of the work. For example, Corresponding Source
129 | includes interface definition files associated with source files for
130 | the work, and the source code for shared libraries and dynamically
131 | linked subprograms that the work is specifically designed to require,
132 | such as by intimate data communication or control flow between those
133 | subprograms and other parts of the work.
134 |
135 | The Corresponding Source need not include anything that users
136 | can regenerate automatically from other parts of the Corresponding
137 | Source.
138 |
139 | The Corresponding Source for a work in source code form is that
140 | same work.
141 |
142 | 2. Basic Permissions.
143 |
144 | All rights granted under this License are granted for the term of
145 | copyright on the Program, and are irrevocable provided the stated
146 | conditions are met. This License explicitly affirms your unlimited
147 | permission to run the unmodified Program. The output from running a
148 | covered work is covered by this License only if the output, given its
149 | content, constitutes a covered work. This License acknowledges your
150 | rights of fair use or other equivalent, as provided by copyright law.
151 |
152 | You may make, run and propagate covered works that you do not
153 | convey, without conditions so long as your license otherwise remains
154 | in force. You may convey covered works to others for the sole purpose
155 | of having them make modifications exclusively for you, or provide you
156 | with facilities for running those works, provided that you comply with
157 | the terms of this License in conveying all material for which you do
158 | not control copyright. Those thus making or running the covered works
159 | for you must do so exclusively on your behalf, under your direction
160 | and control, on terms that prohibit them from making any copies of
161 | your copyrighted material outside their relationship with you.
162 |
163 | Conveying under any other circumstances is permitted solely under
164 | the conditions stated below. Sublicensing is not allowed; section 10
165 | makes it unnecessary.
166 |
167 | 3. Protecting Users' Legal Rights From Anti-Circumvention Law.
168 |
169 | No covered work shall be deemed part of an effective technological
170 | measure under any applicable law fulfilling obligations under article
171 | 11 of the WIPO copyright treaty adopted on 20 December 1996, or
172 | similar laws prohibiting or restricting circumvention of such
173 | measures.
174 |
175 | When you convey a covered work, you waive any legal power to forbid
176 | circumvention of technological measures to the extent such circumvention
177 | is effected by exercising rights under this License with respect to
178 | the covered work, and you disclaim any intention to limit operation or
179 | modification of the work as a means of enforcing, against the work's
180 | users, your or third parties' legal rights to forbid circumvention of
181 | technological measures.
182 |
183 | 4. Conveying Verbatim Copies.
184 |
185 | You may convey verbatim copies of the Program's source code as you
186 | receive it, in any medium, provided that you conspicuously and
187 | appropriately publish on each copy an appropriate copyright notice;
188 | keep intact all notices stating that this License and any
189 | non-permissive terms added in accord with section 7 apply to the code;
190 | keep intact all notices of the absence of any warranty; and give all
191 | recipients a copy of this License along with the Program.
192 |
193 | You may charge any price or no price for each copy that you convey,
194 | and you may offer support or warranty protection for a fee.
195 |
196 | 5. Conveying Modified Source Versions.
197 |
198 | You may convey a work based on the Program, or the modifications to
199 | produce it from the Program, in the form of source code under the
200 | terms of section 4, provided that you also meet all of these conditions:
201 |
202 | a) The work must carry prominent notices stating that you modified
203 | it, and giving a relevant date.
204 |
205 | b) The work must carry prominent notices stating that it is
206 | released under this License and any conditions added under section
207 | 7. This requirement modifies the requirement in section 4 to
208 | "keep intact all notices".
209 |
210 | c) You must license the entire work, as a whole, under this
211 | License to anyone who comes into possession of a copy. This
212 | License will therefore apply, along with any applicable section 7
213 | additional terms, to the whole of the work, and all its parts,
214 | regardless of how they are packaged. This License gives no
215 | permission to license the work in any other way, but it does not
216 | invalidate such permission if you have separately received it.
217 |
218 | d) If the work has interactive user interfaces, each must display
219 | Appropriate Legal Notices; however, if the Program has interactive
220 | interfaces that do not display Appropriate Legal Notices, your
221 | work need not make them do so.
222 |
223 | A compilation of a covered work with other separate and independent
224 | works, which are not by their nature extensions of the covered work,
225 | and which are not combined with it such as to form a larger program,
226 | in or on a volume of a storage or distribution medium, is called an
227 | "aggregate" if the compilation and its resulting copyright are not
228 | used to limit the access or legal rights of the compilation's users
229 | beyond what the individual works permit. Inclusion of a covered work
230 | in an aggregate does not cause this License to apply to the other
231 | parts of the aggregate.
232 |
233 | 6. Conveying Non-Source Forms.
234 |
235 | You may convey a covered work in object code form under the terms
236 | of sections 4 and 5, provided that you also convey the
237 | machine-readable Corresponding Source under the terms of this License,
238 | in one of these ways:
239 |
240 | a) Convey the object code in, or embodied in, a physical product
241 | (including a physical distribution medium), accompanied by the
242 | Corresponding Source fixed on a durable physical medium
243 | customarily used for software interchange.
244 |
245 | b) Convey the object code in, or embodied in, a physical product
246 | (including a physical distribution medium), accompanied by a
247 | written offer, valid for at least three years and valid for as
248 | long as you offer spare parts or customer support for that product
249 | model, to give anyone who possesses the object code either (1) a
250 | copy of the Corresponding Source for all the software in the
251 | product that is covered by this License, on a durable physical
252 | medium customarily used for software interchange, for a price no
253 | more than your reasonable cost of physically performing this
254 | conveying of source, or (2) access to copy the
255 | Corresponding Source from a network server at no charge.
256 |
257 | c) Convey individual copies of the object code with a copy of the
258 | written offer to provide the Corresponding Source. This
259 | alternative is allowed only occasionally and noncommercially, and
260 | only if you received the object code with such an offer, in accord
261 | with subsection 6b.
262 |
263 | d) Convey the object code by offering access from a designated
264 | place (gratis or for a charge), and offer equivalent access to the
265 | Corresponding Source in the same way through the same place at no
266 | further charge. You need not require recipients to copy the
267 | Corresponding Source along with the object code. If the place to
268 | copy the object code is a network server, the Corresponding Source
269 | may be on a different server (operated by you or a third party)
270 | that supports equivalent copying facilities, provided you maintain
271 | clear directions next to the object code saying where to find the
272 | Corresponding Source. Regardless of what server hosts the
273 | Corresponding Source, you remain obligated to ensure that it is
274 | available for as long as needed to satisfy these requirements.
275 |
276 | e) Convey the object code using peer-to-peer transmission, provided
277 | you inform other peers where the object code and Corresponding
278 | Source of the work are being offered to the general public at no
279 | charge under subsection 6d.
280 |
281 | A separable portion of the object code, whose source code is excluded
282 | from the Corresponding Source as a System Library, need not be
283 | included in conveying the object code work.
284 |
285 | A "User Product" is either (1) a "consumer product", which means any
286 | tangible personal property which is normally used for personal, family,
287 | or household purposes, or (2) anything designed or sold for incorporation
288 | into a dwelling. In determining whether a product is a consumer product,
289 | doubtful cases shall be resolved in favor of coverage. For a particular
290 | product received by a particular user, "normally used" refers to a
291 | typical or common use of that class of product, regardless of the status
292 | of the particular user or of the way in which the particular user
293 | actually uses, or expects or is expected to use, the product. A product
294 | is a consumer product regardless of whether the product has substantial
295 | commercial, industrial or non-consumer uses, unless such uses represent
296 | the only significant mode of use of the product.
297 |
298 | "Installation Information" for a User Product means any methods,
299 | procedures, authorization keys, or other information required to install
300 | and execute modified versions of a covered work in that User Product from
301 | a modified version of its Corresponding Source. The information must
302 | suffice to ensure that the continued functioning of the modified object
303 | code is in no case prevented or interfered with solely because
304 | modification has been made.
305 |
306 | If you convey an object code work under this section in, or with, or
307 | specifically for use in, a User Product, and the conveying occurs as
308 | part of a transaction in which the right of possession and use of the
309 | User Product is transferred to the recipient in perpetuity or for a
310 | fixed term (regardless of how the transaction is characterized), the
311 | Corresponding Source conveyed under this section must be accompanied
312 | by the Installation Information. But this requirement does not apply
313 | if neither you nor any third party retains the ability to install
314 | modified object code on the User Product (for example, the work has
315 | been installed in ROM).
316 |
317 | The requirement to provide Installation Information does not include a
318 | requirement to continue to provide support service, warranty, or updates
319 | for a work that has been modified or installed by the recipient, or for
320 | the User Product in which it has been modified or installed. Access to a
321 | network may be denied when the modification itself materially and
322 | adversely affects the operation of the network or violates the rules and
323 | protocols for communication across the network.
324 |
325 | Corresponding Source conveyed, and Installation Information provided,
326 | in accord with this section must be in a format that is publicly
327 | documented (and with an implementation available to the public in
328 | source code form), and must require no special password or key for
329 | unpacking, reading or copying.
330 |
331 | 7. Additional Terms.
332 |
333 | "Additional permissions" are terms that supplement the terms of this
334 | License by making exceptions from one or more of its conditions.
335 | Additional permissions that are applicable to the entire Program shall
336 | be treated as though they were included in this License, to the extent
337 | that they are valid under applicable law. If additional permissions
338 | apply only to part of the Program, that part may be used separately
339 | under those permissions, but the entire Program remains governed by
340 | this License without regard to the additional permissions.
341 |
342 | When you convey a copy of a covered work, you may at your option
343 | remove any additional permissions from that copy, or from any part of
344 | it. (Additional permissions may be written to require their own
345 | removal in certain cases when you modify the work.) You may place
346 | additional permissions on material, added by you to a covered work,
347 | for which you have or can give appropriate copyright permission.
348 |
349 | Notwithstanding any other provision of this License, for material you
350 | add to a covered work, you may (if authorized by the copyright holders of
351 | that material) supplement the terms of this License with terms:
352 |
353 | a) Disclaiming warranty or limiting liability differently from the
354 | terms of sections 15 and 16 of this License; or
355 |
356 | b) Requiring preservation of specified reasonable legal notices or
357 | author attributions in that material or in the Appropriate Legal
358 | Notices displayed by works containing it; or
359 |
360 | c) Prohibiting misrepresentation of the origin of that material, or
361 | requiring that modified versions of such material be marked in
362 | reasonable ways as different from the original version; or
363 |
364 | d) Limiting the use for publicity purposes of names of licensors or
365 | authors of the material; or
366 |
367 | e) Declining to grant rights under trademark law for use of some
368 | trade names, trademarks, or service marks; or
369 |
370 | f) Requiring indemnification of licensors and authors of that
371 | material by anyone who conveys the material (or modified versions of
372 | it) with contractual assumptions of liability to the recipient, for
373 | any liability that these contractual assumptions directly impose on
374 | those licensors and authors.
375 |
376 | All other non-permissive additional terms are considered "further
377 | restrictions" within the meaning of section 10. If the Program as you
378 | received it, or any part of it, contains a notice stating that it is
379 | governed by this License along with a term that is a further
380 | restriction, you may remove that term. If a license document contains
381 | a further restriction but permits relicensing or conveying under this
382 | License, you may add to a covered work material governed by the terms
383 | of that license document, provided that the further restriction does
384 | not survive such relicensing or conveying.
385 |
386 | If you add terms to a covered work in accord with this section, you
387 | must place, in the relevant source files, a statement of the
388 | additional terms that apply to those files, or a notice indicating
389 | where to find the applicable terms.
390 |
391 | Additional terms, permissive or non-permissive, may be stated in the
392 | form of a separately written license, or stated as exceptions;
393 | the above requirements apply either way.
394 |
395 | 8. Termination.
396 |
397 | You may not propagate or modify a covered work except as expressly
398 | provided under this License. Any attempt otherwise to propagate or
399 | modify it is void, and will automatically terminate your rights under
400 | this License (including any patent licenses granted under the third
401 | paragraph of section 11).
402 |
403 | However, if you cease all violation of this License, then your
404 | license from a particular copyright holder is reinstated (a)
405 | provisionally, unless and until the copyright holder explicitly and
406 | finally terminates your license, and (b) permanently, if the copyright
407 | holder fails to notify you of the violation by some reasonable means
408 | prior to 60 days after the cessation.
409 |
410 | Moreover, your license from a particular copyright holder is
411 | reinstated permanently if the copyright holder notifies you of the
412 | violation by some reasonable means, this is the first time you have
413 | received notice of violation of this License (for any work) from that
414 | copyright holder, and you cure the violation prior to 30 days after
415 | your receipt of the notice.
416 |
417 | Termination of your rights under this section does not terminate the
418 | licenses of parties who have received copies or rights from you under
419 | this License. If your rights have been terminated and not permanently
420 | reinstated, you do not qualify to receive new licenses for the same
421 | material under section 10.
422 |
423 | 9. Acceptance Not Required for Having Copies.
424 |
425 | You are not required to accept this License in order to receive or
426 | run a copy of the Program. Ancillary propagation of a covered work
427 | occurring solely as a consequence of using peer-to-peer transmission
428 | to receive a copy likewise does not require acceptance. However,
429 | nothing other than this License grants you permission to propagate or
430 | modify any covered work. These actions infringe copyright if you do
431 | not accept this License. Therefore, by modifying or propagating a
432 | covered work, you indicate your acceptance of this License to do so.
433 |
434 | 10. Automatic Licensing of Downstream Recipients.
435 |
436 | Each time you convey a covered work, the recipient automatically
437 | receives a license from the original licensors, to run, modify and
438 | propagate that work, subject to this License. You are not responsible
439 | for enforcing compliance by third parties with this License.
440 |
441 | An "entity transaction" is a transaction transferring control of an
442 | organization, or substantially all assets of one, or subdividing an
443 | organization, or merging organizations. If propagation of a covered
444 | work results from an entity transaction, each party to that
445 | transaction who receives a copy of the work also receives whatever
446 | licenses to the work the party's predecessor in interest had or could
447 | give under the previous paragraph, plus a right to possession of the
448 | Corresponding Source of the work from the predecessor in interest, if
449 | the predecessor has it or can get it with reasonable efforts.
450 |
451 | You may not impose any further restrictions on the exercise of the
452 | rights granted or affirmed under this License. For example, you may
453 | not impose a license fee, royalty, or other charge for exercise of
454 | rights granted under this License, and you may not initiate litigation
455 | (including a cross-claim or counterclaim in a lawsuit) alleging that
456 | any patent claim is infringed by making, using, selling, offering for
457 | sale, or importing the Program or any portion of it.
458 |
459 | 11. Patents.
460 |
461 | A "contributor" is a copyright holder who authorizes use under this
462 | License of the Program or a work on which the Program is based. The
463 | work thus licensed is called the contributor's "contributor version".
464 |
465 | A contributor's "essential patent claims" are all patent claims
466 | owned or controlled by the contributor, whether already acquired or
467 | hereafter acquired, that would be infringed by some manner, permitted
468 | by this License, of making, using, or selling its contributor version,
469 | but do not include claims that would be infringed only as a
470 | consequence of further modification of the contributor version. For
471 | purposes of this definition, "control" includes the right to grant
472 | patent sublicenses in a manner consistent with the requirements of
473 | this License.
474 |
475 | Each contributor grants you a non-exclusive, worldwide, royalty-free
476 | patent license under the contributor's essential patent claims, to
477 | make, use, sell, offer for sale, import and otherwise run, modify and
478 | propagate the contents of its contributor version.
479 |
480 | In the following three paragraphs, a "patent license" is any express
481 | agreement or commitment, however denominated, not to enforce a patent
482 | (such as an express permission to practice a patent or covenant not to
483 | sue for patent infringement). To "grant" such a patent license to a
484 | party means to make such an agreement or commitment not to enforce a
485 | patent against the party.
486 |
487 | If you convey a covered work, knowingly relying on a patent license,
488 | and the Corresponding Source of the work is not available for anyone
489 | to copy, free of charge and under the terms of this License, through a
490 | publicly available network server or other readily accessible means,
491 | then you must either (1) cause the Corresponding Source to be so
492 | available, or (2) arrange to deprive yourself of the benefit of the
493 | patent license for this particular work, or (3) arrange, in a manner
494 | consistent with the requirements of this License, to extend the patent
495 | license to downstream recipients. "Knowingly relying" means you have
496 | actual knowledge that, but for the patent license, your conveying the
497 | covered work in a country, or your recipient's use of the covered work
498 | in a country, would infringe one or more identifiable patents in that
499 | country that you have reason to believe are valid.
500 |
501 | If, pursuant to or in connection with a single transaction or
502 | arrangement, you convey, or propagate by procuring conveyance of, a
503 | covered work, and grant a patent license to some of the parties
504 | receiving the covered work authorizing them to use, propagate, modify
505 | or convey a specific copy of the covered work, then the patent license
506 | you grant is automatically extended to all recipients of the covered
507 | work and works based on it.
508 |
509 | A patent license is "discriminatory" if it does not include within
510 | the scope of its coverage, prohibits the exercise of, or is
511 | conditioned on the non-exercise of one or more of the rights that are
512 | specifically granted under this License. You may not convey a covered
513 | work if you are a party to an arrangement with a third party that is
514 | in the business of distributing software, under which you make payment
515 | to the third party based on the extent of your activity of conveying
516 | the work, and under which the third party grants, to any of the
517 | parties who would receive the covered work from you, a discriminatory
518 | patent license (a) in connection with copies of the covered work
519 | conveyed by you (or copies made from those copies), or (b) primarily
520 | for and in connection with specific products or compilations that
521 | contain the covered work, unless you entered into that arrangement,
522 | or that patent license was granted, prior to 28 March 2007.
523 |
524 | Nothing in this License shall be construed as excluding or limiting
525 | any implied license or other defenses to infringement that may
526 | otherwise be available to you under applicable patent law.
527 |
528 | 12. No Surrender of Others' Freedom.
529 |
530 | If conditions are imposed on you (whether by court order, agreement or
531 | otherwise) that contradict the conditions of this License, they do not
532 | excuse you from the conditions of this License. If you cannot convey a
533 | covered work so as to satisfy simultaneously your obligations under this
534 | License and any other pertinent obligations, then as a consequence you may
535 | not convey it at all. For example, if you agree to terms that obligate you
536 | to collect a royalty for further conveying from those to whom you convey
537 | the Program, the only way you could satisfy both those terms and this
538 | License would be to refrain entirely from conveying the Program.
539 |
540 | 13. Remote Network Interaction; Use with the GNU General Public License.
541 |
542 | Notwithstanding any other provision of this License, if you modify the
543 | Program, your modified version must prominently offer all users
544 | interacting with it remotely through a computer network (if your version
545 | supports such interaction) an opportunity to receive the Corresponding
546 | Source of your version by providing access to the Corresponding Source
547 | from a network server at no charge, through some standard or customary
548 | means of facilitating copying of software. This Corresponding Source
549 | shall include the Corresponding Source for any work covered by version 3
550 | of the GNU General Public License that is incorporated pursuant to the
551 | following paragraph.
552 |
553 | Notwithstanding any other provision of this License, you have
554 | permission to link or combine any covered work with a work licensed
555 | under version 3 of the GNU General Public License into a single
556 | combined work, and to convey the resulting work. The terms of this
557 | License will continue to apply to the part which is the covered work,
558 | but the work with which it is combined will remain governed by version
559 | 3 of the GNU General Public License.
560 |
561 | 14. Revised Versions of this License.
562 |
563 | The Free Software Foundation may publish revised and/or new versions of
564 | the GNU Affero General Public License from time to time. Such new versions
565 | will be similar in spirit to the present version, but may differ in detail to
566 | address new problems or concerns.
567 |
568 | Each version is given a distinguishing version number. If the
569 | Program specifies that a certain numbered version of the GNU Affero General
570 | Public License "or any later version" applies to it, you have the
571 | option of following the terms and conditions either of that numbered
572 | version or of any later version published by the Free Software
573 | Foundation. If the Program does not specify a version number of the
574 | GNU Affero General Public License, you may choose any version ever published
575 | by the Free Software Foundation.
576 |
577 | If the Program specifies that a proxy can decide which future
578 | versions of the GNU Affero General Public License can be used, that proxy's
579 | public statement of acceptance of a version permanently authorizes you
580 | to choose that version for the Program.
581 |
582 | Later license versions may give you additional or different
583 | permissions. However, no additional obligations are imposed on any
584 | author or copyright holder as a result of your choosing to follow a
585 | later version.
586 |
587 | 15. Disclaimer of Warranty.
588 |
589 | THERE IS NO WARRANTY FOR THE PROGRAM, TO THE EXTENT PERMITTED BY
590 | APPLICABLE LAW. EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT
591 | HOLDERS AND/OR OTHER PARTIES PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY
592 | OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO,
593 | THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
594 | PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE PROGRAM
595 | IS WITH YOU. SHOULD THE PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF
596 | ALL NECESSARY SERVICING, REPAIR OR CORRECTION.
597 |
598 | 16. Limitation of Liability.
599 |
600 | IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING
601 | WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MODIFIES AND/OR CONVEYS
602 | THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, INCLUDING ANY
603 | GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE
604 | USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED TO LOSS OF
605 | DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD
606 | PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER PROGRAMS),
607 | EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF
608 | SUCH DAMAGES.
609 |
610 | 17. Interpretation of Sections 15 and 16.
611 |
612 | If the disclaimer of warranty and limitation of liability provided
613 | above cannot be given local legal effect according to their terms,
614 | reviewing courts shall apply local law that most closely approximates
615 | an absolute waiver of all civil liability in connection with the
616 | Program, unless a warranty or assumption of liability accompanies a
617 | copy of the Program in return for a fee.
618 |
619 | END OF TERMS AND CONDITIONS
620 |
621 | How to Apply These Terms to Your New Programs
622 |
623 | If you develop a new program, and you want it to be of the greatest
624 | possible use to the public, the best way to achieve this is to make it
625 | free software which everyone can redistribute and change under these terms.
626 |
627 | To do so, attach the following notices to the program. It is safest
628 | to attach them to the start of each source file to most effectively
629 | state the exclusion of warranty; and each file should have at least
630 | the "copyright" line and a pointer to where the full notice is found.
631 |
632 |
633 | Copyright (C)
634 |
635 | This program is free software: you can redistribute it and/or modify
636 | it under the terms of the GNU Affero General Public License as published
637 | by the Free Software Foundation, either version 3 of the License, or
638 | (at your option) any later version.
639 |
640 | This program is distributed in the hope that it will be useful,
641 | but WITHOUT ANY WARRANTY; without even the implied warranty of
642 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
643 | GNU Affero General Public License for more details.
644 |
645 | You should have received a copy of the GNU Affero General Public License
646 | along with this program. If not, see .
647 |
648 | Also add information on how to contact you by electronic and paper mail.
649 |
650 | If your software can interact with users remotely through a computer
651 | network, you should also make sure that it provides a way for users to
652 | get its source. For example, if your program is a web application, its
653 | interface could display a "Source" link that leads users to an archive
654 | of the code. There are many ways you could offer source, and different
655 | solutions will be better for different programs; see section 13 for the
656 | specific requirements.
657 |
658 | You should also get your employer (if you work as a programmer) or school,
659 | if any, to sign a "copyright disclaimer" for the program, if necessary.
660 | For more information on this, and how to apply and follow the GNU AGPL, see
661 | .
662 |
--------------------------------------------------------------------------------
/LevelTools Large Logo.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/byteful/LevelTools/e59bfc8f39c5022b17d0226e892cb576138ef05d/LevelTools Large Logo.png
--------------------------------------------------------------------------------
/LevelTools.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/byteful/LevelTools/e59bfc8f39c5022b17d0226e892cb576138ef05d/LevelTools.png
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | [](https://github.com/byteful/LevelTools/actions/workflows/gradle.yml)
2 | [](https://discord.gg/G8BDgqsuyw)
3 | [](https://jitpack.io/#byteful/LevelTools)
4 |
5 | SpigotMC: https://www.spigotmc.org/resources/leveltools-rpg-item-leveling.97516/
6 | Support/Help Server: https://discord.gg/G8BDgqsuyw
7 | WIKI: https://github.com/byteful/LevelTools/wiki
8 |
9 | 
10 |
11 | A plugin that adds a leveling system to tools, swords, and bows.
12 |
13 | ## Features
14 |
15 | - Supports versions 1.8 - 1.21.
16 | - Supports Folia
17 | - No dependencies.
18 | - Super efficient, no lag.
19 | - Simple developer API.
20 | - Commands & enchants on level up.
21 | - Supports blacklisting for blocks and items for XP.
22 | - ActionBar notifications.
23 | - Item lore modification.
24 |
25 | ## Developer API
26 |
27 | ### Gradle:
28 |
29 | ```groovy
30 | repositories {
31 | maven { url 'https://jitpack.io' }
32 | }
33 |
34 | dependencies {
35 | compileOnly 'com.github.byteful:LevelTools:Tag' // Replace Tag with the version. (Ex: v1.4.0)
36 | }
37 | ```
38 |
39 | ### Maven:
40 |
41 | ```xml
42 |
43 |
44 |
45 | jitpack.io
46 | https://jitpack.io
47 |
48 |
49 |
50 |
51 | com.github.byteful
52 | LevelTools
53 | Tag
54 |
55 | ```
56 |
57 | ### Example Usage:
58 |
59 | ```java
60 | // Items
61 |
62 | ItemStack hand = player.getInventory().getItemInMainHand();
63 | LevelToolsItem tool = LevelToolsUtil.createLevelToolsItem(hand);
64 | tool.setLevel(69);
65 | tool.setXp(420);
66 | player.getInventory().setItemInMainHand(tool.getItemStack());
67 |
68 | // Events
69 |
70 | @EventHandler
71 | public void onLevelEvent(LevelToolsLevelIncreaseEvent event) {
72 | event.setNewLevel(69);
73 | }
74 |
75 | @EventHandler
76 | public void onXPEvent(LevelToolsXPIncreaseEvent event) {
77 | event.setNewXp(420);
78 | }
79 | ```
80 |
--------------------------------------------------------------------------------
/build.gradle:
--------------------------------------------------------------------------------
1 | plugins {
2 | id 'java'
3 | id 'idea'
4 | id 'maven-publish'
5 | id("com.gradleup.shadow") version "9.0.0-beta13"
6 | }
7 |
8 | repositories {
9 | mavenCentral()
10 | maven {
11 | url = uri('https://hub.spigotmc.org/nexus/content/repositories/snapshots/')
12 | }
13 | maven {
14 | url = uri('https://repo.papermc.io/repository/maven-public/')
15 | }
16 | maven {
17 | url = uri('https://oss.sonatype.org/content/groups/public/')
18 | }
19 | maven {
20 | url = uri('https://repo.codemc.org/repository/maven-public/')
21 | }
22 | maven {
23 | url = uri('https://repo.maven.apache.org/maven2/')
24 | }
25 | maven {
26 | url = uri('https://redempt.dev')
27 | }
28 | maven {
29 | url = uri('https://jitpack.io')
30 | }
31 | maven {
32 | url = uri('https://repo.extendedclip.com/content/repositories/placeholderapi/')
33 | }
34 | maven {
35 | url = uri('https://hub.jeff-media.com/nexus/repository/jeff-media-public/')
36 | }
37 | }
38 |
39 | dependencies {
40 | implementation 'de.tr7zw:item-nbt-api:2.15.0'
41 | implementation 'com.github.Redempt:RedLib:6.6.1'
42 | implementation 'com.github.Redempt:Crunch:2.0.3'
43 | implementation 'com.github.cryptomorin:XSeries:13.2.0'
44 | implementation 'com.github.Revxrsal.Lamp:common:3.3.6'
45 | implementation 'com.github.Revxrsal.Lamp:bukkit:3.3.6'
46 | implementation 'com.github.Sven65:Item-Names:1.0.2'
47 | implementation 'org.bstats:bstats-bukkit:3.1.0'
48 | implementation 'com.jeff-media:MorePersistentDataTypes:2.4.0'
49 |
50 | compileOnly files('libs/folia-api-1.20.4-R0.1-SNAPSHOT.jar') // Modified API jar with Java 8 support
51 | compileOnly 'net.kyori:adventure-api:4.17.0' // Not used but needed for Folia compilation
52 | compileOnly 'org.spigotmc:spigot-api:1.14.4-R0.1-SNAPSHOT'
53 | compileOnly 'org.jetbrains:annotations:24.1.0'
54 | compileOnly 'me.clip:placeholderapi:2.11.6'
55 | }
56 |
57 | group = 'me.byteful.plugin'
58 | version = '1.4.1'
59 | description = 'LevelTools'
60 | java.sourceCompatibility = JavaVersion.VERSION_17
61 |
62 | publishing {
63 | publications {
64 | maven(MavenPublication) {
65 | from(components.java)
66 | }
67 | }
68 | }
69 |
70 | shadowJar {
71 | minimize()
72 | archiveBaseName.set("LevelTools")
73 | archiveClassifier.set("")
74 |
75 | relocate "de.tr7zw.changeme.nbtapi", "me.byteful.plugin.leveltools.libs.nbtapi"
76 | relocate "com.cryptomorin.xseries", "me.byteful.plugin.leveltools.libs.xseries"
77 | relocate "redempt.redlib", "me.byteful.plugin.leveltools.libs.redlib"
78 | relocate 'revxrsal.commands', 'me.byteful.plugin.leveltools.libs.lamp'
79 | relocate 'org.bstats', 'me.byteful.plugin.leveltools.libs.bstats'
80 | relocate 'com.jeff-media.morepersistentdatatypes', 'me.byteful.plugin.leveltools.libs.morepersistentdatatypes'
81 | }
82 |
83 | def targetJavaVersion = 8
84 | java {
85 | def javaVersion = JavaVersion.toVersion(targetJavaVersion)
86 | sourceCompatibility = 17
87 | targetCompatibility = 8
88 | }
89 |
90 | tasks.withType(JavaCompile).configureEach {
91 | if (targetJavaVersion >= 10 || JavaVersion.current().isJava10Compatible()) {
92 | options.release.set(targetJavaVersion)
93 | }
94 | }
95 |
96 | processResources {
97 | def props = [version: version]
98 | inputs.properties props
99 | filteringCharset 'UTF-8'
100 | filesMatching('*.yml') {
101 | expand props
102 | }
103 | }
104 |
105 | compileJava { // Preserve parameter names in the bytecode
106 | options.compilerArgs += ["-parameters"]
107 | }
108 |
--------------------------------------------------------------------------------
/gradle/wrapper/gradle-wrapper.jar:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/byteful/LevelTools/e59bfc8f39c5022b17d0226e892cb576138ef05d/gradle/wrapper/gradle-wrapper.jar
--------------------------------------------------------------------------------
/gradle/wrapper/gradle-wrapper.properties:
--------------------------------------------------------------------------------
1 | distributionBase=GRADLE_USER_HOME
2 | distributionPath=wrapper/dists
3 | distributionUrl=https\://services.gradle.org/distributions/gradle-8.5-bin.zip
4 | networkTimeout=10000
5 | validateDistributionUrl=true
6 | zipStoreBase=GRADLE_USER_HOME
7 | zipStorePath=wrapper/dists
8 |
--------------------------------------------------------------------------------
/gradlew:
--------------------------------------------------------------------------------
1 | #!/bin/sh
2 |
3 | #
4 | # Copyright © 2015-2021 the original authors.
5 | #
6 | # Licensed under the Apache License, Version 2.0 (the "License");
7 | # you may not use this file except in compliance with the License.
8 | # You may obtain a copy of the License at
9 | #
10 | # https://www.apache.org/licenses/LICENSE-2.0
11 | #
12 | # Unless required by applicable law or agreed to in writing, software
13 | # distributed under the License is distributed on an "AS IS" BASIS,
14 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15 | # See the License for the specific language governing permissions and
16 | # limitations under the License.
17 | #
18 |
19 | ##############################################################################
20 | #
21 | # Gradle start up script for POSIX generated by Gradle.
22 | #
23 | # Important for running:
24 | #
25 | # (1) You need a POSIX-compliant shell to run this script. If your /bin/sh is
26 | # noncompliant, but you have some other compliant shell such as ksh or
27 | # bash, then to run this script, type that shell name before the whole
28 | # command line, like:
29 | #
30 | # ksh Gradle
31 | #
32 | # Busybox and similar reduced shells will NOT work, because this script
33 | # requires all of these POSIX shell features:
34 | # * functions;
35 | # * expansions «$var», «${var}», «${var:-default}», «${var+SET}»,
36 | # «${var#prefix}», «${var%suffix}», and «$( cmd )»;
37 | # * compound commands having a testable exit status, especially «case»;
38 | # * various built-in commands including «command», «set», and «ulimit».
39 | #
40 | # Important for patching:
41 | #
42 | # (2) This script targets any POSIX shell, so it avoids extensions provided
43 | # by Bash, Ksh, etc; in particular arrays are avoided.
44 | #
45 | # The "traditional" practice of packing multiple parameters into a
46 | # space-separated string is a well documented source of bugs and security
47 | # problems, so this is (mostly) avoided, by progressively accumulating
48 | # options in "$@", and eventually passing that to Java.
49 | #
50 | # Where the inherited environment variables (DEFAULT_JVM_OPTS, JAVA_OPTS,
51 | # and GRADLE_OPTS) rely on word-splitting, this is performed explicitly;
52 | # see the in-line comments for details.
53 | #
54 | # There are tweaks for specific operating systems such as AIX, CygWin,
55 | # Darwin, MinGW, and NonStop.
56 | #
57 | # (3) This script is generated from the Groovy template
58 | # https://github.com/gradle/gradle/blob/HEAD/subprojects/plugins/src/main/resources/org/gradle/api/internal/plugins/unixStartScript.txt
59 | # within the Gradle project.
60 | #
61 | # You can find Gradle at https://github.com/gradle/gradle/.
62 | #
63 | ##############################################################################
64 |
65 | # Attempt to set APP_HOME
66 |
67 | # Resolve links: $0 may be a link
68 | app_path=$0
69 |
70 | # Need this for daisy-chained symlinks.
71 | while
72 | APP_HOME=${app_path%"${app_path##*/}"} # leaves a trailing /; empty if no leading path
73 | [ -h "$app_path" ]
74 | do
75 | ls=$( ls -ld "$app_path" )
76 | link=${ls#*' -> '}
77 | case $link in #(
78 | /*) app_path=$link ;; #(
79 | *) app_path=$APP_HOME$link ;;
80 | esac
81 | done
82 |
83 | # This is normally unused
84 | # shellcheck disable=SC2034
85 | APP_BASE_NAME=${0##*/}
86 | # Discard cd standard output in case $CDPATH is set (https://github.com/gradle/gradle/issues/25036)
87 | APP_HOME=$( cd "${APP_HOME:-./}" > /dev/null && pwd -P ) || exit
88 |
89 | # Use the maximum available, or set MAX_FD != -1 to use that value.
90 | MAX_FD=maximum
91 |
92 | warn () {
93 | echo "$*"
94 | } >&2
95 |
96 | die () {
97 | echo
98 | echo "$*"
99 | echo
100 | exit 1
101 | } >&2
102 |
103 | # OS specific support (must be 'true' or 'false').
104 | cygwin=false
105 | msys=false
106 | darwin=false
107 | nonstop=false
108 | case "$( uname )" in #(
109 | CYGWIN* ) cygwin=true ;; #(
110 | Darwin* ) darwin=true ;; #(
111 | MSYS* | MINGW* ) msys=true ;; #(
112 | NONSTOP* ) nonstop=true ;;
113 | esac
114 |
115 | CLASSPATH=$APP_HOME/gradle/wrapper/gradle-wrapper.jar
116 |
117 |
118 | # Determine the Java command to use to start the JVM.
119 | if [ -n "$JAVA_HOME" ] ; then
120 | if [ -x "$JAVA_HOME/jre/sh/java" ] ; then
121 | # IBM's JDK on AIX uses strange locations for the executables
122 | JAVACMD=$JAVA_HOME/jre/sh/java
123 | else
124 | JAVACMD=$JAVA_HOME/bin/java
125 | fi
126 | if [ ! -x "$JAVACMD" ] ; then
127 | die "ERROR: JAVA_HOME is set to an invalid directory: $JAVA_HOME
128 |
129 | Please set the JAVA_HOME variable in your environment to match the
130 | location of your Java installation."
131 | fi
132 | else
133 | JAVACMD=java
134 | if ! command -v java >/dev/null 2>&1
135 | then
136 | die "ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH.
137 |
138 | Please set the JAVA_HOME variable in your environment to match the
139 | location of your Java installation."
140 | fi
141 | fi
142 |
143 | # Increase the maximum file descriptors if we can.
144 | if ! "$cygwin" && ! "$darwin" && ! "$nonstop" ; then
145 | case $MAX_FD in #(
146 | max*)
147 | # In POSIX sh, ulimit -H is undefined. That's why the result is checked to see if it worked.
148 | # shellcheck disable=SC2039,SC3045
149 | MAX_FD=$( ulimit -H -n ) ||
150 | warn "Could not query maximum file descriptor limit"
151 | esac
152 | case $MAX_FD in #(
153 | '' | soft) :;; #(
154 | *)
155 | # In POSIX sh, ulimit -n is undefined. That's why the result is checked to see if it worked.
156 | # shellcheck disable=SC2039,SC3045
157 | ulimit -n "$MAX_FD" ||
158 | warn "Could not set maximum file descriptor limit to $MAX_FD"
159 | esac
160 | fi
161 |
162 | # Collect all arguments for the java command, stacking in reverse order:
163 | # * args from the command line
164 | # * the main class name
165 | # * -classpath
166 | # * -D...appname settings
167 | # * --module-path (only if needed)
168 | # * DEFAULT_JVM_OPTS, JAVA_OPTS, and GRADLE_OPTS environment variables.
169 |
170 | # For Cygwin or MSYS, switch paths to Windows format before running java
171 | if "$cygwin" || "$msys" ; then
172 | APP_HOME=$( cygpath --path --mixed "$APP_HOME" )
173 | CLASSPATH=$( cygpath --path --mixed "$CLASSPATH" )
174 |
175 | JAVACMD=$( cygpath --unix "$JAVACMD" )
176 |
177 | # Now convert the arguments - kludge to limit ourselves to /bin/sh
178 | for arg do
179 | if
180 | case $arg in #(
181 | -*) false ;; # don't mess with options #(
182 | /?*) t=${arg#/} t=/${t%%/*} # looks like a POSIX filepath
183 | [ -e "$t" ] ;; #(
184 | *) false ;;
185 | esac
186 | then
187 | arg=$( cygpath --path --ignore --mixed "$arg" )
188 | fi
189 | # Roll the args list around exactly as many times as the number of
190 | # args, so each arg winds up back in the position where it started, but
191 | # possibly modified.
192 | #
193 | # NB: a `for` loop captures its iteration list before it begins, so
194 | # changing the positional parameters here affects neither the number of
195 | # iterations, nor the values presented in `arg`.
196 | shift # remove old arg
197 | set -- "$@" "$arg" # push replacement arg
198 | done
199 | fi
200 |
201 |
202 | # Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
203 | DEFAULT_JVM_OPTS='"-Xmx64m" "-Xms64m"'
204 |
205 | # Collect all arguments for the java command:
206 | # * DEFAULT_JVM_OPTS, JAVA_OPTS, JAVA_OPTS, and optsEnvironmentVar are not allowed to contain shell fragments,
207 | # and any embedded shellness will be escaped.
208 | # * For example: A user cannot expect ${Hostname} to be expanded, as it is an environment variable and will be
209 | # treated as '${Hostname}' itself on the command line.
210 |
211 | set -- \
212 | "-Dorg.gradle.appname=$APP_BASE_NAME" \
213 | -classpath "$CLASSPATH" \
214 | org.gradle.wrapper.GradleWrapperMain \
215 | "$@"
216 |
217 | # Stop when "xargs" is not available.
218 | if ! command -v xargs >/dev/null 2>&1
219 | then
220 | die "xargs is not available"
221 | fi
222 |
223 | # Use "xargs" to parse quoted args.
224 | #
225 | # With -n1 it outputs one arg per line, with the quotes and backslashes removed.
226 | #
227 | # In Bash we could simply go:
228 | #
229 | # readarray ARGS < <( xargs -n1 <<<"$var" ) &&
230 | # set -- "${ARGS[@]}" "$@"
231 | #
232 | # but POSIX shell has neither arrays nor command substitution, so instead we
233 | # post-process each arg (as a line of input to sed) to backslash-escape any
234 | # character that might be a shell metacharacter, then use eval to reverse
235 | # that process (while maintaining the separation between arguments), and wrap
236 | # the whole thing up as a single "set" statement.
237 | #
238 | # This will of course break if any of these variables contains a newline or
239 | # an unmatched quote.
240 | #
241 |
242 | eval "set -- $(
243 | printf '%s\n' "$DEFAULT_JVM_OPTS $JAVA_OPTS $GRADLE_OPTS" |
244 | xargs -n1 |
245 | sed ' s~[^-[:alnum:]+,./:=@_]~\\&~g; ' |
246 | tr '\n' ' '
247 | )" '"$@"'
248 |
249 | exec "$JAVACMD" "$@"
250 |
--------------------------------------------------------------------------------
/gradlew.bat:
--------------------------------------------------------------------------------
1 | @rem
2 | @rem Copyright 2015 the original author or authors.
3 | @rem
4 | @rem Licensed under the Apache License, Version 2.0 (the "License");
5 | @rem you may not use this file except in compliance with the License.
6 | @rem You may obtain a copy of the License at
7 | @rem
8 | @rem https://www.apache.org/licenses/LICENSE-2.0
9 | @rem
10 | @rem Unless required by applicable law or agreed to in writing, software
11 | @rem distributed under the License is distributed on an "AS IS" BASIS,
12 | @rem WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | @rem See the License for the specific language governing permissions and
14 | @rem limitations under the License.
15 | @rem
16 |
17 | @if "%DEBUG%"=="" @echo off
18 | @rem ##########################################################################
19 | @rem
20 | @rem Gradle startup script for Windows
21 | @rem
22 | @rem ##########################################################################
23 |
24 | @rem Set local scope for the variables with windows NT shell
25 | if "%OS%"=="Windows_NT" setlocal
26 |
27 | set DIRNAME=%~dp0
28 | if "%DIRNAME%"=="" set DIRNAME=.
29 | @rem This is normally unused
30 | set APP_BASE_NAME=%~n0
31 | set APP_HOME=%DIRNAME%
32 |
33 | @rem Resolve any "." and ".." in APP_HOME to make it shorter.
34 | for %%i in ("%APP_HOME%") do set APP_HOME=%%~fi
35 |
36 | @rem Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
37 | set DEFAULT_JVM_OPTS="-Xmx64m" "-Xms64m"
38 |
39 | @rem Find java.exe
40 | if defined JAVA_HOME goto findJavaFromJavaHome
41 |
42 | set JAVA_EXE=java.exe
43 | %JAVA_EXE% -version >NUL 2>&1
44 | if %ERRORLEVEL% equ 0 goto execute
45 |
46 | echo.
47 | echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH.
48 | echo.
49 | echo Please set the JAVA_HOME variable in your environment to match the
50 | echo location of your Java installation.
51 |
52 | goto fail
53 |
54 | :findJavaFromJavaHome
55 | set JAVA_HOME=%JAVA_HOME:"=%
56 | set JAVA_EXE=%JAVA_HOME%/bin/java.exe
57 |
58 | if exist "%JAVA_EXE%" goto execute
59 |
60 | echo.
61 | echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME%
62 | echo.
63 | echo Please set the JAVA_HOME variable in your environment to match the
64 | echo location of your Java installation.
65 |
66 | goto fail
67 |
68 | :execute
69 | @rem Setup the command line
70 |
71 | set CLASSPATH=%APP_HOME%\gradle\wrapper\gradle-wrapper.jar
72 |
73 |
74 | @rem Execute Gradle
75 | "%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" org.gradle.wrapper.GradleWrapperMain %*
76 |
77 | :end
78 | @rem End local scope for the variables with windows NT shell
79 | if %ERRORLEVEL% equ 0 goto mainEnd
80 |
81 | :fail
82 | rem Set variable GRADLE_EXIT_CONSOLE if you need the _script_ return code instead of
83 | rem the _cmd.exe /c_ return code!
84 | set EXIT_CODE=%ERRORLEVEL%
85 | if %EXIT_CODE% equ 0 set EXIT_CODE=1
86 | if not ""=="%GRADLE_EXIT_CONSOLE%" exit %EXIT_CODE%
87 | exit /b %EXIT_CODE%
88 |
89 | :mainEnd
90 | if "%OS%"=="Windows_NT" endlocal
91 |
92 | :omega
93 |
--------------------------------------------------------------------------------
/jitpack.yml:
--------------------------------------------------------------------------------
1 | jdk:
2 | - openjdk17
3 | install:
4 | - chmod +x ./gradlew
5 | - ./gradlew clean build shadowJar publishMavenPublicationToMavenLocal
6 |
--------------------------------------------------------------------------------
/libs/folia-api-1.20.4-R0.1-SNAPSHOT.jar:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/byteful/LevelTools/e59bfc8f39c5022b17d0226e892cb576138ef05d/libs/folia-api-1.20.4-R0.1-SNAPSHOT.jar
--------------------------------------------------------------------------------
/settings.gradle:
--------------------------------------------------------------------------------
1 | rootProject.name = 'LevelTools'
2 |
--------------------------------------------------------------------------------
/src/main/java/me/byteful/plugin/leveltools/LevelToolsCommand.java:
--------------------------------------------------------------------------------
1 | package me.byteful.plugin.leveltools;
2 |
3 | import static me.byteful.plugin.leveltools.util.Text.colorize;
4 |
5 | import java.util.Objects;
6 | import me.byteful.plugin.leveltools.api.item.LevelToolsItem;
7 | import me.byteful.plugin.leveltools.util.LevelToolsUtil;
8 | import org.bukkit.Bukkit;
9 | import org.bukkit.command.CommandSender;
10 | import org.bukkit.entity.Player;
11 | import org.bukkit.inventory.ItemStack;
12 | import org.bukkit.inventory.PlayerInventory;
13 | import revxrsal.commands.annotation.*;
14 | import revxrsal.commands.help.CommandHelp;
15 |
16 | @Command("leveltools")
17 | public class LevelToolsCommand {
18 | @Dependency private LevelToolsPlugin plugin;
19 |
20 | @DefaultFor("leveltools")
21 | @Subcommand("help")
22 | @Description("Shows the list of LevelTools commands.")
23 | public void onHelp(CommandSender sender, CommandHelp help, @Default("1") int page) {
24 | sender.sendMessage(colorize("&6&lLevelTools Command Help:"));
25 | for (String entry : help.paginate(page, 7)) {
26 | sender.sendMessage(colorize(entry));
27 | }
28 | }
29 |
30 | @Subcommand("reload")
31 | @Description("Reloads LevelTools' plugin configuration.")
32 | public void onReload(CommandSender sender) {
33 | if (!checkPerm(sender)) {
34 | return;
35 | }
36 |
37 | plugin.reloadConfig();
38 | plugin.setAnvilCombineMode();
39 | plugin.setLevelXpFormula();
40 | sender.sendMessage(
41 | colorize(
42 | Objects.requireNonNull(plugin.getConfig().getString("messages.successful_reload"))));
43 | }
44 |
45 | @Subcommand("reset")
46 | @Description("Resets all XP/Levels for all the items in the target player.")
47 | public void onReset(CommandSender sender, Player target, @Switch("all") boolean all) {
48 | if (!checkPerm(sender)) {
49 | return;
50 | }
51 |
52 | final ItemStack hand = LevelToolsUtil.getHand(target);
53 | if (!all) {
54 | if (!LevelToolsUtil.isSupportedTool(hand.getType())) {
55 | sender.sendMessage(colorize(plugin.getConfig().getString("messages.item_not_tool")));
56 |
57 | return;
58 | }
59 |
60 | final LevelToolsItem tool = LevelToolsUtil.createLevelToolsItem(hand);
61 | tool.setLevel(0);
62 | tool.setXp(0);
63 | LevelToolsUtil.setHand(target, tool.getItemStack());
64 | sender.sendMessage(
65 | colorize(
66 | plugin
67 | .getConfig()
68 | .getString(
69 | "messages.successfully_reset_hand_tool",
70 | "&aSuccessfully reset tool in hand's XP/Levels for {player}.")
71 | .replace("{player}", target.getName())));
72 |
73 | return;
74 | }
75 |
76 | final PlayerInventory inv = target.getInventory();
77 | final ItemStack[] contents = inv.getContents();
78 | for (int i = 0; i < contents.length; i++) {
79 | final ItemStack item = contents[i];
80 | if (item == null || !LevelToolsUtil.isSupportedTool(item.getType())) {
81 | continue;
82 | }
83 | final LevelToolsItem tool = LevelToolsUtil.createLevelToolsItem(item);
84 | tool.setLevel(0);
85 | tool.setXp(0);
86 | inv.setItem(i, tool.getItemStack());
87 | }
88 | sender.sendMessage(
89 | colorize(
90 | Objects.requireNonNull(
91 | plugin.getConfig().getString("messages.successfully_reset_tools"))
92 | .replace("{player}", target.getName())));
93 | }
94 |
95 | @Subcommand("xp")
96 | @Description("Sets the item in hand's XP to provided XP.")
97 | public void onXP(Player player, double xp) {
98 | if (!checkPerm(player)) {
99 | return;
100 | }
101 |
102 | final ItemStack item = LevelToolsUtil.getHand(player);
103 |
104 | if (LevelToolsUtil.isSupportedTool(item.getType())) {
105 | final LevelToolsItem tool = LevelToolsUtil.createLevelToolsItem(item);
106 | tool.setXp(xp);
107 | LevelToolsUtil.setHand(player, tool.getItemStack());
108 | player.sendMessage(
109 | colorize(
110 | Objects.requireNonNull(
111 | plugin.getConfig().getString("messages.successfully_executed_action"))));
112 | } else {
113 | player.sendMessage(
114 | colorize(Objects.requireNonNull(plugin.getConfig().getString("messages.item_not_tool"))));
115 | }
116 | }
117 |
118 | @Subcommand("level")
119 | @Description("Sets the item in hand's level to provided level.")
120 | public void onLevel(Player player, int level) {
121 | if (!checkPerm(player)) {
122 | return;
123 | }
124 |
125 | final ItemStack item = LevelToolsUtil.getHand(player);
126 |
127 | if (LevelToolsUtil.isSupportedTool(item.getType())) {
128 | final LevelToolsItem tool = LevelToolsUtil.createLevelToolsItem(item);
129 | final int initial = tool.getLevel();
130 | tool.setLevel(level);
131 | LevelToolsUtil.setHand(player, tool.getItemStack());
132 | if (initial != tool.getLevel()) {
133 | LevelToolsUtil.handleReward(tool, player);
134 | }
135 | player.sendMessage(
136 | colorize(
137 | Objects.requireNonNull(
138 | plugin.getConfig().getString("messages.successfully_executed_action"))));
139 | } else {
140 | player.sendMessage(
141 | colorize(Objects.requireNonNull(plugin.getConfig().getString("messages.item_not_tool"))));
142 | }
143 | }
144 |
145 | @Subcommand("levelup")
146 | @Description("Increases the item in hand's level to next level.")
147 | public void onLevelUp(Player player) {
148 | if (!checkPerm(player)) {
149 | return;
150 | }
151 |
152 | final ItemStack item = LevelToolsUtil.getHand(player);
153 |
154 | if (LevelToolsUtil.isSupportedTool(item.getType())) {
155 | final LevelToolsItem tool = LevelToolsUtil.createLevelToolsItem(item);
156 | tool.setLevel(tool.getLevel() + 1);
157 | LevelToolsUtil.setHand(player, tool.getItemStack());
158 | LevelToolsUtil.handleReward(tool, player);
159 | player.sendMessage(
160 | colorize(
161 | Objects.requireNonNull(
162 | plugin.getConfig().getString("messages.successfully_executed_action"))));
163 | } else {
164 | player.sendMessage(
165 | colorize(Objects.requireNonNull(plugin.getConfig().getString("messages.item_not_tool"))));
166 | }
167 | }
168 |
169 | @Subcommand("debug")
170 | @Description("Shows debug information about the server and plugin.")
171 | public void onDebug(CommandSender sender) {
172 | if (!checkPerm(sender)) {
173 | return;
174 | }
175 |
176 | plugin.getUpdateChecker().check();
177 | sender.sendMessage("LevelTools Debug Information:");
178 | sender.sendMessage("- Server Version: " + Bukkit.getVersion());
179 | sender.sendMessage("- Server Type: " + Bukkit.getBukkitVersion());
180 | sender.sendMessage("- Plugin Version: " + plugin.getDescription().getVersion());
181 | sender.sendMessage("- Latest Version: " + plugin.getUpdateChecker().getLastCheckedVersion());
182 | sender.sendMessage("{!} Please include your configuration with this when asking for help. Please COPY AND PASTE configuration into discord server. {!}");
183 | }
184 |
185 | private boolean checkPerm(CommandSender sender) {
186 | if (!sender.hasPermission("leveltools.admin")) {
187 | sender.sendMessage(
188 | colorize(Objects.requireNonNull(plugin.getConfig().getString("messages.no_permission"))));
189 |
190 | return false;
191 | }
192 |
193 | return true;
194 | }
195 | }
196 |
--------------------------------------------------------------------------------
/src/main/java/me/byteful/plugin/leveltools/LevelToolsPlaceholders.java:
--------------------------------------------------------------------------------
1 | package me.byteful.plugin.leveltools;
2 |
3 | import java.util.Locale;
4 | import me.byteful.plugin.leveltools.api.item.LevelToolsItem;
5 | import me.byteful.plugin.leveltools.util.LevelToolsUtil;
6 | import me.clip.placeholderapi.expansion.PlaceholderExpansion;
7 | import org.bukkit.entity.Player;
8 | import org.bukkit.inventory.ItemStack;
9 | import org.jetbrains.annotations.NotNull;
10 | import org.jetbrains.annotations.Nullable;
11 | import redempt.redlib.RedLib;
12 |
13 | public class LevelToolsPlaceholders extends PlaceholderExpansion {
14 | @Override
15 | public @NotNull String getIdentifier() {
16 | return "leveltools";
17 | }
18 |
19 | @Override
20 | public @NotNull String getAuthor() {
21 | return "byteful";
22 | }
23 |
24 | @Override
25 | public @NotNull String getVersion() {
26 | return LevelToolsPlugin.getInstance().getDescription().getVersion();
27 | }
28 |
29 | @Override
30 | public boolean canRegister() {
31 | return true;
32 | }
33 |
34 | @Override
35 | public boolean persist() {
36 | return true;
37 | }
38 |
39 | @Override
40 | public @Nullable String onPlaceholderRequest(Player player, @NotNull String params) {
41 | if (player == null) {
42 | return null;
43 | }
44 |
45 | final ItemStack hand =
46 | RedLib.MID_VERSION <= 8
47 | ? player.getItemInHand()
48 | : player.getInventory().getItemInMainHand();
49 |
50 | if (!LevelToolsUtil.isSupportedTool(hand.getType())) {
51 | return "N/A";
52 | }
53 |
54 | final LevelToolsItem item = LevelToolsUtil.createLevelToolsItem(hand);
55 |
56 | switch (params.toLowerCase(Locale.ROOT).replace(" ", "_")) {
57 | case "level":
58 | {
59 | return "" + item.getLevel();
60 | }
61 |
62 | case "xp":
63 | {
64 | return "" + item.getXp();
65 | }
66 |
67 | case "max_xp":
68 | {
69 | return "" + item.getMaxXp();
70 | }
71 |
72 | case "progress_bar":
73 | {
74 | return LevelToolsUtil.createDefaultProgressBar(item.getXp(), item.getMaxXp());
75 | }
76 |
77 | default:
78 | {
79 | return "N/A";
80 | }
81 | }
82 | }
83 | }
84 |
--------------------------------------------------------------------------------
/src/main/java/me/byteful/plugin/leveltools/LevelToolsPlugin.java:
--------------------------------------------------------------------------------
1 | package me.byteful.plugin.leveltools;
2 |
3 | import static me.byteful.plugin.leveltools.util.Text.colorize;
4 |
5 | import java.io.IOException;
6 | import java.nio.file.Files;
7 | import java.nio.file.Path;
8 | import java.util.Objects;
9 | import java.util.concurrent.TimeUnit;
10 | import me.byteful.plugin.leveltools.api.AnvilCombineMode;
11 | import me.byteful.plugin.leveltools.api.block.BlockDataManager;
12 | import me.byteful.plugin.leveltools.api.block.BlockDataManagerFactory;
13 | import me.byteful.plugin.leveltools.api.block.impl.FileBlockDataManager;
14 | import me.byteful.plugin.leveltools.api.scheduler.Scheduler;
15 | import me.byteful.plugin.leveltools.listeners.AnvilListener;
16 | import me.byteful.plugin.leveltools.listeners.BlockEventListener;
17 | import me.byteful.plugin.leveltools.listeners.EntityEventListener;
18 | import me.byteful.plugin.leveltools.util.LevelToolsUtil;
19 | import me.byteful.plugin.leveltools.util.UpdateChecker;
20 | import org.bstats.bukkit.Metrics;
21 | import org.bukkit.Bukkit;
22 | import org.bukkit.plugin.PluginManager;
23 | import org.bukkit.plugin.java.JavaPlugin;
24 | import redempt.crunch.CompiledExpression;
25 | import redempt.crunch.Crunch;
26 | import redempt.redlib.RedLib;
27 | import revxrsal.commands.bukkit.BukkitCommandHandler;
28 |
29 | public final class LevelToolsPlugin extends JavaPlugin {
30 | private static LevelToolsPlugin instance;
31 |
32 | private BukkitCommandHandler commandManager;
33 | private AnvilCombineMode anvilCombineMode;
34 | private UpdateChecker updateChecker;
35 | private CompiledExpression levelXpFormula;
36 | private Metrics metrics;
37 | private BlockDataManager blockDataManager;
38 | private Scheduler scheduler;
39 |
40 | public static LevelToolsPlugin getInstance() {
41 | return instance;
42 | }
43 |
44 | @Override
45 | public void onEnable() {
46 | sendStartupBanner();
47 | instance = this;
48 |
49 | scheduler = LevelToolsUtil.createScheduler(this);
50 | updateChecker = new UpdateChecker(this, scheduler);
51 |
52 | saveDefaultConfig();
53 | getConfig().options().copyDefaults(true);
54 | setAnvilCombineMode();
55 | setLevelXpFormula();
56 | getLogger().info("Loaded configuration...");
57 |
58 | blockDataManager = BlockDataManagerFactory.createBlockDataManager(
59 | getDataFolder().toPath(),
60 | getConfig(),
61 | scheduler
62 | );
63 | blockDataManager.load();
64 | getLogger().info("Loaded block data manager...");
65 |
66 | if (getConfig().getBoolean("update.start")) {
67 | updateChecker.check();
68 | }
69 |
70 | if (getConfig().getBoolean("update.periodically")) {
71 | final long delay = 20L * TimeUnit.DAYS.toSeconds(1);
72 | scheduler.syncTimer(() -> updateChecker.check(), delay, delay);
73 | }
74 |
75 | registerListeners();
76 | getLogger().info("Registered listeners...");
77 |
78 | commandManager = BukkitCommandHandler.create(this);
79 | commandManager.setHelpWriter(
80 | (command, actor) ->
81 | String.format(
82 | "&7- &b/%s %s&7: &e%s",
83 | command.getPath().toRealString(), command.getUsage(), command.getDescription()));
84 | commandManager.register(new LevelToolsCommand());
85 | commandManager.registerBrigadier();
86 | getLogger().info("Registered commands...");
87 |
88 | if (getServer().getPluginManager().isPluginEnabled("PlaceholderAPI")) {
89 | new LevelToolsPlaceholders().register();
90 | }
91 |
92 | metrics = new Metrics(this, 21451);
93 | getLogger().info("Successfully started " + getDescription().getFullName() + "!");
94 | }
95 |
96 | @Override
97 | public void onDisable() {
98 | if (metrics != null) {
99 | metrics.shutdown();
100 | }
101 |
102 | if (blockDataManager != null) {
103 | try {
104 | blockDataManager.close();
105 | } catch (IOException e) {
106 | throw new RuntimeException(e);
107 | }
108 | }
109 |
110 | instance = null;
111 |
112 | getLogger().info("Successfully stopped " + getDescription().getFullName() + ".");
113 | }
114 |
115 | private void sendStartupBanner() {
116 | Bukkit.getConsoleSender().sendMessage(colorize(" &b _____"));
117 | Bukkit.getConsoleSender().sendMessage(colorize(" &d| &b| &8Created by &2byteful"));
118 | Bukkit.getConsoleSender()
119 | .sendMessage(
120 | colorize(
121 | String.format(
122 | " &d| &b| &8Running &6%s &8on &6MC %s",
123 | getDescription().getFullName(), RedLib.getServerVersion())));
124 | Bukkit.getConsoleSender()
125 | .sendMessage(
126 | colorize(
127 | " &d|_____ &b| &8Join &9&nhttps://discord.gg/G8BDgqsuyw&8 for support!"));
128 | Bukkit.getConsoleSender().sendMessage("");
129 | }
130 |
131 | private void registerListeners() {
132 | final PluginManager pm = Bukkit.getPluginManager();
133 | pm.registerEvents(new BlockEventListener(blockDataManager, scheduler), this);
134 | pm.registerEvents(new EntityEventListener(), this);
135 | pm.registerEvents(new AnvilListener(), this);
136 | }
137 |
138 | public void setAnvilCombineMode() {
139 | anvilCombineMode =
140 | AnvilCombineMode.fromName(Objects.requireNonNull(getConfig().getString("anvil_combine")));
141 | }
142 |
143 | public void setLevelXpFormula() {
144 | levelXpFormula =
145 | Crunch.compileExpression(
146 | getConfig().getString("level_xp_formula").replace("{current_level}", "$1"));
147 | }
148 |
149 | public AnvilCombineMode getAnvilCombineMode() {
150 | return anvilCombineMode;
151 | }
152 |
153 | public CompiledExpression getLevelXpFormula() {
154 | return levelXpFormula;
155 | }
156 |
157 | public BukkitCommandHandler getCommandManager() {
158 | return commandManager;
159 | }
160 |
161 | public UpdateChecker getUpdateChecker() {
162 | return updateChecker;
163 | }
164 |
165 | public Scheduler getScheduler() {
166 | return scheduler;
167 | }
168 |
169 | public BlockDataManager getBlockDataManager() {
170 | return blockDataManager;
171 | }
172 | }
173 |
--------------------------------------------------------------------------------
/src/main/java/me/byteful/plugin/leveltools/api/AnvilCombineMode.java:
--------------------------------------------------------------------------------
1 | package me.byteful.plugin.leveltools.api;
2 |
3 | import java.util.function.BinaryOperator;
4 | import me.byteful.plugin.leveltools.model.LevelAndXPModel;
5 | import org.jetbrains.annotations.NotNull;
6 |
7 | public enum AnvilCombineMode {
8 | HIGHER_OF_BOTH(
9 | (item1, item2) -> {
10 | final int level1 = item1.getLevel();
11 | final int level2 = item2.getLevel();
12 |
13 | final double xp1 = item1.getXp();
14 | final double xp2 = item2.getXp();
15 |
16 | int level;
17 | double xp;
18 |
19 | if (level1 == level2) {
20 | level = level1;
21 | xp = Math.max(xp1, xp2);
22 | } else {
23 | level = Math.max(level1, level2);
24 | if (level == level1) {
25 | xp = xp1;
26 | } else {
27 | xp = xp2;
28 | }
29 | }
30 |
31 | return new LevelAndXPModel(level, xp);
32 | }),
33 | LOWER_OF_BOTH(
34 | (item1, item2) -> {
35 | final int level1 = item1.getLevel();
36 | final int level2 = item2.getLevel();
37 |
38 | final double xp1 = item1.getXp();
39 | final double xp2 = item2.getXp();
40 |
41 | int level;
42 | double xp;
43 |
44 | if (level1 == level2) {
45 | level = level1;
46 | xp = Math.min(xp1, xp2);
47 | } else {
48 | level = Math.min(level1, level2);
49 | if (level == level1) {
50 | xp = xp1;
51 | } else {
52 | xp = xp2;
53 | }
54 | }
55 |
56 | return new LevelAndXPModel(level, xp);
57 | }),
58 | ADD_BOTH(
59 | (item1, item2) -> {
60 | final int level1 = item1.getLevel();
61 | final int level2 = item2.getLevel();
62 |
63 | final double xp1 = item1.getXp();
64 | final double xp2 = item2.getXp();
65 |
66 | return new LevelAndXPModel(level1 + level2, xp1 + xp2);
67 | });
68 |
69 | @NotNull private final BinaryOperator handler;
70 |
71 | AnvilCombineMode(@NotNull BinaryOperator handler) {
72 | this.handler = handler;
73 | }
74 |
75 | @NotNull
76 | public static AnvilCombineMode fromName(@NotNull String name) {
77 | for (AnvilCombineMode value : values()) {
78 | if (value.name().equalsIgnoreCase(name.replace(" ", "_"))) {
79 | return value;
80 | }
81 | }
82 |
83 | return ADD_BOTH;
84 | }
85 |
86 | @NotNull
87 | public BinaryOperator getHandler() {
88 | return handler;
89 | }
90 |
91 | @Override
92 | public String toString() {
93 | return "AnvilCombineMode{" + "handler=" + handler + '}';
94 | }
95 | }
96 |
--------------------------------------------------------------------------------
/src/main/java/me/byteful/plugin/leveltools/api/RewardType.java:
--------------------------------------------------------------------------------
1 | package me.byteful.plugin.leveltools.api;
2 |
3 | import com.cryptomorin.xseries.XEnchantment;
4 | import java.util.Arrays;
5 | import java.util.Locale;
6 | import java.util.Objects;
7 | import java.util.Optional;
8 | import me.byteful.plugin.leveltools.api.item.LevelToolsItem;
9 | import org.apache.commons.lang.StringUtils;
10 | import org.apache.commons.lang.math.NumberUtils;
11 | import org.bukkit.Bukkit;
12 | import org.bukkit.entity.Player;
13 | import org.jetbrains.annotations.NotNull;
14 |
15 | public enum RewardType {
16 | COMMAND("command", false) {
17 | @Override
18 | public void apply(
19 | @NotNull LevelToolsItem tool, @NotNull String[] split, @NotNull Player player) {
20 | Bukkit.dispatchCommand(
21 | Bukkit.getConsoleSender(),
22 | String.join(" ", Arrays.copyOfRange(split, 1, split.length))
23 | .replace("{player}", player.getName())
24 | .replace("%player%", player.getName()));
25 | }
26 | },
27 | PLAYER_COMMAND("player-command", false) {
28 | @Override
29 | public void apply(
30 | @NotNull LevelToolsItem tool, @NotNull String[] split, @NotNull Player player) {
31 | player.chat(
32 | "/"
33 | + String.join(" ", Arrays.copyOfRange(split, 1, split.length))
34 | .replace("{player}", player.getName())
35 | .replace("%player%", player.getName()));
36 | }
37 | },
38 | PLAYER_OPCOMMAND("player-opcommand", false) {
39 | @Override
40 | public void apply(
41 | @NotNull LevelToolsItem tool, @NotNull String[] split, @NotNull Player player) {
42 | final boolean isOP = player.isOp();
43 | if (!isOP) {
44 | player.setOp(true);
45 | }
46 | PLAYER_COMMAND.apply(tool, split, player);
47 | player.setOp(isOP);
48 | }
49 | },
50 | ENCHANT("enchant") {
51 | @Override
52 | public void apply(
53 | @NotNull LevelToolsItem tool, @NotNull String[] split, @NotNull Player player) {
54 | if (split.length < 3) {
55 | return;
56 | }
57 |
58 | final Optional enchant = XEnchantment.matchXEnchantment(split[1]);
59 |
60 | if (enchant.isPresent() && NumberUtils.isNumber(split[2])) {
61 | tool.enchant(enchant.get().getEnchant(), Integer.parseInt(split[2]));
62 | }
63 | }
64 | },
65 | ENCHANT_2("enchant2") {
66 | @Override
67 | public void apply(
68 | @NotNull LevelToolsItem tool, @NotNull String[] split, @NotNull Player player) {
69 | if (split.length < 3) {
70 | return;
71 | }
72 |
73 | final Optional enchant = XEnchantment.matchXEnchantment(split[1]);
74 |
75 | if (NumberUtils.isNumber(split[2])) {
76 | final int level = Integer.parseInt(split[2]);
77 |
78 | if (enchant.isPresent()
79 | && tool.getItemStack()
80 | .getEnchantmentLevel(Objects.requireNonNull(enchant.get().getEnchant()))
81 | < level) {
82 | tool.enchant(enchant.get().getEnchant(), level);
83 | }
84 | }
85 | }
86 | },
87 | ENCHANT_3("enchant3") {
88 | @Override
89 | public void apply(
90 | @NotNull LevelToolsItem tool, @NotNull String[] split, @NotNull Player player) {
91 | if (split.length < 3) {
92 | return;
93 | }
94 |
95 | final Optional enchant = XEnchantment.matchXEnchantment(split[1]);
96 |
97 | if (NumberUtils.isNumber(split[2])) {
98 | final int level = Integer.parseInt(split[2]);
99 |
100 | if (enchant.isPresent()) {
101 | final int currentLvl =
102 | tool.getItemStack()
103 | .getEnchantmentLevel(Objects.requireNonNull(enchant.get().getEnchant()));
104 | tool.enchant(enchant.get().getEnchant(), currentLvl + level);
105 | }
106 | }
107 | }
108 | },
109 | ATTRIBUTE("attribute") {
110 | @Override
111 | public void apply(
112 | @NotNull LevelToolsItem tool, @NotNull String[] split, @NotNull Player player) {
113 | if (split.length < 3) {
114 | return;
115 | }
116 |
117 | String attribute = split[1];
118 |
119 | if (NumberUtils.isNumber(split[2])) {
120 | final double modifier = Double.parseDouble(split[2]);
121 |
122 | if (StringUtils.countMatches(attribute, "_") >= 2) {
123 | attribute = attribute.toLowerCase(Locale.ROOT).replaceFirst("_+", ".").trim();
124 | }
125 |
126 | tool.modifyAttribute(attribute, modifier);
127 | }
128 | }
129 | };
130 |
131 | @NotNull private final String configKey;
132 | private final boolean shouldUpdate;
133 |
134 | RewardType(@NotNull String configKey) {
135 | this.configKey = configKey;
136 | this.shouldUpdate = true;
137 | }
138 |
139 | RewardType(@NotNull String configKey, boolean shouldUpdate) {
140 | this.configKey = configKey;
141 | this.shouldUpdate = shouldUpdate;
142 | }
143 |
144 | @NotNull
145 | public static Optional fromConfigKey(@NotNull String configKey) {
146 | for (RewardType value : values()) {
147 | if (value.configKey.equals(configKey)) {
148 | return Optional.of(value);
149 | }
150 | }
151 |
152 | return Optional.empty();
153 | }
154 |
155 | public abstract void apply(
156 | @NotNull LevelToolsItem tool, @NotNull String[] split, @NotNull Player player);
157 |
158 | @NotNull
159 | public String getConfigKey() {
160 | return configKey;
161 | }
162 |
163 | public boolean isShouldUpdate() {
164 | return shouldUpdate;
165 | }
166 | }
167 |
--------------------------------------------------------------------------------
/src/main/java/me/byteful/plugin/leveltools/api/block/BlockDataManager.java:
--------------------------------------------------------------------------------
1 | package me.byteful.plugin.leveltools.api.block;
2 |
3 |
4 | import java.io.Closeable;
5 |
6 | public interface BlockDataManager extends Closeable {
7 | boolean isPlacedBlock(BlockPosition pos);
8 |
9 | void addPlacedBlock(BlockPosition pos);
10 |
11 | void removePlacedBlock(BlockPosition pos);
12 |
13 | void load();
14 | }
15 |
--------------------------------------------------------------------------------
/src/main/java/me/byteful/plugin/leveltools/api/block/BlockDataManagerFactory.java:
--------------------------------------------------------------------------------
1 | package me.byteful.plugin.leveltools.api.block;
2 |
3 | import me.byteful.plugin.leveltools.api.block.impl.FileBlockDataManager;
4 | import me.byteful.plugin.leveltools.api.block.impl.SqliteBlockDataManager;
5 | import me.byteful.plugin.leveltools.api.scheduler.Scheduler;
6 | import org.bukkit.configuration.ConfigurationSection;
7 |
8 | import java.nio.file.Path;
9 | import java.sql.SQLException;
10 |
11 | public class BlockDataManagerFactory {
12 | public static BlockDataManager createBlockDataManager(Path dataFolder, ConfigurationSection config, Scheduler scheduler) {
13 | String storageType = config.getString("block_data_storage.type", "LEGACY_TEXT");
14 |
15 | switch (storageType.toUpperCase()) {
16 | case "SQLITE":
17 | return new SqliteBlockDataManager(dataFolder.resolve("placed_blocks.db"), scheduler);
18 | case "LEGACY_TEXT":
19 | default:
20 | return new FileBlockDataManager(dataFolder.resolve("placed_blocks.txt"), scheduler);
21 | }
22 | }
23 | }
--------------------------------------------------------------------------------
/src/main/java/me/byteful/plugin/leveltools/api/block/BlockPosition.java:
--------------------------------------------------------------------------------
1 | package me.byteful.plugin.leveltools.api.block;
2 |
3 | import org.bukkit.Bukkit;
4 | import org.bukkit.Location;
5 | import org.bukkit.World;
6 | import org.bukkit.block.Block;
7 |
8 | import java.util.Objects;
9 |
10 | public final class BlockPosition {
11 | private final String world;
12 | private final int x, y, z;
13 |
14 | public BlockPosition(String world, int x, int y, int z) {
15 | this.world = world;
16 | this.x = x;
17 | this.y = y;
18 | this.z = z;
19 | }
20 |
21 | public String getWorld() {
22 | return world;
23 | }
24 |
25 | public int getX() {
26 | return x;
27 | }
28 |
29 | public int getY() {
30 | return y;
31 | }
32 |
33 | public int getZ() {
34 | return z;
35 | }
36 |
37 | public static BlockPosition fromBukkit(Block block) {
38 | final Location l = block.getLocation();
39 |
40 | return new BlockPosition(l.getWorld().getName(), l.getBlockX(), l.getBlockY(), l.getBlockZ());
41 | }
42 |
43 | public Block toBukkit() {
44 | final World bw = Bukkit.getWorld(world);
45 | if (bw == null) return null;
46 |
47 | return new Location(bw, x, y, z).getBlock();
48 | }
49 |
50 | @Override
51 | public boolean equals(Object o) {
52 | if (this == o) return true;
53 | if (o == null || getClass() != o.getClass()) return false;
54 | BlockPosition that = (BlockPosition) o;
55 | return getX() == that.getX() && getY() == that.getY() && getZ() == that.getZ() && Objects.equals(getWorld(), that.getWorld());
56 | }
57 |
58 | @Override
59 | public int hashCode() {
60 | return Objects.hash(getWorld(), getX(), getY(), getZ());
61 | }
62 |
63 | @Override
64 | public String toString() {
65 | return "BlockPosition{" + "world='" + world + '\'' + ", x=" + x + ", y=" + y + ", z=" + z + '}';
66 | }
67 | }
68 |
--------------------------------------------------------------------------------
/src/main/java/me/byteful/plugin/leveltools/api/block/impl/FileBlockDataManager.java:
--------------------------------------------------------------------------------
1 | package me.byteful.plugin.leveltools.api.block.impl;
2 |
3 | import java.io.IOException;
4 | import java.nio.charset.StandardCharsets;
5 | import java.nio.file.Files;
6 | import java.nio.file.Path;
7 | import java.util.Collections;
8 | import java.util.HashSet;
9 | import java.util.Map;
10 | import java.util.Set;
11 | import java.util.concurrent.ConcurrentHashMap;
12 | import java.util.stream.Collectors;
13 |
14 | import com.google.common.collect.Sets;
15 | import me.byteful.plugin.leveltools.api.block.BlockDataManager;
16 | import me.byteful.plugin.leveltools.api.block.BlockPosition;
17 | import me.byteful.plugin.leveltools.api.scheduler.ScheduledTask;
18 | import me.byteful.plugin.leveltools.api.scheduler.Scheduler;
19 | import me.byteful.plugin.leveltools.util.Text;
20 |
21 | public class FileBlockDataManager implements BlockDataManager {
22 | private static final int MAX_CACHE_SIZE = 100_000;
23 | private final Set cache = ConcurrentHashMap.newKeySet();
24 | private final Path file;
25 | private final ScheduledTask saveTask;
26 |
27 | public FileBlockDataManager(Path file, Scheduler scheduler) {
28 | this.file = file;
29 | this.saveTask = scheduler.asyncTimer(this::save, 5 * 20, 5 * 20);
30 | }
31 |
32 | private void save() {
33 | final Set lines;
34 | synchronized (cache) {
35 | lines = cache.stream()
36 | .map(x -> String.format("{%s}{%s}{%s}%s", x.getX(), x.getY(), x.getZ(), x.getWorld()))
37 | .collect(Collectors.toSet());
38 | }
39 |
40 | try {
41 | Files.write(file, lines, StandardCharsets.UTF_8);
42 | } catch (IOException e) {
43 | e.printStackTrace();
44 | }
45 | }
46 |
47 | @Override
48 | public boolean isPlacedBlock(BlockPosition pos) {
49 | return cache.contains(pos);
50 | }
51 |
52 | @Override
53 | public void addPlacedBlock(BlockPosition pos) {
54 | if (cache.size() >= MAX_CACHE_SIZE) return;
55 | cache.add(pos);
56 | }
57 |
58 | @Override
59 | public void removePlacedBlock(BlockPosition pos) {
60 | cache.remove(pos);
61 | }
62 |
63 | @Override
64 | public void load() {
65 | try {
66 | for (String line : Files.readAllLines(file, StandardCharsets.UTF_8)) {
67 | final String[] data = Text.substringsBetween(line, "{", "}");
68 | if (data == null || data.length != 3) continue;
69 |
70 | try {
71 | final int x = Integer.parseInt(data[0]);
72 | final int y = Integer.parseInt(data[1]);
73 | final int z = Integer.parseInt(data[2]);
74 | final String world = line.substring(String.format("{%s}{%s}{%s}", x, y, z).length());
75 |
76 | cache.add(new BlockPosition(world, x, y, z));
77 | } catch (Exception ignored) {}
78 | }
79 | } catch (IOException e) {
80 | throw new RuntimeException(e);
81 | }
82 | }
83 |
84 | @Override
85 | public void close() {
86 | saveTask.stop();
87 | save();
88 | cache.clear();
89 | }
90 | }
91 |
--------------------------------------------------------------------------------
/src/main/java/me/byteful/plugin/leveltools/api/event/LevelToolsLevelIncreaseEvent.java:
--------------------------------------------------------------------------------
1 | package me.byteful.plugin.leveltools.api.event;
2 |
3 | import java.util.Objects;
4 | import me.byteful.plugin.leveltools.api.item.LevelToolsItem;
5 | import org.bukkit.entity.Player;
6 | import org.bukkit.event.Cancellable;
7 | import org.bukkit.event.Event;
8 | import org.bukkit.event.HandlerList;
9 | import org.jetbrains.annotations.NotNull;
10 |
11 | public class LevelToolsLevelIncreaseEvent extends Event implements Cancellable {
12 | private static final HandlerList handlers = new HandlerList();
13 | @NotNull private final LevelToolsItem item;
14 | @NotNull private final Player player;
15 | private int newLevel;
16 | private boolean isCancelled;
17 |
18 | public LevelToolsLevelIncreaseEvent(@NotNull LevelToolsItem item, @NotNull Player player) {
19 | this.item = item;
20 | this.player = player;
21 | }
22 |
23 | public LevelToolsLevelIncreaseEvent(
24 | @NotNull LevelToolsItem item, @NotNull Player player, int newLevel, boolean isCancelled) {
25 | this.item = item;
26 | this.player = player;
27 | this.newLevel = newLevel;
28 | this.isCancelled = isCancelled;
29 | }
30 |
31 | @NotNull
32 | public static HandlerList getHandlerList() {
33 | return handlers;
34 | }
35 |
36 | @NotNull
37 | @Override
38 | public HandlerList getHandlers() {
39 | return handlers;
40 | }
41 |
42 | @NotNull
43 | public LevelToolsItem getItem() {
44 | return item;
45 | }
46 |
47 | @NotNull
48 | public Player getPlayer() {
49 | return player;
50 | }
51 |
52 | public int getNewLevel() {
53 | return newLevel;
54 | }
55 |
56 | public void setNewLevel(int newLevel) {
57 | this.newLevel = newLevel;
58 | }
59 |
60 | @Override
61 | public boolean isCancelled() {
62 | return isCancelled;
63 | }
64 |
65 | @Override
66 | public void setCancelled(boolean cancelled) {
67 | isCancelled = cancelled;
68 | }
69 |
70 | @Override
71 | public boolean equals(Object object) {
72 | if (this == object) return true;
73 | if (object == null || getClass() != object.getClass()) return false;
74 | LevelToolsLevelIncreaseEvent that = (LevelToolsLevelIncreaseEvent) object;
75 | return getNewLevel() == that.getNewLevel()
76 | && isCancelled() == that.isCancelled()
77 | && Objects.equals(getItem(), that.getItem())
78 | && Objects.equals(getPlayer(), that.getPlayer());
79 | }
80 |
81 | @Override
82 | public int hashCode() {
83 | return Objects.hash(getItem(), getPlayer(), getNewLevel(), isCancelled());
84 | }
85 |
86 | @Override
87 | public String toString() {
88 | return "LevelToolsLevelIncreaseEvent{"
89 | + "item="
90 | + item
91 | + ", player="
92 | + player
93 | + ", newLevel="
94 | + newLevel
95 | + ", isCancelled="
96 | + isCancelled
97 | + '}';
98 | }
99 | }
100 |
--------------------------------------------------------------------------------
/src/main/java/me/byteful/plugin/leveltools/api/event/LevelToolsXPIncreaseEvent.java:
--------------------------------------------------------------------------------
1 | package me.byteful.plugin.leveltools.api.event;
2 |
3 | import java.util.Objects;
4 | import me.byteful.plugin.leveltools.api.item.LevelToolsItem;
5 | import org.bukkit.entity.Player;
6 | import org.bukkit.event.Cancellable;
7 | import org.bukkit.event.Event;
8 | import org.bukkit.event.HandlerList;
9 | import org.jetbrains.annotations.NotNull;
10 |
11 | public class LevelToolsXPIncreaseEvent extends Event implements Cancellable {
12 | private static final HandlerList handlers = new HandlerList();
13 | @NotNull private final LevelToolsItem item;
14 | @NotNull private final Player player;
15 | private final double initialXp;
16 | private double newXp;
17 | private boolean isCancelled, isModified = false;
18 |
19 | public LevelToolsXPIncreaseEvent(
20 | @NotNull LevelToolsItem item, @NotNull Player player, double initialXp) {
21 | this.item = item;
22 | this.player = player;
23 | this.initialXp = initialXp;
24 | }
25 |
26 | public LevelToolsXPIncreaseEvent(
27 | @NotNull LevelToolsItem item,
28 | @NotNull Player player,
29 | double initialXp,
30 | double newXp,
31 | boolean isCancelled) {
32 | this.item = item;
33 | this.player = player;
34 | this.initialXp = initialXp;
35 | this.newXp = newXp;
36 | this.isCancelled = isCancelled;
37 | }
38 |
39 | @NotNull
40 | public static HandlerList getHandlerList() {
41 | return handlers;
42 | }
43 |
44 | @Override
45 | @NotNull
46 | public HandlerList getHandlers() {
47 | return handlers;
48 | }
49 |
50 | @Override
51 | public boolean isCancelled() {
52 | return isCancelled;
53 | }
54 |
55 | @Override
56 | public void setCancelled(boolean cancelled) {
57 | isCancelled = cancelled;
58 | }
59 |
60 | @NotNull
61 | public LevelToolsItem getItem() {
62 | return item;
63 | }
64 |
65 | @NotNull
66 | public Player getPlayer() {
67 | return player;
68 | }
69 |
70 | public double getNewXp() {
71 | return newXp;
72 | }
73 |
74 | public void setNewXp(double newXp) {
75 | this.newXp = newXp;
76 | this.isModified = true;
77 | }
78 |
79 | public double getInitialXp() {
80 | return initialXp;
81 | }
82 |
83 | public boolean isModified() {
84 | return isModified;
85 | }
86 |
87 | @Override
88 | public boolean equals(Object object) {
89 | if (this == object) return true;
90 | if (object == null || getClass() != object.getClass()) return false;
91 | LevelToolsXPIncreaseEvent that = (LevelToolsXPIncreaseEvent) object;
92 | return Double.compare(getInitialXp(), that.getInitialXp()) == 0
93 | && Double.compare(getNewXp(), that.getNewXp()) == 0
94 | && isCancelled() == that.isCancelled()
95 | && Objects.equals(getItem(), that.getItem())
96 | && Objects.equals(getPlayer(), that.getPlayer());
97 | }
98 |
99 | @Override
100 | public int hashCode() {
101 | return Objects.hash(getItem(), getPlayer(), getInitialXp(), getNewXp(), isCancelled());
102 | }
103 |
104 | @Override
105 | public String toString() {
106 | return "LevelToolsXPIncreaseEvent{"
107 | + "item="
108 | + item
109 | + ", player="
110 | + player
111 | + ", initialXp="
112 | + initialXp
113 | + ", newXp="
114 | + newXp
115 | + ", isCancelled="
116 | + isCancelled
117 | + '}';
118 | }
119 | }
120 |
--------------------------------------------------------------------------------
/src/main/java/me/byteful/plugin/leveltools/api/item/LevelToolsItem.java:
--------------------------------------------------------------------------------
1 | package me.byteful.plugin.leveltools.api.item;
2 |
3 | import me.byteful.plugin.leveltools.LevelToolsPlugin;
4 | import me.byteful.plugin.leveltools.util.LevelToolsUtil;
5 | import org.bukkit.enchantments.Enchantment;
6 | import org.bukkit.inventory.ItemStack;
7 | import org.jetbrains.annotations.NotNull;
8 | import redempt.crunch.CompiledExpression;
9 |
10 | public interface LevelToolsItem {
11 | @NotNull
12 | ItemStack getItemStack();
13 |
14 | int getLevel();
15 |
16 | void setLevel(int level);
17 |
18 | double getXp();
19 |
20 | void setXp(double xp);
21 |
22 | int getLastHandledReward();
23 |
24 | void setLastHandledReward(int rewardKey);
25 |
26 | default double getMaxXp() {
27 | final CompiledExpression formula = LevelToolsPlugin.getInstance().getLevelXpFormula();
28 | final double nextXpRequirement = LevelToolsUtil.round(formula.evaluate(getLevel()), 1);
29 |
30 | if (nextXpRequirement <= 0.0) {
31 | throw new RuntimeException(
32 | "The next XP requirement formula returned a value too small! Please optimize your formula.");
33 | }
34 |
35 | return nextXpRequirement;
36 | }
37 |
38 | void enchant(Enchantment enchantment, int level);
39 |
40 | void modifyAttribute(String attribute, double modifier);
41 | }
42 |
--------------------------------------------------------------------------------
/src/main/java/me/byteful/plugin/leveltools/api/item/impl/NBTLevelToolsItem.java:
--------------------------------------------------------------------------------
1 | package me.byteful.plugin.leveltools.api.item.impl;
2 |
3 | import de.tr7zw.changeme.nbtapi.NBTCompoundList;
4 | import de.tr7zw.changeme.nbtapi.NBTItem;
5 | import de.tr7zw.changeme.nbtapi.NBTListCompound;
6 | import java.util.HashMap;
7 | import java.util.Map;
8 | import java.util.Objects;
9 | import me.byteful.plugin.leveltools.api.item.LevelToolsItem;
10 | import me.byteful.plugin.leveltools.util.LevelToolsUtil;
11 | import org.bukkit.enchantments.Enchantment;
12 | import org.bukkit.inventory.ItemStack;
13 | import org.jetbrains.annotations.NotNull;
14 |
15 | public class NBTLevelToolsItem implements LevelToolsItem {
16 | @NotNull
17 | public static final String LEVEL_KEY = "levelToolsLevel",
18 | XP_KEY = "levelToolsXp",
19 | LAST_REWARD_KEY = "levelToolsReward";
20 |
21 | @NotNull private NBTItem nbt;
22 | @NotNull private Map enchantments;
23 | @NotNull private Map attributes;
24 |
25 | public NBTLevelToolsItem(@NotNull ItemStack stack) {
26 | this.nbt = new NBTItem(stack);
27 | this.enchantments = new HashMap<>();
28 | this.attributes = new HashMap<>();
29 | }
30 |
31 | @NotNull
32 | @Override
33 | public ItemStack getItemStack() {
34 | final ItemStack stack =
35 | LevelToolsUtil.buildItemStack(
36 | nbt.getItem().clone(), enchantments, getLevel(), getXp(), getMaxXp());
37 |
38 | nbt = new NBTItem(stack);
39 | final NBTCompoundList attr = nbt.getCompoundList("AttributeModifiers");
40 | attributes.forEach(
41 | (attribute, modifier) -> {
42 | final NBTListCompound list = attr.addCompound();
43 | list.setDouble("Amount", modifier);
44 | list.setString("AttributeName", attribute);
45 | list.setString("Name", attribute);
46 | list.setInteger("Operation", 0);
47 | list.setInteger("UUIDLeast", 59664);
48 | list.setInteger("UUIDMost", 31453);
49 | });
50 |
51 | return nbt.getItem();
52 | }
53 |
54 | @Override
55 | public int getLevel() {
56 | if (!nbt.hasKey(LEVEL_KEY)) {
57 | setLevel(0);
58 | }
59 |
60 | return nbt.getInteger(LEVEL_KEY);
61 | }
62 |
63 | @Override
64 | public void setLevel(int level) {
65 | if (level < 0) {
66 | setLevel0(0);
67 |
68 | return;
69 | }
70 |
71 | setLevel0(level);
72 | }
73 |
74 | @Override
75 | public double getXp() {
76 | if (!nbt.hasTag(XP_KEY)) {
77 | setXp(0.0D);
78 | }
79 |
80 | return nbt.getDouble(XP_KEY);
81 | }
82 |
83 | @Override
84 | public void setXp(double xp) {
85 | if (xp < 0.0D) {
86 | setXp0(0.0D);
87 |
88 | return;
89 | }
90 |
91 | setXp0(xp);
92 | }
93 |
94 | @Override
95 | public int getLastHandledReward() {
96 | if (!nbt.hasTag(LAST_REWARD_KEY)) {
97 | setLastHandledReward(-1);
98 | }
99 |
100 | return nbt.getInteger(LAST_REWARD_KEY);
101 | }
102 |
103 | @Override
104 | public void setLastHandledReward(int rewardKey) {
105 | nbt.setInteger(LAST_REWARD_KEY, rewardKey);
106 | }
107 |
108 | private void setLevel0(int level) {
109 | nbt.setInteger(LEVEL_KEY, level);
110 | }
111 |
112 | private void setXp0(double xp) {
113 | nbt.setDouble(XP_KEY, xp);
114 | }
115 |
116 | @Override
117 | public void enchant(Enchantment enchantment, int level) {
118 | enchantments.put(enchantment, level);
119 | }
120 |
121 | @Override
122 | public void modifyAttribute(String attribute, double modifier) {
123 | attributes.put(attribute, modifier);
124 | }
125 |
126 | @NotNull
127 | public NBTItem getNBT() {
128 | return nbt;
129 | }
130 |
131 | public void setNBT(@NotNull NBTItem nbt) {
132 | this.nbt = nbt;
133 | }
134 |
135 | @NotNull
136 | public Map getEnchantments() {
137 | return enchantments;
138 | }
139 |
140 | public void setEnchantments(@NotNull Map enchantments) {
141 | this.enchantments = enchantments;
142 | }
143 |
144 | public @NotNull Map getAttributes() {
145 | return attributes;
146 | }
147 |
148 | public void setAttributes(@NotNull Map attributes) {
149 | this.attributes = attributes;
150 | }
151 |
152 | @Override
153 | public boolean equals(Object o) {
154 | if (this == o) return true;
155 | if (o == null || getClass() != o.getClass()) return false;
156 | NBTLevelToolsItem that = (NBTLevelToolsItem) o;
157 | return nbt.equals(that.nbt)
158 | && enchantments.equals(that.enchantments)
159 | && attributes.equals(that.attributes);
160 | }
161 |
162 | @Override
163 | public int hashCode() {
164 | return Objects.hash(nbt, enchantments, attributes);
165 | }
166 |
167 | @Override
168 | public String toString() {
169 | return "NBTLevelToolsItem{"
170 | + "nbt="
171 | + nbt
172 | + ", enchantments="
173 | + enchantments
174 | + ", attributes="
175 | + attributes
176 | + '}';
177 | }
178 | }
179 |
--------------------------------------------------------------------------------
/src/main/java/me/byteful/plugin/leveltools/api/item/impl/PDCLevelToolsItem.java:
--------------------------------------------------------------------------------
1 | package me.byteful.plugin.leveltools.api.item.impl;
2 |
3 | import java.util.HashMap;
4 | import java.util.Locale;
5 | import java.util.Map;
6 | import java.util.Objects;
7 | import me.byteful.plugin.leveltools.LevelToolsPlugin;
8 | import me.byteful.plugin.leveltools.api.item.LevelToolsItem;
9 | import me.byteful.plugin.leveltools.util.LevelToolsUtil;
10 | import org.bukkit.NamespacedKey;
11 | import org.bukkit.attribute.Attribute;
12 | import org.bukkit.attribute.AttributeModifier;
13 | import org.bukkit.enchantments.Enchantment;
14 | import org.bukkit.inventory.ItemStack;
15 | import org.bukkit.inventory.meta.ItemMeta;
16 | import org.bukkit.persistence.PersistentDataContainer;
17 | import org.bukkit.persistence.PersistentDataHolder;
18 | import org.bukkit.persistence.PersistentDataType;
19 | import org.jetbrains.annotations.NotNull;
20 |
21 | public class PDCLevelToolsItem implements LevelToolsItem {
22 | @NotNull
23 | public static final NamespacedKey
24 | LEVEL_KEY = new NamespacedKey(LevelToolsPlugin.getInstance(), "levelToolsLevel"),
25 | XP_KEY = new NamespacedKey(LevelToolsPlugin.getInstance(), "levelToolsXp"),
26 | LAST_REWARD_KEY = new NamespacedKey(LevelToolsPlugin.getInstance(), "levelToolsReward");
27 |
28 | @NotNull private ItemStack stack;
29 | @NotNull private Map enchantments;
30 | @NotNull private Map attributes;
31 |
32 | public PDCLevelToolsItem(@NotNull ItemStack stack) {
33 | this.stack = stack;
34 | this.enchantments = new HashMap<>();
35 | this.attributes = new HashMap<>();
36 | }
37 |
38 | @Override
39 | public @NotNull ItemStack getItemStack() {
40 | final ItemStack stack =
41 | LevelToolsUtil.buildItemStack(this.stack, enchantments, getLevel(), getXp(), getMaxXp());
42 |
43 | final ItemMeta meta = stack.getItemMeta();
44 | assert meta != null : "ItemMeta is null! Should not happen.";
45 | attributes.forEach(
46 | (attribute, modifier) -> {
47 | final Attribute attr =
48 | Attribute.valueOf(attribute.replace(".", "_").toUpperCase(Locale.ROOT).trim());
49 | final AttributeModifier mod =
50 | new AttributeModifier(attribute, modifier, AttributeModifier.Operation.ADD_NUMBER);
51 | meta.addAttributeModifier(attr, mod);
52 | });
53 | stack.setItemMeta(meta);
54 |
55 | return stack;
56 | }
57 |
58 | @Override
59 | public int getLevel() {
60 | final PersistentDataContainer pdc = getItemPDC().getPersistentDataContainer();
61 |
62 | Integer value = pdc.get(LEVEL_KEY, PersistentDataType.INTEGER);
63 |
64 | if (value == null) {
65 | setLevel(0);
66 |
67 | value = 0;
68 | }
69 |
70 | return value;
71 | }
72 |
73 | @Override
74 | public void setLevel(int level) {
75 | final PersistentDataHolder holder = getItemPDC();
76 | final PersistentDataContainer pdc = holder.getPersistentDataContainer();
77 |
78 | pdc.set(LEVEL_KEY, PersistentDataType.INTEGER, Math.max(level, 0));
79 | stack.setItemMeta((ItemMeta) holder);
80 | }
81 |
82 | @Override
83 | public double getXp() {
84 | final PersistentDataContainer pdc = getItemPDC().getPersistentDataContainer();
85 |
86 | Double value = pdc.get(XP_KEY, PersistentDataType.DOUBLE);
87 |
88 | if (value == null) {
89 | setXp(0.0D);
90 |
91 | value = 0.0D;
92 | }
93 |
94 | return value;
95 | }
96 |
97 | @Override
98 | public void setXp(double xp) {
99 | final PersistentDataHolder holder = getItemPDC();
100 | final PersistentDataContainer pdc = holder.getPersistentDataContainer();
101 |
102 | pdc.set(XP_KEY, PersistentDataType.DOUBLE, Math.max(xp, 0.0));
103 | stack.setItemMeta((ItemMeta) holder);
104 | }
105 |
106 | @Override
107 | public int getLastHandledReward() {
108 | final PersistentDataContainer pdc = getItemPDC().getPersistentDataContainer();
109 |
110 | Integer value = pdc.get(LAST_REWARD_KEY, PersistentDataType.INTEGER);
111 | if (value == null) {
112 | setLastHandledReward(-1);
113 | value = -1;
114 | }
115 |
116 | return value;
117 | }
118 |
119 | @Override
120 | public void setLastHandledReward(int rewardKey) {
121 | final PersistentDataHolder holder = getItemPDC();
122 | final PersistentDataContainer pdc = holder.getPersistentDataContainer();
123 |
124 | pdc.set(LAST_REWARD_KEY, PersistentDataType.INTEGER, rewardKey);
125 | stack.setItemMeta((ItemMeta) holder);
126 | }
127 |
128 | @Override
129 | public void enchant(Enchantment enchantment, int level) {
130 | enchantments.put(enchantment, level);
131 | }
132 |
133 | @Override
134 | public void modifyAttribute(String attribute, double modifier) {
135 | attributes.put(attribute, modifier);
136 | }
137 |
138 | private PersistentDataHolder getItemPDC() {
139 | return stack.getItemMeta();
140 | }
141 |
142 | @NotNull
143 | public ItemStack getStack() {
144 | return stack;
145 | }
146 |
147 | public void setStack(@NotNull ItemStack stack) {
148 | this.stack = stack;
149 | }
150 |
151 | @NotNull
152 | public Map getEnchantments() {
153 | return enchantments;
154 | }
155 |
156 | public void setEnchantments(@NotNull Map enchantments) {
157 | this.enchantments = enchantments;
158 | }
159 |
160 | public @NotNull Map getAttributes() {
161 | return attributes;
162 | }
163 |
164 | public void setAttributes(@NotNull Map attributes) {
165 | this.attributes = attributes;
166 | }
167 |
168 | @Override
169 | public boolean equals(Object o) {
170 | if (this == o) return true;
171 | if (o == null || getClass() != o.getClass()) return false;
172 | PDCLevelToolsItem that = (PDCLevelToolsItem) o;
173 | return stack.equals(that.stack)
174 | && enchantments.equals(that.enchantments)
175 | && attributes.equals(that.attributes);
176 | }
177 |
178 | @Override
179 | public int hashCode() {
180 | return Objects.hash(stack, enchantments, attributes);
181 | }
182 |
183 | @Override
184 | public String toString() {
185 | return "PDCLevelToolsItem{"
186 | + "stack="
187 | + stack
188 | + ", enchantments="
189 | + enchantments
190 | + ", attributes="
191 | + attributes
192 | + '}';
193 | }
194 | }
195 |
--------------------------------------------------------------------------------
/src/main/java/me/byteful/plugin/leveltools/api/scheduler/ScheduledTask.java:
--------------------------------------------------------------------------------
1 | package me.byteful.plugin.leveltools.api.scheduler;
2 |
3 | public interface ScheduledTask {
4 | void stop();
5 | }
6 |
--------------------------------------------------------------------------------
/src/main/java/me/byteful/plugin/leveltools/api/scheduler/Scheduler.java:
--------------------------------------------------------------------------------
1 | package me.byteful.plugin.leveltools.api.scheduler;
2 |
3 | import org.bukkit.Location;
4 |
5 | public interface Scheduler {
6 | void asyncDelayed(Runnable runnable, long ticksDelay);
7 |
8 | void syncTimer(Runnable runnable, long ticksDelay, long ticksPeriod);
9 |
10 | void locationDelayed(Runnable runnable, Location location, long ticksDelay);
11 |
12 | ScheduledTask asyncTimer(Runnable runnable, long ticksDelay, long ticksPeriod);
13 | }
14 |
--------------------------------------------------------------------------------
/src/main/java/me/byteful/plugin/leveltools/api/scheduler/impl/bukkit/BukkitScheduledTask.java:
--------------------------------------------------------------------------------
1 | package me.byteful.plugin.leveltools.api.scheduler.impl.bukkit;
2 |
3 | import me.byteful.plugin.leveltools.api.scheduler.ScheduledTask;
4 | import org.bukkit.scheduler.BukkitTask;
5 |
6 | public class BukkitScheduledTask implements ScheduledTask {
7 | private final BukkitTask task;
8 |
9 | public BukkitScheduledTask(BukkitTask task) {
10 | this.task = task;
11 | }
12 |
13 | @Override
14 | public void stop() {
15 | task.cancel();
16 | }
17 | }
18 |
--------------------------------------------------------------------------------
/src/main/java/me/byteful/plugin/leveltools/api/scheduler/impl/bukkit/BukkitScheduler.java:
--------------------------------------------------------------------------------
1 | package me.byteful.plugin.leveltools.api.scheduler.impl.bukkit;
2 |
3 | import me.byteful.plugin.leveltools.LevelToolsPlugin;
4 | import me.byteful.plugin.leveltools.api.scheduler.ScheduledTask;
5 | import me.byteful.plugin.leveltools.api.scheduler.Scheduler;
6 | import org.bukkit.Bukkit;
7 | import org.bukkit.Location;
8 |
9 | public class BukkitScheduler implements Scheduler {
10 | private final LevelToolsPlugin plugin;
11 |
12 | public BukkitScheduler(LevelToolsPlugin plugin) {
13 | this.plugin = plugin;
14 | }
15 |
16 | @Override
17 | public void asyncDelayed(Runnable runnable, long ticksDelay) {
18 | Bukkit.getScheduler().runTaskLaterAsynchronously(plugin, runnable, ticksDelay);
19 | }
20 |
21 | @Override
22 | public void syncTimer(Runnable runnable, long ticksDelay, long ticksPeriod) {
23 | Bukkit.getScheduler().runTaskTimer(plugin, runnable, ticksDelay, ticksPeriod);
24 | }
25 |
26 | @Override
27 | public void locationDelayed(Runnable runnable, Location location, long ticksDelay) {
28 | Bukkit.getScheduler().runTaskLater(plugin, runnable, ticksDelay);
29 | }
30 |
31 | @Override
32 | public ScheduledTask asyncTimer(Runnable runnable, long ticksDelay, long ticksPeriod) {
33 | return new BukkitScheduledTask(Bukkit.getScheduler().runTaskTimerAsynchronously(plugin, runnable, ticksDelay, ticksPeriod));
34 | }
35 | }
36 |
--------------------------------------------------------------------------------
/src/main/java/me/byteful/plugin/leveltools/api/scheduler/impl/folia/FoliaScheduledTask.java:
--------------------------------------------------------------------------------
1 | package me.byteful.plugin.leveltools.api.scheduler.impl.folia;
2 |
3 |
4 | import me.byteful.plugin.leveltools.api.scheduler.ScheduledTask;
5 |
6 | public class FoliaScheduledTask implements ScheduledTask {
7 | private final io.papermc.paper.threadedregions.scheduler.ScheduledTask task;
8 |
9 | public FoliaScheduledTask(io.papermc.paper.threadedregions.scheduler.ScheduledTask task) {
10 | this.task = task;
11 | }
12 |
13 | @Override
14 | public void stop() {
15 | task.cancel();
16 | }
17 | }
18 |
--------------------------------------------------------------------------------
/src/main/java/me/byteful/plugin/leveltools/api/scheduler/impl/folia/FoliaScheduler.java:
--------------------------------------------------------------------------------
1 | package me.byteful.plugin.leveltools.api.scheduler.impl.folia;
2 |
3 | import me.byteful.plugin.leveltools.LevelToolsPlugin;
4 | import me.byteful.plugin.leveltools.api.scheduler.ScheduledTask;
5 | import me.byteful.plugin.leveltools.api.scheduler.Scheduler;
6 | import org.bukkit.Bukkit;
7 | import org.bukkit.Location;
8 |
9 | import java.util.concurrent.TimeUnit;
10 |
11 | public class FoliaScheduler implements Scheduler {
12 | private final LevelToolsPlugin plugin;
13 |
14 | public FoliaScheduler(LevelToolsPlugin plugin) {
15 | this.plugin = plugin;
16 | }
17 |
18 | @Override
19 | public void asyncDelayed(Runnable runnable, long ticksDelay) {
20 | Bukkit.getAsyncScheduler().runDelayed(plugin, x -> runnable.run(), ticksDelay * 50, TimeUnit.MILLISECONDS);
21 | }
22 |
23 | @Override
24 | public void syncTimer(Runnable runnable, long ticksDelay, long ticksPeriod) {
25 | Bukkit.getGlobalRegionScheduler().runAtFixedRate(plugin, x -> runnable.run(), ticksDelay, ticksPeriod);
26 | }
27 |
28 | @Override
29 | public void locationDelayed(Runnable runnable, Location location, long ticksDelay) {
30 | Bukkit.getRegionScheduler().runDelayed(plugin, location, x -> runnable.run(), ticksDelay);
31 | }
32 |
33 | @Override
34 | public ScheduledTask asyncTimer(Runnable runnable, long ticksDelay, long ticksPeriod) {
35 | return new FoliaScheduledTask(Bukkit.getAsyncScheduler().runAtFixedRate(plugin, x -> runnable.run(), ticksDelay * 50, ticksPeriod + 50, TimeUnit.MILLISECONDS));
36 | }
37 | }
38 |
--------------------------------------------------------------------------------
/src/main/java/me/byteful/plugin/leveltools/listeners/AnvilListener.java:
--------------------------------------------------------------------------------
1 | package me.byteful.plugin.leveltools.listeners;
2 |
3 | import me.byteful.plugin.leveltools.LevelToolsPlugin;
4 | import me.byteful.plugin.leveltools.api.AnvilCombineMode;
5 | import me.byteful.plugin.leveltools.api.item.LevelToolsItem;
6 | import me.byteful.plugin.leveltools.model.LevelAndXPModel;
7 | import me.byteful.plugin.leveltools.util.LevelToolsUtil;
8 | import org.bukkit.event.EventHandler;
9 | import org.bukkit.event.EventPriority;
10 | import org.bukkit.event.Listener;
11 | import org.bukkit.event.inventory.PrepareAnvilEvent;
12 | import org.bukkit.inventory.AnvilInventory;
13 | import org.bukkit.inventory.ItemStack;
14 |
15 | public class AnvilListener implements Listener {
16 | @EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true)
17 | public void onAnvilCombine(PrepareAnvilEvent e) {
18 | final AnvilInventory inv = e.getInventory();
19 | final ItemStack firstItem = inv.getItem(0);
20 | final ItemStack secondItem = inv.getItem(1);
21 | final ItemStack result = e.getResult();
22 |
23 | if (result == null
24 | || !LevelToolsUtil.isSupportedTool(result.getType())
25 | || firstItem == null
26 | || secondItem == null
27 | || !LevelToolsUtil.isSupportedTool(firstItem.getType())
28 | || !LevelToolsUtil.isSupportedTool(secondItem.getType())) {
29 | return;
30 | }
31 |
32 | final AnvilCombineMode mode = LevelToolsPlugin.getInstance().getAnvilCombineMode();
33 | final LevelAndXPModel first =
34 | LevelAndXPModel.fromItem(LevelToolsUtil.createLevelToolsItem(firstItem));
35 | final LevelAndXPModel second =
36 | LevelAndXPModel.fromItem(LevelToolsUtil.createLevelToolsItem(secondItem));
37 | final LevelAndXPModel finished = mode.getHandler().apply(first, second);
38 | final LevelToolsItem finalItem = LevelToolsUtil.createLevelToolsItem(result);
39 | finalItem.setLevel(finished.getLevel());
40 | finalItem.setXp(finished.getXp());
41 |
42 | e.setResult(finalItem.getItemStack());
43 | }
44 |
45 | @EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true)
46 | public void onAnvilRepair(PrepareAnvilEvent e) {
47 | final AnvilInventory inv = e.getInventory();
48 | final ItemStack firstItem = inv.getItem(0);
49 | final ItemStack secondItem = inv.getItem(1);
50 | final ItemStack result = e.getResult();
51 |
52 | if (result == null
53 | || !LevelToolsUtil.isSupportedTool(result.getType())
54 | || firstItem == null
55 | || secondItem == null
56 | || !LevelToolsUtil.isSupportedTool(firstItem.getType())) {
57 | return;
58 | }
59 |
60 | // Use result item to create a new leveltools item instance so other plugins can modify the result and we can still attempt to work with that
61 | // just read the lvl and xp from the original item so it doesnt get reset
62 | final LevelToolsItem original = LevelToolsUtil.createLevelToolsItem(firstItem);
63 | final LevelToolsItem finalItem = LevelToolsUtil.createLevelToolsItem(result);
64 | finalItem.setLevel(original.getLevel());
65 | finalItem.setXp(original.getXp());
66 | finalItem.setLastHandledReward(original.getLastHandledReward());
67 | e.setResult(finalItem.getItemStack()); // This has to be done to patch lore issues.
68 | }
69 | }
70 |
--------------------------------------------------------------------------------
/src/main/java/me/byteful/plugin/leveltools/listeners/BlockEventListener.java:
--------------------------------------------------------------------------------
1 | package me.byteful.plugin.leveltools.listeners;
2 |
3 | import java.util.*;
4 | import java.util.stream.Collectors;
5 | import me.byteful.plugin.leveltools.LevelToolsPlugin;
6 | import me.byteful.plugin.leveltools.api.block.BlockDataManager;
7 | import me.byteful.plugin.leveltools.api.block.BlockPosition;
8 | import me.byteful.plugin.leveltools.api.scheduler.Scheduler;
9 | import me.byteful.plugin.leveltools.util.LevelToolsUtil;
10 | import org.bukkit.Material;
11 | import org.bukkit.block.Block;
12 | import org.bukkit.entity.Player;
13 | import org.bukkit.event.EventHandler;
14 | import org.bukkit.event.EventPriority;
15 | import org.bukkit.event.block.BlockBreakEvent;
16 | import org.bukkit.event.block.BlockPlaceEvent;
17 | import org.bukkit.inventory.ItemStack;
18 |
19 | public class BlockEventListener extends XPListener {
20 | private final BlockDataManager blockDataManager;
21 | private final Scheduler scheduler;
22 |
23 | public BlockEventListener(BlockDataManager blockDataManager, Scheduler scheduler) {
24 | this.blockDataManager = blockDataManager;
25 | this.scheduler = scheduler;
26 | }
27 |
28 | private boolean isPPBEnabled() {
29 | return !LevelToolsPlugin.getInstance().getConfig().getBoolean("playerPlacedBlocks");
30 | }
31 |
32 | @EventHandler(priority = EventPriority.HIGH, ignoreCancelled = true)
33 | public void on(BlockBreakEvent event) {
34 | if (!isPPBEnabled()) return;
35 |
36 | final Block block = event.getBlock();
37 | final BlockPosition pos = BlockPosition.fromBukkit(block);
38 | scheduler.locationDelayed(() -> blockDataManager.removePlacedBlock(pos), block.getLocation(), 1);
39 | }
40 |
41 | @EventHandler(priority = EventPriority.LOW)
42 | public void on(BlockPlaceEvent event) {
43 | if (!isPPBEnabled()) return;
44 |
45 | blockDataManager.addPlacedBlock(BlockPosition.fromBukkit(event.getBlock()));
46 | }
47 |
48 | @EventHandler(priority = EventPriority.MONITOR, ignoreCancelled = true)
49 | public void onBlockBreak(BlockBreakEvent e) {
50 | final Player player = e.getPlayer();
51 |
52 | if (!player.hasPermission("leveltools.enabled")) {
53 | return;
54 | }
55 |
56 | final Block block = e.getBlock();
57 | final ItemStack hand = LevelToolsUtil.getHand(player);
58 |
59 | if (!LevelToolsPlugin.getInstance().getConfig().getBoolean("playerPlacedBlocks")
60 | && blockDataManager.isPlacedBlock(BlockPosition.fromBukkit(block))) {
61 | return;
62 | }
63 |
64 | final String type =
65 | LevelToolsPlugin.getInstance().getConfig().getString("block_list_type", "blacklist");
66 | final Set blocks =
67 | LevelToolsPlugin.getInstance().getConfig().getStringList("block_list").stream()
68 | .map(Material::getMaterial)
69 | .filter(Objects::nonNull)
70 | .collect(Collectors.toSet());
71 |
72 | if (type != null && type.equalsIgnoreCase("whitelist") && !blocks.contains(block.getType())) {
73 | return;
74 | }
75 |
76 | if (type != null && type.equalsIgnoreCase("blacklist") && blocks.contains(block.getType())) {
77 | return;
78 | }
79 |
80 | if (!LevelToolsUtil.isAxe(hand.getType())
81 | && !LevelToolsUtil.isPickaxe(hand.getType())
82 | && !LevelToolsUtil.isShovel(hand.getType())) {
83 | return;
84 | }
85 |
86 | handle(
87 | LevelToolsUtil.createLevelToolsItem(hand),
88 | player,
89 | LevelToolsUtil.getBlockModifier(block.getType()));
90 | }
91 | }
92 |
--------------------------------------------------------------------------------
/src/main/java/me/byteful/plugin/leveltools/listeners/EntityEventListener.java:
--------------------------------------------------------------------------------
1 | package me.byteful.plugin.leveltools.listeners;
2 |
3 | import java.util.Objects;
4 | import java.util.Set;
5 | import java.util.stream.Collectors;
6 | import me.byteful.plugin.leveltools.LevelToolsPlugin;
7 | import me.byteful.plugin.leveltools.util.LevelToolsUtil;
8 | import org.bukkit.entity.EntityType;
9 | import org.bukkit.entity.Player;
10 | import org.bukkit.event.EventHandler;
11 | import org.bukkit.event.EventPriority;
12 | import org.bukkit.event.entity.EntityDeathEvent;
13 | import org.bukkit.inventory.ItemStack;
14 |
15 | public class EntityEventListener extends XPListener {
16 | @EventHandler(priority = EventPriority.MONITOR, ignoreCancelled = true)
17 | public void onEntityKillEntity(EntityDeathEvent e) {
18 | Player killer = e.getEntity().getKiller();
19 |
20 | if (killer == null || !killer.hasPermission("leveltools.enabled")) {
21 | return;
22 | }
23 |
24 | final ItemStack hand = LevelToolsUtil.getHand(killer);
25 |
26 | final String ltype =
27 | LevelToolsPlugin.getInstance().getConfig().getString("entity_list_type", "blacklist");
28 | final Set entities =
29 | LevelToolsPlugin.getInstance().getConfig().getStringList("entity_list").stream()
30 | .map(
31 | str -> {
32 | try {
33 | return EntityType.valueOf(str);
34 | } catch (Exception ignored) {
35 | return null;
36 | }
37 | })
38 | .filter(Objects::nonNull)
39 | .collect(Collectors.toSet());
40 |
41 | if (ltype != null
42 | && ltype.equalsIgnoreCase("whitelist")
43 | && !entities.contains(e.getEntityType())) {
44 | return;
45 | }
46 |
47 | if (ltype != null
48 | && ltype.equalsIgnoreCase("blacklist")
49 | && entities.contains(e.getEntityType())) {
50 | return;
51 | }
52 |
53 | if (!LevelToolsUtil.isSword(hand.getType())
54 | && !LevelToolsUtil.isProjectileShooter(hand.getType())) {
55 | return;
56 | }
57 |
58 | handle(
59 | LevelToolsUtil.createLevelToolsItem(hand),
60 | killer,
61 | LevelToolsUtil.getCombatModifier(e.getEntityType()));
62 | }
63 | }
64 |
--------------------------------------------------------------------------------
/src/main/java/me/byteful/plugin/leveltools/listeners/XPListener.java:
--------------------------------------------------------------------------------
1 | package me.byteful.plugin.leveltools.listeners;
2 |
3 |
4 | import static redempt.redlib.misc.FormatUtils.formatMoney;
5 |
6 | import com.cryptomorin.xseries.XSound;
7 | import java.util.List;
8 | import me.byteful.plugin.leveltools.LevelToolsPlugin;
9 | import me.byteful.plugin.leveltools.api.event.LevelToolsLevelIncreaseEvent;
10 | import me.byteful.plugin.leveltools.api.event.LevelToolsXPIncreaseEvent;
11 | import me.byteful.plugin.leveltools.api.item.LevelToolsItem;
12 | import me.byteful.plugin.leveltools.util.LevelToolsUtil;
13 | import me.byteful.plugin.leveltools.util.Text;
14 | import me.byteful.plugin.leveltools.util.XPBooster;
15 | import org.bukkit.Bukkit;
16 | import org.bukkit.World;
17 | import org.bukkit.configuration.ConfigurationSection;
18 | import org.bukkit.entity.Player;
19 | import org.bukkit.event.Listener;
20 |
21 | public abstract class XPListener implements Listener {
22 |
23 | protected void handle(LevelToolsItem tool, Player player, double modifier) {
24 | World world = player.getWorld();
25 |
26 | final List disabledWorlds =
27 | LevelToolsPlugin.getInstance().getConfig().getStringList("disabled_worlds");
28 | if (disabledWorlds.contains(world.getName())) {
29 | return;
30 | }
31 |
32 | modifier =
33 | Math.max(
34 | 0,
35 | XPBooster.apply(
36 | player, modifier)); // It's best if we just prevent negative XP addition :)
37 | double newXp = LevelToolsUtil.round(tool.getXp() + modifier, 1);
38 |
39 | final LevelToolsXPIncreaseEvent xpEvent =
40 | new LevelToolsXPIncreaseEvent(tool, player, newXp, newXp, false);
41 | Bukkit.getPluginManager().callEvent(xpEvent);
42 |
43 | if (xpEvent.isCancelled()) {
44 | return;
45 | }
46 |
47 | tool.setXp(xpEvent.getNewXp());
48 |
49 | if (tool.getXp() >= tool.getMaxXp()) {
50 | int newLevel = tool.getLevel() + 1;
51 | final int maxLevel = LevelToolsPlugin.getInstance().getConfig().getInt("max_level");
52 |
53 | if (newLevel > maxLevel) {
54 | if (tool.getXp() != tool.getMaxXp()) {
55 | tool.setXp(tool.getMaxXp());
56 | LevelToolsUtil.setHand(player, tool.getItemStack());
57 | }
58 | return;
59 | }
60 |
61 | final LevelToolsLevelIncreaseEvent levelEvent =
62 | new LevelToolsLevelIncreaseEvent(tool, player, newLevel, false);
63 | Bukkit.getPluginManager().callEvent(levelEvent);
64 |
65 | if (levelEvent.isCancelled()) {
66 | return;
67 | }
68 |
69 | tool.setXp(LevelToolsUtil.round(Math.abs(tool.getXp() - tool.getMaxXp()), 1));
70 | tool.setLevel(levelEvent.getNewLevel());
71 |
72 | if (levelEvent.getNewLevel() == maxLevel) {
73 | tool.setXp(0);
74 | tool.setLevel(maxLevel);
75 | }
76 |
77 | final ConfigurationSection soundCs =
78 | LevelToolsPlugin.getInstance().getConfig().getConfigurationSection("level_up_sound");
79 |
80 | final String sound;
81 | final XSound parsed;
82 |
83 | if (soundCs != null) {
84 | sound = soundCs.getString("sound", null);
85 | if (sound != null) {
86 | parsed = XSound.matchXSound(sound).orElse(null);
87 |
88 | if (parsed != null && parsed.isSupported()) {
89 | if (parsed.parseSound() != null) {
90 | player.playSound(
91 | player.getLocation(),
92 | parsed.parseSound(),
93 | (float) soundCs.getDouble("pitch"),
94 | (float) soundCs.getDouble("volume"));
95 | }
96 | }
97 | }
98 | }
99 | }
100 |
101 | LevelToolsUtil.setHand(player, tool.getItemStack());
102 |
103 | if (LevelToolsPlugin.getInstance().getConfig().getBoolean("display.actionBar.enabled")) {
104 | final String text =
105 | Text.colorize(
106 | LevelToolsPlugin.getInstance()
107 | .getConfig()
108 | .getString("display.actionBar.text")
109 | .replace(
110 | "{progress_bar}",
111 | LevelToolsUtil.createDefaultProgressBar(tool.getXp(), tool.getMaxXp()))
112 | .replace("{xp}", String.valueOf(tool.getXp()))
113 | .replace("{max_xp}", String.valueOf(tool.getMaxXp()))
114 | .replace("{level}", String.valueOf(tool.getLevel()))
115 | .replace("{max_xp_formatted}", formatMoney(tool.getMaxXp()))
116 | .replace("{xp_formatted}", formatMoney(tool.getXp())));
117 | LevelToolsUtil.sendActionBar(player, text);
118 | }
119 |
120 | // Update LevelTools stuff before running rewards to prevent any weird errors.
121 | LevelToolsUtil.handleReward(tool, player);
122 | }
123 | }
124 |
--------------------------------------------------------------------------------
/src/main/java/me/byteful/plugin/leveltools/model/LevelAndXPModel.java:
--------------------------------------------------------------------------------
1 | package me.byteful.plugin.leveltools.model;
2 |
3 | import java.util.Objects;
4 | import me.byteful.plugin.leveltools.api.item.LevelToolsItem;
5 | import me.byteful.plugin.leveltools.util.LevelToolsUtil;
6 | import org.jetbrains.annotations.NotNull;
7 |
8 | public final class LevelAndXPModel {
9 | private final int level;
10 | private final double xp;
11 |
12 | public LevelAndXPModel(int level, double xp) {
13 | this.level = level;
14 | this.xp = LevelToolsUtil.round(xp, 1);
15 | }
16 |
17 | @NotNull
18 | public static LevelAndXPModel fromItem(@NotNull LevelToolsItem item) {
19 | return new LevelAndXPModel(item.getLevel(), item.getXp());
20 | }
21 |
22 | public int getLevel() {
23 | return level;
24 | }
25 |
26 | public double getXp() {
27 | return xp;
28 | }
29 |
30 | @Override
31 | public boolean equals(Object o) {
32 | if (this == o) return true;
33 | if (o == null || getClass() != o.getClass()) return false;
34 | LevelAndXPModel that = (LevelAndXPModel) o;
35 | return level == that.level && Double.compare(that.xp, xp) == 0;
36 | }
37 |
38 | @Override
39 | public int hashCode() {
40 | return Objects.hash(level, xp);
41 | }
42 |
43 | @Override
44 | public String toString() {
45 | return "LevelAndXPModel{" + "level=" + level + ", xp=" + xp + '}';
46 | }
47 | }
48 |
--------------------------------------------------------------------------------
/src/main/java/me/byteful/plugin/leveltools/util/LevelToolsUtil.java:
--------------------------------------------------------------------------------
1 | package me.byteful.plugin.leveltools.util;
2 |
3 | import static me.byteful.plugin.leveltools.util.Text.colorize;
4 | import static me.byteful.plugin.leveltools.util.Text.decolorize;
5 | import static redempt.redlib.misc.FormatUtils.formatMoney;
6 |
7 | import com.cryptomorin.xseries.XMaterial;
8 | import com.cryptomorin.xseries.messages.ActionBar;
9 | import com.google.common.base.Strings;
10 | import de.tr7zw.changeme.nbtapi.NBTItem;
11 | import java.math.BigDecimal;
12 | import java.math.RoundingMode;
13 | import java.util.List;
14 | import java.util.Locale;
15 | import java.util.Map;
16 | import java.util.Objects;
17 | import java.util.concurrent.ThreadLocalRandom;
18 | import java.util.stream.Collectors;
19 | import me.byteful.plugin.leveltools.LevelToolsPlugin;
20 | import me.byteful.plugin.leveltools.api.RewardType;
21 | import me.byteful.plugin.leveltools.api.item.LevelToolsItem;
22 | import me.byteful.plugin.leveltools.api.item.impl.NBTLevelToolsItem;
23 | import me.byteful.plugin.leveltools.api.item.impl.PDCLevelToolsItem;
24 | import me.byteful.plugin.leveltools.api.scheduler.Scheduler;
25 | import me.byteful.plugin.leveltools.api.scheduler.impl.bukkit.BukkitScheduler;
26 | import me.byteful.plugin.leveltools.api.scheduler.impl.folia.FoliaScheduler;
27 | import net.md_5.bungee.api.ChatMessageType;
28 | import net.md_5.bungee.api.chat.TextComponent;
29 | import org.apache.commons.lang.math.NumberUtils;
30 | import org.bukkit.ChatColor;
31 | import org.bukkit.Material;
32 | import org.bukkit.configuration.ConfigurationSection;
33 | import org.bukkit.enchantments.Enchantment;
34 | import org.bukkit.entity.EntityType;
35 | import org.bukkit.entity.Player;
36 | import org.bukkit.inventory.ItemFlag;
37 | import org.bukkit.inventory.ItemStack;
38 | import org.bukkit.inventory.meta.ItemMeta;
39 | import org.jetbrains.annotations.NotNull;
40 | import redempt.redlib.RedLib;
41 | import xyz.mackan.ItemNames.ItemNames;
42 |
43 | public final class LevelToolsUtil {
44 | private static final String LORE_PREFIX = "&f&l&o&n&m&k";
45 |
46 | public static String getProgressBar(
47 | double percent,
48 | int totalBars,
49 | String prefixSymbol,
50 | String suffixSymbol,
51 | String barSymbol,
52 | ChatColor prefixColor,
53 | ChatColor suffixColor,
54 | ChatColor completedColor,
55 | ChatColor placeholderColor) {
56 | int progressBars = roundDown(totalBars * percent);
57 |
58 | return colorize(
59 | ""
60 | + prefixColor
61 | + prefixSymbol
62 | + Strings.repeat("" + completedColor + barSymbol, progressBars)
63 | + Strings.repeat("" + placeholderColor + barSymbol, Math.abs(totalBars - progressBars))
64 | + suffixColor
65 | + suffixSymbol);
66 | }
67 |
68 | public static double getCombatModifier(EntityType entityType) {
69 | final ConfigurationSection combat_xp_modifiers =
70 | LevelToolsPlugin.getInstance().getConfig().getConfigurationSection("combat_xp_modifiers");
71 |
72 | final Double custom = getCustomModifier(combat_xp_modifiers, entityType.name());
73 | if (custom != null) return custom;
74 |
75 | final ConfigurationSection default_combat_xp_modifier =
76 | LevelToolsPlugin.getInstance()
77 | .getConfig()
78 | .getConfigurationSection("default_combat_xp_modifier");
79 |
80 | return calculateFromRange(default_combat_xp_modifier);
81 | }
82 |
83 | public static double getBlockModifier(Material material) {
84 | final ConfigurationSection block_xp_modifiers =
85 | LevelToolsPlugin.getInstance().getConfig().getConfigurationSection("block_xp_modifiers");
86 |
87 | final Double custom = getCustomModifier(block_xp_modifiers, material.name());
88 | if (custom != null) return custom;
89 |
90 | final ConfigurationSection default_block_xp_modifier =
91 | LevelToolsPlugin.getInstance()
92 | .getConfig()
93 | .getConfigurationSection("default_block_xp_modifier");
94 |
95 | return calculateFromRange(default_block_xp_modifier);
96 | }
97 |
98 | private static Double getCustomModifier(ConfigurationSection config, String type) {
99 | for (String modifier : config.getKeys(false)) {
100 | if (modifier.equalsIgnoreCase(type)) {
101 | final ConfigurationSection modifierCs = config.getConfigurationSection(modifier);
102 |
103 | return calculateFromRange(modifierCs);
104 | }
105 | }
106 | return null;
107 | }
108 |
109 | @NotNull
110 | private static Double calculateFromRange(ConfigurationSection modifierCs) {
111 | double min = modifierCs.getDouble("min");
112 | double max = modifierCs.getDouble("max");
113 | if (Double.compare(min, max) == 0) {
114 | return min;
115 | }
116 | if (min > max) {
117 | double hold = min;
118 | min = max;
119 | max = hold;
120 | }
121 | return round(ThreadLocalRandom.current().nextDouble(min, max), 1);
122 | }
123 |
124 | public static boolean isPickaxe(Material material) {
125 | return material.name().endsWith("_PICKAXE");
126 | }
127 |
128 | public static boolean isAxe(Material material) {
129 | return material.name().endsWith("_AXE");
130 | }
131 |
132 | public static boolean isShovel(Material material) {
133 | return material.name().endsWith("_SHOVEL");
134 | }
135 |
136 | public static boolean isSword(Material material) {
137 | return material.name().endsWith("_SWORD");
138 | }
139 |
140 | public static boolean isProjectileShooter(Material material) {
141 | return material == XMaterial.BOW.parseMaterial()
142 | || (RedLib.MID_VERSION >= 14 && material == XMaterial.CROSSBOW.parseMaterial());
143 | }
144 |
145 | public static boolean isSupportedTool(Material material) {
146 | return isPickaxe(material)
147 | || isAxe(material)
148 | || isShovel(material)
149 | || isSword(material)
150 | || isProjectileShooter(material);
151 | }
152 |
153 | public static ItemStack getHand(Player player) {
154 | return RedLib.MID_VERSION >= 9
155 | ? player.getInventory().getItemInMainHand().clone()
156 | : player.getItemInHand().clone();
157 | }
158 |
159 | public static void setHand(Player player, ItemStack stack) {
160 | if (RedLib.MID_VERSION >= 9) {
161 | player.getInventory().setItemInMainHand(stack);
162 | } else {
163 | player.setItemInHand(stack);
164 | }
165 | }
166 |
167 | public static String createDefaultProgressBar(double xp, double maxXp) {
168 | ConfigurationSection cs =
169 | LevelToolsPlugin.getInstance().getConfig().getConfigurationSection("progress_bar");
170 |
171 | return LevelToolsUtil.getProgressBar(
172 | (xp / maxXp),
173 | cs.getInt("total_bars"),
174 | cs.getString("prefix_symbol"),
175 | cs.getString("suffix_symbol"),
176 | cs.getString("bar_symbol"),
177 | ChatColor.getByChar(cs.getString("prefix_color")),
178 | ChatColor.getByChar(cs.getString("suffix_color")),
179 | ChatColor.getByChar(cs.getString("completed_color")),
180 | ChatColor.getByChar(cs.getString("placeholder_color")));
181 | }
182 |
183 | public static double round(double value, int places) {
184 | if (places < 0) throw new IllegalArgumentException();
185 |
186 | BigDecimal bd = BigDecimal.valueOf(value);
187 | bd = bd.setScale(places, RoundingMode.HALF_UP);
188 |
189 | return bd.doubleValue();
190 | }
191 |
192 | public static int roundDown(double value) {
193 | BigDecimal bd = BigDecimal.valueOf(value);
194 | bd = bd.setScale(1, RoundingMode.DOWN);
195 |
196 | return bd.intValue();
197 | }
198 |
199 | public static LevelToolsItem createLevelToolsItem(ItemStack stack) {
200 | if (RedLib.MID_VERSION >= 14) {
201 | if (RedLib.MID_VERSION < 18) {
202 | final NBTItem nbt = new NBTItem(stack);
203 | if (nbt.getKeys().stream().anyMatch(s -> s.startsWith("levelTools"))) {
204 | return new NBTLevelToolsItem(
205 | stack); // Support tools created with "old" NBT system for 1.14+.
206 | }
207 | }
208 |
209 | return new PDCLevelToolsItem(stack);
210 | } else {
211 | return new NBTLevelToolsItem(stack);
212 | }
213 | }
214 |
215 | public static String getLocalizedName(ItemStack item) {
216 | return RedLib.MID_VERSION > 16
217 | ? Objects.requireNonNull(item.getItemMeta()).getLocalizedName()
218 | : ItemNames.getItemName(item);
219 | }
220 |
221 | public static ItemStack buildItemStack(
222 | ItemStack stack, Map enchantments, int level, double xp, double maxXp) {
223 | final ConfigurationSection cs =
224 | LevelToolsPlugin.getInstance().getConfig().getConfigurationSection("display");
225 |
226 | final ItemMeta meta = stack.getItemMeta();
227 | assert meta != null : "ItemMeta is null! Should not happen.";
228 | final String progressBar = LevelToolsUtil.createDefaultProgressBar(xp, maxXp);
229 | if (cs.getBoolean("name.enabled")) {
230 | meta.setDisplayName(
231 | Text.colorize(
232 | cs.getString("name.text")
233 | .replace("{item}", getLocalizedName(stack))
234 | .replace("{level}", String.valueOf(level))
235 | .replace("{xp}", String.valueOf(xp))
236 | .replace("{max_xp}", String.valueOf(maxXp))
237 | .replace("{max_xp_formatted}", formatMoney(maxXp))
238 | .replace("{xp_formatted}", formatMoney(xp))
239 | .replace("{progress_bar}", progressBar)));
240 | }
241 | if (cs.getBoolean("lore.enabled")) {
242 | List lines =
243 | cs.getStringList("lore.lines").stream()
244 | .map(str -> LORE_PREFIX + str)
245 | .map(
246 | str ->
247 | colorize(
248 | str.replace("{level}", String.valueOf(level))
249 | .replace("{xp}", String.valueOf(xp))
250 | .replace("{max_xp}", String.valueOf(maxXp))
251 | .replace("{progress_bar}", progressBar))
252 | .replace("{max_xp_formatted}", formatMoney(maxXp))
253 | .replace("{xp_formatted}", formatMoney(xp)))
254 | .collect(Collectors.toList());
255 | smartSetLore(meta, lines);
256 | }
257 | for (Map.Entry entry : enchantments.entrySet()) {
258 | meta.addEnchant(entry.getKey(), entry.getValue(), true);
259 | }
260 | if (LevelToolsPlugin.getInstance().getConfig().getBoolean("hide_attributes", true)) {
261 | meta.addItemFlags(ItemFlag.HIDE_ATTRIBUTES);
262 | }
263 | stack.setItemMeta(meta);
264 |
265 | return stack;
266 | }
267 |
268 | private static void smartSetLore(@NotNull ItemMeta meta, @NotNull List toAdd) {
269 | final List lore = meta.getLore();
270 | if (!meta.hasLore() || lore == null) {
271 | meta.setLore(toAdd);
272 |
273 | return;
274 | }
275 |
276 | final int[] bounds = findPrefixBounds(lore);
277 | final int start = bounds[0];
278 | final int end = bounds[1];
279 | if (start == -1) {
280 | lore.addAll(toAdd);
281 | meta.setLore(lore);
282 |
283 | return;
284 | }
285 | if (end > lore.size()) {
286 | meta.setLore(toAdd);
287 |
288 | return;
289 | }
290 | final List sub = lore.subList(start, end);
291 | sub.clear();
292 | sub.addAll(toAdd);
293 | meta.setLore(lore);
294 | }
295 |
296 | private static int[] findPrefixBounds(@NotNull List lore) {
297 | final int[] arr = new int[]{-1, -1};
298 | for (int i = 0; i < lore.size(); i++) {
299 | if (decolorize(lore.get(i)).startsWith(LORE_PREFIX)) {
300 | if (arr[0] == -1) {
301 | arr[0] = i;
302 | arr[1] = i;
303 | } else {
304 | arr[1] = i;
305 | }
306 | }
307 | }
308 |
309 | return arr;
310 | }
311 |
312 | public static void handleReward(LevelToolsItem tool, Player player) {
313 | final ConfigurationSection rewardCs = getCsFromType(tool.getItemStack().getType());
314 |
315 | for (String key : rewardCs.getKeys(false)) {
316 | if (!NumberUtils.isNumber(key)) {
317 | continue;
318 | }
319 |
320 | final int keyNum = Integer.parseInt(key);
321 | if (keyNum < 0) continue;
322 | if (keyNum != tool.getLevel()) continue;
323 | if (tool.getLastHandledReward() == keyNum) return;
324 |
325 | tool.setLastHandledReward(keyNum);
326 | setHand(player, tool.getItemStack());
327 | for (String rewardStr : rewardCs.getStringList(key)) {
328 | final String[] split = rewardStr.split(" ");
329 |
330 | if (split.length < 2) {
331 | continue;
332 | }
333 |
334 | RewardType.fromConfigKey(
335 | split[0].toLowerCase(Locale.ROOT).trim().replace(" ", "-").replace("_", "-"))
336 | .ifPresent(
337 | type -> {
338 | type.apply(tool, split, player);
339 | if (type.isShouldUpdate()) {
340 | setHand(player, tool.getItemStack());
341 | }
342 | });
343 | }
344 |
345 | return;
346 | }
347 | }
348 |
349 | private static ConfigurationSection getCsFromType(Material material) {
350 | if (LevelToolsUtil.isSword(material)) {
351 | return LevelToolsPlugin.getInstance().getConfig().getConfigurationSection("sword_rewards");
352 | } else if (LevelToolsUtil.isProjectileShooter(material)) {
353 | return LevelToolsPlugin.getInstance().getConfig().getConfigurationSection("bow_rewards");
354 | } else {
355 | return LevelToolsPlugin.getInstance().getConfig().getConfigurationSection("tool_rewards");
356 | }
357 | }
358 |
359 | public static void sendActionBar(Player player, String msg) {
360 | if (RedLib.MID_VERSION > 12) {
361 | player.spigot().sendMessage(ChatMessageType.ACTION_BAR, TextComponent.fromLegacyText(msg));
362 | } else {
363 | ActionBar.sendActionBar(player, msg);
364 | }
365 | }
366 |
367 | public static Scheduler createScheduler(LevelToolsPlugin plugin) {
368 | if (isFolia()) {
369 | return new FoliaScheduler(plugin);
370 | }
371 |
372 | return new BukkitScheduler(plugin);
373 | }
374 |
375 | private static boolean isFolia() {
376 | try {
377 | Class.forName("io.papermc.paper.threadedregions.RegionizedServer");
378 | return true;
379 | } catch (ClassNotFoundException e) {
380 | return false;
381 | }
382 | }
383 | }
384 |
--------------------------------------------------------------------------------
/src/main/java/me/byteful/plugin/leveltools/util/Text.java:
--------------------------------------------------------------------------------
1 | package me.byteful.plugin.leveltools.util;
2 |
3 | import java.util.*;
4 | import org.bukkit.ChatColor;
5 | import org.jetbrains.annotations.NotNull;
6 | import redempt.redlib.misc.FormatUtils;
7 |
8 | public final class Text {
9 | @NotNull
10 | public static String decolorize(@NotNull String string) {
11 | return colorize(string).replace("" + ChatColor.COLOR_CHAR, "&");
12 | }
13 |
14 | @NotNull
15 | public static String colorize(String input) {
16 | return FormatUtils.color(input);
17 | }
18 |
19 | // From Apache lang library
20 | public static String[] substringsBetween(String str, String open, String close) {
21 | int strLen = str.length();
22 | int closeLen = close.length();
23 | int openLen = open.length();
24 | List list = new ArrayList();
25 |
26 | int end;
27 | for (int pos = 0; pos < strLen - closeLen; pos = end + closeLen) {
28 | int start = str.indexOf(open, pos);
29 | if (start < 0) {
30 | break;
31 | }
32 |
33 | start += openLen;
34 | end = str.indexOf(close, start);
35 | if (end < 0) {
36 | break;
37 | }
38 |
39 | list.add(str.substring(start, end));
40 | }
41 |
42 | return list.isEmpty() ? null : list.toArray(new String[0]);
43 | }
44 | }
45 |
--------------------------------------------------------------------------------
/src/main/java/me/byteful/plugin/leveltools/util/UpdateChecker.java:
--------------------------------------------------------------------------------
1 | package me.byteful.plugin.leveltools.util;
2 |
3 | import java.io.IOException;
4 | import java.io.InputStream;
5 | import java.net.URL;
6 | import java.util.Scanner;
7 | import me.byteful.plugin.leveltools.LevelToolsPlugin;
8 | import me.byteful.plugin.leveltools.api.scheduler.Scheduler;
9 | import org.jetbrains.annotations.NotNull;
10 |
11 | public class UpdateChecker {
12 | @NotNull private final LevelToolsPlugin plugin;
13 | private final Scheduler scheduler;
14 | private String lastCheckedVersion = null;
15 |
16 | public UpdateChecker(@NotNull LevelToolsPlugin plugin, Scheduler scheduler) {
17 | this.plugin = plugin;
18 | this.scheduler = scheduler;
19 | }
20 |
21 | public void check() {
22 | plugin.getLogger().info("Checking for updates...");
23 | final String currentVersion = plugin.getDescription().getVersion();
24 | if (currentVersion.contains("BETA")) {
25 | plugin.getLogger().info("Update check was cancelled because you are running a beta build!");
26 |
27 | return;
28 | }
29 |
30 | scheduler.asyncDelayed(() -> check0(currentVersion), 1L);
31 | }
32 |
33 | private void check0(String currentVersion) {
34 | try (final InputStream inputStream =
35 | new URL("https://api.byteful.me/leveltools").openStream();
36 | final Scanner scanner = new Scanner(inputStream)) {
37 | if (!scanner.hasNext()) {
38 | return;
39 | }
40 |
41 | final String latestVersion = scanner.next();
42 |
43 | if (currentVersion.equals(latestVersion)) {
44 | plugin.getLogger().info("No new updates found.");
45 | } else {
46 | plugin
47 | .getLogger()
48 | .info(
49 | "A new update was found. You are on "
50 | + currentVersion
51 | + " while the latest version is "
52 | + latestVersion
53 | + ".");
54 | plugin
55 | .getLogger()
56 | .info(
57 | "Please install this update from: https://github.com/byteful/LevelTools/releases/download/v"
58 | + latestVersion
59 | + "/LevelTools-"
60 | + latestVersion
61 | + ".jar");
62 | }
63 |
64 | lastCheckedVersion = latestVersion;
65 | } catch (IOException e) {
66 | plugin.getLogger().info("Unable to check for updates: " + e.getMessage());
67 | }
68 | }
69 |
70 | public String getLastCheckedVersion() {
71 | return lastCheckedVersion;
72 | }
73 | }
74 |
--------------------------------------------------------------------------------
/src/main/java/me/byteful/plugin/leveltools/util/XPBooster.java:
--------------------------------------------------------------------------------
1 | package me.byteful.plugin.leveltools.util;
2 |
3 | import me.byteful.plugin.leveltools.LevelToolsPlugin;
4 | import org.bukkit.entity.Player;
5 | import org.bukkit.permissions.PermissionAttachmentInfo;
6 |
7 | public final class XPBooster {
8 | public static double apply(Player player, double xp) {
9 | for (PermissionAttachmentInfo permission : player.getEffectivePermissions()) {
10 | if (!permission.getValue() || !permission.getPermission().startsWith("leveltools.booster."))
11 | continue;
12 |
13 | try {
14 | xp *= Double.parseDouble(permission.getPermission().substring(19));
15 | } catch (Exception e) {
16 | LevelToolsPlugin.getInstance()
17 | .getLogger()
18 | .warning(
19 | "Failed to parse LevelTools XPBooster permission: " + permission.getPermission());
20 | }
21 | }
22 |
23 | return xp;
24 | }
25 | }
26 |
--------------------------------------------------------------------------------
/src/main/resources/config.yml:
--------------------------------------------------------------------------------
1 | #
2 | # LevelTools v${version} by byteful#0001
3 | #
4 |
5 | # Useful Links:
6 | # - https://minecraft.fandom.com/wiki/Attribute
7 | # - https://hub.spigotmc.org/javadocs/spigot/org/bukkit/attribute/Attribute.html
8 | # - https://hub.spigotmc.org/javadocs/spigot/org/bukkit/Material.html
9 | # - https://hub.spigotmc.org/javadocs/spigot/org/bukkit/enchantments/Enchantment.html
10 | # - https://hub.spigotmc.org/javadocs/spigot/org/bukkit/Sound.html
11 | # - https://hub.spigotmc.org/javadocs/spigot/org/bukkit/entity/EntityType.html
12 |
13 | # Configuration for update checker.
14 | update:
15 | # Should LevelTools check for updates on start?
16 | start: true
17 | # Should LevelTools check for updates periodically?
18 | periodically: true
19 |
20 | # The max level that tools can reach.
21 | max_level: 100
22 |
23 | # Configuration for block data storage.
24 | block_data_storage:
25 | # Defines the method used for storing and retrieving placed block data.
26 | # Options:
27 | # LEGACY_TEXT: The original custom plain text file format.
28 | # SQLITE: Uses an embedded SQLite database. Recommended for performance,
29 | # scalability with large datasets, and data integrity.
30 | type: SQLITE
31 |
32 | # Configuration for messages.
33 | messages:
34 | no_permission: "&cYou do not have permission to execute this command!"
35 | successful_reload: "&aSuccessfully reloaded LevelTools!"
36 | successfully_executed_action: "&aSuccessfully executed action for item in hand."
37 | item_not_tool: "&cThe item in hand is not supported by LevelTools!"
38 | successfully_reset_tools: "&aSuccessfully reset all tool XP/Levels for {player}."
39 | successfully_reset_hand_tool: "&aSuccessfully reset tool in hand's XP/Levels for {player}."
40 |
41 | # What action should be done when combining items in an anvil?
42 | # Modes: "HIGHER_OF_BOTH" (Takes level and xp of higher level item), "LOWER_OF_BOTH" (Takes level and xp of lower level item), OR "ADD_BOTH" (Adds the level and XP of both items)
43 | anvil_combine: "ADD_BOTH"
44 |
45 | # The mathematical formula to calculate the required XP for next level.
46 | # Placeholders/Variables provided: {current_level}
47 | level_xp_formula: "100 + {current_level} * 100"
48 |
49 | # Should blocks that are placed by a player count towards XP?
50 | playerPlacedBlocks: false
51 |
52 | # Configuration for the sound played during a level up.
53 | level_up_sound:
54 | sound: "ENTITY_PLAYER_LEVELUP" # Set to null to disable this.
55 | pitch: 1.0
56 | volume: 1.0
57 |
58 | # The default block XP modifier. Look at the configuration section below for a better explanation.
59 | default_block_xp_modifier:
60 | min: 0.5
61 | max: 1.5
62 |
63 | # The default combat XP modifier. Look at the configuration section below for a better explanation.
64 | default_combat_xp_modifier:
65 | min: 1.0
66 | max: 2.5
67 |
68 | # Configuration for specific block modifiers.
69 | # These modifiers change the amount of XP a block gives. Set the min and max to the same value to disable the random range system.
70 | block_xp_modifiers:
71 | DIAMOND_ORE:
72 | min: 5.0
73 | max: 10.0
74 |
75 | # Configuration for specific entity (combat) modifiers.
76 | # These modifiers change the amount of XP an entity gives. Set the min and max to the same value to disable the random range system.
77 | combat_xp_modifiers:
78 | BLAZE:
79 | min: 5.0
80 | max: 7.5
81 |
82 | # A list that prevents/allows the blocks listed from giving XP on break.
83 | block_list_type: "BLACKLIST" # Types: WHITELIST, BLACKLIST (blacklist by default)
84 | block_list:
85 | - "FIRE"
86 | - "SOUL_FIRE"
87 | - "CRIMSON_FUNGUS"
88 | - "BROWN_MUSHROOM"
89 | - "RED_MUSHROOM"
90 | - "CRIMSON_ROOTS"
91 | - "GRASS"
92 | - "TALL_GRASS"
93 | - "SEAGRASS"
94 | - "TORCH"
95 | - "FERN"
96 | - "LARGE_FERN"
97 | - "SUNFLOWER"
98 | - "CORNFLOWER"
99 |
100 | # A list that prevents/allows the entities listed from giving XP on kill.
101 | entity_list_type: "BLACKLIST" # Types: WHITELIST, BLACKLIST (blacklist by default)
102 | entity_list:
103 | - "PLAYER"
104 |
105 | # A list of worlds where LevelTools is disabled. Plugins using LevelTools' API will not be affected. Only LevelTools' core logic will be disabled in these worlds.
106 | disabled_worlds:
107 | - "disabled_world"
108 |
109 | # Configuration for tool rewards given at level ups.
110 | # Handlers:
111 | # - "command" : Runs the command provided as the console. (Ex: "command say test")
112 | # - "player-command" : Runs the command provided as the player. ("Ex: player-command say test")
113 | # - "player-opcommand" : Runs the command provided as the player with OP permissions. ("Ex: player-opcommand specialenchant enchantment")
114 | # - "enchant" : Adds an enchantment to the tool. Overrides existing enchantments with the new level provided. (Ex: "enchant efficiency 1")
115 | # - "enchant2" : Does the same thing as "enchant" but doesn't override existing enchantments. (Ex: "enchant2 efficiency 1")
116 | # - "enchant3" : Increases the existing level value of the enchant. (Ex: "enchant3 efficiency 1")
117 | # - "attribute" : Modifies an attribute on the tool. (Ex: "attribute generic.attack_speed 10") OR (Ex: "attribute GENERIC_ATTACK_SPEED 10")
118 | tool_rewards:
119 | 1:
120 | - "enchant2 efficiency 1"
121 | 3:
122 | - "enchant2 efficiency 2"
123 | 5:
124 | - "enchant2 efficiency 3"
125 | 8:
126 | - "enchant2 efficiency 4"
127 | 10:
128 | - "enchant2 efficiency 5"
129 | 11:
130 | - "enchant2 unbreaking 1"
131 | 13:
132 | - "enchant2 unbreaking 2"
133 | 15:
134 | - "enchant2 unbreaking 3"
135 | 20:
136 | - "enchant2 mending 1"
137 | 24:
138 | - "enchant2 fortune 1"
139 | 26:
140 | - "enchant2 fortune 2"
141 | 30:
142 | - "enchant2 fortune 3"
143 | 40:
144 | - "enchant2 efficiency 6"
145 | 50:
146 | - "enchant2 fortune 4"
147 | 65:
148 | - "enchant2 efficiency 7"
149 | - "enchant2 unbreaking 10"
150 | 80:
151 | - "enchant2 efficiency 8"
152 | 90:
153 | - "enchant2 efficiency 9"
154 | 100:
155 | - "enchant2 efficiency 10"
156 | - "enchant2 fortune 5"
157 |
158 | # Configuration for sword rewards given at level ups.
159 | # Handlers:
160 | # - "command" : Runs the command provided as the console. (Ex: "command say test")
161 | # - "player-command" : Runs the command provided as the player. ("Ex: player-command say test")
162 | # - "player-opcommand" : Runs the command provided as the player with OP permissions. ("Ex: player-opcommand specialenchant enchantment")
163 | # - "enchant" : Adds an enchantment to the tool. Overrides existing enchantments with the new level provided. (Ex: "enchant efficiency 1")
164 | # - "enchant2" : Does the same thing as "enchant" but doesn't override existing enchantments. (Ex: "enchant2 efficiency 1")
165 | # - "enchant3" : Increases the existing level value of the enchant. (Ex: "enchant3 efficiency 1")
166 | # - "attribute" : Modifies an attribute on the tool. (Ex: "attribute generic.attack_speed 10") OR (Ex: "attribute GENERIC_ATTACK_SPEED 10")
167 | sword_rewards:
168 | 1:
169 | - "enchant2 sharpness 1"
170 | 3:
171 | - "enchant2 sharpness 2"
172 | 5:
173 | - "enchant2 sharpness 3"
174 | 8:
175 | - "enchant2 sharpness 4"
176 | 10:
177 | - "enchant2 sharpness 5"
178 | 11:
179 | - "enchant2 unbreaking 1"
180 | 13:
181 | - "enchant2 unbreaking 2"
182 | 15:
183 | - "enchant2 unbreaking 3"
184 | 20:
185 | - "enchant2 mending 1"
186 | 24:
187 | - "enchant2 looting 1"
188 | 26:
189 | - "enchant2 looting 2"
190 | 30:
191 | - "enchant2 looting 3"
192 | 40:
193 | - "enchant2 sharpness 6"
194 | 50:
195 | - "enchant2 looting 4"
196 | 65:
197 | - "enchant2 sharpness 7"
198 | - "enchant2 unbreaking 10"
199 | 80:
200 | - "enchant2 sharpness 8"
201 | 90:
202 | - "enchant2 sharpness 9"
203 | 100:
204 | - "enchant2 sharpness 10"
205 | - "enchant2 looting 5"
206 |
207 | # Configuration for bow and crossbow rewards given at level ups.
208 | # Handlers:
209 | # - "command" : Runs the command provided as the console. (Ex: "command say test")
210 | # - "player-command" : Runs the command provided as the player. ("Ex: player-command say test")
211 | # - "player-opcommand" : Runs the command provided as the player with OP permissions. ("Ex: player-opcommand specialenchant enchantment")
212 | # - "enchant" : Adds an enchantment to the tool. Overrides existing enchantments with the new level provided. (Ex: "enchant efficiency 1")
213 | # - "enchant2" : Does the same thing as "enchant" but doesn't override existing enchantments. (Ex: "enchant2 efficiency 1")
214 | # - "enchant3" : Increases the existing level value of the enchant. (Ex: "enchant3 efficiency 1")
215 | # - "attribute" : Modifies an attribute on the tool. (Ex: "attribute generic.attack_speed 10") OR (Ex: "attribute GENERIC_ATTACK_SPEED 10")
216 | bow_rewards:
217 | 1:
218 | - "enchant2 power 1"
219 | 3:
220 | - "enchant2 power 2"
221 | 5:
222 | - "enchant2 power 3"
223 | 8:
224 | - "enchant2 power 4"
225 | 10:
226 | - "enchant2 power 5"
227 | 11:
228 | - "enchant2 unbreaking 1"
229 | 13:
230 | - "enchant2 unbreaking 2"
231 | 15:
232 | - "enchant2 unbreaking 3"
233 | 20:
234 | - "enchant2 mending 1"
235 | 24:
236 | - "enchant2 punch 1"
237 | 26:
238 | - "enchant2 punch 2"
239 | 30:
240 | - "enchant2 punch 3"
241 | 40:
242 | - "enchant2 power 6"
243 | 50:
244 | - "enchant2 flame 1"
245 | 65:
246 | - "enchant2 power 7"
247 | - "enchant2 unbreaking 10"
248 | 80:
249 | - "enchant2 power 8"
250 | 90:
251 | - "enchant2 power 9"
252 | 100:
253 | - "enchant2 power 10"
254 | - "enchant2 infinity 1"
255 |
256 | # Configuration for tool displays.
257 | # Placeholders:
258 | # - {level} : The tool's level.
259 | # - {xp} : The tool's xp.
260 | # - {max_xp} : The tool's max XP needed to reach the next level.
261 | # - {xp_formatted} : The tool's xp. (formatted with K,M,B, etc suffixes) (e.g 100K, 250B, 5K, 1M)
262 | # - {max_xp_formatted} : The tool's max XP needed to reach the next level. (formatted with K,M,B, etc suffixes) (e.g 100K, 250B, 5K, 1M)
263 | # - {progress_bar} : The progress bar text built with the configuration under 'progress_bar'.
264 | display:
265 | name:
266 | enabled: false
267 | text: "{item} &7- &b{level}"
268 | # Sends the progress bar to the action bar of a player when they gain XP on the tool in their hand.
269 | actionBar:
270 | enabled: true
271 | text: "{progress_bar} &e{xp_formatted}&6/&e{max_xp_formatted}"
272 | # Manage the lore displayed on the tool.
273 | lore:
274 | # Should LevelTools override the lore on tools?
275 | enabled: true
276 | # The lore lines that LevelTools overrides the tool with.
277 | lines:
278 | - ""
279 | - "&eLevel: &6{level}"
280 | - ""
281 | - "{progress_bar} &e{xp_formatted}&6/&e{max_xp_formatted}"
282 |
283 | # Set to true if leveled items should show attributes. Recommended to keep this true to prevent "lore spam".
284 | hide_attributes: true
285 |
286 | # Configuration for the progress bar.
287 | progress_bar:
288 | # The total amount of bars in the progress bar.
289 | total_bars: 50
290 |
291 | # The symbol used for the bar.
292 | bar_symbol: '|'
293 |
294 | # The symbol used to prefix the bar symbols.
295 | prefix_symbol: '['
296 |
297 | # The symbol used to suffix the bar symbols.
298 | suffix_symbol: ']'
299 |
300 | # The color for the prefix symbol.
301 | prefix_color: '8' # Do not include the '&'
302 |
303 | # The color for the suffix symbol.
304 | suffix_color: '8' # Do not include the '&'
305 |
306 | # The color for the achieved/completed bars.
307 | completed_color: 'e' # Do not include the '&'
308 |
309 | # The color for the remaining/placeholder bars.
310 | placeholder_color: '7' # Do not include the '&'
311 |
--------------------------------------------------------------------------------
/src/main/resources/plugin.yml:
--------------------------------------------------------------------------------
1 | name: "LevelTools"
2 | version: "${version}"
3 | main: "me.byteful.plugin.leveltools.LevelToolsPlugin"
4 | author: byteful
5 | description: "A plugin that adds a leveling system to tools, swords, and bows."
6 | website: "https://github.com/byteful/LevelTools"
7 | api-version: "1.13"
8 | folia-supported: true
9 | softdepend:
10 | - PlaceholderAPI
11 | permissions:
12 | leveltools.admin:
13 | description: "Permission to use admin commands."
14 | default: op
15 | leveltools.enabled:
16 | description: "Permission to let a player level up a tool."
17 | default: true
18 |
--------------------------------------------------------------------------------