Compare commits
252 Commits
1.6.3
...
c22c36f0a4
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
c22c36f0a4 | ||
|
|
e38ffdef07 | ||
|
|
c7540244bc | ||
|
|
613957fadf | ||
|
|
e48be6ba20 | ||
|
|
c0d79fd740 | ||
|
|
b056972d30 | ||
|
|
525df4bcf6 | ||
|
|
86cbdd58ff | ||
|
|
27a89fd67c | ||
|
|
70ed50ce9e | ||
|
|
84c1f8313a | ||
|
|
f7ec488396 | ||
|
|
df014fd888 | ||
|
|
1d617706a6 | ||
|
|
49e1acc66a | ||
|
|
eddaec1543 | ||
|
|
57ec36d5a7 | ||
|
|
a617875975 | ||
|
|
3ee53e0cf7 | ||
|
|
364859bc0a | ||
|
|
0efc07b12b | ||
|
|
e73ba5376c | ||
|
|
68318e3af2 | ||
|
|
c7cd25e866 | ||
|
|
67d141c452 | ||
|
|
c1300e916f | ||
|
|
6d6f1aab8a | ||
|
|
b2ef154cc6 | ||
|
|
bc8f4948fe | ||
|
|
70e19269ee | ||
|
|
5373792480 | ||
|
|
f71d079e23 | ||
|
|
bcb85c7a28 | ||
|
|
1e4e963fe1 | ||
|
|
298a8dd592 | ||
|
|
49a3c03f94 | ||
|
|
ecd241ac52 | ||
|
|
5a1be37339 | ||
|
|
a07782df5b | ||
|
|
31123fdfd5 | ||
|
|
e310f1cb18 | ||
|
|
3d850ef00c | ||
|
|
dfd2ef7d7b | ||
|
|
957d4d95cb | ||
|
|
2143daa133 | ||
|
|
be8fcc2d57 | ||
|
|
ed9afc1812 | ||
|
|
706175a13a | ||
|
|
256581fa08 | ||
|
|
818f2e7a39 | ||
|
|
d83bc55eec | ||
|
|
3196223d30 | ||
|
|
02d5d1c17e | ||
|
|
d675549209 | ||
|
|
d5324b5db6 | ||
|
|
4fe4c2be25 | ||
|
|
a4393780a2 | ||
|
|
8115c5511a | ||
|
|
f13f17be58 | ||
|
|
90a8ec1fab | ||
|
|
d0199a85e0 | ||
|
|
e37048ff01 | ||
|
|
71f3a3ea10 | ||
|
|
3f850aaef7 | ||
|
|
427628da6e | ||
|
|
820c1dce51 | ||
|
|
ad1a4fe26e | ||
|
|
ceb1dbd297 | ||
|
|
49f4727100 | ||
|
|
cb5345bd14 | ||
|
|
eeb6038b66 | ||
|
|
5e3e9f0825 | ||
|
|
11ee83773e | ||
|
|
9f5da738dd | ||
|
|
434f0dfe30 | ||
|
|
06a3bb2498 | ||
|
|
5624c02ee2 | ||
|
|
3e1c2dcbc3 | ||
|
|
8a1759b6b1 | ||
|
|
b4be9eb741 | ||
|
|
7a18649474 | ||
|
|
32f1e78630 | ||
|
|
f78609b9ed | ||
|
|
9ee1f773da | ||
|
|
61f87a94f7 | ||
|
|
fd7f75fbb3 | ||
|
|
24ee5f9d42 | ||
|
|
2b7c1350c3 | ||
|
|
393f9b74c0 | ||
|
|
c597b4ffeb | ||
|
|
a3f3e0552d | ||
|
|
636374134c | ||
|
|
93f4363c9a | ||
|
|
a48a1492d2 | ||
|
|
8e2e389f78 | ||
|
|
3da98afd49 | ||
|
|
e3629bf813 | ||
|
|
f7697bccfa | ||
|
|
73e472af3a | ||
|
|
4dda215805 | ||
|
|
eada8cc448 | ||
|
|
5bb179bfa9 | ||
|
|
d515d66da8 | ||
|
|
b025fd0b46 | ||
|
|
390aeac226 | ||
|
|
985fb5380d | ||
|
|
dd584fd2b8 | ||
|
|
b8ac32f9b4 | ||
|
|
b14427ced2 | ||
|
|
d0d2d1ad41 | ||
|
|
7051cfd8cf | ||
|
|
73254b3c88 | ||
|
|
d5a4c4e3ef | ||
|
|
30b26533ef | ||
|
|
ff578e170e | ||
|
|
87aa26c7e9 | ||
|
|
2b5f784b93 | ||
|
|
94ff8f251d | ||
|
|
f9fa15dbaf | ||
|
|
1a15fb94f4 | ||
|
|
44b70a8394 | ||
|
|
98ee84ad13 | ||
|
|
c68a04851b | ||
|
|
06e063a072 | ||
|
|
c00c534d49 | ||
|
|
d6f8176ce1 | ||
|
|
eb06dff0bc | ||
|
|
9a72c509ef | ||
|
|
eaca8ac87d | ||
|
|
44a2c5cd26 | ||
|
|
0957a1c989 | ||
|
|
7b12a130a0 | ||
|
|
6b263be041 | ||
|
|
aeaeee680b | ||
|
|
d8c7425a5a | ||
|
|
86c92c9706 | ||
|
|
cd62f7309e | ||
|
|
e2b18cb5f1 | ||
|
|
150956b2c9 | ||
|
|
585e020baf | ||
|
|
50b5823daf | ||
|
|
c87d0ca3bf | ||
|
|
d1a16ff2e6 | ||
|
|
9134da31f4 | ||
|
|
0cf85edda6 | ||
|
|
7fe0234785 | ||
|
|
6385814b52 | ||
|
|
603e1ac1fd | ||
|
|
86dc5f421a | ||
|
|
7d9be0cfd1 | ||
|
|
f7bacec617 | ||
|
|
227723fe10 | ||
|
|
785333e8d1 | ||
|
|
bc784b8d46 | ||
|
|
f5ddada892 | ||
|
|
a43155b0c5 | ||
|
|
e327d132e2 | ||
|
|
f09f2d3703 | ||
|
|
e9782c2985 | ||
|
|
b596310bfe | ||
|
|
6d1f0fe561 | ||
|
|
fb0d179d37 | ||
|
|
e8ab578eef | ||
|
|
57be2371e1 | ||
|
|
f3732a4eea | ||
|
|
7e13159056 | ||
|
|
7cdb8d55b5 | ||
|
|
368e59b1e1 | ||
|
|
9412dc02d7 | ||
|
|
0765c49622 | ||
|
|
91959c223e | ||
|
|
a53cebc589 | ||
|
|
7f7c1d4656 | ||
|
|
1e99fa5076 | ||
|
|
d50ee82a98 | ||
|
|
2a2c9a7376 | ||
|
|
813648e330 | ||
|
|
330001e6de | ||
|
|
75b1a95cb5 | ||
|
|
ca37021e5a | ||
|
|
f72ea3dbfa | ||
|
|
03077d5e2f | ||
|
|
608c870667 | ||
|
|
ea27e4f4ab | ||
|
|
8a7c6c720a | ||
|
|
12e2758ffd | ||
|
|
5939b8f944 | ||
|
|
021d67e505 | ||
|
|
c0ee457c4d | ||
|
|
4f4e4a961a | ||
|
|
3412094f93 | ||
|
|
cdc46a1f5f | ||
|
|
d4c7770352 | ||
|
|
85db07877d | ||
|
|
1e37fcd3cb | ||
|
|
10f9b9404e | ||
|
|
c350536ab6 | ||
|
|
e12a0a80f5 | ||
|
|
44a3fc7d63 | ||
|
|
6a5bb994cc | ||
|
|
1c52664935 | ||
|
|
4d18020065 | ||
|
|
ee5ebff614 | ||
|
|
fa7b19e3fc | ||
|
|
cc4176cfbe | ||
|
|
bd30b05246 | ||
|
|
2ace1c4f16 | ||
|
|
c3f47707c4 | ||
|
|
ee1c197d72 | ||
|
|
74b529ba4f | ||
|
|
c328b9e019 | ||
|
|
38c37ea601 | ||
|
|
700e7bca2c | ||
|
|
59bfdf69ca | ||
|
|
68aed25834 | ||
|
|
0968497fc0 | ||
|
|
c7a5aef9ee | ||
|
|
e40e16c273 | ||
|
|
fc9ef05afd | ||
|
|
26ae28dcd8 | ||
|
|
02a7920ad2 | ||
|
|
68c9685477 | ||
|
|
9f81cb1f74 | ||
|
|
e068aeb9f4 | ||
|
|
b0733935ae | ||
|
|
664eddeab0 | ||
|
|
cda8d94199 | ||
|
|
5551c24202 | ||
|
|
951106177b | ||
|
|
0a3f46fc6e | ||
|
|
2894e2021a | ||
|
|
2e34cb812a | ||
|
|
a38c148b80 | ||
|
|
a55cea4b5d | ||
|
|
d0fcd4fc61 | ||
|
|
f14b9bc474 | ||
|
|
366a54052a | ||
|
|
fe96235ed1 | ||
|
|
fe8052f9d6 | ||
|
|
884bdef444 | ||
|
|
be31202f65 | ||
|
|
39d8a42110 | ||
|
|
91090dd6cc | ||
|
|
29a2a5150c | ||
|
|
b38d2825cb | ||
|
|
fd6c120a58 | ||
|
|
459569a1dc | ||
|
|
9ba6200415 | ||
|
|
b94e0e8c36 | ||
|
|
a42c526198 | ||
|
|
851a494935 |
1
.github/FUNDING.yml
vendored
Normal file
@@ -0,0 +1 @@
|
|||||||
|
buy_me_a_coffee: hyperdefined
|
||||||
31
.github/workflows/hangar.yml
vendored
Normal file
@@ -0,0 +1,31 @@
|
|||||||
|
name: Update Hangar Description
|
||||||
|
on:
|
||||||
|
push:
|
||||||
|
branches: [ master ]
|
||||||
|
jobs:
|
||||||
|
update-hangar-page:
|
||||||
|
runs-on: ubuntu-latest
|
||||||
|
|
||||||
|
steps:
|
||||||
|
- name: Checkout code
|
||||||
|
uses: actions/checkout@v3
|
||||||
|
|
||||||
|
- name: Authenticate with Hangar
|
||||||
|
id: authenticate
|
||||||
|
run: |
|
||||||
|
RESPONSE=$(curl -s -X POST "https://hangar.papermc.io/api/v1/authenticate?apiKey=${{ secrets.HANGAR }}" -H 'accept: application/json')
|
||||||
|
TOKEN=$(echo $RESPONSE | jq -r '.token')
|
||||||
|
if [[ "$TOKEN" == "null" ]]; then
|
||||||
|
echo "Error: Unable to fetch JWT token"
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
|
echo "::add-mask::$TOKEN"
|
||||||
|
echo "token=$TOKEN" >> $GITHUB_OUTPUT
|
||||||
|
|
||||||
|
- name: Update Project Description
|
||||||
|
run: |
|
||||||
|
README_CONTENT=$(cat README.md | jq -Rs .)
|
||||||
|
curl -s -X PATCH "https://hangar.papermc.io/api/v1/pages/editmain/ToolStats" \
|
||||||
|
-H "content-type: application/json" \
|
||||||
|
-H "Authorization: HangarAuth ${{ steps.authenticate.outputs.token }}" \
|
||||||
|
-d "{\"content\":$README_CONTENT}"
|
||||||
9
.github/workflows/maven.yml
vendored
@@ -15,10 +15,11 @@ jobs:
|
|||||||
runs-on: ubuntu-latest
|
runs-on: ubuntu-latest
|
||||||
|
|
||||||
steps:
|
steps:
|
||||||
- uses: actions/checkout@v2
|
- uses: actions/checkout@v4
|
||||||
- name: Set up JDK 1.8
|
- name: Set up JDK 21
|
||||||
uses: actions/setup-java@v1
|
uses: actions/setup-java@v4
|
||||||
with:
|
with:
|
||||||
java-version: 1.8
|
distribution: temurin
|
||||||
|
java-version: 21
|
||||||
- name: Build with Maven
|
- name: Build with Maven
|
||||||
run: mvn -B package --file pom.xml
|
run: mvn -B package --file pom.xml
|
||||||
|
|||||||
13
.github/workflows/modrinth.yml
vendored
Normal file
@@ -0,0 +1,13 @@
|
|||||||
|
name: Update Modrinth Description
|
||||||
|
on:
|
||||||
|
push:
|
||||||
|
branches: [ master ]
|
||||||
|
jobs:
|
||||||
|
modrinth-desc:
|
||||||
|
runs-on: 'ubuntu-latest'
|
||||||
|
steps:
|
||||||
|
- uses: actions/checkout@v3
|
||||||
|
- uses: funnyboy-roks/modrinth-auto-desc@v1.6
|
||||||
|
with:
|
||||||
|
auth-token: ${{ secrets.MODRINTH }}
|
||||||
|
slug: 'oBZj9E15'
|
||||||
674
LICENSE
Normal file
@@ -0,0 +1,674 @@
|
|||||||
|
GNU GENERAL PUBLIC LICENSE
|
||||||
|
Version 3, 29 June 2007
|
||||||
|
|
||||||
|
Copyright (C) 2007 Free Software Foundation, Inc. <https://fsf.org/>
|
||||||
|
Everyone is permitted to copy and distribute verbatim copies
|
||||||
|
of this license document, but changing it is not allowed.
|
||||||
|
|
||||||
|
Preamble
|
||||||
|
|
||||||
|
The GNU General Public License is a free, copyleft license for
|
||||||
|
software and other kinds of works.
|
||||||
|
|
||||||
|
The licenses for most software and other practical works are designed
|
||||||
|
to take away your freedom to share and change the works. By contrast,
|
||||||
|
the GNU General Public License is intended to guarantee your freedom to
|
||||||
|
share and change all versions of a program--to make sure it remains free
|
||||||
|
software for all its users. We, the Free Software Foundation, use the
|
||||||
|
GNU General Public License for most of our software; it applies also to
|
||||||
|
any other work released this way by its authors. You can apply it to
|
||||||
|
your programs, too.
|
||||||
|
|
||||||
|
When we speak of free software, we are referring to freedom, not
|
||||||
|
price. Our General Public Licenses are designed to make sure that you
|
||||||
|
have the freedom to distribute copies of free software (and charge for
|
||||||
|
them if you wish), that you receive source code or can get it if you
|
||||||
|
want it, that you can change the software or use pieces of it in new
|
||||||
|
free programs, and that you know you can do these things.
|
||||||
|
|
||||||
|
To protect your rights, we need to prevent others from denying you
|
||||||
|
these rights or asking you to surrender the rights. Therefore, you have
|
||||||
|
certain responsibilities if you distribute copies of the software, or if
|
||||||
|
you modify it: responsibilities to respect the freedom of others.
|
||||||
|
|
||||||
|
For example, if you distribute copies of such a program, whether
|
||||||
|
gratis or for a fee, you must pass on to the recipients the same
|
||||||
|
freedoms that you received. You must make sure that they, too, receive
|
||||||
|
or can get the source code. And you must show them these terms so they
|
||||||
|
know their rights.
|
||||||
|
|
||||||
|
Developers that use the GNU GPL protect your rights with two steps:
|
||||||
|
(1) assert copyright on the software, and (2) offer you this License
|
||||||
|
giving you legal permission to copy, distribute and/or modify it.
|
||||||
|
|
||||||
|
For the developers' and authors' protection, the GPL clearly explains
|
||||||
|
that there is no warranty for this free software. For both users' and
|
||||||
|
authors' sake, the GPL requires that modified versions be marked as
|
||||||
|
changed, so that their problems will not be attributed erroneously to
|
||||||
|
authors of previous versions.
|
||||||
|
|
||||||
|
Some devices are designed to deny users access to install or run
|
||||||
|
modified versions of the software inside them, although the manufacturer
|
||||||
|
can do so. This is fundamentally incompatible with the aim of
|
||||||
|
protecting users' freedom to change the software. The systematic
|
||||||
|
pattern of such abuse occurs in the area of products for individuals to
|
||||||
|
use, which is precisely where it is most unacceptable. Therefore, we
|
||||||
|
have designed this version of the GPL to prohibit the practice for those
|
||||||
|
products. If such problems arise substantially in other domains, we
|
||||||
|
stand ready to extend this provision to those domains in future versions
|
||||||
|
of the GPL, as needed to protect the freedom of users.
|
||||||
|
|
||||||
|
Finally, every program is threatened constantly by software patents.
|
||||||
|
States should not allow patents to restrict development and use of
|
||||||
|
software on general-purpose computers, but in those that do, we wish to
|
||||||
|
avoid the special danger that patents applied to a free program could
|
||||||
|
make it effectively proprietary. To prevent this, the GPL assures that
|
||||||
|
patents cannot be used to render the program non-free.
|
||||||
|
|
||||||
|
The precise terms and conditions for copying, distribution and
|
||||||
|
modification follow.
|
||||||
|
|
||||||
|
TERMS AND CONDITIONS
|
||||||
|
|
||||||
|
0. Definitions.
|
||||||
|
|
||||||
|
"This License" refers to version 3 of the GNU General Public License.
|
||||||
|
|
||||||
|
"Copyright" also means copyright-like laws that apply to other kinds of
|
||||||
|
works, such as semiconductor masks.
|
||||||
|
|
||||||
|
"The Program" refers to any copyrightable work licensed under this
|
||||||
|
License. Each licensee is addressed as "you". "Licensees" and
|
||||||
|
"recipients" may be individuals or organizations.
|
||||||
|
|
||||||
|
To "modify" a work means to copy from or adapt all or part of the work
|
||||||
|
in a fashion requiring copyright permission, other than the making of an
|
||||||
|
exact copy. The resulting work is called a "modified version" of the
|
||||||
|
earlier work or a work "based on" the earlier work.
|
||||||
|
|
||||||
|
A "covered work" means either the unmodified Program or a work based
|
||||||
|
on the Program.
|
||||||
|
|
||||||
|
To "propagate" a work means to do anything with it that, without
|
||||||
|
permission, would make you directly or secondarily liable for
|
||||||
|
infringement under applicable copyright law, except executing it on a
|
||||||
|
computer or modifying a private copy. Propagation includes copying,
|
||||||
|
distribution (with or without modification), making available to the
|
||||||
|
public, and in some countries other activities as well.
|
||||||
|
|
||||||
|
To "convey" a work means any kind of propagation that enables other
|
||||||
|
parties to make or receive copies. Mere interaction with a user through
|
||||||
|
a computer network, with no transfer of a copy, is not conveying.
|
||||||
|
|
||||||
|
An interactive user interface displays "Appropriate Legal Notices"
|
||||||
|
to the extent that it includes a convenient and prominently visible
|
||||||
|
feature that (1) displays an appropriate copyright notice, and (2)
|
||||||
|
tells the user that there is no warranty for the work (except to the
|
||||||
|
extent that warranties are provided), that licensees may convey the
|
||||||
|
work under this License, and how to view a copy of this License. If
|
||||||
|
the interface presents a list of user commands or options, such as a
|
||||||
|
menu, a prominent item in the list meets this criterion.
|
||||||
|
|
||||||
|
1. Source Code.
|
||||||
|
|
||||||
|
The "source code" for a work means the preferred form of the work
|
||||||
|
for making modifications to it. "Object code" means any non-source
|
||||||
|
form of a work.
|
||||||
|
|
||||||
|
A "Standard Interface" means an interface that either is an official
|
||||||
|
standard defined by a recognized standards body, or, in the case of
|
||||||
|
interfaces specified for a particular programming language, one that
|
||||||
|
is widely used among developers working in that language.
|
||||||
|
|
||||||
|
The "System Libraries" of an executable work include anything, other
|
||||||
|
than the work as a whole, that (a) is included in the normal form of
|
||||||
|
packaging a Major Component, but which is not part of that Major
|
||||||
|
Component, and (b) serves only to enable use of the work with that
|
||||||
|
Major Component, or to implement a Standard Interface for which an
|
||||||
|
implementation is available to the public in source code form. A
|
||||||
|
"Major Component", in this context, means a major essential component
|
||||||
|
(kernel, window system, and so on) of the specific operating system
|
||||||
|
(if any) on which the executable work runs, or a compiler used to
|
||||||
|
produce the work, or an object code interpreter used to run it.
|
||||||
|
|
||||||
|
The "Corresponding Source" for a work in object code form means all
|
||||||
|
the source code needed to generate, install, and (for an executable
|
||||||
|
work) run the object code and to modify the work, including scripts to
|
||||||
|
control those activities. However, it does not include the work's
|
||||||
|
System Libraries, or general-purpose tools or generally available free
|
||||||
|
programs which are used unmodified in performing those activities but
|
||||||
|
which are not part of the work. For example, Corresponding Source
|
||||||
|
includes interface definition files associated with source files for
|
||||||
|
the work, and the source code for shared libraries and dynamically
|
||||||
|
linked subprograms that the work is specifically designed to require,
|
||||||
|
such as by intimate data communication or control flow between those
|
||||||
|
subprograms and other parts of the work.
|
||||||
|
|
||||||
|
The Corresponding Source need not include anything that users
|
||||||
|
can regenerate automatically from other parts of the Corresponding
|
||||||
|
Source.
|
||||||
|
|
||||||
|
The Corresponding Source for a work in source code form is that
|
||||||
|
same work.
|
||||||
|
|
||||||
|
2. Basic Permissions.
|
||||||
|
|
||||||
|
All rights granted under this License are granted for the term of
|
||||||
|
copyright on the Program, and are irrevocable provided the stated
|
||||||
|
conditions are met. This License explicitly affirms your unlimited
|
||||||
|
permission to run the unmodified Program. The output from running a
|
||||||
|
covered work is covered by this License only if the output, given its
|
||||||
|
content, constitutes a covered work. This License acknowledges your
|
||||||
|
rights of fair use or other equivalent, as provided by copyright law.
|
||||||
|
|
||||||
|
You may make, run and propagate covered works that you do not
|
||||||
|
convey, without conditions so long as your license otherwise remains
|
||||||
|
in force. You may convey covered works to others for the sole purpose
|
||||||
|
of having them make modifications exclusively for you, or provide you
|
||||||
|
with facilities for running those works, provided that you comply with
|
||||||
|
the terms of this License in conveying all material for which you do
|
||||||
|
not control copyright. Those thus making or running the covered works
|
||||||
|
for you must do so exclusively on your behalf, under your direction
|
||||||
|
and control, on terms that prohibit them from making any copies of
|
||||||
|
your copyrighted material outside their relationship with you.
|
||||||
|
|
||||||
|
Conveying under any other circumstances is permitted solely under
|
||||||
|
the conditions stated below. Sublicensing is not allowed; section 10
|
||||||
|
makes it unnecessary.
|
||||||
|
|
||||||
|
3. Protecting Users' Legal Rights From Anti-Circumvention Law.
|
||||||
|
|
||||||
|
No covered work shall be deemed part of an effective technological
|
||||||
|
measure under any applicable law fulfilling obligations under article
|
||||||
|
11 of the WIPO copyright treaty adopted on 20 December 1996, or
|
||||||
|
similar laws prohibiting or restricting circumvention of such
|
||||||
|
measures.
|
||||||
|
|
||||||
|
When you convey a covered work, you waive any legal power to forbid
|
||||||
|
circumvention of technological measures to the extent such circumvention
|
||||||
|
is effected by exercising rights under this License with respect to
|
||||||
|
the covered work, and you disclaim any intention to limit operation or
|
||||||
|
modification of the work as a means of enforcing, against the work's
|
||||||
|
users, your or third parties' legal rights to forbid circumvention of
|
||||||
|
technological measures.
|
||||||
|
|
||||||
|
4. Conveying Verbatim Copies.
|
||||||
|
|
||||||
|
You may convey verbatim copies of the Program's source code as you
|
||||||
|
receive it, in any medium, provided that you conspicuously and
|
||||||
|
appropriately publish on each copy an appropriate copyright notice;
|
||||||
|
keep intact all notices stating that this License and any
|
||||||
|
non-permissive terms added in accord with section 7 apply to the code;
|
||||||
|
keep intact all notices of the absence of any warranty; and give all
|
||||||
|
recipients a copy of this License along with the Program.
|
||||||
|
|
||||||
|
You may charge any price or no price for each copy that you convey,
|
||||||
|
and you may offer support or warranty protection for a fee.
|
||||||
|
|
||||||
|
5. Conveying Modified Source Versions.
|
||||||
|
|
||||||
|
You may convey a work based on the Program, or the modifications to
|
||||||
|
produce it from the Program, in the form of source code under the
|
||||||
|
terms of section 4, provided that you also meet all of these conditions:
|
||||||
|
|
||||||
|
a) The work must carry prominent notices stating that you modified
|
||||||
|
it, and giving a relevant date.
|
||||||
|
|
||||||
|
b) The work must carry prominent notices stating that it is
|
||||||
|
released under this License and any conditions added under section
|
||||||
|
7. This requirement modifies the requirement in section 4 to
|
||||||
|
"keep intact all notices".
|
||||||
|
|
||||||
|
c) You must license the entire work, as a whole, under this
|
||||||
|
License to anyone who comes into possession of a copy. This
|
||||||
|
License will therefore apply, along with any applicable section 7
|
||||||
|
additional terms, to the whole of the work, and all its parts,
|
||||||
|
regardless of how they are packaged. This License gives no
|
||||||
|
permission to license the work in any other way, but it does not
|
||||||
|
invalidate such permission if you have separately received it.
|
||||||
|
|
||||||
|
d) If the work has interactive user interfaces, each must display
|
||||||
|
Appropriate Legal Notices; however, if the Program has interactive
|
||||||
|
interfaces that do not display Appropriate Legal Notices, your
|
||||||
|
work need not make them do so.
|
||||||
|
|
||||||
|
A compilation of a covered work with other separate and independent
|
||||||
|
works, which are not by their nature extensions of the covered work,
|
||||||
|
and which are not combined with it such as to form a larger program,
|
||||||
|
in or on a volume of a storage or distribution medium, is called an
|
||||||
|
"aggregate" if the compilation and its resulting copyright are not
|
||||||
|
used to limit the access or legal rights of the compilation's users
|
||||||
|
beyond what the individual works permit. Inclusion of a covered work
|
||||||
|
in an aggregate does not cause this License to apply to the other
|
||||||
|
parts of the aggregate.
|
||||||
|
|
||||||
|
6. Conveying Non-Source Forms.
|
||||||
|
|
||||||
|
You may convey a covered work in object code form under the terms
|
||||||
|
of sections 4 and 5, provided that you also convey the
|
||||||
|
machine-readable Corresponding Source under the terms of this License,
|
||||||
|
in one of these ways:
|
||||||
|
|
||||||
|
a) Convey the object code in, or embodied in, a physical product
|
||||||
|
(including a physical distribution medium), accompanied by the
|
||||||
|
Corresponding Source fixed on a durable physical medium
|
||||||
|
customarily used for software interchange.
|
||||||
|
|
||||||
|
b) Convey the object code in, or embodied in, a physical product
|
||||||
|
(including a physical distribution medium), accompanied by a
|
||||||
|
written offer, valid for at least three years and valid for as
|
||||||
|
long as you offer spare parts or customer support for that product
|
||||||
|
model, to give anyone who possesses the object code either (1) a
|
||||||
|
copy of the Corresponding Source for all the software in the
|
||||||
|
product that is covered by this License, on a durable physical
|
||||||
|
medium customarily used for software interchange, for a price no
|
||||||
|
more than your reasonable cost of physically performing this
|
||||||
|
conveying of source, or (2) access to copy the
|
||||||
|
Corresponding Source from a network server at no charge.
|
||||||
|
|
||||||
|
c) Convey individual copies of the object code with a copy of the
|
||||||
|
written offer to provide the Corresponding Source. This
|
||||||
|
alternative is allowed only occasionally and noncommercially, and
|
||||||
|
only if you received the object code with such an offer, in accord
|
||||||
|
with subsection 6b.
|
||||||
|
|
||||||
|
d) Convey the object code by offering access from a designated
|
||||||
|
place (gratis or for a charge), and offer equivalent access to the
|
||||||
|
Corresponding Source in the same way through the same place at no
|
||||||
|
further charge. You need not require recipients to copy the
|
||||||
|
Corresponding Source along with the object code. If the place to
|
||||||
|
copy the object code is a network server, the Corresponding Source
|
||||||
|
may be on a different server (operated by you or a third party)
|
||||||
|
that supports equivalent copying facilities, provided you maintain
|
||||||
|
clear directions next to the object code saying where to find the
|
||||||
|
Corresponding Source. Regardless of what server hosts the
|
||||||
|
Corresponding Source, you remain obligated to ensure that it is
|
||||||
|
available for as long as needed to satisfy these requirements.
|
||||||
|
|
||||||
|
e) Convey the object code using peer-to-peer transmission, provided
|
||||||
|
you inform other peers where the object code and Corresponding
|
||||||
|
Source of the work are being offered to the general public at no
|
||||||
|
charge under subsection 6d.
|
||||||
|
|
||||||
|
A separable portion of the object code, whose source code is excluded
|
||||||
|
from the Corresponding Source as a System Library, need not be
|
||||||
|
included in conveying the object code work.
|
||||||
|
|
||||||
|
A "User Product" is either (1) a "consumer product", which means any
|
||||||
|
tangible personal property which is normally used for personal, family,
|
||||||
|
or household purposes, or (2) anything designed or sold for incorporation
|
||||||
|
into a dwelling. In determining whether a product is a consumer product,
|
||||||
|
doubtful cases shall be resolved in favor of coverage. For a particular
|
||||||
|
product received by a particular user, "normally used" refers to a
|
||||||
|
typical or common use of that class of product, regardless of the status
|
||||||
|
of the particular user or of the way in which the particular user
|
||||||
|
actually uses, or expects or is expected to use, the product. A product
|
||||||
|
is a consumer product regardless of whether the product has substantial
|
||||||
|
commercial, industrial or non-consumer uses, unless such uses represent
|
||||||
|
the only significant mode of use of the product.
|
||||||
|
|
||||||
|
"Installation Information" for a User Product means any methods,
|
||||||
|
procedures, authorization keys, or other information required to install
|
||||||
|
and execute modified versions of a covered work in that User Product from
|
||||||
|
a modified version of its Corresponding Source. The information must
|
||||||
|
suffice to ensure that the continued functioning of the modified object
|
||||||
|
code is in no case prevented or interfered with solely because
|
||||||
|
modification has been made.
|
||||||
|
|
||||||
|
If you convey an object code work under this section in, or with, or
|
||||||
|
specifically for use in, a User Product, and the conveying occurs as
|
||||||
|
part of a transaction in which the right of possession and use of the
|
||||||
|
User Product is transferred to the recipient in perpetuity or for a
|
||||||
|
fixed term (regardless of how the transaction is characterized), the
|
||||||
|
Corresponding Source conveyed under this section must be accompanied
|
||||||
|
by the Installation Information. But this requirement does not apply
|
||||||
|
if neither you nor any third party retains the ability to install
|
||||||
|
modified object code on the User Product (for example, the work has
|
||||||
|
been installed in ROM).
|
||||||
|
|
||||||
|
The requirement to provide Installation Information does not include a
|
||||||
|
requirement to continue to provide support service, warranty, or updates
|
||||||
|
for a work that has been modified or installed by the recipient, or for
|
||||||
|
the User Product in which it has been modified or installed. Access to a
|
||||||
|
network may be denied when the modification itself materially and
|
||||||
|
adversely affects the operation of the network or violates the rules and
|
||||||
|
protocols for communication across the network.
|
||||||
|
|
||||||
|
Corresponding Source conveyed, and Installation Information provided,
|
||||||
|
in accord with this section must be in a format that is publicly
|
||||||
|
documented (and with an implementation available to the public in
|
||||||
|
source code form), and must require no special password or key for
|
||||||
|
unpacking, reading or copying.
|
||||||
|
|
||||||
|
7. Additional Terms.
|
||||||
|
|
||||||
|
"Additional permissions" are terms that supplement the terms of this
|
||||||
|
License by making exceptions from one or more of its conditions.
|
||||||
|
Additional permissions that are applicable to the entire Program shall
|
||||||
|
be treated as though they were included in this License, to the extent
|
||||||
|
that they are valid under applicable law. If additional permissions
|
||||||
|
apply only to part of the Program, that part may be used separately
|
||||||
|
under those permissions, but the entire Program remains governed by
|
||||||
|
this License without regard to the additional permissions.
|
||||||
|
|
||||||
|
When you convey a copy of a covered work, you may at your option
|
||||||
|
remove any additional permissions from that copy, or from any part of
|
||||||
|
it. (Additional permissions may be written to require their own
|
||||||
|
removal in certain cases when you modify the work.) You may place
|
||||||
|
additional permissions on material, added by you to a covered work,
|
||||||
|
for which you have or can give appropriate copyright permission.
|
||||||
|
|
||||||
|
Notwithstanding any other provision of this License, for material you
|
||||||
|
add to a covered work, you may (if authorized by the copyright holders of
|
||||||
|
that material) supplement the terms of this License with terms:
|
||||||
|
|
||||||
|
a) Disclaiming warranty or limiting liability differently from the
|
||||||
|
terms of sections 15 and 16 of this License; or
|
||||||
|
|
||||||
|
b) Requiring preservation of specified reasonable legal notices or
|
||||||
|
author attributions in that material or in the Appropriate Legal
|
||||||
|
Notices displayed by works containing it; or
|
||||||
|
|
||||||
|
c) Prohibiting misrepresentation of the origin of that material, or
|
||||||
|
requiring that modified versions of such material be marked in
|
||||||
|
reasonable ways as different from the original version; or
|
||||||
|
|
||||||
|
d) Limiting the use for publicity purposes of names of licensors or
|
||||||
|
authors of the material; or
|
||||||
|
|
||||||
|
e) Declining to grant rights under trademark law for use of some
|
||||||
|
trade names, trademarks, or service marks; or
|
||||||
|
|
||||||
|
f) Requiring indemnification of licensors and authors of that
|
||||||
|
material by anyone who conveys the material (or modified versions of
|
||||||
|
it) with contractual assumptions of liability to the recipient, for
|
||||||
|
any liability that these contractual assumptions directly impose on
|
||||||
|
those licensors and authors.
|
||||||
|
|
||||||
|
All other non-permissive additional terms are considered "further
|
||||||
|
restrictions" within the meaning of section 10. If the Program as you
|
||||||
|
received it, or any part of it, contains a notice stating that it is
|
||||||
|
governed by this License along with a term that is a further
|
||||||
|
restriction, you may remove that term. If a license document contains
|
||||||
|
a further restriction but permits relicensing or conveying under this
|
||||||
|
License, you may add to a covered work material governed by the terms
|
||||||
|
of that license document, provided that the further restriction does
|
||||||
|
not survive such relicensing or conveying.
|
||||||
|
|
||||||
|
If you add terms to a covered work in accord with this section, you
|
||||||
|
must place, in the relevant source files, a statement of the
|
||||||
|
additional terms that apply to those files, or a notice indicating
|
||||||
|
where to find the applicable terms.
|
||||||
|
|
||||||
|
Additional terms, permissive or non-permissive, may be stated in the
|
||||||
|
form of a separately written license, or stated as exceptions;
|
||||||
|
the above requirements apply either way.
|
||||||
|
|
||||||
|
8. Termination.
|
||||||
|
|
||||||
|
You may not propagate or modify a covered work except as expressly
|
||||||
|
provided under this License. Any attempt otherwise to propagate or
|
||||||
|
modify it is void, and will automatically terminate your rights under
|
||||||
|
this License (including any patent licenses granted under the third
|
||||||
|
paragraph of section 11).
|
||||||
|
|
||||||
|
However, if you cease all violation of this License, then your
|
||||||
|
license from a particular copyright holder is reinstated (a)
|
||||||
|
provisionally, unless and until the copyright holder explicitly and
|
||||||
|
finally terminates your license, and (b) permanently, if the copyright
|
||||||
|
holder fails to notify you of the violation by some reasonable means
|
||||||
|
prior to 60 days after the cessation.
|
||||||
|
|
||||||
|
Moreover, your license from a particular copyright holder is
|
||||||
|
reinstated permanently if the copyright holder notifies you of the
|
||||||
|
violation by some reasonable means, this is the first time you have
|
||||||
|
received notice of violation of this License (for any work) from that
|
||||||
|
copyright holder, and you cure the violation prior to 30 days after
|
||||||
|
your receipt of the notice.
|
||||||
|
|
||||||
|
Termination of your rights under this section does not terminate the
|
||||||
|
licenses of parties who have received copies or rights from you under
|
||||||
|
this License. If your rights have been terminated and not permanently
|
||||||
|
reinstated, you do not qualify to receive new licenses for the same
|
||||||
|
material under section 10.
|
||||||
|
|
||||||
|
9. Acceptance Not Required for Having Copies.
|
||||||
|
|
||||||
|
You are not required to accept this License in order to receive or
|
||||||
|
run a copy of the Program. Ancillary propagation of a covered work
|
||||||
|
occurring solely as a consequence of using peer-to-peer transmission
|
||||||
|
to receive a copy likewise does not require acceptance. However,
|
||||||
|
nothing other than this License grants you permission to propagate or
|
||||||
|
modify any covered work. These actions infringe copyright if you do
|
||||||
|
not accept this License. Therefore, by modifying or propagating a
|
||||||
|
covered work, you indicate your acceptance of this License to do so.
|
||||||
|
|
||||||
|
10. Automatic Licensing of Downstream Recipients.
|
||||||
|
|
||||||
|
Each time you convey a covered work, the recipient automatically
|
||||||
|
receives a license from the original licensors, to run, modify and
|
||||||
|
propagate that work, subject to this License. You are not responsible
|
||||||
|
for enforcing compliance by third parties with this License.
|
||||||
|
|
||||||
|
An "entity transaction" is a transaction transferring control of an
|
||||||
|
organization, or substantially all assets of one, or subdividing an
|
||||||
|
organization, or merging organizations. If propagation of a covered
|
||||||
|
work results from an entity transaction, each party to that
|
||||||
|
transaction who receives a copy of the work also receives whatever
|
||||||
|
licenses to the work the party's predecessor in interest had or could
|
||||||
|
give under the previous paragraph, plus a right to possession of the
|
||||||
|
Corresponding Source of the work from the predecessor in interest, if
|
||||||
|
the predecessor has it or can get it with reasonable efforts.
|
||||||
|
|
||||||
|
You may not impose any further restrictions on the exercise of the
|
||||||
|
rights granted or affirmed under this License. For example, you may
|
||||||
|
not impose a license fee, royalty, or other charge for exercise of
|
||||||
|
rights granted under this License, and you may not initiate litigation
|
||||||
|
(including a cross-claim or counterclaim in a lawsuit) alleging that
|
||||||
|
any patent claim is infringed by making, using, selling, offering for
|
||||||
|
sale, or importing the Program or any portion of it.
|
||||||
|
|
||||||
|
11. Patents.
|
||||||
|
|
||||||
|
A "contributor" is a copyright holder who authorizes use under this
|
||||||
|
License of the Program or a work on which the Program is based. The
|
||||||
|
work thus licensed is called the contributor's "contributor version".
|
||||||
|
|
||||||
|
A contributor's "essential patent claims" are all patent claims
|
||||||
|
owned or controlled by the contributor, whether already acquired or
|
||||||
|
hereafter acquired, that would be infringed by some manner, permitted
|
||||||
|
by this License, of making, using, or selling its contributor version,
|
||||||
|
but do not include claims that would be infringed only as a
|
||||||
|
consequence of further modification of the contributor version. For
|
||||||
|
purposes of this definition, "control" includes the right to grant
|
||||||
|
patent sublicenses in a manner consistent with the requirements of
|
||||||
|
this License.
|
||||||
|
|
||||||
|
Each contributor grants you a non-exclusive, worldwide, royalty-free
|
||||||
|
patent license under the contributor's essential patent claims, to
|
||||||
|
make, use, sell, offer for sale, import and otherwise run, modify and
|
||||||
|
propagate the contents of its contributor version.
|
||||||
|
|
||||||
|
In the following three paragraphs, a "patent license" is any express
|
||||||
|
agreement or commitment, however denominated, not to enforce a patent
|
||||||
|
(such as an express permission to practice a patent or covenant not to
|
||||||
|
sue for patent infringement). To "grant" such a patent license to a
|
||||||
|
party means to make such an agreement or commitment not to enforce a
|
||||||
|
patent against the party.
|
||||||
|
|
||||||
|
If you convey a covered work, knowingly relying on a patent license,
|
||||||
|
and the Corresponding Source of the work is not available for anyone
|
||||||
|
to copy, free of charge and under the terms of this License, through a
|
||||||
|
publicly available network server or other readily accessible means,
|
||||||
|
then you must either (1) cause the Corresponding Source to be so
|
||||||
|
available, or (2) arrange to deprive yourself of the benefit of the
|
||||||
|
patent license for this particular work, or (3) arrange, in a manner
|
||||||
|
consistent with the requirements of this License, to extend the patent
|
||||||
|
license to downstream recipients. "Knowingly relying" means you have
|
||||||
|
actual knowledge that, but for the patent license, your conveying the
|
||||||
|
covered work in a country, or your recipient's use of the covered work
|
||||||
|
in a country, would infringe one or more identifiable patents in that
|
||||||
|
country that you have reason to believe are valid.
|
||||||
|
|
||||||
|
If, pursuant to or in connection with a single transaction or
|
||||||
|
arrangement, you convey, or propagate by procuring conveyance of, a
|
||||||
|
covered work, and grant a patent license to some of the parties
|
||||||
|
receiving the covered work authorizing them to use, propagate, modify
|
||||||
|
or convey a specific copy of the covered work, then the patent license
|
||||||
|
you grant is automatically extended to all recipients of the covered
|
||||||
|
work and works based on it.
|
||||||
|
|
||||||
|
A patent license is "discriminatory" if it does not include within
|
||||||
|
the scope of its coverage, prohibits the exercise of, or is
|
||||||
|
conditioned on the non-exercise of one or more of the rights that are
|
||||||
|
specifically granted under this License. You may not convey a covered
|
||||||
|
work if you are a party to an arrangement with a third party that is
|
||||||
|
in the business of distributing software, under which you make payment
|
||||||
|
to the third party based on the extent of your activity of conveying
|
||||||
|
the work, and under which the third party grants, to any of the
|
||||||
|
parties who would receive the covered work from you, a discriminatory
|
||||||
|
patent license (a) in connection with copies of the covered work
|
||||||
|
conveyed by you (or copies made from those copies), or (b) primarily
|
||||||
|
for and in connection with specific products or compilations that
|
||||||
|
contain the covered work, unless you entered into that arrangement,
|
||||||
|
or that patent license was granted, prior to 28 March 2007.
|
||||||
|
|
||||||
|
Nothing in this License shall be construed as excluding or limiting
|
||||||
|
any implied license or other defenses to infringement that may
|
||||||
|
otherwise be available to you under applicable patent law.
|
||||||
|
|
||||||
|
12. No Surrender of Others' Freedom.
|
||||||
|
|
||||||
|
If conditions are imposed on you (whether by court order, agreement or
|
||||||
|
otherwise) that contradict the conditions of this License, they do not
|
||||||
|
excuse you from the conditions of this License. If you cannot convey a
|
||||||
|
covered work so as to satisfy simultaneously your obligations under this
|
||||||
|
License and any other pertinent obligations, then as a consequence you may
|
||||||
|
not convey it at all. For example, if you agree to terms that obligate you
|
||||||
|
to collect a royalty for further conveying from those to whom you convey
|
||||||
|
the Program, the only way you could satisfy both those terms and this
|
||||||
|
License would be to refrain entirely from conveying the Program.
|
||||||
|
|
||||||
|
13. Use with the GNU Affero General Public License.
|
||||||
|
|
||||||
|
Notwithstanding any other provision of this License, you have
|
||||||
|
permission to link or combine any covered work with a work licensed
|
||||||
|
under version 3 of the GNU Affero General Public License into a single
|
||||||
|
combined work, and to convey the resulting work. The terms of this
|
||||||
|
License will continue to apply to the part which is the covered work,
|
||||||
|
but the special requirements of the GNU Affero General Public License,
|
||||||
|
section 13, concerning interaction through a network will apply to the
|
||||||
|
combination as such.
|
||||||
|
|
||||||
|
14. Revised Versions of this License.
|
||||||
|
|
||||||
|
The Free Software Foundation may publish revised and/or new versions of
|
||||||
|
the GNU General Public License from time to time. Such new versions will
|
||||||
|
be similar in spirit to the present version, but may differ in detail to
|
||||||
|
address new problems or concerns.
|
||||||
|
|
||||||
|
Each version is given a distinguishing version number. If the
|
||||||
|
Program specifies that a certain numbered version of the GNU General
|
||||||
|
Public License "or any later version" applies to it, you have the
|
||||||
|
option of following the terms and conditions either of that numbered
|
||||||
|
version or of any later version published by the Free Software
|
||||||
|
Foundation. If the Program does not specify a version number of the
|
||||||
|
GNU General Public License, you may choose any version ever published
|
||||||
|
by the Free Software Foundation.
|
||||||
|
|
||||||
|
If the Program specifies that a proxy can decide which future
|
||||||
|
versions of the GNU General Public License can be used, that proxy's
|
||||||
|
public statement of acceptance of a version permanently authorizes you
|
||||||
|
to choose that version for the Program.
|
||||||
|
|
||||||
|
Later license versions may give you additional or different
|
||||||
|
permissions. However, no additional obligations are imposed on any
|
||||||
|
author or copyright holder as a result of your choosing to follow a
|
||||||
|
later version.
|
||||||
|
|
||||||
|
15. Disclaimer of Warranty.
|
||||||
|
|
||||||
|
THERE IS NO WARRANTY FOR THE PROGRAM, TO THE EXTENT PERMITTED BY
|
||||||
|
APPLICABLE LAW. EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT
|
||||||
|
HOLDERS AND/OR OTHER PARTIES PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY
|
||||||
|
OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO,
|
||||||
|
THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
|
||||||
|
PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE PROGRAM
|
||||||
|
IS WITH YOU. SHOULD THE PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF
|
||||||
|
ALL NECESSARY SERVICING, REPAIR OR CORRECTION.
|
||||||
|
|
||||||
|
16. Limitation of Liability.
|
||||||
|
|
||||||
|
IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING
|
||||||
|
WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MODIFIES AND/OR CONVEYS
|
||||||
|
THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, INCLUDING ANY
|
||||||
|
GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE
|
||||||
|
USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED TO LOSS OF
|
||||||
|
DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD
|
||||||
|
PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER PROGRAMS),
|
||||||
|
EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF
|
||||||
|
SUCH DAMAGES.
|
||||||
|
|
||||||
|
17. Interpretation of Sections 15 and 16.
|
||||||
|
|
||||||
|
If the disclaimer of warranty and limitation of liability provided
|
||||||
|
above cannot be given local legal effect according to their terms,
|
||||||
|
reviewing courts shall apply local law that most closely approximates
|
||||||
|
an absolute waiver of all civil liability in connection with the
|
||||||
|
Program, unless a warranty or assumption of liability accompanies a
|
||||||
|
copy of the Program in return for a fee.
|
||||||
|
|
||||||
|
END OF TERMS AND CONDITIONS
|
||||||
|
|
||||||
|
How to Apply These Terms to Your New Programs
|
||||||
|
|
||||||
|
If you develop a new program, and you want it to be of the greatest
|
||||||
|
possible use to the public, the best way to achieve this is to make it
|
||||||
|
free software which everyone can redistribute and change under these terms.
|
||||||
|
|
||||||
|
To do so, attach the following notices to the program. It is safest
|
||||||
|
to attach them to the start of each source file to most effectively
|
||||||
|
state the exclusion of warranty; and each file should have at least
|
||||||
|
the "copyright" line and a pointer to where the full notice is found.
|
||||||
|
|
||||||
|
<one line to give the program's name and a brief idea of what it does.>
|
||||||
|
Copyright (C) <year> <name of author>
|
||||||
|
|
||||||
|
This program is free software: you can redistribute it and/or modify
|
||||||
|
it under the terms of the GNU General Public License as published by
|
||||||
|
the Free Software Foundation, either version 3 of the License, or
|
||||||
|
(at your option) any later version.
|
||||||
|
|
||||||
|
This program is distributed in the hope that it will be useful,
|
||||||
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
GNU General Public License for more details.
|
||||||
|
|
||||||
|
You should have received a copy of the GNU General Public License
|
||||||
|
along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||||
|
|
||||||
|
Also add information on how to contact you by electronic and paper mail.
|
||||||
|
|
||||||
|
If the program does terminal interaction, make it output a short
|
||||||
|
notice like this when it starts in an interactive mode:
|
||||||
|
|
||||||
|
<program> Copyright (C) <year> <name of author>
|
||||||
|
This program comes with ABSOLUTELY NO WARRANTY; for details type `show w'.
|
||||||
|
This is free software, and you are welcome to redistribute it
|
||||||
|
under certain conditions; type `show c' for details.
|
||||||
|
|
||||||
|
The hypothetical commands `show w' and `show c' should show the appropriate
|
||||||
|
parts of the General Public License. Of course, your program's commands
|
||||||
|
might be different; for a GUI interface, you would use an "about box".
|
||||||
|
|
||||||
|
You should also get your employer (if you work as a programmer) or school,
|
||||||
|
if any, to sign a "copyright disclaimer" for the program, if necessary.
|
||||||
|
For more information on this, and how to apply and follow the GNU GPL, see
|
||||||
|
<https://www.gnu.org/licenses/>.
|
||||||
|
|
||||||
|
The GNU General Public License does not permit incorporating your program
|
||||||
|
into proprietary programs. If your program is a subroutine library, you
|
||||||
|
may consider it more useful to permit linking proprietary applications with
|
||||||
|
the library. If this is what you want to do, use the GNU Lesser General
|
||||||
|
Public License instead of this License. But first, please read
|
||||||
|
<https://www.gnu.org/licenses/why-not-lgpl.html>.
|
||||||
55
README.md
@@ -1,41 +1,50 @@
|
|||||||
<h1 align="center">ToolStats</h1>
|
<h1 align="center">ToolStats</h1>
|
||||||
|
|
||||||
<p align="center">
|
<p align="center">
|
||||||
<img src="https://img.shields.io/badge/Minecraft-1.15--1.19.2-orange" alt="Minecraft versions">
|
<a href="https://modrinth.com/plugin/ToolStats"><img alt="modrinth" height="40" src="https://cdn.jsdelivr.net/npm/@intergrav/devins-badges@3/assets/compact/available/modrinth_vector.svg"></a>
|
||||||
<img src="https://img.shields.io/github/v/release/hyperdefined/ToolStats" alt="GitHub release (latest by date)">
|
<a href="https://hangar.papermc.io/hyperdefined/ToolStats"><img alt="hangar" height="40" src="https://cdn.jsdelivr.net/npm/@intergrav/devins-badges@3/assets/compact/available/hangar_vector.svg"></a>
|
||||||
<a href="https://github.com/hyperdefined/ToolStats/releases"><img src="https://img.shields.io/github/downloads/hyperdefined/ToolStats/total?logo=github" alt="Downloads"></a>
|
<a href="https://papermc.io"><img alt="paper" height="40" src="https://cdn.jsdelivr.net/npm/@intergrav/devins-badges@3/assets/compact/supported/paper_vector.svg"></a>
|
||||||
<a href="https://ko-fi.com/hyperdefined"><img src="https://img.shields.io/badge/Donate-Ko--fi-red" alt="Donate via Ko-fi"></a>
|
<a href="https://docs.hyper.lol/plugins/toolstats/about/"><img alt="ghpages" height="40" src="https://cdn.jsdelivr.net/npm/@intergrav/devins-badges@3/assets/compact/documentation/ghpages_vector.svg"></a>
|
||||||
<a href="https://www.gnu.org/licenses/gpl-3.0"><img src="https://img.shields.io/badge/License-GPLv3-blue.svg" alt="License: GPL v3"></a>
|
<a href="https://discord.gg/rJuQXVcJz8"><img alt="discord-singular" height="40" src="https://cdn.jsdelivr.net/npm/@intergrav/devins-badges@3/assets/compact/social/discord-singular_vector.svg"></a>
|
||||||
<a href="https://wakatime.com/badge/user/992a7647-176a-477c-8086-e1abfba87ff4/project/0200f07a-f303-4103-a5f2-34b38c9c1fa4"><img src="https://wakatime.com/badge/user/992a7647-176a-477c-8086-e1abfba87ff4/project/0200f07a-f303-4103-a5f2-34b38c9c1fa4.svg" alt="wakatime"></a>
|
<a href="https://buymeacoffee.com/hyperdefined"><img alt="buymeacoffee-singular" height="40" src="https://cdn.jsdelivr.net/npm/@intergrav/devins-badges@3/assets/compact/donate/buymeacoffee-singular_vector.svg"></a>
|
||||||
|
<a href="https://patreon.com/hyperdefined"><img alt="patreon-singular" height="40" src="https://cdn.jsdelivr.net/npm/@intergrav/devins-badges@3/assets/compact/donate/patreon-singular_vector.svg"></a>
|
||||||
</p>
|
</p>
|
||||||
|
|
||||||
ToolStats is a small plugin that display various stats about tools. This plugin is inspired off of [GearStats](https://www.spigotmc.org/resources/gearstats.12960/). You can disable/enable which stats are shown on which tools via the config. Note: stats are tracked regardless of config setting. The config is to disable the lore on the item.
|
ToolStats is a Paper plugin that display various stats about tools. This plugin is inspired off of [GearStats](https://www.spigotmc.org/resources/gearstats.12960/). You can either track all statistics by default, or a use a token system to add statistics to tool/armor. You can configure how each statistic is shown on the item, or disable it!
|
||||||
|
|
||||||
Here is everything it tracks:
|
Here is everything it tracks:
|
||||||
* Blocks mined (pickaxes, shovels, axes, hoes, shears)
|
* Blocks mined (pickaxes, shovels, axes, hoes, shears).
|
||||||
* Player/mob kills (swords, axes, tridents, bows/crossbows)
|
* Crops mined (hoes).
|
||||||
* Ownership of items when crafted, looted (from chests), traded, and caught from fishing.
|
* Player/mob kills (swords, axes, tridents, bows/crossbows, mace).
|
||||||
|
* Ownership of items when crafted, looted (from chests), traded, spawned via creative, and caught from fishing.
|
||||||
* Armor damage taken.
|
* Armor damage taken.
|
||||||
|
* Damage done with weapons.
|
||||||
* Fish caught.
|
* Fish caught.
|
||||||
* Sheep sheared.
|
* Sheep sheared.
|
||||||
|
* Arrows shot (bows/crossbows).
|
||||||
|
* Flight time with elytras.
|
||||||
|
|
||||||
The best part is, this data is stored on the item itself. You can also change how the lore is displayed on the items!
|
The best part is, this data is stored on the item itself.
|
||||||
|
|
||||||
If item lore is ever incorrect, you can run `/toolstats reset` to reset the item lore so it's correct.
|
If item lore is ever incorrect/missing, you can run `/toolstats reset`. This command fixes the lore on whatever item you are holding.
|
||||||
|
|
||||||

|

|
||||||

|

|
||||||

|

|
||||||

|

|
||||||

|

|
||||||

|

|
||||||

|

|
||||||

|

|
||||||

|

|
||||||

|

|
||||||
|

|
||||||
|

|
||||||
|

|
||||||
|

|
||||||
|
|
||||||
## Documentation
|
## Documentation
|
||||||
Visit the [wiki](https://github.com/hyperdefined/ToolStats/wiki) for help.
|
Visit the [wiki](https://docs.hyper.lol/plugins/toolstats/about/) for help.
|
||||||
|
|
||||||
## License
|
## License
|
||||||
This plugin is released under GNU General Public License v3. See [LICENSE](https://github.com/hyperdefined/ToolStats/blob/master/LICENSE).
|
This plugin is released under GNU General Public License v3. See [LICENSE](https://github.com/hyperdefined/ToolStats/blob/master/LICENSE).
|
||||||
BIN
images/image.png
|
Before Width: | Height: | Size: 28 KiB |
|
Before Width: | Height: | Size: 8.8 KiB |
|
Before Width: | Height: | Size: 18 KiB |
|
Before Width: | Height: | Size: 14 KiB |
|
Before Width: | Height: | Size: 16 KiB |
|
Before Width: | Height: | Size: 25 KiB |
|
Before Width: | Height: | Size: 18 KiB |
|
Before Width: | Height: | Size: 12 KiB |
|
Before Width: | Height: | Size: 47 KiB |
|
Before Width: | Height: | Size: 15 KiB |
60
pom.xml
@@ -23,13 +23,13 @@
|
|||||||
|
|
||||||
<groupId>lol.hyper</groupId>
|
<groupId>lol.hyper</groupId>
|
||||||
<artifactId>toolstats</artifactId>
|
<artifactId>toolstats</artifactId>
|
||||||
<version>1.6.3</version>
|
<version>1.9.9</version>
|
||||||
<packaging>jar</packaging>
|
<packaging>jar</packaging>
|
||||||
|
|
||||||
<name>ToolStats</name>
|
<name>ToolStats</name>
|
||||||
|
|
||||||
<properties>
|
<properties>
|
||||||
<java.version>1.8</java.version>
|
<java.version>21</java.version>
|
||||||
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
|
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
|
||||||
</properties>
|
</properties>
|
||||||
|
|
||||||
@@ -37,7 +37,7 @@
|
|||||||
<plugins>
|
<plugins>
|
||||||
<plugin>
|
<plugin>
|
||||||
<artifactId>maven-clean-plugin</artifactId>
|
<artifactId>maven-clean-plugin</artifactId>
|
||||||
<version>3.2.0</version>
|
<version>3.5.0</version>
|
||||||
<executions>
|
<executions>
|
||||||
<execution>
|
<execution>
|
||||||
<id>auto-clean</id>
|
<id>auto-clean</id>
|
||||||
@@ -51,7 +51,7 @@
|
|||||||
<plugin>
|
<plugin>
|
||||||
<groupId>org.apache.maven.plugins</groupId>
|
<groupId>org.apache.maven.plugins</groupId>
|
||||||
<artifactId>maven-compiler-plugin</artifactId>
|
<artifactId>maven-compiler-plugin</artifactId>
|
||||||
<version>3.11.0</version>
|
<version>3.14.0</version>
|
||||||
<configuration>
|
<configuration>
|
||||||
<source>${java.version}</source>
|
<source>${java.version}</source>
|
||||||
<target>${java.version}</target>
|
<target>${java.version}</target>
|
||||||
@@ -60,20 +60,12 @@
|
|||||||
<plugin>
|
<plugin>
|
||||||
<groupId>org.apache.maven.plugins</groupId>
|
<groupId>org.apache.maven.plugins</groupId>
|
||||||
<artifactId>maven-shade-plugin</artifactId>
|
<artifactId>maven-shade-plugin</artifactId>
|
||||||
<version>3.4.1</version>
|
<version>3.6.0</version>
|
||||||
<configuration>
|
<configuration>
|
||||||
<relocations>
|
<relocations>
|
||||||
<relocation>
|
<relocation>
|
||||||
<pattern>org.bstats</pattern>
|
<pattern>lol.hyper.hyperlib</pattern>
|
||||||
<shadedPattern>lol.hyper.toolstats.bstats</shadedPattern>
|
<shadedPattern>lol.hyper.toolstats.hyperlib</shadedPattern>
|
||||||
</relocation>
|
|
||||||
<relocation>
|
|
||||||
<pattern>net.kyori.adventure</pattern>
|
|
||||||
<shadedPattern>lol.hyper.toolstats.adventure</shadedPattern>
|
|
||||||
</relocation>
|
|
||||||
<relocation>
|
|
||||||
<pattern>lol.hyper.githubreleaseapi</pattern>
|
|
||||||
<shadedPattern>lol.hyper.toolstats.updater</shadedPattern>
|
|
||||||
</relocation>
|
</relocation>
|
||||||
</relocations>
|
</relocations>
|
||||||
</configuration>
|
</configuration>
|
||||||
@@ -100,40 +92,26 @@
|
|||||||
|
|
||||||
<repositories>
|
<repositories>
|
||||||
<repository>
|
<repository>
|
||||||
<id>spigotmc-repo</id>
|
<id>papermc</id>
|
||||||
<url>https://hub.spigotmc.org/nexus/content/repositories/snapshots/</url>
|
<url>https://repo.papermc.io/repository/maven-public/</url>
|
||||||
|
</repository>
|
||||||
|
<repository>
|
||||||
|
<id>jitpack.io</id>
|
||||||
|
<url>https://jitpack.io</url>
|
||||||
</repository>
|
</repository>
|
||||||
</repositories>
|
</repositories>
|
||||||
|
|
||||||
<dependencies>
|
<dependencies>
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>org.spigotmc</groupId>
|
<groupId>io.papermc.paper</groupId>
|
||||||
<artifactId>spigot-api</artifactId>
|
<artifactId>paper-api</artifactId>
|
||||||
<version>1.19-R0.1-SNAPSHOT</version>
|
<version>1.21.8-R0.1-SNAPSHOT</version>
|
||||||
<scope>provided</scope>
|
<scope>provided</scope>
|
||||||
</dependency>
|
</dependency>
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>org.bstats</groupId>
|
<groupId>com.github.hyperdefined</groupId>
|
||||||
<artifactId>bstats-bukkit</artifactId>
|
<artifactId>hyperlib</artifactId>
|
||||||
<version>3.0.2</version>
|
<version>1.0.9</version>
|
||||||
<scope>compile</scope>
|
|
||||||
</dependency>
|
|
||||||
<dependency>
|
|
||||||
<groupId>lol.hyper</groupId>
|
|
||||||
<artifactId>github-release-api</artifactId>
|
|
||||||
<version>1.0.4</version>
|
|
||||||
<scope>compile</scope>
|
|
||||||
</dependency>
|
|
||||||
<dependency>
|
|
||||||
<groupId>net.kyori</groupId>
|
|
||||||
<artifactId>adventure-text-minimessage</artifactId>
|
|
||||||
<version>4.13.1</version>
|
|
||||||
<scope>compile</scope>
|
|
||||||
</dependency>
|
|
||||||
<dependency>
|
|
||||||
<groupId>net.kyori</groupId>
|
|
||||||
<artifactId>adventure-platform-bukkit</artifactId>
|
|
||||||
<version>4.3.0</version>
|
|
||||||
<scope>compile</scope>
|
<scope>compile</scope>
|
||||||
</dependency>
|
</dependency>
|
||||||
</dependencies>
|
</dependencies>
|
||||||
|
|||||||
@@ -17,50 +17,115 @@
|
|||||||
|
|
||||||
package lol.hyper.toolstats;
|
package lol.hyper.toolstats;
|
||||||
|
|
||||||
import lol.hyper.githubreleaseapi.GitHubRelease;
|
import lol.hyper.hyperlib.HyperLib;
|
||||||
import lol.hyper.githubreleaseapi.GitHubReleaseAPI;
|
import lol.hyper.hyperlib.bstats.HyperStats;
|
||||||
|
import lol.hyper.hyperlib.releases.HyperUpdater;
|
||||||
|
import lol.hyper.hyperlib.utils.TextUtils;
|
||||||
import lol.hyper.toolstats.commands.CommandToolStats;
|
import lol.hyper.toolstats.commands.CommandToolStats;
|
||||||
import lol.hyper.toolstats.events.*;
|
import lol.hyper.toolstats.events.*;
|
||||||
import lol.hyper.toolstats.tools.ItemLore;
|
import lol.hyper.toolstats.tools.*;
|
||||||
import lol.hyper.toolstats.tools.NumberFormat;
|
import lol.hyper.toolstats.tools.config.ConfigTools;
|
||||||
import net.kyori.adventure.platform.bukkit.BukkitAudiences;
|
import lol.hyper.toolstats.tools.config.ConfigUpdater;
|
||||||
import org.bstats.bukkit.Metrics;
|
import net.kyori.adventure.text.logger.slf4j.ComponentLogger;
|
||||||
import org.bukkit.Bukkit;
|
import org.bukkit.Bukkit;
|
||||||
import org.bukkit.ChatColor;
|
|
||||||
import org.bukkit.NamespacedKey;
|
import org.bukkit.NamespacedKey;
|
||||||
import org.bukkit.configuration.file.FileConfiguration;
|
|
||||||
import org.bukkit.configuration.file.YamlConfiguration;
|
import org.bukkit.configuration.file.YamlConfiguration;
|
||||||
import org.bukkit.inventory.ItemStack;
|
import org.bukkit.inventory.ShapedRecipe;
|
||||||
import org.bukkit.plugin.java.JavaPlugin;
|
import org.bukkit.plugin.java.JavaPlugin;
|
||||||
|
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
import java.io.IOException;
|
import java.util.HashSet;
|
||||||
import java.util.logging.Logger;
|
import java.util.Set;
|
||||||
|
|
||||||
public final class ToolStats extends JavaPlugin {
|
public final class ToolStats extends JavaPlugin {
|
||||||
|
|
||||||
// stores who created an item
|
/**
|
||||||
public final NamespacedKey genericOwner = new NamespacedKey(this, "owner");
|
* Stores who created an item.
|
||||||
// stores when an item was created
|
*/
|
||||||
|
public final NamespacedKey itemOwner = new NamespacedKey(this, "owner");
|
||||||
|
/**
|
||||||
|
* Stores when the item was created.
|
||||||
|
*/
|
||||||
public final NamespacedKey timeCreated = new NamespacedKey(this, "time-created");
|
public final NamespacedKey timeCreated = new NamespacedKey(this, "time-created");
|
||||||
// stores how many player kills by sword
|
/**
|
||||||
public final NamespacedKey swordPlayerKills = new NamespacedKey(this, "player-kills");
|
* Stores how many player kills.
|
||||||
// stores how many mob kills by sword
|
*/
|
||||||
public final NamespacedKey swordMobKills = new NamespacedKey(this, "mob-kills");
|
public final NamespacedKey playerKills = new NamespacedKey(this, "player-kills");
|
||||||
// stores how blocks mined (used for all tools)
|
/**
|
||||||
public final NamespacedKey genericMined = new NamespacedKey(this, "generic-mined");
|
* Stores how many mob kills.
|
||||||
// stores how many fish were caught
|
*/
|
||||||
public final NamespacedKey fishingRodCaught = new NamespacedKey(this, "fish-caught");
|
public final NamespacedKey mobKills = new NamespacedKey(this, "mob-kills");
|
||||||
// stores how many times sheep were sheared
|
/**
|
||||||
public final NamespacedKey shearsSheared = new NamespacedKey(this, "sheared");
|
* Stores how many blocks were mined.
|
||||||
// stores how much damage armor has taken
|
*/
|
||||||
|
public final NamespacedKey blocksMined = new NamespacedKey(this, "generic-mined");
|
||||||
|
/**
|
||||||
|
* Stores how many crops were harvested.
|
||||||
|
*/
|
||||||
|
public final NamespacedKey cropsHarvested = new NamespacedKey(this, "crops-mined");
|
||||||
|
/**
|
||||||
|
* Stores how many fish were caught.
|
||||||
|
*/
|
||||||
|
public final NamespacedKey fishCaught = new NamespacedKey(this, "fish-caught");
|
||||||
|
/**
|
||||||
|
* Stores how many sheep were sheared.
|
||||||
|
*/
|
||||||
|
public final NamespacedKey sheepSheared = new NamespacedKey(this, "sheared");
|
||||||
|
/**
|
||||||
|
* Stores how much damage an armor piece has taken.
|
||||||
|
*/
|
||||||
public final NamespacedKey armorDamage = new NamespacedKey(this, "damage-taken");
|
public final NamespacedKey armorDamage = new NamespacedKey(this, "damage-taken");
|
||||||
// stores how much damage armor has taken (as int)
|
/**
|
||||||
public final NamespacedKey armorDamageInt = new NamespacedKey(this, "damage-taken-int");
|
* Stores how much damage a weapon has done.
|
||||||
// used for tracking new elytras
|
*/
|
||||||
|
public final NamespacedKey damageDone = new NamespacedKey(this, "damage-done");
|
||||||
|
/**
|
||||||
|
* Key for tracking new elytras that spawn.
|
||||||
|
*/
|
||||||
public final NamespacedKey newElytra = new NamespacedKey(this, "new");
|
public final NamespacedKey newElytra = new NamespacedKey(this, "new");
|
||||||
|
/**
|
||||||
|
* Key for item has.
|
||||||
|
*/
|
||||||
|
public final NamespacedKey hash = new NamespacedKey(this, "hash");
|
||||||
|
/**
|
||||||
|
* Key for arrows shot.
|
||||||
|
*/
|
||||||
|
public final NamespacedKey arrowsShot = new NamespacedKey(this, "arrows-shot");
|
||||||
|
/**
|
||||||
|
* Key for arrows shot.
|
||||||
|
*/
|
||||||
|
public final NamespacedKey droppedBy = new NamespacedKey(this, "dropped-by");
|
||||||
|
/**
|
||||||
|
* Key for tracking flight time.
|
||||||
|
*/
|
||||||
|
public final NamespacedKey flightTime = new NamespacedKey(this, "flightTime");
|
||||||
|
/**
|
||||||
|
* Key for token type. This is for the token itself.
|
||||||
|
*/
|
||||||
|
public final NamespacedKey tokenType = new NamespacedKey(this, "token-type");
|
||||||
|
/**
|
||||||
|
* Key for applied token. This is what goes onto the tool/armor to record the type.
|
||||||
|
*/
|
||||||
|
public final NamespacedKey tokenApplied = new NamespacedKey(this, "token-applied");
|
||||||
|
/**
|
||||||
|
* Stores how an item was created.
|
||||||
|
* 0 = crafted.
|
||||||
|
* 1 = dropped.
|
||||||
|
* 2 = looted.
|
||||||
|
* 3 = traded.
|
||||||
|
* 4 = founded (for elytras).
|
||||||
|
* 5 = fished.
|
||||||
|
* 6 = spawned in (creative).
|
||||||
|
*/
|
||||||
|
public final NamespacedKey originType = new NamespacedKey(this, "origin");
|
||||||
|
|
||||||
public BlocksMined blocksMined;
|
public final int CONFIG_VERSION = 13;
|
||||||
|
public final ComponentLogger logger = this.getComponentLogger();
|
||||||
|
public final File configFile = new File(this.getDataFolder(), "config.yml");
|
||||||
|
public boolean tokens = false;
|
||||||
|
public final Set<NamespacedKey> tokenKeys = new HashSet<>();
|
||||||
|
|
||||||
|
public BlockBreak blockBreak;
|
||||||
public ChunkPopulate chunkPopulate;
|
public ChunkPopulate chunkPopulate;
|
||||||
public CraftItem craftItem;
|
public CraftItem craftItem;
|
||||||
public EntityDeath entityDeath;
|
public EntityDeath entityDeath;
|
||||||
@@ -73,25 +138,48 @@ public final class ToolStats extends JavaPlugin {
|
|||||||
public VillagerTrade villagerTrade;
|
public VillagerTrade villagerTrade;
|
||||||
public CommandToolStats commandToolStats;
|
public CommandToolStats commandToolStats;
|
||||||
public ItemLore itemLore;
|
public ItemLore itemLore;
|
||||||
|
public InventoryOpen inventoryOpen;
|
||||||
public final Logger logger = this.getLogger();
|
public PlayerJoin playerJoin;
|
||||||
public final File configFile = new File(this.getDataFolder(), "config.yml");
|
|
||||||
public FileConfiguration config;
|
|
||||||
public final int CONFIG_VERSION = 4;
|
|
||||||
|
|
||||||
private BukkitAudiences adventure;
|
|
||||||
|
|
||||||
public NumberFormat numberFormat;
|
public NumberFormat numberFormat;
|
||||||
|
public YamlConfiguration config;
|
||||||
|
public HashMaker hashMaker;
|
||||||
|
public CreativeEvent creativeEvent;
|
||||||
|
public PlayerMove playerMove;
|
||||||
|
public ItemChecker itemChecker;
|
||||||
|
public ShootBow shootBow;
|
||||||
|
public ConfigTools configTools;
|
||||||
|
public TokenData tokenData;
|
||||||
|
public AnvilEvent anvilEvent;
|
||||||
|
public PrepareCraft prepareCraft;
|
||||||
|
public HyperLib hyperLib;
|
||||||
|
public TextUtils textUtils;
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onEnable() {
|
public void onEnable() {
|
||||||
this.adventure = BukkitAudiences.create(this);
|
hyperLib = new HyperLib(this);
|
||||||
|
hyperLib.setup();
|
||||||
|
|
||||||
|
HyperStats stats = new HyperStats(hyperLib, 14110);
|
||||||
|
stats.setup();
|
||||||
|
|
||||||
|
textUtils = new TextUtils(hyperLib);
|
||||||
|
|
||||||
if (!configFile.exists()) {
|
if (!configFile.exists()) {
|
||||||
this.saveResource("config.yml", true);
|
this.saveResource("config.yml", true);
|
||||||
logger.info("Copying default config!");
|
logger.info("Copying default config!");
|
||||||
}
|
}
|
||||||
|
|
||||||
loadConfig();
|
loadConfig();
|
||||||
blocksMined = new BlocksMined(this);
|
configTools = new ConfigTools(this);
|
||||||
|
tokenData = new TokenData(this);
|
||||||
|
tokenData.setup();
|
||||||
|
for (ShapedRecipe recipe : tokenData.getRecipes()) {
|
||||||
|
if (tokens && config.getBoolean("tokens.craft-tokens")) {
|
||||||
|
Bukkit.addRecipe(recipe);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
hashMaker = new HashMaker(this);
|
||||||
|
blockBreak = new BlockBreak(this);
|
||||||
craftItem = new CraftItem(this);
|
craftItem = new CraftItem(this);
|
||||||
chunkPopulate = new ChunkPopulate(this);
|
chunkPopulate = new ChunkPopulate(this);
|
||||||
entityDeath = new EntityDeath(this);
|
entityDeath = new EntityDeath(this);
|
||||||
@@ -104,8 +192,28 @@ public final class ToolStats extends JavaPlugin {
|
|||||||
villagerTrade = new VillagerTrade(this);
|
villagerTrade = new VillagerTrade(this);
|
||||||
commandToolStats = new CommandToolStats(this);
|
commandToolStats = new CommandToolStats(this);
|
||||||
itemLore = new ItemLore(this);
|
itemLore = new ItemLore(this);
|
||||||
|
inventoryOpen = new InventoryOpen(this);
|
||||||
|
playerJoin = new PlayerJoin(this);
|
||||||
|
creativeEvent = new CreativeEvent(this);
|
||||||
|
playerMove = new PlayerMove(this);
|
||||||
|
itemChecker = new ItemChecker(this);
|
||||||
|
itemChecker.setup();
|
||||||
|
shootBow = new ShootBow(this);
|
||||||
|
anvilEvent = new AnvilEvent(this);
|
||||||
|
prepareCraft = new PrepareCraft(this);
|
||||||
|
|
||||||
Bukkit.getServer().getPluginManager().registerEvents(blocksMined, this);
|
// save which stat can be used by a reset token
|
||||||
|
tokenKeys.add(blocksMined);
|
||||||
|
tokenKeys.add(playerKills);
|
||||||
|
tokenKeys.add(mobKills);
|
||||||
|
tokenKeys.add(cropsHarvested);
|
||||||
|
tokenKeys.add(sheepSheared);
|
||||||
|
tokenKeys.add(fishCaught);
|
||||||
|
tokenKeys.add(flightTime);
|
||||||
|
tokenKeys.add(arrowsShot);
|
||||||
|
tokenKeys.add(armorDamage);
|
||||||
|
|
||||||
|
Bukkit.getServer().getPluginManager().registerEvents(blockBreak, this);
|
||||||
Bukkit.getServer().getPluginManager().registerEvents(chunkPopulate, this);
|
Bukkit.getServer().getPluginManager().registerEvents(chunkPopulate, this);
|
||||||
Bukkit.getServer().getPluginManager().registerEvents(craftItem, this);
|
Bukkit.getServer().getPluginManager().registerEvents(craftItem, this);
|
||||||
Bukkit.getServer().getPluginManager().registerEvents(entityDeath, this);
|
Bukkit.getServer().getPluginManager().registerEvents(entityDeath, this);
|
||||||
@@ -116,160 +224,39 @@ public final class ToolStats extends JavaPlugin {
|
|||||||
Bukkit.getServer().getPluginManager().registerEvents(playerInteract, this);
|
Bukkit.getServer().getPluginManager().registerEvents(playerInteract, this);
|
||||||
Bukkit.getServer().getPluginManager().registerEvents(sheepShear, this);
|
Bukkit.getServer().getPluginManager().registerEvents(sheepShear, this);
|
||||||
Bukkit.getServer().getPluginManager().registerEvents(villagerTrade, this);
|
Bukkit.getServer().getPluginManager().registerEvents(villagerTrade, this);
|
||||||
|
Bukkit.getServer().getPluginManager().registerEvents(inventoryOpen, this);
|
||||||
|
Bukkit.getServer().getPluginManager().registerEvents(playerJoin, this);
|
||||||
|
Bukkit.getServer().getPluginManager().registerEvents(creativeEvent, this);
|
||||||
|
Bukkit.getServer().getPluginManager().registerEvents(shootBow, this);
|
||||||
|
Bukkit.getServer().getPluginManager().registerEvents(playerMove, this);
|
||||||
|
Bukkit.getServer().getPluginManager().registerEvents(anvilEvent, this);
|
||||||
|
Bukkit.getServer().getPluginManager().registerEvents(prepareCraft, this);
|
||||||
|
|
||||||
this.getCommand("toolstats").setExecutor(commandToolStats);
|
this.getCommand("toolstats").setExecutor(commandToolStats);
|
||||||
|
|
||||||
new Metrics(this, 14110);
|
HyperUpdater updater = new HyperUpdater(hyperLib);
|
||||||
|
updater.setGitHub("hyperdefined", "ToolStats");
|
||||||
Bukkit.getScheduler().runTaskAsynchronously(this, this::checkForUpdates);
|
updater.setModrinth("oBZj9E15");
|
||||||
|
updater.setHangar("ToolStats", "paper");
|
||||||
|
updater.check();
|
||||||
}
|
}
|
||||||
|
|
||||||
public void loadConfig() {
|
public void loadConfig() {
|
||||||
config = YamlConfiguration.loadConfiguration(configFile);
|
config = YamlConfiguration.loadConfiguration(configFile);
|
||||||
if (config.getInt("config-version") != CONFIG_VERSION) {
|
if (config.getInt("config-version") != CONFIG_VERSION) {
|
||||||
logger.warning("Your config file is outdated! Please regenerate the config.");
|
logger.warn("Your config file is outdated! We will try to update it, but you should regenerate it!");
|
||||||
|
ConfigUpdater configUpdater = new ConfigUpdater(this);
|
||||||
|
configUpdater.updateConfig();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (config.getBoolean("tokens.enabled")) {
|
||||||
|
logger.info("The token system is enabled! This means you must apply tokens to items in order for them to track.");
|
||||||
|
logger.info("Item origins (crafted, traded, found, etc) will still apply to items.");
|
||||||
|
logger.info("https://github.com/hyperdefined/ToolStats/wiki/Token-System");
|
||||||
|
}
|
||||||
|
|
||||||
|
tokens = config.getBoolean("tokens.enabled");
|
||||||
|
|
||||||
numberFormat = new NumberFormat(this);
|
numberFormat = new NumberFormat(this);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void checkForUpdates() {
|
|
||||||
GitHubReleaseAPI api;
|
|
||||||
try {
|
|
||||||
api = new GitHubReleaseAPI("ToolStats", "hyperdefined");
|
|
||||||
} catch (IOException e) {
|
|
||||||
logger.warning("Unable to check updates!");
|
|
||||||
e.printStackTrace();
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
GitHubRelease current = api.getReleaseByTag(this.getDescription().getVersion());
|
|
||||||
GitHubRelease latest = api.getLatestVersion();
|
|
||||||
if (current == null) {
|
|
||||||
logger.warning("You are running a version that does not exist on GitHub. If you are in a dev environment, you can ignore this. Otherwise, this is a bug!");
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
int buildsBehind = api.getBuildsBehind(current);
|
|
||||||
if (buildsBehind == 0) {
|
|
||||||
logger.info("You are running the latest version.");
|
|
||||||
} else {
|
|
||||||
logger.warning("A new version is available (" + latest.getTagVersion() + ")! You are running version " + current.getTagVersion() + ". You are " + buildsBehind + " version(s) behind.");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Checks the config to see if we want to show lore on certain items.
|
|
||||||
*
|
|
||||||
* @param itemStack The item to check.
|
|
||||||
* @param configName The config we are checking under.
|
|
||||||
* @return If we want to allow lore or not.
|
|
||||||
*/
|
|
||||||
public boolean checkConfig(ItemStack itemStack, String configName) {
|
|
||||||
String itemName = itemStack.getType().toString().toLowerCase();
|
|
||||||
String itemType = null;
|
|
||||||
if (itemName.contains("bow") || itemName.contains("shears") || itemName.contains("trident")) {
|
|
||||||
if (itemName.contains("bow")) {
|
|
||||||
itemType = "bow";
|
|
||||||
}
|
|
||||||
if (itemName.contains("shears")) {
|
|
||||||
itemType = "shears";
|
|
||||||
}
|
|
||||||
if (itemName.contains("trident")) {
|
|
||||||
itemType = "trident";
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
itemType = itemName.substring(itemName.indexOf('_') + 1);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (itemType == null) {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
switch (itemType) {
|
|
||||||
case "pickaxe": {
|
|
||||||
return config.getBoolean("enabled." + configName + ".pickaxe");
|
|
||||||
}
|
|
||||||
case "sword": {
|
|
||||||
return config.getBoolean("enabled." + configName + ".sword");
|
|
||||||
}
|
|
||||||
case "shovel": {
|
|
||||||
return config.getBoolean("enabled." + configName + ".shovel");
|
|
||||||
}
|
|
||||||
case "axe": {
|
|
||||||
return config.getBoolean("enabled." + configName + ".axe");
|
|
||||||
}
|
|
||||||
case "hoe": {
|
|
||||||
return config.getBoolean("enabled." + configName + ".hoe");
|
|
||||||
}
|
|
||||||
case "shears": {
|
|
||||||
return config.getBoolean("enabled." + configName + ".shears");
|
|
||||||
}
|
|
||||||
case "bow": {
|
|
||||||
return config.getBoolean("enabled." + configName + ".bow");
|
|
||||||
}
|
|
||||||
case "trident": {
|
|
||||||
return config.getBoolean("enabled." + configName + ".trident");
|
|
||||||
}
|
|
||||||
case "helmet":
|
|
||||||
case "chestplate":
|
|
||||||
case "leggings":
|
|
||||||
case "boots": {
|
|
||||||
return config.getBoolean("enabled." + configName + ".armor");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Gets the lore message from the config.
|
|
||||||
*
|
|
||||||
* @param configName The config name, "messages." is already in front.
|
|
||||||
* @param raw If you want the raw message with the formatting codes and placeholders.
|
|
||||||
* @return The lore message.
|
|
||||||
*/
|
|
||||||
public String getLoreFromConfig(String configName, boolean raw) {
|
|
||||||
String lore = config.getString("messages." + configName);
|
|
||||||
if (lore == null) {
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
if (raw) {
|
|
||||||
return ChatColor.translateAlternateColorCodes('&', lore);
|
|
||||||
} else {
|
|
||||||
// we basically add the color codes then remove them
|
|
||||||
// this is a dirty trick to remove color codes
|
|
||||||
lore = ChatColor.translateAlternateColorCodes('&', lore);
|
|
||||||
lore = ChatColor.stripColor(lore);
|
|
||||||
if (lore.contains("{player}")) {
|
|
||||||
lore = lore.replace("{player}", "");
|
|
||||||
}
|
|
||||||
if (lore.contains("{date}")) {
|
|
||||||
lore = lore.replace("{date}", "");
|
|
||||||
}
|
|
||||||
if (lore.contains("{name}")) {
|
|
||||||
lore = lore.replace("{name}", "");
|
|
||||||
}
|
|
||||||
if (lore.contains("{kills}")) {
|
|
||||||
lore = lore.replace("{kills}", "");
|
|
||||||
}
|
|
||||||
if (lore.contains("{blocks}")) {
|
|
||||||
lore = lore.replace("{blocks}", "");
|
|
||||||
}
|
|
||||||
if (lore.contains("{sheep}")) {
|
|
||||||
lore = lore.replace("{sheep}", "");
|
|
||||||
}
|
|
||||||
if (lore.contains("{damage}")) {
|
|
||||||
lore = lore.replace("{damage}", "");
|
|
||||||
}
|
|
||||||
if (lore.contains("{fish}")) {
|
|
||||||
lore = lore.replace("{fish}", "");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return lore;
|
|
||||||
}
|
|
||||||
|
|
||||||
public BukkitAudiences getAdventure() {
|
|
||||||
if (this.adventure == null) {
|
|
||||||
throw new IllegalStateException("Tried to access Adventure when the plugin was disabled!");
|
|
||||||
}
|
|
||||||
return this.adventure;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|||||||
398
src/main/java/lol/hyper/toolstats/events/AnvilEvent.java
Normal file
@@ -0,0 +1,398 @@
|
|||||||
|
/*
|
||||||
|
* This file is part of ToolStats.
|
||||||
|
*
|
||||||
|
* ToolStats is free software: you can redistribute it and/or modify
|
||||||
|
* it under the terms of the GNU General Public License as published by
|
||||||
|
* the Free Software Foundation, either version 3 of the License, or
|
||||||
|
* (at your option) any later version.
|
||||||
|
*
|
||||||
|
* ToolStats is distributed in the hope that it will be useful,
|
||||||
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
* GNU General Public License for more details.
|
||||||
|
*
|
||||||
|
* You should have received a copy of the GNU General Public License
|
||||||
|
* along with ToolStats. If not, see <https://www.gnu.org/licenses/>.
|
||||||
|
*/
|
||||||
|
|
||||||
|
package lol.hyper.toolstats.events;
|
||||||
|
|
||||||
|
import lol.hyper.toolstats.ToolStats;
|
||||||
|
import org.bukkit.Material;
|
||||||
|
import org.bukkit.event.EventHandler;
|
||||||
|
import org.bukkit.event.EventPriority;
|
||||||
|
import org.bukkit.event.Listener;
|
||||||
|
import org.bukkit.event.inventory.PrepareAnvilEvent;
|
||||||
|
import org.bukkit.inventory.AnvilInventory;
|
||||||
|
import org.bukkit.inventory.ItemStack;
|
||||||
|
import org.bukkit.inventory.meta.ItemMeta;
|
||||||
|
import org.bukkit.persistence.PersistentDataContainer;
|
||||||
|
import org.bukkit.persistence.PersistentDataType;
|
||||||
|
|
||||||
|
import java.util.Locale;
|
||||||
|
|
||||||
|
public class AnvilEvent implements Listener {
|
||||||
|
|
||||||
|
private final ToolStats toolStats;
|
||||||
|
|
||||||
|
public AnvilEvent(ToolStats toolStats) {
|
||||||
|
this.toolStats = toolStats;
|
||||||
|
}
|
||||||
|
|
||||||
|
@EventHandler(priority = EventPriority.HIGHEST)
|
||||||
|
public void onAnvilEvent(PrepareAnvilEvent event) {
|
||||||
|
// only listen if the token system is enabled
|
||||||
|
if (!toolStats.config.getBoolean("tokens.enabled")) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
AnvilInventory inventory = event.getInventory();
|
||||||
|
|
||||||
|
ItemStack firstSlot = inventory.getItem(0);
|
||||||
|
ItemStack secondSlot = inventory.getItem(1);
|
||||||
|
|
||||||
|
// make sure both slots have items
|
||||||
|
if (firstSlot == null || secondSlot == null) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
Material firstSlotMaterial = firstSlot.getType();
|
||||||
|
|
||||||
|
// make sure the first item is a valid item
|
||||||
|
if (!toolStats.itemChecker.isValidItem(firstSlotMaterial)) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
PersistentDataContainer secondSlotContainer = secondSlot.getItemMeta().getPersistentDataContainer();
|
||||||
|
|
||||||
|
// make sure the 2nd item is one of ours
|
||||||
|
if (!secondSlotContainer.has(toolStats.tokenType, PersistentDataType.STRING)) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
// get the type from the token
|
||||||
|
String tokenType = secondSlotContainer.get(toolStats.tokenType, PersistentDataType.STRING);
|
||||||
|
if (tokenType == null) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
// don't let the player use more than one
|
||||||
|
if (secondSlot.getAmount() > 1) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
// clone the item
|
||||||
|
ItemStack clone = firstSlot.clone();
|
||||||
|
|
||||||
|
if (tokenType.equalsIgnoreCase("reset")) {
|
||||||
|
reset(event, clone);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (tokenType.equalsIgnoreCase("remove")) {
|
||||||
|
ItemStack removedStats = toolStats.itemLore.removeAll(clone, false);
|
||||||
|
event.setResult(removedStats);
|
||||||
|
event.getView().setRepairCost(toolStats.itemChecker.getCost("remove"));
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
// if the item is a mining tool
|
||||||
|
if (toolStats.itemChecker.isMineTool(firstSlotMaterial)) {
|
||||||
|
if (firstSlotMaterial.toString().toLowerCase(Locale.ROOT).contains("hoe")) {
|
||||||
|
// the item is a hoe
|
||||||
|
if (tokenType.equalsIgnoreCase("blocks-mined")) {
|
||||||
|
addToken(event, tokenType, "blocks-mined", clone);
|
||||||
|
}
|
||||||
|
if (tokenType.equalsIgnoreCase("crops-mined")) {
|
||||||
|
addToken(event, tokenType, "crops-mined", clone);
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
// since shears will fall under here, check if the token is for sheep sheared
|
||||||
|
if (firstSlotMaterial == Material.SHEARS && tokenType.equals("sheep-sheared")) {
|
||||||
|
addToken(event, tokenType, "sheep-sheared", clone);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
addToken(event, tokenType, "blocks-mined", clone);
|
||||||
|
}
|
||||||
|
// axes are a mining tool, so double check them here for player/mob kills
|
||||||
|
if (firstSlotMaterial.toString().toLowerCase(Locale.ROOT).contains("_axe")) {
|
||||||
|
if (tokenType.equalsIgnoreCase("player-kills")) {
|
||||||
|
addToken(event, tokenType, "player-kills", clone);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
if (tokenType.equalsIgnoreCase("mob-kills")) {
|
||||||
|
addToken(event, tokenType, "mob-kills", clone);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
if (tokenType.equalsIgnoreCase("damage-done")) {
|
||||||
|
addToken(event, tokenType, "damage-done", clone);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
if (toolStats.itemChecker.canGlide(clone)) {
|
||||||
|
addToken(event, tokenType, "flight-time", clone);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
if (toolStats.itemChecker.isArmor(firstSlotMaterial)) {
|
||||||
|
addToken(event, tokenType, "damage-taken", clone);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
if (toolStats.itemChecker.isMeleeWeapon(firstSlotMaterial)) {
|
||||||
|
if (tokenType.equalsIgnoreCase("player-kills")) {
|
||||||
|
addToken(event, tokenType, "player-kills", clone);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
if (tokenType.equalsIgnoreCase("mob-kills")) {
|
||||||
|
addToken(event, tokenType, "mob-kills", clone);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
if (tokenType.equalsIgnoreCase("damage-done")) {
|
||||||
|
addToken(event, tokenType, "damage-done", clone);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
if (firstSlotMaterial == Material.BOW || firstSlotMaterial == Material.CROSSBOW) {
|
||||||
|
if (tokenType.equalsIgnoreCase("player-kills")) {
|
||||||
|
addToken(event, tokenType, "player-kills", clone);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
if (tokenType.equalsIgnoreCase("mob-kills")) {
|
||||||
|
addToken(event, tokenType, "mob-kills", clone);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
if (tokenType.equalsIgnoreCase("arrows-shot")) {
|
||||||
|
addToken(event, tokenType, "arrows-shot", clone);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
if (tokenType.equalsIgnoreCase("damage-done")) {
|
||||||
|
addToken(event, tokenType, "damage-done", clone);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
if (firstSlotMaterial == Material.FISHING_ROD) {
|
||||||
|
addToken(event, tokenType, "fish-caught", clone);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Add token to an item.
|
||||||
|
*
|
||||||
|
* @param event The anvil event.
|
||||||
|
* @param attemptToken The token in the 2nd slot of the anvil. The one the player wants to add.
|
||||||
|
* @param targetToken The token we are checking for. This should match the tool.
|
||||||
|
* @param firstSlotItem The item in the first slot.
|
||||||
|
*/
|
||||||
|
private void addToken(PrepareAnvilEvent event, String attemptToken, String targetToken, ItemStack firstSlotItem) {
|
||||||
|
// make sure the token we are using is for this tool
|
||||||
|
if (!attemptToken.equalsIgnoreCase(targetToken)) {
|
||||||
|
event.setResult(null);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
// if the item already has the token, ignore
|
||||||
|
if (toolStats.itemChecker.checkTokens(firstSlotItem.getItemMeta().getPersistentDataContainer(), targetToken)) {
|
||||||
|
event.setResult(null);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
// apply the token and set the result
|
||||||
|
ItemStack newItem = toolStats.itemChecker.addToken(firstSlotItem, targetToken);
|
||||||
|
switch (targetToken) {
|
||||||
|
case "crops-mined": {
|
||||||
|
if (toolStats.config.getBoolean("enabled.crops-harvested")) {
|
||||||
|
newItem.setItemMeta(toolStats.itemLore.updateCropsMined(newItem, 0));
|
||||||
|
} else {
|
||||||
|
event.setResult(null);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
case "blocks-mined": {
|
||||||
|
if (toolStats.configTools.checkConfig(newItem.getType(), "blocks-mined")) {
|
||||||
|
newItem.setItemMeta(toolStats.itemLore.updateBlocksMined(newItem, 0));
|
||||||
|
} else {
|
||||||
|
event.setResult(null);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
case "damage-taken": {
|
||||||
|
if (toolStats.config.getBoolean("enabled.armor-damage")) {
|
||||||
|
newItem.setItemMeta(toolStats.itemLore.updateArmorDamage(newItem, 0.0, false));
|
||||||
|
} else {
|
||||||
|
event.setResult(null);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
case "damage-done": {
|
||||||
|
if (toolStats.configTools.checkConfig(newItem.getType(), "damage-done")) {
|
||||||
|
newItem.setItemMeta(toolStats.itemLore.updateWeaponDamage(newItem, 0.0, false));
|
||||||
|
} else {
|
||||||
|
event.setResult(null);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
case "mob-kills": {
|
||||||
|
if (toolStats.configTools.checkConfig(newItem.getType(), "mob-kills")) {
|
||||||
|
newItem.setItemMeta(toolStats.itemLore.updateMobKills(newItem, 0));
|
||||||
|
} else {
|
||||||
|
event.setResult(null);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
case "player-kills": {
|
||||||
|
if (toolStats.configTools.checkConfig(newItem.getType(), "player-kills")) {
|
||||||
|
newItem.setItemMeta(toolStats.itemLore.updatePlayerKills(newItem, 0));
|
||||||
|
} else {
|
||||||
|
event.setResult(null);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
case "arrows-shot": {
|
||||||
|
if (toolStats.config.getBoolean("enabled.arrows-shot")) {
|
||||||
|
newItem.setItemMeta(toolStats.itemLore.updateArrowsShot(newItem, 0));
|
||||||
|
} else {
|
||||||
|
event.setResult(null);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
case "sheep-sheared": {
|
||||||
|
if (toolStats.config.getBoolean("enabled.sheep-sheared")) {
|
||||||
|
newItem.setItemMeta(toolStats.itemLore.updateSheepSheared(newItem, 0));
|
||||||
|
} else {
|
||||||
|
event.setResult(null);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
case "flight-time": {
|
||||||
|
if (toolStats.config.getBoolean("enabled.flight-time")) {
|
||||||
|
newItem.setItemMeta(toolStats.itemLore.updateFlightTime(newItem, 0));
|
||||||
|
} else {
|
||||||
|
event.setResult(null);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
case "fish-caught": {
|
||||||
|
if (toolStats.config.getBoolean("enabled.fish-caught")) {
|
||||||
|
newItem.setItemMeta(toolStats.itemLore.updateFishCaught(newItem, 0));
|
||||||
|
} else {
|
||||||
|
event.setResult(null);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
event.setResult(newItem);
|
||||||
|
event.getView().setRepairCost(toolStats.itemChecker.getCost(targetToken));
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Reset an item's stats. This function is... gross.
|
||||||
|
* Because of how the lore system is set up, we have to basically revert the stats.
|
||||||
|
* The lore function requires the old value, then adds x to the current stat.
|
||||||
|
* This is required, so it can find the old line in the lore and update it.
|
||||||
|
* So we simply make the stat negative, and add it to reset it to zero.
|
||||||
|
* Gross? Yeah, but I don't want to rewrite the lore system again...
|
||||||
|
*
|
||||||
|
* @param event The PrepareAnvilEvent event.
|
||||||
|
* @param inputItem The input item to reset.
|
||||||
|
*/
|
||||||
|
private void reset(PrepareAnvilEvent event, ItemStack inputItem) {
|
||||||
|
ItemStack finalItem = inputItem.clone();
|
||||||
|
ItemMeta meta = finalItem.getItemMeta();
|
||||||
|
PersistentDataContainer container = meta.getPersistentDataContainer();
|
||||||
|
|
||||||
|
if (container.has(toolStats.playerKills)) {
|
||||||
|
Integer playerKills = container.get(toolStats.playerKills, PersistentDataType.INTEGER);
|
||||||
|
if (playerKills == null) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
meta = toolStats.itemLore.updatePlayerKills(finalItem, -playerKills);
|
||||||
|
finalItem.setItemMeta(meta);
|
||||||
|
}
|
||||||
|
if (container.has(toolStats.mobKills)) {
|
||||||
|
Integer mobKills = container.get(toolStats.mobKills, PersistentDataType.INTEGER);
|
||||||
|
if (mobKills == null) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
meta = toolStats.itemLore.updateMobKills(finalItem, -mobKills);
|
||||||
|
finalItem.setItemMeta(meta);
|
||||||
|
}
|
||||||
|
if (container.has(toolStats.blocksMined)) {
|
||||||
|
Integer blocksMined = container.get(toolStats.blocksMined, PersistentDataType.INTEGER);
|
||||||
|
if (blocksMined == null) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
meta = toolStats.itemLore.updateBlocksMined(finalItem, -blocksMined);
|
||||||
|
finalItem.setItemMeta(meta);
|
||||||
|
}
|
||||||
|
if (container.has(toolStats.cropsHarvested)) {
|
||||||
|
Integer cropsHarvested = container.get(toolStats.playerKills, PersistentDataType.INTEGER);
|
||||||
|
if (cropsHarvested == null) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
meta = toolStats.itemLore.updateCropsMined(finalItem, -cropsHarvested);
|
||||||
|
finalItem.setItemMeta(meta);
|
||||||
|
}
|
||||||
|
if (container.has(toolStats.fishCaught)) {
|
||||||
|
Integer fishCaught = container.get(toolStats.fishCaught, PersistentDataType.INTEGER);
|
||||||
|
if (fishCaught == null) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
meta = toolStats.itemLore.updateFishCaught(finalItem, -fishCaught);
|
||||||
|
finalItem.setItemMeta(meta);
|
||||||
|
}
|
||||||
|
if (container.has(toolStats.sheepSheared)) {
|
||||||
|
Integer sheepSheared = container.get(toolStats.sheepSheared, PersistentDataType.INTEGER);
|
||||||
|
if (sheepSheared == null) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
meta = toolStats.itemLore.updateSheepSheared(finalItem, -sheepSheared);
|
||||||
|
finalItem.setItemMeta(meta);
|
||||||
|
}
|
||||||
|
if (container.has(toolStats.armorDamage)) {
|
||||||
|
Double armorDamage = container.get(toolStats.armorDamage, PersistentDataType.DOUBLE);
|
||||||
|
if (armorDamage == null) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
meta = toolStats.itemLore.updateArmorDamage(finalItem, -armorDamage, true);
|
||||||
|
finalItem.setItemMeta(meta);
|
||||||
|
}
|
||||||
|
if (container.has(toolStats.damageDone)) {
|
||||||
|
Double damageDone = container.get(toolStats.damageDone, PersistentDataType.DOUBLE);
|
||||||
|
if (damageDone == null) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
meta = toolStats.itemLore.updateArmorDamage(finalItem, -damageDone, true);
|
||||||
|
finalItem.setItemMeta(meta);
|
||||||
|
}
|
||||||
|
if (container.has(toolStats.arrowsShot)) {
|
||||||
|
Integer arrowsShot = container.get(toolStats.arrowsShot, PersistentDataType.INTEGER);
|
||||||
|
if (arrowsShot == null) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
meta = toolStats.itemLore.updateArrowsShot(finalItem, -arrowsShot);
|
||||||
|
finalItem.setItemMeta(meta);
|
||||||
|
}
|
||||||
|
if (container.has(toolStats.flightTime)) {
|
||||||
|
Long flightTime = container.get(toolStats.flightTime, PersistentDataType.LONG);
|
||||||
|
if (flightTime == null) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
meta = toolStats.itemLore.updateFlightTime(finalItem, -flightTime);
|
||||||
|
finalItem.setItemMeta(meta);
|
||||||
|
}
|
||||||
|
event.setResult(finalItem);
|
||||||
|
event.getView().setRepairCost(toolStats.itemChecker.getCost("reset"));
|
||||||
|
}
|
||||||
|
}
|
||||||
99
src/main/java/lol/hyper/toolstats/events/BlockBreak.java
Normal file
@@ -0,0 +1,99 @@
|
|||||||
|
/*
|
||||||
|
* This file is part of ToolStats.
|
||||||
|
*
|
||||||
|
* ToolStats is free software: you can redistribute it and/or modify
|
||||||
|
* it under the terms of the GNU General Public License as published by
|
||||||
|
* the Free Software Foundation, either version 3 of the License, or
|
||||||
|
* (at your option) any later version.
|
||||||
|
*
|
||||||
|
* ToolStats is distributed in the hope that it will be useful,
|
||||||
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
* GNU General Public License for more details.
|
||||||
|
*
|
||||||
|
* You should have received a copy of the GNU General Public License
|
||||||
|
* along with ToolStats. If not, see <https://www.gnu.org/licenses/>.
|
||||||
|
*/
|
||||||
|
|
||||||
|
package lol.hyper.toolstats.events;
|
||||||
|
|
||||||
|
import lol.hyper.toolstats.ToolStats;
|
||||||
|
import org.bukkit.Bukkit;
|
||||||
|
import org.bukkit.GameMode;
|
||||||
|
import org.bukkit.Material;
|
||||||
|
import org.bukkit.block.Block;
|
||||||
|
import org.bukkit.block.data.Ageable;
|
||||||
|
import org.bukkit.entity.Player;
|
||||||
|
import org.bukkit.event.EventHandler;
|
||||||
|
import org.bukkit.event.EventPriority;
|
||||||
|
import org.bukkit.event.Listener;
|
||||||
|
import org.bukkit.event.block.BlockBreakEvent;
|
||||||
|
import org.bukkit.inventory.ItemStack;
|
||||||
|
import org.bukkit.inventory.PlayerInventory;
|
||||||
|
import org.bukkit.inventory.meta.ItemMeta;
|
||||||
|
|
||||||
|
import java.util.Locale;
|
||||||
|
|
||||||
|
public class BlockBreak implements Listener {
|
||||||
|
|
||||||
|
private final ToolStats toolStats;
|
||||||
|
|
||||||
|
public BlockBreak(ToolStats toolStats) {
|
||||||
|
this.toolStats = toolStats;
|
||||||
|
}
|
||||||
|
|
||||||
|
@EventHandler(priority = EventPriority.MONITOR)
|
||||||
|
public void onBreak(BlockBreakEvent event) {
|
||||||
|
if (event.isCancelled()) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
Player player = event.getPlayer();
|
||||||
|
if (player.getGameMode() == GameMode.CREATIVE && !toolStats.config.getBoolean("allow-creative")) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
PlayerInventory inventory = player.getInventory();
|
||||||
|
ItemStack heldItem = inventory.getItemInMainHand();
|
||||||
|
Block block = event.getBlock();
|
||||||
|
|
||||||
|
if (block.getType() == Material.CHEST) {
|
||||||
|
toolStats.playerInteract.openedChests.put(block, player);
|
||||||
|
Bukkit.getGlobalRegionScheduler().runDelayed(toolStats, scheduledTask -> toolStats.playerInteract.openedChests.remove(block), 20);
|
||||||
|
}
|
||||||
|
|
||||||
|
// only check certain items
|
||||||
|
if (!toolStats.itemChecker.isMineTool(heldItem.getType())) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
// if the item is a hoe
|
||||||
|
if (heldItem.getType().toString().toLowerCase(Locale.ROOT).contains("hoe")) {
|
||||||
|
// player is breaking crops with a hoe
|
||||||
|
if (block.getBlockData() instanceof Ageable ageable) {
|
||||||
|
// ignore crops that are not fully grown
|
||||||
|
if (ageable.getAge() != ageable.getMaximumAge()) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
ItemMeta newMeta = toolStats.itemLore.updateCropsMined(heldItem, 1);
|
||||||
|
if (newMeta != null) {
|
||||||
|
// replace item in main hand
|
||||||
|
heldItem.setItemMeta(newMeta);
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
// item is a hoe, but not breaking crops
|
||||||
|
ItemMeta newMeta = toolStats.itemLore.updateBlocksMined(heldItem, 1);
|
||||||
|
if (newMeta != null) {
|
||||||
|
// replace item in main hand
|
||||||
|
heldItem.setItemMeta(newMeta);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
// item is not a hoe
|
||||||
|
// update the blocks mined
|
||||||
|
ItemMeta newMeta = toolStats.itemLore.updateBlocksMined(heldItem, 1);
|
||||||
|
if (newMeta != null) {
|
||||||
|
// replace item in main hand
|
||||||
|
heldItem.setItemMeta(newMeta);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -1,95 +0,0 @@
|
|||||||
/*
|
|
||||||
* This file is part of ToolStats.
|
|
||||||
*
|
|
||||||
* ToolStats is free software: you can redistribute it and/or modify
|
|
||||||
* it under the terms of the GNU General Public License as published by
|
|
||||||
* the Free Software Foundation, either version 3 of the License, or
|
|
||||||
* (at your option) any later version.
|
|
||||||
*
|
|
||||||
* ToolStats is distributed in the hope that it will be useful,
|
|
||||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
||||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
||||||
* GNU General Public License for more details.
|
|
||||||
*
|
|
||||||
* You should have received a copy of the GNU General Public License
|
|
||||||
* along with ToolStats. If not, see <https://www.gnu.org/licenses/>.
|
|
||||||
*/
|
|
||||||
|
|
||||||
package lol.hyper.toolstats.events;
|
|
||||||
|
|
||||||
import lol.hyper.toolstats.ToolStats;
|
|
||||||
import lol.hyper.toolstats.tools.ItemChecker;
|
|
||||||
import org.bukkit.GameMode;
|
|
||||||
import org.bukkit.entity.Player;
|
|
||||||
import org.bukkit.event.EventHandler;
|
|
||||||
import org.bukkit.event.EventPriority;
|
|
||||||
import org.bukkit.event.Listener;
|
|
||||||
import org.bukkit.event.block.BlockBreakEvent;
|
|
||||||
import org.bukkit.inventory.ItemStack;
|
|
||||||
import org.bukkit.inventory.PlayerInventory;
|
|
||||||
import org.bukkit.inventory.meta.ItemMeta;
|
|
||||||
import org.bukkit.persistence.PersistentDataContainer;
|
|
||||||
import org.bukkit.persistence.PersistentDataType;
|
|
||||||
|
|
||||||
import java.util.List;
|
|
||||||
|
|
||||||
public class BlocksMined implements Listener {
|
|
||||||
|
|
||||||
private final ToolStats toolStats;
|
|
||||||
|
|
||||||
public BlocksMined(ToolStats toolStats) {
|
|
||||||
this.toolStats = toolStats;
|
|
||||||
}
|
|
||||||
|
|
||||||
@EventHandler(priority = EventPriority.MONITOR)
|
|
||||||
public void onBreak(BlockBreakEvent event) {
|
|
||||||
if (event.isCancelled()) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
Player player = event.getPlayer();
|
|
||||||
if (player.getGameMode() == GameMode.CREATIVE || player.getGameMode() == GameMode.SPECTATOR) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
// if the player mines something with their fist
|
|
||||||
PlayerInventory inventory = player.getInventory();
|
|
||||||
ItemStack heldItem = inventory.getItemInMainHand();
|
|
||||||
// only check certain items
|
|
||||||
if (!ItemChecker.isMineTool(heldItem.getType())) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
// update the blocks mined
|
|
||||||
updateBlocksMined(heldItem);
|
|
||||||
}
|
|
||||||
|
|
||||||
private void updateBlocksMined(ItemStack playerTool) {
|
|
||||||
ItemMeta meta = playerTool.getItemMeta();
|
|
||||||
if (meta == null) {
|
|
||||||
toolStats.logger.warning(playerTool + " does NOT have any meta! Unable to update stats.");
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
// read the current stats from the item
|
|
||||||
// if they don't exist, then start from 0
|
|
||||||
Integer blocksMined = 0;
|
|
||||||
PersistentDataContainer container = meta.getPersistentDataContainer();
|
|
||||||
if (container.has(toolStats.genericMined, PersistentDataType.INTEGER)) {
|
|
||||||
blocksMined = container.get(toolStats.genericMined, PersistentDataType.INTEGER);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (blocksMined == null) {
|
|
||||||
blocksMined = 0;
|
|
||||||
toolStats.logger.warning(playerTool + " does not have valid generic-mined set! Resting to zero. This should NEVER happen.");
|
|
||||||
}
|
|
||||||
|
|
||||||
blocksMined++;
|
|
||||||
container.set(toolStats.genericMined, PersistentDataType.INTEGER, blocksMined);
|
|
||||||
|
|
||||||
String blocksMinedFormatted = toolStats.numberFormat.formatInt(blocksMined);
|
|
||||||
List<String> newLore = toolStats.itemLore.addItemLore(meta, "{blocks}", blocksMinedFormatted, "blocks-mined");
|
|
||||||
|
|
||||||
// do we add the lore based on the config?
|
|
||||||
if (toolStats.checkConfig(playerTool, "blocks-mined")) {
|
|
||||||
meta.setLore(newLore);
|
|
||||||
}
|
|
||||||
playerTool.setItemMeta(meta);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -49,16 +49,16 @@ public class ChunkPopulate implements Listener {
|
|||||||
if (event.getChunk().getWorld().getEnvironment() != World.Environment.THE_END) {
|
if (event.getChunk().getWorld().getEnvironment() != World.Environment.THE_END) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
World world = event.getChunk().getWorld();
|
||||||
// this is delayed because entities are not loaded instantly
|
// this is delayed because entities are not loaded instantly
|
||||||
// we just check 1 second later
|
// we just check 1 second later
|
||||||
Bukkit.getScheduler().runTaskLater(toolStats, () -> {
|
|
||||||
Chunk chunk = event.getChunk();
|
Chunk chunk = event.getChunk();
|
||||||
|
Bukkit.getRegionScheduler().runDelayed(toolStats, world, chunk.getX(), chunk.getZ(), scheduledTask -> {
|
||||||
for (Entity entity : chunk.getEntities()) {
|
for (Entity entity : chunk.getEntities()) {
|
||||||
// if there is a new item frame
|
// if there is a new item frame
|
||||||
if (!(entity instanceof ItemFrame)) {
|
if (!(entity instanceof ItemFrame itemFrame)) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
ItemFrame itemFrame = (ItemFrame) entity;
|
|
||||||
// if the item frame has an elytra
|
// if the item frame has an elytra
|
||||||
if (itemFrame.getItem().getType() == Material.ELYTRA) {
|
if (itemFrame.getItem().getType() == Material.ELYTRA) {
|
||||||
ItemStack elytraCopy = itemFrame.getItem();
|
ItemStack elytraCopy = itemFrame.getItem();
|
||||||
|
|||||||
@@ -17,10 +17,9 @@
|
|||||||
|
|
||||||
package lol.hyper.toolstats.events;
|
package lol.hyper.toolstats.events;
|
||||||
|
|
||||||
|
import lol.hyper.hyperlib.datatypes.UUIDDataType;
|
||||||
import lol.hyper.toolstats.ToolStats;
|
import lol.hyper.toolstats.ToolStats;
|
||||||
import lol.hyper.toolstats.tools.ItemChecker;
|
import net.kyori.adventure.text.Component;
|
||||||
import lol.hyper.toolstats.tools.UUIDDataType;
|
|
||||||
import org.bukkit.ChatColor;
|
|
||||||
import org.bukkit.GameMode;
|
import org.bukkit.GameMode;
|
||||||
import org.bukkit.Material;
|
import org.bukkit.Material;
|
||||||
import org.bukkit.entity.Player;
|
import org.bukkit.entity.Player;
|
||||||
@@ -33,7 +32,9 @@ import org.bukkit.inventory.meta.ItemMeta;
|
|||||||
import org.bukkit.persistence.PersistentDataContainer;
|
import org.bukkit.persistence.PersistentDataContainer;
|
||||||
import org.bukkit.persistence.PersistentDataType;
|
import org.bukkit.persistence.PersistentDataType;
|
||||||
|
|
||||||
import java.util.*;
|
import java.util.ArrayList;
|
||||||
|
import java.util.Date;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
public class CraftItem implements Listener {
|
public class CraftItem implements Listener {
|
||||||
|
|
||||||
@@ -49,29 +50,54 @@ public class CraftItem implements Listener {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
Player player = (Player) event.getWhoClicked();
|
Player player = (Player) event.getWhoClicked();
|
||||||
if (player.getGameMode() == GameMode.CREATIVE || player.getGameMode() == GameMode.SPECTATOR) {
|
if (player.getGameMode() == GameMode.CREATIVE && !toolStats.config.getBoolean("allow-creative")) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
ItemStack itemStack = event.getCurrentItem();
|
ItemStack craftedItem = event.getCurrentItem();
|
||||||
if (itemStack == null || itemStack.getType() == Material.AIR) {
|
if (craftedItem == null || craftedItem.getType() == Material.AIR) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
Material craftedMaterial = craftedItem.getType();
|
||||||
// only check certain items
|
// only check certain items
|
||||||
if (!ItemChecker.isValidItem(itemStack.getType())) {
|
if (!toolStats.itemChecker.isValidItem(craftedMaterial)) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
// if the player shift clicks, send them this warning
|
// if the player shift clicks
|
||||||
if (event.isShiftClick()) {
|
if (event.isShiftClick()) {
|
||||||
String configMessage = toolStats.config.getString("messages.shift-click-warning.crafting");
|
// store the player inventory before they craft the items
|
||||||
if (configMessage != null) {
|
ItemStack[] beforeCraft = player.getInventory().getContents();
|
||||||
if (configMessage.length() != 0) {
|
// run a tick after to see the changes
|
||||||
event.getWhoClicked().sendMessage(ChatColor.translateAlternateColorCodes('&', configMessage));
|
player.getScheduler().runDelayed(toolStats, scheduledTask -> {
|
||||||
|
// get their inventory after the craft
|
||||||
|
ItemStack[] afterCraft = player.getInventory().getContents();
|
||||||
|
for (int i = 0; i < afterCraft.length; i++) {
|
||||||
|
ItemStack newSlotItem = afterCraft[i];
|
||||||
|
ItemStack oldSlotItem = beforeCraft[i];
|
||||||
|
|
||||||
|
// if this slot is empty after crafting, skip it
|
||||||
|
if (newSlotItem == null) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
// if the item matches what we crafted
|
||||||
|
if (newSlotItem.getType() == craftedMaterial) {
|
||||||
|
// if the slot was empty before we crafted, this means we just made it
|
||||||
|
if (oldSlotItem == null) {
|
||||||
|
// add the lore
|
||||||
|
ItemStack newItem = addCraftOrigin(newSlotItem, player);
|
||||||
|
if (newItem != null) {
|
||||||
|
player.getInventory().setItem(i, newItem);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
// test the item before setting it
|
}
|
||||||
ItemStack newItem = addLore(itemStack, player);
|
}, null, 1);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
// the player did not shift click
|
||||||
|
ItemStack newItem = addCraftOrigin(craftedItem, player);
|
||||||
if (newItem != null) {
|
if (newItem != null) {
|
||||||
// set the result
|
// set the result
|
||||||
event.setCurrentItem(newItem);
|
event.setCurrentItem(newItem);
|
||||||
@@ -85,55 +111,60 @@ public class CraftItem implements Listener {
|
|||||||
* @param owner The player crafting.
|
* @param owner The player crafting.
|
||||||
* @return A copy of the item with the tags + lore.
|
* @return A copy of the item with the tags + lore.
|
||||||
*/
|
*/
|
||||||
private ItemStack addLore(ItemStack itemStack, Player owner) {
|
private ItemStack addCraftOrigin(ItemStack itemStack, Player owner) {
|
||||||
// clone the item
|
// clone the item
|
||||||
ItemStack newItem = itemStack.clone();
|
ItemStack newItem = itemStack.clone();
|
||||||
ItemMeta meta = newItem.getItemMeta();
|
ItemMeta meta = newItem.getItemMeta();
|
||||||
if (meta == null) {
|
if (meta == null) {
|
||||||
toolStats.logger.warning(itemStack + " does NOT have any meta! Unable to update stats.");
|
toolStats.logger.warn("{} does NOT have any meta! Unable to update stats.", itemStack);
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
// get the current time
|
// get the current time
|
||||||
long timeCreated = System.currentTimeMillis();
|
long timeCreated = System.currentTimeMillis();
|
||||||
Date finalDate = new Date(timeCreated);
|
Date finalDate;
|
||||||
|
if (toolStats.config.getBoolean("normalize-time-creation")) {
|
||||||
|
finalDate = toolStats.numberFormat.normalizeTime(timeCreated);
|
||||||
|
timeCreated = finalDate.getTime();
|
||||||
|
}
|
||||||
PersistentDataContainer container = meta.getPersistentDataContainer();
|
PersistentDataContainer container = meta.getPersistentDataContainer();
|
||||||
|
|
||||||
// if the item already has the tag
|
// if the item already has the tag
|
||||||
// this is to prevent duplicate tags
|
// this is to prevent duplicate tags
|
||||||
if (container.has(toolStats.timeCreated, PersistentDataType.LONG) || container.has(toolStats.genericOwner, PersistentDataType.LONG)) {
|
if (container.has(toolStats.timeCreated, PersistentDataType.LONG) || container.has(toolStats.itemOwner, PersistentDataType.LONG)) {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
container.set(toolStats.timeCreated, PersistentDataType.LONG, timeCreated);
|
|
||||||
container.set(toolStats.genericOwner, new UUIDDataType(), owner.getUniqueId());
|
|
||||||
|
|
||||||
String createdByRaw = toolStats.getLoreFromConfig("created.created-by", true);
|
|
||||||
String createdOnRaw = toolStats.getLoreFromConfig("created.created-on", true);
|
|
||||||
|
|
||||||
if (createdOnRaw == null) {
|
|
||||||
toolStats.logger.warning("There is no lore message for messages.created.created-on!");
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
if (createdByRaw == null) {
|
|
||||||
toolStats.logger.warning("There is no lore message for messages.created.created-by!");
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
|
|
||||||
List<String> lore;
|
|
||||||
// get the current lore the item
|
// get the current lore the item
|
||||||
|
List<Component> lore;
|
||||||
if (meta.hasLore()) {
|
if (meta.hasLore()) {
|
||||||
lore = meta.getLore();
|
lore = meta.lore();
|
||||||
} else {
|
} else {
|
||||||
lore = new ArrayList<>();
|
lore = new ArrayList<>();
|
||||||
}
|
}
|
||||||
// do we add the lore based on the config?
|
|
||||||
if (toolStats.checkConfig(itemStack, "created-date")) {
|
// if creation date is enabled, add it
|
||||||
lore.add(createdOnRaw.replace("{date}", toolStats.numberFormat.formatDate(finalDate)));
|
Component creationDate = toolStats.itemLore.formatCreationTime(timeCreated, 0, newItem);
|
||||||
|
if (creationDate != null) {
|
||||||
|
container.set(toolStats.timeCreated, PersistentDataType.LONG, timeCreated);
|
||||||
|
container.set(toolStats.originType, PersistentDataType.INTEGER, 0);
|
||||||
|
lore.add(creationDate);
|
||||||
|
meta.lore(lore);
|
||||||
}
|
}
|
||||||
if (toolStats.checkConfig(itemStack, "created-by")) {
|
|
||||||
lore.add(createdByRaw.replace("{player}", owner.getName()));
|
// if ownership is enabled, add it
|
||||||
|
Component itemOwner = toolStats.itemLore.formatOwner(owner.getName(), 0, newItem);
|
||||||
|
if (itemOwner != null) {
|
||||||
|
container.set(toolStats.itemOwner, new UUIDDataType(), owner.getUniqueId());
|
||||||
|
container.set(toolStats.originType, PersistentDataType.INTEGER, 0);
|
||||||
|
lore.add(itemOwner);
|
||||||
|
meta.lore(lore);
|
||||||
|
}
|
||||||
|
|
||||||
|
// if hash is enabled, add it
|
||||||
|
if (toolStats.config.getBoolean("generate-hash-for-items")) {
|
||||||
|
String hash = toolStats.hashMaker.makeHash(newItem.getType(), owner.getUniqueId(), timeCreated);
|
||||||
|
container.set(toolStats.hash, PersistentDataType.STRING, hash);
|
||||||
}
|
}
|
||||||
meta.setLore(lore);
|
|
||||||
newItem.setItemMeta(meta);
|
newItem.setItemMeta(meta);
|
||||||
return newItem;
|
return newItem;
|
||||||
}
|
}
|
||||||
|
|||||||
139
src/main/java/lol/hyper/toolstats/events/CreativeEvent.java
Normal file
@@ -0,0 +1,139 @@
|
|||||||
|
/*
|
||||||
|
* This file is part of ToolStats.
|
||||||
|
*
|
||||||
|
* ToolStats is free software: you can redistribute it and/or modify
|
||||||
|
* it under the terms of the GNU General Public License as published by
|
||||||
|
* the Free Software Foundation, either version 3 of the License, or
|
||||||
|
* (at your option) any later version.
|
||||||
|
*
|
||||||
|
* ToolStats is distributed in the hope that it will be useful,
|
||||||
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
* GNU General Public License for more details.
|
||||||
|
*
|
||||||
|
* You should have received a copy of the GNU General Public License
|
||||||
|
* along with ToolStats. If not, see <https://www.gnu.org/licenses/>.
|
||||||
|
*/
|
||||||
|
|
||||||
|
package lol.hyper.toolstats.events;
|
||||||
|
|
||||||
|
import lol.hyper.hyperlib.datatypes.UUIDDataType;
|
||||||
|
import lol.hyper.toolstats.ToolStats;
|
||||||
|
import net.kyori.adventure.text.Component;
|
||||||
|
import org.bukkit.GameMode;
|
||||||
|
import org.bukkit.entity.Player;
|
||||||
|
import org.bukkit.event.EventHandler;
|
||||||
|
import org.bukkit.event.Listener;
|
||||||
|
import org.bukkit.event.inventory.InventoryCreativeEvent;
|
||||||
|
import org.bukkit.inventory.ItemStack;
|
||||||
|
import org.bukkit.inventory.meta.ItemMeta;
|
||||||
|
import org.bukkit.persistence.PersistentDataContainer;
|
||||||
|
import org.bukkit.persistence.PersistentDataType;
|
||||||
|
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.Date;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
public class CreativeEvent implements Listener {
|
||||||
|
|
||||||
|
private final ToolStats toolStats;
|
||||||
|
|
||||||
|
public CreativeEvent(ToolStats toolStats) {
|
||||||
|
this.toolStats = toolStats;
|
||||||
|
}
|
||||||
|
|
||||||
|
@EventHandler
|
||||||
|
public void onCreativeEvent(InventoryCreativeEvent event) {
|
||||||
|
Player player = (Player) event.getWhoClicked();
|
||||||
|
// make sure they are in creative mode
|
||||||
|
if (player.getGameMode() != GameMode.CREATIVE) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
ItemStack spawnedItem = event.getCursor();
|
||||||
|
if (!toolStats.itemChecker.isValidItem(spawnedItem.getType())) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
ItemMeta spawnedItemMeta = spawnedItem.getItemMeta();
|
||||||
|
if (spawnedItemMeta == null) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
// if the item already has an origin set, don't add it again
|
||||||
|
// this is needed since you can spam click an item and the event will fire again
|
||||||
|
PersistentDataContainer container = spawnedItemMeta.getPersistentDataContainer();
|
||||||
|
if (container.has(toolStats.originType, PersistentDataType.INTEGER)) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
// add the tags to the item
|
||||||
|
ItemStack newItem = addCreativeOrigin(spawnedItem, player);
|
||||||
|
if (newItem != null) {
|
||||||
|
event.setCursor(newItem);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Adds spawned in tags to item.
|
||||||
|
*
|
||||||
|
* @param itemStack The item add item to.
|
||||||
|
* @param owner The player spawning in.
|
||||||
|
* @return A copy of the item with the tags + lore.
|
||||||
|
*/
|
||||||
|
private ItemStack addCreativeOrigin(ItemStack itemStack, Player owner) {
|
||||||
|
ItemStack newSpawnedItem = itemStack.clone();
|
||||||
|
ItemMeta meta = newSpawnedItem.getItemMeta();
|
||||||
|
if (meta == null) {
|
||||||
|
toolStats.logger.warn("{} does NOT have any meta! Unable to update stats.", itemStack);
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
// get the current time
|
||||||
|
long timeCreated = System.currentTimeMillis();
|
||||||
|
Date finalDate;
|
||||||
|
if (toolStats.config.getBoolean("normalize-time-creation")) {
|
||||||
|
finalDate = toolStats.numberFormat.normalizeTime(timeCreated);
|
||||||
|
timeCreated = finalDate.getTime();
|
||||||
|
}
|
||||||
|
PersistentDataContainer container = meta.getPersistentDataContainer();
|
||||||
|
|
||||||
|
// if the item already has the tag
|
||||||
|
// this is to prevent duplicate tags
|
||||||
|
if (container.has(toolStats.timeCreated, PersistentDataType.LONG) || container.has(toolStats.itemOwner, PersistentDataType.LONG)) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
// get the current lore the item
|
||||||
|
List<Component> lore;
|
||||||
|
if (meta.hasLore()) {
|
||||||
|
lore = meta.lore();
|
||||||
|
} else {
|
||||||
|
lore = new ArrayList<>();
|
||||||
|
}
|
||||||
|
|
||||||
|
// if creation date is enabled, add it
|
||||||
|
Component creationDate = toolStats.itemLore.formatCreationTime(timeCreated, 6, newSpawnedItem);
|
||||||
|
if (creationDate != null) {
|
||||||
|
container.set(toolStats.timeCreated, PersistentDataType.LONG, timeCreated);
|
||||||
|
container.set(toolStats.originType, PersistentDataType.INTEGER, 6);
|
||||||
|
lore.add(creationDate);
|
||||||
|
meta.lore(lore);
|
||||||
|
}
|
||||||
|
|
||||||
|
// if ownership is enabled, add it
|
||||||
|
Component itemOwner = toolStats.itemLore.formatOwner(owner.getName(), 6, newSpawnedItem);
|
||||||
|
if (itemOwner != null) {
|
||||||
|
container.set(toolStats.itemOwner, new UUIDDataType(), owner.getUniqueId());
|
||||||
|
container.set(toolStats.originType, PersistentDataType.INTEGER, 6);
|
||||||
|
lore.add(itemOwner);
|
||||||
|
meta.lore(lore);
|
||||||
|
}
|
||||||
|
|
||||||
|
// if hash is enabled, add it
|
||||||
|
if (toolStats.config.getBoolean("generate-hash-for-items")) {
|
||||||
|
String hash = toolStats.hashMaker.makeHash(newSpawnedItem.getType(), owner.getUniqueId(), timeCreated);
|
||||||
|
container.set(toolStats.hash, PersistentDataType.STRING, hash);
|
||||||
|
}
|
||||||
|
|
||||||
|
newSpawnedItem.setItemMeta(meta);
|
||||||
|
return newSpawnedItem;
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -18,7 +18,6 @@
|
|||||||
package lol.hyper.toolstats.events;
|
package lol.hyper.toolstats.events;
|
||||||
|
|
||||||
import lol.hyper.toolstats.ToolStats;
|
import lol.hyper.toolstats.ToolStats;
|
||||||
import lol.hyper.toolstats.tools.ItemChecker;
|
|
||||||
import org.bukkit.Bukkit;
|
import org.bukkit.Bukkit;
|
||||||
import org.bukkit.GameMode;
|
import org.bukkit.GameMode;
|
||||||
import org.bukkit.Material;
|
import org.bukkit.Material;
|
||||||
@@ -26,22 +25,21 @@ import org.bukkit.entity.*;
|
|||||||
import org.bukkit.event.EventHandler;
|
import org.bukkit.event.EventHandler;
|
||||||
import org.bukkit.event.EventPriority;
|
import org.bukkit.event.EventPriority;
|
||||||
import org.bukkit.event.Listener;
|
import org.bukkit.event.Listener;
|
||||||
import org.bukkit.event.entity.EntityDamageByBlockEvent;
|
|
||||||
import org.bukkit.event.entity.EntityDamageByEntityEvent;
|
import org.bukkit.event.entity.EntityDamageByEntityEvent;
|
||||||
import org.bukkit.event.entity.EntityDamageEvent;
|
import org.bukkit.event.entity.EntityDamageEvent;
|
||||||
import org.bukkit.inventory.ItemStack;
|
import org.bukkit.inventory.ItemStack;
|
||||||
import org.bukkit.inventory.PlayerInventory;
|
import org.bukkit.inventory.PlayerInventory;
|
||||||
import org.bukkit.inventory.meta.ItemMeta;
|
import org.bukkit.inventory.meta.ItemMeta;
|
||||||
import org.bukkit.persistence.PersistentDataContainer;
|
import org.bukkit.projectiles.ProjectileSource;
|
||||||
import org.bukkit.persistence.PersistentDataType;
|
|
||||||
|
|
||||||
import java.util.*;
|
import java.util.*;
|
||||||
|
|
||||||
public class EntityDamage implements Listener {
|
public class EntityDamage implements Listener {
|
||||||
|
|
||||||
private final ToolStats toolStats;
|
private final ToolStats toolStats;
|
||||||
|
// track mobs that are killed by a player
|
||||||
public final Set<UUID> trackedMobs = new HashSet<>();
|
public final Set<UUID> trackedMobs = new HashSet<>();
|
||||||
private final List<EntityDamageEvent.DamageCause> ignoredCauses = Arrays.asList(EntityDamageEvent.DamageCause.SUICIDE, EntityDamageEvent.DamageCause.VOID, EntityDamageEvent.DamageCause.CUSTOM);
|
private final List<EntityDamageEvent.DamageCause> ignoredCauses = Arrays.asList(EntityDamageEvent.DamageCause.SUICIDE, EntityDamageEvent.DamageCause.VOID, EntityDamageEvent.DamageCause.CUSTOM, EntityDamageEvent.DamageCause.KILL);
|
||||||
|
|
||||||
public EntityDamage(ToolStats toolStats) {
|
public EntityDamage(ToolStats toolStats) {
|
||||||
this.toolStats = toolStats;
|
this.toolStats = toolStats;
|
||||||
@@ -53,10 +51,9 @@ public class EntityDamage implements Listener {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!(event.getEntity() instanceof LivingEntity)) {
|
if (!(event.getEntity() instanceof LivingEntity mobBeingAttacked)) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
LivingEntity mobBeingAttacked = (LivingEntity) event.getEntity();
|
|
||||||
|
|
||||||
// ignore void and /kill damage
|
// ignore void and /kill damage
|
||||||
EntityDamageEvent.DamageCause cause = event.getCause();
|
EntityDamageEvent.DamageCause cause = event.getCause();
|
||||||
@@ -64,106 +61,90 @@ public class EntityDamage implements Listener {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
// mob is going to die
|
Entity damager = event.getDamager();
|
||||||
if (mobBeingAttacked.getHealth() - event.getFinalDamage() <= 0) {
|
boolean playerAttacking = damager instanceof Player;
|
||||||
// a player is killing something
|
boolean playerBeingAttacked = mobBeingAttacked instanceof Player;
|
||||||
if (event.getDamager() instanceof Player) {
|
double finalDamage = event.getFinalDamage();
|
||||||
Player attackingPlayer = (Player) event.getDamager();
|
boolean modDied = mobBeingAttacked.getHealth() - finalDamage <= 0;
|
||||||
if (attackingPlayer.getGameMode() == GameMode.CREATIVE || attackingPlayer.getGameMode() == GameMode.SPECTATOR) {
|
|
||||||
|
// player attacks something
|
||||||
|
if (playerAttacking) {
|
||||||
|
PlayerInventory playerAttackingInventory = ((Player) damager).getInventory();
|
||||||
|
// make sure the item the player used is an item we want
|
||||||
|
if (!toolStats.itemChecker.isMeleeWeapon(playerAttackingInventory.getItemInMainHand().getType())) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
PlayerInventory attackingPlayerInventory = attackingPlayer.getInventory();
|
|
||||||
ItemStack heldItem = attackingPlayerInventory.getItemInMainHand();
|
// update their weapon's damage
|
||||||
// only check certain items
|
updateWeaponDamage(playerAttackingInventory, event.getFinalDamage());
|
||||||
if (!ItemChecker.isMeleeWeapon(heldItem.getType())) {
|
|
||||||
return;
|
// the mob the player attacked died
|
||||||
}
|
if (modDied) {
|
||||||
// a player is killing another player
|
// player killed another player
|
||||||
if (mobBeingAttacked instanceof Player) {
|
if (playerBeingAttacked) {
|
||||||
updatePlayerKills(heldItem);
|
updateWeaponKills(playerAttackingInventory, "player");
|
||||||
return;
|
|
||||||
}
|
|
||||||
// player is killing regular mob
|
|
||||||
updateMobKills(heldItem);
|
|
||||||
trackedMobs.add(mobBeingAttacked.getUniqueId());
|
|
||||||
}
|
|
||||||
// trident is being thrown at something
|
|
||||||
if (event.getDamager() instanceof Trident) {
|
|
||||||
Trident trident = (Trident) event.getDamager();
|
|
||||||
ItemStack newTrident;
|
|
||||||
// trident is killing player
|
|
||||||
if (mobBeingAttacked instanceof Player) {
|
|
||||||
newTrident = tridentPlayerKills(trident.getItem());
|
|
||||||
} else {
|
} else {
|
||||||
// trident is killing a mob
|
// player kills a regular mob
|
||||||
newTrident = tridentMobKills(trident.getItem());
|
updateWeaponKills(playerAttackingInventory, "mob");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
trackedMobs.add(mobBeingAttacked.getUniqueId());
|
trackedMobs.add(mobBeingAttacked.getUniqueId());
|
||||||
}
|
Bukkit.getGlobalRegionScheduler().runDelayed(toolStats, scheduledTask -> trackedMobs.remove(mobBeingAttacked.getUniqueId()), 20);
|
||||||
if (newTrident != null) {
|
|
||||||
trident.setItem(newTrident);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
// arrow is being shot
|
|
||||||
if (event.getDamager() instanceof Arrow) {
|
|
||||||
Arrow arrow = (Arrow) event.getDamager();
|
|
||||||
// if the shooter is a player
|
|
||||||
if (arrow.getShooter() instanceof Player) {
|
|
||||||
Player shootingPlayer = (Player) arrow.getShooter();
|
|
||||||
if (shootingPlayer.getGameMode() == GameMode.CREATIVE || shootingPlayer.getGameMode() == GameMode.SPECTATOR) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
PlayerInventory inventory = shootingPlayer.getInventory();
|
|
||||||
boolean isMainHand = inventory.getItemInMainHand().getType() == Material.BOW || inventory.getItemInMainHand().getType() == Material.CROSSBOW;
|
|
||||||
boolean isOffHand = inventory.getItemInOffHand().getType() == Material.BOW || inventory.getItemInMainHand().getType() == Material.CROSSBOW;
|
|
||||||
ItemStack heldBow = null;
|
|
||||||
if (isMainHand) {
|
|
||||||
heldBow = inventory.getItemInMainHand();
|
|
||||||
}
|
|
||||||
if (isOffHand) {
|
|
||||||
heldBow = inventory.getItemInOffHand();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// if the player is hold a bow in both hands
|
// something was hit by a trident
|
||||||
// default to main hand since that takes priority
|
if (damager instanceof Trident trident) {
|
||||||
if (isMainHand && isOffHand) {
|
ProjectileSource source = trident.getShooter();
|
||||||
heldBow = inventory.getItemInMainHand();
|
if (source instanceof Player) {
|
||||||
}
|
// update the trident's tracked damage
|
||||||
|
updateTridentDamage(trident, finalDamage);
|
||||||
|
|
||||||
// player swapped
|
// if the mob died from the trident
|
||||||
if (heldBow == null) {
|
if (modDied) {
|
||||||
return;
|
// if the trident killed a player, update the kills
|
||||||
}
|
if (playerBeingAttacked) {
|
||||||
|
updateTridentKills(trident, "player");
|
||||||
// player is shooting another player
|
|
||||||
if (mobBeingAttacked instanceof Player) {
|
|
||||||
updatePlayerKills(heldBow);
|
|
||||||
} else {
|
} else {
|
||||||
updateMobKills(heldBow);
|
// the trident killed a mob, update the kills
|
||||||
|
updateTridentKills(trident, "mob");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
trackedMobs.add(mobBeingAttacked.getUniqueId());
|
trackedMobs.add(mobBeingAttacked.getUniqueId());
|
||||||
|
Bukkit.getGlobalRegionScheduler().runDelayed(toolStats, scheduledTask -> trackedMobs.remove(mobBeingAttacked.getUniqueId()), 20);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// something was hit by an arrow
|
||||||
|
if (damager instanceof Arrow arrow) {
|
||||||
|
ProjectileSource source = arrow.getShooter();
|
||||||
|
|
||||||
|
// a player shot the arrow
|
||||||
|
if (source instanceof Player shootingPlayer) {
|
||||||
|
// update the player's bow damage
|
||||||
|
updateBowDamage(shootingPlayer.getInventory(), finalDamage);
|
||||||
|
|
||||||
|
// if the mob died from the arrow
|
||||||
|
if (modDied) {
|
||||||
|
if (playerBeingAttacked) {
|
||||||
|
// player killed another player with an arrow
|
||||||
|
updateBowKills(shootingPlayer.getInventory(), "player");
|
||||||
|
} else {
|
||||||
|
// player killed mob with an arrow
|
||||||
|
updateBowKills(shootingPlayer.getInventory(), "mob");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
// player is taken damage but not being killed
|
|
||||||
if (mobBeingAttacked instanceof Player) {
|
trackedMobs.add(mobBeingAttacked.getUniqueId());
|
||||||
Player playerTakingDamage = (Player) mobBeingAttacked;
|
Bukkit.getGlobalRegionScheduler().runDelayed(toolStats, scheduledTask -> trackedMobs.remove(mobBeingAttacked.getUniqueId()), 20);
|
||||||
if (playerTakingDamage.getGameMode() == GameMode.CREATIVE || playerTakingDamage.getGameMode() == GameMode.SPECTATOR) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
PlayerInventory playerInventory = playerTakingDamage.getInventory();
|
|
||||||
for (ItemStack armorPiece : playerInventory.getArmorContents()) {
|
|
||||||
if (armorPiece != null) {
|
|
||||||
if (ItemChecker.isArmor(armorPiece.getType())) {
|
|
||||||
updateDamage(armorPiece, event.getFinalDamage());
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@EventHandler(priority = EventPriority.MONITOR)
|
@EventHandler(priority = EventPriority.MONITOR)
|
||||||
public void onDamage(EntityDamageEvent event) {
|
public void onDamage(EntityDamageEvent event) {
|
||||||
if (!(event.getEntity() instanceof LivingEntity)) {
|
if (!(event.getEntity() instanceof LivingEntity mobBeingAttacked)) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -173,231 +154,133 @@ public class EntityDamage implements Listener {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
LivingEntity mobBeingAttacked = (LivingEntity) event.getEntity();
|
// player is taking damage
|
||||||
// player is taken damage but not being killed
|
if (mobBeingAttacked instanceof Player playerTakingDamage) {
|
||||||
if (mobBeingAttacked instanceof Player) {
|
if (playerTakingDamage.getGameMode() == GameMode.CREATIVE && !toolStats.config.getBoolean("allow-creative")) {
|
||||||
Player playerTakingDamage = (Player) mobBeingAttacked;
|
|
||||||
if (playerTakingDamage.getGameMode() == GameMode.CREATIVE || playerTakingDamage.getGameMode() == GameMode.SPECTATOR) {
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
PlayerInventory playerInventory = playerTakingDamage.getInventory();
|
updateArmorDamage(playerTakingDamage.getInventory(), event.getFinalDamage());
|
||||||
for (ItemStack armorPiece : playerInventory.getArmorContents()) {
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private void updateArmorDamage(PlayerInventory playerInventory, double damage) {
|
||||||
|
ItemStack[] armorContents = playerInventory.getArmorContents();
|
||||||
|
for (ItemStack armorPiece : armorContents) {
|
||||||
if (armorPiece != null) {
|
if (armorPiece != null) {
|
||||||
if (ItemChecker.isArmor(armorPiece.getType())) {
|
if (toolStats.itemChecker.isArmor(armorPiece.getType())) {
|
||||||
updateDamage(armorPiece, event.getFinalDamage());
|
ItemMeta newItem = toolStats.itemLore.updateArmorDamage(armorPiece, damage, false);
|
||||||
|
if (newItem != null) {
|
||||||
|
armorPiece.setItemMeta(newItem);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
// apply the new armor
|
||||||
|
playerInventory.setArmorContents(armorContents);
|
||||||
}
|
}
|
||||||
|
|
||||||
@EventHandler(priority = EventPriority.MONITOR)
|
private void updateBowDamage(PlayerInventory playerInventory, double damage) {
|
||||||
public void onDamage(EntityDamageByBlockEvent event) {
|
ItemStack heldBow = toolStats.itemChecker.getBow(playerInventory);
|
||||||
if (!(event.getEntity() instanceof LivingEntity)) {
|
if (heldBow == null) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
// ignore void and /kill damage
|
boolean isMain = playerInventory.getItemInMainHand().getType() == Material.BOW || playerInventory.getItemInMainHand().getType() == Material.CROSSBOW;
|
||||||
EntityDamageEvent.DamageCause cause = event.getCause();
|
boolean isOffHand = playerInventory.getItemInOffHand().getType() == Material.BOW || playerInventory.getItemInOffHand().getType() == Material.CROSSBOW;
|
||||||
if (ignoredCauses.contains(cause)) {
|
ItemMeta newBowDamage = toolStats.itemLore.updateWeaponDamage(heldBow, damage, false);
|
||||||
|
//toolStats.logger.info(newBowDamage.toString());
|
||||||
|
|
||||||
|
// player is shooting another player
|
||||||
|
if (newBowDamage != null) {
|
||||||
|
if (isMain && isOffHand) {
|
||||||
|
playerInventory.getItemInMainHand().setItemMeta(newBowDamage);
|
||||||
|
} else if (isMain) {
|
||||||
|
playerInventory.getItemInMainHand().setItemMeta(newBowDamage);
|
||||||
|
} else if (isOffHand) {
|
||||||
|
playerInventory.getItemInOffHand().setItemMeta(newBowDamage);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private void updateBowKills(PlayerInventory playerInventory, String type) {
|
||||||
|
ItemStack heldBow = toolStats.itemChecker.getBow(playerInventory);
|
||||||
|
if (heldBow == null) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
LivingEntity mobBeingAttacked = (LivingEntity) event.getEntity();
|
boolean isMain = playerInventory.getItemInMainHand().getType() == Material.BOW || playerInventory.getItemInMainHand().getType() == Material.CROSSBOW;
|
||||||
// player is taken damage but not being killed
|
boolean isOffHand = playerInventory.getItemInOffHand().getType() == Material.BOW || playerInventory.getItemInOffHand().getType() == Material.CROSSBOW;
|
||||||
if (mobBeingAttacked instanceof Player) {
|
|
||||||
Player playerTakingDamage = (Player) mobBeingAttacked;
|
if (type.equalsIgnoreCase("mob")) {
|
||||||
if (playerTakingDamage.getGameMode() == GameMode.CREATIVE || playerTakingDamage.getGameMode() == GameMode.SPECTATOR) {
|
// player is shooting a mob
|
||||||
return;
|
ItemMeta newBow = toolStats.itemLore.updateMobKills(heldBow, 1);
|
||||||
|
if (newBow != null) {
|
||||||
|
if (isMain && isOffHand) {
|
||||||
|
playerInventory.getItemInMainHand().setItemMeta(newBow);
|
||||||
|
} else if (isMain) {
|
||||||
|
playerInventory.getItemInMainHand().setItemMeta(newBow);
|
||||||
|
} else if (isOffHand) {
|
||||||
|
playerInventory.getItemInOffHand().setItemMeta(newBow);
|
||||||
}
|
}
|
||||||
PlayerInventory playerInventory = playerTakingDamage.getInventory();
|
|
||||||
for (ItemStack armorPiece : playerInventory.getArmorContents()) {
|
|
||||||
if (armorPiece != null) {
|
|
||||||
if (ItemChecker.isArmor(armorPiece.getType())) {
|
|
||||||
updateDamage(armorPiece, event.getFinalDamage());
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (type.equalsIgnoreCase("player")) {
|
||||||
|
ItemMeta newBowKills = toolStats.itemLore.updatePlayerKills(heldBow, 1);
|
||||||
|
if (newBowKills != null) {
|
||||||
|
if (isMain && isOffHand) {
|
||||||
|
playerInventory.getItemInMainHand().setItemMeta(newBowKills);
|
||||||
|
} else if (isMain) {
|
||||||
|
playerInventory.getItemInMainHand().setItemMeta(newBowKills);
|
||||||
|
} else if (isOffHand) {
|
||||||
|
playerInventory.getItemInOffHand().setItemMeta(newBowKills);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
private void updateTridentKills(Trident trident, String type) {
|
||||||
* Updates a weapon's player kills.
|
ItemStack newTrident = trident.getItemStack();
|
||||||
*
|
ItemMeta newKills;
|
||||||
* @param itemStack The item to update.
|
if (type.equalsIgnoreCase("player")) {
|
||||||
*/
|
newKills = toolStats.itemLore.updatePlayerKills(trident.getItemStack(), 1);
|
||||||
private void updatePlayerKills(ItemStack itemStack) {
|
} else {
|
||||||
ItemMeta meta = itemStack.getItemMeta();
|
newKills = toolStats.itemLore.updateMobKills(trident.getItemStack(), 1);
|
||||||
if (meta == null) {
|
}
|
||||||
toolStats.logger.warning(itemStack + " does NOT have any meta! Unable to update stats.");
|
if (newKills != null) {
|
||||||
return;
|
newTrident.setItemMeta(newKills);
|
||||||
|
trident.setItemStack(newTrident);
|
||||||
}
|
}
|
||||||
Integer playerKills = 0;
|
|
||||||
PersistentDataContainer container = meta.getPersistentDataContainer();
|
|
||||||
if (container.has(toolStats.swordPlayerKills, PersistentDataType.INTEGER)) {
|
|
||||||
playerKills = container.get(toolStats.swordPlayerKills, PersistentDataType.INTEGER);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (playerKills == null) {
|
private void updateTridentDamage(Trident trident, double damage) {
|
||||||
playerKills = 0;
|
ItemStack newTrident = trident.getItemStack();
|
||||||
toolStats.logger.warning(itemStack + " does not have valid player-kills set! Resting to zero. This should NEVER happen.");
|
ItemMeta newDamage = toolStats.itemLore.updateWeaponDamage(trident.getItemStack(), damage, false);
|
||||||
|
if (newDamage != null) {
|
||||||
|
newTrident.setItemMeta(newDamage);
|
||||||
|
trident.setItemStack(newTrident);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
playerKills++;
|
private void updateWeaponDamage(PlayerInventory playerInventory, double damage) {
|
||||||
container.set(toolStats.swordPlayerKills, PersistentDataType.INTEGER, playerKills);
|
ItemStack heldWeapon = playerInventory.getItemInMainHand();
|
||||||
|
ItemMeta newHeldWeaponMeta = toolStats.itemLore.updateWeaponDamage(heldWeapon, damage, false);
|
||||||
String playerKillsFormatted = toolStats.numberFormat.formatInt(playerKills);
|
if (newHeldWeaponMeta != null) {
|
||||||
List<String> newLore = toolStats.itemLore.addItemLore(meta, "{kills}", playerKillsFormatted, "kills.player");
|
playerInventory.getItemInMainHand().setItemMeta(newHeldWeaponMeta);
|
||||||
|
|
||||||
// do we add the lore based on the config?
|
|
||||||
if (toolStats.checkConfig(itemStack, "player-kills")) {
|
|
||||||
meta.setLore(newLore);
|
|
||||||
}
|
}
|
||||||
itemStack.setItemMeta(meta);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
private void updateWeaponKills(PlayerInventory playerInventory, String type) {
|
||||||
* Updates a weapon's mob kills.
|
ItemStack heldWeapon = playerInventory.getItemInMainHand();
|
||||||
*
|
ItemMeta newHeldWeaponMeta = null;
|
||||||
* @param itemStack The item to update.
|
if (type.equalsIgnoreCase("player")) {
|
||||||
*/
|
newHeldWeaponMeta = toolStats.itemLore.updatePlayerKills(heldWeapon, 1);
|
||||||
private void updateMobKills(ItemStack itemStack) {
|
|
||||||
ItemMeta meta = itemStack.getItemMeta();
|
|
||||||
if (meta == null) {
|
|
||||||
toolStats.logger.warning(itemStack + " does NOT have any meta! Unable to update stats.");
|
|
||||||
return;
|
|
||||||
}
|
}
|
||||||
Integer mobKills = 0;
|
if (type.equalsIgnoreCase("mob")) {
|
||||||
PersistentDataContainer container = meta.getPersistentDataContainer();
|
newHeldWeaponMeta = toolStats.itemLore.updateMobKills(heldWeapon, 1);
|
||||||
if (container.has(toolStats.swordMobKills, PersistentDataType.INTEGER)) {
|
|
||||||
mobKills = container.get(toolStats.swordMobKills, PersistentDataType.INTEGER);
|
|
||||||
}
|
}
|
||||||
|
if (newHeldWeaponMeta != null) {
|
||||||
if (mobKills == null) {
|
playerInventory.getItemInMainHand().setItemMeta(newHeldWeaponMeta);
|
||||||
mobKills = 0;
|
|
||||||
toolStats.logger.warning(itemStack + " does not have valid mob-kills set! Resting to zero. This should NEVER happen.");
|
|
||||||
}
|
}
|
||||||
|
|
||||||
mobKills++;
|
|
||||||
container.set(toolStats.swordMobKills, PersistentDataType.INTEGER, mobKills);
|
|
||||||
|
|
||||||
String mobKillsFormatted = toolStats.numberFormat.formatInt(mobKills);
|
|
||||||
List<String> newLore = toolStats.itemLore.addItemLore(meta, "{kills}", mobKillsFormatted, "kills.mob");
|
|
||||||
|
|
||||||
// do we add the lore based on the config?
|
|
||||||
if (toolStats.checkConfig(itemStack, "mob-kills")) {
|
|
||||||
meta.setLore(newLore);
|
|
||||||
}
|
|
||||||
itemStack.setItemMeta(meta);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Updates a player's armor damage stats.
|
|
||||||
*
|
|
||||||
* @param itemStack The armor piece.
|
|
||||||
* @param damage How much damage is being added.
|
|
||||||
*/
|
|
||||||
private void updateDamage(ItemStack itemStack, double damage) {
|
|
||||||
ItemMeta meta = itemStack.getItemMeta();
|
|
||||||
if (meta == null) {
|
|
||||||
toolStats.logger.warning(itemStack + " does NOT have any meta! Unable to update stats.");
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
Double damageTaken = 0.0;
|
|
||||||
PersistentDataContainer container = meta.getPersistentDataContainer();
|
|
||||||
if (container.has(toolStats.armorDamage, PersistentDataType.DOUBLE)) {
|
|
||||||
damageTaken = container.get(toolStats.armorDamage, PersistentDataType.DOUBLE);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (damageTaken == null) {
|
|
||||||
damageTaken = 0.0;
|
|
||||||
toolStats.logger.warning(itemStack + " does not have valid damage-taken set! Resting to zero. This should NEVER happen.");
|
|
||||||
}
|
|
||||||
|
|
||||||
damageTaken = damageTaken + damage;
|
|
||||||
container.set(toolStats.armorDamage, PersistentDataType.DOUBLE, damageTaken);
|
|
||||||
container.set(toolStats.armorDamageInt, PersistentDataType.INTEGER, damageTaken.intValue());
|
|
||||||
|
|
||||||
String damageTakenFormatted = toolStats.numberFormat.formatDouble(damageTaken);
|
|
||||||
List<String> newLore = toolStats.itemLore.addItemLore(meta, "{damage}", damageTakenFormatted, "damage-taken");
|
|
||||||
|
|
||||||
if (toolStats.config.getBoolean("enabled.armor-damage")) {
|
|
||||||
meta.setLore(newLore);
|
|
||||||
}
|
|
||||||
itemStack.setItemMeta(meta);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Updates a trident's mob kills.
|
|
||||||
*
|
|
||||||
* @param trident The item to update.
|
|
||||||
*/
|
|
||||||
private ItemStack tridentMobKills(ItemStack trident) {
|
|
||||||
ItemStack newTrident = trident.clone();
|
|
||||||
ItemMeta meta = newTrident.getItemMeta();
|
|
||||||
if (meta == null) {
|
|
||||||
toolStats.logger.warning(newTrident + " does NOT have any meta! Unable to update stats.");
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
Integer mobKills = 0;
|
|
||||||
PersistentDataContainer container = meta.getPersistentDataContainer();
|
|
||||||
if (container.has(toolStats.swordMobKills, PersistentDataType.INTEGER)) {
|
|
||||||
mobKills = container.get(toolStats.swordMobKills, PersistentDataType.INTEGER);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (mobKills == null) {
|
|
||||||
mobKills = 0;
|
|
||||||
toolStats.logger.warning(newTrident + " does not have valid mob-kills set! Resting to zero. This should NEVER happen.");
|
|
||||||
}
|
|
||||||
|
|
||||||
mobKills++;
|
|
||||||
container.set(toolStats.swordMobKills, PersistentDataType.INTEGER, mobKills);
|
|
||||||
|
|
||||||
String mobKillsFormatted = toolStats.numberFormat.formatInt(mobKills);
|
|
||||||
List<String> newLore = toolStats.itemLore.addItemLore(meta, "{kills}", mobKillsFormatted, "kills.mob");
|
|
||||||
|
|
||||||
// do we add the lore based on the config?
|
|
||||||
if (toolStats.checkConfig(newTrident, "mob-kills")) {
|
|
||||||
meta.setLore(newLore);
|
|
||||||
}
|
|
||||||
newTrident.setItemMeta(meta);
|
|
||||||
return newTrident;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Updates a trident's player kills.
|
|
||||||
*
|
|
||||||
* @param trident The item to update.
|
|
||||||
*/
|
|
||||||
private ItemStack tridentPlayerKills(ItemStack trident) {
|
|
||||||
ItemStack newTrident = trident.clone();
|
|
||||||
ItemMeta meta = newTrident.getItemMeta();
|
|
||||||
if (meta == null) {
|
|
||||||
toolStats.logger.warning(newTrident + " does NOT have any meta! Unable to update stats.");
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
Integer playerKills = 0;
|
|
||||||
PersistentDataContainer container = meta.getPersistentDataContainer();
|
|
||||||
if (container.has(toolStats.swordPlayerKills, PersistentDataType.INTEGER)) {
|
|
||||||
playerKills = container.get(toolStats.swordPlayerKills, PersistentDataType.INTEGER);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (playerKills == null) {
|
|
||||||
playerKills = 0;
|
|
||||||
toolStats.logger.warning(newTrident + " does not have valid player-kills set! Resting to zero. This should NEVER happen.");
|
|
||||||
}
|
|
||||||
|
|
||||||
playerKills++;
|
|
||||||
container.set(toolStats.swordPlayerKills, PersistentDataType.INTEGER, playerKills);
|
|
||||||
|
|
||||||
String playerKillsFormatted = toolStats.numberFormat.formatInt(playerKills);
|
|
||||||
List<String> newLore = toolStats.itemLore.addItemLore(meta, "{kills}", playerKillsFormatted, "kills.player");
|
|
||||||
|
|
||||||
// do we add the lore based on the config?
|
|
||||||
if (toolStats.checkConfig(newTrident, "player-kills")) {
|
|
||||||
meta.setLore(newLore);
|
|
||||||
}
|
|
||||||
newTrident.setItemMeta(meta);
|
|
||||||
return newTrident;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -18,7 +18,7 @@
|
|||||||
package lol.hyper.toolstats.events;
|
package lol.hyper.toolstats.events;
|
||||||
|
|
||||||
import lol.hyper.toolstats.ToolStats;
|
import lol.hyper.toolstats.ToolStats;
|
||||||
import lol.hyper.toolstats.tools.ItemChecker;
|
import net.kyori.adventure.text.Component;
|
||||||
import org.bukkit.entity.LivingEntity;
|
import org.bukkit.entity.LivingEntity;
|
||||||
import org.bukkit.entity.Player;
|
import org.bukkit.entity.Player;
|
||||||
import org.bukkit.event.EventHandler;
|
import org.bukkit.event.EventHandler;
|
||||||
@@ -30,7 +30,10 @@ import org.bukkit.inventory.meta.ItemMeta;
|
|||||||
import org.bukkit.persistence.PersistentDataContainer;
|
import org.bukkit.persistence.PersistentDataContainer;
|
||||||
import org.bukkit.persistence.PersistentDataType;
|
import org.bukkit.persistence.PersistentDataType;
|
||||||
|
|
||||||
import java.util.*;
|
import java.util.ArrayList;
|
||||||
|
import java.util.Date;
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.UUID;
|
||||||
|
|
||||||
public class EntityDeath implements Listener {
|
public class EntityDeath implements Listener {
|
||||||
|
|
||||||
@@ -54,13 +57,13 @@ public class EntityDeath implements Listener {
|
|||||||
ItemMeta droppedItemMeta = droppedItem.getItemMeta();
|
ItemMeta droppedItemMeta = droppedItem.getItemMeta();
|
||||||
if (droppedItemMeta != null) {
|
if (droppedItemMeta != null) {
|
||||||
PersistentDataContainer container = droppedItemMeta.getPersistentDataContainer();
|
PersistentDataContainer container = droppedItemMeta.getPersistentDataContainer();
|
||||||
if (container.has(toolStats.timeCreated, PersistentDataType.LONG)) {
|
if (container.has(toolStats.originType, PersistentDataType.INTEGER)) {
|
||||||
continue; // ignore any items that have our tags
|
continue; // ignore any items that have our tags
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
if (ItemChecker.isValidItem(droppedItem.getType())) {
|
if (toolStats.itemChecker.isValidItem(droppedItem.getType())) {
|
||||||
ItemStack newItem = addLore(droppedItem, livingEntity.getName());
|
ItemStack newItem = addLore(droppedItem, livingEntity);
|
||||||
if (newItem != null) {
|
if (newItem != null) {
|
||||||
event.getDrops().set(i, newItem);
|
event.getDrops().set(i, newItem);
|
||||||
}
|
}
|
||||||
@@ -74,20 +77,52 @@ public class EntityDeath implements Listener {
|
|||||||
* Adds "drop by" tag to item.
|
* Adds "drop by" tag to item.
|
||||||
*
|
*
|
||||||
* @param oldItem The item to add lore to.
|
* @param oldItem The item to add lore to.
|
||||||
* @param mob The mob or player name.
|
* @param entity The mob dying.
|
||||||
*/
|
*/
|
||||||
private ItemStack addLore(ItemStack oldItem, String mob) {
|
private ItemStack addLore(ItemStack oldItem, LivingEntity entity) {
|
||||||
ItemStack newItem = oldItem.clone();
|
ItemStack newItem = oldItem.clone();
|
||||||
ItemMeta meta = newItem.getItemMeta();
|
ItemMeta meta = newItem.getItemMeta();
|
||||||
if (meta == null) {
|
if (meta == null) {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
List<String> newLore = toolStats.itemLore.addItemLore(meta, "{name}", mob, "dropped-by");
|
long timeCreated = System.currentTimeMillis();
|
||||||
|
Date finalDate;
|
||||||
|
if (toolStats.config.getBoolean("normalize-time-creation")) {
|
||||||
|
finalDate = toolStats.numberFormat.normalizeTime(timeCreated);
|
||||||
|
timeCreated = finalDate.getTime();
|
||||||
|
}
|
||||||
|
|
||||||
|
PersistentDataContainer container = meta.getPersistentDataContainer();
|
||||||
|
String mobName = toolStats.config.getString("messages.mob." + entity.getType());
|
||||||
|
if (mobName == null) {
|
||||||
|
mobName = entity.getName();
|
||||||
|
}
|
||||||
|
|
||||||
|
List<Component> lore;
|
||||||
|
if (meta.hasLore()) {
|
||||||
|
lore = meta.lore();
|
||||||
|
} else {
|
||||||
|
lore = new ArrayList<>();
|
||||||
|
}
|
||||||
|
|
||||||
|
// if creation date is enabled, add it
|
||||||
|
Component creationDate = toolStats.itemLore.formatCreationTime(timeCreated, 1, newItem);
|
||||||
|
if (creationDate != null) {
|
||||||
|
container.set(toolStats.timeCreated, PersistentDataType.LONG, timeCreated);
|
||||||
|
container.set(toolStats.originType, PersistentDataType.INTEGER, 1);
|
||||||
|
lore.add(creationDate);
|
||||||
|
meta.lore(lore);
|
||||||
|
}
|
||||||
|
|
||||||
if (toolStats.config.getBoolean("enabled.dropped-by")) {
|
if (toolStats.config.getBoolean("enabled.dropped-by")) {
|
||||||
meta.setLore(newLore);
|
container.set(toolStats.originType, PersistentDataType.INTEGER, 1);
|
||||||
|
container.set(toolStats.droppedBy, PersistentDataType.STRING, mobName);
|
||||||
|
Component droppedBy = toolStats.configTools.formatLore("dropped-by", "{name}", mobName);
|
||||||
|
lore.add(droppedBy);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
meta.lore(lore);
|
||||||
newItem.setItemMeta(meta);
|
newItem.setItemMeta(meta);
|
||||||
return newItem;
|
return newItem;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -17,10 +17,9 @@
|
|||||||
|
|
||||||
package lol.hyper.toolstats.events;
|
package lol.hyper.toolstats.events;
|
||||||
|
|
||||||
|
import lol.hyper.hyperlib.datatypes.UUIDDataType;
|
||||||
import lol.hyper.toolstats.ToolStats;
|
import lol.hyper.toolstats.ToolStats;
|
||||||
import lol.hyper.toolstats.tools.ItemChecker;
|
import net.kyori.adventure.text.Component;
|
||||||
import lol.hyper.toolstats.tools.UUIDDataType;
|
|
||||||
import org.bukkit.Bukkit;
|
|
||||||
import org.bukkit.Location;
|
import org.bukkit.Location;
|
||||||
import org.bukkit.Material;
|
import org.bukkit.Material;
|
||||||
import org.bukkit.block.Block;
|
import org.bukkit.block.Block;
|
||||||
@@ -31,13 +30,13 @@ import org.bukkit.event.EventHandler;
|
|||||||
import org.bukkit.event.EventPriority;
|
import org.bukkit.event.EventPriority;
|
||||||
import org.bukkit.event.Listener;
|
import org.bukkit.event.Listener;
|
||||||
import org.bukkit.event.world.LootGenerateEvent;
|
import org.bukkit.event.world.LootGenerateEvent;
|
||||||
import org.bukkit.inventory.Inventory;
|
|
||||||
import org.bukkit.inventory.InventoryHolder;
|
import org.bukkit.inventory.InventoryHolder;
|
||||||
import org.bukkit.inventory.ItemStack;
|
import org.bukkit.inventory.ItemStack;
|
||||||
import org.bukkit.inventory.meta.ItemMeta;
|
import org.bukkit.inventory.meta.ItemMeta;
|
||||||
import org.bukkit.persistence.PersistentDataContainer;
|
import org.bukkit.persistence.PersistentDataContainer;
|
||||||
import org.bukkit.persistence.PersistentDataType;
|
import org.bukkit.persistence.PersistentDataType;
|
||||||
|
|
||||||
|
import java.util.ArrayList;
|
||||||
import java.util.Date;
|
import java.util.Date;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
@@ -56,12 +55,11 @@ public class GenerateLoot implements Listener {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
Location lootLocation = event.getLootContext().getLocation();
|
Location lootLocation = event.getLootContext().getLocation();
|
||||||
Inventory chestInv = inventoryHolder.getInventory();
|
|
||||||
|
|
||||||
if (inventoryHolder instanceof Chest) {
|
if (inventoryHolder instanceof Chest) {
|
||||||
Block openedChest = null;
|
Block openedChest = null;
|
||||||
// look at the current list of opened chest and get the distance
|
// look at the current list of opened chest and get the distance
|
||||||
// between the lootcontext location and chest location
|
// between the LootContext location and chest location
|
||||||
// if the distance is less than 1, it's the same chest
|
// if the distance is less than 1, it's the same chest
|
||||||
for (Block chest : toolStats.playerInteract.openedChests.keySet()) {
|
for (Block chest : toolStats.playerInteract.openedChests.keySet()) {
|
||||||
Location chestLocation = chest.getLocation();
|
Location chestLocation = chest.getLocation();
|
||||||
@@ -77,45 +75,13 @@ public class GenerateLoot implements Listener {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
// run task later since if it runs on the same tick it breaks idk
|
Player player = toolStats.playerInteract.openedChests.get(openedChest);
|
||||||
Block finalOpenedChest = openedChest;
|
setLoot(event.getLoot(), player);
|
||||||
Bukkit.getScheduler().runTaskLater(toolStats, () -> {
|
|
||||||
Player player = toolStats.playerInteract.openedChests.get(finalOpenedChest);
|
|
||||||
// do a classic for loop, so we keep track of chest index of item
|
|
||||||
for (int i = 0; i < chestInv.getContents().length; i++) {
|
|
||||||
ItemStack itemStack = chestInv.getItem(i);
|
|
||||||
// ignore air
|
|
||||||
if (itemStack == null || itemStack.getType() == Material.AIR) {
|
|
||||||
continue;
|
|
||||||
}
|
}
|
||||||
if (ItemChecker.isValidItem(itemStack.getType())) {
|
if (inventoryHolder instanceof StorageMinecart mineCart) {
|
||||||
ItemStack newItem = addLore(itemStack, player);
|
|
||||||
if (newItem != null) {
|
|
||||||
chestInv.setItem(i, newItem);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
}, 1);
|
|
||||||
}
|
|
||||||
if (inventoryHolder instanceof StorageMinecart) {
|
|
||||||
StorageMinecart mineCart = (StorageMinecart) inventoryHolder;
|
|
||||||
if (toolStats.playerInteract.openedMineCarts.containsKey(mineCart)) {
|
if (toolStats.playerInteract.openedMineCarts.containsKey(mineCart)) {
|
||||||
Player player = toolStats.playerInteract.openedMineCarts.get(mineCart);
|
Player player = toolStats.playerInteract.openedMineCarts.get(mineCart);
|
||||||
// player clicked this minecart
|
setLoot(event.getLoot(), player);
|
||||||
for (int i = 0; i < chestInv.getContents().length; i++) {
|
|
||||||
ItemStack itemStack = chestInv.getItem(i);
|
|
||||||
// ignore air
|
|
||||||
if (itemStack == null || itemStack.getType() == Material.AIR) {
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
if (ItemChecker.isValidItem(itemStack.getType())) {
|
|
||||||
ItemStack newItem = addLore(itemStack, player);
|
|
||||||
if (newItem != null) {
|
|
||||||
chestInv.setItem(i, newItem);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -127,30 +93,79 @@ public class GenerateLoot implements Listener {
|
|||||||
* @param owner The player that found the item.
|
* @param owner The player that found the item.
|
||||||
* @return The item with the lore.
|
* @return The item with the lore.
|
||||||
*/
|
*/
|
||||||
private ItemStack addLore(ItemStack itemStack, Player owner) {
|
private ItemStack addLootedOrigin(ItemStack itemStack, Player owner) {
|
||||||
ItemStack newItem = itemStack.clone();
|
ItemStack newItem = itemStack.clone();
|
||||||
ItemMeta meta = itemStack.getItemMeta();
|
ItemMeta meta = itemStack.getItemMeta();
|
||||||
if (meta == null) {
|
if (meta == null) {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
long timeCreated = System.currentTimeMillis();
|
long timeCreated = System.currentTimeMillis();
|
||||||
Date finalDate = new Date(timeCreated);
|
Date finalDate;
|
||||||
|
if (toolStats.config.getBoolean("normalize-time-creation")) {
|
||||||
|
finalDate = toolStats.numberFormat.normalizeTime(timeCreated);
|
||||||
|
timeCreated = finalDate.getTime();
|
||||||
|
}
|
||||||
PersistentDataContainer container = meta.getPersistentDataContainer();
|
PersistentDataContainer container = meta.getPersistentDataContainer();
|
||||||
|
|
||||||
if (container.has(toolStats.timeCreated, PersistentDataType.LONG) || container.has(toolStats.genericOwner, PersistentDataType.LONG)) {
|
if (container.has(toolStats.timeCreated, PersistentDataType.LONG) || container.has(toolStats.itemOwner, PersistentDataType.LONG)) {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
container.set(toolStats.timeCreated, PersistentDataType.LONG, timeCreated);
|
// get the current lore the item
|
||||||
container.set(toolStats.genericOwner, new UUIDDataType(), owner.getUniqueId());
|
List<Component> lore;
|
||||||
|
if (meta.hasLore()) {
|
||||||
String formattedDate = toolStats.numberFormat.formatDate(finalDate);
|
lore = meta.lore();
|
||||||
List<String> newLore = toolStats.itemLore.addNewOwner(meta, owner.getName(), formattedDate, "LOOTED");
|
} else {
|
||||||
|
lore = new ArrayList<>();
|
||||||
if (toolStats.checkConfig(newItem, "looted-tag")) {
|
|
||||||
meta.setLore(newLore);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// if creation date is enabled, add it
|
||||||
|
Component creationDate = toolStats.itemLore.formatCreationTime(timeCreated, 2, newItem);
|
||||||
|
if (creationDate != null) {
|
||||||
|
container.set(toolStats.timeCreated, PersistentDataType.LONG, timeCreated);
|
||||||
|
container.set(toolStats.originType, PersistentDataType.INTEGER, 2);
|
||||||
|
lore.add(creationDate);
|
||||||
|
meta.lore(lore);
|
||||||
|
}
|
||||||
|
|
||||||
|
// if ownership is enabled, add it
|
||||||
|
Component itemOwner = toolStats.itemLore.formatOwner(owner.getName(), 2, newItem);
|
||||||
|
if (itemOwner != null) {
|
||||||
|
container.set(toolStats.itemOwner, new UUIDDataType(), owner.getUniqueId());
|
||||||
|
container.set(toolStats.originType, PersistentDataType.INTEGER, 2);
|
||||||
|
lore.add(itemOwner);
|
||||||
|
meta.lore(lore);
|
||||||
|
}
|
||||||
|
|
||||||
|
// if hash is enabled, add it
|
||||||
|
if (toolStats.config.getBoolean("generate-hash-for-items")) {
|
||||||
|
String hash = toolStats.hashMaker.makeHash(newItem.getType(), owner.getUniqueId(), timeCreated);
|
||||||
|
container.set(toolStats.hash, PersistentDataType.STRING, hash);
|
||||||
|
}
|
||||||
|
|
||||||
newItem.setItemMeta(meta);
|
newItem.setItemMeta(meta);
|
||||||
return newItem;
|
return newItem;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Add tags to the generated loot.
|
||||||
|
*
|
||||||
|
* @param loot The loot from the event.
|
||||||
|
* @param player The player triggering the event.
|
||||||
|
*/
|
||||||
|
private void setLoot(List<ItemStack> loot, Player player) {
|
||||||
|
for (int i = 0; i < loot.size(); i++) {
|
||||||
|
ItemStack itemStack = loot.get(i);
|
||||||
|
// ignore air
|
||||||
|
if (itemStack == null || itemStack.getType() == Material.AIR) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
if (toolStats.itemChecker.isValidItem(itemStack.getType())) {
|
||||||
|
ItemStack newItem = addLootedOrigin(itemStack, player);
|
||||||
|
if (newItem != null) {
|
||||||
|
loot.set(i, newItem);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
114
src/main/java/lol/hyper/toolstats/events/InventoryOpen.java
Normal file
@@ -0,0 +1,114 @@
|
|||||||
|
/*
|
||||||
|
* This file is part of ToolStats.
|
||||||
|
*
|
||||||
|
* ToolStats is free software: you can redistribute it and/or modify
|
||||||
|
* it under the terms of the GNU General Public License as published by
|
||||||
|
* the Free Software Foundation, either version 3 of the License, or
|
||||||
|
* (at your option) any later version.
|
||||||
|
*
|
||||||
|
* ToolStats is distributed in the hope that it will be useful,
|
||||||
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
* GNU General Public License for more details.
|
||||||
|
*
|
||||||
|
* You should have received a copy of the GNU General Public License
|
||||||
|
* along with ToolStats. If not, see <https://www.gnu.org/licenses/>.
|
||||||
|
*/
|
||||||
|
|
||||||
|
package lol.hyper.toolstats.events;
|
||||||
|
|
||||||
|
import lol.hyper.hyperlib.datatypes.UUIDDataType;
|
||||||
|
import lol.hyper.toolstats.ToolStats;
|
||||||
|
import org.bukkit.entity.Player;
|
||||||
|
import org.bukkit.event.EventHandler;
|
||||||
|
import org.bukkit.event.Listener;
|
||||||
|
import org.bukkit.event.inventory.InventoryOpenEvent;
|
||||||
|
import org.bukkit.event.inventory.InventoryType;
|
||||||
|
import org.bukkit.inventory.Inventory;
|
||||||
|
import org.bukkit.inventory.ItemStack;
|
||||||
|
import org.bukkit.inventory.meta.ItemMeta;
|
||||||
|
import org.bukkit.persistence.PersistentDataContainer;
|
||||||
|
import org.bukkit.persistence.PersistentDataType;
|
||||||
|
|
||||||
|
import java.util.UUID;
|
||||||
|
|
||||||
|
public class InventoryOpen implements Listener {
|
||||||
|
|
||||||
|
private final ToolStats toolStats;
|
||||||
|
|
||||||
|
public InventoryOpen(ToolStats toolStats) {
|
||||||
|
this.toolStats = toolStats;
|
||||||
|
}
|
||||||
|
|
||||||
|
@EventHandler
|
||||||
|
public void onOpen(InventoryOpenEvent event) {
|
||||||
|
if (event.isCancelled()) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
Inventory inventory = event.getInventory();
|
||||||
|
// only check these
|
||||||
|
if (inventory.getType() != InventoryType.CHEST || inventory.getType() != InventoryType.BARREL || inventory.getType() != InventoryType.SHULKER_BOX || inventory.getType() != InventoryType.ENDER_CHEST) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
Player player = (Player) event.getPlayer();
|
||||||
|
for (ItemStack itemStack : inventory) {
|
||||||
|
if (itemStack == null) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
// ignore items that are not the right type
|
||||||
|
if (!toolStats.itemChecker.isValidItem(itemStack.getType())) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
ItemMeta itemMeta = itemStack.getItemMeta();
|
||||||
|
if (itemMeta == null) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
PersistentDataContainer container = itemMeta.getPersistentDataContainer();
|
||||||
|
|
||||||
|
if (toolStats.config.getBoolean("tokens.enabled")) {
|
||||||
|
// if the token system is on and the item doesn't have stat keys
|
||||||
|
if (toolStats.itemChecker.keyCheck(container) && !container.has(toolStats.tokenType)) {
|
||||||
|
// add the tokens
|
||||||
|
String newTokens = toolStats.itemChecker.addTokensToExisting(itemStack);
|
||||||
|
if (newTokens == null) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
container.set(toolStats.tokenApplied, PersistentDataType.STRING, newTokens);
|
||||||
|
itemStack.setItemMeta(itemMeta);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// generate a hash if the item doesn't have one (and enabled)
|
||||||
|
// if hashes are disabled and the item has one, remove it.
|
||||||
|
if (toolStats.config.getBoolean("generate-hash-for-items")) {
|
||||||
|
if (!container.has(toolStats.hash, PersistentDataType.STRING)) {
|
||||||
|
UUID owner = null;
|
||||||
|
// get the current owner if there is one.
|
||||||
|
if (container.has(toolStats.itemOwner, new UUIDDataType())) {
|
||||||
|
owner = container.get(toolStats.itemOwner, new UUIDDataType());
|
||||||
|
}
|
||||||
|
// if there is no owner, use the player holding it
|
||||||
|
if (owner == null) {
|
||||||
|
owner = player.getUniqueId();
|
||||||
|
}
|
||||||
|
Long timestamp = container.get(toolStats.timeCreated, PersistentDataType.LONG);
|
||||||
|
if (timestamp == null) {
|
||||||
|
// if there is no time created, use now
|
||||||
|
timestamp = System.currentTimeMillis();
|
||||||
|
}
|
||||||
|
String hash = toolStats.hashMaker.makeHash(itemStack.getType(), owner, timestamp);
|
||||||
|
container.set(toolStats.hash, PersistentDataType.STRING, hash);
|
||||||
|
itemStack.setItemMeta(itemMeta);
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
// if hashes are disabled but the item has one, remove it.
|
||||||
|
if (container.has(toolStats.hash, PersistentDataType.STRING)) {
|
||||||
|
container.remove(toolStats.hash);
|
||||||
|
itemStack.setItemMeta(itemMeta);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -17,11 +17,15 @@
|
|||||||
|
|
||||||
package lol.hyper.toolstats.events;
|
package lol.hyper.toolstats.events;
|
||||||
|
|
||||||
|
import lol.hyper.hyperlib.datatypes.UUIDDataType;
|
||||||
import lol.hyper.toolstats.ToolStats;
|
import lol.hyper.toolstats.ToolStats;
|
||||||
import lol.hyper.toolstats.tools.UUIDDataType;
|
import net.kyori.adventure.text.Component;
|
||||||
import org.bukkit.GameMode;
|
import org.bukkit.GameMode;
|
||||||
import org.bukkit.Material;
|
import org.bukkit.Material;
|
||||||
import org.bukkit.entity.*;
|
import org.bukkit.entity.Entity;
|
||||||
|
import org.bukkit.entity.EntityType;
|
||||||
|
import org.bukkit.entity.Item;
|
||||||
|
import org.bukkit.entity.Player;
|
||||||
import org.bukkit.event.EventHandler;
|
import org.bukkit.event.EventHandler;
|
||||||
import org.bukkit.event.EventPriority;
|
import org.bukkit.event.EventPriority;
|
||||||
import org.bukkit.event.Listener;
|
import org.bukkit.event.Listener;
|
||||||
@@ -31,6 +35,7 @@ import org.bukkit.inventory.meta.ItemMeta;
|
|||||||
import org.bukkit.persistence.PersistentDataContainer;
|
import org.bukkit.persistence.PersistentDataContainer;
|
||||||
import org.bukkit.persistence.PersistentDataType;
|
import org.bukkit.persistence.PersistentDataType;
|
||||||
|
|
||||||
|
import java.util.ArrayList;
|
||||||
import java.util.Date;
|
import java.util.Date;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
@@ -48,13 +53,12 @@ public class PickupItem implements Listener {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
Entity entity = event.getEntity();
|
Entity entity = event.getEntity();
|
||||||
if (entity instanceof Player) {
|
if (entity instanceof Player player) {
|
||||||
Player player = (Player) entity;
|
if (player.getGameMode() == GameMode.CREATIVE && !toolStats.config.getBoolean("allow-creative")) {
|
||||||
if (player.getGameMode() == GameMode.CREATIVE || player.getGameMode() == GameMode.SPECTATOR) {
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
Item item = event.getItem();
|
Item item = event.getItem();
|
||||||
if (item.getType() == EntityType.DROPPED_ITEM) {
|
if (item.getType() == EntityType.ITEM) {
|
||||||
ItemStack itemStack = event.getItem().getItemStack();
|
ItemStack itemStack = event.getItem().getItemStack();
|
||||||
ItemMeta meta = itemStack.getItemMeta();
|
ItemMeta meta = itemStack.getItemMeta();
|
||||||
if (meta == null) {
|
if (meta == null) {
|
||||||
@@ -64,7 +68,7 @@ public class PickupItem implements Listener {
|
|||||||
if (itemStack.getType() == Material.ELYTRA) {
|
if (itemStack.getType() == Material.ELYTRA) {
|
||||||
// the elytra has the new key, set the lore to it
|
// the elytra has the new key, set the lore to it
|
||||||
if (container.has(toolStats.newElytra, PersistentDataType.INTEGER)) {
|
if (container.has(toolStats.newElytra, PersistentDataType.INTEGER)) {
|
||||||
ItemStack newElytra = addLore(itemStack, (Player) event.getEntity());
|
ItemStack newElytra = addElytraOrigin(itemStack, (Player) event.getEntity());
|
||||||
if (newElytra != null) {
|
if (newElytra != null) {
|
||||||
item.setItemStack(newElytra);
|
item.setItemStack(newElytra);
|
||||||
}
|
}
|
||||||
@@ -80,25 +84,59 @@ public class PickupItem implements Listener {
|
|||||||
* @param itemStack The elytra to add lore to.
|
* @param itemStack The elytra to add lore to.
|
||||||
* @param owner The player who found it.
|
* @param owner The player who found it.
|
||||||
*/
|
*/
|
||||||
private ItemStack addLore(ItemStack itemStack, Player owner) {
|
private ItemStack addElytraOrigin(ItemStack itemStack, Player owner) {
|
||||||
ItemStack finalItem = itemStack.clone();
|
ItemStack finalItem = itemStack.clone();
|
||||||
ItemMeta meta = finalItem.getItemMeta();
|
ItemMeta meta = finalItem.getItemMeta();
|
||||||
if (meta == null) {
|
if (meta == null) {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
long timeCreated = System.currentTimeMillis();
|
long timeCreated = System.currentTimeMillis();
|
||||||
Date finalDate = new Date(timeCreated);
|
Date finalDate;
|
||||||
|
if (toolStats.config.getBoolean("normalize-time-creation")) {
|
||||||
|
finalDate = toolStats.numberFormat.normalizeTime(timeCreated);
|
||||||
|
timeCreated = finalDate.getTime();
|
||||||
|
}
|
||||||
PersistentDataContainer container = meta.getPersistentDataContainer();
|
PersistentDataContainer container = meta.getPersistentDataContainer();
|
||||||
|
|
||||||
|
if (!toolStats.config.getBoolean("enabled.elytra-tag")) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
// only make the hash if it's enabled
|
||||||
|
if (toolStats.config.getBoolean("generate-hash-for-items")) {
|
||||||
|
String hash = toolStats.hashMaker.makeHash(finalItem.getType(), owner.getUniqueId(), timeCreated);
|
||||||
|
container.set(toolStats.hash, PersistentDataType.STRING, hash);
|
||||||
|
}
|
||||||
|
|
||||||
|
// get the current lore the item
|
||||||
|
List<Component> lore;
|
||||||
|
if (meta.hasLore()) {
|
||||||
|
lore = meta.lore();
|
||||||
|
} else {
|
||||||
|
lore = new ArrayList<>();
|
||||||
|
}
|
||||||
|
|
||||||
container.set(toolStats.timeCreated, PersistentDataType.LONG, timeCreated);
|
container.set(toolStats.timeCreated, PersistentDataType.LONG, timeCreated);
|
||||||
container.set(toolStats.genericOwner, new UUIDDataType(), owner.getUniqueId());
|
container.set(toolStats.itemOwner, new UUIDDataType(), owner.getUniqueId());
|
||||||
|
container.set(toolStats.originType, PersistentDataType.INTEGER, 4);
|
||||||
container.remove(toolStats.newElytra);
|
container.remove(toolStats.newElytra);
|
||||||
|
|
||||||
String formattedDate = toolStats.numberFormat.formatDate(finalDate);
|
Component creationDate = toolStats.itemLore.formatCreationTime(timeCreated, 4, finalItem);
|
||||||
List<String> newLore = toolStats.itemLore.addNewOwner(meta, owner.getName(), formattedDate, "LOOTED");
|
if (creationDate != null) {
|
||||||
|
container.set(toolStats.timeCreated, PersistentDataType.LONG, timeCreated);
|
||||||
if (toolStats.config.getBoolean("enabled.elytra-tag")) {
|
container.set(toolStats.originType, PersistentDataType.INTEGER, 4);
|
||||||
meta.setLore(newLore);
|
lore.add(creationDate);
|
||||||
|
meta.lore(lore);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Component itemOwner = toolStats.itemLore.formatOwner(owner.getName(), 4, finalItem);
|
||||||
|
if (itemOwner != null) {
|
||||||
|
container.set(toolStats.itemOwner, new UUIDDataType(), owner.getUniqueId());
|
||||||
|
container.set(toolStats.originType, PersistentDataType.INTEGER, 4);
|
||||||
|
lore.add(itemOwner);
|
||||||
|
meta.lore(lore);
|
||||||
|
}
|
||||||
|
|
||||||
finalItem.setItemMeta(meta);
|
finalItem.setItemMeta(meta);
|
||||||
return finalItem;
|
return finalItem;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -17,9 +17,9 @@
|
|||||||
|
|
||||||
package lol.hyper.toolstats.events;
|
package lol.hyper.toolstats.events;
|
||||||
|
|
||||||
|
import lol.hyper.hyperlib.datatypes.UUIDDataType;
|
||||||
import lol.hyper.toolstats.ToolStats;
|
import lol.hyper.toolstats.ToolStats;
|
||||||
import lol.hyper.toolstats.tools.ItemChecker;
|
import net.kyori.adventure.text.Component;
|
||||||
import lol.hyper.toolstats.tools.UUIDDataType;
|
|
||||||
import org.bukkit.GameMode;
|
import org.bukkit.GameMode;
|
||||||
import org.bukkit.Material;
|
import org.bukkit.Material;
|
||||||
import org.bukkit.entity.Item;
|
import org.bukkit.entity.Item;
|
||||||
@@ -34,6 +34,7 @@ import org.bukkit.inventory.meta.ItemMeta;
|
|||||||
import org.bukkit.persistence.PersistentDataContainer;
|
import org.bukkit.persistence.PersistentDataContainer;
|
||||||
import org.bukkit.persistence.PersistentDataType;
|
import org.bukkit.persistence.PersistentDataType;
|
||||||
|
|
||||||
|
import java.util.ArrayList;
|
||||||
import java.util.Date;
|
import java.util.Date;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
@@ -56,35 +57,30 @@ public class PlayerFish implements Listener {
|
|||||||
}
|
}
|
||||||
|
|
||||||
Player player = event.getPlayer();
|
Player player = event.getPlayer();
|
||||||
if (player.getGameMode() == GameMode.CREATIVE || player.getGameMode() == GameMode.SPECTATOR) {
|
if (player.getGameMode() == GameMode.CREATIVE && !toolStats.config.getBoolean("allow-creative")) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
// make sure the player is holding a fishing rod
|
|
||||||
// player can fish with their offhand
|
|
||||||
PlayerInventory inventory = player.getInventory();
|
|
||||||
boolean isMainHand = inventory.getItemInMainHand().getType() == Material.FISHING_ROD;
|
|
||||||
boolean isOffHand = inventory.getItemInOffHand().getType() == Material.FISHING_ROD;
|
|
||||||
ItemStack fishingRod = null;
|
|
||||||
if (isMainHand) {
|
|
||||||
fishingRod = inventory.getItemInMainHand();
|
|
||||||
}
|
|
||||||
if (isOffHand) {
|
|
||||||
fishingRod = inventory.getItemInOffHand();
|
|
||||||
}
|
|
||||||
|
|
||||||
// if the player is hold fishing rods in both hands
|
|
||||||
// default to main hand since that takes priority
|
|
||||||
if (isMainHand && isOffHand) {
|
|
||||||
fishingRod = inventory.getItemInMainHand();
|
|
||||||
}
|
|
||||||
|
|
||||||
|
ItemStack fishingRod = toolStats.itemChecker.getFishingRod(player.getInventory());
|
||||||
// player swapped items?
|
// player swapped items?
|
||||||
if (fishingRod == null) {
|
if (fishingRod == null) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
// update the fishing rod!
|
// update the fishing rod!
|
||||||
updateFishCount(fishingRod);
|
ItemMeta newFishingRod = toolStats.itemLore.updateFishCaught(fishingRod, 1);
|
||||||
|
if (newFishingRod != null) {
|
||||||
|
PlayerInventory inventory = player.getInventory();
|
||||||
|
boolean isMain = inventory.getItemInMainHand().getType() == Material.FISHING_ROD;
|
||||||
|
boolean isOffHand = inventory.getItemInOffHand().getType() == Material.FISHING_ROD;
|
||||||
|
if (isMain && isOffHand) {
|
||||||
|
inventory.getItemInMainHand().setItemMeta(newFishingRod);
|
||||||
|
} else if (isMain) {
|
||||||
|
inventory.getItemInMainHand().setItemMeta(newFishingRod);
|
||||||
|
} else if (isOffHand) {
|
||||||
|
inventory.getItemInOffHand().setItemMeta(newFishingRod);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// check if the player caught an item
|
// check if the player caught an item
|
||||||
if (event.getCaught() == null) {
|
if (event.getCaught() == null) {
|
||||||
@@ -92,48 +88,14 @@ public class PlayerFish implements Listener {
|
|||||||
}
|
}
|
||||||
ItemStack caughtItem = ((Item) event.getCaught()).getItemStack();
|
ItemStack caughtItem = ((Item) event.getCaught()).getItemStack();
|
||||||
Item caughtItemEntity = (Item) event.getCaught();
|
Item caughtItemEntity = (Item) event.getCaught();
|
||||||
if (ItemChecker.isValidItem(caughtItem.getType())) {
|
if (toolStats.itemChecker.isValidItem(caughtItem.getType())) {
|
||||||
ItemStack newItem = addNewLore(caughtItem, player);
|
ItemStack newItem = addFishedOrigin(caughtItem, player);
|
||||||
if (newItem != null) {
|
if (newItem != null) {
|
||||||
caughtItemEntity.setItemStack(newItem);
|
caughtItemEntity.setItemStack(newItem);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* Update a fishing rod's fish count.
|
|
||||||
*
|
|
||||||
* @param fishingRod The fishing rod to update.
|
|
||||||
*/
|
|
||||||
private void updateFishCount(ItemStack fishingRod) {
|
|
||||||
ItemMeta meta = fishingRod.getItemMeta();
|
|
||||||
if (meta == null) {
|
|
||||||
toolStats.logger.warning(fishingRod + " does NOT have any meta! Unable to update stats.");
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
Integer fishCaught = 0;
|
|
||||||
PersistentDataContainer container = meta.getPersistentDataContainer();
|
|
||||||
if (container.has(toolStats.fishingRodCaught, PersistentDataType.INTEGER)) {
|
|
||||||
fishCaught = container.get(toolStats.fishingRodCaught, PersistentDataType.INTEGER);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (fishCaught == null) {
|
|
||||||
fishCaught = 0;
|
|
||||||
toolStats.logger.warning(fishingRod + " does not have valid fish-caught set! Resting to zero. This should NEVER happen.");
|
|
||||||
}
|
|
||||||
|
|
||||||
fishCaught++;
|
|
||||||
container.set(toolStats.fishingRodCaught, PersistentDataType.INTEGER, fishCaught);
|
|
||||||
|
|
||||||
String fishCaughtFormatted = toolStats.numberFormat.formatInt(fishCaught);
|
|
||||||
List<String> newLore = toolStats.itemLore.addItemLore(meta, "{fish}", fishCaughtFormatted, "fished.fish-caught");
|
|
||||||
|
|
||||||
if (toolStats.config.getBoolean("enabled.fish-caught")) {
|
|
||||||
meta.setLore(newLore);
|
|
||||||
}
|
|
||||||
fishingRod.setItemMeta(meta);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Add lore to newly caught item.
|
* Add lore to newly caught item.
|
||||||
*
|
*
|
||||||
@@ -141,29 +103,56 @@ public class PlayerFish implements Listener {
|
|||||||
* @param owner The player who caught it.
|
* @param owner The player who caught it.
|
||||||
* @return A copy of the new item with lore.
|
* @return A copy of the new item with lore.
|
||||||
*/
|
*/
|
||||||
private ItemStack addNewLore(ItemStack originalItem, Player owner) {
|
private ItemStack addFishedOrigin(ItemStack originalItem, Player owner) {
|
||||||
ItemStack newItem = originalItem.clone();
|
ItemStack newItem = originalItem.clone();
|
||||||
ItemMeta meta = originalItem.getItemMeta();
|
ItemMeta meta = originalItem.getItemMeta();
|
||||||
if (meta == null) {
|
if (meta == null) {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
long timeCreated = System.currentTimeMillis();
|
long timeCreated = System.currentTimeMillis();
|
||||||
Date finalDate = new Date(timeCreated);
|
Date finalDate;
|
||||||
|
if (toolStats.config.getBoolean("normalize-time-creation")) {
|
||||||
|
finalDate = toolStats.numberFormat.normalizeTime(timeCreated);
|
||||||
|
timeCreated = finalDate.getTime();
|
||||||
|
}
|
||||||
PersistentDataContainer container = meta.getPersistentDataContainer();
|
PersistentDataContainer container = meta.getPersistentDataContainer();
|
||||||
|
|
||||||
if (container.has(toolStats.timeCreated, PersistentDataType.LONG) || container.has(toolStats.genericOwner, PersistentDataType.LONG)) {
|
if (container.has(toolStats.timeCreated, PersistentDataType.LONG) || container.has(toolStats.itemOwner, PersistentDataType.LONG)) {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
container.set(toolStats.timeCreated, PersistentDataType.LONG, timeCreated);
|
// get the current lore the item
|
||||||
container.set(toolStats.genericOwner, new UUIDDataType(), owner.getUniqueId());
|
List<Component> lore;
|
||||||
|
if (meta.hasLore()) {
|
||||||
String formattedDate = toolStats.numberFormat.formatDate(finalDate);
|
lore = meta.lore();
|
||||||
List<String> newLore = toolStats.itemLore.addNewOwner(meta, owner.getName(), formattedDate, "FISHED");
|
} else {
|
||||||
|
lore = new ArrayList<>();
|
||||||
if (toolStats.checkConfig(newItem, "fished-tag")) {
|
|
||||||
meta.setLore(newLore);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// if creation date is enabled, add it
|
||||||
|
Component creationDate = toolStats.itemLore.formatCreationTime(timeCreated, 5, newItem);
|
||||||
|
if (creationDate != null) {
|
||||||
|
container.set(toolStats.timeCreated, PersistentDataType.LONG, timeCreated);
|
||||||
|
container.set(toolStats.originType, PersistentDataType.INTEGER, 5);
|
||||||
|
lore.add(creationDate);
|
||||||
|
meta.lore(lore);
|
||||||
|
}
|
||||||
|
|
||||||
|
// if ownership is enabled, add it
|
||||||
|
Component itemOwner = toolStats.itemLore.formatOwner(owner.getName(), 5, newItem);
|
||||||
|
if (itemOwner != null) {
|
||||||
|
container.set(toolStats.itemOwner, new UUIDDataType(), owner.getUniqueId());
|
||||||
|
container.set(toolStats.originType, PersistentDataType.INTEGER, 5);
|
||||||
|
lore.add(itemOwner);
|
||||||
|
meta.lore(lore);
|
||||||
|
}
|
||||||
|
|
||||||
|
// if hash is enabled, add it
|
||||||
|
if (toolStats.config.getBoolean("generate-hash-for-items")) {
|
||||||
|
String hash = toolStats.hashMaker.makeHash(newItem.getType(), owner.getUniqueId(), timeCreated);
|
||||||
|
container.set(toolStats.hash, PersistentDataType.STRING, hash);
|
||||||
|
}
|
||||||
|
|
||||||
newItem.setItemMeta(meta);
|
newItem.setItemMeta(meta);
|
||||||
return newItem;
|
return newItem;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -33,13 +33,14 @@ import org.bukkit.event.player.PlayerInteractEntityEvent;
|
|||||||
import org.bukkit.event.player.PlayerInteractEvent;
|
import org.bukkit.event.player.PlayerInteractEvent;
|
||||||
|
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
|
import java.util.Map;
|
||||||
|
|
||||||
public class PlayerInteract implements Listener {
|
public class PlayerInteract implements Listener {
|
||||||
|
|
||||||
private final ToolStats toolStats;
|
private final ToolStats toolStats;
|
||||||
|
|
||||||
public final HashMap<Block, Player> openedChests = new HashMap<>();
|
public final Map<Block, Player> openedChests = new HashMap<>();
|
||||||
public final HashMap<StorageMinecart, Player> openedMineCarts = new HashMap<>();
|
public final Map<StorageMinecart, Player> openedMineCarts = new HashMap<>();
|
||||||
|
|
||||||
public PlayerInteract(ToolStats toolStats) {
|
public PlayerInteract(ToolStats toolStats) {
|
||||||
this.toolStats = toolStats;
|
this.toolStats = toolStats;
|
||||||
@@ -57,13 +58,13 @@ public class PlayerInteract implements Listener {
|
|||||||
}
|
}
|
||||||
|
|
||||||
Player player = event.getPlayer();
|
Player player = event.getPlayer();
|
||||||
if (player.getGameMode() == GameMode.CREATIVE || player.getGameMode() == GameMode.SPECTATOR) {
|
if (player.getGameMode() == GameMode.CREATIVE && !toolStats.config.getBoolean("allow-creative")) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
// store when a player opens a chest
|
// store when a player opens a chest
|
||||||
if (block.getType() != Material.AIR && block.getType() == Material.CHEST) {
|
if (block.getType() != Material.AIR && block.getType() == Material.CHEST) {
|
||||||
openedChests.put(block, player);
|
openedChests.put(block, player);
|
||||||
Bukkit.getScheduler().runTaskLater(toolStats, () -> openedChests.remove(block), 20);
|
Bukkit.getGlobalRegionScheduler().runDelayed(toolStats, scheduledTask -> openedChests.remove(block), 20);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -71,14 +72,14 @@ public class PlayerInteract implements Listener {
|
|||||||
public void onInteract(PlayerInteractEntityEvent event) {
|
public void onInteract(PlayerInteractEntityEvent event) {
|
||||||
Entity clicked = event.getRightClicked();
|
Entity clicked = event.getRightClicked();
|
||||||
Player player = event.getPlayer();
|
Player player = event.getPlayer();
|
||||||
if (player.getGameMode() == GameMode.CREATIVE || player.getGameMode() == GameMode.SPECTATOR) {
|
if (player.getGameMode() == GameMode.CREATIVE && !toolStats.config.getBoolean("allow-creative")) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
// store when a player opens a minecart
|
// store when a player opens a minecart
|
||||||
if (clicked.getType() == EntityType.MINECART_CHEST) {
|
if (clicked.getType() == EntityType.CHEST_MINECART) {
|
||||||
StorageMinecart storageMinecart = (StorageMinecart) clicked;
|
StorageMinecart storageMinecart = (StorageMinecart) clicked;
|
||||||
openedMineCarts.put(storageMinecart, player);
|
openedMineCarts.put(storageMinecart, player);
|
||||||
Bukkit.getScheduler().runTaskLater(toolStats, () -> openedMineCarts.remove(storageMinecart), 20);
|
Bukkit.getGlobalRegionScheduler().runDelayed(toolStats, scheduledTask -> openedMineCarts.remove(storageMinecart), 20);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
104
src/main/java/lol/hyper/toolstats/events/PlayerJoin.java
Normal file
@@ -0,0 +1,104 @@
|
|||||||
|
/*
|
||||||
|
* This file is part of ToolStats.
|
||||||
|
*
|
||||||
|
* ToolStats is free software: you can redistribute it and/or modify
|
||||||
|
* it under the terms of the GNU General Public License as published by
|
||||||
|
* the Free Software Foundation, either version 3 of the License, or
|
||||||
|
* (at your option) any later version.
|
||||||
|
*
|
||||||
|
* ToolStats is distributed in the hope that it will be useful,
|
||||||
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
* GNU General Public License for more details.
|
||||||
|
*
|
||||||
|
* You should have received a copy of the GNU General Public License
|
||||||
|
* along with ToolStats. If not, see <https://www.gnu.org/licenses/>.
|
||||||
|
*/
|
||||||
|
|
||||||
|
package lol.hyper.toolstats.events;
|
||||||
|
|
||||||
|
import lol.hyper.hyperlib.datatypes.UUIDDataType;
|
||||||
|
import lol.hyper.toolstats.ToolStats;
|
||||||
|
import org.bukkit.entity.Player;
|
||||||
|
import org.bukkit.event.EventHandler;
|
||||||
|
import org.bukkit.event.Listener;
|
||||||
|
import org.bukkit.event.player.PlayerJoinEvent;
|
||||||
|
import org.bukkit.inventory.Inventory;
|
||||||
|
import org.bukkit.inventory.ItemStack;
|
||||||
|
import org.bukkit.inventory.meta.ItemMeta;
|
||||||
|
import org.bukkit.persistence.PersistentDataContainer;
|
||||||
|
import org.bukkit.persistence.PersistentDataType;
|
||||||
|
|
||||||
|
import java.util.UUID;
|
||||||
|
|
||||||
|
public class PlayerJoin implements Listener {
|
||||||
|
|
||||||
|
private final ToolStats toolStats;
|
||||||
|
|
||||||
|
public PlayerJoin(ToolStats toolStats) {
|
||||||
|
this.toolStats = toolStats;
|
||||||
|
}
|
||||||
|
|
||||||
|
@EventHandler
|
||||||
|
public void onJoin(PlayerJoinEvent event) {
|
||||||
|
Player player = event.getPlayer();
|
||||||
|
|
||||||
|
Inventory inventory = player.getInventory();
|
||||||
|
for (ItemStack itemStack : inventory) {
|
||||||
|
if (itemStack == null) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
// ignore items that are not the right type
|
||||||
|
if (!toolStats.itemChecker.isValidItem(itemStack.getType())) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
ItemMeta itemMeta = itemStack.getItemMeta();
|
||||||
|
if (itemMeta == null) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
PersistentDataContainer container = itemMeta.getPersistentDataContainer();
|
||||||
|
|
||||||
|
if (toolStats.config.getBoolean("tokens.enabled")) {
|
||||||
|
// if the token system is on and the item doesn't have stat keys
|
||||||
|
if (toolStats.itemChecker.keyCheck(container) && !container.has(toolStats.tokenType)) {
|
||||||
|
// add the tokens
|
||||||
|
String newTokens = toolStats.itemChecker.addTokensToExisting(itemStack);
|
||||||
|
if (newTokens == null) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
container.set(toolStats.tokenApplied, PersistentDataType.STRING, newTokens);
|
||||||
|
itemStack.setItemMeta(itemMeta);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// generate a hash if the item doesn't have one
|
||||||
|
if (toolStats.config.getBoolean("generate-hash-for-items")) {
|
||||||
|
if (!container.has(toolStats.hash, PersistentDataType.STRING)) {
|
||||||
|
UUID owner = null;
|
||||||
|
// get the current owner if there is one.
|
||||||
|
if (container.has(toolStats.itemOwner, new UUIDDataType())) {
|
||||||
|
owner = container.get(toolStats.itemOwner, new UUIDDataType());
|
||||||
|
}
|
||||||
|
// if there is no owner, use the player holding it
|
||||||
|
if (owner == null) {
|
||||||
|
owner = player.getUniqueId();
|
||||||
|
}
|
||||||
|
Long timestamp = container.get(toolStats.timeCreated, PersistentDataType.LONG);
|
||||||
|
if (timestamp == null) {
|
||||||
|
// if there is no time created, use now
|
||||||
|
timestamp = System.currentTimeMillis();
|
||||||
|
}
|
||||||
|
String hash = toolStats.hashMaker.makeHash(itemStack.getType(), owner, timestamp);
|
||||||
|
container.set(toolStats.hash, PersistentDataType.STRING, hash);
|
||||||
|
itemStack.setItemMeta(itemMeta);
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
// if hashes are disabled but the item has one, remove it.
|
||||||
|
if (container.has(toolStats.hash, PersistentDataType.STRING)) {
|
||||||
|
container.remove(toolStats.hash);
|
||||||
|
itemStack.setItemMeta(itemMeta);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
76
src/main/java/lol/hyper/toolstats/events/PlayerMove.java
Normal file
@@ -0,0 +1,76 @@
|
|||||||
|
/*
|
||||||
|
* This file is part of ToolStats.
|
||||||
|
*
|
||||||
|
* ToolStats is free software: you can redistribute it and/or modify
|
||||||
|
* it under the terms of the GNU General Public License as published by
|
||||||
|
* the Free Software Foundation, either version 3 of the License, or
|
||||||
|
* (at your option) any later version.
|
||||||
|
*
|
||||||
|
* ToolStats is distributed in the hope that it will be useful,
|
||||||
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
* GNU General Public License for more details.
|
||||||
|
*
|
||||||
|
* You should have received a copy of the GNU General Public License
|
||||||
|
* along with ToolStats. If not, see <https://www.gnu.org/licenses/>.
|
||||||
|
*/
|
||||||
|
|
||||||
|
package lol.hyper.toolstats.events;
|
||||||
|
|
||||||
|
import lol.hyper.toolstats.ToolStats;
|
||||||
|
import org.bukkit.entity.Player;
|
||||||
|
import org.bukkit.event.EventHandler;
|
||||||
|
import org.bukkit.event.EventPriority;
|
||||||
|
import org.bukkit.event.Listener;
|
||||||
|
import org.bukkit.event.player.PlayerMoveEvent;
|
||||||
|
import org.bukkit.inventory.ItemStack;
|
||||||
|
import org.bukkit.inventory.PlayerInventory;
|
||||||
|
import org.bukkit.inventory.meta.ItemMeta;
|
||||||
|
|
||||||
|
import java.util.HashMap;
|
||||||
|
import java.util.Map;
|
||||||
|
|
||||||
|
public class PlayerMove implements Listener {
|
||||||
|
|
||||||
|
private final ToolStats toolStats;
|
||||||
|
private final Map<Player, Long> playerStartFlight = new HashMap<>();
|
||||||
|
|
||||||
|
public PlayerMove(ToolStats toolStats) {
|
||||||
|
this.toolStats = toolStats;
|
||||||
|
}
|
||||||
|
|
||||||
|
@EventHandler(priority = EventPriority.MONITOR)
|
||||||
|
public void onMove(PlayerMoveEvent event) {
|
||||||
|
Player player = event.getPlayer();
|
||||||
|
// player starts to fly
|
||||||
|
if (player.isGliding()) {
|
||||||
|
// if they are flying, and we don't have them tracked, add them
|
||||||
|
if (!playerStartFlight.containsKey(player)) {
|
||||||
|
playerStartFlight.put(player, System.currentTimeMillis());
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
// player is not flying
|
||||||
|
if (playerStartFlight.containsKey(player)) {
|
||||||
|
PlayerInventory inventory = player.getInventory();
|
||||||
|
// copy their current armor
|
||||||
|
ItemStack[] armor = inventory.getArmorContents().clone();
|
||||||
|
for (ItemStack armorPiece : armor) {
|
||||||
|
// skip missing slots
|
||||||
|
if (armorPiece == null) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
// if the armor piece can glide, track the flight time
|
||||||
|
if (toolStats.itemChecker.canGlide(armorPiece)) {
|
||||||
|
long duration = (System.currentTimeMillis() - playerStartFlight.get(player));
|
||||||
|
ItemMeta newMeta = toolStats.itemLore.updateFlightTime(armorPiece, duration);
|
||||||
|
if (newMeta != null) {
|
||||||
|
armorPiece.setItemMeta(newMeta);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
inventory.setArmorContents(armor);
|
||||||
|
playerStartFlight.remove(player);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
56
src/main/java/lol/hyper/toolstats/events/PrepareCraft.java
Normal file
@@ -0,0 +1,56 @@
|
|||||||
|
/*
|
||||||
|
* This file is part of ToolStats.
|
||||||
|
*
|
||||||
|
* ToolStats is free software: you can redistribute it and/or modify
|
||||||
|
* it under the terms of the GNU General Public License as published by
|
||||||
|
* the Free Software Foundation, either version 3 of the License, or
|
||||||
|
* (at your option) any later version.
|
||||||
|
*
|
||||||
|
* ToolStats is distributed in the hope that it will be useful,
|
||||||
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
* GNU General Public License for more details.
|
||||||
|
*
|
||||||
|
* You should have received a copy of the GNU General Public License
|
||||||
|
* along with ToolStats. If not, see <https://www.gnu.org/licenses/>.
|
||||||
|
*/
|
||||||
|
|
||||||
|
package lol.hyper.toolstats.events;
|
||||||
|
|
||||||
|
import lol.hyper.toolstats.ToolStats;
|
||||||
|
import org.bukkit.event.EventHandler;
|
||||||
|
import org.bukkit.event.EventPriority;
|
||||||
|
import org.bukkit.event.Listener;
|
||||||
|
import org.bukkit.event.inventory.PrepareItemCraftEvent;
|
||||||
|
import org.bukkit.inventory.ItemStack;
|
||||||
|
import org.bukkit.inventory.meta.ItemMeta;
|
||||||
|
import org.bukkit.persistence.PersistentDataContainer;
|
||||||
|
|
||||||
|
public class PrepareCraft implements Listener {
|
||||||
|
|
||||||
|
private final ToolStats toolStats;
|
||||||
|
|
||||||
|
public PrepareCraft(ToolStats toolStats) {
|
||||||
|
this.toolStats = toolStats;
|
||||||
|
}
|
||||||
|
|
||||||
|
@EventHandler(priority = EventPriority.HIGHEST)
|
||||||
|
public void onCraft(PrepareItemCraftEvent event) {
|
||||||
|
// get the items in the crafting grid
|
||||||
|
ItemStack[] grid = event.getInventory().getMatrix();
|
||||||
|
for (ItemStack item : grid) {
|
||||||
|
if (item == null) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
ItemMeta meta = item.getItemMeta();
|
||||||
|
if (meta == null) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
// if the paper item has our PDC, cancel it
|
||||||
|
PersistentDataContainer container = meta.getPersistentDataContainer();
|
||||||
|
if (container.has(toolStats.tokenType)) {
|
||||||
|
event.getInventory().setResult(null);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -30,10 +30,6 @@ import org.bukkit.event.player.PlayerInteractEntityEvent;
|
|||||||
import org.bukkit.inventory.ItemStack;
|
import org.bukkit.inventory.ItemStack;
|
||||||
import org.bukkit.inventory.PlayerInventory;
|
import org.bukkit.inventory.PlayerInventory;
|
||||||
import org.bukkit.inventory.meta.ItemMeta;
|
import org.bukkit.inventory.meta.ItemMeta;
|
||||||
import org.bukkit.persistence.PersistentDataContainer;
|
|
||||||
import org.bukkit.persistence.PersistentDataType;
|
|
||||||
|
|
||||||
import java.util.List;
|
|
||||||
|
|
||||||
public class SheepShear implements Listener {
|
public class SheepShear implements Listener {
|
||||||
|
|
||||||
@@ -49,80 +45,38 @@ public class SheepShear implements Listener {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
Player player = event.getPlayer();
|
Player player = event.getPlayer();
|
||||||
if (player.getGameMode() == GameMode.CREATIVE || player.getGameMode() == GameMode.SPECTATOR) {
|
if (player.getGameMode() == GameMode.CREATIVE && !toolStats.config.getBoolean("allow-creative")) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
Entity entity = event.getRightClicked();
|
Entity entity = event.getRightClicked();
|
||||||
if (!(entity instanceof Sheep)) {
|
if (!(entity instanceof Sheep sheep)) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
// make sure the player is holding shears
|
ItemStack heldShears = toolStats.itemChecker.getShears(player.getInventory());
|
||||||
// player can shear with their offhand
|
// player swapped or we can't get the shears
|
||||||
PlayerInventory inventory = player.getInventory();
|
if (heldShears == null) {
|
||||||
boolean isMainHand = inventory.getItemInMainHand().getType() == Material.SHEARS;
|
|
||||||
boolean isOffHand = inventory.getItemInOffHand().getType() == Material.SHEARS;
|
|
||||||
ItemStack shears = null;
|
|
||||||
if (isMainHand) {
|
|
||||||
shears = inventory.getItemInMainHand();
|
|
||||||
}
|
|
||||||
if (isOffHand) {
|
|
||||||
shears = inventory.getItemInOffHand();
|
|
||||||
}
|
|
||||||
|
|
||||||
// if the player is hold fishing rods in both hands
|
|
||||||
// default to main hand since that takes priority
|
|
||||||
if (isMainHand && isOffHand) {
|
|
||||||
shears = inventory.getItemInMainHand();
|
|
||||||
}
|
|
||||||
|
|
||||||
// player swapped items?
|
|
||||||
if (shears == null) {
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
Sheep sheep = (Sheep) entity;
|
|
||||||
// make sure the sheep is not sheared
|
// make sure the sheep is not sheared
|
||||||
if (sheep.isSheared()) {
|
if (sheep.isSheared()) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
// update the stats
|
// update the stats
|
||||||
ItemStack finalShears = shears;
|
ItemMeta newShears = toolStats.itemLore.updateSheepSheared(heldShears, 1);
|
||||||
addLore(finalShears);
|
if (newShears != null) {
|
||||||
|
PlayerInventory inventory = player.getInventory();
|
||||||
|
boolean isMain = inventory.getItemInMainHand().getType() == Material.SHEARS;
|
||||||
|
boolean isOffHand = inventory.getItemInOffHand().getType() == Material.SHEARS;
|
||||||
|
if (isMain && isOffHand) {
|
||||||
|
inventory.getItemInMainHand().setItemMeta(newShears);
|
||||||
|
} else if (isMain) {
|
||||||
|
inventory.getItemInMainHand().setItemMeta(newShears);
|
||||||
|
} else if (isOffHand) {
|
||||||
|
inventory.getItemInOffHand().setItemMeta(newShears);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* Adds tags to shears.
|
|
||||||
*
|
|
||||||
* @param newShears The shears.
|
|
||||||
*/
|
|
||||||
private void addLore(ItemStack newShears) {
|
|
||||||
ItemMeta meta = newShears.getItemMeta();
|
|
||||||
if (meta == null) {
|
|
||||||
toolStats.logger.warning(newShears + " does NOT have any meta! Unable to update stats.");
|
|
||||||
return;
|
|
||||||
}
|
}
|
||||||
Integer sheepSheared = 0;
|
|
||||||
PersistentDataContainer container = meta.getPersistentDataContainer();
|
|
||||||
if (container.has(toolStats.shearsSheared, PersistentDataType.INTEGER)) {
|
|
||||||
sheepSheared = container.get(toolStats.shearsSheared, PersistentDataType.INTEGER);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (sheepSheared == null) {
|
|
||||||
sheepSheared = 0;
|
|
||||||
toolStats.logger.warning(newShears + " does not have valid sheared set! Resting to zero. This should NEVER happen.");
|
|
||||||
}
|
|
||||||
|
|
||||||
sheepSheared++;
|
|
||||||
container.set(toolStats.shearsSheared, PersistentDataType.INTEGER, sheepSheared);
|
|
||||||
|
|
||||||
String sheepShearedFormatted = toolStats.numberFormat.formatInt(sheepSheared);
|
|
||||||
List<String> newLore = toolStats.itemLore.addItemLore(meta, "{sheep}", sheepShearedFormatted, "sheep-sheared");
|
|
||||||
|
|
||||||
if (toolStats.config.getBoolean("enabled.sheep-sheared")) {
|
|
||||||
meta.setLore(newLore);
|
|
||||||
}
|
|
||||||
newShears.setItemMeta(meta);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
73
src/main/java/lol/hyper/toolstats/events/ShootBow.java
Normal file
@@ -0,0 +1,73 @@
|
|||||||
|
/*
|
||||||
|
* This file is part of ToolStats.
|
||||||
|
*
|
||||||
|
* ToolStats is free software: you can redistribute it and/or modify
|
||||||
|
* it under the terms of the GNU General Public License as published by
|
||||||
|
* the Free Software Foundation, either version 3 of the License, or
|
||||||
|
* (at your option) any later version.
|
||||||
|
*
|
||||||
|
* ToolStats is distributed in the hope that it will be useful,
|
||||||
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
* GNU General Public License for more details.
|
||||||
|
*
|
||||||
|
* You should have received a copy of the GNU General Public License
|
||||||
|
* along with ToolStats. If not, see <https://www.gnu.org/licenses/>.
|
||||||
|
*/
|
||||||
|
|
||||||
|
package lol.hyper.toolstats.events;
|
||||||
|
|
||||||
|
import lol.hyper.toolstats.ToolStats;
|
||||||
|
import org.bukkit.GameMode;
|
||||||
|
import org.bukkit.Material;
|
||||||
|
import org.bukkit.entity.Entity;
|
||||||
|
import org.bukkit.entity.Player;
|
||||||
|
import org.bukkit.event.EventHandler;
|
||||||
|
import org.bukkit.event.EventPriority;
|
||||||
|
import org.bukkit.event.Listener;
|
||||||
|
import org.bukkit.event.entity.EntityShootBowEvent;
|
||||||
|
import org.bukkit.inventory.ItemStack;
|
||||||
|
import org.bukkit.inventory.PlayerInventory;
|
||||||
|
import org.bukkit.inventory.meta.ItemMeta;
|
||||||
|
|
||||||
|
public class ShootBow implements Listener {
|
||||||
|
|
||||||
|
private final ToolStats toolStats;
|
||||||
|
|
||||||
|
public ShootBow(ToolStats toolStats) {
|
||||||
|
this.toolStats = toolStats;
|
||||||
|
}
|
||||||
|
|
||||||
|
@EventHandler(priority = EventPriority.MONITOR)
|
||||||
|
public void onShoot(EntityShootBowEvent event) {
|
||||||
|
Entity shooter = event.getEntity();
|
||||||
|
// only listen for players
|
||||||
|
if (!(shooter instanceof Player player)) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (player.getGameMode() == GameMode.CREATIVE && !toolStats.config.getBoolean("allow-creative")) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
ItemStack heldBow = toolStats.itemChecker.getBow(player.getInventory());
|
||||||
|
// player swapped or we can't get the bow
|
||||||
|
if (heldBow == null) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
ItemMeta newBow = toolStats.itemLore.updateArrowsShot(heldBow, 1);
|
||||||
|
if (newBow != null) {
|
||||||
|
PlayerInventory inventory = player.getInventory();
|
||||||
|
boolean isMain = inventory.getItemInMainHand().getType() == Material.BOW || inventory.getItemInMainHand().getType() == Material.CROSSBOW;
|
||||||
|
boolean isOffHand = inventory.getItemInOffHand().getType() == Material.BOW || inventory.getItemInOffHand().getType() == Material.CROSSBOW;
|
||||||
|
if (isMain && isOffHand) {
|
||||||
|
inventory.getItemInMainHand().setItemMeta(newBow);
|
||||||
|
} else if (isMain) {
|
||||||
|
inventory.getItemInMainHand().setItemMeta(newBow);
|
||||||
|
} else if (isOffHand) {
|
||||||
|
inventory.getItemInOffHand().setItemMeta(newBow);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -17,12 +17,11 @@
|
|||||||
|
|
||||||
package lol.hyper.toolstats.events;
|
package lol.hyper.toolstats.events;
|
||||||
|
|
||||||
|
import lol.hyper.hyperlib.datatypes.UUIDDataType;
|
||||||
import lol.hyper.toolstats.ToolStats;
|
import lol.hyper.toolstats.ToolStats;
|
||||||
import lol.hyper.toolstats.tools.ItemChecker;
|
import net.kyori.adventure.text.Component;
|
||||||
import lol.hyper.toolstats.tools.UUIDDataType;
|
|
||||||
import org.bukkit.Bukkit;
|
|
||||||
import org.bukkit.ChatColor;
|
|
||||||
import org.bukkit.GameMode;
|
import org.bukkit.GameMode;
|
||||||
|
import org.bukkit.Material;
|
||||||
import org.bukkit.entity.Player;
|
import org.bukkit.entity.Player;
|
||||||
import org.bukkit.event.EventHandler;
|
import org.bukkit.event.EventHandler;
|
||||||
import org.bukkit.event.EventPriority;
|
import org.bukkit.event.EventPriority;
|
||||||
@@ -36,6 +35,7 @@ import org.bukkit.inventory.meta.ItemMeta;
|
|||||||
import org.bukkit.persistence.PersistentDataContainer;
|
import org.bukkit.persistence.PersistentDataContainer;
|
||||||
import org.bukkit.persistence.PersistentDataType;
|
import org.bukkit.persistence.PersistentDataType;
|
||||||
|
|
||||||
|
import java.util.ArrayList;
|
||||||
import java.util.Date;
|
import java.util.Date;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
@@ -53,37 +53,64 @@ public class VillagerTrade implements Listener {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
Inventory inventory = event.getClickedInventory();
|
Inventory inventory = event.getClickedInventory();
|
||||||
if (!(event.getWhoClicked() instanceof Player)) {
|
if (!(event.getWhoClicked() instanceof Player player)) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
Player player = (Player) event.getWhoClicked();
|
|
||||||
if (player.getGameMode() == GameMode.CREATIVE || player.getGameMode() == GameMode.SPECTATOR) {
|
if (player.getGameMode() == GameMode.CREATIVE || player.getGameMode() == GameMode.SPECTATOR) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
// only check villager inventories
|
// only check villager inventories
|
||||||
if (inventory instanceof MerchantInventory) {
|
if (!(inventory instanceof MerchantInventory)) {
|
||||||
// only check the result slot (the item you receive)
|
|
||||||
if (event.getSlotType() == InventoryType.SlotType.RESULT) {
|
|
||||||
ItemStack item = event.getCurrentItem();
|
|
||||||
// only check items we want
|
|
||||||
if (!ItemChecker.isValidItem(item.getType())) {
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
// if the player shift clicks, show the warning
|
// only check the result slot (the item you receive)
|
||||||
|
if (event.getSlotType() != InventoryType.SlotType.RESULT) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
ItemStack tradedItem = event.getCurrentItem();
|
||||||
|
Material tradedMaterial = tradedItem.getType();
|
||||||
|
// only check items we want
|
||||||
|
if (!toolStats.itemChecker.isValidItem(tradedMaterial)) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
// if the player shift clicks
|
||||||
if (event.isShiftClick()) {
|
if (event.isShiftClick()) {
|
||||||
String configMessage = toolStats.config.getString("messages.shift-click-warning.trading");
|
// store the player inventory before they trade the items
|
||||||
if (configMessage != null) {
|
ItemStack[] beforeTrade = player.getInventory().getContents();
|
||||||
player.sendMessage(ChatColor.translateAlternateColorCodes('&', configMessage));
|
// run a tick after to see the changes
|
||||||
|
player.getScheduler().runDelayed(toolStats, scheduledTask -> {
|
||||||
|
// get their inventory after the trade
|
||||||
|
ItemStack[] afterTrade = player.getInventory().getContents();
|
||||||
|
for (int i = 0; i < afterTrade.length; i++) {
|
||||||
|
ItemStack newSlotItem = afterTrade[i];
|
||||||
|
ItemStack oldSlotItem = beforeTrade[i];
|
||||||
|
|
||||||
|
// if this slot is empty after trading, skip it
|
||||||
|
if (newSlotItem == null) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
// if the item matches what we traded
|
||||||
|
if (newSlotItem.getType() == tradedMaterial) {
|
||||||
|
// if the slot was empty before we traded, this means we just traded it
|
||||||
|
if (oldSlotItem == null) {
|
||||||
|
// add the lore
|
||||||
|
ItemStack newItem = addTradeOrigin(newSlotItem, player);
|
||||||
|
if (newItem != null) {
|
||||||
|
player.getInventory().setItem(i, newItem);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
ItemStack newItem = addLore(item, player);
|
}
|
||||||
|
}
|
||||||
|
}, null, 1);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
ItemStack newItem = addTradeOrigin(tradedItem, player);
|
||||||
if (newItem != null) {
|
if (newItem != null) {
|
||||||
// set the new item
|
// set the new item
|
||||||
inventory.setItem(event.getSlot(), newItem);
|
inventory.setItem(event.getSlot(), newItem);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Adds "traded by" tags to item.
|
* Adds "traded by" tags to item.
|
||||||
@@ -92,30 +119,58 @@ public class VillagerTrade implements Listener {
|
|||||||
* @param owner The player who traded.
|
* @param owner The player who traded.
|
||||||
* @return The item with lore.
|
* @return The item with lore.
|
||||||
*/
|
*/
|
||||||
private ItemStack addLore(ItemStack oldItem, Player owner) {
|
private ItemStack addTradeOrigin(ItemStack oldItem, Player owner) {
|
||||||
ItemStack newItem = oldItem.clone();
|
ItemStack newItem = oldItem.clone();
|
||||||
ItemMeta meta = newItem.getItemMeta();
|
ItemMeta meta = newItem.getItemMeta();
|
||||||
if (meta == null) {
|
if (meta == null) {
|
||||||
toolStats.logger.warning(newItem + " does NOT have any meta! Unable to update stats.");
|
toolStats.logger.warn("{} does NOT have any meta! Unable to update stats.", newItem);
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
long timeCreated = System.currentTimeMillis();
|
long timeCreated = System.currentTimeMillis();
|
||||||
Date finalDate = new Date(timeCreated);
|
Date finalDate;
|
||||||
|
if (toolStats.config.getBoolean("normalize-time-creation")) {
|
||||||
|
finalDate = toolStats.numberFormat.normalizeTime(timeCreated);
|
||||||
|
timeCreated = finalDate.getTime();
|
||||||
|
}
|
||||||
PersistentDataContainer container = meta.getPersistentDataContainer();
|
PersistentDataContainer container = meta.getPersistentDataContainer();
|
||||||
|
|
||||||
if (container.has(toolStats.timeCreated, PersistentDataType.LONG) || container.has(toolStats.genericOwner, PersistentDataType.LONG)) {
|
if (container.has(toolStats.timeCreated, PersistentDataType.LONG) || container.has(toolStats.itemOwner, PersistentDataType.LONG)) {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
container.set(toolStats.timeCreated, PersistentDataType.LONG, timeCreated);
|
// get the current lore the item
|
||||||
container.set(toolStats.genericOwner, new UUIDDataType(), owner.getUniqueId());
|
List<Component> lore;
|
||||||
|
if (meta.hasLore()) {
|
||||||
String formattedDate = toolStats.numberFormat.formatDate(finalDate);
|
lore = meta.lore();
|
||||||
List<String> newLore = toolStats.itemLore.addNewOwner(meta, owner.getName(), formattedDate, "TRADED");
|
} else {
|
||||||
|
lore = new ArrayList<>();
|
||||||
if (toolStats.checkConfig(newItem, "traded-tag")) {
|
|
||||||
meta.setLore(newLore);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
// if creation date is enabled, add it
|
||||||
|
Component creationDate = toolStats.itemLore.formatCreationTime(timeCreated, 3, newItem);
|
||||||
|
if (creationDate != null) {
|
||||||
|
container.set(toolStats.timeCreated, PersistentDataType.LONG, timeCreated);
|
||||||
|
container.set(toolStats.originType, PersistentDataType.INTEGER, 3);
|
||||||
|
lore.add(creationDate);
|
||||||
|
meta.lore(lore);
|
||||||
|
}
|
||||||
|
|
||||||
|
// if ownership is enabled, add it
|
||||||
|
Component itemOwner = toolStats.itemLore.formatOwner(owner.getName(), 3, newItem);
|
||||||
|
if (itemOwner != null) {
|
||||||
|
container.set(toolStats.itemOwner, new UUIDDataType(), owner.getUniqueId());
|
||||||
|
container.set(toolStats.originType, PersistentDataType.INTEGER, 3);
|
||||||
|
lore.add(itemOwner);
|
||||||
|
meta.lore(lore);
|
||||||
|
}
|
||||||
|
|
||||||
|
// if hash is enabled, add it
|
||||||
|
if (toolStats.config.getBoolean("generate-hash-for-items")) {
|
||||||
|
String hash = toolStats.hashMaker.makeHash(newItem.getType(), owner.getUniqueId(), timeCreated);
|
||||||
|
container.set(toolStats.hash, PersistentDataType.STRING, hash);
|
||||||
|
}
|
||||||
|
|
||||||
newItem.setItemMeta(meta);
|
newItem.setItemMeta(meta);
|
||||||
return newItem;
|
return newItem;
|
||||||
}
|
}
|
||||||
|
|||||||
60
src/main/java/lol/hyper/toolstats/tools/HashMaker.java
Normal file
@@ -0,0 +1,60 @@
|
|||||||
|
/*
|
||||||
|
* This file is part of ToolStats.
|
||||||
|
*
|
||||||
|
* ToolStats is free software: you can redistribute it and/or modify
|
||||||
|
* it under the terms of the GNU General Public License as published by
|
||||||
|
* the Free Software Foundation, either version 3 of the License, or
|
||||||
|
* (at your option) any later version.
|
||||||
|
*
|
||||||
|
* ToolStats is distributed in the hope that it will be useful,
|
||||||
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
* GNU General Public License for more details.
|
||||||
|
*
|
||||||
|
* You should have received a copy of the GNU General Public License
|
||||||
|
* along with ToolStats. If not, see <https://www.gnu.org/licenses/>.
|
||||||
|
*/
|
||||||
|
|
||||||
|
package lol.hyper.toolstats.tools;
|
||||||
|
|
||||||
|
import lol.hyper.toolstats.ToolStats;
|
||||||
|
import org.bukkit.Material;
|
||||||
|
|
||||||
|
import java.nio.charset.StandardCharsets;
|
||||||
|
import java.security.MessageDigest;
|
||||||
|
import java.security.NoSuchAlgorithmException;
|
||||||
|
import java.util.UUID;
|
||||||
|
|
||||||
|
public class HashMaker {
|
||||||
|
|
||||||
|
private final ToolStats toolStats;
|
||||||
|
|
||||||
|
public HashMaker(ToolStats toolStats) {
|
||||||
|
this.toolStats = toolStats;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String makeHash(Material itemType, UUID player, long timestamp) {
|
||||||
|
String input = itemType.toString() + player.toString() + timestamp;
|
||||||
|
|
||||||
|
try {
|
||||||
|
MessageDigest md = MessageDigest.getInstance("SHA-256");
|
||||||
|
byte[] hashBytes = md.digest(input.getBytes(StandardCharsets.UTF_8));
|
||||||
|
|
||||||
|
StringBuilder hexString = new StringBuilder();
|
||||||
|
for (byte b : hashBytes) {
|
||||||
|
String hex = Integer.toHexString(0xff & b);
|
||||||
|
if (hex.length() == 1) {
|
||||||
|
hexString.append('0');
|
||||||
|
}
|
||||||
|
hexString.append(hex);
|
||||||
|
}
|
||||||
|
|
||||||
|
return hexString.toString();
|
||||||
|
} catch (NoSuchAlgorithmException exception) {
|
||||||
|
toolStats.logger.error("Unable to generate hash", exception);
|
||||||
|
toolStats.logger.warn("Unable to generate hash for {}!", player);
|
||||||
|
toolStats.logger.warn("Generating a random UUID instead.");
|
||||||
|
return java.util.UUID.randomUUID().toString();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -17,17 +17,65 @@
|
|||||||
|
|
||||||
package lol.hyper.toolstats.tools;
|
package lol.hyper.toolstats.tools;
|
||||||
|
|
||||||
|
import io.papermc.paper.datacomponent.DataComponentTypes;
|
||||||
|
import lol.hyper.toolstats.ToolStats;
|
||||||
import org.bukkit.Material;
|
import org.bukkit.Material;
|
||||||
|
import org.bukkit.NamespacedKey;
|
||||||
|
import org.bukkit.inventory.ItemStack;
|
||||||
|
import org.bukkit.inventory.PlayerInventory;
|
||||||
|
import org.bukkit.inventory.meta.ItemMeta;
|
||||||
|
import org.bukkit.persistence.PersistentDataContainer;
|
||||||
|
import org.bukkit.persistence.PersistentDataType;
|
||||||
|
import org.jetbrains.annotations.Nullable;
|
||||||
|
|
||||||
import java.util.Arrays;
|
import java.util.*;
|
||||||
import java.util.Locale;
|
|
||||||
|
|
||||||
public class ItemChecker {
|
public class ItemChecker {
|
||||||
|
|
||||||
private static final String[] validItems = { "pickaxe", "sword", "shovel", "axe", "hoe", "bow", "helmet", "chestplate", "leggings", "boots", "fishing" };
|
private final List<Material> validItems = new ArrayList<>();
|
||||||
private static final String[] validArmor = { "helmet", "chestplate", "leggings", "boots" };
|
private final List<Material> armorItems = new ArrayList<>();
|
||||||
private static final String[] validMelee = {"sword", "trident", "axe"};
|
private final List<Material> meleeItems = new ArrayList<>();
|
||||||
private static final String[] validMine = { "pickaxe", "axe", "hoe", "shovel", "shear" };
|
private final List<Material> mineItems = new ArrayList<>();
|
||||||
|
private final ToolStats toolStats;
|
||||||
|
|
||||||
|
public ItemChecker(ToolStats toolStats) {
|
||||||
|
this.toolStats = toolStats;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Set up the item checker.
|
||||||
|
*/
|
||||||
|
public void setup() {
|
||||||
|
for (Material material : Material.values()) {
|
||||||
|
String lowerCase = material.toString().toLowerCase(Locale.ROOT);
|
||||||
|
if (lowerCase.contains("_pickaxe") || lowerCase.contains("_axe") || lowerCase.contains("_hoe") || lowerCase.contains("_shovel")) {
|
||||||
|
mineItems.add(material);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (lowerCase.contains("_sword") || lowerCase.contains("_axe")) {
|
||||||
|
meleeItems.add(material);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (lowerCase.contains("_helmet") || lowerCase.contains("_chestplate") || lowerCase.contains("_leggings") || lowerCase.contains("_boots")) {
|
||||||
|
armorItems.add(material);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// hardcode these
|
||||||
|
mineItems.add(Material.SHEARS);
|
||||||
|
meleeItems.add(Material.TRIDENT);
|
||||||
|
meleeItems.add(Material.MACE);
|
||||||
|
|
||||||
|
validItems.add(Material.BOW);
|
||||||
|
validItems.add(Material.CROSSBOW);
|
||||||
|
validItems.add(Material.FISHING_ROD);
|
||||||
|
validItems.add(Material.ELYTRA);
|
||||||
|
|
||||||
|
// combine the lists
|
||||||
|
validItems.addAll(armorItems);
|
||||||
|
validItems.addAll(meleeItems);
|
||||||
|
validItems.addAll(mineItems);
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Check if item is an armor piece.
|
* Check if item is an armor piece.
|
||||||
@@ -35,8 +83,8 @@ public class ItemChecker {
|
|||||||
* @param itemType The item type, not name.
|
* @param itemType The item type, not name.
|
||||||
* @return If the item is an armor piece.
|
* @return If the item is an armor piece.
|
||||||
*/
|
*/
|
||||||
public static boolean isArmor(Material itemType) {
|
public boolean isArmor(Material itemType) {
|
||||||
return Arrays.stream(validArmor).anyMatch(type -> itemType.toString().toLowerCase(Locale.ROOT).contains(type));
|
return armorItems.contains(itemType);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -45,8 +93,8 @@ public class ItemChecker {
|
|||||||
* @param itemType The item type, not name.
|
* @param itemType The item type, not name.
|
||||||
* @return If the item something we want to track.
|
* @return If the item something we want to track.
|
||||||
*/
|
*/
|
||||||
public static boolean isValidItem(Material itemType) {
|
public boolean isValidItem(Material itemType) {
|
||||||
return Arrays.stream(validItems).anyMatch(type -> itemType.toString().toLowerCase(Locale.ROOT).contains(type));
|
return validItems.contains(itemType);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -55,8 +103,8 @@ public class ItemChecker {
|
|||||||
* @param itemType The item type, not name.
|
* @param itemType The item type, not name.
|
||||||
* @return If the item is a melee weapon.
|
* @return If the item is a melee weapon.
|
||||||
*/
|
*/
|
||||||
public static boolean isMeleeWeapon(Material itemType) {
|
public boolean isMeleeWeapon(Material itemType) {
|
||||||
return Arrays.stream(validMelee).anyMatch(type -> itemType.toString().toLowerCase(Locale.ROOT).contains(type));
|
return meleeItems.contains(itemType);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -65,7 +113,279 @@ public class ItemChecker {
|
|||||||
* @param itemType The item type, not name.
|
* @param itemType The item type, not name.
|
||||||
* @return If the item is a mining tool.
|
* @return If the item is a mining tool.
|
||||||
*/
|
*/
|
||||||
public static boolean isMineTool(Material itemType) {
|
public boolean isMineTool(Material itemType) {
|
||||||
return Arrays.stream(validMine).anyMatch(type -> itemType.toString().toLowerCase(Locale.ROOT).contains(type));
|
return mineItems.contains(itemType);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* In newer versions of Minecraft, you can make items glide, which works
|
||||||
|
* like an Elytra.
|
||||||
|
*
|
||||||
|
* @param itemStack The item to check.
|
||||||
|
* @return True/false if the item can glide like an Elytra.
|
||||||
|
*/
|
||||||
|
public boolean canGlide(ItemStack itemStack) {
|
||||||
|
// if it's an elytra, we are good
|
||||||
|
if (itemStack.getType() == Material.ELYTRA) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
// otherwise if it has the GLIDER data
|
||||||
|
return itemStack.hasData(DataComponentTypes.GLIDER);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Check a given item for a target token.
|
||||||
|
*
|
||||||
|
* @param container The PDC of the item.
|
||||||
|
* @param targetToken The target to look for.
|
||||||
|
* @return True if the item has a given token, false if not.
|
||||||
|
*/
|
||||||
|
public boolean checkTokens(PersistentDataContainer container, String targetToken) {
|
||||||
|
// make sure the item has tokens
|
||||||
|
if (!container.has(toolStats.tokenApplied, PersistentDataType.STRING)) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
// get the tokens for this item
|
||||||
|
String tokens = container.get(toolStats.tokenApplied, PersistentDataType.STRING);
|
||||||
|
if (tokens == null) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
return tokens.contains(targetToken);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get the tokens for a given item.
|
||||||
|
*
|
||||||
|
* @param item The item.
|
||||||
|
* @return An array of the tokens, empty if there are none.
|
||||||
|
*/
|
||||||
|
private String[] getTokens(ItemStack item) {
|
||||||
|
// make sure the item has tokens
|
||||||
|
ItemMeta meta = item.getItemMeta();
|
||||||
|
if (meta == null) {
|
||||||
|
return new String[0];
|
||||||
|
}
|
||||||
|
PersistentDataContainer container = meta.getPersistentDataContainer();
|
||||||
|
if (!container.has(toolStats.tokenApplied, PersistentDataType.STRING)) {
|
||||||
|
return new String[0];
|
||||||
|
}
|
||||||
|
|
||||||
|
// get the tokens for this item
|
||||||
|
String tokensRaw = container.get(toolStats.tokenApplied, PersistentDataType.STRING);
|
||||||
|
if (tokensRaw == null) {
|
||||||
|
return new String[0];
|
||||||
|
}
|
||||||
|
|
||||||
|
return tokensRaw.split(",");
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Add a token to an item.
|
||||||
|
*
|
||||||
|
* @param item The item.
|
||||||
|
* @param token The token to add.
|
||||||
|
* @return The new PDC with the new token. Null if something went wrong.
|
||||||
|
*/
|
||||||
|
public ItemStack addToken(ItemStack item, String token) {
|
||||||
|
ItemMeta meta = item.getItemMeta();
|
||||||
|
if (meta == null) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
PersistentDataContainer container = meta.getPersistentDataContainer();
|
||||||
|
String[] tokens = getTokens(item);
|
||||||
|
// there are no tokens
|
||||||
|
if (tokens.length == 0) {
|
||||||
|
container.set(toolStats.tokenApplied, PersistentDataType.STRING, token);
|
||||||
|
} else {
|
||||||
|
// other tokens exist, so add
|
||||||
|
String[] newTokens = Arrays.copyOf(tokens, tokens.length + 1);
|
||||||
|
newTokens[tokens.length] = token;
|
||||||
|
container.set(toolStats.tokenApplied, PersistentDataType.STRING, String.join(",", newTokens));
|
||||||
|
}
|
||||||
|
item.setItemMeta(meta);
|
||||||
|
return item;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get the XP levels required to use token in anvil.
|
||||||
|
*
|
||||||
|
* @param tokenType The token type.
|
||||||
|
* @return The amount of levels to use.
|
||||||
|
*/
|
||||||
|
public int getCost(String tokenType) {
|
||||||
|
return toolStats.config.getInt("tokens.data." + tokenType + ".levels");
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get the player's bow/crossbow.
|
||||||
|
*
|
||||||
|
* @param inventory Their inventory.
|
||||||
|
* @return Their bow/crossbow, either main or offhand.
|
||||||
|
*/
|
||||||
|
public @Nullable ItemStack getBow(PlayerInventory inventory) {
|
||||||
|
ItemStack main = inventory.getItemInMainHand();
|
||||||
|
ItemStack offHand = inventory.getItemInOffHand();
|
||||||
|
|
||||||
|
boolean isMain = main.getType() == Material.BOW || main.getType() == Material.CROSSBOW;
|
||||||
|
boolean isOffHand = offHand.getType() == Material.BOW || offHand.getType() == Material.CROSSBOW;
|
||||||
|
|
||||||
|
// if the player is holding a bow in their main hand, use that one
|
||||||
|
// if the bow is in their offhand instead, use that one after checking main hand
|
||||||
|
// Minecraft prioritizes main hand if the player holds in both hands
|
||||||
|
if (isMain && isOffHand) {
|
||||||
|
return main;
|
||||||
|
}
|
||||||
|
if (isMain) {
|
||||||
|
return main;
|
||||||
|
}
|
||||||
|
if (isOffHand) {
|
||||||
|
return offHand;
|
||||||
|
}
|
||||||
|
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get the player's shears.
|
||||||
|
*
|
||||||
|
* @param inventory Their inventory.
|
||||||
|
* @return Their shears, either main or offhand.
|
||||||
|
*/
|
||||||
|
public @Nullable ItemStack getShears(PlayerInventory inventory) {
|
||||||
|
ItemStack main = inventory.getItemInMainHand();
|
||||||
|
ItemStack offHand = inventory.getItemInOffHand();
|
||||||
|
|
||||||
|
boolean isMain = main.getType() == Material.SHEARS;
|
||||||
|
boolean isOffHand = offHand.getType() == Material.SHEARS;
|
||||||
|
|
||||||
|
// if the player is holding shears in their main hand, use that one
|
||||||
|
// if the shears are in their offhand instead, use that one after checking main hand
|
||||||
|
// Minecraft prioritizes main hand if the player holds in both hands
|
||||||
|
if (isMain && isOffHand) {
|
||||||
|
return main;
|
||||||
|
}
|
||||||
|
if (isMain) {
|
||||||
|
return main;
|
||||||
|
}
|
||||||
|
if (isOffHand) {
|
||||||
|
return offHand;
|
||||||
|
}
|
||||||
|
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get the player's fishing rod.
|
||||||
|
*
|
||||||
|
* @param inventory Their inventory.
|
||||||
|
* @return Their fishing rod, either main or offhand.
|
||||||
|
*/
|
||||||
|
public @Nullable ItemStack getFishingRod(PlayerInventory inventory) {
|
||||||
|
ItemStack main = inventory.getItemInMainHand();
|
||||||
|
ItemStack offHand = inventory.getItemInOffHand();
|
||||||
|
|
||||||
|
boolean isMain = main.getType() == Material.FISHING_ROD;
|
||||||
|
boolean isOffHand = offHand.getType() == Material.FISHING_ROD;
|
||||||
|
|
||||||
|
// if the player is holding a fishing rod in their main hand, use that one
|
||||||
|
// if the fishing rod is in their offhand instead, use that one after checking main hand
|
||||||
|
// Minecraft prioritizes main hand if the player holds in both hands
|
||||||
|
if (isMain && isOffHand) {
|
||||||
|
return main;
|
||||||
|
}
|
||||||
|
if (isMain) {
|
||||||
|
return main;
|
||||||
|
}
|
||||||
|
if (isOffHand) {
|
||||||
|
return offHand;
|
||||||
|
}
|
||||||
|
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Checks the keys of the item and returns the tokens we should add.
|
||||||
|
* If the server swaps token systems this should allow compatability.
|
||||||
|
*
|
||||||
|
* @param item The input item.
|
||||||
|
* @return The tokens we should add.
|
||||||
|
*/
|
||||||
|
public String addTokensToExisting(ItemStack item) {
|
||||||
|
ItemStack clone = item.clone();
|
||||||
|
ItemMeta meta = clone.getItemMeta();
|
||||||
|
if (meta == null) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
PersistentDataContainer container = meta.getPersistentDataContainer();
|
||||||
|
ArrayList<String> tokens = new ArrayList<>();
|
||||||
|
if (container.has(toolStats.playerKills)) {
|
||||||
|
tokens.add("player-kills");
|
||||||
|
}
|
||||||
|
if (container.has(toolStats.mobKills)) {
|
||||||
|
tokens.add("mob-kills");
|
||||||
|
}
|
||||||
|
if (container.has(toolStats.blocksMined)) {
|
||||||
|
tokens.add("blocks-mined");
|
||||||
|
}
|
||||||
|
if (container.has(toolStats.cropsHarvested)) {
|
||||||
|
tokens.add("crops-mined");
|
||||||
|
}
|
||||||
|
if (container.has(toolStats.fishCaught)) {
|
||||||
|
tokens.add("fish-caught");
|
||||||
|
}
|
||||||
|
if (container.has(toolStats.sheepSheared)) {
|
||||||
|
tokens.add("sheep-sheared");
|
||||||
|
}
|
||||||
|
if (container.has(toolStats.armorDamage)) {
|
||||||
|
tokens.add("damage-taken");
|
||||||
|
}
|
||||||
|
if (container.has(toolStats.arrowsShot)) {
|
||||||
|
tokens.add("arrows-shot");
|
||||||
|
}
|
||||||
|
if (container.has(toolStats.flightTime)) {
|
||||||
|
tokens.add("flight-time");
|
||||||
|
}
|
||||||
|
if (container.has(toolStats.damageDone)) {
|
||||||
|
tokens.add("damage-done");
|
||||||
|
}
|
||||||
|
if (tokens.isEmpty()) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
return String.join(",", tokens);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Remove a given token from a list of tokens.
|
||||||
|
*
|
||||||
|
* @param appliedTokens The tokens on the item.
|
||||||
|
* @param toRemove The token to remove.
|
||||||
|
* @return The list of tokens.
|
||||||
|
*/
|
||||||
|
public List<String> removeToken(String appliedTokens, String toRemove) {
|
||||||
|
// remove the tokens if they exist
|
||||||
|
List<String> tokenList = new ArrayList<>(Arrays.asList(appliedTokens.split(",")));
|
||||||
|
tokenList.remove(toRemove);
|
||||||
|
|
||||||
|
if (tokenList.isEmpty()) {
|
||||||
|
return Collections.emptyList();
|
||||||
|
} else {
|
||||||
|
return tokenList;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Check to see if a given container has our keys for stats.
|
||||||
|
*
|
||||||
|
* @param container The container.
|
||||||
|
* @return True/false if the container has keys.
|
||||||
|
*/
|
||||||
|
public boolean keyCheck(PersistentDataContainer container) {
|
||||||
|
return container.getKeys().stream()
|
||||||
|
.map(NamespacedKey::getKey)
|
||||||
|
.anyMatch(key -> toolStats.tokenKeys.stream().anyMatch(tokenKey -> tokenKey.getKey().equalsIgnoreCase(key)));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -22,8 +22,14 @@ import lol.hyper.toolstats.ToolStats;
|
|||||||
import java.text.DecimalFormat;
|
import java.text.DecimalFormat;
|
||||||
import java.text.DecimalFormatSymbols;
|
import java.text.DecimalFormatSymbols;
|
||||||
import java.text.SimpleDateFormat;
|
import java.text.SimpleDateFormat;
|
||||||
|
import java.time.Instant;
|
||||||
|
import java.time.LocalDate;
|
||||||
|
import java.time.ZoneId;
|
||||||
|
import java.time.ZonedDateTime;
|
||||||
import java.util.Date;
|
import java.util.Date;
|
||||||
|
import java.util.HashMap;
|
||||||
import java.util.Locale;
|
import java.util.Locale;
|
||||||
|
import java.util.Map;
|
||||||
|
|
||||||
public class NumberFormat {
|
public class NumberFormat {
|
||||||
|
|
||||||
@@ -33,6 +39,7 @@ public class NumberFormat {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Utility class to format different numbers
|
* Utility class to format different numbers
|
||||||
|
*
|
||||||
* @param toolStats Plugin instance.
|
* @param toolStats Plugin instance.
|
||||||
*/
|
*/
|
||||||
public NumberFormat(ToolStats toolStats) {
|
public NumberFormat(ToolStats toolStats) {
|
||||||
@@ -46,35 +53,35 @@ public class NumberFormat {
|
|||||||
// if these config values are missing, use the default ones
|
// if these config values are missing, use the default ones
|
||||||
if (dateFormat == null) {
|
if (dateFormat == null) {
|
||||||
dateFormat = "M/dd/yyyy";
|
dateFormat = "M/dd/yyyy";
|
||||||
toolStats.logger.warning("date-format is missing! Using default American English format.");
|
toolStats.logger.warn("date-format is missing! Using default American English format.");
|
||||||
}
|
}
|
||||||
|
|
||||||
if (decimalSeparator == null) {
|
if (decimalSeparator == null) {
|
||||||
decimalSeparator = ".";
|
decimalSeparator = ".";
|
||||||
toolStats.logger.warning("number-formats.decimal-separator is missing! Using default \".\" instead.");
|
toolStats.logger.warn("number-formats.decimal-separator is missing! Using default \".\" instead.");
|
||||||
}
|
}
|
||||||
|
|
||||||
if (commaSeparator == null) {
|
if (commaSeparator == null) {
|
||||||
commaSeparator = ",";
|
commaSeparator = ",";
|
||||||
toolStats.logger.warning("number-formats.comma-separator is missing! Using default \",\" instead.");
|
toolStats.logger.warn("number-formats.comma-separator is missing! Using default \",\" instead.");
|
||||||
}
|
}
|
||||||
|
|
||||||
if (commaFormat == null) {
|
if (commaFormat == null) {
|
||||||
commaFormat = "#,###";
|
commaFormat = "#,###";
|
||||||
toolStats.logger.warning("number-formats.comma-format is missing! Using default #,### instead.");
|
toolStats.logger.warn("number-formats.comma-format is missing! Using default #,### instead.");
|
||||||
}
|
}
|
||||||
|
|
||||||
if (decimalFormat == null) {
|
if (decimalFormat == null) {
|
||||||
decimalFormat = "#,###.00";
|
decimalFormat = "#,##0.00";
|
||||||
toolStats.logger.warning("number-formats.comma-separator is missing! Using default #,###.00 instead.");
|
toolStats.logger.warn("number-formats.comma-separator is missing! Using default #,###.00 instead.");
|
||||||
}
|
}
|
||||||
|
|
||||||
// test the date format
|
// test the date format
|
||||||
try {
|
try {
|
||||||
DATE_FORMAT = new SimpleDateFormat(dateFormat, Locale.getDefault());
|
DATE_FORMAT = new SimpleDateFormat(dateFormat, Locale.getDefault());
|
||||||
} catch (NullPointerException | IllegalArgumentException exception) {
|
} catch (NullPointerException | IllegalArgumentException exception) {
|
||||||
toolStats.logger.warning("date-format is NOT a valid format! Using default American English format.");
|
toolStats.logger.error("Invalid format or missing format", exception);
|
||||||
exception.printStackTrace();
|
toolStats.logger.warn("date-format is NOT a valid format! Using default American English format.");
|
||||||
DATE_FORMAT = new SimpleDateFormat("M/dd/yyyy", Locale.ENGLISH);
|
DATE_FORMAT = new SimpleDateFormat("M/dd/yyyy", Locale.ENGLISH);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -88,8 +95,8 @@ public class NumberFormat {
|
|||||||
try {
|
try {
|
||||||
COMMA_FORMAT = new DecimalFormat(commaFormat, formatSymbols);
|
COMMA_FORMAT = new DecimalFormat(commaFormat, formatSymbols);
|
||||||
} catch (NullPointerException | IllegalArgumentException exception) {
|
} catch (NullPointerException | IllegalArgumentException exception) {
|
||||||
toolStats.logger.warning("number-formats.comma-format is NOT a valid format! Using default #,### instead.");
|
toolStats.logger.error("Invalid comma or missing format", exception);
|
||||||
exception.printStackTrace();
|
toolStats.logger.warn("number-formats.comma-format is NOT a valid format! Using default #,### instead.");
|
||||||
COMMA_FORMAT = new DecimalFormat("#,###", formatSymbols);
|
COMMA_FORMAT = new DecimalFormat("#,###", formatSymbols);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -97,8 +104,8 @@ public class NumberFormat {
|
|||||||
try {
|
try {
|
||||||
DECIMAL_FORMAT = new DecimalFormat(decimalFormat, formatSymbols);
|
DECIMAL_FORMAT = new DecimalFormat(decimalFormat, formatSymbols);
|
||||||
} catch (NullPointerException | IllegalArgumentException exception) {
|
} catch (NullPointerException | IllegalArgumentException exception) {
|
||||||
toolStats.logger.warning("number-formats.decimal-format is NOT a valid format! Using default #,###.00 instead.");
|
toolStats.logger.error("Invalid decimal or missing format", exception);
|
||||||
exception.printStackTrace();
|
toolStats.logger.warn("number-formats.decimal-format is NOT a valid format! Using default #,###.00 instead.");
|
||||||
DECIMAL_FORMAT = new DecimalFormat("#,###.00", formatSymbols);
|
DECIMAL_FORMAT = new DecimalFormat("#,###.00", formatSymbols);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -136,4 +143,69 @@ public class NumberFormat {
|
|||||||
public String formatDate(Date date) {
|
public String formatDate(Date date) {
|
||||||
return DATE_FORMAT.format(date);
|
return DATE_FORMAT.format(date);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns a human-readable form of time in milliseconds.
|
||||||
|
* E.g. given 3752348000L outputs 1 year, 5 months, 3 days, 14 hours, 12 minutes, 28 seconds.
|
||||||
|
*
|
||||||
|
* @param time The time in ms.
|
||||||
|
* @return Map with units as keys and time value, e.g. "years" (key) -> 1 (value)
|
||||||
|
*/
|
||||||
|
public Map<String, String> formatTime(Long time) {
|
||||||
|
final int SECONDS_PER_MINUTE = 60;
|
||||||
|
final int MINUTES_PER_HOUR = 60;
|
||||||
|
final int HOURS_PER_DAY = 24;
|
||||||
|
final int DAYS_PER_MONTH = 30; // Approximation
|
||||||
|
final int DAYS_PER_YEAR = 365; // Approximation
|
||||||
|
|
||||||
|
long totalSeconds = time / 1000;
|
||||||
|
|
||||||
|
Map<String, String> timeUnits = new HashMap<>();
|
||||||
|
|
||||||
|
long years = totalSeconds / (DAYS_PER_YEAR * HOURS_PER_DAY * MINUTES_PER_HOUR * SECONDS_PER_MINUTE);
|
||||||
|
if (years > 0) {
|
||||||
|
timeUnits.put("years", Long.toString(years));
|
||||||
|
}
|
||||||
|
totalSeconds %= (DAYS_PER_YEAR * HOURS_PER_DAY * MINUTES_PER_HOUR * SECONDS_PER_MINUTE);
|
||||||
|
|
||||||
|
long months = totalSeconds / (DAYS_PER_MONTH * HOURS_PER_DAY * MINUTES_PER_HOUR * SECONDS_PER_MINUTE);
|
||||||
|
if (months > 0) {
|
||||||
|
timeUnits.put("months", Long.toString(months));
|
||||||
|
}
|
||||||
|
totalSeconds %= (DAYS_PER_MONTH * HOURS_PER_DAY * MINUTES_PER_HOUR * SECONDS_PER_MINUTE);
|
||||||
|
|
||||||
|
long days = totalSeconds / (HOURS_PER_DAY * MINUTES_PER_HOUR * SECONDS_PER_MINUTE);
|
||||||
|
if (days > 0) {
|
||||||
|
timeUnits.put("days", Long.toString(days));
|
||||||
|
}
|
||||||
|
totalSeconds %= (HOURS_PER_DAY * MINUTES_PER_HOUR * SECONDS_PER_MINUTE);
|
||||||
|
|
||||||
|
long hours = totalSeconds / (MINUTES_PER_HOUR * SECONDS_PER_MINUTE);
|
||||||
|
if (hours > 0) {
|
||||||
|
timeUnits.put("hours", Long.toString(hours));
|
||||||
|
}
|
||||||
|
totalSeconds %= (MINUTES_PER_HOUR * SECONDS_PER_MINUTE);
|
||||||
|
|
||||||
|
long minutes = totalSeconds / SECONDS_PER_MINUTE;
|
||||||
|
if (minutes > 0) {
|
||||||
|
timeUnits.put("minutes", Long.toString(minutes));
|
||||||
|
}
|
||||||
|
totalSeconds %= SECONDS_PER_MINUTE;
|
||||||
|
|
||||||
|
long seconds = totalSeconds;
|
||||||
|
if (seconds > 0 || timeUnits.isEmpty()) { // Always include seconds if everything else is zero
|
||||||
|
timeUnits.put("seconds", Long.toString(seconds));
|
||||||
|
}
|
||||||
|
|
||||||
|
return timeUnits;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Date normalizeTime(Long time) {
|
||||||
|
Instant instant = Instant.ofEpochMilli(time);
|
||||||
|
ZoneId zone = ZoneId.systemDefault();
|
||||||
|
|
||||||
|
LocalDate localDate = instant.atZone(zone).toLocalDate();
|
||||||
|
ZonedDateTime midnight = localDate.atStartOfDay(zone);
|
||||||
|
return Date.from(midnight.toInstant());
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
225
src/main/java/lol/hyper/toolstats/tools/TokenData.java
Normal file
@@ -0,0 +1,225 @@
|
|||||||
|
/*
|
||||||
|
* This file is part of ToolStats.
|
||||||
|
*
|
||||||
|
* ToolStats is free software: you can redistribute it and/or modify
|
||||||
|
* it under the terms of the GNU General Public License as published by
|
||||||
|
* the Free Software Foundation, either version 3 of the License, or
|
||||||
|
* (at your option) any later version.
|
||||||
|
*
|
||||||
|
* ToolStats is distributed in the hope that it will be useful,
|
||||||
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
* GNU General Public License for more details.
|
||||||
|
*
|
||||||
|
* You should have received a copy of the GNU General Public License
|
||||||
|
* along with ToolStats. If not, see <https://www.gnu.org/licenses/>.
|
||||||
|
*/
|
||||||
|
|
||||||
|
package lol.hyper.toolstats.tools;
|
||||||
|
|
||||||
|
import io.papermc.paper.datacomponent.DataComponentTypes;
|
||||||
|
import io.papermc.paper.datacomponent.item.CustomModelData;
|
||||||
|
import lol.hyper.toolstats.ToolStats;
|
||||||
|
import net.kyori.adventure.text.Component;
|
||||||
|
import org.bukkit.Material;
|
||||||
|
import org.bukkit.NamespacedKey;
|
||||||
|
import org.bukkit.configuration.ConfigurationSection;
|
||||||
|
import org.bukkit.inventory.ItemStack;
|
||||||
|
import org.bukkit.inventory.ShapedRecipe;
|
||||||
|
import org.bukkit.inventory.meta.ItemMeta;
|
||||||
|
import org.bukkit.persistence.PersistentDataContainer;
|
||||||
|
import org.bukkit.persistence.PersistentDataType;
|
||||||
|
|
||||||
|
import java.util.*;
|
||||||
|
|
||||||
|
public class TokenData {
|
||||||
|
|
||||||
|
private final ToolStats toolStats;
|
||||||
|
private final Set<ShapedRecipe> recipes = new HashSet<>();
|
||||||
|
private final ArrayList<String> tokenTypes = new ArrayList<>();
|
||||||
|
|
||||||
|
public TokenData(ToolStats toolStats) {
|
||||||
|
this.toolStats = toolStats;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setup() {
|
||||||
|
NamespacedKey playerKillsKey = new NamespacedKey(toolStats, "player-kills-token");
|
||||||
|
ShapedRecipe playerKillRecipe = new ShapedRecipe(playerKillsKey, createToken("player-kills"));
|
||||||
|
playerKillRecipe.shape(" P ", "PSP", " P ");
|
||||||
|
playerKillRecipe.setIngredient('P', Material.PAPER);
|
||||||
|
playerKillRecipe.setIngredient('S', Material.WOODEN_SWORD);
|
||||||
|
recipes.add(playerKillRecipe);
|
||||||
|
|
||||||
|
NamespacedKey mobKillsKey = new NamespacedKey(toolStats, "mob-kills-token");
|
||||||
|
ShapedRecipe mobKillsRecipe = new ShapedRecipe(mobKillsKey, createToken("mob-kills"));
|
||||||
|
mobKillsRecipe.shape(" P ", "PRP", " P ");
|
||||||
|
mobKillsRecipe.setIngredient('P', Material.PAPER);
|
||||||
|
mobKillsRecipe.setIngredient('R', Material.ROTTEN_FLESH);
|
||||||
|
recipes.add(mobKillsRecipe);
|
||||||
|
|
||||||
|
NamespacedKey blocksMinedKey = new NamespacedKey(toolStats, "blocks-mined-token");
|
||||||
|
ShapedRecipe blocksMinedRecipe = new ShapedRecipe(blocksMinedKey, createToken("blocks-mined"));
|
||||||
|
blocksMinedRecipe.shape(" P ", "PSP", " P ");
|
||||||
|
blocksMinedRecipe.setIngredient('P', Material.PAPER);
|
||||||
|
blocksMinedRecipe.setIngredient('S', Material.WOODEN_PICKAXE);
|
||||||
|
recipes.add(blocksMinedRecipe);
|
||||||
|
|
||||||
|
NamespacedKey cropsMinedKey = new NamespacedKey(toolStats, "crops-mined-token");
|
||||||
|
ShapedRecipe cropsMinedRecipe = new ShapedRecipe(cropsMinedKey, createToken("crops-mined"));
|
||||||
|
cropsMinedRecipe.shape(" P ", "PHP", " P ");
|
||||||
|
cropsMinedRecipe.setIngredient('P', Material.PAPER);
|
||||||
|
cropsMinedRecipe.setIngredient('H', Material.WOODEN_HOE);
|
||||||
|
recipes.add(cropsMinedRecipe);
|
||||||
|
|
||||||
|
NamespacedKey fishCaughtKey = new NamespacedKey(toolStats, "fish-caught-token");
|
||||||
|
ShapedRecipe fishCaughtRecipe = new ShapedRecipe(fishCaughtKey, createToken("fish-caught"));
|
||||||
|
fishCaughtRecipe.shape(" P ", "PCP", " P ");
|
||||||
|
fishCaughtRecipe.setIngredient('P', Material.PAPER);
|
||||||
|
fishCaughtRecipe.setIngredient('C', Material.COD);
|
||||||
|
recipes.add(fishCaughtRecipe);
|
||||||
|
|
||||||
|
NamespacedKey sheepShearedKey = new NamespacedKey(toolStats, "sheep-sheared-token");
|
||||||
|
ShapedRecipe sheepShearedRecipe = new ShapedRecipe(sheepShearedKey, createToken("sheep-sheared"));
|
||||||
|
sheepShearedRecipe.shape(" P ", "PWP", " P ");
|
||||||
|
sheepShearedRecipe.setIngredient('P', Material.PAPER);
|
||||||
|
sheepShearedRecipe.setIngredient('W', Material.WHITE_WOOL);
|
||||||
|
recipes.add(sheepShearedRecipe);
|
||||||
|
|
||||||
|
NamespacedKey armorDamageKey = new NamespacedKey(toolStats, "damage-taken-token");
|
||||||
|
ShapedRecipe armorDamageRecipe = new ShapedRecipe(armorDamageKey, createToken("damage-taken"));
|
||||||
|
armorDamageRecipe.shape(" P ", "PCP", " P ");
|
||||||
|
armorDamageRecipe.setIngredient('P', Material.PAPER);
|
||||||
|
armorDamageRecipe.setIngredient('C', Material.LEATHER_CHESTPLATE);
|
||||||
|
recipes.add(armorDamageRecipe);
|
||||||
|
|
||||||
|
NamespacedKey damageDoneKey = new NamespacedKey(toolStats, "damage-done-token");
|
||||||
|
ShapedRecipe damageDoneRecipe = new ShapedRecipe(damageDoneKey, createToken("damage-done"));
|
||||||
|
damageDoneRecipe.shape(" P ", "PSP", " P ");
|
||||||
|
damageDoneRecipe.setIngredient('P', Material.PAPER);
|
||||||
|
damageDoneRecipe.setIngredient('S', Material.SHIELD);
|
||||||
|
recipes.add(damageDoneRecipe);
|
||||||
|
|
||||||
|
NamespacedKey arrowsShotKey = new NamespacedKey(toolStats, "arrows-shot-token");
|
||||||
|
ShapedRecipe arrowsShotRecipe = new ShapedRecipe(arrowsShotKey, createToken("arrows-shot"));
|
||||||
|
arrowsShotRecipe.shape(" P ", "PAP", " P ");
|
||||||
|
arrowsShotRecipe.setIngredient('P', Material.PAPER);
|
||||||
|
arrowsShotRecipe.setIngredient('A', Material.ARROW);
|
||||||
|
recipes.add(arrowsShotRecipe);
|
||||||
|
|
||||||
|
NamespacedKey flightTimeKey = new NamespacedKey(toolStats, "flight-time-token");
|
||||||
|
ShapedRecipe flightTimeRecipe = new ShapedRecipe(flightTimeKey, createToken("flight-time"));
|
||||||
|
flightTimeRecipe.shape(" P ", "PFP", " P ");
|
||||||
|
flightTimeRecipe.setIngredient('P', Material.PAPER);
|
||||||
|
flightTimeRecipe.setIngredient('F', Material.FEATHER);
|
||||||
|
recipes.add(flightTimeRecipe);
|
||||||
|
|
||||||
|
NamespacedKey resetKey = new NamespacedKey(toolStats, "reset-token");
|
||||||
|
ShapedRecipe resetRecipe = new ShapedRecipe(resetKey, createToken("reset"));
|
||||||
|
resetRecipe.shape(" P ", "PPP", " P ");
|
||||||
|
resetRecipe.setIngredient('P', Material.PAPER);
|
||||||
|
recipes.add(resetRecipe);
|
||||||
|
|
||||||
|
NamespacedKey removeKey = new NamespacedKey(toolStats, "remove-token");
|
||||||
|
ShapedRecipe removeRecipe = new ShapedRecipe(removeKey, createToken("remove"));
|
||||||
|
removeRecipe.shape(" P ", "P P", " P ");
|
||||||
|
removeRecipe.setIngredient('P', Material.PAPER);
|
||||||
|
recipes.add(removeRecipe);
|
||||||
|
|
||||||
|
tokenTypes.add("crops-mined");
|
||||||
|
tokenTypes.add("blocks-mined");
|
||||||
|
tokenTypes.add("damage-taken");
|
||||||
|
tokenTypes.add("damage-done");
|
||||||
|
tokenTypes.add("mob-kills");
|
||||||
|
tokenTypes.add("player-kills");
|
||||||
|
tokenTypes.add("arrows-shot");
|
||||||
|
tokenTypes.add("sheep-sheared");
|
||||||
|
tokenTypes.add("flight-time");
|
||||||
|
tokenTypes.add("fish-caught");
|
||||||
|
tokenTypes.add("reset");
|
||||||
|
tokenTypes.add("remove");
|
||||||
|
}
|
||||||
|
|
||||||
|
public Set<ShapedRecipe> getRecipes() {
|
||||||
|
return recipes;
|
||||||
|
}
|
||||||
|
|
||||||
|
public ArrayList<String> getTokenTypes() {
|
||||||
|
return tokenTypes;
|
||||||
|
}
|
||||||
|
|
||||||
|
public ItemStack createToken(String tokenType) {
|
||||||
|
// we don't have to check if the token exists
|
||||||
|
// we do that prior
|
||||||
|
ConfigurationSection tokenConfig = toolStats.config.getConfigurationSection("tokens.data." + tokenType);
|
||||||
|
|
||||||
|
String materialFromConfig = tokenConfig.getString("material");
|
||||||
|
if (materialFromConfig == null) {
|
||||||
|
toolStats.logger.warn("Could not find material config for token {}", tokenType);
|
||||||
|
toolStats.logger.warn("Using PAPER as default.");
|
||||||
|
materialFromConfig = "PAPER";
|
||||||
|
}
|
||||||
|
Material material = Material.getMaterial(materialFromConfig);
|
||||||
|
if (material == null) {
|
||||||
|
toolStats.logger.warn("Material {} is not a valid Minecraft material.", materialFromConfig);
|
||||||
|
toolStats.logger.warn("Using PAPER as default.");
|
||||||
|
material = Material.PAPER;
|
||||||
|
}
|
||||||
|
|
||||||
|
ItemStack token = new ItemStack(material);
|
||||||
|
ItemMeta tokenMeta = token.getItemMeta();
|
||||||
|
PersistentDataContainer tokenData = tokenMeta.getPersistentDataContainer();
|
||||||
|
|
||||||
|
// set the title and lore
|
||||||
|
String titleFromConfig = toolStats.config.getString("tokens.data." + tokenType + ".title");
|
||||||
|
Component title = toolStats.textUtils.format(titleFromConfig);
|
||||||
|
List<Component> lore = toolStats.configTools.getTokenLore(tokenType);
|
||||||
|
tokenMeta.displayName(title);
|
||||||
|
tokenMeta.lore(lore);
|
||||||
|
|
||||||
|
// set the PDC
|
||||||
|
tokenData.set(toolStats.tokenType, PersistentDataType.STRING, tokenType);
|
||||||
|
token.setItemMeta(tokenMeta);
|
||||||
|
|
||||||
|
// set the custom model data
|
||||||
|
if (tokenConfig.getBoolean("custom-model-data.enabled")) {
|
||||||
|
String type = tokenConfig.getString("custom-model-data.type");
|
||||||
|
Object value = tokenConfig.get("custom-model-data.value");
|
||||||
|
if (type == null || value == null) {
|
||||||
|
toolStats.logger.info("Could not find custom model data for token {}", tokenType);
|
||||||
|
toolStats.logger.info("Type: {}", type);
|
||||||
|
toolStats.logger.info("Value: {}", value);
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
CustomModelData data = setData(type, value);
|
||||||
|
if (data != null) {
|
||||||
|
token.setData(DataComponentTypes.CUSTOM_MODEL_DATA, data);
|
||||||
|
} else {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return token;
|
||||||
|
}
|
||||||
|
|
||||||
|
private CustomModelData setData(String type, Object data) {
|
||||||
|
switch (type.toLowerCase(Locale.ROOT)) {
|
||||||
|
case "float": {
|
||||||
|
float f;
|
||||||
|
try {
|
||||||
|
f = Float.parseFloat(data.toString());
|
||||||
|
} catch (NumberFormatException e) {
|
||||||
|
toolStats.logger.info("{} is not a valid float!", data);
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
return CustomModelData.customModelData().addFloat(f).build();
|
||||||
|
}
|
||||||
|
case "string": {
|
||||||
|
return CustomModelData.customModelData().addString(data.toString()).build();
|
||||||
|
}
|
||||||
|
default: {
|
||||||
|
toolStats.logger.info("{} is not a valid data type!", data);
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -1,71 +0,0 @@
|
|||||||
/*
|
|
||||||
* This file is part of ToolStats.
|
|
||||||
*
|
|
||||||
* ToolStats is free software: you can redistribute it and/or modify
|
|
||||||
* it under the terms of the GNU General Public License as published by
|
|
||||||
* the Free Software Foundation, either version 3 of the License, or
|
|
||||||
* (at your option) any later version.
|
|
||||||
*
|
|
||||||
* ToolStats is distributed in the hope that it will be useful,
|
|
||||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
||||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
||||||
* GNU General Public License for more details.
|
|
||||||
*
|
|
||||||
* You should have received a copy of the GNU General Public License
|
|
||||||
* along with ToolStats. If not, see <https://www.gnu.org/licenses/>.
|
|
||||||
*/
|
|
||||||
|
|
||||||
/*
|
|
||||||
* This file is part of ToolStats.
|
|
||||||
*
|
|
||||||
* ToolStats is free software: you can redistribute it and/or modify
|
|
||||||
* it under the terms of the GNU General Public License as published by
|
|
||||||
* the Free Software Foundation, either version 3 of the License, or
|
|
||||||
* (at your option) any later version.
|
|
||||||
*
|
|
||||||
* ToolStats is distributed in the hope that it will be useful,
|
|
||||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
||||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
||||||
* GNU General Public License for more details.
|
|
||||||
*
|
|
||||||
* You should have received a copy of the GNU General Public License
|
|
||||||
* along with ToolStats. If not, see <https://www.gnu.org/licenses/>.
|
|
||||||
*/
|
|
||||||
|
|
||||||
package lol.hyper.toolstats.tools;
|
|
||||||
|
|
||||||
import org.bukkit.persistence.PersistentDataAdapterContext;
|
|
||||||
import org.bukkit.persistence.PersistentDataType;
|
|
||||||
import org.jetbrains.annotations.NotNull;
|
|
||||||
|
|
||||||
import java.nio.ByteBuffer;
|
|
||||||
import java.util.UUID;
|
|
||||||
|
|
||||||
public class UUIDDataType implements PersistentDataType<byte[], UUID> {
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public @NotNull Class<byte[]> getPrimitiveType() {
|
|
||||||
return byte[].class;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public @NotNull Class<UUID> getComplexType() {
|
|
||||||
return UUID.class;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public byte @NotNull [] toPrimitive(UUID complex, @NotNull PersistentDataAdapterContext context) {
|
|
||||||
ByteBuffer bb = ByteBuffer.wrap(new byte[16]);
|
|
||||||
bb.putLong(complex.getMostSignificantBits());
|
|
||||||
bb.putLong(complex.getLeastSignificantBits());
|
|
||||||
return bb.array();
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public @NotNull UUID fromPrimitive(byte @NotNull [] primitive, @NotNull PersistentDataAdapterContext context) {
|
|
||||||
ByteBuffer bb = ByteBuffer.wrap(primitive);
|
|
||||||
long firstLong = bb.getLong();
|
|
||||||
long secondLong = bb.getLong();
|
|
||||||
return new UUID(firstLong, secondLong);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
205
src/main/java/lol/hyper/toolstats/tools/config/ConfigTools.java
Normal file
@@ -0,0 +1,205 @@
|
|||||||
|
/*
|
||||||
|
* This file is part of ToolStats.
|
||||||
|
*
|
||||||
|
* ToolStats is free software: you can redistribute it and/or modify
|
||||||
|
* it under the terms of the GNU General Public License as published by
|
||||||
|
* the Free Software Foundation, either version 3 of the License, or
|
||||||
|
* (at your option) any later version.
|
||||||
|
*
|
||||||
|
* ToolStats is distributed in the hope that it will be useful,
|
||||||
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
* GNU General Public License for more details.
|
||||||
|
*
|
||||||
|
* You should have received a copy of the GNU General Public License
|
||||||
|
* along with ToolStats. If not, see <https://www.gnu.org/licenses/>.
|
||||||
|
*/
|
||||||
|
|
||||||
|
package lol.hyper.toolstats.tools.config;
|
||||||
|
|
||||||
|
import lol.hyper.toolstats.ToolStats;
|
||||||
|
import net.kyori.adventure.text.Component;
|
||||||
|
import net.kyori.adventure.text.format.TextDecoration;
|
||||||
|
import org.bukkit.Material;
|
||||||
|
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.Collections;
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.Map;
|
||||||
|
import java.util.regex.Matcher;
|
||||||
|
import java.util.regex.Pattern;
|
||||||
|
|
||||||
|
public class ConfigTools {
|
||||||
|
|
||||||
|
private final ToolStats toolStats;
|
||||||
|
|
||||||
|
public ConfigTools(ToolStats toolStats) {
|
||||||
|
this.toolStats = toolStats;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Checks the config to see if we want to show lore on certain items.
|
||||||
|
*
|
||||||
|
* @param material The item type to check.
|
||||||
|
* @param configName The config we are checking under.
|
||||||
|
* @return If we want to add data or not.
|
||||||
|
*/
|
||||||
|
public boolean checkConfig(Material material, String configName) {
|
||||||
|
if (toolStats.config.getConfigurationSection("enabled." + configName) == null) {
|
||||||
|
toolStats.logger.warn("Missing config section for enabled{}", configName);
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
String itemName = material.toString().toLowerCase();
|
||||||
|
String itemType = null;
|
||||||
|
// hardcode these
|
||||||
|
if (material == Material.BOW || material == Material.CROSSBOW || material == Material.SHEARS || material == Material.TRIDENT || material == Material.FISHING_ROD) {
|
||||||
|
switch (material) {
|
||||||
|
case CROSSBOW:
|
||||||
|
case BOW: {
|
||||||
|
itemType = "bow";
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
case SHEARS: {
|
||||||
|
itemType = "shears";
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
case TRIDENT: {
|
||||||
|
itemType = "trident";
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
case FISHING_ROD: {
|
||||||
|
itemType = "fishing-rod";
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
itemType = itemName.substring(itemName.indexOf('_') + 1);
|
||||||
|
}
|
||||||
|
return switch (itemType) {
|
||||||
|
case "pickaxe" -> toolStats.config.getBoolean("enabled." + configName + ".pickaxe");
|
||||||
|
case "sword" -> toolStats.config.getBoolean("enabled." + configName + ".sword");
|
||||||
|
case "shovel" -> toolStats.config.getBoolean("enabled." + configName + ".shovel");
|
||||||
|
case "axe" -> toolStats.config.getBoolean("enabled." + configName + ".axe");
|
||||||
|
case "hoe" -> toolStats.config.getBoolean("enabled." + configName + ".hoe");
|
||||||
|
case "shears" -> toolStats.config.getBoolean("enabled." + configName + ".shears");
|
||||||
|
case "crossbow", "bow" -> toolStats.config.getBoolean("enabled." + configName + ".bow");
|
||||||
|
case "trident" -> toolStats.config.getBoolean("enabled." + configName + ".trident");
|
||||||
|
case "fishing-rod" -> toolStats.config.getBoolean("enabled." + configName + ".fishing-rod");
|
||||||
|
case "mace" -> toolStats.config.getBoolean("enabled." + configName + ".mace");
|
||||||
|
case "helmet", "chestplate", "leggings", "boots" ->
|
||||||
|
toolStats.config.getBoolean("enabled." + configName + ".armor");
|
||||||
|
default -> false;
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Format a string to be ready for lore usage.
|
||||||
|
*
|
||||||
|
* @param configName The message to use.
|
||||||
|
* @param placeHolder The placeholder text in the message.
|
||||||
|
* @param value The value to set the placeholder.
|
||||||
|
* @return Formatted string, null if the configName doesn't exist.
|
||||||
|
*/
|
||||||
|
public Component formatLore(String configName, String placeHolder, Object value) {
|
||||||
|
String lore = toolStats.config.getString("messages." + configName);
|
||||||
|
if (lore == null) {
|
||||||
|
toolStats.logger.warn("Unable to find config message for: messages.{}", configName);
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
// if the config message is empty, don't send it
|
||||||
|
if (lore.isEmpty()) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
// the final component for this lore
|
||||||
|
Component component;
|
||||||
|
|
||||||
|
// set the placeholder to the value
|
||||||
|
if (placeHolder != null && value != null) {
|
||||||
|
lore = lore.replace(placeHolder, String.valueOf(value));
|
||||||
|
}
|
||||||
|
|
||||||
|
component = toolStats.textUtils.format(lore);
|
||||||
|
return component.decorationIfAbsent(TextDecoration.ITALIC, TextDecoration.State.FALSE);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Format a string with several placeholders to be ready for lore usage.
|
||||||
|
*
|
||||||
|
* @param configName The message to use.
|
||||||
|
* @param placeHoldersValues Map containing placeholders names as keys and values.
|
||||||
|
* @return Formatted string, null if the configName doesn't exist.
|
||||||
|
*/
|
||||||
|
public Component formatLoreMultiplePlaceholders(String configName, Map<String, String> placeHoldersValues) {
|
||||||
|
String lore = toolStats.config.getString("messages." + configName);
|
||||||
|
if (lore == null) {
|
||||||
|
toolStats.logger.warn("Unable to find config message for: messages.{}", configName);
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
// if the config message is empty, don't send it
|
||||||
|
if (lore.isEmpty()) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
Pattern pattern = Pattern.compile("\\{([^}]+)\\}(\\S*)\\s*");
|
||||||
|
Matcher matcher = pattern.matcher(lore);
|
||||||
|
|
||||||
|
StringBuilder result = new StringBuilder();
|
||||||
|
int lastEnd = 0;
|
||||||
|
|
||||||
|
while (matcher.find()) {
|
||||||
|
String placeholder = matcher.group(1);
|
||||||
|
String unit = matcher.group(2);
|
||||||
|
|
||||||
|
result.append(lore, lastEnd, matcher.start());
|
||||||
|
|
||||||
|
if (placeHoldersValues.containsKey(placeholder)) {
|
||||||
|
result.append(placeHoldersValues.get(placeholder)).append(unit).append(" ");
|
||||||
|
}
|
||||||
|
|
||||||
|
// Update lastEnd to end of the match
|
||||||
|
lastEnd = matcher.end();
|
||||||
|
}
|
||||||
|
if (lastEnd < lore.length()) {
|
||||||
|
result.append(lore.substring(lastEnd));
|
||||||
|
}
|
||||||
|
|
||||||
|
Component component;
|
||||||
|
// Clean output text
|
||||||
|
String outputText = result.toString().replaceAll("\\s+", " ").trim();
|
||||||
|
component = toolStats.textUtils.format(outputText);
|
||||||
|
|
||||||
|
return component.decorationIfAbsent(TextDecoration.ITALIC, TextDecoration.State.FALSE);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get the token item's lore from config.
|
||||||
|
*
|
||||||
|
* @param tokenType The type.
|
||||||
|
* @return The lore.
|
||||||
|
*/
|
||||||
|
public List<Component> getTokenLore(String tokenType) {
|
||||||
|
List<String> raw = toolStats.config.getStringList("tokens.data." + tokenType + ".lore");
|
||||||
|
if (raw.isEmpty()) {
|
||||||
|
return Collections.emptyList();
|
||||||
|
}
|
||||||
|
|
||||||
|
List<Component> finalLore = new ArrayList<>();
|
||||||
|
for (String line : raw) {
|
||||||
|
if (line.contains("{levels}")) {
|
||||||
|
Integer levels = toolStats.config.getInt("tokens.data." + tokenType + ".levels");
|
||||||
|
// will return 0 if it doesn't exist
|
||||||
|
if (levels != 0) {
|
||||||
|
line = line.replace("{levels}", String.valueOf(levels));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
Component component = toolStats.textUtils.format(line);
|
||||||
|
component = component.decorationIfAbsent(TextDecoration.ITALIC, TextDecoration.State.FALSE);
|
||||||
|
finalLore.add(component);
|
||||||
|
}
|
||||||
|
return finalLore;
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,45 @@
|
|||||||
|
/*
|
||||||
|
* This file is part of ToolStats.
|
||||||
|
*
|
||||||
|
* ToolStats is free software: you can redistribute it and/or modify
|
||||||
|
* it under the terms of the GNU General Public License as published by
|
||||||
|
* the Free Software Foundation, either version 3 of the License, or
|
||||||
|
* (at your option) any later version.
|
||||||
|
*
|
||||||
|
* ToolStats is distributed in the hope that it will be useful,
|
||||||
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
* GNU General Public License for more details.
|
||||||
|
*
|
||||||
|
* You should have received a copy of the GNU General Public License
|
||||||
|
* along with ToolStats. If not, see <https://www.gnu.org/licenses/>.
|
||||||
|
*/
|
||||||
|
|
||||||
|
package lol.hyper.toolstats.tools.config;
|
||||||
|
|
||||||
|
import lol.hyper.toolstats.ToolStats;
|
||||||
|
import lol.hyper.toolstats.tools.config.versions.*;
|
||||||
|
|
||||||
|
public class ConfigUpdater {
|
||||||
|
|
||||||
|
private final ToolStats toolStats;
|
||||||
|
|
||||||
|
public ConfigUpdater(ToolStats toolStats) {
|
||||||
|
this.toolStats = toolStats;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void updateConfig() {
|
||||||
|
int version = toolStats.config.getInt("config-version");
|
||||||
|
|
||||||
|
switch (version) {
|
||||||
|
case 5 -> new Version6(toolStats).update(); // 5 to 6
|
||||||
|
case 6 -> new Version7(toolStats).update(); // 6 to 7
|
||||||
|
case 7 -> new Version8(toolStats).update(); // 7 to 8
|
||||||
|
case 8 -> new Version9(toolStats).update(); // 8 to 9
|
||||||
|
case 9 -> new Version10(toolStats).update(); // 9 to 10
|
||||||
|
case 10 -> new Version11(toolStats).update(); // 10 to 11
|
||||||
|
case 11 -> new Version12(toolStats).update(); // 11 to 12
|
||||||
|
case 12 -> new Version13(toolStats).update(); // 12 to 13
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,79 @@
|
|||||||
|
/*
|
||||||
|
* This file is part of ToolStats.
|
||||||
|
*
|
||||||
|
* ToolStats is free software: you can redistribute it and/or modify
|
||||||
|
* it under the terms of the GNU General Public License as published by
|
||||||
|
* the Free Software Foundation, either version 3 of the License, or
|
||||||
|
* (at your option) any later version.
|
||||||
|
*
|
||||||
|
* ToolStats is distributed in the hope that it will be useful,
|
||||||
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
* GNU General Public License for more details.
|
||||||
|
*
|
||||||
|
* You should have received a copy of the GNU General Public License
|
||||||
|
* along with ToolStats. If not, see <https://www.gnu.org/licenses/>.
|
||||||
|
*/
|
||||||
|
|
||||||
|
package lol.hyper.toolstats.tools.config.versions;
|
||||||
|
|
||||||
|
import lol.hyper.toolstats.ToolStats;
|
||||||
|
|
||||||
|
import java.io.File;
|
||||||
|
import java.io.IOException;
|
||||||
|
|
||||||
|
public class Version10 {
|
||||||
|
|
||||||
|
private final ToolStats toolStats;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Used for updating from version 9 to 10.
|
||||||
|
*
|
||||||
|
* @param toolStats ToolStats instance.
|
||||||
|
*/
|
||||||
|
public Version10(ToolStats toolStats) {
|
||||||
|
this.toolStats = toolStats;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Perform the config update.
|
||||||
|
*/
|
||||||
|
public void update() {
|
||||||
|
// save the old config first
|
||||||
|
try {
|
||||||
|
toolStats.config.save("plugins" + File.separator + "ToolStats" + File.separator + "config-9.yml");
|
||||||
|
} catch (IOException exception) {
|
||||||
|
toolStats.logger.error("Unable to save config-9.yml!", exception);
|
||||||
|
}
|
||||||
|
|
||||||
|
// we make this super verbose so that admins can see what's being added
|
||||||
|
toolStats.logger.info("Updating config.yml to version 10.");
|
||||||
|
toolStats.config.set("config-version", 10);
|
||||||
|
|
||||||
|
// Add missing values I forgot...
|
||||||
|
toolStats.logger.info("Adding entry for enabled.created-by.fishing-rod");
|
||||||
|
toolStats.config.set("enabled.created-by.fishing-rod", true);
|
||||||
|
toolStats.logger.info("Adding entry for enabled.created-date.fishing-rod");
|
||||||
|
toolStats.config.set("enabled.created-date.fishing-rod", true);
|
||||||
|
toolStats.logger.info("Adding entry for enabled.fished-tag.fishing-rod");
|
||||||
|
toolStats.config.set("enabled.fished-tag.fishing-rod", true);
|
||||||
|
toolStats.logger.info("Adding entry for enabled.looted-tag.fishing-rod");
|
||||||
|
toolStats.config.set("enabled.looted-tag.fishing-rod", true);
|
||||||
|
toolStats.logger.info("Adding entry for enabled.traded-tag.fishing-rod");
|
||||||
|
toolStats.config.set("enabled.traded-tag.fishing-rod", true);
|
||||||
|
toolStats.logger.info("Adding entry for enabled.spawned-in.fishing-rod");
|
||||||
|
toolStats.config.set("enabled.spawned-in.fishing-rod", true);
|
||||||
|
|
||||||
|
toolStats.logger.info("Adding entry for enabled.crops-harvested");
|
||||||
|
toolStats.config.set("enabled.crops-harvested", true);
|
||||||
|
|
||||||
|
// save the config and reload it
|
||||||
|
try {
|
||||||
|
toolStats.config.save("plugins" + File.separator + "ToolStats" + File.separator + "config.yml");
|
||||||
|
} catch (IOException exception) {
|
||||||
|
toolStats.logger.error("Unable to save config.yml!", exception);
|
||||||
|
}
|
||||||
|
toolStats.loadConfig();
|
||||||
|
toolStats.logger.info("Config has been updated to version 10. A copy of version 9 has been saved as config-9.yml");
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,102 @@
|
|||||||
|
/*
|
||||||
|
* This file is part of ToolStats.
|
||||||
|
*
|
||||||
|
* ToolStats is free software: you can redistribute it and/or modify
|
||||||
|
* it under the terms of the GNU General Public License as published by
|
||||||
|
* the Free Software Foundation, either version 3 of the License, or
|
||||||
|
* (at your option) any later version.
|
||||||
|
*
|
||||||
|
* ToolStats is distributed in the hope that it will be useful,
|
||||||
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
* GNU General Public License for more details.
|
||||||
|
*
|
||||||
|
* You should have received a copy of the GNU General Public License
|
||||||
|
* along with ToolStats. If not, see <https://www.gnu.org/licenses/>.
|
||||||
|
*/
|
||||||
|
|
||||||
|
package lol.hyper.toolstats.tools.config.versions;
|
||||||
|
|
||||||
|
import lol.hyper.toolstats.ToolStats;
|
||||||
|
|
||||||
|
import java.io.File;
|
||||||
|
import java.io.IOException;
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
public class Version11 {
|
||||||
|
|
||||||
|
private final ToolStats toolStats;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Used for updating from version 10 to 11.
|
||||||
|
*
|
||||||
|
* @param toolStats ToolStats instance.
|
||||||
|
*/
|
||||||
|
public Version11(ToolStats toolStats) {
|
||||||
|
this.toolStats = toolStats;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Perform the config update.
|
||||||
|
*/
|
||||||
|
public void update() {
|
||||||
|
// save the old config first
|
||||||
|
try {
|
||||||
|
toolStats.config.save("plugins" + File.separator + "ToolStats" + File.separator + "config-10.yml");
|
||||||
|
} catch (IOException exception) {
|
||||||
|
toolStats.logger.error("Unable to save config-10.yml!", exception);
|
||||||
|
}
|
||||||
|
|
||||||
|
// we make this super verbose so that admins can see what's being added
|
||||||
|
toolStats.logger.info("Updating config.yml to version 11.");
|
||||||
|
toolStats.config.set("config-version", 11);
|
||||||
|
|
||||||
|
// add new tokens
|
||||||
|
toolStats.logger.info("Adding tokens.data.damage-done.title to config.yml.");
|
||||||
|
toolStats.config.set("tokens.data.damage-done.title", "&7ToolStats: &8Damage Done Token");
|
||||||
|
List<String> damageDoneLore = new ArrayList<>();
|
||||||
|
damageDoneLore.add("&8Combine with a melee or ranged weapon in an anvil to track damage done.");
|
||||||
|
toolStats.config.set("tokens.data.damage-done.lore", damageDoneLore);
|
||||||
|
toolStats.logger.info("Adding tokens.data.damage-done.lore to config.yml.");
|
||||||
|
toolStats.config.set("tokens.data.damage-done.levels", 1);
|
||||||
|
toolStats.logger.info("Adding tokens.data.damage-done.levels to config.yml.");
|
||||||
|
|
||||||
|
toolStats.logger.info("Adding tokens.data.remove.title to config.yml.");
|
||||||
|
toolStats.config.set("tokens.data.remove.title", "&7ToolStats: &8Remove Token");
|
||||||
|
List<String> removeLore = new ArrayList<>();
|
||||||
|
removeLore.add("&8Combine in an anvil with to REMOVE ALL stats and tokens for this item.");
|
||||||
|
toolStats.config.set("tokens.data.remove.lore", removeLore);
|
||||||
|
toolStats.logger.info("Adding tokens.data.remove.lore to config.yml.");
|
||||||
|
toolStats.config.set("tokens.data.remove.levels", 1);
|
||||||
|
toolStats.logger.info("Adding tokens.data.remove.levels to config.yml.");
|
||||||
|
|
||||||
|
toolStats.logger.info("Adding messages.damage-done to config.yml.");
|
||||||
|
toolStats.config.set("messages.damage-done", "&7Damage done: &8{damage}");
|
||||||
|
|
||||||
|
toolStats.config.set("enabled.damage-done.sword", true);
|
||||||
|
toolStats.config.set("enabled.damage-done.axe", true);
|
||||||
|
toolStats.config.set("enabled.damage-done.trident", true);
|
||||||
|
toolStats.config.set("enabled.damage-done.bow", true);
|
||||||
|
toolStats.config.set("enabled.damage-done.mace", true);
|
||||||
|
toolStats.logger.info("Adding enabled.damage-done.sword to config.yml");
|
||||||
|
toolStats.logger.info("Adding enabled.damage-done.axe to config.yml");
|
||||||
|
toolStats.logger.info("Adding enabled.damage-done.trident to config.yml");
|
||||||
|
toolStats.logger.info("Adding enabled.damage-done.bow to config.yml");
|
||||||
|
toolStats.logger.info("Adding enabled.damage-done.mace to config.yml");
|
||||||
|
|
||||||
|
toolStats.logger.info("Updating entry for messages.flight-time");
|
||||||
|
String oldFlightTime = toolStats.config.getString("messages.flight-time");
|
||||||
|
toolStats.config.set("messages.flight-time-old", oldFlightTime);
|
||||||
|
toolStats.config.set("messages.flight-time", "&7Flight time: &8{years}y {months}m {days}d {hours}h {minutes}m {seconds}s");
|
||||||
|
|
||||||
|
// save the config and reload it
|
||||||
|
try {
|
||||||
|
toolStats.config.save("plugins" + File.separator + "ToolStats" + File.separator + "config.yml");
|
||||||
|
} catch (IOException exception) {
|
||||||
|
toolStats.logger.error("Unable to save config.yml!", exception);
|
||||||
|
}
|
||||||
|
toolStats.loadConfig();
|
||||||
|
toolStats.logger.info("Config has been updated to version 11. A copy of version 10 has been saved as config-10.yml");
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,115 @@
|
|||||||
|
/*
|
||||||
|
* This file is part of ToolStats.
|
||||||
|
*
|
||||||
|
* ToolStats is free software: you can redistribute it and/or modify
|
||||||
|
* it under the terms of the GNU General Public License as published by
|
||||||
|
* the Free Software Foundation, either version 3 of the License, or
|
||||||
|
* (at your option) any later version.
|
||||||
|
*
|
||||||
|
* ToolStats is distributed in the hope that it will be useful,
|
||||||
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
* GNU General Public License for more details.
|
||||||
|
*
|
||||||
|
* You should have received a copy of the GNU General Public License
|
||||||
|
* along with ToolStats. If not, see <https://www.gnu.org/licenses/>.
|
||||||
|
*/
|
||||||
|
|
||||||
|
package lol.hyper.toolstats.tools.config.versions;
|
||||||
|
|
||||||
|
import lol.hyper.toolstats.ToolStats;
|
||||||
|
import org.bukkit.configuration.ConfigurationSection;
|
||||||
|
|
||||||
|
import java.io.File;
|
||||||
|
import java.io.IOException;
|
||||||
|
|
||||||
|
public class Version12 {
|
||||||
|
|
||||||
|
private final ToolStats toolStats;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Used for updating from version 11 to 12.
|
||||||
|
*
|
||||||
|
* @param toolStats ToolStats instance.
|
||||||
|
*/
|
||||||
|
public Version12(ToolStats toolStats) {
|
||||||
|
this.toolStats = toolStats;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Perform the config update.
|
||||||
|
*/
|
||||||
|
public void update() {
|
||||||
|
// save the old config first
|
||||||
|
try {
|
||||||
|
toolStats.config.save("plugins" + File.separator + "ToolStats" + File.separator + "config-11.yml");
|
||||||
|
} catch (IOException exception) {
|
||||||
|
toolStats.logger.error("Unable to save config-11.yml!", exception);
|
||||||
|
}
|
||||||
|
|
||||||
|
toolStats.logger.info("Updating config.yml to version 12.");
|
||||||
|
toolStats.config.set("config-version", 12);
|
||||||
|
|
||||||
|
transfer("enabled.created-by", "enabled.crafted-by");
|
||||||
|
transfer("enabled.created-date", "enabled.crafted-on");
|
||||||
|
|
||||||
|
transfer("enabled.fished-tag", "enabled.fished-by");
|
||||||
|
transfer("enabled.fished-tag", "enabled.fished-on");
|
||||||
|
|
||||||
|
transfer("enabled.looted-tag", "enabled.looted-by");
|
||||||
|
transfer("enabled.looted-tag", "enabled.looted-on");
|
||||||
|
|
||||||
|
transfer("enabled.traded-tag", "enabled.traded-by");
|
||||||
|
transfer("enabled.traded-tag", "enabled.traded-on");
|
||||||
|
|
||||||
|
transfer("enabled.spawned-in", "enabled.spawned-in-by");
|
||||||
|
transfer("enabled.spawned-in", "enabled.spawned-in-on");
|
||||||
|
|
||||||
|
transfer("messages.created", "messages.crafted");
|
||||||
|
|
||||||
|
toolStats.config.set("enabled.created-by", null);
|
||||||
|
toolStats.config.set("enabled.created-date", null);
|
||||||
|
toolStats.config.set("enabled.fished-tag", null);
|
||||||
|
toolStats.config.set("enabled.looted-tag", null);
|
||||||
|
toolStats.config.set("enabled.traded-tag", null);
|
||||||
|
toolStats.config.set("enabled.spawned-in", null);
|
||||||
|
|
||||||
|
toolStats.logger.info("Adding enabled.dropped-on");
|
||||||
|
boolean droppedBy = toolStats.config.getBoolean("enabled.dropped-by");
|
||||||
|
toolStats.config.set("enabled.dropped-on", droppedBy);
|
||||||
|
|
||||||
|
toolStats.logger.info("Adding messages.dropped-on");
|
||||||
|
toolStats.config.set("messages.dropped-on", "&7Dropped on: &8{date}");
|
||||||
|
|
||||||
|
|
||||||
|
// rename crafted to crafted here
|
||||||
|
// copy the old ones first
|
||||||
|
String craftedByMessage = toolStats.config.getString("messages.created.created-by");
|
||||||
|
String craftedOnMessage = toolStats.config.getString("messages.created.created-on");
|
||||||
|
|
||||||
|
toolStats.config.set("messages.created", null);
|
||||||
|
toolStats.config.set("messages.crafted.created-by", null);
|
||||||
|
toolStats.config.set("messages.crafted.created-on", null);
|
||||||
|
|
||||||
|
toolStats.config.set("messages.crafted.crafted-by", craftedByMessage);
|
||||||
|
toolStats.config.set("messages.crafted.crafted-on", craftedOnMessage);
|
||||||
|
|
||||||
|
toolStats.logger.info("Adding normalize-time-creation");
|
||||||
|
toolStats.config.set("normalize-time-creation", false);
|
||||||
|
|
||||||
|
// save the config and reload it
|
||||||
|
try {
|
||||||
|
toolStats.config.save("plugins" + File.separator + "ToolStats" + File.separator + "config.yml");
|
||||||
|
} catch (IOException exception) {
|
||||||
|
toolStats.logger.error("Unable to save config.yml!", exception);
|
||||||
|
}
|
||||||
|
toolStats.loadConfig();
|
||||||
|
toolStats.logger.info("Config has been updated to version 12. A copy of version 11 has been saved as config-11.yml");
|
||||||
|
}
|
||||||
|
|
||||||
|
private void transfer(String oldSection, String newSection) {
|
||||||
|
toolStats.logger.info("Moving {} to {}", oldSection, newSection);
|
||||||
|
ConfigurationSection old = toolStats.config.getConfigurationSection(oldSection);
|
||||||
|
toolStats.config.set(newSection, old);
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,72 @@
|
|||||||
|
/*
|
||||||
|
* This file is part of ToolStats.
|
||||||
|
*
|
||||||
|
* ToolStats is free software: you can redistribute it and/or modify
|
||||||
|
* it under the terms of the GNU General Public License as published by
|
||||||
|
* the Free Software Foundation, either version 3 of the License, or
|
||||||
|
* (at your option) any later version.
|
||||||
|
*
|
||||||
|
* ToolStats is distributed in the hope that it will be useful,
|
||||||
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
* GNU General Public License for more details.
|
||||||
|
*
|
||||||
|
* You should have received a copy of the GNU General Public License
|
||||||
|
* along with ToolStats. If not, see <https://www.gnu.org/licenses/>.
|
||||||
|
*/
|
||||||
|
|
||||||
|
package lol.hyper.toolstats.tools.config.versions;
|
||||||
|
|
||||||
|
import lol.hyper.toolstats.ToolStats;
|
||||||
|
|
||||||
|
import java.io.File;
|
||||||
|
import java.io.IOException;
|
||||||
|
|
||||||
|
public class Version13 {
|
||||||
|
|
||||||
|
private final ToolStats toolStats;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Used for updating from version 12 to 13.
|
||||||
|
*
|
||||||
|
* @param toolStats ToolStats instance.
|
||||||
|
*/
|
||||||
|
public Version13(ToolStats toolStats) {
|
||||||
|
this.toolStats = toolStats;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Perform the config update.
|
||||||
|
*/
|
||||||
|
public void update() {
|
||||||
|
// save the old config first
|
||||||
|
try {
|
||||||
|
toolStats.config.save("plugins" + File.separator + "ToolStats" + File.separator + "config-12.yml");
|
||||||
|
} catch (IOException exception) {
|
||||||
|
toolStats.logger.error("Unable to save config-12.yml!", exception);
|
||||||
|
}
|
||||||
|
|
||||||
|
toolStats.logger.info("Updating config.yml to version 13.");
|
||||||
|
toolStats.config.set("config-version", 13);
|
||||||
|
|
||||||
|
for (String key : toolStats.config.getConfigurationSection("tokens.data").getKeys(false)) {
|
||||||
|
toolStats.logger.info("Adding tokens.data.{}.material", key);
|
||||||
|
toolStats.config.set("tokens.data." + key + ".material", "PAPER");
|
||||||
|
toolStats.logger.info("Adding tokens.data.{}.custom-model-data.enabled", key);
|
||||||
|
toolStats.config.set("tokens.data." + key + ".custom-model-data.enabled", false);
|
||||||
|
toolStats.logger.info("Adding tokens.data.{}.custom-model-data.type", key);
|
||||||
|
toolStats.config.set("tokens.data." + key + ".custom-model-data.type", "float");
|
||||||
|
toolStats.logger.info("Adding tokens.data.{}.custom-model-data.value", key);
|
||||||
|
toolStats.config.set("tokens.data." + key + ".custom-model-data.value", 1001);
|
||||||
|
}
|
||||||
|
|
||||||
|
// save the config and reload it
|
||||||
|
try {
|
||||||
|
toolStats.config.save("plugins" + File.separator + "ToolStats" + File.separator + "config.yml");
|
||||||
|
} catch (IOException exception) {
|
||||||
|
toolStats.logger.error("Unable to save config.yml!", exception);
|
||||||
|
}
|
||||||
|
toolStats.loadConfig();
|
||||||
|
toolStats.logger.info("Config has been updated to version 13. A copy of version 12 has been saved as config-12.yml");
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,114 @@
|
|||||||
|
/*
|
||||||
|
* This file is part of ToolStats.
|
||||||
|
*
|
||||||
|
* ToolStats is free software: you can redistribute it and/or modify
|
||||||
|
* it under the terms of the GNU General Public License as published by
|
||||||
|
* the Free Software Foundation, either version 3 of the License, or
|
||||||
|
* (at your option) any later version.
|
||||||
|
*
|
||||||
|
* ToolStats is distributed in the hope that it will be useful,
|
||||||
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
* GNU General Public License for more details.
|
||||||
|
*
|
||||||
|
* You should have received a copy of the GNU General Public License
|
||||||
|
* along with ToolStats. If not, see <https://www.gnu.org/licenses/>.
|
||||||
|
*/
|
||||||
|
|
||||||
|
package lol.hyper.toolstats.tools.config.versions;
|
||||||
|
|
||||||
|
import lol.hyper.toolstats.ToolStats;
|
||||||
|
|
||||||
|
import java.io.File;
|
||||||
|
import java.io.IOException;
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.Collections;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
public class Version6 {
|
||||||
|
|
||||||
|
private final ToolStats toolStats;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Used for updating from version 5 to 6.
|
||||||
|
*
|
||||||
|
* @param toolStats ToolStats instance.
|
||||||
|
*/
|
||||||
|
public Version6(ToolStats toolStats) {
|
||||||
|
this.toolStats = toolStats;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Perform the config update.
|
||||||
|
*/
|
||||||
|
public void update() {
|
||||||
|
// save the old config first
|
||||||
|
try {
|
||||||
|
toolStats.config.save("plugins" + File.separator + "ToolStats" + File.separator + "config-5.yml");
|
||||||
|
} catch (IOException exception) {
|
||||||
|
toolStats.logger.error("Unable to save config-5.yml!", exception);
|
||||||
|
}
|
||||||
|
|
||||||
|
// we make this super verbose so that admins can see what's being added
|
||||||
|
toolStats.logger.info("Updating config.yml to version 6.");
|
||||||
|
toolStats.config.set("config-version", 6);
|
||||||
|
toolStats.logger.info("Adding enabled.spawned-in.pickaxe to config.yml.");
|
||||||
|
toolStats.config.set("enabled.spawned-in.pickaxe", true);
|
||||||
|
|
||||||
|
toolStats.logger.info("Adding enabled.spawned-in.sword to config.yml.");
|
||||||
|
toolStats.config.set("enabled.spawned-in.sword", true);
|
||||||
|
|
||||||
|
toolStats.logger.info("Adding enabled.spawned-in.shovel to config.yml.");
|
||||||
|
toolStats.config.set("enabled.spawned-in.shovel", true);
|
||||||
|
|
||||||
|
toolStats.logger.info("Adding enabled.spawned-in.axe to config.yml.");
|
||||||
|
toolStats.config.set("enabled.spawned-in.axe", true);
|
||||||
|
|
||||||
|
toolStats.logger.info("Adding enabled.spawned-in.hoe to config.yml.");
|
||||||
|
toolStats.config.set("enabled.spawned-in.hoe", true);
|
||||||
|
|
||||||
|
toolStats.logger.info("Adding enabled.spawned-in.fishing-rod to config.yml.");
|
||||||
|
toolStats.config.set("enabled.spawned-in.fishing-rod", true);
|
||||||
|
|
||||||
|
toolStats.logger.info("Adding enabled.spawned-in.shears to config.yml.");
|
||||||
|
toolStats.config.set("enabled.spawned-in.shears", true);
|
||||||
|
|
||||||
|
toolStats.logger.info("Adding enabled.spawned-in.bow to config.yml.");
|
||||||
|
toolStats.config.set("enabled.spawned-in.bow", true);
|
||||||
|
|
||||||
|
toolStats.logger.info("Adding enabled.spawned-in.armor to config.yml.");
|
||||||
|
toolStats.config.set("enabled.spawned-in.armor", true);
|
||||||
|
|
||||||
|
toolStats.logger.info("Adding messages.spawned-in.spawned-by to config.yml.");
|
||||||
|
toolStats.config.set("messages.spawned-in.spawned-by", "&7Spawned in by: &8{player}");
|
||||||
|
|
||||||
|
toolStats.logger.info("Adding messages.spawned-in.spawned-on to config.yml.");
|
||||||
|
toolStats.config.set("messages.spawned-in.spawned-on", "&7Spawned on: &8{date}");
|
||||||
|
|
||||||
|
toolStats.logger.info("Adding generate-hash-for-items to config.yml.");
|
||||||
|
toolStats.config.set("generate-hash-for-items", true);
|
||||||
|
|
||||||
|
toolStats.logger.info("Adding enabled.arrows-shot to config.yml.");
|
||||||
|
toolStats.config.set("enabled.arrows-shot", true);
|
||||||
|
|
||||||
|
toolStats.logger.info("Adding messages.arrows-shot to config.yml.");
|
||||||
|
toolStats.config.set("messages.arrows-shot", "&7Arrows shot: &8{arrows}");
|
||||||
|
|
||||||
|
List<String> hashComments = new ArrayList<>();
|
||||||
|
hashComments.add("When any tool is created, it will generate a hash for the item.");
|
||||||
|
hashComments.add("This hash is not on the item lore, only stored in the NBT data.");
|
||||||
|
hashComments.add("This has no use currently, but can be used for future features for dupe detection.");
|
||||||
|
toolStats.config.setComments("generate-hash-for-items", hashComments);
|
||||||
|
|
||||||
|
toolStats.config.setComments("enabled.spawned-in", Collections.singletonList("Will show \"Spawned in by <player>\""));
|
||||||
|
|
||||||
|
// save the config and reload it
|
||||||
|
try {
|
||||||
|
toolStats.config.save("plugins" + File.separator + "ToolStats" + File.separator + "config.yml");
|
||||||
|
} catch (IOException exception) {
|
||||||
|
toolStats.logger.error("Unable to save config.yml!", exception);
|
||||||
|
}
|
||||||
|
toolStats.loadConfig();
|
||||||
|
toolStats.logger.info("Config has been updated to version 6. A copy of version 5 has been saved as config-5.yml");
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,68 @@
|
|||||||
|
/*
|
||||||
|
* This file is part of ToolStats.
|
||||||
|
*
|
||||||
|
* ToolStats is free software: you can redistribute it and/or modify
|
||||||
|
* it under the terms of the GNU General Public License as published by
|
||||||
|
* the Free Software Foundation, either version 3 of the License, or
|
||||||
|
* (at your option) any later version.
|
||||||
|
*
|
||||||
|
* ToolStats is distributed in the hope that it will be useful,
|
||||||
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
* GNU General Public License for more details.
|
||||||
|
*
|
||||||
|
* You should have received a copy of the GNU General Public License
|
||||||
|
* along with ToolStats. If not, see <https://www.gnu.org/licenses/>.
|
||||||
|
*/
|
||||||
|
|
||||||
|
package lol.hyper.toolstats.tools.config.versions;
|
||||||
|
|
||||||
|
import lol.hyper.toolstats.ToolStats;
|
||||||
|
|
||||||
|
import java.io.File;
|
||||||
|
import java.io.IOException;
|
||||||
|
|
||||||
|
public class Version7 {
|
||||||
|
|
||||||
|
private final ToolStats toolStats;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Used for updating from version 6 to 7.
|
||||||
|
*
|
||||||
|
* @param toolStats ToolStats instance.
|
||||||
|
*/
|
||||||
|
public Version7(ToolStats toolStats) {
|
||||||
|
this.toolStats = toolStats;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Perform the config update.
|
||||||
|
*/
|
||||||
|
public void update() {
|
||||||
|
// save the old config first
|
||||||
|
try {
|
||||||
|
toolStats.config.save("plugins" + File.separator + "ToolStats" + File.separator + "config-6.yml");
|
||||||
|
} catch (IOException exception) {
|
||||||
|
toolStats.logger.error("Unable to save config-6.yml!", exception);
|
||||||
|
}
|
||||||
|
|
||||||
|
// we make this super verbose so that admins can see what's being added
|
||||||
|
toolStats.logger.info("Updating config.yml to version 7.");
|
||||||
|
toolStats.config.set("config-version", 7);
|
||||||
|
|
||||||
|
toolStats.logger.info("Adding messages.flight-time to config.yml.");
|
||||||
|
toolStats.config.set("messages.flight-time", "&7Flight time: &8{time}");
|
||||||
|
|
||||||
|
toolStats.logger.info("Adding enabled.flight-time to config.yml.");
|
||||||
|
toolStats.config.set("enabled.flight-time", true);
|
||||||
|
|
||||||
|
// save the config and reload it
|
||||||
|
try {
|
||||||
|
toolStats.config.save("plugins" + File.separator + "ToolStats" + File.separator + "config.yml");
|
||||||
|
} catch (IOException exception) {
|
||||||
|
toolStats.logger.error("Unable to save config.yml!", exception);
|
||||||
|
}
|
||||||
|
toolStats.loadConfig();
|
||||||
|
toolStats.logger.info("Config has been updated to version 7. A copy of version 6 has been saved as config-6.yml");
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,85 @@
|
|||||||
|
/*
|
||||||
|
* This file is part of ToolStats.
|
||||||
|
*
|
||||||
|
* ToolStats is free software: you can redistribute it and/or modify
|
||||||
|
* it under the terms of the GNU General Public License as published by
|
||||||
|
* the Free Software Foundation, either version 3 of the License, or
|
||||||
|
* (at your option) any later version.
|
||||||
|
*
|
||||||
|
* ToolStats is distributed in the hope that it will be useful,
|
||||||
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
* GNU General Public License for more details.
|
||||||
|
*
|
||||||
|
* You should have received a copy of the GNU General Public License
|
||||||
|
* along with ToolStats. If not, see <https://www.gnu.org/licenses/>.
|
||||||
|
*/
|
||||||
|
|
||||||
|
package lol.hyper.toolstats.tools.config.versions;
|
||||||
|
|
||||||
|
import lol.hyper.toolstats.ToolStats;
|
||||||
|
|
||||||
|
import java.io.File;
|
||||||
|
import java.io.IOException;
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
public class Version8 {
|
||||||
|
|
||||||
|
private final ToolStats toolStats;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Used for updating from version 7 to 8.
|
||||||
|
*
|
||||||
|
* @param toolStats ToolStats instance.
|
||||||
|
*/
|
||||||
|
public Version8(ToolStats toolStats) {
|
||||||
|
this.toolStats = toolStats;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Perform the config update.
|
||||||
|
*/
|
||||||
|
public void update() {
|
||||||
|
// save the old config first
|
||||||
|
try {
|
||||||
|
toolStats.config.save("plugins" + File.separator + "ToolStats" + File.separator + "config-7.yml");
|
||||||
|
} catch (IOException exception) {
|
||||||
|
toolStats.logger.error("Unable to save config-7.yml!", exception);
|
||||||
|
}
|
||||||
|
|
||||||
|
// we make this super verbose so that admins can see what's being added
|
||||||
|
toolStats.logger.info("Updating config.yml to version 8.");
|
||||||
|
toolStats.config.set("config-version", 8);
|
||||||
|
|
||||||
|
// Add example to setting mob names
|
||||||
|
toolStats.logger.info("Adding example for messages.mob.ZOMBIE");
|
||||||
|
toolStats.config.set("messages.mob.ZOMBIE", "Zombie");
|
||||||
|
|
||||||
|
// Add mace to enabled sections
|
||||||
|
toolStats.logger.info("Adding entry for enabled.created-by.mace");
|
||||||
|
toolStats.config.set("enabled.created-by.mace", true);
|
||||||
|
|
||||||
|
toolStats.logger.info("Adding entry for enabled.created-date.mace");
|
||||||
|
toolStats.config.set("enabled.created-date.mace", true);
|
||||||
|
|
||||||
|
toolStats.logger.info("Adding entry for enabled.player-kills.mace");
|
||||||
|
toolStats.config.set("enabled.player-kills.mace", true);
|
||||||
|
|
||||||
|
toolStats.logger.info("Adding entry for enabled.mob-kills.mace");
|
||||||
|
toolStats.config.set("enabled.mob-kills.mace", true);
|
||||||
|
|
||||||
|
List<String> mobComments = new ArrayList<>();
|
||||||
|
mobComments.add("Set display name for mobs. See: https://hub.spigotmc.org/javadocs/bukkit/org/bukkit/entity/EntityType.html");
|
||||||
|
toolStats.config.setComments("messages.mob", mobComments);
|
||||||
|
|
||||||
|
// save the config and reload it
|
||||||
|
try {
|
||||||
|
toolStats.config.save("plugins" + File.separator + "ToolStats" + File.separator + "config.yml");
|
||||||
|
} catch (IOException exception) {
|
||||||
|
toolStats.logger.error("Unable to save config.yml!", exception);
|
||||||
|
}
|
||||||
|
toolStats.loadConfig();
|
||||||
|
toolStats.logger.info("Config has been updated to version 8. A copy of version 7 has been saved as config-7.yml");
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,101 @@
|
|||||||
|
/*
|
||||||
|
* This file is part of ToolStats.
|
||||||
|
*
|
||||||
|
* ToolStats is free software: you can redistribute it and/or modify
|
||||||
|
* it under the terms of the GNU General Public License as published by
|
||||||
|
* the Free Software Foundation, either version 3 of the License, or
|
||||||
|
* (at your option) any later version.
|
||||||
|
*
|
||||||
|
* ToolStats is distributed in the hope that it will be useful,
|
||||||
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
* GNU General Public License for more details.
|
||||||
|
*
|
||||||
|
* You should have received a copy of the GNU General Public License
|
||||||
|
* along with ToolStats. If not, see <https://www.gnu.org/licenses/>.
|
||||||
|
*/
|
||||||
|
|
||||||
|
package lol.hyper.toolstats.tools.config.versions;
|
||||||
|
|
||||||
|
import lol.hyper.toolstats.ToolStats;
|
||||||
|
|
||||||
|
import java.io.File;
|
||||||
|
import java.io.IOException;
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
public class Version9 {
|
||||||
|
|
||||||
|
private final ToolStats toolStats;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Used for updating from version 8 to 9.
|
||||||
|
*
|
||||||
|
* @param toolStats ToolStats instance.
|
||||||
|
*/
|
||||||
|
public Version9(ToolStats toolStats) {
|
||||||
|
this.toolStats = toolStats;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Perform the config update.
|
||||||
|
*/
|
||||||
|
public void update() {
|
||||||
|
// save the old config first
|
||||||
|
try {
|
||||||
|
toolStats.config.save("plugins" + File.separator + "ToolStats" + File.separator + "config-8.yml");
|
||||||
|
} catch (IOException exception) {
|
||||||
|
toolStats.logger.error("Unable to save config-8.yml!", exception);
|
||||||
|
}
|
||||||
|
|
||||||
|
toolStats.logger.info("Updating config.yml to version 9.");
|
||||||
|
toolStats.config.set("config-version", 9);
|
||||||
|
|
||||||
|
toolStats.logger.info("Adding new tokens configuration! Don't worry, this is disabled by default.");
|
||||||
|
toolStats.logger.info("You can find more information here: https://github.com/hyperdefined/ToolStats/wiki/Token-System");
|
||||||
|
// false by default so it doesn't break servers on updating
|
||||||
|
toolStats.config.set("tokens.enabled", false);
|
||||||
|
toolStats.config.set("tokens.craft-tokens", true);
|
||||||
|
|
||||||
|
List<String> tokenComments = new ArrayList<>();
|
||||||
|
tokenComments.add("Use token system for tracking stats.");
|
||||||
|
tokenComments.add("See https://github.com/hyperdefined/ToolStats/wiki/Token-System");
|
||||||
|
toolStats.config.setComments("tokens", tokenComments);
|
||||||
|
|
||||||
|
addToken("player-kills", "&7ToolStats: &8Player Kills Token", "&8Combine with a melee or ranged weapon in an anvil to track player kills.");
|
||||||
|
addToken("mob-kills", "&7ToolStats: &8Mob Kills Token", "&8Combine with a melee or ranged weapon in an anvil to track mob kills.");
|
||||||
|
addToken("blocks-mined", "&7ToolStats: &8Blocks Mined Token", "&8Combine with a pickaxe, axe, shovel, or shears in an anvil to track blocks mined.");
|
||||||
|
addToken("crops-mined", "&7ToolStats: &8Crops Mined Token", "&8Combine with a hoe in an anvil to track crops broken.");
|
||||||
|
addToken("fish-caught", "&7ToolStats: &8Fish Caught Token", "&8Combine with a fishing rod in an anvil to track fish caught.");
|
||||||
|
addToken("sheep-sheared", "&7ToolStats: &8Sheep Sheared Token", "&8Combine with shears in an anvil to track sheep sheared.");
|
||||||
|
addToken("damage-taken", "&7ToolStats: &8Damage Taken Token", "&8Combine with an armor piece in an anvil to track damage taken.");
|
||||||
|
addToken("arrows-shot", "&7ToolStats: &8Arrows Shot Token", "&8Combine with a bow or crossbow in an anvil to track arrows shot.");
|
||||||
|
addToken("flight-time", "&7ToolStats: &8Flight Time Token", "&8Combine with an elytra in an anvil to track flight time.");
|
||||||
|
addToken("reset", "&7ToolStats: &8Reset Token", "&8Combine in an anvil with to reset ALL stats for this item. Tokens on this item stay.");
|
||||||
|
|
||||||
|
// save the config and reload it
|
||||||
|
try {
|
||||||
|
toolStats.config.save("plugins" + File.separator + "ToolStats" + File.separator + "config.yml");
|
||||||
|
} catch (IOException exception) {
|
||||||
|
toolStats.logger.error("Unable to save config.yml!", exception);
|
||||||
|
}
|
||||||
|
toolStats.loadConfig();
|
||||||
|
toolStats.logger.info("Config has been updated to version 9. A copy of version 8 has been saved as config-8.yml");
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Add a given token to the config. Made this since I was lazy.
|
||||||
|
*
|
||||||
|
* @param tokenType The token type to add.
|
||||||
|
* @param title The title for the item.
|
||||||
|
* @param lore The lore of the item.
|
||||||
|
*/
|
||||||
|
private void addToken(String tokenType, String title, String lore) {
|
||||||
|
toolStats.logger.info("Adding token type configuration for {}", tokenType);
|
||||||
|
toolStats.config.set("tokens.data." + tokenType + ".title", title);
|
||||||
|
List<String> loreList = new ArrayList<>();
|
||||||
|
loreList.add(lore);
|
||||||
|
toolStats.config.set("tokens.data." + tokenType + ".lore", loreList);
|
||||||
|
toolStats.config.set("tokens.data." + tokenType + ".levels", 1);
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -1,6 +1,145 @@
|
|||||||
|
# Use token system for tracking stats.
|
||||||
|
# See https://github.com/hyperdefined/ToolStats/wiki/Token-System
|
||||||
|
tokens:
|
||||||
|
enabled: false
|
||||||
|
craft-tokens: true
|
||||||
|
data:
|
||||||
|
player-kills:
|
||||||
|
title: "&7ToolStats: &8Player Kills Token"
|
||||||
|
lore:
|
||||||
|
- "&8Combine with a melee or ranged weapon in an anvil to track player kills."
|
||||||
|
- "&8Uses &7{levels} &8level."
|
||||||
|
levels: 1
|
||||||
|
material: PAPER
|
||||||
|
custom-model-data:
|
||||||
|
enabled: false
|
||||||
|
type: float
|
||||||
|
value: 1001
|
||||||
|
mob-kills:
|
||||||
|
title: "&7ToolStats: &8Mob Kills Token"
|
||||||
|
lore:
|
||||||
|
- "&8Combine with a melee or ranged weapon in an anvil to track mob kills."
|
||||||
|
- "&8Uses &7{levels} &8level."
|
||||||
|
levels: 1
|
||||||
|
material: PAPER
|
||||||
|
custom-model-data:
|
||||||
|
enabled: false
|
||||||
|
type: float
|
||||||
|
value: 1001
|
||||||
|
blocks-mined:
|
||||||
|
title: "&7ToolStats: &8Blocks Mined Token"
|
||||||
|
lore:
|
||||||
|
- "&8Combine with a pickaxe, axe, shovel, or shears in an anvil to track blocks mined."
|
||||||
|
- "&8Uses &7{levels} &8level."
|
||||||
|
levels: 1
|
||||||
|
material: PAPER
|
||||||
|
custom-model-data:
|
||||||
|
enabled: false
|
||||||
|
type: float
|
||||||
|
value: 1001
|
||||||
|
crops-mined:
|
||||||
|
title: "&7ToolStats: &8Crops Mined Token"
|
||||||
|
lore:
|
||||||
|
- "&8Combine with a hoe in an anvil to track crops broken."
|
||||||
|
- "&8Uses &7{levels} &8level."
|
||||||
|
levels: 1
|
||||||
|
material: PAPER
|
||||||
|
custom-model-data:
|
||||||
|
enabled: false
|
||||||
|
type: float
|
||||||
|
value: 1001
|
||||||
|
fish-caught:
|
||||||
|
title: "&7ToolStats: &8Fish Caught Token"
|
||||||
|
lore:
|
||||||
|
- "&8Combine with a fishing rod in an anvil to track fish caught."
|
||||||
|
- "&8Uses &7{levels} &8level."
|
||||||
|
levels: 1
|
||||||
|
material: PAPER
|
||||||
|
custom-model-data:
|
||||||
|
enabled: false
|
||||||
|
type: float
|
||||||
|
value: 1001
|
||||||
|
sheep-sheared:
|
||||||
|
title: "&7ToolStats: &8Sheep Sheared Token"
|
||||||
|
lore:
|
||||||
|
- "&8Combine with shears in an anvil to track sheep sheared."
|
||||||
|
- "&8Uses &7{levels} &8level."
|
||||||
|
levels: 1
|
||||||
|
material: PAPER
|
||||||
|
custom-model-data:
|
||||||
|
enabled: false
|
||||||
|
type: float
|
||||||
|
value: 1001
|
||||||
|
damage-taken:
|
||||||
|
title: "&7ToolStats: &8Damage Taken Token"
|
||||||
|
lore:
|
||||||
|
- "&8Combine with an armor piece in an anvil to track damage taken."
|
||||||
|
- "&8Uses &7{levels} &8level."
|
||||||
|
levels: 1
|
||||||
|
material: PAPER
|
||||||
|
custom-model-data:
|
||||||
|
enabled: false
|
||||||
|
type: float
|
||||||
|
value: 1001
|
||||||
|
damage-done:
|
||||||
|
title: "&7ToolStats: &8Damage Done Token"
|
||||||
|
lore:
|
||||||
|
- "&8Combine with a melee or ranged weapon in an anvil to track damage done."
|
||||||
|
- "&8Uses &7{levels} &8level."
|
||||||
|
levels: 1
|
||||||
|
material: PAPER
|
||||||
|
custom-model-data:
|
||||||
|
enabled: false
|
||||||
|
type: float
|
||||||
|
value: 1001
|
||||||
|
arrows-shot:
|
||||||
|
title: "&7ToolStats: &8Arrows Shot Token"
|
||||||
|
lore:
|
||||||
|
- "&8Combine with a bow or crossbow in an anvil to track arrows shot."
|
||||||
|
- "&8Uses &7{levels} &8level."
|
||||||
|
levels: 1
|
||||||
|
material: PAPER
|
||||||
|
custom-model-data:
|
||||||
|
enabled: false
|
||||||
|
type: float
|
||||||
|
value: 1001
|
||||||
|
flight-time:
|
||||||
|
title: "&7ToolStats: &8Flight Time Token"
|
||||||
|
lore:
|
||||||
|
- "&8Combine with an elytra in an anvil to track flight time."
|
||||||
|
- "&8Uses &7{levels} &8level."
|
||||||
|
levels: 1
|
||||||
|
material: PAPER
|
||||||
|
custom-model-data:
|
||||||
|
enabled: false
|
||||||
|
type: float
|
||||||
|
value: 1001
|
||||||
|
reset:
|
||||||
|
title: "&7ToolStats: &8Reset Token"
|
||||||
|
lore:
|
||||||
|
- "&8Combine in an anvil with to reset ALL stats for this item. Tokens on this item stay."
|
||||||
|
- "&8Uses &7{levels} &8level."
|
||||||
|
levels: 1
|
||||||
|
material: PAPER
|
||||||
|
custom-model-data:
|
||||||
|
enabled: false
|
||||||
|
type: float
|
||||||
|
value: 1001
|
||||||
|
remove:
|
||||||
|
title: "&7ToolStats: &8Remove Token"
|
||||||
|
lore:
|
||||||
|
- "&8Combine in an anvil with to REMOVE ALL stats and tokens for this item."
|
||||||
|
- "&8Uses &7{levels} &8level."
|
||||||
|
levels: 1
|
||||||
|
material: PAPER
|
||||||
|
custom-model-data:
|
||||||
|
enabled: false
|
||||||
|
type: float
|
||||||
|
value: 1001
|
||||||
|
|
||||||
enabled:
|
enabled:
|
||||||
# Will show ownership of items when they are created/found.
|
# Will show "Crafted by <player>"
|
||||||
created-by:
|
crafted-by:
|
||||||
pickaxe: true
|
pickaxe: true
|
||||||
sword: true
|
sword: true
|
||||||
shovel: true
|
shovel: true
|
||||||
@@ -9,8 +148,10 @@ enabled:
|
|||||||
shears: true
|
shears: true
|
||||||
bow: true
|
bow: true
|
||||||
armor: true
|
armor: true
|
||||||
# Will show time the item is created
|
mace: true
|
||||||
created-date:
|
fishing-rod: true
|
||||||
|
# Will show "Crafted on <date>"
|
||||||
|
crafted-on:
|
||||||
pickaxe: true
|
pickaxe: true
|
||||||
sword: true
|
sword: true
|
||||||
shovel: true
|
shovel: true
|
||||||
@@ -19,8 +160,10 @@ enabled:
|
|||||||
shears: true
|
shears: true
|
||||||
bow: true
|
bow: true
|
||||||
armor: true
|
armor: true
|
||||||
|
mace: true
|
||||||
|
fishing-rod: true
|
||||||
# Will show "Fished by <player>"
|
# Will show "Fished by <player>"
|
||||||
fished-tag:
|
fished-by:
|
||||||
pickaxe: true
|
pickaxe: true
|
||||||
sword: true
|
sword: true
|
||||||
shovel: true
|
shovel: true
|
||||||
@@ -29,8 +172,20 @@ enabled:
|
|||||||
shears: true
|
shears: true
|
||||||
bow: true
|
bow: true
|
||||||
armor: true
|
armor: true
|
||||||
|
fishing-rod: true
|
||||||
|
# Will show "Fished on <date>"
|
||||||
|
fished-on:
|
||||||
|
pickaxe: true
|
||||||
|
sword: true
|
||||||
|
shovel: true
|
||||||
|
axe: true
|
||||||
|
hoe: true
|
||||||
|
shears: true
|
||||||
|
bow: true
|
||||||
|
armor: true
|
||||||
|
fishing-rod: true
|
||||||
# Will show "Found by <player>"
|
# Will show "Found by <player>"
|
||||||
looted-tag:
|
looted-by:
|
||||||
pickaxe: true
|
pickaxe: true
|
||||||
sword: true
|
sword: true
|
||||||
shovel: true
|
shovel: true
|
||||||
@@ -39,8 +194,9 @@ enabled:
|
|||||||
shears: true
|
shears: true
|
||||||
bow: true
|
bow: true
|
||||||
armor: true
|
armor: true
|
||||||
# Will show "Trade by <player>"
|
fishing-rod: true
|
||||||
traded-tag:
|
# Will show "Found on <date>"
|
||||||
|
looted-on:
|
||||||
pickaxe: true
|
pickaxe: true
|
||||||
sword: true
|
sword: true
|
||||||
shovel: true
|
shovel: true
|
||||||
@@ -49,37 +205,98 @@ enabled:
|
|||||||
shears: true
|
shears: true
|
||||||
bow: true
|
bow: true
|
||||||
armor: true
|
armor: true
|
||||||
|
fishing-rod: true
|
||||||
|
# Will show "Traded by <player>"
|
||||||
|
traded-by:
|
||||||
|
pickaxe: true
|
||||||
|
sword: true
|
||||||
|
shovel: true
|
||||||
|
axe: true
|
||||||
|
hoe: true
|
||||||
|
shears: true
|
||||||
|
bow: true
|
||||||
|
armor: true
|
||||||
|
fishing-rod: true
|
||||||
|
# Will show "Traded on <date>"
|
||||||
|
traded-on:
|
||||||
|
pickaxe: true
|
||||||
|
sword: true
|
||||||
|
shovel: true
|
||||||
|
axe: true
|
||||||
|
hoe: true
|
||||||
|
shears: true
|
||||||
|
bow: true
|
||||||
|
armor: true
|
||||||
|
fishing-rod: true
|
||||||
|
damage-done:
|
||||||
|
sword: true
|
||||||
|
axe: true
|
||||||
|
trident: true
|
||||||
|
bow: true
|
||||||
|
mace: true
|
||||||
player-kills:
|
player-kills:
|
||||||
sword: true
|
sword: true
|
||||||
axe: true
|
axe: true
|
||||||
trident: true
|
trident: true
|
||||||
bow: true
|
bow: true
|
||||||
|
mace: true
|
||||||
mob-kills:
|
mob-kills:
|
||||||
sword: true
|
sword: true
|
||||||
axe: true
|
axe: true
|
||||||
trident: true
|
trident: true
|
||||||
bow: true
|
bow: true
|
||||||
|
mace: true
|
||||||
blocks-mined:
|
blocks-mined:
|
||||||
pickaxe: true
|
pickaxe: true
|
||||||
shovel: true
|
shovel: true
|
||||||
axe: true
|
axe: true
|
||||||
hoe: true
|
hoe: true
|
||||||
shears: true
|
shears: true
|
||||||
|
# Will show "Spawned in by <player>"
|
||||||
|
spawned-in-by:
|
||||||
|
pickaxe: true
|
||||||
|
sword: true
|
||||||
|
shovel: true
|
||||||
|
axe: true
|
||||||
|
hoe: true
|
||||||
|
shears: true
|
||||||
|
bow: true
|
||||||
|
armor: true
|
||||||
|
mace: true
|
||||||
|
fishing-rod: true
|
||||||
|
# Will show "Spawned in on <date>"
|
||||||
|
spawned-in-on:
|
||||||
|
pickaxe: true
|
||||||
|
sword: true
|
||||||
|
shovel: true
|
||||||
|
axe: true
|
||||||
|
hoe: true
|
||||||
|
shears: true
|
||||||
|
bow: true
|
||||||
|
armor: true
|
||||||
|
mace: true
|
||||||
|
fishing-rod: true
|
||||||
fish-caught: true
|
fish-caught: true
|
||||||
sheep-sheared: true
|
sheep-sheared: true
|
||||||
armor-damage: true
|
armor-damage: true
|
||||||
dropped-by: true
|
dropped-by: true
|
||||||
|
dropped-on: true
|
||||||
elytra-tag: true
|
elytra-tag: true
|
||||||
|
arrows-shot: true
|
||||||
|
flight-time: true
|
||||||
|
crops-harvested: true
|
||||||
|
|
||||||
messages:
|
messages:
|
||||||
created:
|
crafted:
|
||||||
created-by: "&7Crafted by: &8{player}"
|
crafted-by: "&7Crafted by: &8{player}"
|
||||||
created-on: "&7Crafted on: &8{date}"
|
crafted-on: "&7Crafted on: &8{date}"
|
||||||
fished:
|
fished:
|
||||||
caught-by: "&7Caught by: &8{player}"
|
caught-by: "&7Caught by: &8{player}"
|
||||||
caught-on: "&7Caught on: &8{date}"
|
caught-on: "&7Caught on: &8{date}"
|
||||||
fish-caught: "&7Fish caught: &8{fish}"
|
fish-caught: "&7Fish caught: &8{fish}"
|
||||||
looted:
|
looted:
|
||||||
|
looted-by: "&7Looted by: &8{player}"
|
||||||
|
looted-on: "&7Looted on: &8{date}"
|
||||||
found-by: "&7Found by: &8{player}"
|
found-by: "&7Found by: &8{player}"
|
||||||
found-on: "&7Found on: &8{date}"
|
found-on: "&7Found on: &8{date}"
|
||||||
traded:
|
traded:
|
||||||
@@ -88,15 +305,21 @@ messages:
|
|||||||
kills:
|
kills:
|
||||||
mob: "&7Mob kills: &8{kills}"
|
mob: "&7Mob kills: &8{kills}"
|
||||||
player: "&7Player kills: &8{kills}"
|
player: "&7Player kills: &8{kills}"
|
||||||
|
spawned-in:
|
||||||
|
spawned-by: "&7Spawned in by: &8{player}"
|
||||||
|
spawned-on: "&7Spawned on: &8{date}"
|
||||||
blocks-mined: "&7Blocks mined: &8{blocks}"
|
blocks-mined: "&7Blocks mined: &8{blocks}"
|
||||||
|
crops-harvested: "&7Crops harvested: &8{crops}"
|
||||||
sheep-sheared: "&7Sheep sheared: &8{sheep}"
|
sheep-sheared: "&7Sheep sheared: &8{sheep}"
|
||||||
dropped-by: "&7Dropped by: &8{name}" # name will be player/mob name
|
dropped-by: "&7Dropped by: &8{name}" # name will be mob name
|
||||||
|
dropped-on: "&7Dropped on: &8{date}"
|
||||||
damage-taken: "&7Damage taken: &8{damage}"
|
damage-taken: "&7Damage taken: &8{damage}"
|
||||||
# Display this message if the player shift click trades/crafts items. It's not really easy to get every single item
|
arrows-shot: "&7Arrows shot: &8{arrows}"
|
||||||
# that is crafted. The tag will only be added to the first item. If you don't want this message, simply replace them both with ""
|
flight-time: "&7Flight time: &8{years}y {months}m {days}d {hours}h {minutes}m {seconds}s"
|
||||||
shift-click-warning:
|
damage-done: "&7Damage done: &8{damage}"
|
||||||
crafting: "&cCrafting items via shift clicking does not fully apply tags to each item. This is a limitation with the Bukkit API."
|
# Set display name for mobs. See: https://hub.spigotmc.org/javadocs/bukkit/org/bukkit/entity/EntityType.html
|
||||||
trading: "&cTrading items via shift clicking does not fully apply tags to each item. This is a limitation with the Bukkit API."
|
mobs:
|
||||||
|
ZOMBIE: "Zombie"
|
||||||
|
|
||||||
# Change the default formatting for dates.
|
# Change the default formatting for dates.
|
||||||
# See: https://www.digitalocean.com/community/tutorials/java-simpledateformat-java-date-format
|
# See: https://www.digitalocean.com/community/tutorials/java-simpledateformat-java-date-format
|
||||||
@@ -109,6 +332,18 @@ number-formats:
|
|||||||
comma-separator: ","
|
comma-separator: ","
|
||||||
decimal-separator: "."
|
decimal-separator: "."
|
||||||
comma-format: "#,###"
|
comma-format: "#,###"
|
||||||
decimal-format: "#,###.00"
|
decimal-format: "#,##0.00"
|
||||||
|
|
||||||
config-version: 4
|
# When any tool is created, it will generate a hash for the item.
|
||||||
|
# This hash is not on the item lore, only stored in the NBT data.
|
||||||
|
# This has no use currently, but can be used for future features for dupe detection.
|
||||||
|
generate-hash-for-items: false
|
||||||
|
|
||||||
|
# Make when items are created at midnight on the date.
|
||||||
|
# This makes dates for items more "normalized" instead of being at different times.
|
||||||
|
normalize-time-creation: false
|
||||||
|
|
||||||
|
# Allows stats and origins to be tracked if the player is in creative mode.
|
||||||
|
allow-creative: false
|
||||||
|
|
||||||
|
config-version: 13
|
||||||
@@ -1,9 +1,11 @@
|
|||||||
name: ToolStats
|
name: ToolStats
|
||||||
version: '${project.version}'
|
version: '${project.version}'
|
||||||
main: lol.hyper.toolstats.ToolStats
|
main: lol.hyper.toolstats.ToolStats
|
||||||
api-version: 1.15
|
api-version: 1.21
|
||||||
author: hyperdefined
|
author: hyperdefined
|
||||||
description: Track various tool stats!
|
description: Track various tool stats!
|
||||||
|
website: https://github.com/hyperdefined/ToolStats
|
||||||
|
folia-supported: true
|
||||||
commands:
|
commands:
|
||||||
toolstats:
|
toolstats:
|
||||||
usage: /toolstats
|
usage: /toolstats
|
||||||
@@ -21,3 +23,18 @@ permissions:
|
|||||||
toolstats.reset.confirm:
|
toolstats.reset.confirm:
|
||||||
description: Allows the usage of /toolstats reset confirm.
|
description: Allows the usage of /toolstats reset confirm.
|
||||||
default: true
|
default: true
|
||||||
|
toolstats.purge:
|
||||||
|
description: Allows the usage of /toolstats purge.
|
||||||
|
default: true
|
||||||
|
toolstats.purge.confirm:
|
||||||
|
description: Allows the usage of /toolstats purge confirm.
|
||||||
|
default: true
|
||||||
|
toolstats.givetokens:
|
||||||
|
description: Allows the usage of /toolstats givetoken.
|
||||||
|
default: op
|
||||||
|
toolstats.edit:
|
||||||
|
description: Allows the usage of /toolstats edit.
|
||||||
|
default: op
|
||||||
|
toolstats.remove:
|
||||||
|
description: Allows the usage of /toolstats remove.
|
||||||
|
default: op
|
||||||