mirror of
https://github.com/hyperdefined/ToolStats.git
synced 2025-12-05 22:31:45 +00:00
Compare commits
46 Commits
1.9.2-hotf
...
67d141c452
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
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 |
1
.github/FUNDING.yml
vendored
Normal file
1
.github/FUNDING.yml
vendored
Normal file
@@ -0,0 +1 @@
|
||||
buy_me_a_coffee: hyperdefined
|
||||
674
LICENSE
Normal file
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>.
|
||||
@@ -12,14 +12,15 @@
|
||||
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:
|
||||
* Blocks mined (pickaxes, shovels, axes, hoes, shears)
|
||||
* Crops mined (hoes)
|
||||
* Player/mob kills (swords, axes, tridents, bows/crossbows, mace)
|
||||
* Blocks mined (pickaxes, shovels, axes, hoes, shears).
|
||||
* Crops mined (hoes).
|
||||
* 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.
|
||||
* Damage done with weapons.
|
||||
* Fish caught.
|
||||
* Sheep sheared.
|
||||
* Arrows shot (bows/crossbows)
|
||||
* Arrows shot (bows/crossbows).
|
||||
* Flight time with elytras.
|
||||
|
||||
The best part is, this data is stored on the item itself.
|
||||
|
||||
BIN
images/crafting/damage-done.png
Normal file
BIN
images/crafting/damage-done.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 7.6 KiB |
BIN
images/crafting/remove-token.png
Normal file
BIN
images/crafting/remove-token.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 6.6 KiB |
8
pom.xml
8
pom.xml
@@ -23,7 +23,7 @@
|
||||
|
||||
<groupId>lol.hyper</groupId>
|
||||
<artifactId>toolstats</artifactId>
|
||||
<version>1.9.2-hotfix</version>
|
||||
<version>1.9.6</version>
|
||||
<packaging>jar</packaging>
|
||||
|
||||
<name>ToolStats</name>
|
||||
@@ -37,7 +37,7 @@
|
||||
<plugins>
|
||||
<plugin>
|
||||
<artifactId>maven-clean-plugin</artifactId>
|
||||
<version>3.4.0</version>
|
||||
<version>3.4.1</version>
|
||||
<executions>
|
||||
<execution>
|
||||
<id>auto-clean</id>
|
||||
@@ -51,7 +51,7 @@
|
||||
<plugin>
|
||||
<groupId>org.apache.maven.plugins</groupId>
|
||||
<artifactId>maven-compiler-plugin</artifactId>
|
||||
<version>3.13.0</version>
|
||||
<version>3.14.0</version>
|
||||
<configuration>
|
||||
<source>${java.version}</source>
|
||||
<target>${java.version}</target>
|
||||
@@ -105,7 +105,7 @@
|
||||
<dependency>
|
||||
<groupId>io.papermc.paper</groupId>
|
||||
<artifactId>paper-api</artifactId>
|
||||
<version>1.21.4-R0.1-SNAPSHOT</version>
|
||||
<version>1.21.5-R0.1-SNAPSHOT</version>
|
||||
<scope>provided</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
|
||||
@@ -19,6 +19,7 @@ package lol.hyper.toolstats;
|
||||
|
||||
import lol.hyper.githubreleaseapi.GitHubRelease;
|
||||
import lol.hyper.githubreleaseapi.GitHubReleaseAPI;
|
||||
import lol.hyper.githubreleaseapi.ReleaseNotFoundException;
|
||||
import lol.hyper.toolstats.commands.CommandToolStats;
|
||||
import lol.hyper.toolstats.events.*;
|
||||
import lol.hyper.toolstats.tools.*;
|
||||
@@ -76,6 +77,10 @@ public final class ToolStats extends JavaPlugin {
|
||||
* Stores how much damage an armor piece has taken.
|
||||
*/
|
||||
public final NamespacedKey armorDamage = new NamespacedKey(this, "damage-taken");
|
||||
/**
|
||||
* Stores how much damage a weapon has done.
|
||||
*/
|
||||
public final NamespacedKey damageDone = new NamespacedKey(this, "damage-done");
|
||||
/**
|
||||
* Key for tracking new elytras that spawn.
|
||||
*/
|
||||
@@ -88,6 +93,10 @@ public final class ToolStats extends JavaPlugin {
|
||||
* 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.
|
||||
*/
|
||||
@@ -112,7 +121,7 @@ public final class ToolStats extends JavaPlugin {
|
||||
*/
|
||||
public final NamespacedKey originType = new NamespacedKey(this, "origin");
|
||||
|
||||
public final int CONFIG_VERSION = 10;
|
||||
public final int CONFIG_VERSION = 12;
|
||||
public final Logger logger = this.getLogger();
|
||||
public final File configFile = new File(this.getDataFolder(), "config.yml");
|
||||
public boolean tokens = false;
|
||||
@@ -251,12 +260,14 @@ public final class ToolStats extends JavaPlugin {
|
||||
e.printStackTrace();
|
||||
return;
|
||||
}
|
||||
GitHubRelease current = api.getReleaseByTag(this.getPluginMeta().getVersion());
|
||||
GitHubRelease latest = api.getLatestVersion();
|
||||
if (current == null) {
|
||||
GitHubRelease current;
|
||||
try {
|
||||
current = api.getReleaseByTag(this.getPluginMeta().getVersion());
|
||||
} catch (ReleaseNotFoundException e) {
|
||||
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;
|
||||
}
|
||||
GitHubRelease latest = api.getLatestVersion();
|
||||
int buildsBehind = api.getBuildsBehind(current);
|
||||
if (buildsBehind == 0) {
|
||||
logger.info("You are running the latest version.");
|
||||
|
||||
@@ -30,6 +30,7 @@ import org.bukkit.command.ConsoleCommandSender;
|
||||
import org.bukkit.command.TabExecutor;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
import org.bukkit.inventory.PlayerInventory;
|
||||
import org.bukkit.inventory.ShapedRecipe;
|
||||
import org.bukkit.inventory.meta.ItemMeta;
|
||||
import org.bukkit.persistence.PersistentDataContainer;
|
||||
@@ -38,6 +39,7 @@ import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
import java.util.*;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
public class CommandToolStats implements TabExecutor {
|
||||
|
||||
@@ -48,7 +50,7 @@ public class CommandToolStats implements TabExecutor {
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean onCommand(@NotNull CommandSender sender, @NotNull Command command, @NotNull String label, @NotNull String[] args) {
|
||||
public boolean onCommand(@NotNull CommandSender sender, @NotNull Command command, @NotNull String label, @NotNull String @NotNull [] args) {
|
||||
if (!sender.hasPermission("toolstats.command")) {
|
||||
sender.sendMessage(Component.text("You do not have permission for this command.", NamedTextColor.RED));
|
||||
return true;
|
||||
@@ -89,6 +91,41 @@ public class CommandToolStats implements TabExecutor {
|
||||
}
|
||||
return true;
|
||||
}
|
||||
// /toolstats edit stat value
|
||||
case "edit": {
|
||||
if (!sender.hasPermission("toolstats.edit")) {
|
||||
sender.sendMessage(Component.text("You do not have permission for this command.", NamedTextColor.RED));
|
||||
return true;
|
||||
}
|
||||
if (sender instanceof ConsoleCommandSender) {
|
||||
sender.sendMessage(Component.text("You must be a player for this command.", NamedTextColor.RED));
|
||||
return true;
|
||||
}
|
||||
if (args.length < 3) {
|
||||
sender.sendMessage(Component.text("Invalid syntax. Usage: /toolstats edit <stat> <value>", NamedTextColor.RED));
|
||||
return true;
|
||||
}
|
||||
handleEdit(args[1], args[2], (Player) sender);
|
||||
return true;
|
||||
}
|
||||
// /toolstats remove stat
|
||||
case "remove": {
|
||||
if (!sender.hasPermission("toolstats.remove")) {
|
||||
sender.sendMessage(Component.text("You do not have permission for this command.", NamedTextColor.RED));
|
||||
return true;
|
||||
}
|
||||
if (sender instanceof ConsoleCommandSender) {
|
||||
sender.sendMessage(Component.text("You must be a player for this command.", NamedTextColor.RED));
|
||||
return true;
|
||||
}
|
||||
if (args.length < 2) {
|
||||
sender.sendMessage(Component.text("Invalid syntax. Usage: /toolstats remove <stat>", NamedTextColor.RED));
|
||||
return true;
|
||||
}
|
||||
handleRemove(args[1], (Player) sender);
|
||||
return true;
|
||||
|
||||
}
|
||||
case "reset": {
|
||||
if (!sender.hasPermission("toolstats.reset")) {
|
||||
sender.sendMessage(Component.text("You do not have permission for this command.", NamedTextColor.RED));
|
||||
@@ -210,7 +247,8 @@ public class CommandToolStats implements TabExecutor {
|
||||
|
||||
if (flightTime != null) {
|
||||
if (toolStats.config.getBoolean("enabled.flight-time")) {
|
||||
Component line = toolStats.configTools.formatLore("flight-time", "{time}", toolStats.numberFormat.formatDouble((double) flightTime / 1000));
|
||||
Map<String, String> flightTimeFormatted = toolStats.numberFormat.formatTime(flightTime);
|
||||
Component line = toolStats.configTools.formatLoreMultiplePlaceholders("flight-time", flightTimeFormatted);
|
||||
lore.add(line);
|
||||
}
|
||||
}
|
||||
@@ -228,84 +266,109 @@ public class CommandToolStats implements TabExecutor {
|
||||
player.getInventory().setItem(slot, finalItem);
|
||||
}
|
||||
|
||||
if (toolStats.configTools.checkConfig(original.getType(), "created-by")) {
|
||||
if (container.has(toolStats.itemOwner, new UUIDDataType())) {
|
||||
UUID owner = container.get(toolStats.itemOwner, new UUIDDataType());
|
||||
String ownerName = null;
|
||||
// if we can read the current owner
|
||||
if (owner != null) {
|
||||
OfflinePlayer offlinePlayer = Bukkit.getOfflinePlayer(owner);
|
||||
ownerName = offlinePlayer.getName();
|
||||
}
|
||||
|
||||
// if the owner's name is null for whatever reason, set the new owner
|
||||
// to the current player running the command
|
||||
if (ownerName == null) {
|
||||
player.sendMessage(Component.text("The owner of this item is null. Setting to " + player.getName() + ".", NamedTextColor.RED));
|
||||
ownerName = player.getName();
|
||||
container.set(toolStats.itemOwner, new UUIDDataType(), player.getUniqueId());
|
||||
}
|
||||
|
||||
// show how the item was created based on the previous lore
|
||||
switch (origin) {
|
||||
case 0: {
|
||||
lore.add(toolStats.configTools.formatLore("created.created-by", "{player}", ownerName));
|
||||
break;
|
||||
}
|
||||
case 2: {
|
||||
lore.add(toolStats.configTools.formatLore("looted.looted-by", "{player}", ownerName));
|
||||
break;
|
||||
}
|
||||
case 3: {
|
||||
lore.add(toolStats.configTools.formatLore("traded.traded-by", "{player}", ownerName));
|
||||
break;
|
||||
}
|
||||
case 4: {
|
||||
lore.add(toolStats.configTools.formatLore("looted.found-by", "{player}", ownerName));
|
||||
break;
|
||||
}
|
||||
case 5: {
|
||||
lore.add(toolStats.configTools.formatLore("fished.caught-by", "{player}", ownerName));
|
||||
break;
|
||||
}
|
||||
case 6: {
|
||||
lore.add(toolStats.configTools.formatLore("spawned-in.spawned-by", "{player}", ownerName));
|
||||
break;
|
||||
}
|
||||
if (container.has(toolStats.droppedBy, PersistentDataType.STRING)) {
|
||||
if (toolStats.config.getBoolean("enabled.dropped-by")) {
|
||||
if (container.has(toolStats.droppedBy)) {
|
||||
String droppedBy = container.get(toolStats.droppedBy, PersistentDataType.STRING);
|
||||
lore.add(toolStats.configTools.formatLore("dropped-by", "{name}", droppedBy));
|
||||
} else {
|
||||
player.sendMessage(Component.text("Unable to set 'dropped-by', as this item has no record of it."));
|
||||
}
|
||||
}
|
||||
}
|
||||
if (toolStats.configTools.checkConfig(original.getType(), "created-date")) {
|
||||
if (container.has(toolStats.timeCreated, PersistentDataType.LONG)) {
|
||||
Long time = container.get(toolStats.timeCreated, PersistentDataType.LONG);
|
||||
if (time != null) {
|
||||
String date = toolStats.numberFormat.formatDate(new Date(time));
|
||||
// show how when the item was created based on the previous lore
|
||||
switch (origin) {
|
||||
case 0: {
|
||||
lore.add(toolStats.configTools.formatLore("created.created-on", "{date}", date));
|
||||
break;
|
||||
|
||||
if (container.has(toolStats.itemOwner, new UUIDDataType())) {
|
||||
UUID owner = container.get(toolStats.itemOwner, new UUIDDataType());
|
||||
String ownerName = null;
|
||||
// if we can read the current owner
|
||||
if (owner != null) {
|
||||
OfflinePlayer offlinePlayer = Bukkit.getOfflinePlayer(owner);
|
||||
ownerName = offlinePlayer.getName();
|
||||
}
|
||||
|
||||
// if the owner's name is null for whatever reason, set the new owner
|
||||
// to the current player running the command
|
||||
if (ownerName == null) {
|
||||
player.sendMessage(Component.text("The owner of this item is null. Setting to " + player.getName() + ".", NamedTextColor.RED));
|
||||
ownerName = player.getName();
|
||||
container.set(toolStats.itemOwner, new UUIDDataType(), player.getUniqueId());
|
||||
}
|
||||
|
||||
// show how the item was created based on the previous lore
|
||||
switch (origin) {
|
||||
case 0: {
|
||||
if (toolStats.configTools.checkConfig(original.getType(), "crafted-by")) {
|
||||
lore.add(toolStats.configTools.formatLore("crafted.crafted-by", "{player}", ownerName));
|
||||
}
|
||||
break;
|
||||
}
|
||||
case 2: {
|
||||
if (toolStats.configTools.checkConfig(original.getType(), "looted-by")) {
|
||||
lore.add(toolStats.configTools.formatLore("looted.looted-by", "{player}", ownerName));
|
||||
}
|
||||
break;
|
||||
}
|
||||
case 3: {
|
||||
if (toolStats.configTools.checkConfig(original.getType(), "traded-by")) {
|
||||
lore.add(toolStats.configTools.formatLore("traded.traded-by", "{player}", ownerName));
|
||||
}
|
||||
break;
|
||||
}
|
||||
case 5: {
|
||||
if (toolStats.configTools.checkConfig(original.getType(), "fished-by")) {
|
||||
lore.add(toolStats.configTools.formatLore("fished.caught-by", "{player}", ownerName));
|
||||
}
|
||||
break;
|
||||
}
|
||||
case 6: {
|
||||
if (toolStats.configTools.checkConfig(original.getType(), "spawned-in-by")) {
|
||||
lore.add(toolStats.configTools.formatLore("spawned-in.spawned-by", "{player}", ownerName));
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
if (container.has(toolStats.timeCreated, PersistentDataType.LONG)) {
|
||||
Long time = container.get(toolStats.timeCreated, PersistentDataType.LONG);
|
||||
if (time != null) {
|
||||
String date = toolStats.numberFormat.formatDate(new Date(time));
|
||||
// show how when the item was created based on the previous lore
|
||||
switch (origin) {
|
||||
case 0: {
|
||||
if (toolStats.configTools.checkConfig(original.getType(), "crafted-on")) {
|
||||
lore.add(toolStats.configTools.formatLore("crafted.crafted-on", "{date}", date));
|
||||
}
|
||||
case 2: {
|
||||
break;
|
||||
}
|
||||
case 1: {
|
||||
if (toolStats.config.getBoolean("enabled.dropped-on")) {
|
||||
lore.add(toolStats.configTools.formatLore("dropped-on", "{date}", date));
|
||||
}
|
||||
break;
|
||||
}
|
||||
case 2: {
|
||||
if (toolStats.configTools.checkConfig(original.getType(), "looted-on")) {
|
||||
lore.add(toolStats.configTools.formatLore("looted.looted-on", "{date}", date));
|
||||
break;
|
||||
}
|
||||
case 3: {
|
||||
break;
|
||||
}
|
||||
case 3: {
|
||||
if (toolStats.configTools.checkConfig(original.getType(), "traded-on")) {
|
||||
lore.add(toolStats.configTools.formatLore("traded.traded-on", "{date}", date));
|
||||
break;
|
||||
}
|
||||
case 4: {
|
||||
lore.add(toolStats.configTools.formatLore("looted.found-on", "{date}", date));
|
||||
break;
|
||||
}
|
||||
case 5: {
|
||||
break;
|
||||
}
|
||||
case 5: {
|
||||
if (toolStats.configTools.checkConfig(original.getType(), "fished-on")) {
|
||||
lore.add(toolStats.configTools.formatLore("fished.caught-on", "{date}", date));
|
||||
break;
|
||||
}
|
||||
case 6: {
|
||||
break;
|
||||
}
|
||||
case 6: {
|
||||
if (toolStats.configTools.checkConfig(original.getType(), "spawned-in-on")) {
|
||||
lore.add(toolStats.configTools.formatLore("spawned-in.spawned-on", "{date}", date));
|
||||
break;
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -366,6 +429,14 @@ public class CommandToolStats implements TabExecutor {
|
||||
}
|
||||
}
|
||||
}
|
||||
if (toolStats.configTools.checkConfig(original.getType(), "damage-done")) {
|
||||
if (container.has(toolStats.damageDone, PersistentDataType.DOUBLE)) {
|
||||
Double damage = container.get(toolStats.damageDone, PersistentDataType.DOUBLE);
|
||||
if (damage != null) {
|
||||
lore.add(toolStats.configTools.formatLore("damage-done", "{damage}", toolStats.numberFormat.formatDouble(damage)));
|
||||
}
|
||||
}
|
||||
}
|
||||
if (toolStats.config.getBoolean("enabled.arrows-shot")) {
|
||||
if (container.has(toolStats.arrowsShot, PersistentDataType.INTEGER)) {
|
||||
Integer arrows = container.get(toolStats.arrowsShot, PersistentDataType.INTEGER);
|
||||
@@ -406,6 +477,12 @@ public class CommandToolStats implements TabExecutor {
|
||||
target.getInventory().addItem(itemStack);
|
||||
break;
|
||||
}
|
||||
case "damage-done": {
|
||||
ItemStack itemStack = toolStats.tokenItems.damageDone();
|
||||
itemStack.setAmount(amount);
|
||||
target.getInventory().addItem(itemStack);
|
||||
break;
|
||||
}
|
||||
case "mob-kills": {
|
||||
ItemStack itemStack = toolStats.tokenItems.mobKills();
|
||||
itemStack.setAmount(amount);
|
||||
@@ -448,12 +525,610 @@ public class CommandToolStats implements TabExecutor {
|
||||
target.getInventory().addItem(itemStack);
|
||||
break;
|
||||
}
|
||||
case "remove": {
|
||||
ItemStack itemStack = toolStats.tokenItems.removeToken();
|
||||
itemStack.setAmount(amount);
|
||||
target.getInventory().addItem(itemStack);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Handle edit subcommand.
|
||||
*
|
||||
* @param stat The stat to edit.
|
||||
* @param userValue The value the user entered.
|
||||
* @param player The player using the command.
|
||||
*/
|
||||
private void handleEdit(String stat, Object userValue, Player player) {
|
||||
ItemStack editedItem = player.getInventory().getItemInMainHand().clone();
|
||||
if (!toolStats.itemChecker.isValidItem(editedItem.getType())) {
|
||||
player.sendMessage(Component.text("This is not a valid item.", NamedTextColor.RED));
|
||||
return;
|
||||
}
|
||||
ItemMeta editedItemMeta = editedItem.getItemMeta();
|
||||
PersistentDataContainer container = editedItemMeta.getPersistentDataContainer();
|
||||
switch (stat) {
|
||||
case "crops-harvested": {
|
||||
if (!toolStats.config.getBoolean("enabled.crops-harvested")) {
|
||||
player.sendMessage(Component.text("This stat is disabled.", NamedTextColor.RED));
|
||||
return;
|
||||
}
|
||||
if (container.has(toolStats.cropsHarvested)) {
|
||||
int value;
|
||||
try {
|
||||
value = Integer.parseInt((String) userValue);
|
||||
} catch (NumberFormatException exception) {
|
||||
player.sendMessage(Component.text("That is not a valid number.", NamedTextColor.RED));
|
||||
return;
|
||||
}
|
||||
if (value < 0) {
|
||||
player.sendMessage(Component.text("Number must be positive.", NamedTextColor.RED));
|
||||
return;
|
||||
}
|
||||
Integer statValue = container.get(toolStats.cropsHarvested, PersistentDataType.INTEGER);
|
||||
if (statValue == null) {
|
||||
player.sendMessage(Component.text("Unable to get stat from item.", NamedTextColor.RED));
|
||||
return;
|
||||
}
|
||||
int difference = value - statValue;
|
||||
editedItemMeta = toolStats.itemLore.updateCropsMined(editedItem, difference);
|
||||
} else {
|
||||
player.sendMessage(Component.text("This item does not have that stat.", NamedTextColor.RED));
|
||||
}
|
||||
break;
|
||||
}
|
||||
case "blocks-mined": {
|
||||
if (!toolStats.configTools.checkConfig(editedItem.getType(), "blocks-mined")) {
|
||||
player.sendMessage(Component.text("This stat is disabled.", NamedTextColor.RED));
|
||||
return;
|
||||
}
|
||||
if (container.has(toolStats.blocksMined)) {
|
||||
int value;
|
||||
try {
|
||||
value = Integer.parseInt((String) userValue);
|
||||
} catch (NumberFormatException exception) {
|
||||
player.sendMessage(Component.text("That is not a valid number.", NamedTextColor.RED));
|
||||
return;
|
||||
}
|
||||
if (value < 0) {
|
||||
player.sendMessage(Component.text("Number must be positive.", NamedTextColor.RED));
|
||||
return;
|
||||
}
|
||||
Integer statValue = container.get(toolStats.blocksMined, PersistentDataType.INTEGER);
|
||||
if (statValue == null) {
|
||||
player.sendMessage(Component.text("Unable to get stat from item.", NamedTextColor.RED));
|
||||
return;
|
||||
}
|
||||
int difference = value - statValue;
|
||||
editedItemMeta = toolStats.itemLore.updateBlocksMined(editedItem, difference);
|
||||
} else {
|
||||
player.sendMessage(Component.text("This item does not have that stat.", NamedTextColor.RED));
|
||||
}
|
||||
break;
|
||||
}
|
||||
case "damage-taken": {
|
||||
if (!toolStats.config.getBoolean("enabled.armor-damage")) {
|
||||
player.sendMessage(Component.text("This stat is disabled.", NamedTextColor.RED));
|
||||
return;
|
||||
}
|
||||
if (container.has(toolStats.armorDamage)) {
|
||||
double value;
|
||||
try {
|
||||
value = Double.parseDouble((String) userValue);
|
||||
} catch (NumberFormatException exception) {
|
||||
player.sendMessage(Component.text("That is not a valid number.", NamedTextColor.RED));
|
||||
return;
|
||||
}
|
||||
if (value < 0) {
|
||||
player.sendMessage(Component.text("Number must be positive.", NamedTextColor.RED));
|
||||
return;
|
||||
}
|
||||
Double statValue = container.get(toolStats.armorDamage, PersistentDataType.DOUBLE);
|
||||
if (statValue == null) {
|
||||
player.sendMessage(Component.text("Unable to get stat from item.", NamedTextColor.RED));
|
||||
return;
|
||||
}
|
||||
double difference = value - statValue;
|
||||
editedItemMeta = toolStats.itemLore.updateArmorDamage(editedItem, difference, false);
|
||||
} else {
|
||||
player.sendMessage(Component.text("This item does not have that stat.", NamedTextColor.RED));
|
||||
}
|
||||
break;
|
||||
}
|
||||
case "damage-done": {
|
||||
if (!toolStats.configTools.checkConfig(editedItem.getType(), "damage-done")) {
|
||||
player.sendMessage(Component.text("This stat is disabled.", NamedTextColor.RED));
|
||||
return;
|
||||
}
|
||||
if (container.has(toolStats.damageDone)) {
|
||||
double value;
|
||||
try {
|
||||
value = Double.parseDouble((String) userValue);
|
||||
} catch (NumberFormatException exception) {
|
||||
player.sendMessage(Component.text("That is not a valid number.", NamedTextColor.RED));
|
||||
return;
|
||||
}
|
||||
if (value < 0) {
|
||||
player.sendMessage(Component.text("Number must be positive.", NamedTextColor.RED));
|
||||
return;
|
||||
}
|
||||
Double statValue = container.get(toolStats.damageDone, PersistentDataType.DOUBLE);
|
||||
if (statValue == null) {
|
||||
player.sendMessage(Component.text("Unable to get stat from item.", NamedTextColor.RED));
|
||||
return;
|
||||
}
|
||||
double difference = value - statValue;
|
||||
editedItemMeta = toolStats.itemLore.updateWeaponDamage(editedItem, difference, false);
|
||||
} else {
|
||||
player.sendMessage(Component.text("This item does not have that stat.", NamedTextColor.RED));
|
||||
}
|
||||
break;
|
||||
}
|
||||
case "mob-kills": {
|
||||
if (!toolStats.configTools.checkConfig(editedItem.getType(), "mob-kills")) {
|
||||
player.sendMessage(Component.text("This stat is disabled.", NamedTextColor.RED));
|
||||
return;
|
||||
}
|
||||
if (container.has(toolStats.mobKills)) {
|
||||
int value;
|
||||
try {
|
||||
value = Integer.parseInt((String) userValue);
|
||||
} catch (NumberFormatException exception) {
|
||||
player.sendMessage(Component.text("That is not a valid number.", NamedTextColor.RED));
|
||||
return;
|
||||
}
|
||||
if (value < 0) {
|
||||
player.sendMessage(Component.text("Number must be positive.", NamedTextColor.RED));
|
||||
return;
|
||||
}
|
||||
Integer statValue = container.get(toolStats.mobKills, PersistentDataType.INTEGER);
|
||||
if (statValue == null) {
|
||||
player.sendMessage(Component.text("Unable to get stat from item.", NamedTextColor.RED));
|
||||
return;
|
||||
}
|
||||
int difference = value - statValue;
|
||||
editedItemMeta = toolStats.itemLore.updateMobKills(editedItem, difference);
|
||||
} else {
|
||||
player.sendMessage(Component.text("This item does not have that stat.", NamedTextColor.RED));
|
||||
}
|
||||
break;
|
||||
}
|
||||
case "player-kills": {
|
||||
if (!toolStats.configTools.checkConfig(editedItem.getType(), "player-kills")) {
|
||||
player.sendMessage(Component.text("This stat is disabled.", NamedTextColor.RED));
|
||||
return;
|
||||
}
|
||||
if (container.has(toolStats.playerKills)) {
|
||||
int value;
|
||||
try {
|
||||
value = Integer.parseInt((String) userValue);
|
||||
} catch (NumberFormatException exception) {
|
||||
player.sendMessage(Component.text("That is not a valid number.", NamedTextColor.RED));
|
||||
return;
|
||||
}
|
||||
if (value < 0) {
|
||||
player.sendMessage(Component.text("Number must be positive.", NamedTextColor.RED));
|
||||
return;
|
||||
}
|
||||
Integer statValue = container.get(toolStats.playerKills, PersistentDataType.INTEGER);
|
||||
if (statValue == null) {
|
||||
player.sendMessage(Component.text("Unable to get stat from item.", NamedTextColor.RED));
|
||||
return;
|
||||
}
|
||||
int difference = value - statValue;
|
||||
editedItemMeta = toolStats.itemLore.updatePlayerKills(editedItem, difference);
|
||||
} else {
|
||||
player.sendMessage(Component.text("This item does not have that stat.", NamedTextColor.RED));
|
||||
}
|
||||
break;
|
||||
}
|
||||
case "arrows-shot": {
|
||||
if (!toolStats.config.getBoolean("enabled.arrows-shot")) {
|
||||
player.sendMessage(Component.text("This stat is disabled.", NamedTextColor.RED));
|
||||
return;
|
||||
}
|
||||
if (container.has(toolStats.arrowsShot)) {
|
||||
int value;
|
||||
try {
|
||||
value = Integer.parseInt((String) userValue);
|
||||
} catch (NumberFormatException exception) {
|
||||
player.sendMessage(Component.text("That is not a valid number.", NamedTextColor.RED));
|
||||
return;
|
||||
}
|
||||
if (value < 0) {
|
||||
player.sendMessage(Component.text("Number must be positive.", NamedTextColor.RED));
|
||||
return;
|
||||
}
|
||||
Integer statValue = container.get(toolStats.arrowsShot, PersistentDataType.INTEGER);
|
||||
if (statValue == null) {
|
||||
player.sendMessage(Component.text("Unable to get stat from item.", NamedTextColor.RED));
|
||||
return;
|
||||
}
|
||||
int difference = value - statValue;
|
||||
editedItemMeta = toolStats.itemLore.updateArrowsShot(editedItem, difference);
|
||||
} else {
|
||||
player.sendMessage(Component.text("This item does not have that stat.", NamedTextColor.RED));
|
||||
}
|
||||
break;
|
||||
}
|
||||
case "sheep-sheared": {
|
||||
if (!toolStats.config.getBoolean("enabled.sheep-sheared")) {
|
||||
player.sendMessage(Component.text("This stat is disabled.", NamedTextColor.RED));
|
||||
return;
|
||||
}
|
||||
if (container.has(toolStats.sheepSheared)) {
|
||||
int value;
|
||||
try {
|
||||
value = Integer.parseInt((String) userValue);
|
||||
} catch (NumberFormatException exception) {
|
||||
player.sendMessage(Component.text("That is not a valid number.", NamedTextColor.RED));
|
||||
return;
|
||||
}
|
||||
if (value < 0) {
|
||||
player.sendMessage(Component.text("Number must be positive.", NamedTextColor.RED));
|
||||
return;
|
||||
}
|
||||
Integer statValue = container.get(toolStats.sheepSheared, PersistentDataType.INTEGER);
|
||||
if (statValue == null) {
|
||||
player.sendMessage(Component.text("Unable to get stat from item.", NamedTextColor.RED));
|
||||
return;
|
||||
}
|
||||
int difference = value - statValue;
|
||||
editedItemMeta = toolStats.itemLore.updateSheepSheared(editedItem, difference);
|
||||
} else {
|
||||
player.sendMessage(Component.text("This item does not have that stat.", NamedTextColor.RED));
|
||||
}
|
||||
break;
|
||||
}
|
||||
case "flight-time": {
|
||||
if (!toolStats.config.getBoolean("enabled.flight-time")) {
|
||||
player.sendMessage(Component.text("This stat is disabled.", NamedTextColor.RED));
|
||||
return;
|
||||
}
|
||||
if (container.has(toolStats.flightTime)) {
|
||||
int value;
|
||||
try {
|
||||
value = Integer.parseInt((String) userValue);
|
||||
} catch (NumberFormatException exception) {
|
||||
player.sendMessage(Component.text("That is not a valid number.", NamedTextColor.RED));
|
||||
return;
|
||||
}
|
||||
if (value < 0) {
|
||||
player.sendMessage(Component.text("Number must be positive.", NamedTextColor.RED));
|
||||
return;
|
||||
}
|
||||
Long statValue = container.get(toolStats.flightTime, PersistentDataType.LONG);
|
||||
if (statValue == null) {
|
||||
player.sendMessage(Component.text("Unable to get stat from item.", NamedTextColor.RED));
|
||||
return;
|
||||
}
|
||||
long difference = value - statValue;
|
||||
editedItemMeta = toolStats.itemLore.updateFlightTime(editedItem, difference);
|
||||
} else {
|
||||
player.sendMessage(Component.text("This item does not have that stat.", NamedTextColor.RED));
|
||||
}
|
||||
break;
|
||||
}
|
||||
case "fight-caught": {
|
||||
if (!toolStats.config.getBoolean("enabled.fight-caught")) {
|
||||
player.sendMessage(Component.text("This stat is disabled.", NamedTextColor.RED));
|
||||
return;
|
||||
}
|
||||
if (container.has(toolStats.fishCaught)) {
|
||||
int value;
|
||||
try {
|
||||
value = Integer.parseInt((String) userValue);
|
||||
} catch (NumberFormatException exception) {
|
||||
player.sendMessage(Component.text("That is not a valid number.", NamedTextColor.RED));
|
||||
return;
|
||||
}
|
||||
if (value < 0) {
|
||||
player.sendMessage(Component.text("Number must be positive.", NamedTextColor.RED));
|
||||
return;
|
||||
}
|
||||
Integer statValue = container.get(toolStats.fishCaught, PersistentDataType.INTEGER);
|
||||
if (statValue == null) {
|
||||
player.sendMessage(Component.text("Unable to get stat from item.", NamedTextColor.RED));
|
||||
return;
|
||||
}
|
||||
int difference = value - statValue;
|
||||
editedItemMeta = toolStats.itemLore.updateFishCaught(editedItem, difference);
|
||||
} else {
|
||||
player.sendMessage(Component.text("This item does not have that stat.", NamedTextColor.RED));
|
||||
}
|
||||
break;
|
||||
}
|
||||
default: {
|
||||
player.sendMessage(Component.text("That is not a valid stat to update.", NamedTextColor.RED));
|
||||
return;
|
||||
}
|
||||
}
|
||||
editedItem.setItemMeta(editedItemMeta);
|
||||
player.getInventory().setItemInMainHand(editedItem);
|
||||
}
|
||||
|
||||
/**
|
||||
* Handle remove subcommand.
|
||||
*
|
||||
* @param stat The stat to remove.
|
||||
* @param player The player using the command.
|
||||
*/
|
||||
private void handleRemove(String stat, Player player) {
|
||||
ItemStack editedItem = player.getInventory().getItemInMainHand().clone();
|
||||
if (!toolStats.itemChecker.isValidItem(editedItem.getType())) {
|
||||
player.sendMessage(Component.text("This is not a valid item.", NamedTextColor.RED));
|
||||
return;
|
||||
}
|
||||
ItemMeta editedItemMeta = editedItem.getItemMeta();
|
||||
PersistentDataContainer container = editedItemMeta.getPersistentDataContainer();
|
||||
switch (stat) {
|
||||
case "crops-harvested": {
|
||||
if (container.has(toolStats.cropsHarvested)) {
|
||||
Integer statValue = container.get(toolStats.cropsHarvested, PersistentDataType.INTEGER);
|
||||
if (statValue == null) {
|
||||
player.sendMessage(Component.text("Unable to get stat from item.", NamedTextColor.RED));
|
||||
return;
|
||||
}
|
||||
String tokens = container.get(toolStats.tokenApplied, PersistentDataType.STRING);
|
||||
if (tokens == null) {
|
||||
player.sendMessage(Component.text("Unable to get tokens from item.", NamedTextColor.RED));
|
||||
return;
|
||||
}
|
||||
container.remove(toolStats.cropsHarvested);
|
||||
List<String> newTokens = toolStats.itemChecker.removeToken(tokens, "crops-mined");
|
||||
if (newTokens.isEmpty()) {
|
||||
container.remove(toolStats.tokenApplied);
|
||||
} else {
|
||||
container.set(toolStats.tokenApplied, PersistentDataType.STRING, String.join(",", newTokens));
|
||||
}
|
||||
|
||||
Component oldLine = toolStats.configTools.formatLore("crops-harvested", "{crops}", toolStats.numberFormat.formatInt(statValue));
|
||||
List<Component> newLore = toolStats.itemLore.removeLore(editedItemMeta.lore(), oldLine);
|
||||
editedItemMeta.lore(newLore);
|
||||
} else {
|
||||
player.sendMessage(Component.text("This item does not have that stat.", NamedTextColor.RED));
|
||||
}
|
||||
break;
|
||||
}
|
||||
case "blocks-mined": {
|
||||
if (container.has(toolStats.blocksMined)) {
|
||||
Integer statValue = container.get(toolStats.blocksMined, PersistentDataType.INTEGER);
|
||||
if (statValue == null) {
|
||||
player.sendMessage(Component.text("Unable to get stat from item.", NamedTextColor.RED));
|
||||
return;
|
||||
}
|
||||
String tokens = container.get(toolStats.tokenApplied, PersistentDataType.STRING);
|
||||
if (tokens == null) {
|
||||
player.sendMessage(Component.text("Unable to get tokens from item.", NamedTextColor.RED));
|
||||
return;
|
||||
}
|
||||
container.remove(toolStats.blocksMined);
|
||||
List<String> newTokens = toolStats.itemChecker.removeToken(tokens, "blocks-mined");
|
||||
if (newTokens.isEmpty()) {
|
||||
container.remove(toolStats.tokenApplied);
|
||||
} else {
|
||||
container.set(toolStats.tokenApplied, PersistentDataType.STRING, String.join(",", newTokens));
|
||||
}
|
||||
|
||||
Component oldLine = toolStats.configTools.formatLore("blocks-mined", "{blocks}", toolStats.numberFormat.formatInt(statValue));
|
||||
List<Component> newLore = toolStats.itemLore.removeLore(editedItemMeta.lore(), oldLine);
|
||||
editedItemMeta.lore(newLore);
|
||||
} else {
|
||||
player.sendMessage(Component.text("This item does not have that stat.", NamedTextColor.RED));
|
||||
}
|
||||
break;
|
||||
}
|
||||
case "damage-taken": {
|
||||
if (container.has(toolStats.armorDamage)) {
|
||||
Double statValue = container.get(toolStats.armorDamage, PersistentDataType.DOUBLE);
|
||||
if (statValue == null) {
|
||||
player.sendMessage(Component.text("Unable to get stat from item.", NamedTextColor.RED));
|
||||
return;
|
||||
}
|
||||
String tokens = container.get(toolStats.tokenApplied, PersistentDataType.STRING);
|
||||
if (tokens == null) {
|
||||
player.sendMessage(Component.text("Unable to get tokens from item.", NamedTextColor.RED));
|
||||
return;
|
||||
}
|
||||
container.remove(toolStats.armorDamage);
|
||||
List<String> newTokens = toolStats.itemChecker.removeToken(tokens, "damage-taken");
|
||||
if (newTokens.isEmpty()) {
|
||||
container.remove(toolStats.tokenApplied);
|
||||
} else {
|
||||
container.set(toolStats.tokenApplied, PersistentDataType.STRING, String.join(",", newTokens));
|
||||
}
|
||||
|
||||
Component oldLine = toolStats.configTools.formatLore("damage-taken", "{damage}", toolStats.numberFormat.formatDouble(statValue));
|
||||
List<Component> newLore = toolStats.itemLore.removeLore(editedItemMeta.lore(), oldLine);
|
||||
editedItemMeta.lore(newLore);
|
||||
} else {
|
||||
player.sendMessage(Component.text("This item does not have that stat.", NamedTextColor.RED));
|
||||
}
|
||||
break;
|
||||
}
|
||||
case "damage-done": {
|
||||
if (container.has(toolStats.damageDone)) {
|
||||
Double statValue = container.get(toolStats.damageDone, PersistentDataType.DOUBLE);
|
||||
if (statValue == null) {
|
||||
player.sendMessage(Component.text("Unable to get stat from item.", NamedTextColor.RED));
|
||||
return;
|
||||
}
|
||||
String tokens = container.get(toolStats.tokenApplied, PersistentDataType.STRING);
|
||||
if (tokens == null) {
|
||||
player.sendMessage(Component.text("Unable to get tokens from item.", NamedTextColor.RED));
|
||||
return;
|
||||
}
|
||||
container.remove(toolStats.damageDone);
|
||||
List<String> newTokens = toolStats.itemChecker.removeToken(tokens, "damage-done");
|
||||
if (newTokens.isEmpty()) {
|
||||
container.remove(toolStats.tokenApplied);
|
||||
} else {
|
||||
container.set(toolStats.tokenApplied, PersistentDataType.STRING, String.join(",", newTokens));
|
||||
}
|
||||
|
||||
Component oldLine = toolStats.configTools.formatLore("damage-done", "{damage}", toolStats.numberFormat.formatDouble(statValue));
|
||||
List<Component> newLore = toolStats.itemLore.removeLore(editedItemMeta.lore(), oldLine);
|
||||
editedItemMeta.lore(newLore);
|
||||
} else {
|
||||
player.sendMessage(Component.text("This item does not have that stat.", NamedTextColor.RED));
|
||||
}
|
||||
break;
|
||||
}
|
||||
case "mob-kills": {
|
||||
if (container.has(toolStats.mobKills)) {
|
||||
Integer statValue = container.get(toolStats.mobKills, PersistentDataType.INTEGER);
|
||||
if (statValue == null) {
|
||||
player.sendMessage(Component.text("Unable to get stat from item.", NamedTextColor.RED));
|
||||
return;
|
||||
}
|
||||
String tokens = container.get(toolStats.tokenApplied, PersistentDataType.STRING);
|
||||
if (tokens == null) {
|
||||
player.sendMessage(Component.text("Unable to get tokens from item.", NamedTextColor.RED));
|
||||
return;
|
||||
}
|
||||
container.remove(toolStats.mobKills);
|
||||
List<String> newTokens = toolStats.itemChecker.removeToken(tokens, "mob-kills");
|
||||
if (newTokens.isEmpty()) {
|
||||
container.remove(toolStats.tokenApplied);
|
||||
} else {
|
||||
container.set(toolStats.tokenApplied, PersistentDataType.STRING, String.join(",", newTokens));
|
||||
}
|
||||
|
||||
Component oldLine = toolStats.configTools.formatLore("kills.mob", "{kills}", toolStats.numberFormat.formatInt(statValue));
|
||||
List<Component> newLore = toolStats.itemLore.removeLore(editedItemMeta.lore(), oldLine);
|
||||
editedItemMeta.lore(newLore);
|
||||
} else {
|
||||
player.sendMessage(Component.text("This item does not have that stat.", NamedTextColor.RED));
|
||||
}
|
||||
break;
|
||||
}
|
||||
case "player-kills": {
|
||||
if (container.has(toolStats.playerKills)) {
|
||||
Integer statValue = container.get(toolStats.playerKills, PersistentDataType.INTEGER);
|
||||
if (statValue == null) {
|
||||
player.sendMessage(Component.text("Unable to get stat from item.", NamedTextColor.RED));
|
||||
return;
|
||||
}
|
||||
String tokens = container.get(toolStats.tokenApplied, PersistentDataType.STRING);
|
||||
if (tokens == null) {
|
||||
player.sendMessage(Component.text("Unable to get tokens from item.", NamedTextColor.RED));
|
||||
return;
|
||||
}
|
||||
container.remove(toolStats.playerKills);
|
||||
List<String> newTokens = toolStats.itemChecker.removeToken(tokens, "player-kills");
|
||||
if (newTokens.isEmpty()) {
|
||||
container.remove(toolStats.tokenApplied);
|
||||
} else {
|
||||
container.set(toolStats.tokenApplied, PersistentDataType.STRING, String.join(",", newTokens));
|
||||
}
|
||||
|
||||
Component oldLine = toolStats.configTools.formatLore("kills.player", "{kills}", toolStats.numberFormat.formatInt(statValue));
|
||||
List<Component> newLore = toolStats.itemLore.removeLore(editedItemMeta.lore(), oldLine);
|
||||
editedItemMeta.lore(newLore);
|
||||
} else {
|
||||
player.sendMessage(Component.text("This item does not have that stat.", NamedTextColor.RED));
|
||||
}
|
||||
break;
|
||||
}
|
||||
case "sheep-sheared": {
|
||||
if (container.has(toolStats.sheepSheared)) {
|
||||
Integer statValue = container.get(toolStats.sheepSheared, PersistentDataType.INTEGER);
|
||||
if (statValue == null) {
|
||||
player.sendMessage(Component.text("Unable to get stat from item.", NamedTextColor.RED));
|
||||
return;
|
||||
}
|
||||
String tokens = container.get(toolStats.tokenApplied, PersistentDataType.STRING);
|
||||
if (tokens == null) {
|
||||
player.sendMessage(Component.text("Unable to get tokens from item.", NamedTextColor.RED));
|
||||
return;
|
||||
}
|
||||
container.remove(toolStats.sheepSheared);
|
||||
List<String> newTokens = toolStats.itemChecker.removeToken(tokens, "sheep-sheared");
|
||||
if (newTokens.isEmpty()) {
|
||||
container.remove(toolStats.tokenApplied);
|
||||
} else {
|
||||
container.set(toolStats.tokenApplied, PersistentDataType.STRING, String.join(",", newTokens));
|
||||
}
|
||||
|
||||
Component oldLine = toolStats.configTools.formatLore("sheep-sheared", "{sheep}", toolStats.numberFormat.formatInt(statValue));
|
||||
List<Component> newLore = toolStats.itemLore.removeLore(editedItemMeta.lore(), oldLine);
|
||||
editedItemMeta.lore(newLore);
|
||||
} else {
|
||||
player.sendMessage(Component.text("This item does not have that stat.", NamedTextColor.RED));
|
||||
}
|
||||
break;
|
||||
}
|
||||
case "flight-time": {
|
||||
if (container.has(toolStats.flightTime)) {
|
||||
Long statValue = container.get(toolStats.flightTime, PersistentDataType.LONG);
|
||||
if (statValue == null) {
|
||||
player.sendMessage(Component.text("Unable to get stat from item.", NamedTextColor.RED));
|
||||
return;
|
||||
}
|
||||
String tokens = container.get(toolStats.tokenApplied, PersistentDataType.STRING);
|
||||
if (tokens == null) {
|
||||
player.sendMessage(Component.text("Unable to get tokens from item.", NamedTextColor.RED));
|
||||
return;
|
||||
}
|
||||
container.remove(toolStats.flightTime);
|
||||
List<String> newTokens = toolStats.itemChecker.removeToken(tokens, "flight-time");
|
||||
if (newTokens.isEmpty()) {
|
||||
container.remove(toolStats.tokenApplied);
|
||||
} else {
|
||||
container.set(toolStats.tokenApplied, PersistentDataType.STRING, String.join(",", newTokens));
|
||||
}
|
||||
|
||||
Map<String, String> timeFormatted = toolStats.numberFormat.formatTime(statValue);
|
||||
Component oldLine = toolStats.configTools.formatLoreMultiplePlaceholders("flight-time", timeFormatted);
|
||||
List<Component> newLore = toolStats.itemLore.removeLore(editedItemMeta.lore(), oldLine);
|
||||
editedItemMeta.lore(newLore);
|
||||
} else {
|
||||
player.sendMessage(Component.text("This item does not have that stat.", NamedTextColor.RED));
|
||||
}
|
||||
break;
|
||||
}
|
||||
case "fight-caught": {
|
||||
if (container.has(toolStats.fishCaught)) {
|
||||
Integer statValue = container.get(toolStats.fishCaught, PersistentDataType.INTEGER);
|
||||
if (statValue == null) {
|
||||
player.sendMessage(Component.text("Unable to get stat from item.", NamedTextColor.RED));
|
||||
return;
|
||||
}
|
||||
String tokens = container.get(toolStats.tokenApplied, PersistentDataType.STRING);
|
||||
if (tokens == null) {
|
||||
player.sendMessage(Component.text("Unable to get tokens from item.", NamedTextColor.RED));
|
||||
return;
|
||||
}
|
||||
container.remove(toolStats.fishCaught);
|
||||
List<String> newTokens = toolStats.itemChecker.removeToken(tokens, "fight-caught");
|
||||
if (newTokens.isEmpty()) {
|
||||
container.remove(toolStats.tokenApplied);
|
||||
} else {
|
||||
container.set(toolStats.tokenApplied, PersistentDataType.STRING, String.join(",", newTokens));
|
||||
}
|
||||
|
||||
Component oldLine = toolStats.configTools.formatLore("fished.fish-caught", "{fish}", toolStats.numberFormat.formatInt(statValue));
|
||||
List<Component> newLore = toolStats.itemLore.removeLore(editedItemMeta.lore(), oldLine);
|
||||
editedItemMeta.lore(newLore);
|
||||
} else {
|
||||
player.sendMessage(Component.text("This item does not have that stat.", NamedTextColor.RED));
|
||||
}
|
||||
break;
|
||||
}
|
||||
default: {
|
||||
player.sendMessage(Component.text("That is not a valid stat to update.", NamedTextColor.RED));
|
||||
return;
|
||||
}
|
||||
}
|
||||
editedItem.setItemMeta(editedItemMeta);
|
||||
player.getInventory().setItemInMainHand(editedItem);
|
||||
}
|
||||
|
||||
@Nullable
|
||||
@Override
|
||||
public List<String> onTabComplete(@NotNull CommandSender sender, @NotNull Command command, @NotNull String alias, @NotNull String[] args) {
|
||||
public List<String> onTabComplete(@NotNull CommandSender sender, @NotNull Command command, @NotNull String alias, @NotNull String @NotNull [] args) {
|
||||
if (args.length == 1) {
|
||||
List<String> suggestions = new ArrayList<>();
|
||||
if (sender.hasPermission("toolstats.reload")) {
|
||||
@@ -465,12 +1140,32 @@ public class CommandToolStats implements TabExecutor {
|
||||
if (sender.hasPermission("toolstats.givetokens")) {
|
||||
suggestions.add("givetokens");
|
||||
}
|
||||
if (sender.hasPermission("toolstats.edit")) {
|
||||
suggestions.add("edit");
|
||||
}
|
||||
if (sender.hasPermission("toolstats.remove")) {
|
||||
suggestions.add("remove");
|
||||
}
|
||||
return suggestions.isEmpty() ? null : suggestions;
|
||||
}
|
||||
|
||||
if (args.length == 2 && args[0].equalsIgnoreCase("reset") && sender.hasPermission("toolstats.reset.confirm")) {
|
||||
return Collections.singletonList("confirm");
|
||||
}
|
||||
if (args.length == 2 && args[0].equalsIgnoreCase("edit") && sender.hasPermission("toolstats.edit")) {
|
||||
// yes I am lazy
|
||||
return toolStats.tokenCrafting.getTokenTypes().stream()
|
||||
.filter(s -> !s.equals("remove") && !s.equals("reset"))
|
||||
.map(s -> s.equals("crops-mined") ? "crops-harvested" : s)
|
||||
.collect(Collectors.toList());
|
||||
}
|
||||
if (args.length == 2 && args[0].equalsIgnoreCase("remove") && sender.hasPermission("toolstats.remove")) {
|
||||
// yes I am lazy
|
||||
return toolStats.tokenCrafting.getTokenTypes().stream()
|
||||
.filter(s -> !s.equals("remove") && !s.equals("reset"))
|
||||
.map(s -> s.equals("crops-mined") ? "crops-harvested" : s)
|
||||
.collect(Collectors.toList());
|
||||
}
|
||||
if (args.length == 3 && args[0].equalsIgnoreCase("givetokens") && sender.hasPermission("toolstats.givetokens")) {
|
||||
return toolStats.tokenCrafting.getTokenTypes();
|
||||
}
|
||||
|
||||
@@ -18,6 +18,7 @@
|
||||
package lol.hyper.toolstats.events;
|
||||
|
||||
import lol.hyper.toolstats.ToolStats;
|
||||
import net.kyori.adventure.text.Component;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.event.EventHandler;
|
||||
import org.bukkit.event.EventPriority;
|
||||
@@ -89,6 +90,11 @@ public class AnvilEvent implements Listener {
|
||||
return;
|
||||
}
|
||||
|
||||
if (tokenType.equalsIgnoreCase("remove")) {
|
||||
remove(event, clone);
|
||||
return;
|
||||
}
|
||||
|
||||
// if the item is a mining tool
|
||||
if (toolStats.itemChecker.isMineTool(firstSlotMaterial)) {
|
||||
if (firstSlotMaterial.toString().toLowerCase(Locale.ROOT).contains("hoe")) {
|
||||
@@ -133,6 +139,10 @@ public class AnvilEvent implements Listener {
|
||||
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) {
|
||||
@@ -148,6 +158,10 @@ public class AnvilEvent implements Listener {
|
||||
addToken(event, tokenType, "arrows-shot", clone);
|
||||
return;
|
||||
}
|
||||
if (tokenType.equalsIgnoreCase("damage-done")) {
|
||||
addToken(event, tokenType, "damage-done", clone);
|
||||
return;
|
||||
}
|
||||
return;
|
||||
}
|
||||
if (firstSlotMaterial == Material.ELYTRA) {
|
||||
@@ -203,7 +217,16 @@ public class AnvilEvent implements Listener {
|
||||
}
|
||||
case "damage-taken": {
|
||||
if (toolStats.config.getBoolean("enabled.armor-damage")) {
|
||||
newItem.setItemMeta(toolStats.itemLore.updateDamage(newItem, 0.0, false));
|
||||
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;
|
||||
@@ -338,7 +361,15 @@ public class AnvilEvent implements Listener {
|
||||
if (armorDamage == null) {
|
||||
return;
|
||||
}
|
||||
meta = toolStats.itemLore.updateDamage(finalItem, -armorDamage, true);
|
||||
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)) {
|
||||
@@ -360,4 +391,155 @@ public class AnvilEvent implements Listener {
|
||||
event.setResult(finalItem);
|
||||
event.getView().setRepairCost(toolStats.itemChecker.getCost("reset"));
|
||||
}
|
||||
|
||||
/**
|
||||
* Remove all stats from an item.
|
||||
*
|
||||
* @param event The PrepareAnvilEvent event.
|
||||
* @param inputItem The input item to remove stats from.
|
||||
*/
|
||||
private void remove(PrepareAnvilEvent event, ItemStack inputItem) {
|
||||
ItemStack finalItem = inputItem.clone();
|
||||
ItemMeta meta = finalItem.getItemMeta();
|
||||
PersistentDataContainer container = meta.getPersistentDataContainer();
|
||||
|
||||
// remove the applied tokens
|
||||
if (container.has(toolStats.tokenApplied)) {
|
||||
container.remove(toolStats.tokenApplied);
|
||||
}
|
||||
|
||||
if (container.has(toolStats.playerKills)) {
|
||||
Integer playerKills = container.get(toolStats.playerKills, PersistentDataType.INTEGER);
|
||||
if (playerKills == null) {
|
||||
return;
|
||||
}
|
||||
|
||||
container.remove(toolStats.playerKills);
|
||||
|
||||
String playerKillsFormatted = toolStats.numberFormat.formatInt(playerKills);
|
||||
Component lineToRemove = toolStats.configTools.formatLore("kills.player", "{kills}", playerKillsFormatted);
|
||||
meta.lore(toolStats.itemLore.removeLore(meta.lore(), lineToRemove));
|
||||
finalItem.setItemMeta(meta);
|
||||
}
|
||||
if (container.has(toolStats.mobKills)) {
|
||||
Integer mobKills = container.get(toolStats.mobKills, PersistentDataType.INTEGER);
|
||||
if (mobKills == null) {
|
||||
return;
|
||||
}
|
||||
|
||||
container.remove(toolStats.mobKills);
|
||||
|
||||
String mobKillsFormatted = toolStats.numberFormat.formatInt(mobKills);
|
||||
Component lineToRemove = toolStats.configTools.formatLore("kills.mob", "{kills}", mobKillsFormatted);
|
||||
meta.lore(toolStats.itemLore.removeLore(meta.lore(), lineToRemove));
|
||||
finalItem.setItemMeta(meta);
|
||||
}
|
||||
if (container.has(toolStats.blocksMined)) {
|
||||
Integer blocksMined = container.get(toolStats.blocksMined, PersistentDataType.INTEGER);
|
||||
if (blocksMined == null) {
|
||||
return;
|
||||
}
|
||||
|
||||
container.remove(toolStats.blocksMined);
|
||||
|
||||
String blocksMinedFormatted = toolStats.numberFormat.formatInt(blocksMined);
|
||||
Component lineToRemove = toolStats.configTools.formatLore("blocks-mined", "{blocks}", blocksMinedFormatted);
|
||||
meta.lore(toolStats.itemLore.removeLore(meta.lore(), lineToRemove));
|
||||
finalItem.setItemMeta(meta);
|
||||
}
|
||||
if (container.has(toolStats.cropsHarvested)) {
|
||||
Integer cropsHarvested = container.get(toolStats.playerKills, PersistentDataType.INTEGER);
|
||||
if (cropsHarvested == null) {
|
||||
return;
|
||||
}
|
||||
|
||||
container.remove(toolStats.cropsHarvested);
|
||||
|
||||
String cropsHarvestedFormatted = toolStats.numberFormat.formatInt(cropsHarvested);
|
||||
Component lineToRemove = toolStats.configTools.formatLore("crops-harvested", "{crops}", cropsHarvestedFormatted);
|
||||
meta.lore(toolStats.itemLore.removeLore(meta.lore(), lineToRemove));
|
||||
finalItem.setItemMeta(meta);
|
||||
}
|
||||
if (container.has(toolStats.fishCaught)) {
|
||||
Integer fishCaught = container.get(toolStats.fishCaught, PersistentDataType.INTEGER);
|
||||
if (fishCaught == null) {
|
||||
return;
|
||||
}
|
||||
|
||||
container.remove(toolStats.fishCaught);
|
||||
|
||||
String fishCaughtFormatted = toolStats.numberFormat.formatInt(fishCaught);
|
||||
Component lineToRemove = toolStats.configTools.formatLore("fished.fish-caught", "{fish}", fishCaughtFormatted);
|
||||
meta.lore(toolStats.itemLore.removeLore(meta.lore(), lineToRemove));
|
||||
finalItem.setItemMeta(meta);
|
||||
}
|
||||
if (container.has(toolStats.sheepSheared)) {
|
||||
Integer sheepSheared = container.get(toolStats.sheepSheared, PersistentDataType.INTEGER);
|
||||
if (sheepSheared == null) {
|
||||
return;
|
||||
}
|
||||
|
||||
container.remove(toolStats.sheepSheared);
|
||||
|
||||
String sheepShearedFormatted = toolStats.numberFormat.formatInt(sheepSheared);
|
||||
Component lineToRemove = toolStats.configTools.formatLore("sheep.sheared", "{sheep}", sheepShearedFormatted);
|
||||
meta.lore(toolStats.itemLore.removeLore(meta.lore(), lineToRemove));
|
||||
finalItem.setItemMeta(meta);
|
||||
}
|
||||
if (container.has(toolStats.armorDamage)) {
|
||||
Double armorDamage = container.get(toolStats.armorDamage, PersistentDataType.DOUBLE);
|
||||
if (armorDamage == null) {
|
||||
return;
|
||||
}
|
||||
|
||||
container.remove(toolStats.armorDamage);
|
||||
|
||||
String armorDamageFormatted = toolStats.numberFormat.formatDouble(armorDamage);
|
||||
Component lineToRemove = toolStats.configTools.formatLore("damage-taken", "{damage}", armorDamageFormatted);
|
||||
meta.lore(toolStats.itemLore.removeLore(meta.lore(), lineToRemove));
|
||||
finalItem.setItemMeta(meta);
|
||||
}
|
||||
if (container.has(toolStats.damageDone)) {
|
||||
Double damageDone = container.get(toolStats.damageDone, PersistentDataType.DOUBLE);
|
||||
if (damageDone == null) {
|
||||
return;
|
||||
}
|
||||
|
||||
container.remove(toolStats.damageDone);
|
||||
|
||||
String damageDoneFormatted = toolStats.numberFormat.formatDouble(damageDone);
|
||||
Component lineToRemove = toolStats.configTools.formatLore("damage-done", "{damage}", damageDoneFormatted);
|
||||
meta.lore(toolStats.itemLore.removeLore(meta.lore(), lineToRemove));
|
||||
finalItem.setItemMeta(meta);
|
||||
}
|
||||
if (container.has(toolStats.arrowsShot)) {
|
||||
Integer arrowsShot = container.get(toolStats.arrowsShot, PersistentDataType.INTEGER);
|
||||
if (arrowsShot == null) {
|
||||
return;
|
||||
}
|
||||
|
||||
container.remove(toolStats.arrowsShot);
|
||||
|
||||
String arrowsShotFormatted = toolStats.numberFormat.formatInt(arrowsShot);
|
||||
Component lineToRemove = toolStats.configTools.formatLore("arrows-shot", "{arrows}", arrowsShotFormatted);
|
||||
meta.lore(toolStats.itemLore.removeLore(meta.lore(), lineToRemove));
|
||||
finalItem.setItemMeta(meta);
|
||||
}
|
||||
if (container.has(toolStats.flightTime)) {
|
||||
Long flightTime = container.get(toolStats.flightTime, PersistentDataType.LONG);
|
||||
if (flightTime == null) {
|
||||
return;
|
||||
}
|
||||
|
||||
container.remove(toolStats.flightTime);
|
||||
|
||||
String flightTimeFormatted = toolStats.numberFormat.formatDouble(flightTime);
|
||||
Component lineToRemove = toolStats.configTools.formatLore("flight-time", "{time}", flightTimeFormatted);
|
||||
meta.lore(toolStats.itemLore.removeLore(meta.lore(), lineToRemove));
|
||||
finalItem.setItemMeta(meta);
|
||||
}
|
||||
|
||||
event.setResult(finalItem);
|
||||
event.getView().setRepairCost(toolStats.itemChecker.getCost("remove"));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -48,7 +48,7 @@ public class BlockBreak implements Listener {
|
||||
return;
|
||||
}
|
||||
Player player = event.getPlayer();
|
||||
if (player.getGameMode() == GameMode.CREATIVE || player.getGameMode() == GameMode.SPECTATOR) {
|
||||
if (player.getGameMode() == GameMode.CREATIVE && !toolStats.config.getBoolean("allow-creative")) {
|
||||
return;
|
||||
}
|
||||
PlayerInventory inventory = player.getInventory();
|
||||
|
||||
@@ -50,7 +50,7 @@ public class CraftItem implements Listener {
|
||||
return;
|
||||
}
|
||||
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;
|
||||
}
|
||||
ItemStack craftedItem = event.getCurrentItem();
|
||||
@@ -121,7 +121,13 @@ public class CraftItem implements Listener {
|
||||
}
|
||||
// get the current time
|
||||
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();
|
||||
} else {
|
||||
finalDate = new Date(timeCreated);
|
||||
}
|
||||
PersistentDataContainer container = meta.getPersistentDataContainer();
|
||||
|
||||
// if the item already has the tag
|
||||
@@ -139,12 +145,12 @@ public class CraftItem implements Listener {
|
||||
}
|
||||
|
||||
// if creation date is enabled, add it
|
||||
if (toolStats.configTools.checkConfig(itemStack.getType(), "created-date")) {
|
||||
if (toolStats.configTools.checkConfig(itemStack.getType(), "crafted-on")) {
|
||||
container.set(toolStats.timeCreated, PersistentDataType.LONG, timeCreated);
|
||||
container.set(toolStats.originType, PersistentDataType.INTEGER, 0);
|
||||
|
||||
String date = toolStats.numberFormat.formatDate(finalDate);
|
||||
Component newLine = toolStats.configTools.formatLore("created.created-on", "{date}", date);
|
||||
Component newLine = toolStats.configTools.formatLore("crafted.crafted-on", "{date}", date);
|
||||
if (newLine == null) {
|
||||
return null;
|
||||
}
|
||||
@@ -153,11 +159,11 @@ public class CraftItem implements Listener {
|
||||
}
|
||||
|
||||
// if creation owner is enabled, add it
|
||||
if (toolStats.configTools.checkConfig(itemStack.getType(), "created-by")) {
|
||||
if (toolStats.configTools.checkConfig(itemStack.getType(), "crafted-by")) {
|
||||
container.set(toolStats.itemOwner, new UUIDDataType(), owner.getUniqueId());
|
||||
container.set(toolStats.originType, PersistentDataType.INTEGER, 0);
|
||||
|
||||
Component newLine = toolStats.configTools.formatLore("created.created-by", "{player}", owner.getName());
|
||||
Component newLine = toolStats.configTools.formatLore("crafted.crafted-by", "{player}", owner.getName());
|
||||
if (newLine == null) {
|
||||
return null;
|
||||
}
|
||||
|
||||
@@ -30,6 +30,7 @@ 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;
|
||||
|
||||
@@ -87,7 +88,13 @@ public class CreativeEvent implements Listener {
|
||||
}
|
||||
// get the current time
|
||||
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();
|
||||
} else {
|
||||
finalDate = new Date(timeCreated);
|
||||
}
|
||||
PersistentDataContainer container = meta.getPersistentDataContainer();
|
||||
|
||||
// if the item already has the tag
|
||||
@@ -96,22 +103,45 @@ public class CreativeEvent implements Listener {
|
||||
return null;
|
||||
}
|
||||
|
||||
// get the current lore the item
|
||||
List<Component> lore;
|
||||
if (meta.hasLore()) {
|
||||
lore = meta.lore();
|
||||
} else {
|
||||
lore = new ArrayList<>();
|
||||
}
|
||||
|
||||
if (toolStats.configTools.checkConfig(itemStack.getType(), "spawned-in-on")) {
|
||||
container.set(toolStats.timeCreated, PersistentDataType.LONG, timeCreated);
|
||||
container.set(toolStats.originType, PersistentDataType.INTEGER, 6);
|
||||
|
||||
String date = toolStats.numberFormat.formatDate(finalDate);
|
||||
Component newLine = toolStats.configTools.formatLore("spawned-in.spawned-on", "{date}", date);
|
||||
if (newLine == null) {
|
||||
return null;
|
||||
}
|
||||
lore.add(newLine);
|
||||
meta.lore(lore);
|
||||
}
|
||||
|
||||
if (toolStats.configTools.checkConfig(itemStack.getType(), "spawned-in-by")) {
|
||||
container.set(toolStats.itemOwner, new UUIDDataType(), owner.getUniqueId());
|
||||
container.set(toolStats.originType, PersistentDataType.INTEGER, 6);
|
||||
|
||||
Component newLine = toolStats.configTools.formatLore("spawned-in.spawned-by", "{player}", owner.getName());
|
||||
if (newLine == null) {
|
||||
return null;
|
||||
}
|
||||
lore.add(newLine);
|
||||
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);
|
||||
}
|
||||
|
||||
// if spawned in is enabled, add it
|
||||
if (toolStats.configTools.checkConfig(newSpawnedItem.getType(), "spawned-in")) {
|
||||
container.set(toolStats.timeCreated, PersistentDataType.LONG, timeCreated);
|
||||
container.set(toolStats.itemOwner, new UUIDDataType(), owner.getUniqueId());
|
||||
container.set(toolStats.originType, PersistentDataType.INTEGER, 6);
|
||||
|
||||
String formattedDate = toolStats.numberFormat.formatDate(finalDate);
|
||||
List<Component> newLore = toolStats.itemLore.addNewOwner(meta, owner.getName(), formattedDate);
|
||||
meta.lore(newLore);
|
||||
}
|
||||
newSpawnedItem.setItemMeta(meta);
|
||||
return newSpawnedItem;
|
||||
}
|
||||
|
||||
@@ -18,26 +18,26 @@
|
||||
package lol.hyper.toolstats.events;
|
||||
|
||||
import lol.hyper.toolstats.ToolStats;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.GameMode;
|
||||
import org.bukkit.entity.Arrow;
|
||||
import org.bukkit.entity.LivingEntity;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.entity.Trident;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.entity.*;
|
||||
import org.bukkit.event.EventHandler;
|
||||
import org.bukkit.event.EventPriority;
|
||||
import org.bukkit.event.Listener;
|
||||
import org.bukkit.event.entity.EntityDamageByBlockEvent;
|
||||
import org.bukkit.event.entity.EntityDamageByEntityEvent;
|
||||
import org.bukkit.event.entity.EntityDamageEvent;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
import org.bukkit.inventory.PlayerInventory;
|
||||
import org.bukkit.inventory.meta.ItemMeta;
|
||||
import org.bukkit.projectiles.ProjectileSource;
|
||||
|
||||
import java.util.*;
|
||||
|
||||
public class EntityDamage implements Listener {
|
||||
|
||||
private final ToolStats toolStats;
|
||||
// track mobs that are killed by a player
|
||||
public final Set<UUID> trackedMobs = new HashSet<>();
|
||||
private final List<EntityDamageEvent.DamageCause> ignoredCauses = Arrays.asList(EntityDamageEvent.DamageCause.SUICIDE, EntityDamageEvent.DamageCause.VOID, EntityDamageEvent.DamageCause.CUSTOM, EntityDamageEvent.DamageCause.KILL);
|
||||
|
||||
@@ -61,101 +61,84 @@ public class EntityDamage implements Listener {
|
||||
return;
|
||||
}
|
||||
|
||||
// mob is going to die
|
||||
if (mobBeingAttacked.getHealth() - event.getFinalDamage() <= 0) {
|
||||
// a player is killing something
|
||||
if (event.getDamager() instanceof Player attackingPlayer) {
|
||||
if (attackingPlayer.getGameMode() == GameMode.CREATIVE || attackingPlayer.getGameMode() == GameMode.SPECTATOR) {
|
||||
return;
|
||||
}
|
||||
PlayerInventory attackingPlayerInventory = attackingPlayer.getInventory();
|
||||
ItemStack heldItem = attackingPlayerInventory.getItemInMainHand();
|
||||
// only check certain items
|
||||
if (!toolStats.itemChecker.isMeleeWeapon(heldItem.getType())) {
|
||||
return;
|
||||
}
|
||||
// a player is killing another player
|
||||
if (mobBeingAttacked instanceof Player) {
|
||||
ItemMeta newItem = toolStats.itemLore.updatePlayerKills(heldItem, 1);
|
||||
if (newItem != null) {
|
||||
attackingPlayerInventory.getItemInMainHand().setItemMeta(newItem);
|
||||
}
|
||||
return;
|
||||
}
|
||||
// player is killing regular mob
|
||||
ItemMeta newItem = toolStats.itemLore.updateMobKills(heldItem, 1);
|
||||
if (newItem != null) {
|
||||
attackingPlayerInventory.getItemInMainHand().setItemMeta(newItem);
|
||||
}
|
||||
trackedMobs.add(mobBeingAttacked.getUniqueId());
|
||||
}
|
||||
// trident is being thrown at something
|
||||
if (event.getDamager() instanceof Trident trident) {
|
||||
ItemStack newTrident = trident.getItemStack();
|
||||
ItemMeta newMeta;
|
||||
// trident is killing player
|
||||
if (mobBeingAttacked instanceof Player) {
|
||||
newMeta = toolStats.itemLore.updatePlayerKills(trident.getItemStack(), 1);
|
||||
} else {
|
||||
// trident is killing a mob
|
||||
newMeta = toolStats.itemLore.updateMobKills(trident.getItemStack(), 1);
|
||||
trackedMobs.add(mobBeingAttacked.getUniqueId());
|
||||
}
|
||||
if (newMeta != null) {
|
||||
newTrident.setItemMeta(newMeta);
|
||||
trident.setItemStack(newTrident);
|
||||
}
|
||||
}
|
||||
// arrow is being shot
|
||||
if (event.getDamager() instanceof Arrow arrow) {
|
||||
// if the shooter is a player
|
||||
if (arrow.getShooter() instanceof Player shootingPlayer) {
|
||||
if (shootingPlayer.getGameMode() == GameMode.CREATIVE || shootingPlayer.getGameMode() == GameMode.SPECTATOR) {
|
||||
return;
|
||||
}
|
||||
PlayerInventory shootingPlayerInventory = shootingPlayer.getInventory();
|
||||
ItemStack heldBow = toolStats.itemChecker.getBow(shootingPlayerInventory);
|
||||
if (heldBow == null) {
|
||||
return;
|
||||
}
|
||||
Entity damager = event.getDamager();
|
||||
boolean playerAttacking = damager instanceof Player;
|
||||
boolean playerBeingAttacked = mobBeingAttacked instanceof Player;
|
||||
double finalDamage = event.getFinalDamage();
|
||||
boolean modDied = mobBeingAttacked.getHealth() - finalDamage <= 0;
|
||||
|
||||
// player is shooting another player
|
||||
if (mobBeingAttacked instanceof Player) {
|
||||
ItemMeta newItem = toolStats.itemLore.updatePlayerKills(heldBow, 1);
|
||||
if (newItem != null) {
|
||||
shootingPlayerInventory.getItemInMainHand().setItemMeta(newItem);
|
||||
}
|
||||
} else {
|
||||
// player is shooting a mob
|
||||
ItemMeta newItem = toolStats.itemLore.updateMobKills(heldBow, 1);
|
||||
if (newItem != null) {
|
||||
shootingPlayerInventory.getItemInMainHand().setItemMeta(newItem);
|
||||
}
|
||||
trackedMobs.add(mobBeingAttacked.getUniqueId());
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
// player is taken damage but not being killed
|
||||
if (mobBeingAttacked instanceof Player playerTakingDamage) {
|
||||
if (playerTakingDamage.getGameMode() == GameMode.CREATIVE || playerTakingDamage.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;
|
||||
}
|
||||
PlayerInventory playerInventory = playerTakingDamage.getInventory();
|
||||
ItemStack[] armorContents = playerInventory.getArmorContents();
|
||||
for (ItemStack armorPiece : armorContents) {
|
||||
if (armorPiece != null) {
|
||||
if (toolStats.itemChecker.isArmor(armorPiece.getType())) {
|
||||
ItemMeta newItem = toolStats.itemLore.updateDamage(armorPiece, event.getFinalDamage(), false);
|
||||
if (newItem != null) {
|
||||
armorPiece.setItemMeta(newItem);
|
||||
}
|
||||
}
|
||||
|
||||
// update their weapon's damage
|
||||
updateWeaponDamage(playerAttackingInventory, event.getFinalDamage());
|
||||
|
||||
// the mob the player attacked died
|
||||
if (modDied) {
|
||||
// player killed another player
|
||||
if (playerBeingAttacked) {
|
||||
updateWeaponKills(playerAttackingInventory, "player");
|
||||
} else {
|
||||
// player kills a regular mob
|
||||
updateWeaponKills(playerAttackingInventory, "mob");
|
||||
}
|
||||
}
|
||||
|
||||
// apply the new armor
|
||||
playerInventory.setArmorContents(armorContents);
|
||||
trackedMobs.add(mobBeingAttacked.getUniqueId());
|
||||
Bukkit.getGlobalRegionScheduler().runDelayed(toolStats, scheduledTask -> trackedMobs.remove(mobBeingAttacked.getUniqueId()), 20);
|
||||
}
|
||||
|
||||
// something was hit by a trident
|
||||
if (damager instanceof Trident trident) {
|
||||
ProjectileSource source = trident.getShooter();
|
||||
if (source instanceof Player) {
|
||||
// update the trident's tracked damage
|
||||
updateTridentDamage(trident, finalDamage);
|
||||
|
||||
// if the mob died from the trident
|
||||
if (modDied) {
|
||||
// if the trident killed a player, update the kills
|
||||
if (playerBeingAttacked) {
|
||||
updateTridentKills(trident, "player");
|
||||
} else {
|
||||
// the trident killed a mob, update the kills
|
||||
updateTridentKills(trident, "mob");
|
||||
}
|
||||
}
|
||||
|
||||
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");
|
||||
}
|
||||
}
|
||||
|
||||
trackedMobs.add(mobBeingAttacked.getUniqueId());
|
||||
Bukkit.getGlobalRegionScheduler().runDelayed(toolStats, scheduledTask -> trackedMobs.remove(mobBeingAttacked.getUniqueId()), 20);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -171,61 +154,133 @@ public class EntityDamage implements Listener {
|
||||
return;
|
||||
}
|
||||
|
||||
// player is taken damage but not being killed
|
||||
// player is taking damage
|
||||
if (mobBeingAttacked instanceof Player playerTakingDamage) {
|
||||
if (playerTakingDamage.getGameMode() == GameMode.CREATIVE || playerTakingDamage.getGameMode() == GameMode.SPECTATOR) {
|
||||
if (playerTakingDamage.getGameMode() == GameMode.CREATIVE && !toolStats.config.getBoolean("allow-creative")) {
|
||||
return;
|
||||
}
|
||||
PlayerInventory playerInventory = playerTakingDamage.getInventory();
|
||||
ItemStack[] armorContents = playerInventory.getArmorContents();
|
||||
for (ItemStack armorPiece : armorContents) {
|
||||
if (armorPiece != null) {
|
||||
if (toolStats.itemChecker.isArmor(armorPiece.getType())) {
|
||||
ItemMeta newItem = toolStats.itemLore.updateDamage(armorPiece, event.getFinalDamage(),false);
|
||||
if (newItem != null) {
|
||||
armorPiece.setItemMeta(newItem);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// apply the new armor
|
||||
playerInventory.setArmorContents(armorContents);
|
||||
updateArmorDamage(playerTakingDamage.getInventory(), event.getFinalDamage());
|
||||
}
|
||||
}
|
||||
|
||||
@EventHandler(priority = EventPriority.MONITOR)
|
||||
public void onDamage(EntityDamageByBlockEvent event) {
|
||||
if (!(event.getEntity() instanceof LivingEntity mobBeingAttacked)) {
|
||||
return;
|
||||
}
|
||||
|
||||
// ignore void and /kill damage
|
||||
EntityDamageEvent.DamageCause cause = event.getCause();
|
||||
if (ignoredCauses.contains(cause)) {
|
||||
return;
|
||||
}
|
||||
|
||||
// player is taken damage but not being killed
|
||||
if (mobBeingAttacked instanceof Player playerTakingDamage) {
|
||||
if (playerTakingDamage.getGameMode() == GameMode.CREATIVE || playerTakingDamage.getGameMode() == GameMode.SPECTATOR) {
|
||||
return;
|
||||
}
|
||||
PlayerInventory playerInventory = playerTakingDamage.getInventory();
|
||||
ItemStack[] armorContents = playerInventory.getArmorContents();
|
||||
for (ItemStack armorPiece : armorContents) {
|
||||
if (armorPiece != null) {
|
||||
if (toolStats.itemChecker.isArmor(armorPiece.getType())) {
|
||||
ItemMeta newItem = toolStats.itemLore.updateDamage(armorPiece, event.getFinalDamage(), false);
|
||||
if (newItem != null) {
|
||||
armorPiece.setItemMeta(newItem);
|
||||
}
|
||||
private void updateArmorDamage(PlayerInventory playerInventory, double damage) {
|
||||
ItemStack[] armorContents = playerInventory.getArmorContents();
|
||||
for (ItemStack armorPiece : armorContents) {
|
||||
if (armorPiece != null) {
|
||||
if (toolStats.itemChecker.isArmor(armorPiece.getType())) {
|
||||
ItemMeta newItem = toolStats.itemLore.updateArmorDamage(armorPiece, damage, false);
|
||||
if (newItem != null) {
|
||||
armorPiece.setItemMeta(newItem);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
// apply the new armor
|
||||
playerInventory.setArmorContents(armorContents);
|
||||
}
|
||||
|
||||
// apply the new armor
|
||||
playerInventory.setArmorContents(armorContents);
|
||||
private void updateBowDamage(PlayerInventory playerInventory, double damage) {
|
||||
ItemStack heldBow = toolStats.itemChecker.getBow(playerInventory);
|
||||
if (heldBow == null) {
|
||||
return;
|
||||
}
|
||||
|
||||
boolean isMain = playerInventory.getItemInMainHand().getType() == Material.BOW || playerInventory.getItemInMainHand().getType() == Material.CROSSBOW;
|
||||
boolean isOffHand = playerInventory.getItemInOffHand().getType() == Material.BOW || playerInventory.getItemInOffHand().getType() == Material.CROSSBOW;
|
||||
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;
|
||||
}
|
||||
|
||||
boolean isMain = playerInventory.getItemInMainHand().getType() == Material.BOW || playerInventory.getItemInMainHand().getType() == Material.CROSSBOW;
|
||||
boolean isOffHand = playerInventory.getItemInOffHand().getType() == Material.BOW || playerInventory.getItemInOffHand().getType() == Material.CROSSBOW;
|
||||
|
||||
if (type.equalsIgnoreCase("mob")) {
|
||||
// player is shooting a mob
|
||||
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);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
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) {
|
||||
ItemStack newTrident = trident.getItemStack();
|
||||
ItemMeta newKills;
|
||||
if (type.equalsIgnoreCase("player")) {
|
||||
newKills = toolStats.itemLore.updatePlayerKills(trident.getItemStack(), 1);
|
||||
} else {
|
||||
newKills = toolStats.itemLore.updateMobKills(trident.getItemStack(), 1);
|
||||
}
|
||||
if (newKills != null) {
|
||||
newTrident.setItemMeta(newKills);
|
||||
trident.setItemStack(newTrident);
|
||||
}
|
||||
}
|
||||
|
||||
private void updateTridentDamage(Trident trident, double damage) {
|
||||
ItemStack newTrident = trident.getItemStack();
|
||||
ItemMeta newDamage = toolStats.itemLore.updateWeaponDamage(trident.getItemStack(), damage, false);
|
||||
if (newDamage != null) {
|
||||
newTrident.setItemMeta(newDamage);
|
||||
trident.setItemStack(newTrident);
|
||||
}
|
||||
}
|
||||
|
||||
private void updateWeaponDamage(PlayerInventory playerInventory, double damage) {
|
||||
ItemStack heldWeapon = playerInventory.getItemInMainHand();
|
||||
ItemMeta newHeldWeaponMeta = toolStats.itemLore.updateWeaponDamage(heldWeapon, damage, false);
|
||||
if (newHeldWeaponMeta != null) {
|
||||
playerInventory.getItemInMainHand().setItemMeta(newHeldWeaponMeta);
|
||||
}
|
||||
}
|
||||
|
||||
private void updateWeaponKills(PlayerInventory playerInventory, String type) {
|
||||
ItemStack heldWeapon = playerInventory.getItemInMainHand();
|
||||
ItemMeta newHeldWeaponMeta = null;
|
||||
if (type.equalsIgnoreCase("player")) {
|
||||
newHeldWeaponMeta = toolStats.itemLore.updatePlayerKills(heldWeapon, 1);
|
||||
}
|
||||
if (type.equalsIgnoreCase("mob")) {
|
||||
newHeldWeaponMeta = toolStats.itemLore.updateMobKills(heldWeapon, 1);
|
||||
}
|
||||
if (newHeldWeaponMeta != null) {
|
||||
playerInventory.getItemInMainHand().setItemMeta(newHeldWeaponMeta);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -30,6 +30,8 @@ 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;
|
||||
import java.util.UUID;
|
||||
|
||||
@@ -84,19 +86,44 @@ public class EntityDeath implements Listener {
|
||||
return null;
|
||||
}
|
||||
|
||||
if (!toolStats.config.getBoolean("enabled.dropped-by")) {
|
||||
return null;
|
||||
long timeCreated = System.currentTimeMillis();
|
||||
Date finalDate;
|
||||
if (toolStats.config.getBoolean("normalize-time-creation")) {
|
||||
finalDate = toolStats.numberFormat.normalizeTime(timeCreated);
|
||||
timeCreated = finalDate.getTime();
|
||||
} else {
|
||||
finalDate = new Date(timeCreated);
|
||||
}
|
||||
|
||||
PersistentDataContainer container = meta.getPersistentDataContainer();
|
||||
container.set(toolStats.originType, PersistentDataType.INTEGER, 1);
|
||||
String mobName = toolStats.config.getString("messages.mob." + entity.getType());
|
||||
if (mobName == null) {
|
||||
mobName = entity.getName();
|
||||
}
|
||||
Component newLine = toolStats.configTools.formatLore("dropped-by", "{name}", mobName);
|
||||
List<Component> newLore = toolStats.itemLore.addItemLore(meta, newLine);
|
||||
meta.lore(newLore);
|
||||
|
||||
List<Component> lore;
|
||||
if (meta.hasLore()) {
|
||||
lore = meta.lore();
|
||||
} else {
|
||||
lore = new ArrayList<>();
|
||||
}
|
||||
|
||||
if (toolStats.config.getBoolean("enabled.dropped-on")) {
|
||||
container.set(toolStats.originType, PersistentDataType.INTEGER, 1);
|
||||
container.set(toolStats.timeCreated, PersistentDataType.LONG, timeCreated);
|
||||
String date = toolStats.numberFormat.formatDate(finalDate);
|
||||
Component droppedOn = toolStats.configTools.formatLore("dropped-on", "{date}", date);
|
||||
lore.add(droppedOn);
|
||||
}
|
||||
|
||||
if (toolStats.config.getBoolean("enabled.dropped-by")) {
|
||||
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);
|
||||
return newItem;
|
||||
}
|
||||
|
||||
@@ -36,6 +36,7 @@ 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;
|
||||
|
||||
@@ -99,29 +100,58 @@ public class GenerateLoot implements Listener {
|
||||
return null;
|
||||
}
|
||||
long timeCreated = System.currentTimeMillis();
|
||||
Date finalDate = new Date(timeCreated);
|
||||
PersistentDataContainer container = meta.getPersistentDataContainer();
|
||||
|
||||
if (!toolStats.configTools.checkConfig(newItem.getType(), "looted-tag")) {
|
||||
return null;
|
||||
Date finalDate;
|
||||
if (toolStats.config.getBoolean("normalize-time-creation")) {
|
||||
finalDate = toolStats.numberFormat.normalizeTime(timeCreated);
|
||||
timeCreated = finalDate.getTime();
|
||||
} else {
|
||||
finalDate = new Date(timeCreated);
|
||||
}
|
||||
PersistentDataContainer container = meta.getPersistentDataContainer();
|
||||
|
||||
if (container.has(toolStats.timeCreated, PersistentDataType.LONG) || container.has(toolStats.itemOwner, PersistentDataType.LONG)) {
|
||||
return null;
|
||||
}
|
||||
|
||||
// only make the hash if it's enabled
|
||||
// get the current lore the item
|
||||
List<Component> lore;
|
||||
if (meta.hasLore()) {
|
||||
lore = meta.lore();
|
||||
} else {
|
||||
lore = new ArrayList<>();
|
||||
}
|
||||
|
||||
if (toolStats.configTools.checkConfig(newItem.getType(), "looted-on")) {
|
||||
container.set(toolStats.timeCreated, PersistentDataType.LONG, timeCreated);
|
||||
container.set(toolStats.originType, PersistentDataType.INTEGER, 2);
|
||||
|
||||
String date = toolStats.numberFormat.formatDate(finalDate);
|
||||
Component newLine = toolStats.configTools.formatLore("looted.looted-on", "{date}", date);
|
||||
if (newLine == null) {
|
||||
return null;
|
||||
}
|
||||
lore.add(newLine);
|
||||
meta.lore(lore);
|
||||
}
|
||||
|
||||
if (toolStats.configTools.checkConfig(newItem.getType(), "looted-by")) {
|
||||
container.set(toolStats.itemOwner, new UUIDDataType(), owner.getUniqueId());
|
||||
container.set(toolStats.originType, PersistentDataType.INTEGER, 2);
|
||||
|
||||
Component newLine = toolStats.configTools.formatLore("looted.looted-by", "{player}", owner.getName());
|
||||
if (newLine == null) {
|
||||
return null;
|
||||
}
|
||||
lore.add(newLine);
|
||||
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);
|
||||
}
|
||||
|
||||
container.set(toolStats.timeCreated, PersistentDataType.LONG, timeCreated);
|
||||
container.set(toolStats.itemOwner, new UUIDDataType(), owner.getUniqueId());
|
||||
container.set(toolStats.originType, PersistentDataType.INTEGER, 2);
|
||||
String formattedDate = toolStats.numberFormat.formatDate(finalDate);
|
||||
List<Component> newLore = toolStats.itemLore.addNewOwner(meta, owner.getName(), formattedDate);
|
||||
meta.lore(newLore);
|
||||
newItem.setItemMeta(meta);
|
||||
return newItem;
|
||||
}
|
||||
|
||||
@@ -23,6 +23,7 @@ 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;
|
||||
@@ -46,6 +47,11 @@ public class InventoryOpen implements Listener {
|
||||
}
|
||||
|
||||
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) {
|
||||
|
||||
@@ -35,6 +35,7 @@ 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;
|
||||
|
||||
@@ -53,7 +54,7 @@ public class PickupItem implements Listener {
|
||||
}
|
||||
Entity entity = event.getEntity();
|
||||
if (entity instanceof Player player) {
|
||||
if (player.getGameMode() == GameMode.CREATIVE || player.getGameMode() == GameMode.SPECTATOR) {
|
||||
if (player.getGameMode() == GameMode.CREATIVE && !toolStats.config.getBoolean("allow-creative")) {
|
||||
return;
|
||||
}
|
||||
Item item = event.getItem();
|
||||
@@ -90,7 +91,13 @@ public class PickupItem implements Listener {
|
||||
return null;
|
||||
}
|
||||
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();
|
||||
} else {
|
||||
finalDate = new Date(timeCreated);
|
||||
}
|
||||
PersistentDataContainer container = meta.getPersistentDataContainer();
|
||||
|
||||
if (!toolStats.config.getBoolean("enabled.elytra-tag")) {
|
||||
@@ -103,13 +110,25 @@ public class PickupItem implements Listener {
|
||||
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.itemOwner, new UUIDDataType(), owner.getUniqueId());
|
||||
container.set(toolStats.originType, PersistentDataType.INTEGER, 4);
|
||||
container.remove(toolStats.newElytra);
|
||||
|
||||
String formattedDate = toolStats.numberFormat.formatDate(finalDate);
|
||||
List<Component> newLore = toolStats.itemLore.addNewOwner(meta, owner.getName(), formattedDate);
|
||||
meta.lore(newLore);
|
||||
Component dateCreatedLore = toolStats.configTools.formatLore("looted.found-on", "{date}", formattedDate);
|
||||
Component itemOwnerLore = toolStats.configTools.formatLore("looted.found-by", "{player}", owner.getName());
|
||||
lore.add(dateCreatedLore);
|
||||
lore.add(itemOwnerLore);
|
||||
meta.lore(lore);
|
||||
finalItem.setItemMeta(meta);
|
||||
return finalItem;
|
||||
}
|
||||
|
||||
@@ -34,6 +34,7 @@ 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;
|
||||
|
||||
@@ -56,7 +57,7 @@ public class PlayerFish implements Listener {
|
||||
}
|
||||
|
||||
Player player = event.getPlayer();
|
||||
if (player.getGameMode() == GameMode.CREATIVE || player.getGameMode() == GameMode.SPECTATOR) {
|
||||
if (player.getGameMode() == GameMode.CREATIVE && !toolStats.config.getBoolean("allow-creative")) {
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -88,7 +89,7 @@ public class PlayerFish implements Listener {
|
||||
ItemStack caughtItem = ((Item) event.getCaught()).getItemStack();
|
||||
Item caughtItemEntity = (Item) event.getCaught();
|
||||
if (toolStats.itemChecker.isValidItem(caughtItem.getType())) {
|
||||
ItemStack newItem = addNewLore(caughtItem, player);
|
||||
ItemStack newItem = addFishedOrigin(caughtItem, player);
|
||||
if (newItem != null) {
|
||||
caughtItemEntity.setItemStack(newItem);
|
||||
}
|
||||
@@ -102,36 +103,65 @@ public class PlayerFish implements Listener {
|
||||
* @param owner The player who caught it.
|
||||
* @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();
|
||||
ItemMeta meta = originalItem.getItemMeta();
|
||||
if (meta == null) {
|
||||
return null;
|
||||
}
|
||||
long timeCreated = System.currentTimeMillis();
|
||||
Date finalDate = new Date(timeCreated);
|
||||
PersistentDataContainer container = meta.getPersistentDataContainer();
|
||||
|
||||
if (!toolStats.configTools.checkConfig(newItem.getType(), "fished-tag")) {
|
||||
return null;
|
||||
Date finalDate;
|
||||
if (toolStats.config.getBoolean("normalize-time-creation")) {
|
||||
finalDate = toolStats.numberFormat.normalizeTime(timeCreated);
|
||||
timeCreated = finalDate.getTime();
|
||||
} else {
|
||||
finalDate = new Date(timeCreated);
|
||||
}
|
||||
PersistentDataContainer container = meta.getPersistentDataContainer();
|
||||
|
||||
if (container.has(toolStats.timeCreated, PersistentDataType.LONG) || container.has(toolStats.itemOwner, PersistentDataType.LONG)) {
|
||||
return null;
|
||||
}
|
||||
|
||||
// only make the hash if it's enabled
|
||||
// get the current lore the item
|
||||
List<Component> lore;
|
||||
if (meta.hasLore()) {
|
||||
lore = meta.lore();
|
||||
} else {
|
||||
lore = new ArrayList<>();
|
||||
}
|
||||
|
||||
if (toolStats.configTools.checkConfig(newItem.getType(), "fished-on")) {
|
||||
container.set(toolStats.timeCreated, PersistentDataType.LONG, timeCreated);
|
||||
container.set(toolStats.originType, PersistentDataType.INTEGER, 5);
|
||||
|
||||
String date = toolStats.numberFormat.formatDate(finalDate);
|
||||
Component newLine = toolStats.configTools.formatLore("fished.caught-on", "{date}", date);
|
||||
if (newLine == null) {
|
||||
return null;
|
||||
}
|
||||
lore.add(newLine);
|
||||
meta.lore(lore);
|
||||
}
|
||||
|
||||
if (toolStats.configTools.checkConfig(newItem.getType(), "fished-by")) {
|
||||
container.set(toolStats.itemOwner, new UUIDDataType(), owner.getUniqueId());
|
||||
container.set(toolStats.originType, PersistentDataType.INTEGER, 5);
|
||||
|
||||
Component newLine = toolStats.configTools.formatLore("fished.caught-by", "{player}", owner.getName());
|
||||
if (newLine == null) {
|
||||
return null;
|
||||
}
|
||||
lore.add(newLine);
|
||||
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);
|
||||
}
|
||||
|
||||
container.set(toolStats.timeCreated, PersistentDataType.LONG, timeCreated);
|
||||
container.set(toolStats.itemOwner, new UUIDDataType(), owner.getUniqueId());
|
||||
container.set(toolStats.originType, PersistentDataType.INTEGER, 5);
|
||||
String formattedDate = toolStats.numberFormat.formatDate(finalDate);
|
||||
List<Component> newLore = toolStats.itemLore.addNewOwner(meta, owner.getName(), formattedDate);
|
||||
meta.lore(newLore);
|
||||
newItem.setItemMeta(meta);
|
||||
return newItem;
|
||||
}
|
||||
|
||||
@@ -58,7 +58,7 @@ public class PlayerInteract implements Listener {
|
||||
}
|
||||
|
||||
Player player = event.getPlayer();
|
||||
if (player.getGameMode() == GameMode.CREATIVE || player.getGameMode() == GameMode.SPECTATOR) {
|
||||
if (player.getGameMode() == GameMode.CREATIVE && !toolStats.config.getBoolean("allow-creative")) {
|
||||
return;
|
||||
}
|
||||
// store when a player opens a chest
|
||||
@@ -72,7 +72,7 @@ public class PlayerInteract implements Listener {
|
||||
public void onInteract(PlayerInteractEntityEvent event) {
|
||||
Entity clicked = event.getRightClicked();
|
||||
Player player = event.getPlayer();
|
||||
if (player.getGameMode() == GameMode.CREATIVE || player.getGameMode() == GameMode.SPECTATOR) {
|
||||
if (player.getGameMode() == GameMode.CREATIVE && !toolStats.config.getBoolean("allow-creative")) {
|
||||
return;
|
||||
}
|
||||
// store when a player opens a minecart
|
||||
|
||||
@@ -41,7 +41,7 @@ public class PlayerMove implements Listener {
|
||||
}
|
||||
|
||||
@EventHandler(priority = EventPriority.MONITOR)
|
||||
public void onCraft(PlayerMoveEvent event) {
|
||||
public void onMove(PlayerMoveEvent event) {
|
||||
Player player = event.getPlayer();
|
||||
// player starts to fly
|
||||
if (player.isGliding()) {
|
||||
|
||||
@@ -45,7 +45,7 @@ public class SheepShear implements Listener {
|
||||
return;
|
||||
}
|
||||
Player player = event.getPlayer();
|
||||
if (player.getGameMode() == GameMode.CREATIVE || player.getGameMode() == GameMode.SPECTATOR) {
|
||||
if (player.getGameMode() == GameMode.CREATIVE && !toolStats.config.getBoolean("allow-creative")) {
|
||||
return;
|
||||
}
|
||||
Entity entity = event.getRightClicked();
|
||||
|
||||
@@ -46,7 +46,7 @@ public class ShootBow implements Listener {
|
||||
return;
|
||||
}
|
||||
|
||||
if (player.getGameMode() == GameMode.CREATIVE || player.getGameMode() == GameMode.ADVENTURE) {
|
||||
if (player.getGameMode() == GameMode.CREATIVE && !toolStats.config.getBoolean("allow-creative")) {
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
@@ -35,6 +35,7 @@ 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;
|
||||
|
||||
@@ -126,29 +127,58 @@ public class VillagerTrade implements Listener {
|
||||
return null;
|
||||
}
|
||||
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();
|
||||
} else {
|
||||
finalDate = new Date(timeCreated);
|
||||
}
|
||||
PersistentDataContainer container = meta.getPersistentDataContainer();
|
||||
|
||||
if (container.has(toolStats.timeCreated, PersistentDataType.LONG) || container.has(toolStats.itemOwner, PersistentDataType.LONG)) {
|
||||
return null;
|
||||
}
|
||||
|
||||
if (!toolStats.configTools.checkConfig(newItem.getType(), "traded-tag")) {
|
||||
return null;
|
||||
// get the current lore the item
|
||||
List<Component> lore;
|
||||
if (meta.hasLore()) {
|
||||
lore = meta.lore();
|
||||
} else {
|
||||
lore = new ArrayList<>();
|
||||
}
|
||||
|
||||
// only make the hash if it's enabled
|
||||
if (toolStats.configTools.checkConfig(newItem.getType(), "traded-on")) {
|
||||
container.set(toolStats.timeCreated, PersistentDataType.LONG, timeCreated);
|
||||
container.set(toolStats.originType, PersistentDataType.INTEGER, 3);
|
||||
|
||||
String date = toolStats.numberFormat.formatDate(finalDate);
|
||||
Component newLine = toolStats.configTools.formatLore("traded.traded-on", "{date}", date);
|
||||
if (newLine == null) {
|
||||
return null;
|
||||
}
|
||||
lore.add(newLine);
|
||||
meta.lore(lore);
|
||||
}
|
||||
|
||||
if (toolStats.configTools.checkConfig(newItem.getType(), "traded-by")) {
|
||||
container.set(toolStats.itemOwner, new UUIDDataType(), owner.getUniqueId());
|
||||
container.set(toolStats.originType, PersistentDataType.INTEGER, 3);
|
||||
|
||||
Component newLine = toolStats.configTools.formatLore("traded.traded-by", "{player}", owner.getName());
|
||||
if (newLine == null) {
|
||||
return null;
|
||||
}
|
||||
lore.add(newLine);
|
||||
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);
|
||||
}
|
||||
|
||||
container.set(toolStats.timeCreated, PersistentDataType.LONG, timeCreated);
|
||||
container.set(toolStats.itemOwner, new UUIDDataType(), owner.getUniqueId());
|
||||
container.set(toolStats.originType, PersistentDataType.INTEGER, 3);
|
||||
String formattedDate = toolStats.numberFormat.formatDate(finalDate);
|
||||
List<Component> newLore = toolStats.itemLore.addNewOwner(meta, owner.getName(), formattedDate);
|
||||
meta.lore(newLore);
|
||||
newItem.setItemMeta(meta);
|
||||
return newItem;
|
||||
}
|
||||
|
||||
@@ -27,10 +27,7 @@ import org.bukkit.persistence.PersistentDataContainer;
|
||||
import org.bukkit.persistence.PersistentDataType;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
import java.util.Locale;
|
||||
import java.util.*;
|
||||
|
||||
public class ItemChecker {
|
||||
|
||||
@@ -333,6 +330,9 @@ public class ItemChecker {
|
||||
if (container.has(toolStats.flightTime)) {
|
||||
tokens.add("flight-time");
|
||||
}
|
||||
if (container.has(toolStats.damageDone)) {
|
||||
tokens.add("damage-done");
|
||||
}
|
||||
if (tokens.isEmpty()) {
|
||||
return null;
|
||||
}
|
||||
@@ -340,6 +340,26 @@ public class ItemChecker {
|
||||
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.
|
||||
*
|
||||
|
||||
@@ -27,6 +27,7 @@ import org.bukkit.persistence.PersistentDataType;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
public class ItemLore {
|
||||
|
||||
@@ -101,131 +102,6 @@ public class ItemLore {
|
||||
return newLore;
|
||||
}
|
||||
|
||||
/**
|
||||
* Adds new ownership to an item.
|
||||
*
|
||||
* @param itemMeta The item meta.
|
||||
* @param playerName The new owner of item.
|
||||
* @param formattedDate The date of the ownership.
|
||||
* @return The item's new lore.
|
||||
*/
|
||||
public List<Component> addNewOwner(ItemMeta itemMeta, String playerName, String formattedDate) {
|
||||
Component dateCreatedLore;
|
||||
Component itemOwnerLore;
|
||||
Integer origin = null;
|
||||
PersistentDataContainer container = itemMeta.getPersistentDataContainer();
|
||||
if (container.has(toolStats.originType, PersistentDataType.INTEGER)) {
|
||||
origin = container.get(toolStats.originType, PersistentDataType.INTEGER);
|
||||
}
|
||||
|
||||
// if the origin is broken, don't try to set the lore
|
||||
if (origin == null) {
|
||||
toolStats.logger.info("Unable to determine origin for item " + itemMeta.getAsString());
|
||||
toolStats.logger.info("This IS a bug, please report this to the GitHub.");
|
||||
return itemMeta.lore();
|
||||
}
|
||||
|
||||
// set the lore based on the origin
|
||||
switch (origin) {
|
||||
case 2: {
|
||||
dateCreatedLore = toolStats.configTools.formatLore("looted.looted-on", "{date}", formattedDate);
|
||||
itemOwnerLore = toolStats.configTools.formatLore("looted.looted-by", "{player}", playerName);
|
||||
|
||||
if (dateCreatedLore == null) {
|
||||
toolStats.logger.warning("messages.looted.looted-on is not set in your config!");
|
||||
toolStats.logger.warning("Unable to update lore for item.");
|
||||
return itemMeta.lore();
|
||||
}
|
||||
if (itemOwnerLore == null) {
|
||||
toolStats.logger.warning("messages.looted.looted-by is not set in your config!");
|
||||
toolStats.logger.warning("Unable to update lore for item.");
|
||||
return itemMeta.lore();
|
||||
}
|
||||
break;
|
||||
}
|
||||
case 3: {
|
||||
dateCreatedLore = toolStats.configTools.formatLore("traded.traded-on", "{date}", formattedDate);
|
||||
itemOwnerLore = toolStats.configTools.formatLore("traded.traded-by", "{player}", playerName);
|
||||
|
||||
if (dateCreatedLore == null) {
|
||||
toolStats.logger.warning("messages.traded.traded-on is not set in your config!");
|
||||
toolStats.logger.warning("Unable to update lore for item.");
|
||||
return itemMeta.lore();
|
||||
}
|
||||
if (itemOwnerLore == null) {
|
||||
toolStats.logger.warning("messages.traded.traded-by is not set in your config!");
|
||||
toolStats.logger.warning("Unable to update lore for item.");
|
||||
return itemMeta.lore();
|
||||
}
|
||||
break;
|
||||
}
|
||||
case 4: {
|
||||
dateCreatedLore = toolStats.configTools.formatLore("looted.found-on", "{date}", formattedDate);
|
||||
itemOwnerLore = toolStats.configTools.formatLore("looted.found-by", "{player}", playerName);
|
||||
|
||||
if (dateCreatedLore == null) {
|
||||
toolStats.logger.warning("messages.looted.found-on is not set in your config!");
|
||||
toolStats.logger.warning("Unable to update lore for item.");
|
||||
return itemMeta.lore();
|
||||
}
|
||||
if (itemOwnerLore == null) {
|
||||
toolStats.logger.warning("messages.looted.found-by is not set in your config!");
|
||||
toolStats.logger.warning("Unable to update lore for item.");
|
||||
return itemMeta.lore();
|
||||
}
|
||||
break;
|
||||
}
|
||||
case 5: {
|
||||
dateCreatedLore = toolStats.configTools.formatLore("fished.caught-on", "{date}", formattedDate);
|
||||
itemOwnerLore = toolStats.configTools.formatLore("fished.caught-by", "{player}", playerName);
|
||||
|
||||
if (dateCreatedLore == null) {
|
||||
toolStats.logger.warning("messages.fished.caught-on is not set in your config!");
|
||||
toolStats.logger.warning("Unable to update lore for item.");
|
||||
return itemMeta.lore();
|
||||
}
|
||||
if (itemOwnerLore == null) {
|
||||
toolStats.logger.warning("messages.fished.caught-by is not set in your config!");
|
||||
toolStats.logger.warning("Unable to update lore for item.");
|
||||
return itemMeta.lore();
|
||||
}
|
||||
break;
|
||||
}
|
||||
case 6: {
|
||||
dateCreatedLore = toolStats.configTools.formatLore("spawned-in.spawned-on", "{date}", formattedDate);
|
||||
itemOwnerLore = toolStats.configTools.formatLore("spawned-in.spawned-by", "{player}", playerName);
|
||||
|
||||
if (dateCreatedLore == null) {
|
||||
toolStats.logger.warning("messages.spawned-in.spawned-on is not set in your config!");
|
||||
toolStats.logger.warning("Unable to update lore for item.");
|
||||
return itemMeta.lore();
|
||||
}
|
||||
if (itemOwnerLore == null) {
|
||||
toolStats.logger.warning("messages.spawned-in.spawned-by is not set in your config!");
|
||||
toolStats.logger.warning("Unable to update lore for item.");
|
||||
return itemMeta.lore();
|
||||
}
|
||||
break;
|
||||
}
|
||||
default: {
|
||||
toolStats.logger.warning("Origin " + origin + " was found. Data was modified OR something REALLY broke.");
|
||||
toolStats.logger.warning(itemMeta.getAsString());
|
||||
return itemMeta.lore();
|
||||
}
|
||||
}
|
||||
|
||||
List<Component> newLore;
|
||||
if (itemMeta.hasLore()) {
|
||||
newLore = itemMeta.lore();
|
||||
} else {
|
||||
newLore = new ArrayList<>();
|
||||
}
|
||||
|
||||
newLore.add(dateCreatedLore);
|
||||
newLore.add(itemOwnerLore);
|
||||
return newLore;
|
||||
}
|
||||
|
||||
/**
|
||||
* Add x to the crops mined stat.
|
||||
*
|
||||
@@ -251,6 +127,21 @@ public class ItemLore {
|
||||
return null;
|
||||
}
|
||||
container.remove(toolStats.cropsHarvested);
|
||||
// remove the applied token if this stat is disabled
|
||||
if (container.has(toolStats.tokenApplied)) {
|
||||
String appliedTokens = container.get(toolStats.tokenApplied, PersistentDataType.STRING);
|
||||
if (appliedTokens != null) {
|
||||
// remove the token from the list
|
||||
// if the list is empty, remove the PDC
|
||||
// otherwise set the PDC back with the new list
|
||||
List<String> newTokens = toolStats.itemChecker.removeToken(appliedTokens, "crops-mined");
|
||||
if (!newTokens.isEmpty()) {
|
||||
container.set(toolStats.tokenApplied, PersistentDataType.STRING, String.join(",", newTokens));
|
||||
} else {
|
||||
container.remove(toolStats.tokenApplied);
|
||||
}
|
||||
}
|
||||
}
|
||||
if (meta.hasLore()) {
|
||||
String oldCropsMinedFormatted = toolStats.numberFormat.formatInt(cropsMined);
|
||||
Component lineToRemove = toolStats.configTools.formatLore("crops-harvested", "{crops}", oldCropsMinedFormatted);
|
||||
@@ -334,6 +225,21 @@ public class ItemLore {
|
||||
return null;
|
||||
}
|
||||
container.remove(toolStats.blocksMined);
|
||||
// remove the applied token if this stat is disabled
|
||||
if (container.has(toolStats.tokenApplied)) {
|
||||
String appliedTokens = container.get(toolStats.tokenApplied, PersistentDataType.STRING);
|
||||
if (appliedTokens != null) {
|
||||
// remove the token from the list
|
||||
// if the list is empty, remove the PDC
|
||||
// otherwise set the PDC back with the new list
|
||||
List<String> newTokens = toolStats.itemChecker.removeToken(appliedTokens, "blocks-mined");
|
||||
if (!newTokens.isEmpty()) {
|
||||
container.set(toolStats.tokenApplied, PersistentDataType.STRING, String.join(",", newTokens));
|
||||
} else {
|
||||
container.remove(toolStats.tokenApplied);
|
||||
}
|
||||
}
|
||||
}
|
||||
if (meta.hasLore()) {
|
||||
String oldBlocksMinedFormatted = toolStats.numberFormat.formatInt(blocksMined);
|
||||
Component lineToRemove = toolStats.configTools.formatLore("blocks-mined", "{blocks}", oldBlocksMinedFormatted);
|
||||
@@ -418,6 +324,21 @@ public class ItemLore {
|
||||
return null;
|
||||
}
|
||||
container.remove(toolStats.playerKills);
|
||||
// remove the applied token if this stat is disabled
|
||||
if (container.has(toolStats.tokenApplied)) {
|
||||
String appliedTokens = container.get(toolStats.tokenApplied, PersistentDataType.STRING);
|
||||
if (appliedTokens != null) {
|
||||
// remove the token from the list
|
||||
// if the list is empty, remove the PDC
|
||||
// otherwise set the PDC back with the new list
|
||||
List<String> newTokens = toolStats.itemChecker.removeToken(appliedTokens, "player-kills");
|
||||
if (!newTokens.isEmpty()) {
|
||||
container.set(toolStats.tokenApplied, PersistentDataType.STRING, String.join(",", newTokens));
|
||||
} else {
|
||||
container.remove(toolStats.tokenApplied);
|
||||
}
|
||||
}
|
||||
}
|
||||
if (meta.hasLore()) {
|
||||
String oldPlayerKillsFormatted = toolStats.numberFormat.formatInt(playerKills);
|
||||
Component lineToRemove = toolStats.configTools.formatLore("player-kills", "{kills}", oldPlayerKillsFormatted);
|
||||
@@ -501,6 +422,21 @@ public class ItemLore {
|
||||
return null;
|
||||
}
|
||||
container.remove(toolStats.mobKills);
|
||||
// remove the applied token if this stat is disabled
|
||||
if (container.has(toolStats.tokenApplied)) {
|
||||
String appliedTokens = container.get(toolStats.tokenApplied, PersistentDataType.STRING);
|
||||
if (appliedTokens != null) {
|
||||
// remove the token from the list
|
||||
// if the list is empty, remove the PDC
|
||||
// otherwise set the PDC back with the new list
|
||||
List<String> newTokens = toolStats.itemChecker.removeToken(appliedTokens, "mob-kills");
|
||||
if (!newTokens.isEmpty()) {
|
||||
container.set(toolStats.tokenApplied, PersistentDataType.STRING, String.join(",", newTokens));
|
||||
} else {
|
||||
container.remove(toolStats.tokenApplied);
|
||||
}
|
||||
}
|
||||
}
|
||||
if (meta.hasLore()) {
|
||||
String oldMobKillsFormatted = toolStats.numberFormat.formatInt(mobKills);
|
||||
Component lineToRemove = toolStats.configTools.formatLore("mob-kills", "{kills}", oldMobKillsFormatted);
|
||||
@@ -567,7 +503,7 @@ public class ItemLore {
|
||||
* @param damage The amount of damage to apply.
|
||||
* @param bypass Bypass the negative damage check.
|
||||
*/
|
||||
public ItemMeta updateDamage(ItemStack armorPiece, double damage, boolean bypass) {
|
||||
public ItemMeta updateArmorDamage(ItemStack armorPiece, double damage, boolean bypass) {
|
||||
// ignore if the damage is zero or negative
|
||||
if (damage < 0) {
|
||||
if (!bypass) {
|
||||
@@ -592,6 +528,21 @@ public class ItemLore {
|
||||
return null;
|
||||
}
|
||||
container.remove(toolStats.armorDamage);
|
||||
// remove the applied token if this stat is disabled
|
||||
if (container.has(toolStats.tokenApplied)) {
|
||||
String appliedTokens = container.get(toolStats.tokenApplied, PersistentDataType.STRING);
|
||||
if (appliedTokens != null) {
|
||||
// remove the token from the list
|
||||
// if the list is empty, remove the PDC
|
||||
// otherwise set the PDC back with the new list
|
||||
List<String> newTokens = toolStats.itemChecker.removeToken(appliedTokens, "damage-taken");
|
||||
if (!newTokens.isEmpty()) {
|
||||
container.set(toolStats.tokenApplied, PersistentDataType.STRING, String.join(",", newTokens));
|
||||
} else {
|
||||
container.remove(toolStats.tokenApplied);
|
||||
}
|
||||
}
|
||||
}
|
||||
if (meta.hasLore()) {
|
||||
String oldDamageTakenFormatted = toolStats.numberFormat.formatDouble(armorDamage);
|
||||
Component lineToRemove = toolStats.configTools.formatLore("damage-taken", "{damage}", oldDamageTakenFormatted);
|
||||
@@ -651,6 +602,112 @@ public class ItemLore {
|
||||
return meta;
|
||||
}
|
||||
|
||||
/**
|
||||
* Add damage to a weapon.
|
||||
*
|
||||
* @param weapon The weapon to update.
|
||||
* @param damage The amount of damage to apply.
|
||||
* @param bypass Bypass the negative damage check.
|
||||
*/
|
||||
public ItemMeta updateWeaponDamage(ItemStack weapon, double damage, boolean bypass) {
|
||||
// ignore if the damage is zero or negative
|
||||
if (damage < 0) {
|
||||
if (!bypass) {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
ItemStack clone = weapon.clone();
|
||||
ItemMeta meta = clone.getItemMeta();
|
||||
if (meta == null) {
|
||||
toolStats.logger.warning(clone + " does NOT have any meta! Unable to update stats.");
|
||||
return null;
|
||||
}
|
||||
|
||||
PersistentDataContainer container = meta.getPersistentDataContainer();
|
||||
|
||||
// if it's disabled, don't update the stats
|
||||
// check to see if the item has the stats, remove them if it does
|
||||
if (!toolStats.configTools.checkConfig(clone.getType(), "damage-done")) {
|
||||
if (container.has(toolStats.damageDone)) {
|
||||
Double damageDone = container.get(toolStats.damageDone, PersistentDataType.DOUBLE);
|
||||
if (damageDone == null) {
|
||||
return null;
|
||||
}
|
||||
container.remove(toolStats.damageDone);
|
||||
// remove the applied token if this stat is disabled
|
||||
if (container.has(toolStats.tokenApplied)) {
|
||||
String appliedTokens = container.get(toolStats.tokenApplied, PersistentDataType.STRING);
|
||||
if (appliedTokens != null) {
|
||||
// remove the token from the list
|
||||
// if the list is empty, remove the PDC
|
||||
// otherwise set the PDC back with the new list
|
||||
List<String> newTokens = toolStats.itemChecker.removeToken(appliedTokens, "damage-done");
|
||||
if (!newTokens.isEmpty()) {
|
||||
container.set(toolStats.tokenApplied, PersistentDataType.STRING, String.join(",", newTokens));
|
||||
} else {
|
||||
container.remove(toolStats.tokenApplied);
|
||||
}
|
||||
}
|
||||
}
|
||||
if (meta.hasLore()) {
|
||||
String oldDamageDoneFormatted = toolStats.numberFormat.formatDouble(damageDone);
|
||||
Component lineToRemove = toolStats.configTools.formatLore("damage-done", "{damage}", oldDamageDoneFormatted);
|
||||
List<Component> newLore = removeLore(meta.lore(), lineToRemove);
|
||||
meta.lore(newLore);
|
||||
}
|
||||
return meta;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
// check for tokens
|
||||
boolean validToken = toolStats.itemChecker.checkTokens(container, "damage-done");
|
||||
// check for tokens
|
||||
if (toolStats.config.getBoolean("tokens.enabled")) {
|
||||
// if the item has stats but no token, add the token
|
||||
if (container.has(toolStats.damageDone) && !validToken) {
|
||||
String newTokens = toolStats.itemChecker.addTokensToExisting(clone);
|
||||
if (newTokens != null) {
|
||||
container.set(toolStats.tokenApplied, PersistentDataType.STRING, newTokens);
|
||||
}
|
||||
}
|
||||
|
||||
// the item does not have a valid token
|
||||
if (!validToken) {
|
||||
return null;
|
||||
}
|
||||
} else {
|
||||
if (!validToken) {
|
||||
String newTokens = toolStats.itemChecker.addTokensToExisting(clone);
|
||||
if (newTokens != null) {
|
||||
container.set(toolStats.tokenApplied, PersistentDataType.STRING, newTokens);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Double damageDone = 0.0;
|
||||
if (container.has(toolStats.damageDone, PersistentDataType.DOUBLE)) {
|
||||
damageDone = container.get(toolStats.damageDone, PersistentDataType.DOUBLE);
|
||||
}
|
||||
|
||||
if (damageDone == null) {
|
||||
damageDone = 0.0;
|
||||
toolStats.logger.warning(clone + " does not have valid damage-done set! Resting to zero. This should NEVER happen.");
|
||||
}
|
||||
|
||||
container.set(toolStats.damageDone, PersistentDataType.DOUBLE, damageDone + damage);
|
||||
String oldDamageFormatted = toolStats.numberFormat.formatDouble(damageDone);
|
||||
String newDamageFormatted = toolStats.numberFormat.formatDouble(damageDone + damage);
|
||||
Component oldLine = toolStats.configTools.formatLore("damage-done", "{damage}", oldDamageFormatted);
|
||||
Component newLine = toolStats.configTools.formatLore("damage-done", "{damage}", newDamageFormatted);
|
||||
if (oldLine == null || newLine == null) {
|
||||
return null;
|
||||
}
|
||||
List<Component> newLore = toolStats.itemLore.updateItemLore(meta, oldLine, newLine);
|
||||
meta.lore(newLore);
|
||||
return meta;
|
||||
}
|
||||
|
||||
/**
|
||||
* Add flight time to an elytra.
|
||||
*
|
||||
@@ -675,9 +732,32 @@ public class ItemLore {
|
||||
return null;
|
||||
}
|
||||
container.remove(toolStats.flightTime);
|
||||
// remove the applied token if this stat is disabled
|
||||
if (container.has(toolStats.tokenApplied)) {
|
||||
String appliedTokens = container.get(toolStats.tokenApplied, PersistentDataType.STRING);
|
||||
if (appliedTokens != null) {
|
||||
// remove the token from the list
|
||||
// if the list is empty, remove the PDC
|
||||
// otherwise set the PDC back with the new list
|
||||
List<String> newTokens = toolStats.itemChecker.removeToken(appliedTokens, "flight-time");
|
||||
if (!newTokens.isEmpty()) {
|
||||
container.set(toolStats.tokenApplied, PersistentDataType.STRING, String.join(",", newTokens));
|
||||
} else {
|
||||
container.remove(toolStats.tokenApplied);
|
||||
}
|
||||
}
|
||||
}
|
||||
if (meta.hasLore()) {
|
||||
String oldFlightTimeFormatted = toolStats.numberFormat.formatDouble(flightTime);
|
||||
Component lineToRemove = toolStats.configTools.formatLore("flight-time", "{time}", oldFlightTimeFormatted);
|
||||
// if the old format is in the config, check to see if the old format is on the elytra
|
||||
if (toolStats.config.getString("messages.flight-time-old") != null) {
|
||||
String oldFormatFormatted = toolStats.numberFormat.formatDouble((double) flightTime / 1000);
|
||||
Component oldFormat = toolStats.configTools.formatLore("flight-time-old", "{time}", oldFormatFormatted);
|
||||
List<Component> newLore = removeLore(meta.lore(), oldFormat);
|
||||
meta.lore(newLore);
|
||||
}
|
||||
|
||||
Map<String, String> oldFlightTimeFormatted = toolStats.numberFormat.formatTime(flightTime);
|
||||
Component lineToRemove = toolStats.configTools.formatLoreMultiplePlaceholders("flight-time", oldFlightTimeFormatted);
|
||||
List<Component> newLore = removeLore(meta.lore(), lineToRemove);
|
||||
meta.lore(newLore);
|
||||
}
|
||||
@@ -724,10 +804,18 @@ public class ItemLore {
|
||||
}
|
||||
|
||||
container.set(toolStats.flightTime, PersistentDataType.LONG, flightTime + duration);
|
||||
String oldFlightFormatted = toolStats.numberFormat.formatDouble((double) flightTime / 1000);
|
||||
String newFlightFormatted = toolStats.numberFormat.formatDouble((double) (flightTime + duration) / 1000);
|
||||
Component oldLine = toolStats.configTools.formatLore("flight-time", "{time}", oldFlightFormatted);
|
||||
Component newLine = toolStats.configTools.formatLore("flight-time", "{time}", newFlightFormatted);
|
||||
Map<String, String> oldFlightFormatted = toolStats.numberFormat.formatTime(flightTime);
|
||||
Map<String, String> newFlightFormatted = toolStats.numberFormat.formatTime(flightTime + duration);
|
||||
// if the old format is in the config, check to see if the old format is on the elytra
|
||||
if (toolStats.config.getString("messages.flight-time-old") != null) {
|
||||
if (meta.hasLore()) {
|
||||
String oldFormatFormatted = toolStats.numberFormat.formatDouble((double) flightTime / 1000);
|
||||
Component oldFormat = toolStats.configTools.formatLore("flight-time-old", "{time}", oldFormatFormatted);
|
||||
meta.lore(removeLore(meta.lore(), oldFormat));
|
||||
}
|
||||
}
|
||||
Component oldLine = toolStats.configTools.formatLoreMultiplePlaceholders("flight-time", oldFlightFormatted);
|
||||
Component newLine = toolStats.configTools.formatLoreMultiplePlaceholders("flight-time", newFlightFormatted);
|
||||
if (oldLine == null || newLine == null) {
|
||||
return null;
|
||||
}
|
||||
@@ -760,6 +848,21 @@ public class ItemLore {
|
||||
return null;
|
||||
}
|
||||
container.remove(toolStats.sheepSheared);
|
||||
// remove the applied token if this stat is disabled
|
||||
if (container.has(toolStats.tokenApplied)) {
|
||||
String appliedTokens = container.get(toolStats.tokenApplied, PersistentDataType.STRING);
|
||||
if (appliedTokens != null) {
|
||||
// remove the token from the list
|
||||
// if the list is empty, remove the PDC
|
||||
// otherwise set the PDC back with the new list
|
||||
List<String> newTokens = toolStats.itemChecker.removeToken(appliedTokens, "sheep-sheared");
|
||||
if (!newTokens.isEmpty()) {
|
||||
container.set(toolStats.tokenApplied, PersistentDataType.STRING, String.join(",", newTokens));
|
||||
} else {
|
||||
container.remove(toolStats.tokenApplied);
|
||||
}
|
||||
}
|
||||
}
|
||||
if (meta.hasLore()) {
|
||||
String oldSheepShearedFormatted = toolStats.numberFormat.formatDouble(sheepSheared);
|
||||
Component lineToRemove = toolStats.configTools.formatLore("sheep-sheared", "{sheep}", oldSheepShearedFormatted);
|
||||
@@ -843,6 +946,21 @@ public class ItemLore {
|
||||
return null;
|
||||
}
|
||||
container.remove(toolStats.arrowsShot);
|
||||
// remove the applied token if this stat is disabled
|
||||
if (container.has(toolStats.tokenApplied)) {
|
||||
String appliedTokens = container.get(toolStats.tokenApplied, PersistentDataType.STRING);
|
||||
if (appliedTokens != null) {
|
||||
// remove the token from the list
|
||||
// if the list is empty, remove the PDC
|
||||
// otherwise set the PDC back with the new list
|
||||
List<String> newTokens = toolStats.itemChecker.removeToken(appliedTokens, "arrows-shot");
|
||||
if (!newTokens.isEmpty()) {
|
||||
container.set(toolStats.tokenApplied, PersistentDataType.STRING, String.join(",", newTokens));
|
||||
} else {
|
||||
container.remove(toolStats.tokenApplied);
|
||||
}
|
||||
}
|
||||
}
|
||||
if (meta.hasLore()) {
|
||||
String oldArrowsShotFormatted = toolStats.numberFormat.formatDouble(arrowsShot);
|
||||
Component lineToRemove = toolStats.configTools.formatLore("arrows-shot", "{arrows}", oldArrowsShotFormatted);
|
||||
@@ -928,6 +1046,21 @@ public class ItemLore {
|
||||
return null;
|
||||
}
|
||||
container.remove(toolStats.fishCaught);
|
||||
// remove the applied token if this stat is disabled
|
||||
if (container.has(toolStats.tokenApplied)) {
|
||||
String appliedTokens = container.get(toolStats.tokenApplied, PersistentDataType.STRING);
|
||||
if (appliedTokens != null) {
|
||||
// remove the token from the list
|
||||
// if the list is empty, remove the PDC
|
||||
// otherwise set the PDC back with the new list
|
||||
List<String> newTokens = toolStats.itemChecker.removeToken(appliedTokens, "fish-caught");
|
||||
if (!newTokens.isEmpty()) {
|
||||
container.set(toolStats.tokenApplied, PersistentDataType.STRING, String.join(",", newTokens));
|
||||
} else {
|
||||
container.remove(toolStats.tokenApplied);
|
||||
}
|
||||
}
|
||||
}
|
||||
if (meta.hasLore()) {
|
||||
String oldFishCaught = toolStats.numberFormat.formatDouble(fishCaught);
|
||||
Component lineToRemove = toolStats.configTools.formatLore("fished.fish-caught", "{fish}", oldFishCaught);
|
||||
|
||||
@@ -22,8 +22,14 @@ import lol.hyper.toolstats.ToolStats;
|
||||
import java.text.DecimalFormat;
|
||||
import java.text.DecimalFormatSymbols;
|
||||
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.HashMap;
|
||||
import java.util.Locale;
|
||||
import java.util.Map;
|
||||
|
||||
public class NumberFormat {
|
||||
|
||||
@@ -33,6 +39,7 @@ public class NumberFormat {
|
||||
|
||||
/**
|
||||
* Utility class to format different numbers
|
||||
*
|
||||
* @param toolStats Plugin instance.
|
||||
*/
|
||||
public NumberFormat(ToolStats toolStats) {
|
||||
@@ -136,4 +143,69 @@ public class NumberFormat {
|
||||
public String formatDate(Date 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());
|
||||
}
|
||||
}
|
||||
|
||||
@@ -86,6 +86,13 @@ public class TokenCrafting {
|
||||
armorDamageRecipe.setIngredient('C', Material.LEATHER_CHESTPLATE);
|
||||
recipes.add(armorDamageRecipe);
|
||||
|
||||
NamespacedKey damageDoneKey = new NamespacedKey(toolStats, "damage-done-token");
|
||||
ShapedRecipe damageDoneRecipe = new ShapedRecipe(damageDoneKey, toolStats.tokenItems.damageDone());
|
||||
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, toolStats.tokenItems.arrowsShot());
|
||||
arrowsShotRecipe.shape(" P ", "PAP", " P ");
|
||||
@@ -106,9 +113,16 @@ public class TokenCrafting {
|
||||
resetRecipe.setIngredient('P', Material.PAPER);
|
||||
recipes.add(resetRecipe);
|
||||
|
||||
NamespacedKey removeKey = new NamespacedKey(toolStats, "remove-token");
|
||||
ShapedRecipe removeRecipe = new ShapedRecipe(removeKey, toolStats.tokenItems.removeToken());
|
||||
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");
|
||||
@@ -116,6 +130,7 @@ public class TokenCrafting {
|
||||
tokenTypes.add("flight-time");
|
||||
tokenTypes.add("fish-caught");
|
||||
tokenTypes.add("reset");
|
||||
tokenTypes.add("remove");
|
||||
}
|
||||
|
||||
public Set<ShapedRecipe> getRecipes() {
|
||||
|
||||
@@ -27,6 +27,7 @@ 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;
|
||||
|
||||
@@ -48,6 +49,11 @@ public class ConfigTools {
|
||||
* @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.warning("Missing config section for enabled" + configName);
|
||||
return false;
|
||||
}
|
||||
|
||||
String itemName = material.toString().toLowerCase();
|
||||
String itemType = null;
|
||||
// hardcode these
|
||||
@@ -74,7 +80,6 @@ public class ConfigTools {
|
||||
} 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");
|
||||
@@ -133,6 +138,65 @@ public class ConfigTools {
|
||||
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.warning("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();
|
||||
|
||||
// if we match the old color codes, then format them as so
|
||||
Matcher hexMatcher = CONFIG_HEX_PATTERN.matcher(outputText);
|
||||
Matcher colorMatcher = COLOR_CODES.matcher(outputText);
|
||||
if (hexMatcher.find() || colorMatcher.find()) {
|
||||
component = LegacyComponentSerializer.legacyAmpersand().deserialize(outputText);
|
||||
} else {
|
||||
// otherwise format them normally
|
||||
component = MiniMessage.miniMessage().deserialize(outputText);
|
||||
}
|
||||
|
||||
return component.decorationIfAbsent(TextDecoration.ITALIC, TextDecoration.State.FALSE);
|
||||
}
|
||||
|
||||
/**
|
||||
* Format a string from the config.
|
||||
*
|
||||
|
||||
@@ -56,5 +56,15 @@ public class ConfigUpdater {
|
||||
Version10 version10 = new Version10(toolStats);
|
||||
version10.update();
|
||||
}
|
||||
// Version 10 to 11
|
||||
if (version == 10) {
|
||||
Version11 version11 = new Version11(toolStats);
|
||||
version11.update();
|
||||
}
|
||||
// Version 11 to 12
|
||||
if (version == 11) {
|
||||
Version12 version12 = new Version12(toolStats);
|
||||
version12.update();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -25,7 +25,6 @@ import org.bukkit.inventory.meta.ItemMeta;
|
||||
import org.bukkit.persistence.PersistentDataContainer;
|
||||
import org.bukkit.persistence.PersistentDataType;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
public class TokenItems {
|
||||
@@ -162,6 +161,24 @@ public class TokenItems {
|
||||
return token;
|
||||
}
|
||||
|
||||
public ItemStack damageDone() {
|
||||
// set up the item
|
||||
ItemStack token = new ItemStack(Material.PAPER);
|
||||
ItemMeta tokenMeta = token.getItemMeta();
|
||||
PersistentDataContainer tokenData = tokenMeta.getPersistentDataContainer();
|
||||
|
||||
// set the title and lore
|
||||
Component title = toolStats.configTools.format("tokens.data.damage-done.title");
|
||||
List<Component> lore = toolStats.configTools.getTokenLore("damage-done");
|
||||
tokenMeta.displayName(title);
|
||||
tokenMeta.lore(lore);
|
||||
|
||||
// set the PDC
|
||||
tokenData.set(toolStats.tokenType, PersistentDataType.STRING, "damage-done");
|
||||
token.setItemMeta(tokenMeta);
|
||||
return token;
|
||||
}
|
||||
|
||||
public ItemStack arrowsShot() {
|
||||
// set up the item
|
||||
ItemStack token = new ItemStack(Material.PAPER);
|
||||
@@ -215,4 +232,22 @@ public class TokenItems {
|
||||
token.setItemMeta(tokenMeta);
|
||||
return token;
|
||||
}
|
||||
|
||||
public ItemStack removeToken() {
|
||||
// set up the item
|
||||
ItemStack token = new ItemStack(Material.PAPER);
|
||||
ItemMeta tokenMeta = token.getItemMeta();
|
||||
PersistentDataContainer tokenData = tokenMeta.getPersistentDataContainer();
|
||||
|
||||
// set the title and lore
|
||||
Component title = toolStats.configTools.format("tokens.data.remove.title");
|
||||
List<Component> lore = toolStats.configTools.getTokenLore("remove");
|
||||
tokenMeta.displayName(title);
|
||||
tokenMeta.lore(lore);
|
||||
|
||||
// set the PDC
|
||||
tokenData.set(toolStats.tokenType, PersistentDataType.STRING, "remove");
|
||||
token.setItemMeta(tokenMeta);
|
||||
return token;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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.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.severe("Unable to save config-10.yml!");
|
||||
throw new RuntimeException(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.severe("Unable to save config.yml!");
|
||||
throw new RuntimeException(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,122 @@
|
||||
/*
|
||||
* 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 it.unimi.dsi.fastutil.Pair;
|
||||
import lol.hyper.toolstats.ToolStats;
|
||||
import org.bukkit.configuration.Configuration;
|
||||
import org.bukkit.configuration.ConfigurationSection;
|
||||
import org.bukkit.configuration.file.FileConfiguration;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.util.ArrayDeque;
|
||||
import java.util.Deque;
|
||||
|
||||
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.severe("Unable to save config-11.yml!");
|
||||
throw new RuntimeException(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.severe("Unable to save config.yml!");
|
||||
throw new RuntimeException(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 " + oldSection + " to " + newSection);
|
||||
ConfigurationSection old = toolStats.config.getConfigurationSection(oldSection);
|
||||
toolStats.config.set(newSection, old);
|
||||
}
|
||||
}
|
||||
@@ -39,6 +39,11 @@ tokens:
|
||||
lore:
|
||||
- "&8Combine with an armor piece in an anvil to track damage taken."
|
||||
levels: 1
|
||||
damage-done:
|
||||
title: "&7ToolStats: &8Damage Done Token"
|
||||
lore:
|
||||
- "&8Combine with a melee or ranged weapon in an anvil to track damage done."
|
||||
levels: 1
|
||||
arrows-shot:
|
||||
title: "&7ToolStats: &8Arrows Shot Token"
|
||||
lore:
|
||||
@@ -54,10 +59,15 @@ tokens:
|
||||
lore:
|
||||
- "&8Combine in an anvil with to reset ALL stats for this item. Tokens on this item stay."
|
||||
levels: 1
|
||||
remove:
|
||||
title: "&7ToolStats: &8Remove Token"
|
||||
lore:
|
||||
- "&8Combine in an anvil with to REMOVE ALL stats and tokens for this item."
|
||||
levels: 1
|
||||
|
||||
enabled:
|
||||
# Will show ownership of items when they are created/found.
|
||||
created-by:
|
||||
# Will show "Crafted by <player>"
|
||||
crafted-by:
|
||||
pickaxe: true
|
||||
sword: true
|
||||
shovel: true
|
||||
@@ -68,8 +78,8 @@ enabled:
|
||||
armor: true
|
||||
mace: true
|
||||
fishing-rod: true
|
||||
# Will show time the item is created
|
||||
created-date:
|
||||
# Will show "Crafted on <date>"
|
||||
crafted-on:
|
||||
pickaxe: true
|
||||
sword: true
|
||||
shovel: true
|
||||
@@ -81,7 +91,18 @@ enabled:
|
||||
mace: true
|
||||
fishing-rod: true
|
||||
# Will show "Fished by <player>"
|
||||
fished-tag:
|
||||
fished-by:
|
||||
pickaxe: true
|
||||
sword: true
|
||||
shovel: true
|
||||
axe: true
|
||||
hoe: true
|
||||
shears: true
|
||||
bow: true
|
||||
armor: true
|
||||
fishing-rod: true
|
||||
# Will show "Fished on <date>"
|
||||
fished-on:
|
||||
pickaxe: true
|
||||
sword: true
|
||||
shovel: true
|
||||
@@ -92,7 +113,7 @@ enabled:
|
||||
armor: true
|
||||
fishing-rod: true
|
||||
# Will show "Found by <player>"
|
||||
looted-tag:
|
||||
looted-by:
|
||||
pickaxe: true
|
||||
sword: true
|
||||
shovel: true
|
||||
@@ -102,8 +123,8 @@ enabled:
|
||||
bow: true
|
||||
armor: true
|
||||
fishing-rod: true
|
||||
# Will show "Trade by <player>"
|
||||
traded-tag:
|
||||
# Will show "Found on <date>"
|
||||
looted-on:
|
||||
pickaxe: true
|
||||
sword: true
|
||||
shovel: true
|
||||
@@ -113,6 +134,34 @@ enabled:
|
||||
bow: 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:
|
||||
sword: true
|
||||
axe: true
|
||||
@@ -132,7 +181,19 @@ enabled:
|
||||
hoe: true
|
||||
shears: true
|
||||
# Will show "Spawned in by <player>"
|
||||
spawned-in:
|
||||
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
|
||||
@@ -147,15 +208,16 @@ enabled:
|
||||
sheep-sheared: true
|
||||
armor-damage: true
|
||||
dropped-by: true
|
||||
dropped-on: true
|
||||
elytra-tag: true
|
||||
arrows-shot: true
|
||||
flight-time: true
|
||||
crops-harvested: true
|
||||
|
||||
messages:
|
||||
created:
|
||||
created-by: "&7Crafted by: &8{player}"
|
||||
created-on: "&7Crafted on: &8{date}"
|
||||
crafted:
|
||||
crafted-by: "&7Crafted by: &8{player}"
|
||||
crafted-on: "&7Crafted on: &8{date}"
|
||||
fished:
|
||||
caught-by: "&7Caught by: &8{player}"
|
||||
caught-on: "&7Caught on: &8{date}"
|
||||
@@ -177,10 +239,12 @@ messages:
|
||||
blocks-mined: "&7Blocks mined: &8{blocks}"
|
||||
crops-harvested: "&7Crops harvested: &8{crops}"
|
||||
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}"
|
||||
arrows-shot: "&7Arrows shot: &8{arrows}"
|
||||
flight-time: "&7Flight time: &8{time}"
|
||||
flight-time: "&7Flight time: &8{years}y {months}m {days}d {hours}h {minutes}m {seconds}s"
|
||||
damage-done: "&7Damage done: &8{damage}"
|
||||
# Set display name for mobs. See: https://hub.spigotmc.org/javadocs/bukkit/org/bukkit/entity/EntityType.html
|
||||
mobs:
|
||||
ZOMBIE: "Zombie"
|
||||
@@ -203,4 +267,11 @@ number-formats:
|
||||
# This has no use currently, but can be used for future features for dupe detection.
|
||||
generate-hash-for-items: false
|
||||
|
||||
config-version: 10
|
||||
# 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: 12
|
||||
@@ -25,4 +25,10 @@ permissions:
|
||||
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
|
||||
Reference in New Issue
Block a user