v2.0.0-SNAPSHOT - Time for a revamp.

Now under GNU GENERAL PUBLIC LICENSE
This commit is contained in:
RealizedMC committed 2016-10-19 23:15:28 -07:00
1 parent b5dd29631c
commit e1e57f6ca9
66 files changed
+2991 -1149

No files matched your search

+2 -1
View File
@@ -3,4 +3,5 @@
.idea/
*.iml
target/
/jars
/jars
/*.yml
+674
View File
@@ -0,0 +1,674 @@
GNU GENERAL PUBLIC LICENSE
Version 3, 29 June 2007
Copyright (C) 2007 Free Software Foundation, Inc. <http://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 <http://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
<http://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
<http://www.gnu.org/philosophy/why-not-lgpl.html>.
+15 -1
View File
@@ -5,11 +5,12 @@
<modelVersion>4.0.0</modelVersion>
<groupId>me.realized</groupId>
<artifactId>duels</artifactId>
<version>1.3.4</version>
<version>2.0.0-SNAPSHOT</version>
<name>Duels</name>
<description>Everything you need for duels.</description>
<build>
<finalName>Duels</finalName>
<sourceDirectory>src/main/java</sourceDirectory>
<resources>
<resource>
@@ -43,6 +44,7 @@
<artifactSet>
<includes>
<include>me.realized.duels**</include>
<include>com.google.gson**</include>
</includes>
</artifactSet>
</configuration>
@@ -92,5 +94,17 @@
<version>2.0.1</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>com.massivecraft</groupId>
<artifactId>Factions</artifactId>
<version>1.6.9.5-U0.1.14</version>
<scope>provided</scope>
<exclusions>
<exclusion>
<groupId>mkremins</groupId>
<artifactId>fanciful</artifactId>
</exclusion>
</exclusions>
</dependency>
</dependencies>
</project>
+48 -17
View File
@@ -6,19 +6,25 @@ import me.realized.duels.arena.ArenaManager;
import me.realized.duels.commands.BaseCommand;
import me.realized.duels.commands.admin.DuelsCommand;
import me.realized.duels.commands.duel.DuelCommand;
import me.realized.duels.commands.other.SpectateCommand;
import me.realized.duels.commands.other.StatsCommand;
import me.realized.duels.commands.other.ToggleCommand;
import me.realized.duels.configuration.Config;
import me.realized.duels.configuration.ConfigManager;
import me.realized.duels.configuration.ConfigType;
import me.realized.duels.configuration.MainConfig;
import me.realized.duels.configuration.MessagesConfig;
import me.realized.duels.data.DataManager;
import me.realized.duels.dueling.DuelManager;
import me.realized.duels.dueling.RequestManager;
import me.realized.duels.gui.GUIManager;
import me.realized.duels.hooks.EssentialsHook;
import me.realized.duels.hooks.HookManager;
import me.realized.duels.hooks.WorldGuardHook;
import me.realized.duels.dueling.SpectatorManager;
import me.realized.duels.hooks.*;
import me.realized.duels.kits.KitManager;
import me.realized.duels.utilities.ICanHandleReload;
import me.realized.duels.utilities.ReloadType;
import me.realized.duels.utilities.gui.GUIManager;
import org.bukkit.plugin.java.JavaPlugin;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
@@ -26,38 +32,57 @@ public class Core extends JavaPlugin {
private final Gson gson = new GsonBuilder().setPrettyPrinting().create();
private Config config;
private ConfigManager configManager;
private HookManager hookManager;
private RequestManager requestManager;
private GUIManager guiManager;
private DuelManager duelManager;
private DataManager dataManager;
private ArenaManager arenaManager;
private RequestManager requestManager;
private SpectatorManager spectatorManager;
private KitManager kitManager;
private DuelManager duelManager;
private final List<ICanHandleReload> reloadables = new ArrayList<>();
@Override
public void onEnable() {
config = new Config(this);
configManager = new ConfigManager();
configManager.register(ConfigType.MAIN, new MainConfig(this));
configManager.register(ConfigType.MESSAGES, new MessagesConfig(this));
reloadables.add(configManager);
hookManager = new HookManager();
hookManager.register("Factions", new FactionsHook(this));
hookManager.register("WorldGuard", new WorldGuardHook(this));
hookManager.register("Essentials", new EssentialsHook(this));
hookManager.register("mcMMO", new McMMOHook(this));
requestManager = new RequestManager();
reloadables.add(requestManager);
guiManager = new GUIManager(this);
dataManager = new DataManager(this);
dataManager.load();
reloadables.add(dataManager);
arenaManager = new ArenaManager(this);
arenaManager.load();
reloadables.add(arenaManager);
spectatorManager = new SpectatorManager(this);
kitManager = new KitManager(this);
kitManager.load();
reloadables.add(kitManager);
duelManager = new DuelManager(this);
registerCommands();
List<BaseCommand> commands = Arrays.asList(new StatsCommand(), new DuelsCommand(), new ToggleCommand(), new DuelCommand(), new SpectateCommand());
for (BaseCommand command : commands) {
getCommand(command.getName()).setExecutor(command);
}
}
@Override
@@ -67,11 +92,9 @@ public class Core extends JavaPlugin {
kitManager.save();
}
private void registerCommands() {
List<BaseCommand> commands = Arrays.asList(new StatsCommand(), new DuelsCommand(), new ToggleCommand(), new DuelCommand());
for (BaseCommand command : commands) {
command.register();
public void reload(ReloadType type) {
for (ICanHandleReload reloadable : reloadables) {
reloadable.handleReload(type);
}
}
@@ -87,8 +110,12 @@ public class Core extends JavaPlugin {
return gson;
}
public Config getConfiguration() {
return config;
public MainConfig getConfiguration() {
return (MainConfig) configManager.getConfigByType(ConfigType.MAIN);
}
public ConfigManager getConfigManager() {
return configManager;
}
public HookManager getHookManager() {
@@ -107,6 +134,10 @@ public class Core extends JavaPlugin {
return arenaManager;
}
public SpectatorManager getSpectatorManager() {
return spectatorManager;
}
public RequestManager getRequestManager() {
return requestManager;
}
@@ -23,7 +23,7 @@ public class DuelsAPI {
*
* @param force - Should we force the load from the files?
*
* @return UserData
* @return UserData of the player if exists or null.
*/
public static UserData getUser(UUID uuid, boolean force) {
return instance.getDataManager().getUser(uuid, force);
@@ -32,9 +32,9 @@ public class DuelsAPI {
/**
* @param player - player to get userdata.
*
* @param force - Should we force the load from the files?
* @param force - Force the load from the files if not in cache?
*
* @return UserData
* @return UserData of the player if exists or null.
*/
public static UserData getUser(Player player, boolean force) {
return instance.getDataManager().getUser(player.getUniqueId(), force);
@@ -44,9 +44,16 @@ public class DuelsAPI {
*
* @param player - player to check if in match.
*
* @return boolean
* @return whether player is in match or not.
*/
public static boolean isInMatch(Player player) {
return instance.getArenaManager().isInMatch(player);
}
/**
* @return version of the plugin.
*/
public static String getVersion() {
return instance.getDescription().getVersion();
}
}
@@ -1,9 +1,11 @@
package me.realized.duels.arena;
import me.realized.duels.Core;
import me.realized.duels.configuration.Config;
import me.realized.duels.gui.ICanHandleGUI;
import me.realized.duels.configuration.ConfigManager;
import me.realized.duels.configuration.ConfigType;
import me.realized.duels.configuration.MainConfig;
import me.realized.duels.utilities.Helper;
import me.realized.duels.utilities.gui.ICanHandleGUI;
import me.realized.duels.utilities.inventory.ItemBuilder;
import org.bukkit.Bukkit;
import org.bukkit.Location;
@@ -27,10 +29,12 @@ public class Arena implements ICanHandleGUI {
private Match current;
private ItemStack displayed;
private final MainConfig config = (MainConfig) ConfigManager.getConfig(ConfigType.MAIN);
public Arena(String name, boolean disabled) {
this.name = name;
this.disabled = disabled;
this.displayed = ItemBuilder.builder().type(Material.MAP).name(Helper.color(Config.getInstance().getAvailableArenaDisplayName()).replace("{NAME}", name)).build();
this.displayed = ItemBuilder.builder().type(Material.MAP).name(Helper.color(config.getGuiAvailableArenaDisplayname()).replace("{NAME}", name)).build();
}
public String getName() {
@@ -41,21 +45,15 @@ public class Arena implements ICanHandleGUI {
return counting;
}
private void setCounting(boolean b) {
this.counting = b;
}
public void startCountdown() {
Config config = Config.getInstance();
if (!config.isCdEnabled()) {
if (!config.isCountdownEnabled()) {
return;
}
List<String> messages = config.getCdMessages();
List<String> messages = config.getCountdownMessages();
if (!messages.isEmpty()) {
new CountdownTask(this, messages).runTaskTimer(Core.getInstance(), 0L, 20L);
new CountdownTask(messages).runTaskTimer(Core.getInstance(), 0L, 20L);
}
}
@@ -69,15 +67,13 @@ public class Arena implements ICanHandleGUI {
ItemMeta meta = displayed.getItemMeta();
if (!used) {
this.players.clear();
this.current = null;
this.counting = false; // Just in case!
meta.setDisplayName(Helper.color(Config.getInstance().getAvailableArenaDisplayName()).replace("{NAME}", name));
players.clear();
current = null;
counting = false;
meta.setDisplayName(Helper.color(config.getGuiAvailableArenaDisplayname()).replace("{NAME}", name));
} else {
this.current = new Match();
meta.setDisplayName(Helper.color(Config.getInstance().getInUseArenaDisplayName()).replace("{NAME}", name));
current = new Match();
meta.setDisplayName(Helper.color(config.getGuiInUseArenaDisplayname()).replace("{NAME}", name));
}
displayed.setItemMeta(meta);
@@ -98,8 +94,7 @@ public class Arena implements ICanHandleGUI {
public boolean isValid() {
Location pos1 = positions.get(1);
Location pos2 = positions.get(2);
return !(pos1 == null || pos2 == null) && !(pos1.getWorld() == null || pos2.getWorld() == null || !pos1.getWorld().getName().equals(pos2.getWorld().getName()));
return !(pos1 == null || pos2 == null || pos1.getWorld() == null || pos2.getWorld() == null || !pos1.getWorld().getName().equals(pos2.getWorld().getName()));
}
public List<UUID> getPlayers() {
@@ -112,6 +107,10 @@ public class Arena implements ICanHandleGUI {
}
}
public boolean hasPlayer(Player player) {
return players.contains(player.getUniqueId());
}
public void removePlayer(UUID uuid) {
players.remove(uuid);
}
@@ -162,12 +161,12 @@ public class Arena implements ICanHandleGUI {
return result;
}
public void sendMessage(String msg) {
public void broadcast(String msg) {
for (UUID uuid : players) {
Player player = Bukkit.getPlayer(uuid);
if (player != null) {
Helper.pm(msg, player);
Helper.pm(player, msg, false);
}
}
}
@@ -191,10 +190,14 @@ public class Arena implements ICanHandleGUI {
private long end;
private double finishingHealth;
public Match() {
Match() {
this.start = System.currentTimeMillis();
}
public long getStart() {
return start;
}
public int getDuration() {
return (int) (end - start);
}
@@ -232,7 +235,7 @@ public class Arena implements ICanHandleGUI {
private final ItemStack[] armor;
private final ItemStack[] inventory;
public InventoryData(ItemStack[] inventory, ItemStack[] armor) {
InventoryData(ItemStack[] inventory, ItemStack[] armor) {
this.inventory = inventory;
this.armor = armor;
}
@@ -248,24 +251,22 @@ public class Arena implements ICanHandleGUI {
class CountdownTask extends BukkitRunnable {
private final Arena arena;
private final List<String> messages;
private int index = 0;
public CountdownTask(Arena arena, List<String> messages) {
this.arena = arena;
CountdownTask(List<String> messages) {
this.messages = messages;
arena.setCounting(true);
counting = true;
}
@Override
public void run() {
arena.sendMessage(messages.get(index));
broadcast(messages.get(index));
index++;
if (index > messages.size() - 1) {
arena.setCounting(false);
if (index >= messages.size()) {
counting = false;
cancel();
}
}
@@ -2,15 +2,18 @@ package me.realized.duels.arena;
import com.google.gson.reflect.TypeToken;
import me.realized.duels.Core;
import me.realized.duels.configuration.Config;
import me.realized.duels.configuration.MainConfig;
import me.realized.duels.data.ArenaData;
import me.realized.duels.data.DataManager;
import me.realized.duels.dueling.RequestManager;
import me.realized.duels.dueling.Settings;
import me.realized.duels.event.RequestSendEvent;
import me.realized.duels.gui.GUI;
import me.realized.duels.utilities.Helper;
import me.realized.duels.utilities.Metadata;
import me.realized.duels.utilities.ICanHandleReload;
import me.realized.duels.utilities.ReloadType;
import me.realized.duels.utilities.compat.CompatHelper;
import me.realized.duels.utilities.gui.GUI;
import me.realized.duels.utilities.gui.GUIListener;
import org.bukkit.Bukkit;
import org.bukkit.ChatColor;
import org.bukkit.Location;
@@ -23,19 +26,18 @@ import org.bukkit.event.entity.EntityDamageByEntityEvent;
import org.bukkit.event.entity.ProjectileLaunchEvent;
import org.bukkit.event.inventory.InventoryClickEvent;
import org.bukkit.event.inventory.InventoryCloseEvent;
import org.bukkit.event.player.PlayerInteractEvent;
import org.bukkit.inventory.Inventory;
import org.bukkit.inventory.ItemStack;
import org.bukkit.scheduler.BukkitTask;
import java.io.*;
import java.util.ArrayList;
import java.util.List;
import java.util.Random;
import java.util.UUID;
import java.util.*;
public class ArenaManager implements Listener {
public class ArenaManager implements Listener, ICanHandleReload {
private final Core instance;
private final Config config;
private final MainConfig config;
private final RequestManager requestManager;
private final DataManager dataManager;
private final File base;
@@ -44,6 +46,8 @@ public class ArenaManager implements Listener {
private List<Arena> arenas = new ArrayList<>();
private GUI<Arena> gui;
private BukkitTask task;
public ArenaManager(Core instance) {
this.instance = instance;
this.config = instance.getConfiguration();
@@ -81,8 +85,8 @@ public class ArenaManager implements Listener {
instance.warn("Failed to load arenas from the file! (" + ex.getMessage() + ")");
}
if (config.isAllowArenaSelecting()) {
gui = new GUI<>("Arena Selection", arenas, config.arenaSelectorRows(), new GUI.ClickListener() {
if (config.isDuelingAllowArenaSelecting()) {
gui = new GUI<>("Arena Selection", arenas, config.getGuiArenaSelectorRows(), new GUIListener() {
@Override
public void onClick(InventoryClickEvent event) {
Player player = (Player) event.getWhoClicked();
@@ -104,13 +108,13 @@ public class ArenaManager implements Listener {
if (target == null) {
player.closeInventory();
Helper.pm("&cThat player is no longer online.", player);
Helper.pm(player, "Errors.player-left", true);
return;
}
if (isInMatch(target)) {
player.closeInventory();
Helper.pm("&cThat player is already in a match.", player);
Helper.pm(player, "Errors.already-in-match.target", true);
return;
}
@@ -123,8 +127,8 @@ public class ArenaManager implements Listener {
settings.setArena(arena.getName());
requestManager.sendRequestTo(player, target, settings);
player.closeInventory();
Helper.pm(config.getString("on-request-send").replace("{PLAYER}", target.getName()).replace("{KIT}", settings.getKit()).replace("{ARENA}", settings.getArena()), player);
Helper.pm(config.getString("on-request-receive").replace("{PLAYER}", player.getName()).replace("{KIT}", settings.getKit()).replace("{ARENA}", settings.getArena()), target);
Helper.pm(player, "Dueling.on-request-send.sender", true, "{PLAYER}", target.getName(), "{KIT}", settings.getKit(), "{ARENA}", settings.getArena());
Helper.pm(target, "Dueling.on-request-send.receiver", true, "{PLAYER}", player.getName(), "{KIT}", settings.getKit(), "{ARENA}", settings.getArena());
RequestSendEvent requestSendEvent = new RequestSendEvent(requestManager.getRequestTo(player, target), player, target);
Bukkit.getPluginManager().callEvent(requestSendEvent);
@@ -140,39 +144,93 @@ public class ArenaManager implements Listener {
}
@Override
public void onSwitch(Player player, Inventory opened) {
if (player.hasMetadata("request")) {
Object value = player.getMetadata("request").get(0).value();
player.openInventory(opened);
if (value == null || !(value instanceof Settings)) {
return;
}
player.setMetadata("request", new Metadata(instance, value));
}
}
public void onSwitch(Player player, Inventory opened) {}
});
instance.getGUIManager().register(gui);
}
if (config.isDuelingMatchMaxDurationEnabled()) {
task = Bukkit.getScheduler().runTaskTimer(instance, new Runnable() {
private Location lobby = dataManager.getLobby() != null ? dataManager.getLobby() : Bukkit.getWorlds().get(0).getSpawnLocation();
@Override
public void run() {
for (Arena arena : arenas) {
// Checking if both players are alive, to prevent the case where it will end the match when winner task is running.
if (arena.isUsed() && arena.getPlayers().size() >= 2) {
instance.getSpectatorManager().handleMatchEnd(arena);
Arena.Match match = arena.getCurrentMatch();
if ((System.currentTimeMillis() - match.getStart()) / 1000L <= config.getDuelingMatchMaxDurationDuration()) {
return;
}
Iterator<UUID> iterator = arena.getPlayers().iterator();
while (iterator.hasNext()) {
UUID uuid = iterator.next();
iterator.remove();
Player player = Bukkit.getPlayer(uuid);
if (player == null || player.isDead()) {
continue;
}
if (config.isDuelingTeleportToLatestLocation()) {
lobby = match.getLocation(uuid);
}
Helper.pm(player, "Dueling.max-match-time-reached", true);
Helper.reset(player, false);
Arena.InventoryData data = match.getInventories(uuid);
if (!Helper.canTeleportTo(player, lobby)) {
player.setHealth(0.0D);
} else {
player.teleport(lobby);
Helper.setInventory(player, data.getInventoryContents(), data.getArmorContents());
}
}
arena.setUsed(false);
if (gui != null) {
gui.update(arenas);
}
}
}
}
}, 0L, 20L);
}
instance.info("Loaded " + arenas.size() + " arena(s).");
}
public void save() {
if (gui != null) {
gui.close("[Duels] All GUIs are automatically closed on plugin disable.");
gui.close("[Duels] All GUIs are automatically closed on plugin shutdown.");
}
if (task != null) {
task.cancel();
task = null;
}
List<ArenaData> saved = new ArrayList<>();
Location toTeleport = dataManager.getLobby() != null ? dataManager.getLobby() : Bukkit.getWorlds().get(0).getSpawnLocation();
Location lobby = dataManager.getLobby() != null ? dataManager.getLobby() : Bukkit.getWorlds().get(0).getSpawnLocation();
if (!arenas.isEmpty()) {
for (Arena arena : arenas) {
saved.add(new ArenaData(arena));
if (arena.isUsed()) {
instance.getSpectatorManager().handleMatchEnd(arena);
Arena.Match match = arena.getCurrentMatch();
for (UUID uuid : arena.getPlayers()) {
@@ -182,20 +240,20 @@ public class ArenaManager implements Listener {
continue;
}
if (config.isTeleportToLastLoc()) {
toTeleport = match.getLocation(uuid);
if (config.isDuelingTeleportToLatestLocation()) {
lobby = match.getLocation(uuid);
}
Helper.pm("&c&l[Duels] Plugin is disabling, matches are ended by default.", player);
Helper.pm(player, "&c&l[Duels] Plugin is disabling, matches are ended by default.", false);
Helper.reset(player, false);
Arena.InventoryData data = match.getInventories(uuid);
if (!Helper.canTeleportTo(player, toTeleport)) {
if (!Helper.canTeleportTo(player, lobby)) {
player.setHealth(0.0D);
} else {
player.teleport(toTeleport);
Helper.setInventory(player, data.getInventoryContents(), data.getArmorContents(), false);
player.teleport(lobby);
Helper.setInventory(player, data.getInventoryContents(), data.getArmorContents());
}
}
}
@@ -238,7 +296,7 @@ public class ArenaManager implements Listener {
return null;
}
public Arena getArena(Player player, Inventory inventory, int slot) {
private Arena getArena(Player player, Inventory inventory, int slot) {
return gui.getData(player, inventory, slot);
}
@@ -259,13 +317,7 @@ public class ArenaManager implements Listener {
}
public boolean isInMatch(Player player) {
for (Arena arena : arenas) {
if (arena.getPlayers().contains(player.getUniqueId())) {
return true;
}
}
return false;
return getArena(player) != null;
}
public void createArena(String name) {
@@ -319,41 +371,97 @@ public class ArenaManager implements Listener {
@EventHandler (priority = EventPriority.HIGHEST)
public void on(ProjectileLaunchEvent event) {
if (event.isCancelled() || !(event.getEntity().getShooter() instanceof Player) || !config.isCdProjectileBlocked()) {
if (event.isCancelled() || !(event.getEntity().getShooter() instanceof Player) || !config.isCountdownBlockProjectile()) {
return;
}
Player player = (Player) event.getEntity().getShooter();
Arena arena = getArena(player);
if (!isInMatch(player)) {
if (arena == null) {
return;
}
Arena arena = getArena(player);
if (arena.isCounting()) {
Helper.pm("&cYou are not allowed to do this before the match starts.", player);
Helper.pm(player, "Errors.blocked-countdown-action", true);
event.setCancelled(true);
}
}
@EventHandler (priority = EventPriority.HIGHEST)
public void on(EntityDamageByEntityEvent event) {
if (event.isCancelled() || !(event.getEntity() instanceof Player && event.getDamager() instanceof Player) || !config.isCdPvPBlocked()) {
if (!(event.getEntity() instanceof Player && event.getDamager() instanceof Player) || !config.isCountdownBlockPvp()) {
return;
}
Player player = (Player) event.getDamager();
Arena arena = getArena(player);
if (!isInMatch(player)) {
if (arena == null) {
return;
}
Player damaged = (Player) event.getEntity();
if (arena.isCounting()) {
Helper.pm(player, "Errors.blocked-countdown-action", true);
event.setCancelled(true);
} else if (event.isCancelled() && config.isPatchesForceAllowPvp() && arena.hasPlayer(damaged)) {
event.setCancelled(false);
}
}
@SuppressWarnings("deprecation")
@EventHandler
public void on(PlayerInteractEvent event) {
if (!config.isSoupEnabled() || !event.getAction().name().contains("RIGHT")) {
return;
}
Player player = event.getPlayer();
if (player.getHealth() == player.getMaxHealth()) {
return;
}
Arena arena = getArena(player);
if (arena.isCounting()) {
Helper.pm("&cYou are not allowed to do this before the match starts.", player);
event.setCancelled(true);
if (arena == null || !arena.getName().startsWith(config.getSoupArenasStartingWith())) {
return;
}
boolean regen = false;
if (CompatHelper.isPre1_9()) {
if (player.getItemInHand().getType() == Material.MUSHROOM_SOUP) {
player.setItemInHand(new ItemStack(Material.BOWL));
regen = true;
}
} else {
if (player.getInventory().getItemInMainHand().getType() == Material.MUSHROOM_SOUP) {
player.getInventory().setItemInMainHand(new ItemStack(Material.BOWL));
regen = true;
} else if (player.getInventory().getItemInOffHand().getType() == Material.MUSHROOM_SOUP) {
player.getInventory().setItemInOffHand(new ItemStack(Material.BOWL));
regen = true;
}
}
if (!regen) {
return;
}
if (player.getHealth() + config.getSoupHeartsToRegen() * 2.0 <= player.getMaxHealth()) {
player.setHealth(player.getHealth() + config.getSoupHeartsToRegen() * 2.0);
} else {
player.setHealth(player.getHealth() + (player.getMaxHealth() - player.getHealth()));
}
}
@Override
public void handleReload(ReloadType type) {
if (type == ReloadType.STRONG) {
save();
load();
}
}
}
@@ -1,56 +1,59 @@
package me.realized.duels.commands;
import me.realized.duels.Core;
import me.realized.duels.arena.ArenaManager;
import me.realized.duels.configuration.ConfigType;
import me.realized.duels.configuration.MainConfig;
import me.realized.duels.configuration.MessagesConfig;
import me.realized.duels.data.DataManager;
import me.realized.duels.dueling.RequestManager;
import me.realized.duels.dueling.SpectatorManager;
import me.realized.duels.hooks.HookManager;
import me.realized.duels.kits.KitManager;
import me.realized.duels.utilities.Helper;
import org.bukkit.command.Command;
import org.bukkit.command.CommandExecutor;
import org.bukkit.command.CommandSender;
import org.bukkit.command.TabCompleter;
import org.bukkit.entity.Player;
public abstract class BaseCommand implements CommandExecutor, TabCompleter {
public abstract class BaseCommand implements CommandExecutor {
private final String command;
private final String permission;
private transient final Core instance = Core.getInstance();
protected final MainConfig config = Core.getInstance().getConfiguration();
protected final MessagesConfig messages = (MessagesConfig) Core.getInstance().getConfigManager().getConfigByType(ConfigType.MESSAGES);
protected final RequestManager requestManager = Core.getInstance().getRequestManager();
protected final DataManager dataManager = Core.getInstance().getDataManager();
protected final ArenaManager arenaManager = Core.getInstance().getArenaManager();
protected final SpectatorManager spectatorManager = Core.getInstance().getSpectatorManager();
protected final KitManager kitManager = Core.getInstance().getKitManager();
protected final HookManager hookManager = Core.getInstance().getHookManager();
protected BaseCommand(String command, String permission) {
this.command = command;
this.permission = permission;
}
protected String getName() {
public String getName() {
return command;
}
protected Core getInstance() {
return instance;
}
public void register() {
instance.getCommand(command).setExecutor(this);
}
protected void pm(CommandSender sender, String msg) {
sender.sendMessage(Helper.color(msg));
}
@Override
public boolean onCommand(CommandSender sender, Command command, String label, String[] args) {
if (!(sender instanceof Player)) {
pm(sender, "&c&lInvalid executor: " + sender.getName());
Helper.pm(sender, "&cThis command cannot be ran by " + sender.getName() + ".", false);
return true;
}
if (!sender.hasPermission(permission)) {
pm(sender, "&cYou do not have permission.");
Helper.pm(sender, "Errors.no-permission", true);
return true;
}
execute(sender, args);
execute((Player) sender, args);
return true;
}
protected abstract void execute(CommandSender sender, String[] args);
protected abstract void execute(Player sender, String[] args);
}
@@ -1,20 +1,31 @@
package me.realized.duels.commands;
import me.realized.duels.Core;
import me.realized.duels.utilities.Helper;
import org.bukkit.command.CommandSender;
import me.realized.duels.arena.ArenaManager;
import me.realized.duels.data.DataManager;
import me.realized.duels.dueling.DuelManager;
import me.realized.duels.dueling.RequestManager;
import me.realized.duels.kits.KitManager;
import org.bukkit.entity.Player;
public abstract class SubCommand {
private final String name;
private final String usage;
private final String permission;
private final String description;
private final int length;
private transient final Core instance = Core.getInstance();
protected SubCommand(String name, String usage, String description, int length) {
protected final RequestManager requestManager = Core.getInstance().getRequestManager();
protected final DataManager dataManager = Core.getInstance().getDataManager();
protected final ArenaManager arenaManager = Core.getInstance().getArenaManager();
protected final KitManager kitManager = Core.getInstance().getKitManager();
protected final DuelManager duelManager = Core.getInstance().getDuelManager();
protected SubCommand(String name, String usage, String permission, String description, int length) {
this.name = name;
this.usage = usage;
this.permission = permission;
this.description = description;
this.length = length;
}
@@ -27,6 +38,10 @@ public abstract class SubCommand {
return usage;
}
public String getPermission() {
return permission;
}
public String getDescription() {
return description;
}
@@ -35,13 +50,5 @@ public abstract class SubCommand {
return length;
}
protected Core getInstance() {
return instance;
}
protected void pm(CommandSender sender, String msg) {
sender.sendMessage(Helper.color(msg));
}
public abstract void execute(CommandSender sender, String[] args);
public abstract void execute(Player sender, String[] args);
}
@@ -4,75 +4,58 @@ import me.realized.duels.commands.BaseCommand;
import me.realized.duels.commands.SubCommand;
import me.realized.duels.commands.admin.subcommands.*;
import me.realized.duels.utilities.Helper;
import me.realized.duels.utilities.Lang;
import org.bukkit.command.Command;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.HashMap;
import java.util.Map;
public class DuelsCommand extends BaseCommand {
private final List<SubCommand> commands = new ArrayList<>();
private final Map<String, SubCommand> children = new HashMap<>();
public DuelsCommand() {
super("duels", "duels.admin");
commands.addAll(Arrays.asList(new EditCommand(), new CreateCommand(), new SetCommand(), new DeleteCommand(), new ListCommand(), new ToggleCommand(), new InfoCommand(), new SavekitCommand(), new DeletekitCommand(), new LoadkitCommand(), new SetlobbyCommand(), new SetitemCommand()));
children.put("create", new CreateCommand());
children.put("delete", new DeleteCommand());
children.put("edit", new EditCommand());
children.put("info", new InfoCommand());
children.put("list", new ListCommand());
children.put("loadkit", new LoadkitCommand());
children.put("savekit", new SavekitCommand());
children.put("deletekit", new DeletekitCommand());
children.put("reset", new ResetCommand());
children.put("set", new SetCommand());
children.put("setitem", new SetitemCommand());
children.put("setlobby", new SetlobbyCommand());
children.put("toggle", new ToggleCommand());
children.put("reload", new ReloadCommand());
}
@Override
public void execute(CommandSender sender, String[] args) {
public void execute(Player sender, String[] args) {
if (args.length == 0) {
pm(sender, "&b&m------------------------------------------------");
for (SubCommand sub : commands) {
pm(sender, Helper.replaceWithArgs(Lang.ADMIN_COMMAND_USAGE.getMessage(), "{USAGE}", "/" + getName() + " " + sub.getUsage(), "{DESC}", sub.getDescription()));
}
pm(sender, "&b&m------------------------------------------------");
Helper.pm(sender, "Commands.duels.usage", true);
return;
}
SubCommand subCommand = null;
SubCommand child = children.get(args[0].toLowerCase());
for (SubCommand command : commands) {
if (args[0].equalsIgnoreCase(command.getName())) {
subCommand = command;
break;
}
}
if (subCommand == null) {
pm(sender, "&c'" + args[0] + "' is not a valid parent command.");
if (child == null) {
Helper.pm(sender, "Errors.invalid-sub-command", true, "{ARGUMENT}", args[0]);
return;
}
if (args.length < subCommand.length()) {
pm(sender, "&9[Duels] " + Helper.replaceWithArgs(Lang.ADMIN_COMMAND_USAGE.getMessage(), "{USAGE}", "/" + getName() + " " + subCommand.getUsage(), "{DESC}", subCommand.getDescription()));
if (!sender.hasPermission(child.getPermission())) {
Helper.pm(sender, "Errors.no-permission", true);
return;
}
subCommand.execute(sender, args);
}
@Override
public List<String> onTabComplete(CommandSender sender, Command command, String label, String[] args) {
if (args.length != 1) {
return null;
if (args.length < child.length()) {
Helper.pm(sender, "Commands.duels.sub-command-usage", true, "{USAGE}", "/" + getName() + " " + child.getUsage(), "{DESCRIPTION}", child.getDescription());
return;
}
List<String> result = new ArrayList<>();
String input = args[0];
for (SubCommand subCommand : commands) {
if (input == null || input.isEmpty()) {
result.add(subCommand.getName());
} else if (subCommand.getName().startsWith(input)) {
result.add(subCommand.getName());
}
}
return result;
child.execute(sender, args);
}
}
@@ -1,35 +1,30 @@
package me.realized.duels.commands.admin.subcommands;
import me.realized.duels.arena.ArenaManager;
import me.realized.duels.commands.SubCommand;
import me.realized.duels.utilities.Helper;
import me.realized.duels.utilities.Lang;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;
public class CreateCommand extends SubCommand {
private final ArenaManager manager;
public CreateCommand() {
super("create", "create [name]", "Create an arena.", 2);
this.manager = getInstance().getArenaManager();
super("create", "create [name]", "duels.admin", "Create an arena.", 2);
}
@Override
public void execute(CommandSender sender, String[] args) {
String name = args[1].toLowerCase();
public void execute(Player sender, String[] args) {
String name = Helper.join(args, 1, args.length, " ");
if (!Helper.isAlphanumeric(name)) {
pm(sender, "&cArena name must be alphanumeric.");
Helper.pm(sender, "Errors.must-be-alphanumeric", true);
return;
}
if (manager.getArena(name) != null) {
pm(sender, "&cAlready existing arena.");
if (arenaManager.getArena(name) != null) {
Helper.pm(sender, "Errors.arena-exists", true);
return;
}
manager.createArena(name);
pm(sender, Lang.ARENA_CREATE.getMessage().replace("{NAME}", name));
arenaManager.createArena(name);
Helper.pm(sender, "Arenas.created", true, "{NAME}", name);
}
}
@@ -1,37 +1,33 @@
package me.realized.duels.commands.admin.subcommands;
import me.realized.duels.arena.Arena;
import me.realized.duels.arena.ArenaManager;
import me.realized.duels.commands.SubCommand;
import me.realized.duels.utilities.Lang;
import org.bukkit.command.CommandSender;
import me.realized.duels.utilities.Helper;
import org.bukkit.entity.Player;
public class DeleteCommand extends SubCommand {
private final ArenaManager manager;
public DeleteCommand() {
super("delete", "delete [name]", "Remove an arena.", 2);
this.manager = getInstance().getArenaManager();
super("delete", "delete [name]", "duels.admin", "Remove an arena.", 2);
}
@Override
public void execute(CommandSender sender, String[] args) {
String name = args[1].toLowerCase();
public void execute(Player sender, String[] args) {
String name = Helper.join(args, 1, args.length, " ");
if (manager.getArena(name) == null) {
pm(sender, "&cNon-existing arena.");
if (arenaManager.getArena(name) == null) {
Helper.pm(sender, "Errors.arena-not-found", true);
return;
}
Arena arena = manager.getArena(name);
Arena arena = arenaManager.getArena(name);
if (arena.isUsed()) {
pm(sender, "&cThat arena is currently in use. To prevent arena from being used, disable it using /duels toggle [name].");
Helper.pm(sender, "Errors.arena-deletion-failed", true);
return;
}
manager.removeArena(arena);
pm(sender, Lang.ARENA_DELETE.getMessage().replace("{NAME}", name));
arenaManager.removeArena(arena);
Helper.pm(sender, "Arenas.deleted", true, "{NAME}", name);
}
}
@@ -2,34 +2,28 @@ package me.realized.duels.commands.admin.subcommands;
import me.realized.duels.commands.SubCommand;
import me.realized.duels.event.KitRemoveEvent;
import me.realized.duels.kits.KitManager;
import me.realized.duels.utilities.Lang;
import me.realized.duels.utilities.Helper;
import org.bukkit.Bukkit;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;
public class DeletekitCommand extends SubCommand {
private final KitManager manager;
public DeletekitCommand() {
super("deletekit", "deletekit [name]", "Delete a kit with the given name.", 2);
this.manager = getInstance().getKitManager();
super("deletekit", "deletekit [name]", "duels.admin", "Delete a kit with the given name.", 2);
}
@Override
public void execute(CommandSender sender, String[] args) {
Player player = (Player) sender;
String name = args[1];
public void execute(Player sender, String[] args) {
String name = Helper.join(args, 1, args.length, " ");
if (manager.getKit(name) == null) {
pm(player, "&cA kit with that name was not found.");
if (kitManager.getKit(name) == null) {
Helper.pm(sender, "Errors.kit-not-found", true);
return;
}
manager.removeKit(name);
KitRemoveEvent event = new KitRemoveEvent(name, player);
kitManager.removeKit(name);
KitRemoveEvent event = new KitRemoveEvent(name, sender);
Bukkit.getPluginManager().callEvent(event);
pm(player, Lang.KIT_DELETE.getMessage().replace("{NAME}", name));
Helper.pm(sender, "Kits.deleted", true, "{NAME}", name);
}
}
@@ -1,55 +1,50 @@
package me.realized.duels.commands.admin.subcommands;
import me.realized.duels.commands.SubCommand;
import me.realized.duels.data.DataManager;
import me.realized.duels.data.UserData;
import me.realized.duels.utilities.Helper;
import me.realized.duels.utilities.Lang;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;
import java.util.UUID;
public class EditCommand extends SubCommand {
private final DataManager manager;
public EditCommand() {
super("edit", "edit [player] [add:remove:set] [wins:losses] [quantity]", "Edit player's stats.", 5);
this.manager = getInstance().getDataManager();
super("edit", "edit [player] [add:remove:set] [wins:losses] [quantity]", "duels.admin", "Edit player's stats.", 5);
}
@Override
public void execute(CommandSender sender, String[] args) {
public void execute(Player sender, String[] args) {
UUID uuid = Helper.getUUID(args[1]);
if (uuid == null) {
pm(sender, "&cPlayer not found.");
Helper.pm(sender, "Errors.player-not-found", true);
return;
}
UserData target = manager.getUser(uuid, true);
UserData target = dataManager.getUser(uuid, true);
if (target == null) {
pm(sender, "&cPlayer not found.");
Helper.pm(sender, "Errors.player-not-found", true);
return;
}
if (!UserData.EditType.isValue(args[2].toUpperCase())) {
pm(sender, "&c'" + args[2] + "' is not a valid edit type. You may choose from one of the following: add, remove, set");
Helper.pm(sender, "Errors.edit-failed", true, "{REASON}", args[2] + " is not a valid edit type. You may choose from one of the following: add, remove, set");
return;
}
UserData.EditType editType = UserData.EditType.valueOf(args[2].toUpperCase());
if (!UserData.StatsType.isValue(args[3].toUpperCase())) {
pm(sender, "&c'" + args[3] + "' is not a valid stats type. You may choose from one of the following: wins, losses");
Helper.pm(sender, "Errors.edit-failed", true, "{REASON}", args[3] + " is not a valid stats type. You may choose from one of the following: wins, losses");
return;
}
UserData.StatsType statsType = UserData.StatsType.valueOf(args[3].toUpperCase());
if (!Helper.isInt(args[4], false)) {
pm(sender, "&c'" + args[4] + "' is not a valid amount.");
Helper.pm(sender, "Errors.edit-failed", true, "{REASON}", args[4] + " is not a valid amount.");
return;
}
@@ -57,6 +52,6 @@ public class EditCommand extends SubCommand {
target.edit(editType, statsType, amount);
String action = editType.name().toLowerCase() + " " + amount + " " + statsType.name().toLowerCase();
pm(sender, Helper.replaceWithArgs(Lang.EDIT.getMessage(), "{PLAYER}", target.getName(), "{ACTION}", action));
Helper.pm(sender, "Stats.edit", true, "{PLAYER}", target.getName(), "{ACTION}", action);
}
}
@@ -1,36 +1,28 @@
package me.realized.duels.commands.admin.subcommands;
import me.realized.duels.arena.Arena;
import me.realized.duels.arena.ArenaManager;
import me.realized.duels.commands.SubCommand;
import me.realized.duels.utilities.Helper;
import me.realized.duels.utilities.Lang;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;
public class InfoCommand extends SubCommand {
private final ArenaManager manager;
public InfoCommand() {
super("info", "info [name]", "Show arena information.", 2);
this.manager = getInstance().getArenaManager();
super("info", "info [name]", "duels.admin", "Show arena information.", 2);
}
@Override
public void execute(CommandSender sender, String[] args) {
String name = args[1].toLowerCase();
public void execute(Player sender, String[] args) {
String name = Helper.join(args, 1, args.length, " ");
if (manager.getArena(name) == null) {
pm(sender, "&cNon-existing arena.");
if (arenaManager.getArena(name) == null) {
Helper.pm(sender, "Errors.arena-not-found", true);
return;
}
Arena arena = manager.getArena(name);
Arena arena = arenaManager.getArena(name);
String players = Helper.join(arena.getFormattedPlayers(), "&r, ");
String locations = Helper.join(arena.getFormattedLocations(), "&r, ");
for (String s : Lang.ARENA_INFO.getMessages()) {
pm(sender, Helper.replaceWithArgs(s, "{NAME}", arena.getName(), "{IN_USE}", arena.isUsed(), "{DISABLED}", arena.isDisabled(), "{PLAYERS}", players, "{LOCATIONS}", locations));
}
Helper.pm(sender, "Arenas.info", true, "{NAME}", arena.getName(), "{DISABLED}", arena.isDisabled(), "{IN_USE}", arena.isUsed(), "{PLAYERS}", players, "{LOCATIONS}", locations);
}
}
@@ -1,34 +1,20 @@
package me.realized.duels.commands.admin.subcommands;
import me.realized.duels.arena.ArenaManager;
import me.realized.duels.commands.SubCommand;
import me.realized.duels.data.DataManager;
import me.realized.duels.kits.KitManager;
import me.realized.duels.utilities.Helper;
import me.realized.duels.utilities.Lang;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;
public class ListCommand extends SubCommand {
private final KitManager kitManager;
private final ArenaManager arenaManager;
private final DataManager dataManager;
public ListCommand() {
super("list", "list", "Displays the lobby location and lists arenas and kits.", 1);
this.kitManager = getInstance().getKitManager();
this.arenaManager = getInstance().getArenaManager();
this.dataManager = getInstance().getDataManager();
super("list", "list", "duels.admin", "Displays the lobby location and lists arenas and kits.", 1);
}
@Override
public void execute(CommandSender sender, String[] args) {
public void execute(Player sender, String[] args) {
String arenas = Helper.join(arenaManager.getArenaNames(), "&r, ");
String kits = Helper.join(kitManager.getKitNames(), ", ");
String lobby = (dataManager.getLobby() != null ? Helper.format(dataManager.getLobby()) : "Lobby not set, using world's spawn location. Set lobby using /duels setlobby");
for (String s : Lang.LIST.getMessages()) {
pm(sender, Helper.replaceWithArgs(s, "{ARENAS}", arenas, "{KITS}", kits, "{LOBBY}", lobby));
}
Helper.pm(sender, "Extra.list", true, "{ARENAS}", arenas, "{KITS}", kits, "{LOBBY}", lobby);
}
}
@@ -3,35 +3,29 @@ package me.realized.duels.commands.admin.subcommands;
import me.realized.duels.commands.SubCommand;
import me.realized.duels.event.KitLoadEvent;
import me.realized.duels.kits.Kit;
import me.realized.duels.kits.KitManager;
import me.realized.duels.utilities.Lang;
import me.realized.duels.utilities.Helper;
import org.bukkit.Bukkit;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;
public class LoadkitCommand extends SubCommand {
private final KitManager manager;
public LoadkitCommand() {
super("loadkit", "loadkit [name]", "Load a kit with the given name.", 2);
this.manager = getInstance().getKitManager();
super("loadkit", "loadkit [name]", "duels.admin", "Load a kit with the given name.", 2);
}
@Override
public void execute(CommandSender sender, String[] args) {
Player player = (Player) sender;
String name = args[1];
public void execute(Player sender, String[] args) {
String name = Helper.join(args, 1, args.length, " ");
if (manager.getKit(name) == null) {
pm(player, "&cA kit with that name was not found.");
if (kitManager.getKit(name) == null) {
Helper.pm(sender, "Errors.kit-not-found", true);
return;
}
Kit kit = manager.getKit(name);
kit.equip(player);
pm(player, Lang.KIT_LOAD.getMessage().replace("{NAME}", name));
KitLoadEvent event = new KitLoadEvent(name, kit, player);
Kit kit = kitManager.getKit(name);
kit.equip(sender);
Helper.pm(sender, "Kits.loaded", true, "{NAME}", name);
KitLoadEvent event = new KitLoadEvent(name, kit, sender);
Bukkit.getPluginManager().callEvent(event);
}
}
@@ -0,0 +1,30 @@
package me.realized.duels.commands.admin.subcommands;
import me.realized.duels.Core;
import me.realized.duels.commands.SubCommand;
import me.realized.duels.utilities.Helper;
import me.realized.duels.utilities.ReloadType;
import org.bukkit.entity.Player;
public class ReloadCommand extends SubCommand {
// TODO: 10/19/16 Add validation, PreReloadAffect that shows what reloading now will do
public ReloadCommand() {
super("reload", "reload [weak]", "duels.admin", "Reloads the plugin completely or only the messages. Append 'weak' to only reload messages file.", 1);
}
@Override
public void execute(Player sender, String[] args) {
Core instance = Core.getInstance();
if (args.length > 1 && args[1].equalsIgnoreCase("weak")) {
instance.reload(ReloadType.WEAK);
Helper.pm(sender, "&a" + instance.getDescription().getFullName() + ": Weak reload complete.", false);
return;
}
instance.reload(ReloadType.STRONG);
Helper.pm(sender, "&a" + instance.getDescription().getFullName() + ": Reload complete.", false);
}
}
@@ -0,0 +1,37 @@
package me.realized.duels.commands.admin.subcommands;
import me.realized.duels.commands.SubCommand;
import me.realized.duels.data.UserData;
import me.realized.duels.utilities.Helper;
import org.bukkit.entity.Player;
import java.util.UUID;
public class ResetCommand extends SubCommand {
public ResetCommand() {
super("reset", "reset [player]", "duels.admin", "Completely reset a player's stats.", 2);
}
@Override
public void execute(Player sender, String[] args) {
UUID uuid = Helper.getUUID(args[1]);
if (uuid == null) {
Helper.pm(sender, "Errors.player-not-found", true);
return;
}
UserData target = dataManager.getUser(uuid, true);
if (target == null) {
Helper.pm(sender, "Errors.player-not-found", true);
return;
}
target.edit(UserData.EditType.SET, UserData.StatsType.WINS, 0);
target.edit(UserData.EditType.SET, UserData.StatsType.LOSSES, 0);
target.getMatches().clear();
Helper.pm(sender, "Stats.reset", true, "{PLAYER}", target.getName());
}
}
@@ -3,41 +3,34 @@ package me.realized.duels.commands.admin.subcommands;
import me.realized.duels.commands.SubCommand;
import me.realized.duels.event.KitCreateEvent;
import me.realized.duels.kits.Kit;
import me.realized.duels.kits.KitManager;
import me.realized.duels.utilities.Helper;
import me.realized.duels.utilities.Lang;
import org.bukkit.Bukkit;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;
public class SavekitCommand extends SubCommand {
private final KitManager manager;
public SavekitCommand() {
super("savekit", "savekit [name]", "Save a new kit with your inventory contents.", 2);
this.manager = getInstance().getKitManager();
super("savekit", "savekit [name]", "duels.admin", "Save a new kit with your inventory contents.", 2);
}
@Override
public void execute(CommandSender sender, String[] args) {
Player player = (Player) sender;
String name = args[1];
public void execute(Player sender, String[] args) {
String name = Helper.join(args, 1, args.length, " ");
if (!Helper.isAlphanumeric(name)) {
pm(sender, "&cKit name must be alphanumeric.");
Helper.pm(sender, "Errors.must-be-alphanumeric", true);
return;
}
if (manager.getKit(name) != null) {
pm(player, "&cA kit with that name already exists.");
if (kitManager.getKit(name) != null) {
Helper.pm(sender, "Errors.kit-exists", true);
return;
}
Kit kit = new Kit(name, player.getInventory());
manager.addKit(name, kit);
KitCreateEvent event = new KitCreateEvent(name, player);
Kit kit = new Kit(name, sender.getInventory());
kitManager.addKit(name, kit);
KitCreateEvent event = new KitCreateEvent(name, sender);
Bukkit.getPluginManager().callEvent(event);
pm(player, Lang.KIT_CREATE.getMessage().replace("{NAME}", name));
Helper.pm(sender, "Kits.created", true, "{NAME}", name);
}
}
@@ -1,52 +1,45 @@
package me.realized.duels.commands.admin.subcommands;
import me.realized.duels.arena.Arena;
import me.realized.duels.arena.ArenaManager;
import me.realized.duels.commands.SubCommand;
import me.realized.duels.utilities.Helper;
import me.realized.duels.utilities.Lang;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;
public class SetCommand extends SubCommand {
private final ArenaManager manager;
public SetCommand() {
super("set", "set [name] [1 | 2]", "Set spawn position for arena.", 2);
this.manager = getInstance().getArenaManager();
super("set", "set [name] [1 | 2]", "duels.admin", "Set spawn position for arena.", 2);
}
@Override
public void execute(CommandSender sender, String[] args) {
Player player = (Player) sender;
String name = args[1].toLowerCase();
public void execute(Player sender, String[] args) {
String name = Helper.join(args, 1, args.length - 1, " ");
if (manager.getArena(name) == null) {
pm(sender, "&cNon-existing arena.");
if (arenaManager.getArena(name) == null) {
Helper.pm(sender, "Errors.arena-not-found", true);
return;
}
Arena arena = manager.getArena(name);
Arena arena = arenaManager.getArena(name);
if (!Helper.isInt(args[2], false)) {
pm(sender, "&cSpawn positions must be in between range 1 - 2.");
if (!Helper.isInt(args[args.length - 1], false)) {
Helper.pm(sender, "Errors.invalid-spawnpoint", true);
return;
}
int position = Integer.parseInt(args[2]);
int position = Integer.parseInt(args[args.length - 1]);
if (position < 1 || position > 2) {
pm(sender, "&cSpawn positions must be in between range 1 - 2.");
Helper.pm(sender, "Errors.invalid-spawnpoint", true);
return;
}
arena.addPosition(position, player.getLocation().clone());
arena.addPosition(position, sender.getLocation().clone());
if (manager.getGUI() != null) {
manager.getGUI().update(manager.getArenas());
if (arenaManager.getGUI() != null) {
arenaManager.getGUI().update(arenaManager.getArenas());
}
pm(player, Helper.replaceWithArgs(Lang.ARENA_SET_POSITION.getMessage(), "{POSITION}", position, "{NAME}", arena.getName()));
Helper.pm(sender, "Arenas.set-spawnpoint", true, "{POSITION}", position, "{NAME}", arena.getName());
}
}
@@ -3,56 +3,49 @@ package me.realized.duels.commands.admin.subcommands;
import me.realized.duels.commands.SubCommand;
import me.realized.duels.event.KitItemChangeEvent;
import me.realized.duels.kits.Kit;
import me.realized.duels.kits.KitManager;
import me.realized.duels.utilities.Lang;
import me.realized.duels.utilities.Helper;
import me.realized.duels.utilities.compat.CompatHelper;
import org.bukkit.Bukkit;
import org.bukkit.Material;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;
import org.bukkit.inventory.ItemStack;
public class SetitemCommand extends SubCommand {
private final KitManager manager;
public SetitemCommand() {
super("setitem", "setitem [name]", "Replaces the displayed item to held item for selected kit.", 2);
this.manager = getInstance().getKitManager();
super("setitem", "setitem [name]", "duels.admin", "Replaces the displayed item to held item for selected kit.", 2);
}
@SuppressWarnings("deprecation")
@Override
public void execute(CommandSender sender, String[] args) {
Player player = (Player) sender;
public void execute(Player sender, String[] args) {
ItemStack held;
if (Bukkit.getVersion().contains("1.8") || Bukkit.getVersion().contains("1.7")) {
held = player.getInventory().getItemInHand();
if (CompatHelper.isPre1_9()) {
held = sender.getInventory().getItemInHand();
} else {
held = player.getInventory().getItemInMainHand();
held = sender.getInventory().getItemInMainHand();
}
if (held == null || held.getType() == Material.AIR) {
pm(player, "&cPlease hold an item to use this command.");
Helper.pm(sender, "Errors.empty-hand", true);
return;
}
String name = args[1];
String name = Helper.join(args, 1, args.length, " ");
if (manager.getKit(name) == null) {
pm(player, "&cA kit with that name was not found.");
if (kitManager.getKit(name) == null) {
Helper.pm(sender, "Errors.kit-not-found", true);
return;
}
Kit kit = manager.getKit(name);
Kit kit = kitManager.getKit(name);
ItemStack old = kit.getDisplayed();
ItemStack _new = held.clone();
kit.setDisplayed(_new);
manager.getGUI().update(manager.getKits());
pm(player, Lang.REPLACE_KIT_ITEM.getMessage().replace("{NAME}", name));
KitItemChangeEvent event = new KitItemChangeEvent(name, player, old, _new);
kitManager.getGUI().update(kitManager.getKits());
Helper.pm(sender, "Kits.set-item", true, "{NAME}", name);
KitItemChangeEvent event = new KitItemChangeEvent(name, sender, old, _new);
Bukkit.getPluginManager().callEvent(event);
}
}
@@ -1,19 +1,18 @@
package me.realized.duels.commands.admin.subcommands;
import me.realized.duels.commands.SubCommand;
import me.realized.duels.utilities.Lang;
import org.bukkit.command.CommandSender;
import me.realized.duels.utilities.Helper;
import org.bukkit.entity.Player;
public class SetlobbyCommand extends SubCommand {
public SetlobbyCommand() {
super("setlobby", "setlobby", "Set duel lobby on your current location.", 1);
super("setlobby", "setlobby", "duels.admin", "Set duel lobby on your current location.", 1);
}
@Override
public void execute(CommandSender sender, String[] args) {
getInstance().getDataManager().setLobby((Player) sender);
pm(sender, Lang.SET_LOBBY.getMessage());
public void execute(Player sender, String[] args) {
dataManager.setLobby(sender);
Helper.pm(sender, "Extra.set-lobby", true);
}
}
@@ -1,31 +1,27 @@
package me.realized.duels.commands.admin.subcommands;
import me.realized.duels.arena.Arena;
import me.realized.duels.arena.ArenaManager;
import me.realized.duels.commands.SubCommand;
import me.realized.duels.utilities.Lang;
import org.bukkit.command.CommandSender;
import me.realized.duels.utilities.Helper;
import org.bukkit.entity.Player;
public class ToggleCommand extends SubCommand {
private final ArenaManager manager;
public ToggleCommand() {
super("toggle", "toggle [name]", "Enable/Disable an arena.", 2);
this.manager = getInstance().getArenaManager();
super("toggle", "toggle [name]", "duels.admin", "Enable/Disable an arena.", 2);
}
@Override
public void execute(CommandSender sender, String[] args) {
String name = args[1].toLowerCase();
public void execute(Player sender, String[] args) {
String name = Helper.join(args, 1, args.length, " ");
if (manager.getArena(name) == null) {
pm(sender, "&cNon-existing arena.");
if (arenaManager.getArena(name) == null) {
Helper.pm(sender, "Errors.arena-not-found", true);
return;
}
Arena arena = manager.getArena(name);
Arena arena = arenaManager.getArena(name);
arena.setDisabled(!arena.isDisabled());
pm(sender, (arena.isDisabled() ? Lang.ARENA_TOGGLE_OFF : Lang.ARENA_TOGGLE_ON).getMessage().replace("{NAME}", name));
Helper.pm(sender, (arena.isDisabled() ? "Arenas.disabled" : "Arenas.enabled"), true, "{NAME}", name);
}
}
@@ -1,143 +1,135 @@
package me.realized.duels.commands.duel;
import me.realized.duels.arena.ArenaManager;
import me.realized.duels.Core;
import me.realized.duels.commands.BaseCommand;
import me.realized.duels.commands.SubCommand;
import me.realized.duels.commands.duel.subcommands.AcceptCommand;
import me.realized.duels.commands.duel.subcommands.DenyCommand;
import me.realized.duels.configuration.Config;
import me.realized.duels.data.DataManager;
import me.realized.duels.data.UserData;
import me.realized.duels.dueling.RequestManager;
import me.realized.duels.dueling.Settings;
import me.realized.duels.event.RequestSendEvent;
import me.realized.duels.hooks.WorldGuardHook;
import me.realized.duels.kits.KitManager;
import me.realized.duels.utilities.Helper;
import me.realized.duels.utilities.Metadata;
import org.bukkit.Bukkit;
import org.bukkit.command.Command;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.HashMap;
import java.util.Map;
public class DuelCommand extends BaseCommand {
private final Config config;
private final WorldGuardHook wgHook;
private final DataManager dataManager;
private final KitManager kitManager;
private final ArenaManager arenaManager;
private final RequestManager requestManager;
private final List<SubCommand> commands = new ArrayList<>();
private final Map<String, SubCommand> children = new HashMap<>();
public DuelCommand() {
super("duel", "duels.duel");
commands.addAll(Arrays.asList(new AcceptCommand(), new DenyCommand()));
this.config = getInstance().getConfiguration();
this.wgHook = (WorldGuardHook) getInstance().getHookManager().get("WorldGuard");
this.dataManager = getInstance().getDataManager();
this.kitManager = getInstance().getKitManager();
this.arenaManager = getInstance().getArenaManager();
this.requestManager = getInstance().getRequestManager();
this.wgHook = (WorldGuardHook) hookManager.get("WorldGuard");
children.put("accept", new AcceptCommand());
children.put("deny", new DenyCommand());
}
@Override
public void execute(CommandSender sender, String[] args) {
Player player = (Player) sender;
public void execute(Player sender, String[] args) {
if (args.length == 0) {
pm(sender, config.getString("duel-command-usage"));
Helper.pm(sender, "Commands.duel.usage", true);
return;
}
if (!config.isUseOwnInventory() && config.isOnlyEmptyInventory() && !Helper.hasEmptyInventory(player)) {
pm(sender, "&cYour inventory must be empty to use duel commands.");
if (!config.isDuelingUseOwnInventory() && config.isDuelingRequiresClearedInventory() && !Helper.hasEmptyInventory(sender)) {
Helper.pm(sender, "Errors.empty-inventory-only", true);
return;
}
if (!wgHook.canUseDuelCommands(player)) {
pm(sender, "&cYou must be in region '" + config.getDZRegion() + "' to use duel commands.");
if (!wgHook.canUseDuelCommands(sender)) {
Helper.pm(sender, "Errors.not-in-duelzone", true, "{REGION}", config.getDuelZoneRegion());
return;
}
else if (args.length == 1) {
if (args.length == 1) {
Player target = Bukkit.getPlayerExact(args[0]);
if (target == null) {
pm(sender, "&cPlayer not found.");
Helper.pm(sender, "Errors.player-not-found", true);
return;
}
if (target.getUniqueId().equals(player.getUniqueId())) {
pm(sender, "&cYou may not duel yourself.");
return;
}
//if (target.getUniqueId().equals(sender.getUniqueId())) {
// Helper.pm(sender, "Errors.cannot-duel-yourself", true);
// return;
//}
UserData data = dataManager.getUser(target.getUniqueId(), false);
if (data == null) {
pm(sender, "&cPlayer not found.");
Helper.pm(sender, "Errors.player-not-found", true);
return;
}
if (!data.canRequest()) {
pm(sender, "&cThat player is currently not accepting requests.");
Helper.pm(sender, "Errors.has-requests-disabled", true);
return;
}
if (arenaManager.isInMatch(player) || arenaManager.isInMatch(target)) {
pm(player, "&cEither you or that player is already in a match.");
if (spectatorManager.isSpectating(sender)) {
Helper.pm(sender, "Errors.is-in-spectator-mode.sender", true);
return;
}
if (requestManager.hasRequestTo(player, target) == RequestManager.Result.FOUND) {
pm(sender, "&cYou already have a request sent to " + target.getName() + ".");
if (spectatorManager.isSpectating(target)) {
Helper.pm(sender, "Errors.is-in-spectator-mode.target", true);
return;
}
if (!config.isUseOwnInventory()) {
player.setMetadata("request", new Metadata(getInstance(), new Settings(target.getUniqueId())));
player.openInventory(kitManager.getGUI().getFirst());
if (arenaManager.isInMatch(sender)) {
Helper.pm(sender, "Errors.already-in-match.sender", true);
return;
}
if (arenaManager.isInMatch(target)) {
Helper.pm(sender, "Errors.already-in-match.target", true);
return;
}
if (requestManager.hasRequestTo(sender, target) == RequestManager.Result.FOUND) {
Helper.pm(sender, "Errors.already-requested", true, "{PLAYER}", target.getName());
return;
}
if (!config.isDuelingUseOwnInventory()) {
sender.setMetadata("request", new Metadata(Core.getInstance(), new Settings(target.getUniqueId(), sender.getLocation().clone())));
sender.openInventory(kitManager.getGUI().getFirst());
} else {
requestManager.sendRequestTo(player, target, new Settings(target.getUniqueId()));
Helper.pm(config.getString("on-request-send").replace("{PLAYER}", target.getName()).replace("{ARENA}", "random"), player);
Helper.pm(config.getString("on-request-receive").replace("{PLAYER}", player.getName()).replace("{ARENA}", "random"), target);
requestManager.sendRequestTo(sender, target, new Settings(target.getUniqueId(), sender.getLocation().clone()));
Helper.pm(sender, "Dueling.on-request-send.sender", true, "{PLAYER}", target.getName(), "{KIT}", "none", "{ARENA}", "random");
Helper.pm(target, "Dueling.on-request-send.receiver", true, "{PLAYER}", sender.getName(), "{KIT}", "none", "{ARENA}", "random");
RequestSendEvent requestSendEvent = new RequestSendEvent(requestManager.getRequestTo(player, target), player, target);
RequestSendEvent requestSendEvent = new RequestSendEvent(requestManager.getRequestTo(sender, target), sender, target);
Bukkit.getPluginManager().callEvent(requestSendEvent);
}
return;
}
SubCommand subCommand = null;
SubCommand child = children.get(args[0].toLowerCase());
for (SubCommand command : commands) {
if (args[0].equalsIgnoreCase(command.getName())) {
subCommand = command;
break;
}
}
if (subCommand == null) {
pm(sender, "&c'" + args[0] + "' is not a valid parent command.");
if (child == null) {
Helper.pm(sender, "Errors.invalid-sub-command", true, "{ARGUMENT}", args[0]);
return;
}
if (args.length < subCommand.length()) {
pm(sender, "&7Usage: &f/" + getName() + " " + subCommand.getUsage() + " - " + subCommand.getDescription());
if (!sender.hasPermission(child.getPermission())) {
Helper.pm(sender, "Errors.no-permission", true);
return;
}
subCommand.execute(sender, args);
}
if (args.length < child.length()) {
Helper.pm(sender, "Commands.duel.sub-command-usage", true, "{USAGE}", "/" + getName() + " " + child.getUsage(), "{DESCRIPTION}", child.getDescription());
return;
}
@Override
public List<String> onTabComplete(CommandSender commandSender, Command command, String s, String[] strings) {
return null;
child.execute(sender, args);
}
}
@@ -1,77 +1,69 @@
package me.realized.duels.commands.duel.subcommands;
import me.realized.duels.arena.ArenaManager;
import me.realized.duels.commands.SubCommand;
import me.realized.duels.data.DataManager;
import me.realized.duels.data.UserData;
import me.realized.duels.dueling.DuelManager;
import me.realized.duels.dueling.Request;
import me.realized.duels.dueling.RequestManager;
import me.realized.duels.event.RequestHandleEvent;
import me.realized.duels.utilities.Helper;
import org.bukkit.Bukkit;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;
public class AcceptCommand extends SubCommand {
private final DuelManager duelManager;
private final ArenaManager arenaManager;
private final DataManager dataManager;
private final RequestManager requestManager;
public AcceptCommand() {
super("accept", "accept [player]", "Accept a duel request.", 2);
this.duelManager = getInstance().getDuelManager();
this.arenaManager = getInstance().getArenaManager();
this.dataManager = getInstance().getDataManager();
this.requestManager = getInstance().getRequestManager();
super("accept", "accept [player]", "duels.duel", "Accept a duel request.", 2);
}
@Override
public void execute(CommandSender sender, String[] args) {
Player player = (Player) sender;
public void execute(Player sender, String[] args) {
Player target = Bukkit.getPlayerExact(args[1]);
if (target == null) {
pm(sender, "&cPlayer not found.");
Helper.pm(sender, "Errors.player-not-found", true);
return;
}
UserData data = dataManager.getUser(target.getUniqueId(), false);
if (data == null) {
pm(sender, "&cPlayer not found.");
Helper.pm(sender, "Errors.player-not-found", true);
return;
}
RequestManager.Result result = requestManager.hasRequestFrom(player, target);
RequestManager.Result result = requestManager.hasRequestFrom(sender, target);
if (result != RequestManager.Result.FOUND) {
switch (result) {
case TIMED_OUT:
pm(sender, "&cThat duel request has already expired.");
Helper.pm(sender, "Errors.already-expired", true);
return;
case NOT_FOUND:
pm(sender, "&cThat player did not send you a duel request!");
Helper.pm(sender, "Errors.no-request", true);
return;
}
}
if (arenaManager.isInMatch(player) || arenaManager.isInMatch(target)) {
pm(sender, "&cEither you or that player is in a match.");
if (arenaManager.isInMatch(sender)) {
Helper.pm(sender, "Errors.already-in-match.sender", true);
return;
}
if (arenaManager.isInMatch(target)) {
Helper.pm(sender, "Errors.already-in-match.target", true);
return;
}
if(target.isDead()) {
pm(sender, "&cThe player you tried to duel is dead - Try again when they respawn.");
Helper.pm(sender, "Errors.alive-only", true);
return;
}
Request request = requestManager.getRequestFrom(player, target);
requestManager.removeRequestFrom(player, target);
duelManager.startMatch(player, target, request);
Request request = requestManager.getRequestFrom(sender, target);
requestManager.removeRequestFrom(sender, target);
duelManager.startMatch(sender, target, request);
RequestHandleEvent event = new RequestHandleEvent(request, player, target, RequestHandleEvent.Action.ACCEPTED);
RequestHandleEvent event = new RequestHandleEvent(request, sender, target, RequestHandleEvent.Action.ACCEPTED);
Bukkit.getPluginManager().callEvent(event);
}
}
@@ -1,66 +1,55 @@
package me.realized.duels.commands.duel.subcommands;
import me.realized.duels.commands.SubCommand;
import me.realized.duels.configuration.Config;
import me.realized.duels.data.DataManager;
import me.realized.duels.data.UserData;
import me.realized.duels.dueling.Request;
import me.realized.duels.dueling.RequestManager;
import me.realized.duels.event.RequestHandleEvent;
import me.realized.duels.utilities.Helper;
import org.bukkit.Bukkit;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;
public class DenyCommand extends SubCommand {
private final Config config;
private final DataManager dataManager;
private final RequestManager requestManager;
public DenyCommand() {
super("deny", "deny [player]", "Decline a duel request.", 2);
this.config = getInstance().getConfiguration();
this.dataManager = getInstance().getDataManager();
this.requestManager = getInstance().getRequestManager();
super("deny", "deny [player]", "duels.duel", "Decline a duel request.", 2);
}
@Override
public void execute(CommandSender sender, String[] args) {
Player player = (Player) sender;
public void execute(Player sender, String[] args) {
Player target = Bukkit.getPlayerExact(args[1]);
if (target == null) {
pm(sender, "&cPlayer not found.");
Helper.pm(sender, "Errors.player-not-found", true);
return;
}
UserData data = dataManager.getUser(target.getUniqueId(), false);
if (data == null) {
pm(sender, "&cPlayer not found.");
Helper.pm(sender, "Errors.player-not-found", true);
return;
}
RequestManager.Result result = requestManager.hasRequestFrom(player, target);
RequestManager.Result result = requestManager.hasRequestFrom(sender, target);
if (result != RequestManager.Result.FOUND) {
switch (result) {
case TIMED_OUT:
pm(sender, "&cThat duel request has already expired.");
Helper.pm(sender, "Errors.already-expired", true);
return;
case NOT_FOUND:
pm(sender, "&cThat player did not send you a duel request!");
Helper.pm(sender, "Errors.no-request", true);
return;
}
}
Request request = requestManager.getRequestFrom(player, target);
requestManager.removeRequestFrom(player, target);
Helper.pm(Helper.replaceWithArgs(config.getString("on-request-deny-target"), "{PLAYER}", target.getName()), player);
Helper.pm(Helper.replaceWithArgs(config.getString("on-request-deny-sender"), "{PLAYER}", player.getName()), target);
Request request = requestManager.getRequestFrom(sender, target);
requestManager.removeRequestFrom(sender, target);
Helper.pm(sender, "Dueling.on-request-decline.sender", true, "{PLAYER}", target.getName());
Helper.pm(target, "Dueling.on-request-decline.receiver", true, "{PLAYER}", sender.getName());
RequestHandleEvent event = new RequestHandleEvent(request, player, target, RequestHandleEvent.Action.DENIED);
RequestHandleEvent event = new RequestHandleEvent(request, sender, target, RequestHandleEvent.Action.DENIED);
Bukkit.getPluginManager().callEvent(event);
}
}
@@ -0,0 +1,40 @@
package me.realized.duels.commands.other;
import me.realized.duels.commands.BaseCommand;
import me.realized.duels.utilities.Helper;
import org.bukkit.Bukkit;
import org.bukkit.entity.Player;
public class SpectateCommand extends BaseCommand {
public SpectateCommand() {
super("spectate", "duels.spectate");
}
@Override
protected void execute(Player sender, String[] args) {
if (spectatorManager.isSpectating(sender)) {
spectatorManager.stopSpectating(sender);
return;
}
if (args.length == 0) {
Helper.pm(sender, "Commands.spectate.usage", true);
return;
}
if (!Helper.hasEmptyInventory(sender)) {
Helper.pm(sender, "Errors.empty-inventory-only", true);
return;
}
Player target = Bukkit.getPlayerExact(args[0]);
if (target == null) {
Helper.pm(sender, "Errors.player-not-found", true);
return;
}
spectatorManager.spectate(sender, target);
}
}
@@ -1,66 +1,54 @@
package me.realized.duels.commands.other;
import me.realized.duels.Core;
import me.realized.duels.commands.BaseCommand;
import me.realized.duels.configuration.Config;
import me.realized.duels.data.DataManager;
import me.realized.duels.data.MatchData;
import me.realized.duels.data.UserData;
import me.realized.duels.utilities.Helper;
import net.md_5.bungee.api.chat.BaseComponent;
import net.md_5.bungee.api.chat.HoverEvent;
import net.md_5.bungee.api.chat.TextComponent;
import org.bukkit.command.Command;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;
import java.util.Calendar;
import java.util.GregorianCalendar;
import java.util.List;
import java.util.UUID;
public class StatsCommand extends BaseCommand {
private final Core instance;
private final Config config;
private final DataManager manager;
public StatsCommand() {
super("stats", "duels.stats");
this.instance = getInstance();
this.config = instance.getConfiguration();
this.manager = instance.getDataManager();
}
@Override
public void execute(CommandSender sender, String[] args) {
Player player = (Player) sender;
public void execute(Player sender, String[] args) {
if (args.length == 0) {
if (manager.getUser(player.getUniqueId(), player.hasPermission("duels.admin")) == null) {
pm(sender, "&c&lYour data is improperly loaded. Please try re-logging.");
if (dataManager.getUser(sender.getUniqueId(), sender.hasPermission("duels.admin")) == null) {
Helper.pm(sender, "&c&lYour data is improperly loaded. Please try re-logging.", false);
return;
}
displayStats(player, manager.getUser(player.getUniqueId(), false));
UserData target = dataManager.getUser(sender.getUniqueId(), false);
target.refreshMatches();
displayStats(sender, target);
return;
}
UUID uuid = Helper.getUUID(args[0]);
if (uuid == null) {
pm(player, "&cThat player was not found.");
Helper.pm(sender, "Errors.player-not-found", true);
return;
}
UserData target = manager.getUser(uuid, player.hasPermission("duels.admin"));
UserData target = dataManager.getUser(uuid, sender.hasPermission("duels.admin"));
if (target == null) {
pm(player, "&cThat player was not found.");
Helper.pm(sender, "Errors.player-not-found", true);
return;
}
displayStats(player, target);
target.refreshMatches();
displayStats(sender, target);
}
private void displayStats(Player base, UserData user) {
@@ -68,31 +56,22 @@ public class StatsCommand extends BaseCommand {
String wins = String.valueOf(user.get(UserData.StatsType.WINS));
String losses = String.valueOf(user.get(UserData.StatsType.LOSSES));
String requests = String.valueOf(user.canRequest() ? "enabled" : "disabled");
List<String> stats = config.getList("stats", String.class);
Helper.pm(base, "Stats.displayed", true, "{NAME}", user.getName(), "{WINS}", wins, "{LOSSES}", losses, "{REQUESTS_ENABLED}", requests);
for (String txt : stats) {
txt = Helper.replaceWithArgs(Helper.color(txt), "{NAME}", user.getName(), "{WINS}", wins, "{LOSSES}", losses, "{REQUESTS_ENABLED}", requests);
pm(base, txt);
}
if (config.isDisplayMatches()) {
for (MatchData match : user.getMatches()) {
if (config.isStatsDisplayMatches()) {
for (int i = user.getMatches().size() - 1; i >= 0; i--) {
MatchData match = user.getMatches().get(i);
String duration = Helper.toHumanReadableTime(match.getDuration());
String timeSince = Helper.toHumanReadableTime(calendar.getTimeInMillis() - match.getTime());
BaseComponent[] messages = TextComponent.fromLegacyText(Helper.replaceWithArgs(Helper.color(config.getString("match-format")), "{WINNER}", match.getWinner(), "{LOSER}", match.getLoser()));
BaseComponent[] hover = TextComponent.fromLegacyText(Helper.replaceWithArgs(Helper.color(config.getString("match-hover")), "{DURATION}", duration, "{TIME}", timeSince, "{HEALTH}", match.getHealth()));
BaseComponent[] text = TextComponent.fromLegacyText(Helper.replaceWithArgs(Helper.color(messages.getString("Stats.match-format")), "{WINNER}", match.getWinner(), "{LOSER}", match.getLoser()));
BaseComponent[] hover = TextComponent.fromLegacyText(Helper.replaceWithArgs(Helper.color(Helper.join(messages.getList("Stats.match-hover"), "\n")), "{DURATION}", duration, "{TIME}", timeSince, "{HEALTH}", match.getHealth()));
for (BaseComponent message : messages) {
message.setHoverEvent(new HoverEvent(HoverEvent.Action.SHOW_TEXT, hover));
for (BaseComponent line : text) {
line.setHoverEvent(new HoverEvent(HoverEvent.Action.SHOW_TEXT, hover));
}
base.spigot().sendMessage(messages);
base.spigot().sendMessage(text);
}
}
}
@Override
public List<String> onTabComplete(CommandSender sender, Command command, String label, String[] args) {
return null;
}
}
@@ -1,42 +1,26 @@
package me.realized.duels.commands.other;
import me.realized.duels.commands.BaseCommand;
import me.realized.duels.configuration.Config;
import me.realized.duels.data.DataManager;
import me.realized.duels.data.UserData;
import org.bukkit.command.Command;
import org.bukkit.command.CommandSender;
import me.realized.duels.utilities.Helper;
import org.bukkit.entity.Player;
import java.util.List;
public class ToggleCommand extends BaseCommand {
private final Config config;
private final DataManager manager;
public ToggleCommand() {
super("toggle", "duels.toggle");
this.config = getInstance().getConfiguration();
this.manager = getInstance().getDataManager();
}
@Override
public void execute(CommandSender sender, String[] args) {
Player player = (Player) sender;
UserData data = manager.getUser(player.getUniqueId(), true);
public void execute(Player sender, String[] args) {
UserData data = dataManager.getUser(sender.getUniqueId(), true);
if (data == null) {
pm(sender, "&c&lYour data is improperly loaded. Please try re-logging.");
Helper.pm(sender, "&c&lYour data is improperly loaded. Please try re-logging.", false);
return;
}
data.setRequestEnabled(!data.canRequest());
pm(sender, (data.canRequest() ? config.getString("on-requests-enable") : config.getString("on-requests-disable")));
}
@Override
public List<String> onTabComplete(CommandSender commandSender, Command command, String s, String[] strings) {
return null;
Helper.pm(sender, (data.canRequest() ? "Toggle.enabled" : "Toggle.disabled"), true);
}
}
@@ -1,227 +0,0 @@
package me.realized.duels.configuration;
import me.realized.duels.Core;
import org.bukkit.configuration.file.FileConfiguration;
import java.io.File;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
public class Config {
private static Config instance = null;
private final boolean fixVanish;
private final boolean fixBack;
private final boolean fixTeleport;
private final boolean fixInventoryOpen;
private final boolean cdEnabled;
private final List<String> cdMessages;
private final boolean cdProjectile;
private final boolean cdPvp;
private final int kitSelector;
private final int arenaSelector;
private final String availableArenaDisplayName;
private final String inUseArenaDisplayName;
private final boolean mecEnabled;
private final List<String> mecCommands;
private final boolean allowArenaSelecting;
private final boolean useOwnInventory;
private final boolean onlyEmptyInventory;
private final boolean teleportToLastLoc;
private final int teleportationDelay;
private final boolean dropItem;
private final boolean pickUpItem;
private final boolean blockAllCommands;
private final List<String> whitelistedCommands;
private final List<String> disabledCommands;
private final boolean dzEnabled;
private final String dzRegion;
private final boolean displayMatches;
private final Map<String, Object> messages = new HashMap<>();
public Config(Core instance) {
Config.instance = this;
File base = new File(instance.getDataFolder(), "config.yml");
if (!base.exists()) {
instance.saveResource("config.yml", true);
instance.info("Generated configuration file.");
}
FileConfiguration config = instance.getConfig();
this.fixVanish = config.getBoolean("patcher.fix-vanish", false);
this.fixBack = config.getBoolean("patcher.fix-back", true);
this.fixTeleport = config.getBoolean("patcher.fix-teleport", true);
this.fixInventoryOpen = config.getBoolean("patcher.fix-inventory-open", true);
this.cdEnabled = config.getBoolean("countdown.enabled", true);
this.cdMessages = config.isList("countdown.messages") ? config.getStringList("countdown.messages") : new ArrayList<String>();
this.cdProjectile = config.getBoolean("countdown.block-projectile", true);
this.cdPvp = config.getBoolean("countdown.block-pvp", true);
this.kitSelector = config.getInt("GUI.kit-selector", 3);
this.arenaSelector = config.getInt("GUI.arena-selector", 2);
this.availableArenaDisplayName = config.getString("GUI.available-arena-displayname", "&9{NAME}: &aAvailable");
this.inUseArenaDisplayName = config.getString("GUI.in-use-arena-displayname", "&9{NAME}: &cIn Use");
this.mecEnabled = config.getBoolean("Dueling.match-end-commands.enabled", false);
this.mecCommands = config.isList("Dueling.match-end-commands.commands") ? config.getStringList("Dueling.match-end-commands.commands") : new ArrayList<String>();
this.allowArenaSelecting = config.getBoolean("Dueling.allow-arena-selecting", true);
this.useOwnInventory = config.getBoolean("Dueling.use-own-inventory", false);
this.onlyEmptyInventory = config.getBoolean("Dueling.requires-cleared-inventory", true);
this.teleportToLastLoc = config.getBoolean("Dueling.teleport-to-latest-location", false);
this.teleportationDelay = config.getInt("Dueling.delay-until-teleport-on-win", 5);
this.dropItem = config.getBoolean("Dueling.drop-item", true);
this.pickUpItem = config.getBoolean("Dueling.pick-up-item", false);
this.blockAllCommands = config.getBoolean("Dueling.block-all-commands", false);
this.whitelistedCommands = config.isList("Dueling.whitelisted-commands") ? config.getStringList("Dueling.whitelisted-commands") : new ArrayList<String>();
this.disabledCommands = config.isList("Dueling.disabled-commands") ? config.getStringList("Dueling.disabled-commands") : new ArrayList<String>();
this.dzEnabled = config.getBoolean("DuelZone.enabled", false);
this.dzRegion = config.getString("DuelZone.region", "spawn");
this.displayMatches = config.getBoolean("Stats.display-matches", true);
for (String key : config.getConfigurationSection("Messages").getKeys(false)) {
Object result = config.get("Messages." + key);
if (result instanceof String) {
result = ((String) result).replace("{NEWLINE}", "\n");
}
messages.put(key, result);
}
}
public boolean fixVanish() {
return fixVanish;
}
public boolean fixBack() {
return fixBack;
}
public boolean fixTeleport() {
return fixTeleport;
}
public boolean fixInventoryOpen() {
return fixInventoryOpen;
}
public boolean isCdEnabled() {
return cdEnabled;
}
public List<String> getCdMessages() {
return cdMessages;
}
public boolean isCdProjectileBlocked() {
return cdProjectile;
}
public boolean isCdPvPBlocked() {
return cdPvp;
}
public int kitSelectorRows() {
return kitSelector;
}
public int arenaSelectorRows() {
return arenaSelector;
}
public String getAvailableArenaDisplayName() {
return availableArenaDisplayName;
}
public String getInUseArenaDisplayName() {
return inUseArenaDisplayName;
}
public boolean isMECEnabled() {
return mecEnabled;
}
public List<String> getMECommands() {
return mecCommands;
}
public boolean isAllowArenaSelecting() {
return allowArenaSelecting;
}
public boolean isUseOwnInventory() {
return useOwnInventory;
}
public boolean isOnlyEmptyInventory() {
return onlyEmptyInventory;
}
public boolean isTeleportToLastLoc() {
return teleportToLastLoc;
}
public int getTeleportationDelay() {
return teleportationDelay;
}
public boolean isDropItem() {
return dropItem;
}
public boolean isPickUpItem() {
return pickUpItem;
}
public boolean isBlockAllCommands() {
return blockAllCommands;
}
public List<String> getWhitelistedCommands() {
return whitelistedCommands;
}
public List<String> getDisabledCommands() {
return disabledCommands;
}
public boolean isDZEnabled() {
return dzEnabled;
}
public String getDZRegion() {
return dzRegion;
}
public boolean isDisplayMatches() {
return displayMatches;
}
public String getString(String key) {
return (String) messages.get(key);
}
@SuppressWarnings("unchecked")
public <T> List<T> getList(String key, Class<T> type) {
return (List<T>) messages.get(key);
}
public static Config getInstance() {
return instance;
}
}
@@ -0,0 +1,44 @@
package me.realized.duels.configuration;
import me.realized.duels.utilities.ICanHandleReload;
import me.realized.duels.utilities.ReloadType;
import me.realized.duels.utilities.config.Config;
import java.util.HashMap;
import java.util.Map;
public class ConfigManager implements ICanHandleReload {
private static ConfigManager instance;
private final Map<ConfigType, Config> configurations = new HashMap<>();
public ConfigManager() {
instance = this;
}
public void register(ConfigType type, Config config) {
configurations.put(type, config);
}
public Config getConfigByType(ConfigType type) {
return configurations.get(type);
}
@Override
public void handleReload(ReloadType type) {
switch (type) {
case WEAK:
getConfigByType(ConfigType.MESSAGES).reload(true);
break;
case STRONG:
for (Config config : configurations.values()) {
config.reload(true);
}
}
}
public static Config getConfig(ConfigType type) {
return instance.getConfigByType(type);
}
}
@@ -0,0 +1,8 @@
package me.realized.duels.configuration;
public enum ConfigType {
MAIN,
MESSAGES,
}
@@ -0,0 +1,263 @@
package me.realized.duels.configuration;
import me.realized.duels.Core;
import me.realized.duels.utilities.config.Config;
import java.util.ArrayList;
import java.util.List;
public class MainConfig extends Config {
// Class generated with a simple script :^) Automation is life.
private boolean patchesToggleVanishOnStart;
private boolean patchesSetBackLocation;
private boolean patchesCancelTeleportToPlayersInMatch;
private boolean patchesFixInventoryOpen;
private boolean patchesDisableMcMMOInMatch;
private boolean patchesDisablePowerLoss;
private boolean patchesStrictTeleportation;
private boolean patchesForceAllowPvp;
private boolean patchesCancelMatchIfMoved;
private boolean countdownEnabled;
private List<String> countdownMessages;
private boolean countdownBlockProjectile;
private boolean countdownBlockPvp;
private int guiKitSelectorRows;
private int guiArenaSelectorRows;
private String guiAvailableArenaDisplayname;
private String guiInUseArenaDisplayname;
private List<String> spectatingWhitelistedCommands;
private boolean duelingMatchMaxDurationEnabled;
private int duelingMatchMaxDurationDuration;
private boolean duelingMatchEndCommandsEnabled;
private List<String> duelingMatchEndCommandsCommands;
private boolean duelingAllowArenaSelecting;
private boolean duelingUseOwnInventory;
private boolean duelingRequiresClearedInventory;
private boolean duelingTeleportToLatestLocation;
private int duelingDelayUntilTeleport;
private boolean duelingDropItem;
private boolean duelingPickUpItem;
private boolean duelingBlockAllCommands;
private List<String> duelingWhitelistedCommands;
private List<String> duelingDisabledCommands;
private boolean duelZoneEnabled;
private String duelZoneRegion;
private boolean statsDisplayMatches;
private int statsAmountOfMatches;
private boolean soupEnabled;
private String soupArenasStartingWith;
private double soupHeartsToRegen;
public MainConfig(Core instance) {
super("config.yml", instance);
handleLoad();
}
@Override
public void handleLoad() {
this.patchesToggleVanishOnStart = base.getBoolean("Patches.toggle-vanish-on-start", false);
this.patchesSetBackLocation = base.getBoolean("Patches.set-back-location", true);
this.patchesCancelTeleportToPlayersInMatch = base.getBoolean("Patches.cancel-teleport-to-players-in-match", true);
this.patchesFixInventoryOpen = base.getBoolean("Patches.fix-inventory-open", true);
this.patchesDisableMcMMOInMatch = base.getBoolean("Patches.disable-mcMMO-in-match", true);
this.patchesDisablePowerLoss = base.getBoolean("Patches.disable-power-loss", true);
this.patchesStrictTeleportation = base.getBoolean("Patches.strict-teleportation", false);
this.patchesForceAllowPvp = base.getBoolean("Patches.force-allow-pvp", true);
this.patchesCancelMatchIfMoved = base.getBoolean("Patches.cancel-match-if-moved", false);
this.countdownEnabled = base.getBoolean("Countdown.enabled", true);
this.countdownMessages = base.isList("Countdown.messages") ? base.getStringList("Countdown.messages") : new ArrayList<String>();
this.countdownBlockProjectile = base.getBoolean("Countdown.block-projectile", true);
this.countdownBlockPvp = base.getBoolean("Countdown.block-pvp", true);
this.guiKitSelectorRows = base.getInt("GUI.kit-selector-rows", 3);
this.guiArenaSelectorRows = base.getInt("GUI.arena-selector-rows", 2);
this.guiAvailableArenaDisplayname = base.getString("GUI.available-arena-displayname", "&9{NAME}: &aAvailable");
this.guiInUseArenaDisplayname = base.getString("GUI.in-use-arena-displayname", "&9{NAME}: &cIn Use");
this.spectatingWhitelistedCommands = base.isList("Spectating.whitelisted-commands") ? base.getStringList("Spectating.whitelisted-commands") : new ArrayList<String>();
this.duelingMatchMaxDurationEnabled = base.getBoolean("Dueling.match-max-duration.enabled", true);
this.duelingMatchMaxDurationDuration = base.getInt("Dueling.match-max-duration.duration", 600);
this.duelingMatchEndCommandsEnabled = base.getBoolean("Dueling.match-end-commands.enabled", false);
this.duelingMatchEndCommandsCommands = base.isList("Dueling.match-end-commands.commands") ? base.getStringList("Dueling.match-end-commands.commands") : new ArrayList<String>();
this.duelingAllowArenaSelecting = base.getBoolean("Dueling.allow-arena-selecting", true);
this.duelingUseOwnInventory = base.getBoolean("Dueling.use-own-inventory", false);
this.duelingRequiresClearedInventory = base.getBoolean("Dueling.requires-cleared-inventory", true);
this.duelingTeleportToLatestLocation = base.getBoolean("Dueling.teleport-to-latest-location", false);
this.duelingDelayUntilTeleport = base.getInt("Dueling.delay-until-teleport", 5);
this.duelingDropItem = base.getBoolean("Dueling.drop-item", true);
this.duelingPickUpItem = base.getBoolean("Dueling.pick-up-item", true);
this.duelingBlockAllCommands = base.getBoolean("Dueling.block-all-commands", false);
this.duelingWhitelistedCommands = base.isList("Dueling.whitelisted-commands") ? base.getStringList("Dueling.whitelisted-commands") : new ArrayList<String>();
this.duelingDisabledCommands = base.isList("Dueling.disabled-commands") ? base.getStringList("Dueling.disabled-commands") : new ArrayList<String>();
this.duelZoneEnabled = base.getBoolean("DuelZone.enabled", false);
this.duelZoneRegion = base.getString("DuelZone.region", "spawn");
this.statsDisplayMatches = base.getBoolean("Stats.display-matches", true);
this.statsAmountOfMatches = base.getInt("Stats.amount-of-matches", 10);
this.soupEnabled = base.getBoolean("Soup.enabled", false);
this.soupArenasStartingWith = base.getString("Soup.arenas-starting-with", "soup arena");
this.soupHeartsToRegen = base.getDouble("Soup.hearts-to-regen", 3.5);
}
public boolean isPatchesToggleVanishOnStart() {
return patchesToggleVanishOnStart;
}
public boolean isPatchesSetBackLocation() {
return patchesSetBackLocation;
}
public boolean isPatchesCancelTeleportToPlayersInMatch() {
return patchesCancelTeleportToPlayersInMatch;
}
public boolean isPatchesFixInventoryOpen() {
return patchesFixInventoryOpen;
}
public boolean isPatchesDisableMcMMOInMatch() {
return patchesDisableMcMMOInMatch;
}
public boolean isPatchesDisablePowerLoss() {
return patchesDisablePowerLoss;
}
public boolean isPatchesStrictTeleportation() {
return patchesStrictTeleportation;
}
public boolean isPatchesForceAllowPvp() {
return patchesForceAllowPvp;
}
public boolean isPatchesCancelMatchIfMoved() {
return patchesCancelMatchIfMoved;
}
public boolean isCountdownEnabled() {
return countdownEnabled;
}
public List<String> getCountdownMessages() {
return countdownMessages;
}
public boolean isCountdownBlockProjectile() {
return countdownBlockProjectile;
}
public boolean isCountdownBlockPvp() {
return countdownBlockPvp;
}
public int getGuiKitSelectorRows() {
return guiKitSelectorRows;
}
public int getGuiArenaSelectorRows() {
return guiArenaSelectorRows;
}
public String getGuiAvailableArenaDisplayname() {
return guiAvailableArenaDisplayname;
}
public String getGuiInUseArenaDisplayname() {
return guiInUseArenaDisplayname;
}
public List<String> getSpectatingWhitelistedCommands() {
return spectatingWhitelistedCommands;
}
public boolean isDuelingMatchMaxDurationEnabled() {
return duelingMatchMaxDurationEnabled;
}
public int getDuelingMatchMaxDurationDuration() {
return duelingMatchMaxDurationDuration;
}
public boolean isDuelingMatchEndCommandsEnabled() {
return duelingMatchEndCommandsEnabled;
}
public List<String> getDuelingMatchEndCommandsCommands() {
return duelingMatchEndCommandsCommands;
}
public boolean isDuelingAllowArenaSelecting() {
return duelingAllowArenaSelecting;
}
public boolean isDuelingUseOwnInventory() {
return duelingUseOwnInventory;
}
public boolean isDuelingRequiresClearedInventory() {
return duelingRequiresClearedInventory;
}
public boolean isDuelingTeleportToLatestLocation() {
return duelingTeleportToLatestLocation;
}
public int getDuelingDelayUntilTeleport() {
return duelingDelayUntilTeleport;
}
public boolean isDuelingDropItem() {
return duelingDropItem;
}
public boolean isDuelingPickUpItem() {
return duelingPickUpItem;
}
public boolean isDuelingBlockAllCommands() {
return duelingBlockAllCommands;
}
public List<String> getDuelingWhitelistedCommands() {
return duelingWhitelistedCommands;
}
public List<String> getDuelingDisabledCommands() {
return duelingDisabledCommands;
}
public boolean isDuelZoneEnabled() {
return duelZoneEnabled;
}
public String getDuelZoneRegion() {
return duelZoneRegion;
}
public boolean isStatsDisplayMatches() {
return statsDisplayMatches;
}
public int getStatsAmountOfMatches() {
return statsAmountOfMatches;
}
public boolean isSoupEnabled() {
return soupEnabled;
}
public String getSoupArenasStartingWith() {
return soupArenasStartingWith;
}
public double getSoupHeartsToRegen() {
return soupHeartsToRegen;
}
}
@@ -0,0 +1,49 @@
package me.realized.duels.configuration;
import me.realized.duels.Core;
import me.realized.duels.utilities.config.Config;
import org.bukkit.configuration.MemorySection;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
public class MessagesConfig extends Config {
private final Map<String, String> strings = new HashMap<>();
private final Map<String, List<String>> lists = new HashMap<>();
public MessagesConfig(Core instance) {
super("messages.yml", instance);
handleLoad();
}
@Override
public void handleLoad() {
// Clearing in case of configuration reload
strings.clear();
lists.clear();
for (String path : base.getKeys(true)) {
Object value = base.get(path);
if (value == null || value instanceof MemorySection) {
continue;
}
if (value instanceof String) {
strings.put(path, (String) value);
} else {
lists.put(path, base.getStringList(path));
}
}
}
public String getString(String path) {
return strings.get(path);
}
public List<String> getList(String path) {
return lists.get(path);
}
}
@@ -1,6 +1,8 @@
package me.realized.duels.data;
import me.realized.duels.Core;
import me.realized.duels.utilities.ICanHandleReload;
import me.realized.duels.utilities.ReloadType;
import me.realized.duels.utilities.location.SimpleLocation;
import org.bukkit.Bukkit;
import org.bukkit.Location;
@@ -15,7 +17,7 @@ import java.io.*;
import java.util.*;
import java.util.concurrent.ConcurrentHashMap;
public class DataManager implements Listener {
public class DataManager implements Listener, ICanHandleReload {
private final Core instance;
@@ -86,10 +88,6 @@ public class DataManager implements Listener {
return null;
}
private void unloadUser(UUID uuid) {
users.remove(uuid);
}
private void saveUser(UUID uuid, boolean log) {
if (users.get(uuid) == null) {
return;
@@ -144,18 +142,29 @@ public class DataManager implements Listener {
@EventHandler(priority = EventPriority.LOWEST)
public void onJoin(PlayerJoinEvent event) {
UserData user = loadUser(event.getPlayer().getUniqueId(), event.getPlayer().getName(), true);
Player player = event.getPlayer();
UserData user = loadUser(player.getUniqueId(), player.getName(), true);
if (user != null && !user.getMatches().isEmpty()) {
if (user == null) {
return;
}
if (!user.getName().equals(player.getName())) {
user.setName(player.getName());
}
user.refreshMatches();
if (!user.getMatches().isEmpty()) {
Iterator<MatchData> iterator = user.getMatches().iterator();
Calendar now = new GregorianCalendar();
while (iterator.hasNext()) {
MatchData match = iterator.next();
if (now.getTimeInMillis() - match.getTime() > 604800 * 1000L) {
iterator.remove();
}
if (now.getTimeInMillis() - match.getTime() > 604800 * 1000L) {
iterator.remove();
}
}
}
}
@@ -163,6 +172,14 @@ public class DataManager implements Listener {
@EventHandler(priority = EventPriority.LOWEST)
public void onQuit(PlayerQuitEvent event) {
saveUser(event.getPlayer().getUniqueId(), true);
unloadUser(event.getPlayer().getUniqueId());
users.remove(event.getPlayer().getUniqueId());
}
@Override
public void handleReload(ReloadType type) {
if (type == ReloadType.STRONG) {
save();
load();
}
}
}
@@ -1,5 +1,9 @@
package me.realized.duels.data;
import me.realized.duels.configuration.ConfigManager;
import me.realized.duels.configuration.ConfigType;
import me.realized.duels.configuration.MainConfig;
import java.util.ArrayList;
import java.util.List;
import java.util.UUID;
@@ -7,7 +11,7 @@ import java.util.UUID;
public class UserData {
private final UUID uuid;
private final String name;
private String name;
private int wins = 0;
private int losses = 0;
private boolean requests = true;
@@ -26,6 +30,10 @@ public class UserData {
return name;
}
public void setName(String name) {
this.name = name;
}
public boolean canRequest() {
return requests;
}
@@ -39,11 +47,20 @@ public class UserData {
}
public void addMatch(MatchData match) {
if (matches.size() + 1 > 10) {
matches.remove(0);
matches.add(match);
refreshMatches();
}
public void refreshMatches() {
int maxMatches = ((MainConfig) ConfigManager.getConfig(ConfigType.MAIN)).getStatsAmountOfMatches();
if (maxMatches < 0) {
maxMatches = 0;
}
matches.add(match);
if (matches.size() >= maxMatches) {
matches = new ArrayList<>(matches.subList(matches.size() - maxMatches, matches.size()));
}
}
public int get(StatsType type) {
@@ -3,13 +3,15 @@ package me.realized.duels.dueling;
import me.realized.duels.Core;
import me.realized.duels.arena.Arena;
import me.realized.duels.arena.ArenaManager;
import me.realized.duels.configuration.Config;
import me.realized.duels.configuration.MainConfig;
import me.realized.duels.data.DataManager;
import me.realized.duels.data.MatchData;
import me.realized.duels.data.UserData;
import me.realized.duels.event.MatchEndEvent;
import me.realized.duels.event.MatchStartEvent;
import me.realized.duels.event.RequestSendEvent;
import me.realized.duels.hooks.EssentialsHook;
import me.realized.duels.hooks.McMMOHook;
import me.realized.duels.kits.Kit;
import me.realized.duels.kits.KitManager;
import me.realized.duels.utilities.Helper;
@@ -35,97 +37,127 @@ import java.util.*;
public class DuelManager implements Listener {
private final Core instance;
private final Config config;
private final MainConfig config;
private final EssentialsHook essentialsHook;
private final McMMOHook mcMMOHook;
private final DataManager dataManager;
private final KitManager kitManager;
private final ArenaManager arenaManager;
private final SpectatorManager spectatorManager;
public DuelManager(Core instance) {
this.instance = instance;
this.config = instance.getConfiguration();
this.essentialsHook = (EssentialsHook) instance.getHookManager().get("Essentials");
this.mcMMOHook = (McMMOHook) instance.getHookManager().get("mcMMO");
this.dataManager = instance.getDataManager();
this.kitManager = instance.getKitManager();
this.arenaManager = instance.getArenaManager();
this.spectatorManager = instance.getSpectatorManager();
Bukkit.getPluginManager().registerEvents(this, instance);
}
public void startMatch(Player player, Player target, Request request) {
boolean random;
Arena arena;
if (config.isPatchesCancelMatchIfMoved() && (target.getLocation().getX() != request.getBase().getX() || target.getLocation().getY() != request.getBase().getY() || target.getLocation().getZ() != request.getBase().getZ())) {
Helper.pm(player, "Errors.match-failed", true, "{REASON}", target.getName() + " moved after sending request.");
Helper.pm(target, "Errors.match-failed", true, "{REASON}", target.getName() + " moved after sending request.");
return;
}
if (!config.isUseOwnInventory() && config.isAllowArenaSelecting()) {
final Arena arena;
if (!config.isDuelingUseOwnInventory() && config.isDuelingAllowArenaSelecting()) {
arena = arenaManager.getArena(request.getArena());
if (arena == null || arena.isUsed()) {
Helper.pm("&cThe selected arena is no longer available, please choose a different arena.", player, target);
Helper.pm(player, "Errors.arena-no-longer-available", true);
Helper.pm(target, "Errors.arena-no-longer-available", true);
return;
}
random = false;
} else {
arena = arenaManager.getAvailableArena();
if (arena == null) {
Helper.pm("&cNo available arenas were found, please try again later.", player, target);
Helper.pm(player, "Errors.no-available-arena-found", true);
Helper.pm(target, "Errors.no-available-arena-found", true);
return;
}
random = true;
}
Location pos1 = arena.getPositions().get(1);
Location pos2 = arena.getPositions().get(2);
final Location pos1 = arena.getPositions().get(1);
final Location pos2 = arena.getPositions().get(2);
Helper.refreshChunk(pos1, pos2);
if (!Helper.canTeleportTo(player, pos1) || !Helper.canTeleportTo(target, pos2)) {
Helper.pm("&cFailed to teleport to the arena! Please contact an administrator.", player, target);
return;
}
String arenaName = request.getArena() != null ? request.getArena() : "random";
arena.setUsed(true);
arena.getCurrentMatch().setData(player, target);
player.closeInventory();
target.closeInventory();
arena.getCurrentMatch().setData(player, target);
Helper.updatePosition(player, pos1);
if (!Helper.canTeleportTo(player, pos1) || !player.teleport(pos1)) {
Helper.pm(player, "Errors.match-failed", true, "{REASON}", "Failed to teleport " + player.getName() + " to " + Helper.format(pos1));
Helper.pm(target, "Errors.match-failed", true, "{REASON}", "Failed to teleport " + player.getName() + " to " + Helper.format(pos1));
arena.setUsed(false);
return;
}
Helper.updatePosition(target, pos2);
player.teleport(pos1);
target.teleport(pos2);
if (!Helper.canTeleportTo(target, pos2) || !target.teleport(pos2)) {
Helper.pm(player, "Errors.match-failed", true, "{REASON}", "Failed to teleport " + target.getName() + " to " + Helper.format(pos2));
Helper.pm(target, "Errors.match-failed", true, "{REASON}", "Failed to teleport " + target.getName() + " to " + Helper.format(pos2));
arena.setUsed(false);
return;
}
essentialsHook.setUnvanished(player);
essentialsHook.setUnvanished(target);
mcMMOHook.disableSkills(player);
mcMMOHook.disableSkills(target);
if (!config.isUseOwnInventory()) {
if (!config.isDuelingUseOwnInventory()) {
Kit contents = kitManager.getKit(request.getKit());
Helper.reset(true, player, target);
contents.equip(player, target);
} else {
request.setKit("none");
}
arena.addPlayers(player, target);
arena.startCountdown();
Helper.pm(Helper.replaceWithArgs(config.getString("on-request-accept-target"), "{PLAYER}", target.getName(), "{KIT}", request.getKit()).replace("{ARENA}", arenaName), player);
Helper.pm(Helper.replaceWithArgs(config.getString("on-request-accept-sender"), "{PLAYER}", player.getName(), "{KIT}", request.getKit()).replace("{ARENA}", arenaName), target);
Helper.pm(player, "Dueling.on-request-accept.sender", true, "{PLAYER}", target.getName(), "{KIT}", request.getKit(), "{ARENA}", arenaName);
Helper.pm(target, "Dueling.on-request-accept.receiver", true, "{PLAYER}", player.getName(), "{KIT}", request.getKit(), "{ARENA}", arenaName);
if (arenaManager.getGUI() != null) {
arenaManager.getGUI().update(arenaManager.getArenas());
}
MatchStartEvent event = new MatchStartEvent(Collections.unmodifiableList(arena.getPlayers()), arena, random);
MatchStartEvent event = new MatchStartEvent(Collections.unmodifiableList(arena.getPlayers()), arena, request.getArena() == null);
Bukkit.getPluginManager().callEvent(event);
}
@EventHandler
public void on(RequestSendEvent event) {
if (config.isPatchesCancelMatchIfMoved()) {
Helper.pm(event.getSender(), "Dueling.do-not-move-warning", true);
}
}
@EventHandler(priority = EventPriority.HIGHEST)
public void onRespawn(PlayerRespawnEvent event) {
public void on(PlayerRespawnEvent event) {
Player player = event.getPlayer();
if (player.hasMetadata("respawn")) {
Respawn data = (Respawn) player.getMetadata("respawn").get(0).value();
event.setRespawnLocation(data.getRespawnLocation());
if (!config.isUseOwnInventory()) {
if (!config.isDuelingUseOwnInventory()) {
Helper.reset(player, false);
Helper.setInventory(player, data.getInventoryData().getInventoryContents(), data.getInventoryData().getArmorContents(), false);
Helper.setInventory(player, data.getInventoryData().getInventoryContents(), data.getInventoryData().getArmorContents());
}
player.removeMetadata("respawn", instance);
@@ -133,8 +165,8 @@ public class DuelManager implements Listener {
}
}
@EventHandler(priority = EventPriority.HIGHEST)
public void onDeath(PlayerDeathEvent event) {
@EventHandler (priority = EventPriority.HIGHEST)
public void on(PlayerDeathEvent event) {
final Player dead = event.getEntity();
if (!arenaManager.isInMatch(dead)) {
@@ -142,8 +174,10 @@ public class DuelManager implements Listener {
}
event.setDeathMessage(null);
dead.setMetadata("lastMatchDeath", new Metadata(instance, System.currentTimeMillis()));
mcMMOHook.enableSkills(dead);
if (!config.isUseOwnInventory()) {
if (!config.isDuelingUseOwnInventory()) {
event.setKeepLevel(true);
event.setDroppedExp(0);
event.getDrops().clear();
@@ -157,7 +191,7 @@ public class DuelManager implements Listener {
Arena.InventoryData deadData = match.getInventories(dead.getUniqueId());
final Location lobby = dataManager.getLobby() != null ? dataManager.getLobby() : dead.getWorld().getSpawnLocation();
if (config.isTeleportToLastLoc()) {
if (config.isDuelingTeleportToLatestLocation()) {
dead.setMetadata("respawn", new Metadata(Core.getInstance(), new Respawn(deadData, match.getLocation(dead.getUniqueId()))));
} else {
dead.setMetadata("respawn", new Metadata(Core.getInstance(), new Respawn(deadData, lobby)));
@@ -169,7 +203,7 @@ public class DuelManager implements Listener {
FireworkMeta meta = firework.getFireworkMeta();
meta.addEffect(FireworkEffect.builder().withColor(Color.RED).with(FireworkEffect.Type.BALL_LARGE).withTrail().build());
firework.setFireworkMeta(meta);
Bukkit.broadcastMessage(Helper.color(config.getString("on-duel-end").replace("{WINNER}", target.getName()).replace("{LOSER}", dead.getName()).replace("{HEALTH}", String.valueOf(Math.round(target.getHealth()) * 0.5D))));
Helper.broadcast("Dueling.on-match-end", "{WINNER}", target.getName(), "{LOSER}", dead.getName(), "{HEALTH}", Math.round(target.getHealth()) * 0.5D);
Calendar calendar = new GregorianCalendar();
match.setEndTimeMillis(System.currentTimeMillis());
@@ -185,7 +219,7 @@ public class DuelManager implements Listener {
opponent.edit(UserData.EditType.ADD, UserData.StatsType.WINS, 1);
}
int delay = config.getTeleportationDelay();
int delay = config.getDuelingDelayUntilTeleport();
final Location last = arena.getCurrentMatch().getLocation(target.getUniqueId());
final Arena.InventoryData targetData = match.getInventories(target.getUniqueId());
@@ -204,35 +238,37 @@ public class DuelManager implements Listener {
}
private void handleEnd(Arena arena, Player dead, Player target, Arena.InventoryData data, Location lobby, Location last) {
spectatorManager.handleMatchEnd(arena);
if (target.isOnline() && !target.isDead()) {
arena.removePlayer(target.getUniqueId());
if (!config.isTeleportToLastLoc()) {
if (!config.isDuelingTeleportToLatestLocation()) {
target.teleport(lobby);
} else {
target.teleport(last);
}
essentialsHook.setBackLocation(target, target.getLocation());
mcMMOHook.enableSkills(target);
if (!config.isUseOwnInventory()) {
if (!config.isDuelingUseOwnInventory()) {
Helper.reset(target, true);
if (!config.isOnlyEmptyInventory()) {
Helper.setInventory(target, data.getInventoryContents(), data.getArmorContents(), false);
if (!config.isDuelingRequiresClearedInventory()) {
Helper.setInventory(target, data.getInventoryContents(), data.getArmorContents());
}
}
}
if (config.isMECEnabled()) {
for (String command : config.getMECommands()) {
if (config.isDuelingMatchEndCommandsEnabled()) {
for (String command : config.getDuelingMatchEndCommandsCommands()) {
Bukkit.dispatchCommand(Bukkit.getConsoleSender(), command.replace("{WINNER}", target.getName()).replace("{LOSER}", dead.getName()));
}
}
MatchEndEvent event = new MatchEndEvent(Collections.unmodifiableList(Arrays.asList(dead.getUniqueId(), target.getUniqueId())), arena);
Bukkit.getPluginManager().callEvent(event);
arena.setUsed(false);
if (arenaManager.getGUI() != null) {
@@ -241,7 +277,7 @@ public class DuelManager implements Listener {
}
@EventHandler
public void onQuit(PlayerQuitEvent event) {
public void on(PlayerQuitEvent event) {
Player player = event.getPlayer();
if (!arenaManager.isInMatch(player)) {
@@ -251,54 +287,67 @@ public class DuelManager implements Listener {
player.setHealth(0.0D);
}
@EventHandler (priority = EventPriority.HIGHEST)
public void onTeleport(PlayerTeleportEvent event) {
if (event.isCancelled()) {
@EventHandler (priority = EventPriority.HIGHEST, ignoreCancelled = true)
public void on(PlayerTeleportEvent event) {
Player base = event.getPlayer();
Location from = event.getFrom();
Location to = event.getTo();
if (!config.isPatchesStrictTeleportation() && from.distance(to) < 1.0) {
return;
}
Player player = event.getPlayer();
Location to = event.getTo();
PlayerTeleportEvent.TeleportCause cause = event.getCause();
if (event.getCause() == PlayerTeleportEvent.TeleportCause.COMMAND && config.fixTeleport() && !player.isOp() && !player.hasPermission("duels.admin") && !arenaManager.isInMatch(player)) {
if (cause == PlayerTeleportEvent.TeleportCause.COMMAND && config.isPatchesCancelTeleportToPlayersInMatch() && !base.isOp() && !base.hasPermission("duels.admin") && !arenaManager.isInMatch(base)) {
for (Arena arena : arenaManager.getArenas()) {
for (UUID uuid : arena.getPlayers()) {
Player arenaPlayer = Bukkit.getPlayer(uuid);
Player player = Bukkit.getPlayer(uuid);
if (arenaPlayer != null && arenaPlayer.getWorld().equals(to.getWorld()) && arenaPlayer.getLocation().distance(to) < 1.0) {
Helper.pm("&cThat player is currently in a match!", player);
if (player != null && player.getWorld().equals(base.getWorld()) && player.getLocation().distance(to) <= 5.0) {
Helper.pm(base, "Errors.already-in-match.target", true);
event.setCancelled(true);
return;
}
}
}
for (Spectator spectator : spectatorManager.getSpectators()) {
Player player = Bukkit.getPlayer(spectator.getOwner());
if (player != null && player.getWorld().equals(base.getWorld()) && player.getLocation().distance(to) <= 5.0) {
Helper.pm(base, "Errors.is-in-spectator-mode.target", true);
event.setCancelled(true);
return;
}
}
}
if (event.getCause() == PlayerTeleportEvent.TeleportCause.ENDER_PEARL || !arenaManager.isInMatch(player)) {
if (cause == PlayerTeleportEvent.TeleportCause.ENDER_PEARL || !arenaManager.isInMatch(base)) {
return;
}
event.setCancelled(true);
Helper.pm("&cYou may not teleport while in duel.", player);
Helper.pm(base, "Errors.blocked-while-in-match.teleport", true);
}
@EventHandler
public void onDrop(PlayerDropItemEvent event) {
public void on(PlayerDropItemEvent event) {
Player player = event.getPlayer();
if (config.isDropItem() || !arenaManager.isInMatch(player)) {
if (config.isDuelingDropItem() || !arenaManager.isInMatch(player)) {
return;
}
event.setCancelled(true);
Helper.pm("&cYou may not drop items while in duel.", player);
Helper.pm(player, "Errors.blocked-while-in-match.drop-item", true);
}
@EventHandler
public void onPickup(PlayerPickupItemEvent event) {
public void on(PlayerPickupItemEvent event) {
Player player = event.getPlayer();
if (config.isPickUpItem() || !arenaManager.isInMatch(player)) {
if (config.isDuelingPickUpItem() || !arenaManager.isInMatch(player)) {
return;
}
@@ -306,30 +355,30 @@ public class DuelManager implements Listener {
}
@EventHandler
public void onCommand(PlayerCommandPreprocessEvent event) {
public void on(PlayerCommandPreprocessEvent event) {
Player player = event.getPlayer();
String command = event.getMessage().substring(1).split(" ")[0].toLowerCase();
if (arenaManager.isInMatch(player) && ((config.isBlockAllCommands() && !config.getWhitelistedCommands().contains(command)) || (!config.isBlockAllCommands() && config.getDisabledCommands().contains(command)))) {
if (arenaManager.isInMatch(player) && ((config.isDuelingBlockAllCommands() && !config.getDuelingWhitelistedCommands().contains(command)) || (!config.isDuelingBlockAllCommands() && config.getDuelingDisabledCommands().contains(command)))) {
event.setCancelled(true);
Helper.pm("&cYou may not use that command while in duel.", player);
Helper.pm(player, "Errors.blocked-while-in-match.command", true);
}
}
@EventHandler
public void onFlyToggle(PlayerToggleFlightEvent event) {
public void on(PlayerToggleFlightEvent event) {
if (event.isFlying() && arenaManager.isInMatch(event.getPlayer())) {
event.setCancelled(true);
event.getPlayer().setAllowFlight(false);
Helper.pm("&cYou may not fly while in duel.", event.getPlayer());
Helper.pm(event.getPlayer(), "Errors.blocked-while-in-match.fly", true);
}
}
@EventHandler
public void onInventoryOpen(InventoryOpenEvent event) {
if (config.fixInventoryOpen() && arenaManager.isInMatch((Player) event.getPlayer())) {
public void on(InventoryOpenEvent event) {
if (config.isPatchesFixInventoryOpen() && arenaManager.isInMatch((Player) event.getPlayer())) {
event.setCancelled(true);
Helper.pm("&cYou may not open inventory while in duel.", (Player) event.getPlayer());
Helper.pm(event.getPlayer(), "Errors.blocked-while-in-match.open-inventory", true);
}
}
@@ -1,13 +1,16 @@
package me.realized.duels.dueling;
import org.bukkit.Location;
import java.util.UUID;
public class Request {
private final UUID sender;
private final UUID target;
private final String kit;
private String kit;
private final String arena;
private final Location base;
private final long time;
public Request(UUID sender, UUID target, Settings settings) {
@@ -15,6 +18,7 @@ public class Request {
this.target = target;
this.kit = settings.getKit();
this.arena = settings.getArena();
this.base = settings.getBase();
this.time = System.currentTimeMillis();
}
@@ -30,10 +34,18 @@ public class Request {
return kit;
}
public void setKit(String kit) {
this.kit = kit;
}
public String getArena() {
return arena;
}
public Location getBase() {
return base;
}
public long getTime() {
return time;
}
@@ -1,10 +1,12 @@
package me.realized.duels.dueling;
import me.realized.duels.utilities.ICanHandleReload;
import me.realized.duels.utilities.ReloadType;
import org.bukkit.entity.Player;
import java.util.*;
public class RequestManager {
public class RequestManager implements ICanHandleReload {
private Map<UUID, List<Request>> requests = new HashMap<>();
@@ -89,6 +91,13 @@ public class RequestManager {
}
}
@Override
public void handleReload(ReloadType type) {
if (type == ReloadType.STRONG) {
requests.clear();
}
}
public enum Result {
NOT_FOUND, TIMED_OUT, FOUND
@@ -1,16 +1,20 @@
package me.realized.duels.dueling;
import org.bukkit.Location;
import java.util.UUID;
public class Settings {
private final UUID target;
private final Location base;
private String kit;
private String arena;
public Settings(UUID target) {
public Settings(UUID target, Location base) {
this.target = target;
this.base = base;
}
public UUID getTarget() {
@@ -32,4 +36,8 @@ public class Settings {
public void setArena(String arena) {
this.arena = arena;
}
public Location getBase() {
return base;
}
}
@@ -0,0 +1,53 @@
package me.realized.duels.dueling;
import me.realized.duels.arena.Arena;
import org.bukkit.Location;
import org.bukkit.entity.Player;
import java.util.UUID;
class Spectator {
private final UUID owner;
private final String spectating;
private final Location base;
private final Arena target;
public Spectator(Player base, String spectating, Arena target) {
this.owner = base.getUniqueId();
this.spectating = spectating;
this.base = base.getLocation().clone();
this.target = target;
}
public UUID getOwner() {
return owner;
}
public String getSpectatingName() {
return spectating;
}
public Location getBase() {
return base;
}
public Arena getTarget() {
return target;
}
@Override
public boolean equals(Object o) {
if (this == o) return true;
if (o == null || getClass() != o.getClass()) return false;
Spectator spectator = (Spectator) o;
return owner != null ? owner.equals(spectator.owner) : spectator.owner == null;
}
@Override
public int hashCode() {
return owner != null ? owner.hashCode() : 0;
}
}
@@ -0,0 +1,315 @@
package me.realized.duels.dueling;
import me.realized.duels.Core;
import me.realized.duels.arena.Arena;
import me.realized.duels.arena.ArenaManager;
import me.realized.duels.configuration.MainConfig;
import me.realized.duels.hooks.EssentialsHook;
import me.realized.duels.utilities.Helper;
import me.realized.duels.utilities.compat.CompatHelper;
import me.realized.duels.utilities.inventory.ItemBuilder;
import org.bukkit.Bukkit;
import org.bukkit.Material;
import org.bukkit.entity.Player;
import org.bukkit.event.EventHandler;
import org.bukkit.event.EventPriority;
import org.bukkit.event.Listener;
import org.bukkit.event.entity.EntityDamageByEntityEvent;
import org.bukkit.event.inventory.InventoryClickEvent;
import org.bukkit.event.inventory.InventoryDragEvent;
import org.bukkit.event.player.*;
import org.bukkit.inventory.ItemStack;
import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;
import java.util.UUID;
public class SpectatorManager implements Listener {
private final MainConfig config;
private final EssentialsHook hook;
private final ArenaManager manager;
private List<Spectator> spectators = new ArrayList<>();
public SpectatorManager(Core instance) {
this.config = instance.getConfiguration();
this.hook = (EssentialsHook) instance.getHookManager().get("Essentials");
this.manager = instance.getArenaManager();
Bukkit.getPluginManager().registerEvents(this, instance);
}
public void spectate(Player base, Player target) {
if (isSpectating(base)) {
Helper.pm(base, "Errors.already-spectating", true);
return;
}
if (manager.isInMatch(base)) {
Helper.pm(base, "Errors.already-in-match.sender", true);
return;
}
Arena arena = manager.getArena(target);
if (arena == null) {
Helper.pm(base, "Errors.players-in-match-only", true);
return;
}
Spectator spectator = new Spectator(base, target.getName(), arena);
// Hide the base player from the players in match
for (UUID uuid : arena.getPlayers()) {
Player player = Bukkit.getPlayer(uuid);
if (player == null) {
continue;
}
player.hidePlayer(base);
}
base.getInventory().setItem(8, ItemBuilder.builder().type(Material.REDSTONE).name("&cStop Spectating").build());
// Teleport before adding to spectators to prevent tp getting cancelled
base.teleport(target, PlayerTeleportEvent.TeleportCause.SPECTATE);
base.setAllowFlight(true);
base.setFlying(true);
// Finally add to spectators
spectators.add(spectator);
Helper.pm(base, "Spectating.started-spectating", true, "{PLAYER}", target.getName());
if (base.hasPermission("duels.spectate.anonymously")) {
return;
}
Helper.broadcast(arena, "Spectating.arena-broadcast", "{PLAYER}", base.getName());
}
private Spectator getByPlayer(Player player) {
for (Spectator spectator : spectators) {
if (spectator.getOwner().equals(player.getUniqueId())) {
return spectator;
}
}
return null;
}
public boolean isSpectating(Player player) {
return getByPlayer(player) != null;
}
public void stopSpectating(Player base) {
stopSpectating(base, getByPlayer(base));
}
private void stopSpectating(Player base, Spectator spectator) {
spectators.remove(spectator);
Helper.reset(base, false);
base.setFlying(false);
base.setAllowFlight(false);
base.teleport(spectator.getBase());
for (UUID uuid : spectator.getTarget().getPlayers()) {
Player player = Bukkit.getPlayer(uuid);
if (player == null) {
continue;
}
player.showPlayer(base);
}
Helper.pm(base, "Spectating.stopped-spectating", true, "{PLAYER}", spectator.getSpectatingName());
}
public void handleMatchEnd(Arena arena) {
Iterator<Spectator> iterator = spectators.iterator();
while (iterator.hasNext()) {
Spectator spectator = iterator.next();
if (!spectator.getTarget().equals(arena)) {
continue;
}
Player base = Bukkit.getPlayer(spectator.getOwner());
iterator.remove();
// Just in case
if (base == null) {
continue;
}
Helper.reset(base, false);
base.setFlying(false);
base.setAllowFlight(false);
base.teleport(spectator.getBase());
hook.setBackLocation(base, spectator.getBase());
for (UUID uuid : arena.getPlayers()) {
Player player = Bukkit.getPlayer(uuid);
if (player == null) {
continue;
}
player.showPlayer(base);
}
Helper.pm(base, "Spectating.spectating-match-ended", true);
}
}
public List<Spectator> getSpectators() {
return spectators;
}
// Cancel any command except whitelisted commands while in spectator mode.
@EventHandler (priority = EventPriority.HIGHEST, ignoreCancelled = true)
public void on(PlayerCommandPreprocessEvent event) {
Player player = event.getPlayer();
if (!isSpectating(player)) {
return;
}
String command = event.getMessage().substring(1).split(" ")[0].toLowerCase();
if (command.isEmpty() || command.equalsIgnoreCase("spectate") || command.equalsIgnoreCase("spec") || config.getSpectatingWhitelistedCommands().contains(command)) {
return;
}
event.setCancelled(true);
Helper.pm(player, "Errors.cannot-use-while-spectating", true);
}
// Cancel any type of teleportation in spectator mode.
@EventHandler (priority = EventPriority.HIGHEST, ignoreCancelled = true)
public void on(PlayerTeleportEvent event) {
Player player = event.getPlayer();
if (!isSpectating(player)) {
return;
}
event.setCancelled(true);
Helper.pm(player, "Errors.cannot-use-while-spectating", true);
}
// Cancel dropping item while spectating.
@EventHandler (ignoreCancelled = true)
public void on(PlayerDropItemEvent event) {
Player player = event.getPlayer();
if (!isSpectating(player)) {
return;
}
event.setCancelled(true);
Helper.pm(player, "Errors.cannot-use-while-spectating", true);
}
// Cancel pickup while spectating.
@EventHandler (ignoreCancelled = true)
public void on(PlayerPickupItemEvent event) {
Player player = event.getPlayer();
if (!isSpectating(player)) {
return;
}
event.setCancelled(true);
}
// Listen to stopSpectating
@SuppressWarnings("deprecation")
@EventHandler
public void on(PlayerInteractEvent event) {
if (!event.getAction().name().startsWith("RIGHT")) {
return;
}
Player base = event.getPlayer();
ItemStack held;
if (CompatHelper.isPre1_9()) {
held = base.getInventory().getItemInHand();
} else {
held = base.getInventory().getItemInMainHand();
}
if (held == null || held.getType() != Material.REDSTONE) {
return;
}
Spectator spectator = getByPlayer(base);
if (spectator == null) {
return;
}
stopSpectating(base, spectator);
}
// Listen to spectator quitting, set back to starting location
@EventHandler
public void on(PlayerQuitEvent event) {
Player base = event.getPlayer();
Spectator spectator = getByPlayer(base);
if (spectator == null) {
return;
}
spectators.remove(spectator);
Helper.reset(base, false);
base.setFlying(false);
base.setAllowFlight(false);
base.teleport(spectator.getBase());
hook.setBackLocation(base, spectator.getBase());
}
// Listen to any type of inventory interaction
@EventHandler (ignoreCancelled = true)
public void on(InventoryClickEvent event) {
Player player = (Player) event.getWhoClicked();
if (!isSpectating(player)) {
return;
}
event.setCancelled(true);
}
@EventHandler
public void on(InventoryDragEvent event) {
Player player = (Player) event.getWhoClicked();
if (!isSpectating(player)) {
return;
}
event.setCancelled(true);
}
// Cancel any type of damaging.
@EventHandler (ignoreCancelled = true)
public void on(EntityDamageByEntityEvent event) {
if (!(event.getDamager() instanceof Player)) {
return;
}
Player damager = (Player) event.getDamager();
if (!isSpectating(damager)) {
return;
}
event.setCancelled(true);
Helper.pm(damager, "Errors.cannot-use-while-spectating", true);
}
}
@@ -3,25 +3,21 @@ package me.realized.duels.hooks;
import com.earth2me.essentials.Essentials;
import com.earth2me.essentials.User;
import me.realized.duels.Core;
import me.realized.duels.configuration.Config;
import me.realized.duels.configuration.MainConfig;
import org.bukkit.Location;
import org.bukkit.entity.Player;
public class EssentialsHook extends PluginHook {
private final Config config;
private final MainConfig config;
public EssentialsHook(Core instance) {
super("Essentials");
this.config = instance.getConfiguration();
if (isEnabled()) {
instance.info("Hooked into Essentials! 'patcher' options are now functional.");
}
}
public void setUnvanished(Player player) {
if (!config.fixVanish() || !isEnabled()) {
if (!config.isPatchesToggleVanishOnStart() || !isEnabled()) {
return;
}
@@ -29,13 +25,14 @@ public class EssentialsHook extends PluginHook {
User user = essentials.getUser(player);
if (user != null) {
user.setVanished(false);
user.setVanished(true);
user.setVanished(false);
}
}
public void setBackLocation(Player player, Location location) {
if (!config.fixBack() || !isEnabled()) {
if (!config.isPatchesSetBackLocation() || !isEnabled()) {
return;
}
@@ -0,0 +1,42 @@
package me.realized.duels.hooks;
import com.massivecraft.factions.FPlayer;
import com.massivecraft.factions.event.PowerLossEvent;
import me.realized.duels.Core;
import me.realized.duels.configuration.MainConfig;
import org.bukkit.Bukkit;
import org.bukkit.event.EventHandler;
import org.bukkit.event.Listener;
public class FactionsHook extends PluginHook implements Listener {
private final MainConfig config;
public FactionsHook(Core instance) {
super("Factions");
this.config = instance.getConfiguration();
if (isEnabled()) {
Bukkit.getPluginManager().registerEvents(this, instance);
}
}
@EventHandler
public void onPowerLoss(PowerLossEvent event) {
if (!config.isPatchesDisablePowerLoss()) {
return;
}
long now = System.currentTimeMillis();
FPlayer player = event.getfPlayer();
if (player.getPlayer().hasMetadata("lastMatchDeath")) {
long value = (long) player.getPlayer().getMetadata("lastMatchDeath").get(0).value();
if (now - value < 1000L) {
event.setMessage("");
event.setCancelled(true);
}
}
}
}
@@ -1,5 +1,6 @@
package me.realized.duels.hooks;
import me.realized.duels.Core;
import org.bukkit.Bukkit;
import org.bukkit.plugin.Plugin;
@@ -9,6 +10,10 @@ public class PluginHook {
public PluginHook(String name) {
this.name = name;
if (isEnabled()) {
Core.getInstance().info("Successfully hooked into " + name + ".");
}
}
public boolean isEnabled() {
@@ -4,28 +4,24 @@ import com.sk89q.worldguard.bukkit.WorldGuardPlugin;
import com.sk89q.worldguard.protection.ApplicableRegionSet;
import com.sk89q.worldguard.protection.regions.ProtectedRegion;
import me.realized.duels.Core;
import me.realized.duels.configuration.Config;
import me.realized.duels.configuration.MainConfig;
import org.bukkit.entity.Player;
public class WorldGuardHook extends PluginHook {
private final Config config;
private final MainConfig config;
public WorldGuardHook(Core instance) {
super("WorldGuard");
this.config = instance.getConfiguration();
if (isEnabled()) {
instance.info("Hooked into WorldGuard! 'DuelZone' option is now functional.");
}
}
public boolean canUseDuelCommands(Player player) {
if (!isEnabled() || !config.isDZEnabled()) {
if (!isEnabled() || !config.isDuelZoneEnabled()) {
return true;
}
String name = config.getDZRegion();
String name = config.getDuelZoneRegion();
WorldGuardPlugin worldguard = (WorldGuardPlugin) getPlugin();
ApplicableRegionSet regions = worldguard.getRegionManager(player.getWorld()).getApplicableRegions(player.getLocation());
@@ -0,0 +1,53 @@
package me.realized.duels.hooks;
import me.realized.duels.Core;
import me.realized.duels.configuration.MainConfig;
import org.bukkit.entity.Player;
import org.bukkit.permissions.PermissionAttachment;
import java.util.*;
public class McMMOHook extends PluginHook {
private final Core instance;
private final MainConfig config;
private final List<String> skills = Arrays.asList("swords", "archery", "axes", "taming", "unarmed");
private Map<UUID, PermissionAttachment> attachments = new HashMap<>();
public McMMOHook(Core instance) {
super("mcMMO");
this.instance = instance;
this.config = instance.getConfiguration();
}
public void disableSkills(Player player) {
if (!isEnabled() || !config.isPatchesDisableMcMMOInMatch()) {
return;
}
if (!attachments.containsKey(player.getUniqueId())) {
attachments.put(player.getUniqueId(), player.addAttachment(instance));
}
PermissionAttachment attachment = attachments.get(player.getUniqueId());
for (String skill : skills) {
String permission = "mcmmo.skills." + skill;
if (player.hasPermission(permission)) {
attachment.setPermission(permission, false);
}
}
attachment.getPermissible().recalculatePermissions();
}
public void enableSkills(Player player) {
if (!isEnabled() || !config.isPatchesDisableMcMMOInMatch() || !attachments.containsKey(player.getUniqueId())) {
return;
}
player.removeAttachment(attachments.get(player.getUniqueId()));
}
}
@@ -1,6 +1,6 @@
package me.realized.duels.kits;
import me.realized.duels.gui.ICanHandleGUI;
import me.realized.duels.utilities.gui.ICanHandleGUI;
import me.realized.duels.utilities.inventory.ItemBuilder;
import org.bukkit.Material;
import org.bukkit.entity.Player;
@@ -3,14 +3,17 @@ package me.realized.duels.kits;
import com.google.gson.reflect.TypeToken;
import me.realized.duels.Core;
import me.realized.duels.arena.ArenaManager;
import me.realized.duels.configuration.Config;
import me.realized.duels.configuration.MainConfig;
import me.realized.duels.data.KitData;
import me.realized.duels.dueling.RequestManager;
import me.realized.duels.dueling.Settings;
import me.realized.duels.event.RequestSendEvent;
import me.realized.duels.gui.GUI;
import me.realized.duels.utilities.Helper;
import me.realized.duels.utilities.ICanHandleReload;
import me.realized.duels.utilities.Metadata;
import me.realized.duels.utilities.ReloadType;
import me.realized.duels.utilities.gui.GUI;
import me.realized.duels.utilities.gui.GUIListener;
import org.bukkit.Bukkit;
import org.bukkit.Material;
import org.bukkit.entity.Player;
@@ -26,10 +29,10 @@ import java.util.HashMap;
import java.util.List;
import java.util.Map;
public class KitManager implements Listener {
public class KitManager implements Listener, ICanHandleReload {
private final Core instance;
private final Config config;
private final MainConfig config;
private final ArenaManager arenaManager;
private final RequestManager requestManager;
private final File base;
@@ -72,7 +75,7 @@ public class KitManager implements Listener {
}
instance.info("Loaded " + kits.size() + " kit(s).");
gui = new GUI<>("Kit Selection", new ArrayList<>(kits.values()), config.kitSelectorRows(), new GUI.ClickListener() {
gui = new GUI<>("Kit Selection", new ArrayList<>(kits.values()), config.getGuiKitSelectorRows(), new GUIListener() {
@Override
public void onClick(InventoryClickEvent event) {
@@ -95,13 +98,13 @@ public class KitManager implements Listener {
if (target == null) {
player.closeInventory();
Helper.pm("&cThat player is no longer online.", player);
Helper.pm(player, "Errors.player-left", true);
return;
}
if (arenaManager.isInMatch(target)) {
player.closeInventory();
Helper.pm("&cThat player is already in a match.", player);
Helper.pm(player, "Errors.already-in-match.target", true);
return;
}
@@ -113,11 +116,12 @@ public class KitManager implements Listener {
settings.setKit(kit.getName());
if (!config.isAllowArenaSelecting()) {
if (!config.isDuelingAllowArenaSelecting()) {
requestManager.sendRequestTo(player, target, settings);
player.closeInventory();
Helper.pm(config.getString("on-request-send").replace("{PLAYER}", target.getName()).replace("{KIT}", kit.getName()).replace("{ARENA}", "random"), player);
Helper.pm(config.getString("on-request-receive").replace("{PLAYER}", player.getName()).replace("{KIT}", kit.getName()).replace("{ARENA}", "random"), target);
Helper.pm(player, "Dueling.on-request-send.sender", true, "{PLAYER}", target.getName(), "{KIT}", settings.getKit(), "{ARENA}", "random");
Helper.pm(target, "Dueling.on-request-send.receiver", true, "{PLAYER}", player.getName(), "{KIT}", settings.getKit(), "{ARENA}", "random");
RequestSendEvent requestSendEvent = new RequestSendEvent(requestManager.getRequestTo(player, target), player, target);
Bukkit.getPluginManager().callEvent(requestSendEvent);
@@ -207,6 +211,14 @@ public class KitManager implements Listener {
return result;
}
@Override
public void handleReload(ReloadType type) {
if (type == ReloadType.STRONG) {
save();
load();
}
}
public enum Type {
INVENTORY, ARMOR
@@ -1,8 +1,13 @@
package me.realized.duels.utilities;
import me.realized.duels.Core;
import me.realized.duels.arena.Arena;
import me.realized.duels.configuration.ConfigManager;
import me.realized.duels.configuration.ConfigType;
import me.realized.duels.configuration.MessagesConfig;
import org.bukkit.*;
import org.bukkit.block.Block;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;
import org.bukkit.event.inventory.InventoryType;
import org.bukkit.event.player.PlayerTeleportEvent;
@@ -11,15 +16,12 @@ import org.bukkit.inventory.ItemStack;
import org.bukkit.potion.PotionEffect;
import org.bukkit.scheduler.BukkitRunnable;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.UUID;
import java.util.*;
import java.util.regex.Pattern;
public class Helper {
private static final Map<String, Profile> uuidCache = new HashMap<>();
private static Map<String, Profile> uuidCache = new HashMap<>();
@SuppressWarnings("deprecation")
public static UUID getUUID(String username) {
@@ -77,10 +79,10 @@ public class Helper {
}
}
private static final Pattern ALPHANUMERIC = Pattern.compile("^[a-zA-Z0-9]*$");
private static final Pattern ALPHANUMERIC = Pattern.compile("^[a-zA-Z0-9_-]*$");
public static boolean isAlphanumeric(String input) {
return ALPHANUMERIC.matcher(input).matches();
return ALPHANUMERIC.matcher(input.replace(" ", "")).matches();
}
public static String toHumanReadableTime(long ms) {
@@ -172,6 +174,10 @@ public class Helper {
return txt;
}
public static String join(String[] args, int start, int end, String joiner) {
return join(Arrays.asList(Arrays.copyOfRange(args, start, end)), joiner);
}
public static String join(List<String> list, String joiner) {
StringBuilder builder = new StringBuilder();
@@ -210,12 +216,6 @@ public class Helper {
}
public static void pm(String msg, Player... players) {
for (Player player : players) {
player.sendMessage(color(msg));
}
}
private static void extinguish(final Player player) {
new BukkitRunnable() {
@@ -256,22 +256,10 @@ public class Helper {
}
}
public static void setInventory(final Player player, final ItemStack[] inventory, final ItemStack[] armor, boolean delayed) {
if (!delayed) {
player.getInventory().setContents(inventory);
player.getInventory().setArmorContents(armor);
player.updateInventory();
} else {
new BukkitRunnable() {
@Override
public void run() {
player.getInventory().setContents(inventory);
player.getInventory().setArmorContents(armor);
player.updateInventory();
}
}.runTaskLater(Core.getInstance(), 1L);
}
public static void setInventory(final Player player, final ItemStack[] inventory, final ItemStack[] armor) {
player.getInventory().setContents(inventory);
player.getInventory().setArmorContents(armor);
player.updateInventory();
}
public static boolean hasEmptyInventory(Player player) {
@@ -317,4 +305,54 @@ public class Helper {
player.sendBlockChange(location, block.getType(), (byte) 0);
}
public static void pm(CommandSender sender, String in, boolean isConfigMessage, Object... replacers) {
if (isConfigMessage) {
MessagesConfig messages = (MessagesConfig) ConfigManager.getConfig(ConfigType.MESSAGES);
String string = messages.getString(in);
if (string != null) {
sender.sendMessage(color(replaceWithArgs(string, replacers)));
return;
}
List<String> list = messages.getList(in);
if (list != null) {
for (String txt : list) {
sender.sendMessage(color(replaceWithArgs(txt, replacers)));
}
}
} else {
sender.sendMessage(color(replaceWithArgs(in, replacers)));
}
}
public static void broadcast(Arena arena, String in, Object... replacers) {
MessagesConfig messages = (MessagesConfig) ConfigManager.getConfig(ConfigType.MESSAGES);
String string = messages.getString(in);
List<String> list = messages.getList(in);
if (string != null) {
arena.broadcast(color(replaceWithArgs(string, replacers)));
} else if (list != null) {
for (String txt : list) {
arena.broadcast(color(replaceWithArgs(txt, replacers)));
}
}
}
public static void broadcast(String in, Object... replacers) {
MessagesConfig messages = (MessagesConfig) ConfigManager.getConfig(ConfigType.MESSAGES);
String string = messages.getString(in);
List<String> list = messages.getList(in);
if (string != null) {
Bukkit.broadcastMessage(color(replaceWithArgs(string, replacers)));
} else if (list != null) {
for (String txt : list) {
Bukkit.broadcastMessage(color(replaceWithArgs(txt, replacers)));
}
}
}
}
@@ -0,0 +1,6 @@
package me.realized.duels.utilities;
public interface ICanHandleReload {
void handleReload(ReloadType type);
}
@@ -1,63 +0,0 @@
package me.realized.duels.utilities;
import java.util.Arrays;
import java.util.List;
public enum Lang {
ARENA_CREATE("&7Arena &f{NAME} &7was successfully created.", false),
ARENA_DELETE("&7Arena &f{NAME} &7was successfully deleted.", false),
ARENA_INFO(Arrays.asList(
"&b&m------------------------------------",
"&7Displaying info of arena &f{NAME} &7-",
"&7Disabled: &f{DISABLED}", "&7In use: &f{IN_USE}",
"&7Players: &f{PLAYERS}",
"&7Locations: &f{LOCATIONS}",
"&b&m------------------------------------"), false),
ARENA_TOGGLE_ON("&a&lArena {NAME} is now enabled!", false),
ARENA_TOGGLE_OFF("&c&lArena {NAME} is now disabled!", false),
ARENA_SET_POSITION("&7Set spawn position for player &f{POSITION} &7for arena &f{NAME}&7.", false),
KIT_CREATE("&7Saved kit &f{NAME}&7!", false),
KIT_DELETE("&7Deleted kit &f{NAME}&7!", false),
KIT_LOAD("&7Loaded kit &f{NAME} &7to your inventory.", false),
REPLACE_KIT_ITEM("&7Kit &f{NAME}&7's displayed item in Kit Selection GUI was set to your held item.", false),
LIST(Arrays.asList(
"&b&m------------------------------------",
"&7Arena name color states:",
"&4DARK RED&7: Arena is disabled.",
"&9BLUE&7: Arena without valid spawn positions set.",
"&aGREEN&7: Arena available for a match.",
"&cRED&7: Arena in use.",
"&7Arenas: &r{ARENAS}",
"&7Kits: &r{KITS}",
"&7Lobby Location: &r{LOBBY}",
"&b&m------------------------------------"), false),
EDIT("&7Action executed (&f{PLAYER}&7): &e{ACTION}", false),
SET_LOBBY("&7Lobby set on your current location.", false),
ADMIN_COMMAND_USAGE("&e{USAGE} &7- {DESC}", true);
private String message = null;
private List<String> messages = null;
private final boolean excludePrefix;
Lang(String message, boolean excludePrefix) {
this.message = message;
this.excludePrefix = excludePrefix;
}
Lang(List<String> messages, boolean excludePrefix) {
this.messages = messages;
this.excludePrefix = excludePrefix;
}
public String getMessage() {
return (excludePrefix ? "" : "&9[Duels] &r") + message;
}
public List<String> getMessages() {
return messages;
}
}
@@ -0,0 +1,6 @@
package me.realized.duels.utilities;
public enum ReloadType {
WEAK, STRONG
}
@@ -1,11 +1,15 @@
package me.realized.duels.utilities.compat;
import org.bukkit.Bukkit;
import org.bukkit.inventory.ItemStack;
import java.lang.reflect.Method;
public class CompatHelper {
private static Class<?> nmsItemStack;
private static Class<?> craftItemStack;
private static Method asNMSCopy;
private static Method asBukkitCopy;
private static Class<?> nbtTagCompound;
private static Class<?> nbtBase;
@@ -14,20 +18,18 @@ public class CompatHelper {
try {
nmsItemStack = Class.forName("net.minecraft.server." + version + ".ItemStack");
craftItemStack = Class.forName("org.bukkit.craftbukkit." + version + ".inventory.CraftItemStack");
Class<?> craftItemStack = Class.forName("org.bukkit.craftbukkit." + version + ".inventory.CraftItemStack");
asNMSCopy = craftItemStack.getMethod("asNMSCopy", ItemStack.class);
asBukkitCopy = craftItemStack.getMethod("asBukkitCopy", nmsItemStack);
nbtTagCompound = Class.forName("net.minecraft.server." + version + ".NBTTagCompound");
nbtBase = Class.forName("net.minecraft.server." + version + ".NBTBase");
} catch (ClassNotFoundException ignored) {}
} catch (ClassNotFoundException | NoSuchMethodException ignored) {}
}
public static Class<?> getMinecraftStack() {
return nmsItemStack;
}
public static Class<?> getCraftStack() {
return craftItemStack;
}
public static Class<?> getNBTTagCompound() {
return nbtTagCompound;
}
@@ -35,4 +37,20 @@ public class CompatHelper {
public static Class<?> getNBTBase() {
return nbtBase;
}
public static Method asNMSCopy() {
return asNMSCopy;
}
public static Method asBukkitCopy() {
return asBukkitCopy;
}
public static boolean isPre1_9() {
return (Bukkit.getVersion().contains("1.8") || Bukkit.getVersion().contains("1.7"));
}
public static boolean isPre1_8() {
return Bukkit.getVersion().contains("1.7");
}
}
@@ -3,6 +3,8 @@ package me.realized.duels.utilities.compat;
import org.bukkit.Material;
import org.bukkit.inventory.ItemStack;
import java.lang.reflect.Method;
public class Potions {
public enum PotionType {
@@ -17,7 +19,8 @@ public class Potions {
private static final Class<?> itemStack = CompatHelper.getMinecraftStack();
private static final Class<?> nbtTagCompound = CompatHelper.getNBTTagCompound();
private static final Class<?> craftItemStack = CompatHelper.getCraftStack();
private static final Method asNMSCopy = CompatHelper.asNMSCopy();
private static final Method asBukkitCopy = CompatHelper.asBukkitCopy();
private final PotionType type;
private final boolean strong, extended, linger, splash;
@@ -60,7 +63,7 @@ public class Potions {
}
try {
Object stack = craftItemStack.getMethod("asNMSCopy", ItemStack.class).invoke(null, item);
Object stack = asNMSCopy.invoke(null, item);
Object tagCompound = itemStack.getMethod("getTag").invoke(stack);
if (tagCompound == null) {
@@ -175,7 +178,7 @@ public class Potions {
nbtTagCompound.getMethod("setString", String.class, String.class).invoke(tagCompound, "Potion", "minecraft:" + tag);
itemStack.getMethod("setTag", nbtTagCompound).invoke(stack, tagCompound);
return (ItemStack) craftItemStack.getMethod("asBukkitCopy", itemStack).invoke(null, stack);
return (ItemStack) asBukkitCopy.invoke(null, stack);
} catch (Exception e) {
return null;
}
@@ -187,7 +190,7 @@ public class Potions {
}
try {
Object stack = craftItemStack.getMethod("asNMSCopy", ItemStack.class).invoke(null, item);
Object stack = asNMSCopy.invoke(null, item);
Object tagCompound = itemStack.getMethod("getTag").invoke(stack);
Object potion = nbtTagCompound.getMethod("getString", String.class).invoke(tagCompound, "Potion");
@@ -4,13 +4,15 @@ import org.bukkit.Material;
import org.bukkit.entity.EntityType;
import org.bukkit.inventory.ItemStack;
import java.lang.reflect.Method;
public class SpawnEggs {
private static final Class<?> itemStack = CompatHelper.getMinecraftStack();
private static final Class<?> craftItemStack = CompatHelper.getCraftStack();
private static final Class<?> nbtTagCompound = CompatHelper.getNBTTagCompound();
private static final Class<?> nbtBase = CompatHelper.getNBTBase();
private static final Method asNMSCopy = CompatHelper.asNMSCopy();
private static final Method asBukkitCopy = CompatHelper.asBukkitCopy();
private final EntityType type;
@@ -26,7 +28,7 @@ public class SpawnEggs {
public ItemStack toItemStack(int amount) {
try {
ItemStack item = new ItemStack(Material.MONSTER_EGG, amount);
Object stack = craftItemStack.getMethod("asNMSCopy", ItemStack.class).invoke(null, item);
Object stack = asNMSCopy.invoke(null, item);
Object tagCompound = itemStack.getMethod("getTag").invoke(stack);
if (tagCompound == null) {
@@ -37,7 +39,7 @@ public class SpawnEggs {
nbtTagCompound.getMethod("setString", String.class, String.class).invoke(id, "id", type.getName());
nbtTagCompound.getMethod("set", String.class, nbtBase).invoke(tagCompound, "EntityTag", id);
itemStack.getMethod("setTag", nbtTagCompound).invoke(stack, tagCompound);
return (ItemStack) craftItemStack.getMethod("asBukkitCopy", itemStack).invoke(null, stack);
return (ItemStack) asBukkitCopy.invoke(null, stack);
} catch (Exception e) {
return null;
}
@@ -50,7 +52,7 @@ public class SpawnEggs {
}
try {
Object stack = craftItemStack.getMethod("asNMSCopy", ItemStack.class).invoke(null, item);
Object stack = asNMSCopy.invoke(null, item);
Object tagCompound = itemStack.getMethod("getTag").invoke(stack);
if (tagCompound != null) {
@@ -0,0 +1,37 @@
package me.realized.duels.utilities.config;
import org.bukkit.configuration.file.FileConfiguration;
import org.bukkit.configuration.file.YamlConfiguration;
import org.bukkit.plugin.java.JavaPlugin;
import java.io.File;
public abstract class Config {
private final String fileName;
private final JavaPlugin instance;
protected FileConfiguration base;
public Config(String fileName, JavaPlugin instance) {
this.fileName = fileName;
this.instance = instance;
reload(false);
}
public void reload(boolean handleLoad) {
File file = new File(instance.getDataFolder(), fileName);
if (!file.exists()) {
instance.saveResource(fileName, false);
}
this.base = YamlConfiguration.loadConfiguration(file);
if (handleLoad) {
handleLoad();
}
}
public abstract void handleLoad();
}
@@ -1,13 +1,12 @@
package me.realized.duels.gui;
package me.realized.duels.utilities.gui;
import me.realized.duels.utilities.compat.CompatHelper;
import me.realized.duels.utilities.inventory.ItemBuilder;
import org.bukkit.Bukkit;
import org.bukkit.ChatColor;
import org.bukkit.Material;
import org.bukkit.entity.HumanEntity;
import org.bukkit.entity.Player;
import org.bukkit.event.inventory.InventoryClickEvent;
import org.bukkit.event.inventory.InventoryCloseEvent;
import org.bukkit.inventory.Inventory;
import org.bukkit.inventory.ItemStack;
@@ -20,11 +19,11 @@ public class GUI<T> {
private final String title;
private final int rows;
private final ClickListener listener;
private final GUIListener listener;
private final Map<Inventory, Integer> pages = new LinkedHashMap<>();
private final Map<Integer, T> data = new LinkedHashMap<>();
public GUI(String title, List<T> entries, int rows, ClickListener listener) {
public GUI(String title, List<T> entries, int rows, GUIListener listener) {
this.title = title;
if (rows < 1 || rows > 5) {
@@ -63,7 +62,7 @@ public class GUI<T> {
ItemStack separator = ItemBuilder.builder().type(Material.STAINED_GLASS_PANE).name(" ").build();
ItemStack defaultDisplayed;
if (!Bukkit.getVersion().contains("1.7")) {
if (!CompatHelper.isPre1_8()) {
defaultDisplayed = ItemBuilder.builder().type(Material.BARRIER).build();
} else {
defaultDisplayed = ItemBuilder.builder().type(Material.REDSTONE_BLOCK).build();
@@ -112,7 +111,7 @@ public class GUI<T> {
Inventory current = Bukkit.createInventory(null, 54, title + " (page 1/1)");
ItemStack defaultDisplayed;
if (!Bukkit.getVersion().contains("1.7")) {
if (!CompatHelper.isPre1_8()) {
defaultDisplayed = ItemBuilder.builder().type(Material.BARRIER).name(ChatColor.RED + "There was nothing to load to the GUI.").build();
} else {
defaultDisplayed = ItemBuilder.builder().type(Material.REDSTONE_BLOCK).name(ChatColor.RED + "There was nothing to load to the GUI.").build();
@@ -144,7 +143,7 @@ public class GUI<T> {
}
}
public Inventory getByPage(int page) {
private Inventory getByPage(int page) {
for (Map.Entry<Inventory, Integer> entry : pages.entrySet()) {
if (entry.getValue() == page) {
return entry.getKey();
@@ -156,7 +155,7 @@ public class GUI<T> {
public boolean isPage(Inventory another) {
for (Inventory inventory : pages.keySet()) {
if (another.equals(inventory)) {
if (another.getTitle().equals(inventory.getTitle())) {
return true;
}
}
@@ -206,16 +205,7 @@ public class GUI<T> {
return pages.keySet().iterator().next();
}
protected ClickListener getListener() {
GUIListener getListener() {
return listener;
}
public interface ClickListener {
void onClick(InventoryClickEvent event);
void onClose(InventoryCloseEvent event);
void onSwitch(Player player, Inventory opened);
}
}
@@ -0,0 +1,15 @@
package me.realized.duels.utilities.gui;
import org.bukkit.entity.Player;
import org.bukkit.event.inventory.InventoryClickEvent;
import org.bukkit.event.inventory.InventoryCloseEvent;
import org.bukkit.inventory.Inventory;
public interface GUIListener {
void onClick(InventoryClickEvent event);
void onClose(InventoryCloseEvent event);
void onSwitch(Player player, Inventory opened);
}
@@ -1,6 +1,5 @@
package me.realized.duels.gui;
package me.realized.duels.utilities.gui;
import me.realized.duels.Core;
import org.bukkit.Bukkit;
import org.bukkit.entity.Player;
import org.bukkit.event.EventHandler;
@@ -9,15 +8,16 @@ import org.bukkit.event.Listener;
import org.bukkit.event.inventory.InventoryClickEvent;
import org.bukkit.event.inventory.InventoryCloseEvent;
import org.bukkit.inventory.Inventory;
import org.bukkit.plugin.java.JavaPlugin;
import java.util.ArrayList;
import java.util.List;
public class GUIManager implements Listener {
private final List<GUI> registered = new ArrayList<>();
private List<GUI> registered = new ArrayList<>();
public GUIManager(Core instance) {
public GUIManager(JavaPlugin instance) {
Bukkit.getPluginManager().registerEvents(this, instance);
}
@@ -1,4 +1,4 @@
package me.realized.duels.gui;
package me.realized.duels.utilities.gui;
import org.bukkit.inventory.ItemStack;
@@ -1,5 +1,6 @@
package me.realized.duels.utilities.inventory;
import me.realized.duels.utilities.compat.CompatHelper;
import me.realized.duels.utilities.compat.Potions;
import me.realized.duels.utilities.compat.SpawnEggs;
import org.bukkit.Bukkit;
@@ -10,8 +11,10 @@ import org.bukkit.entity.EntityType;
import org.bukkit.inventory.ItemFlag;
import org.bukkit.inventory.ItemStack;
import org.bukkit.inventory.meta.*;
import org.bukkit.potion.PotionData;
import org.bukkit.potion.PotionEffect;
import org.bukkit.potion.PotionEffectType;
import org.bukkit.potion.PotionType;
import java.util.*;
@@ -38,12 +41,12 @@ public class JSONItem {
private String color;
public JSONItem(ItemStack item) {
private JSONItem(ItemStack item) {
this.material = item.getType().name();
this.amount = item.getAmount() == 0 ? 1 : item.getAmount();
this.data = item.getDurability();
if (!(Bukkit.getVersion().contains("1.7") && Bukkit.getVersion().contains("1.8"))) {
if (!CompatHelper.isPre1_9()) {
if (material.contains("POTION")) {
Potions potion = Potions.fromItemStack(item);
@@ -79,6 +82,26 @@ public class JSONItem {
}
this.itemData = spawnEgg.getType().name() + "-";
} else if (material.equals("TIPPED_ARROW")) {
PotionMeta meta = (PotionMeta) item.getItemMeta();
PotionData potionData = meta.getBasePotionData();
if (potionData.getType().getEffectType() == null) {
return;
}
StringBuilder data = new StringBuilder();
data.append(potionData.getType().name()).append("-");
if (potionData.isExtended()) {
data.append("extended-");
}
if (potionData.isUpgraded()) {
data.append("upgraded-");
}
this.itemData = data.toString();
}
}
}
@@ -142,7 +165,7 @@ public class JSONItem {
public ItemStack construct() {
ItemStack item = new ItemStack(Material.getMaterial(this.material), this.amount, this.data);
if (!(Bukkit.getVersion().contains("1.7") && Bukkit.getVersion().contains("1.8")) && itemData != null) {
if (!CompatHelper.isPre1_9() && itemData != null) {
List<String> itemData = Arrays.asList(this.itemData.split("-"));
if (material.contains("POTION")) {
@@ -151,6 +174,11 @@ public class JSONItem {
} else if (material.equals("MONSTER_EGG")) {
SpawnEggs spawnEgg1_9 = new SpawnEggs(EntityType.valueOf(itemData.get(0)));
item = spawnEgg1_9.toItemStack(amount);
} else if (material.equals("TIPPED_ARROW")) {
PotionMeta potionMeta = (PotionMeta) item.getItemMeta();
PotionData data = new PotionData(PotionType.valueOf(itemData.get(0)), itemData.contains("extended"), itemData.contains("upgraded"));
potionMeta.setBasePotionData(data);
item.setItemMeta(potionMeta);
}
}
@@ -251,7 +279,7 @@ public class JSONItem {
result.setLore(meta.getLore());
}
if (!Bukkit.getVersion().contains("1.7") && !meta.getItemFlags().isEmpty()) {
if (!CompatHelper.isPre1_8() && !meta.getItemFlags().isEmpty()) {
for (ItemFlag flag : meta.getItemFlags()) {
result.addFlag(flag.name());
}
+134 -114
View File
@@ -1,32 +1,61 @@
# Make sure to read the comments before configuring! It'll be a big help.
# <-> Duels v2.0.0-SNAPSHOT <->
#
#
# Read the configuration (especially the comments above each option) carefully before PMing me on Spigot,
# you'll probably find what you were looking for.
#
#
# Glitch patches
patcher:
# If enabled: Toggles vanish off if you're vanished. (Essentials)
fix-vanish: false
# If enabled: Patches player returning to arena using /back after the match. (Essentials)
fix-back: true
Patches:
# If enabled: Disables teleporting to players in match. This was implemented due to the following exploit:
# 1) Player 1 sends a duel request to player 2.
# 2) Player 3 sends /tpa to Player 1.
# 3) Player 1 types /tpaccept (Lets assume there's a 5 second delay)
# 4) Player 2 types /duel accept, and player 1 & player 2 teleports to the arena.
# 5) Player 3 will be teleported into the arena after 5 seconds, to player 1.
# 6) The Exploit: Player 3 can now pick up duel kit items
# Players with OP or the permission 'duels.admin' will bypass this function.
fix-teleport: true
# Patch to known glitch with Essentials Vanish where you can't see the player even after unvanish.
toggle-vanish-on-start: true
# If enabled: Blocks opening of another inventory while in duel.
# This prevents people exploiting trading systems and such.
# Patches an exploit with Essentials' /back command which allowed players to return to arena.
set-back-location: true
# Patches an exploit with Essentials' /tpa command which allowed players to teleport others to them.
# Players with OP, duels.admin permission, or spectator mode will bypass the cancellation.
cancel-teleport-to-players-in-match: true
# Prevents exploit with chest access plugins or trading systems by cancelling InventoryOpen in a match.
# Add every command and their aliases to disabled-commands is another way to patch the issue.
fix-inventory-open: true
# Countdown settings
countdown:
# mcMMO: Prevents use of skills & abilities in a match.
disable-mcMMO-in-match: true
# Factions: Prevents player power loss from dying in a match.
disable-power-loss: true
# For v2.0 and above, teleportation with distance under 1.0 is not cancelled due to lagbacks.
# Enable this patch to cancel any teleportation.
strict-teleportation: false
# If enabled, Duels will try to override any entity damage cancellation from other plugins if players are dueling.
# For example, enabling this will allow players in same faction to duel.
# THIS IS AN UNSAFE OPTION, DISABLE IF IT CAUSES ANY ISSUES.
force-allow-pvp: true
# If enabled, players must stay still after sending a request.
# Before the duel starts, Duels will check if player has moved and stop the duel if so.
# This prevents users moving out of the selected DuelZone region after sending a request.
# Duels will send a message after they send a duel request to someone
# in order to notify them to stay still.
# You may edit the sent message in messages.yml.
cancel-match-if-moved: false
Countdown:
# Enable countdown?
enabled: true
# Countdown timer's duration equals to size of this list. (In seconds)
# Countdown timer's duration equals to the length of the list below. (in seconds)
messages:
- '&7Starting in &f5 &7seconds!'
- '&7Starting in &f4 &7seconds!'
@@ -41,64 +70,99 @@ countdown:
# While countdown is running, block pvp.
block-pvp: true
# GUI settings
GUI:
# Select how many rows should each page of the GUI have.
# Note: Excludes the last row which contains 'previous page' & 'next page' buttons.
# Must be in range between 1 - 5, otherwise it'll be set to 5 by default.
kit-selector: 3
arena-selector: 2
# The displayName of the map item in Arena Selector GUI
# displayName for available arenas
GUI:
# Select how many rows should each page of the GUI have.
# Excludes the last row which contains 'previous page' & 'next page' buttons.
# Must be in range between 1 - 5.
kit-selector-rows: 3
arena-selector-rows: 2
# The display name of the map item in Arena Selector GUI.
# display name for available arenas
available-arena-displayname: '&9{NAME}: &aAvailable'
# displayName for in use arenas
# display name for in use arenas
in-use-arena-displayname: '&9{NAME}: &cIn Use'
# Duel settings
Spectating:
# Players will be able to only use the following commands while in specator mode.
whitelisted-commands:
- 'msg'
- 'r'
- 'w'
- 'pm'
- 'reply'
- 'tell'
- 'whisper'
- 'list'
- 'stats'
- 'dstats'
- 'duelstats'
Dueling:
# If enabled: Allows certain commands to be executed on match winner and loser.
# If enabled, match will automatically end after selected amount of seconds.
match-max-duration:
# Enable match max duration?
enabled: true
# The max duration for a match.
duration: 600
# If enabled, allows certain commands to be executed to winner and loser at the end of the match.
match-end-commands:
# Enable match end commands?
enabled: false
# Commands to be executed.
# Available placeholder(s): {WINNER}, {LOSER}
commands:
- 'give {WINNER} diamond 1'
- 'give {LOSER} dirt 1'
# If enabled: Players will have another GUI open after selecting kit that displays clickable arenas.
# They are able to choose which arena they want to play on.
# If enabled, players will have another GUI open after selecting kit that displays all arenas.
# You can select from an arena from the list if available.
# If someone else uses the arena while the request is pending,
# the 'arena in use' message will display and the request will be cancelled.
allow-arena-selecting: true
# If enabled: Sends a duel request directly on /duel [player] without a kit selection,
# Allowing players to use their own inventory for dueling.
# Note: If you're using this option, make sure to edit the duel messages so players
# If enabled, players can send duel request directly without a kit or arena selection GUI popping up.
# This will allow players to use their own inventory for dueling.
# IMPORTANT: If you're using this option, make sure to edit the duel messages so players
# will know they'll be using their own items!
use-own-inventory: false
# If enabled: Players must have a cleared inventory to execute the command /duel.
# Player inventories will be restored on duel end if this value is set to 'false'.
# If enabled, players must have a cleared inventory to execute the command /duel.
# IMPORTANT: Player inventories will be restored on duel end if this value is set to 'false'.
requires-cleared-inventory: true
# If enabled: On duel end, players will be teleported to the latest location they were at before the start of the match.
# Recommended: 'true' if your server type is factions/survival. 'false' if your server type is kitpvp.
# If enabled, players will be teleported to the latest location they were at before the start of the match after the duel.
teleport-to-latest-location: false
# On duel end, winner will be teleported after following amount of seconds to spawn / latest location if enabled.
delay-until-teleport-on-win: 5
delay-until-teleport: 5
# If enabled: Allows players to drop item while in duel.
drop-item: true
# Allows players to drop item while in duel, if enabled.
drop-item: false
# If enabled: Allows players to pick up item while in duel.
# Allows players to pick up item while in duel, if enabled.
pick-up-item: true
# If enabled: All commands will be blocked while in duel.
# All commands will be blocked while in duel, if enabled.
# If you wish to whitelist certain commands, add them to 'whitelisted-commands' list.
block-all-commands: false
# Commands in the following list will be exempted
# from getting blocked if 'block-all-commands' is enabled.
# Commands in the following list will be exempted from getting blocked if 'block-all-commands' is enabled.
whitelisted-commands:
- 'msg'
- 'pm'
@@ -111,10 +175,8 @@ Dueling:
- 'tempban'
# Commands in the following list will be disabled while in duel.
# NOTE: If block-all-commands is enabled, this option will not take affect.
# Recommended: Add all the commands that will allow players to gain advantage while in duel. Examples: /heal, /kit
# Added most of the known commands to default configuration just to save your time. ;)
# If you have too many commands, 'block-all-commands' is another way to go.
# IMPORTANT: If block-all-commands is enabled, this option will not take affect.
# If you have too many commands, 'block-all-commands' is probably a better option.
disabled-commands:
- 'heal'
- 'eheal'
@@ -185,78 +247,36 @@ Dueling:
- 'playervaults:pv'
- 'playervaults:playervaults'
# DuelZone settings. Requires WorldGuard!
# Required plugin(s): WorldGuard
DuelZone:
# If enabled: Player must be inside of the region declared below to execute the command /duel.
# If enabled, player must be inside of the region declared below to execute the command /duel.
enabled: false
# The region players have to be in to use duel commands.
region: spawn
# Stats command settings
Stats:
# If enabled: Displays a list of data of the player's 10 latest matches when /stats is executed.
# If enabled: Displays player's latest matches when /stats is executed.
display-matches: true
# Edit messages here! Read the comments above the messages for more information.
Messages:
# Displayed when player executes the command: /stats
# Placeholders:
# {NAME} - Name of the stats owner.
# {WINS} - Amount of duel wins.
# {LOSSES} - Amount of duel losses.
# {REQUESTS_ENABLED} - Displays 'enabled' if player has duel requests enabled, else 'disabled'.
stats:
- '&7Displaying stats of &f{NAME} &7-'
- '&71v1 Wins: &f{WINS}'
- '&71v1 Losses: &f{LOSSES}'
- '&71v1 Requests: &f{REQUESTS_ENABLED}'
- '&7Latest 1v1 matches -'
# Amount of matches to display if option above is enabled.
amount-of-matches: 10
# Displayed after the list above if 'display-matches' is enabled.
# Placeholders:
# {WINNER} - Name of the winner.
# {LOSER} - Name of the loser.
match-format: '&a{WINNER} &fvs &c{LOSER} &6[Hover Me!]'
# Displayed when hovering the message above.
# Placeholders:
# {DURATION} - Formatted match duration.
# {TIME} - Time since the happening of the match.
# {HEALTH} - Winner's health.
# {NEWLINE} - Moves on to the next line.
match-hover: '&7Duration: &f{DURATION}{NEWLINE}&7Time: &f{TIME} ago{NEWLINE}&7Health: &d&l{HEALTH} ♥'
# Displayed when player sends a duel request.
# Placeholders:
# {PLAYER} - Receiver's name for 'on-request-send', Sender's name for 'on-request-receive'.
# {KIT} - Name of the kit selected on request send.
# {ARENA} - 'random' if arena selecting is disabled, selected arena's name if enabled.
on-request-send: '&9[Duels] &7Duel request sent to &f{PLAYER} &7with kit &f{KIT}&7 on arena &f{ARENA}&7.'
on-request-receive: '&9[Duels] &7Duel request received from &f{PLAYER} &7with kit &f{KIT}&7 on arena &f{ARENA}&7. Type &f/duel accept {PLAYER} &7to accept. &e[Expires in 30s]'
Soup:
# Enable Soup?
enabled: false
# Displayed when a duel ends.
# {WINNER} - Winner's name.
# {LOSER} - Loser's name.
# {HEALTH} - Winner's health.
on-duel-end: '&9[Duels] &f{WINNER} &7has defeated &f{LOSER} &7with &d&l{HEALTH} ♥'
# If enabled, arenas with name starting with the value below will have Soup Regen enabled.
arenas-starting-with: 'soup arena'
# Displayed when player accepts a duel request.
# Placeholders:
# {PLAYER} - Request acceptor's name for 'on-request-accept-target', sender's name for 'on-request-accept-sender'.
# {KIT} - Name of the kit selected on request send.
# {ARENA} - 'random' if arena selecting is disabled, selected arena's name if enabled.
on-request-accept-target: '&9[Duels] &7Accepted duel request from &f{PLAYER}&7. Starting match with kit &f{KIT}&7 on arena &f{ARENA}&7.'
on-request-accept-sender: '&9[Duels] &7Your duel request to &f{PLAYER} &7was accepted. Starting match with kit &f{KIT}&7 on arena &f{ARENA}&7.'
# Hearts to regen on soup.
hearts-to-regen: 3.5
# Displayed when player accepts a duel request.
# Placeholders:
# {PLAYER} - Request acceptor's name for 'on-request-accept-target', sender's name for 'on-request-accept-sender'.
on-request-deny-target: '&9[Duels] &7Denied duel request from &f{PLAYER}&7.'
on-request-deny-sender: '&9[Duels] &7Your duel request to &f{PLAYER} &7was denied.'
# Displayed when player executes the command: /toggle
# Placeholders: none
on-requests-enable: '&a&lOthers may send you duel requests from now on.'
on-requests-disable: '&c&lOthers may not send you duel requests from now on.'
# Displayed when player executes the command: /duel
duel-command-usage: 'Send, accept, or deny a duel request.{NEWLINE}/duel [player]{NEWLINE}/duel [accept | deny] [player]'
+211
View File
@@ -0,0 +1,211 @@
Dueling:
# Placeholder(s): {PLAYER}, {KIT}, {ARENA}
on-request-send:
sender: '&9[Duels] &7Duel request sent to &f{PLAYER} &7with kit &f{KIT}&7 on arena &f{ARENA}&7.'
receiver: '&9[Duels] &7Duel request received from &f{PLAYER} &7with kit &f{KIT}&7 on arena &f{ARENA}&7. Type &f/duel accept {PLAYER} &7to accept. &e[Expires in 30s]'
# Placeholder(s): {PLAYER}, {KIT}, {ARENA}
on-request-accept:
sender: '&9[Duels] &7Your duel request to &f{PLAYER} &7was accepted. Starting match with kit &f{KIT}&7 on arena &f{ARENA}&7.'
receiver: '&9[Duels] &7Accepted duel request from &f{PLAYER}&7. Starting match with kit &f{KIT}&7 on arena &f{ARENA}&7.'
# Placeholder(s): {PLAYER}
on-request-decline:
sender: '&9[Duels] &7Your duel request to &f{PLAYER} &7was denied.'
receiver: '&9[Duels] &7Denied duel request from &f{PLAYER}&7.'
# Placeholder(s): {WINNER}, {LOSER}, {HEALTH}
on-match-end: '&9[Duels] &f{WINNER} &7has defeated &f{LOSER} &7with &d&l{HEALTH} ♥'
max-match-time-reached: '&9[Duels] &7Max match length reached, tie match.'
# Only displayed if cancel-match-if-moved is enabled in the configuration.
do-not-move-warning: '&aRequest sent. Stay still until your opponent accepts the request or the request expires, or the duel will not start.'
Spectating:
# Placeholder(s): {PLAYER}
started-spectating: '&9[Duels] &7You are now spectating &f{PLAYER}&7.'
stopped-spectating: '&9[Duels] &7You are no longer spectating &f{PLAYER}&7.'
arena-broadcast: '&9[Duels] &f{PLAYER} &7is now spectating the match!'
spectating-match-ended: '&9[Duels] &7The match you were spectating has ended.'
Stats:
# Placeholder(s): {NAME}, {WINS}, {LOSSES}, {REQUESTS_ENABLED}
displayed:
- '&7Displaying stats of &f{NAME} &7-'
- '&71v1 Wins: &f{WINS}'
- '&71v1 Losses: &f{LOSSES}'
- '&71v1 Requests: &f{REQUESTS_ENABLED}'
- '&7Latest 1v1 matches -'
# Placeholder(s): {WINNER}, {LOSER}
match-format: '&a{WINNER} &fvs &c{LOSER} &6[Hover Me!]'
# Placeholder(s): {DURATION}, {TIME}, {HEALTH}
match-hover:
- '&7Duration: &f{DURATION}'
- '&7Time: &f{TIME} ago'
- '&7Health: &d&l{HEALTH} ♥'
# Placeholder(s): {PLAYER}, {ACTION}
edit: '&9[Duels] &7Action executed (&f{PLAYER}&7): &e{ACTION}'
# Placeholder(s): {PLAYER}
reset: '&9[Duels] &7Stats reset for &f{PLAYER}&7.'
Arenas:
# Placeholder(s): {NAME}
created: '&9[Duels] &7Arena &f{NAME} &7was successfully created.'
deleted: '&9[Duels] &7Arena &f{NAME} &7was successfully deleted.'
enabled: '&9[Duels] &a&lArena {NAME} is now enabled!'
disabled: '&9[Duels] &c&lArena {NAME} is now disabled!'
# Placeholder(s): {POSITION}, {NAME}
set-spawnpoint: '&9[Duels] &7Set spawn position for player &f{POSITION} &7for arena &f{NAME}&7.'
# Placeholder(s): {NAME}, {DISABLED}, {IN_USE}, {PLAYERS}, {LOCATIONS}
info:
- '&b&m------------------------------------'
- '&7Displaying info of arena &f{NAME} &7-'
- '&7Disabled: &f{DISABLED}'
- '&7In use: &f{IN_USE}'
- '&7Players: &f{PLAYERS}'
- '&7Locations: &f{LOCATIONS}'
- '&b&m------------------------------------'
Kits:
# Placeholder(s): {NAME}
created: '&9[Duels] &7Saved kit &f{NAME}&7!'
deleted: '&9[Duels] &7Deleted kit &f{NAME}&7!'
loaded: '&9[Duels] &7Loaded kit &f{NAME} &7to your inventory.'
set-item: '&9[Duels] &7Kit &f{NAME}&7''s displayed item in Kit Selection GUI was replaced to your held item.'
Extra:
# Placeholder(s): {ARENAS}, {KITS}, {LOBBY}
list:
- "&b&m------------------------------------"
- "&7Arena name color states:"
- "&4DARK RED&7: Arena is disabled."
- "&9BLUE&7: Arena without valid spawn positions set."
- "&aGREEN&7: Arena available for a match."
- "&cRED&7: Arena in use."
- "&7Arenas: &r{ARENAS}"
- "&7Kits: &r{KITS}"
- "&7Lobby Location: &r{LOBBY}"
- "&b&m------------------------------------"
set-lobby: '&9[Duels] &7Lobby set on your current location.'
Toggle:
enabled: '&a&lOthers may send you duel requests from now on.'
disabled: '&c&lOthers may not send you duel requests from now on.'
Commands:
duel:
usage:
- 'Send, accept, or deny a duel request.'
- '/duel [accept | deny] [player]'
# Placeholder(s): {USAGE}, {DESCRIPTION}
sub-command-usage: '&9[Duels] &e{USAGE} &7- {DESCRIPTION}'
duels:
usage:
- '&b&m------------------------------------------------'
- '&e/duels edit [player] [add:remove:set] [wins:losses] [quantity] &7- Edit player''s stats.'
- '&e/duels create [name] &7- Create an arena.'
- '&e/duels set [name] [1 | 2] &7- Set spawn position for arena.'
- '&e/duels delete [name] &7- Remove an arena.'
- '&e/duels list &7- Displays the lobby location and lists arenas and kits.'
- '&e/duels toggle [name] &7- Enable/Disable an arena.'
- '&e/duels info [name] &7- Show arena information.'
- '&e/duels savekit [name] &7- Save a new kit with your inventory contents.'
- '&e/duels deletekit [name] &7- Delete a kit with the given name.'
- '&e/duels loadkit [name] &7- Load a kit with the given name.'
- '&e/duels setlobby &7- Set duel lobby on your current location.'
- '&e/duels setitem [name] &7- Replaces the displayed item to held item for selected kit.'
- '&e/duels reset [player] &7- Completely reset a player''s stats.'
- '&e/duels reload [weak] &7- Reloads the plugin completely. Append ''weak'' to only reload messages file.'
- '&b&m------------------------------------------------'
# Placeholder(s): {USAGE}, {DESCRIPTION}
sub-command-usage: '&9[Duels] &e{USAGE} &7- {DESCRIPTION}'
spectate:
usage:
- 'Spectate a duel.'
- '/spectate [player]'
Errors:
no-permission: '&cNo permission.'
must-be-alphanumeric: '&cNames must be alphanumeric.'
# Placeholder(s): {ARGUMENT}
invalid-sub-command: '&c{ARGUMENT} is not a valid sub command.'
blocked-countdown-action: '&cYou are not allowed to do this before the match starts.'
# Placeholder(s): {REASON}
edit-failed: '&cEdit failed: {REASON}'
arena-exists: '&cAn arena with that name already exists.'
arena-not-found: '&cNon-existing arena.'
arena-deletion-failed: '&cThat arena is currently in use. To prevent an arena from being used, disable it using /duels toggle [name].'
arena-no-longer-available: '&cThe selected arena is no longer available, please choose a different arena.'
no-available-arena-found: '&cNo available arenas were found, please try again later.'
invalid-spawnpoint: '&cSpawn positions must be in between range 1 - 2.'
match-failed: '&cMatch failed! Reason: {REASON}'
kit-exists: '&cA kit with that name already exists.'
kit-not-found: '&cNon-existing kit.'
empty-hand: '&cYou must be holding an item to use this command.'
player-not-found: '&cPlayer not found.'
player-left: '&cThat player is no longer online.'
cannot-duel-yourself: '&cYou cannot duel yourself.'
# Placeholder(s): {REGION}
not-in-duelzone: '&cYou must be in region ''{REGION}'' to use duel related commands.'
has-requests-disabled: '&cThat player has duel requests disabled!'
# Placeholder(s): {PLAYER}
already-requested: '&cYou already have a request sent to {PLAYER}.'
already-expired: '&cThat request has already expired.'
no-request: '&cThat player did not send you a request!'
alive-only: '&cCannot send a request to dead players.'
empty-inventory-only: '&cYour inventory must be empty to use duel related commands.'
blocked-while-in-match:
teleport: '&cYou may not teleport while in a match.'
drop-item: '&cYou may not drop items while in duel.'
fly: '&cYou may not fly while in duel.'
command: '&cYou may not use that command while in duel.'
open-inventory: '&cYou may not open other inventories while in duel.'
already-spectating: '&cYou are already in spectator mode. Type &l/spectate &r&cor right click the redstone to stop spectating.'
players-in-match-only: '&cYou may only spectate players who is in a match.'
cannot-use-while-spectating: '&cYou cannot do this while spectating. Type &l/spectate &r&cor right click the redstone to stop spectating.'
is-in-spectator-mode:
sender: '&cYou are in spectator mode!'
target: '&cThat player is in spectator mode!'
already-in-match:
sender: '&cYou are already in a match!'
target: '&cThat player is already in a match!'
+16 -5
View File
@@ -1,11 +1,15 @@
name: Duels
main: me.realized.duels.Core
version: 1.3.4
version: 2.0.0-SNAPSHOT
author: Realized
website: https://www.spigotmc.org/resources/duels.20171/
description: An ultimate solution to server owners wanting to create a duel system.
softdepend: [WorldGuard, Multiverse-Core, Essentials]
softdepend: [WorldGuard, Multiverse-Core, Essentials, Factions]
# Multiverse-Core added as soft-depend due to locations being null when Duels is loaded first.
# Add any world management plugins to softdepend list if arena doesn't load properly in the generated world.
commands:
duel:
@@ -14,6 +18,9 @@ commands:
stats:
description: Display stats of yours or others.
aliases: [statistics, info, duelstats, dstats]
spectate:
description: Spectate a player in duel.
aliases: [spec]
toggle:
description: Enable or disable receiving duel requests.
aliases: [tg]
@@ -25,11 +32,15 @@ permissions:
duels.*:
children:
duels.admin: true
duels.duel: true
duels.stats: true
duels.toggle: true
duels.default:
children:
duels.duel: true
duels.stats: true
duels.toggle: true
duels.admin:
children:
duels.default: true
duels.spectate: true
duels.spectate.anonymously: true