add item commands
This commit is contained in:
674
LICENSE
Normal file
674
LICENSE
Normal file
@@ -0,0 +1,674 @@
|
|||||||
|
GNU GENERAL PUBLIC LICENSE
|
||||||
|
Version 3, 29 June 2007
|
||||||
|
|
||||||
|
Copyright (C) 2007 Free Software Foundation, Inc. <https://fsf.org/>
|
||||||
|
Everyone is permitted to copy and distribute verbatim copies
|
||||||
|
of this license document, but changing it is not allowed.
|
||||||
|
|
||||||
|
Preamble
|
||||||
|
|
||||||
|
The GNU General Public License is a free, copyleft license for
|
||||||
|
software and other kinds of works.
|
||||||
|
|
||||||
|
The licenses for most software and other practical works are designed
|
||||||
|
to take away your freedom to share and change the works. By contrast,
|
||||||
|
the GNU General Public License is intended to guarantee your freedom to
|
||||||
|
share and change all versions of a program--to make sure it remains free
|
||||||
|
software for all its users. We, the Free Software Foundation, use the
|
||||||
|
GNU General Public License for most of our software; it applies also to
|
||||||
|
any other work released this way by its authors. You can apply it to
|
||||||
|
your programs, too.
|
||||||
|
|
||||||
|
When we speak of free software, we are referring to freedom, not
|
||||||
|
price. Our General Public Licenses are designed to make sure that you
|
||||||
|
have the freedom to distribute copies of free software (and charge for
|
||||||
|
them if you wish), that you receive source code or can get it if you
|
||||||
|
want it, that you can change the software or use pieces of it in new
|
||||||
|
free programs, and that you know you can do these things.
|
||||||
|
|
||||||
|
To protect your rights, we need to prevent others from denying you
|
||||||
|
these rights or asking you to surrender the rights. Therefore, you have
|
||||||
|
certain responsibilities if you distribute copies of the software, or if
|
||||||
|
you modify it: responsibilities to respect the freedom of others.
|
||||||
|
|
||||||
|
For example, if you distribute copies of such a program, whether
|
||||||
|
gratis or for a fee, you must pass on to the recipients the same
|
||||||
|
freedoms that you received. You must make sure that they, too, receive
|
||||||
|
or can get the source code. And you must show them these terms so they
|
||||||
|
know their rights.
|
||||||
|
|
||||||
|
Developers that use the GNU GPL protect your rights with two steps:
|
||||||
|
(1) assert copyright on the software, and (2) offer you this License
|
||||||
|
giving you legal permission to copy, distribute and/or modify it.
|
||||||
|
|
||||||
|
For the developers' and authors' protection, the GPL clearly explains
|
||||||
|
that there is no warranty for this free software. For both users' and
|
||||||
|
authors' sake, the GPL requires that modified versions be marked as
|
||||||
|
changed, so that their problems will not be attributed erroneously to
|
||||||
|
authors of previous versions.
|
||||||
|
|
||||||
|
Some devices are designed to deny users access to install or run
|
||||||
|
modified versions of the software inside them, although the manufacturer
|
||||||
|
can do so. This is fundamentally incompatible with the aim of
|
||||||
|
protecting users' freedom to change the software. The systematic
|
||||||
|
pattern of such abuse occurs in the area of products for individuals to
|
||||||
|
use, which is precisely where it is most unacceptable. Therefore, we
|
||||||
|
have designed this version of the GPL to prohibit the practice for those
|
||||||
|
products. If such problems arise substantially in other domains, we
|
||||||
|
stand ready to extend this provision to those domains in future versions
|
||||||
|
of the GPL, as needed to protect the freedom of users.
|
||||||
|
|
||||||
|
Finally, every program is threatened constantly by software patents.
|
||||||
|
States should not allow patents to restrict development and use of
|
||||||
|
software on general-purpose computers, but in those that do, we wish to
|
||||||
|
avoid the special danger that patents applied to a free program could
|
||||||
|
make it effectively proprietary. To prevent this, the GPL assures that
|
||||||
|
patents cannot be used to render the program non-free.
|
||||||
|
|
||||||
|
The precise terms and conditions for copying, distribution and
|
||||||
|
modification follow.
|
||||||
|
|
||||||
|
TERMS AND CONDITIONS
|
||||||
|
|
||||||
|
0. Definitions.
|
||||||
|
|
||||||
|
"This License" refers to version 3 of the GNU General Public License.
|
||||||
|
|
||||||
|
"Copyright" also means copyright-like laws that apply to other kinds of
|
||||||
|
works, such as semiconductor masks.
|
||||||
|
|
||||||
|
"The Program" refers to any copyrightable work licensed under this
|
||||||
|
License. Each licensee is addressed as "you". "Licensees" and
|
||||||
|
"recipients" may be individuals or organizations.
|
||||||
|
|
||||||
|
To "modify" a work means to copy from or adapt all or part of the work
|
||||||
|
in a fashion requiring copyright permission, other than the making of an
|
||||||
|
exact copy. The resulting work is called a "modified version" of the
|
||||||
|
earlier work or a work "based on" the earlier work.
|
||||||
|
|
||||||
|
A "covered work" means either the unmodified Program or a work based
|
||||||
|
on the Program.
|
||||||
|
|
||||||
|
To "propagate" a work means to do anything with it that, without
|
||||||
|
permission, would make you directly or secondarily liable for
|
||||||
|
infringement under applicable copyright law, except executing it on a
|
||||||
|
computer or modifying a private copy. Propagation includes copying,
|
||||||
|
distribution (with or without modification), making available to the
|
||||||
|
public, and in some countries other activities as well.
|
||||||
|
|
||||||
|
To "convey" a work means any kind of propagation that enables other
|
||||||
|
parties to make or receive copies. Mere interaction with a user through
|
||||||
|
a computer network, with no transfer of a copy, is not conveying.
|
||||||
|
|
||||||
|
An interactive user interface displays "Appropriate Legal Notices"
|
||||||
|
to the extent that it includes a convenient and prominently visible
|
||||||
|
feature that (1) displays an appropriate copyright notice, and (2)
|
||||||
|
tells the user that there is no warranty for the work (except to the
|
||||||
|
extent that warranties are provided), that licensees may convey the
|
||||||
|
work under this License, and how to view a copy of this License. If
|
||||||
|
the interface presents a list of user commands or options, such as a
|
||||||
|
menu, a prominent item in the list meets this criterion.
|
||||||
|
|
||||||
|
1. Source Code.
|
||||||
|
|
||||||
|
The "source code" for a work means the preferred form of the work
|
||||||
|
for making modifications to it. "Object code" means any non-source
|
||||||
|
form of a work.
|
||||||
|
|
||||||
|
A "Standard Interface" means an interface that either is an official
|
||||||
|
standard defined by a recognized standards body, or, in the case of
|
||||||
|
interfaces specified for a particular programming language, one that
|
||||||
|
is widely used among developers working in that language.
|
||||||
|
|
||||||
|
The "System Libraries" of an executable work include anything, other
|
||||||
|
than the work as a whole, that (a) is included in the normal form of
|
||||||
|
packaging a Major Component, but which is not part of that Major
|
||||||
|
Component, and (b) serves only to enable use of the work with that
|
||||||
|
Major Component, or to implement a Standard Interface for which an
|
||||||
|
implementation is available to the public in source code form. A
|
||||||
|
"Major Component", in this context, means a major essential component
|
||||||
|
(kernel, window system, and so on) of the specific operating system
|
||||||
|
(if any) on which the executable work runs, or a compiler used to
|
||||||
|
produce the work, or an object code interpreter used to run it.
|
||||||
|
|
||||||
|
The "Corresponding Source" for a work in object code form means all
|
||||||
|
the source code needed to generate, install, and (for an executable
|
||||||
|
work) run the object code and to modify the work, including scripts to
|
||||||
|
control those activities. However, it does not include the work's
|
||||||
|
System Libraries, or general-purpose tools or generally available free
|
||||||
|
programs which are used unmodified in performing those activities but
|
||||||
|
which are not part of the work. For example, Corresponding Source
|
||||||
|
includes interface definition files associated with source files for
|
||||||
|
the work, and the source code for shared libraries and dynamically
|
||||||
|
linked subprograms that the work is specifically designed to require,
|
||||||
|
such as by intimate data communication or control flow between those
|
||||||
|
subprograms and other parts of the work.
|
||||||
|
|
||||||
|
The Corresponding Source need not include anything that users
|
||||||
|
can regenerate automatically from other parts of the Corresponding
|
||||||
|
Source.
|
||||||
|
|
||||||
|
The Corresponding Source for a work in source code form is that
|
||||||
|
same work.
|
||||||
|
|
||||||
|
2. Basic Permissions.
|
||||||
|
|
||||||
|
All rights granted under this License are granted for the term of
|
||||||
|
copyright on the Program, and are irrevocable provided the stated
|
||||||
|
conditions are met. This License explicitly affirms your unlimited
|
||||||
|
permission to run the unmodified Program. The output from running a
|
||||||
|
covered work is covered by this License only if the output, given its
|
||||||
|
content, constitutes a covered work. This License acknowledges your
|
||||||
|
rights of fair use or other equivalent, as provided by copyright law.
|
||||||
|
|
||||||
|
You may make, run and propagate covered works that you do not
|
||||||
|
convey, without conditions so long as your license otherwise remains
|
||||||
|
in force. You may convey covered works to others for the sole purpose
|
||||||
|
of having them make modifications exclusively for you, or provide you
|
||||||
|
with facilities for running those works, provided that you comply with
|
||||||
|
the terms of this License in conveying all material for which you do
|
||||||
|
not control copyright. Those thus making or running the covered works
|
||||||
|
for you must do so exclusively on your behalf, under your direction
|
||||||
|
and control, on terms that prohibit them from making any copies of
|
||||||
|
your copyrighted material outside their relationship with you.
|
||||||
|
|
||||||
|
Conveying under any other circumstances is permitted solely under
|
||||||
|
the conditions stated below. Sublicensing is not allowed; section 10
|
||||||
|
makes it unnecessary.
|
||||||
|
|
||||||
|
3. Protecting Users' Legal Rights From Anti-Circumvention Law.
|
||||||
|
|
||||||
|
No covered work shall be deemed part of an effective technological
|
||||||
|
measure under any applicable law fulfilling obligations under article
|
||||||
|
11 of the WIPO copyright treaty adopted on 20 December 1996, or
|
||||||
|
similar laws prohibiting or restricting circumvention of such
|
||||||
|
measures.
|
||||||
|
|
||||||
|
When you convey a covered work, you waive any legal power to forbid
|
||||||
|
circumvention of technological measures to the extent such circumvention
|
||||||
|
is effected by exercising rights under this License with respect to
|
||||||
|
the covered work, and you disclaim any intention to limit operation or
|
||||||
|
modification of the work as a means of enforcing, against the work's
|
||||||
|
users, your or third parties' legal rights to forbid circumvention of
|
||||||
|
technological measures.
|
||||||
|
|
||||||
|
4. Conveying Verbatim Copies.
|
||||||
|
|
||||||
|
You may convey verbatim copies of the Program's source code as you
|
||||||
|
receive it, in any medium, provided that you conspicuously and
|
||||||
|
appropriately publish on each copy an appropriate copyright notice;
|
||||||
|
keep intact all notices stating that this License and any
|
||||||
|
non-permissive terms added in accord with section 7 apply to the code;
|
||||||
|
keep intact all notices of the absence of any warranty; and give all
|
||||||
|
recipients a copy of this License along with the Program.
|
||||||
|
|
||||||
|
You may charge any price or no price for each copy that you convey,
|
||||||
|
or you may offer support or warranty protection for a fee.
|
||||||
|
|
||||||
|
5. Conveying Modified Source Versions.
|
||||||
|
|
||||||
|
You may convey a work based on the Program, or the modifications to
|
||||||
|
produce it from the Program, in the form of source code under the
|
||||||
|
terms of section 4, provided that you also meet all of these conditions:
|
||||||
|
|
||||||
|
a) The work must carry prominent notices stating that you modified
|
||||||
|
it, and giving a relevant date.
|
||||||
|
|
||||||
|
b) The work must carry prominent notices stating that it is
|
||||||
|
released under this License and any conditions added under section
|
||||||
|
7. This requirement modifies the requirement in section 4 to
|
||||||
|
"keep intact all notices".
|
||||||
|
|
||||||
|
c) You must license the entire work, as a whole, under this
|
||||||
|
License to anyone who comes into possession of a copy. This
|
||||||
|
License will therefore apply, along with any applicable section 7
|
||||||
|
additional terms, to the whole of the work, and all its parts,
|
||||||
|
regardless of how they are packaged. This License gives no
|
||||||
|
permission to license the work in any other way, but it does not
|
||||||
|
invalidate such permission if you have separately received it.
|
||||||
|
|
||||||
|
d) If the work has interactive user interfaces, each must display
|
||||||
|
Appropriate Legal Notices; however, if the Program has interactive
|
||||||
|
interfaces that do not display Appropriate Legal Notices, your
|
||||||
|
work need not make them do so.
|
||||||
|
|
||||||
|
A compilation of a covered work with other separate and independent
|
||||||
|
works, which are not by their nature extensions of the covered work,
|
||||||
|
and which are not combined with it such as to form a larger program,
|
||||||
|
in or on a volume of a storage or distribution medium, is called an
|
||||||
|
"aggregate" if the compilation and its resulting copyright are not
|
||||||
|
used to limit the access or legal rights of the compilation's users
|
||||||
|
beyond what the individual works permit. Inclusion of a covered work
|
||||||
|
in an aggregate does not cause this License to apply to the other
|
||||||
|
parts of the aggregate.
|
||||||
|
|
||||||
|
6. Conveying Non-Source Forms.
|
||||||
|
|
||||||
|
You may convey a covered work in object code form under the terms
|
||||||
|
of sections 4 and 5, provided that you also convey the
|
||||||
|
machine-readable Corresponding Source under the terms of this License,
|
||||||
|
in one of these ways:
|
||||||
|
|
||||||
|
a) Convey the object code in, or embodied in, a physical product
|
||||||
|
(including a physical distribution medium), accompanied by the
|
||||||
|
Corresponding Source fixed on a durable physical medium
|
||||||
|
customarily used for software interchange.
|
||||||
|
|
||||||
|
b) Convey the object code in, or embodied in, a physical product
|
||||||
|
(including a physical distribution medium), accompanied by a
|
||||||
|
written offer, valid for at least three years and valid for as
|
||||||
|
long as you offer spare parts or customer support for that product
|
||||||
|
model, to give anyone who possesses the object code either (1) a
|
||||||
|
copy of the Corresponding Source for all the software in the
|
||||||
|
product that is covered by this License, on a durable physical
|
||||||
|
medium customarily used for software interchange, for a price no
|
||||||
|
more than your reasonable cost of physically performing this
|
||||||
|
conveying of source, or (2) access to copy the Corresponding
|
||||||
|
Source from a network server at no charge.
|
||||||
|
|
||||||
|
c) Convey individual copies of the object code with a copy of the
|
||||||
|
written offer to provide the Corresponding Source. This
|
||||||
|
alternative is allowed only occasionally and noncommercially, and
|
||||||
|
only if you received the object code with such an offer, in accord
|
||||||
|
with subsection 6b.
|
||||||
|
|
||||||
|
d) Convey the object code by offering access from a designated
|
||||||
|
place (gratis or for a charge), and offer equivalent access to the
|
||||||
|
Corresponding Source in the same way through the same place at no
|
||||||
|
further charge. You need not require recipients to copy the
|
||||||
|
Corresponding Source along with the object code. If the place to
|
||||||
|
copy the object code is a network server, the Corresponding Source
|
||||||
|
may be on a different server (operated by you or a third party)
|
||||||
|
that supports equivalent copying facilities, provided you maintain
|
||||||
|
clear directions next to the object code saying where to find the
|
||||||
|
Corresponding Source. Regardless of what server hosts the
|
||||||
|
Corresponding Source, you remain obligated to ensure that it is
|
||||||
|
available for as long as needed to satisfy these requirements.
|
||||||
|
|
||||||
|
e) Convey the object code using peer-to-peer transmission, provided
|
||||||
|
you inform other peers where the object code and Corresponding
|
||||||
|
Source of the work are being offered to the general public at no
|
||||||
|
charge under subsection 6d.
|
||||||
|
|
||||||
|
A separable portion of the object code, whose source code is excluded
|
||||||
|
from the Corresponding Source as a System Library, need not be
|
||||||
|
included in conveying the object code work.
|
||||||
|
|
||||||
|
A "User Product" is either (1) a "consumer product", which means any
|
||||||
|
tangible personal property which is normally used for personal, family,
|
||||||
|
or household purposes, or (2) anything designed or sold for incorporation
|
||||||
|
into a dwelling. In determining whether a product is a consumer product,
|
||||||
|
doubtful cases shall be resolved in favor of coverage. For a particular
|
||||||
|
product received by a particular user, "normally used" refers to a
|
||||||
|
typical or common use of that class of product, regardless of the status
|
||||||
|
of the particular user or of the way in which the particular user
|
||||||
|
actually uses, or expects or is expected to use, the product. A product
|
||||||
|
is a consumer product regardless of whether the product has substantial
|
||||||
|
commercial, industrial or non-consumer uses, unless such uses represent
|
||||||
|
the only significant mode of use of the product.
|
||||||
|
|
||||||
|
"Installation Information" for a User Product means any methods,
|
||||||
|
procedures, authorization keys, or other information required to install
|
||||||
|
and execute modified versions of a covered work in that User Product from
|
||||||
|
a modified version of its Corresponding Source. The information must
|
||||||
|
suffice to ensure that the continued functioning of the modified object
|
||||||
|
code is in no case prevented or interfered with solely because
|
||||||
|
modification has been made.
|
||||||
|
|
||||||
|
If you convey an object code work under this section in, or with, or
|
||||||
|
specifically for use in, a User Product, and the conveying occurs as
|
||||||
|
part of a transaction in which the right of possession and use of the
|
||||||
|
User Product is transferred to the recipient in perpetuity or for a
|
||||||
|
fixed term (regardless of how the transaction is characterized), the
|
||||||
|
Corresponding Source conveyed under this section must be accompanied
|
||||||
|
by the Installation Information. But this requirement does not apply
|
||||||
|
if neither you nor any third party retains the ability to install
|
||||||
|
modified object code on the User Product (for example, the work has
|
||||||
|
been installed in ROM).
|
||||||
|
|
||||||
|
The requirement to provide Installation Information does not include a
|
||||||
|
requirement to continue to provide support service, warranty, or updates
|
||||||
|
for a work that has been modified or installed by the recipient, or for
|
||||||
|
the User Product in which it has been modified or installed. Access to a
|
||||||
|
network may be denied when the modification itself materially and
|
||||||
|
adversely affects the operation of the network or violates the rules and
|
||||||
|
protocols for communication across the network.
|
||||||
|
|
||||||
|
Corresponding Source conveyed, and Installation Information provided,
|
||||||
|
in accord with this section must be in a format that is publicly
|
||||||
|
documented (and with an implementation available to the public in
|
||||||
|
source code form), and must require no special password or key for
|
||||||
|
unpacking, reading or copying.
|
||||||
|
|
||||||
|
7. Additional Terms.
|
||||||
|
|
||||||
|
"Additional permissions" are terms that supplement the terms of this
|
||||||
|
License by making exceptions from one or more of its conditions.
|
||||||
|
Additional permissions that are applicable to the entire Program shall
|
||||||
|
be treated as though they were included in this License, to the extent
|
||||||
|
that they are valid under applicable law. If additional permissions
|
||||||
|
apply only to part of the Program, that part may be used separately
|
||||||
|
under those permissions, but the entire Program remains governed by
|
||||||
|
this License without regard to the additional permissions.
|
||||||
|
|
||||||
|
When you convey a copy of a covered work, you may at your option
|
||||||
|
remove any additional permissions from that copy, or from any part of
|
||||||
|
it. (Additional permissions may be written to require their own
|
||||||
|
removal in certain cases when you modify the work.) You may place
|
||||||
|
additional permissions on material, added by you to a covered work,
|
||||||
|
for which you have or can give appropriate copyright permission.
|
||||||
|
|
||||||
|
Notwithstanding any other provision of this License, for material you
|
||||||
|
add to a covered work, you may (if authorized by the copyright holders of
|
||||||
|
that material) supplement the terms of this License with terms:
|
||||||
|
|
||||||
|
a) Disclaiming warranty or limiting liability differently from the
|
||||||
|
terms of sections 15 and 16 of this License; or
|
||||||
|
|
||||||
|
b) Requiring preservation of specified reasonable legal notices or
|
||||||
|
author attributions in that material or in the Appropriate Legal
|
||||||
|
Notices displayed by works containing it; or
|
||||||
|
|
||||||
|
c) Prohibiting misrepresentation of the origin of that material, or
|
||||||
|
requiring that modified versions of such material be marked in
|
||||||
|
reasonable ways as different from the original version; or
|
||||||
|
|
||||||
|
d) Limiting the use for publicity purposes of names of licensors or
|
||||||
|
authors of the material; or
|
||||||
|
|
||||||
|
e) Declining to grant rights under trademark law for use of some
|
||||||
|
trade names, trademarks, or service marks; or
|
||||||
|
|
||||||
|
f) Requiring indemnification of licensors and authors of that
|
||||||
|
material by anyone who conveys the material (or modified versions of
|
||||||
|
it) with contractual assumptions of liability to the recipient, for
|
||||||
|
any liability that these contractual assumptions directly impose on
|
||||||
|
those licensors and authors.
|
||||||
|
|
||||||
|
All other non-permissive additional terms are considered "further
|
||||||
|
restrictions" within the meaning of section 10. If the Program as you
|
||||||
|
received it, or any part of it, contains a notice stating that it is
|
||||||
|
governed by this License along with a term that is a further
|
||||||
|
restriction, you may remove that term. If a license document contains
|
||||||
|
a further restriction but permits relicensing or conveying under this
|
||||||
|
License, you may add to a covered work material governed by the terms
|
||||||
|
of that license document, provided that the further restriction does
|
||||||
|
not survive such relicensing or conveying.
|
||||||
|
|
||||||
|
If you add terms to a covered work in accord with this section, you
|
||||||
|
must place, in the relevant source files, a statement of the
|
||||||
|
additional terms that apply to those files, or a notice indicating
|
||||||
|
where to find the applicable terms.
|
||||||
|
|
||||||
|
Additional terms, permissive or non-permissive, may be stated in the
|
||||||
|
form of a separately written license, or stated as exceptions;
|
||||||
|
the above requirements apply either way.
|
||||||
|
|
||||||
|
8. Termination.
|
||||||
|
|
||||||
|
You may not propagate or modify a covered work except as expressly
|
||||||
|
provided under this License. Any attempt otherwise to propagate or
|
||||||
|
modify it is void, and will automatically terminate your rights under
|
||||||
|
this License (including any patent licenses granted under the third
|
||||||
|
paragraph of section 11).
|
||||||
|
|
||||||
|
However, if you cease all violation of this License, then your
|
||||||
|
license from a particular copyright holder is reinstated (a)
|
||||||
|
provisionally, unless and until the copyright holder explicitly and
|
||||||
|
finally terminates your license, and (b) permanently, if the copyright
|
||||||
|
holder fails to notify you of the violation by some reasonable means
|
||||||
|
prior to 60 days after the cessation.
|
||||||
|
|
||||||
|
Moreover, your license from a particular copyright holder is
|
||||||
|
reinstated permanently if the copyright holder notifies you of the
|
||||||
|
violation by some reasonable means, this is the first time you have
|
||||||
|
received notice of violation of this License (for any work) from that
|
||||||
|
copyright holder, and you cure the violation prior to 30 days after
|
||||||
|
your receipt of the notice.
|
||||||
|
|
||||||
|
Termination of your rights under this section does not terminate the
|
||||||
|
licenses of parties who have received copies or rights from you under
|
||||||
|
this License. If your rights have been terminated and not permanently
|
||||||
|
reinstated, you do not qualify to receive new licenses for the same
|
||||||
|
material under section 10.
|
||||||
|
|
||||||
|
9. Acceptance Not Required for Having Copies.
|
||||||
|
|
||||||
|
You are not required to accept this License in order to receive or
|
||||||
|
run a copy of the Program. Ancillary propagation of a covered work
|
||||||
|
occurring solely as a consequence of using peer-to-peer transmission
|
||||||
|
to receive a copy likewise does not require acceptance. However,
|
||||||
|
nothing other than this License grants you permission to propagate or
|
||||||
|
modify any covered work. These actions infringe copyright if you do
|
||||||
|
not accept this License. Therefore, by modifying or propagating a
|
||||||
|
covered work, you indicate your acceptance of this License to do so.
|
||||||
|
|
||||||
|
10. Automatic Licensing of Downstream Recipients.
|
||||||
|
|
||||||
|
Each time you convey a covered work, the recipient automatically
|
||||||
|
receives a license from the original licensors, to run, modify and
|
||||||
|
propagate that work, subject to this License. You are not responsible
|
||||||
|
for enforcing compliance by third parties with this License.
|
||||||
|
|
||||||
|
An "entity transaction" is a transaction transferring control of an
|
||||||
|
organization, or substantially all assets of one, or subdividing an
|
||||||
|
organization, or merging organizations. If propagation of a covered
|
||||||
|
work results from an entity transaction, each party to that
|
||||||
|
transaction who receives a copy of the work also receives whatever
|
||||||
|
licenses to the work the party's predecessor in interest had or could
|
||||||
|
give under the previous paragraph, plus a right to possession of the
|
||||||
|
Corresponding Source of the work from the predecessor in interest, if
|
||||||
|
the predecessor has it or can get it with reasonable efforts.
|
||||||
|
|
||||||
|
You may not impose any further restrictions on the exercise of the
|
||||||
|
rights granted or affirmed under this License. For example, you may
|
||||||
|
not impose a license fee, royalty, or other charge for exercise of
|
||||||
|
rights granted under this License, and you may not initiate litigation
|
||||||
|
(including a cross-claim or counterclaim in a lawsuit) alleging that
|
||||||
|
any patent claim is infringed by making, using, selling, offering for
|
||||||
|
sale, or importing the Program or any portion of it.
|
||||||
|
|
||||||
|
11. Patents.
|
||||||
|
|
||||||
|
A "contributor" is a copyright holder who authorizes use under this
|
||||||
|
License of the Program or a work on which the Program is based. The
|
||||||
|
work thus licensed is called the contributor's "contributor version".
|
||||||
|
|
||||||
|
A contributor's "essential patent claims" are all patent claims
|
||||||
|
owned or controlled by the contributor, whether already acquired or
|
||||||
|
hereafter acquired, that would be infringed by some manner, permitted
|
||||||
|
by this License, of making, using, or selling its contributor version,
|
||||||
|
but do not include claims that would be infringed only as a
|
||||||
|
consequence of further modification of the contributor version. For
|
||||||
|
purposes of this definition, "control" includes the right to grant
|
||||||
|
patent sublicenses in a manner consistent with the requirements of
|
||||||
|
this License.
|
||||||
|
|
||||||
|
Each contributor grants you a non-exclusive, worldwide, royalty-free
|
||||||
|
patent license under the contributor's essential patent claims, to
|
||||||
|
make, use, sell, offer for sale, import and otherwise run, modify and
|
||||||
|
propagate the contents of its contributor version.
|
||||||
|
|
||||||
|
In the following three paragraphs, a "patent license" is any express
|
||||||
|
agreement or commitment, however denominated, not to enforce a patent
|
||||||
|
(such as an express permission to practice a patent or covenant not to
|
||||||
|
sue for patent infringement). To "grant" such a patent license to a
|
||||||
|
party means to make such an agreement or commitment not to enforce a
|
||||||
|
patent against the party.
|
||||||
|
|
||||||
|
If you convey a covered work, knowingly relying on a patent license,
|
||||||
|
and the Corresponding Source of the work is not available for anyone
|
||||||
|
to copy, free of charge and under the terms of this License, through a
|
||||||
|
publicly available network server or other readily accessible means,
|
||||||
|
then you must either (1) cause the Corresponding Source to be so
|
||||||
|
available, or (2) arrange to deprive yourself of the benefit of the
|
||||||
|
patent license for this particular work, or (3) arrange, in a manner
|
||||||
|
consistent with the requirements of this License, to extend the patent
|
||||||
|
license to downstream recipients. "Knowingly relying" means you have
|
||||||
|
actual knowledge that, but for the patent license, your conveying the
|
||||||
|
covered work in a country, or your recipient's use of the covered work
|
||||||
|
in a country, would infringe one or more identifiable patents in that
|
||||||
|
country that you have reason to believe are valid.
|
||||||
|
|
||||||
|
If, pursuant to or in connection with a single transaction or
|
||||||
|
arrangement, you convey, or propagate by procuring conveyance of, a
|
||||||
|
covered work, and grant a patent license to some of the parties
|
||||||
|
receiving the covered work authorizing them to use, propagate, modify
|
||||||
|
or convey a specific copy of the covered work, then the patent license
|
||||||
|
you grant is automatically extended to all recipients of the covered
|
||||||
|
work and works based on it.
|
||||||
|
|
||||||
|
A patent license is "discriminatory" if it does not include within
|
||||||
|
the scope of its coverage, prohibits the exercise of, or is
|
||||||
|
conditioned on the non-exercise of one or more of the rights that are
|
||||||
|
specifically granted under this License. You may not convey a covered
|
||||||
|
work if you are a party to an arrangement with a third party that is
|
||||||
|
in the business of distributing software, under which you make payment
|
||||||
|
to the third party based on the extent of your activity of conveying
|
||||||
|
the work, and under which the third party grants, to any of the
|
||||||
|
parties who would receive the covered work from you, a discriminatory
|
||||||
|
patent license (a) in connection with copies of the covered work
|
||||||
|
conveyed by you (or copies made from those copies), or (b) primarily
|
||||||
|
for and in connection with specific products or compilations that
|
||||||
|
contain the covered work, unless you entered into that arrangement,
|
||||||
|
or that patent license was granted, prior to 28 March 2007.
|
||||||
|
|
||||||
|
Nothing in this License shall be construed as excluding or limiting
|
||||||
|
any implied license or other defenses to infringement that may
|
||||||
|
otherwise be available to you under applicable patent law.
|
||||||
|
|
||||||
|
12. No Surrender of Others' Freedom.
|
||||||
|
|
||||||
|
If conditions are imposed on you (whether by court order, agreement or
|
||||||
|
otherwise) that contradict the conditions of this License, they do not
|
||||||
|
excuse you from the conditions of this License. If you cannot convey a
|
||||||
|
covered work so as to satisfy simultaneously your obligations under this
|
||||||
|
License and any other pertinent obligations, then as a consequence you may
|
||||||
|
not convey it at all. For example, if you agree to terms that obligate you
|
||||||
|
to collect a royalty for further conveying from those to whom you convey
|
||||||
|
the Program, the only way you could satisfy both those terms and this
|
||||||
|
License would be to refrain entirely from conveying the Program.
|
||||||
|
|
||||||
|
13. Use with the GNU Affero General Public License.
|
||||||
|
|
||||||
|
Notwithstanding any other provision of this License, you have
|
||||||
|
permission to link or combine any covered work with a work licensed
|
||||||
|
under version 3 of the GNU Affero General Public License into a single
|
||||||
|
combined work, and to convey the resulting work. The terms of this
|
||||||
|
License will continue to apply to the part which is the covered work,
|
||||||
|
but the special requirements of the GNU Affero General Public License,
|
||||||
|
section 13, concerning interaction through a network will apply to the
|
||||||
|
combination as such.
|
||||||
|
|
||||||
|
14. Revised Versions of this License.
|
||||||
|
|
||||||
|
The Free Software Foundation may publish revised and/or new versions of
|
||||||
|
the GNU General Public License from time to time. Such new versions will
|
||||||
|
be similar in spirit to the present version, but may differ in detail to
|
||||||
|
address new problems or concerns.
|
||||||
|
|
||||||
|
Each version is given a distinguishing version number. If the
|
||||||
|
Program specifies that a certain numbered version of the GNU General
|
||||||
|
Public License "or any later version" applies to it, you have the
|
||||||
|
option of following the terms and conditions either of that numbered
|
||||||
|
version or of any later version published by the Free Software
|
||||||
|
Foundation. If the Program does not specify a version number of the
|
||||||
|
GNU General Public License, you may choose any version ever published
|
||||||
|
by the Free Software Foundation.
|
||||||
|
|
||||||
|
If the Program specifies that a proxy can decide which future
|
||||||
|
versions of the GNU General Public License can be used, that proxy's
|
||||||
|
public statement of acceptance of a version permanently authorizes you
|
||||||
|
to choose that version for the Program.
|
||||||
|
|
||||||
|
Later license versions may give you additional or different
|
||||||
|
permissions. However, no additional obligations are imposed on any
|
||||||
|
author or copyright holder as a result of your choosing to follow a
|
||||||
|
later version.
|
||||||
|
|
||||||
|
15. Disclaimer of Warranty.
|
||||||
|
|
||||||
|
THERE IS NO WARRANTY FOR THE PROGRAM, TO THE EXTENT PERMITTED BY
|
||||||
|
APPLICABLE LAW. EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT
|
||||||
|
HOLDERS AND/OR OTHER PARTIES PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY
|
||||||
|
OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO,
|
||||||
|
THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
|
||||||
|
PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE PROGRAM
|
||||||
|
IS WITH YOU. SHOULD THE PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF
|
||||||
|
ALL NECESSARY SERVICING, REPAIR OR CORRECTION.
|
||||||
|
|
||||||
|
16. Limitation of Liability.
|
||||||
|
|
||||||
|
IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING
|
||||||
|
WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MODIFIES AND/OR CONVEYS
|
||||||
|
THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, INCLUDING ANY
|
||||||
|
GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE
|
||||||
|
USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED TO LOSS OF
|
||||||
|
DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD
|
||||||
|
PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER PROGRAMS),
|
||||||
|
EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF
|
||||||
|
SUCH DAMAGES.
|
||||||
|
|
||||||
|
17. Interpretation of Sections 15 and 16.
|
||||||
|
|
||||||
|
If the disclaimer of warranty and limitation of liability provided
|
||||||
|
above cannot be given local legal effect according to their terms,
|
||||||
|
reviewing courts shall apply local law that most closely approximates
|
||||||
|
an absolute waiver of all civil liability in connection with the
|
||||||
|
Program, unless a warranty or assumption of liability accompanies a
|
||||||
|
copy of the Program in return for a fee.
|
||||||
|
|
||||||
|
END OF TERMS AND CONDITIONS
|
||||||
|
|
||||||
|
How to Apply These Terms to Your New Programs
|
||||||
|
|
||||||
|
If you develop a new program, and you want it to be of the greatest
|
||||||
|
possible use to the public, the best way to achieve this is to make it
|
||||||
|
free software which everyone can redistribute and change under these terms.
|
||||||
|
|
||||||
|
To do so, attach the following notices to the program. It is safest
|
||||||
|
to attach them to the start of each source file to most effectively
|
||||||
|
state the exclusion of warranty; and each file should have at least
|
||||||
|
the "copyright" line and a pointer to where the full notice is found.
|
||||||
|
|
||||||
|
<one line to give the program's name and a brief idea of what it does.>
|
||||||
|
Copyright (C) <year> <name of author>
|
||||||
|
|
||||||
|
This program is free software: you can redistribute it and/or modify
|
||||||
|
it under the terms of the GNU General Public License as published by
|
||||||
|
the Free Software Foundation, either version 3 of the License, or
|
||||||
|
(at your option) any later version.
|
||||||
|
|
||||||
|
This program is distributed in the hope that it will be useful,
|
||||||
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
GNU General Public License for more details.
|
||||||
|
|
||||||
|
You should have received a copy of the GNU General Public License
|
||||||
|
along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||||
|
|
||||||
|
Also add information on how to contact you by electronic and paper mail.
|
||||||
|
|
||||||
|
If the program does terminal interaction, make it output a short
|
||||||
|
notice like this when it starts in an interactive mode:
|
||||||
|
|
||||||
|
<program> Copyright (C) <year> <name of author>
|
||||||
|
This program comes with ABSOLUTELY NO WARRANTY; for details type `show w'.
|
||||||
|
This is free software, and you are welcome to redistribute it
|
||||||
|
under certain conditions; type `show c' for details.
|
||||||
|
|
||||||
|
The hypothetical commands `show w' and `show c' should show the appropriate
|
||||||
|
parts of the General Public License. Of course, your program's commands
|
||||||
|
might be different; for a GUI interface, you would use an "about box".
|
||||||
|
|
||||||
|
You should also get your employer (if you work as a programmer) or school,
|
||||||
|
if any, to sign a "copyright disclaimer" for the program, if necessary.
|
||||||
|
For more information on this, and how to apply and follow the GNU GPL, see
|
||||||
|
<https://www.gnu.org/licenses/>.
|
||||||
|
|
||||||
|
The GNU General Public License does not permit incorporating your program
|
||||||
|
into proprietary programs. If your program is a subroutine library, you
|
||||||
|
may consider it more useful to permit linking proprietary applications with
|
||||||
|
the library. If this is what you want to do, use the GNU Lesser General
|
||||||
|
Public License instead of this License. But first, please read
|
||||||
|
<https://www.gnu.org/licenses/why-not-lgpl.html>.
|
||||||
206
README.md
Normal file
206
README.md
Normal file
@@ -0,0 +1,206 @@
|
|||||||
|
# BedwarsRel - 指令商店物品扩展版
|
||||||
|
|
||||||
|
基于 [BedwarsRel](https://github.com/BedwarsRel/BedwarsRel) 的改进版本,添加了**指令商店物品**功能支持。
|
||||||
|
|
||||||
|
[](https://www.gnu.org/licenses/gpl-3.0)
|
||||||
|
[](https://www.minecraft.net/)
|
||||||
|
[](https://www.spigotmc.org/)
|
||||||
|
|
||||||
|
## 📋 项目说明
|
||||||
|
|
||||||
|
本项目是 BedwarsRel 的分支版本,在保留原项目所有功能的基础上,添加了**商店物品执行指令**功能。这使得服务器管理员可以配置特殊的商店物品,当玩家购买时执行自定义命令而非给予物品。
|
||||||
|
|
||||||
|
### 原项目信息
|
||||||
|
|
||||||
|
- **原作者**: BedwarsRel-Team
|
||||||
|
- **原仓库**: https://github.com/BedwarsRel/BedwarsRel
|
||||||
|
- **原许可证**: GNU General Public License v3.0
|
||||||
|
|
||||||
|
## ✨ 新增功能
|
||||||
|
|
||||||
|
### 1. 指令商店物品支持
|
||||||
|
|
||||||
|
在 `shop.yml` 中配置带命令的商店物品:
|
||||||
|
|
||||||
|
```yaml
|
||||||
|
shop:
|
||||||
|
special:
|
||||||
|
item: STICK
|
||||||
|
name: "§d特殊商店"
|
||||||
|
order: 1
|
||||||
|
offers:
|
||||||
|
- reward:
|
||||||
|
- item: STONE
|
||||||
|
amount: 1
|
||||||
|
name: "§c测试命令物品"
|
||||||
|
commands:
|
||||||
|
- 'say %player% 购买了命令物品'
|
||||||
|
- 'give %player% diamond 1'
|
||||||
|
price:
|
||||||
|
- type: IRON_INGOT
|
||||||
|
amount: 4
|
||||||
|
```
|
||||||
|
|
||||||
|
### 2. 支持两种配置格式
|
||||||
|
|
||||||
|
**格式1 - 扩展格式**(推荐):
|
||||||
|
```yaml
|
||||||
|
reward:
|
||||||
|
- item: LINGERING_POTION
|
||||||
|
amount: 1
|
||||||
|
name: "§c力量药水"
|
||||||
|
lore:
|
||||||
|
- '§7效果: 力量 I'
|
||||||
|
effects:
|
||||||
|
- type: STRENGTH
|
||||||
|
duration: 180
|
||||||
|
amplifier: 1
|
||||||
|
```
|
||||||
|
|
||||||
|
**格式2 - 标准格式**:
|
||||||
|
```yaml
|
||||||
|
reward:
|
||||||
|
- type: STONE
|
||||||
|
amount: 1
|
||||||
|
meta:
|
||||||
|
display-name: "§c测试物品"
|
||||||
|
```
|
||||||
|
|
||||||
|
### 3. 与 BedwarsXP 兼容
|
||||||
|
|
||||||
|
修改后的版本同时支持 BedwarsXP 经验商店插件,在经验模式下也能正常使用指令商店物品。
|
||||||
|
|
||||||
|
## 📥 安装说明
|
||||||
|
|
||||||
|
### 前置要求
|
||||||
|
|
||||||
|
- Spigot/Paper 1.12.2 服务器
|
||||||
|
- Java 8 或更高版本
|
||||||
|
|
||||||
|
### 安装步骤
|
||||||
|
|
||||||
|
1. 下载 `BedwarsRel-1.3.6.jar`
|
||||||
|
2. 将 jar 文件放入服务器的 `plugins/` 目录
|
||||||
|
3. 重启服务器
|
||||||
|
4. 编辑 `plugins/BedwarsRel/shop.yml` 添加带命令的商店物品
|
||||||
|
5. 使用 `/bw reload` 重载配置
|
||||||
|
|
||||||
|
## 🔧 配置示例
|
||||||
|
|
||||||
|
### 完整 shop.yml 示例
|
||||||
|
|
||||||
|
```yaml
|
||||||
|
shop:
|
||||||
|
blocks:
|
||||||
|
item: SANDSTONE
|
||||||
|
name: "§e方块"
|
||||||
|
order: 10
|
||||||
|
lore:
|
||||||
|
- "§7建筑方块"
|
||||||
|
offers:
|
||||||
|
# 普通物品
|
||||||
|
- reward:
|
||||||
|
- type: SANDSTONE
|
||||||
|
amount: 4
|
||||||
|
price:
|
||||||
|
- type: BRONZE
|
||||||
|
amount: 1
|
||||||
|
meta:
|
||||||
|
display-name: "§c青铜"
|
||||||
|
|
||||||
|
# 命令物品示例
|
||||||
|
- reward:
|
||||||
|
- item: STONE
|
||||||
|
amount: 1
|
||||||
|
name: "§c传送物品"
|
||||||
|
lore:
|
||||||
|
- "§7点击传送到基地"
|
||||||
|
commands:
|
||||||
|
- 'tp %player% 0 100 0'
|
||||||
|
- 'say %player% 使用了传送物品!'
|
||||||
|
price:
|
||||||
|
- type: IRON_INGOT
|
||||||
|
amount: 2
|
||||||
|
meta:
|
||||||
|
display-name: "§7铁锭"
|
||||||
|
|
||||||
|
weapons:
|
||||||
|
item: DIAMOND_SWORD
|
||||||
|
name: "§c武器"
|
||||||
|
order: 20
|
||||||
|
offers:
|
||||||
|
- reward:
|
||||||
|
- type: DIAMOND_SWORD
|
||||||
|
amount: 1
|
||||||
|
meta:
|
||||||
|
enchants:
|
||||||
|
DAMAGE_ALL: 1
|
||||||
|
price:
|
||||||
|
- type: GOLD_INGOT
|
||||||
|
amount: 4
|
||||||
|
meta:
|
||||||
|
display-name: "§6金锭"
|
||||||
|
```
|
||||||
|
|
||||||
|
## 🏗️ 构建说明
|
||||||
|
|
||||||
|
### 环境要求
|
||||||
|
|
||||||
|
- Maven 3.6+
|
||||||
|
- Java 8
|
||||||
|
- Git
|
||||||
|
|
||||||
|
### 构建步骤
|
||||||
|
|
||||||
|
```bash
|
||||||
|
# 克隆仓库
|
||||||
|
git clone https://git.lnkos.cn/atob/BedwarsRel.git
|
||||||
|
cd BedwarsRel-CommandShop
|
||||||
|
|
||||||
|
# 构建项目
|
||||||
|
mvn clean package -DskipTests
|
||||||
|
|
||||||
|
# 生成的 jar 文件位于:
|
||||||
|
# plugin/target/BedwarsRel-1.3.6.jar
|
||||||
|
```
|
||||||
|
|
||||||
|
### 模块说明
|
||||||
|
|
||||||
|
- `common/` - 核心代码模块
|
||||||
|
- `v1_12_r1/` - 1.12.2 版本 NMS 适配
|
||||||
|
- `plugin/` - 最终打包模块
|
||||||
|
|
||||||
|
## 📜 许可证
|
||||||
|
|
||||||
|
本项目基于 [GNU General Public License v3.0](LICENSE) 发布。
|
||||||
|
|
||||||
|
### 改进内容版权声明
|
||||||
|
|
||||||
|
本改进版本在 BedwarsRel 原项目基础上添加了以下功能:
|
||||||
|
- 指令商店物品支持
|
||||||
|
- 改进的物品匹配逻辑
|
||||||
|
- BedwarsXP 插件兼容性支持
|
||||||
|
|
||||||
|
所有新增代码同样遵循 GPL-3.0 许可证。
|
||||||
|
|
||||||
|
## 🤝 贡献指南
|
||||||
|
|
||||||
|
欢迎提交 Issue 和 Pull Request!
|
||||||
|
|
||||||
|
## 📝 更新日志
|
||||||
|
|
||||||
|
### v1.3.6+ (2026-04-01)
|
||||||
|
|
||||||
|
- ✨ 新增指令商店物品功能
|
||||||
|
- ✨ 兼容 BedwarsXP 经验商店插件
|
||||||
|
- 🔧 修复物品匹配逻辑问题
|
||||||
|
- 🔧 优化药水类物品解析
|
||||||
|
|
||||||
|
## 👥 致谢
|
||||||
|
|
||||||
|
- [BedwarsRel-Team](https://github.com/BedwarsRel) - 原项目开发团队
|
||||||
|
- [SpigotMC](https://www.spigotmc.org/) - 提供服务器 API
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
**免责声明**: 本插件按"原样"提供,不对因使用本插件造成的任何损失负责。
|
||||||
18
build/get-dependencies.sh
Normal file
18
build/get-dependencies.sh
Normal file
@@ -0,0 +1,18 @@
|
|||||||
|
mkdir CraftBukkit
|
||||||
|
cd CraftBukkit
|
||||||
|
wget https://cdn.getbukkit.org/craftbukkit/craftbukkit-1.8-R0.1-SNAPSHOT-latest.jar
|
||||||
|
mvn install:install-file -Dfile=craftbukkit-1.8-R0.1-SNAPSHOT-latest.jar -DgroupId=org.bukkit -DartifactId=craftbukkit -Dversion=1.8-R0.1-SNAPSHOT -Dpackaging=jar
|
||||||
|
wget https://cdn.getbukkit.org/craftbukkit/craftbukkit-1.8.3-R0.1-SNAPSHOT-latest.jar
|
||||||
|
mvn install:install-file -Dfile=craftbukkit-1.8.3-R0.1-SNAPSHOT-latest.jar -DgroupId=org.bukkit -DartifactId=craftbukkit -Dversion=1.8.3-R0.1-SNAPSHOT -Dpackaging=jar
|
||||||
|
wget https://cdn.getbukkit.org/craftbukkit/craftbukkit-1.8.8-R0.1-SNAPSHOT-latest.jar
|
||||||
|
mvn install:install-file -Dfile=craftbukkit-1.8.8-R0.1-SNAPSHOT-latest.jar -DgroupId=org.bukkit -DartifactId=craftbukkit -Dversion=1.8.8-R0.1-SNAPSHOT -Dpackaging=jar
|
||||||
|
wget https://cdn.getbukkit.org/craftbukkit/craftbukkit-1.9.2-R0.1-SNAPSHOT-latest.jar
|
||||||
|
mvn install:install-file -Dfile=craftbukkit-1.9.2-R0.1-SNAPSHOT-latest.jar -DgroupId=org.bukkit -DartifactId=craftbukkit -Dversion=1.9.2-R0.1-SNAPSHOT -Dpackaging=jar
|
||||||
|
wget https://cdn.getbukkit.org/craftbukkit/craftbukkit-1.9.4-R0.1-SNAPSHOT-latest.jar
|
||||||
|
mvn install:install-file -Dfile=craftbukkit-1.9.4-R0.1-SNAPSHOT-latest.jar -DgroupId=org.bukkit -DartifactId=craftbukkit -Dversion=1.9.4-R0.1-SNAPSHOT -Dpackaging=jar
|
||||||
|
wget https://cdn.getbukkit.org/craftbukkit/craftbukkit-1.10.2-R0.1-SNAPSHOT-latest.jar
|
||||||
|
mvn install:install-file -Dfile=craftbukkit-1.10.2-R0.1-SNAPSHOT-latest.jar -DgroupId=org.bukkit -DartifactId=craftbukkit -Dversion=1.10.2-R0.1-SNAPSHOT -Dpackaging=jar
|
||||||
|
wget https://cdn.getbukkit.org/craftbukkit/craftbukkit-1.11.2.jar
|
||||||
|
mvn install:install-file -Dfile=craftbukkit-1.11.2.jar -DgroupId=org.bukkit -DartifactId=craftbukkit -Dversion=1.11.2-R0.1-SNAPSHOT -Dpackaging=jar
|
||||||
|
wget https://cdn.getbukkit.org/craftbukkit/craftbukkit-1.12.jar
|
||||||
|
mvn install:install-file -Dfile=craftbukkit-1.12.jar -DgroupId=org.bukkit -DartifactId=craftbukkit -Dversion=1.12-R0.1-SNAPSHOT -Dpackaging=jar
|
||||||
38
circle.yml
Normal file
38
circle.yml
Normal file
@@ -0,0 +1,38 @@
|
|||||||
|
version: 2
|
||||||
|
executorType: docker
|
||||||
|
containerInfo:
|
||||||
|
- image: maven:3.5-jdk-8
|
||||||
|
jobs:
|
||||||
|
build:
|
||||||
|
branches:
|
||||||
|
ignore:
|
||||||
|
- l10n
|
||||||
|
working_directory: "~/BedwarsRel"
|
||||||
|
steps:
|
||||||
|
- type: checkout
|
||||||
|
- run:
|
||||||
|
name: "Getting Dependencies"
|
||||||
|
command: './get-dependencies.sh'
|
||||||
|
working_directory: "~/BedwarsRel/build"
|
||||||
|
- run:
|
||||||
|
name: "Building and deploying BedwarsRel"
|
||||||
|
command: |
|
||||||
|
export SHORT_HASH=$(echo $CIRCLE_SHA1 | cut -c -7)
|
||||||
|
if [ "${CIRCLE_BRANCH}" == "master" ]
|
||||||
|
then
|
||||||
|
mvn deploy -fae -P ci-release,deploy-snapshot,attach-javadocs,attach-sources --settings settings.xml
|
||||||
|
elif [ "${CIRCLE_BRANCH}" == "develop" ]
|
||||||
|
then
|
||||||
|
mvn deploy -fae -P ci-snapshot,deploy-snapshot,attach-javadocs,attach-sources --settings settings.xml
|
||||||
|
else
|
||||||
|
mvn clean install -fae -P ci-snapshot,attach-javadocs,attach-sources
|
||||||
|
fi
|
||||||
|
mkdir -p plugin/target/artifacts/
|
||||||
|
cp plugin/target/BedwarsRel-*.jar plugin/target/artifacts/.
|
||||||
|
- type: artifacts-store
|
||||||
|
path: plugin/target/artifacts
|
||||||
|
destination: artifacts
|
||||||
|
|
||||||
|
- type: artifacts-store
|
||||||
|
path: plugin/target/apidocs
|
||||||
|
destination: apidocs
|
||||||
35
common/pom.xml
Normal file
35
common/pom.xml
Normal file
@@ -0,0 +1,35 @@
|
|||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<project xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||||
|
xmlns="http://maven.apache.org/POM/4.0.0"
|
||||||
|
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
|
||||||
|
<parent>
|
||||||
|
<artifactId>BedwarsRel-Parent</artifactId>
|
||||||
|
<groupId>io.github.bedwarsrel</groupId>
|
||||||
|
<version>1.3.6</version>
|
||||||
|
</parent>
|
||||||
|
<modelVersion>4.0.0</modelVersion>
|
||||||
|
|
||||||
|
<artifactId>BedwarsRel-Common</artifactId>
|
||||||
|
|
||||||
|
<dependencies>
|
||||||
|
<dependency>
|
||||||
|
<groupId>com.bugsnag</groupId>
|
||||||
|
<artifactId>bugsnag</artifactId>
|
||||||
|
<version>3.0.2</version>
|
||||||
|
<scope>compile</scope>
|
||||||
|
</dependency>
|
||||||
|
<dependency>
|
||||||
|
<groupId>org.slf4j</groupId>
|
||||||
|
<artifactId>slf4j-log4j12</artifactId>
|
||||||
|
<version>1.7.22</version>
|
||||||
|
<scope>compile</scope>
|
||||||
|
</dependency>
|
||||||
|
<dependency>
|
||||||
|
<groupId>com.zaxxer</groupId>
|
||||||
|
<artifactId>HikariCP-java7</artifactId>
|
||||||
|
<version>2.4.11</version>
|
||||||
|
<scope>compile</scope>
|
||||||
|
</dependency>
|
||||||
|
</dependencies>
|
||||||
|
|
||||||
|
</project>
|
||||||
917
common/src/main/java/io/github/bedwarsrel/BedwarsRel.java
Normal file
917
common/src/main/java/io/github/bedwarsrel/BedwarsRel.java
Normal file
@@ -0,0 +1,917 @@
|
|||||||
|
package io.github.bedwarsrel;
|
||||||
|
|
||||||
|
import com.bugsnag.Bugsnag;
|
||||||
|
import com.bugsnag.Report;
|
||||||
|
import com.bugsnag.callbacks.Callback;
|
||||||
|
import com.google.common.collect.ImmutableMap;
|
||||||
|
import io.github.bedwarsrel.commands.*;
|
||||||
|
import io.github.bedwarsrel.database.DatabaseManager;
|
||||||
|
import io.github.bedwarsrel.game.Game;
|
||||||
|
import io.github.bedwarsrel.game.GameManager;
|
||||||
|
import io.github.bedwarsrel.game.GameState;
|
||||||
|
import io.github.bedwarsrel.game.ResourceSpawner;
|
||||||
|
import io.github.bedwarsrel.game.Team;
|
||||||
|
import io.github.bedwarsrel.listener.BlockListener;
|
||||||
|
import io.github.bedwarsrel.listener.ChunkListener;
|
||||||
|
import io.github.bedwarsrel.listener.EntityListener;
|
||||||
|
import io.github.bedwarsrel.listener.HangingListener;
|
||||||
|
import io.github.bedwarsrel.listener.Player19Listener;
|
||||||
|
import io.github.bedwarsrel.listener.PlayerListener;
|
||||||
|
import io.github.bedwarsrel.listener.PlayerSpigotListener;
|
||||||
|
import io.github.bedwarsrel.listener.ServerListener;
|
||||||
|
import io.github.bedwarsrel.listener.SignListener;
|
||||||
|
import io.github.bedwarsrel.listener.WeatherListener;
|
||||||
|
import io.github.bedwarsrel.localization.LocalizationConfig;
|
||||||
|
import io.github.bedwarsrel.shop.Specials.SpecialItem;
|
||||||
|
import io.github.bedwarsrel.statistics.PlayerStatistic;
|
||||||
|
import io.github.bedwarsrel.statistics.PlayerStatisticManager;
|
||||||
|
import io.github.bedwarsrel.statistics.StorageType;
|
||||||
|
import io.github.bedwarsrel.updater.ConfigUpdater;
|
||||||
|
import io.github.bedwarsrel.updater.PluginUpdater;
|
||||||
|
import io.github.bedwarsrel.updater.PluginUpdater.UpdateCallback;
|
||||||
|
import io.github.bedwarsrel.updater.PluginUpdater.UpdateResult;
|
||||||
|
import io.github.bedwarsrel.utils.BStatsMetrics;
|
||||||
|
import io.github.bedwarsrel.utils.BedwarsCommandExecutor;
|
||||||
|
import io.github.bedwarsrel.utils.ChatWriter;
|
||||||
|
import io.github.bedwarsrel.utils.McStatsMetrics;
|
||||||
|
import io.github.bedwarsrel.utils.SupportData;
|
||||||
|
import io.github.bedwarsrel.utils.Utils;
|
||||||
|
import java.io.BufferedReader;
|
||||||
|
import java.io.File;
|
||||||
|
import java.io.FileInputStream;
|
||||||
|
import java.io.FileOutputStream;
|
||||||
|
import java.io.InputStreamReader;
|
||||||
|
import java.io.OutputStreamWriter;
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.HashMap;
|
||||||
|
import java.util.Iterator;
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.Map;
|
||||||
|
import java.util.Map.Entry;
|
||||||
|
import java.util.UUID;
|
||||||
|
import java.util.concurrent.TimeUnit;
|
||||||
|
import lombok.Getter;
|
||||||
|
import org.bukkit.Bukkit;
|
||||||
|
import org.bukkit.ChatColor;
|
||||||
|
import org.bukkit.Location;
|
||||||
|
import org.bukkit.Material;
|
||||||
|
import org.bukkit.command.CommandSender;
|
||||||
|
import org.bukkit.configuration.file.FileConfiguration;
|
||||||
|
import org.bukkit.configuration.file.YamlConfiguration;
|
||||||
|
import org.bukkit.configuration.serialization.ConfigurationSerialization;
|
||||||
|
import org.bukkit.entity.Player;
|
||||||
|
import org.bukkit.plugin.java.JavaPlugin;
|
||||||
|
import org.bukkit.scheduler.BukkitRunnable;
|
||||||
|
import org.bukkit.scheduler.BukkitTask;
|
||||||
|
import org.bukkit.scoreboard.ScoreboardManager;
|
||||||
|
|
||||||
|
public class BedwarsRel extends JavaPlugin {
|
||||||
|
|
||||||
|
public static int PROJECT_ID = 91743;
|
||||||
|
private static BedwarsRel instance = null;
|
||||||
|
private static Boolean locationSerializable = null;
|
||||||
|
private List<Material> breakableTypes = null;
|
||||||
|
@Getter
|
||||||
|
private Bugsnag bugsnag;
|
||||||
|
private ArrayList<BaseCommand> commands = new ArrayList<>();
|
||||||
|
private Package craftbukkit = null;
|
||||||
|
private DatabaseManager dbManager = null;
|
||||||
|
@Getter
|
||||||
|
private GameManager gameManager = null;
|
||||||
|
private boolean isSpigot = false;
|
||||||
|
@Getter
|
||||||
|
private HashMap<String, LocalizationConfig> localization = new HashMap<>();
|
||||||
|
private Package minecraft = null;
|
||||||
|
@Getter
|
||||||
|
private HashMap<UUID, String> playerLocales = new HashMap<>();
|
||||||
|
private PlayerStatisticManager playerStatisticManager = null;
|
||||||
|
private ScoreboardManager scoreboardManager = null;
|
||||||
|
private YamlConfiguration shopConfig = null;
|
||||||
|
private BukkitTask timeTask = null;
|
||||||
|
private BukkitTask updateChecker = null;
|
||||||
|
private String version = null;
|
||||||
|
|
||||||
|
public static String _l(CommandSender commandSender, String key, String singularValue,
|
||||||
|
Map<String, String> params) {
|
||||||
|
return BedwarsRel
|
||||||
|
._l(BedwarsRel.getInstance().getSenderLocale(commandSender), key, singularValue, params);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static String _l(String locale, String key, String singularValue,
|
||||||
|
Map<String, String> params) {
|
||||||
|
if ("1".equals(params.get(singularValue))) {
|
||||||
|
return BedwarsRel._l(locale, key + "-one", params);
|
||||||
|
}
|
||||||
|
return BedwarsRel._l(locale, key, params);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static String _l(CommandSender commandSender, String key, Map<String, String> params) {
|
||||||
|
return BedwarsRel._l(BedwarsRel.getInstance().getSenderLocale(commandSender), key, params);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static String _l(String locale, String key, Map<String, String> params) {
|
||||||
|
if (!BedwarsRel.getInstance().localization.containsKey(locale)) {
|
||||||
|
BedwarsRel.getInstance().loadLocalization(locale);
|
||||||
|
}
|
||||||
|
return (String) BedwarsRel.getInstance().getLocalization().get(locale).get(key, params);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static String _l(CommandSender commandSender, String key) {
|
||||||
|
return BedwarsRel._l(BedwarsRel.getInstance().getSenderLocale(commandSender), key);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static String _l(String key) {
|
||||||
|
return BedwarsRel._l(BedwarsRel.getInstance().getConfig().getString("locale"), key);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static String _l(String locale, String key) {
|
||||||
|
if (!BedwarsRel.getInstance().localization.containsKey(locale)) {
|
||||||
|
BedwarsRel.getInstance().loadLocalization(locale);
|
||||||
|
}
|
||||||
|
return (String) BedwarsRel.getInstance().getLocalization().get(locale).get(key);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static BedwarsRel getInstance() {
|
||||||
|
return BedwarsRel.instance;
|
||||||
|
}
|
||||||
|
|
||||||
|
public boolean allPlayersBackToMainLobby() {
|
||||||
|
if (this.getConfig().contains("endgame.all-players-to-mainlobby")
|
||||||
|
&& this.getConfig().isBoolean("endgame.all-players-to-mainlobby")) {
|
||||||
|
return this.getConfig().getBoolean("endgame.all-players-to-mainlobby");
|
||||||
|
}
|
||||||
|
|
||||||
|
return false;
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
private void checkUpdates() {
|
||||||
|
try {
|
||||||
|
if (this.getBooleanConfig("check-updates", true)) {
|
||||||
|
this.updateChecker = new BukkitRunnable() {
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void run() {
|
||||||
|
final BukkitRunnable task = this;
|
||||||
|
UpdateCallback callback = new UpdateCallback() {
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onFinish(PluginUpdater updater) {
|
||||||
|
if (updater.getResult() == UpdateResult.SUCCESS) {
|
||||||
|
task.cancel();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
new PluginUpdater(
|
||||||
|
BedwarsRel.getInstance(), BedwarsRel.PROJECT_ID, BedwarsRel.getInstance().getFile(),
|
||||||
|
PluginUpdater.UpdateType.DEFAULT, callback,
|
||||||
|
BedwarsRel.getInstance().getBooleanConfig("update-infos", true));
|
||||||
|
}
|
||||||
|
|
||||||
|
}.runTaskTimerAsynchronously(BedwarsRel.getInstance(), 40L, 36000L);
|
||||||
|
}
|
||||||
|
} catch (Exception ex) {
|
||||||
|
BedwarsRel.getInstance().getBugsnag().notify(ex);
|
||||||
|
this.getServer().getConsoleSender().sendMessage(
|
||||||
|
ChatWriter.pluginMessage(ChatColor.RED + "Check for updates not successful: Error!"));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
private void disableBugsnag() {
|
||||||
|
this.bugsnag.addCallback(new Callback() {
|
||||||
|
@Override
|
||||||
|
public void beforeNotify(Report report) {
|
||||||
|
report.cancel();
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
public void dispatchRewardCommands(List<String> commands, Map<String, String> replacements) {
|
||||||
|
for (String command : commands) {
|
||||||
|
command = command.trim();
|
||||||
|
if ("".equals(command)) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
if ("none".equalsIgnoreCase(command)) {
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (command.startsWith("/")) {
|
||||||
|
command = command.substring(1);
|
||||||
|
}
|
||||||
|
|
||||||
|
for (Entry<String, String> entry : replacements.entrySet()) {
|
||||||
|
command = command.replace(entry.getKey(), entry.getValue());
|
||||||
|
}
|
||||||
|
|
||||||
|
BedwarsRel.getInstance().getServer()
|
||||||
|
.dispatchCommand(BedwarsRel.getInstance().getServer().getConsoleSender(), command);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private void enableBugsnag() {
|
||||||
|
this.bugsnag.addCallback(new Callback() {
|
||||||
|
@Override
|
||||||
|
public void beforeNotify(Report report) {
|
||||||
|
Boolean shouldBeSent = false;
|
||||||
|
for (StackTraceElement stackTraceElement : report.getException().getStackTrace()) {
|
||||||
|
if (stackTraceElement.toString().contains("io.github.bedwarsrel.BedwarsRel")) {
|
||||||
|
shouldBeSent = true;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (!shouldBeSent) {
|
||||||
|
report.cancel();
|
||||||
|
}
|
||||||
|
|
||||||
|
report.setUserId(SupportData.getIdentifier());
|
||||||
|
if (!SupportData.getPluginVersionBuild().equalsIgnoreCase("unknown")) {
|
||||||
|
report.addToTab("Server", "Version Build",
|
||||||
|
BedwarsRel.getInstance().getDescription().getVersion() + " "
|
||||||
|
+ SupportData.getPluginVersionBuild());
|
||||||
|
}
|
||||||
|
report.addToTab("Server", "Version", SupportData.getServerVersion());
|
||||||
|
report.addToTab("Server", "Version Bukkit", SupportData.getBukkitVersion());
|
||||||
|
report.addToTab("Server", "Server Mode", SupportData.getServerMode());
|
||||||
|
report.addToTab("Server", "Plugins", SupportData.getPlugins());
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
private ArrayList<BaseCommand> filterCommandsByPermission(ArrayList<BaseCommand> commands,
|
||||||
|
String permission) {
|
||||||
|
Iterator<BaseCommand> it = commands.iterator();
|
||||||
|
|
||||||
|
while (it.hasNext()) {
|
||||||
|
BaseCommand command = it.next();
|
||||||
|
if (!command.getPermission().equals(permission)) {
|
||||||
|
it.remove();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return commands;
|
||||||
|
}
|
||||||
|
|
||||||
|
public List<String> getAllowedCommands() {
|
||||||
|
FileConfiguration config = this.getConfig();
|
||||||
|
if (config.contains("allowed-commands") && config.isList("allowed-commands")) {
|
||||||
|
return config.getStringList("allowed-commands");
|
||||||
|
}
|
||||||
|
|
||||||
|
return new ArrayList<String>();
|
||||||
|
}
|
||||||
|
|
||||||
|
@SuppressWarnings("unchecked")
|
||||||
|
public ArrayList<BaseCommand> getBaseCommands() {
|
||||||
|
ArrayList<BaseCommand> commands = (ArrayList<BaseCommand>) this.commands.clone();
|
||||||
|
commands = this.filterCommandsByPermission(commands, "base");
|
||||||
|
|
||||||
|
return commands;
|
||||||
|
}
|
||||||
|
|
||||||
|
public boolean getBooleanConfig(String key, boolean defaultBool) {
|
||||||
|
FileConfiguration config = this.getConfig();
|
||||||
|
if (config.contains(key) && config.isBoolean(key)) {
|
||||||
|
return config.getBoolean(key);
|
||||||
|
}
|
||||||
|
return defaultBool;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getBungeeHub() {
|
||||||
|
if (this.getConfig().contains("bungeecord.hubserver")) {
|
||||||
|
return this.getConfig().getString("bungeecord.hubserver");
|
||||||
|
}
|
||||||
|
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
public ArrayList<BaseCommand> getCommands() {
|
||||||
|
return this.commands;
|
||||||
|
}
|
||||||
|
|
||||||
|
@SuppressWarnings("unchecked")
|
||||||
|
public ArrayList<BaseCommand> getCommandsByPermission(String permission) {
|
||||||
|
ArrayList<BaseCommand> commands = (ArrayList<BaseCommand>) this.commands.clone();
|
||||||
|
commands = this.filterCommandsByPermission(commands, permission);
|
||||||
|
|
||||||
|
return commands;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Package getCraftBukkit() {
|
||||||
|
try {
|
||||||
|
if (this.craftbukkit == null) {
|
||||||
|
return Package.getPackage("org.bukkit.craftbukkit."
|
||||||
|
+ Bukkit.getServer().getClass().getPackage().getName().replace(".", ",").split(",")[3]);
|
||||||
|
} else {
|
||||||
|
return this.craftbukkit;
|
||||||
|
}
|
||||||
|
} catch (Exception ex) {
|
||||||
|
BedwarsRel.getInstance().getBugsnag().notify(ex);
|
||||||
|
this.getServer().getConsoleSender().sendMessage(ChatWriter.pluginMessage(ChatColor.RED
|
||||||
|
+ BedwarsRel._l(this.getServer().getConsoleSender(), "errors.packagenotfound",
|
||||||
|
ImmutableMap.of("package", "craftbukkit"))));
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@SuppressWarnings("rawtypes")
|
||||||
|
public Class getCraftBukkitClass(String classname) {
|
||||||
|
try {
|
||||||
|
if (this.craftbukkit == null) {
|
||||||
|
this.craftbukkit = this.getCraftBukkit();
|
||||||
|
}
|
||||||
|
|
||||||
|
return Class.forName(this.craftbukkit.getName() + "." + classname);
|
||||||
|
} catch (Exception ex) {
|
||||||
|
BedwarsRel.getInstance().getBugsnag().notify(ex);
|
||||||
|
this.getServer().getConsoleSender()
|
||||||
|
.sendMessage(ChatWriter.pluginMessage(
|
||||||
|
ChatColor.RED + BedwarsRel
|
||||||
|
._l(this.getServer().getConsoleSender(), "errors.classnotfound",
|
||||||
|
ImmutableMap.of("package", "craftbukkit", "class", classname))));
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getCurrentVersion() {
|
||||||
|
return this.version;
|
||||||
|
}
|
||||||
|
|
||||||
|
public DatabaseManager getDatabaseManager() {
|
||||||
|
return this.dbManager;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getFallbackLocale() {
|
||||||
|
return "en_US";
|
||||||
|
}
|
||||||
|
|
||||||
|
public int getIntConfig(String key, int defaultInt) {
|
||||||
|
FileConfiguration config = this.getConfig();
|
||||||
|
if (config.contains(key) && config.isInt(key)) {
|
||||||
|
return config.getInt(key);
|
||||||
|
}
|
||||||
|
return defaultInt;
|
||||||
|
}
|
||||||
|
|
||||||
|
private boolean getIsSpigot() {
|
||||||
|
try {
|
||||||
|
Package spigotPackage = Package.getPackage("org.spigotmc");
|
||||||
|
return (spigotPackage != null);
|
||||||
|
} catch (Exception e) {
|
||||||
|
BedwarsRel.getInstance().getBugsnag().notify(e);
|
||||||
|
}
|
||||||
|
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns the max length of a game in seconds
|
||||||
|
*
|
||||||
|
* @return The length of the game in seconds
|
||||||
|
*/
|
||||||
|
public int getMaxLength() {
|
||||||
|
if (this.getConfig().contains("gamelength") && this.getConfig().isInt("gamelength")) {
|
||||||
|
return this.getConfig().getInt("gamelength") * 60;
|
||||||
|
}
|
||||||
|
|
||||||
|
// fallback time is 60 minutes
|
||||||
|
return 60 * 60;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Package getMinecraftPackage() {
|
||||||
|
try {
|
||||||
|
if (this.minecraft == null) {
|
||||||
|
return Package.getPackage("net.minecraft.server."
|
||||||
|
+ Bukkit.getServer().getClass().getPackage().getName().replace(".", ",").split(",")[3]);
|
||||||
|
} else {
|
||||||
|
return this.minecraft;
|
||||||
|
}
|
||||||
|
} catch (Exception ex) {
|
||||||
|
BedwarsRel.getInstance().getBugsnag().notify(ex);
|
||||||
|
this.getServer().getConsoleSender().sendMessage(ChatWriter.pluginMessage(ChatColor.RED
|
||||||
|
+ BedwarsRel._l(this.getServer().getConsoleSender(), "errors.packagenotfound",
|
||||||
|
ImmutableMap.of("package", "minecraft server"))));
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@SuppressWarnings("rawtypes")
|
||||||
|
public Class getMinecraftServerClass(String classname) {
|
||||||
|
try {
|
||||||
|
if (this.minecraft == null) {
|
||||||
|
this.minecraft = this.getMinecraftPackage();
|
||||||
|
}
|
||||||
|
|
||||||
|
return Class.forName(this.minecraft.getName() + "." + classname);
|
||||||
|
} catch (Exception ex) {
|
||||||
|
BedwarsRel.getInstance().getBugsnag().notify(ex);
|
||||||
|
this.getServer().getConsoleSender()
|
||||||
|
.sendMessage(ChatWriter.pluginMessage(
|
||||||
|
ChatColor.RED + BedwarsRel
|
||||||
|
._l(this.getServer().getConsoleSender(), "errors.classnotfound",
|
||||||
|
ImmutableMap.of("package", "minecraft server", "class", classname))));
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getMissingHoloDependency() {
|
||||||
|
// 全息功能已禁用
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
public PlayerStatisticManager getPlayerStatisticManager() {
|
||||||
|
return this.playerStatisticManager;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Integer getRespawnProtectionTime() {
|
||||||
|
FileConfiguration config = this.getConfig();
|
||||||
|
if (config.contains("respawn-protection") && config.isInt("respawn-protection")) {
|
||||||
|
return config.getInt("respawn-protection");
|
||||||
|
}
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
public ScoreboardManager getScoreboardManager() {
|
||||||
|
return this.scoreboardManager;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getSenderLocale(CommandSender commandSender) {
|
||||||
|
String locale = BedwarsRel.getInstance().getConfig().getString("locale");
|
||||||
|
if (commandSender instanceof Player) {
|
||||||
|
Player player = (Player) commandSender;
|
||||||
|
if (BedwarsRel.getInstance().getPlayerLocales().containsKey(player.getUniqueId())) {
|
||||||
|
locale = BedwarsRel.getInstance().getPlayerLocales().get(player.getUniqueId());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return locale;
|
||||||
|
}
|
||||||
|
|
||||||
|
@SuppressWarnings("unchecked")
|
||||||
|
public ArrayList<BaseCommand> getSetupCommands() {
|
||||||
|
ArrayList<BaseCommand> commands = (ArrayList<BaseCommand>) this.commands.clone();
|
||||||
|
commands = this.filterCommandsByPermission(commands, "setup");
|
||||||
|
|
||||||
|
return commands;
|
||||||
|
}
|
||||||
|
|
||||||
|
public FileConfiguration getShopConfig() {
|
||||||
|
return this.shopConfig;
|
||||||
|
}
|
||||||
|
|
||||||
|
public StorageType getStatisticStorageType() {
|
||||||
|
String storage = this.getStringConfig("statistics.storage", "yaml");
|
||||||
|
return StorageType.getByName(storage);
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getStringConfig(String key, String defaultString) {
|
||||||
|
FileConfiguration config = this.getConfig();
|
||||||
|
if (config.contains(key) && config.isString(key)) {
|
||||||
|
return config.getString(key);
|
||||||
|
}
|
||||||
|
return defaultString;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Class<?> getVersionRelatedClass(String className) {
|
||||||
|
try {
|
||||||
|
Class<?> clazz = Class.forName(
|
||||||
|
"io.github.bedwarsrel.com." + this.getCurrentVersion().toLowerCase() + "." + className);
|
||||||
|
return clazz;
|
||||||
|
} catch (Exception ex) {
|
||||||
|
BedwarsRel.getInstance().getBugsnag().notify(ex);
|
||||||
|
this.getServer().getConsoleSender()
|
||||||
|
.sendMessage(ChatWriter.pluginMessage(ChatColor.RED
|
||||||
|
+ "Couldn't find version related class io.github.bedwarsrel.com."
|
||||||
|
+ this.getCurrentVersion() + "." + className));
|
||||||
|
}
|
||||||
|
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getYamlDump(YamlConfiguration config) {
|
||||||
|
try {
|
||||||
|
String fullstring = config.saveToString();
|
||||||
|
String endstring = fullstring;
|
||||||
|
endstring = Utils.unescape_perl_string(fullstring);
|
||||||
|
|
||||||
|
return endstring;
|
||||||
|
} catch (Exception ex) {
|
||||||
|
BedwarsRel.getInstance().getBugsnag().notify(ex);
|
||||||
|
ex.printStackTrace();
|
||||||
|
}
|
||||||
|
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
public boolean isBreakableType(Material type) {
|
||||||
|
return ((BedwarsRel.getInstance().getConfig().getBoolean("breakable-blocks.use-as-blacklist")
|
||||||
|
&& !this.breakableTypes.contains(type))
|
||||||
|
|| (!BedwarsRel.getInstance().getConfig().getBoolean("breakable-blocks.use-as-blacklist")
|
||||||
|
&& this.breakableTypes.contains(type)));
|
||||||
|
}
|
||||||
|
|
||||||
|
public boolean isBungee() {
|
||||||
|
return this.getConfig().getBoolean("bungeecord.enabled");
|
||||||
|
}
|
||||||
|
|
||||||
|
public boolean isHologramsEnabled() {
|
||||||
|
// 全息功能已禁用
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
public boolean isLocationSerializable() {
|
||||||
|
if (BedwarsRel.locationSerializable == null) {
|
||||||
|
try {
|
||||||
|
Location.class.getMethod("serialize");
|
||||||
|
BedwarsRel.locationSerializable = true;
|
||||||
|
} catch (Exception ex) {
|
||||||
|
BedwarsRel.getInstance().getBugsnag().notify(ex);
|
||||||
|
BedwarsRel.locationSerializable = false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return BedwarsRel.locationSerializable;
|
||||||
|
}
|
||||||
|
|
||||||
|
public boolean isMineshafterPresent() {
|
||||||
|
try {
|
||||||
|
Class.forName("mineshafter.MineServer");
|
||||||
|
return true;
|
||||||
|
} catch (Exception e) {
|
||||||
|
// NO ERROR
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public boolean isSpigot() {
|
||||||
|
return this.isSpigot;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void loadConfigInUTF() {
|
||||||
|
File configFile = new File(this.getDataFolder(), "config.yml");
|
||||||
|
if (!configFile.exists()) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
try {
|
||||||
|
BufferedReader reader =
|
||||||
|
new BufferedReader(new InputStreamReader(new FileInputStream(configFile), "UTF-8"));
|
||||||
|
this.getConfig().load(reader);
|
||||||
|
} catch (Exception e) {
|
||||||
|
BedwarsRel.getInstance().getBugsnag().notify(e);
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
|
|
||||||
|
if (this.getConfig() == null) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
// load breakable materials
|
||||||
|
this.breakableTypes = new ArrayList<Material>();
|
||||||
|
for (String material : this.getConfig().getStringList("breakable-blocks.list")) {
|
||||||
|
if (material.equalsIgnoreCase("none")) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
Material mat = Utils.parseMaterial(material);
|
||||||
|
if (mat == null) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (this.breakableTypes.contains(mat)) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
this.breakableTypes.add(mat);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private void loadDatabase() {
|
||||||
|
if (!this.getBooleanConfig("statistics.enabled", false)
|
||||||
|
|| !"database".equals(this.getStringConfig("statistics.storage", "yaml"))) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
this.getServer().getConsoleSender()
|
||||||
|
.sendMessage(ChatWriter.pluginMessage(ChatColor.GREEN + "Initialize database ..."));
|
||||||
|
|
||||||
|
String host = this.getStringConfig("database.host", null);
|
||||||
|
int port = this.getIntConfig("database.port", 3306);
|
||||||
|
String user = this.getStringConfig("database.user", null);
|
||||||
|
String password = this.getStringConfig("database.password", null);
|
||||||
|
String db = this.getStringConfig("database.db", null);
|
||||||
|
String tablePrefix = this.getStringConfig("database.table-prefix", "bw_");
|
||||||
|
|
||||||
|
if (host == null || user == null || password == null || db == null) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
this.dbManager = new DatabaseManager(host, port, user, password, db, tablePrefix);
|
||||||
|
this.dbManager.initialize();
|
||||||
|
|
||||||
|
this.getServer().getConsoleSender()
|
||||||
|
.sendMessage(ChatWriter.pluginMessage(ChatColor.GREEN + "Update database ..."));
|
||||||
|
|
||||||
|
this.getServer().getConsoleSender()
|
||||||
|
.sendMessage(ChatWriter.pluginMessage(ChatColor.GREEN + "Done."));
|
||||||
|
}
|
||||||
|
|
||||||
|
private void loadLocalization(String locale) {
|
||||||
|
if (!this.localization.containsKey(locale)) {
|
||||||
|
this.localization.put(locale, new LocalizationConfig(locale));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public void loadShop() {
|
||||||
|
File file = new File(BedwarsRel.getInstance().getDataFolder(), "shop.yml");
|
||||||
|
if (!file.exists()) {
|
||||||
|
// create default file
|
||||||
|
this.saveResource("shop.yml", false);
|
||||||
|
|
||||||
|
// wait until it's really saved
|
||||||
|
try {
|
||||||
|
Thread.sleep(100);
|
||||||
|
} catch (InterruptedException e) {
|
||||||
|
BedwarsRel.getInstance().getBugsnag().notify(e);
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
this.shopConfig = new YamlConfiguration();
|
||||||
|
|
||||||
|
try {
|
||||||
|
BufferedReader reader =
|
||||||
|
new BufferedReader(new InputStreamReader(new FileInputStream(file), "UTF-8"));
|
||||||
|
this.shopConfig.load(reader);
|
||||||
|
} catch (Exception e) {
|
||||||
|
BedwarsRel.getInstance().getBugsnag().notify(e);
|
||||||
|
this.getServer().getConsoleSender().sendMessage(
|
||||||
|
ChatWriter.pluginMessage(ChatColor.RED + "Couldn't load shop! Error in parsing shop!"));
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private void loadStatistics() {
|
||||||
|
this.playerStatisticManager = new PlayerStatisticManager();
|
||||||
|
this.playerStatisticManager.initialize();
|
||||||
|
}
|
||||||
|
|
||||||
|
private String loadVersion() {
|
||||||
|
String packName = Bukkit.getServer().getClass().getPackage().getName();
|
||||||
|
return packName.substring(packName.lastIndexOf('.') + 1);
|
||||||
|
}
|
||||||
|
|
||||||
|
public boolean metricsEnabled() {
|
||||||
|
if (this.getConfig().contains("plugin-metrics")
|
||||||
|
&& this.getConfig().isBoolean("plugin-metrics")) {
|
||||||
|
return this.getConfig().getBoolean("plugin-metrics");
|
||||||
|
}
|
||||||
|
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onDisable() {
|
||||||
|
this.stopTimeListener();
|
||||||
|
this.gameManager.unloadGames();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onEnable() {
|
||||||
|
BedwarsRel.instance = this;
|
||||||
|
|
||||||
|
if (this.getDescription().getVersion().contains("-SNAPSHOT")
|
||||||
|
&& System.getProperty("IReallyKnowWhatIAmDoingISwear") == null) {
|
||||||
|
this.getServer().getConsoleSender().sendMessage(ChatWriter.pluginMessage(ChatColor.RED + "*** Warning, you are using a development build ***"));
|
||||||
|
this.getServer().getConsoleSender().sendMessage(ChatWriter.pluginMessage(ChatColor.RED + "*** You will get NO support regarding this build ***"));
|
||||||
|
this.getServer().getConsoleSender().sendMessage(ChatWriter.pluginMessage(ChatColor.RED + "*** Please download a stable build from https://github.com/BedwarsRel/BedwarsRel/releases ***"));
|
||||||
|
this.getServer().getConsoleSender().sendMessage(ChatWriter.pluginMessage(ChatColor.RED + "*** Server will start in 10 seconds ***"));
|
||||||
|
try {
|
||||||
|
Thread.sleep(TimeUnit.SECONDS.toMillis(10));
|
||||||
|
} catch (InterruptedException e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
this.registerBugsnag();
|
||||||
|
|
||||||
|
// register classes
|
||||||
|
this.registerConfigurationClasses();
|
||||||
|
|
||||||
|
// save default config
|
||||||
|
this.saveDefaultConfig();
|
||||||
|
this.loadConfigInUTF();
|
||||||
|
|
||||||
|
this.getConfig().options().copyDefaults(true);
|
||||||
|
this.getConfig().options().copyHeader(true);
|
||||||
|
|
||||||
|
this.craftbukkit = this.getCraftBukkit();
|
||||||
|
this.minecraft = this.getMinecraftPackage();
|
||||||
|
this.version = this.loadVersion();
|
||||||
|
|
||||||
|
ConfigUpdater configUpdater = new ConfigUpdater();
|
||||||
|
configUpdater.addConfigs();
|
||||||
|
this.saveConfiguration();
|
||||||
|
this.loadConfigInUTF();
|
||||||
|
|
||||||
|
if (this.getBooleanConfig("send-error-data", true) && this.bugsnag != null) {
|
||||||
|
this.enableBugsnag();
|
||||||
|
} else {
|
||||||
|
this.disableBugsnag();
|
||||||
|
}
|
||||||
|
|
||||||
|
this.loadShop();
|
||||||
|
|
||||||
|
this.isSpigot = this.getIsSpigot();
|
||||||
|
this.loadDatabase();
|
||||||
|
|
||||||
|
this.registerCommands();
|
||||||
|
this.registerListener();
|
||||||
|
|
||||||
|
this.gameManager = new GameManager();
|
||||||
|
|
||||||
|
// bungeecord
|
||||||
|
if (BedwarsRel.getInstance().isBungee()) {
|
||||||
|
this.getServer().getMessenger().registerOutgoingPluginChannel(this, "BungeeCord");
|
||||||
|
}
|
||||||
|
|
||||||
|
this.loadStatistics();
|
||||||
|
this.loadLocalization(this.getConfig().getString("locale"));
|
||||||
|
|
||||||
|
this.checkUpdates();
|
||||||
|
|
||||||
|
// Loading
|
||||||
|
this.scoreboardManager = Bukkit.getScoreboardManager();
|
||||||
|
this.gameManager.loadGames();
|
||||||
|
this.startTimeListener();
|
||||||
|
this.startMetricsIfEnabled();
|
||||||
|
}
|
||||||
|
|
||||||
|
private void registerBugsnag() {
|
||||||
|
try {
|
||||||
|
this.bugsnag = new Bugsnag("c23593c1e2f40fc0da36564af1bd00c6");
|
||||||
|
this.bugsnag.setAppVersion(SupportData.getPluginVersion());
|
||||||
|
this.bugsnag.setProjectPackages("io.github.bedwarsrel");
|
||||||
|
this.bugsnag.setReleaseStage(SupportData.getPluginVersionType());
|
||||||
|
} catch (Exception e) {
|
||||||
|
this.getServer().getConsoleSender().sendMessage(
|
||||||
|
ChatWriter.pluginMessage(ChatColor.GOLD + "Couldn't register Bugsnag."));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private void registerCommands() {
|
||||||
|
BedwarsCommandExecutor executor = new BedwarsCommandExecutor(this);
|
||||||
|
|
||||||
|
this.commands.add(new HelpCommand(this));
|
||||||
|
this.commands.add(new SetSpawnerCommand(this));
|
||||||
|
this.commands.add(new AddGameCommand(this));
|
||||||
|
this.commands.add(new StartGameCommand(this));
|
||||||
|
this.commands.add(new StopGameCommand(this));
|
||||||
|
this.commands.add(new SetRegionCommand(this));
|
||||||
|
this.commands.add(new AddTeamCommand(this));
|
||||||
|
this.commands.add(new SaveGameCommand(this));
|
||||||
|
this.commands.add(new JoinGameCommand(this));
|
||||||
|
this.commands.add(new SetSpawnCommand(this));
|
||||||
|
this.commands.add(new SetLobbyCommand(this));
|
||||||
|
this.commands.add(new LeaveGameCommand(this));
|
||||||
|
this.commands.add(new SetTargetCommand(this));
|
||||||
|
this.commands.add(new SetBedCommand(this));
|
||||||
|
this.commands.add(new ReloadCommand(this));
|
||||||
|
this.commands.add(new SetMainLobbyCommand(this));
|
||||||
|
this.commands.add(new ListGamesCommand(this));
|
||||||
|
this.commands.add(new RegionNameCommand(this));
|
||||||
|
this.commands.add(new RemoveTeamCommand(this));
|
||||||
|
this.commands.add(new RemoveGameCommand(this));
|
||||||
|
this.commands.add(new ClearSpawnerCommand(this));
|
||||||
|
this.commands.add(new GameTimeCommand(this));
|
||||||
|
this.commands.add(new StatsCommand(this));
|
||||||
|
this.commands.add(new SetMinPlayersCommand(this));
|
||||||
|
this.commands.add(new SetGameBlockCommand(this));
|
||||||
|
this.commands.add(new SetBuilderCommand(this));
|
||||||
|
this.commands.add(new SetAutobalanceCommand(this));
|
||||||
|
this.commands.add(new KickCommand(this));
|
||||||
|
this.commands.add(new AddTeamJoinCommand(this));
|
||||||
|
this.commands.add(new DebugPasteCommand(this));
|
||||||
|
this.commands.add(new ItemsPasteCommand(this));
|
||||||
|
this.commands.add(new AutoConnectCommand(this));
|
||||||
|
this.getCommand("bw").setExecutor(executor);
|
||||||
|
}
|
||||||
|
|
||||||
|
private void registerConfigurationClasses() {
|
||||||
|
ConfigurationSerialization.registerClass(ResourceSpawner.class, "RessourceSpawner");
|
||||||
|
ConfigurationSerialization.registerClass(Team.class, "Team");
|
||||||
|
ConfigurationSerialization.registerClass(PlayerStatistic.class, "PlayerStatistic");
|
||||||
|
}
|
||||||
|
|
||||||
|
private void registerListener() {
|
||||||
|
new WeatherListener();
|
||||||
|
new BlockListener();
|
||||||
|
new PlayerListener();
|
||||||
|
if (!BedwarsRel.getInstance().getCurrentVersion().startsWith("v1_8")) {
|
||||||
|
new Player19Listener();
|
||||||
|
}
|
||||||
|
new HangingListener();
|
||||||
|
new EntityListener();
|
||||||
|
new ServerListener();
|
||||||
|
new SignListener();
|
||||||
|
new ChunkListener();
|
||||||
|
|
||||||
|
if (this.isSpigot()) {
|
||||||
|
new PlayerSpigotListener();
|
||||||
|
}
|
||||||
|
|
||||||
|
SpecialItem.loadSpecials();
|
||||||
|
}
|
||||||
|
|
||||||
|
public void reloadLocalization() {
|
||||||
|
this.localization = new HashMap<>();
|
||||||
|
this.loadLocalization(this.getConfig().getString("locale"));
|
||||||
|
}
|
||||||
|
|
||||||
|
public void saveConfiguration() {
|
||||||
|
File file = new File(BedwarsRel.getInstance().getDataFolder(), "config.yml");
|
||||||
|
try {
|
||||||
|
file.mkdirs();
|
||||||
|
|
||||||
|
String data = this.getYamlDump((YamlConfiguration) this.getConfig());
|
||||||
|
|
||||||
|
FileOutputStream stream = new FileOutputStream(file);
|
||||||
|
OutputStreamWriter writer = new OutputStreamWriter(stream, "UTF-8");
|
||||||
|
|
||||||
|
try {
|
||||||
|
writer.write(data);
|
||||||
|
} finally {
|
||||||
|
writer.close();
|
||||||
|
stream.close();
|
||||||
|
}
|
||||||
|
} catch (Exception ex) {
|
||||||
|
BedwarsRel.getInstance().getBugsnag().notify(ex);
|
||||||
|
ex.printStackTrace();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public boolean spectationEnabled() {
|
||||||
|
if (this.getConfig().contains("spectation-enabled")
|
||||||
|
&& this.getConfig().isBoolean("spectation-enabled")) {
|
||||||
|
return this.getConfig().getBoolean("spectation-enabled");
|
||||||
|
}
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void startMetricsIfEnabled() {
|
||||||
|
if (this.metricsEnabled()) {
|
||||||
|
new BStatsMetrics(this);
|
||||||
|
try {
|
||||||
|
McStatsMetrics mcStatsMetrics = new McStatsMetrics(this);
|
||||||
|
mcStatsMetrics.start();
|
||||||
|
} catch (Exception ex) {
|
||||||
|
BedwarsRel.getInstance().getBugsnag().notify(ex);
|
||||||
|
this.getServer().getConsoleSender().sendMessage(ChatWriter
|
||||||
|
.pluginMessage(ChatColor.RED + "Metrics are enabled, but couldn't send data!"));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private void startTimeListener() {
|
||||||
|
this.timeTask = this.getServer().getScheduler().runTaskTimer(this, new Runnable() {
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void run() {
|
||||||
|
for (Game g : BedwarsRel.getInstance().getGameManager().getGames()) {
|
||||||
|
if (g.getState() == GameState.RUNNING) {
|
||||||
|
g.getRegion().getWorld().setTime(g.getTime());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}, (long) 5 * 20, (long) 5 * 20);
|
||||||
|
}
|
||||||
|
|
||||||
|
public boolean statisticsEnabled() {
|
||||||
|
return this.getBooleanConfig("statistics.enabled", false);
|
||||||
|
}
|
||||||
|
|
||||||
|
private void stopTimeListener() {
|
||||||
|
try {
|
||||||
|
this.timeTask.cancel();
|
||||||
|
} catch (Exception ex) {
|
||||||
|
// Timer isn't running. Just ignore.
|
||||||
|
}
|
||||||
|
|
||||||
|
try {
|
||||||
|
this.updateChecker.cancel();
|
||||||
|
} catch (Exception ex) {
|
||||||
|
// Timer isn't running. Just ignore.
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public boolean toMainLobby() {
|
||||||
|
if (this.getConfig().contains("endgame.mainlobby-enabled")) {
|
||||||
|
return this.getConfig().getBoolean("endgame.mainlobby-enabled");
|
||||||
|
}
|
||||||
|
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
@@ -0,0 +1,99 @@
|
|||||||
|
package io.github.bedwarsrel.com.fallback;
|
||||||
|
|
||||||
|
import io.github.bedwarsrel.BedwarsRel;
|
||||||
|
import io.github.bedwarsrel.utils.ChatWriter;
|
||||||
|
import io.github.bedwarsrel.utils.Utils;
|
||||||
|
import java.lang.reflect.Constructor;
|
||||||
|
import java.lang.reflect.Field;
|
||||||
|
import java.lang.reflect.Method;
|
||||||
|
import java.util.Arrays;
|
||||||
|
import java.util.List;
|
||||||
|
import org.bukkit.ChatColor;
|
||||||
|
import org.bukkit.entity.Player;
|
||||||
|
import org.bukkit.scheduler.BukkitRunnable;
|
||||||
|
|
||||||
|
public class PerformRespawnRunnable extends BukkitRunnable {
|
||||||
|
|
||||||
|
private Player player = null;
|
||||||
|
|
||||||
|
public PerformRespawnRunnable(Player player) {
|
||||||
|
this.player = player;
|
||||||
|
}
|
||||||
|
|
||||||
|
private Object getPacketObject(String packetName, Class<?>[] constructorClasses,
|
||||||
|
Object[] constructorParams) {
|
||||||
|
try {
|
||||||
|
Class<?> clazz = BedwarsRel.getInstance().getMinecraftServerClass(packetName);
|
||||||
|
if (clazz == null) {
|
||||||
|
// TODO
|
||||||
|
}
|
||||||
|
|
||||||
|
Constructor<?> constr = clazz.getDeclaredConstructor(constructorClasses);
|
||||||
|
if (constr == null) {
|
||||||
|
// TODO
|
||||||
|
}
|
||||||
|
|
||||||
|
constr.setAccessible(true);
|
||||||
|
return constr.newInstance(constructorParams);
|
||||||
|
} catch (Exception ex) {
|
||||||
|
BedwarsRel.getInstance().getBugsnag().notify(ex);
|
||||||
|
BedwarsRel.getInstance().getServer().getConsoleSender().sendMessage(ChatWriter.pluginMessage(
|
||||||
|
ChatColor.RED + "Couldn't catch packet class " + ChatColor.YELLOW + packetName));
|
||||||
|
}
|
||||||
|
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void run() {
|
||||||
|
try {
|
||||||
|
Class<?> enumClientCommand = BedwarsRel.getInstance()
|
||||||
|
.getMinecraftServerClass("EnumClientCommand");
|
||||||
|
Class<?> packetClass =
|
||||||
|
BedwarsRel.getInstance().getMinecraftServerClass("PacketPlayInClientCommand");
|
||||||
|
if (enumClientCommand == null) {
|
||||||
|
for (Class<?> clazz : packetClass.getDeclaredClasses()) {
|
||||||
|
if (clazz.getSimpleName().equals("EnumClientCommand")) {
|
||||||
|
enumClientCommand = clazz;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@SuppressWarnings("unchecked")
|
||||||
|
List<Object> constants = (List<Object>) Arrays.asList(enumClientCommand.getEnumConstants());
|
||||||
|
Object respawnObject = null;
|
||||||
|
|
||||||
|
for (Object constant : constants) {
|
||||||
|
if (constant.toString().equals("PERFORM_RESPAWN")) {
|
||||||
|
respawnObject = constant;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Create packet instance
|
||||||
|
Object packetPlayInClientCommand = this.getPacketObject("PacketPlayInClientCommand",
|
||||||
|
new Class[]{enumClientCommand}, new Object[]{respawnObject});
|
||||||
|
Object craftPlayer = Utils.getCraftPlayer(this.player);
|
||||||
|
Class<?> craftPlayerClass = BedwarsRel.getInstance()
|
||||||
|
.getCraftBukkitClass("entity.CraftPlayer");
|
||||||
|
Field playerConnectionField = craftPlayerClass.getField("playerConnection");
|
||||||
|
playerConnectionField.setAccessible(true);
|
||||||
|
|
||||||
|
// player connection method
|
||||||
|
Object playerConnection = playerConnectionField.get(craftPlayer);
|
||||||
|
Class<?> playerConnectionClass =
|
||||||
|
BedwarsRel.getInstance().getMinecraftServerClass("PlayerConnection");
|
||||||
|
Method aMethod = playerConnectionClass.getMethod("a", new Class[]{packetClass});
|
||||||
|
aMethod.setAccessible(true);
|
||||||
|
|
||||||
|
// invoke respawn
|
||||||
|
aMethod.invoke(playerConnection, new Object[]{packetPlayInClientCommand});
|
||||||
|
} catch (Exception ex) {
|
||||||
|
BedwarsRel.getInstance().getBugsnag().notify(ex);
|
||||||
|
BedwarsRel.getInstance().getServer().getConsoleSender().sendMessage(ChatWriter
|
||||||
|
.pluginMessage(ChatColor.RED + "Plugin not compatible with your server version!"));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
@@ -0,0 +1,77 @@
|
|||||||
|
package io.github.bedwarsrel.commands;
|
||||||
|
|
||||||
|
import com.google.common.collect.ImmutableMap;
|
||||||
|
import io.github.bedwarsrel.BedwarsRel;
|
||||||
|
import io.github.bedwarsrel.game.Game;
|
||||||
|
import io.github.bedwarsrel.utils.ChatWriter;
|
||||||
|
import io.github.bedwarsrel.utils.Utils;
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import org.bukkit.ChatColor;
|
||||||
|
import org.bukkit.command.CommandSender;
|
||||||
|
|
||||||
|
public class AddGameCommand extends BaseCommand {
|
||||||
|
|
||||||
|
public AddGameCommand(BedwarsRel plugin) {
|
||||||
|
super(plugin);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean execute(CommandSender sender, ArrayList<String> args) {
|
||||||
|
if (!sender.hasPermission("bw." + this.getPermission())) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
Game addGame = this.getPlugin().getGameManager().addGame(args.get(0));
|
||||||
|
String minPlayers = args.get(1);
|
||||||
|
|
||||||
|
if (!Utils.isNumber(minPlayers)) {
|
||||||
|
sender.sendMessage(
|
||||||
|
ChatWriter.pluginMessage(ChatColor.RED + BedwarsRel
|
||||||
|
._l(sender, "errors.minplayersmustnumber")));
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (addGame == null) {
|
||||||
|
sender.sendMessage(
|
||||||
|
ChatWriter.pluginMessage(ChatColor.RED + BedwarsRel._l(sender, "errors.gameexists")));
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
int min = Integer.parseInt(minPlayers);
|
||||||
|
if (min <= 0) {
|
||||||
|
min = 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
addGame.setMinPlayers(min);
|
||||||
|
sender.sendMessage(ChatWriter.pluginMessage(ChatColor.GREEN
|
||||||
|
+ BedwarsRel
|
||||||
|
._l(sender, "success.gameadded", ImmutableMap.of("game", args.get(0).toString()))));
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String[] getArguments() {
|
||||||
|
return new String[]{"name", "minplayers"};
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String getCommand() {
|
||||||
|
return "addgame";
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String getDescription() {
|
||||||
|
return BedwarsRel._l("commands.addgame.desc");
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String getName() {
|
||||||
|
return BedwarsRel._l("commands.addgame.name");
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String getPermission() {
|
||||||
|
return "setup";
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
@@ -0,0 +1,108 @@
|
|||||||
|
package io.github.bedwarsrel.commands;
|
||||||
|
|
||||||
|
import com.google.common.collect.ImmutableMap;
|
||||||
|
import io.github.bedwarsrel.BedwarsRel;
|
||||||
|
import io.github.bedwarsrel.game.Game;
|
||||||
|
import io.github.bedwarsrel.game.GameState;
|
||||||
|
import io.github.bedwarsrel.game.TeamColor;
|
||||||
|
import io.github.bedwarsrel.utils.ChatWriter;
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import org.bukkit.ChatColor;
|
||||||
|
import org.bukkit.command.CommandSender;
|
||||||
|
|
||||||
|
public class AddTeamCommand extends BaseCommand {
|
||||||
|
|
||||||
|
public AddTeamCommand(BedwarsRel plugin) {
|
||||||
|
super(plugin);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean execute(CommandSender sender, ArrayList<String> args) {
|
||||||
|
if (!sender.hasPermission("bw." + this.getPermission())) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
Game game = this.getPlugin().getGameManager().getGame(args.get(0));
|
||||||
|
String name = args.get(1);
|
||||||
|
String color = args.get(2);
|
||||||
|
String maxPlayers = args.get(3);
|
||||||
|
TeamColor tColor = null;
|
||||||
|
|
||||||
|
try {
|
||||||
|
tColor = TeamColor.valueOf(color.toUpperCase());
|
||||||
|
} catch (Exception e) {
|
||||||
|
sender.sendMessage(
|
||||||
|
ChatWriter.pluginMessage(ChatColor.RED + BedwarsRel
|
||||||
|
._l(sender, "errors.teamcolornotallowed")));
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (game == null) {
|
||||||
|
sender.sendMessage(ChatWriter.pluginMessage(ChatColor.RED
|
||||||
|
+ BedwarsRel
|
||||||
|
._l(sender, "errors.gamenotfound", ImmutableMap.of("game", args.get(0).toString()))));
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (game.getState() != GameState.STOPPED) {
|
||||||
|
sender.sendMessage(
|
||||||
|
ChatWriter.pluginMessage(ChatColor.RED + BedwarsRel
|
||||||
|
._l(sender, "errors.notwhilegamerunning")));
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
int playerMax = Integer.parseInt(maxPlayers);
|
||||||
|
|
||||||
|
if (playerMax < 1 || playerMax > 24) {
|
||||||
|
sender.sendMessage(
|
||||||
|
ChatWriter.pluginMessage(ChatColor.RED + BedwarsRel._l(sender, "errors.playeramount")));
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (name.length() < 3 || name.length() > 20) {
|
||||||
|
sender
|
||||||
|
.sendMessage(
|
||||||
|
ChatWriter
|
||||||
|
.pluginMessage(ChatColor.RED + BedwarsRel._l(sender, "errors.teamnamelength")));
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (game.getTeam(name) != null) {
|
||||||
|
sender.sendMessage(
|
||||||
|
ChatWriter.pluginMessage(ChatColor.RED + BedwarsRel._l(sender, "errors.teamnameinuse")));
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
game.addTeam(name, tColor, playerMax);
|
||||||
|
sender.sendMessage(ChatWriter.pluginMessage(
|
||||||
|
ChatColor.GREEN + BedwarsRel
|
||||||
|
._l(sender, "success.teamadded", ImmutableMap.of("team", name))));
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String[] getArguments() {
|
||||||
|
return new String[]{"game", "name", "color", "maxplayers"};
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String getCommand() {
|
||||||
|
return "addteam";
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String getDescription() {
|
||||||
|
return BedwarsRel._l("commands.addteam.desc");
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String getName() {
|
||||||
|
return BedwarsRel._l("commands.addteam.name");
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String getPermission() {
|
||||||
|
return "setup";
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
@@ -0,0 +1,118 @@
|
|||||||
|
package io.github.bedwarsrel.commands;
|
||||||
|
|
||||||
|
import com.google.common.collect.ImmutableMap;
|
||||||
|
import io.github.bedwarsrel.BedwarsRel;
|
||||||
|
import io.github.bedwarsrel.game.Game;
|
||||||
|
import io.github.bedwarsrel.game.GameState;
|
||||||
|
import io.github.bedwarsrel.game.Team;
|
||||||
|
import io.github.bedwarsrel.game.TeamJoinMetaDataValue;
|
||||||
|
import io.github.bedwarsrel.utils.ChatWriter;
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import org.bukkit.ChatColor;
|
||||||
|
import org.bukkit.command.CommandSender;
|
||||||
|
import org.bukkit.entity.Player;
|
||||||
|
import org.bukkit.scheduler.BukkitRunnable;
|
||||||
|
|
||||||
|
public class AddTeamJoinCommand extends BaseCommand {
|
||||||
|
|
||||||
|
public AddTeamJoinCommand(BedwarsRel plugin) {
|
||||||
|
super(plugin);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean execute(CommandSender sender, ArrayList<String> args) {
|
||||||
|
if (!super.hasPermission(sender)) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
Player player = (Player) sender;
|
||||||
|
String team = args.get(1);
|
||||||
|
|
||||||
|
Game game = this.getPlugin().getGameManager().getGame(args.get(0));
|
||||||
|
if (game == null) {
|
||||||
|
player.sendMessage(ChatWriter.pluginMessage(ChatColor.RED
|
||||||
|
+ BedwarsRel
|
||||||
|
._l(sender, "errors.gamenotfound", ImmutableMap.of("game", args.get(0).toString()))));
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (game.getState() == GameState.RUNNING) {
|
||||||
|
sender.sendMessage(
|
||||||
|
ChatWriter.pluginMessage(ChatColor.RED + BedwarsRel
|
||||||
|
._l(sender, "errors.notwhilegamerunning")));
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
Team gameTeam = game.getTeam(team);
|
||||||
|
|
||||||
|
if (gameTeam == null) {
|
||||||
|
player.sendMessage(
|
||||||
|
ChatWriter.pluginMessage(ChatColor.RED + BedwarsRel._l(player, "errors.teamnotfound")));
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
// only in lobby
|
||||||
|
if (game.getLobby() == null || !player.getWorld().equals(game.getLobby().getWorld())) {
|
||||||
|
player.sendMessage(
|
||||||
|
ChatWriter
|
||||||
|
.pluginMessage(ChatColor.RED + BedwarsRel._l(player, "errors.mustbeinlobbyworld")));
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (player.hasMetadata("bw-addteamjoin")) {
|
||||||
|
player.removeMetadata("bw-addteamjoin", BedwarsRel.getInstance());
|
||||||
|
}
|
||||||
|
|
||||||
|
player.setMetadata("bw-addteamjoin", new TeamJoinMetaDataValue(gameTeam));
|
||||||
|
final Player runnablePlayer = player;
|
||||||
|
|
||||||
|
new BukkitRunnable() {
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void run() {
|
||||||
|
try {
|
||||||
|
if (!runnablePlayer.hasMetadata("bw-addteamjoin")) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
runnablePlayer.removeMetadata("bw-addteamjoin", BedwarsRel.getInstance());
|
||||||
|
} catch (Exception ex) {
|
||||||
|
BedwarsRel.getInstance().getBugsnag().notify(ex);
|
||||||
|
// just ignore
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}.runTaskLater(BedwarsRel.getInstance(), 20L * 10L);
|
||||||
|
|
||||||
|
player.sendMessage(
|
||||||
|
ChatWriter
|
||||||
|
.pluginMessage(
|
||||||
|
ChatColor.GREEN + BedwarsRel._l(player, "success.selectteamjoinentity")));
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String[] getArguments() {
|
||||||
|
return new String[]{"game", "team"};
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String getCommand() {
|
||||||
|
return "addteamjoin";
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String getDescription() {
|
||||||
|
return BedwarsRel._l("commands.addteamjoin.desc");
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String getName() {
|
||||||
|
return BedwarsRel._l("commands.addteamjoin.name");
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String getPermission() {
|
||||||
|
return "setup";
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
@@ -0,0 +1,102 @@
|
|||||||
|
package io.github.bedwarsrel.commands;
|
||||||
|
|
||||||
|
import com.google.common.collect.ImmutableMap;
|
||||||
|
import io.github.bedwarsrel.BedwarsRel;
|
||||||
|
import io.github.bedwarsrel.game.Game;
|
||||||
|
import io.github.bedwarsrel.game.GameCheckCode;
|
||||||
|
import io.github.bedwarsrel.game.GameManager;
|
||||||
|
import io.github.bedwarsrel.game.GameState;
|
||||||
|
import io.github.bedwarsrel.utils.ChatWriter;
|
||||||
|
import io.github.bedwarsrel.utils.Utils;
|
||||||
|
import org.bukkit.ChatColor;
|
||||||
|
import org.bukkit.command.CommandSender;
|
||||||
|
import org.bukkit.entity.Player;
|
||||||
|
import org.bukkit.util.ChatPaginator;
|
||||||
|
import com.google.common.collect.ImmutableMap;
|
||||||
|
import io.github.bedwarsrel.BedwarsRel;
|
||||||
|
import io.github.bedwarsrel.game.Game;
|
||||||
|
import io.github.bedwarsrel.game.GameCheckCode;
|
||||||
|
import io.github.bedwarsrel.game.GameState;
|
||||||
|
import io.github.bedwarsrel.utils.Utils;
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.List;
|
||||||
|
import org.bukkit.ChatColor;
|
||||||
|
import org.bukkit.command.CommandSender;
|
||||||
|
import org.bukkit.util.ChatPaginator;
|
||||||
|
import org.bukkit.util.ChatPaginator.ChatPage;
|
||||||
|
import java.util.ArrayList;
|
||||||
|
|
||||||
|
import static org.bukkit.Bukkit.getServer;
|
||||||
|
|
||||||
|
public class AutoConnectCommand extends BaseCommand {
|
||||||
|
|
||||||
|
private BedwarsRel plugin = null;
|
||||||
|
|
||||||
|
public AutoConnectCommand(BedwarsRel plugin) {
|
||||||
|
super(plugin);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean execute(CommandSender sender, ArrayList<String> args) {
|
||||||
|
|
||||||
|
|
||||||
|
ArrayList<Game> showedGames = new ArrayList<Game>();
|
||||||
|
List<Game> games = BedwarsRel.getInstance().getGameManager().getGames();
|
||||||
|
for (Game game : games) {
|
||||||
|
GameCheckCode code = game.checkGame();
|
||||||
|
if (code != GameCheckCode.OK && !sender.hasPermission("bw.setup")) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
showedGames.add(game);
|
||||||
|
int players = 0;
|
||||||
|
if (game.getState() == GameState.RUNNING) {
|
||||||
|
players = game.getCurrentPlayerAmount();
|
||||||
|
} else {
|
||||||
|
players = game.getPlayers().size();
|
||||||
|
}
|
||||||
|
String status = game.getState().toString().toLowerCase();
|
||||||
|
if(game.getState() == GameState.WAITING){
|
||||||
|
sender.sendMessage(ChatColor.GREEN + "Connecting to the game lobby.");
|
||||||
|
Player player = getServer().getPlayer(sender.getName());
|
||||||
|
String command = "bw join " + game.getName();
|
||||||
|
player.performCommand(command);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (showedGames.size() == 0) {
|
||||||
|
sender.sendMessage(ChatColor.RED + "No Games :(");
|
||||||
|
}
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String[] getArguments() {
|
||||||
|
return new String[]{};
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String getCommand() {
|
||||||
|
return "autojoin";
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String getDescription() {
|
||||||
|
return "Auto connect to first lobby";
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String getName() {
|
||||||
|
return "autojoin";
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String getPermission() {
|
||||||
|
return "base";
|
||||||
|
}
|
||||||
|
@Override
|
||||||
|
public boolean hasPermission(CommandSender sender){
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,53 @@
|
|||||||
|
package io.github.bedwarsrel.commands;
|
||||||
|
|
||||||
|
import io.github.bedwarsrel.BedwarsRel;
|
||||||
|
import io.github.bedwarsrel.utils.ChatWriter;
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import org.bukkit.ChatColor;
|
||||||
|
import org.bukkit.command.CommandSender;
|
||||||
|
import org.bukkit.entity.Player;
|
||||||
|
|
||||||
|
public abstract class BaseCommand implements ICommand {
|
||||||
|
|
||||||
|
private BedwarsRel plugin = null;
|
||||||
|
|
||||||
|
public BaseCommand(BedwarsRel plugin) {
|
||||||
|
this.plugin = plugin;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public abstract boolean execute(CommandSender sender, ArrayList<String> args);
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public abstract String[] getArguments();
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public abstract String getCommand();
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public abstract String getDescription();
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public abstract String getName();
|
||||||
|
|
||||||
|
protected BedwarsRel getPlugin() {
|
||||||
|
return this.plugin;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean hasPermission(CommandSender sender) {
|
||||||
|
if (!(sender instanceof Player)) {
|
||||||
|
sender.sendMessage(ChatWriter.pluginMessage("Only players should execute this command!"));
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!sender.hasPermission("bw." + this.getPermission())) {
|
||||||
|
sender.sendMessage(ChatWriter
|
||||||
|
.pluginMessage(ChatColor.RED + "You don't have permission to execute this command!"));
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
@@ -0,0 +1,72 @@
|
|||||||
|
package io.github.bedwarsrel.commands;
|
||||||
|
|
||||||
|
import com.google.common.collect.ImmutableMap;
|
||||||
|
import io.github.bedwarsrel.BedwarsRel;
|
||||||
|
import io.github.bedwarsrel.game.Game;
|
||||||
|
import io.github.bedwarsrel.game.GameState;
|
||||||
|
import io.github.bedwarsrel.utils.ChatWriter;
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import org.bukkit.ChatColor;
|
||||||
|
import org.bukkit.command.CommandSender;
|
||||||
|
|
||||||
|
public class ClearSpawnerCommand extends BaseCommand implements ICommand {
|
||||||
|
|
||||||
|
public ClearSpawnerCommand(BedwarsRel plugin) {
|
||||||
|
super(plugin);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean execute(CommandSender sender, ArrayList<String> args) {
|
||||||
|
if (!sender.hasPermission("bw." + this.getPermission())) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
Game game = this.getPlugin().getGameManager().getGame(args.get(0));
|
||||||
|
if (game == null) {
|
||||||
|
sender.sendMessage(ChatWriter.pluginMessage(ChatColor.RED
|
||||||
|
+ BedwarsRel
|
||||||
|
._l(sender, "errors.gamenotfound", ImmutableMap.of("game", args.get(0).toString()))));
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (game.getState() == GameState.RUNNING) {
|
||||||
|
sender.sendMessage(
|
||||||
|
ChatWriter.pluginMessage(ChatColor.RED + BedwarsRel
|
||||||
|
._l(sender, "errors.notwhilegamerunning")));
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
game.getRessourceSpawner().clear();
|
||||||
|
sender
|
||||||
|
.sendMessage(
|
||||||
|
ChatWriter.pluginMessage(ChatColor.GREEN + BedwarsRel
|
||||||
|
._l(sender, "success.spawnercleared")));
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String[] getArguments() {
|
||||||
|
return new String[]{"game"};
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String getCommand() {
|
||||||
|
return "clearspawner";
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String getDescription() {
|
||||||
|
return BedwarsRel._l("commands.clearspawner.desc");
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String getName() {
|
||||||
|
return BedwarsRel._l("commands.clearspawner.name");
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String getPermission() {
|
||||||
|
return "setup";
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
@@ -0,0 +1,133 @@
|
|||||||
|
package io.github.bedwarsrel.commands;
|
||||||
|
|
||||||
|
import io.github.bedwarsrel.BedwarsRel;
|
||||||
|
import io.github.bedwarsrel.utils.ChatWriter;
|
||||||
|
import io.github.bedwarsrel.utils.HastebinUtility;
|
||||||
|
import io.github.bedwarsrel.utils.SupportData;
|
||||||
|
import java.io.File;
|
||||||
|
import java.io.IOException;
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.Date;
|
||||||
|
import net.md_5.bungee.api.ChatColor;
|
||||||
|
import org.bukkit.command.CommandSender;
|
||||||
|
|
||||||
|
public class DebugPasteCommand extends BaseCommand implements ICommand {
|
||||||
|
|
||||||
|
public DebugPasteCommand(BedwarsRel plugin) {
|
||||||
|
super(plugin);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean execute(final CommandSender sender, ArrayList<String> args) {
|
||||||
|
if (!super.hasPermission(sender) && !sender.isOp()) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
BedwarsRel.getInstance().getServer().getScheduler()
|
||||||
|
.runTaskAsynchronously(BedwarsRel.getInstance(),
|
||||||
|
new Runnable() {
|
||||||
|
@Override
|
||||||
|
public void run() {
|
||||||
|
try {
|
||||||
|
String configYML = HastebinUtility.upload(SupportData.getConfigFile());
|
||||||
|
String shopYML = HastebinUtility.upload(SupportData.getShopConfigFile());
|
||||||
|
String latestLOG;
|
||||||
|
try {
|
||||||
|
latestLOG = HastebinUtility
|
||||||
|
.upload(new File(BedwarsRel.getInstance().getDataFolder(),
|
||||||
|
"../../logs/latest.log"));
|
||||||
|
} catch (IOException ignored) {
|
||||||
|
sender.sendMessage(
|
||||||
|
ChatWriter
|
||||||
|
.pluginMessage("&clatest.log is too big to be pasted, will ignore"));
|
||||||
|
latestLOG = "too big :(";
|
||||||
|
}
|
||||||
|
StringBuilder b = new StringBuilder();
|
||||||
|
b.append(
|
||||||
|
"# Welcome to this paste\n# It is meant to provide us with better information about your problem\n\n# We will start with some informational files\n");
|
||||||
|
b.append("files:\n");
|
||||||
|
b.append(" config_yml: ").append("\"" + configYML + "\"").append('\n');
|
||||||
|
b.append(" shop_yml: ").append("\"" + shopYML + "\"").append('\n');
|
||||||
|
b.append(" latest_log: ").append("\"" + latestLOG + "\"").append('\n');
|
||||||
|
b.append("\n# General Information\n");
|
||||||
|
b.append("version:\n");
|
||||||
|
b.append(" plugin: ")
|
||||||
|
.append("\"" + BedwarsRel.getInstance().getDescription().getVersion() + "\"");
|
||||||
|
if (SupportData.getPluginVersionArray().length == 3
|
||||||
|
&& !SupportData.getPluginVersionArray()[1].equals("unknown")) {
|
||||||
|
b.append("(https://github.com/BedwarsRel/BedwarsRel/tree/"
|
||||||
|
+ SupportData.getPluginVersionArray()[1] + ")");
|
||||||
|
}
|
||||||
|
b.append('\n');
|
||||||
|
b.append(" server: ").append("\"" + SupportData.getServerVersion() + "\"")
|
||||||
|
.append('\n');
|
||||||
|
b.append(" bukkit: ").append("\"" + SupportData.getBukkitVersion() + "\"")
|
||||||
|
.append('\n');
|
||||||
|
b.append("online_mode: ")
|
||||||
|
.append(BedwarsRel.getInstance().getServer().getOnlineMode())
|
||||||
|
.append('\n');
|
||||||
|
b.append("plugins("
|
||||||
|
+ BedwarsRel.getInstance().getServer().getPluginManager().getPlugins().length
|
||||||
|
+ "):");
|
||||||
|
for (String plugin : SupportData.getPlugins()) {
|
||||||
|
b.append("\n ").append("\"" + plugin + "\"");
|
||||||
|
}
|
||||||
|
b.append("\n\n# JVM\n");
|
||||||
|
Runtime runtime = Runtime.getRuntime();
|
||||||
|
b.append("memory:\n");
|
||||||
|
b.append(" free: ").append(runtime.freeMemory() / 1000000).append(" MB\n");
|
||||||
|
b.append(" max: ").append(runtime.maxMemory() / 1000000).append(" MB\n");
|
||||||
|
b.append("java:\n");
|
||||||
|
b.append(" specification:\n version: \"")
|
||||||
|
.append(System.getProperty("java.specification.version")).append("\"\n");
|
||||||
|
b.append(" vendor: \"").append(System.getProperty("java.vendor")).append("\"\n");
|
||||||
|
b.append(" version: \"").append(System.getProperty("java.version"))
|
||||||
|
.append("\"\n");
|
||||||
|
b.append("os:\n");
|
||||||
|
b.append(" arch: \"").append(System.getProperty("os.arch")).append("\"\n");
|
||||||
|
b.append(" name: \"").append(System.getProperty("os.name")).append("\"\n");
|
||||||
|
b.append(" version: \"").append(System.getProperty("os.version"))
|
||||||
|
.append("\"\n\n");
|
||||||
|
b.append("# Date\n");
|
||||||
|
b.append("date: ").append(new Date())
|
||||||
|
.append('\n');
|
||||||
|
b.append("\n# Please add a link to this file to your bug report!");
|
||||||
|
b.append("\n# https://github.com/BedwarsRel/BedwarsRel/issues");
|
||||||
|
|
||||||
|
String link = HastebinUtility.upload(b.toString());
|
||||||
|
sender.sendMessage(ChatWriter
|
||||||
|
.pluginMessage(ChatColor.GREEN + "Success! Support data pasted on " + link));
|
||||||
|
} catch (IOException e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
});
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String[] getArguments() {
|
||||||
|
return new String[]{};
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String getCommand() {
|
||||||
|
return "debugpaste";
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String getDescription() {
|
||||||
|
return BedwarsRel._l("commands.debugpaste.desc");
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String getName() {
|
||||||
|
return BedwarsRel._l("commands.debugpaste.name");
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String getPermission() {
|
||||||
|
return "setup";
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
@@ -0,0 +1,91 @@
|
|||||||
|
package io.github.bedwarsrel.commands;
|
||||||
|
|
||||||
|
import com.google.common.collect.ImmutableMap;
|
||||||
|
import io.github.bedwarsrel.BedwarsRel;
|
||||||
|
import io.github.bedwarsrel.game.Game;
|
||||||
|
import io.github.bedwarsrel.game.GameState;
|
||||||
|
import io.github.bedwarsrel.utils.ChatWriter;
|
||||||
|
import io.github.bedwarsrel.utils.Utils;
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import org.bukkit.ChatColor;
|
||||||
|
import org.bukkit.command.CommandSender;
|
||||||
|
import org.bukkit.entity.Player;
|
||||||
|
|
||||||
|
public class GameTimeCommand extends BaseCommand implements ICommand {
|
||||||
|
|
||||||
|
public GameTimeCommand(BedwarsRel plugin) {
|
||||||
|
super(plugin);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean execute(CommandSender sender, ArrayList<String> args) {
|
||||||
|
if (!sender.hasPermission("bw." + this.getPermission())) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
Player player = (Player) sender;
|
||||||
|
|
||||||
|
Game game = this.getPlugin().getGameManager().getGame(args.get(0));
|
||||||
|
String gametime = args.get(1).toString();
|
||||||
|
|
||||||
|
if (game == null) {
|
||||||
|
player.sendMessage(ChatWriter.pluginMessage(ChatColor.RED
|
||||||
|
+ BedwarsRel
|
||||||
|
._l(sender, "errors.gamenotfound", ImmutableMap.of("game", args.get(0).toString()))));
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (game.getState() == GameState.RUNNING) {
|
||||||
|
sender.sendMessage(
|
||||||
|
ChatWriter.pluginMessage(ChatColor.RED + BedwarsRel
|
||||||
|
._l(sender, "errors.notwhilegamerunning")));
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!Utils.isNumber(gametime) && !"day".equals(gametime) && !"night".equals(gametime)) {
|
||||||
|
player.sendMessage(
|
||||||
|
ChatWriter.pluginMessage(ChatColor.RED + BedwarsRel._l(player, "errors.timeincorrect")));
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
int time = 1000;
|
||||||
|
if ("day".equals(gametime)) {
|
||||||
|
time = 6000;
|
||||||
|
} else if ("night".equals(gametime)) {
|
||||||
|
time = 18000;
|
||||||
|
} else {
|
||||||
|
time = Integer.valueOf(gametime);
|
||||||
|
}
|
||||||
|
|
||||||
|
game.setTime(time);
|
||||||
|
player.sendMessage(
|
||||||
|
ChatWriter.pluginMessage(ChatColor.GREEN + BedwarsRel._l(player, "success.gametimeset")));
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String[] getArguments() {
|
||||||
|
return new String[]{"game", "time"};
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String getCommand() {
|
||||||
|
return "gametime";
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String getDescription() {
|
||||||
|
return BedwarsRel._l("commands.gametime.desc");
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String getName() {
|
||||||
|
return BedwarsRel._l("commands.gametime.name");
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String getPermission() {
|
||||||
|
return "setup";
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
@@ -0,0 +1,126 @@
|
|||||||
|
package io.github.bedwarsrel.commands;
|
||||||
|
|
||||||
|
import com.google.common.collect.ImmutableMap;
|
||||||
|
import io.github.bedwarsrel.BedwarsRel;
|
||||||
|
import io.github.bedwarsrel.utils.Utils;
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import org.bukkit.ChatColor;
|
||||||
|
import org.bukkit.command.CommandSender;
|
||||||
|
import org.bukkit.util.ChatPaginator;
|
||||||
|
import org.bukkit.util.ChatPaginator.ChatPage;
|
||||||
|
|
||||||
|
public class HelpCommand extends BaseCommand {
|
||||||
|
|
||||||
|
public HelpCommand(BedwarsRel plugin) {
|
||||||
|
super(plugin);
|
||||||
|
}
|
||||||
|
|
||||||
|
private void appendCommand(BaseCommand command, StringBuilder sb) {
|
||||||
|
String arg = "";
|
||||||
|
for (String argument : command.getArguments()) {
|
||||||
|
arg = arg + " {" + argument + "}";
|
||||||
|
}
|
||||||
|
|
||||||
|
if (command.getCommand().equals("help")) {
|
||||||
|
arg = " {page?}";
|
||||||
|
} else if (command.getCommand().equalsIgnoreCase("list")) {
|
||||||
|
arg = " {page?}";
|
||||||
|
} else if (command.getCommand().equalsIgnoreCase("stats")) {
|
||||||
|
arg = " {player?}";
|
||||||
|
} else if (command.getCommand().equalsIgnoreCase("reload")) {
|
||||||
|
arg = " {config;locale;shop;games;all?}";
|
||||||
|
} else if (command.getCommand().equalsIgnoreCase("stop")) {
|
||||||
|
arg = " {game?}";
|
||||||
|
}
|
||||||
|
|
||||||
|
sb.append(ChatColor.YELLOW + "/" + "bw"
|
||||||
|
+ " " + command.getCommand() + arg + " - " + command.getDescription() + "\n");
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean execute(CommandSender sender, ArrayList<String> args) {
|
||||||
|
if (!sender.hasPermission("bw." + this.getPermission())) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
String paginate;
|
||||||
|
int page = 1;
|
||||||
|
|
||||||
|
if (args.size() == 0 || args.size() > 1) {
|
||||||
|
paginate = "1";
|
||||||
|
} else {
|
||||||
|
paginate = args.get(0);
|
||||||
|
if (paginate.isEmpty()) {
|
||||||
|
paginate = "1";
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!Utils.isNumber(paginate)) {
|
||||||
|
paginate = "1";
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
page = Integer.parseInt(paginate);
|
||||||
|
StringBuilder sb = new StringBuilder();
|
||||||
|
sender.sendMessage(ChatColor.GREEN + "---------- Bedwars Help ----------");
|
||||||
|
|
||||||
|
ArrayList<BaseCommand> baseCommands = BedwarsRel.getInstance().getBaseCommands();
|
||||||
|
ArrayList<BaseCommand> setupCommands = BedwarsRel.getInstance().getSetupCommands();
|
||||||
|
ArrayList<BaseCommand> kickCommands = BedwarsRel.getInstance().getCommandsByPermission("kick");
|
||||||
|
|
||||||
|
for (BaseCommand command : baseCommands) {
|
||||||
|
this.appendCommand(command, sb);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (sender.hasPermission("bw.kick")) {
|
||||||
|
for (BaseCommand command : kickCommands) {
|
||||||
|
this.appendCommand(command, sb);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (sender.hasPermission("bw.setup")) {
|
||||||
|
sb.append(ChatColor.BLUE + "------- Bedwars Admin Help -------\n");
|
||||||
|
|
||||||
|
for (BaseCommand command : setupCommands) {
|
||||||
|
this.appendCommand(command, sb);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
ChatPage chatPage = ChatPaginator.paginate(sb.toString(), page);
|
||||||
|
for (String line : chatPage.getLines()) {
|
||||||
|
sender.sendMessage(line);
|
||||||
|
}
|
||||||
|
sender.sendMessage(ChatColor.GREEN + "---------- "
|
||||||
|
+ BedwarsRel._l(sender, "default.pages",
|
||||||
|
ImmutableMap.of("current", String.valueOf(chatPage.getPageNumber()), "max",
|
||||||
|
String.valueOf(chatPage.getTotalPages())))
|
||||||
|
+ " ----------");
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String[] getArguments() {
|
||||||
|
return new String[]{};
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String getCommand() {
|
||||||
|
return "help";
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String getDescription() {
|
||||||
|
return BedwarsRel._l("commands.help.desc");
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String getName() {
|
||||||
|
return BedwarsRel._l("commands.help.name");
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String getPermission() {
|
||||||
|
return "base";
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
@@ -0,0 +1,22 @@
|
|||||||
|
package io.github.bedwarsrel.commands;
|
||||||
|
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import org.bukkit.command.CommandSender;
|
||||||
|
|
||||||
|
public interface ICommand {
|
||||||
|
|
||||||
|
public boolean execute(CommandSender sender, ArrayList<String> args);
|
||||||
|
|
||||||
|
public String[] getArguments();
|
||||||
|
|
||||||
|
public String getCommand();
|
||||||
|
|
||||||
|
public String getDescription();
|
||||||
|
|
||||||
|
public String getName();
|
||||||
|
|
||||||
|
public String getPermission();
|
||||||
|
|
||||||
|
public boolean hasPermission(CommandSender sender);
|
||||||
|
|
||||||
|
}
|
||||||
@@ -0,0 +1,98 @@
|
|||||||
|
package io.github.bedwarsrel.commands;
|
||||||
|
|
||||||
|
import io.github.bedwarsrel.BedwarsRel;
|
||||||
|
import io.github.bedwarsrel.utils.ChatWriter;
|
||||||
|
import io.github.bedwarsrel.utils.HastebinUtility;
|
||||||
|
import java.io.IOException;
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.Map;
|
||||||
|
import net.md_5.bungee.api.ChatColor;
|
||||||
|
import org.bukkit.command.CommandSender;
|
||||||
|
import org.bukkit.configuration.file.YamlConfiguration;
|
||||||
|
import org.bukkit.entity.Player;
|
||||||
|
import org.bukkit.inventory.ItemStack;
|
||||||
|
|
||||||
|
public class ItemsPasteCommand extends BaseCommand implements ICommand {
|
||||||
|
|
||||||
|
public ItemsPasteCommand(BedwarsRel plugin) {
|
||||||
|
super(plugin);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean execute(final CommandSender sender, ArrayList<String> args) {
|
||||||
|
if (!super.hasPermission(sender) && !sender.isOp()) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!(sender instanceof Player)) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
final Player player = (Player) sender;
|
||||||
|
BedwarsRel.getInstance().getServer().getScheduler()
|
||||||
|
.runTaskAsynchronously(BedwarsRel.getInstance(),
|
||||||
|
new Runnable() {
|
||||||
|
@Override
|
||||||
|
public void run() {
|
||||||
|
try {
|
||||||
|
|
||||||
|
ItemStack[] playerItems = player.getInventory().getContents();
|
||||||
|
|
||||||
|
String uploadConfigFile;
|
||||||
|
|
||||||
|
ArrayList<Map<String, Object>> itemsList = new ArrayList<>();
|
||||||
|
for (ItemStack item : playerItems) {
|
||||||
|
if (item == null) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
itemsList.add(item.serialize());
|
||||||
|
}
|
||||||
|
|
||||||
|
YamlConfiguration uploadConfig = new YamlConfiguration();
|
||||||
|
uploadConfig.set("sampleItems", itemsList);
|
||||||
|
|
||||||
|
StringBuilder b = new StringBuilder();
|
||||||
|
b.append(
|
||||||
|
"# Welcome to this paste\n# This might help you to better add your custom items to BedwarsRel's shop.yml\n\n");
|
||||||
|
b.append(uploadConfig.saveToString());
|
||||||
|
b.append("\n");
|
||||||
|
b.append(
|
||||||
|
"\n# This is not a working shop - it's just a list of items you can add to your shop!");
|
||||||
|
|
||||||
|
String link = HastebinUtility.upload(b.toString());
|
||||||
|
sender.sendMessage(ChatWriter
|
||||||
|
.pluginMessage(ChatColor.GREEN + "Success! Items pasted on " + link));
|
||||||
|
} catch (IOException e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
});
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String[] getArguments() {
|
||||||
|
return new String[]{};
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String getCommand() {
|
||||||
|
return "itemspaste";
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String getDescription() {
|
||||||
|
return BedwarsRel._l("commands.itemspaste.desc");
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String getName() {
|
||||||
|
return BedwarsRel._l("commands.itemspaste.name");
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String getPermission() {
|
||||||
|
return "setup";
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
@@ -0,0 +1,97 @@
|
|||||||
|
package io.github.bedwarsrel.commands;
|
||||||
|
|
||||||
|
import com.google.common.collect.ImmutableMap;
|
||||||
|
import io.github.bedwarsrel.BedwarsRel;
|
||||||
|
import io.github.bedwarsrel.game.Game;
|
||||||
|
import io.github.bedwarsrel.game.GameState;
|
||||||
|
import io.github.bedwarsrel.utils.ChatWriter;
|
||||||
|
import io.github.bedwarsrel.utils.Utils;
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import org.bukkit.ChatColor;
|
||||||
|
import org.bukkit.command.CommandSender;
|
||||||
|
import org.bukkit.entity.Player;
|
||||||
|
|
||||||
|
public class JoinGameCommand extends BaseCommand {
|
||||||
|
|
||||||
|
public JoinGameCommand(BedwarsRel plugin) {
|
||||||
|
super(plugin);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean execute(CommandSender sender, ArrayList<String> args) {
|
||||||
|
if (!super.hasPermission(sender)) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
Player player = (Player) sender;
|
||||||
|
Game game = this.getPlugin().getGameManager().getGame(args.get(0));
|
||||||
|
Game gameOfPlayer = BedwarsRel.getInstance().getGameManager().getGameOfPlayer(player);
|
||||||
|
|
||||||
|
if (gameOfPlayer != null) {
|
||||||
|
if (gameOfPlayer.getState() == GameState.RUNNING) {
|
||||||
|
sender.sendMessage(
|
||||||
|
ChatWriter
|
||||||
|
.pluginMessage(ChatColor.RED + BedwarsRel._l(sender, "errors.notwhileingame")));
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (gameOfPlayer.getState() == GameState.WAITING) {
|
||||||
|
gameOfPlayer.playerLeave(player, false);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (game == null) {
|
||||||
|
if (!args.get(0).equalsIgnoreCase("random")) {
|
||||||
|
sender.sendMessage(ChatWriter.pluginMessage(ChatColor.RED
|
||||||
|
+ BedwarsRel
|
||||||
|
._l(sender, "errors.gamenotfound", ImmutableMap.of("game", args.get(0).toString()))));
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
ArrayList<Game> games = new ArrayList<>();
|
||||||
|
for (Game g : this.getPlugin().getGameManager().getGames()) {
|
||||||
|
if (g.getState() == GameState.WAITING) {
|
||||||
|
games.add(g);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (games.size() == 0) {
|
||||||
|
sender.sendMessage(
|
||||||
|
ChatWriter.pluginMessage(ChatColor.RED + BedwarsRel._l(sender, "errors.nofreegames")));
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
game = games.get(Utils.randInt(0, games.size() - 1));
|
||||||
|
}
|
||||||
|
|
||||||
|
if (game.playerJoins(player)) {
|
||||||
|
sender.sendMessage(
|
||||||
|
ChatWriter.pluginMessage(ChatColor.GREEN + BedwarsRel._l(sender, "success.joined")));
|
||||||
|
}
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String[] getArguments() {
|
||||||
|
return new String[]{"game"};
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String getCommand() {
|
||||||
|
return "join";
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String getDescription() {
|
||||||
|
return BedwarsRel._l("commands.join.desc");
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String getName() {
|
||||||
|
return BedwarsRel._l("commands.join.name");
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String getPermission() {
|
||||||
|
return "base";
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
@@ -0,0 +1,73 @@
|
|||||||
|
package io.github.bedwarsrel.commands;
|
||||||
|
|
||||||
|
import io.github.bedwarsrel.BedwarsRel;
|
||||||
|
import io.github.bedwarsrel.game.Game;
|
||||||
|
import io.github.bedwarsrel.utils.ChatWriter;
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import org.bukkit.command.CommandSender;
|
||||||
|
import org.bukkit.entity.Player;
|
||||||
|
|
||||||
|
public class KickCommand extends BaseCommand implements ICommand {
|
||||||
|
|
||||||
|
public KickCommand(BedwarsRel plugin) {
|
||||||
|
super(plugin);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean execute(CommandSender sender, ArrayList<String> args) {
|
||||||
|
if (!super.hasPermission(sender) && !sender.isOp()) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
Player player = (Player) sender;
|
||||||
|
Game game = BedwarsRel.getInstance().getGameManager().getGameOfPlayer(player);
|
||||||
|
|
||||||
|
// find player
|
||||||
|
Player kickPlayer = BedwarsRel.getInstance().getServer().getPlayer(args.get(0).toString());
|
||||||
|
|
||||||
|
if (game == null) {
|
||||||
|
player
|
||||||
|
.sendMessage(ChatWriter.pluginMessage(BedwarsRel._l(player, "errors.notingameforkick")));
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (kickPlayer == null || !kickPlayer.isOnline()) {
|
||||||
|
player.sendMessage(ChatWriter.pluginMessage(BedwarsRel._l(player, "errors.playernotfound")));
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!game.isInGame(kickPlayer)) {
|
||||||
|
player.sendMessage(ChatWriter.pluginMessage(BedwarsRel._l(player, "errors.playernotingame")));
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
game.playerLeave(kickPlayer, true);
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String[] getArguments() {
|
||||||
|
return new String[]{"player"};
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String getCommand() {
|
||||||
|
return "kick";
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String getDescription() {
|
||||||
|
return BedwarsRel._l("commands.kick.desc");
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String getName() {
|
||||||
|
return BedwarsRel._l("commands.kick.name");
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String getPermission() {
|
||||||
|
return "kick";
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
@@ -0,0 +1,57 @@
|
|||||||
|
package io.github.bedwarsrel.commands;
|
||||||
|
|
||||||
|
import io.github.bedwarsrel.BedwarsRel;
|
||||||
|
import io.github.bedwarsrel.game.Game;
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import org.bukkit.command.CommandSender;
|
||||||
|
import org.bukkit.entity.Player;
|
||||||
|
|
||||||
|
public class LeaveGameCommand extends BaseCommand {
|
||||||
|
|
||||||
|
public LeaveGameCommand(BedwarsRel plugin) {
|
||||||
|
super(plugin);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean execute(CommandSender sender, ArrayList<String> args) {
|
||||||
|
if (!super.hasPermission(sender)) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
Player player = (Player) sender;
|
||||||
|
Game game = BedwarsRel.getInstance().getGameManager().getGameOfPlayer(player);
|
||||||
|
|
||||||
|
if (game == null) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
game.playerLeave(player, false);
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String[] getArguments() {
|
||||||
|
return new String[]{};
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String getCommand() {
|
||||||
|
return "leave";
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String getDescription() {
|
||||||
|
return BedwarsRel._l("commands.leave.desc");
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String getName() {
|
||||||
|
return BedwarsRel._l("commands.leave.name");
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String getPermission() {
|
||||||
|
return "base";
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
@@ -0,0 +1,122 @@
|
|||||||
|
package io.github.bedwarsrel.commands;
|
||||||
|
|
||||||
|
import com.google.common.collect.ImmutableMap;
|
||||||
|
import io.github.bedwarsrel.BedwarsRel;
|
||||||
|
import io.github.bedwarsrel.game.Game;
|
||||||
|
import io.github.bedwarsrel.game.GameCheckCode;
|
||||||
|
import io.github.bedwarsrel.game.GameState;
|
||||||
|
import io.github.bedwarsrel.utils.Utils;
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.List;
|
||||||
|
import org.bukkit.ChatColor;
|
||||||
|
import org.bukkit.command.CommandSender;
|
||||||
|
import org.bukkit.util.ChatPaginator;
|
||||||
|
import org.bukkit.util.ChatPaginator.ChatPage;
|
||||||
|
|
||||||
|
public class ListGamesCommand extends BaseCommand {
|
||||||
|
|
||||||
|
public ListGamesCommand(BedwarsRel plugin) {
|
||||||
|
super(plugin);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean execute(CommandSender sender, ArrayList<String> args) {
|
||||||
|
if (!sender.hasPermission("bw." + this.getPermission())) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
String paginate;
|
||||||
|
int page = 1;
|
||||||
|
ArrayList<Game> showedGames = new ArrayList<Game>();
|
||||||
|
|
||||||
|
if (args != null) {
|
||||||
|
if (args.size() == 0 || args.size() > 1) {
|
||||||
|
paginate = "1";
|
||||||
|
} else {
|
||||||
|
paginate = args.get(0);
|
||||||
|
if (paginate.isEmpty()) {
|
||||||
|
paginate = "1";
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!Utils.isNumber(paginate)) {
|
||||||
|
paginate = "1";
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
paginate = "1";
|
||||||
|
}
|
||||||
|
|
||||||
|
page = Integer.parseInt(paginate);
|
||||||
|
StringBuilder sb = new StringBuilder();
|
||||||
|
sender.sendMessage(ChatColor.GREEN + "---------- Bedwars Games ----------");
|
||||||
|
|
||||||
|
List<Game> games = BedwarsRel.getInstance().getGameManager().getGames();
|
||||||
|
for (Game game : games) {
|
||||||
|
GameCheckCode code = game.checkGame();
|
||||||
|
if (code != GameCheckCode.OK && !sender.hasPermission("bw.setup")) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
showedGames.add(game);
|
||||||
|
int players = 0;
|
||||||
|
if (game.getState() == GameState.RUNNING) {
|
||||||
|
players = game.getCurrentPlayerAmount();
|
||||||
|
} else {
|
||||||
|
players = game.getPlayers().size();
|
||||||
|
}
|
||||||
|
|
||||||
|
sb.append(ChatColor.YELLOW
|
||||||
|
+ ((code != GameCheckCode.OK) ? ChatColor.RED + game.getName() + ChatColor.YELLOW
|
||||||
|
: game.getName())
|
||||||
|
+ " - " + game.getRegion().getName() + " - "
|
||||||
|
+ BedwarsRel._l(sender, "sign.gamestate." + game.getState().toString().toLowerCase())
|
||||||
|
+ ChatColor.YELLOW
|
||||||
|
+ " - " + BedwarsRel._l(sender, "sign.players") + ": " + ChatColor.WHITE + "["
|
||||||
|
+ ChatColor.YELLOW
|
||||||
|
+ players + ChatColor.WHITE + "/" + ChatColor.YELLOW + game.getMaxPlayers()
|
||||||
|
+ ChatColor.WHITE + "]\n");
|
||||||
|
}
|
||||||
|
|
||||||
|
if (showedGames.size() == 0) {
|
||||||
|
sb.append(ChatColor.RED + BedwarsRel._l(sender, "errors.nogames"));
|
||||||
|
}
|
||||||
|
|
||||||
|
ChatPage chatPage = ChatPaginator.paginate(sb.toString(), page);
|
||||||
|
for (String line : chatPage.getLines()) {
|
||||||
|
sender.sendMessage(line);
|
||||||
|
}
|
||||||
|
sender.sendMessage(ChatColor.GREEN + "---------- "
|
||||||
|
+ BedwarsRel._l(sender, "default.pages",
|
||||||
|
ImmutableMap.of("current", String.valueOf(chatPage.getPageNumber()), "max",
|
||||||
|
String.valueOf(chatPage.getTotalPages())))
|
||||||
|
+ " ----------");
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String[] getArguments() {
|
||||||
|
return new String[]{};
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String getCommand() {
|
||||||
|
return "list";
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String getDescription() {
|
||||||
|
return BedwarsRel._l("commands.list.desc");
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String getName() {
|
||||||
|
return BedwarsRel._l("commands.list.name");
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String getPermission() {
|
||||||
|
return "base";
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
@@ -0,0 +1,84 @@
|
|||||||
|
package io.github.bedwarsrel.commands;
|
||||||
|
|
||||||
|
import com.google.common.collect.ImmutableMap;
|
||||||
|
import io.github.bedwarsrel.BedwarsRel;
|
||||||
|
import io.github.bedwarsrel.game.Game;
|
||||||
|
import io.github.bedwarsrel.game.GameState;
|
||||||
|
import io.github.bedwarsrel.utils.ChatWriter;
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import org.bukkit.ChatColor;
|
||||||
|
import org.bukkit.command.CommandSender;
|
||||||
|
import org.bukkit.entity.Player;
|
||||||
|
|
||||||
|
public class RegionNameCommand extends BaseCommand implements ICommand {
|
||||||
|
|
||||||
|
public RegionNameCommand(BedwarsRel plugin) {
|
||||||
|
super(plugin);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean execute(CommandSender sender, ArrayList<String> args) {
|
||||||
|
if (!sender.hasPermission("bw." + this.getPermission())) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
Player player = (Player) sender;
|
||||||
|
|
||||||
|
Game game = this.getPlugin().getGameManager().getGame(args.get(0));
|
||||||
|
String name = args.get(1).toString();
|
||||||
|
|
||||||
|
if (game == null) {
|
||||||
|
player.sendMessage(ChatWriter.pluginMessage(ChatColor.RED
|
||||||
|
+ BedwarsRel
|
||||||
|
._l(sender, "errors.gamenotfound", ImmutableMap.of("game", args.get(0).toString()))));
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (game.getState() == GameState.RUNNING) {
|
||||||
|
sender.sendMessage(
|
||||||
|
ChatWriter.pluginMessage(ChatColor.RED + BedwarsRel
|
||||||
|
._l(sender, "errors.notwhilegamerunning")));
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (name.length() > 15) {
|
||||||
|
player.sendMessage(
|
||||||
|
ChatWriter
|
||||||
|
.pluginMessage(ChatColor.RED + BedwarsRel._l(player, "errors.toolongregionname")));
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
game.setRegionName(name);
|
||||||
|
player
|
||||||
|
.sendMessage(
|
||||||
|
ChatWriter
|
||||||
|
.pluginMessage(ChatColor.GREEN + BedwarsRel._l(player, "success.regionnameset")));
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String[] getArguments() {
|
||||||
|
return new String[]{"game", "name"};
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String getCommand() {
|
||||||
|
return "regionname";
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String getDescription() {
|
||||||
|
return BedwarsRel._l("commands.regionname.desc");
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String getName() {
|
||||||
|
return BedwarsRel._l("commands.regionname.name");
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String getPermission() {
|
||||||
|
return "setup";
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
@@ -0,0 +1,106 @@
|
|||||||
|
package io.github.bedwarsrel.commands;
|
||||||
|
|
||||||
|
import io.github.bedwarsrel.BedwarsRel;
|
||||||
|
import io.github.bedwarsrel.updater.ConfigUpdater;
|
||||||
|
import io.github.bedwarsrel.utils.ChatWriter;
|
||||||
|
import java.io.File;
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import org.bukkit.ChatColor;
|
||||||
|
import org.bukkit.command.CommandSender;
|
||||||
|
|
||||||
|
public class ReloadCommand extends BaseCommand {
|
||||||
|
|
||||||
|
public ReloadCommand(BedwarsRel plugin) {
|
||||||
|
super(plugin);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean execute(CommandSender sender, ArrayList<String> args) {
|
||||||
|
if (!sender.hasPermission(this.getPermission())) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
File config = new File(BedwarsRel.getInstance().getDataFolder(), "config.yml");
|
||||||
|
String command = "";
|
||||||
|
|
||||||
|
if (args.size() > 0) {
|
||||||
|
command = args.get(0);
|
||||||
|
} else {
|
||||||
|
command = "all";
|
||||||
|
}
|
||||||
|
|
||||||
|
if (command.equalsIgnoreCase("all")) {
|
||||||
|
// save default config
|
||||||
|
if (!config.exists()) {
|
||||||
|
BedwarsRel.getInstance().saveDefaultConfig();
|
||||||
|
}
|
||||||
|
|
||||||
|
BedwarsRel.getInstance().loadConfigInUTF();
|
||||||
|
|
||||||
|
BedwarsRel.getInstance().getConfig().options().copyDefaults(true);
|
||||||
|
BedwarsRel.getInstance().getConfig().options().copyHeader(true);
|
||||||
|
|
||||||
|
ConfigUpdater configUpdater = new ConfigUpdater();
|
||||||
|
configUpdater.addConfigs();
|
||||||
|
BedwarsRel.getInstance().saveConfiguration();
|
||||||
|
BedwarsRel.getInstance().loadConfigInUTF();
|
||||||
|
BedwarsRel.getInstance().loadShop();
|
||||||
|
|
||||||
|
BedwarsRel.getInstance().reloadLocalization();
|
||||||
|
BedwarsRel.getInstance().getGameManager().reloadGames();
|
||||||
|
} else if (command.equalsIgnoreCase("shop")) {
|
||||||
|
BedwarsRel.getInstance().loadShop();
|
||||||
|
} else if (command.equalsIgnoreCase("games")) {
|
||||||
|
BedwarsRel.getInstance().getGameManager().reloadGames();
|
||||||
|
} else if (command.equalsIgnoreCase("config")) {
|
||||||
|
// save default config
|
||||||
|
if (!config.exists()) {
|
||||||
|
BedwarsRel.getInstance().saveDefaultConfig();
|
||||||
|
}
|
||||||
|
|
||||||
|
BedwarsRel.getInstance().loadConfigInUTF();
|
||||||
|
|
||||||
|
BedwarsRel.getInstance().getConfig().options().copyDefaults(true);
|
||||||
|
BedwarsRel.getInstance().getConfig().options().copyHeader(true);
|
||||||
|
|
||||||
|
ConfigUpdater configUpdater = new ConfigUpdater();
|
||||||
|
configUpdater.addConfigs();
|
||||||
|
BedwarsRel.getInstance().saveConfiguration();
|
||||||
|
BedwarsRel.getInstance().loadConfigInUTF();
|
||||||
|
} else if (command.equalsIgnoreCase("locale")) {
|
||||||
|
BedwarsRel.getInstance().reloadLocalization();
|
||||||
|
} else {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
sender.sendMessage(
|
||||||
|
ChatWriter.pluginMessage(ChatColor.GREEN + BedwarsRel._l(sender, "success.reloadconfig")));
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String[] getArguments() {
|
||||||
|
return new String[]{};
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String getCommand() {
|
||||||
|
return "reload";
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String getDescription() {
|
||||||
|
return BedwarsRel._l("commands.reload.desc");
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String getName() {
|
||||||
|
return BedwarsRel._l("commands.reload.name");
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String getPermission() {
|
||||||
|
return "setup";
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
@@ -0,0 +1,72 @@
|
|||||||
|
package io.github.bedwarsrel.commands;
|
||||||
|
|
||||||
|
import com.google.common.collect.ImmutableMap;
|
||||||
|
import io.github.bedwarsrel.BedwarsRel;
|
||||||
|
import io.github.bedwarsrel.game.Game;
|
||||||
|
import io.github.bedwarsrel.game.GameState;
|
||||||
|
import io.github.bedwarsrel.utils.ChatWriter;
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import org.bukkit.ChatColor;
|
||||||
|
import org.bukkit.command.CommandSender;
|
||||||
|
|
||||||
|
public class RemoveGameCommand extends BaseCommand {
|
||||||
|
|
||||||
|
public RemoveGameCommand(BedwarsRel plugin) {
|
||||||
|
super(plugin);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean execute(CommandSender sender, ArrayList<String> args) {
|
||||||
|
if (!sender.hasPermission("bw." + this.getPermission())) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
Game game = this.getPlugin().getGameManager().getGame(args.get(0));
|
||||||
|
|
||||||
|
if (game == null) {
|
||||||
|
sender.sendMessage(ChatWriter.pluginMessage(ChatColor.RED
|
||||||
|
+ BedwarsRel
|
||||||
|
._l(sender, "errors.gamenotfound", ImmutableMap.of("game", args.get(0).toString()))));
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (game.getState() == GameState.RUNNING) {
|
||||||
|
sender.sendMessage(
|
||||||
|
ChatWriter.pluginMessage(ChatColor.RED + BedwarsRel
|
||||||
|
._l(sender, "errors.notwhilegamerunning")));
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
BedwarsRel.getInstance().getGameManager().unloadGame(game);
|
||||||
|
BedwarsRel.getInstance().getGameManager().removeGame(game);
|
||||||
|
sender.sendMessage(
|
||||||
|
ChatWriter.pluginMessage(ChatColor.GREEN + BedwarsRel._l(sender, "success.gameremoved")));
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String[] getArguments() {
|
||||||
|
return new String[]{"game"};
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String getCommand() {
|
||||||
|
return "removegame";
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String getDescription() {
|
||||||
|
return BedwarsRel._l("commands.removegame.desc");
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String getName() {
|
||||||
|
return BedwarsRel._l("commands.removegame.name");
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String getPermission() {
|
||||||
|
return "setup";
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
@@ -0,0 +1,80 @@
|
|||||||
|
package io.github.bedwarsrel.commands;
|
||||||
|
|
||||||
|
import com.google.common.collect.ImmutableMap;
|
||||||
|
import io.github.bedwarsrel.BedwarsRel;
|
||||||
|
import io.github.bedwarsrel.game.Game;
|
||||||
|
import io.github.bedwarsrel.game.GameState;
|
||||||
|
import io.github.bedwarsrel.game.Team;
|
||||||
|
import io.github.bedwarsrel.utils.ChatWriter;
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import org.bukkit.ChatColor;
|
||||||
|
import org.bukkit.command.CommandSender;
|
||||||
|
|
||||||
|
public class RemoveTeamCommand extends BaseCommand {
|
||||||
|
|
||||||
|
public RemoveTeamCommand(BedwarsRel plugin) {
|
||||||
|
super(plugin);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean execute(CommandSender sender, ArrayList<String> args) {
|
||||||
|
if (!sender.hasPermission("bw." + this.getPermission())) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
Game game = this.getPlugin().getGameManager().getGame(args.get(0));
|
||||||
|
String name = args.get(1);
|
||||||
|
|
||||||
|
if (game == null) {
|
||||||
|
sender.sendMessage(ChatWriter.pluginMessage(ChatColor.RED
|
||||||
|
+ BedwarsRel
|
||||||
|
._l(sender, "errors.gamenotfound", ImmutableMap.of("game", args.get(0).toString()))));
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (game.getState() != GameState.STOPPED) {
|
||||||
|
sender.sendMessage(
|
||||||
|
ChatWriter.pluginMessage(ChatColor.RED + BedwarsRel
|
||||||
|
._l(sender, "errors.notwhilegamerunning")));
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
Team theTeam = game.getTeam(name);
|
||||||
|
if (theTeam == null) {
|
||||||
|
sender.sendMessage(
|
||||||
|
ChatWriter.pluginMessage(ChatColor.RED + BedwarsRel._l(sender, "errors.teamnotfound")));
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
game.removeTeam(theTeam);
|
||||||
|
sender.sendMessage(
|
||||||
|
ChatWriter.pluginMessage(ChatColor.GREEN + BedwarsRel._l(sender, "success.teamremoved")));
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String[] getArguments() {
|
||||||
|
return new String[]{"game", "name"};
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String getCommand() {
|
||||||
|
return "removeteam";
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String getDescription() {
|
||||||
|
return BedwarsRel._l("commands.removeteam.desc");
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String getName() {
|
||||||
|
return BedwarsRel._l("commands.removeteam.name");
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String getPermission() {
|
||||||
|
return "setup";
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
@@ -0,0 +1,74 @@
|
|||||||
|
package io.github.bedwarsrel.commands;
|
||||||
|
|
||||||
|
import com.google.common.collect.ImmutableMap;
|
||||||
|
import io.github.bedwarsrel.BedwarsRel;
|
||||||
|
import io.github.bedwarsrel.game.Game;
|
||||||
|
import io.github.bedwarsrel.game.GameState;
|
||||||
|
import io.github.bedwarsrel.utils.ChatWriter;
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import org.bukkit.ChatColor;
|
||||||
|
import org.bukkit.command.CommandSender;
|
||||||
|
|
||||||
|
public class SaveGameCommand extends BaseCommand implements ICommand {
|
||||||
|
|
||||||
|
public SaveGameCommand(BedwarsRel plugin) {
|
||||||
|
super(plugin);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean execute(CommandSender sender, ArrayList<String> args) {
|
||||||
|
if (!sender.hasPermission("bw." + this.getPermission())) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
Game game = this.getPlugin().getGameManager().getGame(args.get(0));
|
||||||
|
if (game == null) {
|
||||||
|
sender.sendMessage(ChatWriter.pluginMessage(ChatColor.RED
|
||||||
|
+ BedwarsRel
|
||||||
|
._l(sender, "errors.gamenotfound", ImmutableMap.of("game", args.get(0).toString()))));
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (game.getState() == GameState.RUNNING) {
|
||||||
|
sender.sendMessage(
|
||||||
|
ChatWriter.pluginMessage(ChatColor.RED + BedwarsRel
|
||||||
|
._l(sender, "errors.notwhilegamerunning")));
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!game.saveGame(sender, true)) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
sender
|
||||||
|
.sendMessage(ChatWriter.pluginMessage(ChatColor.GREEN + BedwarsRel
|
||||||
|
._l(sender, "success.saved")));
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String[] getArguments() {
|
||||||
|
return new String[]{"game"};
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String getCommand() {
|
||||||
|
return "save";
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String getDescription() {
|
||||||
|
return BedwarsRel._l("commands.save.desc");
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String getName() {
|
||||||
|
return BedwarsRel._l("commands.save.name");
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String getPermission() {
|
||||||
|
return "setup";
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
@@ -0,0 +1,99 @@
|
|||||||
|
package io.github.bedwarsrel.commands;
|
||||||
|
|
||||||
|
import com.google.common.collect.ImmutableMap;
|
||||||
|
import io.github.bedwarsrel.BedwarsRel;
|
||||||
|
import io.github.bedwarsrel.game.Game;
|
||||||
|
import io.github.bedwarsrel.game.GameState;
|
||||||
|
import io.github.bedwarsrel.utils.ChatWriter;
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import org.bukkit.ChatColor;
|
||||||
|
import org.bukkit.command.CommandSender;
|
||||||
|
import org.bukkit.entity.Player;
|
||||||
|
|
||||||
|
public class SetAutobalanceCommand extends BaseCommand implements ICommand {
|
||||||
|
|
||||||
|
public SetAutobalanceCommand(BedwarsRel plugin) {
|
||||||
|
super(plugin);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean execute(CommandSender sender, ArrayList<String> args) {
|
||||||
|
if (!sender.hasPermission("bw." + this.getPermission())) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
Player player = (Player) sender;
|
||||||
|
|
||||||
|
Game game = this.getPlugin().getGameManager().getGame(args.get(0));
|
||||||
|
String value = args.get(1).toString().trim();
|
||||||
|
|
||||||
|
if (game == null) {
|
||||||
|
player.sendMessage(ChatWriter.pluginMessage(ChatColor.RED
|
||||||
|
+ BedwarsRel
|
||||||
|
._l(player, "errors.gamenotfound", ImmutableMap.of("game", args.get(0).toString()))));
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (game.getState() == GameState.RUNNING) {
|
||||||
|
sender.sendMessage(
|
||||||
|
ChatWriter.pluginMessage(ChatColor.RED + BedwarsRel
|
||||||
|
._l(sender, "errors.notwhilegamerunning")));
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!value.equalsIgnoreCase("true") && !value.equalsIgnoreCase("false")
|
||||||
|
&& !value.equalsIgnoreCase("off") && !value.equalsIgnoreCase("on")
|
||||||
|
&& !value.equalsIgnoreCase("1") && !value.equalsIgnoreCase("0")) {
|
||||||
|
player
|
||||||
|
.sendMessage(
|
||||||
|
ChatWriter.pluginMessage(ChatColor.RED + BedwarsRel
|
||||||
|
._l(player, "errors.wrongvalueonoff")));
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
boolean autobalance = false;
|
||||||
|
if (value.equalsIgnoreCase("true") || value.equalsIgnoreCase("on")
|
||||||
|
|| value.equalsIgnoreCase("1")) {
|
||||||
|
autobalance = true;
|
||||||
|
}
|
||||||
|
|
||||||
|
game.setAutobalance(autobalance);
|
||||||
|
|
||||||
|
if (autobalance) {
|
||||||
|
player.sendMessage(
|
||||||
|
ChatWriter.pluginMessage(ChatColor.GREEN + BedwarsRel
|
||||||
|
._l(player, "success.autobalanceseton")));
|
||||||
|
} else {
|
||||||
|
player.sendMessage(
|
||||||
|
ChatWriter.pluginMessage(ChatColor.GREEN + BedwarsRel
|
||||||
|
._l(player, "success.autobalancesetoff")));
|
||||||
|
}
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String[] getArguments() {
|
||||||
|
return new String[]{"game", "value"};
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String getCommand() {
|
||||||
|
return "setautobalance";
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String getDescription() {
|
||||||
|
return BedwarsRel._l("commands.setautobalance.desc");
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String getName() {
|
||||||
|
return BedwarsRel._l("commands.setautobalance.name");
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String getPermission() {
|
||||||
|
return "setup";
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
@@ -0,0 +1,164 @@
|
|||||||
|
package io.github.bedwarsrel.commands;
|
||||||
|
|
||||||
|
import com.google.common.collect.ImmutableMap;
|
||||||
|
import io.github.bedwarsrel.BedwarsRel;
|
||||||
|
import io.github.bedwarsrel.game.Game;
|
||||||
|
import io.github.bedwarsrel.game.GameState;
|
||||||
|
import io.github.bedwarsrel.game.Team;
|
||||||
|
import io.github.bedwarsrel.utils.ChatWriter;
|
||||||
|
import io.github.bedwarsrel.utils.Utils;
|
||||||
|
import java.lang.reflect.Method;
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.HashSet;
|
||||||
|
import java.util.Set;
|
||||||
|
import org.bukkit.ChatColor;
|
||||||
|
import org.bukkit.Material;
|
||||||
|
import org.bukkit.block.Block;
|
||||||
|
import org.bukkit.block.BlockFace;
|
||||||
|
import org.bukkit.command.CommandSender;
|
||||||
|
import org.bukkit.entity.Player;
|
||||||
|
import org.bukkit.material.Bed;
|
||||||
|
|
||||||
|
public class SetBedCommand extends BaseCommand implements ICommand {
|
||||||
|
|
||||||
|
public SetBedCommand(BedwarsRel plugin) {
|
||||||
|
super(plugin);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean execute(CommandSender sender, ArrayList<String> args) {
|
||||||
|
if (!super.hasPermission(sender)) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
Player player = (Player) sender;
|
||||||
|
String team = args.get(1);
|
||||||
|
|
||||||
|
Game game = this.getPlugin().getGameManager().getGame(args.get(0));
|
||||||
|
if (game == null) {
|
||||||
|
player.sendMessage(ChatWriter.pluginMessage(ChatColor.RED
|
||||||
|
+ BedwarsRel
|
||||||
|
._l(sender, "errors.gamenotfound", ImmutableMap.of("game", args.get(0).toString()))));
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (game.getState() == GameState.RUNNING) {
|
||||||
|
sender.sendMessage(
|
||||||
|
ChatWriter.pluginMessage(ChatColor.RED + BedwarsRel
|
||||||
|
._l(sender, "errors.notwhilegamerunning")));
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
Team gameTeam = game.getTeam(team);
|
||||||
|
|
||||||
|
if (gameTeam == null) {
|
||||||
|
player.sendMessage(
|
||||||
|
ChatWriter.pluginMessage(ChatColor.RED + BedwarsRel._l(player, "errors.teamnotfound")));
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
HashSet<Material> transparent = new HashSet<Material>();
|
||||||
|
transparent.add(Material.AIR);
|
||||||
|
|
||||||
|
Class<?> hashsetType = Utils.getGenericTypeOfParameter(player.getClass(), "getTargetBlock", 0);
|
||||||
|
Method targetBlockMethod = null;
|
||||||
|
Block targetBlock = null;
|
||||||
|
|
||||||
|
// 1.7 compatible
|
||||||
|
try {
|
||||||
|
try {
|
||||||
|
targetBlockMethod =
|
||||||
|
player.getClass().getMethod("getTargetBlock", new Class<?>[]{Set.class, int.class});
|
||||||
|
} catch (Exception ex) {
|
||||||
|
BedwarsRel.getInstance().getBugsnag().notify(ex);
|
||||||
|
try {
|
||||||
|
targetBlockMethod = player.getClass().getMethod("getTargetBlock",
|
||||||
|
new Class<?>[]{HashSet.class, int.class});
|
||||||
|
} catch (Exception exc) {
|
||||||
|
BedwarsRel.getInstance().getBugsnag().notify(exc);
|
||||||
|
exc.printStackTrace();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (hashsetType.equals(Byte.class)) {
|
||||||
|
targetBlock = (Block) targetBlockMethod.invoke(player, new Object[]{null, 15});
|
||||||
|
} else {
|
||||||
|
targetBlock = (Block) targetBlockMethod.invoke(player, new Object[]{transparent, 15});
|
||||||
|
}
|
||||||
|
|
||||||
|
} catch (Exception e) {
|
||||||
|
BedwarsRel.getInstance().getBugsnag().notify(e);
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
|
|
||||||
|
Block standingBlock = player.getLocation().getBlock().getRelative(BlockFace.DOWN);
|
||||||
|
|
||||||
|
if (targetBlock == null || standingBlock == null) {
|
||||||
|
player.sendMessage(
|
||||||
|
ChatWriter.pluginMessage(ChatColor.RED + BedwarsRel._l(player, "errors.bedtargeting")));
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
Material targetMaterial = game.getTargetMaterial();
|
||||||
|
if (targetBlock.getType() != targetMaterial && standingBlock.getType() != targetMaterial) {
|
||||||
|
player.sendMessage(
|
||||||
|
ChatWriter.pluginMessage(ChatColor.RED + BedwarsRel._l(player, "errors.bedtargeting")));
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
Block theBlock = null;
|
||||||
|
if (targetBlock.getType() == targetMaterial) {
|
||||||
|
theBlock = targetBlock;
|
||||||
|
} else {
|
||||||
|
theBlock = standingBlock;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (targetMaterial.equals(Material.BED_BLOCK)) {
|
||||||
|
Block neighbor = null;
|
||||||
|
Bed theBed = (Bed) theBlock.getState().getData();
|
||||||
|
|
||||||
|
if (!theBed.isHeadOfBed()) {
|
||||||
|
neighbor = theBlock;
|
||||||
|
theBlock = Utils.getBedNeighbor(neighbor);
|
||||||
|
} else {
|
||||||
|
neighbor = Utils.getBedNeighbor(theBlock);
|
||||||
|
}
|
||||||
|
|
||||||
|
gameTeam.setTargets(theBlock, neighbor);
|
||||||
|
} else {
|
||||||
|
gameTeam.setTargets(theBlock, null);
|
||||||
|
}
|
||||||
|
|
||||||
|
player.sendMessage(ChatWriter.pluginMessage(ChatColor.GREEN + BedwarsRel
|
||||||
|
._l(player, "success.bedset",
|
||||||
|
ImmutableMap
|
||||||
|
.of("team", gameTeam.getChatColor() + gameTeam.getName() + ChatColor.GREEN))));
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String[] getArguments() {
|
||||||
|
return new String[]{"game", "team"};
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String getCommand() {
|
||||||
|
return "setbed";
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String getDescription() {
|
||||||
|
return BedwarsRel._l("commands.setbed.desc");
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String getName() {
|
||||||
|
return BedwarsRel._l("commands.setbed.name");
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String getPermission() {
|
||||||
|
return "setup";
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
@@ -0,0 +1,64 @@
|
|||||||
|
package io.github.bedwarsrel.commands;
|
||||||
|
|
||||||
|
import com.google.common.collect.ImmutableMap;
|
||||||
|
import io.github.bedwarsrel.BedwarsRel;
|
||||||
|
import io.github.bedwarsrel.game.Game;
|
||||||
|
import io.github.bedwarsrel.utils.ChatWriter;
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import org.bukkit.ChatColor;
|
||||||
|
import org.bukkit.command.CommandSender;
|
||||||
|
|
||||||
|
public class SetBuilderCommand extends BaseCommand implements ICommand {
|
||||||
|
|
||||||
|
public SetBuilderCommand(BedwarsRel plugin) {
|
||||||
|
super(plugin);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean execute(CommandSender sender, ArrayList<String> args) {
|
||||||
|
if (!sender.hasPermission("bw." + this.getPermission())) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
Game game = this.getPlugin().getGameManager().getGame(args.get(0));
|
||||||
|
String builder = args.get(1).toString();
|
||||||
|
|
||||||
|
if (game == null) {
|
||||||
|
sender.sendMessage(ChatWriter.pluginMessage(ChatColor.RED
|
||||||
|
+ BedwarsRel
|
||||||
|
._l(sender, "errors.gamenotfound", ImmutableMap.of("game", args.get(0).toString()))));
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
game.setBuilder(builder);
|
||||||
|
sender.sendMessage(
|
||||||
|
ChatWriter.pluginMessage(ChatColor.GREEN + BedwarsRel._l(sender, "success.builderset")));
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String[] getArguments() {
|
||||||
|
return new String[]{"game", "builder"};
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String getCommand() {
|
||||||
|
return "setbuilder";
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String getDescription() {
|
||||||
|
return BedwarsRel._l("commands.setbuilder.desc");
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String getName() {
|
||||||
|
return BedwarsRel._l("commands.setbuilder.name");
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String getPermission() {
|
||||||
|
return "setup";
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
@@ -0,0 +1,88 @@
|
|||||||
|
package io.github.bedwarsrel.commands;
|
||||||
|
|
||||||
|
import com.google.common.collect.ImmutableMap;
|
||||||
|
import io.github.bedwarsrel.BedwarsRel;
|
||||||
|
import io.github.bedwarsrel.game.Game;
|
||||||
|
import io.github.bedwarsrel.game.GameState;
|
||||||
|
import io.github.bedwarsrel.utils.ChatWriter;
|
||||||
|
import io.github.bedwarsrel.utils.Utils;
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import org.bukkit.ChatColor;
|
||||||
|
import org.bukkit.Material;
|
||||||
|
import org.bukkit.command.CommandSender;
|
||||||
|
|
||||||
|
public class SetGameBlockCommand extends BaseCommand implements ICommand {
|
||||||
|
|
||||||
|
public SetGameBlockCommand(BedwarsRel plugin) {
|
||||||
|
super(plugin);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean execute(CommandSender sender, ArrayList<String> args) {
|
||||||
|
if (!sender.hasPermission("bw." + this.getPermission())) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
Game game = this.getPlugin().getGameManager().getGame(args.get(0));
|
||||||
|
String material = args.get(1).toString();
|
||||||
|
|
||||||
|
if (game == null) {
|
||||||
|
sender.sendMessage(ChatWriter.pluginMessage(ChatColor.RED
|
||||||
|
+ BedwarsRel
|
||||||
|
._l(sender, "errors.gamenotfound", ImmutableMap.of("game", args.get(0).toString()))));
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (game.getState() == GameState.RUNNING) {
|
||||||
|
sender.sendMessage(
|
||||||
|
ChatWriter.pluginMessage(ChatColor.RED + BedwarsRel
|
||||||
|
._l(sender, "errors.notwhilegamerunning")));
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
Material targetMaterial = Utils.parseMaterial(material);
|
||||||
|
if (targetMaterial == null && !"DEFAULT".equals(material)) {
|
||||||
|
sender
|
||||||
|
.sendMessage(
|
||||||
|
ChatWriter.pluginMessage(ChatColor.RED + BedwarsRel
|
||||||
|
._l(sender, "errors.novalidmaterial")));
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
if ("DEFAULT".equalsIgnoreCase(material)) {
|
||||||
|
game.setTargetMaterial(null);
|
||||||
|
} else {
|
||||||
|
game.setTargetMaterial(targetMaterial);
|
||||||
|
}
|
||||||
|
|
||||||
|
sender.sendMessage(
|
||||||
|
ChatWriter.pluginMessage(ChatColor.GREEN + BedwarsRel._l(sender, "success.materialset")));
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String[] getArguments() {
|
||||||
|
return new String[]{"game", "blocktype"};
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String getCommand() {
|
||||||
|
return "setgameblock";
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String getDescription() {
|
||||||
|
return BedwarsRel._l("commands.setgameblock.desc");
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String getName() {
|
||||||
|
return BedwarsRel._l("commands.setgameblock.name");
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String getPermission() {
|
||||||
|
return "setup";
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
@@ -0,0 +1,71 @@
|
|||||||
|
package io.github.bedwarsrel.commands;
|
||||||
|
|
||||||
|
import com.google.common.collect.ImmutableMap;
|
||||||
|
import io.github.bedwarsrel.BedwarsRel;
|
||||||
|
import io.github.bedwarsrel.game.Game;
|
||||||
|
import io.github.bedwarsrel.game.GameState;
|
||||||
|
import io.github.bedwarsrel.utils.ChatWriter;
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import org.bukkit.ChatColor;
|
||||||
|
import org.bukkit.command.CommandSender;
|
||||||
|
import org.bukkit.entity.Player;
|
||||||
|
|
||||||
|
public class SetLobbyCommand extends BaseCommand implements ICommand {
|
||||||
|
|
||||||
|
public SetLobbyCommand(BedwarsRel plugin) {
|
||||||
|
super(plugin);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean execute(CommandSender sender, ArrayList<String> args) {
|
||||||
|
if (!super.hasPermission(sender)) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
Player player = (Player) sender;
|
||||||
|
|
||||||
|
Game game = this.getPlugin().getGameManager().getGame(args.get(0));
|
||||||
|
if (game == null) {
|
||||||
|
player.sendMessage(ChatWriter.pluginMessage(ChatColor.RED
|
||||||
|
+ BedwarsRel
|
||||||
|
._l(player, "errors.gamenotfound", ImmutableMap.of("game", args.get(0).toString()))));
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (game.getState() != GameState.STOPPED) {
|
||||||
|
sender.sendMessage(
|
||||||
|
ChatWriter.pluginMessage(ChatColor.RED + BedwarsRel
|
||||||
|
._l(sender, "errors.notwhilegamerunning")));
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
game.setLobby(player);
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String[] getArguments() {
|
||||||
|
return new String[]{"game"};
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String getCommand() {
|
||||||
|
return "setlobby";
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String getDescription() {
|
||||||
|
return BedwarsRel._l("commands.setlobby.desc");
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String getName() {
|
||||||
|
return BedwarsRel._l("commands.setlobby.name");
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String getPermission() {
|
||||||
|
return "setup";
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
@@ -0,0 +1,73 @@
|
|||||||
|
package io.github.bedwarsrel.commands;
|
||||||
|
|
||||||
|
import com.google.common.collect.ImmutableMap;
|
||||||
|
import io.github.bedwarsrel.BedwarsRel;
|
||||||
|
import io.github.bedwarsrel.game.Game;
|
||||||
|
import io.github.bedwarsrel.game.GameState;
|
||||||
|
import io.github.bedwarsrel.utils.ChatWriter;
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import org.bukkit.ChatColor;
|
||||||
|
import org.bukkit.command.CommandSender;
|
||||||
|
import org.bukkit.entity.Player;
|
||||||
|
|
||||||
|
public class SetMainLobbyCommand extends BaseCommand implements ICommand {
|
||||||
|
|
||||||
|
public SetMainLobbyCommand(BedwarsRel plugin) {
|
||||||
|
super(plugin);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean execute(CommandSender sender, ArrayList<String> args) {
|
||||||
|
if (!super.hasPermission(sender)) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
Player player = (Player) sender;
|
||||||
|
|
||||||
|
Game game = this.getPlugin().getGameManager().getGame(args.get(0));
|
||||||
|
if (game == null) {
|
||||||
|
player.sendMessage(ChatWriter.pluginMessage(ChatColor.RED
|
||||||
|
+ BedwarsRel
|
||||||
|
._l(player, "errors.gamenotfound", ImmutableMap.of("game", args.get(0).toString()))));
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (game.getState() != GameState.STOPPED) {
|
||||||
|
sender.sendMessage(
|
||||||
|
ChatWriter.pluginMessage(ChatColor.RED + BedwarsRel
|
||||||
|
._l(sender, "errors.notwhilegamerunning")));
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
game.setMainLobby(player.getLocation());
|
||||||
|
player.sendMessage(
|
||||||
|
ChatWriter.pluginMessage(ChatColor.GREEN + BedwarsRel._l(player, "success.mainlobbyset")));
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String[] getArguments() {
|
||||||
|
return new String[]{"game"};
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String getCommand() {
|
||||||
|
return "setmainlobby";
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String getDescription() {
|
||||||
|
return BedwarsRel._l("commands.setmainlobby.desc");
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String getName() {
|
||||||
|
return BedwarsRel._l("commands.setmainlobby.name");
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String getPermission() {
|
||||||
|
return "setup";
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
@@ -0,0 +1,82 @@
|
|||||||
|
package io.github.bedwarsrel.commands;
|
||||||
|
|
||||||
|
import com.google.common.collect.ImmutableMap;
|
||||||
|
import io.github.bedwarsrel.BedwarsRel;
|
||||||
|
import io.github.bedwarsrel.game.Game;
|
||||||
|
import io.github.bedwarsrel.game.GameState;
|
||||||
|
import io.github.bedwarsrel.utils.ChatWriter;
|
||||||
|
import io.github.bedwarsrel.utils.Utils;
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import org.bukkit.ChatColor;
|
||||||
|
import org.bukkit.command.CommandSender;
|
||||||
|
|
||||||
|
public class SetMinPlayersCommand extends BaseCommand implements ICommand {
|
||||||
|
|
||||||
|
public SetMinPlayersCommand(BedwarsRel plugin) {
|
||||||
|
super(plugin);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean execute(CommandSender sender, ArrayList<String> args) {
|
||||||
|
if (!sender.hasPermission("bw." + this.getPermission())) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
Game game = this.getPlugin().getGameManager().getGame(args.get(0));
|
||||||
|
String minplayers = args.get(1).toString();
|
||||||
|
|
||||||
|
if (game == null) {
|
||||||
|
sender.sendMessage(ChatWriter.pluginMessage(ChatColor.RED
|
||||||
|
+ BedwarsRel
|
||||||
|
._l(sender, "errors.gamenotfound", ImmutableMap.of("game", args.get(0).toString()))));
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (game.getState() == GameState.RUNNING) {
|
||||||
|
sender.sendMessage(
|
||||||
|
ChatWriter.pluginMessage(ChatColor.RED + BedwarsRel
|
||||||
|
._l(sender, "errors.notwhilegamerunning")));
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!Utils.isNumber(minplayers)) {
|
||||||
|
sender.sendMessage(
|
||||||
|
ChatWriter
|
||||||
|
.pluginMessage(ChatColor.RED + BedwarsRel._l(sender, "errors.minplayersnumeric")));
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
game.setMinPlayers(Integer.valueOf(minplayers));
|
||||||
|
sender
|
||||||
|
.sendMessage(
|
||||||
|
ChatWriter
|
||||||
|
.pluginMessage(ChatColor.GREEN + BedwarsRel._l(sender, "success.minplayersset")));
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String[] getArguments() {
|
||||||
|
return new String[]{"game", "players"};
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String getCommand() {
|
||||||
|
return "setminplayers";
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String getDescription() {
|
||||||
|
return BedwarsRel._l("commands.setminplayers.desc");
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String getName() {
|
||||||
|
return BedwarsRel._l("commands.setminplayers.name");
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String getPermission() {
|
||||||
|
return "setup";
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
@@ -0,0 +1,83 @@
|
|||||||
|
package io.github.bedwarsrel.commands;
|
||||||
|
|
||||||
|
import com.google.common.collect.ImmutableMap;
|
||||||
|
import io.github.bedwarsrel.BedwarsRel;
|
||||||
|
import io.github.bedwarsrel.game.Game;
|
||||||
|
import io.github.bedwarsrel.game.GameState;
|
||||||
|
import io.github.bedwarsrel.utils.ChatWriter;
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import org.bukkit.ChatColor;
|
||||||
|
import org.bukkit.command.CommandSender;
|
||||||
|
import org.bukkit.entity.Player;
|
||||||
|
|
||||||
|
public class SetRegionCommand extends BaseCommand implements ICommand {
|
||||||
|
|
||||||
|
public SetRegionCommand(BedwarsRel plugin) {
|
||||||
|
super(plugin);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean execute(CommandSender sender, ArrayList<String> args) {
|
||||||
|
if (!super.hasPermission(sender)) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
Player player = (Player) sender;
|
||||||
|
|
||||||
|
Game game = this.getPlugin().getGameManager().getGame(args.get(0));
|
||||||
|
if (game == null) {
|
||||||
|
player.sendMessage(ChatWriter.pluginMessage(ChatColor.RED
|
||||||
|
+ BedwarsRel
|
||||||
|
._l(player, "errors.gamenotfound", ImmutableMap.of("game", args.get(0).toString()))));
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (game.getState() == GameState.RUNNING) {
|
||||||
|
sender.sendMessage(
|
||||||
|
ChatWriter.pluginMessage(ChatColor.RED + BedwarsRel
|
||||||
|
._l(sender, "errors.notwhilegamerunning")));
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
String loc = args.get(1);
|
||||||
|
if (!loc.equalsIgnoreCase("loc1") && !loc.equalsIgnoreCase("loc2")) {
|
||||||
|
player
|
||||||
|
.sendMessage(
|
||||||
|
ChatWriter
|
||||||
|
.pluginMessage(ChatColor.RED + BedwarsRel._l(player, "errors.regionargument")));
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
game.setLoc(player.getLocation(), loc);
|
||||||
|
player.sendMessage(ChatWriter.pluginMessage(ChatColor.GREEN
|
||||||
|
+ BedwarsRel._l(player, "success.regionset",
|
||||||
|
ImmutableMap.of("location", loc, "game", game.getName()))));
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String[] getArguments() {
|
||||||
|
return new String[]{"game", "loc1;loc2"};
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String getCommand() {
|
||||||
|
return "setregion";
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String getDescription() {
|
||||||
|
return BedwarsRel._l("commands.setregion.desc");
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String getName() {
|
||||||
|
return BedwarsRel._l("commands.setregion.name");
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String getPermission() {
|
||||||
|
return "setup";
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
@@ -0,0 +1,84 @@
|
|||||||
|
package io.github.bedwarsrel.commands;
|
||||||
|
|
||||||
|
import com.google.common.collect.ImmutableMap;
|
||||||
|
import io.github.bedwarsrel.BedwarsRel;
|
||||||
|
import io.github.bedwarsrel.game.Game;
|
||||||
|
import io.github.bedwarsrel.game.GameState;
|
||||||
|
import io.github.bedwarsrel.game.Team;
|
||||||
|
import io.github.bedwarsrel.utils.ChatWriter;
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import org.bukkit.ChatColor;
|
||||||
|
import org.bukkit.command.CommandSender;
|
||||||
|
import org.bukkit.entity.Player;
|
||||||
|
|
||||||
|
public class SetSpawnCommand extends BaseCommand implements ICommand {
|
||||||
|
|
||||||
|
public SetSpawnCommand(BedwarsRel plugin) {
|
||||||
|
super(plugin);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean execute(CommandSender sender, ArrayList<String> args) {
|
||||||
|
if (!super.hasPermission(sender)) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
Player player = (Player) sender;
|
||||||
|
|
||||||
|
Game game = this.getPlugin().getGameManager().getGame(args.get(0));
|
||||||
|
if (game == null) {
|
||||||
|
player.sendMessage(ChatWriter.pluginMessage(ChatColor.RED
|
||||||
|
+ BedwarsRel
|
||||||
|
._l(player, "errors.gamenotfound", ImmutableMap.of("game", args.get(0).toString()))));
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (game.getState() == GameState.RUNNING) {
|
||||||
|
sender.sendMessage(
|
||||||
|
ChatWriter.pluginMessage(ChatColor.RED + BedwarsRel
|
||||||
|
._l(sender, "errors.notwhilegamerunning")));
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
Team team = game.getTeam(args.get(1));
|
||||||
|
if (team == null) {
|
||||||
|
player.sendMessage(
|
||||||
|
ChatWriter.pluginMessage(ChatColor.RED + BedwarsRel._l(player, "errors.teamnotfound")));
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
team.setSpawnLocation(player.getLocation());
|
||||||
|
player
|
||||||
|
.sendMessage(ChatWriter.pluginMessage(ChatColor.GREEN + BedwarsRel
|
||||||
|
._l(player, "success.spawnset",
|
||||||
|
ImmutableMap
|
||||||
|
.of("team", team.getChatColor() + team.getDisplayName() + ChatColor.GREEN))));
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String[] getArguments() {
|
||||||
|
return new String[]{"game", "team"};
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String getCommand() {
|
||||||
|
return "setspawn";
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String getDescription() {
|
||||||
|
return BedwarsRel._l("commands.setspawn.desc");
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String getName() {
|
||||||
|
return BedwarsRel._l("commands.setspawn.name");
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String getPermission() {
|
||||||
|
return "setup";
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
@@ -0,0 +1,106 @@
|
|||||||
|
package io.github.bedwarsrel.commands;
|
||||||
|
|
||||||
|
import com.google.common.collect.ImmutableMap;
|
||||||
|
import io.github.bedwarsrel.BedwarsRel;
|
||||||
|
import io.github.bedwarsrel.game.Game;
|
||||||
|
import io.github.bedwarsrel.game.GameState;
|
||||||
|
import io.github.bedwarsrel.game.ResourceSpawner;
|
||||||
|
import io.github.bedwarsrel.utils.ChatWriter;
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.Arrays;
|
||||||
|
import java.util.List;
|
||||||
|
import org.bukkit.ChatColor;
|
||||||
|
import org.bukkit.Location;
|
||||||
|
import org.bukkit.command.CommandSender;
|
||||||
|
import org.bukkit.configuration.ConfigurationSection;
|
||||||
|
import org.bukkit.entity.Player;
|
||||||
|
|
||||||
|
public class SetSpawnerCommand extends BaseCommand {
|
||||||
|
|
||||||
|
public SetSpawnerCommand(BedwarsRel plugin) {
|
||||||
|
super(plugin);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean execute(CommandSender sender, ArrayList<String> args) {
|
||||||
|
if (!super.hasPermission(sender)) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
Player player = (Player) sender;
|
||||||
|
ArrayList<String> arguments = new ArrayList<String>(Arrays.asList(this.getResources()));
|
||||||
|
String material = args.get(1).toString().toLowerCase();
|
||||||
|
Game game = this.getPlugin().getGameManager().getGame(args.get(0));
|
||||||
|
|
||||||
|
if (game == null) {
|
||||||
|
player.sendMessage(ChatWriter.pluginMessage(ChatColor.RED
|
||||||
|
+ BedwarsRel
|
||||||
|
._l(player, "errors.gamenotfound", ImmutableMap.of("game", args.get(0).toString()))));
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (game.getState() == GameState.RUNNING) {
|
||||||
|
sender.sendMessage(
|
||||||
|
ChatWriter.pluginMessage(ChatColor.RED + BedwarsRel
|
||||||
|
._l(sender, "errors.notwhilegamerunning")));
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!arguments.contains(material)) {
|
||||||
|
player
|
||||||
|
.sendMessage(
|
||||||
|
ChatWriter.pluginMessage(ChatColor.RED + BedwarsRel
|
||||||
|
._l(player, "errors.spawnerargument")));
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
Location location = player.getLocation();
|
||||||
|
ResourceSpawner spawner = new ResourceSpawner(game, material, location);
|
||||||
|
game.addResourceSpawner(spawner);
|
||||||
|
player.sendMessage(
|
||||||
|
ChatWriter.pluginMessage(ChatColor.GREEN + BedwarsRel._l(player, "success.spawnerset",
|
||||||
|
ImmutableMap.of("name", material + ChatColor.GREEN))));
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String[] getArguments() {
|
||||||
|
return new String[]{"game", "ressource"};
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String getCommand() {
|
||||||
|
return "setspawner";
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String getDescription() {
|
||||||
|
return BedwarsRel._l("commands.setspawner.desc");
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String getName() {
|
||||||
|
return BedwarsRel._l("commands.setspawner.name");
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String getPermission() {
|
||||||
|
return "setup";
|
||||||
|
}
|
||||||
|
|
||||||
|
private String[] getResources() {
|
||||||
|
ConfigurationSection section =
|
||||||
|
BedwarsRel.getInstance().getConfig().getConfigurationSection("resource");
|
||||||
|
if (section == null) {
|
||||||
|
return new String[]{};
|
||||||
|
}
|
||||||
|
|
||||||
|
List<String> resources = new ArrayList<String>();
|
||||||
|
for (String key : section.getKeys(false)) {
|
||||||
|
resources.add(key.toLowerCase());
|
||||||
|
}
|
||||||
|
|
||||||
|
return resources.toArray(new String[resources.size()]);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
@@ -0,0 +1,177 @@
|
|||||||
|
package io.github.bedwarsrel.commands;
|
||||||
|
|
||||||
|
import com.google.common.collect.ImmutableMap;
|
||||||
|
import io.github.bedwarsrel.BedwarsRel;
|
||||||
|
import io.github.bedwarsrel.game.Game;
|
||||||
|
import io.github.bedwarsrel.game.GameState;
|
||||||
|
import io.github.bedwarsrel.game.Team;
|
||||||
|
import io.github.bedwarsrel.utils.ChatWriter;
|
||||||
|
import io.github.bedwarsrel.utils.Utils;
|
||||||
|
import java.lang.reflect.Method;
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.HashSet;
|
||||||
|
import java.util.Set;
|
||||||
|
import org.bukkit.ChatColor;
|
||||||
|
import org.bukkit.Material;
|
||||||
|
import org.bukkit.block.Block;
|
||||||
|
import org.bukkit.block.BlockFace;
|
||||||
|
import org.bukkit.command.CommandSender;
|
||||||
|
import org.bukkit.entity.Player;
|
||||||
|
import org.bukkit.material.Bed;
|
||||||
|
|
||||||
|
public class SetTargetCommand extends BaseCommand implements ICommand {
|
||||||
|
|
||||||
|
public SetTargetCommand(BedwarsRel plugin) {
|
||||||
|
super(plugin);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean execute(CommandSender sender, ArrayList<String> args) {
|
||||||
|
if (!super.hasPermission(sender)) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
Player player = (Player) sender;
|
||||||
|
String team = args.get(1);
|
||||||
|
|
||||||
|
Game game = this.getPlugin().getGameManager().getGame(args.get(0));
|
||||||
|
if (game == null) {
|
||||||
|
player.sendMessage(ChatWriter.pluginMessage(ChatColor.RED
|
||||||
|
+ BedwarsRel
|
||||||
|
._l(player, "errors.gamenotfound", ImmutableMap.of("game", args.get(0).toString()))));
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (game.getState() == GameState.RUNNING) {
|
||||||
|
sender.sendMessage(
|
||||||
|
ChatWriter.pluginMessage(ChatColor.RED + BedwarsRel
|
||||||
|
._l(sender, "errors.notwhilegamerunning")));
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
Team gameTeam = game.getTeam(team);
|
||||||
|
|
||||||
|
if (gameTeam == null) {
|
||||||
|
player.sendMessage(
|
||||||
|
ChatWriter.pluginMessage(ChatColor.RED + BedwarsRel._l(player, "errors.teamnotfound")));
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
Class<?> hashsetType = Utils.getGenericTypeOfParameter(player.getClass(), "getTargetBlock", 0);
|
||||||
|
Method targetBlockMethod = this.getTargetBlockMethod(player);
|
||||||
|
Block targetBlock = null;
|
||||||
|
|
||||||
|
if (targetBlockMethod != null) {
|
||||||
|
targetBlock = this.getTargetBlock(targetBlockMethod, hashsetType, player);
|
||||||
|
}
|
||||||
|
|
||||||
|
Block standingBlock = player.getLocation().getBlock().getRelative(BlockFace.DOWN);
|
||||||
|
|
||||||
|
if (targetBlock == null || standingBlock == null) {
|
||||||
|
player.sendMessage(
|
||||||
|
ChatWriter.pluginMessage(ChatColor.RED + BedwarsRel._l(player, "errors.bedtargeting")));
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
Material targetMaterial = game.getTargetMaterial();
|
||||||
|
if (targetBlock.getType() != targetMaterial && standingBlock.getType() != targetMaterial) {
|
||||||
|
player.sendMessage(
|
||||||
|
ChatWriter.pluginMessage(ChatColor.RED + BedwarsRel._l(player, "errors.bedtargeting")));
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
Block theBlock = null;
|
||||||
|
if (targetBlock.getType() == targetMaterial) {
|
||||||
|
theBlock = targetBlock;
|
||||||
|
} else {
|
||||||
|
theBlock = standingBlock;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (targetMaterial.equals(Material.BED_BLOCK)) {
|
||||||
|
Block neighbor = null;
|
||||||
|
Bed theBed = (Bed) theBlock.getState().getData();
|
||||||
|
|
||||||
|
if (!theBed.isHeadOfBed()) {
|
||||||
|
neighbor = theBlock;
|
||||||
|
theBlock = Utils.getBedNeighbor(neighbor);
|
||||||
|
} else {
|
||||||
|
neighbor = Utils.getBedNeighbor(theBlock);
|
||||||
|
}
|
||||||
|
|
||||||
|
gameTeam.setTargets(theBlock, neighbor);
|
||||||
|
} else {
|
||||||
|
gameTeam.setTargets(theBlock, null);
|
||||||
|
}
|
||||||
|
|
||||||
|
player.sendMessage(ChatWriter.pluginMessage(ChatColor.GREEN + BedwarsRel
|
||||||
|
._l(player, "success.bedset",
|
||||||
|
ImmutableMap
|
||||||
|
.of("team", gameTeam.getChatColor() + gameTeam.getName() + ChatColor.GREEN))));
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String[] getArguments() {
|
||||||
|
return new String[]{"game", "team"};
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String getCommand() {
|
||||||
|
return "settarget";
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String getDescription() {
|
||||||
|
return BedwarsRel._l("commands.settarget.desc");
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String getName() {
|
||||||
|
return BedwarsRel._l("commands.settarget.name");
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String getPermission() {
|
||||||
|
return "setup";
|
||||||
|
}
|
||||||
|
|
||||||
|
private Block getTargetBlock(Method targetBlockMethod, Class<?> hashsetType, Player player) {
|
||||||
|
Block targetBlock = null;
|
||||||
|
HashSet<Material> transparent = new HashSet<Material>();
|
||||||
|
transparent.add(Material.AIR);
|
||||||
|
|
||||||
|
try {
|
||||||
|
if (hashsetType.equals(Byte.class)) {
|
||||||
|
targetBlock = (Block) targetBlockMethod.invoke(player, new Object[]{null, 15});
|
||||||
|
} else {
|
||||||
|
targetBlock = (Block) targetBlockMethod.invoke(player, new Object[]{transparent, 15});
|
||||||
|
}
|
||||||
|
|
||||||
|
} catch (Exception e) {
|
||||||
|
BedwarsRel.getInstance().getBugsnag().notify(e);
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
|
|
||||||
|
return targetBlock;
|
||||||
|
}
|
||||||
|
|
||||||
|
private Method getTargetBlockMethod(Player player) {
|
||||||
|
Method targetBlockMethod = null;
|
||||||
|
try {
|
||||||
|
targetBlockMethod =
|
||||||
|
player.getClass().getMethod("getTargetBlock", new Class<?>[]{Set.class, int.class});
|
||||||
|
} catch (Exception ex) {
|
||||||
|
BedwarsRel.getInstance().getBugsnag().notify(ex);
|
||||||
|
try {
|
||||||
|
targetBlockMethod = player.getClass().getMethod("getTargetBlock",
|
||||||
|
new Class<?>[]{HashSet.class, int.class});
|
||||||
|
} catch (Exception exc) {
|
||||||
|
BedwarsRel.getInstance().getBugsnag().notify(exc);
|
||||||
|
exc.printStackTrace();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return targetBlockMethod;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
@@ -0,0 +1,60 @@
|
|||||||
|
package io.github.bedwarsrel.commands;
|
||||||
|
|
||||||
|
import com.google.common.collect.ImmutableMap;
|
||||||
|
import io.github.bedwarsrel.BedwarsRel;
|
||||||
|
import io.github.bedwarsrel.game.Game;
|
||||||
|
import io.github.bedwarsrel.utils.ChatWriter;
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import org.bukkit.ChatColor;
|
||||||
|
import org.bukkit.command.CommandSender;
|
||||||
|
|
||||||
|
public class StartGameCommand extends BaseCommand implements ICommand {
|
||||||
|
|
||||||
|
public StartGameCommand(BedwarsRel plugin) {
|
||||||
|
super(plugin);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean execute(CommandSender sender, ArrayList<String> args) {
|
||||||
|
if (!sender.hasPermission("bw." + this.getPermission())) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
Game game = this.getPlugin().getGameManager().getGame(args.get(0));
|
||||||
|
if (game == null) {
|
||||||
|
sender.sendMessage(ChatWriter.pluginMessage(ChatColor.RED
|
||||||
|
+ BedwarsRel
|
||||||
|
._l(sender, "errors.gamenotfound", ImmutableMap.of("game", args.get(0).toString()))));
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
game.run(sender);
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String[] getArguments() {
|
||||||
|
return new String[]{"game"};
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String getCommand() {
|
||||||
|
return "start";
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String getDescription() {
|
||||||
|
return BedwarsRel._l("commands.start.desc");
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String getName() {
|
||||||
|
return BedwarsRel._l("commands.start.name");
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String getPermission() {
|
||||||
|
return "setup";
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
@@ -0,0 +1,136 @@
|
|||||||
|
package io.github.bedwarsrel.commands;
|
||||||
|
|
||||||
|
import com.google.common.collect.ImmutableMap;
|
||||||
|
import io.github.bedwarsrel.BedwarsRel;
|
||||||
|
import io.github.bedwarsrel.statistics.PlayerStatistic;
|
||||||
|
import io.github.bedwarsrel.utils.ChatWriter;
|
||||||
|
import io.github.bedwarsrel.utils.UUIDFetcher;
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.UUID;
|
||||||
|
import org.bukkit.ChatColor;
|
||||||
|
import org.bukkit.OfflinePlayer;
|
||||||
|
import org.bukkit.command.CommandSender;
|
||||||
|
import org.bukkit.entity.Player;
|
||||||
|
|
||||||
|
public class StatsCommand extends BaseCommand implements ICommand {
|
||||||
|
|
||||||
|
public StatsCommand(BedwarsRel plugin) {
|
||||||
|
super(plugin);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean execute(CommandSender sender, ArrayList<String> args) {
|
||||||
|
if (!super.hasPermission(sender)) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
Player player = (Player) sender;
|
||||||
|
|
||||||
|
if (!player.hasPermission("bw.otherstats") && args.size() > 0) {
|
||||||
|
args.clear();
|
||||||
|
}
|
||||||
|
|
||||||
|
player.sendMessage(ChatWriter.pluginMessage(
|
||||||
|
ChatColor.GREEN + "----------- " + BedwarsRel._l(player, "stats.header") + " -----------"));
|
||||||
|
|
||||||
|
if (args.size() == 1) {
|
||||||
|
String playerStats = args.get(0).toString();
|
||||||
|
OfflinePlayer offPlayer = BedwarsRel.getInstance().getServer().getPlayerExact(playerStats);
|
||||||
|
|
||||||
|
if (offPlayer != null) {
|
||||||
|
PlayerStatistic statistic =
|
||||||
|
BedwarsRel.getInstance().getPlayerStatisticManager().getStatistic(offPlayer);
|
||||||
|
if (statistic == null) {
|
||||||
|
player.sendMessage(ChatWriter.pluginMessage(ChatColor.RED
|
||||||
|
+ BedwarsRel
|
||||||
|
._l(player, "stats.statsnotfound", ImmutableMap.of("player", playerStats))));
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
this.sendStats(player, statistic);
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
UUID offUUID = null;
|
||||||
|
try {
|
||||||
|
offUUID = UUIDFetcher.getUUIDOf(playerStats);
|
||||||
|
if (offUUID == null) {
|
||||||
|
player.sendMessage(ChatWriter.pluginMessage(ChatColor.RED
|
||||||
|
+ BedwarsRel
|
||||||
|
._l(player, "stats.statsnotfound", ImmutableMap.of("player", playerStats))));
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
} catch (Exception e) {
|
||||||
|
BedwarsRel.getInstance().getBugsnag().notify(e);
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
|
|
||||||
|
offPlayer = BedwarsRel.getInstance().getServer().getOfflinePlayer(offUUID);
|
||||||
|
if (offPlayer == null) {
|
||||||
|
player.sendMessage(ChatWriter.pluginMessage(ChatColor.RED
|
||||||
|
+ BedwarsRel
|
||||||
|
._l(player, "stats.statsnotfound", ImmutableMap.of("player", playerStats))));
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
PlayerStatistic statistic =
|
||||||
|
BedwarsRel.getInstance().getPlayerStatisticManager().getStatistic(offPlayer);
|
||||||
|
if (statistic == null) {
|
||||||
|
player.sendMessage(ChatWriter.pluginMessage(ChatColor.RED
|
||||||
|
+ BedwarsRel
|
||||||
|
._l(player, "stats.statsnotfound", ImmutableMap.of("player", offPlayer.getName()))));
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
this.sendStats(player, statistic);
|
||||||
|
return true;
|
||||||
|
} else if (args.size() == 0) {
|
||||||
|
PlayerStatistic statistic =
|
||||||
|
BedwarsRel.getInstance().getPlayerStatisticManager().getStatistic(player);
|
||||||
|
if (statistic == null) {
|
||||||
|
player.sendMessage(ChatWriter.pluginMessage(ChatColor.RED
|
||||||
|
+ BedwarsRel
|
||||||
|
._l(player, "stats.statsnotfound", ImmutableMap.of("player", player.getName()))));
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
this.sendStats(player, statistic);
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String[] getArguments() {
|
||||||
|
return new String[]{};
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String getCommand() {
|
||||||
|
return "stats";
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String getDescription() {
|
||||||
|
return BedwarsRel._l("commands.stats.desc");
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String getName() {
|
||||||
|
return BedwarsRel._l("commands.stats.name");
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String getPermission() {
|
||||||
|
return "base";
|
||||||
|
}
|
||||||
|
|
||||||
|
private void sendStats(Player player, PlayerStatistic statistic) {
|
||||||
|
for (String line : BedwarsRel.getInstance().getPlayerStatisticManager()
|
||||||
|
.createStatisticLines(statistic, false, ChatColor.GRAY, ChatColor.YELLOW)) {
|
||||||
|
player.sendMessage(line);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
@@ -0,0 +1,85 @@
|
|||||||
|
package io.github.bedwarsrel.commands;
|
||||||
|
|
||||||
|
import com.google.common.collect.ImmutableMap;
|
||||||
|
import io.github.bedwarsrel.BedwarsRel;
|
||||||
|
import io.github.bedwarsrel.game.Game;
|
||||||
|
import io.github.bedwarsrel.utils.ChatWriter;
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import org.bukkit.ChatColor;
|
||||||
|
import org.bukkit.command.CommandSender;
|
||||||
|
import org.bukkit.entity.Player;
|
||||||
|
|
||||||
|
public class StopGameCommand extends BaseCommand implements ICommand {
|
||||||
|
|
||||||
|
public StopGameCommand(BedwarsRel plugin) {
|
||||||
|
super(plugin);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean execute(CommandSender sender, ArrayList<String> args) {
|
||||||
|
if (!sender.hasPermission("bw." + this.getPermission())) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
Game game = null;
|
||||||
|
|
||||||
|
if (args.size() == 0) {
|
||||||
|
game = this.getPlugin().getGameManager().getGameOfPlayer((Player) sender);
|
||||||
|
|
||||||
|
if (game == null) {
|
||||||
|
sender.sendMessage(
|
||||||
|
ChatWriter.pluginMessage(ChatColor.RED + BedwarsRel._l(sender, "errors.notingame")));
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (args.size() != 0) {
|
||||||
|
game = this.getPlugin().getGameManager().getGame(args.get(0));
|
||||||
|
|
||||||
|
if (game == null) {
|
||||||
|
sender.sendMessage(ChatWriter.pluginMessage(ChatColor.RED
|
||||||
|
+ BedwarsRel
|
||||||
|
._l(sender, "errors.gamenotfound", ImmutableMap.of("game", args.get(0).toString()))));
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!game.stop()) {
|
||||||
|
sender
|
||||||
|
.sendMessage(
|
||||||
|
ChatWriter
|
||||||
|
.pluginMessage(ChatColor.RED + BedwarsRel._l(sender, "errors.gamenotrunning")));
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
sender.sendMessage(
|
||||||
|
ChatWriter.pluginMessage(ChatColor.GREEN + BedwarsRel._l(sender, "success.stopped")));
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String[] getArguments() {
|
||||||
|
return new String[]{};
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String getCommand() {
|
||||||
|
return "stop";
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String getDescription() {
|
||||||
|
return BedwarsRel._l("commands.stop.desc");
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String getName() {
|
||||||
|
return BedwarsRel._l("commands.stop.name");
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String getPermission() {
|
||||||
|
return "setup";
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
@@ -0,0 +1,69 @@
|
|||||||
|
package io.github.bedwarsrel.database;
|
||||||
|
|
||||||
|
import com.zaxxer.hikari.HikariConfig;
|
||||||
|
import com.zaxxer.hikari.HikariDataSource;
|
||||||
|
import java.sql.Connection;
|
||||||
|
import java.sql.SQLException;
|
||||||
|
import java.util.TimeZone;
|
||||||
|
import lombok.Getter;
|
||||||
|
|
||||||
|
public class DatabaseManager {
|
||||||
|
|
||||||
|
@Getter
|
||||||
|
private String tablePrefix = "bw_";
|
||||||
|
private String database = null;
|
||||||
|
private HikariDataSource dataSource = null;
|
||||||
|
private String host = null;
|
||||||
|
private String password = null;
|
||||||
|
private int port = 3306;
|
||||||
|
private String user = null;
|
||||||
|
|
||||||
|
public DatabaseManager(String host, int port, String user, String password, String database,
|
||||||
|
String tablePrefix) {
|
||||||
|
this.host = host;
|
||||||
|
this.port = port;
|
||||||
|
this.user = user;
|
||||||
|
this.password = password;
|
||||||
|
this.database = database;
|
||||||
|
this.tablePrefix = tablePrefix;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
public void initialize() {
|
||||||
|
HikariConfig config = new HikariConfig();
|
||||||
|
config.setJdbcUrl("jdbc:mysql://" + this.host + ":" + String.valueOf(this.port) + "/"
|
||||||
|
+ this.database + "?autoReconnect=true&serverTimezone=" + TimeZone
|
||||||
|
.getDefault().getID());
|
||||||
|
config.setUsername(this.user);
|
||||||
|
config.setPassword(this.password);
|
||||||
|
config.addDataSourceProperty("cachePrepStmts", "true");
|
||||||
|
config.addDataSourceProperty("prepStmtCacheSize", "250");
|
||||||
|
config.addDataSourceProperty("prepStmtCacheSqlLimit", "2048");
|
||||||
|
|
||||||
|
this.dataSource = new HikariDataSource(config);
|
||||||
|
}
|
||||||
|
|
||||||
|
public Connection getConnection() {
|
||||||
|
try {
|
||||||
|
return this.dataSource.getConnection();
|
||||||
|
} catch (SQLException e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getCreateTableSql() {
|
||||||
|
return "CREATE TABLE IF NOT EXISTS `" + this.getTablePrefix()
|
||||||
|
+ "stats_players` (`kills` int(11) NOT NULL DEFAULT '0', `wins` int(11) NOT NULL DEFAULT '0', `score` int(11) NOT NULL DEFAULT '0', `loses` int(11) NOT NULL DEFAULT '0', `name` varchar(255) NOT NULL, `destroyedBeds` int(11) NOT NULL DEFAULT '0', `uuid` varchar(255) NOT NULL, `deaths` int(11) NOT NULL DEFAULT '0', PRIMARY KEY (`uuid`))";
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getReadObjectSql() {
|
||||||
|
return "SELECT * FROM " + this.getTablePrefix()
|
||||||
|
+ "stats_players WHERE uuid = ? LIMIT 1";
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getWriteObjectSql() {
|
||||||
|
return "INSERT INTO " + this.getTablePrefix()
|
||||||
|
+ "stats_players(uuid, name, deaths, destroyedBeds, kills, loses, score, wins) VALUES (?, ?, ?, ?, ?, ?, ?, ?) ON DUPLICATE KEY UPDATE uuid=VALUES(uuid),name=VALUES(name),deaths=deaths+VALUES(deaths),destroyedBeds=destroyedBeds+VALUES(destroyedBeds),kills=kills+VALUES(kills),loses=loses+VALUES(loses),score=score+VALUES(score),wins=wins+VALUES(wins)";
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,50 @@
|
|||||||
|
package io.github.bedwarsrel.events;
|
||||||
|
|
||||||
|
import io.github.bedwarsrel.commands.BaseCommand;
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import org.bukkit.command.CommandSender;
|
||||||
|
import org.bukkit.event.Event;
|
||||||
|
import org.bukkit.event.HandlerList;
|
||||||
|
|
||||||
|
public class BedwarsCommandExecutedEvent extends Event {
|
||||||
|
|
||||||
|
private static final HandlerList handlers = new HandlerList();
|
||||||
|
private BaseCommand command = null;
|
||||||
|
private ArrayList<String> params = null;
|
||||||
|
private boolean result = false;
|
||||||
|
private CommandSender sender = null;
|
||||||
|
|
||||||
|
public BedwarsCommandExecutedEvent(CommandSender sender, BaseCommand command,
|
||||||
|
ArrayList<String> params, boolean result) {
|
||||||
|
this.sender = sender;
|
||||||
|
this.command = command;
|
||||||
|
this.params = params;
|
||||||
|
this.result = result;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static HandlerList getHandlerList() {
|
||||||
|
return BedwarsCommandExecutedEvent.handlers;
|
||||||
|
}
|
||||||
|
|
||||||
|
public BaseCommand getCommand() {
|
||||||
|
return this.command;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public HandlerList getHandlers() {
|
||||||
|
return BedwarsCommandExecutedEvent.handlers;
|
||||||
|
}
|
||||||
|
|
||||||
|
public ArrayList<String> getParameter() {
|
||||||
|
return this.params;
|
||||||
|
}
|
||||||
|
|
||||||
|
public CommandSender getSender() {
|
||||||
|
return this.sender;
|
||||||
|
}
|
||||||
|
|
||||||
|
public boolean isSuccess() {
|
||||||
|
return this.result;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
@@ -0,0 +1,56 @@
|
|||||||
|
package io.github.bedwarsrel.events;
|
||||||
|
|
||||||
|
import io.github.bedwarsrel.commands.BaseCommand;
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import org.bukkit.command.CommandSender;
|
||||||
|
import org.bukkit.event.Cancellable;
|
||||||
|
import org.bukkit.event.Event;
|
||||||
|
import org.bukkit.event.HandlerList;
|
||||||
|
|
||||||
|
public class BedwarsExecuteCommandEvent extends Event implements Cancellable {
|
||||||
|
|
||||||
|
private static final HandlerList handlers = new HandlerList();
|
||||||
|
private boolean cancelled = false;
|
||||||
|
private BaseCommand command = null;
|
||||||
|
private ArrayList<String> params = null;
|
||||||
|
private CommandSender sender = null;
|
||||||
|
|
||||||
|
public BedwarsExecuteCommandEvent(CommandSender sender, BaseCommand command,
|
||||||
|
ArrayList<String> params) {
|
||||||
|
this.sender = sender;
|
||||||
|
this.command = command;
|
||||||
|
this.params = params;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static HandlerList getHandlerList() {
|
||||||
|
return BedwarsExecuteCommandEvent.handlers;
|
||||||
|
}
|
||||||
|
|
||||||
|
public BaseCommand getCommand() {
|
||||||
|
return this.command;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public HandlerList getHandlers() {
|
||||||
|
return BedwarsExecuteCommandEvent.handlers;
|
||||||
|
}
|
||||||
|
|
||||||
|
public ArrayList<String> getParameter() {
|
||||||
|
return this.params;
|
||||||
|
}
|
||||||
|
|
||||||
|
public CommandSender getSender() {
|
||||||
|
return this.sender;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean isCancelled() {
|
||||||
|
return this.cancelled;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void setCancelled(boolean cancel) {
|
||||||
|
this.cancelled = cancel;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
@@ -0,0 +1,29 @@
|
|||||||
|
package io.github.bedwarsrel.events;
|
||||||
|
|
||||||
|
import io.github.bedwarsrel.game.Game;
|
||||||
|
import org.bukkit.event.Event;
|
||||||
|
import org.bukkit.event.HandlerList;
|
||||||
|
|
||||||
|
public class BedwarsGameEndEvent extends Event {
|
||||||
|
|
||||||
|
private static final HandlerList handlers = new HandlerList();
|
||||||
|
private Game game = null;
|
||||||
|
|
||||||
|
public BedwarsGameEndEvent(Game game) {
|
||||||
|
this.game = game;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static HandlerList getHandlerList() {
|
||||||
|
return BedwarsGameEndEvent.handlers;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Game getGame() {
|
||||||
|
return this.game;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public HandlerList getHandlers() {
|
||||||
|
return BedwarsGameEndEvent.handlers;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
@@ -0,0 +1,48 @@
|
|||||||
|
package io.github.bedwarsrel.events;
|
||||||
|
|
||||||
|
import io.github.bedwarsrel.game.Game;
|
||||||
|
import io.github.bedwarsrel.game.Team;
|
||||||
|
import org.bukkit.event.Cancellable;
|
||||||
|
import org.bukkit.event.Event;
|
||||||
|
import org.bukkit.event.HandlerList;
|
||||||
|
|
||||||
|
public class BedwarsGameOverEvent extends Event implements Cancellable {
|
||||||
|
|
||||||
|
private static final HandlerList handlers = new HandlerList();
|
||||||
|
private boolean cancelled = false;
|
||||||
|
private Game game = null;
|
||||||
|
private Team winner = null;
|
||||||
|
|
||||||
|
public BedwarsGameOverEvent(Game game, Team winner) {
|
||||||
|
this.game = game;
|
||||||
|
this.winner = winner;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static HandlerList getHandlerList() {
|
||||||
|
return BedwarsGameOverEvent.handlers;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Game getGame() {
|
||||||
|
return this.game;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public HandlerList getHandlers() {
|
||||||
|
return BedwarsGameOverEvent.handlers;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Team getWinner() {
|
||||||
|
return this.winner;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean isCancelled() {
|
||||||
|
return this.cancelled;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void setCancelled(boolean cancel) {
|
||||||
|
this.cancelled = cancel;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
@@ -0,0 +1,41 @@
|
|||||||
|
package io.github.bedwarsrel.events;
|
||||||
|
|
||||||
|
import io.github.bedwarsrel.game.Game;
|
||||||
|
import org.bukkit.event.Cancellable;
|
||||||
|
import org.bukkit.event.Event;
|
||||||
|
import org.bukkit.event.HandlerList;
|
||||||
|
|
||||||
|
public class BedwarsGameStartEvent extends Event implements Cancellable {
|
||||||
|
|
||||||
|
private static final HandlerList handlers = new HandlerList();
|
||||||
|
private boolean cancelled = false;
|
||||||
|
private Game game = null;
|
||||||
|
|
||||||
|
public BedwarsGameStartEvent(Game game) {
|
||||||
|
this.game = game;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static HandlerList getHandlerList() {
|
||||||
|
return BedwarsGameStartEvent.handlers;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Game getGame() {
|
||||||
|
return this.game;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public HandlerList getHandlers() {
|
||||||
|
return BedwarsGameStartEvent.handlers;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean isCancelled() {
|
||||||
|
return this.cancelled;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void setCancelled(boolean cancel) {
|
||||||
|
this.cancelled = cancel;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
@@ -0,0 +1,29 @@
|
|||||||
|
package io.github.bedwarsrel.events;
|
||||||
|
|
||||||
|
import io.github.bedwarsrel.game.Game;
|
||||||
|
import org.bukkit.event.Event;
|
||||||
|
import org.bukkit.event.HandlerList;
|
||||||
|
|
||||||
|
public class BedwarsGameStartedEvent extends Event {
|
||||||
|
|
||||||
|
private static final HandlerList handlers = new HandlerList();
|
||||||
|
private Game game = null;
|
||||||
|
|
||||||
|
public BedwarsGameStartedEvent(Game game) {
|
||||||
|
this.game = game;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static HandlerList getHandlerList() {
|
||||||
|
return BedwarsGameStartedEvent.handlers;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Game getGame() {
|
||||||
|
return this.game;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public HandlerList getHandlers() {
|
||||||
|
return BedwarsGameStartedEvent.handlers;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
@@ -0,0 +1,66 @@
|
|||||||
|
package io.github.bedwarsrel.events;
|
||||||
|
|
||||||
|
import io.github.bedwarsrel.game.Game;
|
||||||
|
import io.github.bedwarsrel.villager.MerchantCategory;
|
||||||
|
import java.util.HashMap;
|
||||||
|
import org.bukkit.Material;
|
||||||
|
import org.bukkit.command.CommandSender;
|
||||||
|
import org.bukkit.entity.Entity;
|
||||||
|
import org.bukkit.entity.Player;
|
||||||
|
import org.bukkit.event.Cancellable;
|
||||||
|
import org.bukkit.event.Event;
|
||||||
|
import org.bukkit.event.HandlerList;
|
||||||
|
|
||||||
|
public class BedwarsOpenShopEvent extends Event implements Cancellable {
|
||||||
|
|
||||||
|
private static final HandlerList handlers = new HandlerList();
|
||||||
|
private boolean cancelled = false;
|
||||||
|
private Entity clickedEntity = null;
|
||||||
|
private Game game = null;
|
||||||
|
private HashMap<Material, MerchantCategory> itemshop = null;
|
||||||
|
private Player player = null;
|
||||||
|
|
||||||
|
public BedwarsOpenShopEvent(Game game, Player player,
|
||||||
|
HashMap<Material, MerchantCategory> itemshop, Entity clickedEntity) {
|
||||||
|
this.player = player;
|
||||||
|
this.game = game;
|
||||||
|
this.itemshop = itemshop;
|
||||||
|
this.clickedEntity = clickedEntity;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static HandlerList getHandlerList() {
|
||||||
|
return BedwarsOpenShopEvent.handlers;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Entity getEntity() {
|
||||||
|
return this.clickedEntity;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Game getGame() {
|
||||||
|
return this.game;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public HandlerList getHandlers() {
|
||||||
|
return BedwarsOpenShopEvent.handlers;
|
||||||
|
}
|
||||||
|
|
||||||
|
public HashMap<Material, MerchantCategory> getItemshop() {
|
||||||
|
return this.itemshop;
|
||||||
|
}
|
||||||
|
|
||||||
|
public CommandSender getPlayer() {
|
||||||
|
return this.player;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean isCancelled() {
|
||||||
|
return this.cancelled;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void setCancelled(boolean cancel) {
|
||||||
|
this.cancelled = cancel;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
@@ -0,0 +1,49 @@
|
|||||||
|
package io.github.bedwarsrel.events;
|
||||||
|
|
||||||
|
import io.github.bedwarsrel.game.Game;
|
||||||
|
import org.bukkit.command.CommandSender;
|
||||||
|
import org.bukkit.entity.Player;
|
||||||
|
import org.bukkit.event.Cancellable;
|
||||||
|
import org.bukkit.event.Event;
|
||||||
|
import org.bukkit.event.HandlerList;
|
||||||
|
|
||||||
|
public class BedwarsOpenTeamSelectionEvent extends Event implements Cancellable {
|
||||||
|
|
||||||
|
private static final HandlerList handlers = new HandlerList();
|
||||||
|
private boolean cancelled = false;
|
||||||
|
private Game game = null;
|
||||||
|
private Player player = null;
|
||||||
|
|
||||||
|
public BedwarsOpenTeamSelectionEvent(Game game, Player player) {
|
||||||
|
this.player = player;
|
||||||
|
this.game = game;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static HandlerList getHandlerList() {
|
||||||
|
return BedwarsOpenTeamSelectionEvent.handlers;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Game getGame() {
|
||||||
|
return this.game;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public HandlerList getHandlers() {
|
||||||
|
return BedwarsOpenTeamSelectionEvent.handlers;
|
||||||
|
}
|
||||||
|
|
||||||
|
public CommandSender getPlayer() {
|
||||||
|
return this.player;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean isCancelled() {
|
||||||
|
return this.cancelled;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void setCancelled(boolean cancel) {
|
||||||
|
this.cancelled = cancel;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
@@ -0,0 +1,67 @@
|
|||||||
|
package io.github.bedwarsrel.events;
|
||||||
|
|
||||||
|
import io.github.bedwarsrel.BedwarsRel;
|
||||||
|
import io.github.bedwarsrel.game.Game;
|
||||||
|
import org.bukkit.entity.Player;
|
||||||
|
import org.bukkit.event.Cancellable;
|
||||||
|
import org.bukkit.event.Event;
|
||||||
|
import org.bukkit.event.HandlerList;
|
||||||
|
|
||||||
|
public class BedwarsPlayerJoinEvent extends Event implements Cancellable {
|
||||||
|
|
||||||
|
private static final HandlerList handlers = new HandlerList();
|
||||||
|
private boolean cancelled = false;
|
||||||
|
private Game game = null;
|
||||||
|
private Player player = null;
|
||||||
|
private Boolean kickOnCancel = true;
|
||||||
|
|
||||||
|
public BedwarsPlayerJoinEvent(Game game, Player player) {
|
||||||
|
this.game = game;
|
||||||
|
this.player = player;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static HandlerList getHandlerList() {
|
||||||
|
return BedwarsPlayerJoinEvent.handlers;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Game getGame() {
|
||||||
|
return this.game;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public HandlerList getHandlers() {
|
||||||
|
return BedwarsPlayerJoinEvent.handlers;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Player getPlayer() {
|
||||||
|
return this.player;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Boolean getKickOnCancel() {
|
||||||
|
return kickOnCancel;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setKickOnCancel(Boolean kick) {
|
||||||
|
this.kickOnCancel = kick;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean isCancelled() {
|
||||||
|
return this.cancelled;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void setCancelled(boolean cancel) {
|
||||||
|
this.cancelled = cancel;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setPlayerLocale(String locale) {
|
||||||
|
if (BedwarsRel.getInstance().getPlayerLocales().containsKey(this.player.getUniqueId())
|
||||||
|
&& !locale
|
||||||
|
.equals(BedwarsRel.getInstance().getPlayerLocales().get(this.player.getUniqueId()))) {
|
||||||
|
BedwarsRel.getInstance().getPlayerLocales().remove(this.player.getUniqueId());
|
||||||
|
}
|
||||||
|
BedwarsRel.getInstance().getPlayerLocales().put(this.player.getUniqueId(), locale);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
@@ -0,0 +1,52 @@
|
|||||||
|
package io.github.bedwarsrel.events;
|
||||||
|
|
||||||
|
import io.github.bedwarsrel.game.Team;
|
||||||
|
import org.bukkit.entity.Player;
|
||||||
|
import org.bukkit.event.Cancellable;
|
||||||
|
import org.bukkit.event.Event;
|
||||||
|
import org.bukkit.event.HandlerList;
|
||||||
|
|
||||||
|
public class BedwarsPlayerJoinTeamEvent extends Event implements Cancellable {
|
||||||
|
|
||||||
|
private static final HandlerList handlers = new HandlerList();
|
||||||
|
private boolean cancelled = false;
|
||||||
|
private Player player = null;
|
||||||
|
private Team team = null;
|
||||||
|
|
||||||
|
public BedwarsPlayerJoinTeamEvent(Team team, Player player) {
|
||||||
|
this.player = player;
|
||||||
|
this.team = team;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static HandlerList getHandlerList() {
|
||||||
|
return BedwarsPlayerJoinTeamEvent.handlers;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public HandlerList getHandlers() {
|
||||||
|
return BedwarsPlayerJoinTeamEvent.handlers;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Player getPlayer() {
|
||||||
|
return this.player;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Team getTeam() {
|
||||||
|
return this.team;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setTeam(Team team) {
|
||||||
|
this.team = team;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean isCancelled() {
|
||||||
|
return this.cancelled;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void setCancelled(boolean cancel) {
|
||||||
|
this.cancelled = cancel;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
@@ -0,0 +1,43 @@
|
|||||||
|
package io.github.bedwarsrel.events;
|
||||||
|
|
||||||
|
import io.github.bedwarsrel.game.Game;
|
||||||
|
import io.github.bedwarsrel.game.Team;
|
||||||
|
import org.bukkit.entity.Player;
|
||||||
|
import org.bukkit.event.Event;
|
||||||
|
import org.bukkit.event.HandlerList;
|
||||||
|
|
||||||
|
public class BedwarsPlayerJoinedEvent extends Event {
|
||||||
|
|
||||||
|
private static final HandlerList handlers = new HandlerList();
|
||||||
|
private Game game = null;
|
||||||
|
private Player player = null;
|
||||||
|
private Team team = null;
|
||||||
|
|
||||||
|
public BedwarsPlayerJoinedEvent(Game game, Team team, Player player) {
|
||||||
|
this.game = game;
|
||||||
|
this.player = player;
|
||||||
|
this.team = team;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static HandlerList getHandlerList() {
|
||||||
|
return BedwarsPlayerJoinedEvent.handlers;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Game getGame() {
|
||||||
|
return this.game;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public HandlerList getHandlers() {
|
||||||
|
return BedwarsPlayerJoinedEvent.handlers;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Player getPlayer() {
|
||||||
|
return this.player;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Team getTeam() {
|
||||||
|
return this.team;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
@@ -0,0 +1,42 @@
|
|||||||
|
package io.github.bedwarsrel.events;
|
||||||
|
|
||||||
|
import io.github.bedwarsrel.game.Game;
|
||||||
|
import org.bukkit.entity.Player;
|
||||||
|
import org.bukkit.event.Event;
|
||||||
|
import org.bukkit.event.HandlerList;
|
||||||
|
|
||||||
|
public class BedwarsPlayerKilledEvent extends Event {
|
||||||
|
|
||||||
|
private static final HandlerList handlers = new HandlerList();
|
||||||
|
private Game game = null;
|
||||||
|
private Player killer = null;
|
||||||
|
private Player player = null;
|
||||||
|
|
||||||
|
public BedwarsPlayerKilledEvent(Game game, Player player, Player killer) {
|
||||||
|
this.player = player;
|
||||||
|
this.killer = killer;
|
||||||
|
this.game = game;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static HandlerList getHandlerList() {
|
||||||
|
return BedwarsPlayerKilledEvent.handlers;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Game getGame() {
|
||||||
|
return this.game;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public HandlerList getHandlers() {
|
||||||
|
return BedwarsPlayerKilledEvent.handlers;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Player getKiller() {
|
||||||
|
return this.killer;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Player getPlayer() {
|
||||||
|
return this.player;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
@@ -0,0 +1,43 @@
|
|||||||
|
package io.github.bedwarsrel.events;
|
||||||
|
|
||||||
|
import io.github.bedwarsrel.game.Game;
|
||||||
|
import io.github.bedwarsrel.game.Team;
|
||||||
|
import org.bukkit.entity.Player;
|
||||||
|
import org.bukkit.event.Event;
|
||||||
|
import org.bukkit.event.HandlerList;
|
||||||
|
|
||||||
|
public class BedwarsPlayerLeaveEvent extends Event {
|
||||||
|
|
||||||
|
private static final HandlerList handlers = new HandlerList();
|
||||||
|
private Game game = null;
|
||||||
|
private Player player = null;
|
||||||
|
private Team team = null;
|
||||||
|
|
||||||
|
public BedwarsPlayerLeaveEvent(Game game, Player player, Team team) {
|
||||||
|
this.game = game;
|
||||||
|
this.player = player;
|
||||||
|
this.team = team;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static HandlerList getHandlerList() {
|
||||||
|
return BedwarsPlayerLeaveEvent.handlers;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Game getGame() {
|
||||||
|
return this.game;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public HandlerList getHandlers() {
|
||||||
|
return BedwarsPlayerLeaveEvent.handlers;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Player getPlayer() {
|
||||||
|
return this.player;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Team getTeam() {
|
||||||
|
return this.team;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
@@ -0,0 +1,69 @@
|
|||||||
|
package io.github.bedwarsrel.events;
|
||||||
|
|
||||||
|
import io.github.bedwarsrel.game.Team;
|
||||||
|
import org.bukkit.entity.Player;
|
||||||
|
import org.bukkit.event.Cancellable;
|
||||||
|
import org.bukkit.event.Event;
|
||||||
|
import org.bukkit.event.HandlerList;
|
||||||
|
|
||||||
|
public class BedwarsPlayerSetNameEvent extends Event implements Cancellable {
|
||||||
|
|
||||||
|
private static final HandlerList handlers = new HandlerList();
|
||||||
|
private boolean cancelled = false;
|
||||||
|
private String displayName = null;
|
||||||
|
private Player player = null;
|
||||||
|
private String playerListName = null;
|
||||||
|
private Team team = null;
|
||||||
|
|
||||||
|
public BedwarsPlayerSetNameEvent(Team team, String displayName, String playerListName,
|
||||||
|
Player player) {
|
||||||
|
this.team = team;
|
||||||
|
this.player = player;
|
||||||
|
this.displayName = displayName;
|
||||||
|
this.playerListName = playerListName;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static HandlerList getHandlerList() {
|
||||||
|
return BedwarsPlayerSetNameEvent.handlers;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getDisplayName() {
|
||||||
|
return this.displayName;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setDisplayName(String displayName) {
|
||||||
|
this.displayName = displayName;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public HandlerList getHandlers() {
|
||||||
|
return BedwarsPlayerSetNameEvent.handlers;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Player getPlayer() {
|
||||||
|
return this.player;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getPlayerListName() {
|
||||||
|
return this.playerListName;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setPlayerListName(String playerListName) {
|
||||||
|
this.playerListName = playerListName;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Team getTeam() {
|
||||||
|
return this.team;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean isCancelled() {
|
||||||
|
return this.cancelled;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void setCancelled(boolean cancel) {
|
||||||
|
this.cancelled = cancel;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
@@ -0,0 +1,59 @@
|
|||||||
|
package io.github.bedwarsrel.events;
|
||||||
|
|
||||||
|
import io.github.bedwarsrel.game.Game;
|
||||||
|
import org.bukkit.Location;
|
||||||
|
import org.bukkit.event.Cancellable;
|
||||||
|
import org.bukkit.event.Event;
|
||||||
|
import org.bukkit.event.HandlerList;
|
||||||
|
import org.bukkit.inventory.ItemStack;
|
||||||
|
|
||||||
|
public class BedwarsResourceSpawnEvent extends Event implements Cancellable {
|
||||||
|
|
||||||
|
private static final HandlerList handlers = new HandlerList();
|
||||||
|
private boolean cancelled = false;
|
||||||
|
private Game game = null;
|
||||||
|
private Location location = null;
|
||||||
|
private ItemStack resource = null;
|
||||||
|
|
||||||
|
public BedwarsResourceSpawnEvent(Game game, Location location, ItemStack resource) {
|
||||||
|
this.game = game;
|
||||||
|
this.location = location;
|
||||||
|
this.resource = resource;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static HandlerList getHandlerList() {
|
||||||
|
return BedwarsResourceSpawnEvent.handlers;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Game getGame() {
|
||||||
|
return this.game;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public HandlerList getHandlers() {
|
||||||
|
return BedwarsResourceSpawnEvent.handlers;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Location getLocation() {
|
||||||
|
return this.location;
|
||||||
|
}
|
||||||
|
|
||||||
|
public ItemStack getResource() {
|
||||||
|
return this.resource;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setResource(ItemStack resource) {
|
||||||
|
this.resource = resource;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean isCancelled() {
|
||||||
|
return this.cancelled;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void setCancelled(boolean cancel) {
|
||||||
|
this.cancelled = cancel;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
@@ -0,0 +1,48 @@
|
|||||||
|
package io.github.bedwarsrel.events;
|
||||||
|
|
||||||
|
import io.github.bedwarsrel.game.Game;
|
||||||
|
import org.bukkit.command.CommandSender;
|
||||||
|
import org.bukkit.event.Cancellable;
|
||||||
|
import org.bukkit.event.Event;
|
||||||
|
import org.bukkit.event.HandlerList;
|
||||||
|
|
||||||
|
public class BedwarsSaveGameEvent extends Event implements Cancellable {
|
||||||
|
|
||||||
|
private static final HandlerList handlers = new HandlerList();
|
||||||
|
private boolean cancelled = false;
|
||||||
|
private Game game = null;
|
||||||
|
private CommandSender sender = null;
|
||||||
|
|
||||||
|
public BedwarsSaveGameEvent(Game game, CommandSender sender) {
|
||||||
|
this.sender = sender;
|
||||||
|
this.game = game;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static HandlerList getHandlerList() {
|
||||||
|
return BedwarsSaveGameEvent.handlers;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Game getGame() {
|
||||||
|
return this.game;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public HandlerList getHandlers() {
|
||||||
|
return BedwarsSaveGameEvent.handlers;
|
||||||
|
}
|
||||||
|
|
||||||
|
public CommandSender getSender() {
|
||||||
|
return this.sender;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean isCancelled() {
|
||||||
|
return this.cancelled;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void setCancelled(boolean cancel) {
|
||||||
|
this.cancelled = cancel;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
@@ -0,0 +1,41 @@
|
|||||||
|
package io.github.bedwarsrel.events;
|
||||||
|
|
||||||
|
import io.github.bedwarsrel.statistics.PlayerStatistic;
|
||||||
|
import org.bukkit.event.Cancellable;
|
||||||
|
import org.bukkit.event.Event;
|
||||||
|
import org.bukkit.event.HandlerList;
|
||||||
|
|
||||||
|
public class BedwarsSavePlayerStatisticEvent extends Event implements Cancellable {
|
||||||
|
|
||||||
|
private static final HandlerList handlers = new HandlerList();
|
||||||
|
private boolean cancelled = false;
|
||||||
|
private PlayerStatistic playerStatistic = null;
|
||||||
|
|
||||||
|
public BedwarsSavePlayerStatisticEvent(PlayerStatistic playerStatistic) {
|
||||||
|
this.playerStatistic = playerStatistic;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static HandlerList getHandlerList() {
|
||||||
|
return BedwarsSavePlayerStatisticEvent.handlers;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public HandlerList getHandlers() {
|
||||||
|
return BedwarsSavePlayerStatisticEvent.handlers;
|
||||||
|
}
|
||||||
|
|
||||||
|
public PlayerStatistic getPlayerStatistic() {
|
||||||
|
return this.playerStatistic;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean isCancelled() {
|
||||||
|
return this.cancelled;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void setCancelled(boolean cancel) {
|
||||||
|
this.cancelled = cancel;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
@@ -0,0 +1,43 @@
|
|||||||
|
package io.github.bedwarsrel.events;
|
||||||
|
|
||||||
|
import io.github.bedwarsrel.game.Game;
|
||||||
|
import io.github.bedwarsrel.game.Team;
|
||||||
|
import org.bukkit.entity.Player;
|
||||||
|
import org.bukkit.event.Event;
|
||||||
|
import org.bukkit.event.HandlerList;
|
||||||
|
|
||||||
|
public class BedwarsTargetBlockDestroyedEvent extends Event {
|
||||||
|
|
||||||
|
private static final HandlerList handlers = new HandlerList();
|
||||||
|
private Game game = null;
|
||||||
|
private Player player = null;
|
||||||
|
private Team team = null;
|
||||||
|
|
||||||
|
public BedwarsTargetBlockDestroyedEvent(Game game, Player player, Team team) {
|
||||||
|
this.player = player;
|
||||||
|
this.team = team;
|
||||||
|
this.game = game;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static HandlerList getHandlerList() {
|
||||||
|
return BedwarsTargetBlockDestroyedEvent.handlers;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Game getGame() {
|
||||||
|
return this.game;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public HandlerList getHandlers() {
|
||||||
|
return BedwarsTargetBlockDestroyedEvent.handlers;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Player getPlayer() {
|
||||||
|
return this.player;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Team getTeam() {
|
||||||
|
return this.team;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
@@ -0,0 +1,71 @@
|
|||||||
|
package io.github.bedwarsrel.events;
|
||||||
|
|
||||||
|
import io.github.bedwarsrel.game.Game;
|
||||||
|
import org.bukkit.Location;
|
||||||
|
import org.bukkit.command.CommandSender;
|
||||||
|
import org.bukkit.entity.Player;
|
||||||
|
import org.bukkit.event.Cancellable;
|
||||||
|
import org.bukkit.event.Event;
|
||||||
|
import org.bukkit.event.HandlerList;
|
||||||
|
|
||||||
|
public class BedwarsUseTNTSheepEvent extends Event implements Cancellable {
|
||||||
|
|
||||||
|
private static final HandlerList handlers = new HandlerList();
|
||||||
|
private boolean cancelled = false;
|
||||||
|
private Game game = null;
|
||||||
|
private Player player = null;
|
||||||
|
private Location startLocation = null;
|
||||||
|
private Player targetPlayer = null;
|
||||||
|
|
||||||
|
public BedwarsUseTNTSheepEvent(Game game, Player player, Player targetPlayer,
|
||||||
|
Location startLocation) {
|
||||||
|
this.player = player;
|
||||||
|
this.game = game;
|
||||||
|
this.startLocation = startLocation;
|
||||||
|
this.targetPlayer = targetPlayer;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static HandlerList getHandlerList() {
|
||||||
|
return BedwarsUseTNTSheepEvent.handlers;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Game getGame() {
|
||||||
|
return this.game;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public HandlerList getHandlers() {
|
||||||
|
return BedwarsUseTNTSheepEvent.handlers;
|
||||||
|
}
|
||||||
|
|
||||||
|
public CommandSender getPlayer() {
|
||||||
|
return this.player;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Location getStartLocation() {
|
||||||
|
return this.startLocation;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setStartLocation(Location loc) {
|
||||||
|
this.startLocation = loc;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Player getTargetPlayer() {
|
||||||
|
return this.targetPlayer;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setTargetPlayer(Player target) {
|
||||||
|
this.targetPlayer = target;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean isCancelled() {
|
||||||
|
return this.cancelled;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void setCancelled(boolean cancel) {
|
||||||
|
this.cancelled = cancel;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
@@ -0,0 +1,315 @@
|
|||||||
|
package io.github.bedwarsrel.game;
|
||||||
|
|
||||||
|
import com.google.common.collect.ImmutableMap;
|
||||||
|
import com.google.common.io.ByteArrayDataOutput;
|
||||||
|
import com.google.common.io.ByteStreams;
|
||||||
|
import io.github.bedwarsrel.BedwarsRel;
|
||||||
|
import io.github.bedwarsrel.events.BedwarsGameEndEvent;
|
||||||
|
import io.github.bedwarsrel.utils.ChatWriter;
|
||||||
|
import io.github.bedwarsrel.utils.Utils;
|
||||||
|
import java.io.ByteArrayOutputStream;
|
||||||
|
import java.io.DataOutputStream;
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.List;
|
||||||
|
import org.bukkit.Bukkit;
|
||||||
|
import org.bukkit.ChatColor;
|
||||||
|
import org.bukkit.Material;
|
||||||
|
import org.bukkit.entity.Player;
|
||||||
|
import org.bukkit.inventory.ItemStack;
|
||||||
|
import org.bukkit.inventory.meta.ItemMeta;
|
||||||
|
import org.bukkit.scheduler.BukkitRunnable;
|
||||||
|
|
||||||
|
public class BungeeGameCycle extends GameCycle {
|
||||||
|
|
||||||
|
public BungeeGameCycle(Game game) {
|
||||||
|
super(game);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void bungeeSendToServer(final String server, final Player player, boolean preventDelay) {
|
||||||
|
if (server == null) {
|
||||||
|
player
|
||||||
|
.sendMessage(
|
||||||
|
ChatWriter
|
||||||
|
.pluginMessage(ChatColor.RED + BedwarsRel._l(player, "errors.bungeenoserver")));
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
new BukkitRunnable() {
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void run() {
|
||||||
|
ByteArrayOutputStream b = new ByteArrayOutputStream();
|
||||||
|
DataOutputStream out = new DataOutputStream(b);
|
||||||
|
|
||||||
|
try {
|
||||||
|
out.writeUTF("Connect");
|
||||||
|
out.writeUTF(server);
|
||||||
|
} catch (Exception e) {
|
||||||
|
BedwarsRel.getInstance().getBugsnag().notify(e);
|
||||||
|
e.printStackTrace();
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (b != null) {
|
||||||
|
player.sendPluginMessage(BedwarsRel.getInstance(), "BungeeCord", b.toByteArray());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}.runTaskLater(BedwarsRel.getInstance(), (preventDelay) ? 0L : 20L);
|
||||||
|
}
|
||||||
|
|
||||||
|
private void kickAllPlayers() {
|
||||||
|
for (Player player : this.getGame().getTeamPlayers()) {
|
||||||
|
for (Player freePlayer : this.getGame().getFreePlayers()) {
|
||||||
|
player.showPlayer(freePlayer);
|
||||||
|
}
|
||||||
|
this.getGame().playerLeave(player, false);
|
||||||
|
}
|
||||||
|
|
||||||
|
for (Player freePlayer : this.getGame().getFreePlayersClone()) {
|
||||||
|
this.getGame().playerLeave(freePlayer, false);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onGameEnds() {
|
||||||
|
if (BedwarsRel.getInstance().getBooleanConfig("bungeecord.full-restart", true)) {
|
||||||
|
this.kickAllPlayers();
|
||||||
|
|
||||||
|
this.getGame().resetRegion();
|
||||||
|
new BukkitRunnable() {
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void run() {
|
||||||
|
if (BedwarsRel.getInstance().isSpigot()
|
||||||
|
&& BedwarsRel.getInstance().getBooleanConfig("bungeecord.spigot-restart", true)) {
|
||||||
|
BedwarsRel.getInstance().getServer()
|
||||||
|
.dispatchCommand(BedwarsRel.getInstance().getServer().getConsoleSender(),
|
||||||
|
"restart");
|
||||||
|
} else {
|
||||||
|
Bukkit.shutdown();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}.runTaskLater(BedwarsRel.getInstance(), 70L);
|
||||||
|
} else {
|
||||||
|
// Reset scoreboard first
|
||||||
|
this.getGame().resetScoreboard();
|
||||||
|
|
||||||
|
// Kick all players
|
||||||
|
this.kickAllPlayers();
|
||||||
|
|
||||||
|
// reset countdown prevention breaks
|
||||||
|
this.setEndGameRunning(false);
|
||||||
|
|
||||||
|
// Reset team chests
|
||||||
|
for (Team team : this.getGame().getTeams().values()) {
|
||||||
|
team.setInventory(null);
|
||||||
|
team.getChests().clear();
|
||||||
|
}
|
||||||
|
|
||||||
|
// clear protections
|
||||||
|
this.getGame().clearProtections();
|
||||||
|
|
||||||
|
// set state and with that, the sign
|
||||||
|
this.getGame().setState(GameState.WAITING);
|
||||||
|
this.getGame().updateScoreboard();
|
||||||
|
|
||||||
|
// reset region
|
||||||
|
this.getGame().resetRegion();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onGameLoaded() {
|
||||||
|
// Reset on game end
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onGameOver(GameOverTask task) {
|
||||||
|
if (BedwarsRel.getInstance().getBooleanConfig("bungeecord.endgame-in-lobby", true)) {
|
||||||
|
final ArrayList<Player> players = new ArrayList<Player>();
|
||||||
|
final Game game = this.getGame();
|
||||||
|
players.addAll(this.getGame().getTeamPlayers());
|
||||||
|
players.addAll(this.getGame().getFreePlayers());
|
||||||
|
for (Player player : players) {
|
||||||
|
|
||||||
|
if (!player.getWorld().equals(this.getGame().getLobby().getWorld())) {
|
||||||
|
game.getPlayerSettings(player).setTeleporting(true);
|
||||||
|
player.teleport(this.getGame().getLobby());
|
||||||
|
game.getPlayerStorage(player).clean();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
new BukkitRunnable() {
|
||||||
|
@Override
|
||||||
|
public void run() {
|
||||||
|
for (Player player : players) {
|
||||||
|
game.setPlayerGameMode(player);
|
||||||
|
game.setPlayerVisibility(player);
|
||||||
|
|
||||||
|
if (!player.getInventory().contains(Material.SLIME_BALL)) {
|
||||||
|
// Leave game (Slimeball)
|
||||||
|
ItemStack leaveGame = new ItemStack(Material.SLIME_BALL, 1);
|
||||||
|
ItemMeta im = leaveGame.getItemMeta();
|
||||||
|
im.setDisplayName(BedwarsRel._l(player, "lobby.leavegame"));
|
||||||
|
leaveGame.setItemMeta(im);
|
||||||
|
player.getInventory().setItem(8, leaveGame);
|
||||||
|
player.updateInventory();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}.runTaskLater(BedwarsRel.getInstance(), 20L);
|
||||||
|
}
|
||||||
|
if (task.getCounter() == task.getStartCount() && task.getWinner() != null) {
|
||||||
|
for (Player aPlayer : this.getGame().getPlayers()) {
|
||||||
|
if (aPlayer.isOnline()) {
|
||||||
|
aPlayer.sendMessage(
|
||||||
|
ChatWriter.pluginMessage(ChatColor.GOLD + BedwarsRel._l(aPlayer, "ingame.teamwon",
|
||||||
|
ImmutableMap.of("team", task.getWinner().getDisplayName() + ChatColor.GOLD))));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} else if (task.getCounter() == task.getStartCount() && task.getWinner() == null) {
|
||||||
|
for (Player aPlayer : this.getGame().getPlayers()) {
|
||||||
|
if (aPlayer.isOnline()) {
|
||||||
|
aPlayer.sendMessage(
|
||||||
|
ChatWriter.pluginMessage(ChatColor.GOLD + BedwarsRel._l(aPlayer, "ingame.draw")));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// game over
|
||||||
|
if (this.getGame().getPlayers().size() == 0 || task.getCounter() == 0) {
|
||||||
|
BedwarsGameEndEvent endEvent = new BedwarsGameEndEvent(this.getGame());
|
||||||
|
BedwarsRel.getInstance().getServer().getPluginManager().callEvent(endEvent);
|
||||||
|
|
||||||
|
this.onGameEnds();
|
||||||
|
task.cancel();
|
||||||
|
} else if ((task.getCounter() == task.getStartCount()) || (task.getCounter() % 10 == 0)
|
||||||
|
|| (task.getCounter() <= 5 && (task.getCounter() > 0))) {
|
||||||
|
for (Player aPlayer : this.getGame().getPlayers()) {
|
||||||
|
if (aPlayer.isOnline()) {
|
||||||
|
aPlayer.sendMessage(ChatWriter
|
||||||
|
.pluginMessage(ChatColor.AQUA + BedwarsRel
|
||||||
|
._l(aPlayer, "ingame.serverrestart", ImmutableMap
|
||||||
|
.of("sec",
|
||||||
|
ChatColor.YELLOW.toString() + task.getCounter() + ChatColor.AQUA))));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
task.decCounter();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onGameStart() {
|
||||||
|
// do nothing, world will be reseted on restarting
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean onPlayerJoins(Player player) {
|
||||||
|
final Player p = player;
|
||||||
|
|
||||||
|
if (this.getGame().isFull() && !player.hasPermission("bw.vip.joinfull")) {
|
||||||
|
if (this.getGame().getState() != GameState.RUNNING
|
||||||
|
|| !BedwarsRel.getInstance().spectationEnabled()) {
|
||||||
|
this.bungeeSendToServer(BedwarsRel.getInstance().getBungeeHub(), p, false);
|
||||||
|
new BukkitRunnable() {
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void run() {
|
||||||
|
BungeeGameCycle.this.sendBungeeMessage(p,
|
||||||
|
ChatWriter.pluginMessage(ChatColor.RED + BedwarsRel._l(p, "lobby.gamefull")));
|
||||||
|
}
|
||||||
|
}.runTaskLater(BedwarsRel.getInstance(), 60L);
|
||||||
|
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
} else if (this.getGame().isFull() && player.hasPermission("bw.vip.joinfull")) {
|
||||||
|
if (this.getGame().getState() == GameState.WAITING) {
|
||||||
|
List<Player> players = this.getGame().getNonVipPlayers();
|
||||||
|
|
||||||
|
if (players.size() == 0) {
|
||||||
|
this.bungeeSendToServer(BedwarsRel.getInstance().getBungeeHub(), p, false);
|
||||||
|
new BukkitRunnable() {
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void run() {
|
||||||
|
BungeeGameCycle.this.sendBungeeMessage(p,
|
||||||
|
ChatWriter
|
||||||
|
.pluginMessage(ChatColor.RED + BedwarsRel._l(p, "lobby.gamefullpremium")));
|
||||||
|
}
|
||||||
|
}.runTaskLater(BedwarsRel.getInstance(), 60L);
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
Player kickPlayer = null;
|
||||||
|
if (players.size() == 1) {
|
||||||
|
kickPlayer = players.get(0);
|
||||||
|
} else {
|
||||||
|
kickPlayer = players.get(Utils.randInt(0, players.size() - 1));
|
||||||
|
}
|
||||||
|
|
||||||
|
final Player kickedPlayer = kickPlayer;
|
||||||
|
|
||||||
|
this.getGame().playerLeave(kickedPlayer, false);
|
||||||
|
new BukkitRunnable() {
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void run() {
|
||||||
|
BungeeGameCycle.this.sendBungeeMessage(kickedPlayer,
|
||||||
|
ChatWriter
|
||||||
|
.pluginMessage(
|
||||||
|
ChatColor.RED + BedwarsRel._l(kickedPlayer, "lobby.kickedbyvip")));
|
||||||
|
}
|
||||||
|
}.runTaskLater(BedwarsRel.getInstance(), 60L);
|
||||||
|
} else {
|
||||||
|
if (this.getGame().getState() == GameState.RUNNING
|
||||||
|
&& !BedwarsRel.getInstance().spectationEnabled()) {
|
||||||
|
|
||||||
|
new BukkitRunnable() {
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void run() {
|
||||||
|
BungeeGameCycle.this
|
||||||
|
.bungeeSendToServer(BedwarsRel.getInstance().getBungeeHub(), p, false);
|
||||||
|
}
|
||||||
|
|
||||||
|
}.runTaskLater(BedwarsRel.getInstance(), 5L);
|
||||||
|
|
||||||
|
new BukkitRunnable() {
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void run() {
|
||||||
|
BungeeGameCycle.this.sendBungeeMessage(p,
|
||||||
|
ChatWriter.pluginMessage(ChatColor.RED + BedwarsRel._l(p, "lobby.gamefull")));
|
||||||
|
}
|
||||||
|
}.runTaskLater(BedwarsRel.getInstance(), 60L);
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onPlayerLeave(Player player) {
|
||||||
|
if (player.isOnline() || player.isDead()) {
|
||||||
|
this.bungeeSendToServer(BedwarsRel.getInstance().getBungeeHub(), player, true);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (this.getGame().getState() == GameState.RUNNING && !this.getGame().isStopping()) {
|
||||||
|
this.checkGameOver();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public void sendBungeeMessage(Player player, String message) {
|
||||||
|
ByteArrayDataOutput out = ByteStreams.newDataOutput();
|
||||||
|
|
||||||
|
out.writeUTF("Message");
|
||||||
|
out.writeUTF(player.getName());
|
||||||
|
out.writeUTF(message);
|
||||||
|
|
||||||
|
player.sendPluginMessage(BedwarsRel.getInstance(), "BungeeCord", out.toByteArray());
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
2045
common/src/main/java/io/github/bedwarsrel/game/Game.java
Normal file
2045
common/src/main/java/io/github/bedwarsrel/game/Game.java
Normal file
File diff suppressed because it is too large
Load Diff
@@ -0,0 +1,34 @@
|
|||||||
|
package io.github.bedwarsrel.game;
|
||||||
|
|
||||||
|
import com.google.common.collect.ImmutableMap;
|
||||||
|
import io.github.bedwarsrel.BedwarsRel;
|
||||||
|
import java.util.HashMap;
|
||||||
|
|
||||||
|
public enum GameCheckCode {
|
||||||
|
OK(200), LOC_NOT_SET_ERROR(400), TEAM_SIZE_LOW_ERROR(401), NO_RES_SPAWNER_ERROR(
|
||||||
|
402), NO_LOBBY_SET(403), TEAMS_WITHOUT_SPAWNS(404), NO_ITEMSHOP_CATEGORIES(
|
||||||
|
405), TEAM_NO_WRONG_BED(406), NO_MAIN_LOBBY_SET(407), TEAM_NO_WRONG_TARGET(408);
|
||||||
|
|
||||||
|
public static HashMap<String, String> GameCheckCodeMessages = null;
|
||||||
|
private int code;
|
||||||
|
|
||||||
|
GameCheckCode(int code) {
|
||||||
|
this.code = code;
|
||||||
|
}
|
||||||
|
|
||||||
|
public int getCode() {
|
||||||
|
return this.code;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getCodeMessage(ImmutableMap<String, String> map) {
|
||||||
|
return BedwarsRel
|
||||||
|
._l(BedwarsRel.getInstance().getServer().getConsoleSender(), "gamecheck." + this.toString(),
|
||||||
|
map);
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getCodeMessage() {
|
||||||
|
return BedwarsRel
|
||||||
|
._l(BedwarsRel.getInstance().getServer().getConsoleSender(),
|
||||||
|
"gamecheck." + this.toString());
|
||||||
|
}
|
||||||
|
}
|
||||||
493
common/src/main/java/io/github/bedwarsrel/game/GameCycle.java
Normal file
493
common/src/main/java/io/github/bedwarsrel/game/GameCycle.java
Normal file
@@ -0,0 +1,493 @@
|
|||||||
|
package io.github.bedwarsrel.game;
|
||||||
|
|
||||||
|
import com.google.common.collect.ImmutableMap;
|
||||||
|
import io.github.bedwarsrel.BedwarsRel;
|
||||||
|
import io.github.bedwarsrel.events.BedwarsGameOverEvent;
|
||||||
|
import io.github.bedwarsrel.events.BedwarsPlayerKilledEvent;
|
||||||
|
import io.github.bedwarsrel.shop.Specials.RescuePlatform;
|
||||||
|
import io.github.bedwarsrel.shop.Specials.SpecialItem;
|
||||||
|
import io.github.bedwarsrel.statistics.PlayerStatistic;
|
||||||
|
import io.github.bedwarsrel.utils.ChatWriter;
|
||||||
|
import io.github.bedwarsrel.utils.SoundMachine;
|
||||||
|
import io.github.bedwarsrel.utils.Utils;
|
||||||
|
import java.lang.reflect.Method;
|
||||||
|
import java.text.DecimalFormat;
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.Collection;
|
||||||
|
import java.util.HashMap;
|
||||||
|
import java.util.Iterator;
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.Map;
|
||||||
|
import org.bukkit.ChatColor;
|
||||||
|
import org.bukkit.entity.Player;
|
||||||
|
import org.bukkit.event.player.PlayerRespawnEvent;
|
||||||
|
import org.bukkit.scheduler.BukkitRunnable;
|
||||||
|
|
||||||
|
public abstract class GameCycle {
|
||||||
|
|
||||||
|
private boolean endGameRunning = false;
|
||||||
|
private Game game = null;
|
||||||
|
|
||||||
|
public GameCycle(Game game) {
|
||||||
|
this.game = game;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void checkGameOver() {
|
||||||
|
if (!BedwarsRel.getInstance().isEnabled()) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
Team winner = this.getGame().isOver();
|
||||||
|
if (winner != null) {
|
||||||
|
if (!this.isEndGameRunning()) {
|
||||||
|
this.runGameOver(winner);
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
if ((this.getGame().getTeamPlayers().size() == 0 || this.getGame().isOverSet())
|
||||||
|
&& !this.isEndGameRunning()) {
|
||||||
|
this.runGameOver(null);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public Game getGame() {
|
||||||
|
return game;
|
||||||
|
}
|
||||||
|
|
||||||
|
private Map<String, String> getRewardPlaceholders(Player player) {
|
||||||
|
Map<String, String> placeholders = new HashMap<String, String>();
|
||||||
|
|
||||||
|
placeholders.put("{player}", player.getName());
|
||||||
|
if (BedwarsRel.getInstance().statisticsEnabled()) {
|
||||||
|
PlayerStatistic statistic =
|
||||||
|
BedwarsRel.getInstance().getPlayerStatisticManager().getStatistic(player);
|
||||||
|
placeholders.put("{score}", String.valueOf(statistic.getCurrentScore()));
|
||||||
|
}
|
||||||
|
|
||||||
|
return placeholders;
|
||||||
|
}
|
||||||
|
|
||||||
|
public boolean isEndGameRunning() {
|
||||||
|
return this.endGameRunning;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setEndGameRunning(boolean running) {
|
||||||
|
this.endGameRunning = running;
|
||||||
|
}
|
||||||
|
|
||||||
|
public abstract void onGameEnds();
|
||||||
|
|
||||||
|
public abstract void onGameLoaded();
|
||||||
|
|
||||||
|
public abstract void onGameOver(GameOverTask task);
|
||||||
|
|
||||||
|
public abstract void onGameStart();
|
||||||
|
|
||||||
|
public void onPlayerDies(Player player, Player killer) {
|
||||||
|
if (this.isEndGameRunning()) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
BedwarsPlayerKilledEvent killedEvent =
|
||||||
|
new BedwarsPlayerKilledEvent(this.getGame(), player, killer);
|
||||||
|
BedwarsRel.getInstance().getServer().getPluginManager().callEvent(killedEvent);
|
||||||
|
|
||||||
|
PlayerStatistic diePlayer = null;
|
||||||
|
PlayerStatistic killerPlayer = null;
|
||||||
|
|
||||||
|
Iterator<SpecialItem> itemIterator = this.game.getSpecialItems().iterator();
|
||||||
|
while (itemIterator.hasNext()) {
|
||||||
|
SpecialItem item = itemIterator.next();
|
||||||
|
if (!(item instanceof RescuePlatform)) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
RescuePlatform rescue = (RescuePlatform) item;
|
||||||
|
if (rescue.getOwner().equals(player)) {
|
||||||
|
itemIterator.remove();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
Team deathTeam = this.getGame().getPlayerTeam(player);
|
||||||
|
if (BedwarsRel.getInstance().statisticsEnabled()) {
|
||||||
|
diePlayer = BedwarsRel.getInstance().getPlayerStatisticManager().getStatistic(player);
|
||||||
|
|
||||||
|
boolean onlyOnBedDestroy =
|
||||||
|
BedwarsRel.getInstance().getBooleanConfig("statistics.bed-destroyed-kills", false);
|
||||||
|
boolean teamIsDead = deathTeam.isDead(this.getGame());
|
||||||
|
|
||||||
|
if ((onlyOnBedDestroy && teamIsDead) || !onlyOnBedDestroy) {
|
||||||
|
diePlayer.setCurrentDeaths(diePlayer.getCurrentDeaths() + 1);
|
||||||
|
diePlayer.setCurrentScore(diePlayer.getCurrentScore() + BedwarsRel
|
||||||
|
.getInstance().getIntConfig("statistics.scores.die", 0));
|
||||||
|
}
|
||||||
|
|
||||||
|
if (killer != null) {
|
||||||
|
if ((onlyOnBedDestroy && teamIsDead) || !onlyOnBedDestroy) {
|
||||||
|
killerPlayer = BedwarsRel.getInstance().getPlayerStatisticManager().getStatistic(killer);
|
||||||
|
if (killerPlayer != null) {
|
||||||
|
killerPlayer.setCurrentKills(killerPlayer.getCurrentKills() + 1);
|
||||||
|
killerPlayer.setCurrentScore(killerPlayer.getCurrentScore() + BedwarsRel
|
||||||
|
.getInstance().getIntConfig("statistics.scores.kill", 10));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// dispatch reward commands directly
|
||||||
|
if (BedwarsRel.getInstance().getBooleanConfig("rewards.enabled", false) && killer != null
|
||||||
|
&& ((onlyOnBedDestroy && teamIsDead) || !onlyOnBedDestroy)) {
|
||||||
|
List<String> commands = BedwarsRel.getInstance().getConfig()
|
||||||
|
.getStringList("rewards.player-kill");
|
||||||
|
BedwarsRel.getInstance().dispatchRewardCommands(commands,
|
||||||
|
ImmutableMap.of("{player}", killer.getName(), "{score}",
|
||||||
|
String
|
||||||
|
.valueOf(BedwarsRel.getInstance().getIntConfig("statistics.scores.kill", 10))));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (killer == null) {
|
||||||
|
for (Player aPlayer : this.getGame().getPlayers()) {
|
||||||
|
if (aPlayer.isOnline()) {
|
||||||
|
aPlayer.sendMessage(
|
||||||
|
ChatWriter.pluginMessage(
|
||||||
|
ChatColor.GOLD + BedwarsRel._l(aPlayer, "ingame.player.died", ImmutableMap
|
||||||
|
.of("player",
|
||||||
|
Game.getPlayerWithTeamString(player, deathTeam, ChatColor.GOLD)))));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
this.sendTeamDeadMessage(deathTeam);
|
||||||
|
this.checkGameOver();
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
Team killerTeam = this.getGame().getPlayerTeam(killer);
|
||||||
|
if (killerTeam == null) {
|
||||||
|
for (Player aPlayer : this.getGame().getPlayers()) {
|
||||||
|
if (aPlayer.isOnline()) {
|
||||||
|
aPlayer.sendMessage(
|
||||||
|
ChatWriter.pluginMessage(
|
||||||
|
ChatColor.GOLD + BedwarsRel._l(aPlayer, "ingame.player.died", ImmutableMap
|
||||||
|
.of("player",
|
||||||
|
Game.getPlayerWithTeamString(player, deathTeam, ChatColor.GOLD)))));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
this.sendTeamDeadMessage(deathTeam);
|
||||||
|
this.checkGameOver();
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
String hearts = "";
|
||||||
|
DecimalFormat format = new DecimalFormat("#");
|
||||||
|
double health = ((double) killer.getHealth()) / ((double) killer.getMaxHealth())
|
||||||
|
* ((double) killer.getHealthScale());
|
||||||
|
if (!BedwarsRel.getInstance().getBooleanConfig("hearts-in-halfs", true)) {
|
||||||
|
format = new DecimalFormat("#.#");
|
||||||
|
health = health / 2;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (BedwarsRel.getInstance().getBooleanConfig("hearts-on-death", true)) {
|
||||||
|
hearts = "[" + ChatColor.RED + "\u2764" + format.format(health) + ChatColor.GOLD + "]";
|
||||||
|
}
|
||||||
|
|
||||||
|
for (Player aPlayer : this.getGame().getPlayers()) {
|
||||||
|
if (aPlayer.isOnline()) {
|
||||||
|
aPlayer.sendMessage(
|
||||||
|
ChatWriter.pluginMessage(ChatColor.GOLD + BedwarsRel._l(aPlayer, "ingame.player.killed",
|
||||||
|
ImmutableMap.of("killer",
|
||||||
|
Game.getPlayerWithTeamString(killer, killerTeam, ChatColor.GOLD, hearts),
|
||||||
|
"player",
|
||||||
|
Game.getPlayerWithTeamString(player, deathTeam, ChatColor.GOLD)))));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (deathTeam.isDead(this.getGame())) {
|
||||||
|
killer.playSound(killer.getLocation(), SoundMachine.get("LEVEL_UP", "ENTITY_PLAYER_LEVELUP"),
|
||||||
|
Float.valueOf("1.0"), Float.valueOf("1.0"));
|
||||||
|
}
|
||||||
|
this.sendTeamDeadMessage(deathTeam);
|
||||||
|
this.checkGameOver();
|
||||||
|
}
|
||||||
|
|
||||||
|
public abstract boolean onPlayerJoins(Player player);
|
||||||
|
|
||||||
|
public abstract void onPlayerLeave(Player player);
|
||||||
|
|
||||||
|
public void onPlayerRespawn(PlayerRespawnEvent pre, Player player) {
|
||||||
|
Team team = this.getGame().getPlayerTeam(player);
|
||||||
|
|
||||||
|
// reset damager
|
||||||
|
this.getGame().setPlayerDamager(player, null);
|
||||||
|
|
||||||
|
if (this.getGame().isSpectator(player)) {
|
||||||
|
Collection<Team> teams = this.getGame().getTeams().values();
|
||||||
|
pre.setRespawnLocation(
|
||||||
|
((Team) teams.toArray()[Utils.randInt(0, teams.size() - 1)]).getSpawnLocation());
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (team.isDead(this.getGame())) {
|
||||||
|
PlayerStorage storage = this.getGame().getPlayerStorage(player);
|
||||||
|
|
||||||
|
if (BedwarsRel.getInstance().statisticsEnabled()) {
|
||||||
|
PlayerStatistic statistic =
|
||||||
|
BedwarsRel.getInstance().getPlayerStatisticManager().getStatistic(player);
|
||||||
|
statistic.setCurrentLoses(statistic.getCurrentLoses() + 1);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (BedwarsRel.getInstance().spectationEnabled()) {
|
||||||
|
if (storage != null && storage.getLeft() != null) {
|
||||||
|
pre.setRespawnLocation(team.getSpawnLocation());
|
||||||
|
}
|
||||||
|
|
||||||
|
this.getGame().toSpectator(player);
|
||||||
|
} else {
|
||||||
|
if (this.game.getCycle() instanceof BungeeGameCycle) {
|
||||||
|
this.getGame().playerLeave(player, false);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!BedwarsRel.getInstance().toMainLobby()) {
|
||||||
|
if (storage != null) {
|
||||||
|
if (storage.getLeft() != null) {
|
||||||
|
pre.setRespawnLocation(storage.getLeft());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
if (this.getGame().getMainLobby() != null) {
|
||||||
|
pre.setRespawnLocation(this.getGame().getMainLobby());
|
||||||
|
} else {
|
||||||
|
if (storage != null) {
|
||||||
|
if (storage.getLeft() != null) {
|
||||||
|
pre.setRespawnLocation(storage.getLeft());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
this.getGame().playerLeave(player, false);
|
||||||
|
}
|
||||||
|
|
||||||
|
} else {
|
||||||
|
if (BedwarsRel.getInstance().getRespawnProtectionTime() > 0) {
|
||||||
|
RespawnProtectionRunnable protection = this.getGame().addProtection(player);
|
||||||
|
protection.runProtection();
|
||||||
|
}
|
||||||
|
pre.setRespawnLocation(team.getSpawnLocation());
|
||||||
|
}
|
||||||
|
|
||||||
|
new BukkitRunnable() {
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void run() {
|
||||||
|
GameCycle.this.checkGameOver();
|
||||||
|
}
|
||||||
|
}.runTaskLater(BedwarsRel.getInstance(), 20L);
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
@SuppressWarnings("unchecked")
|
||||||
|
private void runGameOver(Team winner) {
|
||||||
|
BedwarsGameOverEvent overEvent = new BedwarsGameOverEvent(this.getGame(), winner);
|
||||||
|
BedwarsRel.getInstance().getServer().getPluginManager().callEvent(overEvent);
|
||||||
|
|
||||||
|
if (overEvent.isCancelled()) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
this.getGame().stopWorkers();
|
||||||
|
this.setEndGameRunning(true);
|
||||||
|
|
||||||
|
// new record?
|
||||||
|
boolean storeRecords = BedwarsRel.getInstance().getBooleanConfig("store-game-records", true);
|
||||||
|
boolean storeHolders = BedwarsRel
|
||||||
|
.getInstance().getBooleanConfig("store-game-records-holder", true);
|
||||||
|
boolean madeRecord = false;
|
||||||
|
if (storeRecords && winner != null) {
|
||||||
|
madeRecord = this.storeRecords(storeHolders, winner);
|
||||||
|
}
|
||||||
|
|
||||||
|
int delay = BedwarsRel.getInstance().getConfig().getInt("gameoverdelay"); // configurable
|
||||||
|
// delay
|
||||||
|
|
||||||
|
if (BedwarsRel.getInstance().statisticsEnabled()
|
||||||
|
|| BedwarsRel.getInstance().getBooleanConfig("rewards.enabled", false)
|
||||||
|
|| (BedwarsRel.getInstance().getBooleanConfig("titles.win.enabled", true))) {
|
||||||
|
if (winner != null) {
|
||||||
|
for (Player player : winner.getPlayers()) {
|
||||||
|
String title = this
|
||||||
|
.winTitleReplace(BedwarsRel._l(player, "ingame.title.win-title"), winner);
|
||||||
|
String subtitle = this
|
||||||
|
.winTitleReplace(BedwarsRel._l(player, "ingame.title.win-subtitle"), winner);
|
||||||
|
if (!"".equals(title) || !"".equals(subtitle)) {
|
||||||
|
if (BedwarsRel.getInstance().getBooleanConfig("titles.win.enabled", true)
|
||||||
|
&& (!"".equals(title) || !"".equals(subtitle))) {
|
||||||
|
try {
|
||||||
|
Class<?> clazz = Class.forName("io.github.bedwarsrel.com."
|
||||||
|
+ BedwarsRel.getInstance().getCurrentVersion().toLowerCase() + ".Title");
|
||||||
|
|
||||||
|
if (!"".equals(title)) {
|
||||||
|
double titleFadeIn =
|
||||||
|
BedwarsRel.getInstance().getConfig()
|
||||||
|
.getDouble("titles.win.title-fade-in", 1.5);
|
||||||
|
double titleStay =
|
||||||
|
BedwarsRel.getInstance().getConfig().getDouble("titles.win.title-stay", 5.0);
|
||||||
|
double titleFadeOut =
|
||||||
|
BedwarsRel
|
||||||
|
.getInstance().getConfig().getDouble("titles.win.title-fade-out", 2.0);
|
||||||
|
Method showTitle = clazz
|
||||||
|
.getDeclaredMethod("showTitle", Player.class, String.class,
|
||||||
|
double.class, double.class, double.class);
|
||||||
|
|
||||||
|
showTitle.invoke(null, player, title, titleFadeIn, titleStay, titleFadeOut);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!"".equals(subtitle)) {
|
||||||
|
double subTitleFadeIn =
|
||||||
|
BedwarsRel
|
||||||
|
.getInstance().getConfig().getDouble("titles.win.subtitle-fade-in", 1.5);
|
||||||
|
double subTitleStay =
|
||||||
|
BedwarsRel.getInstance().getConfig()
|
||||||
|
.getDouble("titles.win.subtitle-stay", 5.0);
|
||||||
|
double subTitleFadeOut =
|
||||||
|
BedwarsRel
|
||||||
|
.getInstance().getConfig().getDouble("titles.win.subtitle-fade-out", 2.0);
|
||||||
|
Method showSubTitle = clazz.getDeclaredMethod("showSubTitle", Player.class,
|
||||||
|
String.class, double.class, double.class, double.class);
|
||||||
|
|
||||||
|
showSubTitle.invoke(null, player, subtitle, subTitleFadeIn, subTitleStay,
|
||||||
|
subTitleFadeOut);
|
||||||
|
}
|
||||||
|
} catch (Exception ex) {
|
||||||
|
BedwarsRel.getInstance().getBugsnag().notify(ex);
|
||||||
|
ex.printStackTrace();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (BedwarsRel.getInstance().getBooleanConfig("rewards.enabled", false)) {
|
||||||
|
List<String> commands = new ArrayList<String>();
|
||||||
|
commands = (List<String>) BedwarsRel.getInstance().getConfig()
|
||||||
|
.getList("rewards.player-win");
|
||||||
|
BedwarsRel.getInstance()
|
||||||
|
.dispatchRewardCommands(commands, this.getRewardPlaceholders(player));
|
||||||
|
}
|
||||||
|
|
||||||
|
if (BedwarsRel.getInstance().statisticsEnabled()) {
|
||||||
|
PlayerStatistic statistic =
|
||||||
|
BedwarsRel.getInstance().getPlayerStatisticManager().getStatistic(player);
|
||||||
|
statistic.setCurrentWins(statistic.getCurrentWins() + 1);
|
||||||
|
statistic.setCurrentScore(statistic.getCurrentScore() + BedwarsRel
|
||||||
|
.getInstance().getIntConfig("statistics.scores.win", 50));
|
||||||
|
|
||||||
|
if (madeRecord) {
|
||||||
|
statistic.setCurrentScore(statistic.getCurrentScore() +
|
||||||
|
BedwarsRel.getInstance().getIntConfig("statistics.scores.record", 100));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
for (Player player : this.game.getPlayers()) {
|
||||||
|
if (this.game.isSpectator(player)) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (BedwarsRel.getInstance().getBooleanConfig("rewards.enabled", false)) {
|
||||||
|
List<String> commands = new ArrayList<String>();
|
||||||
|
commands =
|
||||||
|
(List<String>) BedwarsRel.getInstance().getConfig()
|
||||||
|
.getList("rewards.player-end-game");
|
||||||
|
BedwarsRel.getInstance()
|
||||||
|
.dispatchRewardCommands(commands, this.getRewardPlaceholders(player));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
this.getGame().getPlayingTeams().clear();
|
||||||
|
|
||||||
|
GameOverTask gameOver = new GameOverTask(this, delay, winner);
|
||||||
|
gameOver.runTaskTimer(BedwarsRel.getInstance(), 0L, 20L);
|
||||||
|
}
|
||||||
|
|
||||||
|
private void sendTeamDeadMessage(Team deathTeam) {
|
||||||
|
if (deathTeam.getPlayers().size() == 1 && deathTeam.isDead(this.getGame())) {
|
||||||
|
for (Player aPlayer : this.getGame().getPlayers()) {
|
||||||
|
if (aPlayer.isOnline()) {
|
||||||
|
aPlayer.sendMessage(
|
||||||
|
ChatWriter.pluginMessage(
|
||||||
|
ChatColor.RED + BedwarsRel._l(aPlayer, "ingame.team-dead", ImmutableMap.of("team",
|
||||||
|
deathTeam.getChatColor() + deathTeam.getDisplayName() + ChatColor.RED))));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private boolean storeRecords(boolean storeHolders, Team winner) {
|
||||||
|
int playTime = this.getGame().getLength() - this.getGame().getTimeLeft();
|
||||||
|
boolean throughBed = false;
|
||||||
|
|
||||||
|
if (playTime <= this.getGame().getRecord()) {
|
||||||
|
|
||||||
|
// check for winning through bed destroy
|
||||||
|
for (Team team : this.getGame().getPlayingTeams()) {
|
||||||
|
if (team.isDead(this.getGame())) {
|
||||||
|
throughBed = true;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!throughBed) {
|
||||||
|
for (Player aPlayer : this.getGame().getPlayers()) {
|
||||||
|
if (aPlayer.isOnline()) {
|
||||||
|
aPlayer.sendMessage(
|
||||||
|
ChatWriter.pluginMessage(BedwarsRel._l(aPlayer, "ingame.record-nobeddestroy")));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (storeHolders) {
|
||||||
|
if (playTime < this.getGame().getRecord()) {
|
||||||
|
this.getGame().getRecordHolders().clear();
|
||||||
|
}
|
||||||
|
|
||||||
|
for (Player player : winner.getPlayers()) {
|
||||||
|
this.getGame().addRecordHolder(player.getName());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
this.getGame().setRecord(playTime);
|
||||||
|
this.getGame().saveRecord();
|
||||||
|
|
||||||
|
for (Player aPlayer : this.getGame().getPlayers()) {
|
||||||
|
if (aPlayer.isOnline()) {
|
||||||
|
aPlayer.sendMessage(
|
||||||
|
ChatWriter.pluginMessage(BedwarsRel._l(aPlayer, "ingame.newrecord",
|
||||||
|
ImmutableMap.of("record", this.getGame().getFormattedRecord(), "team",
|
||||||
|
winner.getChatColor() + winner.getDisplayName()))));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
private String winTitleReplace(String str, Team winner) {
|
||||||
|
int playTime = this.getGame().getLength() - this.getGame().getTimeLeft();
|
||||||
|
String finalStr = str;
|
||||||
|
String formattedTime = Utils.getFormattedTime(playTime);
|
||||||
|
|
||||||
|
finalStr = finalStr.replace("$time$", formattedTime);
|
||||||
|
|
||||||
|
if (winner == null) {
|
||||||
|
return finalStr;
|
||||||
|
}
|
||||||
|
|
||||||
|
finalStr = finalStr.replace("$team$", winner.getChatColor() + winner.getDisplayName());
|
||||||
|
return finalStr;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
119
common/src/main/java/io/github/bedwarsrel/game/GameJoinSign.java
Normal file
119
common/src/main/java/io/github/bedwarsrel/game/GameJoinSign.java
Normal file
@@ -0,0 +1,119 @@
|
|||||||
|
package io.github.bedwarsrel.game;
|
||||||
|
|
||||||
|
import io.github.bedwarsrel.BedwarsRel;
|
||||||
|
import org.bukkit.ChatColor;
|
||||||
|
import org.bukkit.Location;
|
||||||
|
import org.bukkit.block.BlockState;
|
||||||
|
import org.bukkit.block.Sign;
|
||||||
|
|
||||||
|
public class GameJoinSign {
|
||||||
|
|
||||||
|
private Game game = null;
|
||||||
|
private Location signLocation = null;
|
||||||
|
|
||||||
|
public GameJoinSign(Game game, Location sign) {
|
||||||
|
this.game = game;
|
||||||
|
this.signLocation = sign;
|
||||||
|
}
|
||||||
|
|
||||||
|
private String getCurrentPlayersString() {
|
||||||
|
int maxPlayers = this.game.getMaxPlayers();
|
||||||
|
int currentPlayers = 0;
|
||||||
|
if (this.game.getState() == GameState.RUNNING) {
|
||||||
|
currentPlayers = this.game.getTeamPlayers().size();
|
||||||
|
} else if (this.game.getState() == GameState.WAITING) {
|
||||||
|
currentPlayers = this.game.getPlayers().size();
|
||||||
|
} else {
|
||||||
|
currentPlayers = 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
String current = "0";
|
||||||
|
if (currentPlayers >= maxPlayers) {
|
||||||
|
current = ChatColor.RED + String.valueOf(currentPlayers) + ChatColor.WHITE;
|
||||||
|
} else {
|
||||||
|
current = String.valueOf(currentPlayers);
|
||||||
|
}
|
||||||
|
|
||||||
|
return current;
|
||||||
|
}
|
||||||
|
|
||||||
|
private String getMaxPlayersString() {
|
||||||
|
int maxPlayers = this.game.getMaxPlayers();
|
||||||
|
int currentPlayers = 0;
|
||||||
|
if (this.game.getState() == GameState.RUNNING) {
|
||||||
|
currentPlayers = this.game.getTeamPlayers().size();
|
||||||
|
} else if (this.game.getState() == GameState.WAITING) {
|
||||||
|
currentPlayers = this.game.getPlayers().size();
|
||||||
|
} else {
|
||||||
|
currentPlayers = 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
String max = String.valueOf(maxPlayers);
|
||||||
|
|
||||||
|
if (currentPlayers >= maxPlayers) {
|
||||||
|
max = ChatColor.RED + max + ChatColor.WHITE;
|
||||||
|
}
|
||||||
|
|
||||||
|
return max;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Sign getSign() {
|
||||||
|
BlockState state = this.signLocation.getBlock().getState();
|
||||||
|
|
||||||
|
if (!(state instanceof Sign)) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
return (Sign) state;
|
||||||
|
}
|
||||||
|
|
||||||
|
private String[] getSignLines() {
|
||||||
|
String[] sign = new String[4];
|
||||||
|
sign[0] = this.replacePlaceholder(ChatColor.translateAlternateColorCodes('&',
|
||||||
|
BedwarsRel.getInstance().getConfig().getString("sign.first-line")));
|
||||||
|
sign[1] = this.replacePlaceholder(ChatColor.translateAlternateColorCodes('&',
|
||||||
|
BedwarsRel.getInstance().getConfig().getString("sign.second-line")));
|
||||||
|
sign[2] = this.replacePlaceholder(ChatColor.translateAlternateColorCodes('&',
|
||||||
|
BedwarsRel.getInstance().getConfig().getString("sign.third-line")));
|
||||||
|
sign[3] = this.replacePlaceholder(ChatColor.translateAlternateColorCodes('&',
|
||||||
|
BedwarsRel.getInstance().getConfig().getString("sign.fourth-line")));
|
||||||
|
|
||||||
|
return sign;
|
||||||
|
}
|
||||||
|
|
||||||
|
private String getStatus() {
|
||||||
|
String status = null;
|
||||||
|
if (this.game.getState() == GameState.WAITING && this.game.isFull()) {
|
||||||
|
status = ChatColor.RED + BedwarsRel._l("sign.gamestate.full");
|
||||||
|
} else {
|
||||||
|
status = BedwarsRel._l("sign.gamestate." + this.game.getState().toString().toLowerCase());
|
||||||
|
}
|
||||||
|
|
||||||
|
return status;
|
||||||
|
}
|
||||||
|
|
||||||
|
private String replacePlaceholder(String line) {
|
||||||
|
String finalLine = line;
|
||||||
|
|
||||||
|
finalLine = finalLine.replace("$title$", BedwarsRel._l("sign.firstline"));
|
||||||
|
finalLine = finalLine.replace("$gamename$", this.game.getName());
|
||||||
|
finalLine = finalLine.replace("$regionname$", this.game.getRegion().getName());
|
||||||
|
finalLine = finalLine.replace("$maxplayers$", this.getMaxPlayersString());
|
||||||
|
finalLine = finalLine.replace("$currentplayers$", this.getCurrentPlayersString());
|
||||||
|
finalLine = finalLine.replace("$status$", this.getStatus());
|
||||||
|
|
||||||
|
return finalLine;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void updateSign() {
|
||||||
|
Sign sign = (Sign) this.signLocation.getBlock().getState();
|
||||||
|
|
||||||
|
String[] signLines = this.getSignLines();
|
||||||
|
for (int i = 0; i < signLines.length; i++) {
|
||||||
|
sign.setLine(i, signLines[i]);
|
||||||
|
}
|
||||||
|
|
||||||
|
sign.update(true, true);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
@@ -0,0 +1,193 @@
|
|||||||
|
package io.github.bedwarsrel.game;
|
||||||
|
|
||||||
|
import com.google.common.collect.ImmutableMap;
|
||||||
|
import io.github.bedwarsrel.BedwarsRel;
|
||||||
|
import io.github.bedwarsrel.utils.ChatWriter;
|
||||||
|
import io.github.bedwarsrel.utils.SoundMachine;
|
||||||
|
import java.lang.reflect.Method;
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import lombok.Getter;
|
||||||
|
import lombok.Setter;
|
||||||
|
import org.bukkit.ChatColor;
|
||||||
|
import org.bukkit.Material;
|
||||||
|
import org.bukkit.entity.Player;
|
||||||
|
import org.bukkit.scheduler.BukkitRunnable;
|
||||||
|
|
||||||
|
public class GameLobbyCountdown extends BukkitRunnable {
|
||||||
|
|
||||||
|
@Getter
|
||||||
|
@Setter
|
||||||
|
private int counter = 0;
|
||||||
|
private Game game = null;
|
||||||
|
@Getter
|
||||||
|
private int lobbytime;
|
||||||
|
@Getter
|
||||||
|
private int lobbytimeWhenFull;
|
||||||
|
|
||||||
|
public GameLobbyCountdown(Game game) {
|
||||||
|
this.game = game;
|
||||||
|
this.counter = BedwarsRel.getInstance().getConfig().getInt("lobbytime");
|
||||||
|
this.lobbytime = this.counter;
|
||||||
|
this.lobbytimeWhenFull = BedwarsRel.getInstance().getConfig().getInt("lobbytime-full");
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void run() {
|
||||||
|
ArrayList<Player> players = this.game.getPlayers();
|
||||||
|
float xpPerLevel = 1.0F / this.lobbytime;
|
||||||
|
|
||||||
|
if (this.game.getState() != GameState.WAITING) {
|
||||||
|
this.game.setGameLobbyCountdown(null);
|
||||||
|
this.cancel();
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (this.counter > this.lobbytimeWhenFull
|
||||||
|
&& this.game.getPlayerAmount() == this.game.getMaxPlayers()) {
|
||||||
|
this.counter = this.lobbytimeWhenFull;
|
||||||
|
for (Player aPlayer : players) {
|
||||||
|
if (aPlayer.isOnline()) {
|
||||||
|
aPlayer.sendMessage(ChatWriter.pluginMessage(ChatColor.YELLOW
|
||||||
|
+ BedwarsRel
|
||||||
|
._l(aPlayer, "lobby.countdown",
|
||||||
|
ImmutableMap.of("sec",
|
||||||
|
ChatColor.RED.toString() + this.counter + ChatColor.YELLOW))));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (this.counter == this.lobbytimeWhenFull) {
|
||||||
|
for (Player p : players) {
|
||||||
|
if (p.getInventory().contains(Material.EMERALD)) {
|
||||||
|
p.getInventory().remove(Material.EMERALD);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
for (Player p : players) {
|
||||||
|
p.setLevel(this.counter);
|
||||||
|
if (this.counter == this.lobbytime) {
|
||||||
|
p.setExp(1.0F);
|
||||||
|
} else {
|
||||||
|
p.setExp(1.0F - (xpPerLevel * (this.lobbytime - this.counter)));
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
if (this.counter == this.lobbytime) {
|
||||||
|
for (Player aPlayer : players) {
|
||||||
|
if (aPlayer.isOnline()) {
|
||||||
|
aPlayer.sendMessage(ChatWriter.pluginMessage(ChatColor.YELLOW
|
||||||
|
+ BedwarsRel
|
||||||
|
._l(aPlayer, "lobby.countdown",
|
||||||
|
ImmutableMap.of("sec",
|
||||||
|
ChatColor.RED.toString() + this.counter + ChatColor.YELLOW))));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
for (Player p : players) {
|
||||||
|
if (!p.getInventory().contains(Material.DIAMOND) && p.hasPermission("bw.vip.forcestart")) {
|
||||||
|
this.game.getPlayerStorage(p).addGameStartItem();
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!p.getInventory().contains(Material.EMERALD) && (p.isOp() || p.hasPermission("bw.setup")
|
||||||
|
|| p.hasPermission("bw.vip.reducecountdown"))) {
|
||||||
|
this.game.getPlayerStorage(p).addReduceCountdownItem();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!this.game.isStartable()) {
|
||||||
|
if (!this.game.hasEnoughPlayers()) {
|
||||||
|
for (Player aPlayer : players) {
|
||||||
|
if (aPlayer.isOnline()) {
|
||||||
|
aPlayer.sendMessage(ChatWriter.pluginMessage(
|
||||||
|
ChatColor.RED + BedwarsRel
|
||||||
|
._l(aPlayer, "lobby.cancelcountdown.not_enough_players")));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} else if (!this.game.hasEnoughTeams()) {
|
||||||
|
for (Player aPlayer : players) {
|
||||||
|
if (aPlayer.isOnline()) {
|
||||||
|
aPlayer.sendMessage(ChatWriter.pluginMessage(
|
||||||
|
ChatColor.RED + BedwarsRel._l(aPlayer, "lobby.cancelcountdown.not_enough_teams")));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
this.counter = this.lobbytime;
|
||||||
|
for (Player p : players) {
|
||||||
|
p.setLevel(0);
|
||||||
|
p.setExp(0.0F);
|
||||||
|
if (p.getInventory().contains(Material.EMERALD)) {
|
||||||
|
p.getInventory().remove(Material.EMERALD);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
this.game.setGameLobbyCountdown(null);
|
||||||
|
this.cancel();
|
||||||
|
}
|
||||||
|
|
||||||
|
if (this.counter <= 10 && this.counter > 0) {
|
||||||
|
for (Player aPlayer : players) {
|
||||||
|
if (aPlayer.isOnline()) {
|
||||||
|
aPlayer.sendMessage(ChatWriter.pluginMessage(ChatColor.YELLOW
|
||||||
|
+ BedwarsRel
|
||||||
|
._l(aPlayer, "lobby.countdown",
|
||||||
|
ImmutableMap.of("sec",
|
||||||
|
ChatColor.RED.toString() + this.counter + ChatColor.YELLOW))));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
Class<?> titleClass = null;
|
||||||
|
Method showTitle = null;
|
||||||
|
String title = ChatColor.translateAlternateColorCodes('&',
|
||||||
|
BedwarsRel.getInstance().getStringConfig("titles.countdown.format", "&3{countdown}"));
|
||||||
|
title = title.replace("{countdown}", String.valueOf(this.counter));
|
||||||
|
|
||||||
|
if (BedwarsRel.getInstance().getBooleanConfig("titles.countdown.enabled", true)) {
|
||||||
|
try {
|
||||||
|
titleClass = BedwarsRel.getInstance().getVersionRelatedClass("Title");
|
||||||
|
showTitle = titleClass.getMethod("showTitle", Player.class, String.class, double.class,
|
||||||
|
double.class, double.class);
|
||||||
|
} catch (Exception ex) {
|
||||||
|
BedwarsRel.getInstance().getBugsnag().notify(ex);
|
||||||
|
ex.printStackTrace();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
for (Player player : players) {
|
||||||
|
player.playSound(player.getLocation(), SoundMachine.get("CLICK", "UI_BUTTON_CLICK"),
|
||||||
|
Float.valueOf("1.0"), Float.valueOf("1.0"));
|
||||||
|
|
||||||
|
if (titleClass == null) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
try {
|
||||||
|
showTitle.invoke(null, player, title, 0.2, 0.6, 0.2);
|
||||||
|
} catch (Exception ex) {
|
||||||
|
BedwarsRel.getInstance().getBugsnag().notify(ex);
|
||||||
|
ex.printStackTrace();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (this.counter == 0) {
|
||||||
|
this.game.setGameLobbyCountdown(null);
|
||||||
|
this.cancel();
|
||||||
|
for (Player player : players) {
|
||||||
|
player.playSound(player.getLocation(),
|
||||||
|
SoundMachine.get("LEVEL_UP", "ENTITY_PLAYER_LEVELUP"), Float.valueOf("1.0"),
|
||||||
|
Float.valueOf("1.0"));
|
||||||
|
player.setLevel(0);
|
||||||
|
player.setExp(0.0F);
|
||||||
|
}
|
||||||
|
|
||||||
|
this.game.start(BedwarsRel.getInstance().getServer().getConsoleSender());
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
this.counter--;
|
||||||
|
}
|
||||||
|
}
|
||||||
382
common/src/main/java/io/github/bedwarsrel/game/GameManager.java
Normal file
382
common/src/main/java/io/github/bedwarsrel/game/GameManager.java
Normal file
@@ -0,0 +1,382 @@
|
|||||||
|
package io.github.bedwarsrel.game;
|
||||||
|
|
||||||
|
import com.google.common.collect.ImmutableMap;
|
||||||
|
import io.github.bedwarsrel.BedwarsRel;
|
||||||
|
import io.github.bedwarsrel.utils.ChatWriter;
|
||||||
|
import io.github.bedwarsrel.utils.Utils;
|
||||||
|
import java.io.File;
|
||||||
|
import java.io.FileFilter;
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.HashMap;
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.Map;
|
||||||
|
import org.bukkit.ChatColor;
|
||||||
|
import org.bukkit.Location;
|
||||||
|
import org.bukkit.World;
|
||||||
|
import org.bukkit.block.Block;
|
||||||
|
import org.bukkit.block.Sign;
|
||||||
|
import org.bukkit.configuration.file.YamlConfiguration;
|
||||||
|
import org.bukkit.entity.Player;
|
||||||
|
|
||||||
|
public class GameManager {
|
||||||
|
|
||||||
|
public static String gamesPath = "games";
|
||||||
|
private Map<Player, Game> gamePlayer = null;
|
||||||
|
private ArrayList<Game> games = null;
|
||||||
|
|
||||||
|
public GameManager() {
|
||||||
|
this.games = new ArrayList<Game>();
|
||||||
|
this.gamePlayer = new HashMap<Player, Game>();
|
||||||
|
}
|
||||||
|
|
||||||
|
public Game addGame(String name) {
|
||||||
|
Game existing = this.getGame(name);
|
||||||
|
if (existing != null) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
Game newGame = new Game(name);
|
||||||
|
this.games.add(newGame);
|
||||||
|
return newGame;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void addGamePlayer(Player player, Game game) {
|
||||||
|
if (this.gamePlayer.containsKey(player)) {
|
||||||
|
this.gamePlayer.remove(player);
|
||||||
|
}
|
||||||
|
|
||||||
|
this.gamePlayer.put(player, game);
|
||||||
|
}
|
||||||
|
|
||||||
|
public Game getGame(String name) {
|
||||||
|
for (Game game : this.games) {
|
||||||
|
if (game.getName().equals(name)) {
|
||||||
|
return game;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Game getGameByChunkLocation(int x, int z) {
|
||||||
|
for (Game game : this.games) {
|
||||||
|
if (game.getRegion().chunkIsInRegion(x, z)) {
|
||||||
|
return game;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Game getGameByLocation(Location loc) {
|
||||||
|
for (Game game : this.games) {
|
||||||
|
if (game.getRegion() == null) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (game.getRegion().getWorld() == null) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (game.getRegion().isInRegion(loc)) {
|
||||||
|
return game;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Game getGameBySignLocation(Location location) {
|
||||||
|
for (Game game : this.games) {
|
||||||
|
if (game.getSigns().containsKey(location)) {
|
||||||
|
return game;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Game getGameOfPlayer(Player player) {
|
||||||
|
return this.gamePlayer.get(player);
|
||||||
|
}
|
||||||
|
|
||||||
|
public int getGamePlayerAmount() {
|
||||||
|
return this.gamePlayer.size();
|
||||||
|
}
|
||||||
|
|
||||||
|
public ArrayList<Game> getGames() {
|
||||||
|
return this.games;
|
||||||
|
}
|
||||||
|
|
||||||
|
public List<Game> getGamesByWorld(World world) {
|
||||||
|
List<Game> games = new ArrayList<Game>();
|
||||||
|
|
||||||
|
for (Game game : this.games) {
|
||||||
|
if (game.getRegion() == null) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (game.getRegion().getWorld() == null) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (game.getRegion().getWorld().equals(world)) {
|
||||||
|
games.add(game);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return games;
|
||||||
|
}
|
||||||
|
|
||||||
|
@SuppressWarnings("unchecked")
|
||||||
|
private void loadGame(File configFile) {
|
||||||
|
try {
|
||||||
|
|
||||||
|
YamlConfiguration cfg = YamlConfiguration.loadConfiguration(configFile);
|
||||||
|
String name = cfg.get("name").toString();
|
||||||
|
if (name.isEmpty()) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
Game game = new Game(name);
|
||||||
|
game.setConfig(cfg);
|
||||||
|
|
||||||
|
Map<String, Object> teams = new HashMap<String, Object>();
|
||||||
|
Map<String, Object> spawner = new HashMap<String, Object>();
|
||||||
|
String targetMaterialObj = null;
|
||||||
|
|
||||||
|
if (cfg.contains("teams")) {
|
||||||
|
teams = cfg.getConfigurationSection("teams").getValues(false);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (cfg.contains("spawner")) {
|
||||||
|
if (cfg.isConfigurationSection("spawner")) {
|
||||||
|
spawner = cfg.getConfigurationSection("spawner").getValues(false);
|
||||||
|
|
||||||
|
for (Object obj : spawner.values()) {
|
||||||
|
if (!(obj instanceof ResourceSpawner)) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
ResourceSpawner rs = (ResourceSpawner) obj;
|
||||||
|
rs.setGame(game);
|
||||||
|
game.addResourceSpawner(rs);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (cfg.isList("spawner")) {
|
||||||
|
for (Object rs : cfg.getList("spawner")) {
|
||||||
|
if (!(rs instanceof ResourceSpawner)) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
ResourceSpawner rsp = (ResourceSpawner) rs;
|
||||||
|
rsp.setGame(game);
|
||||||
|
game.addResourceSpawner(rsp);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
for (Object obj : teams.values()) {
|
||||||
|
if (!(obj instanceof Team)) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
game.addTeam((Team) obj);
|
||||||
|
}
|
||||||
|
|
||||||
|
Location loc1 = Utils.locationDeserialize(cfg.get("loc1"));
|
||||||
|
Location loc2 = Utils.locationDeserialize(cfg.get("loc2"));
|
||||||
|
|
||||||
|
File signFile = new File(BedwarsRel.getInstance().getDataFolder() + File.separator
|
||||||
|
+ GameManager.gamesPath + File.separator + game.getName(), "sign.yml");
|
||||||
|
if (signFile.exists()) {
|
||||||
|
YamlConfiguration signConfig = YamlConfiguration.loadConfiguration(signFile);
|
||||||
|
|
||||||
|
List<Object> signs = (List<Object>) signConfig.get("signs");
|
||||||
|
for (Object sign : signs) {
|
||||||
|
Location signLocation = Utils.locationDeserialize(sign);
|
||||||
|
if (signLocation == null) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
signLocation.getChunk().load(true);
|
||||||
|
|
||||||
|
Block signBlock = signLocation.getBlock();
|
||||||
|
if (!(signBlock.getState() instanceof Sign)) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
signBlock.getState().update(true, true);
|
||||||
|
game.addJoinSign(signBlock.getLocation());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
game.setLoc(loc1, "loc1");
|
||||||
|
game.setLoc(loc2, "loc2");
|
||||||
|
game.setLobby(Utils.locationDeserialize(cfg.get("lobby")));
|
||||||
|
|
||||||
|
String regionName = "";
|
||||||
|
|
||||||
|
if (loc1.getWorld() != null) {
|
||||||
|
regionName = loc1.getWorld().getName();
|
||||||
|
}
|
||||||
|
|
||||||
|
if (cfg.contains("regionname")) {
|
||||||
|
regionName = cfg.getString("regionname");
|
||||||
|
}
|
||||||
|
|
||||||
|
if (cfg.contains("time") && cfg.isInt("time")) {
|
||||||
|
game.setTime(cfg.getInt("time"));
|
||||||
|
}
|
||||||
|
|
||||||
|
game.setRegionName(regionName);
|
||||||
|
game.setRegion(new Region(loc1, loc2, regionName));
|
||||||
|
|
||||||
|
if (cfg.contains("autobalance")) {
|
||||||
|
game.setAutobalance(cfg.getBoolean("autobalance"));
|
||||||
|
}
|
||||||
|
|
||||||
|
if (cfg.contains("minplayers")) {
|
||||||
|
game.setMinPlayers(cfg.getInt("minplayers"));
|
||||||
|
}
|
||||||
|
|
||||||
|
if (cfg.contains("mainlobby")) {
|
||||||
|
game.setMainLobby(Utils.locationDeserialize(cfg.get("mainlobby")));
|
||||||
|
}
|
||||||
|
|
||||||
|
if (cfg.contains("record")) {
|
||||||
|
game.setRecord(cfg.getInt("record", BedwarsRel.getInstance().getMaxLength()));
|
||||||
|
}
|
||||||
|
|
||||||
|
if (cfg.contains("targetmaterial")) {
|
||||||
|
targetMaterialObj = cfg.getString("targetmaterial");
|
||||||
|
if (targetMaterialObj != null && !targetMaterialObj.equals("")) {
|
||||||
|
game.setTargetMaterial(Utils.parseMaterial(targetMaterialObj));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (cfg.contains("builder")) {
|
||||||
|
game.setBuilder(cfg.getString("builder"));
|
||||||
|
}
|
||||||
|
|
||||||
|
if (cfg.contains("record-holders")) {
|
||||||
|
List<Object> list = (List<Object>) cfg.getList("record-holders", new ArrayList<Object>());
|
||||||
|
for (Object holder : list) {
|
||||||
|
game.addRecordHolder(holder.toString());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
game.getFreePlayers().clear();
|
||||||
|
game.updateSigns();
|
||||||
|
|
||||||
|
this.games.add(game);
|
||||||
|
BedwarsRel.getInstance().getServer().getConsoleSender()
|
||||||
|
.sendMessage(ChatWriter.pluginMessage(ChatColor.GREEN + BedwarsRel
|
||||||
|
._l(BedwarsRel.getInstance().getServer().getConsoleSender(), "success.gameloaded",
|
||||||
|
ImmutableMap.of("game", game.getRegion().getName()))));
|
||||||
|
} catch (Exception ex) {
|
||||||
|
BedwarsRel.getInstance().getBugsnag().notify(ex);
|
||||||
|
BedwarsRel.getInstance().getServer().getConsoleSender()
|
||||||
|
.sendMessage(ChatWriter.pluginMessage(ChatColor.RED + BedwarsRel
|
||||||
|
._l(BedwarsRel.getInstance().getServer().getConsoleSender(), "errors.gameloaderror",
|
||||||
|
ImmutableMap.of("game", configFile.getParentFile().getName()))));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public void loadGames() {
|
||||||
|
String path = BedwarsRel.getInstance().getDataFolder() + File.separator + GameManager.gamesPath;
|
||||||
|
File file = new File(path);
|
||||||
|
|
||||||
|
if (!file.exists()) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
File[] files = file.listFiles(new FileFilter() {
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean accept(File pathname) {
|
||||||
|
return pathname.isDirectory();
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
if (files.length > 0) {
|
||||||
|
for (File dir : files) {
|
||||||
|
File[] configFiles = dir.listFiles();
|
||||||
|
for (File cfg : configFiles) {
|
||||||
|
if (!cfg.isFile()) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (cfg.getName().equals("game.yml")) {
|
||||||
|
this.loadGame(cfg);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
for (Game g : this.games) {
|
||||||
|
if (!g.run(BedwarsRel.getInstance().getServer().getConsoleSender())) {
|
||||||
|
BedwarsRel.getInstance().getServer().getConsoleSender()
|
||||||
|
.sendMessage(ChatWriter.pluginMessage(ChatColor.RED + BedwarsRel
|
||||||
|
._l(BedwarsRel.getInstance().getServer().getConsoleSender(),
|
||||||
|
"errors.gamenotloaded")));
|
||||||
|
} else {
|
||||||
|
g.getCycle().onGameLoaded();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public void reloadGames() {
|
||||||
|
this.unloadGames();
|
||||||
|
|
||||||
|
this.gamePlayer.clear();
|
||||||
|
this.loadGames();
|
||||||
|
}
|
||||||
|
|
||||||
|
public void removeGame(Game game) {
|
||||||
|
if (game == null) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
File configs = new File(BedwarsRel.getInstance().getDataFolder() + File.separator
|
||||||
|
+ GameManager.gamesPath + File.separator + game.getName());
|
||||||
|
|
||||||
|
if (configs.exists()) {
|
||||||
|
configs.delete();
|
||||||
|
}
|
||||||
|
|
||||||
|
this.games.remove(game);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void removeGamePlayer(Player player) {
|
||||||
|
this.gamePlayer.remove(player);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void unloadGame(Game game) {
|
||||||
|
if (game.getState() != GameState.STOPPED) {
|
||||||
|
game.stop();
|
||||||
|
}
|
||||||
|
|
||||||
|
game.setState(GameState.STOPPED);
|
||||||
|
game.setScoreboard(BedwarsRel.getInstance().getScoreboardManager().getNewScoreboard());
|
||||||
|
|
||||||
|
try {
|
||||||
|
game.kickAllPlayers();
|
||||||
|
} catch (Exception e) {
|
||||||
|
BedwarsRel.getInstance().getBugsnag().notify(e);
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
|
game.resetRegion();
|
||||||
|
game.updateSigns();
|
||||||
|
}
|
||||||
|
|
||||||
|
public void unloadGames() {
|
||||||
|
for (Game g : this.games) {
|
||||||
|
this.unloadGame(g);
|
||||||
|
}
|
||||||
|
|
||||||
|
this.games.clear();
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
@@ -0,0 +1,48 @@
|
|||||||
|
package io.github.bedwarsrel.game;
|
||||||
|
|
||||||
|
import org.bukkit.scheduler.BukkitRunnable;
|
||||||
|
|
||||||
|
public class GameOverTask extends BukkitRunnable {
|
||||||
|
|
||||||
|
private int counter = 10;
|
||||||
|
private int counterStart = 10;
|
||||||
|
private GameCycle cycle = null;
|
||||||
|
private Team winner = null;
|
||||||
|
|
||||||
|
public GameOverTask(GameCycle cycle, int counter, Team winner) {
|
||||||
|
this.counterStart = counter;
|
||||||
|
this.counter = counter;
|
||||||
|
this.cycle = cycle;
|
||||||
|
this.winner = winner;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void decCounter() {
|
||||||
|
this.counter--;
|
||||||
|
}
|
||||||
|
|
||||||
|
public int getCounter() {
|
||||||
|
return this.counter;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setCounter(int counter) {
|
||||||
|
this.counter = counter;
|
||||||
|
}
|
||||||
|
|
||||||
|
public GameCycle getCycle() {
|
||||||
|
return this.cycle;
|
||||||
|
}
|
||||||
|
|
||||||
|
public int getStartCount() {
|
||||||
|
return this.counterStart;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Team getWinner() {
|
||||||
|
return this.winner;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void run() {
|
||||||
|
this.cycle.onGameOver(this);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
@@ -0,0 +1,5 @@
|
|||||||
|
package io.github.bedwarsrel.game;
|
||||||
|
|
||||||
|
public enum GameState {
|
||||||
|
RUNNING, WAITING, STOPPED
|
||||||
|
}
|
||||||
@@ -0,0 +1,58 @@
|
|||||||
|
package io.github.bedwarsrel.game;
|
||||||
|
|
||||||
|
import io.github.bedwarsrel.BedwarsRel;
|
||||||
|
import org.bukkit.entity.Player;
|
||||||
|
|
||||||
|
public class PlayerSettings {
|
||||||
|
|
||||||
|
private Object hologram = null;
|
||||||
|
private boolean isTeleporting = false;
|
||||||
|
private boolean oneStackPerShift = false;
|
||||||
|
private Player player = null;
|
||||||
|
private boolean useOldShop = false;
|
||||||
|
|
||||||
|
public PlayerSettings(Player player) {
|
||||||
|
this.player = player;
|
||||||
|
this.oneStackPerShift = BedwarsRel.getInstance()
|
||||||
|
.getBooleanConfig("player-settings.one-stack-on-shift", false);
|
||||||
|
this.useOldShop = BedwarsRel.getInstance()
|
||||||
|
.getBooleanConfig("player-settings.old-shop-as-default", false);
|
||||||
|
}
|
||||||
|
|
||||||
|
public Object getHologram() {
|
||||||
|
return this.hologram;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setHologram(Object holo) {
|
||||||
|
this.hologram = holo;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Player getPlayer() {
|
||||||
|
return this.player;
|
||||||
|
}
|
||||||
|
|
||||||
|
public boolean isTeleporting() {
|
||||||
|
return isTeleporting;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setTeleporting(boolean isTeleporting) {
|
||||||
|
this.isTeleporting = isTeleporting;
|
||||||
|
}
|
||||||
|
|
||||||
|
public boolean oneStackPerShift() {
|
||||||
|
return this.oneStackPerShift;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setOneStackPerShift(boolean value) {
|
||||||
|
this.oneStackPerShift = value;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setUseOldShop(boolean value) {
|
||||||
|
this.useOldShop = value;
|
||||||
|
}
|
||||||
|
|
||||||
|
public boolean useOldShop() {
|
||||||
|
return this.useOldShop;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
@@ -0,0 +1,264 @@
|
|||||||
|
package io.github.bedwarsrel.game;
|
||||||
|
|
||||||
|
import io.github.bedwarsrel.BedwarsRel;
|
||||||
|
import io.github.bedwarsrel.events.BedwarsOpenTeamSelectionEvent;
|
||||||
|
import io.github.bedwarsrel.events.BedwarsPlayerSetNameEvent;
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.Collection;
|
||||||
|
import java.util.HashMap;
|
||||||
|
import java.util.List;
|
||||||
|
import org.bukkit.Bukkit;
|
||||||
|
import org.bukkit.ChatColor;
|
||||||
|
import org.bukkit.GameMode;
|
||||||
|
import org.bukkit.Location;
|
||||||
|
import org.bukkit.Material;
|
||||||
|
import org.bukkit.entity.Player;
|
||||||
|
import org.bukkit.inventory.Inventory;
|
||||||
|
import org.bukkit.inventory.ItemStack;
|
||||||
|
import org.bukkit.inventory.PlayerInventory;
|
||||||
|
import org.bukkit.inventory.meta.ItemMeta;
|
||||||
|
import org.bukkit.material.Wool;
|
||||||
|
import org.bukkit.potion.PotionEffect;
|
||||||
|
|
||||||
|
public class PlayerStorage {
|
||||||
|
|
||||||
|
private ItemStack[] armor = null;
|
||||||
|
private String displayName = null;
|
||||||
|
private Collection<PotionEffect> effects = null;
|
||||||
|
private int foodLevel = 0;
|
||||||
|
private ItemStack[] inventory = null;
|
||||||
|
private Location left = null;
|
||||||
|
private int level = 0;
|
||||||
|
private String listName = null;
|
||||||
|
private GameMode mode = null;
|
||||||
|
private Player player = null;
|
||||||
|
private float xp = 0.0F;
|
||||||
|
|
||||||
|
public PlayerStorage(Player p) {
|
||||||
|
super();
|
||||||
|
|
||||||
|
this.player = p;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void addGameStartItem() {
|
||||||
|
ItemStack startGame = new ItemStack(Material.DIAMOND, 1);
|
||||||
|
ItemMeta im = startGame.getItemMeta();
|
||||||
|
im.setDisplayName(BedwarsRel._l(player, "lobby.startgame"));
|
||||||
|
startGame.setItemMeta(im);
|
||||||
|
this.player.getInventory().addItem(startGame);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void addReduceCountdownItem() {
|
||||||
|
ItemStack reduceCountdownItem = new ItemStack(Material.EMERALD, 1);
|
||||||
|
ItemMeta im = reduceCountdownItem.getItemMeta();
|
||||||
|
im.setDisplayName(BedwarsRel._l(player, "lobby.reduce_countdown"));
|
||||||
|
reduceCountdownItem.setItemMeta(im);
|
||||||
|
this.player.getInventory().addItem(reduceCountdownItem);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void clean() {
|
||||||
|
|
||||||
|
PlayerInventory inv = this.player.getInventory();
|
||||||
|
inv.setArmorContents(new ItemStack[4]);
|
||||||
|
inv.setContents(new ItemStack[]{});
|
||||||
|
|
||||||
|
this.player.setAllowFlight(false);
|
||||||
|
this.player.setFlying(false);
|
||||||
|
this.player.setExp(0.0F);
|
||||||
|
this.player.setLevel(0);
|
||||||
|
this.player.setSneaking(false);
|
||||||
|
this.player.setSprinting(false);
|
||||||
|
this.player.setFoodLevel(20);
|
||||||
|
this.player.setSaturation(10);
|
||||||
|
this.player.setExhaustion(0);
|
||||||
|
this.player.setMaxHealth(20.0D);
|
||||||
|
this.player.setHealth(20.0D);
|
||||||
|
this.player.setFireTicks(0);
|
||||||
|
|
||||||
|
boolean teamnameOnTab = BedwarsRel.getInstance().getBooleanConfig("teamname-on-tab", true);
|
||||||
|
boolean overwriteNames = BedwarsRel.getInstance().getBooleanConfig("overwrite-names", false);
|
||||||
|
|
||||||
|
String displayName = this.player.getDisplayName();
|
||||||
|
String playerListName = this.player.getPlayerListName();
|
||||||
|
|
||||||
|
if (overwriteNames || teamnameOnTab) {
|
||||||
|
Game game = BedwarsRel.getInstance().getGameManager().getGameOfPlayer(this.player);
|
||||||
|
if (game != null) {
|
||||||
|
game.setPlayerGameMode(player);
|
||||||
|
Team team = game.getPlayerTeam(this.player);
|
||||||
|
|
||||||
|
if (overwriteNames) {
|
||||||
|
if (team != null) {
|
||||||
|
displayName = team.getChatColor() + ChatColor.stripColor(this.player.getName());
|
||||||
|
} else {
|
||||||
|
displayName = ChatColor.stripColor(this.player.getName());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (teamnameOnTab) {
|
||||||
|
if (team != null) {
|
||||||
|
playerListName = team.getChatColor() + team.getName() + ChatColor.WHITE + " | "
|
||||||
|
+ team.getChatColor() + ChatColor.stripColor(this.player.getDisplayName());
|
||||||
|
} else {
|
||||||
|
playerListName = ChatColor.stripColor(this.player.getDisplayName());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
BedwarsPlayerSetNameEvent playerSetNameEvent =
|
||||||
|
new BedwarsPlayerSetNameEvent(team, displayName, playerListName, player);
|
||||||
|
BedwarsRel.getInstance().getServer().getPluginManager().callEvent(playerSetNameEvent);
|
||||||
|
|
||||||
|
if (!playerSetNameEvent.isCancelled()) {
|
||||||
|
this.player.setDisplayName(playerSetNameEvent.getDisplayName());
|
||||||
|
this.player.setPlayerListName(playerSetNameEvent.getPlayerListName());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (this.player.isInsideVehicle()) {
|
||||||
|
this.player.leaveVehicle();
|
||||||
|
}
|
||||||
|
|
||||||
|
for (PotionEffect e : this.player.getActivePotionEffects()) {
|
||||||
|
this.player.removePotionEffect(e.getType());
|
||||||
|
}
|
||||||
|
|
||||||
|
this.player.updateInventory();
|
||||||
|
}
|
||||||
|
|
||||||
|
public Location getLeft() {
|
||||||
|
return this.left;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void loadLobbyInventory(Game game) {
|
||||||
|
ItemMeta im = null;
|
||||||
|
|
||||||
|
// choose team only when autobalance is disabled
|
||||||
|
if (!game.isAutobalanceEnabled()) {
|
||||||
|
// Choose team (Wool)
|
||||||
|
ItemStack teamSelection = new ItemStack(Material.BED, 1);
|
||||||
|
im = teamSelection.getItemMeta();
|
||||||
|
im.setDisplayName(BedwarsRel._l(this.player, "lobby.chooseteam"));
|
||||||
|
teamSelection.setItemMeta(im);
|
||||||
|
this.player.getInventory().addItem(teamSelection);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Leave game (Slimeball)
|
||||||
|
ItemStack leaveGame = new ItemStack(Material.SLIME_BALL, 1);
|
||||||
|
im = leaveGame.getItemMeta();
|
||||||
|
im.setDisplayName(BedwarsRel._l(this.player, "lobby.leavegame"));
|
||||||
|
leaveGame.setItemMeta(im);
|
||||||
|
this.player.getInventory().setItem(8, leaveGame);
|
||||||
|
|
||||||
|
if ((this.player.hasPermission("bw.setup") || this.player.isOp()
|
||||||
|
|| this.player.hasPermission("bw.vip.forcestart"))
|
||||||
|
|| (game.getGameLobbyCountdown() != null && (this.player.hasPermission("bw.setup")
|
||||||
|
|| this.player.isOp() || this.player.hasPermission("bw.vip.forcestart")))) {
|
||||||
|
this.addGameStartItem();
|
||||||
|
}
|
||||||
|
|
||||||
|
if (game.getGameLobbyCountdown() != null
|
||||||
|
&& game.getGameLobbyCountdown().getLobbytime() > game.getGameLobbyCountdown()
|
||||||
|
.getLobbytimeWhenFull()
|
||||||
|
&& (this.player.hasPermission("bw.setup") || this.player.isOp()
|
||||||
|
|| this.player.hasPermission("bw.vip.reducecountdown"))) {
|
||||||
|
this.addReduceCountdownItem();
|
||||||
|
}
|
||||||
|
|
||||||
|
this.player.updateInventory();
|
||||||
|
}
|
||||||
|
|
||||||
|
public void openTeamSelection(Game game) {
|
||||||
|
BedwarsOpenTeamSelectionEvent openEvent = new BedwarsOpenTeamSelectionEvent(game, this.player);
|
||||||
|
BedwarsRel.getInstance().getServer().getPluginManager().callEvent(openEvent);
|
||||||
|
|
||||||
|
if (openEvent.isCancelled()) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
HashMap<String, Team> teams = game.getTeams();
|
||||||
|
|
||||||
|
int nom = (teams.size() % 9 == 0) ? 9 : (teams.size() % 9);
|
||||||
|
Inventory inv =
|
||||||
|
Bukkit.createInventory(this.player, teams.size() + (9 - nom),
|
||||||
|
BedwarsRel._l(this.player, "lobby.chooseteam"));
|
||||||
|
for (Team team : teams.values()) {
|
||||||
|
List<Player> players = team.getPlayers();
|
||||||
|
if (players.size() >= team.getMaxPlayers()) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
Wool wool = new Wool(team.getColor().getDyeColor());
|
||||||
|
ItemStack is = wool.toItemStack(1);
|
||||||
|
ItemMeta im = is.getItemMeta();
|
||||||
|
|
||||||
|
im.setDisplayName(team.getChatColor() + team.getName());
|
||||||
|
ArrayList<String> teamplayers = new ArrayList<>();
|
||||||
|
|
||||||
|
int teamPlayerSize = team.getPlayers().size();
|
||||||
|
int maxPlayers = team.getMaxPlayers();
|
||||||
|
|
||||||
|
String current = "0";
|
||||||
|
if (teamPlayerSize >= maxPlayers) {
|
||||||
|
current = ChatColor.RED + String.valueOf(teamPlayerSize);
|
||||||
|
} else {
|
||||||
|
current = ChatColor.YELLOW + String.valueOf(teamPlayerSize);
|
||||||
|
}
|
||||||
|
|
||||||
|
teamplayers.add(ChatColor.GRAY + "(" + current + ChatColor.GRAY + "/" + ChatColor.YELLOW
|
||||||
|
+ String.valueOf(maxPlayers) + ChatColor.GRAY + ")");
|
||||||
|
teamplayers.add(ChatColor.WHITE + "---------");
|
||||||
|
|
||||||
|
for (Player teamPlayer : players) {
|
||||||
|
teamplayers.add(team.getChatColor() + ChatColor.stripColor(teamPlayer.getDisplayName()));
|
||||||
|
}
|
||||||
|
|
||||||
|
im.setLore(teamplayers);
|
||||||
|
is.setItemMeta(im);
|
||||||
|
inv.addItem(is);
|
||||||
|
}
|
||||||
|
|
||||||
|
this.player.openInventory(inv);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void restore() {
|
||||||
|
if (BedwarsRel.getInstance().getBooleanConfig("save-inventory", true)) {
|
||||||
|
this.player.getInventory().setContents(this.inventory);
|
||||||
|
this.player.getInventory().setArmorContents(this.armor);
|
||||||
|
|
||||||
|
this.player.addPotionEffects(this.effects);
|
||||||
|
this.player.setLevel(this.level);
|
||||||
|
this.player.setExp(this.xp);
|
||||||
|
this.player.setFoodLevel(this.foodLevel);
|
||||||
|
|
||||||
|
for (PotionEffect e : this.player.getActivePotionEffects()) {
|
||||||
|
this.player.removePotionEffect(e.getType());
|
||||||
|
}
|
||||||
|
|
||||||
|
this.player.addPotionEffects(this.effects);
|
||||||
|
}
|
||||||
|
|
||||||
|
this.player.setPlayerListName(this.listName);
|
||||||
|
this.player.setDisplayName(this.displayName);
|
||||||
|
|
||||||
|
this.player.setGameMode(this.mode);
|
||||||
|
|
||||||
|
if (this.mode == GameMode.CREATIVE) {
|
||||||
|
this.player.setAllowFlight(true);
|
||||||
|
}
|
||||||
|
this.player.updateInventory();
|
||||||
|
}
|
||||||
|
|
||||||
|
public void store() {
|
||||||
|
this.inventory = this.player.getInventory().getContents();
|
||||||
|
this.armor = this.player.getInventory().getArmorContents();
|
||||||
|
this.xp = Float.valueOf(this.player.getExp());
|
||||||
|
this.effects = this.player.getActivePotionEffects();
|
||||||
|
this.mode = this.player.getGameMode();
|
||||||
|
this.left = this.player.getLocation();
|
||||||
|
this.level = this.player.getLevel();
|
||||||
|
this.listName = this.player.getPlayerListName();
|
||||||
|
this.displayName = this.player.getDisplayName();
|
||||||
|
this.foodLevel = this.player.getFoodLevel();
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
388
common/src/main/java/io/github/bedwarsrel/game/Region.java
Normal file
388
common/src/main/java/io/github/bedwarsrel/game/Region.java
Normal file
@@ -0,0 +1,388 @@
|
|||||||
|
package io.github.bedwarsrel.game;
|
||||||
|
|
||||||
|
import io.github.bedwarsrel.BedwarsRel;
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.HashMap;
|
||||||
|
import java.util.Iterator;
|
||||||
|
import java.util.List;
|
||||||
|
import org.bukkit.Chunk;
|
||||||
|
import org.bukkit.Location;
|
||||||
|
import org.bukkit.Material;
|
||||||
|
import org.bukkit.World;
|
||||||
|
import org.bukkit.block.Block;
|
||||||
|
import org.bukkit.block.BlockFace;
|
||||||
|
import org.bukkit.block.BlockState;
|
||||||
|
import org.bukkit.entity.Entity;
|
||||||
|
import org.bukkit.entity.EntityType;
|
||||||
|
import org.bukkit.entity.Item;
|
||||||
|
import org.bukkit.entity.LivingEntity;
|
||||||
|
import org.bukkit.inventory.Inventory;
|
||||||
|
import org.bukkit.material.Bed;
|
||||||
|
import org.bukkit.material.Directional;
|
||||||
|
import org.bukkit.material.Lever;
|
||||||
|
import org.bukkit.material.MaterialData;
|
||||||
|
import org.bukkit.material.Redstone;
|
||||||
|
|
||||||
|
public class Region {
|
||||||
|
|
||||||
|
public final static int CHUNK_SIZE = 16;
|
||||||
|
private HashMap<Block, Byte> breakedBlockData = null;
|
||||||
|
private HashMap<Block, BlockFace> breakedBlockFace = null;
|
||||||
|
private HashMap<Block, Boolean> breakedBlockPower = null;
|
||||||
|
private HashMap<Block, Integer> breakedBlockTypes = null;
|
||||||
|
private List<Block> breakedBlocks = null;
|
||||||
|
private List<Inventory> inventories = null;
|
||||||
|
private Location maxCorner = null;
|
||||||
|
private Location minCorner = null;
|
||||||
|
private String name = null;
|
||||||
|
private List<Block> placedBlocks = null;
|
||||||
|
private List<Block> placedUnbreakableBlocks = null;
|
||||||
|
private List<Entity> removingEntities = null;
|
||||||
|
private World world = null;
|
||||||
|
|
||||||
|
public Region(Location pos1, Location pos2, String name) {
|
||||||
|
if (pos1 == null || pos2 == null) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!pos1.getWorld().getName().equals(pos2.getWorld().getName())) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
this.world = pos1.getWorld();
|
||||||
|
this.setMinMax(pos1, pos2);
|
||||||
|
this.placedBlocks = new ArrayList<Block>();
|
||||||
|
this.breakedBlocks = new ArrayList<Block>();
|
||||||
|
this.breakedBlockTypes = new HashMap<Block, Integer>();
|
||||||
|
this.breakedBlockData = new HashMap<Block, Byte>();
|
||||||
|
this.breakedBlockFace = new HashMap<Block, BlockFace>();
|
||||||
|
this.placedUnbreakableBlocks = new ArrayList<Block>();
|
||||||
|
this.breakedBlockPower = new HashMap<Block, Boolean>();
|
||||||
|
this.inventories = new ArrayList<Inventory>();
|
||||||
|
this.removingEntities = new ArrayList<Entity>();
|
||||||
|
|
||||||
|
this.name = name;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Region(World w, int x1, int y1, int z1, int x2, int y2, int z2) {
|
||||||
|
this(new Location(w, x1, y1, z1), new Location(w, x2, y2, z2), w.getName());
|
||||||
|
}
|
||||||
|
|
||||||
|
@SuppressWarnings("deprecation")
|
||||||
|
public void addBreakedBlock(Block bedBlock) {
|
||||||
|
if (bedBlock.getState().getData() instanceof Directional) {
|
||||||
|
this.breakedBlockFace.put(bedBlock,
|
||||||
|
((Directional) bedBlock.getState().getData()).getFacing());
|
||||||
|
}
|
||||||
|
|
||||||
|
this.breakedBlockTypes.put(bedBlock, bedBlock.getTypeId());
|
||||||
|
this.breakedBlockData.put(bedBlock, bedBlock.getData());
|
||||||
|
|
||||||
|
if (bedBlock.getState().getData() instanceof Redstone) {
|
||||||
|
this.breakedBlockPower.put(bedBlock, ((Redstone) bedBlock.getState().getData()).isPowered());
|
||||||
|
}
|
||||||
|
|
||||||
|
this.breakedBlocks.add(bedBlock);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void addInventory(Inventory inventory) {
|
||||||
|
this.inventories.add(inventory);
|
||||||
|
}
|
||||||
|
|
||||||
|
@SuppressWarnings("deprecation")
|
||||||
|
public void addPlacedBlock(Block placeBlock, BlockState replacedBlock) {
|
||||||
|
this.placedBlocks.add(placeBlock);
|
||||||
|
if (replacedBlock != null) {
|
||||||
|
if (replacedBlock.getData() instanceof Directional) {
|
||||||
|
this.breakedBlockFace.put(replacedBlock.getBlock(),
|
||||||
|
((Directional) replacedBlock.getData()).getFacing());
|
||||||
|
}
|
||||||
|
|
||||||
|
this.breakedBlockTypes.put(replacedBlock.getBlock(), replacedBlock.getTypeId());
|
||||||
|
this.breakedBlockData.put(replacedBlock.getBlock(), replacedBlock.getData().getData());
|
||||||
|
|
||||||
|
this.breakedBlocks.add(replacedBlock.getBlock());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@SuppressWarnings("deprecation")
|
||||||
|
public void addPlacedUnbreakableBlock(Block placed, BlockState replaced) {
|
||||||
|
this.placedUnbreakableBlocks.add(placed);
|
||||||
|
if (replaced != null) {
|
||||||
|
if (replaced.getData() instanceof Directional) {
|
||||||
|
this.breakedBlockFace.put(replaced.getBlock(),
|
||||||
|
((Directional) replaced.getData()).getFacing());
|
||||||
|
}
|
||||||
|
|
||||||
|
this.breakedBlockTypes.put(replaced.getBlock(), replaced.getTypeId());
|
||||||
|
this.breakedBlockData.put(replaced.getBlock(), replaced.getData().getData());
|
||||||
|
this.breakedBlocks.add(replaced.getBlock());
|
||||||
|
|
||||||
|
if (replaced.getData() instanceof Redstone) {
|
||||||
|
this.breakedBlockPower.put(placed, ((Redstone) replaced.getData()).isPowered());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public void addRemovingEntity(Entity removing) {
|
||||||
|
this.removingEntities.add(removing);
|
||||||
|
}
|
||||||
|
|
||||||
|
public boolean check() {
|
||||||
|
return (this.minCorner != null && this.maxCorner != null && this.world != null);
|
||||||
|
}
|
||||||
|
|
||||||
|
public boolean chunkIsInRegion(Chunk chunk) {
|
||||||
|
return (chunk.getX() >= this.minCorner.getX() && chunk.getX() <= this.maxCorner.getX()
|
||||||
|
&& chunk.getZ() >= this.minCorner.getZ() && chunk.getZ() <= this.maxCorner.getZ());
|
||||||
|
}
|
||||||
|
|
||||||
|
public boolean chunkIsInRegion(double x, double z) {
|
||||||
|
return (x >= this.minCorner.getX() && x <= this.maxCorner.getX() && z >= this.minCorner.getZ()
|
||||||
|
&& z <= this.maxCorner.getZ());
|
||||||
|
}
|
||||||
|
|
||||||
|
public List<Inventory> getInventories() {
|
||||||
|
return this.inventories;
|
||||||
|
}
|
||||||
|
|
||||||
|
private Location getMaximumCorner(Location pos1, Location pos2) {
|
||||||
|
return new Location(this.world, Math.max(pos1.getBlockX(), pos2.getBlockX()),
|
||||||
|
Math.max(pos1.getBlockY(), pos2.getBlockY()), Math.max(pos1.getBlockZ(), pos2.getBlockZ()));
|
||||||
|
}
|
||||||
|
|
||||||
|
private Location getMinimumCorner(Location pos1, Location pos2) {
|
||||||
|
return new Location(this.world, Math.min(pos1.getBlockX(), pos2.getBlockX()),
|
||||||
|
Math.min(pos1.getBlockY(), pos2.getBlockY()), Math.min(pos1.getBlockZ(), pos2.getBlockZ()));
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getName() {
|
||||||
|
if (this.name == null) {
|
||||||
|
this.name = this.world.getName();
|
||||||
|
}
|
||||||
|
|
||||||
|
return this.name;
|
||||||
|
}
|
||||||
|
|
||||||
|
public World getWorld() {
|
||||||
|
return this.minCorner.getWorld();
|
||||||
|
}
|
||||||
|
|
||||||
|
public boolean isInRegion(Location location) {
|
||||||
|
if (!location.getWorld().equals(this.world)) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
return (location.getBlockX() >= this.minCorner.getBlockX()
|
||||||
|
&& location.getBlockX() <= this.maxCorner.getBlockX()
|
||||||
|
&& location.getBlockY() >= this.minCorner.getBlockY()
|
||||||
|
&& location.getBlockY() <= this.maxCorner.getBlockY()
|
||||||
|
&& location.getBlockZ() >= this.minCorner.getBlockZ()
|
||||||
|
&& location.getBlockZ() <= this.maxCorner.getBlockZ());
|
||||||
|
}
|
||||||
|
|
||||||
|
public boolean isPlacedBlock(Block block) {
|
||||||
|
return this.placedBlocks.contains(block);
|
||||||
|
}
|
||||||
|
|
||||||
|
public boolean isPlacedUnbreakableBlock(Block clickedBlock) {
|
||||||
|
return this.placedUnbreakableBlocks.contains(clickedBlock);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void loadChunks() {
|
||||||
|
int minX = (int) Math.floor(this.minCorner.getX());
|
||||||
|
int maxX = (int) Math.ceil(this.maxCorner.getX());
|
||||||
|
int minZ = (int) Math.floor(this.minCorner.getZ());
|
||||||
|
int maxZ = (int) Math.ceil(this.maxCorner.getZ());
|
||||||
|
|
||||||
|
for (int x = minX; x <= maxX; x += Region.CHUNK_SIZE) {
|
||||||
|
for (int z = minZ; z <= maxZ; z += Region.CHUNK_SIZE) {
|
||||||
|
Chunk chunk = this.world.getChunkAt(x, z);
|
||||||
|
if (!chunk.isLoaded()) {
|
||||||
|
chunk.load();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public void removePlacedBlock(Block block) {
|
||||||
|
this.placedBlocks.remove(block);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void removePlacedUnbreakableBlock(Block block) {
|
||||||
|
this.placedUnbreakableBlocks.remove(block);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void removeRemovingEntity(Entity removing) {
|
||||||
|
this.removingEntities.remove(removing);
|
||||||
|
}
|
||||||
|
|
||||||
|
@SuppressWarnings("deprecation")
|
||||||
|
public void reset(Game game) {
|
||||||
|
this.loadChunks();
|
||||||
|
|
||||||
|
for (Inventory inventory : this.inventories) {
|
||||||
|
inventory.clear();
|
||||||
|
}
|
||||||
|
|
||||||
|
for (Block placed : this.placedBlocks) {
|
||||||
|
Block blockInWorld = this.world.getBlockAt(placed.getLocation());
|
||||||
|
if (blockInWorld.getType() == Material.AIR) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (blockInWorld.equals(placed)) {
|
||||||
|
blockInWorld.setType(Material.AIR);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
this.placedBlocks.clear();
|
||||||
|
|
||||||
|
for (Block placed : this.placedUnbreakableBlocks) {
|
||||||
|
Block blockInWorld = this.world.getBlockAt(placed.getLocation());
|
||||||
|
if (blockInWorld.getType() == Material.AIR) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (blockInWorld.getLocation().equals(placed.getLocation())) {
|
||||||
|
blockInWorld.setType(Material.AIR);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
this.placedUnbreakableBlocks.clear();
|
||||||
|
|
||||||
|
for (Block block : this.breakedBlocks) {
|
||||||
|
Block theBlock = this.getWorld().getBlockAt(block.getLocation());
|
||||||
|
theBlock.setTypeId(this.breakedBlockTypes.get(block));
|
||||||
|
theBlock.setData(this.breakedBlockData.get(block));
|
||||||
|
|
||||||
|
if (this.breakedBlockFace.containsKey(theBlock)) {
|
||||||
|
MaterialData data = theBlock.getState().getData();
|
||||||
|
if (data instanceof Directional) {
|
||||||
|
((Directional) data).setFacingDirection(this.breakedBlockFace.get(block));
|
||||||
|
theBlock.getState().setData(data);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (theBlock.getState().getData() instanceof Lever) {
|
||||||
|
Lever attach = (Lever) theBlock.getState().getData();
|
||||||
|
BlockState supportState = theBlock.getState();
|
||||||
|
BlockState initalState = theBlock.getState();
|
||||||
|
attach.setPowered(this.breakedBlockPower.get(block));
|
||||||
|
theBlock.getState().setData(attach);
|
||||||
|
|
||||||
|
supportState.setType(Material.AIR);
|
||||||
|
supportState.update(true, false);
|
||||||
|
initalState.update(true);
|
||||||
|
} else {
|
||||||
|
theBlock.getState().update(true, true);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
this.breakedBlocks.clear();
|
||||||
|
|
||||||
|
Material targetMaterial = game.getTargetMaterial();
|
||||||
|
for (Team team : game.getTeams().values()) {
|
||||||
|
if (team.getHeadTarget() == null) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
if ((targetMaterial.equals(Material.BED_BLOCK) || targetMaterial.equals(Material.BED))
|
||||||
|
&& team.getFeetTarget() != null) {
|
||||||
|
Block blockHead = this.world.getBlockAt(team.getHeadTarget().getLocation());
|
||||||
|
Block blockFeed = this.world.getBlockAt(team.getFeetTarget().getLocation());
|
||||||
|
BlockState headState = blockHead.getState();
|
||||||
|
BlockState feedState = blockFeed.getState();
|
||||||
|
|
||||||
|
headState.setType(Material.BED_BLOCK);
|
||||||
|
feedState.setType(Material.BED_BLOCK);
|
||||||
|
headState.setRawData((byte) 0x0);
|
||||||
|
feedState.setRawData((byte) 0x8);
|
||||||
|
feedState.update(true, false);
|
||||||
|
headState.update(true, false);
|
||||||
|
|
||||||
|
Bed bedHead = (Bed) headState.getData();
|
||||||
|
bedHead.setHeadOfBed(true);
|
||||||
|
bedHead.setFacingDirection(blockHead.getFace(blockFeed).getOppositeFace());
|
||||||
|
|
||||||
|
Bed bedFeed = (Bed) feedState.getData();
|
||||||
|
bedFeed.setHeadOfBed(false);
|
||||||
|
bedFeed.setFacingDirection(blockFeed.getFace(blockHead));
|
||||||
|
|
||||||
|
feedState.update(true, false);
|
||||||
|
headState.update(true, true);
|
||||||
|
} else {
|
||||||
|
Block blockHead = this.world.getBlockAt(team.getHeadTarget().getLocation());
|
||||||
|
BlockState headState = blockHead.getState();
|
||||||
|
|
||||||
|
headState.setType(targetMaterial);
|
||||||
|
headState.update(true, true);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
for (ResourceSpawner spawner : game.getRessourceSpawner()) {
|
||||||
|
spawner.getLocation().getChunk().load();
|
||||||
|
}
|
||||||
|
|
||||||
|
for (Entity entity : this.removingEntities) {
|
||||||
|
entity.remove();
|
||||||
|
}
|
||||||
|
|
||||||
|
Iterator<Entity> entityIterator = this.world.getEntities().iterator();
|
||||||
|
while (entityIterator.hasNext()) {
|
||||||
|
Entity e = entityIterator.next();
|
||||||
|
|
||||||
|
if (this.removingEntities.contains(e)) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!this.isInRegion(e.getLocation())) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (e instanceof Item) {
|
||||||
|
e.remove();
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (e.getType().equals(EntityType.CREEPER) || e.getType().equals(EntityType.CAVE_SPIDER)
|
||||||
|
|| e.getType().equals(EntityType.SPIDER) || e.getType().equals(EntityType.ZOMBIE)
|
||||||
|
|| e.getType().equals(EntityType.SKELETON) || e.getType().equals(EntityType.SILVERFISH)
|
||||||
|
|| e.getType().equals(EntityType.ARROW)) {
|
||||||
|
e.remove();
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (e instanceof LivingEntity) {
|
||||||
|
LivingEntity le = (LivingEntity) e;
|
||||||
|
le.setRemoveWhenFarAway(false);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
this.removingEntities.clear();
|
||||||
|
}
|
||||||
|
|
||||||
|
private void setMinMax(Location pos1, Location pos2) {
|
||||||
|
this.minCorner = this.getMinimumCorner(pos1, pos2);
|
||||||
|
this.maxCorner = this.getMaximumCorner(pos1, pos2);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setVillagerNametag() {
|
||||||
|
Iterator<Entity> entityIterator = this.world.getEntities().iterator();
|
||||||
|
while (entityIterator.hasNext()) {
|
||||||
|
Entity e = entityIterator.next();
|
||||||
|
|
||||||
|
if (!this.isInRegion(e.getLocation())) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (e.getType() == EntityType.VILLAGER) {
|
||||||
|
LivingEntity le = (LivingEntity) e;
|
||||||
|
le.setCustomNameVisible(false);
|
||||||
|
le.setCustomName(
|
||||||
|
BedwarsRel
|
||||||
|
._l(BedwarsRel.getInstance().getServer().getConsoleSender(), "ingame.shop.name"));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,169 @@
|
|||||||
|
package io.github.bedwarsrel.game;
|
||||||
|
|
||||||
|
import io.github.bedwarsrel.BedwarsRel;
|
||||||
|
import io.github.bedwarsrel.events.BedwarsResourceSpawnEvent;
|
||||||
|
import io.github.bedwarsrel.utils.Utils;
|
||||||
|
import io.github.bedwarsrel.villager.ItemStackParser;
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.HashMap;
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.Map;
|
||||||
|
import lombok.Getter;
|
||||||
|
import lombok.Setter;
|
||||||
|
import org.bukkit.Location;
|
||||||
|
import org.bukkit.block.BlockState;
|
||||||
|
import org.bukkit.block.Chest;
|
||||||
|
import org.bukkit.configuration.serialization.ConfigurationSerializable;
|
||||||
|
import org.bukkit.configuration.serialization.SerializableAs;
|
||||||
|
import org.bukkit.entity.Item;
|
||||||
|
import org.bukkit.inventory.Inventory;
|
||||||
|
import org.bukkit.inventory.ItemStack;
|
||||||
|
|
||||||
|
@Getter
|
||||||
|
@Setter
|
||||||
|
@SerializableAs("RessourceSpawner")
|
||||||
|
public class ResourceSpawner implements Runnable, ConfigurationSerializable {
|
||||||
|
|
||||||
|
private Game game = null;
|
||||||
|
private int interval = 1000;
|
||||||
|
private List<ItemStack> resources = new ArrayList<>();
|
||||||
|
private Location location = null;
|
||||||
|
private double spread = 1.0;
|
||||||
|
private String name = null;
|
||||||
|
|
||||||
|
public ResourceSpawner(Map<String, Object> deserialize) {
|
||||||
|
this.location = Utils.locationDeserialize(deserialize.get("location"));
|
||||||
|
|
||||||
|
if (deserialize.containsKey("name")) {
|
||||||
|
String name = deserialize.get("name").toString();
|
||||||
|
|
||||||
|
if (BedwarsRel.getInstance().getConfig().contains("resource." + name)) {
|
||||||
|
List<Object> resourceList = (List<Object>) BedwarsRel.getInstance().getConfig()
|
||||||
|
.getList("resource." + name + ".item");
|
||||||
|
for (Object resource : resourceList) {
|
||||||
|
ItemStack itemStack = ItemStack.deserialize((Map<String, Object>) resource);
|
||||||
|
if (itemStack != null) {
|
||||||
|
this.resources.add(itemStack);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
this.interval =
|
||||||
|
BedwarsRel.getInstance().getIntConfig("resource." + name + ".spawn-interval", 1000);
|
||||||
|
this.spread =
|
||||||
|
BedwarsRel.getInstance().getConfig().getDouble("resource." + name + ".spread", 1.0);
|
||||||
|
this.name = name;
|
||||||
|
} else {
|
||||||
|
List<Object> resourceList = (List<Object>) BedwarsRel.getInstance().getConfig()
|
||||||
|
.getList("resource." + name + ".item");
|
||||||
|
for (Object resource : resourceList) {
|
||||||
|
ItemStack itemStack = ItemStack.deserialize((Map<String, Object>) resource);
|
||||||
|
if (itemStack != null) {
|
||||||
|
this.resources.add(itemStack);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
this.interval = Integer.parseInt(deserialize.get("interval").toString());
|
||||||
|
if (deserialize.containsKey("spread")) {
|
||||||
|
this.spread = Double.parseDouble(deserialize.get("spread").toString());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
List<Object> resourceList = (List<Object>) BedwarsRel.getInstance().getConfig()
|
||||||
|
.getList("resource." + name + ".item");
|
||||||
|
for (Object resource : resourceList) {
|
||||||
|
ItemStack itemStack = ItemStack.deserialize((Map<String, Object>) resource);
|
||||||
|
if (itemStack != null) {
|
||||||
|
this.resources.add(itemStack);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
this.interval = Integer.parseInt(deserialize.get("interval").toString());
|
||||||
|
if (deserialize.containsKey("spread")) {
|
||||||
|
this.spread = Double.parseDouble(deserialize.get("spread").toString());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public ResourceSpawner(Game game, String name, Location location) {
|
||||||
|
this.game = game;
|
||||||
|
this.name = name;
|
||||||
|
this.interval =
|
||||||
|
BedwarsRel.getInstance().getIntConfig("resource." + name + ".spawn-interval", 1000);
|
||||||
|
this.location = location;
|
||||||
|
List<Object> resourceList = (List<Object>) BedwarsRel.getInstance().getConfig()
|
||||||
|
.getList("resource." + name + ".item");
|
||||||
|
for (Object resource : resourceList) {
|
||||||
|
ItemStack itemStack = ItemStack.deserialize((Map<String, Object>) resource);
|
||||||
|
if (itemStack != null) {
|
||||||
|
this.resources.add(itemStack);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
this.spread =
|
||||||
|
BedwarsRel.getInstance().getConfig().getDouble("resource." + name + ".spread", 1.0);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static ItemStack createSpawnerStackByConfig(Object section) {
|
||||||
|
ItemStackParser parser = new ItemStackParser(section);
|
||||||
|
return parser.parse();
|
||||||
|
}
|
||||||
|
|
||||||
|
public boolean canContainItem(Inventory inv, ItemStack item) {
|
||||||
|
int space = 0;
|
||||||
|
for (ItemStack stack : inv.getContents()) {
|
||||||
|
if (stack == null) {
|
||||||
|
space += item.getMaxStackSize();
|
||||||
|
} else if (stack.getType() == item.getType()
|
||||||
|
&& stack.getDurability() == item.getDurability()) {
|
||||||
|
space += item.getMaxStackSize() - stack.getAmount();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return space >= item.getAmount();
|
||||||
|
}
|
||||||
|
|
||||||
|
public void dropItem(Location dropLocation, ItemStack itemStack) {
|
||||||
|
Item item = this.game.getRegion().getWorld().dropItemNaturally(dropLocation, itemStack);
|
||||||
|
item.setPickupDelay(0);
|
||||||
|
if (this.spread != 1.0) {
|
||||||
|
item.setVelocity(item.getVelocity().multiply(this.spread));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void run() {
|
||||||
|
Location dropLocation = this.location.clone();
|
||||||
|
for (ItemStack itemStack : this.resources) {
|
||||||
|
ItemStack item = itemStack.clone();
|
||||||
|
|
||||||
|
BedwarsResourceSpawnEvent resourceSpawnEvent =
|
||||||
|
new BedwarsResourceSpawnEvent(this.game, this.location, item);
|
||||||
|
BedwarsRel.getInstance().getServer().getPluginManager().callEvent(resourceSpawnEvent);
|
||||||
|
|
||||||
|
if (resourceSpawnEvent.isCancelled()) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
item = resourceSpawnEvent.getResource();
|
||||||
|
|
||||||
|
if (BedwarsRel.getInstance().getBooleanConfig("spawn-resources-in-chest", true)) {
|
||||||
|
BlockState blockState = dropLocation.getBlock().getState();
|
||||||
|
if (blockState instanceof Chest) {
|
||||||
|
Chest chest = (Chest) blockState;
|
||||||
|
if (canContainItem(chest.getInventory(), item)) {
|
||||||
|
chest.getInventory().addItem(item);
|
||||||
|
continue;
|
||||||
|
} else {
|
||||||
|
dropLocation.setY(dropLocation.getY() + 1);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
dropItem(dropLocation, item);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Map<String, Object> serialize() {
|
||||||
|
HashMap<String, Object> rs = new HashMap<>();
|
||||||
|
|
||||||
|
rs.put("location", Utils.locationSerialize(this.location));
|
||||||
|
rs.put("name", this.name);
|
||||||
|
return rs;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
@@ -0,0 +1,43 @@
|
|||||||
|
package io.github.bedwarsrel.game;
|
||||||
|
|
||||||
|
import com.google.common.collect.ImmutableMap;
|
||||||
|
import io.github.bedwarsrel.BedwarsRel;
|
||||||
|
import io.github.bedwarsrel.utils.ChatWriter;
|
||||||
|
import org.bukkit.entity.Player;
|
||||||
|
import org.bukkit.scheduler.BukkitRunnable;
|
||||||
|
|
||||||
|
public class RespawnProtectionRunnable extends BukkitRunnable {
|
||||||
|
|
||||||
|
private Game game = null;
|
||||||
|
private int length = 0;
|
||||||
|
private Player player = null;
|
||||||
|
|
||||||
|
public RespawnProtectionRunnable(Game game, Player player, int seconds) {
|
||||||
|
this.game = game;
|
||||||
|
this.player = player;
|
||||||
|
this.length = seconds;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void run() {
|
||||||
|
if (this.length > 0) {
|
||||||
|
this.player
|
||||||
|
.sendMessage(ChatWriter.pluginMessage(BedwarsRel._l(player, "ingame.protectionleft",
|
||||||
|
ImmutableMap.of("length", String.valueOf(this.length)))));
|
||||||
|
}
|
||||||
|
|
||||||
|
if (this.length <= 0) {
|
||||||
|
this.player
|
||||||
|
.sendMessage(
|
||||||
|
ChatWriter.pluginMessage(BedwarsRel._l(this.player, "ingame.protectionend")));
|
||||||
|
this.game.removeProtection(this.player);
|
||||||
|
}
|
||||||
|
|
||||||
|
this.length--;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void runProtection() {
|
||||||
|
this.runTaskTimerAsynchronously(BedwarsRel.getInstance(), 5L, 20L);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
@@ -0,0 +1,215 @@
|
|||||||
|
package io.github.bedwarsrel.game;
|
||||||
|
|
||||||
|
import com.google.common.collect.ImmutableMap;
|
||||||
|
import io.github.bedwarsrel.BedwarsRel;
|
||||||
|
import io.github.bedwarsrel.events.BedwarsGameEndEvent;
|
||||||
|
import io.github.bedwarsrel.statistics.PlayerStatistic;
|
||||||
|
import io.github.bedwarsrel.utils.ChatWriter;
|
||||||
|
import io.github.bedwarsrel.utils.Utils;
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.List;
|
||||||
|
import org.bukkit.ChatColor;
|
||||||
|
import org.bukkit.entity.Player;
|
||||||
|
|
||||||
|
public class SingleGameCycle extends GameCycle {
|
||||||
|
|
||||||
|
public SingleGameCycle(Game game) {
|
||||||
|
super(game);
|
||||||
|
}
|
||||||
|
|
||||||
|
private void kickPlayer(Player player, boolean wasSpectator) {
|
||||||
|
for (Player freePlayer : this.getGame().getFreePlayers()) {
|
||||||
|
player.showPlayer(freePlayer);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (wasSpectator && this.getGame().isFull()) {
|
||||||
|
this.getGame().playerLeave(player, false);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (BedwarsRel.getInstance().toMainLobby()) {
|
||||||
|
if (BedwarsRel.getInstance().allPlayersBackToMainLobby()) {
|
||||||
|
this.getGame().playerLeave(player, false);
|
||||||
|
return;
|
||||||
|
} else {
|
||||||
|
player.teleport(this.getGame().getLobby());
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
player.teleport(this.getGame().getLobby());
|
||||||
|
}
|
||||||
|
|
||||||
|
if (BedwarsRel.getInstance().statisticsEnabled()) {
|
||||||
|
PlayerStatistic statistic =
|
||||||
|
BedwarsRel.getInstance().getPlayerStatisticManager().getStatistic(player);
|
||||||
|
BedwarsRel.getInstance().getPlayerStatisticManager().storeStatistic(statistic);
|
||||||
|
|
||||||
|
if (BedwarsRel.getInstance().getBooleanConfig("statistics.show-on-game-end", true)) {
|
||||||
|
BedwarsRel.getInstance().getServer().dispatchCommand(player, "bw stats");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
this.getGame().setPlayerDamager(player, null);
|
||||||
|
|
||||||
|
PlayerStorage storage = this.getGame().getPlayerStorage(player);
|
||||||
|
storage.clean();
|
||||||
|
storage.loadLobbyInventory(this.getGame());
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onGameEnds() {
|
||||||
|
// Reset scoreboard first
|
||||||
|
this.getGame().resetScoreboard();
|
||||||
|
|
||||||
|
// First team players, they get a reserved slot in lobby
|
||||||
|
for (Player p : this.getGame().getTeamPlayers()) {
|
||||||
|
this.kickPlayer(p, false);
|
||||||
|
}
|
||||||
|
|
||||||
|
// and now the spectators
|
||||||
|
List<Player> freePlayers = new ArrayList<Player>(this.getGame().getFreePlayers());
|
||||||
|
for (Player p : freePlayers) {
|
||||||
|
this.kickPlayer(p, true);
|
||||||
|
}
|
||||||
|
|
||||||
|
// reset countdown prevention breaks
|
||||||
|
this.setEndGameRunning(false);
|
||||||
|
|
||||||
|
// Reset team chests
|
||||||
|
for (Team team : this.getGame().getTeams().values()) {
|
||||||
|
team.setInventory(null);
|
||||||
|
team.getChests().clear();
|
||||||
|
}
|
||||||
|
|
||||||
|
// clear protections
|
||||||
|
this.getGame().clearProtections();
|
||||||
|
|
||||||
|
// reset region
|
||||||
|
this.getGame().resetRegion();
|
||||||
|
|
||||||
|
// Restart lobby directly?
|
||||||
|
if (this.getGame().isStartable() && this.getGame().getLobbyCountdown() == null) {
|
||||||
|
GameLobbyCountdown lobbyCountdown = new GameLobbyCountdown(this.getGame());
|
||||||
|
lobbyCountdown.runTaskTimer(BedwarsRel.getInstance(), 20L, 20L);
|
||||||
|
this.getGame().setLobbyCountdown(lobbyCountdown);
|
||||||
|
}
|
||||||
|
|
||||||
|
// set state and with that, the sign
|
||||||
|
this.getGame().setState(GameState.WAITING);
|
||||||
|
this.getGame().updateScoreboard();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onGameLoaded() {
|
||||||
|
// Reset on game end
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onGameOver(GameOverTask task) {
|
||||||
|
if (task.getCounter() == task.getStartCount() && task.getWinner() != null) {
|
||||||
|
for (Player aPlayer : this.getGame().getPlayers()) {
|
||||||
|
if (aPlayer.isOnline()) {
|
||||||
|
aPlayer.sendMessage(
|
||||||
|
ChatWriter.pluginMessage(ChatColor.GOLD + BedwarsRel._l(aPlayer, "ingame.teamwon",
|
||||||
|
ImmutableMap.of("team", task.getWinner().getDisplayName() + ChatColor.GOLD))));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
this.getGame().stopWorkers();
|
||||||
|
} else if (task.getCounter() == task.getStartCount() && task.getWinner() == null) {
|
||||||
|
for (Player aPlayer : this.getGame().getPlayers()) {
|
||||||
|
if (aPlayer.isOnline()) {
|
||||||
|
aPlayer.sendMessage(
|
||||||
|
ChatWriter.pluginMessage(ChatColor.GOLD + BedwarsRel._l(aPlayer, "ingame.draw")));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (this.getGame().getPlayers().size() == 0 || task.getCounter() == 0) {
|
||||||
|
BedwarsGameEndEvent endEvent = new BedwarsGameEndEvent(this.getGame());
|
||||||
|
BedwarsRel.getInstance().getServer().getPluginManager().callEvent(endEvent);
|
||||||
|
|
||||||
|
this.onGameEnds();
|
||||||
|
task.cancel();
|
||||||
|
} else {
|
||||||
|
for (Player aPlayer : this.getGame().getPlayers()) {
|
||||||
|
if (aPlayer.isOnline()) {
|
||||||
|
aPlayer.sendMessage(
|
||||||
|
ChatWriter.pluginMessage(
|
||||||
|
ChatColor.AQUA + BedwarsRel
|
||||||
|
._l(aPlayer, "ingame.backtolobby", ImmutableMap.of("sec",
|
||||||
|
ChatColor.YELLOW.toString() + task.getCounter() + ChatColor.AQUA))));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
task.decCounter();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onGameStart() {
|
||||||
|
// Reset on game end
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean onPlayerJoins(Player player) {
|
||||||
|
if (this.getGame().isFull() && !player.hasPermission("bw.vip.joinfull")) {
|
||||||
|
if (this.getGame().getState() != GameState.RUNNING
|
||||||
|
|| !BedwarsRel.getInstance().spectationEnabled()) {
|
||||||
|
player.sendMessage(
|
||||||
|
ChatWriter.pluginMessage(ChatColor.RED + BedwarsRel._l(player, "lobby.gamefull")));
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
} else if (this.getGame().isFull() && player.hasPermission("bw.vip.joinfull")) {
|
||||||
|
if (this.getGame().getState() == GameState.WAITING) {
|
||||||
|
List<Player> players = this.getGame().getNonVipPlayers();
|
||||||
|
|
||||||
|
if (players.size() == 0) {
|
||||||
|
player.sendMessage(
|
||||||
|
ChatWriter
|
||||||
|
.pluginMessage(ChatColor.RED + BedwarsRel._l(player, "lobby.gamefullpremium")));
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
Player kickPlayer = null;
|
||||||
|
if (players.size() == 1) {
|
||||||
|
kickPlayer = players.get(0);
|
||||||
|
} else {
|
||||||
|
kickPlayer = players.get(Utils.randInt(0, players.size() - 1));
|
||||||
|
}
|
||||||
|
|
||||||
|
kickPlayer
|
||||||
|
.sendMessage(
|
||||||
|
ChatWriter.pluginMessage(ChatColor.RED + BedwarsRel
|
||||||
|
._l(kickPlayer, "lobby.kickedbyvip")));
|
||||||
|
this.getGame().playerLeave(kickPlayer, false);
|
||||||
|
} else {
|
||||||
|
if (this.getGame().getState() == GameState.RUNNING
|
||||||
|
&& !BedwarsRel.getInstance().spectationEnabled()) {
|
||||||
|
player.sendMessage(
|
||||||
|
ChatWriter
|
||||||
|
.pluginMessage(ChatColor.RED + BedwarsRel._l(player, "errors.cantjoingame")));
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onPlayerLeave(Player player) {
|
||||||
|
// teleport to join location
|
||||||
|
PlayerStorage storage = this.getGame().getPlayerStorage(player);
|
||||||
|
|
||||||
|
if (BedwarsRel.getInstance().toMainLobby()) {
|
||||||
|
player.teleport(this.getGame().getMainLobby());
|
||||||
|
} else {
|
||||||
|
player.teleport(storage.getLeft());
|
||||||
|
}
|
||||||
|
|
||||||
|
if (this.getGame().getState() == GameState.RUNNING && !this.getGame().isStopping()
|
||||||
|
&& !this.getGame().isSpectator(player)) {
|
||||||
|
this.checkGameOver();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
292
common/src/main/java/io/github/bedwarsrel/game/Team.java
Normal file
292
common/src/main/java/io/github/bedwarsrel/game/Team.java
Normal file
@@ -0,0 +1,292 @@
|
|||||||
|
package io.github.bedwarsrel.game;
|
||||||
|
|
||||||
|
import io.github.bedwarsrel.BedwarsRel;
|
||||||
|
import io.github.bedwarsrel.events.BedwarsPlayerJoinTeamEvent;
|
||||||
|
import io.github.bedwarsrel.events.BedwarsPlayerSetNameEvent;
|
||||||
|
import io.github.bedwarsrel.utils.Utils;
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.HashMap;
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.Map;
|
||||||
|
import lombok.Data;
|
||||||
|
import org.bukkit.Bukkit;
|
||||||
|
import org.bukkit.ChatColor;
|
||||||
|
import org.bukkit.Location;
|
||||||
|
import org.bukkit.Material;
|
||||||
|
import org.bukkit.OfflinePlayer;
|
||||||
|
import org.bukkit.block.Block;
|
||||||
|
import org.bukkit.configuration.serialization.ConfigurationSerializable;
|
||||||
|
import org.bukkit.configuration.serialization.SerializableAs;
|
||||||
|
import org.bukkit.entity.Player;
|
||||||
|
import org.bukkit.event.inventory.InventoryType;
|
||||||
|
import org.bukkit.inventory.Inventory;
|
||||||
|
import org.bukkit.inventory.ItemStack;
|
||||||
|
import org.bukkit.inventory.meta.LeatherArmorMeta;
|
||||||
|
|
||||||
|
@Data
|
||||||
|
@SerializableAs("Team")
|
||||||
|
public class Team implements ConfigurationSerializable {
|
||||||
|
|
||||||
|
private List<Block> chests = null;
|
||||||
|
private TeamColor color = null;
|
||||||
|
private Inventory inventory = null;
|
||||||
|
private int maxPlayers = 0;
|
||||||
|
private String name = null;
|
||||||
|
private org.bukkit.scoreboard.Team scoreboardTeam = null;
|
||||||
|
private Location spawnLocation = null;
|
||||||
|
private Location targetFeetBlock = null;
|
||||||
|
private Location targetHeadBlock = null;
|
||||||
|
|
||||||
|
public Team(Map<String, Object> deserialize) {
|
||||||
|
this.setName(deserialize.get("name").toString());
|
||||||
|
this.setMaxPlayers(Integer.parseInt(deserialize.get("maxplayers").toString()));
|
||||||
|
this.setColor(TeamColor.valueOf(deserialize.get("color").toString().toUpperCase()));
|
||||||
|
this.setSpawnLocation(Utils.locationDeserialize(deserialize.get("spawn")));
|
||||||
|
this.setChests(new ArrayList<Block>());
|
||||||
|
|
||||||
|
if (deserialize.containsKey("bedhead")) {
|
||||||
|
this.setTargetHeadBlock(Utils.locationDeserialize(deserialize.get("bedhead")));
|
||||||
|
|
||||||
|
if (this.getTargetHeadBlock() != null && deserialize.containsKey("bedfeed")
|
||||||
|
&& this.getTargetHeadBlock().getBlock().getType().equals(Material.BED_BLOCK)) {
|
||||||
|
this.setTargetFeetBlock(Utils.locationDeserialize(deserialize.get("bedfeed")));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public Team(String name, TeamColor color, int maxPlayers,
|
||||||
|
org.bukkit.scoreboard.Team scoreboardTeam) {
|
||||||
|
this.setName(name);
|
||||||
|
this.setColor(color);
|
||||||
|
this.setMaxPlayers(maxPlayers);
|
||||||
|
this.setScoreboardTeam(scoreboardTeam);
|
||||||
|
this.setChests(new ArrayList<Block>());
|
||||||
|
}
|
||||||
|
|
||||||
|
public void addChest(Block chestBlock) {
|
||||||
|
this.getChests().add(chestBlock);
|
||||||
|
}
|
||||||
|
|
||||||
|
@SuppressWarnings("deprecation")
|
||||||
|
public boolean addPlayer(Player player) {
|
||||||
|
|
||||||
|
BedwarsPlayerJoinTeamEvent playerJoinTeamEvent = new BedwarsPlayerJoinTeamEvent(this, player);
|
||||||
|
BedwarsRel.getInstance().getServer().getPluginManager().callEvent(playerJoinTeamEvent);
|
||||||
|
|
||||||
|
if (playerJoinTeamEvent.isCancelled()) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (BedwarsRel.getInstance().isSpigot()) {
|
||||||
|
if (this.getScoreboardTeam().getEntries().size() >= this.getMaxPlayers()) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
if (this.getScoreboardTeam().getPlayers().size() >= this.getMaxPlayers()) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
String displayName = player.getDisplayName();
|
||||||
|
String playerListName = player.getPlayerListName();
|
||||||
|
|
||||||
|
if (BedwarsRel.getInstance().getBooleanConfig("overwrite-names", false)) {
|
||||||
|
displayName = this.getChatColor() + ChatColor.stripColor(player.getName());
|
||||||
|
playerListName = this.getChatColor() + ChatColor.stripColor(player.getName());
|
||||||
|
}
|
||||||
|
|
||||||
|
if (BedwarsRel.getInstance().getBooleanConfig("teamname-on-tab", true)) {
|
||||||
|
playerListName = this.getChatColor() + this.getName() + ChatColor.WHITE + " | "
|
||||||
|
+ this.getChatColor() + ChatColor.stripColor(player.getDisplayName());
|
||||||
|
}
|
||||||
|
|
||||||
|
BedwarsPlayerSetNameEvent playerSetNameEvent =
|
||||||
|
new BedwarsPlayerSetNameEvent(this, displayName, playerListName, player);
|
||||||
|
BedwarsRel.getInstance().getServer().getPluginManager().callEvent(playerSetNameEvent);
|
||||||
|
|
||||||
|
if (!playerSetNameEvent.isCancelled()) {
|
||||||
|
player.setDisplayName(playerSetNameEvent.getDisplayName());
|
||||||
|
player.setPlayerListName(playerSetNameEvent.getPlayerListName());
|
||||||
|
}
|
||||||
|
|
||||||
|
if (BedwarsRel.getInstance().isSpigot()) {
|
||||||
|
this.getScoreboardTeam().addEntry(player.getName());
|
||||||
|
} else {
|
||||||
|
this.getScoreboardTeam().addPlayer(player);
|
||||||
|
}
|
||||||
|
this.equipPlayerWithLeather(player);
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void createTeamInventory() {
|
||||||
|
Inventory inventory =
|
||||||
|
Bukkit.createInventory(null, InventoryType.ENDER_CHEST, BedwarsRel._l("ingame.teamchest"));
|
||||||
|
this.setInventory(inventory);
|
||||||
|
}
|
||||||
|
|
||||||
|
private void equipPlayerWithLeather(Player player) {
|
||||||
|
// helmet
|
||||||
|
ItemStack helmet = new ItemStack(Material.LEATHER_HELMET, 1);
|
||||||
|
LeatherArmorMeta meta = (LeatherArmorMeta) helmet.getItemMeta();
|
||||||
|
meta.setColor(this.getColor().getColor());
|
||||||
|
helmet.setItemMeta(meta);
|
||||||
|
|
||||||
|
// chestplate
|
||||||
|
ItemStack chestplate = new ItemStack(Material.LEATHER_CHESTPLATE, 1);
|
||||||
|
meta = (LeatherArmorMeta) chestplate.getItemMeta();
|
||||||
|
meta.setColor(this.getColor().getColor());
|
||||||
|
chestplate.setItemMeta(meta);
|
||||||
|
|
||||||
|
// leggings
|
||||||
|
ItemStack leggings = new ItemStack(Material.LEATHER_LEGGINGS, 1);
|
||||||
|
meta = (LeatherArmorMeta) leggings.getItemMeta();
|
||||||
|
meta.setColor(this.getColor().getColor());
|
||||||
|
leggings.setItemMeta(meta);
|
||||||
|
|
||||||
|
// boots
|
||||||
|
ItemStack boots = new ItemStack(Material.LEATHER_BOOTS, 1);
|
||||||
|
meta = (LeatherArmorMeta) boots.getItemMeta();
|
||||||
|
meta.setColor(this.getColor().getColor());
|
||||||
|
boots.setItemMeta(meta);
|
||||||
|
|
||||||
|
player.getInventory().setHelmet(helmet);
|
||||||
|
player.getInventory().setChestplate(chestplate);
|
||||||
|
player.getInventory().setLeggings(leggings);
|
||||||
|
player.getInventory().setBoots(boots);
|
||||||
|
player.updateInventory();
|
||||||
|
}
|
||||||
|
|
||||||
|
public ChatColor getChatColor() {
|
||||||
|
return this.getColor().getChatColor();
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getDisplayName() {
|
||||||
|
return this.getScoreboardTeam().getDisplayName();
|
||||||
|
}
|
||||||
|
|
||||||
|
public Block getFeetTarget() {
|
||||||
|
if (this.getTargetFeetBlock() == null) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
this.getTargetFeetBlock().getBlock().getChunk().load(true);
|
||||||
|
return this.getTargetFeetBlock().getBlock();
|
||||||
|
}
|
||||||
|
|
||||||
|
public Block getHeadTarget() {
|
||||||
|
if (this.targetHeadBlock == null) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
this.getTargetHeadBlock().getBlock().getChunk().load(true);
|
||||||
|
return this.getTargetHeadBlock().getBlock();
|
||||||
|
}
|
||||||
|
|
||||||
|
@SuppressWarnings("deprecation")
|
||||||
|
public List<Player> getPlayers() {
|
||||||
|
List<Player> players = new ArrayList<>();
|
||||||
|
if (BedwarsRel.getInstance().isSpigot()) {
|
||||||
|
for (String aPlayer : this.getScoreboardTeam().getEntries()) {
|
||||||
|
Player player = BedwarsRel.getInstance().getServer().getPlayer(aPlayer);
|
||||||
|
if (player != null
|
||||||
|
&& BedwarsRel.getInstance().getGameManager().getGameOfPlayer(player) != null
|
||||||
|
&& !BedwarsRel.getInstance().getGameManager().getGameOfPlayer(player)
|
||||||
|
.isSpectator(player)) {
|
||||||
|
players.add(player);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
for (OfflinePlayer offlinePlayer : this.getScoreboardTeam().getPlayers()) {
|
||||||
|
Player player = BedwarsRel.getInstance().getServer().getPlayer(offlinePlayer.getName());
|
||||||
|
if (player != null
|
||||||
|
&& BedwarsRel.getInstance().getGameManager().getGameOfPlayer(player) != null
|
||||||
|
&& !BedwarsRel.getInstance().getGameManager().getGameOfPlayer(player)
|
||||||
|
.isSpectator(player)) {
|
||||||
|
players.add(player);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return players;
|
||||||
|
}
|
||||||
|
|
||||||
|
public boolean isDead(Game game) {
|
||||||
|
Material targetMaterial = game.getTargetMaterial();
|
||||||
|
|
||||||
|
this.getTargetHeadBlock().getBlock().getChunk().load(true);
|
||||||
|
if (this.getTargetFeetBlock() == null) {
|
||||||
|
return this.getTargetHeadBlock().getBlock().getType() != targetMaterial;
|
||||||
|
}
|
||||||
|
|
||||||
|
this.getTargetFeetBlock().getBlock().getChunk().load(true);
|
||||||
|
return (this.getTargetHeadBlock().getBlock().getType() != targetMaterial
|
||||||
|
&& this.getTargetFeetBlock().getBlock().getType() != targetMaterial);
|
||||||
|
}
|
||||||
|
|
||||||
|
@SuppressWarnings("deprecation")
|
||||||
|
public boolean isInTeam(Player p) {
|
||||||
|
if (BedwarsRel.getInstance().isSpigot()) {
|
||||||
|
return this.getScoreboardTeam().hasEntry(p.getName());
|
||||||
|
} else {
|
||||||
|
return this.getScoreboardTeam().hasPlayer(p);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public void removeChest(Block chest) {
|
||||||
|
this.getChests().remove(chest);
|
||||||
|
if (this.getChests().size() == 0) {
|
||||||
|
this.setInventory(null);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@SuppressWarnings("deprecation")
|
||||||
|
public void removePlayer(Player player) {
|
||||||
|
if (BedwarsRel.getInstance().isSpigot()) {
|
||||||
|
if (this.getScoreboardTeam().hasEntry(player.getName())) {
|
||||||
|
this.getScoreboardTeam().removeEntry(player.getName());
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
if (this.getScoreboardTeam().hasPlayer(player)) {
|
||||||
|
this.getScoreboardTeam().removePlayer(player);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (BedwarsRel.getInstance().getBooleanConfig("overwrite-names", false) && player.isOnline()) {
|
||||||
|
player.setDisplayName(ChatColor.RESET + ChatColor.stripColor(player.getName()));
|
||||||
|
player.setPlayerListName(ChatColor.RESET + player.getPlayer().getName());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Map<String, Object> serialize() {
|
||||||
|
HashMap<String, Object> team = new HashMap<>();
|
||||||
|
|
||||||
|
team.put("name", this.getName());
|
||||||
|
team.put("color", this.getColor().toString());
|
||||||
|
team.put("maxplayers", this.getMaxPlayers());
|
||||||
|
team.put("spawn", Utils.locationSerialize(this.getSpawnLocation()));
|
||||||
|
team.put("bedhead", Utils.locationSerialize(this.getTargetHeadBlock()));
|
||||||
|
|
||||||
|
if (this.targetFeetBlock != null) {
|
||||||
|
team.put("bedfeed", Utils.locationSerialize(this.targetFeetBlock));
|
||||||
|
}
|
||||||
|
|
||||||
|
return team;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setScoreboardTeam(org.bukkit.scoreboard.Team scoreboardTeam) {
|
||||||
|
scoreboardTeam.setDisplayName(this.getChatColor() + this.name);
|
||||||
|
this.scoreboardTeam = scoreboardTeam;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setTargets(Block headBlock, Block feetBlock) {
|
||||||
|
this.setTargetHeadBlock(headBlock.getLocation());
|
||||||
|
if (feetBlock != null) {
|
||||||
|
this.setTargetFeetBlock(feetBlock.getLocation());
|
||||||
|
} else {
|
||||||
|
this.setTargetFeetBlock(null);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
@@ -0,0 +1,45 @@
|
|||||||
|
package io.github.bedwarsrel.game;
|
||||||
|
|
||||||
|
import org.bukkit.ChatColor;
|
||||||
|
import org.bukkit.Color;
|
||||||
|
import org.bukkit.DyeColor;
|
||||||
|
|
||||||
|
public enum TeamColor {
|
||||||
|
GREEN(Color.fromRGB(85, 255, 85), ChatColor.GREEN, DyeColor.LIME),
|
||||||
|
RED(Color.fromRGB(255, 85, 85), ChatColor.RED, DyeColor.RED),
|
||||||
|
BLUE(Color.fromRGB(85, 85, 255), ChatColor.BLUE, DyeColor.LIGHT_BLUE),
|
||||||
|
YELLOW(Color.fromRGB(255, 255, 85), ChatColor.YELLOW, DyeColor.YELLOW),
|
||||||
|
AQUA(Color.fromRGB(85, 255, 255), ChatColor.AQUA, DyeColor.CYAN),
|
||||||
|
BLACK(Color.BLACK, ChatColor.BLACK, DyeColor.BLACK),
|
||||||
|
GOLD(Color.fromRGB(255, 170, 0), ChatColor.GOLD, DyeColor.ORANGE),
|
||||||
|
DARK_BLUE(Color.fromRGB(0, 0, 170), ChatColor.DARK_BLUE, DyeColor.BLUE),
|
||||||
|
DARK_GREEN(Color.fromRGB(0, 170, 0), ChatColor.DARK_GREEN, DyeColor.GREEN),
|
||||||
|
DARK_RED(Color.fromRGB(170, 0, 0), ChatColor.DARK_RED, DyeColor.BROWN),
|
||||||
|
DARK_PURPLE(Color.fromRGB(170, 0, 170), ChatColor.DARK_PURPLE, DyeColor.MAGENTA),
|
||||||
|
GRAY(Color.fromRGB(170, 170, 170), ChatColor.GRAY, DyeColor.SILVER),
|
||||||
|
DARK_GRAY(Color.fromRGB(85, 85, 85), ChatColor.DARK_GRAY, DyeColor.GRAY),
|
||||||
|
LIGHT_PURPLE(Color.fromRGB(255, 85, 255), ChatColor.LIGHT_PURPLE, DyeColor.PINK),
|
||||||
|
WHITE(Color.WHITE, ChatColor.WHITE, DyeColor.WHITE);
|
||||||
|
|
||||||
|
private ChatColor chatColor;
|
||||||
|
private Color color;
|
||||||
|
private DyeColor dyeColor;
|
||||||
|
|
||||||
|
private TeamColor(Color color, ChatColor chatColor, DyeColor dye) {
|
||||||
|
this.chatColor = chatColor;
|
||||||
|
this.color = color;
|
||||||
|
this.dyeColor = dye;
|
||||||
|
}
|
||||||
|
|
||||||
|
public ChatColor getChatColor() {
|
||||||
|
return this.chatColor;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Color getColor() {
|
||||||
|
return this.color;
|
||||||
|
}
|
||||||
|
|
||||||
|
public DyeColor getDyeColor() {
|
||||||
|
return this.dyeColor;
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,75 @@
|
|||||||
|
package io.github.bedwarsrel.game;
|
||||||
|
|
||||||
|
import io.github.bedwarsrel.BedwarsRel;
|
||||||
|
import org.bukkit.metadata.MetadataValue;
|
||||||
|
import org.bukkit.plugin.Plugin;
|
||||||
|
|
||||||
|
public class TeamJoinMetaDataValue implements MetadataValue {
|
||||||
|
|
||||||
|
private Team team = null;
|
||||||
|
private boolean teamjoin = true;
|
||||||
|
|
||||||
|
public TeamJoinMetaDataValue(Team team) {
|
||||||
|
this.team = team;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean asBoolean() {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public byte asByte() {
|
||||||
|
return this.asBoolean() ? (byte) 1 : (byte) 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public double asDouble() {
|
||||||
|
return this.asBoolean() ? 1 : 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public float asFloat() {
|
||||||
|
return this.asBoolean() ? 1F : 0F;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public int asInt() {
|
||||||
|
return this.asBoolean() ? 1 : 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public long asLong() {
|
||||||
|
return this.asBoolean() ? 1 : 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public short asShort() {
|
||||||
|
return this.asBoolean() ? (short) 1 : (short) 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String asString() {
|
||||||
|
return this.asBoolean() ? "true" : "false";
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Plugin getOwningPlugin() {
|
||||||
|
return BedwarsRel.getInstance();
|
||||||
|
}
|
||||||
|
|
||||||
|
public Team getTeam() {
|
||||||
|
return this.team;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void invalidate() {
|
||||||
|
this.teamjoin = false;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Object value() {
|
||||||
|
return this.teamjoin;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
@@ -0,0 +1,17 @@
|
|||||||
|
package io.github.bedwarsrel.listener;
|
||||||
|
|
||||||
|
import io.github.bedwarsrel.BedwarsRel;
|
||||||
|
import org.bukkit.event.Listener;
|
||||||
|
|
||||||
|
public abstract class BaseListener implements Listener {
|
||||||
|
|
||||||
|
public BaseListener() {
|
||||||
|
this.registerEvents();
|
||||||
|
}
|
||||||
|
|
||||||
|
private void registerEvents() {
|
||||||
|
BedwarsRel.getInstance().getServer().getPluginManager()
|
||||||
|
.registerEvents(this, BedwarsRel.getInstance());
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
@@ -0,0 +1,414 @@
|
|||||||
|
package io.github.bedwarsrel.listener;
|
||||||
|
|
||||||
|
import io.github.bedwarsrel.BedwarsRel;
|
||||||
|
import io.github.bedwarsrel.game.Game;
|
||||||
|
import io.github.bedwarsrel.game.GameState;
|
||||||
|
import io.github.bedwarsrel.game.Team;
|
||||||
|
import io.github.bedwarsrel.utils.ChatWriter;
|
||||||
|
import java.util.List;
|
||||||
|
import org.bukkit.ChatColor;
|
||||||
|
import org.bukkit.Material;
|
||||||
|
import org.bukkit.block.Block;
|
||||||
|
import org.bukkit.block.BlockFace;
|
||||||
|
import org.bukkit.block.BlockState;
|
||||||
|
import org.bukkit.block.Sign;
|
||||||
|
import org.bukkit.entity.Player;
|
||||||
|
import org.bukkit.event.EventHandler;
|
||||||
|
import org.bukkit.event.EventPriority;
|
||||||
|
import org.bukkit.event.block.BlockBreakEvent;
|
||||||
|
import org.bukkit.event.block.BlockBurnEvent;
|
||||||
|
import org.bukkit.event.block.BlockFadeEvent;
|
||||||
|
import org.bukkit.event.block.BlockFormEvent;
|
||||||
|
import org.bukkit.event.block.BlockGrowEvent;
|
||||||
|
import org.bukkit.event.block.BlockIgniteEvent;
|
||||||
|
import org.bukkit.event.block.BlockIgniteEvent.IgniteCause;
|
||||||
|
import org.bukkit.event.block.BlockPlaceEvent;
|
||||||
|
import org.bukkit.event.block.BlockSpreadEvent;
|
||||||
|
import org.bukkit.event.world.StructureGrowEvent;
|
||||||
|
import org.bukkit.inventory.ItemStack;
|
||||||
|
import org.bukkit.inventory.meta.ItemMeta;
|
||||||
|
|
||||||
|
public class BlockListener extends BaseListener {
|
||||||
|
|
||||||
|
@EventHandler(ignoreCancelled = true)
|
||||||
|
public void onBlockGrow(BlockGrowEvent grow) {
|
||||||
|
|
||||||
|
Game game =
|
||||||
|
BedwarsRel.getInstance().getGameManager().getGameByLocation(grow.getBlock().getLocation());
|
||||||
|
if (game == null) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
grow.setCancelled(true);
|
||||||
|
}
|
||||||
|
|
||||||
|
@EventHandler(priority = EventPriority.NORMAL, ignoreCancelled = true)
|
||||||
|
public void onBreak(BlockBreakEvent e) {
|
||||||
|
|
||||||
|
Player p = e.getPlayer();
|
||||||
|
if (p == null) {
|
||||||
|
Block block = e.getBlock();
|
||||||
|
if (block == null) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
Game game = BedwarsRel.getInstance().getGameManager().getGameByLocation(block.getLocation());
|
||||||
|
if (game == null) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (game.getState() != GameState.RUNNING) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
e.setCancelled(true);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
Game g = BedwarsRel.getInstance().getGameManager().getGameOfPlayer(p);
|
||||||
|
if (g == null) {
|
||||||
|
Block breaked = e.getBlock();
|
||||||
|
if (!(breaked.getState() instanceof Sign)) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!p.hasPermission("bw.setup") || e.isCancelled()) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
Game game = BedwarsRel.getInstance().getGameManager()
|
||||||
|
.getGameBySignLocation(breaked.getLocation());
|
||||||
|
if (game == null) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
game.removeJoinSign(breaked.getLocation());
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (g.getState() != GameState.RUNNING && g.getState() != GameState.WAITING) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (g.getState() == GameState.WAITING) {
|
||||||
|
e.setCancelled(true);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (g.isSpectator(p)) {
|
||||||
|
e.setCancelled(true);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
Material targetMaterial = g.getTargetMaterial();
|
||||||
|
if (e.getBlock().getType() == targetMaterial) {
|
||||||
|
e.setCancelled(true);
|
||||||
|
|
||||||
|
g.handleDestroyTargetMaterial(p, e.getBlock());
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
Block breakedBlock = e.getBlock();
|
||||||
|
|
||||||
|
if (!g.getRegion().isPlacedBlock(breakedBlock)) {
|
||||||
|
if (breakedBlock == null) {
|
||||||
|
e.setCancelled(true);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (BedwarsRel.getInstance().isBreakableType(breakedBlock.getType())) {
|
||||||
|
g.getRegion().addBreakedBlock(breakedBlock);
|
||||||
|
e.setCancelled(false);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
e.setCancelled(true);
|
||||||
|
} else {
|
||||||
|
if (!BedwarsRel.getInstance().getBooleanConfig("friendlybreak", true)) {
|
||||||
|
Team playerTeam = g.getPlayerTeam(p);
|
||||||
|
for (Player player : playerTeam.getPlayers()) {
|
||||||
|
if (player.equals(p)) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (player.getLocation().getBlock().getRelative(BlockFace.DOWN).equals(e.getBlock())) {
|
||||||
|
p.sendMessage(
|
||||||
|
ChatWriter
|
||||||
|
.pluginMessage(ChatColor.RED + BedwarsRel._l(p, "ingame.no-friendlybreak")));
|
||||||
|
e.setCancelled(true);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (e.getBlock().getType() == Material.ENDER_CHEST) {
|
||||||
|
for (Team team : g.getTeams().values()) {
|
||||||
|
List<Block> teamChests = team.getChests();
|
||||||
|
if (teamChests.contains(breakedBlock)) {
|
||||||
|
team.removeChest(breakedBlock);
|
||||||
|
for (Player aPlayer : team.getPlayers()) {
|
||||||
|
if (aPlayer.isOnline()) {
|
||||||
|
aPlayer.sendMessage(
|
||||||
|
ChatWriter.pluginMessage(BedwarsRel._l(aPlayer, "ingame.teamchestdestroy")));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Drop ender chest
|
||||||
|
ItemStack enderChest = new ItemStack(Material.ENDER_CHEST, 1);
|
||||||
|
ItemMeta meta = enderChest.getItemMeta();
|
||||||
|
meta.setDisplayName(BedwarsRel._l("ingame.teamchest"));
|
||||||
|
enderChest.setItemMeta(meta);
|
||||||
|
|
||||||
|
e.setCancelled(true);
|
||||||
|
breakedBlock.getDrops().clear();
|
||||||
|
breakedBlock.setType(Material.AIR);
|
||||||
|
breakedBlock.getWorld().dropItemNaturally(breakedBlock.getLocation(), enderChest);
|
||||||
|
}
|
||||||
|
|
||||||
|
for (ItemStack drop : breakedBlock.getDrops()) {
|
||||||
|
if (!drop.getType().equals(breakedBlock.getType())) {
|
||||||
|
breakedBlock.getDrops().remove(drop);
|
||||||
|
breakedBlock.setType(Material.AIR);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
g.getRegion().removePlacedBlock(breakedBlock);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@EventHandler(priority = EventPriority.HIGH)
|
||||||
|
public void onBurn(BlockBurnEvent bbe) {
|
||||||
|
Block block = bbe.getBlock();
|
||||||
|
if (block == null) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
Game game = BedwarsRel.getInstance().getGameManager().getGameByLocation(block.getLocation());
|
||||||
|
if (game == null) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (game.getState() == GameState.STOPPED) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
bbe.setCancelled(true);
|
||||||
|
}
|
||||||
|
|
||||||
|
@EventHandler(ignoreCancelled = true)
|
||||||
|
public void onFade(BlockFadeEvent e) {
|
||||||
|
|
||||||
|
Game game = BedwarsRel.getInstance().getGameManager()
|
||||||
|
.getGameByLocation(e.getBlock().getLocation());
|
||||||
|
if (game == null) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (game.getState() == GameState.STOPPED) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!game.getRegion().isPlacedBlock(e.getBlock())) {
|
||||||
|
e.setCancelled(true);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@EventHandler(ignoreCancelled = true)
|
||||||
|
public void onForm(BlockFormEvent form) {
|
||||||
|
|
||||||
|
if (form.getNewState().getType() != Material.SNOW) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
Game game =
|
||||||
|
BedwarsRel.getInstance().getGameManager().getGameByLocation(form.getBlock().getLocation());
|
||||||
|
if (game == null) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (game.getState() == GameState.STOPPED) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
form.setCancelled(true);
|
||||||
|
}
|
||||||
|
|
||||||
|
@EventHandler(ignoreCancelled = true)
|
||||||
|
public void onIgnite(BlockIgniteEvent ignite) {
|
||||||
|
|
||||||
|
if (ignite.getIgnitingBlock() == null && ignite.getIgnitingEntity() == null) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
Game game = null;
|
||||||
|
if (ignite.getIgnitingBlock() == null) {
|
||||||
|
if (ignite.getIgnitingEntity() instanceof Player) {
|
||||||
|
game = BedwarsRel.getInstance().getGameManager()
|
||||||
|
.getGameOfPlayer((Player) ignite.getIgnitingEntity());
|
||||||
|
} else {
|
||||||
|
game = BedwarsRel.getInstance().getGameManager()
|
||||||
|
.getGameByLocation(ignite.getIgnitingEntity().getLocation());
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
game = BedwarsRel.getInstance().getGameManager()
|
||||||
|
.getGameByLocation(ignite.getIgnitingBlock().getLocation());
|
||||||
|
}
|
||||||
|
|
||||||
|
if (game == null) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (game.getState() == GameState.STOPPED) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (ignite.getCause() == IgniteCause.ENDER_CRYSTAL || ignite.getCause() == IgniteCause.LIGHTNING
|
||||||
|
|| ignite.getCause() == IgniteCause.SPREAD) {
|
||||||
|
ignite.setCancelled(true);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (ignite.getIgnitingEntity() == null) {
|
||||||
|
ignite.setCancelled(true);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (game.getState() == GameState.WAITING) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!game.getRegion().isPlacedBlock(ignite.getIgnitingBlock())
|
||||||
|
&& ignite.getIgnitingBlock() != null) {
|
||||||
|
game.getRegion().addPlacedBlock(ignite.getIgnitingBlock(),
|
||||||
|
ignite.getIgnitingBlock().getState());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@EventHandler(priority = EventPriority.NORMAL)
|
||||||
|
public void onPlace(BlockPlaceEvent bpe) {
|
||||||
|
Player player = bpe.getPlayer();
|
||||||
|
Game game = BedwarsRel.getInstance().getGameManager().getGameOfPlayer(player);
|
||||||
|
|
||||||
|
if (game == null) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (game.getState() == GameState.STOPPED) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (game.getState() == GameState.WAITING) {
|
||||||
|
bpe.setCancelled(true);
|
||||||
|
bpe.setBuild(false);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (game.getState() == GameState.RUNNING) {
|
||||||
|
if (game.isSpectator(player)) {
|
||||||
|
bpe.setCancelled(true);
|
||||||
|
bpe.setBuild(false);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
Block placeBlock = bpe.getBlockPlaced();
|
||||||
|
BlockState replacedBlock = bpe.getBlockReplacedState();
|
||||||
|
|
||||||
|
if (placeBlock.getType() == game.getTargetMaterial()) {
|
||||||
|
bpe.setCancelled(true);
|
||||||
|
bpe.setBuild(false);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!game.getRegion().isInRegion(placeBlock.getLocation())) {
|
||||||
|
bpe.setCancelled(true);
|
||||||
|
bpe.setBuild(false);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (replacedBlock != null && !BedwarsRel
|
||||||
|
.getInstance().getBooleanConfig("place-in-liquid", true)
|
||||||
|
&& (replacedBlock.getType().equals(Material.WATER)
|
||||||
|
|| replacedBlock.getType().equals(Material.STATIONARY_WATER)
|
||||||
|
|| replacedBlock.getType().equals(Material.LAVA)
|
||||||
|
|| replacedBlock.getType().equals(Material.STATIONARY_LAVA))) {
|
||||||
|
bpe.setCancelled(true);
|
||||||
|
bpe.setBuild(false);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (replacedBlock != null && placeBlock.getType().equals(Material.WEB)
|
||||||
|
&& (replacedBlock.getType().equals(Material.WATER)
|
||||||
|
|| replacedBlock.getType().equals(Material.STATIONARY_WATER)
|
||||||
|
|| replacedBlock.getType().equals(Material.LAVA)
|
||||||
|
|| replacedBlock.getType().equals(Material.STATIONARY_LAVA))) {
|
||||||
|
bpe.setCancelled(true);
|
||||||
|
bpe.setBuild(false);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (placeBlock.getType() == Material.ENDER_CHEST) {
|
||||||
|
Team playerTeam = game.getPlayerTeam(player);
|
||||||
|
if (playerTeam.getInventory() == null) {
|
||||||
|
playerTeam.createTeamInventory();
|
||||||
|
}
|
||||||
|
|
||||||
|
playerTeam.addChest(placeBlock);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!bpe.isCancelled()) {
|
||||||
|
game.getRegion().addPlacedBlock(placeBlock,
|
||||||
|
(replacedBlock.getType().equals(Material.AIR) ? null : replacedBlock));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@EventHandler(ignoreCancelled = true)
|
||||||
|
public void onSpread(BlockSpreadEvent spread) {
|
||||||
|
|
||||||
|
if (spread.getBlock() == null) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
Game game =
|
||||||
|
BedwarsRel.getInstance().getGameManager()
|
||||||
|
.getGameByLocation(spread.getBlock().getLocation());
|
||||||
|
if (game == null) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (game.getState() != GameState.RUNNING) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (spread.getNewState() == null || spread.getSource() == null) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (spread.getNewState().getType().equals(Material.FIRE)) {
|
||||||
|
spread.setCancelled(true);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (game.getRegion().isPlacedBlock(spread.getSource())) {
|
||||||
|
game.getRegion().addPlacedBlock(spread.getBlock(), spread.getBlock().getState());
|
||||||
|
} else {
|
||||||
|
game.getRegion().addPlacedUnbreakableBlock(spread.getBlock(), spread.getBlock().getState());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@EventHandler(ignoreCancelled = true)
|
||||||
|
public void onStructureGrow(StructureGrowEvent grow) {
|
||||||
|
|
||||||
|
Game game = BedwarsRel.getInstance().getGameManager().getGameByLocation(grow.getLocation());
|
||||||
|
if (game == null) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
grow.setCancelled(true);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
@@ -0,0 +1,28 @@
|
|||||||
|
package io.github.bedwarsrel.listener;
|
||||||
|
|
||||||
|
import io.github.bedwarsrel.BedwarsRel;
|
||||||
|
import io.github.bedwarsrel.game.Game;
|
||||||
|
import io.github.bedwarsrel.game.GameState;
|
||||||
|
import org.bukkit.event.EventHandler;
|
||||||
|
import org.bukkit.event.Listener;
|
||||||
|
import org.bukkit.event.world.ChunkUnloadEvent;
|
||||||
|
|
||||||
|
public class ChunkListener implements Listener {
|
||||||
|
|
||||||
|
@EventHandler
|
||||||
|
public void onUnload(ChunkUnloadEvent unload) {
|
||||||
|
Game game = BedwarsRel.getInstance().getGameManager()
|
||||||
|
.getGameByChunkLocation(unload.getChunk().getX(),
|
||||||
|
unload.getChunk().getZ());
|
||||||
|
if (game == null) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (game.getState() != GameState.RUNNING) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
unload.setCancelled(true);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
@@ -0,0 +1,331 @@
|
|||||||
|
package io.github.bedwarsrel.listener;
|
||||||
|
|
||||||
|
import com.google.common.collect.ImmutableMap;
|
||||||
|
import io.github.bedwarsrel.BedwarsRel;
|
||||||
|
import io.github.bedwarsrel.game.Game;
|
||||||
|
import io.github.bedwarsrel.game.GameState;
|
||||||
|
import io.github.bedwarsrel.game.Team;
|
||||||
|
import io.github.bedwarsrel.game.TeamJoinMetaDataValue;
|
||||||
|
import io.github.bedwarsrel.utils.ChatWriter;
|
||||||
|
import io.github.bedwarsrel.utils.Utils;
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.Iterator;
|
||||||
|
import java.util.List;
|
||||||
|
import org.bukkit.ChatColor;
|
||||||
|
import org.bukkit.Material;
|
||||||
|
import org.bukkit.block.Block;
|
||||||
|
import org.bukkit.entity.Entity;
|
||||||
|
import org.bukkit.entity.EntityType;
|
||||||
|
import org.bukkit.entity.LivingEntity;
|
||||||
|
import org.bukkit.entity.Player;
|
||||||
|
import org.bukkit.entity.TNTPrimed;
|
||||||
|
import org.bukkit.event.EventHandler;
|
||||||
|
import org.bukkit.event.EventPriority;
|
||||||
|
import org.bukkit.event.entity.CreatureSpawnEvent;
|
||||||
|
import org.bukkit.event.entity.EntityDamageByEntityEvent;
|
||||||
|
import org.bukkit.event.entity.EntityDamageEvent;
|
||||||
|
import org.bukkit.event.entity.EntityExplodeEvent;
|
||||||
|
import org.bukkit.event.entity.EntityInteractEvent;
|
||||||
|
import org.bukkit.event.entity.EntityRegainHealthEvent;
|
||||||
|
import org.bukkit.event.player.PlayerInteractAtEntityEvent;
|
||||||
|
import org.bukkit.metadata.MetadataValue;
|
||||||
|
|
||||||
|
public class EntityListener extends BaseListener {
|
||||||
|
|
||||||
|
@EventHandler(priority = EventPriority.HIGHEST)
|
||||||
|
public void onEntityDamage(EntityDamageEvent ede) {
|
||||||
|
List<EntityType> canDamageTypes = new ArrayList<EntityType>();
|
||||||
|
canDamageTypes.add(EntityType.PLAYER);
|
||||||
|
|
||||||
|
if (BedwarsRel.getInstance().getServer().getPluginManager().isPluginEnabled("AntiAura")
|
||||||
|
|| BedwarsRel.getInstance().getServer().getPluginManager().isPluginEnabled("AAC")) {
|
||||||
|
canDamageTypes.add(EntityType.SQUID);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (canDamageTypes.contains(ede.getEntityType())) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
Game game =
|
||||||
|
BedwarsRel.getInstance().getGameManager().getGameByLocation(ede.getEntity().getLocation());
|
||||||
|
if (game == null) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (game.getState() == GameState.STOPPED) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
ede.setCancelled(true);
|
||||||
|
}
|
||||||
|
|
||||||
|
@EventHandler(priority = EventPriority.HIGHEST)
|
||||||
|
public void onEntityDamageByEntity(EntityDamageByEntityEvent ede) {
|
||||||
|
List<EntityType> canDamageTypes = new ArrayList<EntityType>();
|
||||||
|
canDamageTypes.add(EntityType.PLAYER);
|
||||||
|
|
||||||
|
if (BedwarsRel.getInstance().getServer().getPluginManager().isPluginEnabled("AntiAura")
|
||||||
|
|| BedwarsRel.getInstance().getServer().getPluginManager().isPluginEnabled("AAC")) {
|
||||||
|
canDamageTypes.add(EntityType.SQUID);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (canDamageTypes.contains(ede.getEntityType())) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
Game game =
|
||||||
|
BedwarsRel.getInstance().getGameManager().getGameByLocation(ede.getEntity().getLocation());
|
||||||
|
if (game == null) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (game.getState() == GameState.STOPPED) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
ede.setCancelled(true);
|
||||||
|
}
|
||||||
|
|
||||||
|
@EventHandler
|
||||||
|
public void onEntityInteract(EntityInteractEvent event) {
|
||||||
|
if (!(event.getEntity() instanceof Player)) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (event.getBlock().getType() != Material.SOIL
|
||||||
|
&& event.getBlock().getType() != Material.WHEAT) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
Player player = (Player) event.getEntity();
|
||||||
|
Game game = BedwarsRel.getInstance().getGameManager().getGameOfPlayer(player);
|
||||||
|
|
||||||
|
if (game == null) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (game.getState() == GameState.WAITING) {
|
||||||
|
event.setCancelled(true);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@EventHandler
|
||||||
|
public void onEntitySpawn(CreatureSpawnEvent ese) {
|
||||||
|
if (BedwarsRel.getInstance().getGameManager() == null) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (ese.getLocation() == null) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (ese.getLocation().getWorld() == null) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
Game game = BedwarsRel.getInstance().getGameManager().getGameByLocation(ese.getLocation());
|
||||||
|
if (game == null) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (game.getState() == GameState.STOPPED) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (ese.getEntityType().equals(EntityType.CREEPER)
|
||||||
|
|| ese.getEntityType().equals(EntityType.CAVE_SPIDER)
|
||||||
|
|| ese.getEntityType().equals(EntityType.SPIDER)
|
||||||
|
|| ese.getEntityType().equals(EntityType.ZOMBIE)
|
||||||
|
|| ese.getEntityType().equals(EntityType.SKELETON)
|
||||||
|
|| ese.getEntityType().equals(EntityType.SILVERFISH)) {
|
||||||
|
ese.setCancelled(true);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@EventHandler(priority = EventPriority.HIGHEST)
|
||||||
|
public void onExplodeDestroy(EntityExplodeEvent eev) {
|
||||||
|
if (eev.isCancelled()) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (eev.getEntity() == null) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (eev.getEntity().getWorld() == null) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
Game game =
|
||||||
|
BedwarsRel.getInstance().getGameManager().getGameByLocation(eev.getEntity().getLocation());
|
||||||
|
|
||||||
|
if (game == null) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (game.getState() == GameState.STOPPED) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
Iterator<Block> explodeBlocks = eev.blockList().iterator();
|
||||||
|
boolean tntDestroyEnabled =
|
||||||
|
BedwarsRel.getInstance().getBooleanConfig("explodes.destroy-worldblocks", false);
|
||||||
|
boolean tntDestroyBeds = BedwarsRel
|
||||||
|
.getInstance().getBooleanConfig("explodes.destroy-beds", false);
|
||||||
|
|
||||||
|
if (!BedwarsRel.getInstance().getBooleanConfig("explodes.drop-blocks", false)) {
|
||||||
|
eev.setYield(0F);
|
||||||
|
}
|
||||||
|
|
||||||
|
Material targetMaterial = game.getTargetMaterial();
|
||||||
|
while (explodeBlocks.hasNext()) {
|
||||||
|
Block exploding = explodeBlocks.next();
|
||||||
|
if (!game.getRegion().isInRegion(exploding.getLocation())) {
|
||||||
|
explodeBlocks.remove();
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
if ((!tntDestroyEnabled && !tntDestroyBeds) || (!tntDestroyEnabled && tntDestroyBeds
|
||||||
|
&& exploding.getType() != Material.BED_BLOCK && exploding.getType() != Material.BED)) {
|
||||||
|
if (!game.getRegion().isPlacedBlock(exploding)) {
|
||||||
|
if (BedwarsRel.getInstance().isBreakableType(exploding.getType())) {
|
||||||
|
game.getRegion().addBreakedBlock(exploding);
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
explodeBlocks.remove();
|
||||||
|
} else {
|
||||||
|
game.getRegion().removePlacedBlock(exploding);
|
||||||
|
}
|
||||||
|
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (game.getRegion().isPlacedBlock(exploding)) {
|
||||||
|
game.getRegion().removePlacedBlock(exploding);
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (exploding.getType().equals(targetMaterial)) {
|
||||||
|
if (!tntDestroyBeds) {
|
||||||
|
explodeBlocks.remove();
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
// only destroyable by tnt
|
||||||
|
if (!eev.getEntityType().equals(EntityType.PRIMED_TNT)
|
||||||
|
&& !eev.getEntityType().equals(EntityType.MINECART_TNT)) {
|
||||||
|
explodeBlocks.remove();
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
// when it wasn't player who ignited the tnt
|
||||||
|
TNTPrimed primedTnt = (TNTPrimed) eev.getEntity();
|
||||||
|
if (!(primedTnt.getSource() instanceof Player)) {
|
||||||
|
explodeBlocks.remove();
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
Player p = (Player) primedTnt.getSource();
|
||||||
|
if (!game.handleDestroyTargetMaterial(p, exploding)) {
|
||||||
|
explodeBlocks.remove();
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
game.getRegion().addBreakedBlock(exploding);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@EventHandler(priority = EventPriority.HIGH)
|
||||||
|
public void onInteractEntity(PlayerInteractAtEntityEvent event) {
|
||||||
|
if (event.getRightClicked() == null) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
Entity entity = event.getRightClicked();
|
||||||
|
Player player = event.getPlayer();
|
||||||
|
if (!player.hasMetadata("bw-addteamjoin")) {
|
||||||
|
if (!(entity instanceof LivingEntity)) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
LivingEntity livEntity = (LivingEntity) entity;
|
||||||
|
Game game = BedwarsRel.getInstance().getGameManager().getGameOfPlayer(player);
|
||||||
|
if (game == null) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (game.getState() != GameState.WAITING) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
Team team = game.getTeam(ChatColor.stripColor(livEntity.getCustomName()));
|
||||||
|
if (team == null) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
game.playerJoinTeam(player, team);
|
||||||
|
event.setCancelled(true);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
List<MetadataValue> values = player.getMetadata("bw-addteamjoin");
|
||||||
|
if (values == null || values.size() == 0) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
event.setCancelled(true);
|
||||||
|
TeamJoinMetaDataValue value = (TeamJoinMetaDataValue) values.get(0);
|
||||||
|
if (!((boolean) value.value())) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!(entity instanceof LivingEntity)) {
|
||||||
|
player.sendMessage(
|
||||||
|
ChatWriter.pluginMessage(ChatColor.RED + BedwarsRel
|
||||||
|
._l(player, "errors.entitynotcompatible")));
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
LivingEntity living = (LivingEntity) entity;
|
||||||
|
living.setRemoveWhenFarAway(false);
|
||||||
|
living.setCanPickupItems(false);
|
||||||
|
living.setCustomName(value.getTeam().getChatColor() + value.getTeam().getDisplayName());
|
||||||
|
living.setCustomNameVisible(
|
||||||
|
BedwarsRel.getInstance().getBooleanConfig("jointeam-entity.show-name", true));
|
||||||
|
|
||||||
|
if (living.getType().equals(EntityType.valueOf("ARMOR_STAND"))) {
|
||||||
|
Utils.equipArmorStand(living, value.getTeam());
|
||||||
|
}
|
||||||
|
|
||||||
|
player.removeMetadata("bw-addteamjoin", BedwarsRel.getInstance());
|
||||||
|
player.sendMessage(ChatWriter
|
||||||
|
.pluginMessage(
|
||||||
|
ChatColor.GREEN + BedwarsRel._l(player, "success.teamjoinadded", ImmutableMap.of("team",
|
||||||
|
value.getTeam().getChatColor() + value.getTeam().getDisplayName()
|
||||||
|
+ ChatColor.GREEN))));
|
||||||
|
}
|
||||||
|
|
||||||
|
@EventHandler(priority = EventPriority.HIGH)
|
||||||
|
public void onRegainHealth(EntityRegainHealthEvent rhe) {
|
||||||
|
if (rhe.getEntityType() != EntityType.PLAYER) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
Player player = (Player) rhe.getEntity();
|
||||||
|
Game game = BedwarsRel.getInstance().getGameManager().getGameOfPlayer(player);
|
||||||
|
|
||||||
|
if (game == null) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (game.getState() != GameState.RUNNING) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (player.getHealth() >= player.getMaxHealth()) {
|
||||||
|
game.setPlayerDamager(player, null);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,22 @@
|
|||||||
|
package io.github.bedwarsrel.listener;
|
||||||
|
|
||||||
|
import org.bukkit.entity.Hanging;
|
||||||
|
import org.bukkit.event.EventHandler;
|
||||||
|
import org.bukkit.event.EventPriority;
|
||||||
|
import org.bukkit.event.hanging.HangingBreakEvent;
|
||||||
|
import org.bukkit.event.hanging.HangingBreakEvent.RemoveCause;
|
||||||
|
|
||||||
|
public class HangingListener extends BaseListener {
|
||||||
|
|
||||||
|
@EventHandler(priority = EventPriority.HIGHEST)
|
||||||
|
public void onHangingBreak(HangingBreakEvent event) {
|
||||||
|
Hanging hanging = event.getEntity();
|
||||||
|
if (event.getCause().equals(RemoveCause.OBSTRUCTION)) {
|
||||||
|
hanging.getLocation().getBlock().breakNaturally();
|
||||||
|
event.setCancelled(true);
|
||||||
|
} else if (event.getCause().equals(RemoveCause.EXPLOSION)) {
|
||||||
|
event.setCancelled(true);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,30 @@
|
|||||||
|
package io.github.bedwarsrel.listener;
|
||||||
|
|
||||||
|
import io.github.bedwarsrel.BedwarsRel;
|
||||||
|
import io.github.bedwarsrel.game.BungeeGameCycle;
|
||||||
|
import io.github.bedwarsrel.game.Game;
|
||||||
|
import io.github.bedwarsrel.game.GameState;
|
||||||
|
import org.bukkit.entity.Player;
|
||||||
|
import org.bukkit.event.EventHandler;
|
||||||
|
import org.bukkit.event.player.PlayerSwapHandItemsEvent;
|
||||||
|
|
||||||
|
public class Player19Listener extends BaseListener {
|
||||||
|
|
||||||
|
@EventHandler
|
||||||
|
public void onPlayerSwapHandItems(PlayerSwapHandItemsEvent event) {
|
||||||
|
Player player = event.getPlayer();
|
||||||
|
Game game = BedwarsRel.getInstance().getGameManager().getGameOfPlayer(player);
|
||||||
|
|
||||||
|
if (game == null) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (game.getState() == GameState.WAITING
|
||||||
|
|| (game.getCycle() instanceof BungeeGameCycle && game.getCycle().isEndGameRunning()
|
||||||
|
&& BedwarsRel.getInstance().getBooleanConfig("bungeecord.endgame-in-lobby", true))) {
|
||||||
|
event.setCancelled(true);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
File diff suppressed because it is too large
Load Diff
@@ -0,0 +1,29 @@
|
|||||||
|
package io.github.bedwarsrel.listener;
|
||||||
|
|
||||||
|
import io.github.bedwarsrel.BedwarsRel;
|
||||||
|
import io.github.bedwarsrel.game.Game;
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import org.bukkit.entity.Player;
|
||||||
|
import org.bukkit.event.EventHandler;
|
||||||
|
import org.bukkit.event.EventPriority;
|
||||||
|
import org.spigotmc.event.player.PlayerSpawnLocationEvent;
|
||||||
|
|
||||||
|
public class PlayerSpigotListener extends BaseListener {
|
||||||
|
|
||||||
|
@EventHandler(priority = EventPriority.HIGH)
|
||||||
|
public void onPlayerSpawnLocation(PlayerSpawnLocationEvent event) {
|
||||||
|
if (BedwarsRel.getInstance().isBungee()) {
|
||||||
|
Player player = event.getPlayer();
|
||||||
|
|
||||||
|
ArrayList<Game> games = BedwarsRel.getInstance().getGameManager().getGames();
|
||||||
|
if (games.size() == 0) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
Game firstGame = games.get(0);
|
||||||
|
|
||||||
|
event.setSpawnLocation(firstGame.getPlayerTeleportLocation(player));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
@@ -0,0 +1,101 @@
|
|||||||
|
package io.github.bedwarsrel.listener;
|
||||||
|
|
||||||
|
import io.github.bedwarsrel.BedwarsRel;
|
||||||
|
import io.github.bedwarsrel.game.Game;
|
||||||
|
import io.github.bedwarsrel.game.GameState;
|
||||||
|
import org.bukkit.ChatColor;
|
||||||
|
import org.bukkit.event.EventHandler;
|
||||||
|
import org.bukkit.event.server.ServerListPingEvent;
|
||||||
|
|
||||||
|
public class ServerListener extends BaseListener {
|
||||||
|
|
||||||
|
private String getCurrentPlayersString(Game game) {
|
||||||
|
int currentPlayers = 0;
|
||||||
|
if (game.getState() == GameState.RUNNING) {
|
||||||
|
currentPlayers = game.getTeamPlayers().size();
|
||||||
|
} else if (game.getState() == GameState.WAITING) {
|
||||||
|
currentPlayers = game.getPlayers().size();
|
||||||
|
} else {
|
||||||
|
currentPlayers = 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
return String.valueOf(currentPlayers);
|
||||||
|
}
|
||||||
|
|
||||||
|
private String getMaxPlayersString(Game game) {
|
||||||
|
int maxPlayers = game.getMaxPlayers();
|
||||||
|
return String.valueOf(maxPlayers);
|
||||||
|
}
|
||||||
|
|
||||||
|
private String getStatus(Game game) {
|
||||||
|
String status = null;
|
||||||
|
if (game.getState() == GameState.WAITING && game.isFull()) {
|
||||||
|
status = ChatColor.RED + BedwarsRel._l("sign.gamestate.full");
|
||||||
|
} else {
|
||||||
|
status = BedwarsRel._l("sign.gamestate." + game.getState().toString().toLowerCase());
|
||||||
|
}
|
||||||
|
|
||||||
|
return status;
|
||||||
|
}
|
||||||
|
|
||||||
|
@EventHandler
|
||||||
|
public void onServerListPing(ServerListPingEvent slpe) {
|
||||||
|
// Only enabled on bungeecord
|
||||||
|
if (!BedwarsRel.getInstance().isBungee()) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
if (BedwarsRel.getInstance().getGameManager() == null
|
||||||
|
|| BedwarsRel.getInstance().getGameManager().getGames() == null
|
||||||
|
|| BedwarsRel.getInstance().getGameManager().getGames().size() == 0) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
Game game = BedwarsRel.getInstance().getGameManager().getGames().get(0);
|
||||||
|
|
||||||
|
if (game == null) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
switch (game.getState()) {
|
||||||
|
case STOPPED:
|
||||||
|
slpe.setMotd(replacePlaceholder(game, ChatColor.translateAlternateColorCodes('&',
|
||||||
|
BedwarsRel.getInstance().getConfig().getString("bungeecord.motds.stopped"))));
|
||||||
|
break;
|
||||||
|
case WAITING:
|
||||||
|
if (game.isFull()) {
|
||||||
|
slpe.setMotd(replacePlaceholder(game, ChatColor.translateAlternateColorCodes('&',
|
||||||
|
BedwarsRel.getInstance().getConfig().getString("bungeecord.motds.full"))));
|
||||||
|
} else {
|
||||||
|
slpe.setMotd(replacePlaceholder(game, ChatColor.translateAlternateColorCodes('&',
|
||||||
|
BedwarsRel.getInstance().getConfig().getString("bungeecord.motds.lobby"))));
|
||||||
|
}
|
||||||
|
|
||||||
|
break;
|
||||||
|
case RUNNING:
|
||||||
|
slpe.setMotd(replacePlaceholder(game, ChatColor.translateAlternateColorCodes('&',
|
||||||
|
BedwarsRel.getInstance().getConfig().getString("bungeecord.motds.running"))));
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
slpe.setMotd(ChatColor.RED + "INVALID GAME STATE!");
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private String replacePlaceholder(Game game, String line) {
|
||||||
|
String finalLine = line;
|
||||||
|
|
||||||
|
finalLine = finalLine.replace("$title$", BedwarsRel._l("sign.firstline"));
|
||||||
|
finalLine = finalLine.replace("$gamename$", game.getName());
|
||||||
|
if (game.getRegion().getName() != null) {
|
||||||
|
finalLine = finalLine.replace("$regionname$", game.getRegion().getName());
|
||||||
|
} else {
|
||||||
|
finalLine = finalLine.replace("$regionname$", game.getName());
|
||||||
|
}
|
||||||
|
finalLine = finalLine.replace("$maxplayers$", getMaxPlayersString(game));
|
||||||
|
finalLine = finalLine.replace("$currentplayers$", getCurrentPlayersString(game));
|
||||||
|
finalLine = finalLine.replace("$status$", getStatus(game));
|
||||||
|
|
||||||
|
return finalLine;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
@@ -0,0 +1,49 @@
|
|||||||
|
package io.github.bedwarsrel.listener;
|
||||||
|
|
||||||
|
import io.github.bedwarsrel.BedwarsRel;
|
||||||
|
import io.github.bedwarsrel.game.Game;
|
||||||
|
import org.bukkit.ChatColor;
|
||||||
|
import org.bukkit.entity.Player;
|
||||||
|
import org.bukkit.event.EventHandler;
|
||||||
|
import org.bukkit.event.block.SignChangeEvent;
|
||||||
|
|
||||||
|
public class SignListener extends BaseListener {
|
||||||
|
|
||||||
|
@EventHandler
|
||||||
|
public void onSignChange(SignChangeEvent sce) {
|
||||||
|
String firstLine = sce.getLine(0).trim();
|
||||||
|
if (!"[bw]".equals(firstLine)) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
Player player = sce.getPlayer();
|
||||||
|
if (!player.hasPermission("bw.setup")) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
String gameName = sce.getLine(1).trim();
|
||||||
|
Game game = BedwarsRel.getInstance().getGameManager().getGame(gameName);
|
||||||
|
|
||||||
|
if (game == null) {
|
||||||
|
String notfound = BedwarsRel._l("errors.gamenotfoundsimple");
|
||||||
|
if (notfound.length() > 16) {
|
||||||
|
String[] splitted = notfound.split(" ", 4);
|
||||||
|
for (int i = 0; i < splitted.length; i++) {
|
||||||
|
sce.setLine(i, ChatColor.RED + splitted[i]);
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
sce.setLine(0, ChatColor.RED + notfound);
|
||||||
|
sce.setLine(1, "");
|
||||||
|
sce.setLine(2, "");
|
||||||
|
sce.setLine(3, "");
|
||||||
|
}
|
||||||
|
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
sce.setCancelled(true);
|
||||||
|
game.addJoinSign(sce.getBlock().getLocation());
|
||||||
|
game.updateSigns();
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
@@ -0,0 +1,32 @@
|
|||||||
|
package io.github.bedwarsrel.listener;
|
||||||
|
|
||||||
|
import io.github.bedwarsrel.BedwarsRel;
|
||||||
|
import io.github.bedwarsrel.game.Game;
|
||||||
|
import io.github.bedwarsrel.game.GameState;
|
||||||
|
import java.util.List;
|
||||||
|
import org.bukkit.event.EventHandler;
|
||||||
|
import org.bukkit.event.weather.WeatherChangeEvent;
|
||||||
|
|
||||||
|
public class WeatherListener extends BaseListener {
|
||||||
|
|
||||||
|
@EventHandler
|
||||||
|
public void onWeatherEvent(WeatherChangeEvent we) {
|
||||||
|
if (we.isCancelled()) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
List<Game> games = BedwarsRel.getInstance().getGameManager().getGamesByWorld(we.getWorld());
|
||||||
|
|
||||||
|
if (games.size() == 0) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
for (Game game : games) {
|
||||||
|
if (game.getState() != GameState.STOPPED) {
|
||||||
|
we.setCancelled(true);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
@@ -0,0 +1,120 @@
|
|||||||
|
package io.github.bedwarsrel.localization;
|
||||||
|
|
||||||
|
import io.github.bedwarsrel.BedwarsRel;
|
||||||
|
import io.github.bedwarsrel.utils.ChatWriter;
|
||||||
|
import java.io.BufferedReader;
|
||||||
|
import java.io.File;
|
||||||
|
import java.io.FileInputStream;
|
||||||
|
import java.io.FileNotFoundException;
|
||||||
|
import java.io.IOException;
|
||||||
|
import java.io.InputStream;
|
||||||
|
import java.io.InputStreamReader;
|
||||||
|
import java.lang.reflect.Field;
|
||||||
|
import java.lang.reflect.Method;
|
||||||
|
import java.util.Map;
|
||||||
|
import org.bukkit.ChatColor;
|
||||||
|
import org.bukkit.configuration.file.YamlConfiguration;
|
||||||
|
import org.bukkit.entity.Player;
|
||||||
|
|
||||||
|
public class LocalizationConfig extends YamlConfiguration {
|
||||||
|
|
||||||
|
private String locale;
|
||||||
|
|
||||||
|
public LocalizationConfig(String locale) {
|
||||||
|
this.locale = locale;
|
||||||
|
this.loadLocale();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Object get(String path) {
|
||||||
|
return this.getString(path);
|
||||||
|
}
|
||||||
|
|
||||||
|
public Object get(String path, Map<String, String> params) {
|
||||||
|
return this.getFormatString(path, params);
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getFormatString(String path, Map<String, String> params) {
|
||||||
|
String str = this.getString(path);
|
||||||
|
for (String key : params.keySet()) {
|
||||||
|
str = str.replace("$" + key.toLowerCase() + "$", params.get(key));
|
||||||
|
}
|
||||||
|
|
||||||
|
return ChatColor.translateAlternateColorCodes('&', str);
|
||||||
|
}
|
||||||
|
|
||||||
|
@SuppressWarnings("unchecked")
|
||||||
|
public String getPlayerLocale(Player player) {
|
||||||
|
try {
|
||||||
|
Method getHandleMethod = BedwarsRel.getInstance().getCraftBukkitClass("entity.CraftPlayer")
|
||||||
|
.getMethod("getHandle", new Class[]{});
|
||||||
|
getHandleMethod.setAccessible(true);
|
||||||
|
Object nmsPlayer = getHandleMethod.invoke(player, new Object[]{});
|
||||||
|
|
||||||
|
Field localeField = nmsPlayer.getClass().getDeclaredField("locale");
|
||||||
|
localeField.setAccessible(true);
|
||||||
|
return localeField.get(nmsPlayer).toString().split("_")[0].toLowerCase();
|
||||||
|
} catch (Exception ex) {
|
||||||
|
BedwarsRel.getInstance().getBugsnag().notify(ex);
|
||||||
|
return BedwarsRel.getInstance().getFallbackLocale();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String getString(String path) {
|
||||||
|
if (super.get(path) == null) {
|
||||||
|
BedwarsRel.getInstance().getServer().getConsoleSender()
|
||||||
|
.sendMessage(ChatWriter
|
||||||
|
.pluginMessage(ChatColor.GOLD + "No translation found for: \"" + path + "\""));
|
||||||
|
return "LOCALE_NOT_FOUND";
|
||||||
|
}
|
||||||
|
|
||||||
|
return ChatColor.translateAlternateColorCodes('&', super.getString(path));
|
||||||
|
}
|
||||||
|
|
||||||
|
public void loadLocale() {
|
||||||
|
File locFile =
|
||||||
|
new File(
|
||||||
|
BedwarsRel.getInstance().getDataFolder().getPath() + "/locale/" + this.locale + ".yml");
|
||||||
|
BufferedReader reader = null;
|
||||||
|
InputStream inputStream = null;
|
||||||
|
if (locFile.exists()) {
|
||||||
|
try {
|
||||||
|
inputStream = new FileInputStream(locFile);
|
||||||
|
} catch (FileNotFoundException e) {
|
||||||
|
// NO ERROR
|
||||||
|
}
|
||||||
|
BedwarsRel.getInstance().getServer().getConsoleSender().sendMessage(ChatWriter
|
||||||
|
.pluginMessage(ChatColor.GOLD + "Using your custom locale \"" + this.locale + "\"."));
|
||||||
|
} else {
|
||||||
|
if (inputStream == null) {
|
||||||
|
inputStream = BedwarsRel.getInstance().getResource("locale/" + this.locale + ".yml");
|
||||||
|
}
|
||||||
|
if (inputStream == null) {
|
||||||
|
BedwarsRel.getInstance().getServer().getConsoleSender()
|
||||||
|
.sendMessage(ChatWriter.pluginMessage(ChatColor.GOLD + "The locale \"" + this.locale
|
||||||
|
+ "\" defined in your config is not available. Using fallback locale: "
|
||||||
|
+ BedwarsRel.getInstance().getFallbackLocale()));
|
||||||
|
inputStream = BedwarsRel.getInstance()
|
||||||
|
.getResource("locale/" + BedwarsRel.getInstance().getFallbackLocale() + ".yml");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
try {
|
||||||
|
reader = new BufferedReader(new InputStreamReader(inputStream, "UTF-8"));
|
||||||
|
this.load(reader);
|
||||||
|
} catch (Exception e) {
|
||||||
|
BedwarsRel.getInstance().getServer().getConsoleSender().sendMessage(
|
||||||
|
ChatWriter.pluginMessage(ChatColor.RED + "Failed to load localization language!"));
|
||||||
|
return;
|
||||||
|
} finally {
|
||||||
|
if (reader != null) {
|
||||||
|
try {
|
||||||
|
reader.close();
|
||||||
|
} catch (IOException e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
605
common/src/main/java/io/github/bedwarsrel/shop/NewItemShop.java
Normal file
605
common/src/main/java/io/github/bedwarsrel/shop/NewItemShop.java
Normal file
@@ -0,0 +1,605 @@
|
|||||||
|
package io.github.bedwarsrel.shop;
|
||||||
|
|
||||||
|
import io.github.bedwarsrel.BedwarsRel;
|
||||||
|
import io.github.bedwarsrel.game.Game;
|
||||||
|
import io.github.bedwarsrel.utils.ChatWriter;
|
||||||
|
import io.github.bedwarsrel.utils.SoundMachine;
|
||||||
|
import io.github.bedwarsrel.utils.Utils;
|
||||||
|
import io.github.bedwarsrel.villager.MerchantCategory;
|
||||||
|
import io.github.bedwarsrel.villager.VillagerTrade;
|
||||||
|
import java.lang.reflect.Method;
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.HashMap;
|
||||||
|
import java.util.Iterator;
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.Map.Entry;
|
||||||
|
import org.bukkit.Bukkit;
|
||||||
|
import org.bukkit.ChatColor;
|
||||||
|
import org.bukkit.Material;
|
||||||
|
import org.bukkit.enchantments.Enchantment;
|
||||||
|
import org.bukkit.entity.Player;
|
||||||
|
import org.bukkit.event.inventory.InventoryClickEvent;
|
||||||
|
import org.bukkit.inventory.Inventory;
|
||||||
|
import org.bukkit.inventory.ItemFlag;
|
||||||
|
import org.bukkit.inventory.ItemStack;
|
||||||
|
import org.bukkit.inventory.PlayerInventory;
|
||||||
|
import org.bukkit.inventory.meta.ItemMeta;
|
||||||
|
import org.bukkit.inventory.meta.PotionMeta;
|
||||||
|
|
||||||
|
public class NewItemShop {
|
||||||
|
|
||||||
|
private List<MerchantCategory> categories = null;
|
||||||
|
private MerchantCategory currentCategory = null;
|
||||||
|
|
||||||
|
public NewItemShop(List<MerchantCategory> categories) {
|
||||||
|
this.categories = categories;
|
||||||
|
}
|
||||||
|
|
||||||
|
@SuppressWarnings("deprecation")
|
||||||
|
private void addCategoriesToInventory(Inventory inventory, Player player, Game game) {
|
||||||
|
for (MerchantCategory category : this.categories) {
|
||||||
|
|
||||||
|
if (category.getMaterial() == null) {
|
||||||
|
BedwarsRel.getInstance().getServer().getConsoleSender()
|
||||||
|
.sendMessage(ChatWriter.pluginMessage(ChatColor.RED
|
||||||
|
+ "Careful: Not supported material in shop category '" + category.getName() + "'"));
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (player != null && !player.hasPermission(category.getPermission())) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
ItemStack is = new ItemStack(category.getMaterial(), 1);
|
||||||
|
ItemMeta im = is.getItemMeta();
|
||||||
|
|
||||||
|
if (Utils.isColorable(is)) {
|
||||||
|
is.setDurability(game.getPlayerTeam(player).getColor().getDyeColor().getWoolData());
|
||||||
|
}
|
||||||
|
if (this.currentCategory != null && this.currentCategory.equals(category)) {
|
||||||
|
im.addEnchant(Enchantment.DAMAGE_ALL, 1, true);
|
||||||
|
im.addItemFlags(ItemFlag.HIDE_ENCHANTS);
|
||||||
|
}
|
||||||
|
|
||||||
|
im.setDisplayName(category.getName());
|
||||||
|
im.setLore(category.getLores());
|
||||||
|
im.addItemFlags(ItemFlag.HIDE_ATTRIBUTES, ItemFlag.HIDE_POTION_EFFECTS);
|
||||||
|
is.setItemMeta(im);
|
||||||
|
|
||||||
|
inventory.addItem(is);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
@SuppressWarnings("unchecked")
|
||||||
|
private boolean buyItem(VillagerTrade trade, ItemStack item, Player player, Game game) {
|
||||||
|
PlayerInventory inventory = player.getInventory();
|
||||||
|
boolean success = true;
|
||||||
|
|
||||||
|
int item1ToPay = trade.getItem1().getAmount();
|
||||||
|
Iterator<?> stackIterator = inventory.all(trade.getItem1().getType()).entrySet().iterator();
|
||||||
|
|
||||||
|
int firstItem1 = inventory.first(trade.getItem1());
|
||||||
|
if (firstItem1 > -1) {
|
||||||
|
inventory.clear(firstItem1);
|
||||||
|
} else {
|
||||||
|
// pay
|
||||||
|
while (stackIterator.hasNext()) {
|
||||||
|
Entry<Integer, ? extends ItemStack> entry =
|
||||||
|
(Entry<Integer, ? extends ItemStack>) stackIterator.next();
|
||||||
|
ItemStack stack = (ItemStack) entry.getValue();
|
||||||
|
|
||||||
|
int endAmount = stack.getAmount() - item1ToPay;
|
||||||
|
if (endAmount < 0) {
|
||||||
|
endAmount = 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
item1ToPay = item1ToPay - stack.getAmount();
|
||||||
|
stack.setAmount(endAmount);
|
||||||
|
inventory.setItem(entry.getKey(), stack);
|
||||||
|
|
||||||
|
if (item1ToPay <= 0) {
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (trade.getItem2() != null) {
|
||||||
|
int item2ToPay = trade.getItem2().getAmount();
|
||||||
|
stackIterator = inventory.all(trade.getItem2().getType()).entrySet().iterator();
|
||||||
|
|
||||||
|
int firstItem2 = inventory.first(trade.getItem2());
|
||||||
|
if (firstItem2 > -1) {
|
||||||
|
inventory.clear(firstItem2);
|
||||||
|
} else {
|
||||||
|
// pay item2
|
||||||
|
while (stackIterator.hasNext()) {
|
||||||
|
Entry<Integer, ? extends ItemStack> entry =
|
||||||
|
(Entry<Integer, ? extends ItemStack>) stackIterator.next();
|
||||||
|
ItemStack stack = (ItemStack) entry.getValue();
|
||||||
|
|
||||||
|
int endAmount = stack.getAmount() - item2ToPay;
|
||||||
|
if (endAmount < 0) {
|
||||||
|
endAmount = 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
item2ToPay = item2ToPay - stack.getAmount();
|
||||||
|
stack.setAmount(endAmount);
|
||||||
|
inventory.setItem(entry.getKey(), stack);
|
||||||
|
|
||||||
|
if (item2ToPay <= 0) {
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (trade.hasCommands()) {
|
||||||
|
BedwarsRel.getInstance().getServer().getConsoleSender().sendMessage(
|
||||||
|
ChatColor.GREEN + "[BW-Shop] 准备执行 " + trade.getCommands().size() + " 条命令,玩家: " + player.getName());
|
||||||
|
for (String command : trade.getCommands()) {
|
||||||
|
String formattedCommand = command.replace("%player%", player.getName());
|
||||||
|
BedwarsRel.getInstance().getServer().getConsoleSender().sendMessage(
|
||||||
|
ChatColor.GREEN + "[BW-Shop] 正在推送到控制台: " + formattedCommand);
|
||||||
|
boolean cmdSuccess = Bukkit.dispatchCommand(Bukkit.getConsoleSender(), formattedCommand);
|
||||||
|
BedwarsRel.getInstance().getServer().getConsoleSender().sendMessage(
|
||||||
|
ChatColor.GREEN + "[BW-Shop] 命令执行结果: " + (cmdSuccess ? "成功" : "失败"));
|
||||||
|
}
|
||||||
|
BedwarsRel.getInstance().getServer().getConsoleSender().sendMessage(
|
||||||
|
ChatColor.GREEN + "[BW-Shop] 所有命令执行完毕");
|
||||||
|
} else {
|
||||||
|
BedwarsRel.getInstance().getServer().getConsoleSender().sendMessage(
|
||||||
|
ChatColor.YELLOW + "[BW-Shop] 该物品没有命令,将直接给予物品");
|
||||||
|
ItemStack addingItem = item.clone();
|
||||||
|
ItemMeta meta = addingItem.getItemMeta();
|
||||||
|
List<String> lore = meta.getLore();
|
||||||
|
|
||||||
|
if (lore.size() > 0) {
|
||||||
|
lore.remove(lore.size() - 1);
|
||||||
|
if (trade.getItem2() != null) {
|
||||||
|
lore.remove(lore.size() - 1);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
meta.setLore(lore);
|
||||||
|
addingItem.setItemMeta(meta);
|
||||||
|
|
||||||
|
HashMap<Integer, ItemStack> notStored = inventory.addItem(addingItem);
|
||||||
|
if (notStored.size() > 0) {
|
||||||
|
ItemStack notAddedItem = notStored.get(0);
|
||||||
|
int removingAmount = addingItem.getAmount() - notAddedItem.getAmount();
|
||||||
|
addingItem.setAmount(removingAmount);
|
||||||
|
inventory.removeItem(addingItem);
|
||||||
|
|
||||||
|
// restore
|
||||||
|
inventory.addItem(trade.getItem1());
|
||||||
|
if (trade.getItem2() != null) {
|
||||||
|
inventory.addItem(trade.getItem2());
|
||||||
|
}
|
||||||
|
|
||||||
|
success = false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
player.updateInventory();
|
||||||
|
return success;
|
||||||
|
}
|
||||||
|
|
||||||
|
private void changeToOldShop(Game game, Player player) {
|
||||||
|
game.getPlayerSettings(player).setUseOldShop(true);
|
||||||
|
|
||||||
|
player.playSound(player.getLocation(), SoundMachine.get("CLICK", "UI_BUTTON_CLICK"),
|
||||||
|
Float.valueOf("1.0"), Float.valueOf("1.0"));
|
||||||
|
|
||||||
|
// open old shop
|
||||||
|
MerchantCategory.openCategorySelection(player, game);
|
||||||
|
}
|
||||||
|
|
||||||
|
private int getBuyInventorySize(int sizeCategories, int sizeOffers) {
|
||||||
|
return this.getInventorySize(sizeCategories) + this.getInventorySize(sizeOffers);
|
||||||
|
}
|
||||||
|
|
||||||
|
public List<MerchantCategory> getCategories() {
|
||||||
|
return this.categories;
|
||||||
|
}
|
||||||
|
|
||||||
|
private int getCategoriesSize(Player player) {
|
||||||
|
int size = 0;
|
||||||
|
for (MerchantCategory cat : this.categories) {
|
||||||
|
if (cat.getMaterial() == null) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (player != null && !player.hasPermission(cat.getPermission())) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
size++;
|
||||||
|
}
|
||||||
|
|
||||||
|
return size;
|
||||||
|
}
|
||||||
|
|
||||||
|
private MerchantCategory getCategoryByMaterial(Material material) {
|
||||||
|
for (MerchantCategory category : this.categories) {
|
||||||
|
if (category.getMaterial() == material) {
|
||||||
|
return category;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
private int getInventorySize(int itemAmount) {
|
||||||
|
int nom = (itemAmount % 9 == 0) ? 9 : (itemAmount % 9);
|
||||||
|
return itemAmount + (9 - nom);
|
||||||
|
}
|
||||||
|
|
||||||
|
private VillagerTrade getTradingItem(MerchantCategory category, ItemStack stack, Game game,
|
||||||
|
Player player) {
|
||||||
|
for (VillagerTrade trade : category.getOffers()) {
|
||||||
|
if (trade.getItem1().getType() == Material.AIR
|
||||||
|
&& trade.getRewardItem().getType() == Material.AIR) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
// 获取原始奖励物品(不经过toItemStack处理)
|
||||||
|
ItemStack reward = trade.getRewardItem();
|
||||||
|
|
||||||
|
// 首先比较类型
|
||||||
|
if (reward.getType() != stack.getType()) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
// 对于药水类特殊处理
|
||||||
|
if (reward.getType() == Material.POTION
|
||||||
|
|| (!BedwarsRel.getInstance().getCurrentVersion().startsWith("v1_8")
|
||||||
|
&& (reward.getType().equals(Material.valueOf("TIPPED_ARROW"))
|
||||||
|
|| reward.getType().equals(Material.valueOf("LINGERING_POTION"))
|
||||||
|
|| reward.getType().equals(Material.valueOf("SPLASH_POTION"))))) {
|
||||||
|
if (BedwarsRel.getInstance().getCurrentVersion().startsWith("v1_8")) {
|
||||||
|
if (reward.getItemMeta().equals(stack.getItemMeta())) {
|
||||||
|
return trade;
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
PotionMeta rewardMeta = (PotionMeta) reward.getItemMeta();
|
||||||
|
PotionMeta stackMeta = (PotionMeta) stack.getItemMeta();
|
||||||
|
if (rewardMeta.getBasePotionData().equals(stackMeta.getBasePotionData()) && rewardMeta
|
||||||
|
.getCustomEffects().equals(stackMeta.getCustomEffects())) {
|
||||||
|
return trade;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
// 对于普通物品,比较显示名和基础属性
|
||||||
|
ItemMeta rewardMeta = reward.getItemMeta();
|
||||||
|
ItemMeta stackMeta = stack.getItemMeta();
|
||||||
|
|
||||||
|
String rewardName = rewardMeta != null ? rewardMeta.getDisplayName() : null;
|
||||||
|
String stackName = stackMeta != null ? stackMeta.getDisplayName() : null;
|
||||||
|
|
||||||
|
// 比较显示名
|
||||||
|
if ((rewardName == null && stackName == null) ||
|
||||||
|
(rewardName != null && rewardName.equals(stackName))) {
|
||||||
|
// 输出匹配的物品信息
|
||||||
|
BedwarsRel.getInstance().getServer().getConsoleSender().sendMessage(
|
||||||
|
ChatColor.YELLOW + "[BW-Shop] 找到匹配物品: 名称='" + rewardName + "', 类型=" + reward.getType() +
|
||||||
|
", 是否有命令=" + trade.hasCommands());
|
||||||
|
return trade;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
BedwarsRel.getInstance().getServer().getConsoleSender().sendMessage(
|
||||||
|
ChatColor.RED + "[BW-Shop] 未找到匹配物品");
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
private void handleBuyInventoryClick(InventoryClickEvent ice, Game game, Player player) {
|
||||||
|
int sizeCategories = this.getCategoriesSize(player);
|
||||||
|
List<VillagerTrade> offers = this.currentCategory.getOffers();
|
||||||
|
int sizeItems = offers.size();
|
||||||
|
int invSizeCategories = this.getInventorySize(sizeCategories);
|
||||||
|
int totalSize = this.getBuyInventorySize(sizeCategories, sizeItems);
|
||||||
|
|
||||||
|
ItemStack item = ice.getCurrentItem();
|
||||||
|
boolean cancel = false;
|
||||||
|
int bought = 0;
|
||||||
|
boolean oneStackPerShift = game.getPlayerSettings(player).oneStackPerShift();
|
||||||
|
|
||||||
|
if (this.currentCategory == null) {
|
||||||
|
player.closeInventory();
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (ice.getRawSlot() < invSizeCategories) {
|
||||||
|
// is category click
|
||||||
|
ice.setCancelled(true);
|
||||||
|
|
||||||
|
if (item == null) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (item.getType().equals(this.currentCategory.getMaterial())) {
|
||||||
|
// back to default category view
|
||||||
|
this.currentCategory = null;
|
||||||
|
this.openCategoryInventory(player);
|
||||||
|
} else {
|
||||||
|
// open the clicked buy inventory
|
||||||
|
this.handleCategoryInventoryClick(ice, game, player);
|
||||||
|
}
|
||||||
|
} else if (ice.getRawSlot() < totalSize) {
|
||||||
|
// its a buying item
|
||||||
|
ice.setCancelled(true);
|
||||||
|
|
||||||
|
if (item == null || item.getType() == Material.AIR) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
MerchantCategory category = this.currentCategory;
|
||||||
|
|
||||||
|
// 输出点击的物品信息
|
||||||
|
ItemMeta itemMeta = item.getItemMeta();
|
||||||
|
String itemName = itemMeta != null ? itemMeta.getDisplayName() : "无名称";
|
||||||
|
BedwarsRel.getInstance().getServer().getConsoleSender().sendMessage(
|
||||||
|
ChatColor.AQUA + "[BW-Shop] 玩家点击物品: 名称='" + itemName + "', 类型=" + item.getType());
|
||||||
|
|
||||||
|
VillagerTrade trade = this.getTradingItem(category, item, game, player);
|
||||||
|
|
||||||
|
if (trade == null) {
|
||||||
|
BedwarsRel.getInstance().getServer().getConsoleSender().sendMessage(
|
||||||
|
ChatColor.RED + "[BW-Shop] getTradingItem 返回 null,无法找到对应交易");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
player.playSound(player.getLocation(), SoundMachine.get("ITEM_PICKUP", "ENTITY_ITEM_PICKUP"),
|
||||||
|
Float.valueOf("1.0"), Float.valueOf("1.0"));
|
||||||
|
|
||||||
|
// enough ressources?
|
||||||
|
if (!this.hasEnoughRessource(player, trade)) {
|
||||||
|
player
|
||||||
|
.sendMessage(
|
||||||
|
ChatWriter.pluginMessage(ChatColor.RED + BedwarsRel
|
||||||
|
._l(player, "errors.notenoughress")));
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (ice.isShiftClick()) {
|
||||||
|
while (this.hasEnoughRessource(player, trade) && !cancel) {
|
||||||
|
cancel = !this.buyItem(trade, ice.getCurrentItem(), player, game);
|
||||||
|
if (!cancel && oneStackPerShift) {
|
||||||
|
bought = bought + item.getAmount();
|
||||||
|
cancel = ((bought + item.getAmount()) > 64);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
bought = 0;
|
||||||
|
} else {
|
||||||
|
this.buyItem(trade, ice.getCurrentItem(), player, game);
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
if (ice.isShiftClick()) {
|
||||||
|
ice.setCancelled(true);
|
||||||
|
} else {
|
||||||
|
ice.setCancelled(false);
|
||||||
|
}
|
||||||
|
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private void handleCategoryInventoryClick(InventoryClickEvent ice, Game game, Player player) {
|
||||||
|
|
||||||
|
int catSize = this.getCategoriesSize(player);
|
||||||
|
int sizeCategories = this.getInventorySize(catSize) + 9;
|
||||||
|
int rawSlot = ice.getRawSlot();
|
||||||
|
|
||||||
|
if (rawSlot >= this.getInventorySize(catSize) && rawSlot < sizeCategories) {
|
||||||
|
ice.setCancelled(true);
|
||||||
|
if (ice.getCurrentItem().getType() == Material.SLIME_BALL) {
|
||||||
|
this.changeToOldShop(game, player);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (ice.getCurrentItem().getType() == Material.BUCKET) {
|
||||||
|
game.getPlayerSettings(player).setOneStackPerShift(false);
|
||||||
|
player.playSound(player.getLocation(), SoundMachine.get("CLICK", "UI_BUTTON_CLICK"),
|
||||||
|
Float.valueOf("1.0"), Float.valueOf("1.0"));
|
||||||
|
this.openCategoryInventory(player);
|
||||||
|
return;
|
||||||
|
} else if (ice.getCurrentItem().getType() == Material.LAVA_BUCKET) {
|
||||||
|
game.getPlayerSettings(player).setOneStackPerShift(true);
|
||||||
|
player.playSound(player.getLocation(), SoundMachine.get("CLICK", "UI_BUTTON_CLICK"),
|
||||||
|
Float.valueOf("1.0"), Float.valueOf("1.0"));
|
||||||
|
this.openCategoryInventory(player);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
if (rawSlot >= sizeCategories) {
|
||||||
|
if (ice.isShiftClick()) {
|
||||||
|
ice.setCancelled(true);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
ice.setCancelled(false);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
MerchantCategory clickedCategory = this.getCategoryByMaterial(ice.getCurrentItem().getType());
|
||||||
|
if (clickedCategory == null) {
|
||||||
|
if (ice.isShiftClick()) {
|
||||||
|
ice.setCancelled(true);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
ice.setCancelled(false);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
this.openBuyInventory(clickedCategory, player, game);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void handleInventoryClick(InventoryClickEvent ice, Game game, Player player) {
|
||||||
|
if (!this.hasOpenCategory()) {
|
||||||
|
this.handleCategoryInventoryClick(ice, game, player);
|
||||||
|
} else {
|
||||||
|
this.handleBuyInventoryClick(ice, game, player);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private boolean hasEnoughRessource(Player player, VillagerTrade trade) {
|
||||||
|
ItemStack item1 = trade.getItem1();
|
||||||
|
ItemStack item2 = trade.getItem2();
|
||||||
|
PlayerInventory inventory = player.getInventory();
|
||||||
|
|
||||||
|
if (item2 != null) {
|
||||||
|
if (!inventory.contains(item1.getType(), item1.getAmount())
|
||||||
|
|| !inventory.contains(item2.getType(), item2.getAmount())) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
if (!inventory.contains(item1.getType(), item1.getAmount())) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
public boolean hasOpenCategory() {
|
||||||
|
return (this.currentCategory != null);
|
||||||
|
}
|
||||||
|
|
||||||
|
public boolean hasOpenCategory(MerchantCategory category) {
|
||||||
|
if (this.currentCategory == null) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
return (this.currentCategory.equals(category));
|
||||||
|
}
|
||||||
|
|
||||||
|
private void openBuyInventory(MerchantCategory category, Player player, Game game) {
|
||||||
|
List<VillagerTrade> offers = category.getOffers();
|
||||||
|
int sizeCategories = this.getCategoriesSize(player);
|
||||||
|
int sizeItems = offers.size();
|
||||||
|
int invSize = this.getBuyInventorySize(sizeCategories, sizeItems);
|
||||||
|
|
||||||
|
player.playSound(player.getLocation(), SoundMachine.get("CLICK", "UI_BUTTON_CLICK"),
|
||||||
|
Float.valueOf("1.0"), Float.valueOf("1.0"));
|
||||||
|
|
||||||
|
this.currentCategory = category;
|
||||||
|
Inventory buyInventory = Bukkit
|
||||||
|
.createInventory(player, invSize, BedwarsRel._l(player, "ingame.shop.name"));
|
||||||
|
this.addCategoriesToInventory(buyInventory, player, game);
|
||||||
|
|
||||||
|
for (int i = 0; i < offers.size(); i++) {
|
||||||
|
VillagerTrade trade = offers.get(i);
|
||||||
|
if (trade.getItem1().getType() == Material.AIR
|
||||||
|
&& trade.getRewardItem().getType() == Material.AIR) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
int slot = (this.getInventorySize(sizeCategories)) + i;
|
||||||
|
ItemStack tradeStack = this.toItemStack(trade, player, game);
|
||||||
|
|
||||||
|
buyInventory.setItem(slot, tradeStack);
|
||||||
|
}
|
||||||
|
|
||||||
|
player.openInventory(buyInventory);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void openCategoryInventory(Player player) {
|
||||||
|
int catSize = this.getCategoriesSize(player);
|
||||||
|
int nom = (catSize % 9 == 0) ? 9 : (catSize % 9);
|
||||||
|
int size = (catSize + (9 - nom)) + 9;
|
||||||
|
|
||||||
|
Inventory inventory = Bukkit.createInventory(player, size, BedwarsRel
|
||||||
|
._l(player, "ingame.shop.name"));
|
||||||
|
|
||||||
|
Game game = BedwarsRel.getInstance().getGameManager().getGameOfPlayer(player);
|
||||||
|
|
||||||
|
this.addCategoriesToInventory(inventory, player, game);
|
||||||
|
|
||||||
|
ItemStack slime = new ItemStack(Material.SLIME_BALL, 1);
|
||||||
|
ItemMeta slimeMeta = slime.getItemMeta();
|
||||||
|
|
||||||
|
slimeMeta.setDisplayName(BedwarsRel._l(player, "ingame.shop.oldshop"));
|
||||||
|
slimeMeta.setLore(new ArrayList<String>());
|
||||||
|
slime.setItemMeta(slimeMeta);
|
||||||
|
ItemStack stack = null;
|
||||||
|
|
||||||
|
if (game != null) {
|
||||||
|
if (game.getPlayerSettings(player).oneStackPerShift()) {
|
||||||
|
stack = new ItemStack(Material.BUCKET, 1);
|
||||||
|
ItemMeta meta = stack.getItemMeta();
|
||||||
|
|
||||||
|
meta.setDisplayName(
|
||||||
|
ChatColor.AQUA + BedwarsRel._l(player, "default.currently") + ": " + ChatColor.WHITE
|
||||||
|
+ BedwarsRel._l(player, "ingame.shop.onestackpershift"));
|
||||||
|
meta.setLore(new ArrayList<String>());
|
||||||
|
stack.setItemMeta(meta);
|
||||||
|
} else {
|
||||||
|
stack = new ItemStack(Material.LAVA_BUCKET, 1);
|
||||||
|
ItemMeta meta = stack.getItemMeta();
|
||||||
|
|
||||||
|
meta.setDisplayName(
|
||||||
|
ChatColor.AQUA + BedwarsRel._l(player, "default.currently") + ": " + ChatColor.WHITE
|
||||||
|
+ BedwarsRel._l(player, "ingame.shop.fullstackpershift"));
|
||||||
|
meta.setLore(new ArrayList<String>());
|
||||||
|
stack.setItemMeta(meta);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (stack != null) {
|
||||||
|
inventory.setItem(size - 4, stack);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (stack == null) {
|
||||||
|
inventory.setItem(size - 5, slime);
|
||||||
|
} else {
|
||||||
|
inventory.setItem(size - 6, slime);
|
||||||
|
}
|
||||||
|
|
||||||
|
player.openInventory(inventory);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setCurrentCategory(MerchantCategory category) {
|
||||||
|
this.currentCategory = category;
|
||||||
|
}
|
||||||
|
|
||||||
|
@SuppressWarnings("deprecation")
|
||||||
|
private ItemStack toItemStack(VillagerTrade trade, Player player, Game game) {
|
||||||
|
ItemStack tradeStack = trade.getRewardItem().clone();
|
||||||
|
Method colorable = Utils.getColorableMethod(tradeStack.getType());
|
||||||
|
ItemMeta meta = tradeStack.getItemMeta();
|
||||||
|
ItemStack item1 = trade.getItem1();
|
||||||
|
ItemStack item2 = trade.getItem2();
|
||||||
|
if (Utils.isColorable(tradeStack)) {
|
||||||
|
tradeStack.setDurability(game.getPlayerTeam(player).getColor().getDyeColor().getWoolData());
|
||||||
|
} else if (colorable != null) {
|
||||||
|
colorable.setAccessible(true);
|
||||||
|
try {
|
||||||
|
colorable.invoke(meta, new Object[]{game.getPlayerTeam(player).getColor().getColor()});
|
||||||
|
} catch (Exception e) {
|
||||||
|
BedwarsRel.getInstance().getBugsnag().notify(e);
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
List<String> lores = meta.getLore();
|
||||||
|
if (lores == null) {
|
||||||
|
lores = new ArrayList<String>();
|
||||||
|
}
|
||||||
|
|
||||||
|
lores.add(ChatColor.WHITE + String.valueOf(item1.getAmount()) + " "
|
||||||
|
+ item1.getItemMeta().getDisplayName());
|
||||||
|
if (item2 != null) {
|
||||||
|
lores.add(ChatColor.WHITE + String.valueOf(item2.getAmount()) + " "
|
||||||
|
+ item2.getItemMeta().getDisplayName());
|
||||||
|
}
|
||||||
|
|
||||||
|
meta.setLore(lores);
|
||||||
|
tradeStack.setItemMeta(meta);
|
||||||
|
return tradeStack;
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,149 @@
|
|||||||
|
package io.github.bedwarsrel.shop.Specials;
|
||||||
|
|
||||||
|
import com.google.common.collect.ImmutableMap;
|
||||||
|
import io.github.bedwarsrel.BedwarsRel;
|
||||||
|
import io.github.bedwarsrel.game.Game;
|
||||||
|
import io.github.bedwarsrel.utils.ChatWriter;
|
||||||
|
import io.github.bedwarsrel.utils.Utils;
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import org.bukkit.Material;
|
||||||
|
import org.bukkit.entity.Player;
|
||||||
|
import org.bukkit.inventory.ItemStack;
|
||||||
|
import org.bukkit.scheduler.BukkitRunnable;
|
||||||
|
import org.bukkit.scheduler.BukkitTask;
|
||||||
|
|
||||||
|
public class ArrowBlocker extends SpecialItem {
|
||||||
|
|
||||||
|
public boolean isActive = false;
|
||||||
|
private Game game = null;
|
||||||
|
private int livingTime = 0;
|
||||||
|
private Player owner = null;
|
||||||
|
private BukkitTask task = null;
|
||||||
|
|
||||||
|
public ArrowBlocker() {
|
||||||
|
super();
|
||||||
|
|
||||||
|
this.game = null;
|
||||||
|
this.owner = null;
|
||||||
|
}
|
||||||
|
|
||||||
|
@SuppressWarnings("deprecation")
|
||||||
|
public void create(Player player, Game game) {
|
||||||
|
this.game = game;
|
||||||
|
this.owner = player;
|
||||||
|
|
||||||
|
int protectionTime = BedwarsRel.getInstance()
|
||||||
|
.getIntConfig("specials.arrow-blocker.protection-time", 10);
|
||||||
|
int waitTime = BedwarsRel
|
||||||
|
.getInstance().getIntConfig("specials.arrow-blocker.using-wait-time", 30);
|
||||||
|
|
||||||
|
if (waitTime > 0) {
|
||||||
|
ArrayList<ArrowBlocker> livingBlockers = this.getLivingBlocker();
|
||||||
|
if (!livingBlockers.isEmpty()) {
|
||||||
|
for (ArrowBlocker livingBlocker : livingBlockers) {
|
||||||
|
int waitLeft = waitTime - livingBlocker.getLivingTime();
|
||||||
|
if (waitLeft > 0) {
|
||||||
|
player.sendMessage(
|
||||||
|
ChatWriter.pluginMessage(BedwarsRel._l(player, "ingame.specials.arrow-blocker.left",
|
||||||
|
ImmutableMap.of("time", String.valueOf(waitLeft)))));
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
ItemStack usedStack = null;
|
||||||
|
|
||||||
|
if (BedwarsRel.getInstance().getCurrentVersion().startsWith("v1_8")) {
|
||||||
|
usedStack = player.getInventory().getItemInHand();
|
||||||
|
usedStack.setAmount(usedStack.getAmount() - 1);
|
||||||
|
player.getInventory().setItem(player.getInventory().getHeldItemSlot(), usedStack);
|
||||||
|
} else {
|
||||||
|
if (player.getInventory().getItemInOffHand().getType() == this.getItemMaterial()) {
|
||||||
|
usedStack = player.getInventory().getItemInOffHand();
|
||||||
|
usedStack.setAmount(usedStack.getAmount() - 1);
|
||||||
|
player.getInventory().setItemInOffHand(usedStack);
|
||||||
|
} else if (player.getInventory().getItemInMainHand().getType() == this.getItemMaterial()) {
|
||||||
|
usedStack = player.getInventory().getItemInMainHand();
|
||||||
|
usedStack.setAmount(usedStack.getAmount() - 1);
|
||||||
|
player.getInventory().setItemInMainHand(usedStack);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
player.updateInventory();
|
||||||
|
|
||||||
|
player
|
||||||
|
.sendMessage(ChatWriter.pluginMessage(
|
||||||
|
BedwarsRel._l(player, "ingame.specials.arrow-blocker.start",
|
||||||
|
ImmutableMap.of("time", String.valueOf(protectionTime)))));
|
||||||
|
|
||||||
|
if (protectionTime > 0 || waitTime > 0) {
|
||||||
|
isActive = true;
|
||||||
|
this.runTask(protectionTime, waitTime, player);
|
||||||
|
game.addSpecialItem(this);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Material getActivatedMaterial() {
|
||||||
|
// not needed
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Game getGame() {
|
||||||
|
return this.game;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Material getItemMaterial() {
|
||||||
|
return Utils.getMaterialByConfig("specials.arrow-blocker.item", Material.EYE_OF_ENDER);
|
||||||
|
}
|
||||||
|
|
||||||
|
private ArrayList<ArrowBlocker> getLivingBlocker() {
|
||||||
|
ArrayList<ArrowBlocker> livingBlocker = new ArrayList<ArrowBlocker>();
|
||||||
|
for (SpecialItem item : game.getSpecialItems()) {
|
||||||
|
if (item instanceof ArrowBlocker) {
|
||||||
|
ArrowBlocker blocker = (ArrowBlocker) item;
|
||||||
|
if (blocker.getOwner().equals(this.getOwner())) {
|
||||||
|
livingBlocker.add(blocker);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return livingBlocker;
|
||||||
|
}
|
||||||
|
|
||||||
|
public int getLivingTime() {
|
||||||
|
return this.livingTime;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Player getOwner() {
|
||||||
|
return this.owner;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void runTask(final int protectionTime, final int waitTime, final Player player) {
|
||||||
|
this.task = new BukkitRunnable() {
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void run() {
|
||||||
|
ArrowBlocker.this.livingTime++;
|
||||||
|
|
||||||
|
if (protectionTime > 0 && ArrowBlocker.this.livingTime == protectionTime) {
|
||||||
|
player.sendMessage(
|
||||||
|
ChatWriter.pluginMessage(BedwarsRel._l(player, "ingame.specials.arrow-blocker.end")));
|
||||||
|
isActive = false;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (ArrowBlocker.this.livingTime >= waitTime
|
||||||
|
&& ArrowBlocker.this.livingTime >= protectionTime) {
|
||||||
|
ArrowBlocker.this.game.removeRunningTask(this);
|
||||||
|
ArrowBlocker.this.game.removeSpecialItem(ArrowBlocker.this);
|
||||||
|
ArrowBlocker.this.task = null;
|
||||||
|
isActive = false;
|
||||||
|
this.cancel();
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}.runTaskTimer(BedwarsRel.getInstance(), 0, 20L);
|
||||||
|
this.game.addRunningTask(this.task);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
@@ -0,0 +1,88 @@
|
|||||||
|
package io.github.bedwarsrel.shop.Specials;
|
||||||
|
|
||||||
|
import io.github.bedwarsrel.BedwarsRel;
|
||||||
|
import io.github.bedwarsrel.game.Game;
|
||||||
|
import io.github.bedwarsrel.game.GameState;
|
||||||
|
import org.bukkit.entity.EntityType;
|
||||||
|
import org.bukkit.entity.Player;
|
||||||
|
import org.bukkit.event.EventHandler;
|
||||||
|
import org.bukkit.event.EventPriority;
|
||||||
|
import org.bukkit.event.Listener;
|
||||||
|
import org.bukkit.event.block.Action;
|
||||||
|
import org.bukkit.event.entity.EntityDamageEvent;
|
||||||
|
import org.bukkit.event.entity.EntityDamageEvent.DamageCause;
|
||||||
|
import org.bukkit.event.player.PlayerInteractEvent;
|
||||||
|
|
||||||
|
public class ArrowBlockerListener implements Listener {
|
||||||
|
|
||||||
|
private boolean isBlockerActive(Player player, Game game) {
|
||||||
|
for (SpecialItem item : game.getSpecialItems()) {
|
||||||
|
if (item instanceof ArrowBlocker) {
|
||||||
|
ArrowBlocker blocker = (ArrowBlocker) item;
|
||||||
|
if (blocker.getOwner().equals(player)) {
|
||||||
|
if (blocker.isActive) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
@EventHandler(priority = EventPriority.HIGH)
|
||||||
|
public void onDamage(EntityDamageEvent ev) {
|
||||||
|
if (!ev.getCause().equals(DamageCause.PROJECTILE)) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!ev.getEntityType().equals(EntityType.PLAYER)) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
Player player = (Player) ev.getEntity();
|
||||||
|
|
||||||
|
Game game = BedwarsRel.getInstance().getGameManager().getGameOfPlayer(player);
|
||||||
|
|
||||||
|
if (game == null) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (game.getState() != GameState.RUNNING) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!isBlockerActive(player, game)) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
ev.setCancelled(true);
|
||||||
|
}
|
||||||
|
|
||||||
|
@EventHandler
|
||||||
|
public void onInteract(PlayerInteractEvent ev) {
|
||||||
|
if (ev.getAction().equals(Action.LEFT_CLICK_AIR)
|
||||||
|
|| ev.getAction().equals(Action.LEFT_CLICK_BLOCK)) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
Player player = ev.getPlayer();
|
||||||
|
Game game = BedwarsRel.getInstance().getGameManager().getGameOfPlayer(player);
|
||||||
|
|
||||||
|
if (game == null) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (game.getState() != GameState.RUNNING) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
ArrowBlocker blocker = new ArrowBlocker();
|
||||||
|
if (!ev.getMaterial().equals(blocker.getItemMaterial())) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
blocker.create(player, game);
|
||||||
|
ev.setCancelled(true);
|
||||||
|
player.updateInventory();
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
@@ -0,0 +1,21 @@
|
|||||||
|
package io.github.bedwarsrel.shop.Specials;
|
||||||
|
|
||||||
|
import org.bukkit.Location;
|
||||||
|
import org.bukkit.entity.Entity;
|
||||||
|
import org.bukkit.entity.TNTPrimed;
|
||||||
|
|
||||||
|
public interface ITNTSheep {
|
||||||
|
|
||||||
|
public Location getLocation();
|
||||||
|
|
||||||
|
public TNTPrimed getTNT();
|
||||||
|
|
||||||
|
public void setTNT(TNTPrimed tnt);
|
||||||
|
|
||||||
|
public void remove();
|
||||||
|
|
||||||
|
public void setPassenger(TNTPrimed tnt);
|
||||||
|
|
||||||
|
public void setTNTSource(Entity source);
|
||||||
|
|
||||||
|
}
|
||||||
@@ -0,0 +1,14 @@
|
|||||||
|
package io.github.bedwarsrel.shop.Specials;
|
||||||
|
|
||||||
|
import org.bukkit.DyeColor;
|
||||||
|
import org.bukkit.Location;
|
||||||
|
import org.bukkit.entity.Player;
|
||||||
|
|
||||||
|
public interface ITNTSheepRegister {
|
||||||
|
|
||||||
|
public void registerEntities(int entityId);
|
||||||
|
|
||||||
|
public ITNTSheep spawnCreature(TNTSheep specialItem, Location location, Player owner,
|
||||||
|
Player target, DyeColor color);
|
||||||
|
|
||||||
|
}
|
||||||
@@ -0,0 +1,33 @@
|
|||||||
|
package io.github.bedwarsrel.shop.Specials;
|
||||||
|
|
||||||
|
import io.github.bedwarsrel.BedwarsRel;
|
||||||
|
import io.github.bedwarsrel.utils.Utils;
|
||||||
|
import org.bukkit.Material;
|
||||||
|
|
||||||
|
public class MagnetShoe extends SpecialItem {
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Material getActivatedMaterial() {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
@SuppressWarnings("deprecation")
|
||||||
|
@Override
|
||||||
|
public Material getItemMaterial() {
|
||||||
|
String item = BedwarsRel.getInstance()
|
||||||
|
.getStringConfig("specials.magnetshoe.boots", "IRON_BOOTS");
|
||||||
|
Material material = null;
|
||||||
|
if (Utils.isNumber(item)) {
|
||||||
|
material = Material.getMaterial(Integer.valueOf(item));
|
||||||
|
} else {
|
||||||
|
material = Material.getMaterial(item);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (material == null) {
|
||||||
|
return Material.IRON_BOOTS;
|
||||||
|
}
|
||||||
|
|
||||||
|
return material;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
@@ -0,0 +1,60 @@
|
|||||||
|
package io.github.bedwarsrel.shop.Specials;
|
||||||
|
|
||||||
|
import io.github.bedwarsrel.BedwarsRel;
|
||||||
|
import io.github.bedwarsrel.game.Game;
|
||||||
|
import io.github.bedwarsrel.game.GameState;
|
||||||
|
import io.github.bedwarsrel.utils.Utils;
|
||||||
|
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.inventory.ItemStack;
|
||||||
|
|
||||||
|
public class MagnetShoeListener implements Listener {
|
||||||
|
|
||||||
|
@EventHandler(priority = EventPriority.HIGHEST)
|
||||||
|
public void onDamage(EntityDamageByEntityEvent ev) {
|
||||||
|
if (ev.isCancelled()) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!(ev.getEntity() instanceof Player)) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
Game game = BedwarsRel.getInstance().getGameManager().getGameOfPlayer((Player) ev.getEntity());
|
||||||
|
if (game == null) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (game.getState() != GameState.RUNNING) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
Player player = (Player) ev.getEntity();
|
||||||
|
ItemStack boots = player.getInventory().getBoots();
|
||||||
|
|
||||||
|
if (boots == null) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
MagnetShoe shoe = new MagnetShoe();
|
||||||
|
if (boots.getType() != shoe.getItemMaterial()) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (this.rollKnockbackDice()) {
|
||||||
|
ev.setCancelled(true);
|
||||||
|
player.damage(ev.getDamage());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private boolean rollKnockbackDice() {
|
||||||
|
int target = BedwarsRel.getInstance().getIntConfig("specials.magnetshoe.probability", 75);
|
||||||
|
int roll = Utils.randInt(0, 100);
|
||||||
|
|
||||||
|
return (roll <= target);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
@@ -0,0 +1,229 @@
|
|||||||
|
package io.github.bedwarsrel.shop.Specials;
|
||||||
|
|
||||||
|
import com.google.common.collect.ImmutableMap;
|
||||||
|
import io.github.bedwarsrel.BedwarsRel;
|
||||||
|
import io.github.bedwarsrel.game.Game;
|
||||||
|
import io.github.bedwarsrel.utils.ChatWriter;
|
||||||
|
import io.github.bedwarsrel.utils.Utils;
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.List;
|
||||||
|
import org.bukkit.Location;
|
||||||
|
import org.bukkit.Material;
|
||||||
|
import org.bukkit.block.Block;
|
||||||
|
import org.bukkit.block.BlockFace;
|
||||||
|
import org.bukkit.entity.Player;
|
||||||
|
import org.bukkit.inventory.ItemStack;
|
||||||
|
import org.bukkit.scheduler.BukkitRunnable;
|
||||||
|
import org.bukkit.scheduler.BukkitTask;
|
||||||
|
|
||||||
|
public class ProtectionWall extends SpecialItem {
|
||||||
|
|
||||||
|
private Game game = null;
|
||||||
|
private int livingTime = 0;
|
||||||
|
private Player owner = null;
|
||||||
|
private BukkitTask task = null;
|
||||||
|
private List<Block> wallBlocks = null;
|
||||||
|
|
||||||
|
public ProtectionWall() {
|
||||||
|
super();
|
||||||
|
this.wallBlocks = new ArrayList<Block>();
|
||||||
|
this.owner = null;
|
||||||
|
this.game = null;
|
||||||
|
}
|
||||||
|
|
||||||
|
@SuppressWarnings("deprecation")
|
||||||
|
public void create(Player player, Game game) {
|
||||||
|
this.owner = player;
|
||||||
|
this.game = game;
|
||||||
|
|
||||||
|
int breakTime = BedwarsRel.getInstance().getIntConfig("specials.protection-wall.break-time", 0);
|
||||||
|
int waitTime = BedwarsRel.getInstance().getIntConfig("specials.protection-wall.wait-time", 20);
|
||||||
|
int width = BedwarsRel.getInstance().getIntConfig("specials.protection-wall.width", 4);
|
||||||
|
int height = BedwarsRel.getInstance().getIntConfig("specials.protection-wall.height", 4);
|
||||||
|
int distance = BedwarsRel.getInstance().getIntConfig("specials.protection-wall.distance", 2);
|
||||||
|
boolean canBreak =
|
||||||
|
BedwarsRel.getInstance().getBooleanConfig("specials.protection-wall.can-break", true);
|
||||||
|
Material blockMaterial =
|
||||||
|
Utils.getMaterialByConfig("specials.protection-wall.block", Material.SANDSTONE);
|
||||||
|
|
||||||
|
if (width % 2 == 0) {
|
||||||
|
BedwarsRel.getInstance().getServer().getConsoleSender().sendMessage(ChatWriter.pluginMessage(
|
||||||
|
"The width of a protection block has to be odd! " + width + " is not an odd number."));
|
||||||
|
width = width + 1;
|
||||||
|
if (width % 2 == 0) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (player.getEyeLocation().getBlock().getType() != Material.AIR) {
|
||||||
|
player.sendMessage(
|
||||||
|
ChatWriter
|
||||||
|
.pluginMessage(
|
||||||
|
BedwarsRel._l(player, "ingame.specials.protection-wall.not-usable-here")));
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (waitTime > 0) {
|
||||||
|
ArrayList<ProtectionWall> livingWalls = this.getLivingWalls();
|
||||||
|
if (!livingWalls.isEmpty()) {
|
||||||
|
for (ProtectionWall livingWall : livingWalls) {
|
||||||
|
int waitLeft = waitTime - livingWall.getLivingTime();
|
||||||
|
if (waitLeft > 0) {
|
||||||
|
player.sendMessage(
|
||||||
|
ChatWriter.pluginMessage(
|
||||||
|
BedwarsRel._l(player, "ingame.specials.protection-wall.left",
|
||||||
|
ImmutableMap.of("time", String.valueOf(waitLeft)))));
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
Location wallLocation = Utils.getDirectionLocation(player.getLocation(), distance);
|
||||||
|
|
||||||
|
ItemStack usedStack = null;
|
||||||
|
|
||||||
|
if (BedwarsRel.getInstance().getCurrentVersion().startsWith("v1_8")) {
|
||||||
|
usedStack = player.getInventory().getItemInHand();
|
||||||
|
usedStack.setAmount(usedStack.getAmount() - 1);
|
||||||
|
player.getInventory().setItem(player.getInventory().getHeldItemSlot(), usedStack);
|
||||||
|
} else {
|
||||||
|
if (player.getInventory().getItemInOffHand().getType() == this.getItemMaterial()) {
|
||||||
|
usedStack = player.getInventory().getItemInOffHand();
|
||||||
|
usedStack.setAmount(usedStack.getAmount() - 1);
|
||||||
|
player.getInventory().setItemInOffHand(usedStack);
|
||||||
|
} else if (player.getInventory().getItemInMainHand().getType() == this.getItemMaterial()) {
|
||||||
|
usedStack = player.getInventory().getItemInMainHand();
|
||||||
|
usedStack.setAmount(usedStack.getAmount() - 1);
|
||||||
|
player.getInventory().setItemInMainHand(usedStack);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
player.updateInventory();
|
||||||
|
|
||||||
|
BlockFace face = Utils.getCardinalDirection(player.getLocation());
|
||||||
|
int widthStart = (int) Math.floor(((double) width) / 2.0);
|
||||||
|
|
||||||
|
for (int w = widthStart * (-1); w < width - widthStart; w++) {
|
||||||
|
for (int h = 0; h < height; h++) {
|
||||||
|
Location wallBlock = wallLocation.clone();
|
||||||
|
|
||||||
|
switch (face) {
|
||||||
|
case SOUTH:
|
||||||
|
case NORTH:
|
||||||
|
case SELF:
|
||||||
|
wallBlock.add(0, h, w);
|
||||||
|
break;
|
||||||
|
case WEST:
|
||||||
|
case EAST:
|
||||||
|
wallBlock.add(w, h, 0);
|
||||||
|
break;
|
||||||
|
case SOUTH_EAST:
|
||||||
|
wallBlock.add(w, h, w);
|
||||||
|
break;
|
||||||
|
case SOUTH_WEST:
|
||||||
|
wallBlock.add(w, h, w * (-1));
|
||||||
|
break;
|
||||||
|
case NORTH_EAST:
|
||||||
|
wallBlock.add(w * (-1), h, w);
|
||||||
|
break;
|
||||||
|
case NORTH_WEST:
|
||||||
|
wallBlock.add(w * (-1), h, w * (-1));
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
wallBlock = null;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (wallBlock == null) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
Block block = wallBlock.getBlock();
|
||||||
|
if (!block.getType().equals(Material.AIR)) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
block.setType(blockMaterial);
|
||||||
|
if (!canBreak) {
|
||||||
|
game.getRegion().addPlacedUnbreakableBlock(wallBlock.getBlock(), null);
|
||||||
|
} else {
|
||||||
|
game.getRegion().addPlacedBlock(wallBlock.getBlock(), null);
|
||||||
|
}
|
||||||
|
this.wallBlocks.add(block);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (breakTime > 0 || waitTime > 0) {
|
||||||
|
this.createTask(breakTime, waitTime);
|
||||||
|
game.addSpecialItem(this);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private void createTask(final int breakTime, final int waitTime) {
|
||||||
|
this.task = new BukkitRunnable() {
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void run() {
|
||||||
|
ProtectionWall.this.livingTime++;
|
||||||
|
|
||||||
|
if (breakTime > 0 && ProtectionWall.this.livingTime == breakTime) {
|
||||||
|
for (Block block : ProtectionWall.this.wallBlocks) {
|
||||||
|
block.getChunk().load(true);
|
||||||
|
block.setType(Material.AIR);
|
||||||
|
ProtectionWall.this.game.getRegion().removePlacedUnbreakableBlock(block);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (ProtectionWall.this.livingTime >= waitTime
|
||||||
|
&& ProtectionWall.this.livingTime >= breakTime) {
|
||||||
|
ProtectionWall.this.game.removeRunningTask(this);
|
||||||
|
ProtectionWall.this.game.removeSpecialItem(ProtectionWall.this);
|
||||||
|
ProtectionWall.this.task = null;
|
||||||
|
this.cancel();
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}.runTaskTimer(BedwarsRel.getInstance(), 20L, 20L);
|
||||||
|
this.game.addRunningTask(this.task);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Material getActivatedMaterial() {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Game getGame() {
|
||||||
|
return this.game;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Material getItemMaterial() {
|
||||||
|
return Utils.getMaterialByConfig("specials.protection-wall.item", Material.BRICK);
|
||||||
|
}
|
||||||
|
|
||||||
|
public int getLivingTime() {
|
||||||
|
return this.livingTime;
|
||||||
|
}
|
||||||
|
|
||||||
|
private ArrayList<ProtectionWall> getLivingWalls() {
|
||||||
|
ArrayList<ProtectionWall> livingWalls = new ArrayList<ProtectionWall>();
|
||||||
|
for (SpecialItem item : game.getSpecialItems()) {
|
||||||
|
if (item instanceof ProtectionWall) {
|
||||||
|
ProtectionWall wall = (ProtectionWall) item;
|
||||||
|
if (wall.getOwner().equals(this.getOwner())) {
|
||||||
|
livingWalls.add(wall);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return livingWalls;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Player getOwner() {
|
||||||
|
return this.owner;
|
||||||
|
}
|
||||||
|
|
||||||
|
public List<Block> getWallBlocks() {
|
||||||
|
return this.wallBlocks;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
@@ -0,0 +1,46 @@
|
|||||||
|
package io.github.bedwarsrel.shop.Specials;
|
||||||
|
|
||||||
|
import io.github.bedwarsrel.BedwarsRel;
|
||||||
|
import io.github.bedwarsrel.game.Game;
|
||||||
|
import io.github.bedwarsrel.game.GameState;
|
||||||
|
import org.bukkit.event.EventHandler;
|
||||||
|
import org.bukkit.event.EventPriority;
|
||||||
|
import org.bukkit.event.Listener;
|
||||||
|
import org.bukkit.event.block.Action;
|
||||||
|
import org.bukkit.event.player.PlayerInteractEvent;
|
||||||
|
|
||||||
|
public class ProtectionWallListener implements Listener {
|
||||||
|
|
||||||
|
@EventHandler(priority = EventPriority.HIGHEST)
|
||||||
|
public void onInteract(PlayerInteractEvent interact) {
|
||||||
|
if (interact.getAction().equals(Action.LEFT_CLICK_AIR)
|
||||||
|
|| interact.getAction().equals(Action.LEFT_CLICK_BLOCK)) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (interact.getMaterial() == null) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
ProtectionWall wall = new ProtectionWall();
|
||||||
|
if (interact.getMaterial() != wall.getItemMaterial()) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
Game game = BedwarsRel.getInstance().getGameManager().getGameOfPlayer(interact.getPlayer());
|
||||||
|
if (game == null) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (game.getState() != GameState.RUNNING) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (game.isSpectator(interact.getPlayer())) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
wall.create(interact.getPlayer(), game);
|
||||||
|
interact.setCancelled(true);
|
||||||
|
}
|
||||||
|
}
|
||||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user